gxmci.c revision 1.1
1/* $NetBSD: gxmci.c,v 1.1 2009/04/21 03:00:30 nonaka 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.1 2009/04/21 03:00:30 nonaka 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 53struct gxmci_softc { 54 struct pxamci_softc sc; 55}; 56 57static int pxamci_match(device_t, cfdata_t, void *); 58static void pxamci_attach(device_t, device_t, void *); 59 60CFATTACH_DECL_NEW(gxmci, sizeof(struct gxmci_softc), 61 pxamci_match, pxamci_attach, NULL, NULL); 62 63static uint32_t gxmci_get_ocr(void *); 64static int gxmci_set_power(void *, uint32_t); 65static int gxmci_card_detect(void *); 66static int gxmci_write_protect(void *); 67 68static int 69pxamci_match(device_t parent, cfdata_t cf, void *aux) 70{ 71 static struct pxa2x0_gpioconf pxa25x_gxmci_gpioconf[] = { 72 { 8, GPIO_ALT_FN_1_OUT }, /* MMCCS0 */ 73 { 53, GPIO_ALT_FN_1_OUT }, /* MMCLK */ 74 { -1 } 75 }; 76 struct pxa2x0_gpioconf *gpioconf; 77 u_int reg; 78 int i; 79 80 /* 81 * Check GPIO configuration. If you use these, it is sure already 82 * to have been set by gxio. 83 */ 84 gpioconf = 85 CPU_IS_PXA250 ? pxa25x_gxmci_gpioconf : pxa27x_pxamci_gpioconf; 86 for (i = 0; gpioconf[i].pin != -1; i++) { 87 reg = pxa2x0_gpio_get_function(gpioconf[i].pin); 88 if (GPIO_FN(reg) != GPIO_FN(gpioconf[i].value) || 89 GPIO_FN_IS_OUT(reg) != GPIO_FN_IS_OUT(gpioconf[i].value)) 90 return 0; 91 } 92 93 return 1; 94} 95 96static void 97pxamci_attach(device_t parent, device_t self, void *aux) 98{ 99 struct gxmci_softc *sc = device_private(self); 100 struct pxaip_attach_args *pxa = aux; 101 102 sc->sc.sc_tag.cookie = sc; 103 sc->sc.sc_tag.get_ocr = gxmci_get_ocr; 104 sc->sc.sc_tag.set_power = gxmci_set_power; 105 sc->sc.sc_tag.card_detect = gxmci_card_detect; 106 sc->sc.sc_tag.write_protect = gxmci_write_protect; 107 sc->sc.sc_caps = 0; 108 109 if (pxamci_attach_sub(self, pxa)) { 110 aprint_error_dev(self, "unable to attach MMC controller\n"); 111 } 112 113 if (!pmf_device_register(self, NULL, NULL)) { 114 aprint_error_dev(self, "couldn't establish power handler\n"); 115 } 116} 117 118static uint32_t 119gxmci_get_ocr(void *arg) 120{ 121 122 return MMC_OCR_3_2V_3_3V|MMC_OCR_3_3V_3_4V; 123} 124 125static int 126gxmci_set_power(void *arg, uint32_t ocr) 127{ 128 129 return 0; 130} 131 132/* 133 * Return non-zero if the card is currently inserted. 134 */ 135static int 136gxmci_card_detect(void *arg) 137{ 138 139 return 1; 140} 141 142/* 143 * Return non-zero if the card is currently write-protected. 144 */ 145static int 146gxmci_write_protect(void *arg) 147{ 148 149 return 0; 150} 151