Path: blob/master/arch/sh/kernel/cpu/sh4a/clock-sh7366.c
17495 views
/*1* arch/sh/kernel/cpu/sh4a/clock-sh7366.c2*3* SH7366 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>2526/* SH7366 registers */27#define FRQCR 0xa415000028#define VCLKCR 0xa415000429#define SCLKACR 0xa415000830#define SCLKBCR 0xa415000c31#define PLLCR 0xa415002432#define MSTPCR0 0xa415003033#define MSTPCR1 0xa415003434#define MSTPCR2 0xa415003835#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};115116enum { DIV4_I, DIV4_U, DIV4_SH, DIV4_B, DIV4_B3, DIV4_P,117DIV4_SIUA, DIV4_SIUB, DIV4_NR };118119#define DIV4(_reg, _bit, _mask, _flags) \120SH_CLK_DIV4(&pll_clk, _reg, _bit, _mask, _flags)121122struct clk div4_clks[DIV4_NR] = {123[DIV4_I] = DIV4(FRQCR, 20, 0x1fef, CLK_ENABLE_ON_INIT),124[DIV4_U] = DIV4(FRQCR, 16, 0x1fff, CLK_ENABLE_ON_INIT),125[DIV4_SH] = DIV4(FRQCR, 12, 0x1fff, CLK_ENABLE_ON_INIT),126[DIV4_B] = DIV4(FRQCR, 8, 0x1fff, CLK_ENABLE_ON_INIT),127[DIV4_B3] = DIV4(FRQCR, 4, 0x1fff, CLK_ENABLE_ON_INIT),128[DIV4_P] = DIV4(FRQCR, 0, 0x1fff, 0),129[DIV4_SIUA] = DIV4(SCLKACR, 0, 0x1fff, 0),130[DIV4_SIUB] = DIV4(SCLKBCR, 0, 0x1fff, 0),131};132133enum { DIV6_V, DIV6_NR };134135struct clk div6_clks[DIV6_NR] = {136[DIV6_V] = SH_CLK_DIV6(&pll_clk, VCLKCR, 0),137};138139#define MSTP(_parent, _reg, _bit, _flags) \140SH_CLK_MSTP32(_parent, _reg, _bit, _flags)141142enum { MSTP031, MSTP030, MSTP029, MSTP028, MSTP026,143MSTP023, MSTP022, MSTP021, MSTP020, MSTP019, MSTP018, MSTP017, MSTP016,144MSTP015, MSTP014, MSTP013, MSTP012, MSTP011, MSTP010,145MSTP007, MSTP006, MSTP005, MSTP002, MSTP001,146MSTP109, MSTP100,147MSTP227, MSTP226, MSTP224, MSTP223, MSTP222, MSTP218, MSTP217,148MSTP211, MSTP207, MSTP205, MSTP204, MSTP203, MSTP202, MSTP201, MSTP200,149MSTP_NR };150151static struct clk mstp_clks[MSTP_NR] = {152/* See page 52 of Datasheet V0.40: Overview -> Block Diagram */153[MSTP031] = MSTP(&div4_clks[DIV4_I], MSTPCR0, 31, CLK_ENABLE_ON_INIT),154[MSTP030] = MSTP(&div4_clks[DIV4_I], MSTPCR0, 30, CLK_ENABLE_ON_INIT),155[MSTP029] = MSTP(&div4_clks[DIV4_I], MSTPCR0, 29, CLK_ENABLE_ON_INIT),156[MSTP028] = MSTP(&div4_clks[DIV4_SH], MSTPCR0, 28, CLK_ENABLE_ON_INIT),157[MSTP026] = MSTP(&div4_clks[DIV4_B], MSTPCR0, 26, CLK_ENABLE_ON_INIT),158[MSTP023] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 23, 0),159[MSTP022] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 22, 0),160[MSTP021] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 21, 0),161[MSTP020] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 20, 0),162[MSTP019] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 19, 0),163[MSTP017] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 17, 0),164[MSTP015] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 15, 0),165[MSTP014] = MSTP(&r_clk, MSTPCR0, 14, 0),166[MSTP013] = MSTP(&r_clk, MSTPCR0, 13, 0),167[MSTP011] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 11, 0),168[MSTP010] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 10, 0),169[MSTP007] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 7, 0),170[MSTP006] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 6, 0),171[MSTP005] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 5, 0),172[MSTP002] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 2, 0),173[MSTP001] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 1, 0),174175[MSTP109] = MSTP(&div4_clks[DIV4_P], MSTPCR1, 9, 0),176177[MSTP227] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 27, 0),178[MSTP226] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 26, 0),179[MSTP224] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 24, 0),180[MSTP223] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 23, 0),181[MSTP222] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 22, 0),182[MSTP218] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 18, 0),183[MSTP217] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 17, 0),184[MSTP211] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 11, 0),185[MSTP207] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 7, CLK_ENABLE_ON_INIT),186[MSTP205] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 5, 0),187[MSTP204] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 4, 0),188[MSTP203] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 3, 0),189[MSTP202] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 2, CLK_ENABLE_ON_INIT),190[MSTP201] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 1, CLK_ENABLE_ON_INIT),191[MSTP200] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 0, 0),192};193194#define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }195196static struct clk_lookup lookups[] = {197/* main clocks */198CLKDEV_CON_ID("rclk", &r_clk),199CLKDEV_CON_ID("extal", &extal_clk),200CLKDEV_CON_ID("dll_clk", &dll_clk),201CLKDEV_CON_ID("pll_clk", &pll_clk),202203/* DIV4 clocks */204CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),205CLKDEV_CON_ID("umem_clk", &div4_clks[DIV4_U]),206CLKDEV_CON_ID("shyway_clk", &div4_clks[DIV4_SH]),207CLKDEV_CON_ID("bus_clk", &div4_clks[DIV4_B]),208CLKDEV_CON_ID("b3_clk", &div4_clks[DIV4_B3]),209CLKDEV_CON_ID("peripheral_clk", &div4_clks[DIV4_P]),210CLKDEV_CON_ID("siua_clk", &div4_clks[DIV4_SIUA]),211CLKDEV_CON_ID("siub_clk", &div4_clks[DIV4_SIUB]),212213/* DIV6 clocks */214CLKDEV_CON_ID("video_clk", &div6_clks[DIV6_V]),215216/* MSTP32 clocks */217CLKDEV_CON_ID("tlb0", &mstp_clks[MSTP031]),218CLKDEV_CON_ID("ic0", &mstp_clks[MSTP030]),219CLKDEV_CON_ID("oc0", &mstp_clks[MSTP029]),220CLKDEV_CON_ID("rsmem0", &mstp_clks[MSTP028]),221CLKDEV_CON_ID("xymem0", &mstp_clks[MSTP026]),222CLKDEV_CON_ID("intc3", &mstp_clks[MSTP023]),223CLKDEV_CON_ID("intc0", &mstp_clks[MSTP022]),224CLKDEV_CON_ID("dmac0", &mstp_clks[MSTP021]),225CLKDEV_CON_ID("sh0", &mstp_clks[MSTP020]),226CLKDEV_CON_ID("hudi0", &mstp_clks[MSTP019]),227CLKDEV_CON_ID("ubc0", &mstp_clks[MSTP017]),228CLKDEV_CON_ID("tmu_fck", &mstp_clks[MSTP015]),229CLKDEV_CON_ID("cmt_fck", &mstp_clks[MSTP014]),230CLKDEV_CON_ID("rwdt0", &mstp_clks[MSTP013]),231CLKDEV_CON_ID("mfi0", &mstp_clks[MSTP011]),232CLKDEV_CON_ID("flctl0", &mstp_clks[MSTP010]),233{234/* SCIF0 */235.dev_id = "sh-sci.0",236.con_id = "sci_fck",237.clk = &mstp_clks[MSTP007],238}, {239/* SCIF1 */240.dev_id = "sh-sci.1",241.con_id = "sci_fck",242.clk = &mstp_clks[MSTP006],243}, {244/* SCIF2 */245.dev_id = "sh-sci.2",246.con_id = "sci_fck",247.clk = &mstp_clks[MSTP005],248},249CLKDEV_CON_ID("msiof0", &mstp_clks[MSTP002]),250CLKDEV_CON_ID("sbr0", &mstp_clks[MSTP001]),251CLKDEV_CON_ID("i2c0", &mstp_clks[MSTP109]),252CLKDEV_CON_ID("icb0", &mstp_clks[MSTP227]),253CLKDEV_CON_ID("meram0", &mstp_clks[MSTP226]),254CLKDEV_CON_ID("dacy1", &mstp_clks[MSTP224]),255CLKDEV_CON_ID("dacy0", &mstp_clks[MSTP223]),256CLKDEV_CON_ID("tsif0", &mstp_clks[MSTP222]),257CLKDEV_CON_ID("sdhi0", &mstp_clks[MSTP218]),258CLKDEV_CON_ID("mmcif0", &mstp_clks[MSTP217]),259CLKDEV_CON_ID("usbf0", &mstp_clks[MSTP211]),260CLKDEV_CON_ID("veu1", &mstp_clks[MSTP207]),261CLKDEV_CON_ID("vou0", &mstp_clks[MSTP205]),262CLKDEV_CON_ID("beu0", &mstp_clks[MSTP204]),263CLKDEV_CON_ID("ceu0", &mstp_clks[MSTP203]),264CLKDEV_CON_ID("veu0", &mstp_clks[MSTP202]),265CLKDEV_CON_ID("vpu0", &mstp_clks[MSTP201]),266CLKDEV_CON_ID("lcdc0", &mstp_clks[MSTP200]),267};268269int __init arch_clk_init(void)270{271int k, ret = 0;272273/* autodetect extal or dll configuration */274if (__raw_readl(PLLCR) & 0x1000)275pll_clk.parent = &dll_clk;276else277pll_clk.parent = &extal_clk;278279for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)280ret = clk_register(main_clks[k]);281282clkdev_add_table(lookups, ARRAY_SIZE(lookups));283284if (!ret)285ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);286287if (!ret)288ret = sh_clk_div6_register(div6_clks, DIV6_NR);289290if (!ret)291ret = sh_clk_mstp32_register(mstp_clks, MSTP_NR);292293return ret;294}295296297