Path: blob/master/arch/sh/kernel/cpu/sh4a/clock-sh7757.c
26498 views
// SPDX-License-Identifier: GPL-2.01/*2* arch/sh/kernel/cpu/sh4/clock-sh7757.c3*4* SH7757 support for the clock framework5*6* Copyright (C) 2009-2010 Renesas Solutions Corp.7*/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>13#include <asm/freq.h>1415/*16* Default rate for the root input clock, reset this with clk_set_rate()17* from the platform code.18*/19static struct clk extal_clk = {20.rate = 48000000,21};2223static unsigned long pll_recalc(struct clk *clk)24{25int multiplier;2627multiplier = test_mode_pin(MODE_PIN0) ? 24 : 16;2829return clk->parent->rate * multiplier;30}3132static struct sh_clk_ops pll_clk_ops = {33.recalc = pll_recalc,34};3536static struct clk pll_clk = {37.ops = &pll_clk_ops,38.parent = &extal_clk,39.flags = CLK_ENABLE_ON_INIT,40};4142static struct clk *clks[] = {43&extal_clk,44&pll_clk,45};4647static unsigned int div2[] = { 1, 1, 2, 1, 1, 4, 1, 6,481, 1, 1, 16, 1, 24, 1, 1 };4950static struct clk_div_mult_table div4_div_mult_table = {51.divisors = div2,52.nr_divisors = ARRAY_SIZE(div2),53};5455static struct clk_div4_table div4_table = {56.div_mult_table = &div4_div_mult_table,57};5859enum { DIV4_I, DIV4_SH, DIV4_P, DIV4_NR };6061#define DIV4(_bit, _mask, _flags) \62SH_CLK_DIV4(&pll_clk, FRQCR, _bit, _mask, _flags)6364struct clk div4_clks[DIV4_NR] = {65/*66* P clock is always enable, because some P clock modules is used67* by Host PC.68*/69[DIV4_P] = DIV4(0, 0x2800, CLK_ENABLE_ON_INIT),70[DIV4_SH] = DIV4(12, 0x00a0, CLK_ENABLE_ON_INIT),71[DIV4_I] = DIV4(20, 0x0004, CLK_ENABLE_ON_INIT),72};7374#define MSTPCR0 0xffc8003075#define MSTPCR1 0xffc8003476#define MSTPCR2 0xffc100287778enum { MSTP004, MSTP000, MSTP127, MSTP114, MSTP113, MSTP112,79MSTP111, MSTP110, MSTP103, MSTP102, MSTP220,80MSTP_NR };8182static struct clk mstp_clks[MSTP_NR] = {83/* MSTPCR0 */84[MSTP004] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 4, 0),85[MSTP000] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 0, 0),8687/* MSTPCR1 */88[MSTP127] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 27, 0),89[MSTP114] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 14, 0),90[MSTP113] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 13, 0),91[MSTP112] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 12, 0),92[MSTP111] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 11, 0),93[MSTP110] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 10, 0),94[MSTP103] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 3, 0),95[MSTP102] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR1, 2, 0),9697/* MSTPCR2 */98[MSTP220] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR2, 20, 0),99};100101static struct clk_lookup lookups[] = {102/* main clocks */103CLKDEV_CON_ID("extal", &extal_clk),104CLKDEV_CON_ID("pll_clk", &pll_clk),105106/* DIV4 clocks */107CLKDEV_CON_ID("peripheral_clk", &div4_clks[DIV4_P]),108CLKDEV_CON_ID("shyway_clk", &div4_clks[DIV4_SH]),109CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),110111/* MSTP32 clocks */112CLKDEV_DEV_ID("sh_mobile_sdhi.0", &mstp_clks[MSTP004]),113CLKDEV_CON_ID("riic0", &mstp_clks[MSTP000]),114CLKDEV_CON_ID("riic1", &mstp_clks[MSTP000]),115CLKDEV_CON_ID("riic2", &mstp_clks[MSTP000]),116CLKDEV_CON_ID("riic3", &mstp_clks[MSTP000]),117CLKDEV_CON_ID("riic4", &mstp_clks[MSTP000]),118CLKDEV_CON_ID("riic5", &mstp_clks[MSTP000]),119CLKDEV_CON_ID("riic6", &mstp_clks[MSTP000]),120CLKDEV_CON_ID("riic7", &mstp_clks[MSTP000]),121122CLKDEV_ICK_ID("fck", "sh-tmu.0", &mstp_clks[MSTP113]),123CLKDEV_ICK_ID("fck", "sh-tmu.1", &mstp_clks[MSTP114]),124CLKDEV_ICK_ID("fck", "sh-sci.2", &mstp_clks[MSTP112]),125CLKDEV_ICK_ID("fck", "sh-sci.1", &mstp_clks[MSTP111]),126CLKDEV_ICK_ID("fck", "sh-sci.0", &mstp_clks[MSTP110]),127128CLKDEV_CON_ID("usb_fck", &mstp_clks[MSTP103]),129CLKDEV_DEV_ID("renesas_usbhs.0", &mstp_clks[MSTP102]),130CLKDEV_CON_ID("mmc0", &mstp_clks[MSTP220]),131CLKDEV_DEV_ID("rspi.2", &mstp_clks[MSTP127]),132};133134int __init arch_clk_init(void)135{136int i, ret = 0;137138for (i = 0; i < ARRAY_SIZE(clks); i++)139ret |= clk_register(clks[i]);140141clkdev_add_table(lookups, ARRAY_SIZE(lookups));142143if (!ret)144ret = sh_clk_div4_register(div4_clks, ARRAY_SIZE(div4_clks),145&div4_table);146if (!ret)147ret = sh_clk_mstp_register(mstp_clks, MSTP_NR);148149return ret;150}151152153154