11.2Sthorpej/* $NetBSD: spdif_tx.c,v 1.2 2021/01/27 03:10:21 thorpej Exp $ */
21.1Sjmcneill
31.1Sjmcneill/*-
41.1Sjmcneill * Copyright (c) 2019 Jared McNeill <jmcneill@invisible.ca>
51.1Sjmcneill * All rights reserved.
61.1Sjmcneill *
71.1Sjmcneill * Redistribution and use in source and binary forms, with or without
81.1Sjmcneill * modification, are permitted provided that the following conditions
91.1Sjmcneill * are met:
101.1Sjmcneill * 1. Redistributions of source code must retain the above copyright
111.1Sjmcneill *    notice, this list of conditions and the following disclaimer.
121.1Sjmcneill * 2. Redistributions in binary form must reproduce the above copyright
131.1Sjmcneill *    notice, this list of conditions and the following disclaimer in the
141.1Sjmcneill *    documentation and/or other materials provided with the distribution.
151.1Sjmcneill *
161.1Sjmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
171.1Sjmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
181.1Sjmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
191.1Sjmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
201.1Sjmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
211.1Sjmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
221.1Sjmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
231.1Sjmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
241.1Sjmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
251.1Sjmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
261.1Sjmcneill * SUCH DAMAGE.
271.1Sjmcneill */
281.1Sjmcneill
291.1Sjmcneill#include <sys/cdefs.h>
301.2Sthorpej__KERNEL_RCSID(0, "$NetBSD: spdif_tx.c,v 1.2 2021/01/27 03:10:21 thorpej Exp $");
311.1Sjmcneill
321.1Sjmcneill#include <sys/param.h>
331.1Sjmcneill#include <sys/bus.h>
341.1Sjmcneill#include <sys/device.h>
351.1Sjmcneill#include <sys/systm.h>
361.1Sjmcneill#include <sys/sysctl.h>
371.1Sjmcneill#include <sys/kmem.h>
381.1Sjmcneill
391.1Sjmcneill#include <dev/audio/audio_dai.h>
401.1Sjmcneill
411.1Sjmcneill#include <dev/fdt/fdtvar.h>
421.1Sjmcneill
431.1Sjmcneillstruct spdif_tx_softc {
441.1Sjmcneill	device_t		sc_dev;
451.1Sjmcneill	struct audio_dai_device	sc_dai;
461.1Sjmcneill};
471.1Sjmcneill
481.1Sjmcneillstatic int	spdif_tx_match(device_t, cfdata_t, void *);
491.1Sjmcneillstatic void	spdif_tx_attach(device_t, device_t, void *);
501.1Sjmcneill
511.2Sthorpejstatic const struct device_compatible_entry compat_data[] = {
521.2Sthorpej	{ .compat = "linux,spdif-dit" },
531.2Sthorpej	DEVICE_COMPAT_EOL
541.1Sjmcneill};
551.1Sjmcneill
561.1SjmcneillCFATTACH_DECL_NEW(spdiftx, sizeof(struct spdif_tx_softc),
571.1Sjmcneill	spdif_tx_match, spdif_tx_attach, NULL, NULL);
581.1Sjmcneill
591.1Sjmcneillstatic int
601.1Sjmcneillspdif_tx_set_format(audio_dai_tag_t dai, u_int format)
611.1Sjmcneill{
621.1Sjmcneill	return 0;
631.1Sjmcneill}
641.1Sjmcneill
651.1Sjmcneillstatic int
661.1Sjmcneillspdif_tx_add_device(audio_dai_tag_t dai, audio_dai_tag_t aux)
671.1Sjmcneill{
681.1Sjmcneill	return 0;
691.1Sjmcneill}
701.1Sjmcneill
711.1Sjmcneillstatic const struct audio_hw_if spdif_tx_hw_if = { };
721.1Sjmcneill
731.1Sjmcneillstatic audio_dai_tag_t
741.1Sjmcneillspdif_tx_dai_get_tag(device_t dev, const void *data, size_t len)
751.1Sjmcneill{
761.1Sjmcneill	struct spdif_tx_softc * const sc = device_private(dev);
771.1Sjmcneill
781.1Sjmcneill	if (len != 4)
791.1Sjmcneill		return NULL;
801.1Sjmcneill
811.1Sjmcneill	return &sc->sc_dai;
821.1Sjmcneill}
831.1Sjmcneill
841.1Sjmcneillstatic struct fdtbus_dai_controller_func spdif_tx_dai_funcs = {
851.1Sjmcneill	.get_tag = spdif_tx_dai_get_tag
861.1Sjmcneill};
871.1Sjmcneill
881.1Sjmcneillstatic int
891.1Sjmcneillspdif_tx_match(device_t parent, cfdata_t cf, void *aux)
901.1Sjmcneill{
911.1Sjmcneill	struct fdt_attach_args * const faa = aux;
921.1Sjmcneill
931.2Sthorpej	return of_compatible_match(faa->faa_phandle, compat_data);
941.1Sjmcneill}
951.1Sjmcneill
961.1Sjmcneillstatic void
971.1Sjmcneillspdif_tx_attach(device_t parent, device_t self, void *aux)
981.1Sjmcneill{
991.1Sjmcneill	struct spdif_tx_softc * const sc = device_private(self);
1001.1Sjmcneill	struct fdt_attach_args * const faa = aux;
1011.1Sjmcneill	const int phandle = faa->faa_phandle;
1021.1Sjmcneill
1031.1Sjmcneill	sc->sc_dev = self;
1041.1Sjmcneill
1051.1Sjmcneill	aprint_naive("\n");
1061.1Sjmcneill	aprint_normal(": SPDIF transmitter\n");
1071.1Sjmcneill
1081.1Sjmcneill	sc->sc_dai.dai_set_format = spdif_tx_set_format;
1091.1Sjmcneill	sc->sc_dai.dai_add_device = spdif_tx_add_device;
1101.1Sjmcneill	sc->sc_dai.dai_hw_if = &spdif_tx_hw_if;
1111.1Sjmcneill	sc->sc_dai.dai_dev = self;
1121.1Sjmcneill	sc->sc_dai.dai_priv = sc;
1131.1Sjmcneill	fdtbus_register_dai_controller(self, phandle, &spdif_tx_dai_funcs);
1141.1Sjmcneill}
115