1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2021 Semihalf 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 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. 14 * 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. 25 */ 26 27 28 #include <sys/cdefs.h> 29 __FBSDID("$FreeBSD$"); 30 31 #include <sys/param.h> 32 #include <sys/bus.h> 33 #include <sys/kernel.h> 34 #include <sys/module.h> 35 #include <sys/taskqueue.h> 36 37 #include <dev/mmc/bridge.h> 38 #include <dev/mmc/mmcbrvar.h> 39 #include <dev/mmc/mmcreg.h> 40 41 #include <dev/mmc/mmc_helpers.h> 42 43 #include <contrib/dev/acpica/include/acpi.h> 44 #include <contrib/dev/acpica/include/accommon.h> 45 #include <dev/acpica/acpivar.h> 46 47 #include <dev/extres/regulator/regulator.h> 48 49 #include <dev/sdhci/sdhci.h> 50 #include <dev/sdhci/sdhci_xenon.h> 51 52 #include "mmcbr_if.h" 53 #include "sdhci_if.h" 54 55 #include "opt_mmccam.h" 56 #include "opt_soc.h" 57 58 static char *sdhci_xenon_hids[] = { 59 "MRVL0002", 60 "MRVL0003", 61 "MRVL0004", 62 NULL 63 }; 64 65 static int 66 sdhci_xenon_acpi_probe(device_t dev) 67 { 68 device_t bus; 69 int err; 70 71 bus = device_get_parent(dev); 72 73 err = ACPI_ID_PROBE(bus, dev, sdhci_xenon_hids, NULL); 74 if (err <= 0) { 75 device_set_desc(dev, "Armada Xenon SDHCI controller"); 76 return (err); 77 } 78 79 return (ENXIO); 80 } 81 82 static int 83 sdhci_xenon_acpi_attach(device_t dev) 84 { 85 struct sdhci_xenon_softc *sc; 86 struct sdhci_slot *slot; 87 struct mmc_helper mmc_helper; 88 89 sc = device_get_softc(dev); 90 memset(&mmc_helper, 0, sizeof(mmc_helper)); 91 92 slot = malloc(sizeof(*slot), M_DEVBUF, M_ZERO | M_WAITOK); 93 if (!slot) 94 return (ENOMEM); 95 96 /* 97 * Don't use regularators. 98 * In ACPI mode the firmware takes care of them for us 99 */ 100 sc->skip_regulators = true; 101 sc->slot = slot; 102 103 if (mmc_parse(dev, &mmc_helper, &slot->host) != 0) 104 return (ENXIO); 105 106 if (mmc_helper.props & MMC_PROP_NON_REMOVABLE) { 107 slot->opt |= SDHCI_NON_REMOVABLE; 108 if (bootverbose) 109 device_printf(dev, "Non-removable media\n"); 110 } 111 112 sc->wp_inverted = mmc_helper.props & MMC_PROP_WP_INVERTED; 113 114 return (sdhci_xenon_attach(dev)); 115 } 116 117 static device_method_t sdhci_xenon_acpi_methods[] = { 118 /* device_if */ 119 DEVMETHOD(device_probe, sdhci_xenon_acpi_probe), 120 DEVMETHOD(device_attach, sdhci_xenon_acpi_attach), 121 DEVMETHOD(device_detach, sdhci_xenon_detach), 122 123 DEVMETHOD(sdhci_get_card_present, sdhci_generic_get_card_present), 124 125 DEVMETHOD_END 126 }; 127 128 DEFINE_CLASS_1(sdhci_xenon, sdhci_xenon_acpi_driver, sdhci_xenon_acpi_methods, 129 sizeof(struct sdhci_xenon_softc), sdhci_xenon_driver); 130 131 DRIVER_MODULE(sdhci_xenon, acpi, sdhci_xenon_acpi_driver, NULL, NULL); 132 133 #ifndef MMCCAM 134 MMC_DECLARE_BRIDGE(sdhci_xenon_acpi); 135 #endif 136