diff options
Diffstat (limited to 'drivers/clocksource/sh_tmu.c')
-rw-r--r-- | drivers/clocksource/sh_tmu.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/drivers/clocksource/sh_tmu.c b/drivers/clocksource/sh_tmu.c index 36aba9923060..17296288a205 100644 --- a/drivers/clocksource/sh_tmu.c +++ b/drivers/clocksource/sh_tmu.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/delay.h> | 25 | #include <linux/delay.h> |
26 | #include <linux/io.h> | 26 | #include <linux/io.h> |
27 | #include <linux/clk.h> | 27 | #include <linux/clk.h> |
28 | #include <linux/pm_runtime.h> | ||
28 | #include <linux/irq.h> | 29 | #include <linux/irq.h> |
29 | #include <linux/err.h> | 30 | #include <linux/err.h> |
30 | #include <linux/clocksource.h> | 31 | #include <linux/clocksource.h> |
@@ -109,10 +110,12 @@ static int sh_tmu_enable(struct sh_tmu_priv *p) | |||
109 | { | 110 | { |
110 | int ret; | 111 | int ret; |
111 | 112 | ||
112 | /* enable clock */ | 113 | /* wake up device and enable clock */ |
114 | pm_runtime_get_sync(&p->pdev->dev); | ||
113 | ret = clk_enable(p->clk); | 115 | ret = clk_enable(p->clk); |
114 | if (ret) { | 116 | if (ret) { |
115 | dev_err(&p->pdev->dev, "cannot enable clock\n"); | 117 | dev_err(&p->pdev->dev, "cannot enable clock\n"); |
118 | pm_runtime_put_sync(&p->pdev->dev); | ||
116 | return ret; | 119 | return ret; |
117 | } | 120 | } |
118 | 121 | ||
@@ -141,8 +144,9 @@ static void sh_tmu_disable(struct sh_tmu_priv *p) | |||
141 | /* disable interrupts in TMU block */ | 144 | /* disable interrupts in TMU block */ |
142 | sh_tmu_write(p, TCR, 0x0000); | 145 | sh_tmu_write(p, TCR, 0x0000); |
143 | 146 | ||
144 | /* stop clock */ | 147 | /* stop clock and mark device as idle */ |
145 | clk_disable(p->clk); | 148 | clk_disable(p->clk); |
149 | pm_runtime_put_sync(&p->pdev->dev); | ||
146 | } | 150 | } |
147 | 151 | ||
148 | static void sh_tmu_set_next(struct sh_tmu_priv *p, unsigned long delta, | 152 | static void sh_tmu_set_next(struct sh_tmu_priv *p, unsigned long delta, |
@@ -199,8 +203,12 @@ static cycle_t sh_tmu_clocksource_read(struct clocksource *cs) | |||
199 | static int sh_tmu_clocksource_enable(struct clocksource *cs) | 203 | static int sh_tmu_clocksource_enable(struct clocksource *cs) |
200 | { | 204 | { |
201 | struct sh_tmu_priv *p = cs_to_sh_tmu(cs); | 205 | struct sh_tmu_priv *p = cs_to_sh_tmu(cs); |
206 | int ret; | ||
202 | 207 | ||
203 | return sh_tmu_enable(p); | 208 | ret = sh_tmu_enable(p); |
209 | if (!ret) | ||
210 | __clocksource_updatefreq_hz(cs, p->rate); | ||
211 | return ret; | ||
204 | } | 212 | } |
205 | 213 | ||
206 | static void sh_tmu_clocksource_disable(struct clocksource *cs) | 214 | static void sh_tmu_clocksource_disable(struct clocksource *cs) |
@@ -221,17 +229,10 @@ static int sh_tmu_register_clocksource(struct sh_tmu_priv *p, | |||
221 | cs->mask = CLOCKSOURCE_MASK(32); | 229 | cs->mask = CLOCKSOURCE_MASK(32); |
222 | cs->flags = CLOCK_SOURCE_IS_CONTINUOUS; | 230 | cs->flags = CLOCK_SOURCE_IS_CONTINUOUS; |
223 | 231 | ||
224 | /* clk_get_rate() needs an enabled clock */ | ||
225 | clk_enable(p->clk); | ||
226 | /* channel will be configured at parent clock / 4 */ | ||
227 | p->rate = clk_get_rate(p->clk) / 4; | ||
228 | clk_disable(p->clk); | ||
229 | /* TODO: calculate good shift from rate and counter bit width */ | ||
230 | cs->shift = 10; | ||
231 | cs->mult = clocksource_hz2mult(p->rate, cs->shift); | ||
232 | |||
233 | dev_info(&p->pdev->dev, "used as clock source\n"); | 232 | dev_info(&p->pdev->dev, "used as clock source\n"); |
234 | clocksource_register(cs); | 233 | |
234 | /* Register with dummy 1 Hz value, gets updated in ->enable() */ | ||
235 | clocksource_register_hz(cs, 1); | ||
235 | return 0; | 236 | return 0; |
236 | } | 237 | } |
237 | 238 | ||
@@ -414,6 +415,7 @@ static int __devinit sh_tmu_probe(struct platform_device *pdev) | |||
414 | 415 | ||
415 | if (p) { | 416 | if (p) { |
416 | dev_info(&pdev->dev, "kept as earlytimer\n"); | 417 | dev_info(&pdev->dev, "kept as earlytimer\n"); |
418 | pm_runtime_enable(&pdev->dev); | ||
417 | return 0; | 419 | return 0; |
418 | } | 420 | } |
419 | 421 | ||
@@ -428,6 +430,9 @@ static int __devinit sh_tmu_probe(struct platform_device *pdev) | |||
428 | kfree(p); | 430 | kfree(p); |
429 | platform_set_drvdata(pdev, NULL); | 431 | platform_set_drvdata(pdev, NULL); |
430 | } | 432 | } |
433 | |||
434 | if (!is_early_platform_device(pdev)) | ||
435 | pm_runtime_enable(&pdev->dev); | ||
431 | return ret; | 436 | return ret; |
432 | } | 437 | } |
433 | 438 | ||