sun6i-prcm.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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_apb0_rstc_res[] = {
  39. {
  40. .start = 0xb0,
  41. .end = 0xb3,
  42. .flags = IORESOURCE_MEM,
  43. },
  44. };
  45. static const struct mfd_cell sun6i_a31_prcm_subdevs[] = {
  46. {
  47. .name = "sun6i-a31-ar100-clk",
  48. .of_compatible = "allwinner,sun6i-a31-ar100-clk",
  49. .num_resources = ARRAY_SIZE(sun6i_a31_ar100_clk_res),
  50. .resources = sun6i_a31_ar100_clk_res,
  51. },
  52. {
  53. .name = "sun6i-a31-apb0-clk",
  54. .of_compatible = "allwinner,sun6i-a31-apb0-clk",
  55. .num_resources = ARRAY_SIZE(sun6i_a31_apb0_clk_res),
  56. .resources = sun6i_a31_apb0_clk_res,
  57. },
  58. {
  59. .name = "sun6i-a31-apb0-gates-clk",
  60. .of_compatible = "allwinner,sun6i-a31-apb0-gates-clk",
  61. .num_resources = ARRAY_SIZE(sun6i_a31_apb0_gates_clk_res),
  62. .resources = sun6i_a31_apb0_gates_clk_res,
  63. },
  64. {
  65. .name = "sun6i-a31-apb0-clock-reset",
  66. .of_compatible = "allwinner,sun6i-a31-clock-reset",
  67. .num_resources = ARRAY_SIZE(sun6i_a31_apb0_rstc_res),
  68. .resources = sun6i_a31_apb0_rstc_res,
  69. },
  70. };
  71. static const struct mfd_cell sun8i_a23_prcm_subdevs[] = {
  72. {
  73. .name = "sun8i-a23-apb0-clk",
  74. .of_compatible = "allwinner,sun8i-a23-apb0-clk",
  75. .num_resources = ARRAY_SIZE(sun6i_a31_apb0_clk_res),
  76. .resources = sun6i_a31_apb0_clk_res,
  77. },
  78. {
  79. .name = "sun6i-a31-apb0-gates-clk",
  80. .of_compatible = "allwinner,sun8i-a23-apb0-gates-clk",
  81. .num_resources = ARRAY_SIZE(sun6i_a31_apb0_gates_clk_res),
  82. .resources = sun6i_a31_apb0_gates_clk_res,
  83. },
  84. {
  85. .name = "sun6i-a31-apb0-clock-reset",
  86. .of_compatible = "allwinner,sun6i-a31-clock-reset",
  87. .num_resources = ARRAY_SIZE(sun6i_a31_apb0_rstc_res),
  88. .resources = sun6i_a31_apb0_rstc_res,
  89. },
  90. };
  91. static const struct prcm_data sun6i_a31_prcm_data = {
  92. .nsubdevs = ARRAY_SIZE(sun6i_a31_prcm_subdevs),
  93. .subdevs = sun6i_a31_prcm_subdevs,
  94. };
  95. static const struct prcm_data sun8i_a23_prcm_data = {
  96. .nsubdevs = ARRAY_SIZE(sun8i_a23_prcm_subdevs),
  97. .subdevs = sun8i_a23_prcm_subdevs,
  98. };
  99. static const struct of_device_id sun6i_prcm_dt_ids[] = {
  100. {
  101. .compatible = "allwinner,sun6i-a31-prcm",
  102. .data = &sun6i_a31_prcm_data,
  103. },
  104. {
  105. .compatible = "allwinner,sun8i-a23-prcm",
  106. .data = &sun8i_a23_prcm_data,
  107. },
  108. { /* sentinel */ },
  109. };
  110. static int sun6i_prcm_probe(struct platform_device *pdev)
  111. {
  112. struct device_node *np = pdev->dev.of_node;
  113. const struct of_device_id *match;
  114. const struct prcm_data *data;
  115. struct resource *res;
  116. int ret;
  117. match = of_match_node(sun6i_prcm_dt_ids, np);
  118. if (!match)
  119. return -EINVAL;
  120. data = match->data;
  121. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  122. if (!res) {
  123. dev_err(&pdev->dev, "no prcm memory region provided\n");
  124. return -ENOENT;
  125. }
  126. ret = mfd_add_devices(&pdev->dev, 0, data->subdevs, data->nsubdevs,
  127. res, -1, NULL);
  128. if (ret) {
  129. dev_err(&pdev->dev, "failed to add subdevices\n");
  130. return ret;
  131. }
  132. return 0;
  133. }
  134. static struct platform_driver sun6i_prcm_driver = {
  135. .driver = {
  136. .name = "sun6i-prcm",
  137. .of_match_table = sun6i_prcm_dt_ids,
  138. },
  139. .probe = sun6i_prcm_probe,
  140. };
  141. module_platform_driver(sun6i_prcm_driver);
  142. MODULE_AUTHOR("Boris BREZILLON <boris.brezillon@free-electrons.com>");
  143. MODULE_DESCRIPTION("Allwinner sun6i PRCM driver");
  144. MODULE_LICENSE("GPL v2");