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