Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Greybus audio driver
0004  * Copyright 2015 Google Inc.
0005  * Copyright 2015 Linaro Ltd.
0006  */
0007 
0008 #ifndef __LINUX_GBAUDIO_CODEC_H
0009 #define __LINUX_GBAUDIO_CODEC_H
0010 
0011 #include <linux/greybus.h>
0012 #include <sound/soc.h>
0013 #include <sound/jack.h>
0014 
0015 #define NAME_SIZE   32
0016 #define MAX_DAIS    2   /* APB1, APB2 */
0017 
0018 enum {
0019     APB1_PCM = 0,
0020     APB2_PCM,
0021     NUM_CODEC_DAIS,
0022 };
0023 
0024 /*
0025  * device_type should be same as defined in audio.h
0026  * (Android media layer)
0027  */
0028 enum {
0029     GBAUDIO_DEVICE_NONE                     = 0x0,
0030     /* reserved bits */
0031     GBAUDIO_DEVICE_BIT_IN                   = 0x80000000,
0032     GBAUDIO_DEVICE_BIT_DEFAULT              = 0x40000000,
0033     /* output devices */
0034     GBAUDIO_DEVICE_OUT_SPEAKER              = 0x2,
0035     GBAUDIO_DEVICE_OUT_WIRED_HEADSET        = 0x4,
0036     GBAUDIO_DEVICE_OUT_WIRED_HEADPHONE      = 0x8,
0037     /* input devices */
0038     GBAUDIO_DEVICE_IN_BUILTIN_MIC           = GBAUDIO_DEVICE_BIT_IN | 0x4,
0039     GBAUDIO_DEVICE_IN_WIRED_HEADSET         = GBAUDIO_DEVICE_BIT_IN | 0x10,
0040 };
0041 
0042 #define GBCODEC_JACK_MASK       0x0000FFFF
0043 #define GBCODEC_JACK_BUTTON_MASK    0xFFFF0000
0044 
0045 enum gbaudio_codec_state {
0046     GBAUDIO_CODEC_SHUTDOWN = 0,
0047     GBAUDIO_CODEC_STARTUP,
0048     GBAUDIO_CODEC_HWPARAMS,
0049     GBAUDIO_CODEC_PREPARE,
0050     GBAUDIO_CODEC_START,
0051     GBAUDIO_CODEC_STOP,
0052 };
0053 
0054 struct gbaudio_stream_params {
0055     int state;
0056     u8 sig_bits, channels;
0057     u32 format, rate;
0058 };
0059 
0060 struct gbaudio_codec_dai {
0061     int id;
0062     /* runtime params for playback/capture streams */
0063     struct gbaudio_stream_params params[2];
0064     struct list_head list;
0065 };
0066 
0067 struct gbaudio_codec_info {
0068     struct device *dev;
0069     struct snd_soc_component *component;
0070     struct list_head module_list;
0071     /* to maintain runtime stream params for each DAI */
0072     struct list_head dai_list;
0073     struct mutex lock;
0074 };
0075 
0076 struct gbaudio_widget {
0077     __u8 id;
0078     const char *name;
0079     struct list_head list;
0080 };
0081 
0082 struct gbaudio_control {
0083     __u8 id;
0084     char *name;
0085     char *wname;
0086     const char * const *texts;
0087     int items;
0088     struct list_head list;
0089 };
0090 
0091 struct gbaudio_data_connection {
0092     int id;
0093     __le16 data_cport;
0094     struct gb_connection *connection;
0095     struct list_head list;
0096     /* maintain runtime state for playback/capture stream */
0097     int state[2];
0098 };
0099 
0100 /* stream direction */
0101 #define GB_PLAYBACK BIT(0)
0102 #define GB_CAPTURE  BIT(1)
0103 
0104 enum gbaudio_module_state {
0105     GBAUDIO_MODULE_OFF = 0,
0106     GBAUDIO_MODULE_ON,
0107 };
0108 
0109 struct gbaudio_jack {
0110     struct snd_soc_jack jack;
0111     struct list_head list;
0112 };
0113 
0114 struct gbaudio_module_info {
0115     /* module info */
0116     struct device *dev;
0117     int dev_id; /* check if it should be bundle_id/hd_cport_id */
0118     int vid;
0119     int pid;
0120     int type;
0121     int set_uevent;
0122     char vstr[NAME_SIZE];
0123     char pstr[NAME_SIZE];
0124     struct list_head list;
0125     /* need to share this info to above user space */
0126     int manager_id;
0127     char name[NAME_SIZE];
0128     unsigned int ip_devices;
0129     unsigned int op_devices;
0130 
0131     /* jack related */
0132     char jack_name[NAME_SIZE];
0133     char button_name[NAME_SIZE];
0134     int jack_type;
0135     int jack_mask;
0136     int button_mask;
0137     int button_status;
0138     struct gbaudio_jack headset;
0139     struct gbaudio_jack button;
0140 
0141     /* connection info */
0142     struct gb_connection *mgmt_connection;
0143     size_t num_data_connections;
0144     struct list_head data_list;
0145 
0146     /* topology related */
0147     int num_dais;
0148     int num_controls;
0149     int num_dapm_widgets;
0150     int num_dapm_routes;
0151     unsigned long dai_offset;
0152     unsigned long widget_offset;
0153     unsigned long control_offset;
0154     unsigned long route_offset;
0155     struct snd_kcontrol_new *controls;
0156     struct snd_soc_dapm_widget *dapm_widgets;
0157     struct snd_soc_dapm_route *dapm_routes;
0158     struct snd_soc_dai_driver *dais;
0159 
0160     struct list_head widget_list;
0161     struct list_head ctl_list;
0162     struct list_head widget_ctl_list;
0163     struct list_head jack_list;
0164 
0165     struct gb_audio_topology *topology;
0166 };
0167 
0168 int gbaudio_tplg_parse_data(struct gbaudio_module_info *module,
0169                 struct gb_audio_topology *tplg_data);
0170 void gbaudio_tplg_release(struct gbaudio_module_info *module);
0171 
0172 int gbaudio_module_update(struct gbaudio_codec_info *codec,
0173               struct snd_soc_dapm_widget *w,
0174               struct gbaudio_module_info *module,
0175               int enable);
0176 int gbaudio_register_module(struct gbaudio_module_info *module);
0177 void gbaudio_unregister_module(struct gbaudio_module_info *module);
0178 
0179 /* protocol related */
0180 int gb_audio_gb_get_topology(struct gb_connection *connection,
0181                  struct gb_audio_topology **topology);
0182 int gb_audio_gb_get_control(struct gb_connection *connection,
0183                 u8 control_id, u8 index,
0184                 struct gb_audio_ctl_elem_value *value);
0185 int gb_audio_gb_set_control(struct gb_connection *connection,
0186                 u8 control_id, u8 index,
0187                 struct gb_audio_ctl_elem_value *value);
0188 int gb_audio_gb_enable_widget(struct gb_connection *connection,
0189                   u8 widget_id);
0190 int gb_audio_gb_disable_widget(struct gb_connection *connection,
0191                    u8 widget_id);
0192 int gb_audio_gb_get_pcm(struct gb_connection *connection,
0193             u16 data_cport, u32 *format,
0194             u32 *rate, u8 *channels,
0195             u8 *sig_bits);
0196 int gb_audio_gb_set_pcm(struct gb_connection *connection,
0197             u16 data_cport, u32 format,
0198             u32 rate, u8 channels,
0199             u8 sig_bits);
0200 int gb_audio_gb_set_tx_data_size(struct gb_connection *connection,
0201                  u16 data_cport, u16 size);
0202 int gb_audio_gb_activate_tx(struct gb_connection *connection,
0203                 u16 data_cport);
0204 int gb_audio_gb_deactivate_tx(struct gb_connection *connection,
0205                   u16 data_cport);
0206 int gb_audio_gb_set_rx_data_size(struct gb_connection *connection,
0207                  u16 data_cport, u16 size);
0208 int gb_audio_gb_activate_rx(struct gb_connection *connection,
0209                 u16 data_cport);
0210 int gb_audio_gb_deactivate_rx(struct gb_connection *connection,
0211                   u16 data_cport);
0212 int gb_audio_apbridgea_set_config(struct gb_connection *connection,
0213                   __u16 i2s_port, __u32 format,
0214                   __u32 rate, __u32 mclk_freq);
0215 int gb_audio_apbridgea_register_cport(struct gb_connection *connection,
0216                       __u16 i2s_port, __u16 cportid,
0217                       __u8 direction);
0218 int gb_audio_apbridgea_unregister_cport(struct gb_connection *connection,
0219                     __u16 i2s_port, __u16 cportid,
0220                     __u8 direction);
0221 int gb_audio_apbridgea_set_tx_data_size(struct gb_connection *connection,
0222                     __u16 i2s_port, __u16 size);
0223 int gb_audio_apbridgea_prepare_tx(struct gb_connection *connection,
0224                   __u16 i2s_port);
0225 int gb_audio_apbridgea_start_tx(struct gb_connection *connection,
0226                 __u16 i2s_port, __u64 timestamp);
0227 int gb_audio_apbridgea_stop_tx(struct gb_connection *connection,
0228                    __u16 i2s_port);
0229 int gb_audio_apbridgea_shutdown_tx(struct gb_connection *connection,
0230                    __u16 i2s_port);
0231 int gb_audio_apbridgea_set_rx_data_size(struct gb_connection *connection,
0232                     __u16 i2s_port, __u16 size);
0233 int gb_audio_apbridgea_prepare_rx(struct gb_connection *connection,
0234                   __u16 i2s_port);
0235 int gb_audio_apbridgea_start_rx(struct gb_connection *connection,
0236                 __u16 i2s_port);
0237 int gb_audio_apbridgea_stop_rx(struct gb_connection *connection,
0238                    __u16 i2s_port);
0239 int gb_audio_apbridgea_shutdown_rx(struct gb_connection *connection,
0240                    __u16 i2s_port);
0241 
0242 #endif /* __LINUX_GBAUDIO_CODEC_H */