Home | History | Annotate | Line # | Download | only in ic
i128.c revision 1.1.12.3
      1 /*	$NetBSD: i128.c,v 1.1.12.3 2007/10/23 20:07:26 ad Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2007 Michael Lorenz
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. Neither the name of The NetBSD Foundation nor the names of its
     16  *    contributors may be used to endorse or promote products derived
     17  *    from this software without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: i128.c,v 1.1.12.3 2007/10/23 20:07:26 ad Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/buf.h>
     38 #include <sys/device.h>
     39 #include <sys/conf.h>
     40 
     41 #include <sys/bus.h>
     42 #include <machine/autoconf.h>
     43 
     44 #include <dev/ic/i128reg.h>
     45 #include <dev/ic/i128var.h>
     46 
     47 void
     48 i128_init(bus_space_tag_t tag, bus_space_handle_t regh, int stride, int depth)
     49 {
     50 	/* initialize the i128's blitter */
     51 	switch (depth) {
     52 		case 8:
     53 			bus_space_write_4(tag, regh, BUF_CTRL, BC_PSIZ_8B);
     54 			break;
     55 		case 16:
     56 			bus_space_write_4(tag, regh, BUF_CTRL, BC_PSIZ_16B);
     57 			break;
     58 		case 32:
     59 			bus_space_write_4(tag, regh, BUF_CTRL, BC_PSIZ_32B);
     60 			break;
     61 		default:
     62 			aprint_error("i128: unsupported colour depth (%d)\n",
     63 			    depth);
     64 			return;
     65 	}
     66 
     67 	bus_space_write_4(tag, regh, DE_PGE, 0);
     68 	bus_space_write_4(tag, regh, DE_SORG, 0);
     69 	bus_space_write_4(tag, regh, DE_DORG, 0);
     70 	bus_space_write_4(tag, regh, DE_MSRC, 0);
     71 	bus_space_write_4(tag, regh, DE_WKEY, 0);
     72 	bus_space_write_4(tag, regh, DE_SPTCH, stride);
     73 	bus_space_write_4(tag, regh, DE_DPTCH, stride);
     74 	bus_space_write_4(tag, regh, RMSK, 0);
     75 	bus_space_write_4(tag, regh, XY4_ZM, ZOOM_NONE);
     76 	bus_space_write_4(tag, regh, LPAT, 0xffffffff);
     77 	bus_space_write_4(tag, regh, ACNTRL, 0);
     78 	bus_space_write_4(tag, regh, INTM, 3);
     79 	bus_space_write_4(tag, regh, CLPTL, 0x00000000);
     80 	bus_space_write_4(tag, regh, CLPBR, 0x1fff0fff);
     81 	bus_space_write_4(tag, regh, MASK, 0xffffffff);
     82 }
     83 
     84 void
     85 i128_bitblt(bus_space_tag_t tag, bus_space_handle_t regh, int xs, int ys,
     86     int xd, int yd, int wi, int he, int rop)
     87 {
     88 	int dir = 0;
     89 
     90 	if (xs < xd) {
     91 		dir |= DIR_RL;
     92 		xs += wi - 1;
     93 		xd += wi - 1;
     94 	}
     95 	if (ys < yd) {
     96 		dir |= DIR_BT;
     97 		ys += he - 1;
     98 		yd += he - 1;
     99 	}
    100 
    101 	I128_READY(tag, regh);
    102 	bus_space_write_4(tag, regh, CMD,
    103 	    (rop & 0xff) << 8 | CO_BITBLT);
    104 	bus_space_write_4(tag, regh, XY3_DIR, dir);
    105 	bus_space_write_4(tag, regh, XY2_WH, (wi << 16) | he);
    106 	bus_space_write_4(tag, regh, XY0_SRC, (xs << 16) | ys);
    107 	bus_space_write_4(tag, regh, XY1_DST, (xd << 16) | yd);
    108 	I128_DONE(tag, regh);
    109 }
    110 
    111 void
    112 i128_rectfill(bus_space_tag_t tag, bus_space_handle_t regh, int x, int y,
    113     int wi, int he, uint32_t color)
    114 {
    115 
    116 	I128_READY(tag, regh);
    117 	bus_space_write_4(tag, regh, CMD,
    118 	    CS_SOLID << 16 | (CR_COPY) << 8 | CO_BITBLT);
    119 	bus_space_write_4(tag, regh, FORE, color);
    120 	bus_space_write_4(tag, regh, XY3_DIR, 0);
    121 	bus_space_write_4(tag, regh, XY2_WH, (wi << 16) | he);
    122 	bus_space_write_4(tag, regh, XY0_SRC, 0);
    123 	bus_space_write_4(tag, regh, XY1_DST, (x << 16) | y);
    124 	I128_DONE(tag, regh);
    125 }
    126