Home | History | Annotate | Line # | Download | only in dev
      1  1.1  kiyohara /*	$NetBSD: nbppcic.c,v 1.1 2011/08/06 03:53:40 kiyohara Exp $ */
      2  1.1  kiyohara /*
      3  1.1  kiyohara  * Copyright (c) 2011 KIYOHARA Takashi
      4  1.1  kiyohara  * All rights reserved.
      5  1.1  kiyohara  *
      6  1.1  kiyohara  * Redistribution and use in source and binary forms, with or without
      7  1.1  kiyohara  * modification, are permitted provided that the following conditions
      8  1.1  kiyohara  * are met:
      9  1.1  kiyohara  * 1. Redistributions of source code must retain the above copyright
     10  1.1  kiyohara  *    notice, this list of conditions and the following disclaimer.
     11  1.1  kiyohara  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  kiyohara  *    notice, this list of conditions and the following disclaimer in the
     13  1.1  kiyohara  *    documentation and/or other materials provided with the distribution.
     14  1.1  kiyohara  *
     15  1.1  kiyohara  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16  1.1  kiyohara  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17  1.1  kiyohara  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18  1.1  kiyohara  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     19  1.1  kiyohara  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     20  1.1  kiyohara  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     21  1.1  kiyohara  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  1.1  kiyohara  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     23  1.1  kiyohara  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     24  1.1  kiyohara  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25  1.1  kiyohara  * POSSIBILITY OF SUCH DAMAGE.
     26  1.1  kiyohara  */
     27  1.1  kiyohara 
     28  1.1  kiyohara #include <sys/param.h>
     29  1.1  kiyohara #include <sys/bus.h>
     30  1.1  kiyohara #include <sys/device.h>
     31  1.1  kiyohara #include <sys/errno.h>
     32  1.1  kiyohara 
     33  1.1  kiyohara #include <machine/platid.h>
     34  1.1  kiyohara #include <machine/platid_mask.h>
     35  1.1  kiyohara 
     36  1.1  kiyohara #include <arm/xscale/pxa2x0var.h>
     37  1.1  kiyohara #include <arm/xscale/pxa2x0_gpio.h>
     38  1.1  kiyohara #include <arm/xscale/pxa2x0_pcic.h>
     39  1.1  kiyohara 
     40  1.1  kiyohara #include <dev/pcmcia/pcmciareg.h>
     41  1.1  kiyohara #include <dev/pcmcia/pcmciavar.h>
     42  1.1  kiyohara #include <dev/pcmcia/pcmciachip.h>
     43  1.1  kiyohara 
     44  1.1  kiyohara 
     45  1.1  kiyohara #define HAVE_CARD(r)	(!((r) & GPIO_SET))
     46  1.1  kiyohara 
     47  1.1  kiyohara 
     48  1.1  kiyohara static int nbppcic_match(device_t, cfdata_t, void *);
     49  1.1  kiyohara static void nbppcic_attach(device_t, device_t, void *);
     50  1.1  kiyohara 
     51  1.1  kiyohara static u_int nbppcic_read(struct pxapcic_socket *, int);
     52  1.1  kiyohara static void nbppcic_write(struct pxapcic_socket *, int, u_int);
     53  1.1  kiyohara static void nbppcic_set_power(struct pxapcic_socket *, int);
     54  1.1  kiyohara static void nbppcic_clear_intr(struct pxapcic_socket *);
     55  1.1  kiyohara static void *nbppcic_intr_establish(struct pxapcic_socket *, int,
     56  1.1  kiyohara 				    int (*)(void *), void *);
     57  1.1  kiyohara static void nbppcic_intr_disestablish(struct pxapcic_socket *, void *);
     58  1.1  kiyohara 
     59  1.1  kiyohara static void nbppcic_socket_setup(struct pxapcic_socket *);
     60  1.1  kiyohara 
     61  1.1  kiyohara CFATTACH_DECL_NEW(nbppcic, sizeof(struct pxapcic_softc),
     62  1.1  kiyohara     nbppcic_match, nbppcic_attach, NULL, NULL);
     63  1.1  kiyohara 
     64  1.1  kiyohara static struct pxapcic_tag nbppcic_functions = {
     65  1.1  kiyohara 	nbppcic_read,
     66  1.1  kiyohara 	nbppcic_write,
     67  1.1  kiyohara 	nbppcic_set_power,
     68  1.1  kiyohara 	nbppcic_clear_intr,
     69  1.1  kiyohara 	nbppcic_intr_establish,
     70  1.1  kiyohara 	nbppcic_intr_disestablish,
     71  1.1  kiyohara };
     72  1.1  kiyohara 
     73  1.1  kiyohara 
     74  1.1  kiyohara static int
     75  1.1  kiyohara nbppcic_match(device_t parent, cfdata_t match, void *aux)
     76  1.1  kiyohara {
     77  1.1  kiyohara 	struct pxaip_attach_args *pxa = aux;
     78  1.1  kiyohara 
     79  1.1  kiyohara 	if (strcmp(pxa->pxa_name, match->cf_name) != 0 ||
     80  1.1  kiyohara 	    !platid_match(&platid, &platid_mask_MACH_PSIONTEKLOGIX_NETBOOK_PRO))
     81  1.1  kiyohara 		return 0;
     82  1.1  kiyohara 
     83  1.1  kiyohara 	return	1;
     84  1.1  kiyohara }
     85  1.1  kiyohara 
     86  1.1  kiyohara static void
     87  1.1  kiyohara nbppcic_attach(device_t parent, device_t self, void *aux)
     88  1.1  kiyohara {
     89  1.1  kiyohara 	struct pxapcic_softc *sc = device_private(self);
     90  1.1  kiyohara 	struct pxaip_attach_args *pxa = aux;
     91  1.1  kiyohara 
     92  1.1  kiyohara 	sc->sc_dev = self;
     93  1.1  kiyohara 	sc->sc_iot = pxa->pxa_iot;
     94  1.1  kiyohara 
     95  1.1  kiyohara 	sc->sc_nslots = 2;
     96  1.1  kiyohara 	sc->sc_irqpin[0] = 71;		/* GPIO 71: PRDY1/~IRQ1 */
     97  1.1  kiyohara 	sc->sc_irqcfpin[0] = 73;	/* GPIO 73: PCD1 */
     98  1.1  kiyohara 	sc->sc_irqpin[1] = 77;		/* GPIO 77: PRDY2/~IRQ2 */
     99  1.1  kiyohara 	sc->sc_irqcfpin[1] = 75;	/* GPIO 75: PCD2 */
    100  1.1  kiyohara 
    101  1.1  kiyohara 	pxapcic_attach_common(sc, &nbppcic_socket_setup);
    102  1.1  kiyohara }
    103  1.1  kiyohara 
    104  1.1  kiyohara static u_int
    105  1.1  kiyohara nbppcic_read(struct pxapcic_socket *so, int which)
    106  1.1  kiyohara {
    107  1.1  kiyohara 	struct pxapcic_softc *sc = so->sc;
    108  1.1  kiyohara 	int reg;
    109  1.1  kiyohara 
    110  1.1  kiyohara 	switch (which) {
    111  1.1  kiyohara 	case PXAPCIC_CARD_STATUS:
    112  1.1  kiyohara 		reg = pxa2x0_gpio_get_function(sc->sc_irqcfpin[so->socket]);
    113  1.1  kiyohara 		return (HAVE_CARD(reg) ?
    114  1.1  kiyohara 		    PXAPCIC_CARD_VALID : PXAPCIC_CARD_INVALID);
    115  1.1  kiyohara 
    116  1.1  kiyohara 	case PXAPCIC_CARD_READY:
    117  1.1  kiyohara 		reg = pxa2x0_gpio_get_function(sc->sc_irqpin[so->socket]);
    118  1.1  kiyohara 		return (reg & GPIO_SET) ? 1 : 0;
    119  1.1  kiyohara 
    120  1.1  kiyohara 	default:
    121  1.1  kiyohara 		panic("%s: bogus register", __func__);
    122  1.1  kiyohara 	}
    123  1.1  kiyohara 	/* NOTREACHED */
    124  1.1  kiyohara }
    125  1.1  kiyohara 
    126  1.1  kiyohara static void
    127  1.1  kiyohara nbppcic_write(struct pxapcic_socket *so, int which, u_int arg)
    128  1.1  kiyohara {
    129  1.1  kiyohara 
    130  1.1  kiyohara 	switch (which) {
    131  1.1  kiyohara 	case PXAPCIC_CARD_POWER:
    132  1.1  kiyohara 		/* To Be Done: ;-) */
    133  1.1  kiyohara 		break;
    134  1.1  kiyohara 
    135  1.1  kiyohara 	case PXAPCIC_CARD_RESET:
    136  1.1  kiyohara 	{
    137  1.1  kiyohara 		int reset_pin[2] = { 70, 74 };	/* GPIO 70, GPIO 74 */
    138  1.1  kiyohara 
    139  1.1  kiyohara 		pxa2x0_gpio_set_function(reset_pin[so->socket],
    140  1.1  kiyohara 		    GPIO_OUT | (arg ? GPIO_CLR : GPIO_SET));
    141  1.1  kiyohara 		break;
    142  1.1  kiyohara 	}
    143  1.1  kiyohara 
    144  1.1  kiyohara 	default:
    145  1.1  kiyohara 		panic("%s: bogus register", __func__);
    146  1.1  kiyohara 	}
    147  1.1  kiyohara 	/* NOTREACHED */
    148  1.1  kiyohara }
    149  1.1  kiyohara 
    150  1.1  kiyohara /* ARGSUSED */
    151  1.1  kiyohara static void
    152  1.1  kiyohara nbppcic_set_power(struct pxapcic_socket *so, int arg)
    153  1.1  kiyohara {
    154  1.1  kiyohara 
    155  1.1  kiyohara 	if(arg != PXAPCIC_POWER_OFF && arg != PXAPCIC_POWER_3V)
    156  1.1  kiyohara 		panic("%s: bogus arg\n", __func__);
    157  1.1  kiyohara }
    158  1.1  kiyohara 
    159  1.1  kiyohara /* ARGSUSED */
    160  1.1  kiyohara static void
    161  1.1  kiyohara nbppcic_clear_intr(struct pxapcic_socket *so)
    162  1.1  kiyohara {
    163  1.1  kiyohara 
    164  1.1  kiyohara 	/* nothing to do */
    165  1.1  kiyohara }
    166  1.1  kiyohara 
    167  1.1  kiyohara static void *
    168  1.1  kiyohara nbppcic_intr_establish(struct pxapcic_socket *so, int level,
    169  1.1  kiyohara     int (* ih_fun)(void *), void *ih_arg)
    170  1.1  kiyohara {
    171  1.1  kiyohara 
    172  1.1  kiyohara 	return pxa2x0_gpio_intr_establish(so->irqpin, IST_EDGE_FALLING,
    173  1.1  kiyohara 	    level, ih_fun, ih_arg);
    174  1.1  kiyohara }
    175  1.1  kiyohara 
    176  1.1  kiyohara /* ARGSUSED */
    177  1.1  kiyohara static void
    178  1.1  kiyohara nbppcic_intr_disestablish(struct pxapcic_socket *so, void *ih)
    179  1.1  kiyohara {
    180  1.1  kiyohara 
    181  1.1  kiyohara 	pxa2x0_gpio_intr_disestablish(ih);
    182  1.1  kiyohara }
    183  1.1  kiyohara 
    184  1.1  kiyohara 
    185  1.1  kiyohara static void
    186  1.1  kiyohara nbppcic_socket_setup(struct pxapcic_socket *so)
    187  1.1  kiyohara {
    188  1.1  kiyohara 
    189  1.1  kiyohara 	so->power_capability = PXAPCIC_POWER_3V;
    190  1.1  kiyohara 	so->pcictag_cookie = NULL;
    191  1.1  kiyohara 	so->pcictag = &nbppcic_functions;
    192  1.1  kiyohara }
    193