mtk_drm_ddp.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. /*
  2. * Copyright (c) 2015 MediaTek Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/clk.h>
  14. #include <linux/iopoll.h>
  15. #include <linux/module.h>
  16. #include <linux/of_device.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/regmap.h>
  19. #include "mtk_drm_ddp.h"
  20. #include "mtk_drm_ddp_comp.h"
  21. #define DISP_REG_CONFIG_DISP_OVL0_MOUT_EN 0x040
  22. #define DISP_REG_CONFIG_DISP_OVL1_MOUT_EN 0x044
  23. #define DISP_REG_CONFIG_DISP_OD_MOUT_EN 0x048
  24. #define DISP_REG_CONFIG_DISP_GAMMA_MOUT_EN 0x04c
  25. #define DISP_REG_CONFIG_DISP_UFOE_MOUT_EN 0x050
  26. #define DISP_REG_CONFIG_DISP_COLOR0_SEL_IN 0x084
  27. #define DISP_REG_CONFIG_DISP_COLOR1_SEL_IN 0x088
  28. #define DISP_REG_CONFIG_DSIE_SEL_IN 0x0a4
  29. #define DISP_REG_CONFIG_DSIO_SEL_IN 0x0a8
  30. #define DISP_REG_CONFIG_DPI_SEL_IN 0x0ac
  31. #define DISP_REG_CONFIG_DISP_RDMA2_SOUT 0x0b8
  32. #define DISP_REG_CONFIG_DISP_RDMA0_SOUT_EN 0x0c4
  33. #define DISP_REG_CONFIG_DISP_RDMA1_SOUT_EN 0x0c8
  34. #define DISP_REG_CONFIG_MMSYS_CG_CON0 0x100
  35. #define DISP_REG_CONFIG_DISP_OVL_MOUT_EN 0x030
  36. #define DISP_REG_CONFIG_OUT_SEL 0x04c
  37. #define DISP_REG_CONFIG_DSI_SEL 0x050
  38. #define DISP_REG_CONFIG_DPI_SEL 0x064
  39. #define DISP_REG_MUTEX_EN(n) (0x20 + 0x20 * (n))
  40. #define DISP_REG_MUTEX(n) (0x24 + 0x20 * (n))
  41. #define DISP_REG_MUTEX_RST(n) (0x28 + 0x20 * (n))
  42. #define DISP_REG_MUTEX_MOD(n) (0x2c + 0x20 * (n))
  43. #define DISP_REG_MUTEX_SOF(n) (0x30 + 0x20 * (n))
  44. #define DISP_REG_MUTEX_MOD2(n) (0x34 + 0x20 * (n))
  45. #define INT_MUTEX BIT(1)
  46. #define MT8173_MUTEX_MOD_DISP_OVL0 11
  47. #define MT8173_MUTEX_MOD_DISP_OVL1 12
  48. #define MT8173_MUTEX_MOD_DISP_RDMA0 13
  49. #define MT8173_MUTEX_MOD_DISP_RDMA1 14
  50. #define MT8173_MUTEX_MOD_DISP_RDMA2 15
  51. #define MT8173_MUTEX_MOD_DISP_WDMA0 16
  52. #define MT8173_MUTEX_MOD_DISP_WDMA1 17
  53. #define MT8173_MUTEX_MOD_DISP_COLOR0 18
  54. #define MT8173_MUTEX_MOD_DISP_COLOR1 19
  55. #define MT8173_MUTEX_MOD_DISP_AAL 20
  56. #define MT8173_MUTEX_MOD_DISP_GAMMA 21
  57. #define MT8173_MUTEX_MOD_DISP_UFOE 22
  58. #define MT8173_MUTEX_MOD_DISP_PWM0 23
  59. #define MT8173_MUTEX_MOD_DISP_PWM1 24
  60. #define MT8173_MUTEX_MOD_DISP_OD 25
  61. #define MT2712_MUTEX_MOD_DISP_PWM2 10
  62. #define MT2712_MUTEX_MOD_DISP_OVL0 11
  63. #define MT2712_MUTEX_MOD_DISP_OVL1 12
  64. #define MT2712_MUTEX_MOD_DISP_RDMA0 13
  65. #define MT2712_MUTEX_MOD_DISP_RDMA1 14
  66. #define MT2712_MUTEX_MOD_DISP_RDMA2 15
  67. #define MT2712_MUTEX_MOD_DISP_WDMA0 16
  68. #define MT2712_MUTEX_MOD_DISP_WDMA1 17
  69. #define MT2712_MUTEX_MOD_DISP_COLOR0 18
  70. #define MT2712_MUTEX_MOD_DISP_COLOR1 19
  71. #define MT2712_MUTEX_MOD_DISP_AAL0 20
  72. #define MT2712_MUTEX_MOD_DISP_UFOE 22
  73. #define MT2712_MUTEX_MOD_DISP_PWM0 23
  74. #define MT2712_MUTEX_MOD_DISP_PWM1 24
  75. #define MT2712_MUTEX_MOD_DISP_OD0 25
  76. #define MT2712_MUTEX_MOD2_DISP_AAL1 33
  77. #define MT2712_MUTEX_MOD2_DISP_OD1 34
  78. #define MT2701_MUTEX_MOD_DISP_OVL 3
  79. #define MT2701_MUTEX_MOD_DISP_WDMA 6
  80. #define MT2701_MUTEX_MOD_DISP_COLOR 7
  81. #define MT2701_MUTEX_MOD_DISP_BLS 9
  82. #define MT2701_MUTEX_MOD_DISP_RDMA0 10
  83. #define MT2701_MUTEX_MOD_DISP_RDMA1 12
  84. #define MUTEX_SOF_SINGLE_MODE 0
  85. #define MUTEX_SOF_DSI0 1
  86. #define MUTEX_SOF_DSI1 2
  87. #define MUTEX_SOF_DPI0 3
  88. #define MUTEX_SOF_DPI1 4
  89. #define MUTEX_SOF_DSI2 5
  90. #define MUTEX_SOF_DSI3 6
  91. #define OVL0_MOUT_EN_COLOR0 0x1
  92. #define OD_MOUT_EN_RDMA0 0x1
  93. #define OD1_MOUT_EN_RDMA1 BIT(16)
  94. #define UFOE_MOUT_EN_DSI0 0x1
  95. #define COLOR0_SEL_IN_OVL0 0x1
  96. #define OVL1_MOUT_EN_COLOR1 0x1
  97. #define GAMMA_MOUT_EN_RDMA1 0x1
  98. #define RDMA0_SOUT_DPI0 0x2
  99. #define RDMA0_SOUT_DPI1 0x3
  100. #define RDMA0_SOUT_DSI1 0x1
  101. #define RDMA0_SOUT_DSI2 0x4
  102. #define RDMA0_SOUT_DSI3 0x5
  103. #define RDMA1_SOUT_DPI0 0x2
  104. #define RDMA1_SOUT_DPI1 0x3
  105. #define RDMA1_SOUT_DSI1 0x1
  106. #define RDMA1_SOUT_DSI2 0x4
  107. #define RDMA1_SOUT_DSI3 0x5
  108. #define RDMA2_SOUT_DPI0 0x2
  109. #define RDMA2_SOUT_DPI1 0x3
  110. #define RDMA2_SOUT_DSI1 0x1
  111. #define RDMA2_SOUT_DSI2 0x4
  112. #define RDMA2_SOUT_DSI3 0x5
  113. #define DPI0_SEL_IN_RDMA1 0x1
  114. #define DPI0_SEL_IN_RDMA2 0x3
  115. #define DPI1_SEL_IN_RDMA1 (0x1 << 8)
  116. #define DPI1_SEL_IN_RDMA2 (0x3 << 8)
  117. #define DSI0_SEL_IN_RDMA1 0x1
  118. #define DSI0_SEL_IN_RDMA2 0x4
  119. #define DSI1_SEL_IN_RDMA1 0x1
  120. #define DSI1_SEL_IN_RDMA2 0x4
  121. #define DSI2_SEL_IN_RDMA1 (0x1 << 16)
  122. #define DSI2_SEL_IN_RDMA2 (0x4 << 16)
  123. #define DSI3_SEL_IN_RDMA1 (0x1 << 16)
  124. #define DSI3_SEL_IN_RDMA2 (0x4 << 16)
  125. #define COLOR1_SEL_IN_OVL1 0x1
  126. #define OVL_MOUT_EN_RDMA 0x1
  127. #define BLS_TO_DSI_RDMA1_TO_DPI1 0x8
  128. #define BLS_TO_DPI_RDMA1_TO_DSI 0x2
  129. #define DSI_SEL_IN_BLS 0x0
  130. #define DPI_SEL_IN_BLS 0x0
  131. #define DSI_SEL_IN_RDMA 0x1
  132. struct mtk_disp_mutex {
  133. int id;
  134. bool claimed;
  135. };
  136. struct mtk_ddp {
  137. struct device *dev;
  138. struct clk *clk;
  139. void __iomem *regs;
  140. struct mtk_disp_mutex mutex[10];
  141. const unsigned int *mutex_mod;
  142. };
  143. static const unsigned int mt2701_mutex_mod[DDP_COMPONENT_ID_MAX] = {
  144. [DDP_COMPONENT_BLS] = MT2701_MUTEX_MOD_DISP_BLS,
  145. [DDP_COMPONENT_COLOR0] = MT2701_MUTEX_MOD_DISP_COLOR,
  146. [DDP_COMPONENT_OVL0] = MT2701_MUTEX_MOD_DISP_OVL,
  147. [DDP_COMPONENT_RDMA0] = MT2701_MUTEX_MOD_DISP_RDMA0,
  148. [DDP_COMPONENT_RDMA1] = MT2701_MUTEX_MOD_DISP_RDMA1,
  149. [DDP_COMPONENT_WDMA0] = MT2701_MUTEX_MOD_DISP_WDMA,
  150. };
  151. static const unsigned int mt2712_mutex_mod[DDP_COMPONENT_ID_MAX] = {
  152. [DDP_COMPONENT_AAL0] = MT2712_MUTEX_MOD_DISP_AAL0,
  153. [DDP_COMPONENT_AAL1] = MT2712_MUTEX_MOD2_DISP_AAL1,
  154. [DDP_COMPONENT_COLOR0] = MT2712_MUTEX_MOD_DISP_COLOR0,
  155. [DDP_COMPONENT_COLOR1] = MT2712_MUTEX_MOD_DISP_COLOR1,
  156. [DDP_COMPONENT_OD0] = MT2712_MUTEX_MOD_DISP_OD0,
  157. [DDP_COMPONENT_OD1] = MT2712_MUTEX_MOD2_DISP_OD1,
  158. [DDP_COMPONENT_OVL0] = MT2712_MUTEX_MOD_DISP_OVL0,
  159. [DDP_COMPONENT_OVL1] = MT2712_MUTEX_MOD_DISP_OVL1,
  160. [DDP_COMPONENT_PWM0] = MT2712_MUTEX_MOD_DISP_PWM0,
  161. [DDP_COMPONENT_PWM1] = MT2712_MUTEX_MOD_DISP_PWM1,
  162. [DDP_COMPONENT_PWM2] = MT2712_MUTEX_MOD_DISP_PWM2,
  163. [DDP_COMPONENT_RDMA0] = MT2712_MUTEX_MOD_DISP_RDMA0,
  164. [DDP_COMPONENT_RDMA1] = MT2712_MUTEX_MOD_DISP_RDMA1,
  165. [DDP_COMPONENT_RDMA2] = MT2712_MUTEX_MOD_DISP_RDMA2,
  166. [DDP_COMPONENT_UFOE] = MT2712_MUTEX_MOD_DISP_UFOE,
  167. [DDP_COMPONENT_WDMA0] = MT2712_MUTEX_MOD_DISP_WDMA0,
  168. [DDP_COMPONENT_WDMA1] = MT2712_MUTEX_MOD_DISP_WDMA1,
  169. };
  170. static const unsigned int mt8173_mutex_mod[DDP_COMPONENT_ID_MAX] = {
  171. [DDP_COMPONENT_AAL0] = MT8173_MUTEX_MOD_DISP_AAL,
  172. [DDP_COMPONENT_COLOR0] = MT8173_MUTEX_MOD_DISP_COLOR0,
  173. [DDP_COMPONENT_COLOR1] = MT8173_MUTEX_MOD_DISP_COLOR1,
  174. [DDP_COMPONENT_GAMMA] = MT8173_MUTEX_MOD_DISP_GAMMA,
  175. [DDP_COMPONENT_OD0] = MT8173_MUTEX_MOD_DISP_OD,
  176. [DDP_COMPONENT_OVL0] = MT8173_MUTEX_MOD_DISP_OVL0,
  177. [DDP_COMPONENT_OVL1] = MT8173_MUTEX_MOD_DISP_OVL1,
  178. [DDP_COMPONENT_PWM0] = MT8173_MUTEX_MOD_DISP_PWM0,
  179. [DDP_COMPONENT_PWM1] = MT8173_MUTEX_MOD_DISP_PWM1,
  180. [DDP_COMPONENT_RDMA0] = MT8173_MUTEX_MOD_DISP_RDMA0,
  181. [DDP_COMPONENT_RDMA1] = MT8173_MUTEX_MOD_DISP_RDMA1,
  182. [DDP_COMPONENT_RDMA2] = MT8173_MUTEX_MOD_DISP_RDMA2,
  183. [DDP_COMPONENT_UFOE] = MT8173_MUTEX_MOD_DISP_UFOE,
  184. [DDP_COMPONENT_WDMA0] = MT8173_MUTEX_MOD_DISP_WDMA0,
  185. [DDP_COMPONENT_WDMA1] = MT8173_MUTEX_MOD_DISP_WDMA1,
  186. };
  187. static unsigned int mtk_ddp_mout_en(enum mtk_ddp_comp_id cur,
  188. enum mtk_ddp_comp_id next,
  189. unsigned int *addr)
  190. {
  191. unsigned int value;
  192. if (cur == DDP_COMPONENT_OVL0 && next == DDP_COMPONENT_COLOR0) {
  193. *addr = DISP_REG_CONFIG_DISP_OVL0_MOUT_EN;
  194. value = OVL0_MOUT_EN_COLOR0;
  195. } else if (cur == DDP_COMPONENT_OVL0 && next == DDP_COMPONENT_RDMA0) {
  196. *addr = DISP_REG_CONFIG_DISP_OVL_MOUT_EN;
  197. value = OVL_MOUT_EN_RDMA;
  198. } else if (cur == DDP_COMPONENT_OD0 && next == DDP_COMPONENT_RDMA0) {
  199. *addr = DISP_REG_CONFIG_DISP_OD_MOUT_EN;
  200. value = OD_MOUT_EN_RDMA0;
  201. } else if (cur == DDP_COMPONENT_UFOE && next == DDP_COMPONENT_DSI0) {
  202. *addr = DISP_REG_CONFIG_DISP_UFOE_MOUT_EN;
  203. value = UFOE_MOUT_EN_DSI0;
  204. } else if (cur == DDP_COMPONENT_OVL1 && next == DDP_COMPONENT_COLOR1) {
  205. *addr = DISP_REG_CONFIG_DISP_OVL1_MOUT_EN;
  206. value = OVL1_MOUT_EN_COLOR1;
  207. } else if (cur == DDP_COMPONENT_GAMMA && next == DDP_COMPONENT_RDMA1) {
  208. *addr = DISP_REG_CONFIG_DISP_GAMMA_MOUT_EN;
  209. value = GAMMA_MOUT_EN_RDMA1;
  210. } else if (cur == DDP_COMPONENT_OD1 && next == DDP_COMPONENT_RDMA1) {
  211. *addr = DISP_REG_CONFIG_DISP_OD_MOUT_EN;
  212. value = OD1_MOUT_EN_RDMA1;
  213. } else if (cur == DDP_COMPONENT_RDMA0 && next == DDP_COMPONENT_DPI0) {
  214. *addr = DISP_REG_CONFIG_DISP_RDMA0_SOUT_EN;
  215. value = RDMA0_SOUT_DPI0;
  216. } else if (cur == DDP_COMPONENT_RDMA0 && next == DDP_COMPONENT_DPI1) {
  217. *addr = DISP_REG_CONFIG_DISP_RDMA0_SOUT_EN;
  218. value = RDMA0_SOUT_DPI1;
  219. } else if (cur == DDP_COMPONENT_RDMA0 && next == DDP_COMPONENT_DSI1) {
  220. *addr = DISP_REG_CONFIG_DISP_RDMA0_SOUT_EN;
  221. value = RDMA0_SOUT_DSI1;
  222. } else if (cur == DDP_COMPONENT_RDMA0 && next == DDP_COMPONENT_DSI2) {
  223. *addr = DISP_REG_CONFIG_DISP_RDMA0_SOUT_EN;
  224. value = RDMA0_SOUT_DSI2;
  225. } else if (cur == DDP_COMPONENT_RDMA0 && next == DDP_COMPONENT_DSI3) {
  226. *addr = DISP_REG_CONFIG_DISP_RDMA0_SOUT_EN;
  227. value = RDMA0_SOUT_DSI3;
  228. } else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DSI1) {
  229. *addr = DISP_REG_CONFIG_DISP_RDMA1_SOUT_EN;
  230. value = RDMA1_SOUT_DSI1;
  231. } else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DSI2) {
  232. *addr = DISP_REG_CONFIG_DISP_RDMA1_SOUT_EN;
  233. value = RDMA1_SOUT_DSI2;
  234. } else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DSI3) {
  235. *addr = DISP_REG_CONFIG_DISP_RDMA1_SOUT_EN;
  236. value = RDMA1_SOUT_DSI3;
  237. } else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DPI0) {
  238. *addr = DISP_REG_CONFIG_DISP_RDMA1_SOUT_EN;
  239. value = RDMA1_SOUT_DPI0;
  240. } else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DPI1) {
  241. *addr = DISP_REG_CONFIG_DISP_RDMA1_SOUT_EN;
  242. value = RDMA1_SOUT_DPI1;
  243. } else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DPI0) {
  244. *addr = DISP_REG_CONFIG_DISP_RDMA2_SOUT;
  245. value = RDMA2_SOUT_DPI0;
  246. } else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DPI1) {
  247. *addr = DISP_REG_CONFIG_DISP_RDMA2_SOUT;
  248. value = RDMA2_SOUT_DPI1;
  249. } else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DSI1) {
  250. *addr = DISP_REG_CONFIG_DISP_RDMA2_SOUT;
  251. value = RDMA2_SOUT_DSI1;
  252. } else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DSI2) {
  253. *addr = DISP_REG_CONFIG_DISP_RDMA2_SOUT;
  254. value = RDMA2_SOUT_DSI2;
  255. } else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DSI3) {
  256. *addr = DISP_REG_CONFIG_DISP_RDMA2_SOUT;
  257. value = RDMA2_SOUT_DSI3;
  258. } else {
  259. value = 0;
  260. }
  261. return value;
  262. }
  263. static unsigned int mtk_ddp_sel_in(enum mtk_ddp_comp_id cur,
  264. enum mtk_ddp_comp_id next,
  265. unsigned int *addr)
  266. {
  267. unsigned int value;
  268. if (cur == DDP_COMPONENT_OVL0 && next == DDP_COMPONENT_COLOR0) {
  269. *addr = DISP_REG_CONFIG_DISP_COLOR0_SEL_IN;
  270. value = COLOR0_SEL_IN_OVL0;
  271. } else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DPI0) {
  272. *addr = DISP_REG_CONFIG_DPI_SEL_IN;
  273. value = DPI0_SEL_IN_RDMA1;
  274. } else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DPI1) {
  275. *addr = DISP_REG_CONFIG_DPI_SEL_IN;
  276. value = DPI1_SEL_IN_RDMA1;
  277. } else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DSI0) {
  278. *addr = DISP_REG_CONFIG_DSIE_SEL_IN;
  279. value = DSI0_SEL_IN_RDMA1;
  280. } else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DSI1) {
  281. *addr = DISP_REG_CONFIG_DSIO_SEL_IN;
  282. value = DSI1_SEL_IN_RDMA1;
  283. } else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DSI2) {
  284. *addr = DISP_REG_CONFIG_DSIE_SEL_IN;
  285. value = DSI2_SEL_IN_RDMA1;
  286. } else if (cur == DDP_COMPONENT_RDMA1 && next == DDP_COMPONENT_DSI3) {
  287. *addr = DISP_REG_CONFIG_DSIO_SEL_IN;
  288. value = DSI3_SEL_IN_RDMA1;
  289. } else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DPI0) {
  290. *addr = DISP_REG_CONFIG_DPI_SEL_IN;
  291. value = DPI0_SEL_IN_RDMA2;
  292. } else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DPI1) {
  293. *addr = DISP_REG_CONFIG_DPI_SEL_IN;
  294. value = DPI1_SEL_IN_RDMA2;
  295. } else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DSI0) {
  296. *addr = DISP_REG_CONFIG_DSIE_SEL_IN;
  297. value = DSI0_SEL_IN_RDMA2;
  298. } else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DSI1) {
  299. *addr = DISP_REG_CONFIG_DSIO_SEL_IN;
  300. value = DSI1_SEL_IN_RDMA2;
  301. } else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DSI2) {
  302. *addr = DISP_REG_CONFIG_DSIE_SEL_IN;
  303. value = DSI2_SEL_IN_RDMA2;
  304. } else if (cur == DDP_COMPONENT_RDMA2 && next == DDP_COMPONENT_DSI3) {
  305. *addr = DISP_REG_CONFIG_DSIE_SEL_IN;
  306. value = DSI3_SEL_IN_RDMA2;
  307. } else if (cur == DDP_COMPONENT_OVL1 && next == DDP_COMPONENT_COLOR1) {
  308. *addr = DISP_REG_CONFIG_DISP_COLOR1_SEL_IN;
  309. value = COLOR1_SEL_IN_OVL1;
  310. } else if (cur == DDP_COMPONENT_BLS && next == DDP_COMPONENT_DSI0) {
  311. *addr = DISP_REG_CONFIG_DSI_SEL;
  312. value = DSI_SEL_IN_BLS;
  313. } else {
  314. value = 0;
  315. }
  316. return value;
  317. }
  318. static void mtk_ddp_sout_sel(void __iomem *config_regs,
  319. enum mtk_ddp_comp_id cur,
  320. enum mtk_ddp_comp_id next)
  321. {
  322. if (cur == DDP_COMPONENT_BLS && next == DDP_COMPONENT_DSI0) {
  323. writel_relaxed(BLS_TO_DSI_RDMA1_TO_DPI1,
  324. config_regs + DISP_REG_CONFIG_OUT_SEL);
  325. } else if (cur == DDP_COMPONENT_BLS && next == DDP_COMPONENT_DPI0) {
  326. writel_relaxed(BLS_TO_DPI_RDMA1_TO_DSI,
  327. config_regs + DISP_REG_CONFIG_OUT_SEL);
  328. writel_relaxed(DSI_SEL_IN_RDMA,
  329. config_regs + DISP_REG_CONFIG_DSI_SEL);
  330. writel_relaxed(DPI_SEL_IN_BLS,
  331. config_regs + DISP_REG_CONFIG_DPI_SEL);
  332. }
  333. }
  334. void mtk_ddp_add_comp_to_path(void __iomem *config_regs,
  335. enum mtk_ddp_comp_id cur,
  336. enum mtk_ddp_comp_id next)
  337. {
  338. unsigned int addr, value, reg;
  339. value = mtk_ddp_mout_en(cur, next, &addr);
  340. if (value) {
  341. reg = readl_relaxed(config_regs + addr) | value;
  342. writel_relaxed(reg, config_regs + addr);
  343. }
  344. mtk_ddp_sout_sel(config_regs, cur, next);
  345. value = mtk_ddp_sel_in(cur, next, &addr);
  346. if (value) {
  347. reg = readl_relaxed(config_regs + addr) | value;
  348. writel_relaxed(reg, config_regs + addr);
  349. }
  350. }
  351. void mtk_ddp_remove_comp_from_path(void __iomem *config_regs,
  352. enum mtk_ddp_comp_id cur,
  353. enum mtk_ddp_comp_id next)
  354. {
  355. unsigned int addr, value, reg;
  356. value = mtk_ddp_mout_en(cur, next, &addr);
  357. if (value) {
  358. reg = readl_relaxed(config_regs + addr) & ~value;
  359. writel_relaxed(reg, config_regs + addr);
  360. }
  361. value = mtk_ddp_sel_in(cur, next, &addr);
  362. if (value) {
  363. reg = readl_relaxed(config_regs + addr) & ~value;
  364. writel_relaxed(reg, config_regs + addr);
  365. }
  366. }
  367. struct mtk_disp_mutex *mtk_disp_mutex_get(struct device *dev, unsigned int id)
  368. {
  369. struct mtk_ddp *ddp = dev_get_drvdata(dev);
  370. if (id >= 10)
  371. return ERR_PTR(-EINVAL);
  372. if (ddp->mutex[id].claimed)
  373. return ERR_PTR(-EBUSY);
  374. ddp->mutex[id].claimed = true;
  375. return &ddp->mutex[id];
  376. }
  377. void mtk_disp_mutex_put(struct mtk_disp_mutex *mutex)
  378. {
  379. struct mtk_ddp *ddp = container_of(mutex, struct mtk_ddp,
  380. mutex[mutex->id]);
  381. WARN_ON(&ddp->mutex[mutex->id] != mutex);
  382. mutex->claimed = false;
  383. }
  384. int mtk_disp_mutex_prepare(struct mtk_disp_mutex *mutex)
  385. {
  386. struct mtk_ddp *ddp = container_of(mutex, struct mtk_ddp,
  387. mutex[mutex->id]);
  388. return clk_prepare_enable(ddp->clk);
  389. }
  390. void mtk_disp_mutex_unprepare(struct mtk_disp_mutex *mutex)
  391. {
  392. struct mtk_ddp *ddp = container_of(mutex, struct mtk_ddp,
  393. mutex[mutex->id]);
  394. clk_disable_unprepare(ddp->clk);
  395. }
  396. void mtk_disp_mutex_add_comp(struct mtk_disp_mutex *mutex,
  397. enum mtk_ddp_comp_id id)
  398. {
  399. struct mtk_ddp *ddp = container_of(mutex, struct mtk_ddp,
  400. mutex[mutex->id]);
  401. unsigned int reg;
  402. unsigned int offset;
  403. WARN_ON(&ddp->mutex[mutex->id] != mutex);
  404. switch (id) {
  405. case DDP_COMPONENT_DSI0:
  406. reg = MUTEX_SOF_DSI0;
  407. break;
  408. case DDP_COMPONENT_DSI1:
  409. reg = MUTEX_SOF_DSI0;
  410. break;
  411. case DDP_COMPONENT_DSI2:
  412. reg = MUTEX_SOF_DSI2;
  413. break;
  414. case DDP_COMPONENT_DSI3:
  415. reg = MUTEX_SOF_DSI3;
  416. break;
  417. case DDP_COMPONENT_DPI0:
  418. reg = MUTEX_SOF_DPI0;
  419. break;
  420. case DDP_COMPONENT_DPI1:
  421. reg = MUTEX_SOF_DPI1;
  422. break;
  423. default:
  424. if (ddp->mutex_mod[id] < 32) {
  425. offset = DISP_REG_MUTEX_MOD(mutex->id);
  426. reg = readl_relaxed(ddp->regs + offset);
  427. reg |= 1 << ddp->mutex_mod[id];
  428. writel_relaxed(reg, ddp->regs + offset);
  429. } else {
  430. offset = DISP_REG_MUTEX_MOD2(mutex->id);
  431. reg = readl_relaxed(ddp->regs + offset);
  432. reg |= 1 << (ddp->mutex_mod[id] - 32);
  433. writel_relaxed(reg, ddp->regs + offset);
  434. }
  435. return;
  436. }
  437. writel_relaxed(reg, ddp->regs + DISP_REG_MUTEX_SOF(mutex->id));
  438. }
  439. void mtk_disp_mutex_remove_comp(struct mtk_disp_mutex *mutex,
  440. enum mtk_ddp_comp_id id)
  441. {
  442. struct mtk_ddp *ddp = container_of(mutex, struct mtk_ddp,
  443. mutex[mutex->id]);
  444. unsigned int reg;
  445. unsigned int offset;
  446. WARN_ON(&ddp->mutex[mutex->id] != mutex);
  447. switch (id) {
  448. case DDP_COMPONENT_DSI0:
  449. case DDP_COMPONENT_DSI1:
  450. case DDP_COMPONENT_DSI2:
  451. case DDP_COMPONENT_DSI3:
  452. case DDP_COMPONENT_DPI0:
  453. case DDP_COMPONENT_DPI1:
  454. writel_relaxed(MUTEX_SOF_SINGLE_MODE,
  455. ddp->regs + DISP_REG_MUTEX_SOF(mutex->id));
  456. break;
  457. default:
  458. if (ddp->mutex_mod[id] < 32) {
  459. offset = DISP_REG_MUTEX_MOD(mutex->id);
  460. reg = readl_relaxed(ddp->regs + offset);
  461. reg &= ~(1 << ddp->mutex_mod[id]);
  462. writel_relaxed(reg, ddp->regs + offset);
  463. } else {
  464. offset = DISP_REG_MUTEX_MOD2(mutex->id);
  465. reg = readl_relaxed(ddp->regs + offset);
  466. reg &= ~(1 << (ddp->mutex_mod[id] - 32));
  467. writel_relaxed(reg, ddp->regs + offset);
  468. }
  469. break;
  470. }
  471. }
  472. void mtk_disp_mutex_enable(struct mtk_disp_mutex *mutex)
  473. {
  474. struct mtk_ddp *ddp = container_of(mutex, struct mtk_ddp,
  475. mutex[mutex->id]);
  476. WARN_ON(&ddp->mutex[mutex->id] != mutex);
  477. writel(1, ddp->regs + DISP_REG_MUTEX_EN(mutex->id));
  478. }
  479. void mtk_disp_mutex_disable(struct mtk_disp_mutex *mutex)
  480. {
  481. struct mtk_ddp *ddp = container_of(mutex, struct mtk_ddp,
  482. mutex[mutex->id]);
  483. WARN_ON(&ddp->mutex[mutex->id] != mutex);
  484. writel(0, ddp->regs + DISP_REG_MUTEX_EN(mutex->id));
  485. }
  486. void mtk_disp_mutex_acquire(struct mtk_disp_mutex *mutex)
  487. {
  488. struct mtk_ddp *ddp = container_of(mutex, struct mtk_ddp,
  489. mutex[mutex->id]);
  490. u32 tmp;
  491. writel(1, ddp->regs + DISP_REG_MUTEX_EN(mutex->id));
  492. writel(1, ddp->regs + DISP_REG_MUTEX(mutex->id));
  493. if (readl_poll_timeout_atomic(ddp->regs + DISP_REG_MUTEX(mutex->id),
  494. tmp, tmp & INT_MUTEX, 1, 10000))
  495. pr_err("could not acquire mutex %d\n", mutex->id);
  496. }
  497. void mtk_disp_mutex_release(struct mtk_disp_mutex *mutex)
  498. {
  499. struct mtk_ddp *ddp = container_of(mutex, struct mtk_ddp,
  500. mutex[mutex->id]);
  501. writel(0, ddp->regs + DISP_REG_MUTEX(mutex->id));
  502. }
  503. static int mtk_ddp_probe(struct platform_device *pdev)
  504. {
  505. struct device *dev = &pdev->dev;
  506. struct mtk_ddp *ddp;
  507. struct resource *regs;
  508. int i;
  509. ddp = devm_kzalloc(dev, sizeof(*ddp), GFP_KERNEL);
  510. if (!ddp)
  511. return -ENOMEM;
  512. for (i = 0; i < 10; i++)
  513. ddp->mutex[i].id = i;
  514. ddp->clk = devm_clk_get(dev, NULL);
  515. if (IS_ERR(ddp->clk)) {
  516. dev_err(dev, "Failed to get clock\n");
  517. return PTR_ERR(ddp->clk);
  518. }
  519. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  520. ddp->regs = devm_ioremap_resource(dev, regs);
  521. if (IS_ERR(ddp->regs)) {
  522. dev_err(dev, "Failed to map mutex registers\n");
  523. return PTR_ERR(ddp->regs);
  524. }
  525. ddp->mutex_mod = of_device_get_match_data(dev);
  526. platform_set_drvdata(pdev, ddp);
  527. return 0;
  528. }
  529. static int mtk_ddp_remove(struct platform_device *pdev)
  530. {
  531. return 0;
  532. }
  533. static const struct of_device_id ddp_driver_dt_match[] = {
  534. { .compatible = "mediatek,mt2701-disp-mutex", .data = mt2701_mutex_mod},
  535. { .compatible = "mediatek,mt2712-disp-mutex", .data = mt2712_mutex_mod},
  536. { .compatible = "mediatek,mt8173-disp-mutex", .data = mt8173_mutex_mod},
  537. {},
  538. };
  539. MODULE_DEVICE_TABLE(of, ddp_driver_dt_match);
  540. struct platform_driver mtk_ddp_driver = {
  541. .probe = mtk_ddp_probe,
  542. .remove = mtk_ddp_remove,
  543. .driver = {
  544. .name = "mediatek-ddp",
  545. .owner = THIS_MODULE,
  546. .of_match_table = ddp_driver_dt_match,
  547. },
  548. };