Home | History | Annotate | Line # | Download | only in dev
tft.c revision 1.1.4.2
      1  1.1.4.2  yamt /* 	$NetBSD: tft.c,v 1.1.4.2 2006/12/30 20:45:54 yamt Exp $ */
      2  1.1.4.2  yamt 
      3  1.1.4.2  yamt /*
      4  1.1.4.2  yamt  * Copyright (c) 2006 Jachym Holecek
      5  1.1.4.2  yamt  * All rights reserved.
      6  1.1.4.2  yamt  *
      7  1.1.4.2  yamt  * Written for DFC Design, s.r.o.
      8  1.1.4.2  yamt  *
      9  1.1.4.2  yamt  * Redistribution and use in source and binary forms, with or without
     10  1.1.4.2  yamt  * modification, are permitted provided that the following conditions
     11  1.1.4.2  yamt  * are met:
     12  1.1.4.2  yamt  *
     13  1.1.4.2  yamt  * 1. Redistributions of source code must retain the above copyright
     14  1.1.4.2  yamt  *    notice, this list of conditions and the following disclaimer.
     15  1.1.4.2  yamt  *
     16  1.1.4.2  yamt  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1.4.2  yamt  *    notice, this list of conditions and the following disclaimer in the
     18  1.1.4.2  yamt  *    documentation and/or other materials provided with the distribution.
     19  1.1.4.2  yamt  *
     20  1.1.4.2  yamt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  1.1.4.2  yamt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  1.1.4.2  yamt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.1.4.2  yamt  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  1.1.4.2  yamt  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  1.1.4.2  yamt  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  1.1.4.2  yamt  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  1.1.4.2  yamt  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.1.4.2  yamt  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  1.1.4.2  yamt  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  1.1.4.2  yamt  */
     31  1.1.4.2  yamt 
     32  1.1.4.2  yamt #include <sys/cdefs.h>
     33  1.1.4.2  yamt __KERNEL_RCSID(0, "$NetBSD: tft.c,v 1.1.4.2 2006/12/30 20:45:54 yamt Exp $");
     34  1.1.4.2  yamt 
     35  1.1.4.2  yamt #include <sys/param.h>
     36  1.1.4.2  yamt #include <sys/systm.h>
     37  1.1.4.2  yamt #include <sys/mbuf.h>
     38  1.1.4.2  yamt #include <sys/kernel.h>
     39  1.1.4.2  yamt #include <sys/socket.h>
     40  1.1.4.2  yamt #include <sys/ioctl.h>
     41  1.1.4.2  yamt #include <sys/device.h>
     42  1.1.4.2  yamt #include <sys/queue.h>
     43  1.1.4.2  yamt 
     44  1.1.4.2  yamt #include <uvm/uvm_extern.h>
     45  1.1.4.2  yamt 
     46  1.1.4.2  yamt #include <machine/bus.h>
     47  1.1.4.2  yamt 
     48  1.1.4.2  yamt #include <dev/wscons/wsdisplayvar.h>
     49  1.1.4.2  yamt #include <dev/wscons/wsconsio.h>
     50  1.1.4.2  yamt #include <dev/wsfont/wsfont.h>
     51  1.1.4.2  yamt #include <dev/rasops/rasops.h>
     52  1.1.4.2  yamt #include <dev/splash/splash.h>
     53  1.1.4.2  yamt #include <dev/wscons/wsdisplay_vconsvar.h>
     54  1.1.4.2  yamt 
     55  1.1.4.2  yamt #include <evbppc/virtex/dev/tftreg.h>
     56  1.1.4.2  yamt #include <evbppc/virtex/dev/tftvar.h>
     57  1.1.4.2  yamt 
     58  1.1.4.2  yamt 
     59  1.1.4.2  yamt /* Template. */
     60  1.1.4.2  yamt static struct wsscreen_descr tft_screen = {
     61  1.1.4.2  yamt 	.name 			= "fb",
     62  1.1.4.2  yamt 	.fontwidth 		= 8,
     63  1.1.4.2  yamt 	.fontheight 		= 16,
     64  1.1.4.2  yamt 	.capabilities 		= (WSSCREEN_WSCOLORS | WSSCREEN_HILIT |
     65  1.1.4.2  yamt 				   WSSCREEN_UNDERLINE | WSSCREEN_REVERSE),
     66  1.1.4.2  yamt };
     67  1.1.4.2  yamt 
     68  1.1.4.2  yamt static void tft_init_screen(void *, struct vcons_screen *, int, long *);
     69  1.1.4.2  yamt 
     70  1.1.4.2  yamt 
     71  1.1.4.2  yamt void
     72  1.1.4.2  yamt tft_attach(device_t self, struct wsdisplay_accessops *accessops)
     73  1.1.4.2  yamt {
     74  1.1.4.2  yamt 	struct wsemuldisplaydev_attach_args waa;
     75  1.1.4.2  yamt 	struct tft_softc 	*sc = device_private(self);
     76  1.1.4.2  yamt 	struct rasops_info 	*ri;
     77  1.1.4.2  yamt 	long 			defattr;
     78  1.1.4.2  yamt 
     79  1.1.4.2  yamt 	KASSERT(accessops->mmap);
     80  1.1.4.2  yamt 
     81  1.1.4.2  yamt 	if (accessops->ioctl == NULL)
     82  1.1.4.2  yamt 		accessops->ioctl = tft_ioctl;
     83  1.1.4.2  yamt 
     84  1.1.4.2  yamt 	printf("%s: %ux%ux%ub\n", device_xname(self), sc->sc_width,
     85  1.1.4.2  yamt 	    sc->sc_height, sc->sc_bpp);
     86  1.1.4.2  yamt 	printf("%s: video memory va %p size %uB stride %uB\n",
     87  1.1.4.2  yamt 	    device_xname(self), sc->sc_image, sc->sc_size, sc->sc_stride);
     88  1.1.4.2  yamt 
     89  1.1.4.2  yamt 	memset(sc->sc_image, 0xf0, sc->sc_size);
     90  1.1.4.2  yamt 
     91  1.1.4.2  yamt 	/* Setup descr template, make up list. */
     92  1.1.4.2  yamt 	sc->sc_ws_descr_storage[0] = tft_screen; 	/* struct copy */
     93  1.1.4.2  yamt 	sc->sc_ws_descr = sc->sc_ws_descr_storage;
     94  1.1.4.2  yamt 	sc->sc_ws_scrlist.nscreens = 1;
     95  1.1.4.2  yamt 	sc->sc_ws_scrlist.screens =
     96  1.1.4.2  yamt 	    (const struct wsscreen_descr **)&sc->sc_ws_descr;
     97  1.1.4.2  yamt 
     98  1.1.4.2  yamt 	vcons_init(&sc->sc_vc_data, self, sc->sc_ws_descr, accessops);
     99  1.1.4.2  yamt 
    100  1.1.4.2  yamt 	sc->sc_vc_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
    101  1.1.4.2  yamt 	sc->sc_vc_data.init_screen = tft_init_screen;
    102  1.1.4.2  yamt 	sc->sc_vc_data.cookie = sc;
    103  1.1.4.2  yamt 
    104  1.1.4.2  yamt 	vcons_init_screen(&sc->sc_vc_data, &sc->sc_vc_screen, 1, &defattr);
    105  1.1.4.2  yamt 
    106  1.1.4.2  yamt 	/* Patch descr. */
    107  1.1.4.2  yamt 	ri = &sc->sc_vc_screen.scr_ri;
    108  1.1.4.2  yamt 	sc->sc_ws_descr->textops = &ri->ri_ops;
    109  1.1.4.2  yamt 	sc->sc_ws_descr->capabilities = ri->ri_caps;
    110  1.1.4.2  yamt 	sc->sc_ws_descr->nrows = ri->ri_rows;
    111  1.1.4.2  yamt 	sc->sc_ws_descr->ncols = ri->ri_cols;
    112  1.1.4.2  yamt 
    113  1.1.4.2  yamt #ifdef	SPLASHSCREEN
    114  1.1.4.2  yamt 	sc->sc_sp_info.si_depth = ri->ri_depth;
    115  1.1.4.2  yamt 	sc->sc_sp_info.si_bits = ri->ri_bits;
    116  1.1.4.2  yamt 	sc->sc_sp_info.si_hwbits = ri->ri_hwbits;
    117  1.1.4.2  yamt 	sc->sc_sp_info.si_width = ri->ri_width;
    118  1.1.4.2  yamt 	sc->sc_sp_info.si_height = ri->ri_height;
    119  1.1.4.2  yamt 	sc->sc_sp_info.si_stride = ri->ri_stride;
    120  1.1.4.2  yamt 	sc->sc_sp_info.si_fillrect = NULL;
    121  1.1.4.2  yamt 
    122  1.1.4.2  yamt 	splash_render(&sc->sc_sp_info, SPLASH_F_CENTER | SPLASH_F_FILL);
    123  1.1.4.2  yamt #endif
    124  1.1.4.2  yamt 
    125  1.1.4.2  yamt #ifdef	SPLASHSCREEN_PROGRESS
    126  1.1.4.2  yamt 	sc->sc_sp_progress.sp_top = (sc->sc_height / 8) * 7;
    127  1.1.4.2  yamt 	sc->sc_sp_progress.sp_width = (sc->sc_width / 4) * 3;
    128  1.1.4.2  yamt 	sc->sc_sp_progress.sp_left = (sc->sc_width -
    129  1.1.4.2  yamt 	    sc->sc_sp_progress.sp_width) / 2;
    130  1.1.4.2  yamt 	sc->sc_sp_progress.sp_height = 20;
    131  1.1.4.2  yamt 	sc->sc_sp_progress.sp_state = -1;
    132  1.1.4.2  yamt 	sc->sc_sp_progress.sp_si = &sc->sc_sp_info;
    133  1.1.4.2  yamt 
    134  1.1.4.2  yamt 	splash_progress_init(&sc->sc_sp_progress);
    135  1.1.4.2  yamt 	SCREEN_DISABLE_DRAWING(&sc->sc_vc_screen);
    136  1.1.4.2  yamt #endif
    137  1.1.4.2  yamt 
    138  1.1.4.2  yamt 	if (sc->sc_sdhook == NULL) {
    139  1.1.4.2  yamt 		sc->sc_sdhook = shutdownhook_establish(tft_shutdown, self);
    140  1.1.4.2  yamt 		if (sc->sc_sdhook == NULL)
    141  1.1.4.2  yamt 			printf("%s: WARNING: unable to establish shutdown "
    142  1.1.4.2  yamt 			    "hook\n", device_xname(self));
    143  1.1.4.2  yamt 	}
    144  1.1.4.2  yamt 
    145  1.1.4.2  yamt 	waa.console = 0; 			/* XXX */
    146  1.1.4.2  yamt 	waa.scrdata = &sc->sc_ws_scrlist;
    147  1.1.4.2  yamt 	waa.accessops = accessops;
    148  1.1.4.2  yamt 	waa.accesscookie = &sc->sc_vc_data;
    149  1.1.4.2  yamt 
    150  1.1.4.2  yamt 	config_found(self, &waa, wsemuldisplaydevprint);
    151  1.1.4.2  yamt }
    152  1.1.4.2  yamt 
    153  1.1.4.2  yamt static void
    154  1.1.4.2  yamt tft_init_screen(void *cookie, struct vcons_screen *scr, int existing,
    155  1.1.4.2  yamt     long *defattr)
    156  1.1.4.2  yamt {
    157  1.1.4.2  yamt 	struct tft_softc 	*sc = cookie;
    158  1.1.4.2  yamt 	struct rasops_info 	*ri = &scr->scr_ri;
    159  1.1.4.2  yamt 
    160  1.1.4.2  yamt 	/* initialize font subsystem */
    161  1.1.4.2  yamt 	wsfont_init();
    162  1.1.4.2  yamt 
    163  1.1.4.2  yamt 	ri->ri_depth = sc->sc_bpp;
    164  1.1.4.2  yamt 	ri->ri_width = sc->sc_width;
    165  1.1.4.2  yamt 	ri->ri_height = sc->sc_height;
    166  1.1.4.2  yamt 	ri->ri_stride = sc->sc_stride;
    167  1.1.4.2  yamt 	ri->ri_flg = /*RI_CENTER |*/ RI_CLEAR;
    168  1.1.4.2  yamt 	ri->ri_bits = (void *)sc->sc_image;
    169  1.1.4.2  yamt 	ri->ri_caps = WSSCREEN_WSCOLORS;
    170  1.1.4.2  yamt 
    171  1.1.4.2  yamt 	ri->ri_rnum = 8;
    172  1.1.4.2  yamt 	ri->ri_gnum = 8;
    173  1.1.4.2  yamt 	ri->ri_bnum = 8;
    174  1.1.4.2  yamt 	ri->ri_rpos = 16;
    175  1.1.4.2  yamt 	ri->ri_gpos = 8;
    176  1.1.4.2  yamt 	ri->ri_bpos = 0;
    177  1.1.4.2  yamt 
    178  1.1.4.2  yamt 	rasops_init(ri, ri->ri_height / 16, ri->ri_width / 8);
    179  1.1.4.2  yamt 
    180  1.1.4.2  yamt 	/* we'd override rasops methods now if we had acceleration */
    181  1.1.4.2  yamt }
    182  1.1.4.2  yamt 
    183  1.1.4.2  yamt void
    184  1.1.4.2  yamt tft_shutdown(void *arg)
    185  1.1.4.2  yamt {
    186  1.1.4.2  yamt 	struct tft_softc 	*sc = arg;
    187  1.1.4.2  yamt 
    188  1.1.4.2  yamt 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, TFT_CTRL, CTRL_RESET);
    189  1.1.4.2  yamt }
    190  1.1.4.2  yamt 
    191  1.1.4.2  yamt int
    192  1.1.4.2  yamt tft_mode(device_t dev)
    193  1.1.4.2  yamt {
    194  1.1.4.2  yamt 	struct tft_softc 		*sc = device_private(dev);
    195  1.1.4.2  yamt 	prop_number_t 			pn;
    196  1.1.4.2  yamt 
    197  1.1.4.2  yamt 	/* Defaults for tft core generics. */
    198  1.1.4.2  yamt 	sc->sc_width 	= 640;
    199  1.1.4.2  yamt 	sc->sc_height 	= 480;
    200  1.1.4.2  yamt 	sc->sc_stride 	= 1024 * 4;
    201  1.1.4.2  yamt 	sc->sc_bpp 	= 32; 		/* 24bit colour, not packed */
    202  1.1.4.2  yamt 
    203  1.1.4.2  yamt 	/* We can make all these mandatory if it becomes practical... */
    204  1.1.4.2  yamt 	pn = prop_dictionary_get(device_properties(dev), "x-resolution");
    205  1.1.4.2  yamt 	if (pn != NULL)
    206  1.1.4.2  yamt 		sc->sc_width = (u_int)prop_number_integer_value(pn);
    207  1.1.4.2  yamt 
    208  1.1.4.2  yamt 	pn = prop_dictionary_get(device_properties(dev), "y-resolution");
    209  1.1.4.2  yamt 	if (pn != NULL)
    210  1.1.4.2  yamt 		sc->sc_height = (u_int)prop_number_integer_value(pn);
    211  1.1.4.2  yamt 
    212  1.1.4.2  yamt 	pn = prop_dictionary_get(device_properties(dev), "stride-bytes");
    213  1.1.4.2  yamt 	if (pn != NULL)
    214  1.1.4.2  yamt 		sc->sc_stride = (u_int)prop_number_integer_value(pn);
    215  1.1.4.2  yamt 
    216  1.1.4.2  yamt 	pn = prop_dictionary_get(device_properties(dev), "bits-per-pixel");
    217  1.1.4.2  yamt 	if (pn != NULL)
    218  1.1.4.2  yamt 		sc->sc_bpp = (u_int)prop_number_integer_value(pn);
    219  1.1.4.2  yamt 
    220  1.1.4.2  yamt 	sc->sc_size = sc->sc_stride * sc->sc_height;
    221  1.1.4.2  yamt 	return (0);
    222  1.1.4.2  yamt }
    223  1.1.4.2  yamt 
    224  1.1.4.2  yamt int
    225  1.1.4.2  yamt tft_ioctl(void *arg, void *scr, u_long cmd, caddr_t data, int flag,
    226  1.1.4.2  yamt     struct lwp *l)
    227  1.1.4.2  yamt {
    228  1.1.4.2  yamt 	struct vcons_data 	*vd = arg;
    229  1.1.4.2  yamt 	struct tft_softc 	*sc = vd->cookie;
    230  1.1.4.2  yamt 	struct wsdisplay_fbinfo *info;
    231  1.1.4.2  yamt 
    232  1.1.4.2  yamt 	switch (cmd) {
    233  1.1.4.2  yamt 	case WSDISPLAYIO_GTYPE:
    234  1.1.4.2  yamt 		*(u_int *)data = WSDISPLAY_TYPE_XILFB;
    235  1.1.4.2  yamt 		return (0);
    236  1.1.4.2  yamt 
    237  1.1.4.2  yamt 	case WSDISPLAYIO_GINFO:
    238  1.1.4.2  yamt 		info = (struct wsdisplay_fbinfo *)data;
    239  1.1.4.2  yamt 
    240  1.1.4.2  yamt 		info->height = sc->sc_height;
    241  1.1.4.2  yamt 		info->width = sc->sc_width;
    242  1.1.4.2  yamt 		info->depth = sc->sc_bpp;
    243  1.1.4.2  yamt 		info->cmsize = 0;
    244  1.1.4.2  yamt 
    245  1.1.4.2  yamt 		return (0);
    246  1.1.4.2  yamt 	case WSDISPLAYIO_LINEBYTES:
    247  1.1.4.2  yamt 		*(u_int *)data = sc->sc_stride;
    248  1.1.4.2  yamt 
    249  1.1.4.2  yamt 		return (0);
    250  1.1.4.2  yamt 	}
    251  1.1.4.2  yamt 
    252  1.1.4.2  yamt 	return (EPASSTHROUGH);
    253  1.1.4.2  yamt }
    254