clk-emev2.c 2.6 KB

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