Magnus Damm | eccf060 | 2013-03-26 10:34:24 +0900 | [diff] [blame] | 1 | /* |
| 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 Morimoto | 5e634d9 | 2013-04-04 21:20:40 -0700 | [diff] [blame^] | 25 | #include <mach/clock.h> |
Magnus Damm | eccf060 | 2013-03-26 10:34:24 +0900 | [diff] [blame] | 26 | #include <mach/common.h> |
| 27 | |
| 28 | #define CPG_BASE 0xe6150000 |
| 29 | #define CPG_LEN 0x270 |
| 30 | |
| 31 | #define MPCKCR 0xe6150080 |
Magnus Damm | e481a52 | 2013-03-26 10:34:33 +0900 | [diff] [blame] | 32 | #define SMSTPCR2 0xe6150138 |
Kuninori Morimoto | c91cf2f | 2013-03-25 23:18:15 -0700 | [diff] [blame] | 33 | #define SMSTPCR5 0xe6150144 |
Magnus Damm | eccf060 | 2013-03-26 10:34:24 +0900 | [diff] [blame] | 34 | |
Kuninori Morimoto | 5e634d9 | 2013-04-04 21:20:40 -0700 | [diff] [blame^] | 35 | #define CKSCR 0xE61500C0 |
| 36 | |
Magnus Damm | eccf060 | 2013-03-26 10:34:24 +0900 | [diff] [blame] | 37 | static struct clk_mapping cpg_mapping = { |
| 38 | .phys = CPG_BASE, |
| 39 | .len = CPG_LEN, |
| 40 | }; |
| 41 | |
| 42 | static struct clk extalr_clk = { |
| 43 | .rate = 32768, |
| 44 | .mapping = &cpg_mapping, |
| 45 | }; |
| 46 | |
| 47 | static struct clk extal1_clk = { |
| 48 | .rate = 26000000, |
| 49 | .mapping = &cpg_mapping, |
| 50 | }; |
| 51 | |
| 52 | static struct clk extal2_clk = { |
| 53 | .rate = 48000000, |
| 54 | .mapping = &cpg_mapping, |
| 55 | }; |
| 56 | |
Kuninori Morimoto | 5e634d9 | 2013-04-04 21:20:40 -0700 | [diff] [blame^] | 57 | static struct sh_clk_ops followparent_clk_ops = { |
| 58 | .recalc = followparent_recalc, |
| 59 | }; |
| 60 | |
| 61 | static struct clk main_clk = { |
| 62 | /* .parent will be set r8a73a4_clock_init */ |
| 63 | .ops = &followparent_clk_ops, |
| 64 | }; |
| 65 | |
| 66 | SH_CLK_RATIO(div2, 1, 2); |
| 67 | SH_CLK_RATIO(div4, 1, 4); |
| 68 | |
| 69 | SH_FIXED_RATIO_CLK(main_div2_clk, main_clk, div2); |
| 70 | SH_FIXED_RATIO_CLK(extal1_div2_clk, extal1_clk, div2); |
| 71 | SH_FIXED_RATIO_CLK(extal2_div2_clk, extal2_clk, div2); |
| 72 | SH_FIXED_RATIO_CLK(extal2_div4_clk, extal2_clk, div4); |
| 73 | |
Magnus Damm | eccf060 | 2013-03-26 10:34:24 +0900 | [diff] [blame] | 74 | static struct clk *main_clks[] = { |
| 75 | &extalr_clk, |
| 76 | &extal1_clk, |
Kuninori Morimoto | 5e634d9 | 2013-04-04 21:20:40 -0700 | [diff] [blame^] | 77 | &extal1_div2_clk, |
Magnus Damm | eccf060 | 2013-03-26 10:34:24 +0900 | [diff] [blame] | 78 | &extal2_clk, |
Kuninori Morimoto | 5e634d9 | 2013-04-04 21:20:40 -0700 | [diff] [blame^] | 79 | &extal2_div2_clk, |
| 80 | &extal2_div4_clk, |
| 81 | &main_clk, |
| 82 | &main_div2_clk, |
Magnus Damm | eccf060 | 2013-03-26 10:34:24 +0900 | [diff] [blame] | 83 | }; |
| 84 | |
Kuninori Morimoto | c91cf2f | 2013-03-25 23:18:15 -0700 | [diff] [blame] | 85 | enum { |
| 86 | MSTP217, MSTP216, MSTP207, MSTP206, MSTP204, MSTP203, |
| 87 | MSTP522, |
| 88 | MSTP_NR |
| 89 | }; |
| 90 | |
Magnus Damm | eccf060 | 2013-03-26 10:34:24 +0900 | [diff] [blame] | 91 | static struct clk mstp_clks[MSTP_NR] = { |
Magnus Damm | e481a52 | 2013-03-26 10:34:33 +0900 | [diff] [blame] | 92 | [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 Morimoto | c91cf2f | 2013-03-25 23:18:15 -0700 | [diff] [blame] | 98 | [MSTP522] = SH_CLK_MSTP32(&extal2_clk, SMSTPCR5, 22, 0), /* Thermal */ |
Magnus Damm | eccf060 | 2013-03-26 10:34:24 +0900 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | static struct clk_lookup lookups[] = { |
Kuninori Morimoto | 5e634d9 | 2013-04-04 21:20:40 -0700 | [diff] [blame^] | 102 | /* 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 Damm | e481a52 | 2013-03-26 10:34:33 +0900 | [diff] [blame] | 109 | 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 Morimoto | c91cf2f | 2013-03-25 23:18:15 -0700 | [diff] [blame] | 115 | CLKDEV_DEV_ID("rcar_thermal", &mstp_clks[MSTP522]), |
| 116 | |
| 117 | /* for DT */ |
| 118 | CLKDEV_DEV_ID("e61f0000.thermal", &mstp_clks[MSTP522]), |
Magnus Damm | eccf060 | 2013-03-26 10:34:24 +0900 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | void __init r8a73a4_clock_init(void) |
| 122 | { |
| 123 | void __iomem *cpg_base, *reg; |
| 124 | int k, ret = 0; |
Kuninori Morimoto | 5e634d9 | 2013-04-04 21:20:40 -0700 | [diff] [blame^] | 125 | u32 ckscr; |
Magnus Damm | eccf060 | 2013-03-26 10:34:24 +0900 | [diff] [blame] | 126 | |
| 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 Morimoto | 5e634d9 | 2013-04-04 21:20:40 -0700 | [diff] [blame^] | 136 | 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 Damm | eccf060 | 2013-03-26 10:34:24 +0900 | [diff] [blame] | 156 | 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 | } |