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 0x0000FFFF
77 #define GBCODEC_JACK_BUTTON_MASK 0xFFFF0000
79 static 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,
90 enum gbaudio_codec_state {
91 GBAUDIO_CODEC_SHUTDOWN = 0,
92 GBAUDIO_CODEC_STARTUP,
93 GBAUDIO_CODEC_HWPARAMS,
94 GBAUDIO_CODEC_PREPARE,
99 struct gbaudio_stream_params {
101 u8 sig_bits, channels;
102 uint32_t format, rate;
105 struct gbaudio_codec_dai {
107 /* runtime params for playback/capture streams */
108 struct gbaudio_stream_params params[2];
109 struct list_head list;
112 struct gbaudio_codec_info {
114 struct snd_soc_codec *codec;
115 struct list_head module_list;
116 /* to maintain runtime stream params for each DAI */
117 struct list_head dai_list;
119 u8 reg[GBCODEC_REG_COUNT];
122 struct gbaudio_widget {
125 struct list_head list;
128 struct gbaudio_control {
132 const char * const *texts;
134 struct list_head list;
137 struct gbaudio_data_connection {
140 struct gb_connection *connection;
141 struct list_head list;
142 /* maintain runtime state for playback/capture stream */
146 /* stream direction */
147 #define GB_PLAYBACK BIT(0)
148 #define GB_CAPTURE BIT(1)
150 enum gbaudio_module_state {
151 GBAUDIO_MODULE_OFF = 0,
155 struct gbaudio_module_info {
158 int dev_id; /* check if it should be bundle_id/hd_cport_id */
164 char vstr[NAME_SIZE];
165 char pstr[NAME_SIZE];
166 struct list_head list;
167 /* need to share this info to above user space */
169 char name[NAME_SIZE];
170 unsigned int ip_devices;
171 unsigned int op_devices;
174 char jack_name[NAME_SIZE];
175 char button_name[NAME_SIZE];
180 struct snd_soc_jack headset_jack;
181 struct snd_soc_jack button_jack;
183 /* connection info */
184 struct gb_connection *mgmt_connection;
185 size_t num_data_connections;
186 struct list_head data_list;
188 /* topology related */
191 int num_dapm_widgets;
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;
202 struct list_head widget_list;
203 struct list_head ctl_list;
204 struct list_head widget_ctl_list;
206 struct gb_audio_topology *topology;
209 int gbaudio_tplg_parse_data(struct gbaudio_module_info *module,
210 struct gb_audio_topology *tplg_data);
211 void gbaudio_tplg_release(struct gbaudio_module_info *module);
213 int gbaudio_module_update(struct gbaudio_codec_info *codec,
214 struct snd_soc_dapm_widget *w,
215 struct gbaudio_module_info *module,
217 int gbaudio_register_module(struct gbaudio_module_info *module);
218 void gbaudio_unregister_module(struct gbaudio_module_info *module);
220 /* protocol related */
221 extern int gb_audio_gb_get_topology(struct gb_connection *connection,
222 struct gb_audio_topology **topology);
223 extern int gb_audio_gb_get_control(struct gb_connection *connection,
224 u8 control_id, u8 index,
225 struct gb_audio_ctl_elem_value *value);
226 extern int gb_audio_gb_set_control(struct gb_connection *connection,
227 u8 control_id, u8 index,
228 struct gb_audio_ctl_elem_value *value);
229 extern int gb_audio_gb_enable_widget(struct gb_connection *connection,
231 extern int gb_audio_gb_disable_widget(struct gb_connection *connection,
233 extern int gb_audio_gb_get_pcm(struct gb_connection *connection,
234 u16 data_cport, uint32_t *format,
235 uint32_t *rate, u8 *channels,
237 extern int gb_audio_gb_set_pcm(struct gb_connection *connection,
238 u16 data_cport, uint32_t format,
239 uint32_t rate, u8 channels,
241 extern int gb_audio_gb_set_tx_data_size(struct gb_connection *connection,
242 u16 data_cport, u16 size);
243 extern int gb_audio_gb_activate_tx(struct gb_connection *connection,
245 extern int gb_audio_gb_deactivate_tx(struct gb_connection *connection,
247 extern int gb_audio_gb_set_rx_data_size(struct gb_connection *connection,
248 u16 data_cport, u16 size);
249 extern int gb_audio_gb_activate_rx(struct gb_connection *connection,
251 extern int gb_audio_gb_deactivate_rx(struct gb_connection *connection,
253 extern int gb_audio_apbridgea_set_config(struct gb_connection *connection,
254 __u16 i2s_port, __u32 format,
255 __u32 rate, __u32 mclk_freq);
256 extern int gb_audio_apbridgea_register_cport(struct gb_connection *connection,
257 __u16 i2s_port, __u16 cportid,
259 extern int gb_audio_apbridgea_unregister_cport(struct gb_connection *connection,
260 __u16 i2s_port, __u16 cportid,
262 extern int gb_audio_apbridgea_set_tx_data_size(struct gb_connection *connection,
263 __u16 i2s_port, __u16 size);
264 extern int gb_audio_apbridgea_prepare_tx(struct gb_connection *connection,
266 extern int gb_audio_apbridgea_start_tx(struct gb_connection *connection,
267 __u16 i2s_port, __u64 timestamp);
268 extern int gb_audio_apbridgea_stop_tx(struct gb_connection *connection,
270 extern int gb_audio_apbridgea_shutdown_tx(struct gb_connection *connection,
272 extern int gb_audio_apbridgea_set_rx_data_size(struct gb_connection *connection,
273 __u16 i2s_port, __u16 size);
274 extern int gb_audio_apbridgea_prepare_rx(struct gb_connection *connection,
276 extern int gb_audio_apbridgea_start_rx(struct gb_connection *connection,
278 extern int gb_audio_apbridgea_stop_rx(struct gb_connection *connection,
280 extern int gb_audio_apbridgea_shutdown_rx(struct gb_connection *connection,
283 #endif /* __LINUX_GBAUDIO_CODEC_H */