1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright 2015 Google Inc.
5 * Copyright 2015 Linaro Ltd.
8 #ifndef __LINUX_GBAUDIO_CODEC_H
9 #define __LINUX_GBAUDIO_CODEC_H
11 #include <sound/soc.h>
12 #include <sound/jack.h>
15 #include "greybus_protocols.h"
18 #define MAX_DAIS 2 /* APB1, APB2 */
27 * device_type should be same as defined in audio.h
28 * (Android media layer)
31 GBAUDIO_DEVICE_NONE = 0x0,
33 GBAUDIO_DEVICE_BIT_IN = 0x80000000,
34 GBAUDIO_DEVICE_BIT_DEFAULT = 0x40000000,
36 GBAUDIO_DEVICE_OUT_SPEAKER = 0x2,
37 GBAUDIO_DEVICE_OUT_WIRED_HEADSET = 0x4,
38 GBAUDIO_DEVICE_OUT_WIRED_HEADPHONE = 0x8,
40 GBAUDIO_DEVICE_IN_BUILTIN_MIC = GBAUDIO_DEVICE_BIT_IN | 0x4,
41 GBAUDIO_DEVICE_IN_WIRED_HEADSET = GBAUDIO_DEVICE_BIT_IN | 0x10,
44 #define GBCODEC_JACK_MASK 0x0000FFFF
45 #define GBCODEC_JACK_BUTTON_MASK 0xFFFF0000
47 enum gbaudio_codec_state {
48 GBAUDIO_CODEC_SHUTDOWN = 0,
49 GBAUDIO_CODEC_STARTUP,
50 GBAUDIO_CODEC_HWPARAMS,
51 GBAUDIO_CODEC_PREPARE,
56 struct gbaudio_stream_params {
58 u8 sig_bits, channels;
62 struct gbaudio_codec_dai {
64 /* runtime params for playback/capture streams */
65 struct gbaudio_stream_params params[2];
66 struct list_head list;
69 struct gbaudio_codec_info {
71 struct snd_soc_codec *codec;
72 struct list_head module_list;
73 /* to maintain runtime stream params for each DAI */
74 struct list_head dai_list;
78 struct gbaudio_widget {
81 struct list_head list;
84 struct gbaudio_control {
88 const char * const *texts;
90 struct list_head list;
93 struct gbaudio_data_connection {
96 struct gb_connection *connection;
97 struct list_head list;
98 /* maintain runtime state for playback/capture stream */
102 /* stream direction */
103 #define GB_PLAYBACK BIT(0)
104 #define GB_CAPTURE BIT(1)
106 enum gbaudio_module_state {
107 GBAUDIO_MODULE_OFF = 0,
111 struct gbaudio_module_info {
114 int dev_id; /* check if it should be bundle_id/hd_cport_id */
119 char vstr[NAME_SIZE];
120 char pstr[NAME_SIZE];
121 struct list_head list;
122 /* need to share this info to above user space */
124 char name[NAME_SIZE];
125 unsigned int ip_devices;
126 unsigned int op_devices;
129 char jack_name[NAME_SIZE];
130 char button_name[NAME_SIZE];
135 struct snd_soc_jack headset_jack;
136 struct snd_soc_jack button_jack;
138 /* connection info */
139 struct gb_connection *mgmt_connection;
140 size_t num_data_connections;
141 struct list_head data_list;
143 /* topology related */
146 int num_dapm_widgets;
148 unsigned long dai_offset;
149 unsigned long widget_offset;
150 unsigned long control_offset;
151 unsigned long route_offset;
152 struct snd_kcontrol_new *controls;
153 struct snd_soc_dapm_widget *dapm_widgets;
154 struct snd_soc_dapm_route *dapm_routes;
155 struct snd_soc_dai_driver *dais;
157 struct list_head widget_list;
158 struct list_head ctl_list;
159 struct list_head widget_ctl_list;
161 struct gb_audio_topology *topology;
164 int gbaudio_tplg_parse_data(struct gbaudio_module_info *module,
165 struct gb_audio_topology *tplg_data);
166 void gbaudio_tplg_release(struct gbaudio_module_info *module);
168 int gbaudio_module_update(struct gbaudio_codec_info *codec,
169 struct snd_soc_dapm_widget *w,
170 struct gbaudio_module_info *module,
172 int gbaudio_register_module(struct gbaudio_module_info *module);
173 void gbaudio_unregister_module(struct gbaudio_module_info *module);
175 /* protocol related */
176 extern int gb_audio_gb_get_topology(struct gb_connection *connection,
177 struct gb_audio_topology **topology);
178 extern int gb_audio_gb_get_control(struct gb_connection *connection,
179 u8 control_id, u8 index,
180 struct gb_audio_ctl_elem_value *value);
181 extern int gb_audio_gb_set_control(struct gb_connection *connection,
182 u8 control_id, u8 index,
183 struct gb_audio_ctl_elem_value *value);
184 extern int gb_audio_gb_enable_widget(struct gb_connection *connection,
186 extern int gb_audio_gb_disable_widget(struct gb_connection *connection,
188 extern int gb_audio_gb_get_pcm(struct gb_connection *connection,
189 u16 data_cport, u32 *format,
190 u32 *rate, u8 *channels,
192 extern int gb_audio_gb_set_pcm(struct gb_connection *connection,
193 u16 data_cport, u32 format,
194 u32 rate, u8 channels,
196 extern int gb_audio_gb_set_tx_data_size(struct gb_connection *connection,
197 u16 data_cport, u16 size);
198 extern int gb_audio_gb_activate_tx(struct gb_connection *connection,
200 extern int gb_audio_gb_deactivate_tx(struct gb_connection *connection,
202 extern int gb_audio_gb_set_rx_data_size(struct gb_connection *connection,
203 u16 data_cport, u16 size);
204 extern int gb_audio_gb_activate_rx(struct gb_connection *connection,
206 extern int gb_audio_gb_deactivate_rx(struct gb_connection *connection,
208 extern int gb_audio_apbridgea_set_config(struct gb_connection *connection,
209 __u16 i2s_port, __u32 format,
210 __u32 rate, __u32 mclk_freq);
211 extern int gb_audio_apbridgea_register_cport(struct gb_connection *connection,
212 __u16 i2s_port, __u16 cportid,
214 extern int gb_audio_apbridgea_unregister_cport(struct gb_connection *connection,
215 __u16 i2s_port, __u16 cportid,
217 extern int gb_audio_apbridgea_set_tx_data_size(struct gb_connection *connection,
218 __u16 i2s_port, __u16 size);
219 extern int gb_audio_apbridgea_prepare_tx(struct gb_connection *connection,
221 extern int gb_audio_apbridgea_start_tx(struct gb_connection *connection,
222 __u16 i2s_port, __u64 timestamp);
223 extern int gb_audio_apbridgea_stop_tx(struct gb_connection *connection,
225 extern int gb_audio_apbridgea_shutdown_tx(struct gb_connection *connection,
227 extern int gb_audio_apbridgea_set_rx_data_size(struct gb_connection *connection,
228 __u16 i2s_port, __u16 size);
229 extern int gb_audio_apbridgea_prepare_rx(struct gb_connection *connection,
231 extern int gb_audio_apbridgea_start_rx(struct gb_connection *connection,
233 extern int gb_audio_apbridgea_stop_rx(struct gb_connection *connection,
235 extern int gb_audio_apbridgea_shutdown_rx(struct gb_connection *connection,
238 #endif /* __LINUX_GBAUDIO_CODEC_H */