Home | History | Annotate | Line # | Download | only in igma
igmafb.c revision 1.1.36.1
      1  1.1.36.1   martin /*	$NetBSD: igmafb.c,v 1.1.36.1 2020/04/08 14:08:10 martin Exp $	*/
      2       1.1  mlelstv 
      3       1.1  mlelstv /*
      4       1.1  mlelstv  * Copyright (c) 2012 Michael van Elst
      5       1.1  mlelstv  *
      6       1.1  mlelstv  * Permission to use, copy, modify, and distribute this software for any
      7       1.1  mlelstv  * purpose with or without fee is hereby granted, provided that the above
      8       1.1  mlelstv  * copyright notice and this permission notice appear in all copies.
      9       1.1  mlelstv  *
     10       1.1  mlelstv  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     11       1.1  mlelstv  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     12       1.1  mlelstv  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     13       1.1  mlelstv  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     14       1.1  mlelstv  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     15       1.1  mlelstv  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     16       1.1  mlelstv  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     17       1.1  mlelstv  */
     18       1.1  mlelstv 
     19       1.1  mlelstv /*
     20       1.1  mlelstv  * Intel Graphic Media Accelerator
     21       1.1  mlelstv  */
     22       1.1  mlelstv 
     23       1.1  mlelstv #include <sys/cdefs.h>
     24  1.1.36.1   martin __KERNEL_RCSID(0, "$NetBSD: igmafb.c,v 1.1.36.1 2020/04/08 14:08:10 martin Exp $");
     25       1.1  mlelstv 
     26       1.1  mlelstv #include <sys/param.h>
     27       1.1  mlelstv #include <sys/systm.h>
     28       1.1  mlelstv #include <sys/device.h>
     29       1.1  mlelstv #include <sys/bus.h>
     30       1.1  mlelstv #include <sys/kmem.h>
     31       1.1  mlelstv 
     32       1.1  mlelstv #include <dev/pci/pcireg.h>
     33       1.1  mlelstv #include <dev/pci/pcivar.h>
     34       1.1  mlelstv #include <dev/pci/pcidevs.h>
     35       1.1  mlelstv #include <dev/pci/pciio.h>
     36       1.1  mlelstv 
     37       1.1  mlelstv #include <dev/videomode/videomode.h>
     38       1.1  mlelstv 
     39       1.1  mlelstv #include <dev/wscons/wsdisplayvar.h>
     40       1.1  mlelstv #include <dev/wscons/wsconsio.h>
     41       1.1  mlelstv #include <dev/wsfont/wsfont.h>
     42       1.1  mlelstv #include <dev/rasops/rasops.h>
     43       1.1  mlelstv #include <dev/wscons/wsdisplay_vconsvar.h>
     44       1.1  mlelstv #include <dev/pci/wsdisplay_pci.h>
     45       1.1  mlelstv 
     46       1.1  mlelstv #include <dev/pci/igmareg.h>
     47       1.1  mlelstv #include <dev/pci/igmavar.h>
     48       1.1  mlelstv 
     49       1.1  mlelstv #include "opt_voyagerfb.h"
     50       1.1  mlelstv 
     51       1.1  mlelstv struct igmafb_softc {
     52       1.1  mlelstv 	device_t		sc_dev;
     53       1.1  mlelstv 
     54       1.1  mlelstv 	int 			sc_width;
     55       1.1  mlelstv 	int 			sc_height;
     56       1.1  mlelstv 	int 			sc_depth;
     57       1.1  mlelstv 	int 			sc_stride;
     58       1.1  mlelstv 	void			*sc_fbaddr;
     59       1.1  mlelstv 	bus_size_t		sc_fbsize;
     60       1.1  mlelstv 	struct vcons_screen	sc_console_screen;
     61       1.1  mlelstv 	struct wsscreen_descr	sc_defaultscreen_descr;
     62       1.1  mlelstv 	const struct wsscreen_descr	*sc_screens[1];
     63       1.1  mlelstv 	struct wsscreen_list	sc_screenlist;
     64       1.1  mlelstv 	struct vcons_data	vd;
     65       1.1  mlelstv 
     66       1.1  mlelstv 	struct igma_chip	sc_chip;
     67       1.1  mlelstv 	void			*sc_vga_save;
     68       1.1  mlelstv 
     69       1.1  mlelstv 	int			sc_backlight;
     70       1.1  mlelstv 	int			sc_brightness;
     71       1.1  mlelstv 	int			sc_brightness_max;
     72       1.1  mlelstv };
     73       1.1  mlelstv 
     74       1.1  mlelstv static int igmafb_match(device_t, cfdata_t, void *);
     75       1.1  mlelstv static void igmafb_attach(device_t, device_t, void *);
     76       1.1  mlelstv 
     77       1.1  mlelstv CFATTACH_DECL_NEW(igmafb, sizeof(struct igmafb_softc),
     78       1.1  mlelstv     igmafb_match, igmafb_attach, NULL, NULL);
     79       1.1  mlelstv 
     80       1.1  mlelstv static int igmafb_ioctl(void *, void *, u_long, void *, int, struct lwp *);
     81       1.1  mlelstv static paddr_t igmafb_mmap(void *, void *, off_t, int);
     82       1.1  mlelstv static void igmafb_pollc(void *v, int);
     83       1.1  mlelstv 
     84       1.1  mlelstv static /*const*/ struct wsdisplay_accessops igmafb_accessops = {
     85       1.1  mlelstv 	igmafb_ioctl,
     86       1.1  mlelstv 	igmafb_mmap,
     87       1.1  mlelstv 	NULL,	/* alloc_screen */
     88       1.1  mlelstv 	NULL,	/* free_screen */
     89       1.1  mlelstv 	NULL,	/* show_screen */
     90       1.1  mlelstv 	NULL,	/* load_font */
     91       1.1  mlelstv 	igmafb_pollc,	/* pollc */
     92       1.1  mlelstv 	NULL	/* scroll */
     93       1.1  mlelstv };
     94       1.1  mlelstv 
     95       1.1  mlelstv static void igmafb_init_screen(void *, struct vcons_screen *, int, long *);
     96       1.1  mlelstv static void igmafb_guess_size(struct igmafb_softc *, int *, int*);
     97       1.1  mlelstv static void igmafb_set_mode(struct igmafb_softc *, bool);
     98       1.1  mlelstv 
     99       1.1  mlelstv static void igmafb_planestart_quirk(struct igmafb_softc *);
    100       1.1  mlelstv static void igmafb_pfitdisable_quirk(struct igmafb_softc *);
    101       1.1  mlelstv 
    102       1.1  mlelstv static void igmafb_get_brightness_max(struct igmafb_softc *, int *);
    103       1.1  mlelstv static void igmafb_get_brightness(struct igmafb_softc *, int *);
    104       1.1  mlelstv static void igmafb_set_brightness(struct igmafb_softc *, int);
    105       1.1  mlelstv 
    106       1.1  mlelstv static int
    107       1.1  mlelstv igmafb_match(device_t parent, cfdata_t match, void *aux)
    108       1.1  mlelstv {
    109       1.1  mlelstv 	struct igma_attach_args *iaa = (struct igma_attach_args *)aux;
    110       1.1  mlelstv 
    111       1.1  mlelstv 	if (strcmp(iaa->iaa_name, "igmafb") == 0) return 100;
    112       1.1  mlelstv 	return 0;
    113       1.1  mlelstv }
    114       1.1  mlelstv 
    115       1.1  mlelstv static void
    116       1.1  mlelstv igmafb_attach(device_t parent, device_t self, void *aux)
    117       1.1  mlelstv {
    118       1.1  mlelstv 	struct igmafb_softc *sc = device_private(self);
    119       1.1  mlelstv 	struct igma_attach_args *iaa = (struct igma_attach_args *)aux;
    120       1.1  mlelstv 	struct rasops_info *ri;
    121       1.1  mlelstv 	prop_dictionary_t dict;
    122       1.1  mlelstv 	bool is_console;
    123       1.1  mlelstv 	unsigned long defattr;
    124       1.1  mlelstv 	struct wsemuldisplaydev_attach_args waa;
    125       1.1  mlelstv 
    126       1.1  mlelstv 	sc->sc_dev = self;
    127       1.1  mlelstv 
    128       1.1  mlelstv 	aprint_normal("\n");
    129       1.1  mlelstv 
    130       1.1  mlelstv 	dict = device_properties(self);
    131       1.1  mlelstv 	prop_dictionary_get_bool(dict, "is_console", &is_console);
    132       1.1  mlelstv 	if (iaa->iaa_console)
    133       1.1  mlelstv 		is_console = true;
    134       1.1  mlelstv 
    135       1.1  mlelstv 	sc->sc_chip = iaa->iaa_chip;
    136       1.1  mlelstv 
    137       1.1  mlelstv 	sc->sc_fbaddr = bus_space_vaddr(sc->sc_chip.gmt, sc->sc_chip.gmh);
    138       1.1  mlelstv 	sc->sc_fbsize = 16 * 1024 * 1024;
    139       1.1  mlelstv 
    140       1.1  mlelstv 	igmafb_guess_size(sc, &sc->sc_width, &sc->sc_height);
    141       1.1  mlelstv 	sc->sc_depth = 32;
    142       1.1  mlelstv 	sc->sc_stride = (sc->sc_width*4 + 511)/512*512;
    143       1.1  mlelstv 
    144       1.1  mlelstv 	aprint_normal("%s: %d x %d, %d bit, stride %d\n", device_xname(self),
    145       1.1  mlelstv 		sc->sc_width, sc->sc_height, sc->sc_depth, sc->sc_stride);
    146       1.1  mlelstv 
    147  1.1.36.1   martin 	aprint_normal("%s: %d MB video memory at %p\n", device_xname(self),
    148       1.1  mlelstv 		(int)sc->sc_fbsize >> 20, (void *)sc->sc_chip.gmb);
    149       1.1  mlelstv 
    150       1.1  mlelstv 	sc->sc_vga_save = kmem_alloc(256*1024, KM_SLEEP);
    151       1.1  mlelstv 
    152       1.1  mlelstv 	igmafb_get_brightness(sc, &sc->sc_brightness);
    153       1.1  mlelstv 	igmafb_get_brightness_max(sc, &sc->sc_brightness_max);
    154       1.1  mlelstv 	sc->sc_backlight = sc->sc_brightness != 0;
    155       1.1  mlelstv 
    156       1.1  mlelstv 	sc->sc_defaultscreen_descr = (struct wsscreen_descr){
    157       1.1  mlelstv 		"default",
    158       1.1  mlelstv 		0, 0,
    159       1.1  mlelstv 		NULL,
    160       1.1  mlelstv 		8, 16,
    161       1.1  mlelstv 		WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    162       1.1  mlelstv 		NULL
    163       1.1  mlelstv 	};
    164       1.1  mlelstv 	sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
    165       1.1  mlelstv 	sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
    166       1.1  mlelstv 
    167       1.1  mlelstv 	vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr,
    168       1.1  mlelstv 		&igmafb_accessops);
    169       1.1  mlelstv 	sc->vd.init_screen = igmafb_init_screen;
    170       1.1  mlelstv 
    171       1.1  mlelstv 	/* enable hardware display */
    172       1.1  mlelstv 	igmafb_set_mode(sc, true);
    173       1.1  mlelstv 
    174       1.1  mlelstv 	ri = &sc->sc_console_screen.scr_ri;
    175       1.1  mlelstv 
    176       1.1  mlelstv 	if (is_console) {
    177       1.1  mlelstv 		vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
    178       1.1  mlelstv 			&defattr);
    179       1.1  mlelstv 
    180       1.1  mlelstv 		sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC
    181       1.1  mlelstv 			| VCONS_NO_COPYROWS | VCONS_NO_COPYCOLS;
    182       1.1  mlelstv 		vcons_redraw_screen(&sc->sc_console_screen);
    183       1.1  mlelstv 
    184       1.1  mlelstv 		sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
    185       1.1  mlelstv 		sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
    186       1.1  mlelstv 		sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
    187       1.1  mlelstv 		sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
    188       1.1  mlelstv 
    189       1.1  mlelstv 		wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
    190       1.1  mlelstv 			defattr);
    191       1.1  mlelstv 		vcons_replay_msgbuf(&sc->sc_console_screen);
    192       1.1  mlelstv 	} else {
    193       1.1  mlelstv 		if (sc->sc_console_screen.scr_ri.ri_rows == 0) {
    194       1.1  mlelstv 			/* do some minimal setup to avoid weirdness later */
    195       1.1  mlelstv 			vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
    196       1.1  mlelstv 				&defattr);
    197       1.1  mlelstv 		} else
    198       1.1  mlelstv 			(*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
    199       1.1  mlelstv 	}
    200       1.1  mlelstv 
    201       1.1  mlelstv 	waa.console = is_console;
    202       1.1  mlelstv 	waa.scrdata = &sc->sc_screenlist;
    203       1.1  mlelstv 	waa.accessops = &igmafb_accessops;
    204       1.1  mlelstv 	waa.accesscookie = &sc->vd;
    205       1.1  mlelstv 
    206       1.1  mlelstv 	config_found(sc->sc_dev, &waa, wsemuldisplaydevprint);
    207       1.1  mlelstv }
    208       1.1  mlelstv 
    209       1.1  mlelstv /*
    210       1.1  mlelstv  * wsdisplay accessops
    211       1.1  mlelstv  */
    212       1.1  mlelstv 
    213       1.1  mlelstv static int
    214       1.1  mlelstv igmafb_ioctl(void *v, void *vs, u_long cmd, void *data, int flags,
    215       1.1  mlelstv     struct lwp *l)
    216       1.1  mlelstv {
    217       1.1  mlelstv 	struct vcons_data *vd = v;
    218       1.1  mlelstv 	struct igmafb_softc *sc = vd->cookie;
    219       1.1  mlelstv 	struct wsdisplay_fbinfo *wdf;
    220       1.1  mlelstv 	struct vcons_screen *ms = vd->active;
    221       1.1  mlelstv 	struct wsdisplayio_fbinfo *fbi;
    222       1.1  mlelstv 	struct wsdisplay_param *param;
    223       1.1  mlelstv 	int val;
    224       1.1  mlelstv 
    225       1.1  mlelstv 	switch (cmd) {
    226       1.1  mlelstv 	case WSDISPLAYIO_GTYPE:
    227       1.1  mlelstv 		*(u_int *)data = WSDISPLAY_TYPE_PCIMISC;
    228       1.1  mlelstv 		return 0;
    229       1.1  mlelstv 	case WSDISPLAYIO_GINFO:
    230       1.1  mlelstv 		if (ms == NULL)
    231       1.1  mlelstv 			return ENODEV;
    232       1.1  mlelstv 		wdf = data;
    233       1.1  mlelstv 		wdf->width  = ms->scr_ri.ri_width;
    234       1.1  mlelstv 		wdf->height = ms->scr_ri.ri_height;
    235       1.1  mlelstv 		wdf->depth  = ms->scr_ri.ri_depth;
    236       1.1  mlelstv 		wdf->cmsize = 256; /* XXX */
    237       1.1  mlelstv 		return 0;
    238       1.1  mlelstv 	case WSDISPLAYIO_LINEBYTES:
    239       1.1  mlelstv 		if (ms == NULL)
    240       1.1  mlelstv 			return ENODEV;
    241       1.1  mlelstv 		*(u_int *)data = ms->scr_ri.ri_stride;
    242       1.1  mlelstv 		return 0;
    243       1.1  mlelstv 	case WSDISPLAYIO_GET_FBINFO:
    244       1.1  mlelstv 		fbi = data;
    245       1.1  mlelstv 		return wsdisplayio_get_fbinfo(&ms->scr_ri, fbi);
    246       1.1  mlelstv 	case WSDISPLAYIO_SVIDEO:
    247       1.1  mlelstv 		val = (*(u_int *)data) != WSDISPLAYIO_VIDEO_OFF;
    248       1.1  mlelstv 		sc->sc_backlight = val;
    249       1.1  mlelstv 		if (val)
    250       1.1  mlelstv 			igmafb_set_brightness(sc, sc->sc_brightness);
    251       1.1  mlelstv 		else
    252       1.1  mlelstv 			igmafb_set_brightness(sc, 0);
    253       1.1  mlelstv 		return 0;
    254       1.1  mlelstv 	case WSDISPLAYIO_GETPARAM:
    255       1.1  mlelstv 		param = (struct wsdisplay_param *)data;
    256       1.1  mlelstv 		switch (param->param) {
    257       1.1  mlelstv 		case WSDISPLAYIO_PARAM_BRIGHTNESS:
    258       1.1  mlelstv 			param->min = 0;
    259       1.1  mlelstv 			param->max = 255;
    260       1.1  mlelstv 			if (sc->sc_backlight)
    261       1.1  mlelstv 				igmafb_get_brightness(sc, &val);
    262       1.1  mlelstv 			else
    263       1.1  mlelstv 				val = sc->sc_brightness;
    264       1.1  mlelstv 			val = val * 255 / sc->sc_brightness_max;
    265       1.1  mlelstv 			param->curval = val;
    266       1.1  mlelstv 			return 0;
    267       1.1  mlelstv 		case WSDISPLAYIO_PARAM_BACKLIGHT:
    268       1.1  mlelstv 			param->min = 0;
    269       1.1  mlelstv 			param->max = 1;
    270       1.1  mlelstv 			param->curval = sc->sc_backlight;
    271       1.1  mlelstv 			return 0;
    272       1.1  mlelstv 		}
    273       1.1  mlelstv 		return EPASSTHROUGH;
    274       1.1  mlelstv 	case WSDISPLAYIO_SETPARAM:
    275       1.1  mlelstv 		param = (struct wsdisplay_param *)data;
    276       1.1  mlelstv 		switch (param->param) {
    277       1.1  mlelstv 		case WSDISPLAYIO_PARAM_BRIGHTNESS:
    278       1.1  mlelstv 			val = param->curval;
    279       1.1  mlelstv 			if (val < 0)
    280       1.1  mlelstv 				val = 0;
    281       1.1  mlelstv 			if (val > 255)
    282       1.1  mlelstv 				val = 255;
    283       1.1  mlelstv 			val = val * sc->sc_brightness_max / 255;
    284       1.1  mlelstv 			sc->sc_brightness = val;
    285       1.1  mlelstv 			if (sc->sc_backlight)
    286       1.1  mlelstv 				igmafb_set_brightness(sc, val);
    287       1.1  mlelstv 			return 0;
    288       1.1  mlelstv 		case WSDISPLAYIO_PARAM_BACKLIGHT:
    289       1.1  mlelstv 			val = param->curval;
    290       1.1  mlelstv 			sc->sc_backlight = val;
    291       1.1  mlelstv 			if (val)
    292       1.1  mlelstv 				igmafb_set_brightness(sc, sc->sc_brightness);
    293       1.1  mlelstv 			else
    294       1.1  mlelstv 				igmafb_set_brightness(sc, 0);
    295       1.1  mlelstv 			return 0;
    296       1.1  mlelstv 		}
    297       1.1  mlelstv 		return EPASSTHROUGH;
    298       1.1  mlelstv 	}
    299       1.1  mlelstv 
    300       1.1  mlelstv 	return EPASSTHROUGH;
    301       1.1  mlelstv }
    302       1.1  mlelstv 
    303       1.1  mlelstv static paddr_t
    304       1.1  mlelstv igmafb_mmap(void *v, void *vs, off_t offset, int prot)
    305       1.1  mlelstv {
    306       1.1  mlelstv 	struct vcons_data *vd = v;
    307       1.1  mlelstv 	struct igmafb_softc *sc = vd->cookie;
    308       1.1  mlelstv 
    309       1.1  mlelstv 	if ((offset & PAGE_MASK) != 0)
    310       1.1  mlelstv 		return -1;
    311       1.1  mlelstv 
    312       1.1  mlelstv 	if (offset < 0 || offset >= sc->sc_fbsize)
    313       1.1  mlelstv 		return -1;
    314       1.1  mlelstv 
    315       1.1  mlelstv 	return bus_space_mmap(sc->sc_chip.gmt, sc->sc_chip.gmb, offset, prot,
    316       1.1  mlelstv 		BUS_SPACE_MAP_LINEAR);
    317       1.1  mlelstv }
    318       1.1  mlelstv 
    319       1.1  mlelstv static void
    320       1.1  mlelstv igmafb_pollc(void *v, int on)
    321       1.1  mlelstv {
    322       1.1  mlelstv 	struct vcons_data *vd = v;
    323       1.1  mlelstv 	struct igmafb_softc *sc = vd->cookie;
    324       1.1  mlelstv 
    325       1.1  mlelstv 	if (sc == NULL)
    326       1.1  mlelstv 		return;
    327       1.1  mlelstv 	if (sc->sc_console_screen.scr_vd == NULL)
    328       1.1  mlelstv 		return;
    329       1.1  mlelstv 
    330       1.1  mlelstv 	if (on)
    331       1.1  mlelstv 		vcons_enable_polling(&sc->vd);
    332       1.1  mlelstv 	else
    333       1.1  mlelstv 		vcons_disable_polling(&sc->vd);
    334       1.1  mlelstv }
    335       1.1  mlelstv 
    336       1.1  mlelstv static void
    337       1.1  mlelstv igmafb_init_screen(void *cookie, struct vcons_screen *scr,
    338       1.1  mlelstv     int existing, long *defattr)
    339       1.1  mlelstv {
    340       1.1  mlelstv 	struct igmafb_softc *sc = cookie;
    341       1.1  mlelstv 	struct rasops_info *ri = &scr->scr_ri;
    342       1.1  mlelstv 
    343       1.1  mlelstv 	memset(ri, 0, sizeof(struct rasops_info));
    344       1.1  mlelstv 
    345       1.1  mlelstv 	ri->ri_depth = sc->sc_depth;
    346       1.1  mlelstv 	ri->ri_width = sc->sc_width;
    347       1.1  mlelstv 	ri->ri_height = sc->sc_height;
    348       1.1  mlelstv 	ri->ri_stride = sc->sc_stride;
    349       1.1  mlelstv 	ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
    350       1.1  mlelstv 
    351       1.1  mlelstv 	ri->ri_bits = (char *)sc->sc_fbaddr;
    352       1.1  mlelstv 
    353       1.1  mlelstv 	if (existing) {
    354       1.1  mlelstv 		ri->ri_flg |= RI_CLEAR;
    355       1.1  mlelstv 	}
    356       1.1  mlelstv 
    357       1.1  mlelstv 	switch (sc->sc_depth) {
    358       1.1  mlelstv 	case 32:
    359       1.1  mlelstv 		ri->ri_rnum = 8;
    360       1.1  mlelstv 		ri->ri_gnum = 8;
    361       1.1  mlelstv 		ri->ri_bnum = 8;
    362       1.1  mlelstv 		ri->ri_rpos = 16;
    363       1.1  mlelstv 		ri->ri_gpos = 8;
    364       1.1  mlelstv 		ri->ri_bpos = 0;
    365       1.1  mlelstv 		break;
    366       1.1  mlelstv 	}
    367       1.1  mlelstv 
    368       1.1  mlelstv 	rasops_init(ri, 0, 0);
    369       1.1  mlelstv 	ri->ri_caps = WSSCREEN_WSCOLORS;
    370       1.1  mlelstv 
    371       1.1  mlelstv 	rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
    372       1.1  mlelstv 		sc->sc_width / ri->ri_font->fontwidth);
    373       1.1  mlelstv 
    374       1.1  mlelstv 	ri->ri_hw = scr;
    375       1.1  mlelstv }
    376       1.1  mlelstv 
    377       1.1  mlelstv static void
    378       1.1  mlelstv igmafb_guess_size(struct igmafb_softc *sc, int *widthp, int *heightp)
    379       1.1  mlelstv {
    380       1.1  mlelstv 	const struct igma_chip *cd = &sc->sc_chip;
    381       1.1  mlelstv 	const struct igma_chip_ops *co = cd->ops;
    382       1.1  mlelstv 	int pipe = cd->use_pipe;
    383       1.1  mlelstv 	u_int32_t r;
    384       1.1  mlelstv 
    385       1.1  mlelstv 	r = co->read_reg(cd, PIPE_HTOTAL(pipe));
    386       1.1  mlelstv 	*widthp = PIPE_HTOTAL_GET_ACTIVE(r);
    387       1.1  mlelstv 	r = co->read_reg(cd, PIPE_VTOTAL(pipe));
    388       1.1  mlelstv 	*heightp = PIPE_VTOTAL_GET_ACTIVE(r);
    389       1.1  mlelstv 
    390       1.1  mlelstv 	aprint_normal("%s: vga active size %d x %d\n",
    391       1.1  mlelstv 		device_xname(sc->sc_dev),
    392       1.1  mlelstv 		*widthp, *heightp);
    393       1.1  mlelstv 
    394       1.1  mlelstv 	if (*widthp < 640 || *heightp < 400) {
    395       1.1  mlelstv 		r = co->read_reg(cd, PF_WINSZ(pipe));
    396       1.1  mlelstv 		*widthp  = PF_WINSZ_GET_WIDTH(r);
    397       1.1  mlelstv 		*heightp = PF_WINSZ_GET_HEIGHT(r);
    398       1.1  mlelstv 
    399       1.1  mlelstv 		aprint_normal("%s: window size %d x %d\n",
    400       1.1  mlelstv 			device_xname(sc->sc_dev),
    401       1.1  mlelstv 			*widthp, *heightp);
    402       1.1  mlelstv 	}
    403       1.1  mlelstv 
    404       1.1  mlelstv 	if (*widthp  < 640) *widthp  = 640;
    405       1.1  mlelstv 	if (*heightp < 400) *heightp = 400;
    406       1.1  mlelstv }
    407       1.1  mlelstv 
    408       1.1  mlelstv static void
    409       1.1  mlelstv igmafb_set_mode(struct igmafb_softc *sc, bool enable)
    410       1.1  mlelstv {
    411       1.1  mlelstv 	const struct igma_chip *cd = &sc->sc_chip;
    412       1.1  mlelstv 	const struct igma_chip_ops *co = cd->ops;
    413       1.1  mlelstv 	int pipe = cd->use_pipe;
    414       1.1  mlelstv 	u_int32_t r;
    415       1.1  mlelstv 	u_int8_t b;
    416       1.1  mlelstv 	int i;
    417       1.1  mlelstv 
    418       1.1  mlelstv 	if (enable) {
    419       1.1  mlelstv 		/* disable VGA machinery */
    420       1.1  mlelstv 		b = co->read_vga(cd, 0x01);
    421       1.1  mlelstv 		co->write_vga(cd, 0x01, b | 0x20);
    422       1.1  mlelstv 
    423       1.1  mlelstv 		/* disable VGA compatible display */
    424       1.1  mlelstv 		r = co->read_reg(cd, sc->sc_chip.vga_cntrl);
    425       1.1  mlelstv 		co->write_reg(cd, sc->sc_chip.vga_cntrl, r | VGA_CNTRL_DISABLE);
    426       1.1  mlelstv 
    427       1.1  mlelstv 		/* save VGA memory */
    428       1.1  mlelstv 		memcpy(sc->sc_vga_save, sc->sc_fbaddr, 256*1024);
    429       1.1  mlelstv 
    430       1.1  mlelstv 		/* configure panel fitter */
    431       1.1  mlelstv 		co->write_reg(cd, PF_WINPOS(pipe),
    432       1.1  mlelstv 			PF_WINPOS_VAL(0, 0));
    433       1.1  mlelstv 		co->write_reg(cd, PF_WINSZ(pipe),
    434       1.1  mlelstv 			PF_WINSZ_VAL(sc->sc_width, sc->sc_height));
    435       1.1  mlelstv 
    436       1.1  mlelstv 		/* pipe size */
    437       1.1  mlelstv 		co->write_reg(cd, PIPE_SRCSZ(pipe),
    438       1.1  mlelstv 			PIPE_SRCSZ_VAL(sc->sc_width, sc->sc_height));
    439       1.1  mlelstv 
    440       1.1  mlelstv 		/* enable pipe */
    441       1.1  mlelstv 		co->write_reg(cd, PIPE_CONF(pipe),
    442       1.1  mlelstv 			PIPE_CONF_ENABLE | PIPE_CONF_8BPP);
    443       1.1  mlelstv 
    444       1.1  mlelstv 		/* configure planes */
    445       1.1  mlelstv 		r = co->read_reg(cd, PRI_CTRL(pipe));
    446       1.1  mlelstv 		r &= ~(PRI_CTRL_PIXFMTMSK | PRI_CTRL_TILED);
    447       1.1  mlelstv 		r |= PRI_CTRL_ENABLE | PRI_CTRL_BGR;
    448       1.1  mlelstv 		co->write_reg(cd, PRI_CTRL(pipe), r | cd->pri_cntrl);
    449       1.1  mlelstv 		co->write_reg(cd, PRI_LINOFF(pipe), 0);
    450       1.1  mlelstv 		co->write_reg(cd, PRI_STRIDE(pipe), sc->sc_stride);
    451       1.1  mlelstv 		co->write_reg(cd, PRI_SURF(pipe), 0);
    452       1.1  mlelstv 		co->write_reg(cd, PRI_TILEOFF(pipe), 0);
    453       1.1  mlelstv 
    454       1.1  mlelstv 		if (cd->quirks & IGMA_PLANESTART_QUIRK)
    455       1.1  mlelstv 			igmafb_planestart_quirk(sc);
    456       1.1  mlelstv 
    457       1.1  mlelstv 		if (cd->quirks & IGMA_PFITDISABLE_QUIRK)
    458       1.1  mlelstv 			igmafb_pfitdisable_quirk(sc);
    459       1.1  mlelstv 	} else {
    460       1.1  mlelstv 		/* disable planes */
    461       1.1  mlelstv 		co->write_reg(cd, PRI_CTRL(pipe), 0 | cd->pri_cntrl);
    462       1.1  mlelstv 		co->write_reg(cd, PRI_LINOFF(pipe), 0);
    463       1.1  mlelstv 		co->write_reg(cd, PRI_STRIDE(pipe), 2560);
    464       1.1  mlelstv 		co->write_reg(cd, PRI_SURF(pipe), 0);
    465       1.1  mlelstv 		co->write_reg(cd, PRI_TILEOFF(pipe), 0);
    466       1.1  mlelstv 
    467       1.1  mlelstv 		/* pipe size */
    468       1.1  mlelstv 		co->write_reg(cd, PIPE_SRCSZ(pipe),
    469       1.1  mlelstv 			PIPE_SRCSZ_VAL(720,400));
    470       1.1  mlelstv 
    471       1.1  mlelstv 		/* disable pipe */
    472       1.1  mlelstv 		co->write_reg(cd, PIPE_CONF(pipe), 0);
    473       1.1  mlelstv 		for (i=0; i<10; ++i) {
    474       1.1  mlelstv 			delay(10);
    475       1.1  mlelstv 			if ((co->read_reg(cd, PIPE_CONF(pipe)) & PIPE_CONF_STATE) == 0)
    476       1.1  mlelstv 				break;
    477       1.1  mlelstv 		}
    478       1.1  mlelstv 
    479       1.1  mlelstv 		/* workaround before enabling VGA */
    480       1.1  mlelstv 		r = co->read_reg(cd, 0x42000);
    481       1.1  mlelstv 		co->write_reg(cd, 0x42000, (r & 0x1fffffff) | 0xa0000000);
    482       1.1  mlelstv 		r = co->read_reg(cd, 0x42004);
    483       1.1  mlelstv 		co->write_reg(cd, 0x42004, (r & 0xfbffffff) | 0x00000000);
    484       1.1  mlelstv 
    485       1.1  mlelstv 		/* configure panel fitter */
    486       1.1  mlelstv 		co->write_reg(cd, PF_WINPOS(pipe),
    487       1.1  mlelstv 			PF_WINPOS_VAL(0, 0));
    488       1.1  mlelstv 		co->write_reg(cd, PF_WINSZ(pipe),
    489       1.1  mlelstv 			PF_WINSZ_VAL(sc->sc_width, sc->sc_height));
    490       1.1  mlelstv 
    491       1.1  mlelstv 		/* enable VGA compatible display */
    492       1.1  mlelstv 		r = co->read_reg(cd, sc->sc_chip.vga_cntrl);
    493       1.1  mlelstv 		co->write_reg(cd, sc->sc_chip.vga_cntrl, r & ~VGA_CNTRL_DISABLE);
    494       1.1  mlelstv 
    495       1.1  mlelstv 		/* enable VGA machinery */
    496       1.1  mlelstv 		b = co->read_vga(cd, 0x01);
    497       1.1  mlelstv 		co->write_vga(cd, 0x01, b & ~0x20);
    498       1.1  mlelstv 
    499       1.1  mlelstv 		/* restore VGA memory */
    500       1.1  mlelstv 		memcpy(sc->sc_fbaddr, sc->sc_vga_save, 256*1024);
    501       1.1  mlelstv 
    502       1.1  mlelstv 		/* enable pipe again */
    503       1.1  mlelstv 		co->write_reg(cd, PIPE_CONF(pipe),
    504       1.1  mlelstv 			PIPE_CONF_ENABLE | PIPE_CONF_6BPP | PIPE_CONF_DITHER);
    505       1.1  mlelstv 	}
    506       1.1  mlelstv }
    507       1.1  mlelstv 
    508       1.1  mlelstv static void
    509       1.1  mlelstv igmafb_planestart_quirk(struct igmafb_softc *sc)
    510       1.1  mlelstv {
    511       1.1  mlelstv 	const struct igma_chip *cd = &sc->sc_chip;
    512       1.1  mlelstv 	const struct igma_chip_ops *co = cd->ops;
    513       1.1  mlelstv 	int pipe = cd->use_pipe;
    514       1.1  mlelstv 	u_int32_t cntrl, fwbcl;
    515       1.1  mlelstv 
    516       1.1  mlelstv 	/* disable self refresh */
    517       1.1  mlelstv 	fwbcl = co->read_reg(cd, FW_BLC_SELF);
    518       1.1  mlelstv 	co->write_reg(cd, FW_BLC_SELF, fwbcl & ~FW_BLC_SELF_EN);
    519       1.1  mlelstv 
    520       1.1  mlelstv 	cntrl = co->read_reg(cd, CUR_CNTR(pipe));
    521       1.1  mlelstv 	co->write_reg(cd, CUR_CNTR(pipe), 1<<5 | 0x07);
    522       1.1  mlelstv 
    523       1.1  mlelstv 	/* "wait for vblank" */
    524       1.1  mlelstv 	delay(40000);
    525       1.1  mlelstv 
    526       1.1  mlelstv 	co->write_reg(cd, CUR_CNTR(pipe), cntrl);
    527       1.1  mlelstv 	co->write_reg(cd, CUR_BASE(pipe),
    528       1.1  mlelstv 		co->read_reg(cd, CUR_BASE(pipe)));
    529       1.1  mlelstv 
    530       1.1  mlelstv 	co->write_reg(cd, FW_BLC_SELF, fwbcl);
    531       1.1  mlelstv }
    532       1.1  mlelstv 
    533       1.1  mlelstv static void
    534       1.1  mlelstv igmafb_pfitdisable_quirk(struct igmafb_softc *sc)
    535       1.1  mlelstv {
    536       1.1  mlelstv 	const struct igma_chip *cd = &sc->sc_chip;
    537       1.1  mlelstv 	const struct igma_chip_ops *co = cd->ops;
    538       1.1  mlelstv 	u_int32_t r;
    539       1.1  mlelstv 
    540       1.1  mlelstv 	/* disable i965 panel fitter */
    541       1.1  mlelstv 	r = co->read_reg(cd, PF_CTRL_I965);
    542       1.1  mlelstv 	co->write_reg(cd, PF_CTRL_I965, r & ~PF_ENABLE);
    543       1.1  mlelstv }
    544       1.1  mlelstv 
    545       1.1  mlelstv static void
    546       1.1  mlelstv igmafb_get_brightness_max(struct igmafb_softc *sc, int *valp)
    547       1.1  mlelstv {
    548       1.1  mlelstv 	const struct igma_chip *cd = &sc->sc_chip;
    549       1.1  mlelstv 	const struct igma_chip_ops *co = cd->ops;
    550       1.1  mlelstv 	u_int32_t r, f;
    551       1.1  mlelstv 
    552       1.1  mlelstv 	r = co->read_reg(cd, cd->backlight_cntrl);
    553       1.1  mlelstv 	f = BACKLIGHT_GET_FREQ(r);
    554       1.1  mlelstv 	if (f == 0) {
    555       1.1  mlelstv 		r = co->read_reg(cd, RAWCLK_FREQ);
    556       1.1  mlelstv 		f = r * 1000000 / (200 * 128);
    557       1.1  mlelstv 		if (f == 0 || f > 32767)
    558       1.1  mlelstv 			f = 125 * 100000 / (200 * 128);
    559       1.1  mlelstv 	}
    560       1.1  mlelstv 
    561       1.1  mlelstv 	*valp = f;
    562       1.1  mlelstv }
    563       1.1  mlelstv 
    564       1.1  mlelstv static void
    565       1.1  mlelstv igmafb_get_brightness(struct igmafb_softc *sc, int *valp)
    566       1.1  mlelstv {
    567       1.1  mlelstv 	const struct igma_chip *cd = &sc->sc_chip;
    568       1.1  mlelstv 	const struct igma_chip_ops *co = cd->ops;
    569       1.1  mlelstv 	u_int32_t r, v;
    570       1.1  mlelstv 
    571       1.1  mlelstv 	r = co->read_reg(cd, cd->backlight_cntrl);
    572       1.1  mlelstv 	v = BACKLIGHT_GET_CYCLE(r);
    573       1.1  mlelstv 	*valp = v;
    574       1.1  mlelstv }
    575       1.1  mlelstv 
    576       1.1  mlelstv static void
    577       1.1  mlelstv igmafb_set_brightness(struct igmafb_softc *sc, int val)
    578       1.1  mlelstv {
    579       1.1  mlelstv 	const struct igma_chip *cd = &sc->sc_chip;
    580       1.1  mlelstv 	const struct igma_chip_ops *co = cd->ops;
    581       1.1  mlelstv 	u_int32_t r, f, l;
    582       1.1  mlelstv 
    583       1.1  mlelstv 	r = co->read_reg(cd, cd->backlight_cntrl);
    584       1.1  mlelstv 	f = BACKLIGHT_GET_FREQ(r);
    585       1.1  mlelstv 	l = BACKLIGHT_GET_LEGACY(r);
    586       1.1  mlelstv 
    587       1.1  mlelstv 	co->write_reg(cd, cd->backlight_cntrl,
    588       1.1  mlelstv 		BACKLIGHT_VAL(f,l,val));
    589       1.1  mlelstv }
    590       1.1  mlelstv 
    591