da8xx-mstpri.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * TI da8xx master peripheral priority driver
  4. *
  5. * Copyright (C) 2016 BayLibre SAS
  6. *
  7. * Author:
  8. * Bartosz Golaszewski <[email protected]>
  9. */
  10. #include <linux/module.h>
  11. #include <linux/of.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/io.h>
  14. #include <linux/regmap.h>
  15. /*
  16. * REVISIT: Linux doesn't have a good framework for the kind of performance
  17. * knobs this driver controls. We can't use device tree properties as it deals
  18. * with hardware configuration rather than description. We also don't want to
  19. * commit to maintaining some random sysfs attributes.
  20. *
  21. * For now we just hardcode the register values for the boards that need
  22. * some changes (as is the case for the LCD controller on da850-lcdk - the
  23. * first board we support here). When linux gets an appropriate framework,
  24. * we'll easily convert the driver to it.
  25. */
  26. #define DA8XX_MSTPRI0_OFFSET 0
  27. #define DA8XX_MSTPRI1_OFFSET 4
  28. #define DA8XX_MSTPRI2_OFFSET 8
  29. enum {
  30. DA8XX_MSTPRI_ARM_I = 0,
  31. DA8XX_MSTPRI_ARM_D,
  32. DA8XX_MSTPRI_UPP,
  33. DA8XX_MSTPRI_SATA,
  34. DA8XX_MSTPRI_PRU0,
  35. DA8XX_MSTPRI_PRU1,
  36. DA8XX_MSTPRI_EDMA30TC0,
  37. DA8XX_MSTPRI_EDMA30TC1,
  38. DA8XX_MSTPRI_EDMA31TC0,
  39. DA8XX_MSTPRI_VPIF_DMA_0,
  40. DA8XX_MSTPRI_VPIF_DMA_1,
  41. DA8XX_MSTPRI_EMAC,
  42. DA8XX_MSTPRI_USB0CFG,
  43. DA8XX_MSTPRI_USB0CDMA,
  44. DA8XX_MSTPRI_UHPI,
  45. DA8XX_MSTPRI_USB1,
  46. DA8XX_MSTPRI_LCDC,
  47. };
  48. struct da8xx_mstpri_descr {
  49. int reg;
  50. int shift;
  51. int mask;
  52. };
  53. static const struct da8xx_mstpri_descr da8xx_mstpri_priority_list[] = {
  54. [DA8XX_MSTPRI_ARM_I] = {
  55. .reg = DA8XX_MSTPRI0_OFFSET,
  56. .shift = 0,
  57. .mask = 0x0000000f,
  58. },
  59. [DA8XX_MSTPRI_ARM_D] = {
  60. .reg = DA8XX_MSTPRI0_OFFSET,
  61. .shift = 4,
  62. .mask = 0x000000f0,
  63. },
  64. [DA8XX_MSTPRI_UPP] = {
  65. .reg = DA8XX_MSTPRI0_OFFSET,
  66. .shift = 16,
  67. .mask = 0x000f0000,
  68. },
  69. [DA8XX_MSTPRI_SATA] = {
  70. .reg = DA8XX_MSTPRI0_OFFSET,
  71. .shift = 20,
  72. .mask = 0x00f00000,
  73. },
  74. [DA8XX_MSTPRI_PRU0] = {
  75. .reg = DA8XX_MSTPRI1_OFFSET,
  76. .shift = 0,
  77. .mask = 0x0000000f,
  78. },
  79. [DA8XX_MSTPRI_PRU1] = {
  80. .reg = DA8XX_MSTPRI1_OFFSET,
  81. .shift = 4,
  82. .mask = 0x000000f0,
  83. },
  84. [DA8XX_MSTPRI_EDMA30TC0] = {
  85. .reg = DA8XX_MSTPRI1_OFFSET,
  86. .shift = 8,
  87. .mask = 0x00000f00,
  88. },
  89. [DA8XX_MSTPRI_EDMA30TC1] = {
  90. .reg = DA8XX_MSTPRI1_OFFSET,
  91. .shift = 12,
  92. .mask = 0x0000f000,
  93. },
  94. [DA8XX_MSTPRI_EDMA31TC0] = {
  95. .reg = DA8XX_MSTPRI1_OFFSET,
  96. .shift = 16,
  97. .mask = 0x000f0000,
  98. },
  99. [DA8XX_MSTPRI_VPIF_DMA_0] = {
  100. .reg = DA8XX_MSTPRI1_OFFSET,
  101. .shift = 24,
  102. .mask = 0x0f000000,
  103. },
  104. [DA8XX_MSTPRI_VPIF_DMA_1] = {
  105. .reg = DA8XX_MSTPRI1_OFFSET,
  106. .shift = 28,
  107. .mask = 0xf0000000,
  108. },
  109. [DA8XX_MSTPRI_EMAC] = {
  110. .reg = DA8XX_MSTPRI2_OFFSET,
  111. .shift = 0,
  112. .mask = 0x0000000f,
  113. },
  114. [DA8XX_MSTPRI_USB0CFG] = {
  115. .reg = DA8XX_MSTPRI2_OFFSET,
  116. .shift = 8,
  117. .mask = 0x00000f00,
  118. },
  119. [DA8XX_MSTPRI_USB0CDMA] = {
  120. .reg = DA8XX_MSTPRI2_OFFSET,
  121. .shift = 12,
  122. .mask = 0x0000f000,
  123. },
  124. [DA8XX_MSTPRI_UHPI] = {
  125. .reg = DA8XX_MSTPRI2_OFFSET,
  126. .shift = 20,
  127. .mask = 0x00f00000,
  128. },
  129. [DA8XX_MSTPRI_USB1] = {
  130. .reg = DA8XX_MSTPRI2_OFFSET,
  131. .shift = 24,
  132. .mask = 0x0f000000,
  133. },
  134. [DA8XX_MSTPRI_LCDC] = {
  135. .reg = DA8XX_MSTPRI2_OFFSET,
  136. .shift = 28,
  137. .mask = 0xf0000000,
  138. },
  139. };
  140. struct da8xx_mstpri_priority {
  141. int which;
  142. u32 val;
  143. };
  144. struct da8xx_mstpri_board_priorities {
  145. const char *board;
  146. const struct da8xx_mstpri_priority *priorities;
  147. size_t numprio;
  148. };
  149. /*
  150. * Default memory settings of da850 do not meet the throughput/latency
  151. * requirements of tilcdc. This results in the image displayed being
  152. * incorrect and the following warning being displayed by the LCDC
  153. * drm driver:
  154. *
  155. * tilcdc da8xx_lcdc.0: tilcdc_crtc_irq(0x00000020): FIFO underfow
  156. */
  157. static const struct da8xx_mstpri_priority da850_lcdk_priorities[] = {
  158. {
  159. .which = DA8XX_MSTPRI_LCDC,
  160. .val = 0,
  161. },
  162. {
  163. .which = DA8XX_MSTPRI_EDMA30TC1,
  164. .val = 0,
  165. },
  166. {
  167. .which = DA8XX_MSTPRI_EDMA30TC0,
  168. .val = 1,
  169. },
  170. };
  171. static const struct da8xx_mstpri_board_priorities da8xx_mstpri_board_confs[] = {
  172. {
  173. .board = "ti,da850-lcdk",
  174. .priorities = da850_lcdk_priorities,
  175. .numprio = ARRAY_SIZE(da850_lcdk_priorities),
  176. },
  177. };
  178. static const struct da8xx_mstpri_board_priorities *
  179. da8xx_mstpri_get_board_prio(void)
  180. {
  181. const struct da8xx_mstpri_board_priorities *board_prio;
  182. int i;
  183. for (i = 0; i < ARRAY_SIZE(da8xx_mstpri_board_confs); i++) {
  184. board_prio = &da8xx_mstpri_board_confs[i];
  185. if (of_machine_is_compatible(board_prio->board))
  186. return board_prio;
  187. }
  188. return NULL;
  189. }
  190. static int da8xx_mstpri_probe(struct platform_device *pdev)
  191. {
  192. const struct da8xx_mstpri_board_priorities *prio_list;
  193. const struct da8xx_mstpri_descr *prio_descr;
  194. const struct da8xx_mstpri_priority *prio;
  195. struct device *dev = &pdev->dev;
  196. struct resource *res;
  197. void __iomem *mstpri;
  198. u32 reg;
  199. int i;
  200. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  201. mstpri = devm_ioremap_resource(dev, res);
  202. if (IS_ERR(mstpri)) {
  203. dev_err(dev, "unable to map MSTPRI registers\n");
  204. return PTR_ERR(mstpri);
  205. }
  206. prio_list = da8xx_mstpri_get_board_prio();
  207. if (!prio_list) {
  208. dev_err(dev, "no master priorities defined for this board\n");
  209. return -EINVAL;
  210. }
  211. for (i = 0; i < prio_list->numprio; i++) {
  212. prio = &prio_list->priorities[i];
  213. prio_descr = &da8xx_mstpri_priority_list[prio->which];
  214. if (prio_descr->reg + sizeof(u32) > resource_size(res)) {
  215. dev_warn(dev, "register offset out of range\n");
  216. continue;
  217. }
  218. reg = readl(mstpri + prio_descr->reg);
  219. reg &= ~prio_descr->mask;
  220. reg |= prio->val << prio_descr->shift;
  221. writel(reg, mstpri + prio_descr->reg);
  222. }
  223. return 0;
  224. }
  225. static const struct of_device_id da8xx_mstpri_of_match[] = {
  226. { .compatible = "ti,da850-mstpri", },
  227. { },
  228. };
  229. static struct platform_driver da8xx_mstpri_driver = {
  230. .probe = da8xx_mstpri_probe,
  231. .driver = {
  232. .name = "da8xx-mstpri",
  233. .of_match_table = da8xx_mstpri_of_match,
  234. },
  235. };
  236. module_platform_driver(da8xx_mstpri_driver);
  237. MODULE_AUTHOR("Bartosz Golaszewski <[email protected]>");
  238. MODULE_DESCRIPTION("TI da8xx master peripheral priority driver");
  239. MODULE_LICENSE("GPL v2");