Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Simple driver for Texas Instruments LM3642 LED Flash driver chip |
| 4 | * Copyright (C) 2012 Texas Instruments |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 5 | */ |
| 6 | #include <linux/module.h> |
| 7 | #include <linux/delay.h> |
| 8 | #include <linux/i2c.h> |
| 9 | #include <linux/leds.h> |
| 10 | #include <linux/slab.h> |
| 11 | #include <linux/platform_device.h> |
| 12 | #include <linux/fs.h> |
| 13 | #include <linux/regmap.h> |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 14 | #include <linux/platform_data/leds-lm3642.h> |
| 15 | |
| 16 | #define REG_FILT_TIME (0x0) |
| 17 | #define REG_IVFM_MODE (0x1) |
| 18 | #define REG_TORCH_TIME (0x6) |
| 19 | #define REG_FLASH (0x8) |
| 20 | #define REG_I_CTRL (0x9) |
| 21 | #define REG_ENABLE (0xA) |
| 22 | #define REG_FLAG (0xB) |
| 23 | #define REG_MAX (0xB) |
| 24 | |
| 25 | #define UVLO_EN_SHIFT (7) |
| 26 | #define IVM_D_TH_SHIFT (2) |
| 27 | #define TORCH_RAMP_UP_TIME_SHIFT (3) |
| 28 | #define TORCH_RAMP_DN_TIME_SHIFT (0) |
| 29 | #define INDUCTOR_I_LIMIT_SHIFT (6) |
| 30 | #define FLASH_RAMP_TIME_SHIFT (3) |
| 31 | #define FLASH_TOUT_TIME_SHIFT (0) |
| 32 | #define TORCH_I_SHIFT (4) |
| 33 | #define FLASH_I_SHIFT (0) |
| 34 | #define IVFM_SHIFT (7) |
| 35 | #define TX_PIN_EN_SHIFT (6) |
| 36 | #define STROBE_PIN_EN_SHIFT (5) |
| 37 | #define TORCH_PIN_EN_SHIFT (4) |
| 38 | #define MODE_BITS_SHIFT (0) |
| 39 | |
| 40 | #define UVLO_EN_MASK (0x1) |
| 41 | #define IVM_D_TH_MASK (0x7) |
| 42 | #define TORCH_RAMP_UP_TIME_MASK (0x7) |
| 43 | #define TORCH_RAMP_DN_TIME_MASK (0x7) |
| 44 | #define INDUCTOR_I_LIMIT_MASK (0x1) |
| 45 | #define FLASH_RAMP_TIME_MASK (0x7) |
| 46 | #define FLASH_TOUT_TIME_MASK (0x7) |
| 47 | #define TORCH_I_MASK (0x7) |
| 48 | #define FLASH_I_MASK (0xF) |
| 49 | #define IVFM_MASK (0x1) |
| 50 | #define TX_PIN_EN_MASK (0x1) |
| 51 | #define STROBE_PIN_EN_MASK (0x1) |
| 52 | #define TORCH_PIN_EN_MASK (0x1) |
| 53 | #define MODE_BITS_MASK (0x73) |
| 54 | #define EX_PIN_CONTROL_MASK (0x71) |
| 55 | #define EX_PIN_ENABLE_MASK (0x70) |
| 56 | |
| 57 | enum lm3642_mode { |
| 58 | MODES_STASNDBY = 0, |
| 59 | MODES_INDIC, |
| 60 | MODES_TORCH, |
| 61 | MODES_FLASH |
| 62 | }; |
| 63 | |
| 64 | struct lm3642_chip_data { |
| 65 | struct device *dev; |
| 66 | |
| 67 | struct led_classdev cdev_flash; |
| 68 | struct led_classdev cdev_torch; |
| 69 | struct led_classdev cdev_indicator; |
| 70 | |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 71 | u8 br_flash; |
| 72 | u8 br_torch; |
| 73 | u8 br_indicator; |
| 74 | |
| 75 | enum lm3642_torch_pin_enable torch_pin; |
| 76 | enum lm3642_strobe_pin_enable strobe_pin; |
| 77 | enum lm3642_tx_pin_enable tx_pin; |
| 78 | |
| 79 | struct lm3642_platform_data *pdata; |
| 80 | struct regmap *regmap; |
| 81 | struct mutex lock; |
| 82 | |
| 83 | unsigned int last_flag; |
| 84 | }; |
| 85 | |
| 86 | /* chip initialize */ |
Bill Pemberton | 98ea1ea | 2012-11-19 13:23:02 -0500 | [diff] [blame] | 87 | static int lm3642_chip_init(struct lm3642_chip_data *chip) |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 88 | { |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 89 | int ret; |
| 90 | struct lm3642_platform_data *pdata = chip->pdata; |
| 91 | |
| 92 | /* set enable register */ |
Axel Lin | e76a322 | 2012-09-22 14:40:14 +0800 | [diff] [blame] | 93 | ret = regmap_update_bits(chip->regmap, REG_ENABLE, EX_PIN_ENABLE_MASK, |
| 94 | pdata->tx_pin); |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 95 | if (ret < 0) |
Axel Lin | e76a322 | 2012-09-22 14:40:14 +0800 | [diff] [blame] | 96 | dev_err(chip->dev, "Failed to update REG_ENABLE Register\n"); |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 97 | return ret; |
| 98 | } |
| 99 | |
| 100 | /* chip control */ |
| 101 | static int lm3642_control(struct lm3642_chip_data *chip, |
| 102 | u8 brightness, enum lm3642_mode opmode) |
| 103 | { |
| 104 | int ret; |
| 105 | |
| 106 | ret = regmap_read(chip->regmap, REG_FLAG, &chip->last_flag); |
| 107 | if (ret < 0) { |
| 108 | dev_err(chip->dev, "Failed to read REG_FLAG Register\n"); |
Pavel Machek | 867b682 | 2020-01-02 22:31:44 +0100 | [diff] [blame] | 109 | return ret; |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | if (chip->last_flag) |
| 113 | dev_info(chip->dev, "Last FLAG is 0x%x\n", chip->last_flag); |
| 114 | |
| 115 | /* brightness 0 means off-state */ |
| 116 | if (!brightness) |
| 117 | opmode = MODES_STASNDBY; |
| 118 | |
| 119 | switch (opmode) { |
| 120 | case MODES_TORCH: |
| 121 | ret = regmap_update_bits(chip->regmap, REG_I_CTRL, |
| 122 | TORCH_I_MASK << TORCH_I_SHIFT, |
| 123 | (brightness - 1) << TORCH_I_SHIFT); |
| 124 | |
| 125 | if (chip->torch_pin) |
| 126 | opmode |= (TORCH_PIN_EN_MASK << TORCH_PIN_EN_SHIFT); |
| 127 | break; |
| 128 | |
| 129 | case MODES_FLASH: |
| 130 | ret = regmap_update_bits(chip->regmap, REG_I_CTRL, |
| 131 | FLASH_I_MASK << FLASH_I_SHIFT, |
| 132 | (brightness - 1) << FLASH_I_SHIFT); |
| 133 | |
| 134 | if (chip->strobe_pin) |
| 135 | opmode |= (STROBE_PIN_EN_MASK << STROBE_PIN_EN_SHIFT); |
| 136 | break; |
| 137 | |
| 138 | case MODES_INDIC: |
| 139 | ret = regmap_update_bits(chip->regmap, REG_I_CTRL, |
| 140 | TORCH_I_MASK << TORCH_I_SHIFT, |
| 141 | (brightness - 1) << TORCH_I_SHIFT); |
| 142 | break; |
| 143 | |
| 144 | case MODES_STASNDBY: |
| 145 | |
| 146 | break; |
| 147 | |
| 148 | default: |
Pavel Machek | 867b682 | 2020-01-02 22:31:44 +0100 | [diff] [blame] | 149 | return -EINVAL; |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 150 | } |
| 151 | if (ret < 0) { |
| 152 | dev_err(chip->dev, "Failed to write REG_I_CTRL Register\n"); |
Pavel Machek | 867b682 | 2020-01-02 22:31:44 +0100 | [diff] [blame] | 153 | return ret; |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | if (chip->tx_pin) |
| 157 | opmode |= (TX_PIN_EN_MASK << TX_PIN_EN_SHIFT); |
| 158 | |
| 159 | ret = regmap_update_bits(chip->regmap, REG_ENABLE, |
| 160 | MODE_BITS_MASK << MODE_BITS_SHIFT, |
| 161 | opmode << MODE_BITS_SHIFT); |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 162 | return ret; |
| 163 | } |
| 164 | |
| 165 | /* torch */ |
| 166 | |
Pavel Machek | 867b682 | 2020-01-02 22:31:44 +0100 | [diff] [blame] | 167 | /* torch pin config for lm3642 */ |
Dwaipayan Ray | 5ccfa39 | 2020-12-14 11:12:05 +0530 | [diff] [blame] | 168 | static ssize_t torch_pin_store(struct device *dev, |
| 169 | struct device_attribute *attr, |
| 170 | const char *buf, size_t size) |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 171 | { |
| 172 | ssize_t ret; |
| 173 | struct led_classdev *led_cdev = dev_get_drvdata(dev); |
| 174 | struct lm3642_chip_data *chip = |
| 175 | container_of(led_cdev, struct lm3642_chip_data, cdev_indicator); |
| 176 | unsigned int state; |
| 177 | |
| 178 | ret = kstrtouint(buf, 10, &state); |
| 179 | if (ret) |
Pavel Machek | 867b682 | 2020-01-02 22:31:44 +0100 | [diff] [blame] | 180 | return ret; |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 181 | if (state != 0) |
| 182 | state = 0x01 << TORCH_PIN_EN_SHIFT; |
| 183 | |
| 184 | chip->torch_pin = state; |
| 185 | ret = regmap_update_bits(chip->regmap, REG_ENABLE, |
| 186 | TORCH_PIN_EN_MASK << TORCH_PIN_EN_SHIFT, |
| 187 | state); |
Pavel Machek | 867b682 | 2020-01-02 22:31:44 +0100 | [diff] [blame] | 188 | if (ret < 0) { |
| 189 | dev_err(chip->dev, "%s:i2c access fail to register\n", __func__); |
| 190 | return ret; |
| 191 | } |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 192 | |
| 193 | return size; |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 194 | } |
| 195 | |
Dwaipayan Ray | 5ccfa39 | 2020-12-14 11:12:05 +0530 | [diff] [blame] | 196 | static DEVICE_ATTR_WO(torch_pin); |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 197 | |
Andrew Lunn | bb58cc8 | 2015-08-20 12:05:54 +0200 | [diff] [blame] | 198 | static int lm3642_torch_brightness_set(struct led_classdev *cdev, |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 199 | enum led_brightness brightness) |
| 200 | { |
| 201 | struct lm3642_chip_data *chip = |
| 202 | container_of(cdev, struct lm3642_chip_data, cdev_torch); |
Andrew Lunn | bb58cc8 | 2015-08-20 12:05:54 +0200 | [diff] [blame] | 203 | int ret; |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 204 | |
Andrew Lunn | bb58cc8 | 2015-08-20 12:05:54 +0200 | [diff] [blame] | 205 | mutex_lock(&chip->lock); |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 206 | chip->br_torch = brightness; |
Andrew Lunn | bb58cc8 | 2015-08-20 12:05:54 +0200 | [diff] [blame] | 207 | ret = lm3642_control(chip, chip->br_torch, MODES_TORCH); |
| 208 | mutex_unlock(&chip->lock); |
| 209 | return ret; |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | /* flash */ |
| 213 | |
| 214 | /* strobe pin config for lm3642*/ |
Dwaipayan Ray | 5ccfa39 | 2020-12-14 11:12:05 +0530 | [diff] [blame] | 215 | static ssize_t strobe_pin_store(struct device *dev, |
| 216 | struct device_attribute *attr, |
| 217 | const char *buf, size_t size) |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 218 | { |
| 219 | ssize_t ret; |
| 220 | struct led_classdev *led_cdev = dev_get_drvdata(dev); |
| 221 | struct lm3642_chip_data *chip = |
| 222 | container_of(led_cdev, struct lm3642_chip_data, cdev_indicator); |
| 223 | unsigned int state; |
| 224 | |
| 225 | ret = kstrtouint(buf, 10, &state); |
| 226 | if (ret) |
Pavel Machek | 867b682 | 2020-01-02 22:31:44 +0100 | [diff] [blame] | 227 | return ret; |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 228 | if (state != 0) |
| 229 | state = 0x01 << STROBE_PIN_EN_SHIFT; |
| 230 | |
| 231 | chip->strobe_pin = state; |
| 232 | ret = regmap_update_bits(chip->regmap, REG_ENABLE, |
| 233 | STROBE_PIN_EN_MASK << STROBE_PIN_EN_SHIFT, |
| 234 | state); |
Pavel Machek | 867b682 | 2020-01-02 22:31:44 +0100 | [diff] [blame] | 235 | if (ret < 0) { |
| 236 | dev_err(chip->dev, "%s:i2c access fail to register\n", __func__); |
| 237 | return ret; |
| 238 | } |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 239 | |
| 240 | return size; |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 241 | } |
| 242 | |
Dwaipayan Ray | 5ccfa39 | 2020-12-14 11:12:05 +0530 | [diff] [blame] | 243 | static DEVICE_ATTR_WO(strobe_pin); |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 244 | |
Andrew Lunn | bb58cc8 | 2015-08-20 12:05:54 +0200 | [diff] [blame] | 245 | static int lm3642_strobe_brightness_set(struct led_classdev *cdev, |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 246 | enum led_brightness brightness) |
| 247 | { |
| 248 | struct lm3642_chip_data *chip = |
| 249 | container_of(cdev, struct lm3642_chip_data, cdev_flash); |
Andrew Lunn | bb58cc8 | 2015-08-20 12:05:54 +0200 | [diff] [blame] | 250 | int ret; |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 251 | |
Andrew Lunn | bb58cc8 | 2015-08-20 12:05:54 +0200 | [diff] [blame] | 252 | mutex_lock(&chip->lock); |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 253 | chip->br_flash = brightness; |
Andrew Lunn | bb58cc8 | 2015-08-20 12:05:54 +0200 | [diff] [blame] | 254 | ret = lm3642_control(chip, chip->br_flash, MODES_FLASH); |
| 255 | mutex_unlock(&chip->lock); |
| 256 | return ret; |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | /* indicator */ |
Andrew Lunn | bb58cc8 | 2015-08-20 12:05:54 +0200 | [diff] [blame] | 260 | static int lm3642_indicator_brightness_set(struct led_classdev *cdev, |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 261 | enum led_brightness brightness) |
| 262 | { |
| 263 | struct lm3642_chip_data *chip = |
| 264 | container_of(cdev, struct lm3642_chip_data, cdev_indicator); |
Andrew Lunn | bb58cc8 | 2015-08-20 12:05:54 +0200 | [diff] [blame] | 265 | int ret; |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 266 | |
Andrew Lunn | bb58cc8 | 2015-08-20 12:05:54 +0200 | [diff] [blame] | 267 | mutex_lock(&chip->lock); |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 268 | chip->br_indicator = brightness; |
Andrew Lunn | bb58cc8 | 2015-08-20 12:05:54 +0200 | [diff] [blame] | 269 | ret = lm3642_control(chip, chip->br_indicator, MODES_INDIC); |
| 270 | mutex_unlock(&chip->lock); |
| 271 | return ret; |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | static const struct regmap_config lm3642_regmap = { |
| 275 | .reg_bits = 8, |
| 276 | .val_bits = 8, |
| 277 | .max_register = REG_MAX, |
| 278 | }; |
| 279 | |
Johan Hovold | fe29a3b | 2014-06-25 10:08:48 -0700 | [diff] [blame] | 280 | static struct attribute *lm3642_flash_attrs[] = { |
| 281 | &dev_attr_strobe_pin.attr, |
| 282 | NULL |
| 283 | }; |
| 284 | ATTRIBUTE_GROUPS(lm3642_flash); |
| 285 | |
| 286 | static struct attribute *lm3642_torch_attrs[] = { |
| 287 | &dev_attr_torch_pin.attr, |
| 288 | NULL |
| 289 | }; |
| 290 | ATTRIBUTE_GROUPS(lm3642_torch); |
| 291 | |
Bill Pemberton | 98ea1ea | 2012-11-19 13:23:02 -0500 | [diff] [blame] | 292 | static int lm3642_probe(struct i2c_client *client, |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 293 | const struct i2c_device_id *id) |
| 294 | { |
Jingoo Han | 87aae1e | 2013-07-30 01:07:35 -0700 | [diff] [blame] | 295 | struct lm3642_platform_data *pdata = dev_get_platdata(&client->dev); |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 296 | struct lm3642_chip_data *chip; |
| 297 | |
| 298 | int err; |
| 299 | |
| 300 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { |
| 301 | dev_err(&client->dev, "i2c functionality check fail.\n"); |
| 302 | return -EOPNOTSUPP; |
| 303 | } |
| 304 | |
| 305 | if (pdata == NULL) { |
| 306 | dev_err(&client->dev, "needs Platform Data.\n"); |
| 307 | return -ENODATA; |
| 308 | } |
| 309 | |
| 310 | chip = devm_kzalloc(&client->dev, |
| 311 | sizeof(struct lm3642_chip_data), GFP_KERNEL); |
| 312 | if (!chip) |
| 313 | return -ENOMEM; |
| 314 | |
| 315 | chip->dev = &client->dev; |
| 316 | chip->pdata = pdata; |
| 317 | |
| 318 | chip->tx_pin = pdata->tx_pin; |
| 319 | chip->torch_pin = pdata->torch_pin; |
| 320 | chip->strobe_pin = pdata->strobe_pin; |
| 321 | |
| 322 | chip->regmap = devm_regmap_init_i2c(client, &lm3642_regmap); |
| 323 | if (IS_ERR(chip->regmap)) { |
| 324 | err = PTR_ERR(chip->regmap); |
| 325 | dev_err(&client->dev, "Failed to allocate register map: %d\n", |
| 326 | err); |
| 327 | return err; |
| 328 | } |
| 329 | |
| 330 | mutex_init(&chip->lock); |
| 331 | i2c_set_clientdata(client, chip); |
| 332 | |
| 333 | err = lm3642_chip_init(chip); |
| 334 | if (err < 0) |
| 335 | goto err_out; |
| 336 | |
| 337 | /* flash */ |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 338 | chip->cdev_flash.name = "flash"; |
| 339 | chip->cdev_flash.max_brightness = 16; |
Andrew Lunn | bb58cc8 | 2015-08-20 12:05:54 +0200 | [diff] [blame] | 340 | chip->cdev_flash.brightness_set_blocking = lm3642_strobe_brightness_set; |
Kim, Milo | 313bf0b | 2013-03-14 04:29:26 -0700 | [diff] [blame] | 341 | chip->cdev_flash.default_trigger = "flash"; |
Zheng Yongjun | fcc96ce | 2021-01-08 17:24:46 +0800 | [diff] [blame] | 342 | chip->cdev_flash.groups = lm3642_flash_groups; |
Johan Hovold | b5684a7 | 2020-06-01 15:39:50 +0200 | [diff] [blame] | 343 | err = led_classdev_register(&client->dev, &chip->cdev_flash); |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 344 | if (err < 0) { |
| 345 | dev_err(chip->dev, "failed to register flash\n"); |
| 346 | goto err_out; |
| 347 | } |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 348 | |
| 349 | /* torch */ |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 350 | chip->cdev_torch.name = "torch"; |
| 351 | chip->cdev_torch.max_brightness = 8; |
Andrew Lunn | bb58cc8 | 2015-08-20 12:05:54 +0200 | [diff] [blame] | 352 | chip->cdev_torch.brightness_set_blocking = lm3642_torch_brightness_set; |
Kim, Milo | 313bf0b | 2013-03-14 04:29:26 -0700 | [diff] [blame] | 353 | chip->cdev_torch.default_trigger = "torch"; |
Zheng Yongjun | fcc96ce | 2021-01-08 17:24:46 +0800 | [diff] [blame] | 354 | chip->cdev_torch.groups = lm3642_torch_groups; |
Johan Hovold | b5684a7 | 2020-06-01 15:39:50 +0200 | [diff] [blame] | 355 | err = led_classdev_register(&client->dev, &chip->cdev_torch); |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 356 | if (err < 0) { |
| 357 | dev_err(chip->dev, "failed to register torch\n"); |
| 358 | goto err_create_torch_file; |
| 359 | } |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 360 | |
| 361 | /* indicator */ |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 362 | chip->cdev_indicator.name = "indicator"; |
| 363 | chip->cdev_indicator.max_brightness = 8; |
Andrew Lunn | bb58cc8 | 2015-08-20 12:05:54 +0200 | [diff] [blame] | 364 | chip->cdev_indicator.brightness_set_blocking = |
| 365 | lm3642_indicator_brightness_set; |
Johan Hovold | b5684a7 | 2020-06-01 15:39:50 +0200 | [diff] [blame] | 366 | err = led_classdev_register(&client->dev, &chip->cdev_indicator); |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 367 | if (err < 0) { |
| 368 | dev_err(chip->dev, "failed to register indicator\n"); |
| 369 | goto err_create_indicator_file; |
| 370 | } |
| 371 | |
| 372 | dev_info(&client->dev, "LM3642 is initialized\n"); |
| 373 | return 0; |
| 374 | |
| 375 | err_create_indicator_file: |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 376 | led_classdev_unregister(&chip->cdev_torch); |
| 377 | err_create_torch_file: |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 378 | led_classdev_unregister(&chip->cdev_flash); |
| 379 | err_out: |
| 380 | return err; |
| 381 | } |
| 382 | |
Bill Pemberton | 678e8a6 | 2012-11-19 13:26:00 -0500 | [diff] [blame] | 383 | static int lm3642_remove(struct i2c_client *client) |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 384 | { |
| 385 | struct lm3642_chip_data *chip = i2c_get_clientdata(client); |
| 386 | |
| 387 | led_classdev_unregister(&chip->cdev_indicator); |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 388 | led_classdev_unregister(&chip->cdev_torch); |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 389 | led_classdev_unregister(&chip->cdev_flash); |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 390 | regmap_write(chip->regmap, REG_ENABLE, 0); |
| 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | static const struct i2c_device_id lm3642_id[] = { |
| 395 | {LM3642_NAME, 0}, |
| 396 | {} |
| 397 | }; |
| 398 | |
| 399 | MODULE_DEVICE_TABLE(i2c, lm3642_id); |
| 400 | |
| 401 | static struct i2c_driver lm3642_i2c_driver = { |
| 402 | .driver = { |
| 403 | .name = LM3642_NAME, |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 404 | .pm = NULL, |
| 405 | }, |
| 406 | .probe = lm3642_probe, |
Bill Pemberton | df07cf8 | 2012-11-19 13:20:20 -0500 | [diff] [blame] | 407 | .remove = lm3642_remove, |
G.Shark Jeong | 8b7cfbe | 2012-09-12 20:05:50 +0800 | [diff] [blame] | 408 | .id_table = lm3642_id, |
| 409 | }; |
| 410 | |
| 411 | module_i2c_driver(lm3642_i2c_driver); |
| 412 | |
| 413 | MODULE_DESCRIPTION("Texas Instruments Flash Lighting driver for LM3642"); |
| 414 | MODULE_AUTHOR("Daniel Jeong <daniel.jeong@ti.com>"); |
| 415 | MODULE_AUTHOR("G.Shark Jeong <gshark.jeong@gmail.com>"); |
| 416 | MODULE_LICENSE("GPL v2"); |