2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2018 Rubicon Communications, LLC (Netgate)
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 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.
29 * Marvell Xenon SDHCI controller driver.
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include <sys/param.h>
36 #include <sys/systm.h>
38 #include <sys/kernel.h>
40 #include <sys/module.h>
41 #include <sys/mutex.h>
42 #include <sys/resource.h>
44 #include <sys/sysctl.h>
45 #include <sys/taskqueue.h>
47 #include <machine/bus.h>
48 #include <machine/resource.h>
50 #include <dev/extres/regulator/regulator.h>
51 #include <dev/fdt/fdt_common.h>
52 #include <dev/ofw/ofw_bus.h>
53 #include <dev/ofw/ofw_bus_subr.h>
55 #include <dev/mmc/bridge.h>
56 #include <dev/mmc/mmc_fdt_helpers.h>
57 #include <dev/mmc/mmcbrvar.h>
58 #include <dev/mmc/mmcreg.h>
60 #include <dev/sdhci/sdhci.h>
61 #include <dev/sdhci/sdhci_fdt_gpio.h>
62 #include <dev/sdhci/sdhci_xenon.h>
67 #include "opt_mmccam.h"
72 static struct ofw_compat_data compat_data[] = {
73 { "marvell,armada-3700-sdhci", 1 },
75 { "marvell,armada-cp110-sdhci", 1 },
76 { "marvell,armada-ap806-sdhci", 1 },
81 struct sdhci_xenon_softc {
82 device_t dev; /* Controller device */
83 int slot_id; /* Controller ID */
84 phandle_t node; /* FDT node */
85 uint32_t quirks; /* Chip specific quirks */
86 uint32_t caps; /* If we override SDHCI_CAPABILITIES */
87 uint32_t max_clk; /* Max possible freq */
88 struct resource *irq_res; /* IRQ resource */
89 void *intrhand; /* Interrupt handle */
90 struct sdhci_fdt_gpio *gpio; /* GPIO pins for CD detection. */
92 struct sdhci_slot *slot; /* SDHCI internal data */
93 struct resource *mem_res; /* Memory resource */
95 uint8_t znr; /* PHY ZNR */
96 uint8_t zpr; /* PHY ZPR */
97 bool no_18v; /* No 1.8V support */
98 bool slow_mode; /* PHY slow mode */
100 struct mmc_fdt_helper mmc_helper; /* MMC helper for parsing FDT */
104 sdhci_xenon_read_1(device_t dev, struct sdhci_slot *slot __unused,
107 struct sdhci_xenon_softc *sc = device_get_softc(dev);
109 return (bus_read_1(sc->mem_res, off));
113 sdhci_xenon_write_1(device_t dev, struct sdhci_slot *slot __unused,
114 bus_size_t off, uint8_t val)
116 struct sdhci_xenon_softc *sc = device_get_softc(dev);
118 bus_write_1(sc->mem_res, off, val);
122 sdhci_xenon_read_2(device_t dev, struct sdhci_slot *slot __unused,
125 struct sdhci_xenon_softc *sc = device_get_softc(dev);
127 return (bus_read_2(sc->mem_res, off));
131 sdhci_xenon_write_2(device_t dev, struct sdhci_slot *slot __unused,
132 bus_size_t off, uint16_t val)
134 struct sdhci_xenon_softc *sc = device_get_softc(dev);
136 bus_write_2(sc->mem_res, off, val);
140 sdhci_xenon_read_4(device_t dev, struct sdhci_slot *slot __unused,
143 struct sdhci_xenon_softc *sc = device_get_softc(dev);
145 return bus_read_4(sc->mem_res, off);
149 sdhci_xenon_write_4(device_t dev, struct sdhci_slot *slot __unused,
150 bus_size_t off, uint32_t val)
152 struct sdhci_xenon_softc *sc = device_get_softc(dev);
154 bus_write_4(sc->mem_res, off, val);
158 sdhci_xenon_read_multi_4(device_t dev, struct sdhci_slot *slot __unused,
159 bus_size_t off, uint32_t *data, bus_size_t count)
161 struct sdhci_xenon_softc *sc = device_get_softc(dev);
163 bus_read_multi_4(sc->mem_res, off, data, count);
167 sdhci_xenon_write_multi_4(device_t dev, struct sdhci_slot *slot __unused,
168 bus_size_t off, uint32_t *data, bus_size_t count)
170 struct sdhci_xenon_softc *sc = device_get_softc(dev);
172 bus_write_multi_4(sc->mem_res, off, data, count);
176 sdhci_xenon_intr(void *arg)
178 struct sdhci_xenon_softc *sc = (struct sdhci_xenon_softc *)arg;
180 sdhci_generic_intr(sc->slot);
184 sdhci_xenon_get_ro(device_t bus, device_t dev)
186 struct sdhci_xenon_softc *sc = device_get_softc(bus);
188 return (sdhci_generic_get_ro(bus, dev) ^
189 (sc->mmc_helper.props & MMC_PROP_WP_INVERTED));
193 sdhci_xenon_get_card_present(device_t dev, struct sdhci_slot *slot)
195 struct sdhci_xenon_softc *sc = device_get_softc(dev);
197 return (sdhci_fdt_gpio_get_present(sc->gpio));
201 sdhci_xenon_set_uhs_timing(device_t brdev, struct sdhci_slot *slot)
203 const struct mmc_ios *ios;
206 if (slot->version < SDHCI_SPEC_300)
209 mtx_assert(&slot->mtx, MA_OWNED);
210 ios = &slot->host.ios;
212 /* Update timing parameteres in SDHCI_HOST_CONTROL2 register. */
213 hostctrl2 = sdhci_xenon_read_2(brdev, slot, SDHCI_HOST_CONTROL2);
214 hostctrl2 &= ~SDHCI_CTRL2_UHS_MASK;
215 if (ios->clock > SD_SDR50_MAX) {
216 if (ios->timing == bus_timing_mmc_hs400 ||
217 ios->timing == bus_timing_mmc_hs400es)
218 hostctrl2 |= XENON_CTRL2_MMC_HS400;
219 else if (ios->timing == bus_timing_mmc_hs200)
220 hostctrl2 |= XENON_CTRL2_MMC_HS200;
222 hostctrl2 |= SDHCI_CTRL2_UHS_SDR104;
224 else if (ios->clock > SD_SDR25_MAX)
225 hostctrl2 |= SDHCI_CTRL2_UHS_SDR50;
226 else if (ios->clock > SD_SDR12_MAX) {
227 if (ios->timing == bus_timing_uhs_ddr50 ||
228 ios->timing == bus_timing_mmc_ddr52)
229 hostctrl2 |= SDHCI_CTRL2_UHS_DDR50;
231 hostctrl2 |= SDHCI_CTRL2_UHS_SDR25;
232 } else if (ios->clock > SD_MMC_CARD_ID_FREQUENCY)
233 hostctrl2 |= SDHCI_CTRL2_UHS_SDR12;
234 sdhci_xenon_write_2(brdev, slot, SDHCI_HOST_CONTROL2, hostctrl2);
238 sdhci_xenon_phy_init(device_t brdev, struct mmc_ios *ios)
241 struct sdhci_xenon_softc *sc;
244 sc = device_get_softc(brdev);
245 reg = bus_read_4(sc->mem_res, XENON_EMMC_PHY_TIMING_ADJUST);
246 reg |= XENON_SAMPL_INV_QSP_PHASE_SELECT;
247 switch (ios->timing) {
248 case bus_timing_normal:
250 case bus_timing_uhs_sdr12:
251 case bus_timing_uhs_sdr25:
252 case bus_timing_uhs_sdr50:
253 reg |= XENON_TIMING_ADJUST_SLOW_MODE;
256 reg &= ~XENON_TIMING_ADJUST_SLOW_MODE;
259 reg |= XENON_TIMING_ADJUST_SLOW_MODE;
260 bus_write_4(sc->mem_res, XENON_EMMC_PHY_TIMING_ADJUST, reg);
262 reg = bus_read_4(sc->mem_res, XENON_EMMC_PHY_TIMING_ADJUST);
263 reg |= XENON_PHY_INITIALIZATION;
264 bus_write_4(sc->mem_res, XENON_EMMC_PHY_TIMING_ADJUST, reg);
266 /* Wait for the eMMC PHY init. */
267 for (i = 100; i > 0; i--) {
270 reg = bus_read_4(sc->mem_res, XENON_EMMC_PHY_TIMING_ADJUST);
271 if ((reg & XENON_PHY_INITIALIZATION) == 0)
276 device_printf(brdev, "eMMC PHY failed to initialize\n");
284 sdhci_xenon_phy_set(device_t brdev, struct mmc_ios *ios)
286 struct sdhci_xenon_softc *sc;
289 sc = device_get_softc(brdev);
290 /* Setup pad, set bit[28] and bits[26:24] */
291 reg = bus_read_4(sc->mem_res, XENON_EMMC_PHY_PAD_CONTROL);
292 reg |= (XENON_FC_DQ_RECEN | XENON_FC_CMD_RECEN |
293 XENON_FC_QSP_RECEN | XENON_OEN_QSN);
294 /* All FC_XX_RECEIVCE should be set as CMOS Type */
295 reg |= XENON_FC_ALL_CMOS_RECEIVER;
296 bus_write_4(sc->mem_res, XENON_EMMC_PHY_PAD_CONTROL, reg);
298 /* Set CMD and DQ Pull Up */
299 reg = bus_read_4(sc->mem_res, XENON_EMMC_PHY_PAD_CONTROL1);
300 reg |= (XENON_EMMC_FC_CMD_PU | XENON_EMMC_FC_DQ_PU);
301 reg &= ~(XENON_EMMC_FC_CMD_PD | XENON_EMMC_FC_DQ_PD);
302 bus_write_4(sc->mem_res, XENON_EMMC_PHY_PAD_CONTROL1, reg);
304 if (ios->timing == bus_timing_normal)
305 return (sdhci_xenon_phy_init(brdev, ios));
307 /* Clear SDIO mode, no SDIO support for now. */
308 reg = bus_read_4(sc->mem_res, XENON_EMMC_PHY_TIMING_ADJUST);
309 reg &= ~XENON_TIMING_ADJUST_SDIO_MODE;
310 bus_write_4(sc->mem_res, XENON_EMMC_PHY_TIMING_ADJUST, reg);
313 * Set preferred ZNR and ZPR value.
314 * The ZNR and ZPR value vary between different boards.
315 * Define them both in the DTS for the board!
317 reg = bus_read_4(sc->mem_res, XENON_EMMC_PHY_PAD_CONTROL2);
318 reg &= ~((XENON_ZNR_MASK << XENON_ZNR_SHIFT) | XENON_ZPR_MASK);
319 reg |= ((sc->znr << XENON_ZNR_SHIFT) | sc->zpr);
320 bus_write_4(sc->mem_res, XENON_EMMC_PHY_PAD_CONTROL2, reg);
322 /* Disable the SD clock to set EMMC_PHY_FUNC_CONTROL. */
323 reg = bus_read_4(sc->mem_res, SDHCI_CLOCK_CONTROL);
324 reg &= ~SDHCI_CLOCK_CARD_EN;
325 bus_write_4(sc->mem_res, SDHCI_CLOCK_CONTROL, reg);
327 reg = bus_read_4(sc->mem_res, XENON_EMMC_PHY_FUNC_CONTROL);
328 switch (ios->timing) {
329 case bus_timing_mmc_hs400:
330 reg |= (XENON_DQ_DDR_MODE_MASK << XENON_DQ_DDR_MODE_SHIFT) |
332 reg &= ~XENON_DQ_ASYNC_MODE;
334 case bus_timing_uhs_ddr50:
335 case bus_timing_mmc_ddr52:
336 reg |= (XENON_DQ_DDR_MODE_MASK << XENON_DQ_DDR_MODE_SHIFT) |
337 XENON_CMD_DDR_MODE | XENON_DQ_ASYNC_MODE;
340 reg &= ~((XENON_DQ_DDR_MODE_MASK << XENON_DQ_DDR_MODE_SHIFT) |
342 reg |= XENON_DQ_ASYNC_MODE;
344 bus_write_4(sc->mem_res, XENON_EMMC_PHY_FUNC_CONTROL, reg);
346 /* Enable SD clock. */
347 reg = bus_read_4(sc->mem_res, SDHCI_CLOCK_CONTROL);
348 reg |= SDHCI_CLOCK_CARD_EN;
349 bus_write_4(sc->mem_res, SDHCI_CLOCK_CONTROL, reg);
351 if (ios->timing == bus_timing_mmc_hs400)
352 bus_write_4(sc->mem_res, XENON_EMMC_PHY_LOGIC_TIMING_ADJUST,
353 XENON_LOGIC_TIMING_VALUE);
355 /* Disable both SDHC Data Strobe and Enhanced Strobe. */
356 reg = bus_read_4(sc->mem_res, XENON_SLOT_EMMC_CTRL);
357 reg &= ~(XENON_ENABLE_DATA_STROBE | XENON_ENABLE_RESP_STROBE);
358 bus_write_4(sc->mem_res, XENON_SLOT_EMMC_CTRL, reg);
360 /* Clear Strobe line Pull down or Pull up. */
361 reg = bus_read_4(sc->mem_res, XENON_EMMC_PHY_PAD_CONTROL1);
362 reg &= ~(XENON_EMMC_FC_QSP_PD | XENON_EMMC_FC_QSP_PU);
363 bus_write_4(sc->mem_res, XENON_EMMC_PHY_PAD_CONTROL1, reg);
366 return (sdhci_xenon_phy_init(brdev, ios));
370 sdhci_xenon_update_ios(device_t brdev, device_t reqdev)
373 struct sdhci_xenon_softc *sc;
375 struct sdhci_slot *slot;
378 err = sdhci_generic_update_ios(brdev, reqdev);
382 sc = device_get_softc(brdev);
383 slot = device_get_ivars(reqdev);
384 ios = &slot->host.ios;
386 switch (ios->power_mode) {
391 device_printf(sc->dev, "Powering down sd/mmc\n");
393 if (sc->mmc_helper.vmmc_supply)
394 regulator_disable(sc->mmc_helper.vmmc_supply);
395 if (sc->mmc_helper.vqmmc_supply)
396 regulator_disable(sc->mmc_helper.vqmmc_supply);
400 device_printf(sc->dev, "Powering up sd/mmc\n");
402 if (sc->mmc_helper.vmmc_supply)
403 regulator_enable(sc->mmc_helper.vmmc_supply);
404 if (sc->mmc_helper.vqmmc_supply)
405 regulator_enable(sc->mmc_helper.vqmmc_supply);
409 /* Update the PHY settings. */
411 sdhci_xenon_phy_set(brdev, ios);
413 if (ios->clock > SD_MMC_CARD_ID_FREQUENCY) {
414 /* Enable SDCLK_IDLEOFF. */
415 reg = bus_read_4(sc->mem_res, XENON_SYS_OP_CTRL);
416 reg |= 1 << (XENON_SDCLK_IDLEOFF_ENABLE_SHIFT + sc->slot_id);
417 bus_write_4(sc->mem_res, XENON_SYS_OP_CTRL, reg);
424 sdhci_xenon_switch_vccq(device_t brdev, device_t reqdev)
426 struct sdhci_xenon_softc *sc;
427 struct sdhci_slot *slot;
431 slot = device_get_ivars(reqdev);
433 if (slot->version < SDHCI_SPEC_300)
436 sc = device_get_softc(brdev);
438 if (sc->mmc_helper.vqmmc_supply == NULL)
443 hostctrl2 = bus_read_2(sc->mem_res, SDHCI_HOST_CONTROL2);
444 switch (slot->host.ios.vccq) {
446 if (!(hostctrl2 & SDHCI_CTRL2_S18_ENABLE))
448 hostctrl2 &= ~SDHCI_CTRL2_S18_ENABLE;
449 bus_write_2(sc->mem_res, SDHCI_HOST_CONTROL2, hostctrl2);
452 err = regulator_set_voltage(sc->mmc_helper.vqmmc_supply,
455 device_printf(sc->dev,
456 "Cannot set vqmmc to %d<->%d\n",
463 * According to the 'SD Host Controller Simplified
464 * Specification 4.20 the host driver should take more
465 * than 5ms for stable time of host voltage regulator
466 * from changing 1.8V Signaling Enable.
469 hostctrl2 = bus_read_2(sc->mem_res, SDHCI_HOST_CONTROL2);
470 if (!(hostctrl2 & SDHCI_CTRL2_S18_ENABLE))
474 if (!(slot->host.caps & MMC_CAP_SIGNALING_180)) {
477 if (hostctrl2 & SDHCI_CTRL2_S18_ENABLE)
479 hostctrl2 |= SDHCI_CTRL2_S18_ENABLE;
480 bus_write_2(sc->mem_res, SDHCI_HOST_CONTROL2, hostctrl2);
483 err = regulator_set_voltage(sc->mmc_helper.vqmmc_supply,
486 device_printf(sc->dev,
487 "Cannot set vqmmc to %d<->%d\n",
494 * According to the 'SD Host Controller Simplified
495 * Specification 4.20 the host driver should take more
496 * than 5ms for stable time of host voltage regulator
497 * from changing 1.8V Signaling Enable.
500 hostctrl2 = bus_read_2(sc->mem_res, SDHCI_HOST_CONTROL2);
501 if (hostctrl2 & SDHCI_CTRL2_S18_ENABLE)
506 "Attempt to set unsupported signaling voltage\n");
512 sdhci_xenon_probe(device_t dev)
514 struct sdhci_xenon_softc *sc = device_get_softc(dev);
519 sc->max_clk = XENON_MMC_MAX_CLK;
521 if (!ofw_bus_status_okay(dev))
524 if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
527 sc->node = ofw_bus_get_node(dev);
528 device_set_desc(dev, "Armada Xenon SDHCI controller");
530 /* Allow dts to patch quirks, slots, and max-frequency. */
531 if ((OF_getencprop(sc->node, "quirks", &cid, sizeof(cid))) > 0)
533 if ((OF_getencprop(sc->node, "max-frequency", &cid, sizeof(cid))) > 0)
535 if (OF_hasprop(sc->node, "no-1-8-v"))
537 if (OF_hasprop(sc->node, "marvell,xenon-phy-slow-mode"))
538 sc->slow_mode = true;
539 sc->znr = XENON_ZNR_DEF_VALUE;
540 if ((OF_getencprop(sc->node, "marvell,xenon-phy-znr", &cid,
542 sc->znr = cid & XENON_ZNR_MASK;
543 sc->zpr = XENON_ZPR_DEF_VALUE;
544 if ((OF_getencprop(sc->node, "marvell,xenon-phy-zpr", &cid,
546 sc->zpr = cid & XENON_ZPR_MASK;
552 sdhci_xenon_attach(device_t dev)
554 struct sdhci_xenon_softc *sc = device_get_softc(dev);
555 struct sdhci_slot *slot;
563 sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
565 if (sc->irq_res == NULL) {
566 device_printf(dev, "Can't allocate IRQ\n");
570 /* Allocate memory. */
572 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
574 if (sc->mem_res == NULL) {
575 bus_release_resource(dev, SYS_RES_IRQ,
576 rman_get_rid(sc->irq_res), sc->irq_res);
577 device_printf(dev, "Can't allocate memory for slot\n");
581 slot = malloc(sizeof(*slot), M_DEVBUF, M_ZERO | M_WAITOK);
583 /* Check if the device is flagged as non-removable. */
584 if (OF_hasprop(sc->node, "non-removable")) {
585 slot->opt |= SDHCI_NON_REMOVABLE;
587 device_printf(dev, "Non-removable media\n");
590 slot->quirks = sc->quirks;
591 slot->caps = sc->caps;
592 slot->max_clk = sc->max_clk;
596 * Set up any gpio pin handling described in the FDT data. This cannot
597 * fail; see comments in sdhci_fdt_gpio.h for details.
599 sc->gpio = sdhci_fdt_gpio_setup(dev, slot);
601 mmc_fdt_parse(dev, 0, &sc->mmc_helper, &sc->slot->host);
603 if (sdhci_init_slot(dev, sc->slot, 0))
606 /* 1.2V signaling is not supported. */
607 sc->slot->host.caps &= ~MMC_CAP_SIGNALING_120;
609 /* Disable UHS in case of lack of 1.8V VCCQ or the PHY slow mode. */
610 if (sc->no_18v || sc->slow_mode)
611 sc->slot->host.caps &= ~MMC_CAP_SIGNALING_180;
613 /* Activate the interrupt */
614 err = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_MISC | INTR_MPSAFE,
615 NULL, sdhci_xenon_intr, sc, &sc->intrhand);
617 device_printf(dev, "Cannot setup IRQ\n");
621 /* Disable Auto Clock Gating. */
622 reg = bus_read_4(sc->mem_res, XENON_SYS_OP_CTRL);
623 reg |= XENON_AUTO_CLKGATE_DISABLE;
624 bus_write_4(sc->mem_res, XENON_SYS_OP_CTRL, reg);
626 /* Enable this SD controller. */
627 reg |= (1 << sc->slot_id);
628 bus_write_4(sc->mem_res, XENON_SYS_OP_CTRL, reg);
630 /* Enable Parallel Transfer. */
631 reg = bus_read_4(sc->mem_res, XENON_SYS_EXT_OP_CTRL);
632 reg |= (1 << sc->slot_id);
633 bus_write_4(sc->mem_res, XENON_SYS_EXT_OP_CTRL, reg);
635 /* Enable Auto Clock Gating. */
636 reg &= ~XENON_AUTO_CLKGATE_DISABLE;
637 bus_write_4(sc->mem_res, XENON_SYS_OP_CTRL, reg);
639 /* Disable SDCLK_IDLEOFF before the card initialization. */
640 reg = bus_read_4(sc->mem_res, XENON_SYS_OP_CTRL);
641 reg &= ~(1 << (XENON_SDCLK_IDLEOFF_ENABLE_SHIFT + sc->slot_id));
642 bus_write_4(sc->mem_res, XENON_SYS_OP_CTRL, reg);
644 /* Mask command conflict errors. */
645 reg = bus_read_4(sc->mem_res, XENON_SYS_EXT_OP_CTRL);
646 reg |= XENON_MASK_CMD_CONFLICT_ERR;
647 bus_write_4(sc->mem_res, XENON_SYS_EXT_OP_CTRL, reg);
649 /* Process cards detection. */
650 sdhci_start_slot(sc->slot);
655 bus_release_resource(dev, SYS_RES_IRQ, rman_get_rid(sc->irq_res),
657 bus_release_resource(dev, SYS_RES_MEMORY, rman_get_rid(sc->mem_res),
659 free(sc->slot, M_DEVBUF);
666 sdhci_xenon_detach(device_t dev)
668 struct sdhci_xenon_softc *sc = device_get_softc(dev);
670 if (sc->gpio != NULL)
671 sdhci_fdt_gpio_teardown(sc->gpio);
673 bus_generic_detach(dev);
674 bus_teardown_intr(dev, sc->irq_res, sc->intrhand);
675 bus_release_resource(dev, SYS_RES_IRQ, rman_get_rid(sc->irq_res),
677 sdhci_cleanup_slot(sc->slot);
678 bus_release_resource(dev, SYS_RES_MEMORY, rman_get_rid(sc->mem_res),
680 free(sc->slot, M_DEVBUF);
686 static device_method_t sdhci_xenon_methods[] = {
688 DEVMETHOD(device_probe, sdhci_xenon_probe),
689 DEVMETHOD(device_attach, sdhci_xenon_attach),
690 DEVMETHOD(device_detach, sdhci_xenon_detach),
693 DEVMETHOD(bus_read_ivar, sdhci_generic_read_ivar),
694 DEVMETHOD(bus_write_ivar, sdhci_generic_write_ivar),
697 DEVMETHOD(mmcbr_update_ios, sdhci_xenon_update_ios),
698 DEVMETHOD(mmcbr_request, sdhci_generic_request),
699 DEVMETHOD(mmcbr_get_ro, sdhci_xenon_get_ro),
700 DEVMETHOD(mmcbr_acquire_host, sdhci_generic_acquire_host),
701 DEVMETHOD(mmcbr_release_host, sdhci_generic_release_host),
702 DEVMETHOD(mmcbr_switch_vccq, sdhci_xenon_switch_vccq),
703 DEVMETHOD(mmcbr_tune, sdhci_generic_tune),
704 DEVMETHOD(mmcbr_retune, sdhci_generic_retune),
706 /* SDHCI registers accessors */
707 DEVMETHOD(sdhci_read_1, sdhci_xenon_read_1),
708 DEVMETHOD(sdhci_read_2, sdhci_xenon_read_2),
709 DEVMETHOD(sdhci_read_4, sdhci_xenon_read_4),
710 DEVMETHOD(sdhci_read_multi_4, sdhci_xenon_read_multi_4),
711 DEVMETHOD(sdhci_write_1, sdhci_xenon_write_1),
712 DEVMETHOD(sdhci_write_2, sdhci_xenon_write_2),
713 DEVMETHOD(sdhci_write_4, sdhci_xenon_write_4),
714 DEVMETHOD(sdhci_write_multi_4, sdhci_xenon_write_multi_4),
715 DEVMETHOD(sdhci_get_card_present, sdhci_xenon_get_card_present),
716 DEVMETHOD(sdhci_set_uhs_timing, sdhci_xenon_set_uhs_timing),
721 static driver_t sdhci_xenon_driver = {
724 sizeof(struct sdhci_xenon_softc),
726 static devclass_t sdhci_xenon_devclass;
728 DRIVER_MODULE(sdhci_xenon, simplebus, sdhci_xenon_driver, sdhci_xenon_devclass,
731 SDHCI_DEPEND(sdhci_xenon);
733 MMC_DECLARE_BRIDGE(sdhci_xenon);