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