Re: [PATCH v10 06/16] leds: lp50xx: Add the LP50XX family of the RGB LED driver

2019-10-07 Thread Dan Murphy

Jacek

On 10/6/19 11:12 AM, Jacek Anaszewski wrote:

Dan,

On 10/1/19 4:56 PM, Dan Murphy wrote:

Introduce the LP5036/30/24/18/12/9 RGB LED driver.
The difference in these parts are the number of
LED outputs where the:

LP5036 can control 36 LEDs
LP5030 can control 30 LEDs
LP5024 can control 24 LEDs
LP5018 can control 18 LEDs
LP5012 can control 12 LEDs
LP5009 can control 9 LEDs

The device has the ability to group LED output into control banks
so that multiple LED banks can be controlled with the same mixing and
brightness.  Inversely the LEDs can also be controlled independently.

Signed-off-by: Dan Murphy 
---
  drivers/leds/Kconfig   |  11 +
  drivers/leds/Makefile  |   1 +
  drivers/leds/leds-lp50xx.c | 784 +
  3 files changed, 796 insertions(+)
  create mode 100644 drivers/leds/leds-lp50xx.c

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index cfb1ebb6517f..84f60e35c5ee 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -363,6 +363,17 @@ config LEDS_LP3952
  To compile this driver as a module, choose M here: the
  module will be called leds-lp3952.
  
+config LEDS_LP50XX

+   tristate "LED Support for TI LP5036/30/24/18/12/9 LED driver chip"
+   depends on LEDS_CLASS && REGMAP_I2C
+   depends on LEDS_CLASS_MULTI_COLOR
+   help
+ If you say yes here you get support for the Texas Instruments
+ LP5036, LP5030, LP5024, LP5018, LP5012 and LP5009 LED driver.
+
+ To compile this driver as a module, choose M here: the
+ module will be called leds-lp50xx.
+
  config LEDS_LP55XX_COMMON
tristate "Common Driver for TI/National LP5521/5523/55231/5562/8501"
depends on LEDS_LP5521 || LEDS_LP5523 || LEDS_LP5562 || LEDS_LP8501
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 841038cfe35b..7a208a0f7b84 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -34,6 +34,7 @@ obj-$(CONFIG_LEDS_GPIO_REGISTER)  += leds-gpio-register.o
  obj-$(CONFIG_LEDS_GPIO)   += leds-gpio.o
  obj-$(CONFIG_LEDS_LP3944) += leds-lp3944.o
  obj-$(CONFIG_LEDS_LP3952) += leds-lp3952.o
+obj-$(CONFIG_LEDS_LP50XX)  += leds-lp50xx.o
  obj-$(CONFIG_LEDS_LP55XX_COMMON)  += leds-lp55xx-common.o
  obj-$(CONFIG_LEDS_LP5521) += leds-lp5521.o
  obj-$(CONFIG_LEDS_LP5523) += leds-lp5523.o
diff --git a/drivers/leds/leds-lp50xx.c b/drivers/leds/leds-lp50xx.c

[...]

+static int lp50xx_probe_dt(struct lp50xx *priv)
+{
+   u32 led_banks[LP5036_MAX_LED_MODULES];
+   struct fwnode_handle *child = NULL;
+   struct fwnode_handle *led_node = NULL;
+   struct led_init_data init_data;
+   struct lp50xx_led *led;
+   int num_colors;
+   u32 color_id;
+   int led_number;
+   size_t i = 0;
+   int ret;
+
+   priv->enable_gpio = devm_gpiod_get_optional(>client->dev,
+  "enable", GPIOD_OUT_LOW);
+   if (IS_ERR(priv->enable_gpio)) {
+   ret = PTR_ERR(priv->enable_gpio);
+   dev_err(>client->dev, "Failed to get enable gpio: %d\n",
+   ret);
+   return ret;
+   }
+
+   priv->regulator = devm_regulator_get(>client->dev, "vled");
+   if (IS_ERR(priv->regulator))
+   priv->regulator = NULL;
+
+   device_for_each_child_node(>client->dev, child) {
+   led = >leds[i];
+   if (fwnode_property_present(child, "ti,led-bank")) {
+   ret = fwnode_property_read_u32_array(child,
+"ti,led-bank",
+NULL, 0);
+   ret = fwnode_property_read_u32_array(child,
+"ti,led-bank",
+led_banks,
+ret);

You could check if bank numbers are within a range.


Ack





+   if (ret) {
+   dev_err(>client->dev,
+   "led-bank property is missing\n");
+   fwnode_handle_put(child);
+   goto child_out;
+   }
+
+   priv->num_of_banked_leds = ARRAY_SIZE(led_banks);
+
+   ret = lp50xx_set_banks(priv, led_banks);
+   if (ret) {
+   dev_err(>client->dev,
+   "Cannot setup banked LEDs\n");
+   fwnode_handle_put(child);
+   goto child_out;
+   }
+   led->ctrl_bank_enabled = 1;
+
+   } else {
+   ret = 

Re: [PATCH v10 06/16] leds: lp50xx: Add the LP50XX family of the RGB LED driver

2019-10-06 Thread Jacek Anaszewski
Dan,

On 10/1/19 4:56 PM, Dan Murphy wrote:
> Introduce the LP5036/30/24/18/12/9 RGB LED driver.
> The difference in these parts are the number of
> LED outputs where the:
> 
> LP5036 can control 36 LEDs
> LP5030 can control 30 LEDs
> LP5024 can control 24 LEDs
> LP5018 can control 18 LEDs
> LP5012 can control 12 LEDs
> LP5009 can control 9 LEDs
> 
> The device has the ability to group LED output into control banks
> so that multiple LED banks can be controlled with the same mixing and
> brightness.  Inversely the LEDs can also be controlled independently.
> 
> Signed-off-by: Dan Murphy 
> ---
>  drivers/leds/Kconfig   |  11 +
>  drivers/leds/Makefile  |   1 +
>  drivers/leds/leds-lp50xx.c | 784 +
>  3 files changed, 796 insertions(+)
>  create mode 100644 drivers/leds/leds-lp50xx.c
> 
> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
> index cfb1ebb6517f..84f60e35c5ee 100644
> --- a/drivers/leds/Kconfig
> +++ b/drivers/leds/Kconfig
> @@ -363,6 +363,17 @@ config LEDS_LP3952
> To compile this driver as a module, choose M here: the
> module will be called leds-lp3952.
>  
> +config LEDS_LP50XX
> + tristate "LED Support for TI LP5036/30/24/18/12/9 LED driver chip"
> + depends on LEDS_CLASS && REGMAP_I2C
> + depends on LEDS_CLASS_MULTI_COLOR
> + help
> +   If you say yes here you get support for the Texas Instruments
> +   LP5036, LP5030, LP5024, LP5018, LP5012 and LP5009 LED driver.
> +
> +   To compile this driver as a module, choose M here: the
> +   module will be called leds-lp50xx.
> +
>  config LEDS_LP55XX_COMMON
>   tristate "Common Driver for TI/National LP5521/5523/55231/5562/8501"
>   depends on LEDS_LP5521 || LEDS_LP5523 || LEDS_LP5562 || LEDS_LP8501
> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
> index 841038cfe35b..7a208a0f7b84 100644
> --- a/drivers/leds/Makefile
> +++ b/drivers/leds/Makefile
> @@ -34,6 +34,7 @@ obj-$(CONFIG_LEDS_GPIO_REGISTER)+= leds-gpio-register.o
>  obj-$(CONFIG_LEDS_GPIO)  += leds-gpio.o
>  obj-$(CONFIG_LEDS_LP3944)+= leds-lp3944.o
>  obj-$(CONFIG_LEDS_LP3952)+= leds-lp3952.o
> +obj-$(CONFIG_LEDS_LP50XX)+= leds-lp50xx.o
>  obj-$(CONFIG_LEDS_LP55XX_COMMON) += leds-lp55xx-common.o
>  obj-$(CONFIG_LEDS_LP5521)+= leds-lp5521.o
>  obj-$(CONFIG_LEDS_LP5523)+= leds-lp5523.o
> diff --git a/drivers/leds/leds-lp50xx.c b/drivers/leds/leds-lp50xx.c
[...]
> +static int lp50xx_probe_dt(struct lp50xx *priv)
> +{
> + u32 led_banks[LP5036_MAX_LED_MODULES];
> + struct fwnode_handle *child = NULL;
> + struct fwnode_handle *led_node = NULL;
> + struct led_init_data init_data;
> + struct lp50xx_led *led;
> + int num_colors;
> + u32 color_id;
> + int led_number;
> + size_t i = 0;
> + int ret;
> +
> + priv->enable_gpio = devm_gpiod_get_optional(>client->dev,
> +"enable", GPIOD_OUT_LOW);
> + if (IS_ERR(priv->enable_gpio)) {
> + ret = PTR_ERR(priv->enable_gpio);
> + dev_err(>client->dev, "Failed to get enable gpio: %d\n",
> + ret);
> + return ret;
> + }
> +
> + priv->regulator = devm_regulator_get(>client->dev, "vled");
> + if (IS_ERR(priv->regulator))
> + priv->regulator = NULL;
> +
> + device_for_each_child_node(>client->dev, child) {
> + led = >leds[i];
> + if (fwnode_property_present(child, "ti,led-bank")) {
> + ret = fwnode_property_read_u32_array(child,
> +  "ti,led-bank",
> +  NULL, 0);
> + ret = fwnode_property_read_u32_array(child,
> +  "ti,led-bank",
> +  led_banks,
> +  ret);

You could check if bank numbers are within a range.

> + if (ret) {
> + dev_err(>client->dev,
> + "led-bank property is missing\n");
> + fwnode_handle_put(child);
> + goto child_out;
> + }
> +
> + priv->num_of_banked_leds = ARRAY_SIZE(led_banks);
> +
> + ret = lp50xx_set_banks(priv, led_banks);
> + if (ret) {
> + dev_err(>client->dev,
> + "Cannot setup banked LEDs\n");
> + fwnode_handle_put(child);
> + goto child_out;
> + }
> + led->ctrl_bank_enabled = 1;
> +
> + } else {
> + ret = 

Re: [PATCH v10 06/16] leds: lp50xx: Add the LP50XX family of the RGB LED driver

2019-10-01 Thread kbuild test robot
Hi Dan,

I love your patch! Yet something to improve:

[auto build test ERROR on j.anaszewski-leds/for-next]
[cannot apply to v5.4-rc1 next-20191001]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:
https://github.com/0day-ci/linux/commits/Dan-Murphy/Multicolor-Framework/20191002-062337
base:   
https://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski/linux-leds.git 
for-next
config: mips-allmodconfig (attached as .config)
compiler: mips-linux-gcc (GCC) 7.4.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=mips 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot 

All errors (new ones prefixed by >>):

>> drivers/leds/leds-lp50xx.c:358:27: error: initializer element is not constant
  .lp50xx_regmap_config = lp5012_regmap_config,
  ^~~~
   drivers/leds/leds-lp50xx.c:358:27: note: (near initialization for 
'lp50xx_chip_info_tbl[0].lp50xx_regmap_config')
   drivers/leds/leds-lp50xx.c:368:27: error: initializer element is not constant
  .lp50xx_regmap_config = lp5012_regmap_config,
  ^~~~
   drivers/leds/leds-lp50xx.c:368:27: note: (near initialization for 
'lp50xx_chip_info_tbl[1].lp50xx_regmap_config')
   drivers/leds/leds-lp50xx.c:378:27: error: initializer element is not constant
  .lp50xx_regmap_config = lp5024_regmap_config,
  ^~~~
   drivers/leds/leds-lp50xx.c:378:27: note: (near initialization for 
'lp50xx_chip_info_tbl[2].lp50xx_regmap_config')
   drivers/leds/leds-lp50xx.c:388:27: error: initializer element is not constant
  .lp50xx_regmap_config = lp5024_regmap_config,
  ^~~~
   drivers/leds/leds-lp50xx.c:388:27: note: (near initialization for 
'lp50xx_chip_info_tbl[3].lp50xx_regmap_config')
   drivers/leds/leds-lp50xx.c:398:27: error: initializer element is not constant
  .lp50xx_regmap_config = lp5036_regmap_config,
  ^~~~
   drivers/leds/leds-lp50xx.c:398:27: note: (near initialization for 
'lp50xx_chip_info_tbl[4].lp50xx_regmap_config')
   drivers/leds/leds-lp50xx.c:408:27: error: initializer element is not constant
  .lp50xx_regmap_config = lp5036_regmap_config,
  ^~~~
   drivers/leds/leds-lp50xx.c:408:27: note: (near initialization for 
'lp50xx_chip_info_tbl[5].lp50xx_regmap_config')

vim +358 drivers/leds/leds-lp50xx.c

   348  
   349  static const struct lp50xx_chip_info lp50xx_chip_info_tbl[] = {
   350  [LP5009] = {
   351  .model_id = LP5009,
   352  .num_leds = LP5009_MAX_LEDS,
   353  .led_brightness0_reg = LP5012_LED0_BRT,
   354  .mix_out0_reg = LP5012_OUT0_CLR,
   355  .bank_brt_reg = LP5012_BNK_BRT,
   356  .bank_mix_reg = LP5012_BNKA_CLR,
   357  .reset_reg = LP5012_RESET,
 > 358  .lp50xx_regmap_config = lp5012_regmap_config,
   359  },
   360  [LP5012] = {
   361  .model_id = LP5012,
   362  .num_leds = LP5012_MAX_LEDS,
   363  .led_brightness0_reg = LP5012_LED0_BRT,
   364  .mix_out0_reg = LP5012_OUT0_CLR,
   365  .bank_brt_reg = LP5012_BNK_BRT,
   366  .bank_mix_reg = LP5012_BNKA_CLR,
   367  .reset_reg = LP5012_RESET,
   368  .lp50xx_regmap_config = lp5012_regmap_config,
   369  },
   370  [LP5018] = {
   371  .model_id = LP5018,
   372  .num_leds = LP5018_MAX_LEDS,
   373  .led_brightness0_reg = LP5024_LED0_BRT,
   374  .mix_out0_reg = LP5024_OUT0_CLR,
   375  .bank_brt_reg = LP5024_BNK_BRT,
   376  .bank_mix_reg = LP5024_BNKA_CLR,
   377  .reset_reg = LP5024_RESET,
   378  .lp50xx_regmap_config = lp5024_regmap_config,
   379  },
   380  [LP5024] = {
   381  .model_id = LP5024,
   382  .num_leds = LP5024_MAX_LEDS,
   383  .led_brightness0_reg = LP5024_LED0_BRT,
   384  .mix_out0_reg = LP5024_OUT0_CLR,
   385  .bank_brt_reg = LP5024_BNK_BRT,
   386  .bank_mix_reg = LP5024_BNKA_CLR,
   387  .reset_reg = LP5024_RESET,
   388  .lp50xx_regmap_config = lp5024_regmap_config,
   389  },
   390  

[PATCH v10 06/16] leds: lp50xx: Add the LP50XX family of the RGB LED driver

2019-10-01 Thread Dan Murphy
Introduce the LP5036/30/24/18/12/9 RGB LED driver.
The difference in these parts are the number of
LED outputs where the:

LP5036 can control 36 LEDs
LP5030 can control 30 LEDs
LP5024 can control 24 LEDs
LP5018 can control 18 LEDs
LP5012 can control 12 LEDs
LP5009 can control 9 LEDs

The device has the ability to group LED output into control banks
so that multiple LED banks can be controlled with the same mixing and
brightness.  Inversely the LEDs can also be controlled independently.

Signed-off-by: Dan Murphy 
---
 drivers/leds/Kconfig   |  11 +
 drivers/leds/Makefile  |   1 +
 drivers/leds/leds-lp50xx.c | 784 +
 3 files changed, 796 insertions(+)
 create mode 100644 drivers/leds/leds-lp50xx.c

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index cfb1ebb6517f..84f60e35c5ee 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -363,6 +363,17 @@ config LEDS_LP3952
  To compile this driver as a module, choose M here: the
  module will be called leds-lp3952.
 
+config LEDS_LP50XX
+   tristate "LED Support for TI LP5036/30/24/18/12/9 LED driver chip"
+   depends on LEDS_CLASS && REGMAP_I2C
+   depends on LEDS_CLASS_MULTI_COLOR
+   help
+ If you say yes here you get support for the Texas Instruments
+ LP5036, LP5030, LP5024, LP5018, LP5012 and LP5009 LED driver.
+
+ To compile this driver as a module, choose M here: the
+ module will be called leds-lp50xx.
+
 config LEDS_LP55XX_COMMON
tristate "Common Driver for TI/National LP5521/5523/55231/5562/8501"
depends on LEDS_LP5521 || LEDS_LP5523 || LEDS_LP5562 || LEDS_LP8501
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 841038cfe35b..7a208a0f7b84 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -34,6 +34,7 @@ obj-$(CONFIG_LEDS_GPIO_REGISTER)  += leds-gpio-register.o
 obj-$(CONFIG_LEDS_GPIO)+= leds-gpio.o
 obj-$(CONFIG_LEDS_LP3944)  += leds-lp3944.o
 obj-$(CONFIG_LEDS_LP3952)  += leds-lp3952.o
+obj-$(CONFIG_LEDS_LP50XX)  += leds-lp50xx.o
 obj-$(CONFIG_LEDS_LP55XX_COMMON)   += leds-lp55xx-common.o
 obj-$(CONFIG_LEDS_LP5521)  += leds-lp5521.o
 obj-$(CONFIG_LEDS_LP5523)  += leds-lp5523.o
diff --git a/drivers/leds/leds-lp50xx.c b/drivers/leds/leds-lp50xx.c
new file mode 100644
index ..a404a9bf9753
--- /dev/null
+++ b/drivers/leds/leds-lp50xx.c
@@ -0,0 +1,784 @@
+// SPDX-License-Identifier: GPL-2.0
+// TI LP50XX LED chip family driver
+// Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define LP50XX_DEV_CFG00x00
+#define LP50XX_DEV_CFG10x01
+#define LP50XX_LED_CFG00x02
+
+/* LP5009 and LP5012 registers */
+#define LP5012_BNK_BRT 0x03
+#define LP5012_BNKA_CLR0x04
+#define LP5012_BNKB_CLR0x05
+#define LP5012_BNKC_CLR0x06
+#define LP5012_LED0_BRT0x07
+#define LP5012_LED1_BRT0x08
+#define LP5012_LED2_BRT0x09
+#define LP5012_LED3_BRT0x0a
+#define LP5012_OUT0_CLR0x0b
+#define LP5012_OUT1_CLR0x0c
+#define LP5012_OUT2_CLR0x0d
+#define LP5012_OUT3_CLR0x0e
+#define LP5012_OUT4_CLR0x0f
+#define LP5012_OUT5_CLR0x10
+#define LP5012_OUT6_CLR0x11
+#define LP5012_OUT7_CLR0x12
+#define LP5012_OUT8_CLR0x13
+#define LP5012_OUT9_CLR0x14
+#define LP5012_OUT10_CLR   0x15
+#define LP5012_OUT11_CLR   0x16
+#define LP5012_RESET   0x17
+
+/* LP5018 and LP5024 registers */
+#define LP5024_BNK_BRT 0x03
+#define LP5024_BNKA_CLR0x04
+#define LP5024_BNKB_CLR0x05
+#define LP5024_BNKC_CLR0x06
+#define LP5024_LED0_BRT0x07
+#define LP5024_LED1_BRT0x08
+#define LP5024_LED2_BRT0x09
+#define LP5024_LED3_BRT0x0a
+#define LP5024_LED4_BRT0x0b
+#define LP5024_LED5_BRT0x0c
+#define LP5024_LED6_BRT0x0d
+#define LP5024_LED7_BRT0x0e
+
+#define LP5024_OUT0_CLR0x0f
+#define LP5024_OUT1_CLR0x10
+#define LP5024_OUT2_CLR0x11
+#define LP5024_OUT3_CLR0x12
+#define LP5024_OUT4_CLR0x13
+#define LP5024_OUT5_CLR0x14
+#define LP5024_OUT6_CLR0x15
+#define LP5024_OUT7_CLR0x16
+#define LP5024_OUT8_CLR0x17
+#define LP5024_OUT9_CLR0x18
+#define LP5024_OUT10_CLR   0x19
+#define LP5024_OUT11_CLR   0x1a