Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/cooloney/linux-leds

Pull LED subsystem changes from Bryan Wu:
"LED subsystem updates for 3.13 are basically cleanup and also add a
new driver for PCA9685"

* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/cooloney/linux-leds:
leds: lp55xx: handle enable pin in driver
leds-gpio: of: led should not be created if its status is disabled
of: introduce of_get_available_child_count
leds: Added driver for the NXP PCA9685 I2C chip
leds: pwm: Remove redundant of_match_ptr
leds: Include linux/of.h header
leds: dac124s085: Remove redundant spi_set_drvdata
leds: lp55xx: enable setting default trigger
leds: blinkm: Remove redundant break

+312 -48
+8 -3
Documentation/devicetree/bindings/leds/leds-lp55xx.txt
··· 10 10 - max-cur: Maximun current at each led channel. 11 11 12 12 Optional properties: 13 + - enable-gpio: GPIO attached to the chip's enable pin 13 14 - label: Used for naming LEDs 14 15 - pwr-sel: LP8501 specific property. Power selection for output channels. 15 16 0: D1~9 are connected to VDD ··· 18 17 2: D1~6 with VOUT, D7~9 with VDD 19 18 3: D1~9 are connected to VOUT 20 19 21 - Alternatively, each child can have specific channel name 22 - - chan-name: Name of each channel name 20 + Alternatively, each child can have a specific channel name and trigger: 21 + - chan-name (optional): name of channel 22 + - linux,default-trigger (optional): see 23 + Documentation/devicetree/bindings/leds/common.txt 23 24 24 25 example 1) LP5521 25 26 3 LED channels, external clock used. Channel names are 'lp5521_pri:channel0', 26 - 'lp5521_pri:channel1' and 'lp5521_pri:channel2' 27 + 'lp5521_pri:channel1' and 'lp5521_pri:channel2', with a heartbeat trigger 28 + on channel 0. 27 29 28 30 lp5521@32 { 29 31 compatible = "national,lp5521"; ··· 37 33 chan0 { 38 34 led-cur = /bits/ 8 <0x2f>; 39 35 max-cur = /bits/ 8 <0x5f>; 36 + linux,default-trigger = "heartbeat"; 40 37 }; 41 38 42 39 chan1 {
+1 -19
arch/arm/mach-omap2/board-rx51-peripherals.c
··· 213 213 } 214 214 }; 215 215 216 - static int rx51_lp5523_setup(void) 217 - { 218 - return gpio_request_one(RX51_LP5523_CHIP_EN_GPIO, GPIOF_DIR_OUT, 219 - "lp5523_enable"); 220 - } 221 - 222 - static void rx51_lp5523_release(void) 223 - { 224 - gpio_free(RX51_LP5523_CHIP_EN_GPIO); 225 - } 226 - 227 - static void rx51_lp5523_enable(bool state) 228 - { 229 - gpio_set_value(RX51_LP5523_CHIP_EN_GPIO, !!state); 230 - } 231 - 232 216 static struct lp55xx_platform_data rx51_lp5523_platform_data = { 233 217 .led_config = rx51_lp5523_led_config, 234 218 .num_channels = ARRAY_SIZE(rx51_lp5523_led_config), 235 219 .clock_mode = LP55XX_CLOCK_AUTO, 236 - .setup_resources = rx51_lp5523_setup, 237 - .release_resources = rx51_lp5523_release, 238 - .enable = rx51_lp5523_enable, 220 + .enable_gpio = RX51_LP5523_CHIP_EN_GPIO, 239 221 }; 240 222 #endif 241 223
+10
drivers/leds/Kconfig
··· 300 300 LED driver chip accessed via the I2C bus. Supported 301 301 devices include PCA9633 and PCA9634 302 302 303 + config LEDS_PCA9685 304 + tristate "LED support for PCA9685 I2C chip" 305 + depends on LEDS_CLASS 306 + depends on I2C 307 + help 308 + This option enables support for LEDs connected to the PCA9685 309 + LED driver chip accessed via the I2C bus. 310 + The PCA9685 offers 12-bit PWM (4095 levels of brightness) on 311 + 16 individual channels. 312 + 303 313 config LEDS_WM831X_STATUS 304 314 tristate "LED support for status LEDs on WM831x PMICs" 305 315 depends on LEDS_CLASS
+1
drivers/leds/Makefile
··· 36 36 obj-$(CONFIG_LEDS_FSG) += leds-fsg.o 37 37 obj-$(CONFIG_LEDS_PCA955X) += leds-pca955x.o 38 38 obj-$(CONFIG_LEDS_PCA963X) += leds-pca963x.o 39 + obj-$(CONFIG_LEDS_PCA9685) += leds-pca9685.o 39 40 obj-$(CONFIG_LEDS_DA903X) += leds-da903x.o 40 41 obj-$(CONFIG_LEDS_DA9052) += leds-da9052.o 41 42 obj-$(CONFIG_LEDS_WM831X_STATUS) += leds-wm831x-status.o
-3
drivers/leds/leds-blinkm.c
··· 161 161 switch (color) { 162 162 case RED: 163 163 return scnprintf(buf, PAGE_SIZE, "%02X\n", data->red); 164 - break; 165 164 case GREEN: 166 165 return scnprintf(buf, PAGE_SIZE, "%02X\n", data->green); 167 - break; 168 166 case BLUE: 169 167 return scnprintf(buf, PAGE_SIZE, "%02X\n", data->blue); 170 - break; 171 168 default: 172 169 return -EINVAL; 173 170 }
-3
drivers/leds/leds-dac124s085.c
··· 101 101 while (i--) 102 102 led_classdev_unregister(&dac->leds[i].ldev); 103 103 104 - spi_set_drvdata(spi, NULL); 105 104 return ret; 106 105 } 107 106 ··· 113 114 led_classdev_unregister(&dac->leds[i].ldev); 114 115 cancel_work_sync(&dac->leds[i].work); 115 116 } 116 - 117 - spi_set_drvdata(spi, NULL); 118 117 119 118 return 0; 120 119 }
+4 -3
drivers/leds/leds-gpio.c
··· 15 15 #include <linux/platform_device.h> 16 16 #include <linux/gpio.h> 17 17 #include <linux/leds.h> 18 + #include <linux/of.h> 18 19 #include <linux/of_platform.h> 19 20 #include <linux/of_gpio.h> 20 21 #include <linux/slab.h> ··· 171 170 int count, ret; 172 171 173 172 /* count LEDs in this device, so we know how much to allocate */ 174 - count = of_get_child_count(np); 173 + count = of_get_available_child_count(np); 175 174 if (!count) 176 175 return ERR_PTR(-ENODEV); 177 176 178 - for_each_child_of_node(np, child) 177 + for_each_available_child_of_node(np, child) 179 178 if (of_get_gpio(child, 0) == -EPROBE_DEFER) 180 179 return ERR_PTR(-EPROBE_DEFER); 181 180 ··· 184 183 if (!priv) 185 184 return ERR_PTR(-ENOMEM); 186 185 187 - for_each_child_of_node(np, child) { 186 + for_each_available_child_of_node(np, child) { 188 187 struct gpio_led led = {}; 189 188 enum of_gpio_flags flags; 190 189 const char *state;
+1
drivers/leds/leds-lp5523.c
··· 29 29 #include <linux/leds.h> 30 30 #include <linux/module.h> 31 31 #include <linux/mutex.h> 32 + #include <linux/of.h> 32 33 #include <linux/platform_data/leds-lp55xx.h> 33 34 #include <linux/slab.h> 34 35
+1
drivers/leds/leds-lp5562.c
··· 17 17 #include <linux/leds.h> 18 18 #include <linux/module.h> 19 19 #include <linux/mutex.h> 20 + #include <linux/of.h> 20 21 #include <linux/platform_data/leds-lp55xx.h> 21 22 #include <linux/slab.h> 22 23
+16 -12
drivers/leds/leds-lp55xx-common.c
··· 20 20 #include <linux/module.h> 21 21 #include <linux/platform_data/leds-lp55xx.h> 22 22 #include <linux/slab.h> 23 + #include <linux/gpio.h> 24 + #include <linux/of_gpio.h> 23 25 24 26 #include "leds-lp55xx-common.h" 25 27 ··· 167 165 led->led_current = pdata->led_config[chan].led_current; 168 166 led->max_current = pdata->led_config[chan].max_current; 169 167 led->chan_nr = pdata->led_config[chan].chan_nr; 168 + led->cdev.default_trigger = pdata->led_config[chan].default_trigger; 170 169 171 170 if (led->chan_nr >= max_channel) { 172 171 dev_err(dev, "Use channel numbers between 0 and %d\n", ··· 409 406 if (!pdata || !cfg) 410 407 return -EINVAL; 411 408 412 - if (pdata->setup_resources) { 413 - ret = pdata->setup_resources(); 409 + if (gpio_is_valid(pdata->enable_gpio)) { 410 + ret = devm_gpio_request_one(dev, pdata->enable_gpio, 411 + GPIOF_DIR_OUT, "lp5523_enable"); 414 412 if (ret < 0) { 415 - dev_err(dev, "setup resoure err: %d\n", ret); 413 + dev_err(dev, "could not acquire enable gpio (err=%d)\n", 414 + ret); 416 415 goto err; 417 416 } 418 - } 419 417 420 - if (pdata->enable) { 421 - pdata->enable(0); 418 + gpio_set_value(pdata->enable_gpio, 0); 422 419 usleep_range(1000, 2000); /* Keep enable down at least 1ms */ 423 - pdata->enable(1); 420 + gpio_set_value(pdata->enable_gpio, 1); 424 421 usleep_range(1000, 2000); /* 500us abs min. */ 425 422 } 426 423 ··· 461 458 if (chip->clk) 462 459 clk_disable_unprepare(chip->clk); 463 460 464 - if (pdata->enable) 465 - pdata->enable(0); 466 - 467 - if (pdata->release_resources) 468 - pdata->release_resources(); 461 + if (gpio_is_valid(pdata->enable_gpio)) 462 + gpio_set_value(pdata->enable_gpio, 0); 469 463 } 470 464 EXPORT_SYMBOL_GPL(lp55xx_deinit_device); 471 465 ··· 586 586 of_property_read_string(child, "chan-name", &cfg[i].name); 587 587 of_property_read_u8(child, "led-cur", &cfg[i].led_current); 588 588 of_property_read_u8(child, "max-cur", &cfg[i].max_current); 589 + cfg[i].default_trigger = 590 + of_get_property(child, "linux,default-trigger", NULL); 589 591 590 592 i++; 591 593 } 592 594 593 595 of_property_read_string(np, "label", &pdata->label); 594 596 of_property_read_u8(np, "clock-mode", &pdata->clock_mode); 597 + 598 + pdata->enable_gpio = of_get_named_gpio(np, "enable-gpio", 0); 595 599 596 600 /* LP8501 specific */ 597 601 of_property_read_u8(np, "pwr-sel", (u8 *)&pdata->pwr_sel);
+1
drivers/leds/leds-lp8501.c
··· 18 18 #include <linux/leds.h> 19 19 #include <linux/module.h> 20 20 #include <linux/mutex.h> 21 + #include <linux/of.h> 21 22 #include <linux/platform_data/leds-lp55xx.h> 22 23 #include <linux/slab.h> 23 24
+1
drivers/leds/leds-ns2.c
··· 30 30 #include <linux/leds.h> 31 31 #include <linux/module.h> 32 32 #include <linux/platform_data/leds-kirkwood-ns2.h> 33 + #include <linux/of.h> 33 34 #include <linux/of_gpio.h> 34 35 35 36 /*
+213
drivers/leds/leds-pca9685.c
··· 1 + /* 2 + * Copyright 2013 Maximilian Güntner <maximilian.guentner@gmail.com> 3 + * 4 + * This file is subject to the terms and conditions of version 2 of 5 + * the GNU General Public License. See the file COPYING in the main 6 + * directory of this archive for more details. 7 + * 8 + * Based on leds-pca963x.c driver by 9 + * Peter Meerwald <p.meerwald@bct-electronic.com> 10 + * 11 + * Driver for the NXP PCA9685 12-Bit PWM LED driver chip. 12 + * 13 + */ 14 + 15 + #include <linux/ctype.h> 16 + #include <linux/delay.h> 17 + #include <linux/err.h> 18 + #include <linux/i2c.h> 19 + #include <linux/leds.h> 20 + #include <linux/module.h> 21 + #include <linux/slab.h> 22 + #include <linux/string.h> 23 + #include <linux/workqueue.h> 24 + 25 + #include <linux/platform_data/leds-pca9685.h> 26 + 27 + /* Register Addresses */ 28 + #define PCA9685_MODE1 0x00 29 + #define PCA9685_MODE2 0x01 30 + #define PCA9685_LED0_ON_L 0x06 31 + #define PCA9685_ALL_LED_ON_L 0xFA 32 + 33 + /* MODE1 Register */ 34 + #define PCA9685_ALLCALL 0x00 35 + #define PCA9685_SLEEP 0x04 36 + #define PCA9685_AI 0x05 37 + 38 + /* MODE2 Register */ 39 + #define PCA9685_INVRT 0x04 40 + #define PCA9685_OUTDRV 0x02 41 + 42 + static const struct i2c_device_id pca9685_id[] = { 43 + { "pca9685", 0 }, 44 + { } 45 + }; 46 + MODULE_DEVICE_TABLE(i2c, pca9685_id); 47 + 48 + struct pca9685_led { 49 + struct i2c_client *client; 50 + struct work_struct work; 51 + u16 brightness; 52 + struct led_classdev led_cdev; 53 + int led_num; /* 0-15 */ 54 + char name[32]; 55 + }; 56 + 57 + static void pca9685_write_msg(struct i2c_client *client, u8 *buf, u8 len) 58 + { 59 + struct i2c_msg msg = { 60 + .addr = client->addr, 61 + .flags = 0x00, 62 + .len = len, 63 + .buf = buf 64 + }; 65 + i2c_transfer(client->adapter, &msg, 1); 66 + } 67 + 68 + static void pca9685_all_off(struct i2c_client *client) 69 + { 70 + u8 i2c_buffer[5] = {PCA9685_ALL_LED_ON_L, 0x00, 0x00, 0x00, 0x10}; 71 + pca9685_write_msg(client, i2c_buffer, 5); 72 + } 73 + 74 + static void pca9685_led_work(struct work_struct *work) 75 + { 76 + struct pca9685_led *pca9685; 77 + u8 i2c_buffer[5]; 78 + 79 + pca9685 = container_of(work, struct pca9685_led, work); 80 + i2c_buffer[0] = PCA9685_LED0_ON_L + 4 * pca9685->led_num; 81 + /* 82 + * 4095 is the maximum brightness, so we set the ON time to 0x1000 83 + * which disables the PWM generator for that LED 84 + */ 85 + if (pca9685->brightness == 4095) 86 + *((__le16 *)(i2c_buffer+1)) = cpu_to_le16(0x1000); 87 + else 88 + *((__le16 *)(i2c_buffer+1)) = 0x0000; 89 + 90 + if (pca9685->brightness == 0) 91 + *((__le16 *)(i2c_buffer+3)) = cpu_to_le16(0x1000); 92 + else if (pca9685->brightness == 4095) 93 + *((__le16 *)(i2c_buffer+3)) = 0x0000; 94 + else 95 + *((__le16 *)(i2c_buffer+3)) = cpu_to_le16(pca9685->brightness); 96 + 97 + pca9685_write_msg(pca9685->client, i2c_buffer, 5); 98 + } 99 + 100 + static void pca9685_led_set(struct led_classdev *led_cdev, 101 + enum led_brightness value) 102 + { 103 + struct pca9685_led *pca9685; 104 + pca9685 = container_of(led_cdev, struct pca9685_led, led_cdev); 105 + pca9685->brightness = value; 106 + 107 + schedule_work(&pca9685->work); 108 + } 109 + 110 + static int pca9685_probe(struct i2c_client *client, 111 + const struct i2c_device_id *id) 112 + { 113 + struct pca9685_led *pca9685; 114 + struct pca9685_platform_data *pdata; 115 + int err; 116 + u8 i; 117 + 118 + pdata = dev_get_platdata(&client->dev); 119 + if (pdata) { 120 + if (pdata->leds.num_leds < 1 || pdata->leds.num_leds > 15) { 121 + dev_err(&client->dev, "board info must claim 1-16 LEDs"); 122 + return -EINVAL; 123 + } 124 + } 125 + 126 + pca9685 = devm_kzalloc(&client->dev, 16 * sizeof(*pca9685), GFP_KERNEL); 127 + if (!pca9685) 128 + return -ENOMEM; 129 + 130 + i2c_set_clientdata(client, pca9685); 131 + pca9685_all_off(client); 132 + 133 + for (i = 0; i < 16; i++) { 134 + pca9685[i].client = client; 135 + pca9685[i].led_num = i; 136 + pca9685[i].name[0] = '\0'; 137 + if (pdata && i < pdata->leds.num_leds) { 138 + if (pdata->leds.leds[i].name) 139 + strncpy(pca9685[i].name, 140 + pdata->leds.leds[i].name, 141 + sizeof(pca9685[i].name)-1); 142 + if (pdata->leds.leds[i].default_trigger) 143 + pca9685[i].led_cdev.default_trigger = 144 + pdata->leds.leds[i].default_trigger; 145 + } 146 + if (strlen(pca9685[i].name) == 0) { 147 + /* 148 + * Write adapter and address to the name as well. 149 + * Otherwise multiple chips attached to one host would 150 + * not work. 151 + */ 152 + snprintf(pca9685[i].name, sizeof(pca9685[i].name), 153 + "pca9685:%d:x%.2x:%d", 154 + client->adapter->nr, client->addr, i); 155 + } 156 + pca9685[i].led_cdev.name = pca9685[i].name; 157 + pca9685[i].led_cdev.max_brightness = 0xfff; 158 + pca9685[i].led_cdev.brightness_set = pca9685_led_set; 159 + 160 + INIT_WORK(&pca9685[i].work, pca9685_led_work); 161 + err = led_classdev_register(&client->dev, &pca9685[i].led_cdev); 162 + if (err < 0) 163 + goto exit; 164 + } 165 + 166 + if (pdata) 167 + i2c_smbus_write_byte_data(client, PCA9685_MODE2, 168 + pdata->outdrv << PCA9685_OUTDRV | 169 + pdata->inverted << PCA9685_INVRT); 170 + else 171 + i2c_smbus_write_byte_data(client, PCA9685_MODE2, 172 + PCA9685_TOTEM_POLE << PCA9685_OUTDRV); 173 + /* Enable Auto-Increment, enable oscillator, ALLCALL/SUBADDR disabled */ 174 + i2c_smbus_write_byte_data(client, PCA9685_MODE1, BIT(PCA9685_AI)); 175 + 176 + return 0; 177 + 178 + exit: 179 + while (i--) { 180 + led_classdev_unregister(&pca9685[i].led_cdev); 181 + cancel_work_sync(&pca9685[i].work); 182 + } 183 + return err; 184 + } 185 + 186 + static int pca9685_remove(struct i2c_client *client) 187 + { 188 + struct pca9685_led *pca9685 = i2c_get_clientdata(client); 189 + u8 i; 190 + 191 + for (i = 0; i < 16; i++) { 192 + led_classdev_unregister(&pca9685[i].led_cdev); 193 + cancel_work_sync(&pca9685[i].work); 194 + } 195 + pca9685_all_off(client); 196 + return 0; 197 + } 198 + 199 + static struct i2c_driver pca9685_driver = { 200 + .driver = { 201 + .name = "leds-pca9685", 202 + .owner = THIS_MODULE, 203 + }, 204 + .probe = pca9685_probe, 205 + .remove = pca9685_remove, 206 + .id_table = pca9685_id, 207 + }; 208 + 209 + module_i2c_driver(pca9685_driver); 210 + 211 + MODULE_AUTHOR("Maximilian Güntner <maximilian.guentner@gmail.com>"); 212 + MODULE_DESCRIPTION("PCA9685 LED Driver"); 213 + MODULE_LICENSE("GPL v2");
+1 -1
drivers/leds/leds-pwm.c
··· 232 232 .driver = { 233 233 .name = "leds_pwm", 234 234 .owner = THIS_MODULE, 235 - .of_match_table = of_match_ptr(of_pwm_leds_match), 235 + .of_match_table = of_pwm_leds_match, 236 236 }, 237 237 }; 238 238
+16
include/linux/of.h
··· 226 226 return num; 227 227 } 228 228 229 + static inline int of_get_available_child_count(const struct device_node *np) 230 + { 231 + struct device_node *child; 232 + int num = 0; 233 + 234 + for_each_available_child_of_node(np, child) 235 + num++; 236 + 237 + return num; 238 + } 239 + 229 240 /* cache lookup */ 230 241 extern struct device_node *of_find_next_cache_node(const struct device_node *); 231 242 extern struct device_node *of_find_node_with_property( ··· 385 374 } 386 375 387 376 static inline int of_get_child_count(const struct device_node *np) 377 + { 378 + return 0; 379 + } 380 + 381 + static inline int of_get_available_child_count(const struct device_node *np) 388 382 { 389 383 return 0; 390 384 }
+3 -4
include/linux/platform_data/leds-lp55xx.h
··· 22 22 23 23 struct lp55xx_led_config { 24 24 const char *name; 25 + const char *default_trigger; 25 26 u8 chan_nr; 26 27 u8 led_current; /* mA x10, 0 if led is not connected */ 27 28 u8 max_current; ··· 67 66 /* Clock configuration */ 68 67 u8 clock_mode; 69 68 70 - /* Platform specific functions */ 71 - int (*setup_resources)(void); 72 - void (*release_resources)(void); 73 - void (*enable)(bool state); 69 + /* optional enable GPIO */ 70 + int enable_gpio; 74 71 75 72 /* Predefined pattern data */ 76 73 struct lp55xx_predef_pattern *patterns;
+35
include/linux/platform_data/leds-pca9685.h
··· 1 + /* 2 + * Copyright 2013 Maximilian Güntner <maximilian.guentner@gmail.com> 3 + * 4 + * This file is subject to the terms and conditions of version 2 of 5 + * the GNU General Public License. See the file COPYING in the main 6 + * directory of this archive for more details. 7 + * 8 + * Based on leds-pca963x.h by Peter Meerwald <p.meerwald@bct-electronic.com> 9 + * 10 + * LED driver for the NXP PCA9685 PWM chip 11 + * 12 + */ 13 + 14 + #ifndef __LINUX_PCA9685_H 15 + #define __LINUX_PCA9685_H 16 + 17 + #include <linux/leds.h> 18 + 19 + enum pca9685_outdrv { 20 + PCA9685_OPEN_DRAIN, 21 + PCA9685_TOTEM_POLE, 22 + }; 23 + 24 + enum pca9685_inverted { 25 + PCA9685_NOT_INVERTED, 26 + PCA9685_INVERTED, 27 + }; 28 + 29 + struct pca9685_platform_data { 30 + struct led_platform_data leds; 31 + enum pca9685_outdrv outdrv; 32 + enum pca9685_inverted inverted; 33 + }; 34 + 35 + #endif /* __LINUX_PCA9685_H */