1*e5fbc36aSthorpej /* $NetBSD: deq.c,v 1.21 2023/12/20 15:29:04 thorpej Exp $ */
219df969aSmacallan
319df969aSmacallan /*-
419df969aSmacallan * Copyright (C) 2005 Michael Lorenz
519df969aSmacallan *
619df969aSmacallan * Redistribution and use in source and binary forms, with or without
719df969aSmacallan * modification, are permitted provided that the following conditions
819df969aSmacallan * are met:
919df969aSmacallan * 1. Redistributions of source code must retain the above copyright
1019df969aSmacallan * notice, this list of conditions and the following disclaimer.
1119df969aSmacallan * 2. Redistributions in binary form must reproduce the above copyright
1219df969aSmacallan * notice, this list of conditions and the following disclaimer in the
1319df969aSmacallan * documentation and/or other materials provided with the distribution.
1419df969aSmacallan * 3. The name of the author may not be used to endorse or promote products
1519df969aSmacallan * derived from this software without specific prior written permission.
1619df969aSmacallan *
1719df969aSmacallan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1819df969aSmacallan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1919df969aSmacallan * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2019df969aSmacallan * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2119df969aSmacallan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2219df969aSmacallan * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2319df969aSmacallan * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2419df969aSmacallan * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2519df969aSmacallan * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2619df969aSmacallan * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2719df969aSmacallan */
2819df969aSmacallan
2919df969aSmacallan /*
3019df969aSmacallan * a dummy device to attach to OF's deq node marking the TAS3004 audio mixer /
3119df969aSmacallan * equalizer chip, needed by snapper
3219df969aSmacallan */
3319df969aSmacallan
3419df969aSmacallan #include <sys/cdefs.h>
35*e5fbc36aSthorpej __KERNEL_RCSID(0, "$NetBSD: deq.c,v 1.21 2023/12/20 15:29:04 thorpej Exp $");
3619df969aSmacallan
3719df969aSmacallan #include <sys/param.h>
3819df969aSmacallan #include <sys/systm.h>
3919df969aSmacallan #include <sys/kernel.h>
4019df969aSmacallan #include <sys/device.h>
4119df969aSmacallan
4219df969aSmacallan #include <dev/ofw/openfirm.h>
4319df969aSmacallan #include <dev/i2c/i2cvar.h>
4419df969aSmacallan
4519df969aSmacallan #include <machine/autoconf.h>
4619df969aSmacallan #include <macppc/dev/deqvar.h>
4719df969aSmacallan
480a928346Smacallan static void deq_attach(device_t, device_t, void *);
490a928346Smacallan static int deq_match(device_t, struct cfdata *, void *);
5019df969aSmacallan
510a928346Smacallan CFATTACH_DECL_NEW(deq, sizeof(struct deq_softc),
5219df969aSmacallan deq_match, deq_attach, NULL, NULL);
5319df969aSmacallan
54feee3a19Sthorpej static const struct device_compatible_entry compat_data[] = {
5556caee62Sthorpej { .compat = "deq" },
5656caee62Sthorpej { .compat = "tas3004" },
5756caee62Sthorpej { .compat = "pcm3052" },
5856caee62Sthorpej { .compat = "cs8416" },
5956caee62Sthorpej { .compat = "codec" },
60ec189949Sthorpej DEVICE_COMPAT_EOL
614f9e5a44Sthorpej };
624f9e5a44Sthorpej
6319df969aSmacallan int
deq_match(device_t parent,struct cfdata * cf,void * aux)64454af1c0Sdsl deq_match(device_t parent, struct cfdata *cf, void *aux)
6519df969aSmacallan {
668cadda84Smacallan struct i2c_attach_args *ia = aux;
67aa41e992Sthorpej int match_result;
6819df969aSmacallan
69feee3a19Sthorpej if (iic_use_direct_match(ia, cf, compat_data, &match_result))
70aa41e992Sthorpej return match_result;
71aa41e992Sthorpej
72aa41e992Sthorpej /* This driver is direct-config only. */
73aa41e992Sthorpej
7419df969aSmacallan return 0;
7519df969aSmacallan }
7619df969aSmacallan
7719df969aSmacallan void
deq_attach(device_t parent,device_t self,void * aux)7882357f6dSdsl deq_attach(device_t parent, device_t self, void *aux)
7919df969aSmacallan {
800a928346Smacallan struct deq_softc *sc = device_private(self);
818cadda84Smacallan struct i2c_attach_args *ia = aux;
829e80246fSmacallan char name[256];
8319df969aSmacallan
840a928346Smacallan sc->sc_dev = self;
858cadda84Smacallan sc->sc_node = ia->ia_cookie;
8619df969aSmacallan sc->sc_parent = parent;
8744c01204Smacallan sc->sc_address = ia->ia_addr;
888cadda84Smacallan sc->sc_i2c = ia->ia_tag;
899e80246fSmacallan if (OF_getprop(sc->sc_node, "compatible", name, 256) <= 0) {
901200baa9Smacallan /* deq has no 'compatible' on my iBook G4 or Quicksilver */
91ec933c7fSmacallan switch (sc->sc_address) {
92ec933c7fSmacallan case 0x35:
93ec933c7fSmacallan strcpy(name, "tas3004");
94ec933c7fSmacallan break;
951200baa9Smacallan case 0x34:
961200baa9Smacallan strcpy(name, "tas3001");
971200baa9Smacallan break;
98ec933c7fSmacallan default:
999e80246fSmacallan strcpy(name, "unknown");
1009e80246fSmacallan }
101ec933c7fSmacallan }
1029e80246fSmacallan aprint_normal(" Audio Codec (%s)\n", name);
10319df969aSmacallan }
104