diff options
author | Axel Lin <axel.lin@ingics.com> | 2013-01-10 23:03:38 -0500 |
---|---|---|
committer | Bryan Wu <cooloney@gmail.com> | 2013-02-01 20:47:06 -0500 |
commit | 4d7983324507ff23ddf0b6e513864d4eca7a62f1 (patch) | |
tree | 93c8614f514fedca1e8742e17e02e2efd9dd8cf5 /drivers/leds | |
parent | 5e3b7c6b1cb1a579a65fa77c7f785d94013025be (diff) |
leds: renesas-tpu: Improve the readability to pick the lowest acceptable rate
I spent a few minutes to understand why the code catching the mismatch case
by checking if k is 0 or not. And the code using "k - 1" as array index is
unusual.
This patch checks acceptable rate from the lowest rate, and then we don't need
to subtract k by 1. This change improves the readability.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
Diffstat (limited to 'drivers/leds')
-rw-r--r-- | drivers/leds/leds-renesas-tpu.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/drivers/leds/leds-renesas-tpu.c b/drivers/leds/leds-renesas-tpu.c index e0fff1ca5923..d3c2b7e68fbc 100644 --- a/drivers/leds/leds-renesas-tpu.c +++ b/drivers/leds/leds-renesas-tpu.c | |||
@@ -133,24 +133,24 @@ static int r_tpu_enable(struct r_tpu_priv *p, enum led_brightness brightness) | |||
133 | rate = clk_get_rate(p->clk); | 133 | rate = clk_get_rate(p->clk); |
134 | 134 | ||
135 | /* pick the lowest acceptable rate */ | 135 | /* pick the lowest acceptable rate */ |
136 | for (k = 0; k < ARRAY_SIZE(prescaler); k++) | 136 | for (k = ARRAY_SIZE(prescaler) - 1; k >= 0; k--) |
137 | if ((rate / prescaler[k]) < p->min_rate) | 137 | if ((rate / prescaler[k]) >= p->min_rate) |
138 | break; | 138 | break; |
139 | 139 | ||
140 | if (!k) { | 140 | if (k < 0) { |
141 | dev_err(&p->pdev->dev, "clock rate mismatch\n"); | 141 | dev_err(&p->pdev->dev, "clock rate mismatch\n"); |
142 | goto err0; | 142 | goto err0; |
143 | } | 143 | } |
144 | dev_dbg(&p->pdev->dev, "rate = %lu, prescaler %u\n", | 144 | dev_dbg(&p->pdev->dev, "rate = %lu, prescaler %u\n", |
145 | rate, prescaler[k - 1]); | 145 | rate, prescaler[k]); |
146 | 146 | ||
147 | /* clear TCNT on TGRB match, count on rising edge, set prescaler */ | 147 | /* clear TCNT on TGRB match, count on rising edge, set prescaler */ |
148 | r_tpu_write(p, TCR, 0x0040 | (k - 1)); | 148 | r_tpu_write(p, TCR, 0x0040 | k); |
149 | 149 | ||
150 | /* output 0 until TGRA, output 1 until TGRB */ | 150 | /* output 0 until TGRA, output 1 until TGRB */ |
151 | r_tpu_write(p, TIOR, 0x0002); | 151 | r_tpu_write(p, TIOR, 0x0002); |
152 | 152 | ||
153 | rate /= prescaler[k - 1] * p->refresh_rate; | 153 | rate /= prescaler[k] * p->refresh_rate; |
154 | r_tpu_write(p, TGRB, rate); | 154 | r_tpu_write(p, TGRB, rate); |
155 | dev_dbg(&p->pdev->dev, "TRGB = 0x%04lx\n", rate); | 155 | dev_dbg(&p->pdev->dev, "TRGB = 0x%04lx\n", rate); |
156 | 156 | ||