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 /* device_type should be same as defined in audio.h (Android media layer) */
29 GBAUDIO_DEVICE_NONE = 0x0,
31 GBAUDIO_DEVICE_BIT_IN = 0x80000000,
32 GBAUDIO_DEVICE_BIT_DEFAULT = 0x40000000,
34 GBAUDIO_DEVICE_OUT_SPEAKER = 0x2,
35 GBAUDIO_DEVICE_OUT_WIRED_HEADSET = 0x4,
36 GBAUDIO_DEVICE_OUT_WIRED_HEADPHONE = 0x8,
38 GBAUDIO_DEVICE_IN_BUILTIN_MIC = GBAUDIO_DEVICE_BIT_IN | 0x4,
39 GBAUDIO_DEVICE_IN_WIRED_HEADSET = GBAUDIO_DEVICE_BIT_IN | 0x10,
42 #define GBCODEC_JACK_MASK 0x0000FFFF
43 #define GBCODEC_JACK_BUTTON_MASK 0xFFFF0000
45 enum gbaudio_codec_state {
46 GBAUDIO_CODEC_SHUTDOWN = 0,
47 GBAUDIO_CODEC_STARTUP,
48 GBAUDIO_CODEC_HWPARAMS,
49 GBAUDIO_CODEC_PREPARE,
54 struct gbaudio_stream_params {
56 u8 sig_bits, channels;
57 uint32_t format, rate;
60 struct gbaudio_codec_dai {
62 /* runtime params for playback/capture streams */
63 struct gbaudio_stream_params params[2];
64 struct list_head list;
67 struct gbaudio_codec_info {
69 struct snd_soc_codec *codec;
70 struct list_head module_list;
71 /* to maintain runtime stream params for each DAI */
72 struct list_head dai_list;
76 struct gbaudio_widget {
79 struct list_head list;
82 struct gbaudio_control {
86 const char * const *texts;
88 struct list_head list;
91 struct gbaudio_data_connection {
94 struct gb_connection *connection;
95 struct list_head list;
96 /* maintain runtime state for playback/capture stream */
100 /* stream direction */
101 #define GB_PLAYBACK BIT(0)
102 #define GB_CAPTURE BIT(1)
104 enum gbaudio_module_state {
105 GBAUDIO_MODULE_OFF = 0,
109 struct gbaudio_module_info {
112 int dev_id; /* check if it should be bundle_id/hd_cport_id */
117 char vstr[NAME_SIZE];
118 char pstr[NAME_SIZE];
119 struct list_head list;
120 /* need to share this info to above user space */
122 char name[NAME_SIZE];
123 unsigned int ip_devices;
124 unsigned int op_devices;
127 char jack_name[NAME_SIZE];
128 char button_name[NAME_SIZE];
133 struct snd_soc_jack headset_jack;
134 struct snd_soc_jack button_jack;
136 /* connection info */
137 struct gb_connection *mgmt_connection;
138 size_t num_data_connections;
139 struct list_head data_list;
141 /* topology related */
144 int num_dapm_widgets;
146 unsigned long dai_offset;
147 unsigned long widget_offset;
148 unsigned long control_offset;
149 unsigned long route_offset;
150 struct snd_kcontrol_new *controls;
151 struct snd_soc_dapm_widget *dapm_widgets;
152 struct snd_soc_dapm_route *dapm_routes;
153 struct snd_soc_dai_driver *dais;
155 struct list_head widget_list;
156 struct list_head ctl_list;
157 struct list_head widget_ctl_list;
159 struct gb_audio_topology *topology;
162 int gbaudio_tplg_parse_data(struct gbaudio_module_info *module,
163 struct gb_audio_topology *tplg_data);
164 void gbaudio_tplg_release(struct gbaudio_module_info *module);
166 int gbaudio_module_update(struct gbaudio_codec_info *codec,
167 struct snd_soc_dapm_widget *w,
168 struct gbaudio_module_info *module,
170 int gbaudio_register_module(struct gbaudio_module_info *module);
171 void gbaudio_unregister_module(struct gbaudio_module_info *module);
173 /* protocol related */
174 extern int gb_audio_gb_get_topology(struct gb_connection *connection,
175 struct gb_audio_topology **topology);
176 extern int gb_audio_gb_get_control(struct gb_connection *connection,
177 u8 control_id, u8 index,
178 struct gb_audio_ctl_elem_value *value);
179 extern int gb_audio_gb_set_control(struct gb_connection *connection,
180 u8 control_id, u8 index,
181 struct gb_audio_ctl_elem_value *value);
182 extern int gb_audio_gb_enable_widget(struct gb_connection *connection,
184 extern int gb_audio_gb_disable_widget(struct gb_connection *connection,
186 extern int gb_audio_gb_get_pcm(struct gb_connection *connection,
187 u16 data_cport, uint32_t *format,
188 uint32_t *rate, u8 *channels,
190 extern int gb_audio_gb_set_pcm(struct gb_connection *connection,
191 u16 data_cport, uint32_t format,
192 uint32_t rate, u8 channels,
194 extern int gb_audio_gb_set_tx_data_size(struct gb_connection *connection,
195 u16 data_cport, u16 size);
196 extern int gb_audio_gb_activate_tx(struct gb_connection *connection,
198 extern int gb_audio_gb_deactivate_tx(struct gb_connection *connection,
200 extern int gb_audio_gb_set_rx_data_size(struct gb_connection *connection,
201 u16 data_cport, u16 size);
202 extern int gb_audio_gb_activate_rx(struct gb_connection *connection,
204 extern int gb_audio_gb_deactivate_rx(struct gb_connection *connection,
206 extern int gb_audio_apbridgea_set_config(struct gb_connection *connection,
207 __u16 i2s_port, __u32 format,
208 __u32 rate, __u32 mclk_freq);
209 extern int gb_audio_apbridgea_register_cport(struct gb_connection *connection,
210 __u16 i2s_port, __u16 cportid,
212 extern int gb_audio_apbridgea_unregister_cport(struct gb_connection *connection,
213 __u16 i2s_port, __u16 cportid,
215 extern int gb_audio_apbridgea_set_tx_data_size(struct gb_connection *connection,
216 __u16 i2s_port, __u16 size);
217 extern int gb_audio_apbridgea_prepare_tx(struct gb_connection *connection,
219 extern int gb_audio_apbridgea_start_tx(struct gb_connection *connection,
220 __u16 i2s_port, __u64 timestamp);
221 extern int gb_audio_apbridgea_stop_tx(struct gb_connection *connection,
223 extern int gb_audio_apbridgea_shutdown_tx(struct gb_connection *connection,
225 extern int gb_audio_apbridgea_set_rx_data_size(struct gb_connection *connection,
226 __u16 i2s_port, __u16 size);
227 extern int gb_audio_apbridgea_prepare_rx(struct gb_connection *connection,
229 extern int gb_audio_apbridgea_start_rx(struct gb_connection *connection,
231 extern int gb_audio_apbridgea_stop_rx(struct gb_connection *connection,
233 extern int gb_audio_apbridgea_shutdown_rx(struct gb_connection *connection,
236 #endif /* __LINUX_GBAUDIO_CODEC_H */