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