Path: blob/master/arch/sh/kernel/cpu/sh4a/clock-sh7366.c
26498 views
// SPDX-License-Identifier: GPL-2.01/*2* arch/sh/kernel/cpu/sh4a/clock-sh7366.c3*4* SH7366 clock framework support5*6* Copyright (C) 2009 Magnus Damm7*/8#include <linux/init.h>9#include <linux/kernel.h>10#include <linux/io.h>11#include <linux/clkdev.h>12#include <asm/clock.h>1314/* SH7366 registers */15#define FRQCR 0xa415000016#define VCLKCR 0xa415000417#define SCLKACR 0xa415000818#define SCLKBCR 0xa415000c19#define PLLCR 0xa415002420#define MSTPCR0 0xa415003021#define MSTPCR1 0xa415003422#define MSTPCR2 0xa415003823#define DLLFRQ 0xa41500502425/* Fixed 32 KHz root clock for RTC and Power Management purposes */26static struct clk r_clk = {27.rate = 32768,28};2930/*31* Default rate for the root input clock, reset this with clk_set_rate()32* from the platform code.33*/34struct clk extal_clk = {35.rate = 33333333,36};3738/* The dll block multiplies the 32khz r_clk, may be used instead of extal */39static unsigned long dll_recalc(struct clk *clk)40{41unsigned long mult;4243if (__raw_readl(PLLCR) & 0x1000)44mult = __raw_readl(DLLFRQ);45else46mult = 0;4748return clk->parent->rate * mult;49}5051static struct sh_clk_ops dll_clk_ops = {52.recalc = dll_recalc,53};5455static struct clk dll_clk = {56.ops = &dll_clk_ops,57.parent = &r_clk,58.flags = CLK_ENABLE_ON_INIT,59};6061static unsigned long pll_recalc(struct clk *clk)62{63unsigned long mult = 1;64unsigned long div = 1;6566if (__raw_readl(PLLCR) & 0x4000)67mult = (((__raw_readl(FRQCR) >> 24) & 0x1f) + 1);68else69div = 2;7071return (clk->parent->rate * mult) / div;72}7374static struct sh_clk_ops pll_clk_ops = {75.recalc = pll_recalc,76};7778static struct clk pll_clk = {79.ops = &pll_clk_ops,80.flags = CLK_ENABLE_ON_INIT,81};8283struct clk *main_clks[] = {84&r_clk,85&extal_clk,86&dll_clk,87&pll_clk,88};8990static int multipliers[] = { 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 };91static int divisors[] = { 1, 3, 2, 5, 3, 4, 5, 6, 8, 10, 12, 16, 20 };9293static struct clk_div_mult_table div4_div_mult_table = {94.divisors = divisors,95.nr_divisors = ARRAY_SIZE(divisors),96.multipliers = multipliers,97.nr_multipliers = ARRAY_SIZE(multipliers),98};99100static struct clk_div4_table div4_table = {101.div_mult_table = &div4_div_mult_table,102};103104enum { DIV4_I, DIV4_U, DIV4_SH, DIV4_B, DIV4_B3, DIV4_P,105DIV4_SIUA, DIV4_SIUB, DIV4_NR };106107#define DIV4(_reg, _bit, _mask, _flags) \108SH_CLK_DIV4(&pll_clk, _reg, _bit, _mask, _flags)109110struct clk div4_clks[DIV4_NR] = {111[DIV4_I] = DIV4(FRQCR, 20, 0x1fef, CLK_ENABLE_ON_INIT),112[DIV4_U] = DIV4(FRQCR, 16, 0x1fff, CLK_ENABLE_ON_INIT),113[DIV4_SH] = DIV4(FRQCR, 12, 0x1fff, CLK_ENABLE_ON_INIT),114[DIV4_B] = DIV4(FRQCR, 8, 0x1fff, CLK_ENABLE_ON_INIT),115[DIV4_B3] = DIV4(FRQCR, 4, 0x1fff, CLK_ENABLE_ON_INIT),116[DIV4_P] = DIV4(FRQCR, 0, 0x1fff, 0),117[DIV4_SIUA] = DIV4(SCLKACR, 0, 0x1fff, 0),118[DIV4_SIUB] = DIV4(SCLKBCR, 0, 0x1fff, 0),119};120121enum { DIV6_V, DIV6_NR };122123struct clk div6_clks[DIV6_NR] = {124[DIV6_V] = SH_CLK_DIV6(&pll_clk, VCLKCR, 0),125};126127#define MSTP(_parent, _reg, _bit, _flags) \128SH_CLK_MSTP32(_parent, _reg, _bit, _flags)129130enum { MSTP031, MSTP030, MSTP029, MSTP028, MSTP026,131MSTP023, MSTP022, MSTP021, MSTP020, MSTP019, MSTP018, MSTP017, MSTP016,132MSTP015, MSTP014, MSTP013, MSTP012, MSTP011, MSTP010,133MSTP007, MSTP006, MSTP005, MSTP002, MSTP001,134MSTP109, MSTP100,135MSTP227, MSTP226, MSTP224, MSTP223, MSTP222, MSTP218, MSTP217,136MSTP211, MSTP207, MSTP205, MSTP204, MSTP203, MSTP202, MSTP201, MSTP200,137MSTP_NR };138139static struct clk mstp_clks[MSTP_NR] = {140/* See page 52 of Datasheet V0.40: Overview -> Block Diagram */141[MSTP031] = MSTP(&div4_clks[DIV4_I], MSTPCR0, 31, CLK_ENABLE_ON_INIT),142[MSTP030] = MSTP(&div4_clks[DIV4_I], MSTPCR0, 30, CLK_ENABLE_ON_INIT),143[MSTP029] = MSTP(&div4_clks[DIV4_I], MSTPCR0, 29, CLK_ENABLE_ON_INIT),144[MSTP028] = MSTP(&div4_clks[DIV4_SH], MSTPCR0, 28, CLK_ENABLE_ON_INIT),145[MSTP026] = MSTP(&div4_clks[DIV4_B], MSTPCR0, 26, CLK_ENABLE_ON_INIT),146[MSTP023] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 23, 0),147[MSTP022] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 22, 0),148[MSTP021] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 21, 0),149[MSTP020] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 20, 0),150[MSTP019] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 19, 0),151[MSTP017] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 17, 0),152[MSTP015] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 15, 0),153[MSTP014] = MSTP(&r_clk, MSTPCR0, 14, 0),154[MSTP013] = MSTP(&r_clk, MSTPCR0, 13, 0),155[MSTP011] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 11, 0),156[MSTP010] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 10, 0),157[MSTP007] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 7, 0),158[MSTP006] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 6, 0),159[MSTP005] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 5, 0),160[MSTP002] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 2, 0),161[MSTP001] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 1, 0),162163[MSTP109] = MSTP(&div4_clks[DIV4_P], MSTPCR1, 9, 0),164165[MSTP227] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 27, 0),166[MSTP226] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 26, 0),167[MSTP224] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 24, 0),168[MSTP223] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 23, 0),169[MSTP222] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 22, 0),170[MSTP218] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 18, 0),171[MSTP217] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 17, 0),172[MSTP211] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 11, 0),173[MSTP207] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 7, CLK_ENABLE_ON_INIT),174[MSTP205] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 5, 0),175[MSTP204] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 4, 0),176[MSTP203] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 3, 0),177[MSTP202] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 2, CLK_ENABLE_ON_INIT),178[MSTP201] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 1, CLK_ENABLE_ON_INIT),179[MSTP200] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 0, 0),180};181182static struct clk_lookup lookups[] = {183/* main clocks */184CLKDEV_CON_ID("rclk", &r_clk),185CLKDEV_CON_ID("extal", &extal_clk),186CLKDEV_CON_ID("dll_clk", &dll_clk),187CLKDEV_CON_ID("pll_clk", &pll_clk),188189/* DIV4 clocks */190CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),191CLKDEV_CON_ID("umem_clk", &div4_clks[DIV4_U]),192CLKDEV_CON_ID("shyway_clk", &div4_clks[DIV4_SH]),193CLKDEV_CON_ID("bus_clk", &div4_clks[DIV4_B]),194CLKDEV_CON_ID("b3_clk", &div4_clks[DIV4_B3]),195CLKDEV_CON_ID("peripheral_clk", &div4_clks[DIV4_P]),196CLKDEV_CON_ID("siua_clk", &div4_clks[DIV4_SIUA]),197CLKDEV_CON_ID("siub_clk", &div4_clks[DIV4_SIUB]),198199/* DIV6 clocks */200CLKDEV_CON_ID("video_clk", &div6_clks[DIV6_V]),201202/* MSTP32 clocks */203CLKDEV_CON_ID("tlb0", &mstp_clks[MSTP031]),204CLKDEV_CON_ID("ic0", &mstp_clks[MSTP030]),205CLKDEV_CON_ID("oc0", &mstp_clks[MSTP029]),206CLKDEV_CON_ID("rsmem0", &mstp_clks[MSTP028]),207CLKDEV_CON_ID("xymem0", &mstp_clks[MSTP026]),208CLKDEV_CON_ID("intc3", &mstp_clks[MSTP023]),209CLKDEV_CON_ID("intc0", &mstp_clks[MSTP022]),210CLKDEV_CON_ID("dmac0", &mstp_clks[MSTP021]),211CLKDEV_CON_ID("sh0", &mstp_clks[MSTP020]),212CLKDEV_CON_ID("hudi0", &mstp_clks[MSTP019]),213CLKDEV_CON_ID("ubc0", &mstp_clks[MSTP017]),214CLKDEV_CON_ID("tmu_fck", &mstp_clks[MSTP015]),215CLKDEV_ICK_ID("fck", "sh-cmt-32.0", &mstp_clks[MSTP014]),216CLKDEV_CON_ID("rwdt0", &mstp_clks[MSTP013]),217CLKDEV_CON_ID("mfi0", &mstp_clks[MSTP011]),218CLKDEV_CON_ID("flctl0", &mstp_clks[MSTP010]),219220CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP007]),221CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP006]),222CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP005]),223224CLKDEV_CON_ID("msiof0", &mstp_clks[MSTP002]),225CLKDEV_CON_ID("sbr0", &mstp_clks[MSTP001]),226CLKDEV_DEV_ID("i2c-sh_mobile.0", &mstp_clks[MSTP109]),227CLKDEV_CON_ID("icb0", &mstp_clks[MSTP227]),228CLKDEV_CON_ID("meram0", &mstp_clks[MSTP226]),229CLKDEV_CON_ID("dacy1", &mstp_clks[MSTP224]),230CLKDEV_CON_ID("dacy0", &mstp_clks[MSTP223]),231CLKDEV_CON_ID("tsif0", &mstp_clks[MSTP222]),232CLKDEV_CON_ID("sdhi0", &mstp_clks[MSTP218]),233CLKDEV_CON_ID("mmcif0", &mstp_clks[MSTP217]),234CLKDEV_CON_ID("usbf0", &mstp_clks[MSTP211]),235CLKDEV_CON_ID("veu1", &mstp_clks[MSTP207]),236CLKDEV_CON_ID("vou0", &mstp_clks[MSTP205]),237CLKDEV_CON_ID("beu0", &mstp_clks[MSTP204]),238CLKDEV_CON_ID("ceu0", &mstp_clks[MSTP203]),239CLKDEV_CON_ID("veu0", &mstp_clks[MSTP202]),240CLKDEV_CON_ID("vpu0", &mstp_clks[MSTP201]),241CLKDEV_CON_ID("lcdc0", &mstp_clks[MSTP200]),242};243244int __init arch_clk_init(void)245{246int k, ret = 0;247248/* autodetect extal or dll configuration */249if (__raw_readl(PLLCR) & 0x1000)250pll_clk.parent = &dll_clk;251else252pll_clk.parent = &extal_clk;253254for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)255ret = clk_register(main_clks[k]);256257clkdev_add_table(lookups, ARRAY_SIZE(lookups));258259if (!ret)260ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);261262if (!ret)263ret = sh_clk_div6_register(div6_clks, DIV6_NR);264265if (!ret)266ret = sh_clk_mstp_register(mstp_clks, MSTP_NR);267268return ret;269}270271272