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