xref: /netbsd-src/sys/arch/arm/sunxi/sunxi_codec.h (revision bf4c995c05c6d362a3e6904bb0d12e1cd6e541c7)
1*bf4c995cSjmcneill /* $NetBSD: sunxi_codec.h,v 1.8 2021/05/05 20:58:03 jmcneill Exp $ */
2e8ba4a22Sjmcneill 
3e8ba4a22Sjmcneill /*-
4e8ba4a22Sjmcneill  * Copyright (c) 2014-2017 Jared McNeill <jmcneill@invisible.ca>
5e8ba4a22Sjmcneill  * All rights reserved.
6e8ba4a22Sjmcneill  *
7e8ba4a22Sjmcneill  * Redistribution and use in source and binary forms, with or without
8e8ba4a22Sjmcneill  * modification, are permitted provided that the following conditions
9e8ba4a22Sjmcneill  * are met:
10e8ba4a22Sjmcneill  * 1. Redistributions of source code must retain the above copyright
11e8ba4a22Sjmcneill  *    notice, this list of conditions and the following disclaimer.
12e8ba4a22Sjmcneill  * 2. Redistributions in binary form must reproduce the above copyright
13e8ba4a22Sjmcneill  *    notice, this list of conditions and the following disclaimer in the
14e8ba4a22Sjmcneill  *    documentation and/or other materials provided with the distribution.
15e8ba4a22Sjmcneill  *
16e8ba4a22Sjmcneill  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17e8ba4a22Sjmcneill  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18e8ba4a22Sjmcneill  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19e8ba4a22Sjmcneill  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20e8ba4a22Sjmcneill  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21e8ba4a22Sjmcneill  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22e8ba4a22Sjmcneill  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23e8ba4a22Sjmcneill  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24e8ba4a22Sjmcneill  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25e8ba4a22Sjmcneill  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26e8ba4a22Sjmcneill  * SUCH DAMAGE.
27e8ba4a22Sjmcneill  */
28e8ba4a22Sjmcneill 
29e8ba4a22Sjmcneill #ifndef _ARM_SUNXI_CODEC_H
30e8ba4a22Sjmcneill #define _ARM_SUNXI_CODEC_H
31e8ba4a22Sjmcneill 
32e8ba4a22Sjmcneill #include <sys/audioio.h>
33e622eac4Sisaki #include <dev/audio/audio_if.h>
34e8ba4a22Sjmcneill 
35e8ba4a22Sjmcneill #include <dev/fdt/fdtvar.h>
36e8ba4a22Sjmcneill 
37e8ba4a22Sjmcneill #include "h3_codec.h"
386c4affb9Sjmcneill #include "v3s_codec.h"
39e8ba4a22Sjmcneill 
40e8ba4a22Sjmcneill struct sunxi_codec_softc;
41e8ba4a22Sjmcneill 
42e8ba4a22Sjmcneill struct sunxi_codec_conf {
43e8ba4a22Sjmcneill 	const char	*name;
44e8ba4a22Sjmcneill 
45e8ba4a22Sjmcneill 	/* initialize codec */
46e8ba4a22Sjmcneill 	int		(*init)(struct sunxi_codec_softc *);
47e8ba4a22Sjmcneill 	/* toggle DAC/ADC mute */
48e8ba4a22Sjmcneill 	void		(*mute)(struct sunxi_codec_softc *, int, u_int);
49e8ba4a22Sjmcneill 	/* mixer controls */
50e8ba4a22Sjmcneill 	int		(*set_port)(struct sunxi_codec_softc *,
51e8ba4a22Sjmcneill 				    mixer_ctrl_t *);
52e8ba4a22Sjmcneill 	int		(*get_port)(struct sunxi_codec_softc *,
53e8ba4a22Sjmcneill 				    mixer_ctrl_t *);
54e8ba4a22Sjmcneill 	int		(*query_devinfo)(struct sunxi_codec_softc *,
55e8ba4a22Sjmcneill 					 mixer_devinfo_t *);
56e8ba4a22Sjmcneill 
57e8ba4a22Sjmcneill 	/* register map */
58e8ba4a22Sjmcneill 	bus_size_t	DPC,
59e8ba4a22Sjmcneill 			DAC_FIFOC,
60e8ba4a22Sjmcneill 			DAC_FIFOS,
61e8ba4a22Sjmcneill 			DAC_TXDATA,
62e8ba4a22Sjmcneill 			ADC_FIFOC,
63e8ba4a22Sjmcneill 			ADC_FIFOS,
64e8ba4a22Sjmcneill 			ADC_RXDATA,
65e8ba4a22Sjmcneill 			DAC_CNT,
66e8ba4a22Sjmcneill 			ADC_CNT;
67e8ba4a22Sjmcneill };
68e8ba4a22Sjmcneill 
69e8ba4a22Sjmcneill struct sunxi_codec_chan {
70e8ba4a22Sjmcneill 	struct sunxi_codec_softc *ch_sc;
71e8ba4a22Sjmcneill 	u_int			ch_mode;
72e8ba4a22Sjmcneill 
73e8ba4a22Sjmcneill 	struct fdtbus_dma	*ch_dma;
74e8ba4a22Sjmcneill 	struct fdtbus_dma_req	ch_req;
75e8ba4a22Sjmcneill 
76e8ba4a22Sjmcneill 	audio_params_t		ch_params;
77e8ba4a22Sjmcneill 
78e8ba4a22Sjmcneill 	bus_addr_t		ch_start_phys;
79e8ba4a22Sjmcneill 	bus_addr_t		ch_end_phys;
80e8ba4a22Sjmcneill 	bus_addr_t		ch_cur_phys;
81e8ba4a22Sjmcneill 	int			ch_blksize;
82e8ba4a22Sjmcneill 
83e8ba4a22Sjmcneill 	void			(*ch_intr)(void *);
84e8ba4a22Sjmcneill 	void			*ch_intrarg;
85e8ba4a22Sjmcneill };
86e8ba4a22Sjmcneill 
87e8ba4a22Sjmcneill struct sunxi_codec_dma {
88e8ba4a22Sjmcneill 	LIST_ENTRY(sunxi_codec_dma) dma_list;
89e8ba4a22Sjmcneill 	bus_dmamap_t		dma_map;
90e8ba4a22Sjmcneill 	void			*dma_addr;
91e8ba4a22Sjmcneill 	size_t			dma_size;
92e8ba4a22Sjmcneill 	bus_dma_segment_t	dma_segs[1];
93e8ba4a22Sjmcneill 	int			dma_nsegs;
94e8ba4a22Sjmcneill };
95e8ba4a22Sjmcneill 
96e8ba4a22Sjmcneill struct sunxi_codec_softc {
97e8ba4a22Sjmcneill 	device_t		sc_dev;
98e8ba4a22Sjmcneill 	bus_space_tag_t		sc_bst;
99e8ba4a22Sjmcneill 	bus_space_handle_t	sc_bsh;
100e8ba4a22Sjmcneill 	bus_dma_tag_t		sc_dmat;
101e8ba4a22Sjmcneill 	int			sc_phandle;
102e8ba4a22Sjmcneill 	bus_addr_t		sc_baseaddr;
103e8ba4a22Sjmcneill 
104646c0f59Sthorpej 	const struct sunxi_codec_conf	*sc_cfg;
105e8ba4a22Sjmcneill 	void			*sc_codec_priv;
106e8ba4a22Sjmcneill 
107e8ba4a22Sjmcneill 	struct fdtbus_gpio_pin	*sc_pin_pa;
108e8ba4a22Sjmcneill 
109e8ba4a22Sjmcneill 	LIST_HEAD(, sunxi_codec_dma) sc_dmalist;
110e8ba4a22Sjmcneill 
111e8ba4a22Sjmcneill 	kmutex_t		sc_lock;
112e8ba4a22Sjmcneill 	kmutex_t		sc_intr_lock;
113e8ba4a22Sjmcneill 
114e8ba4a22Sjmcneill 	struct audio_format	sc_format;
115e8ba4a22Sjmcneill 
116e8ba4a22Sjmcneill 	struct sunxi_codec_chan	sc_pchan;
117e8ba4a22Sjmcneill 	struct sunxi_codec_chan	sc_rchan;
118e8ba4a22Sjmcneill };
119e8ba4a22Sjmcneill 
120e8ba4a22Sjmcneill #if NH3_CODEC > 0
121e8ba4a22Sjmcneill extern const struct sunxi_codec_conf sun8i_h3_codecconf;
122e8ba4a22Sjmcneill #define	H3_CODEC_COMPATDATA						\
123646c0f59Sthorpej 	{ .compat = "allwinner,sun8i-h3-codec",				\
124*bf4c995cSjmcneill 	  .data = &sun8i_h3_codecconf },
125e8ba4a22Sjmcneill #else
126e8ba4a22Sjmcneill #define	H3_CODEC_COMPATDATA
127e8ba4a22Sjmcneill #endif
128e8ba4a22Sjmcneill 
1296c4affb9Sjmcneill #if NV3S_CODEC > 0
1306c4affb9Sjmcneill extern const struct sunxi_codec_conf sun8i_v3s_codecconf;
1316c4affb9Sjmcneill #define V3S_CODEC_COMPATDATA						\
1326c4affb9Sjmcneill 	{ .compat = "allwinner,sun8i-v3s-codec",			\
133*bf4c995cSjmcneill 	  .data = &sun8i_v3s_codecconf },
1346c4affb9Sjmcneill #else
1356c4affb9Sjmcneill #define V3S_CODEC_COMPATDATA
1366c4affb9Sjmcneill #endif
1376c4affb9Sjmcneill 
138cdcf8af9Sjmcneill extern const struct sunxi_codec_conf sun4i_a10_codecconf;
139cdcf8af9Sjmcneill #define	A10_CODEC_COMPATDATA						\
140646c0f59Sthorpej 	{ .compat = "allwinner,sun4i-a10-codec",			\
141646c0f59Sthorpej 	  .data = &sun4i_a10_codecconf }, 				\
142646c0f59Sthorpej 	{ .compat = "allwinner,sun7i-a20-codec",			\
143*bf4c995cSjmcneill 	  .data = &sun4i_a10_codecconf },
144cdcf8af9Sjmcneill 
145d3e86955Sjmcneill extern const struct sunxi_codec_conf sun6i_a31_codecconf;
146d3e86955Sjmcneill #define	A31_CODEC_COMPATDATA						\
147646c0f59Sthorpej 	{ .compat = "allwinner,sun6i-a31-codec",			\
148*bf4c995cSjmcneill 	  .data = &sun6i_a31_codecconf },
149d3e86955Sjmcneill 
150e8ba4a22Sjmcneill #endif /* !_ARM_SUNXI_CODEC_H */
151