Skip to content

Commit b6a6bdf

Browse files
author
Sebastian Andrzej Siewior
committed
arm: at91: do not disable/enable clocks in a row
Currently the driver will disable the clock and enable it one line later if it is switching from periodic mode into one shot. This can be avoided and causes a needless warning on -RT. Signed-off-by: Sebastian Andrzej Siewior <[email protected]>
1 parent 7493477 commit b6a6bdf

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

drivers/clocksource/tcb_clksrc.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ static struct clocksource clksrc = {
126126
struct tc_clkevt_device {
127127
struct clock_event_device clkevt;
128128
struct clk *clk;
129+
bool clk_enabled;
129130
void __iomem *regs;
130131
};
131132

@@ -143,15 +144,39 @@ static struct tc_clkevt_device *to_tc_clkevt(struct clock_event_device *clkevt)
143144
*/
144145
static u32 timer_clock;
145146

147+
static void tc_clk_disable(struct clock_event_device *d)
148+
{
149+
struct tc_clkevt_device *tcd = to_tc_clkevt(d);
150+
151+
clk_disable(tcd->clk);
152+
tcd->clk_enabled = false;
153+
}
154+
155+
static void tc_clk_enable(struct clock_event_device *d)
156+
{
157+
struct tc_clkevt_device *tcd = to_tc_clkevt(d);
158+
159+
if (tcd->clk_enabled)
160+
return;
161+
clk_enable(tcd->clk);
162+
tcd->clk_enabled = true;
163+
}
164+
146165
static int tc_shutdown(struct clock_event_device *d)
147166
{
148167
struct tc_clkevt_device *tcd = to_tc_clkevt(d);
149168
void __iomem *regs = tcd->regs;
150169

151170
writel(0xff, regs + ATMEL_TC_REG(2, IDR));
152171
writel(ATMEL_TC_CLKDIS, regs + ATMEL_TC_REG(2, CCR));
172+
return 0;
173+
}
174+
175+
static int tc_shutdown_clk_off(struct clock_event_device *d)
176+
{
177+
tc_shutdown(d);
153178
if (!clockevent_state_detached(d))
154-
clk_disable(tcd->clk);
179+
tc_clk_disable(d);
155180

156181
return 0;
157182
}
@@ -164,7 +189,7 @@ static int tc_set_oneshot(struct clock_event_device *d)
164189
if (clockevent_state_oneshot(d) || clockevent_state_periodic(d))
165190
tc_shutdown(d);
166191

167-
clk_enable(tcd->clk);
192+
tc_clk_enable(d);
168193

169194
/* slow clock, count up to RC, then irq and stop */
170195
writel(timer_clock | ATMEL_TC_CPCSTOP | ATMEL_TC_WAVE |
@@ -186,7 +211,7 @@ static int tc_set_periodic(struct clock_event_device *d)
186211
/* By not making the gentime core emulate periodic mode on top
187212
* of oneshot, we get lower overhead and improved accuracy.
188213
*/
189-
clk_enable(tcd->clk);
214+
tc_clk_enable(d);
190215

191216
/* slow clock, count up to RC, then irq and restart */
192217
writel(timer_clock | ATMEL_TC_WAVE | ATMEL_TC_WAVESEL_UP_AUTO,
@@ -220,7 +245,7 @@ static struct tc_clkevt_device clkevt = {
220245
/* Should be lower than at91rm9200's system timer */
221246
.rating = 125,
222247
.set_next_event = tc_next_event,
223-
.set_state_shutdown = tc_shutdown,
248+
.set_state_shutdown = tc_shutdown_clk_off,
224249
.set_state_periodic = tc_set_periodic,
225250
.set_state_oneshot = tc_set_oneshot,
226251
},

0 commit comments

Comments
 (0)