Re: [PATCH 08/10] leds: Add LM3633 driver

2014-02-14 Thread Mark Rutland
On Fri, Feb 14, 2014 at 06:32:20AM +, Milo Kim wrote:
> LM3633 LED driver supports generic LED functions and pattern generation.
> Pattern is generated by using LMU effect driver APIs.
> Sysfs documentation is added.
> 
> Cc: Bryan Wu 
> Signed-off-by: Milo Kim 
> ---
>  Documentation/leds/leds-lm3633.txt |   38 +++
>  drivers/leds/Kconfig   |   10 +
>  drivers/leds/Makefile  |1 +
>  drivers/leds/leds-lm3633.c |  661 
> 
>  4 files changed, 710 insertions(+)
>  create mode 100644 Documentation/leds/leds-lm3633.txt
>  create mode 100644 drivers/leds/leds-lm3633.c

[...]

> +static int lm3633_led_parse_dt(struct device *dev, struct ti_lmu *lmu)
> +{
> +   struct ti_lmu_led_platform_data *pdata;
> +   struct device_node *node = dev->of_node;
> +   struct device_node *child;
> +   int num_leds;
> +   int i = 0;
> +   u8 imax_mA;
> +
> +   if (!node) {
> +   dev_err(dev, "No device node exists\n");
> +   return -ENODEV;
> +   }
> +
> +   num_leds = of_get_child_count(node);
> +   if (num_leds == 0) {
> +   dev_err(dev, "No LED channels\n");
> +   return -EINVAL;
> +   }
> +
> +   pdata = devm_kzalloc(dev, sizeof(*pdata) * num_leds, GFP_KERNEL);
> +   if (!pdata)
> +   return -ENOMEM;
> +
> +   for_each_child_of_node(node, child) {
> +   of_property_read_string(child, "chan-name", [i].name);

What if this is missing from a node.?

> +
> +   /* Make LED strings */
> +   pdata[i].led_string = 0;
> +   if (of_find_property(child, "lvled1-used", NULL))
> +   pdata[i].led_string |= LMU_LVLED1;
> +   if (of_find_property(child, "lvled2-used", NULL))
> +   pdata[i].led_string |= LMU_LVLED2;
> +   if (of_find_property(child, "lvled3-used", NULL))
> +   pdata[i].led_string |= LMU_LVLED3;
> +   if (of_find_property(child, "lvled4-used", NULL))
> +   pdata[i].led_string |= LMU_LVLED4;
> +   if (of_find_property(child, "lvled5-used", NULL))
> +   pdata[i].led_string |= LMU_LVLED5;
> +   if (of_find_property(child, "lvled6-used", NULL))
> +   pdata[i].led_string |= LMU_LVLED6;

You can use of_property_read_bool for these.

> +
> +   of_property_read_u8(child, "max-current-milliamp", _mA);
> +   pdata[i].imax = ti_lmu_get_current_code(imax_mA);

What happens if this is missing from a node?

Cheers,
Mark.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 08/10] leds: Add LM3633 driver

2014-02-14 Thread Mark Rutland
On Fri, Feb 14, 2014 at 06:32:20AM +, Milo Kim wrote:
 LM3633 LED driver supports generic LED functions and pattern generation.
 Pattern is generated by using LMU effect driver APIs.
 Sysfs documentation is added.
 
 Cc: Bryan Wu coolo...@gmail.com
 Signed-off-by: Milo Kim milo@ti.com
 ---
  Documentation/leds/leds-lm3633.txt |   38 +++
  drivers/leds/Kconfig   |   10 +
  drivers/leds/Makefile  |1 +
  drivers/leds/leds-lm3633.c |  661 
 
  4 files changed, 710 insertions(+)
  create mode 100644 Documentation/leds/leds-lm3633.txt
  create mode 100644 drivers/leds/leds-lm3633.c

[...]

 +static int lm3633_led_parse_dt(struct device *dev, struct ti_lmu *lmu)
 +{
 +   struct ti_lmu_led_platform_data *pdata;
 +   struct device_node *node = dev-of_node;
 +   struct device_node *child;
 +   int num_leds;
 +   int i = 0;
 +   u8 imax_mA;
 +
 +   if (!node) {
 +   dev_err(dev, No device node exists\n);
 +   return -ENODEV;
 +   }
 +
 +   num_leds = of_get_child_count(node);
 +   if (num_leds == 0) {
 +   dev_err(dev, No LED channels\n);
 +   return -EINVAL;
 +   }
 +
 +   pdata = devm_kzalloc(dev, sizeof(*pdata) * num_leds, GFP_KERNEL);
 +   if (!pdata)
 +   return -ENOMEM;
 +
 +   for_each_child_of_node(node, child) {
 +   of_property_read_string(child, chan-name, pdata[i].name);

What if this is missing from a node.?

 +
 +   /* Make LED strings */
 +   pdata[i].led_string = 0;
 +   if (of_find_property(child, lvled1-used, NULL))
 +   pdata[i].led_string |= LMU_LVLED1;
 +   if (of_find_property(child, lvled2-used, NULL))
 +   pdata[i].led_string |= LMU_LVLED2;
 +   if (of_find_property(child, lvled3-used, NULL))
 +   pdata[i].led_string |= LMU_LVLED3;
 +   if (of_find_property(child, lvled4-used, NULL))
 +   pdata[i].led_string |= LMU_LVLED4;
 +   if (of_find_property(child, lvled5-used, NULL))
 +   pdata[i].led_string |= LMU_LVLED5;
 +   if (of_find_property(child, lvled6-used, NULL))
 +   pdata[i].led_string |= LMU_LVLED6;

You can use of_property_read_bool for these.

 +
 +   of_property_read_u8(child, max-current-milliamp, imax_mA);
 +   pdata[i].imax = ti_lmu_get_current_code(imax_mA);

What happens if this is missing from a node?

Cheers,
Mark.
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 08/10] leds: Add LM3633 driver

2014-02-13 Thread Milo Kim
LM3633 LED driver supports generic LED functions and pattern generation.
Pattern is generated by using LMU effect driver APIs.
Sysfs documentation is added.

Cc: Bryan Wu 
Signed-off-by: Milo Kim 
---
 Documentation/leds/leds-lm3633.txt |   38 +++
 drivers/leds/Kconfig   |   10 +
 drivers/leds/Makefile  |1 +
 drivers/leds/leds-lm3633.c |  661 
 4 files changed, 710 insertions(+)
 create mode 100644 Documentation/leds/leds-lm3633.txt
 create mode 100644 drivers/leds/leds-lm3633.c

diff --git a/Documentation/leds/leds-lm3633.txt 
b/Documentation/leds/leds-lm3633.txt
new file mode 100644
index 000..a5a59c3
--- /dev/null
+++ b/Documentation/leds/leds-lm3633.txt
@@ -0,0 +1,38 @@
+LM3633 LED Driver
+=
+
+LM3633 LED driver supports not only LED functions but also programmable 
pattern.
+A pattern is generated via the sysfs.
+
+LED Pattern Generator
+
+(3)
+  (a) --->  ___
+   /   \
+  (2) / \ (4)
+  (b) > _/   \_  ...
+   (1)   (5)
+
+ |<-   period   -> |
+
+  Time dimension
+(1) delay : 0 ~ 10 sec
+(2) rise  : 0 ~ 16 sec
+(3) high  : 0 ~ 10 sec
+(4) fall  : 0 ~ 16 sec
+(5) low   : 0 ~ 16 sec
+
+  Level dimension - channel current
+(a) low   : 0 ~ 255
+(b) high  : 0 ~ 255
+
+Example)
+Time  : No delay, rise 500ms, high 1000ms, fall 400ms, low 2000ms
+Level : Brightness 0 and 255
+
+echo 0 500 1000 400 2000 > /sys/class/leds//pattern_times
+echo 0 255 >  /sys/class/leds//pattern_levels
+echo 1 >  /sys/class/leds//run_pattern
+
+To stop running pattern,
+echo 0 >  /sys/class/leds//run_pattern
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 72156c1..ed659be 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -63,6 +63,16 @@ config LEDS_LM3533
  hardware-accelerated blinking with maximum on and off periods of 9.8
  and 77 seconds respectively.
 
+config LEDS_LM3633
+   tristate "LED support for the TI LM3633 LMU"
+   depends on LEDS_CLASS
+   depends on MFD_TI_LMU
+   help
+ This option enables support for the LEDs on the LM3633.
+ LM3633 has 6 low voltage indicator LEDs.
+ All low voltage current sinks can have a programmable pattern
+ modulated onto LED output strings.
+
 config LEDS_LM3642
tristate "LED support for LM3642 Chip"
depends on LEDS_CLASS && I2C
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 3cd76db..96f55fe 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -11,6 +11,7 @@ obj-$(CONFIG_LEDS_BD2802) += leds-bd2802.o
 obj-$(CONFIG_LEDS_LOCOMO)  += leds-locomo.o
 obj-$(CONFIG_LEDS_LM3530)  += leds-lm3530.o
 obj-$(CONFIG_LEDS_LM3533)  += leds-lm3533.o
+obj-$(CONFIG_LEDS_LM3633)  += leds-lm3633.o
 obj-$(CONFIG_LEDS_LM3642)  += leds-lm3642.o
 obj-$(CONFIG_LEDS_MIKROTIK_RB532)  += leds-rb532.o
 obj-$(CONFIG_LEDS_S3C24XX) += leds-s3c24xx.o
diff --git a/drivers/leds/leds-lm3633.c b/drivers/leds/leds-lm3633.c
new file mode 100644
index 000..13a43bf
--- /dev/null
+++ b/drivers/leds/leds-lm3633.c
@@ -0,0 +1,661 @@
+/*
+ * TI LM3633 LED driver
+ *
+ * Copyright 2014 Texas Instruments
+ *
+ * Author: Milo Kim 
+ *
+ * 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.
+ *
+ * LM3633 LED driver has features below.
+ *
+ *   - Generic LED subsystem control
+ *   - LED string configuration
+ *   - Pattern programming via the sysfs
+ *   - Platform data configuration from the device tree nodes
+ *
+ * Pattern generated by using LMU effect driver APIs.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define LM3633_LED_MAX_BRIGHTNESS  255
+#define LM3633_DEFAULT_LED_NAME"indicator"
+
+enum lm3633_led_bank_id {
+   LM3633_LED_BANK_C,
+   LM3633_LED_BANK_D,
+   LM3633_LED_BANK_E,
+   LM3633_LED_BANK_F,
+   LM3633_LED_BANK_G,
+   LM3633_LED_BANK_H,
+   LM3633_MAX_LEDS,
+};
+
+struct lm3633_pattern_time {
+   unsigned int delay;
+   unsigned int rise;
+   unsigned int high;
+   unsigned int fall;
+   unsigned int low;
+};
+
+struct lm3633_pattern_level {
+   u8 low;
+   u8 high;
+};
+
+/* One LED chip can have multiple LED strings (max: 6) */
+struct ti_lmu_led_chip {
+   struct device *dev;
+   struct ti_lmu *lmu;
+   struct mutex lock;
+   int num_leds;
+};
+
+/* LED string structure */
+struct ti_lmu_led {
+   enum lm3633_led_bank_id bank_id;
+
+   struct led_classdev cdev;
+ 

[PATCH 08/10] leds: Add LM3633 driver

2014-02-13 Thread Milo Kim
LM3633 LED driver supports generic LED functions and pattern generation.
Pattern is generated by using LMU effect driver APIs.
Sysfs documentation is added.

Cc: Bryan Wu coolo...@gmail.com
Signed-off-by: Milo Kim milo@ti.com
---
 Documentation/leds/leds-lm3633.txt |   38 +++
 drivers/leds/Kconfig   |   10 +
 drivers/leds/Makefile  |1 +
 drivers/leds/leds-lm3633.c |  661 
 4 files changed, 710 insertions(+)
 create mode 100644 Documentation/leds/leds-lm3633.txt
 create mode 100644 drivers/leds/leds-lm3633.c

diff --git a/Documentation/leds/leds-lm3633.txt 
b/Documentation/leds/leds-lm3633.txt
new file mode 100644
index 000..a5a59c3
--- /dev/null
+++ b/Documentation/leds/leds-lm3633.txt
@@ -0,0 +1,38 @@
+LM3633 LED Driver
+=
+
+LM3633 LED driver supports not only LED functions but also programmable 
pattern.
+A pattern is generated via the sysfs.
+
+LED Pattern Generator
+
+(3)
+  (a) ---  ___
+   /   \
+  (2) / \ (4)
+  (b)  _/   \_  ...
+   (1)   (5)
+
+ |-   period   - |
+
+  Time dimension
+(1) delay : 0 ~ 10 sec
+(2) rise  : 0 ~ 16 sec
+(3) high  : 0 ~ 10 sec
+(4) fall  : 0 ~ 16 sec
+(5) low   : 0 ~ 16 sec
+
+  Level dimension - channel current
+(a) low   : 0 ~ 255
+(b) high  : 0 ~ 255
+
+Example)
+Time  : No delay, rise 500ms, high 1000ms, fall 400ms, low 2000ms
+Level : Brightness 0 and 255
+
+echo 0 500 1000 400 2000  /sys/class/leds/LED NAME/pattern_times
+echo 0 255   /sys/class/leds/LED NAME/pattern_levels
+echo 1   /sys/class/leds/LED NAME/run_pattern
+
+To stop running pattern,
+echo 0   /sys/class/leds/LED NAME/run_pattern
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 72156c1..ed659be 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -63,6 +63,16 @@ config LEDS_LM3533
  hardware-accelerated blinking with maximum on and off periods of 9.8
  and 77 seconds respectively.
 
+config LEDS_LM3633
+   tristate LED support for the TI LM3633 LMU
+   depends on LEDS_CLASS
+   depends on MFD_TI_LMU
+   help
+ This option enables support for the LEDs on the LM3633.
+ LM3633 has 6 low voltage indicator LEDs.
+ All low voltage current sinks can have a programmable pattern
+ modulated onto LED output strings.
+
 config LEDS_LM3642
tristate LED support for LM3642 Chip
depends on LEDS_CLASS  I2C
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 3cd76db..96f55fe 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -11,6 +11,7 @@ obj-$(CONFIG_LEDS_BD2802) += leds-bd2802.o
 obj-$(CONFIG_LEDS_LOCOMO)  += leds-locomo.o
 obj-$(CONFIG_LEDS_LM3530)  += leds-lm3530.o
 obj-$(CONFIG_LEDS_LM3533)  += leds-lm3533.o
+obj-$(CONFIG_LEDS_LM3633)  += leds-lm3633.o
 obj-$(CONFIG_LEDS_LM3642)  += leds-lm3642.o
 obj-$(CONFIG_LEDS_MIKROTIK_RB532)  += leds-rb532.o
 obj-$(CONFIG_LEDS_S3C24XX) += leds-s3c24xx.o
diff --git a/drivers/leds/leds-lm3633.c b/drivers/leds/leds-lm3633.c
new file mode 100644
index 000..13a43bf
--- /dev/null
+++ b/drivers/leds/leds-lm3633.c
@@ -0,0 +1,661 @@
+/*
+ * TI LM3633 LED driver
+ *
+ * Copyright 2014 Texas Instruments
+ *
+ * Author: Milo Kim milo@ti.com
+ *
+ * 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.
+ *
+ * LM3633 LED driver has features below.
+ *
+ *   - Generic LED subsystem control
+ *   - LED string configuration
+ *   - Pattern programming via the sysfs
+ *   - Platform data configuration from the device tree nodes
+ *
+ * Pattern generated by using LMU effect driver APIs.
+ *
+ */
+
+#include linux/leds.h
+#include linux/mfd/ti-lmu.h
+#include linux/mfd/ti-lmu-effect.h
+#include linux/mfd/ti-lmu-register.h
+#include linux/module.h
+#include linux/mutex.h
+#include linux/of.h
+#include linux/platform_device.h
+#include linux/slab.h
+
+#define LM3633_LED_MAX_BRIGHTNESS  255
+#define LM3633_DEFAULT_LED_NAMEindicator
+
+enum lm3633_led_bank_id {
+   LM3633_LED_BANK_C,
+   LM3633_LED_BANK_D,
+   LM3633_LED_BANK_E,
+   LM3633_LED_BANK_F,
+   LM3633_LED_BANK_G,
+   LM3633_LED_BANK_H,
+   LM3633_MAX_LEDS,
+};
+
+struct lm3633_pattern_time {
+   unsigned int delay;
+   unsigned int rise;
+   unsigned int high;
+   unsigned int fall;
+   unsigned int low;
+};
+
+struct lm3633_pattern_level {
+   u8 low;
+   u8 high;
+};
+
+/* One LED chip can have multiple LED strings (max: 6) */
+struct ti_lmu_led_chip {
+   struct