| rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Simple driver for Texas Instruments LM355x LED Flash driver chip | 
|  | 3 | * Copyright (C) 2012 Texas Instruments | 
|  | 4 | * | 
|  | 5 | * This program is free software; you can redistribute it and/or modify | 
|  | 6 | * it under the terms of the GNU General Public License version 2 as | 
|  | 7 | * published by the Free Software Foundation. | 
|  | 8 | */ | 
|  | 9 |  | 
|  | 10 | #include <linux/module.h> | 
|  | 11 | #include <linux/delay.h> | 
|  | 12 | #include <linux/i2c.h> | 
|  | 13 | #include <linux/gpio.h> | 
|  | 14 | #include <linux/leds.h> | 
|  | 15 | #include <linux/slab.h> | 
|  | 16 | #include <linux/platform_device.h> | 
|  | 17 | #include <linux/fs.h> | 
|  | 18 | #include <linux/regmap.h> | 
|  | 19 | #include <linux/platform_data/leds-lm355x.h> | 
|  | 20 |  | 
|  | 21 | enum lm355x_type { | 
|  | 22 | CHIP_LM3554 = 0, | 
|  | 23 | CHIP_LM3556, | 
|  | 24 | }; | 
|  | 25 |  | 
|  | 26 | enum lm355x_regs { | 
|  | 27 | REG_FLAG = 0, | 
|  | 28 | REG_TORCH_CFG, | 
|  | 29 | REG_TORCH_CTRL, | 
|  | 30 | REG_STROBE_CFG, | 
|  | 31 | REG_FLASH_CTRL, | 
|  | 32 | REG_INDI_CFG, | 
|  | 33 | REG_INDI_CTRL, | 
|  | 34 | REG_OPMODE, | 
|  | 35 | REG_MAX, | 
|  | 36 | }; | 
|  | 37 |  | 
|  | 38 | /* operation mode */ | 
|  | 39 | enum lm355x_mode { | 
|  | 40 | MODE_SHDN = 0, | 
|  | 41 | MODE_INDIC, | 
|  | 42 | MODE_TORCH, | 
|  | 43 | MODE_FLASH | 
|  | 44 | }; | 
|  | 45 |  | 
|  | 46 | /* register map info. */ | 
|  | 47 | struct lm355x_reg_data { | 
|  | 48 | u8 regno; | 
|  | 49 | u8 mask; | 
|  | 50 | u8 shift; | 
|  | 51 | }; | 
|  | 52 |  | 
|  | 53 | struct lm355x_chip_data { | 
|  | 54 | struct device *dev; | 
|  | 55 | enum lm355x_type type; | 
|  | 56 |  | 
|  | 57 | struct led_classdev cdev_flash; | 
|  | 58 | struct led_classdev cdev_torch; | 
|  | 59 | struct led_classdev cdev_indicator; | 
|  | 60 |  | 
|  | 61 | struct lm355x_platform_data *pdata; | 
|  | 62 | struct regmap *regmap; | 
|  | 63 | struct mutex lock; | 
|  | 64 |  | 
|  | 65 | unsigned int last_flag; | 
|  | 66 | struct lm355x_reg_data *regs; | 
|  | 67 | }; | 
|  | 68 |  | 
|  | 69 | /* specific indicator function for lm3556 */ | 
|  | 70 | enum lm3556_indic_pulse_time { | 
|  | 71 | PULSE_TIME_0_MS = 0, | 
|  | 72 | PULSE_TIME_32_MS, | 
|  | 73 | PULSE_TIME_64_MS, | 
|  | 74 | PULSE_TIME_92_MS, | 
|  | 75 | PULSE_TIME_128_MS, | 
|  | 76 | PULSE_TIME_160_MS, | 
|  | 77 | PULSE_TIME_196_MS, | 
|  | 78 | PULSE_TIME_224_MS, | 
|  | 79 | PULSE_TIME_256_MS, | 
|  | 80 | PULSE_TIME_288_MS, | 
|  | 81 | PULSE_TIME_320_MS, | 
|  | 82 | PULSE_TIME_352_MS, | 
|  | 83 | PULSE_TIME_384_MS, | 
|  | 84 | PULSE_TIME_416_MS, | 
|  | 85 | PULSE_TIME_448_MS, | 
|  | 86 | PULSE_TIME_480_MS, | 
|  | 87 | }; | 
|  | 88 |  | 
|  | 89 | enum lm3556_indic_n_blank { | 
|  | 90 | INDIC_N_BLANK_0 = 0, | 
|  | 91 | INDIC_N_BLANK_1, | 
|  | 92 | INDIC_N_BLANK_2, | 
|  | 93 | INDIC_N_BLANK_3, | 
|  | 94 | INDIC_N_BLANK_4, | 
|  | 95 | INDIC_N_BLANK_5, | 
|  | 96 | INDIC_N_BLANK_6, | 
|  | 97 | INDIC_N_BLANK_7, | 
|  | 98 | INDIC_N_BLANK_8, | 
|  | 99 | INDIC_N_BLANK_9, | 
|  | 100 | INDIC_N_BLANK_10, | 
|  | 101 | INDIC_N_BLANK_11, | 
|  | 102 | INDIC_N_BLANK_12, | 
|  | 103 | INDIC_N_BLANK_13, | 
|  | 104 | INDIC_N_BLANK_14, | 
|  | 105 | INDIC_N_BLANK_15, | 
|  | 106 | }; | 
|  | 107 |  | 
|  | 108 | enum lm3556_indic_period { | 
|  | 109 | INDIC_PERIOD_0 = 0, | 
|  | 110 | INDIC_PERIOD_1, | 
|  | 111 | INDIC_PERIOD_2, | 
|  | 112 | INDIC_PERIOD_3, | 
|  | 113 | INDIC_PERIOD_4, | 
|  | 114 | INDIC_PERIOD_5, | 
|  | 115 | INDIC_PERIOD_6, | 
|  | 116 | INDIC_PERIOD_7, | 
|  | 117 | }; | 
|  | 118 |  | 
|  | 119 | #define INDIC_PATTERN_SIZE 4 | 
|  | 120 |  | 
|  | 121 | struct indicator { | 
|  | 122 | u8 blinking; | 
|  | 123 | u8 period_cnt; | 
|  | 124 | }; | 
|  | 125 |  | 
|  | 126 | /* indicator pattern data only for lm3556 */ | 
|  | 127 | static struct indicator indicator_pattern[INDIC_PATTERN_SIZE] = { | 
|  | 128 | [0] = {(INDIC_N_BLANK_1 << 4) | PULSE_TIME_32_MS, INDIC_PERIOD_1}, | 
|  | 129 | [1] = {(INDIC_N_BLANK_15 << 4) | PULSE_TIME_32_MS, INDIC_PERIOD_2}, | 
|  | 130 | [2] = {(INDIC_N_BLANK_10 << 4) | PULSE_TIME_32_MS, INDIC_PERIOD_4}, | 
|  | 131 | [3] = {(INDIC_N_BLANK_5 << 4) | PULSE_TIME_32_MS, INDIC_PERIOD_7}, | 
|  | 132 | }; | 
|  | 133 |  | 
|  | 134 | static struct lm355x_reg_data lm3554_regs[REG_MAX] = { | 
|  | 135 | [REG_FLAG] = {0xD0, 0xBF, 0}, | 
|  | 136 | [REG_TORCH_CFG] = {0xE0, 0x80, 7}, | 
|  | 137 | [REG_TORCH_CTRL] = {0xA0, 0x38, 3}, | 
|  | 138 | [REG_STROBE_CFG] = {0xE0, 0x04, 2}, | 
|  | 139 | [REG_FLASH_CTRL] = {0xB0, 0x78, 3}, | 
|  | 140 | [REG_INDI_CFG] = {0xE0, 0x08, 3}, | 
|  | 141 | [REG_INDI_CTRL] = {0xA0, 0xC0, 6}, | 
|  | 142 | [REG_OPMODE] = {0xA0, 0x03, 0}, | 
|  | 143 | }; | 
|  | 144 |  | 
|  | 145 | static struct lm355x_reg_data lm3556_regs[REG_MAX] = { | 
|  | 146 | [REG_FLAG] = {0x0B, 0xFF, 0}, | 
|  | 147 | [REG_TORCH_CFG] = {0x0A, 0x10, 4}, | 
|  | 148 | [REG_TORCH_CTRL] = {0x09, 0x70, 4}, | 
|  | 149 | [REG_STROBE_CFG] = {0x0A, 0x20, 5}, | 
|  | 150 | [REG_FLASH_CTRL] = {0x09, 0x0F, 0}, | 
|  | 151 | [REG_INDI_CFG] = {0xFF, 0xFF, 0}, | 
|  | 152 | [REG_INDI_CTRL] = {0x09, 0x70, 4}, | 
|  | 153 | [REG_OPMODE] = {0x0A, 0x03, 0}, | 
|  | 154 | }; | 
|  | 155 |  | 
|  | 156 | static char lm355x_name[][I2C_NAME_SIZE] = { | 
|  | 157 | [CHIP_LM3554] = LM3554_NAME, | 
|  | 158 | [CHIP_LM3556] = LM3556_NAME, | 
|  | 159 | }; | 
|  | 160 |  | 
|  | 161 | /* chip initialize */ | 
|  | 162 | static int lm355x_chip_init(struct lm355x_chip_data *chip) | 
|  | 163 | { | 
|  | 164 | int ret; | 
|  | 165 | unsigned int reg_val; | 
|  | 166 | struct lm355x_platform_data *pdata = chip->pdata; | 
|  | 167 |  | 
|  | 168 | /* input and output pins configuration */ | 
|  | 169 | switch (chip->type) { | 
|  | 170 | case CHIP_LM3554: | 
|  | 171 | reg_val = (u32)pdata->pin_tx2 | (u32)pdata->ntc_pin; | 
|  | 172 | ret = regmap_update_bits(chip->regmap, 0xE0, 0x28, reg_val); | 
|  | 173 | if (ret < 0) | 
|  | 174 | goto out; | 
|  | 175 | reg_val = (u32)pdata->pass_mode; | 
|  | 176 | ret = regmap_update_bits(chip->regmap, 0xA0, 0x04, reg_val); | 
|  | 177 | if (ret < 0) | 
|  | 178 | goto out; | 
|  | 179 | break; | 
|  | 180 |  | 
|  | 181 | case CHIP_LM3556: | 
|  | 182 | reg_val = (u32)pdata->pin_tx2 | (u32)pdata->ntc_pin | | 
|  | 183 | (u32)pdata->pass_mode; | 
|  | 184 | ret = regmap_update_bits(chip->regmap, 0x0A, 0xC4, reg_val); | 
|  | 185 | if (ret < 0) | 
|  | 186 | goto out; | 
|  | 187 | break; | 
|  | 188 | default: | 
|  | 189 | return -ENODATA; | 
|  | 190 | } | 
|  | 191 |  | 
|  | 192 | return ret; | 
|  | 193 | out: | 
|  | 194 | dev_err(chip->dev, "%s:i2c access fail to register\n", __func__); | 
|  | 195 | return ret; | 
|  | 196 | } | 
|  | 197 |  | 
|  | 198 | /* chip control */ | 
|  | 199 | static int lm355x_control(struct lm355x_chip_data *chip, | 
|  | 200 | u8 brightness, enum lm355x_mode opmode) | 
|  | 201 | { | 
|  | 202 | int ret; | 
|  | 203 | unsigned int reg_val; | 
|  | 204 | struct lm355x_platform_data *pdata = chip->pdata; | 
|  | 205 | struct lm355x_reg_data *preg = chip->regs; | 
|  | 206 |  | 
|  | 207 | ret = regmap_read(chip->regmap, preg[REG_FLAG].regno, &chip->last_flag); | 
|  | 208 | if (ret < 0) | 
|  | 209 | goto out; | 
|  | 210 | if (chip->last_flag & preg[REG_FLAG].mask) | 
|  | 211 | dev_info(chip->dev, "%s Last FLAG is 0x%x\n", | 
|  | 212 | lm355x_name[chip->type], | 
|  | 213 | chip->last_flag & preg[REG_FLAG].mask); | 
|  | 214 | /* brightness 0 means shutdown */ | 
|  | 215 | if (!brightness) | 
|  | 216 | opmode = MODE_SHDN; | 
|  | 217 |  | 
|  | 218 | switch (opmode) { | 
|  | 219 | case MODE_TORCH: | 
|  | 220 | ret = | 
|  | 221 | regmap_update_bits(chip->regmap, preg[REG_TORCH_CTRL].regno, | 
|  | 222 | preg[REG_TORCH_CTRL].mask, | 
|  | 223 | (brightness - 1) | 
|  | 224 | << preg[REG_TORCH_CTRL].shift); | 
|  | 225 | if (ret < 0) | 
|  | 226 | goto out; | 
|  | 227 |  | 
|  | 228 | if (pdata->pin_tx1 != LM355x_PIN_TORCH_DISABLE) { | 
|  | 229 | ret = | 
|  | 230 | regmap_update_bits(chip->regmap, | 
|  | 231 | preg[REG_TORCH_CFG].regno, | 
|  | 232 | preg[REG_TORCH_CFG].mask, | 
|  | 233 | 0x01 << | 
|  | 234 | preg[REG_TORCH_CFG].shift); | 
|  | 235 | if (ret < 0) | 
|  | 236 | goto out; | 
|  | 237 | opmode = MODE_SHDN; | 
|  | 238 | dev_info(chip->dev, | 
|  | 239 | "torch brt is set - ext. torch pin mode\n"); | 
|  | 240 | } | 
|  | 241 | break; | 
|  | 242 |  | 
|  | 243 | case MODE_FLASH: | 
|  | 244 |  | 
|  | 245 | ret = | 
|  | 246 | regmap_update_bits(chip->regmap, preg[REG_FLASH_CTRL].regno, | 
|  | 247 | preg[REG_FLASH_CTRL].mask, | 
|  | 248 | (brightness - 1) | 
|  | 249 | << preg[REG_FLASH_CTRL].shift); | 
|  | 250 | if (ret < 0) | 
|  | 251 | goto out; | 
|  | 252 |  | 
|  | 253 | if (pdata->pin_strobe != LM355x_PIN_STROBE_DISABLE) { | 
|  | 254 | if (chip->type == CHIP_LM3554) | 
|  | 255 | reg_val = 0x00; | 
|  | 256 | else | 
|  | 257 | reg_val = 0x01; | 
|  | 258 | ret = | 
|  | 259 | regmap_update_bits(chip->regmap, | 
|  | 260 | preg[REG_STROBE_CFG].regno, | 
|  | 261 | preg[REG_STROBE_CFG].mask, | 
|  | 262 | reg_val << | 
|  | 263 | preg[REG_STROBE_CFG].shift); | 
|  | 264 | if (ret < 0) | 
|  | 265 | goto out; | 
|  | 266 | opmode = MODE_SHDN; | 
|  | 267 | dev_info(chip->dev, | 
|  | 268 | "flash brt is set - ext. strobe pin mode\n"); | 
|  | 269 | } | 
|  | 270 | break; | 
|  | 271 |  | 
|  | 272 | case MODE_INDIC: | 
|  | 273 | ret = | 
|  | 274 | regmap_update_bits(chip->regmap, preg[REG_INDI_CTRL].regno, | 
|  | 275 | preg[REG_INDI_CTRL].mask, | 
|  | 276 | (brightness - 1) | 
|  | 277 | << preg[REG_INDI_CTRL].shift); | 
|  | 278 | if (ret < 0) | 
|  | 279 | goto out; | 
|  | 280 |  | 
|  | 281 | if (pdata->pin_tx2 != LM355x_PIN_TX_DISABLE) { | 
|  | 282 | ret = | 
|  | 283 | regmap_update_bits(chip->regmap, | 
|  | 284 | preg[REG_INDI_CFG].regno, | 
|  | 285 | preg[REG_INDI_CFG].mask, | 
|  | 286 | 0x01 << | 
|  | 287 | preg[REG_INDI_CFG].shift); | 
|  | 288 | if (ret < 0) | 
|  | 289 | goto out; | 
|  | 290 | opmode = MODE_SHDN; | 
|  | 291 | } | 
|  | 292 | break; | 
|  | 293 | case MODE_SHDN: | 
|  | 294 | break; | 
|  | 295 | default: | 
|  | 296 | return -EINVAL; | 
|  | 297 | } | 
|  | 298 | /* operation mode control */ | 
|  | 299 | ret = regmap_update_bits(chip->regmap, preg[REG_OPMODE].regno, | 
|  | 300 | preg[REG_OPMODE].mask, | 
|  | 301 | opmode << preg[REG_OPMODE].shift); | 
|  | 302 | if (ret < 0) | 
|  | 303 | goto out; | 
|  | 304 | return ret; | 
|  | 305 | out: | 
|  | 306 | dev_err(chip->dev, "%s:i2c access fail to register\n", __func__); | 
|  | 307 | return ret; | 
|  | 308 | } | 
|  | 309 |  | 
|  | 310 | /* torch */ | 
|  | 311 |  | 
|  | 312 | static int lm355x_torch_brightness_set(struct led_classdev *cdev, | 
|  | 313 | enum led_brightness brightness) | 
|  | 314 | { | 
|  | 315 | struct lm355x_chip_data *chip = | 
|  | 316 | container_of(cdev, struct lm355x_chip_data, cdev_torch); | 
|  | 317 | int ret; | 
|  | 318 |  | 
|  | 319 | mutex_lock(&chip->lock); | 
|  | 320 | ret = lm355x_control(chip, brightness, MODE_TORCH); | 
|  | 321 | mutex_unlock(&chip->lock); | 
|  | 322 | return ret; | 
|  | 323 | } | 
|  | 324 |  | 
|  | 325 | /* flash */ | 
|  | 326 |  | 
|  | 327 | static int lm355x_strobe_brightness_set(struct led_classdev *cdev, | 
|  | 328 | enum led_brightness brightness) | 
|  | 329 | { | 
|  | 330 | struct lm355x_chip_data *chip = | 
|  | 331 | container_of(cdev, struct lm355x_chip_data, cdev_flash); | 
|  | 332 | int ret; | 
|  | 333 |  | 
|  | 334 | mutex_lock(&chip->lock); | 
|  | 335 | ret = lm355x_control(chip, brightness, MODE_FLASH); | 
|  | 336 | mutex_unlock(&chip->lock); | 
|  | 337 | return ret; | 
|  | 338 | } | 
|  | 339 |  | 
|  | 340 | /* indicator */ | 
|  | 341 |  | 
|  | 342 | static int lm355x_indicator_brightness_set(struct led_classdev *cdev, | 
|  | 343 | enum led_brightness brightness) | 
|  | 344 | { | 
|  | 345 | struct lm355x_chip_data *chip = | 
|  | 346 | container_of(cdev, struct lm355x_chip_data, cdev_indicator); | 
|  | 347 | int ret; | 
|  | 348 |  | 
|  | 349 | mutex_lock(&chip->lock); | 
|  | 350 | ret = lm355x_control(chip, brightness, MODE_INDIC); | 
|  | 351 | mutex_unlock(&chip->lock); | 
|  | 352 | return ret; | 
|  | 353 | } | 
|  | 354 |  | 
|  | 355 | /* indicator pattern only for lm3556*/ | 
|  | 356 | static ssize_t lm3556_indicator_pattern_store(struct device *dev, | 
|  | 357 | struct device_attribute *attr, | 
|  | 358 | const char *buf, size_t size) | 
|  | 359 | { | 
|  | 360 | ssize_t ret; | 
|  | 361 | struct led_classdev *led_cdev = dev_get_drvdata(dev); | 
|  | 362 | struct lm355x_chip_data *chip = | 
|  | 363 | container_of(led_cdev, struct lm355x_chip_data, cdev_indicator); | 
|  | 364 | unsigned int state; | 
|  | 365 |  | 
|  | 366 | ret = kstrtouint(buf, 10, &state); | 
|  | 367 | if (ret) | 
|  | 368 | goto out; | 
|  | 369 | if (state > INDIC_PATTERN_SIZE - 1) | 
|  | 370 | state = INDIC_PATTERN_SIZE - 1; | 
|  | 371 |  | 
|  | 372 | ret = regmap_write(chip->regmap, 0x04, | 
|  | 373 | indicator_pattern[state].blinking); | 
|  | 374 | if (ret < 0) | 
|  | 375 | goto out; | 
|  | 376 |  | 
|  | 377 | ret = regmap_write(chip->regmap, 0x05, | 
|  | 378 | indicator_pattern[state].period_cnt); | 
|  | 379 | if (ret < 0) | 
|  | 380 | goto out; | 
|  | 381 |  | 
|  | 382 | return size; | 
|  | 383 | out: | 
|  | 384 | dev_err(chip->dev, "%s:i2c access fail to register\n", __func__); | 
|  | 385 | return ret; | 
|  | 386 | } | 
|  | 387 |  | 
|  | 388 | static DEVICE_ATTR(pattern, S_IWUSR, NULL, lm3556_indicator_pattern_store); | 
|  | 389 |  | 
|  | 390 | static struct attribute *lm355x_indicator_attrs[] = { | 
|  | 391 | &dev_attr_pattern.attr, | 
|  | 392 | NULL | 
|  | 393 | }; | 
|  | 394 | ATTRIBUTE_GROUPS(lm355x_indicator); | 
|  | 395 |  | 
|  | 396 | static const struct regmap_config lm355x_regmap = { | 
|  | 397 | .reg_bits = 8, | 
|  | 398 | .val_bits = 8, | 
|  | 399 | .max_register = 0xFF, | 
|  | 400 | }; | 
|  | 401 |  | 
|  | 402 | /* module initialize */ | 
|  | 403 | static int lm355x_probe(struct i2c_client *client, | 
|  | 404 | const struct i2c_device_id *id) | 
|  | 405 | { | 
|  | 406 | struct lm355x_platform_data *pdata = dev_get_platdata(&client->dev); | 
|  | 407 | struct lm355x_chip_data *chip; | 
|  | 408 |  | 
|  | 409 | int err; | 
|  | 410 |  | 
|  | 411 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { | 
|  | 412 | dev_err(&client->dev, "i2c functionality check fail.\n"); | 
|  | 413 | return -EOPNOTSUPP; | 
|  | 414 | } | 
|  | 415 |  | 
|  | 416 | if (pdata == NULL) { | 
|  | 417 | dev_err(&client->dev, "needs Platform Data.\n"); | 
|  | 418 | return -ENODATA; | 
|  | 419 | } | 
|  | 420 |  | 
|  | 421 | chip = devm_kzalloc(&client->dev, | 
|  | 422 | sizeof(struct lm355x_chip_data), GFP_KERNEL); | 
|  | 423 | if (!chip) | 
|  | 424 | return -ENOMEM; | 
|  | 425 |  | 
|  | 426 | chip->dev = &client->dev; | 
|  | 427 | chip->type = id->driver_data; | 
|  | 428 | switch (id->driver_data) { | 
|  | 429 | case CHIP_LM3554: | 
|  | 430 | chip->regs = lm3554_regs; | 
|  | 431 | break; | 
|  | 432 | case CHIP_LM3556: | 
|  | 433 | chip->regs = lm3556_regs; | 
|  | 434 | break; | 
|  | 435 | default: | 
|  | 436 | return -ENOSYS; | 
|  | 437 | } | 
|  | 438 | chip->pdata = pdata; | 
|  | 439 |  | 
|  | 440 | chip->regmap = devm_regmap_init_i2c(client, &lm355x_regmap); | 
|  | 441 | if (IS_ERR(chip->regmap)) { | 
|  | 442 | err = PTR_ERR(chip->regmap); | 
|  | 443 | dev_err(&client->dev, | 
|  | 444 | "Failed to allocate register map: %d\n", err); | 
|  | 445 | return err; | 
|  | 446 | } | 
|  | 447 |  | 
|  | 448 | mutex_init(&chip->lock); | 
|  | 449 | i2c_set_clientdata(client, chip); | 
|  | 450 |  | 
|  | 451 | err = lm355x_chip_init(chip); | 
|  | 452 | if (err < 0) | 
|  | 453 | goto err_out; | 
|  | 454 |  | 
|  | 455 | /* flash */ | 
|  | 456 | chip->cdev_flash.name = "flash"; | 
|  | 457 | chip->cdev_flash.max_brightness = 16; | 
|  | 458 | chip->cdev_flash.brightness_set_blocking = lm355x_strobe_brightness_set; | 
|  | 459 | chip->cdev_flash.default_trigger = "flash"; | 
|  | 460 | err = led_classdev_register((struct device *) | 
|  | 461 | &client->dev, &chip->cdev_flash); | 
|  | 462 | if (err < 0) | 
|  | 463 | goto err_out; | 
|  | 464 | /* torch */ | 
|  | 465 | chip->cdev_torch.name = "torch"; | 
|  | 466 | chip->cdev_torch.max_brightness = 8; | 
|  | 467 | chip->cdev_torch.brightness_set_blocking = lm355x_torch_brightness_set; | 
|  | 468 | chip->cdev_torch.default_trigger = "torch"; | 
|  | 469 | err = led_classdev_register((struct device *) | 
|  | 470 | &client->dev, &chip->cdev_torch); | 
|  | 471 | if (err < 0) | 
|  | 472 | goto err_create_torch_file; | 
|  | 473 | /* indicator */ | 
|  | 474 | chip->cdev_indicator.name = "indicator"; | 
|  | 475 | if (id->driver_data == CHIP_LM3554) | 
|  | 476 | chip->cdev_indicator.max_brightness = 4; | 
|  | 477 | else | 
|  | 478 | chip->cdev_indicator.max_brightness = 8; | 
|  | 479 | chip->cdev_indicator.brightness_set_blocking = | 
|  | 480 | lm355x_indicator_brightness_set; | 
|  | 481 | /* indicator pattern control only for LM3556 */ | 
|  | 482 | if (id->driver_data == CHIP_LM3556) | 
|  | 483 | chip->cdev_indicator.groups = lm355x_indicator_groups; | 
|  | 484 | err = led_classdev_register((struct device *) | 
|  | 485 | &client->dev, &chip->cdev_indicator); | 
|  | 486 | if (err < 0) | 
|  | 487 | goto err_create_indicator_file; | 
|  | 488 |  | 
|  | 489 | dev_info(&client->dev, "%s is initialized\n", | 
|  | 490 | lm355x_name[id->driver_data]); | 
|  | 491 | return 0; | 
|  | 492 |  | 
|  | 493 | err_create_indicator_file: | 
|  | 494 | led_classdev_unregister(&chip->cdev_torch); | 
|  | 495 | err_create_torch_file: | 
|  | 496 | led_classdev_unregister(&chip->cdev_flash); | 
|  | 497 | err_out: | 
|  | 498 | return err; | 
|  | 499 | } | 
|  | 500 |  | 
|  | 501 | static int lm355x_remove(struct i2c_client *client) | 
|  | 502 | { | 
|  | 503 | struct lm355x_chip_data *chip = i2c_get_clientdata(client); | 
|  | 504 | struct lm355x_reg_data *preg = chip->regs; | 
|  | 505 |  | 
|  | 506 | regmap_write(chip->regmap, preg[REG_OPMODE].regno, 0); | 
|  | 507 | led_classdev_unregister(&chip->cdev_indicator); | 
|  | 508 | led_classdev_unregister(&chip->cdev_torch); | 
|  | 509 | led_classdev_unregister(&chip->cdev_flash); | 
|  | 510 | dev_info(&client->dev, "%s is removed\n", lm355x_name[chip->type]); | 
|  | 511 |  | 
|  | 512 | return 0; | 
|  | 513 | } | 
|  | 514 |  | 
|  | 515 | static const struct i2c_device_id lm355x_id[] = { | 
|  | 516 | {LM3554_NAME, CHIP_LM3554}, | 
|  | 517 | {LM3556_NAME, CHIP_LM3556}, | 
|  | 518 | {} | 
|  | 519 | }; | 
|  | 520 |  | 
|  | 521 | MODULE_DEVICE_TABLE(i2c, lm355x_id); | 
|  | 522 |  | 
|  | 523 | static struct i2c_driver lm355x_i2c_driver = { | 
|  | 524 | .driver = { | 
|  | 525 | .name = LM355x_NAME, | 
|  | 526 | .pm = NULL, | 
|  | 527 | }, | 
|  | 528 | .probe = lm355x_probe, | 
|  | 529 | .remove = lm355x_remove, | 
|  | 530 | .id_table = lm355x_id, | 
|  | 531 | }; | 
|  | 532 |  | 
|  | 533 | module_i2c_driver(lm355x_i2c_driver); | 
|  | 534 |  | 
|  | 535 | MODULE_DESCRIPTION("Texas Instruments Flash Lighting driver for LM355x"); | 
|  | 536 | MODULE_AUTHOR("Daniel Jeong <daniel.jeong@ti.com>"); | 
|  | 537 | MODULE_AUTHOR("G.Shark Jeong <gshark.jeong@gmail.com>"); | 
|  | 538 | MODULE_LICENSE("GPL v2"); |