sa11xx_pcic.c revision 1.3.2.2       1  1.3.2.1    skrll /*	$NetBSD: sa11xx_pcic.c,v 1.3.2.2 2004/09/18 14:32:39 skrll Exp $	*/
      2      1.1      rjs 
      3      1.1      rjs /*
      4      1.1      rjs  * Copyright (c) 2001 IWAMOTO Toshihiro.  All rights reserved.
      5      1.1      rjs  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
      6      1.1      rjs  *
      7      1.1      rjs  * Redistribution and use in source and binary forms, with or without
      8      1.1      rjs  * modification, are permitted provided that the following conditions
      9      1.1      rjs  * are met:
     10      1.1      rjs  * 1. Redistributions of source code must retain the above copyright
     11      1.1      rjs  *    notice, this list of conditions and the following disclaimer.
     12      1.1      rjs  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1      rjs  *    notice, this list of conditions and the following disclaimer in the
     14      1.1      rjs  *    documentation and/or other materials provided with the distribution.
     15      1.1      rjs  * 3. All advertising materials mentioning features or use of this software
     16      1.1      rjs  *    must display the following acknowledgement:
     17      1.1      rjs  *	This product includes software developed by Marc Horowitz.
     18      1.1      rjs  * 4. The name of the author may not be used to endorse or promote products
     19      1.1      rjs  *    derived from this software without specific prior written permission.
     20      1.1      rjs  *
     21      1.1      rjs  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22      1.1      rjs  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23      1.1      rjs  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24      1.1      rjs  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25      1.1      rjs  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26      1.1      rjs  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27      1.1      rjs  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28      1.1      rjs  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29      1.1      rjs  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30      1.1      rjs  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31      1.1      rjs  */
     32      1.1      rjs 
     33      1.1      rjs /*
     34      1.1      rjs  * Common code for SA11x0 based PCMCIA modules
     35      1.1      rjs  */
     36      1.1      rjs 
     37  1.3.2.1    skrll #include <sys/cdefs.h>
     38  1.3.2.1    skrll __KERNEL_RCSID(0, "$NetBSD: sa11xx_pcic.c,v 1.3.2.2 2004/09/18 14:32:39 skrll Exp $");
     39  1.3.2.1    skrll 
     40      1.1      rjs #include <sys/types.h>
     41      1.1      rjs #include <sys/param.h>
     42      1.1      rjs #include <sys/systm.h>
     43      1.1      rjs #include <sys/device.h>
     44      1.1      rjs #include <sys/callout.h>
     45      1.1      rjs #include <sys/kernel.h>
     46      1.1      rjs #include <sys/kthread.h>
     47      1.1      rjs #include <sys/malloc.h>
     48      1.1      rjs #include <uvm/uvm.h>
     49      1.1      rjs 
     50      1.1      rjs #include <machine/bus.h>
     51      1.1      rjs #include <machine/intr.h>
     52      1.1      rjs 
     53      1.1      rjs #include <dev/pcmcia/pcmciareg.h>
     54      1.1      rjs #include <dev/pcmcia/pcmciavar.h>
     55      1.1      rjs #include <dev/pcmcia/pcmciachip.h>
     56      1.1      rjs 
     57      1.1      rjs #include <arm/sa11x0/sa11x0_reg.h>
     58      1.1      rjs #include <arm/sa11x0/sa11x0_var.h>
     59      1.1      rjs #include <arm/sa11x0/sa11xx_pcicreg.h>
     60      1.1      rjs #include <arm/sa11x0/sa11xx_pcicvar.h>
     61      1.1      rjs 
     62      1.1      rjs static	int	sapcic_mem_alloc(pcmcia_chipset_handle_t, bus_size_t,
     63      1.1      rjs 					struct pcmcia_mem_handle *);
     64      1.1      rjs static	void	sapcic_mem_free(pcmcia_chipset_handle_t,
     65      1.1      rjs 				       struct pcmcia_mem_handle *);
     66      1.1      rjs static	int	sapcic_mem_map(pcmcia_chipset_handle_t, int, bus_addr_t,
     67      1.1      rjs 				      bus_size_t, struct pcmcia_mem_handle *,
     68      1.1      rjs 				      bus_addr_t *, int *);
     69      1.1      rjs static	void	sapcic_mem_unmap(pcmcia_chipset_handle_t, int);
     70      1.1      rjs static	int	sapcic_io_alloc(pcmcia_chipset_handle_t, bus_addr_t,
     71      1.1      rjs 				       bus_size_t, bus_size_t,
     72      1.1      rjs 				       struct pcmcia_io_handle *);
     73      1.1      rjs static	void	sapcic_io_free(pcmcia_chipset_handle_t,
     74      1.1      rjs 				      struct pcmcia_io_handle *);
     75      1.1      rjs static	int	sapcic_io_map(pcmcia_chipset_handle_t, int,
     76      1.1      rjs 				     bus_addr_t, bus_size_t,
     77      1.1      rjs 				     struct pcmcia_io_handle *, int *);
     78      1.1      rjs static	void	sapcic_io_unmap(pcmcia_chipset_handle_t, int);
     79      1.1      rjs static	void	*sapcic_intr_establish(pcmcia_chipset_handle_t,
     80      1.1      rjs 					      struct pcmcia_function *, int,
     81      1.1      rjs 					      int (*)(void *), void *);
     82      1.1      rjs static	void	sapcic_intr_disestablish(pcmcia_chipset_handle_t,
     83      1.1      rjs 						void *);
     84      1.1      rjs static	void	sapcic_socket_enable(pcmcia_chipset_handle_t);
     85      1.1      rjs static	void	sapcic_socket_disable(pcmcia_chipset_handle_t);
     86      1.1      rjs 
     87      1.1      rjs static	void	sapcic_event_thread(void *);
     88      1.1      rjs 
     89      1.1      rjs static	void	sapcic_delay(int, const char *);
     90      1.1      rjs 
     91      1.1      rjs #ifdef DEBUG
     92      1.1      rjs #define DPRINTF(arg)	printf arg
     93      1.1      rjs #else
     94      1.1      rjs #define DPRINTF(arg)
     95      1.1      rjs #endif
     96      1.1      rjs 
     97      1.1      rjs struct pcmcia_chip_functions sa11x0_pcmcia_functions = {
     98      1.1      rjs 	sapcic_mem_alloc,
     99      1.1      rjs 	sapcic_mem_free,
    100      1.1      rjs 	sapcic_mem_map,
    101      1.1      rjs 	sapcic_mem_unmap,
    102      1.1      rjs 
    103      1.1      rjs 	sapcic_io_alloc,
    104      1.1      rjs 	sapcic_io_free,
    105      1.1      rjs 	sapcic_io_map,
    106      1.1      rjs 	sapcic_io_unmap,
    107      1.1      rjs 
    108      1.1      rjs 	sapcic_intr_establish,
    109      1.1      rjs 	sapcic_intr_disestablish,
    110      1.1      rjs 
    111      1.1      rjs 	sapcic_socket_enable,
    112      1.1      rjs 	sapcic_socket_disable,
    113      1.1      rjs };
    114      1.1      rjs 
    115      1.1      rjs 
    116      1.1      rjs void
    117      1.1      rjs sapcic_kthread_create(arg)
    118      1.1      rjs 	void *arg;
    119      1.1      rjs {
    120      1.1      rjs 	struct sapcic_socket *so = arg;
    121      1.1      rjs 
    122      1.1      rjs 	/* XXX attach card if already present */
    123      1.1      rjs 
    124      1.1      rjs 	so->laststatus =(so->pcictag->read)(so, SAPCIC_STATUS_CARD);
    125      1.1      rjs 	if (so->laststatus == SAPCIC_CARD_VALID) {
    126      1.1      rjs 		printf("%s: card present\n",
    127      1.1      rjs 		       so->sc->sc_dev.dv_xname);
    128      1.1      rjs 
    129      1.1      rjs 		pcmcia_card_attach(so->pcmcia);
    130      1.1      rjs 	}
    131      1.1      rjs 
    132      1.1      rjs 	if (kthread_create1(sapcic_event_thread, so, &so->event_thread,
    133      1.1      rjs 			    "%s,%d", so->sc->sc_dev.dv_xname, so->socket)) {
    134      1.1      rjs 		printf("%s: unable to create event thread for socket %d\n",
    135      1.1      rjs 		       so->sc->sc_dev.dv_xname, so->socket);
    136      1.1      rjs 		panic("sapcic_kthread_create");
    137      1.1      rjs 	}
    138      1.1      rjs }
    139      1.1      rjs 
    140      1.1      rjs static void
    141      1.1      rjs sapcic_event_thread(arg)
    142      1.1      rjs 	void *arg;
    143      1.1      rjs {
    144      1.1      rjs 	struct sapcic_socket *so = arg;
    145      1.1      rjs 	int newstatus, s;
    146      1.1      rjs 
    147      1.1      rjs 	while (so->shutdown == 0) {
    148      1.1      rjs 		/*
    149      1.1      rjs 		 * Serialize event processing on the PCIC.  We may
    150      1.1      rjs 		 * sleep while we hold this lock.
    151      1.1      rjs 		 */
    152      1.1      rjs 		(void) lockmgr(&so->sc->sc_lock, LK_EXCLUSIVE, NULL);
    153      1.1      rjs 
    154      1.1      rjs 		/* sleep .25s to be enqueued chatterling interrupts */
    155      1.1      rjs 		(void) tsleep((caddr_t)sapcic_event_thread, PWAIT,
    156      1.1      rjs 			      "pcicss", hz/4);
    157      1.1      rjs 
    158      1.1      rjs 		s = splhigh();
    159      1.1      rjs 		so->event = 0;
    160      1.1      rjs 
    161      1.1      rjs 		/* we don't rely on interrupt type */
    162      1.1      rjs 		newstatus = (so->pcictag->read)(so, SAPCIC_STATUS_CARD);
    163      1.1      rjs 		splx(s);
    164      1.1      rjs 
    165      1.1      rjs 		if (so->laststatus == newstatus) {
    166      1.1      rjs 			/*
    167      1.1      rjs 			 * No events to process; release the PCIC lock.
    168      1.1      rjs 			 */
    169      1.1      rjs 			(void) lockmgr(&so->sc->sc_lock, LK_RELEASE, NULL);
    170      1.1      rjs 			(void) tsleep(&so->event, PWAIT, "pcicev", hz);
    171      1.1      rjs 			continue;
    172      1.1      rjs 		}
    173      1.1      rjs 
    174      1.1      rjs 		so->laststatus = newstatus;
    175      1.1      rjs 		switch (newstatus) {
    176      1.1      rjs 		case SAPCIC_CARD_VALID:
    177      1.1      rjs 			printf("%s: insertion event\n",
    178      1.1      rjs 			       so->sc->sc_dev.dv_xname);
    179      1.1      rjs 
    180      1.1      rjs 			pcmcia_card_attach(so->pcmcia);
    181      1.1      rjs 			break;
    182      1.1      rjs 
    183      1.1      rjs 		case SAPCIC_CARD_INVALID:
    184      1.1      rjs 			printf("%s: removal event\n",
    185      1.1      rjs 			       so->sc->sc_dev.dv_xname);
    186      1.1      rjs 
    187      1.1      rjs 			pcmcia_card_detach(so->pcmcia, DETACH_FORCE);
    188      1.1      rjs 			break;
    189      1.1      rjs 
    190      1.1      rjs 		default:
    191      1.1      rjs 			panic("sapcic_event_thread: unknown status %d",
    192      1.1      rjs 			    newstatus);
    193      1.1      rjs 		}
    194      1.1      rjs 
    195      1.1      rjs 		(void) lockmgr(&so->sc->sc_lock, LK_RELEASE, NULL);
    196      1.1      rjs 	}
    197      1.1      rjs 
    198      1.1      rjs 	so->event_thread = NULL;
    199      1.1      rjs 
    200      1.1      rjs 	/* In case parent is waiting for us to exit. */
    201      1.1      rjs 	wakeup(so->sc);
    202      1.1      rjs 
    203      1.1      rjs 	kthread_exit(0);
    204      1.1      rjs }
    205      1.1      rjs 
    206      1.1      rjs static void
    207      1.1      rjs sapcic_delay(timo, wmesg)
    208      1.1      rjs 	int timo;		/* in milliseconds */
    209      1.1      rjs 	const char *wmesg;
    210      1.1      rjs {
    211      1.1      rjs #ifdef DIAGNOSTIC
    212      1.3  thorpej 	if (curlwp == NULL)
    213      1.2   provos 		panic("sapcic_delay: called in interrupt context");
    214      1.1      rjs #endif
    215      1.1      rjs 
    216      1.1      rjs 	tsleep(sapcic_delay, PWAIT, wmesg, roundup(timo * hz, 1000) / 1000);
    217      1.1      rjs }
    218      1.1      rjs 
    219      1.1      rjs int
    220      1.1      rjs sapcic_intr(arg)
    221      1.1      rjs 	void *arg;
    222      1.1      rjs {
    223      1.1      rjs 	struct sapcic_socket *so = arg;
    224      1.1      rjs 
    225      1.1      rjs 	so->event++;
    226      1.1      rjs 	(so->pcictag->clear_intr)(so->socket);
    227      1.1      rjs 	wakeup(&so->event);
    228      1.1      rjs 	return 1;
    229      1.1      rjs }
    230      1.1      rjs 
    231      1.1      rjs static int
    232      1.1      rjs sapcic_mem_alloc(pch, size, pmh)
    233      1.1      rjs 	pcmcia_chipset_handle_t pch;
    234      1.1      rjs 	bus_size_t size;
    235      1.1      rjs 	struct pcmcia_mem_handle *pmh;
    236      1.1      rjs {
    237      1.1      rjs 	struct sapcic_socket *so = pch;
    238      1.1      rjs 
    239      1.1      rjs 	/* All we need is bus space tag */
    240      1.1      rjs 	memset(pmh, 0, sizeof(*pmh));
    241      1.1      rjs 	pmh->memt = so->sc->sc_iot;
    242      1.1      rjs 	return (0);
    243      1.1      rjs }
    244      1.1      rjs 
    245      1.1      rjs 
    246      1.1      rjs static void
    247      1.1      rjs sapcic_mem_free(pch, pmh)
    248      1.1      rjs 	pcmcia_chipset_handle_t pch;
    249      1.1      rjs 	struct pcmcia_mem_handle *pmh;
    250      1.1      rjs {
    251      1.1      rjs }
    252      1.1      rjs 
    253      1.1      rjs static int
    254      1.1      rjs sapcic_mem_map(pch, kind, card_addr, size, pmh, offsetp, windowp)
    255      1.1      rjs 	pcmcia_chipset_handle_t pch;
    256      1.1      rjs 	int kind;
    257      1.1      rjs 	bus_addr_t card_addr;
    258      1.1      rjs 	bus_size_t size;
    259      1.1      rjs 	struct pcmcia_mem_handle *pmh;
    260      1.1      rjs 	bus_addr_t *offsetp;
    261      1.1      rjs 	int *windowp;
    262      1.1      rjs {
    263      1.1      rjs 	struct sapcic_socket *so = pch;
    264      1.1      rjs 	int error;
    265      1.1      rjs 	bus_addr_t pa;
    266      1.1      rjs 
    267      1.1      rjs 	pa = trunc_page(card_addr);
    268      1.1      rjs 	*offsetp = card_addr - pa;
    269      1.1      rjs 	size = round_page(card_addr + size) - pa;
    270      1.1      rjs 	pmh->realsize = size;
    271      1.1      rjs 
    272      1.1      rjs 	pa += SAPCIC_BASE_OFFSET;
    273      1.1      rjs 	pa += SAPCIC_SOCKET_OFFSET * so->socket;
    274      1.1      rjs 
    275      1.1      rjs 	switch (kind & ~PCMCIA_WIDTH_MEM_MASK) {
    276      1.1      rjs 	case PCMCIA_MEM_ATTR:
    277      1.1      rjs 		pa += SAPCIC_ATTR_OFFSET;
    278      1.1      rjs 		break;
    279      1.1      rjs 	case PCMCIA_MEM_COMMON:
    280      1.1      rjs 		pa += SAPCIC_COMMON_OFFSET;
    281      1.1      rjs 		break;
    282      1.1      rjs 	default:
    283      1.2   provos 		panic("sapcic_mem_map: bogus kind");
    284      1.1      rjs 	}
    285      1.1      rjs 
    286      1.1      rjs 	error = bus_space_map(so->sc->sc_iot, pa, size, 0, &pmh->memh);
    287      1.1      rjs 	if (! error)
    288      1.1      rjs 		*windowp = (int)pmh->memh;
    289      1.1      rjs 	return (error);
    290      1.1      rjs }
    291      1.1      rjs 
    292      1.1      rjs static void
    293      1.1      rjs sapcic_mem_unmap(pch, window)
    294      1.1      rjs 	pcmcia_chipset_handle_t pch;
    295      1.1      rjs 	int window;
    296      1.1      rjs {
    297      1.1      rjs 	struct sapcic_socket *so = pch;
    298      1.1      rjs 
    299      1.1      rjs 	bus_space_unmap(so->sc->sc_iot, (bus_addr_t)window, 4096); /* XXX */
    300      1.1      rjs }
    301      1.1      rjs 
    302      1.1      rjs static int
    303      1.1      rjs sapcic_io_alloc(pch, start, size, align, pih)
    304      1.1      rjs 	pcmcia_chipset_handle_t pch;
    305      1.1      rjs 	bus_addr_t start;
    306      1.1      rjs 	bus_size_t size;
    307      1.1      rjs 	bus_size_t align;
    308      1.1      rjs 	struct pcmcia_io_handle *pih;
    309      1.1      rjs {
    310      1.1      rjs 	struct sapcic_socket *so = pch;
    311      1.1      rjs 	int error;
    312      1.1      rjs 	bus_addr_t pa;
    313      1.1      rjs 
    314      1.1      rjs 	memset(pih, 0, sizeof(*pih));
    315      1.1      rjs 	pih->iot = so->sc->sc_iot;
    316      1.1      rjs 	pih->addr = start;
    317      1.1      rjs 	pih->size = size;
    318      1.1      rjs 
    319      1.1      rjs 	pa = pih->addr;
    320      1.1      rjs 	pa += SAPCIC_BASE_OFFSET;
    321      1.1      rjs 	pa += SAPCIC_SOCKET_OFFSET * so->socket;
    322      1.1      rjs 
    323      1.1      rjs 	DPRINTF(("sapcic_io_alloc: %x %x\n", (unsigned int)pa,
    324      1.1      rjs 		 (unsigned int)size));
    325      1.1      rjs 	/* XXX Are we ignoring alignment constraints? */
    326      1.1      rjs 	error = bus_space_map(so->sc->sc_iot, pa, size, 0, &pih->ioh);
    327      1.1      rjs 
    328      1.1      rjs 	return (error);
    329      1.1      rjs }
    330      1.1      rjs 
    331      1.1      rjs static void
    332      1.1      rjs sapcic_io_free(pch, pih)
    333      1.1      rjs 	pcmcia_chipset_handle_t pch;
    334      1.1      rjs 	struct pcmcia_io_handle *pih;
    335      1.1      rjs {
    336      1.1      rjs 	struct sapcic_socket *so = pch;
    337      1.1      rjs 
    338      1.1      rjs 	bus_space_unmap(so->sc->sc_iot, pih->ioh, pih->size);
    339      1.1      rjs }
    340      1.1      rjs 
    341      1.1      rjs static int
    342      1.1      rjs sapcic_io_map(pch, width, offset, size, pih, windowp)
    343      1.1      rjs 	pcmcia_chipset_handle_t pch;
    344      1.1      rjs 	int width;
    345      1.1      rjs 	bus_addr_t offset;
    346      1.1      rjs 	bus_size_t size;
    347      1.1      rjs 	struct pcmcia_io_handle *pih;
    348      1.1      rjs 	int *windowp;
    349      1.1      rjs {
    350      1.1      rjs 	return (0);
    351      1.1      rjs }
    352      1.1      rjs 
    353      1.1      rjs static void sapcic_io_unmap(pch, window)
    354      1.1      rjs 	pcmcia_chipset_handle_t pch;
    355      1.1      rjs 	int window;
    356      1.1      rjs {
    357      1.1      rjs }
    358      1.1      rjs 
    359      1.1      rjs static void *
    360      1.1      rjs sapcic_intr_establish(pch, pf, ipl, fct, arg)
    361      1.1      rjs 	pcmcia_chipset_handle_t pch;
    362      1.1      rjs 	struct pcmcia_function *pf;
    363      1.1      rjs 	int ipl;
    364      1.1      rjs 	int (*fct)(void *);
    365      1.1      rjs 	void *arg;
    366      1.1      rjs {
    367      1.1      rjs 	struct sapcic_socket *so = pch;
    368      1.1      rjs 
    369      1.1      rjs 	/* XXX need to check if something should be done here */
    370      1.1      rjs 
    371      1.1      rjs 	return ((so->pcictag->intr_establish)(so, ipl, fct, arg));
    372      1.1      rjs }
    373      1.1      rjs 
    374      1.1      rjs static void
    375      1.1      rjs sapcic_intr_disestablish(pch, ih)
    376      1.1      rjs 	pcmcia_chipset_handle_t pch;
    377      1.1      rjs 	void *ih;
    378      1.1      rjs {
    379      1.1      rjs 	struct sapcic_socket *so = pch;
    380      1.1      rjs 
    381      1.1      rjs 	((so->pcictag->intr_disestablish)(so, ih));
    382      1.1      rjs }
    383      1.1      rjs 
    384      1.1      rjs static void
    385      1.1      rjs sapcic_socket_enable(pch)
    386      1.1      rjs 	pcmcia_chipset_handle_t pch;
    387      1.1      rjs {
    388      1.1      rjs 	struct sapcic_socket *so = pch;
    389      1.1      rjs 	int i;
    390      1.1      rjs 
    391      1.1      rjs #if defined(DIAGNOSTIC) && defined(notyet)
    392      1.1      rjs 	if (so->flags & PCIC_FLAG_ENABLED)
    393      1.1      rjs 		printf("sapcic_socket_enable: enabling twice\n");
    394      1.1      rjs #endif
    395      1.1      rjs 
    396      1.1      rjs 	/* disable interrupts */
    397      1.1      rjs 
    398      1.1      rjs 	/* power down the socket to reset it, clear the card reset pin */
    399      1.1      rjs 	(so->pcictag->set_power)(so, SAPCIC_POWER_OFF);
    400      1.1      rjs 
    401      1.1      rjs 	/*
    402      1.1      rjs 	 * wait 300ms until power fails (Tpf).  Then, wait 100ms since
    403      1.1      rjs 	 * we are changing Vcc (Toff).
    404      1.1      rjs 	 */
    405      1.1      rjs 	sapcic_delay(300 + 100, "pccen0");
    406      1.1      rjs 
    407      1.1      rjs 	/* power up the socket */
    408      1.1      rjs 	/* XXX voltage selection should be done in PCMCIA code */
    409      1.1      rjs 	if (so->power_capability & SAPCIC_POWER_5V) {
    410      1.1      rjs 		(so->pcictag->set_power)(so, SAPCIC_POWER_5V);
    411      1.1      rjs 		(so->pcictag->write)(so, SAPCIC_CONTROL_POWERSELECT,
    412      1.1      rjs 				     SAPCIC_POWER_5V);
    413      1.1      rjs 	} else {
    414      1.1      rjs 		(so->pcictag->set_power)(so, SAPCIC_POWER_3V);
    415      1.1      rjs 		(so->pcictag->write)(so, SAPCIC_CONTROL_POWERSELECT,
    416      1.1      rjs 				     SAPCIC_POWER_3V);
    417      1.1      rjs 	}
    418      1.1      rjs 
    419      1.1      rjs 	/* enable PCMCIA control lines */
    420      1.1      rjs 	(so->pcictag->write)(so, SAPCIC_CONTROL_LINEENABLE, 1);
    421      1.1      rjs 
    422      1.1      rjs 	/*
    423      1.1      rjs 	 * wait 100ms until power raise (Tpr) and 20ms to become
    424      1.1      rjs 	 * stable (Tsu(Vcc)).
    425      1.1      rjs 	 *
    426      1.1      rjs 	 * some machines require some more time to be settled
    427      1.1      rjs 	 * (300ms is added here).
    428      1.1      rjs 	 */
    429      1.1      rjs 	sapcic_delay(100 + 20 + 300, "pccen1");
    430      1.1      rjs 
    431      1.1      rjs 	/* honor nWAIT signal */
    432      1.1      rjs 	(so->pcictag->write)(so, SAPCIC_CONTROL_WAITENABLE, 1);
    433      1.1      rjs 	/* now make sure we have reset# active */
    434      1.1      rjs 	(so->pcictag->write)(so, SAPCIC_CONTROL_RESET, 1);
    435      1.1      rjs 
    436      1.1      rjs 	/*
    437      1.1      rjs 	 * hold RESET at least 10us, this is a min allow for slop in
    438      1.1      rjs 	 * delay routine.
    439      1.1      rjs 	 */
    440      1.1      rjs 	delay(20);
    441      1.1      rjs 
    442      1.1      rjs 	/* clear the reset flag */
    443      1.1      rjs 	(so->pcictag->write)(so, SAPCIC_CONTROL_RESET, 0);
    444      1.1      rjs 
    445      1.1      rjs 	/* wait 20ms as per pc card standard (r2.01) section 4.3.6 */
    446      1.1      rjs 	sapcic_delay(20, "pccen2");
    447      1.1      rjs 
    448      1.1      rjs 	/* wait for the chip to finish initializing */
    449      1.1      rjs 	sapcic_delay(10, "pccen3");
    450      1.1      rjs 	for(i = 100; i; i--) {
    451      1.1      rjs 		if ((so->pcictag->read)(so, SAPCIC_STATUS_READY))
    452      1.1      rjs 			break;
    453      1.1      rjs 		sapcic_delay(100, "pccen4");
    454      1.1      rjs 	}
    455      1.1      rjs 	DPRINTF(("sapcic_socket_enable: wait ready %d\n", 100 - i));
    456      1.1      rjs 
    457      1.1      rjs 	/* finally enable the interrupt */
    458      1.1      rjs 
    459      1.1      rjs }
    460      1.1      rjs 
    461      1.1      rjs static void
    462      1.1      rjs sapcic_socket_disable(pch)
    463      1.1      rjs 	pcmcia_chipset_handle_t pch;
    464      1.1      rjs {
    465      1.1      rjs 	struct sapcic_socket *so = pch;
    466      1.1      rjs 
    467      1.1      rjs 	/* XXX mask card interrupts */
    468      1.1      rjs 
    469      1.1      rjs 	/* power down the card */
    470      1.1      rjs 	(so->pcictag->set_power)(so, SAPCIC_POWER_OFF);
    471      1.1      rjs 
    472      1.1      rjs 	/* float controller lines */
    473      1.1      rjs 	(so->pcictag->write)(so, SAPCIC_CONTROL_LINEENABLE, 0);
    474      1.1      rjs }
    475