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