3 * Copyright 2015 Google Inc.
4 * Copyright 2015 Linaro Ltd.
6 * Released under the GPLv2 only.
9 #ifndef __LINUX_GBAUDIO_CODEC_H
10 #define __LINUX_GBAUDIO_CODEC_H
12 #include <sound/soc.h>
13 #include <sound/jack.h>
16 #include "greybus_protocols.h"
19 #define MAX_DAIS 2 /* APB1, APB2 */
27 enum gbcodec_reg_index {
39 /* device_type should be same as defined in audio.h (Android media layer) */
41 GBAUDIO_DEVICE_NONE = 0x0,
43 GBAUDIO_DEVICE_BIT_IN = 0x80000000,
44 GBAUDIO_DEVICE_BIT_DEFAULT = 0x40000000,
46 GBAUDIO_DEVICE_OUT_SPEAKER = 0x2,
47 GBAUDIO_DEVICE_OUT_WIRED_HEADSET = 0x4,
48 GBAUDIO_DEVICE_OUT_WIRED_HEADPHONE = 0x8,
50 GBAUDIO_DEVICE_IN_BUILTIN_MIC = GBAUDIO_DEVICE_BIT_IN | 0x4,
51 GBAUDIO_DEVICE_IN_WIRED_HEADSET = GBAUDIO_DEVICE_BIT_IN | 0x10,
54 /* bit 0-SPK, 1-HP, 2-DAC,
55 * 4-MIC, 5-HSMIC, 6-MIC2
57 #define GBCODEC_CTL_REG_DEFAULT 0x00
59 /* bit 0,1 - APB1-PB-L/R
60 * bit 2,3 - APB2-PB-L/R
61 * bit 4,5 - APB1-Cap-L/R
62 * bit 6,7 - APB2-Cap-L/R
64 #define GBCODEC_MUTE_REG_DEFAULT 0x00
67 #define GBCODEC_PB_VOL_REG_DEFAULT 0x00
68 #define GBCODEC_CAP_VOL_REG_DEFAULT 0x00
70 /* bit 0,1,2 - PB stereo, left, right
71 * bit 8,9,10 - Cap stereo, left, right
73 #define GBCODEC_APB1_MUX_REG_DEFAULT 0x00
74 #define GBCODEC_APB2_MUX_REG_DEFAULT 0x00
76 #define GBCODEC_JACK_MASK (SND_JACK_HEADSET | SND_JACK_LINEOUT | \
77 SND_JACK_LINEIN | SND_JACK_UNSUPPORTED)
78 #define GBCODEC_JACK_BUTTON_MASK (SND_JACK_BTN_0 | SND_JACK_BTN_1 | \
79 SND_JACK_BTN_2 | SND_JACK_BTN_3)
81 static const u8 gbcodec_reg_defaults[GBCODEC_REG_COUNT] = {
82 GBCODEC_CTL_REG_DEFAULT,
83 GBCODEC_MUTE_REG_DEFAULT,
84 GBCODEC_PB_VOL_REG_DEFAULT,
85 GBCODEC_PB_VOL_REG_DEFAULT,
86 GBCODEC_CAP_VOL_REG_DEFAULT,
87 GBCODEC_CAP_VOL_REG_DEFAULT,
88 GBCODEC_APB1_MUX_REG_DEFAULT,
89 GBCODEC_APB2_MUX_REG_DEFAULT,
92 enum gbaudio_codec_state {
93 GBAUDIO_CODEC_SHUTDOWN = 0,
94 GBAUDIO_CODEC_STARTUP,
95 GBAUDIO_CODEC_HWPARAMS,
96 GBAUDIO_CODEC_PREPARE,
101 struct gbaudio_stream {
102 const char *dai_name;
104 uint8_t sig_bits, channels;
105 uint32_t format, rate;
108 struct gbaudio_codec_info {
110 struct snd_soc_codec *codec;
111 struct list_head module_list;
112 struct gbaudio_stream stream[2]; /* PB/CAP */
114 u8 reg[GBCODEC_REG_COUNT];
117 struct gbaudio_widget {
120 struct list_head list;
123 struct gbaudio_control {
127 const char * const *texts;
128 struct list_head list;
131 struct gbaudio_data_connection {
133 int cport_configured;
134 char name[NAME_SIZE];
135 struct gb_connection *connection;
136 struct list_head list;
139 /* stream direction */
140 #define GB_PLAYBACK BIT(0)
141 #define GB_CAPTURE BIT(1)
143 enum gbaudio_module_state {
144 GBAUDIO_MODULE_OFF = 0,
148 struct gbaudio_module_info {
151 int dev_id; /* check if it should be bundle_id/hd_cport_id */
157 char vstr[NAME_SIZE];
158 char pstr[NAME_SIZE];
159 struct list_head list;
160 /* need to share this info to above user space */
162 char name[NAME_SIZE];
163 unsigned int ip_devices;
164 unsigned int op_devices;
167 char jack_name[NAME_SIZE];
168 char button_name[NAME_SIZE];
172 struct snd_soc_jack headset_jack;
173 struct snd_soc_jack button_jack;
175 /* used by codec_ops */
176 int ctrlstate[2]; /* PB/CAP */
178 /* connection info */
179 struct gb_connection *mgmt_connection;
180 size_t num_data_connections;
181 struct list_head data_list;
183 /* topology related */
186 int num_dapm_widgets;
188 unsigned long dai_offset;
189 unsigned long widget_offset;
190 unsigned long control_offset;
191 unsigned long route_offset;
192 struct snd_kcontrol_new *controls;
193 struct snd_soc_dapm_widget *dapm_widgets;
194 struct snd_soc_dapm_route *dapm_routes;
195 struct snd_soc_dai_driver *dais;
197 struct list_head widget_list;
198 struct list_head ctl_list;
199 struct list_head widget_ctl_list;
201 struct gb_audio_topology *topology;
204 int gbaudio_tplg_parse_data(struct gbaudio_module_info *module,
205 struct gb_audio_topology *tplg_data);
206 void gbaudio_tplg_release(struct gbaudio_module_info *module);
208 int gbaudio_module_update(struct gbaudio_codec_info *codec,
210 struct gbaudio_module_info *module,
212 int gbaudio_register_module(struct gbaudio_module_info *module);
213 void gbaudio_unregister_module(struct gbaudio_module_info *module);
215 /* protocol related */
216 extern int gb_audio_gb_get_topology(struct gb_connection *connection,
217 struct gb_audio_topology **topology);
218 extern int gb_audio_gb_get_control(struct gb_connection *connection,
219 uint8_t control_id, uint8_t index,
220 struct gb_audio_ctl_elem_value *value);
221 extern int gb_audio_gb_set_control(struct gb_connection *connection,
222 uint8_t control_id, uint8_t index,
223 struct gb_audio_ctl_elem_value *value);
224 extern int gb_audio_gb_enable_widget(struct gb_connection *connection,
226 extern int gb_audio_gb_disable_widget(struct gb_connection *connection,
228 extern int gb_audio_gb_get_pcm(struct gb_connection *connection,
229 uint16_t data_cport, uint32_t *format,
230 uint32_t *rate, uint8_t *channels,
232 extern int gb_audio_gb_set_pcm(struct gb_connection *connection,
233 uint16_t data_cport, uint32_t format,
234 uint32_t rate, uint8_t channels,
236 extern int gb_audio_gb_set_tx_data_size(struct gb_connection *connection,
237 uint16_t data_cport, uint16_t size);
238 extern int gb_audio_gb_activate_tx(struct gb_connection *connection,
239 uint16_t data_cport);
240 extern int gb_audio_gb_deactivate_tx(struct gb_connection *connection,
241 uint16_t data_cport);
242 extern int gb_audio_gb_set_rx_data_size(struct gb_connection *connection,
243 uint16_t data_cport, uint16_t size);
244 extern int gb_audio_gb_activate_rx(struct gb_connection *connection,
245 uint16_t data_cport);
246 extern int gb_audio_gb_deactivate_rx(struct gb_connection *connection,
247 uint16_t data_cport);
248 extern int gb_audio_apbridgea_set_config(struct gb_connection *connection,
249 __u16 i2s_port, __u32 format,
250 __u32 rate, __u32 mclk_freq);
251 extern int gb_audio_apbridgea_register_cport(struct gb_connection *connection,
252 __u16 i2s_port, __u16 cportid,
254 extern int gb_audio_apbridgea_unregister_cport(struct gb_connection *connection,
255 __u16 i2s_port, __u16 cportid,
257 extern int gb_audio_apbridgea_set_tx_data_size(struct gb_connection *connection,
258 __u16 i2s_port, __u16 size);
259 extern int gb_audio_apbridgea_prepare_tx(struct gb_connection *connection,
261 extern int gb_audio_apbridgea_start_tx(struct gb_connection *connection,
262 __u16 i2s_port, __u64 timestamp);
263 extern int gb_audio_apbridgea_stop_tx(struct gb_connection *connection,
265 extern int gb_audio_apbridgea_shutdown_tx(struct gb_connection *connection,
267 extern int gb_audio_apbridgea_set_rx_data_size(struct gb_connection *connection,
268 __u16 i2s_port, __u16 size);
269 extern int gb_audio_apbridgea_prepare_rx(struct gb_connection *connection,
271 extern int gb_audio_apbridgea_start_rx(struct gb_connection *connection,
273 extern int gb_audio_apbridgea_stop_rx(struct gb_connection *connection,
275 extern int gb_audio_apbridgea_shutdown_rx(struct gb_connection *connection,
278 #endif /* __LINUX_GBAUDIO_CODEC_H */