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