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