clk-emev2.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * EMMA Mobile EV2 common clock framework support
  3. *
  4. * Copyright (C) 2013 Takashi Yoshii <takashi.yoshii.ze@renesas.com>
  5. * Copyright (C) 2012 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/clk-provider.h>
  21. #include <linux/clkdev.h>
  22. #include <linux/io.h>
  23. #include <linux/of.h>
  24. #include <linux/of_address.h>
  25. /* EMEV2 SMU registers */
  26. #define USIAU0_RSTCTRL 0x094
  27. #define USIBU1_RSTCTRL 0x0ac
  28. #define USIBU2_RSTCTRL 0x0b0
  29. #define USIBU3_RSTCTRL 0x0b4
  30. #define IIC0_RSTCTRL 0x0dc
  31. #define IIC1_RSTCTRL 0x0e0
  32. #define STI_RSTCTRL 0x124
  33. #define STI_CLKSEL 0x688
  34. static DEFINE_SPINLOCK(lock);
  35. /* not pretty, but hey */
  36. static void __iomem *smu_base;
  37. static void __init emev2_smu_write(unsigned long value, int offs)
  38. {
  39. BUG_ON(!smu_base || (offs >= PAGE_SIZE));
  40. writel_relaxed(value, smu_base + offs);
  41. }
  42. static const struct of_device_id smu_id[] __initconst = {
  43. { .compatible = "renesas,emev2-smu", },
  44. {},
  45. };
  46. static void __init emev2_smu_init(void)
  47. {
  48. struct device_node *np;
  49. np = of_find_matching_node(NULL, smu_id);
  50. BUG_ON(!np);
  51. smu_base = of_iomap(np, 0);
  52. BUG_ON(!smu_base);
  53. of_node_put(np);
  54. /* setup STI timer to run on 32.768 kHz and deassert reset */
  55. emev2_smu_write(0, STI_CLKSEL);
  56. emev2_smu_write(1, STI_RSTCTRL);
  57. /* deassert reset for UART0->UART3 */
  58. emev2_smu_write(2, USIAU0_RSTCTRL);
  59. emev2_smu_write(2, USIBU1_RSTCTRL);
  60. emev2_smu_write(2, USIBU2_RSTCTRL);
  61. emev2_smu_write(2, USIBU3_RSTCTRL);
  62. /* deassert reset for IIC0->IIC1 */
  63. emev2_smu_write(1, IIC0_RSTCTRL);
  64. emev2_smu_write(1, IIC1_RSTCTRL);
  65. }
  66. static void __init emev2_smu_clkdiv_init(struct device_node *np)
  67. {
  68. u32 reg[2];
  69. struct clk *clk;
  70. const char *parent_name = of_clk_get_parent_name(np, 0);
  71. if (WARN_ON(of_property_read_u32_array(np, "reg", reg, 2)))
  72. return;
  73. if (!smu_base)
  74. emev2_smu_init();
  75. clk = clk_register_divider(NULL, np->name, parent_name, 0,
  76. smu_base + reg[0], reg[1], 8, 0, &lock);
  77. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  78. clk_register_clkdev(clk, np->name, NULL);
  79. pr_debug("## %s %s %p\n", __func__, np->name, clk);
  80. }
  81. CLK_OF_DECLARE(emev2_smu_clkdiv, "renesas,emev2-smu-clkdiv",
  82. emev2_smu_clkdiv_init);
  83. static void __init emev2_smu_gclk_init(struct device_node *np)
  84. {
  85. u32 reg[2];
  86. struct clk *clk;
  87. const char *parent_name = of_clk_get_parent_name(np, 0);
  88. if (WARN_ON(of_property_read_u32_array(np, "reg", reg, 2)))
  89. return;
  90. if (!smu_base)
  91. emev2_smu_init();
  92. clk = clk_register_gate(NULL, np->name, parent_name, 0,
  93. smu_base + reg[0], reg[1], 0, &lock);
  94. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  95. clk_register_clkdev(clk, np->name, NULL);
  96. pr_debug("## %s %s %p\n", __func__, np->name, clk);
  97. }
  98. CLK_OF_DECLARE(emev2_smu_gclk, "renesas,emev2-smu-gclk", emev2_smu_gclk_init);