clock-r8a73a4.c 3.2 KB

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