Home | History | Annotate | Line # | Download | only in tx
tx3912video.c revision 1.1
      1  1.1  uch /*	$NetBSD: tx3912video.c,v 1.1 1999/11/20 19:56:31 uch Exp $ */
      2  1.1  uch 
      3  1.1  uch /*
      4  1.1  uch  * Copyright (c) 1999, by UCHIYAMA Yasushi
      5  1.1  uch  * All rights reserved.
      6  1.1  uch  *
      7  1.1  uch  * Redistribution and use in source and binary forms, with or without
      8  1.1  uch  * modification, are permitted provided that the following conditions
      9  1.1  uch  * are met:
     10  1.1  uch  * 1. Redistributions of source code must retain the above copyright
     11  1.1  uch  *    notice, this list of conditions and the following disclaimer.
     12  1.1  uch  * 2. The name of the developer may NOT be used to endorse or promote products
     13  1.1  uch  *    derived from this software without specific prior written permission.
     14  1.1  uch  *
     15  1.1  uch  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     16  1.1  uch  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17  1.1  uch  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18  1.1  uch  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19  1.1  uch  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20  1.1  uch  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     21  1.1  uch  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  1.1  uch  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23  1.1  uch  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  1.1  uch  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  1.1  uch  * SUCH DAMAGE.
     26  1.1  uch  *
     27  1.1  uch  */
     28  1.1  uch #include "opt_tx39_debug.h"
     29  1.1  uch 
     30  1.1  uch #include <sys/param.h>
     31  1.1  uch #include <sys/systm.h>
     32  1.1  uch #include <sys/device.h>
     33  1.1  uch #include <sys/extent.h>
     34  1.1  uch 
     35  1.1  uch #include <machine/bus.h>
     36  1.1  uch 
     37  1.1  uch #include <hpcmips/tx/tx39var.h>
     38  1.1  uch #include <hpcmips/tx/tx3912videovar.h>
     39  1.1  uch #include <hpcmips/tx/tx3912videoreg.h>
     40  1.1  uch 
     41  1.1  uch void tx3912video_framebuffer_init __P((tx_chipset_tag_t, u_int32_t, u_int32_t));
     42  1.1  uch int  tx3912video_framebuffer_alloc __P((tx_chipset_tag_t, u_int32_t, int, int, int, u_int32_t*, u_int32_t*));
     43  1.1  uch void tx3912video_reset __P((tx_chipset_tag_t));
     44  1.1  uch void tx3912video_resolution_init __P((tx_chipset_tag_t, int, int));
     45  1.1  uch int  tx3912video_fbdepth __P((tx_chipset_tag_t, int));
     46  1.1  uch 
     47  1.1  uch static u_int32_t framebuffer, framebuffersize;
     48  1.1  uch 
     49  1.1  uch int	tx3912video_match __P((struct device*, struct cfdata*, void*));
     50  1.1  uch void	tx3912video_attach __P((struct device*, struct device*, void*));
     51  1.1  uch int	tx3912video_print __P((void*, const char*));
     52  1.1  uch 
     53  1.1  uch struct tx3912video_softc {
     54  1.1  uch 	struct device sc_dev;
     55  1.1  uch 	u_int32_t sc_fbaddr;
     56  1.1  uch 	u_int32_t sc_fbsize;
     57  1.1  uch };
     58  1.1  uch 
     59  1.1  uch struct fb_attach_args {
     60  1.1  uch 	const char *fba_name;
     61  1.1  uch };
     62  1.1  uch 
     63  1.1  uch struct cfattach tx3912video_ca = {
     64  1.1  uch 	sizeof(struct tx3912video_softc), tx3912video_match, tx3912video_attach
     65  1.1  uch };
     66  1.1  uch 
     67  1.1  uch int
     68  1.1  uch tx3912video_match(parent, cf, aux)
     69  1.1  uch 	struct device *parent;
     70  1.1  uch 	struct cfdata *cf;
     71  1.1  uch 	void *aux;
     72  1.1  uch {
     73  1.1  uch 	return 1;
     74  1.1  uch }
     75  1.1  uch 
     76  1.1  uch void
     77  1.1  uch tx3912video_attach(parent, self, aux)
     78  1.1  uch 	struct device *parent;
     79  1.1  uch 	struct device *self;
     80  1.1  uch 	void *aux;
     81  1.1  uch {
     82  1.1  uch 	struct txsim_attach_args *ta = aux;
     83  1.1  uch 	struct tx3912video_softc *sc = (void*)self;
     84  1.1  uch 	tx_chipset_tag_t tc = ta->ta_tc;
     85  1.1  uch 	struct fb_attach_args fba;
     86  1.1  uch 
     87  1.1  uch 	printf("\n");
     88  1.1  uch 	sc->sc_fbaddr = framebuffer;
     89  1.1  uch 	sc->sc_fbsize = framebuffersize;
     90  1.1  uch 	printf("TMPR3912 video module [");
     91  1.1  uch 	tx3912video_fbdepth(tc, 1);
     92  1.1  uch 	printf("] frame buffer: 0x%08x-0x%08x\n", sc->sc_fbaddr,
     93  1.1  uch 	       sc->sc_fbaddr + sc->sc_fbsize);
     94  1.1  uch 
     95  1.1  uch 	/* Attach frame buffer device */
     96  1.1  uch 	fba.fba_name = "fb";
     97  1.1  uch 	config_found(self, &fba, tx3912video_print);
     98  1.1  uch }
     99  1.1  uch 
    100  1.1  uch int
    101  1.1  uch tx3912video_print(aux, pnp)
    102  1.1  uch 	void *aux;
    103  1.1  uch 	const char *pnp;
    104  1.1  uch {
    105  1.1  uch 	return pnp ? QUIET : UNCONF;
    106  1.1  uch }
    107  1.1  uch 
    108  1.1  uch int
    109  1.1  uch tx3912video_init(tc, fb_start, fb_width, fb_height, fb_addr, fb_size,
    110  1.1  uch 		fb_line_bytes)
    111  1.1  uch 	tx_chipset_tag_t tc;
    112  1.1  uch 	u_int32_t fb_start; /* Physical address */
    113  1.1  uch 	int fb_width, fb_height;
    114  1.1  uch 	u_int32_t *fb_addr, *fb_size;
    115  1.1  uch 	int *fb_line_bytes;
    116  1.1  uch {
    117  1.1  uch  	u_int32_t addr, size;
    118  1.1  uch 	int fb_depth;
    119  1.1  uch 
    120  1.1  uch 	/* Inquire bit depth */
    121  1.1  uch 	fb_depth = tx3912video_fbdepth(tc, 0);
    122  1.1  uch 
    123  1.1  uch 	/* Allocate framebuffer area */
    124  1.1  uch 	if (tx3912video_framebuffer_alloc(tc, fb_start, fb_width, fb_height,
    125  1.1  uch 					 fb_depth, &addr, &size)) {
    126  1.1  uch 		return 1;
    127  1.1  uch 	}
    128  1.1  uch #if notyet
    129  1.1  uch 	tx3912video_resolution_init(tc, fb_width, fb_height);
    130  1.1  uch #else
    131  1.1  uch 	/* Use Windows CE setting. */
    132  1.1  uch #endif
    133  1.1  uch 	/* Set DMA transfer address to VID module */
    134  1.1  uch 	tx3912video_framebuffer_init(tc, addr, size);
    135  1.1  uch 
    136  1.1  uch 	/* Syncronize framebuffer addr to frame signal */
    137  1.1  uch 	tx3912video_reset(tc);
    138  1.1  uch 
    139  1.1  uch 	*fb_line_bytes = (fb_width * fb_depth) / 8;
    140  1.1  uch 	*fb_addr = addr; /* Phsical address */
    141  1.1  uch 	*fb_size = size;
    142  1.1  uch 
    143  1.1  uch 	return 0;
    144  1.1  uch }
    145  1.1  uch 
    146  1.1  uch  int
    147  1.1  uch tx3912video_framebuffer_alloc(tc, start, h, v, depth, fb_addr, fb_size)
    148  1.1  uch 	tx_chipset_tag_t tc;
    149  1.1  uch 	u_int32_t start;
    150  1.1  uch 	int h, v, depth;
    151  1.1  uch 	u_int32_t *fb_addr, *fb_size;
    152  1.1  uch {
    153  1.1  uch 	struct extent_fixed ex_fixed[2];
    154  1.1  uch 	struct extent *ex;
    155  1.1  uch 	u_long addr, size;
    156  1.1  uch 	int err;
    157  1.1  uch 
    158  1.1  uch 	/* Calcurate frame buffer size */
    159  1.1  uch 	size = (h * v * depth) / 8;
    160  1.1  uch 
    161  1.1  uch 	/* Allocate V-RAM area */
    162  1.1  uch 	if (!(ex = extent_create("Frame buffer address", start,
    163  1.1  uch 				 start + TX3912_FRAMEBUFFER_MAX,
    164  1.1  uch 				 0, (caddr_t)ex_fixed, sizeof ex_fixed,
    165  1.1  uch  				 EX_NOWAIT))) {
    166  1.1  uch 		return 1;
    167  1.1  uch 	}
    168  1.1  uch 	if((err = extent_alloc_subregion(ex, start, start + size, size,
    169  1.1  uch 					 TX3912_FRAMEBUFFER_ALIGNMENT,
    170  1.1  uch 					 TX3912_FRAMEBUFFER_BOUNDARY,
    171  1.1  uch 					 EX_FAST|EX_NOWAIT, &addr))) {
    172  1.1  uch 		return 1;
    173  1.1  uch 	}
    174  1.1  uch 	framebuffer = addr;
    175  1.1  uch 	framebuffersize = size;
    176  1.1  uch 	*fb_addr = addr;
    177  1.1  uch 	*fb_size = size;
    178  1.1  uch 
    179  1.1  uch 	return 0;
    180  1.1  uch }
    181  1.1  uch 
    182  1.1  uch  void
    183  1.1  uch tx3912video_framebuffer_init(tc, fb_addr, fb_size)
    184  1.1  uch 	tx_chipset_tag_t tc;
    185  1.1  uch 	u_int32_t fb_addr, fb_size;
    186  1.1  uch {
    187  1.1  uch 	u_int32_t reg, vaddr, bank, base;
    188  1.1  uch 
    189  1.1  uch 	/*  XXX currently I don't set DFVAL, so force DF signal toggled on
    190  1.1  uch          *  XXX each frame. */
    191  1.1  uch 	reg = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
    192  1.1  uch 	reg &= ~TX3912_VIDEOCTRL1_DFMODE;
    193  1.1  uch 	tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, reg);
    194  1.1  uch 
    195  1.1  uch 	/* Set DMA transfer start and end address */
    196  1.1  uch 
    197  1.1  uch 	bank = TX3912_VIDEOCTRL3_VIDBANK(fb_addr);
    198  1.1  uch 	base = TX3912_VIDEOCTRL3_VIDBASEHI(fb_addr);
    199  1.1  uch 	reg = TX3912_VIDEOCTRL3_VIDBANK_SET(0, bank);
    200  1.1  uch 	/* Upper address counter */
    201  1.1  uch 	reg = TX3912_VIDEOCTRL3_VIDBASEHI_SET(reg, base);
    202  1.1  uch 	tx_conf_write(tc, TX3912_VIDEOCTRL3_REG, reg);
    203  1.1  uch 
    204  1.1  uch 	/* Lower address counter  */
    205  1.1  uch 	base = TX3912_VIDEOCTRL4_VIDBASELO(fb_addr + fb_size);
    206  1.1  uch 	reg = TX3912_VIDEOCTRL4_VIDBASELO_SET(0, base);
    207  1.1  uch 
    208  1.1  uch 	/* Set DF-signal rate */
    209  1.1  uch 	reg = TX3912_VIDEOCTRL4_DFVAL_SET(reg, 0); /* XXX not yet*/
    210  1.1  uch 
    211  1.1  uch 	/* Set VIDDONE signal delay after FRAME signal */
    212  1.1  uch 	/* XXX not yet*/
    213  1.1  uch 	tx_conf_write(tc, TX3912_VIDEOCTRL4_REG, reg);
    214  1.1  uch 
    215  1.1  uch 	/* Clear frame buffer */
    216  1.1  uch 	vaddr = MIPS_PHYS_TO_KSEG1(fb_addr);
    217  1.1  uch 	bzero((void*)vaddr, fb_size);
    218  1.1  uch }
    219  1.1  uch 
    220  1.1  uch  void
    221  1.1  uch tx3912video_resolution_init(tc, h, v)
    222  1.1  uch 	tx_chipset_tag_t tc;
    223  1.1  uch 	int h;
    224  1.1  uch 	int v;
    225  1.1  uch {
    226  1.1  uch 	u_int32_t reg, val;
    227  1.1  uch 	int split, bit8, horzval, lineval;
    228  1.1  uch 
    229  1.1  uch 	reg = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
    230  1.1  uch 	split = reg & TX3912_VIDEOCTRL1_DISPSPLIT;
    231  1.1  uch 	bit8  = (TX3912_VIDEOCTRL1_BITSEL(reg) ==
    232  1.1  uch 		 TX3912_VIDEOCTRL1_BITSEL_8BITCOLOR);
    233  1.1  uch 	val = TX3912_VIDEOCTRL1_BITSEL(reg);
    234  1.1  uch 
    235  1.1  uch 	if ((val == TX3912_VIDEOCTRL1_BITSEL_8BITCOLOR) &&
    236  1.1  uch 	    !split) {
    237  1.1  uch 		horzval = (h / 8) * 3 - 1; /* (LCD horizontal pixels / 8bit) * RGB - 1 */
    238  1.1  uch 	} else {
    239  1.1  uch 		horzval = h / 4 - 1;
    240  1.1  uch 	}
    241  1.1  uch 	lineval = (split ? v / 2 : v) - 1;
    242  1.1  uch 
    243  1.1  uch 	/* Video rate */
    244  1.1  uch 	/* XXX probably This value should be determined from DFINT and LCDINT */
    245  1.1  uch 	reg = TX3912_VIDEOCTRL2_VIDRATE_SET(0, horzval + 1);
    246  1.1  uch 	/* Horizontal size of LCD */
    247  1.1  uch 	reg = TX3912_VIDEOCTRL2_HORZVAL_SET(reg, horzval);
    248  1.1  uch 	/* # of lines for the LCD */
    249  1.1  uch 	reg = TX3912_VIDEOCTRL2_LINEVAL_SET(reg, lineval);
    250  1.1  uch 
    251  1.1  uch 	tx_conf_write(tc, TX3912_VIDEOCTRL2_REG, reg);
    252  1.1  uch }
    253  1.1  uch 
    254  1.1  uch  int
    255  1.1  uch tx3912video_fbdepth(tc, verbose)
    256  1.1  uch 	tx_chipset_tag_t tc;
    257  1.1  uch 	int verbose;
    258  1.1  uch {
    259  1.1  uch 	u_int32_t reg, val;
    260  1.1  uch 
    261  1.1  uch 	reg = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
    262  1.1  uch 	val = TX3912_VIDEOCTRL1_BITSEL(reg);
    263  1.1  uch 	switch (val) {
    264  1.1  uch 	case TX3912_VIDEOCTRL1_BITSEL_8BITCOLOR:
    265  1.1  uch 		if (verbose)
    266  1.1  uch 			printf("8bit color");
    267  1.1  uch 		return 8;
    268  1.1  uch 	case TX3912_VIDEOCTRL1_BITSEL_4BITGREYSCALE:
    269  1.1  uch 		if (verbose)
    270  1.1  uch 			printf("4bit greyscale");
    271  1.1  uch 		return 4;
    272  1.1  uch 	case TX3912_VIDEOCTRL1_BITSEL_2BITGREYSCALE:
    273  1.1  uch 		if (verbose)
    274  1.1  uch 			printf("2bit greyscale");
    275  1.1  uch 		return 2;
    276  1.1  uch 	case TX3912_VIDEOCTRL1_BITSEL_MONOCHROME:
    277  1.1  uch 		if (verbose)
    278  1.1  uch 			printf("monochrome");
    279  1.1  uch 		return 1;
    280  1.1  uch 	}
    281  1.1  uch 	return 0;
    282  1.1  uch }
    283  1.1  uch 
    284  1.1  uch void
    285  1.1  uch tx3912video_reset(tc)
    286  1.1  uch 	tx_chipset_tag_t tc;
    287  1.1  uch {
    288  1.1  uch 	u_int32_t reg;
    289  1.1  uch 
    290  1.1  uch 	reg = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
    291  1.1  uch 	/* Disable video logic at end of this frame */
    292  1.1  uch 	reg |= TX3912_VIDEOCTRL1_ENFREEZEFRAME;
    293  1.1  uch 	tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, reg);
    294  1.1  uch 	/* Wait for end of frame */
    295  1.1  uch 	delay(300 * 1000);
    296  1.1  uch 	/* Make sure to disable video logic */
    297  1.1  uch 	reg &= ~TX3912_VIDEOCTRL1_ENVID;
    298  1.1  uch 	tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, reg);
    299  1.1  uch 	delay(1000);
    300  1.1  uch 	/* Enable video logic again */
    301  1.1  uch 	reg &= ~TX3912_VIDEOCTRL1_ENFREEZEFRAME;
    302  1.1  uch 	reg |= TX3912_VIDEOCTRL1_ENVID;
    303  1.1  uch 	tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, reg);
    304  1.1  uch 	delay(1000);
    305  1.1  uch }
    306  1.1  uch 
    307  1.1  uch 
    308