1 /* $NetBSD: cgsix_sbus.c,v 1.29 2009/05/26 03:32:51 macallan Exp $ */
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
33 * color display (cgsix) driver; Sbus bus front-end.
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: cgsix_sbus.c,v 1.29 2009/05/26 03:32:51 macallan Exp $");
39 #include <sys/param.h>
40 #include <sys/systm.h>
42 #include <sys/device.h>
43 #include <sys/ioctl.h>
44 #include <sys/malloc.h>
51 #include <sys/syslog.h>
55 #include <machine/autoconf.h>
57 #include <dev/sbus/sbusvar.h>
59 #include <dev/sun/fbio.h>
60 #include <dev/sun/fbvar.h>
61 #include <dev/sun/btreg.h>
62 #include <dev/sun/btvar.h>
63 #include <dev/sun/cgsixreg.h>
64 #include <dev/sun/cgsixvar.h>
66 /* autoconfiguration driver */
67 static int cgsixmatch(device_t
, cfdata_t
, void *);
68 static void cgsixattach(device_t
, device_t
, void *);
70 CFATTACH_DECL_NEW(cgsix_sbus
, sizeof(struct cgsix_softc
),
71 cgsixmatch
, cgsixattach
, NULL
, NULL
);
77 cgsixmatch(device_t parent
, cfdata_t cf
, void *aux
)
79 struct sbus_attach_args
*sa
= aux
;
81 return (strcmp(cf
->cf_name
, sa
->sa_name
) == 0) ? 100 : 0;
89 cgsixattach(device_t parent
, device_t self
, void *aux
)
91 struct cgsix_softc
*sc
= device_private(self
);
92 struct sbus_attach_args
*sa
= aux
;
93 struct fbdevice
*fb
= &sc
->sc_fb
;
96 bus_space_handle_t bh
;
98 /* Remember cookies for cgsix_mmap() */
99 sc
->sc_bustag
= sa
->sa_bustag
;
100 sc
->sc_paddr
= sbus_bus_addr(sa
->sa_bustag
, sa
->sa_slot
, sa
->sa_offset
);
105 fb
->fb_device
= sc
->sc_dev
;
106 fb
->fb_type
.fb_type
= FBTYPE_SUNFAST_COLOR
;
107 fb
->fb_flags
= device_cfdata(sc
->sc_dev
)->cf_flags
& FB_USERMASK
;
108 fb
->fb_type
.fb_depth
= 8;
110 fb_setsize_obp(fb
, fb
->fb_type
.fb_depth
, 1152, 900, node
);
113 * Dunno what the PROM has mapped, though obviously it must have
114 * the video RAM mapped. Just map what we care about for ourselves
115 * (the FHC, THC, and Brooktree registers).
117 if (sbus_bus_map(sa
->sa_bustag
,
119 sa
->sa_offset
+ CGSIX_BT_OFFSET
,
121 BUS_SPACE_MAP_LINEAR
, &bh
) != 0) {
122 aprint_error_dev(self
, "cannot map brooktree registers\n");
125 sc
->sc_bt
= (struct bt_regs
*)bus_space_vaddr(sa
->sa_bustag
, bh
);
127 if (sbus_bus_map(sa
->sa_bustag
,
129 sa
->sa_offset
+ CGSIX_FHC_OFFSET
,
131 BUS_SPACE_MAP_LINEAR
, &bh
) != 0) {
132 aprint_error_dev(self
, "cannot map FHC registers\n");
135 sc
->sc_fhc
= (int *)bus_space_vaddr(sa
->sa_bustag
, bh
);
137 if (sbus_bus_map(sa
->sa_bustag
,
139 sa
->sa_offset
+ CGSIX_THC_OFFSET
,
141 BUS_SPACE_MAP_LINEAR
, &bh
) != 0) {
142 aprint_error_dev(self
, "cannot map THC registers\n");
145 sc
->sc_thc
= (struct cg6_thc
*)bus_space_vaddr(sa
->sa_bustag
, bh
);
147 if (sbus_bus_map(sa
->sa_bustag
,
149 sa
->sa_offset
+ CGSIX_TEC_OFFSET
,
151 BUS_SPACE_MAP_LINEAR
, &bh
) != 0) {
152 aprint_error_dev(self
, "cannot map TEC registers\n");
155 sc
->sc_tec
= (struct cg6_tec_xxx
*)bus_space_vaddr(sa
->sa_bustag
, bh
);
157 if (sbus_bus_map(sa
->sa_bustag
,
159 sa
->sa_offset
+ CGSIX_FBC_OFFSET
,
161 BUS_SPACE_MAP_LINEAR
, &bh
) != 0) {
162 aprint_error_dev(self
, "cannot map FBC registers\n");
165 sc
->sc_fbc
= (struct cg6_fbc
*)bus_space_vaddr(sa
->sa_bustag
, bh
);
167 name
= prom_getpropstring(node
, "model");
169 isconsole
= fb_is_console(node
);
172 * we need the address of the framebuffer, no matter if we're console or
175 sc
->sc_ramsize
= prom_getpropint(node
, "fbmapped", 1024 * 1024);
176 if (sbus_bus_map(sa
->sa_bustag
,
178 sa
->sa_offset
+ CGSIX_RAM_OFFSET
,
180 BUS_SPACE_MAP_LINEAR
| BUS_SPACE_MAP_LARGE
,
182 aprint_error_dev(self
, "cannot map pixels\n");
185 sc
->sc_fb
.fb_pixels
= (void *)bus_space_vaddr(sa
->sa_bustag
, bh
);
187 cg6attach(sc
, name
, isconsole
);