Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'clk' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc

clock management changes for i.MX

Another simple series related to clock management, this time only for
imx.

* tag 'clk' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc:
ARM: mxs: select HAVE_CLK_PREPARE for clock
clk: add config option HAVE_CLK_PREPARE into Kconfig
ASoC: mxs-saif: convert to clk_prepare/clk_unprepare
video: mxsfb: convert to clk_prepare/clk_unprepare
serial: mxs-auart: convert to clk_prepare/clk_unprepare
net: flexcan: convert to clk_prepare/clk_unprepare
mtd: gpmi-lib: convert to clk_prepare/clk_unprepare
mmc: mxs-mmc: convert to clk_prepare/clk_unprepare
dma: mxs-dma: convert to clk_prepare/clk_unprepare
net: fec: add clk_prepare/clk_unprepare
ARM: mxs: convert platform code to clk_prepare/clk_unprepare
clk: add helper functions clk_prepare_enable and clk_disable_unprepare

Fix up trivial conflicts in drivers/net/ethernet/freescale/fec.c due to
commit 0ebafefcaa7a ("net: fec: add clk_prepare/clk_unprepare") clashing
trivially with commit e163cc97f9ac ("net/fec: fix the .remove code").

+97 -58
+1
arch/arm/Kconfig
··· 447 447 select ARCH_REQUIRE_GPIOLIB 448 448 select CLKDEV_LOOKUP 449 449 select CLKSRC_MMIO 450 + select HAVE_CLK_PREPARE 450 451 help 451 452 Support for Freescale MXS-based family of processors 452 453
+5 -5
arch/arm/mach-mxs/clock-mx23.c
··· 545 545 */ 546 546 clk_set_parent(&ssp_clk, &ref_io_clk); 547 547 548 - clk_enable(&cpu_clk); 549 - clk_enable(&hbus_clk); 550 - clk_enable(&xbus_clk); 551 - clk_enable(&emi_clk); 552 - clk_enable(&uart_clk); 548 + clk_prepare_enable(&cpu_clk); 549 + clk_prepare_enable(&hbus_clk); 550 + clk_prepare_enable(&xbus_clk); 551 + clk_prepare_enable(&emi_clk); 552 + clk_prepare_enable(&uart_clk); 553 553 554 554 clkdev_add_table(lookups, ARRAY_SIZE(lookups)); 555 555
+5 -5
arch/arm/mach-mxs/clock-mx28.c
··· 804 804 clk_set_parent(&ssp0_clk, &ref_io0_clk); 805 805 clk_set_parent(&ssp1_clk, &ref_io0_clk); 806 806 807 - clk_enable(&cpu_clk); 808 - clk_enable(&hbus_clk); 809 - clk_enable(&xbus_clk); 810 - clk_enable(&emi_clk); 811 - clk_enable(&uart_clk); 807 + clk_prepare_enable(&cpu_clk); 808 + clk_prepare_enable(&hbus_clk); 809 + clk_prepare_enable(&xbus_clk); 810 + clk_prepare_enable(&emi_clk); 811 + clk_prepare_enable(&uart_clk); 812 812 813 813 clk_set_parent(&lcdif_clk, &ref_pix_clk); 814 814 clk_set_parent(&saif0_clk, &pll0_clk);
+23 -10
arch/arm/mach-mxs/clock.c
··· 74 74 return 0; 75 75 } 76 76 77 - /* This function increments the reference count on the clock and enables the 78 - * clock if not already enabled. The parent clock tree is recursively enabled 77 + /* 78 + * The clk_enable/clk_disable could be called by drivers in atomic context, 79 + * so they should not really hold mutex. Instead, clk_prepare/clk_unprepare 80 + * can hold a mutex, as the pair will only be called in non-atomic context. 81 + * Before migrating to common clk framework, we can have __clk_enable and 82 + * __clk_disable called in clk_prepare/clk_unprepare with mutex held and 83 + * leave clk_enable/clk_disable as the dummy functions. 79 84 */ 80 - int clk_enable(struct clk *clk) 85 + int clk_prepare(struct clk *clk) 81 86 { 82 87 int ret = 0; 83 88 ··· 95 90 96 91 return ret; 97 92 } 98 - EXPORT_SYMBOL(clk_enable); 93 + EXPORT_SYMBOL(clk_prepare); 99 94 100 - /* This function decrements the reference count on the clock and disables 101 - * the clock when reference count is 0. The parent clock tree is 102 - * recursively disabled 103 - */ 104 - void clk_disable(struct clk *clk) 95 + void clk_unprepare(struct clk *clk) 105 96 { 106 97 if (clk == NULL || IS_ERR(clk)) 107 98 return; ··· 105 104 mutex_lock(&clocks_mutex); 106 105 __clk_disable(clk); 107 106 mutex_unlock(&clocks_mutex); 107 + } 108 + EXPORT_SYMBOL(clk_unprepare); 109 + 110 + int clk_enable(struct clk *clk) 111 + { 112 + return 0; 113 + } 114 + EXPORT_SYMBOL(clk_enable); 115 + 116 + void clk_disable(struct clk *clk) 117 + { 118 + /* nothing to do */ 108 119 } 109 120 EXPORT_SYMBOL(clk_disable); 110 121 ··· 179 166 return ret; 180 167 181 168 if (clk->usecount) 182 - clk_enable(parent); 169 + clk_prepare_enable(parent); 183 170 184 171 mutex_lock(&clocks_mutex); 185 172 ret = clk->set_parent(clk, parent);
+1 -1
arch/arm/mach-mxs/mach-mx28evk.c
··· 229 229 /* Enable fec phy clock */ 230 230 clk = clk_get_sys("pll2", NULL); 231 231 if (!IS_ERR(clk)) 232 - clk_enable(clk); 232 + clk_prepare_enable(clk); 233 233 234 234 /* Power up fec phy */ 235 235 ret = gpio_request(MX28EVK_FEC_PHY_POWER, "fec-phy-power");
+1 -1
arch/arm/mach-mxs/system.c
··· 66 66 67 67 clk = clk_get_sys("rtc", NULL); 68 68 if (!IS_ERR(clk)) 69 - clk_enable(clk); 69 + clk_prepare_enable(clk); 70 70 71 71 return 0; 72 72 }
+1 -1
arch/arm/mach-mxs/timer.c
··· 245 245 246 246 void __init mxs_timer_init(struct clk *timer_clk, int irq) 247 247 { 248 - clk_enable(timer_clk); 248 + clk_prepare_enable(timer_clk); 249 249 250 250 /* 251 251 * Initialize timers to a known state
+3
drivers/clk/Kconfig
··· 3 3 bool 4 4 select HAVE_CLK 5 5 6 + config HAVE_CLK_PREPARE 7 + bool 8 + 6 9 config HAVE_MACH_CLKDEV 7 10 bool
+4 -4
drivers/dma/mxs-dma.c
··· 334 334 goto err_irq; 335 335 } 336 336 337 - ret = clk_enable(mxs_dma->clk); 337 + ret = clk_prepare_enable(mxs_dma->clk); 338 338 if (ret) 339 339 goto err_clk; 340 340 ··· 372 372 dma_free_coherent(mxs_dma->dma_device.dev, PAGE_SIZE, 373 373 mxs_chan->ccw, mxs_chan->ccw_phys); 374 374 375 - clk_disable(mxs_dma->clk); 375 + clk_disable_unprepare(mxs_dma->clk); 376 376 } 377 377 378 378 static struct dma_async_tx_descriptor *mxs_dma_prep_slave_sg( ··· 578 578 { 579 579 int ret; 580 580 581 - ret = clk_enable(mxs_dma->clk); 581 + ret = clk_prepare_enable(mxs_dma->clk); 582 582 if (ret) 583 583 goto err_out; 584 584 ··· 604 604 writel(MXS_DMA_CHANNELS_MASK << MXS_DMA_CHANNELS, 605 605 mxs_dma->base + HW_APBHX_CTRL1 + MXS_SET_ADDR); 606 606 607 - clk_disable(mxs_dma->clk); 607 + clk_disable_unprepare(mxs_dma->clk); 608 608 609 609 return 0; 610 610
+5 -5
drivers/mmc/host/mxs-mmc.c
··· 713 713 ret = PTR_ERR(host->clk); 714 714 goto out_iounmap; 715 715 } 716 - clk_enable(host->clk); 716 + clk_prepare_enable(host->clk); 717 717 718 718 mxs_mmc_reset(host); 719 719 ··· 772 772 if (host->dmach) 773 773 dma_release_channel(host->dmach); 774 774 out_clk_put: 775 - clk_disable(host->clk); 775 + clk_disable_unprepare(host->clk); 776 776 clk_put(host->clk); 777 777 out_iounmap: 778 778 iounmap(host->base); ··· 798 798 if (host->dmach) 799 799 dma_release_channel(host->dmach); 800 800 801 - clk_disable(host->clk); 801 + clk_disable_unprepare(host->clk); 802 802 clk_put(host->clk); 803 803 804 804 iounmap(host->base); ··· 819 819 820 820 ret = mmc_suspend_host(mmc); 821 821 822 - clk_disable(host->clk); 822 + clk_disable_unprepare(host->clk); 823 823 824 824 return ret; 825 825 } ··· 830 830 struct mxs_mmc_host *host = mmc_priv(mmc); 831 831 int ret = 0; 832 832 833 - clk_enable(host->clk); 833 + clk_prepare_enable(host->clk); 834 834 835 835 ret = mmc_resume_host(mmc); 836 836
+6 -6
drivers/mtd/nand/gpmi-nand/gpmi-lib.c
··· 126 126 struct resources *r = &this->resources; 127 127 int ret; 128 128 129 - ret = clk_enable(r->clock); 129 + ret = clk_prepare_enable(r->clock); 130 130 if (ret) 131 131 goto err_out; 132 132 ret = gpmi_reset_block(r->gpmi_regs, false); ··· 146 146 /* Select BCH ECC. */ 147 147 writel(BM_GPMI_CTRL1_BCH_MODE, r->gpmi_regs + HW_GPMI_CTRL1_SET); 148 148 149 - clk_disable(r->clock); 149 + clk_disable_unprepare(r->clock); 150 150 return 0; 151 151 err_out: 152 152 return ret; ··· 202 202 ecc_strength = bch_geo->ecc_strength >> 1; 203 203 page_size = bch_geo->page_size; 204 204 205 - ret = clk_enable(r->clock); 205 + ret = clk_prepare_enable(r->clock); 206 206 if (ret) 207 207 goto err_out; 208 208 ··· 229 229 writel(BM_BCH_CTRL_COMPLETE_IRQ_EN, 230 230 r->bch_regs + HW_BCH_CTRL_SET); 231 231 232 - clk_disable(r->clock); 232 + clk_disable_unprepare(r->clock); 233 233 return 0; 234 234 err_out: 235 235 return ret; ··· 704 704 int ret; 705 705 706 706 /* Enable the clock. */ 707 - ret = clk_enable(r->clock); 707 + ret = clk_prepare_enable(r->clock); 708 708 if (ret) { 709 709 pr_err("We failed in enable the clk\n"); 710 710 goto err_out; ··· 773 773 void gpmi_end(struct gpmi_nand_data *this) 774 774 { 775 775 struct resources *r = &this->resources; 776 - clk_disable(r->clock); 776 + clk_disable_unprepare(r->clock); 777 777 } 778 778 779 779 /* Clears a BCH interrupt. */
+5 -5
drivers/net/can/flexcan.c
··· 802 802 struct flexcan_priv *priv = netdev_priv(dev); 803 803 int err; 804 804 805 - clk_enable(priv->clk); 805 + clk_prepare_enable(priv->clk); 806 806 807 807 err = open_candev(dev); 808 808 if (err) ··· 824 824 out_close: 825 825 close_candev(dev); 826 826 out: 827 - clk_disable(priv->clk); 827 + clk_disable_unprepare(priv->clk); 828 828 829 829 return err; 830 830 } ··· 838 838 flexcan_chip_stop(dev); 839 839 840 840 free_irq(dev->irq, dev); 841 - clk_disable(priv->clk); 841 + clk_disable_unprepare(priv->clk); 842 842 843 843 close_candev(dev); 844 844 ··· 877 877 struct flexcan_regs __iomem *regs = priv->base; 878 878 u32 reg, err; 879 879 880 - clk_enable(priv->clk); 880 + clk_prepare_enable(priv->clk); 881 881 882 882 /* select "bus clock", chip must be disabled */ 883 883 flexcan_chip_disable(priv); ··· 911 911 out: 912 912 /* disable core and turn off clocks */ 913 913 flexcan_chip_disable(priv); 914 - clk_disable(priv->clk); 914 + clk_disable_unprepare(priv->clk); 915 915 916 916 return err; 917 917 }
+5 -5
drivers/net/ethernet/freescale/fec.c
··· 1610 1610 ret = PTR_ERR(fep->clk); 1611 1611 goto failed_clk; 1612 1612 } 1613 - clk_enable(fep->clk); 1613 + clk_prepare_enable(fep->clk); 1614 1614 1615 1615 ret = fec_enet_init(ndev); 1616 1616 if (ret) ··· 1633 1633 fec_enet_mii_remove(fep); 1634 1634 failed_mii_init: 1635 1635 failed_init: 1636 - clk_disable(fep->clk); 1636 + clk_disable_unprepare(fep->clk); 1637 1637 clk_put(fep->clk); 1638 1638 failed_clk: 1639 1639 for (i = 0; i < FEC_IRQ_NUM; i++) { ··· 1666 1666 if (irq > 0) 1667 1667 free_irq(irq, ndev); 1668 1668 } 1669 - clk_disable(fep->clk); 1669 + clk_disable_unprepare(fep->clk); 1670 1670 clk_put(fep->clk); 1671 1671 iounmap(fep->hwp); 1672 1672 free_netdev(ndev); ··· 1691 1691 fec_stop(ndev); 1692 1692 netif_device_detach(ndev); 1693 1693 } 1694 - clk_disable(fep->clk); 1694 + clk_disable_unprepare(fep->clk); 1695 1695 1696 1696 return 0; 1697 1697 } ··· 1702 1702 struct net_device *ndev = dev_get_drvdata(dev); 1703 1703 struct fec_enet_private *fep = netdev_priv(ndev); 1704 1704 1705 - clk_enable(fep->clk); 1705 + clk_prepare_enable(fep->clk); 1706 1706 if (netif_running(ndev)) { 1707 1707 fec_restart(ndev, fep->full_duplex); 1708 1708 netif_device_attach(ndev);
+4 -4
drivers/tty/serial/mxs-auart.c
··· 425 425 { 426 426 struct mxs_auart_port *s = to_auart_port(u); 427 427 428 - clk_enable(s->clk); 428 + clk_prepare_enable(s->clk); 429 429 430 430 writel(AUART_CTRL0_CLKGATE, u->membase + AUART_CTRL0_CLR); 431 431 ··· 454 454 writel(AUART_INTR_RXIEN | AUART_INTR_RTIEN | AUART_INTR_CTSMIEN, 455 455 u->membase + AUART_INTR_CLR); 456 456 457 - clk_disable(s->clk); 457 + clk_disable_unprepare(s->clk); 458 458 } 459 459 460 460 static unsigned int mxs_auart_tx_empty(struct uart_port *u) ··· 635 635 if (!s) 636 636 return -ENODEV; 637 637 638 - clk_enable(s->clk); 638 + clk_prepare_enable(s->clk); 639 639 640 640 if (options) 641 641 uart_parse_options(options, &baud, &parity, &bits, &flow); ··· 644 644 645 645 ret = uart_set_options(&s->port, co, baud, parity, bits, flow); 646 646 647 - clk_disable(s->clk); 647 + clk_disable_unprepare(s->clk); 648 648 649 649 return ret; 650 650 }
+4 -4
drivers/video/mxsfb.c
··· 328 328 329 329 dev_dbg(&host->pdev->dev, "%s\n", __func__); 330 330 331 - clk_enable(host->clk); 331 + clk_prepare_enable(host->clk); 332 332 clk_set_rate(host->clk, PICOS2KHZ(fb_info->var.pixclock) * 1000U); 333 333 334 334 /* if it was disabled, re-enable the mode again */ ··· 368 368 369 369 writel(VDCTRL4_SYNC_SIGNALS_ON, host->base + LCDC_VDCTRL4 + REG_CLR); 370 370 371 - clk_disable(host->clk); 371 + clk_disable_unprepare(host->clk); 372 372 373 373 host->enabled = 0; 374 374 } ··· 668 668 line_count = fb_info->fix.smem_len / fb_info->fix.line_length; 669 669 fb_info->fix.ypanstep = 1; 670 670 671 - clk_enable(host->clk); 671 + clk_prepare_enable(host->clk); 672 672 host->enabled = 1; 673 673 674 674 return 0; ··· 841 841 842 842 error_register: 843 843 if (host->enabled) 844 - clk_disable(host->clk); 844 + clk_disable_unprepare(host->clk); 845 845 fb_destroy_modelist(&fb_info->modelist); 846 846 error_init_fb: 847 847 kfree(fb_info->pseudo_palette);
+22
include/linux/clk.h
··· 107 107 } 108 108 #endif 109 109 110 + /* clk_prepare_enable helps cases using clk_enable in non-atomic context. */ 111 + static inline int clk_prepare_enable(struct clk *clk) 112 + { 113 + int ret; 114 + 115 + ret = clk_prepare(clk); 116 + if (ret) 117 + return ret; 118 + ret = clk_enable(clk); 119 + if (ret) 120 + clk_unprepare(clk); 121 + 122 + return ret; 123 + } 124 + 125 + /* clk_disable_unprepare helps cases using clk_disable in non-atomic context. */ 126 + static inline void clk_disable_unprepare(struct clk *clk) 127 + { 128 + clk_disable(clk); 129 + clk_unprepare(clk); 130 + } 131 + 110 132 /** 111 133 * clk_get_rate - obtain the current clock rate (in Hz) for a clock source. 112 134 * This is only valid once the clock source has been enabled.
+2 -2
sound/soc/mxs/mxs-saif.c
··· 210 210 return -EBUSY; 211 211 } 212 212 213 - clk_disable(saif->clk); 213 + clk_disable_unprepare(saif->clk); 214 214 215 215 /* disable MCLK output */ 216 216 __raw_writel(BM_SAIF_CTRL_CLKGATE, ··· 264 264 if (ret) 265 265 return ret; 266 266 267 - ret = clk_enable(saif->clk); 267 + ret = clk_prepare_enable(saif->clk); 268 268 if (ret) 269 269 return ret; 270 270