From 047da762b9a937d60c16e2c8392c326e5ab11a1d Mon Sep 17 00:00:00 2001 From: Yauhen Kharuzhy Date: Sun, 30 Apr 2023 21:59:48 +0200 Subject: leds: Add Intel Cherry Trail Whiskey Cove PMIC LED driver Add support for LEDs connected to the Intel Cherry Trail Whiskey Cove PMIC. Charger and general-purpose LEDs are supported. Hardware blinking is implemented, breathing is not. This driver was tested with Lenovo Yoga Book notebook. Changes by Hans de Goede (in response to review of v2): - Since the PMIC is connected to the battery any changes we make to the LED settings are permanent, even surviving reboot / poweroff. Save LED1 register settings on probe() and if auto-/hw-control was enabled on probe() restore the settings on remove() and shutdown(). - Delay switching LED1 to software control mode to first brightness write. - Use dynamically allocated drvdata instead of a global drvdata variable. - Ensure the LED is on when activating blinking. - Fix CHT_WC_LED_EFF_BREATHING val ((3 << 1) rather then BIT(3)). Link: https://lore.kernel.org/r/20190212205901.13037-2-jekhor@gmail.com Signed-off-by: Yauhen Kharuzhy Co-developed-by: Hans de Goede Signed-off-by: Hans de Goede Link: https://lore.kernel.org/r/20230430195952.862527-2-hdegoede@redhat.com Signed-off-by: Lee Jones --- Documentation/leds/well-known-leds.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Documentation/leds') diff --git a/Documentation/leds/well-known-leds.txt b/Documentation/leds/well-known-leds.txt index e9c30dc75884..326172ca4b62 100644 --- a/Documentation/leds/well-known-leds.txt +++ b/Documentation/leds/well-known-leds.txt @@ -65,7 +65,7 @@ Phones usually have multi-color status LED. * Power management -Good: "platform:*:charging" (allwinner sun50i) +Good: "platform:*:charging" (allwinner sun50i, leds-cht-wcove) * Screen -- cgit v1.2.3 From 5b916aa755551058c0e88e45a8c7db31d7718d59 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Sun, 30 Apr 2023 21:59:50 +0200 Subject: leds: cht-wcove: Add support for breathing mode use hw_pattern sysfs API The hw-blinking of the LED controller in the Whiskey Cove PMIC can also be used for a hw-breathing effect. As discussed during review of v2 of the submission of the new leds-cht-wcove driver, the LED subsystem already supports breathing mode on several other LED controllers using the hw_pattern interface. Implement a pattern_set callback to implement breathing mode modelled after the breathing mode supported by the SC27xx breathing light and Crane EL15203000 LED drivers. The Whiskey Cove PMIC's breathing mode is closer to the EL15203000 one then to the SC27xx one since it does not support staying high / low for a specific time, it only supports rise and fall times. As such the supported hw_pattern and the documentation for this is almost a 1:1 copy of the pattern/docs for the EL15203000 breathing mode. Suggested-by: Jacek Anaszewski Link: https://lore.kernel.org/all/6beed61c-1fc6-6525-e873-a8978f5fbffb@gmail.com/ Signed-off-by: Hans de Goede Link: https://lore.kernel.org/r/20230430195952.862527-4-hdegoede@redhat.com Signed-off-by: Lee Jones --- Documentation/leds/index.rst | 1 + Documentation/leds/leds-cht-wcove.rst | 38 +++++++++++++++++++++++++++++++ drivers/leds/leds-cht-wcove.c | 42 +++++++++++++++++++++++++++++++---- 3 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 Documentation/leds/leds-cht-wcove.rst (limited to 'Documentation/leds') diff --git a/Documentation/leds/index.rst b/Documentation/leds/index.rst index ce57254cb871..3ade16c18328 100644 --- a/Documentation/leds/index.rst +++ b/Documentation/leds/index.rst @@ -17,6 +17,7 @@ LEDs uleds leds-blinkm + leds-cht-wcove leds-el15203000 leds-lm3556 leds-lp3944 diff --git a/Documentation/leds/leds-cht-wcove.rst b/Documentation/leds/leds-cht-wcove.rst new file mode 100644 index 000000000000..5ec7cb60c4aa --- /dev/null +++ b/Documentation/leds/leds-cht-wcove.rst @@ -0,0 +1,38 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=========================================================== +Kernel driver for Intel Cherry Trail Whiskey Cove PMIC LEDs +=========================================================== + +/sys/class/leds//hw_pattern +-------------------------------- + +Specify a hardware pattern for the Whiskey Cove PMIC LEDs. + +The only supported pattern is hardware breathing mode:: + + "0 2000 1 2000" + + ^ + | + Max-| --- + | / \ + | / \ + | / \ / + | / \ / + Min-|- --- + | + 0------2------4--> time (sec) + +The rise and fall times must be the same value. +Supported values are 2000, 1000, 500 and 250 for +breathing frequencies of 1/4, 1/2, 1 and 2 Hz. + +The set pattern only controls the timing. For max brightness the last +set brightness is used and the max brightness can be changed +while breathing by writing the brightness attribute. + +This is just like how blinking works in the LED subsystem, +for both sw and hw blinking the brightness can also be changed +while blinking. Breathing on this hw really is just a variant +mode of blinking. diff --git a/drivers/leds/leds-cht-wcove.c b/drivers/leds/leds-cht-wcove.c index 166b140e132a..36fb4c2c3c13 100644 --- a/drivers/leds/leds-cht-wcove.c +++ b/drivers/leds/leds-cht-wcove.c @@ -217,9 +217,10 @@ static int cht_wc_leds_find_freq(unsigned long period) return -1; } -static int cht_wc_leds_blink_set(struct led_classdev *cdev, - unsigned long *delay_on, - unsigned long *delay_off) +static int cht_wc_leds_set_effect(struct led_classdev *cdev, + unsigned long *delay_on, + unsigned long *delay_off, + u8 effect) { struct cht_wc_led *led = container_of(cdev, struct cht_wc_led, cdev); unsigned int ctrl; @@ -246,7 +247,7 @@ static int cht_wc_leds_blink_set(struct led_classdev *cdev, } ret = regmap_update_bits(led->regmap, led->regs->fsm, - CHT_WC_LED_EFF_MASK, CHT_WC_LED_EFF_BLINKING); + CHT_WC_LED_EFF_MASK, effect); if (ret < 0) dev_err(cdev->dev, "Failed to update LED FSM reg: %d\n", ret); @@ -265,6 +266,37 @@ done: return ret; } +static int cht_wc_leds_blink_set(struct led_classdev *cdev, + unsigned long *delay_on, + unsigned long *delay_off) +{ + return cht_wc_leds_set_effect(cdev, delay_on, delay_off, CHT_WC_LED_EFF_BLINKING); +} + +static int cht_wc_leds_pattern_set(struct led_classdev *cdev, + struct led_pattern *pattern, + u32 len, int repeat) +{ + unsigned long delay_off, delay_on; + + if (repeat > 0 || len != 2 || + pattern[0].brightness != 0 || pattern[1].brightness != 1 || + pattern[0].delta_t != pattern[1].delta_t || + (pattern[0].delta_t != 250 && pattern[0].delta_t != 500 && + pattern[0].delta_t != 1000 && pattern[0].delta_t != 2000)) + return -EINVAL; + + delay_off = pattern[0].delta_t; + delay_on = pattern[1].delta_t; + + return cht_wc_leds_set_effect(cdev, &delay_on, &delay_off, CHT_WC_LED_EFF_BREATHING); +} + +static int cht_wc_leds_pattern_clear(struct led_classdev *cdev) +{ + return cht_wc_leds_brightness_set(cdev, 0); +} + static int cht_wc_led_save_regs(struct cht_wc_led *led, struct cht_wc_led_saved_regs *saved_regs) { @@ -329,6 +361,8 @@ static int cht_wc_leds_probe(struct platform_device *pdev) led->cdev.brightness_set_blocking = cht_wc_leds_brightness_set; led->cdev.brightness_get = cht_wc_leds_brightness_get; led->cdev.blink_set = cht_wc_leds_blink_set; + led->cdev.pattern_set = cht_wc_leds_pattern_set; + led->cdev.pattern_clear = cht_wc_leds_pattern_clear; led->cdev.max_brightness = 255; ret = led_classdev_register(&pdev->dev, &led->cdev); -- cgit v1.2.3 From ece1f480a49e7d1ce57ec7eb7b847321206d0db0 Mon Sep 17 00:00:00 2001 From: Luca Weiss Date: Tue, 23 May 2023 22:41:30 +0200 Subject: Documentation: leds: Add "rgb:status" path The path /sys/class/leds/rgb:status is already widely used with the qcom-lpg driver and others. Document it. Signed-off-by: Luca Weiss Link: https://lore.kernel.org/r/20230414-pmi632-v3-3-079d2cada699@z3ntu.xyz Signed-off-by: Lee Jones --- Documentation/leds/well-known-leds.txt | 1 + 1 file changed, 1 insertion(+) (limited to 'Documentation/leds') diff --git a/Documentation/leds/well-known-leds.txt b/Documentation/leds/well-known-leds.txt index 326172ca4b62..67b44704801f 100644 --- a/Documentation/leds/well-known-leds.txt +++ b/Documentation/leds/well-known-leds.txt @@ -58,6 +58,7 @@ LEDs on notebook body, indicating that sound input / output is muted. * System notification +Good: "rgb:status" Legacy: "status-led:{red,green,blue}" (Motorola Droid 4) Legacy: "lp5523:{r,g,b}" (Nokia N900) -- cgit v1.2.3