]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/greybus/audio_codec.h
greybus: audio: use variable 'is_connected' to maintain module state
[karo-tx-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
14 #include "greybus.h"
15 #include "greybus_protocols.h"
16
17 #define NAME_SIZE       32
18 #define MAX_DAIS        2       /* APB1, APB2 */
19
20 enum {
21         APB1_PCM = 0,
22         APB2_PCM,
23         NUM_CODEC_DAIS,
24 };
25
26 enum gbcodec_reg_index {
27         GBCODEC_CTL_REG,
28         GBCODEC_MUTE_REG,
29         GBCODEC_PB_LVOL_REG,
30         GBCODEC_PB_RVOL_REG,
31         GBCODEC_CAP_LVOL_REG,
32         GBCODEC_CAP_RVOL_REG,
33         GBCODEC_APB1_MUX_REG,
34         GBCODEC_APB2_MUX_REG,
35         GBCODEC_REG_COUNT
36 };
37
38 /* bit 0-SPK, 1-HP, 2-DAC,
39  * 4-MIC, 5-HSMIC, 6-MIC2
40  */
41 #define GBCODEC_CTL_REG_DEFAULT         0x00
42
43 /* bit 0,1 - APB1-PB-L/R
44  * bit 2,3 - APB2-PB-L/R
45  * bit 4,5 - APB1-Cap-L/R
46  * bit 6,7 - APB2-Cap-L/R
47  */
48 #define GBCODEC_MUTE_REG_DEFAULT        0x00
49
50 /* 0-127 steps */
51 #define GBCODEC_PB_VOL_REG_DEFAULT      0x00
52 #define GBCODEC_CAP_VOL_REG_DEFAULT     0x00
53
54 /* bit 0,1,2 - PB stereo, left, right
55  * bit 8,9,10 - Cap stereo, left, right
56  */
57 #define GBCODEC_APB1_MUX_REG_DEFAULT    0x00
58 #define GBCODEC_APB2_MUX_REG_DEFAULT    0x00
59
60 static const u8 gbcodec_reg_defaults[GBCODEC_REG_COUNT] = {
61         GBCODEC_CTL_REG_DEFAULT,
62         GBCODEC_MUTE_REG_DEFAULT,
63         GBCODEC_PB_VOL_REG_DEFAULT,
64         GBCODEC_PB_VOL_REG_DEFAULT,
65         GBCODEC_CAP_VOL_REG_DEFAULT,
66         GBCODEC_CAP_VOL_REG_DEFAULT,
67         GBCODEC_APB1_MUX_REG_DEFAULT,
68         GBCODEC_APB2_MUX_REG_DEFAULT,
69 };
70
71 struct gbaudio_widget {
72         __u8 id;
73         const char *name;
74         struct list_head list;
75 };
76
77 struct gbaudio_control {
78         __u8 id;
79         char *name;
80         const char * const *texts;
81         struct list_head list;
82 };
83
84 struct gbaudio_dai {
85         __le16 data_cport;
86         char name[NAME_SIZE];
87         /* DAI users */
88         atomic_t users;
89         struct gb_connection *connection;
90         struct list_head list;
91 };
92
93 struct gbaudio_codec_info {
94         /* module info */
95         int dev_id;     /* check if it should be bundle_id/hd_cport_id */
96         int vid;
97         int pid;
98         int slot;
99         int type;
100         int dai_added;
101         int codec_registered;
102         int set_uevent;
103         char vstr[NAME_SIZE];
104         char pstr[NAME_SIZE];
105         struct list_head list;
106         struct gb_audio_topology *topology;
107         /* need to share this info to above user space */
108         int manager_id;
109         char name[NAME_SIZE];
110
111         /*
112          * there can be a rece condition between gb_audio_disconnect()
113          * and dai->trigger from above ASoC layer.
114          * To avoid any deadlock over codec_info->lock, atomic variable
115          * is used.
116          */
117         atomic_t is_connected;
118         struct mutex lock;
119
120         /* soc related data */
121         struct snd_soc_codec *codec;
122         struct device *dev;
123         u8 reg[GBCODEC_REG_COUNT];
124
125         /* dai_link related */
126         char card_name[NAME_SIZE];
127         char *dailink_name[MAX_DAIS];
128         int num_dai_links;
129
130         struct gb_connection *mgmt_connection;
131         size_t num_data_connections;
132         /* topology related */
133         int num_dais;
134         int num_kcontrols;
135         int num_dapm_widgets;
136         int num_dapm_routes;
137         unsigned long dai_offset;
138         unsigned long widget_offset;
139         unsigned long control_offset;
140         unsigned long route_offset;
141         struct snd_kcontrol_new *kctls;
142         struct snd_soc_dapm_widget *widgets;
143         struct snd_soc_dapm_route *routes;
144         struct snd_soc_dai_driver *dais;
145
146         /* lists */
147         struct list_head dai_list;
148         struct list_head widget_list;
149         struct list_head codec_ctl_list;
150         struct list_head widget_ctl_list;
151 };
152
153 struct gbaudio_dai *gbaudio_find_dai(struct gbaudio_codec_info *gbcodec,
154                                      int data_cport, const char *name);
155 int gbaudio_tplg_parse_data(struct gbaudio_codec_info *gbcodec,
156                                struct gb_audio_topology *tplg_data);
157 void gbaudio_tplg_release(struct gbaudio_codec_info *gbcodec);
158
159 /* protocol related */
160 extern int gb_audio_gb_get_topology(struct gb_connection *connection,
161                                     struct gb_audio_topology **topology);
162 extern int gb_audio_gb_get_control(struct gb_connection *connection,
163                                    uint8_t control_id, uint8_t index,
164                                    struct gb_audio_ctl_elem_value *value);
165 extern int gb_audio_gb_set_control(struct gb_connection *connection,
166                                    uint8_t control_id, uint8_t index,
167                                    struct gb_audio_ctl_elem_value *value);
168 extern int gb_audio_gb_enable_widget(struct gb_connection *connection,
169                                      uint8_t widget_id);
170 extern int gb_audio_gb_disable_widget(struct gb_connection *connection,
171                                       uint8_t widget_id);
172 extern int gb_audio_gb_get_pcm(struct gb_connection *connection,
173                                uint16_t data_cport, uint32_t *format,
174                                uint32_t *rate, uint8_t *channels,
175                                uint8_t *sig_bits);
176 extern int gb_audio_gb_set_pcm(struct gb_connection *connection,
177                                uint16_t data_cport, uint32_t format,
178                                uint32_t rate, uint8_t channels,
179                                uint8_t sig_bits);
180 extern int gb_audio_gb_set_tx_data_size(struct gb_connection *connection,
181                                         uint16_t data_cport, uint16_t size);
182 extern int gb_audio_gb_get_tx_delay(struct gb_connection *connection,
183                                     uint16_t data_cport, uint32_t *delay);
184 extern int gb_audio_gb_activate_tx(struct gb_connection *connection,
185                                    uint16_t data_cport);
186 extern int gb_audio_gb_deactivate_tx(struct gb_connection *connection,
187                                      uint16_t data_cport);
188 extern int gb_audio_gb_set_rx_data_size(struct gb_connection *connection,
189                                         uint16_t data_cport, uint16_t size);
190 extern int gb_audio_gb_get_rx_delay(struct gb_connection *connection,
191                                     uint16_t data_cport, uint32_t *delay);
192 extern int gb_audio_gb_activate_rx(struct gb_connection *connection,
193                                    uint16_t data_cport);
194 extern int gb_audio_gb_deactivate_rx(struct gb_connection *connection,
195                                      uint16_t data_cport);
196 extern int gb_audio_apbridgea_set_config(struct gb_connection *connection,
197                                          __u16 i2s_port, __u32 format,
198                                          __u32 rate, __u32 mclk_freq);
199 extern int gb_audio_apbridgea_register_cport(struct gb_connection *connection,
200                                              __u16 i2s_port, __u16 cportid);
201 extern int gb_audio_apbridgea_unregister_cport(struct gb_connection *connection,
202                                                __u16 i2s_port, __u16 cportid);
203 extern int gb_audio_apbridgea_set_tx_data_size(struct gb_connection *connection,
204                                                __u16 i2s_port, __u16 size);
205 extern int gb_audio_apbridgea_get_tx_delay(struct gb_connection *connection,
206                                            __u16 i2s_port, __u32 *delay);
207 extern int gb_audio_apbridgea_start_tx(struct gb_connection *connection,
208                                        __u16 i2s_port, __u64 timestamp);
209 extern int gb_audio_apbridgea_stop_tx(struct gb_connection *connection,
210                                       __u16 i2s_port);
211 extern int gb_audio_apbridgea_set_rx_data_size(struct gb_connection *connection,
212                                                __u16 i2s_port, __u16 size);
213 extern int gb_audio_apbridgea_get_rx_delay(struct gb_connection *connection,
214                                            __u16 i2s_port, __u32 *delay);
215 extern int gb_audio_apbridgea_start_rx(struct gb_connection *connection,
216                                        __u16 i2s_port);
217 extern int gb_audio_apbridgea_stop_rx(struct gb_connection *connection,
218                                       __u16 i2s_port);
219
220 #endif /* __LINUX_GBAUDIO_CODEC_H */