24
24
#include <linux/slab.h>
25
25
#include <linux/of.h>
26
26
#include <linux/of_device.h>
27
+ #include <linux/of_dma.h>
27
28
28
29
#include "at_hdmac_regs.h"
29
30
#include "dmaengine.h"
@@ -676,7 +677,7 @@ atc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
676
677
ctrlb |= ATC_DST_ADDR_MODE_FIXED
677
678
| ATC_SRC_ADDR_MODE_INCR
678
679
| ATC_FC_MEM2PER
679
- | ATC_SIF (AT_DMA_MEM_IF ) | ATC_DIF (AT_DMA_PER_IF );
680
+ | ATC_SIF (atchan -> mem_if ) | ATC_DIF (atchan -> per_if );
680
681
reg = sconfig -> dst_addr ;
681
682
for_each_sg (sgl , sg , sg_len , i ) {
682
683
struct at_desc * desc ;
@@ -715,7 +716,7 @@ atc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
715
716
ctrlb |= ATC_DST_ADDR_MODE_INCR
716
717
| ATC_SRC_ADDR_MODE_FIXED
717
718
| ATC_FC_PER2MEM
718
- | ATC_SIF (AT_DMA_PER_IF ) | ATC_DIF (AT_DMA_MEM_IF );
719
+ | ATC_SIF (atchan -> per_if ) | ATC_DIF (atchan -> mem_if );
719
720
720
721
reg = sconfig -> src_addr ;
721
722
for_each_sg (sgl , sg , sg_len , i ) {
@@ -821,8 +822,8 @@ atc_dma_cyclic_fill_desc(struct dma_chan *chan, struct at_desc *desc,
821
822
desc -> lli .ctrlb = ATC_DST_ADDR_MODE_FIXED
822
823
| ATC_SRC_ADDR_MODE_INCR
823
824
| ATC_FC_MEM2PER
824
- | ATC_SIF (AT_DMA_MEM_IF )
825
- | ATC_DIF (AT_DMA_PER_IF );
825
+ | ATC_SIF (atchan -> mem_if )
826
+ | ATC_DIF (atchan -> per_if );
826
827
break ;
827
828
828
829
case DMA_DEV_TO_MEM :
@@ -832,8 +833,8 @@ atc_dma_cyclic_fill_desc(struct dma_chan *chan, struct at_desc *desc,
832
833
desc -> lli .ctrlb = ATC_DST_ADDR_MODE_INCR
833
834
| ATC_SRC_ADDR_MODE_FIXED
834
835
| ATC_FC_PER2MEM
835
- | ATC_SIF (AT_DMA_PER_IF )
836
- | ATC_DIF (AT_DMA_MEM_IF );
836
+ | ATC_SIF (atchan -> per_if )
837
+ | ATC_DIF (atchan -> mem_if );
837
838
break ;
838
839
839
840
default :
@@ -1189,6 +1190,67 @@ static void atc_free_chan_resources(struct dma_chan *chan)
1189
1190
dev_vdbg (chan2dev (chan ), "free_chan_resources: done\n" );
1190
1191
}
1191
1192
1193
+ #ifdef CONFIG_OF
1194
+ static bool at_dma_filter (struct dma_chan * chan , void * slave )
1195
+ {
1196
+ struct at_dma_slave * atslave = slave ;
1197
+
1198
+ if (atslave -> dma_dev == chan -> device -> dev ) {
1199
+ chan -> private = atslave ;
1200
+ return true;
1201
+ } else {
1202
+ return false;
1203
+ }
1204
+ }
1205
+
1206
+ static struct dma_chan * at_dma_xlate (struct of_phandle_args * dma_spec ,
1207
+ struct of_dma * of_dma )
1208
+ {
1209
+ struct dma_chan * chan ;
1210
+ struct at_dma_chan * atchan ;
1211
+ struct at_dma_slave * atslave ;
1212
+ dma_cap_mask_t mask ;
1213
+ unsigned int per_id ;
1214
+ struct platform_device * dmac_pdev ;
1215
+
1216
+ if (dma_spec -> args_count != 2 )
1217
+ return NULL ;
1218
+
1219
+ dmac_pdev = of_find_device_by_node (dma_spec -> np );
1220
+
1221
+ dma_cap_zero (mask );
1222
+ dma_cap_set (DMA_SLAVE , mask );
1223
+
1224
+ atslave = devm_kzalloc (& dmac_pdev -> dev , sizeof (* atslave ), GFP_KERNEL );
1225
+ if (!atslave )
1226
+ return NULL ;
1227
+ /*
1228
+ * We can fill both SRC_PER and DST_PER, one of these fields will be
1229
+ * ignored depending on DMA transfer direction.
1230
+ */
1231
+ per_id = dma_spec -> args [1 ];
1232
+ atslave -> cfg = ATC_FIFOCFG_HALFFIFO | ATC_DST_H2SEL_HW
1233
+ | ATC_SRC_H2SEL_HW | ATC_DST_PER (per_id )
1234
+ | ATC_SRC_PER (per_id );
1235
+ atslave -> dma_dev = & dmac_pdev -> dev ;
1236
+
1237
+ chan = dma_request_channel (mask , at_dma_filter , atslave );
1238
+ if (!chan )
1239
+ return NULL ;
1240
+
1241
+ atchan = to_at_dma_chan (chan );
1242
+ atchan -> per_if = dma_spec -> args [0 ] & 0xff ;
1243
+ atchan -> mem_if = (dma_spec -> args [0 ] >> 16 ) & 0xff ;
1244
+
1245
+ return chan ;
1246
+ }
1247
+ #else
1248
+ static struct dma_chan * at_dma_xlate (struct of_phandle_args * dma_spec ,
1249
+ struct of_dma * of_dma )
1250
+ {
1251
+ return NULL ;
1252
+ }
1253
+ #endif
1192
1254
1193
1255
/*-- Module Management -----------------------------------------------*/
1194
1256
@@ -1343,6 +1405,8 @@ static int __init at_dma_probe(struct platform_device *pdev)
1343
1405
for (i = 0 ; i < plat_dat -> nr_channels ; i ++ ) {
1344
1406
struct at_dma_chan * atchan = & atdma -> chan [i ];
1345
1407
1408
+ atchan -> mem_if = AT_DMA_MEM_IF ;
1409
+ atchan -> per_if = AT_DMA_PER_IF ;
1346
1410
atchan -> chan_common .device = & atdma -> dma_common ;
1347
1411
dma_cookie_init (& atchan -> chan_common );
1348
1412
list_add_tail (& atchan -> chan_common .device_node ,
@@ -1389,8 +1453,25 @@ static int __init at_dma_probe(struct platform_device *pdev)
1389
1453
1390
1454
dma_async_device_register (& atdma -> dma_common );
1391
1455
1456
+ /*
1457
+ * Do not return an error if the dmac node is not present in order to
1458
+ * not break the existing way of requesting channel with
1459
+ * dma_request_channel().
1460
+ */
1461
+ if (pdev -> dev .of_node ) {
1462
+ err = of_dma_controller_register (pdev -> dev .of_node ,
1463
+ at_dma_xlate , atdma );
1464
+ if (err ) {
1465
+ dev_err (& pdev -> dev , "could not register of_dma_controller\n" );
1466
+ goto err_of_dma_controller_register ;
1467
+ }
1468
+ }
1469
+
1392
1470
return 0 ;
1393
1471
1472
+ err_of_dma_controller_register :
1473
+ dma_async_device_unregister (& atdma -> dma_common );
1474
+ dma_pool_destroy (atdma -> dma_desc_pool );
1394
1475
err_pool_create :
1395
1476
platform_set_drvdata (pdev , NULL );
1396
1477
free_irq (platform_get_irq (pdev , 0 ), atdma );
0 commit comments