imx51_ipuv3.c revision 1.1 1 1.1 bsh /* $NetBSD: imx51_ipuv3.c,v 1.1 2012/04/17 10:19:57 bsh 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.1 bsh __KERNEL_RCSID(0, "$NetBSD: imx51_ipuv3.c,v 1.1 2012/04/17 10:19:57 bsh Exp $");
31 1.1 bsh
32 1.1 bsh #include <sys/param.h>
33 1.1 bsh #include <sys/systm.h>
34 1.1 bsh #include <sys/conf.h>
35 1.1 bsh #include <sys/uio.h>
36 1.1 bsh #include <sys/malloc.h>
37 1.1 bsh #include <sys/kernel.h> /* for cold */
38 1.1 bsh
39 1.1 bsh #include <uvm/uvm_extern.h>
40 1.1 bsh
41 1.1 bsh #include <dev/cons.h>
42 1.1 bsh #include <dev/wscons/wsconsio.h>
43 1.1 bsh #include <dev/wscons/wsdisplayvar.h>
44 1.1 bsh #include <dev/wscons/wscons_callbacks.h>
45 1.1 bsh #include <dev/rasops/rasops.h>
46 1.1 bsh #include <dev/wsfont/wsfont.h>
47 1.1 bsh #include <dev/wscons/wsdisplay_vconsvar.h>
48 1.1 bsh
49 1.1 bsh #include <sys/bus.h>
50 1.1 bsh #include <machine/cpu.h>
51 1.1 bsh #include <arm/cpufunc.h>
52 1.1 bsh
53 1.1 bsh #include <arm/imx/imx51var.h>
54 1.1 bsh #include <arm/imx/imx51reg.h>
55 1.1 bsh #include <arm/imx/imx51_ipuv3var.h>
56 1.1 bsh #include <arm/imx/imx51_ipuv3reg.h>
57 1.1 bsh #include <arm/imx/imx51_ccmvar.h>
58 1.1 bsh #include <arm/imx/imx51_ccmreg.h>
59 1.1 bsh
60 1.1 bsh #include "imxccm.h" /* if CCM driver is configured into the kernel */
61 1.1 bsh #include "wsdisplay.h"
62 1.1 bsh #include "opt_imx51_ipuv3.h"
63 1.1 bsh
64 1.1 bsh /*
65 1.1 bsh * Console variables. These are necessary since console is setup very early,
66 1.1 bsh * before devices get attached.
67 1.1 bsh */
68 1.1 bsh struct {
69 1.1 bsh int is_console;
70 1.1 bsh } imx51_ipuv3_console;
71 1.1 bsh
72 1.1 bsh #define IPUV3_READ(ipuv3, module, reg) \
73 1.1 bsh bus_space_read_4((ipuv3)->iot, (ipuv3)->module##_ioh, (reg))
74 1.1 bsh #define IPUV3_WRITE(ipuv3, module, reg, val) \
75 1.1 bsh bus_space_write_4((ipuv3)->iot, (ipuv3)->module##_ioh, (reg), (val))
76 1.1 bsh
77 1.1 bsh #ifdef IPUV3_DEBUG
78 1.1 bsh int ipuv3_debug = IPUV3_DEBUG;
79 1.1 bsh #define DPRINTFN(n,x) if (ipuv3_debug>(n)) printf x; else
80 1.1 bsh #else
81 1.1 bsh #define DPRINTFN(n,x)
82 1.1 bsh #endif
83 1.1 bsh
84 1.1 bsh int ipuv3intr(void *);
85 1.1 bsh
86 1.1 bsh static void imx51_ipuv3_initialize(struct imx51_ipuv3_softc *,
87 1.1 bsh const struct lcd_panel_geometry *);
88 1.1 bsh #if NWSDISPLAY > 0
89 1.1 bsh static void imx51_ipuv3_setup_rasops(struct imx51_ipuv3_softc *,
90 1.1 bsh struct rasops_info *, struct imx51_wsscreen_descr *,
91 1.1 bsh const struct lcd_panel_geometry *);
92 1.1 bsh #endif
93 1.1 bsh static void imx51_ipuv3_set_idma_param(uint32_t *, uint32_t, uint32_t);
94 1.1 bsh
95 1.1 bsh #if NWSDISPLAY > 0
96 1.1 bsh /*
97 1.1 bsh * wsdisplay glue
98 1.1 bsh */
99 1.1 bsh static struct imx51_wsscreen_descr imx51_ipuv3_stdscreen = {
100 1.1 bsh .c = {
101 1.1 bsh .name = "std",
102 1.1 bsh .ncols = 0,
103 1.1 bsh .nrows = 0,
104 1.1 bsh .textops = NULL,
105 1.1 bsh .fontwidth = 8,
106 1.1 bsh .fontheight = 16,
107 1.1 bsh .capabilities = WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
108 1.1 bsh .modecookie = NULL
109 1.1 bsh },
110 1.1 bsh .depth = 16, /* bits per pixel */
111 1.1 bsh .flags = RI_CENTER | RI_FULLCLEAR
112 1.1 bsh };
113 1.1 bsh
114 1.1 bsh static const struct wsscreen_descr *imx51_ipuv3_scr_descr[] = {
115 1.1 bsh &imx51_ipuv3_stdscreen.c,
116 1.1 bsh };
117 1.1 bsh
118 1.1 bsh const struct wsscreen_list imx51_ipuv3_screen_list = {
119 1.1 bsh sizeof imx51_ipuv3_scr_descr / sizeof imx51_ipuv3_scr_descr[0],
120 1.1 bsh imx51_ipuv3_scr_descr
121 1.1 bsh };
122 1.1 bsh
123 1.1 bsh struct wsdisplay_accessops imx51_ipuv3_accessops = {
124 1.1 bsh .ioctl = imx51_ipuv3_ioctl,
125 1.1 bsh .mmap = imx51_ipuv3_mmap,
126 1.1 bsh .alloc_screen = NULL,
127 1.1 bsh .free_screen = NULL,
128 1.1 bsh .show_screen = NULL,
129 1.1 bsh .load_font = NULL,
130 1.1 bsh .pollc = NULL,
131 1.1 bsh .scroll = NULL
132 1.1 bsh };
133 1.1 bsh #endif
134 1.1 bsh
135 1.1 bsh #ifdef IPUV3_DEBUG
136 1.1 bsh static void
137 1.1 bsh imx51_ipuv3_dump(struct imx51_ipuv3_softc *sc)
138 1.1 bsh {
139 1.1 bsh int i;
140 1.1 bsh
141 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
142 1.1 bsh
143 1.1 bsh #define __DUMP(grp, reg) \
144 1.1 bsh DPRINTFN(4, ("%-16s = 0x%08X\n", #reg, IPUV3_READ(sc, grp, IPU_##reg)))
145 1.1 bsh
146 1.1 bsh __DUMP(cm, CM_CONF);
147 1.1 bsh __DUMP(cm, CM_DISP_GEN);
148 1.1 bsh __DUMP(idmac, IDMAC_CONF);
149 1.1 bsh __DUMP(idmac, IDMAC_CH_EN_1);
150 1.1 bsh __DUMP(idmac, IDMAC_CH_EN_2);
151 1.1 bsh __DUMP(idmac, IDMAC_CH_PRI_1);
152 1.1 bsh __DUMP(idmac, IDMAC_CH_PRI_2);
153 1.1 bsh __DUMP(idmac, IDMAC_BNDM_EN_1);
154 1.1 bsh __DUMP(idmac, IDMAC_BNDM_EN_2);
155 1.1 bsh __DUMP(cm, CM_CH_DB_MODE_SEL_0);
156 1.1 bsh __DUMP(cm, CM_CH_DB_MODE_SEL_1);
157 1.1 bsh __DUMP(dmfc, DMFC_WR_CHAN);
158 1.1 bsh __DUMP(dmfc, DMFC_WR_CHAN_DEF);
159 1.1 bsh __DUMP(dmfc, DMFC_DP_CHAN);
160 1.1 bsh __DUMP(dmfc, DMFC_DP_CHAN_DEF);
161 1.1 bsh __DUMP(dmfc, DMFC_IC_CTRL);
162 1.1 bsh __DUMP(cm, CM_FS_PROC_FLOW1);
163 1.1 bsh __DUMP(cm, CM_FS_PROC_FLOW2);
164 1.1 bsh __DUMP(cm, CM_FS_PROC_FLOW3);
165 1.1 bsh __DUMP(cm, CM_FS_DISP_FLOW1);
166 1.1 bsh __DUMP(dc, DC_DISP_CONF1_0);
167 1.1 bsh __DUMP(dc, DC_DISP_CONF2_0);
168 1.1 bsh __DUMP(dc, DC_WR_CH_CONF_5);
169 1.1 bsh
170 1.1 bsh printf("*** IPU ***\n");
171 1.1 bsh for (i = 0; i <= 0x17c; i += 4)
172 1.1 bsh DPRINTFN(6, ("0x%08X = 0x%08X\n", i, IPUV3_READ(sc, cm, i)));
173 1.1 bsh printf("*** IDMAC ***\n");
174 1.1 bsh for (i = 0; i <= 0x104; i += 4)
175 1.1 bsh DPRINTFN(6, ("0x%08X = 0x%08X\n", i, IPUV3_READ(sc, idmac, i)));
176 1.1 bsh printf("*** CPMEM ***\n");
177 1.1 bsh for (i = 0x5c0; i <= 0x600; i += 4)
178 1.1 bsh DPRINTFN(6, ("0x%08X = 0x%08X\n", i, IPUV3_READ(sc, cpmem, i)));
179 1.1 bsh
180 1.1 bsh #undef __DUMP
181 1.1 bsh
182 1.1 bsh }
183 1.1 bsh #endif
184 1.1 bsh
185 1.1 bsh static void
186 1.1 bsh imx51_ipuv3_enable_display(struct imx51_ipuv3_softc *sc)
187 1.1 bsh {
188 1.1 bsh uint32_t reg = 0;
189 1.1 bsh
190 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
191 1.1 bsh
192 1.1 bsh /* enable sub modules */
193 1.1 bsh reg = IPUV3_READ(sc, cm, IPU_CM_CONF);
194 1.1 bsh reg |= CM_CONF_DP_EN |
195 1.1 bsh CM_CONF_DC_EN |
196 1.1 bsh CM_CONF_DMFC_EN |
197 1.1 bsh CM_CONF_DI0_EN;
198 1.1 bsh IPUV3_WRITE(sc, cm, IPU_CM_CONF, reg);
199 1.1 bsh }
200 1.1 bsh
201 1.1 bsh static void
202 1.1 bsh imx51_ipuv3_dmfc_init(struct imx51_ipuv3_softc *sc)
203 1.1 bsh {
204 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
205 1.1 bsh
206 1.1 bsh /* IC channel is disabled */
207 1.1 bsh IPUV3_WRITE(sc, dmfc, IPU_DMFC_IC_CTRL,
208 1.1 bsh IC_IN_PORT_DISABLE);
209 1.1 bsh
210 1.1 bsh IPUV3_WRITE(sc, dmfc, IPU_DMFC_WR_CHAN, 0x00000000);
211 1.1 bsh IPUV3_WRITE(sc, dmfc, IPU_DMFC_WR_CHAN_DEF, 0x20202020);
212 1.1 bsh IPUV3_WRITE(sc, dmfc, IPU_DMFC_DP_CHAN, 0x00000094);
213 1.1 bsh IPUV3_WRITE(sc, dmfc, IPU_DMFC_DP_CHAN_DEF, 0x202020F6);
214 1.1 bsh
215 1.1 bsh IPUV3_WRITE(sc, dmfc, IPU_DMFC_GENERAL1,
216 1.1 bsh DCDP_SYNC_PR_ROUNDROBIN);
217 1.1 bsh
218 1.1 bsh #ifdef IPUV3_DEBUG
219 1.1 bsh int i;
220 1.1 bsh printf("*** DMFC ***\n");
221 1.1 bsh for (i = 0; i <= 0x34; i += 4)
222 1.1 bsh printf("0x%08X = 0x%08X\n", i, IPUV3_READ(sc, dmfc, i));
223 1.1 bsh
224 1.1 bsh printf("%s: DMFC_IC_CTRL 0x%08X\n", __func__,
225 1.1 bsh IPUV3_READ(sc, dmfc, IPU_DMFC_IC_CTRL));
226 1.1 bsh printf("%s: IPU_DMFC_WR_CHAN 0x%08X\n", __func__,
227 1.1 bsh IPUV3_READ(sc, dmfc, IPU_DMFC_WR_CHAN));
228 1.1 bsh printf("%s: IPU_DMFC_WR_CHAN_DEF 0x%08X\n", __func__,
229 1.1 bsh IPUV3_READ(sc, dmfc, IPU_DMFC_WR_CHAN_DEF));
230 1.1 bsh printf("%s: IPU_DMFC_GENERAL1 0x%08X\n", __func__,
231 1.1 bsh IPUV3_READ(sc, dmfc, IPU_DMFC_GENERAL1));
232 1.1 bsh #endif
233 1.1 bsh }
234 1.1 bsh
235 1.1 bsh static void
236 1.1 bsh imx51_ipuv3_dc_map_clear(struct imx51_ipuv3_softc *sc, int map)
237 1.1 bsh {
238 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
239 1.1 bsh
240 1.1 bsh uint32_t reg;
241 1.1 bsh uint32_t addr;
242 1.1 bsh
243 1.1 bsh addr = IPU_DC_MAP_CONF_PNTR(map / 2);
244 1.1 bsh reg = IPUV3_READ(sc, dc, addr);
245 1.1 bsh reg &= ~(0xFFFF << (16 * (map & 0x1)));
246 1.1 bsh IPUV3_WRITE(sc, dc, addr, reg);
247 1.1 bsh }
248 1.1 bsh
249 1.1 bsh static void
250 1.1 bsh imx51_ipuv3_dc_map_conf(struct imx51_ipuv3_softc *sc,
251 1.1 bsh int map, int byte, int offset, uint8_t mask)
252 1.1 bsh {
253 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
254 1.1 bsh
255 1.1 bsh uint32_t reg;
256 1.1 bsh uint32_t addr;
257 1.1 bsh
258 1.1 bsh addr = IPU_DC_MAP_CONF_MASK((map * 3 + byte) / 2);
259 1.1 bsh reg = IPUV3_READ(sc, dc, addr);
260 1.1 bsh reg &= ~(0xFFFF << (16 * ((map * 3 + byte) & 0x1)));
261 1.1 bsh reg |= ((offset << 8) | mask) << (16 * ((map * 3 + byte) & 0x1));
262 1.1 bsh IPUV3_WRITE(sc, dc, addr, reg);
263 1.1 bsh #ifdef IPUV3_DEBUG
264 1.1 bsh printf("%s: addr 0x%08X reg 0x%08X\n", __func__, addr, reg);
265 1.1 bsh #endif
266 1.1 bsh
267 1.1 bsh addr = IPU_DC_MAP_CONF_PNTR(map / 2);
268 1.1 bsh reg = IPUV3_READ(sc, dc, addr);
269 1.1 bsh reg &= ~(0x1F << ((16 * (map & 0x1)) + (5 * byte)));
270 1.1 bsh reg |= ((map * 3) + byte) << ((16 * (map & 0x1)) + (5 * byte));
271 1.1 bsh IPUV3_WRITE(sc, dc, addr, reg);
272 1.1 bsh #ifdef IPUV3_DEBUG
273 1.1 bsh printf("%s: addr 0x%08X reg 0x%08X\n", __func__, addr, reg);
274 1.1 bsh #endif
275 1.1 bsh }
276 1.1 bsh
277 1.1 bsh static void
278 1.1 bsh imx51_ipuv3_dc_template_command(struct imx51_ipuv3_softc *sc,
279 1.1 bsh int index, int sync, int gluelogic, int waveform, int mapping,
280 1.1 bsh int operand, int opecode, int stop)
281 1.1 bsh {
282 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
283 1.1 bsh
284 1.1 bsh uint32_t reg;
285 1.1 bsh
286 1.1 bsh reg = (sync << 0) |
287 1.1 bsh (gluelogic << 4) |
288 1.1 bsh (waveform << 11) |
289 1.1 bsh (mapping << 15) |
290 1.1 bsh (operand << 20);
291 1.1 bsh IPUV3_WRITE(sc, dctmpl, index * 8, reg);
292 1.1 bsh #ifdef IPUV3_DEBUG
293 1.1 bsh printf("%s: addr 0x%08X reg 0x%08X\n", __func__, index * 8, reg);
294 1.1 bsh #endif
295 1.1 bsh reg = (opecode << 0) |
296 1.1 bsh (stop << 9);
297 1.1 bsh IPUV3_WRITE(sc, dctmpl, index * 8 + 4, reg);
298 1.1 bsh #ifdef IPUV3_DEBUG
299 1.1 bsh printf("%s: addr 0x%08X reg 0x%08X\n", __func__, index * 8 + 4, reg);
300 1.1 bsh #endif
301 1.1 bsh }
302 1.1 bsh
303 1.1 bsh static void
304 1.1 bsh imx51_ipuv3_set_routine_link(struct imx51_ipuv3_softc *sc,
305 1.1 bsh int base, int evt, int addr, int pri)
306 1.1 bsh {
307 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
308 1.1 bsh
309 1.1 bsh uint32_t reg;
310 1.1 bsh
311 1.1 bsh reg = IPUV3_READ(sc, dc, IPU_DC_RL(base, evt));
312 1.1 bsh reg &= ~(0xFFFF << (16 * (evt & 0x1)));
313 1.1 bsh reg |= ((addr << 8) | pri) << (16 * (evt & 0x1));
314 1.1 bsh IPUV3_WRITE(sc, dc, IPU_DC_RL(base, evt), reg);
315 1.1 bsh #ifdef IPUV3_DEBUG
316 1.1 bsh printf("%s: event %d addr %d priority %d\n", __func__,
317 1.1 bsh evt, addr, pri);
318 1.1 bsh printf("%s: %p = 0x%08X\n", __func__,
319 1.1 bsh (void *)IPU_DC_RL(base, evt), reg);
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_init(struct imx51_ipuv3_softc *sc)
325 1.1 bsh {
326 1.1 bsh uint32_t reg;
327 1.1 bsh
328 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
329 1.1 bsh
330 1.1 bsh imx51_ipuv3_dc_map_clear(sc, 0);
331 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 0, 0, 7, 0xff);
332 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 0, 1, 15, 0xff);
333 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 0, 2, 23, 0xff);
334 1.1 bsh imx51_ipuv3_dc_map_clear(sc, 1);
335 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 1, 0, 5, 0xfc);
336 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 1, 1, 11, 0xfc);
337 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 1, 2, 17, 0xfc);
338 1.1 bsh imx51_ipuv3_dc_map_clear(sc, 2);
339 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 2, 0, 15, 0xff);
340 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 2, 1, 23, 0xff);
341 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 2, 2, 7, 0xff);
342 1.1 bsh imx51_ipuv3_dc_map_clear(sc, 3);
343 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 3, 0, 4, 0xf8);
344 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 3, 1, 10, 0xfc);
345 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 3, 2, 15, 0xf8);
346 1.1 bsh imx51_ipuv3_dc_map_clear(sc, 4);
347 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 4, 0, 5, 0xfc);
348 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 4, 1, 13, 0xfc);
349 1.1 bsh imx51_ipuv3_dc_map_conf(sc, 4, 2, 21, 0xfc);
350 1.1 bsh
351 1.1 bsh /* microcode */
352 1.1 bsh imx51_ipuv3_dc_template_command(sc,
353 1.1 bsh 5, 5, 8, 1, 5, 0, 0x180, 1);
354 1.1 bsh imx51_ipuv3_dc_template_command(sc,
355 1.1 bsh 6, 5, 4, 1, 5, 0, 0x180, 1);
356 1.1 bsh imx51_ipuv3_dc_template_command(sc,
357 1.1 bsh 7, 5, 0, 1, 5, 0, 0x180, 1);
358 1.1 bsh
359 1.1 bsh reg = (4 << 5) | 0x2;
360 1.1 bsh IPUV3_WRITE(sc, dc, IPU_DC_WR_CH_CONF_5, reg);
361 1.1 bsh IPUV3_WRITE(sc, dc, IPU_DC_WR_CH_CONF_1, 0x4);
362 1.1 bsh IPUV3_WRITE(sc, dc, IPU_DC_WR_CH_ADDR_5, 0x0);
363 1.1 bsh IPUV3_WRITE(sc, dc, IPU_DC_GEN, 0x44);
364 1.1 bsh
365 1.1 bsh imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_NL, 5, 3);
366 1.1 bsh imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_EOL, 6, 2);
367 1.1 bsh imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_NEW_DATA, 7, 1);
368 1.1 bsh imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_NF, 0, 0);
369 1.1 bsh imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_NFIELD, 0, 0);
370 1.1 bsh imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_EOF, 0, 0);
371 1.1 bsh imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_EOFIELD, 0, 0);
372 1.1 bsh imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_NEW_CHAN, 0, 0);
373 1.1 bsh imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_NEW_ADDR, 0, 0);
374 1.1 bsh
375 1.1 bsh #ifdef IPUV3_DEBUG
376 1.1 bsh int i;
377 1.1 bsh printf("*** DC ***\n");
378 1.1 bsh for (i = 0; i <= 0x1C8; i += 4)
379 1.1 bsh printf("0x%08X = 0x%08X\n", i, IPUV3_READ(sc, dc, i));
380 1.1 bsh printf("*** DCTEMPL ***\n");
381 1.1 bsh for (i = 0; i <= 0x100; i += 4)
382 1.1 bsh printf("0x%08X = 0x%08X\n", i, IPUV3_READ(sc, dctmpl, i));
383 1.1 bsh #endif
384 1.1 bsh }
385 1.1 bsh
386 1.1 bsh static void
387 1.1 bsh imx51_ipuv3_dc_display_config(struct imx51_ipuv3_softc *sc, int width)
388 1.1 bsh {
389 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
390 1.1 bsh
391 1.1 bsh IPUV3_WRITE(sc, dc, IPU_DC_DISP_CONF2_0, width);
392 1.1 bsh }
393 1.1 bsh
394 1.1 bsh static void
395 1.1 bsh imx51_ipuv3_di_sync_conf(struct imx51_ipuv3_softc *sc, int no,
396 1.1 bsh uint32_t reg_gen0, uint32_t reg_gen1, uint32_t repeat)
397 1.1 bsh {
398 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
399 1.1 bsh
400 1.1 bsh uint32_t reg;
401 1.1 bsh
402 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN0(no), reg_gen0);
403 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN1(no), reg_gen1);
404 1.1 bsh reg = IPUV3_READ(sc, di0, IPU_DI_STP_REP(no));
405 1.1 bsh reg &= ~DI_STP_REP_MASK(no);
406 1.1 bsh reg |= repeat << DI_STP_REP_SHIFT(no);
407 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_STP_REP(no), reg);
408 1.1 bsh
409 1.1 bsh #ifdef IPUV3_DEBUG
410 1.1 bsh printf("%s: no %d\n", __func__, no);
411 1.1 bsh printf("%s: addr 0x%08X reg_gen0 0x%08X\n", __func__,
412 1.1 bsh IPU_DI_SW_GEN0(no), reg_gen0);
413 1.1 bsh printf("%s: addr 0x%08X reg_gen1 0x%08X\n", __func__,
414 1.1 bsh IPU_DI_SW_GEN1(no), reg_gen1);
415 1.1 bsh printf("%s: addr 0x%08X DI_STP_REP 0x%08X\n", __func__,
416 1.1 bsh IPU_DI_STP_REP(no), reg);
417 1.1 bsh #endif
418 1.1 bsh }
419 1.1 bsh
420 1.1 bsh static void
421 1.1 bsh imx51_ipuv3_di_init(struct imx51_ipuv3_softc *sc)
422 1.1 bsh {
423 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
424 1.1 bsh
425 1.1 bsh uint32_t reg;
426 1.1 bsh uint32_t div;
427 1.1 bsh u_int ipuclk;
428 1.1 bsh const struct lcd_panel_geometry *geom = sc->geometry;
429 1.1 bsh
430 1.1 bsh #if NIMXCCM > 0
431 1.1 bsh ipuclk = imx51_get_clock(IMX51CLK_IPU_HSP_CLK_ROOT);
432 1.1 bsh #elif !defined(IMX51_IPU_HSP_CLOCK)
433 1.1 bsh #error IMX51_CPU_HSP_CLOCK need to be defined.
434 1.1 bsh #else
435 1.1 bsh ipuclk = IMX51_IPU_HSP_CLOCK;
436 1.1 bsh #endif
437 1.1 bsh DPRINTFN(3, ("IPU HSP clock = %d\n", ipuclk));
438 1.1 bsh div = (ipuclk * 16) / geom->pixel_clk;
439 1.1 bsh div = div < 16 ? 16 : div & 0xff8;
440 1.1 bsh
441 1.1 bsh /* DI counter */
442 1.1 bsh reg = IPUV3_READ(sc, cm, IPU_CM_DISP_GEN);
443 1.1 bsh reg &= ~(CM_DISP_GEN_DI1_COUNTER_RELEASE |
444 1.1 bsh CM_DISP_GEN_DI0_COUNTER_RELEASE);
445 1.1 bsh IPUV3_WRITE(sc, cm, IPU_CM_DISP_GEN, reg);
446 1.1 bsh
447 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_BS_CLKGEN0, div);
448 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_BS_CLKGEN1,
449 1.1 bsh (div / 16) << DI_BS_CLKGEN1_DOWN_SHIFT);
450 1.1 bsh #ifdef IPUV3_DEBUG
451 1.1 bsh printf("%s: IPU_DI_BS_CLKGEN0 = 0x%08X\n", __func__,
452 1.1 bsh IPUV3_READ(sc, di0, IPU_DI_BS_CLKGEN0));
453 1.1 bsh printf("%s: IPU_DI_BS_CLKGEN1 = 0x%08X\n", __func__,
454 1.1 bsh IPUV3_READ(sc, di0, IPU_DI_BS_CLKGEN1));
455 1.1 bsh #endif
456 1.1 bsh /* Display Time settings */
457 1.1 bsh reg = ((div / 16 - 1) << DI_DW_GEN_ACCESS_SIZE_SHIFT) |
458 1.1 bsh ((div / 16 - 1) << DI_DW_GEN_COMPONNENT_SIZE_SHIFT) |
459 1.1 bsh (3 << DI_DW_GEN_PIN_SHIFT(15));
460 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_DW_GEN(0), reg);
461 1.1 bsh #ifdef IPUV3_DEBUG
462 1.1 bsh printf("%s: div = %d\n", __func__, div);
463 1.1 bsh printf("%s: IPU_DI_DW_GEN(0) 0x%08X = 0x%08X\n", __func__,
464 1.1 bsh IPU_DI_DW_GEN(0), reg);
465 1.1 bsh #endif
466 1.1 bsh
467 1.1 bsh /* Up & Down Data Wave Set */
468 1.1 bsh reg = (div / 16 * 2) << DI_DW_SET_DOWN_SHIFT;
469 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_DW_SET(0, 3), reg);
470 1.1 bsh #ifdef IPUV3_DEBUG
471 1.1 bsh printf("%s: IPU_DI_DW_SET(0, 3) 0x%08X = 0x%08X\n", __func__,
472 1.1 bsh IPU_DI_DW_SET(0, 3), reg);
473 1.1 bsh #endif
474 1.1 bsh
475 1.1 bsh /* internal HSCYNC */
476 1.1 bsh imx51_ipuv3_di_sync_conf(sc, 1,
477 1.1 bsh __DI_SW_GEN0(geom->panel_width + geom->hsync_width +
478 1.1 bsh geom->left + geom->right - 1, 1, 0, 0),
479 1.1 bsh __DI_SW_GEN1(0, 1, 0, 0, 0, 0, 0),
480 1.1 bsh 0);
481 1.1 bsh
482 1.1 bsh /* HSYNC */
483 1.1 bsh imx51_ipuv3_di_sync_conf(sc, 2,
484 1.1 bsh __DI_SW_GEN0(geom->panel_width + geom->hsync_width +
485 1.1 bsh geom->left + geom->right - 1, 1, 0, 1),
486 1.1 bsh __DI_SW_GEN1(1, 1, 0, geom->hsync_width * 2, 1, 0, 0),
487 1.1 bsh 0);
488 1.1 bsh
489 1.1 bsh /* VSYNC */
490 1.1 bsh imx51_ipuv3_di_sync_conf(sc, 3,
491 1.1 bsh __DI_SW_GEN0(geom->panel_height + geom->vsync_width +
492 1.1 bsh geom->upper + geom->lower - 1, 2, 0, 0),
493 1.1 bsh __DI_SW_GEN1(1, 1, 0, geom->vsync_width * 2, 2, 0, 0),
494 1.1 bsh 0);
495 1.1 bsh
496 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SCR_CONF,
497 1.1 bsh geom->panel_height + geom->vsync_width + geom->upper +
498 1.1 bsh geom->lower - 1);
499 1.1 bsh
500 1.1 bsh /* Active Lines Start */
501 1.1 bsh imx51_ipuv3_di_sync_conf(sc, 4,
502 1.1 bsh __DI_SW_GEN0(0, 3, geom->vsync_width + geom->upper, 3),
503 1.1 bsh __DI_SW_GEN1(0, 0, 4, 0, 0, 0, 0),
504 1.1 bsh geom->panel_height);
505 1.1 bsh
506 1.1 bsh /* Active Clock Start */
507 1.1 bsh imx51_ipuv3_di_sync_conf(sc, 5,
508 1.1 bsh __DI_SW_GEN0(0, 1, geom->hsync_width + geom->left, 1),
509 1.1 bsh __DI_SW_GEN1(0, 0, 5, 0, 0, 0, 0),
510 1.1 bsh geom->panel_width);
511 1.1 bsh
512 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN0(6), 0);
513 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN1(6), 0);
514 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN0(7), 0);
515 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN1(7), 0);
516 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN0(8), 0);
517 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN1(8), 0);
518 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN0(9), 0);
519 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN1(9), 0);
520 1.1 bsh
521 1.1 bsh reg = IPUV3_READ(sc, di0, IPU_DI_STP_REP(6));
522 1.1 bsh reg &= ~DI_STP_REP_MASK(6);
523 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_STP_REP(6), reg);
524 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_STP_REP(7), 0);
525 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_STP_REP(9), 0);
526 1.1 bsh
527 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_GENERAL, 0);
528 1.1 bsh reg = ((3 - 1) << DI_SYNC_AS_GEN_VSYNC_SEL_SHIFT) | 0x2;
529 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_SYNC_AS_GEN, reg);
530 1.1 bsh IPUV3_WRITE(sc, di0, IPU_DI_POL, DI_POL_DRDY_POLARITY_15);
531 1.1 bsh
532 1.1 bsh /* release DI counter */
533 1.1 bsh reg = IPUV3_READ(sc, cm, IPU_CM_DISP_GEN);
534 1.1 bsh reg |= CM_DISP_GEN_DI0_COUNTER_RELEASE;
535 1.1 bsh IPUV3_WRITE(sc, cm, IPU_CM_DISP_GEN, reg);
536 1.1 bsh
537 1.1 bsh #ifdef IPUV3_DEBUG
538 1.1 bsh int i;
539 1.1 bsh printf("*** DI0 ***\n");
540 1.1 bsh for (i = 0; i <= 0x174; i += 4)
541 1.1 bsh printf("0x%08X = 0x%08X\n", i, IPUV3_READ(sc, di0, i));
542 1.1 bsh
543 1.1 bsh printf("%s: IPU_CM_DISP_GEN : 0x%08X\n", __func__,
544 1.1 bsh IPUV3_READ(sc, cm, IPU_CM_DISP_GEN));
545 1.1 bsh printf("%s: IPU_DI_SYNC_AS_GEN : 0x%08X\n", __func__,
546 1.1 bsh IPUV3_READ(sc, di0, IPU_DI_SYNC_AS_GEN));
547 1.1 bsh printf("%s: IPU_DI_GENERAL : 0x%08X\n", __func__,
548 1.1 bsh IPUV3_READ(sc, di0, IPU_DI_GENERAL));
549 1.1 bsh printf("%s: IPU_DI_POL : 0x%08X\n", __func__,
550 1.1 bsh IPUV3_READ(sc, di0, IPU_DI_POL));
551 1.1 bsh #endif
552 1.1 bsh }
553 1.1 bsh
554 1.1 bsh
555 1.1 bsh void
556 1.1 bsh imx51_ipuv3_geometry(struct imx51_ipuv3_softc *sc,
557 1.1 bsh const struct lcd_panel_geometry *geom)
558 1.1 bsh {
559 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
560 1.1 bsh
561 1.1 bsh sc->geometry = geom;
562 1.1 bsh
563 1.1 bsh #ifdef IPUV3_DEBUG
564 1.1 bsh printf("%s: screen height = %d\n",__func__ , geom->panel_height);
565 1.1 bsh printf("%s: width = %d\n",__func__ , geom->panel_width);
566 1.1 bsh printf("%s: IPU Clock = %d\n", __func__,
567 1.1 bsh imx51_get_clock(IMX51CLK_IPU_HSP_CLK_ROOT));
568 1.1 bsh printf("%s: Pixel Clock = %d\n", __func__, geom->pixel_clk);
569 1.1 bsh #endif
570 1.1 bsh
571 1.1 bsh imx51_ipuv3_di_init(sc);
572 1.1 bsh
573 1.1 bsh #ifdef IPUV3_DEBUG
574 1.1 bsh printf("%s: IPU_CM_DISP_GEN : 0x%08X\n", __func__,
575 1.1 bsh IPUV3_READ(sc, cm, IPU_CM_DISP_GEN));
576 1.1 bsh #endif
577 1.1 bsh
578 1.1 bsh imx51_ipuv3_dc_display_config(sc, geom->panel_width);
579 1.1 bsh
580 1.1 bsh return;
581 1.1 bsh }
582 1.1 bsh
583 1.1 bsh /*
584 1.1 bsh * Initialize the IPUV3 controller.
585 1.1 bsh */
586 1.1 bsh static void
587 1.1 bsh imx51_ipuv3_initialize(struct imx51_ipuv3_softc *sc,
588 1.1 bsh const struct lcd_panel_geometry *geom)
589 1.1 bsh {
590 1.1 bsh uint32_t reg;
591 1.1 bsh
592 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
593 1.1 bsh
594 1.1 bsh IPUV3_WRITE(sc, cm, IPU_CM_CONF, 0);
595 1.1 bsh
596 1.1 bsh /* reset */
597 1.1 bsh IPUV3_WRITE(sc, cm, IPU_CM_MEM_RST, CM_MEM_START | CM_MEM_EN);
598 1.1 bsh while (IPUV3_READ(sc, cm, IPU_CM_MEM_RST) & CM_MEM_START)
599 1.1 bsh ; /* wait */
600 1.1 bsh
601 1.1 bsh imx51_ipuv3_dmfc_init(sc);
602 1.1 bsh imx51_ipuv3_dc_init(sc);
603 1.1 bsh
604 1.1 bsh imx51_ipuv3_geometry(sc, geom);
605 1.1 bsh
606 1.1 bsh /* set global alpha */
607 1.1 bsh IPUV3_WRITE(sc, dp, IPU_DP_GRAPH_WIND_CTRL_SYNC, 0x80 << 24);
608 1.1 bsh IPUV3_WRITE(sc, dp, IPU_DP_COM_CONF_SYNC, DP_DP_GWAM_SYNC);
609 1.1 bsh
610 1.1 bsh reg = IPUV3_READ(sc, cm, IPU_CM_DISP_GEN);
611 1.1 bsh reg |= CM_DISP_GEN_MCU_MAX_BURST_STOP |
612 1.1 bsh CM_DISP_GEN_MCU_T(0x8);
613 1.1 bsh IPUV3_WRITE(sc, cm, IPU_CM_DISP_GEN, reg);
614 1.1 bsh }
615 1.1 bsh
616 1.1 bsh static void
617 1.1 bsh imx51_ipuv3_init_screen(void *cookie, struct vcons_screen *scr,
618 1.1 bsh int existing, long *defattr)
619 1.1 bsh {
620 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
621 1.1 bsh
622 1.1 bsh struct imx51_ipuv3_softc *sc = cookie;
623 1.1 bsh struct rasops_info *ri = &scr->scr_ri;
624 1.1 bsh struct imx51_wsscreen_descr *descr = &imx51_ipuv3_stdscreen;
625 1.1 bsh
626 1.1 bsh if ((scr == &sc->console) && (sc->vd.active != NULL))
627 1.1 bsh return;
628 1.1 bsh
629 1.1 bsh ri->ri_bits = sc->active->buf_va;
630 1.1 bsh
631 1.1 bsh scr->scr_flags |= VCONS_DONT_READ;
632 1.1 bsh if (existing)
633 1.1 bsh ri->ri_flg |= RI_CLEAR;
634 1.1 bsh
635 1.1 bsh imx51_ipuv3_setup_rasops(sc, ri, descr, sc->geometry);
636 1.1 bsh
637 1.1 bsh ri->ri_caps = WSSCREEN_WSCOLORS;
638 1.1 bsh
639 1.1 bsh rasops_reconfig(ri,
640 1.1 bsh ri->ri_height / ri->ri_font->fontheight,
641 1.1 bsh ri->ri_width / ri->ri_font->fontwidth);
642 1.1 bsh
643 1.1 bsh ri->ri_hw = scr;
644 1.1 bsh }
645 1.1 bsh
646 1.1 bsh /*
647 1.1 bsh * Common driver attachment code.
648 1.1 bsh */
649 1.1 bsh void
650 1.1 bsh imx51_ipuv3_attach_sub(struct imx51_ipuv3_softc *sc,
651 1.1 bsh struct axi_attach_args *axia, const struct lcd_panel_geometry *geom)
652 1.1 bsh {
653 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
654 1.1 bsh
655 1.1 bsh bus_space_tag_t iot = axia->aa_iot;
656 1.1 bsh bus_space_handle_t ioh;
657 1.1 bsh int error;
658 1.1 bsh
659 1.1 bsh aprint_normal(": i.MX51 IPUV3 controller\n");
660 1.1 bsh
661 1.1 bsh sc->n_screens = 0;
662 1.1 bsh LIST_INIT(&sc->screens);
663 1.1 bsh
664 1.1 bsh sc->iot = iot;
665 1.1 bsh sc->dma_tag = &imx_bus_dma_tag;
666 1.1 bsh
667 1.1 bsh /* map controller registers */
668 1.1 bsh error = bus_space_map(iot, IPU_CM_BASE, IPU_CM_SIZE, 0, &ioh);
669 1.1 bsh if (error)
670 1.1 bsh goto fail_retarn_cm;
671 1.1 bsh sc->cm_ioh = ioh;
672 1.1 bsh
673 1.1 bsh /* map Display Multi FIFO Controller registers */
674 1.1 bsh error = bus_space_map(iot, IPU_DMFC_BASE, IPU_DMFC_SIZE, 0, &ioh);
675 1.1 bsh if (error)
676 1.1 bsh goto fail_retarn_dmfc;
677 1.1 bsh sc->dmfc_ioh = ioh;
678 1.1 bsh
679 1.1 bsh /* map Display Interface registers */
680 1.1 bsh error = bus_space_map(iot, IPU_DI0_BASE, IPU_DI0_SIZE, 0, &ioh);
681 1.1 bsh if (error)
682 1.1 bsh goto fail_retarn_di0;
683 1.1 bsh sc->di0_ioh = ioh;
684 1.1 bsh
685 1.1 bsh /* map Display Processor registers */
686 1.1 bsh error = bus_space_map(iot, IPU_DP_BASE, IPU_DP_SIZE, 0, &ioh);
687 1.1 bsh if (error)
688 1.1 bsh goto fail_retarn_dp;
689 1.1 bsh sc->dp_ioh = ioh;
690 1.1 bsh
691 1.1 bsh /* map Display Controller registers */
692 1.1 bsh error = bus_space_map(iot, IPU_DC_BASE, IPU_DC_SIZE, 0, &ioh);
693 1.1 bsh if (error)
694 1.1 bsh goto fail_retarn_dc;
695 1.1 bsh sc->dc_ioh = ioh;
696 1.1 bsh
697 1.1 bsh /* map Image DMA Controller registers */
698 1.1 bsh error = bus_space_map(iot, IPU_IDMAC_BASE, IPU_IDMAC_SIZE, 0, &ioh);
699 1.1 bsh if (error)
700 1.1 bsh goto fail_retarn_idmac;
701 1.1 bsh sc->idmac_ioh = ioh;
702 1.1 bsh
703 1.1 bsh /* map CPMEM registers */
704 1.1 bsh error = bus_space_map(iot, IPU_CPMEM_BASE, IPU_CPMEM_SIZE, 0, &ioh);
705 1.1 bsh if (error)
706 1.1 bsh goto fail_retarn_cpmem;
707 1.1 bsh sc->cpmem_ioh = ioh;
708 1.1 bsh
709 1.1 bsh /* map DCTEMPL registers */
710 1.1 bsh error = bus_space_map(iot, IPU_DCTMPL_BASE, IPU_DCTMPL_SIZE, 0, &ioh);
711 1.1 bsh if (error)
712 1.1 bsh goto fail_retarn_dctmpl;
713 1.1 bsh sc->dctmpl_ioh = ioh;
714 1.1 bsh
715 1.1 bsh #ifdef notyet
716 1.1 bsh sc->ih = imx51_ipuv3_intr_establish(IMX51_INT_IPUV3, IPL_BIO,
717 1.1 bsh ipuv3intr, sc);
718 1.1 bsh if (sc->ih == NULL) {
719 1.1 bsh aprint_error_dev(sc->dev,
720 1.1 bsh "unable to establish interrupt at irq %d\n",
721 1.1 bsh IMX51_INT_IPUV3);
722 1.1 bsh return;
723 1.1 bsh }
724 1.1 bsh #endif
725 1.1 bsh
726 1.1 bsh imx51_ipuv3_initialize(sc, geom);
727 1.1 bsh
728 1.1 bsh #if NWSDISPLAY > 0
729 1.1 bsh struct imx51_wsscreen_descr *descr = &imx51_ipuv3_stdscreen;
730 1.1 bsh struct imx51_ipuv3_screen *scr;
731 1.1 bsh
732 1.1 bsh sc->mode = WSDISPLAYIO_MODE_EMUL;
733 1.1 bsh error = imx51_ipuv3_new_screen(sc, descr->depth, &scr);
734 1.1 bsh if (error) {
735 1.1 bsh aprint_error_dev(sc->dev,
736 1.1 bsh "unable to create new screen (errno=%d)", error);
737 1.1 bsh return;
738 1.1 bsh }
739 1.1 bsh sc->active = scr;
740 1.1 bsh
741 1.1 bsh vcons_init(&sc->vd, sc, &imx51_ipuv3_stdscreen.c,
742 1.1 bsh &imx51_ipuv3_accessops);
743 1.1 bsh sc->vd.init_screen = imx51_ipuv3_init_screen;
744 1.1 bsh
745 1.1 bsh #ifdef IPUV3_DEBUG
746 1.1 bsh printf("%s: IPUV3 console ? %d\n", __func__, imx51_ipuv3_console.is_console);
747 1.1 bsh #endif
748 1.1 bsh
749 1.1 bsh struct rasops_info *ri;
750 1.1 bsh long defattr;
751 1.1 bsh ri = &sc->console.scr_ri;
752 1.1 bsh
753 1.1 bsh if (imx51_ipuv3_console.is_console) {
754 1.1 bsh vcons_init_screen(&sc->vd, &sc->console, 1,
755 1.1 bsh &defattr);
756 1.1 bsh sc->console.scr_flags |= VCONS_SCREEN_IS_STATIC;
757 1.1 bsh
758 1.1 bsh imx51_ipuv3_stdscreen.c.nrows = ri->ri_rows;
759 1.1 bsh imx51_ipuv3_stdscreen.c.ncols = ri->ri_cols;
760 1.1 bsh imx51_ipuv3_stdscreen.c.textops = &ri->ri_ops;
761 1.1 bsh imx51_ipuv3_stdscreen.c.capabilities = ri->ri_caps;
762 1.1 bsh
763 1.1 bsh wsdisplay_cnattach(&descr->c, ri, 0, 0, defattr);
764 1.1 bsh vcons_replay_msgbuf(&sc->console);
765 1.1 bsh
766 1.1 bsh imx51_ipuv3_start_dma(sc, scr);
767 1.1 bsh
768 1.1 bsh aprint_normal_dev(sc->dev, "console\n");
769 1.1 bsh } else {
770 1.1 bsh /*
771 1.1 bsh * since we're not the console we can postpone the rest
772 1.1 bsh * until someone actually allocates a screen for us
773 1.1 bsh */
774 1.1 bsh (*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
775 1.1 bsh }
776 1.1 bsh
777 1.1 bsh struct wsemuldisplaydev_attach_args aa;
778 1.1 bsh aa.console = imx51_ipuv3_console.is_console;
779 1.1 bsh aa.scrdata = &imx51_ipuv3_screen_list;
780 1.1 bsh aa.accessops = &imx51_ipuv3_accessops;
781 1.1 bsh aa.accesscookie = &sc->vd;
782 1.1 bsh
783 1.1 bsh config_found(sc->dev, &aa, wsemuldisplaydevprint);
784 1.1 bsh #endif
785 1.1 bsh
786 1.1 bsh return;
787 1.1 bsh
788 1.1 bsh fail_retarn_dctmpl:
789 1.1 bsh bus_space_unmap(sc->iot, sc->cpmem_ioh, IPU_CPMEM_SIZE);
790 1.1 bsh fail_retarn_cpmem:
791 1.1 bsh bus_space_unmap(sc->iot, sc->idmac_ioh, IPU_IDMAC_SIZE);
792 1.1 bsh fail_retarn_idmac:
793 1.1 bsh bus_space_unmap(sc->iot, sc->dc_ioh, IPU_DC_SIZE);
794 1.1 bsh fail_retarn_dp:
795 1.1 bsh bus_space_unmap(sc->iot, sc->dp_ioh, IPU_DP_SIZE);
796 1.1 bsh fail_retarn_dc:
797 1.1 bsh bus_space_unmap(sc->iot, sc->di0_ioh, IPU_DI0_SIZE);
798 1.1 bsh fail_retarn_di0:
799 1.1 bsh bus_space_unmap(sc->iot, sc->dmfc_ioh, IPU_DMFC_SIZE);
800 1.1 bsh fail_retarn_dmfc:
801 1.1 bsh bus_space_unmap(sc->iot, sc->dc_ioh, IPU_CM_SIZE);
802 1.1 bsh fail_retarn_cm:
803 1.1 bsh aprint_error_dev(sc->dev,
804 1.1 bsh "failed to map registers (errno=%d)\n", error);
805 1.1 bsh return;
806 1.1 bsh }
807 1.1 bsh
808 1.1 bsh int
809 1.1 bsh imx51_ipuv3_cnattach(const struct lcd_panel_geometry *geom)
810 1.1 bsh {
811 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
812 1.1 bsh imx51_ipuv3_console.is_console = 1;
813 1.1 bsh return 0;
814 1.1 bsh }
815 1.1 bsh
816 1.1 bsh #ifdef notyet
817 1.1 bsh /*
818 1.1 bsh * Interrupt handler.
819 1.1 bsh */
820 1.1 bsh int
821 1.1 bsh ipuv3intr(void *arg)
822 1.1 bsh {
823 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
824 1.1 bsh
825 1.1 bsh struct imx51_ipuv3_softc *sc = (struct imx51_ipuv3_softc *)arg;
826 1.1 bsh bus_space_tag_t iot = sc->iot;
827 1.1 bsh bus_space_handle_t ioh = sc->dc_ioh;
828 1.1 bsh uint32_t status;
829 1.1 bsh
830 1.1 bsh status = IPUV3_READ(ioh, V3CR);
831 1.1 bsh /* Clear stickey status bits */
832 1.1 bsh IPUV3_WRITE(ioh, V3CR, status);
833 1.1 bsh
834 1.1 bsh return 1;
835 1.1 bsh }
836 1.1 bsh #endif
837 1.1 bsh
838 1.1 bsh static void
839 1.1 bsh imx51_ipuv3_write_dmaparam(struct imx51_ipuv3_softc *sc,
840 1.1 bsh int ch, uint32_t *value, int size)
841 1.1 bsh {
842 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
843 1.1 bsh
844 1.1 bsh int i;
845 1.1 bsh uint32_t addr = ch * 0x40;
846 1.1 bsh
847 1.1 bsh for (i = 0; i < size; i++) {
848 1.1 bsh IPUV3_WRITE(sc, cpmem, addr + ((i % 5) * 0x4) +
849 1.1 bsh ((i / 5) * 0x20), value[i]);
850 1.1 bsh #ifdef IPUV3_DEBUG
851 1.1 bsh printf("%s: addr = 0x%08X, val = 0x%08X\n", __func__,
852 1.1 bsh addr + ((i % 5) * 0x4) + ((i / 5) * 0x20),
853 1.1 bsh IPUV3_READ(sc, cpmem, addr + ((i % 5) * 0x4) +
854 1.1 bsh ((i / 5) * 0x20)));
855 1.1 bsh #endif
856 1.1 bsh }
857 1.1 bsh }
858 1.1 bsh
859 1.1 bsh static void
860 1.1 bsh imx51_ipuv3_build_param(struct imx51_ipuv3_softc *sc,
861 1.1 bsh struct imx51_ipuv3_screen *scr,
862 1.1 bsh uint32_t *params)
863 1.1 bsh {
864 1.1 bsh const struct lcd_panel_geometry *geom = sc->geometry;
865 1.1 bsh
866 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
867 1.1 bsh
868 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_FW,
869 1.1 bsh (geom->panel_width - 1));
870 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_FH,
871 1.1 bsh (geom->panel_height - 1));
872 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_EBA0,
873 1.1 bsh scr->segs[0].ds_addr >> 3);
874 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_EBA1,
875 1.1 bsh scr->segs[0].ds_addr >> 3);
876 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_SL,
877 1.1 bsh (scr->stride - 1));
878 1.1 bsh
879 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_PFS, 0x7);
880 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_NPB, 32 - 1);
881 1.1 bsh
882 1.1 bsh switch (scr->depth) {
883 1.1 bsh case 32:
884 1.1 bsh /* ARBG888 */
885 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_BPP, 0x0);
886 1.1 bsh
887 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS0, 0);
888 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS1, 8);
889 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS2, 16);
890 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS3, 24);
891 1.1 bsh
892 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID0, 8 - 1);
893 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID1, 8 - 1);
894 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID2, 8 - 1);
895 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID3, 8 - 1);
896 1.1 bsh break;
897 1.1 bsh case 24:
898 1.1 bsh /* RBG888 */
899 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_BPP, 0x1);
900 1.1 bsh
901 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS0, 0);
902 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS1, 8);
903 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS2, 16);
904 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS3, 24);
905 1.1 bsh
906 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID0, 8 - 1);
907 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID1, 8 - 1);
908 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID2, 8 - 1);
909 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID3, 0);
910 1.1 bsh break;
911 1.1 bsh case 16:
912 1.1 bsh /* RBG565 */
913 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_BPP, 0x3);
914 1.1 bsh
915 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS0, 0);
916 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS1, 5);
917 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS2, 11);
918 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS3, 16);
919 1.1 bsh
920 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID0, 5 - 1);
921 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID1, 6 - 1);
922 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID2, 5 - 1);
923 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID3, 0);
924 1.1 bsh break;
925 1.1 bsh default:
926 1.1 bsh panic("%s: unsupported depth %d\n", __func__, scr->depth);
927 1.1 bsh break;
928 1.1 bsh }
929 1.1 bsh
930 1.1 bsh imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_ID, 1);
931 1.1 bsh }
932 1.1 bsh
933 1.1 bsh static void
934 1.1 bsh imx51_ipuv3_set_idma_param(uint32_t *params, uint32_t name, uint32_t val)
935 1.1 bsh {
936 1.1 bsh int word = (name >> 16) & 0xff;
937 1.1 bsh int shift = (name >> 8) & 0xff;
938 1.1 bsh int width = name & 0xff;
939 1.1 bsh int index;
940 1.1 bsh
941 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
942 1.1 bsh
943 1.1 bsh index = word * 5;
944 1.1 bsh index += shift / 32;
945 1.1 bsh shift = shift % 32;
946 1.1 bsh
947 1.1 bsh params[index] |= val << shift;
948 1.1 bsh shift = 32 - shift;
949 1.1 bsh
950 1.1 bsh if (width > shift)
951 1.1 bsh params[index+1] |= val >> shift;
952 1.1 bsh }
953 1.1 bsh
954 1.1 bsh /*
955 1.1 bsh * Enable DMA to cause the display to be refreshed periodically.
956 1.1 bsh * This brings the screen to life...
957 1.1 bsh */
958 1.1 bsh void
959 1.1 bsh imx51_ipuv3_start_dma(struct imx51_ipuv3_softc *sc,
960 1.1 bsh struct imx51_ipuv3_screen *scr)
961 1.1 bsh {
962 1.1 bsh int save;
963 1.1 bsh uint32_t params[10];
964 1.1 bsh uint32_t reg;
965 1.1 bsh
966 1.1 bsh DPRINTFN(3, ("%s: Pixel depth = %d\n", __func__, scr->depth));
967 1.1 bsh
968 1.1 bsh reg = IPUV3_READ(sc, idmac, IPU_IDMAC_CH_EN_1);
969 1.1 bsh reg &= ~__BIT(CH_PANNEL_BG);
970 1.1 bsh IPUV3_WRITE(sc, idmac, IPU_IDMAC_CH_EN_1, reg);
971 1.1 bsh
972 1.1 bsh memset(params, 0, sizeof(params));
973 1.1 bsh imx51_ipuv3_build_param(sc, scr, params);
974 1.1 bsh
975 1.1 bsh save = disable_interrupts(I32_bit);
976 1.1 bsh
977 1.1 bsh /* IDMAC configuration */
978 1.1 bsh imx51_ipuv3_write_dmaparam(sc, CH_PANNEL_BG, params,
979 1.1 bsh sizeof(params) / sizeof(params[0]));
980 1.1 bsh
981 1.1 bsh IPUV3_WRITE(sc, idmac, IPU_IDMAC_CH_PRI_1, __BIT(CH_PANNEL_BG));
982 1.1 bsh
983 1.1 bsh /* double buffer */
984 1.1 bsh reg = IPUV3_READ(sc, cm, IPU_CM_CH_DB_MODE_SEL_0);
985 1.1 bsh reg |= __BIT(CH_PANNEL_BG);
986 1.1 bsh IPUV3_WRITE(sc, cm, IPU_CM_CH_DB_MODE_SEL_0, reg);
987 1.1 bsh
988 1.1 bsh reg = IPUV3_READ(sc, idmac, IPU_IDMAC_CH_EN_1);
989 1.1 bsh reg |= __BIT(CH_PANNEL_BG);
990 1.1 bsh IPUV3_WRITE(sc, idmac, IPU_IDMAC_CH_EN_1, reg);
991 1.1 bsh
992 1.1 bsh reg = IPUV3_READ(sc, cm, IPU_CM_GPR);
993 1.1 bsh reg &= ~CM_GPR_IPU_CH_BUF0_RDY0_CLR;
994 1.1 bsh IPUV3_WRITE(sc, cm, IPU_CM_GPR, reg);
995 1.1 bsh
996 1.1 bsh IPUV3_WRITE(sc, cm, IPU_CM_CUR_BUF_0, __BIT(CH_PANNEL_BG));
997 1.1 bsh
998 1.1 bsh restore_interrupts(save);
999 1.1 bsh
1000 1.1 bsh imx51_ipuv3_enable_display(sc);
1001 1.1 bsh
1002 1.1 bsh #ifdef IPUV3_DEBUG
1003 1.1 bsh imx51_ipuv3_dump(sc);
1004 1.1 bsh #endif
1005 1.1 bsh }
1006 1.1 bsh
1007 1.1 bsh /*
1008 1.1 bsh * Disable screen refresh.
1009 1.1 bsh */
1010 1.1 bsh static void
1011 1.1 bsh imx51_ipuv3_stop_dma(struct imx51_ipuv3_softc *sc)
1012 1.1 bsh {
1013 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
1014 1.1 bsh
1015 1.1 bsh return;
1016 1.1 bsh }
1017 1.1 bsh
1018 1.1 bsh /*
1019 1.1 bsh * Create and initialize a new screen buffer.
1020 1.1 bsh */
1021 1.1 bsh int
1022 1.1 bsh imx51_ipuv3_new_screen(struct imx51_ipuv3_softc *sc, int depth,
1023 1.1 bsh struct imx51_ipuv3_screen **scrpp)
1024 1.1 bsh {
1025 1.1 bsh const struct lcd_panel_geometry *geometry;
1026 1.1 bsh struct imx51_ipuv3_screen *scr = NULL;
1027 1.1 bsh int width, height;
1028 1.1 bsh bus_size_t size;
1029 1.1 bsh int error;
1030 1.1 bsh int busdma_flag = (cold ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK);
1031 1.1 bsh
1032 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
1033 1.1 bsh
1034 1.1 bsh geometry = sc->geometry;
1035 1.1 bsh
1036 1.1 bsh width = geometry->panel_width;
1037 1.1 bsh height = geometry->panel_height;
1038 1.1 bsh
1039 1.1 bsh scr = malloc(sizeof(*scr), M_DEVBUF, M_NOWAIT);
1040 1.1 bsh if (scr == NULL)
1041 1.1 bsh return ENOMEM;
1042 1.1 bsh
1043 1.1 bsh memset(scr, 0, sizeof(*scr));
1044 1.1 bsh
1045 1.1 bsh scr->nsegs = 0;
1046 1.1 bsh scr->depth = depth;
1047 1.1 bsh scr->stride = width * depth / 8;
1048 1.1 bsh scr->buf_size = size = scr->stride * height;
1049 1.1 bsh scr->buf_va = NULL;
1050 1.1 bsh
1051 1.1 bsh error = bus_dmamem_alloc(sc->dma_tag, size, 16, 0, scr->segs, 1,
1052 1.1 bsh &scr->nsegs, busdma_flag);
1053 1.1 bsh
1054 1.1 bsh if (error || scr->nsegs != 1) {
1055 1.1 bsh /* XXX:
1056 1.1 bsh * Actually we can handle nsegs>1 case by means
1057 1.1 bsh * of multiple DMA descriptors for a panel. It
1058 1.1 bsh * will make code here a bit hairly.
1059 1.1 bsh */
1060 1.1 bsh if (error == 0)
1061 1.1 bsh error = E2BIG;
1062 1.1 bsh goto bad;
1063 1.1 bsh }
1064 1.1 bsh
1065 1.1 bsh error = bus_dmamem_map(sc->dma_tag, scr->segs, scr->nsegs, size,
1066 1.1 bsh (void **)&scr->buf_va, busdma_flag | BUS_DMA_COHERENT);
1067 1.1 bsh if (error)
1068 1.1 bsh goto bad;
1069 1.1 bsh
1070 1.1 bsh memset(scr->buf_va, 0, scr->buf_size);
1071 1.1 bsh
1072 1.1 bsh /* map memory for DMA */
1073 1.1 bsh error = bus_dmamap_create(sc->dma_tag, 1024*1024*2, 1, 1024*1024*2, 0,
1074 1.1 bsh busdma_flag, &scr->dma);
1075 1.1 bsh if (error)
1076 1.1 bsh goto bad;
1077 1.1 bsh
1078 1.1 bsh error = bus_dmamap_load(sc->dma_tag, scr->dma, scr->buf_va, size,
1079 1.1 bsh NULL, busdma_flag);
1080 1.1 bsh if (error)
1081 1.1 bsh goto bad;
1082 1.1 bsh
1083 1.1 bsh LIST_INSERT_HEAD(&sc->screens, scr, link);
1084 1.1 bsh sc->n_screens++;
1085 1.1 bsh
1086 1.1 bsh #ifdef IPUV3_DEBUG
1087 1.1 bsh printf("%s: screen buffer width %d\n", __func__, width);
1088 1.1 bsh printf("%s: screen buffer height %d\n", __func__, height);
1089 1.1 bsh printf("%s: screen buffer depth %d\n", __func__, depth);
1090 1.1 bsh printf("%s: screen buffer stride %d\n", __func__, scr->stride);
1091 1.1 bsh printf("%s: screen buffer size 0x%08X\n", __func__,
1092 1.1 bsh (uint32_t)scr->buf_size);
1093 1.1 bsh printf("%s: screen buffer addr virtual %p\n", __func__, scr->buf_va);
1094 1.1 bsh printf("%s: screen buffer addr physical %p\n", __func__,
1095 1.1 bsh (void *)scr->segs[0].ds_addr);
1096 1.1 bsh #endif
1097 1.1 bsh
1098 1.1 bsh scr->map_size = size; /* used when unmap this. */
1099 1.1 bsh
1100 1.1 bsh *scrpp = scr;
1101 1.1 bsh
1102 1.1 bsh return 0;
1103 1.1 bsh
1104 1.1 bsh bad:
1105 1.1 bsh #ifdef IPUV3_DEBUG
1106 1.1 bsh printf("%s: error = 0x%08X\n", __func__, error);
1107 1.1 bsh #endif
1108 1.1 bsh if (scr) {
1109 1.1 bsh if (scr->buf_va)
1110 1.1 bsh bus_dmamem_unmap(sc->dma_tag, scr->buf_va, size);
1111 1.1 bsh if (scr->nsegs)
1112 1.1 bsh bus_dmamem_free(sc->dma_tag, scr->segs, scr->nsegs);
1113 1.1 bsh free(scr, M_DEVBUF);
1114 1.1 bsh }
1115 1.1 bsh *scrpp = NULL;
1116 1.1 bsh return error;
1117 1.1 bsh }
1118 1.1 bsh
1119 1.1 bsh #if NWSDISPLAY > 0
1120 1.1 bsh /*
1121 1.1 bsh * Initialize rasops for a screen, as well as struct wsscreen_descr if this
1122 1.1 bsh * is the first screen creation.
1123 1.1 bsh */
1124 1.1 bsh static void
1125 1.1 bsh imx51_ipuv3_setup_rasops(struct imx51_ipuv3_softc *sc, struct rasops_info *rinfo,
1126 1.1 bsh struct imx51_wsscreen_descr *descr,
1127 1.1 bsh const struct lcd_panel_geometry *geom)
1128 1.1 bsh {
1129 1.1 bsh
1130 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
1131 1.1 bsh
1132 1.1 bsh rinfo->ri_flg = descr->flags;
1133 1.1 bsh rinfo->ri_depth = descr->depth;
1134 1.1 bsh rinfo->ri_width = geom->panel_width;
1135 1.1 bsh rinfo->ri_height = geom->panel_height;
1136 1.1 bsh rinfo->ri_stride = rinfo->ri_width * rinfo->ri_depth / 8;
1137 1.1 bsh
1138 1.1 bsh /* swap B and R */
1139 1.1 bsh if (descr->depth == 16) {
1140 1.1 bsh rinfo->ri_rnum = 5;
1141 1.1 bsh rinfo->ri_rpos = 11;
1142 1.1 bsh rinfo->ri_gnum = 6;
1143 1.1 bsh rinfo->ri_gpos = 5;
1144 1.1 bsh rinfo->ri_bnum = 5;
1145 1.1 bsh rinfo->ri_bpos = 0;
1146 1.1 bsh }
1147 1.1 bsh
1148 1.1 bsh if (descr->c.nrows == 0) {
1149 1.1 bsh /* get rasops to compute screen size the first time */
1150 1.1 bsh rasops_init(rinfo, 100, 100);
1151 1.1 bsh } else {
1152 1.1 bsh rasops_init(rinfo, descr->c.nrows, descr->c.ncols);
1153 1.1 bsh }
1154 1.1 bsh
1155 1.1 bsh descr->c.nrows = rinfo->ri_rows;
1156 1.1 bsh descr->c.ncols = rinfo->ri_cols;
1157 1.1 bsh descr->c.capabilities = rinfo->ri_caps;
1158 1.1 bsh descr->c.textops = &rinfo->ri_ops;
1159 1.1 bsh }
1160 1.1 bsh #endif
1161 1.1 bsh /*
1162 1.1 bsh * Power management
1163 1.1 bsh */
1164 1.1 bsh void
1165 1.1 bsh imx51_ipuv3_suspend(struct imx51_ipuv3_softc *sc)
1166 1.1 bsh {
1167 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
1168 1.1 bsh
1169 1.1 bsh if (sc->active) {
1170 1.1 bsh imx51_ipuv3_stop_dma(sc);
1171 1.1 bsh }
1172 1.1 bsh }
1173 1.1 bsh
1174 1.1 bsh void
1175 1.1 bsh imx51_ipuv3_resume(struct imx51_ipuv3_softc *sc)
1176 1.1 bsh {
1177 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
1178 1.1 bsh
1179 1.1 bsh if (sc->active) {
1180 1.1 bsh imx51_ipuv3_initialize(sc, sc->geometry);
1181 1.1 bsh imx51_ipuv3_start_dma(sc, sc->active);
1182 1.1 bsh }
1183 1.1 bsh }
1184 1.1 bsh
1185 1.1 bsh void
1186 1.1 bsh imx51_ipuv3_power(int why, void *v)
1187 1.1 bsh {
1188 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
1189 1.1 bsh
1190 1.1 bsh struct imx51_ipuv3_softc *sc = v;
1191 1.1 bsh
1192 1.1 bsh switch (why) {
1193 1.1 bsh case PWR_SUSPEND:
1194 1.1 bsh case PWR_STANDBY:
1195 1.1 bsh imx51_ipuv3_suspend(sc);
1196 1.1 bsh break;
1197 1.1 bsh
1198 1.1 bsh case PWR_RESUME:
1199 1.1 bsh imx51_ipuv3_resume(sc);
1200 1.1 bsh break;
1201 1.1 bsh }
1202 1.1 bsh }
1203 1.1 bsh
1204 1.1 bsh #if NWSDISPLAY > 0
1205 1.1 bsh int
1206 1.1 bsh imx51_ipuv3_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
1207 1.1 bsh struct lwp *l)
1208 1.1 bsh {
1209 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
1210 1.1 bsh
1211 1.1 bsh struct vcons_data *vd = v;
1212 1.1 bsh struct imx51_ipuv3_softc *sc = vd->cookie;
1213 1.1 bsh struct wsdisplay_fbinfo *wsdisp_info;
1214 1.1 bsh struct vcons_screen *ms = vd->active;
1215 1.1 bsh
1216 1.1 bsh switch (cmd) {
1217 1.1 bsh case WSDISPLAYIO_GTYPE:
1218 1.1 bsh *(int *)data = WSDISPLAY_TYPE_IMXIPU;
1219 1.1 bsh return 0;
1220 1.1 bsh
1221 1.1 bsh case WSDISPLAYIO_GINFO:
1222 1.1 bsh wsdisp_info = (struct wsdisplay_fbinfo *)data;
1223 1.1 bsh wsdisp_info->height = ms->scr_ri.ri_height;
1224 1.1 bsh wsdisp_info->width = ms->scr_ri.ri_width;
1225 1.1 bsh wsdisp_info->depth = ms->scr_ri.ri_depth;
1226 1.1 bsh wsdisp_info->cmsize = 0;
1227 1.1 bsh return 0;
1228 1.1 bsh
1229 1.1 bsh case WSDISPLAYIO_LINEBYTES:
1230 1.1 bsh *(u_int *)data = ms->scr_ri.ri_stride;
1231 1.1 bsh return 0;
1232 1.1 bsh
1233 1.1 bsh case WSDISPLAYIO_GETCMAP:
1234 1.1 bsh case WSDISPLAYIO_PUTCMAP:
1235 1.1 bsh return EPASSTHROUGH; /* XXX Colormap */
1236 1.1 bsh
1237 1.1 bsh case WSDISPLAYIO_SVIDEO:
1238 1.1 bsh if (*(int *)data == WSDISPLAYIO_VIDEO_ON) {
1239 1.1 bsh /* turn it on */
1240 1.1 bsh }
1241 1.1 bsh else {
1242 1.1 bsh /* start IPUV3 shutdown */
1243 1.1 bsh /* sleep until interrupt */
1244 1.1 bsh }
1245 1.1 bsh return 0;
1246 1.1 bsh
1247 1.1 bsh case WSDISPLAYIO_GVIDEO:
1248 1.1 bsh *(u_int *)data = WSDISPLAYIO_VIDEO_ON;
1249 1.1 bsh return 0;
1250 1.1 bsh
1251 1.1 bsh case WSDISPLAYIO_GCURPOS:
1252 1.1 bsh case WSDISPLAYIO_SCURPOS:
1253 1.1 bsh case WSDISPLAYIO_GCURMAX:
1254 1.1 bsh case WSDISPLAYIO_GCURSOR:
1255 1.1 bsh case WSDISPLAYIO_SCURSOR:
1256 1.1 bsh return EPASSTHROUGH; /* XXX */
1257 1.1 bsh case WSDISPLAYIO_SMODE:
1258 1.1 bsh {
1259 1.1 bsh int new_mode = *(int*)data;
1260 1.1 bsh
1261 1.1 bsh /* notify the bus backend */
1262 1.1 bsh if (new_mode != sc->mode) {
1263 1.1 bsh sc->mode = new_mode;
1264 1.1 bsh if(new_mode == WSDISPLAYIO_MODE_EMUL)
1265 1.1 bsh vcons_redraw_screen(ms);
1266 1.1 bsh }
1267 1.1 bsh }
1268 1.1 bsh return 0;
1269 1.1 bsh }
1270 1.1 bsh
1271 1.1 bsh return EPASSTHROUGH;
1272 1.1 bsh }
1273 1.1 bsh
1274 1.1 bsh paddr_t
1275 1.1 bsh imx51_ipuv3_mmap(void *v, void *vs, off_t offset, int prot)
1276 1.1 bsh {
1277 1.1 bsh DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
1278 1.1 bsh
1279 1.1 bsh struct vcons_data *vd = v;
1280 1.1 bsh struct imx51_ipuv3_softc *sc = vd->cookie;
1281 1.1 bsh struct imx51_ipuv3_screen *scr = sc->active;
1282 1.1 bsh
1283 1.1 bsh return bus_dmamem_mmap(sc->dma_tag, scr->segs, scr->nsegs,
1284 1.1 bsh offset, prot,
1285 1.1 bsh BUS_DMA_WAITOK | BUS_DMA_COHERENT);
1286 1.1 bsh }
1287 1.1 bsh #endif /* NWSDISPLAY > 0 */
1288 1.1 bsh
1289