greybus: audio: Remove un-necessary goto statement
[cascardo/linux.git] / drivers / staging / greybus / audio_codec.h
1 /*
2  * Greybus audio driver
3  * Copyright 2015 Google Inc.
4  * Copyright 2015 Linaro Ltd.
5  *
6  * Released under the GPLv2 only.
7  */
8
9 #ifndef __LINUX_GBAUDIO_CODEC_H
10 #define __LINUX_GBAUDIO_CODEC_H
11
12 #include <sound/soc.h>
13 #include <sound/jack.h>
14
15 #include "greybus.h"
16 #include "greybus_protocols.h"
17
18 #define NAME_SIZE       32
19 #define MAX_DAIS        2       /* APB1, APB2 */
20
21 enum {
22         APB1_PCM = 0,
23         APB2_PCM,
24         NUM_CODEC_DAIS,
25 };
26
27 enum gbcodec_reg_index {
28         GBCODEC_CTL_REG,
29         GBCODEC_MUTE_REG,
30         GBCODEC_PB_LVOL_REG,
31         GBCODEC_PB_RVOL_REG,
32         GBCODEC_CAP_LVOL_REG,
33         GBCODEC_CAP_RVOL_REG,
34         GBCODEC_APB1_MUX_REG,
35         GBCODEC_APB2_MUX_REG,
36         GBCODEC_REG_COUNT
37 };
38
39 /* device_type should be same as defined in audio.h (Android media layer) */
40 enum {
41         GBAUDIO_DEVICE_NONE                     = 0x0,
42         /* reserved bits */
43         GBAUDIO_DEVICE_BIT_IN                   = 0x80000000,
44         GBAUDIO_DEVICE_BIT_DEFAULT              = 0x40000000,
45         /* output devices */
46         GBAUDIO_DEVICE_OUT_SPEAKER              = 0x2,
47         GBAUDIO_DEVICE_OUT_WIRED_HEADSET        = 0x4,
48         GBAUDIO_DEVICE_OUT_WIRED_HEADPHONE      = 0x8,
49         /* input devices */
50         GBAUDIO_DEVICE_IN_BUILTIN_MIC           = GBAUDIO_DEVICE_BIT_IN | 0x4,
51         GBAUDIO_DEVICE_IN_WIRED_HEADSET         = GBAUDIO_DEVICE_BIT_IN | 0x10,
52 };
53
54 /* bit 0-SPK, 1-HP, 2-DAC,
55  * 4-MIC, 5-HSMIC, 6-MIC2
56  */
57 #define GBCODEC_CTL_REG_DEFAULT         0x00
58
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
63  */
64 #define GBCODEC_MUTE_REG_DEFAULT        0x00
65
66 /* 0-127 steps */
67 #define GBCODEC_PB_VOL_REG_DEFAULT      0x00
68 #define GBCODEC_CAP_VOL_REG_DEFAULT     0x00
69
70 /* bit 0,1,2 - PB stereo, left, right
71  * bit 8,9,10 - Cap stereo, left, right
72  */
73 #define GBCODEC_APB1_MUX_REG_DEFAULT    0x00
74 #define GBCODEC_APB2_MUX_REG_DEFAULT    0x00
75
76 #define GBCODEC_JACK_MASK (SND_JACK_HEADSET | SND_JACK_LINEOUT | \
77                            SND_JACK_LINEIN | SND_JACK_UNSUPPORTED)
78 #define GBCODEC_JACK_BUTTON_MASK (SND_JACK_BTN_0 | SND_JACK_BTN_1 | \
79                                   SND_JACK_BTN_2 | SND_JACK_BTN_3)
80
81 static const u8 gbcodec_reg_defaults[GBCODEC_REG_COUNT] = {
82         GBCODEC_CTL_REG_DEFAULT,
83         GBCODEC_MUTE_REG_DEFAULT,
84         GBCODEC_PB_VOL_REG_DEFAULT,
85         GBCODEC_PB_VOL_REG_DEFAULT,
86         GBCODEC_CAP_VOL_REG_DEFAULT,
87         GBCODEC_CAP_VOL_REG_DEFAULT,
88         GBCODEC_APB1_MUX_REG_DEFAULT,
89         GBCODEC_APB2_MUX_REG_DEFAULT,
90 };
91
92 enum gbaudio_codec_state {
93         GBAUDIO_CODEC_SHUTDOWN = 0,
94         GBAUDIO_CODEC_STARTUP,
95         GBAUDIO_CODEC_HWPARAMS,
96         GBAUDIO_CODEC_PREPARE,
97         GBAUDIO_CODEC_START,
98         GBAUDIO_CODEC_STOP,
99 };
100
101 struct gbaudio_stream {
102         const char *dai_name;
103         int state;
104         uint8_t sig_bits, channels;
105         uint32_t format, rate;
106 };
107
108 struct gbaudio_codec_info {
109         struct device *dev;
110         struct snd_soc_codec *codec;
111         struct list_head module_list;
112         struct gbaudio_stream stream[2];        /* PB/CAP */
113         struct mutex lock;
114         u8 reg[GBCODEC_REG_COUNT];
115 };
116
117 struct gbaudio_widget {
118         __u8 id;
119         const char *name;
120         struct list_head list;
121 };
122
123 struct gbaudio_control {
124         __u8 id;
125         char *name;
126         char *wname;
127         const char * const *texts;
128         struct list_head list;
129 };
130
131 struct gbaudio_data_connection {
132         __le16 data_cport;
133         int cport_configured;
134         char name[NAME_SIZE];
135         struct gb_connection *connection;
136         struct list_head list;
137 };
138
139 /* stream direction */
140 #define GB_PLAYBACK     BIT(0)
141 #define GB_CAPTURE      BIT(1)
142
143 enum gbaudio_module_state {
144         GBAUDIO_MODULE_OFF = 0,
145         GBAUDIO_MODULE_ON,
146 };
147
148 struct gbaudio_module_info {
149         /* module info */
150         struct device *dev;
151         int dev_id;     /* check if it should be bundle_id/hd_cport_id */
152         int vid;
153         int pid;
154         int slot;
155         int type;
156         int set_uevent;
157         char vstr[NAME_SIZE];
158         char pstr[NAME_SIZE];
159         struct list_head list;
160         /* need to share this info to above user space */
161         int manager_id;
162         char name[NAME_SIZE];
163         unsigned int ip_devices;
164         unsigned int op_devices;
165
166         /* jack related */
167         char jack_name[NAME_SIZE];
168         char button_name[NAME_SIZE];
169         int num_jacks;
170         int jack_type;
171         int button_status;
172         struct snd_soc_jack headset_jack;
173         struct snd_soc_jack button_jack;
174
175         /* used by codec_ops */
176         int ctrlstate[2];       /* PB/CAP */
177
178         /* connection info */
179         struct gb_connection *mgmt_connection;
180         size_t num_data_connections;
181         struct list_head data_list;
182
183         /* topology related */
184         int num_dais;
185         int num_controls;
186         int num_dapm_widgets;
187         int num_dapm_routes;
188         unsigned long dai_offset;
189         unsigned long widget_offset;
190         unsigned long control_offset;
191         unsigned long route_offset;
192         struct snd_kcontrol_new *controls;
193         struct snd_soc_dapm_widget *dapm_widgets;
194         struct snd_soc_dapm_route *dapm_routes;
195         struct snd_soc_dai_driver *dais;
196
197         struct list_head widget_list;
198         struct list_head ctl_list;
199         struct list_head widget_ctl_list;
200
201         struct gb_audio_topology *topology;
202 };
203
204 int gbaudio_tplg_parse_data(struct gbaudio_module_info *module,
205                                struct gb_audio_topology *tplg_data);
206 void gbaudio_tplg_release(struct gbaudio_module_info *module);
207
208 int gbaudio_module_update(struct gbaudio_codec_info *codec,
209                                  const char *w_name,
210                                  struct gbaudio_module_info *module,
211                                  int enable);
212 int gbaudio_register_module(struct gbaudio_module_info *module);
213 void gbaudio_unregister_module(struct gbaudio_module_info *module);
214
215 /* protocol related */
216 extern int gb_audio_gb_get_topology(struct gb_connection *connection,
217                                     struct gb_audio_topology **topology);
218 extern int gb_audio_gb_get_control(struct gb_connection *connection,
219                                    uint8_t control_id, uint8_t index,
220                                    struct gb_audio_ctl_elem_value *value);
221 extern int gb_audio_gb_set_control(struct gb_connection *connection,
222                                    uint8_t control_id, uint8_t index,
223                                    struct gb_audio_ctl_elem_value *value);
224 extern int gb_audio_gb_enable_widget(struct gb_connection *connection,
225                                      uint8_t widget_id);
226 extern int gb_audio_gb_disable_widget(struct gb_connection *connection,
227                                       uint8_t widget_id);
228 extern int gb_audio_gb_get_pcm(struct gb_connection *connection,
229                                uint16_t data_cport, uint32_t *format,
230                                uint32_t *rate, uint8_t *channels,
231                                uint8_t *sig_bits);
232 extern int gb_audio_gb_set_pcm(struct gb_connection *connection,
233                                uint16_t data_cport, uint32_t format,
234                                uint32_t rate, uint8_t channels,
235                                uint8_t sig_bits);
236 extern int gb_audio_gb_set_tx_data_size(struct gb_connection *connection,
237                                         uint16_t data_cport, uint16_t size);
238 extern int gb_audio_gb_activate_tx(struct gb_connection *connection,
239                                    uint16_t data_cport);
240 extern int gb_audio_gb_deactivate_tx(struct gb_connection *connection,
241                                      uint16_t data_cport);
242 extern int gb_audio_gb_set_rx_data_size(struct gb_connection *connection,
243                                         uint16_t data_cport, uint16_t size);
244 extern int gb_audio_gb_activate_rx(struct gb_connection *connection,
245                                    uint16_t data_cport);
246 extern int gb_audio_gb_deactivate_rx(struct gb_connection *connection,
247                                      uint16_t data_cport);
248 extern int gb_audio_apbridgea_set_config(struct gb_connection *connection,
249                                          __u16 i2s_port, __u32 format,
250                                          __u32 rate, __u32 mclk_freq);
251 extern int gb_audio_apbridgea_register_cport(struct gb_connection *connection,
252                                              __u16 i2s_port, __u16 cportid,
253                                              __u8 direction);
254 extern int gb_audio_apbridgea_unregister_cport(struct gb_connection *connection,
255                                                __u16 i2s_port, __u16 cportid,
256                                                __u8 direction);
257 extern int gb_audio_apbridgea_set_tx_data_size(struct gb_connection *connection,
258                                                __u16 i2s_port, __u16 size);
259 extern int gb_audio_apbridgea_prepare_tx(struct gb_connection *connection,
260                                          __u16 i2s_port);
261 extern int gb_audio_apbridgea_start_tx(struct gb_connection *connection,
262                                        __u16 i2s_port, __u64 timestamp);
263 extern int gb_audio_apbridgea_stop_tx(struct gb_connection *connection,
264                                       __u16 i2s_port);
265 extern int gb_audio_apbridgea_shutdown_tx(struct gb_connection *connection,
266                                           __u16 i2s_port);
267 extern int gb_audio_apbridgea_set_rx_data_size(struct gb_connection *connection,
268                                                __u16 i2s_port, __u16 size);
269 extern int gb_audio_apbridgea_prepare_rx(struct gb_connection *connection,
270                                          __u16 i2s_port);
271 extern int gb_audio_apbridgea_start_rx(struct gb_connection *connection,
272                                        __u16 i2s_port);
273 extern int gb_audio_apbridgea_stop_rx(struct gb_connection *connection,
274                                       __u16 i2s_port);
275 extern int gb_audio_apbridgea_shutdown_rx(struct gb_connection *connection,
276                                           __u16 i2s_port);
277
278 #endif /* __LINUX_GBAUDIO_CODEC_H */