xref: /netbsd-src/sys/arch/hpcarm/dev/nbpmci.c (revision 2388feef6162e5f55bc0fbaaa9d32d8dfc8354a3)
1*2388feefSnonaka /*	$NetBSD: nbpmci.c,v 1.2 2012/01/21 19:44:29 nonaka Exp $	*/
2587ef940Skiyohara 
3587ef940Skiyohara /*-
4*2388feefSnonaka  * Copyright (C) 2007 NONAKA Kimihiro <nonaka@netbsd.org>
5587ef940Skiyohara  * All rights reserved.
6587ef940Skiyohara  *
7587ef940Skiyohara  * Redistribution and use in source and binary forms, with or without
8587ef940Skiyohara  * modification, are permitted provided that the following conditions
9587ef940Skiyohara  * are met:
10587ef940Skiyohara  * 1. Redistributions of source code must retain the above copyright
11587ef940Skiyohara  *    notice, this list of conditions and the following disclaimer.
12587ef940Skiyohara  * 2. Redistributions in binary form must reproduce the above copyright
13587ef940Skiyohara  *    notice, this list of conditions and the following disclaimer in the
14587ef940Skiyohara  *    documentation and/or other materials provided with the distribution.
15587ef940Skiyohara  *
16*2388feefSnonaka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17*2388feefSnonaka  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18*2388feefSnonaka  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19*2388feefSnonaka  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20*2388feefSnonaka  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21*2388feefSnonaka  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22*2388feefSnonaka  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23*2388feefSnonaka  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24*2388feefSnonaka  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25*2388feefSnonaka  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26587ef940Skiyohara  */
27587ef940Skiyohara 
28587ef940Skiyohara #include <sys/cdefs.h>
29*2388feefSnonaka __KERNEL_RCSID(0, "$NetBSD: nbpmci.c,v 1.2 2012/01/21 19:44:29 nonaka Exp $");
30587ef940Skiyohara 
31587ef940Skiyohara #include <sys/param.h>
32587ef940Skiyohara #include <sys/device.h>
33587ef940Skiyohara 
34587ef940Skiyohara #include <machine/platid.h>
35587ef940Skiyohara #include <machine/platid_mask.h>
36587ef940Skiyohara 
37587ef940Skiyohara #include <arm/xscale/pxa2x0var.h>
38587ef940Skiyohara #include <arm/xscale/pxa2x0_gpio.h>
39587ef940Skiyohara #include <arm/xscale/pxa2x0_mci.h>
40587ef940Skiyohara 
41587ef940Skiyohara #include <dev/sdmmc/sdmmcreg.h>
42587ef940Skiyohara 
43587ef940Skiyohara 
44587ef940Skiyohara static int pxamci_match(device_t, cfdata_t, void *);
45587ef940Skiyohara static void pxamci_attach(device_t, device_t, void *);
46587ef940Skiyohara 
47587ef940Skiyohara static int nbpmci_intr(void *);
48587ef940Skiyohara 
49587ef940Skiyohara static uint32_t nbpmci_get_ocr(void *);
50587ef940Skiyohara static int nbpmci_set_power(void *, uint32_t);
51587ef940Skiyohara static int nbpmci_card_detect(void *);
52587ef940Skiyohara static int nbpmci_write_protect(void *);
53587ef940Skiyohara 
54587ef940Skiyohara CFATTACH_DECL_NEW(nbpmci, sizeof(struct pxamci_softc),
55587ef940Skiyohara     pxamci_match, pxamci_attach, NULL, NULL);
56587ef940Skiyohara 
57587ef940Skiyohara /* ARGSUSED */
58587ef940Skiyohara static int
pxamci_match(device_t parent,cfdata_t match,void * aux)59587ef940Skiyohara pxamci_match(device_t parent, cfdata_t match, void *aux)
60587ef940Skiyohara {
61587ef940Skiyohara 	struct pxaip_attach_args *pxa = aux;
62587ef940Skiyohara 
63587ef940Skiyohara 	if (strcmp(pxa->pxa_name, match->cf_name) != 0 ||
64587ef940Skiyohara 	    !platid_match(&platid, &platid_mask_MACH_PSIONTEKLOGIX_NETBOOK_PRO))
65587ef940Skiyohara 		return 0;
66587ef940Skiyohara 
67587ef940Skiyohara 	pxa->pxa_size = PXA2X0_MMC_SIZE;
68587ef940Skiyohara 
69587ef940Skiyohara 	return 1;
70587ef940Skiyohara }
71587ef940Skiyohara 
72587ef940Skiyohara /* ARGSUSED */
73587ef940Skiyohara static void
pxamci_attach(device_t parent,device_t self,void * aux)74587ef940Skiyohara pxamci_attach(device_t parent, device_t self, void *aux)
75587ef940Skiyohara {
76587ef940Skiyohara 	struct pxamci_softc *sc = device_private(self);
77587ef940Skiyohara 	struct pxaip_attach_args *pxa = aux;
78587ef940Skiyohara 	void *ih;
79587ef940Skiyohara 
80587ef940Skiyohara 	pxa2x0_gpio_set_function(9, GPIO_IN);
81587ef940Skiyohara 	ih = pxa2x0_gpio_intr_establish(9, IST_EDGE_BOTH, IPL_BIO,
82587ef940Skiyohara 	    nbpmci_intr, sc);
83587ef940Skiyohara 	if (ih == NULL) {
84587ef940Skiyohara 		aprint_error_dev(self,
85587ef940Skiyohara 		    "unable to establish card detect interrupt\n");
86587ef940Skiyohara 		return;
87587ef940Skiyohara 	}
88587ef940Skiyohara 
89587ef940Skiyohara 	sc->sc_tag.cookie = sc;
90587ef940Skiyohara 	sc->sc_tag.get_ocr = nbpmci_get_ocr;
91587ef940Skiyohara 	sc->sc_tag.set_power = nbpmci_set_power;
92587ef940Skiyohara 	sc->sc_tag.card_detect = nbpmci_card_detect;
93587ef940Skiyohara 	sc->sc_tag.write_protect = nbpmci_write_protect;
94587ef940Skiyohara 	sc->sc_caps = 0;
95587ef940Skiyohara 
96587ef940Skiyohara 	if (pxamci_attach_sub(self, pxa))
97587ef940Skiyohara 		aprint_error_dev(self, "unable to attach MMC controller\n");
98587ef940Skiyohara 
99587ef940Skiyohara 	if (!pmf_device_register(self, NULL, NULL))
100587ef940Skiyohara 		aprint_error_dev(self, "couldn't establish power handler\n");
101587ef940Skiyohara }
102587ef940Skiyohara 
103587ef940Skiyohara static int
nbpmci_intr(void * arg)104587ef940Skiyohara nbpmci_intr(void *arg)
105587ef940Skiyohara {
106587ef940Skiyohara 	struct pxamci_softc *sc = (struct pxamci_softc *)arg;
107587ef940Skiyohara 
108587ef940Skiyohara 	pxa2x0_gpio_clear_intr(9);
109587ef940Skiyohara 
110587ef940Skiyohara 	pxamci_card_detect_event(sc);
111587ef940Skiyohara 
112587ef940Skiyohara 	return 1;
113587ef940Skiyohara }
114587ef940Skiyohara 
115587ef940Skiyohara /* ARGSUSED */
116587ef940Skiyohara static uint32_t
nbpmci_get_ocr(void * arg)117587ef940Skiyohara nbpmci_get_ocr(void *arg)
118587ef940Skiyohara {
119587ef940Skiyohara 
120587ef940Skiyohara 	return MMC_OCR_3_2V_3_3V|MMC_OCR_3_3V_3_4V;
121587ef940Skiyohara }
122587ef940Skiyohara 
123587ef940Skiyohara /* ARGSUSED */
124587ef940Skiyohara static int
nbpmci_set_power(void * arg,uint32_t ocr)125587ef940Skiyohara nbpmci_set_power(void *arg, uint32_t ocr)
126587ef940Skiyohara {
127587ef940Skiyohara 
128587ef940Skiyohara //	nbp_pcon_command(I2C_SETMMCPOWER, vdd_bits ? 1 : 0, 0, NULL);
129587ef940Skiyohara 	return 0;
130587ef940Skiyohara }
131587ef940Skiyohara 
132587ef940Skiyohara /*
133587ef940Skiyohara  * Return non-zero if the card is currently inserted.
134587ef940Skiyohara  */
135587ef940Skiyohara /* ARGSUSED */
136587ef940Skiyohara static int
nbpmci_card_detect(void * arg)137587ef940Skiyohara nbpmci_card_detect(void *arg)
138587ef940Skiyohara {
139587ef940Skiyohara 
140587ef940Skiyohara 	if (pxa2x0_gpio_get_bit(9))
141587ef940Skiyohara 		return 0;
142587ef940Skiyohara 	return 1;
143587ef940Skiyohara }
144587ef940Skiyohara 
145587ef940Skiyohara /*
146587ef940Skiyohara  * Return non-zero if the card is currently write-protected.
147587ef940Skiyohara  */
148587ef940Skiyohara /* ARGSUSED */
149587ef940Skiyohara static int
nbpmci_write_protect(void * arg)150587ef940Skiyohara nbpmci_write_protect(void *arg)
151587ef940Skiyohara {
152587ef940Skiyohara 
153587ef940Skiyohara 	return 0;
154587ef940Skiyohara }
155