clk-nsp.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright (C) 2015 Broadcom Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation version 2.
  7. *
  8. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  9. * kind, whether express or implied; without even the implied warranty
  10. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/err.h>
  15. #include <linux/clk-provider.h>
  16. #include <linux/io.h>
  17. #include <linux/of.h>
  18. #include <linux/of_address.h>
  19. #include <dt-bindings/clock/bcm-nsp.h>
  20. #include "clk-iproc.h"
  21. #define REG_VAL(o, s, w) { .offset = o, .shift = s, .width = w, }
  22. #define AON_VAL(o, pw, ps, is) { .offset = o, .pwr_width = pw, \
  23. .pwr_shift = ps, .iso_shift = is }
  24. #define RESET_VAL(o, rs, prs) { .offset = o, .reset_shift = rs, \
  25. .p_reset_shift = prs }
  26. #define DF_VAL(o, kis, kiw, kps, kpw, kas, kaw) { .offset = o, .ki_shift = kis,\
  27. .ki_width = kiw, .kp_shift = kps, .kp_width = kpw, .ka_shift = kas, \
  28. .ka_width = kaw }
  29. #define ENABLE_VAL(o, es, hs, bs) { .offset = o, .enable_shift = es, \
  30. .hold_shift = hs, .bypass_shift = bs }
  31. static void __init nsp_armpll_init(struct device_node *node)
  32. {
  33. iproc_armpll_setup(node);
  34. }
  35. CLK_OF_DECLARE(nsp_armpll, "brcm,nsp-armpll", nsp_armpll_init);
  36. static const struct iproc_pll_ctrl genpll = {
  37. .flags = IPROC_CLK_PLL_HAS_NDIV_FRAC | IPROC_CLK_EMBED_PWRCTRL,
  38. .aon = AON_VAL(0x0, 1, 12, 0),
  39. .reset = RESET_VAL(0x0, 11, 10),
  40. .dig_filter = DF_VAL(0x0, 4, 3, 0, 4, 7, 3),
  41. .ndiv_int = REG_VAL(0x14, 20, 10),
  42. .ndiv_frac = REG_VAL(0x14, 0, 20),
  43. .pdiv = REG_VAL(0x18, 24, 3),
  44. .status = REG_VAL(0x20, 12, 1),
  45. };
  46. static const struct iproc_clk_ctrl genpll_clk[] = {
  47. [BCM_NSP_GENPLL_PHY_CLK] = {
  48. .channel = BCM_NSP_GENPLL_PHY_CLK,
  49. .flags = IPROC_CLK_AON,
  50. .enable = ENABLE_VAL(0x4, 12, 6, 18),
  51. .mdiv = REG_VAL(0x18, 16, 8),
  52. },
  53. [BCM_NSP_GENPLL_ENET_SW_CLK] = {
  54. .channel = BCM_NSP_GENPLL_ENET_SW_CLK,
  55. .flags = IPROC_CLK_AON,
  56. .enable = ENABLE_VAL(0x4, 13, 7, 19),
  57. .mdiv = REG_VAL(0x18, 8, 8),
  58. },
  59. [BCM_NSP_GENPLL_USB_PHY_REF_CLK] = {
  60. .channel = BCM_NSP_GENPLL_USB_PHY_REF_CLK,
  61. .flags = IPROC_CLK_AON,
  62. .enable = ENABLE_VAL(0x4, 14, 8, 20),
  63. .mdiv = REG_VAL(0x18, 0, 8),
  64. },
  65. [BCM_NSP_GENPLL_IPROCFAST_CLK] = {
  66. .channel = BCM_NSP_GENPLL_IPROCFAST_CLK,
  67. .flags = IPROC_CLK_AON,
  68. .enable = ENABLE_VAL(0x4, 15, 9, 21),
  69. .mdiv = REG_VAL(0x1c, 16, 8),
  70. },
  71. [BCM_NSP_GENPLL_SATA1_CLK] = {
  72. .channel = BCM_NSP_GENPLL_SATA1_CLK,
  73. .flags = IPROC_CLK_AON,
  74. .enable = ENABLE_VAL(0x4, 16, 10, 22),
  75. .mdiv = REG_VAL(0x1c, 8, 8),
  76. },
  77. [BCM_NSP_GENPLL_SATA2_CLK] = {
  78. .channel = BCM_NSP_GENPLL_SATA2_CLK,
  79. .flags = IPROC_CLK_AON,
  80. .enable = ENABLE_VAL(0x4, 17, 11, 23),
  81. .mdiv = REG_VAL(0x1c, 0, 8),
  82. },
  83. };
  84. static void __init nsp_genpll_clk_init(struct device_node *node)
  85. {
  86. iproc_pll_clk_setup(node, &genpll, NULL, 0, genpll_clk,
  87. ARRAY_SIZE(genpll_clk));
  88. }
  89. CLK_OF_DECLARE(nsp_genpll_clk, "brcm,nsp-genpll", nsp_genpll_clk_init);
  90. static const struct iproc_pll_ctrl lcpll0 = {
  91. .flags = IPROC_CLK_PLL_HAS_NDIV_FRAC | IPROC_CLK_EMBED_PWRCTRL,
  92. .aon = AON_VAL(0x0, 1, 24, 0),
  93. .reset = RESET_VAL(0x0, 23, 22),
  94. .dig_filter = DF_VAL(0x0, 16, 3, 12, 4, 19, 4),
  95. .ndiv_int = REG_VAL(0x4, 20, 8),
  96. .ndiv_frac = REG_VAL(0x4, 0, 20),
  97. .pdiv = REG_VAL(0x4, 28, 3),
  98. .status = REG_VAL(0x10, 12, 1),
  99. };
  100. static const struct iproc_clk_ctrl lcpll0_clk[] = {
  101. [BCM_NSP_LCPLL0_PCIE_PHY_REF_CLK] = {
  102. .channel = BCM_NSP_LCPLL0_PCIE_PHY_REF_CLK,
  103. .flags = IPROC_CLK_AON,
  104. .enable = ENABLE_VAL(0x0, 6, 3, 9),
  105. .mdiv = REG_VAL(0x8, 24, 8),
  106. },
  107. [BCM_NSP_LCPLL0_SDIO_CLK] = {
  108. .channel = BCM_NSP_LCPLL0_SDIO_CLK,
  109. .flags = IPROC_CLK_AON,
  110. .enable = ENABLE_VAL(0x0, 7, 4, 10),
  111. .mdiv = REG_VAL(0x8, 16, 8),
  112. },
  113. [BCM_NSP_LCPLL0_DDR_PHY_CLK] = {
  114. .channel = BCM_NSP_LCPLL0_DDR_PHY_CLK,
  115. .flags = IPROC_CLK_AON,
  116. .enable = ENABLE_VAL(0x0, 8, 5, 11),
  117. .mdiv = REG_VAL(0x8, 8, 8),
  118. },
  119. };
  120. static void __init nsp_lcpll0_clk_init(struct device_node *node)
  121. {
  122. iproc_pll_clk_setup(node, &lcpll0, NULL, 0, lcpll0_clk,
  123. ARRAY_SIZE(lcpll0_clk));
  124. }
  125. CLK_OF_DECLARE(nsp_lcpll0_clk, "brcm,nsp-lcpll0", nsp_lcpll0_clk_init);