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

Merge tag 'leds_for_4.14' of git://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski/linux-leds

Pull LED updates from Jacek Anaszewski:
"LED class drivers improvements:

leds-pca955x:
- add Device Tree support and bindings
- use devm_led_classdev_register()
- add GPIO support
- prevent crippled LED class device name
- check for I2C errors

leds-gpio:
- add optional retain-state-shutdown DT property
- allow LED to retain state at shutdown

leds-tlc591xx:
- merge conditional tests
- add missing of_node_put

leds-powernv:
- delete an error message for a failed memory allocation in
powernv_led_create()

leds-is31fl32xx.c
- convert to using custom %pOF printf format specifier

Constify attribute_group structures in:
- leds-blinkm
- leds-lm3533

Make several arrays static const in:
- leds-aat1290
- leds-lp5521
- leds-lp5562
- leds-lp8501"

* tag 'leds_for_4.14' of git://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski/linux-leds:
leds: pca955x: check for I2C errors
leds: gpio: Allow LED to retain state at shutdown
dt-bindings: leds: gpio: Add optional retain-state-shutdown property
leds: powernv: Delete an error message for a failed memory allocation in powernv_led_create()
leds: lp8501: make several arrays static const
leds: lp5562: make several arrays static const
leds: lp5521: make several arrays static const
leds: aat1290: make array max_mm_current_percent static const
leds: pca955x: Prevent crippled LED device name
leds: lm3533: constify attribute_group structure
dt-bindings: leds: add pca955x
leds: pca955x: add GPIO support
leds: pca955x: use devm_led_classdev_register
leds: pca955x: add device tree support
leds: Convert to using %pOF instead of full_name
leds: blinkm: constify attribute_group structures.
leds: tlc591xx: add missing of_node_put
leds: tlc591xx: merge conditional tests

+438 -94
+3
Documentation/devicetree/bindings/leds/leds-gpio.txt
··· 18 18 see Documentation/devicetree/bindings/leds/common.txt 19 19 - retain-state-suspended: (optional) The suspend state can be retained.Such 20 20 as charge-led gpio. 21 + - retain-state-shutdown: (optional) Retain the state of the LED on shutdown. 22 + Useful in BMC systems, for example when the BMC is rebooted while the host 23 + remains up. 21 24 - panic-indicator : (optional) 22 25 see Documentation/devicetree/bindings/leds/common.txt 23 26
+88
Documentation/devicetree/bindings/leds/leds-pca955x.txt
··· 1 + * NXP - pca955x LED driver 2 + 3 + The PCA955x family of chips are I2C LED blinkers whose pins not used 4 + to control LEDs can be used as general purpose I/Os. The GPIO pins can 5 + be input or output, and output pins can also be pulse-width controlled. 6 + 7 + Required properties: 8 + - compatible : should be one of : 9 + "nxp,pca9550" 10 + "nxp,pca9551" 11 + "nxp,pca9552" 12 + "nxp,pca9553" 13 + - #address-cells: must be 1 14 + - #size-cells: must be 0 15 + - reg: I2C slave address. depends on the model. 16 + 17 + Optional properties: 18 + - gpio-controller: allows pins to be used as GPIOs. 19 + - #gpio-cells: must be 2. 20 + - gpio-line-names: define the names of the GPIO lines 21 + 22 + LED sub-node properties: 23 + - reg : number of LED line. 24 + from 0 to 1 for the pca9550 25 + from 0 to 7 for the pca9551 26 + from 0 to 15 for the pca9552 27 + from 0 to 3 for the pca9553 28 + - type: (optional) either 29 + PCA9532_TYPE_NONE 30 + PCA9532_TYPE_LED 31 + PCA9532_TYPE_GPIO 32 + see dt-bindings/leds/leds-pca955x.h (default to LED) 33 + - label : (optional) 34 + see Documentation/devicetree/bindings/leds/common.txt 35 + - linux,default-trigger : (optional) 36 + see Documentation/devicetree/bindings/leds/common.txt 37 + 38 + Examples: 39 + 40 + pca9552: pca9552@60 { 41 + compatible = "nxp,pca9552"; 42 + #address-cells = <1>; 43 + #size-cells = <0>; 44 + reg = <0x60>; 45 + 46 + gpio-controller; 47 + #gpio-cells = <2>; 48 + gpio-line-names = "GPIO12", "GPIO13", "GPIO14", "GPIO15"; 49 + 50 + gpio@12 { 51 + reg = <12>; 52 + type = <PCA955X_TYPE_GPIO>; 53 + }; 54 + gpio@13 { 55 + reg = <13>; 56 + type = <PCA955X_TYPE_GPIO>; 57 + }; 58 + gpio@14 { 59 + reg = <14>; 60 + type = <PCA955X_TYPE_GPIO>; 61 + }; 62 + gpio@15 { 63 + reg = <15>; 64 + type = <PCA955X_TYPE_GPIO>; 65 + }; 66 + 67 + led@0 { 68 + label = "red:power"; 69 + linux,default-trigger = "default-on"; 70 + reg = <0>; 71 + type = <PCA955X_TYPE_LED>; 72 + }; 73 + led@1 { 74 + label = "green:power"; 75 + reg = <1>; 76 + type = <PCA955X_TYPE_LED>; 77 + }; 78 + led@2 { 79 + label = "pca9552:yellow"; 80 + reg = <2>; 81 + type = <PCA955X_TYPE_LED>; 82 + }; 83 + led@3 { 84 + label = "pca9552:white"; 85 + reg = <3>; 86 + type = <PCA955X_TYPE_LED>; 87 + }; 88 + };
+11
drivers/leds/Kconfig
··· 386 386 LED driver chips accessed via the I2C bus. Supported 387 387 devices include PCA9550, PCA9551, PCA9552, and PCA9553. 388 388 389 + config LEDS_PCA955X_GPIO 390 + bool "Enable GPIO support for PCA955X" 391 + depends on LEDS_PCA955X 392 + depends on GPIOLIB 393 + help 394 + Allow unused pins on PCA955X to be used as gpio. 395 + 396 + To use a pin as gpio the pin type should be set to 397 + PCA955X_TYPE_GPIO in the device tree. 398 + 399 + 389 400 config LEDS_PCA963X 390 401 tristate "LED support for PCA963x I2C chip" 391 402 depends on LEDS_CLASS
+4 -2
drivers/leds/leds-aat1290.c
··· 314 314 static int init_mm_current_scale(struct aat1290_led *led, 315 315 struct aat1290_led_config_data *cfg) 316 316 { 317 - int max_mm_current_percent[] = { 20, 22, 25, 28, 32, 36, 40, 45, 50, 56, 318 - 63, 71, 79, 89, 100 }; 317 + static const int max_mm_current_percent[] = { 318 + 20, 22, 25, 28, 32, 36, 40, 45, 50, 56, 319 + 63, 71, 79, 89, 100 320 + }; 319 321 int i, max_mm_current = 320 322 AAT1290_MAX_MM_CURRENT(cfg->max_flash_current); 321 323
+1 -1
drivers/leds/leds-blinkm.c
··· 298 298 NULL, 299 299 }; 300 300 301 - static struct attribute_group blinkm_group = { 301 + static const struct attribute_group blinkm_group = { 302 302 .name = "blinkm", 303 303 .attrs = blinkm_attrs, 304 304 };
+6 -1
drivers/leds/leds-gpio.c
··· 134 134 led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME; 135 135 if (template->panic_indicator) 136 136 led_dat->cdev.flags |= LED_PANIC_INDICATOR; 137 + if (template->retain_state_shutdown) 138 + led_dat->cdev.flags |= LED_RETAIN_AT_SHUTDOWN; 137 139 138 140 ret = gpiod_direction_output(led_dat->gpiod, state); 139 141 if (ret < 0) ··· 207 205 208 206 if (fwnode_property_present(child, "retain-state-suspended")) 209 207 led.retain_state_suspended = 1; 208 + if (fwnode_property_present(child, "retain-state-shutdown")) 209 + led.retain_state_shutdown = 1; 210 210 if (fwnode_property_present(child, "panic-indicator")) 211 211 led.panic_indicator = 1; 212 212 ··· 271 267 for (i = 0; i < priv->num_leds; i++) { 272 268 struct gpio_led_data *led = &priv->leds[i]; 273 269 274 - gpio_led_set(&led->cdev, LED_OFF); 270 + if (!(led->cdev.flags & LED_RETAIN_AT_SHUTDOWN)) 271 + gpio_led_set(&led->cdev, LED_OFF); 275 272 } 276 273 } 277 274
+2 -2
drivers/leds/leds-is31fl32xx.c
··· 348 348 ret = of_property_read_u32(child, "reg", &reg); 349 349 if (ret || reg < 1 || reg > led_data->priv->cdef->channels) { 350 350 dev_err(dev, 351 - "Child node %s does not have a valid reg property\n", 352 - child->full_name); 351 + "Child node %pOF does not have a valid reg property\n", 352 + child); 353 353 return -EINVAL; 354 354 } 355 355 led_data->channel = reg;
+1 -1
drivers/leds/leds-lm3533.c
··· 626 626 return mode; 627 627 }; 628 628 629 - static struct attribute_group lm3533_led_attribute_group = { 629 + static const struct attribute_group lm3533_led_attribute_group = { 630 630 .is_visible = lm3533_led_attr_is_visible, 631 631 .attrs = lm3533_led_attributes 632 632 };
+4 -4
drivers/leds/leds-lp5521.c
··· 134 134 static void lp5521_load_engine(struct lp55xx_chip *chip) 135 135 { 136 136 enum lp55xx_engine_index idx = chip->engine_idx; 137 - u8 mask[] = { 137 + static const u8 mask[] = { 138 138 [LP55XX_ENGINE_1] = LP5521_MODE_R_M, 139 139 [LP55XX_ENGINE_2] = LP5521_MODE_G_M, 140 140 [LP55XX_ENGINE_3] = LP5521_MODE_B_M, 141 141 }; 142 142 143 - u8 val[] = { 143 + static const u8 val[] = { 144 144 [LP55XX_ENGINE_1] = LP5521_LOAD_R, 145 145 [LP55XX_ENGINE_2] = LP5521_LOAD_G, 146 146 [LP55XX_ENGINE_3] = LP5521_LOAD_B, ··· 160 160 static void lp5521_stop_engine(struct lp55xx_chip *chip) 161 161 { 162 162 enum lp55xx_engine_index idx = chip->engine_idx; 163 - u8 mask[] = { 163 + static const u8 mask[] = { 164 164 [LP55XX_ENGINE_1] = LP5521_MODE_R_M, 165 165 [LP55XX_ENGINE_2] = LP5521_MODE_G_M, 166 166 [LP55XX_ENGINE_3] = LP5521_MODE_B_M, ··· 226 226 { 227 227 enum lp55xx_engine_index idx = chip->engine_idx; 228 228 u8 pattern[LP5521_PROGRAM_LENGTH] = {0}; 229 - u8 addr[] = { 229 + static const u8 addr[] = { 230 230 [LP55XX_ENGINE_1] = LP5521_REG_R_PROG_MEM, 231 231 [LP55XX_ENGINE_2] = LP5521_REG_G_PROG_MEM, 232 232 [LP55XX_ENGINE_3] = LP5521_REG_B_PROG_MEM,
+5 -5
drivers/leds/leds-lp5562.c
··· 116 116 117 117 static void lp5562_set_led_current(struct lp55xx_led *led, u8 led_current) 118 118 { 119 - u8 addr[] = { 119 + static const u8 addr[] = { 120 120 LP5562_REG_R_CURRENT, 121 121 LP5562_REG_G_CURRENT, 122 122 LP5562_REG_B_CURRENT, ··· 130 130 static void lp5562_load_engine(struct lp55xx_chip *chip) 131 131 { 132 132 enum lp55xx_engine_index idx = chip->engine_idx; 133 - u8 mask[] = { 133 + static const u8 mask[] = { 134 134 [LP55XX_ENGINE_1] = LP5562_MODE_ENG1_M, 135 135 [LP55XX_ENGINE_2] = LP5562_MODE_ENG2_M, 136 136 [LP55XX_ENGINE_3] = LP5562_MODE_ENG3_M, 137 137 }; 138 138 139 - u8 val[] = { 139 + static const u8 val[] = { 140 140 [LP55XX_ENGINE_1] = LP5562_LOAD_ENG1, 141 141 [LP55XX_ENGINE_2] = LP5562_LOAD_ENG2, 142 142 [LP55XX_ENGINE_3] = LP5562_LOAD_ENG3, ··· 211 211 { 212 212 enum lp55xx_engine_index idx = chip->engine_idx; 213 213 u8 pattern[LP5562_PROGRAM_LENGTH] = {0}; 214 - u8 addr[] = { 214 + static const u8 addr[] = { 215 215 [LP55XX_ENGINE_1] = LP5562_REG_PROG_MEM_ENG1, 216 216 [LP55XX_ENGINE_2] = LP5562_REG_PROG_MEM_ENG2, 217 217 [LP55XX_ENGINE_3] = LP5562_REG_PROG_MEM_ENG3, ··· 314 314 static int lp5562_led_brightness(struct lp55xx_led *led) 315 315 { 316 316 struct lp55xx_chip *chip = led->chip; 317 - u8 addr[] = { 317 + static const u8 addr[] = { 318 318 LP5562_REG_R_PWM, 319 319 LP5562_REG_G_PWM, 320 320 LP5562_REG_B_PWM,
+3 -3
drivers/leds/leds-lp8501.c
··· 118 118 static void lp8501_load_engine(struct lp55xx_chip *chip) 119 119 { 120 120 enum lp55xx_engine_index idx = chip->engine_idx; 121 - u8 mask[] = { 121 + static const u8 mask[] = { 122 122 [LP55XX_ENGINE_1] = LP8501_MODE_ENG1_M, 123 123 [LP55XX_ENGINE_2] = LP8501_MODE_ENG2_M, 124 124 [LP55XX_ENGINE_3] = LP8501_MODE_ENG3_M, 125 125 }; 126 126 127 - u8 val[] = { 127 + static const u8 val[] = { 128 128 [LP55XX_ENGINE_1] = LP8501_LOAD_ENG1, 129 129 [LP55XX_ENGINE_2] = LP8501_LOAD_ENG2, 130 130 [LP55XX_ENGINE_3] = LP8501_LOAD_ENG3, 131 131 }; 132 132 133 - u8 page_sel[] = { 133 + static const u8 page_sel[] = { 134 134 [LP55XX_ENGINE_1] = LP8501_PAGE_ENG1, 135 135 [LP55XX_ENGINE_2] = LP8501_PAGE_ENG2, 136 136 [LP55XX_ENGINE_3] = LP8501_PAGE_ENG3,
+284 -66
drivers/leds/leds-pca955x.c
··· 41 41 */ 42 42 43 43 #include <linux/acpi.h> 44 - #include <linux/module.h> 45 - #include <linux/delay.h> 46 - #include <linux/string.h> 47 44 #include <linux/ctype.h> 48 - #include <linux/leds.h> 45 + #include <linux/delay.h> 49 46 #include <linux/err.h> 47 + #include <linux/gpio.h> 50 48 #include <linux/i2c.h> 49 + #include <linux/leds.h> 50 + #include <linux/module.h> 51 + #include <linux/of_device.h> 52 + #include <linux/of.h> 51 53 #include <linux/slab.h> 54 + #include <linux/string.h> 55 + 56 + #include <dt-bindings/leds/leds-pca955x.h> 52 57 53 58 /* LED select registers determine the source that drives LED outputs */ 54 59 #define PCA955X_LS_LED_ON 0x0 /* Output LOW */ ··· 120 115 struct pca955x_led *leds; 121 116 struct pca955x_chipdef *chipdef; 122 117 struct i2c_client *client; 118 + #ifdef CONFIG_LEDS_PCA955X_GPIO 119 + struct gpio_chip gpio; 120 + #endif 123 121 }; 124 122 125 123 struct pca955x_led { ··· 130 122 struct led_classdev led_cdev; 131 123 int led_num; /* 0 .. 15 potentially */ 132 124 char name[32]; 125 + u32 type; 126 + const char *default_trigger; 127 + }; 128 + 129 + struct pca955x_platform_data { 130 + struct pca955x_led *leds; 131 + int num_leds; 133 132 }; 134 133 135 134 /* 8 bits per input register */ ··· 165 150 * Write to frequency prescaler register, used to program the 166 151 * period of the PWM output. period = (PSCx + 1) / 38 167 152 */ 168 - static void pca955x_write_psc(struct i2c_client *client, int n, u8 val) 153 + static int pca955x_write_psc(struct i2c_client *client, int n, u8 val) 169 154 { 170 155 struct pca955x *pca955x = i2c_get_clientdata(client); 156 + int ret; 171 157 172 - i2c_smbus_write_byte_data(client, 158 + ret = i2c_smbus_write_byte_data(client, 173 159 pca95xx_num_input_regs(pca955x->chipdef->bits) + 2*n, 174 160 val); 161 + if (ret < 0) 162 + dev_err(&client->dev, "%s: reg 0x%x, val 0x%x, err %d\n", 163 + __func__, n, val, ret); 164 + return ret; 175 165 } 176 166 177 167 /* ··· 186 166 * 187 167 * Duty cycle is (256 - PWMx) / 256 188 168 */ 189 - static void pca955x_write_pwm(struct i2c_client *client, int n, u8 val) 169 + static int pca955x_write_pwm(struct i2c_client *client, int n, u8 val) 190 170 { 191 171 struct pca955x *pca955x = i2c_get_clientdata(client); 172 + int ret; 192 173 193 - i2c_smbus_write_byte_data(client, 174 + ret = i2c_smbus_write_byte_data(client, 194 175 pca95xx_num_input_regs(pca955x->chipdef->bits) + 1 + 2*n, 195 176 val); 177 + if (ret < 0) 178 + dev_err(&client->dev, "%s: reg 0x%x, val 0x%x, err %d\n", 179 + __func__, n, val, ret); 180 + return ret; 196 181 } 197 182 198 183 /* 199 184 * Write to LED selector register, which determines the source that 200 185 * drives the LED output. 201 186 */ 202 - static void pca955x_write_ls(struct i2c_client *client, int n, u8 val) 187 + static int pca955x_write_ls(struct i2c_client *client, int n, u8 val) 203 188 { 204 189 struct pca955x *pca955x = i2c_get_clientdata(client); 190 + int ret; 205 191 206 - i2c_smbus_write_byte_data(client, 192 + ret = i2c_smbus_write_byte_data(client, 207 193 pca95xx_num_input_regs(pca955x->chipdef->bits) + 4 + n, 208 194 val); 195 + if (ret < 0) 196 + dev_err(&client->dev, "%s: reg 0x%x, val 0x%x, err %d\n", 197 + __func__, n, val, ret); 198 + return ret; 209 199 } 210 200 211 201 /* 212 202 * Read the LED selector register, which determines the source that 213 203 * drives the LED output. 214 204 */ 215 - static u8 pca955x_read_ls(struct i2c_client *client, int n) 205 + static int pca955x_read_ls(struct i2c_client *client, int n, u8 *val) 216 206 { 217 207 struct pca955x *pca955x = i2c_get_clientdata(client); 208 + int ret; 218 209 219 - return (u8) i2c_smbus_read_byte_data(client, 210 + ret = i2c_smbus_read_byte_data(client, 220 211 pca95xx_num_input_regs(pca955x->chipdef->bits) + 4 + n); 212 + if (ret < 0) { 213 + dev_err(&client->dev, "%s: reg 0x%x, err %d\n", 214 + __func__, n, ret); 215 + return ret; 216 + } 217 + *val = (u8)ret; 218 + return 0; 221 219 } 222 220 223 221 static int pca955x_led_set(struct led_classdev *led_cdev, ··· 246 208 u8 ls; 247 209 int chip_ls; /* which LSx to use (0-3 potentially) */ 248 210 int ls_led; /* which set of bits within LSx to use (0-3) */ 211 + int ret; 249 212 250 213 pca955x_led = container_of(led_cdev, struct pca955x_led, led_cdev); 251 214 pca955x = pca955x_led->pca955x; ··· 256 217 257 218 mutex_lock(&pca955x->lock); 258 219 259 - ls = pca955x_read_ls(pca955x->client, chip_ls); 220 + ret = pca955x_read_ls(pca955x->client, chip_ls, &ls); 221 + if (ret) 222 + goto out; 260 223 261 224 switch (value) { 262 225 case LED_FULL: ··· 278 237 * OFF, HALF, or FULL. But, this is probably better than 279 238 * just turning off for all other values. 280 239 */ 281 - pca955x_write_pwm(pca955x->client, 1, 282 - 255 - value); 240 + ret = pca955x_write_pwm(pca955x->client, 1, 255 - value); 241 + if (ret) 242 + goto out; 283 243 ls = pca955x_ledsel(ls, ls_led, PCA955X_LS_BLINK1); 284 244 break; 285 245 } 286 246 287 - pca955x_write_ls(pca955x->client, chip_ls, ls); 247 + ret = pca955x_write_ls(pca955x->client, chip_ls, ls); 288 248 249 + out: 289 250 mutex_unlock(&pca955x->lock); 290 251 291 - return 0; 252 + return ret; 292 253 } 254 + 255 + #ifdef CONFIG_LEDS_PCA955X_GPIO 256 + /* 257 + * Read the INPUT register, which contains the state of LEDs. 258 + */ 259 + static int pca955x_read_input(struct i2c_client *client, int n, u8 *val) 260 + { 261 + int ret = i2c_smbus_read_byte_data(client, n); 262 + 263 + if (ret < 0) { 264 + dev_err(&client->dev, "%s: reg 0x%x, err %d\n", 265 + __func__, n, ret); 266 + return ret; 267 + } 268 + *val = (u8)ret; 269 + return 0; 270 + 271 + } 272 + 273 + static int pca955x_gpio_request_pin(struct gpio_chip *gc, unsigned int offset) 274 + { 275 + struct pca955x *pca955x = gpiochip_get_data(gc); 276 + struct pca955x_led *led = &pca955x->leds[offset]; 277 + 278 + if (led->type == PCA955X_TYPE_GPIO) 279 + return 0; 280 + 281 + return -EBUSY; 282 + } 283 + 284 + static int pca955x_set_value(struct gpio_chip *gc, unsigned int offset, 285 + int val) 286 + { 287 + struct pca955x *pca955x = gpiochip_get_data(gc); 288 + struct pca955x_led *led = &pca955x->leds[offset]; 289 + 290 + if (val) 291 + return pca955x_led_set(&led->led_cdev, LED_FULL); 292 + else 293 + return pca955x_led_set(&led->led_cdev, LED_OFF); 294 + } 295 + 296 + static void pca955x_gpio_set_value(struct gpio_chip *gc, unsigned int offset, 297 + int val) 298 + { 299 + pca955x_set_value(gc, offset, val); 300 + } 301 + 302 + static int pca955x_gpio_get_value(struct gpio_chip *gc, unsigned int offset) 303 + { 304 + struct pca955x *pca955x = gpiochip_get_data(gc); 305 + struct pca955x_led *led = &pca955x->leds[offset]; 306 + u8 reg = 0; 307 + 308 + /* There is nothing we can do about errors */ 309 + pca955x_read_input(pca955x->client, led->led_num / 8, &reg); 310 + 311 + return !!(reg & (1 << (led->led_num % 8))); 312 + } 313 + 314 + static int pca955x_gpio_direction_input(struct gpio_chip *gc, 315 + unsigned int offset) 316 + { 317 + /* To use as input ensure pin is not driven */ 318 + return pca955x_set_value(gc, offset, 0); 319 + } 320 + 321 + static int pca955x_gpio_direction_output(struct gpio_chip *gc, 322 + unsigned int offset, int val) 323 + { 324 + return pca955x_set_value(gc, offset, val); 325 + } 326 + #endif /* CONFIG_LEDS_PCA955X_GPIO */ 327 + 328 + #if IS_ENABLED(CONFIG_OF) 329 + static struct pca955x_platform_data * 330 + pca955x_pdata_of_init(struct i2c_client *client, struct pca955x_chipdef *chip) 331 + { 332 + struct device_node *np = client->dev.of_node; 333 + struct device_node *child; 334 + struct pca955x_platform_data *pdata; 335 + int count; 336 + 337 + count = of_get_child_count(np); 338 + if (!count || count > chip->bits) 339 + return ERR_PTR(-ENODEV); 340 + 341 + pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); 342 + if (!pdata) 343 + return ERR_PTR(-ENOMEM); 344 + 345 + pdata->leds = devm_kzalloc(&client->dev, 346 + sizeof(struct pca955x_led) * chip->bits, 347 + GFP_KERNEL); 348 + if (!pdata->leds) 349 + return ERR_PTR(-ENOMEM); 350 + 351 + for_each_child_of_node(np, child) { 352 + const char *name; 353 + u32 reg; 354 + int res; 355 + 356 + res = of_property_read_u32(child, "reg", &reg); 357 + if ((res != 0) || (reg >= chip->bits)) 358 + continue; 359 + 360 + if (of_property_read_string(child, "label", &name)) 361 + name = child->name; 362 + 363 + snprintf(pdata->leds[reg].name, sizeof(pdata->leds[reg].name), 364 + "%s", name); 365 + 366 + pdata->leds[reg].type = PCA955X_TYPE_LED; 367 + of_property_read_u32(child, "type", &pdata->leds[reg].type); 368 + of_property_read_string(child, "linux,default-trigger", 369 + &pdata->leds[reg].default_trigger); 370 + } 371 + 372 + pdata->num_leds = chip->bits; 373 + 374 + return pdata; 375 + } 376 + 377 + static const struct of_device_id of_pca955x_match[] = { 378 + { .compatible = "nxp,pca9550", .data = (void *)pca9550 }, 379 + { .compatible = "nxp,pca9551", .data = (void *)pca9551 }, 380 + { .compatible = "nxp,pca9552", .data = (void *)pca9552 }, 381 + { .compatible = "nxp,pca9553", .data = (void *)pca9553 }, 382 + {}, 383 + }; 384 + 385 + MODULE_DEVICE_TABLE(of, of_pca955x_match); 386 + #else 387 + static struct pca955x_platform_data * 388 + pca955x_pdata_of_init(struct i2c_client *client, struct pca955x_chipdef *chip) 389 + { 390 + return ERR_PTR(-ENODEV); 391 + } 392 + #endif 293 393 294 394 static int pca955x_probe(struct i2c_client *client, 295 395 const struct i2c_device_id *id) ··· 439 257 struct pca955x_led *pca955x_led; 440 258 struct pca955x_chipdef *chip; 441 259 struct i2c_adapter *adapter; 442 - struct led_platform_data *pdata; 443 260 int i, err; 261 + struct pca955x_platform_data *pdata; 262 + int ngpios = 0; 444 263 445 264 if (id) { 446 265 chip = &pca955x_chipdefs[id->driver_data]; ··· 455 272 } 456 273 adapter = to_i2c_adapter(client->dev.parent); 457 274 pdata = dev_get_platdata(&client->dev); 275 + if (!pdata) { 276 + pdata = pca955x_pdata_of_init(client, chip); 277 + if (IS_ERR(pdata)) 278 + return PTR_ERR(pdata); 279 + } 458 280 459 281 /* Make sure the slave address / chip type combo given is possible */ 460 282 if ((client->addr & ~((1 << chip->slv_addr_shift) - 1)) != ··· 476 288 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 477 289 return -EIO; 478 290 479 - if (pdata) { 480 - if (pdata->num_leds != chip->bits) { 481 - dev_err(&client->dev, "board info claims %d LEDs" 482 - " on a %d-bit chip\n", 483 - pdata->num_leds, chip->bits); 484 - return -ENODEV; 485 - } 291 + if (pdata->num_leds != chip->bits) { 292 + dev_err(&client->dev, 293 + "board info claims %d LEDs on a %d-bit chip\n", 294 + pdata->num_leds, chip->bits); 295 + return -ENODEV; 486 296 } 487 297 488 298 pca955x = devm_kzalloc(&client->dev, sizeof(*pca955x), GFP_KERNEL); ··· 502 316 pca955x_led = &pca955x->leds[i]; 503 317 pca955x_led->led_num = i; 504 318 pca955x_led->pca955x = pca955x; 319 + pca955x_led->type = pdata->leds[i].type; 505 320 506 - /* Platform data can specify LED names and default triggers */ 507 - if (pdata) { 508 - if (pdata->leds[i].name) 509 - snprintf(pca955x_led->name, 510 - sizeof(pca955x_led->name), "pca955x:%s", 511 - pdata->leds[i].name); 321 + switch (pca955x_led->type) { 322 + case PCA955X_TYPE_NONE: 323 + break; 324 + case PCA955X_TYPE_GPIO: 325 + ngpios++; 326 + break; 327 + case PCA955X_TYPE_LED: 328 + /* 329 + * Platform data can specify LED names and 330 + * default triggers 331 + */ 332 + if (pdata->leds[i].name[0] == '\0') 333 + snprintf(pdata->leds[i].name, 334 + sizeof(pdata->leds[i].name), "%d", i); 335 + 336 + snprintf(pca955x_led->name, 337 + sizeof(pca955x_led->name), "pca955x:%s", 338 + pdata->leds[i].name); 339 + 512 340 if (pdata->leds[i].default_trigger) 513 341 pca955x_led->led_cdev.default_trigger = 514 342 pdata->leds[i].default_trigger; 515 - } else { 516 - snprintf(pca955x_led->name, sizeof(pca955x_led->name), 517 - "pca955x:%d", i); 343 + 344 + pca955x_led->led_cdev.name = pca955x_led->name; 345 + pca955x_led->led_cdev.brightness_set_blocking = 346 + pca955x_led_set; 347 + 348 + err = devm_led_classdev_register(&client->dev, 349 + &pca955x_led->led_cdev); 350 + if (err) 351 + return err; 352 + 353 + /* Turn off LED */ 354 + err = pca955x_led_set(&pca955x_led->led_cdev, LED_OFF); 355 + if (err) 356 + return err; 518 357 } 519 - 520 - pca955x_led->led_cdev.name = pca955x_led->name; 521 - pca955x_led->led_cdev.brightness_set_blocking = pca955x_led_set; 522 - 523 - err = led_classdev_register(&client->dev, 524 - &pca955x_led->led_cdev); 525 - if (err < 0) 526 - goto exit; 527 358 } 528 359 529 - /* Turn off LEDs */ 530 - for (i = 0; i < pca95xx_num_led_regs(chip->bits); i++) 531 - pca955x_write_ls(client, i, 0x55); 532 - 533 360 /* PWM0 is used for half brightness or 50% duty cycle */ 534 - pca955x_write_pwm(client, 0, 255-LED_HALF); 361 + err = pca955x_write_pwm(client, 0, 255 - LED_HALF); 362 + if (err) 363 + return err; 535 364 536 365 /* PWM1 is used for variable brightness, default to OFF */ 537 - pca955x_write_pwm(client, 1, 0); 366 + err = pca955x_write_pwm(client, 1, 0); 367 + if (err) 368 + return err; 538 369 539 370 /* Set to fast frequency so we do not see flashing */ 540 - pca955x_write_psc(client, 0, 0); 541 - pca955x_write_psc(client, 1, 0); 371 + err = pca955x_write_psc(client, 0, 0); 372 + if (err) 373 + return err; 374 + err = pca955x_write_psc(client, 1, 0); 375 + if (err) 376 + return err; 542 377 543 - return 0; 378 + #ifdef CONFIG_LEDS_PCA955X_GPIO 379 + if (ngpios) { 380 + pca955x->gpio.label = "gpio-pca955x"; 381 + pca955x->gpio.direction_input = pca955x_gpio_direction_input; 382 + pca955x->gpio.direction_output = pca955x_gpio_direction_output; 383 + pca955x->gpio.set = pca955x_gpio_set_value; 384 + pca955x->gpio.get = pca955x_gpio_get_value; 385 + pca955x->gpio.request = pca955x_gpio_request_pin; 386 + pca955x->gpio.can_sleep = 1; 387 + pca955x->gpio.base = -1; 388 + pca955x->gpio.ngpio = ngpios; 389 + pca955x->gpio.parent = &client->dev; 390 + pca955x->gpio.owner = THIS_MODULE; 544 391 545 - exit: 546 - while (i--) 547 - led_classdev_unregister(&pca955x->leds[i].led_cdev); 548 - 549 - return err; 550 - } 551 - 552 - static int pca955x_remove(struct i2c_client *client) 553 - { 554 - struct pca955x *pca955x = i2c_get_clientdata(client); 555 - int i; 556 - 557 - for (i = 0; i < pca955x->chipdef->bits; i++) 558 - led_classdev_unregister(&pca955x->leds[i].led_cdev); 392 + err = devm_gpiochip_add_data(&client->dev, &pca955x->gpio, 393 + pca955x); 394 + if (err) { 395 + /* Use data->gpio.dev as a flag for freeing gpiochip */ 396 + pca955x->gpio.parent = NULL; 397 + dev_warn(&client->dev, "could not add gpiochip\n"); 398 + return err; 399 + } 400 + dev_info(&client->dev, "gpios %i...%i\n", 401 + pca955x->gpio.base, pca955x->gpio.base + 402 + pca955x->gpio.ngpio - 1); 403 + } 404 + #endif 559 405 560 406 return 0; 561 407 } ··· 596 378 .driver = { 597 379 .name = "leds-pca955x", 598 380 .acpi_match_table = ACPI_PTR(pca955x_acpi_ids), 381 + .of_match_table = of_match_ptr(of_pca955x_match), 599 382 }, 600 383 .probe = pca955x_probe, 601 - .remove = pca955x_remove, 602 384 .id_table = pca955x_id, 603 385 }; 604 386
+1 -5
drivers/leds/leds-powernv.c
··· 224 224 powernv_led->cdev.name = devm_kasprintf(dev, GFP_KERNEL, "%s:%s", 225 225 powernv_led->loc_code, 226 226 led_type_desc); 227 - if (!powernv_led->cdev.name) { 228 - dev_err(dev, 229 - "%s: Memory allocation failed for classdev name\n", 230 - __func__); 227 + if (!powernv_led->cdev.name) 231 228 return -ENOMEM; 232 - } 233 229 234 230 powernv_led->cdev.brightness_set_blocking = powernv_brightness_set; 235 231 powernv_led->cdev.brightness_get = powernv_brightness_get;
+7 -4
drivers/leds/leds-tlc591xx.c
··· 230 230 231 231 for_each_child_of_node(np, child) { 232 232 err = of_property_read_u32(child, "reg", &reg); 233 - if (err) 233 + if (err) { 234 + of_node_put(child); 234 235 return err; 235 - if (reg < 0 || reg >= tlc591xx->max_leds) 236 + } 237 + if (reg < 0 || reg >= tlc591xx->max_leds || 238 + priv->leds[reg].active) { 239 + of_node_put(child); 236 240 return -EINVAL; 237 - if (priv->leds[reg].active) 238 - return -EINVAL; 241 + } 239 242 priv->leds[reg].active = true; 240 243 priv->leds[reg].ldev.name = 241 244 of_get_property(child, "label", NULL) ? : child->name;
+16
include/dt-bindings/leds/leds-pca955x.h
··· 1 + /* 2 + * This header provides constants for pca955x LED bindings. 3 + * 4 + * This file is licensed under the terms of the GNU General Public 5 + * License version 2. This program is licensed "as is" without any 6 + * warranty of any kind, whether express or implied. 7 + */ 8 + 9 + #ifndef _DT_BINDINGS_LEDS_PCA955X_H 10 + #define _DT_BINDINGS_LEDS_PCA955X_H 11 + 12 + #define PCA955X_TYPE_NONE 0 13 + #define PCA955X_TYPE_LED 1 14 + #define PCA955X_TYPE_GPIO 2 15 + 16 + #endif /* _DT_BINDINGS_LEDS_PCA955X_H */
+2
include/linux/leds.h
··· 49 49 #define LED_HW_PLUGGABLE (1 << 19) 50 50 #define LED_PANIC_INDICATOR (1 << 20) 51 51 #define LED_BRIGHT_HW_CHANGED (1 << 21) 52 + #define LED_RETAIN_AT_SHUTDOWN (1 << 22) 52 53 53 54 /* set_brightness_work / blink_timer flags, atomic, private. */ 54 55 unsigned long work_flags; ··· 393 392 unsigned retain_state_suspended : 1; 394 393 unsigned panic_indicator : 1; 395 394 unsigned default_state : 2; 395 + unsigned retain_state_shutdown : 1; 396 396 /* default_state should be one of LEDS_GPIO_DEFSTATE_(ON|OFF|KEEP) */ 397 397 struct gpio_desc *gpiod; 398 398 };