1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
|
/*
* Copyright 2004-2009 Freescale Semiconductor, Inc. All Rights Reserved.
*/
/*
* The code contained herein is licensed under the GNU General Public
* License. You may obtain a copy of the GNU General Public License
* Version 2 or later at the following locations:
*
* http://www.opensource.org/licenses/gpl-license.html
* http://www.gnu.org/copyleft/gpl.html
*/
/* Front-end to the DMA handling. This handles the allocation/freeing
* of DMA channels, and provides a unified interface to the machines
* DMA facilities.
*/
/*!
* @file plat-mxc/dma_mx2.c
* @brief This file contains functions for DMA API
*
* @ingroup DMA_MX27
*/
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/sched.h>
#include <linux/mman.h>
#include <linux/init.h>
#include <linux/spinlock.h>
#include <linux/interrupt.h>
#include <linux/clk.h>
#include <linux/proc_fs.h>
#include <linux/io.h>
#include <mach/hardware.h>
#include <mach/dma.h>
#include <asm/delay.h>
#include <asm/atomic.h>
/* commented temperily for mx27 compilation
#define DMA_PM
*/
#ifdef DMA_PM
#include <linux/pm.h>
#include <mach/apmc.h>
struct apmc_user *dma_apmc_user;
struct pm_dev *dma_pm;
#define DMA_PMST_RESUME 0
#define DMA_PMST_STANDBY 1
#define DMA_PMST_SUSPEND 2
static unsigned int dma_pm_status = DMA_PMST_RESUME;
#endif
/*!
* This variable is used to controll the clock of DMA.
* It counts the number of actived channels
*/
static atomic_t g_dma_actived = ATOMIC_INIT(0);
/*!
* This variable point a proc file which contains the information
* of DMA channels
*/
static struct proc_dir_entry *g_proc_dir;
/*!
* The dma channels
*/
static mxc_dma_channel_t g_dma_channels[MAX_DMA_CHANNELS];
static mx2_dma_priv_t g_dma_privates[MXC_DMA_CHANNELS];
static mx2_dma_bd_t g_dma_bd_table[MXC_DMA_CHANNELS][MAX_BD_SIZE];
static DEFINE_SPINLOCK(dma_list_lock);
static struct clk *dma_clk;
/*!@brief flush buffer descriptor ring*/
#define flush_dma_bd(private) \
{ \
atomic_set(&(private->bd_used), 0); \
private->bd_rd = private->bd_wr;\
}
/*!@brief get next buffer discriptor */
#define next_dma_bd(private) \
({ \
int bd_next = (private->bd_rd+1)%MAX_BD_SIZE; \
(bd_next == private->bd_wr) ? NULL: private->bd_ring+bd_next;\
})
static inline int consume_dma_bd(mxc_dma_channel_t * dma, int error);
/*!
*@brief allocate a dma channel.
*
*@param idx Requested channel NO.
* @li MXC_INVLAID_CHANNEL System allocates a free channel which is not statically allocated.
* @li Others User requests a specific channel
*@return @li MXC_INVLAID_CHANNEL Failure
* @li Others Success
*/
static inline int get_dma_channel(int idx)
{
int i;
mxc_dma_channel_t *p;
if ((idx >= MAX_DMA_CHANNELS) && (idx != MXC_DMA_DYNAMIC_CHANNEL)) {
return -1;
}
if (idx != MXC_DMA_DYNAMIC_CHANNEL) {
p = g_dma_channels + idx;
BUG_ON(p->dynamic != 0);
if (xchg(&p->lock, 1) != 0) {
return -1;
}
return idx;
}
p = g_dma_channels;
for (i = 0; (i < MAX_DMA_CHANNELS); i++, p++) {
if (p->dynamic && (xchg(&p->lock, 1) == 0)) {
return i;
}
}
return -1;
}
/*!
*@brief release a dma channel.
*
*@param idx channel number
*@return none;
*/
static inline void put_dma_channel(int idx)
{
mxc_dma_channel_t *p;
if ((idx < MAX_DMA_CHANNELS) && (idx >= 0)) {
p = g_dma_channels + idx;
(void)xchg(&p->lock, 0);
}
}
/*!
*@brief Get dma list for /proc/dma
*/
static int mxc_get_dma_list(char *buf)
{
mxc_dma_channel_t *dma;
char *p = buf;
int i;
for (i = 0, dma = g_dma_channels; i < MAX_DMA_CHANNELS; i++, dma++) {
if (dma->lock) {
p += sprintf(p, "dma channel %2d: %s\n", i,
dma->dev_name ? dma->dev_name : "unknown");
} else {
p += sprintf(p, "dma channel %2d: unused\n", i);
}
}
return p - buf;
}
/*!@brief save the mask of dma interrupts*/
#define save_dma_interrupt(flags) \
flags = __raw_readl(IO_ADDRESS(DMA_BASE_ADDR) + DMA_DIMR)
/*!@brief restore the mask of dma interrupts*/
#define restore_dma_interrupt(flags) \
__raw_writel(flags, IO_ADDRESS(DMA_BASE_ADDR) + DMA_DIMR)
/*!@brief disable interrupt of dma channel*/
static inline void mask_dma_interrupt(int channel)
{
unsigned long reg;
save_dma_interrupt(reg);
reg |= 1 << channel; /*mask interrupt; */
restore_dma_interrupt(reg);
}
/*!@brief enable interrupt of dma channel */
static inline void unmask_dma_interrupt(int channel)
{
unsigned long reg;
save_dma_interrupt(reg);
reg &= ~(1 << channel); /*unmask interrupt; */
restore_dma_interrupt(reg);
}
/*!@brief get interrupt event of dma channel */
static unsigned long inline __get_dma_interrupt(int channel)
{
unsigned long mode;
mode = 0;
if (__raw_readl(IO_ADDRESS(DMA_BASE_ADDR) + DMA_DISR) & (1 << channel))
mode |= DMA_DONE;
if (__raw_readl(IO_ADDRESS(DMA_BASE_ADDR) + DMA_DBTOSR) &
(1 << channel))
mode |= DMA_BURST_TIMEOUT;
if (__raw_readl(IO_ADDRESS(DMA_BASE_ADDR) + DMA_DSESR) & (1 << channel))
mode |= DMA_TRANSFER_ERROR;
if (__raw_readl(IO_ADDRESS(DMA_BASE_ADDR) + DMA_DBOSR) & (1 << channel))
mode |= DMA_BUFFER_OVERFLOW;
if (__raw_readl(IO_ADDRESS(DMA_BASE_ADDR) + DMA_DRTOSR) &
(1 << channel))
mode |= DMA_REQUEST_TIMEOUT;
return mode;
}
/*!
*@brief clean all event of dma interrupt and return the valid event.
*/
static unsigned long inline __clear_dma_interrupt(int channel)
{
unsigned long mode;
mode = __get_dma_interrupt(channel);
__raw_writel(1 << channel, IO_ADDRESS(DMA_BASE_ADDR) + DMA_DISR);
__raw_writel(1 << channel, IO_ADDRESS(DMA_BASE_ADDR) + DMA_DBTOSR);
__raw_writel(1 << channel, IO_ADDRESS(DMA_BASE_ADDR) + DMA_DRTOSR);
__raw_writel(1 << channel, IO_ADDRESS(DMA_BASE_ADDR) + DMA_DSESR);
__raw_writel(1 << channel, IO_ADDRESS(DMA_BASE_ADDR) + DMA_DBOSR);
return mode;
}
/*!@brief This function enables dma clocks without lock */
static void inline __enable_dma_clk(void)
{
unsigned long reg;
clk_enable(dma_clk);
reg = __raw_readl(IO_ADDRESS(DMA_BASE_ADDR) + DMA_DCR);
reg |= 0x1;
__raw_writel(reg, IO_ADDRESS(DMA_BASE_ADDR) + DMA_DCR);
}
/*!@brief This function disables dma clocks without lock */
static void inline __disable_dma_clk(void)
{
unsigned long reg;
reg = __raw_readl(IO_ADDRESS(DMA_BASE_ADDR) + DMA_DCR);
reg &= ~0x1;
__raw_writel(reg, IO_ADDRESS(DMA_BASE_ADDR) + DMA_DCR);
clk_disable(dma_clk);
}
/*!@brief This function enables dma clocks with lock */
static void inline enable_dma_clk(void)
{
unsigned long flags;
spin_lock_irqsave(&dma_list_lock, flags);
if (atomic_read(&g_dma_actived) == 0) {
__enable_dma_clk();
}
spin_unlock_irqrestore(&dma_list_lock, flags);
return;
}
/*!@brief This function disables dma clocks without locked */
static void inline disable_dma_clk(void)
{
unsigned long flags;
spin_lock_irqsave(&dma_list_lock, flags);
if (atomic_read(&g_dma_actived) == 0) {
__disable_dma_clk();
}
spin_unlock_irqrestore(&dma_list_lock, flags);
return;
}
/*!@brief select a buffer to transfer and
* setup dma channel for current transfer
*/
static void setup_dmac(mxc_dma_channel_t * dma)
{
mx2_dma_priv_t *priv = (mx2_dma_priv_t *) dma->private;
dma_regs_t *dma_base = (dma_regs_t *) (priv->dma_base);
mx2_dma_bd_t *p, *q;
unsigned long ctrl_val;
if (dma->active == 0) {
printk(KERN_ERR
"dma channel %d is not enabled, when receiving this channel 's interrupt\n",
dma->channel);
return;
}
if (atomic_read(&(priv->bd_used)) <= 0) {
printk(KERN_ERR "dma channel %d is empty\n", dma->channel);
dma->active = 0;
atomic_dec(&g_dma_actived);
return;
}
/* BUSY: transfering
* PEND: Wait for set to DMAC.
* s1: no transfering:
* set first(one BUSY). if there are more than one tranfer. set second &repeat is enabled(two BUSY).
*
* s2: transfering & just on transfer
* one BUSY. set the tranesfer and set repeat bit(two BUSY)
* s3: transfering & repeat has set
* has two BUSY.
*/
p = priv->bd_ring + priv->bd_rd;
q = next_dma_bd(priv);
if (!(p->state & DMA_BD_ST_BUSY)) {
/*NOTICE:: This is first buffer or dma chain does not support chain-buffer. So CEN must clear & set again */
ctrl_val =
__raw_readl(&(dma_base->Ctl)) &
(~(DMA_CTL_ACRPT | DMA_CTL_RPT | DMA_CTL_CEN));
__raw_writel(ctrl_val, &(dma_base->Ctl));
if (p->mode != dma->mode) {
dma->mode = p->mode; /* bi-dir channel do mode change */
if (dma->mode == MXC_DMA_MODE_READ) {
DMA_CTL_SET_SMOD(ctrl_val,
priv->dma_info->sourceType);
DMA_CTL_SET_SSIZ(ctrl_val,
priv->dma_info->sourcePort);
DMA_CTL_SET_DMOD(ctrl_val,
priv->dma_info->destType);
DMA_CTL_SET_DSIZ(ctrl_val,
priv->dma_info->destPort);
} else {
DMA_CTL_SET_SMOD(ctrl_val,
priv->dma_info->destType);
DMA_CTL_SET_SSIZ(ctrl_val,
priv->dma_info->destPort);
DMA_CTL_SET_DMOD(ctrl_val,
priv->dma_info->sourceType);
DMA_CTL_SET_DSIZ(ctrl_val,
priv->dma_info->sourcePort);
}
}
__raw_writel(p->src_addr, &(dma_base->SourceAddr));
__raw_writel(p->dst_addr, &(dma_base->DestAddr));
__raw_writel(p->count, &(dma_base->Count));
p->state |= DMA_BD_ST_BUSY;
p->state &= ~(DMA_BD_ST_PEND);
ctrl_val |= DMA_CTL_CEN;
__raw_writel(ctrl_val, &(dma_base->Ctl));
if (q && priv->dma_chaining) { /*DO chain-buffer */
__raw_writel(q->src_addr, &(dma_base->SourceAddr));
__raw_writel(q->dst_addr, &(dma_base->DestAddr));
__raw_writel(q->count, &(dma_base->Count));
q->state |= DMA_BD_ST_BUSY;
q->state &= ~(DMA_BD_ST_PEND);
ctrl_val |= DMA_CTL_ACRPT | DMA_CTL_RPT | DMA_CTL_CEN;
__raw_writel(ctrl_val, &(dma_base->Ctl));
}
} else { /* Just dma channel which supports dma buffer can run to there */
BUG_ON(!priv->dma_chaining);
if (q) { /* p is tranfering, then q must be set into dma controller */
/*WARNING:: [1] dangerous area begin.
* If the p is completed during MCU run in this erea, the dma channel is crashed.
*/
__raw_writel(q->src_addr, &(dma_base->SourceAddr));
__raw_writel(q->dst_addr, &(dma_base->DestAddr));
__raw_writel(q->count, &(dma_base->Count));
/*WARNING:: [2] dangerous area end */
ctrl_val =
__raw_readl(&(dma_base->Ctl)) | (DMA_CTL_ACRPT |
DMA_CTL_RPT |
DMA_CTL_CEN);
__raw_writel(ctrl_val, &(dma_base->Ctl));
/* WARNING:: This is workaround and it is dangerous:
* the judgement is not safety.
*/
if (!__get_dma_interrupt(dma->channel)) {
q->state |= DMA_BD_ST_BUSY;
q->state &= ~(DMA_BD_ST_PEND);
} else {
/*Waiting re-enable is in ISR */
printk(KERN_ERR
"Warning:: The privous transfer is completed. Maybe the chain buffer is stopped.");
}
} else { /* Last buffer is transfering: just clear RPT bit */
ctrl_val =
__raw_readl(&(dma_base->Ctl)) &
(~(DMA_CTL_ACRPT | DMA_CTL_RPT));
__raw_writel(ctrl_val, &(dma_base->Ctl));
}
}
}
/*!
* @brief interrupt handler of dma channel
*/
static irqreturn_t dma_irq_handler(int irq, void *dev_id)
{
mxc_dma_channel_t *dma = (mxc_dma_channel_t *) dev_id;
mx2_dma_priv_t *priv = (mx2_dma_priv_t *) (dma ? dma->private : NULL);
dma_regs_t *dma_base;
int state, error = MXC_DMA_DONE;
BUG_ON(priv == NULL);
dma_base = (dma_regs_t *) priv->dma_base;
state = __clear_dma_interrupt(dma->channel);
priv->trans_bytes += dma_base->transferd;
if (state != DMA_DONE) {
if (state & DMA_REQUEST_TIMEOUT) {
error = MXC_DMA_REQUEST_TIMEOUT;
} else {
error = MXC_DMA_TRANSFER_ERROR;
}
}
if (consume_dma_bd(dma, error)) {
disable_dma_clk();
if (dma->cb_fn) {
dma->cb_fn(dma->cb_args, error, priv->trans_bytes);
}
priv->trans_bytes = 0;
} else {
disable_dma_clk();
}
return IRQ_HANDLED;
}
/*!
*@brief Set DMA channel parameters
*
*@param dma Requested channel NO.
*@param dma_info Channel configuration
*@return @li 0 Success
* @li others Failure
*/
static int setup_dma_channel(mxc_dma_channel_t * dma, mx2_dma_info_t * dma_info)
{
mx2_dma_priv_t *priv = (mx2_dma_priv_t *) (dma ? dma->private : NULL);
dma_regs_t *dma_base;
unsigned long reg;
if (!dma_info || !priv) {
return -1;
}
if (dma_info->sourceType > 3) {
return -1;
}
if (dma_info->destType > 3) {
return -1;
}
if (dma_info->destPort > 3) {
return -1;
}
if (dma_info->sourcePort > 3) {
return -1;
}
if (dma_info->M2D_Valid) {
/*add for second dma */
if (dma_info->W < dma_info->X) {
return -1;
}
}
priv->dma_chaining = dma_info->dma_chaining;
priv->ren = dma_info->ren;
if (dma_info->sourceType != DMA_TYPE_FIFO
&& dma_info->destType != DMA_TYPE_FIFO) {
if (dma_info->ren) {
printk(KERN_INFO
"Warning:request enable just affect source or destination port is FIFO !\n");
priv->ren = 0;
}
}
if (dma_info->M2D_Valid) {
if (dma_info->msel) {
__raw_writel(dma_info->W,
IO_ADDRESS(DMA_BASE_ADDR) + DMA_WSRB);
__raw_writel(dma_info->X,
IO_ADDRESS(DMA_BASE_ADDR) + DMA_XSRB);
__raw_writel(dma_info->Y,
IO_ADDRESS(DMA_BASE_ADDR) + DMA_YSRB);
} else {
__raw_writel(dma_info->W,
IO_ADDRESS(DMA_BASE_ADDR) + DMA_WSRA);
__raw_writel(dma_info->X,
IO_ADDRESS(DMA_BASE_ADDR) + DMA_XSRA);
__raw_writel(dma_info->Y,
IO_ADDRESS(DMA_BASE_ADDR) + DMA_YSRA);
}
}
dma_base = (dma_regs_t *) (priv->dma_base);
__raw_writel(dma_info->burstLength, &(dma_base->BurstLength));
__raw_writel(dma_info->request, &(dma_base->RequestSource));
if (dma_info->ren) {
reg = dma_info->busuntils & 0x1FFFF;
if (dma_info->rto_en) {
reg |= 0xE000;
}
__raw_writel(reg, &(dma_base->BusUtilt));
} else {
__raw_writel(dma_info->busuntils, &(dma_base->BusUtilt));
}
reg = __raw_readl(&(dma_base->Ctl)) & (~(DMA_CTL_ACRPT | DMA_CTL_RPT));
if (dma_info->dir) {
reg |= DMA_CTL_MDIR;
} else {
reg &= ~DMA_CTL_MDIR;
}
if (priv->ren) {
reg |= DMA_CTL_REN;
} else {
reg &= ~DMA_CTL_REN;
}
if ((dma_info->M2D_Valid) && (dma_info->msel)) {
reg |= DMA_CTL_MSEL;
} else {
reg &= ~DMA_CTL_MSEL;
}
if (dma_info->mode) {
DMA_CTL_SET_SMOD(reg, dma_info->destType);
DMA_CTL_SET_SSIZ(reg, dma_info->destPort);
DMA_CTL_SET_DMOD(reg, dma_info->sourceType);
DMA_CTL_SET_DSIZ(reg, dma_info->sourcePort);
} else {
DMA_CTL_SET_SMOD(reg, dma_info->sourceType);
DMA_CTL_SET_SSIZ(reg, dma_info->sourcePort);
DMA_CTL_SET_DMOD(reg, dma_info->destType);
DMA_CTL_SET_DSIZ(reg, dma_info->destPort);
}
__raw_writel(reg, &(dma_base->Ctl));
__clear_dma_interrupt(dma->channel);
unmask_dma_interrupt(dma->channel);
disable_dma_clk();
return 0;
}
/*!@brief setup interrupt and setup dma channel by dma parameter */
static inline int __init_dma_channel(mxc_dma_channel_t * chan,
mx2_dma_info_t * dma_info)
{
mx2_dma_priv_t *dma_private = (mx2_dma_priv_t *) chan->private;
dma_regs_t *dma_base;
int ret;
mask_dma_interrupt(chan->channel);
ret =
request_irq(dma_private->dma_irq, dma_irq_handler,
IRQF_DISABLED | IRQF_SHARED, chan->dev_name,
(void *)chan);
if (ret) {
printk(KERN_ERR
"%s: unable to request IRQ %d for DMA channel\n",
chan->dev_name, dma_private->dma_irq);
return ret;
}
enable_dma_clk();
dma_base = (dma_regs_t *) (dma_private->dma_base);
__raw_writel(0, &(dma_base->Ctl));
ret = 0;
if ((ret = setup_dma_channel(chan, dma_info))) {
free_irq(dma_private->dma_irq, (void *)chan);
}
disable_dma_clk();
return 0;
}
/*!@brief initialize buffer descriptor ring.*/
static inline void init_dma_bd(mx2_dma_priv_t * private)
{
int i;
mx2_dma_bd_t *pbd;
private->bd_rd = private->bd_wr = 0;
atomic_set(&(private->bd_used), 0);
for (i = 0, pbd = private->bd_ring; i < MAX_BD_SIZE; i++, pbd++) {
pbd->state = 0;
}
}
/*!@brief add dma buffer into buffer descriptor ring */
static inline int fill_dma_bd(mxc_dma_channel_t * dma,
mxc_dma_requestbuf_t * buf, int num,
mxc_dma_mode_t mode)
{
int i, wr;
unsigned long flags, mask;
mx2_dma_priv_t *priv = dma->private;
mx2_dma_bd_t *p, *q;
if ((atomic_read(&(priv->bd_used)) + num) > MAX_BD_SIZE) {
return -EBUSY;
}
for (i = 0; i < num; i++) {
wr = priv->bd_wr;
p = priv->bd_ring + wr;
p->mode = mode;
p->count = buf[i].num_of_bytes;
p->src_addr = buf[i].src_addr;
p->dst_addr = buf[i].dst_addr;
if (i == num - 1) {
p->state = DMA_BD_ST_LAST | DMA_BD_ST_PEND;
} else {
p->state = DMA_BD_ST_PEND;
}
priv->bd_wr = (wr + 1) % MAX_BD_SIZE;
atomic_inc(&(priv->bd_used));
if (atomic_read(&(priv->bd_used)) != 2)
continue;
/* Disable interrupt of this channel */
local_irq_save(flags);
local_irq_disable();
save_dma_interrupt(mask);
mask_dma_interrupt(dma->channel);
local_irq_restore(flags);
/*TODO ::
* If channel is transfering and supports chain_buffer,
* when the new buffer is 2st buffer , repeat must be enabled
*/
if (priv->dma_chaining && dma->active) {
q = priv->bd_ring + priv->bd_rd;
if (q && (q->state & DMA_BD_ST_BUSY)) {
if (atomic_read(&(priv->bd_used)) == 2) {
setup_dmac(dma);
}
}
}
restore_dma_interrupt(mask);
}
return 0;
}
/*!@brief add sg-list into buffer descriptor ring */
static inline int fill_dma_bd_by_sg(mxc_dma_channel_t * dma,
struct scatterlist *sg, int num,
int real_bytes, mxc_dma_mode_t mode)
{
int i, wr, total_bytes = real_bytes;
unsigned long flags, mask;
mx2_dma_priv_t *priv = dma->private;
mx2_dma_bd_t *p, *q;
if ((atomic_read(&(priv->bd_used)) + num) > MAX_BD_SIZE) {
return -EBUSY;
}
for (i = 0; i < num && ((real_bytes <= 0) || (total_bytes > 0)); i++) {
wr = priv->bd_wr;
p = priv->bd_ring + wr;
p->mode = mode;
if (real_bytes > 0) {
if (sg[i].length >= total_bytes) {
p->count = total_bytes;
} else {
p->count = sg[i].length;
}
total_bytes -= p->count;
} else {
p->count = sg[i].length;
}
if (mode == MXC_DMA_MODE_READ) {
p->src_addr = priv->dma_info->per_address;
p->dst_addr = sg[i].dma_address;
} else {
p->dst_addr = priv->dma_info->per_address;
p->src_addr = sg[i].dma_address;
}
if ((i == num - 1) || ((real_bytes > 0) && (total_bytes == 0))) {
p->state = DMA_BD_ST_LAST | DMA_BD_ST_PEND;
} else {
p->state = DMA_BD_ST_PEND;
}
priv->bd_wr = (wr + 1) % MAX_BD_SIZE;
atomic_inc(&(priv->bd_used));
if (atomic_read(&(priv->bd_used)) != 2)
continue;
/* Disable interrupt of this channel */
local_irq_save(flags);
local_irq_disable();
save_dma_interrupt(mask);
mask_dma_interrupt(dma->channel);
local_irq_restore(flags);
/*TODO ::
* If channel is transfering and supports chain_buffer,
* when the new buffer is 2st buffer , repeat must be enabled
*/
if (priv->dma_chaining && dma->active) {
q = next_dma_bd(priv);
if (q && (q->state & DMA_BD_ST_BUSY)) {
if ((atomic_read(&(priv->bd_used))) == 2) {
setup_dmac(dma);
}
}
}
restore_dma_interrupt(mask);
}
return 0;
}
/*!@brief select next buffer descripter to transfer.
* return 1: need call call-back function. 0: Not need call call-back.
* it just is called in ISR
*/
static inline int consume_dma_bd(mxc_dma_channel_t * dma, int error)
{
mx2_dma_priv_t *priv = dma->private;
mx2_dma_bd_t *p;
int notify = 0;
if (priv == NULL) {
printk(KERN_ERR
"request dma channel %d which is not initialize completed.!\n",
dma->channel);
return 1;
}
if (error != MXC_DMA_DONE) {
for (p = priv->bd_ring + priv->bd_rd;
atomic_read(&(priv->bd_used)) > 0;) {
priv->bd_rd = (priv->bd_rd + 1) % MAX_BD_SIZE;
atomic_dec(&(priv->bd_used));
if (p->state & DMA_BD_ST_LAST) {
p->state = 0;
break;
}
p->state = 0;
}
notify = 1;
} else {
p = priv->bd_ring + priv->bd_rd;
priv->bd_rd = (priv->bd_rd + 1) % MAX_BD_SIZE;
atomic_dec(&(priv->bd_used));
notify = (p->state & DMA_BD_ST_LAST) == DMA_BD_ST_LAST;
}
if (atomic_read(&(priv->bd_used)) <= 0) {
dma->active = 0;
atomic_dec(&g_dma_actived);
} else {
setup_dmac(dma);
}
return notify;
}
/*!
* This function is generally called by the driver at open time.
* The DMA driver would do any initialization steps that is required
* to get the channel ready for data transfer.
*
* @param channel_id a pre-defined id. The peripheral driver would specify
* the id associated with its peripheral. This would be
* used by the DMA driver to identify the peripheral
* requesting DMA and do the necessary setup on the
* channel associated with the particular peripheral.
* The DMA driver could use static or dynamic DMA channel
* allocation.
* @param dev_name module name or device name
* @return returns a negative number on error if request for a DMA channel did not
* succeed, returns the channel number to be used on success.
*/
int mxc_dma_request(mxc_dma_device_t channel_id, char *dev_name)
{
mxc_dma_channel_t *dma;
mx2_dma_priv_t *dma_private = NULL;
mx2_dma_info_t *dma_info = mxc_dma_get_info(channel_id);
int index;
int ret;
if (dma_info == NULL) {
return -EINVAL;
}
if ((index = get_dma_channel(dma_info->dma_chan)) < 0) {
return -ENODEV;
}
dma = g_dma_channels + index;
dma_private = (mx2_dma_priv_t *) dma->private;
if (dma_private == NULL) {
printk(KERN_ERR
"request dma channel %d which is not initialize completed.!\n",
index);
ret = -EFAULT;
goto exit;
}
dma->active = 0;
dma_private->dma_info = NULL;
dma->cb_fn = NULL;
dma->cb_args = NULL;
dma->dev_name = dev_name;
dma->mode = dma_info->mode ? MXC_DMA_MODE_WRITE : MXC_DMA_MODE_READ;
init_dma_bd(dma_private);
if (!(ret = __init_dma_channel(dma, dma_info))) {
dma_private->dma_info = dma_info;
return index;
}
exit:
put_dma_channel(index);
return ret;
}
/*!
* This function is generally called by the driver at close time. The DMA
* driver would do any cleanup associated with this channel.
*
* @param channel_num the channel number returned at request time. This
* would be used by the DMA driver to identify the calling
* driver and do the necessary cleanup on the channel
* associated with the particular peripheral
* @return returns a negative number on error or 0 on success
*/
int mxc_dma_free(int channel_num)
{
mxc_dma_channel_t *dma;
mx2_dma_priv_t *dma_private;
if ((channel_num >= MAX_DMA_CHANNELS) || (channel_num < 0)) {
return -EINVAL;
}
dma = g_dma_channels + channel_num;
dma_private = (mx2_dma_priv_t *) dma->private;
if (dma_private == NULL) {
printk(KERN_ERR
"Free dma %d which is not completed initialization \n",
channel_num);
return -EFAULT;
}
if (dma->lock) {
if (dma->active) { /*Channel is busy */
mxc_dma_disable(channel_num);
}
dma_private = (mx2_dma_priv_t *) dma->private;
enable_dma_clk();
mask_dma_interrupt(channel_num);
disable_dma_clk();
free_irq(dma_private->dma_irq, (void *)dma);
put_dma_channel(channel_num);
}
return 0;
}
/*!
* This function would just configure the buffers specified by the user into
* dma channel. The caller must call mxc_dma_enable to start this transfer.
*
* @param channel_num the channel number returned at request time. This
* would be used by the DMA driver to identify the calling
* driver and do the necessary cleanup on the channel
* associated with the particular peripheral
* @param dma_buf an array of physical addresses to the user defined
* buffers. The caller must guarantee the dma_buf is
* available until the transfer is completed.
* @param num_buf number of buffers in the array
* @param mode specifies whether this is READ or WRITE operation
* @return This function returns a negative number on error if buffer could not be
* added with DMA for transfer. On Success, it returns 0
*/
int mxc_dma_config(int channel_num, mxc_dma_requestbuf_t * dma_buf, int num_buf,
mxc_dma_mode_t mode)
{
mxc_dma_channel_t *dma;
mx2_dma_priv_t *dma_private;
if ((dma_buf == NULL) || (num_buf < 1)) {
return -EINVAL;
}
if ((channel_num >= MAX_DMA_CHANNELS) || (channel_num < 0)) {
return -EINVAL;
}
dma = g_dma_channels + channel_num;
dma_private = (mx2_dma_priv_t *) dma->private;
if (dma_private == NULL) {
printk(KERN_ERR
"config dma %d which is not completed initialization \n",
channel_num);
return -EFAULT;
}
if (dma->lock == 0) {
return -ENODEV;
}
/*TODO: dma chainning can not support on bi-dir channel */
if (dma_private->dma_chaining && (dma->mode != mode)) {
return -EINVAL;
}
/*TODO: fill dma buffer into driver .
* If driver is no enought buffer to save them , it will return -EBUSY
*/
if (fill_dma_bd(dma, dma_buf, num_buf, mode)) {
return -EBUSY;
}
return 0;
}
/*!
* This function would just configure the scatterlist specified by the
* user into dma channel. This is a slight variation of mxc_dma_config(),
* it is provided for the convenience of drivers that have a scatterlist
* passed into them. It is the calling driver's responsibility to have the
* correct physical address filled in the "dma_address" field of the
* scatterlist.
*
* @param channel_num the channel number returned at request time. This
* would be used by the DMA driver to identify the calling
* driver and do the necessary cleanup on the channel
* associated with the particular peripheral
* @param sg a scatterlist of buffers. The caller must guarantee
* the dma_buf is available until the transfer is
* completed.
* @param num_buf number of buffers in the array
* @param num_of_bytes total number of bytes to transfer. If set to 0, this
* would imply to use the length field of the scatterlist
* for each DMA transfer. Else it would calculate the size
* for each DMA transfer.
* @param mode specifies whether this is READ or WRITE operation
* @return This function returns a negative number on error if buffer could not
* be added with DMA for transfer. On Success, it returns 0
*/
int mxc_dma_sg_config(int channel_num, struct scatterlist *sg,
int num_buf, int num_of_bytes, mxc_dma_mode_t mode)
{
mxc_dma_channel_t *dma;
mx2_dma_priv_t *dma_private;
if ((sg == NULL) || (num_buf < 1) || (num_of_bytes < 0)) {
return -EINVAL;
}
if ((channel_num >= MAX_DMA_CHANNELS) || (channel_num < 0)) {
return -EINVAL;
}
dma = g_dma_channels + channel_num;
dma_private = (mx2_dma_priv_t *) dma->private;
if (dma_private == NULL) {
printk(KERN_ERR
"config_sg dma %d which is not completed initialization \n",
channel_num);
return -EFAULT;
}
if (dma->lock == 0) {
return -ENODEV;
}
/*TODO: dma chainning can not support on bi-dir channel */
if (dma_private->dma_chaining && (dma->mode != mode)) {
return -EINVAL;
}
/*TODO: fill dma buffer into driver .
* If driver is no enought buffer to save them , it will return -EBUSY
*/
if (fill_dma_bd_by_sg(dma, sg, num_buf, num_of_bytes, mode)) {
return -EBUSY;
}
return 0;
}
/*!
* This function is provided if the driver would like to set/change its
* callback function.
*
* @param channel_num the channel number returned at request time. This
* would be used by the DMA driver to identify the calling
* driver and do the necessary cleanup on the channel
* associated with the particular peripheral
* @param callback a callback function to provide notification on transfer
* completion, user could specify NULL if he does not wish
* to be notified
* @param arg an argument that gets passed in to the callback
* function, used by the user to do any driver specific
* operations.
* @return this function returns an error if the callback could not be set
* for the channel
*/
int mxc_dma_callback_set(int channel_num, mxc_dma_callback_t callback,
void *arg)
{
mxc_dma_channel_t *dma;
if ((channel_num >= MAX_DMA_CHANNELS) || (channel_num < 0)) {
return -EINVAL;
}
dma = g_dma_channels + channel_num;
if (!dma->lock) {
return -ENODEV;
}
if (dma->active) {
return -EBUSY;
}
dma->cb_fn = callback;
dma->cb_args = arg;
return 0;
}
/*!
* This stops the DMA channel and any ongoing transfers. Subsequent use of
* mxc_dma_enable() will restart the channel and restart the transfer.
*
* @param channel_num the channel number returned at request time. This
* would be used by the DMA driver to identify the calling
* driver and do the necessary cleanup on the channel
* associated with the particular peripheral
* @return returns a negative number on error or 0 on success
*/
int mxc_dma_disable(int channel_num)
{
mxc_dma_channel_t *dma;
mx2_dma_priv_t *priv;
unsigned long ctrl_val;
if ((channel_num >= MAX_DMA_CHANNELS) || (channel_num < 0)) {
return -EINVAL;
}
dma = g_dma_channels + channel_num;
if (dma->lock == 0) {
return -EINVAL;
}
if (!dma->active) {
return -EINVAL;
}
priv = (mx2_dma_priv_t *) dma->private;
if (priv == NULL) {
printk(KERN_ERR "disable a uncompleted dma channel %d\n",
channel_num);
return -EFAULT;
}
dma->active = 0;
enable_dma_clk();
__clear_dma_interrupt(channel_num);
ctrl_val =
__raw_readl(IO_ADDRESS(DMA_BASE_ADDR) + DMA_CCR(channel_num));
ctrl_val &= ~DMA_CTL_CEN; /* clear CEN bit */
__raw_writel(ctrl_val,
IO_ADDRESS(DMA_BASE_ADDR) + DMA_CCR(channel_num));
disable_dma_clk();
atomic_dec(&g_dma_actived);
/*TODO: Clear all request buffers */
flush_dma_bd(priv);
return 0;
}
/*!
* This starts DMA transfer. Or it restarts DMA on a stopped channel
* previously stopped with mxc_dma_disable().
*
* @param channel_num the channel number returned at request time. This
* would be used by the DMA driver to identify the calling
* driver and do the necessary cleanup on the channel
* associated with the particular peripheral
* @return returns a negative number on error or 0 on success
*/
int mxc_dma_enable(int channel_num)
{
mxc_dma_channel_t *dma;
mx2_dma_priv_t *priv;
if ((channel_num >= MAX_DMA_CHANNELS) || (channel_num < 0)) {
return -EINVAL;
}
dma = g_dma_channels + channel_num;
if (dma->lock == 0) {
return -EINVAL;
}
priv = (mx2_dma_priv_t *) dma->private;
if (priv == NULL) {
printk(KERN_ERR "enable a uncompleted dma channel %d\n",
channel_num);
return -EFAULT;
}
if (dma->active) {
return 0;
}
dma->active = 1;
priv->trans_bytes = 0;
enable_dma_clk();
atomic_inc(&g_dma_actived);
__clear_dma_interrupt(channel_num);
setup_dmac(dma);
disable_dma_clk();
return 0;
}
/*!
*@brief Dump DMA registers
*
*@param channel Requested channel NO.
*@return none
*/
void mxc_dump_dma_register(int channel)
{
mxc_dma_channel_t *dma = &g_dma_channels[channel];
mx2_dma_priv_t *priv = (mx2_dma_priv_t *) dma->private;
dma_regs_t *dma_base;
printk(KERN_INFO "======== Dump dma channel %d \n", channel);
if ((unsigned)channel >= MXC_DMA_CHANNELS) {
printk(KERN_INFO "Channel number is invalid \n");
return;
}
if (!dma->lock) {
printk(KERN_INFO "Channel is not allocated \n");
return;
}
printk(KERN_INFO "g_dma_actived = %d\n", atomic_read(&g_dma_actived));
enable_dma_clk();
dma_base = (dma_regs_t *) (priv->dma_base);
printk(KERN_INFO "DMA COMMON REGISTER\n");
printk(KERN_INFO "DMA CONTROL DMA_DCR: %08x\n",
__raw_readl(IO_ADDRESS(DMA_BASE_ADDR) + DMA_DCR));
printk(KERN_INFO "DMA Interrupt status DMA_DISR: %08x\n",
__raw_readl(IO_ADDRESS(DMA_BASE_ADDR) + DMA_DISR));
printk(KERN_INFO "DMA Interrupt Mask DMA_DIMR: %08x\n",
__raw_readl(IO_ADDRESS(DMA_BASE_ADDR) + DMA_DIMR));
printk(KERN_INFO "DMA Burst Time Out DMA_DBTOSR: %08x\n",
__raw_readl(IO_ADDRESS(DMA_BASE_ADDR) + DMA_DBTOSR));
printk(KERN_INFO "DMA request Time Out DMA_DRTOSR: %08x\n",
__raw_readl(IO_ADDRESS(DMA_BASE_ADDR) + DMA_DRTOSR));
printk(KERN_INFO "DMA Transfer Error DMA_DSESR: %08x\n",
__raw_readl(IO_ADDRESS(DMA_BASE_ADDR) + DMA_DSESR));
printk(KERN_INFO "DMA DMA_Overflow DMA_DBOSR: %08x\n",
__raw_readl(IO_ADDRESS(DMA_BASE_ADDR) + DMA_DBOSR));
printk(KERN_INFO "DMA Burst Time OutCtl DMA_BurstTOCtl: %08x\n",
__raw_readl(IO_ADDRESS(DMA_BASE_ADDR) + DMA_DBTOCR));
printk(KERN_INFO "DMA 2D X size: %08x\n",
__raw_readl(IO_ADDRESS(DMA_BASE_ADDR) + DMA_XSRA));
printk(KERN_INFO "DMA 2D Y size: %08x\n",
__raw_readl(IO_ADDRESS(DMA_BASE_ADDR) + DMA_YSRA));
printk(KERN_INFO "DMA 2D Z size: %08x\n",
__raw_readl(IO_ADDRESS(DMA_BASE_ADDR) + DMA_WSRA));
printk(KERN_INFO "DMA Chan %2d Sourc SourceAddr: %08x\n", channel,
__raw_readl(&(dma_base->SourceAddr)));
printk(KERN_INFO "DMA Chan %2d dest DestAddr: %08x\n", channel,
__raw_readl(&(dma_base->DestAddr)));
printk(KERN_INFO "DMA Chan %2d count Count: %08x\n", channel,
__raw_readl(&(dma_base->Count)));
printk(KERN_INFO "DMA Chan %2d Ctl Ctl: %08x\n", channel,
__raw_readl(&(dma_base->Ctl)));
printk(KERN_INFO "DMA Chan %2d request RequestSource: %08x\n",
channel, __raw_readl(&(dma_base->RequestSource)));
printk(KERN_INFO "DMA Chan %2d burstL BurstLength: %08x\n", channel,
__raw_readl(&(dma_base->BurstLength)));
printk(KERN_INFO "DMA Chan %2d requestTO ReqTimeout: %08x\n", channel,
__raw_readl(&(dma_base->ReqTimeout)));
printk(KERN_INFO "DMA Chan %2d BusUtilt BusUtilt: %08x\n", channel,
__raw_readl(&(dma_base->BusUtilt)));
disable_dma_clk();
}
#ifdef DMA_PM
static int channel_in_use(void)
{
int i;
for (i = 0; i < MXC_DMA_CHANNELS; i++) {
if (dma_chan[i].lock)
return 1;
}
return 0;
}
int mxc_dma_pm_standby(void)
{
unsigned long reg;
if (dma_pm_status == DMA_PMST_STANDBY)
return 0;
if (!channel_in_use()) {
/*Disable DMA */
__disable_dma_clk();
dma_pm_status = DMA_PMST_STANDBY;
return 0;
}
return -1;
}
int mxc_dma_pm_resume(void)
{
unsigned long reg;
if (dma_pm_status == DMA_PMST_RESUME)
return 0;
/*Enable HCLK_DMA and DMA(ipg clock) */
dma_pm_status = DMA_PMST_RESUME;
return 0;
}
int mxc_dma_pm_suspend(void)
{
unsigned long reg;
if (dma_pm_status == DMA_PMST_SUSPEND)
return 0;
if (!channel_in_use()) {
/*Disable DMA */
__disable_dma_clk();
dma_pm_status = DMA_PMST_SUSPEND;
return 0;
}
return -1;
}
int mxc_dma_pm_handler(struct pm_dev *dev, pm_request_t rqst, void *data)
{
int ret = 0;
switch (rqst) {
/*APM doesn't send PM_STANDBY and PM_STANDBY_RESUME request now. */
case PM_SUSPEND:
ret = dma_pm_suspend();
break;
case PM_RESUME:
ret = dma_pm_resume();
break;
}
return ret;
}
#endif /*DMA_PM */
int __init mxc_dma_init(void)
{
int i;
mxc_dma_channel_t *dma = g_dma_channels;
mx2_dma_priv_t *private = g_dma_privates;
memset(dma, 0, sizeof(mxc_dma_channel_t) * MXC_DMA_CHANNELS);
for (i = 0; i < MXC_DMA_CHANNELS; i++, dma++, private++) {
dma->channel = i;
dma->private = private;
private->dma_base =
(unsigned int)(IO_ADDRESS(DMA_BASE_ADDR + DMA_CH_BASE(i)));
private->dma_irq = i + MXC_DMA_INTR_0; /*Dma channel interrupt number */
private->bd_ring = &g_dma_bd_table[i][0];
}
mxc_dma_load_info(g_dma_channels);
dma_clk = clk_get(NULL, "dma_clk");
clk_enable(dma_clk);
__raw_writel(0x2, IO_ADDRESS(DMA_BASE_ADDR) + DMA_DCR); /*reset DMA; */
disable_dma_clk();
/*use module init because create_proc after init_dma */
g_proc_dir = create_proc_entry("dma", 0, NULL);
g_proc_dir->read_proc = (read_proc_t *) mxc_get_dma_list;
g_proc_dir->data = NULL;
#ifdef DMA_PM
/* Register the device with power management. */
dma_pm = pm_register(PM_DMA_DEV, PM_SYS_UNKNOWN, dma_pm_handler);
#endif
return 0;
}
arch_initcall(mxc_dma_init);
EXPORT_SYMBOL(mxc_dma_request);
EXPORT_SYMBOL(mxc_dma_free);
EXPORT_SYMBOL(mxc_dma_callback_set);
EXPORT_SYMBOL(mxc_dma_enable);
EXPORT_SYMBOL(mxc_dma_disable);
EXPORT_SYMBOL(mxc_dma_config);
EXPORT_SYMBOL(mxc_dma_sg_config);
EXPORT_SYMBOL(mxc_dump_dma_register);
|