xref: /netbsd-src/sys/dev/sbus/cgsix_sbus.c (revision e5548b402ae4c44fb816de42c7bba9581ce23ef5)
1 /*	$NetBSD: cgsix_sbus.c,v 1.18 2005/12/11 12:23:44 christos Exp $ */
2 
3 /*-
4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Paul Kranenburg.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 /*
40  * color display (cgsix) driver; Sbus bus front-end.
41  */
42 
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: cgsix_sbus.c,v 1.18 2005/12/11 12:23:44 christos Exp $");
45 
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/buf.h>
49 #include <sys/device.h>
50 #include <sys/ioctl.h>
51 #include <sys/malloc.h>
52 #include <sys/mman.h>
53 #include <sys/tty.h>
54 #include <sys/conf.h>
55 
56 #ifdef DEBUG
57 #include <sys/proc.h>
58 #include <sys/syslog.h>
59 #endif
60 
61 #include <machine/bus.h>
62 #include <machine/autoconf.h>
63 
64 #include <dev/sbus/sbusvar.h>
65 
66 #include <dev/sun/fbio.h>
67 #include <dev/sun/fbvar.h>
68 #include <dev/sun/btreg.h>
69 #include <dev/sun/btvar.h>
70 #include <dev/sun/cgsixreg.h>
71 #include <dev/sun/cgsixvar.h>
72 
73 /* autoconfiguration driver */
74 static int	cgsixmatch(struct device *, struct cfdata *, void *);
75 static void	cgsixattach(struct device *, struct device *, void *);
76 
77 /* Allocate an `sbusdev' in addition to the cgsix softc */
78 struct cgsix_sbus_softc {
79 	struct cgsix_softc bss_softc;
80 	struct sbusdev bss_sd;
81 };
82 
83 CFATTACH_DECL(cgsix_sbus, sizeof(struct cgsix_sbus_softc),
84     cgsixmatch, cgsixattach, NULL, NULL);
85 
86 /*
87  * Match a cgsix.
88  */
89 int
90 cgsixmatch(parent, cf, aux)
91 	struct device *parent;
92 	struct cfdata *cf;
93 	void *aux;
94 {
95 	struct sbus_attach_args *sa = aux;
96 
97 	return (strcmp(cf->cf_name, sa->sa_name) == 0);
98 }
99 
100 
101 /*
102  * Attach a cgsix.
103  */
104 void
105 cgsixattach(parent, self, aux)
106 	struct device *parent, *self;
107 	void *aux;
108 {
109 	struct cgsix_softc *sc = (struct cgsix_softc *)self;
110 	struct sbusdev *sd = &((struct cgsix_sbus_softc *)self)->bss_sd;
111 	struct sbus_attach_args *sa = aux;
112 	struct fbdevice *fb = &sc->sc_fb;
113 	int node, isconsole;
114 	const char *name;
115 	bus_space_handle_t bh;
116 
117 	/* Remember cookies for cgsix_mmap() */
118 	sc->sc_bustag = sa->sa_bustag;
119 	sc->sc_paddr = sbus_bus_addr(sa->sa_bustag, sa->sa_slot, sa->sa_offset);
120 
121 	node = sa->sa_node;
122 
123 	fb->fb_device = &sc->sc_dev;
124 	fb->fb_type.fb_type = FBTYPE_SUNFAST_COLOR;
125 	fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags & FB_USERMASK;
126 	fb->fb_type.fb_depth = 8;
127 
128 	fb_setsize_obp(fb, fb->fb_type.fb_depth, 1152, 900, node);
129 
130 	/*
131 	 * Dunno what the PROM has mapped, though obviously it must have
132 	 * the video RAM mapped.  Just map what we care about for ourselves
133 	 * (the FHC, THC, and Brooktree registers).
134 	 */
135 	if (sbus_bus_map(sa->sa_bustag,
136 			 sa->sa_slot,
137 			 sa->sa_offset + CGSIX_BT_OFFSET,
138 			 sizeof(*sc->sc_bt),
139 			 BUS_SPACE_MAP_LINEAR, &bh) != 0) {
140 		printf("%s: cannot map brooktree registers\n", self->dv_xname);
141 		return;
142 	}
143 	sc->sc_bt = (struct bt_regs *)bus_space_vaddr(sa->sa_bustag, bh);
144 
145 	if (sbus_bus_map(sa->sa_bustag,
146 			 sa->sa_slot,
147 			 sa->sa_offset + CGSIX_FHC_OFFSET,
148 			 sizeof(*sc->sc_fhc),
149 			 BUS_SPACE_MAP_LINEAR, &bh) != 0) {
150 		printf("%s: cannot map FHC registers\n", self->dv_xname);
151 		return;
152 	}
153 	sc->sc_fhc = (int *)bus_space_vaddr(sa->sa_bustag, bh);
154 
155 	if (sbus_bus_map(sa->sa_bustag,
156 			 sa->sa_slot,
157 			 sa->sa_offset + CGSIX_THC_OFFSET,
158 			 sizeof(*sc->sc_thc),
159 			 BUS_SPACE_MAP_LINEAR, &bh) != 0) {
160 		printf("%s: cannot map THC registers\n", self->dv_xname);
161 		return;
162 	}
163 	sc->sc_thc = (struct cg6_thc *)bus_space_vaddr(sa->sa_bustag, bh);
164 
165 	if (sbus_bus_map(sa->sa_bustag,
166 			 sa->sa_slot,
167 			 sa->sa_offset + CGSIX_TEC_OFFSET,
168 			 sizeof(*sc->sc_tec),
169 			 BUS_SPACE_MAP_LINEAR, &bh) != 0) {
170 		printf("%s: cannot map TEC registers\n", self->dv_xname);
171 		return;
172 	}
173 	sc->sc_tec = (struct cg6_tec_xxx *)bus_space_vaddr(sa->sa_bustag, bh);
174 
175 	if (sbus_bus_map(sa->sa_bustag,
176 			 sa->sa_slot,
177 			 sa->sa_offset + CGSIX_FBC_OFFSET,
178 			 sizeof(*sc->sc_fbc),
179 			 BUS_SPACE_MAP_LINEAR, &bh) != 0) {
180 		printf("%s: cannot map FBC registers\n", self->dv_xname);
181 		return;
182 	}
183 	sc->sc_fbc = (struct cg6_fbc *)bus_space_vaddr(sa->sa_bustag, bh);
184 
185 	sbus_establish(sd, &sc->sc_dev);
186 	name = prom_getpropstring(node, "model");
187 
188 	isconsole = fb_is_console(node);
189 
190 	/* we need the address of the framebuffer, no matter if we're console or not. */
191 	sc->sc_ramsize = prom_getpropint(node, "fbmapped", 1024 * 1024);
192 	if (sbus_bus_map(sa->sa_bustag,
193 			sa->sa_slot,
194 			sa->sa_offset + CGSIX_RAM_OFFSET,
195 			sc->sc_ramsize,
196 			BUS_SPACE_MAP_LINEAR, &bh) != 0) {
197 		printf("%s: cannot map pixels\n", self->dv_xname);
198 		return;
199 	}
200 	sc->sc_fb.fb_pixels = (caddr_t)bus_space_vaddr(sa->sa_bustag, bh);
201 
202 	cg6attach(sc, name, isconsole);
203 }
204