Tue Oct 4 16:06:42 2016 UTC ()
Support am335x's MMCHS2(sdhc@mainbus).
  Tested on Gumstix Pepper 43C.


(kiyohara)
diff -r1.25 -r1.26 src/sys/arch/arm/omap/omap3_sdhc.c

cvs diff -r1.25 -r1.26 src/sys/arch/arm/omap/Attic/omap3_sdhc.c (expand / switch to unified diff)

--- src/sys/arch/arm/omap/Attic/omap3_sdhc.c 2016/10/04 15:51:34 1.25
+++ src/sys/arch/arm/omap/Attic/omap3_sdhc.c 2016/10/04 16:06:42 1.26
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: omap3_sdhc.c,v 1.25 2016/10/04 15:51:34 kiyohara Exp $ */ 1/* $NetBSD: omap3_sdhc.c,v 1.26 2016/10/04 16:06:42 kiyohara Exp $ */
2/*- 2/*-
3 * Copyright (c) 2011 The NetBSD Foundation, Inc. 3 * Copyright (c) 2011 The NetBSD Foundation, Inc.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * This code is derived from software contributed to The NetBSD Foundation 6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Matt Thomas of 3am Software Foundry. 7 * by Matt Thomas of 3am Software Foundry.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -19,48 +19,51 @@ @@ -19,48 +19,51 @@
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE. 28 * POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31#include <sys/cdefs.h> 31#include <sys/cdefs.h>
32__KERNEL_RCSID(0, "$NetBSD: omap3_sdhc.c,v 1.25 2016/10/04 15:51:34 kiyohara Exp $"); 32__KERNEL_RCSID(0, "$NetBSD: omap3_sdhc.c,v 1.26 2016/10/04 16:06:42 kiyohara Exp $");
33 33
34#include "opt_omap.h" 34#include "opt_omap.h"
35#include "edma.h" 35#include "edma.h"
36 36
37#include <sys/param.h> 37#include <sys/param.h>
38#include <sys/systm.h> 38#include <sys/systm.h>
39#include <sys/device.h> 39#include <sys/device.h>
 40#include <sys/errno.h>
40#include <sys/kernel.h> 41#include <sys/kernel.h>
41#include <sys/proc.h> 42#include <sys/proc.h>
42#include <sys/queue.h> 43#include <sys/queue.h>
43#include <sys/mutex.h> 44#include <sys/mutex.h>
44#include <sys/condvar.h> 45#include <sys/condvar.h>
45#include <sys/bus.h> 46#include <sys/bus.h>
46 47
47#include <arm/omap/omap2_obiovar.h> 48#include <arm/omap/omap2_obiovar.h>
48#include <arm/omap/omap2_reg.h> 49#include <arm/omap/omap2_reg.h>
49#include <arm/omap/omap3_sdmmcreg.h> 50#include <arm/omap/omap3_sdmmcreg.h>
50 51
51#ifdef TI_AM335X 52#ifdef TI_AM335X
 53# include <arm/mainbus/mainbus.h>
52# include <arm/omap/am335x_prcm.h> 54# include <arm/omap/am335x_prcm.h>
53# include <arm/omap/omap2_prcm.h> 55# include <arm/omap/omap2_prcm.h>
 56# include <arm/omap/omap_var.h>
54# include <arm/omap/sitara_cm.h> 57# include <arm/omap/sitara_cm.h>
55# include <arm/omap/sitara_cmreg.h> 58# include <arm/omap/sitara_cmreg.h>
56#endif 59#endif
57 60
58#if NEDMA > 0 61#if NEDMA > 0
59# include <arm/omap/omap_edma.h> 62# include <arm/omap/omap_edma.h>
60#endif 63#endif
61 64
62#include <dev/sdmmc/sdhcreg.h> 65#include <dev/sdmmc/sdhcreg.h>
63#include <dev/sdmmc/sdhcvar.h> 66#include <dev/sdmmc/sdhcvar.h>
64#include <dev/sdmmc/sdmmcvar.h> 67#include <dev/sdmmc/sdmmcvar.h>
65 68
66#ifdef TI_AM335X 69#ifdef TI_AM335X
@@ -72,170 +75,254 @@ int om3sdhcdebug = 1; @@ -72,170 +75,254 @@ int om3sdhcdebug = 1;
72#define DPRINTF(n,s) do { if ((n) <= om3sdhcdebug) device_printf s; } while (0) 75#define DPRINTF(n,s) do { if ((n) <= om3sdhcdebug) device_printf s; } while (0)
73#else 76#else
74#define DPRINTF(n,s) do {} while (0) 77#define DPRINTF(n,s) do {} while (0)
75#endif 78#endif
76 79
77 80
78#define CLKD(kz) (sc->sc.sc_clkbase / (kz)) 81#define CLKD(kz) (sc->sc.sc_clkbase / (kz))
79 82
80#define SDHC_READ(sc, reg) \ 83#define SDHC_READ(sc, reg) \
81 bus_space_read_4((sc)->sc_bst, (sc)->sc_sdhc_bsh, (reg)) 84 bus_space_read_4((sc)->sc_bst, (sc)->sc_sdhc_bsh, (reg))
82#define SDHC_WRITE(sc, reg, val) \ 85#define SDHC_WRITE(sc, reg, val) \
83 bus_space_write_4((sc)->sc_bst, (sc)->sc_sdhc_bsh, (reg), (val)) 86 bus_space_write_4((sc)->sc_bst, (sc)->sc_sdhc_bsh, (reg), (val))
84 87
85static int obiosdhc_match(device_t, cfdata_t, void *); 88struct mmchs_softc {
86static void obiosdhc_attach(device_t, device_t, void *); 
87static int obiosdhc_detach(device_t, int); 
88 
89static int obiosdhc_bus_width(struct sdhc_softc *, int); 
90static int obiosdhc_rod(struct sdhc_softc *, int); 
91static int obiosdhc_write_protect(struct sdhc_softc *); 
92static int obiosdhc_card_detect(struct sdhc_softc *); 
93 
94struct obiosdhc_softc { 
95 struct sdhc_softc sc; 89 struct sdhc_softc sc;
 90 bus_addr_t sc_addr;
96 bus_space_tag_t sc_bst; 91 bus_space_tag_t sc_bst;
97 bus_space_handle_t sc_bsh; 92 bus_space_handle_t sc_bsh;
98 bus_space_handle_t sc_hl_bsh; 93 bus_space_handle_t sc_hl_bsh;
99 bus_space_handle_t sc_sdhc_bsh; 94 bus_space_handle_t sc_sdhc_bsh;
100 struct sdhc_host *sc_hosts[1]; 95 struct sdhc_host *sc_hosts[1];
 96 int sc_irq;
101 void *sc_ih; /* interrupt vectoring */ 97 void *sc_ih; /* interrupt vectoring */
102 98
103#if NEDMA > 0 99#if NEDMA > 0
 100 int sc_edmabase;
104 struct edma_channel *sc_edma_tx; 101 struct edma_channel *sc_edma_tx;
105 struct edma_channel *sc_edma_rx; 102 struct edma_channel *sc_edma_rx;
106 uint16_t sc_edma_param_tx[EDMA_MAX_PARAMS]; 103 uint16_t sc_edma_param_tx[EDMA_MAX_PARAMS];
107 uint16_t sc_edma_param_rx[EDMA_MAX_PARAMS]; 104 uint16_t sc_edma_param_rx[EDMA_MAX_PARAMS];
108 kcondvar_t sc_edma_cv; 105 kcondvar_t sc_edma_cv;
109 bus_addr_t sc_edma_fifo; 106 bus_addr_t sc_edma_fifo;
110 bool sc_edma_pending; 107 bool sc_edma_pending;
111 bus_dmamap_t sc_edma_dmamap; 108 bus_dmamap_t sc_edma_dmamap;
112 bus_dma_segment_t sc_edma_segs[1]; 109 bus_dma_segment_t sc_edma_segs[1];
113 void *sc_edma_bbuf; 110 void *sc_edma_bbuf;
114#endif 111#endif
115}; 112};
116 113
 114static int obiosdhc_match(device_t, cfdata_t, void *);
 115static void obiosdhc_attach(device_t, device_t, void *);
 116#ifdef TI_AM335X
 117static int mainbussdhc_match(device_t, cfdata_t, void *);
 118static void mainbussdhc_attach(device_t, device_t, void *);
 119#endif
 120static int mmchs_detach(device_t, int);
 121
 122static int mmchs_attach(struct mmchs_softc *);
 123static void mmchs_init(device_t);
 124
 125static int mmchs_bus_width(struct sdhc_softc *, int);
 126static int mmchs_rod(struct sdhc_softc *, int);
 127static int mmchs_write_protect(struct sdhc_softc *);
 128static int mmchs_card_detect(struct sdhc_softc *);
 129
117#if NEDMA > 0 130#if NEDMA > 0
118static int obiosdhc_edma_init(struct obiosdhc_softc *, unsigned int); 131static int mmchs_edma_init(struct mmchs_softc *, unsigned int);
119static int obiosdhc_edma_xfer_data(struct sdhc_softc *, struct sdmmc_command *); 132static int mmchs_edma_xfer_data(struct sdhc_softc *, struct sdmmc_command *);
120static void obiosdhc_edma_done(void *); 133static void mmchs_edma_done(void *);
121static int obiosdhc_edma_transfer(struct sdhc_softc *, struct sdmmc_command *); 134static int mmchs_edma_transfer(struct sdhc_softc *, struct sdmmc_command *);
122#endif 135#endif
123 136
124#ifdef TI_AM335X 137#ifdef TI_AM335X
125struct am335x_sdhc { 138struct am335x_mmchs {
126 const char *as_name; 139 const char *as_name;
 140 const char *as_parent_name;
127 bus_addr_t as_base_addr; 141 bus_addr_t as_base_addr;
128 int as_intr; 142 int as_intr;
129 struct omap_module as_module; 143 struct omap_module as_module;
130}; 144};
131 145
132static const struct am335x_sdhc am335x_sdhc[] = { 146static const struct am335x_mmchs am335x_mmchs[] = {
133 /* XXX All offset by 0x100 because of the am335x's mmc registers. */ 147 { "MMCHS0", "obio",
134 { "MMCHS0", SDMMC1_BASE_TIAM335X, 64, { AM335X_PRCM_CM_PER, 0x3c } }, 148 SDMMC1_BASE_TIAM335X, 64, { AM335X_PRCM_CM_PER, 0x3c } },
135 { "MMC1", SDMMC2_BASE_TIAM335X, 28, { AM335X_PRCM_CM_PER, 0xf4 } }, 149 { "MMC1", "obio",
136 { "MMCHS2", SDMMC3_BASE_TIAM335X, 29, { AM335X_PRCM_CM_WKUP, 0xf8 } }, 150 SDMMC2_BASE_TIAM335X, 28, { AM335X_PRCM_CM_PER, 0xf4 } },
 151 { "MMCHS2", "mainbus",
 152 SDMMC3_BASE_TIAM335X, 29, { AM335X_PRCM_CM_PER, 0xf8 } },
137}; 153};
138 154
139struct am335x_padconf { 155struct am335x_padconf {
140 const char *padname; 156 const char *padname;
141 const char *padmode; 157 const char *padmode;
142}; 158};
143const struct am335x_padconf am335x_padconf_mmc1[] = { 159const struct am335x_padconf am335x_padconf_mmc1[] = {
144 { "GPMC_CSn1", "mmc1_clk" }, 160 { "GPMC_CSn1", "mmc1_clk" },
145 { "GPMC_CSn2", "mmc1_cmd" }, 161 { "GPMC_CSn2", "mmc1_cmd" },
146 { "GPMC_AD0", "mmc1_dat0" }, 162 { "GPMC_AD0", "mmc1_dat0" },
147 { "GPMC_AD1", "mmc1_dat1" }, 163 { "GPMC_AD1", "mmc1_dat1" },
148 { "GPMC_AD2", "mmc1_dat2" }, 164 { "GPMC_AD2", "mmc1_dat2" },
149 { "GPMC_AD3", "mmc1_dat3" }, 165 { "GPMC_AD3", "mmc1_dat3" },
150 { "GPMC_AD4", "mmc1_dat4" }, 166 { "GPMC_AD4", "mmc1_dat4" },
151 { "GPMC_AD5", "mmc1_dat5" }, 167 { "GPMC_AD5", "mmc1_dat5" },
152 { "GPMC_AD6", "mmc1_dat6" }, 168 { "GPMC_AD6", "mmc1_dat6" },
153 { "GPMC_AD7", "mmc1_dat7" }, 169 { "GPMC_AD7", "mmc1_dat7" },
154 { NULL, NULL } 170 { NULL, NULL }
155}; 171};
156#endif 172#endif
157 173
158CFATTACH_DECL_NEW(obiosdhc, sizeof(struct obiosdhc_softc), 174CFATTACH_DECL_NEW(obiosdhc, sizeof(struct mmchs_softc),
159 obiosdhc_match, obiosdhc_attach, obiosdhc_detach, NULL); 175 obiosdhc_match, obiosdhc_attach, mmchs_detach, NULL);
160 176
161static int 177static int
162obiosdhc_match(device_t parent, cfdata_t cf, void *aux) 178obiosdhc_match(device_t parent, cfdata_t cf, void *aux)
163{ 179{
164#if defined(OMAP_3430) || defined(OMAP_3530) || defined(OMAP4) 
165 struct obio_attach_args * const oa = aux; 180 struct obio_attach_args * const oa = aux;
166#endif 
167#ifdef TI_AM335X 181#ifdef TI_AM335X
168 struct obio_attach_args * const oa = aux; 
169 size_t i; 182 size_t i;
170#endif 183#endif
171 184
172#if defined(OMAP_3430) 185#if defined(OMAP_3430)
173 if (oa->obio_addr == SDMMC1_BASE_3430 186 if (oa->obio_addr == SDMMC1_BASE_3430
174 || oa->obio_addr == SDMMC2_BASE_3430 187 || oa->obio_addr == SDMMC2_BASE_3430
175 || oa->obio_addr == SDMMC3_BASE_3430) 188 || oa->obio_addr == SDMMC3_BASE_3430)
176 return 1; 189 return 1;
177#elif defined(OMAP_3530) 190#elif defined(OMAP_3530)
178 if (oa->obio_addr == SDMMC1_BASE_3530 191 if (oa->obio_addr == SDMMC1_BASE_3530
179 || oa->obio_addr == SDMMC2_BASE_3530 192 || oa->obio_addr == SDMMC2_BASE_3530
180 || oa->obio_addr == SDMMC3_BASE_3530) 193 || oa->obio_addr == SDMMC3_BASE_3530)
181 return 1; 194 return 1;
182#elif defined(OMAP4) || defined(OMAP5) 195#elif defined(OMAP4) || defined(OMAP5)
183 if (oa->obio_addr == SDMMC1_BASE_4430 196 if (oa->obio_addr == SDMMC1_BASE_4430
184 || oa->obio_addr == SDMMC2_BASE_4430 197 || oa->obio_addr == SDMMC2_BASE_4430
185 || oa->obio_addr == SDMMC3_BASE_4430 198 || oa->obio_addr == SDMMC3_BASE_4430
186 || oa->obio_addr == SDMMC4_BASE_4430 199 || oa->obio_addr == SDMMC4_BASE_4430
187 || oa->obio_addr == SDMMC5_BASE_4430) 200 || oa->obio_addr == SDMMC5_BASE_4430)
188 return 1; 201 return 1;
189#endif 202#endif
190 203
191#ifdef TI_AM335X 204#ifdef TI_AM335X
192 for (i = 0; i < __arraycount(am335x_sdhc); i++) 205 for (i = 0; i < __arraycount(am335x_mmchs); i++)
193 if ((oa->obio_addr == am335x_sdhc[i].as_base_addr) && 206 if (device_is_a(parent, am335x_mmchs[i].as_parent_name) &&
194 (oa->obio_intr == am335x_sdhc[i].as_intr)) 207 (oa->obio_addr == am335x_mmchs[i].as_base_addr) &&
 208 (oa->obio_intr == am335x_mmchs[i].as_intr))
195 return 1; 209 return 1;
196#endif 210#endif
197 211
198 return 0; 212 return 0;
199} 213}
200 214
201static void 215static void
202obiosdhc_attach(device_t parent, device_t self, void *aux) 216obiosdhc_attach(device_t parent, device_t self, void *aux)
203{ 217{
204 struct obiosdhc_softc * const sc = device_private(self); 218 struct mmchs_softc * const sc = device_private(self);
205 struct obio_attach_args * const oa = aux; 219 struct obio_attach_args * const oa = aux;
206 prop_dictionary_t prop = device_properties(self); 220 int error;
207 uint32_t clkd, stat; 221
208 int error, timo, clksft, n; 222 sc->sc.sc_dmat = oa->obio_dmat;
209 bool support8bit = false; 223 sc->sc.sc_dev = self;
210 const char *transfer_mode = "PIO"; 224 sc->sc_addr = oa->obio_addr;
211#if defined(OMAP4) 225 sc->sc_bst = oa->obio_iot;
212 uint32_t v; 226 sc->sc_irq = oa->obio_intr;
213 int x, y; 227#if defined(TI_AM335X)
 228 sc->sc_edmabase = oa->obio_edmabase;
 229#endif
 230
 231#if defined(TI_AM335X)
 232 error = bus_space_map(sc->sc_bst, oa->obio_addr + OMAP4_SDMMC_HL_SIZE,
 233 oa->obio_size - OMAP4_SDMMC_HL_SIZE, 0, &sc->sc_bsh);
 234#elif defined(OMAP4)
 235 error = bus_space_map(sc->sc_bst, oa->obio_addr, oa->obio_size, 0,
 236 &sc->sc_hl_bsh);
 237 if (error == 0)
 238 error = bus_space_subregion(sc->sc_bst, sc->sc_hl_bsh,
 239 OMAP4_SDMMC_HL_SIZE, oa->obio_size - OMAP4_SDMMC_HL_SIZE,
 240 &sc->sc_bsh);
 241#else
 242 error = bus_space_map(sc->sc_bst, oa->obio_addr, oa->obio_size, 0,
 243 &sc->sc_bsh);
214#endif 244#endif
 245 if (error != 0) {
 246 aprint_error("can't map registers: %d\n", error);
 247 return;
 248 }
 249
 250 if (mmchs_attach(sc) == 0)
 251 mmchs_init(self);
 252}
 253
215#ifdef TI_AM335X 254#ifdef TI_AM335X
216 size_t i; 255CFATTACH_DECL_NEW(mainbussdhc, sizeof(struct mmchs_softc),
 256 mainbussdhc_match, mainbussdhc_attach, mmchs_detach, NULL);
 257
 258static int
 259mainbussdhc_match(device_t parent, cfdata_t cf, void *aux)
 260{
 261 struct mainbus_attach_args * const mb = aux;
 262 int i;
 263
 264 for (i = 0; i < __arraycount(am335x_mmchs); i++)
 265 if (device_is_a(parent, am335x_mmchs[i].as_parent_name) &&
 266 (mb->mb_iobase == am335x_mmchs[i].as_base_addr) &&
 267 (mb->mb_irq == am335x_mmchs[i].as_intr))
 268 return 1;
 269 return 0;
 270}
 271
 272static void
 273mainbussdhc_attach(device_t parent, device_t self, void *aux)
 274{
 275 struct mmchs_softc * const sc = device_private(self);
 276 struct mainbus_attach_args * const mb = aux;
 277 int error;
 278
 279 sc->sc.sc_dmat = &omap_bus_dma_tag;
 280 sc->sc.sc_dev = self;
 281 sc->sc_addr = mb->mb_iobase;
 282 sc->sc_bst = &omap_bs_tag;
 283 sc->sc_irq = mb->mb_irq;
 284 sc->sc_edmabase = -1;
 285
 286 error = bus_space_map(sc->sc_bst, mb->mb_iobase + OMAP4_SDMMC_HL_SIZE,
 287 mb->mb_iosize - OMAP4_SDMMC_HL_SIZE, 0, &sc->sc_bsh);
 288 if (error != 0) {
 289 aprint_error("can't map registers: %d\n", error);
 290 return;
 291 }
 292
 293 if (mmchs_attach(sc) == 0)
 294 /* Ensure attach prcm, icu and edma. */
 295 config_defer(self, mmchs_init);
 296}
217#endif 297#endif
218 298
 299static int
 300mmchs_attach(struct mmchs_softc *sc)
 301{
 302 device_t dev = sc->sc.sc_dev;
 303 prop_dictionary_t prop = device_properties(dev);
 304 int error;
 305 bool support8bit = false, dualvolt = false;
 306
219 prop_dictionary_get_bool(prop, "8bit", &support8bit); 307 prop_dictionary_get_bool(prop, "8bit", &support8bit);
 308 prop_dictionary_get_bool(prop, "dual-volt", &dualvolt);
220 309
221 sc->sc.sc_dmat = oa->obio_dmat; 
222 sc->sc.sc_dev = self; 
223 sc->sc.sc_flags |= SDHC_FLAG_32BIT_ACCESS; 310 sc->sc.sc_flags |= SDHC_FLAG_32BIT_ACCESS;
224 sc->sc.sc_flags |= SDHC_FLAG_NO_LED_ON; 311 sc->sc.sc_flags |= SDHC_FLAG_NO_LED_ON;
225 sc->sc.sc_flags |= SDHC_FLAG_RSP136_CRC; 312 sc->sc.sc_flags |= SDHC_FLAG_RSP136_CRC;
226 if (support8bit) 313 if (support8bit)
227 sc->sc.sc_flags |= SDHC_FLAG_8BIT_MODE; 314 sc->sc.sc_flags |= SDHC_FLAG_8BIT_MODE;
228#if defined(OMAP_3430) || /* XXX until TI_DM37XX has working omap_devid() */ defined(TI_DM37XX) 315#if defined(OMAP_3430)
229 sc->sc.sc_flags |= SDHC_FLAG_SINGLE_ONLY; 316 sc->sc.sc_flags |= SDHC_FLAG_SINGLE_ONLY;
230#elif defined(OMAP_3530) || defined(TI_DM37XX) 317#elif defined(OMAP_3530) || defined(TI_DM37XX)
231 /* 318 /*
232 * Advisory 2.1.1.128: MMC: Multiple Block Read Operation Issue 319 * Advisory 2.1.1.128: MMC: Multiple Block Read Operation Issue
233 * from "OMAP3530/25/15/03 Applications Processor Silicon Revisions 320 * from "OMAP3530/25/15/03 Applications Processor Silicon Revisions
234 * 3.1.2, 3.1, 3.0, 2.1, and 2.0". 321 * 3.1.2, 3.1, 3.0, 2.1, and 2.0".
235 */ 322 */
236 switch (omap_devid()) { 323 switch (omap_devid()) {
237 case DEVID_OMAP35X_ES10: 324 case DEVID_OMAP35X_ES10:
238 case DEVID_OMAP35X_ES20: 325 case DEVID_OMAP35X_ES20:
239 case DEVID_OMAP35X_ES21: 326 case DEVID_OMAP35X_ES21:
240 case DEVID_AMDM37X_ES10: /* XXXX ? */ 327 case DEVID_AMDM37X_ES10: /* XXXX ? */
241 case DEVID_AMDM37X_ES11: /* XXXX ? */ 328 case DEVID_AMDM37X_ES11: /* XXXX ? */
@@ -248,168 +335,170 @@ obiosdhc_attach(device_t parent, device_ @@ -248,168 +335,170 @@ obiosdhc_attach(device_t parent, device_
248 sc->sc.sc_flags |= SDHC_FLAG_NO_HS_BIT; 335 sc->sc.sc_flags |= SDHC_FLAG_NO_HS_BIT;
249#elif defined(TI_AM335X) 336#elif defined(TI_AM335X)
250 sc->sc.sc_flags |= SDHC_FLAG_WAIT_RESET; 337 sc->sc.sc_flags |= SDHC_FLAG_WAIT_RESET;
251#elif defined(OMAP_4430) 338#elif defined(OMAP_4430)
252 /* 339 /*
253 * MMCHS_HCTL.HSPE Is Not Functional 340 * MMCHS_HCTL.HSPE Is Not Functional
254 * Errata ID: i626 341 * Errata ID: i626
255 * 342 *
256 * Due to design issue MMCHS_HCTL.HSPE bit does not work as intended. 343 * Due to design issue MMCHS_HCTL.HSPE bit does not work as intended.
257 * This means that the configuration must always be the normal speed 344 * This means that the configuration must always be the normal speed
258 * mode configuration (MMCHS_HCTL.HSPE=0). 345 * mode configuration (MMCHS_HCTL.HSPE=0).
259 */ 346 */
260 sc->sc.sc_flags |= SDHC_FLAG_NO_HS_BIT; 347 sc->sc.sc_flags |= SDHC_FLAG_NO_HS_BIT;
261 
262 sc->sc.sc_flags |= SDHC_FLAG_USE_DMA; 
263 sc->sc.sc_flags |= SDHC_FLAG_USE_ADMA2; 
264#endif 348#endif
265 sc->sc.sc_host = sc->sc_hosts; 349 sc->sc.sc_host = sc->sc_hosts;
266 sc->sc.sc_clkbase = 96000; /* 96MHZ */ 350 sc->sc.sc_clkbase = 96000; /* 96MHZ */
267 if (!prop_dictionary_get_uint32(prop, "clkmask", &sc->sc.sc_clkmsk)) 351 if (!prop_dictionary_get_uint32(prop, "clkmask", &sc->sc.sc_clkmsk))
268 sc->sc.sc_clkmsk = 0x0000ffc0; 352 sc->sc.sc_clkmsk = 0x0000ffc0;
269 sc->sc.sc_vendor_rod = obiosdhc_rod; 353 if (sc->sc_addr == SDMMC1_BASE_3530 ||
270 sc->sc.sc_vendor_write_protect = obiosdhc_write_protect; 354 sc->sc_addr == SDMMC1_BASE_TIAM335X ||
271 sc->sc.sc_vendor_card_detect = obiosdhc_card_detect; 355 sc->sc_addr == SDMMC1_BASE_4430 ||
272 sc->sc.sc_vendor_bus_width = obiosdhc_bus_width; 356 dualvolt)
273 sc->sc_bst = oa->obio_iot; 357 sc->sc.sc_caps = SDHC_VOLTAGE_SUPP_3_0V;
274 358 sc->sc.sc_vendor_rod = mmchs_rod;
275 clksft = ffs(sc->sc.sc_clkmsk) - 1; 359 sc->sc.sc_vendor_write_protect = mmchs_write_protect;
 360 sc->sc.sc_vendor_card_detect = mmchs_card_detect;
 361 sc->sc.sc_vendor_bus_width = mmchs_bus_width;
276 362
277#if defined(TI_AM335X) 363 error = bus_space_subregion(sc->sc_bst, sc->sc_bsh,
278 error = bus_space_map(sc->sc_bst, oa->obio_addr + OMAP4_SDMMC_HL_SIZE, 364 OMAP3_SDMMC_SDHC_OFFSET, OMAP3_SDMMC_SDHC_SIZE, &sc->sc_sdhc_bsh);
279 oa->obio_size - OMAP4_SDMMC_HL_SIZE, 0, &sc->sc_bsh); 365 if (error != 0) {
280#elif defined(OMAP4) 366 aprint_error("can't map subregion: %d\n", error);
281 error = bus_space_map(sc->sc_bst, oa->obio_addr, oa->obio_size, 0, 367 return -1;
282 &sc->sc_hl_bsh); 
283 if (!error) 
284 bus_space_subregion(sc->sc_bst, sc->sc_hl_bsh, 
285 OMAP4_SDMMC_HL_SIZE, oa->obio_size - OMAP4_SDMMC_HL_SIZE, 
286 &sc->sc_bsh); 
287#else 
288 error = bus_space_map(sc->sc_bst, oa->obio_addr, oa->obio_size, 0, 
289 &sc->sc_bsh); 
290#endif 
291 if (error) { 
292 aprint_error_dev(self, 
293 "can't map registers: %d\n", error); 
294 return; 
295 } 368 }
296 369
297 bus_space_subregion(sc->sc_bst, sc->sc_bsh, OMAP3_SDMMC_SDHC_OFFSET, 370 aprint_naive("\n");
298 OMAP3_SDMMC_SDHC_SIZE, &sc->sc_sdhc_bsh); 371 aprint_normal(": SDHC controller\n");
 372
 373 return 0;
 374}
 375
 376static void
 377mmchs_init(device_t dev)
 378{
 379 struct mmchs_softc * const sc = device_private(dev);
 380 uint32_t clkd, stat;
 381 int error, timo, clksft, n;
 382#if defined(OMAP4)
 383 uint32_t rev, hwinfo;
 384 int x, y;
 385#elif defined(TI_AM335X)
 386 int i;
 387#endif
299 388
300#if NEDMA > 0 389#if NEDMA > 0
301 if (oa->obio_edmabase != -1) { 390 if (sc->sc_edmabase != -1) {
302 if (obiosdhc_edma_init(sc, oa->obio_edmabase) != 0) 391 if (mmchs_edma_init(sc, sc->sc_edmabase) != 0)
303 goto no_dma; 392 goto no_dma;
304 393
305 cv_init(&sc->sc_edma_cv, "sdhcedma"); 394 cv_init(&sc->sc_edma_cv, "sdhcedma");
306 sc->sc_edma_fifo = oa->obio_addr + 395 sc->sc_edma_fifo = sc->sc_addr +
307#ifdef TI_AM335X 396#ifdef TI_AM335X
308 OMAP4_SDMMC_HL_SIZE + 397 OMAP4_SDMMC_HL_SIZE +
309#endif 398#endif
310 OMAP3_SDMMC_SDHC_OFFSET + SDHC_DATA; 399 OMAP3_SDMMC_SDHC_OFFSET + SDHC_DATA;
311 sc->sc.sc_flags |= SDHC_FLAG_USE_DMA; 400 sc->sc.sc_flags |= SDHC_FLAG_USE_DMA;
312 sc->sc.sc_flags |= SDHC_FLAG_EXTERNAL_DMA; 401 sc->sc.sc_flags |= SDHC_FLAG_EXTERNAL_DMA;
313 sc->sc.sc_flags |= SDHC_FLAG_EXTDMA_DMAEN; 402 sc->sc.sc_flags |= SDHC_FLAG_EXTDMA_DMAEN;
314 sc->sc.sc_vendor_transfer_data_dma = obiosdhc_edma_xfer_data; 403 sc->sc.sc_vendor_transfer_data_dma = mmchs_edma_xfer_data;
315 transfer_mode = "EDMA"; 
316 } 
317no_dma: 
318#endif 
319 if (sc->sc.sc_flags & SDHC_FLAG_USE_ADMA2) 
320 transfer_mode = "ADMA2"; 
321 
322 aprint_naive("\n"); 
323 aprint_normal(": SDHC controller (%s)\n", transfer_mode); 
324 
325#if defined(OMAP4) 
326 v = bus_space_read_4(sc->sc_bst, sc->sc_hl_bsh, MMCHS_HL_REV); 
327 aprint_normal_dev(sc->sc.sc_dev, "IP Rev 0x%08x", v); 
328 v = bus_space_read_4(sc->sc_bst, sc->sc_hl_bsh, MMCHS_HL_HWINFO); 
329 aprint_normal("%s", v & HL_HWINFO_RETMODE ? ", Retention Mode" : ""); 
330 x = 0; 
331 switch (v & HL_HWINFO_MEM_SIZE_MASK) { 
332 case HL_HWINFO_MEM_SIZE_512: x = 512; y = 512; break; 
333 case HL_HWINFO_MEM_SIZE_1024: x = 1024; y = 1024; break; 
334 case HL_HWINFO_MEM_SIZE_2048: x = 2048; y = 2048; break; 
335 case HL_HWINFO_MEM_SIZE_4096: x = 4096; y = 2048; break; 
336 } 
337 if (x != 0) 
338 aprint_normal(", %d byte FIFO, max block length %d bytes", 
339 x, y); 
340 aprint_normal("\n"); 
341#endif 
342 
343#if NEDMA > 0 
344 if (strcmp(transfer_mode, "EDMA") == 0) 
345 aprint_normal_dev(sc->sc.sc_dev, 404 aprint_normal_dev(sc->sc.sc_dev,
346 "EDMA tx channel %d, rx channel %d\n", 405 "EDMA tx channel %d, rx channel %d\n",
347 edma_channel_index(sc->sc_edma_tx), 406 edma_channel_index(sc->sc_edma_tx),
348 edma_channel_index(sc->sc_edma_rx)); 407 edma_channel_index(sc->sc_edma_rx));
 408 }
 409no_dma:
349#endif 410#endif
350 411
 412 /* XXXXXX: Turn-on regulator via I2C. */
 413 /* XXXXXX: And enable ICLOCK/FCLOCK. */
 414
351#ifdef TI_AM335X 415#ifdef TI_AM335X
352 /* XXX Not really AM335X-specific. */ 416 /* XXX Not really AM335X-specific. */
353 for (i = 0; i < __arraycount(am335x_sdhc); i++) 417 for (i = 0; i < __arraycount(am335x_mmchs); i++)
354 if ((oa->obio_addr == am335x_sdhc[i].as_base_addr) && 418 if ((sc->sc_addr == am335x_mmchs[i].as_base_addr) &&
355 (oa->obio_intr == am335x_sdhc[i].as_intr)) { 419 (sc->sc_irq == am335x_mmchs[i].as_intr)) {
356 prcm_module_enable(&am335x_sdhc[i].as_module); 420 prcm_module_enable(&am335x_mmchs[i].as_module);
357 break; 421 break;
358 } 422 }
359 KASSERT(i < __arraycount(am335x_sdhc)); 423 KASSERT(i < __arraycount(am335x_mmchs));
360 424
361 if (oa->obio_addr == SDMMC2_BASE_TIAM335X) { 425 if (sc->sc_addr == SDMMC2_BASE_TIAM335X) {
362 const char *mode; 426 const char *mode;
363 u_int state; 427 u_int state;
364 428
365 const struct am335x_padconf *padconf = am335x_padconf_mmc1; 429 const struct am335x_padconf *padconf = am335x_padconf_mmc1;
366 for (i = 0; padconf[i].padname; i++) { 430 for (i = 0; padconf[i].padname; i++) {
367 const char *padname = padconf[i].padname; 431 const char *padname = padconf[i].padname;
368 const char *padmode = padconf[i].padmode; 432 const char *padmode = padconf[i].padmode;
369 if (sitara_cm_padconf_get(padname, &mode, &state) == 0) { 433 if (sitara_cm_padconf_get(padname, &mode, &state) == 0)
370 aprint_debug_dev(self, "%s mode %s state %d\n", 434 aprint_debug_dev(dev, "%s mode %s state %d\n",
371 padname, mode, state); 435 padname, mode, state);
372 } 
373 if (sitara_cm_padconf_set(padname, padmode, 436 if (sitara_cm_padconf_set(padname, padmode,
374 (1 << 4) | (1 << 5)) != 0) { 437 (1 << 4) | (1 << 5)) != 0) {
375 aprint_error_dev(self, "can't switch %s pad from %s to %s\n", 438 aprint_error_dev(dev,
 439 "can't switch %s pad from %s to %s\n",
376 padname, mode, padmode); 440 padname, mode, padmode);
377 return; 441 return;
378 } 442 }
379 } 443 }
380 } 444 }
381#endif 445#endif
382 446
383 /* XXXXXX: Turn-on regulator via I2C. */ 447#if defined(OMAP4)
384 /* XXXXXX: And enable ICLOCK/FCLOCK. */ 448 rev = bus_space_read_4(sc->sc_bst, sc->sc_hl_bsh, MMCHS_HL_REV);
 449 hwinfo = bus_space_read_4(sc->sc_bst, sc->sc_hl_bsh, MMCHS_HL_HWINFO);
 450 x = 0;
 451 switch (hwinfo & HL_HWINFO_MEM_SIZE_MASK) {
 452 case HL_HWINFO_MEM_SIZE_512: x = 512; y = 512; break;
 453 case HL_HWINFO_MEM_SIZE_1024: x = 1024; y = 1024; break;
 454 case HL_HWINFO_MEM_SIZE_2048: x = 2048; y = 2048; break;
 455 case HL_HWINFO_MEM_SIZE_4096: x = 4096; y = 2048; break;
 456 }
 457 if (hwinfo & HL_HWINFO_MADMA_EN) {
 458 sc->sc.sc_flags |= SDHC_FLAG_USE_DMA;
 459 sc->sc.sc_flags |= SDHC_FLAG_USE_ADMA2;
 460 }
 461 aprint_normal_dev(sc->sc.sc_dev, "IP Rev 0x%08x%s",
 462 rev, hwinfo & HL_HWINFO_RETMODE ? ", Retention Mode" : "");
 463 if (x != 0)
 464 aprint_normal(", %d byte FIFO, max block length %d bytes",
 465 x, y);
 466 aprint_normal("\n");
 467#endif
 468
 469 SDHC_WRITE(sc, SDHC_CAPABILITIES,
 470 SDHC_READ(sc, SDHC_CAPABILITIES) | SDHC_VOLTAGE_SUPP_1_8V);
 471 if (sc->sc.sc_caps & SDHC_VOLTAGE_SUPP_3_0V)
 472 SDHC_WRITE(sc, SDHC_CAPABILITIES,
 473 SDHC_READ(sc, SDHC_CAPABILITIES) | SDHC_VOLTAGE_SUPP_3_0V);
385 474
386 /* MMCHS Soft reset */ 475 /* MMCHS Soft reset */
387 bus_space_write_4(sc->sc_bst, sc->sc_bsh, MMCHS_SYSCONFIG, 476 bus_space_write_4(sc->sc_bst, sc->sc_bsh, MMCHS_SYSCONFIG,
388 SYSCONFIG_SOFTRESET); 477 SYSCONFIG_SOFTRESET);
389 timo = 3000000; /* XXXX 3 sec. */ 478 timo = 3000000; /* XXXX 3 sec. */
390 while (timo--) { 479 while (timo--) {
391 if (bus_space_read_4(sc->sc_bst, sc->sc_bsh, MMCHS_SYSSTATUS) & 480 if (bus_space_read_4(sc->sc_bst, sc->sc_bsh, MMCHS_SYSSTATUS) &
392 SYSSTATUS_RESETDONE) 481 SYSSTATUS_RESETDONE)
393 break; 482 break;
394 delay(1); 483 delay(1);
395 } 484 }
396 if (timo == 0) 485 if (timo == 0)
397 aprint_error_dev(self, "Soft reset timeout\n"); 486 aprint_error_dev(self, "Soft reset timeout\n");
398 bus_space_write_4(sc->sc_bst, sc->sc_bsh, MMCHS_SYSCONFIG, 487 bus_space_write_4(sc->sc_bst, sc->sc_bsh, MMCHS_SYSCONFIG,
399 SYSCONFIG_ENAWAKEUP | SYSCONFIG_AUTOIDLE | SYSCONFIG_SIDLEMODE_AUTO | 488 SYSCONFIG_ENAWAKEUP | SYSCONFIG_AUTOIDLE | SYSCONFIG_SIDLEMODE_AUTO |
400 SYSCONFIG_CLOCKACTIVITY_FCLK | SYSCONFIG_CLOCKACTIVITY_ICLK); 489 SYSCONFIG_CLOCKACTIVITY_FCLK | SYSCONFIG_CLOCKACTIVITY_ICLK);
401 490
402 sc->sc_ih = intr_establish(oa->obio_intr, IPL_SDMMC, IST_LEVEL, 491 sc->sc_ih = intr_establish(oa->obio_intr, IPL_VM, IST_LEVEL,
403 sdhc_intr, &sc->sc); 492 sdhc_intr, &sc->sc);
404 if (sc->sc_ih == NULL) { 493 if (sc->sc_ih == NULL) {
405 aprint_error_dev(self, "failed to establish interrupt %d\n", 494 aprint_error_dev(self, "failed to establish interrupt %d\n",
406 oa->obio_intr); 495 oa->obio_intr);
407 goto fail; 496 goto fail;
408 } 497 }
409 498
410 error = sdhc_host_found(&sc->sc, sc->sc_bst, sc->sc_sdhc_bsh, 499 error = sdhc_host_found(&sc->sc, sc->sc_bst, sc->sc_sdhc_bsh,
411 oa->obio_size - OMAP3_SDMMC_SDHC_OFFSET); 500 oa->obio_size - OMAP3_SDMMC_SDHC_OFFSET);
412 if (error != 0) { 501 if (error != 0) {
413 aprint_error_dev(self, "couldn't initialize host, error=%d\n", 502 aprint_error_dev(self, "couldn't initialize host, error=%d\n",
414 error); 503 error);
415 goto fail; 504 goto fail;
@@ -466,120 +555,111 @@ no_dma: @@ -466,120 +555,111 @@ no_dma:
466 SDHC_WRITE(sc, SDHC_CLOCK_CTL, 555 SDHC_WRITE(sc, SDHC_CLOCK_CTL,
467 SDHC_READ(sc, SDHC_CLOCK_CTL) & ~SDHC_SDCLK_ENABLE); 556 SDHC_READ(sc, SDHC_CLOCK_CTL) & ~SDHC_SDCLK_ENABLE);
468 SDHC_WRITE(sc, SDHC_CLOCK_CTL, 557 SDHC_WRITE(sc, SDHC_CLOCK_CTL,
469 SDHC_READ(sc, SDHC_CLOCK_CTL) & ~sc->sc.sc_clkmsk); 558 SDHC_READ(sc, SDHC_CLOCK_CTL) & ~sc->sc.sc_clkmsk);
470 SDHC_WRITE(sc, SDHC_CLOCK_CTL, 559 SDHC_WRITE(sc, SDHC_CLOCK_CTL,
471 SDHC_READ(sc, SDHC_CLOCK_CTL) | CLKD(150) << clksft); 560 SDHC_READ(sc, SDHC_CLOCK_CTL) | CLKD(150) << clksft);
472 timo = 3000000; /* XXXX 3 sec. */ 561 timo = 3000000; /* XXXX 3 sec. */
473 while (--timo) { 562 while (--timo) {
474 if (SDHC_READ(sc, SDHC_CLOCK_CTL) & SDHC_INTCLK_STABLE) 563 if (SDHC_READ(sc, SDHC_CLOCK_CTL) & SDHC_INTCLK_STABLE)
475 break; 564 break;
476 delay(1); 565 delay(1);
477 } 566 }
478 if (timo == 0) 567 if (timo == 0)
479 aprint_error_dev(self, "ICS timeout(2)\n"); 568 aprint_error_dev(dev, "ICS timeout\n");
480 SDHC_WRITE(sc, SDHC_CLOCK_CTL, 569 SDHC_WRITE(sc, SDHC_CLOCK_CTL,
481 SDHC_READ(sc, SDHC_CLOCK_CTL) | SDHC_SDCLK_ENABLE); 570 SDHC_READ(sc, SDHC_CLOCK_CTL) | SDHC_SDCLK_ENABLE);
482 571
483 if (sc->sc.sc_flags & SDHC_FLAG_USE_ADMA2) 572 if (sc->sc.sc_flags & SDHC_FLAG_USE_ADMA2)
484 bus_space_write_4(sc->sc_bst, sc->sc_bsh, MMCHS_CON, 573 bus_space_write_4(sc->sc_bst, sc->sc_bsh, MMCHS_CON,
485 bus_space_read_4(sc->sc_bst, sc->sc_bsh, MMCHS_CON) | 574 bus_space_read_4(sc->sc_bst, sc->sc_bsh, MMCHS_CON) |
486 CON_MNS); 575 CON_MNS);
487 
488 return; 
489 
490fail: 
491 if (sc->sc_ih) { 
492 intr_disestablish(sc->sc_ih); 
493 sc->sc_ih = NULL; 
494 } 
495 bus_space_unmap(sc->sc_bst, sc->sc_bsh, oa->obio_size); 
496} 576}
497 577
498static int 578static int
499obiosdhc_detach(device_t self, int flags) 579mmchs_detach(device_t self, int flags)
500{ 580{
501// struct obiosdhc_softc *sc = device_private(self); 581// struct mmchs_softc *sc = device_private(self);
502 int error; 582 int error;
503 583
504 error = config_detach_children(self, flags); 584 error = config_detach_children(self, flags);
505 585
506 /* XXXXXX: Regurator turn-off via I2C. */ 586 /* XXXXXX: Regurator turn-off via I2C. */
507 /* XXXXXX: And disable ICLOCK/FCLOCK. */ 587 /* XXXXXX: And disable ICLOCK/FCLOCK. */
508 588
509 return error; 589 return error;
510} 590}
511 591
512static int 592static int
513obiosdhc_rod(struct sdhc_softc *sc, int on) 593mmchs_rod(struct sdhc_softc *sc, int on)
514{ 594{
515 struct obiosdhc_softc *osc = (struct obiosdhc_softc *)sc; 595 struct mmchs_softc *hmsc = (struct mmchs_softc *)sc;
516 uint32_t con; 596 uint32_t con;
517 597
518 con = bus_space_read_4(osc->sc_bst, osc->sc_bsh, MMCHS_CON); 598 con = bus_space_read_4(hmsc->sc_bst, hmsc->sc_bsh, MMCHS_CON);
519 if (on) 599 if (on)
520 con |= CON_OD; 600 con |= CON_OD;
521 else 601 else
522 con &= ~CON_OD; 602 con &= ~CON_OD;
523 bus_space_write_4(osc->sc_bst, osc->sc_bsh, MMCHS_CON, con); 603 bus_space_write_4(hmsc->sc_bst, hmsc->sc_bsh, MMCHS_CON, con);
524 604
525 return 0; 605 return 0;
526} 606}
527 607
528static int 608static int
529obiosdhc_write_protect(struct sdhc_softc *sc) 609mmchs_write_protect(struct sdhc_softc *sc)
530{ 610{
531 611
532 /* Maybe board dependent, using GPIO. Get GPIO-pin from prop? */ 612 /* Maybe board dependent, using GPIO. Get GPIO-pin from prop? */
533 return 0; /* XXXXXXX */ 613 return 0; /* XXXXXXX */
534} 614}
535 615
536static int 616static int
537obiosdhc_card_detect(struct sdhc_softc *sc) 617mmchs_card_detect(struct sdhc_softc *sc)
538{ 618{
539 619
540 /* Maybe board dependent, using GPIO. Get GPIO-pin from prop? */ 620 /* Maybe board dependent, using GPIO. Get GPIO-pin from prop? */
541 return 1; /* XXXXXXXX */ 621 return 1; /* XXXXXXXX */
542} 622}
543 623
544static int 624static int
545obiosdhc_bus_width(struct sdhc_softc *sc, int width) 625mmchs_bus_width(struct sdhc_softc *sc, int width)
546{ 626{
547 struct obiosdhc_softc *osc = (struct obiosdhc_softc *)sc; 627 struct mmchs_softc *hmsc = (struct mmchs_softc *)sc;
548 uint32_t con; 628 uint32_t con;
549 629
550 con = bus_space_read_4(osc->sc_bst, osc->sc_bsh, MMCHS_CON); 630 con = bus_space_read_4(hmsc->sc_bst, hmsc->sc_bsh, MMCHS_CON);
551 if (width == 8) { 631 if (width == 8) {
552 con |= CON_DW8; 632 con |= CON_DW8;
553 } else { 633 } else {
554 con &= ~CON_DW8; 634 con &= ~CON_DW8;
555 } 635 }
556 bus_space_write_4(osc->sc_bst, osc->sc_bsh, MMCHS_CON, con); 636 bus_space_write_4(hmsc->sc_bst, hmsc->sc_bsh, MMCHS_CON, con);
557 637
558 return 0; 638 return 0;
559} 639}
560 640
561#if NEDMA > 0 641#if NEDMA > 0
562static int 642static int
563obiosdhc_edma_init(struct obiosdhc_softc *sc, unsigned int edmabase) 643mmchs_edma_init(struct mmchs_softc *sc, unsigned int edmabase)
564{ 644{
565 int i, error, rseg; 645 int i, error, rseg;
566 646
567 /* Request tx and rx DMA channels */ 647 /* Request tx and rx DMA channels */
568 sc->sc_edma_tx = edma_channel_alloc(EDMA_TYPE_DMA, edmabase + 0, 648 sc->sc_edma_tx = edma_channel_alloc(EDMA_TYPE_DMA, edmabase + 0,
569 obiosdhc_edma_done, sc); 649 mmchs_edma_done, sc);
570 KASSERT(sc->sc_edma_tx != NULL); 650 KASSERT(sc->sc_edma_tx != NULL);
571 sc->sc_edma_rx = edma_channel_alloc(EDMA_TYPE_DMA, edmabase + 1, 651 sc->sc_edma_rx = edma_channel_alloc(EDMA_TYPE_DMA, edmabase + 1,
572 obiosdhc_edma_done, sc); 652 mmchs_edma_done, sc);
573 KASSERT(sc->sc_edma_rx != NULL); 653 KASSERT(sc->sc_edma_rx != NULL);
574 654
575 /* Allocate some PaRAM pages */ 655 /* Allocate some PaRAM pages */
576 for (i = 0; i < __arraycount(sc->sc_edma_param_tx); i++) { 656 for (i = 0; i < __arraycount(sc->sc_edma_param_tx); i++) {
577 sc->sc_edma_param_tx[i] = edma_param_alloc(sc->sc_edma_tx); 657 sc->sc_edma_param_tx[i] = edma_param_alloc(sc->sc_edma_tx);
578 KASSERT(sc->sc_edma_param_tx[i] != 0xffff); 658 KASSERT(sc->sc_edma_param_tx[i] != 0xffff);
579 } 659 }
580 for (i = 0; i < __arraycount(sc->sc_edma_param_rx); i++) { 660 for (i = 0; i < __arraycount(sc->sc_edma_param_rx); i++) {
581 sc->sc_edma_param_rx[i] = edma_param_alloc(sc->sc_edma_rx); 661 sc->sc_edma_param_rx[i] = edma_param_alloc(sc->sc_edma_rx);
582 KASSERT(sc->sc_edma_param_rx[i] != 0xffff); 662 KASSERT(sc->sc_edma_param_rx[i] != 0xffff);
583 } 663 }
584 664
585 /* Setup bounce buffer */ 665 /* Setup bounce buffer */
@@ -600,29 +680,29 @@ obiosdhc_edma_init(struct obiosdhc_softc @@ -600,29 +680,29 @@ obiosdhc_edma_init(struct obiosdhc_softc
600 } 680 }
601 error = bus_dmamap_create(sc->sc.sc_dmat, MAXPHYS, 1, MAXPHYS, 0, 681 error = bus_dmamap_create(sc->sc.sc_dmat, MAXPHYS, 1, MAXPHYS, 0,
602 BUS_DMA_WAITOK, &sc->sc_edma_dmamap); 682 BUS_DMA_WAITOK, &sc->sc_edma_dmamap);
603 if (error) { 683 if (error) {
604 aprint_error_dev(sc->sc.sc_dev, "couldn't create dmamap: %d\n", 684 aprint_error_dev(sc->sc.sc_dev, "couldn't create dmamap: %d\n",
605 error); 685 error);
606 return error; 686 return error;
607 } 687 }
608 688
609 return error; 689 return error;
610} 690}
611 691
612static int 692static int
613obiosdhc_edma_xfer_data(struct sdhc_softc *sdhc_sc, struct sdmmc_command *cmd) 693mmchs_edma_xfer_data(struct sdhc_softc *sdhc_sc, struct sdmmc_command *cmd)
614{ 694{
615 struct obiosdhc_softc *sc = device_private(sdhc_sc->sc_dev); 695 struct mmchs_softc *sc = device_private(sdhc_sc->sc_dev);
616 const bus_dmamap_t map = cmd->c_dmamap; 696 const bus_dmamap_t map = cmd->c_dmamap;
617 int seg, error; 697 int seg, error;
618 bool bounce; 698 bool bounce;
619 699
620 for (bounce = false, seg = 0; seg < cmd->c_dmamap->dm_nsegs; seg++) { 700 for (bounce = false, seg = 0; seg < cmd->c_dmamap->dm_nsegs; seg++) {
621 if ((cmd->c_dmamap->dm_segs[seg].ds_addr & 0x1f) != 0) { 701 if ((cmd->c_dmamap->dm_segs[seg].ds_addr & 0x1f) != 0) {
622 bounce = true; 702 bounce = true;
623 break; 703 break;
624 } 704 }
625 } 705 }
626 706
627 if (bounce) { 707 if (bounce) {
628 error = bus_dmamap_load(sc->sc.sc_dmat, sc->sc_edma_dmamap, 708 error = bus_dmamap_load(sc->sc.sc_dmat, sc->sc_edma_dmamap,
@@ -634,51 +714,51 @@ obiosdhc_edma_xfer_data(struct sdhc_soft @@ -634,51 +714,51 @@ obiosdhc_edma_xfer_data(struct sdhc_soft
634 } 714 }
635 if (ISSET(cmd->c_flags, SCF_CMD_READ)) { 715 if (ISSET(cmd->c_flags, SCF_CMD_READ)) {
636 bus_dmamap_sync(sc->sc.sc_dmat, sc->sc_edma_dmamap, 0, 716 bus_dmamap_sync(sc->sc.sc_dmat, sc->sc_edma_dmamap, 0,
637 MAXPHYS, BUS_DMASYNC_PREREAD); 717 MAXPHYS, BUS_DMASYNC_PREREAD);
638 } else { 718 } else {
639 memcpy(sc->sc_edma_bbuf, cmd->c_data, cmd->c_datalen); 719 memcpy(sc->sc_edma_bbuf, cmd->c_data, cmd->c_datalen);
640 bus_dmamap_sync(sc->sc.sc_dmat, sc->sc_edma_dmamap, 0, 720 bus_dmamap_sync(sc->sc.sc_dmat, sc->sc_edma_dmamap, 0,
641 MAXPHYS, BUS_DMASYNC_PREWRITE); 721 MAXPHYS, BUS_DMASYNC_PREWRITE);
642 } 722 }
643 723
644 cmd->c_dmamap = sc->sc_edma_dmamap; 724 cmd->c_dmamap = sc->sc_edma_dmamap;
645 } 725 }
646 726
647 error = obiosdhc_edma_transfer(sdhc_sc, cmd); 727 error = mmchs_edma_transfer(sdhc_sc, cmd);
648 728
649 if (bounce) { 729 if (bounce) {
650 if (ISSET(cmd->c_flags, SCF_CMD_READ)) { 730 if (ISSET(cmd->c_flags, SCF_CMD_READ)) {
651 bus_dmamap_sync(sc->sc.sc_dmat, sc->sc_edma_dmamap, 0, 731 bus_dmamap_sync(sc->sc.sc_dmat, sc->sc_edma_dmamap, 0,
652 MAXPHYS, BUS_DMASYNC_POSTREAD); 732 MAXPHYS, BUS_DMASYNC_POSTREAD);
653 } else { 733 } else {
654 bus_dmamap_sync(sc->sc.sc_dmat, sc->sc_edma_dmamap, 0, 734 bus_dmamap_sync(sc->sc.sc_dmat, sc->sc_edma_dmamap, 0,
655 MAXPHYS, BUS_DMASYNC_POSTWRITE); 735 MAXPHYS, BUS_DMASYNC_POSTWRITE);
656 } 736 }
657 bus_dmamap_unload(sc->sc.sc_dmat, sc->sc_edma_dmamap); 737 bus_dmamap_unload(sc->sc.sc_dmat, sc->sc_edma_dmamap);
658 if (ISSET(cmd->c_flags, SCF_CMD_READ) && error == 0) { 738 if (ISSET(cmd->c_flags, SCF_CMD_READ) && error == 0) {
659 memcpy(cmd->c_data, sc->sc_edma_bbuf, cmd->c_datalen); 739 memcpy(cmd->c_data, sc->sc_edma_bbuf, cmd->c_datalen);
660 } 740 }
661 741
662 cmd->c_dmamap = map; 742 cmd->c_dmamap = map;
663 } 743 }
664 744
665 return error; 745 return error;
666} 746}
667 747
668static int 748static int
669obiosdhc_edma_transfer(struct sdhc_softc *sdhc_sc, struct sdmmc_command *cmd) 749mmchs_edma_transfer(struct sdhc_softc *sdhc_sc, struct sdmmc_command *cmd)
670{ 750{
671 struct obiosdhc_softc *sc = device_private(sdhc_sc->sc_dev); 751 struct mmchs_softc *sc = device_private(sdhc_sc->sc_dev);
672 kmutex_t *plock = sdhc_host_lock(sc->sc_hosts[0]); 752 kmutex_t *plock = sdhc_host_lock(sc->sc_hosts[0]);
673 struct edma_channel *edma; 753 struct edma_channel *edma;
674 uint16_t *edma_param; 754 uint16_t *edma_param;
675 struct edma_param ep; 755 struct edma_param ep;
676 size_t seg; 756 size_t seg;
677 int error, resid = cmd->c_datalen; 757 int error, resid = cmd->c_datalen;
678 int blksize = MIN(cmd->c_datalen, cmd->c_blklen); 758 int blksize = MIN(cmd->c_datalen, cmd->c_blklen);
679 759
680 KASSERT(mutex_owned(plock)); 760 KASSERT(mutex_owned(plock));
681 761
682 edma = ISSET(cmd->c_flags, SCF_CMD_READ) ? 762 edma = ISSET(cmd->c_flags, SCF_CMD_READ) ?
683 sc->sc_edma_rx : sc->sc_edma_tx; 763 sc->sc_edma_rx : sc->sc_edma_tx;
684 edma_param = ISSET(cmd->c_flags, SCF_CMD_READ) ? 764 edma_param = ISSET(cmd->c_flags, SCF_CMD_READ) ?
@@ -766,25 +846,25 @@ obiosdhc_edma_transfer(struct sdhc_softc @@ -766,25 +846,25 @@ obiosdhc_edma_transfer(struct sdhc_softc
766 edma_dump_param(edma, edma_param[0]); 846 edma_dump_param(edma, edma_param[0]);
767 edma_halt(edma); 847 edma_halt(edma);
768 sc->sc_edma_pending = false; 848 sc->sc_edma_pending = false;
769 error = ETIMEDOUT; 849 error = ETIMEDOUT;
770 break; 850 break;
771 } 851 }
772 } 852 }
773 edma_halt(edma); 853 edma_halt(edma);
774 854
775 return error; 855 return error;
776} 856}
777 857
778static void 858static void
779obiosdhc_edma_done(void *priv) 859mmchs_edma_done(void *priv)
780{ 860{
781 struct obiosdhc_softc *sc = priv; 861 struct mmchs_softc *sc = priv;
782 kmutex_t *plock = sdhc_host_lock(sc->sc_hosts[0]); 862 kmutex_t *plock = sdhc_host_lock(sc->sc_hosts[0]);
783 863
784 mutex_enter(plock); 864 mutex_enter(plock);
785 KASSERT(sc->sc_edma_pending == true); 865 KASSERT(sc->sc_edma_pending == true);
786 sc->sc_edma_pending = false; 866 sc->sc_edma_pending = false;
787 cv_broadcast(&sc->sc_edma_cv); 867 cv_broadcast(&sc->sc_edma_cv);
788 mutex_exit(plock); 868 mutex_exit(plock);
789} 869}
790#endif 870#endif