Path: blob/master/arch/arm/mach-pxa/clock-pxa3xx.c
10817 views
/*1* linux/arch/arm/mach-pxa/clock-pxa3xx.c2*3* This program is free software; you can redistribute it and/or modify4* it under the terms of the GNU General Public License version 2 as5* published by the Free Software Foundation.6*/78#include <linux/module.h>9#include <linux/kernel.h>10#include <linux/init.h>11#include <linux/io.h>12#include <linux/syscore_ops.h>1314#include <mach/smemc.h>15#include <mach/pxa3xx-regs.h>1617#include "clock.h"1819/* Crystal clock: 13MHz */20#define BASE_CLK 130000002122/* Ring Oscillator Clock: 60MHz */23#define RO_CLK 600000002425#define ACCR_D0CS (1 << 26)26#define ACCR_PCCE (1 << 11)2728/* crystal frequency to HSIO bus frequency multiplier (HSS) */29static unsigned char hss_mult[4] = { 8, 12, 16, 24 };3031/*32* Get the clock frequency as reflected by CCSR and the turbo flag.33* We assume these values have been applied via a fcs.34* If info is not 0 we also display the current settings.35*/36unsigned int pxa3xx_get_clk_frequency_khz(int info)37{38unsigned long acsr, xclkcfg;39unsigned int t, xl, xn, hss, ro, XL, XN, CLK, HSS;4041/* Read XCLKCFG register turbo bit */42__asm__ __volatile__("mrc\tp14, 0, %0, c6, c0, 0" : "=r"(xclkcfg));43t = xclkcfg & 0x1;4445acsr = ACSR;4647xl = acsr & 0x1f;48xn = (acsr >> 8) & 0x7;49hss = (acsr >> 14) & 0x3;5051XL = xl * BASE_CLK;52XN = xn * XL;5354ro = acsr & ACCR_D0CS;5556CLK = (ro) ? RO_CLK : ((t) ? XN : XL);57HSS = (ro) ? RO_CLK : hss_mult[hss] * BASE_CLK;5859if (info) {60pr_info("RO Mode clock: %d.%02dMHz (%sactive)\n",61RO_CLK / 1000000, (RO_CLK % 1000000) / 10000,62(ro) ? "" : "in");63pr_info("Run Mode clock: %d.%02dMHz (*%d)\n",64XL / 1000000, (XL % 1000000) / 10000, xl);65pr_info("Turbo Mode clock: %d.%02dMHz (*%d, %sactive)\n",66XN / 1000000, (XN % 1000000) / 10000, xn,67(t) ? "" : "in");68pr_info("HSIO bus clock: %d.%02dMHz\n",69HSS / 1000000, (HSS % 1000000) / 10000);70}7172return CLK / 1000;73}7475/*76* Return the current AC97 clock frequency.77*/78static unsigned long clk_pxa3xx_ac97_getrate(struct clk *clk)79{80unsigned long rate = 312000000;81unsigned long ac97_div;8283ac97_div = AC97_DIV;8485/* This may loose precision for some rates but won't for the86* standard 24.576MHz.87*/88rate /= (ac97_div >> 12) & 0x7fff;89rate *= (ac97_div & 0xfff);9091return rate;92}9394/*95* Return the current HSIO bus clock frequency96*/97static unsigned long clk_pxa3xx_hsio_getrate(struct clk *clk)98{99unsigned long acsr;100unsigned int hss, hsio_clk;101102acsr = ACSR;103104hss = (acsr >> 14) & 0x3;105hsio_clk = (acsr & ACCR_D0CS) ? RO_CLK : hss_mult[hss] * BASE_CLK;106107return hsio_clk;108}109110/* crystal frequency to static memory controller multiplier (SMCFS) */111static unsigned int smcfs_mult[8] = { 6, 0, 8, 0, 0, 16, };112static unsigned int df_clkdiv[4] = { 1, 2, 4, 1 };113114static unsigned long clk_pxa3xx_smemc_getrate(struct clk *clk)115{116unsigned long acsr = ACSR;117unsigned long memclkcfg = __raw_readl(MEMCLKCFG);118119return BASE_CLK * smcfs_mult[(acsr >> 23) & 0x7] /120df_clkdiv[(memclkcfg >> 16) & 0x3];121}122123void clk_pxa3xx_cken_enable(struct clk *clk)124{125unsigned long mask = 1ul << (clk->cken & 0x1f);126127if (clk->cken < 32)128CKENA |= mask;129else130CKENB |= mask;131}132133void clk_pxa3xx_cken_disable(struct clk *clk)134{135unsigned long mask = 1ul << (clk->cken & 0x1f);136137if (clk->cken < 32)138CKENA &= ~mask;139else140CKENB &= ~mask;141}142143const struct clkops clk_pxa3xx_cken_ops = {144.enable = clk_pxa3xx_cken_enable,145.disable = clk_pxa3xx_cken_disable,146};147148const struct clkops clk_pxa3xx_hsio_ops = {149.enable = clk_pxa3xx_cken_enable,150.disable = clk_pxa3xx_cken_disable,151.getrate = clk_pxa3xx_hsio_getrate,152};153154const struct clkops clk_pxa3xx_ac97_ops = {155.enable = clk_pxa3xx_cken_enable,156.disable = clk_pxa3xx_cken_disable,157.getrate = clk_pxa3xx_ac97_getrate,158};159160const struct clkops clk_pxa3xx_smemc_ops = {161.enable = clk_pxa3xx_cken_enable,162.disable = clk_pxa3xx_cken_disable,163.getrate = clk_pxa3xx_smemc_getrate,164};165166static void clk_pout_enable(struct clk *clk)167{168OSCC |= OSCC_PEN;169}170171static void clk_pout_disable(struct clk *clk)172{173OSCC &= ~OSCC_PEN;174}175176const struct clkops clk_pxa3xx_pout_ops = {177.enable = clk_pout_enable,178.disable = clk_pout_disable,179};180181#ifdef CONFIG_PM182static uint32_t cken[2];183static uint32_t accr;184185static int pxa3xx_clock_suspend(void)186{187cken[0] = CKENA;188cken[1] = CKENB;189accr = ACCR;190return 0;191}192193static void pxa3xx_clock_resume(void)194{195ACCR = accr;196CKENA = cken[0];197CKENB = cken[1];198}199#else200#define pxa3xx_clock_suspend NULL201#define pxa3xx_clock_resume NULL202#endif203204struct syscore_ops pxa3xx_clock_syscore_ops = {205.suspend = pxa3xx_clock_suspend,206.resume = pxa3xx_clock_resume,207};208209210