diff options
-rw-r--r-- | Documentation/acpi/dsd/leds.txt | 99 | ||||
-rw-r--r-- | Documentation/devicetree/bindings/leds/leds-lm3532.txt | 101 | ||||
-rw-r--r-- | Documentation/devicetree/bindings/mfd/ti-lmu.txt | 20 | ||||
-rw-r--r-- | arch/arm/boot/dts/omap4-droid4-xt894.dts | 27 | ||||
-rw-r--r-- | drivers/leds/Kconfig | 33 | ||||
-rw-r--r-- | drivers/leds/Makefile | 1 | ||||
-rw-r--r-- | drivers/leds/led-class.c | 1 | ||||
-rw-r--r-- | drivers/leds/led-core.c | 5 | ||||
-rw-r--r-- | drivers/leds/leds-as3645a.c | 93 | ||||
-rw-r--r-- | drivers/leds/leds-blinkm.c | 1 | ||||
-rw-r--r-- | drivers/leds/leds-lm3532.c | 683 | ||||
-rw-r--r-- | drivers/leds/leds-lt3593.c | 64 | ||||
-rw-r--r-- | drivers/leds/leds-pca955x.c | 57 | ||||
-rw-r--r-- | drivers/leds/leds-pca963x.c | 66 | ||||
-rw-r--r-- | drivers/mfd/ti-lmu.c | 11 | ||||
-rw-r--r-- | include/linux/mfd/ti-lmu-register.h | 44 | ||||
-rw-r--r-- | include/linux/mfd/ti-lmu.h | 1 | ||||
-rw-r--r-- | sound/usb/line6/toneport.c | 8 |
18 files changed, 1023 insertions, 292 deletions
diff --git a/Documentation/acpi/dsd/leds.txt b/Documentation/acpi/dsd/leds.txt new file mode 100644 index 000000000000..81a63af42ed2 --- /dev/null +++ b/Documentation/acpi/dsd/leds.txt @@ -0,0 +1,99 @@ +Describing and referring to LEDs in ACPI + +Individual LEDs are described by hierarchical data extension [6] nodes under the +device node, the LED driver chip. The "reg" property in the LED specific nodes +tells the numerical ID of each individual LED output to which the LEDs are +connected. [3] The hierarchical data nodes are named "led@X", where X is the +number of the LED output. + +Referring to LEDs in Device tree is documented in [4], in "flash-leds" property +documentation. In short, LEDs are directly referred to by using phandles. + +While Device tree allows referring to any node in the tree[1], in ACPI +references are limited to device nodes only [2]. For this reason using the same +mechanism on ACPI is not possible. A mechanism to refer to non-device ACPI nodes +is documented in [7]. + +ACPI allows (as does DT) using integer arguments after the reference. A +combination of the LED driver device reference and an integer argument, +referring to the "reg" property of the relevant LED, is used to identify +individual LEDs. The value of the "reg" property is a contract between the +firmware and software, it uniquely identifies the LED driver outputs. + +Under the LED driver device, The first hierarchical data extension package list +entry shall contain the string "led@" followed by the number of the LED, +followed by the referred object name. That object shall be named "LED" followed +by the number of the LED. + +An ASL example of a camera sensor device and a LED driver device for two LEDs. +Objects not relevant for LEDs or the references to them have been omitted. + + Device (LED) + { + Name (_DSD, Package () { + ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"), + Package () { + Package () { "led@0", LED0 }, + Package () { "led@1", LED1 }, + } + }) + Name (LED0, Package () { + ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), + Package () { + Package () { "reg", 0 }, + Package () { "flash-max-microamp", 1000000 }, + Package () { "flash-timeout-us", 200000 }, + Package () { "led-max-microamp", 100000 }, + Package () { "label", "white:flash" }, + } + }) + Name (LED1, Package () { + ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), + Package () { + Package () { "reg", 1 }, + Package () { "led-max-microamp", 10000 }, + Package () { "label", "red:indicator" }, + } + }) + } + + Device (SEN) + { + Name (_DSD, Package () { + ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), + Package () { + Package () { + "flash-leds", + Package () { ^LED, "led@0", ^LED, "led@1" }, + } + } + }) + } + +where + + LED LED driver device + LED0 First LED + LED1 Second LED + SEN Camera sensor device (or another device the LED is + related to) + +[1] Device tree. <URL:http://www.devicetree.org>, referenced 2019-02-21. + +[2] Advanced Configuration and Power Interface Specification. + <URL:https://uefi.org/sites/default/files/resources/ACPI_6_3_final_Jan30.pdf>, + referenced 2019-02-21. + +[3] Documentation/devicetree/bindings/leds/common.txt + +[4] Documentation/devicetree/bindings/media/video-interfaces.txt + +[5] Device Properties UUID For _DSD. + <URL:http://www.uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf>, + referenced 2019-02-21. + +[6] Hierarchical Data Extension UUID For _DSD. + <URL:http://www.uefi.org/sites/default/files/resources/_DSD-hierarchical-data-extension-UUID-v1.1.pdf>, + referenced 2019-02-21. + +[7] Documentation/acpi/dsd/data-node-reference.txt diff --git a/Documentation/devicetree/bindings/leds/leds-lm3532.txt b/Documentation/devicetree/bindings/leds/leds-lm3532.txt new file mode 100644 index 000000000000..c087f85ddddc --- /dev/null +++ b/Documentation/devicetree/bindings/leds/leds-lm3532.txt @@ -0,0 +1,101 @@ +* Texas Instruments - lm3532 White LED driver with ambient light sensing +capability. + +The LM3532 provides the 3 high-voltage, low-side current sinks. The device is +programmable over an I2C-compatible interface and has independent +current control for all three channels. The adaptive current regulation +method allows for different LED currents in each current sink thus allowing +for a wide variety of backlight and keypad applications. + +The main features of the LM3532 include dual ambient light sensor inputs +each with 32 internal voltage setting resistors, 8-bit logarithmic and linear +brightness control, dual external PWM brightness control inputs, and up to +1000:1 dimming ratio with programmable fade in and fade out settings. + +Required properties: + - compatible : "ti,lm3532" + - reg : I2C slave address + - #address-cells : 1 + - #size-cells : 0 + +Optional properties: + - enable-gpios : gpio pin to enable (active high)/disable the device. + - ramp-up-us - The Run time ramp rates/step are from one current + set-point to another after the device has reached its + initial target set point from turn-on + - ramp-down-us - The Run time ramp rates/step are from one current + set-point to another after the device has reached its + initial target set point from turn-on + Range for ramp settings: 8us - 65536us + +Optional properties if ALS mode is used: + - ti,als-vmin - Minimum ALS voltage defined in Volts + - ti,als-vmax - Maximum ALS voltage defined in Volts + Per the data sheet the max ALS voltage is 2V and the min is 0V + + - ti,als1-imp-sel - ALS1 impedance resistor selection in Ohms + - ti,als2-imp-sel - ALS2 impedance resistor selection in Ohms + Range for impedance select: 37000 Ohms - 1190 Ohms + Values above 37kohms will be set to the "High Impedance" setting + + - ti,als-avrg-time-us - Determines the length of time the device needs to + average the two ALS inputs. This is only used if + the input mode is LM3532_ALS_INPUT_AVRG. + Range: 17920us - 2293760us + - ti,als-input-mode - Determines how the device uses the attached ALS + devices. + 0x00 - ALS1 and ALS2 input average + 0x01 - ALS1 Input + 0x02 - ALS2 Input + 0x03 - Max of ALS1 and ALS2 + +Required child properties: + - reg : Indicates control bank the LED string is controlled by + - led-sources : see Documentation/devicetree/bindings/leds/common.txt + - ti,led-mode : Defines if the LED strings are manually controlled or + if the LED strings are controlled by the ALS. + 0x00 - LED strings are I2C controlled via full scale + brightness control register + 0x01 - LED strings are ALS controlled + +Optional LED child properties: + - label : see Documentation/devicetree/bindings/leds/common.txt + - linux,default-trigger : + see Documentation/devicetree/bindings/leds/common.txt + +Example: +led-controller@38 { + compatible = "ti,lm3532"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x38>; + + enable-gpios = <&gpio6 12 GPIO_ACTIVE_HIGH>; + ramp-up-us = <1024>; + ramp-down-us = <65536>; + + ti,als-vmin = <0>; + ti,als-vmax = <2000>; + ti,als1-imp-sel = <4110>; + ti,als2-imp-sel = <2180>; + ti,als-avrg-time-us = <17920>; + ti,als-input-mode = <0x00>; + + led@0 { + reg = <0>; + led-sources = <2>; + ti,led-mode = <1>; + label = ":backlight"; + linux,default-trigger = "backlight"; + }; + + led@1 { + reg = <1>; + led-sources = <1>; + ti,led-mode = <0>; + label = ":kbd_backlight"; + }; +}; + +For more product information please see the links below: +http://www.ti.com/product/LM3532 diff --git a/Documentation/devicetree/bindings/mfd/ti-lmu.txt b/Documentation/devicetree/bindings/mfd/ti-lmu.txt index c885cf89b8ce..980394d701a7 100644 --- a/Documentation/devicetree/bindings/mfd/ti-lmu.txt +++ b/Documentation/devicetree/bindings/mfd/ti-lmu.txt @@ -4,7 +4,6 @@ TI LMU driver supports lighting devices below. Name Child nodes ------ --------------------------------- - LM3532 Backlight LM3631 Backlight and regulator LM3632 Backlight and regulator LM3633 Backlight, LED and fault monitor @@ -13,7 +12,6 @@ TI LMU driver supports lighting devices below. Required properties: - compatible: Should be one of: - "ti,lm3532" "ti,lm3631" "ti,lm3632" "ti,lm3633" @@ -23,7 +21,6 @@ Required properties: 0x11 for LM3632 0x29 for LM3631 0x36 for LM3633, LM3697 - 0x38 for LM3532 0x63 for LM3695 Optional property: @@ -47,23 +44,6 @@ Optional nodes: [2] ../leds/leds-lm3633.txt [3] ../regulator/lm363x-regulator.txt -lm3532@38 { - compatible = "ti,lm3532"; - reg = <0x38>; - - enable-gpios = <&pioC 2 GPIO_ACTIVE_HIGH>; - - backlight { - compatible = "ti,lm3532-backlight"; - - lcd { - led-sources = <0 1 2>; - ramp-up-msec = <30>; - ramp-down-msec = <0>; - }; - }; -}; - lm3631@29 { compatible = "ti,lm3631"; reg = <0x29>; diff --git a/arch/arm/boot/dts/omap4-droid4-xt894.dts b/arch/arm/boot/dts/omap4-droid4-xt894.dts index e21ec929f096..714863f8f261 100644 --- a/arch/arm/boot/dts/omap4-droid4-xt894.dts +++ b/arch/arm/boot/dts/omap4-droid4-xt894.dts @@ -214,7 +214,6 @@ width-mm = <50>; height-mm = <89>; - backlight = <&lcd_backlight>; panel-timing { clock-frequency = <0>; /* Calculated by dsi */ @@ -383,20 +382,30 @@ }; &i2c1 { - lm3532@38 { + led-controller@38 { compatible = "ti,lm3532"; + #address-cells = <1>; + #size-cells = <0>; reg = <0x38>; enable-gpios = <&gpio6 12 GPIO_ACTIVE_HIGH>; - lcd_backlight: backlight { - compatible = "ti,lm3532-backlight"; + ramp-up-us = <1024>; + ramp-down-us = <8193>; - lcd { - led-sources = <0 1 2>; - ramp-up-msec = <1>; - ramp-down-msec = <0>; - }; + led@0 { + reg = <0>; + led-sources = <2>; + ti,led-mode = <0>; + label = ":backlight"; + linux,default-trigger = "backlight"; + }; + + led@1 { + reg = <1>; + led-sources = <1>; + ti,led-mode = <0>; + label = ":kbd_backlight"; }; }; }; diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index a72f97fca57b..f3000ccb8d35 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -23,8 +23,8 @@ config LEDS_CLASS_FLASH tristate "LED Flash Class Support" depends on LEDS_CLASS help - This option enables the flash led sysfs class in /sys/class/leds. - It wrapps LED Class and adds flash LEDs specific sysfs attributes + This option enables the flash LED sysfs class in /sys/class/leds. + It wraps LED Class and adds flash LEDs specific sysfs attributes and kernel internal API to it. You'll need this to provide support for the flash related features of a LED device. It can be built as a module. @@ -56,7 +56,7 @@ config LEDS_AAT1290 depends on OF depends on PINCTRL help - This option enables support for the LEDs on the AAT1290. + This option enables support for the LEDs on the AAT1290. config LEDS_AN30259A tristate "LED support for Panasonic AN30259A" @@ -138,6 +138,16 @@ config LEDS_LM3530 controlled manually or using PWM input or using ambient light automatically. +config LEDS_LM3532 + tristate "LCD Backlight driver for LM3532" + depends on LEDS_CLASS + depends on I2C + help + This option enables support for the LCD backlight using + LM3532 ambient light sensor chip. This ALS chip can be + controlled manually or using PWM input or using ambient + light automatically. + config LEDS_LM3533 tristate "LED support for LM3533" depends on LEDS_CLASS @@ -413,13 +423,13 @@ config LEDS_CLEVO_MAIL This module can drive the mail LED for the following notebooks: - Clevo D400P - Clevo D410J - Clevo D410V - Clevo D400V/D470V (not tested, but might work) - Clevo M540N - Clevo M5x0N (not tested, but might work) - Positivo Mobile (Clevo M5x0V) + Clevo D400P + Clevo D410J + Clevo D410V + Clevo D400V/D470V (not tested, but might work) + Clevo M540N + Clevo M5x0N (not tested, but might work) + Positivo Mobile (Clevo M5x0V) If your model is not listed here you can try the "nodetect" module parameter. @@ -462,7 +472,7 @@ config LEDS_WM831X_STATUS depends on MFD_WM831X help This option enables support for the status LEDs of the WM831x - series of PMICs. + series of PMICs. config LEDS_WM8350 tristate "LED Support for WM8350 AudioPlus PMIC" @@ -533,6 +543,7 @@ config LEDS_LT3593 tristate "LED driver for LT3593 controllers" depends on LEDS_CLASS depends on GPIOLIB || COMPILE_TEST + depends on OF help This option enables support for LEDs driven by a Linear Technology LT3593 controller. This controller uses a special one-wire pulse diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index 4c1b0054f379..7a8b1f55d459 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -18,6 +18,7 @@ obj-$(CONFIG_LEDS_BD2802) += leds-bd2802.o obj-$(CONFIG_LEDS_CPCAP) += leds-cpcap.o obj-$(CONFIG_LEDS_LOCOMO) += leds-locomo.o obj-$(CONFIG_LEDS_LM3530) += leds-lm3530.o +obj-$(CONFIG_LEDS_LM3532) += leds-lm3532.o obj-$(CONFIG_LEDS_LM3533) += leds-lm3533.o obj-$(CONFIG_LEDS_LM3642) += leds-lm3642.o obj-$(CONFIG_LEDS_MIKROTIK_RB532) += leds-rb532.o diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index 3c7e3487b373..85848c5da705 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -57,6 +57,7 @@ static ssize_t brightness_store(struct device *dev, if (state == LED_OFF) led_trigger_remove(led_cdev); led_set_brightness(led_cdev, state); + flush_work(&led_cdev->set_brightness_work); ret = size; unlock: diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c index e3da7c03da1b..e9ae7f87ab90 100644 --- a/drivers/leds/led-core.c +++ b/drivers/leds/led-core.c @@ -164,6 +164,11 @@ static void led_blink_setup(struct led_classdev *led_cdev, unsigned long *delay_on, unsigned long *delay_off) { + /* + * If "set brightness to 0" is pending in workqueue, we don't + * want that to be reordered after blink_set() + */ + flush_work(&led_cdev->set_brightness_work); if (!test_bit(LED_BLINK_ONESHOT, &led_cdev->work_flags) && led_cdev->blink_set && !led_cdev->blink_set(led_cdev, delay_on, delay_off)) diff --git a/drivers/leds/leds-as3645a.c b/drivers/leds/leds-as3645a.c index 98a69b1a43f9..b0df514992e1 100644 --- a/drivers/leds/leds-as3645a.c +++ b/drivers/leds/leds-as3645a.c @@ -25,7 +25,7 @@ #include <linux/leds.h> #include <linux/module.h> #include <linux/mutex.h> -#include <linux/of.h> +#include <linux/property.h> #include <linux/slab.h> #include <media/v4l2-flash-led-class.h> @@ -148,8 +148,8 @@ struct as3645a { struct v4l2_flash *vf; struct v4l2_flash *vfind; - struct device_node *flash_node; - struct device_node *indicator_node; + struct fwnode_handle *flash_node; + struct fwnode_handle *indicator_node; struct as3645a_config cfg; @@ -493,30 +493,31 @@ static int as3645a_detect(struct as3645a *flash) static int as3645a_parse_node(struct as3645a *flash, struct as3645a_names *names, - struct device_node *node) + struct fwnode_handle *fwnode) { struct as3645a_config *cfg = &flash->cfg; - struct device_node *child; + struct fwnode_handle *child; const char *name; int rval; - for_each_child_of_node(node, child) { + fwnode_for_each_child_node(fwnode, child) { u32 id = 0; - of_property_read_u32(child, "reg", &id); + fwnode_property_read_u32(child, "reg", &id); switch (id) { case AS_LED_FLASH: - flash->flash_node = of_node_get(child); + flash->flash_node = child; break; case AS_LED_INDICATOR: - flash->indicator_node = of_node_get(child); + flash->indicator_node = child; break; default: dev_warn(&flash->client->dev, "unknown LED %u encountered, ignoring\n", id); break; } + fwnode_handle_get(child); } if (!flash->flash_node) { @@ -524,42 +525,46 @@ static int as3645a_parse_node(struct as3645a *flash, return -ENODEV; } - rval = of_property_read_string(flash->flash_node, "label", &name); - if (!rval) + rval = fwnode_property_read_string(flash->flash_node, "label", &name); + if (!rval) { strlcpy(names->flash, name, sizeof(names->flash)); - else + } else if (is_of_node(fwnode)) { snprintf(names->flash, sizeof(names->flash), - "%pOFn:flash", node); + "%pOFn:flash", to_of_node(fwnode)); + } else { + dev_err(&flash->client->dev, "flash node has no label!\n"); + return -EINVAL; + } - rval = of_property_read_u32(flash->flash_node, "flash-timeout-us", - &cfg->flash_timeout_us); + rval = fwnode_property_read_u32(flash->flash_node, "flash-timeout-us", + &cfg->flash_timeout_us); if (rval < 0) { dev_err(&flash->client->dev, "can't read flash-timeout-us property for flash\n"); goto out_err; } - rval = of_property_read_u32(flash->flash_node, "flash-max-microamp", - &cfg->flash_max_ua); + rval = fwnode_property_read_u32(flash->flash_node, "flash-max-microamp", + &cfg->flash_max_ua); if (rval < 0) { dev_err(&flash->client->dev, "can't read flash-max-microamp property for flash\n"); goto out_err; } - rval = of_property_read_u32(flash->flash_node, "led-max-microamp", - &cfg->assist_max_ua); + rval = fwnode_property_read_u32(flash->flash_node, "led-max-microamp", + &cfg->assist_max_ua); if (rval < 0) { dev_err(&flash->client->dev, "can't read led-max-microamp property for flash\n"); goto out_err; } - of_property_read_u32(flash->flash_node, "voltage-reference", - &cfg->voltage_reference); + fwnode_property_read_u32(flash->flash_node, "voltage-reference", + &cfg->voltage_reference); - of_property_read_u32(flash->flash_node, "ams,input-max-microamp", - &cfg->peak); + fwnode_property_read_u32(flash->flash_node, "ams,input-max-microamp", + &cfg->peak); cfg->peak = AS_PEAK_mA_TO_REG(cfg->peak); if (!flash->indicator_node) { @@ -568,15 +573,21 @@ static int as3645a_parse_node(struct as3645a *flash, goto out_err; } - rval = of_property_read_string(flash->indicator_node, "label", &name); - if (!rval) + rval = fwnode_property_read_string(flash->indicator_node, "label", + &name); + if (!rval) { strlcpy(names->indicator, name, sizeof(names->indicator)); - else + } else if (is_of_node(fwnode)) { snprintf(names->indicator, sizeof(names->indicator), - "%pOFn:indicator", node); + "%pOFn:indicator", to_of_node(fwnode)); + } else { + dev_err(&flash->client->dev, "indicator node has no label!\n"); + return -EINVAL; + } - rval = of_property_read_u32(flash->indicator_node, "led-max-microamp", - &cfg->indicator_max_ua); + rval = fwnode_property_read_u32(flash->indicator_node, + "led-max-microamp", + &cfg->indicator_max_ua); if (rval < 0) { dev_err(&flash->client->dev, "can't read led-max-microamp property for indicator\n"); @@ -586,8 +597,8 @@ static int as3645a_parse_node(struct as3645a *flash, return 0; out_err: - of_node_put(flash->flash_node); - of_node_put(flash->indicator_node); + fwnode_handle_put(flash->flash_node); + fwnode_handle_put(flash->indicator_node); return rval; } @@ -668,14 +679,14 @@ static int as3645a_v4l2_setup(struct as3645a *flash) strlcpy(cfgind.dev_name, flash->iled_cdev.name, sizeof(cfg.dev_name)); flash->vf = v4l2_flash_init( - &flash->client->dev, of_fwnode_handle(flash->flash_node), - &flash->fled, NULL, &cfg); + &flash->client->dev, flash->flash_node, &flash->fled, NULL, + &cfg); if (IS_ERR(flash->vf)) return PTR_ERR(flash->vf); flash->vfind = v4l2_flash_indicator_init( - &flash->client->dev, of_fwnode_handle(flash->indicator_node), - &flash->iled_cdev, &cfgind); + &flash->client->dev, flash->indicator_node, &flash->iled_cdev, + &cfgind); if (IS_ERR(flash->vfind)) { v4l2_flash_release(flash->vf); return PTR_ERR(flash->vfind); @@ -690,7 +701,7 @@ static int as3645a_probe(struct i2c_client *client) struct as3645a *flash; int rval; - if (client->dev.of_node == NULL) + if (!dev_fwnode(&client->dev)) return -ENODEV; flash = devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL); @@ -699,7 +710,7 @@ static int as3645a_probe(struct i2c_client *client) flash->client = client; - rval = as3645a_parse_node(flash, &names, client->dev.of_node); + rval = as3645a_parse_node(flash, &names, dev_fwnode(&client->dev)); if (rval < 0) return rval; @@ -731,8 +742,8 @@ out_mutex_destroy: mutex_destroy(&flash->mutex); out_put_nodes: - of_node_put(flash->flash_node); - of_node_put(flash->indicator_node); + fwnode_handle_put(flash->flash_node); + fwnode_handle_put(flash->indicator_node); return rval; } @@ -751,8 +762,8 @@ static int as3645a_remove(struct i2c_client *client) mutex_destroy(&flash->mutex); - of_node_put(flash->flash_node); - of_node_put(flash->indicator_node); + fwnode_handle_put(flash->flash_node); + fwnode_handle_put(flash->indicator_node); return 0; } diff --git a/drivers/leds/leds-blinkm.c b/drivers/leds/leds-blinkm.c index 851c1920b63c..11b771fb933b 100644 --- a/drivers/leds/leds-blinkm.c +++ b/drivers/leds/leds-blinkm.c @@ -594,7 +594,6 @@ static int blinkm_probe(struct i2c_client *client, goto exit; } - data->i2c_addr = 0x09; data->i2c_addr = 0x08; /* i2c addr - use fake addr of 0x08 initially (real is 0x09) */ data->fw_ver = 0xfe; diff --git a/drivers/leds/leds-lm3532.c b/drivers/leds/leds-lm3532.c new file mode 100644 index 000000000000..180895b83b88 --- /dev/null +++ b/drivers/leds/leds-lm3532.c @@ -0,0 +1,683 @@ +// SPDX-License-Identifier: GPL-2.0 +// TI LM3532 LED driver +// Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/ + +#include <linux/i2c.h> +#include <linux/leds.h> +#include <linux/slab.h> +#include <linux/regmap.h> +#include <linux/types.h> +#include <linux/regulator/consumer.h> +#include <linux/module.h> +#include <uapi/linux/uleds.h> +#include <linux/gpio/consumer.h> + +#define LM3532_NAME "lm3532-led" +#define LM3532_BL_MODE_MANUAL 0x00 +#define LM3532_BL_MODE_ALS 0x01 + +#define LM3532_REG_OUTPUT_CFG 0x10 +#define LM3532_REG_STARTSHUT_RAMP 0x11 +#define LM3532_REG_RT_RAMP 0x12 +#define LM3532_REG_PWM_A_CFG 0x13 +#define LM3532_REG_PWM_B_CFG 0x14 +#define LM3532_REG_PWM_C_CFG 0x15 +#define LM3532_REG_ZONE_CFG_A 0x16 +#define LM3532_REG_CTRL_A_BRT 0x17 +#define LM3532_REG_ZONE_CFG_B 0x18 +#define LM3532_REG_CTRL_B_BRT 0x19 +#define LM3532_REG_ZONE_CFG_C 0x1a +#define LM3532_REG_CTRL_C_BRT 0x1b +#define LM3532_REG_ENABLE 0x1d +#define LM3532_ALS_CONFIG 0x23 +#define LM3532_REG_ZN_0_HI 0x60 +#define LM3532_REG_ZN_0_LO 0x61 +#define LM3532_REG_ZN_1_HI 0x62 +#define LM3532_REG_ZN_1_LO 0x63 +#define LM3532_REG_ZN_2_HI 0x64 +#define LM3532_REG_ZN_2_LO 0x65 +#define LM3532_REG_ZN_3_HI 0x66 +#define LM3532_REG_ZN_3_LO 0x67 +#define LM3532_REG_MAX 0x7e + +/* Contorl Enable */ +#define LM3532_CTRL_A_ENABLE BIT(0) +#define LM3532_CTRL_B_ENABLE BIT(1) +#define LM3532_CTRL_C_ENABLE BIT(2) + +/* PWM Zone Control */ +#define LM3532_PWM_ZONE_MASK 0x7c +#define LM3532_PWM_ZONE_0_EN BIT(2) +#define LM3532_PWM_ZONE_1_EN BIT(3) +#define LM3532_PWM_ZONE_2_EN BIT(4) +#define LM3532_PWM_ZONE_3_EN BIT(5) +#define LM3532_PWM_ZONE_4_EN BIT(6) + +/* Brightness Configuration */ +#define LM3532_I2C_CTRL BIT(0) +#define LM3532_ALS_CTRL 0 +#define LM3532_LINEAR_MAP BIT(1) +#define LM3532_ZONE_MASK (BIT(2) | BIT(3) | BIT(4)) +#define LM3532_ZONE_0 0 +#define LM3532_ZONE_1 BIT(2) +#define LM3532_ZONE_2 BIT(3) +#define LM3532_ZONE_3 (BIT(2) | BIT(3)) +#define LM3532_ZONE_4 BIT(4) + +#define LM3532_ENABLE_ALS BIT(3) +#define LM3532_ALS_SEL_SHIFT 6 + +/* Zone Boundary Register */ +#define LM3532_ALS_WINDOW_mV 2000 +#define LM3532_ALS_ZB_MAX 4 +#define LM3532_ALS_OFFSET_mV 2 + +#define LM3532_CONTROL_A 0 +#define LM3532_CONTROL_B 1 +#define LM3532_CONTROL_C 2 +#define LM3532_MAX_CONTROL_BANKS 3 +#define LM3532_MAX_LED_STRINGS 3 + +#define LM3532_OUTPUT_CFG_MASK 0x3 +#define LM3532_BRT_VAL_ADJUST 8 +#define LM3532_RAMP_DOWN_SHIFT 3 + +#define LM3532_NUM_RAMP_VALS 8 +#define LM3532_NUM_AVG_VALS 8 +#define LM3532_NUM_IMP_VALS 32 + +/* + * struct lm3532_als_data + * @config - value of ALS configuration register + * @als1_imp_sel - value of ALS1 resistor select register + * @als2_imp_sel - value of ALS2 resistor select register + * @als_avrg_time - ALS averaging time + * @als_input_mode - ALS input mode for brightness control + * @als_vmin - Minimum ALS voltage + * @als_vmax - Maximum ALS voltage + * @zone_lo - values of ALS lo ZB(Zone Boundary) registers + * @zone_hi - values of ALS hi ZB(Zone Boundary) registers + */ +struct lm3532_als_data { + u8 config; + u8 als1_imp_sel; + u8 als2_imp_sel; + u8 als_avrg_time; + u8 als_input_mode; + u32 als_vmin; + u32 als_vmax; + u8 zones_lo[LM3532_ALS_ZB_MAX]; + u8 zones_hi[LM3532_ALS_ZB_MAX]; +}; + +/** + * struct lm3532_led + * @led_dev: led class device + * @priv - Pointer the device data structure + * @control_bank - Control bank the LED is associated to + * @mode - Mode of the LED string + * @num_leds - Number of LED strings are supported in this array + * @led_strings - The LED strings supported in this array + * @label - LED label + */ +struct lm3532_led { + struct led_classdev led_dev; + struct lm3532_data *priv; + + int control_bank; + int mode; + int num_leds; + u32 led_strings[LM3532_MAX_CONTROL_BANKS]; + char label[LED_MAX_NAME_SIZE]; +}; + +/** + * struct lm3532_data + * @enable_gpio - Hardware enable gpio + * @regulator: regulator + * @client: i2c client + * @regmap - Devices register map + * @dev - Pointer to the devices device struct + * @lock - Lock for reading/writing the device + * @als_data - Pointer to the als data struct + * @runtime_ramp_up - Runtime ramp up setting + * @runtime_ramp_down - Runtime ramp down setting + * @leds - Array of LED strings + */ +struct lm3532_data { + struct gpio_desc *enable_gpio; + struct regulator *regulator; + struct i2c_client *client; + struct regmap *regmap; + struct device *dev; + struct mutex lock; + + struct lm3532_als_data *als_data; + + u32 runtime_ramp_up; + u32 runtime_ramp_down; + + struct lm3532_led leds[]; +}; + +static const struct reg_default lm3532_reg_defs[] = { + {LM3532_REG_OUTPUT_CFG, 0xe4}, + {LM3532_REG_STARTSHUT_RAMP, 0xc0}, + {LM3532_REG_RT_RAMP, 0xc0}, + {LM3532_REG_PWM_A_CFG, 0x82}, + {LM3532_REG_PWM_B_CFG, 0x82}, + {LM3532_REG_PWM_C_CFG, 0x82}, + {LM3532_REG_ZONE_CFG_A, 0xf1}, + {LM3532_REG_CTRL_A_BRT, 0xf3}, + {LM3532_REG_ZONE_CFG_B, 0xf1}, + {LM3532_REG_CTRL_B_BRT, 0xf3}, + {LM3532_REG_ZONE_CFG_C, 0xf1}, + {LM3532_REG_CTRL_C_BRT, 0xf3}, + {LM3532_REG_ENABLE, 0xf8}, + {LM3532_ALS_CONFIG, 0x44}, + {LM3532_REG_ZN_0_HI, 0x35}, + {LM3532_REG_ZN_0_LO, 0x33}, + {LM3532_REG_ZN_1_HI, 0x6a}, + {LM3532_REG_ZN_1_LO, 0x66}, + {LM3532_REG_ZN_2_HI, 0xa1}, + {LM3532_REG_ZN_2_LO, 0x99}, + {LM3532_REG_ZN_3_HI, 0xdc}, + {LM3532_REG_ZN_3_LO, 0xcc}, +}; + +static const struct regmap_config lm3532_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + + .max_register = LM3532_REG_MAX, + .reg_defaults = lm3532_reg_defs, + .num_reg_defaults = ARRAY_SIZE(lm3532_reg_defs), + .cache_type = REGCACHE_FLAT, +}; + +const static int als_imp_table[LM3532_NUM_IMP_VALS] = {37000, 18500, 12330, + 92500, 7400, 6170, 5290, + 4630, 4110, 3700, 3360, + 3080, 2850, 2640, 2440, + 2310, 2180, 2060, 1950, + 1850, 1760, 1680, 1610, + 1540, 1480, 1420, 1370, + 1320, 1280, 1230, 1190}; +static int lm3532_get_als_imp_index(int als_imped) +{ + int i; + + if (als_imped > als_imp_table[1]) + return 0; + + if (als_imped < als_imp_table[LM3532_NUM_IMP_VALS - 1]) + return LM3532_NUM_IMP_VALS - 1; + + for (i = 1; i < LM3532_NUM_IMP_VALS; i++) { + if (als_imped == als_imp_table[i]) + return i; + + /* Find an approximate index by looking up the table */ + if (als_imped < als_imp_table[i - 1] && + als_imped > als_imp_table[i]) { + if (als_imped - als_imp_table[i - 1] < + als_imp_table[i] - als_imped) + return i + 1; + else + return i; + } + } + + return -EINVAL; +} + +static int lm3532_get_index(const int table[], int size, int value) +{ + int i; + + for (i = 1; i < size; i++) { + if (value == table[i]) + return i; + + /* Find an approximate index by looking up the table */ + if (value > table[i - 1] && + value < table[i]) { + if (value - table[i - 1] < table[i] - value) + return i - 1; + else + return i; + } + } + + return -EINVAL; +} + +const static int als_avrg_table[LM3532_NUM_AVG_VALS] = {17920, 35840, 71680, + 1433360, 286720, 573440, + 1146880, 2293760}; +static int lm3532_get_als_avg_index(int avg_time) +{ + if (avg_time <= als_avrg_table[0]) + return 0; + + if (avg_time > als_avrg_table[LM3532_NUM_AVG_VALS - 1]) + return LM3532_NUM_AVG_VALS - 1; + + return lm3532_get_index(&als_avrg_table[0], LM3532_NUM_AVG_VALS, + avg_time); +} + +const static int ramp_table[LM3532_NUM_RAMP_VALS] = { 8, 1024, 2048, 4096, 8192, + 16384, 32768, 65536}; +static int lm3532_get_ramp_index(int ramp_time) +{ + if (ramp_time <= ramp_table[0]) + return 0; + + if (ramp_time > ramp_table[LM3532_NUM_RAMP_VALS - 1]) + return LM3532_NUM_RAMP_VALS - 1; + + return lm3532_get_index(&ramp_table[0], LM3532_NUM_RAMP_VALS, + ramp_time); +} + +static int lm3532_led_enable(struct lm3532_led *led_data) +{ + int ctrl_en_val = BIT(led_data->control_bank); + int ret; + + ret = regmap_update_bits(led_data->priv->regmap, LM3532_REG_ENABLE, + ctrl_en_val, ctrl_en_val); + if (ret) { + dev_err(led_data->priv->dev, "Failed to set ctrl:%d\n", ret); + return ret; + } + + return regulator_enable(led_data->priv->regulator); +} + +static int lm3532_led_disable(struct lm3532_led *led_data) +{ + int ctrl_en_val = BIT(led_data->control_bank); |