1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Greybus audio driver 4 * Copyright 2015 Google Inc. 5 * Copyright 2015 Linaro Ltd. 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 /* APB1, APB2 */ 17 18 enum { 19 APB1_PCM = 0, 20 APB2_PCM, 21 NUM_CODEC_DAIS, 22 }; 23 24 /* 25 * device_type should be same as defined in audio.h 26 * (Android media layer) 27 */ 28 enum { 29 GBAUDIO_DEVICE_NONE = 0x0, 30 /* reserved bits */ 31 GBAUDIO_DEVICE_BIT_IN = 0x80000000, 32 GBAUDIO_DEVICE_BIT_DEFAULT = 0x40000000, 33 /* output devices */ 34 GBAUDIO_DEVICE_OUT_SPEAKER = 0x2, 35 GBAUDIO_DEVICE_OUT_WIRED_HEADSET = 0x4, 36 GBAUDIO_DEVICE_OUT_WIRED_HEADPHONE = 0x8, 37 /* input devices */ 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 45 enum 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 54 struct gbaudio_stream_params { 55 int state; 56 u8 sig_bits, channels; 57 u32 format, rate; 58 }; 59 60 struct gbaudio_codec_dai { 61 int id; 62 /* runtime params for playback/capture streams */ 63 struct gbaudio_stream_params params[2]; 64 struct list_head list; 65 }; 66 67 struct gbaudio_codec_info { 68 struct device *dev; 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; 73 struct mutex lock; 74 struct mutex register_mutex; 75 }; 76 77 struct gbaudio_widget { 78 __u8 id; 79 const char *name; 80 struct list_head list; 81 }; 82 83 struct gbaudio_control { 84 __u8 id; 85 char *name; 86 char *wname; 87 const char * const *texts; 88 int items; 89 struct list_head list; 90 }; 91 92 struct gbaudio_data_connection { 93 int id; 94 __le16 data_cport; 95 struct gb_connection *connection; 96 struct list_head list; 97 /* maintain runtime state for playback/capture stream */ 98 int state[2]; 99 }; 100 101 /* stream direction */ 102 #define GB_PLAYBACK BIT(0) 103 #define GB_CAPTURE BIT(1) 104 105 enum gbaudio_module_state { 106 GBAUDIO_MODULE_OFF = 0, 107 GBAUDIO_MODULE_ON, 108 }; 109 110 struct gbaudio_jack { 111 struct snd_soc_jack jack; 112 struct list_head list; 113 }; 114 115 struct gbaudio_module_info { 116 /* module info */ 117 struct device *dev; 118 int dev_id; /* check if it should be bundle_id/hd_cport_id */ 119 int vid; 120 int pid; 121 int type; 122 int set_uevent; 123 char vstr[NAME_SIZE]; 124 char pstr[NAME_SIZE]; 125 struct list_head list; 126 /* need to share this info to above user space */ 127 int manager_id; 128 char name[NAME_SIZE]; 129 unsigned int ip_devices; 130 unsigned int op_devices; 131 132 /* jack related */ 133 char jack_name[NAME_SIZE]; 134 char button_name[NAME_SIZE]; 135 int jack_type; 136 int jack_mask; 137 int button_mask; 138 int button_status; 139 struct gbaudio_jack headset; 140 struct gbaudio_jack button; 141 142 /* connection info */ 143 struct gb_connection *mgmt_connection; 144 size_t num_data_connections; 145 struct list_head data_list; 146 147 /* topology related */ 148 int num_dais; 149 int num_controls; 150 int num_dapm_widgets; 151 int num_dapm_routes; 152 unsigned long dai_offset; 153 unsigned long widget_offset; 154 unsigned long control_offset; 155 unsigned long route_offset; 156 struct snd_kcontrol_new *controls; 157 struct snd_soc_dapm_widget *dapm_widgets; 158 struct snd_soc_dapm_route *dapm_routes; 159 struct snd_soc_dai_driver *dais; 160 161 struct list_head widget_list; 162 struct list_head ctl_list; 163 struct list_head widget_ctl_list; 164 struct list_head jack_list; 165 166 struct gb_audio_topology *topology; 167 }; 168 169 int gbaudio_tplg_parse_data(struct gbaudio_module_info *module, 170 struct gb_audio_topology *tplg_data); 171 void gbaudio_tplg_release(struct gbaudio_module_info *module); 172 173 int gbaudio_module_update(struct gbaudio_codec_info *codec, 174 struct snd_soc_dapm_widget *w, 175 struct gbaudio_module_info *module, 176 int enable); 177 int gbaudio_register_module(struct gbaudio_module_info *module); 178 void gbaudio_unregister_module(struct gbaudio_module_info *module); 179 180 /* protocol related */ 181 int gb_audio_gb_get_topology(struct gb_connection *connection, 182 struct gb_audio_topology **topology); 183 int gb_audio_gb_get_control(struct gb_connection *connection, 184 u8 control_id, u8 index, 185 struct gb_audio_ctl_elem_value *value); 186 int gb_audio_gb_set_control(struct gb_connection *connection, 187 u8 control_id, u8 index, 188 struct gb_audio_ctl_elem_value *value); 189 int gb_audio_gb_enable_widget(struct gb_connection *connection, 190 u8 widget_id); 191 int gb_audio_gb_disable_widget(struct gb_connection *connection, 192 u8 widget_id); 193 int gb_audio_gb_get_pcm(struct gb_connection *connection, 194 u16 data_cport, u32 *format, 195 u32 *rate, u8 *channels, 196 u8 *sig_bits); 197 int gb_audio_gb_set_pcm(struct gb_connection *connection, 198 u16 data_cport, u32 format, 199 u32 rate, u8 channels, 200 u8 sig_bits); 201 int gb_audio_gb_set_tx_data_size(struct gb_connection *connection, 202 u16 data_cport, u16 size); 203 int gb_audio_gb_activate_tx(struct gb_connection *connection, 204 u16 data_cport); 205 int gb_audio_gb_deactivate_tx(struct gb_connection *connection, 206 u16 data_cport); 207 int gb_audio_gb_set_rx_data_size(struct gb_connection *connection, 208 u16 data_cport, u16 size); 209 int gb_audio_gb_activate_rx(struct gb_connection *connection, 210 u16 data_cport); 211 int gb_audio_gb_deactivate_rx(struct gb_connection *connection, 212 u16 data_cport); 213 int gb_audio_apbridgea_set_config(struct gb_connection *connection, 214 __u16 i2s_port, __u32 format, 215 __u32 rate, __u32 mclk_freq); 216 int gb_audio_apbridgea_register_cport(struct gb_connection *connection, 217 __u16 i2s_port, __u16 cportid, 218 __u8 direction); 219 int gb_audio_apbridgea_unregister_cport(struct gb_connection *connection, 220 __u16 i2s_port, __u16 cportid, 221 __u8 direction); 222 int gb_audio_apbridgea_set_tx_data_size(struct gb_connection *connection, 223 __u16 i2s_port, __u16 size); 224 int gb_audio_apbridgea_prepare_tx(struct gb_connection *connection, 225 __u16 i2s_port); 226 int gb_audio_apbridgea_start_tx(struct gb_connection *connection, 227 __u16 i2s_port, __u64 timestamp); 228 int gb_audio_apbridgea_stop_tx(struct gb_connection *connection, 229 __u16 i2s_port); 230 int gb_audio_apbridgea_shutdown_tx(struct gb_connection *connection, 231 __u16 i2s_port); 232 int gb_audio_apbridgea_set_rx_data_size(struct gb_connection *connection, 233 __u16 i2s_port, __u16 size); 234 int gb_audio_apbridgea_prepare_rx(struct gb_connection *connection, 235 __u16 i2s_port); 236 int gb_audio_apbridgea_start_rx(struct gb_connection *connection, 237 __u16 i2s_port); 238 int gb_audio_apbridgea_stop_rx(struct gb_connection *connection, 239 __u16 i2s_port); 240 int gb_audio_apbridgea_shutdown_rx(struct gb_connection *connection, 241 __u16 i2s_port); 242 243 #endif /* __LINUX_GBAUDIO_CODEC_H */ 244