1*cc5bdd41Skn /* $OpenBSD: aoa.c,v 1.16 2022/10/26 20:19:07 kn Exp $ */
2eeeca696Sjoris
3eeeca696Sjoris /*-
4eeeca696Sjoris * Copyright (c) 2005 Tsubai Masanari. All rights reserved.
5eeeca696Sjoris *
6eeeca696Sjoris * Redistribution and use in source and binary forms, with or without
7eeeca696Sjoris * modification, are permitted provided that the following conditions
8eeeca696Sjoris * are met:
9eeeca696Sjoris * 1. Redistributions of source code must retain the above copyright
10eeeca696Sjoris * notice, this list of conditions and the following disclaimer.
11eeeca696Sjoris * 2. Redistributions in binary form must reproduce the above copyright
12eeeca696Sjoris * notice, this list of conditions and the following disclaimer in the
13eeeca696Sjoris * documentation and/or other materials provided with the distribution.
14eeeca696Sjoris * 3. The name of the author may not be used to endorse or promote products
15eeeca696Sjoris * derived from this software without specific prior written permission.
16eeeca696Sjoris *
17eeeca696Sjoris * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18eeeca696Sjoris * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19eeeca696Sjoris * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20eeeca696Sjoris * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21eeeca696Sjoris * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22eeeca696Sjoris * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23eeeca696Sjoris * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24eeeca696Sjoris * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25eeeca696Sjoris * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26eeeca696Sjoris * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27eeeca696Sjoris */
28eeeca696Sjoris
29eeeca696Sjoris /*
30eeeca696Sjoris * WORK-IN-PROGRESS AOAKeylargo audio driver.
31eeeca696Sjoris */
32eeeca696Sjoris
33eeeca696Sjoris #include <sys/param.h>
34eeeca696Sjoris #include <sys/audioio.h>
35eeeca696Sjoris #include <sys/device.h>
36eeeca696Sjoris #include <sys/systm.h>
37eeeca696Sjoris
38eeeca696Sjoris #include <dev/audio_if.h>
39eeeca696Sjoris #include <dev/ofw/openfirm.h>
40ea884047Sbrad #include <macppc/dev/dbdma.h>
41eeeca696Sjoris
42eeeca696Sjoris #include <machine/autoconf.h>
43eeeca696Sjoris
44eeeca696Sjoris #include <macppc/dev/i2svar.h>
45eeeca696Sjoris
46eeeca696Sjoris #ifdef AOA_DEBUG
47eeeca696Sjoris # define DPRINTF printf
48eeeca696Sjoris #else
49eeeca696Sjoris # define DPRINTF while (0) printf
50eeeca696Sjoris #endif
51eeeca696Sjoris
52ea884047Sbrad /* XXX */
53ea884047Sbrad #define aoa_softc i2s_softc
54eeeca696Sjoris
55eeeca696Sjoris int aoa_match(struct device *, void *, void *);
56eeeca696Sjoris void aoa_attach(struct device *, struct device *, void *);
5720e972fcSmglocker void aoa_defer(struct device *);
58eeeca696Sjoris void aoa_set_volume(struct aoa_softc *, int, int);
59eeeca696Sjoris
6089ed722cSmpi const struct cfattach aoa_ca = {
61eeeca696Sjoris sizeof(struct aoa_softc), aoa_match, aoa_attach
62eeeca696Sjoris };
63eeeca696Sjoris
64eeeca696Sjoris struct cfdriver aoa_cd = {
65eeeca696Sjoris NULL, "aoa", DV_DULL
66eeeca696Sjoris };
67eeeca696Sjoris
680d6a2fdeSmiod const struct audio_hw_if aoa_hw_if = {
695a8d990aSkn .open = i2s_open,
705a8d990aSkn .close = i2s_close,
715a8d990aSkn .set_params = i2s_set_params,
725a8d990aSkn .round_blocksize = i2s_round_blocksize,
735a8d990aSkn .halt_output = i2s_halt_output,
745a8d990aSkn .halt_input = i2s_halt_input,
755a8d990aSkn .set_port = i2s_set_port,
765a8d990aSkn .get_port = i2s_get_port,
775a8d990aSkn .query_devinfo = i2s_query_devinfo,
785a8d990aSkn .allocm = i2s_allocm,
795a8d990aSkn .round_buffersize = i2s_round_buffersize,
805a8d990aSkn .trigger_output = i2s_trigger_output,
815a8d990aSkn .trigger_input = i2s_trigger_input,
82eeeca696Sjoris };
83eeeca696Sjoris
84eeeca696Sjoris int
aoa_match(struct device * parent,void * match,void * aux)85ea884047Sbrad aoa_match(struct device *parent, void *match, void *aux)
86eeeca696Sjoris {
87eeeca696Sjoris struct confargs *ca = aux;
88eeeca696Sjoris int soundbus, soundchip;
89eeeca696Sjoris char compat[32];
90eeeca696Sjoris
91eeeca696Sjoris if (strcmp(ca->ca_name, "i2s") != 0)
92ea884047Sbrad return (0);
93eeeca696Sjoris
94eeeca696Sjoris if ((soundbus = OF_child(ca->ca_node)) == 0 ||
95eeeca696Sjoris (soundchip = OF_child(soundbus)) == 0)
96ea884047Sbrad return (0);
97eeeca696Sjoris
98eeeca696Sjoris bzero(compat, sizeof compat);
99eeeca696Sjoris OF_getprop(soundchip, "compatible", compat, sizeof compat);
100eeeca696Sjoris
101ff2d06fbSgkoehler if (strcmp(compat, "AOAKeylargo") == 0 &&
102ff2d06fbSgkoehler strcmp(hw_prod, "PowerBook5,4") != 0)
103ea884047Sbrad return (1);
104eeeca696Sjoris if (strcmp(compat, "AOAK2") == 0)
105ea884047Sbrad return (1);
10620e972fcSmglocker if (strcmp(compat, "AOAShasta") == 0)
10720e972fcSmglocker return (1);
108eeeca696Sjoris
109ea884047Sbrad return (0);
110eeeca696Sjoris }
111eeeca696Sjoris
112eeeca696Sjoris void
aoa_attach(struct device * parent,struct device * self,void * aux)113ea884047Sbrad aoa_attach(struct device *parent, struct device *self, void *aux)
114eeeca696Sjoris {
115eeeca696Sjoris struct aoa_softc *sc = (struct aoa_softc *)self;
116eeeca696Sjoris
117eeeca696Sjoris sc->sc_setvolume = aoa_set_volume;
118eeeca696Sjoris
119eeeca696Sjoris i2s_attach(parent, sc, aux);
12020e972fcSmglocker config_defer(self, aoa_defer);
12120e972fcSmglocker }
12220e972fcSmglocker
12320e972fcSmglocker void
aoa_defer(struct device * dev)12420e972fcSmglocker aoa_defer(struct device *dev)
12520e972fcSmglocker {
12620e972fcSmglocker struct aoa_softc *sc = (struct aoa_softc *)dev;
12720e972fcSmglocker
1282baa08e2Santon audio_attach_mi(&aoa_hw_if, sc, NULL, &sc->sc_dev);
12920e972fcSmglocker deq_reset(sc);
130eeeca696Sjoris }
131eeeca696Sjoris
132eeeca696Sjoris void
aoa_set_volume(struct aoa_softc * sc,int left,int right)133ea884047Sbrad aoa_set_volume(struct aoa_softc *sc, int left, int right)
134eeeca696Sjoris {
1354f5469acSjasper /* This device doesn't provide volume control. */
136eeeca696Sjoris }
137