11.22Sthorpej/*	$NetBSD: deq.c,v 1.22 2025/09/17 14:15:58 thorpej Exp $	*/
21.1Smacallan
31.1Smacallan/*-
41.1Smacallan * Copyright (C) 2005 Michael Lorenz
51.1Smacallan *
61.1Smacallan * Redistribution and use in source and binary forms, with or without
71.1Smacallan * modification, are permitted provided that the following conditions
81.1Smacallan * are met:
91.1Smacallan * 1. Redistributions of source code must retain the above copyright
101.1Smacallan *    notice, this list of conditions and the following disclaimer.
111.1Smacallan * 2. Redistributions in binary form must reproduce the above copyright
121.1Smacallan *    notice, this list of conditions and the following disclaimer in the
131.1Smacallan *    documentation and/or other materials provided with the distribution.
141.1Smacallan * 3. The name of the author may not be used to endorse or promote products
151.1Smacallan *    derived from this software without specific prior written permission.
161.1Smacallan *
171.1Smacallan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
181.1Smacallan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
191.1Smacallan * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
201.1Smacallan * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
211.1Smacallan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
221.1Smacallan * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
231.1Smacallan * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
241.1Smacallan * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
251.1Smacallan * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
261.1Smacallan * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
271.1Smacallan */
281.1Smacallan
291.1Smacallan/*
301.1Smacallan * a dummy device to attach to OF's deq node marking the TAS3004 audio mixer /
311.1Smacallan * equalizer chip, needed by snapper
321.1Smacallan */
331.1Smacallan
341.1Smacallan#include <sys/cdefs.h>
351.22Sthorpej__KERNEL_RCSID(0, "$NetBSD: deq.c,v 1.22 2025/09/17 14:15:58 thorpej Exp $");
361.1Smacallan
371.1Smacallan#include <sys/param.h>
381.1Smacallan#include <sys/systm.h>
391.1Smacallan#include <sys/kernel.h>
401.1Smacallan#include <sys/device.h>
411.1Smacallan
421.1Smacallan#include <dev/ofw/openfirm.h>
431.1Smacallan#include <dev/i2c/i2cvar.h>
441.1Smacallan
451.1Smacallan#include <machine/autoconf.h>
461.1Smacallan#include <macppc/dev/deqvar.h>
471.1Smacallan
481.4Smacallanstatic void deq_attach(device_t, device_t, void *);
491.4Smacallanstatic int deq_match(device_t, struct cfdata *, void *);
501.1Smacallan
511.4SmacallanCFATTACH_DECL_NEW(deq, sizeof(struct deq_softc),
521.1Smacallan    deq_match, deq_attach, NULL, NULL);
531.1Smacallan
541.16Sthorpejstatic const struct device_compatible_entry compat_data[] = {
551.18Sthorpej	{ .compat = "deq" },
561.18Sthorpej	{ .compat = "tas3004" },
571.18Sthorpej	{ .compat = "pcm3052" },
581.18Sthorpej	{ .compat = "cs8416" },
591.18Sthorpej	{ .compat = "codec" },
601.20Sthorpej	DEVICE_COMPAT_EOL
611.15Sthorpej};
621.15Sthorpej
631.1Smacallanint
641.5Sdsldeq_match(device_t parent, struct cfdata *cf, void *aux)
651.1Smacallan{
661.10Smacallan	struct i2c_attach_args *ia = aux;
671.14Sthorpej	int match_result;
681.14Sthorpej
691.16Sthorpej	if (iic_use_direct_match(ia, cf, compat_data, &match_result))
701.14Sthorpej		return match_result;
711.14Sthorpej
721.14Sthorpej	/* This driver is direct-config only. */
731.14Sthorpej
741.1Smacallan	return 0;
751.1Smacallan}
761.1Smacallan
771.1Smacallanvoid
781.6Sdsldeq_attach(device_t parent, device_t self, void *aux)
791.1Smacallan{
801.4Smacallan	struct deq_softc *sc = device_private(self);
811.10Smacallan	struct i2c_attach_args *ia = aux;
821.11Smacallan	char name[256];
831.1Smacallan
841.4Smacallan	sc->sc_dev = self;
851.22Sthorpej	sc->sc_node = devhandle_to_of(device_handle(self));
861.1Smacallan	sc->sc_parent = parent;
871.13Smacallan	sc->sc_address = ia->ia_addr;
881.10Smacallan	sc->sc_i2c = ia->ia_tag;
891.11Smacallan	if (OF_getprop(sc->sc_node, "compatible", name, 256) <= 0) {
901.17Smacallan		/* deq has no 'compatible' on my iBook G4 or Quicksilver */
911.12Smacallan		switch (sc->sc_address) {
921.12Smacallan			case 0x35:
931.12Smacallan				strcpy(name, "tas3004");
941.12Smacallan				break;
951.17Smacallan			case 0x34:
961.17Smacallan				strcpy(name, "tas3001");
971.17Smacallan				break;
981.12Smacallan			default:
991.12Smacallan				strcpy(name, "unknown");
1001.12Smacallan		}
1011.11Smacallan	}
1021.11Smacallan	aprint_normal(" Audio Codec (%s)\n", name);
1031.1Smacallan}
104