Path: blob/master/arch/sh/kernel/cpu/sh4a/clock-sh7734.c
26498 views
// SPDX-License-Identifier: GPL-2.01/*2* arch/sh/kernel/cpu/sh4a/clock-sh7734.c3*4* Clock framework for SH77345*6* Copyright (C) 2011, 2012 Nobuhiro Iwamatsu <[email protected]>7* Copyright (C) 2011, 2012 Renesas Solutions Corp.8*/910#include <linux/init.h>11#include <linux/kernel.h>12#include <linux/io.h>13#include <linux/clkdev.h>14#include <linux/delay.h>15#include <asm/clock.h>16#include <asm/freq.h>1718static struct clk extal_clk = {19.rate = 33333333,20};2122#define MODEMR (0xFFCC0020)23#define MODEMR_MASK (0x6)24#define MODEMR_533MHZ (0x2)2526static unsigned long pll_recalc(struct clk *clk)27{28int mode = 12;29u32 r = __raw_readl(MODEMR);3031if ((r & MODEMR_MASK) & MODEMR_533MHZ)32mode = 16;3334return clk->parent->rate * mode;35}3637static struct sh_clk_ops pll_clk_ops = {38.recalc = pll_recalc,39};4041static struct clk pll_clk = {42.ops = &pll_clk_ops,43.parent = &extal_clk,44.flags = CLK_ENABLE_ON_INIT,45};4647static struct clk *main_clks[] = {48&extal_clk,49&pll_clk,50};5152static int multipliers[] = { 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };53static int divisors[] = { 1, 3, 2, 3, 4, 6, 8, 9, 12, 16, 18, 24 };5455static struct clk_div_mult_table div4_div_mult_table = {56.divisors = divisors,57.nr_divisors = ARRAY_SIZE(divisors),58.multipliers = multipliers,59.nr_multipliers = ARRAY_SIZE(multipliers),60};6162static struct clk_div4_table div4_table = {63.div_mult_table = &div4_div_mult_table,64};6566enum { DIV4_I, DIV4_S, DIV4_B, DIV4_M, DIV4_S1, DIV4_P, DIV4_NR };6768#define DIV4(_reg, _bit, _mask, _flags) \69SH_CLK_DIV4(&pll_clk, _reg, _bit, _mask, _flags)7071struct clk div4_clks[DIV4_NR] = {72[DIV4_I] = DIV4(FRQMR1, 28, 0x0003, CLK_ENABLE_ON_INIT),73[DIV4_S] = DIV4(FRQMR1, 20, 0x000C, CLK_ENABLE_ON_INIT),74[DIV4_B] = DIV4(FRQMR1, 16, 0x0140, CLK_ENABLE_ON_INIT),75[DIV4_M] = DIV4(FRQMR1, 12, 0x0004, CLK_ENABLE_ON_INIT),76[DIV4_S1] = DIV4(FRQMR1, 4, 0x0030, CLK_ENABLE_ON_INIT),77[DIV4_P] = DIV4(FRQMR1, 0, 0x0140, CLK_ENABLE_ON_INIT),78};7980#define MSTPCR0 0xFFC8003081#define MSTPCR1 0xFFC8003482#define MSTPCR3 0xFFC8003C8384enum {85MSTP030, MSTP029, /* IIC */86MSTP026, MSTP025, MSTP024, /* SCIF */87MSTP023,88MSTP022, MSTP021,89MSTP019, /* HSCIF */90MSTP016, MSTP015, MSTP014, /* TMU / TIMER */91MSTP012, MSTP011, MSTP010, MSTP009, MSTP008, /* SSI */92MSTP007, /* HSPI */93MSTP115, /* ADMAC */94MSTP114, /* GETHER */95MSTP111, /* DMAC */96MSTP109, /* VIDEOIN1 */97MSTP108, /* VIDEOIN0 */98MSTP107, /* RGPVBG */99MSTP106, /* 2DG */100MSTP103, /* VIEW */101MSTP100, /* USB */102MSTP331, /* MMC */103MSTP330, /* MIMLB */104MSTP323, /* SDHI0 */105MSTP322, /* SDHI1 */106MSTP321, /* SDHI2 */107MSTP320, /* RQSPI */108MSTP319, /* SRC0 */109MSTP318, /* SRC1 */110MSTP317, /* RSPI */111MSTP316, /* RCAN0 */112MSTP315, /* RCAN1 */113MSTP314, /* FLTCL */114MSTP313, /* ADC */115MSTP312, /* MTU */116MSTP304, /* IE-BUS */117MSTP303, /* RTC */118MSTP302, /* HIF */119MSTP301, /* STIF0 */120MSTP300, /* STIF1 */121MSTP_NR };122123static struct clk mstp_clks[MSTP_NR] = {124/* MSTPCR0 */125[MSTP030] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 30, 0),126[MSTP029] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 29, 0),127[MSTP026] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 26, 0),128[MSTP025] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 25, 0),129[MSTP024] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 24, 0),130[MSTP023] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 23, 0),131[MSTP022] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 22, 0),132[MSTP021] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 21, 0),133[MSTP019] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 19, 0),134[MSTP016] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 16, 0),135[MSTP015] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 15, 0),136[MSTP014] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 14, 0),137[MSTP012] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 12, 0),138[MSTP011] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 11, 0),139[MSTP010] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 10, 0),140[MSTP009] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 9, 0),141[MSTP008] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 8, 0),142[MSTP007] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 7, 0),143144/* MSTPCR1 */145[MSTP115] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 15, 0),146[MSTP114] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 14, 0),147[MSTP111] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 11, 0),148[MSTP109] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 9, 0),149[MSTP108] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 8, 0),150[MSTP107] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 7, 0),151[MSTP106] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 6, 0),152[MSTP103] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 3, 0),153[MSTP100] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 0, 0),154155/* MSTPCR3 */156[MSTP331] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 31, 0),157[MSTP330] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 30, 0),158[MSTP323] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 23, 0),159[MSTP322] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 22, 0),160[MSTP321] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 21, 0),161[MSTP320] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 20, 0),162[MSTP319] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 19, 0),163[MSTP318] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 18, 0),164[MSTP317] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 17, 0),165[MSTP316] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 16, 0),166[MSTP315] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 15, 0),167[MSTP314] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 14, 0),168[MSTP313] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 13, 0),169[MSTP312] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 12, 0),170[MSTP304] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 4, 0),171[MSTP303] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 3, 0),172[MSTP302] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 2, 0),173[MSTP301] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 1, 0),174[MSTP300] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR3, 0, 0),175};176177static struct clk_lookup lookups[] = {178/* main clocks */179CLKDEV_CON_ID("extal", &extal_clk),180CLKDEV_CON_ID("pll_clk", &pll_clk),181182/* clocks */183CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),184CLKDEV_CON_ID("shyway_clk", &div4_clks[DIV4_S]),185CLKDEV_CON_ID("ddr_clk", &div4_clks[DIV4_M]),186CLKDEV_CON_ID("bus_clk", &div4_clks[DIV4_B]),187CLKDEV_CON_ID("shyway_clk1", &div4_clks[DIV4_S1]),188CLKDEV_CON_ID("peripheral_clk", &div4_clks[DIV4_P]),189190/* MSTP32 clocks */191CLKDEV_DEV_ID("i2c-sh7734.0", &mstp_clks[MSTP030]),192CLKDEV_DEV_ID("i2c-sh7734.1", &mstp_clks[MSTP029]),193CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP026]),194CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP025]),195CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP024]),196CLKDEV_ICK_ID("fck", "sh-sci.3", &mstp_clks[MSTP023]),197CLKDEV_ICK_ID("fck", "sh-sci.4", &mstp_clks[MSTP022]),198CLKDEV_ICK_ID("fck", "sh-sci.5", &mstp_clks[MSTP021]),199CLKDEV_CON_ID("hscif", &mstp_clks[MSTP019]),200CLKDEV_ICK_ID("fck", "sh-tmu.0", &mstp_clks[MSTP016]),201CLKDEV_ICK_ID("fck", "sh-tmu.1", &mstp_clks[MSTP015]),202CLKDEV_ICK_ID("fck", "sh-tmu.2", &mstp_clks[MSTP014]),203CLKDEV_CON_ID("ssi0", &mstp_clks[MSTP012]),204CLKDEV_CON_ID("ssi1", &mstp_clks[MSTP011]),205CLKDEV_CON_ID("ssi2", &mstp_clks[MSTP010]),206CLKDEV_CON_ID("ssi3", &mstp_clks[MSTP009]),207CLKDEV_CON_ID("sss", &mstp_clks[MSTP008]),208CLKDEV_CON_ID("hspi", &mstp_clks[MSTP007]),209CLKDEV_CON_ID("usb_fck", &mstp_clks[MSTP100]),210CLKDEV_CON_ID("videoin0", &mstp_clks[MSTP109]),211CLKDEV_CON_ID("videoin1", &mstp_clks[MSTP108]),212CLKDEV_CON_ID("rgpvg", &mstp_clks[MSTP107]),213CLKDEV_CON_ID("2dg", &mstp_clks[MSTP106]),214CLKDEV_CON_ID("view", &mstp_clks[MSTP103]),215216CLKDEV_CON_ID("mmc0", &mstp_clks[MSTP331]),217CLKDEV_CON_ID("mimlb0", &mstp_clks[MSTP330]),218CLKDEV_CON_ID("sdhi0", &mstp_clks[MSTP323]),219CLKDEV_CON_ID("sdhi1", &mstp_clks[MSTP322]),220CLKDEV_CON_ID("sdhi2", &mstp_clks[MSTP321]),221CLKDEV_CON_ID("rqspi0", &mstp_clks[MSTP320]),222CLKDEV_CON_ID("src0", &mstp_clks[MSTP319]),223CLKDEV_CON_ID("src1", &mstp_clks[MSTP318]),224CLKDEV_CON_ID("rsp0", &mstp_clks[MSTP317]),225CLKDEV_CON_ID("rcan0", &mstp_clks[MSTP316]),226CLKDEV_CON_ID("rcan1", &mstp_clks[MSTP315]),227CLKDEV_CON_ID("fltcl0", &mstp_clks[MSTP314]),228CLKDEV_CON_ID("adc0", &mstp_clks[MSTP313]),229CLKDEV_CON_ID("mtu0", &mstp_clks[MSTP312]),230CLKDEV_CON_ID("iebus0", &mstp_clks[MSTP304]),231CLKDEV_DEV_ID("sh7734-gether.0", &mstp_clks[MSTP114]),232CLKDEV_CON_ID("rtc0", &mstp_clks[MSTP303]),233CLKDEV_CON_ID("hif0", &mstp_clks[MSTP302]),234CLKDEV_CON_ID("stif0", &mstp_clks[MSTP301]),235CLKDEV_CON_ID("stif1", &mstp_clks[MSTP300]),236};237238int __init arch_clk_init(void)239{240int i, ret = 0;241242for (i = 0; i < ARRAY_SIZE(main_clks); i++)243ret |= clk_register(main_clks[i]);244245clkdev_add_table(lookups, ARRAY_SIZE(lookups));246247if (!ret)248ret = sh_clk_div4_register(div4_clks, ARRAY_SIZE(div4_clks),249&div4_table);250251if (!ret)252ret = sh_clk_mstp_register(mstp_clks, MSTP_NR);253254return ret;255}256257258