1 /* $NetBSD: gxmci.c,v 1.2 2009/08/09 06:12:34 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: gxmci.c,v 1.2 2009/08/09 06:12:34 kiyohara Exp $"); 31 32 #include <sys/param.h> 33 #include <sys/device.h> 34 #include <sys/systm.h> 35 36 #include <machine/bus.h> 37 #include <machine/intr.h> 38 39 #include <arm/xscale/pxa2x0cpu.h> 40 #include <arm/xscale/pxa2x0reg.h> 41 #include <arm/xscale/pxa2x0var.h> 42 #include <arm/xscale/pxa2x0_gpio.h> 43 #include <arm/xscale/pxa2x0_mci.h> 44 45 #include <dev/sdmmc/sdmmcreg.h> 46 47 #if defined(PXAMCI_DEBUG) 48 #define DPRINTF(s) printf s 49 #else 50 #define DPRINTF(s) 51 #endif 52 53 struct gxmci_softc { 54 struct pxamci_softc sc; 55 }; 56 57 static int pxamci_match(device_t, cfdata_t, void *); 58 static void pxamci_attach(device_t, device_t, void *); 59 60 CFATTACH_DECL_NEW(gxmci, sizeof(struct gxmci_softc), 61 pxamci_match, pxamci_attach, NULL, NULL); 62 63 static uint32_t gxmci_get_ocr(void *); 64 static int gxmci_set_power(void *, uint32_t); 65 static int gxmci_card_detect(void *); 66 static int gxmci_write_protect(void *); 67 68 static int 69 pxamci_match(device_t parent, cfdata_t match, void *aux) 70 { 71 struct pxaip_attach_args *pxa = aux; 72 static struct pxa2x0_gpioconf pxa25x_gxmci_gpioconf[] = { 73 { 8, GPIO_ALT_FN_1_OUT }, /* MMCCS0 */ 74 { 53, GPIO_ALT_FN_1_OUT }, /* MMCLK */ 75 { -1 } 76 }; 77 struct pxa2x0_gpioconf *gpioconf; 78 u_int reg; 79 int i; 80 81 if (strcmp(pxa->pxa_name, match->cf_name) != 0) 82 return 0; 83 84 /* 85 * Check GPIO configuration. If you use these, it is sure already 86 * to have been set by gxio. 87 */ 88 gpioconf = 89 CPU_IS_PXA250 ? pxa25x_gxmci_gpioconf : pxa27x_pxamci_gpioconf; 90 for (i = 0; gpioconf[i].pin != -1; i++) { 91 reg = pxa2x0_gpio_get_function(gpioconf[i].pin); 92 if (GPIO_FN(reg) != GPIO_FN(gpioconf[i].value) || 93 GPIO_FN_IS_OUT(reg) != GPIO_FN_IS_OUT(gpioconf[i].value)) 94 return 0; 95 } 96 pxa->pxa_size = PXA2X0_MMC_SIZE; 97 98 return 1; 99 } 100 101 static void 102 pxamci_attach(device_t parent, device_t self, void *aux) 103 { 104 struct gxmci_softc *sc = device_private(self); 105 struct pxaip_attach_args *pxa = aux; 106 107 sc->sc.sc_tag.cookie = sc; 108 sc->sc.sc_tag.get_ocr = gxmci_get_ocr; 109 sc->sc.sc_tag.set_power = gxmci_set_power; 110 sc->sc.sc_tag.card_detect = gxmci_card_detect; 111 sc->sc.sc_tag.write_protect = gxmci_write_protect; 112 sc->sc.sc_caps = 0; 113 114 if (pxamci_attach_sub(self, pxa)) { 115 aprint_error_dev(self, "unable to attach MMC controller\n"); 116 } 117 118 if (!pmf_device_register(self, NULL, NULL)) { 119 aprint_error_dev(self, "couldn't establish power handler\n"); 120 } 121 } 122 123 static uint32_t 124 gxmci_get_ocr(void *arg) 125 { 126 127 return MMC_OCR_3_2V_3_3V|MMC_OCR_3_3V_3_4V; 128 } 129 130 static int 131 gxmci_set_power(void *arg, uint32_t ocr) 132 { 133 134 return 0; 135 } 136 137 /* 138 * Return non-zero if the card is currently inserted. 139 */ 140 static int 141 gxmci_card_detect(void *arg) 142 { 143 144 return 1; 145 } 146 147 /* 148 * Return non-zero if the card is currently write-protected. 149 */ 150 static int 151 gxmci_write_protect(void *arg) 152 { 153 154 return 0; 155 } 156