xref: /openbsd/sys/arch/macppc/dev/aoa.c (revision cc5bdd41)
1 /*	$OpenBSD: aoa.c,v 1.16 2022/10/26 20:19:07 kn Exp $	*/
2 
3 /*-
4  * Copyright (c) 2005 Tsubai Masanari.  All rights reserved.
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  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /*
30  * WORK-IN-PROGRESS AOAKeylargo audio driver.
31  */
32 
33 #include <sys/param.h>
34 #include <sys/audioio.h>
35 #include <sys/device.h>
36 #include <sys/systm.h>
37 
38 #include <dev/audio_if.h>
39 #include <dev/ofw/openfirm.h>
40 #include <macppc/dev/dbdma.h>
41 
42 #include <machine/autoconf.h>
43 
44 #include <macppc/dev/i2svar.h>
45 
46 #ifdef AOA_DEBUG
47 # define DPRINTF printf
48 #else
49 # define DPRINTF while (0) printf
50 #endif
51 
52 /* XXX */
53 #define aoa_softc i2s_softc
54 
55 int aoa_match(struct device *, void *, void *);
56 void aoa_attach(struct device *, struct device *, void *);
57 void aoa_defer(struct device *);
58 void aoa_set_volume(struct aoa_softc *, int, int);
59 
60 const struct cfattach aoa_ca = {
61 	sizeof(struct aoa_softc), aoa_match, aoa_attach
62 };
63 
64 struct cfdriver aoa_cd = {
65 	NULL, "aoa", DV_DULL
66 };
67 
68 const struct audio_hw_if aoa_hw_if = {
69 	.open = i2s_open,
70 	.close = i2s_close,
71 	.set_params = i2s_set_params,
72 	.round_blocksize = i2s_round_blocksize,
73 	.halt_output = i2s_halt_output,
74 	.halt_input = i2s_halt_input,
75 	.set_port = i2s_set_port,
76 	.get_port = i2s_get_port,
77 	.query_devinfo = i2s_query_devinfo,
78 	.allocm = i2s_allocm,
79 	.round_buffersize = i2s_round_buffersize,
80 	.trigger_output = i2s_trigger_output,
81 	.trigger_input = i2s_trigger_input,
82 };
83 
84 int
aoa_match(struct device * parent,void * match,void * aux)85 aoa_match(struct device *parent, void *match, void *aux)
86 {
87 	struct confargs *ca = aux;
88 	int soundbus, soundchip;
89 	char compat[32];
90 
91 	if (strcmp(ca->ca_name, "i2s") != 0)
92 		return (0);
93 
94 	if ((soundbus = OF_child(ca->ca_node)) == 0 ||
95 	    (soundchip = OF_child(soundbus)) == 0)
96 		return (0);
97 
98 	bzero(compat, sizeof compat);
99 	OF_getprop(soundchip, "compatible", compat, sizeof compat);
100 
101 	if (strcmp(compat, "AOAKeylargo") == 0 &&
102 	    strcmp(hw_prod, "PowerBook5,4") != 0)
103 		return (1);
104 	if (strcmp(compat, "AOAK2") == 0)
105 		return (1);
106 	if (strcmp(compat, "AOAShasta") == 0)
107 		return (1);
108 
109 	return (0);
110 }
111 
112 void
aoa_attach(struct device * parent,struct device * self,void * aux)113 aoa_attach(struct device *parent, struct device *self, void *aux)
114 {
115 	struct aoa_softc *sc = (struct aoa_softc *)self;
116 
117 	sc->sc_setvolume = aoa_set_volume;
118 
119 	i2s_attach(parent, sc, aux);
120 	config_defer(self, aoa_defer);
121 }
122 
123 void
aoa_defer(struct device * dev)124 aoa_defer(struct device *dev)
125 {
126 	struct aoa_softc *sc = (struct aoa_softc *)dev;
127 
128 	audio_attach_mi(&aoa_hw_if, sc, NULL, &sc->sc_dev);
129 	deq_reset(sc);
130 }
131 
132 void
aoa_set_volume(struct aoa_softc * sc,int left,int right)133 aoa_set_volume(struct aoa_softc *sc, int left, int right)
134 {
135 	/* This device doesn't provide volume control. */
136 }
137