From: "Guillaume Douézan-Grard" <gdouezangrard@gmail.com>
To: Andy Shevchenko <andy@infradead.org>
Cc: Darren Hart <dvhart@infradead.org>,
platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v4 4/7] platform/x86: topstar-laptop: add platform device
Date: Wed, 21 Feb 2018 17:10:00 +0100 [thread overview]
Message-ID: <0692865d68df413be7963cd9fecad0fccd60c0f6.1519228823.git.gdouezangrard@gmail.com> (raw)
In-Reply-To: <cover.1519228823.git.gdouezangrard@gmail.com>
* add a platform device to support further addition of a led subsystem,
* register the existing input device to this platform device.
Signed-off-by: Guillaume Douézan-Grard <gdouezangrard@gmail.com>
---
drivers/platform/x86/topstar-laptop.c | 59 +++++++++++++++++++++++++++++++++--
1 file changed, 57 insertions(+), 2 deletions(-)
diff --git a/drivers/platform/x86/topstar-laptop.c b/drivers/platform/x86/topstar-laptop.c
index fbf020e8a0e1..792c90d62724 100644
--- a/drivers/platform/x86/topstar-laptop.c
+++ b/drivers/platform/x86/topstar-laptop.c
@@ -20,11 +20,13 @@
#include <linux/acpi.h>
#include <linux/input.h>
#include <linux/input/sparse-keymap.h>
+#include <linux/platform_device.h>
#define TOPSTAR_LAPTOP_CLASS "topstar"
struct topstar_laptop {
struct acpi_device *device;
+ struct platform_device *platform;
struct input_dev *input;
};
@@ -80,6 +82,7 @@ static int topstar_input_init(struct topstar_laptop *topstar)
input->name = "Topstar Laptop extra buttons";
input->phys = TOPSTAR_LAPTOP_CLASS "/input0";
input->id.bustype = BUS_HOST;
+ input->dev.parent = &topstar->platform->dev;
err = sparse_keymap_setup(input, topstar_keymap, NULL);
if (err) {
@@ -106,6 +109,42 @@ static void topstar_input_exit(struct topstar_laptop *topstar)
input_unregister_device(topstar->input);
}
+/*
+ * Platform
+ */
+
+static struct platform_driver topstar_platform_driver = {
+ .driver = {
+ .name = TOPSTAR_LAPTOP_CLASS,
+ },
+};
+
+static int topstar_platform_init(struct topstar_laptop *topstar)
+{
+ int err;
+
+ topstar->platform = platform_device_alloc(TOPSTAR_LAPTOP_CLASS, -1);
+ if (!topstar->platform)
+ return -ENOMEM;
+
+ platform_set_drvdata(topstar->platform, topstar);
+
+ err = platform_device_add(topstar->platform);
+ if (err)
+ goto err_device_put;
+
+ return 0;
+
+err_device_put:
+ platform_device_put(topstar->platform);
+ return err;
+}
+
+static void topstar_platform_exit(struct topstar_laptop *topstar)
+{
+ platform_device_unregister(topstar->platform);
+}
+
/*
* ACPI
*/
@@ -171,12 +210,18 @@ static int topstar_acpi_add(struct acpi_device *device)
if (err)
goto err_free;
- err = topstar_input_init(topstar);
+ err = topstar_platform_init(topstar);
if (err)
goto err_acpi_exit;
+ err = topstar_input_init(topstar);
+ if (err)
+ goto err_platform_exit;
+
return 0;
+err_platform_exit:
+ topstar_platform_exit(topstar);
err_acpi_exit:
topstar_acpi_exit(topstar);
err_free:
@@ -189,6 +234,7 @@ static int topstar_acpi_remove(struct acpi_device *device)
struct topstar_laptop *topstar = acpi_driver_data(device);
topstar_input_exit(topstar);
+ topstar_platform_exit(topstar);
topstar_acpi_exit(topstar);
kfree(topstar);
@@ -217,17 +263,26 @@ static int __init topstar_laptop_init(void)
{
int ret;
- ret = acpi_bus_register_driver(&topstar_acpi_driver);
+ ret = platform_driver_register(&topstar_platform_driver);
if (ret < 0)
return ret;
+ ret = acpi_bus_register_driver(&topstar_acpi_driver);
+ if (ret < 0)
+ goto err_driver_unreg;
+
pr_info("ACPI extras driver loaded\n");
return 0;
+
+err_driver_unreg:
+ platform_driver_unregister(&topstar_platform_driver);
+ return ret;
}
static void __exit topstar_laptop_exit(void)
{
acpi_bus_unregister_driver(&topstar_acpi_driver);
+ platform_driver_unregister(&topstar_platform_driver);
}
module_init(topstar_laptop_init);
--
2.16.1
next prev parent reply other threads:[~2018-02-21 16:10 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-21 16:09 [PATCH v4 0/7] Topstar U931/RVP7 ACPI LED Workaround Guillaume Douézan-Grard
2018-02-21 16:09 ` [PATCH v4 1/7] platform/x86: topstar-laptop: revert "convert to module_acpi_driver()" Guillaume Douézan-Grard
2018-02-21 16:09 ` [PATCH v4 2/7] platform/x86: topstar-laptop: use consistent naming scheme Guillaume Douézan-Grard
2018-02-21 16:09 ` [PATCH v4 3/7] platform/x86: topstar-laptop: split ACPI events and input handling Guillaume Douézan-Grard
2018-02-21 16:10 ` Guillaume Douézan-Grard [this message]
2018-02-21 16:10 ` [PATCH v4 5/7] platform/x86: topstar-laptop: add Topstar U931/RVP7 WLAN LED workaround Guillaume Douézan-Grard
2018-02-21 16:25 ` Andy Shevchenko
2018-02-21 16:39 ` Guillaume Douézan-Grard
2018-02-21 16:10 ` [PATCH v4 6/7] platform/x86: topstar-laptop: update copyright and fix some comments Guillaume Douézan-Grard
2018-02-21 16:10 ` [PATCH v4 7/7] platform/x86: topstar-laptop: replace licence text with SPDX tag Guillaume Douézan-Grard
2018-02-21 16:26 ` Andy Shevchenko
2018-02-21 16:26 ` Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0692865d68df413be7963cd9fecad0fccd60c0f6.1519228823.git.gdouezangrard@gmail.com \
--to=gdouezangrard@gmail.com \
--cc=andy@infradead.org \
--cc=dvhart@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).