at91cf.c revision 1.2 1 1.2 matt /* $Id: at91cf.c,v 1.2 2008/07/03 01:15:38 matt Exp $ */
2 1.2 matt /* $NetBSD: at91cf.c,v 1.2 2008/07/03 01:15:38 matt 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.2 matt __KERNEL_RCSID(0, "$NetBSD: at91cf.c,v 1.2 2008/07/03 01:15:38 matt 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.2 matt #include <machine/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.2 matt ph = malloc(sizeof(struct at91cf_handle), M_DEVBUF, M_NOWAIT|M_ZERO);
178 1.2 matt if (ph == NULL) {
179 1.2 matt printf("%s: Cannot allocate memory\n", device_xname(self));
180 1.2 matt // @@@@ unmap? @@@@
181 1.2 matt return; /* ENOMEM */
182 1.2 matt }
183 1.2 matt sc->sc_ph = ph;
184 1.2 matt ph->ph_sc = sc;
185 1.2 matt ph->ph_space[IO].base = sa->sa_addr + IO_BASE;
186 1.2 matt ph->ph_space[IO].size = IO_SIZE;
187 1.2 matt ph->ph_space[COMMON].base = sa->sa_addr + COMMON_BASE;
188 1.2 matt ph->ph_space[COMMON].size = COMMON_SIZE;
189 1.2 matt ph->ph_space[ATTRIBUTE].base = sa->sa_addr + MEMORY_BASE;
190 1.2 matt ph->ph_space[ATTRIBUTE].size = MEMORY_SIZE;
191 1.2 matt at91cf_attach_socket(ph);
192 1.2 matt
193 1.2 matt // @@@ reset CF now? @@@@
194 1.2 matt
195 1.2 matt at91cf_config_socket(sc->sc_ph);
196 1.2 matt }
197 1.2 matt
198 1.2 matt static void
199 1.2 matt at91cf_attach_socket(struct at91cf_handle *ph)
200 1.2 matt {
201 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
202 1.2 matt at91cf_chipset_tag_t cscf = sc->sc_cscf;
203 1.2 matt int wait;
204 1.2 matt
205 1.2 matt ph->ph_width = 16;
206 1.2 matt ph->ph_vcc = 3;
207 1.2 matt ph->ph_event_thread = NULL;
208 1.2 matt ph->ph_run = 0;
209 1.2 matt ph->ph_ih_func = NULL;
210 1.2 matt ph->ph_ih_arg = NULL;
211 1.2 matt
212 1.2 matt ph->ph_status = (*cscf->card_detect)(sc);
213 1.2 matt
214 1.2 matt wait = (cscf->power_ctl)(sc, POWER_OFF);
215 1.2 matt delay(wait);
216 1.2 matt wait = (cscf->power_ctl)(sc, POWER_ON);
217 1.2 matt delay(wait);
218 1.2 matt }
219 1.2 matt
220 1.2 matt static void
221 1.2 matt at91cf_config_socket(struct at91cf_handle *ph)
222 1.2 matt {
223 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
224 1.2 matt at91cf_chipset_tag_t cscf = sc->sc_cscf;
225 1.2 matt struct pcmciabus_attach_args paa;
226 1.2 matt int wait;
227 1.2 matt
228 1.2 matt paa.paa_busname = "pcmcia";
229 1.2 matt paa.pct = (pcmcia_chipset_tag_t)&at91cf_functions;
230 1.2 matt paa.pch = (pcmcia_chipset_handle_t)ph;
231 1.2 matt paa.iobase = ph->ph_space[IO].base;
232 1.2 matt paa.iosize = ph->ph_space[IO].size;
233 1.2 matt ph->ph_card = config_found_ia(sc->sc_dev, "pcmciabus", &paa,
234 1.2 matt at91cf_print);
235 1.2 matt
236 1.2 matt (*cscf->intr_establish)(sc, CD_IRQ, IPL_BIO, at91cf_intr_carddetect, ph);
237 1.2 matt wait = (*cscf->power_ctl)(sc, POWER_OFF);
238 1.2 matt delay(wait);
239 1.2 matt
240 1.2 matt kthread_create(PRI_NONE, 0, NULL, at91cf_create_event_thread, ph,
241 1.2 matt &ph->ph_event_thread, "%s", device_xname(sc->sc_dev));
242 1.2 matt }
243 1.2 matt
244 1.2 matt static int
245 1.2 matt at91cf_print(void *arg, const char *pnp)
246 1.2 matt {
247 1.2 matt return (UNCONF);
248 1.2 matt }
249 1.2 matt
250 1.2 matt static void
251 1.2 matt at91cf_create_event_thread(void *arg)
252 1.2 matt {
253 1.2 matt struct at91cf_handle *ph = arg;
254 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
255 1.2 matt at91cf_chipset_tag_t cscf = sc->sc_cscf;
256 1.2 matt
257 1.2 matt ph->ph_status = (*cscf->card_detect)(sc);
258 1.2 matt
259 1.2 matt DPRINTFN(1, ("at91cf_create_event_thread: status=%d\n", ph->ph_status));
260 1.2 matt
261 1.2 matt if (ph->ph_status)
262 1.2 matt pcmcia_card_attach(ph->ph_card);
263 1.2 matt
264 1.2 matt ph->ph_run = 1;
265 1.2 matt kthread_create(PRI_NONE, 0, NULL, at91cf_event_thread, ph,
266 1.2 matt &ph->ph_event_thread, "%s", device_xname(sc->sc_dev));
267 1.2 matt }
268 1.2 matt
269 1.2 matt static void
270 1.2 matt at91cf_event_thread(void *arg)
271 1.2 matt {
272 1.2 matt struct at91cf_handle *ph = arg;
273 1.2 matt int status;
274 1.2 matt
275 1.2 matt for (;;) {
276 1.2 matt status = ph->ph_status;
277 1.2 matt tsleep(ph, PWAIT, "CSC wait", 0);
278 1.2 matt if (!ph->ph_run)
279 1.2 matt break;
280 1.2 matt
281 1.2 matt DPRINTFN(1, ("at91cf_event_thread: old status=%d, new status=%d\n", status, ph->ph_status));
282 1.2 matt
283 1.2 matt if (!status && ph->ph_status)
284 1.2 matt pcmcia_card_attach(ph->ph_card);
285 1.2 matt else if (status && !ph->ph_status)
286 1.2 matt pcmcia_card_detach(ph->ph_card, DETACH_FORCE);
287 1.2 matt }
288 1.2 matt
289 1.2 matt DPRINTFN(1, ("at91cf_event_thread: run=%d\n",ph->ph_run));
290 1.2 matt ph->ph_event_thread = NULL;
291 1.2 matt kthread_exit(0);
292 1.2 matt }
293 1.2 matt
294 1.2 matt void
295 1.2 matt at91cf_shutdown(void *arg)
296 1.2 matt {
297 1.2 matt struct at91cf_handle *ph = arg;
298 1.2 matt
299 1.2 matt DPRINTFN(1, ("at91cf_shutdown\n"));
300 1.2 matt ph->ph_run = 0;
301 1.2 matt wakeup(ph);
302 1.2 matt }
303 1.2 matt
304 1.2 matt static int
305 1.2 matt at91cf_intr_carddetect(void *arg)
306 1.2 matt {
307 1.2 matt struct at91cf_handle *ph = arg;
308 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
309 1.2 matt at91cf_chipset_tag_t cscf = sc->sc_cscf;
310 1.2 matt int nstatus;
311 1.2 matt
312 1.2 matt nstatus = (*cscf->card_detect)(sc);
313 1.2 matt
314 1.2 matt DPRINTFN(1, ("at91cf_intr: nstatus=%#x, ostatus=%#x\n", nstatus, ph->ph_status));
315 1.2 matt
316 1.2 matt if (nstatus != ph->ph_status) {
317 1.2 matt ph->ph_status = nstatus;
318 1.2 matt wakeup(ph);
319 1.2 matt }
320 1.2 matt
321 1.2 matt return 0;
322 1.2 matt }
323 1.2 matt
324 1.2 matt static int
325 1.2 matt at91cf_mem_alloc(pcmcia_chipset_handle_t pch, bus_size_t size,
326 1.2 matt struct pcmcia_mem_handle *pmh)
327 1.2 matt {
328 1.2 matt struct at91cf_handle *ph = (struct at91cf_handle *)pch;
329 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
330 1.2 matt
331 1.2 matt DPRINTFN(1, ("at91cf_mem_alloc: size=%#x\n",(unsigned)size));
332 1.2 matt
333 1.2 matt pmh->memt = sc->sc_iot;
334 1.2 matt return 0;
335 1.2 matt }
336 1.2 matt
337 1.2 matt static void
338 1.2 matt at91cf_mem_free(pcmcia_chipset_handle_t pch, struct pcmcia_mem_handle *pmh)
339 1.2 matt {
340 1.2 matt DPRINTFN(1, ("at91cf_mem_free\n"));
341 1.2 matt }
342 1.2 matt
343 1.2 matt static int
344 1.2 matt at91cf_mem_map(pcmcia_chipset_handle_t pch, int kind, bus_addr_t addr,
345 1.2 matt bus_size_t size, struct pcmcia_mem_handle *pmh,
346 1.2 matt bus_size_t *offsetp, int *windowp)
347 1.2 matt {
348 1.2 matt struct at91cf_handle *ph = (struct at91cf_handle *)pch;
349 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
350 1.2 matt bus_addr_t pa;
351 1.2 matt int err;
352 1.2 matt
353 1.2 matt DPRINTFN(1, ("at91cf_mem_map: kind=%d, addr=%#x, size=%#x\n",kind,(unsigned)addr,(unsigned)size));
354 1.2 matt
355 1.2 matt pa = addr;
356 1.2 matt *offsetp = 0;
357 1.2 matt size = round_page(size);
358 1.2 matt pmh->realsize = size;
359 1.2 matt if (kind & PCMCIA_WIDTH_MEM8)
360 1.2 matt ph->ph_width = 8;
361 1.2 matt else
362 1.2 matt ph->ph_width = 16;
363 1.2 matt switch (kind & ~PCMCIA_WIDTH_MEM_MASK) {
364 1.2 matt case PCMCIA_MEM_ATTR:
365 1.2 matt pa += ph->ph_space[ATTRIBUTE].base;
366 1.2 matt break;
367 1.2 matt case PCMCIA_MEM_COMMON:
368 1.2 matt pa += ph->ph_space[COMMON].base;
369 1.2 matt break;
370 1.2 matt default:
371 1.2 matt return -1;
372 1.2 matt }
373 1.2 matt
374 1.2 matt DPRINTFN(1, ("at91cf_mem_map: pa=%#x, *offsetp=%#x, size=%#x\n",(unsigned)pa,(unsigned)addr,(unsigned)size));
375 1.2 matt
376 1.2 matt if (!(err = bus_space_map(sc->sc_iot, pa, size, 0, &pmh->memh)))
377 1.2 matt *windowp = (int)pmh->memh;
378 1.2 matt return err;
379 1.2 matt }
380 1.2 matt
381 1.2 matt static void
382 1.2 matt at91cf_mem_unmap(pcmcia_chipset_handle_t pch, int window)
383 1.2 matt {
384 1.2 matt struct at91cf_handle *ph = (struct at91cf_handle *)pch;
385 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
386 1.2 matt
387 1.2 matt DPRINTFN(1, ("at91cf_mem_unmap: window=%#x\n",window));
388 1.2 matt
389 1.2 matt bus_space_unmap(sc->sc_iot, (bus_addr_t)window, 0x1000);
390 1.2 matt }
391 1.2 matt
392 1.2 matt static int
393 1.2 matt at91cf_io_alloc(pcmcia_chipset_handle_t pch, bus_addr_t start, bus_size_t size,
394 1.2 matt bus_size_t align, struct pcmcia_io_handle *pih)
395 1.2 matt {
396 1.2 matt struct at91cf_handle *ph = (struct at91cf_handle *)pch;
397 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
398 1.2 matt bus_addr_t pa;
399 1.2 matt
400 1.2 matt DPRINTFN(1, ("at91cf_io_alloc: start=%#x, size=%#x, align=%#x\n",(unsigned)start,(unsigned)size,(unsigned)align));
401 1.2 matt
402 1.2 matt pih->iot = sc->sc_iot;
403 1.2 matt pih->addr = start;
404 1.2 matt pih->size = size;
405 1.2 matt pa = pih->addr + ph->ph_space[IO].base;
406 1.2 matt return bus_space_map(sc->sc_iot, pa, size, 0, &pih->ioh);
407 1.2 matt }
408 1.2 matt
409 1.2 matt static void
410 1.2 matt at91cf_io_free(pcmcia_chipset_handle_t pch, struct pcmcia_io_handle *pih)
411 1.2 matt {
412 1.2 matt struct at91cf_handle *ph = (struct at91cf_handle *)pch;
413 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
414 1.2 matt
415 1.2 matt DPRINTFN(1, ("at91cf_io_free\n"));
416 1.2 matt
417 1.2 matt bus_space_unmap(sc->sc_iot, pih->ioh, pih->size);
418 1.2 matt }
419 1.2 matt
420 1.2 matt static int
421 1.2 matt at91cf_io_map(pcmcia_chipset_handle_t pch, int width, bus_addr_t offset,
422 1.2 matt bus_size_t size, struct pcmcia_io_handle *pih, int *windowp)
423 1.2 matt {
424 1.2 matt struct at91cf_handle *ph = (struct at91cf_handle *)pch;
425 1.2 matt
426 1.2 matt DPRINTFN(1, ("at91cf_io_map: offset=%#x, size=%#x, width=%d",(unsigned)offset,(unsigned)size,width));
427 1.2 matt
428 1.2 matt switch (width) {
429 1.2 matt case PCMCIA_WIDTH_IO8:
430 1.2 matt DPRINTFN(1, ("(8bit)\n"));
431 1.2 matt ph->ph_width = 8;
432 1.2 matt break;
433 1.2 matt case PCMCIA_WIDTH_IO16:
434 1.2 matt case PCMCIA_WIDTH_AUTO: /* I don't understand how I check it */
435 1.2 matt DPRINTFN(1, ("(16bit)\n"));
436 1.2 matt ph->ph_width = 16;
437 1.2 matt break;
438 1.2 matt default:
439 1.2 matt DPRINTFN(1, ("(unknown)\n"));
440 1.2 matt return -1;
441 1.2 matt }
442 1.2 matt *windowp = 0; /* unused */
443 1.2 matt return 0;
444 1.2 matt }
445 1.2 matt
446 1.2 matt static void
447 1.2 matt at91cf_io_unmap(pcmcia_chipset_handle_t pch, int window)
448 1.2 matt {
449 1.2 matt DPRINTFN(1, ("at91cf_io_unmap: window=%#x\n",window));
450 1.2 matt }
451 1.2 matt
452 1.2 matt static void *
453 1.2 matt at91cf_intr_establish(pcmcia_chipset_handle_t pch, struct pcmcia_function *pf,
454 1.2 matt int ipl, int (*ih_func)(void *), void *ih_arg)
455 1.2 matt {
456 1.2 matt struct at91cf_handle *ph = (struct at91cf_handle *)pch;
457 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
458 1.2 matt at91cf_chipset_tag_t cscf = sc->sc_cscf;
459 1.2 matt
460 1.2 matt DPRINTFN(1, ("at91cf_intr_establish\n"));
461 1.2 matt
462 1.2 matt if (ph->ph_ih_func)
463 1.2 matt return 0;
464 1.2 matt
465 1.2 matt ph->ph_ih_func = ih_func;
466 1.2 matt ph->ph_ih_arg = ih_arg;
467 1.2 matt
468 1.2 matt return (*cscf->intr_establish)(sc, CF_IRQ, ipl, at91cf_intr_socket, ph);
469 1.2 matt // return (*cscf->intr_establish)(sc, CF_IRQ, ipl, ih_func, ih_arg);
470 1.2 matt }
471 1.2 matt
472 1.2 matt static void
473 1.2 matt at91cf_intr_disestablish(pcmcia_chipset_handle_t pch, void *ih)
474 1.2 matt {
475 1.2 matt struct at91cf_handle *ph = (struct at91cf_handle *)pch;
476 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
477 1.2 matt at91cf_chipset_tag_t cscf = sc->sc_cscf;
478 1.2 matt
479 1.2 matt DPRINTFN(1, ("at91cf_intr_disestablish\n"));
480 1.2 matt
481 1.2 matt ph->ph_ih_func = NULL;
482 1.2 matt ph->ph_ih_arg = NULL;
483 1.2 matt
484 1.2 matt (*cscf->intr_disestablish)(sc, CF_IRQ, ih);
485 1.2 matt }
486 1.2 matt
487 1.2 matt static int
488 1.2 matt at91cf_intr_socket(void *arg)
489 1.2 matt {
490 1.2 matt struct at91cf_handle *ph = arg;
491 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
492 1.2 matt at91cf_chipset_tag_t cscf = sc->sc_cscf;
493 1.2 matt int err = 0, irq;
494 1.2 matt
495 1.2 matt if (ph->ph_ih_func) {
496 1.2 matt irq = (*cscf->irq_line)(sc);
497 1.2 matt if (ph->ph_type == PCMCIA_IFTYPE_IO)
498 1.2 matt irq = !irq;
499 1.2 matt if (irq)
500 1.2 matt err = (*ph->ph_ih_func)(ph->ph_ih_arg);
501 1.2 matt else
502 1.2 matt DPRINTFN(2,("%s: other edge ignored\n", __FUNCTION__));
503 1.2 matt }
504 1.2 matt
505 1.2 matt return err;
506 1.2 matt }
507 1.2 matt
508 1.2 matt static void
509 1.2 matt at91cf_socket_enable(pcmcia_chipset_handle_t pch)
510 1.2 matt {
511 1.2 matt struct at91cf_handle *ph = (struct at91cf_handle *)pch;
512 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
513 1.2 matt at91cf_chipset_tag_t cscf = sc->sc_cscf;
514 1.2 matt int wait;
515 1.2 matt
516 1.2 matt DPRINTFN(1, ("at91cf_socket_enable\n"));
517 1.2 matt
518 1.2 matt wait = (cscf->power_ctl)(sc, POWER_ON);
519 1.2 matt delay(wait);
520 1.2 matt }
521 1.2 matt
522 1.2 matt static void
523 1.2 matt at91cf_socket_disable(pcmcia_chipset_handle_t pch)
524 1.2 matt {
525 1.2 matt struct at91cf_handle *ph = (struct at91cf_handle *)pch;
526 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
527 1.2 matt at91cf_chipset_tag_t cscf = sc->sc_cscf;
528 1.2 matt int wait;
529 1.2 matt
530 1.2 matt DPRINTFN(1, ("at91cf_socket_disable\n"));
531 1.2 matt
532 1.2 matt wait = (cscf->power_ctl)(sc, POWER_OFF);
533 1.2 matt delay(wait);
534 1.2 matt }
535 1.2 matt
536 1.2 matt static void
537 1.2 matt at91cf_socket_settype(pcmcia_chipset_handle_t pch, int type)
538 1.2 matt {
539 1.2 matt struct at91cf_handle *ph = (struct at91cf_handle *)pch;
540 1.2 matt
541 1.2 matt DPRINTFN(1, ("at91cf_socket_settype: type=%d",type));
542 1.2 matt
543 1.2 matt ph->ph_type = type;
544 1.2 matt
545 1.2 matt switch (type) {
546 1.2 matt case PCMCIA_IFTYPE_MEMORY:
547 1.2 matt DPRINTFN(1, ("(Memory)\n"));
548 1.2 matt break;
549 1.2 matt case PCMCIA_IFTYPE_IO:
550 1.2 matt DPRINTFN(1, ("(I/O)\n"));
551 1.2 matt break;
552 1.2 matt default:
553 1.2 matt DPRINTFN(1, ("(unknown)\n"));
554 1.2 matt return;
555 1.2 matt }
556 1.2 matt }
557 1.2 matt
558 1.2 matt #if 0
559 1.2 matt static int
560 1.2 matt at91cf_get_voltage(struct at91cf_handle *ph)
561 1.2 matt {
562 1.2 matt struct at91cf_softc *sc = ph->ph_sc;
563 1.2 matt at91cf_chipset_tag_t cscf = sc->sc_cscf;
564 1.2 matt int cap, vcc = 0;
565 1.2 matt
566 1.2 matt cap = (cscf->power_capability)(sc);
567 1.2 matt if (eppio_read(sc->sc_pio, ph->ph_port, ph->ph_vs[0])) {
568 1.2 matt if (cap | VCC_5V)
569 1.2 matt vcc = 5;
570 1.2 matt else
571 1.2 matt printf("%s: unsupported Vcc 5 Volts",
572 1.2 matt device_xname(sc->sc_dev));
573 1.2 matt } else {
574 1.2 matt if (cap | VCC_3V)
575 1.2 matt vcc = 3;
576 1.2 matt else
577 1.2 matt printf("%s: unsupported Vcc 3.3 Volts",
578 1.2 matt device_xname(sc->sc_dev));
579 1.2 matt }
580 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));
581 1.2 matt return vcc;
582 1.2 matt }
583 1.2 matt
584 1.2 matt #endif
585