ipaq_pcic.c revision 1.6.2.4 1 1.6.2.4 jdolecek /* $NetBSD: ipaq_pcic.c,v 1.6.2.4 2002/10/10 18:32:50 jdolecek Exp $ */
2 1.6.2.2 lukem
3 1.6.2.2 lukem /*-
4 1.6.2.2 lukem * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.6.2.2 lukem * All rights reserved.
6 1.6.2.2 lukem *
7 1.6.2.2 lukem * This code is derived from software contributed to The NetBSD Foundation
8 1.6.2.2 lukem * by Ichiro FUKUHARA (ichiro (at) ichiro.org).
9 1.6.2.2 lukem *
10 1.6.2.2 lukem * Redistribution and use in source and binary forms, with or without
11 1.6.2.2 lukem * modification, are permitted provided that the following conditions
12 1.6.2.2 lukem * are met:
13 1.6.2.2 lukem * 1. Redistributions of source code must retain the above copyright
14 1.6.2.2 lukem * notice, this list of conditions and the following disclaimer.
15 1.6.2.2 lukem * 2. Redistributions in binary form must reproduce the above copyright
16 1.6.2.2 lukem * notice, this list of conditions and the following disclaimer in the
17 1.6.2.2 lukem * documentation and/or other materials provided with the distribution.
18 1.6.2.2 lukem * 3. All advertising materials mentioning features or use of this software
19 1.6.2.2 lukem * must display the following acknowledgement:
20 1.6.2.2 lukem * This product includes software developed by the NetBSD
21 1.6.2.2 lukem * Foundation, Inc. and its contributors.
22 1.6.2.2 lukem * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.6.2.2 lukem * contributors may be used to endorse or promote products derived
24 1.6.2.2 lukem * from this software without specific prior written permission.
25 1.6.2.2 lukem *
26 1.6.2.2 lukem * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.6.2.2 lukem * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.6.2.2 lukem * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.6.2.2 lukem * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.6.2.2 lukem * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.6.2.2 lukem * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.6.2.2 lukem * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.6.2.2 lukem * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.6.2.2 lukem * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.6.2.2 lukem * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.6.2.2 lukem * POSSIBILITY OF SUCH DAMAGE.
37 1.6.2.2 lukem */
38 1.6.2.2 lukem
39 1.6.2.2 lukem #include <sys/param.h>
40 1.6.2.2 lukem #include <sys/systm.h>
41 1.6.2.2 lukem #include <sys/types.h>
42 1.6.2.2 lukem #include <sys/conf.h>
43 1.6.2.2 lukem #include <sys/file.h>
44 1.6.2.2 lukem #include <sys/device.h>
45 1.6.2.2 lukem #include <sys/kernel.h>
46 1.6.2.2 lukem #include <sys/kthread.h>
47 1.6.2.2 lukem #include <sys/malloc.h>
48 1.6.2.2 lukem
49 1.6.2.2 lukem #include <machine/bus.h>
50 1.6.2.2 lukem #include <dev/pcmcia/pcmciachip.h>
51 1.6.2.2 lukem #include <dev/pcmcia/pcmciavar.h>
52 1.6.2.2 lukem
53 1.6.2.2 lukem #include <hpcarm/dev/ipaq_saipvar.h>
54 1.6.2.2 lukem #include <hpcarm/dev/ipaq_pcicreg.h>
55 1.6.2.2 lukem #include <hpcarm/dev/ipaq_gpioreg.h>
56 1.6.2.3 jdolecek
57 1.6.2.3 jdolecek #include <arm/sa11x0/sa11x0_gpioreg.h>
58 1.6.2.3 jdolecek #include <arm/sa11x0/sa11x0_var.h>
59 1.6.2.3 jdolecek #include <arm/sa11x0/sa11xx_pcicvar.h>
60 1.6.2.2 lukem
61 1.6.2.2 lukem #include "ipaqpcic.h"
62 1.6.2.2 lukem
63 1.6.2.2 lukem static int ipaqpcic_match(struct device *, struct cfdata *, void *);
64 1.6.2.2 lukem static void ipaqpcic_attach(struct device *, struct device *, void *);
65 1.6.2.2 lukem static int ipaqpcic_print(void *, const char *);
66 1.6.2.2 lukem static int ipaqpcic_submatch(struct device *, struct cfdata *, void *);
67 1.6.2.2 lukem
68 1.6.2.2 lukem static int ipaqpcic_read(struct sapcic_socket *, int);
69 1.6.2.2 lukem static void ipaqpcic_write(struct sapcic_socket *, int, int);
70 1.6.2.2 lukem static void ipaqpcic_set_power(struct sapcic_socket *, int);
71 1.6.2.2 lukem static void ipaqpcic_clear_intr(int);
72 1.6.2.2 lukem static void *ipaqpcic_intr_establish(struct sapcic_socket *, int,
73 1.6.2.2 lukem int (*)(void *), void *);
74 1.6.2.2 lukem static void ipaqpcic_intr_disestablish(struct sapcic_socket *, void *);
75 1.6.2.2 lukem
76 1.6.2.2 lukem struct ipaqpcic_softc {
77 1.6.2.2 lukem struct sapcic_softc sc_pc;
78 1.6.2.2 lukem bus_space_handle_t sc_ioh;
79 1.6.2.2 lukem struct ipaq_softc *sc_parent;
80 1.6.2.2 lukem struct sapcic_socket sc_socket[2];
81 1.6.2.2 lukem };
82 1.6.2.2 lukem
83 1.6.2.2 lukem static void ipaqpcic_init(struct ipaqpcic_softc *);
84 1.6.2.2 lukem
85 1.6.2.2 lukem static struct sapcic_tag ipaqpcic_functions = {
86 1.6.2.2 lukem ipaqpcic_read,
87 1.6.2.2 lukem ipaqpcic_write,
88 1.6.2.2 lukem ipaqpcic_set_power,
89 1.6.2.2 lukem ipaqpcic_clear_intr,
90 1.6.2.2 lukem ipaqpcic_intr_establish,
91 1.6.2.2 lukem ipaqpcic_intr_disestablish
92 1.6.2.2 lukem };
93 1.6.2.2 lukem
94 1.6.2.4 jdolecek CFATTACH_DECL(ipaqpcic, sizeof(struct ipaqpcic_softc),
95 1.6.2.4 jdolecek ipaqpcic_match, ipaqpcic_attach, NULL, NULL);
96 1.6.2.2 lukem
97 1.6.2.2 lukem static int
98 1.6.2.2 lukem ipaqpcic_match(parent, cf, aux)
99 1.6.2.2 lukem struct device *parent;
100 1.6.2.2 lukem struct cfdata *cf;
101 1.6.2.2 lukem void *aux;
102 1.6.2.2 lukem {
103 1.6.2.2 lukem return (1);
104 1.6.2.2 lukem }
105 1.6.2.2 lukem
106 1.6.2.2 lukem static void
107 1.6.2.2 lukem ipaqpcic_attach(parent, self, aux)
108 1.6.2.2 lukem struct device *parent;
109 1.6.2.2 lukem struct device *self;
110 1.6.2.2 lukem void *aux;
111 1.6.2.2 lukem {
112 1.6.2.2 lukem int i;
113 1.6.2.2 lukem struct pcmciabus_attach_args paa;
114 1.6.2.2 lukem struct ipaqpcic_softc *sc = (struct ipaqpcic_softc *)self;
115 1.6.2.2 lukem struct ipaq_softc *psc = (struct ipaq_softc *)parent;
116 1.6.2.2 lukem
117 1.6.2.2 lukem printf("\n");
118 1.6.2.2 lukem
119 1.6.2.2 lukem sc->sc_pc.sc_iot = psc->sc_iot;
120 1.6.2.2 lukem sc->sc_ioh = psc->sc_ioh;
121 1.6.2.2 lukem sc->sc_parent = (struct ipaq_softc *)parent;
122 1.6.2.2 lukem
123 1.6.2.2 lukem ipaqpcic_init(sc);
124 1.6.2.2 lukem
125 1.6.2.2 lukem for(i = 0; i < 2; i++) {
126 1.6.2.2 lukem sc->sc_socket[i].sc = (struct sapcic_softc *)sc;
127 1.6.2.2 lukem sc->sc_socket[i].socket = i;
128 1.6.2.2 lukem sc->sc_socket[i].pcictag_cookie = psc;
129 1.6.2.2 lukem sc->sc_socket[i].pcictag = &ipaqpcic_functions;
130 1.6.2.2 lukem sc->sc_socket[i].event_thread = NULL;
131 1.6.2.2 lukem sc->sc_socket[i].event = 0;
132 1.6.2.2 lukem sc->sc_socket[i].laststatus = SAPCIC_CARD_INVALID;
133 1.6.2.2 lukem sc->sc_socket[i].shutdown = 0;
134 1.6.2.2 lukem
135 1.6.2.2 lukem paa.paa_busname = "pcmcia";
136 1.6.2.2 lukem paa.pct = (pcmcia_chipset_tag_t)&sa11x0_pcmcia_functions;
137 1.6.2.2 lukem paa.pch = (pcmcia_chipset_handle_t)&sc->sc_socket[i];
138 1.6.2.2 lukem paa.iobase = 0;
139 1.6.2.2 lukem paa.iosize = 0x4000000;
140 1.6.2.2 lukem
141 1.6.2.2 lukem sc->sc_socket[i].pcmcia =
142 1.6.2.2 lukem (struct device *)config_found_sm(&sc->sc_pc.sc_dev,
143 1.6.2.2 lukem &paa, ipaqpcic_print, ipaqpcic_submatch);
144 1.6.2.2 lukem
145 1.6.2.2 lukem sa11x0_intr_establish((sa11x0_chipset_tag_t)psc,
146 1.6.2.2 lukem i ? IRQ_CD1 : IRQ_CD0,
147 1.6.2.2 lukem 1, IPL_BIO, sapcic_intr,
148 1.6.2.2 lukem &sc->sc_socket[i]);
149 1.6.2.2 lukem
150 1.6.2.2 lukem /* schedule kthread creation */
151 1.6.2.2 lukem kthread_create(sapcic_kthread_create, &sc->sc_socket[i]);
152 1.6.2.2 lukem
153 1.6.2.2 lukem #if 0 /* XXX */
154 1.6.2.2 lukem /* establish_intr should be after creating the kthread */
155 1.6.2.2 lukem config_interrupt(&sc->sc_socket[i], ipaqpcic_config_intr);
156 1.6.2.2 lukem #endif
157 1.6.2.2 lukem }
158 1.6.2.2 lukem }
159 1.6.2.2 lukem
160 1.6.2.2 lukem static int
161 1.6.2.2 lukem ipaqpcic_print(aux, name)
162 1.6.2.2 lukem void *aux;
163 1.6.2.2 lukem const char *name;
164 1.6.2.2 lukem {
165 1.6.2.2 lukem return (UNCONF);
166 1.6.2.2 lukem }
167 1.6.2.2 lukem
168 1.6.2.2 lukem static int
169 1.6.2.2 lukem ipaqpcic_submatch(parent, cf, aux)
170 1.6.2.2 lukem struct device *parent;
171 1.6.2.2 lukem struct cfdata *cf;
172 1.6.2.2 lukem void *aux;
173 1.6.2.2 lukem {
174 1.6.2.4 jdolecek return config_match(parent, cf, aux);
175 1.6.2.2 lukem }
176 1.6.2.2 lukem
177 1.6.2.2 lukem static void
178 1.6.2.2 lukem ipaqpcic_init(sc)
179 1.6.2.2 lukem struct ipaqpcic_softc *sc;
180 1.6.2.2 lukem {
181 1.6.2.2 lukem int cr;
182 1.6.2.2 lukem
183 1.6.2.2 lukem /* All those are inputs */
184 1.6.2.2 lukem cr = bus_space_read_4(sc->sc_pc.sc_iot, sc->sc_parent->sc_gpioh, SAGPIO_PDR);
185 1.6.2.2 lukem cr &= ~(GPIO_H3600_PCMCIA_CD0 | GPIO_H3600_PCMCIA_CD1 | GPIO_H3600_PCMCIA_IRQ0 |
186 1.6.2.2 lukem GPIO_H3600_PCMCIA_IRQ1);
187 1.6.2.2 lukem bus_space_write_4(sc->sc_pc.sc_iot, sc->sc_parent->sc_gpioh, SAGPIO_PDR, cr);
188 1.6.2.2 lukem
189 1.6.2.2 lukem sc->sc_parent->ipaq_egpio |=
190 1.6.2.2 lukem EGPIO_H3600_OPT_NVRAM_ON | EGPIO_H3600_OPT_ON ;
191 1.6.2.2 lukem sc->sc_parent->ipaq_egpio &=
192 1.6.2.2 lukem ~(EGPIO_H3600_CARD_RESET | EGPIO_H3600_OPT_RESET);
193 1.6.2.2 lukem bus_space_write_2(sc->sc_pc.sc_iot, sc->sc_parent->sc_egpioh,
194 1.6.2.2 lukem 0, sc->sc_parent->ipaq_egpio);
195 1.6.2.2 lukem }
196 1.6.2.2 lukem
197 1.6.2.2 lukem static int
198 1.6.2.2 lukem ipaqpcic_read(so, reg)
199 1.6.2.2 lukem struct sapcic_socket *so;
200 1.6.2.2 lukem int reg;
201 1.6.2.2 lukem {
202 1.6.2.2 lukem int cr, bit;
203 1.6.2.2 lukem struct ipaqpcic_softc *sc = (struct ipaqpcic_softc *)so->sc;
204 1.6.2.2 lukem
205 1.6.2.2 lukem cr = bus_space_read_4(sc->sc_pc.sc_iot, sc->sc_parent->sc_gpioh, SAGPIO_PLR);
206 1.6.2.2 lukem
207 1.6.2.2 lukem switch (reg) {
208 1.6.2.2 lukem case SAPCIC_STATUS_CARD:
209 1.6.2.2 lukem bit = (so->socket ? GPIO_H3600_PCMCIA_CD0 :
210 1.6.2.2 lukem GPIO_H3600_PCMCIA_CD1) & cr;
211 1.6.2.2 lukem if (!bit)
212 1.6.2.2 lukem return SAPCIC_CARD_INVALID;
213 1.6.2.2 lukem else
214 1.6.2.2 lukem return SAPCIC_CARD_VALID;
215 1.6.2.2 lukem case SAPCIC_STATUS_VS1:
216 1.6.2.2 lukem case SAPCIC_STATUS_VS2:
217 1.6.2.2 lukem case SAPCIC_STATUS_READY:
218 1.6.2.2 lukem bit = (so->socket ? GPIO_H3600_PCMCIA_IRQ0:
219 1.6.2.2 lukem GPIO_H3600_PCMCIA_IRQ1);
220 1.6.2.2 lukem return (bit & cr);
221 1.6.2.2 lukem default:
222 1.6.2.4 jdolecek panic("ipaqpcic_read: bogus register");
223 1.6.2.2 lukem }
224 1.6.2.2 lukem }
225 1.6.2.2 lukem
226 1.6.2.2 lukem static void
227 1.6.2.2 lukem ipaqpcic_write(so, reg, arg)
228 1.6.2.2 lukem struct sapcic_socket *so;
229 1.6.2.2 lukem int reg;
230 1.6.2.2 lukem int arg;
231 1.6.2.2 lukem {
232 1.6.2.2 lukem int s;
233 1.6.2.2 lukem struct ipaqpcic_softc *sc = (struct ipaqpcic_softc *)so->sc;
234 1.6.2.2 lukem
235 1.6.2.2 lukem s = splhigh();
236 1.6.2.2 lukem switch (reg) {
237 1.6.2.2 lukem case SAPCIC_CONTROL_RESET:
238 1.6.2.2 lukem sc->sc_parent->ipaq_egpio |= EGPIO_H3600_CARD_RESET;
239 1.6.2.2 lukem break;
240 1.6.2.2 lukem case SAPCIC_CONTROL_LINEENABLE:
241 1.6.2.2 lukem case SAPCIC_CONTROL_WAITENABLE:
242 1.6.2.2 lukem case SAPCIC_CONTROL_POWERSELECT:
243 1.6.2.2 lukem break;
244 1.6.2.2 lukem
245 1.6.2.2 lukem default:
246 1.6.2.2 lukem splx(s);
247 1.6.2.2 lukem panic("ipaqpcic_write: bogus register");
248 1.6.2.2 lukem }
249 1.6.2.2 lukem bus_space_write_2(sc->sc_pc.sc_iot, sc->sc_parent->sc_egpioh, 0,
250 1.6.2.2 lukem sc->sc_parent->ipaq_egpio);
251 1.6.2.2 lukem splx(s);
252 1.6.2.2 lukem }
253 1.6.2.2 lukem
254 1.6.2.2 lukem static void
255 1.6.2.2 lukem ipaqpcic_set_power(so, arg)
256 1.6.2.2 lukem struct sapcic_socket *so;
257 1.6.2.2 lukem int arg;
258 1.6.2.2 lukem {
259 1.6.2.2 lukem int s;
260 1.6.2.2 lukem struct ipaqpcic_softc *sc = (struct ipaqpcic_softc *)so->sc;
261 1.6.2.2 lukem
262 1.6.2.2 lukem s = splbio();
263 1.6.2.2 lukem switch (arg) {
264 1.6.2.2 lukem case SAPCIC_POWER_OFF:
265 1.6.2.2 lukem sc->sc_parent->ipaq_egpio &=
266 1.6.2.2 lukem ~(EGPIO_H3600_OPT_NVRAM_ON | EGPIO_H3600_OPT_ON);
267 1.6.2.2 lukem break;
268 1.6.2.2 lukem case SAPCIC_POWER_3V:
269 1.6.2.2 lukem case SAPCIC_POWER_5V:
270 1.6.2.2 lukem sc->sc_parent->ipaq_egpio |=
271 1.6.2.2 lukem EGPIO_H3600_OPT_NVRAM_ON | EGPIO_H3600_OPT_ON;
272 1.6.2.2 lukem break;
273 1.6.2.2 lukem default:
274 1.6.2.4 jdolecek panic("ipaqpcic_set_power: bogus arg");
275 1.6.2.2 lukem }
276 1.6.2.2 lukem bus_space_write_2(sc->sc_pc.sc_iot, sc->sc_parent->sc_egpioh,
277 1.6.2.2 lukem 0, sc->sc_parent->ipaq_egpio);
278 1.6.2.2 lukem splx(s);
279 1.6.2.2 lukem }
280 1.6.2.2 lukem
281 1.6.2.2 lukem static void
282 1.6.2.2 lukem ipaqpcic_clear_intr(arg)
283 1.6.2.2 lukem {
284 1.6.2.2 lukem }
285 1.6.2.2 lukem
286 1.6.2.2 lukem static void *
287 1.6.2.2 lukem ipaqpcic_intr_establish(so, level, ih_fun, ih_arg)
288 1.6.2.2 lukem struct sapcic_socket *so;
289 1.6.2.2 lukem int level;
290 1.6.2.2 lukem int (*ih_fun)(void *);
291 1.6.2.2 lukem void *ih_arg;
292 1.6.2.2 lukem {
293 1.6.2.2 lukem int irq;
294 1.6.2.2 lukem
295 1.6.2.2 lukem irq = so->socket ? IRQ_IRQ0 : IRQ_IRQ1;
296 1.6.2.2 lukem return (sa11x0_intr_establish((sa11x0_chipset_tag_t)so->pcictag_cookie,
297 1.6.2.2 lukem irq-16, 1, level, ih_fun, ih_arg));
298 1.6.2.2 lukem }
299 1.6.2.2 lukem
300 1.6.2.2 lukem static void
301 1.6.2.2 lukem ipaqpcic_intr_disestablish(so, ih)
302 1.6.2.2 lukem struct sapcic_socket *so;
303 1.6.2.2 lukem void *ih;
304 1.6.2.2 lukem {
305 1.6.2.2 lukem sa11x0_intr_disestablish((sa11x0_chipset_tag_t)so->pcictag_cookie, ih);
306 1.6.2.2 lukem }
307