sun6i-prcm.c 4.1 KB

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