From 4ae10f3042c646f83cb1f30138291f5d9c4a838d Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E9=BB=84=E6=B6=9B?= Date: Wed, 22 Dec 2010 11:37:19 +0800 Subject: [PATCH] rk29: clock close unused, fix fb/backlight/spi --- arch/arm/mach-rk29/clock.c | 93 +++++++++++++++++++----- drivers/spi/rk29_spim.c | 7 +- drivers/video/backlight/rk29_backlight.c | 2 +- drivers/video/rk29_fb.c | 62 ++++++++-------- 4 files changed, 109 insertions(+), 55 deletions(-) diff --git a/arch/arm/mach-rk29/clock.c b/arch/arm/mach-rk29/clock.c index b13d61c35107..5a3eaa9fd21c 100755 --- a/arch/arm/mach-rk29/clock.c +++ b/arch/arm/mach-rk29/clock.c @@ -84,7 +84,6 @@ /* bit 0 is free */ #define RATE_FIXED (1 << 1) /* Fixed clock rate */ #define CONFIG_PARTICIPANT (1 << 10) /* Fundamental clock */ -#define ENABLE_ON_INIT (1 << 11) /* Enable upon framework init */ #define cru_readl(offset) readl(RK29_CRU_BASE + offset) #define cru_writel(v, offset) writel(v, RK29_CRU_BASE + offset) @@ -1788,11 +1787,11 @@ static struct clk_lookup clks[] = { CLK(NULL, "pclk_periph", &pclk_periph), CLK1(vip), - CLK("rk29_otgphy.0", "otgphy", &clk_otgphy0), - CLK("rk29_otgphy.1", "otgphy", &clk_otgphy1), - CLK(NULL, "uhost", &clk_uhost), - CLK(NULL, "mac_ref_div", &clk_mac_ref_div), - CLK(NULL, "mac_ref", &clk_mac_ref), + CLK1(otgphy0), + CLK1(otgphy1), + CLK1(uhost), + CLK1(mac_ref_div), + CLK1(mac_ref), CLK("rk29_i2s.0", "i2s_div", &clk_i2s0_div), CLK("rk29_i2s.0", "i2s_frac_div", &clk_i2s0_frac_div), @@ -1805,8 +1804,8 @@ static struct clk_lookup clks[] = { CLK(NULL, "spdif", &clk_spdif), CLK1(spi_src), - CLK("rk29xx_spim.0", "spi0", &clk_spi0), - CLK("rk29xx_spim.1", "spi1", &clk_spi1), + CLK("rk29xx_spim.0", "spi", &clk_spi0), + CLK("rk29xx_spim.1", "spi", &clk_spi1), CLK1(saradc), CLK1(timer0), @@ -2249,16 +2248,6 @@ static int clk_register(struct clk *clk) return 0; } -static void clk_enable_init_clocks(void) -{ - struct clk *clkp; - - list_for_each_entry(clkp, &clocks, node) { - if (clkp->flags & ENABLE_ON_INIT) - clk_enable(clkp); - } -} - static void rk29_clock_common_init(void) { /* periph pll */ @@ -2289,6 +2278,69 @@ static void rk29_clock_common_init(void) clk_set_rate_nolock(&arm_pll_clk, 624 * MHZ); } +static void clk_enable_init_clocks(void) +{ + clk_enable_nolock(&clk_cpu_display_ahb); + clk_enable_nolock(&clk_cpu_vcodec_ahb); + clk_enable_nolock(&clk_ddr_gpu_axi); + clk_enable_nolock(&clk_ddr_vdpu_axi); + clk_enable_nolock(&clk_ddr_vepu_axi); + clk_enable_nolock(&clk_display_matrix_ahb); + clk_enable_nolock(&clk_display_matrix_axi); + clk_enable_nolock(&clk_ipp_ahb); + clk_enable_nolock(&clk_ipp_axi); + clk_enable_nolock(&clk_ddr_lcdc_axi); + clk_enable_nolock(&clk_uhost_ahb); + clk_enable_nolock(&clk_usbotg1); + clk_enable_nolock(&clk_usbotg0); + clk_enable_nolock(&clk_nandc); + clk_enable_nolock(&clk_smc); + clk_enable_nolock(&clk_smc_axi); + clk_enable_nolock(&clk_periph_cpu); + clk_enable_nolock(&clk_ddr_periph); + clk_enable_nolock(&clk_usb); + clk_enable_nolock(&clk_grf); + clk_enable_nolock(&clk_pmu); + clk_enable_nolock(&clk_ddr_cpu); + clk_enable_nolock(&clk_ddr_reg); + clk_enable_nolock(&clk_ddr_phy); + clk_enable_nolock(&clk_gic); + clk_enable_nolock(&clk_dma2); + clk_enable_nolock(&clk_dma1); + clk_enable_nolock(&clk_dma0); + clk_enable_nolock(&clk_spdif); + clk_enable_nolock(&clk_i2s0); + /* backlight */ + clk_enable_nolock(&clk_pwm); + /* vpu */ + clk_enable_nolock(&aclk_vdpu); + clk_enable_nolock(&hclk_vdpu); + clk_enable_nolock(&clk_ddr_vdpu_axi); + clk_enable_nolock(&aclk_vepu); + clk_enable_nolock(&hclk_vepu); + clk_enable_nolock(&clk_ddr_vepu_axi); + clk_enable_nolock(&clk_cpu_vcodec_ahb); +} + +static int __init clk_disable_unused(void) +{ + struct clk *ck; + + list_for_each_entry(ck, &clocks, node) { + if (ck->usecount > 0 || ck->mode == NULL) + continue; + +printk("disable %s\n", ck->name); + LOCK(); + clk_enable_nolock(ck); + clk_disable_nolock(ck); + UNLOCK(); + } + mutex_unlock(&clocks_mutex); + + return 0; +} + void __init rk29_clock_init(void) { struct clk_lookup *lk; @@ -2314,6 +2366,11 @@ void __init rk29_clock_init(void) * enable other clocks as necessary */ clk_enable_init_clocks(); + + /* + * Disable any unused clocks left on by the bootloader + */ + clk_disable_unused(); } #ifdef CONFIG_PROC_FS diff --git a/drivers/spi/rk29_spim.c b/drivers/spi/rk29_spim.c index 1227e6e836ff..c706987e12cc 100755 --- a/drivers/spi/rk29_spim.c +++ b/drivers/spi/rk29_spim.c @@ -1800,7 +1800,6 @@ static int __init rk29xx_spim_probe(struct platform_device *pdev) int irq; int ret; struct rk29xx_spi_platform_data *pdata = pdev->dev.platform_data; - char szBuf[8]; if (pdata && pdata->io_init) { ret = pdata->io_init(pdata->chipselect_gpios, pdata->num_chipselect); @@ -1836,12 +1835,10 @@ static int __init rk29xx_spim_probe(struct platform_device *pdev) platform_set_drvdata(pdev, master); dws = spi_master_get_devdata(master); - memset(szBuf, 0, sizeof(szBuf)); - sprintf(szBuf, "%s%d", "spi", pdev->id); - dws->clock_spim = clk_get(&pdev->dev, szBuf); + dws->clock_spim = clk_get(&pdev->dev, "spi"); clk_enable(dws->clock_spim); if (IS_ERR(dws->clock_spim)) { - dev_err(&pdev->dev, "clk_get for %s fail(%p)\n", szBuf, dws->clock_spim); + dev_err(&pdev->dev, "clk_get for spi fail(%p)\n", dws->clock_spim); return PTR_ERR(dws->clock_spim); } diff --git a/drivers/video/backlight/rk29_backlight.c b/drivers/video/backlight/rk29_backlight.c index a54f7d925abb..12843c7b29f3 100644 --- a/drivers/video/backlight/rk29_backlight.c +++ b/drivers/video/backlight/rk29_backlight.c @@ -250,7 +250,7 @@ static int rk29_backlight_probe(struct platform_device *pdev) if (!pwm_clk) pwm_clk = clk_get(NULL, "pwm"); - if (!pwm_clk || IS_ERR(pwm_clk)) { + if (IS_ERR(pwm_clk)) { printk(KERN_ERR "failed to get pwm clock source\n"); return -ENODEV; } diff --git a/drivers/video/rk29_fb.c b/drivers/video/rk29_fb.c index 0b8c089ae478..5979c7da5f31 100755 --- a/drivers/video/rk29_fb.c +++ b/drivers/video/rk29_fb.c @@ -405,6 +405,14 @@ int init_lcdc(struct fb_info *info) fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__); + inf->clk = clk_get(NULL, "hclk_lcdc"); + if (IS_ERR(inf->clk)) + { + printk(KERN_ERR "failed to get lcdc_hclk source\n"); + return inf->clk; + } + clk_enable(inf->clk); + // set AHB access rule and disable all windows LcdWrReg(inf, SYS_CONFIG, 0x20000000); LcdWrReg(inf, SWAP_CTRL, 0); @@ -544,51 +552,44 @@ void load_screen(struct fb_info *info, bool initscreen) // let above to take effect LcdWrReg(inf, REG_CFG_DONE, 0x01); - inf->clk = clk_get(&g_pdev->dev, "hclk_lcdc"); - if (!inf->clk || IS_ERR(inf->clk)) + inf->dclk = clk_get(NULL, "dclk_lcdc"); + if (IS_ERR(inf->dclk)) { - printk(KERN_ERR "failed to get lcdc_hclk source\n"); + printk(KERN_ERR "failed to get lcd dclock source\n"); return ; } - - inf->dclk = clk_get(&g_pdev->dev, "dclk_lcdc"); - if (!inf->dclk || IS_ERR(inf->dclk)) + inf->dclk_divider= clk_get(NULL, "dclk_lcdc_div"); + if (IS_ERR(inf->dclk_divider)) { - printk(KERN_ERR "failed to get lcd dclock source\n"); + printk(KERN_ERR "failed to get lcd clock lcdc_divider source \n"); return ; - } - inf->dclk_divider= clk_get(&g_pdev->dev, "dclk_lcdc_div"); - if (!inf->dclk_divider || IS_ERR(inf->dclk_divider)) - { - printk(KERN_ERR "failed to get lcd clock lcdc_divider source \n"); - return ; - } + } if(inf->cur_screen == &inf->panel1_info) { - inf->dclk_parent = clk_get(&g_pdev->dev, "periph_pll"); + inf->dclk_parent = clk_get(NULL, "periph_pll"); } else { - inf->dclk_parent = clk_get(&g_pdev->dev, "codec_pll"); + inf->dclk_parent = clk_get(NULL, "codec_pll"); clk_set_rate(inf->dclk_parent, 297000000); } - if (!inf->dclk_parent || IS_ERR(inf->dclk_parent)) + if (IS_ERR(inf->dclk_parent)) { - printk(KERN_ERR "failed to get lcd dclock parent source\n"); - return ; - } + printk(KERN_ERR "failed to get lcd dclock parent source\n"); + return; + } - inf->aclk = clk_get(&g_pdev->dev, "aclk_lcdc"); - if (!inf->aclk || IS_ERR(inf->aclk)) + inf->aclk = clk_get(NULL, "aclk_lcdc"); + if (IS_ERR(inf->aclk)) { - printk(KERN_ERR "failed to get lcd clock clk_share_mem source \n"); - return ; - } - inf->aclk_parent = clk_get(&g_pdev->dev, "periph_pll"); - if (!inf->dclk_parent || IS_ERR(inf->dclk_parent)) + printk(KERN_ERR "failed to get lcd clock clk_share_mem source \n"); + return; + } + inf->aclk_parent = clk_get(NULL, "periph_pll"); + if (IS_ERR(inf->dclk_parent)) { - printk(KERN_ERR "failed to get lcd dclock parent source\n"); - return ; - } + printk(KERN_ERR "failed to get lcd dclock parent source\n"); + return ; + } // set lcdc clk if(SCREEN_MCU==screen->type) screen->pixclock = 150000000; //mcu fix to 150 MHz @@ -621,7 +622,6 @@ void load_screen(struct fb_info *info, bool initscreen) } clk_enable(inf->dclk); - clk_enable(inf->clk); clk_enable(inf->aclk); // init screen panel -- 2.34.1