3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
13 * The USB controller is tested in the local loopback mode.
14 * It is configured so that endpoint 0 operates as host and endpoint 1
15 * operates as function endpoint. After that an IN token transaction
17 * Refer to MPC850 User Manual, Section 32.11.1 USB Host Controller
18 * Initialization Example.
23 #if CONFIG_POST & CONFIG_SYS_POST_USB
30 #define PROFF_USB ((uint)0x0000)
32 #define CPM_USB_EP0_BASE 0x0a00
33 #define CPM_USB_EP1_BASE 0x0a20
35 #define CPM_USB_DT0_BASE 0x0a80
36 #define CPM_USB_DT1_BASE 0x0a90
37 #define CPM_USB_DR0_BASE 0x0aa0
38 #define CPM_USB_DR1_BASE 0x0ab0
40 #define CPM_USB_RX0_BASE 0x0b00
41 #define CPM_USB_RX1_BASE 0x0b08
42 #define CPM_USB_TX0_BASE 0x0b20
43 #define CPM_USB_TX1_BASE 0x0b28
45 #define USB_EXPECT(x) if (!(x)) goto Done;
47 typedef struct usb_param {
59 typedef struct usb_param_block {
89 int usb_post_test (int flags)
92 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
93 volatile cpm8xx_t *cp = &(im->im_cpm);
94 volatile usb_param_t *pram_ptr;
100 volatile usb_param_block_t *ep0;
101 volatile usb_param_block_t *ep1;
104 pram_ptr = (usb_param_t *) & (im->im_cpm.cp_dparam[PROFF_USB]);
105 dpram = (uint) im->im_cpm.cp_dpmem;
107 tx = (cbd_t *) (dpram + CPM_USB_TX0_BASE);
108 rx = (cbd_t *) (dpram + CPM_USB_RX0_BASE);
109 ep0 = (usb_param_block_t *) (dpram + CPM_USB_EP0_BASE);
110 ep1 = (usb_param_block_t *) (dpram + CPM_USB_EP1_BASE);
111 usbr = (usb_t *) & (im->im_cpm.cp_scc[0]);
114 im->im_ioport.iop_padir &= ~(ushort) 0x0200;
115 im->im_ioport.iop_papar |= (ushort) 0x0200;
117 cp->cp_sicr &= ~0x000000FF;
118 cp->cp_sicr |= 0x00000018;
120 cp->cp_brgc4 = 0x00010001;
123 im->im_ioport.iop_padir &= ~(ushort) 0x0002;
124 im->im_ioport.iop_padir &= ~(ushort) 0x0001;
126 im->im_ioport.iop_papar |= (ushort) 0x0002;
127 im->im_ioport.iop_papar |= (ushort) 0x0001;
130 im->im_ioport.iop_pcdir &= ~(ushort) 0x0020;
131 im->im_ioport.iop_pcdir &= ~(ushort) 0x0010;
133 im->im_ioport.iop_pcpar &= ~(ushort) 0x0020;
134 im->im_ioport.iop_pcpar &= ~(ushort) 0x0010;
136 im->im_ioport.iop_pcso |= (ushort) 0x0020;
137 im->im_ioport.iop_pcso |= (ushort) 0x0010;
140 im->im_ioport.iop_pcdir |= (ushort) 0x0200;
141 im->im_ioport.iop_pcdir |= (ushort) 0x0100;
143 im->im_ioport.iop_pcpar |= (ushort) 0x0200;
144 im->im_ioport.iop_pcpar |= (ushort) 0x0100;
147 pram_ptr->frame_n = 0;
150 pram_ptr->ep0ptr = DPRAM + CPM_USB_EP0_BASE;
151 pram_ptr->ep1ptr = DPRAM + CPM_USB_EP1_BASE;
154 tx[0].cbd_sc = 0xB800;
155 tx[0].cbd_datlen = 3;
156 tx[0].cbd_bufaddr = dpram + CPM_USB_DT0_BASE;
158 tx[1].cbd_sc = 0xBC80;
159 tx[1].cbd_datlen = 3;
160 tx[1].cbd_bufaddr = dpram + CPM_USB_DT1_BASE;
162 rx[0].cbd_sc = 0xA000;
163 rx[0].cbd_datlen = 0;
164 rx[0].cbd_bufaddr = dpram + CPM_USB_DR0_BASE;
166 rx[1].cbd_sc = 0xA000;
167 rx[1].cbd_datlen = 0;
168 rx[1].cbd_bufaddr = dpram + CPM_USB_DR1_BASE;
171 *(volatile int *) (dpram + CPM_USB_DT0_BASE) = 0x69856000;
172 *(volatile int *) (dpram + CPM_USB_DT1_BASE) = 0xABCD1234;
174 *(volatile int *) (dpram + CPM_USB_DR0_BASE) = 0;
175 *(volatile int *) (dpram + CPM_USB_DR1_BASE) = 0;
178 ep0->rbase = DPRAM + CPM_USB_RX0_BASE;
179 ep0->tbase = DPRAM + CPM_USB_TX0_BASE;
183 ep0->rbptr = DPRAM + CPM_USB_RX0_BASE;
184 ep0->tbptr = DPRAM + CPM_USB_TX0_BASE;
188 ep1->rbase = DPRAM + CPM_USB_RX1_BASE;
189 ep1->tbase = DPRAM + CPM_USB_TX1_BASE;
193 ep1->rbptr = DPRAM + CPM_USB_RX1_BASE;
194 ep1->tbptr = DPRAM + CPM_USB_TX1_BASE;
198 usbr->usep[0] = 0x0000;
199 usbr->usep[1] = 0x1100;
200 usbr->usep[2] = 0x2200;
201 usbr->usep[3] = 0x3300;
220 /* Wait for the data packet to be transmitted */
221 for (j = 0; j < TOUT_LOOP; j++) {
222 if (tx[1].cbd_sc & (ushort) 0x8000)
228 USB_EXPECT (j < TOUT_LOOP);
230 USB_EXPECT (tx[0].cbd_sc == 0x3800);
231 USB_EXPECT (tx[0].cbd_datlen == 3);
233 USB_EXPECT (tx[1].cbd_sc == 0x3C80);
234 USB_EXPECT (tx[1].cbd_datlen == 3);
236 USB_EXPECT (rx[0].cbd_sc == 0x2C00);
237 USB_EXPECT (rx[0].cbd_datlen == 5);
239 USB_EXPECT (*(volatile int *) (dpram + CPM_USB_DR0_BASE) ==
241 USB_EXPECT (*(volatile char *) (dpram + CPM_USB_DR0_BASE + 4) == 0x42);
249 #endif /* CONFIG_POST & CONFIG_SYS_POST_USB */