4 * Copyright (c) 2006-2008 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$");
32 #include <sys/param.h>
33 #include <sys/device.h>
34 #include <sys/systm.h>
38 #include <machine/intr.h>
40 #include <arm/xscale/pxa2x0cpu.h>
41 #include <arm/xscale/pxa2x0reg.h>
42 #include <arm/xscale/pxa2x0var.h>
43 #include <arm/xscale/pxa2x0_gpio.h>
44 #include <arm/xscale/pxa2x0_mci.h>
46 #include <dev/sdmmc/sdmmcreg.h>
48 #include <zaurus/dev/scoopreg.h>
49 #include <zaurus/dev/scoopvar.h>
51 #include <zaurus/zaurus/zaurus_reg.h>
52 #include <zaurus/zaurus/zaurus_var.h>
54 #if defined(PXAMCI_DEBUG)
55 #define DPRINTF(s) do { printf s; } while (0)
57 #define DPRINTF(s) do {} while (0)
61 struct pxamci_softc sc
;
68 static int pxamci_match(device_t
, cfdata_t
, void *);
69 static void pxamci_attach(device_t
, device_t
, void *);
71 CFATTACH_DECL_NEW(zmci
, sizeof(struct zmci_softc
),
72 pxamci_match
, pxamci_attach
, NULL
, NULL
);
74 static int zmci_intr(void *arg
);
76 static uint32_t zmci_get_ocr(void *);
77 static int zmci_set_power(void *, uint32_t);
78 static int zmci_card_detect(void *);
79 static int zmci_write_protect(void *);
82 pxamci_match(device_t parent
, cfdata_t cf
, void *aux
)
91 pxamci_attach(device_t parent
, device_t self
, void *aux
)
93 struct zmci_softc
*sc
= device_private(self
);
94 struct pxaip_attach_args
*pxa
= aux
;
99 sc
->sc_detect_pin
= C3000_GPIO_SD_DETECT_PIN
;
100 sc
->sc_wp_pin
= C3000_GPIO_SD_WP_PIN
;
101 pxa2x0_gpio_set_function(sc
->sc_detect_pin
, GPIO_IN
);
102 pxa2x0_gpio_set_function(sc
->sc_wp_pin
, GPIO_IN
);
108 /* Establish SD detect interrupt */
109 sc
->sc_detect_ih
= pxa2x0_gpio_intr_establish(sc
->sc_detect_pin
,
110 IST_EDGE_BOTH
, IPL_BIO
, zmci_intr
, sc
);
111 if (sc
->sc_detect_ih
== NULL
) {
112 aprint_error_dev(self
,
113 "unable to establish nSD_DETECT interrupt\n");
117 sc
->sc
.sc_tag
.cookie
= sc
;
118 sc
->sc
.sc_tag
.get_ocr
= zmci_get_ocr
;
119 sc
->sc
.sc_tag
.set_power
= zmci_set_power
;
120 sc
->sc
.sc_tag
.card_detect
= zmci_card_detect
;
121 sc
->sc
.sc_tag
.write_protect
= zmci_write_protect
;
124 if (pxamci_attach_sub(self
, pxa
)) {
125 aprint_error_dev(self
, "unable to attach MMC controller\n");
129 if (!pmf_device_register(self
, NULL
, NULL
)) {
130 aprint_error_dev(self
, "couldn't establish power handler\n");
136 pxa2x0_gpio_intr_disestablish(sc
->sc_detect_ih
);
137 sc
->sc_detect_ih
= NULL
;
143 struct zmci_softc
*sc
= (struct zmci_softc
*)arg
;
145 pxa2x0_gpio_clear_intr(sc
->sc_detect_pin
);
147 pxamci_card_detect_event(&sc
->sc
);
153 zmci_get_ocr(void *arg
)
156 return MMC_OCR_3_2V_3_3V
|MMC_OCR_3_3V_3_4V
;
160 zmci_set_power(void *arg
, uint32_t ocr
)
162 struct zmci_softc
*sc
= (struct zmci_softc
*)arg
;
164 if (ISSET(ocr
, MMC_OCR_3_2V_3_3V
|MMC_OCR_3_3V_3_4V
)) {
165 scoop_set_sdmmc_power(1);
170 printf("%s: zmci_set_power(): unsupported OCR (%#x)\n",
171 device_xname(sc
->sc
.sc_dev
), ocr
);
176 scoop_set_sdmmc_power(0);
181 * Return non-zero if the card is currently inserted.
184 zmci_card_detect(void *arg
)
186 struct zmci_softc
*sc
= (struct zmci_softc
*)arg
;
188 if (!pxa2x0_gpio_get_bit(sc
->sc_detect_pin
))
194 * Return non-zero if the card is currently write-protected.
197 zmci_write_protect(void *arg
)
199 struct zmci_softc
*sc
= (struct zmci_softc
*)arg
;
201 if (pxa2x0_gpio_get_bit(sc
->sc_wp_pin
))