ccu-sun9i-a80-de.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016 Chen-Yu Tsai. All rights reserved.
  4. */
  5. #include <linux/clk.h>
  6. #include <linux/clk-provider.h>
  7. #include <linux/module.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/reset.h>
  10. #include "ccu_common.h"
  11. #include "ccu_div.h"
  12. #include "ccu_gate.h"
  13. #include "ccu_reset.h"
  14. #include "ccu-sun9i-a80-de.h"
  15. static SUNXI_CCU_GATE(fe0_clk, "fe0", "fe0-div",
  16. 0x00, BIT(0), 0);
  17. static SUNXI_CCU_GATE(fe1_clk, "fe1", "fe1-div",
  18. 0x00, BIT(1), 0);
  19. static SUNXI_CCU_GATE(fe2_clk, "fe2", "fe2-div",
  20. 0x00, BIT(2), 0);
  21. static SUNXI_CCU_GATE(iep_deu0_clk, "iep-deu0", "de",
  22. 0x00, BIT(4), 0);
  23. static SUNXI_CCU_GATE(iep_deu1_clk, "iep-deu1", "de",
  24. 0x00, BIT(5), 0);
  25. static SUNXI_CCU_GATE(be0_clk, "be0", "be0-div",
  26. 0x00, BIT(8), 0);
  27. static SUNXI_CCU_GATE(be1_clk, "be1", "be1-div",
  28. 0x00, BIT(9), 0);
  29. static SUNXI_CCU_GATE(be2_clk, "be2", "be2-div",
  30. 0x00, BIT(10), 0);
  31. static SUNXI_CCU_GATE(iep_drc0_clk, "iep-drc0", "de",
  32. 0x00, BIT(12), 0);
  33. static SUNXI_CCU_GATE(iep_drc1_clk, "iep-drc1", "de",
  34. 0x00, BIT(13), 0);
  35. static SUNXI_CCU_GATE(merge_clk, "merge", "de",
  36. 0x00, BIT(20), 0);
  37. static SUNXI_CCU_GATE(dram_fe0_clk, "dram-fe0", "sdram",
  38. 0x04, BIT(0), 0);
  39. static SUNXI_CCU_GATE(dram_fe1_clk, "dram-fe1", "sdram",
  40. 0x04, BIT(1), 0);
  41. static SUNXI_CCU_GATE(dram_fe2_clk, "dram-fe2", "sdram",
  42. 0x04, BIT(2), 0);
  43. static SUNXI_CCU_GATE(dram_deu0_clk, "dram-deu0", "sdram",
  44. 0x04, BIT(4), 0);
  45. static SUNXI_CCU_GATE(dram_deu1_clk, "dram-deu1", "sdram",
  46. 0x04, BIT(5), 0);
  47. static SUNXI_CCU_GATE(dram_be0_clk, "dram-be0", "sdram",
  48. 0x04, BIT(8), 0);
  49. static SUNXI_CCU_GATE(dram_be1_clk, "dram-be1", "sdram",
  50. 0x04, BIT(9), 0);
  51. static SUNXI_CCU_GATE(dram_be2_clk, "dram-be2", "sdram",
  52. 0x04, BIT(10), 0);
  53. static SUNXI_CCU_GATE(dram_drc0_clk, "dram-drc0", "sdram",
  54. 0x04, BIT(12), 0);
  55. static SUNXI_CCU_GATE(dram_drc1_clk, "dram-drc1", "sdram",
  56. 0x04, BIT(13), 0);
  57. static SUNXI_CCU_GATE(bus_fe0_clk, "bus-fe0", "bus-de",
  58. 0x08, BIT(0), 0);
  59. static SUNXI_CCU_GATE(bus_fe1_clk, "bus-fe1", "bus-de",
  60. 0x08, BIT(1), 0);
  61. static SUNXI_CCU_GATE(bus_fe2_clk, "bus-fe2", "bus-de",
  62. 0x08, BIT(2), 0);
  63. static SUNXI_CCU_GATE(bus_deu0_clk, "bus-deu0", "bus-de",
  64. 0x08, BIT(4), 0);
  65. static SUNXI_CCU_GATE(bus_deu1_clk, "bus-deu1", "bus-de",
  66. 0x08, BIT(5), 0);
  67. static SUNXI_CCU_GATE(bus_be0_clk, "bus-be0", "bus-de",
  68. 0x08, BIT(8), 0);
  69. static SUNXI_CCU_GATE(bus_be1_clk, "bus-be1", "bus-de",
  70. 0x08, BIT(9), 0);
  71. static SUNXI_CCU_GATE(bus_be2_clk, "bus-be2", "bus-de",
  72. 0x08, BIT(10), 0);
  73. static SUNXI_CCU_GATE(bus_drc0_clk, "bus-drc0", "bus-de",
  74. 0x08, BIT(12), 0);
  75. static SUNXI_CCU_GATE(bus_drc1_clk, "bus-drc1", "bus-de",
  76. 0x08, BIT(13), 0);
  77. static SUNXI_CCU_M(fe0_div_clk, "fe0-div", "de", 0x20, 0, 4, 0);
  78. static SUNXI_CCU_M(fe1_div_clk, "fe1-div", "de", 0x20, 4, 4, 0);
  79. static SUNXI_CCU_M(fe2_div_clk, "fe2-div", "de", 0x20, 8, 4, 0);
  80. static SUNXI_CCU_M(be0_div_clk, "be0-div", "de", 0x20, 16, 4, 0);
  81. static SUNXI_CCU_M(be1_div_clk, "be1-div", "de", 0x20, 20, 4, 0);
  82. static SUNXI_CCU_M(be2_div_clk, "be2-div", "de", 0x20, 24, 4, 0);
  83. static struct ccu_common *sun9i_a80_de_clks[] = {
  84. &fe0_clk.common,
  85. &fe1_clk.common,
  86. &fe2_clk.common,
  87. &iep_deu0_clk.common,
  88. &iep_deu1_clk.common,
  89. &be0_clk.common,
  90. &be1_clk.common,
  91. &be2_clk.common,
  92. &iep_drc0_clk.common,
  93. &iep_drc1_clk.common,
  94. &merge_clk.common,
  95. &dram_fe0_clk.common,
  96. &dram_fe1_clk.common,
  97. &dram_fe2_clk.common,
  98. &dram_deu0_clk.common,
  99. &dram_deu1_clk.common,
  100. &dram_be0_clk.common,
  101. &dram_be1_clk.common,
  102. &dram_be2_clk.common,
  103. &dram_drc0_clk.common,
  104. &dram_drc1_clk.common,
  105. &bus_fe0_clk.common,
  106. &bus_fe1_clk.common,
  107. &bus_fe2_clk.common,
  108. &bus_deu0_clk.common,
  109. &bus_deu1_clk.common,
  110. &bus_be0_clk.common,
  111. &bus_be1_clk.common,
  112. &bus_be2_clk.common,
  113. &bus_drc0_clk.common,
  114. &bus_drc1_clk.common,
  115. &fe0_div_clk.common,
  116. &fe1_div_clk.common,
  117. &fe2_div_clk.common,
  118. &be0_div_clk.common,
  119. &be1_div_clk.common,
  120. &be2_div_clk.common,
  121. };
  122. static struct clk_hw_onecell_data sun9i_a80_de_hw_clks = {
  123. .hws = {
  124. [CLK_FE0] = &fe0_clk.common.hw,
  125. [CLK_FE1] = &fe1_clk.common.hw,
  126. [CLK_FE2] = &fe2_clk.common.hw,
  127. [CLK_IEP_DEU0] = &iep_deu0_clk.common.hw,
  128. [CLK_IEP_DEU1] = &iep_deu1_clk.common.hw,
  129. [CLK_BE0] = &be0_clk.common.hw,
  130. [CLK_BE1] = &be1_clk.common.hw,
  131. [CLK_BE2] = &be2_clk.common.hw,
  132. [CLK_IEP_DRC0] = &iep_drc0_clk.common.hw,
  133. [CLK_IEP_DRC1] = &iep_drc1_clk.common.hw,
  134. [CLK_MERGE] = &merge_clk.common.hw,
  135. [CLK_DRAM_FE0] = &dram_fe0_clk.common.hw,
  136. [CLK_DRAM_FE1] = &dram_fe1_clk.common.hw,
  137. [CLK_DRAM_FE2] = &dram_fe2_clk.common.hw,
  138. [CLK_DRAM_DEU0] = &dram_deu0_clk.common.hw,
  139. [CLK_DRAM_DEU1] = &dram_deu1_clk.common.hw,
  140. [CLK_DRAM_BE0] = &dram_be0_clk.common.hw,
  141. [CLK_DRAM_BE1] = &dram_be1_clk.common.hw,
  142. [CLK_DRAM_BE2] = &dram_be2_clk.common.hw,
  143. [CLK_DRAM_DRC0] = &dram_drc0_clk.common.hw,
  144. [CLK_DRAM_DRC1] = &dram_drc1_clk.common.hw,
  145. [CLK_BUS_FE0] = &bus_fe0_clk.common.hw,
  146. [CLK_BUS_FE1] = &bus_fe1_clk.common.hw,
  147. [CLK_BUS_FE2] = &bus_fe2_clk.common.hw,
  148. [CLK_BUS_DEU0] = &bus_deu0_clk.common.hw,
  149. [CLK_BUS_DEU1] = &bus_deu1_clk.common.hw,
  150. [CLK_BUS_BE0] = &bus_be0_clk.common.hw,
  151. [CLK_BUS_BE1] = &bus_be1_clk.common.hw,
  152. [CLK_BUS_BE2] = &bus_be2_clk.common.hw,
  153. [CLK_BUS_DRC0] = &bus_drc0_clk.common.hw,
  154. [CLK_BUS_DRC1] = &bus_drc1_clk.common.hw,
  155. [CLK_FE0_DIV] = &fe0_div_clk.common.hw,
  156. [CLK_FE1_DIV] = &fe1_div_clk.common.hw,
  157. [CLK_FE2_DIV] = &fe2_div_clk.common.hw,
  158. [CLK_BE0_DIV] = &be0_div_clk.common.hw,
  159. [CLK_BE1_DIV] = &be1_div_clk.common.hw,
  160. [CLK_BE2_DIV] = &be2_div_clk.common.hw,
  161. },
  162. .num = CLK_NUMBER,
  163. };
  164. static struct ccu_reset_map sun9i_a80_de_resets[] = {
  165. [RST_FE0] = { 0x0c, BIT(0) },
  166. [RST_FE1] = { 0x0c, BIT(1) },
  167. [RST_FE2] = { 0x0c, BIT(2) },
  168. [RST_DEU0] = { 0x0c, BIT(4) },
  169. [RST_DEU1] = { 0x0c, BIT(5) },
  170. [RST_BE0] = { 0x0c, BIT(8) },
  171. [RST_BE1] = { 0x0c, BIT(9) },
  172. [RST_BE2] = { 0x0c, BIT(10) },
  173. [RST_DRC0] = { 0x0c, BIT(12) },
  174. [RST_DRC1] = { 0x0c, BIT(13) },
  175. [RST_MERGE] = { 0x0c, BIT(20) },
  176. };
  177. static const struct sunxi_ccu_desc sun9i_a80_de_clk_desc = {
  178. .ccu_clks = sun9i_a80_de_clks,
  179. .num_ccu_clks = ARRAY_SIZE(sun9i_a80_de_clks),
  180. .hw_clks = &sun9i_a80_de_hw_clks,
  181. .resets = sun9i_a80_de_resets,
  182. .num_resets = ARRAY_SIZE(sun9i_a80_de_resets),
  183. };
  184. static int sun9i_a80_de_clk_probe(struct platform_device *pdev)
  185. {
  186. struct clk *bus_clk;
  187. struct reset_control *rstc;
  188. void __iomem *reg;
  189. int ret;
  190. reg = devm_platform_ioremap_resource(pdev, 0);
  191. if (IS_ERR(reg))
  192. return PTR_ERR(reg);
  193. bus_clk = devm_clk_get(&pdev->dev, "bus");
  194. if (IS_ERR(bus_clk))
  195. return dev_err_probe(&pdev->dev, PTR_ERR(bus_clk),
  196. "Couldn't get bus clk\n");
  197. rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
  198. if (IS_ERR(rstc))
  199. return dev_err_probe(&pdev->dev, PTR_ERR(rstc),
  200. "Couldn't get reset control\n");
  201. /* The bus clock needs to be enabled for us to access the registers */
  202. ret = clk_prepare_enable(bus_clk);
  203. if (ret) {
  204. dev_err(&pdev->dev, "Couldn't enable bus clk: %d\n", ret);
  205. return ret;
  206. }
  207. /* The reset control needs to be asserted for the controls to work */
  208. ret = reset_control_deassert(rstc);
  209. if (ret) {
  210. dev_err(&pdev->dev,
  211. "Couldn't deassert reset control: %d\n", ret);
  212. goto err_disable_clk;
  213. }
  214. ret = devm_sunxi_ccu_probe(&pdev->dev, reg, &sun9i_a80_de_clk_desc);
  215. if (ret)
  216. goto err_assert_reset;
  217. return 0;
  218. err_assert_reset:
  219. reset_control_assert(rstc);
  220. err_disable_clk:
  221. clk_disable_unprepare(bus_clk);
  222. return ret;
  223. }
  224. static const struct of_device_id sun9i_a80_de_clk_ids[] = {
  225. { .compatible = "allwinner,sun9i-a80-de-clks" },
  226. { }
  227. };
  228. static struct platform_driver sun9i_a80_de_clk_driver = {
  229. .probe = sun9i_a80_de_clk_probe,
  230. .driver = {
  231. .name = "sun9i-a80-de-clks",
  232. .suppress_bind_attrs = true,
  233. .of_match_table = sun9i_a80_de_clk_ids,
  234. },
  235. };
  236. module_platform_driver(sun9i_a80_de_clk_driver);
  237. MODULE_IMPORT_NS(SUNXI_CCU);
  238. MODULE_LICENSE("GPL");