Thomas Gleixner | 09c434b | 2019-05-19 13:08:20 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 2 | /* |
| 3 | * leds-tca6507 |
| 4 | * |
| 5 | * The TCA6507 is a programmable LED controller that can drive 7 |
| 6 | * separate lines either by holding them low, or by pulsing them |
| 7 | * with modulated width. |
NeilBrown | 1f431af | 2013-11-12 21:52:43 -0800 | [diff] [blame] | 8 | * The modulation can be varied in a simple pattern to produce a |
| 9 | * blink or double-blink. |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 10 | * |
NeilBrown | 1f431af | 2013-11-12 21:52:43 -0800 | [diff] [blame] | 11 | * This driver can configure each line either as a 'GPIO' which is |
| 12 | * out-only (pull-up resistor required) or as an LED with variable |
| 13 | * brightness and hardware-assisted blinking. |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 14 | * |
NeilBrown | 1f431af | 2013-11-12 21:52:43 -0800 | [diff] [blame] | 15 | * Apart from OFF and ON there are three programmable brightness |
| 16 | * levels which can be programmed from 0 to 15 and indicate how many |
| 17 | * 500usec intervals in each 8msec that the led is 'on'. The levels |
| 18 | * are named MASTER, BANK0 and BANK1. |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 19 | * |
NeilBrown | 1f431af | 2013-11-12 21:52:43 -0800 | [diff] [blame] | 20 | * There are two different blink rates that can be programmed, each |
| 21 | * with separate time for rise, on, fall, off and second-off. Thus if |
| 22 | * 3 or more different non-trivial rates are required, software must |
| 23 | * be used for the extra rates. The two different blink rates must |
| 24 | * align with the two levels BANK0 and BANK1. This driver does not |
| 25 | * support double-blink so 'second-off' always matches 'off'. |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 26 | * |
NeilBrown | 1f431af | 2013-11-12 21:52:43 -0800 | [diff] [blame] | 27 | * Only 16 different times can be programmed in a roughly logarithmic |
| 28 | * scale from 64ms to 16320ms. To be precise the possible times are: |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 29 | * 0, 64, 128, 192, 256, 384, 512, 768, |
| 30 | * 1024, 1536, 2048, 3072, 4096, 5760, 8128, 16320 |
| 31 | * |
NeilBrown | 1f431af | 2013-11-12 21:52:43 -0800 | [diff] [blame] | 32 | * Times that cannot be closely matched with these must be handled in |
| 33 | * software. This driver allows 12.5% error in matching. |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 34 | * |
NeilBrown | 1f431af | 2013-11-12 21:52:43 -0800 | [diff] [blame] | 35 | * This driver does not allow rise/fall rates to be set explicitly. |
| 36 | * When trying to match a given 'on' or 'off' period, an appropriate |
| 37 | * pair of 'change' and 'hold' times are chosen to get a close match. |
| 38 | * If the target delay is even, the 'change' number will be the |
| 39 | * smaller; if odd, the 'hold' number will be the smaller. |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 40 | |
NeilBrown | 1f431af | 2013-11-12 21:52:43 -0800 | [diff] [blame] | 41 | * Choosing pairs of delays with 12.5% errors allows us to match |
| 42 | * delays in the ranges: 56-72, 112-144, 168-216, 224-27504, |
| 43 | * 28560-36720. |
| 44 | * 26% of the achievable sums can be matched by multiple pairings. |
| 45 | * For example 1536 == 1536+0, 1024+512, or 768+768. |
| 46 | * This driver will always choose the pairing with the least |
| 47 | * maximum - 768+768 in this case. Other pairings are not available. |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 48 | * |
NeilBrown | 1f431af | 2013-11-12 21:52:43 -0800 | [diff] [blame] | 49 | * Access to the 3 levels and 2 blinks are on a first-come, |
| 50 | * first-served basis. Access can be shared by multiple leds if they |
| 51 | * have the same level and either same blink rates, or some don't |
| 52 | * blink. When a led changes, it relinquishes access and tries again, |
| 53 | * so it might lose access to hardware blink. |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 54 | * |
NeilBrown | 1f431af | 2013-11-12 21:52:43 -0800 | [diff] [blame] | 55 | * If a blink engine cannot be allocated, software blink is used. If |
| 56 | * the desired brightness cannot be allocated, the closest available |
| 57 | * non-zero brightness is used. As 'full' is always available, the |
| 58 | * worst case would be to have two different blink rates at '1', with |
| 59 | * Max at '2', then other leds will have to choose between '2' and |
| 60 | * '16'. Hopefully this is not likely. |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 61 | * |
NeilBrown | 1f431af | 2013-11-12 21:52:43 -0800 | [diff] [blame] | 62 | * Each bank (BANK0 and BANK1) has two usage counts - LEDs using the |
| 63 | * brightness and LEDs using the blink. It can only be reprogrammed |
| 64 | * when the appropriate counter is zero. The MASTER level has a |
| 65 | * single usage count. |
| 66 | * |
| 67 | * Each LED has programmable 'on' and 'off' time as milliseconds. |
| 68 | * With each there is a flag saying if it was explicitly requested or |
| 69 | * defaulted. Similarly the banks know if each time was explicit or a |
| 70 | * default. Defaults are permitted to be changed freely - they are |
| 71 | * not recognised when matching. |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 72 | */ |
| 73 | |
| 74 | #include <linux/module.h> |
| 75 | #include <linux/slab.h> |
| 76 | #include <linux/leds.h> |
| 77 | #include <linux/err.h> |
| 78 | #include <linux/i2c.h> |
Linus Walleij | ca99522 | 2020-04-15 17:08:37 +0200 | [diff] [blame] | 79 | #include <linux/gpio/driver.h> |
Marek Behún | 96f5241 | 2020-09-20 00:15:37 +0200 | [diff] [blame] | 80 | #include <linux/property.h> |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 81 | #include <linux/workqueue.h> |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 82 | |
| 83 | /* LED select registers determine the source that drives LED outputs */ |
| 84 | #define TCA6507_LS_LED_OFF 0x0 /* Output HI-Z (off) */ |
| 85 | #define TCA6507_LS_LED_OFF1 0x1 /* Output HI-Z (off) - not used */ |
| 86 | #define TCA6507_LS_LED_PWM0 0x2 /* Output LOW with Bank0 rate */ |
| 87 | #define TCA6507_LS_LED_PWM1 0x3 /* Output LOW with Bank1 rate */ |
| 88 | #define TCA6507_LS_LED_ON 0x4 /* Output LOW (on) */ |
| 89 | #define TCA6507_LS_LED_MIR 0x5 /* Output LOW with Master Intensity */ |
| 90 | #define TCA6507_LS_BLINK0 0x6 /* Blink at Bank0 rate */ |
| 91 | #define TCA6507_LS_BLINK1 0x7 /* Blink at Bank1 rate */ |
| 92 | |
Marek Behún | 38b393f | 2020-09-20 00:15:36 +0200 | [diff] [blame] | 93 | struct tca6507_platform_data { |
| 94 | struct led_platform_data leds; |
| 95 | #ifdef CONFIG_GPIOLIB |
| 96 | int gpio_base; |
Marek Behún | 38b393f | 2020-09-20 00:15:36 +0200 | [diff] [blame] | 97 | #endif |
| 98 | }; |
| 99 | |
| 100 | #define TCA6507_MAKE_GPIO 1 |
| 101 | |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 102 | enum { |
| 103 | BANK0, |
| 104 | BANK1, |
| 105 | MASTER, |
| 106 | }; |
| 107 | static int bank_source[3] = { |
| 108 | TCA6507_LS_LED_PWM0, |
| 109 | TCA6507_LS_LED_PWM1, |
| 110 | TCA6507_LS_LED_MIR, |
| 111 | }; |
| 112 | static int blink_source[2] = { |
| 113 | TCA6507_LS_BLINK0, |
| 114 | TCA6507_LS_BLINK1, |
| 115 | }; |
| 116 | |
| 117 | /* PWM registers */ |
| 118 | #define TCA6507_REG_CNT 11 |
| 119 | |
| 120 | /* |
| 121 | * 0x00, 0x01, 0x02 encode the TCA6507_LS_* values, each output |
| 122 | * owns one bit in each register |
| 123 | */ |
| 124 | #define TCA6507_FADE_ON 0x03 |
| 125 | #define TCA6507_FULL_ON 0x04 |
| 126 | #define TCA6507_FADE_OFF 0x05 |
| 127 | #define TCA6507_FIRST_OFF 0x06 |
| 128 | #define TCA6507_SECOND_OFF 0x07 |
| 129 | #define TCA6507_MAX_INTENSITY 0x08 |
| 130 | #define TCA6507_MASTER_INTENSITY 0x09 |
| 131 | #define TCA6507_INITIALIZE 0x0A |
| 132 | |
| 133 | #define INIT_CODE 0x8 |
| 134 | |
| 135 | #define TIMECODES 16 |
| 136 | static int time_codes[TIMECODES] = { |
| 137 | 0, 64, 128, 192, 256, 384, 512, 768, |
| 138 | 1024, 1536, 2048, 3072, 4096, 5760, 8128, 16320 |
| 139 | }; |
| 140 | |
| 141 | /* Convert an led.brightness level (0..255) to a TCA6507 level (0..15) */ |
| 142 | static inline int TO_LEVEL(int brightness) |
| 143 | { |
| 144 | return brightness >> 4; |
| 145 | } |
| 146 | |
| 147 | /* ...and convert back */ |
| 148 | static inline int TO_BRIGHT(int level) |
| 149 | { |
| 150 | if (level) |
| 151 | return (level << 4) | 0xf; |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | #define NUM_LEDS 7 |
| 156 | struct tca6507_chip { |
| 157 | int reg_set; /* One bit per register where |
| 158 | * a '1' means the register |
| 159 | * should be written */ |
| 160 | u8 reg_file[TCA6507_REG_CNT]; |
| 161 | /* Bank 2 is Master Intensity and doesn't use times */ |
| 162 | struct bank { |
| 163 | int level; |
| 164 | int ontime, offtime; |
| 165 | int on_dflt, off_dflt; |
| 166 | int time_use, level_use; |
| 167 | } bank[3]; |
| 168 | struct i2c_client *client; |
| 169 | struct work_struct work; |
| 170 | spinlock_t lock; |
| 171 | |
| 172 | struct tca6507_led { |
| 173 | struct tca6507_chip *chip; |
| 174 | struct led_classdev led_cdev; |
| 175 | int num; |
| 176 | int ontime, offtime; |
| 177 | int on_dflt, off_dflt; |
| 178 | int bank; /* Bank used, or -1 */ |
| 179 | int blink; /* Set if hardware-blinking */ |
| 180 | } leds[NUM_LEDS]; |
| 181 | #ifdef CONFIG_GPIOLIB |
| 182 | struct gpio_chip gpio; |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 183 | int gpio_map[NUM_LEDS]; |
| 184 | #endif |
| 185 | }; |
| 186 | |
| 187 | static const struct i2c_device_id tca6507_id[] = { |
| 188 | { "tca6507" }, |
| 189 | { } |
| 190 | }; |
| 191 | MODULE_DEVICE_TABLE(i2c, tca6507_id); |
| 192 | |
| 193 | static int choose_times(int msec, int *c1p, int *c2p) |
| 194 | { |
| 195 | /* |
NeilBrown | 1f431af | 2013-11-12 21:52:43 -0800 | [diff] [blame] | 196 | * Choose two timecodes which add to 'msec' as near as |
| 197 | * possible. The first returned is the 'on' or 'off' time. |
| 198 | * The second is to be used as a 'fade-on' or 'fade-off' time. |
| 199 | * If 'msec' is even, the first will not be smaller than the |
| 200 | * second. If 'msec' is odd, the first will not be larger |
| 201 | * than the second. |
| 202 | * If we cannot get a sum within 1/8 of 'msec' fail with |
| 203 | * -EINVAL, otherwise return the sum that was achieved, plus 1 |
| 204 | * if the first is smaller. |
| 205 | * If two possibilities are equally good (e.g. 512+0, |
| 206 | * 256+256), choose the first pair so there is more |
| 207 | * change-time visible (i.e. it is softer). |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 208 | */ |
| 209 | int c1, c2; |
| 210 | int tmax = msec * 9 / 8; |
| 211 | int tmin = msec * 7 / 8; |
| 212 | int diff = 65536; |
| 213 | |
| 214 | /* We start at '1' to ensure we never even think of choosing a |
| 215 | * total time of '0'. |
| 216 | */ |
| 217 | for (c1 = 1; c1 < TIMECODES; c1++) { |
| 218 | int t = time_codes[c1]; |
| 219 | if (t*2 < tmin) |
| 220 | continue; |
| 221 | if (t > tmax) |
| 222 | break; |
| 223 | for (c2 = 0; c2 <= c1; c2++) { |
| 224 | int tt = t + time_codes[c2]; |
| 225 | int d; |
| 226 | if (tt < tmin) |
| 227 | continue; |
| 228 | if (tt > tmax) |
| 229 | break; |
| 230 | /* This works! */ |
| 231 | d = abs(msec - tt); |
| 232 | if (d >= diff) |
| 233 | continue; |
| 234 | /* Best yet */ |
| 235 | *c1p = c1; |
| 236 | *c2p = c2; |
| 237 | diff = d; |
| 238 | if (d == 0) |
| 239 | return msec; |
| 240 | } |
| 241 | } |
| 242 | if (diff < 65536) { |
| 243 | int actual; |
| 244 | if (msec & 1) { |
| 245 | c1 = *c2p; |
| 246 | *c2p = *c1p; |
| 247 | *c1p = c1; |
| 248 | } |
| 249 | actual = time_codes[*c1p] + time_codes[*c2p]; |
| 250 | if (*c1p < *c2p) |
| 251 | return actual + 1; |
| 252 | else |
| 253 | return actual; |
| 254 | } |
| 255 | /* No close match */ |
| 256 | return -EINVAL; |
| 257 | } |
| 258 | |
| 259 | /* |
NeilBrown | 1f431af | 2013-11-12 21:52:43 -0800 | [diff] [blame] | 260 | * Update the register file with the appropriate 3-bit state for the |
| 261 | * given led. |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 262 | */ |
| 263 | static void set_select(struct tca6507_chip *tca, int led, int val) |
| 264 | { |
| 265 | int mask = (1 << led); |
| 266 | int bit; |
| 267 | |
| 268 | for (bit = 0; bit < 3; bit++) { |
| 269 | int n = tca->reg_file[bit] & ~mask; |
| 270 | if (val & (1 << bit)) |
| 271 | n |= mask; |
| 272 | if (tca->reg_file[bit] != n) { |
| 273 | tca->reg_file[bit] = n; |
| 274 | tca->reg_set |= (1 << bit); |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | |
NeilBrown | 1f431af | 2013-11-12 21:52:43 -0800 | [diff] [blame] | 279 | /* Update the register file with the appropriate 4-bit code for one |
| 280 | * bank or other. This can be used for timers, for levels, or for |
| 281 | * initialization. |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 282 | */ |
| 283 | static void set_code(struct tca6507_chip *tca, int reg, int bank, int new) |
| 284 | { |
| 285 | int mask = 0xF; |
| 286 | int n; |
| 287 | if (bank) { |
| 288 | mask <<= 4; |
| 289 | new <<= 4; |
| 290 | } |
| 291 | n = tca->reg_file[reg] & ~mask; |
| 292 | n |= new; |
| 293 | if (tca->reg_file[reg] != n) { |
| 294 | tca->reg_file[reg] = n; |
| 295 | tca->reg_set |= 1 << reg; |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | /* Update brightness level. */ |
| 300 | static void set_level(struct tca6507_chip *tca, int bank, int level) |
| 301 | { |
| 302 | switch (bank) { |
| 303 | case BANK0: |
| 304 | case BANK1: |
| 305 | set_code(tca, TCA6507_MAX_INTENSITY, bank, level); |
| 306 | break; |
| 307 | case MASTER: |
| 308 | set_code(tca, TCA6507_MASTER_INTENSITY, 0, level); |
| 309 | break; |
| 310 | } |
| 311 | tca->bank[bank].level = level; |
| 312 | } |
| 313 | |
NeilBrown | 1f431af | 2013-11-12 21:52:43 -0800 | [diff] [blame] | 314 | /* Record all relevant time codes for a given bank */ |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 315 | static void set_times(struct tca6507_chip *tca, int bank) |
| 316 | { |
| 317 | int c1, c2; |
| 318 | int result; |
| 319 | |
| 320 | result = choose_times(tca->bank[bank].ontime, &c1, &c2); |
Dan Carpenter | 4a91c45 | 2016-04-14 12:36:16 +0300 | [diff] [blame] | 321 | if (result < 0) |
| 322 | return; |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 323 | dev_dbg(&tca->client->dev, |
NeilBrown | 1f431af | 2013-11-12 21:52:43 -0800 | [diff] [blame] | 324 | "Chose on times %d(%d) %d(%d) for %dms\n", |
| 325 | c1, time_codes[c1], |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 326 | c2, time_codes[c2], tca->bank[bank].ontime); |
| 327 | set_code(tca, TCA6507_FADE_ON, bank, c2); |
| 328 | set_code(tca, TCA6507_FULL_ON, bank, c1); |
| 329 | tca->bank[bank].ontime = result; |
| 330 | |
| 331 | result = choose_times(tca->bank[bank].offtime, &c1, &c2); |
| 332 | dev_dbg(&tca->client->dev, |
NeilBrown | 1f431af | 2013-11-12 21:52:43 -0800 | [diff] [blame] | 333 | "Chose off times %d(%d) %d(%d) for %dms\n", |
| 334 | c1, time_codes[c1], |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 335 | c2, time_codes[c2], tca->bank[bank].offtime); |
| 336 | set_code(tca, TCA6507_FADE_OFF, bank, c2); |
| 337 | set_code(tca, TCA6507_FIRST_OFF, bank, c1); |
| 338 | set_code(tca, TCA6507_SECOND_OFF, bank, c1); |
| 339 | tca->bank[bank].offtime = result; |
| 340 | |
| 341 | set_code(tca, TCA6507_INITIALIZE, bank, INIT_CODE); |
| 342 | } |
| 343 | |
| 344 | /* Write all needed register of tca6507 */ |
| 345 | |
| 346 | static void tca6507_work(struct work_struct *work) |
| 347 | { |
| 348 | struct tca6507_chip *tca = container_of(work, struct tca6507_chip, |
| 349 | work); |
| 350 | struct i2c_client *cl = tca->client; |
| 351 | int set; |
| 352 | u8 file[TCA6507_REG_CNT]; |
| 353 | int r; |
| 354 | |
| 355 | spin_lock_irq(&tca->lock); |
| 356 | set = tca->reg_set; |
| 357 | memcpy(file, tca->reg_file, TCA6507_REG_CNT); |
| 358 | tca->reg_set = 0; |
| 359 | spin_unlock_irq(&tca->lock); |
| 360 | |
| 361 | for (r = 0; r < TCA6507_REG_CNT; r++) |
| 362 | if (set & (1<<r)) |
| 363 | i2c_smbus_write_byte_data(cl, r, file[r]); |
| 364 | } |
| 365 | |
| 366 | static void led_release(struct tca6507_led *led) |
| 367 | { |
| 368 | /* If led owns any resource, release it. */ |
| 369 | struct tca6507_chip *tca = led->chip; |
| 370 | if (led->bank >= 0) { |
| 371 | struct bank *b = tca->bank + led->bank; |
| 372 | if (led->blink) |
| 373 | b->time_use--; |
| 374 | b->level_use--; |
| 375 | } |
| 376 | led->blink = 0; |
| 377 | led->bank = -1; |
| 378 | } |
| 379 | |
| 380 | static int led_prepare(struct tca6507_led *led) |
| 381 | { |
NeilBrown | 1f431af | 2013-11-12 21:52:43 -0800 | [diff] [blame] | 382 | /* Assign this led to a bank, configuring that bank if |
| 383 | * necessary. */ |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 384 | int level = TO_LEVEL(led->led_cdev.brightness); |
| 385 | struct tca6507_chip *tca = led->chip; |
| 386 | int c1, c2; |
| 387 | int i; |
| 388 | struct bank *b; |
| 389 | int need_init = 0; |
| 390 | |
| 391 | led->led_cdev.brightness = TO_BRIGHT(level); |
| 392 | if (level == 0) { |
| 393 | set_select(tca, led->num, TCA6507_LS_LED_OFF); |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | if (led->ontime == 0 || led->offtime == 0) { |
| 398 | /* |
NeilBrown | 1f431af | 2013-11-12 21:52:43 -0800 | [diff] [blame] | 399 | * Just set the brightness, choosing first usable |
| 400 | * bank. If none perfect, choose best. Count |
| 401 | * backwards so we check MASTER bank first to avoid |
| 402 | * wasting a timer. |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 403 | */ |
| 404 | int best = -1;/* full-on */ |
| 405 | int diff = 15-level; |
| 406 | |
| 407 | if (level == 15) { |
| 408 | set_select(tca, led->num, TCA6507_LS_LED_ON); |
| 409 | return 0; |
| 410 | } |
| 411 | |
| 412 | for (i = MASTER; i >= BANK0; i--) { |
| 413 | int d; |
| 414 | if (tca->bank[i].level == level || |
| 415 | tca->bank[i].level_use == 0) { |
| 416 | best = i; |
| 417 | break; |
| 418 | } |
| 419 | d = abs(level - tca->bank[i].level); |
| 420 | if (d < diff) { |
| 421 | diff = d; |
| 422 | best = i; |
| 423 | } |
| 424 | } |
| 425 | if (best == -1) { |
| 426 | /* Best brightness is full-on */ |
| 427 | set_select(tca, led->num, TCA6507_LS_LED_ON); |
| 428 | led->led_cdev.brightness = LED_FULL; |
| 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | if (!tca->bank[best].level_use) |
| 433 | set_level(tca, best, level); |
| 434 | |
| 435 | tca->bank[best].level_use++; |
| 436 | led->bank = best; |
| 437 | set_select(tca, led->num, bank_source[best]); |
| 438 | led->led_cdev.brightness = TO_BRIGHT(tca->bank[best].level); |
| 439 | return 0; |
| 440 | } |
| 441 | |
| 442 | /* |
NeilBrown | 1f431af | 2013-11-12 21:52:43 -0800 | [diff] [blame] | 443 | * We have on/off time so we need to try to allocate a timing |
| 444 | * bank. First check if times are compatible with hardware |
| 445 | * and give up if not. |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 446 | */ |
| 447 | if (choose_times(led->ontime, &c1, &c2) < 0) |
| 448 | return -EINVAL; |
| 449 | if (choose_times(led->offtime, &c1, &c2) < 0) |
| 450 | return -EINVAL; |
| 451 | |
| 452 | for (i = BANK0; i <= BANK1; i++) { |
| 453 | if (tca->bank[i].level_use == 0) |
| 454 | /* not in use - it is ours! */ |
| 455 | break; |
| 456 | if (tca->bank[i].level != level) |
| 457 | /* Incompatible level - skip */ |
| 458 | /* FIX: if timer matches we maybe should consider |
| 459 | * this anyway... |
| 460 | */ |
| 461 | continue; |
| 462 | |
| 463 | if (tca->bank[i].time_use == 0) |
| 464 | /* Timer not in use, and level matches - use it */ |
| 465 | break; |
| 466 | |
| 467 | if (!(tca->bank[i].on_dflt || |
| 468 | led->on_dflt || |
| 469 | tca->bank[i].ontime == led->ontime)) |
| 470 | /* on time is incompatible */ |
| 471 | continue; |
| 472 | |
| 473 | if (!(tca->bank[i].off_dflt || |
| 474 | led->off_dflt || |
| 475 | tca->bank[i].offtime == led->offtime)) |
| 476 | /* off time is incompatible */ |
| 477 | continue; |
| 478 | |
| 479 | /* looks like a suitable match */ |
| 480 | break; |
| 481 | } |
| 482 | |
| 483 | if (i > BANK1) |
| 484 | /* Nothing matches - how sad */ |
| 485 | return -EINVAL; |
| 486 | |
| 487 | b = &tca->bank[i]; |
| 488 | if (b->level_use == 0) |
| 489 | set_level(tca, i, level); |
| 490 | b->level_use++; |
| 491 | led->bank = i; |
| 492 | |
| 493 | if (b->on_dflt || |
| 494 | !led->on_dflt || |
| 495 | b->time_use == 0) { |
| 496 | b->ontime = led->ontime; |
| 497 | b->on_dflt = led->on_dflt; |
| 498 | need_init = 1; |
| 499 | } |
| 500 | |
| 501 | if (b->off_dflt || |
| 502 | !led->off_dflt || |
| 503 | b->time_use == 0) { |
| 504 | b->offtime = led->offtime; |
| 505 | b->off_dflt = led->off_dflt; |
| 506 | need_init = 1; |
| 507 | } |
| 508 | |
| 509 | if (need_init) |
| 510 | set_times(tca, i); |
| 511 | |
| 512 | led->ontime = b->ontime; |
| 513 | led->offtime = b->offtime; |
| 514 | |
| 515 | b->time_use++; |
| 516 | led->blink = 1; |
| 517 | led->led_cdev.brightness = TO_BRIGHT(b->level); |
| 518 | set_select(tca, led->num, blink_source[i]); |
| 519 | return 0; |
| 520 | } |
| 521 | |
| 522 | static int led_assign(struct tca6507_led *led) |
| 523 | { |
| 524 | struct tca6507_chip *tca = led->chip; |
| 525 | int err; |
| 526 | unsigned long flags; |
| 527 | |
| 528 | spin_lock_irqsave(&tca->lock, flags); |
| 529 | led_release(led); |
| 530 | err = led_prepare(led); |
| 531 | if (err) { |
| 532 | /* |
NeilBrown | 1f431af | 2013-11-12 21:52:43 -0800 | [diff] [blame] | 533 | * Can only fail on timer setup. In that case we need |
| 534 | * to re-establish as steady level. |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 535 | */ |
| 536 | led->ontime = 0; |
| 537 | led->offtime = 0; |
| 538 | led_prepare(led); |
| 539 | } |
| 540 | spin_unlock_irqrestore(&tca->lock, flags); |
| 541 | |
| 542 | if (tca->reg_set) |
| 543 | schedule_work(&tca->work); |
| 544 | return err; |
| 545 | } |
| 546 | |
| 547 | static void tca6507_brightness_set(struct led_classdev *led_cdev, |
| 548 | enum led_brightness brightness) |
| 549 | { |
| 550 | struct tca6507_led *led = container_of(led_cdev, struct tca6507_led, |
| 551 | led_cdev); |
| 552 | led->led_cdev.brightness = brightness; |
| 553 | led->ontime = 0; |
| 554 | led->offtime = 0; |
| 555 | led_assign(led); |
| 556 | } |
| 557 | |
| 558 | static int tca6507_blink_set(struct led_classdev *led_cdev, |
| 559 | unsigned long *delay_on, |
| 560 | unsigned long *delay_off) |
| 561 | { |
| 562 | struct tca6507_led *led = container_of(led_cdev, struct tca6507_led, |
| 563 | led_cdev); |
| 564 | |
| 565 | if (*delay_on == 0) |
| 566 | led->on_dflt = 1; |
| 567 | else if (delay_on != &led_cdev->blink_delay_on) |
| 568 | led->on_dflt = 0; |
| 569 | led->ontime = *delay_on; |
| 570 | |
| 571 | if (*delay_off == 0) |
| 572 | led->off_dflt = 1; |
| 573 | else if (delay_off != &led_cdev->blink_delay_off) |
| 574 | led->off_dflt = 0; |
| 575 | led->offtime = *delay_off; |
| 576 | |
| 577 | if (led->ontime == 0) |
| 578 | led->ontime = 512; |
| 579 | if (led->offtime == 0) |
| 580 | led->offtime = 512; |
| 581 | |
| 582 | if (led->led_cdev.brightness == LED_OFF) |
| 583 | led->led_cdev.brightness = LED_FULL; |
| 584 | if (led_assign(led) < 0) { |
| 585 | led->ontime = 0; |
| 586 | led->offtime = 0; |
| 587 | led->led_cdev.brightness = LED_OFF; |
| 588 | return -EINVAL; |
| 589 | } |
| 590 | *delay_on = led->ontime; |
| 591 | *delay_off = led->offtime; |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | #ifdef CONFIG_GPIOLIB |
| 596 | static void tca6507_gpio_set_value(struct gpio_chip *gc, |
| 597 | unsigned offset, int val) |
| 598 | { |
Linus Walleij | 2a66434 | 2015-12-08 16:42:58 +0100 | [diff] [blame] | 599 | struct tca6507_chip *tca = gpiochip_get_data(gc); |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 600 | unsigned long flags; |
| 601 | |
| 602 | spin_lock_irqsave(&tca->lock, flags); |
| 603 | /* |
NeilBrown | 1f431af | 2013-11-12 21:52:43 -0800 | [diff] [blame] | 604 | * 'OFF' is floating high, and 'ON' is pulled down, so it has |
| 605 | * the inverse sense of 'val'. |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 606 | */ |
| 607 | set_select(tca, tca->gpio_map[offset], |
| 608 | val ? TCA6507_LS_LED_OFF : TCA6507_LS_LED_ON); |
| 609 | spin_unlock_irqrestore(&tca->lock, flags); |
| 610 | if (tca->reg_set) |
| 611 | schedule_work(&tca->work); |
| 612 | } |
| 613 | |
| 614 | static int tca6507_gpio_direction_output(struct gpio_chip *gc, |
| 615 | unsigned offset, int val) |
| 616 | { |
| 617 | tca6507_gpio_set_value(gc, offset, val); |
| 618 | return 0; |
| 619 | } |
| 620 | |
Marek Behún | c1ff1a1 | 2020-09-20 00:15:41 +0200 | [diff] [blame] | 621 | static int tca6507_probe_gpios(struct device *dev, |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 622 | struct tca6507_chip *tca, |
| 623 | struct tca6507_platform_data *pdata) |
| 624 | { |
| 625 | int err; |
| 626 | int i = 0; |
| 627 | int gpios = 0; |
| 628 | |
| 629 | for (i = 0; i < NUM_LEDS; i++) |
| 630 | if (pdata->leds.leds[i].name && pdata->leds.leds[i].flags) { |
| 631 | /* Configure as a gpio */ |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 632 | tca->gpio_map[gpios] = i; |
| 633 | gpios++; |
| 634 | } |
| 635 | |
| 636 | if (!gpios) |
| 637 | return 0; |
| 638 | |
| 639 | tca->gpio.label = "gpio-tca6507"; |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 640 | tca->gpio.ngpio = gpios; |
| 641 | tca->gpio.base = pdata->gpio_base; |
| 642 | tca->gpio.owner = THIS_MODULE; |
| 643 | tca->gpio.direction_output = tca6507_gpio_direction_output; |
| 644 | tca->gpio.set = tca6507_gpio_set_value; |
Marek Behún | c1ff1a1 | 2020-09-20 00:15:41 +0200 | [diff] [blame] | 645 | tca->gpio.parent = dev; |
NeilBrown | 10ead6e | 2013-10-31 19:41:20 -0700 | [diff] [blame] | 646 | #ifdef CONFIG_OF_GPIO |
Marek Behún | c1ff1a1 | 2020-09-20 00:15:41 +0200 | [diff] [blame] | 647 | tca->gpio.of_node = of_node_get(dev_of_node(dev)); |
NeilBrown | 10ead6e | 2013-10-31 19:41:20 -0700 | [diff] [blame] | 648 | #endif |
Linus Walleij | 2a66434 | 2015-12-08 16:42:58 +0100 | [diff] [blame] | 649 | err = gpiochip_add_data(&tca->gpio, tca); |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 650 | if (err) { |
| 651 | tca->gpio.ngpio = 0; |
| 652 | return err; |
| 653 | } |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | static void tca6507_remove_gpio(struct tca6507_chip *tca) |
| 658 | { |
abdoulaye berthe | 88d5e52 | 2014-07-12 22:30:14 +0200 | [diff] [blame] | 659 | if (tca->gpio.ngpio) |
| 660 | gpiochip_remove(&tca->gpio); |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 661 | } |
| 662 | #else /* CONFIG_GPIOLIB */ |
Marek Behún | c1ff1a1 | 2020-09-20 00:15:41 +0200 | [diff] [blame] | 663 | static int tca6507_probe_gpios(struct device *dev, |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 664 | struct tca6507_chip *tca, |
| 665 | struct tca6507_platform_data *pdata) |
| 666 | { |
| 667 | return 0; |
| 668 | } |
| 669 | static void tca6507_remove_gpio(struct tca6507_chip *tca) |
| 670 | { |
| 671 | } |
| 672 | #endif /* CONFIG_GPIOLIB */ |
| 673 | |
Marek Belisko | 0c596a7 | 2012-11-30 14:00:49 -0800 | [diff] [blame] | 674 | static struct tca6507_platform_data * |
Marek Behún | c1ff1a1 | 2020-09-20 00:15:41 +0200 | [diff] [blame] | 675 | tca6507_led_dt_init(struct device *dev) |
Marek Belisko | 0c596a7 | 2012-11-30 14:00:49 -0800 | [diff] [blame] | 676 | { |
Marek Belisko | 0c596a7 | 2012-11-30 14:00:49 -0800 | [diff] [blame] | 677 | struct tca6507_platform_data *pdata; |
Marek Behún | 96f5241 | 2020-09-20 00:15:37 +0200 | [diff] [blame] | 678 | struct fwnode_handle *child; |
Marek Belisko | 0c596a7 | 2012-11-30 14:00:49 -0800 | [diff] [blame] | 679 | struct led_info *tca_leds; |
Axel Lin | ef754e8 | 2013-01-27 01:14:14 -0800 | [diff] [blame] | 680 | int count; |
Marek Belisko | 0c596a7 | 2012-11-30 14:00:49 -0800 | [diff] [blame] | 681 | |
Marek Behún | c1ff1a1 | 2020-09-20 00:15:41 +0200 | [diff] [blame] | 682 | count = device_get_child_node_count(dev); |
Axel Lin | ef754e8 | 2013-01-27 01:14:14 -0800 | [diff] [blame] | 683 | if (!count || count > NUM_LEDS) |
Marek Belisko | 0c596a7 | 2012-11-30 14:00:49 -0800 | [diff] [blame] | 684 | return ERR_PTR(-ENODEV); |
| 685 | |
Marek Behún | c1ff1a1 | 2020-09-20 00:15:41 +0200 | [diff] [blame] | 686 | tca_leds = devm_kcalloc(dev, NUM_LEDS, sizeof(struct led_info), |
Marek Behún | 96f5241 | 2020-09-20 00:15:37 +0200 | [diff] [blame] | 687 | GFP_KERNEL); |
Marek Belisko | 0c596a7 | 2012-11-30 14:00:49 -0800 | [diff] [blame] | 688 | if (!tca_leds) |
| 689 | return ERR_PTR(-ENOMEM); |
| 690 | |
Marek Behún | c1ff1a1 | 2020-09-20 00:15:41 +0200 | [diff] [blame] | 691 | device_for_each_child_node(dev, child) { |
Marek Belisko | 0c596a7 | 2012-11-30 14:00:49 -0800 | [diff] [blame] | 692 | struct led_info led; |
| 693 | u32 reg; |
| 694 | int ret; |
| 695 | |
Marek Behún | 96f5241 | 2020-09-20 00:15:37 +0200 | [diff] [blame] | 696 | if (fwnode_property_read_string(child, "label", &led.name)) |
| 697 | led.name = fwnode_get_name(child); |
| 698 | |
| 699 | fwnode_property_read_string(child, "linux,default-trigger", |
| 700 | &led.default_trigger); |
| 701 | |
NeilBrown | 9334129 | 2013-10-31 19:33:45 -0700 | [diff] [blame] | 702 | led.flags = 0; |
Marek Behún | 96f5241 | 2020-09-20 00:15:37 +0200 | [diff] [blame] | 703 | if (fwnode_property_match_string(child, "compatible", |
| 704 | "gpio") >= 0) |
NeilBrown | 10ead6e | 2013-10-31 19:41:20 -0700 | [diff] [blame] | 705 | led.flags |= TCA6507_MAKE_GPIO; |
Marek Behún | 96f5241 | 2020-09-20 00:15:37 +0200 | [diff] [blame] | 706 | |
| 707 | ret = fwnode_property_read_u32(child, "reg", ®); |
| 708 | if (ret || reg >= NUM_LEDS) { |
| 709 | fwnode_handle_put(child); |
Marek Behún | a238098 | 2020-09-26 21:43:02 +0200 | [diff] [blame] | 710 | return ERR_PTR(ret ? : -EINVAL); |
Marek Behún | 96f5241 | 2020-09-20 00:15:37 +0200 | [diff] [blame] | 711 | } |
Marek Belisko | 0c596a7 | 2012-11-30 14:00:49 -0800 | [diff] [blame] | 712 | |
| 713 | tca_leds[reg] = led; |
| 714 | } |
Marek Behún | 96f5241 | 2020-09-20 00:15:37 +0200 | [diff] [blame] | 715 | |
Marek Behún | c1ff1a1 | 2020-09-20 00:15:41 +0200 | [diff] [blame] | 716 | pdata = devm_kzalloc(dev, sizeof(struct tca6507_platform_data), |
Marek Behún | 96f5241 | 2020-09-20 00:15:37 +0200 | [diff] [blame] | 717 | GFP_KERNEL); |
Marek Belisko | 0c596a7 | 2012-11-30 14:00:49 -0800 | [diff] [blame] | 718 | if (!pdata) |
| 719 | return ERR_PTR(-ENOMEM); |
| 720 | |
| 721 | pdata->leds.leds = tca_leds; |
NeilBrown | 9334129 | 2013-10-31 19:33:45 -0700 | [diff] [blame] | 722 | pdata->leds.num_leds = NUM_LEDS; |
Chen Gang | 33ca153 | 2013-12-08 20:41:37 -0800 | [diff] [blame] | 723 | #ifdef CONFIG_GPIOLIB |
NeilBrown | 10ead6e | 2013-10-31 19:41:20 -0700 | [diff] [blame] | 724 | pdata->gpio_base = -1; |
Chen Gang | 33ca153 | 2013-12-08 20:41:37 -0800 | [diff] [blame] | 725 | #endif |
Marek Behún | 96f5241 | 2020-09-20 00:15:37 +0200 | [diff] [blame] | 726 | |
Marek Belisko | 0c596a7 | 2012-11-30 14:00:49 -0800 | [diff] [blame] | 727 | return pdata; |
| 728 | } |
| 729 | |
Pavel Machek | e8b7dab | 2020-09-25 11:24:12 +0200 | [diff] [blame] | 730 | static const struct of_device_id __maybe_unused of_tca6507_leds_match[] = { |
Marek Belisko | 0c596a7 | 2012-11-30 14:00:49 -0800 | [diff] [blame] | 731 | { .compatible = "ti,tca6507", }, |
| 732 | {}, |
| 733 | }; |
Javier Martinez Canillas | 4d59ed8 | 2015-08-25 08:31:16 +0200 | [diff] [blame] | 734 | MODULE_DEVICE_TABLE(of, of_tca6507_leds_match); |
Marek Belisko | 0c596a7 | 2012-11-30 14:00:49 -0800 | [diff] [blame] | 735 | |
Bill Pemberton | 98ea1ea | 2012-11-19 13:23:02 -0500 | [diff] [blame] | 736 | static int tca6507_probe(struct i2c_client *client, |
Marek Belisko | 0c596a7 | 2012-11-30 14:00:49 -0800 | [diff] [blame] | 737 | const struct i2c_device_id *id) |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 738 | { |
Marek Behún | c1ff1a1 | 2020-09-20 00:15:41 +0200 | [diff] [blame] | 739 | struct device *dev = &client->dev; |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 740 | struct i2c_adapter *adapter; |
Marek Behún | c1ff1a1 | 2020-09-20 00:15:41 +0200 | [diff] [blame] | 741 | struct tca6507_chip *tca; |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 742 | struct tca6507_platform_data *pdata; |
| 743 | int err; |
| 744 | int i = 0; |
| 745 | |
Wolfram Sang | 09bfa5f | 2019-06-08 12:55:44 +0200 | [diff] [blame] | 746 | adapter = client->adapter; |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 747 | |
| 748 | if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) |
| 749 | return -EIO; |
| 750 | |
Marek Behún | c1ff1a1 | 2020-09-20 00:15:41 +0200 | [diff] [blame] | 751 | pdata = tca6507_led_dt_init(dev); |
Marek Behún | 96f5241 | 2020-09-20 00:15:37 +0200 | [diff] [blame] | 752 | if (IS_ERR(pdata)) { |
Marek Behún | c1ff1a1 | 2020-09-20 00:15:41 +0200 | [diff] [blame] | 753 | dev_err(dev, "Need %d entries in platform-data list\n", NUM_LEDS); |
Marek Behún | 96f5241 | 2020-09-20 00:15:37 +0200 | [diff] [blame] | 754 | return PTR_ERR(pdata); |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 755 | } |
Marek Behún | c1ff1a1 | 2020-09-20 00:15:41 +0200 | [diff] [blame] | 756 | tca = devm_kzalloc(dev, sizeof(*tca), GFP_KERNEL); |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 757 | if (!tca) |
Dan Carpenter | 920c4f4 | 2012-03-23 15:02:07 -0700 | [diff] [blame] | 758 | return -ENOMEM; |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 759 | |
| 760 | tca->client = client; |
| 761 | INIT_WORK(&tca->work, tca6507_work); |
| 762 | spin_lock_init(&tca->lock); |
| 763 | i2c_set_clientdata(client, tca); |
| 764 | |
| 765 | for (i = 0; i < NUM_LEDS; i++) { |
| 766 | struct tca6507_led *l = tca->leds + i; |
| 767 | |
| 768 | l->chip = tca; |
| 769 | l->num = i; |
| 770 | if (pdata->leds.leds[i].name && !pdata->leds.leds[i].flags) { |
| 771 | l->led_cdev.name = pdata->leds.leds[i].name; |
| 772 | l->led_cdev.default_trigger |
| 773 | = pdata->leds.leds[i].default_trigger; |
| 774 | l->led_cdev.brightness_set = tca6507_brightness_set; |
| 775 | l->led_cdev.blink_set = tca6507_blink_set; |
| 776 | l->bank = -1; |
Marek Behún | c1ff1a1 | 2020-09-20 00:15:41 +0200 | [diff] [blame] | 777 | err = led_classdev_register(dev, &l->led_cdev); |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 778 | if (err < 0) |
| 779 | goto exit; |
| 780 | } |
| 781 | } |
Marek Behún | c1ff1a1 | 2020-09-20 00:15:41 +0200 | [diff] [blame] | 782 | err = tca6507_probe_gpios(dev, tca, pdata); |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 783 | if (err) |
| 784 | goto exit; |
| 785 | /* set all registers to known state - zero */ |
| 786 | tca->reg_set = 0x7f; |
| 787 | schedule_work(&tca->work); |
| 788 | |
| 789 | return 0; |
| 790 | exit: |
Dan Carpenter | 920c4f4 | 2012-03-23 15:02:07 -0700 | [diff] [blame] | 791 | while (i--) { |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 792 | if (tca->leds[i].led_cdev.name) |
| 793 | led_classdev_unregister(&tca->leds[i].led_cdev); |
Dan Carpenter | 920c4f4 | 2012-03-23 15:02:07 -0700 | [diff] [blame] | 794 | } |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 795 | return err; |
| 796 | } |
| 797 | |
Bill Pemberton | 678e8a6 | 2012-11-19 13:26:00 -0500 | [diff] [blame] | 798 | static int tca6507_remove(struct i2c_client *client) |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 799 | { |
| 800 | int i; |
| 801 | struct tca6507_chip *tca = i2c_get_clientdata(client); |
| 802 | struct tca6507_led *tca_leds = tca->leds; |
| 803 | |
| 804 | for (i = 0; i < NUM_LEDS; i++) { |
| 805 | if (tca_leds[i].led_cdev.name) |
| 806 | led_classdev_unregister(&tca_leds[i].led_cdev); |
| 807 | } |
| 808 | tca6507_remove_gpio(tca); |
| 809 | cancel_work_sync(&tca->work); |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 810 | |
| 811 | return 0; |
| 812 | } |
| 813 | |
| 814 | static struct i2c_driver tca6507_driver = { |
| 815 | .driver = { |
| 816 | .name = "leds-tca6507", |
Sachin Kamat | fbd9df2 | 2013-03-14 03:09:49 -0700 | [diff] [blame] | 817 | .of_match_table = of_match_ptr(of_tca6507_leds_match), |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 818 | }, |
| 819 | .probe = tca6507_probe, |
Bill Pemberton | df07cf8 | 2012-11-19 13:20:20 -0500 | [diff] [blame] | 820 | .remove = tca6507_remove, |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 821 | .id_table = tca6507_id, |
| 822 | }; |
| 823 | |
Peter Meerwald | 2e91176 | 2012-07-03 16:03:38 +0800 | [diff] [blame] | 824 | module_i2c_driver(tca6507_driver); |
NeilBrown | a6d511e | 2012-01-10 15:09:40 -0800 | [diff] [blame] | 825 | |
| 826 | MODULE_AUTHOR("NeilBrown <neilb@suse.de>"); |
| 827 | MODULE_DESCRIPTION("TCA6507 LED/GPO driver"); |
| 828 | MODULE_LICENSE("GPL v2"); |