Skip to content

Commit 9426adb

Browse files
committed
platform/x86: x86-android-tablets: Create LED device for Xiaomi Pad 2 bottom bezel touch buttons
The Xiaomi [Mi]Pad 2 has 3 menu / home / back capacitive touch-buttons on its bottom bezel. These are backlit by LEDs attached to a TPS61158 LED controller which is controlled by the "pwm_soc_lpss_2" PWM output. Create a LED class device for this, using the new input-events trigger as default trigger so that the buttons automatically light up on any input activity. Note alternatively a "leds_pwm" platform device could be created together with the necessary fwnode_s_ and a fwnode link to the PWM controller. There are 2 downsides to this approach: 1. The code would still need to pwm_get() the PWM controller to get/attach a fwnode for the PWM controller fwnode link and setting up the necessary fwnodes is non-trivial. So this would likely require more code then simply registering the LED class device directly. 2. Currently the leds_pwm driver and its devicetree bindings do not support limiting the maximum dutycycle to less then 100% which is required in this case (the leds_pwm driver can probably be extended to allow this). Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Hans de Goede <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 0b57e2e commit 9426adb

File tree

1 file changed

+47
-0
lines changed
  • drivers/platform/x86/x86-android-tablets

1 file changed

+47
-0
lines changed

drivers/platform/x86/x86-android-tablets/other.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
#include <linux/acpi.h>
1212
#include <linux/gpio/machine.h>
1313
#include <linux/input.h>
14+
#include <linux/leds.h>
1415
#include <linux/platform_device.h>
16+
#include <linux/pwm.h>
1517

1618
#include <dt-bindings/leds/common.h>
1719

@@ -662,8 +664,53 @@ static const struct software_node *ktd2026_node_group[] = {
662664
NULL
663665
};
664666

667+
/*
668+
* For the LEDs which backlight the menu / home / back capacitive buttons on
669+
* the bottom bezel. These are attached to a TPS61158 LED controller which
670+
* is controlled by the "pwm_soc_lpss_2" PWM output.
671+
*/
672+
#define XIAOMI_MIPAD2_LED_PERIOD_NS 19200
673+
#define XIAOMI_MIPAD2_LED_DEFAULT_DUTY 6000 /* From Android kernel */
674+
675+
static struct pwm_device *xiaomi_mipad2_led_pwm;
676+
677+
static int xiaomi_mipad2_brightness_set(struct led_classdev *led_cdev,
678+
enum led_brightness val)
679+
{
680+
struct pwm_state state = {
681+
.period = XIAOMI_MIPAD2_LED_PERIOD_NS,
682+
.duty_cycle = val,
683+
/* Always set PWM enabled to avoid the pin floating */
684+
.enabled = true,
685+
};
686+
687+
return pwm_apply_might_sleep(xiaomi_mipad2_led_pwm, &state);
688+
}
689+
665690
static int __init xiaomi_mipad2_init(struct device *dev)
666691
{
692+
struct led_classdev *led_cdev;
693+
int ret;
694+
695+
xiaomi_mipad2_led_pwm = devm_pwm_get(dev, "pwm_soc_lpss_2");
696+
if (IS_ERR(xiaomi_mipad2_led_pwm))
697+
return dev_err_probe(dev, PTR_ERR(xiaomi_mipad2_led_pwm), "getting pwm\n");
698+
699+
led_cdev = devm_kzalloc(dev, sizeof(*led_cdev), GFP_KERNEL);
700+
if (!led_cdev)
701+
return -ENOMEM;
702+
703+
led_cdev->name = "mipad2:white:touch-buttons-backlight";
704+
led_cdev->max_brightness = XIAOMI_MIPAD2_LED_PERIOD_NS;
705+
/* "input-events" trigger uses blink_brightness */
706+
led_cdev->blink_brightness = XIAOMI_MIPAD2_LED_DEFAULT_DUTY;
707+
led_cdev->default_trigger = "input-events";
708+
led_cdev->brightness_set_blocking = xiaomi_mipad2_brightness_set;
709+
710+
ret = devm_led_classdev_register(dev, led_cdev);
711+
if (ret)
712+
return dev_err_probe(dev, ret, "registering LED\n");
713+
667714
return software_node_register_node_group(ktd2026_node_group);
668715
}
669716

0 commit comments

Comments
 (0)