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 __FBSDID("$FreeBSD$"); 30 31 #include <sys/param.h> 32 #include <sys/systm.h> 33 #include <sys/bus.h> 34 #include <sys/kernel.h> 35 #include <sys/lock.h> 36 #include <sys/module.h> 37 #include <sys/mutex.h> 38 #include <sys/rman.h> 39 #include <sys/resource.h> 40 #include <machine/bus.h> 41 42 #include <dev/ofw/ofw_bus.h> 43 #include <dev/ofw/ofw_bus_subr.h> 44 45 #include "opt_snd.h" 46 #include <dev/sound/pcm/sound.h> 47 #include <dev/sound/fdt/audio_dai.h> 48 #include "audio_dai_if.h" 49 50 static struct ofw_compat_data compat_data[] = { 51 { "dummy-codec", 1}, 52 { NULL, 0 } 53 }; 54 55 struct dummy_codec_softc { 56 device_t dev; 57 }; 58 59 static int dummy_codec_probe(device_t dev); 60 static int dummy_codec_attach(device_t dev); 61 static int dummy_codec_detach(device_t dev); 62 63 static int 64 dummy_codec_probe(device_t dev) 65 { 66 if (!ofw_bus_status_okay(dev)) 67 return (ENXIO); 68 69 if (!ofw_bus_search_compatible(dev, compat_data)->ocd_data) 70 return (ENXIO); 71 72 device_set_desc(dev, "Dummy Codec"); 73 return (BUS_PROBE_DEFAULT); 74 } 75 76 static int 77 dummy_codec_attach(device_t dev) 78 { 79 struct dummy_codec_softc *sc; 80 phandle_t node; 81 82 sc = device_get_softc(dev); 83 sc->dev = dev; 84 85 node = ofw_bus_get_node(dev); 86 OF_device_register_xref(OF_xref_from_node(node), dev); 87 88 return (0); 89 } 90 91 static int 92 dummy_codec_detach(device_t dev) 93 { 94 95 return (0); 96 } 97 98 static int 99 dummy_codec_dai_init(device_t dev, uint32_t format) 100 { 101 102 return (0); 103 } 104 105 static device_method_t dummy_codec_methods[] = { 106 /* Device interface */ 107 DEVMETHOD(device_probe, dummy_codec_probe), 108 DEVMETHOD(device_attach, dummy_codec_attach), 109 DEVMETHOD(device_detach, dummy_codec_detach), 110 111 DEVMETHOD(audio_dai_init, dummy_codec_dai_init), 112 113 DEVMETHOD_END 114 }; 115 116 static driver_t dummy_codec_driver = { 117 "dummycodec", 118 dummy_codec_methods, 119 sizeof(struct dummy_codec_softc), 120 }; 121 122 DRIVER_MODULE(dummy_codec, simplebus, dummy_codec_driver, 0, 0); 123 SIMPLEBUS_PNP_INFO(compat_data); 124