* [PATCH 0/4] leds: Add driver for the ISSI IS31FL32xx family of LED controllers @ 2016-03-03 3:01 David Rivshin (Allworx) 2016-03-03 3:01 ` [PATCH 1/4] DT: Add vendor prefix for Integrated Silicon Solutions Inc David Rivshin (Allworx) ` (3 more replies) 0 siblings, 4 replies; 28+ messages in thread From: David Rivshin (Allworx) @ 2016-03-03 3:01 UTC (permalink / raw) To: linux-leds-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA Cc: Richard Purdie, Jacek Anaszewski, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Stefan Wahren, linux-kernel-u79uwXL29TY76Z2rM5mHXA From: David Rivshin <drivshin-5fOYsn7Fw8lBDgjK7y7TUQ@public.gmane.org> This series adds support for the ISSI IS31FL32xx family of I2C LED controllers. Since the IS31FL3218 is actually the same device as the SN3218, the dedicated leds-sn3218 driver is removed and the compatible string is folded into this driver. Changes from RFC [1]: - Removed max-brightness DT property. - Added #address-cells and #size-cells properties to the example DT. - Refer to these devices as "LED controllers" in Kconfig. - Removed redundant last sentence from Kconfig entry - Removed unnecessary debug code. - Do not set led_classdev.brightness to 0 explicitly, as it is already initialized to 0 by devm_kzalloc(). - Used of_property_read_string() instead of of_get_property(). - Fail immediately on DT parsing error in a child node, rather than continuing on with the non-faulty ones. - Added additional comments for some things that might be non-obvious. - Added constants for the location of the SSD bit in the SHUTDOWN register, and the 3216's CONFIG register. - Added special sw_shutdown_func for the 3216 device, as that bit is in a different register, at a different position, and has reverse polarity compared to all the other devices. - Refactored is31fl32xx_init_regs() to separate out some logic into is31fl32xx_reset_regs() and is31fl32xx_software_shutdown(). - Added 4th patch to replace the now-redundant leds-sn3218. [1] http://www.spinics.net/lists/linux-leds/msg05564.html http://thread.gmane.org/gmane.linux.leds/4530 David Rivshin (4): DT: Add vendor prefix for Integrated Silicon Solutions Inc. DT: leds: Add binding for the ISSI IS31FL32xx family of LED controllers leds: Add driver for the ISSI IS31FL32xx family of LED controllers leds: Replace dedicated SN3218 driver with IS31FL32XX driver .../devicetree/bindings/leds/leds-is31fl32xx.txt | 52 +++ .../devicetree/bindings/leds/leds-sn3218.txt | 41 -- .../devicetree/bindings/vendor-prefixes.txt | 1 + drivers/leds/Kconfig | 16 +- drivers/leds/Makefile | 2 +- drivers/leds/leds-is31fl32xx.c | 509 +++++++++++++++++++++ drivers/leds/leds-sn3218.c | 306 ------------- 7 files changed, 569 insertions(+), 358 deletions(-) create mode 100644 Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt delete mode 100644 Documentation/devicetree/bindings/leds/leds-sn3218.txt create mode 100644 drivers/leds/leds-is31fl32xx.c delete mode 100644 drivers/leds/leds-sn3218.c -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 1/4] DT: Add vendor prefix for Integrated Silicon Solutions Inc. 2016-03-03 3:01 [PATCH 0/4] leds: Add driver for the ISSI IS31FL32xx family of LED controllers David Rivshin (Allworx) @ 2016-03-03 3:01 ` David Rivshin (Allworx) 2016-03-05 4:28 ` Rob Herring 2016-03-03 3:01 ` [PATCH 2/4] DT: leds: Add binding for the ISSI IS31FL32xx family of LED controllers David Rivshin (Allworx) ` (2 subsequent siblings) 3 siblings, 1 reply; 28+ messages in thread From: David Rivshin (Allworx) @ 2016-03-03 3:01 UTC (permalink / raw) To: linux-leds, devicetree Cc: Richard Purdie, Jacek Anaszewski, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Stefan Wahren, linux-kernel From: David Rivshin <drivshin@allworx.com> ISSI is the stock ticker Integrated Silicon Solutions Inc. Company website: http://www.issi.com Signed-off-by: David Rivshin <drivshin@allworx.com> --- Changes from RFC: none Documentation/devicetree/bindings/vendor-prefixes.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt index 52f22f9..dd72e05 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.txt +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt @@ -120,6 +120,7 @@ intercontrol Inter Control Group invensense InvenSense Inc. isee ISEE 2007 S.L. isil Intersil +issi Integrated Silicon Solutions Inc. jedec JEDEC Solid State Technology Association karo Ka-Ro electronics GmbH keymile Keymile GmbH -- 2.5.0 ^ permalink raw reply related [flat|nested] 28+ messages in thread
* Re: [PATCH 1/4] DT: Add vendor prefix for Integrated Silicon Solutions Inc. 2016-03-03 3:01 ` [PATCH 1/4] DT: Add vendor prefix for Integrated Silicon Solutions Inc David Rivshin (Allworx) @ 2016-03-05 4:28 ` Rob Herring 0 siblings, 0 replies; 28+ messages in thread From: Rob Herring @ 2016-03-05 4:28 UTC (permalink / raw) To: David Rivshin (Allworx) Cc: linux-leds, devicetree, Richard Purdie, Jacek Anaszewski, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Stefan Wahren, linux-kernel On Wed, Mar 02, 2016 at 10:01:32PM -0500, David Rivshin (Allworx) wrote: > From: David Rivshin <drivshin@allworx.com> > > ISSI is the stock ticker Integrated Silicon Solutions Inc. > Company website: http://www.issi.com > > Signed-off-by: David Rivshin <drivshin@allworx.com> > --- > > Changes from RFC: > none > > Documentation/devicetree/bindings/vendor-prefixes.txt | 1 + > 1 file changed, 1 insertion(+) Acked-by: Rob Herring <robh@kernel.org> ^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 2/4] DT: leds: Add binding for the ISSI IS31FL32xx family of LED controllers 2016-03-03 3:01 [PATCH 0/4] leds: Add driver for the ISSI IS31FL32xx family of LED controllers David Rivshin (Allworx) 2016-03-03 3:01 ` [PATCH 1/4] DT: Add vendor prefix for Integrated Silicon Solutions Inc David Rivshin (Allworx) @ 2016-03-03 3:01 ` David Rivshin (Allworx) 2016-03-05 4:28 ` Rob Herring 2016-03-03 3:01 ` [PATCH 3/4] leds: Add driver " David Rivshin (Allworx) 2016-03-03 3:01 ` [PATCH 4/4] leds: Replace dedicated SN3218 driver with IS31FL32XX driver David Rivshin (Allworx) 3 siblings, 1 reply; 28+ messages in thread From: David Rivshin (Allworx) @ 2016-03-03 3:01 UTC (permalink / raw) To: linux-leds, devicetree Cc: Richard Purdie, Jacek Anaszewski, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Stefan Wahren, linux-kernel From: David Rivshin <drivshin@allworx.com> This adds a binding description for the is31fl3236/35/18/16 I2C LED controllers. Signed-off-by: David Rivshin <drivshin@allworx.com> --- Rob, I went with the 1-based 'reg' property here. I inferred that that would be your preference based on the previous thread [1]. Let me know if that's not the case. Changes from RFC: - Removed max-brightness property. - Added #address-cells and #size-cells properties to the example. [1] http://www.spinics.net/lists/linux-leds/msg05589.html .../devicetree/bindings/leds/leds-is31fl32xx.txt | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt diff --git a/Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt b/Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt new file mode 100644 index 0000000..539df2e --- /dev/null +++ b/Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt @@ -0,0 +1,49 @@ +Binding for ISSI IS31FL32xx LED Drivers + +The IS31FL32xx family of LED drivers are I2C devices with multiple +constant-current channels, each with independent 256-level PWM control. +Each LED is represented as a sub-node of the device. + +Required properties: +- compatible: one of + issi,is31fl3236 + issi,is31fl3235 + issi,is31fl3218 + issi,is31fl3216 +- reg: I2C slave address +- address-cells : must be 1 +- size-cells : must be 0 + +LED sub-node properties: +- reg : LED channel number (1..N) +- label : (optional) + see Documentation/devicetree/bindings/leds/common.txt +- linux,default-trigger : (optional) + see Documentation/devicetree/bindings/leds/common.txt + + +Example: + +leds: is31fl3236@3c { + compatible = "issi,is31fl3236"; + reg = <0x3c>; + #address-cells = <1>; + #size-cells = <0>; + + led@1 { + reg = <1>; + label = "EB:blue:usr0"; + }; + led@2 { + reg = <2>; + label = "EB:blue:usr1"; + }; + ... + led@36 { + reg = <36>; + label = "EB:blue:usr35"; + }; +}; + +For more product information please see the link below: +http://www.issi.com/US/product-analog-fxled-driver.shtml -- 2.5.0 ^ permalink raw reply related [flat|nested] 28+ messages in thread
* Re: [PATCH 2/4] DT: leds: Add binding for the ISSI IS31FL32xx family of LED controllers 2016-03-03 3:01 ` [PATCH 2/4] DT: leds: Add binding for the ISSI IS31FL32xx family of LED controllers David Rivshin (Allworx) @ 2016-03-05 4:28 ` Rob Herring 0 siblings, 0 replies; 28+ messages in thread From: Rob Herring @ 2016-03-05 4:28 UTC (permalink / raw) To: David Rivshin (Allworx) Cc: linux-leds, devicetree, Richard Purdie, Jacek Anaszewski, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Stefan Wahren, linux-kernel On Wed, Mar 02, 2016 at 10:01:33PM -0500, David Rivshin (Allworx) wrote: > From: David Rivshin <drivshin@allworx.com> > > This adds a binding description for the is31fl3236/35/18/16 I2C LED > controllers. > > Signed-off-by: David Rivshin <drivshin@allworx.com> > --- > > Rob, > I went with the 1-based 'reg' property here. I inferred that that > would be your preference based on the previous thread [1]. Let me > know if that's not the case. > > Changes from RFC: > - Removed max-brightness property. > - Added #address-cells and #size-cells properties to the example. > > [1] http://www.spinics.net/lists/linux-leds/msg05589.html > > .../devicetree/bindings/leds/leds-is31fl32xx.txt | 49 ++++++++++++++++++++++ > 1 file changed, 49 insertions(+) > create mode 100644 Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt > > diff --git a/Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt b/Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt > new file mode 100644 > index 0000000..539df2e > --- /dev/null > +++ b/Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt > @@ -0,0 +1,49 @@ > +Binding for ISSI IS31FL32xx LED Drivers > + > +The IS31FL32xx family of LED drivers are I2C devices with multiple > +constant-current channels, each with independent 256-level PWM control. > +Each LED is represented as a sub-node of the device. > + > +Required properties: > +- compatible: one of > + issi,is31fl3236 > + issi,is31fl3235 > + issi,is31fl3218 > + issi,is31fl3216 > +- reg: I2C slave address > +- address-cells : must be 1 > +- size-cells : must be 0 > + > +LED sub-node properties: > +- reg : LED channel number (1..N) > +- label : (optional) > + see Documentation/devicetree/bindings/leds/common.txt > +- linux,default-trigger : (optional) > + see Documentation/devicetree/bindings/leds/common.txt > + > + > +Example: > + > +leds: is31fl3236@3c { Other way around: is31fl3236: leds@3c Otherwise, Acked-by: Rob Herring <robh@kernel.org> ^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 3/4] leds: Add driver for the ISSI IS31FL32xx family of LED controllers 2016-03-03 3:01 [PATCH 0/4] leds: Add driver for the ISSI IS31FL32xx family of LED controllers David Rivshin (Allworx) 2016-03-03 3:01 ` [PATCH 1/4] DT: Add vendor prefix for Integrated Silicon Solutions Inc David Rivshin (Allworx) 2016-03-03 3:01 ` [PATCH 2/4] DT: leds: Add binding for the ISSI IS31FL32xx family of LED controllers David Rivshin (Allworx) @ 2016-03-03 3:01 ` David Rivshin (Allworx) 2016-03-03 3:21 ` kbuild test robot ` (2 more replies) 2016-03-03 3:01 ` [PATCH 4/4] leds: Replace dedicated SN3218 driver with IS31FL32XX driver David Rivshin (Allworx) 3 siblings, 3 replies; 28+ messages in thread From: David Rivshin (Allworx) @ 2016-03-03 3:01 UTC (permalink / raw) To: linux-leds, devicetree Cc: Richard Purdie, Jacek Anaszewski, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Stefan Wahren, linux-kernel From: David Rivshin <drivshin@allworx.com> The IS31FL32xx family of LED controllers are I2C devices with multiple constant-current channels, each with independent 256-level PWM control. Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml This has been tested on the IS31FL3236 and IS31FL3216, on an ARM (TI am335x) platform. The programming paradigm of these devices is similar in the following ways: - All registers are 8 bit - All LED control registers are write-only - Each LED channel has a PWM register (0-255) - PWM register writes are shadowed until an Update register is poked - All have a concept of Software Shutdown, which disables output However, there are some differences in devices: - 3236/3235 have a separate Control register for each LED, (3218/3216 pack the enable bits into fewer registers) - 3236/3235 have a per-channel current divisor setting - 3236/3235 have a Global Control register that can turn off all LEDs - 3216 is unique in a number of ways - OUT9-OUT16 can be configured as GPIOs instead of LED controls - LEDs can be programmed with an 8-frame animation, with programmable delay between frames - LEDs can be modulated by an input audio signal - Max output current can be adjusted from 1/4 to 2x globally - Has a Configuration register instead of a Shutdown register This driver currently only supports the base PWM control function of these devices. The following features of these devices are not implemented, although it should be possible to add them in the future: - All devices are capable of going into a lower-power "software shutdown" mode. - The is31fl3236 and is31fl3235 can reduce the max output current per-channel with a divisor of 1, 2, 3, or 4. - The is31fl3216 can use some LED channels as GPIOs instead. - The is31fl3216 can animate LEDs in hardware. - The is31fl3216 can modulate LEDs according to an audio input. - The is31fl3216 can reduce/increase max output current globally. Signed-off-by: David Rivshin <drivshin@allworx.com> --- You may see two instances of this warning: "passing argument 1 of 'of_property_read_string' discards 'const' qualifier from pointer target type" That is a result of of_property_read_string() taking a non-const struct device_node pointer parameter. I have separately submitted a patch to fix that [1], and a few related functions which had the same issue. I'm hoping that will get into linux-next before this does, so that the warnings never show up there. Changes from RFC: - Removed max-brightness DT property. - Refer to these devices as "LED controllers" in Kconfig. - Removed redundant last sentence from Kconfig entry - Removed unnecessary debug code. - Do not set led_classdev.brightness to 0 explicitly, as it is already initialized to 0 by devm_kzalloc(). - Used of_property_read_string() instead of of_get_property(). - Fail immediately on DT parsing error in a child node, rather than continuing on with the non-faulty ones. - Added additional comments for some things that might be non-obvious. - Added constants for the location of the SSD bit in the SHUTDOWN register, and the 3216's CONFIG register. - Added special sw_shutdown_func for the 3216 device, as that bit is in a different register, at a different position, and has reverse polarity compared to all the other devices. - Refactored is31fl32xx_init_regs() to separate out some logic into is31fl32xx_reset_regs() and is31fl32xx_software_shutdown(). [1] https://lkml.org/lkml/2016/3/2/746 drivers/leds/Kconfig | 8 + drivers/leds/Makefile | 1 + drivers/leds/leds-is31fl32xx.c | 505 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 514 insertions(+) create mode 100644 drivers/leds/leds-is31fl32xx.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 1034696..9c63ba4 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -580,6 +580,14 @@ config LEDS_SN3218 This driver can also be built as a module. If so the module will be called leds-sn3218. +config LEDS_IS31FL32XX + tristate "LED support for ISSI IS31FL32XX I2C LED controller family" + depends on LEDS_CLASS && I2C && OF + help + Say Y here to include support for ISSI IS31FL32XX LED controllers. + They are I2C devices with multiple constant-current channels, each + with independent 256-level PWM control. + comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)" config LEDS_BLINKM diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index 89c9b6f..3fdf313 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -67,6 +67,7 @@ obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o obj-$(CONFIG_LEDS_SN3218) += leds-sn3218.o +obj-$(CONFIG_LEDS_IS31FL32XX) += leds-is31fl32xx.o # LED SPI Drivers obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c new file mode 100644 index 0000000..49818f0 --- /dev/null +++ b/drivers/leds/leds-is31fl32xx.c @@ -0,0 +1,505 @@ +/* + * linux/drivers/leds-is31fl32xx.c + * + * Driver for ISSI IS31FL32xx family of I2C LED controllers + * + * Copyright 2015 Allworx Corp. + * + * + * 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. + * + * Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml + */ + +#include <linux/err.h> +#include <linux/i2c.h> +#include <linux/kernel.h> +#include <linux/leds.h> +#include <linux/module.h> +#include <linux/of_platform.h> + +/* Used to indicate a device has no such register */ +#define IS31FL32XX_REG_NONE 0xFF + +/* Software Shutdown bit in Shutdown Register */ +#define IS31FL32XX_SHUTDOWN_SSD_ENABLE 0 +#define IS31FL32XX_SHUTDOWN_SSD_DISABLE BIT(0) + +/* IS31FL3216 has a number of unique registers */ +#define IS31FL3216_CONFIG_REG 0x00 +#define IS31FL3216_LIGHTING_EFFECT_REG 0x03 +#define IS31FL3216_CHANNEL_CONFIG_REG 0x04 + +/* Software Shutdown bit in 3216 Config Register */ +#define IS31FL3216_CONFIG_SSD_ENABLE BIT(7) +#define IS31FL3216_CONFIG_SSD_DISABLE 0 + +struct is31fl32xx_priv; +struct is31fl32xx_led_data { + struct led_classdev cdev; + u8 channel; /* 1-based, max priv->cdef->channels */ + struct is31fl32xx_priv *priv; +}; + +struct is31fl32xx_priv { + const struct is31fl32xx_chipdef *cdef; + struct i2c_client *client; + unsigned int num_leds; + struct is31fl32xx_led_data leds[0]; +}; + +/** + * struct is31fl32xx_chipdef - chip-specific attributes + * @channels : Number of LED channels + * @shutdown_reg : address of Shutdown register (optional) + * @pwm_update_reg : address of PWM Update register + * @global_control_reg : address of Global Control register (optional) + * @reset_reg : address of Reset register (optional) + * @pwm_register_base : address of first PWM register + * @pwm_registers_reversed: : true if PWM registers count down instead of up + * @led_control_register_base : address of first LED control register (optional) + * @enable_bits_per_led_control_register: number of LEDs enable bits in each + * @reset_func: : pointer to reset function + * + * For all optional register addresses, the sentinel value %IS31FL32XX_REG_NONE + * indicates that this chip has no such register. + * + * If non-NULL, @reset_func will be called during probing to set all + * necessary registers to a known initialization state. This is needed + * for chips that do not have a @reset_reg. + * + * @enable_bits_per_led_control_register must be >=1 if + * @led_control_register_base != %IS31FL32XX_REG_NONE. + */ +struct is31fl32xx_chipdef { + u8 channels; + u8 shutdown_reg; + u8 pwm_update_reg; + u8 global_control_reg; + u8 reset_reg; + u8 pwm_register_base; + bool pwm_registers_reversed; + u8 led_control_register_base; + u8 enable_bits_per_led_control_register; + int (*reset_func)(struct is31fl32xx_priv *priv); + int (*sw_shutdown_func)(struct is31fl32xx_priv *priv, bool enable); +}; + +static const struct is31fl32xx_chipdef is31fl3236_cdef = { + .channels = 36, + .shutdown_reg = 0x00, + .pwm_update_reg = 0x25, + .global_control_reg = 0x4a, + .reset_reg = 0x4f, + .pwm_register_base = 0x01, + .led_control_register_base = 0x26, + .enable_bits_per_led_control_register = 1, +}; + +static const struct is31fl32xx_chipdef is31fl3235_cdef = { + .channels = 28, + .shutdown_reg = 0x00, + .pwm_update_reg = 0x25, + .global_control_reg = 0x4a, + .reset_reg = 0x4f, + .pwm_register_base = 0x05, + .led_control_register_base = 0x2a, + .enable_bits_per_led_control_register = 1, +}; + +static const struct is31fl32xx_chipdef is31fl3218_cdef = { + .channels = 18, + .shutdown_reg = 0x00, + .pwm_update_reg = 0x16, + .global_control_reg = IS31FL32XX_REG_NONE, + .reset_reg = 0x17, + .pwm_register_base = 0x01, + .led_control_register_base = 0x13, + .enable_bits_per_led_control_register = 6, +}; + +static int is31fl3216_reset(struct is31fl32xx_priv *priv); +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, + bool enable); +static const struct is31fl32xx_chipdef is31fl3216_cdef = { + .channels = 16, + .shutdown_reg = IS31FL32XX_REG_NONE, + .pwm_update_reg = 0xB0, + .global_control_reg = IS31FL32XX_REG_NONE, + .reset_reg = IS31FL32XX_REG_NONE, + .pwm_register_base = 0x10, + .pwm_registers_reversed = true, + .led_control_register_base = 0x01, + .enable_bits_per_led_control_register = 8, + .reset_func = is31fl3216_reset, + .sw_shutdown_func = is31fl3216_software_shutdown, +}; + +static int is31fl32xx_write(struct is31fl32xx_priv *priv, u8 reg, u8 val) +{ + int ret; + + dev_dbg(&priv->client->dev, "writing register 0x%02X=0x%02X", reg, val); + + ret = i2c_smbus_write_byte_data(priv->client, reg, val); + if (ret) { + dev_err(&priv->client->dev, + "register write to 0x%02X failed (error %d)", + reg, ret); + } + return ret; +} + +/* + * Custom reset function for IS31FL3216 because it does not have a RESET + * register the way that the other IS31FL32xx chips do. We don't bother + * writing the GPIO and animation registers, because the registers we + * do write ensure those will have no effect. + */ +static int is31fl3216_reset(struct is31fl32xx_priv *priv) +{ + unsigned int i; + int ret; + + ret = is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, + IS31FL3216_CONFIG_SSD_ENABLE); + if (ret) + return ret; + for (i = 0; i < priv->cdef->channels; i++) { + ret = is31fl32xx_write(priv, priv->cdef->pwm_register_base+i, + 0x00); + if (ret) + return ret; + } + ret = is31fl32xx_write(priv, priv->cdef->pwm_update_reg, 0); + if (ret) + return ret; + ret = is31fl32xx_write(priv, IS31FL3216_LIGHTING_EFFECT_REG, 0x00); + if (ret) + return ret; + ret = is31fl32xx_write(priv, IS31FL3216_CHANNEL_CONFIG_REG, 0x00); + if (ret) + return ret; + + return 0; +} + +/* + * Custom Software-Shutdown function for IS31FL3216 because it does not have + * a SHUTDOWN register the way that the other IS31FL32xx chips do. + * We don't bother doing a read/modify/write on the CONFIG register because + * we only ever use a value of '0' for the other fields in that register. + */ +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, + bool enable) +{ + u8 value = enable ? IS31FL3216_CONFIG_SSD_ENABLE : + IS31FL3216_CONFIG_SSD_DISABLE; + + return is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, value); +} + +/* + * NOTE: A mutex is not needed in this function because: + * - All referenced data is read-only after probe() + * - The I2C core has a mutex on to protect the bus + * - There are no read/modify/write operations + * - Intervening operations between the write of the PWM register + * and the Update register are harmless. + * + * Example: + * PWM_REG_1 write 16 + * UPDATE_REG write 0 + * PWM_REG_2 write 128 + * UPDATE_REG write 0 + * vs: + * PWM_REG_1 write 16 + * PWM_REG_2 write 128 + * UPDATE_REG write 0 + * UPDATE_REG write 0 + * are equivalent. Poking the Update register merely applies all PWM + * register writes up to that point. + */ +static int is31fl32xx_brightness_set(struct led_classdev *led_cdev, + enum led_brightness brightness) +{ + const struct is31fl32xx_led_data *led_data = + container_of(led_cdev, struct is31fl32xx_led_data, cdev); + const struct is31fl32xx_chipdef *cdef = led_data->priv->cdef; + u8 pwm_register_offset; + int ret; + + dev_dbg(led_cdev->dev, "%s: %d\n", __func__, brightness); + + /* NOTE: led_data->channel is 1-based */ + if (cdef->pwm_registers_reversed) + pwm_register_offset = cdef->channels - led_data->channel; + else + pwm_register_offset = led_data->channel - 1; + + ret = is31fl32xx_write(led_data->priv, + cdef->pwm_register_base + pwm_register_offset, + brightness); + if (ret) + return ret; + + return is31fl32xx_write(led_data->priv, cdef->pwm_update_reg, 0); +} + +static int is31fl32xx_reset_regs(struct is31fl32xx_priv *priv) +{ + const struct is31fl32xx_chipdef *cdef = priv->cdef; + int ret; + + if (cdef->reset_reg != IS31FL32XX_REG_NONE) { + ret = is31fl32xx_write(priv, cdef->reset_reg, 0); + if (ret) + return ret; + } + + if (cdef->reset_func) + return cdef->reset_func(priv); + + return 0; +} + +static int is31fl32xx_software_shutdown(struct is31fl32xx_priv *priv, + bool enable) +{ + const struct is31fl32xx_chipdef *cdef = priv->cdef; + int ret; + + if (cdef->shutdown_reg != IS31FL32XX_REG_NONE) { + u8 value = enable ? IS31FL32XX_SHUTDOWN_SSD_ENABLE : + IS31FL32XX_SHUTDOWN_SSD_DISABLE; + ret = is31fl32xx_write(priv, cdef->shutdown_reg, value); + if (ret) + return ret; + } + + if (cdef->sw_shutdown_func) + return cdef->sw_shutdown_func(priv, enable); + + return 0; +} + +static int is31fl32xx_init_regs(struct is31fl32xx_priv *priv) +{ + const struct is31fl32xx_chipdef *cdef = priv->cdef; + int ret; + + ret = is31fl32xx_reset_regs(priv); + if (ret) + return ret; + + /* + * Set enable bit for all channels. + * We will control state with PWM registers alone. + */ + if (cdef->led_control_register_base != IS31FL32XX_REG_NONE) { + u8 value = + GENMASK(cdef->enable_bits_per_led_control_register-1, 0); + u8 num_regs = cdef->channels / + cdef->enable_bits_per_led_control_register; + int i; + + for (i = 0; i < num_regs; i++) { + ret = is31fl32xx_write(priv, + cdef->led_control_register_base+i, + value); + if (ret) + return ret; + } + } + + ret = is31fl32xx_software_shutdown(priv, false); + if (ret) + return ret; + + if (cdef->global_control_reg != IS31FL32XX_REG_NONE) { + ret = is31fl32xx_write(priv, cdef->global_control_reg, 0x00); + if (ret) + return ret; + } + + return 0; +} + +static inline size_t sizeof_is31fl32xx_priv(int num_leds) +{ + return sizeof(struct is31fl32xx_priv) + + (sizeof(struct is31fl32xx_led_data) * num_leds); +} + +static int is31fl32xx_parse_child_dt(const struct device *dev, + const struct device_node *child, + struct is31fl32xx_led_data *led_data) +{ + struct led_classdev *cdev = &led_data->cdev; + int ret = 0; + u32 reg; + + if (of_property_read_string(child, "label", &cdev->name)) + cdev->name = child->name; + + ret = of_property_read_u32(child, "reg", ®); + if (ret || reg < 1 || reg > led_data->priv->cdef->channels) { + dev_err(dev, + "Child node %s does not have a valid reg property\n", + child->full_name); + return -EINVAL; + } + led_data->channel = reg; + + of_property_read_string(child, "linux,default-trigger", + &cdev->default_trigger); + + cdev->brightness_set_blocking = is31fl32xx_brightness_set; + + return 0; +} + +static struct is31fl32xx_led_data *is31fl32xx_find_led_data( + struct is31fl32xx_priv *priv, + u8 channel) +{ + size_t i; + + for (i = 0; i < priv->num_leds; i++) { + if (priv->leds[i].channel == channel) + return &priv->leds[i]; + } + + return NULL; +} + +static int is31fl32xx_parse_dt(struct device *dev, + struct is31fl32xx_priv *priv) +{ + struct device_node *child; + int ret = 0; + + for_each_child_of_node(dev->of_node, child) { + struct is31fl32xx_led_data *led_data = + &priv->leds[priv->num_leds]; + const struct is31fl32xx_led_data *other_led_data; + + led_data->priv = priv; + + ret = is31fl32xx_parse_child_dt(dev, child, led_data); + if (ret) + goto err; + + /* Detect if channel is already in use by another child */ + other_led_data = is31fl32xx_find_led_data(priv, + led_data->channel); + if (other_led_data) { + dev_err(dev, + "%s and %s both attempting to use channel %d\n", + led_data->cdev.name, + other_led_data->cdev.name, + led_data->channel); + goto err; + } + + ret = devm_led_classdev_register(dev, &led_data->cdev); + if (ret) { + dev_err(dev, "failed to register PWM led for %s: %d\n", + led_data->cdev.name, ret); + goto err; + } + + priv->num_leds++; + } + + return 0; + +err: + of_node_put(child); + return ret; +} + +static const struct of_device_id of_is31fl31xx_match[] = { + { .compatible = "issi,is31fl3236", .data = &is31fl3236_cdef, }, + { .compatible = "issi,is31fl3235", .data = &is31fl3235_cdef, }, + { .compatible = "issi,is31fl3218", .data = &is31fl3218_cdef, }, + { .compatible = "issi,is31fl3216", .data = &is31fl3216_cdef, }, + {}, +}; + +MODULE_DEVICE_TABLE(of, of_is31fl31xx_match); + +static int is31fl32xx_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + const struct is31fl32xx_chipdef *cdef; + const struct of_device_id *of_dev_id; + struct device *dev = &client->dev; + struct is31fl32xx_priv *priv; + int count; + int ret = 0; + + of_dev_id = of_match_device(of_is31fl31xx_match, dev); + if (!of_dev_id) + return -EINVAL; + + cdef = of_dev_id->data; + + count = of_get_child_count(dev->of_node); + if (!count) + return -EINVAL; + + priv = devm_kzalloc(dev, sizeof_is31fl32xx_priv(count), + GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->client = client; + priv->cdef = cdef; + i2c_set_clientdata(client, priv); + + ret = is31fl32xx_init_regs(priv); + if (ret) + return ret; + + ret = is31fl32xx_parse_dt(dev, priv); + if (ret) + return ret; + + return 0; +} + +static int is31fl32xx_remove(struct i2c_client *client) +{ + struct is31fl32xx_priv *priv = i2c_get_clientdata(client); + + return is31fl32xx_reset_regs(priv); +} + +/* + * i2c-core requires that id_table be non-NULL, even though + * it is not used for DeviceTree based instantiation. + */ +static const struct i2c_device_id is31fl31xx_id[] = { + {}, +}; + +MODULE_DEVICE_TABLE(i2c, is31fl31xx_id); + +static struct i2c_driver is31fl32xx_driver = { + .driver = { + .name = "is31fl32xx", + .of_match_table = of_is31fl31xx_match, + }, + .probe = is31fl32xx_probe, + .remove = is31fl32xx_remove, + .id_table = is31fl31xx_id, +}; + +module_i2c_driver(is31fl32xx_driver); + +MODULE_AUTHOR("David Rivshin <drivshin@allworx.com>"); +MODULE_DESCRIPTION("ISSI IS31FL32xx LED driver"); +MODULE_LICENSE("GPL v2"); -- 2.5.0 ^ permalink raw reply related [flat|nested] 28+ messages in thread
* Re: [PATCH 3/4] leds: Add driver for the ISSI IS31FL32xx family of LED controllers 2016-03-03 3:01 ` [PATCH 3/4] leds: Add driver " David Rivshin (Allworx) @ 2016-03-03 3:21 ` kbuild test robot 2016-03-03 14:51 ` Jacek Anaszewski 2016-03-03 18:13 ` Stefan Wahren 2 siblings, 0 replies; 28+ messages in thread From: kbuild test robot @ 2016-03-03 3:21 UTC (permalink / raw) To: David Rivshin (Allworx) Cc: kbuild-all, linux-leds, devicetree, Richard Purdie, Jacek Anaszewski, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Stefan Wahren, linux-kernel [-- Attachment #1: Type: text/plain, Size: 3397 bytes --] Hi David, [auto build test WARNING on j.anaszewski-leds/for-next] [also build test WARNING on next-20160302] [cannot apply to v4.5-rc6] [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/David-Rivshin-Allworx/leds-Add-driver-for-the-ISSI-IS31FL32xx-family-of-LED-controllers/20160303-110656 base: https://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski/linux-leds for-next config: sparc64-allyesconfig (attached as .config) reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross ARCH=sparc64 All warnings (new ones prefixed by >>): drivers/leds/leds-is31fl32xx.c: In function 'is31fl32xx_parse_child_dt': >> drivers/leds/leds-is31fl32xx.c:344:6: warning: passing argument 1 of 'of_property_read_string' discards 'const' qualifier from pointer target type if (of_property_read_string(child, "label", &cdev->name)) ^ In file included from arch/sparc/include/asm/openprom.h:14:0, from arch/sparc/include/asm/device.h:9, from include/linux/device.h:30, from include/linux/i2c.h:30, from drivers/leds/leds-is31fl32xx.c:17: include/linux/of.h:299:12: note: expected 'struct device_node *' but argument is of type 'const struct device_node *' extern int of_property_read_string(struct device_node *np, ^ drivers/leds/leds-is31fl32xx.c:356:2: warning: passing argument 1 of 'of_property_read_string' discards 'const' qualifier from pointer target type of_property_read_string(child, "linux,default-trigger", ^ In file included from arch/sparc/include/asm/openprom.h:14:0, from arch/sparc/include/asm/device.h:9, from include/linux/device.h:30, from include/linux/i2c.h:30, from drivers/leds/leds-is31fl32xx.c:17: include/linux/of.h:299:12: note: expected 'struct device_node *' but argument is of type 'const struct device_node *' extern int of_property_read_string(struct device_node *np, ^ vim +344 drivers/leds/leds-is31fl32xx.c 328 } 329 330 static inline size_t sizeof_is31fl32xx_priv(int num_leds) 331 { 332 return sizeof(struct is31fl32xx_priv) + 333 (sizeof(struct is31fl32xx_led_data) * num_leds); 334 } 335 336 static int is31fl32xx_parse_child_dt(const struct device *dev, 337 const struct device_node *child, 338 struct is31fl32xx_led_data *led_data) 339 { 340 struct led_classdev *cdev = &led_data->cdev; 341 int ret = 0; 342 u32 reg; 343 > 344 if (of_property_read_string(child, "label", &cdev->name)) 345 cdev->name = child->name; 346 347 ret = of_property_read_u32(child, "reg", ®); 348 if (ret || reg < 1 || reg > led_data->priv->cdef->channels) { 349 dev_err(dev, 350 "Child node %s does not have a valid reg property\n", 351 child->full_name); 352 return -EINVAL; --- 0-DAY kernel test infrastructure Open Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation [-- Attachment #2: .config.gz --] [-- Type: application/octet-stream, Size: 45112 bytes --] ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 3/4] leds: Add driver for the ISSI IS31FL32xx family of LED controllers 2016-03-03 3:01 ` [PATCH 3/4] leds: Add driver " David Rivshin (Allworx) 2016-03-03 3:21 ` kbuild test robot @ 2016-03-03 14:51 ` Jacek Anaszewski 2016-03-04 0:45 ` David Rivshin (Allworx) 2016-03-03 18:13 ` Stefan Wahren 2 siblings, 1 reply; 28+ messages in thread From: Jacek Anaszewski @ 2016-03-03 14:51 UTC (permalink / raw) To: David Rivshin (Allworx) Cc: linux-leds, devicetree, Richard Purdie, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Stefan Wahren, linux-kernel Hi David, Thanks for the update. Two remarks in the code. On 03/03/2016 04:01 AM, David Rivshin (Allworx) wrote: > From: David Rivshin <drivshin@allworx.com> > > The IS31FL32xx family of LED controllers are I2C devices with multiple > constant-current channels, each with independent 256-level PWM control. > > Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml > > This has been tested on the IS31FL3236 and IS31FL3216, on an ARM > (TI am335x) platform. > > The programming paradigm of these devices is similar in the following > ways: > - All registers are 8 bit > - All LED control registers are write-only > - Each LED channel has a PWM register (0-255) > - PWM register writes are shadowed until an Update register is poked > - All have a concept of Software Shutdown, which disables output > > However, there are some differences in devices: > - 3236/3235 have a separate Control register for each LED, > (3218/3216 pack the enable bits into fewer registers) > - 3236/3235 have a per-channel current divisor setting > - 3236/3235 have a Global Control register that can turn off all LEDs > - 3216 is unique in a number of ways > - OUT9-OUT16 can be configured as GPIOs instead of LED controls > - LEDs can be programmed with an 8-frame animation, with > programmable delay between frames > - LEDs can be modulated by an input audio signal > - Max output current can be adjusted from 1/4 to 2x globally > - Has a Configuration register instead of a Shutdown register > > This driver currently only supports the base PWM control function > of these devices. The following features of these devices are not > implemented, although it should be possible to add them in the future: > - All devices are capable of going into a lower-power "software > shutdown" mode. > - The is31fl3236 and is31fl3235 can reduce the max output current > per-channel with a divisor of 1, 2, 3, or 4. > - The is31fl3216 can use some LED channels as GPIOs instead. > - The is31fl3216 can animate LEDs in hardware. > - The is31fl3216 can modulate LEDs according to an audio input. > - The is31fl3216 can reduce/increase max output current globally. > > Signed-off-by: David Rivshin <drivshin@allworx.com> > --- > > You may see two instances of this warning: > "passing argument 1 of 'of_property_read_string' discards 'const' > qualifier from pointer target type" > That is a result of of_property_read_string() taking a non-const > struct device_node pointer parameter. I have separately submitted a > patch to fix that [1], and a few related functions which had the same > issue. I'm hoping that will get into linux-next before this does, so > that the warnings never show up there. Please adjust the patch so that it compiles without warnings on current linux-next. Your patch for DT API hasn't been reviewed yet AFICS, and I can imagine that there will be some resistance against. > Changes from RFC: > - Removed max-brightness DT property. > - Refer to these devices as "LED controllers" in Kconfig. > - Removed redundant last sentence from Kconfig entry > - Removed unnecessary debug code. > - Do not set led_classdev.brightness to 0 explicitly, as it is > already initialized to 0 by devm_kzalloc(). > - Used of_property_read_string() instead of of_get_property(). > - Fail immediately on DT parsing error in a child node, rather than > continuing on with the non-faulty ones. > - Added additional comments for some things that might be non-obvious. > - Added constants for the location of the SSD bit in the SHUTDOWN > register, and the 3216's CONFIG register. > - Added special sw_shutdown_func for the 3216 device, as that bit > is in a different register, at a different position, and has reverse > polarity compared to all the other devices. > - Refactored is31fl32xx_init_regs() to separate out some logic into > is31fl32xx_reset_regs() and is31fl32xx_software_shutdown(). > > [1] https://lkml.org/lkml/2016/3/2/746 > > drivers/leds/Kconfig | 8 + > drivers/leds/Makefile | 1 + > drivers/leds/leds-is31fl32xx.c | 505 +++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 514 insertions(+) > create mode 100644 drivers/leds/leds-is31fl32xx.c > > diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig > index 1034696..9c63ba4 100644 > --- a/drivers/leds/Kconfig > +++ b/drivers/leds/Kconfig > @@ -580,6 +580,14 @@ config LEDS_SN3218 > This driver can also be built as a module. If so the module > will be called leds-sn3218. > > +config LEDS_IS31FL32XX > + tristate "LED support for ISSI IS31FL32XX I2C LED controller family" > + depends on LEDS_CLASS && I2C && OF > + help > + Say Y here to include support for ISSI IS31FL32XX LED controllers. > + They are I2C devices with multiple constant-current channels, each > + with independent 256-level PWM control. > + > comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)" > > config LEDS_BLINKM > diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile > index 89c9b6f..3fdf313 100644 > --- a/drivers/leds/Makefile > +++ b/drivers/leds/Makefile > @@ -67,6 +67,7 @@ obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o > obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o > obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o > obj-$(CONFIG_LEDS_SN3218) += leds-sn3218.o > +obj-$(CONFIG_LEDS_IS31FL32XX) += leds-is31fl32xx.o > > # LED SPI Drivers > obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o > diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c > new file mode 100644 > index 0000000..49818f0 > --- /dev/null > +++ b/drivers/leds/leds-is31fl32xx.c > @@ -0,0 +1,505 @@ > +/* > + * linux/drivers/leds-is31fl32xx.c > + * > + * Driver for ISSI IS31FL32xx family of I2C LED controllers > + * > + * Copyright 2015 Allworx Corp. > + * > + * > + * 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. > + * > + * Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml > + */ > + > +#include <linux/err.h> > +#include <linux/i2c.h> > +#include <linux/kernel.h> > +#include <linux/leds.h> > +#include <linux/module.h> > +#include <linux/of_platform.h> > + > +/* Used to indicate a device has no such register */ > +#define IS31FL32XX_REG_NONE 0xFF > + > +/* Software Shutdown bit in Shutdown Register */ > +#define IS31FL32XX_SHUTDOWN_SSD_ENABLE 0 > +#define IS31FL32XX_SHUTDOWN_SSD_DISABLE BIT(0) > + > +/* IS31FL3216 has a number of unique registers */ > +#define IS31FL3216_CONFIG_REG 0x00 > +#define IS31FL3216_LIGHTING_EFFECT_REG 0x03 > +#define IS31FL3216_CHANNEL_CONFIG_REG 0x04 > + > +/* Software Shutdown bit in 3216 Config Register */ > +#define IS31FL3216_CONFIG_SSD_ENABLE BIT(7) > +#define IS31FL3216_CONFIG_SSD_DISABLE 0 > + > +struct is31fl32xx_priv; > +struct is31fl32xx_led_data { > + struct led_classdev cdev; > + u8 channel; /* 1-based, max priv->cdef->channels */ > + struct is31fl32xx_priv *priv; > +}; > + > +struct is31fl32xx_priv { > + const struct is31fl32xx_chipdef *cdef; > + struct i2c_client *client; > + unsigned int num_leds; > + struct is31fl32xx_led_data leds[0]; > +}; > + > +/** > + * struct is31fl32xx_chipdef - chip-specific attributes > + * @channels : Number of LED channels > + * @shutdown_reg : address of Shutdown register (optional) > + * @pwm_update_reg : address of PWM Update register > + * @global_control_reg : address of Global Control register (optional) > + * @reset_reg : address of Reset register (optional) > + * @pwm_register_base : address of first PWM register > + * @pwm_registers_reversed: : true if PWM registers count down instead of up > + * @led_control_register_base : address of first LED control register (optional) > + * @enable_bits_per_led_control_register: number of LEDs enable bits in each > + * @reset_func: : pointer to reset function > + * > + * For all optional register addresses, the sentinel value %IS31FL32XX_REG_NONE > + * indicates that this chip has no such register. > + * > + * If non-NULL, @reset_func will be called during probing to set all > + * necessary registers to a known initialization state. This is needed > + * for chips that do not have a @reset_reg. > + * > + * @enable_bits_per_led_control_register must be >=1 if > + * @led_control_register_base != %IS31FL32XX_REG_NONE. > + */ > +struct is31fl32xx_chipdef { > + u8 channels; > + u8 shutdown_reg; > + u8 pwm_update_reg; > + u8 global_control_reg; > + u8 reset_reg; > + u8 pwm_register_base; > + bool pwm_registers_reversed; > + u8 led_control_register_base; > + u8 enable_bits_per_led_control_register; > + int (*reset_func)(struct is31fl32xx_priv *priv); > + int (*sw_shutdown_func)(struct is31fl32xx_priv *priv, bool enable); > +}; > + > +static const struct is31fl32xx_chipdef is31fl3236_cdef = { > + .channels = 36, > + .shutdown_reg = 0x00, > + .pwm_update_reg = 0x25, > + .global_control_reg = 0x4a, > + .reset_reg = 0x4f, > + .pwm_register_base = 0x01, > + .led_control_register_base = 0x26, > + .enable_bits_per_led_control_register = 1, > +}; > + > +static const struct is31fl32xx_chipdef is31fl3235_cdef = { > + .channels = 28, > + .shutdown_reg = 0x00, > + .pwm_update_reg = 0x25, > + .global_control_reg = 0x4a, > + .reset_reg = 0x4f, > + .pwm_register_base = 0x05, > + .led_control_register_base = 0x2a, > + .enable_bits_per_led_control_register = 1, > +}; > + > +static const struct is31fl32xx_chipdef is31fl3218_cdef = { > + .channels = 18, > + .shutdown_reg = 0x00, > + .pwm_update_reg = 0x16, > + .global_control_reg = IS31FL32XX_REG_NONE, > + .reset_reg = 0x17, > + .pwm_register_base = 0x01, > + .led_control_register_base = 0x13, > + .enable_bits_per_led_control_register = 6, > +}; > + > +static int is31fl3216_reset(struct is31fl32xx_priv *priv); > +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, > + bool enable); > +static const struct is31fl32xx_chipdef is31fl3216_cdef = { > + .channels = 16, > + .shutdown_reg = IS31FL32XX_REG_NONE, > + .pwm_update_reg = 0xB0, > + .global_control_reg = IS31FL32XX_REG_NONE, > + .reset_reg = IS31FL32XX_REG_NONE, > + .pwm_register_base = 0x10, > + .pwm_registers_reversed = true, > + .led_control_register_base = 0x01, > + .enable_bits_per_led_control_register = 8, > + .reset_func = is31fl3216_reset, > + .sw_shutdown_func = is31fl3216_software_shutdown, > +}; > + > +static int is31fl32xx_write(struct is31fl32xx_priv *priv, u8 reg, u8 val) > +{ > + int ret; > + > + dev_dbg(&priv->client->dev, "writing register 0x%02X=0x%02X", reg, val); > + > + ret = i2c_smbus_write_byte_data(priv->client, reg, val); > + if (ret) { > + dev_err(&priv->client->dev, > + "register write to 0x%02X failed (error %d)", > + reg, ret); > + } > + return ret; > +} > + > +/* > + * Custom reset function for IS31FL3216 because it does not have a RESET > + * register the way that the other IS31FL32xx chips do. We don't bother > + * writing the GPIO and animation registers, because the registers we > + * do write ensure those will have no effect. > + */ > +static int is31fl3216_reset(struct is31fl32xx_priv *priv) > +{ > + unsigned int i; > + int ret; > + > + ret = is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, > + IS31FL3216_CONFIG_SSD_ENABLE); > + if (ret) > + return ret; > + for (i = 0; i < priv->cdef->channels; i++) { > + ret = is31fl32xx_write(priv, priv->cdef->pwm_register_base+i, > + 0x00); > + if (ret) > + return ret; > + } > + ret = is31fl32xx_write(priv, priv->cdef->pwm_update_reg, 0); > + if (ret) > + return ret; > + ret = is31fl32xx_write(priv, IS31FL3216_LIGHTING_EFFECT_REG, 0x00); > + if (ret) > + return ret; > + ret = is31fl32xx_write(priv, IS31FL3216_CHANNEL_CONFIG_REG, 0x00); > + if (ret) > + return ret; > + > + return 0; > +} > + > +/* > + * Custom Software-Shutdown function for IS31FL3216 because it does not have > + * a SHUTDOWN register the way that the other IS31FL32xx chips do. > + * We don't bother doing a read/modify/write on the CONFIG register because > + * we only ever use a value of '0' for the other fields in that register. > + */ > +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, > + bool enable) > +{ > + u8 value = enable ? IS31FL3216_CONFIG_SSD_ENABLE : > + IS31FL3216_CONFIG_SSD_DISABLE; > + > + return is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, value); > +} > + > +/* > + * NOTE: A mutex is not needed in this function because: > + * - All referenced data is read-only after probe() > + * - The I2C core has a mutex on to protect the bus > + * - There are no read/modify/write operations > + * - Intervening operations between the write of the PWM register > + * and the Update register are harmless. > + * > + * Example: > + * PWM_REG_1 write 16 > + * UPDATE_REG write 0 > + * PWM_REG_2 write 128 > + * UPDATE_REG write 0 > + * vs: > + * PWM_REG_1 write 16 > + * PWM_REG_2 write 128 > + * UPDATE_REG write 0 > + * UPDATE_REG write 0 > + * are equivalent. Poking the Update register merely applies all PWM > + * register writes up to that point. > + */ > +static int is31fl32xx_brightness_set(struct led_classdev *led_cdev, > + enum led_brightness brightness) > +{ > + const struct is31fl32xx_led_data *led_data = > + container_of(led_cdev, struct is31fl32xx_led_data, cdev); > + const struct is31fl32xx_chipdef *cdef = led_data->priv->cdef; > + u8 pwm_register_offset; > + int ret; > + > + dev_dbg(led_cdev->dev, "%s: %d\n", __func__, brightness); > + > + /* NOTE: led_data->channel is 1-based */ > + if (cdef->pwm_registers_reversed) > + pwm_register_offset = cdef->channels - led_data->channel; > + else > + pwm_register_offset = led_data->channel - 1; > + > + ret = is31fl32xx_write(led_data->priv, > + cdef->pwm_register_base + pwm_register_offset, > + brightness); > + if (ret) > + return ret; > + > + return is31fl32xx_write(led_data->priv, cdef->pwm_update_reg, 0); > +} > + > +static int is31fl32xx_reset_regs(struct is31fl32xx_priv *priv) > +{ > + const struct is31fl32xx_chipdef *cdef = priv->cdef; > + int ret; > + > + if (cdef->reset_reg != IS31FL32XX_REG_NONE) { > + ret = is31fl32xx_write(priv, cdef->reset_reg, 0); > + if (ret) > + return ret; > + } > + > + if (cdef->reset_func) > + return cdef->reset_func(priv); > + > + return 0; > +} > + > +static int is31fl32xx_software_shutdown(struct is31fl32xx_priv *priv, > + bool enable) > +{ > + const struct is31fl32xx_chipdef *cdef = priv->cdef; > + int ret; > + > + if (cdef->shutdown_reg != IS31FL32XX_REG_NONE) { > + u8 value = enable ? IS31FL32XX_SHUTDOWN_SSD_ENABLE : > + IS31FL32XX_SHUTDOWN_SSD_DISABLE; > + ret = is31fl32xx_write(priv, cdef->shutdown_reg, value); > + if (ret) > + return ret; > + } > + > + if (cdef->sw_shutdown_func) > + return cdef->sw_shutdown_func(priv, enable); You seem to call sw_shutdown_func only here, so why should we have enable parameter in this op? > + return 0; > +} > + > +static int is31fl32xx_init_regs(struct is31fl32xx_priv *priv) > +{ > + const struct is31fl32xx_chipdef *cdef = priv->cdef; > + int ret; > + > + ret = is31fl32xx_reset_regs(priv); > + if (ret) > + return ret; > + > + /* > + * Set enable bit for all channels. > + * We will control state with PWM registers alone. > + */ > + if (cdef->led_control_register_base != IS31FL32XX_REG_NONE) { > + u8 value = > + GENMASK(cdef->enable_bits_per_led_control_register-1, 0); > + u8 num_regs = cdef->channels / > + cdef->enable_bits_per_led_control_register; > + int i; > + > + for (i = 0; i < num_regs; i++) { > + ret = is31fl32xx_write(priv, > + cdef->led_control_register_base+i, > + value); > + if (ret) > + return ret; > + } > + } > + > + ret = is31fl32xx_software_shutdown(priv, false); > + if (ret) > + return ret; > + > + if (cdef->global_control_reg != IS31FL32XX_REG_NONE) { > + ret = is31fl32xx_write(priv, cdef->global_control_reg, 0x00); > + if (ret) > + return ret; > + } > + > + return 0; > +} > + > +static inline size_t sizeof_is31fl32xx_priv(int num_leds) > +{ > + return sizeof(struct is31fl32xx_priv) + > + (sizeof(struct is31fl32xx_led_data) * num_leds); > +} > + > +static int is31fl32xx_parse_child_dt(const struct device *dev, > + const struct device_node *child, > + struct is31fl32xx_led_data *led_data) > +{ > + struct led_classdev *cdev = &led_data->cdev; > + int ret = 0; > + u32 reg; > + > + if (of_property_read_string(child, "label", &cdev->name)) > + cdev->name = child->name; > + > + ret = of_property_read_u32(child, "reg", ®); > + if (ret || reg < 1 || reg > led_data->priv->cdef->channels) { > + dev_err(dev, > + "Child node %s does not have a valid reg property\n", > + child->full_name); > + return -EINVAL; > + } > + led_data->channel = reg; > + > + of_property_read_string(child, "linux,default-trigger", > + &cdev->default_trigger); > + > + cdev->brightness_set_blocking = is31fl32xx_brightness_set; > + > + return 0; > +} > + > +static struct is31fl32xx_led_data *is31fl32xx_find_led_data( > + struct is31fl32xx_priv *priv, > + u8 channel) > +{ > + size_t i; > + > + for (i = 0; i < priv->num_leds; i++) { > + if (priv->leds[i].channel == channel) > + return &priv->leds[i]; > + } > + > + return NULL; > +} > + > +static int is31fl32xx_parse_dt(struct device *dev, > + struct is31fl32xx_priv *priv) > +{ > + struct device_node *child; > + int ret = 0; > + > + for_each_child_of_node(dev->of_node, child) { > + struct is31fl32xx_led_data *led_data = > + &priv->leds[priv->num_leds]; > + const struct is31fl32xx_led_data *other_led_data; > + > + led_data->priv = priv; > + > + ret = is31fl32xx_parse_child_dt(dev, child, led_data); > + if (ret) > + goto err; > + > + /* Detect if channel is already in use by another child */ > + other_led_data = is31fl32xx_find_led_data(priv, > + led_data->channel); > + if (other_led_data) { > + dev_err(dev, > + "%s and %s both attempting to use channel %d\n", > + led_data->cdev.name, > + other_led_data->cdev.name, > + led_data->channel); > + goto err; > + } > + > + ret = devm_led_classdev_register(dev, &led_data->cdev); > + if (ret) { > + dev_err(dev, "failed to register PWM led for %s: %d\n", > + led_data->cdev.name, ret); > + goto err; > + } > + > + priv->num_leds++; > + } > + > + return 0; > + > +err: > + of_node_put(child); > + return ret; > +} > + > +static const struct of_device_id of_is31fl31xx_match[] = { > + { .compatible = "issi,is31fl3236", .data = &is31fl3236_cdef, }, > + { .compatible = "issi,is31fl3235", .data = &is31fl3235_cdef, }, > + { .compatible = "issi,is31fl3218", .data = &is31fl3218_cdef, }, > + { .compatible = "issi,is31fl3216", .data = &is31fl3216_cdef, }, > + {}, > +}; > + > +MODULE_DEVICE_TABLE(of, of_is31fl31xx_match); > + > +static int is31fl32xx_probe(struct i2c_client *client, > + const struct i2c_device_id *id) > +{ > + const struct is31fl32xx_chipdef *cdef; > + const struct of_device_id *of_dev_id; > + struct device *dev = &client->dev; > + struct is31fl32xx_priv *priv; > + int count; > + int ret = 0; > + > + of_dev_id = of_match_device(of_is31fl31xx_match, dev); > + if (!of_dev_id) > + return -EINVAL; > + > + cdef = of_dev_id->data; > + > + count = of_get_child_count(dev->of_node); > + if (!count) > + return -EINVAL; > + > + priv = devm_kzalloc(dev, sizeof_is31fl32xx_priv(count), > + GFP_KERNEL); > + if (!priv) > + return -ENOMEM; > + > + priv->client = client; > + priv->cdef = cdef; > + i2c_set_clientdata(client, priv); > + > + ret = is31fl32xx_init_regs(priv); > + if (ret) > + return ret; > + > + ret = is31fl32xx_parse_dt(dev, priv); > + if (ret) > + return ret; > + > + return 0; > +} > + > +static int is31fl32xx_remove(struct i2c_client *client) > +{ > + struct is31fl32xx_priv *priv = i2c_get_clientdata(client); > + > + return is31fl32xx_reset_regs(priv); > +} > + > +/* > + * i2c-core requires that id_table be non-NULL, even though > + * it is not used for DeviceTree based instantiation. > + */ > +static const struct i2c_device_id is31fl31xx_id[] = { > + {}, > +}; > + > +MODULE_DEVICE_TABLE(i2c, is31fl31xx_id); > + > +static struct i2c_driver is31fl32xx_driver = { > + .driver = { > + .name = "is31fl32xx", > + .of_match_table = of_is31fl31xx_match, > + }, > + .probe = is31fl32xx_probe, > + .remove = is31fl32xx_remove, > + .id_table = is31fl31xx_id, > +}; > + > +module_i2c_driver(is31fl32xx_driver); > + > +MODULE_AUTHOR("David Rivshin <drivshin@allworx.com>"); > +MODULE_DESCRIPTION("ISSI IS31FL32xx LED driver"); > +MODULE_LICENSE("GPL v2"); > -- Best regards, Jacek Anaszewski ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 3/4] leds: Add driver for the ISSI IS31FL32xx family of LED controllers 2016-03-03 14:51 ` Jacek Anaszewski @ 2016-03-04 0:45 ` David Rivshin (Allworx) [not found] ` <20160303194531.316d7918.drivshin.allworx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 0 siblings, 1 reply; 28+ messages in thread From: David Rivshin (Allworx) @ 2016-03-04 0:45 UTC (permalink / raw) To: Jacek Anaszewski Cc: linux-leds, devicetree, Richard Purdie, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Stefan Wahren, linux-kernel On Thu, 03 Mar 2016 15:51:32 +0100 Jacek Anaszewski <j.anaszewski@samsung.com> wrote: > Hi David, > > Thanks for the update. Two remarks in the code. > > On 03/03/2016 04:01 AM, David Rivshin (Allworx) wrote: > > From: David Rivshin <drivshin@allworx.com> > > > > The IS31FL32xx family of LED controllers are I2C devices with multiple > > constant-current channels, each with independent 256-level PWM control. > > > > Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml > > > > This has been tested on the IS31FL3236 and IS31FL3216, on an ARM > > (TI am335x) platform. > > > > The programming paradigm of these devices is similar in the following > > ways: > > - All registers are 8 bit > > - All LED control registers are write-only > > - Each LED channel has a PWM register (0-255) > > - PWM register writes are shadowed until an Update register is poked > > - All have a concept of Software Shutdown, which disables output > > > > However, there are some differences in devices: > > - 3236/3235 have a separate Control register for each LED, > > (3218/3216 pack the enable bits into fewer registers) > > - 3236/3235 have a per-channel current divisor setting > > - 3236/3235 have a Global Control register that can turn off all LEDs > > - 3216 is unique in a number of ways > > - OUT9-OUT16 can be configured as GPIOs instead of LED controls > > - LEDs can be programmed with an 8-frame animation, with > > programmable delay between frames > > - LEDs can be modulated by an input audio signal > > - Max output current can be adjusted from 1/4 to 2x globally > > - Has a Configuration register instead of a Shutdown register > > > > This driver currently only supports the base PWM control function > > of these devices. The following features of these devices are not > > implemented, although it should be possible to add them in the future: > > - All devices are capable of going into a lower-power "software > > shutdown" mode. > > - The is31fl3236 and is31fl3235 can reduce the max output current > > per-channel with a divisor of 1, 2, 3, or 4. > > - The is31fl3216 can use some LED channels as GPIOs instead. > > - The is31fl3216 can animate LEDs in hardware. > > - The is31fl3216 can modulate LEDs according to an audio input. > > - The is31fl3216 can reduce/increase max output current globally. > > > > Signed-off-by: David Rivshin <drivshin@allworx.com> > > --- > > > > You may see two instances of this warning: > > "passing argument 1 of 'of_property_read_string' discards 'const' > > qualifier from pointer target type" > > That is a result of of_property_read_string() taking a non-const > > struct device_node pointer parameter. I have separately submitted a > > patch to fix that [1], and a few related functions which had the same > > issue. I'm hoping that will get into linux-next before this does, so > > that the warnings never show up there. > > Please adjust the patch so that it compiles without warnings on > current linux-next. Your patch for DT API hasn't been reviewed yet > AFICS, and I can imagine that there will be some resistance against. Since the DT API patch was just accepted by Rob [1], would it be OK to wait for the results of Stefan's testing (and any other reviews) before making a decision on this? From Stefan's note, it won't be until this weekend that he will have a chance to test, and I'm guessing the DT API patch will make its way through Rob's tree to linux-next by then. FYI, the warning workaround would be to make the second parameter to is31fl32xx_parse_child_dt() non-const. [1] https://lkml.org/lkml/2016/3/3/924 > > Changes from RFC: > > - Removed max-brightness DT property. > > - Refer to these devices as "LED controllers" in Kconfig. > > - Removed redundant last sentence from Kconfig entry > > - Removed unnecessary debug code. > > - Do not set led_classdev.brightness to 0 explicitly, as it is > > already initialized to 0 by devm_kzalloc(). > > - Used of_property_read_string() instead of of_get_property(). > > - Fail immediately on DT parsing error in a child node, rather than > > continuing on with the non-faulty ones. > > - Added additional comments for some things that might be non-obvious. > > - Added constants for the location of the SSD bit in the SHUTDOWN > > register, and the 3216's CONFIG register. > > - Added special sw_shutdown_func for the 3216 device, as that bit > > is in a different register, at a different position, and has reverse > > polarity compared to all the other devices. > > - Refactored is31fl32xx_init_regs() to separate out some logic into > > is31fl32xx_reset_regs() and is31fl32xx_software_shutdown(). > > > > [1] https://lkml.org/lkml/2016/3/2/746 > > > > drivers/leds/Kconfig | 8 + > > drivers/leds/Makefile | 1 + > > drivers/leds/leds-is31fl32xx.c | 505 +++++++++++++++++++++++++++++++++++++++++ > > 3 files changed, 514 insertions(+) > > create mode 100644 drivers/leds/leds-is31fl32xx.c > > > > diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig > > index 1034696..9c63ba4 100644 > > --- a/drivers/leds/Kconfig > > +++ b/drivers/leds/Kconfig > > @@ -580,6 +580,14 @@ config LEDS_SN3218 > > This driver can also be built as a module. If so the module > > will be called leds-sn3218. > > > > +config LEDS_IS31FL32XX > > + tristate "LED support for ISSI IS31FL32XX I2C LED controller family" > > + depends on LEDS_CLASS && I2C && OF > > + help > > + Say Y here to include support for ISSI IS31FL32XX LED controllers. > > + They are I2C devices with multiple constant-current channels, each > > + with independent 256-level PWM control. > > + > > comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)" > > > > config LEDS_BLINKM > > diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile > > index 89c9b6f..3fdf313 100644 > > --- a/drivers/leds/Makefile > > +++ b/drivers/leds/Makefile > > @@ -67,6 +67,7 @@ obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o > > obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o > > obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o > > obj-$(CONFIG_LEDS_SN3218) += leds-sn3218.o > > +obj-$(CONFIG_LEDS_IS31FL32XX) += leds-is31fl32xx.o > > > > # LED SPI Drivers > > obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o > > diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c > > new file mode 100644 > > index 0000000..49818f0 > > --- /dev/null > > +++ b/drivers/leds/leds-is31fl32xx.c > > @@ -0,0 +1,505 @@ > > +/* > > + * linux/drivers/leds-is31fl32xx.c > > + * > > + * Driver for ISSI IS31FL32xx family of I2C LED controllers > > + * > > + * Copyright 2015 Allworx Corp. > > + * > > + * > > + * 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. > > + * > > + * Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml > > + */ > > + > > +#include <linux/err.h> > > +#include <linux/i2c.h> > > +#include <linux/kernel.h> > > +#include <linux/leds.h> > > +#include <linux/module.h> > > +#include <linux/of_platform.h> > > + > > +/* Used to indicate a device has no such register */ > > +#define IS31FL32XX_REG_NONE 0xFF > > + > > +/* Software Shutdown bit in Shutdown Register */ > > +#define IS31FL32XX_SHUTDOWN_SSD_ENABLE 0 > > +#define IS31FL32XX_SHUTDOWN_SSD_DISABLE BIT(0) > > + > > +/* IS31FL3216 has a number of unique registers */ > > +#define IS31FL3216_CONFIG_REG 0x00 > > +#define IS31FL3216_LIGHTING_EFFECT_REG 0x03 > > +#define IS31FL3216_CHANNEL_CONFIG_REG 0x04 > > + > > +/* Software Shutdown bit in 3216 Config Register */ > > +#define IS31FL3216_CONFIG_SSD_ENABLE BIT(7) > > +#define IS31FL3216_CONFIG_SSD_DISABLE 0 > > + > > +struct is31fl32xx_priv; > > +struct is31fl32xx_led_data { > > + struct led_classdev cdev; > > + u8 channel; /* 1-based, max priv->cdef->channels */ > > + struct is31fl32xx_priv *priv; > > +}; > > + > > +struct is31fl32xx_priv { > > + const struct is31fl32xx_chipdef *cdef; > > + struct i2c_client *client; > > + unsigned int num_leds; > > + struct is31fl32xx_led_data leds[0]; > > +}; > > + > > +/** > > + * struct is31fl32xx_chipdef - chip-specific attributes > > + * @channels : Number of LED channels > > + * @shutdown_reg : address of Shutdown register (optional) > > + * @pwm_update_reg : address of PWM Update register > > + * @global_control_reg : address of Global Control register (optional) > > + * @reset_reg : address of Reset register (optional) > > + * @pwm_register_base : address of first PWM register > > + * @pwm_registers_reversed: : true if PWM registers count down instead of up > > + * @led_control_register_base : address of first LED control register (optional) > > + * @enable_bits_per_led_control_register: number of LEDs enable bits in each > > + * @reset_func: : pointer to reset function > > + * > > + * For all optional register addresses, the sentinel value %IS31FL32XX_REG_NONE > > + * indicates that this chip has no such register. > > + * > > + * If non-NULL, @reset_func will be called during probing to set all > > + * necessary registers to a known initialization state. This is needed > > + * for chips that do not have a @reset_reg. > > + * > > + * @enable_bits_per_led_control_register must be >=1 if > > + * @led_control_register_base != %IS31FL32XX_REG_NONE. > > + */ > > +struct is31fl32xx_chipdef { > > + u8 channels; > > + u8 shutdown_reg; > > + u8 pwm_update_reg; > > + u8 global_control_reg; > > + u8 reset_reg; > > + u8 pwm_register_base; > > + bool pwm_registers_reversed; > > + u8 led_control_register_base; > > + u8 enable_bits_per_led_control_register; > > + int (*reset_func)(struct is31fl32xx_priv *priv); > > + int (*sw_shutdown_func)(struct is31fl32xx_priv *priv, bool enable); > > +}; > > + > > +static const struct is31fl32xx_chipdef is31fl3236_cdef = { > > + .channels = 36, > > + .shutdown_reg = 0x00, > > + .pwm_update_reg = 0x25, > > + .global_control_reg = 0x4a, > > + .reset_reg = 0x4f, > > + .pwm_register_base = 0x01, > > + .led_control_register_base = 0x26, > > + .enable_bits_per_led_control_register = 1, > > +}; > > + > > +static const struct is31fl32xx_chipdef is31fl3235_cdef = { > > + .channels = 28, > > + .shutdown_reg = 0x00, > > + .pwm_update_reg = 0x25, > > + .global_control_reg = 0x4a, > > + .reset_reg = 0x4f, > > + .pwm_register_base = 0x05, > > + .led_control_register_base = 0x2a, > > + .enable_bits_per_led_control_register = 1, > > +}; > > + > > +static const struct is31fl32xx_chipdef is31fl3218_cdef = { > > + .channels = 18, > > + .shutdown_reg = 0x00, > > + .pwm_update_reg = 0x16, > > + .global_control_reg = IS31FL32XX_REG_NONE, > > + .reset_reg = 0x17, > > + .pwm_register_base = 0x01, > > + .led_control_register_base = 0x13, > > + .enable_bits_per_led_control_register = 6, > > +}; > > + > > +static int is31fl3216_reset(struct is31fl32xx_priv *priv); > > +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, > > + bool enable); > > +static const struct is31fl32xx_chipdef is31fl3216_cdef = { > > + .channels = 16, > > + .shutdown_reg = IS31FL32XX_REG_NONE, > > + .pwm_update_reg = 0xB0, > > + .global_control_reg = IS31FL32XX_REG_NONE, > > + .reset_reg = IS31FL32XX_REG_NONE, > > + .pwm_register_base = 0x10, > > + .pwm_registers_reversed = true, > > + .led_control_register_base = 0x01, > > + .enable_bits_per_led_control_register = 8, > > + .reset_func = is31fl3216_reset, > > + .sw_shutdown_func = is31fl3216_software_shutdown, > > +}; > > + > > +static int is31fl32xx_write(struct is31fl32xx_priv *priv, u8 reg, u8 val) > > +{ > > + int ret; > > + > > + dev_dbg(&priv->client->dev, "writing register 0x%02X=0x%02X", reg, val); > > + > > + ret = i2c_smbus_write_byte_data(priv->client, reg, val); > > + if (ret) { > > + dev_err(&priv->client->dev, > > + "register write to 0x%02X failed (error %d)", > > + reg, ret); > > + } > > + return ret; > > +} > > + > > +/* > > + * Custom reset function for IS31FL3216 because it does not have a RESET > > + * register the way that the other IS31FL32xx chips do. We don't bother > > + * writing the GPIO and animation registers, because the registers we > > + * do write ensure those will have no effect. > > + */ > > +static int is31fl3216_reset(struct is31fl32xx_priv *priv) > > +{ > > + unsigned int i; > > + int ret; > > + > > + ret = is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, > > + IS31FL3216_CONFIG_SSD_ENABLE); > > + if (ret) > > + return ret; > > + for (i = 0; i < priv->cdef->channels; i++) { > > + ret = is31fl32xx_write(priv, priv->cdef->pwm_register_base+i, > > + 0x00); > > + if (ret) > > + return ret; > > + } > > + ret = is31fl32xx_write(priv, priv->cdef->pwm_update_reg, 0); > > + if (ret) > > + return ret; > > + ret = is31fl32xx_write(priv, IS31FL3216_LIGHTING_EFFECT_REG, 0x00); > > + if (ret) > > + return ret; > > + ret = is31fl32xx_write(priv, IS31FL3216_CHANNEL_CONFIG_REG, 0x00); > > + if (ret) > > + return ret; > > + > > + return 0; > > +} > > + > > +/* > > + * Custom Software-Shutdown function for IS31FL3216 because it does not have > > + * a SHUTDOWN register the way that the other IS31FL32xx chips do. > > + * We don't bother doing a read/modify/write on the CONFIG register because > > + * we only ever use a value of '0' for the other fields in that register. > > + */ > > +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, > > + bool enable) > > +{ > > + u8 value = enable ? IS31FL3216_CONFIG_SSD_ENABLE : > > + IS31FL3216_CONFIG_SSD_DISABLE; > > + > > + return is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, value); > > +} > > + > > +/* > > + * NOTE: A mutex is not needed in this function because: > > + * - All referenced data is read-only after probe() > > + * - The I2C core has a mutex on to protect the bus > > + * - There are no read/modify/write operations > > + * - Intervening operations between the write of the PWM register > > + * and the Update register are harmless. > > + * > > + * Example: > > + * PWM_REG_1 write 16 > > + * UPDATE_REG write 0 > > + * PWM_REG_2 write 128 > > + * UPDATE_REG write 0 > > + * vs: > > + * PWM_REG_1 write 16 > > + * PWM_REG_2 write 128 > > + * UPDATE_REG write 0 > > + * UPDATE_REG write 0 > > + * are equivalent. Poking the Update register merely applies all PWM > > + * register writes up to that point. > > + */ > > +static int is31fl32xx_brightness_set(struct led_classdev *led_cdev, > > + enum led_brightness brightness) > > +{ > > + const struct is31fl32xx_led_data *led_data = > > + container_of(led_cdev, struct is31fl32xx_led_data, cdev); > > + const struct is31fl32xx_chipdef *cdef = led_data->priv->cdef; > > + u8 pwm_register_offset; > > + int ret; > > + > > + dev_dbg(led_cdev->dev, "%s: %d\n", __func__, brightness); > > + > > + /* NOTE: led_data->channel is 1-based */ > > + if (cdef->pwm_registers_reversed) > > + pwm_register_offset = cdef->channels - led_data->channel; > > + else > > + pwm_register_offset = led_data->channel - 1; > > + > > + ret = is31fl32xx_write(led_data->priv, > > + cdef->pwm_register_base + pwm_register_offset, > > + brightness); > > + if (ret) > > + return ret; > > + > > + return is31fl32xx_write(led_data->priv, cdef->pwm_update_reg, 0); > > +} > > + > > +static int is31fl32xx_reset_regs(struct is31fl32xx_priv *priv) > > +{ > > + const struct is31fl32xx_chipdef *cdef = priv->cdef; > > + int ret; > > + > > + if (cdef->reset_reg != IS31FL32XX_REG_NONE) { > > + ret = is31fl32xx_write(priv, cdef->reset_reg, 0); > > + if (ret) > > + return ret; > > + } > > + > > + if (cdef->reset_func) > > + return cdef->reset_func(priv); > > + > > + return 0; > > +} > > + > > +static int is31fl32xx_software_shutdown(struct is31fl32xx_priv *priv, > > + bool enable) > > +{ > > + const struct is31fl32xx_chipdef *cdef = priv->cdef; > > + int ret; > > + > > + if (cdef->shutdown_reg != IS31FL32XX_REG_NONE) { > > + u8 value = enable ? IS31FL32XX_SHUTDOWN_SSD_ENABLE : > > + IS31FL32XX_SHUTDOWN_SSD_DISABLE; > > + ret = is31fl32xx_write(priv, cdef->shutdown_reg, value); > > + if (ret) > > + return ret; > > + } > > + > > + if (cdef->sw_shutdown_func) > > + return cdef->sw_shutdown_func(priv, enable); > > You seem to call sw_shutdown_func only here, so why should we have > enable parameter in this op? I'm not sure if I understand the question, but I will try to answer. 'enable' is passed through is31fl32xx_software_shutdown to cdef->sw_shutdown_func, so it can be either true or false at that point. The purpose of sw_shutdown_func is to add any special behavior when enabling/disabling software-shutdown mode, which is needed for the 3216 because its SSD bit is in a different position and with opposite polarity. Is it that 'enable' in that line of code makes it look like it's being called with an hardcoded value rather than a variable? If so, perhaps a different parameter name would make it more obvious? Or a kerneldoc comment for the function to describe the parameter? Or have I totally missed the point of the question? > > + return 0; > > +} > > + > > +static int is31fl32xx_init_regs(struct is31fl32xx_priv *priv) > > +{ > > + const struct is31fl32xx_chipdef *cdef = priv->cdef; > > + int ret; > > + > > + ret = is31fl32xx_reset_regs(priv); > > + if (ret) > > + return ret; > > + > > + /* > > + * Set enable bit for all channels. > > + * We will control state with PWM registers alone. > > + */ > > + if (cdef->led_control_register_base != IS31FL32XX_REG_NONE) { > > + u8 value = > > + GENMASK(cdef->enable_bits_per_led_control_register-1, 0); > > + u8 num_regs = cdef->channels / > > + cdef->enable_bits_per_led_control_register; > > + int i; > > + > > + for (i = 0; i < num_regs; i++) { > > + ret = is31fl32xx_write(priv, > > + cdef->led_control_register_base+i, > > + value); > > + if (ret) > > + return ret; > > + } > > + } > > + > > + ret = is31fl32xx_software_shutdown(priv, false); > > + if (ret) > > + return ret; > > + > > + if (cdef->global_control_reg != IS31FL32XX_REG_NONE) { > > + ret = is31fl32xx_write(priv, cdef->global_control_reg, 0x00); > > + if (ret) > > + return ret; > > + } > > + > > + return 0; > > +} > > + > > +static inline size_t sizeof_is31fl32xx_priv(int num_leds) > > +{ > > + return sizeof(struct is31fl32xx_priv) + > > + (sizeof(struct is31fl32xx_led_data) * num_leds); > > +} > > + > > +static int is31fl32xx_parse_child_dt(const struct device *dev, > > + const struct device_node *child, > > + struct is31fl32xx_led_data *led_data) > > +{ > > + struct led_classdev *cdev = &led_data->cdev; > > + int ret = 0; > > + u32 reg; > > + > > + if (of_property_read_string(child, "label", &cdev->name)) > > + cdev->name = child->name; > > + > > + ret = of_property_read_u32(child, "reg", ®); > > + if (ret || reg < 1 || reg > led_data->priv->cdef->channels) { > > + dev_err(dev, > > + "Child node %s does not have a valid reg property\n", > > + child->full_name); > > + return -EINVAL; > > + } > > + led_data->channel = reg; > > + > > + of_property_read_string(child, "linux,default-trigger", > > + &cdev->default_trigger); > > + > > + cdev->brightness_set_blocking = is31fl32xx_brightness_set; > > + > > + return 0; > > +} > > + > > +static struct is31fl32xx_led_data *is31fl32xx_find_led_data( > > + struct is31fl32xx_priv *priv, > > + u8 channel) > > +{ > > + size_t i; > > + > > + for (i = 0; i < priv->num_leds; i++) { > > + if (priv->leds[i].channel == channel) > > + return &priv->leds[i]; > > + } > > + > > + return NULL; > > +} > > + > > +static int is31fl32xx_parse_dt(struct device *dev, > > + struct is31fl32xx_priv *priv) > > +{ > > + struct device_node *child; > > + int ret = 0; > > + > > + for_each_child_of_node(dev->of_node, child) { > > + struct is31fl32xx_led_data *led_data = > > + &priv->leds[priv->num_leds]; > > + const struct is31fl32xx_led_data *other_led_data; > > + > > + led_data->priv = priv; > > + > > + ret = is31fl32xx_parse_child_dt(dev, child, led_data); > > + if (ret) > > + goto err; > > + > > + /* Detect if channel is already in use by another child */ > > + other_led_data = is31fl32xx_find_led_data(priv, > > + led_data->channel); > > + if (other_led_data) { > > + dev_err(dev, > > + "%s and %s both attempting to use channel %d\n", > > + led_data->cdev.name, > > + other_led_data->cdev.name, > > + led_data->channel); > > + goto err; > > + } > > + > > + ret = devm_led_classdev_register(dev, &led_data->cdev); > > + if (ret) { > > + dev_err(dev, "failed to register PWM led for %s: %d\n", > > + led_data->cdev.name, ret); > > + goto err; > > + } > > + > > + priv->num_leds++; > > + } > > + > > + return 0; > > + > > +err: > > + of_node_put(child); > > + return ret; > > +} > > + > > +static const struct of_device_id of_is31fl31xx_match[] = { > > + { .compatible = "issi,is31fl3236", .data = &is31fl3236_cdef, }, > > + { .compatible = "issi,is31fl3235", .data = &is31fl3235_cdef, }, > > + { .compatible = "issi,is31fl3218", .data = &is31fl3218_cdef, }, > > + { .compatible = "issi,is31fl3216", .data = &is31fl3216_cdef, }, > > + {}, > > +}; > > + > > +MODULE_DEVICE_TABLE(of, of_is31fl31xx_match); > > + > > +static int is31fl32xx_probe(struct i2c_client *client, > > + const struct i2c_device_id *id) > > +{ > > + const struct is31fl32xx_chipdef *cdef; > > + const struct of_device_id *of_dev_id; > > + struct device *dev = &client->dev; > > + struct is31fl32xx_priv *priv; > > + int count; > > + int ret = 0; > > + > > + of_dev_id = of_match_device(of_is31fl31xx_match, dev); > > + if (!of_dev_id) > > + return -EINVAL; > > + > > + cdef = of_dev_id->data; > > + > > + count = of_get_child_count(dev->of_node); > > + if (!count) > > + return -EINVAL; > > + > > + priv = devm_kzalloc(dev, sizeof_is31fl32xx_priv(count), > > + GFP_KERNEL); > > + if (!priv) > > + return -ENOMEM; > > + > > + priv->client = client; > > + priv->cdef = cdef; > > + i2c_set_clientdata(client, priv); > > + > > + ret = is31fl32xx_init_regs(priv); > > + if (ret) > > + return ret; > > + > > + ret = is31fl32xx_parse_dt(dev, priv); > > + if (ret) > > + return ret; > > + > > + return 0; > > +} > > + > > +static int is31fl32xx_remove(struct i2c_client *client) > > +{ > > + struct is31fl32xx_priv *priv = i2c_get_clientdata(client); > > + > > + return is31fl32xx_reset_regs(priv); > > +} > > + > > +/* > > + * i2c-core requires that id_table be non-NULL, even though > > + * it is not used for DeviceTree based instantiation. > > + */ > > +static const struct i2c_device_id is31fl31xx_id[] = { > > + {}, > > +}; > > + > > +MODULE_DEVICE_TABLE(i2c, is31fl31xx_id); > > + > > +static struct i2c_driver is31fl32xx_driver = { > > + .driver = { > > + .name = "is31fl32xx", > > + .of_match_table = of_is31fl31xx_match, > > + }, > > + .probe = is31fl32xx_probe, > > + .remove = is31fl32xx_remove, > > + .id_table = is31fl31xx_id, > > +}; > > + > > +module_i2c_driver(is31fl32xx_driver); > > + > > +MODULE_AUTHOR("David Rivshin <drivshin@allworx.com>"); > > +MODULE_DESCRIPTION("ISSI IS31FL32xx LED driver"); > > +MODULE_LICENSE("GPL v2"); > > ^ permalink raw reply [flat|nested] 28+ messages in thread
[parent not found: <20160303194531.316d7918.drivshin.allworx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>]
* Re: [PATCH 3/4] leds: Add driver for the ISSI IS31FL32xx family of LED controllers [not found] ` <20160303194531.316d7918.drivshin.allworx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> @ 2016-03-04 7:54 ` Jacek Anaszewski [not found] ` <56D93F1A.6030305-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> 0 siblings, 1 reply; 28+ messages in thread From: Jacek Anaszewski @ 2016-03-04 7:54 UTC (permalink / raw) To: David Rivshin (Allworx) Cc: linux-leds-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA, Richard Purdie, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Stefan Wahren, linux-kernel-u79uwXL29TY76Z2rM5mHXA On 03/04/2016 01:45 AM, David Rivshin (Allworx) wrote: > On Thu, 03 Mar 2016 15:51:32 +0100 > Jacek Anaszewski <j.anaszewski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> wrote: > >> Hi David, >> >> Thanks for the update. Two remarks in the code. >> >> On 03/03/2016 04:01 AM, David Rivshin (Allworx) wrote: >>> From: David Rivshin <drivshin-5fOYsn7Fw8lBDgjK7y7TUQ@public.gmane.org> >>> >>> The IS31FL32xx family of LED controllers are I2C devices with multiple >>> constant-current channels, each with independent 256-level PWM control. >>> >>> Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml >>> >>> This has been tested on the IS31FL3236 and IS31FL3216, on an ARM >>> (TI am335x) platform. >>> >>> The programming paradigm of these devices is similar in the following >>> ways: >>> - All registers are 8 bit >>> - All LED control registers are write-only >>> - Each LED channel has a PWM register (0-255) >>> - PWM register writes are shadowed until an Update register is poked >>> - All have a concept of Software Shutdown, which disables output >>> >>> However, there are some differences in devices: >>> - 3236/3235 have a separate Control register for each LED, >>> (3218/3216 pack the enable bits into fewer registers) >>> - 3236/3235 have a per-channel current divisor setting >>> - 3236/3235 have a Global Control register that can turn off all LEDs >>> - 3216 is unique in a number of ways >>> - OUT9-OUT16 can be configured as GPIOs instead of LED controls >>> - LEDs can be programmed with an 8-frame animation, with >>> programmable delay between frames >>> - LEDs can be modulated by an input audio signal >>> - Max output current can be adjusted from 1/4 to 2x globally >>> - Has a Configuration register instead of a Shutdown register >>> >>> This driver currently only supports the base PWM control function >>> of these devices. The following features of these devices are not >>> implemented, although it should be possible to add them in the future: >>> - All devices are capable of going into a lower-power "software >>> shutdown" mode. >>> - The is31fl3236 and is31fl3235 can reduce the max output current >>> per-channel with a divisor of 1, 2, 3, or 4. >>> - The is31fl3216 can use some LED channels as GPIOs instead. >>> - The is31fl3216 can animate LEDs in hardware. >>> - The is31fl3216 can modulate LEDs according to an audio input. >>> - The is31fl3216 can reduce/increase max output current globally. >>> >>> Signed-off-by: David Rivshin <drivshin-5fOYsn7Fw8lBDgjK7y7TUQ@public.gmane.org> >>> --- >>> >>> You may see two instances of this warning: >>> "passing argument 1 of 'of_property_read_string' discards 'const' >>> qualifier from pointer target type" >>> That is a result of of_property_read_string() taking a non-const >>> struct device_node pointer parameter. I have separately submitted a >>> patch to fix that [1], and a few related functions which had the same >>> issue. I'm hoping that will get into linux-next before this does, so >>> that the warnings never show up there. >> >> Please adjust the patch so that it compiles without warnings on >> current linux-next. Your patch for DT API hasn't been reviewed yet >> AFICS, and I can imagine that there will be some resistance against. > > Since the DT API patch was just accepted by Rob [1], would it be OK > to wait for the results of Stefan's testing (and any other reviews) > before making a decision on this? From Stefan's note, it won't be > until this weekend that he will have a chance to test, and I'm > guessing the DT API patch will make its way through Rob's tree to > linux-next by then. OK. > FYI, the warning workaround would be to make the second parameter to > is31fl32xx_parse_child_dt() non-const. > > [1] https://lkml.org/lkml/2016/3/3/924 > >>> Changes from RFC: >>> - Removed max-brightness DT property. >>> - Refer to these devices as "LED controllers" in Kconfig. >>> - Removed redundant last sentence from Kconfig entry >>> - Removed unnecessary debug code. >>> - Do not set led_classdev.brightness to 0 explicitly, as it is >>> already initialized to 0 by devm_kzalloc(). >>> - Used of_property_read_string() instead of of_get_property(). >>> - Fail immediately on DT parsing error in a child node, rather than >>> continuing on with the non-faulty ones. >>> - Added additional comments for some things that might be non-obvious. >>> - Added constants for the location of the SSD bit in the SHUTDOWN >>> register, and the 3216's CONFIG register. >>> - Added special sw_shutdown_func for the 3216 device, as that bit >>> is in a different register, at a different position, and has reverse >>> polarity compared to all the other devices. >>> - Refactored is31fl32xx_init_regs() to separate out some logic into >>> is31fl32xx_reset_regs() and is31fl32xx_software_shutdown(). >>> >>> [1] https://lkml.org/lkml/2016/3/2/746 >>> >>> drivers/leds/Kconfig | 8 + >>> drivers/leds/Makefile | 1 + >>> drivers/leds/leds-is31fl32xx.c | 505 +++++++++++++++++++++++++++++++++++++++++ >>> 3 files changed, 514 insertions(+) >>> create mode 100644 drivers/leds/leds-is31fl32xx.c >>> >>> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig >>> index 1034696..9c63ba4 100644 >>> --- a/drivers/leds/Kconfig >>> +++ b/drivers/leds/Kconfig >>> @@ -580,6 +580,14 @@ config LEDS_SN3218 >>> This driver can also be built as a module. If so the module >>> will be called leds-sn3218. >>> >>> +config LEDS_IS31FL32XX >>> + tristate "LED support for ISSI IS31FL32XX I2C LED controller family" >>> + depends on LEDS_CLASS && I2C && OF >>> + help >>> + Say Y here to include support for ISSI IS31FL32XX LED controllers. >>> + They are I2C devices with multiple constant-current channels, each >>> + with independent 256-level PWM control. >>> + >>> comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)" >>> >>> config LEDS_BLINKM >>> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile >>> index 89c9b6f..3fdf313 100644 >>> --- a/drivers/leds/Makefile >>> +++ b/drivers/leds/Makefile >>> @@ -67,6 +67,7 @@ obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o >>> obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o >>> obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o >>> obj-$(CONFIG_LEDS_SN3218) += leds-sn3218.o >>> +obj-$(CONFIG_LEDS_IS31FL32XX) += leds-is31fl32xx.o >>> >>> # LED SPI Drivers >>> obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o >>> diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c >>> new file mode 100644 >>> index 0000000..49818f0 >>> --- /dev/null >>> +++ b/drivers/leds/leds-is31fl32xx.c >>> @@ -0,0 +1,505 @@ >>> +/* >>> + * linux/drivers/leds-is31fl32xx.c >>> + * >>> + * Driver for ISSI IS31FL32xx family of I2C LED controllers >>> + * >>> + * Copyright 2015 Allworx Corp. >>> + * >>> + * >>> + * 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. >>> + * >>> + * Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml >>> + */ >>> + >>> +#include <linux/err.h> >>> +#include <linux/i2c.h> >>> +#include <linux/kernel.h> >>> +#include <linux/leds.h> >>> +#include <linux/module.h> >>> +#include <linux/of_platform.h> >>> + >>> +/* Used to indicate a device has no such register */ >>> +#define IS31FL32XX_REG_NONE 0xFF >>> + >>> +/* Software Shutdown bit in Shutdown Register */ >>> +#define IS31FL32XX_SHUTDOWN_SSD_ENABLE 0 >>> +#define IS31FL32XX_SHUTDOWN_SSD_DISABLE BIT(0) >>> + >>> +/* IS31FL3216 has a number of unique registers */ >>> +#define IS31FL3216_CONFIG_REG 0x00 >>> +#define IS31FL3216_LIGHTING_EFFECT_REG 0x03 >>> +#define IS31FL3216_CHANNEL_CONFIG_REG 0x04 >>> + >>> +/* Software Shutdown bit in 3216 Config Register */ >>> +#define IS31FL3216_CONFIG_SSD_ENABLE BIT(7) >>> +#define IS31FL3216_CONFIG_SSD_DISABLE 0 >>> + >>> +struct is31fl32xx_priv; >>> +struct is31fl32xx_led_data { >>> + struct led_classdev cdev; >>> + u8 channel; /* 1-based, max priv->cdef->channels */ >>> + struct is31fl32xx_priv *priv; >>> +}; >>> + >>> +struct is31fl32xx_priv { >>> + const struct is31fl32xx_chipdef *cdef; >>> + struct i2c_client *client; >>> + unsigned int num_leds; >>> + struct is31fl32xx_led_data leds[0]; >>> +}; >>> + >>> +/** >>> + * struct is31fl32xx_chipdef - chip-specific attributes >>> + * @channels : Number of LED channels >>> + * @shutdown_reg : address of Shutdown register (optional) >>> + * @pwm_update_reg : address of PWM Update register >>> + * @global_control_reg : address of Global Control register (optional) >>> + * @reset_reg : address of Reset register (optional) >>> + * @pwm_register_base : address of first PWM register >>> + * @pwm_registers_reversed: : true if PWM registers count down instead of up >>> + * @led_control_register_base : address of first LED control register (optional) >>> + * @enable_bits_per_led_control_register: number of LEDs enable bits in each >>> + * @reset_func: : pointer to reset function >>> + * >>> + * For all optional register addresses, the sentinel value %IS31FL32XX_REG_NONE >>> + * indicates that this chip has no such register. >>> + * >>> + * If non-NULL, @reset_func will be called during probing to set all >>> + * necessary registers to a known initialization state. This is needed >>> + * for chips that do not have a @reset_reg. >>> + * >>> + * @enable_bits_per_led_control_register must be >=1 if >>> + * @led_control_register_base != %IS31FL32XX_REG_NONE. >>> + */ >>> +struct is31fl32xx_chipdef { >>> + u8 channels; >>> + u8 shutdown_reg; >>> + u8 pwm_update_reg; >>> + u8 global_control_reg; >>> + u8 reset_reg; >>> + u8 pwm_register_base; >>> + bool pwm_registers_reversed; >>> + u8 led_control_register_base; >>> + u8 enable_bits_per_led_control_register; >>> + int (*reset_func)(struct is31fl32xx_priv *priv); >>> + int (*sw_shutdown_func)(struct is31fl32xx_priv *priv, bool enable); >>> +}; >>> + >>> +static const struct is31fl32xx_chipdef is31fl3236_cdef = { >>> + .channels = 36, >>> + .shutdown_reg = 0x00, >>> + .pwm_update_reg = 0x25, >>> + .global_control_reg = 0x4a, >>> + .reset_reg = 0x4f, >>> + .pwm_register_base = 0x01, >>> + .led_control_register_base = 0x26, >>> + .enable_bits_per_led_control_register = 1, >>> +}; >>> + >>> +static const struct is31fl32xx_chipdef is31fl3235_cdef = { >>> + .channels = 28, >>> + .shutdown_reg = 0x00, >>> + .pwm_update_reg = 0x25, >>> + .global_control_reg = 0x4a, >>> + .reset_reg = 0x4f, >>> + .pwm_register_base = 0x05, >>> + .led_control_register_base = 0x2a, >>> + .enable_bits_per_led_control_register = 1, >>> +}; >>> + >>> +static const struct is31fl32xx_chipdef is31fl3218_cdef = { >>> + .channels = 18, >>> + .shutdown_reg = 0x00, >>> + .pwm_update_reg = 0x16, >>> + .global_control_reg = IS31FL32XX_REG_NONE, >>> + .reset_reg = 0x17, >>> + .pwm_register_base = 0x01, >>> + .led_control_register_base = 0x13, >>> + .enable_bits_per_led_control_register = 6, >>> +}; >>> + >>> +static int is31fl3216_reset(struct is31fl32xx_priv *priv); >>> +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, >>> + bool enable); >>> +static const struct is31fl32xx_chipdef is31fl3216_cdef = { >>> + .channels = 16, >>> + .shutdown_reg = IS31FL32XX_REG_NONE, >>> + .pwm_update_reg = 0xB0, >>> + .global_control_reg = IS31FL32XX_REG_NONE, >>> + .reset_reg = IS31FL32XX_REG_NONE, >>> + .pwm_register_base = 0x10, >>> + .pwm_registers_reversed = true, >>> + .led_control_register_base = 0x01, >>> + .enable_bits_per_led_control_register = 8, >>> + .reset_func = is31fl3216_reset, >>> + .sw_shutdown_func = is31fl3216_software_shutdown, >>> +}; >>> + >>> +static int is31fl32xx_write(struct is31fl32xx_priv *priv, u8 reg, u8 val) >>> +{ >>> + int ret; >>> + >>> + dev_dbg(&priv->client->dev, "writing register 0x%02X=0x%02X", reg, val); >>> + >>> + ret = i2c_smbus_write_byte_data(priv->client, reg, val); >>> + if (ret) { >>> + dev_err(&priv->client->dev, >>> + "register write to 0x%02X failed (error %d)", >>> + reg, ret); >>> + } >>> + return ret; >>> +} >>> + >>> +/* >>> + * Custom reset function for IS31FL3216 because it does not have a RESET >>> + * register the way that the other IS31FL32xx chips do. We don't bother >>> + * writing the GPIO and animation registers, because the registers we >>> + * do write ensure those will have no effect. >>> + */ >>> +static int is31fl3216_reset(struct is31fl32xx_priv *priv) >>> +{ >>> + unsigned int i; >>> + int ret; >>> + >>> + ret = is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, >>> + IS31FL3216_CONFIG_SSD_ENABLE); >>> + if (ret) >>> + return ret; >>> + for (i = 0; i < priv->cdef->channels; i++) { >>> + ret = is31fl32xx_write(priv, priv->cdef->pwm_register_base+i, >>> + 0x00); >>> + if (ret) >>> + return ret; >>> + } >>> + ret = is31fl32xx_write(priv, priv->cdef->pwm_update_reg, 0); >>> + if (ret) >>> + return ret; >>> + ret = is31fl32xx_write(priv, IS31FL3216_LIGHTING_EFFECT_REG, 0x00); >>> + if (ret) >>> + return ret; >>> + ret = is31fl32xx_write(priv, IS31FL3216_CHANNEL_CONFIG_REG, 0x00); >>> + if (ret) >>> + return ret; >>> + >>> + return 0; >>> +} >>> + >>> +/* >>> + * Custom Software-Shutdown function for IS31FL3216 because it does not have >>> + * a SHUTDOWN register the way that the other IS31FL32xx chips do. >>> + * We don't bother doing a read/modify/write on the CONFIG register because >>> + * we only ever use a value of '0' for the other fields in that register. >>> + */ >>> +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, >>> + bool enable) >>> +{ >>> + u8 value = enable ? IS31FL3216_CONFIG_SSD_ENABLE : >>> + IS31FL3216_CONFIG_SSD_DISABLE; >>> + >>> + return is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, value); >>> +} >>> + >>> +/* >>> + * NOTE: A mutex is not needed in this function because: >>> + * - All referenced data is read-only after probe() >>> + * - The I2C core has a mutex on to protect the bus >>> + * - There are no read/modify/write operations >>> + * - Intervening operations between the write of the PWM register >>> + * and the Update register are harmless. >>> + * >>> + * Example: >>> + * PWM_REG_1 write 16 >>> + * UPDATE_REG write 0 >>> + * PWM_REG_2 write 128 >>> + * UPDATE_REG write 0 >>> + * vs: >>> + * PWM_REG_1 write 16 >>> + * PWM_REG_2 write 128 >>> + * UPDATE_REG write 0 >>> + * UPDATE_REG write 0 >>> + * are equivalent. Poking the Update register merely applies all PWM >>> + * register writes up to that point. >>> + */ >>> +static int is31fl32xx_brightness_set(struct led_classdev *led_cdev, >>> + enum led_brightness brightness) >>> +{ >>> + const struct is31fl32xx_led_data *led_data = >>> + container_of(led_cdev, struct is31fl32xx_led_data, cdev); >>> + const struct is31fl32xx_chipdef *cdef = led_data->priv->cdef; >>> + u8 pwm_register_offset; >>> + int ret; >>> + >>> + dev_dbg(led_cdev->dev, "%s: %d\n", __func__, brightness); >>> + >>> + /* NOTE: led_data->channel is 1-based */ >>> + if (cdef->pwm_registers_reversed) >>> + pwm_register_offset = cdef->channels - led_data->channel; >>> + else >>> + pwm_register_offset = led_data->channel - 1; >>> + >>> + ret = is31fl32xx_write(led_data->priv, >>> + cdef->pwm_register_base + pwm_register_offset, >>> + brightness); >>> + if (ret) >>> + return ret; >>> + >>> + return is31fl32xx_write(led_data->priv, cdef->pwm_update_reg, 0); >>> +} >>> + >>> +static int is31fl32xx_reset_regs(struct is31fl32xx_priv *priv) >>> +{ >>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; >>> + int ret; >>> + >>> + if (cdef->reset_reg != IS31FL32XX_REG_NONE) { >>> + ret = is31fl32xx_write(priv, cdef->reset_reg, 0); >>> + if (ret) >>> + return ret; >>> + } >>> + >>> + if (cdef->reset_func) >>> + return cdef->reset_func(priv); >>> + >>> + return 0; >>> +} >>> + >>> +static int is31fl32xx_software_shutdown(struct is31fl32xx_priv *priv, >>> + bool enable) >>> +{ >>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; >>> + int ret; >>> + >>> + if (cdef->shutdown_reg != IS31FL32XX_REG_NONE) { >>> + u8 value = enable ? IS31FL32XX_SHUTDOWN_SSD_ENABLE : >>> + IS31FL32XX_SHUTDOWN_SSD_DISABLE; >>> + ret = is31fl32xx_write(priv, cdef->shutdown_reg, value); >>> + if (ret) >>> + return ret; >>> + } >>> + >>> + if (cdef->sw_shutdown_func) >>> + return cdef->sw_shutdown_func(priv, enable); >> >> You seem to call sw_shutdown_func only here, so why should we have >> enable parameter in this op? > > I'm not sure if I understand the question, but I will try to answer. > > 'enable' is passed through is31fl32xx_software_shutdown to > cdef->sw_shutdown_func, so it can be either true or false at that > point. The purpose of sw_shutdown_func is to add any special behavior > when enabling/disabling software-shutdown mode, which is needed for > the 3216 because its SSD bit is in a different position and with > opposite polarity. > > Is it that 'enable' in that line of code makes it look like it's being > called with an hardcoded value rather than a variable? If so, perhaps a > different parameter name would make it more obvious? Or a kerneldoc > comment for the function to describe the parameter? > > Or have I totally missed the point of the question? Actually I should have placed this question next to the call to s31fl32xx_software_shutdown() in is31fl32xx_init_regs(), which is passed "false" in the second argument, and there is no other call to s31fl32xx_software_shutdown() in the driver. Having the argument makes people wondering that there is some use case in the driver, where "true" is passed, but it seems not to be the case. >>> + return 0; >>> +} >>> + >>> +static int is31fl32xx_init_regs(struct is31fl32xx_priv *priv) >>> +{ >>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; >>> + int ret; >>> + >>> + ret = is31fl32xx_reset_regs(priv); >>> + if (ret) >>> + return ret; >>> + >>> + /* >>> + * Set enable bit for all channels. >>> + * We will control state with PWM registers alone. >>> + */ >>> + if (cdef->led_control_register_base != IS31FL32XX_REG_NONE) { >>> + u8 value = >>> + GENMASK(cdef->enable_bits_per_led_control_register-1, 0); >>> + u8 num_regs = cdef->channels / >>> + cdef->enable_bits_per_led_control_register; >>> + int i; >>> + >>> + for (i = 0; i < num_regs; i++) { >>> + ret = is31fl32xx_write(priv, >>> + cdef->led_control_register_base+i, >>> + value); >>> + if (ret) >>> + return ret; >>> + } >>> + } >>> + >>> + ret = is31fl32xx_software_shutdown(priv, false); >>> + if (ret) >>> + return ret; >>> + >>> + if (cdef->global_control_reg != IS31FL32XX_REG_NONE) { >>> + ret = is31fl32xx_write(priv, cdef->global_control_reg, 0x00); >>> + if (ret) >>> + return ret; >>> + } >>> + >>> + return 0; >>> +} >>> + >>> +static inline size_t sizeof_is31fl32xx_priv(int num_leds) >>> +{ >>> + return sizeof(struct is31fl32xx_priv) + >>> + (sizeof(struct is31fl32xx_led_data) * num_leds); >>> +} >>> + >>> +static int is31fl32xx_parse_child_dt(const struct device *dev, >>> + const struct device_node *child, >>> + struct is31fl32xx_led_data *led_data) >>> +{ >>> + struct led_classdev *cdev = &led_data->cdev; >>> + int ret = 0; >>> + u32 reg; >>> + >>> + if (of_property_read_string(child, "label", &cdev->name)) >>> + cdev->name = child->name; >>> + >>> + ret = of_property_read_u32(child, "reg", ®); >>> + if (ret || reg < 1 || reg > led_data->priv->cdef->channels) { >>> + dev_err(dev, >>> + "Child node %s does not have a valid reg property\n", >>> + child->full_name); >>> + return -EINVAL; >>> + } >>> + led_data->channel = reg; >>> + >>> + of_property_read_string(child, "linux,default-trigger", >>> + &cdev->default_trigger); >>> + >>> + cdev->brightness_set_blocking = is31fl32xx_brightness_set; >>> + >>> + return 0; >>> +} >>> + >>> +static struct is31fl32xx_led_data *is31fl32xx_find_led_data( >>> + struct is31fl32xx_priv *priv, >>> + u8 channel) >>> +{ >>> + size_t i; >>> + >>> + for (i = 0; i < priv->num_leds; i++) { >>> + if (priv->leds[i].channel == channel) >>> + return &priv->leds[i]; >>> + } >>> + >>> + return NULL; >>> +} >>> + >>> +static int is31fl32xx_parse_dt(struct device *dev, >>> + struct is31fl32xx_priv *priv) >>> +{ >>> + struct device_node *child; >>> + int ret = 0; >>> + >>> + for_each_child_of_node(dev->of_node, child) { >>> + struct is31fl32xx_led_data *led_data = >>> + &priv->leds[priv->num_leds]; >>> + const struct is31fl32xx_led_data *other_led_data; >>> + >>> + led_data->priv = priv; >>> + >>> + ret = is31fl32xx_parse_child_dt(dev, child, led_data); >>> + if (ret) >>> + goto err; >>> + >>> + /* Detect if channel is already in use by another child */ >>> + other_led_data = is31fl32xx_find_led_data(priv, >>> + led_data->channel); >>> + if (other_led_data) { >>> + dev_err(dev, >>> + "%s and %s both attempting to use channel %d\n", >>> + led_data->cdev.name, >>> + other_led_data->cdev.name, >>> + led_data->channel); >>> + goto err; >>> + } >>> + >>> + ret = devm_led_classdev_register(dev, &led_data->cdev); >>> + if (ret) { >>> + dev_err(dev, "failed to register PWM led for %s: %d\n", >>> + led_data->cdev.name, ret); >>> + goto err; >>> + } >>> + >>> + priv->num_leds++; >>> + } >>> + >>> + return 0; >>> + >>> +err: >>> + of_node_put(child); >>> + return ret; >>> +} >>> + >>> +static const struct of_device_id of_is31fl31xx_match[] = { >>> + { .compatible = "issi,is31fl3236", .data = &is31fl3236_cdef, }, >>> + { .compatible = "issi,is31fl3235", .data = &is31fl3235_cdef, }, >>> + { .compatible = "issi,is31fl3218", .data = &is31fl3218_cdef, }, >>> + { .compatible = "issi,is31fl3216", .data = &is31fl3216_cdef, }, >>> + {}, >>> +}; >>> + >>> +MODULE_DEVICE_TABLE(of, of_is31fl31xx_match); >>> + >>> +static int is31fl32xx_probe(struct i2c_client *client, >>> + const struct i2c_device_id *id) >>> +{ >>> + const struct is31fl32xx_chipdef *cdef; >>> + const struct of_device_id *of_dev_id; >>> + struct device *dev = &client->dev; >>> + struct is31fl32xx_priv *priv; >>> + int count; >>> + int ret = 0; >>> + >>> + of_dev_id = of_match_device(of_is31fl31xx_match, dev); >>> + if (!of_dev_id) >>> + return -EINVAL; >>> + >>> + cdef = of_dev_id->data; >>> + >>> + count = of_get_child_count(dev->of_node); >>> + if (!count) >>> + return -EINVAL; >>> + >>> + priv = devm_kzalloc(dev, sizeof_is31fl32xx_priv(count), >>> + GFP_KERNEL); >>> + if (!priv) >>> + return -ENOMEM; >>> + >>> + priv->client = client; >>> + priv->cdef = cdef; >>> + i2c_set_clientdata(client, priv); >>> + >>> + ret = is31fl32xx_init_regs(priv); >>> + if (ret) >>> + return ret; >>> + >>> + ret = is31fl32xx_parse_dt(dev, priv); >>> + if (ret) >>> + return ret; >>> + >>> + return 0; >>> +} >>> + >>> +static int is31fl32xx_remove(struct i2c_client *client) >>> +{ >>> + struct is31fl32xx_priv *priv = i2c_get_clientdata(client); >>> + >>> + return is31fl32xx_reset_regs(priv); >>> +} >>> + >>> +/* >>> + * i2c-core requires that id_table be non-NULL, even though >>> + * it is not used for DeviceTree based instantiation. >>> + */ >>> +static const struct i2c_device_id is31fl31xx_id[] = { >>> + {}, >>> +}; >>> + >>> +MODULE_DEVICE_TABLE(i2c, is31fl31xx_id); >>> + >>> +static struct i2c_driver is31fl32xx_driver = { >>> + .driver = { >>> + .name = "is31fl32xx", >>> + .of_match_table = of_is31fl31xx_match, >>> + }, >>> + .probe = is31fl32xx_probe, >>> + .remove = is31fl32xx_remove, >>> + .id_table = is31fl31xx_id, >>> +}; >>> + >>> +module_i2c_driver(is31fl32xx_driver); >>> + >>> +MODULE_AUTHOR("David Rivshin <drivshin-5fOYsn7Fw8lBDgjK7y7TUQ@public.gmane.org>"); >>> +MODULE_DESCRIPTION("ISSI IS31FL32xx LED driver"); >>> +MODULE_LICENSE("GPL v2"); >>> > > > -- Best regards, Jacek Anaszewski -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 28+ messages in thread
[parent not found: <56D93F1A.6030305-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>]
* Re: [PATCH 3/4] leds: Add driver for the ISSI IS31FL32xx family of LED controllers [not found] ` <56D93F1A.6030305-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> @ 2016-03-04 15:05 ` David Rivshin (Allworx) 2016-03-04 16:01 ` Jacek Anaszewski 0 siblings, 1 reply; 28+ messages in thread From: David Rivshin (Allworx) @ 2016-03-04 15:05 UTC (permalink / raw) To: Jacek Anaszewski Cc: linux-leds-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA, Richard Purdie, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Stefan Wahren, linux-kernel-u79uwXL29TY76Z2rM5mHXA On Fri, 04 Mar 2016 08:54:02 +0100 Jacek Anaszewski <j.anaszewski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> wrote: > On 03/04/2016 01:45 AM, David Rivshin (Allworx) wrote: > > On Thu, 03 Mar 2016 15:51:32 +0100 > > Jacek Anaszewski <j.anaszewski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> wrote: > > > >> Hi David, > >> > >> Thanks for the update. Two remarks in the code. > >> > >> On 03/03/2016 04:01 AM, David Rivshin (Allworx) wrote: > >>> From: David Rivshin <drivshin-5fOYsn7Fw8lBDgjK7y7TUQ@public.gmane.org> > >>> > >>> The IS31FL32xx family of LED controllers are I2C devices with multiple > >>> constant-current channels, each with independent 256-level PWM control. > >>> > >>> Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml > >>> > >>> This has been tested on the IS31FL3236 and IS31FL3216, on an ARM > >>> (TI am335x) platform. > >>> > >>> The programming paradigm of these devices is similar in the following > >>> ways: > >>> - All registers are 8 bit > >>> - All LED control registers are write-only > >>> - Each LED channel has a PWM register (0-255) > >>> - PWM register writes are shadowed until an Update register is poked > >>> - All have a concept of Software Shutdown, which disables output > >>> > >>> However, there are some differences in devices: > >>> - 3236/3235 have a separate Control register for each LED, > >>> (3218/3216 pack the enable bits into fewer registers) > >>> - 3236/3235 have a per-channel current divisor setting > >>> - 3236/3235 have a Global Control register that can turn off all LEDs > >>> - 3216 is unique in a number of ways > >>> - OUT9-OUT16 can be configured as GPIOs instead of LED controls > >>> - LEDs can be programmed with an 8-frame animation, with > >>> programmable delay between frames > >>> - LEDs can be modulated by an input audio signal > >>> - Max output current can be adjusted from 1/4 to 2x globally > >>> - Has a Configuration register instead of a Shutdown register > >>> > >>> This driver currently only supports the base PWM control function > >>> of these devices. The following features of these devices are not > >>> implemented, although it should be possible to add them in the future: > >>> - All devices are capable of going into a lower-power "software > >>> shutdown" mode. > >>> - The is31fl3236 and is31fl3235 can reduce the max output current > >>> per-channel with a divisor of 1, 2, 3, or 4. > >>> - The is31fl3216 can use some LED channels as GPIOs instead. > >>> - The is31fl3216 can animate LEDs in hardware. > >>> - The is31fl3216 can modulate LEDs according to an audio input. > >>> - The is31fl3216 can reduce/increase max output current globally. > >>> > >>> Signed-off-by: David Rivshin <drivshin-5fOYsn7Fw8lBDgjK7y7TUQ@public.gmane.org> > >>> --- > >>> > >>> You may see two instances of this warning: > >>> "passing argument 1 of 'of_property_read_string' discards 'const' > >>> qualifier from pointer target type" > >>> That is a result of of_property_read_string() taking a non-const > >>> struct device_node pointer parameter. I have separately submitted a > >>> patch to fix that [1], and a few related functions which had the same > >>> issue. I'm hoping that will get into linux-next before this does, so > >>> that the warnings never show up there. > >> > >> Please adjust the patch so that it compiles without warnings on > >> current linux-next. Your patch for DT API hasn't been reviewed yet > >> AFICS, and I can imagine that there will be some resistance against. > > > > Since the DT API patch was just accepted by Rob [1], would it be OK > > to wait for the results of Stefan's testing (and any other reviews) > > before making a decision on this? From Stefan's note, it won't be > > until this weekend that he will have a chance to test, and I'm > > guessing the DT API patch will make its way through Rob's tree to > > linux-next by then. > > OK. > > > FYI, the warning workaround would be to make the second parameter to > > is31fl32xx_parse_child_dt() non-const. > > > > [1] https://lkml.org/lkml/2016/3/3/924 > > > >>> Changes from RFC: > >>> - Removed max-brightness DT property. > >>> - Refer to these devices as "LED controllers" in Kconfig. > >>> - Removed redundant last sentence from Kconfig entry > >>> - Removed unnecessary debug code. > >>> - Do not set led_classdev.brightness to 0 explicitly, as it is > >>> already initialized to 0 by devm_kzalloc(). > >>> - Used of_property_read_string() instead of of_get_property(). > >>> - Fail immediately on DT parsing error in a child node, rather than > >>> continuing on with the non-faulty ones. > >>> - Added additional comments for some things that might be non-obvious. > >>> - Added constants for the location of the SSD bit in the SHUTDOWN > >>> register, and the 3216's CONFIG register. > >>> - Added special sw_shutdown_func for the 3216 device, as that bit > >>> is in a different register, at a different position, and has reverse > >>> polarity compared to all the other devices. > >>> - Refactored is31fl32xx_init_regs() to separate out some logic into > >>> is31fl32xx_reset_regs() and is31fl32xx_software_shutdown(). > >>> > >>> [1] https://lkml.org/lkml/2016/3/2/746 > >>> > >>> drivers/leds/Kconfig | 8 + > >>> drivers/leds/Makefile | 1 + > >>> drivers/leds/leds-is31fl32xx.c | 505 +++++++++++++++++++++++++++++++++++++++++ > >>> 3 files changed, 514 insertions(+) > >>> create mode 100644 drivers/leds/leds-is31fl32xx.c > >>> > >>> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig > >>> index 1034696..9c63ba4 100644 > >>> --- a/drivers/leds/Kconfig > >>> +++ b/drivers/leds/Kconfig > >>> @@ -580,6 +580,14 @@ config LEDS_SN3218 > >>> This driver can also be built as a module. If so the module > >>> will be called leds-sn3218. > >>> > >>> +config LEDS_IS31FL32XX > >>> + tristate "LED support for ISSI IS31FL32XX I2C LED controller family" > >>> + depends on LEDS_CLASS && I2C && OF > >>> + help > >>> + Say Y here to include support for ISSI IS31FL32XX LED controllers. > >>> + They are I2C devices with multiple constant-current channels, each > >>> + with independent 256-level PWM control. > >>> + > >>> comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)" > >>> > >>> config LEDS_BLINKM > >>> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile > >>> index 89c9b6f..3fdf313 100644 > >>> --- a/drivers/leds/Makefile > >>> +++ b/drivers/leds/Makefile > >>> @@ -67,6 +67,7 @@ obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o > >>> obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o > >>> obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o > >>> obj-$(CONFIG_LEDS_SN3218) += leds-sn3218.o > >>> +obj-$(CONFIG_LEDS_IS31FL32XX) += leds-is31fl32xx.o > >>> > >>> # LED SPI Drivers > >>> obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o > >>> diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c > >>> new file mode 100644 > >>> index 0000000..49818f0 > >>> --- /dev/null > >>> +++ b/drivers/leds/leds-is31fl32xx.c > >>> @@ -0,0 +1,505 @@ > >>> +/* > >>> + * linux/drivers/leds-is31fl32xx.c > >>> + * > >>> + * Driver for ISSI IS31FL32xx family of I2C LED controllers > >>> + * > >>> + * Copyright 2015 Allworx Corp. > >>> + * > >>> + * > >>> + * 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. > >>> + * > >>> + * Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml > >>> + */ > >>> + > >>> +#include <linux/err.h> > >>> +#include <linux/i2c.h> > >>> +#include <linux/kernel.h> > >>> +#include <linux/leds.h> > >>> +#include <linux/module.h> > >>> +#include <linux/of_platform.h> > >>> + > >>> +/* Used to indicate a device has no such register */ > >>> +#define IS31FL32XX_REG_NONE 0xFF > >>> + > >>> +/* Software Shutdown bit in Shutdown Register */ > >>> +#define IS31FL32XX_SHUTDOWN_SSD_ENABLE 0 > >>> +#define IS31FL32XX_SHUTDOWN_SSD_DISABLE BIT(0) > >>> + > >>> +/* IS31FL3216 has a number of unique registers */ > >>> +#define IS31FL3216_CONFIG_REG 0x00 > >>> +#define IS31FL3216_LIGHTING_EFFECT_REG 0x03 > >>> +#define IS31FL3216_CHANNEL_CONFIG_REG 0x04 > >>> + > >>> +/* Software Shutdown bit in 3216 Config Register */ > >>> +#define IS31FL3216_CONFIG_SSD_ENABLE BIT(7) > >>> +#define IS31FL3216_CONFIG_SSD_DISABLE 0 > >>> + > >>> +struct is31fl32xx_priv; > >>> +struct is31fl32xx_led_data { > >>> + struct led_classdev cdev; > >>> + u8 channel; /* 1-based, max priv->cdef->channels */ > >>> + struct is31fl32xx_priv *priv; > >>> +}; > >>> + > >>> +struct is31fl32xx_priv { > >>> + const struct is31fl32xx_chipdef *cdef; > >>> + struct i2c_client *client; > >>> + unsigned int num_leds; > >>> + struct is31fl32xx_led_data leds[0]; > >>> +}; > >>> + > >>> +/** > >>> + * struct is31fl32xx_chipdef - chip-specific attributes > >>> + * @channels : Number of LED channels > >>> + * @shutdown_reg : address of Shutdown register (optional) > >>> + * @pwm_update_reg : address of PWM Update register > >>> + * @global_control_reg : address of Global Control register (optional) > >>> + * @reset_reg : address of Reset register (optional) > >>> + * @pwm_register_base : address of first PWM register > >>> + * @pwm_registers_reversed: : true if PWM registers count down instead of up > >>> + * @led_control_register_base : address of first LED control register (optional) > >>> + * @enable_bits_per_led_control_register: number of LEDs enable bits in each > >>> + * @reset_func: : pointer to reset function > >>> + * > >>> + * For all optional register addresses, the sentinel value %IS31FL32XX_REG_NONE > >>> + * indicates that this chip has no such register. > >>> + * > >>> + * If non-NULL, @reset_func will be called during probing to set all > >>> + * necessary registers to a known initialization state. This is needed > >>> + * for chips that do not have a @reset_reg. > >>> + * > >>> + * @enable_bits_per_led_control_register must be >=1 if > >>> + * @led_control_register_base != %IS31FL32XX_REG_NONE. > >>> + */ > >>> +struct is31fl32xx_chipdef { > >>> + u8 channels; > >>> + u8 shutdown_reg; > >>> + u8 pwm_update_reg; > >>> + u8 global_control_reg; > >>> + u8 reset_reg; > >>> + u8 pwm_register_base; > >>> + bool pwm_registers_reversed; > >>> + u8 led_control_register_base; > >>> + u8 enable_bits_per_led_control_register; > >>> + int (*reset_func)(struct is31fl32xx_priv *priv); > >>> + int (*sw_shutdown_func)(struct is31fl32xx_priv *priv, bool enable); > >>> +}; > >>> + > >>> +static const struct is31fl32xx_chipdef is31fl3236_cdef = { > >>> + .channels = 36, > >>> + .shutdown_reg = 0x00, > >>> + .pwm_update_reg = 0x25, > >>> + .global_control_reg = 0x4a, > >>> + .reset_reg = 0x4f, > >>> + .pwm_register_base = 0x01, > >>> + .led_control_register_base = 0x26, > >>> + .enable_bits_per_led_control_register = 1, > >>> +}; > >>> + > >>> +static const struct is31fl32xx_chipdef is31fl3235_cdef = { > >>> + .channels = 28, > >>> + .shutdown_reg = 0x00, > >>> + .pwm_update_reg = 0x25, > >>> + .global_control_reg = 0x4a, > >>> + .reset_reg = 0x4f, > >>> + .pwm_register_base = 0x05, > >>> + .led_control_register_base = 0x2a, > >>> + .enable_bits_per_led_control_register = 1, > >>> +}; > >>> + > >>> +static const struct is31fl32xx_chipdef is31fl3218_cdef = { > >>> + .channels = 18, > >>> + .shutdown_reg = 0x00, > >>> + .pwm_update_reg = 0x16, > >>> + .global_control_reg = IS31FL32XX_REG_NONE, > >>> + .reset_reg = 0x17, > >>> + .pwm_register_base = 0x01, > >>> + .led_control_register_base = 0x13, > >>> + .enable_bits_per_led_control_register = 6, > >>> +}; > >>> + > >>> +static int is31fl3216_reset(struct is31fl32xx_priv *priv); > >>> +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, > >>> + bool enable); > >>> +static const struct is31fl32xx_chipdef is31fl3216_cdef = { > >>> + .channels = 16, > >>> + .shutdown_reg = IS31FL32XX_REG_NONE, > >>> + .pwm_update_reg = 0xB0, > >>> + .global_control_reg = IS31FL32XX_REG_NONE, > >>> + .reset_reg = IS31FL32XX_REG_NONE, > >>> + .pwm_register_base = 0x10, > >>> + .pwm_registers_reversed = true, > >>> + .led_control_register_base = 0x01, > >>> + .enable_bits_per_led_control_register = 8, > >>> + .reset_func = is31fl3216_reset, > >>> + .sw_shutdown_func = is31fl3216_software_shutdown, > >>> +}; > >>> + > >>> +static int is31fl32xx_write(struct is31fl32xx_priv *priv, u8 reg, u8 val) > >>> +{ > >>> + int ret; > >>> + > >>> + dev_dbg(&priv->client->dev, "writing register 0x%02X=0x%02X", reg, val); > >>> + > >>> + ret = i2c_smbus_write_byte_data(priv->client, reg, val); > >>> + if (ret) { > >>> + dev_err(&priv->client->dev, > >>> + "register write to 0x%02X failed (error %d)", > >>> + reg, ret); > >>> + } > >>> + return ret; > >>> +} > >>> + > >>> +/* > >>> + * Custom reset function for IS31FL3216 because it does not have a RESET > >>> + * register the way that the other IS31FL32xx chips do. We don't bother > >>> + * writing the GPIO and animation registers, because the registers we > >>> + * do write ensure those will have no effect. > >>> + */ > >>> +static int is31fl3216_reset(struct is31fl32xx_priv *priv) > >>> +{ > >>> + unsigned int i; > >>> + int ret; > >>> + > >>> + ret = is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, > >>> + IS31FL3216_CONFIG_SSD_ENABLE); > >>> + if (ret) > >>> + return ret; > >>> + for (i = 0; i < priv->cdef->channels; i++) { > >>> + ret = is31fl32xx_write(priv, priv->cdef->pwm_register_base+i, > >>> + 0x00); > >>> + if (ret) > >>> + return ret; > >>> + } > >>> + ret = is31fl32xx_write(priv, priv->cdef->pwm_update_reg, 0); > >>> + if (ret) > >>> + return ret; > >>> + ret = is31fl32xx_write(priv, IS31FL3216_LIGHTING_EFFECT_REG, 0x00); > >>> + if (ret) > >>> + return ret; > >>> + ret = is31fl32xx_write(priv, IS31FL3216_CHANNEL_CONFIG_REG, 0x00); > >>> + if (ret) > >>> + return ret; > >>> + > >>> + return 0; > >>> +} > >>> + > >>> +/* > >>> + * Custom Software-Shutdown function for IS31FL3216 because it does not have > >>> + * a SHUTDOWN register the way that the other IS31FL32xx chips do. > >>> + * We don't bother doing a read/modify/write on the CONFIG register because > >>> + * we only ever use a value of '0' for the other fields in that register. > >>> + */ > >>> +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, > >>> + bool enable) > >>> +{ > >>> + u8 value = enable ? IS31FL3216_CONFIG_SSD_ENABLE : > >>> + IS31FL3216_CONFIG_SSD_DISABLE; > >>> + > >>> + return is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, value); > >>> +} > >>> + > >>> +/* > >>> + * NOTE: A mutex is not needed in this function because: > >>> + * - All referenced data is read-only after probe() > >>> + * - The I2C core has a mutex on to protect the bus > >>> + * - There are no read/modify/write operations > >>> + * - Intervening operations between the write of the PWM register > >>> + * and the Update register are harmless. > >>> + * > >>> + * Example: > >>> + * PWM_REG_1 write 16 > >>> + * UPDATE_REG write 0 > >>> + * PWM_REG_2 write 128 > >>> + * UPDATE_REG write 0 > >>> + * vs: > >>> + * PWM_REG_1 write 16 > >>> + * PWM_REG_2 write 128 > >>> + * UPDATE_REG write 0 > >>> + * UPDATE_REG write 0 > >>> + * are equivalent. Poking the Update register merely applies all PWM > >>> + * register writes up to that point. > >>> + */ > >>> +static int is31fl32xx_brightness_set(struct led_classdev *led_cdev, > >>> + enum led_brightness brightness) > >>> +{ > >>> + const struct is31fl32xx_led_data *led_data = > >>> + container_of(led_cdev, struct is31fl32xx_led_data, cdev); > >>> + const struct is31fl32xx_chipdef *cdef = led_data->priv->cdef; > >>> + u8 pwm_register_offset; > >>> + int ret; > >>> + > >>> + dev_dbg(led_cdev->dev, "%s: %d\n", __func__, brightness); > >>> + > >>> + /* NOTE: led_data->channel is 1-based */ > >>> + if (cdef->pwm_registers_reversed) > >>> + pwm_register_offset = cdef->channels - led_data->channel; > >>> + else > >>> + pwm_register_offset = led_data->channel - 1; > >>> + > >>> + ret = is31fl32xx_write(led_data->priv, > >>> + cdef->pwm_register_base + pwm_register_offset, > >>> + brightness); > >>> + if (ret) > >>> + return ret; > >>> + > >>> + return is31fl32xx_write(led_data->priv, cdef->pwm_update_reg, 0); > >>> +} > >>> + > >>> +static int is31fl32xx_reset_regs(struct is31fl32xx_priv *priv) > >>> +{ > >>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; > >>> + int ret; > >>> + > >>> + if (cdef->reset_reg != IS31FL32XX_REG_NONE) { > >>> + ret = is31fl32xx_write(priv, cdef->reset_reg, 0); > >>> + if (ret) > >>> + return ret; > >>> + } > >>> + > >>> + if (cdef->reset_func) > >>> + return cdef->reset_func(priv); > >>> + > >>> + return 0; > >>> +} > >>> + > >>> +static int is31fl32xx_software_shutdown(struct is31fl32xx_priv *priv, > >>> + bool enable) > >>> +{ > >>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; > >>> + int ret; > >>> + > >>> + if (cdef->shutdown_reg != IS31FL32XX_REG_NONE) { > >>> + u8 value = enable ? IS31FL32XX_SHUTDOWN_SSD_ENABLE : > >>> + IS31FL32XX_SHUTDOWN_SSD_DISABLE; > >>> + ret = is31fl32xx_write(priv, cdef->shutdown_reg, value); > >>> + if (ret) > >>> + return ret; > >>> + } > >>> + > >>> + if (cdef->sw_shutdown_func) > >>> + return cdef->sw_shutdown_func(priv, enable); > >> > >> You seem to call sw_shutdown_func only here, so why should we have > >> enable parameter in this op? > > > > I'm not sure if I understand the question, but I will try to answer. > > > > 'enable' is passed through is31fl32xx_software_shutdown to > > cdef->sw_shutdown_func, so it can be either true or false at that > > point. The purpose of sw_shutdown_func is to add any special behavior > > when enabling/disabling software-shutdown mode, which is needed for > > the 3216 because its SSD bit is in a different position and with > > opposite polarity. > > > > Is it that 'enable' in that line of code makes it look like it's being > > called with an hardcoded value rather than a variable? If so, perhaps a > > different parameter name would make it more obvious? Or a kerneldoc > > comment for the function to describe the parameter? > > > > Or have I totally missed the point of the question? > > Actually I should have placed this question next to > the call to s31fl32xx_software_shutdown() in is31fl32xx_init_regs(), > which is passed "false" in the second argument, and there is no > other call to s31fl32xx_software_shutdown() in the driver. > > Having the argument makes people wondering that there is some > use case in the driver, where "true" is passed, but it seems not > to be the case. Thanks for the clarification. Yes, there is currently no explicit call to enable software-shutdown mode. Since the reset state of these devices is to have software-shutdown enabled, the only explicit operation on it that's currently needed is to disable it. Reasons I can think to have the 'enable' parameter anyways include: - It seems logical to me that an API to manipulate the software-shutdown state should allow both enabling and disabling. - Having a parameter for that seemed the most obvious way to go, and it was trivial to implement. - Alternatively having separate "enable" and "disable" functions would duplicate most of the logic, vs the parameter being just a single conditional. And that would also imply two function pointers in the chipdefs, which I'd prefer to minimize. - If anyone wanted to implement suspend/resume in the future, they would most likely do it by enabling/disabling software-shutdown. Supporting both enable/disable from the start should make that trivial to do. - I thought the code read better with a bool parameter, vs a longer function name. So nothing really critical, but mostly just my aesthetic and preference. Also, I expect that is31fl32xx_software_shutdown() would be inlined, so the conditional check in there is optimized out anyways, and there is no performance penalty. Looking at the disassembly in my ARMv7a build, both of those have indeed happened there. > >>> + return 0; > >>> +} > >>> + > >>> +static int is31fl32xx_init_regs(struct is31fl32xx_priv *priv) > >>> +{ > >>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; > >>> + int ret; > >>> + > >>> + ret = is31fl32xx_reset_regs(priv); > >>> + if (ret) > >>> + return ret; > >>> + > >>> + /* > >>> + * Set enable bit for all channels. > >>> + * We will control state with PWM registers alone. > >>> + */ > >>> + if (cdef->led_control_register_base != IS31FL32XX_REG_NONE) { > >>> + u8 value = > >>> + GENMASK(cdef->enable_bits_per_led_control_register-1, 0); > >>> + u8 num_regs = cdef->channels / > >>> + cdef->enable_bits_per_led_control_register; > >>> + int i; > >>> + > >>> + for (i = 0; i < num_regs; i++) { > >>> + ret = is31fl32xx_write(priv, > >>> + cdef->led_control_register_base+i, > >>> + value); > >>> + if (ret) > >>> + return ret; > >>> + } > >>> + } > >>> + > >>> + ret = is31fl32xx_software_shutdown(priv, false); > >>> + if (ret) > >>> + return ret; > >>> + > >>> + if (cdef->global_control_reg != IS31FL32XX_REG_NONE) { > >>> + ret = is31fl32xx_write(priv, cdef->global_control_reg, 0x00); > >>> + if (ret) > >>> + return ret; > >>> + } > >>> + > >>> + return 0; > >>> +} > >>> + > >>> +static inline size_t sizeof_is31fl32xx_priv(int num_leds) > >>> +{ > >>> + return sizeof(struct is31fl32xx_priv) + > >>> + (sizeof(struct is31fl32xx_led_data) * num_leds); > >>> +} > >>> + > >>> +static int is31fl32xx_parse_child_dt(const struct device *dev, > >>> + const struct device_node *child, > >>> + struct is31fl32xx_led_data *led_data) > >>> +{ > >>> + struct led_classdev *cdev = &led_data->cdev; > >>> + int ret = 0; > >>> + u32 reg; > >>> + > >>> + if (of_property_read_string(child, "label", &cdev->name)) > >>> + cdev->name = child->name; > >>> + > >>> + ret = of_property_read_u32(child, "reg", ®); > >>> + if (ret || reg < 1 || reg > led_data->priv->cdef->channels) { > >>> + dev_err(dev, > >>> + "Child node %s does not have a valid reg property\n", > >>> + child->full_name); > >>> + return -EINVAL; > >>> + } > >>> + led_data->channel = reg; > >>> + > >>> + of_property_read_string(child, "linux,default-trigger", > >>> + &cdev->default_trigger); > >>> + > >>> + cdev->brightness_set_blocking = is31fl32xx_brightness_set; > >>> + > >>> + return 0; > >>> +} > >>> + > >>> +static struct is31fl32xx_led_data *is31fl32xx_find_led_data( > >>> + struct is31fl32xx_priv *priv, > >>> + u8 channel) > >>> +{ > >>> + size_t i; > >>> + > >>> + for (i = 0; i < priv->num_leds; i++) { > >>> + if (priv->leds[i].channel == channel) > >>> + return &priv->leds[i]; > >>> + } > >>> + > >>> + return NULL; > >>> +} > >>> + > >>> +static int is31fl32xx_parse_dt(struct device *dev, > >>> + struct is31fl32xx_priv *priv) > >>> +{ > >>> + struct device_node *child; > >>> + int ret = 0; > >>> + > >>> + for_each_child_of_node(dev->of_node, child) { > >>> + struct is31fl32xx_led_data *led_data = > >>> + &priv->leds[priv->num_leds]; > >>> + const struct is31fl32xx_led_data *other_led_data; > >>> + > >>> + led_data->priv = priv; > >>> + > >>> + ret = is31fl32xx_parse_child_dt(dev, child, led_data); > >>> + if (ret) > >>> + goto err; > >>> + > >>> + /* Detect if channel is already in use by another child */ > >>> + other_led_data = is31fl32xx_find_led_data(priv, > >>> + led_data->channel); > >>> + if (other_led_data) { > >>> + dev_err(dev, > >>> + "%s and %s both attempting to use channel %d\n", > >>> + led_data->cdev.name, > >>> + other_led_data->cdev.name, > >>> + led_data->channel); > >>> + goto err; > >>> + } > >>> + > >>> + ret = devm_led_classdev_register(dev, &led_data->cdev); > >>> + if (ret) { > >>> + dev_err(dev, "failed to register PWM led for %s: %d\n", > >>> + led_data->cdev.name, ret); > >>> + goto err; > >>> + } > >>> + > >>> + priv->num_leds++; > >>> + } > >>> + > >>> + return 0; > >>> + > >>> +err: > >>> + of_node_put(child); > >>> + return ret; > >>> +} > >>> + > >>> +static const struct of_device_id of_is31fl31xx_match[] = { > >>> + { .compatible = "issi,is31fl3236", .data = &is31fl3236_cdef, }, > >>> + { .compatible = "issi,is31fl3235", .data = &is31fl3235_cdef, }, > >>> + { .compatible = "issi,is31fl3218", .data = &is31fl3218_cdef, }, > >>> + { .compatible = "issi,is31fl3216", .data = &is31fl3216_cdef, }, > >>> + {}, > >>> +}; > >>> + > >>> +MODULE_DEVICE_TABLE(of, of_is31fl31xx_match); > >>> + > >>> +static int is31fl32xx_probe(struct i2c_client *client, > >>> + const struct i2c_device_id *id) > >>> +{ > >>> + const struct is31fl32xx_chipdef *cdef; > >>> + const struct of_device_id *of_dev_id; > >>> + struct device *dev = &client->dev; > >>> + struct is31fl32xx_priv *priv; > >>> + int count; > >>> + int ret = 0; > >>> + > >>> + of_dev_id = of_match_device(of_is31fl31xx_match, dev); > >>> + if (!of_dev_id) > >>> + return -EINVAL; > >>> + > >>> + cdef = of_dev_id->data; > >>> + > >>> + count = of_get_child_count(dev->of_node); > >>> + if (!count) > >>> + return -EINVAL; > >>> + > >>> + priv = devm_kzalloc(dev, sizeof_is31fl32xx_priv(count), > >>> + GFP_KERNEL); > >>> + if (!priv) > >>> + return -ENOMEM; > >>> + > >>> + priv->client = client; > >>> + priv->cdef = cdef; > >>> + i2c_set_clientdata(client, priv); > >>> + > >>> + ret = is31fl32xx_init_regs(priv); > >>> + if (ret) > >>> + return ret; > >>> + > >>> + ret = is31fl32xx_parse_dt(dev, priv); > >>> + if (ret) > >>> + return ret; > >>> + > >>> + return 0; > >>> +} > >>> + > >>> +static int is31fl32xx_remove(struct i2c_client *client) > >>> +{ > >>> + struct is31fl32xx_priv *priv = i2c_get_clientdata(client); > >>> + > >>> + return is31fl32xx_reset_regs(priv); > >>> +} > >>> + > >>> +/* > >>> + * i2c-core requires that id_table be non-NULL, even though > >>> + * it is not used for DeviceTree based instantiation. > >>> + */ > >>> +static const struct i2c_device_id is31fl31xx_id[] = { > >>> + {}, > >>> +}; > >>> + > >>> +MODULE_DEVICE_TABLE(i2c, is31fl31xx_id); > >>> + > >>> +static struct i2c_driver is31fl32xx_driver = { > >>> + .driver = { > >>> + .name = "is31fl32xx", > >>> + .of_match_table = of_is31fl31xx_match, > >>> + }, > >>> + .probe = is31fl32xx_probe, > >>> + .remove = is31fl32xx_remove, > >>> + .id_table = is31fl31xx_id, > >>> +}; > >>> + > >>> +module_i2c_driver(is31fl32xx_driver); > >>> + > >>> +MODULE_AUTHOR("David Rivshin <drivshin-5fOYsn7Fw8lBDgjK7y7TUQ@public.gmane.org>"); > >>> +MODULE_DESCRIPTION("ISSI IS31FL32xx LED driver"); > >>> +MODULE_LICENSE("GPL v2"); > >>> -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 3/4] leds: Add driver for the ISSI IS31FL32xx family of LED controllers 2016-03-04 15:05 ` David Rivshin (Allworx) @ 2016-03-04 16:01 ` Jacek Anaszewski 2016-03-04 19:02 ` David Rivshin (Allworx) 0 siblings, 1 reply; 28+ messages in thread From: Jacek Anaszewski @ 2016-03-04 16:01 UTC (permalink / raw) To: David Rivshin (Allworx) Cc: linux-leds, devicetree, Richard Purdie, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Stefan Wahren, linux-kernel On 03/04/2016 04:05 PM, David Rivshin (Allworx) wrote: > On Fri, 04 Mar 2016 08:54:02 +0100 > Jacek Anaszewski <j.anaszewski@samsung.com> wrote: > >> On 03/04/2016 01:45 AM, David Rivshin (Allworx) wrote: >>> On Thu, 03 Mar 2016 15:51:32 +0100 >>> Jacek Anaszewski <j.anaszewski@samsung.com> wrote: >>> >>>> Hi David, >>>> >>>> Thanks for the update. Two remarks in the code. >>>> >>>> On 03/03/2016 04:01 AM, David Rivshin (Allworx) wrote: >>>>> From: David Rivshin <drivshin@allworx.com> >>>>> >>>>> The IS31FL32xx family of LED controllers are I2C devices with multiple >>>>> constant-current channels, each with independent 256-level PWM control. >>>>> >>>>> Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml >>>>> >>>>> This has been tested on the IS31FL3236 and IS31FL3216, on an ARM >>>>> (TI am335x) platform. >>>>> >>>>> The programming paradigm of these devices is similar in the following >>>>> ways: >>>>> - All registers are 8 bit >>>>> - All LED control registers are write-only >>>>> - Each LED channel has a PWM register (0-255) >>>>> - PWM register writes are shadowed until an Update register is poked >>>>> - All have a concept of Software Shutdown, which disables output >>>>> >>>>> However, there are some differences in devices: >>>>> - 3236/3235 have a separate Control register for each LED, >>>>> (3218/3216 pack the enable bits into fewer registers) >>>>> - 3236/3235 have a per-channel current divisor setting >>>>> - 3236/3235 have a Global Control register that can turn off all LEDs >>>>> - 3216 is unique in a number of ways >>>>> - OUT9-OUT16 can be configured as GPIOs instead of LED controls >>>>> - LEDs can be programmed with an 8-frame animation, with >>>>> programmable delay between frames >>>>> - LEDs can be modulated by an input audio signal >>>>> - Max output current can be adjusted from 1/4 to 2x globally >>>>> - Has a Configuration register instead of a Shutdown register >>>>> >>>>> This driver currently only supports the base PWM control function >>>>> of these devices. The following features of these devices are not >>>>> implemented, although it should be possible to add them in the future: >>>>> - All devices are capable of going into a lower-power "software >>>>> shutdown" mode. >>>>> - The is31fl3236 and is31fl3235 can reduce the max output current >>>>> per-channel with a divisor of 1, 2, 3, or 4. >>>>> - The is31fl3216 can use some LED channels as GPIOs instead. >>>>> - The is31fl3216 can animate LEDs in hardware. >>>>> - The is31fl3216 can modulate LEDs according to an audio input. >>>>> - The is31fl3216 can reduce/increase max output current globally. >>>>> >>>>> Signed-off-by: David Rivshin <drivshin@allworx.com> >>>>> --- >>>>> >>>>> You may see two instances of this warning: >>>>> "passing argument 1 of 'of_property_read_string' discards 'const' >>>>> qualifier from pointer target type" >>>>> That is a result of of_property_read_string() taking a non-const >>>>> struct device_node pointer parameter. I have separately submitted a >>>>> patch to fix that [1], and a few related functions which had the same >>>>> issue. I'm hoping that will get into linux-next before this does, so >>>>> that the warnings never show up there. >>>> >>>> Please adjust the patch so that it compiles without warnings on >>>> current linux-next. Your patch for DT API hasn't been reviewed yet >>>> AFICS, and I can imagine that there will be some resistance against. >>> >>> Since the DT API patch was just accepted by Rob [1], would it be OK >>> to wait for the results of Stefan's testing (and any other reviews) >>> before making a decision on this? From Stefan's note, it won't be >>> until this weekend that he will have a chance to test, and I'm >>> guessing the DT API patch will make its way through Rob's tree to >>> linux-next by then. >> >> OK. >> >>> FYI, the warning workaround would be to make the second parameter to >>> is31fl32xx_parse_child_dt() non-const. >>> >>> [1] https://lkml.org/lkml/2016/3/3/924 >>> >>>>> Changes from RFC: >>>>> - Removed max-brightness DT property. >>>>> - Refer to these devices as "LED controllers" in Kconfig. >>>>> - Removed redundant last sentence from Kconfig entry >>>>> - Removed unnecessary debug code. >>>>> - Do not set led_classdev.brightness to 0 explicitly, as it is >>>>> already initialized to 0 by devm_kzalloc(). >>>>> - Used of_property_read_string() instead of of_get_property(). >>>>> - Fail immediately on DT parsing error in a child node, rather than >>>>> continuing on with the non-faulty ones. >>>>> - Added additional comments for some things that might be non-obvious. >>>>> - Added constants for the location of the SSD bit in the SHUTDOWN >>>>> register, and the 3216's CONFIG register. >>>>> - Added special sw_shutdown_func for the 3216 device, as that bit >>>>> is in a different register, at a different position, and has reverse >>>>> polarity compared to all the other devices. >>>>> - Refactored is31fl32xx_init_regs() to separate out some logic into >>>>> is31fl32xx_reset_regs() and is31fl32xx_software_shutdown(). >>>>> >>>>> [1] https://lkml.org/lkml/2016/3/2/746 >>>>> >>>>> drivers/leds/Kconfig | 8 + >>>>> drivers/leds/Makefile | 1 + >>>>> drivers/leds/leds-is31fl32xx.c | 505 +++++++++++++++++++++++++++++++++++++++++ >>>>> 3 files changed, 514 insertions(+) >>>>> create mode 100644 drivers/leds/leds-is31fl32xx.c >>>>> >>>>> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig >>>>> index 1034696..9c63ba4 100644 >>>>> --- a/drivers/leds/Kconfig >>>>> +++ b/drivers/leds/Kconfig >>>>> @@ -580,6 +580,14 @@ config LEDS_SN3218 >>>>> This driver can also be built as a module. If so the module >>>>> will be called leds-sn3218. >>>>> >>>>> +config LEDS_IS31FL32XX >>>>> + tristate "LED support for ISSI IS31FL32XX I2C LED controller family" >>>>> + depends on LEDS_CLASS && I2C && OF >>>>> + help >>>>> + Say Y here to include support for ISSI IS31FL32XX LED controllers. >>>>> + They are I2C devices with multiple constant-current channels, each >>>>> + with independent 256-level PWM control. >>>>> + >>>>> comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)" >>>>> >>>>> config LEDS_BLINKM >>>>> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile >>>>> index 89c9b6f..3fdf313 100644 >>>>> --- a/drivers/leds/Makefile >>>>> +++ b/drivers/leds/Makefile >>>>> @@ -67,6 +67,7 @@ obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o >>>>> obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o >>>>> obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o >>>>> obj-$(CONFIG_LEDS_SN3218) += leds-sn3218.o >>>>> +obj-$(CONFIG_LEDS_IS31FL32XX) += leds-is31fl32xx.o >>>>> >>>>> # LED SPI Drivers >>>>> obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o >>>>> diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c >>>>> new file mode 100644 >>>>> index 0000000..49818f0 >>>>> --- /dev/null >>>>> +++ b/drivers/leds/leds-is31fl32xx.c >>>>> @@ -0,0 +1,505 @@ >>>>> +/* >>>>> + * linux/drivers/leds-is31fl32xx.c >>>>> + * >>>>> + * Driver for ISSI IS31FL32xx family of I2C LED controllers >>>>> + * >>>>> + * Copyright 2015 Allworx Corp. >>>>> + * >>>>> + * >>>>> + * 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. >>>>> + * >>>>> + * Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml >>>>> + */ >>>>> + >>>>> +#include <linux/err.h> >>>>> +#include <linux/i2c.h> >>>>> +#include <linux/kernel.h> >>>>> +#include <linux/leds.h> >>>>> +#include <linux/module.h> >>>>> +#include <linux/of_platform.h> >>>>> + >>>>> +/* Used to indicate a device has no such register */ >>>>> +#define IS31FL32XX_REG_NONE 0xFF >>>>> + >>>>> +/* Software Shutdown bit in Shutdown Register */ >>>>> +#define IS31FL32XX_SHUTDOWN_SSD_ENABLE 0 >>>>> +#define IS31FL32XX_SHUTDOWN_SSD_DISABLE BIT(0) >>>>> + >>>>> +/* IS31FL3216 has a number of unique registers */ >>>>> +#define IS31FL3216_CONFIG_REG 0x00 >>>>> +#define IS31FL3216_LIGHTING_EFFECT_REG 0x03 >>>>> +#define IS31FL3216_CHANNEL_CONFIG_REG 0x04 >>>>> + >>>>> +/* Software Shutdown bit in 3216 Config Register */ >>>>> +#define IS31FL3216_CONFIG_SSD_ENABLE BIT(7) >>>>> +#define IS31FL3216_CONFIG_SSD_DISABLE 0 >>>>> + >>>>> +struct is31fl32xx_priv; >>>>> +struct is31fl32xx_led_data { >>>>> + struct led_classdev cdev; >>>>> + u8 channel; /* 1-based, max priv->cdef->channels */ >>>>> + struct is31fl32xx_priv *priv; >>>>> +}; >>>>> + >>>>> +struct is31fl32xx_priv { >>>>> + const struct is31fl32xx_chipdef *cdef; >>>>> + struct i2c_client *client; >>>>> + unsigned int num_leds; >>>>> + struct is31fl32xx_led_data leds[0]; >>>>> +}; >>>>> + >>>>> +/** >>>>> + * struct is31fl32xx_chipdef - chip-specific attributes >>>>> + * @channels : Number of LED channels >>>>> + * @shutdown_reg : address of Shutdown register (optional) >>>>> + * @pwm_update_reg : address of PWM Update register >>>>> + * @global_control_reg : address of Global Control register (optional) >>>>> + * @reset_reg : address of Reset register (optional) >>>>> + * @pwm_register_base : address of first PWM register >>>>> + * @pwm_registers_reversed: : true if PWM registers count down instead of up >>>>> + * @led_control_register_base : address of first LED control register (optional) >>>>> + * @enable_bits_per_led_control_register: number of LEDs enable bits in each >>>>> + * @reset_func: : pointer to reset function >>>>> + * >>>>> + * For all optional register addresses, the sentinel value %IS31FL32XX_REG_NONE >>>>> + * indicates that this chip has no such register. >>>>> + * >>>>> + * If non-NULL, @reset_func will be called during probing to set all >>>>> + * necessary registers to a known initialization state. This is needed >>>>> + * for chips that do not have a @reset_reg. >>>>> + * >>>>> + * @enable_bits_per_led_control_register must be >=1 if >>>>> + * @led_control_register_base != %IS31FL32XX_REG_NONE. >>>>> + */ >>>>> +struct is31fl32xx_chipdef { >>>>> + u8 channels; >>>>> + u8 shutdown_reg; >>>>> + u8 pwm_update_reg; >>>>> + u8 global_control_reg; >>>>> + u8 reset_reg; >>>>> + u8 pwm_register_base; >>>>> + bool pwm_registers_reversed; >>>>> + u8 led_control_register_base; >>>>> + u8 enable_bits_per_led_control_register; >>>>> + int (*reset_func)(struct is31fl32xx_priv *priv); >>>>> + int (*sw_shutdown_func)(struct is31fl32xx_priv *priv, bool enable); >>>>> +}; >>>>> + >>>>> +static const struct is31fl32xx_chipdef is31fl3236_cdef = { >>>>> + .channels = 36, >>>>> + .shutdown_reg = 0x00, >>>>> + .pwm_update_reg = 0x25, >>>>> + .global_control_reg = 0x4a, >>>>> + .reset_reg = 0x4f, >>>>> + .pwm_register_base = 0x01, >>>>> + .led_control_register_base = 0x26, >>>>> + .enable_bits_per_led_control_register = 1, >>>>> +}; >>>>> + >>>>> +static const struct is31fl32xx_chipdef is31fl3235_cdef = { >>>>> + .channels = 28, >>>>> + .shutdown_reg = 0x00, >>>>> + .pwm_update_reg = 0x25, >>>>> + .global_control_reg = 0x4a, >>>>> + .reset_reg = 0x4f, >>>>> + .pwm_register_base = 0x05, >>>>> + .led_control_register_base = 0x2a, >>>>> + .enable_bits_per_led_control_register = 1, >>>>> +}; >>>>> + >>>>> +static const struct is31fl32xx_chipdef is31fl3218_cdef = { >>>>> + .channels = 18, >>>>> + .shutdown_reg = 0x00, >>>>> + .pwm_update_reg = 0x16, >>>>> + .global_control_reg = IS31FL32XX_REG_NONE, >>>>> + .reset_reg = 0x17, >>>>> + .pwm_register_base = 0x01, >>>>> + .led_control_register_base = 0x13, >>>>> + .enable_bits_per_led_control_register = 6, >>>>> +}; >>>>> + >>>>> +static int is31fl3216_reset(struct is31fl32xx_priv *priv); >>>>> +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, >>>>> + bool enable); >>>>> +static const struct is31fl32xx_chipdef is31fl3216_cdef = { >>>>> + .channels = 16, >>>>> + .shutdown_reg = IS31FL32XX_REG_NONE, >>>>> + .pwm_update_reg = 0xB0, >>>>> + .global_control_reg = IS31FL32XX_REG_NONE, >>>>> + .reset_reg = IS31FL32XX_REG_NONE, >>>>> + .pwm_register_base = 0x10, >>>>> + .pwm_registers_reversed = true, >>>>> + .led_control_register_base = 0x01, >>>>> + .enable_bits_per_led_control_register = 8, >>>>> + .reset_func = is31fl3216_reset, >>>>> + .sw_shutdown_func = is31fl3216_software_shutdown, >>>>> +}; >>>>> + >>>>> +static int is31fl32xx_write(struct is31fl32xx_priv *priv, u8 reg, u8 val) >>>>> +{ >>>>> + int ret; >>>>> + >>>>> + dev_dbg(&priv->client->dev, "writing register 0x%02X=0x%02X", reg, val); >>>>> + >>>>> + ret = i2c_smbus_write_byte_data(priv->client, reg, val); >>>>> + if (ret) { >>>>> + dev_err(&priv->client->dev, >>>>> + "register write to 0x%02X failed (error %d)", >>>>> + reg, ret); >>>>> + } >>>>> + return ret; >>>>> +} >>>>> + >>>>> +/* >>>>> + * Custom reset function for IS31FL3216 because it does not have a RESET >>>>> + * register the way that the other IS31FL32xx chips do. We don't bother >>>>> + * writing the GPIO and animation registers, because the registers we >>>>> + * do write ensure those will have no effect. >>>>> + */ >>>>> +static int is31fl3216_reset(struct is31fl32xx_priv *priv) >>>>> +{ >>>>> + unsigned int i; >>>>> + int ret; >>>>> + >>>>> + ret = is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, >>>>> + IS31FL3216_CONFIG_SSD_ENABLE); >>>>> + if (ret) >>>>> + return ret; >>>>> + for (i = 0; i < priv->cdef->channels; i++) { >>>>> + ret = is31fl32xx_write(priv, priv->cdef->pwm_register_base+i, >>>>> + 0x00); >>>>> + if (ret) >>>>> + return ret; >>>>> + } >>>>> + ret = is31fl32xx_write(priv, priv->cdef->pwm_update_reg, 0); >>>>> + if (ret) >>>>> + return ret; >>>>> + ret = is31fl32xx_write(priv, IS31FL3216_LIGHTING_EFFECT_REG, 0x00); >>>>> + if (ret) >>>>> + return ret; >>>>> + ret = is31fl32xx_write(priv, IS31FL3216_CHANNEL_CONFIG_REG, 0x00); >>>>> + if (ret) >>>>> + return ret; >>>>> + >>>>> + return 0; >>>>> +} >>>>> + >>>>> +/* >>>>> + * Custom Software-Shutdown function for IS31FL3216 because it does not have >>>>> + * a SHUTDOWN register the way that the other IS31FL32xx chips do. >>>>> + * We don't bother doing a read/modify/write on the CONFIG register because >>>>> + * we only ever use a value of '0' for the other fields in that register. >>>>> + */ >>>>> +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, >>>>> + bool enable) >>>>> +{ >>>>> + u8 value = enable ? IS31FL3216_CONFIG_SSD_ENABLE : >>>>> + IS31FL3216_CONFIG_SSD_DISABLE; >>>>> + >>>>> + return is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, value); >>>>> +} >>>>> + >>>>> +/* >>>>> + * NOTE: A mutex is not needed in this function because: >>>>> + * - All referenced data is read-only after probe() >>>>> + * - The I2C core has a mutex on to protect the bus >>>>> + * - There are no read/modify/write operations >>>>> + * - Intervening operations between the write of the PWM register >>>>> + * and the Update register are harmless. >>>>> + * >>>>> + * Example: >>>>> + * PWM_REG_1 write 16 >>>>> + * UPDATE_REG write 0 >>>>> + * PWM_REG_2 write 128 >>>>> + * UPDATE_REG write 0 >>>>> + * vs: >>>>> + * PWM_REG_1 write 16 >>>>> + * PWM_REG_2 write 128 >>>>> + * UPDATE_REG write 0 >>>>> + * UPDATE_REG write 0 >>>>> + * are equivalent. Poking the Update register merely applies all PWM >>>>> + * register writes up to that point. >>>>> + */ >>>>> +static int is31fl32xx_brightness_set(struct led_classdev *led_cdev, >>>>> + enum led_brightness brightness) >>>>> +{ >>>>> + const struct is31fl32xx_led_data *led_data = >>>>> + container_of(led_cdev, struct is31fl32xx_led_data, cdev); >>>>> + const struct is31fl32xx_chipdef *cdef = led_data->priv->cdef; >>>>> + u8 pwm_register_offset; >>>>> + int ret; >>>>> + >>>>> + dev_dbg(led_cdev->dev, "%s: %d\n", __func__, brightness); >>>>> + >>>>> + /* NOTE: led_data->channel is 1-based */ >>>>> + if (cdef->pwm_registers_reversed) >>>>> + pwm_register_offset = cdef->channels - led_data->channel; >>>>> + else >>>>> + pwm_register_offset = led_data->channel - 1; >>>>> + >>>>> + ret = is31fl32xx_write(led_data->priv, >>>>> + cdef->pwm_register_base + pwm_register_offset, >>>>> + brightness); >>>>> + if (ret) >>>>> + return ret; >>>>> + >>>>> + return is31fl32xx_write(led_data->priv, cdef->pwm_update_reg, 0); >>>>> +} >>>>> + >>>>> +static int is31fl32xx_reset_regs(struct is31fl32xx_priv *priv) >>>>> +{ >>>>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; >>>>> + int ret; >>>>> + >>>>> + if (cdef->reset_reg != IS31FL32XX_REG_NONE) { >>>>> + ret = is31fl32xx_write(priv, cdef->reset_reg, 0); >>>>> + if (ret) >>>>> + return ret; >>>>> + } >>>>> + >>>>> + if (cdef->reset_func) >>>>> + return cdef->reset_func(priv); >>>>> + >>>>> + return 0; >>>>> +} >>>>> + >>>>> +static int is31fl32xx_software_shutdown(struct is31fl32xx_priv *priv, >>>>> + bool enable) >>>>> +{ >>>>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; >>>>> + int ret; >>>>> + >>>>> + if (cdef->shutdown_reg != IS31FL32XX_REG_NONE) { >>>>> + u8 value = enable ? IS31FL32XX_SHUTDOWN_SSD_ENABLE : >>>>> + IS31FL32XX_SHUTDOWN_SSD_DISABLE; >>>>> + ret = is31fl32xx_write(priv, cdef->shutdown_reg, value); >>>>> + if (ret) >>>>> + return ret; >>>>> + } >>>>> + >>>>> + if (cdef->sw_shutdown_func) >>>>> + return cdef->sw_shutdown_func(priv, enable); >>>> >>>> You seem to call sw_shutdown_func only here, so why should we have >>>> enable parameter in this op? >>> >>> I'm not sure if I understand the question, but I will try to answer. >>> >>> 'enable' is passed through is31fl32xx_software_shutdown to >>> cdef->sw_shutdown_func, so it can be either true or false at that >>> point. The purpose of sw_shutdown_func is to add any special behavior >>> when enabling/disabling software-shutdown mode, which is needed for >>> the 3216 because its SSD bit is in a different position and with >>> opposite polarity. >>> >>> Is it that 'enable' in that line of code makes it look like it's being >>> called with an hardcoded value rather than a variable? If so, perhaps a >>> different parameter name would make it more obvious? Or a kerneldoc >>> comment for the function to describe the parameter? >>> >>> Or have I totally missed the point of the question? >> >> Actually I should have placed this question next to >> the call to s31fl32xx_software_shutdown() in is31fl32xx_init_regs(), >> which is passed "false" in the second argument, and there is no >> other call to s31fl32xx_software_shutdown() in the driver. >> >> Having the argument makes people wondering that there is some >> use case in the driver, where "true" is passed, but it seems not >> to be the case. > > Thanks for the clarification. > > Yes, there is currently no explicit call to enable software-shutdown > mode. Since the reset state of these devices is to have software-shutdown > enabled, the only explicit operation on it that's currently needed is > to disable it. > > Reasons I can think to have the 'enable' parameter anyways include: > - It seems logical to me that an API to manipulate the software-shutdown > state should allow both enabling and disabling. > - Having a parameter for that seemed the most obvious way to go, and it > was trivial to implement. > - Alternatively having separate "enable" and "disable" functions would > duplicate most of the logic, vs the parameter being just a single > conditional. And that would also imply two function pointers in the > chipdefs, which I'd prefer to minimize. > - If anyone wanted to implement suspend/resume in the future, they would > most likely do it by enabling/disabling software-shutdown. Supporting > both enable/disable from the start should make that trivial to do. Suspend/resume callbacks are already implemented in led-class.c and related ops indirectly call brightness_set. If you want to support suspend/resume you have to set LED_CORE_SUSPENDRESUME flag. Setting brightness to 0 is equivalent to turning the LED controller in a shutdown mode, provided that all sub-LEDs are off. > - I thought the code read better with a bool parameter, vs a longer > function name. > > So nothing really critical, but mostly just my aesthetic and preference. > > Also, I expect that is31fl32xx_software_shutdown() would be inlined, so > the conditional check in there is optimized out anyways, and there is no > performance penalty. Looking at the disassembly in my ARMv7a build, both > of those have indeed happened there. Not only the size of a binary and the performance, but also code readability matters. The function is called only with false argument, so I expect that some people may submit patches optimizing this. Let's avoid the confusion. >>>>> + return 0; >>>>> +} >>>>> + >>>>> +static int is31fl32xx_init_regs(struct is31fl32xx_priv *priv) >>>>> +{ >>>>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; >>>>> + int ret; >>>>> + >>>>> + ret = is31fl32xx_reset_regs(priv); >>>>> + if (ret) >>>>> + return ret; >>>>> + >>>>> + /* >>>>> + * Set enable bit for all channels. >>>>> + * We will control state with PWM registers alone. >>>>> + */ >>>>> + if (cdef->led_control_register_base != IS31FL32XX_REG_NONE) { >>>>> + u8 value = >>>>> + GENMASK(cdef->enable_bits_per_led_control_register-1, 0); >>>>> + u8 num_regs = cdef->channels / >>>>> + cdef->enable_bits_per_led_control_register; >>>>> + int i; >>>>> + >>>>> + for (i = 0; i < num_regs; i++) { >>>>> + ret = is31fl32xx_write(priv, >>>>> + cdef->led_control_register_base+i, >>>>> + value); >>>>> + if (ret) >>>>> + return ret; >>>>> + } >>>>> + } >>>>> + >>>>> + ret = is31fl32xx_software_shutdown(priv, false); >>>>> + if (ret) >>>>> + return ret; >>>>> + >>>>> + if (cdef->global_control_reg != IS31FL32XX_REG_NONE) { >>>>> + ret = is31fl32xx_write(priv, cdef->global_control_reg, 0x00); >>>>> + if (ret) >>>>> + return ret; >>>>> + } >>>>> + >>>>> + return 0; >>>>> +} >>>>> + >>>>> +static inline size_t sizeof_is31fl32xx_priv(int num_leds) >>>>> +{ >>>>> + return sizeof(struct is31fl32xx_priv) + >>>>> + (sizeof(struct is31fl32xx_led_data) * num_leds); >>>>> +} >>>>> + >>>>> +static int is31fl32xx_parse_child_dt(const struct device *dev, >>>>> + const struct device_node *child, >>>>> + struct is31fl32xx_led_data *led_data) >>>>> +{ >>>>> + struct led_classdev *cdev = &led_data->cdev; >>>>> + int ret = 0; >>>>> + u32 reg; >>>>> + >>>>> + if (of_property_read_string(child, "label", &cdev->name)) >>>>> + cdev->name = child->name; >>>>> + >>>>> + ret = of_property_read_u32(child, "reg", ®); >>>>> + if (ret || reg < 1 || reg > led_data->priv->cdef->channels) { >>>>> + dev_err(dev, >>>>> + "Child node %s does not have a valid reg property\n", >>>>> + child->full_name); >>>>> + return -EINVAL; >>>>> + } >>>>> + led_data->channel = reg; >>>>> + >>>>> + of_property_read_string(child, "linux,default-trigger", >>>>> + &cdev->default_trigger); >>>>> + >>>>> + cdev->brightness_set_blocking = is31fl32xx_brightness_set; >>>>> + >>>>> + return 0; >>>>> +} >>>>> + >>>>> +static struct is31fl32xx_led_data *is31fl32xx_find_led_data( >>>>> + struct is31fl32xx_priv *priv, >>>>> + u8 channel) >>>>> +{ >>>>> + size_t i; >>>>> + >>>>> + for (i = 0; i < priv->num_leds; i++) { >>>>> + if (priv->leds[i].channel == channel) >>>>> + return &priv->leds[i]; >>>>> + } >>>>> + >>>>> + return NULL; >>>>> +} >>>>> + >>>>> +static int is31fl32xx_parse_dt(struct device *dev, >>>>> + struct is31fl32xx_priv *priv) >>>>> +{ >>>>> + struct device_node *child; >>>>> + int ret = 0; >>>>> + >>>>> + for_each_child_of_node(dev->of_node, child) { >>>>> + struct is31fl32xx_led_data *led_data = >>>>> + &priv->leds[priv->num_leds]; >>>>> + const struct is31fl32xx_led_data *other_led_data; >>>>> + >>>>> + led_data->priv = priv; >>>>> + >>>>> + ret = is31fl32xx_parse_child_dt(dev, child, led_data); >>>>> + if (ret) >>>>> + goto err; >>>>> + >>>>> + /* Detect if channel is already in use by another child */ >>>>> + other_led_data = is31fl32xx_find_led_data(priv, >>>>> + led_data->channel); >>>>> + if (other_led_data) { >>>>> + dev_err(dev, >>>>> + "%s and %s both attempting to use channel %d\n", >>>>> + led_data->cdev.name, >>>>> + other_led_data->cdev.name, >>>>> + led_data->channel); >>>>> + goto err; >>>>> + } >>>>> + >>>>> + ret = devm_led_classdev_register(dev, &led_data->cdev); >>>>> + if (ret) { >>>>> + dev_err(dev, "failed to register PWM led for %s: %d\n", >>>>> + led_data->cdev.name, ret); >>>>> + goto err; >>>>> + } >>>>> + >>>>> + priv->num_leds++; >>>>> + } >>>>> + >>>>> + return 0; >>>>> + >>>>> +err: >>>>> + of_node_put(child); >>>>> + return ret; >>>>> +} >>>>> + >>>>> +static const struct of_device_id of_is31fl31xx_match[] = { >>>>> + { .compatible = "issi,is31fl3236", .data = &is31fl3236_cdef, }, >>>>> + { .compatible = "issi,is31fl3235", .data = &is31fl3235_cdef, }, >>>>> + { .compatible = "issi,is31fl3218", .data = &is31fl3218_cdef, }, >>>>> + { .compatible = "issi,is31fl3216", .data = &is31fl3216_cdef, }, >>>>> + {}, >>>>> +}; >>>>> + >>>>> +MODULE_DEVICE_TABLE(of, of_is31fl31xx_match); >>>>> + >>>>> +static int is31fl32xx_probe(struct i2c_client *client, >>>>> + const struct i2c_device_id *id) >>>>> +{ >>>>> + const struct is31fl32xx_chipdef *cdef; >>>>> + const struct of_device_id *of_dev_id; >>>>> + struct device *dev = &client->dev; >>>>> + struct is31fl32xx_priv *priv; >>>>> + int count; >>>>> + int ret = 0; >>>>> + >>>>> + of_dev_id = of_match_device(of_is31fl31xx_match, dev); >>>>> + if (!of_dev_id) >>>>> + return -EINVAL; >>>>> + >>>>> + cdef = of_dev_id->data; >>>>> + >>>>> + count = of_get_child_count(dev->of_node); >>>>> + if (!count) >>>>> + return -EINVAL; >>>>> + >>>>> + priv = devm_kzalloc(dev, sizeof_is31fl32xx_priv(count), >>>>> + GFP_KERNEL); >>>>> + if (!priv) >>>>> + return -ENOMEM; >>>>> + >>>>> + priv->client = client; >>>>> + priv->cdef = cdef; >>>>> + i2c_set_clientdata(client, priv); >>>>> + >>>>> + ret = is31fl32xx_init_regs(priv); >>>>> + if (ret) >>>>> + return ret; >>>>> + >>>>> + ret = is31fl32xx_parse_dt(dev, priv); >>>>> + if (ret) >>>>> + return ret; >>>>> + >>>>> + return 0; >>>>> +} >>>>> + >>>>> +static int is31fl32xx_remove(struct i2c_client *client) >>>>> +{ >>>>> + struct is31fl32xx_priv *priv = i2c_get_clientdata(client); >>>>> + >>>>> + return is31fl32xx_reset_regs(priv); >>>>> +} >>>>> + >>>>> +/* >>>>> + * i2c-core requires that id_table be non-NULL, even though >>>>> + * it is not used for DeviceTree based instantiation. >>>>> + */ >>>>> +static const struct i2c_device_id is31fl31xx_id[] = { >>>>> + {}, >>>>> +}; >>>>> + >>>>> +MODULE_DEVICE_TABLE(i2c, is31fl31xx_id); >>>>> + >>>>> +static struct i2c_driver is31fl32xx_driver = { >>>>> + .driver = { >>>>> + .name = "is31fl32xx", >>>>> + .of_match_table = of_is31fl31xx_match, >>>>> + }, >>>>> + .probe = is31fl32xx_probe, >>>>> + .remove = is31fl32xx_remove, >>>>> + .id_table = is31fl31xx_id, >>>>> +}; >>>>> + >>>>> +module_i2c_driver(is31fl32xx_driver); >>>>> + >>>>> +MODULE_AUTHOR("David Rivshin <drivshin@allworx.com>"); >>>>> +MODULE_DESCRIPTION("ISSI IS31FL32xx LED driver"); >>>>> +MODULE_LICENSE("GPL v2"); >>>>> > > > -- Best regards, Jacek Anaszewski ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 3/4] leds: Add driver for the ISSI IS31FL32xx family of LED controllers 2016-03-04 16:01 ` Jacek Anaszewski @ 2016-03-04 19:02 ` David Rivshin (Allworx) 2016-03-04 21:39 ` Jacek Anaszewski 0 siblings, 1 reply; 28+ messages in thread From: David Rivshin (Allworx) @ 2016-03-04 19:02 UTC (permalink / raw) To: Jacek Anaszewski Cc: linux-leds, devicetree, Richard Purdie, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Stefan Wahren, linux-kernel On Fri, 04 Mar 2016 17:01:52 +0100 Jacek Anaszewski <j.anaszewski@samsung.com> wrote: > On 03/04/2016 04:05 PM, David Rivshin (Allworx) wrote: > > On Fri, 04 Mar 2016 08:54:02 +0100 > > Jacek Anaszewski <j.anaszewski@samsung.com> wrote: > > > >> On 03/04/2016 01:45 AM, David Rivshin (Allworx) wrote: > >>> On Thu, 03 Mar 2016 15:51:32 +0100 > >>> Jacek Anaszewski <j.anaszewski@samsung.com> wrote: > >>> > >>>> Hi David, > >>>> > >>>> Thanks for the update. Two remarks in the code. > >>>> > >>>> On 03/03/2016 04:01 AM, David Rivshin (Allworx) wrote: > >>>>> From: David Rivshin <drivshin@allworx.com> > >>>>> > >>>>> The IS31FL32xx family of LED controllers are I2C devices with multiple > >>>>> constant-current channels, each with independent 256-level PWM control. > >>>>> > >>>>> Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml > >>>>> > >>>>> This has been tested on the IS31FL3236 and IS31FL3216, on an ARM > >>>>> (TI am335x) platform. > >>>>> > >>>>> The programming paradigm of these devices is similar in the following > >>>>> ways: > >>>>> - All registers are 8 bit > >>>>> - All LED control registers are write-only > >>>>> - Each LED channel has a PWM register (0-255) > >>>>> - PWM register writes are shadowed until an Update register is poked > >>>>> - All have a concept of Software Shutdown, which disables output > >>>>> > >>>>> However, there are some differences in devices: > >>>>> - 3236/3235 have a separate Control register for each LED, > >>>>> (3218/3216 pack the enable bits into fewer registers) > >>>>> - 3236/3235 have a per-channel current divisor setting > >>>>> - 3236/3235 have a Global Control register that can turn off all LEDs > >>>>> - 3216 is unique in a number of ways > >>>>> - OUT9-OUT16 can be configured as GPIOs instead of LED controls > >>>>> - LEDs can be programmed with an 8-frame animation, with > >>>>> programmable delay between frames > >>>>> - LEDs can be modulated by an input audio signal > >>>>> - Max output current can be adjusted from 1/4 to 2x globally > >>>>> - Has a Configuration register instead of a Shutdown register > >>>>> > >>>>> This driver currently only supports the base PWM control function > >>>>> of these devices. The following features of these devices are not > >>>>> implemented, although it should be possible to add them in the future: > >>>>> - All devices are capable of going into a lower-power "software > >>>>> shutdown" mode. > >>>>> - The is31fl3236 and is31fl3235 can reduce the max output current > >>>>> per-channel with a divisor of 1, 2, 3, or 4. > >>>>> - The is31fl3216 can use some LED channels as GPIOs instead. > >>>>> - The is31fl3216 can animate LEDs in hardware. > >>>>> - The is31fl3216 can modulate LEDs according to an audio input. > >>>>> - The is31fl3216 can reduce/increase max output current globally. > >>>>> > >>>>> Signed-off-by: David Rivshin <drivshin@allworx.com> > >>>>> --- > >>>>> > >>>>> You may see two instances of this warning: > >>>>> "passing argument 1 of 'of_property_read_string' discards 'const' > >>>>> qualifier from pointer target type" > >>>>> That is a result of of_property_read_string() taking a non-const > >>>>> struct device_node pointer parameter. I have separately submitted a > >>>>> patch to fix that [1], and a few related functions which had the same > >>>>> issue. I'm hoping that will get into linux-next before this does, so > >>>>> that the warnings never show up there. > >>>> > >>>> Please adjust the patch so that it compiles without warnings on > >>>> current linux-next. Your patch for DT API hasn't been reviewed yet > >>>> AFICS, and I can imagine that there will be some resistance against. > >>> > >>> Since the DT API patch was just accepted by Rob [1], would it be OK > >>> to wait for the results of Stefan's testing (and any other reviews) > >>> before making a decision on this? From Stefan's note, it won't be > >>> until this weekend that he will have a chance to test, and I'm > >>> guessing the DT API patch will make its way through Rob's tree to > >>> linux-next by then. > >> > >> OK. > >> > >>> FYI, the warning workaround would be to make the second parameter to > >>> is31fl32xx_parse_child_dt() non-const. > >>> > >>> [1] https://lkml.org/lkml/2016/3/3/924 > >>> > >>>>> Changes from RFC: > >>>>> - Removed max-brightness DT property. > >>>>> - Refer to these devices as "LED controllers" in Kconfig. > >>>>> - Removed redundant last sentence from Kconfig entry > >>>>> - Removed unnecessary debug code. > >>>>> - Do not set led_classdev.brightness to 0 explicitly, as it is > >>>>> already initialized to 0 by devm_kzalloc(). > >>>>> - Used of_property_read_string() instead of of_get_property(). > >>>>> - Fail immediately on DT parsing error in a child node, rather than > >>>>> continuing on with the non-faulty ones. > >>>>> - Added additional comments for some things that might be non-obvious. > >>>>> - Added constants for the location of the SSD bit in the SHUTDOWN > >>>>> register, and the 3216's CONFIG register. > >>>>> - Added special sw_shutdown_func for the 3216 device, as that bit > >>>>> is in a different register, at a different position, and has reverse > >>>>> polarity compared to all the other devices. > >>>>> - Refactored is31fl32xx_init_regs() to separate out some logic into > >>>>> is31fl32xx_reset_regs() and is31fl32xx_software_shutdown(). > >>>>> > >>>>> [1] https://lkml.org/lkml/2016/3/2/746 > >>>>> > >>>>> drivers/leds/Kconfig | 8 + > >>>>> drivers/leds/Makefile | 1 + > >>>>> drivers/leds/leds-is31fl32xx.c | 505 +++++++++++++++++++++++++++++++++++++++++ > >>>>> 3 files changed, 514 insertions(+) > >>>>> create mode 100644 drivers/leds/leds-is31fl32xx.c > >>>>> > >>>>> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig > >>>>> index 1034696..9c63ba4 100644 > >>>>> --- a/drivers/leds/Kconfig > >>>>> +++ b/drivers/leds/Kconfig > >>>>> @@ -580,6 +580,14 @@ config LEDS_SN3218 > >>>>> This driver can also be built as a module. If so the module > >>>>> will be called leds-sn3218. > >>>>> > >>>>> +config LEDS_IS31FL32XX > >>>>> + tristate "LED support for ISSI IS31FL32XX I2C LED controller family" > >>>>> + depends on LEDS_CLASS && I2C && OF > >>>>> + help > >>>>> + Say Y here to include support for ISSI IS31FL32XX LED controllers. > >>>>> + They are I2C devices with multiple constant-current channels, each > >>>>> + with independent 256-level PWM control. > >>>>> + > >>>>> comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)" > >>>>> > >>>>> config LEDS_BLINKM > >>>>> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile > >>>>> index 89c9b6f..3fdf313 100644 > >>>>> --- a/drivers/leds/Makefile > >>>>> +++ b/drivers/leds/Makefile > >>>>> @@ -67,6 +67,7 @@ obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o > >>>>> obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o > >>>>> obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o > >>>>> obj-$(CONFIG_LEDS_SN3218) += leds-sn3218.o > >>>>> +obj-$(CONFIG_LEDS_IS31FL32XX) += leds-is31fl32xx.o > >>>>> > >>>>> # LED SPI Drivers > >>>>> obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o > >>>>> diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c > >>>>> new file mode 100644 > >>>>> index 0000000..49818f0 > >>>>> --- /dev/null > >>>>> +++ b/drivers/leds/leds-is31fl32xx.c > >>>>> @@ -0,0 +1,505 @@ > >>>>> +/* > >>>>> + * linux/drivers/leds-is31fl32xx.c > >>>>> + * > >>>>> + * Driver for ISSI IS31FL32xx family of I2C LED controllers > >>>>> + * > >>>>> + * Copyright 2015 Allworx Corp. > >>>>> + * > >>>>> + * > >>>>> + * 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. > >>>>> + * > >>>>> + * Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml > >>>>> + */ > >>>>> + > >>>>> +#include <linux/err.h> > >>>>> +#include <linux/i2c.h> > >>>>> +#include <linux/kernel.h> > >>>>> +#include <linux/leds.h> > >>>>> +#include <linux/module.h> > >>>>> +#include <linux/of_platform.h> > >>>>> + > >>>>> +/* Used to indicate a device has no such register */ > >>>>> +#define IS31FL32XX_REG_NONE 0xFF > >>>>> + > >>>>> +/* Software Shutdown bit in Shutdown Register */ > >>>>> +#define IS31FL32XX_SHUTDOWN_SSD_ENABLE 0 > >>>>> +#define IS31FL32XX_SHUTDOWN_SSD_DISABLE BIT(0) > >>>>> + > >>>>> +/* IS31FL3216 has a number of unique registers */ > >>>>> +#define IS31FL3216_CONFIG_REG 0x00 > >>>>> +#define IS31FL3216_LIGHTING_EFFECT_REG 0x03 > >>>>> +#define IS31FL3216_CHANNEL_CONFIG_REG 0x04 > >>>>> + > >>>>> +/* Software Shutdown bit in 3216 Config Register */ > >>>>> +#define IS31FL3216_CONFIG_SSD_ENABLE BIT(7) > >>>>> +#define IS31FL3216_CONFIG_SSD_DISABLE 0 > >>>>> + > >>>>> +struct is31fl32xx_priv; > >>>>> +struct is31fl32xx_led_data { > >>>>> + struct led_classdev cdev; > >>>>> + u8 channel; /* 1-based, max priv->cdef->channels */ > >>>>> + struct is31fl32xx_priv *priv; > >>>>> +}; > >>>>> + > >>>>> +struct is31fl32xx_priv { > >>>>> + const struct is31fl32xx_chipdef *cdef; > >>>>> + struct i2c_client *client; > >>>>> + unsigned int num_leds; > >>>>> + struct is31fl32xx_led_data leds[0]; > >>>>> +}; > >>>>> + > >>>>> +/** > >>>>> + * struct is31fl32xx_chipdef - chip-specific attributes > >>>>> + * @channels : Number of LED channels > >>>>> + * @shutdown_reg : address of Shutdown register (optional) > >>>>> + * @pwm_update_reg : address of PWM Update register > >>>>> + * @global_control_reg : address of Global Control register (optional) > >>>>> + * @reset_reg : address of Reset register (optional) > >>>>> + * @pwm_register_base : address of first PWM register > >>>>> + * @pwm_registers_reversed: : true if PWM registers count down instead of up > >>>>> + * @led_control_register_base : address of first LED control register (optional) > >>>>> + * @enable_bits_per_led_control_register: number of LEDs enable bits in each > >>>>> + * @reset_func: : pointer to reset function > >>>>> + * > >>>>> + * For all optional register addresses, the sentinel value %IS31FL32XX_REG_NONE > >>>>> + * indicates that this chip has no such register. > >>>>> + * > >>>>> + * If non-NULL, @reset_func will be called during probing to set all > >>>>> + * necessary registers to a known initialization state. This is needed > >>>>> + * for chips that do not have a @reset_reg. > >>>>> + * > >>>>> + * @enable_bits_per_led_control_register must be >=1 if > >>>>> + * @led_control_register_base != %IS31FL32XX_REG_NONE. > >>>>> + */ > >>>>> +struct is31fl32xx_chipdef { > >>>>> + u8 channels; > >>>>> + u8 shutdown_reg; > >>>>> + u8 pwm_update_reg; > >>>>> + u8 global_control_reg; > >>>>> + u8 reset_reg; > >>>>> + u8 pwm_register_base; > >>>>> + bool pwm_registers_reversed; > >>>>> + u8 led_control_register_base; > >>>>> + u8 enable_bits_per_led_control_register; > >>>>> + int (*reset_func)(struct is31fl32xx_priv *priv); > >>>>> + int (*sw_shutdown_func)(struct is31fl32xx_priv *priv, bool enable); > >>>>> +}; > >>>>> + > >>>>> +static const struct is31fl32xx_chipdef is31fl3236_cdef = { > >>>>> + .channels = 36, > >>>>> + .shutdown_reg = 0x00, > >>>>> + .pwm_update_reg = 0x25, > >>>>> + .global_control_reg = 0x4a, > >>>>> + .reset_reg = 0x4f, > >>>>> + .pwm_register_base = 0x01, > >>>>> + .led_control_register_base = 0x26, > >>>>> + .enable_bits_per_led_control_register = 1, > >>>>> +}; > >>>>> + > >>>>> +static const struct is31fl32xx_chipdef is31fl3235_cdef = { > >>>>> + .channels = 28, > >>>>> + .shutdown_reg = 0x00, > >>>>> + .pwm_update_reg = 0x25, > >>>>> + .global_control_reg = 0x4a, > >>>>> + .reset_reg = 0x4f, > >>>>> + .pwm_register_base = 0x05, > >>>>> + .led_control_register_base = 0x2a, > >>>>> + .enable_bits_per_led_control_register = 1, > >>>>> +}; > >>>>> + > >>>>> +static const struct is31fl32xx_chipdef is31fl3218_cdef = { > >>>>> + .channels = 18, > >>>>> + .shutdown_reg = 0x00, > >>>>> + .pwm_update_reg = 0x16, > >>>>> + .global_control_reg = IS31FL32XX_REG_NONE, > >>>>> + .reset_reg = 0x17, > >>>>> + .pwm_register_base = 0x01, > >>>>> + .led_control_register_base = 0x13, > >>>>> + .enable_bits_per_led_control_register = 6, > >>>>> +}; > >>>>> + > >>>>> +static int is31fl3216_reset(struct is31fl32xx_priv *priv); > >>>>> +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, > >>>>> + bool enable); > >>>>> +static const struct is31fl32xx_chipdef is31fl3216_cdef = { > >>>>> + .channels = 16, > >>>>> + .shutdown_reg = IS31FL32XX_REG_NONE, > >>>>> + .pwm_update_reg = 0xB0, > >>>>> + .global_control_reg = IS31FL32XX_REG_NONE, > >>>>> + .reset_reg = IS31FL32XX_REG_NONE, > >>>>> + .pwm_register_base = 0x10, > >>>>> + .pwm_registers_reversed = true, > >>>>> + .led_control_register_base = 0x01, > >>>>> + .enable_bits_per_led_control_register = 8, > >>>>> + .reset_func = is31fl3216_reset, > >>>>> + .sw_shutdown_func = is31fl3216_software_shutdown, > >>>>> +}; > >>>>> + > >>>>> +static int is31fl32xx_write(struct is31fl32xx_priv *priv, u8 reg, u8 val) > >>>>> +{ > >>>>> + int ret; > >>>>> + > >>>>> + dev_dbg(&priv->client->dev, "writing register 0x%02X=0x%02X", reg, val); > >>>>> + > >>>>> + ret = i2c_smbus_write_byte_data(priv->client, reg, val); > >>>>> + if (ret) { > >>>>> + dev_err(&priv->client->dev, > >>>>> + "register write to 0x%02X failed (error %d)", > >>>>> + reg, ret); > >>>>> + } > >>>>> + return ret; > >>>>> +} > >>>>> + > >>>>> +/* > >>>>> + * Custom reset function for IS31FL3216 because it does not have a RESET > >>>>> + * register the way that the other IS31FL32xx chips do. We don't bother > >>>>> + * writing the GPIO and animation registers, because the registers we > >>>>> + * do write ensure those will have no effect. > >>>>> + */ > >>>>> +static int is31fl3216_reset(struct is31fl32xx_priv *priv) > >>>>> +{ > >>>>> + unsigned int i; > >>>>> + int ret; > >>>>> + > >>>>> + ret = is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, > >>>>> + IS31FL3216_CONFIG_SSD_ENABLE); > >>>>> + if (ret) > >>>>> + return ret; > >>>>> + for (i = 0; i < priv->cdef->channels; i++) { > >>>>> + ret = is31fl32xx_write(priv, priv->cdef->pwm_register_base+i, > >>>>> + 0x00); > >>>>> + if (ret) > >>>>> + return ret; > >>>>> + } > >>>>> + ret = is31fl32xx_write(priv, priv->cdef->pwm_update_reg, 0); > >>>>> + if (ret) > >>>>> + return ret; > >>>>> + ret = is31fl32xx_write(priv, IS31FL3216_LIGHTING_EFFECT_REG, 0x00); > >>>>> + if (ret) > >>>>> + return ret; > >>>>> + ret = is31fl32xx_write(priv, IS31FL3216_CHANNEL_CONFIG_REG, 0x00); > >>>>> + if (ret) > >>>>> + return ret; > >>>>> + > >>>>> + return 0; > >>>>> +} > >>>>> + > >>>>> +/* > >>>>> + * Custom Software-Shutdown function for IS31FL3216 because it does not have > >>>>> + * a SHUTDOWN register the way that the other IS31FL32xx chips do. > >>>>> + * We don't bother doing a read/modify/write on the CONFIG register because > >>>>> + * we only ever use a value of '0' for the other fields in that register. > >>>>> + */ > >>>>> +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, > >>>>> + bool enable) > >>>>> +{ > >>>>> + u8 value = enable ? IS31FL3216_CONFIG_SSD_ENABLE : > >>>>> + IS31FL3216_CONFIG_SSD_DISABLE; > >>>>> + > >>>>> + return is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, value); > >>>>> +} > >>>>> + > >>>>> +/* > >>>>> + * NOTE: A mutex is not needed in this function because: > >>>>> + * - All referenced data is read-only after probe() > >>>>> + * - The I2C core has a mutex on to protect the bus > >>>>> + * - There are no read/modify/write operations > >>>>> + * - Intervening operations between the write of the PWM register > >>>>> + * and the Update register are harmless. > >>>>> + * > >>>>> + * Example: > >>>>> + * PWM_REG_1 write 16 > >>>>> + * UPDATE_REG write 0 > >>>>> + * PWM_REG_2 write 128 > >>>>> + * UPDATE_REG write 0 > >>>>> + * vs: > >>>>> + * PWM_REG_1 write 16 > >>>>> + * PWM_REG_2 write 128 > >>>>> + * UPDATE_REG write 0 > >>>>> + * UPDATE_REG write 0 > >>>>> + * are equivalent. Poking the Update register merely applies all PWM > >>>>> + * register writes up to that point. > >>>>> + */ > >>>>> +static int is31fl32xx_brightness_set(struct led_classdev *led_cdev, > >>>>> + enum led_brightness brightness) > >>>>> +{ > >>>>> + const struct is31fl32xx_led_data *led_data = > >>>>> + container_of(led_cdev, struct is31fl32xx_led_data, cdev); > >>>>> + const struct is31fl32xx_chipdef *cdef = led_data->priv->cdef; > >>>>> + u8 pwm_register_offset; > >>>>> + int ret; > >>>>> + > >>>>> + dev_dbg(led_cdev->dev, "%s: %d\n", __func__, brightness); > >>>>> + > >>>>> + /* NOTE: led_data->channel is 1-based */ > >>>>> + if (cdef->pwm_registers_reversed) > >>>>> + pwm_register_offset = cdef->channels - led_data->channel; > >>>>> + else > >>>>> + pwm_register_offset = led_data->channel - 1; > >>>>> + > >>>>> + ret = is31fl32xx_write(led_data->priv, > >>>>> + cdef->pwm_register_base + pwm_register_offset, > >>>>> + brightness); > >>>>> + if (ret) > >>>>> + return ret; > >>>>> + > >>>>> + return is31fl32xx_write(led_data->priv, cdef->pwm_update_reg, 0); > >>>>> +} > >>>>> + > >>>>> +static int is31fl32xx_reset_regs(struct is31fl32xx_priv *priv) > >>>>> +{ > >>>>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; > >>>>> + int ret; > >>>>> + > >>>>> + if (cdef->reset_reg != IS31FL32XX_REG_NONE) { > >>>>> + ret = is31fl32xx_write(priv, cdef->reset_reg, 0); > >>>>> + if (ret) > >>>>> + return ret; > >>>>> + } > >>>>> + > >>>>> + if (cdef->reset_func) > >>>>> + return cdef->reset_func(priv); > >>>>> + > >>>>> + return 0; > >>>>> +} > >>>>> + > >>>>> +static int is31fl32xx_software_shutdown(struct is31fl32xx_priv *priv, > >>>>> + bool enable) > >>>>> +{ > >>>>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; > >>>>> + int ret; > >>>>> + > >>>>> + if (cdef->shutdown_reg != IS31FL32XX_REG_NONE) { > >>>>> + u8 value = enable ? IS31FL32XX_SHUTDOWN_SSD_ENABLE : > >>>>> + IS31FL32XX_SHUTDOWN_SSD_DISABLE; > >>>>> + ret = is31fl32xx_write(priv, cdef->shutdown_reg, value); > >>>>> + if (ret) > >>>>> + return ret; > >>>>> + } > >>>>> + > >>>>> + if (cdef->sw_shutdown_func) > >>>>> + return cdef->sw_shutdown_func(priv, enable); > >>>> > >>>> You seem to call sw_shutdown_func only here, so why should we have > >>>> enable parameter in this op? > >>> > >>> I'm not sure if I understand the question, but I will try to answer. > >>> > >>> 'enable' is passed through is31fl32xx_software_shutdown to > >>> cdef->sw_shutdown_func, so it can be either true or false at that > >>> point. The purpose of sw_shutdown_func is to add any special behavior > >>> when enabling/disabling software-shutdown mode, which is needed for > >>> the 3216 because its SSD bit is in a different position and with > >>> opposite polarity. > >>> > >>> Is it that 'enable' in that line of code makes it look like it's being > >>> called with an hardcoded value rather than a variable? If so, perhaps a > >>> different parameter name would make it more obvious? Or a kerneldoc > >>> comment for the function to describe the parameter? > >>> > >>> Or have I totally missed the point of the question? > >> > >> Actually I should have placed this question next to > >> the call to s31fl32xx_software_shutdown() in is31fl32xx_init_regs(), > >> which is passed "false" in the second argument, and there is no > >> other call to s31fl32xx_software_shutdown() in the driver. > >> > >> Having the argument makes people wondering that there is some > >> use case in the driver, where "true" is passed, but it seems not > >> to be the case. > > > > Thanks for the clarification. > > > > Yes, there is currently no explicit call to enable software-shutdown > > mode. Since the reset state of these devices is to have software-shutdown > > enabled, the only explicit operation on it that's currently needed is > > to disable it. > > > > Reasons I can think to have the 'enable' parameter anyways include: > > - It seems logical to me that an API to manipulate the software-shutdown > > state should allow both enabling and disabling. > > - Having a parameter for that seemed the most obvious way to go, and it > > was trivial to implement. > > - Alternatively having separate "enable" and "disable" functions would > > duplicate most of the logic, vs the parameter being just a single > > conditional. And that would also imply two function pointers in the > > chipdefs, which I'd prefer to minimize. > > - If anyone wanted to implement suspend/resume in the future, they would > > most likely do it by enabling/disabling software-shutdown. Supporting > > both enable/disable from the start should make that trivial to do. > > Suspend/resume callbacks are already implemented in led-class.c and > related ops indirectly call brightness_set. If you want to support > suspend/resume you have to set LED_CORE_SUSPENDRESUME flag. If I understand correctly, all LED_CORE_SUSPENDRESUME will do is cause the led core to set the brightness to 0 on suspend (and reverse that on resume). I see some drivers use this flag and other do not. This brings up the question in my mind: how would a driver decide whether it is appropriate for an LED to go dark on suspend? Is that just the drivers that know the logical purpose of the LEDs they control? > Setting brightness to 0 is equivalent to turning the LED controller > in a shutdown mode, provided that all sub-LEDs are off. This is not strictly true for these devices. If someone cared very much about power usage when suspended they may want to put the LED controller into what it calls "shutdown mode" via the SSD bit. I didn't bother mainly because I have no need, and also because I wasn't sure how to even trigger a suspend in order to test an implementation. FYI, I just measured it the effect of software-shutdown even with all LEDs already off. The difference in current is about 5mA, measured at the 5V supply to a 3216 eval board. Not huge, but someone might care. > > - I thought the code read better with a bool parameter, vs a longer > > function name. > > > > So nothing really critical, but mostly just my aesthetic and preference. > > > > Also, I expect that is31fl32xx_software_shutdown() would be inlined, so > > the conditional check in there is optimized out anyways, and there is no > > performance penalty. Looking at the disassembly in my ARMv7a build, both > > of those have indeed happened there. > > Not only the size of a binary and the performance, but also code > readability matters. The function is called only with false argument, > so I expect that some people may submit patches optimizing this. > > Let's avoid the confusion. I guess we just have a difference of opinion on which way is more readable, which is OK. Unless the above explanation causes you to change your mind, I will remove the 'enable' parameter and add a "_disable" suffix to both functions. That will also leave the #define IS31FL32XX_SHUTDOWN_SSD_ENABLE 0 constant unused in the code, should that also be removed? Note that the 3216 specific constant #define IS31FL3216_CONFIG_SSD_ENABLE BIT(7) would still be used in is31fl3216_reset(). > >>>>> + return 0; > >>>>> +} > >>>>> + > >>>>> +static int is31fl32xx_init_regs(struct is31fl32xx_priv *priv) > >>>>> +{ > >>>>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; > >>>>> + int ret; > >>>>> + > >>>>> + ret = is31fl32xx_reset_regs(priv); > >>>>> + if (ret) > >>>>> + return ret; > >>>>> + > >>>>> + /* > >>>>> + * Set enable bit for all channels. > >>>>> + * We will control state with PWM registers alone. > >>>>> + */ > >>>>> + if (cdef->led_control_register_base != IS31FL32XX_REG_NONE) { > >>>>> + u8 value = > >>>>> + GENMASK(cdef->enable_bits_per_led_control_register-1, 0); > >>>>> + u8 num_regs = cdef->channels / > >>>>> + cdef->enable_bits_per_led_control_register; > >>>>> + int i; > >>>>> + > >>>>> + for (i = 0; i < num_regs; i++) { > >>>>> + ret = is31fl32xx_write(priv, > >>>>> + cdef->led_control_register_base+i, > >>>>> + value); > >>>>> + if (ret) > >>>>> + return ret; > >>>>> + } > >>>>> + } > >>>>> + > >>>>> + ret = is31fl32xx_software_shutdown(priv, false); > >>>>> + if (ret) > >>>>> + return ret; > >>>>> + > >>>>> + if (cdef->global_control_reg != IS31FL32XX_REG_NONE) { > >>>>> + ret = is31fl32xx_write(priv, cdef->global_control_reg, 0x00); > >>>>> + if (ret) > >>>>> + return ret; > >>>>> + } > >>>>> + > >>>>> + return 0; > >>>>> +} > >>>>> + > >>>>> +static inline size_t sizeof_is31fl32xx_priv(int num_leds) > >>>>> +{ > >>>>> + return sizeof(struct is31fl32xx_priv) + > >>>>> + (sizeof(struct is31fl32xx_led_data) * num_leds); > >>>>> +} > >>>>> + > >>>>> +static int is31fl32xx_parse_child_dt(const struct device *dev, > >>>>> + const struct device_node *child, > >>>>> + struct is31fl32xx_led_data *led_data) > >>>>> +{ > >>>>> + struct led_classdev *cdev = &led_data->cdev; > >>>>> + int ret = 0; > >>>>> + u32 reg; > >>>>> + > >>>>> + if (of_property_read_string(child, "label", &cdev->name)) > >>>>> + cdev->name = child->name; > >>>>> + > >>>>> + ret = of_property_read_u32(child, "reg", ®); > >>>>> + if (ret || reg < 1 || reg > led_data->priv->cdef->channels) { > >>>>> + dev_err(dev, > >>>>> + "Child node %s does not have a valid reg property\n", > >>>>> + child->full_name); > >>>>> + return -EINVAL; > >>>>> + } > >>>>> + led_data->channel = reg; > >>>>> + > >>>>> + of_property_read_string(child, "linux,default-trigger", > >>>>> + &cdev->default_trigger); > >>>>> + > >>>>> + cdev->brightness_set_blocking = is31fl32xx_brightness_set; > >>>>> + > >>>>> + return 0; > >>>>> +} > >>>>> + > >>>>> +static struct is31fl32xx_led_data *is31fl32xx_find_led_data( > >>>>> + struct is31fl32xx_priv *priv, > >>>>> + u8 channel) > >>>>> +{ > >>>>> + size_t i; > >>>>> + > >>>>> + for (i = 0; i < priv->num_leds; i++) { > >>>>> + if (priv->leds[i].channel == channel) > >>>>> + return &priv->leds[i]; > >>>>> + } > >>>>> + > >>>>> + return NULL; > >>>>> +} > >>>>> + > >>>>> +static int is31fl32xx_parse_dt(struct device *dev, > >>>>> + struct is31fl32xx_priv *priv) > >>>>> +{ > >>>>> + struct device_node *child; > >>>>> + int ret = 0; > >>>>> + > >>>>> + for_each_child_of_node(dev->of_node, child) { > >>>>> + struct is31fl32xx_led_data *led_data = > >>>>> + &priv->leds[priv->num_leds]; > >>>>> + const struct is31fl32xx_led_data *other_led_data; > >>>>> + > >>>>> + led_data->priv = priv; > >>>>> + > >>>>> + ret = is31fl32xx_parse_child_dt(dev, child, led_data); > >>>>> + if (ret) > >>>>> + goto err; > >>>>> + > >>>>> + /* Detect if channel is already in use by another child */ > >>>>> + other_led_data = is31fl32xx_find_led_data(priv, > >>>>> + led_data->channel); > >>>>> + if (other_led_data) { > >>>>> + dev_err(dev, > >>>>> + "%s and %s both attempting to use channel %d\n", > >>>>> + led_data->cdev.name, > >>>>> + other_led_data->cdev.name, > >>>>> + led_data->channel); > >>>>> + goto err; > >>>>> + } > >>>>> + > >>>>> + ret = devm_led_classdev_register(dev, &led_data->cdev); > >>>>> + if (ret) { > >>>>> + dev_err(dev, "failed to register PWM led for %s: %d\n", > >>>>> + led_data->cdev.name, ret); > >>>>> + goto err; > >>>>> + } > >>>>> + > >>>>> + priv->num_leds++; > >>>>> + } > >>>>> + > >>>>> + return 0; > >>>>> + > >>>>> +err: > >>>>> + of_node_put(child); > >>>>> + return ret; > >>>>> +} > >>>>> + > >>>>> +static const struct of_device_id of_is31fl31xx_match[] = { > >>>>> + { .compatible = "issi,is31fl3236", .data = &is31fl3236_cdef, }, > >>>>> + { .compatible = "issi,is31fl3235", .data = &is31fl3235_cdef, }, > >>>>> + { .compatible = "issi,is31fl3218", .data = &is31fl3218_cdef, }, > >>>>> + { .compatible = "issi,is31fl3216", .data = &is31fl3216_cdef, }, > >>>>> + {}, > >>>>> +}; > >>>>> + > >>>>> +MODULE_DEVICE_TABLE(of, of_is31fl31xx_match); > >>>>> + > >>>>> +static int is31fl32xx_probe(struct i2c_client *client, > >>>>> + const struct i2c_device_id *id) > >>>>> +{ > >>>>> + const struct is31fl32xx_chipdef *cdef; > >>>>> + const struct of_device_id *of_dev_id; > >>>>> + struct device *dev = &client->dev; > >>>>> + struct is31fl32xx_priv *priv; > >>>>> + int count; > >>>>> + int ret = 0; > >>>>> + > >>>>> + of_dev_id = of_match_device(of_is31fl31xx_match, dev); > >>>>> + if (!of_dev_id) > >>>>> + return -EINVAL; > >>>>> + > >>>>> + cdef = of_dev_id->data; > >>>>> + > >>>>> + count = of_get_child_count(dev->of_node); > >>>>> + if (!count) > >>>>> + return -EINVAL; > >>>>> + > >>>>> + priv = devm_kzalloc(dev, sizeof_is31fl32xx_priv(count), > >>>>> + GFP_KERNEL); > >>>>> + if (!priv) > >>>>> + return -ENOMEM; > >>>>> + > >>>>> + priv->client = client; > >>>>> + priv->cdef = cdef; > >>>>> + i2c_set_clientdata(client, priv); > >>>>> + > >>>>> + ret = is31fl32xx_init_regs(priv); > >>>>> + if (ret) > >>>>> + return ret; > >>>>> + > >>>>> + ret = is31fl32xx_parse_dt(dev, priv); > >>>>> + if (ret) > >>>>> + return ret; > >>>>> + > >>>>> + return 0; > >>>>> +} > >>>>> + > >>>>> +static int is31fl32xx_remove(struct i2c_client *client) > >>>>> +{ > >>>>> + struct is31fl32xx_priv *priv = i2c_get_clientdata(client); > >>>>> + > >>>>> + return is31fl32xx_reset_regs(priv); > >>>>> +} > >>>>> + > >>>>> +/* > >>>>> + * i2c-core requires that id_table be non-NULL, even though > >>>>> + * it is not used for DeviceTree based instantiation. > >>>>> + */ > >>>>> +static const struct i2c_device_id is31fl31xx_id[] = { > >>>>> + {}, > >>>>> +}; > >>>>> + > >>>>> +MODULE_DEVICE_TABLE(i2c, is31fl31xx_id); > >>>>> + > >>>>> +static struct i2c_driver is31fl32xx_driver = { > >>>>> + .driver = { > >>>>> + .name = "is31fl32xx", > >>>>> + .of_match_table = of_is31fl31xx_match, > >>>>> + }, > >>>>> + .probe = is31fl32xx_probe, > >>>>> + .remove = is31fl32xx_remove, > >>>>> + .id_table = is31fl31xx_id, > >>>>> +}; > >>>>> + > >>>>> +module_i2c_driver(is31fl32xx_driver); > >>>>> + > >>>>> +MODULE_AUTHOR("David Rivshin <drivshin@allworx.com>"); > >>>>> +MODULE_DESCRIPTION("ISSI IS31FL32xx LED driver"); > >>>>> +MODULE_LICENSE("GPL v2"); > >>>>> ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 3/4] leds: Add driver for the ISSI IS31FL32xx family of LED controllers 2016-03-04 19:02 ` David Rivshin (Allworx) @ 2016-03-04 21:39 ` Jacek Anaszewski 2016-03-05 5:29 ` David Rivshin (Allworx) 0 siblings, 1 reply; 28+ messages in thread From: Jacek Anaszewski @ 2016-03-04 21:39 UTC (permalink / raw) To: David Rivshin (Allworx), Jacek Anaszewski Cc: linux-leds, devicetree, Richard Purdie, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Stefan Wahren, linux-kernel On 03/04/2016 08:02 PM, David Rivshin (Allworx) wrote: > On Fri, 04 Mar 2016 17:01:52 +0100 > Jacek Anaszewski <j.anaszewski@samsung.com> wrote: > >> On 03/04/2016 04:05 PM, David Rivshin (Allworx) wrote: >>> On Fri, 04 Mar 2016 08:54:02 +0100 >>> Jacek Anaszewski <j.anaszewski@samsung.com> wrote: >>> >>>> On 03/04/2016 01:45 AM, David Rivshin (Allworx) wrote: >>>>> On Thu, 03 Mar 2016 15:51:32 +0100 >>>>> Jacek Anaszewski <j.anaszewski@samsung.com> wrote: >>>>> >>>>>> Hi David, >>>>>> >>>>>> Thanks for the update. Two remarks in the code. >>>>>> >>>>>> On 03/03/2016 04:01 AM, David Rivshin (Allworx) wrote: >>>>>>> From: David Rivshin <drivshin@allworx.com> >>>>>>> >>>>>>> The IS31FL32xx family of LED controllers are I2C devices with multiple >>>>>>> constant-current channels, each with independent 256-level PWM control. >>>>>>> >>>>>>> Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml >>>>>>> >>>>>>> This has been tested on the IS31FL3236 and IS31FL3216, on an ARM >>>>>>> (TI am335x) platform. >>>>>>> >>>>>>> The programming paradigm of these devices is similar in the following >>>>>>> ways: >>>>>>> - All registers are 8 bit >>>>>>> - All LED control registers are write-only >>>>>>> - Each LED channel has a PWM register (0-255) >>>>>>> - PWM register writes are shadowed until an Update register is poked >>>>>>> - All have a concept of Software Shutdown, which disables output >>>>>>> >>>>>>> However, there are some differences in devices: >>>>>>> - 3236/3235 have a separate Control register for each LED, >>>>>>> (3218/3216 pack the enable bits into fewer registers) >>>>>>> - 3236/3235 have a per-channel current divisor setting >>>>>>> - 3236/3235 have a Global Control register that can turn off all LEDs >>>>>>> - 3216 is unique in a number of ways >>>>>>> - OUT9-OUT16 can be configured as GPIOs instead of LED controls >>>>>>> - LEDs can be programmed with an 8-frame animation, with >>>>>>> programmable delay between frames >>>>>>> - LEDs can be modulated by an input audio signal >>>>>>> - Max output current can be adjusted from 1/4 to 2x globally >>>>>>> - Has a Configuration register instead of a Shutdown register >>>>>>> >>>>>>> This driver currently only supports the base PWM control function >>>>>>> of these devices. The following features of these devices are not >>>>>>> implemented, although it should be possible to add them in the future: >>>>>>> - All devices are capable of going into a lower-power "software >>>>>>> shutdown" mode. >>>>>>> - The is31fl3236 and is31fl3235 can reduce the max output current >>>>>>> per-channel with a divisor of 1, 2, 3, or 4. >>>>>>> - The is31fl3216 can use some LED channels as GPIOs instead. >>>>>>> - The is31fl3216 can animate LEDs in hardware. >>>>>>> - The is31fl3216 can modulate LEDs according to an audio input. >>>>>>> - The is31fl3216 can reduce/increase max output current globally. >>>>>>> >>>>>>> Signed-off-by: David Rivshin <drivshin@allworx.com> >>>>>>> --- >>>>>>> >>>>>>> You may see two instances of this warning: >>>>>>> "passing argument 1 of 'of_property_read_string' discards 'const' >>>>>>> qualifier from pointer target type" >>>>>>> That is a result of of_property_read_string() taking a non-const >>>>>>> struct device_node pointer parameter. I have separately submitted a >>>>>>> patch to fix that [1], and a few related functions which had the same >>>>>>> issue. I'm hoping that will get into linux-next before this does, so >>>>>>> that the warnings never show up there. >>>>>> >>>>>> Please adjust the patch so that it compiles without warnings on >>>>>> current linux-next. Your patch for DT API hasn't been reviewed yet >>>>>> AFICS, and I can imagine that there will be some resistance against. >>>>> >>>>> Since the DT API patch was just accepted by Rob [1], would it be OK >>>>> to wait for the results of Stefan's testing (and any other reviews) >>>>> before making a decision on this? From Stefan's note, it won't be >>>>> until this weekend that he will have a chance to test, and I'm >>>>> guessing the DT API patch will make its way through Rob's tree to >>>>> linux-next by then. >>>> >>>> OK. >>>> >>>>> FYI, the warning workaround would be to make the second parameter to >>>>> is31fl32xx_parse_child_dt() non-const. >>>>> >>>>> [1] https://lkml.org/lkml/2016/3/3/924 >>>>> >>>>>>> Changes from RFC: >>>>>>> - Removed max-brightness DT property. >>>>>>> - Refer to these devices as "LED controllers" in Kconfig. >>>>>>> - Removed redundant last sentence from Kconfig entry >>>>>>> - Removed unnecessary debug code. >>>>>>> - Do not set led_classdev.brightness to 0 explicitly, as it is >>>>>>> already initialized to 0 by devm_kzalloc(). >>>>>>> - Used of_property_read_string() instead of of_get_property(). >>>>>>> - Fail immediately on DT parsing error in a child node, rather than >>>>>>> continuing on with the non-faulty ones. >>>>>>> - Added additional comments for some things that might be non-obvious. >>>>>>> - Added constants for the location of the SSD bit in the SHUTDOWN >>>>>>> register, and the 3216's CONFIG register. >>>>>>> - Added special sw_shutdown_func for the 3216 device, as that bit >>>>>>> is in a different register, at a different position, and has reverse >>>>>>> polarity compared to all the other devices. >>>>>>> - Refactored is31fl32xx_init_regs() to separate out some logic into >>>>>>> is31fl32xx_reset_regs() and is31fl32xx_software_shutdown(). >>>>>>> >>>>>>> [1] https://lkml.org/lkml/2016/3/2/746 >>>>>>> >>>>>>> drivers/leds/Kconfig | 8 + >>>>>>> drivers/leds/Makefile | 1 + >>>>>>> drivers/leds/leds-is31fl32xx.c | 505 +++++++++++++++++++++++++++++++++++++++++ >>>>>>> 3 files changed, 514 insertions(+) >>>>>>> create mode 100644 drivers/leds/leds-is31fl32xx.c >>>>>>> >>>>>>> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig >>>>>>> index 1034696..9c63ba4 100644 >>>>>>> --- a/drivers/leds/Kconfig >>>>>>> +++ b/drivers/leds/Kconfig >>>>>>> @@ -580,6 +580,14 @@ config LEDS_SN3218 >>>>>>> This driver can also be built as a module. If so the module >>>>>>> will be called leds-sn3218. >>>>>>> >>>>>>> +config LEDS_IS31FL32XX >>>>>>> + tristate "LED support for ISSI IS31FL32XX I2C LED controller family" >>>>>>> + depends on LEDS_CLASS && I2C && OF >>>>>>> + help >>>>>>> + Say Y here to include support for ISSI IS31FL32XX LED controllers. >>>>>>> + They are I2C devices with multiple constant-current channels, each >>>>>>> + with independent 256-level PWM control. >>>>>>> + >>>>>>> comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)" >>>>>>> >>>>>>> config LEDS_BLINKM >>>>>>> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile >>>>>>> index 89c9b6f..3fdf313 100644 >>>>>>> --- a/drivers/leds/Makefile >>>>>>> +++ b/drivers/leds/Makefile >>>>>>> @@ -67,6 +67,7 @@ obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o >>>>>>> obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o >>>>>>> obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o >>>>>>> obj-$(CONFIG_LEDS_SN3218) += leds-sn3218.o >>>>>>> +obj-$(CONFIG_LEDS_IS31FL32XX) += leds-is31fl32xx.o >>>>>>> >>>>>>> # LED SPI Drivers >>>>>>> obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o >>>>>>> diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c >>>>>>> new file mode 100644 >>>>>>> index 0000000..49818f0 >>>>>>> --- /dev/null >>>>>>> +++ b/drivers/leds/leds-is31fl32xx.c >>>>>>> @@ -0,0 +1,505 @@ >>>>>>> +/* >>>>>>> + * linux/drivers/leds-is31fl32xx.c >>>>>>> + * >>>>>>> + * Driver for ISSI IS31FL32xx family of I2C LED controllers >>>>>>> + * >>>>>>> + * Copyright 2015 Allworx Corp. >>>>>>> + * >>>>>>> + * >>>>>>> + * 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. >>>>>>> + * >>>>>>> + * Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml >>>>>>> + */ >>>>>>> + >>>>>>> +#include <linux/err.h> >>>>>>> +#include <linux/i2c.h> >>>>>>> +#include <linux/kernel.h> >>>>>>> +#include <linux/leds.h> >>>>>>> +#include <linux/module.h> >>>>>>> +#include <linux/of_platform.h> >>>>>>> + >>>>>>> +/* Used to indicate a device has no such register */ >>>>>>> +#define IS31FL32XX_REG_NONE 0xFF >>>>>>> + >>>>>>> +/* Software Shutdown bit in Shutdown Register */ >>>>>>> +#define IS31FL32XX_SHUTDOWN_SSD_ENABLE 0 >>>>>>> +#define IS31FL32XX_SHUTDOWN_SSD_DISABLE BIT(0) >>>>>>> + >>>>>>> +/* IS31FL3216 has a number of unique registers */ >>>>>>> +#define IS31FL3216_CONFIG_REG 0x00 >>>>>>> +#define IS31FL3216_LIGHTING_EFFECT_REG 0x03 >>>>>>> +#define IS31FL3216_CHANNEL_CONFIG_REG 0x04 >>>>>>> + >>>>>>> +/* Software Shutdown bit in 3216 Config Register */ >>>>>>> +#define IS31FL3216_CONFIG_SSD_ENABLE BIT(7) >>>>>>> +#define IS31FL3216_CONFIG_SSD_DISABLE 0 >>>>>>> + >>>>>>> +struct is31fl32xx_priv; >>>>>>> +struct is31fl32xx_led_data { >>>>>>> + struct led_classdev cdev; >>>>>>> + u8 channel; /* 1-based, max priv->cdef->channels */ >>>>>>> + struct is31fl32xx_priv *priv; >>>>>>> +}; >>>>>>> + >>>>>>> +struct is31fl32xx_priv { >>>>>>> + const struct is31fl32xx_chipdef *cdef; >>>>>>> + struct i2c_client *client; >>>>>>> + unsigned int num_leds; >>>>>>> + struct is31fl32xx_led_data leds[0]; >>>>>>> +}; >>>>>>> + >>>>>>> +/** >>>>>>> + * struct is31fl32xx_chipdef - chip-specific attributes >>>>>>> + * @channels : Number of LED channels >>>>>>> + * @shutdown_reg : address of Shutdown register (optional) >>>>>>> + * @pwm_update_reg : address of PWM Update register >>>>>>> + * @global_control_reg : address of Global Control register (optional) >>>>>>> + * @reset_reg : address of Reset register (optional) >>>>>>> + * @pwm_register_base : address of first PWM register >>>>>>> + * @pwm_registers_reversed: : true if PWM registers count down instead of up >>>>>>> + * @led_control_register_base : address of first LED control register (optional) >>>>>>> + * @enable_bits_per_led_control_register: number of LEDs enable bits in each >>>>>>> + * @reset_func: : pointer to reset function >>>>>>> + * >>>>>>> + * For all optional register addresses, the sentinel value %IS31FL32XX_REG_NONE >>>>>>> + * indicates that this chip has no such register. >>>>>>> + * >>>>>>> + * If non-NULL, @reset_func will be called during probing to set all >>>>>>> + * necessary registers to a known initialization state. This is needed >>>>>>> + * for chips that do not have a @reset_reg. >>>>>>> + * >>>>>>> + * @enable_bits_per_led_control_register must be >=1 if >>>>>>> + * @led_control_register_base != %IS31FL32XX_REG_NONE. >>>>>>> + */ >>>>>>> +struct is31fl32xx_chipdef { >>>>>>> + u8 channels; >>>>>>> + u8 shutdown_reg; >>>>>>> + u8 pwm_update_reg; >>>>>>> + u8 global_control_reg; >>>>>>> + u8 reset_reg; >>>>>>> + u8 pwm_register_base; >>>>>>> + bool pwm_registers_reversed; >>>>>>> + u8 led_control_register_base; >>>>>>> + u8 enable_bits_per_led_control_register; >>>>>>> + int (*reset_func)(struct is31fl32xx_priv *priv); >>>>>>> + int (*sw_shutdown_func)(struct is31fl32xx_priv *priv, bool enable); >>>>>>> +}; >>>>>>> + >>>>>>> +static const struct is31fl32xx_chipdef is31fl3236_cdef = { >>>>>>> + .channels = 36, >>>>>>> + .shutdown_reg = 0x00, >>>>>>> + .pwm_update_reg = 0x25, >>>>>>> + .global_control_reg = 0x4a, >>>>>>> + .reset_reg = 0x4f, >>>>>>> + .pwm_register_base = 0x01, >>>>>>> + .led_control_register_base = 0x26, >>>>>>> + .enable_bits_per_led_control_register = 1, >>>>>>> +}; >>>>>>> + >>>>>>> +static const struct is31fl32xx_chipdef is31fl3235_cdef = { >>>>>>> + .channels = 28, >>>>>>> + .shutdown_reg = 0x00, >>>>>>> + .pwm_update_reg = 0x25, >>>>>>> + .global_control_reg = 0x4a, >>>>>>> + .reset_reg = 0x4f, >>>>>>> + .pwm_register_base = 0x05, >>>>>>> + .led_control_register_base = 0x2a, >>>>>>> + .enable_bits_per_led_control_register = 1, >>>>>>> +}; >>>>>>> + >>>>>>> +static const struct is31fl32xx_chipdef is31fl3218_cdef = { >>>>>>> + .channels = 18, >>>>>>> + .shutdown_reg = 0x00, >>>>>>> + .pwm_update_reg = 0x16, >>>>>>> + .global_control_reg = IS31FL32XX_REG_NONE, >>>>>>> + .reset_reg = 0x17, >>>>>>> + .pwm_register_base = 0x01, >>>>>>> + .led_control_register_base = 0x13, >>>>>>> + .enable_bits_per_led_control_register = 6, >>>>>>> +}; >>>>>>> + >>>>>>> +static int is31fl3216_reset(struct is31fl32xx_priv *priv); >>>>>>> +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, >>>>>>> + bool enable); >>>>>>> +static const struct is31fl32xx_chipdef is31fl3216_cdef = { >>>>>>> + .channels = 16, >>>>>>> + .shutdown_reg = IS31FL32XX_REG_NONE, >>>>>>> + .pwm_update_reg = 0xB0, >>>>>>> + .global_control_reg = IS31FL32XX_REG_NONE, >>>>>>> + .reset_reg = IS31FL32XX_REG_NONE, >>>>>>> + .pwm_register_base = 0x10, >>>>>>> + .pwm_registers_reversed = true, >>>>>>> + .led_control_register_base = 0x01, >>>>>>> + .enable_bits_per_led_control_register = 8, >>>>>>> + .reset_func = is31fl3216_reset, >>>>>>> + .sw_shutdown_func = is31fl3216_software_shutdown, >>>>>>> +}; >>>>>>> + >>>>>>> +static int is31fl32xx_write(struct is31fl32xx_priv *priv, u8 reg, u8 val) >>>>>>> +{ >>>>>>> + int ret; >>>>>>> + >>>>>>> + dev_dbg(&priv->client->dev, "writing register 0x%02X=0x%02X", reg, val); >>>>>>> + >>>>>>> + ret = i2c_smbus_write_byte_data(priv->client, reg, val); >>>>>>> + if (ret) { >>>>>>> + dev_err(&priv->client->dev, >>>>>>> + "register write to 0x%02X failed (error %d)", >>>>>>> + reg, ret); >>>>>>> + } >>>>>>> + return ret; >>>>>>> +} >>>>>>> + >>>>>>> +/* >>>>>>> + * Custom reset function for IS31FL3216 because it does not have a RESET >>>>>>> + * register the way that the other IS31FL32xx chips do. We don't bother >>>>>>> + * writing the GPIO and animation registers, because the registers we >>>>>>> + * do write ensure those will have no effect. >>>>>>> + */ >>>>>>> +static int is31fl3216_reset(struct is31fl32xx_priv *priv) >>>>>>> +{ >>>>>>> + unsigned int i; >>>>>>> + int ret; >>>>>>> + >>>>>>> + ret = is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, >>>>>>> + IS31FL3216_CONFIG_SSD_ENABLE); >>>>>>> + if (ret) >>>>>>> + return ret; >>>>>>> + for (i = 0; i < priv->cdef->channels; i++) { >>>>>>> + ret = is31fl32xx_write(priv, priv->cdef->pwm_register_base+i, >>>>>>> + 0x00); >>>>>>> + if (ret) >>>>>>> + return ret; >>>>>>> + } >>>>>>> + ret = is31fl32xx_write(priv, priv->cdef->pwm_update_reg, 0); >>>>>>> + if (ret) >>>>>>> + return ret; >>>>>>> + ret = is31fl32xx_write(priv, IS31FL3216_LIGHTING_EFFECT_REG, 0x00); >>>>>>> + if (ret) >>>>>>> + return ret; >>>>>>> + ret = is31fl32xx_write(priv, IS31FL3216_CHANNEL_CONFIG_REG, 0x00); >>>>>>> + if (ret) >>>>>>> + return ret; >>>>>>> + >>>>>>> + return 0; >>>>>>> +} >>>>>>> + >>>>>>> +/* >>>>>>> + * Custom Software-Shutdown function for IS31FL3216 because it does not have >>>>>>> + * a SHUTDOWN register the way that the other IS31FL32xx chips do. >>>>>>> + * We don't bother doing a read/modify/write on the CONFIG register because >>>>>>> + * we only ever use a value of '0' for the other fields in that register. >>>>>>> + */ >>>>>>> +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, >>>>>>> + bool enable) >>>>>>> +{ >>>>>>> + u8 value = enable ? IS31FL3216_CONFIG_SSD_ENABLE : >>>>>>> + IS31FL3216_CONFIG_SSD_DISABLE; >>>>>>> + >>>>>>> + return is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, value); >>>>>>> +} >>>>>>> + >>>>>>> +/* >>>>>>> + * NOTE: A mutex is not needed in this function because: >>>>>>> + * - All referenced data is read-only after probe() >>>>>>> + * - The I2C core has a mutex on to protect the bus >>>>>>> + * - There are no read/modify/write operations >>>>>>> + * - Intervening operations between the write of the PWM register >>>>>>> + * and the Update register are harmless. >>>>>>> + * >>>>>>> + * Example: >>>>>>> + * PWM_REG_1 write 16 >>>>>>> + * UPDATE_REG write 0 >>>>>>> + * PWM_REG_2 write 128 >>>>>>> + * UPDATE_REG write 0 >>>>>>> + * vs: >>>>>>> + * PWM_REG_1 write 16 >>>>>>> + * PWM_REG_2 write 128 >>>>>>> + * UPDATE_REG write 0 >>>>>>> + * UPDATE_REG write 0 >>>>>>> + * are equivalent. Poking the Update register merely applies all PWM >>>>>>> + * register writes up to that point. >>>>>>> + */ >>>>>>> +static int is31fl32xx_brightness_set(struct led_classdev *led_cdev, >>>>>>> + enum led_brightness brightness) >>>>>>> +{ >>>>>>> + const struct is31fl32xx_led_data *led_data = >>>>>>> + container_of(led_cdev, struct is31fl32xx_led_data, cdev); >>>>>>> + const struct is31fl32xx_chipdef *cdef = led_data->priv->cdef; >>>>>>> + u8 pwm_register_offset; >>>>>>> + int ret; >>>>>>> + >>>>>>> + dev_dbg(led_cdev->dev, "%s: %d\n", __func__, brightness); >>>>>>> + >>>>>>> + /* NOTE: led_data->channel is 1-based */ >>>>>>> + if (cdef->pwm_registers_reversed) >>>>>>> + pwm_register_offset = cdef->channels - led_data->channel; >>>>>>> + else >>>>>>> + pwm_register_offset = led_data->channel - 1; >>>>>>> + >>>>>>> + ret = is31fl32xx_write(led_data->priv, >>>>>>> + cdef->pwm_register_base + pwm_register_offset, >>>>>>> + brightness); >>>>>>> + if (ret) >>>>>>> + return ret; >>>>>>> + >>>>>>> + return is31fl32xx_write(led_data->priv, cdef->pwm_update_reg, 0); >>>>>>> +} >>>>>>> + >>>>>>> +static int is31fl32xx_reset_regs(struct is31fl32xx_priv *priv) >>>>>>> +{ >>>>>>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; >>>>>>> + int ret; >>>>>>> + >>>>>>> + if (cdef->reset_reg != IS31FL32XX_REG_NONE) { >>>>>>> + ret = is31fl32xx_write(priv, cdef->reset_reg, 0); >>>>>>> + if (ret) >>>>>>> + return ret; >>>>>>> + } >>>>>>> + >>>>>>> + if (cdef->reset_func) >>>>>>> + return cdef->reset_func(priv); >>>>>>> + >>>>>>> + return 0; >>>>>>> +} >>>>>>> + >>>>>>> +static int is31fl32xx_software_shutdown(struct is31fl32xx_priv *priv, >>>>>>> + bool enable) >>>>>>> +{ >>>>>>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; >>>>>>> + int ret; >>>>>>> + >>>>>>> + if (cdef->shutdown_reg != IS31FL32XX_REG_NONE) { >>>>>>> + u8 value = enable ? IS31FL32XX_SHUTDOWN_SSD_ENABLE : >>>>>>> + IS31FL32XX_SHUTDOWN_SSD_DISABLE; >>>>>>> + ret = is31fl32xx_write(priv, cdef->shutdown_reg, value); >>>>>>> + if (ret) >>>>>>> + return ret; >>>>>>> + } >>>>>>> + >>>>>>> + if (cdef->sw_shutdown_func) >>>>>>> + return cdef->sw_shutdown_func(priv, enable); >>>>>> >>>>>> You seem to call sw_shutdown_func only here, so why should we have >>>>>> enable parameter in this op? >>>>> >>>>> I'm not sure if I understand the question, but I will try to answer. >>>>> >>>>> 'enable' is passed through is31fl32xx_software_shutdown to >>>>> cdef->sw_shutdown_func, so it can be either true or false at that >>>>> point. The purpose of sw_shutdown_func is to add any special behavior >>>>> when enabling/disabling software-shutdown mode, which is needed for >>>>> the 3216 because its SSD bit is in a different position and with >>>>> opposite polarity. >>>>> >>>>> Is it that 'enable' in that line of code makes it look like it's being >>>>> called with an hardcoded value rather than a variable? If so, perhaps a >>>>> different parameter name would make it more obvious? Or a kerneldoc >>>>> comment for the function to describe the parameter? >>>>> >>>>> Or have I totally missed the point of the question? >>>> >>>> Actually I should have placed this question next to >>>> the call to s31fl32xx_software_shutdown() in is31fl32xx_init_regs(), >>>> which is passed "false" in the second argument, and there is no >>>> other call to s31fl32xx_software_shutdown() in the driver. >>>> >>>> Having the argument makes people wondering that there is some >>>> use case in the driver, where "true" is passed, but it seems not >>>> to be the case. >>> >>> Thanks for the clarification. >>> >>> Yes, there is currently no explicit call to enable software-shutdown >>> mode. Since the reset state of these devices is to have software-shutdown >>> enabled, the only explicit operation on it that's currently needed is >>> to disable it. >>> >>> Reasons I can think to have the 'enable' parameter anyways include: >>> - It seems logical to me that an API to manipulate the software-shutdown >>> state should allow both enabling and disabling. >>> - Having a parameter for that seemed the most obvious way to go, and it >>> was trivial to implement. >>> - Alternatively having separate "enable" and "disable" functions would >>> duplicate most of the logic, vs the parameter being just a single >>> conditional. And that would also imply two function pointers in the >>> chipdefs, which I'd prefer to minimize. >>> - If anyone wanted to implement suspend/resume in the future, they would >>> most likely do it by enabling/disabling software-shutdown. Supporting >>> both enable/disable from the start should make that trivial to do. >> >> Suspend/resume callbacks are already implemented in led-class.c and >> related ops indirectly call brightness_set. If you want to support >> suspend/resume you have to set LED_CORE_SUSPENDRESUME flag. > > If I understand correctly, all LED_CORE_SUSPENDRESUME will do is cause > the led core to set the brightness to 0 on suspend (and reverse that > on resume). I see some drivers use this flag and other do not. > This brings up the question in my mind: how would a driver decide > whether it is appropriate for an LED to go dark on suspend? Is that > just the drivers that know the logical purpose of the LEDs they control? There is a room for improvement here. Possibly a new LED class sysfs attribute could be of help in determining that. >> Setting brightness to 0 is equivalent to turning the LED controller >> in a shutdown mode, provided that all sub-LEDs are off. > > This is not strictly true for these devices. If someone cared very much > about power usage when suspended they may want to put the LED controller > into what it calls "shutdown mode" via the SSD bit. I didn't bother mainly > because I have no need, and also because I wasn't sure how to even trigger > a suspend in order to test an implementation. I meant that LED class driver should put the device in a software shutdown mode after last sub-LED is turned off. > FYI, I just measured it the effect of software-shutdown even with all LEDs > already off. The difference in current is about 5mA, measured at the 5V > supply to a 3216 eval board. Not huge, but someone might care. This can be vital difference for some use cases. You could count the number of currently active sub-LEDs and put the controller in a software shutdown mode in case the value is 0. >>> - I thought the code read better with a bool parameter, vs a longer >>> function name. >>> >>> So nothing really critical, but mostly just my aesthetic and preference. >>> >>> Also, I expect that is31fl32xx_software_shutdown() would be inlined, so >>> the conditional check in there is optimized out anyways, and there is no >>> performance penalty. Looking at the disassembly in my ARMv7a build, both >>> of those have indeed happened there. >> >> Not only the size of a binary and the performance, but also code >> readability matters. The function is called only with false argument, >> so I expect that some people may submit patches optimizing this. >> >> Let's avoid the confusion. > > I guess we just have a difference of opinion on which way is more > readable, which is OK. Unless the above explanation causes you to > change your mind, I will remove the 'enable' parameter and add a > "_disable" suffix to both functions. That will also leave the > #define IS31FL32XX_SHUTDOWN_SSD_ENABLE 0 > constant unused in the code, should that also be removed? Note that > the 3216 specific constant > #define IS31FL3216_CONFIG_SSD_ENABLE BIT(7) > would still be used in is31fl3216_reset(). Current version of the function would be required for enabling shutting down the controller from brightness_set op when the count of active sub-LEDs drops to 0. >>>>>>> + return 0; >>>>>>> +} >>>>>>> + >>>>>>> +static int is31fl32xx_init_regs(struct is31fl32xx_priv *priv) >>>>>>> +{ >>>>>>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; >>>>>>> + int ret; >>>>>>> + >>>>>>> + ret = is31fl32xx_reset_regs(priv); >>>>>>> + if (ret) >>>>>>> + return ret; >>>>>>> + >>>>>>> + /* >>>>>>> + * Set enable bit for all channels. >>>>>>> + * We will control state with PWM registers alone. >>>>>>> + */ >>>>>>> + if (cdef->led_control_register_base != IS31FL32XX_REG_NONE) { >>>>>>> + u8 value = >>>>>>> + GENMASK(cdef->enable_bits_per_led_control_register-1, 0); >>>>>>> + u8 num_regs = cdef->channels / >>>>>>> + cdef->enable_bits_per_led_control_register; >>>>>>> + int i; >>>>>>> + >>>>>>> + for (i = 0; i < num_regs; i++) { >>>>>>> + ret = is31fl32xx_write(priv, >>>>>>> + cdef->led_control_register_base+i, >>>>>>> + value); >>>>>>> + if (ret) >>>>>>> + return ret; >>>>>>> + } >>>>>>> + } >>>>>>> + >>>>>>> + ret = is31fl32xx_software_shutdown(priv, false); >>>>>>> + if (ret) >>>>>>> + return ret; >>>>>>> + >>>>>>> + if (cdef->global_control_reg != IS31FL32XX_REG_NONE) { >>>>>>> + ret = is31fl32xx_write(priv, cdef->global_control_reg, 0x00); >>>>>>> + if (ret) >>>>>>> + return ret; >>>>>>> + } >>>>>>> + >>>>>>> + return 0; >>>>>>> +} >>>>>>> + >>>>>>> +static inline size_t sizeof_is31fl32xx_priv(int num_leds) >>>>>>> +{ >>>>>>> + return sizeof(struct is31fl32xx_priv) + >>>>>>> + (sizeof(struct is31fl32xx_led_data) * num_leds); >>>>>>> +} >>>>>>> + >>>>>>> +static int is31fl32xx_parse_child_dt(const struct device *dev, >>>>>>> + const struct device_node *child, >>>>>>> + struct is31fl32xx_led_data *led_data) >>>>>>> +{ >>>>>>> + struct led_classdev *cdev = &led_data->cdev; >>>>>>> + int ret = 0; >>>>>>> + u32 reg; >>>>>>> + >>>>>>> + if (of_property_read_string(child, "label", &cdev->name)) >>>>>>> + cdev->name = child->name; >>>>>>> + >>>>>>> + ret = of_property_read_u32(child, "reg", ®); >>>>>>> + if (ret || reg < 1 || reg > led_data->priv->cdef->channels) { >>>>>>> + dev_err(dev, >>>>>>> + "Child node %s does not have a valid reg property\n", >>>>>>> + child->full_name); >>>>>>> + return -EINVAL; >>>>>>> + } >>>>>>> + led_data->channel = reg; >>>>>>> + >>>>>>> + of_property_read_string(child, "linux,default-trigger", >>>>>>> + &cdev->default_trigger); >>>>>>> + >>>>>>> + cdev->brightness_set_blocking = is31fl32xx_brightness_set; >>>>>>> + >>>>>>> + return 0; >>>>>>> +} >>>>>>> + >>>>>>> +static struct is31fl32xx_led_data *is31fl32xx_find_led_data( >>>>>>> + struct is31fl32xx_priv *priv, >>>>>>> + u8 channel) >>>>>>> +{ >>>>>>> + size_t i; >>>>>>> + >>>>>>> + for (i = 0; i < priv->num_leds; i++) { >>>>>>> + if (priv->leds[i].channel == channel) >>>>>>> + return &priv->leds[i]; >>>>>>> + } >>>>>>> + >>>>>>> + return NULL; >>>>>>> +} >>>>>>> + >>>>>>> +static int is31fl32xx_parse_dt(struct device *dev, >>>>>>> + struct is31fl32xx_priv *priv) >>>>>>> +{ >>>>>>> + struct device_node *child; >>>>>>> + int ret = 0; >>>>>>> + >>>>>>> + for_each_child_of_node(dev->of_node, child) { >>>>>>> + struct is31fl32xx_led_data *led_data = >>>>>>> + &priv->leds[priv->num_leds]; >>>>>>> + const struct is31fl32xx_led_data *other_led_data; >>>>>>> + >>>>>>> + led_data->priv = priv; >>>>>>> + >>>>>>> + ret = is31fl32xx_parse_child_dt(dev, child, led_data); >>>>>>> + if (ret) >>>>>>> + goto err; >>>>>>> + >>>>>>> + /* Detect if channel is already in use by another child */ >>>>>>> + other_led_data = is31fl32xx_find_led_data(priv, >>>>>>> + led_data->channel); >>>>>>> + if (other_led_data) { >>>>>>> + dev_err(dev, >>>>>>> + "%s and %s both attempting to use channel %d\n", >>>>>>> + led_data->cdev.name, >>>>>>> + other_led_data->cdev.name, >>>>>>> + led_data->channel); >>>>>>> + goto err; >>>>>>> + } >>>>>>> + >>>>>>> + ret = devm_led_classdev_register(dev, &led_data->cdev); >>>>>>> + if (ret) { >>>>>>> + dev_err(dev, "failed to register PWM led for %s: %d\n", >>>>>>> + led_data->cdev.name, ret); >>>>>>> + goto err; >>>>>>> + } >>>>>>> + >>>>>>> + priv->num_leds++; >>>>>>> + } >>>>>>> + >>>>>>> + return 0; >>>>>>> + >>>>>>> +err: >>>>>>> + of_node_put(child); >>>>>>> + return ret; >>>>>>> +} >>>>>>> + >>>>>>> +static const struct of_device_id of_is31fl31xx_match[] = { >>>>>>> + { .compatible = "issi,is31fl3236", .data = &is31fl3236_cdef, }, >>>>>>> + { .compatible = "issi,is31fl3235", .data = &is31fl3235_cdef, }, >>>>>>> + { .compatible = "issi,is31fl3218", .data = &is31fl3218_cdef, }, >>>>>>> + { .compatible = "issi,is31fl3216", .data = &is31fl3216_cdef, }, >>>>>>> + {}, >>>>>>> +}; >>>>>>> + >>>>>>> +MODULE_DEVICE_TABLE(of, of_is31fl31xx_match); >>>>>>> + >>>>>>> +static int is31fl32xx_probe(struct i2c_client *client, >>>>>>> + const struct i2c_device_id *id) >>>>>>> +{ >>>>>>> + const struct is31fl32xx_chipdef *cdef; >>>>>>> + const struct of_device_id *of_dev_id; >>>>>>> + struct device *dev = &client->dev; >>>>>>> + struct is31fl32xx_priv *priv; >>>>>>> + int count; >>>>>>> + int ret = 0; >>>>>>> + >>>>>>> + of_dev_id = of_match_device(of_is31fl31xx_match, dev); >>>>>>> + if (!of_dev_id) >>>>>>> + return -EINVAL; >>>>>>> + >>>>>>> + cdef = of_dev_id->data; >>>>>>> + >>>>>>> + count = of_get_child_count(dev->of_node); >>>>>>> + if (!count) >>>>>>> + return -EINVAL; >>>>>>> + >>>>>>> + priv = devm_kzalloc(dev, sizeof_is31fl32xx_priv(count), >>>>>>> + GFP_KERNEL); >>>>>>> + if (!priv) >>>>>>> + return -ENOMEM; >>>>>>> + >>>>>>> + priv->client = client; >>>>>>> + priv->cdef = cdef; >>>>>>> + i2c_set_clientdata(client, priv); >>>>>>> + >>>>>>> + ret = is31fl32xx_init_regs(priv); >>>>>>> + if (ret) >>>>>>> + return ret; >>>>>>> + >>>>>>> + ret = is31fl32xx_parse_dt(dev, priv); >>>>>>> + if (ret) >>>>>>> + return ret; >>>>>>> + >>>>>>> + return 0; >>>>>>> +} >>>>>>> + >>>>>>> +static int is31fl32xx_remove(struct i2c_client *client) >>>>>>> +{ >>>>>>> + struct is31fl32xx_priv *priv = i2c_get_clientdata(client); >>>>>>> + >>>>>>> + return is31fl32xx_reset_regs(priv); >>>>>>> +} >>>>>>> + >>>>>>> +/* >>>>>>> + * i2c-core requires that id_table be non-NULL, even though >>>>>>> + * it is not used for DeviceTree based instantiation. >>>>>>> + */ >>>>>>> +static const struct i2c_device_id is31fl31xx_id[] = { >>>>>>> + {}, >>>>>>> +}; >>>>>>> + >>>>>>> +MODULE_DEVICE_TABLE(i2c, is31fl31xx_id); >>>>>>> + >>>>>>> +static struct i2c_driver is31fl32xx_driver = { >>>>>>> + .driver = { >>>>>>> + .name = "is31fl32xx", >>>>>>> + .of_match_table = of_is31fl31xx_match, >>>>>>> + }, >>>>>>> + .probe = is31fl32xx_probe, >>>>>>> + .remove = is31fl32xx_remove, >>>>>>> + .id_table = is31fl31xx_id, >>>>>>> +}; >>>>>>> + >>>>>>> +module_i2c_driver(is31fl32xx_driver); >>>>>>> + >>>>>>> +MODULE_AUTHOR("David Rivshin <drivshin@allworx.com>"); >>>>>>> +MODULE_DESCRIPTION("ISSI IS31FL32xx LED driver"); >>>>>>> +MODULE_LICENSE("GPL v2"); >>>>>>> > > -- > To unsubscribe from this list: send the line "unsubscribe linux-leds" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > -- Best Regards, Jacek Anaszewski ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 3/4] leds: Add driver for the ISSI IS31FL32xx family of LED controllers 2016-03-04 21:39 ` Jacek Anaszewski @ 2016-03-05 5:29 ` David Rivshin (Allworx) 2016-03-05 11:37 ` Jacek Anaszewski 0 siblings, 1 reply; 28+ messages in thread From: David Rivshin (Allworx) @ 2016-03-05 5:29 UTC (permalink / raw) To: Jacek Anaszewski Cc: Jacek Anaszewski, linux-leds, devicetree, Richard Purdie, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Stefan Wahren, linux-kernel On Fri, 4 Mar 2016 22:39:06 +0100 Jacek Anaszewski <jacek.anaszewski@gmail.com> wrote: > On 03/04/2016 08:02 PM, David Rivshin (Allworx) wrote: > > On Fri, 04 Mar 2016 17:01:52 +0100 > > Jacek Anaszewski <j.anaszewski@samsung.com> wrote: > > > >> On 03/04/2016 04:05 PM, David Rivshin (Allworx) wrote: > >>> On Fri, 04 Mar 2016 08:54:02 +0100 > >>> Jacek Anaszewski <j.anaszewski@samsung.com> wrote: > >>> > >>>> On 03/04/2016 01:45 AM, David Rivshin (Allworx) wrote: > >>>>> On Thu, 03 Mar 2016 15:51:32 +0100 > >>>>> Jacek Anaszewski <j.anaszewski@samsung.com> wrote: > >>>>> > >>>>>> Hi David, > >>>>>> > >>>>>> Thanks for the update. Two remarks in the code. > >>>>>> > >>>>>> On 03/03/2016 04:01 AM, David Rivshin (Allworx) wrote: > >>>>>>> From: David Rivshin <drivshin@allworx.com> > >>>>>>> > >>>>>>> The IS31FL32xx family of LED controllers are I2C devices with multiple > >>>>>>> constant-current channels, each with independent 256-level PWM control. > >>>>>>> > >>>>>>> Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml > >>>>>>> > >>>>>>> This has been tested on the IS31FL3236 and IS31FL3216, on an ARM > >>>>>>> (TI am335x) platform. > >>>>>>> > >>>>>>> The programming paradigm of these devices is similar in the following > >>>>>>> ways: > >>>>>>> - All registers are 8 bit > >>>>>>> - All LED control registers are write-only > >>>>>>> - Each LED channel has a PWM register (0-255) > >>>>>>> - PWM register writes are shadowed until an Update register is poked > >>>>>>> - All have a concept of Software Shutdown, which disables output > >>>>>>> > >>>>>>> However, there are some differences in devices: > >>>>>>> - 3236/3235 have a separate Control register for each LED, > >>>>>>> (3218/3216 pack the enable bits into fewer registers) > >>>>>>> - 3236/3235 have a per-channel current divisor setting > >>>>>>> - 3236/3235 have a Global Control register that can turn off all LEDs > >>>>>>> - 3216 is unique in a number of ways > >>>>>>> - OUT9-OUT16 can be configured as GPIOs instead of LED controls > >>>>>>> - LEDs can be programmed with an 8-frame animation, with > >>>>>>> programmable delay between frames > >>>>>>> - LEDs can be modulated by an input audio signal > >>>>>>> - Max output current can be adjusted from 1/4 to 2x globally > >>>>>>> - Has a Configuration register instead of a Shutdown register > >>>>>>> > >>>>>>> This driver currently only supports the base PWM control function > >>>>>>> of these devices. The following features of these devices are not > >>>>>>> implemented, although it should be possible to add them in the future: > >>>>>>> - All devices are capable of going into a lower-power "software > >>>>>>> shutdown" mode. > >>>>>>> - The is31fl3236 and is31fl3235 can reduce the max output current > >>>>>>> per-channel with a divisor of 1, 2, 3, or 4. > >>>>>>> - The is31fl3216 can use some LED channels as GPIOs instead. > >>>>>>> - The is31fl3216 can animate LEDs in hardware. > >>>>>>> - The is31fl3216 can modulate LEDs according to an audio input. > >>>>>>> - The is31fl3216 can reduce/increase max output current globally. > >>>>>>> > >>>>>>> Signed-off-by: David Rivshin <drivshin@allworx.com> > >>>>>>> --- > >>>>>>> > >>>>>>> You may see two instances of this warning: > >>>>>>> "passing argument 1 of 'of_property_read_string' discards 'const' > >>>>>>> qualifier from pointer target type" > >>>>>>> That is a result of of_property_read_string() taking a non-const > >>>>>>> struct device_node pointer parameter. I have separately submitted a > >>>>>>> patch to fix that [1], and a few related functions which had the same > >>>>>>> issue. I'm hoping that will get into linux-next before this does, so > >>>>>>> that the warnings never show up there. > >>>>>> > >>>>>> Please adjust the patch so that it compiles without warnings on > >>>>>> current linux-next. Your patch for DT API hasn't been reviewed yet > >>>>>> AFICS, and I can imagine that there will be some resistance against. > >>>>> > >>>>> Since the DT API patch was just accepted by Rob [1], would it be OK > >>>>> to wait for the results of Stefan's testing (and any other reviews) > >>>>> before making a decision on this? From Stefan's note, it won't be > >>>>> until this weekend that he will have a chance to test, and I'm > >>>>> guessing the DT API patch will make its way through Rob's tree to > >>>>> linux-next by then. > >>>> > >>>> OK. > >>>> > >>>>> FYI, the warning workaround would be to make the second parameter to > >>>>> is31fl32xx_parse_child_dt() non-const. > >>>>> > >>>>> [1] https://lkml.org/lkml/2016/3/3/924 > >>>>> > >>>>>>> Changes from RFC: > >>>>>>> - Removed max-brightness DT property. > >>>>>>> - Refer to these devices as "LED controllers" in Kconfig. > >>>>>>> - Removed redundant last sentence from Kconfig entry > >>>>>>> - Removed unnecessary debug code. > >>>>>>> - Do not set led_classdev.brightness to 0 explicitly, as it is > >>>>>>> already initialized to 0 by devm_kzalloc(). > >>>>>>> - Used of_property_read_string() instead of of_get_property(). > >>>>>>> - Fail immediately on DT parsing error in a child node, rather than > >>>>>>> continuing on with the non-faulty ones. > >>>>>>> - Added additional comments for some things that might be non-obvious. > >>>>>>> - Added constants for the location of the SSD bit in the SHUTDOWN > >>>>>>> register, and the 3216's CONFIG register. > >>>>>>> - Added special sw_shutdown_func for the 3216 device, as that bit > >>>>>>> is in a different register, at a different position, and has reverse > >>>>>>> polarity compared to all the other devices. > >>>>>>> - Refactored is31fl32xx_init_regs() to separate out some logic into > >>>>>>> is31fl32xx_reset_regs() and is31fl32xx_software_shutdown(). > >>>>>>> > >>>>>>> [1] https://lkml.org/lkml/2016/3/2/746 > >>>>>>> > >>>>>>> drivers/leds/Kconfig | 8 + > >>>>>>> drivers/leds/Makefile | 1 + > >>>>>>> drivers/leds/leds-is31fl32xx.c | 505 +++++++++++++++++++++++++++++++++++++++++ > >>>>>>> 3 files changed, 514 insertions(+) > >>>>>>> create mode 100644 drivers/leds/leds-is31fl32xx.c > >>>>>>> > >>>>>>> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig > >>>>>>> index 1034696..9c63ba4 100644 > >>>>>>> --- a/drivers/leds/Kconfig > >>>>>>> +++ b/drivers/leds/Kconfig > >>>>>>> @@ -580,6 +580,14 @@ config LEDS_SN3218 > >>>>>>> This driver can also be built as a module. If so the module > >>>>>>> will be called leds-sn3218. > >>>>>>> > >>>>>>> +config LEDS_IS31FL32XX > >>>>>>> + tristate "LED support for ISSI IS31FL32XX I2C LED controller family" > >>>>>>> + depends on LEDS_CLASS && I2C && OF > >>>>>>> + help > >>>>>>> + Say Y here to include support for ISSI IS31FL32XX LED controllers. > >>>>>>> + They are I2C devices with multiple constant-current channels, each > >>>>>>> + with independent 256-level PWM control. > >>>>>>> + > >>>>>>> comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)" > >>>>>>> > >>>>>>> config LEDS_BLINKM > >>>>>>> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile > >>>>>>> index 89c9b6f..3fdf313 100644 > >>>>>>> --- a/drivers/leds/Makefile > >>>>>>> +++ b/drivers/leds/Makefile > >>>>>>> @@ -67,6 +67,7 @@ obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o > >>>>>>> obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o > >>>>>>> obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o > >>>>>>> obj-$(CONFIG_LEDS_SN3218) += leds-sn3218.o > >>>>>>> +obj-$(CONFIG_LEDS_IS31FL32XX) += leds-is31fl32xx.o > >>>>>>> > >>>>>>> # LED SPI Drivers > >>>>>>> obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o > >>>>>>> diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c > >>>>>>> new file mode 100644 > >>>>>>> index 0000000..49818f0 > >>>>>>> --- /dev/null > >>>>>>> +++ b/drivers/leds/leds-is31fl32xx.c > >>>>>>> @@ -0,0 +1,505 @@ > >>>>>>> +/* > >>>>>>> + * linux/drivers/leds-is31fl32xx.c > >>>>>>> + * > >>>>>>> + * Driver for ISSI IS31FL32xx family of I2C LED controllers > >>>>>>> + * > >>>>>>> + * Copyright 2015 Allworx Corp. > >>>>>>> + * > >>>>>>> + * > >>>>>>> + * 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. > >>>>>>> + * > >>>>>>> + * Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml > >>>>>>> + */ > >>>>>>> + > >>>>>>> +#include <linux/err.h> > >>>>>>> +#include <linux/i2c.h> > >>>>>>> +#include <linux/kernel.h> > >>>>>>> +#include <linux/leds.h> > >>>>>>> +#include <linux/module.h> > >>>>>>> +#include <linux/of_platform.h> > >>>>>>> + > >>>>>>> +/* Used to indicate a device has no such register */ > >>>>>>> +#define IS31FL32XX_REG_NONE 0xFF > >>>>>>> + > >>>>>>> +/* Software Shutdown bit in Shutdown Register */ > >>>>>>> +#define IS31FL32XX_SHUTDOWN_SSD_ENABLE 0 > >>>>>>> +#define IS31FL32XX_SHUTDOWN_SSD_DISABLE BIT(0) > >>>>>>> + > >>>>>>> +/* IS31FL3216 has a number of unique registers */ > >>>>>>> +#define IS31FL3216_CONFIG_REG 0x00 > >>>>>>> +#define IS31FL3216_LIGHTING_EFFECT_REG 0x03 > >>>>>>> +#define IS31FL3216_CHANNEL_CONFIG_REG 0x04 > >>>>>>> + > >>>>>>> +/* Software Shutdown bit in 3216 Config Register */ > >>>>>>> +#define IS31FL3216_CONFIG_SSD_ENABLE BIT(7) > >>>>>>> +#define IS31FL3216_CONFIG_SSD_DISABLE 0 > >>>>>>> + > >>>>>>> +struct is31fl32xx_priv; > >>>>>>> +struct is31fl32xx_led_data { > >>>>>>> + struct led_classdev cdev; > >>>>>>> + u8 channel; /* 1-based, max priv->cdef->channels */ > >>>>>>> + struct is31fl32xx_priv *priv; > >>>>>>> +}; > >>>>>>> + > >>>>>>> +struct is31fl32xx_priv { > >>>>>>> + const struct is31fl32xx_chipdef *cdef; > >>>>>>> + struct i2c_client *client; > >>>>>>> + unsigned int num_leds; > >>>>>>> + struct is31fl32xx_led_data leds[0]; > >>>>>>> +}; > >>>>>>> + > >>>>>>> +/** > >>>>>>> + * struct is31fl32xx_chipdef - chip-specific attributes > >>>>>>> + * @channels : Number of LED channels > >>>>>>> + * @shutdown_reg : address of Shutdown register (optional) > >>>>>>> + * @pwm_update_reg : address of PWM Update register > >>>>>>> + * @global_control_reg : address of Global Control register (optional) > >>>>>>> + * @reset_reg : address of Reset register (optional) > >>>>>>> + * @pwm_register_base : address of first PWM register > >>>>>>> + * @pwm_registers_reversed: : true if PWM registers count down instead of up > >>>>>>> + * @led_control_register_base : address of first LED control register (optional) > >>>>>>> + * @enable_bits_per_led_control_register: number of LEDs enable bits in each > >>>>>>> + * @reset_func: : pointer to reset function > >>>>>>> + * > >>>>>>> + * For all optional register addresses, the sentinel value %IS31FL32XX_REG_NONE > >>>>>>> + * indicates that this chip has no such register. > >>>>>>> + * > >>>>>>> + * If non-NULL, @reset_func will be called during probing to set all > >>>>>>> + * necessary registers to a known initialization state. This is needed > >>>>>>> + * for chips that do not have a @reset_reg. > >>>>>>> + * > >>>>>>> + * @enable_bits_per_led_control_register must be >=1 if > >>>>>>> + * @led_control_register_base != %IS31FL32XX_REG_NONE. > >>>>>>> + */ > >>>>>>> +struct is31fl32xx_chipdef { > >>>>>>> + u8 channels; > >>>>>>> + u8 shutdown_reg; > >>>>>>> + u8 pwm_update_reg; > >>>>>>> + u8 global_control_reg; > >>>>>>> + u8 reset_reg; > >>>>>>> + u8 pwm_register_base; > >>>>>>> + bool pwm_registers_reversed; > >>>>>>> + u8 led_control_register_base; > >>>>>>> + u8 enable_bits_per_led_control_register; > >>>>>>> + int (*reset_func)(struct is31fl32xx_priv *priv); > >>>>>>> + int (*sw_shutdown_func)(struct is31fl32xx_priv *priv, bool enable); > >>>>>>> +}; > >>>>>>> + > >>>>>>> +static const struct is31fl32xx_chipdef is31fl3236_cdef = { > >>>>>>> + .channels = 36, > >>>>>>> + .shutdown_reg = 0x00, > >>>>>>> + .pwm_update_reg = 0x25, > >>>>>>> + .global_control_reg = 0x4a, > >>>>>>> + .reset_reg = 0x4f, > >>>>>>> + .pwm_register_base = 0x01, > >>>>>>> + .led_control_register_base = 0x26, > >>>>>>> + .enable_bits_per_led_control_register = 1, > >>>>>>> +}; > >>>>>>> + > >>>>>>> +static const struct is31fl32xx_chipdef is31fl3235_cdef = { > >>>>>>> + .channels = 28, > >>>>>>> + .shutdown_reg = 0x00, > >>>>>>> + .pwm_update_reg = 0x25, > >>>>>>> + .global_control_reg = 0x4a, > >>>>>>> + .reset_reg = 0x4f, > >>>>>>> + .pwm_register_base = 0x05, > >>>>>>> + .led_control_register_base = 0x2a, > >>>>>>> + .enable_bits_per_led_control_register = 1, > >>>>>>> +}; > >>>>>>> + > >>>>>>> +static const struct is31fl32xx_chipdef is31fl3218_cdef = { > >>>>>>> + .channels = 18, > >>>>>>> + .shutdown_reg = 0x00, > >>>>>>> + .pwm_update_reg = 0x16, > >>>>>>> + .global_control_reg = IS31FL32XX_REG_NONE, > >>>>>>> + .reset_reg = 0x17, > >>>>>>> + .pwm_register_base = 0x01, > >>>>>>> + .led_control_register_base = 0x13, > >>>>>>> + .enable_bits_per_led_control_register = 6, > >>>>>>> +}; > >>>>>>> + > >>>>>>> +static int is31fl3216_reset(struct is31fl32xx_priv *priv); > >>>>>>> +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, > >>>>>>> + bool enable); > >>>>>>> +static const struct is31fl32xx_chipdef is31fl3216_cdef = { > >>>>>>> + .channels = 16, > >>>>>>> + .shutdown_reg = IS31FL32XX_REG_NONE, > >>>>>>> + .pwm_update_reg = 0xB0, > >>>>>>> + .global_control_reg = IS31FL32XX_REG_NONE, > >>>>>>> + .reset_reg = IS31FL32XX_REG_NONE, > >>>>>>> + .pwm_register_base = 0x10, > >>>>>>> + .pwm_registers_reversed = true, > >>>>>>> + .led_control_register_base = 0x01, > >>>>>>> + .enable_bits_per_led_control_register = 8, > >>>>>>> + .reset_func = is31fl3216_reset, > >>>>>>> + .sw_shutdown_func = is31fl3216_software_shutdown, > >>>>>>> +}; > >>>>>>> + > >>>>>>> +static int is31fl32xx_write(struct is31fl32xx_priv *priv, u8 reg, u8 val) > >>>>>>> +{ > >>>>>>> + int ret; > >>>>>>> + > >>>>>>> + dev_dbg(&priv->client->dev, "writing register 0x%02X=0x%02X", reg, val); > >>>>>>> + > >>>>>>> + ret = i2c_smbus_write_byte_data(priv->client, reg, val); > >>>>>>> + if (ret) { > >>>>>>> + dev_err(&priv->client->dev, > >>>>>>> + "register write to 0x%02X failed (error %d)", > >>>>>>> + reg, ret); > >>>>>>> + } > >>>>>>> + return ret; > >>>>>>> +} > >>>>>>> + > >>>>>>> +/* > >>>>>>> + * Custom reset function for IS31FL3216 because it does not have a RESET > >>>>>>> + * register the way that the other IS31FL32xx chips do. We don't bother > >>>>>>> + * writing the GPIO and animation registers, because the registers we > >>>>>>> + * do write ensure those will have no effect. > >>>>>>> + */ > >>>>>>> +static int is31fl3216_reset(struct is31fl32xx_priv *priv) > >>>>>>> +{ > >>>>>>> + unsigned int i; > >>>>>>> + int ret; > >>>>>>> + > >>>>>>> + ret = is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, > >>>>>>> + IS31FL3216_CONFIG_SSD_ENABLE); > >>>>>>> + if (ret) > >>>>>>> + return ret; > >>>>>>> + for (i = 0; i < priv->cdef->channels; i++) { > >>>>>>> + ret = is31fl32xx_write(priv, priv->cdef->pwm_register_base+i, > >>>>>>> + 0x00); > >>>>>>> + if (ret) > >>>>>>> + return ret; > >>>>>>> + } > >>>>>>> + ret = is31fl32xx_write(priv, priv->cdef->pwm_update_reg, 0); > >>>>>>> + if (ret) > >>>>>>> + return ret; > >>>>>>> + ret = is31fl32xx_write(priv, IS31FL3216_LIGHTING_EFFECT_REG, 0x00); > >>>>>>> + if (ret) > >>>>>>> + return ret; > >>>>>>> + ret = is31fl32xx_write(priv, IS31FL3216_CHANNEL_CONFIG_REG, 0x00); > >>>>>>> + if (ret) > >>>>>>> + return ret; > >>>>>>> + > >>>>>>> + return 0; > >>>>>>> +} > >>>>>>> + > >>>>>>> +/* > >>>>>>> + * Custom Software-Shutdown function for IS31FL3216 because it does not have > >>>>>>> + * a SHUTDOWN register the way that the other IS31FL32xx chips do. > >>>>>>> + * We don't bother doing a read/modify/write on the CONFIG register because > >>>>>>> + * we only ever use a value of '0' for the other fields in that register. > >>>>>>> + */ > >>>>>>> +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, > >>>>>>> + bool enable) > >>>>>>> +{ > >>>>>>> + u8 value = enable ? IS31FL3216_CONFIG_SSD_ENABLE : > >>>>>>> + IS31FL3216_CONFIG_SSD_DISABLE; > >>>>>>> + > >>>>>>> + return is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, value); > >>>>>>> +} > >>>>>>> + > >>>>>>> +/* > >>>>>>> + * NOTE: A mutex is not needed in this function because: > >>>>>>> + * - All referenced data is read-only after probe() > >>>>>>> + * - The I2C core has a mutex on to protect the bus > >>>>>>> + * - There are no read/modify/write operations > >>>>>>> + * - Intervening operations between the write of the PWM register > >>>>>>> + * and the Update register are harmless. > >>>>>>> + * > >>>>>>> + * Example: > >>>>>>> + * PWM_REG_1 write 16 > >>>>>>> + * UPDATE_REG write 0 > >>>>>>> + * PWM_REG_2 write 128 > >>>>>>> + * UPDATE_REG write 0 > >>>>>>> + * vs: > >>>>>>> + * PWM_REG_1 write 16 > >>>>>>> + * PWM_REG_2 write 128 > >>>>>>> + * UPDATE_REG write 0 > >>>>>>> + * UPDATE_REG write 0 > >>>>>>> + * are equivalent. Poking the Update register merely applies all PWM > >>>>>>> + * register writes up to that point. > >>>>>>> + */ > >>>>>>> +static int is31fl32xx_brightness_set(struct led_classdev *led_cdev, > >>>>>>> + enum led_brightness brightness) > >>>>>>> +{ > >>>>>>> + const struct is31fl32xx_led_data *led_data = > >>>>>>> + container_of(led_cdev, struct is31fl32xx_led_data, cdev); > >>>>>>> + const struct is31fl32xx_chipdef *cdef = led_data->priv->cdef; > >>>>>>> + u8 pwm_register_offset; > >>>>>>> + int ret; > >>>>>>> + > >>>>>>> + dev_dbg(led_cdev->dev, "%s: %d\n", __func__, brightness); > >>>>>>> + > >>>>>>> + /* NOTE: led_data->channel is 1-based */ > >>>>>>> + if (cdef->pwm_registers_reversed) > >>>>>>> + pwm_register_offset = cdef->channels - led_data->channel; > >>>>>>> + else > >>>>>>> + pwm_register_offset = led_data->channel - 1; > >>>>>>> + > >>>>>>> + ret = is31fl32xx_write(led_data->priv, > >>>>>>> + cdef->pwm_register_base + pwm_register_offset, > >>>>>>> + brightness); > >>>>>>> + if (ret) > >>>>>>> + return ret; > >>>>>>> + > >>>>>>> + return is31fl32xx_write(led_data->priv, cdef->pwm_update_reg, 0); > >>>>>>> +} > >>>>>>> + > >>>>>>> +static int is31fl32xx_reset_regs(struct is31fl32xx_priv *priv) > >>>>>>> +{ > >>>>>>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; > >>>>>>> + int ret; > >>>>>>> + > >>>>>>> + if (cdef->reset_reg != IS31FL32XX_REG_NONE) { > >>>>>>> + ret = is31fl32xx_write(priv, cdef->reset_reg, 0); > >>>>>>> + if (ret) > >>>>>>> + return ret; > >>>>>>> + } > >>>>>>> + > >>>>>>> + if (cdef->reset_func) > >>>>>>> + return cdef->reset_func(priv); > >>>>>>> + > >>>>>>> + return 0; > >>>>>>> +} > >>>>>>> + > >>>>>>> +static int is31fl32xx_software_shutdown(struct is31fl32xx_priv *priv, > >>>>>>> + bool enable) > >>>>>>> +{ > >>>>>>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; > >>>>>>> + int ret; > >>>>>>> + > >>>>>>> + if (cdef->shutdown_reg != IS31FL32XX_REG_NONE) { > >>>>>>> + u8 value = enable ? IS31FL32XX_SHUTDOWN_SSD_ENABLE : > >>>>>>> + IS31FL32XX_SHUTDOWN_SSD_DISABLE; > >>>>>>> + ret = is31fl32xx_write(priv, cdef->shutdown_reg, value); > >>>>>>> + if (ret) > >>>>>>> + return ret; > >>>>>>> + } > >>>>>>> + > >>>>>>> + if (cdef->sw_shutdown_func) > >>>>>>> + return cdef->sw_shutdown_func(priv, enable); > >>>>>> > >>>>>> You seem to call sw_shutdown_func only here, so why should we have > >>>>>> enable parameter in this op? > >>>>> > >>>>> I'm not sure if I understand the question, but I will try to answer. > >>>>> > >>>>> 'enable' is passed through is31fl32xx_software_shutdown to > >>>>> cdef->sw_shutdown_func, so it can be either true or false at that > >>>>> point. The purpose of sw_shutdown_func is to add any special behavior > >>>>> when enabling/disabling software-shutdown mode, which is needed for > >>>>> the 3216 because its SSD bit is in a different position and with > >>>>> opposite polarity. > >>>>> > >>>>> Is it that 'enable' in that line of code makes it look like it's being > >>>>> called with an hardcoded value rather than a variable? If so, perhaps a > >>>>> different parameter name would make it more obvious? Or a kerneldoc > >>>>> comment for the function to describe the parameter? > >>>>> > >>>>> Or have I totally missed the point of the question? > >>>> > >>>> Actually I should have placed this question next to > >>>> the call to s31fl32xx_software_shutdown() in is31fl32xx_init_regs(), > >>>> which is passed "false" in the second argument, and there is no > >>>> other call to s31fl32xx_software_shutdown() in the driver. > >>>> > >>>> Having the argument makes people wondering that there is some > >>>> use case in the driver, where "true" is passed, but it seems not > >>>> to be the case. > >>> > >>> Thanks for the clarification. > >>> > >>> Yes, there is currently no explicit call to enable software-shutdown > >>> mode. Since the reset state of these devices is to have software-shutdown > >>> enabled, the only explicit operation on it that's currently needed is > >>> to disable it. > >>> > >>> Reasons I can think to have the 'enable' parameter anyways include: > >>> - It seems logical to me that an API to manipulate the software-shutdown > >>> state should allow both enabling and disabling. > >>> - Having a parameter for that seemed the most obvious way to go, and it > >>> was trivial to implement. > >>> - Alternatively having separate "enable" and "disable" functions would > >>> duplicate most of the logic, vs the parameter being just a single > >>> conditional. And that would also imply two function pointers in the > >>> chipdefs, which I'd prefer to minimize. > >>> - If anyone wanted to implement suspend/resume in the future, they would > >>> most likely do it by enabling/disabling software-shutdown. Supporting > >>> both enable/disable from the start should make that trivial to do. > >> > >> Suspend/resume callbacks are already implemented in led-class.c and > >> related ops indirectly call brightness_set. If you want to support > >> suspend/resume you have to set LED_CORE_SUSPENDRESUME flag. > > > > If I understand correctly, all LED_CORE_SUSPENDRESUME will do is cause > > the led core to set the brightness to 0 on suspend (and reverse that > > on resume). I see some drivers use this flag and other do not. > > This brings up the question in my mind: how would a driver decide > > whether it is appropriate for an LED to go dark on suspend? Is that > > just the drivers that know the logical purpose of the LEDs they control? > > There is a room for improvement here. Possibly a new LED class sysfs > attribute could be of help in determining that. > > >> Setting brightness to 0 is equivalent to turning the LED controller > >> in a shutdown mode, provided that all sub-LEDs are off. > > > > This is not strictly true for these devices. If someone cared very much > > about power usage when suspended they may want to put the LED controller > > into what it calls "shutdown mode" via the SSD bit. I didn't bother mainly > > because I have no need, and also because I wasn't sure how to even trigger > > a suspend in order to test an implementation. > > I meant that LED class driver should put the device in a software > shutdown mode after last sub-LED is turned off. > > > FYI, I just measured it the effect of software-shutdown even with all LEDs > > already off. The difference in current is about 5mA, measured at the 5V > > supply to a 3216 eval board. Not huge, but someone might care. > > This can be vital difference for some use cases. You could count the > number of currently active sub-LEDs and put the controller in a software > shutdown mode in case the value is 0. I had thought about that, but I had some concerns that dissuaded me from perusing it: - Would need some way to know whether a brightness_set has changed an LED from on->off or off->on in order to update that counter. leds-core modifies led_cdev->brightness before calling brightness_set, so that information would need to be somehow maintained in the driver. - It requires an additional mutex to protect whatever data is involved in the previous bullet. That mutex would need to be taken on every brightness update. - If a single LED is blinking rapidly (e.g. a cpu trigger), it would thrash software shutdown mode. That in turn adds even more CPU usage (due to register writes and mutexes), potentially making power usage worse in some cases. - Time it might take to implement and review (mostly depending on how the first bullet is handled), especially since the 4.6 merge window is fast approaching. That said, I could propose the following simple-to-implement design: - counter, and mutex to protect it, added to 'priv' - previous_brightness field added to 'led_data' - brightness_set compares new brightness vs previous - if on/off state has changed: - takes mutex - updates counter - sets software-shutdown mode to (counter==0) - releases mutex If you think that's worth doing, I can try to get it in along with the other changes for v2. > >>> - I thought the code read better with a bool parameter, vs a longer > >>> function name. > >>> > >>> So nothing really critical, but mostly just my aesthetic and preference. > >>> > >>> Also, I expect that is31fl32xx_software_shutdown() would be inlined, so > >>> the conditional check in there is optimized out anyways, and there is no > >>> performance penalty. Looking at the disassembly in my ARMv7a build, both > >>> of those have indeed happened there. > >> > >> Not only the size of a binary and the performance, but also code > >> readability matters. The function is called only with false argument, > >> so I expect that some people may submit patches optimizing this. > >> > >> Let's avoid the confusion. > > > > I guess we just have a difference of opinion on which way is more > > readable, which is OK. Unless the above explanation causes you to > > change your mind, I will remove the 'enable' parameter and add a > > "_disable" suffix to both functions. That will also leave the > > #define IS31FL32XX_SHUTDOWN_SSD_ENABLE 0 > > constant unused in the code, should that also be removed? Note that > > the 3216 specific constant > > #define IS31FL3216_CONFIG_SSD_ENABLE BIT(7) > > would still be used in is31fl3216_reset(). > > Current version of the function would be required for enabling > shutting down the controller from brightness_set op when the > count of active sub-LEDs drops to 0. Agreed. That's a reason I would have for leaving it so even if the auto-software-shutdown logic is not implemented at this time. But I would understand if you still prefer to only have the current form if there is currently code which uses both possible values of the 'enable' parameter. > >>>>>>> + return 0; > >>>>>>> +} > >>>>>>> + > >>>>>>> +static int is31fl32xx_init_regs(struct is31fl32xx_priv *priv) > >>>>>>> +{ > >>>>>>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; > >>>>>>> + int ret; > >>>>>>> + > >>>>>>> + ret = is31fl32xx_reset_regs(priv); > >>>>>>> + if (ret) > >>>>>>> + return ret; > >>>>>>> + > >>>>>>> + /* > >>>>>>> + * Set enable bit for all channels. > >>>>>>> + * We will control state with PWM registers alone. > >>>>>>> + */ > >>>>>>> + if (cdef->led_control_register_base != IS31FL32XX_REG_NONE) { > >>>>>>> + u8 value = > >>>>>>> + GENMASK(cdef->enable_bits_per_led_control_register-1, 0); > >>>>>>> + u8 num_regs = cdef->channels / > >>>>>>> + cdef->enable_bits_per_led_control_register; > >>>>>>> + int i; > >>>>>>> + > >>>>>>> + for (i = 0; i < num_regs; i++) { > >>>>>>> + ret = is31fl32xx_write(priv, > >>>>>>> + cdef->led_control_register_base+i, > >>>>>>> + value); > >>>>>>> + if (ret) > >>>>>>> + return ret; > >>>>>>> + } > >>>>>>> + } > >>>>>>> + > >>>>>>> + ret = is31fl32xx_software_shutdown(priv, false); > >>>>>>> + if (ret) > >>>>>>> + return ret; > >>>>>>> + > >>>>>>> + if (cdef->global_control_reg != IS31FL32XX_REG_NONE) { > >>>>>>> + ret = is31fl32xx_write(priv, cdef->global_control_reg, 0x00); > >>>>>>> + if (ret) > >>>>>>> + return ret; > >>>>>>> + } > >>>>>>> + > >>>>>>> + return 0; > >>>>>>> +} > >>>>>>> + > >>>>>>> +static inline size_t sizeof_is31fl32xx_priv(int num_leds) > >>>>>>> +{ > >>>>>>> + return sizeof(struct is31fl32xx_priv) + > >>>>>>> + (sizeof(struct is31fl32xx_led_data) * num_leds); > >>>>>>> +} > >>>>>>> + > >>>>>>> +static int is31fl32xx_parse_child_dt(const struct device *dev, > >>>>>>> + const struct device_node *child, > >>>>>>> + struct is31fl32xx_led_data *led_data) > >>>>>>> +{ > >>>>>>> + struct led_classdev *cdev = &led_data->cdev; > >>>>>>> + int ret = 0; > >>>>>>> + u32 reg; > >>>>>>> + > >>>>>>> + if (of_property_read_string(child, "label", &cdev->name)) > >>>>>>> + cdev->name = child->name; > >>>>>>> + > >>>>>>> + ret = of_property_read_u32(child, "reg", ®); > >>>>>>> + if (ret || reg < 1 || reg > led_data->priv->cdef->channels) { > >>>>>>> + dev_err(dev, > >>>>>>> + "Child node %s does not have a valid reg property\n", > >>>>>>> + child->full_name); > >>>>>>> + return -EINVAL; > >>>>>>> + } > >>>>>>> + led_data->channel = reg; > >>>>>>> + > >>>>>>> + of_property_read_string(child, "linux,default-trigger", > >>>>>>> + &cdev->default_trigger); > >>>>>>> + > >>>>>>> + cdev->brightness_set_blocking = is31fl32xx_brightness_set; > >>>>>>> + > >>>>>>> + return 0; > >>>>>>> +} > >>>>>>> + > >>>>>>> +static struct is31fl32xx_led_data *is31fl32xx_find_led_data( > >>>>>>> + struct is31fl32xx_priv *priv, > >>>>>>> + u8 channel) > >>>>>>> +{ > >>>>>>> + size_t i; > >>>>>>> + > >>>>>>> + for (i = 0; i < priv->num_leds; i++) { > >>>>>>> + if (priv->leds[i].channel == channel) > >>>>>>> + return &priv->leds[i]; > >>>>>>> + } > >>>>>>> + > >>>>>>> + return NULL; > >>>>>>> +} > >>>>>>> + > >>>>>>> +static int is31fl32xx_parse_dt(struct device *dev, > >>>>>>> + struct is31fl32xx_priv *priv) > >>>>>>> +{ > >>>>>>> + struct device_node *child; > >>>>>>> + int ret = 0; > >>>>>>> + > >>>>>>> + for_each_child_of_node(dev->of_node, child) { > >>>>>>> + struct is31fl32xx_led_data *led_data = > >>>>>>> + &priv->leds[priv->num_leds]; > >>>>>>> + const struct is31fl32xx_led_data *other_led_data; > >>>>>>> + > >>>>>>> + led_data->priv = priv; > >>>>>>> + > >>>>>>> + ret = is31fl32xx_parse_child_dt(dev, child, led_data); > >>>>>>> + if (ret) > >>>>>>> + goto err; > >>>>>>> + > >>>>>>> + /* Detect if channel is already in use by another child */ > >>>>>>> + other_led_data = is31fl32xx_find_led_data(priv, > >>>>>>> + led_data->channel); > >>>>>>> + if (other_led_data) { > >>>>>>> + dev_err(dev, > >>>>>>> + "%s and %s both attempting to use channel %d\n", > >>>>>>> + led_data->cdev.name, > >>>>>>> + other_led_data->cdev.name, > >>>>>>> + led_data->channel); > >>>>>>> + goto err; > >>>>>>> + } > >>>>>>> + > >>>>>>> + ret = devm_led_classdev_register(dev, &led_data->cdev); > >>>>>>> + if (ret) { > >>>>>>> + dev_err(dev, "failed to register PWM led for %s: %d\n", > >>>>>>> + led_data->cdev.name, ret); > >>>>>>> + goto err; > >>>>>>> + } > >>>>>>> + > >>>>>>> + priv->num_leds++; > >>>>>>> + } > >>>>>>> + > >>>>>>> + return 0; > >>>>>>> + > >>>>>>> +err: > >>>>>>> + of_node_put(child); > >>>>>>> + return ret; > >>>>>>> +} > >>>>>>> + > >>>>>>> +static const struct of_device_id of_is31fl31xx_match[] = { > >>>>>>> + { .compatible = "issi,is31fl3236", .data = &is31fl3236_cdef, }, > >>>>>>> + { .compatible = "issi,is31fl3235", .data = &is31fl3235_cdef, }, > >>>>>>> + { .compatible = "issi,is31fl3218", .data = &is31fl3218_cdef, }, > >>>>>>> + { .compatible = "issi,is31fl3216", .data = &is31fl3216_cdef, }, > >>>>>>> + {}, > >>>>>>> +}; > >>>>>>> + > >>>>>>> +MODULE_DEVICE_TABLE(of, of_is31fl31xx_match); > >>>>>>> + > >>>>>>> +static int is31fl32xx_probe(struct i2c_client *client, > >>>>>>> + const struct i2c_device_id *id) > >>>>>>> +{ > >>>>>>> + const struct is31fl32xx_chipdef *cdef; > >>>>>>> + const struct of_device_id *of_dev_id; > >>>>>>> + struct device *dev = &client->dev; > >>>>>>> + struct is31fl32xx_priv *priv; > >>>>>>> + int count; > >>>>>>> + int ret = 0; > >>>>>>> + > >>>>>>> + of_dev_id = of_match_device(of_is31fl31xx_match, dev); > >>>>>>> + if (!of_dev_id) > >>>>>>> + return -EINVAL; > >>>>>>> + > >>>>>>> + cdef = of_dev_id->data; > >>>>>>> + > >>>>>>> + count = of_get_child_count(dev->of_node); > >>>>>>> + if (!count) > >>>>>>> + return -EINVAL; > >>>>>>> + > >>>>>>> + priv = devm_kzalloc(dev, sizeof_is31fl32xx_priv(count), > >>>>>>> + GFP_KERNEL); > >>>>>>> + if (!priv) > >>>>>>> + return -ENOMEM; > >>>>>>> + > >>>>>>> + priv->client = client; > >>>>>>> + priv->cdef = cdef; > >>>>>>> + i2c_set_clientdata(client, priv); > >>>>>>> + > >>>>>>> + ret = is31fl32xx_init_regs(priv); > >>>>>>> + if (ret) > >>>>>>> + return ret; > >>>>>>> + > >>>>>>> + ret = is31fl32xx_parse_dt(dev, priv); > >>>>>>> + if (ret) > >>>>>>> + return ret; > >>>>>>> + > >>>>>>> + return 0; > >>>>>>> +} > >>>>>>> + > >>>>>>> +static int is31fl32xx_remove(struct i2c_client *client) > >>>>>>> +{ > >>>>>>> + struct is31fl32xx_priv *priv = i2c_get_clientdata(client); > >>>>>>> + > >>>>>>> + return is31fl32xx_reset_regs(priv); > >>>>>>> +} > >>>>>>> + > >>>>>>> +/* > >>>>>>> + * i2c-core requires that id_table be non-NULL, even though > >>>>>>> + * it is not used for DeviceTree based instantiation. > >>>>>>> + */ > >>>>>>> +static const struct i2c_device_id is31fl31xx_id[] = { > >>>>>>> + {}, > >>>>>>> +}; > >>>>>>> + > >>>>>>> +MODULE_DEVICE_TABLE(i2c, is31fl31xx_id); > >>>>>>> + > >>>>>>> +static struct i2c_driver is31fl32xx_driver = { > >>>>>>> + .driver = { > >>>>>>> + .name = "is31fl32xx", > >>>>>>> + .of_match_table = of_is31fl31xx_match, > >>>>>>> + }, > >>>>>>> + .probe = is31fl32xx_probe, > >>>>>>> + .remove = is31fl32xx_remove, > >>>>>>> + .id_table = is31fl31xx_id, > >>>>>>> +}; > >>>>>>> + > >>>>>>> +module_i2c_driver(is31fl32xx_driver); > >>>>>>> + > >>>>>>> +MODULE_AUTHOR("David Rivshin <drivshin@allworx.com>"); > >>>>>>> +MODULE_DESCRIPTION("ISSI IS31FL32xx LED driver"); > >>>>>>> +MODULE_LICENSE("GPL v2"); > >>>>>>> ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 3/4] leds: Add driver for the ISSI IS31FL32xx family of LED controllers 2016-03-05 5:29 ` David Rivshin (Allworx) @ 2016-03-05 11:37 ` Jacek Anaszewski 0 siblings, 0 replies; 28+ messages in thread From: Jacek Anaszewski @ 2016-03-05 11:37 UTC (permalink / raw) To: David Rivshin (Allworx) Cc: Jacek Anaszewski, linux-leds, devicetree, Richard Purdie, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Stefan Wahren, linux-kernel On 03/05/2016 06:29 AM, David Rivshin (Allworx) wrote: > On Fri, 4 Mar 2016 22:39:06 +0100 > Jacek Anaszewski <jacek.anaszewski@gmail.com> wrote: > >> On 03/04/2016 08:02 PM, David Rivshin (Allworx) wrote: >>> On Fri, 04 Mar 2016 17:01:52 +0100 >>> Jacek Anaszewski <j.anaszewski@samsung.com> wrote: >>> >>>> On 03/04/2016 04:05 PM, David Rivshin (Allworx) wrote: >>>>> On Fri, 04 Mar 2016 08:54:02 +0100 >>>>> Jacek Anaszewski <j.anaszewski@samsung.com> wrote: >>>>> >>>>>> On 03/04/2016 01:45 AM, David Rivshin (Allworx) wrote: >>>>>>> On Thu, 03 Mar 2016 15:51:32 +0100 >>>>>>> Jacek Anaszewski <j.anaszewski@samsung.com> wrote: >>>>>>> >>>>>>>> Hi David, >>>>>>>> >>>>>>>> Thanks for the update. Two remarks in the code. >>>>>>>> >>>>>>>> On 03/03/2016 04:01 AM, David Rivshin (Allworx) wrote: >>>>>>>>> From: David Rivshin <drivshin@allworx.com> >>>>>>>>> >>>>>>>>> The IS31FL32xx family of LED controllers are I2C devices with multiple >>>>>>>>> constant-current channels, each with independent 256-level PWM control. >>>>>>>>> >>>>>>>>> Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml >>>>>>>>> >>>>>>>>> This has been tested on the IS31FL3236 and IS31FL3216, on an ARM >>>>>>>>> (TI am335x) platform. >>>>>>>>> >>>>>>>>> The programming paradigm of these devices is similar in the following >>>>>>>>> ways: >>>>>>>>> - All registers are 8 bit >>>>>>>>> - All LED control registers are write-only >>>>>>>>> - Each LED channel has a PWM register (0-255) >>>>>>>>> - PWM register writes are shadowed until an Update register is poked >>>>>>>>> - All have a concept of Software Shutdown, which disables output >>>>>>>>> >>>>>>>>> However, there are some differences in devices: >>>>>>>>> - 3236/3235 have a separate Control register for each LED, >>>>>>>>> (3218/3216 pack the enable bits into fewer registers) >>>>>>>>> - 3236/3235 have a per-channel current divisor setting >>>>>>>>> - 3236/3235 have a Global Control register that can turn off all LEDs >>>>>>>>> - 3216 is unique in a number of ways >>>>>>>>> - OUT9-OUT16 can be configured as GPIOs instead of LED controls >>>>>>>>> - LEDs can be programmed with an 8-frame animation, with >>>>>>>>> programmable delay between frames >>>>>>>>> - LEDs can be modulated by an input audio signal >>>>>>>>> - Max output current can be adjusted from 1/4 to 2x globally >>>>>>>>> - Has a Configuration register instead of a Shutdown register >>>>>>>>> >>>>>>>>> This driver currently only supports the base PWM control function >>>>>>>>> of these devices. The following features of these devices are not >>>>>>>>> implemented, although it should be possible to add them in the future: >>>>>>>>> - All devices are capable of going into a lower-power "software >>>>>>>>> shutdown" mode. >>>>>>>>> - The is31fl3236 and is31fl3235 can reduce the max output current >>>>>>>>> per-channel with a divisor of 1, 2, 3, or 4. >>>>>>>>> - The is31fl3216 can use some LED channels as GPIOs instead. >>>>>>>>> - The is31fl3216 can animate LEDs in hardware. >>>>>>>>> - The is31fl3216 can modulate LEDs according to an audio input. >>>>>>>>> - The is31fl3216 can reduce/increase max output current globally. >>>>>>>>> >>>>>>>>> Signed-off-by: David Rivshin <drivshin@allworx.com> >>>>>>>>> --- >>>>>>>>> >>>>>>>>> You may see two instances of this warning: >>>>>>>>> "passing argument 1 of 'of_property_read_string' discards 'const' >>>>>>>>> qualifier from pointer target type" >>>>>>>>> That is a result of of_property_read_string() taking a non-const >>>>>>>>> struct device_node pointer parameter. I have separately submitted a >>>>>>>>> patch to fix that [1], and a few related functions which had the same >>>>>>>>> issue. I'm hoping that will get into linux-next before this does, so >>>>>>>>> that the warnings never show up there. >>>>>>>> >>>>>>>> Please adjust the patch so that it compiles without warnings on >>>>>>>> current linux-next. Your patch for DT API hasn't been reviewed yet >>>>>>>> AFICS, and I can imagine that there will be some resistance against. >>>>>>> >>>>>>> Since the DT API patch was just accepted by Rob [1], would it be OK >>>>>>> to wait for the results of Stefan's testing (and any other reviews) >>>>>>> before making a decision on this? From Stefan's note, it won't be >>>>>>> until this weekend that he will have a chance to test, and I'm >>>>>>> guessing the DT API patch will make its way through Rob's tree to >>>>>>> linux-next by then. >>>>>> >>>>>> OK. >>>>>> >>>>>>> FYI, the warning workaround would be to make the second parameter to >>>>>>> is31fl32xx_parse_child_dt() non-const. >>>>>>> >>>>>>> [1] https://lkml.org/lkml/2016/3/3/924 >>>>>>> >>>>>>>>> Changes from RFC: >>>>>>>>> - Removed max-brightness DT property. >>>>>>>>> - Refer to these devices as "LED controllers" in Kconfig. >>>>>>>>> - Removed redundant last sentence from Kconfig entry >>>>>>>>> - Removed unnecessary debug code. >>>>>>>>> - Do not set led_classdev.brightness to 0 explicitly, as it is >>>>>>>>> already initialized to 0 by devm_kzalloc(). >>>>>>>>> - Used of_property_read_string() instead of of_get_property(). >>>>>>>>> - Fail immediately on DT parsing error in a child node, rather than >>>>>>>>> continuing on with the non-faulty ones. >>>>>>>>> - Added additional comments for some things that might be non-obvious. >>>>>>>>> - Added constants for the location of the SSD bit in the SHUTDOWN >>>>>>>>> register, and the 3216's CONFIG register. >>>>>>>>> - Added special sw_shutdown_func for the 3216 device, as that bit >>>>>>>>> is in a different register, at a different position, and has reverse >>>>>>>>> polarity compared to all the other devices. >>>>>>>>> - Refactored is31fl32xx_init_regs() to separate out some logic into >>>>>>>>> is31fl32xx_reset_regs() and is31fl32xx_software_shutdown(). >>>>>>>>> >>>>>>>>> [1] https://lkml.org/lkml/2016/3/2/746 >>>>>>>>> >>>>>>>>> drivers/leds/Kconfig | 8 + >>>>>>>>> drivers/leds/Makefile | 1 + >>>>>>>>> drivers/leds/leds-is31fl32xx.c | 505 +++++++++++++++++++++++++++++++++++++++++ >>>>>>>>> 3 files changed, 514 insertions(+) >>>>>>>>> create mode 100644 drivers/leds/leds-is31fl32xx.c >>>>>>>>> >>>>>>>>> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig >>>>>>>>> index 1034696..9c63ba4 100644 >>>>>>>>> --- a/drivers/leds/Kconfig >>>>>>>>> +++ b/drivers/leds/Kconfig >>>>>>>>> @@ -580,6 +580,14 @@ config LEDS_SN3218 >>>>>>>>> This driver can also be built as a module. If so the module >>>>>>>>> will be called leds-sn3218. >>>>>>>>> >>>>>>>>> +config LEDS_IS31FL32XX >>>>>>>>> + tristate "LED support for ISSI IS31FL32XX I2C LED controller family" >>>>>>>>> + depends on LEDS_CLASS && I2C && OF >>>>>>>>> + help >>>>>>>>> + Say Y here to include support for ISSI IS31FL32XX LED controllers. >>>>>>>>> + They are I2C devices with multiple constant-current channels, each >>>>>>>>> + with independent 256-level PWM control. >>>>>>>>> + >>>>>>>>> comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)" >>>>>>>>> >>>>>>>>> config LEDS_BLINKM >>>>>>>>> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile >>>>>>>>> index 89c9b6f..3fdf313 100644 >>>>>>>>> --- a/drivers/leds/Makefile >>>>>>>>> +++ b/drivers/leds/Makefile >>>>>>>>> @@ -67,6 +67,7 @@ obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o >>>>>>>>> obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o >>>>>>>>> obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o >>>>>>>>> obj-$(CONFIG_LEDS_SN3218) += leds-sn3218.o >>>>>>>>> +obj-$(CONFIG_LEDS_IS31FL32XX) += leds-is31fl32xx.o >>>>>>>>> >>>>>>>>> # LED SPI Drivers >>>>>>>>> obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o >>>>>>>>> diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c >>>>>>>>> new file mode 100644 >>>>>>>>> index 0000000..49818f0 >>>>>>>>> --- /dev/null >>>>>>>>> +++ b/drivers/leds/leds-is31fl32xx.c >>>>>>>>> @@ -0,0 +1,505 @@ >>>>>>>>> +/* >>>>>>>>> + * linux/drivers/leds-is31fl32xx.c >>>>>>>>> + * >>>>>>>>> + * Driver for ISSI IS31FL32xx family of I2C LED controllers >>>>>>>>> + * >>>>>>>>> + * Copyright 2015 Allworx Corp. >>>>>>>>> + * >>>>>>>>> + * >>>>>>>>> + * 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. >>>>>>>>> + * >>>>>>>>> + * Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml >>>>>>>>> + */ >>>>>>>>> + >>>>>>>>> +#include <linux/err.h> >>>>>>>>> +#include <linux/i2c.h> >>>>>>>>> +#include <linux/kernel.h> >>>>>>>>> +#include <linux/leds.h> >>>>>>>>> +#include <linux/module.h> >>>>>>>>> +#include <linux/of_platform.h> >>>>>>>>> + >>>>>>>>> +/* Used to indicate a device has no such register */ >>>>>>>>> +#define IS31FL32XX_REG_NONE 0xFF >>>>>>>>> + >>>>>>>>> +/* Software Shutdown bit in Shutdown Register */ >>>>>>>>> +#define IS31FL32XX_SHUTDOWN_SSD_ENABLE 0 >>>>>>>>> +#define IS31FL32XX_SHUTDOWN_SSD_DISABLE BIT(0) >>>>>>>>> + >>>>>>>>> +/* IS31FL3216 has a number of unique registers */ >>>>>>>>> +#define IS31FL3216_CONFIG_REG 0x00 >>>>>>>>> +#define IS31FL3216_LIGHTING_EFFECT_REG 0x03 >>>>>>>>> +#define IS31FL3216_CHANNEL_CONFIG_REG 0x04 >>>>>>>>> + >>>>>>>>> +/* Software Shutdown bit in 3216 Config Register */ >>>>>>>>> +#define IS31FL3216_CONFIG_SSD_ENABLE BIT(7) >>>>>>>>> +#define IS31FL3216_CONFIG_SSD_DISABLE 0 >>>>>>>>> + >>>>>>>>> +struct is31fl32xx_priv; >>>>>>>>> +struct is31fl32xx_led_data { >>>>>>>>> + struct led_classdev cdev; >>>>>>>>> + u8 channel; /* 1-based, max priv->cdef->channels */ >>>>>>>>> + struct is31fl32xx_priv *priv; >>>>>>>>> +}; >>>>>>>>> + >>>>>>>>> +struct is31fl32xx_priv { >>>>>>>>> + const struct is31fl32xx_chipdef *cdef; >>>>>>>>> + struct i2c_client *client; >>>>>>>>> + unsigned int num_leds; >>>>>>>>> + struct is31fl32xx_led_data leds[0]; >>>>>>>>> +}; >>>>>>>>> + >>>>>>>>> +/** >>>>>>>>> + * struct is31fl32xx_chipdef - chip-specific attributes >>>>>>>>> + * @channels : Number of LED channels >>>>>>>>> + * @shutdown_reg : address of Shutdown register (optional) >>>>>>>>> + * @pwm_update_reg : address of PWM Update register >>>>>>>>> + * @global_control_reg : address of Global Control register (optional) >>>>>>>>> + * @reset_reg : address of Reset register (optional) >>>>>>>>> + * @pwm_register_base : address of first PWM register >>>>>>>>> + * @pwm_registers_reversed: : true if PWM registers count down instead of up >>>>>>>>> + * @led_control_register_base : address of first LED control register (optional) >>>>>>>>> + * @enable_bits_per_led_control_register: number of LEDs enable bits in each >>>>>>>>> + * @reset_func: : pointer to reset function >>>>>>>>> + * >>>>>>>>> + * For all optional register addresses, the sentinel value %IS31FL32XX_REG_NONE >>>>>>>>> + * indicates that this chip has no such register. >>>>>>>>> + * >>>>>>>>> + * If non-NULL, @reset_func will be called during probing to set all >>>>>>>>> + * necessary registers to a known initialization state. This is needed >>>>>>>>> + * for chips that do not have a @reset_reg. >>>>>>>>> + * >>>>>>>>> + * @enable_bits_per_led_control_register must be >=1 if >>>>>>>>> + * @led_control_register_base != %IS31FL32XX_REG_NONE. >>>>>>>>> + */ >>>>>>>>> +struct is31fl32xx_chipdef { >>>>>>>>> + u8 channels; >>>>>>>>> + u8 shutdown_reg; >>>>>>>>> + u8 pwm_update_reg; >>>>>>>>> + u8 global_control_reg; >>>>>>>>> + u8 reset_reg; >>>>>>>>> + u8 pwm_register_base; >>>>>>>>> + bool pwm_registers_reversed; >>>>>>>>> + u8 led_control_register_base; >>>>>>>>> + u8 enable_bits_per_led_control_register; >>>>>>>>> + int (*reset_func)(struct is31fl32xx_priv *priv); >>>>>>>>> + int (*sw_shutdown_func)(struct is31fl32xx_priv *priv, bool enable); >>>>>>>>> +}; >>>>>>>>> + >>>>>>>>> +static const struct is31fl32xx_chipdef is31fl3236_cdef = { >>>>>>>>> + .channels = 36, >>>>>>>>> + .shutdown_reg = 0x00, >>>>>>>>> + .pwm_update_reg = 0x25, >>>>>>>>> + .global_control_reg = 0x4a, >>>>>>>>> + .reset_reg = 0x4f, >>>>>>>>> + .pwm_register_base = 0x01, >>>>>>>>> + .led_control_register_base = 0x26, >>>>>>>>> + .enable_bits_per_led_control_register = 1, >>>>>>>>> +}; >>>>>>>>> + >>>>>>>>> +static const struct is31fl32xx_chipdef is31fl3235_cdef = { >>>>>>>>> + .channels = 28, >>>>>>>>> + .shutdown_reg = 0x00, >>>>>>>>> + .pwm_update_reg = 0x25, >>>>>>>>> + .global_control_reg = 0x4a, >>>>>>>>> + .reset_reg = 0x4f, >>>>>>>>> + .pwm_register_base = 0x05, >>>>>>>>> + .led_control_register_base = 0x2a, >>>>>>>>> + .enable_bits_per_led_control_register = 1, >>>>>>>>> +}; >>>>>>>>> + >>>>>>>>> +static const struct is31fl32xx_chipdef is31fl3218_cdef = { >>>>>>>>> + .channels = 18, >>>>>>>>> + .shutdown_reg = 0x00, >>>>>>>>> + .pwm_update_reg = 0x16, >>>>>>>>> + .global_control_reg = IS31FL32XX_REG_NONE, >>>>>>>>> + .reset_reg = 0x17, >>>>>>>>> + .pwm_register_base = 0x01, >>>>>>>>> + .led_control_register_base = 0x13, >>>>>>>>> + .enable_bits_per_led_control_register = 6, >>>>>>>>> +}; >>>>>>>>> + >>>>>>>>> +static int is31fl3216_reset(struct is31fl32xx_priv *priv); >>>>>>>>> +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, >>>>>>>>> + bool enable); >>>>>>>>> +static const struct is31fl32xx_chipdef is31fl3216_cdef = { >>>>>>>>> + .channels = 16, >>>>>>>>> + .shutdown_reg = IS31FL32XX_REG_NONE, >>>>>>>>> + .pwm_update_reg = 0xB0, >>>>>>>>> + .global_control_reg = IS31FL32XX_REG_NONE, >>>>>>>>> + .reset_reg = IS31FL32XX_REG_NONE, >>>>>>>>> + .pwm_register_base = 0x10, >>>>>>>>> + .pwm_registers_reversed = true, >>>>>>>>> + .led_control_register_base = 0x01, >>>>>>>>> + .enable_bits_per_led_control_register = 8, >>>>>>>>> + .reset_func = is31fl3216_reset, >>>>>>>>> + .sw_shutdown_func = is31fl3216_software_shutdown, >>>>>>>>> +}; >>>>>>>>> + >>>>>>>>> +static int is31fl32xx_write(struct is31fl32xx_priv *priv, u8 reg, u8 val) >>>>>>>>> +{ >>>>>>>>> + int ret; >>>>>>>>> + >>>>>>>>> + dev_dbg(&priv->client->dev, "writing register 0x%02X=0x%02X", reg, val); >>>>>>>>> + >>>>>>>>> + ret = i2c_smbus_write_byte_data(priv->client, reg, val); >>>>>>>>> + if (ret) { >>>>>>>>> + dev_err(&priv->client->dev, >>>>>>>>> + "register write to 0x%02X failed (error %d)", >>>>>>>>> + reg, ret); >>>>>>>>> + } >>>>>>>>> + return ret; >>>>>>>>> +} >>>>>>>>> + >>>>>>>>> +/* >>>>>>>>> + * Custom reset function for IS31FL3216 because it does not have a RESET >>>>>>>>> + * register the way that the other IS31FL32xx chips do. We don't bother >>>>>>>>> + * writing the GPIO and animation registers, because the registers we >>>>>>>>> + * do write ensure those will have no effect. >>>>>>>>> + */ >>>>>>>>> +static int is31fl3216_reset(struct is31fl32xx_priv *priv) >>>>>>>>> +{ >>>>>>>>> + unsigned int i; >>>>>>>>> + int ret; >>>>>>>>> + >>>>>>>>> + ret = is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, >>>>>>>>> + IS31FL3216_CONFIG_SSD_ENABLE); >>>>>>>>> + if (ret) >>>>>>>>> + return ret; >>>>>>>>> + for (i = 0; i < priv->cdef->channels; i++) { >>>>>>>>> + ret = is31fl32xx_write(priv, priv->cdef->pwm_register_base+i, >>>>>>>>> + 0x00); >>>>>>>>> + if (ret) >>>>>>>>> + return ret; >>>>>>>>> + } >>>>>>>>> + ret = is31fl32xx_write(priv, priv->cdef->pwm_update_reg, 0); >>>>>>>>> + if (ret) >>>>>>>>> + return ret; >>>>>>>>> + ret = is31fl32xx_write(priv, IS31FL3216_LIGHTING_EFFECT_REG, 0x00); >>>>>>>>> + if (ret) >>>>>>>>> + return ret; >>>>>>>>> + ret = is31fl32xx_write(priv, IS31FL3216_CHANNEL_CONFIG_REG, 0x00); >>>>>>>>> + if (ret) >>>>>>>>> + return ret; >>>>>>>>> + >>>>>>>>> + return 0; >>>>>>>>> +} >>>>>>>>> + >>>>>>>>> +/* >>>>>>>>> + * Custom Software-Shutdown function for IS31FL3216 because it does not have >>>>>>>>> + * a SHUTDOWN register the way that the other IS31FL32xx chips do. >>>>>>>>> + * We don't bother doing a read/modify/write on the CONFIG register because >>>>>>>>> + * we only ever use a value of '0' for the other fields in that register. >>>>>>>>> + */ >>>>>>>>> +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, >>>>>>>>> + bool enable) >>>>>>>>> +{ >>>>>>>>> + u8 value = enable ? IS31FL3216_CONFIG_SSD_ENABLE : >>>>>>>>> + IS31FL3216_CONFIG_SSD_DISABLE; >>>>>>>>> + >>>>>>>>> + return is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, value); >>>>>>>>> +} >>>>>>>>> + >>>>>>>>> +/* >>>>>>>>> + * NOTE: A mutex is not needed in this function because: >>>>>>>>> + * - All referenced data is read-only after probe() >>>>>>>>> + * - The I2C core has a mutex on to protect the bus >>>>>>>>> + * - There are no read/modify/write operations >>>>>>>>> + * - Intervening operations between the write of the PWM register >>>>>>>>> + * and the Update register are harmless. >>>>>>>>> + * >>>>>>>>> + * Example: >>>>>>>>> + * PWM_REG_1 write 16 >>>>>>>>> + * UPDATE_REG write 0 >>>>>>>>> + * PWM_REG_2 write 128 >>>>>>>>> + * UPDATE_REG write 0 >>>>>>>>> + * vs: >>>>>>>>> + * PWM_REG_1 write 16 >>>>>>>>> + * PWM_REG_2 write 128 >>>>>>>>> + * UPDATE_REG write 0 >>>>>>>>> + * UPDATE_REG write 0 >>>>>>>>> + * are equivalent. Poking the Update register merely applies all PWM >>>>>>>>> + * register writes up to that point. >>>>>>>>> + */ >>>>>>>>> +static int is31fl32xx_brightness_set(struct led_classdev *led_cdev, >>>>>>>>> + enum led_brightness brightness) >>>>>>>>> +{ >>>>>>>>> + const struct is31fl32xx_led_data *led_data = >>>>>>>>> + container_of(led_cdev, struct is31fl32xx_led_data, cdev); >>>>>>>>> + const struct is31fl32xx_chipdef *cdef = led_data->priv->cdef; >>>>>>>>> + u8 pwm_register_offset; >>>>>>>>> + int ret; >>>>>>>>> + >>>>>>>>> + dev_dbg(led_cdev->dev, "%s: %d\n", __func__, brightness); >>>>>>>>> + >>>>>>>>> + /* NOTE: led_data->channel is 1-based */ >>>>>>>>> + if (cdef->pwm_registers_reversed) >>>>>>>>> + pwm_register_offset = cdef->channels - led_data->channel; >>>>>>>>> + else >>>>>>>>> + pwm_register_offset = led_data->channel - 1; >>>>>>>>> + >>>>>>>>> + ret = is31fl32xx_write(led_data->priv, >>>>>>>>> + cdef->pwm_register_base + pwm_register_offset, >>>>>>>>> + brightness); >>>>>>>>> + if (ret) >>>>>>>>> + return ret; >>>>>>>>> + >>>>>>>>> + return is31fl32xx_write(led_data->priv, cdef->pwm_update_reg, 0); >>>>>>>>> +} >>>>>>>>> + >>>>>>>>> +static int is31fl32xx_reset_regs(struct is31fl32xx_priv *priv) >>>>>>>>> +{ >>>>>>>>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; >>>>>>>>> + int ret; >>>>>>>>> + >>>>>>>>> + if (cdef->reset_reg != IS31FL32XX_REG_NONE) { >>>>>>>>> + ret = is31fl32xx_write(priv, cdef->reset_reg, 0); >>>>>>>>> + if (ret) >>>>>>>>> + return ret; >>>>>>>>> + } >>>>>>>>> + >>>>>>>>> + if (cdef->reset_func) >>>>>>>>> + return cdef->reset_func(priv); >>>>>>>>> + >>>>>>>>> + return 0; >>>>>>>>> +} >>>>>>>>> + >>>>>>>>> +static int is31fl32xx_software_shutdown(struct is31fl32xx_priv *priv, >>>>>>>>> + bool enable) >>>>>>>>> +{ >>>>>>>>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; >>>>>>>>> + int ret; >>>>>>>>> + >>>>>>>>> + if (cdef->shutdown_reg != IS31FL32XX_REG_NONE) { >>>>>>>>> + u8 value = enable ? IS31FL32XX_SHUTDOWN_SSD_ENABLE : >>>>>>>>> + IS31FL32XX_SHUTDOWN_SSD_DISABLE; >>>>>>>>> + ret = is31fl32xx_write(priv, cdef->shutdown_reg, value); >>>>>>>>> + if (ret) >>>>>>>>> + return ret; >>>>>>>>> + } >>>>>>>>> + >>>>>>>>> + if (cdef->sw_shutdown_func) >>>>>>>>> + return cdef->sw_shutdown_func(priv, enable); >>>>>>>> >>>>>>>> You seem to call sw_shutdown_func only here, so why should we have >>>>>>>> enable parameter in this op? >>>>>>> >>>>>>> I'm not sure if I understand the question, but I will try to answer. >>>>>>> >>>>>>> 'enable' is passed through is31fl32xx_software_shutdown to >>>>>>> cdef->sw_shutdown_func, so it can be either true or false at that >>>>>>> point. The purpose of sw_shutdown_func is to add any special behavior >>>>>>> when enabling/disabling software-shutdown mode, which is needed for >>>>>>> the 3216 because its SSD bit is in a different position and with >>>>>>> opposite polarity. >>>>>>> >>>>>>> Is it that 'enable' in that line of code makes it look like it's being >>>>>>> called with an hardcoded value rather than a variable? If so, perhaps a >>>>>>> different parameter name would make it more obvious? Or a kerneldoc >>>>>>> comment for the function to describe the parameter? >>>>>>> >>>>>>> Or have I totally missed the point of the question? >>>>>> >>>>>> Actually I should have placed this question next to >>>>>> the call to s31fl32xx_software_shutdown() in is31fl32xx_init_regs(), >>>>>> which is passed "false" in the second argument, and there is no >>>>>> other call to s31fl32xx_software_shutdown() in the driver. >>>>>> >>>>>> Having the argument makes people wondering that there is some >>>>>> use case in the driver, where "true" is passed, but it seems not >>>>>> to be the case. >>>>> >>>>> Thanks for the clarification. >>>>> >>>>> Yes, there is currently no explicit call to enable software-shutdown >>>>> mode. Since the reset state of these devices is to have software-shutdown >>>>> enabled, the only explicit operation on it that's currently needed is >>>>> to disable it. >>>>> >>>>> Reasons I can think to have the 'enable' parameter anyways include: >>>>> - It seems logical to me that an API to manipulate the software-shutdown >>>>> state should allow both enabling and disabling. >>>>> - Having a parameter for that seemed the most obvious way to go, and it >>>>> was trivial to implement. >>>>> - Alternatively having separate "enable" and "disable" functions would >>>>> duplicate most of the logic, vs the parameter being just a single >>>>> conditional. And that would also imply two function pointers in the >>>>> chipdefs, which I'd prefer to minimize. >>>>> - If anyone wanted to implement suspend/resume in the future, they would >>>>> most likely do it by enabling/disabling software-shutdown. Supporting >>>>> both enable/disable from the start should make that trivial to do. >>>> >>>> Suspend/resume callbacks are already implemented in led-class.c and >>>> related ops indirectly call brightness_set. If you want to support >>>> suspend/resume you have to set LED_CORE_SUSPENDRESUME flag. >>> >>> If I understand correctly, all LED_CORE_SUSPENDRESUME will do is cause >>> the led core to set the brightness to 0 on suspend (and reverse that >>> on resume). I see some drivers use this flag and other do not. >>> This brings up the question in my mind: how would a driver decide >>> whether it is appropriate for an LED to go dark on suspend? Is that >>> just the drivers that know the logical purpose of the LEDs they control? >> >> There is a room for improvement here. Possibly a new LED class sysfs >> attribute could be of help in determining that. >> >>>> Setting brightness to 0 is equivalent to turning the LED controller >>>> in a shutdown mode, provided that all sub-LEDs are off. >>> >>> This is not strictly true for these devices. If someone cared very much >>> about power usage when suspended they may want to put the LED controller >>> into what it calls "shutdown mode" via the SSD bit. I didn't bother mainly >>> because I have no need, and also because I wasn't sure how to even trigger >>> a suspend in order to test an implementation. >> >> I meant that LED class driver should put the device in a software >> shutdown mode after last sub-LED is turned off. >> >>> FYI, I just measured it the effect of software-shutdown even with all LEDs >>> already off. The difference in current is about 5mA, measured at the 5V >>> supply to a 3216 eval board. Not huge, but someone might care. >> >> This can be vital difference for some use cases. You could count the >> number of currently active sub-LEDs and put the controller in a software >> shutdown mode in case the value is 0. > > I had thought about that, but I had some concerns that dissuaded me from > perusing it: > - Would need some way to know whether a brightness_set has changed an LED > from on->off or off->on in order to update that counter. leds-core > modifies led_cdev->brightness before calling brightness_set, so that > information would need to be somehow maintained in the driver. We could think of adding some generic mechanism to the LED core in the future. > - It requires an additional mutex to protect whatever data is involved in > the previous bullet. That mutex would need to be taken on every brightness > update. > - If a single LED is blinking rapidly (e.g. a cpu trigger), it would thrash > software shutdown mode. That in turn adds even more CPU usage (due to > register writes and mutexes), potentially making power usage worse in > some cases. > - Time it might take to implement and review (mostly depending on how the > first bullet is handled), especially since the 4.6 merge window is fast > approaching. Thanks for this analysis. The issue turns out to be non-trivial. > That said, I could propose the following simple-to-implement design: > - counter, and mutex to protect it, added to 'priv' > - previous_brightness field added to 'led_data' > - brightness_set compares new brightness vs previous > - if on/off state has changed: > - takes mutex > - updates counter > - sets software-shutdown mode to (counter==0) > - releases mutex > > If you think that's worth doing, I can try to get it in along with the > other changes for v2. This can be added as an incremental patch. As you noticed, the merge window is approaching and it would be good to have this driver in linux-next for some time before sending it to Linus. In view of the prospective improvements around shutdown mode please leave the related code as is. >>>>> - I thought the code read better with a bool parameter, vs a longer >>>>> function name. >>>>> >>>>> So nothing really critical, but mostly just my aesthetic and preference. >>>>> >>>>> Also, I expect that is31fl32xx_software_shutdown() would be inlined, so >>>>> the conditional check in there is optimized out anyways, and there is no >>>>> performance penalty. Looking at the disassembly in my ARMv7a build, both >>>>> of those have indeed happened there. >>>> >>>> Not only the size of a binary and the performance, but also code >>>> readability matters. The function is called only with false argument, >>>> so I expect that some people may submit patches optimizing this. >>>> >>>> Let's avoid the confusion. >>> >>> I guess we just have a difference of opinion on which way is more >>> readable, which is OK. Unless the above explanation causes you to >>> change your mind, I will remove the 'enable' parameter and add a >>> "_disable" suffix to both functions. That will also leave the >>> #define IS31FL32XX_SHUTDOWN_SSD_ENABLE 0 >>> constant unused in the code, should that also be removed? Note that >>> the 3216 specific constant >>> #define IS31FL3216_CONFIG_SSD_ENABLE BIT(7) >>> would still be used in is31fl3216_reset(). >> >> Current version of the function would be required for enabling >> shutting down the controller from brightness_set op when the >> count of active sub-LEDs drops to 0. > > Agreed. That's a reason I would have for leaving it so even if the > auto-software-shutdown logic is not implemented at this time. But I > would understand if you still prefer to only have the current form > if there is currently code which uses both possible values of the > 'enable' parameter. We can stay by the current implementation. >>>>>>>>> + return 0; >>>>>>>>> +} >>>>>>>>> + >>>>>>>>> +static int is31fl32xx_init_regs(struct is31fl32xx_priv *priv) >>>>>>>>> +{ >>>>>>>>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; >>>>>>>>> + int ret; >>>>>>>>> + >>>>>>>>> + ret = is31fl32xx_reset_regs(priv); >>>>>>>>> + if (ret) >>>>>>>>> + return ret; >>>>>>>>> + >>>>>>>>> + /* >>>>>>>>> + * Set enable bit for all channels. >>>>>>>>> + * We will control state with PWM registers alone. >>>>>>>>> + */ >>>>>>>>> + if (cdef->led_control_register_base != IS31FL32XX_REG_NONE) { >>>>>>>>> + u8 value = >>>>>>>>> + GENMASK(cdef->enable_bits_per_led_control_register-1, 0); >>>>>>>>> + u8 num_regs = cdef->channels / >>>>>>>>> + cdef->enable_bits_per_led_control_register; >>>>>>>>> + int i; >>>>>>>>> + >>>>>>>>> + for (i = 0; i < num_regs; i++) { >>>>>>>>> + ret = is31fl32xx_write(priv, >>>>>>>>> + cdef->led_control_register_base+i, >>>>>>>>> + value); >>>>>>>>> + if (ret) >>>>>>>>> + return ret; >>>>>>>>> + } >>>>>>>>> + } >>>>>>>>> + >>>>>>>>> + ret = is31fl32xx_software_shutdown(priv, false); >>>>>>>>> + if (ret) >>>>>>>>> + return ret; >>>>>>>>> + >>>>>>>>> + if (cdef->global_control_reg != IS31FL32XX_REG_NONE) { >>>>>>>>> + ret = is31fl32xx_write(priv, cdef->global_control_reg, 0x00); >>>>>>>>> + if (ret) >>>>>>>>> + return ret; >>>>>>>>> + } >>>>>>>>> + >>>>>>>>> + return 0; >>>>>>>>> +} >>>>>>>>> + >>>>>>>>> +static inline size_t sizeof_is31fl32xx_priv(int num_leds) >>>>>>>>> +{ >>>>>>>>> + return sizeof(struct is31fl32xx_priv) + >>>>>>>>> + (sizeof(struct is31fl32xx_led_data) * num_leds); >>>>>>>>> +} >>>>>>>>> + >>>>>>>>> +static int is31fl32xx_parse_child_dt(const struct device *dev, >>>>>>>>> + const struct device_node *child, >>>>>>>>> + struct is31fl32xx_led_data *led_data) >>>>>>>>> +{ >>>>>>>>> + struct led_classdev *cdev = &led_data->cdev; >>>>>>>>> + int ret = 0; >>>>>>>>> + u32 reg; >>>>>>>>> + >>>>>>>>> + if (of_property_read_string(child, "label", &cdev->name)) >>>>>>>>> + cdev->name = child->name; >>>>>>>>> + >>>>>>>>> + ret = of_property_read_u32(child, "reg", ®); >>>>>>>>> + if (ret || reg < 1 || reg > led_data->priv->cdef->channels) { >>>>>>>>> + dev_err(dev, >>>>>>>>> + "Child node %s does not have a valid reg property\n", >>>>>>>>> + child->full_name); >>>>>>>>> + return -EINVAL; >>>>>>>>> + } >>>>>>>>> + led_data->channel = reg; >>>>>>>>> + >>>>>>>>> + of_property_read_string(child, "linux,default-trigger", >>>>>>>>> + &cdev->default_trigger); >>>>>>>>> + >>>>>>>>> + cdev->brightness_set_blocking = is31fl32xx_brightness_set; >>>>>>>>> + >>>>>>>>> + return 0; >>>>>>>>> +} >>>>>>>>> + >>>>>>>>> +static struct is31fl32xx_led_data *is31fl32xx_find_led_data( >>>>>>>>> + struct is31fl32xx_priv *priv, >>>>>>>>> + u8 channel) >>>>>>>>> +{ >>>>>>>>> + size_t i; >>>>>>>>> + >>>>>>>>> + for (i = 0; i < priv->num_leds; i++) { >>>>>>>>> + if (priv->leds[i].channel == channel) >>>>>>>>> + return &priv->leds[i]; >>>>>>>>> + } >>>>>>>>> + >>>>>>>>> + return NULL; >>>>>>>>> +} >>>>>>>>> + >>>>>>>>> +static int is31fl32xx_parse_dt(struct device *dev, >>>>>>>>> + struct is31fl32xx_priv *priv) >>>>>>>>> +{ >>>>>>>>> + struct device_node *child; >>>>>>>>> + int ret = 0; >>>>>>>>> + >>>>>>>>> + for_each_child_of_node(dev->of_node, child) { >>>>>>>>> + struct is31fl32xx_led_data *led_data = >>>>>>>>> + &priv->leds[priv->num_leds]; >>>>>>>>> + const struct is31fl32xx_led_data *other_led_data; >>>>>>>>> + >>>>>>>>> + led_data->priv = priv; >>>>>>>>> + >>>>>>>>> + ret = is31fl32xx_parse_child_dt(dev, child, led_data); >>>>>>>>> + if (ret) >>>>>>>>> + goto err; >>>>>>>>> + >>>>>>>>> + /* Detect if channel is already in use by another child */ >>>>>>>>> + other_led_data = is31fl32xx_find_led_data(priv, >>>>>>>>> + led_data->channel); >>>>>>>>> + if (other_led_data) { >>>>>>>>> + dev_err(dev, >>>>>>>>> + "%s and %s both attempting to use channel %d\n", >>>>>>>>> + led_data->cdev.name, >>>>>>>>> + other_led_data->cdev.name, >>>>>>>>> + led_data->channel); >>>>>>>>> + goto err; >>>>>>>>> + } >>>>>>>>> + >>>>>>>>> + ret = devm_led_classdev_register(dev, &led_data->cdev); >>>>>>>>> + if (ret) { >>>>>>>>> + dev_err(dev, "failed to register PWM led for %s: %d\n", >>>>>>>>> + led_data->cdev.name, ret); >>>>>>>>> + goto err; >>>>>>>>> + } >>>>>>>>> + >>>>>>>>> + priv->num_leds++; >>>>>>>>> + } >>>>>>>>> + >>>>>>>>> + return 0; >>>>>>>>> + >>>>>>>>> +err: >>>>>>>>> + of_node_put(child); >>>>>>>>> + return ret; >>>>>>>>> +} >>>>>>>>> + >>>>>>>>> +static const struct of_device_id of_is31fl31xx_match[] = { >>>>>>>>> + { .compatible = "issi,is31fl3236", .data = &is31fl3236_cdef, }, >>>>>>>>> + { .compatible = "issi,is31fl3235", .data = &is31fl3235_cdef, }, >>>>>>>>> + { .compatible = "issi,is31fl3218", .data = &is31fl3218_cdef, }, >>>>>>>>> + { .compatible = "issi,is31fl3216", .data = &is31fl3216_cdef, }, >>>>>>>>> + {}, >>>>>>>>> +}; >>>>>>>>> + >>>>>>>>> +MODULE_DEVICE_TABLE(of, of_is31fl31xx_match); >>>>>>>>> + >>>>>>>>> +static int is31fl32xx_probe(struct i2c_client *client, >>>>>>>>> + const struct i2c_device_id *id) >>>>>>>>> +{ >>>>>>>>> + const struct is31fl32xx_chipdef *cdef; >>>>>>>>> + const struct of_device_id *of_dev_id; >>>>>>>>> + struct device *dev = &client->dev; >>>>>>>>> + struct is31fl32xx_priv *priv; >>>>>>>>> + int count; >>>>>>>>> + int ret = 0; >>>>>>>>> + >>>>>>>>> + of_dev_id = of_match_device(of_is31fl31xx_match, dev); >>>>>>>>> + if (!of_dev_id) >>>>>>>>> + return -EINVAL; >>>>>>>>> + >>>>>>>>> + cdef = of_dev_id->data; >>>>>>>>> + >>>>>>>>> + count = of_get_child_count(dev->of_node); >>>>>>>>> + if (!count) >>>>>>>>> + return -EINVAL; >>>>>>>>> + >>>>>>>>> + priv = devm_kzalloc(dev, sizeof_is31fl32xx_priv(count), >>>>>>>>> + GFP_KERNEL); >>>>>>>>> + if (!priv) >>>>>>>>> + return -ENOMEM; >>>>>>>>> + >>>>>>>>> + priv->client = client; >>>>>>>>> + priv->cdef = cdef; >>>>>>>>> + i2c_set_clientdata(client, priv); >>>>>>>>> + >>>>>>>>> + ret = is31fl32xx_init_regs(priv); >>>>>>>>> + if (ret) >>>>>>>>> + return ret; >>>>>>>>> + >>>>>>>>> + ret = is31fl32xx_parse_dt(dev, priv); >>>>>>>>> + if (ret) >>>>>>>>> + return ret; >>>>>>>>> + >>>>>>>>> + return 0; >>>>>>>>> +} >>>>>>>>> + >>>>>>>>> +static int is31fl32xx_remove(struct i2c_client *client) >>>>>>>>> +{ >>>>>>>>> + struct is31fl32xx_priv *priv = i2c_get_clientdata(client); >>>>>>>>> + >>>>>>>>> + return is31fl32xx_reset_regs(priv); >>>>>>>>> +} >>>>>>>>> + >>>>>>>>> +/* >>>>>>>>> + * i2c-core requires that id_table be non-NULL, even though >>>>>>>>> + * it is not used for DeviceTree based instantiation. >>>>>>>>> + */ >>>>>>>>> +static const struct i2c_device_id is31fl31xx_id[] = { >>>>>>>>> + {}, >>>>>>>>> +}; >>>>>>>>> + >>>>>>>>> +MODULE_DEVICE_TABLE(i2c, is31fl31xx_id); >>>>>>>>> + >>>>>>>>> +static struct i2c_driver is31fl32xx_driver = { >>>>>>>>> + .driver = { >>>>>>>>> + .name = "is31fl32xx", >>>>>>>>> + .of_match_table = of_is31fl31xx_match, >>>>>>>>> + }, >>>>>>>>> + .probe = is31fl32xx_probe, >>>>>>>>> + .remove = is31fl32xx_remove, >>>>>>>>> + .id_table = is31fl31xx_id, >>>>>>>>> +}; >>>>>>>>> + >>>>>>>>> +module_i2c_driver(is31fl32xx_driver); >>>>>>>>> + >>>>>>>>> +MODULE_AUTHOR("David Rivshin <drivshin@allworx.com>"); >>>>>>>>> +MODULE_DESCRIPTION("ISSI IS31FL32xx LED driver"); >>>>>>>>> +MODULE_LICENSE("GPL v2"); >>>>>>>>> > -- Best Regards, Jacek Anaszewski ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 3/4] leds: Add driver for the ISSI IS31FL32xx family of LED controllers 2016-03-03 3:01 ` [PATCH 3/4] leds: Add driver " David Rivshin (Allworx) 2016-03-03 3:21 ` kbuild test robot 2016-03-03 14:51 ` Jacek Anaszewski @ 2016-03-03 18:13 ` Stefan Wahren 2016-03-04 14:27 ` David Rivshin (Allworx) 2 siblings, 1 reply; 28+ messages in thread From: Stefan Wahren @ 2016-03-03 18:13 UTC (permalink / raw) To: linux-leds, David Rivshin (Allworx), devicetree Cc: Pawel Moll, Rob Herring, Ian Campbell, Kumar Gala, linux-kernel, Jacek Anaszewski, Richard Purdie, Mark Rutland Hi David, i will test the driver on weekend. Some comments below > "David Rivshin (Allworx)" <drivshin.allworx@gmail.com> hat am 3. März 2016 um > 04:01 geschrieben: > > > From: David Rivshin <drivshin@allworx.com> > > The IS31FL32xx family of LED controllers are I2C devices with multiple > constant-current channels, each with independent 256-level PWM control. > > Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml > > This has been tested on the IS31FL3236 and IS31FL3216, on an ARM > (TI am335x) platform. > > The programming paradigm of these devices is similar in the following > ways: > - All registers are 8 bit > - All LED control registers are write-only > - Each LED channel has a PWM register (0-255) > - PWM register writes are shadowed until an Update register is poked > - All have a concept of Software Shutdown, which disables output > > However, there are some differences in devices: > - 3236/3235 have a separate Control register for each LED, > (3218/3216 pack the enable bits into fewer registers) > - 3236/3235 have a per-channel current divisor setting > - 3236/3235 have a Global Control register that can turn off all LEDs > - 3216 is unique in a number of ways > - OUT9-OUT16 can be configured as GPIOs instead of LED controls > - LEDs can be programmed with an 8-frame animation, with > programmable delay between frames > - LEDs can be modulated by an input audio signal > - Max output current can be adjusted from 1/4 to 2x globally > - Has a Configuration register instead of a Shutdown register > > This driver currently only supports the base PWM control function > of these devices. The following features of these devices are not > implemented, although it should be possible to add them in the future: > - All devices are capable of going into a lower-power "software > shutdown" mode. > - The is31fl3236 and is31fl3235 can reduce the max output current > per-channel with a divisor of 1, 2, 3, or 4. > - The is31fl3216 can use some LED channels as GPIOs instead. > - The is31fl3216 can animate LEDs in hardware. > - The is31fl3216 can modulate LEDs according to an audio input. > - The is31fl3216 can reduce/increase max output current globally. > > Signed-off-by: David Rivshin <drivshin@allworx.com> > --- > > You may see two instances of this warning: > "passing argument 1 of 'of_property_read_string' discards 'const' > qualifier from pointer target type" > That is a result of of_property_read_string() taking a non-const > struct device_node pointer parameter. I have separately submitted a > patch to fix that [1], and a few related functions which had the same > issue. I'm hoping that will get into linux-next before this does, so > that the warnings never show up there. > > Changes from RFC: > - Removed max-brightness DT property. > - Refer to these devices as "LED controllers" in Kconfig. > - Removed redundant last sentence from Kconfig entry > - Removed unnecessary debug code. > - Do not set led_classdev.brightness to 0 explicitly, as it is > already initialized to 0 by devm_kzalloc(). > - Used of_property_read_string() instead of of_get_property(). > - Fail immediately on DT parsing error in a child node, rather than > continuing on with the non-faulty ones. > - Added additional comments for some things that might be non-obvious. > - Added constants for the location of the SSD bit in the SHUTDOWN > register, and the 3216's CONFIG register. > - Added special sw_shutdown_func for the 3216 device, as that bit > is in a different register, at a different position, and has reverse > polarity compared to all the other devices. > - Refactored is31fl32xx_init_regs() to separate out some logic into > is31fl32xx_reset_regs() and is31fl32xx_software_shutdown(). > > [1] https://lkml.org/lkml/2016/3/2/746 > > drivers/leds/Kconfig | 8 + > drivers/leds/Makefile | 1 + > drivers/leds/leds-is31fl32xx.c | 505 +++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 514 insertions(+) > create mode 100644 drivers/leds/leds-is31fl32xx.c > > diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig > index 1034696..9c63ba4 100644 > --- a/drivers/leds/Kconfig > +++ b/drivers/leds/Kconfig > @@ -580,6 +580,14 @@ config LEDS_SN3218 > This driver can also be built as a module. If so the module > will be called leds-sn3218. > > +config LEDS_IS31FL32XX > + tristate "LED support for ISSI IS31FL32XX I2C LED controller family" > + depends on LEDS_CLASS && I2C && OF > + help > + Say Y here to include support for ISSI IS31FL32XX LED controllers. > + They are I2C devices with multiple constant-current channels, each > + with independent 256-level PWM control. Is it worth to mention the module name here? > + > comment "LED driver for blink(1) USB RGB LED is under Special HID drivers > (HID_THINGM)" > > config LEDS_BLINKM > diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile > index 89c9b6f..3fdf313 100644 > --- a/drivers/leds/Makefile > +++ b/drivers/leds/Makefile > @@ -67,6 +67,7 @@ obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o > obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o > obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o > obj-$(CONFIG_LEDS_SN3218) += leds-sn3218.o > +obj-$(CONFIG_LEDS_IS31FL32XX) += leds-is31fl32xx.o > > # LED SPI Drivers > obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o > diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c > new file mode 100644 > index 0000000..49818f0 > --- /dev/null > +++ b/drivers/leds/leds-is31fl32xx.c > @@ -0,0 +1,505 @@ > +/* > + * linux/drivers/leds-is31fl32xx.c I think this is unnecessary. > + * > + * Driver for ISSI IS31FL32xx family of I2C LED controllers > + * > + * Copyright 2015 Allworx Corp. > + * > + * > + * 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. > + * > + * Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml > + */ > + Shouldn't we include <linux/device.h> here? > +#include <linux/err.h> > +#include <linux/i2c.h> > +#include <linux/kernel.h> > +#include <linux/leds.h> > +#include <linux/module.h> > +#include <linux/of_platform.h> > + > +/* Used to indicate a device has no such register */ > +#define IS31FL32XX_REG_NONE 0xFF > + > +/* Software Shutdown bit in Shutdown Register */ > +#define IS31FL32XX_SHUTDOWN_SSD_ENABLE 0 > +#define IS31FL32XX_SHUTDOWN_SSD_DISABLE BIT(0) > + > +/* IS31FL3216 has a number of unique registers */ > +#define IS31FL3216_CONFIG_REG 0x00 > +#define IS31FL3216_LIGHTING_EFFECT_REG 0x03 > +#define IS31FL3216_CHANNEL_CONFIG_REG 0x04 > + > +/* Software Shutdown bit in 3216 Config Register */ > +#define IS31FL3216_CONFIG_SSD_ENABLE BIT(7) > +#define IS31FL3216_CONFIG_SSD_DISABLE 0 > + > +struct is31fl32xx_priv; > +struct is31fl32xx_led_data { > + struct led_classdev cdev; > + u8 channel; /* 1-based, max priv->cdef->channels */ > + struct is31fl32xx_priv *priv; > +}; > + > +struct is31fl32xx_priv { > + const struct is31fl32xx_chipdef *cdef; > + struct i2c_client *client; > + unsigned int num_leds; > + struct is31fl32xx_led_data leds[0]; > +}; > + > +/** > + * struct is31fl32xx_chipdef - chip-specific attributes > + * @channels : Number of LED channels > + * @shutdown_reg : address of Shutdown register (optional) > + * @pwm_update_reg : address of PWM Update register > + * @global_control_reg : address of Global Control register (optional) > + * @reset_reg : address of Reset register (optional) > + * @pwm_register_base : address of first PWM register > + * @pwm_registers_reversed: : true if PWM registers count down instead of up > + * @led_control_register_base : address of first LED control register > (optional) > + * @enable_bits_per_led_control_register: number of LEDs enable bits in each > + * @reset_func: : pointer to reset function > + * > + * For all optional register addresses, the sentinel value > %IS31FL32XX_REG_NONE > + * indicates that this chip has no such register. > + * > + * If non-NULL, @reset_func will be called during probing to set all > + * necessary registers to a known initialization state. This is needed > + * for chips that do not have a @reset_reg. > + * > + * @enable_bits_per_led_control_register must be >=1 if > + * @led_control_register_base != %IS31FL32XX_REG_NONE. > + */ > +struct is31fl32xx_chipdef { > + u8 channels; > + u8 shutdown_reg; > + u8 pwm_update_reg; > + u8 global_control_reg; > + u8 reset_reg; > + u8 pwm_register_base; > + bool pwm_registers_reversed; > + u8 led_control_register_base; > + u8 enable_bits_per_led_control_register; > + int (*reset_func)(struct is31fl32xx_priv *priv); > + int (*sw_shutdown_func)(struct is31fl32xx_priv *priv, bool enable); > +}; > + > +static const struct is31fl32xx_chipdef is31fl3236_cdef = { > + .channels = 36, > + .shutdown_reg = 0x00, > + .pwm_update_reg = 0x25, > + .global_control_reg = 0x4a, > + .reset_reg = 0x4f, > + .pwm_register_base = 0x01, > + .led_control_register_base = 0x26, > + .enable_bits_per_led_control_register = 1, > +}; > + > +static const struct is31fl32xx_chipdef is31fl3235_cdef = { > + .channels = 28, > + .shutdown_reg = 0x00, > + .pwm_update_reg = 0x25, > + .global_control_reg = 0x4a, > + .reset_reg = 0x4f, > + .pwm_register_base = 0x05, > + .led_control_register_base = 0x2a, > + .enable_bits_per_led_control_register = 1, > +}; > + > +static const struct is31fl32xx_chipdef is31fl3218_cdef = { > + .channels = 18, > + .shutdown_reg = 0x00, > + .pwm_update_reg = 0x16, > + .global_control_reg = IS31FL32XX_REG_NONE, > + .reset_reg = 0x17, > + .pwm_register_base = 0x01, > + .led_control_register_base = 0x13, > + .enable_bits_per_led_control_register = 6, > +}; > + > +static int is31fl3216_reset(struct is31fl32xx_priv *priv); > +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, > + bool enable); > +static const struct is31fl32xx_chipdef is31fl3216_cdef = { > + .channels = 16, > + .shutdown_reg = IS31FL32XX_REG_NONE, > + .pwm_update_reg = 0xB0, > + .global_control_reg = IS31FL32XX_REG_NONE, > + .reset_reg = IS31FL32XX_REG_NONE, > + .pwm_register_base = 0x10, > + .pwm_registers_reversed = true, > + .led_control_register_base = 0x01, > + .enable_bits_per_led_control_register = 8, > + .reset_func = is31fl3216_reset, > + .sw_shutdown_func = is31fl3216_software_shutdown, > +}; > + > +static int is31fl32xx_write(struct is31fl32xx_priv *priv, u8 reg, u8 val) > +{ > + int ret; > + > + dev_dbg(&priv->client->dev, "writing register 0x%02X=0x%02X", reg, val); > + > + ret = i2c_smbus_write_byte_data(priv->client, reg, val); > + if (ret) { > + dev_err(&priv->client->dev, > + "register write to 0x%02X failed (error %d)", > + reg, ret); > + } In case somebody use this driver as heartbeat and writing fails permanently the log will be flooded. > + return ret; > +} > + > +/* > + * Custom reset function for IS31FL3216 because it does not have a RESET > + * register the way that the other IS31FL32xx chips do. We don't bother > + * writing the GPIO and animation registers, because the registers we > + * do write ensure those will have no effect. > + */ > +static int is31fl3216_reset(struct is31fl32xx_priv *priv) > +{ > + unsigned int i; > + int ret; > + > + ret = is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, > + IS31FL3216_CONFIG_SSD_ENABLE); > + if (ret) > + return ret; > + for (i = 0; i < priv->cdef->channels; i++) { > + ret = is31fl32xx_write(priv, priv->cdef->pwm_register_base+i, > + 0x00); > + if (ret) > + return ret; > + } > + ret = is31fl32xx_write(priv, priv->cdef->pwm_update_reg, 0); > + if (ret) > + return ret; > + ret = is31fl32xx_write(priv, IS31FL3216_LIGHTING_EFFECT_REG, 0x00); > + if (ret) > + return ret; > + ret = is31fl32xx_write(priv, IS31FL3216_CHANNEL_CONFIG_REG, 0x00); > + if (ret) > + return ret; > + > + return 0; > +} > + > +/* > + * Custom Software-Shutdown function for IS31FL3216 because it does not have > + * a SHUTDOWN register the way that the other IS31FL32xx chips do. > + * We don't bother doing a read/modify/write on the CONFIG register because > + * we only ever use a value of '0' for the other fields in that register. > + */ > +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, > + bool enable) > +{ > + u8 value = enable ? IS31FL3216_CONFIG_SSD_ENABLE : > + IS31FL3216_CONFIG_SSD_DISABLE; > + > + return is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, value); > +} > + > +/* > + * NOTE: A mutex is not needed in this function because: > + * - All referenced data is read-only after probe() > + * - The I2C core has a mutex on to protect the bus > + * - There are no read/modify/write operations > + * - Intervening operations between the write of the PWM register > + * and the Update register are harmless. > + * > + * Example: > + * PWM_REG_1 write 16 > + * UPDATE_REG write 0 > + * PWM_REG_2 write 128 > + * UPDATE_REG write 0 > + * vs: > + * PWM_REG_1 write 16 > + * PWM_REG_2 write 128 > + * UPDATE_REG write 0 > + * UPDATE_REG write 0 > + * are equivalent. Poking the Update register merely applies all PWM > + * register writes up to that point. > + */ > +static int is31fl32xx_brightness_set(struct led_classdev *led_cdev, > + enum led_brightness brightness) > +{ > + const struct is31fl32xx_led_data *led_data = > + container_of(led_cdev, struct is31fl32xx_led_data, cdev); > + const struct is31fl32xx_chipdef *cdef = led_data->priv->cdef; > + u8 pwm_register_offset; > + int ret; > + > + dev_dbg(led_cdev->dev, "%s: %d\n", __func__, brightness); > + > + /* NOTE: led_data->channel is 1-based */ > + if (cdef->pwm_registers_reversed) > + pwm_register_offset = cdef->channels - led_data->channel; > + else > + pwm_register_offset = led_data->channel - 1; > + > + ret = is31fl32xx_write(led_data->priv, > + cdef->pwm_register_base + pwm_register_offset, > + brightness); > + if (ret) > + return ret; > + > + return is31fl32xx_write(led_data->priv, cdef->pwm_update_reg, 0); > +} > + > +static int is31fl32xx_reset_regs(struct is31fl32xx_priv *priv) > +{ > + const struct is31fl32xx_chipdef *cdef = priv->cdef; > + int ret; > + > + if (cdef->reset_reg != IS31FL32XX_REG_NONE) { > + ret = is31fl32xx_write(priv, cdef->reset_reg, 0); > + if (ret) > + return ret; > + } > + > + if (cdef->reset_func) > + return cdef->reset_func(priv); > + > + return 0; > +} > + > +static int is31fl32xx_software_shutdown(struct is31fl32xx_priv *priv, > + bool enable) > +{ > + const struct is31fl32xx_chipdef *cdef = priv->cdef; > + int ret; > + > + if (cdef->shutdown_reg != IS31FL32XX_REG_NONE) { > + u8 value = enable ? IS31FL32XX_SHUTDOWN_SSD_ENABLE : > + IS31FL32XX_SHUTDOWN_SSD_DISABLE; > + ret = is31fl32xx_write(priv, cdef->shutdown_reg, value); > + if (ret) > + return ret; > + } > + > + if (cdef->sw_shutdown_func) > + return cdef->sw_shutdown_func(priv, enable); > + > + return 0; > +} > + > +static int is31fl32xx_init_regs(struct is31fl32xx_priv *priv) > +{ > + const struct is31fl32xx_chipdef *cdef = priv->cdef; > + int ret; > + > + ret = is31fl32xx_reset_regs(priv); > + if (ret) > + return ret; > + > + /* > + * Set enable bit for all channels. > + * We will control state with PWM registers alone. > + */ > + if (cdef->led_control_register_base != IS31FL32XX_REG_NONE) { > + u8 value = > + GENMASK(cdef->enable_bits_per_led_control_register-1, 0); > + u8 num_regs = cdef->channels / > + cdef->enable_bits_per_led_control_register; > + int i; > + > + for (i = 0; i < num_regs; i++) { > + ret = is31fl32xx_write(priv, > + cdef->led_control_register_base+i, > + value); > + if (ret) > + return ret; > + } > + } > + > + ret = is31fl32xx_software_shutdown(priv, false); > + if (ret) > + return ret; > + > + if (cdef->global_control_reg != IS31FL32XX_REG_NONE) { > + ret = is31fl32xx_write(priv, cdef->global_control_reg, 0x00); > + if (ret) > + return ret; > + } > + > + return 0; > +} > + > +static inline size_t sizeof_is31fl32xx_priv(int num_leds) > +{ > + return sizeof(struct is31fl32xx_priv) + > + (sizeof(struct is31fl32xx_led_data) * num_leds); > +} > + > +static int is31fl32xx_parse_child_dt(const struct device *dev, > + const struct device_node *child, > + struct is31fl32xx_led_data *led_data) > +{ > + struct led_classdev *cdev = &led_data->cdev; > + int ret = 0; > + u32 reg; > + > + if (of_property_read_string(child, "label", &cdev->name)) > + cdev->name = child->name; > + > + ret = of_property_read_u32(child, "reg", ®); > + if (ret || reg < 1 || reg > led_data->priv->cdef->channels) { > + dev_err(dev, > + "Child node %s does not have a valid reg property\n", > + child->full_name); > + return -EINVAL; > + } > + led_data->channel = reg; > + > + of_property_read_string(child, "linux,default-trigger", > + &cdev->default_trigger); > + > + cdev->brightness_set_blocking = is31fl32xx_brightness_set; > + > + return 0; > +} > + > +static struct is31fl32xx_led_data *is31fl32xx_find_led_data( > + struct is31fl32xx_priv *priv, > + u8 channel) > +{ > + size_t i; > + > + for (i = 0; i < priv->num_leds; i++) { > + if (priv->leds[i].channel == channel) > + return &priv->leds[i]; > + } > + > + return NULL; > +} > + > +static int is31fl32xx_parse_dt(struct device *dev, > + struct is31fl32xx_priv *priv) > +{ > + struct device_node *child; > + int ret = 0; > + > + for_each_child_of_node(dev->of_node, child) { > + struct is31fl32xx_led_data *led_data = > + &priv->leds[priv->num_leds]; Maybe i missed something, but is it really protected against out of index access? > + const struct is31fl32xx_led_data *other_led_data; > + > + led_data->priv = priv; > + > + ret = is31fl32xx_parse_child_dt(dev, child, led_data); > + if (ret) > + goto err; > + > + /* Detect if channel is already in use by another child */ > + other_led_data = is31fl32xx_find_led_data(priv, > + led_data->channel); > + if (other_led_data) { > + dev_err(dev, > + "%s and %s both attempting to use channel %d\n", > + led_data->cdev.name, > + other_led_data->cdev.name, > + led_data->channel); > + goto err; > + } > + > + ret = devm_led_classdev_register(dev, &led_data->cdev); > + if (ret) { > + dev_err(dev, "failed to register PWM led for %s: %d\n", > + led_data->cdev.name, ret); > + goto err; > + } > + > + priv->num_leds++; > + } > + > + return 0; > + > +err: > + of_node_put(child); > + return ret; > +} > + > +static const struct of_device_id of_is31fl31xx_match[] = { > + { .compatible = "issi,is31fl3236", .data = &is31fl3236_cdef, }, > + { .compatible = "issi,is31fl3235", .data = &is31fl3235_cdef, }, > + { .compatible = "issi,is31fl3218", .data = &is31fl3218_cdef, }, > + { .compatible = "issi,is31fl3216", .data = &is31fl3216_cdef, }, > + {}, > +}; > + > +MODULE_DEVICE_TABLE(of, of_is31fl31xx_match); > + > +static int is31fl32xx_probe(struct i2c_client *client, > + const struct i2c_device_id *id) > +{ > + const struct is31fl32xx_chipdef *cdef; > + const struct of_device_id *of_dev_id; > + struct device *dev = &client->dev; > + struct is31fl32xx_priv *priv; > + int count; > + int ret = 0; > + > + of_dev_id = of_match_device(of_is31fl31xx_match, dev); > + if (!of_dev_id) > + return -EINVAL; > + > + cdef = of_dev_id->data; > + > + count = of_get_child_count(dev->of_node); > + if (!count) > + return -EINVAL; > + > + priv = devm_kzalloc(dev, sizeof_is31fl32xx_priv(count), > + GFP_KERNEL); > + if (!priv) > + return -ENOMEM; > + > + priv->client = client; > + priv->cdef = cdef; > + i2c_set_clientdata(client, priv); > + > + ret = is31fl32xx_init_regs(priv); > + if (ret) > + return ret; > + > + ret = is31fl32xx_parse_dt(dev, priv); > + if (ret) > + return ret; > + > + return 0; > +} > + > +static int is31fl32xx_remove(struct i2c_client *client) > +{ > + struct is31fl32xx_priv *priv = i2c_get_clientdata(client); > + > + return is31fl32xx_reset_regs(priv); > +} > + > +/* > + * i2c-core requires that id_table be non-NULL, even though > + * it is not used for DeviceTree based instantiation. > + */ > +static const struct i2c_device_id is31fl31xx_id[] = { > + {}, > +}; > + > +MODULE_DEVICE_TABLE(i2c, is31fl31xx_id); > + > +static struct i2c_driver is31fl32xx_driver = { > + .driver = { > + .name = "is31fl32xx", > + .of_match_table = of_is31fl31xx_match, > + }, > + .probe = is31fl32xx_probe, > + .remove = is31fl32xx_remove, Sorry, what was the reason to skip shutdown? Thanks Stefan > + .id_table = is31fl31xx_id, > +}; > + > +module_i2c_driver(is31fl32xx_driver); > + > +MODULE_AUTHOR("David Rivshin <drivshin@allworx.com>"); > +MODULE_DESCRIPTION("ISSI IS31FL32xx LED driver"); > +MODULE_LICENSE("GPL v2"); > -- > 2.5.0 > ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 3/4] leds: Add driver for the ISSI IS31FL32xx family of LED controllers 2016-03-03 18:13 ` Stefan Wahren @ 2016-03-04 14:27 ` David Rivshin (Allworx) 2016-03-04 15:38 ` Jacek Anaszewski 0 siblings, 1 reply; 28+ messages in thread From: David Rivshin (Allworx) @ 2016-03-04 14:27 UTC (permalink / raw) To: Stefan Wahren, Jacek Anaszewski Cc: linux-leds, devicetree, Pawel Moll, Rob Herring, Ian Campbell, Kumar Gala, linux-kernel, Richard Purdie, Mark Rutland (Stefan, sorry for the duplicate, I just realized that I originally replied only to you by accident). On Thu, 3 Mar 2016 19:13:03 +0100 (CET) Stefan Wahren <stefan.wahren@i2se.com> wrote: > Hi David, > > i will test the driver on weekend. Some comments below Great, thanks very much. > > "David Rivshin (Allworx)" <drivshin.allworx@gmail.com> hat am 3. März 2016 um > > 04:01 geschrieben: > > > > > > From: David Rivshin <drivshin@allworx.com> > > > > The IS31FL32xx family of LED controllers are I2C devices with multiple > > constant-current channels, each with independent 256-level PWM control. > > > > Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml > > > > This has been tested on the IS31FL3236 and IS31FL3216, on an ARM > > (TI am335x) platform. > > > > The programming paradigm of these devices is similar in the following > > ways: > > - All registers are 8 bit > > - All LED control registers are write-only > > - Each LED channel has a PWM register (0-255) > > - PWM register writes are shadowed until an Update register is poked > > - All have a concept of Software Shutdown, which disables output > > > > However, there are some differences in devices: > > - 3236/3235 have a separate Control register for each LED, > > (3218/3216 pack the enable bits into fewer registers) > > - 3236/3235 have a per-channel current divisor setting > > - 3236/3235 have a Global Control register that can turn off all LEDs > > - 3216 is unique in a number of ways > > - OUT9-OUT16 can be configured as GPIOs instead of LED controls > > - LEDs can be programmed with an 8-frame animation, with > > programmable delay between frames > > - LEDs can be modulated by an input audio signal > > - Max output current can be adjusted from 1/4 to 2x globally > > - Has a Configuration register instead of a Shutdown register > > > > This driver currently only supports the base PWM control function > > of these devices. The following features of these devices are not > > implemented, although it should be possible to add them in the future: > > - All devices are capable of going into a lower-power "software > > shutdown" mode. > > - The is31fl3236 and is31fl3235 can reduce the max output current > > per-channel with a divisor of 1, 2, 3, or 4. > > - The is31fl3216 can use some LED channels as GPIOs instead. > > - The is31fl3216 can animate LEDs in hardware. > > - The is31fl3216 can modulate LEDs according to an audio input. > > - The is31fl3216 can reduce/increase max output current globally. > > > > Signed-off-by: David Rivshin <drivshin@allworx.com> > > --- > > > > You may see two instances of this warning: > > "passing argument 1 of 'of_property_read_string' discards 'const' > > qualifier from pointer target type" > > That is a result of of_property_read_string() taking a non-const > > struct device_node pointer parameter. I have separately submitted a > > patch to fix that [1], and a few related functions which had the same > > issue. I'm hoping that will get into linux-next before this does, so > > that the warnings never show up there. > > > > Changes from RFC: > > - Removed max-brightness DT property. > > - Refer to these devices as "LED controllers" in Kconfig. > > - Removed redundant last sentence from Kconfig entry > > - Removed unnecessary debug code. > > - Do not set led_classdev.brightness to 0 explicitly, as it is > > already initialized to 0 by devm_kzalloc(). > > - Used of_property_read_string() instead of of_get_property(). > > - Fail immediately on DT parsing error in a child node, rather than > > continuing on with the non-faulty ones. > > - Added additional comments for some things that might be non-obvious. > > - Added constants for the location of the SSD bit in the SHUTDOWN > > register, and the 3216's CONFIG register. > > - Added special sw_shutdown_func for the 3216 device, as that bit > > is in a different register, at a different position, and has reverse > > polarity compared to all the other devices. > > - Refactored is31fl32xx_init_regs() to separate out some logic into > > is31fl32xx_reset_regs() and is31fl32xx_software_shutdown(). > > > > [1] https://lkml.org/lkml/2016/3/2/746 > > > > drivers/leds/Kconfig | 8 + > > drivers/leds/Makefile | 1 + > > drivers/leds/leds-is31fl32xx.c | 505 +++++++++++++++++++++++++++++++++++++++++ > > 3 files changed, 514 insertions(+) > > create mode 100644 drivers/leds/leds-is31fl32xx.c > > > > diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig > > index 1034696..9c63ba4 100644 > > --- a/drivers/leds/Kconfig > > +++ b/drivers/leds/Kconfig > > @@ -580,6 +580,14 @@ config LEDS_SN3218 > > This driver can also be built as a module. If so the module > > will be called leds-sn3218. > > > > +config LEDS_IS31FL32XX > > + tristate "LED support for ISSI IS31FL32XX I2C LED controller family" > > + depends on LEDS_CLASS && I2C && OF > > + help > > + Say Y here to include support for ISSI IS31FL32XX LED controllers. > > + They are I2C devices with multiple constant-current channels, each > > + with independent 256-level PWM control. > > Is it worth to mention the module name here? I noticed that some do and some don't. I don't mind adding it, but it also seemed like it would be obvious, and therefore unnecessary. Jacek, which do you prefer? > > + > > comment "LED driver for blink(1) USB RGB LED is under Special HID drivers > > (HID_THINGM)" > > > > config LEDS_BLINKM > > diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile > > index 89c9b6f..3fdf313 100644 > > --- a/drivers/leds/Makefile > > +++ b/drivers/leds/Makefile > > @@ -67,6 +67,7 @@ obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o > > obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o > > obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o > > obj-$(CONFIG_LEDS_SN3218) += leds-sn3218.o > > +obj-$(CONFIG_LEDS_IS31FL32XX) += leds-is31fl32xx.o > > > > # LED SPI Drivers > > obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o > > diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c > > new file mode 100644 > > index 0000000..49818f0 > > --- /dev/null > > +++ b/drivers/leds/leds-is31fl32xx.c > > @@ -0,0 +1,505 @@ > > +/* > > + * linux/drivers/leds-is31fl32xx.c > > I think this is unnecessary. I tend to agree. I think I used leds-pwm.c as a template, and that had such a comment. I assumed it was coding-style and kept it, but now I see that only a minority of led drivers have it. If I do another spin for any reason I'll remove it. > > + * > > + * Driver for ISSI IS31FL32xx family of I2C LED controllers > > + * > > + * Copyright 2015 Allworx Corp. > > + * > > + * > > + * 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. > > + * > > + * Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml > > + */ > > + > > Shouldn't we include <linux/device.h> here? Good catch. I was getting that via i2c.h, but since struct device is referenced explicitly in a few places, device.h should probably be included directly. > > +#include <linux/err.h> > > +#include <linux/i2c.h> > > +#include <linux/kernel.h> > > +#include <linux/leds.h> > > +#include <linux/module.h> > > +#include <linux/of_platform.h> > > + > > +/* Used to indicate a device has no such register */ > > +#define IS31FL32XX_REG_NONE 0xFF > > + > > +/* Software Shutdown bit in Shutdown Register */ > > +#define IS31FL32XX_SHUTDOWN_SSD_ENABLE 0 > > +#define IS31FL32XX_SHUTDOWN_SSD_DISABLE BIT(0) > > + > > +/* IS31FL3216 has a number of unique registers */ > > +#define IS31FL3216_CONFIG_REG 0x00 > > +#define IS31FL3216_LIGHTING_EFFECT_REG 0x03 > > +#define IS31FL3216_CHANNEL_CONFIG_REG 0x04 > > + > > +/* Software Shutdown bit in 3216 Config Register */ > > +#define IS31FL3216_CONFIG_SSD_ENABLE BIT(7) > > +#define IS31FL3216_CONFIG_SSD_DISABLE 0 > > + > > +struct is31fl32xx_priv; > > +struct is31fl32xx_led_data { > > + struct led_classdev cdev; > > + u8 channel; /* 1-based, max priv->cdef->channels */ > > + struct is31fl32xx_priv *priv; > > +}; > > + > > +struct is31fl32xx_priv { > > + const struct is31fl32xx_chipdef *cdef; > > + struct i2c_client *client; > > + unsigned int num_leds; > > + struct is31fl32xx_led_data leds[0]; > > +}; > > + > > +/** > > + * struct is31fl32xx_chipdef - chip-specific attributes > > + * @channels : Number of LED channels > > + * @shutdown_reg : address of Shutdown register (optional) > > + * @pwm_update_reg : address of PWM Update register > > + * @global_control_reg : address of Global Control register (optional) > > + * @reset_reg : address of Reset register (optional) > > + * @pwm_register_base : address of first PWM register > > + * @pwm_registers_reversed: : true if PWM registers count down instead of up > > + * @led_control_register_base : address of first LED control register > > (optional) > > + * @enable_bits_per_led_control_register: number of LEDs enable bits in each > > + * @reset_func: : pointer to reset function > > + * > > + * For all optional register addresses, the sentinel value > > %IS31FL32XX_REG_NONE > > + * indicates that this chip has no such register. > > + * > > + * If non-NULL, @reset_func will be called during probing to set all > > + * necessary registers to a known initialization state. This is needed > > + * for chips that do not have a @reset_reg. > > + * > > + * @enable_bits_per_led_control_register must be >=1 if > > + * @led_control_register_base != %IS31FL32XX_REG_NONE. > > + */ > > +struct is31fl32xx_chipdef { > > + u8 channels; > > + u8 shutdown_reg; > > + u8 pwm_update_reg; > > + u8 global_control_reg; > > + u8 reset_reg; > > + u8 pwm_register_base; > > + bool pwm_registers_reversed; > > + u8 led_control_register_base; > > + u8 enable_bits_per_led_control_register; > > + int (*reset_func)(struct is31fl32xx_priv *priv); > > + int (*sw_shutdown_func)(struct is31fl32xx_priv *priv, bool enable); > > +}; > > + > > +static const struct is31fl32xx_chipdef is31fl3236_cdef = { > > + .channels = 36, > > + .shutdown_reg = 0x00, > > + .pwm_update_reg = 0x25, > > + .global_control_reg = 0x4a, > > + .reset_reg = 0x4f, > > + .pwm_register_base = 0x01, > > + .led_control_register_base = 0x26, > > + .enable_bits_per_led_control_register = 1, > > +}; > > + > > +static const struct is31fl32xx_chipdef is31fl3235_cdef = { > > + .channels = 28, > > + .shutdown_reg = 0x00, > > + .pwm_update_reg = 0x25, > > + .global_control_reg = 0x4a, > > + .reset_reg = 0x4f, > > + .pwm_register_base = 0x05, > > + .led_control_register_base = 0x2a, > > + .enable_bits_per_led_control_register = 1, > > +}; > > + > > +static const struct is31fl32xx_chipdef is31fl3218_cdef = { > > + .channels = 18, > > + .shutdown_reg = 0x00, > > + .pwm_update_reg = 0x16, > > + .global_control_reg = IS31FL32XX_REG_NONE, > > + .reset_reg = 0x17, > > + .pwm_register_base = 0x01, > > + .led_control_register_base = 0x13, > > + .enable_bits_per_led_control_register = 6, > > +}; > > + > > +static int is31fl3216_reset(struct is31fl32xx_priv *priv); > > +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, > > + bool enable); > > +static const struct is31fl32xx_chipdef is31fl3216_cdef = { > > + .channels = 16, > > + .shutdown_reg = IS31FL32XX_REG_NONE, > > + .pwm_update_reg = 0xB0, > > + .global_control_reg = IS31FL32XX_REG_NONE, > > + .reset_reg = IS31FL32XX_REG_NONE, > > + .pwm_register_base = 0x10, > > + .pwm_registers_reversed = true, > > + .led_control_register_base = 0x01, > > + .enable_bits_per_led_control_register = 8, > > + .reset_func = is31fl3216_reset, > > + .sw_shutdown_func = is31fl3216_software_shutdown, > > +}; > > + > > +static int is31fl32xx_write(struct is31fl32xx_priv *priv, u8 reg, u8 val) > > +{ > > + int ret; > > + > > + dev_dbg(&priv->client->dev, "writing register 0x%02X=0x%02X", reg, val); > > + > > + ret = i2c_smbus_write_byte_data(priv->client, reg, val); > > + if (ret) { > > + dev_err(&priv->client->dev, > > + "register write to 0x%02X failed (error %d)", > > + reg, ret); > > + } > > In case somebody use this driver as heartbeat and writing fails permanently the > log will be flooded. Unless I'm mistaken that would require the device/bus to fail after successfully probing (probe code itself bails on the first write failure, so there would be no flooding as a result of that). So while not impossible, I imagine it would be unlikely, and I'd hate to remove an error message for such an important condition. I suppose I could use dev_err_ratelimited() to soften any potential flooding, but I second guess that because: - In led_core.c set_brightness_delayed() has a dev_err() that would come out on each failed LED update anyways. - There is precedent in other led drivers of a similar error message. - Some userspace logging programs will compresses repeated messages anyways. Jacek, what is your preference on this? > > + return ret; > > +} > > + > > +/* > > + * Custom reset function for IS31FL3216 because it does not have a RESET > > + * register the way that the other IS31FL32xx chips do. We don't bother > > + * writing the GPIO and animation registers, because the registers we > > + * do write ensure those will have no effect. > > + */ > > +static int is31fl3216_reset(struct is31fl32xx_priv *priv) > > +{ > > + unsigned int i; > > + int ret; > > + > > + ret = is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, > > + IS31FL3216_CONFIG_SSD_ENABLE); > > + if (ret) > > + return ret; > > + for (i = 0; i < priv->cdef->channels; i++) { > > + ret = is31fl32xx_write(priv, priv->cdef->pwm_register_base+i, > > + 0x00); > > + if (ret) > > + return ret; > > + } > > + ret = is31fl32xx_write(priv, priv->cdef->pwm_update_reg, 0); > > + if (ret) > > + return ret; > > + ret = is31fl32xx_write(priv, IS31FL3216_LIGHTING_EFFECT_REG, 0x00); > > + if (ret) > > + return ret; > > + ret = is31fl32xx_write(priv, IS31FL3216_CHANNEL_CONFIG_REG, 0x00); > > + if (ret) > > + return ret; > > + > > + return 0; > > +} > > + > > +/* > > + * Custom Software-Shutdown function for IS31FL3216 because it does not have > > + * a SHUTDOWN register the way that the other IS31FL32xx chips do. > > + * We don't bother doing a read/modify/write on the CONFIG register because > > + * we only ever use a value of '0' for the other fields in that register. > > + */ > > +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, > > + bool enable) > > +{ > > + u8 value = enable ? IS31FL3216_CONFIG_SSD_ENABLE : > > + IS31FL3216_CONFIG_SSD_DISABLE; > > + > > + return is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, value); > > +} > > + > > +/* > > + * NOTE: A mutex is not needed in this function because: > > + * - All referenced data is read-only after probe() > > + * - The I2C core has a mutex on to protect the bus > > + * - There are no read/modify/write operations > > + * - Intervening operations between the write of the PWM register > > + * and the Update register are harmless. > > + * > > + * Example: > > + * PWM_REG_1 write 16 > > + * UPDATE_REG write 0 > > + * PWM_REG_2 write 128 > > + * UPDATE_REG write 0 > > + * vs: > > + * PWM_REG_1 write 16 > > + * PWM_REG_2 write 128 > > + * UPDATE_REG write 0 > > + * UPDATE_REG write 0 > > + * are equivalent. Poking the Update register merely applies all PWM > > + * register writes up to that point. > > + */ > > +static int is31fl32xx_brightness_set(struct led_classdev *led_cdev, > > + enum led_brightness brightness) > > +{ > > + const struct is31fl32xx_led_data *led_data = > > + container_of(led_cdev, struct is31fl32xx_led_data, cdev); > > + const struct is31fl32xx_chipdef *cdef = led_data->priv->cdef; > > + u8 pwm_register_offset; > > + int ret; > > + > > + dev_dbg(led_cdev->dev, "%s: %d\n", __func__, brightness); > > + > > + /* NOTE: led_data->channel is 1-based */ > > + if (cdef->pwm_registers_reversed) > > + pwm_register_offset = cdef->channels - led_data->channel; > > + else > > + pwm_register_offset = led_data->channel - 1; > > + > > + ret = is31fl32xx_write(led_data->priv, > > + cdef->pwm_register_base + pwm_register_offset, > > + brightness); > > + if (ret) > > + return ret; > > + > > + return is31fl32xx_write(led_data->priv, cdef->pwm_update_reg, 0); > > +} > > + > > +static int is31fl32xx_reset_regs(struct is31fl32xx_priv *priv) > > +{ > > + const struct is31fl32xx_chipdef *cdef = priv->cdef; > > + int ret; > > + > > + if (cdef->reset_reg != IS31FL32XX_REG_NONE) { > > + ret = is31fl32xx_write(priv, cdef->reset_reg, 0); > > + if (ret) > > + return ret; > > + } > > + > > + if (cdef->reset_func) > > + return cdef->reset_func(priv); > > + > > + return 0; > > +} > > + > > +static int is31fl32xx_software_shutdown(struct is31fl32xx_priv *priv, > > + bool enable) > > +{ > > + const struct is31fl32xx_chipdef *cdef = priv->cdef; > > + int ret; > > + > > + if (cdef->shutdown_reg != IS31FL32XX_REG_NONE) { > > + u8 value = enable ? IS31FL32XX_SHUTDOWN_SSD_ENABLE : > > + IS31FL32XX_SHUTDOWN_SSD_DISABLE; > > + ret = is31fl32xx_write(priv, cdef->shutdown_reg, value); > > + if (ret) > > + return ret; > > + } > > + > > + if (cdef->sw_shutdown_func) > > + return cdef->sw_shutdown_func(priv, enable); > > + > > + return 0; > > +} > > + > > +static int is31fl32xx_init_regs(struct is31fl32xx_priv *priv) > > +{ > > + const struct is31fl32xx_chipdef *cdef = priv->cdef; > > + int ret; > > + > > + ret = is31fl32xx_reset_regs(priv); > > + if (ret) > > + return ret; > > + > > + /* > > + * Set enable bit for all channels. > > + * We will control state with PWM registers alone. > > + */ > > + if (cdef->led_control_register_base != IS31FL32XX_REG_NONE) { > > + u8 value = > > + GENMASK(cdef->enable_bits_per_led_control_register-1, 0); > > + u8 num_regs = cdef->channels / > > + cdef->enable_bits_per_led_control_register; > > + int i; > > + > > + for (i = 0; i < num_regs; i++) { > > + ret = is31fl32xx_write(priv, > > + cdef->led_control_register_base+i, > > + value); > > + if (ret) > > + return ret; > > + } > > + } > > + > > + ret = is31fl32xx_software_shutdown(priv, false); > > + if (ret) > > + return ret; > > + > > + if (cdef->global_control_reg != IS31FL32XX_REG_NONE) { > > + ret = is31fl32xx_write(priv, cdef->global_control_reg, 0x00); > > + if (ret) > > + return ret; > > + } > > + > > + return 0; > > +} > > + > > +static inline size_t sizeof_is31fl32xx_priv(int num_leds) > > +{ > > + return sizeof(struct is31fl32xx_priv) + > > + (sizeof(struct is31fl32xx_led_data) * num_leds); > > +} > > + > > +static int is31fl32xx_parse_child_dt(const struct device *dev, > > + const struct device_node *child, > > + struct is31fl32xx_led_data *led_data) > > +{ > > + struct led_classdev *cdev = &led_data->cdev; > > + int ret = 0; > > + u32 reg; > > + > > + if (of_property_read_string(child, "label", &cdev->name)) > > + cdev->name = child->name; > > + > > + ret = of_property_read_u32(child, "reg", ®); > > + if (ret || reg < 1 || reg > led_data->priv->cdef->channels) { > > + dev_err(dev, > > + "Child node %s does not have a valid reg property\n", > > + child->full_name); > > + return -EINVAL; > > + } > > + led_data->channel = reg; > > + > > + of_property_read_string(child, "linux,default-trigger", > > + &cdev->default_trigger); > > + > > + cdev->brightness_set_blocking = is31fl32xx_brightness_set; > > + > > + return 0; > > +} > > + > > +static struct is31fl32xx_led_data *is31fl32xx_find_led_data( > > + struct is31fl32xx_priv *priv, > > + u8 channel) > > +{ > > + size_t i; > > + > > + for (i = 0; i < priv->num_leds; i++) { > > + if (priv->leds[i].channel == channel) > > + return &priv->leds[i]; > > + } > > + > > + return NULL; > > +} > > + > > +static int is31fl32xx_parse_dt(struct device *dev, > > + struct is31fl32xx_priv *priv) > > +{ > > + struct device_node *child; > > + int ret = 0; > > + > > + for_each_child_of_node(dev->of_node, child) { > > + struct is31fl32xx_led_data *led_data = > > + &priv->leds[priv->num_leds]; > > Maybe i missed something, but is it really protected against out of index > access? The array is allocated with size equal to the number of child nodes, and num_leds is incremented once for each child node parsed. So in order for the index to be out of bounds, the number of child nodes would need to increase during the probe. I assumed that the DT is static during probing, but if that's not the case then you're right that this is a potential problem. Also, this equivalent logic is used in leds-pwm, leds-gpio, and leds-ns2, so that gives me confidence that its safe. Unless DT overlays change that assumption? > > + const struct is31fl32xx_led_data *other_led_data; > > + > > + led_data->priv = priv; > > + > > + ret = is31fl32xx_parse_child_dt(dev, child, led_data); > > + if (ret) > > + goto err; > > + > > + /* Detect if channel is already in use by another child */ > > + other_led_data = is31fl32xx_find_led_data(priv, > > + led_data->channel); > > + if (other_led_data) { > > + dev_err(dev, > > + "%s and %s both attempting to use channel %d\n", > > + led_data->cdev.name, > > + other_led_data->cdev.name, > > + led_data->channel); > > + goto err; > > + } > > + > > + ret = devm_led_classdev_register(dev, &led_data->cdev); > > + if (ret) { > > + dev_err(dev, "failed to register PWM led for %s: %d\n", > > + led_data->cdev.name, ret); > > + goto err; > > + } > > + > > + priv->num_leds++; > > + } > > + > > + return 0; > > + > > +err: > > + of_node_put(child); > > + return ret; > > +} > > + > > +static const struct of_device_id of_is31fl31xx_match[] = { > > + { .compatible = "issi,is31fl3236", .data = &is31fl3236_cdef, }, > > + { .compatible = "issi,is31fl3235", .data = &is31fl3235_cdef, }, > > + { .compatible = "issi,is31fl3218", .data = &is31fl3218_cdef, }, > > + { .compatible = "issi,is31fl3216", .data = &is31fl3216_cdef, }, > > + {}, > > +}; > > + > > +MODULE_DEVICE_TABLE(of, of_is31fl31xx_match); > > + > > +static int is31fl32xx_probe(struct i2c_client *client, > > + const struct i2c_device_id *id) > > +{ > > + const struct is31fl32xx_chipdef *cdef; > > + const struct of_device_id *of_dev_id; > > + struct device *dev = &client->dev; > > + struct is31fl32xx_priv *priv; > > + int count; > > + int ret = 0; > > + > > + of_dev_id = of_match_device(of_is31fl31xx_match, dev); > > + if (!of_dev_id) > > + return -EINVAL; > > + > > + cdef = of_dev_id->data; > > + > > + count = of_get_child_count(dev->of_node); > > + if (!count) > > + return -EINVAL; > > + > > + priv = devm_kzalloc(dev, sizeof_is31fl32xx_priv(count), > > + GFP_KERNEL); > > + if (!priv) > > + return -ENOMEM; > > + > > + priv->client = client; > > + priv->cdef = cdef; > > + i2c_set_clientdata(client, priv); > > + > > + ret = is31fl32xx_init_regs(priv); > > + if (ret) > > + return ret; > > + > > + ret = is31fl32xx_parse_dt(dev, priv); > > + if (ret) > > + return ret; > > + > > + return 0; > > +} > > + > > +static int is31fl32xx_remove(struct i2c_client *client) > > +{ > > + struct is31fl32xx_priv *priv = i2c_get_clientdata(client); > > + > > + return is31fl32xx_reset_regs(priv); > > +} > > + > > +/* > > + * i2c-core requires that id_table be non-NULL, even though > > + * it is not used for DeviceTree based instantiation. > > + */ > > +static const struct i2c_device_id is31fl31xx_id[] = { > > + {}, > > +}; > > + > > +MODULE_DEVICE_TABLE(i2c, is31fl31xx_id); > > + > > +static struct i2c_driver is31fl32xx_driver = { > > + .driver = { > > + .name = "is31fl32xx", > > + .of_match_table = of_is31fl31xx_match, > > + }, > > + .probe = is31fl32xx_probe, > > + .remove = is31fl32xx_remove, > > Sorry, what was the reason to skip shutdown? If I understood Jacek's last email on the topic [1] correctly, he's now of the opinion that the decision to turn LEDs off on reboot should be left to userspace, rather than done by the driver. For these devices, the only thing a shutdown callback would do is turn off the LEDs (through any of multiple methods). So, if we want to leave the state as-is on reboot there's no need for a shutdown callback. [1] http://www.spinics.net/lists/linux-leds/msg05644.html > > + .id_table = is31fl31xx_id, > > +}; > > + > > +module_i2c_driver(is31fl32xx_driver); > > + > > +MODULE_AUTHOR("David Rivshin <drivshin@allworx.com>"); > > +MODULE_DESCRIPTION("ISSI IS31FL32xx LED driver"); > > +MODULE_LICENSE("GPL v2"); > > -- > > 2.5.0 > > ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 3/4] leds: Add driver for the ISSI IS31FL32xx family of LED controllers 2016-03-04 14:27 ` David Rivshin (Allworx) @ 2016-03-04 15:38 ` Jacek Anaszewski 2016-03-05 6:12 ` David Rivshin (Allworx) 0 siblings, 1 reply; 28+ messages in thread From: Jacek Anaszewski @ 2016-03-04 15:38 UTC (permalink / raw) To: David Rivshin (Allworx) Cc: Stefan Wahren, linux-leds, devicetree, Pawel Moll, Rob Herring, Ian Campbell, Kumar Gala, linux-kernel, Richard Purdie, Mark Rutland On 03/04/2016 03:27 PM, David Rivshin (Allworx) wrote: > (Stefan, sorry for the duplicate, I just realized that I originally > replied only to you by accident). > > On Thu, 3 Mar 2016 19:13:03 +0100 (CET) > Stefan Wahren <stefan.wahren@i2se.com> wrote: > >> Hi David, >> >> i will test the driver on weekend. Some comments below > > Great, thanks very much. > >>> "David Rivshin (Allworx)" <drivshin.allworx@gmail.com> hat am 3. März 2016 um >>> 04:01 geschrieben: >>> >>> >>> From: David Rivshin <drivshin@allworx.com> >>> >>> The IS31FL32xx family of LED controllers are I2C devices with multiple >>> constant-current channels, each with independent 256-level PWM control. >>> >>> Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml >>> >>> This has been tested on the IS31FL3236 and IS31FL3216, on an ARM >>> (TI am335x) platform. >>> >>> The programming paradigm of these devices is similar in the following >>> ways: >>> - All registers are 8 bit >>> - All LED control registers are write-only >>> - Each LED channel has a PWM register (0-255) >>> - PWM register writes are shadowed until an Update register is poked >>> - All have a concept of Software Shutdown, which disables output >>> >>> However, there are some differences in devices: >>> - 3236/3235 have a separate Control register for each LED, >>> (3218/3216 pack the enable bits into fewer registers) >>> - 3236/3235 have a per-channel current divisor setting >>> - 3236/3235 have a Global Control register that can turn off all LEDs >>> - 3216 is unique in a number of ways >>> - OUT9-OUT16 can be configured as GPIOs instead of LED controls >>> - LEDs can be programmed with an 8-frame animation, with >>> programmable delay between frames >>> - LEDs can be modulated by an input audio signal >>> - Max output current can be adjusted from 1/4 to 2x globally >>> - Has a Configuration register instead of a Shutdown register >>> >>> This driver currently only supports the base PWM control function >>> of these devices. The following features of these devices are not >>> implemented, although it should be possible to add them in the future: >>> - All devices are capable of going into a lower-power "software >>> shutdown" mode. >>> - The is31fl3236 and is31fl3235 can reduce the max output current >>> per-channel with a divisor of 1, 2, 3, or 4. >>> - The is31fl3216 can use some LED channels as GPIOs instead. >>> - The is31fl3216 can animate LEDs in hardware. >>> - The is31fl3216 can modulate LEDs according to an audio input. >>> - The is31fl3216 can reduce/increase max output current globally. >>> >>> Signed-off-by: David Rivshin <drivshin@allworx.com> >>> --- >>> >>> You may see two instances of this warning: >>> "passing argument 1 of 'of_property_read_string' discards 'const' >>> qualifier from pointer target type" >>> That is a result of of_property_read_string() taking a non-const >>> struct device_node pointer parameter. I have separately submitted a >>> patch to fix that [1], and a few related functions which had the same >>> issue. I'm hoping that will get into linux-next before this does, so >>> that the warnings never show up there. >>> >>> Changes from RFC: >>> - Removed max-brightness DT property. >>> - Refer to these devices as "LED controllers" in Kconfig. >>> - Removed redundant last sentence from Kconfig entry >>> - Removed unnecessary debug code. >>> - Do not set led_classdev.brightness to 0 explicitly, as it is >>> already initialized to 0 by devm_kzalloc(). >>> - Used of_property_read_string() instead of of_get_property(). >>> - Fail immediately on DT parsing error in a child node, rather than >>> continuing on with the non-faulty ones. >>> - Added additional comments for some things that might be non-obvious. >>> - Added constants for the location of the SSD bit in the SHUTDOWN >>> register, and the 3216's CONFIG register. >>> - Added special sw_shutdown_func for the 3216 device, as that bit >>> is in a different register, at a different position, and has reverse >>> polarity compared to all the other devices. >>> - Refactored is31fl32xx_init_regs() to separate out some logic into >>> is31fl32xx_reset_regs() and is31fl32xx_software_shutdown(). >>> >>> [1] https://lkml.org/lkml/2016/3/2/746 >>> >>> drivers/leds/Kconfig | 8 + >>> drivers/leds/Makefile | 1 + >>> drivers/leds/leds-is31fl32xx.c | 505 +++++++++++++++++++++++++++++++++++++++++ >>> 3 files changed, 514 insertions(+) >>> create mode 100644 drivers/leds/leds-is31fl32xx.c >>> >>> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig >>> index 1034696..9c63ba4 100644 >>> --- a/drivers/leds/Kconfig >>> +++ b/drivers/leds/Kconfig >>> @@ -580,6 +580,14 @@ config LEDS_SN3218 >>> This driver can also be built as a module. If so the module >>> will be called leds-sn3218. >>> >>> +config LEDS_IS31FL32XX >>> + tristate "LED support for ISSI IS31FL32XX I2C LED controller family" >>> + depends on LEDS_CLASS && I2C && OF >>> + help >>> + Say Y here to include support for ISSI IS31FL32XX LED controllers. >>> + They are I2C devices with multiple constant-current channels, each >>> + with independent 256-level PWM control. >> >> Is it worth to mention the module name here? > > I noticed that some do and some don't. I don't mind adding it, but it > also seemed like it would be obvious, and therefore unnecessary. > > Jacek, which do you prefer? I agree - it's obvious, we can skip it. >>> + >>> comment "LED driver for blink(1) USB RGB LED is under Special HID drivers >>> (HID_THINGM)" >>> >>> config LEDS_BLINKM >>> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile >>> index 89c9b6f..3fdf313 100644 >>> --- a/drivers/leds/Makefile >>> +++ b/drivers/leds/Makefile >>> @@ -67,6 +67,7 @@ obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o >>> obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o >>> obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o >>> obj-$(CONFIG_LEDS_SN3218) += leds-sn3218.o >>> +obj-$(CONFIG_LEDS_IS31FL32XX) += leds-is31fl32xx.o >>> >>> # LED SPI Drivers >>> obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o >>> diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c >>> new file mode 100644 >>> index 0000000..49818f0 >>> --- /dev/null >>> +++ b/drivers/leds/leds-is31fl32xx.c >>> @@ -0,0 +1,505 @@ >>> +/* >>> + * linux/drivers/leds-is31fl32xx.c >> >> I think this is unnecessary. > > I tend to agree. I think I used leds-pwm.c as a template, and that had > such a comment. I assumed it was coding-style and kept it, but now I see > that only a minority of led drivers have it. If I do another spin for > any reason I'll remove it. > >>> + * >>> + * Driver for ISSI IS31FL32xx family of I2C LED controllers >>> + * >>> + * Copyright 2015 Allworx Corp. >>> + * >>> + * >>> + * 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. >>> + * >>> + * Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml >>> + */ >>> + >> >> Shouldn't we include <linux/device.h> here? > > Good catch. I was getting that via i2c.h, but since struct device is > referenced explicitly in a few places, device.h should probably be > included directly. linux/device.h is included from linux/leds.h >>> +#include <linux/err.h> >>> +#include <linux/i2c.h> >>> +#include <linux/kernel.h> >>> +#include <linux/leds.h> >>> +#include <linux/module.h> >>> +#include <linux/of_platform.h> >>> + >>> +/* Used to indicate a device has no such register */ >>> +#define IS31FL32XX_REG_NONE 0xFF >>> + >>> +/* Software Shutdown bit in Shutdown Register */ >>> +#define IS31FL32XX_SHUTDOWN_SSD_ENABLE 0 >>> +#define IS31FL32XX_SHUTDOWN_SSD_DISABLE BIT(0) >>> + >>> +/* IS31FL3216 has a number of unique registers */ >>> +#define IS31FL3216_CONFIG_REG 0x00 >>> +#define IS31FL3216_LIGHTING_EFFECT_REG 0x03 >>> +#define IS31FL3216_CHANNEL_CONFIG_REG 0x04 >>> + >>> +/* Software Shutdown bit in 3216 Config Register */ >>> +#define IS31FL3216_CONFIG_SSD_ENABLE BIT(7) >>> +#define IS31FL3216_CONFIG_SSD_DISABLE 0 >>> + >>> +struct is31fl32xx_priv; >>> +struct is31fl32xx_led_data { >>> + struct led_classdev cdev; >>> + u8 channel; /* 1-based, max priv->cdef->channels */ >>> + struct is31fl32xx_priv *priv; >>> +}; >>> + >>> +struct is31fl32xx_priv { >>> + const struct is31fl32xx_chipdef *cdef; >>> + struct i2c_client *client; >>> + unsigned int num_leds; >>> + struct is31fl32xx_led_data leds[0]; >>> +}; >>> + >>> +/** >>> + * struct is31fl32xx_chipdef - chip-specific attributes >>> + * @channels : Number of LED channels >>> + * @shutdown_reg : address of Shutdown register (optional) >>> + * @pwm_update_reg : address of PWM Update register >>> + * @global_control_reg : address of Global Control register (optional) >>> + * @reset_reg : address of Reset register (optional) >>> + * @pwm_register_base : address of first PWM register >>> + * @pwm_registers_reversed: : true if PWM registers count down instead of up >>> + * @led_control_register_base : address of first LED control register >>> (optional) >>> + * @enable_bits_per_led_control_register: number of LEDs enable bits in each >>> + * @reset_func: : pointer to reset function >>> + * >>> + * For all optional register addresses, the sentinel value >>> %IS31FL32XX_REG_NONE >>> + * indicates that this chip has no such register. >>> + * >>> + * If non-NULL, @reset_func will be called during probing to set all >>> + * necessary registers to a known initialization state. This is needed >>> + * for chips that do not have a @reset_reg. >>> + * >>> + * @enable_bits_per_led_control_register must be >=1 if >>> + * @led_control_register_base != %IS31FL32XX_REG_NONE. >>> + */ >>> +struct is31fl32xx_chipdef { >>> + u8 channels; >>> + u8 shutdown_reg; >>> + u8 pwm_update_reg; >>> + u8 global_control_reg; >>> + u8 reset_reg; >>> + u8 pwm_register_base; >>> + bool pwm_registers_reversed; >>> + u8 led_control_register_base; >>> + u8 enable_bits_per_led_control_register; >>> + int (*reset_func)(struct is31fl32xx_priv *priv); >>> + int (*sw_shutdown_func)(struct is31fl32xx_priv *priv, bool enable); >>> +}; >>> + >>> +static const struct is31fl32xx_chipdef is31fl3236_cdef = { >>> + .channels = 36, >>> + .shutdown_reg = 0x00, >>> + .pwm_update_reg = 0x25, >>> + .global_control_reg = 0x4a, >>> + .reset_reg = 0x4f, >>> + .pwm_register_base = 0x01, >>> + .led_control_register_base = 0x26, >>> + .enable_bits_per_led_control_register = 1, >>> +}; >>> + >>> +static const struct is31fl32xx_chipdef is31fl3235_cdef = { >>> + .channels = 28, >>> + .shutdown_reg = 0x00, >>> + .pwm_update_reg = 0x25, >>> + .global_control_reg = 0x4a, >>> + .reset_reg = 0x4f, >>> + .pwm_register_base = 0x05, >>> + .led_control_register_base = 0x2a, >>> + .enable_bits_per_led_control_register = 1, >>> +}; >>> + >>> +static const struct is31fl32xx_chipdef is31fl3218_cdef = { >>> + .channels = 18, >>> + .shutdown_reg = 0x00, >>> + .pwm_update_reg = 0x16, >>> + .global_control_reg = IS31FL32XX_REG_NONE, >>> + .reset_reg = 0x17, >>> + .pwm_register_base = 0x01, >>> + .led_control_register_base = 0x13, >>> + .enable_bits_per_led_control_register = 6, >>> +}; >>> + >>> +static int is31fl3216_reset(struct is31fl32xx_priv *priv); >>> +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, >>> + bool enable); >>> +static const struct is31fl32xx_chipdef is31fl3216_cdef = { >>> + .channels = 16, >>> + .shutdown_reg = IS31FL32XX_REG_NONE, >>> + .pwm_update_reg = 0xB0, >>> + .global_control_reg = IS31FL32XX_REG_NONE, >>> + .reset_reg = IS31FL32XX_REG_NONE, >>> + .pwm_register_base = 0x10, >>> + .pwm_registers_reversed = true, >>> + .led_control_register_base = 0x01, >>> + .enable_bits_per_led_control_register = 8, >>> + .reset_func = is31fl3216_reset, >>> + .sw_shutdown_func = is31fl3216_software_shutdown, >>> +}; >>> + >>> +static int is31fl32xx_write(struct is31fl32xx_priv *priv, u8 reg, u8 val) >>> +{ >>> + int ret; >>> + >>> + dev_dbg(&priv->client->dev, "writing register 0x%02X=0x%02X", reg, val); >>> + >>> + ret = i2c_smbus_write_byte_data(priv->client, reg, val); >>> + if (ret) { >>> + dev_err(&priv->client->dev, >>> + "register write to 0x%02X failed (error %d)", >>> + reg, ret); >>> + } >> >> In case somebody use this driver as heartbeat and writing fails permanently the >> log will be flooded. > > Unless I'm mistaken that would require the device/bus to fail after > successfully probing (probe code itself bails on the first write > failure, so there would be no flooding as a result of that). So while > not impossible, I imagine it would be unlikely, and I'd hate to remove > an error message for such an important condition. > > I suppose I could use dev_err_ratelimited() to soften any potential > flooding, but I second guess that because: > - In led_core.c set_brightness_delayed() has a dev_err() that would come > out on each failed LED update anyways. > - There is precedent in other led drivers of a similar error message. > - Some userspace logging programs will compresses repeated messages anyways. > > Jacek, what is your preference on this? Let's leave it as is. Permanent I2C bus failure is a critical error and flooding the log would only allow to diagnose the problem quicker. >>> + return ret; >>> +} >>> + >>> +/* >>> + * Custom reset function for IS31FL3216 because it does not have a RESET >>> + * register the way that the other IS31FL32xx chips do. We don't bother >>> + * writing the GPIO and animation registers, because the registers we >>> + * do write ensure those will have no effect. >>> + */ >>> +static int is31fl3216_reset(struct is31fl32xx_priv *priv) >>> +{ >>> + unsigned int i; >>> + int ret; >>> + >>> + ret = is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, >>> + IS31FL3216_CONFIG_SSD_ENABLE); >>> + if (ret) >>> + return ret; >>> + for (i = 0; i < priv->cdef->channels; i++) { >>> + ret = is31fl32xx_write(priv, priv->cdef->pwm_register_base+i, >>> + 0x00); >>> + if (ret) >>> + return ret; >>> + } >>> + ret = is31fl32xx_write(priv, priv->cdef->pwm_update_reg, 0); >>> + if (ret) >>> + return ret; >>> + ret = is31fl32xx_write(priv, IS31FL3216_LIGHTING_EFFECT_REG, 0x00); >>> + if (ret) >>> + return ret; >>> + ret = is31fl32xx_write(priv, IS31FL3216_CHANNEL_CONFIG_REG, 0x00); >>> + if (ret) >>> + return ret; >>> + >>> + return 0; >>> +} >>> + >>> +/* >>> + * Custom Software-Shutdown function for IS31FL3216 because it does not have >>> + * a SHUTDOWN register the way that the other IS31FL32xx chips do. >>> + * We don't bother doing a read/modify/write on the CONFIG register because >>> + * we only ever use a value of '0' for the other fields in that register. >>> + */ >>> +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, >>> + bool enable) >>> +{ >>> + u8 value = enable ? IS31FL3216_CONFIG_SSD_ENABLE : >>> + IS31FL3216_CONFIG_SSD_DISABLE; >>> + >>> + return is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, value); >>> +} >>> + >>> +/* >>> + * NOTE: A mutex is not needed in this function because: >>> + * - All referenced data is read-only after probe() >>> + * - The I2C core has a mutex on to protect the bus >>> + * - There are no read/modify/write operations >>> + * - Intervening operations between the write of the PWM register >>> + * and the Update register are harmless. >>> + * >>> + * Example: >>> + * PWM_REG_1 write 16 >>> + * UPDATE_REG write 0 >>> + * PWM_REG_2 write 128 >>> + * UPDATE_REG write 0 >>> + * vs: >>> + * PWM_REG_1 write 16 >>> + * PWM_REG_2 write 128 >>> + * UPDATE_REG write 0 >>> + * UPDATE_REG write 0 >>> + * are equivalent. Poking the Update register merely applies all PWM >>> + * register writes up to that point. >>> + */ >>> +static int is31fl32xx_brightness_set(struct led_classdev *led_cdev, >>> + enum led_brightness brightness) >>> +{ >>> + const struct is31fl32xx_led_data *led_data = >>> + container_of(led_cdev, struct is31fl32xx_led_data, cdev); >>> + const struct is31fl32xx_chipdef *cdef = led_data->priv->cdef; >>> + u8 pwm_register_offset; >>> + int ret; >>> + >>> + dev_dbg(led_cdev->dev, "%s: %d\n", __func__, brightness); >>> + >>> + /* NOTE: led_data->channel is 1-based */ >>> + if (cdef->pwm_registers_reversed) >>> + pwm_register_offset = cdef->channels - led_data->channel; >>> + else >>> + pwm_register_offset = led_data->channel - 1; >>> + >>> + ret = is31fl32xx_write(led_data->priv, >>> + cdef->pwm_register_base + pwm_register_offset, >>> + brightness); >>> + if (ret) >>> + return ret; >>> + >>> + return is31fl32xx_write(led_data->priv, cdef->pwm_update_reg, 0); >>> +} >>> + >>> +static int is31fl32xx_reset_regs(struct is31fl32xx_priv *priv) >>> +{ >>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; >>> + int ret; >>> + >>> + if (cdef->reset_reg != IS31FL32XX_REG_NONE) { >>> + ret = is31fl32xx_write(priv, cdef->reset_reg, 0); >>> + if (ret) >>> + return ret; >>> + } >>> + >>> + if (cdef->reset_func) >>> + return cdef->reset_func(priv); >>> + >>> + return 0; >>> +} >>> + >>> +static int is31fl32xx_software_shutdown(struct is31fl32xx_priv *priv, >>> + bool enable) >>> +{ >>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; >>> + int ret; >>> + >>> + if (cdef->shutdown_reg != IS31FL32XX_REG_NONE) { >>> + u8 value = enable ? IS31FL32XX_SHUTDOWN_SSD_ENABLE : >>> + IS31FL32XX_SHUTDOWN_SSD_DISABLE; >>> + ret = is31fl32xx_write(priv, cdef->shutdown_reg, value); >>> + if (ret) >>> + return ret; >>> + } >>> + >>> + if (cdef->sw_shutdown_func) >>> + return cdef->sw_shutdown_func(priv, enable); >>> + >>> + return 0; >>> +} >>> + >>> +static int is31fl32xx_init_regs(struct is31fl32xx_priv *priv) >>> +{ >>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; >>> + int ret; >>> + >>> + ret = is31fl32xx_reset_regs(priv); >>> + if (ret) >>> + return ret; >>> + >>> + /* >>> + * Set enable bit for all channels. >>> + * We will control state with PWM registers alone. >>> + */ >>> + if (cdef->led_control_register_base != IS31FL32XX_REG_NONE) { >>> + u8 value = >>> + GENMASK(cdef->enable_bits_per_led_control_register-1, 0); >>> + u8 num_regs = cdef->channels / >>> + cdef->enable_bits_per_led_control_register; >>> + int i; >>> + >>> + for (i = 0; i < num_regs; i++) { >>> + ret = is31fl32xx_write(priv, >>> + cdef->led_control_register_base+i, >>> + value); >>> + if (ret) >>> + return ret; >>> + } >>> + } >>> + >>> + ret = is31fl32xx_software_shutdown(priv, false); >>> + if (ret) >>> + return ret; >>> + >>> + if (cdef->global_control_reg != IS31FL32XX_REG_NONE) { >>> + ret = is31fl32xx_write(priv, cdef->global_control_reg, 0x00); >>> + if (ret) >>> + return ret; >>> + } >>> + >>> + return 0; >>> +} >>> + >>> +static inline size_t sizeof_is31fl32xx_priv(int num_leds) >>> +{ >>> + return sizeof(struct is31fl32xx_priv) + >>> + (sizeof(struct is31fl32xx_led_data) * num_leds); >>> +} >>> + >>> +static int is31fl32xx_parse_child_dt(const struct device *dev, >>> + const struct device_node *child, >>> + struct is31fl32xx_led_data *led_data) >>> +{ >>> + struct led_classdev *cdev = &led_data->cdev; >>> + int ret = 0; >>> + u32 reg; >>> + >>> + if (of_property_read_string(child, "label", &cdev->name)) >>> + cdev->name = child->name; >>> + >>> + ret = of_property_read_u32(child, "reg", ®); >>> + if (ret || reg < 1 || reg > led_data->priv->cdef->channels) { >>> + dev_err(dev, >>> + "Child node %s does not have a valid reg property\n", >>> + child->full_name); >>> + return -EINVAL; >>> + } >>> + led_data->channel = reg; >>> + >>> + of_property_read_string(child, "linux,default-trigger", >>> + &cdev->default_trigger); >>> + >>> + cdev->brightness_set_blocking = is31fl32xx_brightness_set; >>> + >>> + return 0; >>> +} >>> + >>> +static struct is31fl32xx_led_data *is31fl32xx_find_led_data( >>> + struct is31fl32xx_priv *priv, >>> + u8 channel) >>> +{ >>> + size_t i; >>> + >>> + for (i = 0; i < priv->num_leds; i++) { >>> + if (priv->leds[i].channel == channel) >>> + return &priv->leds[i]; >>> + } >>> + >>> + return NULL; >>> +} >>> + >>> +static int is31fl32xx_parse_dt(struct device *dev, >>> + struct is31fl32xx_priv *priv) >>> +{ >>> + struct device_node *child; >>> + int ret = 0; >>> + >>> + for_each_child_of_node(dev->of_node, child) { >>> + struct is31fl32xx_led_data *led_data = >>> + &priv->leds[priv->num_leds]; >> >> Maybe i missed something, but is it really protected against out of index >> access? > > The array is allocated with size equal to the number of child nodes, > and num_leds is incremented once for each child node parsed. So in > order for the index to be out of bounds, the number of child nodes > would need to increase during the probe. I assumed that the DT is > static during probing, but if that's not the case then you're right > that this is a potential problem. Also, this equivalent logic is > used in leds-pwm, leds-gpio, and leds-ns2, so that gives me > confidence that its safe. > Unless DT overlays change that assumption? DT overlays would matter here if child DT nodes could be dynamically removed, i.e. if it was possible by design to dynamically unplug LEDs from the current outputs during LED controller operation, which is not the case for this device (and any other LED controller I am aware of). >>> + const struct is31fl32xx_led_data *other_led_data; >>> + >>> + led_data->priv = priv; >>> + >>> + ret = is31fl32xx_parse_child_dt(dev, child, led_data); >>> + if (ret) >>> + goto err; >>> + >>> + /* Detect if channel is already in use by another child */ >>> + other_led_data = is31fl32xx_find_led_data(priv, >>> + led_data->channel); >>> + if (other_led_data) { >>> + dev_err(dev, >>> + "%s and %s both attempting to use channel %d\n", >>> + led_data->cdev.name, >>> + other_led_data->cdev.name, >>> + led_data->channel); >>> + goto err; >>> + } >>> + >>> + ret = devm_led_classdev_register(dev, &led_data->cdev); >>> + if (ret) { >>> + dev_err(dev, "failed to register PWM led for %s: %d\n", >>> + led_data->cdev.name, ret); >>> + goto err; >>> + } >>> + >>> + priv->num_leds++; >>> + } >>> + >>> + return 0; >>> + >>> +err: >>> + of_node_put(child); >>> + return ret; >>> +} >>> + >>> +static const struct of_device_id of_is31fl31xx_match[] = { >>> + { .compatible = "issi,is31fl3236", .data = &is31fl3236_cdef, }, >>> + { .compatible = "issi,is31fl3235", .data = &is31fl3235_cdef, }, >>> + { .compatible = "issi,is31fl3218", .data = &is31fl3218_cdef, }, >>> + { .compatible = "issi,is31fl3216", .data = &is31fl3216_cdef, }, >>> + {}, >>> +}; >>> + >>> +MODULE_DEVICE_TABLE(of, of_is31fl31xx_match); >>> + >>> +static int is31fl32xx_probe(struct i2c_client *client, >>> + const struct i2c_device_id *id) >>> +{ >>> + const struct is31fl32xx_chipdef *cdef; >>> + const struct of_device_id *of_dev_id; >>> + struct device *dev = &client->dev; >>> + struct is31fl32xx_priv *priv; >>> + int count; >>> + int ret = 0; >>> + >>> + of_dev_id = of_match_device(of_is31fl31xx_match, dev); >>> + if (!of_dev_id) >>> + return -EINVAL; >>> + >>> + cdef = of_dev_id->data; >>> + >>> + count = of_get_child_count(dev->of_node); >>> + if (!count) >>> + return -EINVAL; >>> + >>> + priv = devm_kzalloc(dev, sizeof_is31fl32xx_priv(count), >>> + GFP_KERNEL); >>> + if (!priv) >>> + return -ENOMEM; >>> + >>> + priv->client = client; >>> + priv->cdef = cdef; >>> + i2c_set_clientdata(client, priv); >>> + >>> + ret = is31fl32xx_init_regs(priv); >>> + if (ret) >>> + return ret; >>> + >>> + ret = is31fl32xx_parse_dt(dev, priv); >>> + if (ret) >>> + return ret; >>> + >>> + return 0; >>> +} >>> + >>> +static int is31fl32xx_remove(struct i2c_client *client) >>> +{ >>> + struct is31fl32xx_priv *priv = i2c_get_clientdata(client); >>> + >>> + return is31fl32xx_reset_regs(priv); >>> +} >>> + >>> +/* >>> + * i2c-core requires that id_table be non-NULL, even though >>> + * it is not used for DeviceTree based instantiation. >>> + */ >>> +static const struct i2c_device_id is31fl31xx_id[] = { >>> + {}, >>> +}; >>> + >>> +MODULE_DEVICE_TABLE(i2c, is31fl31xx_id); >>> + >>> +static struct i2c_driver is31fl32xx_driver = { >>> + .driver = { >>> + .name = "is31fl32xx", >>> + .of_match_table = of_is31fl31xx_match, >>> + }, >>> + .probe = is31fl32xx_probe, >>> + .remove = is31fl32xx_remove, >> >> Sorry, what was the reason to skip shutdown? > > If I understood Jacek's last email on the topic [1] correctly, he's now > of the opinion that the decision to turn LEDs off on reboot should be > left to userspace, rather than done by the driver. For these devices, > the only thing a shutdown callback would do is turn off the LEDs (through > any of multiple methods). So, if we want to leave the state as-is on > reboot there's no need for a shutdown callback. > > [1] http://www.spinics.net/lists/linux-leds/msg05644.html > >>> + .id_table = is31fl31xx_id, >>> +}; >>> + >>> +module_i2c_driver(is31fl32xx_driver); >>> + >>> +MODULE_AUTHOR("David Rivshin <drivshin@allworx.com>"); >>> +MODULE_DESCRIPTION("ISSI IS31FL32xx LED driver"); >>> +MODULE_LICENSE("GPL v2"); >>> -- >>> 2.5.0 >>> > > > -- Best regards, Jacek Anaszewski ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 3/4] leds: Add driver for the ISSI IS31FL32xx family of LED controllers 2016-03-04 15:38 ` Jacek Anaszewski @ 2016-03-05 6:12 ` David Rivshin (Allworx) 2016-03-05 11:39 ` Jacek Anaszewski 0 siblings, 1 reply; 28+ messages in thread From: David Rivshin (Allworx) @ 2016-03-05 6:12 UTC (permalink / raw) To: Jacek Anaszewski Cc: Stefan Wahren, linux-leds, devicetree, Pawel Moll, Rob Herring, Ian Campbell, Kumar Gala, linux-kernel, Richard Purdie, Mark Rutland On Fri, 04 Mar 2016 16:38:01 +0100 Jacek Anaszewski <j.anaszewski@samsung.com> wrote: > On 03/04/2016 03:27 PM, David Rivshin (Allworx) wrote: > > (Stefan, sorry for the duplicate, I just realized that I originally > > replied only to you by accident). > > > > On Thu, 3 Mar 2016 19:13:03 +0100 (CET) > > Stefan Wahren <stefan.wahren@i2se.com> wrote: > > > >> Hi David, > >> > >> i will test the driver on weekend. Some comments below > > > > Great, thanks very much. > > > >>> "David Rivshin (Allworx)" <drivshin.allworx@gmail.com> hat am 3. März 2016 um > >>> 04:01 geschrieben: > >>> > >>> > >>> From: David Rivshin <drivshin@allworx.com> > >>> > >>> The IS31FL32xx family of LED controllers are I2C devices with multiple > >>> constant-current channels, each with independent 256-level PWM control. > >>> > >>> Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml > >>> > >>> This has been tested on the IS31FL3236 and IS31FL3216, on an ARM > >>> (TI am335x) platform. > >>> > >>> The programming paradigm of these devices is similar in the following > >>> ways: > >>> - All registers are 8 bit > >>> - All LED control registers are write-only > >>> - Each LED channel has a PWM register (0-255) > >>> - PWM register writes are shadowed until an Update register is poked > >>> - All have a concept of Software Shutdown, which disables output > >>> > >>> However, there are some differences in devices: > >>> - 3236/3235 have a separate Control register for each LED, > >>> (3218/3216 pack the enable bits into fewer registers) > >>> - 3236/3235 have a per-channel current divisor setting > >>> - 3236/3235 have a Global Control register that can turn off all LEDs > >>> - 3216 is unique in a number of ways > >>> - OUT9-OUT16 can be configured as GPIOs instead of LED controls > >>> - LEDs can be programmed with an 8-frame animation, with > >>> programmable delay between frames > >>> - LEDs can be modulated by an input audio signal > >>> - Max output current can be adjusted from 1/4 to 2x globally > >>> - Has a Configuration register instead of a Shutdown register > >>> > >>> This driver currently only supports the base PWM control function > >>> of these devices. The following features of these devices are not > >>> implemented, although it should be possible to add them in the future: > >>> - All devices are capable of going into a lower-power "software > >>> shutdown" mode. > >>> - The is31fl3236 and is31fl3235 can reduce the max output current > >>> per-channel with a divisor of 1, 2, 3, or 4. > >>> - The is31fl3216 can use some LED channels as GPIOs instead. > >>> - The is31fl3216 can animate LEDs in hardware. > >>> - The is31fl3216 can modulate LEDs according to an audio input. > >>> - The is31fl3216 can reduce/increase max output current globally. > >>> > >>> Signed-off-by: David Rivshin <drivshin@allworx.com> > >>> --- > >>> > >>> You may see two instances of this warning: > >>> "passing argument 1 of 'of_property_read_string' discards 'const' > >>> qualifier from pointer target type" > >>> That is a result of of_property_read_string() taking a non-const > >>> struct device_node pointer parameter. I have separately submitted a > >>> patch to fix that [1], and a few related functions which had the same > >>> issue. I'm hoping that will get into linux-next before this does, so > >>> that the warnings never show up there. > >>> > >>> Changes from RFC: > >>> - Removed max-brightness DT property. > >>> - Refer to these devices as "LED controllers" in Kconfig. > >>> - Removed redundant last sentence from Kconfig entry > >>> - Removed unnecessary debug code. > >>> - Do not set led_classdev.brightness to 0 explicitly, as it is > >>> already initialized to 0 by devm_kzalloc(). > >>> - Used of_property_read_string() instead of of_get_property(). > >>> - Fail immediately on DT parsing error in a child node, rather than > >>> continuing on with the non-faulty ones. > >>> - Added additional comments for some things that might be non-obvious. > >>> - Added constants for the location of the SSD bit in the SHUTDOWN > >>> register, and the 3216's CONFIG register. > >>> - Added special sw_shutdown_func for the 3216 device, as that bit > >>> is in a different register, at a different position, and has reverse > >>> polarity compared to all the other devices. > >>> - Refactored is31fl32xx_init_regs() to separate out some logic into > >>> is31fl32xx_reset_regs() and is31fl32xx_software_shutdown(). > >>> > >>> [1] https://lkml.org/lkml/2016/3/2/746 > >>> > >>> drivers/leds/Kconfig | 8 + > >>> drivers/leds/Makefile | 1 + > >>> drivers/leds/leds-is31fl32xx.c | 505 +++++++++++++++++++++++++++++++++++++++++ > >>> 3 files changed, 514 insertions(+) > >>> create mode 100644 drivers/leds/leds-is31fl32xx.c > >>> > >>> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig > >>> index 1034696..9c63ba4 100644 > >>> --- a/drivers/leds/Kconfig > >>> +++ b/drivers/leds/Kconfig > >>> @@ -580,6 +580,14 @@ config LEDS_SN3218 > >>> This driver can also be built as a module. If so the module > >>> will be called leds-sn3218. > >>> > >>> +config LEDS_IS31FL32XX > >>> + tristate "LED support for ISSI IS31FL32XX I2C LED controller family" > >>> + depends on LEDS_CLASS && I2C && OF > >>> + help > >>> + Say Y here to include support for ISSI IS31FL32XX LED controllers. > >>> + They are I2C devices with multiple constant-current channels, each > >>> + with independent 256-level PWM control. > >> > >> Is it worth to mention the module name here? > > > > I noticed that some do and some don't. I don't mind adding it, but it > > also seemed like it would be obvious, and therefore unnecessary. > > > > Jacek, which do you prefer? > > I agree - it's obvious, we can skip it. > > >>> + > >>> comment "LED driver for blink(1) USB RGB LED is under Special HID drivers > >>> (HID_THINGM)" > >>> > >>> config LEDS_BLINKM > >>> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile > >>> index 89c9b6f..3fdf313 100644 > >>> --- a/drivers/leds/Makefile > >>> +++ b/drivers/leds/Makefile > >>> @@ -67,6 +67,7 @@ obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o > >>> obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o > >>> obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o > >>> obj-$(CONFIG_LEDS_SN3218) += leds-sn3218.o > >>> +obj-$(CONFIG_LEDS_IS31FL32XX) += leds-is31fl32xx.o > >>> > >>> # LED SPI Drivers > >>> obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o > >>> diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c > >>> new file mode 100644 > >>> index 0000000..49818f0 > >>> --- /dev/null > >>> +++ b/drivers/leds/leds-is31fl32xx.c > >>> @@ -0,0 +1,505 @@ > >>> +/* > >>> + * linux/drivers/leds-is31fl32xx.c > >> > >> I think this is unnecessary. > > > > I tend to agree. I think I used leds-pwm.c as a template, and that had > > such a comment. I assumed it was coding-style and kept it, but now I see > > that only a minority of led drivers have it. If I do another spin for > > any reason I'll remove it. > > > >>> + * > >>> + * Driver for ISSI IS31FL32xx family of I2C LED controllers > >>> + * > >>> + * Copyright 2015 Allworx Corp. > >>> + * > >>> + * > >>> + * 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. > >>> + * > >>> + * Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml > >>> + */ > >>> + > >> > >> Shouldn't we include <linux/device.h> here? > > > > Good catch. I was getting that via i2c.h, but since struct device is > > referenced explicitly in a few places, device.h should probably be > > included directly. > > linux/device.h is included from linux/leds.h This is true, but SubmitChecklist says the following on this topic: 1: If you use a facility then #include the file that defines/declares that facility. Don't depend on other header files pulling in ones that you use. (Oddly CodingStyle is silent on the topic, which is where I would have thought such a thing would be documented.) I interpreted that to mean that because 'struct device*' appears in this file, it should include <linux/device.h> directly. > >>> +#include <linux/err.h> > >>> +#include <linux/i2c.h> > >>> +#include <linux/kernel.h> > >>> +#include <linux/leds.h> > >>> +#include <linux/module.h> > >>> +#include <linux/of_platform.h> > >>> + > >>> +/* Used to indicate a device has no such register */ > >>> +#define IS31FL32XX_REG_NONE 0xFF > >>> + > >>> +/* Software Shutdown bit in Shutdown Register */ > >>> +#define IS31FL32XX_SHUTDOWN_SSD_ENABLE 0 > >>> +#define IS31FL32XX_SHUTDOWN_SSD_DISABLE BIT(0) > >>> + > >>> +/* IS31FL3216 has a number of unique registers */ > >>> +#define IS31FL3216_CONFIG_REG 0x00 > >>> +#define IS31FL3216_LIGHTING_EFFECT_REG 0x03 > >>> +#define IS31FL3216_CHANNEL_CONFIG_REG 0x04 > >>> + > >>> +/* Software Shutdown bit in 3216 Config Register */ > >>> +#define IS31FL3216_CONFIG_SSD_ENABLE BIT(7) > >>> +#define IS31FL3216_CONFIG_SSD_DISABLE 0 > >>> + > >>> +struct is31fl32xx_priv; > >>> +struct is31fl32xx_led_data { > >>> + struct led_classdev cdev; > >>> + u8 channel; /* 1-based, max priv->cdef->channels */ > >>> + struct is31fl32xx_priv *priv; > >>> +}; > >>> + > >>> +struct is31fl32xx_priv { > >>> + const struct is31fl32xx_chipdef *cdef; > >>> + struct i2c_client *client; > >>> + unsigned int num_leds; > >>> + struct is31fl32xx_led_data leds[0]; > >>> +}; > >>> + > >>> +/** > >>> + * struct is31fl32xx_chipdef - chip-specific attributes > >>> + * @channels : Number of LED channels > >>> + * @shutdown_reg : address of Shutdown register (optional) > >>> + * @pwm_update_reg : address of PWM Update register > >>> + * @global_control_reg : address of Global Control register (optional) > >>> + * @reset_reg : address of Reset register (optional) > >>> + * @pwm_register_base : address of first PWM register > >>> + * @pwm_registers_reversed: : true if PWM registers count down instead of up > >>> + * @led_control_register_base : address of first LED control register > >>> (optional) > >>> + * @enable_bits_per_led_control_register: number of LEDs enable bits in each > >>> + * @reset_func: : pointer to reset function > >>> + * > >>> + * For all optional register addresses, the sentinel value > >>> %IS31FL32XX_REG_NONE > >>> + * indicates that this chip has no such register. > >>> + * > >>> + * If non-NULL, @reset_func will be called during probing to set all > >>> + * necessary registers to a known initialization state. This is needed > >>> + * for chips that do not have a @reset_reg. > >>> + * > >>> + * @enable_bits_per_led_control_register must be >=1 if > >>> + * @led_control_register_base != %IS31FL32XX_REG_NONE. > >>> + */ > >>> +struct is31fl32xx_chipdef { > >>> + u8 channels; > >>> + u8 shutdown_reg; > >>> + u8 pwm_update_reg; > >>> + u8 global_control_reg; > >>> + u8 reset_reg; > >>> + u8 pwm_register_base; > >>> + bool pwm_registers_reversed; > >>> + u8 led_control_register_base; > >>> + u8 enable_bits_per_led_control_register; > >>> + int (*reset_func)(struct is31fl32xx_priv *priv); > >>> + int (*sw_shutdown_func)(struct is31fl32xx_priv *priv, bool enable); > >>> +}; > >>> + > >>> +static const struct is31fl32xx_chipdef is31fl3236_cdef = { > >>> + .channels = 36, > >>> + .shutdown_reg = 0x00, > >>> + .pwm_update_reg = 0x25, > >>> + .global_control_reg = 0x4a, > >>> + .reset_reg = 0x4f, > >>> + .pwm_register_base = 0x01, > >>> + .led_control_register_base = 0x26, > >>> + .enable_bits_per_led_control_register = 1, > >>> +}; > >>> + > >>> +static const struct is31fl32xx_chipdef is31fl3235_cdef = { > >>> + .channels = 28, > >>> + .shutdown_reg = 0x00, > >>> + .pwm_update_reg = 0x25, > >>> + .global_control_reg = 0x4a, > >>> + .reset_reg = 0x4f, > >>> + .pwm_register_base = 0x05, > >>> + .led_control_register_base = 0x2a, > >>> + .enable_bits_per_led_control_register = 1, > >>> +}; > >>> + > >>> +static const struct is31fl32xx_chipdef is31fl3218_cdef = { > >>> + .channels = 18, > >>> + .shutdown_reg = 0x00, > >>> + .pwm_update_reg = 0x16, > >>> + .global_control_reg = IS31FL32XX_REG_NONE, > >>> + .reset_reg = 0x17, > >>> + .pwm_register_base = 0x01, > >>> + .led_control_register_base = 0x13, > >>> + .enable_bits_per_led_control_register = 6, > >>> +}; > >>> + > >>> +static int is31fl3216_reset(struct is31fl32xx_priv *priv); > >>> +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, > >>> + bool enable); > >>> +static const struct is31fl32xx_chipdef is31fl3216_cdef = { > >>> + .channels = 16, > >>> + .shutdown_reg = IS31FL32XX_REG_NONE, > >>> + .pwm_update_reg = 0xB0, > >>> + .global_control_reg = IS31FL32XX_REG_NONE, > >>> + .reset_reg = IS31FL32XX_REG_NONE, > >>> + .pwm_register_base = 0x10, > >>> + .pwm_registers_reversed = true, > >>> + .led_control_register_base = 0x01, > >>> + .enable_bits_per_led_control_register = 8, > >>> + .reset_func = is31fl3216_reset, > >>> + .sw_shutdown_func = is31fl3216_software_shutdown, > >>> +}; > >>> + > >>> +static int is31fl32xx_write(struct is31fl32xx_priv *priv, u8 reg, u8 val) > >>> +{ > >>> + int ret; > >>> + > >>> + dev_dbg(&priv->client->dev, "writing register 0x%02X=0x%02X", reg, val); > >>> + > >>> + ret = i2c_smbus_write_byte_data(priv->client, reg, val); > >>> + if (ret) { > >>> + dev_err(&priv->client->dev, > >>> + "register write to 0x%02X failed (error %d)", > >>> + reg, ret); > >>> + } > >> > >> In case somebody use this driver as heartbeat and writing fails permanently the > >> log will be flooded. > > > > Unless I'm mistaken that would require the device/bus to fail after > > successfully probing (probe code itself bails on the first write > > failure, so there would be no flooding as a result of that). So while > > not impossible, I imagine it would be unlikely, and I'd hate to remove > > an error message for such an important condition. > > > > I suppose I could use dev_err_ratelimited() to soften any potential > > flooding, but I second guess that because: > > - In led_core.c set_brightness_delayed() has a dev_err() that would come > > out on each failed LED update anyways. > > - There is precedent in other led drivers of a similar error message. > > - Some userspace logging programs will compresses repeated messages anyways. > > > > Jacek, what is your preference on this? > > Let's leave it as is. Permanent I2C bus failure is a critical error and > flooding the log would only allow to diagnose the problem quicker. > > >>> + return ret; > >>> +} > >>> + > >>> +/* > >>> + * Custom reset function for IS31FL3216 because it does not have a RESET > >>> + * register the way that the other IS31FL32xx chips do. We don't bother > >>> + * writing the GPIO and animation registers, because the registers we > >>> + * do write ensure those will have no effect. > >>> + */ > >>> +static int is31fl3216_reset(struct is31fl32xx_priv *priv) > >>> +{ > >>> + unsigned int i; > >>> + int ret; > >>> + > >>> + ret = is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, > >>> + IS31FL3216_CONFIG_SSD_ENABLE); > >>> + if (ret) > >>> + return ret; > >>> + for (i = 0; i < priv->cdef->channels; i++) { > >>> + ret = is31fl32xx_write(priv, priv->cdef->pwm_register_base+i, > >>> + 0x00); > >>> + if (ret) > >>> + return ret; > >>> + } > >>> + ret = is31fl32xx_write(priv, priv->cdef->pwm_update_reg, 0); > >>> + if (ret) > >>> + return ret; > >>> + ret = is31fl32xx_write(priv, IS31FL3216_LIGHTING_EFFECT_REG, 0x00); > >>> + if (ret) > >>> + return ret; > >>> + ret = is31fl32xx_write(priv, IS31FL3216_CHANNEL_CONFIG_REG, 0x00); > >>> + if (ret) > >>> + return ret; > >>> + > >>> + return 0; > >>> +} > >>> + > >>> +/* > >>> + * Custom Software-Shutdown function for IS31FL3216 because it does not have > >>> + * a SHUTDOWN register the way that the other IS31FL32xx chips do. > >>> + * We don't bother doing a read/modify/write on the CONFIG register because > >>> + * we only ever use a value of '0' for the other fields in that register. > >>> + */ > >>> +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, > >>> + bool enable) > >>> +{ > >>> + u8 value = enable ? IS31FL3216_CONFIG_SSD_ENABLE : > >>> + IS31FL3216_CONFIG_SSD_DISABLE; > >>> + > >>> + return is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, value); > >>> +} > >>> + > >>> +/* > >>> + * NOTE: A mutex is not needed in this function because: > >>> + * - All referenced data is read-only after probe() > >>> + * - The I2C core has a mutex on to protect the bus > >>> + * - There are no read/modify/write operations > >>> + * - Intervening operations between the write of the PWM register > >>> + * and the Update register are harmless. > >>> + * > >>> + * Example: > >>> + * PWM_REG_1 write 16 > >>> + * UPDATE_REG write 0 > >>> + * PWM_REG_2 write 128 > >>> + * UPDATE_REG write 0 > >>> + * vs: > >>> + * PWM_REG_1 write 16 > >>> + * PWM_REG_2 write 128 > >>> + * UPDATE_REG write 0 > >>> + * UPDATE_REG write 0 > >>> + * are equivalent. Poking the Update register merely applies all PWM > >>> + * register writes up to that point. > >>> + */ > >>> +static int is31fl32xx_brightness_set(struct led_classdev *led_cdev, > >>> + enum led_brightness brightness) > >>> +{ > >>> + const struct is31fl32xx_led_data *led_data = > >>> + container_of(led_cdev, struct is31fl32xx_led_data, cdev); > >>> + const struct is31fl32xx_chipdef *cdef = led_data->priv->cdef; > >>> + u8 pwm_register_offset; > >>> + int ret; > >>> + > >>> + dev_dbg(led_cdev->dev, "%s: %d\n", __func__, brightness); > >>> + > >>> + /* NOTE: led_data->channel is 1-based */ > >>> + if (cdef->pwm_registers_reversed) > >>> + pwm_register_offset = cdef->channels - led_data->channel; > >>> + else > >>> + pwm_register_offset = led_data->channel - 1; > >>> + > >>> + ret = is31fl32xx_write(led_data->priv, > >>> + cdef->pwm_register_base + pwm_register_offset, > >>> + brightness); > >>> + if (ret) > >>> + return ret; > >>> + > >>> + return is31fl32xx_write(led_data->priv, cdef->pwm_update_reg, 0); > >>> +} > >>> + > >>> +static int is31fl32xx_reset_regs(struct is31fl32xx_priv *priv) > >>> +{ > >>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; > >>> + int ret; > >>> + > >>> + if (cdef->reset_reg != IS31FL32XX_REG_NONE) { > >>> + ret = is31fl32xx_write(priv, cdef->reset_reg, 0); > >>> + if (ret) > >>> + return ret; > >>> + } > >>> + > >>> + if (cdef->reset_func) > >>> + return cdef->reset_func(priv); > >>> + > >>> + return 0; > >>> +} > >>> + > >>> +static int is31fl32xx_software_shutdown(struct is31fl32xx_priv *priv, > >>> + bool enable) > >>> +{ > >>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; > >>> + int ret; > >>> + > >>> + if (cdef->shutdown_reg != IS31FL32XX_REG_NONE) { > >>> + u8 value = enable ? IS31FL32XX_SHUTDOWN_SSD_ENABLE : > >>> + IS31FL32XX_SHUTDOWN_SSD_DISABLE; > >>> + ret = is31fl32xx_write(priv, cdef->shutdown_reg, value); > >>> + if (ret) > >>> + return ret; > >>> + } > >>> + > >>> + if (cdef->sw_shutdown_func) > >>> + return cdef->sw_shutdown_func(priv, enable); > >>> + > >>> + return 0; > >>> +} > >>> + > >>> +static int is31fl32xx_init_regs(struct is31fl32xx_priv *priv) > >>> +{ > >>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; > >>> + int ret; > >>> + > >>> + ret = is31fl32xx_reset_regs(priv); > >>> + if (ret) > >>> + return ret; > >>> + > >>> + /* > >>> + * Set enable bit for all channels. > >>> + * We will control state with PWM registers alone. > >>> + */ > >>> + if (cdef->led_control_register_base != IS31FL32XX_REG_NONE) { > >>> + u8 value = > >>> + GENMASK(cdef->enable_bits_per_led_control_register-1, 0); > >>> + u8 num_regs = cdef->channels / > >>> + cdef->enable_bits_per_led_control_register; > >>> + int i; > >>> + > >>> + for (i = 0; i < num_regs; i++) { > >>> + ret = is31fl32xx_write(priv, > >>> + cdef->led_control_register_base+i, > >>> + value); > >>> + if (ret) > >>> + return ret; > >>> + } > >>> + } > >>> + > >>> + ret = is31fl32xx_software_shutdown(priv, false); > >>> + if (ret) > >>> + return ret; > >>> + > >>> + if (cdef->global_control_reg != IS31FL32XX_REG_NONE) { > >>> + ret = is31fl32xx_write(priv, cdef->global_control_reg, 0x00); > >>> + if (ret) > >>> + return ret; > >>> + } > >>> + > >>> + return 0; > >>> +} > >>> + > >>> +static inline size_t sizeof_is31fl32xx_priv(int num_leds) > >>> +{ > >>> + return sizeof(struct is31fl32xx_priv) + > >>> + (sizeof(struct is31fl32xx_led_data) * num_leds); > >>> +} > >>> + > >>> +static int is31fl32xx_parse_child_dt(const struct device *dev, > >>> + const struct device_node *child, > >>> + struct is31fl32xx_led_data *led_data) > >>> +{ > >>> + struct led_classdev *cdev = &led_data->cdev; > >>> + int ret = 0; > >>> + u32 reg; > >>> + > >>> + if (of_property_read_string(child, "label", &cdev->name)) > >>> + cdev->name = child->name; > >>> + > >>> + ret = of_property_read_u32(child, "reg", ®); > >>> + if (ret || reg < 1 || reg > led_data->priv->cdef->channels) { > >>> + dev_err(dev, > >>> + "Child node %s does not have a valid reg property\n", > >>> + child->full_name); > >>> + return -EINVAL; > >>> + } > >>> + led_data->channel = reg; > >>> + > >>> + of_property_read_string(child, "linux,default-trigger", > >>> + &cdev->default_trigger); > >>> + > >>> + cdev->brightness_set_blocking = is31fl32xx_brightness_set; > >>> + > >>> + return 0; > >>> +} > >>> + > >>> +static struct is31fl32xx_led_data *is31fl32xx_find_led_data( > >>> + struct is31fl32xx_priv *priv, > >>> + u8 channel) > >>> +{ > >>> + size_t i; > >>> + > >>> + for (i = 0; i < priv->num_leds; i++) { > >>> + if (priv->leds[i].channel == channel) > >>> + return &priv->leds[i]; > >>> + } > >>> + > >>> + return NULL; > >>> +} > >>> + > >>> +static int is31fl32xx_parse_dt(struct device *dev, > >>> + struct is31fl32xx_priv *priv) > >>> +{ > >>> + struct device_node *child; > >>> + int ret = 0; > >>> + > >>> + for_each_child_of_node(dev->of_node, child) { > >>> + struct is31fl32xx_led_data *led_data = > >>> + &priv->leds[priv->num_leds]; > >> > >> Maybe i missed something, but is it really protected against out of index > >> access? > > > > The array is allocated with size equal to the number of child nodes, > > and num_leds is incremented once for each child node parsed. So in > > order for the index to be out of bounds, the number of child nodes > > would need to increase during the probe. I assumed that the DT is > > static during probing, but if that's not the case then you're right > > that this is a potential problem. Also, this equivalent logic is > > used in leds-pwm, leds-gpio, and leds-ns2, so that gives me > > confidence that its safe. > > Unless DT overlays change that assumption? > > DT overlays would matter here if child DT nodes could be dynamically > removed, i.e. if it was possible by design to dynamically unplug LEDs > from the current outputs during LED controller operation, which is not > the case for this device (and any other LED controller I am aware of). > > >>> + const struct is31fl32xx_led_data *other_led_data; > >>> + > >>> + led_data->priv = priv; > >>> + > >>> + ret = is31fl32xx_parse_child_dt(dev, child, led_data); > >>> + if (ret) > >>> + goto err; > >>> + > >>> + /* Detect if channel is already in use by another child */ > >>> + other_led_data = is31fl32xx_find_led_data(priv, > >>> + led_data->channel); > >>> + if (other_led_data) { > >>> + dev_err(dev, > >>> + "%s and %s both attempting to use channel %d\n", > >>> + led_data->cdev.name, > >>> + other_led_data->cdev.name, > >>> + led_data->channel); > >>> + goto err; > >>> + } > >>> + > >>> + ret = devm_led_classdev_register(dev, &led_data->cdev); > >>> + if (ret) { > >>> + dev_err(dev, "failed to register PWM led for %s: %d\n", > >>> + led_data->cdev.name, ret); > >>> + goto err; > >>> + } > >>> + > >>> + priv->num_leds++; > >>> + } > >>> + > >>> + return 0; > >>> + > >>> +err: > >>> + of_node_put(child); > >>> + return ret; > >>> +} > >>> + > >>> +static const struct of_device_id of_is31fl31xx_match[] = { > >>> + { .compatible = "issi,is31fl3236", .data = &is31fl3236_cdef, }, > >>> + { .compatible = "issi,is31fl3235", .data = &is31fl3235_cdef, }, > >>> + { .compatible = "issi,is31fl3218", .data = &is31fl3218_cdef, }, > >>> + { .compatible = "issi,is31fl3216", .data = &is31fl3216_cdef, }, > >>> + {}, > >>> +}; > >>> + > >>> +MODULE_DEVICE_TABLE(of, of_is31fl31xx_match); > >>> + > >>> +static int is31fl32xx_probe(struct i2c_client *client, > >>> + const struct i2c_device_id *id) > >>> +{ > >>> + const struct is31fl32xx_chipdef *cdef; > >>> + const struct of_device_id *of_dev_id; > >>> + struct device *dev = &client->dev; > >>> + struct is31fl32xx_priv *priv; > >>> + int count; > >>> + int ret = 0; > >>> + > >>> + of_dev_id = of_match_device(of_is31fl31xx_match, dev); > >>> + if (!of_dev_id) > >>> + return -EINVAL; > >>> + > >>> + cdef = of_dev_id->data; > >>> + > >>> + count = of_get_child_count(dev->of_node); > >>> + if (!count) > >>> + return -EINVAL; > >>> + > >>> + priv = devm_kzalloc(dev, sizeof_is31fl32xx_priv(count), > >>> + GFP_KERNEL); > >>> + if (!priv) > >>> + return -ENOMEM; > >>> + > >>> + priv->client = client; > >>> + priv->cdef = cdef; > >>> + i2c_set_clientdata(client, priv); > >>> + > >>> + ret = is31fl32xx_init_regs(priv); > >>> + if (ret) > >>> + return ret; > >>> + > >>> + ret = is31fl32xx_parse_dt(dev, priv); > >>> + if (ret) > >>> + return ret; > >>> + > >>> + return 0; > >>> +} > >>> + > >>> +static int is31fl32xx_remove(struct i2c_client *client) > >>> +{ > >>> + struct is31fl32xx_priv *priv = i2c_get_clientdata(client); > >>> + > >>> + return is31fl32xx_reset_regs(priv); > >>> +} > >>> + > >>> +/* > >>> + * i2c-core requires that id_table be non-NULL, even though > >>> + * it is not used for DeviceTree based instantiation. > >>> + */ > >>> +static const struct i2c_device_id is31fl31xx_id[] = { > >>> + {}, > >>> +}; > >>> + > >>> +MODULE_DEVICE_TABLE(i2c, is31fl31xx_id); > >>> + > >>> +static struct i2c_driver is31fl32xx_driver = { > >>> + .driver = { > >>> + .name = "is31fl32xx", > >>> + .of_match_table = of_is31fl31xx_match, > >>> + }, > >>> + .probe = is31fl32xx_probe, > >>> + .remove = is31fl32xx_remove, > >> > >> Sorry, what was the reason to skip shutdown? > > > > If I understood Jacek's last email on the topic [1] correctly, he's now > > of the opinion that the decision to turn LEDs off on reboot should be > > left to userspace, rather than done by the driver. For these devices, > > the only thing a shutdown callback would do is turn off the LEDs (through > > any of multiple methods). So, if we want to leave the state as-is on > > reboot there's no need for a shutdown callback. > > > > [1] http://www.spinics.net/lists/linux-leds/msg05644.html > > > >>> + .id_table = is31fl31xx_id, > >>> +}; > >>> + > >>> +module_i2c_driver(is31fl32xx_driver); > >>> + > >>> +MODULE_AUTHOR("David Rivshin <drivshin@allworx.com>"); > >>> +MODULE_DESCRIPTION("ISSI IS31FL32xx LED driver"); > >>> +MODULE_LICENSE("GPL v2"); > >>> -- > >>> 2.5.0 > >>> ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 3/4] leds: Add driver for the ISSI IS31FL32xx family of LED controllers 2016-03-05 6:12 ` David Rivshin (Allworx) @ 2016-03-05 11:39 ` Jacek Anaszewski 0 siblings, 0 replies; 28+ messages in thread From: Jacek Anaszewski @ 2016-03-05 11:39 UTC (permalink / raw) To: David Rivshin (Allworx), Jacek Anaszewski Cc: Stefan Wahren, linux-leds, devicetree, Pawel Moll, Rob Herring, Ian Campbell, Kumar Gala, linux-kernel, Richard Purdie, Mark Rutland On 03/05/2016 07:12 AM, David Rivshin (Allworx) wrote: > On Fri, 04 Mar 2016 16:38:01 +0100 > Jacek Anaszewski <j.anaszewski@samsung.com> wrote: > >> On 03/04/2016 03:27 PM, David Rivshin (Allworx) wrote: >>> (Stefan, sorry for the duplicate, I just realized that I originally >>> replied only to you by accident). >>> >>> On Thu, 3 Mar 2016 19:13:03 +0100 (CET) >>> Stefan Wahren <stefan.wahren@i2se.com> wrote: >>> >>>> Hi David, >>>> >>>> i will test the driver on weekend. Some comments below >>> >>> Great, thanks very much. >>> >>>>> "David Rivshin (Allworx)" <drivshin.allworx@gmail.com> hat am 3. März 2016 um >>>>> 04:01 geschrieben: >>>>> >>>>> >>>>> From: David Rivshin <drivshin@allworx.com> >>>>> >>>>> The IS31FL32xx family of LED controllers are I2C devices with multiple >>>>> constant-current channels, each with independent 256-level PWM control. >>>>> >>>>> Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml >>>>> >>>>> This has been tested on the IS31FL3236 and IS31FL3216, on an ARM >>>>> (TI am335x) platform. >>>>> >>>>> The programming paradigm of these devices is similar in the following >>>>> ways: >>>>> - All registers are 8 bit >>>>> - All LED control registers are write-only >>>>> - Each LED channel has a PWM register (0-255) >>>>> - PWM register writes are shadowed until an Update register is poked >>>>> - All have a concept of Software Shutdown, which disables output >>>>> >>>>> However, there are some differences in devices: >>>>> - 3236/3235 have a separate Control register for each LED, >>>>> (3218/3216 pack the enable bits into fewer registers) >>>>> - 3236/3235 have a per-channel current divisor setting >>>>> - 3236/3235 have a Global Control register that can turn off all LEDs >>>>> - 3216 is unique in a number of ways >>>>> - OUT9-OUT16 can be configured as GPIOs instead of LED controls >>>>> - LEDs can be programmed with an 8-frame animation, with >>>>> programmable delay between frames >>>>> - LEDs can be modulated by an input audio signal >>>>> - Max output current can be adjusted from 1/4 to 2x globally >>>>> - Has a Configuration register instead of a Shutdown register >>>>> >>>>> This driver currently only supports the base PWM control function >>>>> of these devices. The following features of these devices are not >>>>> implemented, although it should be possible to add them in the future: >>>>> - All devices are capable of going into a lower-power "software >>>>> shutdown" mode. >>>>> - The is31fl3236 and is31fl3235 can reduce the max output current >>>>> per-channel with a divisor of 1, 2, 3, or 4. >>>>> - The is31fl3216 can use some LED channels as GPIOs instead. >>>>> - The is31fl3216 can animate LEDs in hardware. >>>>> - The is31fl3216 can modulate LEDs according to an audio input. >>>>> - The is31fl3216 can reduce/increase max output current globally. >>>>> >>>>> Signed-off-by: David Rivshin <drivshin@allworx.com> >>>>> --- >>>>> >>>>> You may see two instances of this warning: >>>>> "passing argument 1 of 'of_property_read_string' discards 'const' >>>>> qualifier from pointer target type" >>>>> That is a result of of_property_read_string() taking a non-const >>>>> struct device_node pointer parameter. I have separately submitted a >>>>> patch to fix that [1], and a few related functions which had the same >>>>> issue. I'm hoping that will get into linux-next before this does, so >>>>> that the warnings never show up there. >>>>> >>>>> Changes from RFC: >>>>> - Removed max-brightness DT property. >>>>> - Refer to these devices as "LED controllers" in Kconfig. >>>>> - Removed redundant last sentence from Kconfig entry >>>>> - Removed unnecessary debug code. >>>>> - Do not set led_classdev.brightness to 0 explicitly, as it is >>>>> already initialized to 0 by devm_kzalloc(). >>>>> - Used of_property_read_string() instead of of_get_property(). >>>>> - Fail immediately on DT parsing error in a child node, rather than >>>>> continuing on with the non-faulty ones. >>>>> - Added additional comments for some things that might be non-obvious. >>>>> - Added constants for the location of the SSD bit in the SHUTDOWN >>>>> register, and the 3216's CONFIG register. >>>>> - Added special sw_shutdown_func for the 3216 device, as that bit >>>>> is in a different register, at a different position, and has reverse >>>>> polarity compared to all the other devices. >>>>> - Refactored is31fl32xx_init_regs() to separate out some logic into >>>>> is31fl32xx_reset_regs() and is31fl32xx_software_shutdown(). >>>>> >>>>> [1] https://lkml.org/lkml/2016/3/2/746 >>>>> >>>>> drivers/leds/Kconfig | 8 + >>>>> drivers/leds/Makefile | 1 + >>>>> drivers/leds/leds-is31fl32xx.c | 505 +++++++++++++++++++++++++++++++++++++++++ >>>>> 3 files changed, 514 insertions(+) >>>>> create mode 100644 drivers/leds/leds-is31fl32xx.c >>>>> >>>>> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig >>>>> index 1034696..9c63ba4 100644 >>>>> --- a/drivers/leds/Kconfig >>>>> +++ b/drivers/leds/Kconfig >>>>> @@ -580,6 +580,14 @@ config LEDS_SN3218 >>>>> This driver can also be built as a module. If so the module >>>>> will be called leds-sn3218. >>>>> >>>>> +config LEDS_IS31FL32XX >>>>> + tristate "LED support for ISSI IS31FL32XX I2C LED controller family" >>>>> + depends on LEDS_CLASS && I2C && OF >>>>> + help >>>>> + Say Y here to include support for ISSI IS31FL32XX LED controllers. >>>>> + They are I2C devices with multiple constant-current channels, each >>>>> + with independent 256-level PWM control. >>>> >>>> Is it worth to mention the module name here? >>> >>> I noticed that some do and some don't. I don't mind adding it, but it >>> also seemed like it would be obvious, and therefore unnecessary. >>> >>> Jacek, which do you prefer? >> >> I agree - it's obvious, we can skip it. >> >>>>> + >>>>> comment "LED driver for blink(1) USB RGB LED is under Special HID drivers >>>>> (HID_THINGM)" >>>>> >>>>> config LEDS_BLINKM >>>>> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile >>>>> index 89c9b6f..3fdf313 100644 >>>>> --- a/drivers/leds/Makefile >>>>> +++ b/drivers/leds/Makefile >>>>> @@ -67,6 +67,7 @@ obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o >>>>> obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o >>>>> obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o >>>>> obj-$(CONFIG_LEDS_SN3218) += leds-sn3218.o >>>>> +obj-$(CONFIG_LEDS_IS31FL32XX) += leds-is31fl32xx.o >>>>> >>>>> # LED SPI Drivers >>>>> obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o >>>>> diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c >>>>> new file mode 100644 >>>>> index 0000000..49818f0 >>>>> --- /dev/null >>>>> +++ b/drivers/leds/leds-is31fl32xx.c >>>>> @@ -0,0 +1,505 @@ >>>>> +/* >>>>> + * linux/drivers/leds-is31fl32xx.c >>>> >>>> I think this is unnecessary. >>> >>> I tend to agree. I think I used leds-pwm.c as a template, and that had >>> such a comment. I assumed it was coding-style and kept it, but now I see >>> that only a minority of led drivers have it. If I do another spin for >>> any reason I'll remove it. >>> >>>>> + * >>>>> + * Driver for ISSI IS31FL32xx family of I2C LED controllers >>>>> + * >>>>> + * Copyright 2015 Allworx Corp. >>>>> + * >>>>> + * >>>>> + * 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. >>>>> + * >>>>> + * Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml >>>>> + */ >>>>> + >>>> >>>> Shouldn't we include <linux/device.h> here? >>> >>> Good catch. I was getting that via i2c.h, but since struct device is >>> referenced explicitly in a few places, device.h should probably be >>> included directly. >> >> linux/device.h is included from linux/leds.h > > This is true, but SubmitChecklist says the following on this topic: > 1: If you use a facility then #include the file that defines/declares > that facility. Don't depend on other header files pulling in ones > that you use. I'm not sure why declarations are mentioned here. If a type is used only as an opaque pointer, a declaration suffices. It reduces the number of build dependencies. > (Oddly CodingStyle is silent on the topic, which is where I would have > thought such a thing would be documented.) > > I interpreted that to mean that because 'struct device*' appears in > this file, it should include <linux/device.h> directly. The header is required if full information about the type implementation is required, i.e. there are defined variables of the type or the code refers to the type properties (e.g. dev->of_node). linux/leds.h could compile without including linux/device.h, if only it declared struct device, struct attribute_group and struct device_attribute types. It might have been that that this include directive has been added intentionally for the LED class drivers not to be forced to include it on their own, and indeed most of them don't do it. Nothing prevents us from sticking to the SubmitChecklist though. >>>>> +#include <linux/err.h> >>>>> +#include <linux/i2c.h> >>>>> +#include <linux/kernel.h> >>>>> +#include <linux/leds.h> >>>>> +#include <linux/module.h> >>>>> +#include <linux/of_platform.h> >>>>> + >>>>> +/* Used to indicate a device has no such register */ >>>>> +#define IS31FL32XX_REG_NONE 0xFF >>>>> + >>>>> +/* Software Shutdown bit in Shutdown Register */ >>>>> +#define IS31FL32XX_SHUTDOWN_SSD_ENABLE 0 >>>>> +#define IS31FL32XX_SHUTDOWN_SSD_DISABLE BIT(0) >>>>> + >>>>> +/* IS31FL3216 has a number of unique registers */ >>>>> +#define IS31FL3216_CONFIG_REG 0x00 >>>>> +#define IS31FL3216_LIGHTING_EFFECT_REG 0x03 >>>>> +#define IS31FL3216_CHANNEL_CONFIG_REG 0x04 >>>>> + >>>>> +/* Software Shutdown bit in 3216 Config Register */ >>>>> +#define IS31FL3216_CONFIG_SSD_ENABLE BIT(7) >>>>> +#define IS31FL3216_CONFIG_SSD_DISABLE 0 >>>>> + >>>>> +struct is31fl32xx_priv; >>>>> +struct is31fl32xx_led_data { >>>>> + struct led_classdev cdev; >>>>> + u8 channel; /* 1-based, max priv->cdef->channels */ >>>>> + struct is31fl32xx_priv *priv; >>>>> +}; >>>>> + >>>>> +struct is31fl32xx_priv { >>>>> + const struct is31fl32xx_chipdef *cdef; >>>>> + struct i2c_client *client; >>>>> + unsigned int num_leds; >>>>> + struct is31fl32xx_led_data leds[0]; >>>>> +}; >>>>> + >>>>> +/** >>>>> + * struct is31fl32xx_chipdef - chip-specific attributes >>>>> + * @channels : Number of LED channels >>>>> + * @shutdown_reg : address of Shutdown register (optional) >>>>> + * @pwm_update_reg : address of PWM Update register >>>>> + * @global_control_reg : address of Global Control register (optional) >>>>> + * @reset_reg : address of Reset register (optional) >>>>> + * @pwm_register_base : address of first PWM register >>>>> + * @pwm_registers_reversed: : true if PWM registers count down instead of up >>>>> + * @led_control_register_base : address of first LED control register >>>>> (optional) >>>>> + * @enable_bits_per_led_control_register: number of LEDs enable bits in each >>>>> + * @reset_func: : pointer to reset function >>>>> + * >>>>> + * For all optional register addresses, the sentinel value >>>>> %IS31FL32XX_REG_NONE >>>>> + * indicates that this chip has no such register. >>>>> + * >>>>> + * If non-NULL, @reset_func will be called during probing to set all >>>>> + * necessary registers to a known initialization state. This is needed >>>>> + * for chips that do not have a @reset_reg. >>>>> + * >>>>> + * @enable_bits_per_led_control_register must be >=1 if >>>>> + * @led_control_register_base != %IS31FL32XX_REG_NONE. >>>>> + */ >>>>> +struct is31fl32xx_chipdef { >>>>> + u8 channels; >>>>> + u8 shutdown_reg; >>>>> + u8 pwm_update_reg; >>>>> + u8 global_control_reg; >>>>> + u8 reset_reg; >>>>> + u8 pwm_register_base; >>>>> + bool pwm_registers_reversed; >>>>> + u8 led_control_register_base; >>>>> + u8 enable_bits_per_led_control_register; >>>>> + int (*reset_func)(struct is31fl32xx_priv *priv); >>>>> + int (*sw_shutdown_func)(struct is31fl32xx_priv *priv, bool enable); >>>>> +}; >>>>> + >>>>> +static const struct is31fl32xx_chipdef is31fl3236_cdef = { >>>>> + .channels = 36, >>>>> + .shutdown_reg = 0x00, >>>>> + .pwm_update_reg = 0x25, >>>>> + .global_control_reg = 0x4a, >>>>> + .reset_reg = 0x4f, >>>>> + .pwm_register_base = 0x01, >>>>> + .led_control_register_base = 0x26, >>>>> + .enable_bits_per_led_control_register = 1, >>>>> +}; >>>>> + >>>>> +static const struct is31fl32xx_chipdef is31fl3235_cdef = { >>>>> + .channels = 28, >>>>> + .shutdown_reg = 0x00, >>>>> + .pwm_update_reg = 0x25, >>>>> + .global_control_reg = 0x4a, >>>>> + .reset_reg = 0x4f, >>>>> + .pwm_register_base = 0x05, >>>>> + .led_control_register_base = 0x2a, >>>>> + .enable_bits_per_led_control_register = 1, >>>>> +}; >>>>> + >>>>> +static const struct is31fl32xx_chipdef is31fl3218_cdef = { >>>>> + .channels = 18, >>>>> + .shutdown_reg = 0x00, >>>>> + .pwm_update_reg = 0x16, >>>>> + .global_control_reg = IS31FL32XX_REG_NONE, >>>>> + .reset_reg = 0x17, >>>>> + .pwm_register_base = 0x01, >>>>> + .led_control_register_base = 0x13, >>>>> + .enable_bits_per_led_control_register = 6, >>>>> +}; >>>>> + >>>>> +static int is31fl3216_reset(struct is31fl32xx_priv *priv); >>>>> +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, >>>>> + bool enable); >>>>> +static const struct is31fl32xx_chipdef is31fl3216_cdef = { >>>>> + .channels = 16, >>>>> + .shutdown_reg = IS31FL32XX_REG_NONE, >>>>> + .pwm_update_reg = 0xB0, >>>>> + .global_control_reg = IS31FL32XX_REG_NONE, >>>>> + .reset_reg = IS31FL32XX_REG_NONE, >>>>> + .pwm_register_base = 0x10, >>>>> + .pwm_registers_reversed = true, >>>>> + .led_control_register_base = 0x01, >>>>> + .enable_bits_per_led_control_register = 8, >>>>> + .reset_func = is31fl3216_reset, >>>>> + .sw_shutdown_func = is31fl3216_software_shutdown, >>>>> +}; >>>>> + >>>>> +static int is31fl32xx_write(struct is31fl32xx_priv *priv, u8 reg, u8 val) >>>>> +{ >>>>> + int ret; >>>>> + >>>>> + dev_dbg(&priv->client->dev, "writing register 0x%02X=0x%02X", reg, val); >>>>> + >>>>> + ret = i2c_smbus_write_byte_data(priv->client, reg, val); >>>>> + if (ret) { >>>>> + dev_err(&priv->client->dev, >>>>> + "register write to 0x%02X failed (error %d)", >>>>> + reg, ret); >>>>> + } >>>> >>>> In case somebody use this driver as heartbeat and writing fails permanently the >>>> log will be flooded. >>> >>> Unless I'm mistaken that would require the device/bus to fail after >>> successfully probing (probe code itself bails on the first write >>> failure, so there would be no flooding as a result of that). So while >>> not impossible, I imagine it would be unlikely, and I'd hate to remove >>> an error message for such an important condition. >>> >>> I suppose I could use dev_err_ratelimited() to soften any potential >>> flooding, but I second guess that because: >>> - In led_core.c set_brightness_delayed() has a dev_err() that would come >>> out on each failed LED update anyways. >>> - There is precedent in other led drivers of a similar error message. >>> - Some userspace logging programs will compresses repeated messages anyways. >>> >>> Jacek, what is your preference on this? >> >> Let's leave it as is. Permanent I2C bus failure is a critical error and >> flooding the log would only allow to diagnose the problem quicker. >> >>>>> + return ret; >>>>> +} >>>>> + >>>>> +/* >>>>> + * Custom reset function for IS31FL3216 because it does not have a RESET >>>>> + * register the way that the other IS31FL32xx chips do. We don't bother >>>>> + * writing the GPIO and animation registers, because the registers we >>>>> + * do write ensure those will have no effect. >>>>> + */ >>>>> +static int is31fl3216_reset(struct is31fl32xx_priv *priv) >>>>> +{ >>>>> + unsigned int i; >>>>> + int ret; >>>>> + >>>>> + ret = is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, >>>>> + IS31FL3216_CONFIG_SSD_ENABLE); >>>>> + if (ret) >>>>> + return ret; >>>>> + for (i = 0; i < priv->cdef->channels; i++) { >>>>> + ret = is31fl32xx_write(priv, priv->cdef->pwm_register_base+i, >>>>> + 0x00); >>>>> + if (ret) >>>>> + return ret; >>>>> + } >>>>> + ret = is31fl32xx_write(priv, priv->cdef->pwm_update_reg, 0); >>>>> + if (ret) >>>>> + return ret; >>>>> + ret = is31fl32xx_write(priv, IS31FL3216_LIGHTING_EFFECT_REG, 0x00); >>>>> + if (ret) >>>>> + return ret; >>>>> + ret = is31fl32xx_write(priv, IS31FL3216_CHANNEL_CONFIG_REG, 0x00); >>>>> + if (ret) >>>>> + return ret; >>>>> + >>>>> + return 0; >>>>> +} >>>>> + >>>>> +/* >>>>> + * Custom Software-Shutdown function for IS31FL3216 because it does not have >>>>> + * a SHUTDOWN register the way that the other IS31FL32xx chips do. >>>>> + * We don't bother doing a read/modify/write on the CONFIG register because >>>>> + * we only ever use a value of '0' for the other fields in that register. >>>>> + */ >>>>> +static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, >>>>> + bool enable) >>>>> +{ >>>>> + u8 value = enable ? IS31FL3216_CONFIG_SSD_ENABLE : >>>>> + IS31FL3216_CONFIG_SSD_DISABLE; >>>>> + >>>>> + return is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, value); >>>>> +} >>>>> + >>>>> +/* >>>>> + * NOTE: A mutex is not needed in this function because: >>>>> + * - All referenced data is read-only after probe() >>>>> + * - The I2C core has a mutex on to protect the bus >>>>> + * - There are no read/modify/write operations >>>>> + * - Intervening operations between the write of the PWM register >>>>> + * and the Update register are harmless. >>>>> + * >>>>> + * Example: >>>>> + * PWM_REG_1 write 16 >>>>> + * UPDATE_REG write 0 >>>>> + * PWM_REG_2 write 128 >>>>> + * UPDATE_REG write 0 >>>>> + * vs: >>>>> + * PWM_REG_1 write 16 >>>>> + * PWM_REG_2 write 128 >>>>> + * UPDATE_REG write 0 >>>>> + * UPDATE_REG write 0 >>>>> + * are equivalent. Poking the Update register merely applies all PWM >>>>> + * register writes up to that point. >>>>> + */ >>>>> +static int is31fl32xx_brightness_set(struct led_classdev *led_cdev, >>>>> + enum led_brightness brightness) >>>>> +{ >>>>> + const struct is31fl32xx_led_data *led_data = >>>>> + container_of(led_cdev, struct is31fl32xx_led_data, cdev); >>>>> + const struct is31fl32xx_chipdef *cdef = led_data->priv->cdef; >>>>> + u8 pwm_register_offset; >>>>> + int ret; >>>>> + >>>>> + dev_dbg(led_cdev->dev, "%s: %d\n", __func__, brightness); >>>>> + >>>>> + /* NOTE: led_data->channel is 1-based */ >>>>> + if (cdef->pwm_registers_reversed) >>>>> + pwm_register_offset = cdef->channels - led_data->channel; >>>>> + else >>>>> + pwm_register_offset = led_data->channel - 1; >>>>> + >>>>> + ret = is31fl32xx_write(led_data->priv, >>>>> + cdef->pwm_register_base + pwm_register_offset, >>>>> + brightness); >>>>> + if (ret) >>>>> + return ret; >>>>> + >>>>> + return is31fl32xx_write(led_data->priv, cdef->pwm_update_reg, 0); >>>>> +} >>>>> + >>>>> +static int is31fl32xx_reset_regs(struct is31fl32xx_priv *priv) >>>>> +{ >>>>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; >>>>> + int ret; >>>>> + >>>>> + if (cdef->reset_reg != IS31FL32XX_REG_NONE) { >>>>> + ret = is31fl32xx_write(priv, cdef->reset_reg, 0); >>>>> + if (ret) >>>>> + return ret; >>>>> + } >>>>> + >>>>> + if (cdef->reset_func) >>>>> + return cdef->reset_func(priv); >>>>> + >>>>> + return 0; >>>>> +} >>>>> + >>>>> +static int is31fl32xx_software_shutdown(struct is31fl32xx_priv *priv, >>>>> + bool enable) >>>>> +{ >>>>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; >>>>> + int ret; >>>>> + >>>>> + if (cdef->shutdown_reg != IS31FL32XX_REG_NONE) { >>>>> + u8 value = enable ? IS31FL32XX_SHUTDOWN_SSD_ENABLE : >>>>> + IS31FL32XX_SHUTDOWN_SSD_DISABLE; >>>>> + ret = is31fl32xx_write(priv, cdef->shutdown_reg, value); >>>>> + if (ret) >>>>> + return ret; >>>>> + } >>>>> + >>>>> + if (cdef->sw_shutdown_func) >>>>> + return cdef->sw_shutdown_func(priv, enable); >>>>> + >>>>> + return 0; >>>>> +} >>>>> + >>>>> +static int is31fl32xx_init_regs(struct is31fl32xx_priv *priv) >>>>> +{ >>>>> + const struct is31fl32xx_chipdef *cdef = priv->cdef; >>>>> + int ret; >>>>> + >>>>> + ret = is31fl32xx_reset_regs(priv); >>>>> + if (ret) >>>>> + return ret; >>>>> + >>>>> + /* >>>>> + * Set enable bit for all channels. >>>>> + * We will control state with PWM registers alone. >>>>> + */ >>>>> + if (cdef->led_control_register_base != IS31FL32XX_REG_NONE) { >>>>> + u8 value = >>>>> + GENMASK(cdef->enable_bits_per_led_control_register-1, 0); >>>>> + u8 num_regs = cdef->channels / >>>>> + cdef->enable_bits_per_led_control_register; >>>>> + int i; >>>>> + >>>>> + for (i = 0; i < num_regs; i++) { >>>>> + ret = is31fl32xx_write(priv, >>>>> + cdef->led_control_register_base+i, >>>>> + value); >>>>> + if (ret) >>>>> + return ret; >>>>> + } >>>>> + } >>>>> + >>>>> + ret = is31fl32xx_software_shutdown(priv, false); >>>>> + if (ret) >>>>> + return ret; >>>>> + >>>>> + if (cdef->global_control_reg != IS31FL32XX_REG_NONE) { >>>>> + ret = is31fl32xx_write(priv, cdef->global_control_reg, 0x00); >>>>> + if (ret) >>>>> + return ret; >>>>> + } >>>>> + >>>>> + return 0; >>>>> +} >>>>> + >>>>> +static inline size_t sizeof_is31fl32xx_priv(int num_leds) >>>>> +{ >>>>> + return sizeof(struct is31fl32xx_priv) + >>>>> + (sizeof(struct is31fl32xx_led_data) * num_leds); >>>>> +} >>>>> + >>>>> +static int is31fl32xx_parse_child_dt(const struct device *dev, >>>>> + const struct device_node *child, >>>>> + struct is31fl32xx_led_data *led_data) >>>>> +{ >>>>> + struct led_classdev *cdev = &led_data->cdev; >>>>> + int ret = 0; >>>>> + u32 reg; >>>>> + >>>>> + if (of_property_read_string(child, "label", &cdev->name)) >>>>> + cdev->name = child->name; >>>>> + >>>>> + ret = of_property_read_u32(child, "reg", ®); >>>>> + if (ret || reg < 1 || reg > led_data->priv->cdef->channels) { >>>>> + dev_err(dev, >>>>> + "Child node %s does not have a valid reg property\n", >>>>> + child->full_name); >>>>> + return -EINVAL; >>>>> + } >>>>> + led_data->channel = reg; >>>>> + >>>>> + of_property_read_string(child, "linux,default-trigger", >>>>> + &cdev->default_trigger); >>>>> + >>>>> + cdev->brightness_set_blocking = is31fl32xx_brightness_set; >>>>> + >>>>> + return 0; >>>>> +} >>>>> + >>>>> +static struct is31fl32xx_led_data *is31fl32xx_find_led_data( >>>>> + struct is31fl32xx_priv *priv, >>>>> + u8 channel) >>>>> +{ >>>>> + size_t i; >>>>> + >>>>> + for (i = 0; i < priv->num_leds; i++) { >>>>> + if (priv->leds[i].channel == channel) >>>>> + return &priv->leds[i]; >>>>> + } >>>>> + >>>>> + return NULL; >>>>> +} >>>>> + >>>>> +static int is31fl32xx_parse_dt(struct device *dev, >>>>> + struct is31fl32xx_priv *priv) >>>>> +{ >>>>> + struct device_node *child; >>>>> + int ret = 0; >>>>> + >>>>> + for_each_child_of_node(dev->of_node, child) { >>>>> + struct is31fl32xx_led_data *led_data = >>>>> + &priv->leds[priv->num_leds]; >>>> >>>> Maybe i missed something, but is it really protected against out of index >>>> access? >>> >>> The array is allocated with size equal to the number of child nodes, >>> and num_leds is incremented once for each child node parsed. So in >>> order for the index to be out of bounds, the number of child nodes >>> would need to increase during the probe. I assumed that the DT is >>> static during probing, but if that's not the case then you're right >>> that this is a potential problem. Also, this equivalent logic is >>> used in leds-pwm, leds-gpio, and leds-ns2, so that gives me >>> confidence that its safe. >>> Unless DT overlays change that assumption? >> >> DT overlays would matter here if child DT nodes could be dynamically >> removed, i.e. if it was possible by design to dynamically unplug LEDs >> from the current outputs during LED controller operation, which is not >> the case for this device (and any other LED controller I am aware of). >> >>>>> + const struct is31fl32xx_led_data *other_led_data; >>>>> + >>>>> + led_data->priv = priv; >>>>> + >>>>> + ret = is31fl32xx_parse_child_dt(dev, child, led_data); >>>>> + if (ret) >>>>> + goto err; >>>>> + >>>>> + /* Detect if channel is already in use by another child */ >>>>> + other_led_data = is31fl32xx_find_led_data(priv, >>>>> + led_data->channel); >>>>> + if (other_led_data) { >>>>> + dev_err(dev, >>>>> + "%s and %s both attempting to use channel %d\n", >>>>> + led_data->cdev.name, >>>>> + other_led_data->cdev.name, >>>>> + led_data->channel); >>>>> + goto err; >>>>> + } >>>>> + >>>>> + ret = devm_led_classdev_register(dev, &led_data->cdev); >>>>> + if (ret) { >>>>> + dev_err(dev, "failed to register PWM led for %s: %d\n", >>>>> + led_data->cdev.name, ret); >>>>> + goto err; >>>>> + } >>>>> + >>>>> + priv->num_leds++; >>>>> + } >>>>> + >>>>> + return 0; >>>>> + >>>>> +err: >>>>> + of_node_put(child); >>>>> + return ret; >>>>> +} >>>>> + >>>>> +static const struct of_device_id of_is31fl31xx_match[] = { >>>>> + { .compatible = "issi,is31fl3236", .data = &is31fl3236_cdef, }, >>>>> + { .compatible = "issi,is31fl3235", .data = &is31fl3235_cdef, }, >>>>> + { .compatible = "issi,is31fl3218", .data = &is31fl3218_cdef, }, >>>>> + { .compatible = "issi,is31fl3216", .data = &is31fl3216_cdef, }, >>>>> + {}, >>>>> +}; >>>>> + >>>>> +MODULE_DEVICE_TABLE(of, of_is31fl31xx_match); >>>>> + >>>>> +static int is31fl32xx_probe(struct i2c_client *client, >>>>> + const struct i2c_device_id *id) >>>>> +{ >>>>> + const struct is31fl32xx_chipdef *cdef; >>>>> + const struct of_device_id *of_dev_id; >>>>> + struct device *dev = &client->dev; >>>>> + struct is31fl32xx_priv *priv; >>>>> + int count; >>>>> + int ret = 0; >>>>> + >>>>> + of_dev_id = of_match_device(of_is31fl31xx_match, dev); >>>>> + if (!of_dev_id) >>>>> + return -EINVAL; >>>>> + >>>>> + cdef = of_dev_id->data; >>>>> + >>>>> + count = of_get_child_count(dev->of_node); >>>>> + if (!count) >>>>> + return -EINVAL; >>>>> + >>>>> + priv = devm_kzalloc(dev, sizeof_is31fl32xx_priv(count), >>>>> + GFP_KERNEL); >>>>> + if (!priv) >>>>> + return -ENOMEM; >>>>> + >>>>> + priv->client = client; >>>>> + priv->cdef = cdef; >>>>> + i2c_set_clientdata(client, priv); >>>>> + >>>>> + ret = is31fl32xx_init_regs(priv); >>>>> + if (ret) >>>>> + return ret; >>>>> + >>>>> + ret = is31fl32xx_parse_dt(dev, priv); >>>>> + if (ret) >>>>> + return ret; >>>>> + >>>>> + return 0; >>>>> +} >>>>> + >>>>> +static int is31fl32xx_remove(struct i2c_client *client) >>>>> +{ >>>>> + struct is31fl32xx_priv *priv = i2c_get_clientdata(client); >>>>> + >>>>> + return is31fl32xx_reset_regs(priv); >>>>> +} >>>>> + >>>>> +/* >>>>> + * i2c-core requires that id_table be non-NULL, even though >>>>> + * it is not used for DeviceTree based instantiation. >>>>> + */ >>>>> +static const struct i2c_device_id is31fl31xx_id[] = { >>>>> + {}, >>>>> +}; >>>>> + >>>>> +MODULE_DEVICE_TABLE(i2c, is31fl31xx_id); >>>>> + >>>>> +static struct i2c_driver is31fl32xx_driver = { >>>>> + .driver = { >>>>> + .name = "is31fl32xx", >>>>> + .of_match_table = of_is31fl31xx_match, >>>>> + }, >>>>> + .probe = is31fl32xx_probe, >>>>> + .remove = is31fl32xx_remove, >>>> >>>> Sorry, what was the reason to skip shutdown? >>> >>> If I understood Jacek's last email on the topic [1] correctly, he's now >>> of the opinion that the decision to turn LEDs off on reboot should be >>> left to userspace, rather than done by the driver. For these devices, >>> the only thing a shutdown callback would do is turn off the LEDs (through >>> any of multiple methods). So, if we want to leave the state as-is on >>> reboot there's no need for a shutdown callback. >>> >>> [1] http://www.spinics.net/lists/linux-leds/msg05644.html >>> >>>>> + .id_table = is31fl31xx_id, >>>>> +}; >>>>> + >>>>> +module_i2c_driver(is31fl32xx_driver); >>>>> + >>>>> +MODULE_AUTHOR("David Rivshin <drivshin@allworx.com>"); >>>>> +MODULE_DESCRIPTION("ISSI IS31FL32xx LED driver"); >>>>> +MODULE_LICENSE("GPL v2"); >>>>> -- >>>>> 2.5.0 >>>>> > -- > To unsubscribe from this list: send the line "unsubscribe linux-leds" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > -- Best Regards, Jacek Anaszewski ^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 4/4] leds: Replace dedicated SN3218 driver with IS31FL32XX driver 2016-03-03 3:01 [PATCH 0/4] leds: Add driver for the ISSI IS31FL32xx family of LED controllers David Rivshin (Allworx) ` (2 preceding siblings ...) 2016-03-03 3:01 ` [PATCH 3/4] leds: Add driver " David Rivshin (Allworx) @ 2016-03-03 3:01 ` David Rivshin (Allworx) 2016-03-03 14:51 ` Jacek Anaszewski ` (2 more replies) 3 siblings, 3 replies; 28+ messages in thread From: David Rivshin (Allworx) @ 2016-03-03 3:01 UTC (permalink / raw) To: linux-leds, devicetree Cc: Richard Purdie, Jacek Anaszewski, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Stefan Wahren, linux-kernel From: David Rivshin <drivshin@allworx.com> Si-En Technology was acquired by ISSI in 2011, and it appears that the IS31FL3218/IS31FL3216 are just rebranded SN3218/SN3216 devices. As the IS31FL32XX driver already handles the *3218 devices, there is no longer a need for the dedicated SN3218 driver. Add the "sn,sn3218" and "sn,sn3216" compatible strings into the IS31FL32XX driver and binding documentation, and remove the leds-sn3218 driver. Datasheets: IS31FL3218: http://www.issi.com/WW/pdf/31FL3218.pdf SN3218: http://www.si-en.com/uploadpdf/s2011517171720.pdf IS31FL3216: http://www.issi.com/WW/pdf/31FL3216.pdf SN3216; http://www.si-en.com/uploadpdf/SN3216201152410148.pdf Signed-off-by: David Rivshin <drivshin@allworx.com> --- Note that the leds-sn3218 binding use a 0-based 'reg' property, while the leds-is31fl32xx binding uses a 1-based 'reg' property. This seemed to be the preferred binding based on [1]. Since leds-sn3216 has not been in a released kernel, there is are no backwards-compatibility concerns. Changes from RFC: new [1] http://www.spinics.net/lists/linux-leds/msg05589.html .../devicetree/bindings/leds/leds-is31fl32xx.txt | 9 +- .../devicetree/bindings/leds/leds-sn3218.txt | 41 --- drivers/leds/Kconfig | 18 +- drivers/leds/Makefile | 1 - drivers/leds/leds-is31fl32xx.c | 6 +- drivers/leds/leds-sn3218.c | 306 --------------------- 6 files changed, 14 insertions(+), 367 deletions(-) delete mode 100644 Documentation/devicetree/bindings/leds/leds-sn3218.txt delete mode 100644 drivers/leds/leds-sn3218.c diff --git a/Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt b/Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt index 539df2e..c59eb1a 100644 --- a/Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt +++ b/Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt @@ -1,6 +1,6 @@ -Binding for ISSI IS31FL32xx LED Drivers +Binding for ISSI IS31FL32xx and Si-En SN32xx LED Drivers -The IS31FL32xx family of LED drivers are I2C devices with multiple +The IS31FL32xx/SN32xx family of LED drivers are I2C devices with multiple constant-current channels, each with independent 256-level PWM control. Each LED is represented as a sub-node of the device. @@ -10,6 +10,8 @@ Required properties: issi,is31fl3235 issi,is31fl3218 issi,is31fl3216 + si-en,sn3218 + si-en,sn3216 - reg: I2C slave address - address-cells : must be 1 - size-cells : must be 0 @@ -45,5 +47,6 @@ leds: is31fl3236@3c { }; }; -For more product information please see the link below: +For more product information please see the links below: http://www.issi.com/US/product-analog-fxled-driver.shtml +http://www.si-en.com/product.asp?parentid=890 diff --git a/Documentation/devicetree/bindings/leds/leds-sn3218.txt b/Documentation/devicetree/bindings/leds/leds-sn3218.txt deleted file mode 100644 index 19cbf57..0000000 --- a/Documentation/devicetree/bindings/leds/leds-sn3218.txt +++ /dev/null @@ -1,41 +0,0 @@ -* Si-En Technology - SN3218 18-Channel LED Driver - -Required properties: -- compatible : - "si-en,sn3218" -- address-cells : must be 1 -- size-cells : must be 0 -- reg : I2C slave address, typically 0x54 - -There must be at least 1 LED which is represented as a sub-node -of the sn3218 device. - -LED sub-node properties: -- label : (optional) see Documentation/devicetree/bindings/leds/common.txt -- reg : number of LED line (could be from 0 to 17) -- linux,default-trigger : (optional) - see Documentation/devicetree/bindings/leds/common.txt - -Example: - -sn3218: led-controller@54 { - compatible = "si-en,sn3218"; - #address-cells = <1>; - #size-cells = <0>; - reg = <0x54>; - - led@0 { - label = "led1"; - reg = <0x0>; - }; - - led@1 { - label = "led2"; - reg = <0x1>; - }; - - led@2 { - label = "led3"; - reg = <0x2>; - }; -}; diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 9c63ba4..1f64151 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -568,25 +568,13 @@ config LEDS_SEAD3 This driver can also be built as a module. If so the module will be called leds-sead3. -config LEDS_SN3218 - tristate "LED support for Si-En SN3218 I2C chip" - depends on LEDS_CLASS && I2C - depends on OF - select REGMAP_I2C - help - This option enables support for the Si-EN SN3218 LED driver - connected through I2C. Say Y to enable support for the SN3218 LED. - - This driver can also be built as a module. If so the module - will be called leds-sn3218. - config LEDS_IS31FL32XX tristate "LED support for ISSI IS31FL32XX I2C LED controller family" depends on LEDS_CLASS && I2C && OF help - Say Y here to include support for ISSI IS31FL32XX LED controllers. - They are I2C devices with multiple constant-current channels, each - with independent 256-level PWM control. + Say Y here to include support for ISSI IS31FL32XX and Si-En SN32xx + LED controllers. They are I2C devices with multiple constant-current + channels, each with independent 256-level PWM control. comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)" diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index 3fdf313..cb2013d 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -66,7 +66,6 @@ obj-$(CONFIG_LEDS_MENF21BMC) += leds-menf21bmc.o obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o -obj-$(CONFIG_LEDS_SN3218) += leds-sn3218.o obj-$(CONFIG_LEDS_IS31FL32XX) += leds-is31fl32xx.o # LED SPI Drivers diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c index 49818f0..ec3f541 100644 --- a/drivers/leds/leds-is31fl32xx.c +++ b/drivers/leds/leds-is31fl32xx.c @@ -10,7 +10,9 @@ * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * - * Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml + * Datasheets: + * http://www.issi.com/US/product-analog-fxled-driver.shtml + * http://www.si-en.com/product.asp?parentid=890 */ #include <linux/err.h> @@ -425,7 +427,9 @@ static const struct of_device_id of_is31fl31xx_match[] = { { .compatible = "issi,is31fl3236", .data = &is31fl3236_cdef, }, { .compatible = "issi,is31fl3235", .data = &is31fl3235_cdef, }, { .compatible = "issi,is31fl3218", .data = &is31fl3218_cdef, }, + { .compatible = "si-en,sn3218", .data = &is31fl3218_cdef, }, { .compatible = "issi,is31fl3216", .data = &is31fl3216_cdef, }, + { .compatible = "si-en,sn3216", .data = &is31fl3216_cdef, }, {}, }; diff --git a/drivers/leds/leds-sn3218.c b/drivers/leds/leds-sn3218.c deleted file mode 100644 index dcc2581..0000000 --- a/drivers/leds/leds-sn3218.c +++ /dev/null @@ -1,306 +0,0 @@ -/* - * Si-En SN3218 18 Channel LED Driver - * - * Copyright (C) 2016 Stefan Wahren <stefan.wahren@i2se.com> - * - * Based on leds-pca963x.c - * - * 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. - * - * Datasheet: http://www.si-en.com/uploadpdf/s2011517171720.pdf - * - */ - -#include <linux/err.h> -#include <linux/i2c.h> -#include <linux/leds.h> -#include <linux/module.h> -#include <linux/of.h> -#include <linux/regmap.h> -#include <linux/slab.h> - -#define SN3218_MODE 0x00 -#define SN3218_PWM_1 0x01 -#define SN3218_PWM_2 0x02 -#define SN3218_PWM_3 0x03 -#define SN3218_PWM_4 0x04 -#define SN3218_PWM_5 0x05 -#define SN3218_PWM_6 0x06 -#define SN3218_PWM_7 0x07 -#define SN3218_PWM_8 0x08 -#define SN3218_PWM_9 0x09 -#define SN3218_PWM_10 0x0a -#define SN3218_PWM_11 0x0b -#define SN3218_PWM_12 0x0c -#define SN3218_PWM_13 0x0d -#define SN3218_PWM_14 0x0e -#define SN3218_PWM_15 0x0f -#define SN3218_PWM_16 0x10 -#define SN3218_PWM_17 0x11 -#define SN3218_PWM_18 0x12 -#define SN3218_LED_1_6 0x13 -#define SN3218_LED_7_12 0x14 -#define SN3218_LED_13_18 0x15 -#define SN3218_UPDATE 0x16 /* applies to reg 0x01 .. 0x15 */ -#define SN3218_RESET 0x17 - -#define SN3218_LED_MASK 0x3f -#define SN3218_LED_ON 0x01 -#define SN3218_LED_OFF 0x00 - -#define SN3218_MODE_SHUTDOWN 0x00 -#define SN3218_MODE_NORMAL 0x01 - -#define NUM_LEDS 18 - -struct sn3218_led; - -/** - * struct sn3218 - - * @client - Pointer to the I2C client - * @leds - Pointer to the individual LEDs - * @num_leds - Actual number of LEDs -**/ -struct sn3218 { - struct i2c_client *client; - struct regmap *regmap; - struct sn3218_led *leds; - int num_leds; -}; - -/** - * struct sn3218_led - - * @chip - Pointer to the container - * @led_cdev - led class device pointer - * @led_num - LED index ( 0 .. 17 ) -**/ -struct sn3218_led { - struct sn3218 *chip; - struct led_classdev led_cdev; - int led_num; -}; - -static int sn3218_led_set(struct led_classdev *led_cdev, - enum led_brightness brightness) -{ - struct sn3218_led *led = - container_of(led_cdev, struct sn3218_led, led_cdev); - struct regmap *regmap = led->chip->regmap; - u8 bank = led->led_num / 6; - u8 mask = 0x1 << (led->led_num % 6); - u8 val; - int ret; - - if (brightness == LED_OFF) - val = 0; - else - val = mask; - - ret = regmap_update_bits(regmap, SN3218_LED_1_6 + bank, mask, val); - if (ret < 0) - return ret; - - if (brightness > LED_OFF) { - ret = regmap_write(regmap, SN3218_PWM_1 + led->led_num, - brightness); - if (ret < 0) - return ret; - } - - ret = regmap_write(regmap, SN3218_UPDATE, 0xff); - - return ret; -} - -static void sn3218_led_init(struct sn3218 *sn3218, struct device_node *node, - u32 reg) -{ - struct sn3218_led *leds = sn3218->leds; - struct led_classdev *cdev = &leds[reg].led_cdev; - - leds[reg].led_num = reg; - leds[reg].chip = sn3218; - - if (of_property_read_string(node, "label", &cdev->name)) - cdev->name = node->name; - - of_property_read_string(node, "linux,default-trigger", - &cdev->default_trigger); - - cdev->brightness_set_blocking = sn3218_led_set; -} - -static const struct reg_default sn3218_reg_defs[] = { - { SN3218_MODE, 0x00}, - { SN3218_PWM_1, 0x00}, - { SN3218_PWM_2, 0x00}, - { SN3218_PWM_3, 0x00}, - { SN3218_PWM_4, 0x00}, - { SN3218_PWM_5, 0x00}, - { SN3218_PWM_6, 0x00}, - { SN3218_PWM_7, 0x00}, - { SN3218_PWM_8, 0x00}, - { SN3218_PWM_9, 0x00}, - { SN3218_PWM_10, 0x00}, - { SN3218_PWM_11, 0x00}, - { SN3218_PWM_12, 0x00}, - { SN3218_PWM_13, 0x00}, - { SN3218_PWM_14, 0x00}, - { SN3218_PWM_15, 0x00}, - { SN3218_PWM_16, 0x00}, - { SN3218_PWM_17, 0x00}, - { SN3218_PWM_18, 0x00}, - { SN3218_LED_1_6, 0x00}, - { SN3218_LED_7_12, 0x00}, - { SN3218_LED_13_18, 0x00}, - { SN3218_UPDATE, 0x00}, - { SN3218_RESET, 0x00}, -}; - -static const struct regmap_config sn3218_regmap_config = { - .reg_bits = 8, - .val_bits = 8, - - .max_register = SN3218_RESET, - .reg_defaults = sn3218_reg_defs, - .num_reg_defaults = ARRAY_SIZE(sn3218_reg_defs), - .cache_type = REGCACHE_RBTREE, -}; - -static int sn3218_init(struct i2c_client *client, struct sn3218 *sn3218) -{ - struct device_node *np = client->dev.of_node, *child; - struct sn3218_led *leds; - int ret, count; - - count = of_get_child_count(np); - if (!count) - return -ENODEV; - - if (count > NUM_LEDS) { - dev_err(&client->dev, "Invalid LED count %d\n", count); - return -EINVAL; - } - - leds = devm_kzalloc(&client->dev, count * sizeof(*leds), GFP_KERNEL); - if (!leds) - return -ENOMEM; - - sn3218->leds = leds; - sn3218->num_leds = count; - sn3218->client = client; - - sn3218->regmap = devm_regmap_init_i2c(client, &sn3218_regmap_config); - if (IS_ERR(sn3218->regmap)) { - ret = PTR_ERR(sn3218->regmap); - dev_err(&client->dev, "Failed to allocate register map: %d\n", - ret); - return ret; - } - - for_each_child_of_node(np, child) { - u32 reg; - - ret = of_property_read_u32(child, "reg", ®); - if (ret) - goto fail; - - if (reg >= count) { - dev_err(&client->dev, "Invalid LED (%u >= %d)\n", reg, - count); - ret = -EINVAL; - goto fail; - } - - sn3218_led_init(sn3218, child, reg); - } - - return 0; - -fail: - of_node_put(child); - return ret; -} - -static int sn3218_probe(struct i2c_client *client, - const struct i2c_device_id *id) -{ - struct sn3218 *sn3218; - struct sn3218_led *leds; - struct device *dev = &client->dev; - int i, ret; - - sn3218 = devm_kzalloc(dev, sizeof(*sn3218), GFP_KERNEL); - if (!sn3218) - return -ENOMEM; - - ret = sn3218_init(client, sn3218); - if (ret) - return ret; - - i2c_set_clientdata(client, sn3218); - leds = sn3218->leds; - - /* - * Since the chip is write-only we need to reset him into - * a defined state (all LEDs off). - */ - ret = regmap_write(sn3218->regmap, SN3218_RESET, 0xff); - if (ret) - return ret; - - for (i = 0; i < sn3218->num_leds; i++) { - ret = devm_led_classdev_register(dev, &leds[i].led_cdev); - if (ret < 0) - return ret; - } - - return regmap_write(sn3218->regmap, SN3218_MODE, SN3218_MODE_NORMAL); -} - -static int sn3218_remove(struct i2c_client *client) -{ - struct sn3218 *sn3218 = i2c_get_clientdata(client); - - regmap_write(sn3218->regmap, SN3218_MODE, SN3218_MODE_SHUTDOWN); - - return 0; -} - -static void sn3218_shutdown(struct i2c_client *client) -{ - struct sn3218 *sn3218 = i2c_get_clientdata(client); - - regmap_write(sn3218->regmap, SN3218_MODE, SN3218_MODE_SHUTDOWN); -} - -static const struct i2c_device_id sn3218_id[] = { - { "sn3218", 0 }, - { } -}; -MODULE_DEVICE_TABLE(i2c, sn3218_id); - -static const struct of_device_id of_sn3218_match[] = { - { .compatible = "si-en,sn3218", }, - {}, -}; -MODULE_DEVICE_TABLE(of, of_sn3218_match); - -static struct i2c_driver sn3218_driver = { - .driver = { - .name = "leds-sn3218", - .of_match_table = of_match_ptr(of_sn3218_match), - }, - .probe = sn3218_probe, - .remove = sn3218_remove, - .shutdown = sn3218_shutdown, - .id_table = sn3218_id, -}; - -module_i2c_driver(sn3218_driver); - -MODULE_DESCRIPTION("Si-En SN3218 LED Driver"); -MODULE_AUTHOR("Stefan Wahren <stefan.wahren@i2se.com>"); -MODULE_LICENSE("GPL v2"); -- 2.5.0 ^ permalink raw reply related [flat|nested] 28+ messages in thread
* Re: [PATCH 4/4] leds: Replace dedicated SN3218 driver with IS31FL32XX driver 2016-03-03 3:01 ` [PATCH 4/4] leds: Replace dedicated SN3218 driver with IS31FL32XX driver David Rivshin (Allworx) @ 2016-03-03 14:51 ` Jacek Anaszewski 2016-03-05 5:34 ` David Rivshin (Allworx) 2016-03-04 21:14 ` Stefan Wahren 2016-03-05 4:28 ` Rob Herring 2 siblings, 1 reply; 28+ messages in thread From: Jacek Anaszewski @ 2016-03-03 14:51 UTC (permalink / raw) To: David Rivshin (Allworx) Cc: linux-leds, devicetree, Richard Purdie, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Stefan Wahren, linux-kernel Hi David, I'll wait for Tested-by from Stefan before applying this patch. If Stefan will have managed to test your driver with his hardware by the end of this cycle, it will suffice for this patch to contain only leds-is31fl32xx extension part. leds-sn3218 hasn't been merged to mainline yet, so I'd rather remove it when I get Tested-by from Stefan. Otherwise, I will send leds-sn3218 to Linus, and this patch will be applied after being tested, during 4.7 cycle. Thanks, Jacek Anaszewski On 03/03/2016 04:01 AM, David Rivshin (Allworx) wrote: > From: David Rivshin <drivshin@allworx.com> > > Si-En Technology was acquired by ISSI in 2011, and it appears that > the IS31FL3218/IS31FL3216 are just rebranded SN3218/SN3216 devices. > As the IS31FL32XX driver already handles the *3218 devices, there > is no longer a need for the dedicated SN3218 driver. > > Add the "sn,sn3218" and "sn,sn3216" compatible strings into the > IS31FL32XX driver and binding documentation, and remove the > leds-sn3218 driver. > > Datasheets: > IS31FL3218: http://www.issi.com/WW/pdf/31FL3218.pdf > SN3218: http://www.si-en.com/uploadpdf/s2011517171720.pdf > > IS31FL3216: http://www.issi.com/WW/pdf/31FL3216.pdf > SN3216; http://www.si-en.com/uploadpdf/SN3216201152410148.pdf > > Signed-off-by: David Rivshin <drivshin@allworx.com> > --- > > Note that the leds-sn3218 binding use a 0-based 'reg' property, while > the leds-is31fl32xx binding uses a 1-based 'reg' property. This seemed > to be the preferred binding based on [1]. Since leds-sn3216 has not been > in a released kernel, there is are no backwards-compatibility concerns. > > Changes from RFC: > new > > [1] http://www.spinics.net/lists/linux-leds/msg05589.html > > .../devicetree/bindings/leds/leds-is31fl32xx.txt | 9 +- > .../devicetree/bindings/leds/leds-sn3218.txt | 41 --- > drivers/leds/Kconfig | 18 +- > drivers/leds/Makefile | 1 - > drivers/leds/leds-is31fl32xx.c | 6 +- > drivers/leds/leds-sn3218.c | 306 --------------------- > 6 files changed, 14 insertions(+), 367 deletions(-) > delete mode 100644 Documentation/devicetree/bindings/leds/leds-sn3218.txt > delete mode 100644 drivers/leds/leds-sn3218.c > > diff --git a/Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt b/Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt > index 539df2e..c59eb1a 100644 > --- a/Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt > +++ b/Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt > @@ -1,6 +1,6 @@ > -Binding for ISSI IS31FL32xx LED Drivers > +Binding for ISSI IS31FL32xx and Si-En SN32xx LED Drivers > > -The IS31FL32xx family of LED drivers are I2C devices with multiple > +The IS31FL32xx/SN32xx family of LED drivers are I2C devices with multiple > constant-current channels, each with independent 256-level PWM control. > Each LED is represented as a sub-node of the device. > > @@ -10,6 +10,8 @@ Required properties: > issi,is31fl3235 > issi,is31fl3218 > issi,is31fl3216 > + si-en,sn3218 > + si-en,sn3216 > - reg: I2C slave address > - address-cells : must be 1 > - size-cells : must be 0 > @@ -45,5 +47,6 @@ leds: is31fl3236@3c { > }; > }; > > -For more product information please see the link below: > +For more product information please see the links below: > http://www.issi.com/US/product-analog-fxled-driver.shtml > +http://www.si-en.com/product.asp?parentid=890 > diff --git a/Documentation/devicetree/bindings/leds/leds-sn3218.txt b/Documentation/devicetree/bindings/leds/leds-sn3218.txt > deleted file mode 100644 > index 19cbf57..0000000 > --- a/Documentation/devicetree/bindings/leds/leds-sn3218.txt > +++ /dev/null > @@ -1,41 +0,0 @@ > -* Si-En Technology - SN3218 18-Channel LED Driver > - > -Required properties: > -- compatible : > - "si-en,sn3218" > -- address-cells : must be 1 > -- size-cells : must be 0 > -- reg : I2C slave address, typically 0x54 > - > -There must be at least 1 LED which is represented as a sub-node > -of the sn3218 device. > - > -LED sub-node properties: > -- label : (optional) see Documentation/devicetree/bindings/leds/common.txt > -- reg : number of LED line (could be from 0 to 17) > -- linux,default-trigger : (optional) > - see Documentation/devicetree/bindings/leds/common.txt > - > -Example: > - > -sn3218: led-controller@54 { > - compatible = "si-en,sn3218"; > - #address-cells = <1>; > - #size-cells = <0>; > - reg = <0x54>; > - > - led@0 { > - label = "led1"; > - reg = <0x0>; > - }; > - > - led@1 { > - label = "led2"; > - reg = <0x1>; > - }; > - > - led@2 { > - label = "led3"; > - reg = <0x2>; > - }; > -}; > diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig > index 9c63ba4..1f64151 100644 > --- a/drivers/leds/Kconfig > +++ b/drivers/leds/Kconfig > @@ -568,25 +568,13 @@ config LEDS_SEAD3 > This driver can also be built as a module. If so the module > will be called leds-sead3. > > -config LEDS_SN3218 > - tristate "LED support for Si-En SN3218 I2C chip" > - depends on LEDS_CLASS && I2C > - depends on OF > - select REGMAP_I2C > - help > - This option enables support for the Si-EN SN3218 LED driver > - connected through I2C. Say Y to enable support for the SN3218 LED. > - > - This driver can also be built as a module. If so the module > - will be called leds-sn3218. > - > config LEDS_IS31FL32XX > tristate "LED support for ISSI IS31FL32XX I2C LED controller family" > depends on LEDS_CLASS && I2C && OF > help > - Say Y here to include support for ISSI IS31FL32XX LED controllers. > - They are I2C devices with multiple constant-current channels, each > - with independent 256-level PWM control. > + Say Y here to include support for ISSI IS31FL32XX and Si-En SN32xx > + LED controllers. They are I2C devices with multiple constant-current > + channels, each with independent 256-level PWM control. > > comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)" > > diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile > index 3fdf313..cb2013d 100644 > --- a/drivers/leds/Makefile > +++ b/drivers/leds/Makefile > @@ -66,7 +66,6 @@ obj-$(CONFIG_LEDS_MENF21BMC) += leds-menf21bmc.o > obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o > obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o > obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o > -obj-$(CONFIG_LEDS_SN3218) += leds-sn3218.o > obj-$(CONFIG_LEDS_IS31FL32XX) += leds-is31fl32xx.o > > # LED SPI Drivers > diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c > index 49818f0..ec3f541 100644 > --- a/drivers/leds/leds-is31fl32xx.c > +++ b/drivers/leds/leds-is31fl32xx.c > @@ -10,7 +10,9 @@ > * it under the terms of the GNU General Public License version 2 as > * published by the Free Software Foundation. > * > - * Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml > + * Datasheets: > + * http://www.issi.com/US/product-analog-fxled-driver.shtml > + * http://www.si-en.com/product.asp?parentid=890 > */ > > #include <linux/err.h> > @@ -425,7 +427,9 @@ static const struct of_device_id of_is31fl31xx_match[] = { > { .compatible = "issi,is31fl3236", .data = &is31fl3236_cdef, }, > { .compatible = "issi,is31fl3235", .data = &is31fl3235_cdef, }, > { .compatible = "issi,is31fl3218", .data = &is31fl3218_cdef, }, > + { .compatible = "si-en,sn3218", .data = &is31fl3218_cdef, }, > { .compatible = "issi,is31fl3216", .data = &is31fl3216_cdef, }, > + { .compatible = "si-en,sn3216", .data = &is31fl3216_cdef, }, > {}, > }; > > diff --git a/drivers/leds/leds-sn3218.c b/drivers/leds/leds-sn3218.c > deleted file mode 100644 > index dcc2581..0000000 > --- a/drivers/leds/leds-sn3218.c > +++ /dev/null > @@ -1,306 +0,0 @@ > -/* > - * Si-En SN3218 18 Channel LED Driver > - * > - * Copyright (C) 2016 Stefan Wahren <stefan.wahren@i2se.com> > - * > - * Based on leds-pca963x.c > - * > - * 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. > - * > - * Datasheet: http://www.si-en.com/uploadpdf/s2011517171720.pdf > - * > - */ > - > -#include <linux/err.h> > -#include <linux/i2c.h> > -#include <linux/leds.h> > -#include <linux/module.h> > -#include <linux/of.h> > -#include <linux/regmap.h> > -#include <linux/slab.h> > - > -#define SN3218_MODE 0x00 > -#define SN3218_PWM_1 0x01 > -#define SN3218_PWM_2 0x02 > -#define SN3218_PWM_3 0x03 > -#define SN3218_PWM_4 0x04 > -#define SN3218_PWM_5 0x05 > -#define SN3218_PWM_6 0x06 > -#define SN3218_PWM_7 0x07 > -#define SN3218_PWM_8 0x08 > -#define SN3218_PWM_9 0x09 > -#define SN3218_PWM_10 0x0a > -#define SN3218_PWM_11 0x0b > -#define SN3218_PWM_12 0x0c > -#define SN3218_PWM_13 0x0d > -#define SN3218_PWM_14 0x0e > -#define SN3218_PWM_15 0x0f > -#define SN3218_PWM_16 0x10 > -#define SN3218_PWM_17 0x11 > -#define SN3218_PWM_18 0x12 > -#define SN3218_LED_1_6 0x13 > -#define SN3218_LED_7_12 0x14 > -#define SN3218_LED_13_18 0x15 > -#define SN3218_UPDATE 0x16 /* applies to reg 0x01 .. 0x15 */ > -#define SN3218_RESET 0x17 > - > -#define SN3218_LED_MASK 0x3f > -#define SN3218_LED_ON 0x01 > -#define SN3218_LED_OFF 0x00 > - > -#define SN3218_MODE_SHUTDOWN 0x00 > -#define SN3218_MODE_NORMAL 0x01 > - > -#define NUM_LEDS 18 > - > -struct sn3218_led; > - > -/** > - * struct sn3218 - > - * @client - Pointer to the I2C client > - * @leds - Pointer to the individual LEDs > - * @num_leds - Actual number of LEDs > -**/ > -struct sn3218 { > - struct i2c_client *client; > - struct regmap *regmap; > - struct sn3218_led *leds; > - int num_leds; > -}; > - > -/** > - * struct sn3218_led - > - * @chip - Pointer to the container > - * @led_cdev - led class device pointer > - * @led_num - LED index ( 0 .. 17 ) > -**/ > -struct sn3218_led { > - struct sn3218 *chip; > - struct led_classdev led_cdev; > - int led_num; > -}; > - > -static int sn3218_led_set(struct led_classdev *led_cdev, > - enum led_brightness brightness) > -{ > - struct sn3218_led *led = > - container_of(led_cdev, struct sn3218_led, led_cdev); > - struct regmap *regmap = led->chip->regmap; > - u8 bank = led->led_num / 6; > - u8 mask = 0x1 << (led->led_num % 6); > - u8 val; > - int ret; > - > - if (brightness == LED_OFF) > - val = 0; > - else > - val = mask; > - > - ret = regmap_update_bits(regmap, SN3218_LED_1_6 + bank, mask, val); > - if (ret < 0) > - return ret; > - > - if (brightness > LED_OFF) { > - ret = regmap_write(regmap, SN3218_PWM_1 + led->led_num, > - brightness); > - if (ret < 0) > - return ret; > - } > - > - ret = regmap_write(regmap, SN3218_UPDATE, 0xff); > - > - return ret; > -} > - > -static void sn3218_led_init(struct sn3218 *sn3218, struct device_node *node, > - u32 reg) > -{ > - struct sn3218_led *leds = sn3218->leds; > - struct led_classdev *cdev = &leds[reg].led_cdev; > - > - leds[reg].led_num = reg; > - leds[reg].chip = sn3218; > - > - if (of_property_read_string(node, "label", &cdev->name)) > - cdev->name = node->name; > - > - of_property_read_string(node, "linux,default-trigger", > - &cdev->default_trigger); > - > - cdev->brightness_set_blocking = sn3218_led_set; > -} > - > -static const struct reg_default sn3218_reg_defs[] = { > - { SN3218_MODE, 0x00}, > - { SN3218_PWM_1, 0x00}, > - { SN3218_PWM_2, 0x00}, > - { SN3218_PWM_3, 0x00}, > - { SN3218_PWM_4, 0x00}, > - { SN3218_PWM_5, 0x00}, > - { SN3218_PWM_6, 0x00}, > - { SN3218_PWM_7, 0x00}, > - { SN3218_PWM_8, 0x00}, > - { SN3218_PWM_9, 0x00}, > - { SN3218_PWM_10, 0x00}, > - { SN3218_PWM_11, 0x00}, > - { SN3218_PWM_12, 0x00}, > - { SN3218_PWM_13, 0x00}, > - { SN3218_PWM_14, 0x00}, > - { SN3218_PWM_15, 0x00}, > - { SN3218_PWM_16, 0x00}, > - { SN3218_PWM_17, 0x00}, > - { SN3218_PWM_18, 0x00}, > - { SN3218_LED_1_6, 0x00}, > - { SN3218_LED_7_12, 0x00}, > - { SN3218_LED_13_18, 0x00}, > - { SN3218_UPDATE, 0x00}, > - { SN3218_RESET, 0x00}, > -}; > - > -static const struct regmap_config sn3218_regmap_config = { > - .reg_bits = 8, > - .val_bits = 8, > - > - .max_register = SN3218_RESET, > - .reg_defaults = sn3218_reg_defs, > - .num_reg_defaults = ARRAY_SIZE(sn3218_reg_defs), > - .cache_type = REGCACHE_RBTREE, > -}; > - > -static int sn3218_init(struct i2c_client *client, struct sn3218 *sn3218) > -{ > - struct device_node *np = client->dev.of_node, *child; > - struct sn3218_led *leds; > - int ret, count; > - > - count = of_get_child_count(np); > - if (!count) > - return -ENODEV; > - > - if (count > NUM_LEDS) { > - dev_err(&client->dev, "Invalid LED count %d\n", count); > - return -EINVAL; > - } > - > - leds = devm_kzalloc(&client->dev, count * sizeof(*leds), GFP_KERNEL); > - if (!leds) > - return -ENOMEM; > - > - sn3218->leds = leds; > - sn3218->num_leds = count; > - sn3218->client = client; > - > - sn3218->regmap = devm_regmap_init_i2c(client, &sn3218_regmap_config); > - if (IS_ERR(sn3218->regmap)) { > - ret = PTR_ERR(sn3218->regmap); > - dev_err(&client->dev, "Failed to allocate register map: %d\n", > - ret); > - return ret; > - } > - > - for_each_child_of_node(np, child) { > - u32 reg; > - > - ret = of_property_read_u32(child, "reg", ®); > - if (ret) > - goto fail; > - > - if (reg >= count) { > - dev_err(&client->dev, "Invalid LED (%u >= %d)\n", reg, > - count); > - ret = -EINVAL; > - goto fail; > - } > - > - sn3218_led_init(sn3218, child, reg); > - } > - > - return 0; > - > -fail: > - of_node_put(child); > - return ret; > -} > - > -static int sn3218_probe(struct i2c_client *client, > - const struct i2c_device_id *id) > -{ > - struct sn3218 *sn3218; > - struct sn3218_led *leds; > - struct device *dev = &client->dev; > - int i, ret; > - > - sn3218 = devm_kzalloc(dev, sizeof(*sn3218), GFP_KERNEL); > - if (!sn3218) > - return -ENOMEM; > - > - ret = sn3218_init(client, sn3218); > - if (ret) > - return ret; > - > - i2c_set_clientdata(client, sn3218); > - leds = sn3218->leds; > - > - /* > - * Since the chip is write-only we need to reset him into > - * a defined state (all LEDs off). > - */ > - ret = regmap_write(sn3218->regmap, SN3218_RESET, 0xff); > - if (ret) > - return ret; > - > - for (i = 0; i < sn3218->num_leds; i++) { > - ret = devm_led_classdev_register(dev, &leds[i].led_cdev); > - if (ret < 0) > - return ret; > - } > - > - return regmap_write(sn3218->regmap, SN3218_MODE, SN3218_MODE_NORMAL); > -} > - > -static int sn3218_remove(struct i2c_client *client) > -{ > - struct sn3218 *sn3218 = i2c_get_clientdata(client); > - > - regmap_write(sn3218->regmap, SN3218_MODE, SN3218_MODE_SHUTDOWN); > - > - return 0; > -} > - > -static void sn3218_shutdown(struct i2c_client *client) > -{ > - struct sn3218 *sn3218 = i2c_get_clientdata(client); > - > - regmap_write(sn3218->regmap, SN3218_MODE, SN3218_MODE_SHUTDOWN); > -} > - > -static const struct i2c_device_id sn3218_id[] = { > - { "sn3218", 0 }, > - { } > -}; > -MODULE_DEVICE_TABLE(i2c, sn3218_id); > - > -static const struct of_device_id of_sn3218_match[] = { > - { .compatible = "si-en,sn3218", }, > - {}, > -}; > -MODULE_DEVICE_TABLE(of, of_sn3218_match); > - > -static struct i2c_driver sn3218_driver = { > - .driver = { > - .name = "leds-sn3218", > - .of_match_table = of_match_ptr(of_sn3218_match), > - }, > - .probe = sn3218_probe, > - .remove = sn3218_remove, > - .shutdown = sn3218_shutdown, > - .id_table = sn3218_id, > -}; > - > -module_i2c_driver(sn3218_driver); > - > -MODULE_DESCRIPTION("Si-En SN3218 LED Driver"); > -MODULE_AUTHOR("Stefan Wahren <stefan.wahren@i2se.com>"); > -MODULE_LICENSE("GPL v2"); > ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 4/4] leds: Replace dedicated SN3218 driver with IS31FL32XX driver 2016-03-03 14:51 ` Jacek Anaszewski @ 2016-03-05 5:34 ` David Rivshin (Allworx) 2016-03-05 11:37 ` Jacek Anaszewski 0 siblings, 1 reply; 28+ messages in thread From: David Rivshin (Allworx) @ 2016-03-05 5:34 UTC (permalink / raw) To: Jacek Anaszewski Cc: linux-leds, devicetree, Richard Purdie, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Stefan Wahren, linux-kernel On Thu, 03 Mar 2016 15:51:36 +0100 Jacek Anaszewski <j.anaszewski@samsung.com> wrote: > Hi David, > > I'll wait for Tested-by from Stefan before applying this patch. > If Stefan will have managed to test your driver with his hardware > by the end of this cycle, it will suffice for this patch to contain > only leds-is31fl32xx extension part. > > leds-sn3218 hasn't been merged to mainline yet, so I'd rather > remove it when I get Tested-by from Stefan. > > Otherwise, I will send leds-sn3218 to Linus, and this patch > will be applied after being tested, during 4.7 cycle. Since Stefan has given his Tested-by, do I understand correctly that you would prefer to: - revert sn3218 patches 2 and 3 yourself - have me provide v2 patches that would apply ontop of that If so, should I do as Rob suggests and fold the sn3216/3218 bits into the earlier patches, or leave it as a 4th patch? I'd probably prefer the former as being an easier workflow (less "rebase -i"ing). And should I base off v4.5-rc6 at that point, or your for-next minus those patches? The only difference should be a 1-line offset in the vendor-prefixes.txt hunk. Either way is equally easy for me. > > Thanks, > Jacek Anaszewski > > On 03/03/2016 04:01 AM, David Rivshin (Allworx) wrote: > > From: David Rivshin <drivshin@allworx.com> > > > > Si-En Technology was acquired by ISSI in 2011, and it appears that > > the IS31FL3218/IS31FL3216 are just rebranded SN3218/SN3216 devices. > > As the IS31FL32XX driver already handles the *3218 devices, there > > is no longer a need for the dedicated SN3218 driver. > > > > Add the "sn,sn3218" and "sn,sn3216" compatible strings into the > > IS31FL32XX driver and binding documentation, and remove the > > leds-sn3218 driver. > > > > Datasheets: > > IS31FL3218: http://www.issi.com/WW/pdf/31FL3218.pdf > > SN3218: http://www.si-en.com/uploadpdf/s2011517171720.pdf > > > > IS31FL3216: http://www.issi.com/WW/pdf/31FL3216.pdf > > SN3216; http://www.si-en.com/uploadpdf/SN3216201152410148.pdf > > > > Signed-off-by: David Rivshin <drivshin@allworx.com> > > --- > > > > Note that the leds-sn3218 binding use a 0-based 'reg' property, while > > the leds-is31fl32xx binding uses a 1-based 'reg' property. This seemed > > to be the preferred binding based on [1]. Since leds-sn3216 has not been > > in a released kernel, there is are no backwards-compatibility concerns. > > > > Changes from RFC: > > new > > > > [1] http://www.spinics.net/lists/linux-leds/msg05589.html > > > > .../devicetree/bindings/leds/leds-is31fl32xx.txt | 9 +- > > .../devicetree/bindings/leds/leds-sn3218.txt | 41 --- > > drivers/leds/Kconfig | 18 +- > > drivers/leds/Makefile | 1 - > > drivers/leds/leds-is31fl32xx.c | 6 +- > > drivers/leds/leds-sn3218.c | 306 --------------------- > > 6 files changed, 14 insertions(+), 367 deletions(-) > > delete mode 100644 Documentation/devicetree/bindings/leds/leds-sn3218.txt > > delete mode 100644 drivers/leds/leds-sn3218.c > > > > diff --git a/Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt b/Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt > > index 539df2e..c59eb1a 100644 > > --- a/Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt > > +++ b/Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt > > @@ -1,6 +1,6 @@ > > -Binding for ISSI IS31FL32xx LED Drivers > > +Binding for ISSI IS31FL32xx and Si-En SN32xx LED Drivers > > > > -The IS31FL32xx family of LED drivers are I2C devices with multiple > > +The IS31FL32xx/SN32xx family of LED drivers are I2C devices with multiple > > constant-current channels, each with independent 256-level PWM control. > > Each LED is represented as a sub-node of the device. > > > > @@ -10,6 +10,8 @@ Required properties: > > issi,is31fl3235 > > issi,is31fl3218 > > issi,is31fl3216 > > + si-en,sn3218 > > + si-en,sn3216 > > - reg: I2C slave address > > - address-cells : must be 1 > > - size-cells : must be 0 > > @@ -45,5 +47,6 @@ leds: is31fl3236@3c { > > }; > > }; > > > > -For more product information please see the link below: > > +For more product information please see the links below: > > http://www.issi.com/US/product-analog-fxled-driver.shtml > > +http://www.si-en.com/product.asp?parentid=890 > > diff --git a/Documentation/devicetree/bindings/leds/leds-sn3218.txt b/Documentation/devicetree/bindings/leds/leds-sn3218.txt > > deleted file mode 100644 > > index 19cbf57..0000000 > > --- a/Documentation/devicetree/bindings/leds/leds-sn3218.txt > > +++ /dev/null > > @@ -1,41 +0,0 @@ > > -* Si-En Technology - SN3218 18-Channel LED Driver > > - > > -Required properties: > > -- compatible : > > - "si-en,sn3218" > > -- address-cells : must be 1 > > -- size-cells : must be 0 > > -- reg : I2C slave address, typically 0x54 > > - > > -There must be at least 1 LED which is represented as a sub-node > > -of the sn3218 device. > > - > > -LED sub-node properties: > > -- label : (optional) see Documentation/devicetree/bindings/leds/common.txt > > -- reg : number of LED line (could be from 0 to 17) > > -- linux,default-trigger : (optional) > > - see Documentation/devicetree/bindings/leds/common.txt > > - > > -Example: > > - > > -sn3218: led-controller@54 { > > - compatible = "si-en,sn3218"; > > - #address-cells = <1>; > > - #size-cells = <0>; > > - reg = <0x54>; > > - > > - led@0 { > > - label = "led1"; > > - reg = <0x0>; > > - }; > > - > > - led@1 { > > - label = "led2"; > > - reg = <0x1>; > > - }; > > - > > - led@2 { > > - label = "led3"; > > - reg = <0x2>; > > - }; > > -}; > > diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig > > index 9c63ba4..1f64151 100644 > > --- a/drivers/leds/Kconfig > > +++ b/drivers/leds/Kconfig > > @@ -568,25 +568,13 @@ config LEDS_SEAD3 > > This driver can also be built as a module. If so the module > > will be called leds-sead3. > > > > -config LEDS_SN3218 > > - tristate "LED support for Si-En SN3218 I2C chip" > > - depends on LEDS_CLASS && I2C > > - depends on OF > > - select REGMAP_I2C > > - help > > - This option enables support for the Si-EN SN3218 LED driver > > - connected through I2C. Say Y to enable support for the SN3218 LED. > > - > > - This driver can also be built as a module. If so the module > > - will be called leds-sn3218. > > - > > config LEDS_IS31FL32XX > > tristate "LED support for ISSI IS31FL32XX I2C LED controller family" > > depends on LEDS_CLASS && I2C && OF > > help > > - Say Y here to include support for ISSI IS31FL32XX LED controllers. > > - They are I2C devices with multiple constant-current channels, each > > - with independent 256-level PWM control. > > + Say Y here to include support for ISSI IS31FL32XX and Si-En SN32xx > > + LED controllers. They are I2C devices with multiple constant-current > > + channels, each with independent 256-level PWM control. > > > > comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)" > > > > diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile > > index 3fdf313..cb2013d 100644 > > --- a/drivers/leds/Makefile > > +++ b/drivers/leds/Makefile > > @@ -66,7 +66,6 @@ obj-$(CONFIG_LEDS_MENF21BMC) += leds-menf21bmc.o > > obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o > > obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o > > obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o > > -obj-$(CONFIG_LEDS_SN3218) += leds-sn3218.o > > obj-$(CONFIG_LEDS_IS31FL32XX) += leds-is31fl32xx.o > > > > # LED SPI Drivers > > diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c > > index 49818f0..ec3f541 100644 > > --- a/drivers/leds/leds-is31fl32xx.c > > +++ b/drivers/leds/leds-is31fl32xx.c > > @@ -10,7 +10,9 @@ > > * it under the terms of the GNU General Public License version 2 as > > * published by the Free Software Foundation. > > * > > - * Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml > > + * Datasheets: > > + * http://www.issi.com/US/product-analog-fxled-driver.shtml > > + * http://www.si-en.com/product.asp?parentid=890 > > */ > > > > #include <linux/err.h> > > @@ -425,7 +427,9 @@ static const struct of_device_id of_is31fl31xx_match[] = { > > { .compatible = "issi,is31fl3236", .data = &is31fl3236_cdef, }, > > { .compatible = "issi,is31fl3235", .data = &is31fl3235_cdef, }, > > { .compatible = "issi,is31fl3218", .data = &is31fl3218_cdef, }, > > + { .compatible = "si-en,sn3218", .data = &is31fl3218_cdef, }, > > { .compatible = "issi,is31fl3216", .data = &is31fl3216_cdef, }, > > + { .compatible = "si-en,sn3216", .data = &is31fl3216_cdef, }, > > {}, > > }; > > > > diff --git a/drivers/leds/leds-sn3218.c b/drivers/leds/leds-sn3218.c > > deleted file mode 100644 > > index dcc2581..0000000 > > --- a/drivers/leds/leds-sn3218.c > > +++ /dev/null > > @@ -1,306 +0,0 @@ > > -/* > > - * Si-En SN3218 18 Channel LED Driver > > - * > > - * Copyright (C) 2016 Stefan Wahren <stefan.wahren@i2se.com> > > - * > > - * Based on leds-pca963x.c > > - * > > - * 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. > > - * > > - * Datasheet: http://www.si-en.com/uploadpdf/s2011517171720.pdf > > - * > > - */ > > - > > -#include <linux/err.h> > > -#include <linux/i2c.h> > > -#include <linux/leds.h> > > -#include <linux/module.h> > > -#include <linux/of.h> > > -#include <linux/regmap.h> > > -#include <linux/slab.h> > > - > > -#define SN3218_MODE 0x00 > > -#define SN3218_PWM_1 0x01 > > -#define SN3218_PWM_2 0x02 > > -#define SN3218_PWM_3 0x03 > > -#define SN3218_PWM_4 0x04 > > -#define SN3218_PWM_5 0x05 > > -#define SN3218_PWM_6 0x06 > > -#define SN3218_PWM_7 0x07 > > -#define SN3218_PWM_8 0x08 > > -#define SN3218_PWM_9 0x09 > > -#define SN3218_PWM_10 0x0a > > -#define SN3218_PWM_11 0x0b > > -#define SN3218_PWM_12 0x0c > > -#define SN3218_PWM_13 0x0d > > -#define SN3218_PWM_14 0x0e > > -#define SN3218_PWM_15 0x0f > > -#define SN3218_PWM_16 0x10 > > -#define SN3218_PWM_17 0x11 > > -#define SN3218_PWM_18 0x12 > > -#define SN3218_LED_1_6 0x13 > > -#define SN3218_LED_7_12 0x14 > > -#define SN3218_LED_13_18 0x15 > > -#define SN3218_UPDATE 0x16 /* applies to reg 0x01 .. 0x15 */ > > -#define SN3218_RESET 0x17 > > - > > -#define SN3218_LED_MASK 0x3f > > -#define SN3218_LED_ON 0x01 > > -#define SN3218_LED_OFF 0x00 > > - > > -#define SN3218_MODE_SHUTDOWN 0x00 > > -#define SN3218_MODE_NORMAL 0x01 > > - > > -#define NUM_LEDS 18 > > - > > -struct sn3218_led; > > - > > -/** > > - * struct sn3218 - > > - * @client - Pointer to the I2C client > > - * @leds - Pointer to the individual LEDs > > - * @num_leds - Actual number of LEDs > > -**/ > > -struct sn3218 { > > - struct i2c_client *client; > > - struct regmap *regmap; > > - struct sn3218_led *leds; > > - int num_leds; > > -}; > > - > > -/** > > - * struct sn3218_led - > > - * @chip - Pointer to the container > > - * @led_cdev - led class device pointer > > - * @led_num - LED index ( 0 .. 17 ) > > -**/ > > -struct sn3218_led { > > - struct sn3218 *chip; > > - struct led_classdev led_cdev; > > - int led_num; > > -}; > > - > > -static int sn3218_led_set(struct led_classdev *led_cdev, > > - enum led_brightness brightness) > > -{ > > - struct sn3218_led *led = > > - container_of(led_cdev, struct sn3218_led, led_cdev); > > - struct regmap *regmap = led->chip->regmap; > > - u8 bank = led->led_num / 6; > > - u8 mask = 0x1 << (led->led_num % 6); > > - u8 val; > > - int ret; > > - > > - if (brightness == LED_OFF) > > - val = 0; > > - else > > - val = mask; > > - > > - ret = regmap_update_bits(regmap, SN3218_LED_1_6 + bank, mask, val); > > - if (ret < 0) > > - return ret; > > - > > - if (brightness > LED_OFF) { > > - ret = regmap_write(regmap, SN3218_PWM_1 + led->led_num, > > - brightness); > > - if (ret < 0) > > - return ret; > > - } > > - > > - ret = regmap_write(regmap, SN3218_UPDATE, 0xff); > > - > > - return ret; > > -} > > - > > -static void sn3218_led_init(struct sn3218 *sn3218, struct device_node *node, > > - u32 reg) > > -{ > > - struct sn3218_led *leds = sn3218->leds; > > - struct led_classdev *cdev = &leds[reg].led_cdev; > > - > > - leds[reg].led_num = reg; > > - leds[reg].chip = sn3218; > > - > > - if (of_property_read_string(node, "label", &cdev->name)) > > - cdev->name = node->name; > > - > > - of_property_read_string(node, "linux,default-trigger", > > - &cdev->default_trigger); > > - > > - cdev->brightness_set_blocking = sn3218_led_set; > > -} > > - > > -static const struct reg_default sn3218_reg_defs[] = { > > - { SN3218_MODE, 0x00}, > > - { SN3218_PWM_1, 0x00}, > > - { SN3218_PWM_2, 0x00}, > > - { SN3218_PWM_3, 0x00}, > > - { SN3218_PWM_4, 0x00}, > > - { SN3218_PWM_5, 0x00}, > > - { SN3218_PWM_6, 0x00}, > > - { SN3218_PWM_7, 0x00}, > > - { SN3218_PWM_8, 0x00}, > > - { SN3218_PWM_9, 0x00}, > > - { SN3218_PWM_10, 0x00}, > > - { SN3218_PWM_11, 0x00}, > > - { SN3218_PWM_12, 0x00}, > > - { SN3218_PWM_13, 0x00}, > > - { SN3218_PWM_14, 0x00}, > > - { SN3218_PWM_15, 0x00}, > > - { SN3218_PWM_16, 0x00}, > > - { SN3218_PWM_17, 0x00}, > > - { SN3218_PWM_18, 0x00}, > > - { SN3218_LED_1_6, 0x00}, > > - { SN3218_LED_7_12, 0x00}, > > - { SN3218_LED_13_18, 0x00}, > > - { SN3218_UPDATE, 0x00}, > > - { SN3218_RESET, 0x00}, > > -}; > > - > > -static const struct regmap_config sn3218_regmap_config = { > > - .reg_bits = 8, > > - .val_bits = 8, > > - > > - .max_register = SN3218_RESET, > > - .reg_defaults = sn3218_reg_defs, > > - .num_reg_defaults = ARRAY_SIZE(sn3218_reg_defs), > > - .cache_type = REGCACHE_RBTREE, > > -}; > > - > > -static int sn3218_init(struct i2c_client *client, struct sn3218 *sn3218) > > -{ > > - struct device_node *np = client->dev.of_node, *child; > > - struct sn3218_led *leds; > > - int ret, count; > > - > > - count = of_get_child_count(np); > > - if (!count) > > - return -ENODEV; > > - > > - if (count > NUM_LEDS) { > > - dev_err(&client->dev, "Invalid LED count %d\n", count); > > - return -EINVAL; > > - } > > - > > - leds = devm_kzalloc(&client->dev, count * sizeof(*leds), GFP_KERNEL); > > - if (!leds) > > - return -ENOMEM; > > - > > - sn3218->leds = leds; > > - sn3218->num_leds = count; > > - sn3218->client = client; > > - > > - sn3218->regmap = devm_regmap_init_i2c(client, &sn3218_regmap_config); > > - if (IS_ERR(sn3218->regmap)) { > > - ret = PTR_ERR(sn3218->regmap); > > - dev_err(&client->dev, "Failed to allocate register map: %d\n", > > - ret); > > - return ret; > > - } > > - > > - for_each_child_of_node(np, child) { > > - u32 reg; > > - > > - ret = of_property_read_u32(child, "reg", ®); > > - if (ret) > > - goto fail; > > - > > - if (reg >= count) { > > - dev_err(&client->dev, "Invalid LED (%u >= %d)\n", reg, > > - count); > > - ret = -EINVAL; > > - goto fail; > > - } > > - > > - sn3218_led_init(sn3218, child, reg); > > - } > > - > > - return 0; > > - > > -fail: > > - of_node_put(child); > > - return ret; > > -} > > - > > -static int sn3218_probe(struct i2c_client *client, > > - const struct i2c_device_id *id) > > -{ > > - struct sn3218 *sn3218; > > - struct sn3218_led *leds; > > - struct device *dev = &client->dev; > > - int i, ret; > > - > > - sn3218 = devm_kzalloc(dev, sizeof(*sn3218), GFP_KERNEL); > > - if (!sn3218) > > - return -ENOMEM; > > - > > - ret = sn3218_init(client, sn3218); > > - if (ret) > > - return ret; > > - > > - i2c_set_clientdata(client, sn3218); > > - leds = sn3218->leds; > > - > > - /* > > - * Since the chip is write-only we need to reset him into > > - * a defined state (all LEDs off). > > - */ > > - ret = regmap_write(sn3218->regmap, SN3218_RESET, 0xff); > > - if (ret) > > - return ret; > > - > > - for (i = 0; i < sn3218->num_leds; i++) { > > - ret = devm_led_classdev_register(dev, &leds[i].led_cdev); > > - if (ret < 0) > > - return ret; > > - } > > - > > - return regmap_write(sn3218->regmap, SN3218_MODE, SN3218_MODE_NORMAL); > > -} > > - > > -static int sn3218_remove(struct i2c_client *client) > > -{ > > - struct sn3218 *sn3218 = i2c_get_clientdata(client); > > - > > - regmap_write(sn3218->regmap, SN3218_MODE, SN3218_MODE_SHUTDOWN); > > - > > - return 0; > > -} > > - > > -static void sn3218_shutdown(struct i2c_client *client) > > -{ > > - struct sn3218 *sn3218 = i2c_get_clientdata(client); > > - > > - regmap_write(sn3218->regmap, SN3218_MODE, SN3218_MODE_SHUTDOWN); > > -} > > - > > -static const struct i2c_device_id sn3218_id[] = { > > - { "sn3218", 0 }, > > - { } > > -}; > > -MODULE_DEVICE_TABLE(i2c, sn3218_id); > > - > > -static const struct of_device_id of_sn3218_match[] = { > > - { .compatible = "si-en,sn3218", }, > > - {}, > > -}; > > -MODULE_DEVICE_TABLE(of, of_sn3218_match); > > - > > -static struct i2c_driver sn3218_driver = { > > - .driver = { > > - .name = "leds-sn3218", > > - .of_match_table = of_match_ptr(of_sn3218_match), > > - }, > > - .probe = sn3218_probe, > > - .remove = sn3218_remove, > > - .shutdown = sn3218_shutdown, > > - .id_table = sn3218_id, > > -}; > > - > > -module_i2c_driver(sn3218_driver); > > - > > -MODULE_DESCRIPTION("Si-En SN3218 LED Driver"); > > -MODULE_AUTHOR("Stefan Wahren <stefan.wahren@i2se.com>"); > > -MODULE_LICENSE("GPL v2"); ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 4/4] leds: Replace dedicated SN3218 driver with IS31FL32XX driver 2016-03-05 5:34 ` David Rivshin (Allworx) @ 2016-03-05 11:37 ` Jacek Anaszewski 0 siblings, 0 replies; 28+ messages in thread From: Jacek Anaszewski @ 2016-03-05 11:37 UTC (permalink / raw) To: David Rivshin (Allworx), Jacek Anaszewski Cc: linux-leds, devicetree, Richard Purdie, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Stefan Wahren, linux-kernel On 03/05/2016 06:34 AM, David Rivshin (Allworx) wrote: > On Thu, 03 Mar 2016 15:51:36 +0100 > Jacek Anaszewski <j.anaszewski@samsung.com> wrote: > >> Hi David, >> >> I'll wait for Tested-by from Stefan before applying this patch. >> If Stefan will have managed to test your driver with his hardware >> by the end of this cycle, it will suffice for this patch to contain >> only leds-is31fl32xx extension part. >> >> leds-sn3218 hasn't been merged to mainline yet, so I'd rather >> remove it when I get Tested-by from Stefan. >> >> Otherwise, I will send leds-sn3218 to Linus, and this patch >> will be applied after being tested, during 4.7 cycle. > > Since Stefan has given his Tested-by, do I understand correctly > that you would prefer to: > - revert sn3218 patches 2 and 3 yourself > - have me provide v2 patches that would apply ontop of that Correct. > If so, should I do as Rob suggests and fold the sn3216/3218 bits into > the earlier patches, or leave it as a 4th patch? I'd probably prefer > the former as being an easier workflow (less "rebase -i"ing). I think that it would be more striking if leds-sn3218 specific compatible would be added both to the driver and the documentation as separate patches. Separate commit description would highlight the reasons for which the same driver supports compatibles with different vendor prefixes. > And should I base off v4.5-rc6 at that point, or your for-next minus > those patches? I like the latter option. I'll do the same - will drop leds-sn3218 patches and apply yours. > The only difference should be a 1-line offset in the > vendor-prefixes.txt hunk. Either way is equally easy for me. > >> >> Thanks, >> Jacek Anaszewski >> >> On 03/03/2016 04:01 AM, David Rivshin (Allworx) wrote: >>> From: David Rivshin <drivshin@allworx.com> >>> >>> Si-En Technology was acquired by ISSI in 2011, and it appears that >>> the IS31FL3218/IS31FL3216 are just rebranded SN3218/SN3216 devices. >>> As the IS31FL32XX driver already handles the *3218 devices, there >>> is no longer a need for the dedicated SN3218 driver. >>> >>> Add the "sn,sn3218" and "sn,sn3216" compatible strings into the >>> IS31FL32XX driver and binding documentation, and remove the >>> leds-sn3218 driver. >>> >>> Datasheets: >>> IS31FL3218: http://www.issi.com/WW/pdf/31FL3218.pdf >>> SN3218: http://www.si-en.com/uploadpdf/s2011517171720.pdf >>> >>> IS31FL3216: http://www.issi.com/WW/pdf/31FL3216.pdf >>> SN3216; http://www.si-en.com/uploadpdf/SN3216201152410148.pdf >>> >>> Signed-off-by: David Rivshin <drivshin@allworx.com> >>> --- >>> >>> Note that the leds-sn3218 binding use a 0-based 'reg' property, while >>> the leds-is31fl32xx binding uses a 1-based 'reg' property. This seemed >>> to be the preferred binding based on [1]. Since leds-sn3216 has not been >>> in a released kernel, there is are no backwards-compatibility concerns. >>> >>> Changes from RFC: >>> new >>> >>> [1] http://www.spinics.net/lists/linux-leds/msg05589.html >>> >>> .../devicetree/bindings/leds/leds-is31fl32xx.txt | 9 +- >>> .../devicetree/bindings/leds/leds-sn3218.txt | 41 --- >>> drivers/leds/Kconfig | 18 +- >>> drivers/leds/Makefile | 1 - >>> drivers/leds/leds-is31fl32xx.c | 6 +- >>> drivers/leds/leds-sn3218.c | 306 --------------------- >>> 6 files changed, 14 insertions(+), 367 deletions(-) >>> delete mode 100644 Documentation/devicetree/bindings/leds/leds-sn3218.txt >>> delete mode 100644 drivers/leds/leds-sn3218.c >>> >>> diff --git a/Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt b/Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt >>> index 539df2e..c59eb1a 100644 >>> --- a/Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt >>> +++ b/Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt >>> @@ -1,6 +1,6 @@ >>> -Binding for ISSI IS31FL32xx LED Drivers >>> +Binding for ISSI IS31FL32xx and Si-En SN32xx LED Drivers >>> >>> -The IS31FL32xx family of LED drivers are I2C devices with multiple >>> +The IS31FL32xx/SN32xx family of LED drivers are I2C devices with multiple >>> constant-current channels, each with independent 256-level PWM control. >>> Each LED is represented as a sub-node of the device. >>> >>> @@ -10,6 +10,8 @@ Required properties: >>> issi,is31fl3235 >>> issi,is31fl3218 >>> issi,is31fl3216 >>> + si-en,sn3218 >>> + si-en,sn3216 >>> - reg: I2C slave address >>> - address-cells : must be 1 >>> - size-cells : must be 0 >>> @@ -45,5 +47,6 @@ leds: is31fl3236@3c { >>> }; >>> }; >>> >>> -For more product information please see the link below: >>> +For more product information please see the links below: >>> http://www.issi.com/US/product-analog-fxled-driver.shtml >>> +http://www.si-en.com/product.asp?parentid=890 >>> diff --git a/Documentation/devicetree/bindings/leds/leds-sn3218.txt b/Documentation/devicetree/bindings/leds/leds-sn3218.txt >>> deleted file mode 100644 >>> index 19cbf57..0000000 >>> --- a/Documentation/devicetree/bindings/leds/leds-sn3218.txt >>> +++ /dev/null >>> @@ -1,41 +0,0 @@ >>> -* Si-En Technology - SN3218 18-Channel LED Driver >>> - >>> -Required properties: >>> -- compatible : >>> - "si-en,sn3218" >>> -- address-cells : must be 1 >>> -- size-cells : must be 0 >>> -- reg : I2C slave address, typically 0x54 >>> - >>> -There must be at least 1 LED which is represented as a sub-node >>> -of the sn3218 device. >>> - >>> -LED sub-node properties: >>> -- label : (optional) see Documentation/devicetree/bindings/leds/common.txt >>> -- reg : number of LED line (could be from 0 to 17) >>> -- linux,default-trigger : (optional) >>> - see Documentation/devicetree/bindings/leds/common.txt >>> - >>> -Example: >>> - >>> -sn3218: led-controller@54 { >>> - compatible = "si-en,sn3218"; >>> - #address-cells = <1>; >>> - #size-cells = <0>; >>> - reg = <0x54>; >>> - >>> - led@0 { >>> - label = "led1"; >>> - reg = <0x0>; >>> - }; >>> - >>> - led@1 { >>> - label = "led2"; >>> - reg = <0x1>; >>> - }; >>> - >>> - led@2 { >>> - label = "led3"; >>> - reg = <0x2>; >>> - }; >>> -}; >>> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig >>> index 9c63ba4..1f64151 100644 >>> --- a/drivers/leds/Kconfig >>> +++ b/drivers/leds/Kconfig >>> @@ -568,25 +568,13 @@ config LEDS_SEAD3 >>> This driver can also be built as a module. If so the module >>> will be called leds-sead3. >>> >>> -config LEDS_SN3218 >>> - tristate "LED support for Si-En SN3218 I2C chip" >>> - depends on LEDS_CLASS && I2C >>> - depends on OF >>> - select REGMAP_I2C >>> - help >>> - This option enables support for the Si-EN SN3218 LED driver >>> - connected through I2C. Say Y to enable support for the SN3218 LED. >>> - >>> - This driver can also be built as a module. If so the module >>> - will be called leds-sn3218. >>> - >>> config LEDS_IS31FL32XX >>> tristate "LED support for ISSI IS31FL32XX I2C LED controller family" >>> depends on LEDS_CLASS && I2C && OF >>> help >>> - Say Y here to include support for ISSI IS31FL32XX LED controllers. >>> - They are I2C devices with multiple constant-current channels, each >>> - with independent 256-level PWM control. >>> + Say Y here to include support for ISSI IS31FL32XX and Si-En SN32xx >>> + LED controllers. They are I2C devices with multiple constant-current >>> + channels, each with independent 256-level PWM control. >>> >>> comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)" >>> >>> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile >>> index 3fdf313..cb2013d 100644 >>> --- a/drivers/leds/Makefile >>> +++ b/drivers/leds/Makefile >>> @@ -66,7 +66,6 @@ obj-$(CONFIG_LEDS_MENF21BMC) += leds-menf21bmc.o >>> obj-$(CONFIG_LEDS_KTD2692) += leds-ktd2692.o >>> obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o >>> obj-$(CONFIG_LEDS_SEAD3) += leds-sead3.o >>> -obj-$(CONFIG_LEDS_SN3218) += leds-sn3218.o >>> obj-$(CONFIG_LEDS_IS31FL32XX) += leds-is31fl32xx.o >>> >>> # LED SPI Drivers >>> diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c >>> index 49818f0..ec3f541 100644 >>> --- a/drivers/leds/leds-is31fl32xx.c >>> +++ b/drivers/leds/leds-is31fl32xx.c >>> @@ -10,7 +10,9 @@ >>> * it under the terms of the GNU General Public License version 2 as >>> * published by the Free Software Foundation. >>> * >>> - * Datasheets: http://www.issi.com/US/product-analog-fxled-driver.shtml >>> + * Datasheets: >>> + * http://www.issi.com/US/product-analog-fxled-driver.shtml >>> + * http://www.si-en.com/product.asp?parentid=890 >>> */ >>> >>> #include <linux/err.h> >>> @@ -425,7 +427,9 @@ static const struct of_device_id of_is31fl31xx_match[] = { >>> { .compatible = "issi,is31fl3236", .data = &is31fl3236_cdef, }, >>> { .compatible = "issi,is31fl3235", .data = &is31fl3235_cdef, }, >>> { .compatible = "issi,is31fl3218", .data = &is31fl3218_cdef, }, >>> + { .compatible = "si-en,sn3218", .data = &is31fl3218_cdef, }, >>> { .compatible = "issi,is31fl3216", .data = &is31fl3216_cdef, }, >>> + { .compatible = "si-en,sn3216", .data = &is31fl3216_cdef, }, >>> {}, >>> }; >>> >>> diff --git a/drivers/leds/leds-sn3218.c b/drivers/leds/leds-sn3218.c >>> deleted file mode 100644 >>> index dcc2581..0000000 >>> --- a/drivers/leds/leds-sn3218.c >>> +++ /dev/null >>> @@ -1,306 +0,0 @@ >>> -/* >>> - * Si-En SN3218 18 Channel LED Driver >>> - * >>> - * Copyright (C) 2016 Stefan Wahren <stefan.wahren@i2se.com> >>> - * >>> - * Based on leds-pca963x.c >>> - * >>> - * 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. >>> - * >>> - * Datasheet: http://www.si-en.com/uploadpdf/s2011517171720.pdf >>> - * >>> - */ >>> - >>> -#include <linux/err.h> >>> -#include <linux/i2c.h> >>> -#include <linux/leds.h> >>> -#include <linux/module.h> >>> -#include <linux/of.h> >>> -#include <linux/regmap.h> >>> -#include <linux/slab.h> >>> - >>> -#define SN3218_MODE 0x00 >>> -#define SN3218_PWM_1 0x01 >>> -#define SN3218_PWM_2 0x02 >>> -#define SN3218_PWM_3 0x03 >>> -#define SN3218_PWM_4 0x04 >>> -#define SN3218_PWM_5 0x05 >>> -#define SN3218_PWM_6 0x06 >>> -#define SN3218_PWM_7 0x07 >>> -#define SN3218_PWM_8 0x08 >>> -#define SN3218_PWM_9 0x09 >>> -#define SN3218_PWM_10 0x0a >>> -#define SN3218_PWM_11 0x0b >>> -#define SN3218_PWM_12 0x0c >>> -#define SN3218_PWM_13 0x0d >>> -#define SN3218_PWM_14 0x0e >>> -#define SN3218_PWM_15 0x0f >>> -#define SN3218_PWM_16 0x10 >>> -#define SN3218_PWM_17 0x11 >>> -#define SN3218_PWM_18 0x12 >>> -#define SN3218_LED_1_6 0x13 >>> -#define SN3218_LED_7_12 0x14 >>> -#define SN3218_LED_13_18 0x15 >>> -#define SN3218_UPDATE 0x16 /* applies to reg 0x01 .. 0x15 */ >>> -#define SN3218_RESET 0x17 >>> - >>> -#define SN3218_LED_MASK 0x3f >>> -#define SN3218_LED_ON 0x01 >>> -#define SN3218_LED_OFF 0x00 >>> - >>> -#define SN3218_MODE_SHUTDOWN 0x00 >>> -#define SN3218_MODE_NORMAL 0x01 >>> - >>> -#define NUM_LEDS 18 >>> - >>> -struct sn3218_led; >>> - >>> -/** >>> - * struct sn3218 - >>> - * @client - Pointer to the I2C client >>> - * @leds - Pointer to the individual LEDs >>> - * @num_leds - Actual number of LEDs >>> -**/ >>> -struct sn3218 { >>> - struct i2c_client *client; >>> - struct regmap *regmap; >>> - struct sn3218_led *leds; >>> - int num_leds; >>> -}; >>> - >>> -/** >>> - * struct sn3218_led - >>> - * @chip - Pointer to the container >>> - * @led_cdev - led class device pointer >>> - * @led_num - LED index ( 0 .. 17 ) >>> -**/ >>> -struct sn3218_led { >>> - struct sn3218 *chip; >>> - struct led_classdev led_cdev; >>> - int led_num; >>> -}; >>> - >>> -static int sn3218_led_set(struct led_classdev *led_cdev, >>> - enum led_brightness brightness) >>> -{ >>> - struct sn3218_led *led = >>> - container_of(led_cdev, struct sn3218_led, led_cdev); >>> - struct regmap *regmap = led->chip->regmap; >>> - u8 bank = led->led_num / 6; >>> - u8 mask = 0x1 << (led->led_num % 6); >>> - u8 val; >>> - int ret; >>> - >>> - if (brightness == LED_OFF) >>> - val = 0; >>> - else >>> - val = mask; >>> - >>> - ret = regmap_update_bits(regmap, SN3218_LED_1_6 + bank, mask, val); >>> - if (ret < 0) >>> - return ret; >>> - >>> - if (brightness > LED_OFF) { >>> - ret = regmap_write(regmap, SN3218_PWM_1 + led->led_num, >>> - brightness); >>> - if (ret < 0) >>> - return ret; >>> - } >>> - >>> - ret = regmap_write(regmap, SN3218_UPDATE, 0xff); >>> - >>> - return ret; >>> -} >>> - >>> -static void sn3218_led_init(struct sn3218 *sn3218, struct device_node *node, >>> - u32 reg) >>> -{ >>> - struct sn3218_led *leds = sn3218->leds; >>> - struct led_classdev *cdev = &leds[reg].led_cdev; >>> - >>> - leds[reg].led_num = reg; >>> - leds[reg].chip = sn3218; >>> - >>> - if (of_property_read_string(node, "label", &cdev->name)) >>> - cdev->name = node->name; >>> - >>> - of_property_read_string(node, "linux,default-trigger", >>> - &cdev->default_trigger); >>> - >>> - cdev->brightness_set_blocking = sn3218_led_set; >>> -} >>> - >>> -static const struct reg_default sn3218_reg_defs[] = { >>> - { SN3218_MODE, 0x00}, >>> - { SN3218_PWM_1, 0x00}, >>> - { SN3218_PWM_2, 0x00}, >>> - { SN3218_PWM_3, 0x00}, >>> - { SN3218_PWM_4, 0x00}, >>> - { SN3218_PWM_5, 0x00}, >>> - { SN3218_PWM_6, 0x00}, >>> - { SN3218_PWM_7, 0x00}, >>> - { SN3218_PWM_8, 0x00}, >>> - { SN3218_PWM_9, 0x00}, >>> - { SN3218_PWM_10, 0x00}, >>> - { SN3218_PWM_11, 0x00}, >>> - { SN3218_PWM_12, 0x00}, >>> - { SN3218_PWM_13, 0x00}, >>> - { SN3218_PWM_14, 0x00}, >>> - { SN3218_PWM_15, 0x00}, >>> - { SN3218_PWM_16, 0x00}, >>> - { SN3218_PWM_17, 0x00}, >>> - { SN3218_PWM_18, 0x00}, >>> - { SN3218_LED_1_6, 0x00}, >>> - { SN3218_LED_7_12, 0x00}, >>> - { SN3218_LED_13_18, 0x00}, >>> - { SN3218_UPDATE, 0x00}, >>> - { SN3218_RESET, 0x00}, >>> -}; >>> - >>> -static const struct regmap_config sn3218_regmap_config = { >>> - .reg_bits = 8, >>> - .val_bits = 8, >>> - >>> - .max_register = SN3218_RESET, >>> - .reg_defaults = sn3218_reg_defs, >>> - .num_reg_defaults = ARRAY_SIZE(sn3218_reg_defs), >>> - .cache_type = REGCACHE_RBTREE, >>> -}; >>> - >>> -static int sn3218_init(struct i2c_client *client, struct sn3218 *sn3218) >>> -{ >>> - struct device_node *np = client->dev.of_node, *child; >>> - struct sn3218_led *leds; >>> - int ret, count; >>> - >>> - count = of_get_child_count(np); >>> - if (!count) >>> - return -ENODEV; >>> - >>> - if (count > NUM_LEDS) { >>> - dev_err(&client->dev, "Invalid LED count %d\n", count); >>> - return -EINVAL; >>> - } >>> - >>> - leds = devm_kzalloc(&client->dev, count * sizeof(*leds), GFP_KERNEL); >>> - if (!leds) >>> - return -ENOMEM; >>> - >>> - sn3218->leds = leds; >>> - sn3218->num_leds = count; >>> - sn3218->client = client; >>> - >>> - sn3218->regmap = devm_regmap_init_i2c(client, &sn3218_regmap_config); >>> - if (IS_ERR(sn3218->regmap)) { >>> - ret = PTR_ERR(sn3218->regmap); >>> - dev_err(&client->dev, "Failed to allocate register map: %d\n", >>> - ret); >>> - return ret; >>> - } >>> - >>> - for_each_child_of_node(np, child) { >>> - u32 reg; >>> - >>> - ret = of_property_read_u32(child, "reg", ®); >>> - if (ret) >>> - goto fail; >>> - >>> - if (reg >= count) { >>> - dev_err(&client->dev, "Invalid LED (%u >= %d)\n", reg, >>> - count); >>> - ret = -EINVAL; >>> - goto fail; >>> - } >>> - >>> - sn3218_led_init(sn3218, child, reg); >>> - } >>> - >>> - return 0; >>> - >>> -fail: >>> - of_node_put(child); >>> - return ret; >>> -} >>> - >>> -static int sn3218_probe(struct i2c_client *client, >>> - const struct i2c_device_id *id) >>> -{ >>> - struct sn3218 *sn3218; >>> - struct sn3218_led *leds; >>> - struct device *dev = &client->dev; >>> - int i, ret; >>> - >>> - sn3218 = devm_kzalloc(dev, sizeof(*sn3218), GFP_KERNEL); >>> - if (!sn3218) >>> - return -ENOMEM; >>> - >>> - ret = sn3218_init(client, sn3218); >>> - if (ret) >>> - return ret; >>> - >>> - i2c_set_clientdata(client, sn3218); >>> - leds = sn3218->leds; >>> - >>> - /* >>> - * Since the chip is write-only we need to reset him into >>> - * a defined state (all LEDs off). >>> - */ >>> - ret = regmap_write(sn3218->regmap, SN3218_RESET, 0xff); >>> - if (ret) >>> - return ret; >>> - >>> - for (i = 0; i < sn3218->num_leds; i++) { >>> - ret = devm_led_classdev_register(dev, &leds[i].led_cdev); >>> - if (ret < 0) >>> - return ret; >>> - } >>> - >>> - return regmap_write(sn3218->regmap, SN3218_MODE, SN3218_MODE_NORMAL); >>> -} >>> - >>> -static int sn3218_remove(struct i2c_client *client) >>> -{ >>> - struct sn3218 *sn3218 = i2c_get_clientdata(client); >>> - >>> - regmap_write(sn3218->regmap, SN3218_MODE, SN3218_MODE_SHUTDOWN); >>> - >>> - return 0; >>> -} >>> - >>> -static void sn3218_shutdown(struct i2c_client *client) >>> -{ >>> - struct sn3218 *sn3218 = i2c_get_clientdata(client); >>> - >>> - regmap_write(sn3218->regmap, SN3218_MODE, SN3218_MODE_SHUTDOWN); >>> -} >>> - >>> -static const struct i2c_device_id sn3218_id[] = { >>> - { "sn3218", 0 }, >>> - { } >>> -}; >>> -MODULE_DEVICE_TABLE(i2c, sn3218_id); >>> - >>> -static const struct of_device_id of_sn3218_match[] = { >>> - { .compatible = "si-en,sn3218", }, >>> - {}, >>> -}; >>> -MODULE_DEVICE_TABLE(of, of_sn3218_match); >>> - >>> -static struct i2c_driver sn3218_driver = { >>> - .driver = { >>> - .name = "leds-sn3218", >>> - .of_match_table = of_match_ptr(of_sn3218_match), >>> - }, >>> - .probe = sn3218_probe, >>> - .remove = sn3218_remove, >>> - .shutdown = sn3218_shutdown, >>> - .id_table = sn3218_id, >>> -}; >>> - >>> -module_i2c_driver(sn3218_driver); >>> - >>> -MODULE_DESCRIPTION("Si-En SN3218 LED Driver"); >>> -MODULE_AUTHOR("Stefan Wahren <stefan.wahren@i2se.com>"); >>> -MODULE_LICENSE("GPL v2"); > > -- > To unsubscribe from this list: send the line "unsubscribe linux-leds" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > -- Best Regards, Jacek Anaszewski ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 4/4] leds: Replace dedicated SN3218 driver with IS31FL32XX driver 2016-03-03 3:01 ` [PATCH 4/4] leds: Replace dedicated SN3218 driver with IS31FL32XX driver David Rivshin (Allworx) 2016-03-03 14:51 ` Jacek Anaszewski @ 2016-03-04 21:14 ` Stefan Wahren 2016-03-05 5:00 ` David Rivshin (Allworx) 2016-03-05 4:28 ` Rob Herring 2 siblings, 1 reply; 28+ messages in thread From: Stefan Wahren @ 2016-03-04 21:14 UTC (permalink / raw) To: linux-leds, David Rivshin (Allworx), devicetree Cc: Pawel Moll, Rob Herring, Ian Campbell, Kumar Gala, linux-kernel, Jacek Anaszewski, Richard Purdie, Mark Rutland Hi David, > "David Rivshin (Allworx)" <drivshin.allworx@gmail.com> hat am 3. März 2016 um > 04:01 geschrieben: > > > From: David Rivshin <drivshin@allworx.com> > > Si-En Technology was acquired by ISSI in 2011, and it appears that > the IS31FL3218/IS31FL3216 are just rebranded SN3218/SN3216 devices. > As the IS31FL32XX driver already handles the *3218 devices, there > is no longer a need for the dedicated SN3218 driver. > > Add the "sn,sn3218" and "sn,sn3216" compatible strings into the > IS31FL32XX driver and binding documentation, and remove the > leds-sn3218 driver. > > Datasheets: > IS31FL3218: http://www.issi.com/WW/pdf/31FL3218.pdf > SN3218: http://www.si-en.com/uploadpdf/s2011517171720.pdf > > IS31FL3216: http://www.issi.com/WW/pdf/31FL3216.pdf > SN3216; http://www.si-en.com/uploadpdf/SN3216201152410148.pdf > > Signed-off-by: David Rivshin <drivshin@allworx.com> i tested this patch successfully with a Raspberry Pi and a PiGlow (SN3218). Tested-by: Stefan Wahren <stefan.wahren@i2se.com> ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 4/4] leds: Replace dedicated SN3218 driver with IS31FL32XX driver 2016-03-04 21:14 ` Stefan Wahren @ 2016-03-05 5:00 ` David Rivshin (Allworx) 0 siblings, 0 replies; 28+ messages in thread From: David Rivshin (Allworx) @ 2016-03-05 5:00 UTC (permalink / raw) To: Stefan Wahren Cc: linux-leds, devicetree, Pawel Moll, Rob Herring, Ian Campbell, Kumar Gala, linux-kernel, Jacek Anaszewski, Richard Purdie, Mark Rutland On Fri, 4 Mar 2016 22:14:27 +0100 (CET) Stefan Wahren <stefan.wahren@i2se.com> wrote: > Hi David, > > > "David Rivshin (Allworx)" <drivshin.allworx@gmail.com> hat am 3. März 2016 um > > 04:01 geschrieben: > > > > > > From: David Rivshin <drivshin@allworx.com> > > > > Si-En Technology was acquired by ISSI in 2011, and it appears that > > the IS31FL3218/IS31FL3216 are just rebranded SN3218/SN3216 devices. > > As the IS31FL32XX driver already handles the *3218 devices, there > > is no longer a need for the dedicated SN3218 driver. > > > > Add the "sn,sn3218" and "sn,sn3216" compatible strings into the > > IS31FL32XX driver and binding documentation, and remove the > > leds-sn3218 driver. > > > > Datasheets: > > IS31FL3218: http://www.issi.com/WW/pdf/31FL3218.pdf > > SN3218: http://www.si-en.com/uploadpdf/s2011517171720.pdf > > > > IS31FL3216: http://www.issi.com/WW/pdf/31FL3216.pdf > > SN3216; http://www.si-en.com/uploadpdf/SN3216201152410148.pdf > > > > Signed-off-by: David Rivshin <drivshin@allworx.com> > > i tested this patch successfully with a Raspberry Pi and a PiGlow (SN3218). > > Tested-by: Stefan Wahren <stefan.wahren@i2se.com> Thanks very much for testing! The PiGlow looks interesting, if I had known about it I might have just ordered one for testing myself. Looks rather easier to hook up than the ISSI 3216 eval board. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 4/4] leds: Replace dedicated SN3218 driver with IS31FL32XX driver 2016-03-03 3:01 ` [PATCH 4/4] leds: Replace dedicated SN3218 driver with IS31FL32XX driver David Rivshin (Allworx) 2016-03-03 14:51 ` Jacek Anaszewski 2016-03-04 21:14 ` Stefan Wahren @ 2016-03-05 4:28 ` Rob Herring 2 siblings, 0 replies; 28+ messages in thread From: Rob Herring @ 2016-03-05 4:28 UTC (permalink / raw) To: David Rivshin (Allworx) Cc: linux-leds, devicetree, Richard Purdie, Jacek Anaszewski, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Stefan Wahren, linux-kernel On Wed, Mar 02, 2016 at 10:01:35PM -0500, David Rivshin (Allworx) wrote: > From: David Rivshin <drivshin@allworx.com> > > Si-En Technology was acquired by ISSI in 2011, and it appears that > the IS31FL3218/IS31FL3216 are just rebranded SN3218/SN3216 devices. > As the IS31FL32XX driver already handles the *3218 devices, there > is no longer a need for the dedicated SN3218 driver. > > Add the "sn,sn3218" and "sn,sn3216" compatible strings into the > IS31FL32XX driver and binding documentation, and remove the > leds-sn3218 driver. > > Datasheets: > IS31FL3218: http://www.issi.com/WW/pdf/31FL3218.pdf > SN3218: http://www.si-en.com/uploadpdf/s2011517171720.pdf > > IS31FL3216: http://www.issi.com/WW/pdf/31FL3216.pdf > SN3216; http://www.si-en.com/uploadpdf/SN3216201152410148.pdf > > Signed-off-by: David Rivshin <drivshin@allworx.com> > --- > > Note that the leds-sn3218 binding use a 0-based 'reg' property, while > the leds-is31fl32xx binding uses a 1-based 'reg' property. This seemed > to be the preferred binding based on [1]. Since leds-sn3216 has not been > in a released kernel, there is are no backwards-compatibility concerns. It would probably make more sense to revert the sn3216 driver/binding and add the additions to the previous patches. Doesn't matter to me though. Acked-by: Rob Herring <robh@kernel.org> > > Changes from RFC: > new > > [1] http://www.spinics.net/lists/linux-leds/msg05589.html > > .../devicetree/bindings/leds/leds-is31fl32xx.txt | 9 +- > .../devicetree/bindings/leds/leds-sn3218.txt | 41 --- > drivers/leds/Kconfig | 18 +- > drivers/leds/Makefile | 1 - > drivers/leds/leds-is31fl32xx.c | 6 +- > drivers/leds/leds-sn3218.c | 306 --------------------- > 6 files changed, 14 insertions(+), 367 deletions(-) > delete mode 100644 Documentation/devicetree/bindings/leds/leds-sn3218.txt > delete mode 100644 drivers/leds/leds-sn3218.c ^ permalink raw reply [flat|nested] 28+ messages in thread
end of thread, other threads:[~2016-03-05 11:39 UTC | newest] Thread overview: 28+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-03-03 3:01 [PATCH 0/4] leds: Add driver for the ISSI IS31FL32xx family of LED controllers David Rivshin (Allworx) 2016-03-03 3:01 ` [PATCH 1/4] DT: Add vendor prefix for Integrated Silicon Solutions Inc David Rivshin (Allworx) 2016-03-05 4:28 ` Rob Herring 2016-03-03 3:01 ` [PATCH 2/4] DT: leds: Add binding for the ISSI IS31FL32xx family of LED controllers David Rivshin (Allworx) 2016-03-05 4:28 ` Rob Herring 2016-03-03 3:01 ` [PATCH 3/4] leds: Add driver " David Rivshin (Allworx) 2016-03-03 3:21 ` kbuild test robot 2016-03-03 14:51 ` Jacek Anaszewski 2016-03-04 0:45 ` David Rivshin (Allworx) [not found] ` <20160303194531.316d7918.drivshin.allworx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 2016-03-04 7:54 ` Jacek Anaszewski [not found] ` <56D93F1A.6030305-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> 2016-03-04 15:05 ` David Rivshin (Allworx) 2016-03-04 16:01 ` Jacek Anaszewski 2016-03-04 19:02 ` David Rivshin (Allworx) 2016-03-04 21:39 ` Jacek Anaszewski 2016-03-05 5:29 ` David Rivshin (Allworx) 2016-03-05 11:37 ` Jacek Anaszewski 2016-03-03 18:13 ` Stefan Wahren 2016-03-04 14:27 ` David Rivshin (Allworx) 2016-03-04 15:38 ` Jacek Anaszewski 2016-03-05 6:12 ` David Rivshin (Allworx) 2016-03-05 11:39 ` Jacek Anaszewski 2016-03-03 3:01 ` [PATCH 4/4] leds: Replace dedicated SN3218 driver with IS31FL32XX driver David Rivshin (Allworx) 2016-03-03 14:51 ` Jacek Anaszewski 2016-03-05 5:34 ` David Rivshin (Allworx) 2016-03-05 11:37 ` Jacek Anaszewski 2016-03-04 21:14 ` Stefan Wahren 2016-03-05 5:00 ` David Rivshin (Allworx) 2016-03-05 4:28 ` Rob Herring
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).