mtk_drm_ddp.c 19 KB

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