imx51_ipuv3.c revision 1.11 1 1.11 thorpej /* $NetBSD: imx51_ipuv3.c,v 1.11 2021/08/07 16:18:44 thorpej Exp $ */
2 1.1 bsh
3 1.1 bsh /*
4 1.1 bsh * Copyright (c) 2011, 2012 Genetec Corporation. All rights reserved.
5 1.1 bsh * Written by Hashimoto Kenichi for Genetec Corporation.
6 1.1 bsh *
7 1.1 bsh * Redistribution and use in source and binary forms, with or without
8 1.1 bsh * modification, are permitted provided that the following conditions
9 1.1 bsh * are met:
10 1.1 bsh * 1. Redistributions of source code must retain the above copyright
11 1.1 bsh * notice, this list of conditions and the following disclaimer.
12 1.1 bsh * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 bsh * notice, this list of conditions and the following disclaimer in the
14 1.1 bsh * documentation and/or other materials provided with the distribution.
15 1.1 bsh *
16 1.1 bsh * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
17 1.1 bsh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.1 bsh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.1 bsh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
20 1.1 bsh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1 bsh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1 bsh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1 bsh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1 bsh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.1 bsh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 bsh * POSSIBILITY OF SUCH DAMAGE.
27 1.1 bsh */
28 1.1 bsh
29 1.1 bsh #include <sys/cdefs.h>
30 1.11 thorpej __KERNEL_RCSID(0, "$NetBSD: imx51_ipuv3.c,v 1.11 2021/08/07 16:18:44 thorpej Exp $");
31 1.4 hkenken
32 1.4 hkenken #include "opt_imx51_ipuv3.h"
33 1.1 bsh
34 1.1 bsh #include <sys/param.h>
35 1.1 bsh #include <sys/systm.h>
36 1.1 bsh #include <sys/conf.h>
37 1.1 bsh #include <sys/uio.h>
38 1.9 thorpej #include <sys/kmem.h>
39 1.1 bsh #include <sys/kernel.h> /* for cold */
40 1.1 bsh
41 1.1 bsh #include <sys/bus.h>
42 1.1 bsh #include <machine/cpu.h>
43 1.1 bsh #include <arm/cpufunc.h>
44 1.1 bsh
45 1.1 bsh #include <arm/imx/imx51var.h>
46 1.1 bsh #include <arm/imx/imx51reg.h>
47 1.1 bsh #include <arm/imx/imx51_ipuv3var.h>
48 1.1 bsh #include <arm/imx/imx51_ipuv3reg.h>
49 1.1 bsh #include <arm/imx/imx51_ccmvar.h>
50 1.1 bsh #include <arm/imx/imx51_ccmreg.h>
51 1.1 bsh
52 1.1 bsh #include "imxccm.h" /* if CCM driver is configured into the kernel */
53 1.1 bsh
54 1.1 bsh #define IPUV3_READ(ipuv3, module, reg) \
55 1.1 bsh bus_space_read_4((ipuv3)->iot, (ipuv3)->module##_ioh, (reg))
56 1.1 bsh #define IPUV3_WRITE(ipuv3, module, reg, val) \
57 1.1 bsh bus_space_write_4((ipuv3)->iot, (ipuv3)->module##_ioh, (reg), (val))
58 1.1 bsh
59 1.1 bsh #ifdef IPUV3_DEBUG
60 1.1 bsh int ipuv3_debug = IPUV3_DEBUG;
61 1.1 bsh #define DPRINTFN(n,x) if (ipuv3_debug>(n)) printf x; else
62 1.1 bsh #else
63 1.1 bsh #define DPRINTFN(n,x)
64 1.1 bsh #endif
65 1.1 bsh
66 1.1 bsh int ipuv3intr(void *);
67 1.1 bsh
68 1.1 bsh static void imx51_ipuv3_initialize(struct imx51_ipuv3_softc *,
69 1.1 bsh const struct lcd_panel_geometry *);
70 1.1 bsh static void imx51_ipuv3_set_idma_param(uint32_t *, uint32_t, uint32_t);
71 1.1 bsh
72 1.1 bsh #ifdef IPUV3_DEBUG
73 1.1 bsh static void
74 1.1 bsh imx51_ipuv3_dump(struct imx51_ipuv3_softc *sc)
75 1.1 bsh {
76 1.1 bsh int i;
77 1.1 bsh
78 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
79 1.1 bsh
80 1.1 bsh #define __DUMP(grp, reg) \
81 1.1 bsh DPRINTFN(4, ("%-16s = 0x%08X\n", #reg, IPUV3_READ(sc, grp, IPU_##reg)))
82 1.1 bsh
83 1.1 bsh __DUMP(cm, CM_CONF);
84 1.1 bsh __DUMP(cm, CM_DISP_GEN);
85 1.1 bsh __DUMP(idmac, IDMAC_CONF);
86 1.1 bsh __DUMP(idmac, IDMAC_CH_EN_1);
87 1.1 bsh __DUMP(idmac, IDMAC_CH_EN_2);
88 1.1 bsh __DUMP(idmac, IDMAC_CH_PRI_1);
89 1.1 bsh __DUMP(idmac, IDMAC_CH_PRI_2);
90 1.1 bsh __DUMP(idmac, IDMAC_BNDM_EN_1);
91 1.1 bsh __DUMP(idmac, IDMAC_BNDM_EN_2);
92 1.1 bsh __DUMP(cm, CM_CH_DB_MODE_SEL_0);
93 1.1 bsh __DUMP(cm, CM_CH_DB_MODE_SEL_1);
94 1.1 bsh __DUMP(dmfc, DMFC_WR_CHAN);
95 1.1 bsh __DUMP(dmfc, DMFC_WR_CHAN_DEF);
96 1.1 bsh __DUMP(dmfc, DMFC_DP_CHAN);
97 1.1 bsh __DUMP(dmfc, DMFC_DP_CHAN_DEF);
98 1.1 bsh __DUMP(dmfc, DMFC_IC_CTRL);
99 1.1 bsh __DUMP(cm, CM_FS_PROC_FLOW1);
100 1.1 bsh __DUMP(cm, CM_FS_PROC_FLOW2);
101 1.1 bsh __DUMP(cm, CM_FS_PROC_FLOW3);
102 1.1 bsh __DUMP(cm, CM_FS_DISP_FLOW1);
103 1.1 bsh __DUMP(dc, DC_DISP_CONF1_0);
104 1.1 bsh __DUMP(dc, DC_DISP_CONF2_0);
105 1.1 bsh __DUMP(dc, DC_WR_CH_CONF_5);
106 1.1 bsh
107 1.1 bsh printf("*** IPU ***\n");
108 1.1 bsh for (i = 0; i <= 0x17c; i += 4)
109 1.1 bsh DPRINTFN(6, ("0x%08X = 0x%08X\n", i, IPUV3_READ(sc, cm, i)));
110 1.1 bsh printf("*** IDMAC ***\n");
111 1.1 bsh for (i = 0; i <= 0x104; i += 4)
112 1.1 bsh DPRINTFN(6, ("0x%08X = 0x%08X\n", i, IPUV3_READ(sc, idmac, i)));
113 1.1 bsh printf("*** CPMEM ***\n");
114 1.1 bsh for (i = 0x5c0; i <= 0x600; i += 4)
115 1.1 bsh DPRINTFN(6, ("0x%08X = 0x%08X\n", i, IPUV3_READ(sc, cpmem, i)));
116 1.1 bsh
117 1.1 bsh #undef __DUMP
118 1.1 bsh
119 1.1 bsh }
120 1.1 bsh #endif
121 1.1 bsh
122 1.1 bsh static void
123 1.1 bsh imx51_ipuv3_enable_display(struct imx51_ipuv3_softc *sc)
124 1.1 bsh {
125 1.1 bsh uint32_t reg = 0;
126 1.1 bsh
127 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
128 1.1 bsh
129 1.1 bsh /* enable sub modules */
130 1.1 bsh reg = IPUV3_READ(sc, cm, IPU_CM_CONF);
131 1.1 bsh reg |= CM_CONF_DP_EN |
132 1.1 bsh CM_CONF_DC_EN |
133 1.1 bsh CM_CONF_DMFC_EN |
134 1.1 bsh CM_CONF_DI0_EN;
135 1.1 bsh IPUV3_WRITE(sc, cm, IPU_CM_CONF, reg);
136 1.1 bsh }
137 1.1 bsh
138 1.1 bsh static void
139 1.1 bsh imx51_ipuv3_dmfc_init(struct imx51_ipuv3_softc *sc)
140 1.1 bsh {
141 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
142 1.1 bsh
143 1.1 bsh /* IC channel is disabled */
144 1.1 bsh IPUV3_WRITE(sc, dmfc, IPU_DMFC_IC_CTRL,
145 1.1 bsh IC_IN_PORT_DISABLE);
146 1.1 bsh
147 1.1 bsh IPUV3_WRITE(sc, dmfc, IPU_DMFC_WR_CHAN, 0x00000000);
148 1.1 bsh IPUV3_WRITE(sc, dmfc, IPU_DMFC_WR_CHAN_DEF, 0x20202020);
149 1.1 bsh IPUV3_WRITE(sc, dmfc, IPU_DMFC_DP_CHAN, 0x00000094);
150 1.1 bsh IPUV3_WRITE(sc, dmfc, IPU_DMFC_DP_CHAN_DEF, 0x202020F6);
151 1.1 bsh
152 1.1 bsh IPUV3_WRITE(sc, dmfc, IPU_DMFC_GENERAL1,
153 1.1 bsh DCDP_SYNC_PR_ROUNDROBIN);
154 1.1 bsh
155 1.1 bsh #ifdef IPUV3_DEBUG
156 1.1 bsh int i;
157 1.1 bsh printf("*** DMFC ***\n");
158 1.1 bsh for (i = 0; i <= 0x34; i += 4)
159 1.1 bsh printf("0x%08X = 0x%08X\n", i, IPUV3_READ(sc, dmfc, i));
160 1.1 bsh
161 1.1 bsh printf("%s: DMFC_IC_CTRL 0x%08X\n", __func__,
162 1.1 bsh IPUV3_READ(sc, dmfc, IPU_DMFC_IC_CTRL));
163 1.1 bsh printf("%s: IPU_DMFC_WR_CHAN 0x%08X\n", __func__,
164 1.1 bsh IPUV3_READ(sc, dmfc, IPU_DMFC_WR_CHAN));
165 1.1 bsh printf("%s: IPU_DMFC_WR_CHAN_DEF 0x%08X\n", __func__,
166 1.1 bsh IPUV3_READ(sc, dmfc, IPU_DMFC_WR_CHAN_DEF));
167 1.1 bsh printf("%s: IPU_DMFC_GENERAL1 0x%08X\n", __func__,
168 1.1 bsh IPUV3_READ(sc, dmfc, IPU_DMFC_GENERAL1));
169 1.1 bsh #endif
170 1.1 bsh }
171 1.1 bsh
172 1.1 bsh static void
173 1.1 bsh imx51_ipuv3_dc_map_clear(struct imx51_ipuv3_softc *sc, int map)
174 1.1 bsh {
175 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
176 1.1 bsh
177 1.1 bsh uint32_t reg;
178 1.1 bsh uint32_t addr;
179 1.1 bsh
180 1.1 bsh addr = IPU_DC_MAP_CONF_PNTR(map / 2);
181 1.1 bsh reg = IPUV3_READ(sc, dc, addr);
182 1.1 bsh reg &= ~(0xFFFF << (16 * (map & 0x1)));
183 1.1 bsh IPUV3_WRITE(sc, dc, addr, reg);
184 1.1 bsh }
185 1.1 bsh
186 1.1 bsh static void
187 1.1 bsh imx51_ipuv3_dc_map_conf(struct imx51_ipuv3_softc *sc,
188 1.1 bsh int map, int byte, int offset, uint8_t mask)
189 1.1 bsh {
190 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
191 1.1 bsh
192 1.1 bsh uint32_t reg;
193 1.1 bsh uint32_t addr;
194 1.1 bsh
195 1.1 bsh addr = IPU_DC_MAP_CONF_MASK((map * 3 + byte) / 2);
196 1.1 bsh reg = IPUV3_READ(sc, dc, addr);
197 1.1 bsh reg &= ~(0xFFFF << (16 * ((map * 3 + byte) & 0x1)));
198 1.1 bsh reg |= ((offset << 8) | mask) << (16 * ((map * 3 + byte) & 0x1));
199 1.1 bsh IPUV3_WRITE(sc, dc, addr, reg);
200 1.1 bsh #ifdef IPUV3_DEBUG
201 1.1 bsh printf("%s: addr 0x%08X reg 0x%08X\n", __func__, addr, reg);
202 1.1 bsh #endif
203 1.1 bsh
204 1.1 bsh addr = IPU_DC_MAP_CONF_PNTR(map / 2);
205 1.1 bsh reg = IPUV3_READ(sc, dc, addr);
206 1.1 bsh reg &= ~(0x1F << ((16 * (map & 0x1)) + (5 * byte)));
207 1.1 bsh reg |= ((map * 3) + byte) << ((16 * (map & 0x1)) + (5 * byte));
208 1.1 bsh IPUV3_WRITE(sc, dc, addr, reg);
209 1.1 bsh #ifdef IPUV3_DEBUG
210 1.1 bsh printf("%s: addr 0x%08X reg 0x%08X\n", __func__, addr, reg);
211 1.1 bsh #endif
212 1.1 bsh }
213 1.1 bsh
214 1.1 bsh static void
215 1.1 bsh imx51_ipuv3_dc_template_command(struct imx51_ipuv3_softc *sc,
216 1.1 bsh int index, int sync, int gluelogic, int waveform, int mapping,
217 1.1 bsh int operand, int opecode, int stop)
218 1.1 bsh {
219 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
220 1.1 bsh
221 1.1 bsh uint32_t reg;
222 1.1 bsh
223 1.1 bsh reg = (sync << 0) |
224 1.1 bsh (gluelogic << 4) |
225 1.1 bsh (waveform << 11) |
226 1.1 bsh (mapping << 15) |
227 1.1 bsh (operand << 20);
228 1.1 bsh IPUV3_WRITE(sc, dctmpl, index * 8, reg);
229 1.1 bsh #ifdef IPUV3_DEBUG
230 1.1 bsh printf("%s: addr 0x%08X reg 0x%08X\n", __func__, index * 8, reg);
231 1.1 bsh #endif
232 1.1 bsh reg = (opecode << 0) |
233 1.1 bsh (stop << 9);
234 1.1 bsh IPUV3_WRITE(sc, dctmpl, index * 8 + 4, reg);
235 1.1 bsh #ifdef IPUV3_DEBUG
236 1.1 bsh printf("%s: addr 0x%08X reg 0x%08X\n", __func__, index * 8 + 4, reg);
237 1.1 bsh #endif
238 1.1 bsh }
239 1.1 bsh
240 1.1 bsh static void
241 1.1 bsh imx51_ipuv3_set_routine_link(struct imx51_ipuv3_softc *sc,
242 1.1 bsh int base, int evt, int addr, int pri)
243 1.1 bsh {
244 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
245 1.1 bsh
246 1.1 bsh uint32_t reg;
247 1.1 bsh
248 1.1 bsh reg = IPUV3_READ(sc, dc, IPU_DC_RL(base, evt));
249 1.1 bsh reg &= ~(0xFFFF << (16 * (evt & 0x1)));
250 1.1 bsh reg |= ((addr << 8) | pri) << (16 * (evt & 0x1));
251 1.1 bsh IPUV3_WRITE(sc, dc, IPU_DC_RL(base, evt), reg);
252 1.1 bsh #ifdef IPUV3_DEBUG
253 1.1 bsh printf("%s: event %d addr %d priority %d\n", __func__,
254 1.1 bsh evt, addr, pri);
255 1.1 bsh printf("%s: %p = 0x%08X\n", __func__,
256 1.1 bsh (void *)IPU_DC_RL(base, evt), reg);
257 1.1 bsh #endif
258 1.1 bsh }
259 1.1 bsh
260 1.1 bsh static void
261 1.1 bsh imx51_ipuv3_dc_init(struct imx51_ipuv3_softc *sc)
262 1.1 bsh {
263 1.1 bsh uint32_t reg;
264 1.1 bsh
265 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
266 1.1 bsh
267 1.1 bsh imx51_ipuv3_dc_map_clear(sc, 0);
268 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 0, 0, 7, 0xff);
269 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 0, 1, 15, 0xff);
270 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 0, 2, 23, 0xff);
271 1.1 bsh imx51_ipuv3_dc_map_clear(sc, 1);
272 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 1, 0, 5, 0xfc);
273 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 1, 1, 11, 0xfc);
274 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 1, 2, 17, 0xfc);
275 1.1 bsh imx51_ipuv3_dc_map_clear(sc, 2);
276 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 2, 0, 15, 0xff);
277 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 2, 1, 23, 0xff);
278 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 2, 2, 7, 0xff);
279 1.1 bsh imx51_ipuv3_dc_map_clear(sc, 3);
280 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 3, 0, 4, 0xf8);
281 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 3, 1, 10, 0xfc);
282 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 3, 2, 15, 0xf8);
283 1.1 bsh imx51_ipuv3_dc_map_clear(sc, 4);
284 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 4, 0, 5, 0xfc);
285 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 4, 1, 13, 0xfc);
286 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 4, 2, 21, 0xfc);
287 1.1 bsh
288 1.1 bsh /* microcode */
289 1.1 bsh imx51_ipuv3_dc_template_command(sc,
290 1.1 bsh 5, 5, 8, 1, 5, 0, 0x180, 1);
291 1.1 bsh imx51_ipuv3_dc_template_command(sc,
292 1.1 bsh 6, 5, 4, 1, 5, 0, 0x180, 1);
293 1.1 bsh imx51_ipuv3_dc_template_command(sc,
294 1.1 bsh 7, 5, 0, 1, 5, 0, 0x180, 1);
295 1.1 bsh
296 1.1 bsh reg = (4 << 5) | 0x2;
297 1.1 bsh IPUV3_WRITE(sc, dc, IPU_DC_WR_CH_CONF_5, reg);
298 1.1 bsh IPUV3_WRITE(sc, dc, IPU_DC_WR_CH_CONF_1, 0x4);
299 1.1 bsh IPUV3_WRITE(sc, dc, IPU_DC_WR_CH_ADDR_5, 0x0);
300 1.1 bsh IPUV3_WRITE(sc, dc, IPU_DC_GEN, 0x44);
301 1.1 bsh
302 1.1 bsh imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_NL, 5, 3);
303 1.1 bsh imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_EOL, 6, 2);
304 1.1 bsh imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_NEW_DATA, 7, 1);
305 1.1 bsh imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_NF, 0, 0);
306 1.1 bsh imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_NFIELD, 0, 0);
307 1.1 bsh imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_EOF, 0, 0);
308 1.1 bsh imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_EOFIELD, 0, 0);
309 1.1 bsh imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_NEW_CHAN, 0, 0);
310 1.1 bsh imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_NEW_ADDR, 0, 0);
311 1.1 bsh
312 1.1 bsh #ifdef IPUV3_DEBUG
313 1.1 bsh int i;
314 1.1 bsh printf("*** DC ***\n");
315 1.1 bsh for (i = 0; i <= 0x1C8; i += 4)
316 1.1 bsh printf("0x%08X = 0x%08X\n", i, IPUV3_READ(sc, dc, i));
317 1.1 bsh printf("*** DCTEMPL ***\n");
318 1.1 bsh for (i = 0; i <= 0x100; i += 4)
319 1.1 bsh printf("0x%08X = 0x%08X\n", i, IPUV3_READ(sc, dctmpl, i));
320 1.1 bsh #endif
321 1.1 bsh }
322 1.1 bsh
323 1.1 bsh static void
324 1.1 bsh imx51_ipuv3_dc_display_config(struct imx51_ipuv3_softc *sc, int width)
325 1.1 bsh {
326 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
327 1.1 bsh
328 1.1 bsh IPUV3_WRITE(sc, dc, IPU_DC_DISP_CONF2_0, width);
329 1.1 bsh }
330 1.1 bsh
331 1.1 bsh static void
332 1.1 bsh imx51_ipuv3_di_sync_conf(struct imx51_ipuv3_softc *sc, int no,
333 1.1 bsh uint32_t reg_gen0, uint32_t reg_gen1, uint32_t repeat)
334 1.1 bsh {
335 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
336 1.1 bsh
337 1.1 bsh uint32_t reg;
338 1.1 bsh
339 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN0(no), reg_gen0);
340 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN1(no), reg_gen1);
341 1.1 bsh reg = IPUV3_READ(sc, di0, IPU_DI_STP_REP(no));
342 1.3 hkenken reg &= ~DI_STP_REP(no);
343 1.3 hkenken reg |= __SHIFTIN(repeat, DI_STP_REP(no));
344 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_STP_REP(no), reg);
345 1.1 bsh
346 1.1 bsh #ifdef IPUV3_DEBUG
347 1.1 bsh printf("%s: no %d\n", __func__, no);
348 1.1 bsh printf("%s: addr 0x%08X reg_gen0 0x%08X\n", __func__,
349 1.1 bsh IPU_DI_SW_GEN0(no), reg_gen0);
350 1.1 bsh printf("%s: addr 0x%08X reg_gen1 0x%08X\n", __func__,
351 1.1 bsh IPU_DI_SW_GEN1(no), reg_gen1);
352 1.1 bsh printf("%s: addr 0x%08X DI_STP_REP 0x%08X\n", __func__,
353 1.1 bsh IPU_DI_STP_REP(no), reg);
354 1.1 bsh #endif
355 1.1 bsh }
356 1.1 bsh
357 1.1 bsh static void
358 1.1 bsh imx51_ipuv3_di_init(struct imx51_ipuv3_softc *sc)
359 1.1 bsh {
360 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
361 1.1 bsh
362 1.1 bsh uint32_t reg;
363 1.1 bsh uint32_t div;
364 1.1 bsh u_int ipuclk;
365 1.1 bsh const struct lcd_panel_geometry *geom = sc->geometry;
366 1.1 bsh
367 1.1 bsh #if NIMXCCM > 0
368 1.1 bsh ipuclk = imx51_get_clock(IMX51CLK_IPU_HSP_CLK_ROOT);
369 1.1 bsh #elif !defined(IMX51_IPU_HSP_CLOCK)
370 1.1 bsh #error IMX51_CPU_HSP_CLOCK need to be defined.
371 1.1 bsh #else
372 1.1 bsh ipuclk = IMX51_IPU_HSP_CLOCK;
373 1.1 bsh #endif
374 1.1 bsh DPRINTFN(3, ("IPU HSP clock = %d\n", ipuclk));
375 1.1 bsh div = (ipuclk * 16) / geom->pixel_clk;
376 1.1 bsh div = div < 16 ? 16 : div & 0xff8;
377 1.1 bsh
378 1.1 bsh /* DI counter */
379 1.1 bsh reg = IPUV3_READ(sc, cm, IPU_CM_DISP_GEN);
380 1.1 bsh reg &= ~(CM_DISP_GEN_DI1_COUNTER_RELEASE |
381 1.1 bsh CM_DISP_GEN_DI0_COUNTER_RELEASE);
382 1.1 bsh IPUV3_WRITE(sc, cm, IPU_CM_DISP_GEN, reg);
383 1.1 bsh
384 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_BS_CLKGEN0, div);
385 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_BS_CLKGEN1,
386 1.3 hkenken __SHIFTIN(div / 16, DI_BS_CLKGEN1_DOWN));
387 1.1 bsh #ifdef IPUV3_DEBUG
388 1.1 bsh printf("%s: IPU_DI_BS_CLKGEN0 = 0x%08X\n", __func__,
389 1.1 bsh IPUV3_READ(sc, di0, IPU_DI_BS_CLKGEN0));
390 1.1 bsh printf("%s: IPU_DI_BS_CLKGEN1 = 0x%08X\n", __func__,
391 1.1 bsh IPUV3_READ(sc, di0, IPU_DI_BS_CLKGEN1));
392 1.1 bsh #endif
393 1.1 bsh /* Display Time settings */
394 1.3 hkenken reg = __SHIFTIN(div / 16 - 1, DI_DW_GEN_ACCESS_SIZE) |
395 1.3 hkenken __SHIFTIN(div / 16 - 1, DI_DW_GEN_COMPONNENT_SIZE) |
396 1.3 hkenken __SHIFTIN(3, DI_DW_GEN_PIN(15));
397 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_DW_GEN(0), reg);
398 1.1 bsh #ifdef IPUV3_DEBUG
399 1.1 bsh printf("%s: div = %d\n", __func__, div);
400 1.1 bsh printf("%s: IPU_DI_DW_GEN(0) 0x%08X = 0x%08X\n", __func__,
401 1.1 bsh IPU_DI_DW_GEN(0), reg);
402 1.1 bsh #endif
403 1.1 bsh
404 1.1 bsh /* Up & Down Data Wave Set */
405 1.3 hkenken reg = __SHIFTIN(div / 16 * 2, DI_DW_SET_DOWN);
406 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_DW_SET(0, 3), reg);
407 1.1 bsh #ifdef IPUV3_DEBUG
408 1.1 bsh printf("%s: IPU_DI_DW_SET(0, 3) 0x%08X = 0x%08X\n", __func__,
409 1.1 bsh IPU_DI_DW_SET(0, 3), reg);
410 1.1 bsh #endif
411 1.1 bsh
412 1.1 bsh /* internal HSCYNC */
413 1.1 bsh imx51_ipuv3_di_sync_conf(sc, 1,
414 1.1 bsh __DI_SW_GEN0(geom->panel_width + geom->hsync_width +
415 1.1 bsh geom->left + geom->right - 1, 1, 0, 0),
416 1.1 bsh __DI_SW_GEN1(0, 1, 0, 0, 0, 0, 0),
417 1.1 bsh 0);
418 1.1 bsh
419 1.1 bsh /* HSYNC */
420 1.1 bsh imx51_ipuv3_di_sync_conf(sc, 2,
421 1.1 bsh __DI_SW_GEN0(geom->panel_width + geom->hsync_width +
422 1.1 bsh geom->left + geom->right - 1, 1, 0, 1),
423 1.1 bsh __DI_SW_GEN1(1, 1, 0, geom->hsync_width * 2, 1, 0, 0),
424 1.1 bsh 0);
425 1.1 bsh
426 1.1 bsh /* VSYNC */
427 1.1 bsh imx51_ipuv3_di_sync_conf(sc, 3,
428 1.1 bsh __DI_SW_GEN0(geom->panel_height + geom->vsync_width +
429 1.1 bsh geom->upper + geom->lower - 1, 2, 0, 0),
430 1.1 bsh __DI_SW_GEN1(1, 1, 0, geom->vsync_width * 2, 2, 0, 0),
431 1.1 bsh 0);
432 1.1 bsh
433 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SCR_CONF,
434 1.1 bsh geom->panel_height + geom->vsync_width + geom->upper +
435 1.1 bsh geom->lower - 1);
436 1.1 bsh
437 1.1 bsh /* Active Lines Start */
438 1.1 bsh imx51_ipuv3_di_sync_conf(sc, 4,
439 1.1 bsh __DI_SW_GEN0(0, 3, geom->vsync_width + geom->upper, 3),
440 1.1 bsh __DI_SW_GEN1(0, 0, 4, 0, 0, 0, 0),
441 1.1 bsh geom->panel_height);
442 1.1 bsh
443 1.1 bsh /* Active Clock Start */
444 1.1 bsh imx51_ipuv3_di_sync_conf(sc, 5,
445 1.1 bsh __DI_SW_GEN0(0, 1, geom->hsync_width + geom->left, 1),
446 1.1 bsh __DI_SW_GEN1(0, 0, 5, 0, 0, 0, 0),
447 1.1 bsh geom->panel_width);
448 1.1 bsh
449 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN0(6), 0);
450 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN1(6), 0);
451 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN0(7), 0);
452 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN1(7), 0);
453 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN0(8), 0);
454 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN1(8), 0);
455 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN0(9), 0);
456 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN1(9), 0);
457 1.1 bsh
458 1.1 bsh reg = IPUV3_READ(sc, di0, IPU_DI_STP_REP(6));
459 1.3 hkenken reg &= ~DI_STP_REP(6);
460 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_STP_REP(6), reg);
461 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_STP_REP(7), 0);
462 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_STP_REP(9), 0);
463 1.1 bsh
464 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_GENERAL, 0);
465 1.3 hkenken reg = __SHIFTIN(3 - 1, DI_SYNC_AS_GEN_VSYNC_SEL) |
466 1.3 hkenken __SHIFTIN(0x2, DI_SYNC_AS_GEN_SYNC_START);
467 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SYNC_AS_GEN, reg);
468 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_POL, DI_POL_DRDY_POLARITY_15);
469 1.1 bsh
470 1.1 bsh /* release DI counter */
471 1.1 bsh reg = IPUV3_READ(sc, cm, IPU_CM_DISP_GEN);
472 1.1 bsh reg |= CM_DISP_GEN_DI0_COUNTER_RELEASE;
473 1.1 bsh IPUV3_WRITE(sc, cm, IPU_CM_DISP_GEN, reg);
474 1.1 bsh
475 1.1 bsh #ifdef IPUV3_DEBUG
476 1.1 bsh int i;
477 1.1 bsh printf("*** DI0 ***\n");
478 1.1 bsh for (i = 0; i <= 0x174; i += 4)
479 1.1 bsh printf("0x%08X = 0x%08X\n", i, IPUV3_READ(sc, di0, i));
480 1.1 bsh
481 1.1 bsh printf("%s: IPU_CM_DISP_GEN : 0x%08X\n", __func__,
482 1.1 bsh IPUV3_READ(sc, cm, IPU_CM_DISP_GEN));
483 1.1 bsh printf("%s: IPU_DI_SYNC_AS_GEN : 0x%08X\n", __func__,
484 1.1 bsh IPUV3_READ(sc, di0, IPU_DI_SYNC_AS_GEN));
485 1.1 bsh printf("%s: IPU_DI_GENERAL : 0x%08X\n", __func__,
486 1.1 bsh IPUV3_READ(sc, di0, IPU_DI_GENERAL));
487 1.1 bsh printf("%s: IPU_DI_POL : 0x%08X\n", __func__,
488 1.1 bsh IPUV3_READ(sc, di0, IPU_DI_POL));
489 1.1 bsh #endif
490 1.1 bsh }
491 1.1 bsh
492 1.1 bsh
493 1.1 bsh void
494 1.1 bsh imx51_ipuv3_geometry(struct imx51_ipuv3_softc *sc,
495 1.1 bsh const struct lcd_panel_geometry *geom)
496 1.1 bsh {
497 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
498 1.1 bsh
499 1.1 bsh sc->geometry = geom;
500 1.1 bsh
501 1.1 bsh #ifdef IPUV3_DEBUG
502 1.1 bsh printf("%s: screen height = %d\n",__func__ , geom->panel_height);
503 1.1 bsh printf("%s: width = %d\n",__func__ , geom->panel_width);
504 1.1 bsh printf("%s: IPU Clock = %d\n", __func__,
505 1.1 bsh imx51_get_clock(IMX51CLK_IPU_HSP_CLK_ROOT));
506 1.1 bsh printf("%s: Pixel Clock = %d\n", __func__, geom->pixel_clk);
507 1.1 bsh #endif
508 1.1 bsh
509 1.1 bsh imx51_ipuv3_di_init(sc);
510 1.1 bsh
511 1.1 bsh #ifdef IPUV3_DEBUG
512 1.1 bsh printf("%s: IPU_CM_DISP_GEN : 0x%08X\n", __func__,
513 1.1 bsh IPUV3_READ(sc, cm, IPU_CM_DISP_GEN));
514 1.1 bsh #endif
515 1.1 bsh
516 1.1 bsh imx51_ipuv3_dc_display_config(sc, geom->panel_width);
517 1.1 bsh
518 1.1 bsh return;
519 1.1 bsh }
520 1.1 bsh
521 1.1 bsh /*
522 1.1 bsh * Initialize the IPUV3 controller.
523 1.1 bsh */
524 1.1 bsh static void
525 1.1 bsh imx51_ipuv3_initialize(struct imx51_ipuv3_softc *sc,
526 1.1 bsh const struct lcd_panel_geometry *geom)
527 1.1 bsh {
528 1.1 bsh uint32_t reg;
529 1.1 bsh
530 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
531 1.1 bsh
532 1.1 bsh IPUV3_WRITE(sc, cm, IPU_CM_CONF, 0);
533 1.1 bsh
534 1.1 bsh /* reset */
535 1.1 bsh IPUV3_WRITE(sc, cm, IPU_CM_MEM_RST, CM_MEM_START | CM_MEM_EN);
536 1.1 bsh while (IPUV3_READ(sc, cm, IPU_CM_MEM_RST) & CM_MEM_START)
537 1.1 bsh ; /* wait */
538 1.1 bsh
539 1.1 bsh imx51_ipuv3_dmfc_init(sc);
540 1.1 bsh imx51_ipuv3_dc_init(sc);
541 1.1 bsh
542 1.1 bsh imx51_ipuv3_geometry(sc, geom);
543 1.1 bsh
544 1.1 bsh /* set global alpha */
545 1.1 bsh IPUV3_WRITE(sc, dp, IPU_DP_GRAPH_WIND_CTRL_SYNC, 0x80 << 24);
546 1.1 bsh IPUV3_WRITE(sc, dp, IPU_DP_COM_CONF_SYNC, DP_DP_GWAM_SYNC);
547 1.1 bsh
548 1.1 bsh reg = IPUV3_READ(sc, cm, IPU_CM_DISP_GEN);
549 1.1 bsh reg |= CM_DISP_GEN_MCU_MAX_BURST_STOP |
550 1.3 hkenken __SHIFTIN(0x8, CM_DISP_GEN_MCU_T);
551 1.1 bsh IPUV3_WRITE(sc, cm, IPU_CM_DISP_GEN, reg);
552 1.1 bsh }
553 1.1 bsh
554 1.4 hkenken static int
555 1.4 hkenken imx51_ipuv3_print(void *aux, const char *pnp)
556 1.1 bsh {
557 1.4 hkenken const struct imxfb_attach_args * const ifb = aux;
558 1.1 bsh
559 1.4 hkenken aprint_normal(" output %s", device_xname(ifb->ifb_outputdev));
560 1.1 bsh
561 1.4 hkenken return UNCONF;
562 1.1 bsh }
563 1.1 bsh
564 1.1 bsh /*
565 1.1 bsh * Common driver attachment code.
566 1.1 bsh */
567 1.1 bsh void
568 1.1 bsh imx51_ipuv3_attach_sub(struct imx51_ipuv3_softc *sc,
569 1.1 bsh struct axi_attach_args *axia, const struct lcd_panel_geometry *geom)
570 1.1 bsh {
571 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
572 1.1 bsh
573 1.1 bsh bus_space_tag_t iot = axia->aa_iot;
574 1.1 bsh int error;
575 1.1 bsh
576 1.1 bsh aprint_normal(": i.MX51 IPUV3 controller\n");
577 1.1 bsh
578 1.1 bsh sc->n_screens = 0;
579 1.1 bsh LIST_INIT(&sc->screens);
580 1.1 bsh
581 1.1 bsh sc->iot = iot;
582 1.7 ryo sc->dma_tag = &arm_generic_dma_tag;
583 1.1 bsh
584 1.1 bsh /* map controller registers */
585 1.4 hkenken error = bus_space_map(iot, IPU_CM_BASE, IPU_CM_SIZE, 0, &sc->cm_ioh);
586 1.1 bsh if (error)
587 1.1 bsh goto fail_retarn_cm;
588 1.1 bsh
589 1.1 bsh /* map Display Multi FIFO Controller registers */
590 1.4 hkenken error = bus_space_map(iot, IPU_DMFC_BASE, IPU_DMFC_SIZE, 0, &sc->dmfc_ioh);
591 1.1 bsh if (error)
592 1.1 bsh goto fail_retarn_dmfc;
593 1.1 bsh
594 1.1 bsh /* map Display Interface registers */
595 1.4 hkenken error = bus_space_map(iot, IPU_DI0_BASE, IPU_DI0_SIZE, 0, &sc->di0_ioh);
596 1.1 bsh if (error)
597 1.1 bsh goto fail_retarn_di0;
598 1.1 bsh
599 1.1 bsh /* map Display Processor registers */
600 1.4 hkenken error = bus_space_map(iot, IPU_DP_BASE, IPU_DP_SIZE, 0, &sc->dp_ioh);
601 1.1 bsh if (error)
602 1.1 bsh goto fail_retarn_dp;
603 1.1 bsh
604 1.1 bsh /* map Display Controller registers */
605 1.4 hkenken error = bus_space_map(iot, IPU_DC_BASE, IPU_DC_SIZE, 0, &sc->dc_ioh);
606 1.1 bsh if (error)
607 1.1 bsh goto fail_retarn_dc;
608 1.1 bsh
609 1.1 bsh /* map Image DMA Controller registers */
610 1.4 hkenken error = bus_space_map(iot, IPU_IDMAC_BASE, IPU_IDMAC_SIZE, 0, &sc->idmac_ioh);
611 1.1 bsh if (error)
612 1.1 bsh goto fail_retarn_idmac;
613 1.1 bsh
614 1.1 bsh /* map CPMEM registers */
615 1.4 hkenken error = bus_space_map(iot, IPU_CPMEM_BASE, IPU_CPMEM_SIZE, 0, &sc->cpmem_ioh);
616 1.1 bsh if (error)
617 1.1 bsh goto fail_retarn_cpmem;
618 1.1 bsh
619 1.1 bsh /* map DCTEMPL registers */
620 1.4 hkenken error = bus_space_map(iot, IPU_DCTMPL_BASE, IPU_DCTMPL_SIZE, 0, &sc->dctmpl_ioh);
621 1.1 bsh if (error)
622 1.1 bsh goto fail_retarn_dctmpl;
623 1.1 bsh
624 1.1 bsh #ifdef notyet
625 1.1 bsh sc->ih = imx51_ipuv3_intr_establish(IMX51_INT_IPUV3, IPL_BIO,
626 1.1 bsh ipuv3intr, sc);
627 1.1 bsh if (sc->ih == NULL) {
628 1.1 bsh aprint_error_dev(sc->dev,
629 1.1 bsh "unable to establish interrupt at irq %d\n",
630 1.1 bsh IMX51_INT_IPUV3);
631 1.1 bsh return;
632 1.1 bsh }
633 1.1 bsh #endif
634 1.1 bsh
635 1.1 bsh imx51_ipuv3_initialize(sc, geom);
636 1.1 bsh
637 1.1 bsh struct imx51_ipuv3_screen *scr;
638 1.4 hkenken error = imx51_ipuv3_new_screen(sc, &scr);
639 1.1 bsh if (error) {
640 1.1 bsh aprint_error_dev(sc->dev,
641 1.1 bsh "unable to create new screen (errno=%d)", error);
642 1.1 bsh return;
643 1.1 bsh }
644 1.1 bsh sc->active = scr;
645 1.1 bsh
646 1.4 hkenken imx51_ipuv3_start_dma(sc, scr);
647 1.2 hkenken
648 1.4 hkenken struct imxfb_attach_args ifb = {
649 1.4 hkenken .ifb_dmat = sc->dma_tag,
650 1.4 hkenken .ifb_dmamap = scr->dma,
651 1.4 hkenken .ifb_dmasegs = scr->segs,
652 1.4 hkenken .ifb_ndmasegs = scr->nsegs,
653 1.4 hkenken .ifb_fb = scr->buf_va,
654 1.4 hkenken .ifb_width = geom->panel_width,
655 1.4 hkenken .ifb_height = geom->panel_height,
656 1.4 hkenken .ifb_depth = scr->depth,
657 1.4 hkenken .ifb_stride = geom->panel_width * (scr->depth / 8),
658 1.4 hkenken .ifb_outputdev = sc->dev,
659 1.4 hkenken };
660 1.1 bsh
661 1.11 thorpej sc->fbdev = config_found(sc->dev, &ifb, imx51_ipuv3_print, CFARGS_NONE);
662 1.2 hkenken
663 1.1 bsh return;
664 1.1 bsh
665 1.1 bsh fail_retarn_dctmpl:
666 1.1 bsh bus_space_unmap(sc->iot, sc->cpmem_ioh, IPU_CPMEM_SIZE);
667 1.1 bsh fail_retarn_cpmem:
668 1.1 bsh bus_space_unmap(sc->iot, sc->idmac_ioh, IPU_IDMAC_SIZE);
669 1.1 bsh fail_retarn_idmac:
670 1.1 bsh bus_space_unmap(sc->iot, sc->dc_ioh, IPU_DC_SIZE);
671 1.1 bsh fail_retarn_dp:
672 1.1 bsh bus_space_unmap(sc->iot, sc->dp_ioh, IPU_DP_SIZE);
673 1.1 bsh fail_retarn_dc:
674 1.1 bsh bus_space_unmap(sc->iot, sc->di0_ioh, IPU_DI0_SIZE);
675 1.1 bsh fail_retarn_di0:
676 1.1 bsh bus_space_unmap(sc->iot, sc->dmfc_ioh, IPU_DMFC_SIZE);
677 1.1 bsh fail_retarn_dmfc:
678 1.1 bsh bus_space_unmap(sc->iot, sc->dc_ioh, IPU_CM_SIZE);
679 1.1 bsh fail_retarn_cm:
680 1.1 bsh aprint_error_dev(sc->dev,
681 1.1 bsh "failed to map registers (errno=%d)\n", error);
682 1.1 bsh return;
683 1.1 bsh }
684 1.1 bsh
685 1.1 bsh #ifdef notyet
686 1.1 bsh /*
687 1.1 bsh * Interrupt handler.
688 1.1 bsh */
689 1.1 bsh int
690 1.1 bsh ipuv3intr(void *arg)
691 1.1 bsh {
692 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
693 1.1 bsh
694 1.1 bsh struct imx51_ipuv3_softc *sc = (struct imx51_ipuv3_softc *)arg;
695 1.1 bsh bus_space_tag_t iot = sc->iot;
696 1.1 bsh bus_space_handle_t ioh = sc->dc_ioh;
697 1.1 bsh uint32_t status;
698 1.1 bsh
699 1.1 bsh status = IPUV3_READ(ioh, V3CR);
700 1.1 bsh /* Clear stickey status bits */
701 1.1 bsh IPUV3_WRITE(ioh, V3CR, status);
702 1.1 bsh
703 1.1 bsh return 1;
704 1.1 bsh }
705 1.1 bsh #endif
706 1.1 bsh
707 1.1 bsh static void
708 1.1 bsh imx51_ipuv3_write_dmaparam(struct imx51_ipuv3_softc *sc,
709 1.1 bsh int ch, uint32_t *value, int size)
710 1.1 bsh {
711 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
712 1.1 bsh
713 1.1 bsh int i;
714 1.1 bsh uint32_t addr = ch * 0x40;
715 1.1 bsh
716 1.1 bsh for (i = 0; i < size; i++) {
717 1.1 bsh IPUV3_WRITE(sc, cpmem, addr + ((i % 5) * 0x4) +
718 1.1 bsh ((i / 5) * 0x20), value[i]);
719 1.1 bsh #ifdef IPUV3_DEBUG
720 1.1 bsh printf("%s: addr = 0x%08X, val = 0x%08X\n", __func__,
721 1.1 bsh addr + ((i % 5) * 0x4) + ((i / 5) * 0x20),
722 1.1 bsh IPUV3_READ(sc, cpmem, addr + ((i % 5) * 0x4) +
723 1.1 bsh ((i / 5) * 0x20)));
724 1.1 bsh #endif
725 1.1 bsh }
726 1.1 bsh }
727 1.1 bsh
728 1.1 bsh static void
729 1.1 bsh imx51_ipuv3_build_param(struct imx51_ipuv3_softc *sc,
730 1.1 bsh struct imx51_ipuv3_screen *scr,
731 1.1 bsh uint32_t *params)
732 1.1 bsh {
733 1.1 bsh const struct lcd_panel_geometry *geom = sc->geometry;
734 1.1 bsh
735 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
736 1.1 bsh
737 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_FW,
738 1.1 bsh (geom->panel_width - 1));
739 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_FH,
740 1.1 bsh (geom->panel_height - 1));
741 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_EBA0,
742 1.1 bsh scr->segs[0].ds_addr >> 3);
743 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_EBA1,
744 1.1 bsh scr->segs[0].ds_addr >> 3);
745 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_SL,
746 1.1 bsh (scr->stride - 1));
747 1.1 bsh
748 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_PFS, 0x7);
749 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_NPB, 32 - 1);
750 1.1 bsh
751 1.1 bsh switch (scr->depth) {
752 1.1 bsh case 32:
753 1.1 bsh /* ARBG888 */
754 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_BPP, 0x0);
755 1.1 bsh
756 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS0, 0);
757 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS1, 8);
758 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS2, 16);
759 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS3, 24);
760 1.1 bsh
761 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID0, 8 - 1);
762 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID1, 8 - 1);
763 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID2, 8 - 1);
764 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID3, 8 - 1);
765 1.1 bsh break;
766 1.1 bsh case 24:
767 1.1 bsh /* RBG888 */
768 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_BPP, 0x1);
769 1.1 bsh
770 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS0, 0);
771 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS1, 8);
772 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS2, 16);
773 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS3, 24);
774 1.1 bsh
775 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID0, 8 - 1);
776 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID1, 8 - 1);
777 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID2, 8 - 1);
778 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID3, 0);
779 1.1 bsh break;
780 1.1 bsh case 16:
781 1.1 bsh /* RBG565 */
782 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_BPP, 0x3);
783 1.1 bsh
784 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS0, 0);
785 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS1, 5);
786 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS2, 11);
787 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS3, 16);
788 1.1 bsh
789 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID0, 5 - 1);
790 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID1, 6 - 1);
791 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID2, 5 - 1);
792 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID3, 0);
793 1.1 bsh break;
794 1.1 bsh default:
795 1.1 bsh panic("%s: unsupported depth %d\n", __func__, scr->depth);
796 1.1 bsh break;
797 1.1 bsh }
798 1.1 bsh
799 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_ID, 1);
800 1.1 bsh }
801 1.1 bsh
802 1.1 bsh static void
803 1.1 bsh imx51_ipuv3_set_idma_param(uint32_t *params, uint32_t name, uint32_t val)
804 1.1 bsh {
805 1.1 bsh int word = (name >> 16) & 0xff;
806 1.1 bsh int shift = (name >> 8) & 0xff;
807 1.1 bsh int width = name & 0xff;
808 1.1 bsh int index;
809 1.1 bsh
810 1.1 bsh index = word * 5;
811 1.1 bsh index += shift / 32;
812 1.1 bsh shift = shift % 32;
813 1.1 bsh
814 1.1 bsh params[index] |= val << shift;
815 1.1 bsh shift = 32 - shift;
816 1.1 bsh
817 1.1 bsh if (width > shift)
818 1.1 bsh params[index+1] |= val >> shift;
819 1.1 bsh }
820 1.1 bsh
821 1.1 bsh /*
822 1.1 bsh * Enable DMA to cause the display to be refreshed periodically.
823 1.1 bsh * This brings the screen to life...
824 1.1 bsh */
825 1.1 bsh void
826 1.1 bsh imx51_ipuv3_start_dma(struct imx51_ipuv3_softc *sc,
827 1.1 bsh struct imx51_ipuv3_screen *scr)
828 1.1 bsh {
829 1.1 bsh int save;
830 1.1 bsh uint32_t params[10];
831 1.1 bsh uint32_t reg;
832 1.1 bsh
833 1.1 bsh DPRINTFN(3, ("%s: Pixel depth = %d\n", __func__, scr->depth));
834 1.1 bsh
835 1.1 bsh reg = IPUV3_READ(sc, idmac, IPU_IDMAC_CH_EN_1);
836 1.1 bsh reg &= ~__BIT(CH_PANNEL_BG);
837 1.1 bsh IPUV3_WRITE(sc, idmac, IPU_IDMAC_CH_EN_1, reg);
838 1.1 bsh
839 1.1 bsh memset(params, 0, sizeof(params));
840 1.1 bsh imx51_ipuv3_build_param(sc, scr, params);
841 1.1 bsh
842 1.1 bsh save = disable_interrupts(I32_bit);
843 1.1 bsh
844 1.1 bsh /* IDMAC configuration */
845 1.1 bsh imx51_ipuv3_write_dmaparam(sc, CH_PANNEL_BG, params,
846 1.1 bsh sizeof(params) / sizeof(params[0]));
847 1.1 bsh
848 1.1 bsh IPUV3_WRITE(sc, idmac, IPU_IDMAC_CH_PRI_1, __BIT(CH_PANNEL_BG));
849 1.1 bsh
850 1.1 bsh /* double buffer */
851 1.1 bsh reg = IPUV3_READ(sc, cm, IPU_CM_CH_DB_MODE_SEL_0);
852 1.1 bsh reg |= __BIT(CH_PANNEL_BG);
853 1.1 bsh IPUV3_WRITE(sc, cm, IPU_CM_CH_DB_MODE_SEL_0, reg);
854 1.1 bsh
855 1.1 bsh reg = IPUV3_READ(sc, idmac, IPU_IDMAC_CH_EN_1);
856 1.1 bsh reg |= __BIT(CH_PANNEL_BG);
857 1.1 bsh IPUV3_WRITE(sc, idmac, IPU_IDMAC_CH_EN_1, reg);
858 1.1 bsh
859 1.1 bsh reg = IPUV3_READ(sc, cm, IPU_CM_GPR);
860 1.1 bsh reg &= ~CM_GPR_IPU_CH_BUF0_RDY0_CLR;
861 1.1 bsh IPUV3_WRITE(sc, cm, IPU_CM_GPR, reg);
862 1.1 bsh
863 1.1 bsh IPUV3_WRITE(sc, cm, IPU_CM_CUR_BUF_0, __BIT(CH_PANNEL_BG));
864 1.1 bsh
865 1.1 bsh restore_interrupts(save);
866 1.1 bsh
867 1.1 bsh imx51_ipuv3_enable_display(sc);
868 1.1 bsh
869 1.1 bsh #ifdef IPUV3_DEBUG
870 1.1 bsh imx51_ipuv3_dump(sc);
871 1.1 bsh #endif
872 1.1 bsh }
873 1.1 bsh
874 1.4 hkenken static int
875 1.4 hkenken imx51_ipuv3_allocmem(struct imx51_ipuv3_softc *sc,
876 1.4 hkenken struct imx51_ipuv3_screen *scr)
877 1.1 bsh {
878 1.4 hkenken int error;
879 1.4 hkenken
880 1.4 hkenken error = bus_dmamem_alloc(sc->dma_tag, scr->buf_size, PAGE_SIZE, 0,
881 1.4 hkenken scr->segs, 1, &scr->nsegs, BUS_DMA_WAITOK);
882 1.4 hkenken if (error)
883 1.4 hkenken return error;
884 1.4 hkenken error = bus_dmamem_map(sc->dma_tag, scr->segs, scr->nsegs, scr->buf_size,
885 1.4 hkenken (void **)&scr->buf_va, BUS_DMA_WAITOK | BUS_DMA_COHERENT);
886 1.4 hkenken if (error)
887 1.4 hkenken goto free;
888 1.4 hkenken /* map memory for DMA */
889 1.4 hkenken error = bus_dmamap_create(sc->dma_tag, scr->buf_size, 1, scr->buf_size, 0,
890 1.4 hkenken BUS_DMA_WAITOK, &scr->dma);
891 1.4 hkenken if (error)
892 1.4 hkenken goto unmap;
893 1.4 hkenken error = bus_dmamap_load(sc->dma_tag, scr->dma, scr->buf_va, scr->buf_size,
894 1.4 hkenken NULL, BUS_DMA_WAITOK);
895 1.4 hkenken if (error)
896 1.4 hkenken goto destroy;
897 1.4 hkenken
898 1.4 hkenken memset(scr->buf_va, 0, scr->buf_size);
899 1.4 hkenken
900 1.4 hkenken return 0;
901 1.4 hkenken
902 1.4 hkenken destroy:
903 1.4 hkenken bus_dmamap_destroy(sc->dma_tag, scr->dma);
904 1.4 hkenken unmap:
905 1.4 hkenken bus_dmamem_unmap(sc->dma_tag, scr->buf_va, scr->buf_size);
906 1.4 hkenken free:
907 1.4 hkenken bus_dmamem_free(sc->dma_tag, scr->segs, scr->nsegs);
908 1.4 hkenken
909 1.4 hkenken scr->buf_size = 0;
910 1.4 hkenken scr->buf_va = NULL;
911 1.1 bsh
912 1.4 hkenken return error;
913 1.1 bsh }
914 1.1 bsh
915 1.1 bsh /*
916 1.1 bsh * Create and initialize a new screen buffer.
917 1.1 bsh */
918 1.1 bsh int
919 1.4 hkenken imx51_ipuv3_new_screen(struct imx51_ipuv3_softc *sc,
920 1.1 bsh struct imx51_ipuv3_screen **scrpp)
921 1.1 bsh {
922 1.1 bsh const struct lcd_panel_geometry *geometry;
923 1.1 bsh struct imx51_ipuv3_screen *scr = NULL;
924 1.4 hkenken int depth, width, height;
925 1.1 bsh int error;
926 1.1 bsh
927 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
928 1.1 bsh
929 1.1 bsh geometry = sc->geometry;
930 1.1 bsh
931 1.4 hkenken depth = geometry->depth;
932 1.1 bsh width = geometry->panel_width;
933 1.1 bsh height = geometry->panel_height;
934 1.1 bsh
935 1.9 thorpej scr = kmem_zalloc(sizeof(*scr), KM_SLEEP);
936 1.1 bsh scr->nsegs = 0;
937 1.1 bsh scr->depth = depth;
938 1.1 bsh scr->stride = width * depth / 8;
939 1.4 hkenken scr->buf_size = scr->stride * height;
940 1.1 bsh scr->buf_va = NULL;
941 1.1 bsh
942 1.4 hkenken error = imx51_ipuv3_allocmem(sc, scr);
943 1.4 hkenken if (error) {
944 1.4 hkenken aprint_error_dev(sc->dev,
945 1.4 hkenken "failed to allocate %u bytes of video memory: %d\n",
946 1.4 hkenken scr->stride * height, error);
947 1.9 thorpej kmem_free(scr, sizeof(*scr));
948 1.4 hkenken return error;
949 1.1 bsh }
950 1.1 bsh
951 1.1 bsh LIST_INSERT_HEAD(&sc->screens, scr, link);
952 1.1 bsh sc->n_screens++;
953 1.1 bsh
954 1.1 bsh #ifdef IPUV3_DEBUG
955 1.1 bsh printf("%s: screen buffer width %d\n", __func__, width);
956 1.1 bsh printf("%s: screen buffer height %d\n", __func__, height);
957 1.1 bsh printf("%s: screen buffer depth %d\n", __func__, depth);
958 1.1 bsh printf("%s: screen buffer stride %d\n", __func__, scr->stride);
959 1.1 bsh printf("%s: screen buffer size 0x%08X\n", __func__,
960 1.1 bsh (uint32_t)scr->buf_size);
961 1.1 bsh printf("%s: screen buffer addr virtual %p\n", __func__, scr->buf_va);
962 1.1 bsh printf("%s: screen buffer addr physical %p\n", __func__,
963 1.1 bsh (void *)scr->segs[0].ds_addr);
964 1.1 bsh #endif
965 1.1 bsh
966 1.4 hkenken scr->map_size = scr->buf_size; /* used when unmap this. */
967 1.1 bsh
968 1.1 bsh *scrpp = scr;
969 1.1 bsh
970 1.1 bsh return 0;
971 1.1 bsh }
972