diff options
author | NeilBrown <neilb@suse.de> | 2013-11-13 00:52:43 -0500 |
---|---|---|
committer | Bryan Wu <cooloney@gmail.com> | 2014-01-27 20:28:47 -0500 |
commit | 1f431afdb4572c4f1dc8a3c5159fe910c53fc814 (patch) | |
tree | 00e482f15560809cb028ac646217df7418459a1b /drivers/leds/leds-tca6507.c | |
parent | 10ead6e59934be76b6ce255d6b842a432b207b7f (diff) |
LEDS: tca6507 - fix up some comments.
In particular fix the capitalisation of GPIO and LED and
correct TCA6507_MAKE_CPIO, but also rewrite the comment about
platform-data to include reference to devicetree.
Also re-wrap comments to fit 80 columns.
Reported-by: Bryan Wu <cooloney@gmail.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
Diffstat (limited to 'drivers/leds/leds-tca6507.c')
-rw-r--r-- | drivers/leds/leds-tca6507.c | 190 |
1 files changed, 102 insertions, 88 deletions
diff --git a/drivers/leds/leds-tca6507.c b/drivers/leds/leds-tca6507.c index 93a2b1759054..503df834c690 100644 --- a/drivers/leds/leds-tca6507.c +++ b/drivers/leds/leds-tca6507.c | |||
@@ -4,77 +4,87 @@ | |||
4 | * The TCA6507 is a programmable LED controller that can drive 7 | 4 | * The TCA6507 is a programmable LED controller that can drive 7 |
5 | * separate lines either by holding them low, or by pulsing them | 5 | * separate lines either by holding them low, or by pulsing them |
6 | * with modulated width. | 6 | * with modulated width. |
7 | * The modulation can be varied in a simple pattern to produce a blink or | 7 | * The modulation can be varied in a simple pattern to produce a |
8 | * double-blink. | 8 | * blink or double-blink. |
9 | * | 9 | * |
10 | * This driver can configure each line either as a 'GPIO' which is out-only | 10 | * This driver can configure each line either as a 'GPIO' which is |
11 | * (no pull-up) or as an LED with variable brightness and hardware-assisted | 11 | * out-only (pull-up resistor required) or as an LED with variable |
12 | * blinking. | 12 | * brightness and hardware-assisted blinking. |
13 | * | 13 | * |
14 | * Apart from OFF and ON there are three programmable brightness levels which | 14 | * Apart from OFF and ON there are three programmable brightness |
15 | * can be programmed from 0 to 15 and indicate how many 500usec intervals in | 15 | * levels which can be programmed from 0 to 15 and indicate how many |
16 | * each 8msec that the led is 'on'. The levels are named MASTER, BANK0 and | 16 | * 500usec intervals in each 8msec that the led is 'on'. The levels |
17 | * BANK1. | 17 | * are named MASTER, BANK0 and BANK1. |
18 | * | 18 | * |
19 | * There are two different blink rates that can be programmed, each with | 19 | * There are two different blink rates that can be programmed, each |
20 | * separate time for rise, on, fall, off and second-off. Thus if 3 or more | 20 | * with separate time for rise, on, fall, off and second-off. Thus if |
21 | * different non-trivial rates are required, software must be used for the extra | 21 | * 3 or more different non-trivial rates are required, software must |
22 | * rates. The two different blink rates must align with the two levels BANK0 and | 22 | * be used for the extra rates. The two different blink rates must |
23 | * BANK1. | 23 | * align with the two levels BANK0 and BANK1. This driver does not |
24 | * This driver does not support double-blink so 'second-off' always matches | 24 | * support double-blink so 'second-off' always matches 'off'. |
25 | * 'off'. | ||
26 | * | 25 | * |
27 | * Only 16 different times can be programmed in a roughly logarithmic scale from | 26 | * Only 16 different times can be programmed in a roughly logarithmic |
28 | * 64ms to 16320ms. To be precise the possible times are: | 27 | * scale from 64ms to 16320ms. To be precise the possible times are: |
29 | * 0, 64, 128, 192, 256, 384, 512, 768, | 28 | * 0, 64, 128, 192, 256, 384, 512, 768, |
30 | * 1024, 1536, 2048, 3072, 4096, 5760, 8128, 16320 | 29 | * 1024, 1536, 2048, 3072, 4096, 5760, 8128, 16320 |
31 | * | 30 | * |
32 | * Times that cannot be closely matched with these must be | 31 | * Times that cannot be closely matched with these must be handled in |
33 | * handled in software. This driver allows 12.5% error in matching. | 32 | * software. This driver allows 12.5% error in matching. |
34 | * | 33 | * |
35 | * This driver does not allow rise/fall rates to be set explicitly. When trying | 34 | * This driver does not allow rise/fall rates to be set explicitly. |
36 | * to match a given 'on' or 'off' period, an appropriate pair of 'change' and | 35 | * When trying to match a given 'on' or 'off' period, an appropriate |
37 | * 'hold' times are chosen to get a close match. If the target delay is even, | 36 | * pair of 'change' and 'hold' times are chosen to get a close match. |
38 | * the 'change' number will be the smaller; if odd, the 'hold' number will be | 37 | * If the target delay is even, the 'change' number will be the |
39 | * the smaller. | 38 | * smaller; if odd, the 'hold' number will be the smaller. |
40 | 39 | ||
41 | * Choosing pairs of delays with 12.5% errors allows us to match delays in the | 40 | * Choosing pairs of delays with 12.5% errors allows us to match |
42 | * ranges: 56-72, 112-144, 168-216, 224-27504, 28560-36720. | 41 | * delays in the ranges: 56-72, 112-144, 168-216, 224-27504, |
43 | * 26% of the achievable sums can be matched by multiple pairings. For example | 42 | * 28560-36720. |
44 | * 1536 == 1536+0, 1024+512, or 768+768. This driver will always choose the | 43 | * 26% of the achievable sums can be matched by multiple pairings. |
45 | * pairing with the least maximum - 768+768 in this case. Other pairings are | 44 | * For example 1536 == 1536+0, 1024+512, or 768+768. |
46 | * not available. | 45 | * This driver will always choose the pairing with the least |
46 | * maximum - 768+768 in this case. Other pairings are not available. | ||
47 | * | 47 | * |
48 | * Access to the 3 levels and 2 blinks are on a first-come, first-served basis. | 48 | * Access to the 3 levels and 2 blinks are on a first-come, |
49 | * Access can be shared by multiple leds if they have the same level and | 49 | * first-served basis. Access can be shared by multiple leds if they |
50 | * either same blink rates, or some don't blink. | 50 | * have the same level and either same blink rates, or some don't |
51 | * When a led changes, it relinquishes access and tries again, so it might | 51 | * blink. When a led changes, it relinquishes access and tries again, |
52 | * lose access to hardware blink. | 52 | * so it might lose access to hardware blink. |
53 | * If a blink engine cannot be allocated, software blink is used. | ||
54 | * If the desired brightness cannot be allocated, the closest available non-zero | ||
55 | * brightness is used. As 'full' is always available, the worst case would be | ||
56 | * to have two different blink rates at '1', with Max at '2', then other leds | ||
57 | * will have to choose between '2' and '16'. Hopefully this is not likely. | ||
58 | * | 53 | * |
59 | * Each bank (BANK0 and BANK1) has two usage counts - LEDs using the brightness | 54 | * If a blink engine cannot be allocated, software blink is used. If |
60 | * and LEDs using the blink. It can only be reprogrammed when the appropriate | 55 | * the desired brightness cannot be allocated, the closest available |
61 | * counter is zero. The MASTER level has a single usage count. | 56 | * non-zero brightness is used. As 'full' is always available, the |
57 | * worst case would be to have two different blink rates at '1', with | ||
58 | * Max at '2', then other leds will have to choose between '2' and | ||
59 | * '16'. Hopefully this is not likely. | ||
62 | * | 60 | * |
63 | * Each Led has programmable 'on' and 'off' time as milliseconds. With each | 61 | * Each bank (BANK0 and BANK1) has two usage counts - LEDs using the |
64 | * there is a flag saying if it was explicitly requested or defaulted. | 62 | * brightness and LEDs using the blink. It can only be reprogrammed |
65 | * Similarly the banks know if each time was explicit or a default. Defaults | 63 | * when the appropriate counter is zero. The MASTER level has a |
66 | * are permitted to be changed freely - they are not recognised when matching. | 64 | * single usage count. |
67 | * | 65 | * |
66 | * Each LED has programmable 'on' and 'off' time as milliseconds. | ||
67 | * With each there is a flag saying if it was explicitly requested or | ||
68 | * defaulted. Similarly the banks know if each time was explicit or a | ||
69 | * default. Defaults are permitted to be changed freely - they are | ||
70 | * not recognised when matching. | ||
68 | * | 71 | * |
69 | * An led-tca6507 device must be provided with platform data. This data | ||
70 | * lists for each output: the name, default trigger, and whether the signal | ||
71 | * is being used as a GPiO rather than an led. 'struct led_plaform_data' | ||
72 | * is used for this. If 'name' is NULL, the output isn't used. If 'flags' | ||
73 | * is TCA6507_MAKE_CPIO, the output is a GPO. | ||
74 | * The "struct led_platform_data" can be embedded in a | ||
75 | * "struct tca6507_platform_data" which adds a 'gpio_base' for the GPiOs, | ||
76 | * and a 'setup' callback which is called once the GPiOs are available. | ||
77 | * | 72 | * |
73 | * An led-tca6507 device must be provided with platform data or | ||
74 | * configured via devicetree. | ||
75 | * | ||
76 | * The platform-data lists for each output: the name, default trigger, | ||
77 | * and whether the signal is being used as a GPIO rather than an LED. | ||
78 | * 'struct led_plaform_data' is used for this. If 'name' is NULL, the | ||
79 | * output isn't used. If 'flags' is TCA6507_MAKE_GPIO, the output is | ||
80 | * a GPO. The "struct led_platform_data" can be embedded in a "struct | ||
81 | * tca6507_platform_data" which adds a 'gpio_base' for the GPIOs, and | ||
82 | * a 'setup' callback which is called once the GPIOs are available. | ||
83 | * | ||
84 | * When configured via devicetree there is one child for each output. | ||
85 | * The "reg" determines the output number and "compatible" determines | ||
86 | * whether it is an LED or a GPIO. "linux,default-trigger" can set a | ||
87 | * default trigger. | ||
78 | */ | 88 | */ |
79 | 89 | ||
80 | #include <linux/module.h> | 90 | #include <linux/module.h> |
@@ -192,17 +202,18 @@ MODULE_DEVICE_TABLE(i2c, tca6507_id); | |||
192 | static int choose_times(int msec, int *c1p, int *c2p) | 202 | static int choose_times(int msec, int *c1p, int *c2p) |
193 | { | 203 | { |
194 | /* | 204 | /* |
195 | * Choose two timecodes which add to 'msec' as near as possible. | 205 | * Choose two timecodes which add to 'msec' as near as |
196 | * The first returned is the 'on' or 'off' time. The second is to be | 206 | * possible. The first returned is the 'on' or 'off' time. |
197 | * used as a 'fade-on' or 'fade-off' time. If 'msec' is even, | 207 | * The second is to be used as a 'fade-on' or 'fade-off' time. |
198 | * the first will not be smaller than the second. If 'msec' is odd, | 208 | * If 'msec' is even, the first will not be smaller than the |
199 | * the first will not be larger than the second. | 209 | * second. If 'msec' is odd, the first will not be larger |
200 | * If we cannot get a sum within 1/8 of 'msec' fail with -EINVAL, | 210 | * than the second. |
201 | * otherwise return the sum that was achieved, plus 1 if the first is | 211 | * If we cannot get a sum within 1/8 of 'msec' fail with |
202 | * smaller. | 212 | * -EINVAL, otherwise return the sum that was achieved, plus 1 |
203 | * If two possibilities are equally good (e.g. 512+0, 256+256), choose | 213 | * if the first is smaller. |
204 | * the first pair so there is more change-time visible (i.e. it is | 214 | * If two possibilities are equally good (e.g. 512+0, |
205 | * softer). | 215 | * 256+256), choose the first pair so there is more |
216 | * change-time visible (i.e. it is softer). | ||
206 | */ | 217 | */ |
207 | int c1, c2; | 218 | int c1, c2; |
208 | int tmax = msec * 9 / 8; | 219 | int tmax = msec * 9 / 8; |
@@ -255,8 +266,8 @@ static int choose_times(int msec, int *c1p, int *c2p) | |||
255 | } | 266 | } |
256 | 267 | ||
257 | /* | 268 | /* |
258 | * Update the register file with the appropriate 3-bit state for | 269 | * Update the register file with the appropriate 3-bit state for the |
259 | * the given led. | 270 | * given led. |
260 | */ | 271 | */ |
261 | static void set_select(struct tca6507_chip *tca, int led, int val) | 272 | static void set_select(struct tca6507_chip *tca, int led, int val) |
262 | { | 273 | { |
@@ -274,9 +285,9 @@ static void set_select(struct tca6507_chip *tca, int led, int val) | |||
274 | } | 285 | } |
275 | } | 286 | } |
276 | 287 | ||
277 | /* Update the register file with the appropriate 4-bit code for | 288 | /* Update the register file with the appropriate 4-bit code for one |
278 | * one bank or other. This can be used for timers, for levels, or | 289 | * bank or other. This can be used for timers, for levels, or for |
279 | * for initialisation. | 290 | * initialization. |
280 | */ | 291 | */ |
281 | static void set_code(struct tca6507_chip *tca, int reg, int bank, int new) | 292 | static void set_code(struct tca6507_chip *tca, int reg, int bank, int new) |
282 | { | 293 | { |
@@ -309,7 +320,7 @@ static void set_level(struct tca6507_chip *tca, int bank, int level) | |||
309 | tca->bank[bank].level = level; | 320 | tca->bank[bank].level = level; |
310 | } | 321 | } |
311 | 322 | ||
312 | /* Record all relevant time code for a given bank */ | 323 | /* Record all relevant time codes for a given bank */ |
313 | static void set_times(struct tca6507_chip *tca, int bank) | 324 | static void set_times(struct tca6507_chip *tca, int bank) |
314 | { | 325 | { |
315 | int c1, c2; | 326 | int c1, c2; |
@@ -317,7 +328,8 @@ static void set_times(struct tca6507_chip *tca, int bank) | |||
317 | 328 | ||
318 | result = choose_times(tca->bank[bank].ontime, &c1, &c2); | 329 | result = choose_times(tca->bank[bank].ontime, &c1, &c2); |
319 | dev_dbg(&tca->client->dev, | 330 | dev_dbg(&tca->client->dev, |
320 | "Chose on times %d(%d) %d(%d) for %dms\n", c1, time_codes[c1], | 331 | "Chose on times %d(%d) %d(%d) for %dms\n", |
332 | c1, time_codes[c1], | ||
321 | c2, time_codes[c2], tca->bank[bank].ontime); | 333 | c2, time_codes[c2], tca->bank[bank].ontime); |
322 | set_code(tca, TCA6507_FADE_ON, bank, c2); | 334 | set_code(tca, TCA6507_FADE_ON, bank, c2); |
323 | set_code(tca, TCA6507_FULL_ON, bank, c1); | 335 | set_code(tca, TCA6507_FULL_ON, bank, c1); |
@@ -325,7 +337,8 @@ static void set_times(struct tca6507_chip *tca, int bank) | |||
325 | 337 | ||
326 | result = choose_times(tca->bank[bank].offtime, &c1, &c2); | 338 | result = choose_times(tca->bank[bank].offtime, &c1, &c2); |
327 | dev_dbg(&tca->client->dev, | 339 | dev_dbg(&tca->client->dev, |
328 | "Chose off times %d(%d) %d(%d) for %dms\n", c1, time_codes[c1], | 340 | "Chose off times %d(%d) %d(%d) for %dms\n", |
341 | c1, time_codes[c1], | ||
329 | c2, time_codes[c2], tca->bank[bank].offtime); | 342 | c2, time_codes[c2], tca->bank[bank].offtime); |
330 | set_code(tca, TCA6507_FADE_OFF, bank, c2); | 343 | set_code(tca, TCA6507_FADE_OFF, bank, c2); |
331 | set_code(tca, TCA6507_FIRST_OFF, bank, c1); | 344 | set_code(tca, TCA6507_FIRST_OFF, bank, c1); |
@@ -373,7 +386,8 @@ static void led_release(struct tca6507_led *led) | |||
373 | 386 | ||
374 | static int led_prepare(struct tca6507_led *led) | 387 | static int led_prepare(struct tca6507_led *led) |
375 | { | 388 | { |
376 | /* Assign this led to a bank, configuring that bank if necessary. */ | 389 | /* Assign this led to a bank, configuring that bank if |
390 | * necessary. */ | ||
377 | int level = TO_LEVEL(led->led_cdev.brightness); | 391 | int level = TO_LEVEL(led->led_cdev.brightness); |
378 | struct tca6507_chip *tca = led->chip; | 392 | struct tca6507_chip *tca = led->chip; |
379 | int c1, c2; | 393 | int c1, c2; |
@@ -389,10 +403,10 @@ static int led_prepare(struct tca6507_led *led) | |||
389 | 403 | ||
390 | if (led->ontime == 0 || led->offtime == 0) { | 404 | if (led->ontime == 0 || led->offtime == 0) { |
391 | /* | 405 | /* |
392 | * Just set the brightness, choosing first usable bank. | 406 | * Just set the brightness, choosing first usable |
393 | * If none perfect, choose best. | 407 | * bank. If none perfect, choose best. Count |
394 | * Count backwards so we check MASTER bank first | 408 | * backwards so we check MASTER bank first to avoid |
395 | * to avoid wasting a timer. | 409 | * wasting a timer. |
396 | */ | 410 | */ |
397 | int best = -1;/* full-on */ | 411 | int best = -1;/* full-on */ |
398 | int diff = 15-level; | 412 | int diff = 15-level; |
@@ -433,9 +447,9 @@ static int led_prepare(struct tca6507_led *led) | |||
433 | } | 447 | } |
434 | 448 | ||
435 | /* | 449 | /* |
436 | * We have on/off time so we need to try to allocate a timing bank. | 450 | * We have on/off time so we need to try to allocate a timing |
437 | * First check if times are compatible with hardware and give up if | 451 | * bank. First check if times are compatible with hardware |
438 | * not. | 452 | * and give up if not. |
439 | */ | 453 | */ |
440 | if (choose_times(led->ontime, &c1, &c2) < 0) | 454 | if (choose_times(led->ontime, &c1, &c2) < 0) |
441 | return -EINVAL; | 455 | return -EINVAL; |
@@ -523,8 +537,8 @@ static int led_assign(struct tca6507_led *led) | |||
523 | err = led_prepare(led); | 537 | err = led_prepare(led); |
524 | if (err) { | 538 | if (err) { |
525 | /* | 539 | /* |
526 | * Can only fail on timer setup. In that case we need to | 540 | * Can only fail on timer setup. In that case we need |
527 | * re-establish as steady level. | 541 | * to re-establish as steady level. |
528 | */ | 542 | */ |
529 | led->ontime = 0; | 543 | led->ontime = 0; |
530 | led->offtime = 0; | 544 | led->offtime = 0; |
@@ -594,8 +608,8 @@ static void tca6507_gpio_set_value(struct gpio_chip *gc, | |||
594 | 608 | ||
595 | spin_lock_irqsave(&tca->lock, flags); | 609 | spin_lock_irqsave(&tca->lock, flags); |
596 | /* | 610 | /* |
597 | * 'OFF' is floating high, and 'ON' is pulled down, so it has the | 611 | * 'OFF' is floating high, and 'ON' is pulled down, so it has |
598 | * inverse sense of 'val'. | 612 | * the inverse sense of 'val'. |
599 | */ | 613 | */ |
600 | set_select(tca, tca->gpio_map[offset], | 614 | set_select(tca, tca->gpio_map[offset], |
601 | val ? TCA6507_LS_LED_OFF : TCA6507_LS_LED_ON); | 615 | val ? TCA6507_LS_LED_OFF : TCA6507_LS_LED_ON); |