Magnus Damm | 0468b2d | 2013-03-28 00:49:34 +0900 | [diff] [blame] | 1 | /* |
| 2 | * r8a7790 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 Morimoto | 8d100c0 | 2013-04-12 00:42:22 -0700 | [diff] [blame^] | 25 | #include <mach/clock.h> |
Magnus Damm | 0468b2d | 2013-03-28 00:49:34 +0900 | [diff] [blame] | 26 | #include <mach/common.h> |
| 27 | |
Kuninori Morimoto | 8d100c0 | 2013-04-12 00:42:22 -0700 | [diff] [blame^] | 28 | /* |
| 29 | * MD EXTAL PLL0 PLL1 PLL3 |
| 30 | * 14 13 19 (MHz) *1 *1 |
| 31 | *--------------------------------------------------- |
| 32 | * 0 0 0 15 x 1 x172/2 x208/2 x106 |
| 33 | * 0 0 1 15 x 1 x172/2 x208/2 x88 |
| 34 | * 0 1 0 20 x 1 x130/2 x156/2 x80 |
| 35 | * 0 1 1 20 x 1 x130/2 x156/2 x66 |
| 36 | * 1 0 0 26 / 2 x200/2 x240/2 x122 |
| 37 | * 1 0 1 26 / 2 x200/2 x240/2 x102 |
| 38 | * 1 1 0 30 / 2 x172/2 x208/2 x106 |
| 39 | * 1 1 1 30 / 2 x172/2 x208/2 x88 |
| 40 | * |
| 41 | * *1 : Table 7.6 indicates VCO ouput (PLLx = VCO/2) |
| 42 | * see "p1 / 2" on R8A7790_CLOCK_ROOT() below |
| 43 | */ |
| 44 | |
| 45 | #define MD(nr) (1 << nr) |
| 46 | |
Magnus Damm | 0468b2d | 2013-03-28 00:49:34 +0900 | [diff] [blame] | 47 | #define CPG_BASE 0xe6150000 |
| 48 | #define CPG_LEN 0x1000 |
| 49 | |
Magnus Damm | 55d9fab | 2013-03-28 00:49:44 +0900 | [diff] [blame] | 50 | #define SMSTPCR2 0xe6150138 |
| 51 | #define SMSTPCR7 0xe615014c |
| 52 | |
Kuninori Morimoto | 8d100c0 | 2013-04-12 00:42:22 -0700 | [diff] [blame^] | 53 | #define MODEMR 0xE6160060 |
| 54 | |
Magnus Damm | 0468b2d | 2013-03-28 00:49:34 +0900 | [diff] [blame] | 55 | static struct clk_mapping cpg_mapping = { |
| 56 | .phys = CPG_BASE, |
| 57 | .len = CPG_LEN, |
| 58 | }; |
| 59 | |
Kuninori Morimoto | 8d100c0 | 2013-04-12 00:42:22 -0700 | [diff] [blame^] | 60 | static struct clk extal_clk = { |
| 61 | /* .rate will be updated on r8a7790_clock_init() */ |
Magnus Damm | 55d9fab | 2013-03-28 00:49:44 +0900 | [diff] [blame] | 62 | .mapping = &cpg_mapping, |
Magnus Damm | 0468b2d | 2013-03-28 00:49:34 +0900 | [diff] [blame] | 63 | }; |
| 64 | |
Kuninori Morimoto | 8d100c0 | 2013-04-12 00:42:22 -0700 | [diff] [blame^] | 65 | static struct sh_clk_ops followparent_clk_ops = { |
| 66 | .recalc = followparent_recalc, |
Magnus Damm | 55d9fab | 2013-03-28 00:49:44 +0900 | [diff] [blame] | 67 | }; |
| 68 | |
Kuninori Morimoto | 8d100c0 | 2013-04-12 00:42:22 -0700 | [diff] [blame^] | 69 | static struct clk main_clk = { |
| 70 | /* .parent will be set r8a73a4_clock_init */ |
| 71 | .ops = &followparent_clk_ops, |
| 72 | }; |
| 73 | |
| 74 | /* |
| 75 | * clock ratio of these clock will be updated |
| 76 | * on r8a7790_clock_init() |
| 77 | */ |
| 78 | SH_FIXED_RATIO_CLK_SET(pll1_clk, main_clk, 1, 1); |
| 79 | SH_FIXED_RATIO_CLK_SET(pll3_clk, main_clk, 1, 1); |
| 80 | SH_FIXED_RATIO_CLK_SET(lb_clk, pll1_clk, 1, 1); |
| 81 | SH_FIXED_RATIO_CLK_SET(qspi_clk, pll1_clk, 1, 1); |
| 82 | |
| 83 | /* fixed ratio clock */ |
| 84 | SH_FIXED_RATIO_CLK_SET(extal_div2_clk, extal_clk, 1, 2); |
| 85 | SH_FIXED_RATIO_CLK_SET(cp_clk, extal_clk, 1, 2); |
| 86 | |
| 87 | SH_FIXED_RATIO_CLK_SET(pll1_div2_clk, pll1_clk, 1, 2); |
| 88 | SH_FIXED_RATIO_CLK_SET(zg_clk, pll1_clk, 1, 3); |
| 89 | SH_FIXED_RATIO_CLK_SET(zx_clk, pll1_clk, 1, 3); |
| 90 | SH_FIXED_RATIO_CLK_SET(zs_clk, pll1_clk, 1, 6); |
| 91 | SH_FIXED_RATIO_CLK_SET(hp_clk, pll1_clk, 1, 12); |
| 92 | SH_FIXED_RATIO_CLK_SET(i_clk, pll1_clk, 1, 2); |
| 93 | SH_FIXED_RATIO_CLK_SET(b_clk, pll1_clk, 1, 12); |
| 94 | SH_FIXED_RATIO_CLK_SET(p_clk, pll1_clk, 1, 24); |
| 95 | SH_FIXED_RATIO_CLK_SET(cl_clk, pll1_clk, 1, 48); |
| 96 | SH_FIXED_RATIO_CLK_SET(m2_clk, pll1_clk, 1, 8); |
| 97 | SH_FIXED_RATIO_CLK_SET(imp_clk, pll1_clk, 1, 4); |
| 98 | SH_FIXED_RATIO_CLK_SET(rclk_clk, pll1_clk, 1, (48 * 1024)); |
| 99 | SH_FIXED_RATIO_CLK_SET(oscclk_clk, pll1_clk, 1, (12 * 1024)); |
| 100 | |
| 101 | SH_FIXED_RATIO_CLK_SET(zb3_clk, pll3_clk, 1, 4); |
| 102 | SH_FIXED_RATIO_CLK_SET(zb3d2_clk, pll3_clk, 1, 8); |
| 103 | SH_FIXED_RATIO_CLK_SET(ddr_clk, pll3_clk, 1, 8); |
| 104 | SH_FIXED_RATIO_CLK_SET(mp_clk, pll1_div2_clk, 1, 15); |
| 105 | |
Magnus Damm | 55d9fab | 2013-03-28 00:49:44 +0900 | [diff] [blame] | 106 | static struct clk *main_clks[] = { |
Kuninori Morimoto | 8d100c0 | 2013-04-12 00:42:22 -0700 | [diff] [blame^] | 107 | &extal_clk, |
| 108 | &extal_div2_clk, |
| 109 | &main_clk, |
| 110 | &pll1_clk, |
| 111 | &pll1_div2_clk, |
| 112 | &pll3_clk, |
| 113 | &lb_clk, |
| 114 | &qspi_clk, |
| 115 | &zg_clk, |
| 116 | &zx_clk, |
| 117 | &zs_clk, |
| 118 | &hp_clk, |
| 119 | &i_clk, |
| 120 | &b_clk, |
Magnus Damm | 55d9fab | 2013-03-28 00:49:44 +0900 | [diff] [blame] | 121 | &p_clk, |
Kuninori Morimoto | 8d100c0 | 2013-04-12 00:42:22 -0700 | [diff] [blame^] | 122 | &cl_clk, |
| 123 | &m2_clk, |
| 124 | &imp_clk, |
| 125 | &rclk_clk, |
| 126 | &oscclk_clk, |
| 127 | &zb3_clk, |
| 128 | &zb3d2_clk, |
| 129 | &ddr_clk, |
Magnus Damm | 55d9fab | 2013-03-28 00:49:44 +0900 | [diff] [blame] | 130 | &mp_clk, |
Kuninori Morimoto | 8d100c0 | 2013-04-12 00:42:22 -0700 | [diff] [blame^] | 131 | &cp_clk, |
Magnus Damm | 55d9fab | 2013-03-28 00:49:44 +0900 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | enum { MSTP721, MSTP720, |
| 135 | MSTP216, MSTP207, MSTP206, MSTP204, MSTP203, MSTP202, MSTP_NR }; |
Magnus Damm | 0468b2d | 2013-03-28 00:49:34 +0900 | [diff] [blame] | 136 | static struct clk mstp_clks[MSTP_NR] = { |
Magnus Damm | 55d9fab | 2013-03-28 00:49:44 +0900 | [diff] [blame] | 137 | [MSTP721] = SH_CLK_MSTP32(&p_clk, SMSTPCR7, 21, 0), /* SCIF0 */ |
| 138 | [MSTP720] = SH_CLK_MSTP32(&p_clk, SMSTPCR7, 20, 0), /* SCIF1 */ |
| 139 | [MSTP216] = SH_CLK_MSTP32(&mp_clk, SMSTPCR2, 16, 0), /* SCIFB2 */ |
| 140 | [MSTP207] = SH_CLK_MSTP32(&mp_clk, SMSTPCR2, 7, 0), /* SCIFB1 */ |
| 141 | [MSTP206] = SH_CLK_MSTP32(&mp_clk, SMSTPCR2, 6, 0), /* SCIFB0 */ |
| 142 | [MSTP204] = SH_CLK_MSTP32(&mp_clk, SMSTPCR2, 4, 0), /* SCIFA0 */ |
| 143 | [MSTP203] = SH_CLK_MSTP32(&mp_clk, SMSTPCR2, 3, 0), /* SCIFA1 */ |
| 144 | [MSTP202] = SH_CLK_MSTP32(&mp_clk, SMSTPCR2, 2, 0), /* SCIFA2 */ |
Magnus Damm | 0468b2d | 2013-03-28 00:49:34 +0900 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | static struct clk_lookup lookups[] = { |
Kuninori Morimoto | 8d100c0 | 2013-04-12 00:42:22 -0700 | [diff] [blame^] | 148 | |
| 149 | /* main clocks */ |
| 150 | CLKDEV_CON_ID("extal", &extal_clk), |
| 151 | CLKDEV_CON_ID("extal_div2", &extal_div2_clk), |
| 152 | CLKDEV_CON_ID("main", &main_clk), |
| 153 | CLKDEV_CON_ID("pll1", &pll1_clk), |
| 154 | CLKDEV_CON_ID("pll1_div2", &pll1_div2_clk), |
| 155 | CLKDEV_CON_ID("pll3", &pll3_clk), |
| 156 | CLKDEV_CON_ID("zg", &zg_clk), |
| 157 | CLKDEV_CON_ID("zx", &zx_clk), |
| 158 | CLKDEV_CON_ID("zs", &zs_clk), |
| 159 | CLKDEV_CON_ID("hp", &hp_clk), |
| 160 | CLKDEV_CON_ID("i", &i_clk), |
| 161 | CLKDEV_CON_ID("b", &b_clk), |
| 162 | CLKDEV_CON_ID("lb", &lb_clk), |
| 163 | CLKDEV_CON_ID("p", &p_clk), |
| 164 | CLKDEV_CON_ID("cl", &cl_clk), |
| 165 | CLKDEV_CON_ID("m2", &m2_clk), |
| 166 | CLKDEV_CON_ID("imp", &imp_clk), |
| 167 | CLKDEV_CON_ID("rclk", &rclk_clk), |
| 168 | CLKDEV_CON_ID("oscclk", &oscclk_clk), |
| 169 | CLKDEV_CON_ID("zb3", &zb3_clk), |
| 170 | CLKDEV_CON_ID("zb3d2", &zb3d2_clk), |
| 171 | CLKDEV_CON_ID("ddr", &ddr_clk), |
| 172 | CLKDEV_CON_ID("mp", &mp_clk), |
| 173 | CLKDEV_CON_ID("qspi", &qspi_clk), |
| 174 | CLKDEV_CON_ID("cp", &cp_clk), |
| 175 | |
| 176 | /* MSTP */ |
Magnus Damm | 55d9fab | 2013-03-28 00:49:44 +0900 | [diff] [blame] | 177 | CLKDEV_DEV_ID("sh-sci.0", &mstp_clks[MSTP204]), |
| 178 | CLKDEV_DEV_ID("sh-sci.1", &mstp_clks[MSTP203]), |
| 179 | CLKDEV_DEV_ID("sh-sci.2", &mstp_clks[MSTP206]), |
| 180 | CLKDEV_DEV_ID("sh-sci.3", &mstp_clks[MSTP207]), |
| 181 | CLKDEV_DEV_ID("sh-sci.4", &mstp_clks[MSTP216]), |
| 182 | CLKDEV_DEV_ID("sh-sci.5", &mstp_clks[MSTP202]), |
| 183 | CLKDEV_DEV_ID("sh-sci.6", &mstp_clks[MSTP721]), |
| 184 | CLKDEV_DEV_ID("sh-sci.7", &mstp_clks[MSTP720]), |
Magnus Damm | 0468b2d | 2013-03-28 00:49:34 +0900 | [diff] [blame] | 185 | }; |
| 186 | |
Kuninori Morimoto | 8d100c0 | 2013-04-12 00:42:22 -0700 | [diff] [blame^] | 187 | #define R8A7790_CLOCK_ROOT(e, m, p0, p1, p30, p31) \ |
| 188 | extal_clk.rate = e * 1000 * 1000; \ |
| 189 | main_clk.parent = m; \ |
| 190 | SH_CLK_SET_RATIO(&pll1_clk_ratio, p1 / 2, 1); \ |
| 191 | if (mode & MD(19)) \ |
| 192 | SH_CLK_SET_RATIO(&pll3_clk_ratio, p31, 1); \ |
| 193 | else \ |
| 194 | SH_CLK_SET_RATIO(&pll3_clk_ratio, p30, 1) |
| 195 | |
| 196 | |
Magnus Damm | 0468b2d | 2013-03-28 00:49:34 +0900 | [diff] [blame] | 197 | void __init r8a7790_clock_init(void) |
| 198 | { |
Kuninori Morimoto | 8d100c0 | 2013-04-12 00:42:22 -0700 | [diff] [blame^] | 199 | void __iomem *modemr = ioremap_nocache(MODEMR, PAGE_SIZE); |
| 200 | u32 mode; |
Magnus Damm | 0468b2d | 2013-03-28 00:49:34 +0900 | [diff] [blame] | 201 | int k, ret = 0; |
| 202 | |
Kuninori Morimoto | 8d100c0 | 2013-04-12 00:42:22 -0700 | [diff] [blame^] | 203 | BUG_ON(!modemr); |
| 204 | mode = ioread32(modemr); |
| 205 | iounmap(modemr); |
| 206 | |
| 207 | switch (mode & (MD(14) | MD(13))) { |
| 208 | case 0: |
| 209 | R8A7790_CLOCK_ROOT(15, &extal_clk, 172, 208, 106, 88); |
| 210 | break; |
| 211 | case MD(13): |
| 212 | R8A7790_CLOCK_ROOT(20, &extal_clk, 130, 156, 80, 66); |
| 213 | break; |
| 214 | case MD(14): |
| 215 | R8A7790_CLOCK_ROOT(26, &extal_div2_clk, 200, 240, 122, 102); |
| 216 | break; |
| 217 | case MD(13) | MD(14): |
| 218 | R8A7790_CLOCK_ROOT(30, &extal_div2_clk, 172, 208, 106, 88); |
| 219 | break; |
| 220 | } |
| 221 | |
| 222 | if (mode & (MD(18))) |
| 223 | SH_CLK_SET_RATIO(&lb_clk_ratio, 1, 36); |
| 224 | else |
| 225 | SH_CLK_SET_RATIO(&lb_clk_ratio, 1, 24); |
| 226 | |
| 227 | if ((mode & (MD(3) | MD(2) | MD(1))) == MD(2)) |
| 228 | SH_CLK_SET_RATIO(&qspi_clk_ratio, 1, 16); |
| 229 | else |
| 230 | SH_CLK_SET_RATIO(&qspi_clk_ratio, 1, 20); |
| 231 | |
Magnus Damm | 0468b2d | 2013-03-28 00:49:34 +0900 | [diff] [blame] | 232 | for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++) |
| 233 | ret = clk_register(main_clks[k]); |
| 234 | |
| 235 | if (!ret) |
| 236 | ret = sh_clk_mstp_register(mstp_clks, MSTP_NR); |
| 237 | |
| 238 | clkdev_add_table(lookups, ARRAY_SIZE(lookups)); |
| 239 | |
| 240 | if (!ret) |
| 241 | shmobile_clk_init(); |
| 242 | else |
| 243 | panic("failed to setup r8a7790 clocks\n"); |
| 244 | } |