summaryrefslogtreecommitdiff
path: root/sys/arch/arm/sunxi/sunxi_codec.h
blob: 46bc9f668e786dd5ac9c0467f9af44c654b6d053 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* $NetBSD: sunxi_codec.h,v 1.8 2021/05/05 20:58:03 jmcneill Exp $ */

/*-
 * Copyright (c) 2014-2017 Jared McNeill <jmcneill@invisible.ca>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef _ARM_SUNXI_CODEC_H
#define _ARM_SUNXI_CODEC_H

#include <sys/audioio.h>
#include <dev/audio/audio_if.h>

#include <dev/fdt/fdtvar.h>

#include "h3_codec.h"
#include "v3s_codec.h"

struct sunxi_codec_softc;

struct sunxi_codec_conf {
	const char	*name;

	/* initialize codec */
	int		(*init)(struct sunxi_codec_softc *);
	/* toggle DAC/ADC mute */
	void		(*mute)(struct sunxi_codec_softc *, int, u_int);
	/* mixer controls */
	int		(*set_port)(struct sunxi_codec_softc *,
				    mixer_ctrl_t *);
	int		(*get_port)(struct sunxi_codec_softc *,
				    mixer_ctrl_t *);
	int		(*query_devinfo)(struct sunxi_codec_softc *,
					 mixer_devinfo_t *);

	/* register map */
	bus_size_t	DPC,
			DAC_FIFOC,
			DAC_FIFOS,
			DAC_TXDATA,
			ADC_FIFOC,
			ADC_FIFOS,
			ADC_RXDATA,
			DAC_CNT,
			ADC_CNT;
};

struct sunxi_codec_chan {
	struct sunxi_codec_softc *ch_sc;
	u_int			ch_mode;

	struct fdtbus_dma	*ch_dma;
	struct fdtbus_dma_req	ch_req;

	audio_params_t		ch_params;

	bus_addr_t		ch_start_phys;
	bus_addr_t		ch_end_phys;
	bus_addr_t		ch_cur_phys;
	int			ch_blksize;

	void			(*ch_intr)(void *);
	void			*ch_intrarg;
};

struct sunxi_codec_dma {
	LIST_ENTRY(sunxi_codec_dma) dma_list;
	bus_dmamap_t		dma_map;
	void			*dma_addr;
	size_t			dma_size;
	bus_dma_segment_t	dma_segs[1];
	int			dma_nsegs;
};

struct sunxi_codec_softc {
	device_t		sc_dev;
	bus_space_tag_t		sc_bst;
	bus_space_handle_t	sc_bsh;
	bus_dma_tag_t		sc_dmat;
	int			sc_phandle;
	bus_addr_t		sc_baseaddr;

	const struct sunxi_codec_conf	*sc_cfg;
	void			*sc_codec_priv;

	struct fdtbus_gpio_pin	*sc_pin_pa;

	LIST_HEAD(, sunxi_codec_dma) sc_dmalist;

	kmutex_t		sc_lock;
	kmutex_t		sc_intr_lock;

	struct audio_format	sc_format;

	struct sunxi_codec_chan	sc_pchan;
	struct sunxi_codec_chan	sc_rchan;
};

#if NH3_CODEC > 0
extern const struct sunxi_codec_conf sun8i_h3_codecconf;
#define	H3_CODEC_COMPATDATA						\
	{ .compat = "allwinner,sun8i-h3-codec",				\
	  .data = &sun8i_h3_codecconf },
#else
#define	H3_CODEC_COMPATDATA
#endif

#if NV3S_CODEC > 0
extern const struct sunxi_codec_conf sun8i_v3s_codecconf;
#define V3S_CODEC_COMPATDATA						\
	{ .compat = "allwinner,sun8i-v3s-codec",			\
	  .data = &sun8i_v3s_codecconf },
#else
#define V3S_CODEC_COMPATDATA
#endif

extern const struct sunxi_codec_conf sun4i_a10_codecconf;
#define	A10_CODEC_COMPATDATA						\
	{ .compat = "allwinner,sun4i-a10-codec",			\
	  .data = &sun4i_a10_codecconf }, 				\
	{ .compat = "allwinner,sun7i-a20-codec",			\
	  .data = &sun4i_a10_codecconf },

extern const struct sunxi_codec_conf sun6i_a31_codecconf;
#define	A31_CODEC_COMPATDATA						\
	{ .compat = "allwinner,sun6i-a31-codec",			\
	  .data = &sun6i_a31_codecconf },

#endif /* !_ARM_SUNXI_CODEC_H */