1
2
3
4
5
6
7
8
9#ifndef __LINUX_GBAUDIO_CODEC_H
10#define __LINUX_GBAUDIO_CODEC_H
11
12#include <sound/soc.h>
13#include <sound/jack.h>
14
15#include "greybus.h"
16#include "greybus_protocols.h"
17
18#define NAME_SIZE 32
19#define MAX_DAIS 2
20
21enum {
22 APB1_PCM = 0,
23 APB2_PCM,
24 NUM_CODEC_DAIS,
25};
26
27enum gbcodec_reg_index {
28 GBCODEC_CTL_REG,
29 GBCODEC_MUTE_REG,
30 GBCODEC_PB_LVOL_REG,
31 GBCODEC_PB_RVOL_REG,
32 GBCODEC_CAP_LVOL_REG,
33 GBCODEC_CAP_RVOL_REG,
34 GBCODEC_APB1_MUX_REG,
35 GBCODEC_APB2_MUX_REG,
36 GBCODEC_REG_COUNT
37};
38
39
40enum {
41 GBAUDIO_DEVICE_NONE = 0x0,
42
43 GBAUDIO_DEVICE_BIT_IN = 0x80000000,
44 GBAUDIO_DEVICE_BIT_DEFAULT = 0x40000000,
45
46 GBAUDIO_DEVICE_OUT_SPEAKER = 0x2,
47 GBAUDIO_DEVICE_OUT_WIRED_HEADSET = 0x4,
48 GBAUDIO_DEVICE_OUT_WIRED_HEADPHONE = 0x8,
49
50 GBAUDIO_DEVICE_IN_BUILTIN_MIC = GBAUDIO_DEVICE_BIT_IN | 0x4,
51 GBAUDIO_DEVICE_IN_WIRED_HEADSET = GBAUDIO_DEVICE_BIT_IN | 0x10,
52};
53
54
55
56
57#define GBCODEC_CTL_REG_DEFAULT 0x00
58
59
60
61
62
63
64#define GBCODEC_MUTE_REG_DEFAULT 0x00
65
66
67#define GBCODEC_PB_VOL_REG_DEFAULT 0x00
68#define GBCODEC_CAP_VOL_REG_DEFAULT 0x00
69
70
71
72
73#define GBCODEC_APB1_MUX_REG_DEFAULT 0x00
74#define GBCODEC_APB2_MUX_REG_DEFAULT 0x00
75
76#define GBCODEC_JACK_MASK 0x0000FFFF
77#define GBCODEC_JACK_BUTTON_MASK 0xFFFF0000
78
79static const u8 gbcodec_reg_defaults[GBCODEC_REG_COUNT] = {
80 GBCODEC_CTL_REG_DEFAULT,
81 GBCODEC_MUTE_REG_DEFAULT,
82 GBCODEC_PB_VOL_REG_DEFAULT,
83 GBCODEC_PB_VOL_REG_DEFAULT,
84 GBCODEC_CAP_VOL_REG_DEFAULT,
85 GBCODEC_CAP_VOL_REG_DEFAULT,
86 GBCODEC_APB1_MUX_REG_DEFAULT,
87 GBCODEC_APB2_MUX_REG_DEFAULT,
88};
89
90enum gbaudio_codec_state {
91 GBAUDIO_CODEC_SHUTDOWN = 0,
92 GBAUDIO_CODEC_STARTUP,
93 GBAUDIO_CODEC_HWPARAMS,
94 GBAUDIO_CODEC_PREPARE,
95 GBAUDIO_CODEC_START,
96 GBAUDIO_CODEC_STOP,
97};
98
99struct gbaudio_stream_params {
100 int state;
101 u8 sig_bits, channels;
102 uint32_t format, rate;
103};
104
105struct gbaudio_codec_dai {
106 int id;
107
108 struct gbaudio_stream_params params[2];
109 struct list_head list;
110};
111
112struct gbaudio_codec_info {
113 struct device *dev;
114 struct snd_soc_codec *codec;
115 struct list_head module_list;
116
117 struct list_head dai_list;
118 struct mutex lock;
119 u8 reg[GBCODEC_REG_COUNT];
120};
121
122struct gbaudio_widget {
123 __u8 id;
124 const char *name;
125 struct list_head list;
126};
127
128struct gbaudio_control {
129 __u8 id;
130 char *name;
131 char *wname;
132 const char * const *texts;
133 int items;
134 struct list_head list;
135};
136
137struct gbaudio_data_connection {
138 int id;
139 __le16 data_cport;
140 struct gb_connection *connection;
141 struct list_head list;
142
143 int state[2];
144};
145
146
147#define GB_PLAYBACK BIT(0)
148#define GB_CAPTURE BIT(1)
149
150enum gbaudio_module_state {
151 GBAUDIO_MODULE_OFF = 0,
152 GBAUDIO_MODULE_ON,
153};
154
155struct gbaudio_module_info {
156
157 struct device *dev;
158 int dev_id;
159 int vid;
160 int pid;
161 int slot;
162 int type;
163 int set_uevent;
164 char vstr[NAME_SIZE];
165 char pstr[NAME_SIZE];
166 struct list_head list;
167
168 int manager_id;
169 char name[NAME_SIZE];
170 unsigned int ip_devices;
171 unsigned int op_devices;
172
173
174 char jack_name[NAME_SIZE];
175 char button_name[NAME_SIZE];
176 int jack_type;
177 int jack_mask;
178 int button_mask;
179 int button_status;
180 struct snd_soc_jack headset_jack;
181 struct snd_soc_jack button_jack;
182
183
184 struct gb_connection *mgmt_connection;
185 size_t num_data_connections;
186 struct list_head data_list;
187
188
189 int num_dais;
190 int num_controls;
191 int num_dapm_widgets;
192 int num_dapm_routes;
193 unsigned long dai_offset;
194 unsigned long widget_offset;
195 unsigned long control_offset;
196 unsigned long route_offset;
197 struct snd_kcontrol_new *controls;
198 struct snd_soc_dapm_widget *dapm_widgets;
199 struct snd_soc_dapm_route *dapm_routes;
200 struct snd_soc_dai_driver *dais;
201
202 struct list_head widget_list;
203 struct list_head ctl_list;
204 struct list_head widget_ctl_list;
205
206 struct gb_audio_topology *topology;
207};
208
209int gbaudio_tplg_parse_data(struct gbaudio_module_info *module,
210 struct gb_audio_topology *tplg_data);
211void gbaudio_tplg_release(struct gbaudio_module_info *module);
212
213int gbaudio_module_update(struct gbaudio_codec_info *codec,
214 struct snd_soc_dapm_widget *w,
215 struct gbaudio_module_info *module,
216 int enable);
217int gbaudio_register_module(struct gbaudio_module_info *module);
218void gbaudio_unregister_module(struct gbaudio_module_info *module);
219
220
221extern int gb_audio_gb_get_topology(struct gb_connection *connection,
222 struct gb_audio_topology **topology);
223extern int gb_audio_gb_get_control(struct gb_connection *connection,
224 u8 control_id, u8 index,
225 struct gb_audio_ctl_elem_value *value);
226extern int gb_audio_gb_set_control(struct gb_connection *connection,
227 u8 control_id, u8 index,
228 struct gb_audio_ctl_elem_value *value);
229extern int gb_audio_gb_enable_widget(struct gb_connection *connection,
230 u8 widget_id);
231extern int gb_audio_gb_disable_widget(struct gb_connection *connection,
232 u8 widget_id);
233extern int gb_audio_gb_get_pcm(struct gb_connection *connection,
234 u16 data_cport, uint32_t *format,
235 uint32_t *rate, u8 *channels,
236 u8 *sig_bits);
237extern int gb_audio_gb_set_pcm(struct gb_connection *connection,
238 u16 data_cport, uint32_t format,
239 uint32_t rate, u8 channels,
240 u8 sig_bits);
241extern int gb_audio_gb_set_tx_data_size(struct gb_connection *connection,
242 u16 data_cport, u16 size);
243extern int gb_audio_gb_activate_tx(struct gb_connection *connection,
244 u16 data_cport);
245extern int gb_audio_gb_deactivate_tx(struct gb_connection *connection,
246 u16 data_cport);
247extern int gb_audio_gb_set_rx_data_size(struct gb_connection *connection,
248 u16 data_cport, u16 size);
249extern int gb_audio_gb_activate_rx(struct gb_connection *connection,
250 u16 data_cport);
251extern int gb_audio_gb_deactivate_rx(struct gb_connection *connection,
252 u16 data_cport);
253extern int gb_audio_apbridgea_set_config(struct gb_connection *connection,
254 __u16 i2s_port, __u32 format,
255 __u32 rate, __u32 mclk_freq);
256extern int gb_audio_apbridgea_register_cport(struct gb_connection *connection,
257 __u16 i2s_port, __u16 cportid,
258 __u8 direction);
259extern int gb_audio_apbridgea_unregister_cport(struct gb_connection *connection,
260 __u16 i2s_port, __u16 cportid,
261 __u8 direction);
262extern int gb_audio_apbridgea_set_tx_data_size(struct gb_connection *connection,
263 __u16 i2s_port, __u16 size);
264extern int gb_audio_apbridgea_prepare_tx(struct gb_connection *connection,
265 __u16 i2s_port);
266extern int gb_audio_apbridgea_start_tx(struct gb_connection *connection,
267 __u16 i2s_port, __u64 timestamp);
268extern int gb_audio_apbridgea_stop_tx(struct gb_connection *connection,
269 __u16 i2s_port);
270extern int gb_audio_apbridgea_shutdown_tx(struct gb_connection *connection,
271 __u16 i2s_port);
272extern int gb_audio_apbridgea_set_rx_data_size(struct gb_connection *connection,
273 __u16 i2s_port, __u16 size);
274extern int gb_audio_apbridgea_prepare_rx(struct gb_connection *connection,
275 __u16 i2s_port);
276extern int gb_audio_apbridgea_start_rx(struct gb_connection *connection,
277 __u16 i2s_port);
278extern int gb_audio_apbridgea_stop_rx(struct gb_connection *connection,
279 __u16 i2s_port);
280extern int gb_audio_apbridgea_shutdown_rx(struct gb_connection *connection,
281 __u16 i2s_port);
282
283#endif
284