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