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
|
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright IBM Corp 2019
#include <linux/aspeed-xdma.h>
#include <linux/bitfield.h>
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/dma-mapping.h>
#include <linux/fs.h>
#include <linux/genalloc.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/jiffies.h>
#include <linux/mfd/syscon.h>
#include <linux/miscdevice.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/of_device.h>
#include <linux/of_reserved_mem.h>
#include <linux/platform_device.h>
#include <linux/poll.h>
#include <linux/regmap.h>
#include <linux/reset.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/string.h>
#include <linux/uaccess.h>
#include <linux/wait.h>
#include <linux/workqueue.h>
#define DEVICE_NAME "aspeed-xdma"
#define SCU_AST2600_MISC_CTRL 0x0c0
#define SCU_AST2600_MISC_CTRL_XDMA_BMC BIT(8)
#define SCU_AST2600_DEBUG_CTRL 0x0c8
#define DEBUG_CTRL_XDMA_DISABLE BIT(2)
#define SCU_AST2500_PCIE_CONF 0x180
#define SCU_AST2600_PCIE_CONF 0xc20
#define SCU_PCIE_CONF_VGA_EN BIT(0)
#define SCU_PCIE_CONF_VGA_EN_MMIO BIT(1)
#define SCU_PCIE_CONF_VGA_EN_LPC BIT(2)
#define SCU_PCIE_CONF_VGA_EN_MSI BIT(3)
#define SCU_PCIE_CONF_VGA_EN_MCTP BIT(4)
#define SCU_PCIE_CONF_VGA_EN_IRQ BIT(5)
#define SCU_PCIE_CONF_VGA_EN_DMA BIT(6)
#define SCU_PCIE_CONF_BMC_EN BIT(8)
#define SCU_PCIE_CONF_BMC_EN_MMIO BIT(9)
#define SCU_PCIE_CONF_BMC_EN_MSI BIT(11)
#define SCU_PCIE_CONF_BMC_EN_MCTP BIT(12)
#define SCU_PCIE_CONF_BMC_EN_IRQ BIT(13)
#define SCU_PCIE_CONF_BMC_EN_DMA BIT(14)
#define SCU_AST2500_BMC_CLASS_REV 0x19c
#define SCU_AST2600_BMC_CLASS_REV 0xc68
#define SCU_BMC_CLASS_REV_XDMA 0xff000001
#define XDMA_CMDQ_SIZE PAGE_SIZE
#define XDMA_NUM_CMDS \
(XDMA_CMDQ_SIZE / sizeof(struct aspeed_xdma_cmd))
/* Aspeed specification requires 100us after disabling the reset */
#define XDMA_ENGINE_SETUP_TIME_MAX_US 1000
#define XDMA_ENGINE_SETUP_TIME_MIN_US 100
#define XDMA_CMD_AST2500_PITCH_SHIFT 3
#define XDMA_CMD_AST2500_PITCH_BMC GENMASK_ULL(62, 51)
#define XDMA_CMD_AST2500_PITCH_HOST GENMASK_ULL(46, 35)
#define XDMA_CMD_AST2500_PITCH_UPSTREAM BIT_ULL(31)
#define XDMA_CMD_AST2500_PITCH_ADDR GENMASK_ULL(29, 4)
#define XDMA_CMD_AST2500_PITCH_ID BIT_ULL(0)
#define XDMA_CMD_AST2500_CMD_IRQ_EN BIT_ULL(31)
#define XDMA_CMD_AST2500_CMD_LINE_NO GENMASK_ULL(27, 16)
#define XDMA_CMD_AST2500_CMD_IRQ_BMC BIT_ULL(15)
#define XDMA_CMD_AST2500_CMD_LINE_SIZE_SHIFT 4
#define XDMA_CMD_AST2500_CMD_LINE_SIZE \
GENMASK_ULL(14, XDMA_CMD_AST2500_CMD_LINE_SIZE_SHIFT)
#define XDMA_CMD_AST2500_CMD_ID BIT_ULL(1)
#define XDMA_CMD_AST2600_PITCH_BMC GENMASK_ULL(62, 48)
#define XDMA_CMD_AST2600_PITCH_HOST GENMASK_ULL(46, 32)
#define XDMA_CMD_AST2600_PITCH_ADDR GENMASK_ULL(30, 0)
#define XDMA_CMD_AST2600_CMD_64_EN BIT_ULL(40)
#define XDMA_CMD_AST2600_CMD_IRQ_BMC BIT_ULL(37)
#define XDMA_CMD_AST2600_CMD_IRQ_HOST BIT_ULL(36)
#define XDMA_CMD_AST2600_CMD_UPSTREAM BIT_ULL(32)
#define XDMA_CMD_AST2600_CMD_LINE_NO GENMASK_ULL(27, 16)
#define XDMA_CMD_AST2600_CMD_LINE_SIZE GENMASK_ULL(14, 0)
#define XDMA_CMD_AST2600_CMD_MULTILINE_SIZE GENMASK_ULL(14, 12)
#define XDMA_AST2500_QUEUE_ENTRY_SIZE 4
#define XDMA_AST2500_HOST_CMDQ_ADDR0 0x00
#define XDMA_AST2500_HOST_CMDQ_ENDP 0x04
#define XDMA_AST2500_HOST_CMDQ_WRITEP 0x08
#define XDMA_AST2500_HOST_CMDQ_READP 0x0c
#define XDMA_AST2500_BMC_CMDQ_ADDR 0x10
#define XDMA_AST2500_BMC_CMDQ_ENDP 0x14
#define XDMA_AST2500_BMC_CMDQ_WRITEP 0x18
#define XDMA_AST2500_BMC_CMDQ_READP 0x1c
#define XDMA_BMC_CMDQ_READP_RESET 0xee882266
#define XDMA_AST2500_CTRL 0x20
#define XDMA_AST2500_CTRL_US_COMP BIT(4)
#define XDMA_AST2500_CTRL_DS_COMP BIT(5)
#define XDMA_AST2500_CTRL_DS_DIRTY BIT(6)
#define XDMA_AST2500_CTRL_DS_SIZE_256 BIT(17)
#define XDMA_AST2500_CTRL_DS_TIMEOUT BIT(28)
#define XDMA_AST2500_CTRL_DS_CHECK_ID BIT(29)
#define XDMA_AST2500_STATUS 0x24
#define XDMA_AST2500_STATUS_US_COMP BIT(4)
#define XDMA_AST2500_STATUS_DS_COMP BIT(5)
#define XDMA_AST2500_STATUS_DS_DIRTY BIT(6)
#define XDMA_AST2500_INPRG_DS_CMD1 0x38
#define XDMA_AST2500_INPRG_DS_CMD2 0x3c
#define XDMA_AST2500_INPRG_US_CMD00 0x40
#define XDMA_AST2500_INPRG_US_CMD01 0x44
#define XDMA_AST2500_INPRG_US_CMD10 0x48
#define XDMA_AST2500_INPRG_US_CMD11 0x4c
#define XDMA_AST2500_INPRG_US_CMD20 0x50
#define XDMA_AST2500_INPRG_US_CMD21 0x54
#define XDMA_AST2500_HOST_CMDQ_ADDR1 0x60
#define XDMA_AST2500_VGA_CMDQ_ADDR0 0x64
#define XDMA_AST2500_VGA_CMDQ_ENDP 0x68
#define XDMA_AST2500_VGA_CMDQ_WRITEP 0x6c
#define XDMA_AST2500_VGA_CMDQ_READP 0x70
#define XDMA_AST2500_VGA_CMD_STATUS 0x74
#define XDMA_AST2500_VGA_CMDQ_ADDR1 0x78
#define XDMA_AST2600_QUEUE_ENTRY_SIZE 2
#define XDMA_AST2600_HOST_CMDQ_ADDR0 0x00
#define XDMA_AST2600_HOST_CMDQ_ADDR1 0x04
#define XDMA_AST2600_HOST_CMDQ_ENDP 0x08
#define XDMA_AST2600_HOST_CMDQ_WRITEP 0x0c
#define XDMA_AST2600_HOST_CMDQ_READP 0x10
#define XDMA_AST2600_BMC_CMDQ_ADDR 0x14
#define XDMA_AST2600_BMC_CMDQ_ENDP 0x18
#define XDMA_AST2600_BMC_CMDQ_WRITEP 0x1c
#define XDMA_AST2600_BMC_CMDQ_READP 0x20
#define XDMA_AST2600_VGA_CMDQ_ADDR0 0x24
#define XDMA_AST2600_VGA_CMDQ_ADDR1 0x28
#define XDMA_AST2600_VGA_CMDQ_ENDP 0x2c
#define XDMA_AST2600_VGA_CMDQ_WRITEP 0x30
#define XDMA_AST2600_VGA_CMDQ_READP 0x34
#define XDMA_AST2600_CTRL 0x38
#define XDMA_AST2600_CTRL_US_COMP BIT(16)
#define XDMA_AST2600_CTRL_DS_COMP BIT(17)
#define XDMA_AST2600_CTRL_DS_DIRTY BIT(18)
#define XDMA_AST2600_CTRL_DS_SIZE_256 BIT(20)
#define XDMA_AST2600_STATUS 0x3c
#define XDMA_AST2600_STATUS_US_COMP BIT(16)
#define XDMA_AST2600_STATUS_DS_COMP BIT(17)
#define XDMA_AST2600_STATUS_DS_DIRTY BIT(18)
#define XDMA_AST2600_INPRG_DS_CMD00 0x40
#define XDMA_AST2600_INPRG_DS_CMD01 0x44
#define XDMA_AST2600_INPRG_DS_CMD10 0x48
#define XDMA_AST2600_INPRG_DS_CMD11 0x4c
#define XDMA_AST2600_INPRG_DS_CMD20 0x50
#define XDMA_AST2600_INPRG_DS_CMD21 0x54
#define XDMA_AST2600_INPRG_US_CMD00 0x60
#define XDMA_AST2600_INPRG_US_CMD01 0x64
#define XDMA_AST2600_INPRG_US_CMD10 0x68
#define XDMA_AST2600_INPRG_US_CMD11 0x6c
#define XDMA_AST2600_INPRG_US_CMD20 0x70
#define XDMA_AST2600_INPRG_US_CMD21 0x74
struct aspeed_xdma_cmd {
u64 host_addr;
u64 pitch;
u64 cmd;
u64 reserved;
};
struct aspeed_xdma_regs {
u8 bmc_cmdq_addr;
u8 bmc_cmdq_endp;
u8 bmc_cmdq_writep;
u8 bmc_cmdq_readp;
u8 control;
u8 status;
};
struct aspeed_xdma_status_bits {
u32 us_comp;
u32 ds_comp;
u32 ds_dirty;
};
struct aspeed_xdma;
struct aspeed_xdma_chip {
u32 control;
u32 scu_bmc_class;
u32 scu_misc_ctrl;
u32 scu_pcie_conf;
unsigned int queue_entry_size;
struct aspeed_xdma_regs regs;
struct aspeed_xdma_status_bits status_bits;
unsigned int (*set_cmd)(struct aspeed_xdma *ctx,
struct aspeed_xdma_cmd cmds[2],
struct aspeed_xdma_op *op, u32 bmc_addr);
};
struct aspeed_xdma_client;
struct aspeed_xdma {
struct kobject kobj;
const struct aspeed_xdma_chip *chip;
int irq;
int pcie_irq;
struct clk *clock;
struct device *dev;
void __iomem *base;
resource_size_t res_size;
resource_size_t res_start;
struct reset_control *reset;
struct reset_control *reset_rc;
/* Protects current_client */
spinlock_t client_lock;
struct aspeed_xdma_client *current_client;
/* Protects engine configuration */
spinlock_t engine_lock;
struct aspeed_xdma_cmd *cmdq;
unsigned int cmd_idx;
bool in_reset;
bool upstream;
/* Queue waiters for idle engine */
wait_queue_head_t wait;
struct work_struct reset_work;
u32 mem_phys;
u32 mem_size;
void *mem_virt;
dma_addr_t mem_coherent;
dma_addr_t cmdq_phys;
struct gen_pool *pool;
struct miscdevice misc;
};
struct aspeed_xdma_client {
struct aspeed_xdma *ctx;
bool error;
bool in_progress;
void *virt;
dma_addr_t phys;
u32 size;
};
static u32 aspeed_xdma_readl(struct aspeed_xdma *ctx, u8 reg)
{
u32 v = readl(ctx->base + reg);
dev_dbg(ctx->dev, "read %02x[%08x]\n", reg, v);
return v;
}
static void aspeed_xdma_writel(struct aspeed_xdma *ctx, u8 reg, u32 val)
{
writel(val, ctx->base + reg);
dev_dbg(ctx->dev, "write %02x[%08x]\n", reg, val);
}
static void aspeed_xdma_init_eng(struct aspeed_xdma *ctx)
{
unsigned long flags;
spin_lock_irqsave(&ctx->engine_lock, flags);
aspeed_xdma_writel(ctx, ctx->chip->regs.bmc_cmdq_endp,
ctx->chip->queue_entry_size * XDMA_NUM_CMDS);
aspeed_xdma_writel(ctx, ctx->chip->regs.bmc_cmdq_readp,
XDMA_BMC_CMDQ_READP_RESET);
aspeed_xdma_writel(ctx, ctx->chip->regs.bmc_cmdq_writep, 0);
aspeed_xdma_writel(ctx, ctx->chip->regs.control, ctx->chip->control);
aspeed_xdma_writel(ctx, ctx->chip->regs.bmc_cmdq_addr, ctx->cmdq_phys);
ctx->cmd_idx = 0;
spin_unlock_irqrestore(&ctx->engine_lock, flags);
}
static unsigned int aspeed_xdma_ast2500_set_cmd(struct aspeed_xdma *ctx,
struct aspeed_xdma_cmd cmds[2],
struct aspeed_xdma_op *op,
u32 bmc_addr)
{
unsigned int rc = 1;
unsigned int pitch = 1;
unsigned int line_no = 1;
unsigned int line_size = op->len >>
XDMA_CMD_AST2500_CMD_LINE_SIZE_SHIFT;
u64 cmd = XDMA_CMD_AST2500_CMD_IRQ_EN | XDMA_CMD_AST2500_CMD_IRQ_BMC |
XDMA_CMD_AST2500_CMD_ID;
u64 cmd_pitch = (op->direction ? XDMA_CMD_AST2500_PITCH_UPSTREAM : 0) |
XDMA_CMD_AST2500_PITCH_ID;
dev_dbg(ctx->dev, "xdma %s ast2500: bmc[%08x] len[%08x] host[%08x]\n",
op->direction ? "upstream" : "downstream", bmc_addr, op->len,
(u32)op->host_addr);
if (op->len > XDMA_CMD_AST2500_CMD_LINE_SIZE) {
unsigned int rem;
unsigned int total;
line_no = op->len / XDMA_CMD_AST2500_CMD_LINE_SIZE;
total = XDMA_CMD_AST2500_CMD_LINE_SIZE * line_no;
rem = (op->len - total) >>
XDMA_CMD_AST2500_CMD_LINE_SIZE_SHIFT;
line_size = XDMA_CMD_AST2500_CMD_LINE_SIZE;
pitch = line_size >> XDMA_CMD_AST2500_PITCH_SHIFT;
line_size >>= XDMA_CMD_AST2500_CMD_LINE_SIZE_SHIFT;
if (rem) {
u32 rbmc = bmc_addr + total;
cmds[1].host_addr = op->host_addr + (u64)total;
cmds[1].pitch = cmd_pitch |
((u64)rbmc & XDMA_CMD_AST2500_PITCH_ADDR) |
FIELD_PREP(XDMA_CMD_AST2500_PITCH_HOST, 1) |
FIELD_PREP(XDMA_CMD_AST2500_PITCH_BMC, 1);
cmds[1].cmd = cmd |
FIELD_PREP(XDMA_CMD_AST2500_CMD_LINE_NO, 1) |
FIELD_PREP(XDMA_CMD_AST2500_CMD_LINE_SIZE,
rem);
cmds[1].reserved = 0ULL;
print_hex_dump_debug("xdma rem ", DUMP_PREFIX_OFFSET,
16, 1, &cmds[1], sizeof(*cmds),
true);
cmd &= ~(XDMA_CMD_AST2500_CMD_IRQ_EN |
XDMA_CMD_AST2500_CMD_IRQ_BMC);
rc++;
}
}
cmds[0].host_addr = op->host_addr;
cmds[0].pitch = cmd_pitch |
((u64)bmc_addr & XDMA_CMD_AST2500_PITCH_ADDR) |
FIELD_PREP(XDMA_CMD_AST2500_PITCH_HOST, pitch) |
FIELD_PREP(XDMA_CMD_AST2500_PITCH_BMC, pitch);
cmds[0].cmd = cmd | FIELD_PREP(XDMA_CMD_AST2500_CMD_LINE_NO, line_no) |
FIELD_PREP(XDMA_CMD_AST2500_CMD_LINE_SIZE, line_size);
cmds[0].reserved = 0ULL;
print_hex_dump_debug("xdma cmd ", DUMP_PREFIX_OFFSET, 16, 1, cmds,
sizeof(*cmds), true);
return rc;
}
static unsigned int aspeed_xdma_ast2600_set_cmd(struct aspeed_xdma *ctx,
struct aspeed_xdma_cmd cmds[2],
struct aspeed_xdma_op *op,
u32 bmc_addr)
{
unsigned int rc = 1;
unsigned int pitch = 1;
unsigned int line_no = 1;
unsigned int line_size = op->len;
u64 cmd = XDMA_CMD_AST2600_CMD_IRQ_BMC |
(op->direction ? XDMA_CMD_AST2600_CMD_UPSTREAM : 0);
if (op->host_addr & 0xffffffff00000000ULL ||
(op->host_addr + (u64)op->len) & 0xffffffff00000000ULL)
cmd |= XDMA_CMD_AST2600_CMD_64_EN;
dev_dbg(ctx->dev, "xdma %s ast2600: bmc[%08x] len[%08x] "
"host[%016llx]\n", op->direction ? "upstream" : "downstream",
bmc_addr, op->len, op->host_addr);
if (op->len > XDMA_CMD_AST2600_CMD_LINE_SIZE) {
unsigned int rem;
unsigned int total;
line_no = op->len / XDMA_CMD_AST2600_CMD_MULTILINE_SIZE;
total = XDMA_CMD_AST2600_CMD_MULTILINE_SIZE * line_no;
rem = op->len - total;
line_size = XDMA_CMD_AST2600_CMD_MULTILINE_SIZE;
pitch = line_size;
if (rem) {
u32 rbmc = bmc_addr + total;
cmds[1].host_addr = op->host_addr + (u64)total;
cmds[1].pitch =
((u64)rbmc & XDMA_CMD_AST2600_PITCH_ADDR) |
FIELD_PREP(XDMA_CMD_AST2600_PITCH_HOST, 1) |
FIELD_PREP(XDMA_CMD_AST2600_PITCH_BMC, 1);
cmds[1].cmd = cmd |
FIELD_PREP(XDMA_CMD_AST2600_CMD_LINE_NO, 1) |
FIELD_PREP(XDMA_CMD_AST2600_CMD_LINE_SIZE,
rem);
cmds[1].reserved = 0ULL;
print_hex_dump_debug("xdma rem ", DUMP_PREFIX_OFFSET,
16, 1, &cmds[1], sizeof(*cmds),
true);
cmd &= ~XDMA_CMD_AST2600_CMD_IRQ_BMC;
rc++;
}
}
cmds[0].host_addr = op->host_addr;
cmds[0].pitch = ((u64)bmc_addr & XDMA_CMD_AST2600_PITCH_ADDR) |
FIELD_PREP(XDMA_CMD_AST2600_PITCH_HOST, pitch) |
FIELD_PREP(XDMA_CMD_AST2600_PITCH_BMC, pitch);
cmds[0].cmd = cmd | FIELD_PREP(XDMA_CMD_AST2600_CMD_LINE_NO, line_no) |
FIELD_PREP(XDMA_CMD_AST2600_CMD_LINE_SIZE, line_size);
cmds[0].reserved = 0ULL;
print_hex_dump_debug("xdma cmd ", DUMP_PREFIX_OFFSET, 16, 1, cmds,
sizeof(*cmds), true);
return rc;
}
static int aspeed_xdma_start(struct aspeed_xdma *ctx, unsigned int num_cmds,
struct aspeed_xdma_cmd cmds[2], bool upstream,
struct aspeed_xdma_client *client)
{
unsigned int i;
int rc = -EBUSY;
unsigned long flags;
spin_lock_irqsave(&ctx->engine_lock, flags);
if (ctx->in_reset)
goto unlock;
spin_lock(&ctx->client_lock);
if (ctx->current_client) {
spin_unlock(&ctx->client_lock);
goto unlock;
}
client->error = false;
client->in_progress = true;
ctx->current_client = client;
spin_unlock(&ctx->client_lock);
ctx->upstream = upstream;
for (i = 0; i < num_cmds; ++i) {
/*
* Use memcpy_toio here to get some barriers before starting
* the operation. The command(s) need to be in physical memory
* before the XDMA engine starts.
*/
memcpy_toio(&ctx->cmdq[ctx->cmd_idx], &cmds[i],
sizeof(struct aspeed_xdma_cmd));
ctx->cmd_idx = (ctx->cmd_idx + 1) % XDMA_NUM_CMDS;
}
aspeed_xdma_writel(ctx, ctx->chip->regs.bmc_cmdq_writep,
ctx->cmd_idx * ctx->chip->queue_entry_size);
rc = 0;
unlock:
spin_unlock_irqrestore(&ctx->engine_lock, flags);
return rc;
}
static void aspeed_xdma_done(struct aspeed_xdma *ctx, bool error)
{
unsigned long flags;
spin_lock_irqsave(&ctx->client_lock, flags);
if (ctx->current_client) {
ctx->current_client->error = error;
ctx->current_client->in_progress = false;
ctx->current_client = NULL;
}
spin_unlock_irqrestore(&ctx->client_lock, flags);
wake_up_interruptible_all(&ctx->wait);
}
static irqreturn_t aspeed_xdma_irq(int irq, void *arg)
{
struct aspeed_xdma *ctx = arg;
u32 status;
spin_lock(&ctx->engine_lock);
status = aspeed_xdma_readl(ctx, ctx->chip->regs.status);
if (status & ctx->chip->status_bits.ds_dirty) {
aspeed_xdma_done(ctx, true);
} else {
if (status & ctx->chip->status_bits.us_comp) {
if (ctx->upstream)
aspeed_xdma_done(ctx, false);
}
if (status & ctx->chip->status_bits.ds_comp) {
if (!ctx->upstream)
aspeed_xdma_done(ctx, false);
}
}
aspeed_xdma_writel(ctx, ctx->chip->regs.status, status);
spin_unlock(&ctx->engine_lock);
return IRQ_HANDLED;
}
static void aspeed_xdma_reset(struct aspeed_xdma *ctx)
{
unsigned long flags;
reset_control_assert(ctx->reset);
usleep_range(XDMA_ENGINE_SETUP_TIME_MIN_US,
XDMA_ENGINE_SETUP_TIME_MAX_US);
reset_control_deassert(ctx->reset);
usleep_range(XDMA_ENGINE_SETUP_TIME_MIN_US,
XDMA_ENGINE_SETUP_TIME_MAX_US);
aspeed_xdma_init_eng(ctx);
aspeed_xdma_done(ctx, true);
spin_lock_irqsave(&ctx->engine_lock, flags);
ctx->in_reset = false;
spin_unlock_irqrestore(&ctx->engine_lock, flags);
wake_up_interruptible(&ctx->wait);
}
static void aspeed_xdma_reset_work(struct work_struct *work)
{
struct aspeed_xdma *ctx = container_of(work, struct aspeed_xdma,
reset_work);
aspeed_xdma_reset(ctx);
}
static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg)
{
struct aspeed_xdma *ctx = arg;
dev_dbg(ctx->dev, "PCI-E reset requested.\n");
spin_lock(&ctx->engine_lock);
if (ctx->in_reset) {
spin_unlock(&ctx->engine_lock);
return IRQ_HANDLED;
}
ctx->in_reset = true;
spin_unlock(&ctx->engine_lock);
schedule_work(&ctx->reset_work);
return IRQ_HANDLED;
}
static ssize_t aspeed_xdma_write(struct file *file, const char __user *buf,
size_t len, loff_t *offset)
{
int rc;
unsigned int num_cmds;
struct aspeed_xdma_op op;
struct aspeed_xdma_cmd cmds[2];
struct aspeed_xdma_client *client = file->private_data;
struct aspeed_xdma *ctx = client->ctx;
if (len != sizeof(op))
return -EINVAL;
if (copy_from_user(&op, buf, len))
return -EFAULT;
if (!op.len || op.len > client->size ||
op.direction > ASPEED_XDMA_DIRECTION_UPSTREAM)
return -EINVAL;
num_cmds = ctx->chip->set_cmd(ctx, cmds, &op, client->phys);
do {
rc = aspeed_xdma_start(ctx, num_cmds, cmds, !!op.direction,
client);
if (!rc)
break;
if ((file->f_flags & O_NONBLOCK) || rc != -EBUSY)
return rc;
rc = wait_event_interruptible(ctx->wait,
!(ctx->current_client ||
ctx->in_reset));
} while (!rc);
if (rc)
return -EINTR;
if (!(file->f_flags & O_NONBLOCK)) {
rc = wait_event_interruptible(ctx->wait, !client->in_progress);
if (rc)
return -EINTR;
if (client->error)
return -EIO;
}
return len;
}
static __poll_t aspeed_xdma_poll(struct file *file,
struct poll_table_struct *wait)
{
__poll_t mask = 0;
__poll_t req = poll_requested_events(wait);
struct aspeed_xdma_client *client = file->private_data;
struct aspeed_xdma *ctx = client->ctx;
if (req & (EPOLLIN | EPOLLRDNORM)) {
if (READ_ONCE(client->in_progress))
poll_wait(file, &ctx->wait, wait);
if (!READ_ONCE(client->in_progress)) {
if (READ_ONCE(client->error))
mask |= EPOLLERR;
else
mask |= EPOLLIN | EPOLLRDNORM;
}
}
if (req & (EPOLLOUT | EPOLLWRNORM)) {
if (READ_ONCE(ctx->current_client))
poll_wait(file, &ctx->wait, wait);
if (!READ_ONCE(ctx->current_client))
mask |= EPOLLOUT | EPOLLWRNORM;
}
return mask;
}
static long aspeed_xdma_ioctl(struct file *file, unsigned int cmd,
unsigned long param)
{
unsigned long flags;
struct aspeed_xdma_client *client = file->private_data;
struct aspeed_xdma *ctx = client->ctx;
switch (cmd) {
case ASPEED_XDMA_IOCTL_RESET:
spin_lock_irqsave(&ctx->engine_lock, flags);
if (ctx->in_reset) {
spin_unlock_irqrestore(&ctx->engine_lock, flags);
return 0;
}
ctx->in_reset = true;
spin_unlock_irqrestore(&ctx->engine_lock, flags);
if (READ_ONCE(ctx->current_client))
dev_warn(ctx->dev,
"User reset with transfer in progress.\n");
aspeed_xdma_reset(ctx);
break;
default:
return -EINVAL;
}
return 0;
}
static void aspeed_xdma_vma_close(struct vm_area_struct *vma)
{
int rc;
struct aspeed_xdma_client *client = vma->vm_private_data;
rc = wait_event_interruptible(client->ctx->wait, !client->in_progress);
if (rc)
return;
gen_pool_free(client->ctx->pool, (unsigned long)client->virt,
client->size);
client->virt = NULL;
client->phys = 0;
client->size = 0;
}
static const struct vm_operations_struct aspeed_xdma_vm_ops = {
.close = aspeed_xdma_vma_close,
};
static int aspeed_xdma_mmap(struct file *file, struct vm_area_struct *vma)
{
int rc;
struct aspeed_xdma_client *client = file->private_data;
struct aspeed_xdma *ctx = client->ctx;
/* restrict file to one mapping */
if (client->size)
return -EBUSY;
client->size = vma->vm_end - vma->vm_start;
client->virt = gen_pool_dma_alloc(ctx->pool, client->size,
&client->phys);
if (!client->virt) {
client->phys = 0;
client->size = 0;
return -ENOMEM;
}
vma->vm_pgoff = (client->phys - ctx->mem_phys) >> PAGE_SHIFT;
vma->vm_ops = &aspeed_xdma_vm_ops;
vma->vm_private_data = client;
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
rc = io_remap_pfn_range(vma, vma->vm_start, client->phys >> PAGE_SHIFT,
client->size, vma->vm_page_prot);
if (rc) {
dev_warn(ctx->dev, "mmap err: v[%08lx] to p[%08x], s[%08x]\n",
vma->vm_start, (u32)client->phys, client->size);
gen_pool_free(ctx->pool, (unsigned long)client->virt,
client->size);
client->virt = NULL;
client->phys = 0;
client->size = 0;
return rc;
}
dev_dbg(ctx->dev, "mmap: v[%08lx] to p[%08x], s[%08x]\n",
vma->vm_start, (u32)client->phys, client->size);
return 0;
}
static int aspeed_xdma_open(struct inode *inode, struct file *file)
{
struct miscdevice *misc = file->private_data;
struct aspeed_xdma *ctx = container_of(misc, struct aspeed_xdma, misc);
struct aspeed_xdma_client *client = kzalloc(sizeof(*client),
GFP_KERNEL);
if (!client)
return -ENOMEM;
kobject_get(&ctx->kobj);
client->ctx = ctx;
file->private_data = client;
return 0;
}
static int aspeed_xdma_release(struct inode *inode, struct file *file)
{
bool reset = false;
unsigned long flags;
struct aspeed_xdma_client *client = file->private_data;
struct aspeed_xdma *ctx = client->ctx;
spin_lock_irqsave(&ctx->client_lock, flags);
if (client == ctx->current_client) {
spin_lock(&ctx->engine_lock);
if (ctx->in_reset) {
ctx->current_client = NULL;
} else {
ctx->in_reset = true;
reset = true;
}
spin_unlock(&ctx->engine_lock);
}
spin_unlock_irqrestore(&ctx->client_lock, flags);
if (reset)
aspeed_xdma_reset(ctx);
if (client->virt)
gen_pool_free(ctx->pool, (unsigned long)client->virt,
client->size);
kfree(client);
kobject_put(&ctx->kobj);
return 0;
}
static const struct file_operations aspeed_xdma_fops = {
.owner = THIS_MODULE,
.write = aspeed_xdma_write,
.poll = aspeed_xdma_poll,
.unlocked_ioctl = aspeed_xdma_ioctl,
.mmap = aspeed_xdma_mmap,
.open = aspeed_xdma_open,
.release = aspeed_xdma_release,
};
static int aspeed_xdma_init_scu(struct aspeed_xdma *ctx, struct device *dev)
{
struct regmap *scu = syscon_regmap_lookup_by_phandle(dev->of_node,
"aspeed,scu");
if (!IS_ERR(scu)) {
u32 selection;
bool pcie_device_bmc = true;
const u32 bmc = SCU_PCIE_CONF_BMC_EN |
SCU_PCIE_CONF_BMC_EN_MSI | SCU_PCIE_CONF_BMC_EN_IRQ |
SCU_PCIE_CONF_BMC_EN_DMA;
const u32 vga = SCU_PCIE_CONF_VGA_EN |
SCU_PCIE_CONF_VGA_EN_MSI | SCU_PCIE_CONF_VGA_EN_IRQ |
SCU_PCIE_CONF_VGA_EN_DMA;
const char *pcie = NULL;
if (!of_property_read_string(dev->of_node,
"aspeed,pcie-device", &pcie)) {
if (!strcmp(pcie, "vga")) {
pcie_device_bmc = false;
} else if (strcmp(pcie, "bmc")) {
dev_err(dev,
"Invalid pcie-device property %s.\n",
pcie);
return -EINVAL;
}
}
if (pcie_device_bmc) {
selection = bmc;
regmap_write(scu, ctx->chip->scu_bmc_class,
SCU_BMC_CLASS_REV_XDMA);
} else {
selection = vga;
}
regmap_update_bits(scu, ctx->chip->scu_pcie_conf, bmc | vga,
selection);
if (ctx->chip->scu_misc_ctrl) {
regmap_update_bits(scu, ctx->chip->scu_misc_ctrl,
SCU_AST2600_MISC_CTRL_XDMA_BMC,
SCU_AST2600_MISC_CTRL_XDMA_BMC);
/* Allow XDMA to be used on AST2600 */
regmap_update_bits(scu, SCU_AST2600_DEBUG_CTRL,
DEBUG_CTRL_XDMA_DISABLE, 0);
}
} else {
dev_warn(dev, "Unable to configure PCIe: %ld; continuing.\n",
PTR_ERR(scu));
}
return 0;
}
static void aspeed_xdma_kobject_release(struct kobject *kobj)
{
struct aspeed_xdma *ctx = container_of(kobj, struct aspeed_xdma, kobj);
if (ctx->pcie_irq >= 0)
free_irq(ctx->pcie_irq, ctx);
gen_pool_free(ctx->pool, (unsigned long)ctx->cmdq, XDMA_CMDQ_SIZE);
gen_pool_destroy(ctx->pool);
dma_free_coherent(ctx->dev, ctx->mem_size, ctx->mem_virt,
ctx->mem_coherent);
if (ctx->reset_rc)
reset_control_put(ctx->reset_rc);
reset_control_put(ctx->reset);
clk_put(ctx->clock);
free_irq(ctx->irq, ctx);
iounmap(ctx->base);
release_mem_region(ctx->res_start, ctx->res_size);
kfree(ctx);
}
static struct kobj_type aspeed_xdma_kobject_type = {
.release = aspeed_xdma_kobject_release,
};
static int aspeed_xdma_iomap(struct aspeed_xdma *ctx,
struct platform_device *pdev)
{
resource_size_t size;
struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res)
return -ENOMEM;
size = resource_size(res);
if (!request_mem_region(res->start, size, dev_name(ctx->dev)))
return -ENOMEM;
ctx->base = ioremap(res->start, size);
if (!ctx->base) {
release_mem_region(res->start, size);
return -ENOMEM;
}
ctx->res_start = res->start;
ctx->res_size = size;
return 0;
}
static int aspeed_xdma_probe(struct platform_device *pdev)
{
int rc;
struct aspeed_xdma *ctx;
struct reserved_mem *mem;
struct device *dev = &pdev->dev;
struct device_node *memory_region;
const void *md = of_device_get_match_data(dev);
if (!md)
return -ENODEV;
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
if (!ctx)
return -ENOMEM;
ctx->chip = md;
ctx->dev = dev;
platform_set_drvdata(pdev, ctx);
spin_lock_init(&ctx->client_lock);
spin_lock_init(&ctx->engine_lock);
INIT_WORK(&ctx->reset_work, aspeed_xdma_reset_work);
init_waitqueue_head(&ctx->wait);
rc = aspeed_xdma_iomap(ctx, pdev);
if (rc) {
dev_err(dev, "Failed to map registers.\n");
goto err_nomap;
}
ctx->irq = platform_get_irq(pdev, 0);
if (ctx->irq < 0) {
dev_err(dev, "Failed to find IRQ.\n");
rc = ctx->irq;
goto err_noirq;
}
rc = request_irq(ctx->irq, aspeed_xdma_irq, 0, DEVICE_NAME, ctx);
if (rc < 0) {
dev_err(dev, "Failed to request IRQ %d.\n", ctx->irq);
goto err_noirq;
}
ctx->clock = clk_get(dev, NULL);
if (IS_ERR(ctx->clock)) {
dev_err(dev, "Failed to request clock.\n");
rc = PTR_ERR(ctx->clock);
goto err_noclk;
}
ctx->reset = reset_control_get_exclusive(dev, NULL);
if (IS_ERR(ctx->reset)) {
dev_err(dev, "Failed to request reset control.\n");
rc = PTR_ERR(ctx->reset);
goto err_noreset;
}
ctx->reset_rc = reset_control_get_exclusive(dev, "root-complex");
if (IS_ERR(ctx->reset_rc)) {
dev_dbg(dev, "Failed to request reset RC control.\n");
ctx->reset_rc = NULL;
}
memory_region = of_parse_phandle(dev->of_node, "memory-region", 0);
if (!memory_region) {
dev_err(dev, "Failed to find memory-region.\n");
rc = -ENOMEM;
goto err_nomem;
}
mem = of_reserved_mem_lookup(memory_region);
of_node_put(memory_region);
if (!mem) {
dev_err(dev, "Failed to find reserved memory.\n");
rc = -ENOMEM;
goto err_nomem;
}
ctx->mem_phys = mem->base;
ctx->mem_size = mem->size;
rc = of_reserved_mem_device_init(dev);
if (rc) {
dev_err(dev, "Failed to init reserved memory.\n");
goto err_nomem;
}
rc = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
if (rc) {
dev_err(dev, "Failed to mask DMA.\n");
goto err_nomem;
}
ctx->mem_virt = dma_alloc_coherent(dev, ctx->mem_size,
&ctx->mem_coherent, 0);
if (!ctx->mem_virt) {
dev_err(dev, "Failed to allocate reserved memory.\n");
rc = -ENOMEM;
goto err_nomem;
}
ctx->pool = gen_pool_create(ilog2(PAGE_SIZE), -1);
if (!ctx->pool) {
dev_err(dev, "Failed to setup genalloc pool.\n");
rc = -ENOMEM;
goto err_nopool;
}
rc = gen_pool_add_virt(ctx->pool, (unsigned long)ctx->mem_virt,
ctx->mem_phys, ctx->mem_size, -1);
if (rc) {
dev_err(ctx->dev, "Failed to add memory to genalloc pool.\n");
goto err_pool_scu_clk;
}
rc = aspeed_xdma_init_scu(ctx, dev);
if (rc)
goto err_pool_scu_clk;
rc = clk_prepare_enable(ctx->clock);
if (rc) {
dev_err(dev, "Failed to enable the clock.\n");
goto err_pool_scu_clk;
}
if (ctx->reset_rc) {
rc = reset_control_deassert(ctx->reset_rc);
if (rc) {
dev_err(dev, "Failed to clear the RC reset.\n");
goto err_reset_rc;
}
usleep_range(XDMA_ENGINE_SETUP_TIME_MIN_US,
XDMA_ENGINE_SETUP_TIME_MAX_US);
}
rc = reset_control_deassert(ctx->reset);
if (rc) {
dev_err(dev, "Failed to clear the reset.\n");
goto err_reset;
}
usleep_range(XDMA_ENGINE_SETUP_TIME_MIN_US,
XDMA_ENGINE_SETUP_TIME_MAX_US);
ctx->cmdq = gen_pool_dma_alloc(ctx->pool, XDMA_CMDQ_SIZE,
&ctx->cmdq_phys);
if (!ctx->cmdq) {
dev_err(ctx->dev, "Failed to genalloc cmdq.\n");
rc = -ENOMEM;
goto err_pool;
}
aspeed_xdma_init_eng(ctx);
ctx->misc.minor = MISC_DYNAMIC_MINOR;
ctx->misc.fops = &aspeed_xdma_fops;
ctx->misc.name = "aspeed-xdma";
ctx->misc.parent = dev;
rc = misc_register(&ctx->misc);
if (rc) {
dev_err(dev, "Failed to register xdma miscdevice.\n");
goto err_misc;
}
/*
* This interrupt could fire immediately so only request it once the
* engine and driver are initialized.
*/
ctx->pcie_irq = platform_get_irq(pdev, 1);
if (ctx->pcie_irq < 0) {
dev_warn(dev, "Failed to find PCI-E IRQ.\n");
} else {
rc = request_irq(ctx->pcie_irq, aspeed_xdma_pcie_irq,
IRQF_SHARED, DEVICE_NAME, ctx);
if (rc < 0) {
dev_warn(dev, "Failed to request PCI-E IRQ %d.\n", rc);
ctx->pcie_irq = -1;
}
}
kobject_init(&ctx->kobj, &aspeed_xdma_kobject_type);
return 0;
err_misc:
gen_pool_free(ctx->pool, (unsigned long)ctx->cmdq, XDMA_CMDQ_SIZE);
err_pool:
reset_control_assert(ctx->reset);
err_reset:
if (ctx->reset_rc)
reset_control_assert(ctx->reset_rc);
err_reset_rc:
clk_disable_unprepare(ctx->clock);
err_pool_scu_clk:
gen_pool_destroy(ctx->pool);
err_nopool:
dma_free_coherent(ctx->dev, ctx->mem_size, ctx->mem_virt,
ctx->mem_coherent);
err_nomem:
if (ctx->reset_rc)
reset_control_put(ctx->reset_rc);
reset_control_put(ctx->reset);
err_noreset:
clk_put(ctx->clock);
err_noclk:
free_irq(ctx->irq, ctx);
err_noirq:
iounmap(ctx->base);
release_mem_region(ctx->res_start, ctx->res_size);
err_nomap:
kfree(ctx);
return rc;
}
static int aspeed_xdma_remove(struct platform_device *pdev)
{
struct aspeed_xdma *ctx = platform_get_drvdata(pdev);
reset_control_assert(ctx->reset);
if (ctx->reset_rc)
reset_control_assert(ctx->reset_rc);
clk_disable_unprepare(ctx->clock);
aspeed_xdma_done(ctx, true);
misc_deregister(&ctx->misc);
kobject_put(&ctx->kobj);
return 0;
}
static const struct aspeed_xdma_chip aspeed_ast2500_xdma_chip = {
.control = XDMA_AST2500_CTRL_US_COMP | XDMA_AST2500_CTRL_DS_COMP |
XDMA_AST2500_CTRL_DS_DIRTY | XDMA_AST2500_CTRL_DS_SIZE_256 |
XDMA_AST2500_CTRL_DS_TIMEOUT | XDMA_AST2500_CTRL_DS_CHECK_ID,
.scu_bmc_class = SCU_AST2500_BMC_CLASS_REV,
.scu_misc_ctrl = 0,
.scu_pcie_conf = SCU_AST2500_PCIE_CONF,
.queue_entry_size = XDMA_AST2500_QUEUE_ENTRY_SIZE,
.regs = {
.bmc_cmdq_addr = XDMA_AST2500_BMC_CMDQ_ADDR,
.bmc_cmdq_endp = XDMA_AST2500_BMC_CMDQ_ENDP,
.bmc_cmdq_writep = XDMA_AST2500_BMC_CMDQ_WRITEP,
.bmc_cmdq_readp = XDMA_AST2500_BMC_CMDQ_READP,
.control = XDMA_AST2500_CTRL,
.status = XDMA_AST2500_STATUS,
},
.status_bits = {
.us_comp = XDMA_AST2500_STATUS_US_COMP,
.ds_comp = XDMA_AST2500_STATUS_DS_COMP,
.ds_dirty = XDMA_AST2500_STATUS_DS_DIRTY,
},
.set_cmd = aspeed_xdma_ast2500_set_cmd,
};
static const struct aspeed_xdma_chip aspeed_ast2600_xdma_chip = {
.control = XDMA_AST2600_CTRL_US_COMP | XDMA_AST2600_CTRL_DS_COMP |
XDMA_AST2600_CTRL_DS_DIRTY | XDMA_AST2600_CTRL_DS_SIZE_256,
.scu_bmc_class = SCU_AST2600_BMC_CLASS_REV,
.scu_misc_ctrl = SCU_AST2600_MISC_CTRL,
.scu_pcie_conf = SCU_AST2600_PCIE_CONF,
.queue_entry_size = XDMA_AST2600_QUEUE_ENTRY_SIZE,
.regs = {
.bmc_cmdq_addr = XDMA_AST2600_BMC_CMDQ_ADDR,
.bmc_cmdq_endp = XDMA_AST2600_BMC_CMDQ_ENDP,
.bmc_cmdq_writep = XDMA_AST2600_BMC_CMDQ_WRITEP,
.bmc_cmdq_readp = XDMA_AST2600_BMC_CMDQ_READP,
.control = XDMA_AST2600_CTRL,
.status = XDMA_AST2600_STATUS,
},
.status_bits = {
.us_comp = XDMA_AST2600_STATUS_US_COMP,
.ds_comp = XDMA_AST2600_STATUS_DS_COMP,
.ds_dirty = XDMA_AST2600_STATUS_DS_DIRTY,
},
.set_cmd = aspeed_xdma_ast2600_set_cmd,
};
static const struct of_device_id aspeed_xdma_match[] = {
{
.compatible = "aspeed,ast2500-xdma",
.data = &aspeed_ast2500_xdma_chip,
},
{
.compatible = "aspeed,ast2600-xdma",
.data = &aspeed_ast2600_xdma_chip,
},
{ },
};
static struct platform_driver aspeed_xdma_driver = {
.probe = aspeed_xdma_probe,
.remove = aspeed_xdma_remove,
.driver = {
.name = DEVICE_NAME,
.of_match_table = aspeed_xdma_match,
},
};
module_platform_driver(aspeed_xdma_driver);
MODULE_AUTHOR("Eddie James");
MODULE_DESCRIPTION("ASPEED XDMA Engine Driver");
MODULE_LICENSE("GPL v2");
|