diff options
-rw-r--r-- | sound/soc/intel/sst-acpi.c | 1 | ||||
-rw-r--r-- | sound/soc/intel/sst-baytrail-dsp.c | 2 | ||||
-rw-r--r-- | sound/soc/intel/sst-baytrail-ipc.c | 8 | ||||
-rw-r--r-- | sound/soc/intel/sst-dsp-priv.h | 1 | ||||
-rw-r--r-- | sound/soc/intel/sst-dsp.c | 1 | ||||
-rw-r--r-- | sound/soc/intel/sst-dsp.h | 1 | ||||
-rw-r--r-- | sound/soc/intel/sst-firmware.c | 25 | ||||
-rw-r--r-- | sound/soc/intel/sst-haswell-dsp.c | 4 | ||||
-rw-r--r-- | sound/soc/intel/sst-haswell-ipc.c | 31 | ||||
-rw-r--r-- | sound/soc/intel/sst-haswell-ipc.h | 4 | ||||
-rw-r--r-- | sound/soc/intel/sst-haswell-pcm.c | 107 |
11 files changed, 126 insertions, 59 deletions
diff --git a/sound/soc/intel/sst-acpi.c b/sound/soc/intel/sst-acpi.c index 5d06eecb6198..18aee77f8d4a 100644 --- a/sound/soc/intel/sst-acpi.c +++ b/sound/soc/intel/sst-acpi.c | |||
@@ -138,6 +138,7 @@ static int sst_acpi_probe(struct platform_device *pdev) | |||
138 | 138 | ||
139 | sst_pdata = &sst_acpi->sst_pdata; | 139 | sst_pdata = &sst_acpi->sst_pdata; |
140 | sst_pdata->id = desc->sst_id; | 140 | sst_pdata->id = desc->sst_id; |
141 | sst_pdata->dma_dev = dev; | ||
141 | sst_acpi->desc = desc; | 142 | sst_acpi->desc = desc; |
142 | sst_acpi->mach = mach; | 143 | sst_acpi->mach = mach; |
143 | 144 | ||
diff --git a/sound/soc/intel/sst-baytrail-dsp.c b/sound/soc/intel/sst-baytrail-dsp.c index a50bf7fc0e3a..adf0aca5aca6 100644 --- a/sound/soc/intel/sst-baytrail-dsp.c +++ b/sound/soc/intel/sst-baytrail-dsp.c | |||
@@ -324,7 +324,7 @@ static int sst_byt_init(struct sst_dsp *sst, struct sst_pdata *pdata) | |||
324 | memcpy_toio(sst->addr.lpe + SST_BYT_MAILBOX_OFFSET, | 324 | memcpy_toio(sst->addr.lpe + SST_BYT_MAILBOX_OFFSET, |
325 | &pdata->fw_base, sizeof(u32)); | 325 | &pdata->fw_base, sizeof(u32)); |
326 | 326 | ||
327 | ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32)); | 327 | ret = dma_coerce_mask_and_coherent(sst->dma_dev, DMA_BIT_MASK(32)); |
328 | if (ret) | 328 | if (ret) |
329 | return ret; | 329 | return ret; |
330 | 330 | ||
diff --git a/sound/soc/intel/sst-baytrail-ipc.c b/sound/soc/intel/sst-baytrail-ipc.c index d0eaeee21be4..0d31dbbf4806 100644 --- a/sound/soc/intel/sst-baytrail-ipc.c +++ b/sound/soc/intel/sst-baytrail-ipc.c | |||
@@ -542,16 +542,20 @@ struct sst_byt_stream *sst_byt_stream_new(struct sst_byt *byt, int id, | |||
542 | void *data) | 542 | void *data) |
543 | { | 543 | { |
544 | struct sst_byt_stream *stream; | 544 | struct sst_byt_stream *stream; |
545 | struct sst_dsp *sst = byt->dsp; | ||
546 | unsigned long flags; | ||
545 | 547 | ||
546 | stream = kzalloc(sizeof(*stream), GFP_KERNEL); | 548 | stream = kzalloc(sizeof(*stream), GFP_KERNEL); |
547 | if (stream == NULL) | 549 | if (stream == NULL) |
548 | return NULL; | 550 | return NULL; |
549 | 551 | ||
552 | spin_lock_irqsave(&sst->spinlock, flags); | ||
550 | list_add(&stream->node, &byt->stream_list); | 553 | list_add(&stream->node, &byt->stream_list); |
551 | stream->notify_position = notify_position; | 554 | stream->notify_position = notify_position; |
552 | stream->pdata = data; | 555 | stream->pdata = data; |
553 | stream->byt = byt; | 556 | stream->byt = byt; |
554 | stream->str_id = id; | 557 | stream->str_id = id; |
558 | spin_unlock_irqrestore(&sst->spinlock, flags); | ||
555 | 559 | ||
556 | return stream; | 560 | return stream; |
557 | } | 561 | } |
@@ -630,6 +634,8 @@ int sst_byt_stream_free(struct sst_byt *byt, struct sst_byt_stream *stream) | |||
630 | { | 634 | { |
631 | u64 header; | 635 | u64 header; |
632 | int ret = 0; | 636 | int ret = 0; |
637 | struct sst_dsp *sst = byt->dsp; | ||
638 | unsigned long flags; | ||
633 | 639 | ||
634 | if (!stream->commited) | 640 | if (!stream->commited) |
635 | goto out; | 641 | goto out; |
@@ -644,8 +650,10 @@ int sst_byt_stream_free(struct sst_byt *byt, struct sst_byt_stream *stream) | |||
644 | 650 | ||
645 | stream->commited = false; | 651 | stream->commited = false; |
646 | out: | 652 | out: |
653 | spin_lock_irqsave(&sst->spinlock, flags); | ||
647 | list_del(&stream->node); | 654 | list_del(&stream->node); |
648 | kfree(stream); | 655 | kfree(stream); |
656 | spin_unlock_irqrestore(&sst->spinlock, flags); | ||
649 | 657 | ||
650 | return ret; | 658 | return ret; |
651 | } | 659 | } |
diff --git a/sound/soc/intel/sst-dsp-priv.h b/sound/soc/intel/sst-dsp-priv.h index 30ca14a6a835..401213455497 100644 --- a/sound/soc/intel/sst-dsp-priv.h +++ b/sound/soc/intel/sst-dsp-priv.h | |||
@@ -228,6 +228,7 @@ struct sst_dsp { | |||
228 | spinlock_t spinlock; /* IPC locking */ | 228 | spinlock_t spinlock; /* IPC locking */ |
229 | struct mutex mutex; /* DSP FW lock */ | 229 | struct mutex mutex; /* DSP FW lock */ |
230 | struct device *dev; | 230 | struct device *dev; |
231 | struct device *dma_dev; | ||
231 | void *thread_context; | 232 | void *thread_context; |
232 | int irq; | 233 | int irq; |
233 | u32 id; | 234 | u32 id; |
diff --git a/sound/soc/intel/sst-dsp.c b/sound/soc/intel/sst-dsp.c index 0c129fd85ecf..0b715b20a2d7 100644 --- a/sound/soc/intel/sst-dsp.c +++ b/sound/soc/intel/sst-dsp.c | |||
@@ -337,6 +337,7 @@ struct sst_dsp *sst_dsp_new(struct device *dev, | |||
337 | spin_lock_init(&sst->spinlock); | 337 | spin_lock_init(&sst->spinlock); |
338 | mutex_init(&sst->mutex); | 338 | mutex_init(&sst->mutex); |
339 | sst->dev = dev; | 339 | sst->dev = dev; |
340 | sst->dma_dev = pdata->dma_dev; | ||
340 | sst->thread_context = sst_dev->thread_context; | 341 | sst->thread_context = sst_dev->thread_context; |
341 | sst->sst_dev = sst_dev; | 342 | sst->sst_dev = sst_dev; |
342 | sst->id = pdata->id; | 343 | sst->id = pdata->id; |
diff --git a/sound/soc/intel/sst-dsp.h b/sound/soc/intel/sst-dsp.h index 74052b59485c..e44423be66c4 100644 --- a/sound/soc/intel/sst-dsp.h +++ b/sound/soc/intel/sst-dsp.h | |||
@@ -169,6 +169,7 @@ struct sst_pdata { | |||
169 | u32 dma_base; | 169 | u32 dma_base; |
170 | u32 dma_size; | 170 | u32 dma_size; |
171 | int dma_engine; | 171 | int dma_engine; |
172 | struct device *dma_dev; | ||
172 | 173 | ||
173 | /* DSP */ | 174 | /* DSP */ |
174 | u32 id; | 175 | u32 id; |
diff --git a/sound/soc/intel/sst-firmware.c b/sound/soc/intel/sst-firmware.c index f7687107cf7f..928f228c38e7 100644 --- a/sound/soc/intel/sst-firmware.c +++ b/sound/soc/intel/sst-firmware.c | |||
@@ -57,14 +57,8 @@ struct sst_fw *sst_fw_new(struct sst_dsp *dsp, | |||
57 | sst_fw->private = private; | 57 | sst_fw->private = private; |
58 | sst_fw->size = fw->size; | 58 | sst_fw->size = fw->size; |
59 | 59 | ||
60 | err = dma_coerce_mask_and_coherent(dsp->dev, DMA_BIT_MASK(32)); | ||
61 | if (err < 0) { | ||
62 | kfree(sst_fw); | ||
63 | return NULL; | ||
64 | } | ||
65 | |||
66 | /* allocate DMA buffer to store FW data */ | 60 | /* allocate DMA buffer to store FW data */ |
67 | sst_fw->dma_buf = dma_alloc_coherent(dsp->dev, sst_fw->size, | 61 | sst_fw->dma_buf = dma_alloc_coherent(dsp->dma_dev, sst_fw->size, |
68 | &sst_fw->dmable_fw_paddr, GFP_DMA | GFP_KERNEL); | 62 | &sst_fw->dmable_fw_paddr, GFP_DMA | GFP_KERNEL); |
69 | if (!sst_fw->dma_buf) { | 63 | if (!sst_fw->dma_buf) { |
70 | dev_err(dsp->dev, "error: DMA alloc failed\n"); | 64 | dev_err(dsp->dev, "error: DMA alloc failed\n"); |
@@ -106,7 +100,7 @@ void sst_fw_free(struct sst_fw *sst_fw) | |||
106 | list_del(&sst_fw->list); | 100 | list_del(&sst_fw->list); |
107 | mutex_unlock(&dsp->mutex); | 101 | mutex_unlock(&dsp->mutex); |
108 | 102 | ||
109 | dma_free_coherent(dsp->dev, sst_fw->size, sst_fw->dma_buf, | 103 | dma_free_coherent(dsp->dma_dev, sst_fw->size, sst_fw->dma_buf, |
110 | sst_fw->dmable_fw_paddr); | 104 | sst_fw->dmable_fw_paddr); |
111 | kfree(sst_fw); | 105 | kfree(sst_fw); |
112 | } | 106 | } |
@@ -202,6 +196,9 @@ static int block_alloc_contiguous(struct sst_module *module, | |||
202 | size -= block->size; | 196 | size -= block->size; |
203 | } | 197 | } |
204 | 198 | ||
199 | list_for_each_entry(block, &tmp, list) | ||
200 | list_add(&block->module_list, &module->block_list); | ||
201 | |||
205 | list_splice(&tmp, &dsp->used_block_list); | 202 | list_splice(&tmp, &dsp->used_block_list); |
206 | return 0; | 203 | return 0; |
207 | } | 204 | } |
@@ -247,8 +244,7 @@ static int block_alloc(struct sst_module *module, | |||
247 | /* do we span > 1 blocks */ | 244 | /* do we span > 1 blocks */ |
248 | if (data->size > block->size) { | 245 | if (data->size > block->size) { |
249 | ret = block_alloc_contiguous(module, data, | 246 | ret = block_alloc_contiguous(module, data, |
250 | block->offset + block->size, | 247 | block->offset, data->size); |
251 | data->size - block->size); | ||
252 | if (ret == 0) | 248 | if (ret == 0) |
253 | return ret; | 249 | return ret; |
254 | } | 250 | } |
@@ -344,7 +340,7 @@ static int block_alloc_fixed(struct sst_module *module, | |||
344 | 340 | ||
345 | err = block_alloc_contiguous(module, data, | 341 | err = block_alloc_contiguous(module, data, |
346 | block->offset + block->size, | 342 | block->offset + block->size, |
347 | data->size - block->size + data->offset - block->offset); | 343 | data->size - block->size); |
348 | if (err < 0) | 344 | if (err < 0) |
349 | return -ENOMEM; | 345 | return -ENOMEM; |
350 | 346 | ||
@@ -371,15 +367,10 @@ static int block_alloc_fixed(struct sst_module *module, | |||
371 | if (data->offset >= block->offset && data->offset < block_end) { | 367 | if (data->offset >= block->offset && data->offset < block_end) { |
372 | 368 | ||
373 | err = block_alloc_contiguous(module, data, | 369 | err = block_alloc_contiguous(module, data, |
374 | block->offset + block->size, | 370 | block->offset, data->size); |
375 | data->size - block->size); | ||
376 | if (err < 0) | 371 | if (err < 0) |
377 | return -ENOMEM; | 372 | return -ENOMEM; |
378 | 373 | ||
379 | /* add block */ | ||
380 | block->data_type = data->data_type; | ||
381 | list_move(&block->list, &dsp->used_block_list); | ||
382 | list_add(&block->module_list, &module->block_list); | ||
383 | return 0; | 374 | return 0; |
384 | } | 375 | } |
385 | 376 | ||
diff --git a/sound/soc/intel/sst-haswell-dsp.c b/sound/soc/intel/sst-haswell-dsp.c index f5ebf36af889..535f517629fd 100644 --- a/sound/soc/intel/sst-haswell-dsp.c +++ b/sound/soc/intel/sst-haswell-dsp.c | |||
@@ -433,7 +433,7 @@ static int hsw_init(struct sst_dsp *sst, struct sst_pdata *pdata) | |||
433 | int ret = -ENODEV, i, j, region_count; | 433 | int ret = -ENODEV, i, j, region_count; |
434 | u32 offset, size; | 434 | u32 offset, size; |
435 | 435 | ||
436 | dev = sst->dev; | 436 | dev = sst->dma_dev; |
437 | 437 | ||
438 | switch (sst->id) { | 438 | switch (sst->id) { |
439 | case SST_DEV_ID_LYNX_POINT: | 439 | case SST_DEV_ID_LYNX_POINT: |
@@ -466,7 +466,7 @@ static int hsw_init(struct sst_dsp *sst, struct sst_pdata *pdata) | |||
466 | return ret; | 466 | return ret; |
467 | } | 467 | } |
468 | 468 | ||
469 | ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32)); | 469 | ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(31)); |
470 | if (ret) | 470 | if (ret) |
471 | return ret; | 471 | return ret; |
472 | 472 | ||
diff --git a/sound/soc/intel/sst-haswell-ipc.c b/sound/soc/intel/sst-haswell-ipc.c index 50e4246d4b57..e7996b39a484 100644 --- a/sound/soc/intel/sst-haswell-ipc.c +++ b/sound/soc/intel/sst-haswell-ipc.c | |||
@@ -1159,11 +1159,14 @@ struct sst_hsw_stream *sst_hsw_stream_new(struct sst_hsw *hsw, int id, | |||
1159 | void *data) | 1159 | void *data) |
1160 | { | 1160 | { |
1161 | struct sst_hsw_stream *stream; | 1161 | struct sst_hsw_stream *stream; |
1162 | struct sst_dsp *sst = hsw->dsp; | ||
1163 | unsigned long flags; | ||
1162 | 1164 | ||
1163 | stream = kzalloc(sizeof(*stream), GFP_KERNEL); | 1165 | stream = kzalloc(sizeof(*stream), GFP_KERNEL); |
1164 | if (stream == NULL) | 1166 | if (stream == NULL) |
1165 | return NULL; | 1167 | return NULL; |
1166 | 1168 | ||
1169 | spin_lock_irqsave(&sst->spinlock, flags); | ||
1167 | list_add(&stream->node, &hsw->stream_list); | 1170 | list_add(&stream->node, &hsw->stream_list); |
1168 | stream->notify_position = notify_position; | 1171 | stream->notify_position = notify_position; |
1169 | stream->pdata = data; | 1172 | stream->pdata = data; |
@@ -1172,6 +1175,7 @@ struct sst_hsw_stream *sst_hsw_stream_new(struct sst_hsw *hsw, int id, | |||
1172 | 1175 | ||
1173 | /* work to process notification messages */ | 1176 | /* work to process notification messages */ |
1174 | INIT_WORK(&stream->notify_work, hsw_notification_work); | 1177 | INIT_WORK(&stream->notify_work, hsw_notification_work); |
1178 | spin_unlock_irqrestore(&sst->spinlock, flags); | ||
1175 | 1179 | ||
1176 | return stream; | 1180 | return stream; |
1177 | } | 1181 | } |
@@ -1180,6 +1184,8 @@ int sst_hsw_stream_free(struct sst_hsw *hsw, struct sst_hsw_stream *stream) | |||
1180 | { | 1184 | { |
1181 | u32 header; | 1185 | u32 header; |
1182 | int ret = 0; | 1186 | int ret = 0; |
1187 | struct sst_dsp *sst = hsw->dsp; | ||
1188 | unsigned long flags; | ||
1183 | 1189 | ||
1184 | /* dont free DSP streams that are not commited */ | 1190 | /* dont free DSP streams that are not commited */ |
1185 | if (!stream->commited) | 1191 | if (!stream->commited) |
@@ -1201,8 +1207,11 @@ int sst_hsw_stream_free(struct sst_hsw *hsw, struct sst_hsw_stream *stream) | |||
1201 | trace_hsw_stream_free_req(stream, &stream->free_req); | 1207 | trace_hsw_stream_free_req(stream, &stream->free_req); |
1202 | 1208 | ||
1203 | out: | 1209 | out: |
1210 | cancel_work_sync(&stream->notify_work); | ||
1211 | spin_lock_irqsave(&sst->spinlock, flags); | ||
1204 | list_del(&stream->node); | 1212 | list_del(&stream->node); |
1205 | kfree(stream); | 1213 | kfree(stream); |
1214 | spin_unlock_irqrestore(&sst->spinlock, flags); | ||
1206 | 1215 | ||
1207 | return ret; | 1216 | return ret; |
1208 | } | 1217 | } |
@@ -1538,10 +1547,28 @@ int sst_hsw_stream_reset(struct sst_hsw *hsw, struct sst_hsw_stream *stream) | |||
1538 | } | 1547 | } |
1539 | 1548 | ||
1540 | /* Stream pointer positions */ | 1549 | /* Stream pointer positions */ |
1541 | int sst_hsw_get_dsp_position(struct sst_hsw *hsw, | 1550 | u32 sst_hsw_get_dsp_position(struct sst_hsw *hsw, |
1542 | struct sst_hsw_stream *stream) | 1551 | struct sst_hsw_stream *stream) |
1543 | { | 1552 | { |
1544 | return stream->rpos.position; | 1553 | u32 rpos; |
1554 | |||
1555 | sst_dsp_read(hsw->dsp, &rpos, | ||
1556 | stream->reply.read_position_register_address, sizeof(rpos)); | ||
1557 | |||
1558 | return rpos; | ||
1559 | } | ||
1560 | |||
1561 | /* Stream presentation (monotonic) positions */ | ||
1562 | u64 sst_hsw_get_dsp_presentation_position(struct sst_hsw *hsw, | ||
1563 | struct sst_hsw_stream *stream) | ||
1564 | { | ||
1565 | u64 ppos; | ||
1566 | |||
1567 | sst_dsp_read(hsw->dsp, &ppos, | ||
1568 | stream->reply.presentation_position_register_address, | ||
1569 | sizeof(ppos)); | ||
1570 | |||
1571 | return ppos; | ||
1545 | } | 1572 | } |
1546 | 1573 | ||
1547 | int sst_hsw_stream_set_write_position(struct sst_hsw *hsw, | 1574 | int sst_hsw_stream_set_write_position(struct sst_hsw *hsw, |
diff --git a/sound/soc/intel/sst-haswell-ipc.h b/sound/soc/intel/sst-haswell-ipc.h index d517929ccc38..2ac194a6d04b 100644 --- a/sound/soc/intel/sst-haswell-ipc.h +++ b/sound/soc/intel/sst-haswell-ipc.h | |||
@@ -464,7 +464,9 @@ int sst_hsw_stream_get_write_pos(struct sst_hsw *hsw, | |||
464 | struct sst_hsw_stream *stream, u32 *position); | 464 | struct sst_hsw_stream *stream, u32 *position); |
465 | int sst_hsw_stream_set_write_position(struct sst_hsw *hsw, | 465 | int sst_hsw_stream_set_write_position(struct sst_hsw *hsw, |
466 | struct sst_hsw_stream *stream, u32 stage_id, u32 position); | 466 | struct sst_hsw_stream *stream, u32 stage_id, u32 position); |
467 | int sst_hsw_get_dsp_position(struct sst_hsw *hsw, | 467 | u32 sst_hsw_get_dsp_position(struct sst_hsw *hsw, |
468 | struct sst_hsw_stream *stream); | ||
469 | u64 sst_hsw_get_dsp_presentation_position(struct sst_hsw *hsw, | ||
468 | struct sst_hsw_stream *stream); | 470 | struct sst_hsw_stream *stream); |
469 | 471 | ||
470 | /* HW port config */ | 472 | /* HW port config */ |
diff --git a/sound/soc/intel/sst-haswell-pcm.c b/sound/soc/intel/sst-haswell-pcm.c index 0a32dd13a23d..9d5f64a583a3 100644 --- a/sound/soc/intel/sst-haswell-pcm.c +++ b/sound/soc/intel/sst-haswell-pcm.c | |||
@@ -99,6 +99,7 @@ struct hsw_pcm_data { | |||
99 | struct snd_compr_stream *cstream; | 99 | struct snd_compr_stream *cstream; |
100 | unsigned int wpos; | 100 | unsigned int wpos; |
101 | struct mutex mutex; | 101 | struct mutex mutex; |
102 | bool allocated; | ||
102 | }; | 103 | }; |
103 | 104 | ||
104 | /* private data for the driver */ | 105 | /* private data for the driver */ |
@@ -107,12 +108,14 @@ struct hsw_priv_data { | |||
107 | struct sst_hsw *hsw; | 108 | struct sst_hsw *hsw; |
108 | 109 | ||
109 | /* page tables */ | 110 | /* page tables */ |
110 | unsigned char *pcm_pg[HSW_PCM_COUNT][2]; | 111 | struct snd_dma_buffer dmab[HSW_PCM_COUNT][2]; |
111 | 112 | ||
112 | /* DAI data */ | 113 | /* DAI data */ |
113 | struct hsw_pcm_data pcm[HSW_PCM_COUNT]; | 114 | struct hsw_pcm_data pcm[HSW_PCM_COUNT]; |
114 | }; | 115 | }; |
115 | 116 | ||
117 | static u32 hsw_notify_pointer(struct sst_hsw_stream *stream, void *data); | ||
118 | |||
116 | static inline u32 hsw_mixer_to_ipc(unsigned int value) | 119 | static inline u32 hsw_mixer_to_ipc(unsigned int value) |
117 | { | 120 | { |
118 | if (value >= ARRAY_SIZE(volume_map)) | 121 | if (value >= ARRAY_SIZE(volume_map)) |
@@ -273,28 +276,26 @@ static const struct snd_kcontrol_new hsw_volume_controls[] = { | |||
273 | }; | 276 | }; |
274 | 277 | ||
275 | /* Create DMA buffer page table for DSP */ | 278 | /* Create DMA buffer page table for DSP */ |
276 | static int create_adsp_page_table(struct hsw_priv_data *pdata, | 279 | static int create_adsp_page_table(struct snd_pcm_substream *substream, |
277 | struct snd_soc_pcm_runtime *rtd, | 280 | struct hsw_priv_data *pdata, struct snd_soc_pcm_runtime *rtd, |
278 | unsigned char *dma_area, size_t size, int pcm, int stream) | 281 | unsigned char *dma_area, size_t size, int pcm) |
279 | { | 282 | { |
280 | int i, pages; | 283 | struct snd_dma_buffer *dmab = snd_pcm_get_dma_buf(substream); |
284 | int i, pages, stream = substream->stream; | ||
281 | 285 | ||
282 | if (size % PAGE_SIZE) | 286 | pages = snd_sgbuf_aligned_pages(size); |
283 | pages = (size / PAGE_SIZE) + 1; | ||
284 | else | ||
285 | pages = size / PAGE_SIZE; | ||
286 | 287 | ||
287 | dev_dbg(rtd->dev, "generating page table for %p size 0x%zu pages %d\n", | 288 | dev_dbg(rtd->dev, "generating page table for %p size 0x%zu pages %d\n", |
288 | dma_area, size, pages); | 289 | dma_area, size, pages); |
289 | 290 | ||
290 | for (i = 0; i < pages; i++) { | 291 | for (i = 0; i < pages; i++) { |
291 | u32 idx = (((i << 2) + i)) >> 1; | 292 | u32 idx = (((i << 2) + i)) >> 1; |
292 | u32 pfn = (virt_to_phys(dma_area + i * PAGE_SIZE)) >> PAGE_SHIFT; | 293 | u32 pfn = snd_sgbuf_get_addr(dmab, i * PAGE_SIZE) >> PAGE_SHIFT; |
293 | u32 *pg_table; | 294 | u32 *pg_table; |
294 | 295 | ||
295 | dev_dbg(rtd->dev, "pfn i %i idx %d pfn %x\n", i, idx, pfn); | 296 | dev_dbg(rtd->dev, "pfn i %i idx %d pfn %x\n", i, idx, pfn); |
296 | 297 | ||
297 | pg_table = (u32*)(pdata->pcm_pg[pcm][stream] + idx); | 298 | pg_table = (u32 *)(pdata->dmab[pcm][stream].area + idx); |
298 | 299 | ||
299 | if (i & 1) | 300 | if (i & 1) |
300 | *pg_table |= (pfn << 4); | 301 | *pg_table |= (pfn << 4); |
@@ -317,12 +318,36 @@ static int hsw_pcm_hw_params(struct snd_pcm_substream *substream, | |||
317 | struct sst_hsw *hsw = pdata->hsw; | 318 | struct sst_hsw *hsw = pdata->hsw; |
318 | struct sst_module *module_data; | 319 | struct sst_module *module_data; |
319 | struct sst_dsp *dsp; | 320 | struct sst_dsp *dsp; |
321 | struct snd_dma_buffer *dmab; | ||
320 | enum sst_hsw_stream_type stream_type; | 322 | enum sst_hsw_stream_type stream_type; |
321 | enum sst_hsw_stream_path_id path_id; | 323 | enum sst_hsw_stream_path_id path_id; |
322 | u32 rate, bits, map, pages, module_id; | 324 | u32 rate, bits, map, pages, module_id; |
323 | u8 channels; | 325 | u8 channels; |
324 | int ret; | 326 | int ret; |
325 | 327 | ||
328 | /* check if we are being called a subsequent time */ | ||
329 | if (pcm_data->allocated) { | ||
330 | ret = sst_hsw_stream_reset(hsw, pcm_data->stream); | ||
331 | if (ret < 0) | ||
332 | dev_dbg(rtd->dev, "error: reset stream failed %d\n", | ||
333 | ret); | ||
334 | |||
335 | ret = sst_hsw_stream_free(hsw, pcm_data->stream); | ||
336 | if (ret < 0) { | ||
337 | dev_dbg(rtd->dev, "error: free stream failed %d\n", | ||
338 | ret); | ||
339 | return ret; | ||
340 | } | ||
341 | pcm_data->allocated = false; | ||
342 | |||
343 | pcm_data->stream = sst_hsw_stream_new(hsw, rtd->cpu_dai->id, | ||
344 | hsw_notify_pointer, pcm_data); | ||
345 | if (pcm_data->stream == NULL) { | ||
346 | dev_err(rtd->dev, "error: failed to create stream\n"); | ||
347 | return -EINVAL; | ||
348 | } | ||
349 | } | ||
350 | |||
326 | /* stream direction */ | 351 | /* stream direction */ |
327 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | 352 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
328 | path_id = SST_HSW_STREAM_PATH_SSP0_OUT; | 353 | path_id = SST_HSW_STREAM_PATH_SSP0_OUT; |
@@ -416,8 +441,10 @@ static int hsw_pcm_hw_params(struct snd_pcm_substream *substream, | |||
416 | return ret; | 441 | return ret; |
417 | } | 442 | } |
418 | 443 | ||
419 | ret = create_adsp_page_table(pdata, rtd, runtime->dma_area, | 444 | dmab = snd_pcm_get_dma_buf(substream); |
420 | runtime->dma_bytes, rtd->cpu_dai->id, substream->stream); | 445 | |
446 | ret = create_adsp_page_table(substream, pdata, rtd, runtime->dma_area, | ||
447 | runtime->dma_bytes, rtd->cpu_dai->id); | ||
421 | if (ret < 0) | 448 | if (ret < 0) |
422 | return ret; | 449 | return ret; |
423 | 450 | ||
@@ -430,9 +457,9 @@ static int hsw_pcm_hw_params(struct snd_pcm_substream *substream, | |||
430 | pages = runtime->dma_bytes / PAGE_SIZE; | 457 | pages = runtime->dma_bytes / PAGE_SIZE; |
431 | 458 | ||
432 | ret = sst_hsw_stream_buffer(hsw, pcm_data->stream, | 459 | ret = sst_hsw_stream_buffer(hsw, pcm_data->stream, |
433 | virt_to_phys(pdata->pcm_pg[rtd->cpu_dai->id][substream->stream]), | 460 | pdata->dmab[rtd->cpu_dai->id][substream->stream].addr, |
434 | pages, runtime->dma_bytes, 0, | 461 | pages, runtime->dma_bytes, 0, |
435 | (u32)(virt_to_phys(runtime->dma_area) >> PAGE_SHIFT)); | 462 | snd_sgbuf_get_addr(dmab, 0) >> PAGE_SHIFT); |
436 | if (ret < 0) { | 463 | if (ret < 0) { |
437 | dev_err(rtd->dev, "error: failed to set DMA buffer %d\n", ret); | 464 | dev_err(rtd->dev, "error: failed to set DMA buffer %d\n", ret); |
438 | return ret; | 465 | return ret; |
@@ -474,6 +501,7 @@ static int hsw_pcm_hw_params(struct snd_pcm_substream *substream, | |||
474 | dev_err(rtd->dev, "error: failed to commit stream %d\n", ret); | 501 | dev_err(rtd->dev, "error: failed to commit stream %d\n", ret); |
475 | return ret; | 502 | return ret; |
476 | } | 503 | } |
504 | pcm_data->allocated = true; | ||
477 | 505 | ||
478 | ret = sst_hsw_stream_pause(hsw, pcm_data->stream, 1); | 506 | ret = sst_hsw_stream_pause(hsw, pcm_data->stream, 1); |
479 | if (ret < 0) | 507 | if (ret < 0) |
@@ -541,12 +569,14 @@ static snd_pcm_uframes_t hsw_pcm_pointer(struct snd_pcm_substream *substream) | |||
541 | struct hsw_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd); | 569 | struct hsw_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd); |
542 | struct sst_hsw *hsw = pdata->hsw; | 570 | struct sst_hsw *hsw = pdata->hsw; |
543 | snd_pcm_uframes_t offset; | 571 | snd_pcm_uframes_t offset; |
572 | uint64_t ppos; | ||
573 | u32 position = sst_hsw_get_dsp_position(hsw, pcm_data->stream); | ||
544 | 574 | ||
545 | offset = bytes_to_frames(runtime, | 575 | offset = bytes_to_frames(runtime, position); |
546 | sst_hsw_get_dsp_position(hsw, pcm_data->stream)); | 576 | ppos = sst_hsw_get_dsp_presentation_position(hsw, pcm_data->stream); |
547 | 577 | ||
548 | dev_dbg(rtd->dev, "PCM: DMA pointer %zu bytes\n", | 578 | dev_dbg(rtd->dev, "PCM: DMA pointer %du bytes, pos %llu\n", |
549 | frames_to_bytes(runtime, (u32)offset)); | 579 | position, ppos); |
550 | return offset; | 580 | return offset; |
551 | } | 581 | } |
552 | 582 | ||
@@ -606,6 +636,7 @@ static int hsw_pcm_close(struct snd_pcm_substream *substream) | |||
606 | dev_dbg(rtd->dev, "error: free stream failed %d\n", ret); | 636 | dev_dbg(rtd->dev, "error: free stream failed %d\n", ret); |
607 | goto out; | 637 | goto out; |
608 | } | 638 | } |
639 | pcm_data->allocated = 0; | ||
609 | pcm_data->stream = NULL; | 640 | pcm_data->stream = NULL; |
610 | 641 | ||
611 | out: | 642 | out: |
@@ -621,7 +652,7 @@ static struct snd_pcm_ops hsw_pcm_ops = { | |||
621 | .hw_free = hsw_pcm_hw_free, | 652 | .hw_free = hsw_pcm_hw_free, |
622 | .trigger = hsw_pcm_trigger, | 653 | .trigger = hsw_pcm_trigger, |
623 | .pointer = hsw_pcm_pointer, | 654 | .pointer = hsw_pcm_pointer, |
624 | .mmap = snd_pcm_lib_default_mmap, | 655 | .page = snd_pcm_sgbuf_ops_page, |
625 | }; | 656 | }; |
626 | 657 | ||
627 | static void hsw_pcm_free(struct snd_pcm *pcm) | 658 | static void hsw_pcm_free(struct snd_pcm *pcm) |
@@ -632,17 +663,16 @@ static void hsw_pcm_free(struct snd_pcm *pcm) | |||
632 | static int hsw_pcm_new(struct snd_soc_pcm_runtime *rtd) | 663 | static int hsw_pcm_new(struct snd_soc_pcm_runtime *rtd) |
633 | { | 664 | { |
634 | struct snd_pcm *pcm = rtd->pcm; | 665 | struct snd_pcm *pcm = rtd->pcm; |
666 | struct snd_soc_platform *platform = rtd->platform; | ||
667 | struct sst_pdata *pdata = dev_get_platdata(platform->dev); | ||
668 | struct device *dev = pdata->dma_dev; | ||
635 | int ret = 0; | 669 | int ret = 0; |
636 | 670 | ||
637 | ret = dma_coerce_mask_and_coherent(rtd->card->dev, DMA_BIT_MASK(32)); | ||
638 | if (ret) | ||
639 | return ret; | ||
640 | |||
641 | if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream || | 671 | if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream || |
642 | pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) { | 672 | pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) { |
643 | ret = snd_pcm_lib_preallocate_pages_for_all(pcm, | 673 | ret = snd_pcm_lib_preallocate_pages_for_all(pcm, |
644 | SNDRV_DMA_TYPE_DEV, | 674 | SNDRV_DMA_TYPE_DEV_SG, |
645 | rtd->card->dev, | 675 | dev, |
646 | hsw_pcm_hardware.buffer_bytes_max, | 676 | hsw_pcm_hardware.buffer_bytes_max, |
647 | hsw_pcm_hardware.buffer_bytes_max); | 677 | hsw_pcm_hardware.buffer_bytes_max); |
648 | if (ret) { | 678 | if (ret) { |
@@ -742,11 +772,14 @@ static int hsw_pcm_probe(struct snd_soc_platform *platform) | |||
742 | { | 772 | { |
743 | struct sst_pdata *pdata = dev_get_platdata(platform->dev); | 773 | struct sst_pdata *pdata = dev_get_platdata(platform->dev); |
744 | struct hsw_priv_data *priv_data; | 774 | struct hsw_priv_data *priv_data; |
745 | int i; | 775 | struct device *dma_dev; |
776 | int i, ret = 0; | ||
746 | 777 | ||
747 | if (!pdata) | 778 | if (!pdata) |
748 | return -ENODEV; | 779 | return -ENODEV; |
749 | 780 | ||
781 | dma_dev = pdata->dma_dev; | ||
782 | |||
750 | priv_data = devm_kzalloc(platform->dev, sizeof(*priv_data), GFP_KERNEL); | 783 | priv_data = devm_kzalloc(platform->dev, sizeof(*priv_data), GFP_KERNEL); |
751 | priv_data->hsw = pdata->dsp; | 784 | priv_data->hsw = pdata->dsp; |
752 | snd_soc_platform_set_drvdata(platform, priv_data); | 785 | snd_soc_platform_set_drvdata(platform, priv_data); |
@@ -758,15 +791,17 @@ static int hsw_pcm_probe(struct snd_soc_platform *platform) | |||
758 | 791 | ||
759 | /* playback */ | 792 | /* playback */ |
760 | if (hsw_dais[i].playback.channels_min) { | 793 | if (hsw_dais[i].playback.channels_min) { |
761 | priv_data->pcm_pg[i][0] = kzalloc(PAGE_SIZE, GFP_DMA); | 794 | ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, dma_dev, |
762 | if (priv_data->pcm_pg[i][0] == NULL) | 795 | PAGE_SIZE, &priv_data->dmab[i][0]); |
796 | if (ret < 0) | ||
763 | goto err; | 797 | goto err; |
764 | } | 798 | } |
765 | 799 | ||
766 | /* capture */ | 800 | /* capture */ |
767 | if (hsw_dais[i].capture.channels_min) { | 801 | if (hsw_dais[i].capture.channels_min) { |
768 | priv_data->pcm_pg[i][1] = kzalloc(PAGE_SIZE, GFP_DMA); | 802 | ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, dma_dev, |
769 | if (priv_data->pcm_pg[i][1] == NULL) | 803 | PAGE_SIZE, &priv_data->dmab[i][1]); |
804 | if (ret < 0) | ||
770 | goto err; | 805 | goto err; |
771 | } | 806 | } |
772 | } | 807 | } |
@@ -776,11 +811,11 @@ static int hsw_pcm_probe(struct snd_soc_platform *platform) | |||
776 | err: | 811 | err: |
777 | for (;i >= 0; i--) { | 812 | for (;i >= 0; i--) { |
778 | if (hsw_dais[i].playback.channels_min) | 813 | if (hsw_dais[i].playback.channels_min) |
779 | kfree(priv_data->pcm_pg[i][0]); | 814 | snd_dma_free_pages(&priv_data->dmab[i][0]); |
780 | if (hsw_dais[i].capture.channels_min) | 815 | if (hsw_dais[i].capture.channels_min) |
781 | kfree(priv_data->pcm_pg[i][1]); | 816 | snd_dma_free_pages(&priv_data->dmab[i][1]); |
782 | } | 817 | } |
783 | return -ENOMEM; | 818 | return ret; |
784 | } | 819 | } |
785 | 820 | ||
786 | static int hsw_pcm_remove(struct snd_soc_platform *platform) | 821 | static int hsw_pcm_remove(struct snd_soc_platform *platform) |
@@ -791,9 +826,9 @@ static int hsw_pcm_remove(struct snd_soc_platform *platform) | |||
791 | 826 | ||
792 | for (i = 0; i < ARRAY_SIZE(hsw_dais); i++) { | 827 | for (i = 0; i < ARRAY_SIZE(hsw_dais); i++) { |
793 | if (hsw_dais[i].playback.channels_min) | 828 | if (hsw_dais[i].playback.channels_min) |
794 | kfree(priv_data->pcm_pg[i][0]); | 829 | snd_dma_free_pages(&priv_data->dmab[i][0]); |
795 | if (hsw_dais[i].capture.channels_min) | 830 | if (hsw_dais[i].capture.channels_min) |
796 | kfree(priv_data->pcm_pg[i][1]); | 831 | snd_dma_free_pages(&priv_data->dmab[i][1]); |
797 | } | 832 | } |
798 | 833 | ||
799 | return 0; | 834 | return 0; |