1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2023 Emmanuel Vadot <manu@freebsd.org> 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/systm.h> 29 #include <sys/bus.h> 30 #include <sys/kernel.h> 31 #include <sys/lock.h> 32 #include <sys/module.h> 33 #include <sys/mutex.h> 34 #include <sys/resource.h> 35 #include <sys/rman.h> 36 #include <sys/sysctl.h> 37 #include <sys/taskqueue.h> 38 39 #include <machine/bus.h> 40 #include <machine/resource.h> 41 42 #include <dev/fdt/fdt_common.h> 43 #include <dev/ofw/ofw_bus.h> 44 #include <dev/ofw/ofw_bus_subr.h> 45 46 #include <dev/ofw/ofw_subr.h> 47 #include <dev/clk/clk.h> 48 #include <dev/clk/clk_fixed.h> 49 #include <dev/ofw/openfirm.h> 50 #include <dev/syscon/syscon.h> 51 #include <dev/phy/phy.h> 52 53 #include <dev/mmc/bridge.h> 54 55 #include <dev/sdhci/sdhci.h> 56 #include <dev/sdhci/sdhci_fdt.h> 57 58 #include "mmcbr_if.h" 59 #include "sdhci_if.h" 60 61 #include "opt_mmccam.h" 62 63 #include "clkdev_if.h" 64 #include "syscon_if.h" 65 66 static int 67 sdhci_fdt_xilinx_probe(device_t dev) 68 { 69 struct sdhci_fdt_softc *sc = device_get_softc(dev); 70 71 if (!ofw_bus_is_compatible(dev, "xlnx,zynqmp-8.9a")) 72 return (ENXIO); 73 74 sc->quirks = 0; 75 device_set_desc(dev, "ZynqMP generic fdt SDHCI controller"); 76 77 return (0); 78 } 79 80 static int 81 sdhci_fdt_xilinx_attach(device_t dev) 82 { 83 struct sdhci_fdt_softc *sc = device_get_softc(dev); 84 int err; 85 86 err = sdhci_init_clocks(dev); 87 if (err != 0) { 88 device_printf(dev, "Cannot init clocks\n"); 89 return (err); 90 } 91 sdhci_export_clocks(sc); 92 if ((err = sdhci_init_phy(sc)) != 0) { 93 device_printf(dev, "Cannot init phy\n"); 94 return (err); 95 } 96 if ((err = sdhci_get_syscon(sc)) != 0) { 97 device_printf(dev, "Cannot get syscon handle\n"); 98 return (err); 99 } 100 101 return (sdhci_fdt_attach(dev)); 102 } 103 104 static device_method_t sdhci_fdt_xilinx_methods[] = { 105 /* device_if */ 106 DEVMETHOD(device_probe, sdhci_fdt_xilinx_probe), 107 DEVMETHOD(device_attach, sdhci_fdt_xilinx_attach), 108 109 DEVMETHOD_END 110 }; 111 extern driver_t sdhci_fdt_driver; 112 113 DEFINE_CLASS_1(sdhci_xilinx, sdhci_fdt_xilinx_driver, sdhci_fdt_xilinx_methods, 114 sizeof(struct sdhci_fdt_softc), sdhci_fdt_driver); 115 DRIVER_MODULE(sdhci_xilinx, simplebus, sdhci_fdt_xilinx_driver, NULL, NULL); 116