3 * Copyright (C) 2015 Rockchip Electronics
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 #ifndef __DWC2_REGISTERS__
15 #define __DWC2_REGISTERS__
17 #define MAX_EPS_CHANNELS 16
19 typedef struct core_reg
{
41 uint32_t reserved1
[(0x100 - 0x54) / 4];
43 uint32_t dptxfsiz_dieptxf
[MAX_EPS_CHANNELS
- 1];
44 uint32_t reserved2
[(0x400 - 0x140) / 4];
47 typedef struct hc_reg
{
57 /* Host Mode Register Structures */
58 typedef struct host_reg
{
66 uint32_t reserved1
[(0x440 - 0x41c) / 4];
68 uint32_t reserved2
[(0x500 - 0x444) / 4];
69 hc_reg_t hchn
[MAX_EPS_CHANNELS
];
70 uint32_t reserved3
[(0x800 - 0x700) / 4];
73 typedef struct ep_reg
{
84 /* Device Mode Registers Structures */
85 typedef struct device_reg
{
98 uint32_t dtknqr3_dthrctl
;
99 uint32_t dtknqr4_fifoemptymsk
;
100 uint32_t reserved1
[(0x900 - 0x838) / 4];
102 dwc2_ep_reg_t inep
[MAX_EPS_CHANNELS
];
103 dwc2_ep_reg_t outep
[MAX_EPS_CHANNELS
];
104 uint32_t reserved8
[(0xe00 - 0xd00) / 4];
107 typedef struct pwr_clk_ctrl_reg
{
109 uint32_t reserved
[(0x1000 - 0xe04) / 4];
110 } pwr_clk_ctrl_reg_t
;
112 typedef struct data_fifo
{
114 uint32_t reserved
[(0x1000 - 0x004) / 4];
117 typedef struct dwc2_otg_reg
{
121 pwr_clk_ctrl_reg_t pcgr
;
122 data_fifo_t dfifo
[MAX_EPS_CHANNELS
];
123 uint32_t reserved
[(0x40000 - 0x11000) / 4];
127 * This union represents the bit fields of the Core AHB Configuration
128 * Register (GAHBCFG).
131 /* raw register data */
135 unsigned glblintrmsk
:1;
136 #define GLBINT_ENABLE 1
139 #define DMA_BURST_SINGLE 0
140 #define DMA_BURST_INCR 1
141 #define DMA_BURST_INCR4 3
142 #define DMA_BURST_INCR8 5
143 #define DMA_BURST_INCR16 7
147 unsigned nptxfemplvl
:1;
148 unsigned ptxfemplvl
:1;
149 unsigned reserved9_31
:23;
154 * This union represents the bit fields of the Core USB Configuration
155 * Register (GUSBCFG).
158 /* raw register data */
164 unsigned ulpiutmisel
:1;
170 unsigned usbtrdtim
:4;
171 unsigned reserved14
:1;
172 unsigned phylpwrclksel
:1;
173 unsigned otgi2csel
:1;
175 unsigned ulpiautores
:1;
176 unsigned ulpiclksusm
:1;
177 unsigned ulpiextvbusdrv
:1;
178 unsigned ulpiextvbusindicator
:1;
179 unsigned termseldlpulse
:1;
180 unsigned reserved23_28
:6;
181 unsigned forcehstmode
:1;
182 unsigned forcedevmode
:1;
188 * This union represents the bit fields of the Core Reset Register
192 /* raw register data */
196 /** Core Soft Reset (CSftRst) (Device and Host)
198 * The application can flush the control logic in the
199 * entire core using this bit. This bit resets the
200 * pipelines in the AHB Clock domain as well as the
203 * The state machines are reset to an IDLE state, the
204 * control bits in the CSRs are cleared, all the
205 * transmit FIFOs and the receive FIFO are flushed.
207 * The status mask bits that control the generation of
208 * the interrupt, are cleared, to clear the
209 * interrupt. The interrupt status bits are not
210 * cleared, so the application can get the status of
211 * any events that occurred in the core after it has
214 * Any transactions on the AHB are terminated as soon
215 * as possible following the protocol. Any
216 * transactions on the USB are terminated immediately.
218 * The configuration settings in the CSRs are
219 * unchanged, so the software doesn't have to
220 * reprogram these registers (Device
221 * Configuration/Host Configuration/Core System
222 * Configuration/Core PHY Configuration).
224 * The application can write to this bit, any time it
225 * wants to reset the core. This is a self clearing
226 * bit and the core clears this bit after all the
227 * necessary logic is reset in the core, which may
228 * take several clocks, depending on the current state
234 * The application uses this bit to reset the control logic in
235 * the AHB clock domain. Only AHB clock domain pipelines are
239 /** Host Frame Counter Reset (Host Only)<br>
241 * The application can reset the (micro)frame number
242 * counter inside the core, using this bit. When the
243 * (micro)frame counter is reset, the subsequent SOF
244 * sent out by the core, will have a (micro)frame
247 unsigned frmcntrrst
:1;
248 /** In Token Sequence Learning Queue Flush
249 * (INTknQFlsh) (Device Only)
251 unsigned intknqflsh
:1;
252 /** RxFIFO Flush (RxFFlsh) (Device and Host)
254 * The application can flush the entire Receive FIFO
255 * using this bit. <p>The application must first
256 * ensure that the core is not in the middle of a
257 * transaction. <p>The application should write into
258 * this bit, only after making sure that neither the
259 * DMA engine is reading from the RxFIFO nor the MAC
260 * is writing the data in to the FIFO. <p>The
261 * application should wait until the bit is cleared
262 * before performing any other operations. This bit
263 * will takes 8 clocks (slowest of PHY or AHB clock)
267 /** TxFIFO Flush (TxFFlsh) (Device and Host).
269 * This bit is used to selectively flush a single or
270 * all transmit FIFOs. The application must first
271 * ensure that the core is not in the middle of a
272 * transaction. <p>The application should write into
273 * this bit, only after making sure that neither the
274 * DMA engine is writing into the TxFIFO nor the MAC
275 * is reading the data out of the FIFO. <p>The
276 * application should wait until the core clears this
277 * bit, before performing any operations. This bit
278 * will takes 8 clocks (slowest of PHY or AHB clock)
283 /** TxFIFO Number (TxFNum) (Device and Host).
285 * This is the FIFO number which needs to be flushed,
286 * using the TxFIFO Flush bit. This field should not
287 * be changed until the TxFIFO Flush bit is cleared by
289 * - 0x0 : Non Periodic TxFIFO Flush
290 * - 0x1 : Periodic TxFIFO #1 Flush in device mode
291 * or Periodic TxFIFO in host mode
292 * - 0x2 : Periodic TxFIFO #2 Flush in device mode.
294 * - 0xF : Periodic TxFIFO #15 Flush in device mode
295 * - 0x10: Flush all the Transmit NonPeriodic and
296 * Transmit Periodic FIFOs in the core
300 unsigned reserved11_29
:19;
301 /** DMA Request Signal. Indicated DMA request is in
302 * probress. Used for debug purpose. */
304 /** AHB Master Idle. Indicates the AHB Master State
305 * Machine is in IDLE condition. */
311 * This union represents the bit fields of the Core Interrupt Mask
312 * Register (GINTMSK).
315 /* raw register data */
325 unsigned ginnakeff
:1;
326 unsigned goutnakeff
:1;
327 unsigned reserved8
:1;
333 unsigned isooutdrop
:1;
335 unsigned reserved16
:1;
339 unsigned incompisoin
:1;
341 unsigned reserved22_23
:2;
345 unsigned reserved27
:1;
346 unsigned conidstschng
:1;
347 unsigned disconnint
:1;
348 unsigned sessreqint
:1;
354 * This union represents the bit fields of the Core Non-Periodic
355 * Transmit FIFO Size Register(GNPTXFSIZ).
358 /* raw register data */
362 unsigned txfstaddr
:16;
368 * This union represents the bit fields of the Core Receive FIFO Size
372 /* raw register data */
375 /*The value in this fieles is in terms of 32-bit words size.
379 unsigned reserved
:16;
384 * This union represents the bit fields of the Core Device
385 * Transmit FIFO Size Register(GNPTXFSIZ).
388 /* raw register data */
392 unsigned dtxfstaddr
:16;
398 * This union represents the bit fields of the Core Interrupt Register
402 /* raw register data */
404 #define SOF_INTR_MASK 0x0008
409 #define DEVICE_MODE 0
415 unsigned ginnakeff
:1;
416 unsigned goutnakeff
:1;
417 unsigned reserved8
:1;
423 unsigned isooutdrop
:1;
425 unsigned reserved16_17
:2;
428 unsigned reserved20
:1;
430 unsigned reserved22_23
:2;
434 unsigned reserved27
:1;
435 unsigned conidstschng
:1;
436 unsigned disconnint
:1;
437 unsigned sessreqint
:1;
442 #define GINTSTS_WKUPINT (1 << 31)
443 #define GINTSTS_SESSREQINT (1 << 30)
444 #define GINTSTS_DISCONNINT (1 << 29)
445 #define GINTSTS_CONIDSTSCHNG (1 << 28)
446 #define GINTSTS_LPMTRANRCVD (1 << 27)
447 #define GINTSTS_PTXFEMP (1 << 26)
448 #define GINTSTS_HCHINT (1 << 25)
449 #define GINTSTS_PRTINT (1 << 24)
450 #define GINTSTS_RESETDET (1 << 23)
451 #define GINTSTS_FET_SUSP (1 << 22)
452 #define GINTSTS_INCOMPL_IP (1 << 21)
453 #define GINTSTS_INCOMPL_SOIN (1 << 20)
454 #define GINTSTS_OEPINT (1 << 19)
455 #define GINTSTS_IEPINT (1 << 18)
456 #define GINTSTS_EPMIS (1 << 17)
457 #define GINTSTS_RESTOREDONE (1 << 16)
458 #define GINTSTS_EOPF (1 << 15)
459 #define GINTSTS_ISOUTDROP (1 << 14)
460 #define GINTSTS_ENUMDONE (1 << 13)
461 #define GINTSTS_USBRST (1 << 12)
462 #define GINTSTS_USBSUSP (1 << 11)
463 #define GINTSTS_ERLYSUSP (1 << 10)
464 #define GINTSTS_I2CINT (1 << 9)
465 #define GINTSTS_ULPI_CK_INT (1 << 8)
466 #define GINTSTS_GOUTNAKEFF (1 << 7)
467 #define GINTSTS_GINNAKEFF (1 << 6)
468 #define GINTSTS_NPTXFEMP (1 << 5)
469 #define GINTSTS_RXFLVL (1 << 4)
470 #define GINTSTS_SOF (1 << 3)
471 #define GINTSTS_OTGINT (1 << 2)
472 #define GINTSTS_MODEMIS (1 << 1)
473 #define GINTSTS_CURMODE_HOST (1 << 0)
476 * This union represents the bit fields of the User HW Config3 Register
480 /* raw register data */
484 unsigned reserved
:16;
485 unsigned dfifodepth
:16;
490 * This union represents the bit fields in the Host Configuration Register.
493 /* raw register data */
498 /** FS/LS Phy Clock Select */
499 unsigned fslspclksel
:2;
500 #define PHYCLK_30_60_MHZ 0
501 #define PHYCLK_48_MHZ 1
502 #define PHYCLK_6_MHZ 2
504 /** FS/LS Only Support */
510 * This union represents the bit fields in the Host Frame Number/Frame Time
514 /* raw register data */
521 /** Frame Time Remaining */
527 * This union represents the bit fields in the Host Port Control and status
531 /* raw register data */
535 unsigned prtconnsts
:1;
536 unsigned prtconndet
:1;
538 unsigned prtenchng
:1;
539 unsigned prtovrcurract
:1;
540 unsigned prtovrcurrchng
:1;
544 unsigned reserved9
:1;
547 unsigned prttstctl
:4;
549 #define PRTSPD_HIGH 0
550 #define PRTSPD_FULL 1
552 unsigned reserved19_31
:13;
556 #define HPRT_W1C_MASK (~((1 << 1) | (1 << 2) | (1 << 3) | (1 << 5)))
559 * This union represents the bit fields in the Host Channel Characteristics
563 /* raw register data */
568 /** Maximum packet size in bytes */
570 /** Endpoint number */
575 /** 0: Full/high speed device, 1: Low speed device */
577 /** 0: Control, 1: Isoc, 2: Bulk, 3: Intr */
579 /** Packets per frame for periodic transfers. 0 is reserved. */
581 /** Device address */
584 * Frame to transmit periodic transaction.
588 /** Channel disable */
590 /** Channel enable */
596 * This union represents the bit fields in the Host Channel-n Split Control
600 /* raw register data */
609 /** Transaction Position */
611 /** Do Complete Split */
613 unsigned reserved
:14;
625 * This union represents the bit fields in the Host All Interrupt
629 /* raw register data */
633 /** Transfer Complete */
635 /** Channel Halted */
639 /** STALL Response Received */
641 /** NAK Response Received */
643 /** ACK Response Received */
645 /** NYET Response Received */
647 /** Transaction Err */
653 /** Data Toggle Error */
654 unsigned datatglerr
:1;
656 unsigned reserved
:21;
661 * This union represents the bit fields in the Host Channel Transfer Size
665 /* raw register data */
670 /* Total transfer size in bytes */
671 unsigned xfersize
:19;
672 /** Data packets to transfer */
675 * Packet ID for next data packet
679 * 3: MDATA (non-Control), SETUP (Control)
687 /* Do PING protocol when 1 */
693 * This union represents the bit fields in the Host Channel Interrupt Mask
697 /* raw register data */
711 unsigned datatglerr
:1;
712 unsigned reserved
:21;
717 /* raw register data */
722 unsigned nzstsouthshk
:1;
723 unsigned ena32ksusp
:1;
726 unsigned endevoutnak
:1;
727 unsigned reservedi14_17
:4;
729 unsigned reserved26_31
:9;
734 /* raw register data */
740 unsigned errticerr
:1;
741 unsigned reserved4_31
:28;
746 /* raw register data */
750 unsigned rmtwkupsig
:1;
751 unsigned sftdiscon
:1;
752 unsigned gnpinnaksts
:1;
753 unsigned goutnaksts
:1;
755 unsigned sgnpinnak
:1;
756 unsigned cgnpinnak
:1;
759 unsigned pwronprgdone
:1;
760 unsigned reserved12
:1;
762 unsigned ignrfrmnum
:1;
763 unsigned nakonbble
:1;
764 unsigned encontbna
:1;
765 unsigned reserved19_31
:14;
770 /* raw register data */
774 #define D0EPCTL_MPS_SHIFT 0
775 #define D0EPCTL_MPS_64 0
776 #define D0EPCTL_MPS_32 1
777 #define D0EPCTL_MPS_16 2
778 #define D0EPCTL_MPS_8 3
785 unsigned reserved20
:1;
798 /* raw register data */
802 unsigned xfercompl
:1;
806 unsigned reserved4_14
:12;
807 unsigned stuppktrcvd
:1;
808 unsigned reserved16_31
:15;
812 #define DXEPINT_SETUP_RCVD (1 << 15)
813 #define DXEPINT_INEPNAKEFF (1 << 6)
814 #define DXEPINT_BACK2BACKSETUP (1 << 6)
815 #define DXEPINT_INTKNEPMIS (1 << 5)
816 #define DXEPINT_INTKNTXFEMP (1 << 4)
817 #define DXEPINT_OUTTKNEPDIS (1 << 4)
818 #define DXEPINT_TIMEOUT (1 << 3)
819 #define DXEPINT_SETUP (1 << 3)
820 #define DXEPINT_AHBERR (1 << 2)
821 #define DXEPINT_EPDISBLD (1 << 1)
822 #define DXEPINT_XFERCOMPL (1 << 0)
825 /* raw register data */
829 unsigned xfersize
:19;
832 unsigned reserved31
:1;
836 #define DAINT_OUTEP_SHIFT MAX_EPS_CHANNELS