Path: blob/master/arch/sh/kernel/cpu/sh4a/clock-sh7722.c
17533 views
/*1* arch/sh/kernel/cpu/sh4a/clock-sh7722.c2*3* SH7722 clock framework support4*5* Copyright (C) 2009 Magnus Damm6*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License as published by9* the Free Software Foundation; either version 2 of the License10*11* This program is distributed in the hope that it will be useful,12* but WITHOUT ANY WARRANTY; without even the implied warranty of13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14* GNU General Public License for more details.15*16* You should have received a copy of the GNU General Public License17* along with this program; if not, write to the Free Software18* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA19*/20#include <linux/init.h>21#include <linux/kernel.h>22#include <linux/io.h>23#include <linux/clkdev.h>24#include <asm/clock.h>25#include <asm/hwblk.h>26#include <cpu/sh7722.h>2728/* SH7722 registers */29#define FRQCR 0xa415000030#define VCLKCR 0xa415000431#define SCLKACR 0xa415000832#define SCLKBCR 0xa415000c33#define IRDACLKCR 0xa415001834#define PLLCR 0xa415002435#define DLLFRQ 0xa41500503637/* Fixed 32 KHz root clock for RTC and Power Management purposes */38static struct clk r_clk = {39.rate = 32768,40};4142/*43* Default rate for the root input clock, reset this with clk_set_rate()44* from the platform code.45*/46struct clk extal_clk = {47.rate = 33333333,48};4950/* The dll block multiplies the 32khz r_clk, may be used instead of extal */51static unsigned long dll_recalc(struct clk *clk)52{53unsigned long mult;5455if (__raw_readl(PLLCR) & 0x1000)56mult = __raw_readl(DLLFRQ);57else58mult = 0;5960return clk->parent->rate * mult;61}6263static struct clk_ops dll_clk_ops = {64.recalc = dll_recalc,65};6667static struct clk dll_clk = {68.ops = &dll_clk_ops,69.parent = &r_clk,70.flags = CLK_ENABLE_ON_INIT,71};7273static unsigned long pll_recalc(struct clk *clk)74{75unsigned long mult = 1;76unsigned long div = 1;7778if (__raw_readl(PLLCR) & 0x4000)79mult = (((__raw_readl(FRQCR) >> 24) & 0x1f) + 1);80else81div = 2;8283return (clk->parent->rate * mult) / div;84}8586static struct clk_ops pll_clk_ops = {87.recalc = pll_recalc,88};8990static struct clk pll_clk = {91.ops = &pll_clk_ops,92.flags = CLK_ENABLE_ON_INIT,93};9495struct clk *main_clks[] = {96&r_clk,97&extal_clk,98&dll_clk,99&pll_clk,100};101102static int multipliers[] = { 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 };103static int divisors[] = { 1, 3, 2, 5, 3, 4, 5, 6, 8, 10, 12, 16, 20 };104105static struct clk_div_mult_table div4_div_mult_table = {106.divisors = divisors,107.nr_divisors = ARRAY_SIZE(divisors),108.multipliers = multipliers,109.nr_multipliers = ARRAY_SIZE(multipliers),110};111112static struct clk_div4_table div4_table = {113.div_mult_table = &div4_div_mult_table,114};115116#define DIV4(_reg, _bit, _mask, _flags) \117SH_CLK_DIV4(&pll_clk, _reg, _bit, _mask, _flags)118119enum { DIV4_I, DIV4_U, DIV4_SH, DIV4_B, DIV4_B3, DIV4_P, DIV4_NR };120121struct clk div4_clks[DIV4_NR] = {122[DIV4_I] = DIV4(FRQCR, 20, 0x1fef, CLK_ENABLE_ON_INIT),123[DIV4_U] = DIV4(FRQCR, 16, 0x1fff, CLK_ENABLE_ON_INIT),124[DIV4_SH] = DIV4(FRQCR, 12, 0x1fff, CLK_ENABLE_ON_INIT),125[DIV4_B] = DIV4(FRQCR, 8, 0x1fff, CLK_ENABLE_ON_INIT),126[DIV4_B3] = DIV4(FRQCR, 4, 0x1fff, CLK_ENABLE_ON_INIT),127[DIV4_P] = DIV4(FRQCR, 0, 0x1fff, 0),128};129130enum { DIV4_IRDA, DIV4_ENABLE_NR };131132struct clk div4_enable_clks[DIV4_ENABLE_NR] = {133[DIV4_IRDA] = DIV4(IRDACLKCR, 0, 0x1fff, 0),134};135136enum { DIV4_SIUA, DIV4_SIUB, DIV4_REPARENT_NR };137138struct clk div4_reparent_clks[DIV4_REPARENT_NR] = {139[DIV4_SIUA] = DIV4(SCLKACR, 0, 0x1fff, 0),140[DIV4_SIUB] = DIV4(SCLKBCR, 0, 0x1fff, 0),141};142143enum { DIV6_V, DIV6_NR };144145struct clk div6_clks[DIV6_NR] = {146[DIV6_V] = SH_CLK_DIV6(&pll_clk, VCLKCR, 0),147};148149static struct clk mstp_clks[HWBLK_NR] = {150SH_HWBLK_CLK(HWBLK_URAM, &div4_clks[DIV4_U], CLK_ENABLE_ON_INIT),151SH_HWBLK_CLK(HWBLK_XYMEM, &div4_clks[DIV4_B], CLK_ENABLE_ON_INIT),152SH_HWBLK_CLK(HWBLK_TMU, &div4_clks[DIV4_P], 0),153SH_HWBLK_CLK(HWBLK_CMT, &r_clk, 0),154SH_HWBLK_CLK(HWBLK_RWDT, &r_clk, 0),155SH_HWBLK_CLK(HWBLK_FLCTL, &div4_clks[DIV4_P], 0),156SH_HWBLK_CLK(HWBLK_SCIF0, &div4_clks[DIV4_P], 0),157SH_HWBLK_CLK(HWBLK_SCIF1, &div4_clks[DIV4_P], 0),158SH_HWBLK_CLK(HWBLK_SCIF2, &div4_clks[DIV4_P], 0),159160SH_HWBLK_CLK(HWBLK_IIC, &div4_clks[DIV4_P], 0),161SH_HWBLK_CLK(HWBLK_RTC, &r_clk, 0),162163SH_HWBLK_CLK(HWBLK_SDHI, &div4_clks[DIV4_P], 0),164SH_HWBLK_CLK(HWBLK_KEYSC, &r_clk, 0),165SH_HWBLK_CLK(HWBLK_USBF, &div4_clks[DIV4_P], 0),166SH_HWBLK_CLK(HWBLK_2DG, &div4_clks[DIV4_B], 0),167SH_HWBLK_CLK(HWBLK_SIU, &div4_clks[DIV4_B], 0),168SH_HWBLK_CLK(HWBLK_VOU, &div4_clks[DIV4_B], 0),169SH_HWBLK_CLK(HWBLK_JPU, &div4_clks[DIV4_B], 0),170SH_HWBLK_CLK(HWBLK_BEU, &div4_clks[DIV4_B], 0),171SH_HWBLK_CLK(HWBLK_CEU, &div4_clks[DIV4_B], 0),172SH_HWBLK_CLK(HWBLK_VEU, &div4_clks[DIV4_B], 0),173SH_HWBLK_CLK(HWBLK_VPU, &div4_clks[DIV4_B], 0),174SH_HWBLK_CLK(HWBLK_LCDC, &div4_clks[DIV4_P], 0),175};176177#define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }178179static struct clk_lookup lookups[] = {180/* main clocks */181CLKDEV_CON_ID("rclk", &r_clk),182CLKDEV_CON_ID("extal", &extal_clk),183CLKDEV_CON_ID("dll_clk", &dll_clk),184CLKDEV_CON_ID("pll_clk", &pll_clk),185186/* DIV4 clocks */187CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),188CLKDEV_CON_ID("umem_clk", &div4_clks[DIV4_U]),189CLKDEV_CON_ID("shyway_clk", &div4_clks[DIV4_SH]),190CLKDEV_CON_ID("bus_clk", &div4_clks[DIV4_B]),191CLKDEV_CON_ID("b3_clk", &div4_clks[DIV4_B3]),192CLKDEV_CON_ID("peripheral_clk", &div4_clks[DIV4_P]),193CLKDEV_CON_ID("irda_clk", &div4_enable_clks[DIV4_IRDA]),194CLKDEV_CON_ID("siua_clk", &div4_reparent_clks[DIV4_SIUA]),195CLKDEV_CON_ID("siub_clk", &div4_reparent_clks[DIV4_SIUB]),196197/* DIV6 clocks */198CLKDEV_CON_ID("video_clk", &div6_clks[DIV6_V]),199200/* MSTP clocks */201CLKDEV_CON_ID("uram0", &mstp_clks[HWBLK_URAM]),202CLKDEV_CON_ID("xymem0", &mstp_clks[HWBLK_XYMEM]),203{204/* TMU0 */205.dev_id = "sh_tmu.0",206.con_id = "tmu_fck",207.clk = &mstp_clks[HWBLK_TMU],208}, {209/* TMU1 */210.dev_id = "sh_tmu.1",211.con_id = "tmu_fck",212.clk = &mstp_clks[HWBLK_TMU],213}, {214/* TMU2 */215.dev_id = "sh_tmu.2",216.con_id = "tmu_fck",217.clk = &mstp_clks[HWBLK_TMU],218},219CLKDEV_CON_ID("cmt_fck", &mstp_clks[HWBLK_CMT]),220CLKDEV_CON_ID("rwdt0", &mstp_clks[HWBLK_RWDT]),221CLKDEV_CON_ID("flctl0", &mstp_clks[HWBLK_FLCTL]),222{223/* SCIF0 */224.dev_id = "sh-sci.0",225.con_id = "sci_fck",226.clk = &mstp_clks[HWBLK_SCIF0],227}, {228/* SCIF1 */229.dev_id = "sh-sci.1",230.con_id = "sci_fck",231.clk = &mstp_clks[HWBLK_SCIF1],232}, {233/* SCIF2 */234.dev_id = "sh-sci.2",235.con_id = "sci_fck",236.clk = &mstp_clks[HWBLK_SCIF2],237},238CLKDEV_CON_ID("i2c0", &mstp_clks[HWBLK_IIC]),239CLKDEV_CON_ID("rtc0", &mstp_clks[HWBLK_RTC]),240CLKDEV_CON_ID("sdhi0", &mstp_clks[HWBLK_SDHI]),241CLKDEV_CON_ID("keysc0", &mstp_clks[HWBLK_KEYSC]),242CLKDEV_CON_ID("usbf0", &mstp_clks[HWBLK_USBF]),243CLKDEV_CON_ID("2dg0", &mstp_clks[HWBLK_2DG]),244CLKDEV_CON_ID("siu0", &mstp_clks[HWBLK_SIU]),245CLKDEV_CON_ID("vou0", &mstp_clks[HWBLK_VOU]),246CLKDEV_CON_ID("jpu0", &mstp_clks[HWBLK_JPU]),247CLKDEV_CON_ID("beu0", &mstp_clks[HWBLK_BEU]),248CLKDEV_CON_ID("ceu0", &mstp_clks[HWBLK_CEU]),249CLKDEV_CON_ID("veu0", &mstp_clks[HWBLK_VEU]),250CLKDEV_CON_ID("vpu0", &mstp_clks[HWBLK_VPU]),251CLKDEV_CON_ID("lcdc0", &mstp_clks[HWBLK_LCDC]),252};253254int __init arch_clk_init(void)255{256int k, ret = 0;257258/* autodetect extal or dll configuration */259if (__raw_readl(PLLCR) & 0x1000)260pll_clk.parent = &dll_clk;261else262pll_clk.parent = &extal_clk;263264for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)265ret = clk_register(main_clks[k]);266267clkdev_add_table(lookups, ARRAY_SIZE(lookups));268269if (!ret)270ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);271272if (!ret)273ret = sh_clk_div4_enable_register(div4_enable_clks,274DIV4_ENABLE_NR, &div4_table);275276if (!ret)277ret = sh_clk_div4_reparent_register(div4_reparent_clks,278DIV4_REPARENT_NR, &div4_table);279280if (!ret)281ret = sh_clk_div6_register(div6_clks, DIV6_NR);282283if (!ret)284ret = sh_hwblk_clk_register(mstp_clks, HWBLK_NR);285286return ret;287}288289290