From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Hans de Goede <hdegoede@redhat.com>
Cc: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Thierry Reding" <thierry.reding@gmail.com>,
"Yauhen Kharuzhy" <jekhor@gmail.com>,
platform-driver-x86@vger.kernel.org, linux-pwm@vger.kernel.org
Subject: Re: [PATCH v2 18/19] platform/x86: lenovo-yogabook: Add keyboard backlight control to platform driver
Date: Thu, 4 May 2023 18:53:07 +0200 [thread overview]
Message-ID: <20230504165307.tydqlk6sml7sp5qe@pengutronix.de> (raw)
In-Reply-To: <20230430165807.472798-19-hdegoede@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 3950 bytes --]
Hello,
On Sun, Apr 30, 2023 at 06:58:06PM +0200, Hans de Goede wrote:
> On the Android yb1-x90f/l models there is not ACPI method to control
> the keyboard backlight brightness. Instead the second PWM controller
> is exposed directly to the OS there.
>
> Add support for controlling keyboard backlight brightness on the Android
> model by using the PWM subsystem to directly control the PWM.
>
> The Android model also requires explicitly turning the backlight off
> on suspend, which on the Windows model was done automatically.
>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> Changes in v2:
> - Use YB_KBD_BL_PWM_PERIOD define in yogabook_pdev_pwm_lookup[]
> - Turn off keyboard backlight on suspend
> ---
> drivers/platform/x86/lenovo-yogabook-wmi.c | 31 +++++++++++++++++++++-
> 1 file changed, 30 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/platform/x86/lenovo-yogabook-wmi.c b/drivers/platform/x86/lenovo-yogabook-wmi.c
> index 0183b75a47e8..b49109d91ec3 100644
> --- a/drivers/platform/x86/lenovo-yogabook-wmi.c
> +++ b/drivers/platform/x86/lenovo-yogabook-wmi.c
> @@ -19,6 +19,7 @@
> #include <linux/leds.h>
> #include <linux/module.h>
> #include <linux/platform_device.h>
> +#include <linux/pwm.h>
> #include <linux/wmi.h>
> #include <linux/workqueue.h>
>
> @@ -26,6 +27,7 @@
>
> #define YB_KBD_BL_DEFAULT 128
> #define YB_KBD_BL_MAX 255
> +#define YB_KBD_BL_PWM_PERIOD 13333
>
> #define YB_PDEV_NAME "yogabook-touch-kbd-digitizer-switch"
>
> @@ -48,6 +50,7 @@ struct yogabook_data {
> struct gpio_desc *pen_touch_event;
> struct gpio_desc *kbd_bl_led_enable;
> struct gpio_desc *backside_hall_gpio;
> + struct pwm_device *kbd_bl_pwm;
> int (*set_kbd_backlight)(struct yogabook_data *data, uint8_t level);
> int pen_touch_irq;
> int backside_hall_irq;
> @@ -267,8 +270,11 @@ static int yogabook_suspend(struct device *dev)
> struct yogabook_data *data = dev_get_drvdata(dev);
>
> set_bit(YB_SUSPENDED, &data->flags);
> -
> flush_work(&data->work);
> +
> + if (test_bit(YB_KBD_IS_ON, &data->flags))
> + data->set_kbd_backlight(data, 0);
> +
> return 0;
> }
>
> @@ -424,8 +430,21 @@ static struct gpiod_lookup_table yogabook_pdev_gpios = {
> },
> };
>
> +static struct pwm_lookup yogabook_pdev_pwm_lookup[] = {
> + PWM_LOOKUP_WITH_MODULE("80862289:00", 0, YB_PDEV_NAME, "kbd_bl_pwm",
> + YB_KBD_BL_PWM_PERIOD, PWM_POLARITY_NORMAL,
> + "pwm-lpss-platform"),
> +};
> +
> static int yogabook_pdev_set_kbd_backlight(struct yogabook_data *data, u8 level)
> {
> + struct pwm_state state = {
> + .period = YB_KBD_BL_PWM_PERIOD,
> + .duty_cycle = YB_KBD_BL_PWM_PERIOD * level / YB_KBD_BL_MAX,
> + .enabled = level,
> + };
> +
> + pwm_apply_state(data->kbd_bl_pwm, &state);
> gpiod_set_value(data->kbd_bl_led_enable, level ? 1 : 0);
> return 0;
> }
> @@ -475,6 +494,16 @@ static int yogabook_pdev_probe(struct platform_device *pdev)
> goto error_put_devs;
> }
>
> + pwm_add_table(yogabook_pdev_pwm_lookup, ARRAY_SIZE(yogabook_pdev_pwm_lookup));
> + data->kbd_bl_pwm = devm_pwm_get(dev, "kbd_bl_pwm");
> + pwm_remove_table(yogabook_pdev_pwm_lookup, ARRAY_SIZE(yogabook_pdev_pwm_lookup));
Keeping the table added just long enough to call devm_pwm_get() looks
very creative to me. Why don't you keep the table around while the
device is available? Also note that a given table must only ever be
added once using pwm_add_table(). If there happen to be two yogabook
devices and .probe() is called a second time, the list of tables might
be corrupted.
I don't know much about x86, but I think the table belongs to where this
"80862289:00" device is created.
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2023-05-04 16:53 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-30 16:57 [PATCH v2 00/19] platform/x86: lenovo-yogabook: Modify to also work on Android version Hans de Goede
2023-04-30 16:57 ` [PATCH v2 01/19] pwm: Export pwm_add_table() / pwm_remove_table() Hans de Goede
2023-04-30 16:57 ` [PATCH v2 02/19] platform/x86: lenovo-yogabook: Fix work race on remove() Hans de Goede
2023-04-30 16:57 ` [PATCH v2 03/19] platform/x86: lenovo-yogabook: Reprobe devices " Hans de Goede
2023-04-30 16:57 ` [PATCH v2 04/19] platform/x86: lenovo-yogabook: Set default keyboard backligh brightness on probe() Hans de Goede
2023-04-30 16:57 ` [PATCH v2 05/19] platform/x86: lenovo-yogabook: Simplify gpio lookup table cleanup Hans de Goede
2023-04-30 16:57 ` [PATCH v2 06/19] platform/x86: lenovo-yogabook: Switch to DEFINE_SIMPLE_DEV_PM_OPS() Hans de Goede
2023-04-30 16:57 ` [PATCH v2 07/19] platform/x86: lenovo-yogabook: Store dev instead of wdev in drvdata struct Hans de Goede
2023-04-30 16:57 ` [PATCH v2 08/19] platform/x86: lenovo-yogabook: Add dev local variable to probe() Hans de Goede
2023-04-30 16:57 ` [PATCH v2 09/19] platform/x86: lenovo-yogabook: Use PMIC LED driver for pen icon LED control Hans de Goede
2023-04-30 16:57 ` [PATCH v2 10/19] platform/x86: lenovo-yogabook: Split probe() into generic and WMI specific parts Hans de Goede
2023-05-01 9:53 ` Andy Shevchenko
2023-05-09 10:32 ` Hans de Goede
2023-04-30 16:57 ` [PATCH v2 11/19] platform/x86: lenovo-yogabook: Stop checking adev->power.state Hans de Goede
2023-04-30 16:58 ` [PATCH v2 12/19] platform/x86: lenovo-yogabook: Abstract kbd backlight setting Hans de Goede
2023-04-30 16:58 ` [PATCH v2 13/19] platform/x86: lenovo-yogabook: Add a yogabook_toggle_digitizer_mode() helper function Hans de Goede
2023-04-30 16:58 ` [PATCH v2 14/19] platform/x86: lenovo-yogabook: Drop _wmi_ from remaining generic symbols Hans de Goede
2023-04-30 16:58 ` [PATCH v2 15/19] platform/x86: lenovo-yogabook: Group WMI specific code together Hans de Goede
2023-04-30 16:58 ` [PATCH v2 16/19] platform/x86: lenovo-yogabook: Add YB_KBD_BL_MAX define Hans de Goede
2023-04-30 16:58 ` [PATCH v2 17/19] platform/x86: lenovo-yogabook: Add platform driver support Hans de Goede
2023-04-30 16:58 ` [PATCH v2 18/19] platform/x86: lenovo-yogabook: Add keyboard backlight control to platform driver Hans de Goede
2023-05-04 16:53 ` Uwe Kleine-König [this message]
2023-05-05 9:07 ` Andy Shevchenko
2023-05-05 9:21 ` Uwe Kleine-König
2023-05-05 11:43 ` Andy Shevchenko
2023-05-06 11:26 ` Hans de Goede
2023-05-09 10:39 ` Hans de Goede
2023-04-30 16:58 ` [PATCH v2 19/19] platform/x86: lenovo-yogabook: Rename lenovo-yogabook-wmi to lenovo-yogabook Hans de Goede
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=20230504165307.tydqlk6sml7sp5qe@pengutronix.de \
--to=u.kleine-koenig@pengutronix.de \
--cc=andy@kernel.org \
--cc=hdegoede@redhat.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jekhor@gmail.com \
--cc=linux-pwm@vger.kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
--cc=thierry.reding@gmail.com \
/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