shpcmcia.c revision 1.1.4.2 1 1.1.4.2 rmind /* $NetBSD: shpcmcia.c,v 1.1.4.2 2010/05/30 05:16:45 rmind Exp $ */
2 1.1.4.2 rmind
3 1.1.4.2 rmind /*-
4 1.1.4.2 rmind * Copyright (c) 2009 NONAKA Kimihiro <nonaka (at) netbsd.org>
5 1.1.4.2 rmind * All rights reserved.
6 1.1.4.2 rmind *
7 1.1.4.2 rmind * Redistribution and use in source and binary forms, with or without
8 1.1.4.2 rmind * modification, are permitted provided that the following conditions
9 1.1.4.2 rmind * are met:
10 1.1.4.2 rmind * 1. Redistributions of source code must retain the above copyright
11 1.1.4.2 rmind * notice, this list of conditions and the following disclaimer.
12 1.1.4.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.4.2 rmind * notice, this list of conditions and the following disclaimer in the
14 1.1.4.2 rmind * documentation and/or other materials provided with the distribution.
15 1.1.4.2 rmind *
16 1.1.4.2 rmind * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 1.1.4.2 rmind * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.1.4.2 rmind * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.1.4.2 rmind * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 1.1.4.2 rmind * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.1.4.2 rmind * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.1.4.2 rmind * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1.4.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.1.4.2 rmind * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1.4.2 rmind * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1.4.2 rmind * SUCH DAMAGE.
27 1.1.4.2 rmind */
28 1.1.4.2 rmind
29 1.1.4.2 rmind #include <sys/cdefs.h>
30 1.1.4.2 rmind __KERNEL_RCSID(0, "$NetBSD: shpcmcia.c,v 1.1.4.2 2010/05/30 05:16:45 rmind Exp $");
31 1.1.4.2 rmind
32 1.1.4.2 rmind #include <sys/types.h>
33 1.1.4.2 rmind #include <sys/param.h>
34 1.1.4.2 rmind #include <sys/systm.h>
35 1.1.4.2 rmind #include <sys/device.h>
36 1.1.4.2 rmind #include <sys/malloc.h>
37 1.1.4.2 rmind #include <sys/kthread.h>
38 1.1.4.2 rmind #include <sys/kernel.h>
39 1.1.4.2 rmind #include <sys/callout.h>
40 1.1.4.2 rmind #include <sys/bus.h>
41 1.1.4.2 rmind #include <sys/intr.h>
42 1.1.4.2 rmind
43 1.1.4.2 rmind #include <dev/pcmcia/pcmciachip.h>
44 1.1.4.2 rmind #include <dev/pcmcia/pcmciavar.h>
45 1.1.4.2 rmind
46 1.1.4.2 rmind #include <machine/autoconf.h>
47 1.1.4.2 rmind
48 1.1.4.2 rmind #include <sh3/devreg.h>
49 1.1.4.2 rmind #include <sh3/bscreg.h>
50 1.1.4.2 rmind #include <sh3/pfcreg.h>
51 1.1.4.2 rmind
52 1.1.4.2 rmind #include <evbsh3/ap_ms104_sh4/ap_ms104_sh4reg.h>
53 1.1.4.2 rmind #include <evbsh3/ap_ms104_sh4/ap_ms104_sh4var.h>
54 1.1.4.2 rmind
55 1.1.4.2 rmind #ifdef SHPCMCIA_DEBUG
56 1.1.4.2 rmind #define DPRINTF(s) printf s
57 1.1.4.2 rmind #else
58 1.1.4.2 rmind #define DPRINTF(s)
59 1.1.4.2 rmind #endif
60 1.1.4.2 rmind
61 1.1.4.2 rmind static int shpcmcia_chip_mem_alloc(pcmcia_chipset_handle_t,
62 1.1.4.2 rmind bus_size_t, struct pcmcia_mem_handle *);
63 1.1.4.2 rmind static void shpcmcia_chip_mem_free(pcmcia_chipset_handle_t,
64 1.1.4.2 rmind struct pcmcia_mem_handle *);
65 1.1.4.2 rmind static int shpcmcia_chip_mem_map(pcmcia_chipset_handle_t, int,
66 1.1.4.2 rmind bus_addr_t, bus_size_t, struct pcmcia_mem_handle *,
67 1.1.4.2 rmind bus_size_t *, int *);
68 1.1.4.2 rmind static void shpcmcia_chip_mem_unmap(pcmcia_chipset_handle_t, int);
69 1.1.4.2 rmind static int shpcmcia_chip_io_alloc(pcmcia_chipset_handle_t,
70 1.1.4.2 rmind bus_addr_t, bus_size_t, bus_size_t,
71 1.1.4.2 rmind struct pcmcia_io_handle *);
72 1.1.4.2 rmind static void shpcmcia_chip_io_free(pcmcia_chipset_handle_t,
73 1.1.4.2 rmind struct pcmcia_io_handle *);
74 1.1.4.2 rmind static int shpcmcia_chip_io_map(pcmcia_chipset_handle_t, int,
75 1.1.4.2 rmind bus_addr_t, bus_size_t, struct pcmcia_io_handle *, int *);
76 1.1.4.2 rmind static void shpcmcia_chip_io_unmap(pcmcia_chipset_handle_t, int);
77 1.1.4.2 rmind static void *shpcmcia_chip_intr_establish(pcmcia_chipset_handle_t,
78 1.1.4.2 rmind struct pcmcia_function *, int, int (*)(void *), void *);
79 1.1.4.2 rmind static void shpcmcia_chip_intr_disestablish(pcmcia_chipset_handle_t,
80 1.1.4.2 rmind void *);
81 1.1.4.2 rmind static void shpcmcia_chip_socket_enable(pcmcia_chipset_handle_t);
82 1.1.4.2 rmind static void shpcmcia_chip_socket_disable(pcmcia_chipset_handle_t);
83 1.1.4.2 rmind static void shpcmcia_chip_socket_settype(pcmcia_chipset_handle_t,
84 1.1.4.2 rmind int);
85 1.1.4.2 rmind
86 1.1.4.2 rmind static struct pcmcia_chip_functions shpcmcia_chip_functions = {
87 1.1.4.2 rmind /* memory space allocation */
88 1.1.4.2 rmind .mem_alloc = shpcmcia_chip_mem_alloc,
89 1.1.4.2 rmind .mem_free = shpcmcia_chip_mem_free,
90 1.1.4.2 rmind
91 1.1.4.2 rmind /* memory space window mapping */
92 1.1.4.2 rmind .mem_map = shpcmcia_chip_mem_map,
93 1.1.4.2 rmind .mem_unmap = shpcmcia_chip_mem_unmap,
94 1.1.4.2 rmind
95 1.1.4.2 rmind /* I/O space allocation */
96 1.1.4.2 rmind .io_alloc = shpcmcia_chip_io_alloc,
97 1.1.4.2 rmind .io_free = shpcmcia_chip_io_free,
98 1.1.4.2 rmind
99 1.1.4.2 rmind /* I/O space window mapping */
100 1.1.4.2 rmind .io_map = shpcmcia_chip_io_map,
101 1.1.4.2 rmind .io_unmap = shpcmcia_chip_io_unmap,
102 1.1.4.2 rmind
103 1.1.4.2 rmind /* interrupt glue */
104 1.1.4.2 rmind .intr_establish = shpcmcia_chip_intr_establish,
105 1.1.4.2 rmind .intr_disestablish = shpcmcia_chip_intr_disestablish,
106 1.1.4.2 rmind
107 1.1.4.2 rmind /* card enable/disable */
108 1.1.4.2 rmind .socket_enable = shpcmcia_chip_socket_enable,
109 1.1.4.2 rmind .socket_disable = shpcmcia_chip_socket_disable,
110 1.1.4.2 rmind .socket_settype = shpcmcia_chip_socket_settype,
111 1.1.4.2 rmind
112 1.1.4.2 rmind /* card detection */
113 1.1.4.2 rmind .card_detect = NULL,
114 1.1.4.2 rmind };
115 1.1.4.2 rmind
116 1.1.4.2 rmind /*
117 1.1.4.2 rmind * event thread
118 1.1.4.2 rmind */
119 1.1.4.2 rmind struct shpcmcia_event {
120 1.1.4.2 rmind SIMPLEQ_ENTRY(shpcmcia_event) pe_q;
121 1.1.4.2 rmind int pe_type;
122 1.1.4.2 rmind };
123 1.1.4.2 rmind
124 1.1.4.2 rmind /* pe_type */
125 1.1.4.2 rmind #define SHPCMCIA_EVENT_INSERT 0
126 1.1.4.2 rmind #define SHPCMCIA_EVENT_REMOVE 1
127 1.1.4.2 rmind
128 1.1.4.2 rmind struct shpcmcia_softc;
129 1.1.4.2 rmind struct shpcmcia_handle {
130 1.1.4.2 rmind struct shpcmcia_softc *sc;
131 1.1.4.2 rmind
132 1.1.4.2 rmind int flags;
133 1.1.4.2 rmind #define SHPCMCIA_FLAG_SOCKETP 0x0001
134 1.1.4.2 rmind #define SHPCMCIA_FLAG_CARDP 0x0002
135 1.1.4.2 rmind int laststate;
136 1.1.4.2 rmind #define SHPCMCIA_LASTSTATE_EMPTY 0x0000
137 1.1.4.2 rmind #define SHPCMCIA_LASTSTATE_PRESENT 0x0002
138 1.1.4.2 rmind
139 1.1.4.2 rmind
140 1.1.4.2 rmind int memalloc;
141 1.1.4.2 rmind struct {
142 1.1.4.2 rmind bus_addr_t addr;
143 1.1.4.2 rmind bus_size_t size;
144 1.1.4.2 rmind long offset;
145 1.1.4.2 rmind int kind;
146 1.1.4.2 rmind #define SHPCMCIA_MEM_WINS 5
147 1.1.4.2 rmind } mem[SHPCMCIA_MEM_WINS];
148 1.1.4.2 rmind
149 1.1.4.2 rmind int ioalloc;
150 1.1.4.2 rmind struct {
151 1.1.4.2 rmind bus_addr_t addr;
152 1.1.4.2 rmind bus_size_t size;
153 1.1.4.2 rmind int width;
154 1.1.4.2 rmind #define SHPCMCIA_IO_WINS 2
155 1.1.4.2 rmind } io[SHPCMCIA_IO_WINS];
156 1.1.4.2 rmind
157 1.1.4.2 rmind struct device *pcmcia;
158 1.1.4.2 rmind
159 1.1.4.2 rmind int shutdown;
160 1.1.4.2 rmind lwp_t *event_thread;
161 1.1.4.2 rmind SIMPLEQ_HEAD(, shpcmcia_event) events;
162 1.1.4.2 rmind };
163 1.1.4.2 rmind
164 1.1.4.2 rmind struct shpcmcia_softc {
165 1.1.4.2 rmind device_t sc_dev;
166 1.1.4.2 rmind
167 1.1.4.2 rmind bus_space_tag_t sc_iot;
168 1.1.4.2 rmind bus_space_handle_t sc_ioh;
169 1.1.4.2 rmind bus_space_tag_t sc_memt;
170 1.1.4.2 rmind bus_space_handle_t sc_memh;
171 1.1.4.2 rmind bus_space_tag_t sc_attt;
172 1.1.4.2 rmind bus_space_handle_t sc_atth;
173 1.1.4.2 rmind
174 1.1.4.2 rmind pcmcia_chipset_tag_t sc_pct;
175 1.1.4.2 rmind
176 1.1.4.2 rmind void *sc_ih;
177 1.1.4.2 rmind #if 0
178 1.1.4.2 rmind void *sc_detect_ih;
179 1.1.4.2 rmind #else
180 1.1.4.2 rmind callout_t sc_detect_ch;
181 1.1.4.2 rmind #endif
182 1.1.4.2 rmind
183 1.1.4.2 rmind bus_addr_t sc_membase;
184 1.1.4.2 rmind #define SHPCMCIA_MAX_MEM_PAGES (8 * sizeof(int))
185 1.1.4.2 rmind
186 1.1.4.2 rmind bus_addr_t sc_iobase;
187 1.1.4.2 rmind bus_size_t sc_iosize;
188 1.1.4.2 rmind
189 1.1.4.2 rmind #define SHPCMCIA_NSLOTS 1
190 1.1.4.2 rmind struct shpcmcia_handle sc_handle[SHPCMCIA_NSLOTS];
191 1.1.4.2 rmind };
192 1.1.4.2 rmind
193 1.1.4.2 rmind static int shpcmcia_probe(device_t, cfdata_t, void *);
194 1.1.4.2 rmind static void shpcmcia_attach(device_t, device_t, void *);
195 1.1.4.2 rmind static int shpcmcia_print(void *, const char *);
196 1.1.4.2 rmind
197 1.1.4.2 rmind CFATTACH_DECL_NEW(shpcmcia, sizeof(struct shpcmcia_softc),
198 1.1.4.2 rmind shpcmcia_probe, shpcmcia_attach, NULL, NULL);
199 1.1.4.2 rmind
200 1.1.4.2 rmind #if 0
201 1.1.4.2 rmind static int shpcmcia_card_detect_intr(void *arg);
202 1.1.4.2 rmind #else
203 1.1.4.2 rmind static void shpcmcia_card_detect_poll(void *arg);
204 1.1.4.2 rmind #endif
205 1.1.4.2 rmind
206 1.1.4.2 rmind static void shpcmcia_init_socket(struct shpcmcia_handle *);
207 1.1.4.2 rmind static void shpcmcia_attach_socket(struct shpcmcia_handle *);
208 1.1.4.2 rmind static void shpcmcia_attach_sockets(struct shpcmcia_softc *);
209 1.1.4.2 rmind
210 1.1.4.2 rmind static void shpcmcia_event_thread(void *);
211 1.1.4.2 rmind static void shpcmcia_queue_event(struct shpcmcia_handle *, int);
212 1.1.4.2 rmind
213 1.1.4.2 rmind static void shpcmcia_attach_card(struct shpcmcia_handle *);
214 1.1.4.2 rmind static void shpcmcia_detach_card(struct shpcmcia_handle *, int );
215 1.1.4.2 rmind static void shpcmcia_deactivate_card(struct shpcmcia_handle *);
216 1.1.4.2 rmind
217 1.1.4.2 rmind static int
218 1.1.4.2 rmind shpcmcia_probe(device_t parent, cfdata_t cfp, void *aux)
219 1.1.4.2 rmind {
220 1.1.4.2 rmind struct mainbus_attach_args *maa = aux;
221 1.1.4.2 rmind
222 1.1.4.2 rmind if (strcmp(maa->ma_name, "shpcmcia") != 0)
223 1.1.4.2 rmind return 0;
224 1.1.4.2 rmind return 1;
225 1.1.4.2 rmind }
226 1.1.4.2 rmind
227 1.1.4.2 rmind static void
228 1.1.4.2 rmind shpcmcia_attach(device_t parent, device_t self, void *aux)
229 1.1.4.2 rmind {
230 1.1.4.2 rmind struct shpcmcia_softc *sc = device_private(self);
231 1.1.4.2 rmind #if 0
232 1.1.4.2 rmind uint32_t reg;
233 1.1.4.2 rmind #endif
234 1.1.4.2 rmind
235 1.1.4.2 rmind sc->sc_dev = self;
236 1.1.4.2 rmind
237 1.1.4.2 rmind aprint_naive("\n");
238 1.1.4.2 rmind aprint_normal("\n");
239 1.1.4.2 rmind
240 1.1.4.2 rmind #if 0
241 1.1.4.2 rmind /* setup bus controller */
242 1.1.4.2 rmind /* max wait */
243 1.1.4.2 rmind reg = _reg_read_4(SH4_WCR1);
244 1.1.4.2 rmind reg |= 0x00700000;
245 1.1.4.2 rmind _reg_write_4(SH4_WCR1, reg);
246 1.1.4.2 rmind reg = _reg_read_4(SH4_WCR2);
247 1.1.4.2 rmind reg |= 0xfff00000;
248 1.1.4.2 rmind _reg_write_4(SH4_WCR2, reg);
249 1.1.4.2 rmind reg = _reg_read_4(SH4_WCR3);
250 1.1.4.2 rmind reg |= 0x07700000;
251 1.1.4.2 rmind _reg_write_4(SH4_WCR3, reg);
252 1.1.4.2 rmind reg = _reg_read_4(SH4_PCR);
253 1.1.4.2 rmind reg |= 0xffffffff;
254 1.1.4.2 rmind _reg_write_4(SH4_PCR, reg);
255 1.1.4.2 rmind #endif
256 1.1.4.2 rmind
257 1.1.4.2 rmind sc->sc_pct = (pcmcia_chipset_tag_t)&shpcmcia_chip_functions;
258 1.1.4.2 rmind sc->sc_iot = &ap_ms104_sh4_bus_io;
259 1.1.4.2 rmind sc->sc_memt = &ap_ms104_sh4_bus_mem;
260 1.1.4.2 rmind sc->sc_attt = &ap_ms104_sh4_bus_att;
261 1.1.4.2 rmind
262 1.1.4.2 rmind if (bus_space_map(sc->sc_attt, 0x14000000, 4 * 1024, 0, &sc->sc_atth))
263 1.1.4.2 rmind panic("%s: couldn't map attribute\n", device_xname(sc->sc_dev));
264 1.1.4.2 rmind if (bus_space_map(sc->sc_iot, 0x15000000, 64 * 1024, 0,
265 1.1.4.2 rmind &sc->sc_ioh))
266 1.1.4.2 rmind panic("%s: couldn't map io memory\n", device_xname(sc->sc_dev));
267 1.1.4.2 rmind if (bus_space_map(sc->sc_memt, 0x16000000, 32 * 1024 * 1024, 0,
268 1.1.4.2 rmind &sc->sc_memh))
269 1.1.4.2 rmind panic("%s: couldn't map memory\n", device_xname(sc->sc_dev));
270 1.1.4.2 rmind
271 1.1.4.2 rmind sc->sc_iobase = sc->sc_ioh;
272 1.1.4.2 rmind sc->sc_iosize = 64 * 1024;
273 1.1.4.2 rmind sc->sc_membase = sc->sc_memh;
274 1.1.4.2 rmind
275 1.1.4.2 rmind sc->sc_handle[0].sc = sc;
276 1.1.4.2 rmind sc->sc_handle[0].flags = SHPCMCIA_FLAG_SOCKETP;
277 1.1.4.2 rmind sc->sc_handle[0].laststate = SHPCMCIA_LASTSTATE_EMPTY;
278 1.1.4.2 rmind SIMPLEQ_INIT(&sc->sc_handle[0].events);
279 1.1.4.2 rmind
280 1.1.4.2 rmind #if 0
281 1.1.4.2 rmind sc->sc_detect_ih = gpio_intr_establish(GPIO_PIN_CARD_CD,
282 1.1.4.2 rmind shpcmcia_card_detect_intr, sc);
283 1.1.4.2 rmind if (sc->sc_detect_ih == NULL) {
284 1.1.4.2 rmind aprint_error_dev(self, "couldn't establish detect interrupt\n");
285 1.1.4.2 rmind }
286 1.1.4.2 rmind #else
287 1.1.4.2 rmind callout_init(&sc->sc_detect_ch, 0);
288 1.1.4.2 rmind callout_reset(&sc->sc_detect_ch, hz, shpcmcia_card_detect_poll, sc);
289 1.1.4.2 rmind #endif
290 1.1.4.2 rmind
291 1.1.4.2 rmind shpcmcia_attach_sockets(sc);
292 1.1.4.2 rmind }
293 1.1.4.2 rmind
294 1.1.4.2 rmind static void
295 1.1.4.2 rmind shpcmcia_attach_sockets(struct shpcmcia_softc *sc)
296 1.1.4.2 rmind {
297 1.1.4.2 rmind
298 1.1.4.2 rmind shpcmcia_attach_socket(&sc->sc_handle[0]);
299 1.1.4.2 rmind }
300 1.1.4.2 rmind
301 1.1.4.2 rmind static void
302 1.1.4.2 rmind shpcmcia_attach_socket(struct shpcmcia_handle *h)
303 1.1.4.2 rmind {
304 1.1.4.2 rmind struct pcmciabus_attach_args paa;
305 1.1.4.2 rmind
306 1.1.4.2 rmind /* initialize the rest of the handle */
307 1.1.4.2 rmind h->shutdown = 0;
308 1.1.4.2 rmind h->memalloc = 0;
309 1.1.4.2 rmind h->ioalloc = 0;
310 1.1.4.2 rmind
311 1.1.4.2 rmind /* now, config one pcmcia device per socket */
312 1.1.4.2 rmind paa.paa_busname = "pcmcia";
313 1.1.4.2 rmind paa.pct = (pcmcia_chipset_tag_t)h->sc->sc_pct;
314 1.1.4.2 rmind paa.pch = (pcmcia_chipset_handle_t)h;
315 1.1.4.2 rmind paa.iobase = h->sc->sc_iobase;
316 1.1.4.2 rmind paa.iosize = h->sc->sc_iosize;
317 1.1.4.2 rmind
318 1.1.4.2 rmind h->pcmcia = config_found_ia(h->sc->sc_dev, "pcmciabus", &paa,
319 1.1.4.2 rmind shpcmcia_print);
320 1.1.4.2 rmind
321 1.1.4.2 rmind /* if there's actually a pcmcia device attached, initialize the slot */
322 1.1.4.2 rmind if (h->pcmcia)
323 1.1.4.2 rmind shpcmcia_init_socket(h);
324 1.1.4.2 rmind }
325 1.1.4.2 rmind
326 1.1.4.2 rmind /*ARGSUSED*/
327 1.1.4.2 rmind static int
328 1.1.4.2 rmind shpcmcia_print(void *arg, const char *pnp)
329 1.1.4.2 rmind {
330 1.1.4.2 rmind
331 1.1.4.2 rmind if (pnp)
332 1.1.4.2 rmind aprint_normal("pcmcia at %s", pnp);
333 1.1.4.2 rmind return UNCONF;
334 1.1.4.2 rmind }
335 1.1.4.2 rmind
336 1.1.4.2 rmind static void
337 1.1.4.2 rmind shpcmcia_init_socket(struct shpcmcia_handle *h)
338 1.1.4.2 rmind {
339 1.1.4.2 rmind uint16_t reg;
340 1.1.4.2 rmind
341 1.1.4.2 rmind /*
342 1.1.4.2 rmind * queue creation of a kernel thread to handle insert/removal events.
343 1.1.4.2 rmind */
344 1.1.4.2 rmind #ifdef DIAGNOSTIC
345 1.1.4.2 rmind if (h->event_thread != NULL)
346 1.1.4.2 rmind panic("shpcmcia_attach_socket: event thread");
347 1.1.4.2 rmind #endif
348 1.1.4.2 rmind
349 1.1.4.2 rmind /* if there's a card there, then attach it. */
350 1.1.4.2 rmind reg = _reg_read_2(SH4_PDTRA);
351 1.1.4.2 rmind if (!(reg & (1 << GPIO_PIN_CARD_CD))) {
352 1.1.4.2 rmind shpcmcia_attach_card(h);
353 1.1.4.2 rmind h->laststate = SHPCMCIA_LASTSTATE_PRESENT;
354 1.1.4.2 rmind } else {
355 1.1.4.2 rmind h->laststate = SHPCMCIA_LASTSTATE_EMPTY;
356 1.1.4.2 rmind }
357 1.1.4.2 rmind
358 1.1.4.2 rmind if (kthread_create(PRI_NONE, 0, NULL, shpcmcia_event_thread, h,
359 1.1.4.2 rmind &h->event_thread, "%s", device_xname(h->sc->sc_dev))) {
360 1.1.4.2 rmind aprint_error_dev(h->sc->sc_dev,
361 1.1.4.2 rmind "unable to create event thread\n");
362 1.1.4.2 rmind panic("shpcmcia_create_event_thread");
363 1.1.4.2 rmind }
364 1.1.4.2 rmind }
365 1.1.4.2 rmind
366 1.1.4.2 rmind /*
367 1.1.4.2 rmind * event thread
368 1.1.4.2 rmind */
369 1.1.4.2 rmind static void
370 1.1.4.2 rmind shpcmcia_event_thread(void *arg)
371 1.1.4.2 rmind {
372 1.1.4.2 rmind struct shpcmcia_handle *h = (struct shpcmcia_handle *)arg;
373 1.1.4.2 rmind struct shpcmcia_event *pe;
374 1.1.4.2 rmind int s;
375 1.1.4.2 rmind
376 1.1.4.2 rmind while (h->shutdown == 0) {
377 1.1.4.2 rmind s = splhigh();
378 1.1.4.2 rmind if ((pe = SIMPLEQ_FIRST(&h->events)) == NULL) {
379 1.1.4.2 rmind splx(s);
380 1.1.4.2 rmind (void) tsleep(&h->events, PWAIT, "waitev", 0);
381 1.1.4.2 rmind continue;
382 1.1.4.2 rmind } else {
383 1.1.4.2 rmind splx(s);
384 1.1.4.2 rmind /* sleep .25s to be enqueued chatterling interrupts */
385 1.1.4.2 rmind (void) tsleep((void *)shpcmcia_event_thread,
386 1.1.4.2 rmind PWAIT, "waitss", hz / 4);
387 1.1.4.2 rmind }
388 1.1.4.2 rmind s = splhigh();
389 1.1.4.2 rmind SIMPLEQ_REMOVE_HEAD(&h->events, pe_q);
390 1.1.4.2 rmind splx(s);
391 1.1.4.2 rmind
392 1.1.4.2 rmind switch (pe->pe_type) {
393 1.1.4.2 rmind case SHPCMCIA_EVENT_INSERT:
394 1.1.4.2 rmind s = splhigh();
395 1.1.4.2 rmind for (;;) {
396 1.1.4.2 rmind struct shpcmcia_event *pe1, *pe2;
397 1.1.4.2 rmind
398 1.1.4.2 rmind if ((pe1 = SIMPLEQ_FIRST(&h->events)) == NULL)
399 1.1.4.2 rmind break;
400 1.1.4.2 rmind if (pe1->pe_type != SHPCMCIA_EVENT_REMOVE)
401 1.1.4.2 rmind break;
402 1.1.4.2 rmind if ((pe2 = SIMPLEQ_NEXT(pe1, pe_q)) == NULL)
403 1.1.4.2 rmind break;
404 1.1.4.2 rmind if (pe2->pe_type == SHPCMCIA_EVENT_INSERT) {
405 1.1.4.2 rmind SIMPLEQ_REMOVE_HEAD(&h->events, pe_q);
406 1.1.4.2 rmind free(pe1, M_TEMP);
407 1.1.4.2 rmind SIMPLEQ_REMOVE_HEAD(&h->events, pe_q);
408 1.1.4.2 rmind free(pe2, M_TEMP);
409 1.1.4.2 rmind }
410 1.1.4.2 rmind }
411 1.1.4.2 rmind splx(s);
412 1.1.4.2 rmind
413 1.1.4.2 rmind DPRINTF(("%s: insertion event\n",
414 1.1.4.2 rmind device_xname(h->sc->sc_dev)));
415 1.1.4.2 rmind shpcmcia_attach_card(h);
416 1.1.4.2 rmind break;
417 1.1.4.2 rmind
418 1.1.4.2 rmind case SHPCMCIA_EVENT_REMOVE:
419 1.1.4.2 rmind s = splhigh();
420 1.1.4.2 rmind for (;;) {
421 1.1.4.2 rmind struct shpcmcia_event *pe1, *pe2;
422 1.1.4.2 rmind
423 1.1.4.2 rmind if ((pe1 = SIMPLEQ_FIRST(&h->events)) == NULL)
424 1.1.4.2 rmind break;
425 1.1.4.2 rmind if (pe1->pe_type != SHPCMCIA_EVENT_INSERT)
426 1.1.4.2 rmind break;
427 1.1.4.2 rmind if ((pe2 = SIMPLEQ_NEXT(pe1, pe_q)) == NULL)
428 1.1.4.2 rmind break;
429 1.1.4.2 rmind if (pe2->pe_type == SHPCMCIA_EVENT_REMOVE) {
430 1.1.4.2 rmind SIMPLEQ_REMOVE_HEAD(&h->events, pe_q);
431 1.1.4.2 rmind free(pe1, M_TEMP);
432 1.1.4.2 rmind SIMPLEQ_REMOVE_HEAD(&h->events, pe_q);
433 1.1.4.2 rmind free(pe2, M_TEMP);
434 1.1.4.2 rmind }
435 1.1.4.2 rmind }
436 1.1.4.2 rmind splx(s);
437 1.1.4.2 rmind
438 1.1.4.2 rmind DPRINTF(("%s: removal event\n",
439 1.1.4.2 rmind device_xname(h->sc->sc_dev)));
440 1.1.4.2 rmind shpcmcia_detach_card(h, DETACH_FORCE);
441 1.1.4.2 rmind break;
442 1.1.4.2 rmind
443 1.1.4.2 rmind default:
444 1.1.4.2 rmind panic("shpcmcia_event_thread: unknown event %d",
445 1.1.4.2 rmind pe->pe_type);
446 1.1.4.2 rmind }
447 1.1.4.2 rmind free(pe, M_TEMP);
448 1.1.4.2 rmind }
449 1.1.4.2 rmind
450 1.1.4.2 rmind h->event_thread = NULL;
451 1.1.4.2 rmind
452 1.1.4.2 rmind /* In case parent is waiting for us to exit. */
453 1.1.4.2 rmind wakeup(h->sc);
454 1.1.4.2 rmind
455 1.1.4.2 rmind kthread_exit(0);
456 1.1.4.2 rmind }
457 1.1.4.2 rmind
458 1.1.4.2 rmind static void
459 1.1.4.2 rmind shpcmcia_queue_event(struct shpcmcia_handle *h, int event)
460 1.1.4.2 rmind {
461 1.1.4.2 rmind struct shpcmcia_event *pe;
462 1.1.4.2 rmind int s;
463 1.1.4.2 rmind
464 1.1.4.2 rmind pe = malloc(sizeof(*pe), M_TEMP, M_NOWAIT);
465 1.1.4.2 rmind if (pe == NULL)
466 1.1.4.2 rmind panic("shpcmcia_queue_event: can't allocate event");
467 1.1.4.2 rmind
468 1.1.4.2 rmind pe->pe_type = event;
469 1.1.4.2 rmind s = splhigh();
470 1.1.4.2 rmind SIMPLEQ_INSERT_TAIL(&h->events, pe, pe_q);
471 1.1.4.2 rmind splx(s);
472 1.1.4.2 rmind wakeup(&h->events);
473 1.1.4.2 rmind }
474 1.1.4.2 rmind
475 1.1.4.2 rmind static void
476 1.1.4.2 rmind shpcmcia_attach_card(struct shpcmcia_handle *h)
477 1.1.4.2 rmind {
478 1.1.4.2 rmind
479 1.1.4.2 rmind DPRINTF(("%s\n", __func__));
480 1.1.4.2 rmind
481 1.1.4.2 rmind if (!(h->flags & SHPCMCIA_FLAG_CARDP)) {
482 1.1.4.2 rmind /* call the MI attach function */
483 1.1.4.2 rmind pcmcia_card_attach(h->pcmcia);
484 1.1.4.2 rmind
485 1.1.4.2 rmind h->flags |= SHPCMCIA_FLAG_CARDP;
486 1.1.4.2 rmind } else {
487 1.1.4.2 rmind DPRINTF(("shpcmcia_attach_card: already attached"));
488 1.1.4.2 rmind }
489 1.1.4.2 rmind }
490 1.1.4.2 rmind
491 1.1.4.2 rmind static void
492 1.1.4.2 rmind shpcmcia_detach_card(struct shpcmcia_handle *h, int flags)
493 1.1.4.2 rmind {
494 1.1.4.2 rmind
495 1.1.4.2 rmind DPRINTF(("%s\n", __func__));
496 1.1.4.2 rmind
497 1.1.4.2 rmind if (h->flags & SHPCMCIA_FLAG_CARDP) {
498 1.1.4.2 rmind h->flags &= ~SHPCMCIA_FLAG_CARDP;
499 1.1.4.2 rmind
500 1.1.4.2 rmind /* call the MI detach function */
501 1.1.4.2 rmind pcmcia_card_detach(h->pcmcia, flags);
502 1.1.4.2 rmind } else {
503 1.1.4.2 rmind DPRINTF(("shpcmcia_detach_card: already detached"));
504 1.1.4.2 rmind }
505 1.1.4.2 rmind }
506 1.1.4.2 rmind
507 1.1.4.2 rmind static void
508 1.1.4.2 rmind shpcmcia_deactivate_card(struct shpcmcia_handle *h)
509 1.1.4.2 rmind {
510 1.1.4.2 rmind
511 1.1.4.2 rmind DPRINTF(("%s\n", __func__));
512 1.1.4.2 rmind
513 1.1.4.2 rmind /* call the MI deactivate function */
514 1.1.4.2 rmind pcmcia_card_deactivate(h->pcmcia);
515 1.1.4.2 rmind
516 1.1.4.2 rmind shpcmcia_chip_socket_disable(h);
517 1.1.4.2 rmind }
518 1.1.4.2 rmind
519 1.1.4.2 rmind #if 0
520 1.1.4.2 rmind /*
521 1.1.4.2 rmind * interrupt
522 1.1.4.2 rmind */
523 1.1.4.2 rmind static int
524 1.1.4.2 rmind shpcmcia_card_detect_intr(void *arg)
525 1.1.4.2 rmind {
526 1.1.4.2 rmind struct shpcmcia_softc *sc = (struct shpcmcia_softc *)arg;
527 1.1.4.2 rmind struct shpcmcia_handle *h = &sc->sc_handle[0];
528 1.1.4.2 rmind uint16_t reg;
529 1.1.4.2 rmind
530 1.1.4.2 rmind DPRINTF(("%s\n", __func__));
531 1.1.4.2 rmind
532 1.1.4.2 rmind reg = _reg_read_2(SH4_PDTRA);
533 1.1.4.2 rmind if (reg & (1 << GPIO_PIN_CARD_CD)) {
534 1.1.4.2 rmind /* remove */
535 1.1.4.2 rmind if (h->laststate == SHPCMCIA_LASTSTATE_PRESENT) {
536 1.1.4.2 rmind /* Deactivate the card now. */
537 1.1.4.2 rmind shpcmcia_deactivate_card(h);
538 1.1.4.2 rmind shpcmcia_queue_event(h, SHPCMCIA_EVENT_REMOVE);
539 1.1.4.2 rmind }
540 1.1.4.2 rmind h->laststate = SHPCMCIA_LASTSTATE_EMPTY;
541 1.1.4.2 rmind } else {
542 1.1.4.2 rmind /* insert */
543 1.1.4.2 rmind if (h->laststate != SHPCMCIA_LASTSTATE_PRESENT) {
544 1.1.4.2 rmind shpcmcia_queue_event(h, SHPCMCIA_EVENT_INSERT);
545 1.1.4.2 rmind }
546 1.1.4.2 rmind h->laststate = SHPCMCIA_LASTSTATE_PRESENT;
547 1.1.4.2 rmind }
548 1.1.4.2 rmind return 1;
549 1.1.4.2 rmind }
550 1.1.4.2 rmind #else
551 1.1.4.2 rmind /*
552 1.1.4.2 rmind * card polling
553 1.1.4.2 rmind */
554 1.1.4.2 rmind static void
555 1.1.4.2 rmind shpcmcia_card_detect_poll(void *arg)
556 1.1.4.2 rmind {
557 1.1.4.2 rmind struct shpcmcia_softc *sc = (struct shpcmcia_softc *)arg;
558 1.1.4.2 rmind struct shpcmcia_handle *h = &sc->sc_handle[0];
559 1.1.4.2 rmind uint16_t reg;
560 1.1.4.2 rmind
561 1.1.4.2 rmind DPRINTF(("%s\n", __func__));
562 1.1.4.2 rmind
563 1.1.4.2 rmind reg = _reg_read_2(SH4_PDTRA);
564 1.1.4.2 rmind if (reg & (1 << GPIO_PIN_CARD_CD)) {
565 1.1.4.2 rmind /* remove */
566 1.1.4.2 rmind if (h->laststate == SHPCMCIA_LASTSTATE_PRESENT) {
567 1.1.4.2 rmind /* Deactivate the card now. */
568 1.1.4.2 rmind shpcmcia_deactivate_card(h);
569 1.1.4.2 rmind shpcmcia_queue_event(h, SHPCMCIA_EVENT_REMOVE);
570 1.1.4.2 rmind }
571 1.1.4.2 rmind h->laststate = SHPCMCIA_LASTSTATE_EMPTY;
572 1.1.4.2 rmind } else {
573 1.1.4.2 rmind /* insert */
574 1.1.4.2 rmind if (h->laststate != SHPCMCIA_LASTSTATE_PRESENT) {
575 1.1.4.2 rmind shpcmcia_queue_event(h, SHPCMCIA_EVENT_INSERT);
576 1.1.4.2 rmind }
577 1.1.4.2 rmind h->laststate = SHPCMCIA_LASTSTATE_PRESENT;
578 1.1.4.2 rmind }
579 1.1.4.2 rmind
580 1.1.4.2 rmind callout_schedule(&sc->sc_detect_ch, hz);
581 1.1.4.2 rmind }
582 1.1.4.2 rmind #endif
583 1.1.4.2 rmind
584 1.1.4.2 rmind /*
585 1.1.4.2 rmind * pcmcia chip functions
586 1.1.4.2 rmind */
587 1.1.4.2 rmind /* Memory space functions. */
588 1.1.4.2 rmind static int
589 1.1.4.2 rmind shpcmcia_chip_mem_alloc(pcmcia_chipset_handle_t pch, bus_size_t size,
590 1.1.4.2 rmind struct pcmcia_mem_handle *pmhp)
591 1.1.4.2 rmind {
592 1.1.4.2 rmind struct shpcmcia_handle *h = (struct shpcmcia_handle *)pch;
593 1.1.4.2 rmind struct shpcmcia_softc *sc = h->sc;
594 1.1.4.2 rmind
595 1.1.4.2 rmind DPRINTF(("%s: size=%d\n", __func__, (unsigned)size));
596 1.1.4.2 rmind
597 1.1.4.2 rmind memset(pmhp, 0, sizeof(*pmhp));
598 1.1.4.2 rmind pmhp->memt = sc->sc_memt;
599 1.1.4.2 rmind pmhp->memh = sc->sc_memh;
600 1.1.4.2 rmind pmhp->addr = 0;
601 1.1.4.2 rmind pmhp->size = size;
602 1.1.4.2 rmind pmhp->realsize = size;
603 1.1.4.2 rmind
604 1.1.4.2 rmind return 0;
605 1.1.4.2 rmind }
606 1.1.4.2 rmind
607 1.1.4.2 rmind /*ARGSUSED*/
608 1.1.4.2 rmind static void
609 1.1.4.2 rmind shpcmcia_chip_mem_free(pcmcia_chipset_handle_t pch,
610 1.1.4.2 rmind struct pcmcia_mem_handle *pmhp)
611 1.1.4.2 rmind {
612 1.1.4.2 rmind
613 1.1.4.2 rmind DPRINTF(("%s\n", __func__));
614 1.1.4.2 rmind }
615 1.1.4.2 rmind
616 1.1.4.2 rmind static int
617 1.1.4.2 rmind shpcmcia_chip_mem_map(pcmcia_chipset_handle_t pch, int kind,
618 1.1.4.2 rmind bus_addr_t card_addr, bus_size_t size, struct pcmcia_mem_handle *pmhp,
619 1.1.4.2 rmind bus_size_t *offsetp, int *windowp)
620 1.1.4.2 rmind {
621 1.1.4.2 rmind struct shpcmcia_handle *h = (struct shpcmcia_handle *)pch;
622 1.1.4.2 rmind struct shpcmcia_softc *sc = h->sc;
623 1.1.4.2 rmind int win;
624 1.1.4.2 rmind int i;
625 1.1.4.2 rmind int s;
626 1.1.4.2 rmind
627 1.1.4.2 rmind DPRINTF(("%s: kind=%#x, card_addr=%#x, size=%d\n",
628 1.1.4.2 rmind __func__, kind, (unsigned)card_addr, (unsigned)size));
629 1.1.4.2 rmind
630 1.1.4.2 rmind s = splbio();
631 1.1.4.2 rmind win = -1;
632 1.1.4.2 rmind for (i = 0; i < SHPCMCIA_MEM_WINS; i++) {
633 1.1.4.2 rmind if ((h->memalloc & (1 << i)) == 0) {
634 1.1.4.2 rmind win = i;
635 1.1.4.2 rmind h->memalloc |= (1 << i);
636 1.1.4.2 rmind break;
637 1.1.4.2 rmind }
638 1.1.4.2 rmind }
639 1.1.4.2 rmind splx(s);
640 1.1.4.2 rmind if (win == -1)
641 1.1.4.2 rmind return 1;
642 1.1.4.2 rmind
643 1.1.4.2 rmind *windowp = win;
644 1.1.4.2 rmind *offsetp = 0;
645 1.1.4.2 rmind
646 1.1.4.2 rmind h->mem[win].addr = pmhp->addr;
647 1.1.4.2 rmind h->mem[win].size = size;
648 1.1.4.2 rmind h->mem[win].offset = (((long)card_addr) - ((long)pmhp->addr));
649 1.1.4.2 rmind h->mem[win].kind = kind;
650 1.1.4.2 rmind
651 1.1.4.2 rmind switch (kind) {
652 1.1.4.2 rmind case PCMCIA_MEM_ATTR:
653 1.1.4.2 rmind DPRINTF(("%s:PCMCIA_MEM_ATTR\n",device_xname(sc->sc_dev)));
654 1.1.4.2 rmind pmhp->memh = sc->sc_atth + card_addr;
655 1.1.4.2 rmind break;
656 1.1.4.2 rmind
657 1.1.4.2 rmind default:
658 1.1.4.2 rmind pmhp->memh = sc->sc_memh + card_addr;
659 1.1.4.2 rmind break;
660 1.1.4.2 rmind }
661 1.1.4.2 rmind
662 1.1.4.2 rmind return 0;
663 1.1.4.2 rmind }
664 1.1.4.2 rmind
665 1.1.4.2 rmind /*ARGSUSED*/
666 1.1.4.2 rmind static void
667 1.1.4.2 rmind shpcmcia_chip_mem_unmap(pcmcia_chipset_handle_t pch, int window)
668 1.1.4.2 rmind {
669 1.1.4.2 rmind struct shpcmcia_handle *h = (struct shpcmcia_handle *)pch;
670 1.1.4.2 rmind int s;
671 1.1.4.2 rmind
672 1.1.4.2 rmind DPRINTF(("%s\n", __func__));
673 1.1.4.2 rmind
674 1.1.4.2 rmind s = splbio();
675 1.1.4.2 rmind h->memalloc &= ~(1 << window);
676 1.1.4.2 rmind splx(s);
677 1.1.4.2 rmind }
678 1.1.4.2 rmind
679 1.1.4.2 rmind /* I/O space functions. */
680 1.1.4.2 rmind static int
681 1.1.4.2 rmind shpcmcia_chip_io_alloc(pcmcia_chipset_handle_t pch,
682 1.1.4.2 rmind bus_addr_t start, bus_size_t size, bus_size_t align,
683 1.1.4.2 rmind struct pcmcia_io_handle *pihp)
684 1.1.4.2 rmind {
685 1.1.4.2 rmind struct shpcmcia_handle *h = (struct shpcmcia_handle *)pch;
686 1.1.4.2 rmind struct shpcmcia_softc *sc = h->sc;
687 1.1.4.2 rmind
688 1.1.4.2 rmind DPRINTF(("%s\n", __func__));
689 1.1.4.2 rmind
690 1.1.4.2 rmind memset(pihp, 0, sizeof(*pihp));
691 1.1.4.2 rmind pihp->iot = sc->sc_iot;
692 1.1.4.2 rmind pihp->ioh = sc->sc_ioh;
693 1.1.4.2 rmind pihp->addr = start;
694 1.1.4.2 rmind pihp->size = size;
695 1.1.4.2 rmind pihp->flags |= PCMCIA_IO_ALLOCATED;
696 1.1.4.2 rmind
697 1.1.4.2 rmind return 0;
698 1.1.4.2 rmind }
699 1.1.4.2 rmind
700 1.1.4.2 rmind /*ARGSUSED*/
701 1.1.4.2 rmind static void
702 1.1.4.2 rmind shpcmcia_chip_io_free(pcmcia_chipset_handle_t pch,
703 1.1.4.2 rmind struct pcmcia_io_handle *pih)
704 1.1.4.2 rmind {
705 1.1.4.2 rmind
706 1.1.4.2 rmind DPRINTF(("%s\n", __func__));
707 1.1.4.2 rmind }
708 1.1.4.2 rmind
709 1.1.4.2 rmind /*ARGSUSED*/
710 1.1.4.2 rmind static int
711 1.1.4.2 rmind shpcmcia_chip_io_map(pcmcia_chipset_handle_t pch, int width,
712 1.1.4.2 rmind bus_addr_t card_addr, bus_size_t size, struct pcmcia_io_handle *pihp,
713 1.1.4.2 rmind int *windowp)
714 1.1.4.2 rmind {
715 1.1.4.2 rmind struct shpcmcia_handle *h = (struct shpcmcia_handle *)pch;
716 1.1.4.2 rmind struct shpcmcia_softc *sc = h->sc;
717 1.1.4.2 rmind bus_addr_t ioaddr = pihp->addr + card_addr;
718 1.1.4.2 rmind int win;
719 1.1.4.2 rmind int i;
720 1.1.4.2 rmind int s;
721 1.1.4.2 rmind
722 1.1.4.2 rmind DPRINTF(("%s\n", __func__));
723 1.1.4.2 rmind
724 1.1.4.2 rmind s = splbio();
725 1.1.4.2 rmind win = -1;
726 1.1.4.2 rmind for (i = 0; i < SHPCMCIA_IO_WINS; i++) {
727 1.1.4.2 rmind if ((h->ioalloc & (1 << i)) == 0) {
728 1.1.4.2 rmind win = i;
729 1.1.4.2 rmind h->ioalloc |= (1 << i);
730 1.1.4.2 rmind break;
731 1.1.4.2 rmind }
732 1.1.4.2 rmind }
733 1.1.4.2 rmind splx(s);
734 1.1.4.2 rmind if (win == -1)
735 1.1.4.2 rmind return 1;
736 1.1.4.2 rmind
737 1.1.4.2 rmind *windowp = win;
738 1.1.4.2 rmind
739 1.1.4.2 rmind /* XXX: IOS16 */
740 1.1.4.2 rmind
741 1.1.4.2 rmind aprint_normal_dev(sc->sc_dev, "port 0x%0lx", (u_long)ioaddr);
742 1.1.4.2 rmind if (size > 1)
743 1.1.4.2 rmind aprint_normal("-0x%lx", (u_long) ioaddr + (u_long) size - 1);
744 1.1.4.2 rmind aprint_normal("\n");
745 1.1.4.2 rmind
746 1.1.4.2 rmind h->io[win].addr = ioaddr;
747 1.1.4.2 rmind h->io[win].size = size;
748 1.1.4.2 rmind h->io[win].width = width;
749 1.1.4.2 rmind
750 1.1.4.2 rmind return 0;
751 1.1.4.2 rmind }
752 1.1.4.2 rmind
753 1.1.4.2 rmind /*ARGSUSED*/
754 1.1.4.2 rmind static void
755 1.1.4.2 rmind shpcmcia_chip_io_unmap(pcmcia_chipset_handle_t pch, int window)
756 1.1.4.2 rmind {
757 1.1.4.2 rmind struct shpcmcia_handle *h = (struct shpcmcia_handle *)pch;
758 1.1.4.2 rmind int s;
759 1.1.4.2 rmind
760 1.1.4.2 rmind DPRINTF(("%s\n", __func__));
761 1.1.4.2 rmind
762 1.1.4.2 rmind s = splbio();
763 1.1.4.2 rmind h->ioalloc &= ~(1 << window);
764 1.1.4.2 rmind splx(s);
765 1.1.4.2 rmind }
766 1.1.4.2 rmind
767 1.1.4.2 rmind /* Interrupt functions. */
768 1.1.4.2 rmind static void *
769 1.1.4.2 rmind shpcmcia_chip_intr_establish(pcmcia_chipset_handle_t pch,
770 1.1.4.2 rmind struct pcmcia_function *pf, int ipl, int (*ih_func)(void *), void *ih_arg)
771 1.1.4.2 rmind {
772 1.1.4.2 rmind struct shpcmcia_handle *h = (struct shpcmcia_handle *)pch;
773 1.1.4.2 rmind struct shpcmcia_softc *sc = h->sc;
774 1.1.4.2 rmind int s;
775 1.1.4.2 rmind
776 1.1.4.2 rmind KASSERT(sc->sc_ih == NULL);
777 1.1.4.2 rmind DPRINTF(("%s\n", __func__));
778 1.1.4.2 rmind
779 1.1.4.2 rmind s = splhigh();
780 1.1.4.2 rmind sc->sc_ih = extintr_establish(EXTINTR_INTR_CFIREQ, IST_LEVEL, ipl,
781 1.1.4.2 rmind ih_func, ih_arg);
782 1.1.4.2 rmind if (sc->sc_ih == NULL) {
783 1.1.4.2 rmind aprint_error_dev(sc->sc_dev,
784 1.1.4.2 rmind "couldn't establish card interrupt\n");
785 1.1.4.2 rmind }
786 1.1.4.2 rmind splx(s);
787 1.1.4.2 rmind
788 1.1.4.2 rmind return sc->sc_ih;
789 1.1.4.2 rmind }
790 1.1.4.2 rmind
791 1.1.4.2 rmind static void
792 1.1.4.2 rmind shpcmcia_chip_intr_disestablish(pcmcia_chipset_handle_t pch, void *cookie)
793 1.1.4.2 rmind {
794 1.1.4.2 rmind struct shpcmcia_handle *h = (struct shpcmcia_handle *)pch;
795 1.1.4.2 rmind struct shpcmcia_softc *sc = h->sc;
796 1.1.4.2 rmind int s;
797 1.1.4.2 rmind
798 1.1.4.2 rmind KASSERT(sc->sc_ih != NULL);
799 1.1.4.2 rmind DPRINTF(("%s\n", __func__));
800 1.1.4.2 rmind
801 1.1.4.2 rmind s = splhigh();
802 1.1.4.2 rmind extintr_disestablish(sc->sc_ih);
803 1.1.4.2 rmind sc->sc_ih = NULL;
804 1.1.4.2 rmind splx(s);
805 1.1.4.2 rmind }
806 1.1.4.2 rmind
807 1.1.4.2 rmind /* Socket functions. */
808 1.1.4.2 rmind static void
809 1.1.4.2 rmind shpcmcia_chip_socket_enable(pcmcia_chipset_handle_t pch)
810 1.1.4.2 rmind {
811 1.1.4.2 rmind uint16_t reg;
812 1.1.4.2 rmind
813 1.1.4.2 rmind DPRINTF(("%s\n", __func__));
814 1.1.4.2 rmind
815 1.1.4.2 rmind /* power on the card */
816 1.1.4.2 rmind reg = _reg_read_2(SH4_PDTRA);
817 1.1.4.2 rmind reg &= ~(1 << GPIO_PIN_CARD_PON);
818 1.1.4.2 rmind _reg_write_2(SH4_PDTRA, reg);
819 1.1.4.2 rmind
820 1.1.4.2 rmind /* wait for card ready */
821 1.1.4.2 rmind while (_reg_read_1(EXTINTR_STAT1) & MASK1_INT12)
822 1.1.4.2 rmind continue;
823 1.1.4.2 rmind
824 1.1.4.2 rmind /* enable bus buffer */
825 1.1.4.2 rmind reg = _reg_read_2(SH4_PDTRA);
826 1.1.4.2 rmind reg &= ~(1 << GPIO_PIN_CARD_ENABLE);
827 1.1.4.2 rmind _reg_write_2(SH4_PDTRA, reg);
828 1.1.4.2 rmind
829 1.1.4.2 rmind /* reset the card */
830 1.1.4.2 rmind reg = _reg_read_2(SH4_PDTRA);
831 1.1.4.2 rmind reg &= ~(1 << GPIO_PIN_CARD_RESET);
832 1.1.4.2 rmind _reg_write_2(SH4_PDTRA, reg);
833 1.1.4.2 rmind delay(100 * 1000);
834 1.1.4.2 rmind }
835 1.1.4.2 rmind
836 1.1.4.2 rmind /*ARGSUSED*/
837 1.1.4.2 rmind static void
838 1.1.4.2 rmind shpcmcia_chip_socket_disable(pcmcia_chipset_handle_t pch)
839 1.1.4.2 rmind {
840 1.1.4.2 rmind uint16_t reg;
841 1.1.4.2 rmind
842 1.1.4.2 rmind DPRINTF(("%s\n", __func__));
843 1.1.4.2 rmind
844 1.1.4.2 rmind /* reset the card */
845 1.1.4.2 rmind reg = _reg_read_2(SH4_PDTRA);
846 1.1.4.2 rmind reg |= (1 << GPIO_PIN_CARD_RESET);
847 1.1.4.2 rmind _reg_write_2(SH4_PDTRA, reg);
848 1.1.4.2 rmind
849 1.1.4.2 rmind /* power off the card */
850 1.1.4.2 rmind reg = _reg_read_2(SH4_PDTRA);
851 1.1.4.2 rmind reg |= (1 << GPIO_PIN_CARD_PON);
852 1.1.4.2 rmind _reg_write_2(SH4_PDTRA, reg);
853 1.1.4.2 rmind
854 1.1.4.2 rmind /* disable bus buffer */
855 1.1.4.2 rmind reg = _reg_read_2(SH4_PDTRA);
856 1.1.4.2 rmind reg |= (1 << GPIO_PIN_CARD_ENABLE);
857 1.1.4.2 rmind _reg_write_2(SH4_PDTRA, reg);
858 1.1.4.2 rmind }
859 1.1.4.2 rmind
860 1.1.4.2 rmind /*ARGSUSED*/
861 1.1.4.2 rmind static void
862 1.1.4.2 rmind shpcmcia_chip_socket_settype(pcmcia_chipset_handle_t pch, int type)
863 1.1.4.2 rmind {
864 1.1.4.2 rmind
865 1.1.4.2 rmind DPRINTF(("%s\n", __func__));
866 1.1.4.2 rmind }
867