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