1 /* $NetBSD: nbpmci.c,v 1.2 2012/01/21 19:44:29 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 AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: nbpmci.c,v 1.2 2012/01/21 19:44:29 nonaka Exp $");
30
31 #include <sys/param.h>
32 #include <sys/device.h>
33
34 #include <machine/platid.h>
35 #include <machine/platid_mask.h>
36
37 #include <arm/xscale/pxa2x0var.h>
38 #include <arm/xscale/pxa2x0_gpio.h>
39 #include <arm/xscale/pxa2x0_mci.h>
40
41 #include <dev/sdmmc/sdmmcreg.h>
42
43
44 static int pxamci_match(device_t, cfdata_t, void *);
45 static void pxamci_attach(device_t, device_t, void *);
46
47 static int nbpmci_intr(void *);
48
49 static uint32_t nbpmci_get_ocr(void *);
50 static int nbpmci_set_power(void *, uint32_t);
51 static int nbpmci_card_detect(void *);
52 static int nbpmci_write_protect(void *);
53
54 CFATTACH_DECL_NEW(nbpmci, sizeof(struct pxamci_softc),
55 pxamci_match, pxamci_attach, NULL, NULL);
56
57 /* ARGSUSED */
58 static int
pxamci_match(device_t parent,cfdata_t match,void * aux)59 pxamci_match(device_t parent, cfdata_t match, void *aux)
60 {
61 struct pxaip_attach_args *pxa = aux;
62
63 if (strcmp(pxa->pxa_name, match->cf_name) != 0 ||
64 !platid_match(&platid, &platid_mask_MACH_PSIONTEKLOGIX_NETBOOK_PRO))
65 return 0;
66
67 pxa->pxa_size = PXA2X0_MMC_SIZE;
68
69 return 1;
70 }
71
72 /* ARGSUSED */
73 static void
pxamci_attach(device_t parent,device_t self,void * aux)74 pxamci_attach(device_t parent, device_t self, void *aux)
75 {
76 struct pxamci_softc *sc = device_private(self);
77 struct pxaip_attach_args *pxa = aux;
78 void *ih;
79
80 pxa2x0_gpio_set_function(9, GPIO_IN);
81 ih = pxa2x0_gpio_intr_establish(9, IST_EDGE_BOTH, IPL_BIO,
82 nbpmci_intr, sc);
83 if (ih == NULL) {
84 aprint_error_dev(self,
85 "unable to establish card detect interrupt\n");
86 return;
87 }
88
89 sc->sc_tag.cookie = sc;
90 sc->sc_tag.get_ocr = nbpmci_get_ocr;
91 sc->sc_tag.set_power = nbpmci_set_power;
92 sc->sc_tag.card_detect = nbpmci_card_detect;
93 sc->sc_tag.write_protect = nbpmci_write_protect;
94 sc->sc_caps = 0;
95
96 if (pxamci_attach_sub(self, pxa))
97 aprint_error_dev(self, "unable to attach MMC controller\n");
98
99 if (!pmf_device_register(self, NULL, NULL))
100 aprint_error_dev(self, "couldn't establish power handler\n");
101 }
102
103 static int
nbpmci_intr(void * arg)104 nbpmci_intr(void *arg)
105 {
106 struct pxamci_softc *sc = (struct pxamci_softc *)arg;
107
108 pxa2x0_gpio_clear_intr(9);
109
110 pxamci_card_detect_event(sc);
111
112 return 1;
113 }
114
115 /* ARGSUSED */
116 static uint32_t
nbpmci_get_ocr(void * arg)117 nbpmci_get_ocr(void *arg)
118 {
119
120 return MMC_OCR_3_2V_3_3V|MMC_OCR_3_3V_3_4V;
121 }
122
123 /* ARGSUSED */
124 static int
nbpmci_set_power(void * arg,uint32_t ocr)125 nbpmci_set_power(void *arg, uint32_t ocr)
126 {
127
128 // nbp_pcon_command(I2C_SETMMCPOWER, vdd_bits ? 1 : 0, 0, NULL);
129 return 0;
130 }
131
132 /*
133 * Return non-zero if the card is currently inserted.
134 */
135 /* ARGSUSED */
136 static int
nbpmci_card_detect(void * arg)137 nbpmci_card_detect(void *arg)
138 {
139
140 if (pxa2x0_gpio_get_bit(9))
141 return 0;
142 return 1;
143 }
144
145 /*
146 * Return non-zero if the card is currently write-protected.
147 */
148 /* ARGSUSED */
149 static int
nbpmci_write_protect(void * arg)150 nbpmci_write_protect(void *arg)
151 {
152
153 return 0;
154 }
155