blob: 42942b4359dc1647ab0fb04d6af80565f01b12d9 [file] [log] [blame]
Magnus Dammeccf0602013-03-26 10:34:24 +09001/*
2 * r8a73a4 clock framework support
3 *
4 * Copyright (C) 2013 Renesas Solutions Corp.
5 * Copyright (C) 2013 Magnus Damm
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20#include <linux/init.h>
21#include <linux/io.h>
22#include <linux/kernel.h>
23#include <linux/sh_clk.h>
24#include <linux/clkdev.h>
Kuninori Morimoto5e634d92013-04-04 21:20:40 -070025#include <mach/clock.h>
Magnus Dammeccf0602013-03-26 10:34:24 +090026#include <mach/common.h>
27
28#define CPG_BASE 0xe6150000
29#define CPG_LEN 0x270
30
31#define MPCKCR 0xe6150080
Magnus Damme481a522013-03-26 10:34:33 +090032#define SMSTPCR2 0xe6150138
Kuninori Morimotoc91cf2f2013-03-25 23:18:15 -070033#define SMSTPCR5 0xe6150144
Magnus Dammeccf0602013-03-26 10:34:24 +090034
Kuninori Morimoto5e634d92013-04-04 21:20:40 -070035#define CKSCR 0xE61500C0
36
Magnus Dammeccf0602013-03-26 10:34:24 +090037static struct clk_mapping cpg_mapping = {
38 .phys = CPG_BASE,
39 .len = CPG_LEN,
40};
41
42static struct clk extalr_clk = {
43 .rate = 32768,
44 .mapping = &cpg_mapping,
45};
46
47static struct clk extal1_clk = {
48 .rate = 26000000,
49 .mapping = &cpg_mapping,
50};
51
52static struct clk extal2_clk = {
53 .rate = 48000000,
54 .mapping = &cpg_mapping,
55};
56
Kuninori Morimoto5e634d92013-04-04 21:20:40 -070057static struct sh_clk_ops followparent_clk_ops = {
58 .recalc = followparent_recalc,
59};
60
61static struct clk main_clk = {
62 /* .parent will be set r8a73a4_clock_init */
63 .ops = &followparent_clk_ops,
64};
65
66SH_CLK_RATIO(div2, 1, 2);
67SH_CLK_RATIO(div4, 1, 4);
68
69SH_FIXED_RATIO_CLK(main_div2_clk, main_clk, div2);
70SH_FIXED_RATIO_CLK(extal1_div2_clk, extal1_clk, div2);
71SH_FIXED_RATIO_CLK(extal2_div2_clk, extal2_clk, div2);
72SH_FIXED_RATIO_CLK(extal2_div4_clk, extal2_clk, div4);
73
Magnus Dammeccf0602013-03-26 10:34:24 +090074static struct clk *main_clks[] = {
75 &extalr_clk,
76 &extal1_clk,
Kuninori Morimoto5e634d92013-04-04 21:20:40 -070077 &extal1_div2_clk,
Magnus Dammeccf0602013-03-26 10:34:24 +090078 &extal2_clk,
Kuninori Morimoto5e634d92013-04-04 21:20:40 -070079 &extal2_div2_clk,
80 &extal2_div4_clk,
81 &main_clk,
82 &main_div2_clk,
Magnus Dammeccf0602013-03-26 10:34:24 +090083};
84
Kuninori Morimotoc91cf2f2013-03-25 23:18:15 -070085enum {
86 MSTP217, MSTP216, MSTP207, MSTP206, MSTP204, MSTP203,
87 MSTP522,
88 MSTP_NR
89};
90
Magnus Dammeccf0602013-03-26 10:34:24 +090091static struct clk mstp_clks[MSTP_NR] = {
Magnus Damme481a522013-03-26 10:34:33 +090092 [MSTP204] = SH_CLK_MSTP32(&extal2_clk, SMSTPCR2, 4, 0), /* SCIFA0 */
93 [MSTP203] = SH_CLK_MSTP32(&extal2_clk, SMSTPCR2, 3, 0), /* SCIFA1 */
94 [MSTP206] = SH_CLK_MSTP32(&extal2_clk, SMSTPCR2, 6, 0), /* SCIFB0 */
95 [MSTP207] = SH_CLK_MSTP32(&extal2_clk, SMSTPCR2, 7, 0), /* SCIFB1 */
96 [MSTP216] = SH_CLK_MSTP32(&extal2_clk, SMSTPCR2, 16, 0), /* SCIFB2 */
97 [MSTP217] = SH_CLK_MSTP32(&extal2_clk, SMSTPCR2, 17, 0), /* SCIFB3 */
Kuninori Morimotoc91cf2f2013-03-25 23:18:15 -070098 [MSTP522] = SH_CLK_MSTP32(&extal2_clk, SMSTPCR5, 22, 0), /* Thermal */
Magnus Dammeccf0602013-03-26 10:34:24 +090099};
100
101static struct clk_lookup lookups[] = {
Kuninori Morimoto5e634d92013-04-04 21:20:40 -0700102 /* main clock */
103 CLKDEV_CON_ID("extal1", &extal1_clk),
104 CLKDEV_CON_ID("extal1_div2", &extal1_div2_clk),
105 CLKDEV_CON_ID("extal2", &extal2_clk),
106 CLKDEV_CON_ID("extal2_div2", &extal2_div2_clk),
107 CLKDEV_CON_ID("extal2_div4", &extal2_div4_clk),
108
Magnus Damme481a522013-03-26 10:34:33 +0900109 CLKDEV_DEV_ID("sh-sci.0", &mstp_clks[MSTP204]),
110 CLKDEV_DEV_ID("sh-sci.1", &mstp_clks[MSTP203]),
111 CLKDEV_DEV_ID("sh-sci.2", &mstp_clks[MSTP206]),
112 CLKDEV_DEV_ID("sh-sci.3", &mstp_clks[MSTP207]),
113 CLKDEV_DEV_ID("sh-sci.4", &mstp_clks[MSTP216]),
114 CLKDEV_DEV_ID("sh-sci.5", &mstp_clks[MSTP217]),
Kuninori Morimotoc91cf2f2013-03-25 23:18:15 -0700115 CLKDEV_DEV_ID("rcar_thermal", &mstp_clks[MSTP522]),
116
117 /* for DT */
118 CLKDEV_DEV_ID("e61f0000.thermal", &mstp_clks[MSTP522]),
Magnus Dammeccf0602013-03-26 10:34:24 +0900119};
120
121void __init r8a73a4_clock_init(void)
122{
123 void __iomem *cpg_base, *reg;
124 int k, ret = 0;
Kuninori Morimoto5e634d92013-04-04 21:20:40 -0700125 u32 ckscr;
Magnus Dammeccf0602013-03-26 10:34:24 +0900126
127 /* fix MPCLK to EXTAL2 for now.
128 * this is needed until more detailed clock topology is supported
129 */
130 cpg_base = ioremap_nocache(CPG_BASE, CPG_LEN);
131 BUG_ON(!cpg_base);
132 reg = cpg_base + (MPCKCR - CPG_BASE);
133 iowrite32(ioread32(reg) | 1 << 7 | 0x0c, reg); /* set CKSEL */
134 iounmap(cpg_base);
135
Kuninori Morimoto5e634d92013-04-04 21:20:40 -0700136 reg = ioremap_nocache(CKSCR, PAGE_SIZE);
137 BUG_ON(!reg);
138 ckscr = ioread32(reg);
139 iounmap(reg);
140
141 switch ((ckscr >> 28) & 0x3) {
142 case 0:
143 main_clk.parent = &extal1_clk;
144 break;
145 case 1:
146 main_clk.parent = &extal1_div2_clk;
147 break;
148 case 2:
149 main_clk.parent = &extal2_clk;
150 break;
151 case 3:
152 main_clk.parent = &extal2_div2_clk;
153 break;
154 }
155
Magnus Dammeccf0602013-03-26 10:34:24 +0900156 for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
157 ret = clk_register(main_clks[k]);
158
159 if (!ret)
160 ret = sh_clk_mstp_register(mstp_clks, MSTP_NR);
161
162 clkdev_add_table(lookups, ARRAY_SIZE(lookups));
163
164 if (!ret)
165 shmobile_clk_init();
166 else
167 panic("failed to setup r8a73a4 clocks\n");
168}