Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20240509141207.63570-2-hdegoede@redhat.com

+47
+47
drivers/platform/x86/x86-android-tablets/other.c
··· 11 11 #include <linux/acpi.h> 12 12 #include <linux/gpio/machine.h> 13 13 #include <linux/input.h> 14 + #include <linux/leds.h> 14 15 #include <linux/platform_device.h> 16 + #include <linux/pwm.h> 15 17 16 18 #include <dt-bindings/leds/common.h> 17 19 ··· 664 662 NULL 665 663 }; 666 664 665 + /* 666 + * For the LEDs which backlight the menu / home / back capacitive buttons on 667 + * the bottom bezel. These are attached to a TPS61158 LED controller which 668 + * is controlled by the "pwm_soc_lpss_2" PWM output. 669 + */ 670 + #define XIAOMI_MIPAD2_LED_PERIOD_NS 19200 671 + #define XIAOMI_MIPAD2_LED_DEFAULT_DUTY 6000 /* From Android kernel */ 672 + 673 + static struct pwm_device *xiaomi_mipad2_led_pwm; 674 + 675 + static int xiaomi_mipad2_brightness_set(struct led_classdev *led_cdev, 676 + enum led_brightness val) 677 + { 678 + struct pwm_state state = { 679 + .period = XIAOMI_MIPAD2_LED_PERIOD_NS, 680 + .duty_cycle = val, 681 + /* Always set PWM enabled to avoid the pin floating */ 682 + .enabled = true, 683 + }; 684 + 685 + return pwm_apply_might_sleep(xiaomi_mipad2_led_pwm, &state); 686 + } 687 + 667 688 static int __init xiaomi_mipad2_init(struct device *dev) 668 689 { 690 + struct led_classdev *led_cdev; 691 + int ret; 692 + 693 + xiaomi_mipad2_led_pwm = devm_pwm_get(dev, "pwm_soc_lpss_2"); 694 + if (IS_ERR(xiaomi_mipad2_led_pwm)) 695 + return dev_err_probe(dev, PTR_ERR(xiaomi_mipad2_led_pwm), "getting pwm\n"); 696 + 697 + led_cdev = devm_kzalloc(dev, sizeof(*led_cdev), GFP_KERNEL); 698 + if (!led_cdev) 699 + return -ENOMEM; 700 + 701 + led_cdev->name = "mipad2:white:touch-buttons-backlight"; 702 + led_cdev->max_brightness = XIAOMI_MIPAD2_LED_PERIOD_NS; 703 + /* "input-events" trigger uses blink_brightness */ 704 + led_cdev->blink_brightness = XIAOMI_MIPAD2_LED_DEFAULT_DUTY; 705 + led_cdev->default_trigger = "input-events"; 706 + led_cdev->brightness_set_blocking = xiaomi_mipad2_brightness_set; 707 + 708 + ret = devm_led_classdev_register(dev, led_cdev); 709 + if (ret) 710 + return dev_err_probe(dev, ret, "registering LED\n"); 711 + 669 712 return software_node_register_node_group(ktd2026_node_group); 670 713 } 671 714