1 /* $NetBSD: gxmci.c,v 1.1 2009/04/21 03:00:30 nonaka Exp $ */
4 * Copyright (c) 2007 NONAKA Kimihiro <nonaka@netbsd.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: gxmci.c,v 1.1 2009/04/21 03:00:30 nonaka Exp $");
32 #include <sys/param.h>
33 #include <sys/device.h>
34 #include <sys/systm.h>
36 #include <machine/bus.h>
37 #include <machine/intr.h>
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>
45 #include <dev/sdmmc/sdmmcreg.h>
47 #if defined(PXAMCI_DEBUG)
48 #define DPRINTF(s) printf s
54 struct pxamci_softc sc
;
57 static int pxamci_match(device_t
, cfdata_t
, void *);
58 static void pxamci_attach(device_t
, device_t
, void *);
60 CFATTACH_DECL_NEW(gxmci
, sizeof(struct gxmci_softc
),
61 pxamci_match
, pxamci_attach
, NULL
, NULL
);
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 *);
69 pxamci_match(device_t parent
, cfdata_t match
, void *aux
)
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 */
77 struct pxa2x0_gpioconf
*gpioconf
;
81 if (strcmp(pxa
->pxa_name
, match
->cf_name
) != 0)
85 * Check GPIO configuration. If you use these, it is sure already
86 * to have been set by gxio.
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
))
96 pxa
->pxa_size
= PXA2X0_MMC_SIZE
;
102 pxamci_attach(device_t parent
, device_t self
, void *aux
)
104 struct gxmci_softc
*sc
= device_private(self
);
105 struct pxaip_attach_args
*pxa
= aux
;
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
;
114 if (pxamci_attach_sub(self
, pxa
)) {
115 aprint_error_dev(self
, "unable to attach MMC controller\n");
118 if (!pmf_device_register(self
, NULL
, NULL
)) {
119 aprint_error_dev(self
, "couldn't establish power handler\n");
124 gxmci_get_ocr(void *arg
)
127 return MMC_OCR_3_2V_3_3V
|MMC_OCR_3_3V_3_4V
;
131 gxmci_set_power(void *arg
, uint32_t ocr
)
138 * Return non-zero if the card is currently inserted.
141 gxmci_card_detect(void *arg
)
148 * Return non-zero if the card is currently write-protected.
151 gxmci_write_protect(void *arg
)