@@ -198,12 +198,12 @@ struct sdma_script_start_addrs {
198
198
s32 per_2_firi_addr ;
199
199
s32 mcu_2_firi_addr ;
200
200
s32 uart_2_per_addr ;
201
- s32 uart_2_mcu_addr ;
201
+ s32 uart_2_mcu_ram_addr ;
202
202
s32 per_2_app_addr ;
203
203
s32 mcu_2_app_addr ;
204
204
s32 per_2_per_addr ;
205
205
s32 uartsh_2_per_addr ;
206
- s32 uartsh_2_mcu_addr ;
206
+ s32 uartsh_2_mcu_ram_addr ;
207
207
s32 per_2_shp_addr ;
208
208
s32 mcu_2_shp_addr ;
209
209
s32 ata_2_mcu_addr ;
@@ -230,6 +230,10 @@ struct sdma_script_start_addrs {
230
230
s32 zcanfd_2_mcu_addr ;
231
231
s32 zqspi_2_mcu_addr ;
232
232
s32 mcu_2_ecspi_addr ;
233
+ s32 mcu_2_sai_addr ;
234
+ s32 sai_2_mcu_addr ;
235
+ s32 uart_2_mcu_addr ;
236
+ s32 uartsh_2_mcu_addr ;
233
237
/* End of v3 array */
234
238
s32 mcu_2_zqspi_addr ;
235
239
/* End of v4 array */
@@ -433,9 +437,10 @@ struct sdma_channel {
433
437
unsigned long watermark_level ;
434
438
u32 shp_addr , per_addr ;
435
439
enum dma_status status ;
436
- bool context_loaded ;
437
440
struct imx_dma_data data ;
438
441
struct work_struct terminate_worker ;
442
+ struct list_head terminated ;
443
+ bool is_ram_script ;
439
444
};
440
445
441
446
#define IMX_DMA_SG_LOOP BIT(0)
@@ -476,6 +481,13 @@ struct sdma_driver_data {
476
481
int num_events ;
477
482
struct sdma_script_start_addrs * script_addrs ;
478
483
bool check_ratio ;
484
+ /*
485
+ * ecspi ERR009165 fixed should be done in sdma script
486
+ * and it has been fixed in soc from i.mx6ul.
487
+ * please get more information from the below link:
488
+ * https://www.nxp.com/docs/en/errata/IMX6DQCE.pdf
489
+ */
490
+ bool ecspi_fixed ;
479
491
};
480
492
481
493
struct sdma_engine {
@@ -499,6 +511,7 @@ struct sdma_engine {
499
511
struct sdma_buffer_descriptor * bd0 ;
500
512
/* clock ratio for AHB:SDMA core. 1:1 is 1, 2:1 is 0*/
501
513
bool clk_ratio ;
514
+ bool fw_loaded ;
502
515
};
503
516
504
517
static int sdma_config_write (struct dma_chan * chan ,
@@ -595,6 +608,13 @@ static struct sdma_driver_data sdma_imx6q = {
595
608
.script_addrs = & sdma_script_imx6q ,
596
609
};
597
610
611
+ static struct sdma_driver_data sdma_imx6ul = {
612
+ .chnenbl0 = SDMA_CHNENBL0_IMX35 ,
613
+ .num_events = 48 ,
614
+ .script_addrs = & sdma_script_imx6q ,
615
+ .ecspi_fixed = true,
616
+ };
617
+
598
618
static struct sdma_script_start_addrs sdma_script_imx7d = {
599
619
.ap_2_ap_addr = 644 ,
600
620
.uart_2_mcu_addr = 819 ,
@@ -628,6 +648,7 @@ static const struct of_device_id sdma_dt_ids[] = {
628
648
{ .compatible = "fsl,imx31-sdma" , .data = & sdma_imx31 , },
629
649
{ .compatible = "fsl,imx25-sdma" , .data = & sdma_imx25 , },
630
650
{ .compatible = "fsl,imx7d-sdma" , .data = & sdma_imx7d , },
651
+ { .compatible = "fsl,imx6ul-sdma" , .data = & sdma_imx6ul , },
631
652
{ .compatible = "fsl,imx8mq-sdma" , .data = & sdma_imx8mq , },
632
653
{ /* sentinel */ }
633
654
};
@@ -919,6 +940,7 @@ static void sdma_get_pc(struct sdma_channel *sdmac,
919
940
sdmac -> pc_to_device = 0 ;
920
941
sdmac -> device_to_device = 0 ;
921
942
sdmac -> pc_to_pc = 0 ;
943
+ sdmac -> is_ram_script = false;
922
944
923
945
switch (peripheral_type ) {
924
946
case IMX_DMATYPE_MEMORY :
@@ -945,6 +967,17 @@ static void sdma_get_pc(struct sdma_channel *sdmac,
945
967
emi_2_per = sdma -> script_addrs -> mcu_2_ata_addr ;
946
968
break ;
947
969
case IMX_DMATYPE_CSPI :
970
+ per_2_emi = sdma -> script_addrs -> app_2_mcu_addr ;
971
+
972
+ /* Use rom script mcu_2_app if ERR009165 fixed */
973
+ if (sdmac -> sdma -> drvdata -> ecspi_fixed ) {
974
+ emi_2_per = sdma -> script_addrs -> mcu_2_app_addr ;
975
+ } else {
976
+ emi_2_per = sdma -> script_addrs -> mcu_2_ecspi_addr ;
977
+ sdmac -> is_ram_script = true;
978
+ }
979
+
980
+ break ;
948
981
case IMX_DMATYPE_EXT :
949
982
case IMX_DMATYPE_SSI :
950
983
case IMX_DMATYPE_SAI :
@@ -954,6 +987,7 @@ static void sdma_get_pc(struct sdma_channel *sdmac,
954
987
case IMX_DMATYPE_SSI_DUAL :
955
988
per_2_emi = sdma -> script_addrs -> ssish_2_mcu_addr ;
956
989
emi_2_per = sdma -> script_addrs -> mcu_2_ssish_addr ;
990
+ sdmac -> is_ram_script = true;
957
991
break ;
958
992
case IMX_DMATYPE_SSI_SP :
959
993
case IMX_DMATYPE_MMC :
@@ -968,6 +1002,7 @@ static void sdma_get_pc(struct sdma_channel *sdmac,
968
1002
per_2_emi = sdma -> script_addrs -> asrc_2_mcu_addr ;
969
1003
emi_2_per = sdma -> script_addrs -> asrc_2_mcu_addr ;
970
1004
per_2_per = sdma -> script_addrs -> per_2_per_addr ;
1005
+ sdmac -> is_ram_script = true;
971
1006
break ;
972
1007
case IMX_DMATYPE_ASRC_SP :
973
1008
per_2_emi = sdma -> script_addrs -> shp_2_mcu_addr ;
@@ -1008,9 +1043,6 @@ static int sdma_load_context(struct sdma_channel *sdmac)
1008
1043
int ret ;
1009
1044
unsigned long flags ;
1010
1045
1011
- if (sdmac -> context_loaded )
1012
- return 0 ;
1013
-
1014
1046
if (sdmac -> direction == DMA_DEV_TO_MEM )
1015
1047
load_address = sdmac -> pc_from_device ;
1016
1048
else if (sdmac -> direction == DMA_DEV_TO_DEV )
@@ -1053,8 +1085,6 @@ static int sdma_load_context(struct sdma_channel *sdmac)
1053
1085
1054
1086
spin_unlock_irqrestore (& sdma -> channel_0_lock , flags );
1055
1087
1056
- sdmac -> context_loaded = true;
1057
-
1058
1088
return ret ;
1059
1089
}
1060
1090
@@ -1078,9 +1108,6 @@ static void sdma_channel_terminate_work(struct work_struct *work)
1078
1108
{
1079
1109
struct sdma_channel * sdmac = container_of (work , struct sdma_channel ,
1080
1110
terminate_worker );
1081
- unsigned long flags ;
1082
- LIST_HEAD (head );
1083
-
1084
1111
/*
1085
1112
* According to NXP R&D team a delay of one BD SDMA cost time
1086
1113
* (maximum is 1ms) should be added after disable of the channel
@@ -1089,11 +1116,7 @@ static void sdma_channel_terminate_work(struct work_struct *work)
1089
1116
*/
1090
1117
usleep_range (1000 , 2000 );
1091
1118
1092
- spin_lock_irqsave (& sdmac -> vc .lock , flags );
1093
- vchan_get_all_descriptors (& sdmac -> vc , & head );
1094
- spin_unlock_irqrestore (& sdmac -> vc .lock , flags );
1095
- vchan_dma_desc_free_list (& sdmac -> vc , & head );
1096
- sdmac -> context_loaded = false;
1119
+ vchan_dma_desc_free_list (& sdmac -> vc , & sdmac -> terminated );
1097
1120
}
1098
1121
1099
1122
static int sdma_terminate_all (struct dma_chan * chan )
@@ -1107,6 +1130,13 @@ static int sdma_terminate_all(struct dma_chan *chan)
1107
1130
1108
1131
if (sdmac -> desc ) {
1109
1132
vchan_terminate_vdesc (& sdmac -> desc -> vd );
1133
+ /*
1134
+ * move out current descriptor into terminated list so that
1135
+ * it could be free in sdma_channel_terminate_work alone
1136
+ * later without potential involving next descriptor raised
1137
+ * up before the last descriptor terminated.
1138
+ */
1139
+ vchan_get_all_descriptors (& sdmac -> vc , & sdmac -> terminated );
1110
1140
sdmac -> desc = NULL ;
1111
1141
schedule_work (& sdmac -> terminate_worker );
1112
1142
}
@@ -1168,7 +1198,6 @@ static void sdma_set_watermarklevel_for_p2p(struct sdma_channel *sdmac)
1168
1198
static int sdma_config_channel (struct dma_chan * chan )
1169
1199
{
1170
1200
struct sdma_channel * sdmac = to_sdma_chan (chan );
1171
- int ret ;
1172
1201
1173
1202
sdma_disable_channel (chan );
1174
1203
@@ -1208,9 +1237,7 @@ static int sdma_config_channel(struct dma_chan *chan)
1208
1237
sdmac -> watermark_level = 0 ; /* FIXME: M3_BASE_ADDRESS */
1209
1238
}
1210
1239
1211
- ret = sdma_load_context (sdmac );
1212
-
1213
- return ret ;
1240
+ return 0 ;
1214
1241
}
1215
1242
1216
1243
static int sdma_set_channel_priority (struct sdma_channel * sdmac ,
@@ -1361,7 +1388,6 @@ static void sdma_free_chan_resources(struct dma_chan *chan)
1361
1388
1362
1389
sdmac -> event_id0 = 0 ;
1363
1390
sdmac -> event_id1 = 0 ;
1364
- sdmac -> context_loaded = false;
1365
1391
1366
1392
sdma_set_channel_priority (sdmac , 0 );
1367
1393
@@ -1374,6 +1400,11 @@ static struct sdma_desc *sdma_transfer_init(struct sdma_channel *sdmac,
1374
1400
{
1375
1401
struct sdma_desc * desc ;
1376
1402
1403
+ if (!sdmac -> sdma -> fw_loaded && sdmac -> is_ram_script ) {
1404
+ dev_warn_once (sdmac -> sdma -> dev , "sdma firmware not ready!\n" );
1405
+ goto err_out ;
1406
+ }
1407
+
1377
1408
desc = kzalloc ((sizeof (* desc )), GFP_NOWAIT );
1378
1409
if (!desc )
1379
1410
goto err_out ;
@@ -1722,8 +1753,8 @@ static void sdma_issue_pending(struct dma_chan *chan)
1722
1753
1723
1754
#define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V1 34
1724
1755
#define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V2 38
1725
- #define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V3 41
1726
- #define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V4 42
1756
+ #define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V3 45
1757
+ #define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V4 46
1727
1758
1728
1759
static void sdma_add_scripts (struct sdma_engine * sdma ,
1729
1760
const struct sdma_script_start_addrs * addr )
@@ -1747,6 +1778,19 @@ static void sdma_add_scripts(struct sdma_engine *sdma,
1747
1778
for (i = 0 ; i < sdma -> script_number ; i ++ )
1748
1779
if (addr_arr [i ] > 0 )
1749
1780
saddr_arr [i ] = addr_arr [i ];
1781
+
1782
+ /*
1783
+ * get uart_2_mcu_addr/uartsh_2_mcu_addr rom script specially because
1784
+ * they are now replaced by uart_2_mcu_ram_addr/uartsh_2_mcu_ram_addr
1785
+ * to be compatible with legacy freescale/nxp sdma firmware, and they
1786
+ * are located in the bottom part of sdma_script_start_addrs which are
1787
+ * beyond the SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V1.
1788
+ */
1789
+ if (addr -> uart_2_mcu_addr )
1790
+ sdma -> script_addrs -> uart_2_mcu_addr = addr -> uart_2_mcu_addr ;
1791
+ if (addr -> uartsh_2_mcu_addr )
1792
+ sdma -> script_addrs -> uartsh_2_mcu_addr = addr -> uartsh_2_mcu_addr ;
1793
+
1750
1794
}
1751
1795
1752
1796
static void sdma_load_firmware (const struct firmware * fw , void * context )
@@ -1803,6 +1847,8 @@ static void sdma_load_firmware(const struct firmware *fw, void *context)
1803
1847
1804
1848
sdma_add_scripts (sdma , addr );
1805
1849
1850
+ sdma -> fw_loaded = true;
1851
+
1806
1852
dev_info (sdma -> dev , "loaded firmware %d.%d\n" ,
1807
1853
header -> version_major ,
1808
1854
header -> version_minor );
@@ -2086,6 +2132,7 @@ static int sdma_probe(struct platform_device *pdev)
2086
2132
2087
2133
sdmac -> channel = i ;
2088
2134
sdmac -> vc .desc_free = sdma_desc_free ;
2135
+ INIT_LIST_HEAD (& sdmac -> terminated );
2089
2136
INIT_WORK (& sdmac -> terminate_worker ,
2090
2137
sdma_channel_terminate_work );
2091
2138
/*
0 commit comments