sun6i-prcm.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * Copyright (C) 2014 Free Electrons
  3. *
  4. * License Terms: GNU General Public License v2
  5. * Author: Boris BREZILLON <boris.brezillon@free-electrons.com>
  6. *
  7. * Allwinner PRCM (Power/Reset/Clock Management) driver
  8. *
  9. */
  10. #include <linux/mfd/core.h>
  11. #include <linux/init.h>
  12. #include <linux/of.h>
  13. #define SUN8I_CODEC_ANALOG_BASE 0x1c0
  14. #define SUN8I_CODEC_ANALOG_SIZE 0x4
  15. struct prcm_data {
  16. int nsubdevs;
  17. const struct mfd_cell *subdevs;
  18. };
  19. static const struct resource sun6i_a31_ar100_clk_res[] = {
  20. {
  21. .start = 0x0,
  22. .end = 0x3,
  23. .flags = IORESOURCE_MEM,
  24. },
  25. };
  26. static const struct resource sun6i_a31_apb0_clk_res[] = {
  27. {
  28. .start = 0xc,
  29. .end = 0xf,
  30. .flags = IORESOURCE_MEM,
  31. },
  32. };
  33. static const struct resource sun6i_a31_apb0_gates_clk_res[] = {
  34. {
  35. .start = 0x28,
  36. .end = 0x2b,
  37. .flags = IORESOURCE_MEM,
  38. },
  39. };
  40. static const struct resource sun6i_a31_ir_clk_res[] = {
  41. {
  42. .start = 0x54,
  43. .end = 0x57,
  44. .flags = IORESOURCE_MEM,
  45. },
  46. };
  47. static const struct resource sun6i_a31_apb0_rstc_res[] = {
  48. {
  49. .start = 0xb0,
  50. .end = 0xb3,
  51. .flags = IORESOURCE_MEM,
  52. },
  53. };
  54. static const struct resource sun8i_codec_analog_res[] = {
  55. DEFINE_RES_MEM(SUN8I_CODEC_ANALOG_BASE, SUN8I_CODEC_ANALOG_SIZE),
  56. };
  57. static const struct mfd_cell sun6i_a31_prcm_subdevs[] = {
  58. {
  59. .name = "sun6i-a31-ar100-clk",
  60. .of_compatible = "allwinner,sun6i-a31-ar100-clk",
  61. .num_resources = ARRAY_SIZE(sun6i_a31_ar100_clk_res),
  62. .resources = sun6i_a31_ar100_clk_res,
  63. },
  64. {
  65. .name = "sun6i-a31-apb0-clk",
  66. .of_compatible = "allwinner,sun6i-a31-apb0-clk",
  67. .num_resources = ARRAY_SIZE(sun6i_a31_apb0_clk_res),
  68. .resources = sun6i_a31_apb0_clk_res,
  69. },
  70. {
  71. .name = "sun6i-a31-apb0-gates-clk",
  72. .of_compatible = "allwinner,sun6i-a31-apb0-gates-clk",
  73. .num_resources = ARRAY_SIZE(sun6i_a31_apb0_gates_clk_res),
  74. .resources = sun6i_a31_apb0_gates_clk_res,
  75. },
  76. {
  77. .name = "sun6i-a31-ir-clk",
  78. .of_compatible = "allwinner,sun4i-a10-mod0-clk",
  79. .num_resources = ARRAY_SIZE(sun6i_a31_ir_clk_res),
  80. .resources = sun6i_a31_ir_clk_res,
  81. },
  82. {
  83. .name = "sun6i-a31-apb0-clock-reset",
  84. .of_compatible = "allwinner,sun6i-a31-clock-reset",
  85. .num_resources = ARRAY_SIZE(sun6i_a31_apb0_rstc_res),
  86. .resources = sun6i_a31_apb0_rstc_res,
  87. },
  88. };
  89. static const struct mfd_cell sun8i_a23_prcm_subdevs[] = {
  90. {
  91. .name = "sun8i-a23-apb0-clk",
  92. .of_compatible = "allwinner,sun8i-a23-apb0-clk",
  93. .num_resources = ARRAY_SIZE(sun6i_a31_apb0_clk_res),
  94. .resources = sun6i_a31_apb0_clk_res,
  95. },
  96. {
  97. .name = "sun6i-a31-apb0-gates-clk",
  98. .of_compatible = "allwinner,sun8i-a23-apb0-gates-clk",
  99. .num_resources = ARRAY_SIZE(sun6i_a31_apb0_gates_clk_res),
  100. .resources = sun6i_a31_apb0_gates_clk_res,
  101. },
  102. {
  103. .name = "sun6i-a31-apb0-clock-reset",
  104. .of_compatible = "allwinner,sun6i-a31-clock-reset",
  105. .num_resources = ARRAY_SIZE(sun6i_a31_apb0_rstc_res),
  106. .resources = sun6i_a31_apb0_rstc_res,
  107. },
  108. {
  109. .name = "sun8i-codec-analog",
  110. .of_compatible = "allwinner,sun8i-a23-codec-analog",
  111. .num_resources = ARRAY_SIZE(sun8i_codec_analog_res),
  112. .resources = sun8i_codec_analog_res,
  113. },
  114. };
  115. static const struct prcm_data sun6i_a31_prcm_data = {
  116. .nsubdevs = ARRAY_SIZE(sun6i_a31_prcm_subdevs),
  117. .subdevs = sun6i_a31_prcm_subdevs,
  118. };
  119. static const struct prcm_data sun8i_a23_prcm_data = {
  120. .nsubdevs = ARRAY_SIZE(sun8i_a23_prcm_subdevs),
  121. .subdevs = sun8i_a23_prcm_subdevs,
  122. };
  123. static const struct of_device_id sun6i_prcm_dt_ids[] = {
  124. {
  125. .compatible = "allwinner,sun6i-a31-prcm",
  126. .data = &sun6i_a31_prcm_data,
  127. },
  128. {
  129. .compatible = "allwinner,sun8i-a23-prcm",
  130. .data = &sun8i_a23_prcm_data,
  131. },
  132. { /* sentinel */ },
  133. };
  134. static int sun6i_prcm_probe(struct platform_device *pdev)
  135. {
  136. struct device_node *np = pdev->dev.of_node;
  137. const struct of_device_id *match;
  138. const struct prcm_data *data;
  139. struct resource *res;
  140. int ret;
  141. match = of_match_node(sun6i_prcm_dt_ids, np);
  142. if (!match)
  143. return -EINVAL;
  144. data = match->data;
  145. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  146. if (!res) {
  147. dev_err(&pdev->dev, "no prcm memory region provided\n");
  148. return -ENOENT;
  149. }
  150. ret = mfd_add_devices(&pdev->dev, 0, data->subdevs, data->nsubdevs,
  151. res, -1, NULL);
  152. if (ret) {
  153. dev_err(&pdev->dev, "failed to add subdevices\n");
  154. return ret;
  155. }
  156. return 0;
  157. }
  158. static struct platform_driver sun6i_prcm_driver = {
  159. .driver = {
  160. .name = "sun6i-prcm",
  161. .of_match_table = sun6i_prcm_dt_ids,
  162. },
  163. .probe = sun6i_prcm_probe,
  164. };
  165. builtin_platform_driver(sun6i_prcm_driver);