2017-11-07 06:58:41 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-11-23 03:27:45 -07:00
|
|
|
/*
|
|
|
|
* Greybus audio driver
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
* Copyright 2015 Linaro Ltd.
|
|
|
|
*/
|
|
|
|
|
2016-01-13 14:07:49 -07:00
|
|
|
#ifndef __LINUX_GBAUDIO_CODEC_H
|
|
|
|
#define __LINUX_GBAUDIO_CODEC_H
|
2015-11-23 03:27:45 -07:00
|
|
|
|
|
|
|
#include <sound/soc.h>
|
2016-03-29 05:02:36 -06:00
|
|
|
#include <sound/jack.h>
|
2015-11-23 03:27:45 -07:00
|
|
|
|
2016-01-13 14:07:46 -07:00
|
|
|
#include "greybus.h"
|
|
|
|
#include "greybus_protocols.h"
|
|
|
|
|
2015-11-23 03:27:45 -07:00
|
|
|
#define NAME_SIZE 32
|
2016-01-13 14:07:50 -07:00
|
|
|
#define MAX_DAIS 2 /* APB1, APB2 */
|
2015-11-23 03:27:45 -07:00
|
|
|
|
|
|
|
enum {
|
|
|
|
APB1_PCM = 0,
|
|
|
|
APB2_PCM,
|
|
|
|
NUM_CODEC_DAIS,
|
|
|
|
};
|
|
|
|
|
2018-04-06 05:09:22 -06:00
|
|
|
/*
|
|
|
|
* device_type should be same as defined in audio.h
|
|
|
|
* (Android media layer)
|
|
|
|
*/
|
2016-03-30 01:53:56 -06:00
|
|
|
enum {
|
|
|
|
GBAUDIO_DEVICE_NONE = 0x0,
|
|
|
|
/* reserved bits */
|
|
|
|
GBAUDIO_DEVICE_BIT_IN = 0x80000000,
|
|
|
|
GBAUDIO_DEVICE_BIT_DEFAULT = 0x40000000,
|
|
|
|
/* output devices */
|
|
|
|
GBAUDIO_DEVICE_OUT_SPEAKER = 0x2,
|
|
|
|
GBAUDIO_DEVICE_OUT_WIRED_HEADSET = 0x4,
|
|
|
|
GBAUDIO_DEVICE_OUT_WIRED_HEADPHONE = 0x8,
|
|
|
|
/* input devices */
|
|
|
|
GBAUDIO_DEVICE_IN_BUILTIN_MIC = GBAUDIO_DEVICE_BIT_IN | 0x4,
|
|
|
|
GBAUDIO_DEVICE_IN_WIRED_HEADSET = GBAUDIO_DEVICE_BIT_IN | 0x10,
|
|
|
|
};
|
|
|
|
|
2016-09-01 00:08:40 -06:00
|
|
|
#define GBCODEC_JACK_MASK 0x0000FFFF
|
|
|
|
#define GBCODEC_JACK_BUTTON_MASK 0xFFFF0000
|
2016-03-29 05:02:36 -06:00
|
|
|
|
2016-03-29 12:01:41 -06:00
|
|
|
enum gbaudio_codec_state {
|
|
|
|
GBAUDIO_CODEC_SHUTDOWN = 0,
|
|
|
|
GBAUDIO_CODEC_STARTUP,
|
|
|
|
GBAUDIO_CODEC_HWPARAMS,
|
|
|
|
GBAUDIO_CODEC_PREPARE,
|
|
|
|
GBAUDIO_CODEC_START,
|
|
|
|
GBAUDIO_CODEC_STOP,
|
|
|
|
};
|
|
|
|
|
2016-08-04 03:44:38 -06:00
|
|
|
struct gbaudio_stream_params {
|
2016-03-29 12:01:41 -06:00
|
|
|
int state;
|
2016-09-19 18:47:29 -06:00
|
|
|
u8 sig_bits, channels;
|
2018-01-17 07:52:30 -07:00
|
|
|
u32 format, rate;
|
2016-03-29 12:01:41 -06:00
|
|
|
};
|
|
|
|
|
2016-08-04 03:44:38 -06:00
|
|
|
struct gbaudio_codec_dai {
|
|
|
|
int id;
|
|
|
|
/* runtime params for playback/capture streams */
|
|
|
|
struct gbaudio_stream_params params[2];
|
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
2016-03-29 12:01:41 -06:00
|
|
|
struct gbaudio_codec_info {
|
|
|
|
struct device *dev;
|
|
|
|
struct snd_soc_codec *codec;
|
|
|
|
struct list_head module_list;
|
2016-08-04 03:44:38 -06:00
|
|
|
/* to maintain runtime stream params for each DAI */
|
|
|
|
struct list_head dai_list;
|
2016-03-29 12:01:41 -06:00
|
|
|
struct mutex lock;
|
|
|
|
};
|
|
|
|
|
2016-01-13 14:07:51 -07:00
|
|
|
struct gbaudio_widget {
|
|
|
|
__u8 id;
|
|
|
|
const char *name;
|
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct gbaudio_control {
|
|
|
|
__u8 id;
|
|
|
|
char *name;
|
2016-07-05 16:09:20 -06:00
|
|
|
char *wname;
|
2016-01-13 14:07:51 -07:00
|
|
|
const char * const *texts;
|
2016-08-16 01:06:50 -06:00
|
|
|
int items;
|
2016-01-13 14:07:51 -07:00
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
2016-03-29 12:01:41 -06:00
|
|
|
struct gbaudio_data_connection {
|
2016-08-04 03:44:34 -06:00
|
|
|
int id;
|
2016-01-13 14:07:50 -07:00
|
|
|
__le16 data_cport;
|
|
|
|
struct gb_connection *connection;
|
|
|
|
struct list_head list;
|
2016-08-04 03:44:39 -06:00
|
|
|
/* maintain runtime state for playback/capture stream */
|
|
|
|
int state[2];
|
2016-01-13 14:07:50 -07:00
|
|
|
};
|
|
|
|
|
2016-03-29 12:01:41 -06:00
|
|
|
/* stream direction */
|
|
|
|
#define GB_PLAYBACK BIT(0)
|
|
|
|
#define GB_CAPTURE BIT(1)
|
|
|
|
|
|
|
|
enum gbaudio_module_state {
|
|
|
|
GBAUDIO_MODULE_OFF = 0,
|
|
|
|
GBAUDIO_MODULE_ON,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct gbaudio_module_info {
|
2016-01-13 14:07:50 -07:00
|
|
|
/* module info */
|
2016-03-29 12:01:41 -06:00
|
|
|
struct device *dev;
|
2016-01-13 14:07:50 -07:00
|
|
|
int dev_id; /* check if it should be bundle_id/hd_cport_id */
|
|
|
|
int vid;
|
|
|
|
int pid;
|
|
|
|
int type;
|
2016-01-13 14:07:53 -07:00
|
|
|
int set_uevent;
|
2016-01-13 14:07:50 -07:00
|
|
|
char vstr[NAME_SIZE];
|
|
|
|
char pstr[NAME_SIZE];
|
|
|
|
struct list_head list;
|
2016-01-13 14:07:53 -07:00
|
|
|
/* need to share this info to above user space */
|
|
|
|
int manager_id;
|
2016-01-13 14:07:50 -07:00
|
|
|
char name[NAME_SIZE];
|
2016-03-30 01:53:56 -06:00
|
|
|
unsigned int ip_devices;
|
|
|
|
unsigned int op_devices;
|
2015-11-23 03:27:45 -07:00
|
|
|
|
2016-03-29 05:02:36 -06:00
|
|
|
/* jack related */
|
|
|
|
char jack_name[NAME_SIZE];
|
|
|
|
char button_name[NAME_SIZE];
|
|
|
|
int jack_type;
|
2016-09-01 00:08:40 -06:00
|
|
|
int jack_mask;
|
|
|
|
int button_mask;
|
2016-03-29 05:02:36 -06:00
|
|
|
int button_status;
|
|
|
|
struct snd_soc_jack headset_jack;
|
|
|
|
struct snd_soc_jack button_jack;
|
|
|
|
|
2016-03-29 12:01:41 -06:00
|
|
|
/* connection info */
|
2016-01-13 14:07:50 -07:00
|
|
|
struct gb_connection *mgmt_connection;
|
2016-01-28 08:45:39 -07:00
|
|
|
size_t num_data_connections;
|
2016-03-29 12:01:41 -06:00
|
|
|
struct list_head data_list;
|
|
|
|
|
2016-01-28 08:45:39 -07:00
|
|
|
/* topology related */
|
2016-01-13 14:07:50 -07:00
|
|
|
int num_dais;
|
2016-03-29 12:01:41 -06:00
|
|
|
int num_controls;
|
2015-11-23 03:27:45 -07:00
|
|
|
int num_dapm_widgets;
|
|
|
|
int num_dapm_routes;
|
2016-01-13 14:07:51 -07:00
|
|
|
unsigned long dai_offset;
|
|
|
|
unsigned long widget_offset;
|
|
|
|
unsigned long control_offset;
|
|
|
|
unsigned long route_offset;
|
2016-03-29 12:01:41 -06:00
|
|
|
struct snd_kcontrol_new *controls;
|
|
|
|
struct snd_soc_dapm_widget *dapm_widgets;
|
|
|
|
struct snd_soc_dapm_route *dapm_routes;
|
2016-01-13 14:07:50 -07:00
|
|
|
struct snd_soc_dai_driver *dais;
|
|
|
|
|
2016-01-13 14:07:51 -07:00
|
|
|
struct list_head widget_list;
|
2016-03-29 12:01:41 -06:00
|
|
|
struct list_head ctl_list;
|
2016-01-13 14:07:51 -07:00
|
|
|
struct list_head widget_ctl_list;
|
2016-03-29 12:01:41 -06:00
|
|
|
|
|
|
|
struct gb_audio_topology *topology;
|
2015-11-23 03:27:45 -07:00
|
|
|
};
|
|
|
|
|
2016-03-29 12:01:41 -06:00
|
|
|
int gbaudio_tplg_parse_data(struct gbaudio_module_info *module,
|
2018-01-17 07:52:31 -07:00
|
|
|
struct gb_audio_topology *tplg_data);
|
2016-03-29 12:01:41 -06:00
|
|
|
void gbaudio_tplg_release(struct gbaudio_module_info *module);
|
|
|
|
|
|
|
|
int gbaudio_module_update(struct gbaudio_codec_info *codec,
|
2016-08-04 03:44:32 -06:00
|
|
|
struct snd_soc_dapm_widget *w,
|
|
|
|
struct gbaudio_module_info *module,
|
|
|
|
int enable);
|
2016-03-29 12:01:41 -06:00
|
|
|
int gbaudio_register_module(struct gbaudio_module_info *module);
|
|
|
|
void gbaudio_unregister_module(struct gbaudio_module_info *module);
|
2016-01-13 14:07:51 -07:00
|
|
|
|
2016-01-13 14:07:50 -07:00
|
|
|
/* protocol related */
|
2016-01-13 14:07:51 -07:00
|
|
|
extern int gb_audio_gb_get_topology(struct gb_connection *connection,
|
|
|
|
struct gb_audio_topology **topology);
|
2016-01-13 14:07:46 -07:00
|
|
|
extern int gb_audio_gb_get_control(struct gb_connection *connection,
|
2016-09-19 18:47:29 -06:00
|
|
|
u8 control_id, u8 index,
|
2016-01-13 14:07:46 -07:00
|
|
|
struct gb_audio_ctl_elem_value *value);
|
|
|
|
extern int gb_audio_gb_set_control(struct gb_connection *connection,
|
2016-09-19 18:47:29 -06:00
|
|
|
u8 control_id, u8 index,
|
2016-01-13 14:07:46 -07:00
|
|
|
struct gb_audio_ctl_elem_value *value);
|
|
|
|
extern int gb_audio_gb_enable_widget(struct gb_connection *connection,
|
2016-09-19 18:47:29 -06:00
|
|
|
u8 widget_id);
|
2016-01-13 14:07:46 -07:00
|
|
|
extern int gb_audio_gb_disable_widget(struct gb_connection *connection,
|
2016-09-19 18:47:29 -06:00
|
|
|
u8 widget_id);
|
2016-01-13 14:07:46 -07:00
|
|
|
extern int gb_audio_gb_get_pcm(struct gb_connection *connection,
|
2018-01-17 07:52:30 -07:00
|
|
|
u16 data_cport, u32 *format,
|
|
|
|
u32 *rate, u8 *channels,
|
2016-09-19 18:47:29 -06:00
|
|
|
u8 *sig_bits);
|
2016-01-13 14:07:46 -07:00
|
|
|
extern int gb_audio_gb_set_pcm(struct gb_connection *connection,
|
2018-01-17 07:52:30 -07:00
|
|
|
u16 data_cport, u32 format,
|
|
|
|
u32 rate, u8 channels,
|
2016-09-19 18:47:29 -06:00
|
|
|
u8 sig_bits);
|
2016-01-13 14:07:46 -07:00
|
|
|
extern int gb_audio_gb_set_tx_data_size(struct gb_connection *connection,
|
2016-09-19 18:47:30 -06:00
|
|
|
u16 data_cport, u16 size);
|
2016-01-13 14:07:46 -07:00
|
|
|
extern int gb_audio_gb_activate_tx(struct gb_connection *connection,
|
2016-09-19 18:47:30 -06:00
|
|
|
u16 data_cport);
|
2016-01-13 14:07:46 -07:00
|
|
|
extern int gb_audio_gb_deactivate_tx(struct gb_connection *connection,
|
2016-09-19 18:47:30 -06:00
|
|
|
u16 data_cport);
|
2016-01-13 14:07:46 -07:00
|
|
|
extern int gb_audio_gb_set_rx_data_size(struct gb_connection *connection,
|
2016-09-19 18:47:30 -06:00
|
|
|
u16 data_cport, u16 size);
|
2016-01-13 14:07:46 -07:00
|
|
|
extern int gb_audio_gb_activate_rx(struct gb_connection *connection,
|
2016-09-19 18:47:30 -06:00
|
|
|
u16 data_cport);
|
2016-01-13 14:07:46 -07:00
|
|
|
extern int gb_audio_gb_deactivate_rx(struct gb_connection *connection,
|
2016-09-19 18:47:30 -06:00
|
|
|
u16 data_cport);
|
2016-01-13 14:07:47 -07:00
|
|
|
extern int gb_audio_apbridgea_set_config(struct gb_connection *connection,
|
|
|
|
__u16 i2s_port, __u32 format,
|
|
|
|
__u32 rate, __u32 mclk_freq);
|
|
|
|
extern int gb_audio_apbridgea_register_cport(struct gb_connection *connection,
|
2016-02-26 17:04:36 -07:00
|
|
|
__u16 i2s_port, __u16 cportid,
|
|
|
|
__u8 direction);
|
2016-01-13 14:07:47 -07:00
|
|
|
extern int gb_audio_apbridgea_unregister_cport(struct gb_connection *connection,
|
2016-02-26 17:04:36 -07:00
|
|
|
__u16 i2s_port, __u16 cportid,
|
|
|
|
__u8 direction);
|
2016-01-13 14:07:47 -07:00
|
|
|
extern int gb_audio_apbridgea_set_tx_data_size(struct gb_connection *connection,
|
|
|
|
__u16 i2s_port, __u16 size);
|
2016-02-29 15:31:02 -07:00
|
|
|
extern int gb_audio_apbridgea_prepare_tx(struct gb_connection *connection,
|
|
|
|
__u16 i2s_port);
|
2016-01-13 14:07:47 -07:00
|
|
|
extern int gb_audio_apbridgea_start_tx(struct gb_connection *connection,
|
|
|
|
__u16 i2s_port, __u64 timestamp);
|
|
|
|
extern int gb_audio_apbridgea_stop_tx(struct gb_connection *connection,
|
|
|
|
__u16 i2s_port);
|
2016-02-29 15:31:02 -07:00
|
|
|
extern int gb_audio_apbridgea_shutdown_tx(struct gb_connection *connection,
|
|
|
|
__u16 i2s_port);
|
2016-01-13 14:07:47 -07:00
|
|
|
extern int gb_audio_apbridgea_set_rx_data_size(struct gb_connection *connection,
|
|
|
|
__u16 i2s_port, __u16 size);
|
2016-02-29 15:31:02 -07:00
|
|
|
extern int gb_audio_apbridgea_prepare_rx(struct gb_connection *connection,
|
|
|
|
__u16 i2s_port);
|
2016-01-13 14:07:47 -07:00
|
|
|
extern int gb_audio_apbridgea_start_rx(struct gb_connection *connection,
|
|
|
|
__u16 i2s_port);
|
|
|
|
extern int gb_audio_apbridgea_stop_rx(struct gb_connection *connection,
|
|
|
|
__u16 i2s_port);
|
2016-02-29 15:31:02 -07:00
|
|
|
extern int gb_audio_apbridgea_shutdown_rx(struct gb_connection *connection,
|
|
|
|
__u16 i2s_port);
|
2016-01-13 14:07:46 -07:00
|
|
|
|
2016-01-13 14:07:49 -07:00
|
|
|
#endif /* __LINUX_GBAUDIO_CODEC_H */
|