aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/arm/common/sa1111.c9
-rw-r--r--arch/arm/common/timer-sp.c9
-rw-r--r--drivers/amba/bus.c11
-rw-r--r--drivers/mmc/host/mmci.c9
-rw-r--r--drivers/spi/spi-pl022.c10
-rw-r--r--drivers/tty/serial/amba-pl010.c14
-rw-r--r--drivers/tty/serial/amba-pl011.c14
-rw-r--r--drivers/video/amba-clcd.c9
-rw-r--r--include/linux/clk.h43
-rw-r--r--include/linux/clkdev.h7
10 files changed, 129 insertions, 6 deletions
diff --git a/arch/arm/common/sa1111.c b/arch/arm/common/sa1111.c
index 0569de6acfba..61691cdbdcf2 100644
--- a/arch/arm/common/sa1111.c
+++ b/arch/arm/common/sa1111.c
@@ -718,6 +718,10 @@ __sa1111_probe(struct device *me, struct resource *mem, int irq)
718 goto err_free; 718 goto err_free;
719 } 719 }
720 720
721 ret = clk_prepare(sachip->clk);
722 if (ret)
723 goto err_clkput;
724
721 spin_lock_init(&sachip->lock); 725 spin_lock_init(&sachip->lock);
722 726
723 sachip->dev = me; 727 sachip->dev = me;
@@ -733,7 +737,7 @@ __sa1111_probe(struct device *me, struct resource *mem, int irq)
733 sachip->base = ioremap(mem->start, PAGE_SIZE * 2); 737 sachip->base = ioremap(mem->start, PAGE_SIZE * 2);
734 if (!sachip->base) { 738 if (!sachip->base) {
735 ret = -ENOMEM; 739 ret = -ENOMEM;
736 goto err_clkput; 740 goto err_clk_unprep;
737 } 741 }
738 742
739 /* 743 /*
@@ -809,6 +813,8 @@ __sa1111_probe(struct device *me, struct resource *mem, int irq)
809 813
810 err_unmap: 814 err_unmap:
811 iounmap(sachip->base); 815 iounmap(sachip->base);
816 err_clk_unprep:
817 clk_unprepare(sachip->clk);
812 err_clkput: 818 err_clkput:
813 clk_put(sachip->clk); 819 clk_put(sachip->clk);
814 err_free: 820 err_free:
@@ -835,6 +841,7 @@ static void __sa1111_remove(struct sa1111 *sachip)
835 sa1111_writel(0, irqbase + SA1111_WAKEEN1); 841 sa1111_writel(0, irqbase + SA1111_WAKEEN1);
836 842
837 clk_disable(sachip->clk); 843 clk_disable(sachip->clk);
844 clk_unprepare(sachip->clk);
838 845
839 if (sachip->irq != NO_IRQ) { 846 if (sachip->irq != NO_IRQ) {
840 irq_set_chained_handler(sachip->irq, NULL); 847 irq_set_chained_handler(sachip->irq, NULL);
diff --git a/arch/arm/common/timer-sp.c b/arch/arm/common/timer-sp.c
index 41df47875122..2393b5bc96fa 100644
--- a/arch/arm/common/timer-sp.c
+++ b/arch/arm/common/timer-sp.c
@@ -41,9 +41,17 @@ static long __init sp804_get_clock_rate(const char *name)
41 return PTR_ERR(clk); 41 return PTR_ERR(clk);
42 } 42 }
43 43
44 err = clk_prepare(clk);
45 if (err) {
46 pr_err("sp804: %s clock failed to prepare: %d\n", name, err);
47 clk_put(clk);
48 return err;
49 }
50
44 err = clk_enable(clk); 51 err = clk_enable(clk);
45 if (err) { 52 if (err) {
46 pr_err("sp804: %s clock failed to enable: %d\n", name, err); 53 pr_err("sp804: %s clock failed to enable: %d\n", name, err);
54 clk_unprepare(clk);
47 clk_put(clk); 55 clk_put(clk);
48 return err; 56 return err;
49 } 57 }
@@ -52,6 +60,7 @@ static long __init sp804_get_clock_rate(const char *name)
52 if (rate < 0) { 60 if (rate < 0) {
53 pr_err("sp804: %s clock failed to get rate: %ld\n", name, rate); 61 pr_err("sp804: %s clock failed to get rate: %ld\n", name, rate);
54 clk_disable(clk); 62 clk_disable(clk);
63 clk_unprepare(clk);
55 clk_put(clk); 64 clk_put(clk);
56 } 65 }
57 66
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 84bdaace56c8..bd230e801131 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -460,9 +460,17 @@ static int amba_get_enable_pclk(struct amba_device *pcdev)
460 if (IS_ERR(pclk)) 460 if (IS_ERR(pclk))
461 return PTR_ERR(pclk); 461 return PTR_ERR(pclk);
462 462
463 ret = clk_prepare(pclk);
464 if (ret) {
465 clk_put(pclk);
466 return ret;
467 }
468
463 ret = clk_enable(pclk); 469 ret = clk_enable(pclk);
464 if (ret) 470 if (ret) {
471 clk_unprepare(pclk);
465 clk_put(pclk); 472 clk_put(pclk);
473 }
466 474
467 return ret; 475 return ret;
468} 476}
@@ -472,6 +480,7 @@ static void amba_put_disable_pclk(struct amba_device *pcdev)
472 struct clk *pclk = pcdev->pclk; 480 struct clk *pclk = pcdev->pclk;
473 481
474 clk_disable(pclk); 482 clk_disable(pclk);
483 clk_unprepare(pclk);
475 clk_put(pclk); 484 clk_put(pclk);
476} 485}
477 486
diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
index 5e142b7f5ecf..7be8db0f9f7d 100644
--- a/drivers/mmc/host/mmci.c
+++ b/drivers/mmc/host/mmci.c
@@ -1160,10 +1160,14 @@ static int __devinit mmci_probe(struct amba_device *dev,
1160 goto host_free; 1160 goto host_free;
1161 } 1161 }
1162 1162
1163 ret = clk_enable(host->clk); 1163 ret = clk_prepare(host->clk);
1164 if (ret) 1164 if (ret)
1165 goto clk_free; 1165 goto clk_free;
1166 1166
1167 ret = clk_enable(host->clk);
1168 if (ret)
1169 goto clk_unprep;
1170
1167 host->plat = plat; 1171 host->plat = plat;
1168 host->variant = variant; 1172 host->variant = variant;
1169 host->mclk = clk_get_rate(host->clk); 1173 host->mclk = clk_get_rate(host->clk);
@@ -1351,6 +1355,8 @@ static int __devinit mmci_probe(struct amba_device *dev,
1351 iounmap(host->base); 1355 iounmap(host->base);
1352 clk_disable: 1356 clk_disable:
1353 clk_disable(host->clk); 1357 clk_disable(host->clk);
1358 clk_unprep:
1359 clk_unprepare(host->clk);
1354 clk_free: 1360 clk_free:
1355 clk_put(host->clk); 1361 clk_put(host->clk);
1356 host_free: 1362 host_free:
@@ -1398,6 +1404,7 @@ static int __devexit mmci_remove(struct amba_device *dev)
1398 1404
1399 iounmap(host->base); 1405 iounmap(host->base);
1400 clk_disable(host->clk); 1406 clk_disable(host->clk);
1407 clk_unprepare(host->clk);
1401 clk_put(host->clk); 1408 clk_put(host->clk);
1402 1409
1403 if (host->vcc) 1410 if (host->vcc)
diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c
index 3520cf955b95..1ab2fa0d37fd 100644
--- a/drivers/spi/spi-pl022.c
+++ b/drivers/spi/spi-pl022.c
@@ -2187,6 +2187,13 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
2187 dev_err(&adev->dev, "could not retrieve SSP/SPI bus clock\n"); 2187 dev_err(&adev->dev, "could not retrieve SSP/SPI bus clock\n");
2188 goto err_no_clk; 2188 goto err_no_clk;
2189 } 2189 }
2190
2191 status = clk_prepare(pl022->clk);
2192 if (status) {
2193 dev_err(&adev->dev, "could not prepare SSP/SPI bus clock\n");
2194 goto err_clk_prep;
2195 }
2196
2190 /* Disable SSP */ 2197 /* Disable SSP */
2191 writew((readw(SSP_CR1(pl022->virtbase)) & (~SSP_CR1_MASK_SSE)), 2198 writew((readw(SSP_CR1(pl022->virtbase)) & (~SSP_CR1_MASK_SSE)),
2192 SSP_CR1(pl022->virtbase)); 2199 SSP_CR1(pl022->virtbase));
@@ -2238,6 +2245,8 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
2238 pl022_dma_remove(pl022); 2245 pl022_dma_remove(pl022);
2239 free_irq(adev->irq[0], pl022); 2246 free_irq(adev->irq[0], pl022);
2240 err_no_irq: 2247 err_no_irq:
2248 clk_unprepare(pl022->clk);
2249 err_clk_prep:
2241 clk_put(pl022->clk); 2250 clk_put(pl022->clk);
2242 err_no_clk: 2251 err_no_clk:
2243 iounmap(pl022->virtbase); 2252 iounmap(pl022->virtbase);
@@ -2271,6 +2280,7 @@ pl022_remove(struct amba_device *adev)
2271 pl022_dma_remove(pl022); 2280 pl022_dma_remove(pl022);
2272 free_irq(adev->irq[0], pl022); 2281 free_irq(adev->irq[0], pl022);
2273 clk_disable(pl022->clk); 2282 clk_disable(pl022->clk);
2283 clk_unprepare(pl022->clk);
2274 clk_put(pl022->clk); 2284 clk_put(pl022->clk);
2275 iounmap(pl022->virtbase); 2285 iounmap(pl022->virtbase);
2276 amba_release_regions(adev); 2286 amba_release_regions(adev);
diff --git a/drivers/tty/serial/amba-pl010.c b/drivers/tty/serial/amba-pl010.c
index c0d10c4ddb73..efdf92c3a352 100644
--- a/drivers/tty/serial/amba-pl010.c
+++ b/drivers/tty/serial/amba-pl010.c
@@ -312,12 +312,16 @@ static int pl010_startup(struct uart_port *port)
312 struct uart_amba_port *uap = (struct uart_amba_port *)port; 312 struct uart_amba_port *uap = (struct uart_amba_port *)port;
313 int retval; 313 int retval;
314 314
315 retval = clk_prepare(uap->clk);
316 if (retval)
317 goto out;
318
315 /* 319 /*
316 * Try to enable the clock producer. 320 * Try to enable the clock producer.
317 */ 321 */
318 retval = clk_enable(uap->clk); 322 retval = clk_enable(uap->clk);
319 if (retval) 323 if (retval)
320 goto out; 324 goto clk_unprep;
321 325
322 uap->port.uartclk = clk_get_rate(uap->clk); 326 uap->port.uartclk = clk_get_rate(uap->clk);
323 327
@@ -343,6 +347,8 @@ static int pl010_startup(struct uart_port *port)
343 347
344 clk_dis: 348 clk_dis:
345 clk_disable(uap->clk); 349 clk_disable(uap->clk);
350 clk_unprep:
351 clk_unprepare(uap->clk);
346 out: 352 out:
347 return retval; 353 return retval;
348} 354}
@@ -370,6 +376,7 @@ static void pl010_shutdown(struct uart_port *port)
370 * Shut down the clock producer 376 * Shut down the clock producer
371 */ 377 */
372 clk_disable(uap->clk); 378 clk_disable(uap->clk);
379 clk_unprepare(uap->clk);
373} 380}
374 381
375static void 382static void
@@ -626,6 +633,7 @@ static int __init pl010_console_setup(struct console *co, char *options)
626 int bits = 8; 633 int bits = 8;
627 int parity = 'n'; 634 int parity = 'n';
628 int flow = 'n'; 635 int flow = 'n';
636 int ret;
629 637
630 /* 638 /*
631 * Check whether an invalid uart number has been specified, and 639 * Check whether an invalid uart number has been specified, and
@@ -638,6 +646,10 @@ static int __init pl010_console_setup(struct console *co, char *options)
638 if (!uap) 646 if (!uap)
639 return -ENODEV; 647 return -ENODEV;
640 648
649 ret = clk_prepare(uap->clk);
650 if (ret)
651 return ret;
652
641 uap->port.uartclk = clk_get_rate(uap->clk); 653 uap->port.uartclk = clk_get_rate(uap->clk);
642 654
643 if (options) 655 if (options)
diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
index f5f6831b0a64..00233af1acc4 100644
--- a/drivers/tty/serial/amba-pl011.c
+++ b/drivers/tty/serial/amba-pl011.c
@@ -1367,12 +1367,16 @@ static int pl011_startup(struct uart_port *port)
1367 unsigned int cr; 1367 unsigned int cr;
1368 int retval; 1368 int retval;
1369 1369
1370 retval = clk_prepare(uap->clk);
1371 if (retval)
1372 goto out;
1373
1370 /* 1374 /*
1371 * Try to enable the clock producer. 1375 * Try to enable the clock producer.
1372 */ 1376 */
1373 retval = clk_enable(uap->clk); 1377 retval = clk_enable(uap->clk);
1374 if (retval) 1378 if (retval)
1375 goto out; 1379 goto clk_unprep;
1376 1380
1377 uap->port.uartclk = clk_get_rate(uap->clk); 1381 uap->port.uartclk = clk_get_rate(uap->clk);
1378 1382
@@ -1446,6 +1450,8 @@ static int pl011_startup(struct uart_port *port)
1446 1450
1447 clk_dis: 1451 clk_dis:
1448 clk_disable(uap->clk); 1452 clk_disable(uap->clk);
1453 clk_unprep:
1454 clk_unprepare(uap->clk);
1449 out: 1455 out:
1450 return retval; 1456 return retval;
1451} 1457}
@@ -1497,6 +1503,7 @@ static void pl011_shutdown(struct uart_port *port)
1497 * Shut down the clock producer 1503 * Shut down the clock producer
1498 */ 1504 */
1499 clk_disable(uap->clk); 1505 clk_disable(uap->clk);
1506 clk_unprepare(uap->clk);
1500 1507
1501 if (uap->port.dev->platform_data) { 1508 if (uap->port.dev->platform_data) {
1502 struct amba_pl011_data *plat; 1509 struct amba_pl011_data *plat;
@@ -1800,6 +1807,7 @@ static int __init pl011_console_setup(struct console *co, char *options)
1800 int bits = 8; 1807 int bits = 8;
1801 int parity = 'n'; 1808 int parity = 'n';
1802 int flow = 'n'; 1809 int flow = 'n';
1810 int ret;
1803 1811
1804 /* 1812 /*
1805 * Check whether an invalid uart number has been specified, and 1813 * Check whether an invalid uart number has been specified, and
@@ -1812,6 +1820,10 @@ static int __init pl011_console_setup(struct console *co, char *options)
1812 if (!uap) 1820 if (!uap)
1813 return -ENODEV; 1821 return -ENODEV;
1814 1822
1823 ret = clk_prepare(uap->clk);
1824 if (ret)
1825 return ret;
1826
1815 if (uap->port.dev->platform_data) { 1827 if (uap->port.dev->platform_data) {
1816 struct amba_pl011_data *plat; 1828 struct amba_pl011_data *plat;
1817 1829
diff --git a/drivers/video/amba-clcd.c b/drivers/video/amba-clcd.c
index cf03ad067147..2cda6ba0939b 100644
--- a/drivers/video/amba-clcd.c
+++ b/drivers/video/amba-clcd.c
@@ -447,6 +447,10 @@ static int clcdfb_register(struct clcd_fb *fb)
447 goto out; 447 goto out;
448 } 448 }
449 449
450 ret = clk_prepare(fb->clk);
451 if (ret)
452 goto free_clk;
453
450 fb->fb.device = &fb->dev->dev; 454 fb->fb.device = &fb->dev->dev;
451 455
452 fb->fb.fix.mmio_start = fb->dev->res.start; 456 fb->fb.fix.mmio_start = fb->dev->res.start;
@@ -456,7 +460,7 @@ static int clcdfb_register(struct clcd_fb *fb)
456 if (!fb->regs) { 460 if (!fb->regs) {
457 printk(KERN_ERR "CLCD: unable to remap registers\n"); 461 printk(KERN_ERR "CLCD: unable to remap registers\n");
458 ret = -ENOMEM; 462 ret = -ENOMEM;
459 goto free_clk; 463 goto clk_unprep;
460 } 464 }
461 465
462 fb->fb.fbops = &clcdfb_ops; 466 fb->fb.fbops = &clcdfb_ops;
@@ -530,6 +534,8 @@ static int clcdfb_register(struct clcd_fb *fb)
530 fb_dealloc_cmap(&fb->fb.cmap); 534 fb_dealloc_cmap(&fb->fb.cmap);
531 unmap: 535 unmap:
532 iounmap(fb->regs); 536 iounmap(fb->regs);
537 clk_unprep:
538 clk_unprepare(fb->clk);
533 free_clk: 539 free_clk:
534 clk_put(fb->clk); 540 clk_put(fb->clk);
535 out: 541 out:
@@ -595,6 +601,7 @@ static int clcdfb_remove(struct amba_device *dev)
595 if (fb->fb.cmap.len) 601 if (fb->fb.cmap.len)
596 fb_dealloc_cmap(&fb->fb.cmap); 602 fb_dealloc_cmap(&fb->fb.cmap);
597 iounmap(fb->regs); 603 iounmap(fb->regs);
604 clk_unprepare(fb->clk);
598 clk_put(fb->clk); 605 clk_put(fb->clk);
599 606
600 fb->board->remove(fb); 607 fb->board->remove(fb);
diff --git a/include/linux/clk.h b/include/linux/clk.h
index 1d37f42ac294..7213b52b2c0e 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -11,6 +11,8 @@
11#ifndef __LINUX_CLK_H 11#ifndef __LINUX_CLK_H
12#define __LINUX_CLK_H 12#define __LINUX_CLK_H
13 13
14#include <linux/kernel.h>
15
14struct device; 16struct device;
15 17
16/* 18/*
@@ -41,11 +43,31 @@ struct clk;
41struct clk *clk_get(struct device *dev, const char *id); 43struct clk *clk_get(struct device *dev, const char *id);
42 44
43/** 45/**
46 * clk_prepare - prepare a clock source
47 * @clk: clock source
48 *
49 * This prepares the clock source for use.
50 *
51 * Must not be called from within atomic context.
52 */
53#ifdef CONFIG_HAVE_CLK_PREPARE
54int clk_prepare(struct clk *clk);
55#else
56static inline int clk_prepare(struct clk *clk)
57{
58 might_sleep();
59 return 0;
60}
61#endif
62
63/**
44 * clk_enable - inform the system when the clock source should be running. 64 * clk_enable - inform the system when the clock source should be running.
45 * @clk: clock source 65 * @clk: clock source
46 * 66 *
47 * If the clock can not be enabled/disabled, this should return success. 67 * If the clock can not be enabled/disabled, this should return success.
48 * 68 *
69 * May be called from atomic contexts.
70 *
49 * Returns success (0) or negative errno. 71 * Returns success (0) or negative errno.
50 */ 72 */
51int clk_enable(struct clk *clk); 73int clk_enable(struct clk *clk);
@@ -57,6 +79,8 @@ int clk_enable(struct clk *clk);
57 * Inform the system that a clock source is no longer required by 79 * Inform the system that a clock source is no longer required by
58 * a driver and may be shut down. 80 * a driver and may be shut down.
59 * 81 *
82 * May be called from atomic contexts.
83 *
60 * Implementation detail: if the clock source is shared between 84 * Implementation detail: if the clock source is shared between
61 * multiple drivers, clk_enable() calls must be balanced by the 85 * multiple drivers, clk_enable() calls must be balanced by the
62 * same number of clk_disable() calls for the clock source to be 86 * same number of clk_disable() calls for the clock source to be
@@ -64,6 +88,25 @@ int clk_enable(struct clk *clk);
64 */ 88 */
65void clk_disable(struct clk *clk); 89void clk_disable(struct clk *clk);
66 90
91
92/**
93 * clk_unprepare - undo preparation of a clock source
94 * @clk: clock source
95 *
96 * This undoes a previously prepared clock. The caller must balance
97 * the number of prepare and unprepare calls.
98 *
99 * Must not be called from within atomic context.
100 */
101#ifdef CONFIG_HAVE_CLK_PREPARE
102void clk_unprepare(struct clk *clk);
103#else
104static inline void clk_unprepare(struct clk *clk)
105{
106 might_sleep();
107}
108#endif
109
67/** 110/**
68 * clk_get_rate - obtain the current clock rate (in Hz) for a clock source. 111 * clk_get_rate - obtain the current clock rate (in Hz) for a clock source.
69 * This is only valid once the clock source has been enabled. 112 * This is only valid once the clock source has been enabled.
diff --git a/include/linux/clkdev.h b/include/linux/clkdev.h
index 457bcb0a310a..d9a4fd028c9d 100644
--- a/include/linux/clkdev.h
+++ b/include/linux/clkdev.h
@@ -24,6 +24,13 @@ struct clk_lookup {
24 struct clk *clk; 24 struct clk *clk;
25}; 25};
26 26
27#define CLKDEV_INIT(d, n, c) \
28 { \
29 .dev_id = d, \
30 .con_id = n, \
31 .clk = c, \
32 }
33
27struct clk_lookup *clkdev_alloc(struct clk *clk, const char *con_id, 34struct clk_lookup *clkdev_alloc(struct clk *clk, const char *con_id,
28 const char *dev_fmt, ...); 35 const char *dev_fmt, ...);
29 36