igsfb_ofbus.c revision 1.1.4.5 1 1.1.4.5 yamt /* $NetBSD: igsfb_ofbus.c,v 1.1.4.5 2007/11/15 11:43:26 yamt Exp $ */
2 1.1.4.2 yamt
3 1.1.4.2 yamt /*
4 1.1.4.2 yamt * Copyright (c) 2006 Michael Lorenz
5 1.1.4.2 yamt * All rights reserved.
6 1.1.4.2 yamt *
7 1.1.4.2 yamt * Redistribution and use in source and binary forms, with or without
8 1.1.4.2 yamt * modification, are permitted provided that the following conditions
9 1.1.4.2 yamt * are met:
10 1.1.4.2 yamt * 1. Redistributions of source code must retain the above copyright
11 1.1.4.2 yamt * notice, this list of conditions and the following disclaimer.
12 1.1.4.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.4.2 yamt * notice, this list of conditions and the following disclaimer in the
14 1.1.4.2 yamt * documentation and/or other materials provided with the distribution.
15 1.1.4.2 yamt * 3. The name of the author may not be used to endorse or promote products
16 1.1.4.2 yamt * derived from this software without specific prior written permission
17 1.1.4.2 yamt *
18 1.1.4.2 yamt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1.4.2 yamt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1.4.2 yamt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1.4.2 yamt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.1.4.2 yamt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 1.1.4.2 yamt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 1.1.4.2 yamt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 1.1.4.2 yamt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 1.1.4.2 yamt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 1.1.4.2 yamt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.1.4.2 yamt */
29 1.1.4.2 yamt
30 1.1.4.2 yamt /*
31 1.1.4.2 yamt * Integraphics Systems IGA 168x and CyberPro series.
32 1.1.4.2 yamt * ofbus attachment for Valeriy E. Ushakov's igsfb driver
33 1.1.4.2 yamt */
34 1.1.4.2 yamt
35 1.1.4.2 yamt #include <sys/cdefs.h>
36 1.1.4.5 yamt __KERNEL_RCSID(0, "$NetBSD: igsfb_ofbus.c,v 1.1.4.5 2007/11/15 11:43:26 yamt Exp $");
37 1.1.4.2 yamt
38 1.1.4.2 yamt #include <sys/param.h>
39 1.1.4.2 yamt #include <sys/systm.h>
40 1.1.4.2 yamt #include <sys/kernel.h>
41 1.1.4.2 yamt #include <sys/device.h>
42 1.1.4.2 yamt #include <sys/malloc.h>
43 1.1.4.2 yamt #include <sys/buf.h>
44 1.1.4.2 yamt
45 1.1.4.2 yamt #include <machine/bus.h>
46 1.1.4.2 yamt #include <machine/intr.h>
47 1.1.4.2 yamt #include <machine/ofw.h>
48 1.1.4.2 yamt
49 1.1.4.2 yamt #include <dev/isa/isavar.h>
50 1.1.4.2 yamt
51 1.1.4.2 yamt #include <dev/wscons/wsdisplayvar.h>
52 1.1.4.2 yamt #include <dev/wscons/wsconsio.h>
53 1.1.4.2 yamt #include <dev/rasops/rasops.h>
54 1.1.4.2 yamt #include <dev/wscons/wsdisplay_vconsvar.h>
55 1.1.4.2 yamt #include <dev/ofw/openfirm.h>
56 1.1.4.2 yamt
57 1.1.4.2 yamt #include <dev/ic/igsfbreg.h>
58 1.1.4.2 yamt #include <dev/ic/igsfbvar.h>
59 1.1.4.4 yamt #include <shark/ofw/igsfb_ofbusvar.h>
60 1.1.4.2 yamt
61 1.1.4.2 yamt static int igsfb_ofbus_is_console(int);
62 1.1.4.2 yamt
63 1.1.4.2 yamt static int igsfb_ofbus_console = 0;
64 1.1.4.2 yamt static int igsfb_ofbus_phandle = 0;
65 1.1.4.2 yamt
66 1.1.4.2 yamt
67 1.1.4.2 yamt
68 1.1.4.2 yamt static int igsfb_ofbus_match(struct device *, struct cfdata *, void *);
69 1.1.4.2 yamt static void igsfb_ofbus_attach(struct device *, struct device *, void *);
70 1.1.4.2 yamt static int igsfb_setup_dc(struct igsfb_devconfig *);
71 1.1.4.2 yamt
72 1.1.4.2 yamt CFATTACH_DECL(igsfb_ofbus, sizeof(struct igsfb_softc),
73 1.1.4.2 yamt igsfb_ofbus_match, igsfb_ofbus_attach, NULL, NULL);
74 1.1.4.2 yamt
75 1.1.4.4 yamt static const char const *compat_strings[] = { "igs,cyperpro2010", NULL };
76 1.1.4.2 yamt
77 1.1.4.2 yamt vaddr_t igsfb_mem_vaddr = 0, igsfb_mmio_vaddr = 0;
78 1.1.4.2 yamt paddr_t igsfb_mem_paddr;
79 1.1.4.2 yamt struct bus_space igsfb_memt, igsfb_iot;
80 1.1.4.2 yamt
81 1.1.4.5 yamt #if (NIGSFB_OFBUS > 0) || (NVGA_OFBUS > 0)
82 1.1.4.3 yamt extern int console_ihandle;
83 1.1.4.4 yamt #endif
84 1.1.4.3 yamt
85 1.1.4.2 yamt int
86 1.1.4.2 yamt igsfb_ofbus_cnattach(bus_space_tag_t iot, bus_space_tag_t memt)
87 1.1.4.2 yamt {
88 1.1.4.2 yamt struct igsfb_devconfig *dc;
89 1.1.4.2 yamt int ret;
90 1.1.4.2 yamt int chosen_phandle, igs_node;
91 1.1.4.2 yamt int stdout_ihandle, stdout_phandle;
92 1.1.4.2 yamt uint32_t regs[16];
93 1.1.4.2 yamt
94 1.1.4.2 yamt stdout_phandle = 0;
95 1.1.4.2 yamt
96 1.1.4.2 yamt /* first find out if there's a CyberPro at all in this machine */
97 1.1.4.4 yamt igs_node = OF_finddevice("/vlbus/display");
98 1.1.4.4 yamt if (igs_node == -1)
99 1.1.4.2 yamt return ENXIO;
100 1.1.4.2 yamt if (of_compatible(igs_node, compat_strings) < 0)
101 1.1.4.2 yamt return ENXIO;
102 1.1.4.4 yamt
103 1.1.4.2 yamt /*
104 1.1.4.2 yamt * now we know there's a CyberPro in this machine so map it into
105 1.1.4.2 yamt * kernel space, even if it's not the console
106 1.1.4.2 yamt */
107 1.1.4.2 yamt if (OF_getprop(igs_node, "reg", regs, sizeof(regs)) <= 0)
108 1.1.4.2 yamt return ENXIO;
109 1.1.4.2 yamt
110 1.1.4.2 yamt igsfb_mem_paddr = be32toh(regs[13]);
111 1.1.4.2 yamt /* 4MB VRAM */
112 1.1.4.2 yamt igsfb_mem_vaddr = ofw_map(igsfb_mem_paddr, 0x00400000, 0);
113 1.1.4.2 yamt /* MMIO registers */
114 1.1.4.2 yamt igsfb_mmio_vaddr = ofw_map(igsfb_mem_paddr + IGS_MEM_MMIO_SELECT,
115 1.1.4.2 yamt 0x00100000, 0);
116 1.1.4.2 yamt
117 1.1.4.2 yamt memcpy(&igsfb_memt, memt, sizeof(struct bus_space));
118 1.1.4.2 yamt igsfb_memt.bs_cookie = (void *)igsfb_mem_vaddr;
119 1.1.4.2 yamt memcpy(&igsfb_iot, memt, sizeof(struct bus_space));
120 1.1.4.2 yamt igsfb_iot.bs_cookie = (void *)igsfb_mmio_vaddr;
121 1.1.4.2 yamt
122 1.1.4.2 yamt /*
123 1.1.4.2 yamt * check if the firmware output device is indeed the CyberPro
124 1.1.4.2 yamt */
125 1.1.4.2 yamt if ((chosen_phandle = OF_finddevice("/chosen")) == -1 ||
126 1.1.4.2 yamt OF_getprop(chosen_phandle, "stdout", &stdout_ihandle,
127 1.1.4.2 yamt sizeof(stdout_ihandle)) != sizeof(stdout_ihandle)) {
128 1.1.4.2 yamt return ENXIO;
129 1.1.4.2 yamt }
130 1.1.4.4 yamt stdout_ihandle = of_decode_int((void *)&stdout_ihandle);
131 1.1.4.2 yamt stdout_phandle = OF_instance_to_package(stdout_ihandle);
132 1.1.4.2 yamt
133 1.1.4.2 yamt if (stdout_phandle != igs_node)
134 1.1.4.2 yamt return ENXIO;
135 1.1.4.2 yamt
136 1.1.4.2 yamt /* ok, now setup and attach the console */
137 1.1.4.2 yamt dc = &igsfb_console_dc;
138 1.1.4.2 yamt ret = igsfb_setup_dc(dc);
139 1.1.4.2 yamt if (ret)
140 1.1.4.2 yamt return ret;
141 1.1.4.2 yamt
142 1.1.4.2 yamt ret = igsfb_cnattach_subr(dc);
143 1.1.4.2 yamt if (ret)
144 1.1.4.2 yamt return ret;
145 1.1.4.2 yamt
146 1.1.4.2 yamt igsfb_ofbus_console = 1;
147 1.1.4.2 yamt igsfb_ofbus_phandle = stdout_phandle;
148 1.1.4.5 yamt #if (NIGSFB_OFBUS > 0) || (NVGA_OFBUS > 0)
149 1.1.4.3 yamt console_ihandle = stdout_ihandle;
150 1.1.4.4 yamt #endif
151 1.1.4.2 yamt return 0;
152 1.1.4.2 yamt }
153 1.1.4.2 yamt
154 1.1.4.2 yamt static int
155 1.1.4.2 yamt igsfb_setup_dc(struct igsfb_devconfig *dc)
156 1.1.4.2 yamt {
157 1.1.4.2 yamt int ret;
158 1.1.4.2 yamt
159 1.1.4.4 yamt dc->dc_id = 0x2010;
160 1.1.4.2 yamt dc->dc_memt = &igsfb_memt;
161 1.1.4.2 yamt dc->dc_memaddr = 0;
162 1.1.4.2 yamt dc->dc_memsz= 0x00400000;
163 1.1.4.4 yamt dc->dc_memflags = 0;
164 1.1.4.2 yamt
165 1.1.4.2 yamt dc->dc_iot = &igsfb_iot;
166 1.1.4.2 yamt dc->dc_iobase = 0;
167 1.1.4.2 yamt dc->dc_ioflags = 0;
168 1.1.4.2 yamt
169 1.1.4.2 yamt if (bus_space_map(dc->dc_iot,
170 1.1.4.2 yamt dc->dc_iobase + IGS_REG_BASE, IGS_REG_SIZE,
171 1.1.4.2 yamt dc->dc_ioflags,
172 1.1.4.2 yamt &dc->dc_ioh) != 0)
173 1.1.4.2 yamt {
174 1.1.4.2 yamt printf("unable to map I/O registers\n");
175 1.1.4.2 yamt return 1;
176 1.1.4.2 yamt }
177 1.1.4.2 yamt ret = igsfb_enable(dc->dc_iot, dc->dc_iobase, dc->dc_ioflags);
178 1.1.4.2 yamt if (ret)
179 1.1.4.2 yamt return ret;
180 1.1.4.2 yamt return 0;
181 1.1.4.2 yamt }
182 1.1.4.2 yamt
183 1.1.4.2 yamt static int
184 1.1.4.2 yamt igsfb_ofbus_is_console(int phandle)
185 1.1.4.2 yamt {
186 1.1.4.2 yamt
187 1.1.4.2 yamt return igsfb_ofbus_console && (phandle == igsfb_ofbus_phandle);
188 1.1.4.2 yamt }
189 1.1.4.2 yamt
190 1.1.4.2 yamt
191 1.1.4.2 yamt static int
192 1.1.4.2 yamt igsfb_ofbus_match(struct device *parent, struct cfdata *match, void *aux)
193 1.1.4.2 yamt {
194 1.1.4.2 yamt struct ofbus_attach_args *oba = aux;
195 1.1.4.2 yamt
196 1.1.4.4 yamt if (of_compatible(oba->oba_phandle, compat_strings) < 0)
197 1.1.4.4 yamt return 0;
198 1.1.4.4 yamt
199 1.1.4.2 yamt return 10; /* beat vga etc. */
200 1.1.4.2 yamt }
201 1.1.4.2 yamt
202 1.1.4.2 yamt
203 1.1.4.2 yamt static void
204 1.1.4.2 yamt igsfb_ofbus_attach(struct device *parent, struct device *self, void *aux)
205 1.1.4.2 yamt {
206 1.1.4.2 yamt struct igsfb_softc *sc = (struct igsfb_softc *)self;
207 1.1.4.2 yamt struct ofbus_attach_args *oba = aux;
208 1.1.4.2 yamt uint32_t regs[16];
209 1.1.4.2 yamt int isconsole, ret;
210 1.1.4.2 yamt
211 1.1.4.2 yamt if (igsfb_ofbus_is_console(oba->oba_phandle)) {
212 1.1.4.2 yamt isconsole = 1;
213 1.1.4.4 yamt sc->sc_dc = &igsfb_console_dc;
214 1.1.4.2 yamt } else {
215 1.1.4.4 yamt isconsole = 0;
216 1.1.4.2 yamt sc->sc_dc = malloc(sizeof(struct igsfb_devconfig),
217 1.1.4.2 yamt M_DEVBUF, M_NOWAIT | M_ZERO);
218 1.1.4.2 yamt if (sc->sc_dc == NULL)
219 1.1.4.2 yamt panic("unable to allocate igsfb_devconfig");
220 1.1.4.4 yamt if (OF_getprop(oba->oba_phandle, "reg",
221 1.1.4.4 yamt regs, sizeof(regs)) <= 0)
222 1.1.4.4 yamt {
223 1.1.4.4 yamt printf(": unable to read 'reg' property\n");
224 1.1.4.2 yamt return;
225 1.1.4.2 yamt }
226 1.1.4.2 yamt ret = igsfb_setup_dc(sc->sc_dc);
227 1.1.4.2 yamt if (ret)
228 1.1.4.2 yamt return;
229 1.1.4.2 yamt }
230 1.1.4.2 yamt printf(": IGS CyberPro 2010 at 0x%08x\n", (uint32_t)igsfb_mem_paddr);
231 1.1.4.2 yamt
232 1.1.4.2 yamt igsfb_attach_subr(sc, isconsole);
233 1.1.4.2 yamt }
234