1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2020 Oleksandr Tymoshenko <gonzo@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, 20 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28 #include <sys/cdefs.h> 29 #include <sys/param.h> 30 #include <sys/systm.h> 31 #include <sys/bus.h> 32 #include <sys/kernel.h> 33 #include <sys/lock.h> 34 #include <sys/module.h> 35 #include <sys/mutex.h> 36 #include <sys/rman.h> 37 #include <sys/resource.h> 38 #include <machine/bus.h> 39 40 #include <dev/ofw/ofw_bus.h> 41 #include <dev/ofw/ofw_bus_subr.h> 42 43 #include "opt_snd.h" 44 #include <dev/sound/pcm/sound.h> 45 #include <dev/sound/fdt/audio_dai.h> 46 #include "audio_dai_if.h" 47 48 static struct ofw_compat_data compat_data[] = { 49 { "dummy-codec", 1}, 50 { NULL, 0 } 51 }; 52 53 struct dummy_codec_softc { 54 device_t dev; 55 }; 56 57 static int dummy_codec_probe(device_t dev); 58 static int dummy_codec_attach(device_t dev); 59 static int dummy_codec_detach(device_t dev); 60 61 static int 62 dummy_codec_probe(device_t dev) 63 { 64 if (!ofw_bus_status_okay(dev)) 65 return (ENXIO); 66 67 if (!ofw_bus_search_compatible(dev, compat_data)->ocd_data) 68 return (ENXIO); 69 70 device_set_desc(dev, "Dummy Codec"); 71 return (BUS_PROBE_DEFAULT); 72 } 73 74 static int 75 dummy_codec_attach(device_t dev) 76 { 77 struct dummy_codec_softc *sc; 78 phandle_t node; 79 80 sc = device_get_softc(dev); 81 sc->dev = dev; 82 83 node = ofw_bus_get_node(dev); 84 OF_device_register_xref(OF_xref_from_node(node), dev); 85 86 return (0); 87 } 88 89 static int 90 dummy_codec_detach(device_t dev) 91 { 92 93 return (0); 94 } 95 96 static int 97 dummy_codec_dai_init(device_t dev, uint32_t format) 98 { 99 100 return (0); 101 } 102 103 static device_method_t dummy_codec_methods[] = { 104 /* Device interface */ 105 DEVMETHOD(device_probe, dummy_codec_probe), 106 DEVMETHOD(device_attach, dummy_codec_attach), 107 DEVMETHOD(device_detach, dummy_codec_detach), 108 109 DEVMETHOD(audio_dai_init, dummy_codec_dai_init), 110 111 DEVMETHOD_END 112 }; 113 114 static driver_t dummy_codec_driver = { 115 "dummycodec", 116 dummy_codec_methods, 117 sizeof(struct dummy_codec_softc), 118 }; 119 120 DRIVER_MODULE(dummy_codec, simplebus, dummy_codec_driver, 0, 0); 121 SIMPLEBUS_PNP_INFO(compat_data); 122