]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - sys/arm/freescale/imx/imx51_ipuv3.c
MFC r257199, r257200, r257217:
[FreeBSD/stable/10.git] / sys / arm / freescale / imx / imx51_ipuv3.c
1 /*-
2  * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org>
3  * Copyright (c) 2012, 2013 The FreeBSD Foundation
4  * All rights reserved.
5  *
6  * Portions of this software were developed by Oleksandr Rybalko
7  * under sponsorship from the FreeBSD Foundation.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  */
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/bio.h>
37 #include <sys/bus.h>
38 #include <sys/conf.h>
39 #include <sys/endian.h>
40 #include <sys/kernel.h>
41 #include <sys/kthread.h>
42 #include <sys/lock.h>
43 #include <sys/malloc.h>
44 #include <sys/module.h>
45 #include <sys/mutex.h>
46 #include <sys/queue.h>
47 #include <sys/resource.h>
48 #include <sys/rman.h>
49 #include <sys/time.h>
50 #include <sys/timetc.h>
51 #include <sys/fbio.h>
52 #include <sys/consio.h>
53
54 #include <sys/kdb.h>
55
56 #include <machine/bus.h>
57 #include <machine/cpu.h>
58 #include <machine/cpufunc.h>
59 #include <machine/resource.h>
60 #include <machine/intr.h>
61
62 #include <dev/fdt/fdt_common.h>
63 #include <dev/ofw/ofw_bus.h>
64 #include <dev/ofw/ofw_bus_subr.h>
65
66 #include <dev/fb/fbreg.h>
67 #include <dev/syscons/syscons.h>
68
69 #include <arm/freescale/imx/imx51_ccmvar.h>
70
71 #include <arm/freescale/imx/imx51_ipuv3reg.h>
72
73 #define IMX51_IPU_HSP_CLOCK     665000000
74 #define IPU3FB_FONT_HEIGHT      16
75
76 struct ipu3sc_softc {
77         device_t                dev;
78         bus_addr_t              pbase;
79         bus_addr_t              vbase;
80
81         bus_space_tag_t         iot;
82         bus_space_handle_t      ioh;
83         bus_space_handle_t      cm_ioh;
84         bus_space_handle_t      dp_ioh;
85         bus_space_handle_t      di0_ioh;
86         bus_space_handle_t      di1_ioh;
87         bus_space_handle_t      dctmpl_ioh;
88         bus_space_handle_t      dc_ioh;
89         bus_space_handle_t      dmfc_ioh;
90         bus_space_handle_t      idmac_ioh;
91         bus_space_handle_t      cpmem_ioh;
92 };
93
94 struct video_adapter_softc {
95         /* Videoadpater part */
96         video_adapter_t va;
97
98         intptr_t        fb_addr;
99         intptr_t        fb_paddr;
100         unsigned int    fb_size;
101
102         int             bpp;
103         int             depth;
104         unsigned int    height;
105         unsigned int    width;
106         unsigned int    stride;
107
108         unsigned int    xmargin;
109         unsigned int    ymargin;
110
111         unsigned char   *font;
112         int             initialized;
113 };
114
115 static struct ipu3sc_softc *ipu3sc_softc;
116 static struct video_adapter_softc va_softc;
117
118 /* FIXME: not only 2 bytes color supported */
119 static uint16_t colors[16] = {
120         0x0000, /* black */
121         0x001f, /* blue */
122         0x07e0, /* green */
123         0x07ff, /* cyan */
124         0xf800, /* red */
125         0xf81f, /* magenta */
126         0x3800, /* brown */
127         0xc618, /* light grey */
128         0xc618, /* XXX: dark grey */
129         0x001f, /* XXX: light blue */
130         0x07e0, /* XXX: light green */
131         0x07ff, /* XXX: light cyan */
132         0xf800, /* XXX: light red */
133         0xf81f, /* XXX: light magenta */
134         0xffe0, /* yellow */
135         0xffff, /* white */
136 };
137 static uint32_t colors_24[16] = {
138         0x000000,/* Black       */
139         0x000080,/* Blue        */
140         0x008000,/* Green       */
141         0x008080,/* Cyan        */
142         0x800000,/* Red         */
143         0x800080,/* Magenta     */
144         0xcc6600,/* brown       */
145         0xC0C0C0,/* Silver      */
146         0x808080,/* Gray        */
147         0x0000FF,/* Light Blue  */
148         0x00FF00,/* Light Green */
149         0x00FFFF,/* Light Cyan  */
150         0xFF0000,/* Light Red   */
151         0xFF00FF,/* Light Magenta */
152         0xFFFF00,/* Yellow      */
153         0xFFFFFF,/* White       */
154
155
156 };
157
158 #define IPUV3_READ(ipuv3, module, reg)                                  \
159         bus_space_read_4((ipuv3)->iot, (ipuv3)->module##_ioh, (reg))
160 #define IPUV3_WRITE(ipuv3, module, reg, val)                            \
161         bus_space_write_4((ipuv3)->iot, (ipuv3)->module##_ioh, (reg), (val))
162
163 #define CPMEM_CHANNEL_OFFSET(_c)        ((_c) * 0x40)
164 #define CPMEM_WORD_OFFSET(_w)           ((_w) * 0x20)
165 #define CPMEM_DP_OFFSET(_d)             ((_d) * 0x10000)
166 #define IMX_IPU_DP0             0
167 #define IMX_IPU_DP1             1
168 #define CPMEM_CHANNEL(_dp, _ch, _w)                                     \
169             (CPMEM_DP_OFFSET(_dp) + CPMEM_CHANNEL_OFFSET(_ch) +         \
170                 CPMEM_WORD_OFFSET(_w))
171 #define CPMEM_OFFSET(_dp, _ch, _w, _o)                                  \
172             (CPMEM_CHANNEL((_dp), (_ch), (_w)) + (_o))
173
174 #define IPUV3_DEBUG 100
175
176 #ifdef IPUV3_DEBUG
177 #define SUBMOD_DUMP_REG(_sc, _m, _l)                                    \
178         {                                                               \
179                 int i;                                                  \
180                 printf("*** " #_m " ***\n");                            \
181                 for (i = 0; i <= (_l); i += 4) {                        \
182                         if ((i % 32) == 0)                              \
183                                 printf("%04x: ", i & 0xffff);           \
184                         printf("0x%08x%c", IPUV3_READ((_sc), _m, i),    \
185                             ((i + 4) % 32)?' ':'\n');                   \
186                 }                                                       \
187                 printf("\n");                                           \
188         }
189 #endif
190
191 #ifdef IPUV3_DEBUG
192 int ipuv3_debug = IPUV3_DEBUG;
193 #define DPRINTFN(n,x)   if (ipuv3_debug>(n)) printf x; else
194 #else
195 #define DPRINTFN(n,x)
196 #endif
197
198 static int      ipu3_fb_probe(device_t);
199 static int      ipu3_fb_attach(device_t);
200
201 static int
202 ipu3_fb_malloc(struct ipu3sc_softc *sc, size_t size)
203 {
204
205         sc->vbase = (uint32_t)contigmalloc(size, M_DEVBUF, M_ZERO, 0, ~0,
206             PAGE_SIZE, 0);
207         sc->pbase = vtophys(sc->vbase);
208
209         return (0);
210 }
211
212 static void
213 ipu3_fb_init(void *arg)
214 {
215         struct ipu3sc_softc *sc = arg;
216         struct video_adapter_softc *va_sc = &va_softc;
217         uint64_t w0sh96;
218         uint32_t w1sh96;
219
220         /* FW W0[137:125] - 96 = [41:29] */
221         /* FH W0[149:138] - 96 = [53:42] */
222         w0sh96 = IPUV3_READ(sc, cpmem, CPMEM_OFFSET(IMX_IPU_DP1, 23, 0, 16));
223         w0sh96 <<= 32;
224         w0sh96 |= IPUV3_READ(sc, cpmem, CPMEM_OFFSET(IMX_IPU_DP1, 23, 0, 12));
225
226         va_sc->width = ((w0sh96 >> 29) & 0x1fff) + 1;
227         va_sc->height = ((w0sh96 >> 42) & 0x0fff) + 1;
228
229         /* SLY W1[115:102] - 96 = [19:6] */
230         w1sh96 = IPUV3_READ(sc, cpmem, CPMEM_OFFSET(IMX_IPU_DP1, 23, 1, 12));
231         va_sc->stride = ((w1sh96 >> 6) & 0x3fff) + 1;
232
233         printf("%dx%d [%d]\n", va_sc->width, va_sc->height, va_sc->stride);
234         va_sc->fb_size = va_sc->height * va_sc->stride;
235
236         ipu3_fb_malloc(sc, va_sc->fb_size);
237
238         /* DP1 + config_ch_23 + word_2 */
239         IPUV3_WRITE(sc, cpmem, CPMEM_OFFSET(IMX_IPU_DP1, 23, 1, 0),
240             ((sc->pbase >> 3) | ((sc->pbase >> 3) << 29)) & 0xffffffff);
241
242         IPUV3_WRITE(sc, cpmem, CPMEM_OFFSET(IMX_IPU_DP1, 23, 1, 4),
243             ((sc->pbase >> 3) >> 3) & 0xffffffff);
244
245         va_sc->fb_addr = (intptr_t)sc->vbase;
246         va_sc->fb_paddr = (intptr_t)sc->pbase;
247         va_sc->bpp = va_sc->stride / va_sc->width;
248         va_sc->depth = va_sc->bpp * 8;
249 }
250
251 static int
252 ipu3_fb_probe(device_t dev)
253 {
254         int error;
255
256         if (!ofw_bus_is_compatible(dev, "fsl,ipu3"))
257                 return (ENXIO);
258
259         device_set_desc(dev, "i.MX515 Image Processing Unit (FB)");
260
261         error = sc_probe_unit(device_get_unit(dev), 
262             device_get_flags(dev) | SC_AUTODETECT_KBD);
263
264         if (error != 0)
265                 return (error);
266
267         return (BUS_PROBE_DEFAULT);
268 }
269
270 static int
271 ipu3_fb_attach(device_t dev)
272 {
273         struct ipu3sc_softc *sc = device_get_softc(dev);
274         bus_space_tag_t iot;
275         bus_space_handle_t ioh;
276         int err;
277
278         if (ipu3sc_softc)
279                 return (ENXIO);
280
281         ipu3sc_softc = sc;
282
283         device_printf(dev, "\tclock gate status is %d\n",
284             imx51_get_clk_gating(IMX51CLK_IPU_HSP_CLK_ROOT));
285
286         sc->dev = dev;
287
288         err = (sc_attach_unit(device_get_unit(dev),
289             device_get_flags(dev) | SC_AUTODETECT_KBD));
290
291         if (err) {
292                 device_printf(dev, "failed to attach syscons\n");
293                 goto fail;
294         }
295
296         sc = device_get_softc(dev);
297         sc->iot = iot = fdtbus_bs_tag;
298
299         device_printf(sc->dev, ": i.MX51 IPUV3 controller\n");
300
301         /* map controller registers */
302         err = bus_space_map(iot, IPU_CM_BASE, IPU_CM_SIZE, 0, &ioh);
303         if (err)
304                 goto fail_retarn_cm;
305         sc->cm_ioh = ioh;
306
307         /* map Display Multi FIFO Controller registers */
308         err = bus_space_map(iot, IPU_DMFC_BASE, IPU_DMFC_SIZE, 0, &ioh);
309         if (err)
310                 goto fail_retarn_dmfc;
311         sc->dmfc_ioh = ioh;
312
313         /* map Display Interface 0 registers */
314         err = bus_space_map(iot, IPU_DI0_BASE, IPU_DI0_SIZE, 0, &ioh);
315         if (err)
316                 goto fail_retarn_di0;
317         sc->di0_ioh = ioh;
318
319         /* map Display Interface 1 registers */
320         err = bus_space_map(iot, IPU_DI1_BASE, IPU_DI0_SIZE, 0, &ioh);
321         if (err)
322                 goto fail_retarn_di1;
323         sc->di1_ioh = ioh;
324
325         /* map Display Processor registers */
326         err = bus_space_map(iot, IPU_DP_BASE, IPU_DP_SIZE, 0, &ioh);
327         if (err)
328                 goto fail_retarn_dp;
329         sc->dp_ioh = ioh;
330
331         /* map Display Controller registers */
332         err = bus_space_map(iot, IPU_DC_BASE, IPU_DC_SIZE, 0, &ioh);
333         if (err)
334                 goto fail_retarn_dc;
335         sc->dc_ioh = ioh;
336
337         /* map Image DMA Controller registers */
338         err = bus_space_map(iot, IPU_IDMAC_BASE, IPU_IDMAC_SIZE, 0, &ioh);
339         if (err)
340                 goto fail_retarn_idmac;
341         sc->idmac_ioh = ioh;
342
343         /* map CPMEM registers */
344         err = bus_space_map(iot, IPU_CPMEM_BASE, IPU_CPMEM_SIZE, 0, &ioh);
345         if (err)
346                 goto fail_retarn_cpmem;
347         sc->cpmem_ioh = ioh;
348
349         /* map DCTEMPL registers */
350         err = bus_space_map(iot, IPU_DCTMPL_BASE, IPU_DCTMPL_SIZE, 0, &ioh);
351         if (err)
352                 goto fail_retarn_dctmpl;
353         sc->dctmpl_ioh = ioh;
354
355 #ifdef notyet
356         sc->ih = imx51_ipuv3_intr_establish(IMX51_INT_IPUV3, IPL_BIO,
357             ipuv3intr, sc);
358         if (sc->ih == NULL) {
359                 device_printf(sc->dev,
360                     "unable to establish interrupt at irq %d\n",
361                     IMX51_INT_IPUV3);
362                 return (ENXIO);
363         }
364 #endif
365
366         /*
367          * We have to wait until interrupts are enabled. 
368          * Mailbox relies on it to get data from VideoCore
369          */
370         ipu3_fb_init(sc);
371
372         return (0);
373
374 fail:
375         return (ENXIO);
376 fail_retarn_dctmpl:
377         bus_space_unmap(sc->iot, sc->cpmem_ioh, IPU_CPMEM_SIZE);
378 fail_retarn_cpmem:
379         bus_space_unmap(sc->iot, sc->idmac_ioh, IPU_IDMAC_SIZE);
380 fail_retarn_idmac:
381         bus_space_unmap(sc->iot, sc->dc_ioh, IPU_DC_SIZE);
382 fail_retarn_dp:
383         bus_space_unmap(sc->iot, sc->dp_ioh, IPU_DP_SIZE);
384 fail_retarn_dc:
385         bus_space_unmap(sc->iot, sc->di1_ioh, IPU_DI1_SIZE);
386 fail_retarn_di1:
387         bus_space_unmap(sc->iot, sc->di0_ioh, IPU_DI0_SIZE);
388 fail_retarn_di0:
389         bus_space_unmap(sc->iot, sc->dmfc_ioh, IPU_DMFC_SIZE);
390 fail_retarn_dmfc:
391         bus_space_unmap(sc->iot, sc->dc_ioh, IPU_CM_SIZE);
392 fail_retarn_cm:
393         device_printf(sc->dev,
394             "failed to map registers (errno=%d)\n", err);
395         return (err);
396 }
397
398 static device_method_t ipu3_fb_methods[] = {
399         /* Device interface */
400         DEVMETHOD(device_probe,         ipu3_fb_probe),
401         DEVMETHOD(device_attach,        ipu3_fb_attach),
402
403         { 0, 0 }
404 };
405
406 static devclass_t ipu3_fb_devclass;
407
408 static driver_t ipu3_fb_driver = {
409         "fb",
410         ipu3_fb_methods,
411         sizeof(struct ipu3sc_softc),
412 };
413
414 DRIVER_MODULE(ipu3fb, simplebus, ipu3_fb_driver, ipu3_fb_devclass, 0, 0);
415
416 /*
417  * Video driver routines and glue.
418  */
419 static int                      ipu3fb_configure(int);
420 static vi_probe_t               ipu3fb_probe;
421 static vi_init_t                ipu3fb_init;
422 static vi_get_info_t            ipu3fb_get_info;
423 static vi_query_mode_t          ipu3fb_query_mode;
424 static vi_set_mode_t            ipu3fb_set_mode;
425 static vi_save_font_t           ipu3fb_save_font;
426 static vi_load_font_t           ipu3fb_load_font;
427 static vi_show_font_t           ipu3fb_show_font;
428 static vi_save_palette_t        ipu3fb_save_palette;
429 static vi_load_palette_t        ipu3fb_load_palette;
430 static vi_set_border_t          ipu3fb_set_border;
431 static vi_save_state_t          ipu3fb_save_state;
432 static vi_load_state_t          ipu3fb_load_state;
433 static vi_set_win_org_t         ipu3fb_set_win_org;
434 static vi_read_hw_cursor_t      ipu3fb_read_hw_cursor;
435 static vi_set_hw_cursor_t       ipu3fb_set_hw_cursor;
436 static vi_set_hw_cursor_shape_t ipu3fb_set_hw_cursor_shape;
437 static vi_blank_display_t       ipu3fb_blank_display;
438 static vi_mmap_t                ipu3fb_mmap;
439 static vi_ioctl_t               ipu3fb_ioctl;
440 static vi_clear_t               ipu3fb_clear;
441 static vi_fill_rect_t           ipu3fb_fill_rect;
442 static vi_bitblt_t              ipu3fb_bitblt;
443 static vi_diag_t                ipu3fb_diag;
444 static vi_save_cursor_palette_t ipu3fb_save_cursor_palette;
445 static vi_load_cursor_palette_t ipu3fb_load_cursor_palette;
446 static vi_copy_t                ipu3fb_copy;
447 static vi_putp_t                ipu3fb_putp;
448 static vi_putc_t                ipu3fb_putc;
449 static vi_puts_t                ipu3fb_puts;
450 static vi_putm_t                ipu3fb_putm;
451
452 static video_switch_t ipu3fbvidsw = {
453         .probe                  = ipu3fb_probe,
454         .init                   = ipu3fb_init,
455         .get_info               = ipu3fb_get_info,
456         .query_mode             = ipu3fb_query_mode,
457         .set_mode               = ipu3fb_set_mode,
458         .save_font              = ipu3fb_save_font,
459         .load_font              = ipu3fb_load_font,
460         .show_font              = ipu3fb_show_font,
461         .save_palette           = ipu3fb_save_palette,
462         .load_palette           = ipu3fb_load_palette,
463         .set_border             = ipu3fb_set_border,
464         .save_state             = ipu3fb_save_state,
465         .load_state             = ipu3fb_load_state,
466         .set_win_org            = ipu3fb_set_win_org,
467         .read_hw_cursor         = ipu3fb_read_hw_cursor,
468         .set_hw_cursor          = ipu3fb_set_hw_cursor,
469         .set_hw_cursor_shape    = ipu3fb_set_hw_cursor_shape,
470         .blank_display          = ipu3fb_blank_display,
471         .mmap                   = ipu3fb_mmap,
472         .ioctl                  = ipu3fb_ioctl,
473         .clear                  = ipu3fb_clear,
474         .fill_rect              = ipu3fb_fill_rect,
475         .bitblt                 = ipu3fb_bitblt,
476         .diag                   = ipu3fb_diag,
477         .save_cursor_palette    = ipu3fb_save_cursor_palette,
478         .load_cursor_palette    = ipu3fb_load_cursor_palette,
479         .copy                   = ipu3fb_copy,
480         .putp                   = ipu3fb_putp,
481         .putc                   = ipu3fb_putc,
482         .puts                   = ipu3fb_puts,
483         .putm                   = ipu3fb_putm,
484 };
485
486 VIDEO_DRIVER(ipu3fb, ipu3fbvidsw, ipu3fb_configure);
487
488 extern sc_rndr_sw_t txtrndrsw;
489 RENDERER(ipu3fb, 0, txtrndrsw, gfb_set);
490 RENDERER_MODULE(ipu3fb, gfb_set);
491
492 static uint16_t ipu3fb_static_window[ROW*COL];
493 extern u_char dflt_font_16[];
494
495 static int
496 ipu3fb_configure(int flags)
497 {
498         struct video_adapter_softc *sc;
499
500         sc = &va_softc;
501
502         if (sc->initialized)
503                 return 0;
504
505         sc->width = 640;
506         sc->height = 480;
507         sc->bpp = 2;
508         sc->stride = sc->width * sc->bpp;
509
510         ipu3fb_init(0, &sc->va, 0);
511
512         sc->initialized = 1;
513
514         return (0);
515 }
516
517 static int
518 ipu3fb_probe(int unit, video_adapter_t **adp, void *arg, int flags)
519 {
520
521         return (0);
522 }
523
524 static int
525 ipu3fb_init(int unit, video_adapter_t *adp, int flags)
526 {
527         struct video_adapter_softc *sc;
528         video_info_t *vi;
529
530         sc = (struct video_adapter_softc *)adp;
531         vi = &adp->va_info;
532
533         vid_init_struct(adp, "ipu3fb", -1, unit);
534
535         sc->font = dflt_font_16;
536         vi->vi_cheight = IPU3FB_FONT_HEIGHT;
537         vi->vi_cwidth = 8;
538         vi->vi_width = sc->width/8;
539         vi->vi_height = sc->height/vi->vi_cheight;
540
541         /*
542          * Clamp width/height to syscons maximums
543          */
544         if (vi->vi_width > COL)
545                 vi->vi_width = COL;
546         if (vi->vi_height > ROW)
547                 vi->vi_height = ROW;
548
549         sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2;
550         sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight))/2;
551
552         adp->va_window = (vm_offset_t) ipu3fb_static_window;
553         adp->va_flags |= V_ADP_FONT /* | V_ADP_COLOR | V_ADP_MODECHANGE */;
554         adp->va_line_width = sc->stride;
555         adp->va_buffer_size = sc->fb_size;
556
557         vid_register(&sc->va);
558
559         return (0);
560 }
561
562 static int
563 ipu3fb_get_info(video_adapter_t *adp, int mode, video_info_t *info)
564 {
565
566         bcopy(&adp->va_info, info, sizeof(*info));
567         return (0);
568 }
569
570 static int
571 ipu3fb_query_mode(video_adapter_t *adp, video_info_t *info)
572 {
573
574         return (0);
575 }
576
577 static int
578 ipu3fb_set_mode(video_adapter_t *adp, int mode)
579 {
580
581         return (0);
582 }
583
584 static int
585 ipu3fb_save_font(video_adapter_t *adp, int page, int size, int width,
586     u_char *data, int c, int count)
587 {
588
589         return (0);
590 }
591
592 static int
593 ipu3fb_load_font(video_adapter_t *adp, int page, int size, int width,
594     u_char *data, int c, int count)
595 {
596         struct video_adapter_softc *sc;
597
598         sc = (struct video_adapter_softc *)adp;
599         sc->font = data;
600
601         return (0);
602 }
603
604 static int
605 ipu3fb_show_font(video_adapter_t *adp, int page)
606 {
607
608         return (0);
609 }
610
611 static int
612 ipu3fb_save_palette(video_adapter_t *adp, u_char *palette)
613 {
614
615         return (0);
616 }
617
618 static int
619 ipu3fb_load_palette(video_adapter_t *adp, u_char *palette)
620 {
621
622         return (0);
623 }
624
625 static int
626 ipu3fb_set_border(video_adapter_t *adp, int border)
627 {
628
629         return (ipu3fb_blank_display(adp, border));
630 }
631
632 static int
633 ipu3fb_save_state(video_adapter_t *adp, void *p, size_t size)
634 {
635
636         return (0);
637 }
638
639 static int
640 ipu3fb_load_state(video_adapter_t *adp, void *p)
641 {
642
643         return (0);
644 }
645
646 static int
647 ipu3fb_set_win_org(video_adapter_t *adp, off_t offset)
648 {
649
650         return (0);
651 }
652
653 static int
654 ipu3fb_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
655 {
656
657         *col = *row = 0;
658         return (0);
659 }
660
661 static int
662 ipu3fb_set_hw_cursor(video_adapter_t *adp, int col, int row)
663 {
664
665         return (0);
666 }
667
668 static int
669 ipu3fb_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
670     int celsize, int blink)
671 {
672
673         return (0);
674 }
675
676 static int
677 ipu3fb_blank_display(video_adapter_t *adp, int mode)
678 {
679
680         return (0);
681 }
682
683 static int
684 ipu3fb_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr,
685     int prot, vm_memattr_t *memattr)
686 {
687         struct video_adapter_softc *sc;
688
689         sc = (struct video_adapter_softc *)adp;
690
691         /*
692          * This might be a legacy VGA mem request: if so, just point it at the
693          * framebuffer, since it shouldn't be touched
694          */
695         if (offset < sc->stride * sc->height) {
696                 *paddr = sc->fb_paddr + offset;
697                 return (0);
698         }
699
700         return (EINVAL);
701 }
702
703 static int
704 ipu3fb_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data)
705 {
706         struct video_adapter_softc *sc;
707         struct fbtype *fb;
708
709         sc = (struct video_adapter_softc *)adp;
710
711         switch (cmd) {
712         case FBIOGTYPE:
713                 fb = (struct fbtype *)data;
714                 fb->fb_type = FBTYPE_PCIMISC;
715                 fb->fb_height = sc->height;
716                 fb->fb_width = sc->width;
717                 fb->fb_depth = sc->depth;
718                 if (sc->depth <= 1 || sc->depth > 8)
719                         fb->fb_cmsize = 0;
720                 else
721                         fb->fb_cmsize = 1 << sc->depth;
722                 fb->fb_size = sc->fb_size;
723                 break;
724         case FBIOSCURSOR:
725                 return (ENODEV);
726         default:
727                 return (fb_commonioctl(adp, cmd, data));
728         }
729
730         return (0);
731 }
732
733 static int
734 ipu3fb_clear(video_adapter_t *adp)
735 {
736
737         return (ipu3fb_blank_display(adp, 0));
738 }
739
740 static int
741 ipu3fb_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
742 {
743
744         return (0);
745 }
746
747 static int
748 ipu3fb_bitblt(video_adapter_t *adp, ...)
749 {
750
751         return (0);
752 }
753
754 static int
755 ipu3fb_diag(video_adapter_t *adp, int level)
756 {
757
758         return (0);
759 }
760
761 static int
762 ipu3fb_save_cursor_palette(video_adapter_t *adp, u_char *palette)
763 {
764
765         return (0);
766 }
767
768 static int
769 ipu3fb_load_cursor_palette(video_adapter_t *adp, u_char *palette)
770 {
771
772         return (0);
773 }
774
775 static int
776 ipu3fb_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n)
777 {
778
779         return (0);
780 }
781
782 static int
783 ipu3fb_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a,
784     int size, int bpp, int bit_ltor, int byte_ltor)
785 {
786
787         return (0);
788 }
789
790 static int
791 ipu3fb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a)
792 {
793         struct video_adapter_softc *sc;
794         int col, row, bpp;
795         int b, i, j, k;
796         uint8_t *addr;
797         u_char *p;
798         uint32_t fg, bg, color;
799
800         sc = (struct video_adapter_softc *)adp;
801         bpp = sc->bpp;
802
803         if (sc->fb_addr == 0)
804                 return (0);
805         row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight;
806         col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth;
807         p = sc->font + c * IPU3FB_FONT_HEIGHT;
808         addr = (uint8_t *)sc->fb_addr
809             + (row + sc->ymargin) * (sc->stride)
810             + bpp * (col + sc->xmargin);
811
812         if (bpp == 2) {
813                 bg = colors[(a >> 4) & 0x0f];
814                 fg = colors[a & 0x0f];
815         } else if (bpp == 3) {
816                 bg = colors_24[(a >> 4) & 0x0f];
817                 fg = colors_24[a & 0x0f];
818         } else {
819                 return (ENXIO);
820         }
821
822         for (i = 0; i < IPU3FB_FONT_HEIGHT; i++) {
823                 for (j = 0, k = 7; j < 8; j++, k--) {
824                         if ((p[i] & (1 << k)) == 0)
825                                 color = bg;
826                         else
827                                 color = fg;
828                         /* FIXME: BPP maybe different */
829                         for (b = 0; b < bpp; b ++)
830                                 addr[bpp * j + b] =
831                                     (color >> (b << 3)) & 0xff;
832                 }
833
834                 addr += (sc->stride);
835         }
836
837         return (0);
838 }
839
840 static int
841 ipu3fb_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len)
842 {
843         int i;
844
845         for (i = 0; i < len; i++) 
846                 ipu3fb_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8);
847
848         return (0);
849 }
850
851 static int
852 ipu3fb_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image,
853     uint32_t pixel_mask, int size, int width)
854 {
855
856         return (0);
857 }
858
859 /*
860  * Define a stub keyboard driver in case one hasn't been
861  * compiled into the kernel
862  */
863 #include <sys/kbio.h>
864 #include <dev/kbd/kbdreg.h>
865
866 static int dummy_kbd_configure(int flags);
867
868 keyboard_switch_t ipu3dummysw;
869
870 static int
871 dummy_kbd_configure(int flags)
872 {
873
874         return (0);
875 }
876 KEYBOARD_DRIVER(ipu3dummy, ipu3dummysw, dummy_kbd_configure);