1*cc5bdd41Skn /* $OpenBSD: snapper.c,v 1.44 2022/10/26 20:19:07 kn Exp $ */
23b608985Sdrahn /* $NetBSD: snapper.c,v 1.1 2003/12/27 02:19:34 grant Exp $ */
33b608985Sdrahn
43b608985Sdrahn /*-
53b608985Sdrahn * Copyright (c) 2002 Tsubai Masanari. All rights reserved.
63b608985Sdrahn *
73b608985Sdrahn * Redistribution and use in source and binary forms, with or without
83b608985Sdrahn * modification, are permitted provided that the following conditions
93b608985Sdrahn * are met:
103b608985Sdrahn * 1. Redistributions of source code must retain the above copyright
113b608985Sdrahn * notice, this list of conditions and the following disclaimer.
123b608985Sdrahn * 2. Redistributions in binary form must reproduce the above copyright
133b608985Sdrahn * notice, this list of conditions and the following disclaimer in the
143b608985Sdrahn * documentation and/or other materials provided with the distribution.
153b608985Sdrahn * 3. The name of the author may not be used to endorse or promote products
163b608985Sdrahn * derived from this software without specific prior written permission.
173b608985Sdrahn *
183b608985Sdrahn * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
193b608985Sdrahn * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
203b608985Sdrahn * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
213b608985Sdrahn * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
223b608985Sdrahn * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
233b608985Sdrahn * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
243b608985Sdrahn * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
253b608985Sdrahn * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
263b608985Sdrahn * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
273b608985Sdrahn * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
283b608985Sdrahn */
293b608985Sdrahn
303b608985Sdrahn /*
313b608985Sdrahn * Datasheet is available from
32d12b3179Sbrad * http://focus.ti.com/docs/prod/folders/print/tas3004.html
333b608985Sdrahn */
343b608985Sdrahn
353b608985Sdrahn #include <sys/param.h>
363b608985Sdrahn #include <sys/audioio.h>
373b608985Sdrahn #include <sys/device.h>
383b608985Sdrahn #include <sys/systm.h>
393b608985Sdrahn
403b608985Sdrahn #include <dev/audio_if.h>
413b608985Sdrahn #include <dev/ofw/openfirm.h>
423b608985Sdrahn #include <macppc/dev/dbdma.h>
433b608985Sdrahn
443b608985Sdrahn #include <machine/autoconf.h>
453b608985Sdrahn
46da53b1f9Sjoris #include <macppc/dev/i2svar.h>
47da53b1f9Sjoris
483b608985Sdrahn #ifdef SNAPPER_DEBUG
49ea884047Sbrad # define DPRINTF printf
503b608985Sdrahn #else
51ea884047Sbrad # define DPRINTF while (0) printf
523b608985Sdrahn #endif
533b608985Sdrahn
54da53b1f9Sjoris /* XXX */
55da53b1f9Sjoris #define snapper_softc i2s_softc
563b608985Sdrahn
57da53b1f9Sjoris /* XXX */
58715b6a7bSderaadt int kiic_write(struct device *, int, int, const void *, int);
59715b6a7bSderaadt int kiic_writereg(struct device *, int, u_int);
603b608985Sdrahn
61f3538de4Sjoris void snapper_init(struct snapper_softc *);
623b608985Sdrahn int snapper_match(struct device *, void *, void *);
633b608985Sdrahn void snapper_attach(struct device *, struct device *, void *);
643b608985Sdrahn void snapper_defer(struct device *);
653b608985Sdrahn void snapper_set_volume(struct snapper_softc *, int, int);
66ddfa3b0dSjoris void snapper_set_bass(struct snapper_softc *, int);
67ddfa3b0dSjoris void snapper_set_treble(struct snapper_softc *, int);
68f0d5bc97Stodd void snapper_set_input(struct snapper_softc *, int);
693b608985Sdrahn
703b608985Sdrahn int tas3004_write(struct snapper_softc *, u_int, const void *);
713b608985Sdrahn int tas3004_init(struct snapper_softc *);
723b608985Sdrahn
7389ed722cSmpi const struct cfattach snapper_ca = {
743b608985Sdrahn sizeof(struct snapper_softc), snapper_match, snapper_attach
753b608985Sdrahn };
763b608985Sdrahn struct cfdriver snapper_cd = {
773b608985Sdrahn NULL, "snapper", DV_DULL
783b608985Sdrahn };
793b608985Sdrahn
800d6a2fdeSmiod const struct audio_hw_if snapper_hw_if = {
815a8d990aSkn .open = i2s_open,
825a8d990aSkn .close = i2s_close,
835a8d990aSkn .set_params = i2s_set_params,
845a8d990aSkn .round_blocksize = i2s_round_blocksize,
855a8d990aSkn .halt_output = i2s_halt_output,
865a8d990aSkn .halt_input = i2s_halt_input,
875a8d990aSkn .set_port = i2s_set_port,
885a8d990aSkn .get_port = i2s_get_port,
895a8d990aSkn .query_devinfo = i2s_query_devinfo,
905a8d990aSkn .allocm = i2s_allocm,
915a8d990aSkn .round_buffersize = i2s_round_buffersize,
925a8d990aSkn .trigger_output = i2s_trigger_output,
935a8d990aSkn .trigger_input = i2s_trigger_input,
943b608985Sdrahn };
953b608985Sdrahn
96ddfa3b0dSjoris const uint8_t snapper_trebletab[] = {
97ddfa3b0dSjoris 0x96, /* -18dB */
98ddfa3b0dSjoris 0x94, /* -17dB */
99ddfa3b0dSjoris 0x92, /* -16dB */
100ddfa3b0dSjoris 0x90, /* -15dB */
101ddfa3b0dSjoris 0x8e, /* -14dB */
102ddfa3b0dSjoris 0x8c, /* -13dB */
103ddfa3b0dSjoris 0x8a, /* -12dB */
104ddfa3b0dSjoris 0x88, /* -11dB */
105ddfa3b0dSjoris 0x86, /* -10dB */
106ddfa3b0dSjoris 0x84, /* -9dB */
107ddfa3b0dSjoris 0x82, /* -8dB */
108ddfa3b0dSjoris 0x80, /* -7dB */
109ddfa3b0dSjoris 0x7e, /* -6dB */
110ddfa3b0dSjoris 0x7c, /* -5dB */
111ddfa3b0dSjoris 0x7a, /* -4dB */
112ddfa3b0dSjoris 0x78, /* -3dB */
113ddfa3b0dSjoris 0x76, /* -2dB */
114ddfa3b0dSjoris 0x74, /* -1dB */
115ddfa3b0dSjoris 0x72, /* 0dB */
116ddfa3b0dSjoris 0x70, /* 1dB */
117ddfa3b0dSjoris 0x6d, /* 2dB */
118ddfa3b0dSjoris 0x6b, /* 3dB */
119ddfa3b0dSjoris 0x68, /* 4dB */
120ddfa3b0dSjoris 0x65, /* 5dB */
121ddfa3b0dSjoris 0x62, /* 6dB */
122ddfa3b0dSjoris 0x5d, /* 7dB */
123ddfa3b0dSjoris 0x59, /* 8dB */
124ddfa3b0dSjoris 0x53, /* 9dB */
125ddfa3b0dSjoris 0x4d, /* 10dB */
126ddfa3b0dSjoris 0x47, /* 11dB */
127ddfa3b0dSjoris 0x3f, /* 12dB */
128ddfa3b0dSjoris 0x36, /* 13dB */
129ddfa3b0dSjoris 0x2c, /* 14dB */
130ddfa3b0dSjoris 0x20, /* 15dB */
131ddfa3b0dSjoris 0x13, /* 16dB */
132ddfa3b0dSjoris 0x04, /* 17dB */
133ddfa3b0dSjoris 0x01, /* 18dB */
134ddfa3b0dSjoris };
135ddfa3b0dSjoris
136ddfa3b0dSjoris const uint8_t snapper_basstab[] = {
137ddfa3b0dSjoris 0x96, /* -18dB */
138ddfa3b0dSjoris 0x94, /* -17dB */
139ddfa3b0dSjoris 0x92, /* -16dB */
140ddfa3b0dSjoris 0x90, /* -15dB */
141ddfa3b0dSjoris 0x8e, /* -14dB */
142ddfa3b0dSjoris 0x8c, /* -13dB */
143ddfa3b0dSjoris 0x8a, /* -12dB */
144ddfa3b0dSjoris 0x88, /* -11dB */
145ddfa3b0dSjoris 0x86, /* -10dB */
146ddfa3b0dSjoris 0x84, /* -9dB */
147ddfa3b0dSjoris 0x82, /* -8dB */
148ddfa3b0dSjoris 0x80, /* -7dB */
149ddfa3b0dSjoris 0x7e, /* -6dB */
150ddfa3b0dSjoris 0x7c, /* -5dB */
151ddfa3b0dSjoris 0x7a, /* -4dB */
152ddfa3b0dSjoris 0x78, /* -3dB */
153ddfa3b0dSjoris 0x76, /* -2dB */
154ddfa3b0dSjoris 0x74, /* -1dB */
155ddfa3b0dSjoris 0x72, /* 0dB */
156ddfa3b0dSjoris 0x6f, /* 1dB */
157ddfa3b0dSjoris 0x6d, /* 2dB */
158ddfa3b0dSjoris 0x6a, /* 3dB */
159ddfa3b0dSjoris 0x67, /* 4dB */
160ddfa3b0dSjoris 0x65, /* 5dB */
161ddfa3b0dSjoris 0x62, /* 6dB */
162ddfa3b0dSjoris 0x5f, /* 7dB */
163ddfa3b0dSjoris 0x5b, /* 8dB */
164ddfa3b0dSjoris 0x55, /* 9dB */
165ddfa3b0dSjoris 0x4f, /* 10dB */
166ddfa3b0dSjoris 0x49, /* 11dB */
167ddfa3b0dSjoris 0x43, /* 12dB */
168ddfa3b0dSjoris 0x3b, /* 13dB */
169ddfa3b0dSjoris 0x33, /* 14dB */
170ddfa3b0dSjoris 0x29, /* 15dB */
171ddfa3b0dSjoris 0x1e, /* 16dB */
172ddfa3b0dSjoris 0x11, /* 17dB */
173ddfa3b0dSjoris 0x01, /* 18dB */
174ddfa3b0dSjoris };
175ddfa3b0dSjoris
176f0d5bc97Stodd struct {
177f0d5bc97Stodd int high, mid, low;
178f0d5bc97Stodd } snapper_volumetab[] = {
179f0d5bc97Stodd { 0x07, 0xF1, 0x7B }, /* 18.0 */
180237b6a0cStodd { 0x07, 0x7F, 0xBB }, /* 17.5 */
181f0d5bc97Stodd { 0x07, 0x14, 0x57 }, /* 17.0 */
182f0d5bc97Stodd { 0x06, 0xAE, 0xF6 }, /* 16.5 */
183f0d5bc97Stodd { 0x06, 0x4F, 0x40 }, /* 16.0 */
184f0d5bc97Stodd { 0x05, 0xF4, 0xE5 }, /* 15.5 */
185f0d5bc97Stodd { 0x05, 0x9F, 0x98 }, /* 15.0 */
186f0d5bc97Stodd { 0x05, 0x4F, 0x10 }, /* 14.5 */
187f0d5bc97Stodd { 0x05, 0x03, 0x0A }, /* 14.0 */
188f0d5bc97Stodd { 0x04, 0xBB, 0x44 }, /* 13.5 */
189f0d5bc97Stodd { 0x04, 0x77, 0x83 }, /* 13.0 */
190f0d5bc97Stodd { 0x04, 0x37, 0x8B }, /* 12.5 */
191f0d5bc97Stodd { 0x03, 0xFB, 0x28 }, /* 12.0 */
192f0d5bc97Stodd { 0x03, 0xC2, 0x25 }, /* 11.5 */
193f0d5bc97Stodd { 0x03, 0x8C, 0x53 }, /* 11.0 */
194f0d5bc97Stodd { 0x03, 0x59, 0x83 }, /* 10.5 */
195f0d5bc97Stodd { 0x03, 0x29, 0x8B }, /* 10.0 */
196f0d5bc97Stodd { 0x02, 0xFC, 0x42 }, /* 9.5 */
197f0d5bc97Stodd { 0x02, 0xD1, 0x82 }, /* 9.0 */
198f0d5bc97Stodd { 0x02, 0xA9, 0x25 }, /* 8.5 */
199f0d5bc97Stodd { 0x02, 0x83, 0x0B }, /* 8.0 */
200f0d5bc97Stodd { 0x02, 0x5F, 0x12 }, /* 7.5 */
201f0d5bc97Stodd { 0x02, 0x3D, 0x1D }, /* 7.0 */
202f0d5bc97Stodd { 0x02, 0x1D, 0x0E }, /* 6.5 */
203f0d5bc97Stodd { 0x01, 0xFE, 0xCA }, /* 6.0 */
204f0d5bc97Stodd { 0x01, 0xE2, 0x37 }, /* 5.5 */
205f0d5bc97Stodd { 0x01, 0xC7, 0x3D }, /* 5.0 */
206f0d5bc97Stodd { 0x01, 0xAD, 0xC6 }, /* 4.5 */
207f0d5bc97Stodd { 0x01, 0x95, 0xBC }, /* 4.0 */
208f0d5bc97Stodd { 0x01, 0x7F, 0x09 }, /* 3.5 */
209f0d5bc97Stodd { 0x01, 0x69, 0x9C }, /* 3.0 */
210f0d5bc97Stodd { 0x01, 0x55, 0x62 }, /* 2.5 */
211f0d5bc97Stodd { 0x01, 0x42, 0x49 }, /* 2.0 */
212f0d5bc97Stodd { 0x01, 0x30, 0x42 }, /* 1.5 */
213f0d5bc97Stodd { 0x01, 0x1F, 0x3D }, /* 1.0 */
214f0d5bc97Stodd { 0x01, 0x0F, 0x2B }, /* 0.5 */
215f0d5bc97Stodd { 0x01, 0x00, 0x00 }, /* 0.0 */
216f0d5bc97Stodd { 0x00, 0xF1, 0xAE }, /* -0.5 */
217f0d5bc97Stodd { 0x00, 0xE4, 0x29 }, /* -1.0 */
218f0d5bc97Stodd { 0x00, 0xD7, 0x66 }, /* -1.5 */
219f0d5bc97Stodd { 0x00, 0xCB, 0x59 }, /* -2.0 */
220f0d5bc97Stodd { 0x00, 0xBF, 0xF9 }, /* -2.5 */
221f0d5bc97Stodd { 0x00, 0xB5, 0x3C }, /* -3.0 */
222f0d5bc97Stodd { 0x00, 0xAB, 0x19 }, /* -3.5 */
223f0d5bc97Stodd { 0x00, 0xA1, 0x86 }, /* -4.0 */
224f0d5bc97Stodd { 0x00, 0x98, 0x7D }, /* -4.5 */
225f0d5bc97Stodd { 0x00, 0x8F, 0xF6 }, /* -5.0 */
226f0d5bc97Stodd { 0x00, 0x87, 0xE8 }, /* -5.5 */
227f0d5bc97Stodd { 0x00, 0x80, 0x4E }, /* -6.0 */
228f0d5bc97Stodd { 0x00, 0x79, 0x20 }, /* -6.5 */
229f0d5bc97Stodd { 0x00, 0x72, 0x5A }, /* -7.0 */
230f0d5bc97Stodd { 0x00, 0x6B, 0xF4 }, /* -7.5 */
231f0d5bc97Stodd { 0x00, 0x65, 0xEA }, /* -8.0 */
232f0d5bc97Stodd { 0x00, 0x60, 0x37 }, /* -8.5 */
233f0d5bc97Stodd { 0x00, 0x5A, 0xD5 }, /* -9.0 */
234f0d5bc97Stodd { 0x00, 0x55, 0xC0 }, /* -9.5 */
235f0d5bc97Stodd { 0x00, 0x50, 0xF4 }, /* -10.0 */
236f0d5bc97Stodd { 0x00, 0x4C, 0x6D }, /* -10.5 */
237f0d5bc97Stodd { 0x00, 0x48, 0x27 }, /* -11.0 */
238f0d5bc97Stodd { 0x00, 0x44, 0x1D }, /* -11.5 */
239f0d5bc97Stodd { 0x00, 0x40, 0x4E }, /* -12.0 */
240f0d5bc97Stodd { 0x00, 0x3C, 0xB5 }, /* -12.5 */
241f0d5bc97Stodd { 0x00, 0x39, 0x50 }, /* -13.0 */
242f0d5bc97Stodd { 0x00, 0x36, 0x1B }, /* -13.5 */
243f0d5bc97Stodd { 0x00, 0x33, 0x14 }, /* -14.0 */
244f0d5bc97Stodd { 0x00, 0x30, 0x39 }, /* -14.5 */
245f0d5bc97Stodd { 0x00, 0x2D, 0x86 }, /* -15.0 */
246f0d5bc97Stodd { 0x00, 0x2A, 0xFA }, /* -15.5 */
247f0d5bc97Stodd { 0x00, 0x28, 0x93 }, /* -16.0 */
248f0d5bc97Stodd { 0x00, 0x26, 0x4E }, /* -16.5 */
249f0d5bc97Stodd { 0x00, 0x24, 0x29 }, /* -17.0 */
250f0d5bc97Stodd { 0x00, 0x22, 0x23 }, /* -17.5 */
251f0d5bc97Stodd { 0x00, 0x20, 0x3A }, /* -18.0 */
252f0d5bc97Stodd { 0x00, 0x1E, 0x6D }, /* -18.5 */
253f0d5bc97Stodd { 0x00, 0x1C, 0xB9 }, /* -19.0 */
254f0d5bc97Stodd { 0x00, 0x1B, 0x1E }, /* -19.5 */
255f0d5bc97Stodd { 0x00, 0x19, 0x9A }, /* -20.0 */
256f0d5bc97Stodd { 0x00, 0x18, 0x2B }, /* -20.5 */
257f0d5bc97Stodd { 0x00, 0x16, 0xD1 }, /* -21.0 */
258f0d5bc97Stodd { 0x00, 0x15, 0x8A }, /* -21.5 */
259f0d5bc97Stodd { 0x00, 0x14, 0x56 }, /* -22.0 */
260f0d5bc97Stodd { 0x00, 0x13, 0x33 }, /* -22.5 */
261f0d5bc97Stodd { 0x00, 0x12, 0x20 }, /* -23.0 */
262f0d5bc97Stodd { 0x00, 0x11, 0x1C }, /* -23.5 */
263f0d5bc97Stodd { 0x00, 0x10, 0x27 }, /* -24.0 */
264f0d5bc97Stodd { 0x00, 0x0F, 0x40 }, /* -24.5 */
265f0d5bc97Stodd { 0x00, 0x0E, 0x65 }, /* -25.0 */
266f0d5bc97Stodd { 0x00, 0x0D, 0x97 }, /* -25.5 */
267f0d5bc97Stodd { 0x00, 0x0C, 0xD5 }, /* -26.0 */
268f0d5bc97Stodd { 0x00, 0x0C, 0x1D }, /* -26.5 */
269f0d5bc97Stodd { 0x00, 0x0B, 0x6F }, /* -27.0 */
270f0d5bc97Stodd { 0x00, 0x0A, 0xCC }, /* -27.5 */
271f0d5bc97Stodd { 0x00, 0x0A, 0x31 }, /* -28.0 */
272f0d5bc97Stodd { 0x00, 0x09, 0x9F }, /* -28.5 */
273f0d5bc97Stodd { 0x00, 0x09, 0x15 }, /* -29.0 */
274f0d5bc97Stodd { 0x00, 0x08, 0x93 }, /* -29.5 */
275f0d5bc97Stodd { 0x00, 0x08, 0x18 }, /* -30.0 */
276f0d5bc97Stodd { 0x00, 0x07, 0xA5 }, /* -30.5 */
277f0d5bc97Stodd { 0x00, 0x07, 0x37 }, /* -31.0 */
278f0d5bc97Stodd { 0x00, 0x06, 0xD0 }, /* -31.5 */
279f0d5bc97Stodd { 0x00, 0x06, 0x6E }, /* -32.0 */
280f0d5bc97Stodd { 0x00, 0x06, 0x12 }, /* -32.5 */
281f0d5bc97Stodd { 0x00, 0x05, 0xBB }, /* -33.0 */
282f0d5bc97Stodd { 0x00, 0x05, 0x69 }, /* -33.5 */
283f0d5bc97Stodd { 0x00, 0x05, 0x1C }, /* -34.0 */
284f0d5bc97Stodd { 0x00, 0x04, 0xD2 }, /* -34.5 */
285f0d5bc97Stodd { 0x00, 0x04, 0x8D }, /* -35.0 */
286f0d5bc97Stodd { 0x00, 0x04, 0x4C }, /* -35.5 */
287f0d5bc97Stodd { 0x00, 0x04, 0x0F }, /* -36.0 */
288f0d5bc97Stodd { 0x00, 0x03, 0xD5 }, /* -36.5 */
289f0d5bc97Stodd { 0x00, 0x03, 0x9E }, /* -37.0 */
290f0d5bc97Stodd { 0x00, 0x03, 0x6A }, /* -37.5 */
291f0d5bc97Stodd { 0x00, 0x03, 0x39 }, /* -38.0 */
292f0d5bc97Stodd { 0x00, 0x03, 0x0B }, /* -38.5 */
293f0d5bc97Stodd { 0x00, 0x02, 0xDF }, /* -39.0 */
294f0d5bc97Stodd { 0x00, 0x02, 0xB6 }, /* -39.5 */
295f0d5bc97Stodd { 0x00, 0x02, 0x8F }, /* -40.0 */
296f0d5bc97Stodd { 0x00, 0x02, 0x6B }, /* -40.5 */
297f0d5bc97Stodd { 0x00, 0x02, 0x48 }, /* -41.0 */
298f0d5bc97Stodd { 0x00, 0x02, 0x27 }, /* -41.5 */
299f0d5bc97Stodd { 0x00, 0x02, 0x09 }, /* -42.0 */
300f0d5bc97Stodd { 0x00, 0x01, 0xEB }, /* -42.5 */
301f0d5bc97Stodd { 0x00, 0x01, 0xD0 }, /* -43.0 */
302f0d5bc97Stodd { 0x00, 0x01, 0xB6 }, /* -43.5 */
303f0d5bc97Stodd { 0x00, 0x01, 0x9E }, /* -44.0 */
304f0d5bc97Stodd { 0x00, 0x01, 0x86 }, /* -44.5 */
305f0d5bc97Stodd { 0x00, 0x01, 0x71 }, /* -45.0 */
306f0d5bc97Stodd { 0x00, 0x01, 0x5C }, /* -45.5 */
307f0d5bc97Stodd { 0x00, 0x01, 0x48 }, /* -46.0 */
308f0d5bc97Stodd { 0x00, 0x01, 0x36 }, /* -46.5 */
309f0d5bc97Stodd { 0x00, 0x01, 0x25 }, /* -47.0 */
310f0d5bc97Stodd { 0x00, 0x01, 0x14 }, /* -47.5 */
311f0d5bc97Stodd { 0x00, 0x01, 0x05 }, /* -48.0 */
312f0d5bc97Stodd { 0x00, 0x00, 0xF6 }, /* -48.5 */
313f0d5bc97Stodd { 0x00, 0x00, 0xE9 }, /* -49.0 */
314f0d5bc97Stodd { 0x00, 0x00, 0xDC }, /* -49.5 */
315f0d5bc97Stodd { 0x00, 0x00, 0xCF }, /* -50.0 */
316f0d5bc97Stodd { 0x00, 0x00, 0xC4 }, /* -50.5 */
317f0d5bc97Stodd { 0x00, 0x00, 0xB9 }, /* -51.0 */
318f0d5bc97Stodd { 0x00, 0x00, 0xAE }, /* -51.5 */
319f0d5bc97Stodd { 0x00, 0x00, 0xA5 }, /* -52.0 */
320f0d5bc97Stodd { 0x00, 0x00, 0x9B }, /* -52.5 */
321f0d5bc97Stodd { 0x00, 0x00, 0x93 }, /* -53.0 */
322f0d5bc97Stodd { 0x00, 0x00, 0x8B }, /* -53.5 */
323f0d5bc97Stodd { 0x00, 0x00, 0x83 }, /* -54.0 */
324f0d5bc97Stodd { 0x00, 0x00, 0x7B }, /* -54.5 */
325f0d5bc97Stodd { 0x00, 0x00, 0x75 }, /* -55.0 */
326f0d5bc97Stodd { 0x00, 0x00, 0x6E }, /* -55.5 */
327f0d5bc97Stodd { 0x00, 0x00, 0x68 }, /* -56.0 */
328f0d5bc97Stodd { 0x00, 0x00, 0x62 }, /* -56.5 */
329f0d5bc97Stodd { 0x00, 0x00, 0x0 } /* Mute? */
330f0d5bc97Stodd
331f0d5bc97Stodd };
332f0d5bc97Stodd
3333b608985Sdrahn /* TAS3004 registers */
3343b608985Sdrahn #define DEQ_MCR1 0x01 /* Main control register 1 (1byte) */
3353b608985Sdrahn #define DEQ_DRC 0x02 /* Dynamic range compression (6bytes?) */
3363b608985Sdrahn #define DEQ_VOLUME 0x04 /* Volume (6bytes) */
3373b608985Sdrahn #define DEQ_TREBLE 0x05 /* Treble control (1byte) */
3383b608985Sdrahn #define DEQ_BASS 0x06 /* Bass control (1byte) */
3393b608985Sdrahn #define DEQ_MIXER_L 0x07 /* Mixer left gain (9bytes) */
3403b608985Sdrahn #define DEQ_MIXER_R 0x08 /* Mixer right gain (9bytes) */
3413b608985Sdrahn #define DEQ_LB0 0x0a /* Left biquad 0 (15bytes) */
3423b608985Sdrahn #define DEQ_LB1 0x0b /* Left biquad 1 (15bytes) */
3433b608985Sdrahn #define DEQ_LB2 0x0c /* Left biquad 2 (15bytes) */
3443b608985Sdrahn #define DEQ_LB3 0x0d /* Left biquad 3 (15bytes) */
3453b608985Sdrahn #define DEQ_LB4 0x0e /* Left biquad 4 (15bytes) */
3463b608985Sdrahn #define DEQ_LB5 0x0f /* Left biquad 5 (15bytes) */
3473b608985Sdrahn #define DEQ_LB6 0x10 /* Left biquad 6 (15bytes) */
3483b608985Sdrahn #define DEQ_RB0 0x13 /* Right biquad 0 (15bytes) */
3493b608985Sdrahn #define DEQ_RB1 0x14 /* Right biquad 1 (15bytes) */
3503b608985Sdrahn #define DEQ_RB2 0x15 /* Right biquad 2 (15bytes) */
3513b608985Sdrahn #define DEQ_RB3 0x16 /* Right biquad 3 (15bytes) */
3523b608985Sdrahn #define DEQ_RB4 0x17 /* Right biquad 4 (15bytes) */
3533b608985Sdrahn #define DEQ_RB5 0x18 /* Right biquad 5 (15bytes) */
3543b608985Sdrahn #define DEQ_RB6 0x19 /* Right biquad 6 (15bytes) */
3553b608985Sdrahn #define DEQ_LLB 0x21 /* Left loudness biquad (15bytes) */
3563b608985Sdrahn #define DEQ_RLB 0x22 /* Right loudness biquad (15bytes) */
3573b608985Sdrahn #define DEQ_LLB_GAIN 0x23 /* Left loudness biquad gain (3bytes) */
3583b608985Sdrahn #define DEQ_RLB_GAIN 0x24 /* Right loudness biquad gain (3bytes) */
3593b608985Sdrahn #define DEQ_ACR 0x40 /* Analog control register (1byte) */
3603b608985Sdrahn #define DEQ_MCR2 0x43 /* Main control register 2 (1byte) */
3613b608985Sdrahn
3623b608985Sdrahn #define DEQ_MCR1_FL 0x80 /* Fast load */
3633b608985Sdrahn #define DEQ_MCR1_SC 0x40 /* SCLK frequency */
3643b608985Sdrahn #define DEQ_MCR1_SC_32 0x00 /* 32fs */
3653b608985Sdrahn #define DEQ_MCR1_SC_64 0x40 /* 64fs */
3663b608985Sdrahn #define DEQ_MCR1_SM 0x30 /* Output serial port mode */
3673b608985Sdrahn #define DEQ_MCR1_SM_L 0x00 /* Left justified */
3683b608985Sdrahn #define DEQ_MCR1_SM_R 0x10 /* Right justified */
3693b608985Sdrahn #define DEQ_MCR1_SM_I2S 0x20 /* I2S */
3703b608985Sdrahn #define DEQ_MCR1_W 0x03 /* Serial port word length */
3713b608985Sdrahn #define DEQ_MCR1_W_16 0x00 /* 16 bit */
3723b608985Sdrahn #define DEQ_MCR1_W_18 0x01 /* 18 bit */
3733b608985Sdrahn #define DEQ_MCR1_W_20 0x02 /* 20 bit */
3743b608985Sdrahn
3753b608985Sdrahn #define DEQ_MCR2_DL 0x80 /* Download */
3763b608985Sdrahn #define DEQ_MCR2_AP 0x02 /* All pass mode */
3773b608985Sdrahn
3783b608985Sdrahn #define DEQ_ACR_ADM 0x80 /* ADC output mode */
3793b608985Sdrahn #define DEQ_ACR_LRB 0x40 /* Select B input */
3803b608985Sdrahn #define DEQ_ACR_DM 0x0c /* De-emphasis control */
3813b608985Sdrahn #define DEQ_ACR_DM_OFF 0x00 /* off */
3823b608985Sdrahn #define DEQ_ACR_DM_48 0x04 /* fs = 48kHz */
3833b608985Sdrahn #define DEQ_ACR_DM_44 0x08 /* fs = 44.1kHz */
3843b608985Sdrahn #define DEQ_ACR_INP 0x02 /* Analog input select */
3853b608985Sdrahn #define DEQ_ACR_INP_A 0x00 /* A */
3863b608985Sdrahn #define DEQ_ACR_INP_B 0x02 /* B */
3873b608985Sdrahn #define DEQ_ACR_APD 0x01 /* Analog power down */
3883b608985Sdrahn
3893b608985Sdrahn struct tas3004_reg {
3903b608985Sdrahn u_char MCR1[1];
3913b608985Sdrahn u_char DRC[6];
3923b608985Sdrahn u_char VOLUME[6];
3933b608985Sdrahn u_char TREBLE[1];
3943b608985Sdrahn u_char BASS[1];
3953b608985Sdrahn u_char MIXER_L[9];
3963b608985Sdrahn u_char MIXER_R[9];
3973b608985Sdrahn u_char LB0[15];
3983b608985Sdrahn u_char LB1[15];
3993b608985Sdrahn u_char LB2[15];
4003b608985Sdrahn u_char LB3[15];
4013b608985Sdrahn u_char LB4[15];
4023b608985Sdrahn u_char LB5[15];
4033b608985Sdrahn u_char LB6[15];
4043b608985Sdrahn u_char RB0[15];
4053b608985Sdrahn u_char RB1[15];
4063b608985Sdrahn u_char RB2[15];
4073b608985Sdrahn u_char RB3[15];
4083b608985Sdrahn u_char RB4[15];
4093b608985Sdrahn u_char RB5[15];
4103b608985Sdrahn u_char RB6[15];
4113b608985Sdrahn u_char LLB[15];
4123b608985Sdrahn u_char RLB[15];
4133b608985Sdrahn u_char LLB_GAIN[3];
4143b608985Sdrahn u_char RLB_GAIN[3];
4153b608985Sdrahn u_char ACR[1];
4163b608985Sdrahn u_char MCR2[1];
4173b608985Sdrahn };
4183b608985Sdrahn
4193b608985Sdrahn int
snapper_match(struct device * parent,void * match,void * aux)420ea884047Sbrad snapper_match(struct device *parent, void *match, void *aux)
4213b608985Sdrahn {
4223b608985Sdrahn struct confargs *ca = aux;
423ea8dca19Skettenis int soundbus, soundchip, soundcodec;
4243b608985Sdrahn char compat[32];
4253b608985Sdrahn
4263b608985Sdrahn if (strcmp(ca->ca_name, "i2s") != 0)
427ea884047Sbrad return (0);
4283b608985Sdrahn
4293b608985Sdrahn if ((soundbus = OF_child(ca->ca_node)) == 0 ||
4303b608985Sdrahn (soundchip = OF_child(soundbus)) == 0)
431ea884047Sbrad return (0);
4323b608985Sdrahn
4333b608985Sdrahn bzero(compat, sizeof compat);
4343b608985Sdrahn OF_getprop(soundchip, "compatible", compat, sizeof compat);
4353b608985Sdrahn
436ff2d06fbSgkoehler if (strcmp(compat, "AOAKeylargo") == 0 &&
437ff2d06fbSgkoehler strcmp(hw_prod, "PowerBook5,4") == 0)
438ff2d06fbSgkoehler return (1);
43927a32e3aSkettenis if (strcmp(compat, "snapper") == 0)
440ea884047Sbrad return (1);
441ea8dca19Skettenis
442ea8dca19Skettenis if (OF_getprop(soundchip, "platform-tas-codec-ref",
44327a32e3aSkettenis &soundcodec, sizeof soundcodec) == sizeof soundcodec)
444ea8dca19Skettenis return (1);
445ea8dca19Skettenis
446ea8dca19Skettenis return (0);
4473b608985Sdrahn }
4483b608985Sdrahn
4493b608985Sdrahn void
snapper_attach(struct device * parent,struct device * self,void * aux)450ea884047Sbrad snapper_attach(struct device *parent, struct device *self, void *aux)
4513b608985Sdrahn {
4523b608985Sdrahn struct snapper_softc *sc = (struct snapper_softc *)self;
4533b608985Sdrahn
454da53b1f9Sjoris sc->sc_setvolume = snapper_set_volume;
455ddfa3b0dSjoris sc->sc_setbass = snapper_set_bass;
456ddfa3b0dSjoris sc->sc_settreble = snapper_set_treble;
457f0d5bc97Stodd sc->sc_setinput = snapper_set_input;
4583b608985Sdrahn
459da53b1f9Sjoris i2s_attach(parent, sc, aux);
4603b608985Sdrahn config_defer(self, snapper_defer);
4613b608985Sdrahn }
4623b608985Sdrahn
4633b608985Sdrahn void
snapper_defer(struct device * dev)4643b608985Sdrahn snapper_defer(struct device *dev)
4653b608985Sdrahn {
4663b608985Sdrahn struct snapper_softc *sc = (struct snapper_softc *)dev;
4673b608985Sdrahn struct device *dv;
4683b608985Sdrahn
4695cf5f4a3Smiod TAILQ_FOREACH(dv, &alldevs, dv_list)
4709f4ceda2Sderaadt if (strcmp(dv->dv_cfdata->cf_driver->cd_name, "kiic") == 0 &&
4719f4ceda2Sderaadt strcmp(dv->dv_parent->dv_cfdata->cf_driver->cd_name, "macobio") == 0)
4723b608985Sdrahn sc->sc_i2c = dv;
4733b608985Sdrahn if (sc->sc_i2c == NULL) {
4743b608985Sdrahn printf("%s: unable to find i2c\n", sc->sc_dev.dv_xname);
4753b608985Sdrahn return;
4763b608985Sdrahn }
4773b608985Sdrahn
478d8128495Smiod /* XXX If i2c has failed to attach, what should we do? */
4793b608985Sdrahn
4802baa08e2Santon audio_attach_mi(&snapper_hw_if, sc, NULL, &sc->sc_dev);
4813b608985Sdrahn
482715b6a7bSderaadt /* kiic_setmode(sc->sc_i2c, I2C_STDSUBMODE); */
483f3538de4Sjoris snapper_init(sc);
4843b608985Sdrahn }
4853b608985Sdrahn
4863b608985Sdrahn void
snapper_set_volume(struct snapper_softc * sc,int left,int right)487ea884047Sbrad snapper_set_volume(struct snapper_softc *sc, int left, int right)
4883b608985Sdrahn {
4893b608985Sdrahn u_char vol[6];
490f0d5bc97Stodd int nentries = sizeof(snapper_volumetab) / sizeof(snapper_volumetab[0]);
491f0d5bc97Stodd int l, r;
4923b608985Sdrahn
4933b608985Sdrahn sc->sc_vol_l = left;
4943b608985Sdrahn sc->sc_vol_r = right;
4953b608985Sdrahn
496f0d5bc97Stodd l = nentries - (left * nentries / 256);
497f0d5bc97Stodd r = nentries - (right * nentries / 256);
4983b608985Sdrahn
499f0d5bc97Stodd DPRINTF(" left %d vol %d %d, right %d vol %d %d\n",
500f0d5bc97Stodd left, l, nentries,
501f0d5bc97Stodd right, r, nentries);
502f0d5bc97Stodd if (l >= nentries)
503f0d5bc97Stodd l = nentries-1;
504f0d5bc97Stodd if (r >= nentries)
505f0d5bc97Stodd r = nentries-1;
506f0d5bc97Stodd
507f0d5bc97Stodd vol[0] = snapper_volumetab[l].high;
508f0d5bc97Stodd vol[1] = snapper_volumetab[l].mid;
509f0d5bc97Stodd vol[2] = snapper_volumetab[l].low;
510f0d5bc97Stodd vol[3] = snapper_volumetab[r].high;
511f0d5bc97Stodd vol[4] = snapper_volumetab[r].mid;
512f0d5bc97Stodd vol[5] = snapper_volumetab[r].low;
5133b608985Sdrahn
5143b608985Sdrahn tas3004_write(sc, DEQ_VOLUME, vol);
5153b608985Sdrahn }
5163b608985Sdrahn
517ddfa3b0dSjoris void
snapper_set_treble(struct snapper_softc * sc,int value)518ddfa3b0dSjoris snapper_set_treble(struct snapper_softc *sc, int value)
519ddfa3b0dSjoris {
520ddfa3b0dSjoris uint8_t reg;
521ddfa3b0dSjoris
522ddfa3b0dSjoris if ((value >= 0) && (value <= 255) && (value != sc->sc_treble)) {
523ddfa3b0dSjoris reg = snapper_trebletab[(value >> 3) + 2];
524ddfa3b0dSjoris if (tas3004_write(sc, DEQ_TREBLE, ®) < 0)
525ddfa3b0dSjoris return;
526ddfa3b0dSjoris sc->sc_treble = value;
527ddfa3b0dSjoris }
528ddfa3b0dSjoris }
529ddfa3b0dSjoris
530ddfa3b0dSjoris void
snapper_set_bass(struct snapper_softc * sc,int value)531ddfa3b0dSjoris snapper_set_bass(struct snapper_softc *sc, int value)
532ddfa3b0dSjoris {
533ddfa3b0dSjoris uint8_t reg;
534ddfa3b0dSjoris
535ddfa3b0dSjoris if ((value >= 0) && (value <= 255) && (value != sc->sc_bass)) {
536ddfa3b0dSjoris reg = snapper_basstab[(value >> 3) + 2];
537ddfa3b0dSjoris if (tas3004_write(sc, DEQ_BASS, ®) < 0)
538ddfa3b0dSjoris return;
539ddfa3b0dSjoris sc->sc_bass = value;
540ddfa3b0dSjoris }
541ddfa3b0dSjoris }
542ddfa3b0dSjoris
543f0d5bc97Stodd void
snapper_set_input(struct snapper_softc * sc,int mask)544f0d5bc97Stodd snapper_set_input(struct snapper_softc *sc, int mask)
545f0d5bc97Stodd {
546262988ecSjakemsr uint8_t val = 0;
547262988ecSjakemsr
548f0d5bc97Stodd switch (mask) {
549f0d5bc97Stodd case 1 << 0: /* microphone */
550f0d5bc97Stodd val = DEQ_ACR_ADM | DEQ_ACR_LRB | DEQ_ACR_INP_B;
551f0d5bc97Stodd break;
552f0d5bc97Stodd case 1 << 1: /* line in */
553f0d5bc97Stodd val = 0;
554f0d5bc97Stodd break;
555f0d5bc97Stodd }
556f0d5bc97Stodd tas3004_write(sc, DEQ_ACR, &val);
557f0d5bc97Stodd }
558f0d5bc97Stodd
5593b608985Sdrahn const struct tas3004_reg tas3004_initdata = {
5603b608985Sdrahn { DEQ_MCR1_SC_64 | DEQ_MCR1_SM_I2S | DEQ_MCR1_W_20 }, /* MCR1 */
5613b608985Sdrahn { 1, 0, 0, 0, 0, 0 }, /* DRC */
5626fa5fca9Stodd { 0x00, 0xd7, 0x66, 0x00, 0xd7, 0x66 }, /* VOLUME */
5633b608985Sdrahn { 0x72 }, /* TREBLE */
5643b608985Sdrahn { 0x72 }, /* BASS */
5653b608985Sdrahn { 0x10, 0x00, 0x00, 0, 0, 0, 0, 0, 0 }, /* MIXER_L */
5663b608985Sdrahn { 0x10, 0x00, 0x00, 0, 0, 0, 0, 0, 0 }, /* MIXER_R */
5673b608985Sdrahn { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* BIQUAD */
5683b608985Sdrahn { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* BIQUAD */
5693b608985Sdrahn { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* BIQUAD */
5703b608985Sdrahn { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* BIQUAD */
5713b608985Sdrahn { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* BIQUAD */
5723b608985Sdrahn { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* BIQUAD */
5733b608985Sdrahn { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* BIQUAD */
5743b608985Sdrahn { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* BIQUAD */
5753b608985Sdrahn { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* BIQUAD */
5763b608985Sdrahn { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* BIQUAD */
5773b608985Sdrahn { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* BIQUAD */
5783b608985Sdrahn { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* BIQUAD */
5793b608985Sdrahn { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* BIQUAD */
5803b608985Sdrahn { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* BIQUAD */
5813b608985Sdrahn { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* BIQUAD */
5823b608985Sdrahn { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* BIQUAD */
5833b608985Sdrahn { 0, 0, 0 }, /* LLB_GAIN */
5843b608985Sdrahn { 0, 0, 0 }, /* RLB_GAIN */
5856fa5fca9Stodd { DEQ_ACR_ADM | DEQ_ACR_LRB | DEQ_ACR_INP_B }, /* ACR */
5863b608985Sdrahn { 0 } /* MCR2 */
5873b608985Sdrahn };
5883b608985Sdrahn
5893b608985Sdrahn const char tas3004_regsize[] = {
5903b608985Sdrahn 0, /* 0x00 */
5913b608985Sdrahn sizeof tas3004_initdata.MCR1, /* 0x01 */
5923b608985Sdrahn sizeof tas3004_initdata.DRC, /* 0x02 */
5933b608985Sdrahn 0, /* 0x03 */
5943b608985Sdrahn sizeof tas3004_initdata.VOLUME, /* 0x04 */
5953b608985Sdrahn sizeof tas3004_initdata.TREBLE, /* 0x05 */
5963b608985Sdrahn sizeof tas3004_initdata.BASS, /* 0x06 */
5973b608985Sdrahn sizeof tas3004_initdata.MIXER_L, /* 0x07 */
5983b608985Sdrahn sizeof tas3004_initdata.MIXER_R, /* 0x08 */
5993b608985Sdrahn 0, /* 0x09 */
6003b608985Sdrahn sizeof tas3004_initdata.LB0, /* 0x0a */
6013b608985Sdrahn sizeof tas3004_initdata.LB1, /* 0x0b */
6023b608985Sdrahn sizeof tas3004_initdata.LB2, /* 0x0c */
6033b608985Sdrahn sizeof tas3004_initdata.LB3, /* 0x0d */
6043b608985Sdrahn sizeof tas3004_initdata.LB4, /* 0x0e */
6053b608985Sdrahn sizeof tas3004_initdata.LB5, /* 0x0f */
6063b608985Sdrahn sizeof tas3004_initdata.LB6, /* 0x10 */
6073b608985Sdrahn 0, /* 0x11 */
6083b608985Sdrahn 0, /* 0x12 */
6093b608985Sdrahn sizeof tas3004_initdata.RB0, /* 0x13 */
6103b608985Sdrahn sizeof tas3004_initdata.RB1, /* 0x14 */
6113b608985Sdrahn sizeof tas3004_initdata.RB2, /* 0x15 */
6123b608985Sdrahn sizeof tas3004_initdata.RB3, /* 0x16 */
6133b608985Sdrahn sizeof tas3004_initdata.RB4, /* 0x17 */
6143b608985Sdrahn sizeof tas3004_initdata.RB5, /* 0x18 */
6153b608985Sdrahn sizeof tas3004_initdata.RB6, /* 0x19 */
6163b608985Sdrahn 0,0,0,0, 0,0,
6173b608985Sdrahn 0, /* 0x20 */
6183b608985Sdrahn sizeof tas3004_initdata.LLB, /* 0x21 */
6193b608985Sdrahn sizeof tas3004_initdata.RLB, /* 0x22 */
6203b608985Sdrahn sizeof tas3004_initdata.LLB_GAIN, /* 0x23 */
6213b608985Sdrahn sizeof tas3004_initdata.RLB_GAIN, /* 0x24 */
6223b608985Sdrahn 0,0,0,0, 0,0,0,0, 0,0,0,
6233b608985Sdrahn 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
6243b608985Sdrahn sizeof tas3004_initdata.ACR, /* 0x40 */
6253b608985Sdrahn 0, /* 0x41 */
6263b608985Sdrahn 0, /* 0x42 */
6273b608985Sdrahn sizeof tas3004_initdata.MCR2 /* 0x43 */
6283b608985Sdrahn };
6293b608985Sdrahn
630da53b1f9Sjoris #define DEQaddr 0x6a
631da53b1f9Sjoris
6323b608985Sdrahn int
tas3004_write(struct snapper_softc * sc,u_int reg,const void * data)633ea884047Sbrad tas3004_write(struct snapper_softc *sc, u_int reg, const void *data)
6343b608985Sdrahn {
6353b608985Sdrahn int size;
6363b608985Sdrahn
6373b608985Sdrahn KASSERT(reg < sizeof tas3004_regsize);
6383b608985Sdrahn size = tas3004_regsize[reg];
6393b608985Sdrahn KASSERT(size > 0);
6403b608985Sdrahn
641715b6a7bSderaadt if (kiic_write(sc->sc_i2c, DEQaddr, reg, data, size))
642ea884047Sbrad return (-1);
6433b608985Sdrahn
644ea884047Sbrad return (0);
6453b608985Sdrahn }
6463b608985Sdrahn
6473b608985Sdrahn #define DEQ_WRITE(sc, reg, addr) \
6483b608985Sdrahn if (tas3004_write(sc, reg, addr)) goto err
6493b608985Sdrahn
6503b608985Sdrahn int
tas3004_init(struct snapper_softc * sc)651ea884047Sbrad tas3004_init(struct snapper_softc *sc)
6523b608985Sdrahn {
653da53b1f9Sjoris deq_reset(sc);
6543b608985Sdrahn
6553b608985Sdrahn DEQ_WRITE(sc, DEQ_LB0, tas3004_initdata.LB0);
6563b608985Sdrahn DEQ_WRITE(sc, DEQ_LB1, tas3004_initdata.LB1);
6573b608985Sdrahn DEQ_WRITE(sc, DEQ_LB2, tas3004_initdata.LB2);
6583b608985Sdrahn DEQ_WRITE(sc, DEQ_LB3, tas3004_initdata.LB3);
6593b608985Sdrahn DEQ_WRITE(sc, DEQ_LB4, tas3004_initdata.LB4);
6603b608985Sdrahn DEQ_WRITE(sc, DEQ_LB5, tas3004_initdata.LB5);
6613b608985Sdrahn DEQ_WRITE(sc, DEQ_LB6, tas3004_initdata.LB6);
6623b608985Sdrahn DEQ_WRITE(sc, DEQ_RB0, tas3004_initdata.RB0);
6633b608985Sdrahn DEQ_WRITE(sc, DEQ_RB1, tas3004_initdata.RB1);
6643b608985Sdrahn DEQ_WRITE(sc, DEQ_RB1, tas3004_initdata.RB1);
6653b608985Sdrahn DEQ_WRITE(sc, DEQ_RB2, tas3004_initdata.RB2);
6663b608985Sdrahn DEQ_WRITE(sc, DEQ_RB3, tas3004_initdata.RB3);
6673b608985Sdrahn DEQ_WRITE(sc, DEQ_RB4, tas3004_initdata.RB4);
6683b608985Sdrahn DEQ_WRITE(sc, DEQ_RB5, tas3004_initdata.RB5);
669262988ecSjakemsr DEQ_WRITE(sc, DEQ_RB6, tas3004_initdata.RB6);
6703b608985Sdrahn DEQ_WRITE(sc, DEQ_MCR1, tas3004_initdata.MCR1);
6713b608985Sdrahn DEQ_WRITE(sc, DEQ_MCR2, tas3004_initdata.MCR2);
6723b608985Sdrahn DEQ_WRITE(sc, DEQ_DRC, tas3004_initdata.DRC);
6733b608985Sdrahn DEQ_WRITE(sc, DEQ_VOLUME, tas3004_initdata.VOLUME);
6743b608985Sdrahn DEQ_WRITE(sc, DEQ_TREBLE, tas3004_initdata.TREBLE);
6753b608985Sdrahn DEQ_WRITE(sc, DEQ_BASS, tas3004_initdata.BASS);
6763b608985Sdrahn DEQ_WRITE(sc, DEQ_MIXER_L, tas3004_initdata.MIXER_L);
6773b608985Sdrahn DEQ_WRITE(sc, DEQ_MIXER_R, tas3004_initdata.MIXER_R);
6783b608985Sdrahn DEQ_WRITE(sc, DEQ_LLB, tas3004_initdata.LLB);
6793b608985Sdrahn DEQ_WRITE(sc, DEQ_RLB, tas3004_initdata.RLB);
6803b608985Sdrahn DEQ_WRITE(sc, DEQ_LLB_GAIN, tas3004_initdata.LLB_GAIN);
6813b608985Sdrahn DEQ_WRITE(sc, DEQ_RLB_GAIN, tas3004_initdata.RLB_GAIN);
6823b608985Sdrahn DEQ_WRITE(sc, DEQ_ACR, tas3004_initdata.ACR);
6833b608985Sdrahn
684ea884047Sbrad return (0);
6853b608985Sdrahn err:
686d8128495Smiod printf("%s: tas3004_init failed\n", sc->sc_dev.dv_xname);
687ea884047Sbrad return (-1);
6883b608985Sdrahn }
6893b608985Sdrahn
6903b608985Sdrahn void
snapper_init(struct snapper_softc * sc)691f3538de4Sjoris snapper_init(struct snapper_softc *sc)
6923b608985Sdrahn {
6933b608985Sdrahn
6943b608985Sdrahn /* "sample-rates" (44100, 48000) */
695da53b1f9Sjoris i2s_set_rate(sc, 44100);
6963b608985Sdrahn
6973b608985Sdrahn #if 1
6983b608985Sdrahn /* Enable I2C interrupts. */
6993b608985Sdrahn #define IER 4
7003b608985Sdrahn #define I2C_INT_DATA 0x01
7013b608985Sdrahn #define I2C_INT_ADDR 0x02
7023b608985Sdrahn #define I2C_INT_STOP 0x04
703715b6a7bSderaadt kiic_writereg(sc->sc_i2c, IER,I2C_INT_DATA|I2C_INT_ADDR|I2C_INT_STOP);
7043b608985Sdrahn #endif
7053b608985Sdrahn
7063b608985Sdrahn if (tas3004_init(sc))
7073b608985Sdrahn return;
7083b608985Sdrahn
7096fa5fca9Stodd snapper_set_volume(sc, 190, 190);
710262988ecSjakemsr snapper_set_treble(sc, 128); /* 0 dB */
711262988ecSjakemsr snapper_set_bass(sc, 128); /* 0 dB */
712262988ecSjakemsr
7136fa5fca9Stodd /* Mic in, reflects tas3004_initdata.ACR */
714262988ecSjakemsr sc->sc_record_source = 1 << 1;
7156fa5fca9Stodd snapper_set_input(sc, sc->sc_record_source);
7163b608985Sdrahn }
717