at91cf.c revision 1.5 1 1.5 chs /* $Id: at91cf.c,v 1.5 2019/11/10 21:16:23 chs Exp $ */
2 1.5 chs /* $NetBSD: at91cf.c,v 1.5 2019/11/10 21:16:23 chs Exp $ */
3 1.2 matt
4 1.2 matt /*
5 1.2 matt * Copyright (c) 2007 Embedtronics Oy. All rights reserved.
6 1.2 matt *
7 1.2 matt * Based on arch/evbarm/ep93xx/eppcic.c,
8 1.2 matt * Copyright (c) 2005 HAMAJIMA Katsuomi. All rights reserved.
9 1.2 matt *
10 1.2 matt * Redistribution and use in source and binary forms, with or without
11 1.2 matt * modification, are permitted provided that the following conditions
12 1.2 matt * are met:
13 1.2 matt * 1. Redistributions of source code must retain the above copyright
14 1.2 matt * notice, this list of conditions and the following disclaimer.
15 1.2 matt * 2. Redistributions in binary form must reproduce the above copyright
16 1.2 matt * notice, this list of conditions and the following disclaimer in the
17 1.2 matt * documentation and/or other materials provided with the distribution.
18 1.2 matt *
19 1.2 matt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 1.2 matt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.2 matt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.2 matt * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 1.2 matt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.2 matt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.2 matt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.2 matt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.2 matt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.2 matt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.2 matt * SUCH DAMAGE.
30 1.2 matt */
31 1.2 matt
32 1.2 matt #include <sys/cdefs.h>
33 1.5 chs __KERNEL_RCSID(0, "$NetBSD: at91cf.c,v 1.5 2019/11/10 21:16:23 chs Exp $");
34 1.2 matt
35 1.2 matt #include <sys/param.h>
36 1.2 matt #include <sys/systm.h>
37 1.2 matt #include <sys/kernel.h>
38 1.2 matt #include <sys/malloc.h>
39 1.2 matt #include <sys/device.h>
40 1.2 matt #include <sys/kthread.h>
41 1.2 matt #include <uvm/uvm_param.h>
42 1.3 dyoung #include <sys/bus.h>
43 1.2 matt #include <dev/pcmcia/pcmciareg.h>
44 1.2 matt #include <dev/pcmcia/pcmciavar.h>
45 1.2 matt #include <dev/pcmcia/pcmciachip.h>
46 1.2 matt #include <arm/at91/at91reg.h>
47 1.2 matt #include <arm/at91/at91var.h>
48 1.2 matt #include <arm/at91/at91cfvar.h>
49 1.2 matt
50 1.2 matt #include "at91pio.h"
51 1.2 matt #if NAT91PIO == 0
52 1.2 matt #error "at91cf requires at91pio"
53 1.2 matt #endif
54 1.2 matt
55 1.2 matt #ifdef AT91CF_DEBUG
56 1.2 matt int at91cf_debug = AT91CF_DEBUG;
57 1.2 matt #define DPRINTFN(n,x) if (at91cf_debug>(n)) printf x;
58 1.2 matt #else
59 1.2 matt #define DPRINTFN(n,x)
60 1.2 matt #endif
61 1.2 matt
62 1.2 matt struct at91cf_handle {
63 1.2 matt struct at91cf_softc *ph_sc;
64 1.2 matt device_t ph_card;
65 1.2 matt int (*ph_ih_func)(void *);
66 1.2 matt void *ph_ih_arg;
67 1.2 matt lwp_t *ph_event_thread;
68 1.2 matt int ph_type; /* current access type */
69 1.2 matt int ph_run; /* kthread running */
70 1.2 matt int ph_width; /* 8 or 16 */
71 1.2 matt int ph_vcc; /* 3 or 5 */
72 1.2 matt int ph_status; /* combined cd1 and cd2 */
73 1.2 matt struct {
74 1.2 matt bus_size_t reg;
75 1.2 matt bus_addr_t base;
76 1.2 matt bus_size_t size;
77 1.2 matt } ph_space[3];
78 1.2 matt #define IO 0
79 1.2 matt #define COMMON 1
80 1.2 matt #define ATTRIBUTE 2
81 1.2 matt };
82 1.2 matt
83 1.2 matt static int at91cf_intr_carddetect(void *);
84 1.2 matt static int at91cf_intr_socket(void *);
85 1.2 matt static int at91cf_print(void *, const char *);
86 1.2 matt static void at91cf_create_event_thread(void *);
87 1.2 matt static void at91cf_event_thread(void *);
88 1.2 matt void at91cf_shutdown(void *);
89 1.2 matt
90 1.2 matt static int at91cf_mem_alloc(pcmcia_chipset_handle_t, bus_size_t,
91 1.2 matt struct pcmcia_mem_handle *);
92 1.2 matt static void at91cf_mem_free(pcmcia_chipset_handle_t,
93 1.2 matt struct pcmcia_mem_handle *);
94 1.2 matt static int at91cf_mem_map(pcmcia_chipset_handle_t, int, bus_addr_t, bus_size_t,
95 1.2 matt struct pcmcia_mem_handle *, bus_size_t *, int *);
96 1.2 matt static void at91cf_mem_unmap(pcmcia_chipset_handle_t, int);
97 1.2 matt static int at91cf_io_alloc(pcmcia_chipset_handle_t, bus_addr_t, bus_size_t,
98 1.2 matt bus_size_t, struct pcmcia_io_handle *);
99 1.2 matt static void at91cf_io_free(pcmcia_chipset_handle_t, struct pcmcia_io_handle *);
100 1.2 matt static int at91cf_io_map(pcmcia_chipset_handle_t, int, bus_addr_t, bus_size_t,
101 1.2 matt struct pcmcia_io_handle *, int *);
102 1.2 matt static void at91cf_io_unmap(pcmcia_chipset_handle_t, int);
103 1.2 matt static void *at91cf_intr_establish(pcmcia_chipset_handle_t,
104 1.2 matt struct pcmcia_function *,
105 1.2 matt int, int (*)(void *), void *);
106 1.2 matt static void at91cf_intr_disestablish(pcmcia_chipset_handle_t, void *);
107 1.2 matt static void at91cf_socket_enable(pcmcia_chipset_handle_t);
108 1.2 matt static void at91cf_socket_disable(pcmcia_chipset_handle_t);
109 1.2 matt static void at91cf_socket_settype(pcmcia_chipset_handle_t, int);
110 1.2 matt
111 1.2 matt static void at91cf_attach_socket(struct at91cf_handle *);
112 1.2 matt static void at91cf_config_socket(struct at91cf_handle *);
113 1.2 matt //static int at91cf_get_voltage(struct at91cf_handle *);
114 1.2 matt
115 1.2 matt static struct pcmcia_chip_functions at91cf_functions = {
116 1.2 matt at91cf_mem_alloc, at91cf_mem_free,
117 1.2 matt at91cf_mem_map, at91cf_mem_unmap,
118 1.2 matt at91cf_io_alloc, at91cf_io_free,
119 1.2 matt at91cf_io_map, at91cf_io_unmap,
120 1.2 matt at91cf_intr_establish, at91cf_intr_disestablish,
121 1.2 matt at91cf_socket_enable, at91cf_socket_disable,
122 1.2 matt at91cf_socket_settype
123 1.2 matt };
124 1.2 matt
125 1.2 matt #define MEMORY_BASE 0
126 1.2 matt #define MEMORY_SIZE 0x1000
127 1.2 matt #define COMMON_BASE 0x400000
128 1.2 matt #define COMMON_SIZE 0x1000
129 1.2 matt #define IO_BASE 0x800000
130 1.2 matt #define IO_SIZE 0x1000
131 1.2 matt #define MIN_SIZE (IO_BASE + IO_SIZE)
132 1.2 matt
133 1.2 matt void
134 1.2 matt at91cf_attach_common(device_t parent, device_t self, void *aux,
135 1.2 matt at91cf_chipset_tag_t cscf)
136 1.2 matt {
137 1.2 matt struct at91cf_softc *sc = device_private(self);
138 1.2 matt struct at91bus_attach_args *sa = aux;
139 1.2 matt struct at91cf_handle *ph;
140 1.2 matt
141 1.2 matt if (sa->sa_size < MIN_SIZE) {
142 1.2 matt printf("%s: it's not possible to map registers\n",
143 1.2 matt device_xname(self));
144 1.2 matt return;
145 1.2 matt }
146 1.2 matt
147 1.2 matt sc->sc_dev = self;
148 1.2 matt sc->sc_iot = sa->sa_iot;
149 1.2 matt sc->sc_cscf = cscf;
150 1.2 matt sc->sc_enable = 0;
151 1.2 matt
152 1.2 matt if (bus_space_map(sa->sa_iot, sa->sa_addr + MEMORY_BASE,
153 1.2 matt MEMORY_SIZE, 0, &sc->sc_memory_ioh)){
154 1.2 matt printf("%s: Cannot map memory space\n", device_xname(self));
155 1.2 matt return;
156 1.2 matt }
157 1.2 matt
158 1.2 matt if (bus_space_map(sa->sa_iot, sa->sa_addr + COMMON_BASE,
159 1.2 matt COMMON_SIZE, 0, &sc->sc_common_ioh)){
160 1.2 matt printf("%s: Cannot map common memory space\n",
161 1.2 matt device_xname(self));
162 1.2 matt bus_space_unmap(sa->sa_iot, sc->sc_memory_ioh, MEMORY_SIZE);
163 1.2 matt return;
164 1.2 matt }
165 1.2 matt
166 1.2 matt if (bus_space_map(sa->sa_iot, sa->sa_addr + IO_BASE,
167 1.2 matt IO_SIZE, 0, &sc->sc_io_ioh)){
168 1.2 matt printf("%s: Cannot map I/O space\n", device_xname(self));
169 1.2 matt bus_space_unmap(sa->sa_iot, sc->sc_memory_ioh, MEMORY_SIZE);
170 1.2 matt bus_space_unmap(sa->sa_iot, sc->sc_common_ioh, COMMON_SIZE);
171 1.2 matt return;
172 1.2 matt }
173 1.2 matt
174 1.2 matt printf("\n");
175 1.2 matt
176 1.2 matt /* socket 0 */
177 1.5 chs ph = malloc(sizeof(struct at91cf_handle), M_DEVBUF, M_WAITOK|M_ZERO);
178 1.2 matt sc->sc_ph = ph;
179 1.2 matt ph->ph_sc = sc;
180 1.2 matt ph->ph_space[IO].base = sa->sa_addr + IO_BASE;
181 1.2 matt ph->ph_space[IO].size = IO_SIZE;
182 1.2 matt ph->ph_space[COMMON].base = sa->sa_addr + COMMON_BASE;
183 1.2 matt ph->ph_space[COMMON].size = COMMON_SIZE;
184 1.2 matt ph->ph_space[ATTRIBUTE].base = sa->sa_addr + MEMORY_BASE;
185 1.2 matt ph->ph_space[ATTRIBUTE].size = MEMORY_SIZE;
186 1.2 matt at91cf_attach_socket(ph);
187 1.2 matt
188 1.2 matt // @@@ reset CF now? @@@@
189 1.2 matt
190 1.2 matt at91cf_config_socket(sc->sc_ph);
191 1.2 matt }
192 1.2 matt
193 1.2 matt static void
194 1.2 matt at91cf_attach_socket(struct at91cf_handle *ph)
195 1.2 matt {
196 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
197 1.2 matt at91cf_chipset_tag_t cscf = sc->sc_cscf;
198 1.2 matt int wait;
199 1.2 matt
200 1.2 matt ph->ph_width = 16;
201 1.2 matt ph->ph_vcc = 3;
202 1.2 matt ph->ph_event_thread = NULL;
203 1.2 matt ph->ph_run = 0;
204 1.2 matt ph->ph_ih_func = NULL;
205 1.2 matt ph->ph_ih_arg = NULL;
206 1.2 matt
207 1.2 matt ph->ph_status = (*cscf->card_detect)(sc);
208 1.2 matt
209 1.2 matt wait = (cscf->power_ctl)(sc, POWER_OFF);
210 1.2 matt delay(wait);
211 1.2 matt wait = (cscf->power_ctl)(sc, POWER_ON);
212 1.2 matt delay(wait);
213 1.2 matt }
214 1.2 matt
215 1.2 matt static void
216 1.2 matt at91cf_config_socket(struct at91cf_handle *ph)
217 1.2 matt {
218 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
219 1.2 matt at91cf_chipset_tag_t cscf = sc->sc_cscf;
220 1.2 matt struct pcmciabus_attach_args paa;
221 1.2 matt int wait;
222 1.2 matt
223 1.2 matt paa.paa_busname = "pcmcia";
224 1.2 matt paa.pct = (pcmcia_chipset_tag_t)&at91cf_functions;
225 1.2 matt paa.pch = (pcmcia_chipset_handle_t)ph;
226 1.2 matt ph->ph_card = config_found_ia(sc->sc_dev, "pcmciabus", &paa,
227 1.2 matt at91cf_print);
228 1.2 matt
229 1.2 matt (*cscf->intr_establish)(sc, CD_IRQ, IPL_BIO, at91cf_intr_carddetect, ph);
230 1.2 matt wait = (*cscf->power_ctl)(sc, POWER_OFF);
231 1.2 matt delay(wait);
232 1.2 matt
233 1.2 matt kthread_create(PRI_NONE, 0, NULL, at91cf_create_event_thread, ph,
234 1.2 matt &ph->ph_event_thread, "%s", device_xname(sc->sc_dev));
235 1.2 matt }
236 1.2 matt
237 1.2 matt static int
238 1.2 matt at91cf_print(void *arg, const char *pnp)
239 1.2 matt {
240 1.2 matt return (UNCONF);
241 1.2 matt }
242 1.2 matt
243 1.2 matt static void
244 1.2 matt at91cf_create_event_thread(void *arg)
245 1.2 matt {
246 1.2 matt struct at91cf_handle *ph = arg;
247 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
248 1.2 matt at91cf_chipset_tag_t cscf = sc->sc_cscf;
249 1.2 matt
250 1.2 matt ph->ph_status = (*cscf->card_detect)(sc);
251 1.2 matt
252 1.2 matt DPRINTFN(1, ("at91cf_create_event_thread: status=%d\n", ph->ph_status));
253 1.2 matt
254 1.2 matt if (ph->ph_status)
255 1.2 matt pcmcia_card_attach(ph->ph_card);
256 1.2 matt
257 1.2 matt ph->ph_run = 1;
258 1.2 matt kthread_create(PRI_NONE, 0, NULL, at91cf_event_thread, ph,
259 1.2 matt &ph->ph_event_thread, "%s", device_xname(sc->sc_dev));
260 1.2 matt }
261 1.2 matt
262 1.2 matt static void
263 1.2 matt at91cf_event_thread(void *arg)
264 1.2 matt {
265 1.2 matt struct at91cf_handle *ph = arg;
266 1.2 matt int status;
267 1.2 matt
268 1.2 matt for (;;) {
269 1.2 matt status = ph->ph_status;
270 1.2 matt tsleep(ph, PWAIT, "CSC wait", 0);
271 1.2 matt if (!ph->ph_run)
272 1.2 matt break;
273 1.2 matt
274 1.2 matt DPRINTFN(1, ("at91cf_event_thread: old status=%d, new status=%d\n", status, ph->ph_status));
275 1.2 matt
276 1.2 matt if (!status && ph->ph_status)
277 1.2 matt pcmcia_card_attach(ph->ph_card);
278 1.2 matt else if (status && !ph->ph_status)
279 1.2 matt pcmcia_card_detach(ph->ph_card, DETACH_FORCE);
280 1.2 matt }
281 1.2 matt
282 1.2 matt DPRINTFN(1, ("at91cf_event_thread: run=%d\n",ph->ph_run));
283 1.2 matt ph->ph_event_thread = NULL;
284 1.2 matt kthread_exit(0);
285 1.2 matt }
286 1.2 matt
287 1.2 matt void
288 1.2 matt at91cf_shutdown(void *arg)
289 1.2 matt {
290 1.2 matt struct at91cf_handle *ph = arg;
291 1.2 matt
292 1.2 matt DPRINTFN(1, ("at91cf_shutdown\n"));
293 1.2 matt ph->ph_run = 0;
294 1.2 matt wakeup(ph);
295 1.2 matt }
296 1.2 matt
297 1.2 matt static int
298 1.2 matt at91cf_intr_carddetect(void *arg)
299 1.2 matt {
300 1.2 matt struct at91cf_handle *ph = arg;
301 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
302 1.2 matt at91cf_chipset_tag_t cscf = sc->sc_cscf;
303 1.2 matt int nstatus;
304 1.2 matt
305 1.2 matt nstatus = (*cscf->card_detect)(sc);
306 1.2 matt
307 1.2 matt DPRINTFN(1, ("at91cf_intr: nstatus=%#x, ostatus=%#x\n", nstatus, ph->ph_status));
308 1.2 matt
309 1.2 matt if (nstatus != ph->ph_status) {
310 1.2 matt ph->ph_status = nstatus;
311 1.2 matt wakeup(ph);
312 1.2 matt }
313 1.2 matt
314 1.2 matt return 0;
315 1.2 matt }
316 1.2 matt
317 1.2 matt static int
318 1.2 matt at91cf_mem_alloc(pcmcia_chipset_handle_t pch, bus_size_t size,
319 1.2 matt struct pcmcia_mem_handle *pmh)
320 1.2 matt {
321 1.2 matt struct at91cf_handle *ph = (struct at91cf_handle *)pch;
322 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
323 1.2 matt
324 1.2 matt DPRINTFN(1, ("at91cf_mem_alloc: size=%#x\n",(unsigned)size));
325 1.2 matt
326 1.2 matt pmh->memt = sc->sc_iot;
327 1.2 matt return 0;
328 1.2 matt }
329 1.2 matt
330 1.2 matt static void
331 1.2 matt at91cf_mem_free(pcmcia_chipset_handle_t pch, struct pcmcia_mem_handle *pmh)
332 1.2 matt {
333 1.2 matt DPRINTFN(1, ("at91cf_mem_free\n"));
334 1.2 matt }
335 1.2 matt
336 1.2 matt static int
337 1.2 matt at91cf_mem_map(pcmcia_chipset_handle_t pch, int kind, bus_addr_t addr,
338 1.2 matt bus_size_t size, struct pcmcia_mem_handle *pmh,
339 1.2 matt bus_size_t *offsetp, int *windowp)
340 1.2 matt {
341 1.2 matt struct at91cf_handle *ph = (struct at91cf_handle *)pch;
342 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
343 1.2 matt bus_addr_t pa;
344 1.2 matt int err;
345 1.2 matt
346 1.2 matt DPRINTFN(1, ("at91cf_mem_map: kind=%d, addr=%#x, size=%#x\n",kind,(unsigned)addr,(unsigned)size));
347 1.2 matt
348 1.2 matt pa = addr;
349 1.2 matt *offsetp = 0;
350 1.2 matt size = round_page(size);
351 1.2 matt pmh->realsize = size;
352 1.2 matt if (kind & PCMCIA_WIDTH_MEM8)
353 1.2 matt ph->ph_width = 8;
354 1.2 matt else
355 1.2 matt ph->ph_width = 16;
356 1.2 matt switch (kind & ~PCMCIA_WIDTH_MEM_MASK) {
357 1.2 matt case PCMCIA_MEM_ATTR:
358 1.2 matt pa += ph->ph_space[ATTRIBUTE].base;
359 1.2 matt break;
360 1.2 matt case PCMCIA_MEM_COMMON:
361 1.2 matt pa += ph->ph_space[COMMON].base;
362 1.2 matt break;
363 1.2 matt default:
364 1.2 matt return -1;
365 1.2 matt }
366 1.2 matt
367 1.2 matt DPRINTFN(1, ("at91cf_mem_map: pa=%#x, *offsetp=%#x, size=%#x\n",(unsigned)pa,(unsigned)addr,(unsigned)size));
368 1.2 matt
369 1.2 matt if (!(err = bus_space_map(sc->sc_iot, pa, size, 0, &pmh->memh)))
370 1.2 matt *windowp = (int)pmh->memh;
371 1.2 matt return err;
372 1.2 matt }
373 1.2 matt
374 1.2 matt static void
375 1.2 matt at91cf_mem_unmap(pcmcia_chipset_handle_t pch, int window)
376 1.2 matt {
377 1.2 matt struct at91cf_handle *ph = (struct at91cf_handle *)pch;
378 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
379 1.2 matt
380 1.2 matt DPRINTFN(1, ("at91cf_mem_unmap: window=%#x\n",window));
381 1.2 matt
382 1.2 matt bus_space_unmap(sc->sc_iot, (bus_addr_t)window, 0x1000);
383 1.2 matt }
384 1.2 matt
385 1.2 matt static int
386 1.2 matt at91cf_io_alloc(pcmcia_chipset_handle_t pch, bus_addr_t start, bus_size_t size,
387 1.2 matt bus_size_t align, struct pcmcia_io_handle *pih)
388 1.2 matt {
389 1.2 matt struct at91cf_handle *ph = (struct at91cf_handle *)pch;
390 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
391 1.2 matt bus_addr_t pa;
392 1.2 matt
393 1.2 matt DPRINTFN(1, ("at91cf_io_alloc: start=%#x, size=%#x, align=%#x\n",(unsigned)start,(unsigned)size,(unsigned)align));
394 1.2 matt
395 1.2 matt pih->iot = sc->sc_iot;
396 1.2 matt pih->addr = start;
397 1.2 matt pih->size = size;
398 1.2 matt pa = pih->addr + ph->ph_space[IO].base;
399 1.2 matt return bus_space_map(sc->sc_iot, pa, size, 0, &pih->ioh);
400 1.2 matt }
401 1.2 matt
402 1.2 matt static void
403 1.2 matt at91cf_io_free(pcmcia_chipset_handle_t pch, struct pcmcia_io_handle *pih)
404 1.2 matt {
405 1.2 matt struct at91cf_handle *ph = (struct at91cf_handle *)pch;
406 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
407 1.2 matt
408 1.2 matt DPRINTFN(1, ("at91cf_io_free\n"));
409 1.2 matt
410 1.2 matt bus_space_unmap(sc->sc_iot, pih->ioh, pih->size);
411 1.2 matt }
412 1.2 matt
413 1.2 matt static int
414 1.2 matt at91cf_io_map(pcmcia_chipset_handle_t pch, int width, bus_addr_t offset,
415 1.2 matt bus_size_t size, struct pcmcia_io_handle *pih, int *windowp)
416 1.2 matt {
417 1.2 matt struct at91cf_handle *ph = (struct at91cf_handle *)pch;
418 1.2 matt
419 1.2 matt DPRINTFN(1, ("at91cf_io_map: offset=%#x, size=%#x, width=%d",(unsigned)offset,(unsigned)size,width));
420 1.2 matt
421 1.2 matt switch (width) {
422 1.2 matt case PCMCIA_WIDTH_IO8:
423 1.2 matt DPRINTFN(1, ("(8bit)\n"));
424 1.2 matt ph->ph_width = 8;
425 1.2 matt break;
426 1.2 matt case PCMCIA_WIDTH_IO16:
427 1.2 matt case PCMCIA_WIDTH_AUTO: /* I don't understand how I check it */
428 1.2 matt DPRINTFN(1, ("(16bit)\n"));
429 1.2 matt ph->ph_width = 16;
430 1.2 matt break;
431 1.2 matt default:
432 1.2 matt DPRINTFN(1, ("(unknown)\n"));
433 1.2 matt return -1;
434 1.2 matt }
435 1.2 matt *windowp = 0; /* unused */
436 1.2 matt return 0;
437 1.2 matt }
438 1.2 matt
439 1.2 matt static void
440 1.2 matt at91cf_io_unmap(pcmcia_chipset_handle_t pch, int window)
441 1.2 matt {
442 1.2 matt DPRINTFN(1, ("at91cf_io_unmap: window=%#x\n",window));
443 1.2 matt }
444 1.2 matt
445 1.2 matt static void *
446 1.2 matt at91cf_intr_establish(pcmcia_chipset_handle_t pch, struct pcmcia_function *pf,
447 1.2 matt int ipl, int (*ih_func)(void *), void *ih_arg)
448 1.2 matt {
449 1.2 matt struct at91cf_handle *ph = (struct at91cf_handle *)pch;
450 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
451 1.2 matt at91cf_chipset_tag_t cscf = sc->sc_cscf;
452 1.2 matt
453 1.2 matt DPRINTFN(1, ("at91cf_intr_establish\n"));
454 1.2 matt
455 1.2 matt if (ph->ph_ih_func)
456 1.2 matt return 0;
457 1.2 matt
458 1.2 matt ph->ph_ih_func = ih_func;
459 1.2 matt ph->ph_ih_arg = ih_arg;
460 1.2 matt
461 1.2 matt return (*cscf->intr_establish)(sc, CF_IRQ, ipl, at91cf_intr_socket, ph);
462 1.2 matt // return (*cscf->intr_establish)(sc, CF_IRQ, ipl, ih_func, ih_arg);
463 1.2 matt }
464 1.2 matt
465 1.2 matt static void
466 1.2 matt at91cf_intr_disestablish(pcmcia_chipset_handle_t pch, void *ih)
467 1.2 matt {
468 1.2 matt struct at91cf_handle *ph = (struct at91cf_handle *)pch;
469 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
470 1.2 matt at91cf_chipset_tag_t cscf = sc->sc_cscf;
471 1.2 matt
472 1.2 matt DPRINTFN(1, ("at91cf_intr_disestablish\n"));
473 1.2 matt
474 1.2 matt ph->ph_ih_func = NULL;
475 1.2 matt ph->ph_ih_arg = NULL;
476 1.2 matt
477 1.2 matt (*cscf->intr_disestablish)(sc, CF_IRQ, ih);
478 1.2 matt }
479 1.2 matt
480 1.2 matt static int
481 1.2 matt at91cf_intr_socket(void *arg)
482 1.2 matt {
483 1.2 matt struct at91cf_handle *ph = arg;
484 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
485 1.2 matt at91cf_chipset_tag_t cscf = sc->sc_cscf;
486 1.2 matt int err = 0, irq;
487 1.2 matt
488 1.2 matt if (ph->ph_ih_func) {
489 1.2 matt irq = (*cscf->irq_line)(sc);
490 1.2 matt if (ph->ph_type == PCMCIA_IFTYPE_IO)
491 1.2 matt irq = !irq;
492 1.2 matt if (irq)
493 1.2 matt err = (*ph->ph_ih_func)(ph->ph_ih_arg);
494 1.2 matt else
495 1.2 matt DPRINTFN(2,("%s: other edge ignored\n", __FUNCTION__));
496 1.2 matt }
497 1.2 matt
498 1.2 matt return err;
499 1.2 matt }
500 1.2 matt
501 1.2 matt static void
502 1.2 matt at91cf_socket_enable(pcmcia_chipset_handle_t pch)
503 1.2 matt {
504 1.2 matt struct at91cf_handle *ph = (struct at91cf_handle *)pch;
505 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
506 1.2 matt at91cf_chipset_tag_t cscf = sc->sc_cscf;
507 1.2 matt int wait;
508 1.2 matt
509 1.2 matt DPRINTFN(1, ("at91cf_socket_enable\n"));
510 1.2 matt
511 1.2 matt wait = (cscf->power_ctl)(sc, POWER_ON);
512 1.2 matt delay(wait);
513 1.2 matt }
514 1.2 matt
515 1.2 matt static void
516 1.2 matt at91cf_socket_disable(pcmcia_chipset_handle_t pch)
517 1.2 matt {
518 1.2 matt struct at91cf_handle *ph = (struct at91cf_handle *)pch;
519 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
520 1.2 matt at91cf_chipset_tag_t cscf = sc->sc_cscf;
521 1.2 matt int wait;
522 1.2 matt
523 1.2 matt DPRINTFN(1, ("at91cf_socket_disable\n"));
524 1.2 matt
525 1.2 matt wait = (cscf->power_ctl)(sc, POWER_OFF);
526 1.2 matt delay(wait);
527 1.2 matt }
528 1.2 matt
529 1.2 matt static void
530 1.2 matt at91cf_socket_settype(pcmcia_chipset_handle_t pch, int type)
531 1.2 matt {
532 1.2 matt struct at91cf_handle *ph = (struct at91cf_handle *)pch;
533 1.2 matt
534 1.2 matt DPRINTFN(1, ("at91cf_socket_settype: type=%d",type));
535 1.2 matt
536 1.2 matt ph->ph_type = type;
537 1.2 matt
538 1.2 matt switch (type) {
539 1.2 matt case PCMCIA_IFTYPE_MEMORY:
540 1.2 matt DPRINTFN(1, ("(Memory)\n"));
541 1.2 matt break;
542 1.2 matt case PCMCIA_IFTYPE_IO:
543 1.2 matt DPRINTFN(1, ("(I/O)\n"));
544 1.2 matt break;
545 1.2 matt default:
546 1.2 matt DPRINTFN(1, ("(unknown)\n"));
547 1.2 matt return;
548 1.2 matt }
549 1.2 matt }
550 1.2 matt
551 1.2 matt #if 0
552 1.2 matt static int
553 1.2 matt at91cf_get_voltage(struct at91cf_handle *ph)
554 1.2 matt {
555 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
556 1.2 matt at91cf_chipset_tag_t cscf = sc->sc_cscf;
557 1.2 matt int cap, vcc = 0;
558 1.2 matt
559 1.2 matt cap = (cscf->power_capability)(sc);
560 1.2 matt if (eppio_read(sc->sc_pio, ph->ph_port, ph->ph_vs[0])) {
561 1.2 matt if (cap | VCC_5V)
562 1.2 matt vcc = 5;
563 1.2 matt else
564 1.2 matt printf("%s: unsupported Vcc 5 Volts",
565 1.2 matt device_xname(sc->sc_dev));
566 1.2 matt } else {
567 1.2 matt if (cap | VCC_3V)
568 1.2 matt vcc = 3;
569 1.2 matt else
570 1.2 matt printf("%s: unsupported Vcc 3.3 Volts",
571 1.2 matt device_xname(sc->sc_dev));
572 1.2 matt }
573 1.2 matt DPRINTFN(1, ("at91cf_get_voltage: vs1=%d, vs2=%d (%dV)\n",eppio_read_bit(sc->sc_pio, ph->ph_port, ph->ph_vs[0]),eppio_read_bit(sc->sc_pio, ph->ph_port, ph->ph_vs[1]),vcc));
574 1.2 matt return vcc;
575 1.2 matt }
576 1.2 matt
577 1.2 matt #endif
578