cgtwelve.c revision 1.1 1 1.1 macallan /* $NetBSD: cgtwelve.c,v 1.1 2010/03/24 00:33:06 macallan Exp $ */
2 1.1 macallan
3 1.1 macallan /*-
4 1.1 macallan * Copyright (c) 2010 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 *
16 1.1 macallan * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.1 macallan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.1 macallan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.1 macallan * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.1 macallan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1 macallan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1 macallan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1 macallan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1 macallan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.1 macallan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 macallan * POSSIBILITY OF SUCH DAMAGE.
27 1.1 macallan */
28 1.1 macallan
29 1.1 macallan /* a console driver for the Sun CG12 / Matrox SG3 graphics board */
30 1.1 macallan
31 1.1 macallan #include <sys/cdefs.h>
32 1.1 macallan __KERNEL_RCSID(0, "$NetBSD: cgtwelve.c,v 1.1 2010/03/24 00:33:06 macallan Exp $");
33 1.1 macallan
34 1.1 macallan #include <sys/param.h>
35 1.1 macallan #include <sys/systm.h>
36 1.1 macallan #include <sys/buf.h>
37 1.1 macallan #include <sys/device.h>
38 1.1 macallan #include <sys/ioctl.h>
39 1.1 macallan #include <sys/conf.h>
40 1.1 macallan
41 1.1 macallan #include <sys/bus.h>
42 1.1 macallan #include <machine/autoconf.h>
43 1.1 macallan
44 1.1 macallan #include <dev/sbus/sbusvar.h>
45 1.1 macallan #include <dev/sun/fbio.h>
46 1.1 macallan #include <dev/sun/fbvar.h>
47 1.1 macallan
48 1.1 macallan #include <dev/wscons/wsdisplayvar.h>
49 1.1 macallan #include <dev/wscons/wsconsio.h>
50 1.1 macallan #include <dev/wsfont/wsfont.h>
51 1.1 macallan #include <dev/rasops/rasops.h>
52 1.1 macallan
53 1.1 macallan #include <dev/wscons/wsdisplay_vconsvar.h>
54 1.1 macallan
55 1.1 macallan #include <dev/sbus/cgtwelvereg.h>
56 1.1 macallan
57 1.1 macallan #include "opt_wsemul.h"
58 1.1 macallan #include "opt_cgtwelve.h"
59 1.1 macallan
60 1.1 macallan
61 1.1 macallan struct cgtwelve_softc {
62 1.1 macallan device_t sc_dev;
63 1.1 macallan bus_space_tag_t sc_tag;
64 1.1 macallan void *sc_fbaddr;
65 1.1 macallan int sc_width;
66 1.1 macallan int sc_height;
67 1.1 macallan int sc_stride;
68 1.1 macallan int sc_fbsize;
69 1.1 macallan int sc_mode;
70 1.1 macallan struct vcons_data vd;
71 1.1 macallan };
72 1.1 macallan
73 1.1 macallan static int cgtwelve_match(device_t, cfdata_t, void *);
74 1.1 macallan static void cgtwelve_attach(device_t, device_t, void *);
75 1.1 macallan static int cgtwelve_ioctl(void *, void *, u_long, void *, int,
76 1.1 macallan struct lwp*);
77 1.1 macallan static paddr_t cgtwelve_mmap(void *, void *, off_t, int);
78 1.1 macallan static void cgtwelve_init_screen(void *, struct vcons_screen *, int,
79 1.1 macallan long *);
80 1.1 macallan
81 1.1 macallan CFATTACH_DECL_NEW(cgtwelve, sizeof(struct cgtwelve_softc),
82 1.1 macallan cgtwelve_match, cgtwelve_attach, NULL, NULL);
83 1.1 macallan
84 1.1 macallan struct wsscreen_descr cgtwelve_defscreendesc = {
85 1.1 macallan "default",
86 1.1 macallan 0, 0,
87 1.1 macallan NULL,
88 1.1 macallan 8, 16,
89 1.1 macallan 0,
90 1.1 macallan };
91 1.1 macallan
92 1.1 macallan static struct vcons_screen cgtwelve_console_screen;
93 1.1 macallan
94 1.1 macallan const struct wsscreen_descr *_cgtwelve_scrlist[] = {
95 1.1 macallan &cgtwelve_defscreendesc,
96 1.1 macallan /* XXX other formats, graphics screen? */
97 1.1 macallan };
98 1.1 macallan
99 1.1 macallan struct wsscreen_list cgtwelve_screenlist = {
100 1.1 macallan sizeof(_cgtwelve_scrlist) / sizeof(struct wsscreen_descr *),
101 1.1 macallan _cgtwelve_scrlist
102 1.1 macallan };
103 1.1 macallan
104 1.1 macallan struct wsdisplay_accessops cgtwelve_accessops = {
105 1.1 macallan cgtwelve_ioctl,
106 1.1 macallan cgtwelve_mmap,
107 1.1 macallan NULL, /* vcons_alloc_screen */
108 1.1 macallan NULL, /* vcons_free_screen */
109 1.1 macallan NULL, /* vcons_show_screen */
110 1.1 macallan NULL, /* load_font */
111 1.1 macallan NULL, /* polls */
112 1.1 macallan NULL, /* scroll */
113 1.1 macallan };
114 1.1 macallan
115 1.1 macallan static int
116 1.1 macallan cgtwelve_match(device_t parent, cfdata_t cf, void *aux)
117 1.1 macallan {
118 1.1 macallan struct sbus_attach_args *sa = aux;
119 1.1 macallan
120 1.1 macallan if (strcmp("cgtwelve", sa->sa_name) == 0)
121 1.1 macallan return 100;
122 1.1 macallan return 0;
123 1.1 macallan }
124 1.1 macallan
125 1.1 macallan /*
126 1.1 macallan * Attach a display. We need to notice if it is the console, too.
127 1.1 macallan */
128 1.1 macallan static void
129 1.1 macallan cgtwelve_attach(device_t parent, device_t self, void *args)
130 1.1 macallan {
131 1.1 macallan struct cgtwelve_softc *sc = device_private(self);
132 1.1 macallan struct sbus_attach_args *sa = args;
133 1.1 macallan struct wsemuldisplaydev_attach_args aa;
134 1.1 macallan struct rasops_info *ri;
135 1.1 macallan unsigned long defattr;
136 1.1 macallan bus_space_handle_t bh;
137 1.1 macallan int node = sa->sa_node;
138 1.1 macallan int isconsole;
139 1.1 macallan
140 1.1 macallan aprint_normal("\n");
141 1.1 macallan sc->sc_dev = self;
142 1.1 macallan sc->sc_tag = sa->sa_bustag;
143 1.1 macallan
144 1.1 macallan /* read geometry information from the device tree */
145 1.1 macallan sc->sc_width = prom_getpropint(sa->sa_node, "width", 1152);
146 1.1 macallan sc->sc_height = prom_getpropint(sa->sa_node, "height", 900);
147 1.1 macallan sc->sc_stride = (sc->sc_width + 7) >> 3;
148 1.1 macallan
149 1.1 macallan sc->sc_fbsize = sc->sc_height * sc->sc_stride;
150 1.1 macallan sc->sc_fbaddr = (void *)prom_getpropint(sa->sa_node, "address", 0);
151 1.1 macallan if (sc->sc_fbaddr == NULL) {
152 1.1 macallan if (sbus_bus_map(sa->sa_bustag,
153 1.1 macallan sa->sa_slot,
154 1.1 macallan sa->sa_offset + CG12_FB_MONO,
155 1.1 macallan sc->sc_fbsize,
156 1.1 macallan BUS_SPACE_MAP_LINEAR, &bh) != 0) {
157 1.1 macallan aprint_error_dev(self, "cannot map framebuffer\n");
158 1.1 macallan return;
159 1.1 macallan }
160 1.1 macallan sc->sc_fbaddr = bus_space_vaddr(sa->sa_bustag, bh);
161 1.1 macallan }
162 1.1 macallan
163 1.1 macallan aprint_normal_dev(self, "%d x %d\n", sc->sc_width, sc->sc_height);
164 1.1 macallan
165 1.1 macallan isconsole = fb_is_console(node);
166 1.1 macallan
167 1.1 macallan sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
168 1.1 macallan wsfont_init();
169 1.1 macallan
170 1.1 macallan vcons_init(&sc->vd, sc, &cgtwelve_defscreendesc, &cgtwelve_accessops);
171 1.1 macallan sc->vd.init_screen = cgtwelve_init_screen;
172 1.1 macallan
173 1.1 macallan vcons_init_screen(&sc->vd, &cgtwelve_console_screen, 1, &defattr);
174 1.1 macallan cgtwelve_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
175 1.1 macallan
176 1.1 macallan memset(sc->sc_fbaddr, 0, sc->sc_fbsize);
177 1.1 macallan
178 1.1 macallan ri = &cgtwelve_console_screen.scr_ri;
179 1.1 macallan
180 1.1 macallan cgtwelve_defscreendesc.nrows = ri->ri_rows;
181 1.1 macallan cgtwelve_defscreendesc.ncols = ri->ri_cols;
182 1.1 macallan cgtwelve_defscreendesc.textops = &ri->ri_ops;
183 1.1 macallan cgtwelve_defscreendesc.capabilities = ri->ri_caps;
184 1.1 macallan
185 1.1 macallan if(isconsole) {
186 1.1 macallan wsdisplay_cnattach(&cgtwelve_defscreendesc, ri, 0, 0, defattr);
187 1.1 macallan vcons_replay_msgbuf(&cgtwelve_console_screen);
188 1.1 macallan }
189 1.1 macallan
190 1.1 macallan aa.console = isconsole;
191 1.1 macallan aa.scrdata = &cgtwelve_screenlist;
192 1.1 macallan aa.accessops = &cgtwelve_accessops;
193 1.1 macallan aa.accesscookie = &sc->vd;
194 1.1 macallan
195 1.1 macallan config_found(self, &aa, wsemuldisplaydevprint);
196 1.1 macallan
197 1.1 macallan }
198 1.1 macallan
199 1.1 macallan
200 1.1 macallan static void
201 1.1 macallan cgtwelve_init_screen(void *cookie, struct vcons_screen *scr,
202 1.1 macallan int existing, long *defattr)
203 1.1 macallan {
204 1.1 macallan struct cgtwelve_softc *sc = cookie;
205 1.1 macallan struct rasops_info *ri = &scr->scr_ri;
206 1.1 macallan
207 1.1 macallan ri->ri_depth = 1;
208 1.1 macallan ri->ri_width = sc->sc_width;
209 1.1 macallan ri->ri_height = sc->sc_height;
210 1.1 macallan ri->ri_stride = sc->sc_stride;
211 1.1 macallan ri->ri_flg = RI_CENTER;
212 1.1 macallan
213 1.1 macallan ri->ri_bits = sc->sc_fbaddr;
214 1.1 macallan
215 1.1 macallan rasops_init(ri, ri->ri_height/8, ri->ri_width/8);
216 1.1 macallan ri->ri_caps = WSSCREEN_REVERSE;
217 1.1 macallan rasops_reconfig(ri, ri->ri_height / ri->ri_font->fontheight,
218 1.1 macallan ri->ri_width / ri->ri_font->fontwidth);
219 1.1 macallan }
220 1.1 macallan
221 1.1 macallan static int
222 1.1 macallan cgtwelve_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
223 1.1 macallan struct lwp *l)
224 1.1 macallan {
225 1.1 macallan
226 1.1 macallan switch (cmd) {
227 1.1 macallan case WSDISPLAYIO_GTYPE:
228 1.1 macallan *(u_int *)data = WSDISPLAY_TYPE_SUNCG12;
229 1.1 macallan return 0;
230 1.1 macallan }
231 1.1 macallan
232 1.1 macallan return EPASSTHROUGH;
233 1.1 macallan }
234 1.1 macallan
235 1.1 macallan static paddr_t
236 1.1 macallan cgtwelve_mmap(void *v, void *vs, off_t offset, int prot)
237 1.1 macallan {
238 1.1 macallan struct cgtwelve_softc *sc = v;
239 1.1 macallan
240 1.1 macallan /* regular fb mapping at 0 */
241 1.1 macallan if ((offset >= 0) && (offset < sc->sc_fbsize)) {
242 1.1 macallan #if 0
243 1.1 macallan return bus_space_mmap(sc->sc_tag, sc->sc_paddr,
244 1.1 macallan CG12_FB_MONO + offset, prot,
245 1.1 macallan BUS_SPACE_MAP_LINEAR);
246 1.1 macallan #endif
247 1.1 macallan }
248 1.1 macallan
249 1.1 macallan return -1;
250 1.1 macallan }
251