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> |
| 25 | #include <mach/common.h> |
| 26 | |
| 27 | #define CPG_BASE 0xe6150000 |
| 28 | #define CPG_LEN 0x270 |
| 29 | |
| 30 | #define MPCKCR 0xe6150080 |
Magnus Damm | e481a52 | 2013-03-26 10:34:33 +0900 | [diff] [blame^] | 31 | #define SMSTPCR2 0xe6150138 |
Magnus Damm | eccf060 | 2013-03-26 10:34:24 +0900 | [diff] [blame] | 32 | |
| 33 | static struct clk_mapping cpg_mapping = { |
| 34 | .phys = CPG_BASE, |
| 35 | .len = CPG_LEN, |
| 36 | }; |
| 37 | |
| 38 | static struct clk extalr_clk = { |
| 39 | .rate = 32768, |
| 40 | .mapping = &cpg_mapping, |
| 41 | }; |
| 42 | |
| 43 | static struct clk extal1_clk = { |
| 44 | .rate = 26000000, |
| 45 | .mapping = &cpg_mapping, |
| 46 | }; |
| 47 | |
| 48 | static struct clk extal2_clk = { |
| 49 | .rate = 48000000, |
| 50 | .mapping = &cpg_mapping, |
| 51 | }; |
| 52 | |
| 53 | static struct clk *main_clks[] = { |
| 54 | &extalr_clk, |
| 55 | &extal1_clk, |
| 56 | &extal2_clk, |
| 57 | }; |
| 58 | |
Magnus Damm | e481a52 | 2013-03-26 10:34:33 +0900 | [diff] [blame^] | 59 | enum { MSTP217, MSTP216, MSTP207, MSTP206, MSTP204, MSTP203, MSTP_NR }; |
Magnus Damm | eccf060 | 2013-03-26 10:34:24 +0900 | [diff] [blame] | 60 | static struct clk mstp_clks[MSTP_NR] = { |
Magnus Damm | e481a52 | 2013-03-26 10:34:33 +0900 | [diff] [blame^] | 61 | [MSTP204] = SH_CLK_MSTP32(&extal2_clk, SMSTPCR2, 4, 0), /* SCIFA0 */ |
| 62 | [MSTP203] = SH_CLK_MSTP32(&extal2_clk, SMSTPCR2, 3, 0), /* SCIFA1 */ |
| 63 | [MSTP206] = SH_CLK_MSTP32(&extal2_clk, SMSTPCR2, 6, 0), /* SCIFB0 */ |
| 64 | [MSTP207] = SH_CLK_MSTP32(&extal2_clk, SMSTPCR2, 7, 0), /* SCIFB1 */ |
| 65 | [MSTP216] = SH_CLK_MSTP32(&extal2_clk, SMSTPCR2, 16, 0), /* SCIFB2 */ |
| 66 | [MSTP217] = SH_CLK_MSTP32(&extal2_clk, SMSTPCR2, 17, 0), /* SCIFB3 */ |
Magnus Damm | eccf060 | 2013-03-26 10:34:24 +0900 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | static struct clk_lookup lookups[] = { |
Magnus Damm | e481a52 | 2013-03-26 10:34:33 +0900 | [diff] [blame^] | 70 | CLKDEV_DEV_ID("sh-sci.0", &mstp_clks[MSTP204]), |
| 71 | CLKDEV_DEV_ID("sh-sci.1", &mstp_clks[MSTP203]), |
| 72 | CLKDEV_DEV_ID("sh-sci.2", &mstp_clks[MSTP206]), |
| 73 | CLKDEV_DEV_ID("sh-sci.3", &mstp_clks[MSTP207]), |
| 74 | CLKDEV_DEV_ID("sh-sci.4", &mstp_clks[MSTP216]), |
| 75 | CLKDEV_DEV_ID("sh-sci.5", &mstp_clks[MSTP217]), |
Magnus Damm | eccf060 | 2013-03-26 10:34:24 +0900 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | void __init r8a73a4_clock_init(void) |
| 79 | { |
| 80 | void __iomem *cpg_base, *reg; |
| 81 | int k, ret = 0; |
| 82 | |
| 83 | /* fix MPCLK to EXTAL2 for now. |
| 84 | * this is needed until more detailed clock topology is supported |
| 85 | */ |
| 86 | cpg_base = ioremap_nocache(CPG_BASE, CPG_LEN); |
| 87 | BUG_ON(!cpg_base); |
| 88 | reg = cpg_base + (MPCKCR - CPG_BASE); |
| 89 | iowrite32(ioread32(reg) | 1 << 7 | 0x0c, reg); /* set CKSEL */ |
| 90 | iounmap(cpg_base); |
| 91 | |
| 92 | for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++) |
| 93 | ret = clk_register(main_clks[k]); |
| 94 | |
| 95 | if (!ret) |
| 96 | ret = sh_clk_mstp_register(mstp_clks, MSTP_NR); |
| 97 | |
| 98 | clkdev_add_table(lookups, ARRAY_SIZE(lookups)); |
| 99 | |
| 100 | if (!ret) |
| 101 | shmobile_clk_init(); |
| 102 | else |
| 103 | panic("failed to setup r8a73a4 clocks\n"); |
| 104 | } |