meson_sdio.c revision 1.1.2.2 1 1.1.2.2 pgoyette /* $NetBSD: meson_sdio.c,v 1.1.2.2 2019/01/26 21:59:59 pgoyette Exp $ */
2 1.1.2.2 pgoyette
3 1.1.2.2 pgoyette /*-
4 1.1.2.2 pgoyette * Copyright (c) 2015-2019 Jared D. McNeill <jmcneill (at) invisible.ca>
5 1.1.2.2 pgoyette * All rights reserved.
6 1.1.2.2 pgoyette *
7 1.1.2.2 pgoyette * Redistribution and use in source and binary forms, with or without
8 1.1.2.2 pgoyette * modification, are permitted provided that the following conditions
9 1.1.2.2 pgoyette * are met:
10 1.1.2.2 pgoyette * 1. Redistributions of source code must retain the above copyright
11 1.1.2.2 pgoyette * notice, this list of conditions and the following disclaimer.
12 1.1.2.2 pgoyette * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.2.2 pgoyette * notice, this list of conditions and the following disclaimer in the
14 1.1.2.2 pgoyette * documentation and/or other materials provided with the distribution.
15 1.1.2.2 pgoyette *
16 1.1.2.2 pgoyette * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1.2.2 pgoyette * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1.2.2 pgoyette * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1.2.2 pgoyette * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1.2.2 pgoyette * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.1.2.2 pgoyette * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.1.2.2 pgoyette * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.1.2.2 pgoyette * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.1.2.2 pgoyette * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1.2.2 pgoyette * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1.2.2 pgoyette * SUCH DAMAGE.
27 1.1.2.2 pgoyette */
28 1.1.2.2 pgoyette
29 1.1.2.2 pgoyette #include <sys/cdefs.h>
30 1.1.2.2 pgoyette __KERNEL_RCSID(0, "$NetBSD: meson_sdio.c,v 1.1.2.2 2019/01/26 21:59:59 pgoyette Exp $");
31 1.1.2.2 pgoyette
32 1.1.2.2 pgoyette #include <sys/param.h>
33 1.1.2.2 pgoyette #include <sys/bus.h>
34 1.1.2.2 pgoyette #include <sys/device.h>
35 1.1.2.2 pgoyette #include <sys/intr.h>
36 1.1.2.2 pgoyette #include <sys/systm.h>
37 1.1.2.2 pgoyette #include <sys/kernel.h>
38 1.1.2.2 pgoyette #include <sys/gpio.h>
39 1.1.2.2 pgoyette
40 1.1.2.2 pgoyette #include <dev/sdmmc/sdmmcvar.h>
41 1.1.2.2 pgoyette #include <dev/sdmmc/sdmmcchip.h>
42 1.1.2.2 pgoyette #include <dev/sdmmc/sdmmc_ioreg.h>
43 1.1.2.2 pgoyette
44 1.1.2.2 pgoyette #include <dev/fdt/fdtvar.h>
45 1.1.2.2 pgoyette
46 1.1.2.2 pgoyette #include <arm/amlogic/meson_sdioreg.h>
47 1.1.2.2 pgoyette
48 1.1.2.2 pgoyette static int meson_sdio_match(device_t, cfdata_t, void *);
49 1.1.2.2 pgoyette static void meson_sdio_attach(device_t, device_t, void *);
50 1.1.2.2 pgoyette static void meson_sdio_attach_i(device_t);
51 1.1.2.2 pgoyette
52 1.1.2.2 pgoyette static int meson_sdio_intr(void *);
53 1.1.2.2 pgoyette
54 1.1.2.2 pgoyette struct meson_sdio_softc {
55 1.1.2.2 pgoyette device_t sc_dev;
56 1.1.2.2 pgoyette bus_space_tag_t sc_bst;
57 1.1.2.2 pgoyette bus_space_handle_t sc_bsh;
58 1.1.2.2 pgoyette bus_dma_tag_t sc_dmat;
59 1.1.2.2 pgoyette void *sc_ih;
60 1.1.2.2 pgoyette
61 1.1.2.2 pgoyette int sc_slot_phandle;
62 1.1.2.2 pgoyette
63 1.1.2.2 pgoyette uint32_t sc_bus_freq;
64 1.1.2.2 pgoyette u_int sc_cur_width;
65 1.1.2.2 pgoyette int sc_cur_port;
66 1.1.2.2 pgoyette
67 1.1.2.2 pgoyette struct fdtbus_gpio_pin *sc_gpio_cd;
68 1.1.2.2 pgoyette int sc_gpio_cd_inverted;
69 1.1.2.2 pgoyette struct fdtbus_gpio_pin *sc_gpio_wp;
70 1.1.2.2 pgoyette int sc_gpio_wp_inverted;
71 1.1.2.2 pgoyette
72 1.1.2.2 pgoyette struct fdtbus_regulator *sc_reg_vmmc;
73 1.1.2.2 pgoyette struct fdtbus_regulator *sc_reg_vqmmc;
74 1.1.2.2 pgoyette
75 1.1.2.2 pgoyette bool sc_non_removable;
76 1.1.2.2 pgoyette bool sc_broken_cd;
77 1.1.2.2 pgoyette
78 1.1.2.2 pgoyette device_t sc_sdmmc_dev;
79 1.1.2.2 pgoyette kmutex_t sc_intr_lock;
80 1.1.2.2 pgoyette kcondvar_t sc_intr_cv;
81 1.1.2.2 pgoyette
82 1.1.2.2 pgoyette uint32_t sc_intr_irqs;
83 1.1.2.2 pgoyette
84 1.1.2.2 pgoyette bus_dmamap_t sc_dmamap;
85 1.1.2.2 pgoyette bus_dma_segment_t sc_segs[1];
86 1.1.2.2 pgoyette void *sc_bbuf;
87 1.1.2.2 pgoyette };
88 1.1.2.2 pgoyette
89 1.1.2.2 pgoyette CFATTACH_DECL_NEW(meson_sdio, sizeof(struct meson_sdio_softc),
90 1.1.2.2 pgoyette meson_sdio_match, meson_sdio_attach, NULL, NULL);
91 1.1.2.2 pgoyette
92 1.1.2.2 pgoyette static int meson_sdio_host_reset(sdmmc_chipset_handle_t);
93 1.1.2.2 pgoyette static uint32_t meson_sdio_host_ocr(sdmmc_chipset_handle_t);
94 1.1.2.2 pgoyette static int meson_sdio_host_maxblklen(sdmmc_chipset_handle_t);
95 1.1.2.2 pgoyette static int meson_sdio_card_detect(sdmmc_chipset_handle_t);
96 1.1.2.2 pgoyette static int meson_sdio_write_protect(sdmmc_chipset_handle_t);
97 1.1.2.2 pgoyette static int meson_sdio_bus_power(sdmmc_chipset_handle_t, uint32_t);
98 1.1.2.2 pgoyette static int meson_sdio_bus_clock(sdmmc_chipset_handle_t, int);
99 1.1.2.2 pgoyette static int meson_sdio_bus_width(sdmmc_chipset_handle_t, int);
100 1.1.2.2 pgoyette static int meson_sdio_bus_rod(sdmmc_chipset_handle_t, int);
101 1.1.2.2 pgoyette static int meson_sdio_signal_voltage(sdmmc_chipset_handle_t, int);
102 1.1.2.2 pgoyette static void meson_sdio_exec_command(sdmmc_chipset_handle_t,
103 1.1.2.2 pgoyette struct sdmmc_command *);
104 1.1.2.2 pgoyette static void meson_sdio_card_enable_intr(sdmmc_chipset_handle_t, int);
105 1.1.2.2 pgoyette static void meson_sdio_card_intr_ack(sdmmc_chipset_handle_t);
106 1.1.2.2 pgoyette
107 1.1.2.2 pgoyette static int meson_sdio_set_clock(struct meson_sdio_softc *, u_int);
108 1.1.2.2 pgoyette static int meson_sdio_wait_irqs(struct meson_sdio_softc *, uint32_t, int);
109 1.1.2.2 pgoyette
110 1.1.2.2 pgoyette static void meson_sdio_dmainit(struct meson_sdio_softc *);
111 1.1.2.2 pgoyette
112 1.1.2.2 pgoyette static struct sdmmc_chip_functions meson_sdio_chip_functions = {
113 1.1.2.2 pgoyette .host_reset = meson_sdio_host_reset,
114 1.1.2.2 pgoyette .host_ocr = meson_sdio_host_ocr,
115 1.1.2.2 pgoyette .host_maxblklen = meson_sdio_host_maxblklen,
116 1.1.2.2 pgoyette .card_detect = meson_sdio_card_detect,
117 1.1.2.2 pgoyette .write_protect = meson_sdio_write_protect,
118 1.1.2.2 pgoyette .bus_power = meson_sdio_bus_power,
119 1.1.2.2 pgoyette .bus_clock = meson_sdio_bus_clock,
120 1.1.2.2 pgoyette .bus_width = meson_sdio_bus_width,
121 1.1.2.2 pgoyette .bus_rod = meson_sdio_bus_rod,
122 1.1.2.2 pgoyette .signal_voltage = meson_sdio_signal_voltage,
123 1.1.2.2 pgoyette .exec_command = meson_sdio_exec_command,
124 1.1.2.2 pgoyette .card_enable_intr = meson_sdio_card_enable_intr,
125 1.1.2.2 pgoyette .card_intr_ack = meson_sdio_card_intr_ack,
126 1.1.2.2 pgoyette };
127 1.1.2.2 pgoyette
128 1.1.2.2 pgoyette #define SDIO_WRITE(sc, reg, val) \
129 1.1.2.2 pgoyette bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val))
130 1.1.2.2 pgoyette #define SDIO_READ(sc, reg) \
131 1.1.2.2 pgoyette bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg))
132 1.1.2.2 pgoyette
133 1.1.2.2 pgoyette static const char * const compatible[] = {
134 1.1.2.2 pgoyette "amlogic,meson8b-sdio",
135 1.1.2.2 pgoyette NULL
136 1.1.2.2 pgoyette };
137 1.1.2.2 pgoyette
138 1.1.2.2 pgoyette static const char * const slot_compatible[] = {
139 1.1.2.2 pgoyette "mmc-slot",
140 1.1.2.2 pgoyette NULL
141 1.1.2.2 pgoyette };
142 1.1.2.2 pgoyette
143 1.1.2.2 pgoyette static int
144 1.1.2.2 pgoyette meson_sdio_match(device_t parent, cfdata_t cf, void *aux)
145 1.1.2.2 pgoyette {
146 1.1.2.2 pgoyette struct fdt_attach_args * const faa = aux;
147 1.1.2.2 pgoyette
148 1.1.2.2 pgoyette return of_match_compatible(faa->faa_phandle, compatible);
149 1.1.2.2 pgoyette }
150 1.1.2.2 pgoyette
151 1.1.2.2 pgoyette static void
152 1.1.2.2 pgoyette meson_sdio_attach(device_t parent, device_t self, void *aux)
153 1.1.2.2 pgoyette {
154 1.1.2.2 pgoyette struct meson_sdio_softc * const sc = device_private(self);
155 1.1.2.2 pgoyette struct fdt_attach_args * const faa = aux;
156 1.1.2.2 pgoyette const int phandle = faa->faa_phandle;
157 1.1.2.2 pgoyette char intrstr[128];
158 1.1.2.2 pgoyette struct clk *clk_clkin, *clk_core;
159 1.1.2.2 pgoyette bus_addr_t addr, port;
160 1.1.2.2 pgoyette bus_size_t size;
161 1.1.2.2 pgoyette int child;
162 1.1.2.2 pgoyette
163 1.1.2.2 pgoyette if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) {
164 1.1.2.2 pgoyette aprint_error(": couldn't get registers\n");
165 1.1.2.2 pgoyette return;
166 1.1.2.2 pgoyette }
167 1.1.2.2 pgoyette
168 1.1.2.2 pgoyette if (!fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr))) {
169 1.1.2.2 pgoyette aprint_error(": failed to decode interrupt\n");
170 1.1.2.2 pgoyette return;
171 1.1.2.2 pgoyette }
172 1.1.2.2 pgoyette
173 1.1.2.2 pgoyette clk_core = fdtbus_clock_get(phandle, "core");
174 1.1.2.2 pgoyette if (clk_core == NULL || clk_enable(clk_core) != 0) {
175 1.1.2.2 pgoyette aprint_error(": failed to enable core clock\n");
176 1.1.2.2 pgoyette return;
177 1.1.2.2 pgoyette }
178 1.1.2.2 pgoyette
179 1.1.2.2 pgoyette clk_clkin = fdtbus_clock_get(phandle, "clkin");
180 1.1.2.2 pgoyette if (clk_clkin == NULL) {
181 1.1.2.2 pgoyette aprint_error(": failed to get clkin clock\n");
182 1.1.2.2 pgoyette return;
183 1.1.2.2 pgoyette }
184 1.1.2.2 pgoyette
185 1.1.2.2 pgoyette sc->sc_dev = self;
186 1.1.2.2 pgoyette sc->sc_bst = faa->faa_bst;
187 1.1.2.2 pgoyette sc->sc_dmat = faa->faa_dmat;
188 1.1.2.2 pgoyette if (bus_space_map(sc->sc_bst, addr, size, 0, &sc->sc_bsh) != 0) {
189 1.1.2.2 pgoyette aprint_error(": failed to map registers\n");
190 1.1.2.2 pgoyette return;
191 1.1.2.2 pgoyette }
192 1.1.2.2 pgoyette
193 1.1.2.2 pgoyette mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_BIO);
194 1.1.2.2 pgoyette cv_init(&sc->sc_intr_cv, "sdiointr");
195 1.1.2.2 pgoyette
196 1.1.2.2 pgoyette sc->sc_cur_port = -1;
197 1.1.2.2 pgoyette for (child = OF_child(phandle); child; child = OF_peer(child))
198 1.1.2.2 pgoyette if (of_match_compatible(child, slot_compatible) > 0) {
199 1.1.2.2 pgoyette if (fdtbus_get_reg(child, 0, &port, NULL) == 0) {
200 1.1.2.2 pgoyette sc->sc_slot_phandle = child;
201 1.1.2.2 pgoyette sc->sc_cur_port = port;
202 1.1.2.2 pgoyette }
203 1.1.2.2 pgoyette break;
204 1.1.2.2 pgoyette }
205 1.1.2.2 pgoyette if (sc->sc_cur_port == -1) {
206 1.1.2.2 pgoyette aprint_error(": couldn't get mmc slot\n");
207 1.1.2.2 pgoyette return;
208 1.1.2.2 pgoyette }
209 1.1.2.2 pgoyette
210 1.1.2.2 pgoyette aprint_naive("\n");
211 1.1.2.2 pgoyette aprint_normal(": SDIO controller (port %c)\n", sc->sc_cur_port + 'A');
212 1.1.2.2 pgoyette
213 1.1.2.2 pgoyette sc->sc_reg_vmmc = fdtbus_regulator_acquire(sc->sc_slot_phandle, "vmmc-supply");
214 1.1.2.2 pgoyette sc->sc_reg_vqmmc = fdtbus_regulator_acquire(sc->sc_slot_phandle, "vqmmc-supply");
215 1.1.2.2 pgoyette
216 1.1.2.2 pgoyette sc->sc_gpio_cd = fdtbus_gpio_acquire(sc->sc_slot_phandle, "cd-gpios",
217 1.1.2.2 pgoyette GPIO_PIN_INPUT);
218 1.1.2.2 pgoyette sc->sc_gpio_wp = fdtbus_gpio_acquire(sc->sc_slot_phandle, "wp-gpios",
219 1.1.2.2 pgoyette GPIO_PIN_INPUT);
220 1.1.2.2 pgoyette
221 1.1.2.2 pgoyette sc->sc_gpio_cd_inverted = of_hasprop(sc->sc_slot_phandle, "cd-inverted");
222 1.1.2.2 pgoyette sc->sc_gpio_wp_inverted = of_hasprop(sc->sc_slot_phandle, "wp-inverted");
223 1.1.2.2 pgoyette
224 1.1.2.2 pgoyette sc->sc_non_removable = of_hasprop(sc->sc_slot_phandle, "non-removable");
225 1.1.2.2 pgoyette sc->sc_broken_cd = of_hasprop(sc->sc_slot_phandle, "broken-cd");
226 1.1.2.2 pgoyette
227 1.1.2.2 pgoyette sc->sc_ih = fdtbus_intr_establish(phandle, 0, IPL_BIO, 0, meson_sdio_intr, sc);
228 1.1.2.2 pgoyette if (sc->sc_ih == NULL) {
229 1.1.2.2 pgoyette aprint_error_dev(self, "couldn't establish interrupt on %s\n",
230 1.1.2.2 pgoyette intrstr);
231 1.1.2.2 pgoyette return;
232 1.1.2.2 pgoyette }
233 1.1.2.2 pgoyette aprint_normal_dev(self, "interrupting on %s\n", intrstr);
234 1.1.2.2 pgoyette
235 1.1.2.2 pgoyette sc->sc_bus_freq = clk_get_rate(clk_clkin);
236 1.1.2.2 pgoyette
237 1.1.2.2 pgoyette aprint_normal_dev(self, "core %u Hz, clkin %u Hz\n", clk_get_rate(clk_core), clk_get_rate(clk_clkin));
238 1.1.2.2 pgoyette
239 1.1.2.2 pgoyette meson_sdio_dmainit(sc);
240 1.1.2.2 pgoyette
241 1.1.2.2 pgoyette config_interrupts(self, meson_sdio_attach_i);
242 1.1.2.2 pgoyette }
243 1.1.2.2 pgoyette
244 1.1.2.2 pgoyette static void
245 1.1.2.2 pgoyette meson_sdio_attach_i(device_t self)
246 1.1.2.2 pgoyette {
247 1.1.2.2 pgoyette struct meson_sdio_softc *sc = device_private(self);
248 1.1.2.2 pgoyette struct sdmmcbus_attach_args saa;
249 1.1.2.2 pgoyette
250 1.1.2.2 pgoyette meson_sdio_signal_voltage(sc, SDMMC_SIGNAL_VOLTAGE_330);
251 1.1.2.2 pgoyette meson_sdio_host_reset(sc);
252 1.1.2.2 pgoyette meson_sdio_bus_clock(sc, 400);
253 1.1.2.2 pgoyette meson_sdio_bus_width(sc, 1);
254 1.1.2.2 pgoyette
255 1.1.2.2 pgoyette memset(&saa, 0, sizeof(saa));
256 1.1.2.2 pgoyette saa.saa_busname = "sdmmc";
257 1.1.2.2 pgoyette saa.saa_sct = &meson_sdio_chip_functions;
258 1.1.2.2 pgoyette saa.saa_dmat = sc->sc_dmat;
259 1.1.2.2 pgoyette saa.saa_sch = sc;
260 1.1.2.2 pgoyette saa.saa_clkmin = 400;
261 1.1.2.2 pgoyette saa.saa_clkmax = sc->sc_bus_freq;
262 1.1.2.2 pgoyette /* Do not advertise DMA capabilities, we handle DMA ourselves */
263 1.1.2.2 pgoyette saa.saa_caps = SMC_CAPS_4BIT_MODE|
264 1.1.2.2 pgoyette SMC_CAPS_SD_HIGHSPEED|
265 1.1.2.2 pgoyette SMC_CAPS_MMC_HIGHSPEED;
266 1.1.2.2 pgoyette
267 1.1.2.2 pgoyette sc->sc_sdmmc_dev = config_found(self, &saa, NULL);
268 1.1.2.2 pgoyette }
269 1.1.2.2 pgoyette
270 1.1.2.2 pgoyette static int
271 1.1.2.2 pgoyette meson_sdio_intr(void *priv)
272 1.1.2.2 pgoyette {
273 1.1.2.2 pgoyette struct meson_sdio_softc *sc = priv;
274 1.1.2.2 pgoyette
275 1.1.2.2 pgoyette mutex_enter(&sc->sc_intr_lock);
276 1.1.2.2 pgoyette const u_int irqs = SDIO_READ(sc, SDIO_IRQS_REG);
277 1.1.2.2 pgoyette if (irqs & SDIO_IRQS_CLEAR) {
278 1.1.2.2 pgoyette SDIO_WRITE(sc, SDIO_IRQS_REG, irqs);
279 1.1.2.2 pgoyette sc->sc_intr_irqs |= irqs;
280 1.1.2.2 pgoyette cv_broadcast(&sc->sc_intr_cv);
281 1.1.2.2 pgoyette }
282 1.1.2.2 pgoyette mutex_exit(&sc->sc_intr_lock);
283 1.1.2.2 pgoyette
284 1.1.2.2 pgoyette return 1;
285 1.1.2.2 pgoyette }
286 1.1.2.2 pgoyette
287 1.1.2.2 pgoyette static void
288 1.1.2.2 pgoyette meson_sdio_dmainit(struct meson_sdio_softc *sc)
289 1.1.2.2 pgoyette {
290 1.1.2.2 pgoyette int error, rseg;
291 1.1.2.2 pgoyette
292 1.1.2.2 pgoyette error = bus_dmamem_alloc(sc->sc_dmat, MAXPHYS, PAGE_SIZE, MAXPHYS,
293 1.1.2.2 pgoyette sc->sc_segs, 1, &rseg, BUS_DMA_WAITOK);
294 1.1.2.2 pgoyette if (error) {
295 1.1.2.2 pgoyette device_printf(sc->sc_dev, "bus_dmamem_alloc failed\n");
296 1.1.2.2 pgoyette return;
297 1.1.2.2 pgoyette }
298 1.1.2.2 pgoyette KASSERT(rseg == 1);
299 1.1.2.2 pgoyette
300 1.1.2.2 pgoyette error = bus_dmamem_map(sc->sc_dmat, sc->sc_segs, rseg, MAXPHYS,
301 1.1.2.2 pgoyette &sc->sc_bbuf, BUS_DMA_WAITOK);
302 1.1.2.2 pgoyette if (error) {
303 1.1.2.2 pgoyette device_printf(sc->sc_dev, "bus_dmamem_map failed\n");
304 1.1.2.2 pgoyette return;
305 1.1.2.2 pgoyette }
306 1.1.2.2 pgoyette
307 1.1.2.2 pgoyette error = bus_dmamap_create(sc->sc_dmat, MAXPHYS, 1, MAXPHYS, 0,
308 1.1.2.2 pgoyette BUS_DMA_WAITOK, &sc->sc_dmamap);
309 1.1.2.2 pgoyette if (error) {
310 1.1.2.2 pgoyette device_printf(sc->sc_dev, "bus_dmamap_create failed\n");
311 1.1.2.2 pgoyette return;
312 1.1.2.2 pgoyette }
313 1.1.2.2 pgoyette }
314 1.1.2.2 pgoyette
315 1.1.2.2 pgoyette static int
316 1.1.2.2 pgoyette meson_sdio_set_clock(struct meson_sdio_softc *sc, u_int freq)
317 1.1.2.2 pgoyette {
318 1.1.2.2 pgoyette const u_int pll_freq = sc->sc_bus_freq / 2000;
319 1.1.2.2 pgoyette uint32_t conf;
320 1.1.2.2 pgoyette int clk_div;
321 1.1.2.2 pgoyette
322 1.1.2.2 pgoyette if (freq == 0)
323 1.1.2.2 pgoyette return 0;
324 1.1.2.2 pgoyette
325 1.1.2.2 pgoyette clk_div = howmany(pll_freq, freq);
326 1.1.2.2 pgoyette
327 1.1.2.2 pgoyette conf = SDIO_READ(sc, SDIO_CONF_REG);
328 1.1.2.2 pgoyette conf &= ~SDIO_CONF_COMMAND_CLK_DIV;
329 1.1.2.2 pgoyette conf |= __SHIFTIN(clk_div - 1, SDIO_CONF_COMMAND_CLK_DIV);
330 1.1.2.2 pgoyette SDIO_WRITE(sc, SDIO_CONF_REG, conf);
331 1.1.2.2 pgoyette
332 1.1.2.2 pgoyette return 0;
333 1.1.2.2 pgoyette }
334 1.1.2.2 pgoyette
335 1.1.2.2 pgoyette static int
336 1.1.2.2 pgoyette meson_sdio_wait_irqs(struct meson_sdio_softc *sc, uint32_t mask, int timeout)
337 1.1.2.2 pgoyette {
338 1.1.2.2 pgoyette int retry, error;
339 1.1.2.2 pgoyette
340 1.1.2.2 pgoyette KASSERT(mutex_owned(&sc->sc_intr_lock));
341 1.1.2.2 pgoyette
342 1.1.2.2 pgoyette if (sc->sc_intr_irqs & mask)
343 1.1.2.2 pgoyette return 0;
344 1.1.2.2 pgoyette
345 1.1.2.2 pgoyette retry = timeout / hz;
346 1.1.2.2 pgoyette
347 1.1.2.2 pgoyette while (retry > 0) {
348 1.1.2.2 pgoyette error = cv_timedwait(&sc->sc_intr_cv, &sc->sc_intr_lock, hz);
349 1.1.2.2 pgoyette if (error && error != EWOULDBLOCK)
350 1.1.2.2 pgoyette return error;
351 1.1.2.2 pgoyette if (sc->sc_intr_irqs & mask)
352 1.1.2.2 pgoyette return 0;
353 1.1.2.2 pgoyette --retry;
354 1.1.2.2 pgoyette }
355 1.1.2.2 pgoyette
356 1.1.2.2 pgoyette return ETIMEDOUT;
357 1.1.2.2 pgoyette }
358 1.1.2.2 pgoyette
359 1.1.2.2 pgoyette static int
360 1.1.2.2 pgoyette meson_sdio_host_reset(sdmmc_chipset_handle_t sch)
361 1.1.2.2 pgoyette {
362 1.1.2.2 pgoyette struct meson_sdio_softc *sc = sch;
363 1.1.2.2 pgoyette
364 1.1.2.2 pgoyette SDIO_WRITE(sc, SDIO_IRQC_REG, SDIO_IRQC_SOFT_RESET);
365 1.1.2.2 pgoyette
366 1.1.2.2 pgoyette delay(2);
367 1.1.2.2 pgoyette
368 1.1.2.2 pgoyette SDIO_WRITE(sc, SDIO_IRQS_REG, SDIO_IRQS_CLEAR);
369 1.1.2.2 pgoyette SDIO_WRITE(sc, SDIO_CONF_REG,
370 1.1.2.2 pgoyette __SHIFTIN(2, SDIO_CONF_WRITE_CRC_OK_STATUS) |
371 1.1.2.2 pgoyette __SHIFTIN(2, SDIO_CONF_WRITE_NWR) |
372 1.1.2.2 pgoyette __SHIFTIN(3, SDIO_CONF_M_ENDIAN) |
373 1.1.2.2 pgoyette __SHIFTIN(39, SDIO_CONF_COMMAND_ARG_BITS) |
374 1.1.2.2 pgoyette __SHIFTIN(0x1f4, SDIO_CONF_COMMAND_CLK_DIV));
375 1.1.2.2 pgoyette
376 1.1.2.2 pgoyette SDIO_WRITE(sc, SDIO_MULT_REG,
377 1.1.2.2 pgoyette __SHIFTIN(sc->sc_cur_port, SDIO_MULT_PORT_SEL));
378 1.1.2.2 pgoyette
379 1.1.2.2 pgoyette return 0;
380 1.1.2.2 pgoyette }
381 1.1.2.2 pgoyette
382 1.1.2.2 pgoyette static uint32_t
383 1.1.2.2 pgoyette meson_sdio_host_ocr(sdmmc_chipset_handle_t sch)
384 1.1.2.2 pgoyette {
385 1.1.2.2 pgoyette return MMC_OCR_3_2V_3_3V | MMC_OCR_3_3V_3_4V;
386 1.1.2.2 pgoyette }
387 1.1.2.2 pgoyette
388 1.1.2.2 pgoyette static int
389 1.1.2.2 pgoyette meson_sdio_host_maxblklen(sdmmc_chipset_handle_t sch)
390 1.1.2.2 pgoyette {
391 1.1.2.2 pgoyette return 512;
392 1.1.2.2 pgoyette }
393 1.1.2.2 pgoyette
394 1.1.2.2 pgoyette static int
395 1.1.2.2 pgoyette meson_sdio_card_detect(sdmmc_chipset_handle_t sch)
396 1.1.2.2 pgoyette {
397 1.1.2.2 pgoyette struct meson_sdio_softc *sc = sch;
398 1.1.2.2 pgoyette int val;
399 1.1.2.2 pgoyette
400 1.1.2.2 pgoyette if (sc->sc_non_removable || sc->sc_broken_cd) {
401 1.1.2.2 pgoyette return 1;
402 1.1.2.2 pgoyette } else if (sc->sc_gpio_cd != NULL) {
403 1.1.2.2 pgoyette val = fdtbus_gpio_read(sc->sc_gpio_cd);
404 1.1.2.2 pgoyette if (sc->sc_gpio_cd_inverted)
405 1.1.2.2 pgoyette val = !val;
406 1.1.2.2 pgoyette return val;
407 1.1.2.2 pgoyette } else {
408 1.1.2.2 pgoyette return 1;
409 1.1.2.2 pgoyette }
410 1.1.2.2 pgoyette }
411 1.1.2.2 pgoyette
412 1.1.2.2 pgoyette static int
413 1.1.2.2 pgoyette meson_sdio_write_protect(sdmmc_chipset_handle_t sch)
414 1.1.2.2 pgoyette {
415 1.1.2.2 pgoyette struct meson_sdio_softc *sc = sch;
416 1.1.2.2 pgoyette int val;
417 1.1.2.2 pgoyette
418 1.1.2.2 pgoyette if (sc->sc_gpio_wp != NULL) {
419 1.1.2.2 pgoyette val = fdtbus_gpio_read(sc->sc_gpio_wp);
420 1.1.2.2 pgoyette if (sc->sc_gpio_wp_inverted)
421 1.1.2.2 pgoyette val = !val;
422 1.1.2.2 pgoyette return val;
423 1.1.2.2 pgoyette }
424 1.1.2.2 pgoyette
425 1.1.2.2 pgoyette return 0;
426 1.1.2.2 pgoyette }
427 1.1.2.2 pgoyette
428 1.1.2.2 pgoyette static int
429 1.1.2.2 pgoyette meson_sdio_bus_power(sdmmc_chipset_handle_t sch, uint32_t ocr)
430 1.1.2.2 pgoyette {
431 1.1.2.2 pgoyette return 0;
432 1.1.2.2 pgoyette }
433 1.1.2.2 pgoyette
434 1.1.2.2 pgoyette static int
435 1.1.2.2 pgoyette meson_sdio_bus_clock(sdmmc_chipset_handle_t sch, int freq)
436 1.1.2.2 pgoyette {
437 1.1.2.2 pgoyette struct meson_sdio_softc *sc = sch;
438 1.1.2.2 pgoyette
439 1.1.2.2 pgoyette return meson_sdio_set_clock(sc, freq);
440 1.1.2.2 pgoyette }
441 1.1.2.2 pgoyette
442 1.1.2.2 pgoyette static int
443 1.1.2.2 pgoyette meson_sdio_bus_width(sdmmc_chipset_handle_t sch, int width)
444 1.1.2.2 pgoyette {
445 1.1.2.2 pgoyette struct meson_sdio_softc *sc = sch;
446 1.1.2.2 pgoyette uint32_t conf;
447 1.1.2.2 pgoyette
448 1.1.2.2 pgoyette conf = SDIO_READ(sc, SDIO_CONF_REG);
449 1.1.2.2 pgoyette if (width == 1) {
450 1.1.2.2 pgoyette conf &= ~SDIO_CONF_BUS_WIDTH;
451 1.1.2.2 pgoyette } else if (width == 4) {
452 1.1.2.2 pgoyette conf |= SDIO_CONF_BUS_WIDTH;
453 1.1.2.2 pgoyette } else {
454 1.1.2.2 pgoyette return EINVAL;
455 1.1.2.2 pgoyette }
456 1.1.2.2 pgoyette SDIO_WRITE(sc, SDIO_CONF_REG, conf);
457 1.1.2.2 pgoyette
458 1.1.2.2 pgoyette sc->sc_cur_width = width;
459 1.1.2.2 pgoyette
460 1.1.2.2 pgoyette return 0;
461 1.1.2.2 pgoyette }
462 1.1.2.2 pgoyette
463 1.1.2.2 pgoyette static int
464 1.1.2.2 pgoyette meson_sdio_bus_rod(sdmmc_chipset_handle_t sch, int on)
465 1.1.2.2 pgoyette {
466 1.1.2.2 pgoyette return ENOTSUP;
467 1.1.2.2 pgoyette }
468 1.1.2.2 pgoyette
469 1.1.2.2 pgoyette static int
470 1.1.2.2 pgoyette meson_sdio_signal_voltage(sdmmc_chipset_handle_t sch, int signal_voltage)
471 1.1.2.2 pgoyette {
472 1.1.2.2 pgoyette struct meson_sdio_softc *sc = sch;
473 1.1.2.2 pgoyette u_int uvol;
474 1.1.2.2 pgoyette int error;
475 1.1.2.2 pgoyette
476 1.1.2.2 pgoyette if (sc->sc_reg_vqmmc == NULL)
477 1.1.2.2 pgoyette return 0;
478 1.1.2.2 pgoyette
479 1.1.2.2 pgoyette switch (signal_voltage) {
480 1.1.2.2 pgoyette case SDMMC_SIGNAL_VOLTAGE_330:
481 1.1.2.2 pgoyette uvol = 3300000;
482 1.1.2.2 pgoyette break;
483 1.1.2.2 pgoyette case SDMMC_SIGNAL_VOLTAGE_180:
484 1.1.2.2 pgoyette uvol = 1800000;
485 1.1.2.2 pgoyette break;
486 1.1.2.2 pgoyette default:
487 1.1.2.2 pgoyette return EINVAL;
488 1.1.2.2 pgoyette }
489 1.1.2.2 pgoyette
490 1.1.2.2 pgoyette error = fdtbus_regulator_supports_voltage(sc->sc_reg_vqmmc, uvol, uvol);
491 1.1.2.2 pgoyette if (error != 0)
492 1.1.2.2 pgoyette return 0;
493 1.1.2.2 pgoyette
494 1.1.2.2 pgoyette error = fdtbus_regulator_set_voltage(sc->sc_reg_vqmmc, uvol, uvol);
495 1.1.2.2 pgoyette if (error != 0)
496 1.1.2.2 pgoyette return error;
497 1.1.2.2 pgoyette
498 1.1.2.2 pgoyette return fdtbus_regulator_enable(sc->sc_reg_vqmmc);
499 1.1.2.2 pgoyette }
500 1.1.2.2 pgoyette
501 1.1.2.2 pgoyette static void
502 1.1.2.2 pgoyette meson_sdio_exec_command(sdmmc_chipset_handle_t sch, struct sdmmc_command *cmd)
503 1.1.2.2 pgoyette {
504 1.1.2.2 pgoyette struct meson_sdio_softc *sc = sch;
505 1.1.2.2 pgoyette uint32_t send, ext, mult, addr;
506 1.1.2.2 pgoyette bool use_bbuf = false;
507 1.1.2.2 pgoyette int i;
508 1.1.2.2 pgoyette
509 1.1.2.2 pgoyette KASSERT(cmd->c_blklen <= 512);
510 1.1.2.2 pgoyette
511 1.1.2.2 pgoyette send = ext = mult = addr = 0;
512 1.1.2.2 pgoyette
513 1.1.2.2 pgoyette mutex_enter(&sc->sc_intr_lock);
514 1.1.2.2 pgoyette
515 1.1.2.2 pgoyette if (cmd->c_opcode == SD_IO_SEND_OP_COND ||
516 1.1.2.2 pgoyette cmd->c_opcode == SD_IO_RW_DIRECT ||
517 1.1.2.2 pgoyette cmd->c_opcode == SD_IO_RW_EXTENDED) {
518 1.1.2.2 pgoyette cmd->c_error = EINVAL;
519 1.1.2.2 pgoyette goto done;
520 1.1.2.2 pgoyette }
521 1.1.2.2 pgoyette
522 1.1.2.2 pgoyette sc->sc_intr_irqs = 0;
523 1.1.2.2 pgoyette
524 1.1.2.2 pgoyette if (cmd->c_flags & SCF_RSP_PRESENT) {
525 1.1.2.2 pgoyette if (cmd->c_flags & SCF_RSP_136) {
526 1.1.2.2 pgoyette send |= __SHIFTIN(133, SDIO_SEND_RESPONSE_BITS);
527 1.1.2.2 pgoyette send |= SDIO_SEND_RESPONSE_CRC7_FROM_8;
528 1.1.2.2 pgoyette } else {
529 1.1.2.2 pgoyette send |= __SHIFTIN(45, SDIO_SEND_RESPONSE_BITS);
530 1.1.2.2 pgoyette }
531 1.1.2.2 pgoyette }
532 1.1.2.2 pgoyette if ((cmd->c_flags & SCF_RSP_CRC) == 0) {
533 1.1.2.2 pgoyette send |= SDIO_SEND_RESPONSE_NO_CRC;
534 1.1.2.2 pgoyette }
535 1.1.2.2 pgoyette if (cmd->c_flags & SCF_RSP_BSY) {
536 1.1.2.2 pgoyette send |= SDIO_SEND_CHECK_BUSY_DAT0;
537 1.1.2.2 pgoyette }
538 1.1.2.2 pgoyette
539 1.1.2.2 pgoyette if (cmd->c_datalen > 0) {
540 1.1.2.2 pgoyette unsigned int nblks, packlen;
541 1.1.2.2 pgoyette
542 1.1.2.2 pgoyette nblks = cmd->c_datalen / cmd->c_blklen;
543 1.1.2.2 pgoyette if (nblks == 0 || (cmd->c_datalen % cmd->c_blklen) != 0)
544 1.1.2.2 pgoyette ++nblks;
545 1.1.2.2 pgoyette packlen = (cmd->c_blklen * 8) + (0xf * sc->sc_cur_width);
546 1.1.2.2 pgoyette
547 1.1.2.2 pgoyette send |= __SHIFTIN(nblks - 1, SDIO_SEND_REPEAT_PACKAGE);
548 1.1.2.2 pgoyette ext |= __SHIFTIN(packlen, SDIO_EXT_DATA_RW_NUMBER);
549 1.1.2.2 pgoyette
550 1.1.2.2 pgoyette if (ISSET(cmd->c_flags, SCF_CMD_READ)) {
551 1.1.2.2 pgoyette send |= SDIO_SEND_RESPONSE_DATA;
552 1.1.2.2 pgoyette } else {
553 1.1.2.2 pgoyette send |= SDIO_SEND_COMMAND_HAS_DATA;
554 1.1.2.2 pgoyette }
555 1.1.2.2 pgoyette
556 1.1.2.2 pgoyette cmd->c_error = bus_dmamap_load(sc->sc_dmat, sc->sc_dmamap,
557 1.1.2.2 pgoyette sc->sc_bbuf, MAXPHYS, NULL, BUS_DMA_WAITOK);
558 1.1.2.2 pgoyette if (cmd->c_error) {
559 1.1.2.2 pgoyette device_printf(sc->sc_dev, "bus_dmamap_load failed\n");
560 1.1.2.2 pgoyette goto done;
561 1.1.2.2 pgoyette }
562 1.1.2.2 pgoyette if (ISSET(cmd->c_flags, SCF_CMD_READ)) {
563 1.1.2.2 pgoyette bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap, 0,
564 1.1.2.2 pgoyette MAXPHYS, BUS_DMASYNC_PREREAD);
565 1.1.2.2 pgoyette } else {
566 1.1.2.2 pgoyette memcpy(sc->sc_bbuf, cmd->c_data, cmd->c_datalen);
567 1.1.2.2 pgoyette bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap, 0,
568 1.1.2.2 pgoyette MAXPHYS, BUS_DMASYNC_PREWRITE);
569 1.1.2.2 pgoyette }
570 1.1.2.2 pgoyette addr = sc->sc_dmamap->dm_segs[0].ds_addr;
571 1.1.2.2 pgoyette use_bbuf = true;
572 1.1.2.2 pgoyette }
573 1.1.2.2 pgoyette send |= __SHIFTIN(cmd->c_opcode | 0x40, SDIO_SEND_COMMAND_INDEX);
574 1.1.2.2 pgoyette
575 1.1.2.2 pgoyette mult |= __SHIFTIN(sc->sc_cur_port, SDIO_MULT_PORT_SEL);
576 1.1.2.2 pgoyette
577 1.1.2.2 pgoyette SDIO_WRITE(sc, SDIO_IRQC_REG, SDIO_IRQC_SOFT_RESET);
578 1.1.2.2 pgoyette delay(2);
579 1.1.2.2 pgoyette
580 1.1.2.2 pgoyette SDIO_WRITE(sc, SDIO_IRQC_REG, SDIO_IRQC_ARC_CMD_INTEN);
581 1.1.2.2 pgoyette SDIO_WRITE(sc, SDIO_IRQS_REG, SDIO_IRQS_CLEAR);
582 1.1.2.2 pgoyette
583 1.1.2.2 pgoyette SDIO_WRITE(sc, SDIO_ARGU_REG, cmd->c_arg);
584 1.1.2.2 pgoyette SDIO_WRITE(sc, SDIO_MULT_REG, mult);
585 1.1.2.2 pgoyette SDIO_WRITE(sc, SDIO_EXT_REG, ext);
586 1.1.2.2 pgoyette SDIO_WRITE(sc, SDIO_ADDR_REG, addr);
587 1.1.2.2 pgoyette SDIO_WRITE(sc, SDIO_SEND_REG, send);
588 1.1.2.2 pgoyette
589 1.1.2.2 pgoyette cmd->c_error = meson_sdio_wait_irqs(sc, SDIO_IRQS_CMD_INT, hz * 3);
590 1.1.2.2 pgoyette if (cmd->c_error) {
591 1.1.2.2 pgoyette goto done;
592 1.1.2.2 pgoyette }
593 1.1.2.2 pgoyette
594 1.1.2.2 pgoyette if (SDIO_READ(sc, SDIO_IRQS_REG) & SDIO_IRQS_CMD_BUSY) {
595 1.1.2.2 pgoyette int retry;
596 1.1.2.2 pgoyette for (retry = 10000; retry > 0; retry--) {
597 1.1.2.2 pgoyette const uint32_t irqs = SDIO_READ(sc, SDIO_IRQS_REG);
598 1.1.2.2 pgoyette if ((irqs & SDIO_IRQS_CMD_BUSY) == 0)
599 1.1.2.2 pgoyette break;
600 1.1.2.2 pgoyette delay(100);
601 1.1.2.2 pgoyette }
602 1.1.2.2 pgoyette if (retry == 0) {
603 1.1.2.2 pgoyette aprint_debug_dev(sc->sc_dev,
604 1.1.2.2 pgoyette "busy timeout, opcode %d flags %#x datalen %d\n",
605 1.1.2.2 pgoyette cmd->c_opcode, cmd->c_flags, cmd->c_datalen);
606 1.1.2.2 pgoyette cmd->c_error = ETIMEDOUT;
607 1.1.2.2 pgoyette goto done;
608 1.1.2.2 pgoyette }
609 1.1.2.2 pgoyette }
610 1.1.2.2 pgoyette
611 1.1.2.2 pgoyette const uint32_t irqs = SDIO_READ(sc, SDIO_IRQS_REG);
612 1.1.2.2 pgoyette if (cmd->c_flags & SCF_RSP_CRC) {
613 1.1.2.2 pgoyette if ((irqs & SDIO_IRQS_RESPONSE_CRC7_OK) == 0) {
614 1.1.2.2 pgoyette device_printf(sc->sc_dev, "response crc error\n");
615 1.1.2.2 pgoyette cmd->c_error = EIO;
616 1.1.2.2 pgoyette goto done;
617 1.1.2.2 pgoyette }
618 1.1.2.2 pgoyette }
619 1.1.2.2 pgoyette if (cmd->c_datalen > 0) {
620 1.1.2.2 pgoyette uint32_t crcmask = SDIO_IRQS_DATA_READ_CRC16_OK|
621 1.1.2.2 pgoyette SDIO_IRQS_DATA_WRITE_CRC16_OK;
622 1.1.2.2 pgoyette if ((irqs & crcmask) == 0) {
623 1.1.2.2 pgoyette device_printf(sc->sc_dev, "data crc error\n");
624 1.1.2.2 pgoyette cmd->c_error = EIO;
625 1.1.2.2 pgoyette goto done;
626 1.1.2.2 pgoyette }
627 1.1.2.2 pgoyette }
628 1.1.2.2 pgoyette
629 1.1.2.2 pgoyette if (cmd->c_flags & SCF_RSP_PRESENT) {
630 1.1.2.2 pgoyette mult |= SDIO_MULT_WRITE_READ_OUT_INDEX;
631 1.1.2.2 pgoyette mult &= ~SDIO_MULT_RESPONSE_READ_INDEX;
632 1.1.2.2 pgoyette SDIO_WRITE(sc, SDIO_MULT_REG, mult);
633 1.1.2.2 pgoyette
634 1.1.2.2 pgoyette if (cmd->c_flags & SCF_RSP_136) {
635 1.1.2.2 pgoyette for (i = 0; i < 4; i++) {
636 1.1.2.2 pgoyette cmd->c_resp[i] = SDIO_READ(sc, SDIO_ARGU_REG);
637 1.1.2.2 pgoyette }
638 1.1.2.2 pgoyette } else {
639 1.1.2.2 pgoyette cmd->c_resp[0] = SDIO_READ(sc, SDIO_ARGU_REG);
640 1.1.2.2 pgoyette }
641 1.1.2.2 pgoyette }
642 1.1.2.2 pgoyette
643 1.1.2.2 pgoyette done:
644 1.1.2.2 pgoyette if (use_bbuf) {
645 1.1.2.2 pgoyette if (ISSET(cmd->c_flags, SCF_CMD_READ)) {
646 1.1.2.2 pgoyette bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap, 0,
647 1.1.2.2 pgoyette MAXPHYS, BUS_DMASYNC_POSTREAD);
648 1.1.2.2 pgoyette } else {
649 1.1.2.2 pgoyette bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap, 0,
650 1.1.2.2 pgoyette MAXPHYS, BUS_DMASYNC_POSTWRITE);
651 1.1.2.2 pgoyette }
652 1.1.2.2 pgoyette bus_dmamap_unload(sc->sc_dmat, sc->sc_dmamap);
653 1.1.2.2 pgoyette if (ISSET(cmd->c_flags, SCF_CMD_READ)) {
654 1.1.2.2 pgoyette memcpy(cmd->c_data, sc->sc_bbuf, cmd->c_datalen);
655 1.1.2.2 pgoyette }
656 1.1.2.2 pgoyette }
657 1.1.2.2 pgoyette cmd->c_flags |= SCF_ITSDONE;
658 1.1.2.2 pgoyette
659 1.1.2.2 pgoyette SDIO_WRITE(sc, SDIO_IRQC_REG, 0);
660 1.1.2.2 pgoyette SDIO_WRITE(sc, SDIO_IRQS_REG, SDIO_IRQS_CLEAR);
661 1.1.2.2 pgoyette
662 1.1.2.2 pgoyette mutex_exit(&sc->sc_intr_lock);
663 1.1.2.2 pgoyette }
664 1.1.2.2 pgoyette
665 1.1.2.2 pgoyette static void
666 1.1.2.2 pgoyette meson_sdio_card_enable_intr(sdmmc_chipset_handle_t sch, int enable)
667 1.1.2.2 pgoyette {
668 1.1.2.2 pgoyette struct meson_sdio_softc *sc = sch;
669 1.1.2.2 pgoyette uint32_t irqc;
670 1.1.2.2 pgoyette
671 1.1.2.2 pgoyette mutex_enter(&sc->sc_intr_lock);
672 1.1.2.2 pgoyette irqc = SDIO_READ(sc, SDIO_IRQC_REG);
673 1.1.2.2 pgoyette if (enable) {
674 1.1.2.2 pgoyette irqc |= SDIO_IRQC_ARC_IF_INTEN;
675 1.1.2.2 pgoyette } else {
676 1.1.2.2 pgoyette irqc &= ~SDIO_IRQC_ARC_IF_INTEN;
677 1.1.2.2 pgoyette }
678 1.1.2.2 pgoyette SDIO_WRITE(sc, SDIO_IRQC_REG, irqc);
679 1.1.2.2 pgoyette mutex_exit(&sc->sc_intr_lock);
680 1.1.2.2 pgoyette }
681 1.1.2.2 pgoyette
682 1.1.2.2 pgoyette static void
683 1.1.2.2 pgoyette meson_sdio_card_intr_ack(sdmmc_chipset_handle_t sch)
684 1.1.2.2 pgoyette {
685 1.1.2.2 pgoyette struct meson_sdio_softc *sc = sch;
686 1.1.2.2 pgoyette
687 1.1.2.2 pgoyette mutex_enter(&sc->sc_intr_lock);
688 1.1.2.2 pgoyette SDIO_WRITE(sc, SDIO_IRQS_REG, SDIO_IRQS_IF_INT);
689 1.1.2.2 pgoyette mutex_exit(&sc->sc_intr_lock);
690 1.1.2.2 pgoyette }
691