From 2491c5c8c99dfcf2519ca73798be60f874a2b16e Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Wed, 11 Sep 2013 21:20:29 -0700 Subject: leds: blinkm: Remove redundant break MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 'break' after return is redundant. Remove it. Signed-off-by: Sachin Kamat Acked-by: Jan-Simon Möller Signed-off-by: Bryan Wu diff --git a/drivers/leds/leds-blinkm.c b/drivers/leds/leds-blinkm.c index a502678..66d0a57 100644 --- a/drivers/leds/leds-blinkm.c +++ b/drivers/leds/leds-blinkm.c @@ -161,13 +161,10 @@ static ssize_t show_color_common(struct device *dev, char *buf, int color) switch (color) { case RED: return scnprintf(buf, PAGE_SIZE, "%02X\n", data->red); - break; case GREEN: return scnprintf(buf, PAGE_SIZE, "%02X\n", data->green); - break; case BLUE: return scnprintf(buf, PAGE_SIZE, "%02X\n", data->blue); - break; default: return -EINVAL; } -- cgit v0.10.2 From f65f0a1a9836abbfbe5c9b8fa0452e4d8eb7bf00 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Sun, 15 Sep 2013 03:50:17 -0700 Subject: leds: lp55xx: enable setting default trigger This enables setting a default trigger on an LP55xx channel, either from platform data or device tree. This mechanism is identical to the mechanism for GPIO LEDs and references the common LEDs device tree bindings. Signed-off-by: Linus Walleij Tested-by: Milo Kim Acked-by: Milo Kim Signed-off-by: Bryan Wu diff --git a/Documentation/devicetree/bindings/leds/leds-lp55xx.txt b/Documentation/devicetree/bindings/leds/leds-lp55xx.txt index a61727f..d221e75 100644 --- a/Documentation/devicetree/bindings/leds/leds-lp55xx.txt +++ b/Documentation/devicetree/bindings/leds/leds-lp55xx.txt @@ -17,12 +17,15 @@ Optional properties: 2: D1~6 with VOUT, D7~9 with VDD 3: D1~9 are connected to VOUT -Alternatively, each child can have specific channel name -- chan-name: Name of each channel name +Alternatively, each child can have a specific channel name and trigger: +- chan-name (optional): name of channel +- linux,default-trigger (optional): see + Documentation/devicetree/bindings/leds/common.txt example 1) LP5521 3 LED channels, external clock used. Channel names are 'lp5521_pri:channel0', -'lp5521_pri:channel1' and 'lp5521_pri:channel2' +'lp5521_pri:channel1' and 'lp5521_pri:channel2', with a heartbeat trigger +on channel 0. lp5521@32 { compatible = "national,lp5521"; @@ -33,6 +36,7 @@ lp5521@32 { chan0 { led-cur = /bits/ 8 <0x2f>; max-cur = /bits/ 8 <0x5f>; + linux,default-trigger = "heartbeat"; }; chan1 { diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 351825b..075acf5 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -165,6 +165,7 @@ static int lp55xx_init_led(struct lp55xx_led *led, led->led_current = pdata->led_config[chan].led_current; led->max_current = pdata->led_config[chan].max_current; led->chan_nr = pdata->led_config[chan].chan_nr; + led->cdev.default_trigger = pdata->led_config[chan].default_trigger; if (led->chan_nr >= max_channel) { dev_err(dev, "Use channel numbers between 0 and %d\n", @@ -586,6 +587,8 @@ int lp55xx_of_populate_pdata(struct device *dev, struct device_node *np) of_property_read_string(child, "chan-name", &cfg[i].name); of_property_read_u8(child, "led-cur", &cfg[i].led_current); of_property_read_u8(child, "max-cur", &cfg[i].max_current); + cfg[i].default_trigger = + of_get_property(child, "linux,default-trigger", NULL); i++; } diff --git a/include/linux/platform_data/leds-lp55xx.h b/include/linux/platform_data/leds-lp55xx.h index 51a2ff5..c32de4d 100644 --- a/include/linux/platform_data/leds-lp55xx.h +++ b/include/linux/platform_data/leds-lp55xx.h @@ -22,6 +22,7 @@ struct lp55xx_led_config { const char *name; + const char *default_trigger; u8 chan_nr; u8 led_current; /* mA x10, 0 if led is not connected */ u8 max_current; -- cgit v0.10.2 From b4f31ad6184fd5124abdb69b3b7ee5c18ac76db6 Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Thu, 19 Sep 2013 21:27:59 -0700 Subject: leds: dac124s085: Remove redundant spi_set_drvdata Driver core sets driver data to NULL upon failure or remove. Signed-off-by: Sachin Kamat Cc: Guennadi Liakhovetski Signed-off-by: Bryan Wu diff --git a/drivers/leds/leds-dac124s085.c b/drivers/leds/leds-dac124s085.c index 1f9d8e6..db3ba8b 100644 --- a/drivers/leds/leds-dac124s085.c +++ b/drivers/leds/leds-dac124s085.c @@ -101,7 +101,6 @@ eledcr: while (i--) led_classdev_unregister(&dac->leds[i].ldev); - spi_set_drvdata(spi, NULL); return ret; } @@ -115,8 +114,6 @@ static int dac124s085_remove(struct spi_device *spi) cancel_work_sync(&dac->leds[i].work); } - spi_set_drvdata(spi, NULL); - return 0; } -- cgit v0.10.2 From c68f46dd6aec29b4db9eb85d014981bbdd686428 Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Sat, 28 Sep 2013 04:38:30 -0700 Subject: leds: Include linux/of.h header 'of_match_ptr' is defined in linux/of.h. Include it explicitly. Signed-off-by: Sachin Kamat Signed-off-by: Bryan Wu diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c index e8b01e5..7ccafde 100644 --- a/drivers/leds/leds-gpio.c +++ b/drivers/leds/leds-gpio.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index fe3bcbb..6b553d9 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include diff --git a/drivers/leds/leds-lp5562.c b/drivers/leds/leds-lp5562.c index 2585cfd..bf006f4 100644 --- a/drivers/leds/leds-lp5562.c +++ b/drivers/leds/leds-lp5562.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include diff --git a/drivers/leds/leds-lp8501.c b/drivers/leds/leds-lp8501.c index 8d55a780..f1c704f 100644 --- a/drivers/leds/leds-lp8501.c +++ b/drivers/leds/leds-lp8501.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c index 141f134..c7a4230 100644 --- a/drivers/leds/leds-ns2.c +++ b/drivers/leds/leds-ns2.c @@ -30,6 +30,7 @@ #include #include #include +#include #include /* -- cgit v0.10.2 From 1e08f72dd248645450b01c86ccc066c0a90767d8 Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Sat, 28 Sep 2013 04:38:31 -0700 Subject: leds: pwm: Remove redundant of_match_ptr The data structure of_match_ptr() protects is always compiled in. Hence of_match_ptr() is not needed. Signed-off-by: Sachin Kamat Signed-off-by: Bryan Wu diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c index bb6f948..2848171 100644 --- a/drivers/leds/leds-pwm.c +++ b/drivers/leds/leds-pwm.c @@ -232,7 +232,7 @@ static struct platform_driver led_pwm_driver = { .driver = { .name = "leds_pwm", .owner = THIS_MODULE, - .of_match_table = of_match_ptr(of_pwm_leds_match), + .of_match_table = of_pwm_leds_match, }, }; -- cgit v0.10.2 From bb6febdc90efe7f664328075c204eed8e9af7ec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20G=C3=BCntner?= Date: Wed, 16 Oct 2013 18:09:17 -0700 Subject: leds: Added driver for the NXP PCA9685 I2C chip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The NXP PCA9685 supports 16 channels/leds using a 12-bit PWM (4095 levels of brightness) This driver supports configuration using platform_data. Signed-off-by: Maximilian Güntner Signed-off-by: Bryan Wu diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 875bbe4..72156c1 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -300,6 +300,16 @@ config LEDS_PCA963X LED driver chip accessed via the I2C bus. Supported devices include PCA9633 and PCA9634 +config LEDS_PCA9685 + tristate "LED support for PCA9685 I2C chip" + depends on LEDS_CLASS + depends on I2C + help + This option enables support for LEDs connected to the PCA9685 + LED driver chip accessed via the I2C bus. + The PCA9685 offers 12-bit PWM (4095 levels of brightness) on + 16 individual channels. + config LEDS_WM831X_STATUS tristate "LED support for status LEDs on WM831x PMICs" depends on LEDS_CLASS diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index 8979b0b..3cd76db 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -36,6 +36,7 @@ obj-$(CONFIG_LEDS_OT200) += leds-ot200.o obj-$(CONFIG_LEDS_FSG) += leds-fsg.o obj-$(CONFIG_LEDS_PCA955X) += leds-pca955x.o obj-$(CONFIG_LEDS_PCA963X) += leds-pca963x.o +obj-$(CONFIG_LEDS_PCA9685) += leds-pca9685.o obj-$(CONFIG_LEDS_DA903X) += leds-da903x.o obj-$(CONFIG_LEDS_DA9052) += leds-da9052.o obj-$(CONFIG_LEDS_WM831X_STATUS) += leds-wm831x-status.o diff --git a/drivers/leds/leds-pca9685.c b/drivers/leds/leds-pca9685.c new file mode 100644 index 0000000..6e1ef3a --- /dev/null +++ b/drivers/leds/leds-pca9685.c @@ -0,0 +1,213 @@ +/* + * Copyright 2013 Maximilian Güntner + * + * This file is subject to the terms and conditions of version 2 of + * the GNU General Public License. See the file COPYING in the main + * directory of this archive for more details. + * + * Based on leds-pca963x.c driver by + * Peter Meerwald + * + * Driver for the NXP PCA9685 12-Bit PWM LED driver chip. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +/* Register Addresses */ +#define PCA9685_MODE1 0x00 +#define PCA9685_MODE2 0x01 +#define PCA9685_LED0_ON_L 0x06 +#define PCA9685_ALL_LED_ON_L 0xFA + +/* MODE1 Register */ +#define PCA9685_ALLCALL 0x00 +#define PCA9685_SLEEP 0x04 +#define PCA9685_AI 0x05 + +/* MODE2 Register */ +#define PCA9685_INVRT 0x04 +#define PCA9685_OUTDRV 0x02 + +static const struct i2c_device_id pca9685_id[] = { + { "pca9685", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, pca9685_id); + +struct pca9685_led { + struct i2c_client *client; + struct work_struct work; + u16 brightness; + struct led_classdev led_cdev; + int led_num; /* 0-15 */ + char name[32]; +}; + +static void pca9685_write_msg(struct i2c_client *client, u8 *buf, u8 len) +{ + struct i2c_msg msg = { + .addr = client->addr, + .flags = 0x00, + .len = len, + .buf = buf + }; + i2c_transfer(client->adapter, &msg, 1); +} + +static void pca9685_all_off(struct i2c_client *client) +{ + u8 i2c_buffer[5] = {PCA9685_ALL_LED_ON_L, 0x00, 0x00, 0x00, 0x10}; + pca9685_write_msg(client, i2c_buffer, 5); +} + +static void pca9685_led_work(struct work_struct *work) +{ + struct pca9685_led *pca9685; + u8 i2c_buffer[5]; + + pca9685 = container_of(work, struct pca9685_led, work); + i2c_buffer[0] = PCA9685_LED0_ON_L + 4 * pca9685->led_num; + /* + * 4095 is the maximum brightness, so we set the ON time to 0x1000 + * which disables the PWM generator for that LED + */ + if (pca9685->brightness == 4095) + *((__le16 *)(i2c_buffer+1)) = cpu_to_le16(0x1000); + else + *((__le16 *)(i2c_buffer+1)) = 0x0000; + + if (pca9685->brightness == 0) + *((__le16 *)(i2c_buffer+3)) = cpu_to_le16(0x1000); + else if (pca9685->brightness == 4095) + *((__le16 *)(i2c_buffer+3)) = 0x0000; + else + *((__le16 *)(i2c_buffer+3)) = cpu_to_le16(pca9685->brightness); + + pca9685_write_msg(pca9685->client, i2c_buffer, 5); +} + +static void pca9685_led_set(struct led_classdev *led_cdev, + enum led_brightness value) +{ + struct pca9685_led *pca9685; + pca9685 = container_of(led_cdev, struct pca9685_led, led_cdev); + pca9685->brightness = value; + + schedule_work(&pca9685->work); +} + +static int pca9685_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct pca9685_led *pca9685; + struct pca9685_platform_data *pdata; + int err; + u8 i; + + pdata = dev_get_platdata(&client->dev); + if (pdata) { + if (pdata->leds.num_leds < 1 || pdata->leds.num_leds > 15) { + dev_err(&client->dev, "board info must claim 1-16 LEDs"); + return -EINVAL; + } + } + + pca9685 = devm_kzalloc(&client->dev, 16 * sizeof(*pca9685), GFP_KERNEL); + if (!pca9685) + return -ENOMEM; + + i2c_set_clientdata(client, pca9685); + pca9685_all_off(client); + + for (i = 0; i < 16; i++) { + pca9685[i].client = client; + pca9685[i].led_num = i; + pca9685[i].name[0] = '\0'; + if (pdata && i < pdata->leds.num_leds) { + if (pdata->leds.leds[i].name) + strncpy(pca9685[i].name, + pdata->leds.leds[i].name, + sizeof(pca9685[i].name)-1); + if (pdata->leds.leds[i].default_trigger) + pca9685[i].led_cdev.default_trigger = + pdata->leds.leds[i].default_trigger; + } + if (strlen(pca9685[i].name) == 0) { + /* + * Write adapter and address to the name as well. + * Otherwise multiple chips attached to one host would + * not work. + */ + snprintf(pca9685[i].name, sizeof(pca9685[i].name), + "pca9685:%d:x%.2x:%d", + client->adapter->nr, client->addr, i); + } + pca9685[i].led_cdev.name = pca9685[i].name; + pca9685[i].led_cdev.max_brightness = 0xfff; + pca9685[i].led_cdev.brightness_set = pca9685_led_set; + + INIT_WORK(&pca9685[i].work, pca9685_led_work); + err = led_classdev_register(&client->dev, &pca9685[i].led_cdev); + if (err < 0) + goto exit; + } + + if (pdata) + i2c_smbus_write_byte_data(client, PCA9685_MODE2, + pdata->outdrv << PCA9685_OUTDRV | + pdata->inverted << PCA9685_INVRT); + else + i2c_smbus_write_byte_data(client, PCA9685_MODE2, + PCA9685_TOTEM_POLE << PCA9685_OUTDRV); + /* Enable Auto-Increment, enable oscillator, ALLCALL/SUBADDR disabled */ + i2c_smbus_write_byte_data(client, PCA9685_MODE1, BIT(PCA9685_AI)); + + return 0; + +exit: + while (i--) { + led_classdev_unregister(&pca9685[i].led_cdev); + cancel_work_sync(&pca9685[i].work); + } + return err; +} + +static int pca9685_remove(struct i2c_client *client) +{ + struct pca9685_led *pca9685 = i2c_get_clientdata(client); + u8 i; + + for (i = 0; i < 16; i++) { + led_classdev_unregister(&pca9685[i].led_cdev); + cancel_work_sync(&pca9685[i].work); + } + pca9685_all_off(client); + return 0; +} + +static struct i2c_driver pca9685_driver = { + .driver = { + .name = "leds-pca9685", + .owner = THIS_MODULE, + }, + .probe = pca9685_probe, + .remove = pca9685_remove, + .id_table = pca9685_id, +}; + +module_i2c_driver(pca9685_driver); + +MODULE_AUTHOR("Maximilian Güntner "); +MODULE_DESCRIPTION("PCA9685 LED Driver"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/platform_data/leds-pca9685.h b/include/linux/platform_data/leds-pca9685.h new file mode 100644 index 0000000..778e9e4 --- /dev/null +++ b/include/linux/platform_data/leds-pca9685.h @@ -0,0 +1,35 @@ +/* + * Copyright 2013 Maximilian Güntner + * + * This file is subject to the terms and conditions of version 2 of + * the GNU General Public License. See the file COPYING in the main + * directory of this archive for more details. + * + * Based on leds-pca963x.h by Peter Meerwald + * + * LED driver for the NXP PCA9685 PWM chip + * + */ + +#ifndef __LINUX_PCA9685_H +#define __LINUX_PCA9685_H + +#include + +enum pca9685_outdrv { + PCA9685_OPEN_DRAIN, + PCA9685_TOTEM_POLE, +}; + +enum pca9685_inverted { + PCA9685_NOT_INVERTED, + PCA9685_INVERTED, +}; + +struct pca9685_platform_data { + struct led_platform_data leds; + enum pca9685_outdrv outdrv; + enum pca9685_inverted inverted; +}; + +#endif /* __LINUX_PCA9685_H */ -- cgit v0.10.2 From 954e04b9491adea99e4590bc73937fdd8774ab3c Mon Sep 17 00:00:00 2001 From: Bryan Wu Date: Tue, 24 Sep 2013 10:38:26 -0700 Subject: of: introduce of_get_available_child_count Some drivers keep counting available child by themselves. So introduce a new simple API like of_get_child_count() but for available childs. Cc: Josh Wu Signed-off-by: Bryan Wu Acked-by: Rob Herring diff --git a/include/linux/of.h b/include/linux/of.h index f95aee3..54c2560 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -226,6 +226,17 @@ static inline int of_get_child_count(const struct device_node *np) return num; } +static inline int of_get_available_child_count(const struct device_node *np) +{ + struct device_node *child; + int num = 0; + + for_each_available_child_of_node(np, child) + num++; + + return num; +} + extern struct device_node *of_find_node_with_property( struct device_node *from, const char *prop_name); #define for_each_node_with_property(dn, prop_name) \ @@ -376,6 +387,11 @@ static inline int of_get_child_count(const struct device_node *np) return 0; } +static inline int of_get_available_child_count(const struct device_node *np) +{ + return 0; +} + static inline int of_device_is_compatible(const struct device_node *device, const char *name) { -- cgit v0.10.2 From b0bb83df0a004ff6ef9b1a11784361c9eb63dbf9 Mon Sep 17 00:00:00 2001 From: Josh Wu Date: Thu, 26 Sep 2013 04:27:56 -0700 Subject: leds-gpio: of: led should not be created if its status is disabled now the leds-gpio driver will create every child led node without checking the status is disabled or not. for example, if we have a led node like d3, and its status is disabled: leds { d3 { label = "d3"; gpios = <&pioE 24 0>; status = "disabled"; }; }; we except the d3 should not be created. And the gpios should not be request as well. But current driver will create d3 and request its gpio. This patch fix this by using for_each_available_child_of_node() and of_get_available_child_count() to enumerate all child nodes. So the disabled node will be inavailable. Signed-off-by: Josh Wu Signed-off-by: Bryan Wu diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c index 7ccafde..78b0e27 100644 --- a/drivers/leds/leds-gpio.c +++ b/drivers/leds/leds-gpio.c @@ -171,11 +171,11 @@ static struct gpio_leds_priv *gpio_leds_create_of(struct platform_device *pdev) int count, ret; /* count LEDs in this device, so we know how much to allocate */ - count = of_get_child_count(np); + count = of_get_available_child_count(np); if (!count) return ERR_PTR(-ENODEV); - for_each_child_of_node(np, child) + for_each_available_child_of_node(np, child) if (of_get_gpio(child, 0) == -EPROBE_DEFER) return ERR_PTR(-EPROBE_DEFER); @@ -184,7 +184,7 @@ static struct gpio_leds_priv *gpio_leds_create_of(struct platform_device *pdev) if (!priv) return ERR_PTR(-ENOMEM); - for_each_child_of_node(np, child) { + for_each_available_child_of_node(np, child) { struct gpio_led led = {}; enum of_gpio_flags flags; const char *state; -- cgit v0.10.2 From 30dae2f98612d7c8cd855861b9de205ebd9ef4fa Mon Sep 17 00:00:00 2001 From: Sebastian Reichel Date: Tue, 22 Oct 2013 11:02:56 -0700 Subject: leds: lp55xx: handle enable pin in driver This patch moves the handling of the chip's enable pin from the board code into the driver. It also updates all board-code files using the driver to incorporate this change. This is needed for device tree support of the enable pin. Signed-off-by: Sebastian Reichel Acked-by: Linus Walleij Acked-by: Tony Lindgren Signed-off-by: Bryan Wu diff --git a/Documentation/devicetree/bindings/leds/leds-lp55xx.txt b/Documentation/devicetree/bindings/leds/leds-lp55xx.txt index d221e75..c55b8c0 100644 --- a/Documentation/devicetree/bindings/leds/leds-lp55xx.txt +++ b/Documentation/devicetree/bindings/leds/leds-lp55xx.txt @@ -10,6 +10,7 @@ Each child has own specific current settings - max-cur: Maximun current at each led channel. Optional properties: +- enable-gpio: GPIO attached to the chip's enable pin - label: Used for naming LEDs - pwr-sel: LP8501 specific property. Power selection for output channels. 0: D1~9 are connected to VDD diff --git a/arch/arm/mach-omap2/board-rx51-peripherals.c b/arch/arm/mach-omap2/board-rx51-peripherals.c index f6fe388..68dc998 100644 --- a/arch/arm/mach-omap2/board-rx51-peripherals.c +++ b/arch/arm/mach-omap2/board-rx51-peripherals.c @@ -211,29 +211,11 @@ static struct lp55xx_led_config rx51_lp5523_led_config[] = { } }; -static int rx51_lp5523_setup(void) -{ - return gpio_request_one(RX51_LP5523_CHIP_EN_GPIO, GPIOF_DIR_OUT, - "lp5523_enable"); -} - -static void rx51_lp5523_release(void) -{ - gpio_free(RX51_LP5523_CHIP_EN_GPIO); -} - -static void rx51_lp5523_enable(bool state) -{ - gpio_set_value(RX51_LP5523_CHIP_EN_GPIO, !!state); -} - static struct lp55xx_platform_data rx51_lp5523_platform_data = { .led_config = rx51_lp5523_led_config, .num_channels = ARRAY_SIZE(rx51_lp5523_led_config), .clock_mode = LP55XX_CLOCK_AUTO, - .setup_resources = rx51_lp5523_setup, - .release_resources = rx51_lp5523_release, - .enable = rx51_lp5523_enable, + .enable_gpio = RX51_LP5523_CHIP_EN_GPIO, }; #endif diff --git a/arch/arm/mach-ux500/board-mop500.c b/arch/arm/mach-ux500/board-mop500.c index ad0806e..703dec2 100644 --- a/arch/arm/mach-ux500/board-mop500.c +++ b/arch/arm/mach-ux500/board-mop500.c @@ -297,6 +297,7 @@ static struct lp55xx_platform_data __initdata lp5521_pri_data = { .led_config = &lp5521_pri_led[0], .num_channels = 3, .clock_mode = LP55XX_CLOCK_EXT, + .enable_gpio = -1, }; static struct lp55xx_led_config lp5521_sec_led[] = { @@ -322,6 +323,7 @@ static struct lp55xx_platform_data __initdata lp5521_sec_data = { .led_config = &lp5521_sec_led[0], .num_channels = 3, .clock_mode = LP55XX_CLOCK_EXT, + .enable_gpio = -1, }; /* I2C0 devices only available on the first HREF/MOP500 */ diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 075acf5..9acc6bb 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include "leds-lp55xx-common.h" @@ -407,18 +409,18 @@ int lp55xx_init_device(struct lp55xx_chip *chip) if (!pdata || !cfg) return -EINVAL; - if (pdata->setup_resources) { - ret = pdata->setup_resources(); + if (gpio_is_valid(pdata->enable_gpio)) { + ret = devm_gpio_request_one(dev, pdata->enable_gpio, + GPIOF_DIR_OUT, "lp5523_enable"); if (ret < 0) { - dev_err(dev, "setup resoure err: %d\n", ret); + dev_err(dev, "could not acquire enable gpio (err=%d)\n", + ret); goto err; } - } - if (pdata->enable) { - pdata->enable(0); + gpio_set_value(pdata->enable_gpio, 0); usleep_range(1000, 2000); /* Keep enable down at least 1ms */ - pdata->enable(1); + gpio_set_value(pdata->enable_gpio, 1); usleep_range(1000, 2000); /* 500us abs min. */ } @@ -459,11 +461,8 @@ void lp55xx_deinit_device(struct lp55xx_chip *chip) if (chip->clk) clk_disable_unprepare(chip->clk); - if (pdata->enable) - pdata->enable(0); - - if (pdata->release_resources) - pdata->release_resources(); + if (gpio_is_valid(pdata->enable_gpio)) + gpio_set_value(pdata->enable_gpio, 0); } EXPORT_SYMBOL_GPL(lp55xx_deinit_device); @@ -596,6 +595,8 @@ int lp55xx_of_populate_pdata(struct device *dev, struct device_node *np) of_property_read_string(np, "label", &pdata->label); of_property_read_u8(np, "clock-mode", &pdata->clock_mode); + pdata->enable_gpio = of_get_named_gpio(np, "enable-gpio", 0); + /* LP8501 specific */ of_property_read_u8(np, "pwr-sel", (u8 *)&pdata->pwr_sel); diff --git a/include/linux/platform_data/leds-lp55xx.h b/include/linux/platform_data/leds-lp55xx.h index c32de4d..624ff9e 100644 --- a/include/linux/platform_data/leds-lp55xx.h +++ b/include/linux/platform_data/leds-lp55xx.h @@ -67,10 +67,8 @@ struct lp55xx_platform_data { /* Clock configuration */ u8 clock_mode; - /* Platform specific functions */ - int (*setup_resources)(void); - void (*release_resources)(void); - void (*enable)(bool state); + /* optional enable GPIO */ + int enable_gpio; /* Predefined pattern data */ struct lp55xx_predef_pattern *patterns; -- cgit v0.10.2