xref: /netbsd-src/sys/dev/fdt/spdif_tx.c (revision 6e54367a22fbc89a1139d033e95bec0c0cf0975b)
1*6e54367aSthorpej /* $NetBSD: spdif_tx.c,v 1.2 2021/01/27 03:10:21 thorpej Exp $ */
26b393291Sjmcneill 
36b393291Sjmcneill /*-
46b393291Sjmcneill  * Copyright (c) 2019 Jared McNeill <jmcneill@invisible.ca>
56b393291Sjmcneill  * All rights reserved.
66b393291Sjmcneill  *
76b393291Sjmcneill  * Redistribution and use in source and binary forms, with or without
86b393291Sjmcneill  * modification, are permitted provided that the following conditions
96b393291Sjmcneill  * are met:
106b393291Sjmcneill  * 1. Redistributions of source code must retain the above copyright
116b393291Sjmcneill  *    notice, this list of conditions and the following disclaimer.
126b393291Sjmcneill  * 2. Redistributions in binary form must reproduce the above copyright
136b393291Sjmcneill  *    notice, this list of conditions and the following disclaimer in the
146b393291Sjmcneill  *    documentation and/or other materials provided with the distribution.
156b393291Sjmcneill  *
166b393291Sjmcneill  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
176b393291Sjmcneill  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
186b393291Sjmcneill  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
196b393291Sjmcneill  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
206b393291Sjmcneill  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
216b393291Sjmcneill  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
226b393291Sjmcneill  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
236b393291Sjmcneill  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
246b393291Sjmcneill  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
256b393291Sjmcneill  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
266b393291Sjmcneill  * SUCH DAMAGE.
276b393291Sjmcneill  */
286b393291Sjmcneill 
296b393291Sjmcneill #include <sys/cdefs.h>
30*6e54367aSthorpej __KERNEL_RCSID(0, "$NetBSD: spdif_tx.c,v 1.2 2021/01/27 03:10:21 thorpej Exp $");
316b393291Sjmcneill 
326b393291Sjmcneill #include <sys/param.h>
336b393291Sjmcneill #include <sys/bus.h>
346b393291Sjmcneill #include <sys/device.h>
356b393291Sjmcneill #include <sys/systm.h>
366b393291Sjmcneill #include <sys/sysctl.h>
376b393291Sjmcneill #include <sys/kmem.h>
386b393291Sjmcneill 
396b393291Sjmcneill #include <dev/audio/audio_dai.h>
406b393291Sjmcneill 
416b393291Sjmcneill #include <dev/fdt/fdtvar.h>
426b393291Sjmcneill 
436b393291Sjmcneill struct spdif_tx_softc {
446b393291Sjmcneill 	device_t		sc_dev;
456b393291Sjmcneill 	struct audio_dai_device	sc_dai;
466b393291Sjmcneill };
476b393291Sjmcneill 
486b393291Sjmcneill static int	spdif_tx_match(device_t, cfdata_t, void *);
496b393291Sjmcneill static void	spdif_tx_attach(device_t, device_t, void *);
506b393291Sjmcneill 
51*6e54367aSthorpej static const struct device_compatible_entry compat_data[] = {
52*6e54367aSthorpej 	{ .compat = "linux,spdif-dit" },
53*6e54367aSthorpej 	DEVICE_COMPAT_EOL
546b393291Sjmcneill };
556b393291Sjmcneill 
566b393291Sjmcneill CFATTACH_DECL_NEW(spdiftx, sizeof(struct spdif_tx_softc),
576b393291Sjmcneill 	spdif_tx_match, spdif_tx_attach, NULL, NULL);
586b393291Sjmcneill 
596b393291Sjmcneill static int
spdif_tx_set_format(audio_dai_tag_t dai,u_int format)606b393291Sjmcneill spdif_tx_set_format(audio_dai_tag_t dai, u_int format)
616b393291Sjmcneill {
626b393291Sjmcneill 	return 0;
636b393291Sjmcneill }
646b393291Sjmcneill 
656b393291Sjmcneill static int
spdif_tx_add_device(audio_dai_tag_t dai,audio_dai_tag_t aux)666b393291Sjmcneill spdif_tx_add_device(audio_dai_tag_t dai, audio_dai_tag_t aux)
676b393291Sjmcneill {
686b393291Sjmcneill 	return 0;
696b393291Sjmcneill }
706b393291Sjmcneill 
716b393291Sjmcneill static const struct audio_hw_if spdif_tx_hw_if = { };
726b393291Sjmcneill 
736b393291Sjmcneill static audio_dai_tag_t
spdif_tx_dai_get_tag(device_t dev,const void * data,size_t len)746b393291Sjmcneill spdif_tx_dai_get_tag(device_t dev, const void *data, size_t len)
756b393291Sjmcneill {
766b393291Sjmcneill 	struct spdif_tx_softc * const sc = device_private(dev);
776b393291Sjmcneill 
786b393291Sjmcneill 	if (len != 4)
796b393291Sjmcneill 		return NULL;
806b393291Sjmcneill 
816b393291Sjmcneill 	return &sc->sc_dai;
826b393291Sjmcneill }
836b393291Sjmcneill 
846b393291Sjmcneill static struct fdtbus_dai_controller_func spdif_tx_dai_funcs = {
856b393291Sjmcneill 	.get_tag = spdif_tx_dai_get_tag
866b393291Sjmcneill };
876b393291Sjmcneill 
886b393291Sjmcneill static int
spdif_tx_match(device_t parent,cfdata_t cf,void * aux)896b393291Sjmcneill spdif_tx_match(device_t parent, cfdata_t cf, void *aux)
906b393291Sjmcneill {
916b393291Sjmcneill 	struct fdt_attach_args * const faa = aux;
926b393291Sjmcneill 
93*6e54367aSthorpej 	return of_compatible_match(faa->faa_phandle, compat_data);
946b393291Sjmcneill }
956b393291Sjmcneill 
966b393291Sjmcneill static void
spdif_tx_attach(device_t parent,device_t self,void * aux)976b393291Sjmcneill spdif_tx_attach(device_t parent, device_t self, void *aux)
986b393291Sjmcneill {
996b393291Sjmcneill 	struct spdif_tx_softc * const sc = device_private(self);
1006b393291Sjmcneill 	struct fdt_attach_args * const faa = aux;
1016b393291Sjmcneill 	const int phandle = faa->faa_phandle;
1026b393291Sjmcneill 
1036b393291Sjmcneill 	sc->sc_dev = self;
1046b393291Sjmcneill 
1056b393291Sjmcneill 	aprint_naive("\n");
1066b393291Sjmcneill 	aprint_normal(": SPDIF transmitter\n");
1076b393291Sjmcneill 
1086b393291Sjmcneill 	sc->sc_dai.dai_set_format = spdif_tx_set_format;
1096b393291Sjmcneill 	sc->sc_dai.dai_add_device = spdif_tx_add_device;
1106b393291Sjmcneill 	sc->sc_dai.dai_hw_if = &spdif_tx_hw_if;
1116b393291Sjmcneill 	sc->sc_dai.dai_dev = self;
1126b393291Sjmcneill 	sc->sc_dai.dai_priv = sc;
1136b393291Sjmcneill 	fdtbus_register_dai_controller(self, phandle, &spdif_tx_dai_funcs);
1146b393291Sjmcneill }
115