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
|
/*++
Copyright (c) 2010 WonderMedia Technologies, Inc.
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details. You
should have received a copy of the GNU General Public License along with this
program. If not, see http://www.gnu.org/licenses/>.
WonderMedia Technologies, Inc.
10F, 529, Chung-Cheng Road, Hsin-Tien, Taipei 231, R.O.C.
--*/
#ifndef _USBREG_H_
#define _USBREG_H_
//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
#define UINT volatile unsigned int
#define USHORT volatile unsigned short
#define UCHAR volatile unsigned char
#define ULL volatile unsigned long long
//#define DWORD volatile unsigned long
//#define WORD volatile unsigned short
//#define BYTE volatile unsigned char
#define u16 unsigned short
#define u8 unsigned char
//#define u32 unsigned long
// Basic Define
#define REG32 *(volatile unsigned int *)
#define REG16 *(volatile unsigned short *)
#define REG8 *(volatile unsigned char *)
#define REG_GET32(addr) ( REG32(addr) ) /* Read 32 bits Register */
#define REG_GET16(addr) ( REG16(addr) ) /* Read 16 bits Register */
#define REG_GET8(addr) ( REG8(addr) ) /* Read 8 bits Register */
#define REG_SET32(addr,val) ( REG32(addr) = (val) ) /* Write 32 bits Register */
#define REG_SET16(addr,val) ( REG16(addr) = (val) ) /* Write 16 bits Register */
#define REG_SET8(addr,val) ( REG8(addr) = (val) ) /* Write 8 bits Register */
#define MEM_GET32(addr) ( REG32(addr) ) /* Read 32 bits Memory */
#define MEM_SET32(addr,val) ( REG32(addr) = (val) ) /* Write 32 bits Memory */
/*HW reg-----------------------------------------------------------------*/
#ifndef OTGIP
#define UDC_IRQ_DMA 2
#endif
/*#define DWORD volatile unsigned long*/
/*#define WORD volatile unsigned short*/
/*#define BYTE volatile unsigned char*/
#define USB_IP_BASE 0xD8007800
/*UDC Register Space 0x400~0x7EF*/
#define USB_UDC_REG_BASE (USB_IP_BASE + 0x400)
/*Bulk Endpoint DMA Register Space 0x100*/
#define USB_UDC_DMA_REG_BASE (USB_IP_BASE + 0x500)
#ifdef OTGIP
/*UHDC Global Register Space 0x7F0~0x7F7*/
#define USB_GLOBAL_REG_BASE (USB_IP_BASE + 0x7f0)
#endif
#define UDC_REG(offset) REG32_PTR(USB_UDC_REG_BASE + offset)
#define OTG_HOST_MEM_BASE 0x01400000/*20MB*/
#define USB_EP0_CTRL_DMA_BASE OTG_HOST_MEM_BASE /*64 bytes*/
#define USB_EP1_BULK_IN_DMA_BASE 0x01400040/*OTG_HOST_MEM_BASE + 64 */ /*64B +64KB*/
//#define USB_EP2_BULK_OUT_DMA_BASE 0x01410040/*OTG_HOST_MEM_BASE + 65536*/ /* ~ END*/
//#define USB_EP2_BULK_OUT_DMA_BASE 0x01410000/*OTG_HOST_MEM_BASE + 65536*/ /* ~ END*/
#define USB_DOWNLOAD_KERNEL_RAM_ADDR USB_EP2_BULK_OUT_DMA_BASE
#define USB_PRI_BULK_OUT_BASE 0x01510040 /* ~ END*/ //Charles,tmp
/* Basic Define*/
#define REG32 *(volatile unsigned int *)
#define REG16 *(volatile unsigned short *)
#define REG8 *(volatile unsigned char *)
#define REG_GET32(addr) ( REG32(addr) ) /* Read 32 bits Register */
#define REG_GET16(addr) ( REG16(addr) ) /* Read 16 bits Register */
#define REG_GET8(addr) ( REG8(addr) ) /* Read 8 bits Register */
#define REG_SET32(addr, val) ( REG32(addr) = (val) ) /* Write 32 bits Register */
#define REG_SET16(addr, val) ( REG16(addr) = (val) ) /* Write 16 bits Register */
#define REG_SET8(addr, val) ( REG8(addr) = (val) ) /* Write 8 bits Register */
#define MEM_GET32(addr) ( REG32(addr) ) /* Read 32 bits Memory */
#define MEM_SET32(addr, val) ( REG32(addr) = (val) ) /* Write 32 bits Memory */
/*#define USB_TIMEOUT 0x100*/ /*256*/
/*#define USB_TEST_SUCCESS 1*/
/*#define USB_TEST_FAIL 0*/
/* define the state of the USB device*/
#define USBSTATE_ATTACHED 0x00 /* device attached to host*/
#define USBSTATE_POWERED 0x01 /* device obtain power*/
#define USBSTATE_DEFAULT 0x02 /* default working state*/
#define USBSTATE_ADDRESS 0x04 /* device has get the address*/
#define USBSTATE_CONFIGED 0x10 /* deivce has set the configuration*/
#define USBSTATE_SUSPEND 0x20 /* No bus activity device goes to suspend */
#define UDC_TEST_J_STATE 1
#define UDC_TEST_K_STATE 2
#define UDC_TEST_SE0_NAK 3
#define UDC_TEST_PACKET 4
#define UDC_TEST_FRORCE_ENABLE 5
#define UDC_TEST_EYE_PATTERN 6
#define UDC_TEST_MODE_NOT_ENABLED 0
/*Define the USB register bit value*/
/* USB device commmand/status register - 20*/
#define USBREG_RUNCONTROLLER 0x01 /* set the controller run*/
#define USBREG_RESETCONTROLLER 0x02 /* reset the device contrller*/
#define USBREG_COMPLETEINT 0x04 /* the completion interrupt*/
#define USBREG_BABBLEINT 0x08 /* the babble interrupt*/
#define USBREG_BUSACTINT 0x10 /* the bus activity interrupt*/
#define USBREG_TEST_J 0x20 /* set test J state*/
#define USBREG_TEST_K 0x40 /* set test k state*/
#define USBREG_SE0_NAK 0x60 /* set test SE0 and NAK*/
#define USBREG_TESTPACKET 0x80 /* set device sending test packet*/
#define USBREG_FORCEENABLE 0xA0 /* force port enable*/
#define USBREG_TESTEYE 0xC0 /* Send test eye pattern packet*/
/* The device address register - 21*/
#define DEVADDR_ADDRCHANGE 0x80 /* the address change bit for device address register*/
/* Device port control register - 22*/
#define PORTCTRL_CONNECTSTATUS 0x01 /* current connection status*/
#define PORTCTRL_CONNECTCHANGE 0x02 /* connection change bit*/
#define PORTCTRL_SELFPOWER 0x04 /* the device is in the self power configuration*/
#define PORTCTRL_FORCERESUME 0x08 /* force deivce to wake the host*/
#define PORTCTRL_HIGHSPEEDMODE 0x10 /* device is in the high speed mode*/
#define PORTCTRL_FULLSPEEDMODE 0x20 /* device is in the full speed mode*/
/* Device itnerrupt enable register - 23*/
#define INTENABLE_DEVICERESET 0x01 /* this bit is set when the bus reset is completed*/
#define INTENABLE_SUSPENDDETECT 0x02 /* device controller detect the suspend signal*/
#define INTENABLE_RESUMEDETECT 0x04 /* device controller detect the resume signal*/
#define INTENABLE_COMPLETEINTEN 0x10 /* enable completion interrupt*/
#define INTENABLE_BABBLEINTEN 0x20 /* enable babble interrupt*/
#define INTENABLE_BUSACTINTEN 0x40 /* enable bus activity interrupt*/
#define INTENABLE_ALL 0x70 /* enable all interrupt */
#define INTENABLE_FULLSPEEDONLY 0x80 /* force device to support full speed only*/
/* Control endpoint control - 24*/
/* Bulk endpoint control - 28*/
/* Interrupt endpoint control - 2C*/
/* Bulk endpoint control - 0x310*/
#define EP_RUN 0x01 /* run the enpoint DMA*/
#define EP_ENABLEDMA 0x02 /* enable the DMA engine to run the schedule*/
#define EP_DMALIGHTRESET 0x04 /* light reset the DMA engine*/
#define EP_STALL 0x08 /* set the endpoint to stall*/
#define EP_ACTIVE 0x10 /* the endpoint DMA is active*/
#define EP_COMPLETEINT 0x20 /* endpoint transfer complete interrupt*/
#define EP_BABBLE 0x40 /* endpoint babble interrupt*/
/* Control transfer descriptor status byte - 30*/
#define CTRLXFER_XACTERR 0x01 /* trnasacion error of control transfer*/
#define CTRLXFER_BABBLE 0x02 /* babbe error of control transfer*/
#define CTRLXFER_SHORTPKT 0x04 /* shortpacket detect of control transfer*/
#define CTRLXFER_ACTIVE 0x08 /* transfer active of control transfer*/
#define CTRLXFER_IN 0x08 /* I/O control bit 0 for OUT , 1 for In*/
#define CTRLXFER_OUT 0x00 /**/
#define CTRLXFER_CMDVALID 0x10 /* setup command is valid*/
#define CTRLXFER_IOC 0x80 /* determine to gen interrupt for completion or not*/
#define CTRLXFER_DATA1 0x80 /* for data_toggle 1*/
#define CTRLXFER_DATA0 0x00 /* for data_toggle 0*/
/* Bulk endpoint transfer descriptor status - 34*/
/* Bulk endpoint transfer descriptor status - 0x314 */
#define BULKXFER_XACTERR 0x01 /* trnasacion error of bulk transfer*/
#define BULKXFER_BABBLE 0x02 /* babbe error of bulk transfer*/
#define BULKXFER_SHORTPKT 0X04 /* shortpacket detect of bulk transfer*/
#define BULKXFER_ACTIVE 0x08 /* transfer active of bulk transfer*/
#define BULKXFER_IN 0x10 /* I/O control bit 0 for OUT , 1 for In*/
#define BULKXFER_OUT 0x00
/*HP05_Begin*/
#define BULKXFER_CBWBUF 0x20 /* enable CBW dedicated buffer*/
/*HP05_End*/
#define BULKXFER_IOC 0x80 /* determine to generate interrupt for completion or not*/
#define BULKXFER_DATA1 0x80 /* for data_toggle 1*/
#define BULKXFER_DATA0 0x00 /* for data_toggle 0*/
/* Interupt endpoint transfer descriptor - 33*/
#define INTXFER_XACTERR 0x01 /* trnasacion error for interrupt transfer*/
#define INTXFER_ACTIVE 0x02 /* transfer active*/
#define INTXFER_IOC 0x04 /* determine to generate interrupt for completion or not*/
#define INTXFER_DATA1 0x08 /* for data_toggle 1*/
#define INTXFER_DATA0 0x00 /* for data_toggle 0*/
/*UDC 0x400 ~ 0x7FF*/
struct UDC_REGISTER{
UCHAR Reserved0[0x20]; /* 0x00~0x19 Reserved 0*/
UCHAR CommandStatus; /* USB device commmand/status register - 20*/
UCHAR DeviceAddr; /* The device address register - 21*/
UCHAR PortControl; /* Device port control register - 22*/
UCHAR IntEnable; /* Device itnerrupt enable register - 23*/
UCHAR ControlEpControl; /* Control endpoint control - 24*/
UCHAR ControlEpReserved; /* Control endpoint reserved byte - 25*/
UCHAR ControlEpMaxLen; /* max length of control endpoint - 26*/
UCHAR ControlEpEpNum; /* The control endpoint number - 27*/
UCHAR Bulk1EpControl; /* Bulk endpoint control - 28*/
UCHAR Bulk1EpOutEpNum; /* Bulk out endpoint number - 29*/
UCHAR Bulk1EpMaxLen; /* Bulk maximum length - 2A*/
UCHAR Bulk1EpInEpNum; /* Bulk In endpoint number - 2B*/
UCHAR InterruptEpControl; /* Interrupt endpoint control - 2C*/
UCHAR InterruptReserved; /* Interrupt endpoint reserved byte - 2D*/
UCHAR InterruptEpMaxLen; /* Interrupt maximum transfer length - 2E*/
UCHAR InterruptEpEpNum; /* interrupt endpoint number - 2F*/
UCHAR ControlDesStatus; /* Control transfer descriptor status byte - 30*/
UCHAR ControlDesControl; /* Control transfer descriptor control byte - 31*/
UCHAR ControlDesTbytes; /* Control transfer descriptor total bytes - 32*/
UCHAR InterruptDes; /* Interupt endpoint transfer descriptor - 33*/
UCHAR Bulk1DesStatus; /* Bulk endpoint transfer descriptor status - 34*/
UCHAR Bulk1DesTbytes0; /* Bulk endpoint transfer descriptor control - 35*/
UCHAR Bulk1DesTbytes1; /* Bulk endpoint transfer descriptor lower total bytes - 36*/
UCHAR Bulk1DesTbytes2; /* Bulk endpoint transfer descriptor higer total bytes - 37*/
UCHAR MacToParameter; /* USB2.0 MAC timeout parameter register - 38*/
UCHAR PhyMisc; /* PHY misc control register - 39*/
UCHAR MiscControl0; /* Misc. control register 0 - 3A*/
UCHAR MiscControl1; /* Misc. control register 1 - 3B*/
UCHAR MiscControl2; /* Misc. control register 2 - 3C*/
UCHAR MiscControl3; /* Misc. control register 3 - 3D*/
UCHAR MACDelay; /* MAC receiver enable delay parameter - 3E*/
UCHAR FunctionPatchEn; /* Function Patch Enable bits - 3F*/
UCHAR InterruptInBuf[32]; /* Interrupt In Endpoint Data Buffer - 40 ~ 5F (32 bytes) for CBW(31 bytes)*/
UCHAR Reserved1[0x2A0]; /* 0x060~0x2FF ; 0x2FF - 0x60 + 1 = 0x2A0 for Bulk Endpoint 01 02 DMA Source / Destination*/
UCHAR SetupCommand[8]; /* 0x300~0x307 */
UCHAR PHYControlBit; /* 0x308 Phy Control Bit */
UCHAR Reserved2[2]; /* 0x309 ~ 0x30A*/
UCHAR NewUSBPhyTestControl;/* 0x30B New USB 1.1 and USB 2.0 PHY test control bit*/
UCHAR NewUSBPhyTestStatus; /* 0x30C New USB 1.1 and USB 2.0 PHY test status bit*/
UCHAR SelfPowerConnect; /* 0x30D Debug pins for USBC side control bit*/
UCHAR Reserved3[2]; /* 0x30E ~ 0x30F*/
UCHAR Bulk2EpControl; /* Bulk endpoint control - 0x310*/
UCHAR Bulk2EpOutEpNum; /* Bulk out endpoint number - 0x311*/
UCHAR Bulk2EpMaxLen; /* Bulk maximum length - 0x312*/
UCHAR Bulk2EpInEpNum; /* Bulk In endpoint number - 0x313*/
UCHAR Bulk2DesStatus; /* Bulk endpoint transfer descriptor status - 0x314*/
UCHAR Bulk2DesTbytes0; /* Bulk endpoint transfer descriptor control - 0x315*/
UCHAR Bulk2DesTbytes1; /* Bulk endpoint transfer descriptor lower total bytes - 0x316*/
UCHAR Bulk2DesTbytes2; /* Bulk endpoint transfer descriptor higer total bytes - 0x317*/
UCHAR Reserved4[0x28]; /*0x318 ~ 0x33F ; 0x33F - 0x318 + 1 = 0x28*/
UCHAR ControlDataBuf[64]; /*0x340~0x37F Control Endpoint Data Buffer */
};
/*DMA_Context_Control*/
/*1:IF0-->peripheral 0:peripher-->IF0*/
#define DMA_TRANS_OUT_DIR 0x00400000
/*1:Run 0:Stop Scheduled*/
#define DMA_RUN 0x00000080
/*DMA Interrupt Enable*/
/*enable interfac 0 interrupt*/
#define DMA_INTERRUPT_ENABLE0 0x00000001
/*enable interfac 1 interrupt*/
#define DMA_INTERRUPT_ENABLE1 0x00000002
/*enable interfac 0 status*/
#define DMA_INTERRUPT_STATUS0 0x00000001
/*enable interfac 1 status*/
#define DMA_INTERRUPT_STATUS1 0x00000002
struct UDC_DMA_REG {
union { /*Rx00 - DMA Global Register (0x100~0x103)*/
UINT DMA_Global;
struct {
UINT DMAConrollerEnable:1;
UINT Reserved0:7;
UINT SoftwareReset:1;
UINT SoftwareReset0:1;
UINT SoftwareReset1:1;
UINT SoftwareReset2:1;
UINT Reserved1:20;
} DMA_Global_Bits;
};
union { /*Rx04 - DMA Interrupt Enable (0x104~x107)*/
UINT DMA_IER;
struct {
UINT DMAInterruptEnable0:1;
UINT DMAInterruptEnable1:1;
UINT DMAInterruptEnable2:1;
UINT Reserved:29;
} DMA_IER_Bits;
};
union { /*Rx08 - DMA Interrupt Status Register (0x108~0x10b)*/
UINT DMA_ISR;
struct {
UINT InterruptStatus0:1;
UINT InterruptStatus1:1;
UINT Reserved:30;
} DMA_ISR_Bits;
};
/*Interface 0*/
union {/*Rx10c - DMA Memory-Descriptor Point Register dor Interdace 0 (0x10c~0x10f)*/
UINT DMA_Descriptor_Point0;
struct {
UINT Reserved:2;
UINT DesBaseAddr:30;
} DMA_Descriptor_Point0_Bits;
};
union { /*Rx110 - DMA Residual Bytes Register for Interface 0 (Rx110~Rx103)*/
UINT DMA_Residual_Bytes0;
struct {
UINT ResidualBytes:16;
UINT IntEn:1;
UINT Reseved:13;
UINT Format:1;
UINT End:1;
} DMA_Residual_Bytes0_Bits;
};
/*Rx114 - DMA Data Address Register for Interface 0 (0x114~0x117)*/
UINT DMA_Data_Addr0;
union {/*Rx118 DMA Branch Address Register for INterface 0(0x118~0x11b)*/
UINT DMA_Branch_Addr0;
struct {
UINT Reserved:4;
UINT BranchDesxriptorAddress:28;
} DMA_Branch_Addr0_Bits;
};
union {/*Rx11c DMA command Pointer Register for Interrface 0(0x11c~0x11f)*/
UINT Descriptor_Addr0;
struct {
UINT Reserved:4;
UINT DescriptorAddr:28;
} Descriptor_Addr0_Bits;
};
union {/*Rx120 DMA Context Control Register for Interfaxe 0(0x120~0x123)*/
UINT DMA_Context_Control0;
struct {
UINT EventCode:4;
UINT Reserved0:3;
UINT Run:1;
UINT Active:1;
UINT P0Cmpl:1;
UINT Reserved1:2;
UINT Prot:4;
UINT Reserved2:6;
UINT TransDir:1;
UINT Reserved3:9;
} DMA_Context_Control0_Bis;
};
/*Interface 1*/
union {/*Rx124 - DMA Memory-Descriptor Point Register dor Interdace 1 (0x124~0x127)*/
UINT DMA_Descriptor_Point1;
struct {
UINT Reserved:2;
UINT DesBaseAddr:30;
} DMA_Descriptor_Point1_Bits;
};
union { /*Rx128 - DMA Residual Bytes Register for Interface 1 (Rx128~Rx12b)*/
UINT DMA_Residual_Bytes1;
struct {
UINT ResidualBytes:16;
UINT IntEn:1;
UINT Reseved:13;
UINT Format:1;
UINT End:1;
} DMA_Residual_Bytes1_Bits;
};
/*Rx12c - DMA Data Address Register for Interface 1 (0x12c~0x12f)*/
UINT DMA_Data_Addr1;
union {/*Rx130 DMA Branch Address Register for INterface 10(0x130~0x133)*/
UINT DMA_Branch_Addr1;
struct {
UINT Reserved:4;
UINT BranchDesxriptorAddress:28;
} DMA_Branch_Addr1_Bits;
};
union {/*Rx134 DMA command Pointer Register for Interrface 1(0x134~0x137)*/
UINT Descriptor_Addr1;
struct {
UINT Reserved:4;
UINT DescriptorAddr:28;
} Descriptor_Addr1_Bits;
};
union {/*Rx138DMA Context Control Register for Interfaxe 1(0x138~0x13b)*/
UINT DMA_Context_Control1;
struct {
UINT EventCode:4;
UINT Reserved0:3;
UINT Run:1;
UINT Active:1;
UINT P0Cmpl:1;
UINT Reserved1:2;
UINT Prot:4;
UINT Reserved2:6;
UINT TransDir:1;
UINT Reserved3:9;
} DMA_Context_Control1_Bis;
};
} __attribute__ ((packed));
#define DESCRIPTOT_TYPE_SHORT 0
#define DESCRIPTOT_TYPE_LONG 1
#define DESCRIPTOT_TYPE_MIX 2
#define TRANS_OUT 1
#define TRANS_IN 0
#define DES_L_SIZE 0x10
#define DES_S_SIZE 0x4
//#define USB_DESCRIPT_LO_SIZE 0x00004000 /*16KB*/
#define USB_DESCRIPT_LO_SIZE 0x100 /*256B*/
/*
* PDMA Descriptor short
*/
struct _UDC_PDMA_DESC_S {
union {
UINT D_Word0;
struct {
UINT ReqCount:16; /* bit 0 -15 -Request count*/
UINT i:1; /* bit 16 -interrupt*/
UINT Reserved:13;
UINT Format:1; /* bit 30 -The descriptor format*/
UINT End:1; /* bit 31-End flag of descriptor list*/
} D_Word0_Bits;
};
UINT Data_Addr; /* bit 0-31 -Data Buffer address*/
}__attribute__ ((packed));
/*
* PDMA Descriptor long
*/
struct _UDC_PDMA_DESC_L {
union {
UINT D_Word0;
struct {
UINT ReqCount:16; /* bit 0 -15-Request count*/
UINT i:1; /* bit 16-interrupt*/
UINT Reserved:13;
UINT Format:1; /* bit 30-The descriptor format*/
UINT End:1; /* bit 31-End flag of descriptor list*/
} D_Word0_Bits;
};
UINT Data_Addr; /* bit 0-31 -Data Buffer address*/
union {
UINT Branch_addr;
struct {
UINT Reserved:2;
UINT BranchAddr:30; /* bit 31-2 -Descriptor Branch address*/
} Branch_addr_Bits;
};
UINT Reserve0;
}__attribute__ ((packed));
/*Rx00 - UHDC Interrupt Status Register*/
#define UHDC_INT_UDC 0x0700
#define UHDC_INT_UDC_DMA2 0x0400
#define UHDC_INT_UDC_DMA1 0x0200
#define UHDC_INT_UDC_CORE 0x0100
#ifdef OTGIP
/*UHDC Global Register Space : 0x7F0~0x7F7*/
struct USB_GLOBAL_REG {
union { /*Rx00 - UHDC Interrupt Status Register*/
USHORT UHDC_Interrupt_Status;
struct {
USHORT EHCIInt:1; /* [0] EHCI Interrupt bit*/
USHORT UHCIInt:1; /* [1] UHCI Interrupt bit*/
USHORT Reserved0:6; /* reserved for future use*/
USHORT UDCCoreInt:1; /* [8] UDC Core Interrupt bit(IOC/Babble/Bus Activity)*/
USHORT UDCDMA1Int:1; /* [9] DMA1 Interrupt bit (Bulk Transfer)*/
USHORT UDCDMA2Int:1; /* [10] DMA2 Interrupt bit (Bulk Transfer)*/
USHORT Reserved1:5; /* reserved for future use*/
} UHDC_Interrupt_Status_Bits;
};
union { /*Rx01 - UHDC ID Status Register*/
UCHAR UHDC_ID_Status;
struct {
UCHAR DualRoleID:1; /* Dual-Role USB Controller ID Value*/
UCHAR Reserved:7; /* reserved for future use*/
} UHDC_ID_Status_Bits;
};
union { /*Rx02 - UHDC Offchip Power Control Register*/
UCHAR UHDC_OffChip_PowerControl;
struct {
UCHAR PowerSupplyMode:1; /* Power Supply Mode Select (1)SW mode (0)HW mode*/
UCHAR PowerSupplySWEn:1; /* Power Supply SW Mode Enable bit */
UCHAR Reserved:6; /* reserved for future use */
} UHDC_OffChip_PowerControl_Bits;
};
union { /*Rx03 - UHDC Clock Reset Control Register*/
USHORT UHDC_Clock_Reset_Control;
struct {
USHORT AHBClkGatingEn:1; /* [0] AHB clock Gating Enable bit*/
USHORT HCSuspendClkGatingEn:1; /* [1] Host Controller Suspend Clock Gating Enable bit*/
USHORT DCSuspendClkGatingEn:1; /* [2] Device Controller Suspend Clock Gating Enable bit*/
USHORT DataReceivingClkGatingEn:1;/* [3] Controller Data-Receiving Clock Gating Enable bit*/
USHORT Phy120MClkGatingEn:1; /* [4] Phy 120M Clock Gating Enable bit*/
USHORT Phy60MClkGatingEn:1; /* [5] Phy 60M Clock Gating Enable bit*/
USHORT Phy48MClkGatingEn:1; /* [6] Phy 48M Clock Gating Enable bit */
USHORT Reserved0:1; /* [7] reserved for future use*/
USHORT AHBResetGatingEn:1; /* [8] AHB Bus Reset Gating Enable bit*/
USHORT PowerOnResetGatingEn:1; /* [9] Power-on Reset Gating Enable bit */
USHORT Reserved1:6; /* [15:10] reserved for future use*/
} UHDC_Clock_Reset_Control_Bits;
};
union { /*Rx04 - UHDC Pullup/Pulldown Control Register*/
USHORT UHDC_Pull_Up_Down_Control;
struct {
USHORT PullUpDownSWControlEn:1; /* [0] Pullup/Pulldown SW Control Enable bit*/
USHORT DPLinePullUpEn:1; /* [1] DP Line Pullup Enable bit*/
USHORT DPLinePullDownEn:1; /* [2] DP Line Pulldown Enable bit*/
USHORT DMLinePullDownEn:1; /* [3] DM Line Pulldown Enable bit*/
USHORT HSTerminationRegisterEn:1; /* [4] High Speed Termination Register On bit*/
USHORT Reserved1:11; /* [15:5] reserved for future use*/
} UHDC_Pull_Up_Down_Control_Bits;
};
}__attribute__ ((packed));
#endif
#define UDC_FULL_SPEED 0
#define UDC_HIGH_SPEED 1
/* Define the setup command buffer*/
#define MAX_TRANSFER_LENGTH 0x200 /* original is 0x20000, shift 16bits for minimum block size is 0x200*/
/*HP04_End*/
/* Define the interrupt transfer buffer*/
#define INTBUFFERSTART 0x308 /* the start byte of interrupt transfer buffer*/
#define INTBUFFEREND 0x30F /* the last byte of interrupt transfer buffer*/
#define INTBUFFERSIZE 0x08 /* the size of the interrupt transfer buffer*/
/* Define the control endpoint buffer*/
#define CONTROLBUFFERSTART 0x340 /* the start byte of the control data buffer*/
#define CONTROLBUFFEREND 0x37F /* the last byte of the control data buffer*/
#define CONTROLBUFFERSIZE 0x40 /* the size of the control data buffer*/
/* Define the bulk transfer buffer*/
#define BULKBUFFERSTART 0x800 /* the start byte of the bulk transfer buffer*/
#define BULKBUFFEREND 0xFFF /* the last byte of the bulk transfer buffer*/
#define BULKBUFFERSIZE 0x800 /* the size of the bulk transfer buffer*/
/* define the endpoint number for each endpoint*/
#define BULKINEPNUM 0x01
/*HP01_begin*/
#define BULKOUTEPNUM 0x02
/*HP01_End*/
#define INTEPNUM 0x03
#define MAXEPNUM 0x04
/* define the structure of string table for default strings and vendor specified strings*/
/* define the IO state of USB to handle */
#define IOSTATE_CBWIDLE 0x00 /* usb is idle and set the 8051 clock to stop*/
#define IOSTATE_ACCEPTCBW 0x01 /* the usb accept a new CBW*/
#define IOSTATE_DEVICEPREPAREIO 0x02 /* the state will call deivce startio to prepare IO*/
#define IOSTATE_STARTIO 0x03 /* the CBW send to device to start IO operation*/
#define IOSTATE_CSW 0x04 /* the state to send CSW back to host*/
#define IOSTATE_CSWCOMPLETE 0x05 /* the CSW is returned, maybe need some more process*/
#define IOSTATE_TIMEOUT 0x06 /* the IO is hang to long and it is timeout*/
#define IOSTATE_FWDOWNLOAD 0x07 /* Download the new firmware.*/
#define IOSTATE_WAITFORCBW 0x08 /* In this state, the controller is waiting for CBW*/
#define IOSTATE_CSWIDLE 0x09 /* the idle state for wait for CSW complete, 8051 will stopped*/
/*VT3214 Define */
/* define the state of Control endpoint*/
#define CONTROLSTATE_SETUP 0x00 /* the control endpoint is in the Setup state*/
#define CONTROLSTATE_DATA 0x01 /* the control endpoint is in the Data state*/
#define CONTROLSTATE_STATUS 0x02 /* the control endpoint is in the Status state*/
/* VT3300 PACK Size Defination*/
#define UCE_MAX_DMA ((unsigned)64)
#define UIE_MAX_DMA ((unsigned)8)
//#define UBE_MAX_DMA ((unsigned)0x20000) /* max length = 128K */
//#define UBE_MAX_DMA ((unsigned)0x80000) /* max length = 512k */
#define EP0_FIFO_SIZE ((unsigned)64)
#define BULK_FIFO_SIZE ((unsigned)512)
#define INT_FIFO_SIZE ((unsigned)8)
/* Define the setup command buffer*/
typedef struct _SETUP_COMMAND
{
unsigned char RequestType; /* the Request type of the SETUP command*/
unsigned char Request; /* the Request code of the SETUP command*/
unsigned char ValueLow; /* the lower value field of the SETUP command*/
unsigned char ValueHigh; /* the higher value field of the SETUP command*/
unsigned char IndexLow; /* the lower index field of the SETUP command*/
unsigned char IndexHigh; /* the higher index field of the SETUP command*/
unsigned char LengthLow; /* the lower length field of the SETUP command*/
unsigned char LengthHigh; /* the higher length field of the SETUP command*/
} SETUPCOMMAND, *PSETUPCOMMAND;
/*HW reg-----------------------------------------------------------------*/
//Function Prototype---------------------------------------------------------------------------------
void usb_isr(void);
void config_usb_global_register(void);
void otg_enable_internal_debug_out(void);
//USB Global Test------------------------------------------------------------------------------------
void usb_global_startio(void);
void usb_global_dump_register(void);
void usb_global_port_status(volatile unsigned char port_num);
void usb_global_regulator_autopower(volatile unsigned char port_num);
void usb_global_port_pwr_enable(volatile unsigned char port_num);
void usb_global_port_pwr_disable(void);
void usb_global_regulator_turn_off(volatile unsigned char port_num);
void usb_global_regulator_turn_on(volatile unsigned char port_num);
void usb_global_ulpi_phy_write(volatile unsigned char port_num, volatile unsigned char addr, volatile unsigned char data);
unsigned char usb_global_ulpi_phy_read(volatile unsigned char port_num, volatile unsigned char addr);
void usb_global_bist_control(volatile unsigned char port_num);
//USB Host Test-------------------------------------------------------------------------------------
void usb_host_startio(void);
void usb_high_host_dump_register(void);
void usb_full_host_dump_register(void);
void usb_host_sof_en(volatile unsigned char enable);
unsigned char usb_port0_get_desc(void);
//OTG Test------------------------------------------------------------------------------------------
void usb_otg_startio(void);
void usb_otg_dump_register(void);
void usb_otg_srp_test(unsigned char port_num);
void usb_otg_srp_sess_req(void);
void usb_otg_a_set_b_hnp_en(volatile unsigned char control_bits);
void usb_otg_b_hnp_enable(volatile unsigned char control_bits);
void usb_otg_b_bus_req(volatile unsigned char control_bits);
unsigned char usb_otg_a_get_descriptor(void);
unsigned char usb_otg_b_get_descriptor(void);
//Device Test---------------------------------------------------------------------------------------
void usb_device_startio(void);
void usb_device_dump_register(void);
void usb_device_enable_1_5K_pull_up(unsigned char hnp_enable);
unsigned char usb_vt3104_get_desc_port0(unsigned char is_high_speed);
void usb_force_full_speed(void);
void FillData(UCHAR *Buf, int Size, int InitValue, int Method);
int CheckSetup(UINT SetupLo, UINT SetupHi);
int CheckMem(UCHAR *Mem0, UCHAR *Mem1, int Size);
//-----------------------------------------------------------------------------------------------------
// define pass() and fail() to replace original function call
#define pass() return(USB_TEST_SUCCESS)
#define fail() return(USB_TEST_FAIL)
void wmt_ep_setup(char *name, u8 addr, u8 type,unsigned maxp);
int wmt_udc_setup(void);
int wmt_udc_irq(void);
void dma_irq(int addr);
int BULK_XFER(UCHAR direction,UINT length);
void
GoCmd(
char *src,
char *dst,
unsigned long len
);
//-----------------------------------------------------------------------------------------------------
/*---------------------- usbcore.h ----------------------------------*/
/*
* Device State (c.f USB Spec 2.0 Figure 9-1)
*
* What state the usb device is in.
*
* Note the state does not change if the device is suspended, we simply set a
* flag to show that it is suspended.
*
*/
typedef enum usb_device_state {
STATE_INIT, /* just initialized */
STATE_CREATED, /* just created */
STATE_ATTACHED, /* we are attached */
STATE_POWERED, /* we have seen power indication (electrical bus signal) */
STATE_DEFAULT, /* we been reset */
STATE_ADDRESSED, /* we have been addressed (in default configuration) */
STATE_CONFIGURED, /* we have seen a set configuration device command */
STATE_UNKNOWN, /* destroyed */
} usb_device_state_t;
/*
* Device status
*
* Overall state
*/
typedef enum usb_device_status {
USBD_OPENING, /* we are currently opening */
USBD_OK, /* ok to use */
USBD_SUSPENDED, /* we are currently suspended */
USBD_CLOSING, /* we are currently closing */
} usb_device_status_t;
typedef enum usb_device_event {
DEVICE_UNKNOWN, /* bi - unknown event */
DEVICE_INIT, /* bi - initialize */
DEVICE_CREATE, /* bi - */
DEVICE_HUB_CONFIGURED, /* bi - bus has been plugged int */
DEVICE_RESET, /* bi - hub has powered our port */
DEVICE_ADDRESS_ASSIGNED, /* ep0 - set address setup received */
DEVICE_CONFIGURED, /* ep0 - set configure setup received */
DEVICE_SET_INTERFACE, /* ep0 - set interface setup received */
DEVICE_SET_FEATURE, /* ep0 - set feature setup received */
DEVICE_CLEAR_FEATURE, /* ep0 - clear feature setup received */
DEVICE_DE_CONFIGURED, /* ep0 - set configure setup received for ?? */
DEVICE_BUS_INACTIVE, /* bi - bus in inactive (no SOF packets) */
DEVICE_BUS_ACTIVITY, /* bi - bus is active again */
DEVICE_POWER_INTERRUPTION, /* bi - hub has depowered our port */
DEVICE_HUB_RESET, /* bi - bus has been unplugged */
DEVICE_DESTROY, /* bi - device instance should be destroyed */
DEVICE_HOTPLUG, /* bi - a hotplug event has occured */
DEVICE_FUNCTION_PRIVATE, /* function - private */
} usb_device_event_t;
/* USB Requests
*
*/
struct usb_device_request {
u8 bmRequestType;
u8 bRequest;
u16 wValue;
u16 wIndex;
u16 wLength;
} __attribute__ ((packed));
/* USB Status
*
*/
typedef enum urb_send_status {
SEND_IN_PROGRESS,
SEND_FINISHED_OK,
SEND_FINISHED_ERROR,
RECV_READY,
RECV_OK,
RECV_ERROR
} urb_send_status_t;
typedef struct urb_link {
struct urb_link *next;
struct urb_link *prev;
} urb_link;
#define URB_BUF_SIZE 128 /* in linux we'd malloc this, but in u-boot we prefer static data */
//Charles, 512K for urb buffer size
//#define URB_BUF_SIZE 0x80000 /* in linux we'd malloc this, but in u-boot we prefer static data */
struct urb {
struct usb_endpoint_instance *endpoint;
struct usb_device_instance *device;
struct usb_device_request device_request; /* contents of received SETUP packet */
struct urb_link link; /* embedded struct for circular doubly linked list of urbs */
u8* buffer;
unsigned int buffer_length;
unsigned int actual_length;
urb_send_status_t status;
int data;
u16 buffer_data[URB_BUF_SIZE]; /* data received (OUT) or being sent (IN) */
//u8 buffer_data[URB_BUF_SIZE]; /* data received (OUT) or being sent (IN) */
};
/* Endpoint configuration
*
* Per endpoint configuration data. Used to track which function driver owns
* an endpoint.
*
*/
struct usb_endpoint_instance {
int endpoint_address; /* logical endpoint address */
/* control */
int status; /* halted */
int state; /* available for use by bus interface driver */
/* receive side */
struct urb_link rcv; /* received urbs */
struct urb_link rdy; /* empty urbs ready to receive */
struct urb *rcv_urb; /* active urb */
int rcv_attributes; /* copy of bmAttributes from endpoint descriptor */
int rcv_packetSize; /* maximum packet size from endpoint descriptor */
int rcv_transferSize; /* maximum transfer size from function driver */
int rcv_queue;
/* transmit side */
struct urb_link tx; /* urbs ready to transmit */
struct urb_link done; /* transmitted urbs */
struct urb *tx_urb; /* active urb */
int tx_attributes; /* copy of bmAttributes from endpoint descriptor */
int tx_packetSize; /* maximum packet size from endpoint descriptor */
int tx_transferSize; /* maximum transfer size from function driver */
int tx_queue;
int sent; /* data already sent */
int last; /* data sent in last packet XXX do we need this */
}__attribute__ ((packed));
/*
* standard usb descriptor structures
*/
struct usb_endpoint_descriptor {
u8 bLength;
u8 bDescriptorType; /* 0x5 */
u8 bEndpointAddress;
u8 bmAttributes;
u16 wMaxPacketSize;
u8 bInterval;
} __attribute__ ((packed));
struct usb_interface_descriptor {
u8 bLength;
u8 bDescriptorType; /* 0x04 */
u8 bInterfaceNumber;
u8 bAlternateSetting;
u8 bNumEndpoints;
u8 bInterfaceClass;
u8 bInterfaceSubClass;
u8 bInterfaceProtocol;
u8 iInterface;
} __attribute__ ((packed));
struct usb_configuration_descriptor {
u8 bLength;
u8 bDescriptorType; /* 0x2 */
u16 wTotalLength;
u8 bNumInterfaces;
u8 bConfigurationValue;
u8 iConfiguration;
u8 bmAttributes;
u8 bMaxPower;
} __attribute__ ((packed));
struct usb_device_descriptor {
u8 bLength;
u8 bDescriptorType; /* 0x01 */
u16 bcdUSB;
u8 bDeviceClass;
u8 bDeviceSubClass;
u8 bDeviceProtocol;
u8 bMaxPacketSize0;
u16 idVendor;
u16 idProduct;
u16 bcdDevice;
u8 iManufacturer;
u8 iProduct;
u8 iSerialNumber;
u8 bNumConfigurations;
} __attribute__ ((packed));
struct usb_string_descriptor {
u8 bLength;
u8 bDescriptorType; /* 0x03 */
u16 wData[0];
} __attribute__ ((packed));
struct usb_generic_descriptor {
u8 bLength;
u8 bDescriptorType;
u8 bDescriptorSubtype;
} __attribute__ ((packed));
struct usb_alternate_instance {
struct usb_interface_descriptor *interface_descriptor;
int endpoints;
int *endpoint_transfersize_array;
struct usb_endpoint_descriptor **endpoints_descriptor_array;
};
struct usb_interface_instance {
int alternates;
struct usb_alternate_instance *alternates_instance_array;
};
struct usb_configuration_instance {
int interfaces;
struct usb_configuration_descriptor *configuration_descriptor;
struct usb_interface_instance *interface_instance_array;
};
/* USB Device Instance
*
* For each physical bus interface we create a logical device structure. This
* tracks all of the required state to track the USB HOST's view of the device.
*
* Keep track of the device configuration for a real physical bus interface,
* this includes the bus interface, multiple function drivers, the current
* configuration and the current state.
*
* This will show:
* the specific bus interface driver
* the default endpoint 0 driver
* the configured function driver
* device state
* device status
* endpoint list
*/
struct usb_device_instance {
/* generic */
char *name;
struct usb_device_descriptor *device_descriptor; /* per device descriptor */
void (*event) (struct usb_device_instance *device, usb_device_event_t event, int data);
int (*cdc_recv_setup)(struct usb_device_request *request, struct urb *urb);
/* bus interface */
struct usb_bus_instance *bus; /* which bus interface driver */
/* configuration descriptors */
int configurations;
struct usb_configuration_instance *configuration_instance_array;
/* device state */
usb_device_state_t device_state; /* current USB Device state */
usb_device_state_t device_previous_state; /* current USB Device state */
u8 address; /* current address (zero is default) */
u8 configuration; /* current show configuration (zero is default) */
u8 interface; /* current interface (zero is default) */
u8 alternate; /* alternate flag */
usb_device_status_t status; /* device status */
int urbs_queued; /* number of submitted urbs */
/* Shouldn't need to make this atomic, all we need is a change indicator */
unsigned long usbd_rxtx_timestamp;
unsigned long usbd_last_rxtx_timestamp;
unsigned int speed;
};
/* Bus Interface configuration structure
*
* This is allocated for each configured instance of a bus interface driver.
*
* The privdata pointer may be used by the bus interface driver to store private
* per instance state information.
*/
struct usb_bus_instance {
struct usb_device_instance *device;
struct usb_endpoint_instance *endpoint_array; /* array of available configured endpoints */
int max_endpoints; /* maximimum number of rx enpoints */
unsigned char maxpacketsize;
unsigned int serial_number;
char *serial_number_str;
void *privdata; /* private data for the bus interface */
};
/*--------------------------------------------------------------------------------------*/
/* Declarations */
int udc_init(void);
void udc_endpoint_write(struct usb_endpoint_instance *endpoint);
void udc_setup_ep(struct usb_device_instance *device, unsigned int ep,
struct usb_endpoint_instance *endpoint);
void udc_connect(void);
void udc_disconnect(void);
void udc_enable(struct usb_device_instance *device);
void udc_disable(void);
void udc_startup_events(struct usb_device_instance *device);
void udc_device_dump_register(void);
void udc_bulk_dma_dump_register(void);
void memdump (void *pv, int num);
/* Flow control */
//void udc_set_nak(int epid);
//void udc_unset_nak (int epid);
int wmt_udc_connected(void);
#endif
|