Say hello to a sound system update from FreeBSD. This includes the long
[dragonfly.git] / sys / dev / sound / pcm / fake.c
CommitLineData
558a398b
SS
1/*-
2 * Copyright (c) 1999 Cameron Grant <cg@freebsd.org>
984263bc
MD
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
1de703da 25 *
558a398b
SS
26 * $FreeBSD: src/sys/dev/sound/pcm/fake.c,v 1.14.2.1 2005/12/30 19:55:54 netchild Exp $
27 * $DragonFly: src/sys/dev/sound/pcm/fake.c,v 1.5 2007/01/04 21:47:03 corecode Exp $
984263bc
MD
28 */
29
30#include <dev/sound/pcm/sound.h>
31
984263bc
MD
32
33static u_int32_t fk_fmt[] = {
558a398b
SS
34 AFMT_MU_LAW,
35 AFMT_STEREO | AFMT_MU_LAW,
36 AFMT_A_LAW,
37 AFMT_STEREO | AFMT_A_LAW,
984263bc
MD
38 AFMT_U8,
39 AFMT_STEREO | AFMT_U8,
40 AFMT_S8,
41 AFMT_STEREO | AFMT_S8,
42 AFMT_S16_LE,
43 AFMT_STEREO | AFMT_S16_LE,
44 AFMT_U16_LE,
45 AFMT_STEREO | AFMT_U16_LE,
46 AFMT_S16_BE,
47 AFMT_STEREO | AFMT_S16_BE,
48 AFMT_U16_BE,
49 AFMT_STEREO | AFMT_U16_BE,
558a398b
SS
50 AFMT_S24_LE,
51 AFMT_STEREO | AFMT_S24_LE,
52 AFMT_U24_LE,
53 AFMT_STEREO | AFMT_U24_LE,
54 AFMT_S24_BE,
55 AFMT_STEREO | AFMT_S24_BE,
56 AFMT_U24_BE,
57 AFMT_STEREO | AFMT_U24_BE,
58 AFMT_S32_LE,
59 AFMT_STEREO | AFMT_S32_LE,
60 AFMT_U32_LE,
61 AFMT_STEREO | AFMT_U32_LE,
62 AFMT_S32_BE,
63 AFMT_STEREO | AFMT_S32_BE,
64 AFMT_U32_BE,
65 AFMT_STEREO | AFMT_U32_BE,
984263bc
MD
66 0
67};
68static struct pcmchan_caps fk_caps = {0, 1000000, fk_fmt, 0};
69
70#define FKBUFSZ 4096
71static char fakebuf[FKBUFSZ];
72
73/* channel interface */
74static void *
75fkchan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, struct pcm_channel *c, int dir)
76{
77 sndbuf_setup(b, fakebuf, FKBUFSZ);
78 return (void *)0xbabef00d;
79}
80
81static int
82fkchan_free(kobj_t obj, void *data)
83{
84 return 0;
85}
86
87static int
88fkchan_setformat(kobj_t obj, void *data, u_int32_t format)
89{
90 return 0;
91}
92
93static int
94fkchan_setspeed(kobj_t obj, void *data, u_int32_t speed)
95{
96 return speed;
97}
98
99static int
100fkchan_setblocksize(kobj_t obj, void *data, u_int32_t blocksize)
101{
102 return blocksize;
103}
104
105static int
106fkchan_trigger(kobj_t obj, void *data, int go)
107{
108 return 0;
109}
110
111static int
112fkchan_getptr(kobj_t obj, void *data)
113{
114 return 0;
115}
116
117static struct pcmchan_caps *
118fkchan_getcaps(kobj_t obj, void *data)
119{
120 return &fk_caps;
121}
122
123static kobj_method_t fkchan_methods[] = {
124 KOBJMETHOD(channel_init, fkchan_init),
125 KOBJMETHOD(channel_free, fkchan_free),
126 KOBJMETHOD(channel_setformat, fkchan_setformat),
127 KOBJMETHOD(channel_setspeed, fkchan_setspeed),
128 KOBJMETHOD(channel_setblocksize, fkchan_setblocksize),
129 KOBJMETHOD(channel_trigger, fkchan_trigger),
130 KOBJMETHOD(channel_getptr, fkchan_getptr),
131 KOBJMETHOD(channel_getcaps, fkchan_getcaps),
132 { 0, 0 }
133};
134CHANNEL_DECLARE(fkchan);
135
136struct pcm_channel *
137fkchan_setup(device_t dev)
138{
139 struct snddev_info *d = device_get_softc(dev);
140 struct pcm_channel *c;
141
efda3bd0 142 c = kmalloc(sizeof(*c), M_DEVBUF, M_WAITOK);
984263bc
MD
143 c->methods = kobj_create(&fkchan_class, M_DEVBUF, M_WAITOK);
144 c->parentsnddev = d;
558a398b
SS
145 /*
146 * Fake channel is such a blessing in disguise. Using this,
147 * we can keep track prefered virtual channel speed without
148 * querying kernel hint repetitively (see vchan_create / vchan.c).
149 */
150 c->speed = 0;
f8c7a42d 151 ksnprintf(c->name, CHN_NAMELEN, "%s:fake", device_get_nameunit(dev));
984263bc
MD
152
153 return c;
154}
155
156int
157fkchan_kill(struct pcm_channel *c)
158{
159 kobj_delete(c->methods, M_DEVBUF);
160 c->methods = NULL;
efda3bd0 161 kfree(c, M_DEVBUF);
984263bc
MD
162 return 0;
163}
164
165