Path: blob/master/arch/sh/kernel/cpu/sh4a/clock-sh7786.c
17531 views
/*1* arch/sh/kernel/cpu/sh4a/clock-sh7786.c2*3* SH7786 support for the clock framework4*5* Copyright (C) 2010 Paul Mundt6*7* This file is subject to the terms and conditions of the GNU General Public8* License. See the file "COPYING" in the main directory of this archive9* for more details.10*/11#include <linux/init.h>12#include <linux/kernel.h>13#include <linux/clk.h>14#include <linux/io.h>15#include <linux/clkdev.h>16#include <asm/clock.h>17#include <asm/freq.h>1819/*20* Default rate for the root input clock, reset this with clk_set_rate()21* from the platform code.22*/23static struct clk extal_clk = {24.rate = 33333333,25};2627static unsigned long pll_recalc(struct clk *clk)28{29int multiplier;3031/*32* Clock modes 0, 1, and 2 use an x64 multiplier against PLL1,33* while modes 3, 4, and 5 use an x32.34*/35multiplier = (sh_mv.mv_mode_pins() & 0xf) < 3 ? 64 : 32;3637return clk->parent->rate * multiplier;38}3940static struct clk_ops pll_clk_ops = {41.recalc = pll_recalc,42};4344static struct clk pll_clk = {45.ops = &pll_clk_ops,46.parent = &extal_clk,47.flags = CLK_ENABLE_ON_INIT,48};4950static struct clk *clks[] = {51&extal_clk,52&pll_clk,53};5455static unsigned int div2[] = { 1, 2, 4, 6, 8, 12, 16, 18,5624, 32, 36, 48 };5758static struct clk_div_mult_table div4_div_mult_table = {59.divisors = div2,60.nr_divisors = ARRAY_SIZE(div2),61};6263static struct clk_div4_table div4_table = {64.div_mult_table = &div4_div_mult_table,65};6667enum { DIV4_I, DIV4_SH, DIV4_B, DIV4_DDR, DIV4_DU, DIV4_P, DIV4_NR };6869#define DIV4(_bit, _mask, _flags) \70SH_CLK_DIV4(&pll_clk, FRQMR1, _bit, _mask, _flags)7172struct clk div4_clks[DIV4_NR] = {73[DIV4_P] = DIV4(0, 0x0b40, 0),74[DIV4_DU] = DIV4(4, 0x0010, 0),75[DIV4_DDR] = DIV4(12, 0x0002, CLK_ENABLE_ON_INIT),76[DIV4_B] = DIV4(16, 0x0360, CLK_ENABLE_ON_INIT),77[DIV4_SH] = DIV4(20, 0x0002, CLK_ENABLE_ON_INIT),78[DIV4_I] = DIV4(28, 0x0006, CLK_ENABLE_ON_INIT),79};8081#define MSTPCR0 0xffc4003082#define MSTPCR1 0xffc400348384enum { MSTP029, MSTP028, MSTP027, MSTP026, MSTP025, MSTP024,85MSTP023, MSTP022, MSTP021, MSTP020, MSTP017, MSTP016,86MSTP015, MSTP014, MSTP011, MSTP010, MSTP009, MSTP008,87MSTP005, MSTP004, MSTP002,88MSTP112, MSTP110, MSTP109, MSTP108,89MSTP105, MSTP104, MSTP103, MSTP102,90MSTP_NR };9192static struct clk mstp_clks[MSTP_NR] = {93/* MSTPCR0 */94[MSTP029] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 29, 0),95[MSTP028] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 28, 0),96[MSTP027] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 27, 0),97[MSTP026] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 26, 0),98[MSTP025] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 25, 0),99[MSTP024] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 24, 0),100[MSTP023] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 23, 0),101[MSTP022] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 22, 0),102[MSTP021] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 21, 0),103[MSTP020] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 20, 0),104[MSTP017] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 17, 0),105[MSTP016] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 16, 0),106[MSTP015] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 15, 0),107[MSTP014] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 14, 0),108[MSTP011] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 11, 0),109[MSTP010] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 10, 0),110[MSTP009] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 9, 0),111[MSTP008] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 8, 0),112[MSTP005] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 5, 0),113[MSTP004] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 4, 0),114[MSTP002] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 2, 0),115116/* MSTPCR1 */117[MSTP112] = SH_CLK_MSTP32(NULL, MSTPCR1, 12, 0),118[MSTP110] = SH_CLK_MSTP32(NULL, MSTPCR1, 10, 0),119[MSTP109] = SH_CLK_MSTP32(NULL, MSTPCR1, 9, 0),120[MSTP108] = SH_CLK_MSTP32(NULL, MSTPCR1, 8, 0),121[MSTP105] = SH_CLK_MSTP32(NULL, MSTPCR1, 5, 0),122[MSTP104] = SH_CLK_MSTP32(NULL, MSTPCR1, 4, 0),123[MSTP103] = SH_CLK_MSTP32(NULL, MSTPCR1, 3, 0),124[MSTP102] = SH_CLK_MSTP32(NULL, MSTPCR1, 2, 0),125};126127#define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }128129static struct clk_lookup lookups[] = {130/* main clocks */131CLKDEV_CON_ID("extal", &extal_clk),132CLKDEV_CON_ID("pll_clk", &pll_clk),133134/* DIV4 clocks */135CLKDEV_CON_ID("peripheral_clk", &div4_clks[DIV4_P]),136CLKDEV_CON_ID("du_clk", &div4_clks[DIV4_DU]),137CLKDEV_CON_ID("ddr_clk", &div4_clks[DIV4_DDR]),138CLKDEV_CON_ID("bus_clk", &div4_clks[DIV4_B]),139CLKDEV_CON_ID("shyway_clk", &div4_clks[DIV4_SH]),140CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),141142/* MSTP32 clocks */143{144/* SCIF5 */145.dev_id = "sh-sci.5",146.con_id = "sci_fck",147.clk = &mstp_clks[MSTP029],148}, {149/* SCIF4 */150.dev_id = "sh-sci.4",151.con_id = "sci_fck",152.clk = &mstp_clks[MSTP028],153}, {154/* SCIF3 */155.dev_id = "sh-sci.3",156.con_id = "sci_fck",157.clk = &mstp_clks[MSTP027],158}, {159/* SCIF2 */160.dev_id = "sh-sci.2",161.con_id = "sci_fck",162.clk = &mstp_clks[MSTP026],163}, {164/* SCIF1 */165.dev_id = "sh-sci.1",166.con_id = "sci_fck",167.clk = &mstp_clks[MSTP025],168}, {169/* SCIF0 */170.dev_id = "sh-sci.0",171.con_id = "sci_fck",172.clk = &mstp_clks[MSTP024],173},174CLKDEV_CON_ID("ssi3_fck", &mstp_clks[MSTP023]),175CLKDEV_CON_ID("ssi2_fck", &mstp_clks[MSTP022]),176CLKDEV_CON_ID("ssi1_fck", &mstp_clks[MSTP021]),177CLKDEV_CON_ID("ssi0_fck", &mstp_clks[MSTP020]),178CLKDEV_CON_ID("hac1_fck", &mstp_clks[MSTP017]),179CLKDEV_CON_ID("hac0_fck", &mstp_clks[MSTP016]),180CLKDEV_CON_ID("i2c1_fck", &mstp_clks[MSTP015]),181CLKDEV_CON_ID("i2c0_fck", &mstp_clks[MSTP014]),182{183/* TMU0 */184.dev_id = "sh_tmu.0",185.con_id = "tmu_fck",186.clk = &mstp_clks[MSTP008],187}, {188/* TMU1 */189.dev_id = "sh_tmu.1",190.con_id = "tmu_fck",191.clk = &mstp_clks[MSTP008],192}, {193/* TMU2 */194.dev_id = "sh_tmu.2",195.con_id = "tmu_fck",196.clk = &mstp_clks[MSTP008],197}, {198/* TMU3 */199.dev_id = "sh_tmu.3",200.con_id = "tmu_fck",201.clk = &mstp_clks[MSTP009],202}, {203/* TMU4 */204.dev_id = "sh_tmu.4",205.con_id = "tmu_fck",206.clk = &mstp_clks[MSTP009],207}, {208/* TMU5 */209.dev_id = "sh_tmu.5",210.con_id = "tmu_fck",211.clk = &mstp_clks[MSTP009],212}, {213/* TMU6 */214.dev_id = "sh_tmu.6",215.con_id = "tmu_fck",216.clk = &mstp_clks[MSTP010],217}, {218/* TMU7 */219.dev_id = "sh_tmu.7",220.con_id = "tmu_fck",221.clk = &mstp_clks[MSTP010],222}, {223/* TMU8 */224.dev_id = "sh_tmu.8",225.con_id = "tmu_fck",226.clk = &mstp_clks[MSTP010],227}, {228/* TMU9 */229.dev_id = "sh_tmu.9",230.con_id = "tmu_fck",231.clk = &mstp_clks[MSTP011],232}, {233/* TMU10 */234.dev_id = "sh_tmu.10",235.con_id = "tmu_fck",236.clk = &mstp_clks[MSTP011],237}, {238/* TMU11 */239.dev_id = "sh_tmu.11",240.con_id = "tmu_fck",241.clk = &mstp_clks[MSTP011],242},243CLKDEV_CON_ID("sdif1_fck", &mstp_clks[MSTP005]),244CLKDEV_CON_ID("sdif0_fck", &mstp_clks[MSTP004]),245CLKDEV_CON_ID("hspi_fck", &mstp_clks[MSTP002]),246CLKDEV_CON_ID("usb_fck", &mstp_clks[MSTP112]),247CLKDEV_CON_ID("pcie2_fck", &mstp_clks[MSTP110]),248CLKDEV_CON_ID("pcie1_fck", &mstp_clks[MSTP109]),249CLKDEV_CON_ID("pcie0_fck", &mstp_clks[MSTP108]),250CLKDEV_CON_ID("dmac_11_6_fck", &mstp_clks[MSTP105]),251CLKDEV_CON_ID("dmac_5_0_fck", &mstp_clks[MSTP104]),252CLKDEV_CON_ID("du_fck", &mstp_clks[MSTP103]),253CLKDEV_CON_ID("ether_fck", &mstp_clks[MSTP102]),254};255256int __init arch_clk_init(void)257{258int i, ret = 0;259260for (i = 0; i < ARRAY_SIZE(clks); i++)261ret |= clk_register(clks[i]);262for (i = 0; i < ARRAY_SIZE(lookups); i++)263clkdev_add(&lookups[i]);264265if (!ret)266ret = sh_clk_div4_register(div4_clks, ARRAY_SIZE(div4_clks),267&div4_table);268if (!ret)269ret = sh_clk_mstp32_register(mstp_clks, MSTP_NR);270271return ret;272}273274275