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 }; 75 76 struct gbaudio_widget { 77 __u8 id; 78 const char *name; 79 struct list_head list; 80 }; 81 82 struct 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 91 struct gbaudio_data_connection { 92 int id; 93 __le16 data_cport; 94 struct gb_connection *connection; 95 struct list_head list; 96 /* maintain runtime state for playback/capture stream */ 97 int state[2]; 98 }; 99 100 /* stream direction */ 101 #define GB_PLAYBACK BIT(0) 102 #define GB_CAPTURE BIT(1) 103 104 enum gbaudio_module_state { 105 GBAUDIO_MODULE_OFF = 0, 106 GBAUDIO_MODULE_ON, 107 }; 108 109 struct gbaudio_jack { 110 struct snd_soc_jack jack; 111 struct list_head list; 112 }; 113 114 struct gbaudio_module_info { 115 /* module info */ 116 struct device *dev; 117 int dev_id; /* check if it should be bundle_id/hd_cport_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 /* need to share this info to above user space */ 126 int manager_id; 127 char name[NAME_SIZE]; 128 unsigned int ip_devices; 129 unsigned int op_devices; 130 131 /* jack related */ 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 /* connection info */ 142 struct gb_connection *mgmt_connection; 143 size_t num_data_connections; 144 struct list_head data_list; 145 146 /* topology related */ 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 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); 171 172 int gbaudio_module_update(struct gbaudio_codec_info *codec, 173 struct snd_soc_dapm_widget *w, 174 struct gbaudio_module_info *module, 175 int enable); 176 int gbaudio_register_module(struct gbaudio_module_info *module); 177 void gbaudio_unregister_module(struct gbaudio_module_info *module); 178 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, 189 u8 widget_id); 190 int gb_audio_gb_disable_widget(struct gb_connection *connection, 191 u8 widget_id); 192 int gb_audio_gb_get_pcm(struct gb_connection *connection, 193 u16 data_cport, u32 *format, 194 u32 *rate, u8 *channels, 195 u8 *sig_bits); 196 int gb_audio_gb_set_pcm(struct gb_connection *connection, 197 u16 data_cport, u32 format, 198 u32 rate, u8 channels, 199 u8 sig_bits); 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, 203 u16 data_cport); 204 int gb_audio_gb_deactivate_tx(struct gb_connection *connection, 205 u16 data_cport); 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, 209 u16 data_cport); 210 int gb_audio_gb_deactivate_rx(struct gb_connection *connection, 211 u16 data_cport); 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, 217 __u8 direction); 218 int gb_audio_apbridgea_unregister_cport(struct gb_connection *connection, 219 __u16 i2s_port, __u16 cportid, 220 __u8 direction); 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, 224 __u16 i2s_port); 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, 228 __u16 i2s_port); 229 int gb_audio_apbridgea_shutdown_tx(struct gb_connection *connection, 230 __u16 i2s_port); 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, 234 __u16 i2s_port); 235 int gb_audio_apbridgea_start_rx(struct gb_connection *connection, 236 __u16 i2s_port); 237 int gb_audio_apbridgea_stop_rx(struct gb_connection *connection, 238 __u16 i2s_port); 239 int gb_audio_apbridgea_shutdown_rx(struct gb_connection *connection, 240 __u16 i2s_port); 241 242 #endif /* __LINUX_GBAUDIO_CODEC_H */ 243