@@ -280,147 +280,6 @@ static int dai_get_fifo(struct dai *dai, int direction, int stream_id)
280280 return fifo_address ;
281281}
282282
283- #if 0
284- #ifdef CONFIG_DAI_INTEL_UAOL
285- int dai_get_uaol_stream_id (struct dai * dai , int * uaol_link_id , int * uaol_stream_id )
286- {
287- const struct dai_properties * props ;
288- k_spinlock_key_t key ;
289-
290- key = k_spin_lock (& dai -> lock );
291-
292- props = dai_get_properties (dai -> dev , 0 , 0 );
293- * uaol_link_id = props -> uaol_link_id ;
294- * uaol_stream_id = props -> uaol_stream_id ;
295-
296- k_spin_unlock (& dai -> lock , key );
297-
298- return 0 ;
299- }
300- #endif /* CONFIG_DAI_INTEL_UAOL */
301-
302- static void process_uaol_feedback (struct comp_dev * dev , struct dai_data * dd )
303- {
304- assert (dd && dd -> uaol .fb_chan_idx >= 0 && dd -> uaol .fb_dma_buf );
305- ///assert(dev->direction == SOF_IPC_STREAM_PLAYBACK);
306-
307- struct dma_status stat = {0 };
308- int ret = sof_dma_get_status (dd -> dma , dd -> uaol .fb_chan_idx , & stat );
309- if (ret ) {
310- comp_err (dev , "Failed to get UAOL feedback DMA status: %d" , ret );
311- return ;
312- }
313-
314- if (stat .pending_length < 4 ) {
315- /* TODO: That's a normal case, remove this comp_dbg() ??? */
316- comp_dbg (dev , "Not enough data in UAOL feedback buffer: %d bytes" , stat .pending_length );
317- return ;
318- }
319-
320- assert (dd -> uaol .fb_dma_buf_size >= 4 );
321- if (stat .read_position < 0 || stat .read_position > dd -> uaol .fb_dma_buf_size - 4 ) {
322- comp_err (dev , "Invalid read position in UAOL feedback buffer: %d" , stat .read_position );
323- return ;
324- }
325-
326- /* Use uncached pointer to read DMA buffer */
327- assert (is_uncached (dd -> uaol .fb_dma_buf ));
328-
329- /* NOTE: Not all DMA drivers populate stat.write_position. Intel ACE HDA does. */
330- assert (stat .write_position & 3 == 0 ); /* 4-byte alignment check. */
331- /* Read the last received 4 bytes (ignore older ones if any). */
332- int last_4_bytes_pos = stat .write_position >= 4 ? (stat .write_position - 4 ) :
333- (dd -> uaol .fb_dma_buf_size - 4 );
334- uint32_t feedback_value = dd -> uaol .fb_dma_buf [last_4_bytes_pos / 4 ];
335-
336- ret = sof_dma_reload (dd -> dma , dd -> uaol .fb_chan_idx , stat .pending_length );
337- if (ret < 0 ) {
338- comp_err (dev , "Failed to reload UAOL feedback DMA: %d, pending_length: %d" ,
339- ret , stat .pending_length );
340- return ;
341- }
342-
343- comp_dbg (dev , "UAOL feedback value: %u" , feedback_value );
344-
345- const struct device * uaol_zdev = get_uaol_zdevice (dd -> uaol .link_id );
346- int freq = uaol_interpret_feedback_value (uaol_zdev , dd -> uaol .stream_id , feedback_value );
347-
348- if (freq < 0 ) {
349- comp_err (dev , "Bad unexpected feedback freq value: %d" , freq );
350- return ;
351- }
352-
353- /* Let's limit the maximum drift to a reasonable value to prevent significant audio distortion
354- * when, for some reason, the reported drift is quite big.
355- */
356- #define MAX_UAOL_DRIFT_HZ 6
357-
358- int drift = freq - dd -> ipc_config .sampling_frequency ;
359- if (drift < - MAX_UAOL_DRIFT_HZ || drift > MAX_UAOL_DRIFT_HZ ) {
360- comp_warn (dev , "Too much/unreasonable UAOL feedback freq value: %d, drift: %d" , freq , drift );
361- return ;
362- }
363-
364- dd -> uaol .feedback_drift = drift ;
365- if (dd -> uaol .feedback_drift > 0 )
366- dsrc_set_rate (& dd -> uaol .dsrc , dd -> ipc_config .sampling_frequency , freq );
367- }
368-
369- static void adjust_uaol_rate (const struct dai_data * dd , bool increase )
370- {
371- const struct device * uaol_zdev = get_uaol_zdevice (dd -> uaol .link_id );
372- int ret = uaol_adjust_rate (uaol_zdev , dd -> uaol .stream_id , increase );
373-
374- if (ret != 0 )
375- comp_err (dd -> dai_dev , "Failed to adjust UAOL rate: %d" , ret );
376- }
377-
378- static int uaol_dma_buffer_copy_to (struct dai_data * dd , size_t bytes )
379- {
380- int ret = 0 ;
381-
382- assert (dd -> uaol .feedback_drift != 0 );
383-
384- if (dd -> uaol .feedback_drift > 0 ) {
385- buffer_stream_invalidate (dd -> local_buffer , bytes );
386-
387- struct cir_buf_ptr in = { dd -> local_buffer -> stream .addr ,
388- dd -> local_buffer -> stream .end_addr , dd -> local_buffer -> stream .r_ptr };
389- assert (dd -> uaol .dsrc_buf );
390- struct cir_buf_ptr out = { dd -> uaol .dsrc_buf -> stream .addr ,
391- dd -> uaol .dsrc_buf -> stream .end_addr , dd -> uaol .dsrc_buf -> stream .w_ptr };
392- size_t frames = bytes / audio_stream_frame_bytes (& dd -> local_buffer -> stream );
393-
394- size_t added_frames = dsrc_process (& dd -> uaol .dsrc , & in , & out , frames );
395- size_t added_bytes = added_frames * audio_stream_frame_bytes (& dd -> local_buffer -> stream );
396-
397- comp_update_buffer_consume (dd -> local_buffer , bytes );
398- audio_stream_produce (& dd -> uaol .dsrc_buf -> stream , bytes + added_bytes );
399-
400- if (added_frames )
401- adjust_uaol_rate (dd , true);
402-
403- size_t extra_bytes = added_frames * audio_stream_frame_bytes (& dd -> dma_buffer -> stream );
404- ret = dma_buffer_copy_to (dd -> uaol .dsrc_buf , dd -> dma_buffer ,
405- dd -> process , bytes + extra_bytes , dd -> chmap );
406- } else if (dd -> uaol .feedback_drift < 0 ) {
407- assert (dd -> uaol .feedback_drift <= -1 && dd -> uaol .feedback_drift >= -1000 );
408- dd -> uaol .ms_since_last_adjustment ++ ;
409- if (-1000 / dd -> uaol .feedback_drift >= dd -> uaol .ms_since_last_adjustment ) {
410- dd -> uaol .ms_since_last_adjustment = 0 ;
411- adjust_uaol_rate (dd , false);
412- }
413-
414- ret = dma_buffer_copy_to (dd -> local_buffer , dd -> dma_buffer ,
415- dd -> process , bytes , dd -> chmap );
416- } else {
417- return - EINVAL ;
418- }
419-
420- return ret ;
421- }
422- #endif //0
423-
424283/* this is called by DMA driver every time descriptor has completed */
425284static enum sof_dma_cb_status
426285dai_dma_cb (struct dai_data * dd , struct comp_dev * dev , uint32_t bytes ,
@@ -787,28 +646,6 @@ static int dai_dma_suspend(struct dai_data *dd)
787646 return ret ;
788647}
789648
790- #if 0
791- static void uaol_free (struct dai_data * dd )
792- {
793- if (dd -> uaol .fb_z_config ) {
794- rfree (dd -> uaol .fb_z_config -> head_block );
795- rfree (dd -> uaol .fb_z_config );
796- dd -> uaol .fb_z_config = NULL ;
797- }
798-
799- if (dd -> uaol .fb_dma_buf ) {
800- rfree (dd -> uaol .fb_dma_buf );
801- dd -> uaol .fb_dma_buf = NULL ;
802- dd -> uaol .fb_dma_buf_size = 0 ;
803- }
804-
805- if (dd -> uaol .dsrc_buf ) {
806- buffer_free (dd -> uaol .dsrc_buf );
807- dd -> uaol .dsrc_buf = NULL ;
808- }
809- }
810- #endif //0
811-
812649__cold static struct comp_dev * dai_new (const struct comp_driver * drv ,
813650 const struct comp_ipc_config * config ,
814651 const void * spec )
@@ -1396,103 +1233,6 @@ static int dai_params(struct comp_dev *dev, struct sof_ipc_stream_params *params
13961233 return dai_common_params (dd , dev , params );
13971234}
13981235
1399- #if 0
1400- static int setup_uaol_feedback_dma (struct dai_data * dd , struct comp_dev * dev )
1401- {
1402- struct ipc_config_dai * dai = & dd -> ipc_config ;
1403- struct dma_config * dma_cfg ;
1404-
1405- dd -> uaol .fb_chan_idx = - EINVAL ;
1406- dd -> uaol .feedback_drift = 0 ;
1407- dd -> uaol .ms_since_last_adjustment = 0 ;
1408-
1409- if (dai -> type != SOF_DAI_INTEL_UAOL || dai -> direction != SOF_IPC_STREAM_PLAYBACK )
1410- return 0 ;
1411-
1412- /* UAOL feedback is an optional 2nd DMA link (1st is audio DMA link) */
1413- assert (GTW_DMA_DEVICE_MAX_COUNT >= 2 );
1414- if (!dai -> host_dma_config [1 ] || !dai -> host_dma_config [1 ]-> pre_allocated_by_host ) {
1415- comp_info (dev , "No UAOL feedback DMA link supplied by host!" );
1416- return 0 ;
1417- }
1418-
1419- int channel = dai -> host_dma_config [1 ]-> dma_channel_id ;
1420- comp_dbg (dev , "UAOL feedback channel = %d" , channel );
1421-
1422- /*
1423- * UAOL feedback endpoint payload is 4 bytes.
1424- * Hi-Speed USB microframe period is 125 us (8 per 1 ms).
1425- * Double the buffer size just in case.
1426- */
1427- dd -> uaol .fb_dma_buf_size = 4 * 8 * 2 ;
1428-
1429- /* TODO: perhaps get alignment by reading DMA alignment attribute? */
1430- dd -> uaol .fb_dma_buf = (uint32_t * )rballoc_align (SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA ,
1431- dd -> uaol .fb_dma_buf_size , 64 );
1432- if (!dd -> uaol .fb_dma_buf ) {
1433- comp_err (dev , "UAOL feedback buffer allocation failed!" );
1434- return - ENOMEM ;
1435- }
1436- memset (dd -> uaol .fb_dma_buf , 0 , dd -> uaol .fb_dma_buf_size );
1437-
1438- dma_cfg = rballoc (SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT | SOF_MEM_FLAG_DMA ,
1439- sizeof (struct dma_config ));
1440- if (!dma_cfg ) {
1441- rfree (dd -> uaol .fb_dma_buf );
1442- dd -> uaol .fb_dma_buf = NULL ;
1443- comp_err (dev , "dma_cfg allocation failed" );
1444- return - ENOMEM ;
1445- }
1446-
1447- memset (dma_cfg , 0 , sizeof (struct dma_config ));
1448- dma_cfg -> dma_slot = 0 ;
1449- dma_cfg -> channel_direction = PERIPHERAL_TO_MEMORY ;
1450- dma_cfg -> source_data_size = 4 ;
1451- dma_cfg -> dest_data_size = 4 ;
1452- dma_cfg -> source_burst_length = 4 ;
1453- dma_cfg -> dest_burst_length = 4 ;
1454- dma_cfg -> cyclic = 1 ;
1455- dma_cfg -> block_count = 1 ;
1456-
1457- dma_cfg -> head_block = rballoc (SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT | SOF_MEM_FLAG_DMA ,
1458- sizeof (struct dma_block_config ));
1459- if (!dma_cfg -> head_block ) {
1460- rfree (dma_cfg );
1461- rfree (dd -> uaol .fb_dma_buf );
1462- dd -> uaol .fb_dma_buf = NULL ;
1463- comp_err (dev , "dma_block_config allocation failed" );
1464- return - ENOMEM ;
1465- }
1466-
1467- memset (dma_cfg -> head_block , 0 , sizeof (struct dma_block_config ));
1468- dma_cfg -> head_block -> dest_scatter_en = 0 ;
1469- dma_cfg -> head_block -> block_size = dd -> uaol .fb_dma_buf_size ;
1470- dma_cfg -> head_block -> source_addr_adj = DMA_ADDR_ADJ_INCREMENT ;
1471- dma_cfg -> head_block -> dest_addr_adj = DMA_ADDR_ADJ_DECREMENT ; /* WHY? IS THIS OK??? */
1472- dma_cfg -> head_block -> source_address = 0 ;
1473- dma_cfg -> head_block -> dest_address = (uint32_t )local_to_host (dd -> uaol .fb_dma_buf );
1474- dma_cfg -> head_block -> next_block = dma_cfg -> head_block ;
1475- dd -> uaol .fb_z_config = dma_cfg ;
1476-
1477- /* get DMA channel */
1478- dd -> uaol .fb_chan_idx = sof_dma_request_channel (dd -> dma , channel );
1479- if (dd -> uaol .fb_chan_idx < 0 ) {
1480- rfree (dma_cfg -> head_block );
1481- rfree (dma_cfg );
1482- rfree (dd -> uaol .fb_dma_buf );
1483- dd -> uaol .fb_dma_buf = NULL ;
1484- comp_err (dev , "dma_request_channel() failed" );
1485- return - EIO ;
1486- }
1487-
1488- dsrc_init (& dd -> uaol .dsrc , dai -> gtw_fmt -> channels_count );
1489-
1490- comp_dbg (dev , "New configured UAOL feedback DMA channel index %d" , dd -> uaol .fb_chan_idx );
1491-
1492- return 0 ;
1493- }
1494- #endif //0
1495-
14961236int dai_common_config_prepare (struct dai_data * dd , struct comp_dev * dev )
14971237{
14981238 int channel ;
0 commit comments