xref: /linux/sound/soc/intel/atom/sst-mfld-platform.h (revision cbecf716ca618fd44feda6bd9a64a8179d031fc5)
18e8e69d6SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2b97169daSJie Yang /*
3b97169daSJie Yang  *  sst_mfld_platform.h - Intel MID Platform driver header file
4b97169daSJie Yang  *
5b97169daSJie Yang  *  Copyright (C) 2010 Intel Corp
6b97169daSJie Yang  *  Author: Vinod Koul <vinod.koul@intel.com>
7b97169daSJie Yang  *  Author: Harsha Priya <priya.harsha@intel.com>
8b97169daSJie Yang  *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9b97169daSJie Yang  *
10b97169daSJie Yang  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11b97169daSJie Yang  */
12b97169daSJie Yang 
13b97169daSJie Yang #ifndef __SST_PLATFORMDRV_H__
14b97169daSJie Yang #define __SST_PLATFORMDRV_H__
15b97169daSJie Yang 
16b97169daSJie Yang #include "sst-mfld-dsp.h"
175749d70eSVinod Koul #include "sst-atom-controls.h"
18b97169daSJie Yang 
19b97169daSJie Yang extern struct sst_device *sst;
20c60e4459SKuninori Morimoto extern const struct snd_compress_ops sst_platform_compress_ops;
21b97169daSJie Yang 
226840962bSKuninori Morimoto #define DRV_NAME "sst"
236840962bSKuninori Morimoto 
24b97169daSJie Yang #define SST_MONO		1
25b97169daSJie Yang #define SST_STEREO		2
26b97169daSJie Yang #define SST_MAX_CAP		5
27b97169daSJie Yang 
28b97169daSJie Yang #define SST_MAX_BUFFER		(800*1024)
29b97169daSJie Yang #define SST_MIN_BUFFER		(800*1024)
30b97169daSJie Yang #define SST_MIN_PERIOD_BYTES	32
31b97169daSJie Yang #define SST_MAX_PERIOD_BYTES	SST_MAX_BUFFER
32b97169daSJie Yang #define SST_MIN_PERIODS		2
33b97169daSJie Yang #define SST_MAX_PERIODS		(1024*2)
34b97169daSJie Yang #define SST_FIFO_SIZE		0
35b97169daSJie Yang 
36b97169daSJie Yang struct pcm_stream_info {
37b97169daSJie Yang 	int str_id;
38b97169daSJie Yang 	void *arg;
39b97169daSJie Yang 	void (*period_elapsed) (void *arg);
40b97169daSJie Yang 	unsigned long long buffer_ptr;
41b97169daSJie Yang 	unsigned long long pcm_delay;
42b97169daSJie Yang 	int sfreq;
43b97169daSJie Yang };
44b97169daSJie Yang 
45b97169daSJie Yang enum sst_drv_status {
46b97169daSJie Yang 	SST_PLATFORM_INIT = 1,
47b97169daSJie Yang 	SST_PLATFORM_STARTED,
48b97169daSJie Yang 	SST_PLATFORM_RUNNING,
49b97169daSJie Yang 	SST_PLATFORM_PAUSED,
50b97169daSJie Yang 	SST_PLATFORM_DROPPED,
51b97169daSJie Yang };
52b97169daSJie Yang 
53b97169daSJie Yang enum sst_stream_ops {
54b97169daSJie Yang 	STREAM_OPS_PLAYBACK = 0,
55b97169daSJie Yang 	STREAM_OPS_CAPTURE,
56b97169daSJie Yang };
57b97169daSJie Yang 
58b97169daSJie Yang enum sst_audio_device_type {
59b97169daSJie Yang 	SND_SST_DEVICE_HEADSET = 1,
60b97169daSJie Yang 	SND_SST_DEVICE_IHF,
61b97169daSJie Yang 	SND_SST_DEVICE_VIBRA,
62b97169daSJie Yang 	SND_SST_DEVICE_HAPTIC,
63b97169daSJie Yang 	SND_SST_DEVICE_CAPTURE,
64b97169daSJie Yang 	SND_SST_DEVICE_COMPRESS,
65b97169daSJie Yang };
66b97169daSJie Yang 
67b97169daSJie Yang /* PCM Parameters */
68b97169daSJie Yang struct sst_pcm_params {
69b97169daSJie Yang 	u16 codec;	/* codec type */
70b97169daSJie Yang 	u8 num_chan;	/* 1=Mono, 2=Stereo */
71b97169daSJie Yang 	u8 pcm_wd_sz;	/* 16/24 - bit*/
72b97169daSJie Yang 	u32 reserved;	/* Bitrate in bits per second */
73b97169daSJie Yang 	u32 sfreq;	/* Sampling rate in Hz */
74b97169daSJie Yang 	u32 ring_buffer_size;
75b97169daSJie Yang 	u32 period_count;	/* period elapsed in samples*/
76b97169daSJie Yang 	u32 ring_buffer_addr;
77b97169daSJie Yang };
78b97169daSJie Yang 
79b97169daSJie Yang struct sst_stream_params {
80b97169daSJie Yang 	u32 result;
81b97169daSJie Yang 	u32 stream_id;
82b97169daSJie Yang 	u8 codec;
83b97169daSJie Yang 	u8 ops;
84b97169daSJie Yang 	u8 stream_type;
85b97169daSJie Yang 	u8 device_type;
86b97169daSJie Yang 	struct sst_pcm_params sparams;
87b97169daSJie Yang };
88b97169daSJie Yang 
89b97169daSJie Yang struct sst_compress_cb {
90b97169daSJie Yang 	void *param;
91b97169daSJie Yang 	void (*compr_cb)(void *param);
92b97169daSJie Yang 	void *drain_cb_param;
93b97169daSJie Yang 	void (*drain_notify)(void *param);
94b97169daSJie Yang };
95b97169daSJie Yang 
96b97169daSJie Yang struct compress_sst_ops {
97b97169daSJie Yang 	const char *name;
98b97169daSJie Yang 	int (*open)(struct device *dev,
99b97169daSJie Yang 		struct snd_sst_params *str_params, struct sst_compress_cb *cb);
100b97169daSJie Yang 	int (*stream_start)(struct device *dev, unsigned int str_id);
101b97169daSJie Yang 	int (*stream_drop)(struct device *dev, unsigned int str_id);
102b97169daSJie Yang 	int (*stream_drain)(struct device *dev, unsigned int str_id);
103b97169daSJie Yang 	int (*stream_partial_drain)(struct device *dev,	unsigned int str_id);
104b97169daSJie Yang 	int (*stream_pause)(struct device *dev, unsigned int str_id);
105b97169daSJie Yang 	int (*stream_pause_release)(struct device *dev,	unsigned int str_id);
106b97169daSJie Yang 
107b97169daSJie Yang 	int (*tstamp)(struct device *dev, unsigned int str_id,
108b97169daSJie Yang 			struct snd_compr_tstamp *tstamp);
109b97169daSJie Yang 	int (*ack)(struct device *dev, unsigned int str_id,
110b97169daSJie Yang 			unsigned long bytes);
111b97169daSJie Yang 	int (*close)(struct device *dev, unsigned int str_id);
112b97169daSJie Yang 	int (*get_caps)(struct snd_compr_caps *caps);
113b97169daSJie Yang 	int (*get_codec_caps)(struct snd_compr_codec_caps *codec);
114b97169daSJie Yang 	int (*set_metadata)(struct device *dev,	unsigned int str_id,
115b97169daSJie Yang 			struct snd_compr_metadata *mdata);
116b97169daSJie Yang 	int (*power)(struct device *dev, bool state);
117b97169daSJie Yang };
118b97169daSJie Yang 
119b97169daSJie Yang struct sst_ops {
120b97169daSJie Yang 	int (*open)(struct device *dev, struct snd_sst_params *str_param);
121b97169daSJie Yang 	int (*stream_init)(struct device *dev, struct pcm_stream_info *str_info);
122b97169daSJie Yang 	int (*stream_start)(struct device *dev, int str_id);
123b97169daSJie Yang 	int (*stream_drop)(struct device *dev, int str_id);
124b97169daSJie Yang 	int (*stream_pause)(struct device *dev, int str_id);
125b97169daSJie Yang 	int (*stream_pause_release)(struct device *dev, int str_id);
126b97169daSJie Yang 	int (*stream_read_tstamp)(struct device *dev, struct pcm_stream_info *str_info);
127b97169daSJie Yang 	int (*send_byte_stream)(struct device *dev, struct snd_sst_bytes_v2 *bytes);
128b97169daSJie Yang 	int (*close)(struct device *dev, unsigned int str_id);
129b97169daSJie Yang 	int (*power)(struct device *dev, bool state);
130b97169daSJie Yang };
131b97169daSJie Yang 
132b97169daSJie Yang struct sst_runtime_stream {
133b97169daSJie Yang 	int     stream_status;
134b97169daSJie Yang 	unsigned int id;
135b97169daSJie Yang 	size_t bytes_written;
136b97169daSJie Yang 	struct pcm_stream_info stream_info;
137b97169daSJie Yang 	struct sst_ops *ops;
138b97169daSJie Yang 	struct compress_sst_ops *compr_ops;
139b97169daSJie Yang 	spinlock_t	status_lock;
140b97169daSJie Yang };
141b97169daSJie Yang 
142b97169daSJie Yang struct sst_device {
143b97169daSJie Yang 	char *name;
144b97169daSJie Yang 	struct device *dev;
145b97169daSJie Yang 	struct sst_ops *ops;
146b97169daSJie Yang 	struct platform_device *pdev;
147b97169daSJie Yang 	struct compress_sst_ops *compr_ops;
148b97169daSJie Yang };
149b97169daSJie Yang 
150b97169daSJie Yang struct sst_data;
151b97169daSJie Yang 
1526840962bSKuninori Morimoto int sst_dsp_init_v2_dpcm(struct snd_soc_component *component);
153b97169daSJie Yang int sst_send_pipe_gains(struct snd_soc_dai *dai, int stream, int mute);
154b97169daSJie Yang int send_ssp_cmd(struct snd_soc_dai *dai, const char *id, bool enable);
155b97169daSJie Yang int sst_handle_vb_timer(struct snd_soc_dai *dai, bool enable);
156b97169daSJie Yang 
157b97169daSJie Yang void sst_set_stream_status(struct sst_runtime_stream *stream, int state);
158b97169daSJie Yang int sst_fill_stream_params(void *substream, const struct sst_data *ctx,
159b97169daSJie Yang 			   struct snd_sst_params *str_params, bool is_compress);
160b97169daSJie Yang 
161b97169daSJie Yang struct sst_algo_int_control_v2 {
162b97169daSJie Yang 	struct soc_mixer_control mc;
163b97169daSJie Yang 	u16 module_id; /* module identifieer */
164b97169daSJie Yang 	u16 pipe_id; /* location info: pipe_id + instance_id */
165b97169daSJie Yang 	u16 instance_id;
166b97169daSJie Yang 	unsigned int value; /* Value received is stored here */
167b97169daSJie Yang };
168b97169daSJie Yang struct sst_data {
169b97169daSJie Yang 	struct platform_device *pdev;
170b97169daSJie Yang 	struct sst_platform_data *pdata;
171b97169daSJie Yang 	struct snd_sst_bytes_v2 *byte_stream;
172b97169daSJie Yang 	struct mutex lock;
173b97169daSJie Yang 	struct snd_soc_card *soc_card;
1745749d70eSVinod Koul 	struct sst_cmd_sba_hw_set_ssp ssp_cmd;
175b97169daSJie Yang };
176*cfe8cc94SPierre-Louis Bossart int sst_register_dsp(struct sst_device *dev);
177*cfe8cc94SPierre-Louis Bossart int sst_unregister_dsp(struct sst_device *dev);
178b97169daSJie Yang #endif
179