driver: leds: is31fl3196/99 dimmable dual/triple rgb driver
Subsystems (2)
PATCH 1/1 driver: leds: is31fl3196/99 dimmable dual/triple rgb driver
This patch adds a driver for the is31fl3196/99 dimmable dual/triple rgb controller chips from ISSI.
H. Nikolaus Schaller (1):
drivers: led: is31fl319x: 6/9-channel light effect led driver
.../devicetree/bindings/leds/is31fl319x.txt | 41 +++ drivers/leds/Kconfig | 8 + drivers/leds/Makefile | 1 + drivers/leds/leds-is31fl319x.c | 406 +++++++++++++++++++++ include/linux/leds-is31fl319x.h | 24 ++ 5 files changed, 480 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/is31fl319x.txt create mode 100644 drivers/leds/leds-is31fl319x.c create mode 100644 include/linux/leds-is31fl319x.h
Signature · 1 line
2.7.3
PATCH 1/1 drivers: led: is31fl319x: 6/9-channel light effect led driver
This is a driver for the Integrated Silicon Solution Inc. LED driver chips IS31FL3196 and IS31FL3199. They can drive up to 6 or 9 LEDs.
Each LED is individually controllable in brightness (through pwm) in 256 steps so that RGB LEDs can show any of ca. 16 Mio colors.
The maximum current of the LEDs can be programmed and limited to 5 .. 40mA through a device tree property.
The chip is connected through I2C and can have one of 4 addresses (0x64 .. 0x67) depending on how the AD pin is connected. The address is defined by the reg property as usual.
The chip also has a shutdown input which could be connected to a GPIO, but this driver uses software shutdown if all LEDs are inactivated.
The chip also has breathing and audio features which are not supported by this driver.
This driver was developed and tested on OMAP5 based Pyra handheld prototype.
--- .../devicetree/bindings/leds/is31fl319x.txt | 41 +++ drivers/leds/Kconfig | 8 + drivers/leds/Makefile | 1 + drivers/leds/leds-is31fl319x.c | 406 +++++++++++++++++++++ include/linux/leds-is31fl319x.h | 24 ++ 5 files changed, 480 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/is31fl319x.txt create mode 100644 drivers/leds/leds-is31fl319x.c create mode 100644 include/linux/leds-is31fl319x.h
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +41 -0
@@ -0,0 +1,41 @@ +LEDs connected to is31fl319x RGB LED controller chip + +Required properties: +- compatible : should be : "issi,is31fl3196" or "issi,is31fl3199". +- #address-cells: must be 1 +- #size-cells: must be 0 +- reg: 0x64, 0x65, 0x66, 0x67. + +Optional properties: +- max-current-ma: maximum led current (5..40 mA, default 20 mA) +- audio-gain-db: audio gain selection (0..21 dB. default 0 dB) +- breathing & audio: not implemented + +Each led is represented as a sub-node of the issi,is31fl319x device. + +LED sub-node properties: +- label : (optional) see Documentation/devicetree/bindings/leds/common.txt +- reg : number of LED line (0 to 5 or 0 to 8 - not all need to be present) +- linux,default-trigger : (optional) + see Documentation/devicetree/bindings/leds/common.txt + +Examples: + +fancy_leds: is31fl3196@65 { + compatible = "issi,is31fl319x"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x65>; + + led0: red-aux@0 { + label = "red:aux"; + reg = <0>; + }; + + led1: green-power@4 { + label = "green:power"; + reg = <4>; + linux,default-trigger = "default-on"; + }; +}; +
drivers/leds/Kconfig +8 -0
@@ -491,6 +491,14 @@ config LEDS_ASIC3 cannot be used. This driver supports hardware blinking with an on+off period from 62ms to 125s. Say Y to enable LEDs on the HP iPAQ hx4700. +config LEDS_IS31FL319X + tristate "LED Support for IS31FL319x I2C chip" + depends on LEDS_CLASS && I2C + help + This option enables support for LEDs connected to IS31FL3196 + or IS31FL3199 LED driver chips accessed via the I2C bus. + Driver support brightness control and hardware-assisted blinking. + config LEDS_TCA6507 tristate "LED Support for TCA6507 I2C chip" depends on LEDS_CLASS && I2C
drivers/leds/Makefile +1 -0
@@ -37,6 +37,7 @@ obj-$(CONFIG_LEDS_TCA6507) += leds-tca6507.o obj-$(CONFIG_LEDS_TLC591XX) += leds-tlc591xx.o obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o obj-$(CONFIG_LEDS_IPAQ_MICRO) += leds-ipaq-micro.o +obj-$(CONFIG_LEDS_IS31FL319X) += leds-is31fl319x.o obj-$(CONFIG_LEDS_HP6XX) += leds-hp6xx.o obj-$(CONFIG_LEDS_OT200) += leds-ot200.o obj-$(CONFIG_LEDS_FSG) += leds-fsg.o
drivers/leds/leds-is31fl319x.c new file +406 -0
406 lines not on this page · raw message
include/linux/leds-is31fl319x.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* IS31FL3196 LED chip driver. +* +* Copyright (C) 2015 H. Nikolaus Schaller <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +*/ + +#ifndef __LINUX_IS31FL319X_H +#define __LINUX_IS31FL319X_H +#include <linux/leds.h> + +struct is31fl319x_platform_data { +struct led_platform_data leds; +}; + +#endif /* __LINUX_IS31FL319X_H */
Signature · 6 lines
2.7.3 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
kbuild test robot
build botRe: [PATCH] drivers: led: is31fl319x: 6/9-channel light effect led driver
reproduce:
Hi Nikolaus,
[auto build test ERROR on j.anaszewski-leds/for-next]
[also build test ERROR on v4.6-rc4 next-20160418]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
url: https://github.com/0day-ci/linux/commits/H-Nikolaus-Schaller/drivers-led-is31fl319x-6-9-channel-light-effect-led-driver/20160419-024650 base: https://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski/linux-leds for-next config: i386-randconfig-b0-04190529 (attached as .config) reproduce: # save the attached .config to linux build tree make ARCH=i386
All errors (new ones prefixed by >>):
drivers/leds/leds-is31fl319x.c: In function 'is31fl319x_probe':
>> drivers/leds/leds-is31fl319x.c:299:11: error: too many arguments to function 'is31fl319x_led_dt_init'
pdata = is31fl319x_led_dt_init(client, (int) id->driver_data);
^
drivers/leds/leds-is31fl319x.c:271:1: note: declared here
is31fl319x_led_dt_init(struct i2c_client *client)
^vim +/is31fl319x_led_dt_init +299 drivers/leds/leds-is31fl319x.c
293 NUM_LEDS, (int) id->driver_data);
294
295 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
296 return -EIO;
297
298 if (!pdata) {
> 299 pdata = is31fl319x_led_dt_init(client, (int) id->driver_data);
300 if (IS_ERR(pdata)) {
301 dev_err(&client->dev, "DT led error %d\n",
302 (int) PTR_ERR(pdata));
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Re: [PATCH] drivers: led: is31fl319x: 6/9-channel light effect led driver
In reply to H. Nikolaus SchallerHi Nikolaus,
I recently submitted a driver for the IS31FL32xx family of devices, so this driver caught my eye. I have a few comments below.
Quoted 45 lines · On Mon, 18 Apr 2016 20:43:16 +0200 "H. Nikolaus Schaller" <[email protected]>…
This is a driver for the Integrated Silicon Solution Inc. LED driver chips IS31FL3196 and IS31FL3199. They can drive up to 6 or 9 LEDs.
Each LED is individually controllable in brightness (through pwm) in 256 steps so that RGB LEDs can show any of ca. 16 Mio colors.
The maximum current of the LEDs can be programmed and limited to 5 .. 40mA through a device tree property.
The chip is connected through I2C and can have one of 4 addresses (
0x64..0x67) depending on how the AD pin is connected. The address is defined by the reg property as usual.The chip also has a shutdown input which could be connected to a GPIO, but this driver uses software shutdown if all LEDs are inactivated.
The chip also has breathing and audio features which are not supported by this driver.
This driver was developed and tested on OMAP5 based Pyra handheld prototype.
Signed-off-by H. Nikolaus Schaller <[email protected]>--- .../devicetree/bindings/leds/is31fl319x.txt | 41 +++ drivers/leds/Kconfig | 8 + drivers/leds/Makefile | 1 + drivers/leds/leds-is31fl319x.c | 406 +++++++++++++++++++++ include/linux/leds-is31fl319x.h | 24 ++ 5 files changed, 480 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/is31fl319x.txt create mode 100644 drivers/leds/leds-is31fl319x.c create mode 100644 include/linux/leds-is31fl319x.hDocumentation/devicetree/bindings/leds/is31fl319x.txt new file +4
-0@@ -0,0 +1,41 @@ +LEDs connected to is31fl319x RGB LED controller chip + +Required properties: +- compatible : should be : "issi,is31fl3196" or "issi,is31fl3199".
Quoted 1 line
From a quick look at the datasheets, I believe the Si-En SN3199 [1]
is the same as the ISSI IS31FL3199. ISSI purchased Si-En in 2011, and looks to have rebranded Si-En's existing LED controllers. Assuming the SN3199 is indeed the same as the IS31FL3199, I would suggest adding a compatible string of "si-en,sn3199" both here and in the driver itself (and update the Kconfig text as well).
[1] http://www.si-en.com/product.asp?parentid=890
Documentation/devicetree/bindings/leds/is31fl319x.txt line 12
Quoted 8 lines
+- #address-cells: must be 1 +- #size-cells: must be 0 +- reg: 0x64, 0x65, 0x66, 0x67.Documentation/devicetree/bindings/leds/is31fl319x.txt new file +5
-0+ +Optional properties: +- max-current-ma: maximum led current (5..40 mA, default 20 mA) +- audio-gain-db: audio gain selection (0..21 dB. default 0 dB) +- breathing & audio: not implemented
I'm not certain, but that last line feels wrong to me. I would expect to see just defined properties in this section, while that is more commentary. I would just leave it out, myself.
Documentation/devicetree/bindings/leds/is31fl319x.txt line 18
Quoted 6 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +6
-0+ +Each led is represented as a sub-node of the issi,is31fl319x device. + +LED sub-node properties: +- label : (optional) see Documentation/devicetree/bindings/leds/common.txt +- reg : number of LED line (0 to 5 or 0 to 8 - not all need to be present)
Since the datasheets for these devices name the outputs "OUT1" through "OUT6"/"OUT9", I believe the correct range for the 'reg' property should be 1-6 and 1-9. At least that was the result of a discussion with Rob Herring [2], and therefore how the IS31FL32xx binding/driver was done. It also makes devicetrees easier to write relative to schematics which likely use the OUT1-N naming.
Documentation/devicetree/bindings/leds/is31fl319x.txt line 24
Quoted 6 lines
+- linux,default-trigger : (optional)
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +5
-0+ see Documentation/devicetree/bindings/leds/common.txt + +Examples: + +fancy_leds: is31fl3196@65 {
I believe the current preference would be to name the node by its function, rather than the device. For example:
fancy_leds: leds@65
Documentation/devicetree/bindings/leds/is31fl319x.txt line 25
Quoted 1 line
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +1
-0+ compatible = "issi,is31fl319x";
I believe this should be "issi,is31fl3196" here.
Quoted 21 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +16
-0+ #address-cells = <1>; + #size-cells = <0>; + reg = <0x65>; + + led0: red-aux@0 { + label = "red:aux"; + reg = <0>; + }; + + led1: green-power@4 { + label = "green:power"; + reg = <4>; + linux,default-trigger = "default-on"; + }; +}; +drivers/leds/Kconfig +0
-0
drivers/leds/Kconfig config LEDS_ASIC3 · line 495
Quoted 5 lines
drivers/leds/Kconfig +2
-0@@ -491,6 +491,14 @@ config LEDS_ASIC3 cannot be used. This driver supports hardware blinking with an on+off period from 62ms to 125s. Say Y to enable LEDs on the HP iPAQ hx4700. +config LEDS_IS31FL319X + tristate "LED Support for IS31FL319x I2C chip"
Pedantic: "chips" (plural) seems appropriate here.
drivers/leds/Kconfig config LEDS_ASIC3 · line 500
Quoted 5 lines
drivers/leds/Kconfig +5
-0+ depends on LEDS_CLASS && I2C + help + This option enables support for LEDs connected to IS31FL3196 + or IS31FL3199 LED driver chips accessed via the I2C bus. + Driver support brightness control and hardware-assisted blinking.
Pedantic: "supports" seems appropriate here.
I don't think this matters much, but I'm curious: any reason why this entry is inserted in the middle of the list, rather than at the end? Or better, right before/after the IS31FL32XX entry?
drivers/leds/Makefile obj-$(CONFIG_LEDS_TCA6507) += leds-tca6507.o · line 40
Quoted 13 lines
drivers/leds/Kconfig +1
-0+ config LEDS_TCA6507 tristate "LED Support for TCA6507 I2C chip" depends on LEDS_CLASS && I2Cdrivers/leds/Makefile +1
-0@@ -37,6 +37,7 @@ obj-$(CONFIG_LEDS_TCA6507) += leds-tca6507.o obj-$(CONFIG_LEDS_TLC591XX) += leds-tlc591xx.o obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o obj-$(CONFIG_LEDS_IPAQ_MICRO) += leds-ipaq-micro.o +obj-$(CONFIG_LEDS_IS31FL319X) += leds-is31fl319x.o
Ditto.
Quoted 11 lines
drivers/leds/Makefile +0
-0obj-$(CONFIG_LEDS_HP6XX) += leds-hp6xx.o obj-$(CONFIG_LEDS_OT200) += leds-ot200.o obj-$(CONFIG_LEDS_FSG) += leds-fsg.odrivers/leds/leds-is31fl319x.c new file +2
-0@@ -0,0 +1,406 @@ +/* +* Copyright 2015 Golden Delcious Computers
drivers/leds/leds-is31fl319x.c line 12
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+* +* Author: Nikolaus Schaller <[email protected]> +* +* Based on leds-tca6507.c +* +* This file is subject to the terms and conditions of version 2 of +* the GNU General Public License. See the file COPYING in the main +* directory of this archive for more details. +* +* LED driver for the IS31FL3196/99 to drive 6 or 9 light effect LEDs.
I see that there are also 3190, 3191, and 3193 devices. Is it reasonable to think that support for those devices could be added to this driver in the future? I'm merely thinking of it from the POV that it is named is31fl319x.c.
Quoted 53 lines
drivers/leds/leds-is31fl319x.c new file +53
-0+* +*/ + +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/leds.h> +#include <linux/err.h> +#include <linux/i2c.h> +#include <linux/workqueue.h> +#include <linux/leds-is31fl319x.h> +#include <linux/of.h> + +/* register numbers */ +#define IS31FL319X_SHUTDOWN 0x00 +#define IS31FL319X_CTRL1 0x01 +#define IS31FL319X_CTRL2 0x02 +#define IS31FL319X_CONFIG1 0x03 +#define IS31FL319X_CONFIG2 0x04 +#define IS31FL319X_RAMP_MODE 0x05 +#define IS31FL319X_BREATH_MASK 0x06 +#define IS31FL319X_PWM1 0x07 +#define IS31FL319X_PWM2 0x08 +#define IS31FL319X_PWM3 0x09 +#define IS31FL319X_PWM4 0x0a +#define IS31FL319X_PWM5 0x0b +#define IS31FL319X_PWM6 0x0c +#define IS31FL319X_PWM7 0x0d +#define IS31FL319X_PWM8 0x0e +#define IS31FL319X_PWM9 0x0f +#define IS31FL319X_DATA_UPDATE 0x10 +#define IS31FL319X_T0_1 0x11 +#define IS31FL319X_T0_2 0x12 +#define IS31FL319X_T0_3 0x13 +#define IS31FL319X_T0_4 0x14 +#define IS31FL319X_T0_5 0x15 +#define IS31FL319X_T0_6 0x16 +#define IS31FL319X_T0_7 0x17 +#define IS31FL319X_T0_8 0x18 +#define IS31FL319X_T0_9 0x19 +#define IS31FL319X_T123_1 0x1a +#define IS31FL319X_T123_2 0x1b +#define IS31FL319X_T123_3 0x1c +#define IS31FL319X_T4_1 0x1d +#define IS31FL319X_T4_2 0x1e +#define IS31FL319X_T4_3 0x1f +#define IS31FL319X_T4_4 0x20 +#define IS31FL319X_T4_5 0x21 +#define IS31FL319X_T4_6 0x22 +#define IS31FL319X_T4_7 0x23 +#define IS31FL319X_T4_8 0x24 +#define IS31FL319X_T4_9 0x25 +#define IS31FL319X_TIME_UPDATE 0x26 +
drivers/leds/leds-is31fl319x.c line 75
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+#define IS31FL319X_REG_CNT (IS31FL319X_TIME_UPDATE + 1) + +#define NUM_LEDS 9/* max for 3199 chip */ + +struct is31fl319x_chip { +struct i2c_client *client; +struct work_struct work; +bool work_scheduled; +spinlock_t lock; +u8 reg_file[IS31FL319X_REG_CNT ];
I would suggest using the regmap infrastructure if you need to cache the register values. It also helpfully exports a debugfs interface.
Quoted 38 lines
drivers/leds/leds-is31fl319x.c new file +38
-0+ +struct is31fl319x_led { +struct is31fl319x_chip *chip; +struct led_classdev led_cdev; + } leds[NUM_LEDS ]; +}; + +static const struct i2c_device_id is31fl319x_id[] = { + {"is31fl3196" ,6 }, + {"is31fl3196" ,9 }, + { } +}; +MODULE_DEVICE_TABLE (i2c, is31fl319x_id); + + +static int is31fl319x_write (struct is31fl319x_chip *is31,u8 reg,u8 byte) +{ +struct i2c_client *cl = is31->client; + +if (reg >=IS31FL319X_REG_CNT ) +return -EIO ; + is31->reg_file[reg] = byte;/* save in cache */ +dev_dbg (&is31->client->dev,"write %02x to reg %02x\n" , byte, reg); +return i2c_smbus_write_byte_data (cl, reg, byte); +} + +static int is31fl319x_read (struct is31fl319x_chip *is31,u8 reg) +{ +if (reg >=IS31FL319X_REG_CNT ) +return -EIO ; +return is31->reg_file[reg];/* read crom cache (can't read chip) */ +} + +static void is31fl319x_work (struct work_struct *work) +{ +struct is31fl319x_chip *is31 =container_of (work, + struct is31fl319x_chip, + work);
drivers/leds/leds-is31fl319x.c line 123
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+unsigned long flags; +int i; +u8 ctrl1, ctrl2; + +dev_dbg (&is31->client->dev,"work called\n" ); + +spin_lock_irqsave (&is31->lock, flags); +/* make subsequent changes run another schedule_work */ + is31->work_scheduled = false; +spin_unlock_irqrestore (&is31->lock, flags);
I believe the LEDS core now handles the workqueues generically for blocking operations, so it's no longer needed in the individual drivers.
Quoted 18 lines
drivers/leds/leds-is31fl319x.c new file +18
-0+ +dev_dbg (&is31->client->dev,"write to chip\n" ); + + ctrl1 =0 ; + ctrl2 =0 ; + +for (i =0 ; i <NUM_LEDS ; i++) { +struct led_classdev *led = &is31->leds[i].led_cdev; +bool on; + +if (!is31->leds[i].led_cdev.name) +continue ; + +dev_dbg (&is31->client->dev,"set brightness %u for led %u\n" , + led->brightness, i); + +/* update brightness register */ +is31fl319x_write (is31,IS31FL319X_PWM1 + i, led->brightness);
drivers/leds/leds-is31fl319x.c line 151
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+ +/* update output enable bits */ + on = led->brightness >LED_OFF ; +if (i <3 ) + ctrl1 |= on << i;/* 0..2 => bit 0..2 */ +else if (i <6 ) + ctrl1 |= on << (i+1 );/* 3..5 => bit 4..6 */ +else + ctrl2 |= on << (i-6 );/* 6..8 => bit 0..2 */ + }
Is any locking needed while iterating over is31->leds[]? Is there any opportunity for a race?
Quoted 22 lines
drivers/leds/leds-is31fl319x.c new file +22
-0+ +/* check if any PWM is enabled or all outputs are now off */ +if (ctrl1 >0 || ctrl2 >0 ) { +dev_dbg (&is31->client->dev,"power up\n" ); +is31fl319x_write (is31,IS31FL319X_CTRL1 , ctrl1); +is31fl319x_write (is31,IS31FL319X_CTRL2 , ctrl2); +/* update PWMs */ +is31fl319x_write (is31,IS31FL319X_DATA_UPDATE ,0x00 ); +/* enable chip from shut down */ +is31fl319x_write (is31,IS31FL319X_SHUTDOWN ,0x01 ); + }else { +dev_dbg (&is31->client->dev,"power down\n" ); +/* shut down */ +is31fl319x_write (is31,IS31FL319X_SHUTDOWN ,0x00 ); + } + +dev_dbg (&is31->client->dev,"work done\n" ); + +} + +/* NOTE: this may be called from within irq context, e.g. led_trigger_event */ +
drivers/leds/leds-is31fl319x.c line 183
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+static int is31fl319x_brightness_get (struct led_classdev *led_cdev) +{ +struct is31fl319x_led *led =container_of (led_cdev, + struct is31fl319x_led, + led_cdev); +struct is31fl319x_chip *is31 = led->chip; + +/* read PWM register */ +return is31fl319x_read (is31,IS31FL319X_PWM1 + (led - is31->leds)); +}
I believe that the LEDS core remembers the last set brightness for each LED,
and will use it if no brightness_get function is implemented. Since all is31fl319x_brightness_get() does is retrieve the saved value from your cache, I think you can just eliminate is31fl319x_brightness_get() altogether.
Quoted 18 lines
drivers/leds/leds-is31fl319x.c new file +18
-0+ +static void is31fl319x_brightness_set (struct led_classdev *led_cdev, +enum led_brightness brightness) +{ +struct is31fl319x_led *led =container_of (led_cdev, + struct is31fl319x_led, + led_cdev); +struct is31fl319x_chip *is31 = led->chip; +unsigned long flags; + +spin_lock_irqsave (&is31->lock, flags); + +if (brightness !=is31fl319x_brightness_get (led_cdev)) { +if (!is31->work_scheduled) { +schedule_work (&is31->work); + is31->work_scheduled = true; + } + }
drivers/leds/leds-is31fl319x.c line 211
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+ +spin_unlock_irqrestore (&is31->lock, flags); +} + +static int is31fl319x_blink_set (struct led_classdev *led_cdev, +unsigned long *delay_on, +unsigned long *delay_off) +{ +/* use software blink */ +return 1 ;
The Kconfig entry claims hardware blink support. The comment here says the opposite. I believe this current implementation will result in the LEDS core falling back to software blink, but the same result would be achieved by just not setting the blink_set callback.
Quoted 20 lines
drivers/leds/leds-is31fl319x.c new file +20
-0+} + +#ifdef CONFIG_OF +static struct is31fl319x_platform_data * +is31fl319x_led_dt_init (struct i2c_client *client,int num_leds) +{ +struct device_node *np = client->dev.of_node, *child; +struct is31fl319x_platform_data *pdata; +struct led_info *is31_leds; +int count; + + count =of_get_child_count (np); +dev_dbg (&client->dev,"child count %d\n" , count); +if (!count || count >NUM_LEDS ) +return ERR_PTR (-ENODEV ); + + is31_leds =devm_kzalloc (&client->dev, +sizeof (struct led_info ) *NUM_LEDS ,GFP_KERNEL ); +if (!is31_leds) +return ERR_PTR (-ENOMEM );
drivers/leds/leds-is31fl319x.c line 241
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+ +for_each_child_of_node (np, child) { +struct led_info led; +u32 reg; +int ret; + + led.name = +of_get_property (child,"label" ,NULL ) ? : child->name; + led.default_trigger = +of_get_property (child,"linux,default-trigger" ,NULL );
I believe it is better to use of_property_read_string() for these.
drivers/leds/leds-is31fl319x.c line 250
Quoted 9 lines
drivers/leds/leds-is31fl319x.c new file +9
-0+ led.flags =0 ; + ret =of_property_read_u32 (child,"reg" , ®); +dev_dbg (&client->dev,"name = %s reg = %d\n" , led.name, reg); +if (ret !=0 || reg <0 || reg >= num_leds) +continue ; + +if (is31_leds[reg].name) +dev_err (&client->dev,"duplicate led line %d for %s -> %s\n" , + reg, is31_leds[reg].name, led.name);
There are two errors (invalid DT) detected here, but the driver continues to load. I believe the preference is for errors like this to result in the probe failing outright.
Quoted 72 lines
drivers/leds/leds-is31fl319x.c new file +72
-0+ is31_leds[reg] = led; + } + pdata =devm_kzalloc (&client->dev, +sizeof (struct is31fl319x_platform_data ),GFP_KERNEL ); +if (!pdata) +return ERR_PTR (-ENOMEM ); + + pdata->leds.leds = is31_leds; +return pdata; +} + +static const struct of_device_id of_is31fl319x_leds_match[] = { + { .compatible ="issi,is31fl3196" , (void *)6 }, + { .compatible ="issi,is31fl3199" , (void *)9 }, + {}, +}; +MODULE_DEVICE_TABLE (of, of_is31fl319x_leds_match); + +#else +static struct is31fl319x_platform_data * +is31fl319x_led_dt_init (struct i2c_client *client) +{ +return ERR_PTR (-ENODEV ); +} + +#endif + +static int is31fl319x_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +struct is31fl319x_chip *is31; +struct i2c_adapter *adapter; +struct is31fl319x_platform_data *pdata; +int err; +int i =0 ; + + adapter =to_i2c_adapter (client->dev.parent); + pdata =dev_get_platdata (&client->dev); + +dev_dbg (&client->dev,"probe\n" ); + +dev_dbg (&client->dev,"NUM_LEDS = %d num_leds = %d\n" , +NUM_LEDS , (int ) id->driver_data); + +if (!i2c_check_functionality (adapter,I2C_FUNC_I2C )) +return -EIO ; + +if (!pdata) { + pdata =is31fl319x_led_dt_init (client, (int ) id->driver_data); +if (IS_ERR (pdata)) { +dev_err (&client->dev,"DT led error %d\n" , + (int )PTR_ERR (pdata)); +return PTR_ERR (pdata); + } + } + is31 =devm_kzalloc (&client->dev,sizeof (*is31),GFP_KERNEL ); +if (!is31) +return -ENOMEM ; + + is31->client = client; +INIT_WORK (&is31->work, is31fl319x_work); +spin_lock_init (&is31->lock); +i2c_set_clientdata (client, is31); + +/* check for reply from chip (we can't read any registers) */ + err =is31fl319x_write (is31,IS31FL319X_SHUTDOWN ,0x01 ); +if (err <0 ) { +dev_err (&client->dev,"no response from chip write: err = %d\n" , + err); +return -EPROBE_DEFER ;/* does not answer (yet) */ + } +
drivers/leds/leds-is31fl319x.c line 332
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+for (i =0 ; i <NUM_LEDS ; i++) { +struct is31fl319x_led *l = is31->leds + i; + + l->chip = is31; +if (pdata->leds.leds[i].name && !pdata->leds.leds[i].flags) { + l->led_cdev.name = pdata->leds.leds[i].name; + l->led_cdev.default_trigger + = pdata->leds.leds[i].default_trigger; + l->led_cdev.brightness_set = is31fl319x_brightness_set; + l->led_cdev.blink_set = is31fl319x_blink_set;
I don't see led_cdev.brightness_get being set here. Although if you do remove is31fl319x_brightness_get(), it obviously won't need to be set.
drivers/leds/leds-is31fl319x.c line 334
Quoted 2 lines
drivers/leds/leds-is31fl319x.c new file +2
-0+ err =led_classdev_register (&client->dev, + &l->led_cdev);
I would suggest using devm_led_classdev_register(). Then you can remove all the calls to led_classdev_unregister() in error and cleanup paths.
Quoted 102 lines
drivers/leds/leds-is31fl319x.c new file +72
-0+if (err <0 ) + goto exit; + } + } + +if (client->dev.of_node) { +u32 val; +u8 config2 =0 ; + +if (of_property_read_u32 (client->dev.of_node,"max-current-ma" , + &val)) { +if (val >40 ) + val =40 ; +if (val <5 ) + val =5 ; + config2 |= (((64 - val) /5 ) &0x7 ) <<4 ;/* CS */ + } +if (of_property_read_u32 (client->dev.of_node,"audio-gain-db" , + &val)) { +if (val >21 ) + val =21 ; + config2 |= val /3 ;/* AGS */ + } +if (config2) +is31fl319x_write (is31,IS31FL319X_CONFIG2 , config2); + } + +schedule_work (&is31->work);/* first update */ + +dev_dbg (&client->dev,"probed\n" ); +return 0 ; +exit: +dev_err (&client->dev,"led error %d\n" , err); + +while (i--) { +if (is31->leds[i].led_cdev.name) +led_classdev_unregister (&is31->leds[i].led_cdev); + } +return err; +} + +static int is31fl319x_remove (struct i2c_client *client) +{ +int i; +struct is31fl319x_chip *is31 =i2c_get_clientdata (client); +struct is31fl319x_led *is31_leds = is31->leds; + +for (i =0 ; i <NUM_LEDS ; i++) { +if (is31_leds[i].led_cdev.name) +led_classdev_unregister (&is31_leds[i].led_cdev); + } + +cancel_work_sync (&is31->work); + +return 0 ; +} + +static struct i2c_driver is31fl319x_driver = { + .driver = { + .name ="leds-is31fl319x" , + .of_match_table =of_match_ptr (of_is31fl319x_leds_match), + }, + .probe = is31fl319x_probe, + .remove = is31fl319x_remove, + .id_table = is31fl319x_id, +}; + +module_i2c_driver (is31fl319x_driver); + +MODULE_AUTHOR ("H. Nikolaus Schaller <[email protected]>" ); +MODULE_DESCRIPTION ("IS31FL319X LED driver" ); +MODULE_LICENSE ("GPL v2" );include/linux/leds-is31fl319x.h new file +24
-0@@ -0,0 +1,24 @@ +/* +* IS31FL3196 LED chip driver. +* +* Copyright (C) 2015 H. Nikolaus Schaller <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +*/ + +#ifndef __LINUX_IS31FL319X_H +#define __LINUX_IS31FL319X_H +#include <linux/leds.h> + +struct is31fl319x_platform_data { +struct led_platform_data leds; +}; + +#endif /* __LINUX_IS31FL319X_H */
Re: [PATCH] drivers: led: is31fl319x: 6/9-channel light effect led driver
Hi David,
Thanks for the review.
Nikolaus - please address David's remarks.
Thanks,
Jacek Anaszewski
Quoted 663 lines · David Rivshin (Allworx)
Hi Nikolaus,
I recently submitted a driver for the IS31FL32xx family of devices, so this driver caught my eye. I have a few comments below.
Quoted 45 lines · On Mon, 18 Apr 2016 20:43:16 +0200 "H. Nikolaus Schaller" <[email protected]>…
This is a driver for the Integrated Silicon Solution Inc. LED driver chips IS31FL3196 and IS31FL3199. They can drive up to 6 or 9 LEDs.
Each LED is individually controllable in brightness (through pwm) in 256 steps so that RGB LEDs can show any of ca. 16 Mio colors.
The maximum current of the LEDs can be programmed and limited to 5 .. 40mA through a device tree property.
The chip is connected through I2C and can have one of 4 addresses (
0x64..0x67) depending on how the AD pin is connected. The address is defined by the reg property as usual.The chip also has a shutdown input which could be connected to a GPIO, but this driver uses software shutdown if all LEDs are inactivated.
The chip also has breathing and audio features which are not supported by this driver.
This driver was developed and tested on OMAP5 based Pyra handheld prototype.
Signed-off-by H. Nikolaus Schaller <[email protected]>--- .../devicetree/bindings/leds/is31fl319x.txt | 41 +++ drivers/leds/Kconfig | 8 + drivers/leds/Makefile | 1 + drivers/leds/leds-is31fl319x.c | 406 +++++++++++++++++++++ include/linux/leds-is31fl319x.h | 24 ++ 5 files changed, 480 insertions(+)create mode 100644
Documentation/devicetree/bindings/leds/is31fl319x.txtcreate mode 100644drivers/leds/leds-is31fl319x.c
create mode 100644include/linux/leds-is31fl319x.hDocumentation/devicetree/bindings/leds/is31fl319x.txt new file +4
-0@@ -0,0 +1,41 @@ +LEDs connected to is31fl319x RGB LED controller chip + +Required properties: +- compatible : should be : "issi,is31fl3196" or "issi,is31fl3199".Quoted 1 line
From a quick look at the datasheets, I believe the Si-En SN3199 [1]
is the same as the ISSI IS31FL3199. ISSI purchased Si-En in 2011, and looks to have rebranded Si-En's existing LED controllers. Assuming the SN3199 is indeed the same as the IS31FL3199, I would suggest adding a compatible string of "si-en,sn3199" both here and in the driver itself (and update the
Kconfigtext as well).[1] http://www.si-en.com/product.asp?parentid=890
Documentation/devicetree/bindings/leds/is31fl319x.txt line 12
Quoted 8 lines
+- #address-cells: must be 1 +- #size-cells: must be 0 +- reg: 0x64, 0x65, 0x66, 0x67.Documentation/devicetree/bindings/leds/is31fl319x.txt new file +5
-0+ +Optional properties: +- max-current-ma: maximum led current (5..40 mA, default 20 mA) +- audio-gain-db: audio gain selection (0..21 dB. default 0 dB) +- breathing & audio: not implementedI'm not certain, but that last line feels wrong to me. I would expect to see just defined properties in this section, while that is more commentary. I would just leave it out, myself.
Documentation/devicetree/bindings/leds/is31fl319x.txt line 18
Quoted 6 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +6
-0+ +Each led is represented as a sub-node of the issi,is31fl319x device. + +LED sub-node properties: +- label : (optional) see Documentation/devicetree/bindings/leds/common.txt +- reg : number of LED line (0 to 5 or 0 to 8 - not all need to be present)Since the datasheets for these devices name the outputs "OUT1" through "OUT6"/"OUT9", I believe the correct range for the 'reg' property should be 1-6 and 1-9. At least that was the result of a discussion with Rob Herring [2], and therefore how the IS31FL32xx binding/driver was done. It also makes devicetrees easier to write relative to schematics which likely use the OUT1-N naming.
Documentation/devicetree/bindings/leds/is31fl319x.txt line 24
Quoted 6 lines
+- linux,default-trigger : (optional)
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +5
-0+ see Documentation/devicetree/bindings/leds/common.txt + +Examples: + +fancy_leds: is31fl3196@65 {I believe the current preference would be to name the node by its function, rather than the device. For example:
fancy_leds: leds@65Documentation/devicetree/bindings/leds/is31fl319x.txt line 25
Quoted 1 line
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +1
-0+ compatible = "issi,is31fl319x";I believe this should be "issi,is31fl3196" here.
Quoted 21 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +16
-0+ #address-cells = <1>; + #size-cells = <0>; + reg = <0x65>; + + led0: red-aux@0 { + label = "red:aux"; + reg = <0>; + }; + + led1: green-power@4 { + label = "green:power"; + reg = <4>; + linux,default-trigger = "default-on"; + }; +}; +drivers/leds/Kconfig +0
-0drivers/leds/Kconfig config LEDS_ASIC3 · line 495
Quoted 5 lines
drivers/leds/Kconfig +2
-0@@ -491,6 +491,14 @@ config LEDS_ASIC3 cannot be used. This driver supports hardware blinking with an on+off period from 62ms to 125s. Say Y to enable LEDs on the HP iPAQ hx4700. +config LEDS_IS31FL319X + tristate "LED Support for IS31FL319x I2C chip"Pedantic: "chips" (plural) seems appropriate here.
drivers/leds/Kconfig config LEDS_ASIC3 · line 500
Quoted 5 lines
drivers/leds/Kconfig +5
-0+ depends on LEDS_CLASS && I2C + help + This option enables support for LEDs connected to IS31FL3196 + or IS31FL3199 LED driver chips accessed via the I2C bus. + Driver support brightness control and hardware-assisted blinking.Pedantic: "supports" seems appropriate here.
I don't think this matters much, but I'm curious: any reason why this entry is inserted in the middle of the list, rather than at the end? Or better, right before/after the IS31FL32XX entry?
drivers/leds/Makefile obj-$(CONFIG_LEDS_TCA6507) += leds-tca6507.o · line 40
Quoted 13 lines
drivers/leds/Kconfig +1
-0+ config LEDS_TCA6507 tristate "LED Support for TCA6507 I2C chip" depends on LEDS_CLASS && I2Cdrivers/leds/Makefile +1
-0@@ -37,6 +37,7 @@ obj-$(CONFIG_LEDS_TCA6507) += leds-tca6507.o obj-$(CONFIG_LEDS_TLC591XX) += leds-tlc591xx.o obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o obj-$(CONFIG_LEDS_IPAQ_MICRO) += leds-ipaq-micro.o +obj-$(CONFIG_LEDS_IS31FL319X) += leds-is31fl319x.oDitto.
Quoted 11 lines
drivers/leds/Makefile +0
-0obj-$(CONFIG_LEDS_HP6XX) += leds-hp6xx.o obj-$(CONFIG_LEDS_OT200) += leds-ot200.o obj-$(CONFIG_LEDS_FSG) += leds-fsg.odrivers/leds/leds-is31fl319x.c new file +2
-0@@ -0,0 +1,406 @@ +/* +* Copyright 2015 Golden Delcious Computers drivers/leds/leds-is31fl319x.c line 12
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+* +* Author: Nikolaus Schaller <[email protected]> +* +* Based on leds-tca6507.c +* +* This file is subject to the terms and conditions of version 2 of +* the GNU General Public License. See the file COPYING in the main +* directory of this archive for more details. +* +* LED driver for the IS31FL3196/99 to drive 6 or 9 light effect LEDs. I see that there are also 3190, 3191, and 3193 devices. Is it reasonable to think that support for those devices could be added to this driver in the future? I'm merely thinking of it from the POV that it is named
is31fl319x.c.Quoted 53 lines
drivers/leds/leds-is31fl319x.c new file +53
-0+* +*/ + +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/leds.h> +#include <linux/err.h> +#include <linux/i2c.h> +#include <linux/workqueue.h> +#include <linux/leds-is31fl319x.h> +#include <linux/of.h> + +/* register numbers */ +#define IS31FL319X_SHUTDOWN 0x00 +#define IS31FL319X_CTRL1 0x01 +#define IS31FL319X_CTRL2 0x02 +#define IS31FL319X_CONFIG1 0x03 +#define IS31FL319X_CONFIG2 0x04 +#define IS31FL319X_RAMP_MODE 0x05 +#define IS31FL319X_BREATH_MASK 0x06 +#define IS31FL319X_PWM1 0x07 +#define IS31FL319X_PWM2 0x08 +#define IS31FL319X_PWM3 0x09 +#define IS31FL319X_PWM4 0x0a +#define IS31FL319X_PWM5 0x0b +#define IS31FL319X_PWM6 0x0c +#define IS31FL319X_PWM7 0x0d +#define IS31FL319X_PWM8 0x0e +#define IS31FL319X_PWM9 0x0f +#define IS31FL319X_DATA_UPDATE 0x10 +#define IS31FL319X_T0_1 0x11 +#define IS31FL319X_T0_2 0x12 +#define IS31FL319X_T0_3 0x13 +#define IS31FL319X_T0_4 0x14 +#define IS31FL319X_T0_5 0x15 +#define IS31FL319X_T0_6 0x16 +#define IS31FL319X_T0_7 0x17 +#define IS31FL319X_T0_8 0x18 +#define IS31FL319X_T0_9 0x19 +#define IS31FL319X_T123_1 0x1a +#define IS31FL319X_T123_2 0x1b +#define IS31FL319X_T123_3 0x1c +#define IS31FL319X_T4_1 0x1d +#define IS31FL319X_T4_2 0x1e +#define IS31FL319X_T4_3 0x1f +#define IS31FL319X_T4_4 0x20 +#define IS31FL319X_T4_5 0x21 +#define IS31FL319X_T4_6 0x22 +#define IS31FL319X_T4_7 0x23 +#define IS31FL319X_T4_8 0x24 +#define IS31FL319X_T4_9 0x25 +#define IS31FL319X_TIME_UPDATE 0x26 +drivers/leds/leds-is31fl319x.c line 75
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+#define IS31FL319X_REG_CNT (IS31FL319X_TIME_UPDATE + 1) + +#define NUM_LEDS 9/* max for 3199 chip */ + +struct is31fl319x_chip { +struct i2c_client *client; +struct work_struct work; +bool work_scheduled; +spinlock_t lock; +u8 reg_file[IS31FL319X_REG_CNT ];I would suggest using the regmap infrastructure if you need to cache the register values. It also helpfully exports a debugfs interface.
Quoted 38 lines
drivers/leds/leds-is31fl319x.c new file +38
-0+ +struct is31fl319x_led { +struct is31fl319x_chip *chip; +struct led_classdev led_cdev; + } leds[NUM_LEDS ]; +}; + +static const struct i2c_device_id is31fl319x_id[] = { + {"is31fl3196" ,6 }, + {"is31fl3196" ,9 }, + { } +}; +MODULE_DEVICE_TABLE (i2c, is31fl319x_id); + + +static int is31fl319x_write (struct is31fl319x_chip *is31,u8 reg,u8 byte) +{ +struct i2c_client *cl = is31->client; + +if (reg >=IS31FL319X_REG_CNT ) +return -EIO ; + is31->reg_file[reg] = byte;/* save in cache */ +dev_dbg (&is31->client->dev,"write %02x to reg %02x\n" , byte, reg); +return i2c_smbus_write_byte_data (cl, reg, byte); +} + +static int is31fl319x_read (struct is31fl319x_chip *is31,u8 reg) +{ +if (reg >=IS31FL319X_REG_CNT ) +return -EIO ; +return is31->reg_file[reg];/* read crom cache (can't read chip) */ +} + +static void is31fl319x_work (struct work_struct *work) +{ +struct is31fl319x_chip *is31 =container_of (work, + struct is31fl319x_chip, + work);drivers/leds/leds-is31fl319x.c line 123
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+unsigned long flags; +int i; +u8 ctrl1, ctrl2; + +dev_dbg (&is31->client->dev,"work called\n" ); + +spin_lock_irqsave (&is31->lock, flags); +/* make subsequent changes run another schedule_work */ + is31->work_scheduled = false; +spin_unlock_irqrestore (&is31->lock, flags);I believe the LEDS core now handles the workqueues generically for blocking operations, so it's no longer needed in the individual drivers.
Quoted 18 lines
drivers/leds/leds-is31fl319x.c new file +18
-0+ +dev_dbg (&is31->client->dev,"write to chip\n" ); + + ctrl1 =0 ; + ctrl2 =0 ; + +for (i =0 ; i <NUM_LEDS ; i++) { +struct led_classdev *led = &is31->leds[i].led_cdev; +bool on; + +if (!is31->leds[i].led_cdev.name) +continue ; + +dev_dbg (&is31->client->dev,"set brightness %u for led %u\n" , + led->brightness, i); + +/* update brightness register */ +is31fl319x_write (is31,IS31FL319X_PWM1 + i, led->brightness);drivers/leds/leds-is31fl319x.c line 151
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+ +/* update output enable bits */ + on = led->brightness >LED_OFF ; +if (i <3 ) + ctrl1 |= on << i;/* 0..2 => bit 0..2 */ +else if (i <6 ) + ctrl1 |= on << (i+1 );/* 3..5 => bit 4..6 */ +else + ctrl2 |= on << (i-6 );/* 6..8 => bit 0..2 */ + }Is any locking needed while iterating over is31->leds[]? Is there any opportunity for a race?
Quoted 22 lines
drivers/leds/leds-is31fl319x.c new file +22
-0+ +/* check if any PWM is enabled or all outputs are now off */ +if (ctrl1 >0 || ctrl2 >0 ) { +dev_dbg (&is31->client->dev,"power up\n" ); +is31fl319x_write (is31,IS31FL319X_CTRL1 , ctrl1); +is31fl319x_write (is31,IS31FL319X_CTRL2 , ctrl2); +/* update PWMs */ +is31fl319x_write (is31,IS31FL319X_DATA_UPDATE ,0x00 ); +/* enable chip from shut down */ +is31fl319x_write (is31,IS31FL319X_SHUTDOWN ,0x01 ); + }else { +dev_dbg (&is31->client->dev,"power down\n" ); +/* shut down */ +is31fl319x_write (is31,IS31FL319X_SHUTDOWN ,0x00 ); + } + +dev_dbg (&is31->client->dev,"work done\n" ); + +} + +/* NOTE: this may be called from within irq context, e.g. led_trigger_event */ +drivers/leds/leds-is31fl319x.c line 183
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+static int is31fl319x_brightness_get (struct led_classdev *led_cdev) +{ +struct is31fl319x_led *led =container_of (led_cdev, + struct is31fl319x_led, + led_cdev); +struct is31fl319x_chip *is31 = led->chip; + +/* read PWM register */ +return is31fl319x_read (is31,IS31FL319X_PWM1 + (led - is31->leds)); +}I believe that the LEDS core remembers the last set brightness for each LED,
and will use it if nobrightness_getfunction is implemented. Since allis31fl319x_brightness_get()does is retrieve the saved value from your cache, I think you can just eliminateis31fl319x_brightness_get()altogether.Quoted 18 lines
drivers/leds/leds-is31fl319x.c new file +18
-0+ +static void is31fl319x_brightness_set (struct led_classdev *led_cdev, +enum led_brightness brightness) +{ +struct is31fl319x_led *led =container_of (led_cdev, + struct is31fl319x_led, + led_cdev); +struct is31fl319x_chip *is31 = led->chip; +unsigned long flags; + +spin_lock_irqsave (&is31->lock, flags); + +if (brightness !=is31fl319x_brightness_get (led_cdev)) { +if (!is31->work_scheduled) { +schedule_work (&is31->work); + is31->work_scheduled = true; + } + }drivers/leds/leds-is31fl319x.c line 211
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+ +spin_unlock_irqrestore (&is31->lock, flags); +} + +static int is31fl319x_blink_set (struct led_classdev *led_cdev, +unsigned long *delay_on, +unsigned long *delay_off) +{ +/* use software blink */ +return 1 ;The
Kconfigentry claims hardware blink support. The comment here says the opposite. I believe this current implementation will result in the LEDS core falling back to software blink, but the same result would be achieved by just not setting theblink_setcallback.Quoted 20 lines
drivers/leds/leds-is31fl319x.c new file +20
-0+} + +#ifdef CONFIG_OF +static struct is31fl319x_platform_data * +is31fl319x_led_dt_init (struct i2c_client *client,int num_leds) +{ +struct device_node *np = client->dev.of_node, *child; +struct is31fl319x_platform_data *pdata; +struct led_info *is31_leds; +int count; + + count =of_get_child_count (np); +dev_dbg (&client->dev,"child count %d\n" , count); +if (!count || count >NUM_LEDS ) +return ERR_PTR (-ENODEV ); + + is31_leds =devm_kzalloc (&client->dev, +sizeof (struct led_info ) *NUM_LEDS ,GFP_KERNEL ); +if (!is31_leds) +return ERR_PTR (-ENOMEM );drivers/leds/leds-is31fl319x.c line 241
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+ +for_each_child_of_node (np, child) { +struct led_info led; +u32 reg; +int ret; + + led.name = +of_get_property (child,"label" ,NULL ) ? : child->name; + led.default_trigger = +of_get_property (child,"linux,default-trigger" ,NULL );I believe it is better to use
of_property_read_string()for these.drivers/leds/leds-is31fl319x.c line 250
Quoted 9 lines
drivers/leds/leds-is31fl319x.c new file +9
-0+ led.flags =0 ; + ret =of_property_read_u32 (child,"reg" , ®); +dev_dbg (&client->dev,"name = %s reg = %d\n" , led.name, reg); +if (ret !=0 || reg <0 || reg >= num_leds) +continue ; + +if (is31_leds[reg].name) +dev_err (&client->dev,"duplicate led line %d for %s -> %s\n" , + reg, is31_leds[reg].name, led.name);There are two errors (invalid DT) detected here, but the driver continues to load. I believe the preference is for errors like this to result in the probe failing outright.
Quoted 72 lines
drivers/leds/leds-is31fl319x.c new file +72
-0+ is31_leds[reg] = led; + } + pdata =devm_kzalloc (&client->dev, +sizeof (struct is31fl319x_platform_data ),GFP_KERNEL ); +if (!pdata) +return ERR_PTR (-ENOMEM ); + + pdata->leds.leds = is31_leds; +return pdata; +} + +static const struct of_device_id of_is31fl319x_leds_match[] = { + { .compatible ="issi,is31fl3196" , (void *)6 }, + { .compatible ="issi,is31fl3199" , (void *)9 }, + {}, +}; +MODULE_DEVICE_TABLE (of, of_is31fl319x_leds_match); + +#else +static struct is31fl319x_platform_data * +is31fl319x_led_dt_init (struct i2c_client *client) +{ +return ERR_PTR (-ENODEV ); +} + +#endif + +static int is31fl319x_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +struct is31fl319x_chip *is31; +struct i2c_adapter *adapter; +struct is31fl319x_platform_data *pdata; +int err; +int i =0 ; + + adapter =to_i2c_adapter (client->dev.parent); + pdata =dev_get_platdata (&client->dev); + +dev_dbg (&client->dev,"probe\n" ); + +dev_dbg (&client->dev,"NUM_LEDS = %d num_leds = %d\n" , +NUM_LEDS , (int ) id->driver_data); + +if (!i2c_check_functionality (adapter,I2C_FUNC_I2C )) +return -EIO ; + +if (!pdata) { + pdata =is31fl319x_led_dt_init (client, (int ) id->driver_data); +if (IS_ERR (pdata)) { +dev_err (&client->dev,"DT led error %d\n" , + (int )PTR_ERR (pdata)); +return PTR_ERR (pdata); + } + } + is31 =devm_kzalloc (&client->dev,sizeof (*is31),GFP_KERNEL ); +if (!is31) +return -ENOMEM ; + + is31->client = client; +INIT_WORK (&is31->work, is31fl319x_work); +spin_lock_init (&is31->lock); +i2c_set_clientdata (client, is31); + +/* check for reply from chip (we can't read any registers) */ + err =is31fl319x_write (is31,IS31FL319X_SHUTDOWN ,0x01 ); +if (err <0 ) { +dev_err (&client->dev,"no response from chip write: err = %d\n" , + err); +return -EPROBE_DEFER ;/* does not answer (yet) */ + } +drivers/leds/leds-is31fl319x.c line 332
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+for (i =0 ; i <NUM_LEDS ; i++) { +struct is31fl319x_led *l = is31->leds + i; + + l->chip = is31; +if (pdata->leds.leds[i].name && !pdata->leds.leds[i].flags) { + l->led_cdev.name = pdata->leds.leds[i].name; + l->led_cdev.default_trigger + = pdata->leds.leds[i].default_trigger; + l->led_cdev.brightness_set = is31fl319x_brightness_set; + l->led_cdev.blink_set = is31fl319x_blink_set;I don't see led_cdev.brightness_get being set here. Although if you do remove
is31fl319x_brightness_get(), it obviously won't need to be set.drivers/leds/leds-is31fl319x.c line 334
Quoted 2 lines
drivers/leds/leds-is31fl319x.c new file +2
-0+ err =led_classdev_register (&client->dev, + &l->led_cdev);I would suggest using
devm_led_classdev_register(). Then you can remove all the calls toled_classdev_unregister()in error and cleanup paths.Quoted 92 lines
drivers/leds/leds-is31fl319x.c new file +72
-0+if (err <0 ) + goto exit; + } + } + +if (client->dev.of_node) { +u32 val; +u8 config2 =0 ; + +if (of_property_read_u32 (client->dev.of_node,"max-current-ma" , + &val)) { +if (val >40 ) + val =40 ; +if (val <5 ) + val =5 ; + config2 |= (((64 - val) /5 ) &0x7 ) <<4 ;/* CS */ + } +if (of_property_read_u32 (client->dev.of_node,"audio-gain-db" , + &val)) { +if (val >21 ) + val =21 ; + config2 |= val /3 ;/* AGS */ + } +if (config2) +is31fl319x_write (is31,IS31FL319X_CONFIG2 , config2); + } + +schedule_work (&is31->work);/* first update */ + +dev_dbg (&client->dev,"probed\n" ); +return 0 ; +exit: +dev_err (&client->dev,"led error %d\n" , err); + +while (i--) { +if (is31->leds[i].led_cdev.name) +led_classdev_unregister (&is31->leds[i].led_cdev); + } +return err; +} + +static int is31fl319x_remove (struct i2c_client *client) +{ +int i; +struct is31fl319x_chip *is31 =i2c_get_clientdata (client); +struct is31fl319x_led *is31_leds = is31->leds; + +for (i =0 ; i <NUM_LEDS ; i++) { +if (is31_leds[i].led_cdev.name) +led_classdev_unregister (&is31_leds[i].led_cdev); + } + +cancel_work_sync (&is31->work); + +return 0 ; +} + +static struct i2c_driver is31fl319x_driver = { + .driver = { + .name ="leds-is31fl319x" , + .of_match_table =of_match_ptr (of_is31fl319x_leds_match), + }, + .probe = is31fl319x_probe, + .remove = is31fl319x_remove, + .id_table = is31fl319x_id, +}; + +module_i2c_driver (is31fl319x_driver); + +MODULE_AUTHOR ("H. Nikolaus Schaller <[email protected]>" ); +MODULE_DESCRIPTION ("IS31FL319X LED driver" ); +MODULE_LICENSE ("GPL v2" );include/linux/leds-is31fl319x.h new file +14
-0@@ -0,0 +1,24 @@ +/* +* IS31FL3196 LED chip driver. +* +* Copyright (C) 2015 H. Nikolaus Schaller <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +*/ include/linux/leds-is31fl319x.h line 24
Quoted 10 lines
include/linux/leds-is31fl319x.h new file +10
-0+ +#ifndef __LINUX_IS31FL319X_H +#define __LINUX_IS31FL319X_H +#include <linux/leds.h> + +struct is31fl319x_platform_data { +struct led_platform_data leds; +}; + +#endif /* __LINUX_IS31FL319X_H */ --
To unsubscribe from this list: send the line "unsubscribe linux-leds" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] drivers: led: is31fl319x: 6/9-channel light effect led driver
In reply to David Rivshin (Allworx)Hi David,
Quoted 62 lines
Am 19.04.2016 um 03:25 schrieb David Rivshin (Allworx) <[email protected]>:
Hi Nikolaus,
I recently submitted a driver for the IS31FL32xx family of devices, so this driver caught my eye. I have a few comments below.
Quoted 40 lines · On Mon, 18 Apr 2016 20:43:16 +0200 "H. Nikolaus Schaller" <[email protected]>…
This is a driver for the Integrated Silicon Solution Inc. LED driver chips IS31FL3196 and IS31FL3199. They can drive up to 6 or 9 LEDs.
Each LED is individually controllable in brightness (through pwm) in 256 steps so that RGB LEDs can show any of ca. 16 Mio colors.
The maximum current of the LEDs can be programmed and limited to 5 .. 40mA through a device tree property.
The chip is connected through I2C and can have one of 4 addresses (
0x64..0x67) depending on how the AD pin is connected. The address is defined by the reg property as usual.The chip also has a shutdown input which could be connected to a GPIO, but this driver uses software shutdown if all LEDs are inactivated.
The chip also has breathing and audio features which are not supported by this driver.
This driver was developed and tested on OMAP5 based Pyra handheld prototype.
Signed-off-by H. Nikolaus Schaller <[email protected]>---
.../devicetree/bindings/leds/is31fl319x.txt | 41 +++ drivers/leds/Kconfig | 8 + drivers/leds/Makefile | 1 + drivers/leds/leds-is31fl319x.c | 406 +++++++++++++++++++++ include/linux/leds-is31fl319x.h | 24 ++ 5 files changed, 480 insertions(+)create mode 100644
Documentation/devicetree/bindings/leds/is31fl319x.txtcreate mode 100644drivers/leds/leds-is31fl319x.c
create mode 100644include/linux/leds-is31fl319x.hDocumentation/devicetree/bindings/leds/is31fl319x.txt new file +0
-0Documentation/devicetree/bindings/leds/is31fl319x.txt line 4
Quoted 4 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +4
-0@@ -0,0 +1,41 @@ +LEDs connected to is31fl319x RGB LED controller chip + +Required properties: +- compatible : should be : "issi,is31fl3196" or "issi,is31fl3199".From a quick look at the datasheets, I believe the Si-En SN3199 [1] is the same as the ISSI IS31FL3199. ISSI purchased Si-En in 2011, and looks to have rebranded Si-En's existing LED controllers. Assuming the SN3199 is indeed the same as the IS31FL3199, I would suggest adding a compatible string of "si-en,sn3199" both here and in the driver itself (and update the
Kconfigtext as well).
Quoted 1 line
Sounds reasonable. Added.
Quoted 13 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt line 12
Quoted 9 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +8
-0+- #address-cells: must be 1 +- #size-cells: must be 0 +- reg: 0x64, 0x65, 0x66, 0x67. + +Optional properties: +- max-current-ma: maximum led current (5..40 mA, default 20 mA) +- audio-gain-db: audio gain selection (0..21 dB. default 0 dB) +- breathing & audio: not implementedI'm not certain, but that last line feels wrong to me. I would expect to see just defined properties in this section, while that is more commentary. I would just leave it out, myself.
Yes, you are right. We had planned to add something and written the bindings document first but never implemented it (because we don't need it any more).
Quoted 15 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt line 18
Quoted 7 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +6
-0+ +Each led is represented as a sub-node of the issi,is31fl319x device. + +LED sub-node properties: +- label : (optional) see Documentation/devicetree/bindings/leds/common.txt +- reg : number of LED line (0 to 5 or 0 to 8 - not all need to be present)Since the datasheets for these devices name the outputs "OUT1" through "OUT6"/"OUT9", I believe the correct range for the 'reg' property should be 1-6 and 1-9. At least that was the result of a discussion with Rob Herring [2], and therefore how the IS31FL32xx binding/driver was done. It also makes devicetrees easier to write relative to schematics which likely use the OUT1-N naming.
Quoted 1 line
Ok, done.
Quoted 11 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt line 24
Quoted 8 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +6
-0+- linux,default-trigger : (optional) + see Documentation/devicetree/bindings/leds/common.txt + +Examples: + +fancy_leds: is31fl3196@65 {I believe the current preference would be to name the node by its function, rather than the device. For example:
Quoted 1 line
fancy_leds: leds@65
Updated.
Quoted 4 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt line 25
Quoted 2 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +1
-0+ compatible = "issi,is31fl319x";I believe this should be "issi,is31fl3196" here.
Indeed.
Quoted 25 lines
Quoted 25 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +16
-0+ #address-cells = <1>; + #size-cells = <0>; + reg = <0x65>; + + led0: red-aux@0 { + label = "red:aux"; + reg = <0>; + }; + + led1: green-power@4 { + label = "green:power"; + reg = <4>; + linux,default-trigger = "default-on"; + }; +}; +drivers/leds/Kconfig +0
-0@@ -491,6 +491,14 @@ config LEDS_ASIC3 cannot be used. This driver supports hardware blinking with an on+off period from 62ms to 125s. Say Y to enable LEDs on the HP iPAQ hx4700.
Quoted 4 lines
drivers/leds/Kconfig config LEDS_ASIC3 · line 495
Quoted 2 lines
drivers/leds/Kconfig +2
-0+config LEDS_IS31FL319X + tristate "LED Support for IS31FL319x I2C chip"Pedantic: "chips" (plural) seems appropriate here.
:)
Quoted 8 lines
drivers/leds/Kconfig config LEDS_ASIC3 · line 500
Quoted 6 lines
drivers/leds/Kconfig +5
-0+ depends on LEDS_CLASS && I2C + help + This option enables support for LEDs connected to IS31FL3196 + or IS31FL3199 LED driver chips accessed via the I2C bus. + Driver support brightness control and hardware-assisted blinking.Pedantic: "supports" seems appropriate here.
Ok.
Quoted 3 lines
I don't think this matters much, but I'm curious: any reason why this entry is inserted in the middle of the list, rather than at the end?
Hm. Probably by accident. We were working on it for a while and maybe appended it somewhere reasonable and rebasing has moved it around.
Quoted 2 lines
Or better,
right before/after the IS31FL32XX entry?
Ah, we were not aware that it exists. It appeared some weeks ago, right?
Yes, that would be the logical position and IMHO before the FL32.
I have also harmonized the config help with the is21fl32.
Quoted 35 lines
Quoted 10 lines
drivers/leds/Kconfig +1
-0+config
LEDS_TCA6507tristate "LED Support for TCA6507 I2C chip" depends on LEDS_CLASS && I2Cdrivers/leds/Makefile +0
-0@@ -37,6 +37,7 @@ obj-$(CONFIG_LEDS_TCA6507) += leds-tca6507.oQuoted 4 lines
obj-$(CONFIG_LEDS_TLC591XX) += leds-tlc591xx.o
obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o
obj-$(CONFIG_LEDS_IPAQ_MICRO) += leds-ipaq-micro.o
+obj-$(CONFIG_LEDS_IS31FL319X) += leds-is31fl319x.oDitto.
Quoted 18 lines
obj-$(CONFIG_LEDS_HP6XX) += leds-hp6xx.o
obj-$(CONFIG_LEDS_OT200) += leds-ot200.o
obj-$(CONFIG_LEDS_FSG) += leds-fsg.odrivers/leds/leds-is31fl319x.c new file +9
-0@@ -0,0 +1,406 @@ +/* +* Copyright 2015 Golden Delcious Computers +* +* Author: Nikolaus Schaller <[email protected]> +* +* Based on leds-tca6507.c +* +* This file is subject to the terms and conditions of version 2 of +* the GNU General Public License. See the file COPYING in the main
Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 12
Quoted 3 lines
drivers/leds/leds-is31fl319x.c new file +3
-0+* directory of this archive for more details. +* +* LED driver for the IS31FL3196/99 to drive 6 or 9 light effect LEDs. I see that there are also 3190, 3191, and 3193 devices. Is it reasonable to think that support for those devices could be added to this driver in the future? I'm merely thinking of it from the POV that it is named
is31fl319x.c.
I wasn't even aware of the 0/1/3 variants. I have checked with the data sheet and could not find any significant difference except the number of outputs and which output pads are available.
Since there isn't even any difference between the 3190 and 3191 except the date of publication, I assume it is all the same silion die selected after testing. So they package those with broken outputs 7-9 as 3196, with broken outputs 4-6 as 3193 etc. Would be very reasonable from a commecial/chip production point of view.
So I have added all of them to the compatible strings. Since the driver already dynamically takes care of the number of leds it should simply work.
Quoted 60 lines
Quoted 60 lines
drivers/leds/leds-is31fl319x.c new file +59
-0+* +*/ + +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/leds.h> +#include <linux/err.h> +#include <linux/i2c.h> +#include <linux/workqueue.h> +#include <linux/leds-is31fl319x.h> +#include <linux/of.h> + +/* register numbers */ +#define IS31FL319X_SHUTDOWN 0x00 +#define IS31FL319X_CTRL1 0x01 +#define IS31FL319X_CTRL2 0x02 +#define IS31FL319X_CONFIG1 0x03 +#define IS31FL319X_CONFIG2 0x04 +#define IS31FL319X_RAMP_MODE 0x05 +#define IS31FL319X_BREATH_MASK 0x06 +#define IS31FL319X_PWM1 0x07 +#define IS31FL319X_PWM2 0x08 +#define IS31FL319X_PWM3 0x09 +#define IS31FL319X_PWM4 0x0a +#define IS31FL319X_PWM5 0x0b +#define IS31FL319X_PWM6 0x0c +#define IS31FL319X_PWM7 0x0d +#define IS31FL319X_PWM8 0x0e +#define IS31FL319X_PWM9 0x0f +#define IS31FL319X_DATA_UPDATE 0x10 +#define IS31FL319X_T0_1 0x11 +#define IS31FL319X_T0_2 0x12 +#define IS31FL319X_T0_3 0x13 +#define IS31FL319X_T0_4 0x14 +#define IS31FL319X_T0_5 0x15 +#define IS31FL319X_T0_6 0x16 +#define IS31FL319X_T0_7 0x17 +#define IS31FL319X_T0_8 0x18 +#define IS31FL319X_T0_9 0x19 +#define IS31FL319X_T123_1 0x1a +#define IS31FL319X_T123_2 0x1b +#define IS31FL319X_T123_3 0x1c +#define IS31FL319X_T4_1 0x1d +#define IS31FL319X_T4_2 0x1e +#define IS31FL319X_T4_3 0x1f +#define IS31FL319X_T4_4 0x20 +#define IS31FL319X_T4_5 0x21 +#define IS31FL319X_T4_6 0x22 +#define IS31FL319X_T4_7 0x23 +#define IS31FL319X_T4_8 0x24 +#define IS31FL319X_T4_9 0x25 +#define IS31FL319X_TIME_UPDATE 0x26 + +#define IS31FL319X_REG_CNT (IS31FL319X_TIME_UPDATE + 1) + +#define NUM_LEDS 9/* max for 3199 chip */ + +struct is31fl319x_chip { +struct i2c_client *client;
Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 75
Quoted 4 lines
drivers/leds/leds-is31fl319x.c new file +4
-0+struct work_struct work; +bool work_scheduled; +spinlock_t lock; +u8 reg_file[IS31FL319X_REG_CNT ];I would suggest using the regmap infrastructure if you need to cache the register values. It also helpfully exports a debugfs interface.
There was an issue with regmap I don't exactly remember.
Maybe it was because it is impossible to read (initial) values from the chip. Only write new ones. And check for chip presence can also only be done by checking if it responds or fails to a write command. So we would have to use tricks to make regmap work as intended.
And it may introduce overhead in initialization and does not save memory.
Quoted 11 lines
drivers/leds/leds-is31fl319x.c line 85
Quoted 11 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+ +struct is31fl319x_led { +struct is31fl319x_chip *chip; +struct led_classdev led_cdev; + } leds[NUM_LEDS ]; +}; + +static const struct i2c_device_id is31fl319x_id[] = { + {"is31fl3196" ,6 }, + {"is31fl3196" ,9 },
^^^there is also a bug using is31fl3196 twice
Quoted 33 lines
Quoted 33 lines
drivers/leds/leds-is31fl319x.c new file +33
-0+ { } +}; +MODULE_DEVICE_TABLE (i2c, is31fl319x_id); + + +static int is31fl319x_write (struct is31fl319x_chip *is31,u8 reg,u8 byte) +{ +struct i2c_client *cl = is31->client; + +if (reg >=IS31FL319X_REG_CNT ) +return -EIO ; + is31->reg_file[reg] = byte;/* save in cache */ +dev_dbg (&is31->client->dev,"write %02x to reg %02x\n" , byte, reg); +return i2c_smbus_write_byte_data (cl, reg, byte); +} + +static int is31fl319x_read (struct is31fl319x_chip *is31,u8 reg) +{ +if (reg >=IS31FL319X_REG_CNT ) +return -EIO ; +return is31->reg_file[reg];/* read crom cache (can't read chip) */ +} + +static void is31fl319x_work (struct work_struct *work) +{ +struct is31fl319x_chip *is31 =container_of (work, + struct is31fl319x_chip, + work); +unsigned long flags; +int i; +u8 ctrl1, ctrl2; + +dev_dbg (&is31->client->dev,"work called\n" );
Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 123
Quoted 5 lines
drivers/leds/leds-is31fl319x.c new file +5
-0+ +spin_lock_irqsave (&is31->lock, flags); +/* make subsequent changes run another schedule_work */ + is31->work_scheduled = false; +spin_unlock_irqrestore (&is31->lock, flags);I believe the LEDS core now handles the workqueues generically for blocking operations, so it's no longer needed in the individual drivers.
We had a lot of trouble with locking and blocking especially if we want to indicate CPU or (root) disk activity.
So it is implemented in a way that changes can be requested faster than the I2C bus can write new values to the chip.
Only after one sequence of I2C writes is done, another work function can be scheduled. And each group of writes updates as many LEDs in parallel if necessary.
Quoted 24 lines
Quoted 24 lines
drivers/leds/leds-is31fl319x.c new file +23
-0+ +dev_dbg (&is31->client->dev,"write to chip\n" ); + + ctrl1 =0 ; + ctrl2 =0 ; + +for (i =0 ; i <NUM_LEDS ; i++) { +struct led_classdev *led = &is31->leds[i].led_cdev; +bool on; + +if (!is31->leds[i].led_cdev.name) +continue ; + +dev_dbg (&is31->client->dev,"set brightness %u for led %u\n" , + led->brightness, i); + +/* update brightness register */ +is31fl319x_write (is31,IS31FL319X_PWM1 + i, led->brightness); + +/* update output enable bits */ + on = led->brightness >LED_OFF ; +if (i <3 ) + ctrl1 |= on << i;/* 0..2 => bit 0..2 */
Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 151
Quoted 5 lines
drivers/leds/leds-is31fl319x.c new file +5
-0+else if (i <6 ) + ctrl1 |= on << (i+1 );/* 3..5 => bit 4..6 */ +else + ctrl2 |= on << (i-6 );/* 6..8 => bit 0..2 */ + }Is any locking needed while iterating over is31->leds[]? Is there any opportunity for a race?
No, because our locking mechanism ensures that only one work function is running at a time.
Yes there is a small race if a brightness value is updated by an interrupt.
But since the worker is already running, another one will be scheduled that will fix the value. So for an invisibly short moment there might be the wrong value.
Quoted 29 lines
Quoted 29 lines
drivers/leds/leds-is31fl319x.c new file +28
-0+ +/* check if any PWM is enabled or all outputs are now off */ +if (ctrl1 >0 || ctrl2 >0 ) { +dev_dbg (&is31->client->dev,"power up\n" ); +is31fl319x_write (is31,IS31FL319X_CTRL1 , ctrl1); +is31fl319x_write (is31,IS31FL319X_CTRL2 , ctrl2); +/* update PWMs */ +is31fl319x_write (is31,IS31FL319X_DATA_UPDATE ,0x00 ); +/* enable chip from shut down */ +is31fl319x_write (is31,IS31FL319X_SHUTDOWN ,0x01 ); + }else { +dev_dbg (&is31->client->dev,"power down\n" ); +/* shut down */ +is31fl319x_write (is31,IS31FL319X_SHUTDOWN ,0x00 ); + } + +dev_dbg (&is31->client->dev,"work done\n" ); + +} + +/* NOTE: this may be called from within irq context, e.g. led_trigger_event */ + +static int is31fl319x_brightness_get (struct led_classdev *led_cdev) +{ +struct is31fl319x_led *led =container_of (led_cdev, + struct is31fl319x_led, + led_cdev); +struct is31fl319x_chip *is31 = led->chip;
Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 183
Quoted 4 lines
drivers/leds/leds-is31fl319x.c new file +4
-0+ +/* read PWM register */ +return is31fl319x_read (is31,IS31FL319X_PWM1 + (led - is31->leds)); +}I believe that the LEDS core remembers the last set brightness for each LED,
and will use it if nobrightness_getfunction is implemented. Since allis31fl319x_brightness_get()does is retrieve the saved value from your cache, I think you can just eliminateis31fl319x_brightness_get()altogether.
Well, we do not use it as a real getter because as you say the LEDS core remembers it.
But we call it in the setter to determine if there is a change.
Quoted 14 lines
Quoted 4 lines
drivers/leds/leds-is31fl319x.c new file +3
-0+ +static void is31fl319x_brightness_set (struct led_classdev *led_cdev, +enum led_brightness brightness)drivers/leds/leds-is31fl319x.c line 196
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+{ +struct is31fl319x_led *led =container_of (led_cdev, + struct is31fl319x_led, + led_cdev); +struct is31fl319x_chip *is31 = led->chip; +unsigned long flags; + +spin_lock_irqsave (&is31->lock, flags); + +if (brightness !=is31fl319x_brightness_get (led_cdev)) {
Here.
Maybe we could inline the call to is31fl319x_read() and even inline is31fl319x_read because that is also the only location where it is used.
But it removes some inherent layering of the code (lowest level = read/write chip, get = know which registers to read, set = schedule work only if needed).
I have left it as is for the next version. Let's see if there are more comments.
Quoted 12 lines
Quoted 12 lines
drivers/leds/leds-is31fl319x.c new file +12
-0+if (!is31->work_scheduled) { +schedule_work (&is31->work); + is31->work_scheduled = true; + } + } + +spin_unlock_irqrestore (&is31->lock, flags); +} + +static int is31fl319x_blink_set (struct led_classdev *led_cdev, +unsigned long *delay_on, +unsigned long *delay_off)
Quoted 9 lines
drivers/leds/leds-is31fl319x.c line 211
Quoted 3 lines
drivers/leds/leds-is31fl319x.c new file +3
-0+{ +/* use software blink */ +return 1 ;The
Kconfigentry claims hardware blink support. The comment here says the opposite. I believe this current implementation will result in the LEDS core falling back to software blink, but the same result would be achieved by just not setting theblink_setcallback.
Yes, you are right. We wanted to implement HW blinking later. So let's remove it here and from Kconfig.
Quoted 24 lines
Quoted 24 lines
drivers/leds/leds-is31fl319x.c new file +24
-0+} + +#ifdef CONFIG_OF +static struct is31fl319x_platform_data * +is31fl319x_led_dt_init (struct i2c_client *client,int num_leds) +{ +struct device_node *np = client->dev.of_node, *child; +struct is31fl319x_platform_data *pdata; +struct led_info *is31_leds; +int count; + + count =of_get_child_count (np); +dev_dbg (&client->dev,"child count %d\n" , count); +if (!count || count >NUM_LEDS ) +return ERR_PTR (-ENODEV ); + + is31_leds =devm_kzalloc (&client->dev, +sizeof (struct led_info ) *NUM_LEDS ,GFP_KERNEL ); +if (!is31_leds) +return ERR_PTR (-ENOMEM ); + +for_each_child_of_node (np, child) { +struct led_info led; +u32 reg;
Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 241
Quoted 6 lines
drivers/leds/leds-is31fl319x.c new file +6
-0+int ret; + + led.name = +of_get_property (child,"label" ,NULL ) ? : child->name; + led.default_trigger = +of_get_property (child,"linux,default-trigger" ,NULL );I believe it is better to use
of_property_read_string()for these.
Sounds good, because it does some error checks but makes error handling a little more complex (since it is an optional property).
Quoted 14 lines
drivers/leds/leds-is31fl319x.c line 250
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +9
-0+ led.flags =0 ; + ret =of_property_read_u32 (child,"reg" , ®); +dev_dbg (&client->dev,"name = %s reg = %d\n" , led.name, reg); +if (ret !=0 || reg <0 || reg >= num_leds) +continue ; + +if (is31_leds[reg].name) +dev_err (&client->dev,"duplicate led line %d for %s -> %s\n" , + reg, is31_leds[reg].name, led.name);There are two errors (invalid DT) detected here, but the driver continues to load. I believe the preference is for errors like this to result in the probe failing outright.
I regard this type of error as a flaw that does not require the driver to probe completely. It simply uses the last of the duplicate definitions. By looking into the kernel log the error in DT can be easily seen and fixed (instead of wondering why all LEDs remain off).
Quoted 79 lines
Quoted 79 lines
drivers/leds/leds-is31fl319x.c new file +77
-0+ is31_leds[reg] = led; + } + pdata =devm_kzalloc (&client->dev, +sizeof (struct is31fl319x_platform_data ),GFP_KERNEL ); +if (!pdata) +return ERR_PTR (-ENOMEM ); + + pdata->leds.leds = is31_leds; +return pdata; +} + +static const struct of_device_id of_is31fl319x_leds_match[] = { + { .compatible ="issi,is31fl3196" , (void *)6 }, + { .compatible ="issi,is31fl3199" , (void *)9 }, + {}, +}; +MODULE_DEVICE_TABLE (of, of_is31fl319x_leds_match); + +#else +static struct is31fl319x_platform_data * +is31fl319x_led_dt_init (struct i2c_client *client) +{ +return ERR_PTR (-ENODEV ); +} + +#endif + +static int is31fl319x_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +struct is31fl319x_chip *is31; +struct i2c_adapter *adapter; +struct is31fl319x_platform_data *pdata; +int err; +int i =0 ; + + adapter =to_i2c_adapter (client->dev.parent); + pdata =dev_get_platdata (&client->dev); + +dev_dbg (&client->dev,"probe\n" ); + +dev_dbg (&client->dev,"NUM_LEDS = %d num_leds = %d\n" , +NUM_LEDS , (int ) id->driver_data); + +if (!i2c_check_functionality (adapter,I2C_FUNC_I2C )) +return -EIO ; + +if (!pdata) { + pdata =is31fl319x_led_dt_init (client, (int ) id->driver_data); +if (IS_ERR (pdata)) { +dev_err (&client->dev,"DT led error %d\n" , + (int )PTR_ERR (pdata)); +return PTR_ERR (pdata); + } + } + is31 =devm_kzalloc (&client->dev,sizeof (*is31),GFP_KERNEL ); +if (!is31) +return -ENOMEM ; + + is31->client = client; +INIT_WORK (&is31->work, is31fl319x_work); +spin_lock_init (&is31->lock); +i2c_set_clientdata (client, is31); + +/* check for reply from chip (we can't read any registers) */ + err =is31fl319x_write (is31,IS31FL319X_SHUTDOWN ,0x01 ); +if (err <0 ) { +dev_err (&client->dev,"no response from chip write: err = %d\n" , + err); +return -EPROBE_DEFER ;/* does not answer (yet) */ + } + +for (i =0 ; i <NUM_LEDS ; i++) { +struct is31fl319x_led *l = is31->leds + i; + + l->chip = is31; +if (pdata->leds.leds[i].name && !pdata->leds.leds[i].flags) {
Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 332
Quoted 5 lines
drivers/leds/leds-is31fl319x.c new file +5
-0+ l->led_cdev.name = pdata->leds.leds[i].name; + l->led_cdev.default_trigger + = pdata->leds.leds[i].default_trigger; + l->led_cdev.brightness_set = is31fl319x_brightness_set; + l->led_cdev.blink_set = is31fl319x_blink_set;I don't see led_cdev.brightness_get being set here. Although if you do remove
is31fl319x_brightness_get(), it obviously won't need to be set.
Well, it is used in our is31fl319x_brightness_set function so we can't remove it completely.
Quoted 6 lines
drivers/leds/leds-is31fl319x.c line 334
Quoted 3 lines
drivers/leds/leds-is31fl319x.c new file +2
-0+ err =led_classdev_register (&client->dev, + &l->led_cdev);I would suggest using
devm_led_classdev_register(). Then you can remove all the calls toled_classdev_unregister()in error and cleanup paths.
Ok.
Quoted 95 lines
Quoted 95 lines
drivers/leds/leds-is31fl319x.c new file +72
-0+if (err <0 ) + goto exit; + } + } + +if (client->dev.of_node) { +u32 val; +u8 config2 =0 ; + +if (of_property_read_u32 (client->dev.of_node,"max-current-ma" , + &val)) { +if (val >40 ) + val =40 ; +if (val <5 ) + val =5 ; + config2 |= (((64 - val) /5 ) &0x7 ) <<4 ;/* CS */ + } +if (of_property_read_u32 (client->dev.of_node,"audio-gain-db" , + &val)) { +if (val >21 ) + val =21 ; + config2 |= val /3 ;/* AGS */ + } +if (config2) +is31fl319x_write (is31,IS31FL319X_CONFIG2 , config2); + } + +schedule_work (&is31->work);/* first update */ + +dev_dbg (&client->dev,"probed\n" ); +return 0 ; +exit: +dev_err (&client->dev,"led error %d\n" , err); + +while (i--) { +if (is31->leds[i].led_cdev.name) +led_classdev_unregister (&is31->leds[i].led_cdev); + } +return err; +} + +static int is31fl319x_remove (struct i2c_client *client) +{ +int i; +struct is31fl319x_chip *is31 =i2c_get_clientdata (client); +struct is31fl319x_led *is31_leds = is31->leds; + +for (i =0 ; i <NUM_LEDS ; i++) { +if (is31_leds[i].led_cdev.name) +led_classdev_unregister (&is31_leds[i].led_cdev); + } + +cancel_work_sync (&is31->work); + +return 0 ; +} + +static struct i2c_driver is31fl319x_driver = { + .driver = { + .name ="leds-is31fl319x" , + .of_match_table =of_match_ptr (of_is31fl319x_leds_match), + }, + .probe = is31fl319x_probe, + .remove = is31fl319x_remove, + .id_table = is31fl319x_id, +}; + +module_i2c_driver (is31fl319x_driver); + +MODULE_AUTHOR ("H. Nikolaus Schaller <[email protected]>" ); +MODULE_DESCRIPTION ("IS31FL319X LED driver" ); +MODULE_LICENSE ("GPL v2" );include/linux/leds-is31fl319x.h new file +16
-0@@ -0,0 +1,24 @@ +/* +* IS31FL3196 LED chip driver. +* +* Copyright (C) 2015 H. Nikolaus Schaller <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +*/ + +#ifndef __LINUX_IS31FL319X_H
Quoted 9 lines
include/linux/leds-is31fl319x.h line 24
Quoted 8 lines
include/linux/leds-is31fl319x.h new file +8
-0+#define __LINUX_IS31FL319X_H +#include <linux/leds.h> + +struct is31fl319x_platform_data { +struct led_platform_data leds; +}; + +#endif /* __LINUX_IS31FL319X_H */
In the next days I will debug and test the fixes...
BR and thanks,
Nikolaus
Re: [PATCH] drivers: led: is31fl319x: 6/9-channel light effect led driver
Hi Nikolaus,
Quoted 4 lines · H. Nikolaus Schaller
Hi David,
Quoted 1 line
Am 19.04.2016 um 03:25 schrieb David Rivshin (Allworx) <[email protected]>:
[...]
Quoted 11 lines
Quoted 10 lines
drivers/leds/leds-is31fl319x.c line 75
Quoted 6 lines
drivers/leds/leds-is31fl319x.c new file +6
-0+struct is31fl319x_chip { +struct i2c_client *client; +struct work_struct work; +bool work_scheduled; +spinlock_t lock; +u8 reg_file[IS31FL319X_REG_CNT ];I would suggest using the regmap infrastructure if you need to cache the register values. It also helpfully exports a debugfs interface.
Quoted 8 lines
There was an issue with regmap I don't exactly remember.
Maybe it was because it is impossible to read (initial) values from the chip.
Only write new ones. And check for chip presence can also only be done by checking if it responds or fails to a write command. So we would have to use tricks to make regmap work as intended.
Wouldn't it be enough to write Reset Register, to check the device presence? You would hit two birds with one stone, by having registers reset to a known default state, according to the documentation.
Quoted 59 lines
And it may introduce overhead in initialization and does not save memory.
Quoted 11 lines
drivers/leds/leds-is31fl319x.c line 85
Quoted 11 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+ +struct is31fl319x_led { +struct is31fl319x_chip *chip; +struct led_classdev led_cdev; + } leds[NUM_LEDS ]; +}; + +static const struct i2c_device_id is31fl319x_id[] = { + {"is31fl3196" ,6 }, + {"is31fl3196" ,9 },^^^there is also a bug using is31fl3196 twice
Quoted 33 lines
Quoted 33 lines
drivers/leds/leds-is31fl319x.c new file +33
-0+ { } +}; +MODULE_DEVICE_TABLE (i2c, is31fl319x_id); + + +static int is31fl319x_write (struct is31fl319x_chip *is31,u8 reg,u8 byte) +{ +struct i2c_client *cl = is31->client; + +if (reg >=IS31FL319X_REG_CNT ) +return -EIO ; + is31->reg_file[reg] = byte;/* save in cache */ +dev_dbg (&is31->client->dev,"write %02x to reg %02x\n" , byte, reg); +return i2c_smbus_write_byte_data (cl, reg, byte); +} + +static int is31fl319x_read (struct is31fl319x_chip *is31,u8 reg) +{ +if (reg >=IS31FL319X_REG_CNT ) +return -EIO ; +return is31->reg_file[reg];/* read crom cache (can't read chip) */ +} + +static void is31fl319x_work (struct work_struct *work) +{ +struct is31fl319x_chip *is31 =container_of (work, + struct is31fl319x_chip, + work); +unsigned long flags; +int i; +u8 ctrl1, ctrl2; + +dev_dbg (&is31->client->dev,"work called\n" );Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 123
Quoted 5 lines
drivers/leds/leds-is31fl319x.c new file +5
-0+ +spin_lock_irqsave (&is31->lock, flags); +/* make subsequent changes run another schedule_work */ + is31->work_scheduled = false; +spin_unlock_irqrestore (&is31->lock, flags);I believe the LEDS core now handles the workqueues generically for blocking operations, so it's no longer needed in the individual drivers.
Quoted 2 lines
We had a lot of trouble with locking and blocking especially if we want to indicate CPU or (root) disk activity.
What kind of troubles you had? Could you share more details? Does it mean that current LED core design doesn't fit for your use cases?
Quoted 6 lines
So it is implemented in a way that changes can be requested faster than the I2C bus can write new values to the chip.
Only after one sequence of I2C writes is done, another work function can be scheduled. And each group of writes updates as many LEDs in parallel if necessary.
You can serialize the operations in brightness_set_blocking with a mutex.
Quoted 185 lines
Quoted 24 lines
Quoted 24 lines
drivers/leds/leds-is31fl319x.c new file +23
-0+ +dev_dbg (&is31->client->dev,"write to chip\n" ); + + ctrl1 =0 ; + ctrl2 =0 ; + +for (i =0 ; i <NUM_LEDS ; i++) { +struct led_classdev *led = &is31->leds[i].led_cdev; +bool on; + +if (!is31->leds[i].led_cdev.name) +continue ; + +dev_dbg (&is31->client->dev,"set brightness %u for led %u\n" , + led->brightness, i); + +/* update brightness register */ +is31fl319x_write (is31,IS31FL319X_PWM1 + i, led->brightness); + +/* update output enable bits */ + on = led->brightness >LED_OFF ; +if (i <3 ) + ctrl1 |= on << i;/* 0..2 => bit 0..2 */ Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 151
Quoted 5 lines
drivers/leds/leds-is31fl319x.c new file +5
-0+else if (i <6 ) + ctrl1 |= on << (i+1 );/* 3..5 => bit 4..6 */ +else + ctrl2 |= on << (i-6 );/* 6..8 => bit 0..2 */ + }Is any locking needed while iterating over is31->leds[]? Is there any opportunity for a race?
No, because our locking mechanism ensures that only one work function is running at a time.
Yes there is a small race if a brightness value is updated by an interrupt.
But since the worker is already running, another one will be scheduled that will fix the value. So for an invisibly short moment there might be the wrong value.
Quoted 29 lines
Quoted 29 lines
drivers/leds/leds-is31fl319x.c new file +28
-0+ +/* check if any PWM is enabled or all outputs are now off */ +if (ctrl1 >0 || ctrl2 >0 ) { +dev_dbg (&is31->client->dev,"power up\n" ); +is31fl319x_write (is31,IS31FL319X_CTRL1 , ctrl1); +is31fl319x_write (is31,IS31FL319X_CTRL2 , ctrl2); +/* update PWMs */ +is31fl319x_write (is31,IS31FL319X_DATA_UPDATE ,0x00 ); +/* enable chip from shut down */ +is31fl319x_write (is31,IS31FL319X_SHUTDOWN ,0x01 ); + }else { +dev_dbg (&is31->client->dev,"power down\n" ); +/* shut down */ +is31fl319x_write (is31,IS31FL319X_SHUTDOWN ,0x00 ); + } + +dev_dbg (&is31->client->dev,"work done\n" ); + +} + +/* NOTE: this may be called from within irq context, e.g. led_trigger_event */ + +static int is31fl319x_brightness_get (struct led_classdev *led_cdev) +{ +struct is31fl319x_led *led =container_of (led_cdev, + struct is31fl319x_led, + led_cdev); +struct is31fl319x_chip *is31 = led->chip;Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 183
Quoted 4 lines
drivers/leds/leds-is31fl319x.c new file +4
-0+ +/* read PWM register */ +return is31fl319x_read (is31,IS31FL319X_PWM1 + (led - is31->leds)); +}I believe that the LEDS core remembers the last set brightness for each LED,
and will use it if nobrightness_getfunction is implemented. Since allis31fl319x_brightness_get()does is retrieve the saved value from your cache, I think you can just eliminateis31fl319x_brightness_get()altogether.Well, we do not use it as a real getter because as you say the LEDS core remembers it.
But we call it in the setter to determine if there is a change.
Quoted 14 lines
Quoted 4 lines
drivers/leds/leds-is31fl319x.c new file +3
-0+ +static void is31fl319x_brightness_set (struct led_classdev *led_cdev, +enum led_brightness brightness)drivers/leds/leds-is31fl319x.c line 196
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+{ +struct is31fl319x_led *led =container_of (led_cdev, + struct is31fl319x_led, + led_cdev); +struct is31fl319x_chip *is31 = led->chip; +unsigned long flags; + +spin_lock_irqsave (&is31->lock, flags); + +if (brightness !=is31fl319x_brightness_get (led_cdev)) {Here.
Maybe we could inline the call to
is31fl319x_read()and even inlineis31fl319x_readbecause that is also the only location where it is used.But it removes some inherent layering of the code (lowest level = read/write chip, get = know which registers to read, set = schedule work only if needed).
I have left it as is for the next version. Let's see if there are more comments.
Quoted 12 lines
Quoted 12 lines
drivers/leds/leds-is31fl319x.c new file +12
-0+if (!is31->work_scheduled) { +schedule_work (&is31->work); + is31->work_scheduled = true; + } + } + +spin_unlock_irqrestore (&is31->lock, flags); +} + +static int is31fl319x_blink_set (struct led_classdev *led_cdev, +unsigned long *delay_on, +unsigned long *delay_off)Quoted 9 lines
drivers/leds/leds-is31fl319x.c line 211
Quoted 3 lines
drivers/leds/leds-is31fl319x.c new file +3
-0+{ +/* use software blink */ +return 1 ;The
Kconfigentry claims hardware blink support. The comment here says the opposite. I believe this current implementation will result in the LEDS core falling back to software blink, but the same result would be achieved by just not setting theblink_setcallback.Yes, you are right. We wanted to implement HW blinking later. So let's remove it here and from
Kconfig.Quoted 24 lines
Quoted 24 lines
drivers/leds/leds-is31fl319x.c new file +24
-0+} + +#ifdef CONFIG_OF +static struct is31fl319x_platform_data * +is31fl319x_led_dt_init (struct i2c_client *client,int num_leds) +{ +struct device_node *np = client->dev.of_node, *child; +struct is31fl319x_platform_data *pdata; +struct led_info *is31_leds; +int count; + + count =of_get_child_count (np); +dev_dbg (&client->dev,"child count %d\n" , count); +if (!count || count >NUM_LEDS ) +return ERR_PTR (-ENODEV ); + + is31_leds =devm_kzalloc (&client->dev, +sizeof (struct led_info ) *NUM_LEDS ,GFP_KERNEL ); +if (!is31_leds) +return ERR_PTR (-ENOMEM ); + +for_each_child_of_node (np, child) { +struct led_info led; +u32 reg;Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 241
Quoted 6 lines
drivers/leds/leds-is31fl319x.c new file +6
-0+int ret; + + led.name = +of_get_property (child,"label" ,NULL ) ? : child->name; + led.default_trigger = +of_get_property (child,"linux,default-trigger" ,NULL );I believe it is better to use
of_property_read_string()for these.Sounds good, because it does some error checks but makes error handling a little more complex (since it is an optional property).
Quoted 14 lines
drivers/leds/leds-is31fl319x.c line 250
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +9
-0+ led.flags =0 ; + ret =of_property_read_u32 (child,"reg" , ®); +dev_dbg (&client->dev,"name = %s reg = %d\n" , led.name, reg); +if (ret !=0 || reg <0 || reg >= num_leds) +continue ; + +if (is31_leds[reg].name) +dev_err (&client->dev,"duplicate led line %d for %s -> %s\n" , + reg, is31_leds[reg].name, led.name);There are two errors (invalid DT) detected here, but the driver continues to load. I believe the preference is for errors like this to result in the probe failing outright.
Quoted 4 lines
I regard this type of error as a flaw that does not require the driver to probe completely. It simply uses the last of the duplicate definitions. By looking into the kernel log the error in DT can be easily seen and fixed (instead of wondering why all LEDs remain off).
Allowing the probe to continue in case of DT configuration mismatch can defer in time the moment when one realizes that something went wrong while probing. I.e. the affected LED can be configured by user space to be off on init, and effectively the malfunction wouldn't be easily noticeable at first glance.
That's why I prefer to fail on any problem during DT parsing.
Quoted 216 lines
Quoted 80 lines
Quoted 80 lines
drivers/leds/leds-is31fl319x.c new file +77
-0+ is31_leds[reg] = led; + } + pdata =devm_kzalloc (&client->dev, +sizeof (struct is31fl319x_platform_data ),GFP_KERNEL ); +if (!pdata) +return ERR_PTR (-ENOMEM ); + + pdata->leds.leds = is31_leds; +return pdata; +} + +static const struct of_device_id of_is31fl319x_leds_match[] = { + { .compatible ="issi,is31fl3196" , (void *)6 }, + { .compatible ="issi,is31fl3199" , (void *)9 }, + {}, +}; +MODULE_DEVICE_TABLE (of, of_is31fl319x_leds_match); + +#else +static struct is31fl319x_platform_data * +is31fl319x_led_dt_init (struct i2c_client *client) +{ +return ERR_PTR (-ENODEV ); +} + +#endif + +static int is31fl319x_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +struct is31fl319x_chip *is31; +struct i2c_adapter *adapter; +struct is31fl319x_platform_data *pdata; +int err; +int i =0 ; + + adapter =to_i2c_adapter (client->dev.parent); + pdata =dev_get_platdata (&client->dev); + +dev_dbg (&client->dev,"probe\n" ); + +dev_dbg (&client->dev,"NUM_LEDS = %d num_leds = %d\n" , +NUM_LEDS , (int ) id->driver_data); + +if (!i2c_check_functionality (adapter,I2C_FUNC_I2C )) +return -EIO ; + +if (!pdata) { + pdata =is31fl319x_led_dt_init (client, (int ) id->driver_data); +if (IS_ERR (pdata)) { +dev_err (&client->dev,"DT led error %d\n" , + (int )PTR_ERR (pdata)); +return PTR_ERR (pdata); + } + } + is31 =devm_kzalloc (&client->dev,sizeof (*is31),GFP_KERNEL ); +if (!is31) +return -ENOMEM ; + + is31->client = client; +INIT_WORK (&is31->work, is31fl319x_work); +spin_lock_init (&is31->lock); +i2c_set_clientdata (client, is31); + +/* check for reply from chip (we can't read any registers) */ + err =is31fl319x_write (is31,IS31FL319X_SHUTDOWN ,0x01 ); +if (err <0 ) { +dev_err (&client->dev,"no response from chip write: err = %d\n" , + err); +return -EPROBE_DEFER ;/* does not answer (yet) */ + } + +for (i =0 ; i <NUM_LEDS ; i++) { +struct is31fl319x_led *l = is31->leds + i; + + l->chip = is31; +if (pdata->leds.leds[i].name && !pdata->leds.leds[i].flags) {Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 332
Quoted 5 lines
drivers/leds/leds-is31fl319x.c new file +5
-0+ l->led_cdev.name = pdata->leds.leds[i].name; + l->led_cdev.default_trigger + = pdata->leds.leds[i].default_trigger; + l->led_cdev.brightness_set = is31fl319x_brightness_set; + l->led_cdev.blink_set = is31fl319x_blink_set;I don't see led_cdev.brightness_get being set here. Although if you do remove
is31fl319x_brightness_get(), it obviously won't need to be set.Well, it is used in our
is31fl319x_brightness_setfunction so we can't remove it completely.Quoted 6 lines
drivers/leds/leds-is31fl319x.c line 334
Quoted 3 lines
drivers/leds/leds-is31fl319x.c new file +2
-0+ err =led_classdev_register (&client->dev, + &l->led_cdev);I would suggest using
devm_led_classdev_register(). Then you can remove all the calls toled_classdev_unregister()in error and cleanup paths.Ok.
Quoted 95 lines
Quoted 95 lines
drivers/leds/leds-is31fl319x.c new file +72
-0+if (err <0 ) + goto exit; + } + } + +if (client->dev.of_node) { +u32 val; +u8 config2 =0 ; + +if (of_property_read_u32 (client->dev.of_node,"max-current-ma" , + &val)) { +if (val >40 ) + val =40 ; +if (val <5 ) + val =5 ; + config2 |= (((64 - val) /5 ) &0x7 ) <<4 ;/* CS */ + } +if (of_property_read_u32 (client->dev.of_node,"audio-gain-db" , + &val)) { +if (val >21 ) + val =21 ; + config2 |= val /3 ;/* AGS */ + } +if (config2) +is31fl319x_write (is31,IS31FL319X_CONFIG2 , config2); + } + +schedule_work (&is31->work);/* first update */ + +dev_dbg (&client->dev,"probed\n" ); +return 0 ; +exit: +dev_err (&client->dev,"led error %d\n" , err); + +while (i--) { +if (is31->leds[i].led_cdev.name) +led_classdev_unregister (&is31->leds[i].led_cdev); + } +return err; +} + +static int is31fl319x_remove (struct i2c_client *client) +{ +int i; +struct is31fl319x_chip *is31 =i2c_get_clientdata (client); +struct is31fl319x_led *is31_leds = is31->leds; + +for (i =0 ; i <NUM_LEDS ; i++) { +if (is31_leds[i].led_cdev.name) +led_classdev_unregister (&is31_leds[i].led_cdev); + } + +cancel_work_sync (&is31->work); + +return 0 ; +} + +static struct i2c_driver is31fl319x_driver = { + .driver = { + .name ="leds-is31fl319x" , + .of_match_table =of_match_ptr (of_is31fl319x_leds_match), + }, + .probe = is31fl319x_probe, + .remove = is31fl319x_remove, + .id_table = is31fl319x_id, +}; + +module_i2c_driver (is31fl319x_driver); + +MODULE_AUTHOR ("H. Nikolaus Schaller <[email protected]>" ); +MODULE_DESCRIPTION ("IS31FL319X LED driver" ); +MODULE_LICENSE ("GPL v2" );include/linux/leds-is31fl319x.h new file +16
-0@@ -0,0 +1,24 @@ +/* +* IS31FL3196 LED chip driver. +* +* Copyright (C) 2015 H. Nikolaus Schaller <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +*/ + +#ifndef __LINUX_IS31FL319X_HQuoted 9 lines
include/linux/leds-is31fl319x.h line 24
Quoted 8 lines
include/linux/leds-is31fl319x.h new file +8
-0+#define __LINUX_IS31FL319X_H +#include <linux/leds.h> + +struct is31fl319x_platform_data { +struct led_platform_data leds; +}; + +#endif /* __LINUX_IS31FL319X_H */ In the next days I will debug and test the fixes...
BR and thanks,
Nikolaus--
To unsubscribe from this list: send the line "unsubscribe linux-leds" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Best regards, Jacek Anaszewski
Re: [PATCH] drivers: led: is31fl319x: 6/9-channel light effect led driver
Hi,
finally, I found the time to update the driver according to the many comments received a while ago.
Most of them have been worked in, including the regmap idea and brightness_set_blocking().
The driver works on our system, so that I will mail [PATCH v2] as a followup.
There is only one aspect of the new solution I am not sure if it is really better than our old proposal (see below).
Quoted 6 lines
Am 20.04.2016 um 23:04 schrieb Jacek Anaszewski <[email protected]>:
Quoted 3 lines · H. Nikolaus Schaller
Quoted 2 lines
I believe the LEDS core now handles the workqueues generically for blocking operations, so it's no longer needed in the individual drivers.
Quoted 6 lines
Quoted 2 lines
We had a lot of trouble with locking and blocking especially if we want to indicate CPU or (root) disk activity.
What kind of troubles you had? Could you share more details? Does it mean that current LED core design doesn't fit for your use cases?
The system started to flicker the LEDs irregularily and sometimes the whole kernel stalled.
Quoted 10 lines
Quoted 7 lines
So it is implemented in a way that changes can be requested faster than the I2C bus can write new values to the chip.
Only after one sequence of I2C writes is done, another work function can be scheduled. And each group of writes updates as many LEDs in parallel if necessary.
You can serialize the operations in
brightness_set_blockingwith a mutex.
Yes, that works fine in our (incomplete) test setup.
But I think it assumes that the i2c bus is never congested by other i2c traffic.
I have not found code that obviously takes care of the situation if led trigger events (e.g. mmc or cpu triggers) are coming in faster than the i2c (even using regmap) can write out over i2c.
If I understand the led core code correctly, it will just do another schedule_work for every single change of led brightness.
So I wonder if Is there some guarantee that this work queue will not fill up memory and is really processed faster than being filled? I.e. can the queue overflow?
To reduce this risk, my original implementation strategy was different. The update speed was limited by i2c writing. A new register update batch job was only scheduled if the previous one is finished. If i2c was blocked/congested, the writing worker thread would come to a halt.
All incoming led brightness changes were simply accumulated until a new batch job is started, because LEDs would anyways flicker invisibly fast.
Tests with the new driver have shown that it seems not to run into this situation on our system but it might depend on factors we have not yet tested (slow i2c, other i2c traffic on the same bus, CPU speed, event types choosen).
So I am a little in doubt about this risk. But I may have simply missed the reason why the standard approach works and can never overflow.
BR,
Nikolaus
Re: [PATCH] drivers: led: is31fl319x: 6/9-channel light effect led driver
Hi Nikolaus,
Quoted 42 lines · H. Nikolaus Schaller
Hi,
finally, I found the time to update the driver according to the many comments received a while ago.Most of them have been worked in, including the regmap idea and
brightness_set_blocking().The driver works on our system, so that I will mail [PATCH v2] as a followup.
There is only one aspect of the new solution I am not sure if it is really better than our old proposal (see below).
Quoted 6 lines
Am 20.04.2016 um 23:04 schrieb Jacek Anaszewski <[email protected]>:
Quoted 3 lines · H. Nikolaus Schaller
Quoted 2 lines
I believe the LEDS core now handles the workqueues generically for blocking operations, so it's no longer needed in the individual drivers.
Quoted 6 lines
Quoted 2 lines
We had a lot of trouble with locking and blocking especially if we want to indicate CPU or (root) disk activity.
What kind of troubles you had? Could you share more details? Does it mean that current LED core design doesn't fit for your use cases?
The system started to flicker the LEDs irregularily and sometimes the whole kernel stalled.
Quoted 10 lines
Quoted 7 lines
So it is implemented in a way that changes can be requested faster than the I2C bus can write new values to the chip.
Only after one sequence of I2C writes is done, another work function can be scheduled. And each group of writes updates as many LEDs in parallel if necessary.
You can serialize the operations in
brightness_set_blockingwith a mutex.Yes, that works fine in our (incomplete) test setup.
Quoted 8 lines
But I think it assumes that the i2c bus is never congested by other i2c traffic.
I have not found code that obviously takes care of the situation if led trigger events (e.g. mmc or cpu triggers) are coming in faster than the i2c (even using regmap) can write out over i2c.
If I understand the led core code correctly, it will just do another
schedule_workfor every single change of led brightness.
Please look at schedule_work documentation in include/linux/workqueue.h:
/**
* schedule_work - put work task in global workqueue
* @work: job to be done
*
* Returns %false if @work was already on the kernel-global workqueue and
* %true otherwise.
*
* This puts a job in the kernel-global workqueue if it was not already
* queued and leaves it in the same position on the kernel-global
* workqueue otherwise.
*/
static inline bool schedule_work(struct work_struct *work)
{
return queue_work(system_wq, work);
}Quoted 25 lines
So I wonder if Is there some guarantee that this work queue will not fill up memory and is really processed faster than being filled? I.e. can the queue overflow?
To reduce this risk, my original implementation strategy was different. The update speed was limited by i2c writing. A new register update batch job was only scheduled if the previous one is finished. If i2c was blocked/congested, the writing worker thread would come to a halt.
All incoming led brightness changes were simply accumulated until a new batch job is started, because LEDs would anyways flicker invisibly fast.
Tests with the new driver have shown that it seems not to run into this situation on our system but it might depend on factors we have not yet tested (slow i2c, other i2c traffic on the same bus, CPU speed, event types choosen).
So I am a little in doubt about this risk. But I may have simply missed the reason why the standard approach works and can never overflow.
BR,
Nikolaus
Signature · 2 lines
Best regards, Jacek Anaszewski
Re: [PATCH] drivers: led: is31fl319x: 6/9-channel light effect led driver
Hi,
Quoted 58 lines
Am 07.07.2016 um 10:46 schrieb Jacek Anaszewski <[email protected]>:
Hi Nikolaus,
Quoted 42 lines · H. Nikolaus Schaller
Hi,
finally, I found the time to update the driver according to the many comments received a while ago.Most of them have been worked in, including the regmap idea and
brightness_set_blocking().The driver works on our system, so that I will mail [PATCH v2] as a followup.
There is only one aspect of the new solution I am not sure if it is really better than our old proposal (see below).
Quoted 6 lines
Am 20.04.2016 um 23:04 schrieb Jacek Anaszewski <[email protected]>:
Quoted 3 lines · H. Nikolaus Schaller
Quoted 2 lines
I believe the LEDS core now handles the workqueues generically for blocking operations, so it's no longer needed in the individual drivers.
Quoted 6 lines
Quoted 2 lines
We had a lot of trouble with locking and blocking especially if we want to indicate CPU or (root) disk activity.
What kind of troubles you had? Could you share more details? Does it mean that current LED core design doesn't fit for your use cases?
The system started to flicker the LEDs irregularily and sometimes the whole kernel stalled.
Quoted 10 lines
Quoted 7 lines
So it is implemented in a way that changes can be requested faster than the I2C bus can write new values to the chip.
Only after one sequence of I2C writes is done, another work function can be scheduled. And each group of writes updates as many LEDs in parallel if necessary.
You can serialize the operations in
brightness_set_blockingwith a mutex.Yes, that works fine in our (incomplete) test setup.
Quoted 8 lines
But I think it assumes that the i2c bus is never congested by other i2c traffic.
I have not found code that obviously takes care of the situation if led trigger events (e.g. mmc or cpu triggers) are coming in faster than the i2c (even using regmap) can write out over i2c.
If I understand the led core code correctly, it will just do another
schedule_workfor every single change of led brightness.Please look at
schedule_workdocumentation ininclude/linux/workqueue.h:
Quoted 8 lines
/**
*schedule_work- put work task in global workqueue
* @work: job to be done
*
* Returns %false if @work was already on the kernel-global workqueue and
* %true otherwise.
*
* This puts a job in the kernel-global workqueue if it was not already
Ah, ok. I missed that. Thanks!
Quoted 39 lines
* queued and leaves it in the same position on the kernel-global
* workqueue otherwise.
*/
static inline boolschedule_work(struct work_struct *work){ return queue_work(system_wq, work); }Quoted 25 lines
So I wonder if Is there some guarantee that this work queue will not fill up memory and is really processed faster than being filled? I.e. can the queue overflow?
To reduce this risk, my original implementation strategy was different. The update speed was limited by i2c writing. A new register update batch job was only scheduled if the previous one is finished. If i2c was blocked/congested, the writing worker thread would come to a halt.
All incoming led brightness changes were simply accumulated until a new batch job is started, because LEDs would anyways flicker invisibly fast.
Tests with the new driver have shown that it seems not to run into this situation on our system but it might depend on factors we have not yet tested (slow i2c, other i2c traffic on the same bus, CPU speed, event types choosen).
So I am a little in doubt about this risk. But I may have simply missed the reason why the standard approach works and can never overflow.
BR,
NikolausSignature · 2 lines
Best regards, Jacek Anaszewski
Re: [PATCH] drivers: led: is31fl319x: 6/9-channel light effect led driver
In reply to Jacek AnaszewskiHi,
finally, I found the time to update the driver according to the many comments received a while ago.
Most of them have been worked in, including the regmap idea and brightness_set_blocking().
The driver works on our system, so that I will mail [PATCH v2] as a followup.
There is only one aspect of the new solution I am not sure if it is really better than our old proposal (see below).
Quoted 6 lines
Am 20.04.2016 um 23:04 schrieb Jacek Anaszewski <[email protected]>:
Quoted 3 lines · H. Nikolaus Schaller
Quoted 2 lines
I believe the LEDS core now handles the workqueues generically for blocking operations, so it's no longer needed in the individual drivers.
Quoted 6 lines
Quoted 2 lines
We had a lot of trouble with locking and blocking especially if we want to indicate CPU or (root) disk activity.
What kind of troubles you had? Could you share more details? Does it mean that current LED core design doesn't fit for your use cases?
The system started to flicker the LEDs irregularily and sometimes the whole kernel stalled.
Quoted 10 lines
Quoted 7 lines
So it is implemented in a way that changes can be requested faster than the I2C bus can write new values to the chip.
Only after one sequence of I2C writes is done, another work function can be scheduled. And each group of writes updates as many LEDs in parallel if necessary.
You can serialize the operations in
brightness_set_blockingwith a mutex.
Yes, that works fine in our (incomplete) test setup.
But I think it assumes that the i2c bus is never congested by other i2c traffic.
I have not found code that obviously takes care of the situation if led trigger events (e.g. mmc or cpu triggers) are coming in faster than the i2c (even using regmap) can write out over i2c.
If I understand the led core code correctly, it will just do another schedule_work for every single change of led brightness.
So I wonder if Is there some guarantee that this work queue will not fill up memory and is really processed faster than being filled? I.e. can the queue overflow?
To reduce this risk, my original implementation strategy was different. The update speed was limited by i2c writing. A new register update batch job was only scheduled if the previous one is finished. If i2c was blocked/congested, the writing worker thread would come to a halt.
All incoming led brightness changes were simply accumulated until a new batch job is started, because LEDs would anyways flicker invisibly fast.
Tests with the new driver have shown that it seems not to run into this situation on our system but it might depend on factors we have not yet tested (slow i2c, other i2c traffic on the same bus, CPU speed, event types choosen).
So I am a little in doubt about this risk. But I may have simply missed the reason why the standard approach works and can never overflow.
BR,
Nikolaus
Re: [PATCH] drivers: led: is31fl319x: 6/9-channel light effect led driver
In reply to H. Nikolaus SchallerHi Nikolaus,
Thanks for the patch. Please refer to my remarks in the code.
Quoted 40 lines · H. Nikolaus Schaller
This is a driver for the Integrated Silicon Solution Inc. LED driver chips IS31FL3196 and IS31FL3199. They can drive up to 6 or 9 LEDs.
Each LED is individually controllable in brightness (through pwm) in 256 steps so that RGB LEDs can show any of ca. 16 Mio colors.
The maximum current of the LEDs can be programmed and limited to 5 .. 40mA through a device tree property.
The chip is connected through I2C and can have one of 4 addresses (
0x64..0x67) depending on how the AD pin is connected. The address is defined by the reg property as usual.The chip also has a shutdown input which could be connected to a GPIO, but this driver uses software shutdown if all LEDs are inactivated.
The chip also has breathing and audio features which are not supported by this driver.
This driver was developed and tested on OMAP5 based Pyra handheld prototype.
Signed-off-by H. Nikolaus Schaller <[email protected]>--- .../devicetree/bindings/leds/is31fl319x.txt | 41 +++ drivers/leds/Kconfig | 8 + drivers/leds/Makefile | 1 + drivers/leds/leds-is31fl319x.c | 406 +++++++++++++++++++++ include/linux/leds-is31fl319x.h | 24 ++ 5 files changed, 480 insertions(+)create mode 100644
Documentation/devicetree/bindings/leds/is31fl319x.txtcreate mode 100644drivers/leds/leds-is31fl319x.c
create mode 100644include/linux/leds-is31fl319x.hDocumentation/devicetree/bindings/leds/is31fl319x.txt new file +0
-0
Documentation/devicetree/bindings/leds/is31fl319x.txt line 4
Quoted 4 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +4
-0@@ -0,0 +1,41 @@ +LEDs connected to is31fl319x RGB LED controller chip + +Required properties: +- compatible : should be : "issi,is31fl3196" or "issi,is31fl3199".
s/should be :/Should be/
Documentation/devicetree/bindings/leds/is31fl319x.txt line 6
Quoted 2 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +2
-0+- #address-cells: must be 1 +- #size-cells: must be 0
s/must/Must/
Please begin the property description with a capital letter, and also end it with a dot.
This remark applies also to the other properties.
Documentation/devicetree/bindings/leds/is31fl319x.txt line 10
Quoted 4 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +4
-0+- reg: 0x64, 0x65, 0x66, 0x67. + +Optional properties: +- max-current-ma: maximum led current (5..40 mA, default 20 mA)
There is leds-max-microamp property for this - see Documentation/devicetree/bindings/leds/common.txt. I'd rephrase this as follows:
- led-max-microamp: See Documentation/devicetree/bindings/leds/common.txt.
Valid values: 50000 - 400000, step by (?) (rounded {up|down})
Default: 20000Documentation/devicetree/bindings/leds/is31fl319x.txt line 11
Quoted 1 line
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +1
-0+- audio-gain-db: audio gain selection (0..21 dB. default 0 dB)
Please follow the aforementioned "Valid values" pattern. It would also be nice to have more informative description on the purpose of this property.
Documentation/devicetree/bindings/leds/is31fl319x.txt line 12
Quoted 1 line
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +1
-0+- breathing & audio: not implemented
There is no point in documenting unused properties.
Quoted 18 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +18
-0+ +Each led is represented as a sub-node of the issi,is31fl319x device. + +LED sub-node properties: +- label : (optional) see Documentation/devicetree/bindings/leds/common.txt +- reg : number of LED line (0 to 5 or 0 to 8 - not all need to be present) +- linux,default-trigger : (optional) + see Documentation/devicetree/bindings/leds/common.txt + +Examples: + +fancy_leds: is31fl3196@65 { + compatible = "issi,is31fl319x"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x65>; + + led0: red-aux@0 {
Documentation/devicetree/bindings/leds/is31fl319x.txt line 40
Quoted 10 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +10
-0+ label = "red:aux"; + reg = <0>; + }; + + led1: green-power@4 { + label = "green:power"; + reg = <4>; + linux,default-trigger = "default-on"; + }; +};
Generally I prefer to have DT bindings documentation in a separate patch.
Quoted 50 lines
drivers/leds/Kconfig +8
-0@@ -491,6 +491,14 @@ config LEDS_ASIC3 cannot be used. This driver supports hardware blinking with an on+off period from 62ms to 125s. Say Y to enable LEDs on the HP iPAQ hx4700. +config LEDS_IS31FL319X + tristate "LED Support for IS31FL319x I2C chip" + depends on LEDS_CLASS && I2C + help + This option enables support for LEDs connected to IS31FL3196 + or IS31FL3199 LED driver chips accessed via the I2C bus. + Driver support brightness control and hardware-assisted blinking. + config LEDS_TCA6507 tristate "LED Support for TCA6507 I2C chip" depends on LEDS_CLASS && I2Cdrivers/leds/Makefile +1
-0@@ -37,6 +37,7 @@ obj-$(CONFIG_LEDS_TCA6507) += leds-tca6507.o obj-$(CONFIG_LEDS_TLC591XX) += leds-tlc591xx.o obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o obj-$(CONFIG_LEDS_IPAQ_MICRO) += leds-ipaq-micro.o +obj-$(CONFIG_LEDS_IS31FL319X) += leds-is31fl319x.o obj-$(CONFIG_LEDS_HP6XX) += leds-hp6xx.o obj-$(CONFIG_LEDS_OT200) += leds-ot200.o obj-$(CONFIG_LEDS_FSG) += leds-fsg.odrivers/leds/leds-is31fl319x.c new file +13
-0@@ -0,0 +1,406 @@ +/* +* Copyright 2015 Golden Delcious Computers +* +* Author: Nikolaus Schaller <[email protected]> +* +* Based on leds-tca6507.c +* +* This file is subject to the terms and conditions of version 2 of +* the GNU General Public License. See the file COPYING in the main +* directory of this archive for more details. +* +* LED driver for the IS31FL3196/99 to drive 6 or 9 light effect LEDs. +*
drivers/leds/leds-is31fl319x.c line 23
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+*/ + +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/leds.h> +#include <linux/err.h> +#include <linux/i2c.h> +#include <linux/workqueue.h> +#include <linux/leds-is31fl319x.h> +#include <linux/of.h>
Please keep include directives in an alphabetical order.
Quoted 111 lines
drivers/leds/leds-is31fl319x.c new file +111
-0+ +/* register numbers */ +#define IS31FL319X_SHUTDOWN 0x00 +#define IS31FL319X_CTRL1 0x01 +#define IS31FL319X_CTRL2 0x02 +#define IS31FL319X_CONFIG1 0x03 +#define IS31FL319X_CONFIG2 0x04 +#define IS31FL319X_RAMP_MODE 0x05 +#define IS31FL319X_BREATH_MASK 0x06 +#define IS31FL319X_PWM1 0x07 +#define IS31FL319X_PWM2 0x08 +#define IS31FL319X_PWM3 0x09 +#define IS31FL319X_PWM4 0x0a +#define IS31FL319X_PWM5 0x0b +#define IS31FL319X_PWM6 0x0c +#define IS31FL319X_PWM7 0x0d +#define IS31FL319X_PWM8 0x0e +#define IS31FL319X_PWM9 0x0f +#define IS31FL319X_DATA_UPDATE 0x10 +#define IS31FL319X_T0_1 0x11 +#define IS31FL319X_T0_2 0x12 +#define IS31FL319X_T0_3 0x13 +#define IS31FL319X_T0_4 0x14 +#define IS31FL319X_T0_5 0x15 +#define IS31FL319X_T0_6 0x16 +#define IS31FL319X_T0_7 0x17 +#define IS31FL319X_T0_8 0x18 +#define IS31FL319X_T0_9 0x19 +#define IS31FL319X_T123_1 0x1a +#define IS31FL319X_T123_2 0x1b +#define IS31FL319X_T123_3 0x1c +#define IS31FL319X_T4_1 0x1d +#define IS31FL319X_T4_2 0x1e +#define IS31FL319X_T4_3 0x1f +#define IS31FL319X_T4_4 0x20 +#define IS31FL319X_T4_5 0x21 +#define IS31FL319X_T4_6 0x22 +#define IS31FL319X_T4_7 0x23 +#define IS31FL319X_T4_8 0x24 +#define IS31FL319X_T4_9 0x25 +#define IS31FL319X_TIME_UPDATE 0x26 + +#define IS31FL319X_REG_CNT (IS31FL319X_TIME_UPDATE + 1) + +#define NUM_LEDS 9/* max for 3199 chip */ + +struct is31fl319x_chip { +struct i2c_client *client; +struct work_struct work; +bool work_scheduled; +spinlock_t lock; +u8 reg_file[IS31FL319X_REG_CNT ]; + +struct is31fl319x_led { +struct is31fl319x_chip *chip; +struct led_classdev led_cdev; + } leds[NUM_LEDS ]; +}; + +static const struct i2c_device_id is31fl319x_id[] = { + {"is31fl3196" ,6 }, + {"is31fl3196" ,9 }, + { } +}; +MODULE_DEVICE_TABLE (i2c, is31fl319x_id); + + +static int is31fl319x_write (struct is31fl319x_chip *is31,u8 reg,u8 byte) +{ +struct i2c_client *cl = is31->client; + +if (reg >=IS31FL319X_REG_CNT ) +return -EIO ; + is31->reg_file[reg] = byte;/* save in cache */ +dev_dbg (&is31->client->dev,"write %02x to reg %02x\n" , byte, reg); +return i2c_smbus_write_byte_data (cl, reg, byte); +} + +static int is31fl319x_read (struct is31fl319x_chip *is31,u8 reg) +{ +if (reg >=IS31FL319X_REG_CNT ) +return -EIO ; +return is31->reg_file[reg];/* read crom cache (can't read chip) */ +} + +static void is31fl319x_work (struct work_struct *work) +{ +struct is31fl319x_chip *is31 =container_of (work, + struct is31fl319x_chip, + work); +unsigned long flags; +int i; +u8 ctrl1, ctrl2; + +dev_dbg (&is31->client->dev,"work called\n" ); + +spin_lock_irqsave (&is31->lock, flags); +/* make subsequent changes run another schedule_work */ + is31->work_scheduled = false; +spin_unlock_irqrestore (&is31->lock, flags); + +dev_dbg (&is31->client->dev,"write to chip\n" ); + + ctrl1 =0 ; + ctrl2 =0 ; + +for (i =0 ; i <NUM_LEDS ; i++) { +struct led_classdev *led = &is31->leds[i].led_cdev; +bool on; + +if (!is31->leds[i].led_cdev.name)
drivers/leds/leds-is31fl319x.c line 144
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+continue ; + +dev_dbg (&is31->client->dev,"set brightness %u for led %u\n" , + led->brightness, i); + +/* update brightness register */ +is31fl319x_write (is31,IS31FL319X_PWM1 + i, led->brightness); + +/* update output enable bits */ + on = led->brightness >LED_OFF ;
It's more common to achieve the same in the following way:
on = !!led->brightness;
drivers/leds/leds-is31fl319x.c line 151
Quoted 7 lines
drivers/leds/leds-is31fl319x.c new file +7
-0+if (i <3 ) + ctrl1 |= on << i;/* 0..2 => bit 0..2 */ +else if (i <6 ) + ctrl1 |= on << (i+1 );/* 3..5 => bit 4..6 */ +else + ctrl2 |= on << (i-6 );/* 6..8 => bit 0..2 */ + }
Why are you iterating over all sub-LEDs? One LED class device should control single sub-LED/iout.
Quoted 35 lines
drivers/leds/leds-is31fl319x.c new file +35
-0+ +/* check if any PWM is enabled or all outputs are now off */ +if (ctrl1 >0 || ctrl2 >0 ) { +dev_dbg (&is31->client->dev,"power up\n" ); +is31fl319x_write (is31,IS31FL319X_CTRL1 , ctrl1); +is31fl319x_write (is31,IS31FL319X_CTRL2 , ctrl2); +/* update PWMs */ +is31fl319x_write (is31,IS31FL319X_DATA_UPDATE ,0x00 ); +/* enable chip from shut down */ +is31fl319x_write (is31,IS31FL319X_SHUTDOWN ,0x01 ); + }else { +dev_dbg (&is31->client->dev,"power down\n" ); +/* shut down */ +is31fl319x_write (is31,IS31FL319X_SHUTDOWN ,0x00 ); + } + +dev_dbg (&is31->client->dev,"work done\n" ); + +} + +/* NOTE: this may be called from within irq context, e.g. led_trigger_event */ + +static int is31fl319x_brightness_get (struct led_classdev *led_cdev) +{ +struct is31fl319x_led *led =container_of (led_cdev, + struct is31fl319x_led, + led_cdev); +struct is31fl319x_chip *is31 = led->chip; + +/* read PWM register */ +return is31fl319x_read (is31,IS31FL319X_PWM1 + (led - is31->leds)); +} + +static void is31fl319x_brightness_set (struct led_classdev *led_cdev, +enum led_brightness brightness)
drivers/leds/leds-is31fl319x.c line 196
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+{ +struct is31fl319x_led *led =container_of (led_cdev, + struct is31fl319x_led, + led_cdev); +struct is31fl319x_chip *is31 = led->chip; +unsigned long flags; + +spin_lock_irqsave (&is31->lock, flags); + +if (brightness !=is31fl319x_brightness_get (led_cdev)) {
Current brightness is cached in led_cdev->brightness.
Quoted 6 lines
drivers/leds/leds-is31fl319x.c new file +6
-0+if (!is31->work_scheduled) { +schedule_work (&is31->work); + is31->work_scheduled = true; + } + } +
drivers/leds/leds-is31fl319x.c line 212
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+spin_unlock_irqrestore (&is31->lock, flags); +} + +static int is31fl319x_blink_set (struct led_classdev *led_cdev, +unsigned long *delay_on, +unsigned long *delay_off) +{ +/* use software blink */ +return 1 ; +}
This function is useless, please remove it.
drivers/leds/leds-is31fl319x.c line 214
Quoted 1 line
drivers/leds/leds-is31fl319x.c new file +1
-0+#ifdef CONFIG_OF
Please provide only version for CONFIG_OF defined case and just fail probing if of_node is NULL.
drivers/leds/leds-is31fl319x.c line 216
Quoted 2 lines
drivers/leds/leds-is31fl319x.c new file +2
-0+static struct is31fl319x_platform_data * +is31fl319x_led_dt_init (struct i2c_client *client,int num_leds)
Please rename it to is31fl319x_parse_dt.
Quoted 67 lines
drivers/leds/leds-is31fl319x.c new file +67
-0+{ +struct device_node *np = client->dev.of_node, *child; +struct is31fl319x_platform_data *pdata; +struct led_info *is31_leds; +int count; + + count =of_get_child_count (np); +dev_dbg (&client->dev,"child count %d\n" , count); +if (!count || count >NUM_LEDS ) +return ERR_PTR (-ENODEV ); + + is31_leds =devm_kzalloc (&client->dev, +sizeof (struct led_info ) *NUM_LEDS ,GFP_KERNEL ); +if (!is31_leds) +return ERR_PTR (-ENOMEM ); + +for_each_child_of_node (np, child) { +struct led_info led; +u32 reg; +int ret; + + led.name = +of_get_property (child,"label" ,NULL ) ? : child->name; + led.default_trigger = +of_get_property (child,"linux,default-trigger" ,NULL ); + led.flags =0 ; + ret =of_property_read_u32 (child,"reg" , ®); +dev_dbg (&client->dev,"name = %s reg = %d\n" , led.name, reg); +if (ret !=0 || reg <0 || reg >= num_leds) +continue ; + +if (is31_leds[reg].name) +dev_err (&client->dev,"duplicate led line %d for %s -> %s\n" , + reg, is31_leds[reg].name, led.name); + is31_leds[reg] = led; + } + pdata =devm_kzalloc (&client->dev, +sizeof (struct is31fl319x_platform_data ),GFP_KERNEL ); +if (!pdata) +return ERR_PTR (-ENOMEM ); + + pdata->leds.leds = is31_leds; +return pdata; +} + +static const struct of_device_id of_is31fl319x_leds_match[] = { + { .compatible ="issi,is31fl3196" , (void *)6 }, + { .compatible ="issi,is31fl3199" , (void *)9 }, + {}, +}; +MODULE_DEVICE_TABLE (of, of_is31fl319x_leds_match); + +#else +static struct is31fl319x_platform_data * +is31fl319x_led_dt_init (struct i2c_client *client) +{ +return ERR_PTR (-ENODEV ); +} + +#endif + +static int is31fl319x_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +struct is31fl319x_chip *is31; +struct i2c_adapter *adapter; +struct is31fl319x_platform_data *pdata;
drivers/leds/leds-is31fl319x.c line 293
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+int err; +int i =0 ; + + adapter =to_i2c_adapter (client->dev.parent); + pdata =dev_get_platdata (&client->dev); + +dev_dbg (&client->dev,"probe\n" ); + +dev_dbg (&client->dev,"NUM_LEDS = %d num_leds = %d\n" , +NUM_LEDS , (int ) id->driver_data);
I believe this is stray debug logging.
drivers/leds/leds-is31fl319x.c line 301
Quoted 8 lines
drivers/leds/leds-is31fl319x.c new file +8
-0+ +if (!i2c_check_functionality (adapter,I2C_FUNC_I2C )) +return -EIO ; + +if (!pdata) { + pdata =is31fl319x_led_dt_init (client, (int ) id->driver_data); +if (IS_ERR (pdata)) { + dev_err(&client->dev, "DT led error %d\n",
s/DT led error/DT parsing error/
Quoted 9 lines
drivers/leds/leds-is31fl319x.c new file +9
-0+ (int) PTR_ERR(pdata)); +return PTR_ERR (pdata); + } + } + is31 =devm_kzalloc (&client->dev,sizeof (*is31),GFP_KERNEL ); +if (!is31) +return -ENOMEM ; + + is31->client = client;
drivers/leds/leds-is31fl319x.c line 320
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+INIT_WORK (&is31->work, is31fl319x_work); +spin_lock_init (&is31->lock); +i2c_set_clientdata (client, is31); + +/* check for reply from chip (we can't read any registers) */ + err =is31fl319x_write (is31,IS31FL319X_SHUTDOWN ,0x01 ); +if (err <0 ) { +dev_err (&client->dev,"no response from chip write: err = %d\n" , + err); +return -EPROBE_DEFER ;/* does not answer (yet) */
When can it happen? Does the chip have a long booting time or so?
Quoted 30 lines
drivers/leds/leds-is31fl319x.c new file +30
-0+ } + +for (i =0 ; i <NUM_LEDS ; i++) { +struct is31fl319x_led *l = is31->leds + i; + + l->chip = is31; +if (pdata->leds.leds[i].name && !pdata->leds.leds[i].flags) { + l->led_cdev.name = pdata->leds.leds[i].name; + l->led_cdev.default_trigger + = pdata->leds.leds[i].default_trigger; + l->led_cdev.brightness_set = is31fl319x_brightness_set; + l->led_cdev.blink_set = is31fl319x_blink_set; + err =led_classdev_register (&client->dev, + &l->led_cdev); +if (err <0 ) + goto exit; + } + } + +if (client->dev.of_node) { +u32 val; +u8 config2 =0 ; + +if (of_property_read_u32 (client->dev.of_node,"max-current-ma" , + &val)) { +if (val >40 ) + val =40 ; +if (val <5 ) + val =5 ; + config2 |= (((64 - val) /5 ) &0x7 ) <<4 ;/* CS */
drivers/leds/leds-is31fl319x.c line 360
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+ } +if (of_property_read_u32 (client->dev.of_node,"audio-gain-db" , + &val)) { +if (val >21 ) + val =21 ; + config2 |= val /3 ;/* AGS */ + } +if (config2) +is31fl319x_write (is31,IS31FL319X_CONFIG2 , config2); + }
Could you move the contents of this condition to is31fl319x_led_dt_init?
Quoted 64 lines
drivers/leds/leds-is31fl319x.c new file +46
-0+ +schedule_work (&is31->work);/* first update */ + +dev_dbg (&client->dev,"probed\n" ); +return 0 ; +exit: +dev_err (&client->dev,"led error %d\n" , err); + +while (i--) { +if (is31->leds[i].led_cdev.name) +led_classdev_unregister (&is31->leds[i].led_cdev); + } +return err; +} + +static int is31fl319x_remove (struct i2c_client *client) +{ +int i; +struct is31fl319x_chip *is31 =i2c_get_clientdata (client); +struct is31fl319x_led *is31_leds = is31->leds; + +for (i =0 ; i <NUM_LEDS ; i++) { +if (is31_leds[i].led_cdev.name) +led_classdev_unregister (&is31_leds[i].led_cdev); + } + +cancel_work_sync (&is31->work); + +return 0 ; +} + +static struct i2c_driver is31fl319x_driver = { + .driver = { + .name ="leds-is31fl319x" , + .of_match_table =of_match_ptr (of_is31fl319x_leds_match), + }, + .probe = is31fl319x_probe, + .remove = is31fl319x_remove, + .id_table = is31fl319x_id, +}; + +module_i2c_driver (is31fl319x_driver); + +MODULE_AUTHOR ("H. Nikolaus Schaller <[email protected]>" ); +MODULE_DESCRIPTION ("IS31FL319X LED driver" ); +MODULE_LICENSE ("GPL v2" );include/linux/leds-is31fl319x.h new file +12
-0@@ -0,0 +1,24 @@ +/* +* IS31FL3196 LED chip driver. +* +* Copyright (C) 2015 H. Nikolaus Schaller <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
include/linux/leds-is31fl319x.h line 22
Quoted 10 lines
include/linux/leds-is31fl319x.h new file +10
-0+* General Public License for more details. +*/ + +#ifndef __LINUX_IS31FL319X_H +#define __LINUX_IS31FL319X_H +#include <linux/leds.h> + +struct is31fl319x_platform_data { +struct led_platform_data leds; +};
We don't use led_platform_data for new drivers. Device Tree has become a standard. Effectively this header is not needed, please drop it.
Quoted 2 lines
include/linux/leds-is31fl319x.h new file +1
-0+#endif /* __LINUX_IS31FL319X_H */
Signature · 6 lines
Best regards, Jacek Anaszewski -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] drivers: led: is31fl319x: 6/9-channel light effect led driver
Hi Jacek,
Quoted 5 lines
Am 19.04.2016 um 11:14 schrieb Jacek Anaszewski <[email protected]>:
Hi Nikolaus,
Thanks for the patch. Please refer to my remarks in the code.
Thanks for the remarks!
Quoted 36 lines · H. Nikolaus Schaller
Quoted 34 lines
This is a driver for the Integrated Silicon Solution Inc. LED driver chips IS31FL3196 and IS31FL3199. They can drive up to 6 or 9 LEDs.
Each LED is individually controllable in brightness (through pwm) in 256 steps so that RGB LEDs can show any of ca. 16 Mio colors.
The maximum current of the LEDs can be programmed and limited to 5 .. 40mA through a device tree property.
The chip is connected through I2C and can have one of 4 addresses (
0x64..0x67) depending on how the AD pin is connected. The address is defined by the reg property as usual.The chip also has a shutdown input which could be connected to a GPIO, but this driver uses software shutdown if all LEDs are inactivated.
The chip also has breathing and audio features which are not supported by this driver.
This driver was developed and tested on OMAP5 based Pyra handheld prototype.
Signed-off-by H. Nikolaus Schaller <[email protected]>--- .../devicetree/bindings/leds/is31fl319x.txt | 41 +++ drivers/leds/Kconfig | 8 + drivers/leds/Makefile | 1 + drivers/leds/leds-is31fl319x.c | 406 +++++++++++++++++++++ include/linux/leds-is31fl319x.h | 24 ++ 5 files changed, 480 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/is31fl319x.txt create mode 100644 drivers/leds/leds-is31fl319x.c create mode 100644 include/linux/leds-is31fl319x.h
Quoted 12 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt line 4
Quoted 10 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +4
-0@@ -0,0 +1,41 @@ +LEDs connected to is31fl319x RGB LED controller chip + +Required properties: +- compatible : should be : "issi,is31fl3196" or "issi,is31fl3199".s/should be :/Should be/
done.
Quoted 9 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt line 6
Quoted 3 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +2
-0+- #address-cells: must be 1 +- #size-cells: must be 0s/must/Must/
Please begin the property description with a capital letter, and also end it with a dot.
This remark applies also to the other properties.
Done.
Quoted 8 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt line 10
Quoted 5 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +4
-0+- reg: 0x64, 0x65, 0x66, 0x67. + +Optional properties: +- max-current-ma: maximum led current (5..40 mA, default 20 mA)There is leds-max-microamp property for this - see
Documentation/devicetree/bindings/leds/common.txt.
Ah, I wasn't aware that this property should also apply to the whole chip (in that document it is described as a property for each individual LED).
Renamed.
Quoted 11 lines
I'd rephrase this as follows:
- led-max-microamp: See
Documentation/devicetree/bindings/leds/common.txt.Valid values: 50000 - 400000, step by (?) (rounded {up|down}) Default: 20000Documentation/devicetree/bindings/leds/is31fl319x.txt line 11
Quoted 1 line
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +1
-0+- audio-gain-db: audio gain selection (0..21 dB. default 0 dB)Please follow the aforementioned "Valid values" pattern. It would also be nice to have more informative description on the purpose of this property.
Done.
Quoted 4 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt line 12
Quoted 2 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +1
-0+- breathing & audio: not implementedThere is no point in documenting unused properties.
Done.
Quoted 24 lines
Quoted 24 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +23
-0+ +Each led is represented as a sub-node of the issi,is31fl319x device. + +LED sub-node properties: +- label : (optional) see Documentation/devicetree/bindings/leds/common.txt +- reg : number of LED line (0 to 5 or 0 to 8 - not all need to be present) +- linux,default-trigger : (optional) + see Documentation/devicetree/bindings/leds/common.txt + +Examples: + +fancy_leds: is31fl3196@65 { + compatible = "issi,is31fl319x"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x65>; + + led0: red-aux@0 { + label = "red:aux"; + reg = <0>; + }; + + led1: green-power@4 {
Quoted 8 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt line 40
Quoted 5 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +5
-0+ label = "green:power"; + reg = <4>; + linux,default-trigger = "default-on"; + }; +};Generally I prefer to have DT bindings documentation in a separate patch.
Yes, you are right and not only you prefer it :)
It just gets forgotten for such simple drivers...
Quoted 55 lines
Quoted 55 lines
drivers/leds/Kconfig +8
-0@@ -491,6 +491,14 @@ config LEDS_ASIC3 cannot be used. This driver supports hardware blinking with an on+off period from 62ms to 125s. Say Y to enable LEDs on the HP iPAQ hx4700. +config LEDS_IS31FL319X + tristate "LED Support for IS31FL319x I2C chip" + depends on LEDS_CLASS && I2C + help + This option enables support for LEDs connected to IS31FL3196 + or IS31FL3199 LED driver chips accessed via the I2C bus. + Driver support brightness control and hardware-assisted blinking. + config LEDS_TCA6507 tristate "LED Support for TCA6507 I2C chip" depends on LEDS_CLASS && I2Cdrivers/leds/Makefile +1
-0@@ -37,6 +37,7 @@ obj-$(CONFIG_LEDS_TCA6507) += leds-tca6507.o obj-$(CONFIG_LEDS_TLC591XX) += leds-tlc591xx.o obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o obj-$(CONFIG_LEDS_IPAQ_MICRO) += leds-ipaq-micro.o +obj-$(CONFIG_LEDS_IS31FL319X) += leds-is31fl319x.o obj-$(CONFIG_LEDS_HP6XX) += leds-hp6xx.o obj-$(CONFIG_LEDS_OT200) += leds-ot200.o obj-$(CONFIG_LEDS_FSG) += leds-fsg.odrivers/leds/leds-is31fl319x.c new file +17
-0@@ -0,0 +1,406 @@ +/* +* Copyright 2015 Golden Delcious Computers +* +* Author: Nikolaus Schaller <[email protected]> +* +* Based on leds-tca6507.c +* +* This file is subject to the terms and conditions of version 2 of +* the GNU General Public License. See the file COPYING in the main +* directory of this archive for more details. +* +* LED driver for the IS31FL3196/99 to drive 6 or 9 light effect LEDs. +* +*/ + +#include <linux/module.h> +#include <linux/slab.h>
Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 23
Quoted 6 lines
drivers/leds/leds-is31fl319x.c new file +6
-0+#include <linux/leds.h> +#include <linux/err.h> +#include <linux/i2c.h> +#include <linux/workqueue.h> +#include <linux/leds-is31fl319x.h> +#include <linux/of.h> Please keep include directives in an alphabetical order.
Done.
Quoted 125 lines
Quoted 112 lines
drivers/leds/leds-is31fl319x.c new file +111
-0+ +/* register numbers */ +#define IS31FL319X_SHUTDOWN 0x00 +#define IS31FL319X_CTRL1 0x01 +#define IS31FL319X_CTRL2 0x02 +#define IS31FL319X_CONFIG1 0x03 +#define IS31FL319X_CONFIG2 0x04 +#define IS31FL319X_RAMP_MODE 0x05 +#define IS31FL319X_BREATH_MASK 0x06 +#define IS31FL319X_PWM1 0x07 +#define IS31FL319X_PWM2 0x08 +#define IS31FL319X_PWM3 0x09 +#define IS31FL319X_PWM4 0x0a +#define IS31FL319X_PWM5 0x0b +#define IS31FL319X_PWM6 0x0c +#define IS31FL319X_PWM7 0x0d +#define IS31FL319X_PWM8 0x0e +#define IS31FL319X_PWM9 0x0f +#define IS31FL319X_DATA_UPDATE 0x10 +#define IS31FL319X_T0_1 0x11 +#define IS31FL319X_T0_2 0x12 +#define IS31FL319X_T0_3 0x13 +#define IS31FL319X_T0_4 0x14 +#define IS31FL319X_T0_5 0x15 +#define IS31FL319X_T0_6 0x16 +#define IS31FL319X_T0_7 0x17 +#define IS31FL319X_T0_8 0x18 +#define IS31FL319X_T0_9 0x19 +#define IS31FL319X_T123_1 0x1a +#define IS31FL319X_T123_2 0x1b +#define IS31FL319X_T123_3 0x1c +#define IS31FL319X_T4_1 0x1d +#define IS31FL319X_T4_2 0x1e +#define IS31FL319X_T4_3 0x1f +#define IS31FL319X_T4_4 0x20 +#define IS31FL319X_T4_5 0x21 +#define IS31FL319X_T4_6 0x22 +#define IS31FL319X_T4_7 0x23 +#define IS31FL319X_T4_8 0x24 +#define IS31FL319X_T4_9 0x25 +#define IS31FL319X_TIME_UPDATE 0x26 + +#define IS31FL319X_REG_CNT (IS31FL319X_TIME_UPDATE + 1) + +#define NUM_LEDS 9/* max for 3199 chip */ + +struct is31fl319x_chip { +struct i2c_client *client; +struct work_struct work; +bool work_scheduled; +spinlock_t lock; +u8 reg_file[IS31FL319X_REG_CNT ]; + +struct is31fl319x_led { +struct is31fl319x_chip *chip; +struct led_classdev led_cdev; + } leds[NUM_LEDS ]; +}; + +static const struct i2c_device_id is31fl319x_id[] = { + {"is31fl3196" ,6 }, + {"is31fl3196" ,9 }, + { } +}; +MODULE_DEVICE_TABLE (i2c, is31fl319x_id); + + +static int is31fl319x_write (struct is31fl319x_chip *is31,u8 reg,u8 byte) +{ +struct i2c_client *cl = is31->client; + +if (reg >=IS31FL319X_REG_CNT ) +return -EIO ; + is31->reg_file[reg] = byte;/* save in cache */ +dev_dbg (&is31->client->dev,"write %02x to reg %02x\n" , byte, reg); +return i2c_smbus_write_byte_data (cl, reg, byte); +} + +static int is31fl319x_read (struct is31fl319x_chip *is31,u8 reg) +{ +if (reg >=IS31FL319X_REG_CNT ) +return -EIO ; +return is31->reg_file[reg];/* read crom cache (can't read chip) */ +} + +static void is31fl319x_work (struct work_struct *work) +{ +struct is31fl319x_chip *is31 =container_of (work, + struct is31fl319x_chip, + work); +unsigned long flags; +int i; +u8 ctrl1, ctrl2; + +dev_dbg (&is31->client->dev,"work called\n" ); + +spin_lock_irqsave (&is31->lock, flags); +/* make subsequent changes run another schedule_work */ + is31->work_scheduled = false; +spin_unlock_irqrestore (&is31->lock, flags); + +dev_dbg (&is31->client->dev,"write to chip\n" ); + + ctrl1 =0 ; + ctrl2 =0 ; + +for (i =0 ; i <NUM_LEDS ; i++) { +struct led_classdev *led = &is31->leds[i].led_cdev; +bool on; + +if (!is31->leds[i].led_cdev.name)drivers/leds/leds-is31fl319x.c line 144
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+continue ; + +dev_dbg (&is31->client->dev,"set brightness %u for led %u\n" , + led->brightness, i); + +/* update brightness register */ +is31fl319x_write (is31,IS31FL319X_PWM1 + i, led->brightness); + +/* update output enable bits */ + on = led->brightness >LED_OFF ;It's more common to achieve the same in the following way:
Quoted 1 line
on = !!led->brightness;
Hm. This is quite difficult to understand and assumes that LED_OFF is 0. If find brightness > LED_OFF much more readable.
Quoted 11 lines
drivers/leds/leds-is31fl319x.c line 151
Quoted 8 lines
drivers/leds/leds-is31fl319x.c new file +7
-0+if (i <3 ) + ctrl1 |= on << i;/* 0..2 => bit 0..2 */ +else if (i <6 ) + ctrl1 |= on << (i+1 );/* 3..5 => bit 4..6 */ +else + ctrl2 |= on << (i-6 );/* 6..8 => bit 0..2 */ + }Why are you iterating over all sub-LEDs? One LED class device should control single sub-LED/iout.
Because they share two common control registers which are updated
in one batch (instead of individual read-modify-write which introduces race issues).
And to properly control chip shutdown (code below) we must know when the last LED was set to brightness 0. This means we have to loop over them anyways to get the aggregate state of all LEDs.
This is also the reason why I am hesitating to switch to the brand new brightness_set_blocking which appears to assume that each LED can and shall be controlled independently by independent i2c write commands. It could here, except for shutting down the chip if all LEDs are off (which is different from setting PWM to 0 for all LEDs). So this would probably increase I2C traffic compared to our batch mode (if any number of LEDs is modified since the last one, we trigger only a single i2c transaction for all LEDs).
Quoted 40 lines
Quoted 40 lines
drivers/leds/leds-is31fl319x.c new file +39
-0+ +/* check if any PWM is enabled or all outputs are now off */ +if (ctrl1 >0 || ctrl2 >0 ) { +dev_dbg (&is31->client->dev,"power up\n" ); +is31fl319x_write (is31,IS31FL319X_CTRL1 , ctrl1); +is31fl319x_write (is31,IS31FL319X_CTRL2 , ctrl2); +/* update PWMs */ +is31fl319x_write (is31,IS31FL319X_DATA_UPDATE ,0x00 ); +/* enable chip from shut down */ +is31fl319x_write (is31,IS31FL319X_SHUTDOWN ,0x01 ); + }else { +dev_dbg (&is31->client->dev,"power down\n" ); +/* shut down */ +is31fl319x_write (is31,IS31FL319X_SHUTDOWN ,0x00 ); + } + +dev_dbg (&is31->client->dev,"work done\n" ); + +} + +/* NOTE: this may be called from within irq context, e.g. led_trigger_event */ + +static int is31fl319x_brightness_get (struct led_classdev *led_cdev) +{ +struct is31fl319x_led *led =container_of (led_cdev, + struct is31fl319x_led, + led_cdev); +struct is31fl319x_chip *is31 = led->chip; + +/* read PWM register */ +return is31fl319x_read (is31,IS31FL319X_PWM1 + (led - is31->leds)); +} + +static void is31fl319x_brightness_set (struct led_classdev *led_cdev, +enum led_brightness brightness) +{ +struct is31fl319x_led *led =container_of (led_cdev, + struct is31fl319x_led, + led_cdev);
Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 196
Quoted 6 lines
drivers/leds/leds-is31fl319x.c new file +6
-0+struct is31fl319x_chip *is31 = led->chip; +unsigned long flags; + +spin_lock_irqsave (&is31->lock, flags); + +if (brightness !=is31fl319x_brightness_get (led_cdev)) {Current brightness is cached in
led_cdev->brightness.
Hm. I could not find the code line where it is cached.
And if I remember correctly (it is a while ago that we did develop this driver) experiments didn't show that it is cached there. Or the old value is not available inside the brightness setter but already the new one. Something like that was the reason why we cache it inside the driver.
Quoted 11 lines
Quoted 11 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+if (!is31->work_scheduled) { +schedule_work (&is31->work); + is31->work_scheduled = true; + } + } + +spin_unlock_irqrestore (&is31->lock, flags); +} + +static int is31fl319x_blink_set(struct led_classdev *led_cdev,
Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 212
Quoted 6 lines
drivers/leds/leds-is31fl319x.c new file +6
-0+ unsigned long *delay_on, + unsigned long *delay_off) +{ +/* use software blink */ +return 1 ; +}This function is useless, please remove it.
Ok.
Quoted 5 lines
drivers/leds/leds-is31fl319x.c line 214
Quoted 2 lines
drivers/leds/leds-is31fl319x.c new file +1
-0+#ifdef CONFIG_OF Please provide only version for
CONFIG_OFdefined case and just fail probing ifof_nodeis NULL.
Ok.
Quoted 5 lines
drivers/leds/leds-is31fl319x.c line 216
Quoted 3 lines
drivers/leds/leds-is31fl319x.c new file +2
-0+static struct is31fl319x_platform_data * +is31fl319x_led_dt_init (struct i2c_client *client,int num_leds)Please rename it to
is31fl319x_parse_dt.
Done.
Quoted 72 lines
Quoted 72 lines
drivers/leds/leds-is31fl319x.c new file +71
-0+{ +struct device_node *np = client->dev.of_node, *child; +struct is31fl319x_platform_data *pdata; +struct led_info *is31_leds; +int count; + + count =of_get_child_count (np); +dev_dbg (&client->dev,"child count %d\n" , count); +if (!count || count >NUM_LEDS ) +return ERR_PTR (-ENODEV ); + + is31_leds =devm_kzalloc (&client->dev, +sizeof (struct led_info ) *NUM_LEDS ,GFP_KERNEL ); +if (!is31_leds) +return ERR_PTR (-ENOMEM ); + +for_each_child_of_node (np, child) { +struct led_info led; +u32 reg; +int ret; + + led.name = +of_get_property (child,"label" ,NULL ) ? : child->name; + led.default_trigger = +of_get_property (child,"linux,default-trigger" ,NULL ); + led.flags =0 ; + ret =of_property_read_u32 (child,"reg" , ®); +dev_dbg (&client->dev,"name = %s reg = %d\n" , led.name, reg); +if (ret !=0 || reg <0 || reg >= num_leds) +continue ; + +if (is31_leds[reg].name) +dev_err (&client->dev,"duplicate led line %d for %s -> %s\n" , + reg, is31_leds[reg].name, led.name); + is31_leds[reg] = led; + } + pdata =devm_kzalloc (&client->dev, +sizeof (struct is31fl319x_platform_data ),GFP_KERNEL ); +if (!pdata) +return ERR_PTR (-ENOMEM ); + + pdata->leds.leds = is31_leds; +return pdata; +} + +static const struct of_device_id of_is31fl319x_leds_match[] = { + { .compatible ="issi,is31fl3196" , (void *)6 }, + { .compatible ="issi,is31fl3199" , (void *)9 }, + {}, +}; +MODULE_DEVICE_TABLE (of, of_is31fl319x_leds_match); + +#else +static struct is31fl319x_platform_data * +is31fl319x_led_dt_init (struct i2c_client *client) +{ +return ERR_PTR (-ENODEV ); +} + +#endif + +static int is31fl319x_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +struct is31fl319x_chip *is31; +struct i2c_adapter *adapter; +struct is31fl319x_platform_data *pdata; +int err; +int i =0 ; + + adapter =to_i2c_adapter (client->dev.parent);
Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 293
Quoted 6 lines
drivers/leds/leds-is31fl319x.c new file +6
-0+ pdata =dev_get_platdata (&client->dev); + +dev_dbg (&client->dev,"probe\n" ); + +dev_dbg (&client->dev,"NUM_LEDS = %d num_leds = %d\n" , +NUM_LEDS , (int ) id->driver_data);I believe this is stray debug logging.
I have merged it with the probe debug message to give more useful information.
Quoted 11 lines
drivers/leds/leds-is31fl319x.c line 301
Quoted 9 lines
drivers/leds/leds-is31fl319x.c new file +8
-0+ +if (!i2c_check_functionality (adapter,I2C_FUNC_I2C )) +return -EIO ; + +if (!pdata) { + pdata =is31fl319x_led_dt_init (client, (int ) id->driver_data); +if (IS_ERR (pdata)) { + dev_err(&client->dev, "DT led error %d\n",s/DT led error/DT parsing error/
done.
Quoted 14 lines
Quoted 14 lines
drivers/leds/leds-is31fl319x.c new file +13
-0+ (int) PTR_ERR(pdata)); +return PTR_ERR (pdata); + } + } + is31 =devm_kzalloc (&client->dev,sizeof (*is31),GFP_KERNEL ); +if (!is31) +return -ENOMEM ; + + is31->client = client; +INIT_WORK (&is31->work, is31fl319x_work); +spin_lock_init (&is31->lock); +i2c_set_clientdata (client, is31); +
Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 320
Quoted 6 lines
drivers/leds/leds-is31fl319x.c new file +6
-0+/* check for reply from chip (we can't read any registers) */ + err =is31fl319x_write (is31,IS31FL319X_SHUTDOWN ,0x01 ); +if (err <0 ) { +dev_err (&client->dev,"no response from chip write: err = %d\n" , + err); +return -EPROBE_DEFER ;/* does not answer (yet) */ When can it happen? Does the chip have a long booting time or so?
Hm. Rarely...
So if it is not available on first attempt, there is no reason to probe later.
I will make it return -EIO.
Quoted 36 lines
Quoted 36 lines
drivers/leds/leds-is31fl319x.c new file +34
-0+ } + +for (i =0 ; i <NUM_LEDS ; i++) { +struct is31fl319x_led *l = is31->leds + i; + + l->chip = is31; +if (pdata->leds.leds[i].name && !pdata->leds.leds[i].flags) { + l->led_cdev.name = pdata->leds.leds[i].name; + l->led_cdev.default_trigger + = pdata->leds.leds[i].default_trigger; + l->led_cdev.brightness_set = is31fl319x_brightness_set; + l->led_cdev.blink_set = is31fl319x_blink_set; + err =led_classdev_register (&client->dev, + &l->led_cdev); +if (err <0 ) + goto exit; + } + } + +if (client->dev.of_node) { +u32 val; +u8 config2 =0 ; + +if (of_property_read_u32 (client->dev.of_node,"max-current-ma" , + &val)) { +if (val >40 ) + val =40 ; +if (val <5 ) + val =5 ; + config2 |= (((64 - val) /5 ) &0x7 ) <<4 ;/* CS */ + } +if (of_property_read_u32 (client->dev.of_node,"audio-gain-db" , + &val)) { +if (val >21 )
Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 360
Quoted 6 lines
drivers/leds/leds-is31fl319x.c new file +6
-0+ val =21 ; + config2 |= val /3 ;/* AGS */ + } +if (config2) +is31fl319x_write (is31,IS31FL319X_CONFIG2 , config2); + }Could you move the contents of this condition to
is31fl319x_led_dt_init?
What would that improve? It is intended as a timing optimization to skip the i2c write. With the implicit assumption that the register is already initialized to 0.
Which I know think is not always the case. The chip might already be initialized by U-Boot or after a reboot when it was not powered down.
So I think the condition must be removed completely.
Quoted 71 lines
Quoted 71 lines
drivers/leds/leds-is31fl319x.c new file +46
-0+ +schedule_work (&is31->work);/* first update */ + +dev_dbg (&client->dev,"probed\n" ); +return 0 ; +exit: +dev_err (&client->dev,"led error %d\n" , err); + +while (i--) { +if (is31->leds[i].led_cdev.name) +led_classdev_unregister (&is31->leds[i].led_cdev); + } +return err; +} + +static int is31fl319x_remove (struct i2c_client *client) +{ +int i; +struct is31fl319x_chip *is31 =i2c_get_clientdata (client); +struct is31fl319x_led *is31_leds = is31->leds; + +for (i =0 ; i <NUM_LEDS ; i++) { +if (is31_leds[i].led_cdev.name) +led_classdev_unregister (&is31_leds[i].led_cdev); + } + +cancel_work_sync (&is31->work); + +return 0 ; +} + +static struct i2c_driver is31fl319x_driver = { + .driver = { + .name ="leds-is31fl319x" , + .of_match_table =of_match_ptr (of_is31fl319x_leds_match), + }, + .probe = is31fl319x_probe, + .remove = is31fl319x_remove, + .id_table = is31fl319x_id, +}; + +module_i2c_driver (is31fl319x_driver); + +MODULE_AUTHOR ("H. Nikolaus Schaller <[email protected]>" ); +MODULE_DESCRIPTION ("IS31FL319X LED driver" ); +MODULE_LICENSE ("GPL v2" );include/linux/leds-is31fl319x.h new file +18
-0@@ -0,0 +1,24 @@ +/* +* IS31FL3196 LED chip driver. +* +* Copyright (C) 2015 H. Nikolaus Schaller <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +*/ + +#ifndef __LINUX_IS31FL319X_H +#define __LINUX_IS31FL319X_H +#include <linux/leds.h>
Quoted 8 lines
include/linux/leds-is31fl319x.h line 22
Quoted 4 lines
include/linux/leds-is31fl319x.h new file +4
-0+ +struct is31fl319x_platform_data { +struct led_platform_data leds; +};We don't use
led_platform_datafor new drivers. Device Tree has become a standard. Effectively this header is not needed, please drop it.
Ok, fine with that!
Quoted 8 lines
Quoted 3 lines
include/linux/leds-is31fl319x.h new file +1
-0+#endif /* __LINUX_IS31FL319X_H */ Signature · 2 lines
Best regards, Jacek Anaszewski
I will combine all this and resubmit V2 after testing.
BR and thanks,
Nikolaus
Re: [Letux-kernel] [PATCH] drivers: led: is31fl319x: 6/9-channel light effect led driver
Hi Jacek,
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/leds/leds-is31fl319x.c new file +6
-0+static void is31fl319x_brightness_set (struct led_classdev *led_cdev, +enum led_brightness brightness) +{ +struct is31fl319x_led *led =container_of (led_cdev, + struct is31fl319x_led, + led_cdev);Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 196
Quoted 6 lines
drivers/leds/leds-is31fl319x.c new file +6
-0+struct is31fl319x_chip *is31 = led->chip; +unsigned long flags; + +spin_lock_irqsave (&is31->lock, flags); + +if (brightness !=is31fl319x_brightness_get (led_cdev)) {Current brightness is cached in
led_cdev->brightness.
Quoted 8 lines
Hm. I could not find the code line where it is cached.
And if I remember correctly (it is a while ago that we did develop this driver) experiments didn't show that it is cached there. Or the old value is not available inside the brightness setter but already the new one. Something like that was the reason why we cache it inside the driver.
I have added a printk inside is31fl319x_brightness_set but never got a difference between brightness and led_cdev->brightness.
This seems to confirm that it is already set to the new value. Thus we can't detect changes in brightness by comparing to the previous value.
Can you please confirm?
Otherwise the driver works well so that I am almost ready for posting V2.
Thanks,
Nikolaus
Re: [PATCH] drivers: led: is31fl319x: 6/9-channel light effect led driver
In reply to H. Nikolaus SchallerHi Nikolaus,
Quoted 9 lines · H. Nikolaus Schaller
Hi Jacek,
Quoted 5 lines
Am 19.04.2016 um 11:14 schrieb Jacek Anaszewski <[email protected]>:
Hi Nikolaus,
Thanks for the patch. Please refer to my remarks in the code.
Thanks for the remarks!
You're welcome.
Quoted 72 lines
Quoted 36 lines · H. Nikolaus Schaller
Quoted 34 lines
This is a driver for the Integrated Silicon Solution Inc. LED driver chips IS31FL3196 and IS31FL3199. They can drive up to 6 or 9 LEDs.
Each LED is individually controllable in brightness (through pwm) in 256 steps so that RGB LEDs can show any of ca. 16 Mio colors.
The maximum current of the LEDs can be programmed and limited to 5 .. 40mA through a device tree property.
The chip is connected through I2C and can have one of 4 addresses (
0x64..0x67) depending on how the AD pin is connected. The address is defined by the reg property as usual.The chip also has a shutdown input which could be connected to a GPIO, but this driver uses software shutdown if all LEDs are inactivated.
The chip also has breathing and audio features which are not supported by this driver.
This driver was developed and tested on OMAP5 based Pyra handheld prototype.
Signed-off-by H. Nikolaus Schaller <[email protected]>--- .../devicetree/bindings/leds/is31fl319x.txt | 41 +++ drivers/leds/Kconfig | 8 + drivers/leds/Makefile | 1 + drivers/leds/leds-is31fl319x.c | 406 +++++++++++++++++++++ include/linux/leds-is31fl319x.h | 24 ++ 5 files changed, 480 insertions(+)create mode 100644
Documentation/devicetree/bindings/leds/is31fl319x.txtcreate mode 100644drivers/leds/leds-is31fl319x.c
create mode 100644include/linux/leds-is31fl319x.hQuoted 12 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt line 4
Quoted 10 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +4
-0@@ -0,0 +1,41 @@ +LEDs connected to is31fl319x RGB LED controller chip + +Required properties: +- compatible : should be : "issi,is31fl3196" or "issi,is31fl3199".s/should be :/Should be/
done.
Quoted 9 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt line 6
Quoted 3 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +2
-0+- #address-cells: must be 1 +- #size-cells: must be 0s/must/Must/
Please begin the property description with a capital letter, and also end it with a dot.
This remark applies also to the other properties.Done.
Quoted 8 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt line 10
Quoted 5 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +4
-0+- reg: 0x64, 0x65, 0x66, 0x67. + +Optional properties: +- max-current-ma: maximum led current (5..40 mA, default 20 mA)There is leds-max-microamp property for this - see
Documentation/devicetree/bindings/leds/common.txt.
Quoted 2 lines
Ah, I wasn't aware that this property should also apply to the whole chip (in that document it is described as a property for each individual LED).
It is indented for individual LEDs. I missed that you defined it for the whole chip. The property, when present, should have an impact on the max_brightness property of the struct led_classdev.
Quoted 250 lines
Renamed.
Quoted 11 lines
I'd rephrase this as follows:
- led-max-microamp: See
Documentation/devicetree/bindings/leds/common.txt.Valid values: 50000 - 400000, step by (?) (rounded {up|down}) Default: 20000Documentation/devicetree/bindings/leds/is31fl319x.txt line 11
Quoted 1 line
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +1
-0+- audio-gain-db: audio gain selection (0..21 dB. default 0 dB)Please follow the aforementioned "Valid values" pattern. It would also be nice to have more informative description on the purpose of this property.
Done.
Quoted 4 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt line 12
Quoted 2 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +1
-0+- breathing & audio: not implementedThere is no point in documenting unused properties.
Done.
Quoted 24 lines
Quoted 24 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +23
-0+ +Each led is represented as a sub-node of the issi,is31fl319x device. + +LED sub-node properties: +- label : (optional) see Documentation/devicetree/bindings/leds/common.txt +- reg : number of LED line (0 to 5 or 0 to 8 - not all need to be present) +- linux,default-trigger : (optional) + see Documentation/devicetree/bindings/leds/common.txt + +Examples: + +fancy_leds: is31fl3196@65 { + compatible = "issi,is31fl319x"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x65>; + + led0: red-aux@0 { + label = "red:aux"; + reg = <0>; + }; + + led1: green-power@4 {Quoted 8 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt line 40
Quoted 5 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +5
-0+ label = "green:power"; + reg = <4>; + linux,default-trigger = "default-on"; + }; +};Generally I prefer to have DT bindings documentation in a separate patch.
Yes, you are right and not only you prefer it :)
It just gets forgotten for such simple drivers...Quoted 55 lines
Quoted 55 lines
drivers/leds/Kconfig +8
-0@@ -491,6 +491,14 @@ config LEDS_ASIC3 cannot be used. This driver supports hardware blinking with an on+off period from 62ms to 125s. Say Y to enable LEDs on the HP iPAQ hx4700. +config LEDS_IS31FL319X + tristate "LED Support for IS31FL319x I2C chip" + depends on LEDS_CLASS && I2C + help + This option enables support for LEDs connected to IS31FL3196 + or IS31FL3199 LED driver chips accessed via the I2C bus. + Driver support brightness control and hardware-assisted blinking. + config LEDS_TCA6507 tristate "LED Support for TCA6507 I2C chip" depends on LEDS_CLASS && I2Cdrivers/leds/Makefile +1
-0@@ -37,6 +37,7 @@ obj-$(CONFIG_LEDS_TCA6507) += leds-tca6507.o obj-$(CONFIG_LEDS_TLC591XX) += leds-tlc591xx.o obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o obj-$(CONFIG_LEDS_IPAQ_MICRO) += leds-ipaq-micro.o +obj-$(CONFIG_LEDS_IS31FL319X) += leds-is31fl319x.o obj-$(CONFIG_LEDS_HP6XX) += leds-hp6xx.o obj-$(CONFIG_LEDS_OT200) += leds-ot200.o obj-$(CONFIG_LEDS_FSG) += leds-fsg.odrivers/leds/leds-is31fl319x.c new file +17
-0@@ -0,0 +1,406 @@ +/* +* Copyright 2015 Golden Delcious Computers +* +* Author: Nikolaus Schaller <[email protected]> +* +* Based on leds-tca6507.c +* +* This file is subject to the terms and conditions of version 2 of +* the GNU General Public License. See the file COPYING in the main +* directory of this archive for more details. +* +* LED driver for the IS31FL3196/99 to drive 6 or 9 light effect LEDs. +* +*/ + +#include <linux/module.h> +#include <linux/slab.h> Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 23
Quoted 6 lines
drivers/leds/leds-is31fl319x.c new file +6
-0+#include <linux/leds.h> +#include <linux/err.h> +#include <linux/i2c.h> +#include <linux/workqueue.h> +#include <linux/leds-is31fl319x.h> +#include <linux/of.h> Please keep include directives in an alphabetical order.
Done.
Quoted 125 lines
Quoted 112 lines
drivers/leds/leds-is31fl319x.c new file +111
-0+ +/* register numbers */ +#define IS31FL319X_SHUTDOWN 0x00 +#define IS31FL319X_CTRL1 0x01 +#define IS31FL319X_CTRL2 0x02 +#define IS31FL319X_CONFIG1 0x03 +#define IS31FL319X_CONFIG2 0x04 +#define IS31FL319X_RAMP_MODE 0x05 +#define IS31FL319X_BREATH_MASK 0x06 +#define IS31FL319X_PWM1 0x07 +#define IS31FL319X_PWM2 0x08 +#define IS31FL319X_PWM3 0x09 +#define IS31FL319X_PWM4 0x0a +#define IS31FL319X_PWM5 0x0b +#define IS31FL319X_PWM6 0x0c +#define IS31FL319X_PWM7 0x0d +#define IS31FL319X_PWM8 0x0e +#define IS31FL319X_PWM9 0x0f +#define IS31FL319X_DATA_UPDATE 0x10 +#define IS31FL319X_T0_1 0x11 +#define IS31FL319X_T0_2 0x12 +#define IS31FL319X_T0_3 0x13 +#define IS31FL319X_T0_4 0x14 +#define IS31FL319X_T0_5 0x15 +#define IS31FL319X_T0_6 0x16 +#define IS31FL319X_T0_7 0x17 +#define IS31FL319X_T0_8 0x18 +#define IS31FL319X_T0_9 0x19 +#define IS31FL319X_T123_1 0x1a +#define IS31FL319X_T123_2 0x1b +#define IS31FL319X_T123_3 0x1c +#define IS31FL319X_T4_1 0x1d +#define IS31FL319X_T4_2 0x1e +#define IS31FL319X_T4_3 0x1f +#define IS31FL319X_T4_4 0x20 +#define IS31FL319X_T4_5 0x21 +#define IS31FL319X_T4_6 0x22 +#define IS31FL319X_T4_7 0x23 +#define IS31FL319X_T4_8 0x24 +#define IS31FL319X_T4_9 0x25 +#define IS31FL319X_TIME_UPDATE 0x26 + +#define IS31FL319X_REG_CNT (IS31FL319X_TIME_UPDATE + 1) + +#define NUM_LEDS 9/* max for 3199 chip */ + +struct is31fl319x_chip { +struct i2c_client *client; +struct work_struct work; +bool work_scheduled; +spinlock_t lock; +u8 reg_file[IS31FL319X_REG_CNT ]; + +struct is31fl319x_led { +struct is31fl319x_chip *chip; +struct led_classdev led_cdev; + } leds[NUM_LEDS ]; +}; + +static const struct i2c_device_id is31fl319x_id[] = { + {"is31fl3196" ,6 }, + {"is31fl3196" ,9 }, + { } +}; +MODULE_DEVICE_TABLE (i2c, is31fl319x_id); + + +static int is31fl319x_write (struct is31fl319x_chip *is31,u8 reg,u8 byte) +{ +struct i2c_client *cl = is31->client; + +if (reg >=IS31FL319X_REG_CNT ) +return -EIO ; + is31->reg_file[reg] = byte;/* save in cache */ +dev_dbg (&is31->client->dev,"write %02x to reg %02x\n" , byte, reg); +return i2c_smbus_write_byte_data (cl, reg, byte); +} + +static int is31fl319x_read (struct is31fl319x_chip *is31,u8 reg) +{ +if (reg >=IS31FL319X_REG_CNT ) +return -EIO ; +return is31->reg_file[reg];/* read crom cache (can't read chip) */ +} + +static void is31fl319x_work (struct work_struct *work) +{ +struct is31fl319x_chip *is31 =container_of (work, + struct is31fl319x_chip, + work); +unsigned long flags; +int i; +u8 ctrl1, ctrl2; + +dev_dbg (&is31->client->dev,"work called\n" ); + +spin_lock_irqsave (&is31->lock, flags); +/* make subsequent changes run another schedule_work */ + is31->work_scheduled = false; +spin_unlock_irqrestore (&is31->lock, flags); + +dev_dbg (&is31->client->dev,"write to chip\n" ); + + ctrl1 =0 ; + ctrl2 =0 ; + +for (i =0 ; i <NUM_LEDS ; i++) { +struct led_classdev *led = &is31->leds[i].led_cdev; +bool on; + +if (!is31->leds[i].led_cdev.name)drivers/leds/leds-is31fl319x.c line 144
Quoted 10 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+continue ; + +dev_dbg (&is31->client->dev,"set brightness %u for led %u\n" , + led->brightness, i); + +/* update brightness register */ +is31fl319x_write (is31,IS31FL319X_PWM1 + i, led->brightness); + +/* update output enable bits */ + on = led->brightness >LED_OFF ;It's more common to achieve the same in the following way:
Quoted 3 lines
Quoted 1 line
on = !!led->brightness;Hm. This is quite difficult to understand and assumes that
LED_OFFis 0.
Because LED_OFF is 0. See include/linux/leds.h.
Quoted 1 line
If find brightness >
LED_OFFmuch more readable.
This is a matter of taste. We have already few occurrences of "!!" use in the LED subsystem in similar context. It is also prevailing throughout the whole kernel.
Quoted 12 lines
Quoted 11 lines
drivers/leds/leds-is31fl319x.c line 151
Quoted 8 lines
drivers/leds/leds-is31fl319x.c new file +7
-0+if (i <3 ) + ctrl1 |= on << i;/* 0..2 => bit 0..2 */ +else if (i <6 ) + ctrl1 |= on << (i+1 );/* 3..5 => bit 4..6 */ +else + ctrl2 |= on << (i-6 );/* 6..8 => bit 0..2 */ + }Why are you iterating over all sub-LEDs? One LED class device should control single sub-LED/iout.
Quoted 2 lines
Because they share two common control registers which are updated
in one batch (instead of individual read-modify-write which introduces race issues).
Could you share some details about those races?
Quoted 4 lines
And to properly control chip shutdown (code below) we must know when the last LED was set to brightness 0. This means we have to loop over them anyways to get the aggregate state of all LEDs.
The driver knows the actual state of the device, doesn't it? Why should it retrieve the information back from the device? It knows what it has written to. That is what the regmap relies on. AFAIR regmap_read doesn't perform physical read from the device, but returns the value cached on last regmap_write(), unless the register is marked volatile.
Quoted 7 lines
This is also the reason why I am hesitating to switch to the brand new
brightness_set_blockingwhich appears to assume that each LED can and shall be controlled independently by independent i2c write commands. It could here, except for shutting down the chip if all LEDs are off (which is different from setting PWM to 0 for all LEDs). So this would probably increase I2C traffic compared to our batch mode (if any number of LEDs is modified since the last one, we trigger only a single i2c transaction for all LEDs).
Could you specify what is the batch mode, and where it is implemented in the driver?
Quoted 49 lines
Quoted 40 lines
Quoted 40 lines
drivers/leds/leds-is31fl319x.c new file +39
-0+ +/* check if any PWM is enabled or all outputs are now off */ +if (ctrl1 >0 || ctrl2 >0 ) { +dev_dbg (&is31->client->dev,"power up\n" ); +is31fl319x_write (is31,IS31FL319X_CTRL1 , ctrl1); +is31fl319x_write (is31,IS31FL319X_CTRL2 , ctrl2); +/* update PWMs */ +is31fl319x_write (is31,IS31FL319X_DATA_UPDATE ,0x00 ); +/* enable chip from shut down */ +is31fl319x_write (is31,IS31FL319X_SHUTDOWN ,0x01 ); + }else { +dev_dbg (&is31->client->dev,"power down\n" ); +/* shut down */ +is31fl319x_write (is31,IS31FL319X_SHUTDOWN ,0x00 ); + } + +dev_dbg (&is31->client->dev,"work done\n" ); + +} + +/* NOTE: this may be called from within irq context, e.g. led_trigger_event */ + +static int is31fl319x_brightness_get (struct led_classdev *led_cdev) +{ +struct is31fl319x_led *led =container_of (led_cdev, + struct is31fl319x_led, + led_cdev); +struct is31fl319x_chip *is31 = led->chip; + +/* read PWM register */ +return is31fl319x_read (is31,IS31FL319X_PWM1 + (led - is31->leds)); +} + +static void is31fl319x_brightness_set (struct led_classdev *led_cdev, +enum led_brightness brightness) +{ +struct is31fl319x_led *led =container_of (led_cdev, + struct is31fl319x_led, + led_cdev);Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 196
Quoted 6 lines
drivers/leds/leds-is31fl319x.c new file +6
-0+struct is31fl319x_chip *is31 = led->chip; +unsigned long flags; + +spin_lock_irqsave (&is31->lock, flags); + +if (brightness !=is31fl319x_brightness_get (led_cdev)) {Current brightness is cached in
led_cdev->brightness.
Quoted 1 line
Hm. I could not find the code line where it is cached.
The first line in led_set_brightness_nosleep() (drivers/leds/led-core.c).
But it is cached before the call to brightness_set op, so it wouldn't be useful in your approach.
Nevertheless I don't think you need to check the old brightness by performing I2C readout. You can cache it on write. You don't need to reinvent the wheel, but use very flexible regmap feature, though.
Quoted 216 lines
And if I remember correctly (it is a while ago that we did develop this driver) experiments didn't show that it is cached there. Or the old value is not available inside the brightness setter but already the new one. Something like that was the reason why we cache it inside the driver.
Quoted 11 lines
Quoted 11 lines
drivers/leds/leds-is31fl319x.c new file +10
-0+if (!is31->work_scheduled) { +schedule_work (&is31->work); + is31->work_scheduled = true; + } + } + +spin_unlock_irqrestore (&is31->lock, flags); +} + +static int is31fl319x_blink_set(struct led_classdev *led_cdev,Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 212
Quoted 6 lines
drivers/leds/leds-is31fl319x.c new file +6
-0+ unsigned long *delay_on, + unsigned long *delay_off) +{ +/* use software blink */ +return 1 ; +}This function is useless, please remove it.
Ok.
Quoted 5 lines
drivers/leds/leds-is31fl319x.c line 214
Quoted 2 lines
drivers/leds/leds-is31fl319x.c new file +1
-0+#ifdef CONFIG_OF Please provide only version for
CONFIG_OFdefined case and just fail probing ifof_nodeis NULL.Ok.
Quoted 5 lines
drivers/leds/leds-is31fl319x.c line 216
Quoted 3 lines
drivers/leds/leds-is31fl319x.c new file +2
-0+static struct is31fl319x_platform_data * +is31fl319x_led_dt_init (struct i2c_client *client,int num_leds)Please rename it to
is31fl319x_parse_dt.Done.
Quoted 72 lines
Quoted 72 lines
drivers/leds/leds-is31fl319x.c new file +71
-0+{ +struct device_node *np = client->dev.of_node, *child; +struct is31fl319x_platform_data *pdata; +struct led_info *is31_leds; +int count; + + count =of_get_child_count (np); +dev_dbg (&client->dev,"child count %d\n" , count); +if (!count || count >NUM_LEDS ) +return ERR_PTR (-ENODEV ); + + is31_leds =devm_kzalloc (&client->dev, +sizeof (struct led_info ) *NUM_LEDS ,GFP_KERNEL ); +if (!is31_leds) +return ERR_PTR (-ENOMEM ); + +for_each_child_of_node (np, child) { +struct led_info led; +u32 reg; +int ret; + + led.name = +of_get_property (child,"label" ,NULL ) ? : child->name; + led.default_trigger = +of_get_property (child,"linux,default-trigger" ,NULL ); + led.flags =0 ; + ret =of_property_read_u32 (child,"reg" , ®); +dev_dbg (&client->dev,"name = %s reg = %d\n" , led.name, reg); +if (ret !=0 || reg <0 || reg >= num_leds) +continue ; + +if (is31_leds[reg].name) +dev_err (&client->dev,"duplicate led line %d for %s -> %s\n" , + reg, is31_leds[reg].name, led.name); + is31_leds[reg] = led; + } + pdata =devm_kzalloc (&client->dev, +sizeof (struct is31fl319x_platform_data ),GFP_KERNEL ); +if (!pdata) +return ERR_PTR (-ENOMEM ); + + pdata->leds.leds = is31_leds; +return pdata; +} + +static const struct of_device_id of_is31fl319x_leds_match[] = { + { .compatible ="issi,is31fl3196" , (void *)6 }, + { .compatible ="issi,is31fl3199" , (void *)9 }, + {}, +}; +MODULE_DEVICE_TABLE (of, of_is31fl319x_leds_match); + +#else +static struct is31fl319x_platform_data * +is31fl319x_led_dt_init (struct i2c_client *client) +{ +return ERR_PTR (-ENODEV ); +} + +#endif + +static int is31fl319x_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +struct is31fl319x_chip *is31; +struct i2c_adapter *adapter; +struct is31fl319x_platform_data *pdata; +int err; +int i =0 ; + + adapter =to_i2c_adapter (client->dev.parent);Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 293
Quoted 6 lines
drivers/leds/leds-is31fl319x.c new file +6
-0+ pdata =dev_get_platdata (&client->dev); + +dev_dbg (&client->dev,"probe\n" ); + +dev_dbg (&client->dev,"NUM_LEDS = %d num_leds = %d\n" , +NUM_LEDS , (int ) id->driver_data);I believe this is stray debug logging.
I have merged it with the probe debug message to give more useful information.
Quoted 11 lines
drivers/leds/leds-is31fl319x.c line 301
Quoted 9 lines
drivers/leds/leds-is31fl319x.c new file +8
-0+ +if (!i2c_check_functionality (adapter,I2C_FUNC_I2C )) +return -EIO ; + +if (!pdata) { + pdata =is31fl319x_led_dt_init (client, (int ) id->driver_data); +if (IS_ERR (pdata)) { + dev_err(&client->dev, "DT led error %d\n",s/DT led error/DT parsing error/
done.
Quoted 14 lines
Quoted 14 lines
drivers/leds/leds-is31fl319x.c new file +13
-0+ (int) PTR_ERR(pdata)); +return PTR_ERR (pdata); + } + } + is31 =devm_kzalloc (&client->dev,sizeof (*is31),GFP_KERNEL ); +if (!is31) +return -ENOMEM ; + + is31->client = client; +INIT_WORK (&is31->work, is31fl319x_work); +spin_lock_init (&is31->lock); +i2c_set_clientdata (client, is31); +Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 320
Quoted 6 lines
drivers/leds/leds-is31fl319x.c new file +6
-0+/* check for reply from chip (we can't read any registers) */ + err =is31fl319x_write (is31,IS31FL319X_SHUTDOWN ,0x01 ); +if (err <0 ) { +dev_err (&client->dev,"no response from chip write: err = %d\n" , + err); +return -EPROBE_DEFER ;/* does not answer (yet) */ When can it happen? Does the chip have a long booting time or so?
Hm. Rarely...
So if it is not available on first attempt, there is no reason to probe later.
I will make it return
-EIO.Quoted 36 lines
Quoted 36 lines
drivers/leds/leds-is31fl319x.c new file +34
-0+ } + +for (i =0 ; i <NUM_LEDS ; i++) { +struct is31fl319x_led *l = is31->leds + i; + + l->chip = is31; +if (pdata->leds.leds[i].name && !pdata->leds.leds[i].flags) { + l->led_cdev.name = pdata->leds.leds[i].name; + l->led_cdev.default_trigger + = pdata->leds.leds[i].default_trigger; + l->led_cdev.brightness_set = is31fl319x_brightness_set; + l->led_cdev.blink_set = is31fl319x_blink_set; + err =led_classdev_register (&client->dev, + &l->led_cdev); +if (err <0 ) + goto exit; + } + } + +if (client->dev.of_node) { +u32 val; +u8 config2 =0 ; + +if (of_property_read_u32 (client->dev.of_node,"max-current-ma" , + &val)) { +if (val >40 ) + val =40 ; +if (val <5 ) + val =5 ; + config2 |= (((64 - val) /5 ) &0x7 ) <<4 ;/* CS */ + } +if (of_property_read_u32 (client->dev.of_node,"audio-gain-db" , + &val)) { +if (val >21 )Quoted 8 lines
drivers/leds/leds-is31fl319x.c line 360
Quoted 6 lines
drivers/leds/leds-is31fl319x.c new file +6
-0+ val =21 ; + config2 |= val /3 ;/* AGS */ + } +if (config2) +is31fl319x_write (is31,IS31FL319X_CONFIG2 , config2); + }Could you move the contents of this condition to
is31fl319x_led_dt_init?
Quoted 1 line
What would that improve?
Code readability? Having DT parsing in a single place is a good practice.
Quoted 110 lines
It is intended as a timing optimization to skip the i2c write.
With the implicit assumption that the register is already initialized to 0.
Which I know think is not always the case. The chip might already be initialized by U-Boot or after a reboot when it was not powered down.
So I think the condition must be removed completely.
Quoted 71 lines
Quoted 71 lines
drivers/leds/leds-is31fl319x.c new file +46
-0+ +schedule_work (&is31->work);/* first update */ + +dev_dbg (&client->dev,"probed\n" ); +return 0 ; +exit: +dev_err (&client->dev,"led error %d\n" , err); + +while (i--) { +if (is31->leds[i].led_cdev.name) +led_classdev_unregister (&is31->leds[i].led_cdev); + } +return err; +} + +static int is31fl319x_remove (struct i2c_client *client) +{ +int i; +struct is31fl319x_chip *is31 =i2c_get_clientdata (client); +struct is31fl319x_led *is31_leds = is31->leds; + +for (i =0 ; i <NUM_LEDS ; i++) { +if (is31_leds[i].led_cdev.name) +led_classdev_unregister (&is31_leds[i].led_cdev); + } + +cancel_work_sync (&is31->work); + +return 0 ; +} + +static struct i2c_driver is31fl319x_driver = { + .driver = { + .name ="leds-is31fl319x" , + .of_match_table =of_match_ptr (of_is31fl319x_leds_match), + }, + .probe = is31fl319x_probe, + .remove = is31fl319x_remove, + .id_table = is31fl319x_id, +}; + +module_i2c_driver (is31fl319x_driver); + +MODULE_AUTHOR ("H. Nikolaus Schaller <[email protected]>" ); +MODULE_DESCRIPTION ("IS31FL319X LED driver" ); +MODULE_LICENSE ("GPL v2" );include/linux/leds-is31fl319x.h new file +18
-0@@ -0,0 +1,24 @@ +/* +* IS31FL3196 LED chip driver. +* +* Copyright (C) 2015 H. Nikolaus Schaller <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +*/ + +#ifndef __LINUX_IS31FL319X_H +#define __LINUX_IS31FL319X_H +#include <linux/leds.h> Quoted 8 lines
include/linux/leds-is31fl319x.h line 22
Quoted 4 lines
include/linux/leds-is31fl319x.h new file +4
-0+ +struct is31fl319x_platform_data { +struct led_platform_data leds; +};We don't use
led_platform_datafor new drivers. Device Tree has become a standard. Effectively this header is not needed, please drop it.Ok, fine with that!
Quoted 8 lines
include/linux/leds-is31fl319x.h line 24
Quoted 3 lines
include/linux/leds-is31fl319x.h new file +1
-0+#endif /* __LINUX_IS31FL319X_H */ --
Best regards,
Jacek AnaszewskiI will combine all this and resubmit V2 after testing.
BR and thanks,
Nikolaus--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Best regards, Jacek Anaszewski
Rob Herring
maintainerRe: [PATCH] drivers: led: is31fl319x: 6/9-channel light effect led driver
In reply to H. Nikolaus SchallerQuoted 40 lines · H. Nikolaus Schaller
This is a driver for the Integrated Silicon Solution Inc. LED driver chips IS31FL3196 and IS31FL3199. They can drive up to 6 or 9 LEDs.
Each LED is individually controllable in brightness (through pwm) in 256 steps so that RGB LEDs can show any of ca. 16 Mio colors.
The maximum current of the LEDs can be programmed and limited to 5 .. 40mA through a device tree property.
The chip is connected through I2C and can have one of 4 addresses (
0x64..0x67) depending on how the AD pin is connected. The address is defined by the reg property as usual.The chip also has a shutdown input which could be connected to a GPIO, but this driver uses software shutdown if all LEDs are inactivated.
The chip also has breathing and audio features which are not supported by this driver.
This driver was developed and tested on OMAP5 based Pyra handheld prototype.
Signed-off-by H. Nikolaus Schaller <[email protected]>--- .../devicetree/bindings/leds/is31fl319x.txt | 41 +++ drivers/leds/Kconfig | 8 + drivers/leds/Makefile | 1 + drivers/leds/leds-is31fl319x.c | 406 +++++++++++++++++++++ include/linux/leds-is31fl319x.h | 24 ++ 5 files changed, 480 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/is31fl319x.txt create mode 100644 drivers/leds/leds-is31fl319x.c create mode 100644 include/linux/leds-is31fl319x.hDocumentation/devicetree/bindings/leds/is31fl319x.txt new file +0
-0
Documentation/devicetree/bindings/leds/is31fl319x.txt line 4
Quoted 4 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +4
-0@@ -0,0 +1,41 @@ +LEDs connected to is31fl319x RGB LED controller chip + +Required properties: +- compatible : should be : "issi,is31fl3196" or "issi,is31fl3199".
One per line please.
Documentation/devicetree/bindings/leds/is31fl319x.txt line 10
Quoted 6 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +6
-0+- #address-cells: must be 1 +- #size-cells: must be 0 +- reg: 0x64, 0x65, 0x66, 0x67. + +Optional properties: +- max-current-ma: maximum led current (5..40 mA, default 20 mA)
Use standard property led-max-microamp.
Quoted 10 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +10
-0+- audio-gain-db: audio gain selection (0..21 dB. default 0 dB) +- breathing & audio: not implemented + +Each led is represented as a sub-node of the issi,is31fl319x device. + +LED sub-node properties: +- label : (optional) see Documentation/devicetree/bindings/leds/common.txt +- reg : number of LED line (0 to 5 or 0 to 8 - not all need to be present) +- linux,default-trigger : (optional) + see Documentation/devicetree/bindings/leds/common.txt
Documentation/devicetree/bindings/leds/is31fl319x.txt line 30
Quoted 10 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +10
-0+ +Examples: + +fancy_leds: is31fl3196@65 { + compatible = "issi,is31fl319x"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x65>; + + led0: red-aux@0 {
Use generic unit names:
red-aux: led@0
Documentation/devicetree/bindings/leds/is31fl319x.txt line 35
Quoted 5 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +5
-0+ label = "red:aux"; + reg = <0>; + }; + + led1: green-power@4 {
ditto
Quoted 6 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +6
-0+ label = "green:power"; + reg = <4>; + linux,default-trigger = "default-on"; + }; +}; +
Re: [PATCH] drivers: led: is31fl319x: 6/9-channel light effect led driver
Hi,
Quoted 92 lines
Am 21.04.2016 um 17:01 schrieb Rob Herring <[email protected]>:
Quoted 40 lines · H. Nikolaus Schaller
This is a driver for the Integrated Silicon Solution Inc. LED driver chips IS31FL3196 and IS31FL3199. They can drive up to 6 or 9 LEDs.
Each LED is individually controllable in brightness (through pwm) in 256 steps so that RGB LEDs can show any of ca. 16 Mio colors.
The maximum current of the LEDs can be programmed and limited to 5 .. 40mA through a device tree property.
The chip is connected through I2C and can have one of 4 addresses (
0x64..0x67) depending on how the AD pin is connected. The address is defined by the reg property as usual.The chip also has a shutdown input which could be connected to a GPIO, but this driver uses software shutdown if all LEDs are inactivated.
The chip also has breathing and audio features which are not supported by this driver.
This driver was developed and tested on OMAP5 based Pyra handheld prototype.
Signed-off-by H. Nikolaus Schaller <[email protected]>---
.../devicetree/bindings/leds/is31fl319x.txt | 41 +++ drivers/leds/Kconfig | 8 + drivers/leds/Makefile | 1 + drivers/leds/leds-is31fl319x.c | 406 +++++++++++++++++++++ include/linux/leds-is31fl319x.h | 24 ++ 5 files changed, 480 insertions(+)create mode 100644
Documentation/devicetree/bindings/leds/is31fl319x.txtcreate mode 100644drivers/leds/leds-is31fl319x.c
create mode 100644include/linux/leds-is31fl319x.hDocumentation/devicetree/bindings/leds/is31fl319x.txt new file +0
-0Documentation/devicetree/bindings/leds/is31fl319x.txt line 4
Quoted 4 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +4
-0@@ -0,0 +1,41 @@ +LEDs connected to is31fl319x RGB LED controller chip + +Required properties: +- compatible : should be : "issi,is31fl3196" or "issi,is31fl3199".One per line please.
Documentation/devicetree/bindings/leds/is31fl319x.txt line 10
Quoted 6 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +6
-0+- #address-cells: must be 1 +- #size-cells: must be 0 +- reg: 0x64, 0x65, 0x66, 0x67. + +Optional properties: +- max-current-ma: maximum led current (5..40 mA, default 20 mA)Use standard property led-max-microamp.
Quoted 10 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +10
-0+- audio-gain-db: audio gain selection (0..21 dB. default 0 dB) +- breathing & audio: not implemented + +Each led is represented as a sub-node of the issi,is31fl319x device. + +LED sub-node properties: +- label : (optional) see Documentation/devicetree/bindings/leds/common.txt +- reg : number of LED line (0 to 5 or 0 to 8 - not all need to be present) +- linux,default-trigger : (optional) + see Documentation/devicetree/bindings/leds/common.txtDocumentation/devicetree/bindings/leds/is31fl319x.txt line 30
Quoted 10 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +10
-0+ +Examples: + +fancy_leds: is31fl3196@65 { + compatible = "issi,is31fl319x"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x65>; + + led0: red-aux@0 {Use generic unit names:
red-aux: led@0
Documentation/devicetree/bindings/leds/is31fl319x.txt line 35
Quoted 5 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +5
-0+ label = "red:aux"; + reg = <0>; + }; + + led1: green-power@4 {ditto
Quoted 6 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt line 41
Quoted 6 lines
Documentation/devicetree/bindings/leds/is31fl319x.txt new file +6
-0+ label = "green:power"; + reg = <4>; + linux,default-trigger = "default-on"; + }; +}; +
thanks! Will be included in upcoming V2.
BR,
Nikolaus