* [PATCH RFC 0/3] leds: add SN3218 LED driver @ 2016-01-28 20:41 Stefan Wahren [not found] ` <1454013667-25889-1-git-send-email-stefan.wahren-eS4NqCHxEME@public.gmane.org> 2016-01-28 20:41 ` [PATCH RFC 2/3] DT: add binding for " Stefan Wahren 0 siblings, 2 replies; 7+ messages in thread From: Stefan Wahren @ 2016-01-28 20:41 UTC (permalink / raw) To: Richard Purdie, Jacek Anaszewski, Rob Herring, Mark Rutland Cc: devicetree, linux-kernel, linux-leds, Stefan Wahren This patch series implements support for the Si-En SN3218 18 Channel LED Driver through I2C. This implemention only write data over I2C und get the platform data via DT. The driver has been tested on a Raspberry Pi B. Stefan Wahren (3): of: Add vendor prefix for Si-En Technology DT: add binding for SN3218 LED driver leds: add SN3218 LED driver .../devicetree/bindings/leds/leds-sn3218.txt | 41 ++++ .../devicetree/bindings/vendor-prefixes.txt | 1 + drivers/leds/Kconfig | 8 + drivers/leds/Makefile | 1 + drivers/leds/leds-sn3218.c | 254 ++++++++++++++++++++ 5 files changed, 305 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-sn3218.txt create mode 100644 drivers/leds/leds-sn3218.c -- 1.7.9.5 ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <1454013667-25889-1-git-send-email-stefan.wahren-eS4NqCHxEME@public.gmane.org>]
* [PATCH RFC 1/3] of: Add vendor prefix for Si-En Technology [not found] ` <1454013667-25889-1-git-send-email-stefan.wahren-eS4NqCHxEME@public.gmane.org> @ 2016-01-28 20:41 ` Stefan Wahren [not found] ` <1454013667-25889-2-git-send-email-stefan.wahren-eS4NqCHxEME@public.gmane.org> 2016-01-28 20:41 ` [PATCH RFC 3/3] leds: add SN3218 LED driver Stefan Wahren 1 sibling, 1 reply; 7+ messages in thread From: Stefan Wahren @ 2016-01-28 20:41 UTC (permalink / raw) To: Richard Purdie, Jacek Anaszewski, Rob Herring, Mark Rutland Cc: devicetree-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, linux-leds-u79uwXL29TY76Z2rM5mHXA, Stefan Wahren Si-En Technology is a fabless design house which offers audio amplifiers, LED drivers and sensors. Signed-off-by: Stefan Wahren <stefan.wahren-eS4NqCHxEME@public.gmane.org> --- .../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 72e2c5a..52f22f9 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.txt +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt @@ -204,6 +204,7 @@ seagate Seagate Technology PLC semtech Semtech Corporation sgx SGX Sensortech sharp Sharp Corporation +si-en Si-En Technology Ltd. sigma Sigma Designs, Inc. sil Silicon Image silabs Silicon Laboratories -- 1.7.9.5 -- 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 related [flat|nested] 7+ messages in thread
[parent not found: <1454013667-25889-2-git-send-email-stefan.wahren-eS4NqCHxEME@public.gmane.org>]
* Re: [PATCH RFC 1/3] of: Add vendor prefix for Si-En Technology [not found] ` <1454013667-25889-2-git-send-email-stefan.wahren-eS4NqCHxEME@public.gmane.org> @ 2016-01-29 3:27 ` Rob Herring 0 siblings, 0 replies; 7+ messages in thread From: Rob Herring @ 2016-01-29 3:27 UTC (permalink / raw) To: Stefan Wahren Cc: Richard Purdie, Jacek Anaszewski, Mark Rutland, devicetree-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, linux-leds-u79uwXL29TY76Z2rM5mHXA On Thu, Jan 28, 2016 at 08:41:05PM +0000, Stefan Wahren wrote: > Si-En Technology is a fabless design house which offers > audio amplifiers, LED drivers and sensors. > > Signed-off-by: Stefan Wahren <stefan.wahren-eS4NqCHxEME@public.gmane.org> > --- > .../devicetree/bindings/vendor-prefixes.txt | 1 + > 1 file changed, 1 insertion(+) Acked-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> -- 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] 7+ messages in thread
* [PATCH RFC 3/3] leds: add SN3218 LED driver [not found] ` <1454013667-25889-1-git-send-email-stefan.wahren-eS4NqCHxEME@public.gmane.org> 2016-01-28 20:41 ` [PATCH RFC 1/3] of: Add vendor prefix for Si-En Technology Stefan Wahren @ 2016-01-28 20:41 ` Stefan Wahren 2016-01-29 12:54 ` Jacek Anaszewski 1 sibling, 1 reply; 7+ messages in thread From: Stefan Wahren @ 2016-01-28 20:41 UTC (permalink / raw) To: Richard Purdie, Jacek Anaszewski, Rob Herring, Mark Rutland Cc: devicetree-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, linux-leds-u79uwXL29TY76Z2rM5mHXA, Stefan Wahren This patch adds support for Si-En SN3218 18 Channel LED Driver. Signed-off-by: Stefan Wahren <stefan.wahren-eS4NqCHxEME@public.gmane.org> --- drivers/leds/Kconfig | 8 ++ drivers/leds/Makefile | 1 + drivers/leds/leds-sn3218.c | 254 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 263 insertions(+) create mode 100644 drivers/leds/leds-sn3218.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 7f940c2..4a1bb4e 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -568,6 +568,14 @@ 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 + help + This option enables support for the Si-EN SN3218 LED driver + through I2C. Say Y to enable support for the SN3218 LED. + 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 e9d5309..89c9b6f 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -66,6 +66,7 @@ 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 # LED SPI Drivers obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o diff --git a/drivers/leds/leds-sn3218.c b/drivers/leds/leds-sn3218.c new file mode 100644 index 0000000..f52e7cc --- /dev/null +++ b/drivers/leds/leds-sn3218.c @@ -0,0 +1,254 @@ +/* + * Si-En SN3218 18 Channel LED Driver + * + * Copyright (C) 2016 Stefan Wahren <stefan.wahren-eS4NqCHxEME@public.gmane.org> + * + * 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/mutex.h> +#include <linux/of.h> +#include <linux/slab.h> + +#define SN3218_MODE 0x00 +#define SN3218_PWM_BASE 0x01 +#define SN3218_LED_BASE 0x13 /* 6 channels per reg */ +#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 NUM_LEDS 18 + +static const struct i2c_device_id sn3218_id[] = { + { "sn3218", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, sn3218_id); + +struct sn3218_led; + +/** + * struct sn3218 - + * @lock - Lock for writing the device + * @client - Pointer to the I2C client + * @leds - Pointer to the individual LEDs + * @leds_state - Copy of LED CTRL registers +**/ +struct sn3218 { + struct mutex lock; + struct i2c_client *client; + struct sn3218_led *leds; + u8 leds_state[3]; +}; + +/** + * struct sn3218_led - + * @chip - Pointer to the container + * @led_cdev - led class device pointer + * @led_num - LED index ( 0 .. 17 ) + * @name - LED name +**/ +struct sn3218_led { + struct sn3218 *chip; + struct led_classdev led_cdev; + int led_num; + char name[32]; +}; + +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 i2c_client *client = led->chip->client; + u8 bank = led->led_num / 6; + u8 mask = 0x1 << (led->led_num % 6); + int ret; + + mutex_lock(&led->chip->lock); + + if (brightness == LED_OFF) + led->chip->leds_state[bank] &= ~mask; + else + led->chip->leds_state[bank] |= mask; + + ret = i2c_smbus_write_byte_data(client, SN3218_LED_BASE + bank, + led->chip->leds_state[bank]); + if (ret < 0) + goto unlock; + + if (brightness > LED_OFF) { + ret = i2c_smbus_write_byte_data(client, + SN3218_PWM_BASE + led->led_num, brightness); + if (ret < 0) + goto unlock; + } + + ret = i2c_smbus_write_byte_data(client, SN3218_UPDATE, 0xFF); + +unlock: + mutex_unlock(&led->chip->lock); + return ret; +} + +static struct led_platform_data *sn3218_init(struct i2c_client *client) +{ + struct device_node *np = client->dev.of_node, *child; + struct led_platform_data *pdata; + struct led_info *sn3218_leds; + int count; + + count = of_get_child_count(np); + if (!count || count > NUM_LEDS) + return NULL; + + sn3218_leds = devm_kzalloc(&client->dev, + sizeof(struct led_info) * NUM_LEDS, GFP_KERNEL); + if (!sn3218_leds) + return NULL; + + for_each_child_of_node(np, child) { + struct led_info led = {}; + u32 reg; + int ret; + + ret = of_property_read_u32(child, "reg", ®); + if (ret != 0 || reg < 0 || reg >= NUM_LEDS) + continue; + led.name = + of_get_property(child, "label", NULL) ? : child->name; + led.default_trigger = + of_get_property(child, "linux,default-trigger", NULL); + sn3218_leds[reg] = led; + } + + pdata = devm_kzalloc(&client->dev, sizeof(struct led_platform_data), + GFP_KERNEL); + + pdata->leds = sn3218_leds; + pdata->num_leds = NUM_LEDS; + + return pdata; +} + +static const struct of_device_id of_sn3218_match[] = { + { .compatible = "si-en,sn3218", }, + {}, +}; +MODULE_DEVICE_TABLE(of, of_sn3218_match); + +static int sn3218_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct led_platform_data *pdata; + struct sn3218 *sn3218_chip; + struct sn3218_led *sn3218; + int i, ret; + + pdata = sn3218_init(client); + if (IS_ERR(pdata)) + return PTR_ERR(pdata); + + sn3218_chip = devm_kzalloc(&client->dev, sizeof(*sn3218_chip), + GFP_KERNEL); + if (!sn3218_chip) + return -ENOMEM; + + sn3218 = devm_kzalloc(&client->dev, NUM_LEDS * sizeof(*sn3218), + GFP_KERNEL); + if (!sn3218) + return -ENOMEM; + + i2c_set_clientdata(client, sn3218_chip); + + mutex_init(&sn3218_chip->lock); + sn3218_chip->client = client; + sn3218_chip->leds = sn3218; + + for (i = 0; i < NUM_LEDS; i++) { + sn3218[i].led_num = i; + sn3218[i].chip = sn3218_chip; + + if (i < pdata->num_leds) { + if (pdata->leds[i].name) + snprintf(sn3218[i].name, + sizeof(sn3218[i].name), "sn3218:%s", + pdata->leds[i].name); + if (pdata->leds[i].default_trigger) + sn3218[i].led_cdev.default_trigger = + pdata->leds[i].default_trigger; + } + + if (i >= pdata->num_leds || !pdata->leds[i].name) { + snprintf(sn3218[i].name, sizeof(sn3218[i].name), + "sn3218:%d:%.2x:%d", client->adapter->nr, + client->addr, i); + } + + sn3218[i].led_cdev.name = sn3218[i].name; + sn3218[i].led_cdev.brightness_set_blocking = sn3218_led_set; + sn3218[i].led_cdev.max_brightness = LED_FULL; + + ret = led_classdev_register(&client->dev, &sn3218[i].led_cdev); + if (ret < 0) + goto exit; + } + + /* Reset chip to default, all LEDs off */ + i2c_smbus_write_byte_data(client, SN3218_RESET, 0xFF); + + /* Set normal mode */ + i2c_smbus_write_byte_data(client, SN3218_MODE, 0x01); + + return 0; + +exit: + while (i--) + led_classdev_unregister(&sn3218[i].led_cdev); + + return ret; +} + +static int sn3218_remove(struct i2c_client *client) +{ + struct sn3218 *sn3218 = i2c_get_clientdata(client); + int i; + + for (i = 0; i < NUM_LEDS; i++) + led_classdev_unregister(&sn3218->leds[i].led_cdev); + + /* Set shutdown mode */ + i2c_smbus_write_byte_data(client, SN3218_MODE, 0x00); + + return 0; +} + +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, + .id_table = sn3218_id, +}; + +module_i2c_driver(sn3218_driver); + +MODULE_DESCRIPTION("Si-En SN3218 LED Driver"); +MODULE_AUTHOR("Stefan Wahren <stefan.wahren-eS4NqCHxEME@public.gmane.org>"); +MODULE_LICENSE("GPL"); -- 1.7.9.5 -- 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 related [flat|nested] 7+ messages in thread
* Re: [PATCH RFC 3/3] leds: add SN3218 LED driver 2016-01-28 20:41 ` [PATCH RFC 3/3] leds: add SN3218 LED driver Stefan Wahren @ 2016-01-29 12:54 ` Jacek Anaszewski 0 siblings, 0 replies; 7+ messages in thread From: Jacek Anaszewski @ 2016-01-29 12:54 UTC (permalink / raw) To: Stefan Wahren Cc: Richard Purdie, Rob Herring, Mark Rutland, devicetree, linux-kernel, linux-leds Hi Stefan, Thanks for the patch. Please find my comments in the code below. On 01/28/2016 09:41 PM, Stefan Wahren wrote: > This patch adds support for Si-En SN3218 18 Channel LED Driver. > > Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com> > --- > drivers/leds/Kconfig | 8 ++ > drivers/leds/Makefile | 1 + > drivers/leds/leds-sn3218.c | 254 ++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 263 insertions(+) > create mode 100644 drivers/leds/leds-sn3218.c > > diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig > index 7f940c2..4a1bb4e 100644 > --- a/drivers/leds/Kconfig > +++ b/drivers/leds/Kconfig > @@ -568,6 +568,14 @@ 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 > + help > + This option enables support for the Si-EN SN3218 LED driver > + through I2C. Say Y to enable support for the SN3218 LED. s/through/connected through/ > + > 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 e9d5309..89c9b6f 100644 > --- a/drivers/leds/Makefile > +++ b/drivers/leds/Makefile > @@ -66,6 +66,7 @@ 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 > > # LED SPI Drivers > obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o > diff --git a/drivers/leds/leds-sn3218.c b/drivers/leds/leds-sn3218.c > new file mode 100644 > index 0000000..f52e7cc > --- /dev/null > +++ b/drivers/leds/leds-sn3218.c > @@ -0,0 +1,254 @@ > +/* > + * 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/mutex.h> > +#include <linux/of.h> > +#include <linux/slab.h> > + > +#define SN3218_MODE 0x00 > +#define SN3218_PWM_BASE 0x01 > +#define SN3218_LED_BASE 0x13 /* 6 channels per reg */ > +#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 NUM_LEDS 18 > + > +static const struct i2c_device_id sn3218_id[] = { > + { "sn3218", 0 }, > + { } > +}; > +MODULE_DEVICE_TABLE(i2c, sn3218_id); Please put the above i2c_device_id definition at the end of file, similarly to e.g. drivers/leds/leds-lp5523.c. > + > +struct sn3218_led; > + > +/** > + * struct sn3218 - > + * @lock - Lock for writing the device > + * @client - Pointer to the I2C client > + * @leds - Pointer to the individual LEDs > + * @leds_state - Copy of LED CTRL registers > +**/ > +struct sn3218 { > + struct mutex lock; > + struct i2c_client *client; > + struct sn3218_led *leds; > + u8 leds_state[3]; > +}; > + > +/** > + * struct sn3218_led - > + * @chip - Pointer to the container > + * @led_cdev - led class device pointer > + * @led_num - LED index ( 0 .. 17 ) > + * @name - LED name > +**/ > +struct sn3218_led { > + struct sn3218 *chip; > + struct led_classdev led_cdev; > + int led_num; > + char name[32]; You don't need to cache the LED name - it is required only during LED class device registration. Just assign the pointer to led_cdev->name. > +}; > + > +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 i2c_client *client = led->chip->client; > + u8 bank = led->led_num / 6; > + u8 mask = 0x1 << (led->led_num % 6); > + int ret; > + > + mutex_lock(&led->chip->lock); > + > + if (brightness == LED_OFF) > + led->chip->leds_state[bank] &= ~mask; > + else > + led->chip->leds_state[bank] |= mask; If you used regmap you could get rid of led_state, as you'd have the caching for free. Please check regmap_update_bits(). > + ret = i2c_smbus_write_byte_data(client, SN3218_LED_BASE + bank, > + led->chip->leds_state[bank]); This should be switched to regmap_write then. > + if (ret < 0) > + goto unlock; > + > + if (brightness > LED_OFF) { > + ret = i2c_smbus_write_byte_data(client, > + SN3218_PWM_BASE + led->led_num, brightness); > + if (ret < 0) > + goto unlock; > + } > + > + ret = i2c_smbus_write_byte_data(client, SN3218_UPDATE, 0xFF); > + > +unlock: > + mutex_unlock(&led->chip->lock); > + return ret; > +} > + > +static struct led_platform_data *sn3218_init(struct i2c_client *client) > +{ > + struct device_node *np = client->dev.of_node, *child; > + struct led_platform_data *pdata; > + struct led_info *sn3218_leds; > + int count; > + > + count = of_get_child_count(np); > + if (!count || count > NUM_LEDS) > + return NULL; > + > + sn3218_leds = devm_kzalloc(&client->dev, > + sizeof(struct led_info) * NUM_LEDS, GFP_KERNEL); Please don't use struct led_info and struct led_platform_data. You can assign parsed data directly to the struct sn3218_led and its member - led_cdev. It could be allocated in sn3218_probe() and passed here as an argument. Return type could be switched to int (error code) then. I'd also allocate a memory only for the number of LEDs defined in the DT ("count" in this case). > + if (!sn3218_leds) > + return NULL; > + > + for_each_child_of_node(np, child) { > + struct led_info led = {}; > + u32 reg; > + int ret; > + > + ret = of_property_read_u32(child, "reg", ®); > + if (ret != 0 || reg < 0 || reg >= NUM_LEDS) > + continue; I'd prefer to fail in case of DT validation error. Please keep in mind that before breaking the loop we have to release the child by calling of_node_put(). > + led.name = > + of_get_property(child, "label", NULL) ? : child->name; > + led.default_trigger = > + of_get_property(child, "linux,default-trigger", NULL); > + sn3218_leds[reg] = led; > + } > + > + pdata = devm_kzalloc(&client->dev, sizeof(struct led_platform_data), > + GFP_KERNEL); > + > + pdata->leds = sn3218_leds; > + pdata->num_leds = NUM_LEDS; > + > + return pdata; > +} > + > +static const struct of_device_id of_sn3218_match[] = { > + { .compatible = "si-en,sn3218", }, > + {}, > +}; > +MODULE_DEVICE_TABLE(of, of_sn3218_match); Please put it at the end of file. > + > +static int sn3218_probe(struct i2c_client *client, > + const struct i2c_device_id *id) > +{ > + struct led_platform_data *pdata; > + struct sn3218 *sn3218_chip; > + struct sn3218_led *sn3218; > + int i, ret; > + > + pdata = sn3218_init(client); > + if (IS_ERR(pdata)) > + return PTR_ERR(pdata); > + > + sn3218_chip = devm_kzalloc(&client->dev, sizeof(*sn3218_chip), > + GFP_KERNEL); > + if (!sn3218_chip) > + return -ENOMEM; > + > + sn3218 = devm_kzalloc(&client->dev, NUM_LEDS * sizeof(*sn3218), > + GFP_KERNEL); > + if (!sn3218) > + return -ENOMEM; > + > + i2c_set_clientdata(client, sn3218_chip); > + > + mutex_init(&sn3218_chip->lock); > + sn3218_chip->client = client; > + sn3218_chip->leds = sn3218; > + > + for (i = 0; i < NUM_LEDS; i++) { > + sn3218[i].led_num = i; > + sn3218[i].chip = sn3218_chip; > + > + if (i < pdata->num_leds) { > + if (pdata->leds[i].name) > + snprintf(sn3218[i].name, > + sizeof(sn3218[i].name), "sn3218:%s", > + pdata->leds[i].name); > + if (pdata->leds[i].default_trigger) > + sn3218[i].led_cdev.default_trigger = > + pdata->leds[i].default_trigger; > + } > + > + if (i >= pdata->num_leds || !pdata->leds[i].name) { Name will be always not NULL - either pointer to the "label" property or to the child->name. > + snprintf(sn3218[i].name, sizeof(sn3218[i].name), > + "sn3218:%d:%.2x:%d", client->adapter->nr, > + client->addr, i); Just use the string obtained from DT. > + } > + > + sn3218[i].led_cdev.name = sn3218[i].name; > + sn3218[i].led_cdev.brightness_set_blocking = sn3218_led_set; > + sn3218[i].led_cdev.max_brightness = LED_FULL; > + > + ret = led_classdev_register(&client->dev, &sn3218[i].led_cdev); > + if (ret < 0) > + goto exit; Use devm_ prefixed version. > + } > + > + /* Reset chip to default, all LEDs off */ > + i2c_smbus_write_byte_data(client, SN3218_RESET, 0xFF); > + > + /* Set normal mode */ > + i2c_smbus_write_byte_data(client, SN3218_MODE, 0x01); > + > + return 0; > + > +exit: > + while (i--) > + led_classdev_unregister(&sn3218[i].led_cdev); > + > + return ret; > +} > + > +static int sn3218_remove(struct i2c_client *client) > +{ > + struct sn3218 *sn3218 = i2c_get_clientdata(client); > + int i; > + > + for (i = 0; i < NUM_LEDS; i++) > + led_classdev_unregister(&sn3218->leds[i].led_cdev); > + > + /* Set shutdown mode */ > + i2c_smbus_write_byte_data(client, SN3218_MODE, 0x00); > + > + return 0; > +} > + > +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, > + .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"); s/GPL/GPL v2/ - to be in accordance with the statement in the beginning. -- Best Regards, Jacek Anaszewski ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH RFC 2/3] DT: add binding for SN3218 LED driver 2016-01-28 20:41 [PATCH RFC 0/3] leds: add SN3218 LED driver Stefan Wahren [not found] ` <1454013667-25889-1-git-send-email-stefan.wahren-eS4NqCHxEME@public.gmane.org> @ 2016-01-28 20:41 ` Stefan Wahren 2016-01-29 3:26 ` Rob Herring 1 sibling, 1 reply; 7+ messages in thread From: Stefan Wahren @ 2016-01-28 20:41 UTC (permalink / raw) To: Richard Purdie, Jacek Anaszewski, Rob Herring, Mark Rutland Cc: devicetree, linux-kernel, linux-leds, Stefan Wahren This patch adds the binding for Si-En Technology SN3218 18-Channel LED driver. Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com> --- .../devicetree/bindings/leds/leds-sn3218.txt | 41 ++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-sn3218.txt diff --git a/Documentation/devicetree/bindings/leds/leds-sn3218.txt b/Documentation/devicetree/bindings/leds/leds-sn3218.txt new file mode 100644 index 0000000..bf632df --- /dev/null +++ b/Documentation/devicetree/bindings/leds/leds-sn3218.txt @@ -0,0 +1,41 @@ +* 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 + +Each led is represented as a sub-node of the si-en,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@54 { + compatible = "si-en,sn3218"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x54>; + + led1@0 { + label = "led1"; + reg = <0x0>; + }; + + led2@1 { + label = "led2"; + reg = <0x1>; + }; + + led3@2 { + label = "led3"; + reg = <0x2>; + }; +}; + -- 1.7.9.5 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH RFC 2/3] DT: add binding for SN3218 LED driver 2016-01-28 20:41 ` [PATCH RFC 2/3] DT: add binding for " Stefan Wahren @ 2016-01-29 3:26 ` Rob Herring 0 siblings, 0 replies; 7+ messages in thread From: Rob Herring @ 2016-01-29 3:26 UTC (permalink / raw) To: Stefan Wahren Cc: Richard Purdie, Jacek Anaszewski, Mark Rutland, devicetree, linux-kernel, linux-leds On Thu, Jan 28, 2016 at 08:41:06PM +0000, Stefan Wahren wrote: > This patch adds the binding for Si-En Technology SN3218 > 18-Channel LED driver. > > Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com> > --- > .../devicetree/bindings/leds/leds-sn3218.txt | 41 ++++++++++++++++++++ > 1 file changed, 41 insertions(+) > create mode 100644 Documentation/devicetree/bindings/leds/leds-sn3218.txt One nit, otherwise: Acked-by: Rob Herring <robh@kernel.org> > > diff --git a/Documentation/devicetree/bindings/leds/leds-sn3218.txt b/Documentation/devicetree/bindings/leds/leds-sn3218.txt > new file mode 100644 > index 0000000..bf632df > --- /dev/null > +++ b/Documentation/devicetree/bindings/leds/leds-sn3218.txt > @@ -0,0 +1,41 @@ > +* 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 > + > +Each led is represented as a sub-node of the si-en,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@54 { > + compatible = "si-en,sn3218"; > + #address-cells = <1>; > + #size-cells = <0>; > + reg = <0x54>; > + > + led1@0 { Just led@X please. > + label = "led1"; > + reg = <0x0>; > + }; > + > + led2@1 { > + label = "led2"; > + reg = <0x1>; > + }; > + > + led3@2 { > + label = "led3"; > + reg = <0x2>; > + }; > +}; > + > -- > 1.7.9.5 > ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-01-29 12:54 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-01-28 20:41 [PATCH RFC 0/3] leds: add SN3218 LED driver Stefan Wahren [not found] ` <1454013667-25889-1-git-send-email-stefan.wahren-eS4NqCHxEME@public.gmane.org> 2016-01-28 20:41 ` [PATCH RFC 1/3] of: Add vendor prefix for Si-En Technology Stefan Wahren [not found] ` <1454013667-25889-2-git-send-email-stefan.wahren-eS4NqCHxEME@public.gmane.org> 2016-01-29 3:27 ` Rob Herring 2016-01-28 20:41 ` [PATCH RFC 3/3] leds: add SN3218 LED driver Stefan Wahren 2016-01-29 12:54 ` Jacek Anaszewski 2016-01-28 20:41 ` [PATCH RFC 2/3] DT: add binding for " Stefan Wahren 2016-01-29 3:26 ` 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).