1
2
3
4
5
6
7
8#ifndef __LINUX_GBAUDIO_CODEC_H
9#define __LINUX_GBAUDIO_CODEC_H
10
11#include <linux/greybus.h>
12#include <sound/soc.h>
13#include <sound/jack.h>
14
15#define NAME_SIZE 32
16#define MAX_DAIS 2
17
18enum {
19 APB1_PCM = 0,
20 APB2_PCM,
21 NUM_CODEC_DAIS,
22};
23
24
25
26
27
28enum {
29 GBAUDIO_DEVICE_NONE = 0x0,
30
31 GBAUDIO_DEVICE_BIT_IN = 0x80000000,
32 GBAUDIO_DEVICE_BIT_DEFAULT = 0x40000000,
33
34 GBAUDIO_DEVICE_OUT_SPEAKER = 0x2,
35 GBAUDIO_DEVICE_OUT_WIRED_HEADSET = 0x4,
36 GBAUDIO_DEVICE_OUT_WIRED_HEADPHONE = 0x8,
37
38 GBAUDIO_DEVICE_IN_BUILTIN_MIC = GBAUDIO_DEVICE_BIT_IN | 0x4,
39 GBAUDIO_DEVICE_IN_WIRED_HEADSET = GBAUDIO_DEVICE_BIT_IN | 0x10,
40};
41
42#define GBCODEC_JACK_MASK 0x0000FFFF
43#define GBCODEC_JACK_BUTTON_MASK 0xFFFF0000
44
45enum gbaudio_codec_state {
46 GBAUDIO_CODEC_SHUTDOWN = 0,
47 GBAUDIO_CODEC_STARTUP,
48 GBAUDIO_CODEC_HWPARAMS,
49 GBAUDIO_CODEC_PREPARE,
50 GBAUDIO_CODEC_START,
51 GBAUDIO_CODEC_STOP,
52};
53
54struct gbaudio_stream_params {
55 int state;
56 u8 sig_bits, channels;
57 u32 format, rate;
58};
59
60struct gbaudio_codec_dai {
61 int id;
62
63 struct gbaudio_stream_params params[2];
64 struct list_head list;
65};
66
67struct gbaudio_codec_info {
68 struct device *dev;
69 struct snd_soc_component *component;
70 struct list_head module_list;
71
72 struct list_head dai_list;
73 struct mutex lock;
74};
75
76struct gbaudio_widget {
77 __u8 id;
78 const char *name;
79 struct list_head list;
80};
81
82struct gbaudio_control {
83 __u8 id;
84 char *name;
85 char *wname;
86 const char * const *texts;
87 int items;
88 struct list_head list;
89};
90
91struct gbaudio_data_connection {
92 int id;
93 __le16 data_cport;
94 struct gb_connection *connection;
95 struct list_head list;
96
97 int state[2];
98};
99
100
101#define GB_PLAYBACK BIT(0)
102#define GB_CAPTURE BIT(1)
103
104enum gbaudio_module_state {
105 GBAUDIO_MODULE_OFF = 0,
106 GBAUDIO_MODULE_ON,
107};
108
109struct gbaudio_jack {
110 struct snd_soc_jack jack;
111 struct list_head list;
112};
113
114struct gbaudio_module_info {
115
116 struct device *dev;
117 int dev_id;
118 int vid;
119 int pid;
120 int type;
121 int set_uevent;
122 char vstr[NAME_SIZE];
123 char pstr[NAME_SIZE];
124 struct list_head list;
125
126 int manager_id;
127 char name[NAME_SIZE];
128 unsigned int ip_devices;
129 unsigned int op_devices;
130
131
132 char jack_name[NAME_SIZE];
133 char button_name[NAME_SIZE];
134 int jack_type;
135 int jack_mask;
136 int button_mask;
137 int button_status;
138 struct gbaudio_jack headset;
139 struct gbaudio_jack button;
140
141
142 struct gb_connection *mgmt_connection;
143 size_t num_data_connections;
144 struct list_head data_list;
145
146
147 int num_dais;
148 int num_controls;
149 int num_dapm_widgets;
150 int num_dapm_routes;
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;
159
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;
164
165 struct gb_audio_topology *topology;
166};
167
168int gbaudio_tplg_parse_data(struct gbaudio_module_info *module,
169 struct gb_audio_topology *tplg_data);
170void gbaudio_tplg_release(struct gbaudio_module_info *module);
171
172int gbaudio_module_update(struct gbaudio_codec_info *codec,
173 struct snd_soc_dapm_widget *w,
174 struct gbaudio_module_info *module,
175 int enable);
176int gbaudio_register_module(struct gbaudio_module_info *module);
177void gbaudio_unregister_module(struct gbaudio_module_info *module);
178
179
180int gb_audio_gb_get_topology(struct gb_connection *connection,
181 struct gb_audio_topology **topology);
182int gb_audio_gb_get_control(struct gb_connection *connection,
183 u8 control_id, u8 index,
184 struct gb_audio_ctl_elem_value *value);
185int gb_audio_gb_set_control(struct gb_connection *connection,
186 u8 control_id, u8 index,
187 struct gb_audio_ctl_elem_value *value);
188int gb_audio_gb_enable_widget(struct gb_connection *connection,
189 u8 widget_id);
190int gb_audio_gb_disable_widget(struct gb_connection *connection,
191 u8 widget_id);
192int gb_audio_gb_get_pcm(struct gb_connection *connection,
193 u16 data_cport, u32 *format,
194 u32 *rate, u8 *channels,
195 u8 *sig_bits);
196int gb_audio_gb_set_pcm(struct gb_connection *connection,
197 u16 data_cport, u32 format,
198 u32 rate, u8 channels,
199 u8 sig_bits);
200int gb_audio_gb_set_tx_data_size(struct gb_connection *connection,
201 u16 data_cport, u16 size);
202int gb_audio_gb_activate_tx(struct gb_connection *connection,
203 u16 data_cport);
204int gb_audio_gb_deactivate_tx(struct gb_connection *connection,
205 u16 data_cport);
206int gb_audio_gb_set_rx_data_size(struct gb_connection *connection,
207 u16 data_cport, u16 size);
208int gb_audio_gb_activate_rx(struct gb_connection *connection,
209 u16 data_cport);
210int gb_audio_gb_deactivate_rx(struct gb_connection *connection,
211 u16 data_cport);
212int gb_audio_apbridgea_set_config(struct gb_connection *connection,
213 __u16 i2s_port, __u32 format,
214 __u32 rate, __u32 mclk_freq);
215int gb_audio_apbridgea_register_cport(struct gb_connection *connection,
216 __u16 i2s_port, __u16 cportid,
217 __u8 direction);
218int gb_audio_apbridgea_unregister_cport(struct gb_connection *connection,
219 __u16 i2s_port, __u16 cportid,
220 __u8 direction);
221int gb_audio_apbridgea_set_tx_data_size(struct gb_connection *connection,
222 __u16 i2s_port, __u16 size);
223int gb_audio_apbridgea_prepare_tx(struct gb_connection *connection,
224 __u16 i2s_port);
225int gb_audio_apbridgea_start_tx(struct gb_connection *connection,
226 __u16 i2s_port, __u64 timestamp);
227int gb_audio_apbridgea_stop_tx(struct gb_connection *connection,
228 __u16 i2s_port);
229int gb_audio_apbridgea_shutdown_tx(struct gb_connection *connection,
230 __u16 i2s_port);
231int gb_audio_apbridgea_set_rx_data_size(struct gb_connection *connection,
232 __u16 i2s_port, __u16 size);
233int gb_audio_apbridgea_prepare_rx(struct gb_connection *connection,
234 __u16 i2s_port);
235int gb_audio_apbridgea_start_rx(struct gb_connection *connection,
236 __u16 i2s_port);
237int gb_audio_apbridgea_stop_rx(struct gb_connection *connection,
238 __u16 i2s_port);
239int gb_audio_apbridgea_shutdown_rx(struct gb_connection *connection,
240 __u16 i2s_port);
241
242#endif
243