Home | History | Annotate | Line # | Download | only in dev
nbpmci.c revision 1.1
      1  1.1  kiyohara /*	$NetBSD: nbpmci.c,v 1.1 2011/08/06 03:53:40 kiyohara Exp $	*/
      2  1.1  kiyohara 
      3  1.1  kiyohara /*-
      4  1.1  kiyohara  * Copyright (c) 2007 NONAKA Kimihiro <nonaka (at) netbsd.org>
      5  1.1  kiyohara  * All rights reserved.
      6  1.1  kiyohara  *
      7  1.1  kiyohara  * Redistribution and use in source and binary forms, with or without
      8  1.1  kiyohara  * modification, are permitted provided that the following conditions
      9  1.1  kiyohara  * are met:
     10  1.1  kiyohara  * 1. Redistributions of source code must retain the above copyright
     11  1.1  kiyohara  *    notice, this list of conditions and the following disclaimer.
     12  1.1  kiyohara  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  kiyohara  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  kiyohara  *    documentation and/or other materials provided with the distribution.
     15  1.1  kiyohara  *
     16  1.1  kiyohara  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     17  1.1  kiyohara  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  1.1  kiyohara  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  1.1  kiyohara  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     20  1.1  kiyohara  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  1.1  kiyohara  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  1.1  kiyohara  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  1.1  kiyohara  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  1.1  kiyohara  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  1.1  kiyohara  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  1.1  kiyohara  * SUCH DAMAGE.
     27  1.1  kiyohara  */
     28  1.1  kiyohara 
     29  1.1  kiyohara #include <sys/cdefs.h>
     30  1.1  kiyohara __KERNEL_RCSID(0, "$NetBSD: nbpmci.c,v 1.1 2011/08/06 03:53:40 kiyohara Exp $");
     31  1.1  kiyohara 
     32  1.1  kiyohara #include <sys/param.h>
     33  1.1  kiyohara #include <sys/device.h>
     34  1.1  kiyohara 
     35  1.1  kiyohara #include <machine/platid.h>
     36  1.1  kiyohara #include <machine/platid_mask.h>
     37  1.1  kiyohara 
     38  1.1  kiyohara #include <arm/xscale/pxa2x0var.h>
     39  1.1  kiyohara #include <arm/xscale/pxa2x0_gpio.h>
     40  1.1  kiyohara #include <arm/xscale/pxa2x0_mci.h>
     41  1.1  kiyohara 
     42  1.1  kiyohara #include <dev/sdmmc/sdmmcreg.h>
     43  1.1  kiyohara 
     44  1.1  kiyohara 
     45  1.1  kiyohara static int pxamci_match(device_t, cfdata_t, void *);
     46  1.1  kiyohara static void pxamci_attach(device_t, device_t, void *);
     47  1.1  kiyohara 
     48  1.1  kiyohara static int nbpmci_intr(void *);
     49  1.1  kiyohara 
     50  1.1  kiyohara static uint32_t nbpmci_get_ocr(void *);
     51  1.1  kiyohara static int nbpmci_set_power(void *, uint32_t);
     52  1.1  kiyohara static int nbpmci_card_detect(void *);
     53  1.1  kiyohara static int nbpmci_write_protect(void *);
     54  1.1  kiyohara 
     55  1.1  kiyohara CFATTACH_DECL_NEW(nbpmci, sizeof(struct pxamci_softc),
     56  1.1  kiyohara     pxamci_match, pxamci_attach, NULL, NULL);
     57  1.1  kiyohara 
     58  1.1  kiyohara /* ARGSUSED */
     59  1.1  kiyohara static int
     60  1.1  kiyohara pxamci_match(device_t parent, cfdata_t match, void *aux)
     61  1.1  kiyohara {
     62  1.1  kiyohara 	struct pxaip_attach_args *pxa = aux;
     63  1.1  kiyohara 
     64  1.1  kiyohara 	if (strcmp(pxa->pxa_name, match->cf_name) != 0 ||
     65  1.1  kiyohara 	    !platid_match(&platid, &platid_mask_MACH_PSIONTEKLOGIX_NETBOOK_PRO))
     66  1.1  kiyohara 		return 0;
     67  1.1  kiyohara 
     68  1.1  kiyohara 	pxa->pxa_size = PXA2X0_MMC_SIZE;
     69  1.1  kiyohara 
     70  1.1  kiyohara 	return 1;
     71  1.1  kiyohara }
     72  1.1  kiyohara 
     73  1.1  kiyohara /* ARGSUSED */
     74  1.1  kiyohara static void
     75  1.1  kiyohara pxamci_attach(device_t parent, device_t self, void *aux)
     76  1.1  kiyohara {
     77  1.1  kiyohara 	struct pxamci_softc *sc = device_private(self);
     78  1.1  kiyohara 	struct pxaip_attach_args *pxa = aux;
     79  1.1  kiyohara 	void *ih;
     80  1.1  kiyohara 
     81  1.1  kiyohara 	pxa2x0_gpio_set_function(9, GPIO_IN);
     82  1.1  kiyohara 	ih = pxa2x0_gpio_intr_establish(9, IST_EDGE_BOTH, IPL_BIO,
     83  1.1  kiyohara 	    nbpmci_intr, sc);
     84  1.1  kiyohara 	if (ih == NULL) {
     85  1.1  kiyohara 		aprint_error_dev(self,
     86  1.1  kiyohara 		    "unable to establish card detect interrupt\n");
     87  1.1  kiyohara 		return;
     88  1.1  kiyohara 	}
     89  1.1  kiyohara 
     90  1.1  kiyohara 	sc->sc_tag.cookie = sc;
     91  1.1  kiyohara 	sc->sc_tag.get_ocr = nbpmci_get_ocr;
     92  1.1  kiyohara 	sc->sc_tag.set_power = nbpmci_set_power;
     93  1.1  kiyohara 	sc->sc_tag.card_detect = nbpmci_card_detect;
     94  1.1  kiyohara 	sc->sc_tag.write_protect = nbpmci_write_protect;
     95  1.1  kiyohara 	sc->sc_caps = 0;
     96  1.1  kiyohara 
     97  1.1  kiyohara 	if (pxamci_attach_sub(self, pxa))
     98  1.1  kiyohara 		aprint_error_dev(self, "unable to attach MMC controller\n");
     99  1.1  kiyohara 
    100  1.1  kiyohara 	if (!pmf_device_register(self, NULL, NULL))
    101  1.1  kiyohara 		aprint_error_dev(self, "couldn't establish power handler\n");
    102  1.1  kiyohara }
    103  1.1  kiyohara 
    104  1.1  kiyohara static int
    105  1.1  kiyohara nbpmci_intr(void *arg)
    106  1.1  kiyohara {
    107  1.1  kiyohara 	struct pxamci_softc *sc = (struct pxamci_softc *)arg;
    108  1.1  kiyohara 
    109  1.1  kiyohara 	pxa2x0_gpio_clear_intr(9);
    110  1.1  kiyohara 
    111  1.1  kiyohara 	pxamci_card_detect_event(sc);
    112  1.1  kiyohara 
    113  1.1  kiyohara 	return 1;
    114  1.1  kiyohara }
    115  1.1  kiyohara 
    116  1.1  kiyohara /* ARGSUSED */
    117  1.1  kiyohara static uint32_t
    118  1.1  kiyohara nbpmci_get_ocr(void *arg)
    119  1.1  kiyohara {
    120  1.1  kiyohara 
    121  1.1  kiyohara 	return MMC_OCR_3_2V_3_3V|MMC_OCR_3_3V_3_4V;
    122  1.1  kiyohara }
    123  1.1  kiyohara 
    124  1.1  kiyohara /* ARGSUSED */
    125  1.1  kiyohara static int
    126  1.1  kiyohara nbpmci_set_power(void *arg, uint32_t ocr)
    127  1.1  kiyohara {
    128  1.1  kiyohara 
    129  1.1  kiyohara //	nbp_pcon_command(I2C_SETMMCPOWER, vdd_bits ? 1 : 0, 0, NULL);
    130  1.1  kiyohara 	return 0;
    131  1.1  kiyohara }
    132  1.1  kiyohara 
    133  1.1  kiyohara /*
    134  1.1  kiyohara  * Return non-zero if the card is currently inserted.
    135  1.1  kiyohara  */
    136  1.1  kiyohara /* ARGSUSED */
    137  1.1  kiyohara static int
    138  1.1  kiyohara nbpmci_card_detect(void *arg)
    139  1.1  kiyohara {
    140  1.1  kiyohara 
    141  1.1  kiyohara 	if (pxa2x0_gpio_get_bit(9))
    142  1.1  kiyohara 		return 0;
    143  1.1  kiyohara 	return 1;
    144  1.1  kiyohara }
    145  1.1  kiyohara 
    146  1.1  kiyohara /*
    147  1.1  kiyohara  * Return non-zero if the card is currently write-protected.
    148  1.1  kiyohara  */
    149  1.1  kiyohara /* ARGSUSED */
    150  1.1  kiyohara static int
    151  1.1  kiyohara nbpmci_write_protect(void *arg)
    152  1.1  kiyohara {
    153  1.1  kiyohara 
    154  1.1  kiyohara 	return 0;
    155  1.1  kiyohara }
    156