clock-r8a73a4.c 2.9 KB

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