diff options
Diffstat (limited to 'sound/soc/mid-x86/sst_platform.c')
-rw-r--r-- | sound/soc/mid-x86/sst_platform.c | 123 |
1 files changed, 53 insertions, 70 deletions
diff --git a/sound/soc/mid-x86/sst_platform.c b/sound/soc/mid-x86/sst_platform.c index 0e994c16e7ab..a4e3fa3761fa 100644 --- a/sound/soc/mid-x86/sst_platform.c +++ b/sound/soc/mid-x86/sst_platform.c | |||
@@ -105,7 +105,45 @@ struct snd_soc_dai_driver sst_platform_dai[] = { | |||
105 | }, | 105 | }, |
106 | }, | 106 | }, |
107 | }; | 107 | }; |
108 | |||
108 | /* helper functions */ | 109 | /* helper functions */ |
110 | static inline void sst_set_stream_status(struct sst_runtime_stream *stream, | ||
111 | int state) | ||
112 | { | ||
113 | spin_lock(&stream->status_lock); | ||
114 | stream->stream_status = state; | ||
115 | spin_unlock(&stream->status_lock); | ||
116 | } | ||
117 | |||
118 | static inline int sst_get_stream_status(struct sst_runtime_stream *stream) | ||
119 | { | ||
120 | int state; | ||
121 | |||
122 | spin_lock(&stream->status_lock); | ||
123 | state = stream->stream_status; | ||
124 | spin_unlock(&stream->status_lock); | ||
125 | return state; | ||
126 | } | ||
127 | |||
128 | static void sst_fill_pcm_params(struct snd_pcm_substream *substream, | ||
129 | struct snd_sst_stream_params *param) | ||
130 | { | ||
131 | |||
132 | param->uc.pcm_params.codec = SST_CODEC_TYPE_PCM; | ||
133 | param->uc.pcm_params.num_chan = (u8) substream->runtime->channels; | ||
134 | param->uc.pcm_params.pcm_wd_sz = substream->runtime->sample_bits; | ||
135 | param->uc.pcm_params.reserved = 0; | ||
136 | param->uc.pcm_params.sfreq = substream->runtime->rate; | ||
137 | param->uc.pcm_params.ring_buffer_size = | ||
138 | snd_pcm_lib_buffer_bytes(substream); | ||
139 | param->uc.pcm_params.period_count = substream->runtime->period_size; | ||
140 | param->uc.pcm_params.ring_buffer_addr = | ||
141 | virt_to_phys(substream->dma_buffer.area); | ||
142 | pr_debug("period_cnt = %d\n", param->uc.pcm_params.period_count); | ||
143 | pr_debug("sfreq= %d, wd_sz = %d\n", | ||
144 | param->uc.pcm_params.sfreq, param->uc.pcm_params.pcm_wd_sz); | ||
145 | } | ||
146 | |||
109 | static int sst_platform_alloc_stream(struct snd_pcm_substream *substream) | 147 | static int sst_platform_alloc_stream(struct snd_pcm_substream *substream) |
110 | { | 148 | { |
111 | struct sst_runtime_stream *stream = | 149 | struct sst_runtime_stream *stream = |
@@ -115,26 +153,10 @@ static int sst_platform_alloc_stream(struct snd_pcm_substream *substream) | |||
115 | int ret_val; | 153 | int ret_val; |
116 | 154 | ||
117 | /* set codec params and inform SST driver the same */ | 155 | /* set codec params and inform SST driver the same */ |
118 | 156 | sst_fill_pcm_params(substream, ¶m); | |
119 | param.uc.pcm_params.codec = SST_CODEC_TYPE_PCM; | ||
120 | param.uc.pcm_params.num_chan = (u8) substream->runtime->channels; | ||
121 | param.uc.pcm_params.pcm_wd_sz = substream->runtime->sample_bits; | ||
122 | param.uc.pcm_params.reserved = 0; | ||
123 | param.uc.pcm_params.sfreq = substream->runtime->rate; | ||
124 | param.uc.pcm_params.ring_buffer_size = | ||
125 | snd_pcm_lib_buffer_bytes(substream); | ||
126 | param.uc.pcm_params.period_count = substream->runtime->period_size; | ||
127 | param.uc.pcm_params.ring_buffer_addr = | ||
128 | virt_to_phys(substream->dma_buffer.area); | ||
129 | substream->runtime->dma_area = substream->dma_buffer.area; | 157 | substream->runtime->dma_area = substream->dma_buffer.area; |
130 | |||
131 | pr_debug("period_cnt = %d\n", param.uc.pcm_params.period_count); | ||
132 | pr_debug("sfreq= %d, wd_sz = %d\n", | ||
133 | param.uc.pcm_params.sfreq, param.uc.pcm_params.pcm_wd_sz); | ||
134 | |||
135 | str_params.sparams = param; | 158 | str_params.sparams = param; |
136 | str_params.codec = SST_CODEC_TYPE_PCM; | 159 | str_params.codec = param.uc.pcm_params.codec; |
137 | |||
138 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | 160 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
139 | str_params.ops = STREAM_OPS_PLAYBACK; | 161 | str_params.ops = STREAM_OPS_PLAYBACK; |
140 | str_params.device_type = substream->pcm->device + 1; | 162 | str_params.device_type = substream->pcm->device + 1; |
@@ -153,28 +175,23 @@ static int sst_platform_alloc_stream(struct snd_pcm_substream *substream) | |||
153 | 175 | ||
154 | stream->stream_info.str_id = ret_val; | 176 | stream->stream_info.str_id = ret_val; |
155 | pr_debug("str id : %d\n", stream->stream_info.str_id); | 177 | pr_debug("str id : %d\n", stream->stream_info.str_id); |
156 | |||
157 | return ret_val; | 178 | return ret_val; |
158 | } | 179 | } |
159 | 180 | ||
160 | |||
161 | static void sst_period_elapsed(void *mad_substream) | 181 | static void sst_period_elapsed(void *mad_substream) |
162 | { | 182 | { |
163 | struct snd_pcm_substream *substream = mad_substream; | 183 | struct snd_pcm_substream *substream = mad_substream; |
164 | struct sst_runtime_stream *stream; | 184 | struct sst_runtime_stream *stream; |
185 | int status; | ||
165 | 186 | ||
166 | if (!substream || !substream->runtime) | 187 | if (!substream || !substream->runtime) |
167 | return; | 188 | return; |
168 | stream = substream->runtime->private_data; | 189 | stream = substream->runtime->private_data; |
169 | if (!stream) | 190 | if (!stream) |
170 | return; | 191 | return; |
171 | 192 | status = sst_get_stream_status(stream); | |
172 | spin_lock(&stream->status_lock); | 193 | if (status != SST_PLATFORM_RUNNING) |
173 | if (stream->stream_status != SST_PLATFORM_RUNNING) { | ||
174 | spin_unlock(&stream->status_lock); | ||
175 | return; | 194 | return; |
176 | } | ||
177 | spin_unlock(&stream->status_lock); | ||
178 | snd_pcm_period_elapsed(substream); | 195 | snd_pcm_period_elapsed(substream); |
179 | } | 196 | } |
180 | 197 | ||
@@ -185,9 +202,7 @@ static int sst_platform_init_stream(struct snd_pcm_substream *substream) | |||
185 | int ret_val; | 202 | int ret_val; |
186 | 203 | ||
187 | pr_debug("setting buffer ptr param\n"); | 204 | pr_debug("setting buffer ptr param\n"); |
188 | spin_lock(&stream->status_lock); | 205 | sst_set_stream_status(stream, SST_PLATFORM_INIT); |
189 | stream->stream_status = SST_PLATFORM_INIT; | ||
190 | spin_unlock(&stream->status_lock); | ||
191 | stream->stream_info.period_elapsed = sst_period_elapsed; | 206 | stream->stream_info.period_elapsed = sst_period_elapsed; |
192 | stream->stream_info.mad_substream = substream; | 207 | stream->stream_info.mad_substream = substream; |
193 | stream->stream_info.buffer_ptr = 0; | 208 | stream->stream_info.buffer_ptr = 0; |
@@ -208,21 +223,14 @@ static int sst_platform_open(struct snd_pcm_substream *substream) | |||
208 | int ret_val = 0; | 223 | int ret_val = 0; |
209 | 224 | ||
210 | pr_debug("sst_platform_open called\n"); | 225 | pr_debug("sst_platform_open called\n"); |
211 | |||
212 | runtime = substream->runtime; | 226 | runtime = substream->runtime; |
213 | runtime->hw = sst_platform_pcm_hw; | 227 | runtime->hw = sst_platform_pcm_hw; |
214 | |||
215 | stream = kzalloc(sizeof(*stream), GFP_KERNEL); | 228 | stream = kzalloc(sizeof(*stream), GFP_KERNEL); |
216 | if (!stream) | 229 | if (!stream) |
217 | return -ENOMEM; | 230 | return -ENOMEM; |
218 | |||
219 | spin_lock_init(&stream->status_lock); | 231 | spin_lock_init(&stream->status_lock); |
220 | stream->stream_info.str_id = 0; | 232 | stream->stream_info.str_id = 0; |
221 | 233 | sst_set_stream_status(stream, SST_PLATFORM_INIT); | |
222 | spin_lock(&stream->status_lock); | ||
223 | stream->stream_status = SST_PLATFORM_INIT; | ||
224 | spin_unlock(&stream->status_lock); | ||
225 | |||
226 | stream->stream_info.mad_substream = substream; | 234 | stream->stream_info.mad_substream = substream; |
227 | /* allocate memory for SST API set */ | 235 | /* allocate memory for SST API set */ |
228 | stream->sstdrv_ops = kzalloc(sizeof(*stream->sstdrv_ops), | 236 | stream->sstdrv_ops = kzalloc(sizeof(*stream->sstdrv_ops), |
@@ -233,7 +241,6 @@ static int sst_platform_open(struct snd_pcm_substream *substream) | |||
233 | return -ENOMEM; | 241 | return -ENOMEM; |
234 | } | 242 | } |
235 | stream->sstdrv_ops->vendor_id = MSIC_VENDOR_ID; | 243 | stream->sstdrv_ops->vendor_id = MSIC_VENDOR_ID; |
236 | |||
237 | /* registering with SST driver to get access to SST APIs to use */ | 244 | /* registering with SST driver to get access to SST APIs to use */ |
238 | ret_val = register_sst_card(stream->sstdrv_ops); | 245 | ret_val = register_sst_card(stream->sstdrv_ops); |
239 | if (ret_val) { | 246 | if (ret_val) { |
@@ -251,14 +258,11 @@ static int sst_platform_close(struct snd_pcm_substream *substream) | |||
251 | int ret_val = 0, str_id; | 258 | int ret_val = 0, str_id; |
252 | 259 | ||
253 | pr_debug("sst_platform_close called\n"); | 260 | pr_debug("sst_platform_close called\n"); |
254 | |||
255 | stream = substream->runtime->private_data; | 261 | stream = substream->runtime->private_data; |
256 | str_id = stream->stream_info.str_id; | 262 | str_id = stream->stream_info.str_id; |
257 | |||
258 | if (str_id) | 263 | if (str_id) |
259 | ret_val = stream->sstdrv_ops->control_set( | 264 | ret_val = stream->sstdrv_ops->control_set( |
260 | SST_SND_FREE, &str_id); | 265 | SST_SND_FREE, &str_id); |
261 | |||
262 | kfree(stream->sstdrv_ops); | 266 | kfree(stream->sstdrv_ops); |
263 | kfree(stream); | 267 | kfree(stream); |
264 | return ret_val; | 268 | return ret_val; |
@@ -270,7 +274,6 @@ static int sst_platform_pcm_prepare(struct snd_pcm_substream *substream) | |||
270 | int ret_val = 0, str_id; | 274 | int ret_val = 0, str_id; |
271 | 275 | ||
272 | pr_debug("sst_platform_pcm_prepare called\n"); | 276 | pr_debug("sst_platform_pcm_prepare called\n"); |
273 | |||
274 | stream = substream->runtime->private_data; | 277 | stream = substream->runtime->private_data; |
275 | str_id = stream->stream_info.str_id; | 278 | str_id = stream->stream_info.str_id; |
276 | if (stream->stream_info.str_id) { | 279 | if (stream->stream_info.str_id) { |
@@ -299,11 +302,8 @@ static int sst_platform_pcm_trigger(struct snd_pcm_substream *substream, | |||
299 | struct sst_runtime_stream *stream; | 302 | struct sst_runtime_stream *stream; |
300 | 303 | ||
301 | pr_debug("sst_platform_pcm_trigger called\n"); | 304 | pr_debug("sst_platform_pcm_trigger called\n"); |
302 | |||
303 | stream = substream->runtime->private_data; | 305 | stream = substream->runtime->private_data; |
304 | |||
305 | str_id = stream->stream_info.str_id; | 306 | str_id = stream->stream_info.str_id; |
306 | |||
307 | switch (cmd) { | 307 | switch (cmd) { |
308 | case SNDRV_PCM_TRIGGER_START: | 308 | case SNDRV_PCM_TRIGGER_START: |
309 | pr_debug("sst: Trigger Start\n"); | 309 | pr_debug("sst: Trigger Start\n"); |
@@ -311,9 +311,7 @@ static int sst_platform_pcm_trigger(struct snd_pcm_substream *substream, | |||
311 | SST_SND_START, &str_id); | 311 | SST_SND_START, &str_id); |
312 | if (ret_val) | 312 | if (ret_val) |
313 | break; | 313 | break; |
314 | spin_lock(&stream->status_lock); | 314 | sst_set_stream_status(stream, SST_PLATFORM_RUNNING); |
315 | stream->stream_status = SST_PLATFORM_RUNNING; | ||
316 | spin_unlock(&stream->status_lock); | ||
317 | stream->stream_info.mad_substream = substream; | 315 | stream->stream_info.mad_substream = substream; |
318 | break; | 316 | break; |
319 | case SNDRV_PCM_TRIGGER_STOP: | 317 | case SNDRV_PCM_TRIGGER_STOP: |
@@ -322,9 +320,7 @@ static int sst_platform_pcm_trigger(struct snd_pcm_substream *substream, | |||
322 | SST_SND_DROP, &str_id); | 320 | SST_SND_DROP, &str_id); |
323 | if (ret_val) | 321 | if (ret_val) |
324 | break; | 322 | break; |
325 | spin_lock(&stream->status_lock); | 323 | sst_set_stream_status(stream, SST_PLATFORM_DROPPED); |
326 | stream->stream_status = SST_PLATFORM_DROPPED; | ||
327 | spin_unlock(&stream->status_lock); | ||
328 | break; | 324 | break; |
329 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | 325 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
330 | pr_debug("sst: in pause\n"); | 326 | pr_debug("sst: in pause\n"); |
@@ -332,9 +328,7 @@ static int sst_platform_pcm_trigger(struct snd_pcm_substream *substream, | |||
332 | SST_SND_PAUSE, &str_id); | 328 | SST_SND_PAUSE, &str_id); |
333 | if (ret_val) | 329 | if (ret_val) |
334 | break; | 330 | break; |
335 | spin_lock(&stream->status_lock); | 331 | sst_set_stream_status(stream, SST_PLATFORM_PAUSED); |
336 | stream->stream_status = SST_PLATFORM_PAUSED; | ||
337 | spin_unlock(&stream->status_lock); | ||
338 | break; | 332 | break; |
339 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | 333 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
340 | pr_debug("sst: in pause release\n"); | 334 | pr_debug("sst: in pause release\n"); |
@@ -342,9 +336,7 @@ static int sst_platform_pcm_trigger(struct snd_pcm_substream *substream, | |||
342 | SST_SND_RESUME, &str_id); | 336 | SST_SND_RESUME, &str_id); |
343 | if (ret_val) | 337 | if (ret_val) |
344 | break; | 338 | break; |
345 | spin_lock(&stream->status_lock); | 339 | sst_set_stream_status(stream, SST_PLATFORM_RUNNING); |
346 | stream->stream_status = SST_PLATFORM_RUNNING; | ||
347 | spin_unlock(&stream->status_lock); | ||
348 | break; | 340 | break; |
349 | default: | 341 | default: |
350 | ret_val = -EINVAL; | 342 | ret_val = -EINVAL; |
@@ -357,18 +349,13 @@ static snd_pcm_uframes_t sst_platform_pcm_pointer | |||
357 | (struct snd_pcm_substream *substream) | 349 | (struct snd_pcm_substream *substream) |
358 | { | 350 | { |
359 | struct sst_runtime_stream *stream; | 351 | struct sst_runtime_stream *stream; |
360 | int ret_val; | 352 | int ret_val, status; |
361 | struct pcm_stream_info *str_info; | 353 | struct pcm_stream_info *str_info; |
362 | 354 | ||
363 | |||
364 | stream = substream->runtime->private_data; | 355 | stream = substream->runtime->private_data; |
365 | spin_lock(&stream->status_lock); | 356 | status = sst_get_stream_status(stream); |
366 | if (stream->stream_status == SST_PLATFORM_INIT) { | 357 | if (status == SST_PLATFORM_INIT) |
367 | spin_unlock(&stream->status_lock); | ||
368 | return 0; | 358 | return 0; |
369 | } | ||
370 | spin_unlock(&stream->status_lock); | ||
371 | |||
372 | str_info = &stream->stream_info; | 359 | str_info = &stream->stream_info; |
373 | ret_val = stream->sstdrv_ops->control_set( | 360 | ret_val = stream->sstdrv_ops->control_set( |
374 | SST_SND_BUFFER_POINTER, str_info); | 361 | SST_SND_BUFFER_POINTER, str_info); |
@@ -376,7 +363,6 @@ static snd_pcm_uframes_t sst_platform_pcm_pointer | |||
376 | pr_err("sst: error code = %d\n", ret_val); | 363 | pr_err("sst: error code = %d\n", ret_val); |
377 | return ret_val; | 364 | return ret_val; |
378 | } | 365 | } |
379 | |||
380 | return stream->stream_info.buffer_ptr; | 366 | return stream->stream_info.buffer_ptr; |
381 | } | 367 | } |
382 | 368 | ||
@@ -402,7 +388,6 @@ int sst_pcm_new(struct snd_card *card, struct snd_soc_dai *dai, | |||
402 | int retval = 0; | 388 | int retval = 0; |
403 | 389 | ||
404 | pr_debug("sst_pcm_new called\n"); | 390 | pr_debug("sst_pcm_new called\n"); |
405 | |||
406 | if (dai->driver->playback.channels_min || | 391 | if (dai->driver->playback.channels_min || |
407 | dai->driver->capture.channels_min) { | 392 | dai->driver->capture.channels_min) { |
408 | retval = snd_pcm_lib_preallocate_pages_for_all(pcm, | 393 | retval = snd_pcm_lib_preallocate_pages_for_all(pcm, |
@@ -414,7 +399,6 @@ int sst_pcm_new(struct snd_card *card, struct snd_soc_dai *dai, | |||
414 | return retval; | 399 | return retval; |
415 | } | 400 | } |
416 | } | 401 | } |
417 | |||
418 | return retval; | 402 | return retval; |
419 | } | 403 | } |
420 | struct snd_soc_platform_driver sst_soc_platform_drv = { | 404 | struct snd_soc_platform_driver sst_soc_platform_drv = { |
@@ -433,6 +417,7 @@ static int sst_platform_probe(struct platform_device *pdev) | |||
433 | pr_err("registering soc platform failed\n"); | 417 | pr_err("registering soc platform failed\n"); |
434 | return ret; | 418 | return ret; |
435 | } | 419 | } |
420 | |||
436 | ret = snd_soc_register_dais(&pdev->dev, | 421 | ret = snd_soc_register_dais(&pdev->dev, |
437 | sst_platform_dai, ARRAY_SIZE(sst_platform_dai)); | 422 | sst_platform_dai, ARRAY_SIZE(sst_platform_dai)); |
438 | if (ret) { | 423 | if (ret) { |
@@ -446,10 +431,8 @@ static int sst_platform_remove(struct platform_device *pdev) | |||
446 | { | 431 | { |
447 | 432 | ||
448 | snd_soc_unregister_dais(&pdev->dev, ARRAY_SIZE(sst_platform_dai)); | 433 | snd_soc_unregister_dais(&pdev->dev, ARRAY_SIZE(sst_platform_dai)); |
449 | |||
450 | snd_soc_unregister_platform(&pdev->dev); | 434 | snd_soc_unregister_platform(&pdev->dev); |
451 | pr_debug("sst_platform_remove sucess\n"); | 435 | pr_debug("sst_platform_remove sucess\n"); |
452 | |||
453 | return 0; | 436 | return 0; |
454 | } | 437 | } |
455 | 438 | ||