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