sa11x1_pcic.c revision 1.9 1 /* $NetBSD: sa11x1_pcic.c,v 1.9 2003/08/08 12:29:23 bsh Exp $ */
2
3 /*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by IWAMOTO Toshihiro.
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 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: sa11x1_pcic.c,v 1.9 2003/08/08 12:29:23 bsh Exp $");
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/types.h>
45 #include <sys/conf.h>
46 #include <sys/file.h>
47 #include <sys/device.h>
48 #include <sys/kernel.h>
49 #include <sys/kthread.h>
50 #include <sys/malloc.h>
51
52 #include <machine/bus.h>
53
54 #include <dev/pcmcia/pcmciachip.h>
55 #include <dev/pcmcia/pcmciavar.h>
56 #include <arm/sa11x0/sa11x0_reg.h>
57 #include <arm/sa11x0/sa11x0_var.h>
58 #include <arm/sa11x0/sa1111_reg.h>
59 #include <arm/sa11x0/sa1111_var.h>
60 #include <arm/sa11x0/sa11x1_pcicreg.h>
61 #include <arm/sa11x0/sa11xx_pcicvar.h>
62 #include <arm/sa11x0/sa11x1_pcicvar.h>
63
64 #include "sacpcic.h"
65
66 static int sacpcic_print(void *, const char *);
67 static int sacpcic_submatch(struct device *, struct cfdata *, void *);
68
69
70 void
71 sacpcic_attach_common(struct sacc_softc *psc, struct sacpcic_softc *sc,
72 void *aux, void (* socket_setup_hook)(struct sapcic_socket *))
73 {
74 int i;
75 struct pcmciabus_attach_args paa;
76
77 printf("\n");
78
79 sc->sc_pc.sc_iot = psc->sc_iot;
80 sc->sc_ioh = psc->sc_ioh;
81
82 for(i = 0; i < 2; i++) {
83 sc->sc_socket[i].sc = (struct sapcic_softc *)sc;
84 sc->sc_socket[i].socket = i;
85 sc->sc_socket[i].pcictag_cookie = psc;
86 sc->sc_socket[i].pcictag = NULL;
87 sc->sc_socket[i].event_thread = NULL;
88 sc->sc_socket[i].event = 0;
89 sc->sc_socket[i].laststatus = SAPCIC_CARD_INVALID;
90 sc->sc_socket[i].shutdown = 0;
91
92 socket_setup_hook(&sc->sc_socket[i]);
93
94 paa.paa_busname = "pcmcia";
95 paa.pct = (pcmcia_chipset_tag_t)&sa11x0_pcmcia_functions;
96 paa.pch = (pcmcia_chipset_handle_t)&sc->sc_socket[i];
97 paa.iobase = 0;
98 paa.iosize = 0x4000000;
99
100 sc->sc_socket[i].pcmcia =
101 (struct device *)config_found_sm(&sc->sc_pc.sc_dev,
102 &paa, sacpcic_print, sacpcic_submatch);
103
104 sacc_intr_establish((sacc_chipset_tag_t)psc,
105 i ? IRQ_S1_CDVALID : IRQ_S0_CDVALID,
106 IST_EDGE_RAISE, IPL_BIO, sapcic_intr,
107 &sc->sc_socket[i]);
108
109 /* schedule kthread creation */
110 kthread_create(sapcic_kthread_create, &sc->sc_socket[i]);
111
112 #if 0 /* XXX */
113 /* establish_intr should be after creating the kthread */
114 config_interrupt(&sc->sc_socket[i], sacpcic_config_intr);
115 #endif
116 }
117 }
118
119 int
120 sacpcic_print(aux, name)
121 void *aux;
122 const char *name;
123 {
124 return (UNCONF);
125 }
126
127 int
128 sacpcic_submatch(struct device *parent, struct cfdata *cf, void *aux)
129 {
130 return config_match(parent, cf, aux);
131 }
132
133
134 int
135 sacpcic_read(struct sapcic_socket *so, int reg)
136 {
137 int cr, bit;
138 struct sacpcic_softc *sc = (struct sacpcic_softc *)so->sc;
139
140 cr = bus_space_read_4(sc->sc_pc.sc_iot, sc->sc_ioh, SACPCIC_SR);
141
142 switch (reg) {
143 case SAPCIC_STATUS_CARD:
144 bit = (so->socket ? SR_S1_CARDDETECT : SR_S0_CARDDETECT) & cr;
145 if (bit)
146 return SAPCIC_CARD_INVALID;
147 else
148 return SAPCIC_CARD_VALID;
149
150 case SAPCIC_STATUS_VS1:
151 bit = (so->socket ? SR_S1_VS1 : SR_S0_VS1);
152 return (bit & cr);
153
154 case SAPCIC_STATUS_VS2:
155 bit = (so->socket ? SR_S1_VS2 : SR_S0_VS2);
156 return (bit & cr);
157
158 case SAPCIC_STATUS_READY:
159 bit = (so->socket ? SR_S1_READY : SR_S0_READY);
160 return (bit & cr);
161
162 default:
163 panic("sacpcic_read: bogus register");
164 }
165 }
166
167 void
168 sacpcic_write(struct sapcic_socket *so, int reg, int arg)
169 {
170 int s, oldvalue, newvalue, mask;
171 struct sacpcic_softc *sc = (struct sacpcic_softc *)so->sc;
172
173 s = splhigh();
174 oldvalue = bus_space_read_4(sc->sc_pc.sc_iot, sc->sc_ioh, SACPCIC_CR);
175
176 switch (reg) {
177 case SAPCIC_CONTROL_RESET:
178 mask = so->socket ? CR_S1_RST : CR_S0_RST;
179
180 newvalue = (oldvalue & ~mask) | (arg ? mask : 0);
181 break;
182
183 case SAPCIC_CONTROL_LINEENABLE:
184 mask = so->socket ? CR_S1_FLT : CR_S0_FLT;
185
186 newvalue = (oldvalue & ~mask) | (arg ? mask : 0);
187 break;
188
189 case SAPCIC_CONTROL_WAITENABLE:
190 mask = so->socket ? CR_S1_PWAITEN : CR_S0_PWAITEN;
191
192 newvalue = (oldvalue & ~mask) | (arg ? mask : 0);
193 break;
194
195 case SAPCIC_CONTROL_POWERSELECT:
196 mask = so->socket ? CR_S1_PSE : CR_S0_PSE;
197 newvalue = oldvalue & ~mask;
198
199 switch (arg) {
200 case SAPCIC_POWER_3V:
201 break;
202 case SAPCIC_POWER_5V:
203 newvalue |= mask;
204 break;
205 default:
206 splx(s);
207 panic("sacpcic_write: bogus arg");
208 }
209 break;
210
211 default:
212 splx(s);
213 panic("sacpcic_write: bogus register");
214 }
215 bus_space_write_4(sc->sc_pc.sc_iot, sc->sc_ioh, SACPCIC_CR, newvalue);
216 splx(s);
217 }
218
219 void
220 sacpcic_clear_intr(arg)
221 {
222 /* sacc_intr_dispatch takes care of intr status */
223 }
224
225 void *
226 sacpcic_intr_establish(so, level, ih_fun, ih_arg)
227 struct sapcic_socket *so;
228 int level;
229 int (*ih_fun)(void *);
230 void *ih_arg;
231 {
232 int irq;
233
234 irq = so->socket ? IRQ_S1_READY : IRQ_S0_READY;
235 return (sacc_intr_establish((sacc_chipset_tag_t)so->pcictag_cookie, irq,
236 IST_EDGE_FALL, level, ih_fun, ih_arg));
237 }
238
239 void
240 sacpcic_intr_disestablish(so, ih)
241 struct sapcic_socket *so;
242 void *ih;
243 {
244 sacc_intr_disestablish((sacc_chipset_tag_t)so->pcictag_cookie, ih);
245 }
246