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 <linux/greybus.h>
12 #include <sound/soc.h>
13 #include <sound/jack.h>
16 #define MAX_DAIS 2 /* APB1, APB2 */
25 * device_type should be same as defined in audio.h
26 * (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;
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_component *component;
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_jack {
110 struct snd_soc_jack jack;
111 struct list_head list;
114 struct gbaudio_module_info {
117 int dev_id; /* check if it should be bundle_id/hd_cport_id */
122 char vstr[NAME_SIZE];
123 char pstr[NAME_SIZE];
124 struct list_head list;
125 /* need to share this info to above user space */
127 char name[NAME_SIZE];
128 unsigned int ip_devices;
129 unsigned int op_devices;
132 char jack_name[NAME_SIZE];
133 char button_name[NAME_SIZE];
138 struct gbaudio_jack headset;
139 struct gbaudio_jack button;
141 /* connection info */
142 struct gb_connection *mgmt_connection;
143 size_t num_data_connections;
144 struct list_head data_list;
146 /* topology related */
149 int num_dapm_widgets;
151 unsigned long dai_offset;
152 unsigned long widget_offset;
153 unsigned long control_offset;
154 unsigned long route_offset;
155 struct snd_kcontrol_new *controls;
156 struct snd_soc_dapm_widget *dapm_widgets;
157 struct snd_soc_dapm_route *dapm_routes;
158 struct snd_soc_dai_driver *dais;
160 struct list_head widget_list;
161 struct list_head ctl_list;
162 struct list_head widget_ctl_list;
163 struct list_head jack_list;
165 struct gb_audio_topology *topology;
168 int gbaudio_tplg_parse_data(struct gbaudio_module_info *module,
169 struct gb_audio_topology *tplg_data);
170 void gbaudio_tplg_release(struct gbaudio_module_info *module);
172 int gbaudio_module_update(struct gbaudio_codec_info *codec,
173 struct snd_soc_dapm_widget *w,
174 struct gbaudio_module_info *module,
176 int gbaudio_register_module(struct gbaudio_module_info *module);
177 void gbaudio_unregister_module(struct gbaudio_module_info *module);
179 /* protocol related */
180 int gb_audio_gb_get_topology(struct gb_connection *connection,
181 struct gb_audio_topology **topology);
182 int gb_audio_gb_get_control(struct gb_connection *connection,
183 u8 control_id, u8 index,
184 struct gb_audio_ctl_elem_value *value);
185 int gb_audio_gb_set_control(struct gb_connection *connection,
186 u8 control_id, u8 index,
187 struct gb_audio_ctl_elem_value *value);
188 int gb_audio_gb_enable_widget(struct gb_connection *connection,
190 int gb_audio_gb_disable_widget(struct gb_connection *connection,
192 int gb_audio_gb_get_pcm(struct gb_connection *connection,
193 u16 data_cport, u32 *format,
194 u32 *rate, u8 *channels,
196 int gb_audio_gb_set_pcm(struct gb_connection *connection,
197 u16 data_cport, u32 format,
198 u32 rate, u8 channels,
200 int gb_audio_gb_set_tx_data_size(struct gb_connection *connection,
201 u16 data_cport, u16 size);
202 int gb_audio_gb_activate_tx(struct gb_connection *connection,
204 int gb_audio_gb_deactivate_tx(struct gb_connection *connection,
206 int gb_audio_gb_set_rx_data_size(struct gb_connection *connection,
207 u16 data_cport, u16 size);
208 int gb_audio_gb_activate_rx(struct gb_connection *connection,
210 int gb_audio_gb_deactivate_rx(struct gb_connection *connection,
212 int gb_audio_apbridgea_set_config(struct gb_connection *connection,
213 __u16 i2s_port, __u32 format,
214 __u32 rate, __u32 mclk_freq);
215 int gb_audio_apbridgea_register_cport(struct gb_connection *connection,
216 __u16 i2s_port, __u16 cportid,
218 int gb_audio_apbridgea_unregister_cport(struct gb_connection *connection,
219 __u16 i2s_port, __u16 cportid,
221 int gb_audio_apbridgea_set_tx_data_size(struct gb_connection *connection,
222 __u16 i2s_port, __u16 size);
223 int gb_audio_apbridgea_prepare_tx(struct gb_connection *connection,
225 int gb_audio_apbridgea_start_tx(struct gb_connection *connection,
226 __u16 i2s_port, __u64 timestamp);
227 int gb_audio_apbridgea_stop_tx(struct gb_connection *connection,
229 int gb_audio_apbridgea_shutdown_tx(struct gb_connection *connection,
231 int gb_audio_apbridgea_set_rx_data_size(struct gb_connection *connection,
232 __u16 i2s_port, __u16 size);
233 int gb_audio_apbridgea_prepare_rx(struct gb_connection *connection,
235 int gb_audio_apbridgea_start_rx(struct gb_connection *connection,
237 int gb_audio_apbridgea_stop_rx(struct gb_connection *connection,
239 int gb_audio_apbridgea_shutdown_rx(struct gb_connection *connection,
242 #endif /* __LINUX_GBAUDIO_CODEC_H */