Merge branch 'for-rc-5.11' of git://git.kernel.org/pub/scm/linux/kernel/git/pavel/linux-leds

Pull LED fixes from Pavel Machek:
"This pull is due to 'leds: trigger: fix potential deadlock with
libata' -- people find the warn annoying.

It also contains new driver and two trivial fixes"

* 'for-rc-5.11' of git://git.kernel.org/pub/scm/linux/kernel/git/pavel/linux-leds:
leds: rt8515: Add Richtek RT8515 LED driver
dt-bindings: leds: Add DT binding for Richtek RT8515
leds: trigger: fix potential deadlock with libata
leds: leds-ariel: convert comma to semicolon
leds: leds-lm3533: convert comma to semicolon

+542 -8
+111
Documentation/devicetree/bindings/leds/richtek,rt8515.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/leds/richtek,rt8515.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Richtek RT8515 1.5A dual channel LED driver 8 + 9 + maintainers: 10 + - Linus Walleij <linus.walleij@linaro.org> 11 + 12 + description: | 13 + The Richtek RT8515 is a dual channel (two mode) LED driver that 14 + supports driving a white LED in flash or torch mode. The maximum 15 + current for each mode is defined in hardware using two resistors 16 + RFS and RTS. 17 + 18 + properties: 19 + compatible: 20 + const: richtek,rt8515 21 + 22 + enf-gpios: 23 + maxItems: 1 24 + description: A connection to the 'ENF' (enable flash) pin. 25 + 26 + ent-gpios: 27 + maxItems: 1 28 + description: A connection to the 'ENT' (enable torch) pin. 29 + 30 + richtek,rfs-ohms: 31 + minimum: 7680 32 + maximum: 367000 33 + description: The resistance value of the RFS resistor. This 34 + resistors limits the maximum flash current. This must be set 35 + for the property flash-max-microamp to work, the RFS resistor 36 + defines the range of the dimmer setting (brightness) of the 37 + flash LED. 38 + 39 + richtek,rts-ohms: 40 + minimum: 7680 41 + maximum: 367000 42 + description: The resistance value of the RTS resistor. This 43 + resistors limits the maximum torch current. This must be set 44 + for the property torch-max-microamp to work, the RTS resistor 45 + defines the range of the dimmer setting (brightness) of the 46 + torch LED. 47 + 48 + led: 49 + type: object 50 + $ref: common.yaml# 51 + properties: 52 + function: true 53 + color: true 54 + flash-max-timeout-us: true 55 + 56 + flash-max-microamp: 57 + maximum: 700000 58 + description: The maximum current for flash mode 59 + is hardwired to the component using the RFS resistor to 60 + ground. The maximum hardware current setting is calculated 61 + according to the formula Imax = 5500 / RFS. The lowest 62 + allowed resistance value is 7.86 kOhm giving an absolute 63 + maximum current of 700mA. By setting this attribute in 64 + the device tree, you can further restrict the maximum 65 + current below the hardware limit. This requires the RFS 66 + to be defined as it defines the maximum range. 67 + 68 + led-max-microamp: 69 + maximum: 700000 70 + description: The maximum current for torch mode 71 + is hardwired to the component using the RTS resistor to 72 + ground. The maximum hardware current setting is calculated 73 + according to the formula Imax = 5500 / RTS. The lowest 74 + allowed resistance value is 7.86 kOhm giving an absolute 75 + maximum current of 700mA. By setting this attribute in 76 + the device tree, you can further restrict the maximum 77 + current below the hardware limit. This requires the RTS 78 + to be defined as it defines the maximum range. 79 + 80 + additionalProperties: false 81 + 82 + required: 83 + - compatible 84 + - ent-gpios 85 + - enf-gpios 86 + - led 87 + 88 + additionalProperties: false 89 + 90 + examples: 91 + - | 92 + #include <dt-bindings/gpio/gpio.h> 93 + #include <dt-bindings/leds/common.h> 94 + 95 + led-controller { 96 + compatible = "richtek,rt8515"; 97 + enf-gpios = <&gpio4 12 GPIO_ACTIVE_HIGH>; 98 + ent-gpios = <&gpio4 13 GPIO_ACTIVE_HIGH>; 99 + richtek,rfs-ohms = <16000>; 100 + richtek,rts-ohms = <100000>; 101 + 102 + led { 103 + function = LED_FUNCTION_FLASH; 104 + color = <LED_COLOR_ID_WHITE>; 105 + flash-max-timeout-us = <250000>; 106 + flash-max-microamp = <150000>; 107 + led-max-microamp = <25000>; 108 + }; 109 + }; 110 + 111 + ...
+3
drivers/leds/Kconfig
··· 928 928 This option enables support for the Power Button LED of 929 929 Acer Iconia Tab A500. 930 930 931 + comment "Flash and Torch LED drivers" 932 + source "drivers/leds/flash/Kconfig" 933 + 931 934 comment "LED Triggers" 932 935 source "drivers/leds/trigger/Kconfig" 933 936
+3
drivers/leds/Makefile
··· 103 103 # LED Userspace Drivers 104 104 obj-$(CONFIG_LEDS_USER) += uleds.o 105 105 106 + # Flash and Torch LED Drivers 107 + obj-$(CONFIG_LEDS_CLASS_FLASH) += flash/ 108 + 106 109 # LED Triggers 107 110 obj-$(CONFIG_LEDS_TRIGGERS) += trigger/
+15
drivers/leds/flash/Kconfig
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + 3 + if LEDS_CLASS_FLASH 4 + 5 + config LEDS_RT8515 6 + tristate "LED support for Richtek RT8515 flash/torch LED" 7 + depends on GPIOLIB 8 + help 9 + This option enables support for the Richtek RT8515 flash 10 + and torch LEDs found on some mobile phones. 11 + 12 + To compile this driver as a module, choose M here: the module 13 + will be called leds-rt8515. 14 + 15 + endif # LEDS_CLASS_FLASH
+3
drivers/leds/flash/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + 3 + obj-$(CONFIG_LEDS_RT8515) += leds-rt8515.o
+397
drivers/leds/flash/leds-rt8515.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * LED driver for Richtek RT8515 flash/torch white LEDs 4 + * found on some Samsung mobile phones. 5 + * 6 + * This is a 1.5A Boost dual channel driver produced around 2011. 7 + * 8 + * The component lacks a datasheet, but in the schematic picture 9 + * from the LG P970 service manual you can see the connections 10 + * from the RT8515 to the LED, with two resistors connected 11 + * from the pins "RFS" and "RTS" to ground. 12 + * 13 + * On the LG P970: 14 + * RFS (resistance flash setting?) is 20 kOhm 15 + * RTS (resistance torch setting?) is 39 kOhm 16 + * 17 + * Some sleuthing finds us the RT9387A which we have a datasheet for: 18 + * https://static5.arrow.com/pdfs/2014/7/27/8/21/12/794/rtt_/manual/94download_ds.jspprt9387a.jspprt9387a.pdf 19 + * This apparently works the same way so in theory this driver 20 + * should cover RT9387A as well. This has not been tested, please 21 + * update the compatibles if you add RT9387A support. 22 + * 23 + * Linus Walleij <linus.walleij@linaro.org> 24 + */ 25 + #include <linux/delay.h> 26 + #include <linux/err.h> 27 + #include <linux/gpio/consumer.h> 28 + #include <linux/led-class-flash.h> 29 + #include <linux/mod_devicetable.h> 30 + #include <linux/module.h> 31 + #include <linux/platform_device.h> 32 + #include <linux/property.h> 33 + #include <linux/regulator/consumer.h> 34 + 35 + #include <media/v4l2-flash-led-class.h> 36 + 37 + /* We can provide 15-700 mA out to the LED */ 38 + #define RT8515_MIN_IOUT_MA 15 39 + #define RT8515_MAX_IOUT_MA 700 40 + /* The maximum intensity is 1-16 for flash and 1-100 for torch */ 41 + #define RT8515_FLASH_MAX 16 42 + #define RT8515_TORCH_MAX 100 43 + 44 + #define RT8515_TIMEOUT_US 250000U 45 + #define RT8515_MAX_TIMEOUT_US 300000U 46 + 47 + struct rt8515 { 48 + struct led_classdev_flash fled; 49 + struct device *dev; 50 + struct v4l2_flash *v4l2_flash; 51 + struct mutex lock; 52 + struct regulator *reg; 53 + struct gpio_desc *enable_torch; 54 + struct gpio_desc *enable_flash; 55 + struct timer_list powerdown_timer; 56 + u32 max_timeout; /* Flash max timeout */ 57 + int flash_max_intensity; 58 + int torch_max_intensity; 59 + }; 60 + 61 + static struct rt8515 *to_rt8515(struct led_classdev_flash *fled) 62 + { 63 + return container_of(fled, struct rt8515, fled); 64 + } 65 + 66 + static void rt8515_gpio_led_off(struct rt8515 *rt) 67 + { 68 + gpiod_set_value(rt->enable_flash, 0); 69 + gpiod_set_value(rt->enable_torch, 0); 70 + } 71 + 72 + static void rt8515_gpio_brightness_commit(struct gpio_desc *gpiod, 73 + int brightness) 74 + { 75 + int i; 76 + 77 + /* 78 + * Toggling a GPIO line with a small delay increases the 79 + * brightness one step at a time. 80 + */ 81 + for (i = 0; i < brightness; i++) { 82 + gpiod_set_value(gpiod, 0); 83 + udelay(1); 84 + gpiod_set_value(gpiod, 1); 85 + udelay(1); 86 + } 87 + } 88 + 89 + /* This is setting the torch light level */ 90 + static int rt8515_led_brightness_set(struct led_classdev *led, 91 + enum led_brightness brightness) 92 + { 93 + struct led_classdev_flash *fled = lcdev_to_flcdev(led); 94 + struct rt8515 *rt = to_rt8515(fled); 95 + 96 + mutex_lock(&rt->lock); 97 + 98 + if (brightness == LED_OFF) { 99 + /* Off */ 100 + rt8515_gpio_led_off(rt); 101 + } else if (brightness < RT8515_TORCH_MAX) { 102 + /* Step it up to movie mode brightness using the flash pin */ 103 + rt8515_gpio_brightness_commit(rt->enable_torch, brightness); 104 + } else { 105 + /* Max torch brightness requested */ 106 + gpiod_set_value(rt->enable_torch, 1); 107 + } 108 + 109 + mutex_unlock(&rt->lock); 110 + 111 + return 0; 112 + } 113 + 114 + static int rt8515_led_flash_strobe_set(struct led_classdev_flash *fled, 115 + bool state) 116 + { 117 + struct rt8515 *rt = to_rt8515(fled); 118 + struct led_flash_setting *timeout = &fled->timeout; 119 + int brightness = rt->flash_max_intensity; 120 + 121 + mutex_lock(&rt->lock); 122 + 123 + if (state) { 124 + /* Enable LED flash mode and set brightness */ 125 + rt8515_gpio_brightness_commit(rt->enable_flash, brightness); 126 + /* Set timeout */ 127 + mod_timer(&rt->powerdown_timer, 128 + jiffies + usecs_to_jiffies(timeout->val)); 129 + } else { 130 + del_timer_sync(&rt->powerdown_timer); 131 + /* Turn the LED off */ 132 + rt8515_gpio_led_off(rt); 133 + } 134 + 135 + fled->led_cdev.brightness = LED_OFF; 136 + /* After this the torch LED will be disabled */ 137 + 138 + mutex_unlock(&rt->lock); 139 + 140 + return 0; 141 + } 142 + 143 + static int rt8515_led_flash_strobe_get(struct led_classdev_flash *fled, 144 + bool *state) 145 + { 146 + struct rt8515 *rt = to_rt8515(fled); 147 + 148 + *state = timer_pending(&rt->powerdown_timer); 149 + 150 + return 0; 151 + } 152 + 153 + static int rt8515_led_flash_timeout_set(struct led_classdev_flash *fled, 154 + u32 timeout) 155 + { 156 + /* The timeout is stored in the led-class-flash core */ 157 + return 0; 158 + } 159 + 160 + static const struct led_flash_ops rt8515_flash_ops = { 161 + .strobe_set = rt8515_led_flash_strobe_set, 162 + .strobe_get = rt8515_led_flash_strobe_get, 163 + .timeout_set = rt8515_led_flash_timeout_set, 164 + }; 165 + 166 + static void rt8515_powerdown_timer(struct timer_list *t) 167 + { 168 + struct rt8515 *rt = from_timer(rt, t, powerdown_timer); 169 + 170 + /* Turn the LED off */ 171 + rt8515_gpio_led_off(rt); 172 + } 173 + 174 + static void rt8515_init_flash_timeout(struct rt8515 *rt) 175 + { 176 + struct led_classdev_flash *fled = &rt->fled; 177 + struct led_flash_setting *s; 178 + 179 + /* Init flash timeout setting */ 180 + s = &fled->timeout; 181 + s->min = 1; 182 + s->max = rt->max_timeout; 183 + s->step = 1; 184 + /* 185 + * Set default timeout to RT8515_TIMEOUT_US except if 186 + * max_timeout from DT is lower. 187 + */ 188 + s->val = min(rt->max_timeout, RT8515_TIMEOUT_US); 189 + } 190 + 191 + #if IS_ENABLED(CONFIG_V4L2_FLASH_LED_CLASS) 192 + /* Configure the V2L2 flash subdevice */ 193 + static void rt8515_init_v4l2_flash_config(struct rt8515 *rt, 194 + struct v4l2_flash_config *v4l2_sd_cfg) 195 + { 196 + struct led_classdev *led = &rt->fled.led_cdev; 197 + struct led_flash_setting *s; 198 + 199 + strscpy(v4l2_sd_cfg->dev_name, led->dev->kobj.name, 200 + sizeof(v4l2_sd_cfg->dev_name)); 201 + 202 + /* 203 + * Init flash intensity setting: this is a linear scale 204 + * capped from the device tree max intensity setting 205 + * 1..flash_max_intensity 206 + */ 207 + s = &v4l2_sd_cfg->intensity; 208 + s->min = 1; 209 + s->max = rt->flash_max_intensity; 210 + s->step = 1; 211 + s->val = s->max; 212 + } 213 + 214 + static void rt8515_v4l2_flash_release(struct rt8515 *rt) 215 + { 216 + v4l2_flash_release(rt->v4l2_flash); 217 + } 218 + 219 + #else 220 + static void rt8515_init_v4l2_flash_config(struct rt8515 *rt, 221 + struct v4l2_flash_config *v4l2_sd_cfg) 222 + { 223 + } 224 + 225 + static void rt8515_v4l2_flash_release(struct rt8515 *rt) 226 + { 227 + } 228 + #endif 229 + 230 + static void rt8515_determine_max_intensity(struct rt8515 *rt, 231 + struct fwnode_handle *led, 232 + const char *resistance, 233 + const char *max_ua_prop, int hw_max, 234 + int *max_intensity_setting) 235 + { 236 + u32 res = 0; /* Can't be 0 so 0 is undefined */ 237 + u32 ua; 238 + u32 max_ma; 239 + int max_intensity; 240 + int ret; 241 + 242 + fwnode_property_read_u32(rt->dev->fwnode, resistance, &res); 243 + ret = fwnode_property_read_u32(led, max_ua_prop, &ua); 244 + 245 + /* Missing info in DT, OK go with hardware maxima */ 246 + if (ret || res == 0) { 247 + dev_err(rt->dev, 248 + "either %s or %s missing from DT, using HW max\n", 249 + resistance, max_ua_prop); 250 + max_ma = RT8515_MAX_IOUT_MA; 251 + max_intensity = hw_max; 252 + goto out_assign_max; 253 + } 254 + 255 + /* 256 + * Formula from the datasheet, this is the maximum current 257 + * defined by the hardware. 258 + */ 259 + max_ma = (5500 * 1000) / res; 260 + /* 261 + * Calculate max intensity (linear scaling) 262 + * Formula is ((ua / 1000) / max_ma) * 100, then simplified 263 + */ 264 + max_intensity = (ua / 10) / max_ma; 265 + 266 + dev_info(rt->dev, 267 + "current restricted from %u to %u mA, max intensity %d/100\n", 268 + max_ma, (ua / 1000), max_intensity); 269 + 270 + out_assign_max: 271 + dev_info(rt->dev, "max intensity %d/%d = %d mA\n", 272 + max_intensity, hw_max, max_ma); 273 + *max_intensity_setting = max_intensity; 274 + } 275 + 276 + static int rt8515_probe(struct platform_device *pdev) 277 + { 278 + struct device *dev = &pdev->dev; 279 + struct fwnode_handle *child; 280 + struct rt8515 *rt; 281 + struct led_classdev *led; 282 + struct led_classdev_flash *fled; 283 + struct led_init_data init_data = {}; 284 + struct v4l2_flash_config v4l2_sd_cfg = {}; 285 + int ret; 286 + 287 + rt = devm_kzalloc(dev, sizeof(*rt), GFP_KERNEL); 288 + if (!rt) 289 + return -ENOMEM; 290 + 291 + rt->dev = dev; 292 + fled = &rt->fled; 293 + led = &fled->led_cdev; 294 + 295 + /* ENF - Enable Flash line */ 296 + rt->enable_flash = devm_gpiod_get(dev, "enf", GPIOD_OUT_LOW); 297 + if (IS_ERR(rt->enable_flash)) 298 + return dev_err_probe(dev, PTR_ERR(rt->enable_flash), 299 + "cannot get ENF (enable flash) GPIO\n"); 300 + 301 + /* ENT - Enable Torch line */ 302 + rt->enable_torch = devm_gpiod_get(dev, "ent", GPIOD_OUT_LOW); 303 + if (IS_ERR(rt->enable_torch)) 304 + return dev_err_probe(dev, PTR_ERR(rt->enable_torch), 305 + "cannot get ENT (enable torch) GPIO\n"); 306 + 307 + child = fwnode_get_next_available_child_node(dev->fwnode, NULL); 308 + if (!child) { 309 + dev_err(dev, 310 + "No fwnode child node found for connected LED.\n"); 311 + return -EINVAL; 312 + } 313 + init_data.fwnode = child; 314 + 315 + rt8515_determine_max_intensity(rt, child, "richtek,rfs-ohms", 316 + "flash-max-microamp", 317 + RT8515_FLASH_MAX, 318 + &rt->flash_max_intensity); 319 + rt8515_determine_max_intensity(rt, child, "richtek,rts-ohms", 320 + "led-max-microamp", 321 + RT8515_TORCH_MAX, 322 + &rt->torch_max_intensity); 323 + 324 + ret = fwnode_property_read_u32(child, "flash-max-timeout-us", 325 + &rt->max_timeout); 326 + if (ret) { 327 + rt->max_timeout = RT8515_MAX_TIMEOUT_US; 328 + dev_warn(dev, 329 + "flash-max-timeout-us property missing\n"); 330 + } 331 + timer_setup(&rt->powerdown_timer, rt8515_powerdown_timer, 0); 332 + rt8515_init_flash_timeout(rt); 333 + 334 + fled->ops = &rt8515_flash_ops; 335 + 336 + led->max_brightness = rt->torch_max_intensity; 337 + led->brightness_set_blocking = rt8515_led_brightness_set; 338 + led->flags |= LED_CORE_SUSPENDRESUME | LED_DEV_CAP_FLASH; 339 + 340 + mutex_init(&rt->lock); 341 + 342 + platform_set_drvdata(pdev, rt); 343 + 344 + ret = devm_led_classdev_flash_register_ext(dev, fled, &init_data); 345 + if (ret) { 346 + dev_err(dev, "can't register LED %s\n", led->name); 347 + mutex_destroy(&rt->lock); 348 + return ret; 349 + } 350 + 351 + rt8515_init_v4l2_flash_config(rt, &v4l2_sd_cfg); 352 + 353 + /* Create a V4L2 Flash device if V4L2 flash is enabled */ 354 + rt->v4l2_flash = v4l2_flash_init(dev, child, fled, NULL, &v4l2_sd_cfg); 355 + if (IS_ERR(rt->v4l2_flash)) { 356 + ret = PTR_ERR(rt->v4l2_flash); 357 + dev_err(dev, "failed to register V4L2 flash device (%d)\n", 358 + ret); 359 + /* 360 + * Continue without the V4L2 flash 361 + * (we still have the classdev) 362 + */ 363 + } 364 + 365 + return 0; 366 + } 367 + 368 + static int rt8515_remove(struct platform_device *pdev) 369 + { 370 + struct rt8515 *rt = platform_get_drvdata(pdev); 371 + 372 + rt8515_v4l2_flash_release(rt); 373 + del_timer_sync(&rt->powerdown_timer); 374 + mutex_destroy(&rt->lock); 375 + 376 + return 0; 377 + } 378 + 379 + static const struct of_device_id rt8515_match[] = { 380 + { .compatible = "richtek,rt8515", }, 381 + { /* sentinel */ } 382 + }; 383 + MODULE_DEVICE_TABLE(of, rt8515_match); 384 + 385 + static struct platform_driver rt8515_driver = { 386 + .driver = { 387 + .name = "rt8515", 388 + .of_match_table = rt8515_match, 389 + }, 390 + .probe = rt8515_probe, 391 + .remove = rt8515_remove, 392 + }; 393 + module_platform_driver(rt8515_driver); 394 + 395 + MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>"); 396 + MODULE_DESCRIPTION("Richtek RT8515 LED driver"); 397 + MODULE_LICENSE("GPL");
+6 -4
drivers/leds/led-triggers.c
··· 378 378 enum led_brightness brightness) 379 379 { 380 380 struct led_classdev *led_cdev; 381 + unsigned long flags; 381 382 382 383 if (!trig) 383 384 return; 384 385 385 - read_lock(&trig->leddev_list_lock); 386 + read_lock_irqsave(&trig->leddev_list_lock, flags); 386 387 list_for_each_entry(led_cdev, &trig->led_cdevs, trig_list) 387 388 led_set_brightness(led_cdev, brightness); 388 - read_unlock(&trig->leddev_list_lock); 389 + read_unlock_irqrestore(&trig->leddev_list_lock, flags); 389 390 } 390 391 EXPORT_SYMBOL_GPL(led_trigger_event); 391 392 ··· 397 396 int invert) 398 397 { 399 398 struct led_classdev *led_cdev; 399 + unsigned long flags; 400 400 401 401 if (!trig) 402 402 return; 403 403 404 - read_lock(&trig->leddev_list_lock); 404 + read_lock_irqsave(&trig->leddev_list_lock, flags); 405 405 list_for_each_entry(led_cdev, &trig->led_cdevs, trig_list) { 406 406 if (oneshot) 407 407 led_blink_set_oneshot(led_cdev, delay_on, delay_off, ··· 410 408 else 411 409 led_blink_set(led_cdev, delay_on, delay_off); 412 410 } 413 - read_unlock(&trig->leddev_list_lock); 411 + read_unlock_irqrestore(&trig->leddev_list_lock, flags); 414 412 } 415 413 416 414 void led_trigger_blink(struct led_trigger *trig,
+3 -3
drivers/leds/leds-ariel.c
··· 96 96 return -ENOMEM; 97 97 98 98 leds[0].ec_index = EC_BLUE_LED; 99 - leds[0].led_cdev.name = "blue:power", 99 + leds[0].led_cdev.name = "blue:power"; 100 100 leds[0].led_cdev.default_trigger = "default-on"; 101 101 102 102 leds[1].ec_index = EC_AMBER_LED; 103 - leds[1].led_cdev.name = "amber:status", 103 + leds[1].led_cdev.name = "amber:status"; 104 104 105 105 leds[2].ec_index = EC_GREEN_LED; 106 - leds[2].led_cdev.name = "green:status", 106 + leds[2].led_cdev.name = "green:status"; 107 107 leds[2].led_cdev.default_trigger = "default-on"; 108 108 109 109 for (i = 0; i < NLEDS; i++) {
+1 -1
drivers/leds/leds-lm3533.c
··· 679 679 led->cdev.brightness_get = lm3533_led_get; 680 680 led->cdev.blink_set = lm3533_led_blink_set; 681 681 led->cdev.brightness = LED_OFF; 682 - led->cdev.groups = lm3533_led_attribute_groups, 682 + led->cdev.groups = lm3533_led_attribute_groups; 683 683 led->id = pdev->id; 684 684 685 685 mutex_init(&led->mutex);