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