@@ -505,7 +505,6 @@ __cold int dai_common_new(struct dai_data *dd, struct comp_dev *dev,
505505
506506 dma_sg_init (& dd -> config .elem_array );
507507 dd -> xrun = 0 ;
508- dd -> chan = NULL ;
509508
510509#ifdef CONFIG_SOF_USERSPACE_LL
511510 /*
@@ -591,6 +590,8 @@ __cold static struct comp_dev *dai_new(const struct comp_driver *drv,
591590
592591 memset (dd , 0 , sizeof (* dd ));
593592 dd -> heap = heap ;
593+ dd -> chan_index = -1 ;
594+ comp_info (dev , "dd %p initialized, index %d" , dd , dd -> chan_index );
594595
595596 comp_set_drvdata (dev , dd );
596597
@@ -622,10 +623,8 @@ __cold void dai_common_free(struct dai_data *dd)
622623 if (dd -> group )
623624 dai_group_put (dd -> group );
624625
625- if (dd -> chan ) {
626- sof_dma_release_channel (dd -> dma , dd -> chan -> index );
627- dd -> chan -> dev_data = NULL ;
628- }
626+ if (dd -> chan_index != -1 )
627+ sof_dma_release_channel (dd -> dma , dd -> chan_index );
629628
630629 sof_dma_put (dd -> dma );
631630
@@ -1157,9 +1156,9 @@ int dai_common_config_prepare(struct dai_data *dd, struct comp_dev *dev)
11571156 return - EINVAL ;
11581157 }
11591158
1160- if (dd -> chan ) {
1159+ if (dd -> chan_index != -1 ) {
11611160 comp_info (dev , "dma channel index %d already configured" ,
1162- dd -> chan -> index );
1161+ dd -> chan_index );
11631162 return 0 ;
11641163 }
11651164
@@ -1173,18 +1172,14 @@ int dai_common_config_prepare(struct dai_data *dd, struct comp_dev *dev)
11731172 }
11741173
11751174 /* get DMA channel */
1176- channel = sof_dma_request_channel (dd -> dma , channel );
1177- if (channel < 0 ) {
1175+ dd -> chan_index = sof_dma_request_channel (dd -> dma , channel );
1176+ if (dd -> chan_index < 0 ) {
11781177 comp_err (dev , "dma_request_channel() failed" );
1179- dd -> chan = NULL ;
11801178 return - EIO ;
11811179 }
11821180
1183- dd -> chan = & dd -> dma -> chan [channel ];
1184- dd -> chan -> dev_data = dd ;
1185-
11861181 comp_dbg (dev , "new configured dma channel index %d" ,
1187- dd -> chan -> index );
1182+ dd -> chan_index );
11881183
11891184 return 0 ;
11901185}
@@ -1195,8 +1190,8 @@ int dai_common_prepare(struct dai_data *dd, struct comp_dev *dev)
11951190
11961191 dd -> total_data_processed = 0 ;
11971192
1198- if (! dd -> chan ) {
1199- comp_err (dev , "Missing dd->chan ." );
1193+ if (dd -> chan_index == -1 ) {
1194+ comp_err (dev , "Missing dd->chan_index ." );
12001195 comp_set_state (dev , COMP_TRIGGER_RESET );
12011196 return - EINVAL ;
12021197 }
@@ -1217,7 +1212,7 @@ int dai_common_prepare(struct dai_data *dd, struct comp_dev *dev)
12171212 return 0 ;
12181213 }
12191214
1220- ret = sof_dma_config (dd -> chan -> dma , dd -> chan -> index , dd -> z_config );
1215+ ret = sof_dma_config (dd -> dma , dd -> chan_index , dd -> z_config );
12211216 if (ret < 0 )
12221217 comp_set_state (dev , COMP_TRIGGER_RESET );
12231218
@@ -1304,7 +1299,7 @@ static int dai_comp_trigger_internal(struct dai_data *dd, struct comp_dev *dev,
13041299
13051300 /* only start the DAI if we are not XRUN handling */
13061301 if (dd -> xrun == 0 ) {
1307- ret = sof_dma_start (dd -> chan -> dma , dd -> chan -> index );
1302+ ret = sof_dma_start (dd -> dma , dd -> chan_index );
13081303 if (ret < 0 )
13091304 return ret ;
13101305
@@ -1342,16 +1337,16 @@ static int dai_comp_trigger_internal(struct dai_data *dd, struct comp_dev *dev,
13421337 /* only start the DAI if we are not XRUN handling */
13431338 if (dd -> xrun == 0 ) {
13441339 /* recover valid start position */
1345- ret = sof_dma_stop (dd -> chan -> dma , dd -> chan -> index );
1340+ ret = sof_dma_stop (dd -> dma , dd -> chan_index );
13461341 if (ret < 0 )
13471342 return ret ;
13481343
13491344 /* dma_config needed after stop */
1350- ret = sof_dma_config (dd -> chan -> dma , dd -> chan -> index , dd -> z_config );
1345+ ret = sof_dma_config (dd -> dma , dd -> chan_index , dd -> z_config );
13511346 if (ret < 0 )
13521347 return ret ;
13531348
1354- ret = sof_dma_start (dd -> chan -> dma , dd -> chan -> index );
1349+ ret = sof_dma_start (dd -> dma , dd -> chan_index );
13551350 if (ret < 0 )
13561351 return ret ;
13571352
@@ -1379,11 +1374,11 @@ static int dai_comp_trigger_internal(struct dai_data *dd, struct comp_dev *dev,
13791374 * as soon as possible.
13801375 */
13811376#if CONFIG_COMP_DAI_STOP_TRIGGER_ORDER_REVERSE
1382- ret = sof_dma_stop (dd -> chan -> dma , dd -> chan -> index );
1377+ ret = sof_dma_stop (dd -> dma , dd -> chan_index );
13831378 dai_trigger_op (dd -> dai , cmd , dev -> direction );
13841379#else
13851380 dai_trigger_op (dd -> dai , cmd , dev -> direction );
1386- ret = sof_dma_stop (dd -> chan -> dma , dd -> chan -> index );
1381+ ret = sof_dma_stop (dd -> dma , dd -> chan_index );
13871382 if (ret ) {
13881383 comp_warn (dev , "dma was stopped earlier" );
13891384 ret = 0 ;
@@ -1393,11 +1388,11 @@ static int dai_comp_trigger_internal(struct dai_data *dd, struct comp_dev *dev,
13931388 case COMP_TRIGGER_PAUSE :
13941389 comp_dbg (dev , "PAUSE" );
13951390#if CONFIG_COMP_DAI_STOP_TRIGGER_ORDER_REVERSE
1396- ret = sof_dma_suspend (dd -> chan -> dma , dd -> chan -> index );
1391+ ret = sof_dma_suspend (dd -> dma , dd -> chan_index );
13971392 dai_trigger_op (dd -> dai , cmd , dev -> direction );
13981393#else
13991394 dai_trigger_op (dd -> dai , cmd , dev -> direction );
1400- ret = sof_dma_suspend (dd -> chan -> dma , dd -> chan -> index );
1395+ ret = sof_dma_suspend (dd -> dma , dd -> chan_index );
14011396#endif
14021397 break ;
14031398 case COMP_TRIGGER_PRE_START :
@@ -1495,7 +1490,7 @@ static int dai_comp_trigger(struct comp_dev *dev, int cmd)
14951490 */
14961491static int dai_get_status (struct comp_dev * dev , struct dai_data * dd , struct dma_status * stat )
14971492{
1498- int ret = sof_dma_get_status (dd -> chan -> dma , dd -> chan -> index , stat );
1493+ int ret = sof_dma_get_status (dd -> dma , dd -> chan_index , stat );
14991494#if CONFIG_XRUN_NOTIFICATIONS_ENABLE
15001495 if (ret == - EPIPE && !dd -> xrun_notification_sent ) {
15011496 struct ipc_msg * notify = ipc_notification_pool_get (IPC4_RESOURCE_EVENT_SIZE );
@@ -1611,7 +1606,7 @@ int dai_zephyr_multi_endpoint_copy(struct dai_data **dd, struct comp_dev *dev,
16111606#endif
16121607
16131608 for (i = 0 ; i < num_endpoints ; i ++ ) {
1614- ret = sof_dma_reload (dd [i ]-> chan -> dma , dd [i ]-> chan -> index , 0 );
1609+ ret = sof_dma_reload (dd [i ]-> dma , dd [i ]-> chan_index , 0 );
16151610 if (ret < 0 ) {
16161611 dai_report_reload_xrun (dd [i ], dev , 0 );
16171612 return ret ;
@@ -1637,10 +1632,10 @@ int dai_zephyr_multi_endpoint_copy(struct dai_data **dd, struct comp_dev *dev,
16371632
16381633 status = dai_dma_multi_endpoint_cb (dd [i ], dev , frames , multi_endpoint_buffer );
16391634 if (status == SOF_DMA_CB_STATUS_END )
1640- sof_dma_stop (dd [i ]-> chan -> dma , dd [i ]-> chan -> index );
1635+ sof_dma_stop (dd [i ]-> dma , dd [i ]-> chan_index );
16411636
16421637 copy_bytes = frames * audio_stream_frame_bytes (& dd [i ]-> dma_buffer -> stream );
1643- ret = sof_dma_reload (dd [i ]-> chan -> dma , dd [i ]-> chan -> index , copy_bytes );
1638+ ret = sof_dma_reload (dd [i ]-> dma , dd [i ]-> chan_index , copy_bytes );
16441639 if (ret < 0 ) {
16451640 dai_report_reload_xrun (dd [i ], dev , copy_bytes );
16461641 return ret ;
@@ -1829,7 +1824,7 @@ int dai_common_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_fun
18291824 comp_warn (dev , "nothing to copy, src_frames: %u, sink_frames: %u" ,
18301825 src_frames , sink_frames );
18311826#endif
1832- sof_dma_reload (dd -> chan -> dma , dd -> chan -> index , 0 );
1827+ sof_dma_reload (dd -> dma , dd -> chan_index , 0 );
18331828 return 0 ;
18341829 }
18351830
@@ -1839,9 +1834,9 @@ int dai_common_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_fun
18391834 comp_warn (dev , "dai trigger copy failed" );
18401835
18411836 if (dai_dma_cb (dd , dev , copy_bytes , converter ) == SOF_DMA_CB_STATUS_END )
1842- sof_dma_stop (dd -> chan -> dma , dd -> chan -> index );
1837+ sof_dma_stop (dd -> dma , dd -> chan_index );
18431838
1844- ret = sof_dma_reload (dd -> chan -> dma , dd -> chan -> index , copy_bytes );
1839+ ret = sof_dma_reload (dd -> dma , dd -> chan_index , copy_bytes );
18451840 if (ret < 0 ) {
18461841 dai_report_reload_xrun (dd , dev , copy_bytes );
18471842 return ret ;
@@ -1879,7 +1874,7 @@ int dai_common_ts_config_op(struct dai_data *dd, struct comp_dev *dev)
18791874 struct dai_ts_cfg * cfg = & dd -> ts_config ;
18801875
18811876 comp_dbg (dev , "dai_ts_config()" );
1882- if (! dd -> chan ) {
1877+ if (dd -> chan_index == -1 ) {
18831878 comp_err (dev , "No DMA channel information" );
18841879 return - EINVAL ;
18851880 }
@@ -1902,7 +1897,7 @@ int dai_common_ts_config_op(struct dai_data *dd, struct comp_dev *dev)
19021897 cfg -> direction = dai -> direction ;
19031898 cfg -> index = dd -> dai -> index ;
19041899 cfg -> dma_id = dd -> dma -> plat_data .id ;
1905- cfg -> dma_chan_index = dd -> chan -> index ;
1900+ cfg -> dma_chan_index = dd -> chan_index ;
19061901 cfg -> dma_chan_count = dd -> dma -> plat_data .channels ;
19071902
19081903 return dai_ts_config (dd -> dai -> dev , cfg );
0 commit comments