2 * Copyright (C) 2006 Bryan O'Donoghue, CodeHermit
3 * bodonoghue@codehermit.ie
5 * SPDX-License-Identifier: GPL-2.0+
12 #define USMOD_HOST 0x02
13 #define USMOD_TEST 0x04
14 #define USMOD_SFTE 0x08
15 #define USMOD_RESUME 0x40
16 #define USMOD_LSS 0x80
18 /* Endpoint Registers */
19 #define USEP_RHS_NORM 0x00
20 #define USEP_RHS_IGNORE 0x01
21 #define USEP_RHS_NAK 0x02
22 #define USEP_RHS_STALL 0x03
24 #define USEP_THS_NORM 0x00
25 #define USEP_THS_IGNORE 0x04
26 #define USEP_THS_NAK 0x08
27 #define USEP_THS_STALL 0x0C
32 #define USEP_TM_CONTROL 0x00
33 #define USEP_TM_INT 0x100
34 #define USEP_TM_BULK 0x200
35 #define USEP_TM_ISO 0x300
37 /* Command Register */
38 #define USCOM_EP0 0x00
39 #define USCOM_EP1 0x01
40 #define USCOM_EP2 0x02
41 #define USCOM_EP3 0x03
43 #define USCOM_FLUSH 0x40
44 #define USCOM_STR 0x80
47 #define USB_E_RXB 0x0001
48 #define USB_E_TXB 0x0002
49 #define USB_E_BSY 0x0004
50 #define USB_E_SOF 0x0008
51 #define USB_E_TXE1 0x0010
52 #define USB_E_TXE2 0x0020
53 #define USB_E_TXE3 0x0040
54 #define USB_E_TXE4 0x0080
55 #define USB_TX_ERRMASK (USB_E_TXE1|USB_E_TXE2|USB_E_TXE3|USB_E_TXE4)
56 #define USB_E_IDLE 0x0100
57 #define USB_E_RESET 0x0200
60 #define USBS_IDLE 0x01
62 /* RX Buffer Descriptor */
67 #define RX_BD_PID_DATA0 0x00
68 #define RX_BD_PID_DATA1 0x40
69 #define RX_BD_PID_SETUP 0x80
72 #define RX_BD_I 0x1000
73 #define RX_BD_W 0x2000
74 #define RX_BD_E 0x8000
77 #define RX_BD_PID_BITMASK (RX_BD_PID_DATA1 | RX_BD_PID_SETUP)
78 #define STALL_BITMASK (USEP_THS_STALL | USEP_RHS_STALL)
79 #define NAK_BITMASK (USEP_THS_NAK | USEP_RHS_NAK)
80 #define CBD_TX_BITMASK (TX_BD_R | TX_BD_L | TX_BD_TC | TX_BD_I | TX_BD_CNF)
82 /* TX Buffer Descriptor */
85 #define TX_BD_NO_PID 0x00
86 #define TX_BD_PID_DATA0 0x80
87 #define TX_BD_PID_DATA1 0xC0
88 #define TX_BD_CNF 0x200
89 #define TX_BD_TC 0x400
91 #define TX_BD_I 0x1000
92 #define TX_BD_W 0x2000
93 #define TX_BD_R 0x8000
95 /* Implementation specific defines */
97 #define EP_MIN_PACKET_SIZE 0x08
98 #define MAX_ENDPOINTS 0x04
99 #define FIFO_SIZE 0x10
100 #define EP_MAX_PKT FIFO_SIZE
101 #define TX_RING_SIZE 0x04
102 #define RX_RING_SIZE 0x06
103 #define USB_MAX_PKT 0x40
104 #define TOGGLE_TX_PID(x) x= ((~x)&0x40)|0x80
105 #define TOGGLE_RX_PID(x) x^= 0x40
106 #define EP_ATTACHED 0x01 /* Endpoint has a urb attached or not */
107 #define EP_SEND_ZLP 0x02 /* Send ZLP y/n ? */
109 #define PROFF_USB 0x00000000
110 #define CPM_USB_BASE 0x00000A00
112 /* UDC device defines */
113 #define EP0_MAX_PACKET_SIZE EP_MAX_PKT
114 #define UDC_OUT_ENDPOINT 0x02
115 #define UDC_OUT_PACKET_SIZE EP_MIN_PACKET_SIZE
116 #define UDC_IN_ENDPOINT 0x03
117 #define UDC_IN_PACKET_SIZE EP_MIN_PACKET_SIZE
118 #define UDC_INT_ENDPOINT 0x01
119 #define UDC_INT_PACKET_SIZE UDC_IN_PACKET_SIZE
120 #define UDC_BULK_PACKET_SIZE EP_MIN_PACKET_SIZE
126 volatile cbd_t * prx;
129 typedef struct mpc8xx_usb{
130 char usmod; /* Mode Register */
131 char usaddr; /* Slave Address Register */
132 char uscom; /* Command Register */
133 char res1; /* Reserved */
135 ulong res2; /* Reserved */
136 ushort usber; /* Event Register */
137 ushort res3; /* Reserved */
138 ushort usbmr; /* Mask Register */
139 char res4; /* Reserved */
140 char usbs; /* Status Register */
141 char res5[8]; /* Reserved */
144 typedef struct mpc8xx_parameter_ram{
145 ushort ep0ptr; /* Endpoint Pointer Register 0 */
146 ushort ep1ptr; /* Endpoint Pointer Register 1 */
147 ushort ep2ptr; /* Endpoint Pointer Register 2 */
148 ushort ep3ptr; /* Endpoint Pointer Register 3 */
149 uint rstate; /* Receive state */
150 uint rptr; /* Receive internal data pointer */
151 ushort frame_n; /* Frame number */
152 ushort rbcnt; /* Receive byte count */
153 uint rtemp; /* Receive temp cp use only */
154 uint rxusb; /* Rx Data Temp */
155 ushort rxuptr; /* Rx microcode return address temp */
158 typedef struct endpoint_parameter_block_pointer{
159 ushort rbase; /* RxBD base address */
160 ushort tbase; /* TxBD base address */
161 char rfcr; /* Rx Function code */
162 char tfcr; /* Tx Function code */
163 ushort mrblr; /* Maximum Receive Buffer Length */
164 ushort rbptr; /* RxBD pointer Next Buffer Descriptor */
165 ushort tbptr; /* TxBD pointer Next Buffer Descriptor */
166 ulong tstate; /* Transmit internal state */
167 ulong tptr; /* Transmit internal data pointer */
168 ushort tcrc; /* Transmit temp CRC */
169 ushort tbcnt; /* Transmit internal bye count */
170 ulong ttemp; /* Tx temp */
171 ushort txuptr; /* Tx microcode return address */
172 ushort res1; /* Reserved */
175 typedef enum mpc8xx_udc_state{
184 int udc_endpoint_write(struct usb_endpoint_instance *endpoint);
185 void udc_setup_ep(struct usb_device_instance *device, unsigned int ep,
186 struct usb_endpoint_instance *endpoint);
187 void udc_connect(void);
188 void udc_disconnect(void);
189 void udc_enable(struct usb_device_instance *device);
190 void udc_disable(void);
191 void udc_startup_events(struct usb_device_instance *device);
194 void udc_set_nak(int epid);
195 void udc_unset_nak (int epid);