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