2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2021 Semihalf
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
33 #include <sys/kernel.h>
34 #include <sys/types.h>
35 #include <sys/taskqueue.h>
36 #include <sys/module.h>
38 #include <machine/bus.h>
40 #include <dev/ofw/ofw_bus.h>
41 #include <dev/ofw/ofw_bus_subr.h>
43 #include <dev/mmc/bridge.h>
44 #include <dev/mmc/mmcbrvar.h>
45 #include <dev/mmc/mmcreg.h>
47 #include <dev/fdt/fdt_common.h>
48 #include <dev/mmc/mmc_fdt_helpers.h>
50 #include <dev/sdhci/sdhci.h>
51 #include <dev/sdhci/sdhci_fdt_gpio.h>
52 #include <dev/sdhci/sdhci_xenon.h>
57 #include "opt_mmccam.h"
60 static struct ofw_compat_data compat_data[] = {
61 { "marvell,armada-3700-sdhci", 1 },
63 { "marvell,armada-cp110-sdhci", 1 },
64 { "marvell,armada-ap806-sdhci", 1 },
65 { "marvell,armada-ap807-sdhci", 1 },
71 sdhci_xenon_fdt_get_card_present(device_t dev, struct sdhci_slot *slot)
73 struct sdhci_xenon_softc *sc;
75 sc = device_get_softc(dev);
77 return (sdhci_fdt_gpio_get_present(sc->gpio));
81 sdhci_xenon_fdt_probe(device_t dev)
83 if (!ofw_bus_status_okay(dev))
86 if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
89 device_set_desc(dev, "Armada Xenon SDHCI controller");
91 return (BUS_PROBE_SPECIFIC);
95 sdhci_xenon_fdt_parse(device_t dev, struct sdhci_slot *slot)
97 struct sdhci_xenon_softc *sc;
98 struct mmc_helper mmc_helper;
100 sc = device_get_softc(dev);
101 memset(&mmc_helper, 0, sizeof(mmc_helper));
103 /* MMC helper for parsing FDT */
104 mmc_fdt_parse(dev, 0, &mmc_helper, &slot->host);
106 sc->skip_regulators = false;
107 sc->vmmc_supply = mmc_helper.vmmc_supply;
108 sc->vqmmc_supply = mmc_helper.vqmmc_supply;
109 sc->wp_inverted = mmc_helper.props & MMC_PROP_WP_INVERTED;
111 /* Check if the device is flagged as non-removable. */
112 if (mmc_helper.props & MMC_PROP_NON_REMOVABLE) {
113 slot->opt |= SDHCI_NON_REMOVABLE;
115 device_printf(dev, "Non-removable media\n");
120 sdhci_xenon_fdt_attach(device_t dev)
122 struct sdhci_xenon_softc *sc;
123 struct sdhci_slot *slot;
125 sc = device_get_softc(dev);
126 slot = malloc(sizeof(*slot), M_DEVBUF, M_ZERO | M_WAITOK);
128 sdhci_xenon_fdt_parse(dev, slot);
131 * Set up any gpio pin handling described in the FDT data. This cannot
132 * fail; see comments in sdhci_fdt_gpio.h for details.
134 sc->gpio = sdhci_fdt_gpio_setup(dev, slot);
137 return (sdhci_xenon_attach(dev));
141 sdhci_xenon_fdt_detach(device_t dev)
143 struct sdhci_xenon_softc *sc;
145 sc = device_get_softc(dev);
146 if (sc->gpio != NULL)
147 sdhci_fdt_gpio_teardown(sc->gpio);
149 return (sdhci_xenon_detach(dev));
152 static device_method_t sdhci_xenon_fdt_methods[] = {
154 DEVMETHOD(device_probe, sdhci_xenon_fdt_probe),
155 DEVMETHOD(device_attach, sdhci_xenon_fdt_attach),
156 DEVMETHOD(device_detach, sdhci_xenon_fdt_detach),
158 DEVMETHOD(sdhci_get_card_present, sdhci_xenon_fdt_get_card_present),
163 DEFINE_CLASS_1(sdhci_xenon, sdhci_xenon_fdt_driver, sdhci_xenon_fdt_methods,
164 sizeof(struct sdhci_xenon_softc), sdhci_xenon_driver);
166 static devclass_t sdhci_xenon_fdt_devclass;
168 DRIVER_MODULE(sdhci_xenon, simplebus, sdhci_xenon_fdt_driver,
169 sdhci_xenon_fdt_devclass, NULL, NULL);
172 MMC_DECLARE_BRIDGE(sdhci_xenon_fdt);