This source file includes following definitions.
- get_mult_div
- get_bits
- hda_dsp_pcm_hw_params
- hda_dsp_pcm_trigger
- hda_dsp_pcm_pointer
- hda_dsp_pcm_open
- hda_dsp_pcm_close
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include <sound/hda_register.h>
19 #include <sound/pcm_params.h>
20 #include "../ops.h"
21 #include "hda.h"
22
23 #define SDnFMT_BASE(x) ((x) << 14)
24 #define SDnFMT_MULT(x) (((x) - 1) << 11)
25 #define SDnFMT_DIV(x) (((x) - 1) << 8)
26 #define SDnFMT_BITS(x) ((x) << 4)
27 #define SDnFMT_CHAN(x) ((x) << 0)
28
29 static inline u32 get_mult_div(struct snd_sof_dev *sdev, int rate)
30 {
31 switch (rate) {
32 case 8000:
33 return SDnFMT_DIV(6);
34 case 9600:
35 return SDnFMT_DIV(5);
36 case 11025:
37 return SDnFMT_BASE(1) | SDnFMT_DIV(4);
38 case 16000:
39 return SDnFMT_DIV(3);
40 case 22050:
41 return SDnFMT_BASE(1) | SDnFMT_DIV(2);
42 case 32000:
43 return SDnFMT_DIV(3) | SDnFMT_MULT(2);
44 case 44100:
45 return SDnFMT_BASE(1);
46 case 48000:
47 return 0;
48 case 88200:
49 return SDnFMT_BASE(1) | SDnFMT_MULT(2);
50 case 96000:
51 return SDnFMT_MULT(2);
52 case 176400:
53 return SDnFMT_BASE(1) | SDnFMT_MULT(4);
54 case 192000:
55 return SDnFMT_MULT(4);
56 default:
57 dev_warn(sdev->dev, "can't find div rate %d using 48kHz\n",
58 rate);
59 return 0;
60 }
61 };
62
63 static inline u32 get_bits(struct snd_sof_dev *sdev, int sample_bits)
64 {
65 switch (sample_bits) {
66 case 8:
67 return SDnFMT_BITS(0);
68 case 16:
69 return SDnFMT_BITS(1);
70 case 20:
71 return SDnFMT_BITS(2);
72 case 24:
73 return SDnFMT_BITS(3);
74 case 32:
75 return SDnFMT_BITS(4);
76 default:
77 dev_warn(sdev->dev, "can't find %d bits using 16bit\n",
78 sample_bits);
79 return SDnFMT_BITS(1);
80 }
81 };
82
83 int hda_dsp_pcm_hw_params(struct snd_sof_dev *sdev,
84 struct snd_pcm_substream *substream,
85 struct snd_pcm_hw_params *params,
86 struct sof_ipc_stream_params *ipc_params)
87 {
88 struct hdac_stream *hstream = substream->runtime->private_data;
89 struct hdac_ext_stream *stream = stream_to_hdac_ext_stream(hstream);
90 struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
91 struct snd_dma_buffer *dmab;
92 int ret;
93 u32 size, rate, bits;
94
95 size = params_buffer_bytes(params);
96 rate = get_mult_div(sdev, params_rate(params));
97 bits = get_bits(sdev, params_width(params));
98
99 hstream->substream = substream;
100
101 dmab = substream->runtime->dma_buffer_p;
102
103 hstream->format_val = rate | bits | (params_channels(params) - 1);
104 hstream->bufsize = size;
105 hstream->period_bytes = params_period_bytes(params);
106 hstream->no_period_wakeup =
107 (params->info & SNDRV_PCM_INFO_NO_PERIOD_WAKEUP) &&
108 (params->flags & SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP);
109
110 ret = hda_dsp_stream_hw_params(sdev, stream, dmab, params);
111 if (ret < 0) {
112 dev_err(sdev->dev, "error: hdac prepare failed: %x\n", ret);
113 return ret;
114 }
115
116
117 hda_dsp_stream_spib_config(sdev, stream, HDA_DSP_SPIB_DISABLE, 0);
118
119
120 if (hda && hda->no_ipc_position)
121 ipc_params->host_period_bytes = 0;
122
123 ipc_params->stream_tag = hstream->stream_tag;
124
125 return 0;
126 }
127
128 int hda_dsp_pcm_trigger(struct snd_sof_dev *sdev,
129 struct snd_pcm_substream *substream, int cmd)
130 {
131 struct hdac_stream *hstream = substream->runtime->private_data;
132 struct hdac_ext_stream *stream = stream_to_hdac_ext_stream(hstream);
133
134 return hda_dsp_stream_trigger(sdev, stream, cmd);
135 }
136
137 snd_pcm_uframes_t hda_dsp_pcm_pointer(struct snd_sof_dev *sdev,
138 struct snd_pcm_substream *substream)
139 {
140 struct snd_soc_pcm_runtime *rtd = substream->private_data;
141 struct hdac_stream *hstream = substream->runtime->private_data;
142 struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
143 struct snd_sof_pcm *spcm;
144 snd_pcm_uframes_t pos;
145
146 spcm = snd_sof_find_spcm_dai(sdev, rtd);
147 if (!spcm) {
148 dev_warn_ratelimited(sdev->dev, "warn: can't find PCM with DAI ID %d\n",
149 rtd->dai_link->id);
150 return 0;
151 }
152
153 if (hda && !hda->no_ipc_position) {
154
155 pos = spcm->stream[substream->stream].posn.host_posn;
156 goto found;
157 }
158
159
160
161
162
163
164
165
166
167 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
168 pos = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR,
169 AZX_REG_VS_SDXDPIB_XBASE +
170 (AZX_REG_VS_SDXDPIB_XINTERVAL *
171 hstream->index));
172 } else {
173
174
175
176
177
178
179
180
181
182
183
184
185 usleep_range(20, 21);
186 snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR,
187 AZX_REG_VS_SDXDPIB_XBASE +
188 (AZX_REG_VS_SDXDPIB_XINTERVAL *
189 hstream->index));
190 pos = snd_hdac_stream_get_pos_posbuf(hstream);
191 }
192
193 if (pos >= hstream->bufsize)
194 pos = 0;
195
196 found:
197 pos = bytes_to_frames(substream->runtime, pos);
198
199 dev_vdbg(sdev->dev, "PCM: stream %d dir %d position %lu\n",
200 hstream->index, substream->stream, pos);
201 return pos;
202 }
203
204 int hda_dsp_pcm_open(struct snd_sof_dev *sdev,
205 struct snd_pcm_substream *substream)
206 {
207 struct hdac_ext_stream *dsp_stream;
208 int direction = substream->stream;
209
210 dsp_stream = hda_dsp_stream_get(sdev, direction);
211
212 if (!dsp_stream) {
213 dev_err(sdev->dev, "error: no stream available\n");
214 return -ENODEV;
215 }
216
217
218 substream->runtime->private_data = &dsp_stream->hstream;
219 return 0;
220 }
221
222 int hda_dsp_pcm_close(struct snd_sof_dev *sdev,
223 struct snd_pcm_substream *substream)
224 {
225 struct hdac_stream *hstream = substream->runtime->private_data;
226 int direction = substream->stream;
227 int ret;
228
229 ret = hda_dsp_stream_put(sdev, direction, hstream->stream_tag);
230
231 if (ret) {
232 dev_dbg(sdev->dev, "stream %s not opened!\n", substream->name);
233 return -ENODEV;
234 }
235
236
237 substream->runtime->private_data = NULL;
238 return 0;
239 }