From: "Michał Kępień" <kernel@kempniu.pl>
To: Jonathan Woithe <jwoithe@just42.net>,
Darren Hart <dvhart@infradead.org>,
Andy Shevchenko <andy@infradead.org>
Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 09/10] platform/x86: fujitsu-laptop: use device-specific data in LED-related code
Date: Mon, 24 Apr 2017 15:33:33 +0200 [thread overview]
Message-ID: <20170424133334.7064-10-kernel@kempniu.pl> (raw)
In-Reply-To: <20170424133334.7064-1-kernel@kempniu.pl>
In order to perform their duties, all LED callbacks need a handle to the
FUJ02E3 ACPI device. If that handle is to be fetched without accessing
module-wide data, it needs to be extracted from data that gets passed to
the LED callbacks as arguments. However, LED core does not currently
support supplying driver-specific pointers to struct led_classdev
callbacks, so the latter will have to be implemented a bit differently
than backlight device callbacks and platform device attribute callbacks.
As the FUJ02E3 ACPI device is the parent device of all LED class devices
registered by fujitsu-laptop, we can get to the struct acpi_device
representing the former by following the parent link present inside the
struct device belonging to the struct led_classdev passed as an argument
to each LED callback. Note that acpi_driver_data() is not used to
retrieve the ACPI handle. Doing that would break cleanup upon module
removal, because the managed LED class device release callback,
devm_led_classdev_release(), would be called after the bus-level device
removal callback, acpi_device_remove(), which sets the driver_data
member of struct acpi_device to NULL and as devm_led_classdev_release()
calls led_classdev_unregister(), which in turn resets the LED's
brightness to LED_OFF, LED callbacks would not be able to retrieve the
ACPI handle needed to perform that operation. To work around this, the
handle is retrieved directly from struct acpi_device as the latter is
guaranteed to be available upon brightness reset because parent device's
reference count is only decremented once brightness gets reset.
To get rid of module-wide structures defining LED class devices,
allocate them dynamically using devm_kzalloc() and initialize them in
acpi_fujitsu_laptop_leds_register().
Signed-off-by: Michał Kępień <kernel@kempniu.pl>
---
drivers/platform/x86/fujitsu-laptop.c | 113 ++++++++++++++++------------------
1 file changed, 53 insertions(+), 60 deletions(-)
diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
index f26abc41266e..77082e35f26a 100644
--- a/drivers/platform/x86/fujitsu-laptop.c
+++ b/drivers/platform/x86/fujitsu-laptop.c
@@ -635,6 +635,7 @@ static void fujitsu_laptop_platform_remove(void)
static int logolamp_set(struct led_classdev *cdev,
enum led_brightness brightness)
{
+ acpi_handle handle = to_acpi_device(cdev->dev->parent)->handle;
int poweron = FUNC_LED_ON, always = FUNC_LED_ON;
int ret;
@@ -644,136 +645,120 @@ static int logolamp_set(struct led_classdev *cdev,
if (brightness < LED_FULL)
always = FUNC_LED_OFF;
- ret = fext_leds(fujitsu_laptop->handle, 0x1, LOGOLAMP_POWERON, poweron);
+ ret = fext_leds(handle, 0x1, LOGOLAMP_POWERON, poweron);
if (ret < 0)
return ret;
- return fext_leds(fujitsu_laptop->handle, 0x1, LOGOLAMP_ALWAYS, always);
+ return fext_leds(handle, 0x1, LOGOLAMP_ALWAYS, always);
}
static enum led_brightness logolamp_get(struct led_classdev *cdev)
{
+ acpi_handle handle = to_acpi_device(cdev->dev->parent)->handle;
int ret;
- ret = fext_leds(fujitsu_laptop->handle, 0x2, LOGOLAMP_ALWAYS, 0x0);
+ ret = fext_leds(handle, 0x2, LOGOLAMP_ALWAYS, 0x0);
if (ret == FUNC_LED_ON)
return LED_FULL;
- ret = fext_leds(fujitsu_laptop->handle, 0x2, LOGOLAMP_POWERON, 0x0);
+ ret = fext_leds(handle, 0x2, LOGOLAMP_POWERON, 0x0);
if (ret == FUNC_LED_ON)
return LED_HALF;
return LED_OFF;
}
-static struct led_classdev logolamp_led = {
- .name = "fujitsu::logolamp",
- .brightness_set_blocking = logolamp_set,
- .brightness_get = logolamp_get
-};
-
static int kblamps_set(struct led_classdev *cdev,
enum led_brightness brightness)
{
+ acpi_handle handle = to_acpi_device(cdev->dev->parent)->handle;
+
if (brightness >= LED_FULL)
- return fext_leds(fujitsu_laptop->handle, 0x1, KEYBOARD_LAMPS,
- FUNC_LED_ON);
+ return fext_leds(handle, 0x1, KEYBOARD_LAMPS, FUNC_LED_ON);
else
- return fext_leds(fujitsu_laptop->handle, 0x1, KEYBOARD_LAMPS,
- FUNC_LED_OFF);
+ return fext_leds(handle, 0x1, KEYBOARD_LAMPS, FUNC_LED_OFF);
}
static enum led_brightness kblamps_get(struct led_classdev *cdev)
{
+ acpi_handle handle = to_acpi_device(cdev->dev->parent)->handle;
enum led_brightness brightness = LED_OFF;
- if (fext_leds(fujitsu_laptop->handle,
- 0x2, KEYBOARD_LAMPS, 0x0) == FUNC_LED_ON)
+ if (fext_leds(handle, 0x2, KEYBOARD_LAMPS, 0x0) == FUNC_LED_ON)
brightness = LED_FULL;
return brightness;
}
-static struct led_classdev kblamps_led = {
- .name = "fujitsu::kblamps",
- .brightness_set_blocking = kblamps_set,
- .brightness_get = kblamps_get
-};
-
static int radio_led_set(struct led_classdev *cdev,
enum led_brightness brightness)
{
+ acpi_handle handle = to_acpi_device(cdev->dev->parent)->handle;
+
if (brightness >= LED_FULL)
- return fext_flags(fujitsu_laptop->handle, 0x5, RADIO_LED_ON,
- RADIO_LED_ON);
+ return fext_flags(handle, 0x5, RADIO_LED_ON, RADIO_LED_ON);
else
- return fext_flags(fujitsu_laptop->handle, 0x5, RADIO_LED_ON,
- 0x0);
+ return fext_flags(handle, 0x5, RADIO_LED_ON, 0x0);
}
static enum led_brightness radio_led_get(struct led_classdev *cdev)
{
+ acpi_handle handle = to_acpi_device(cdev->dev->parent)->handle;
enum led_brightness brightness = LED_OFF;
- if (fext_flags(fujitsu_laptop->handle, 0x4, 0x0, 0x0) & RADIO_LED_ON)
+ if (fext_flags(handle, 0x4, 0x0, 0x0) & RADIO_LED_ON)
brightness = LED_FULL;
return brightness;
}
-static struct led_classdev radio_led = {
- .name = "fujitsu::radio_led",
- .brightness_set_blocking = radio_led_set,
- .brightness_get = radio_led_get,
- .default_trigger = "rfkill-any"
-};
-
static int eco_led_set(struct led_classdev *cdev,
enum led_brightness brightness)
{
+ acpi_handle handle = to_acpi_device(cdev->dev->parent)->handle;
int curr;
- curr = fext_leds(fujitsu_laptop->handle, 0x2, ECO_LED, 0x0);
+ curr = fext_leds(handle, 0x2, ECO_LED, 0x0);
if (brightness >= LED_FULL)
- return fext_leds(fujitsu_laptop->handle, 0x1, ECO_LED,
- curr | ECO_LED_ON);
+ return fext_leds(handle, 0x1, ECO_LED, curr | ECO_LED_ON);
else
- return fext_leds(fujitsu_laptop->handle, 0x1, ECO_LED,
- curr & ~ECO_LED_ON);
+ return fext_leds(handle, 0x1, ECO_LED, curr & ~ECO_LED_ON);
}
static enum led_brightness eco_led_get(struct led_classdev *cdev)
{
+ acpi_handle handle = to_acpi_device(cdev->dev->parent)->handle;
enum led_brightness brightness = LED_OFF;
- if (fext_leds(fujitsu_laptop->handle, 0x2, ECO_LED, 0x0) & ECO_LED_ON)
+ if (fext_leds(handle, 0x2, ECO_LED, 0x0) & ECO_LED_ON)
brightness = LED_FULL;
return brightness;
}
-static struct led_classdev eco_led = {
- .name = "fujitsu::eco_led",
- .brightness_set_blocking = eco_led_set,
- .brightness_get = eco_led_get
-};
-
static int acpi_fujitsu_laptop_leds_register(struct acpi_device *device)
{
+ struct fujitsu_laptop *priv = acpi_driver_data(device);
+ struct led_classdev *led;
int result;
- if (fext_leds(fujitsu_laptop->handle,
- 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) {
- result = devm_led_classdev_register(&device->dev,
- &logolamp_led);
+ if (fext_leds(priv->handle, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) {
+ led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
+ led->name = "fujitsu::logolamp";
+ led->brightness_set_blocking = logolamp_set;
+ led->brightness_get = logolamp_get;
+ result = devm_led_classdev_register(&device->dev, led);
if (result)
return result;
}
- if ((fext_leds(fujitsu_laptop->handle,
- 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) &&
- (fext_buttons(fujitsu_laptop->handle, 0x0, 0x0, 0x0) == 0x0)) {
- result = devm_led_classdev_register(&device->dev, &kblamps_led);
+ if ((fext_leds(priv->handle, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) &&
+ (fext_buttons(priv->handle, 0x0, 0x0, 0x0) == 0x0)) {
+ led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
+ led->name = "fujitsu::kblamps";
+ led->brightness_set_blocking = kblamps_set;
+ led->brightness_get = kblamps_get;
+ result = devm_led_classdev_register(&device->dev, led);
if (result)
return result;
}
@@ -784,8 +769,13 @@ static int acpi_fujitsu_laptop_leds_register(struct acpi_device *device)
* to also have an RF LED. Therefore use bit 24 as an indicator
* that an RF LED is present.
*/
- if (fext_buttons(fujitsu_laptop->handle, 0x0, 0x0, 0x0) & BIT(24)) {
- result = devm_led_classdev_register(&device->dev, &radio_led);
+ if (fext_buttons(priv->handle, 0x0, 0x0, 0x0) & BIT(24)) {
+ led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
+ led->name = "fujitsu::radio_led";
+ led->brightness_set_blocking = radio_led_set;
+ led->brightness_get = radio_led_get;
+ led->default_trigger = "rfkill-any";
+ result = devm_led_classdev_register(&device->dev, led);
if (result)
return result;
}
@@ -795,10 +785,13 @@ static int acpi_fujitsu_laptop_leds_register(struct acpi_device *device)
* bit 14 seems to indicate presence of said led as well.
* Confirm by testing the status.
*/
- if ((fext_leds(fujitsu_laptop->handle, 0x0, 0x0, 0x0) & BIT(14)) &&
- (fext_leds(fujitsu_laptop->handle,
- 0x2, ECO_LED, 0x0) != UNSUPPORTED_CMD)) {
- result = devm_led_classdev_register(&device->dev, &eco_led);
+ if ((fext_leds(priv->handle, 0x0, 0x0, 0x0) & BIT(14)) &&
+ (fext_leds(priv->handle, 0x2, ECO_LED, 0x0) != UNSUPPORTED_CMD)) {
+ led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
+ led->name = "fujitsu::eco_led";
+ led->brightness_set_blocking = eco_led_set;
+ led->brightness_get = eco_led_get;
+ result = devm_led_classdev_register(&device->dev, led);
if (result)
return result;
}
--
2.12.2
next prev parent reply other threads:[~2017-04-24 13:35 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-24 13:33 [PATCH 00/10] fujitsu-laptop: use device-specific data instead of module-wide globals Michał Kępień
2017-04-24 13:33 ` [PATCH 01/10] platform/x86: fujitsu-laptop: introduce fext_*() helper functions Michał Kępień
2017-05-01 13:13 ` Jonathan Woithe
2017-05-02 13:24 ` Michał Kępień
2017-04-24 13:33 ` [PATCH 02/10] platform/x86: fujitsu-laptop: shorten names of acpi_handle fields Michał Kępień
2017-05-01 13:19 ` Jonathan Woithe
2017-05-01 16:09 ` Darren Hart
2017-04-24 13:33 ` [PATCH 03/10] platform/x86: fujitsu-laptop: explicitly pass ACPI handle to call_fext_func() Michał Kępień
2017-04-24 13:33 ` [PATCH 04/10] platform/x86: fujitsu-laptop: rework backlight power synchronization Michał Kępień
2017-05-01 13:32 ` Jonathan Woithe
2017-05-01 16:17 ` Darren Hart
2017-04-24 13:33 ` [PATCH 05/10] platform/x86: fujitsu-laptop: distinguish current uses of device-specific data Michał Kępień
2017-05-01 13:40 ` Jonathan Woithe
2017-04-24 13:33 ` [PATCH 06/10] platform/x86: fujitsu-laptop: allocate struct fujitsu_bl in acpi_fujitsu_bl_add() Michał Kępień
2017-04-24 13:33 ` [PATCH 07/10] platform/x86: fujitsu-laptop: use device-specific data in backlight code Michał Kępień
2017-04-24 13:33 ` [PATCH 08/10] platform/x86: fujitsu-laptop: allocate struct fujitsu_laptop in acpi_fujitsu_laptop_add() Michał Kępień
2017-04-24 13:33 ` Michał Kępień [this message]
2017-04-24 13:33 ` [PATCH 10/10] platform/x86: fujitsu-laptop: use device-specific data in remaining module code Michał Kępień
2017-05-01 13:05 ` [PATCH 00/10] fujitsu-laptop: use device-specific data instead of module-wide globals Jonathan Woithe
2017-05-02 13:21 ` Michał Kępień
2017-05-04 23:40 ` Jonathan Woithe
2017-05-05 16:15 ` Darren Hart
2017-05-06 12:31 ` Michał Kępień
2017-05-06 12:45 ` Michał Kępień
2017-05-06 14:21 ` Andy Shevchenko
2017-05-06 14:23 ` Andy Shevchenko
2017-05-08 16:01 ` Darren Hart
2017-05-09 9:35 ` Michał Kępień
2017-05-09 12:13 ` Jonathan Woithe
2017-05-09 16:47 ` Darren Hart
2017-05-09 21:24 ` Rafael J. Wysocki
2017-05-11 13:52 ` Michał Kępień
2017-05-11 14:37 ` Rafael J. Wysocki
2017-05-11 15:38 ` Darren Hart
2017-05-11 13:40 ` Michał Kępień
2017-05-15 23:27 ` Darren Hart
2017-05-16 0:06 ` Jonathan Woithe
2017-05-16 6:40 ` Michał Kępień
2017-05-15 23:56 ` Jonathan Woithe
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=20170424133334.7064-10-kernel@kempniu.pl \
--to=kernel@kempniu.pl \
--cc=andy@infradead.org \
--cc=dvhart@infradead.org \
--cc=jwoithe@just42.net \
--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).