3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * The USB controller is tested in the local loopback mode.
30 * It is configured so that endpoint 0 operates as host and endpoint 1
31 * operates as function endpoint. After that an IN token transaction
33 * Refer to MPC850 User Manual, Section 32.11.1 USB Host Controller
34 * Initialization Example.
39 #if CONFIG_POST & CONFIG_SYS_POST_USB
46 #define PROFF_USB ((uint)0x0000)
48 #define CPM_USB_EP0_BASE 0x0a00
49 #define CPM_USB_EP1_BASE 0x0a20
51 #define CPM_USB_DT0_BASE 0x0a80
52 #define CPM_USB_DT1_BASE 0x0a90
53 #define CPM_USB_DR0_BASE 0x0aa0
54 #define CPM_USB_DR1_BASE 0x0ab0
56 #define CPM_USB_RX0_BASE 0x0b00
57 #define CPM_USB_RX1_BASE 0x0b08
58 #define CPM_USB_TX0_BASE 0x0b20
59 #define CPM_USB_TX1_BASE 0x0b28
61 #define USB_EXPECT(x) if (!(x)) goto Done;
63 typedef struct usb_param {
75 typedef struct usb_param_block {
105 int usb_post_test (int flags)
108 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
109 volatile cpm8xx_t *cp = &(im->im_cpm);
110 volatile usb_param_t *pram_ptr;
115 volatile usb_t *usbr;
116 volatile usb_param_block_t *ep0;
117 volatile usb_param_block_t *ep1;
120 pram_ptr = (usb_param_t *) & (im->im_cpm.cp_dparam[PROFF_USB]);
121 dpram = (uint) im->im_cpm.cp_dpmem;
123 tx = (cbd_t *) (dpram + CPM_USB_TX0_BASE);
124 rx = (cbd_t *) (dpram + CPM_USB_RX0_BASE);
125 ep0 = (usb_param_block_t *) (dpram + CPM_USB_EP0_BASE);
126 ep1 = (usb_param_block_t *) (dpram + CPM_USB_EP1_BASE);
127 usbr = (usb_t *) & (im->im_cpm.cp_scc[0]);
130 im->im_ioport.iop_padir &= ~(ushort) 0x0200;
131 im->im_ioport.iop_papar |= (ushort) 0x0200;
133 cp->cp_sicr &= ~0x000000FF;
134 cp->cp_sicr |= 0x00000018;
136 cp->cp_brgc4 = 0x00010001;
139 im->im_ioport.iop_padir &= ~(ushort) 0x0002;
140 im->im_ioport.iop_padir &= ~(ushort) 0x0001;
142 im->im_ioport.iop_papar |= (ushort) 0x0002;
143 im->im_ioport.iop_papar |= (ushort) 0x0001;
146 im->im_ioport.iop_pcdir &= ~(ushort) 0x0020;
147 im->im_ioport.iop_pcdir &= ~(ushort) 0x0010;
149 im->im_ioport.iop_pcpar &= ~(ushort) 0x0020;
150 im->im_ioport.iop_pcpar &= ~(ushort) 0x0010;
152 im->im_ioport.iop_pcso |= (ushort) 0x0020;
153 im->im_ioport.iop_pcso |= (ushort) 0x0010;
156 im->im_ioport.iop_pcdir |= (ushort) 0x0200;
157 im->im_ioport.iop_pcdir |= (ushort) 0x0100;
159 im->im_ioport.iop_pcpar |= (ushort) 0x0200;
160 im->im_ioport.iop_pcpar |= (ushort) 0x0100;
163 pram_ptr->frame_n = 0;
166 pram_ptr->ep0ptr = DPRAM + CPM_USB_EP0_BASE;
167 pram_ptr->ep1ptr = DPRAM + CPM_USB_EP1_BASE;
170 tx[0].cbd_sc = 0xB800;
171 tx[0].cbd_datlen = 3;
172 tx[0].cbd_bufaddr = dpram + CPM_USB_DT0_BASE;
174 tx[1].cbd_sc = 0xBC80;
175 tx[1].cbd_datlen = 3;
176 tx[1].cbd_bufaddr = dpram + CPM_USB_DT1_BASE;
178 rx[0].cbd_sc = 0xA000;
179 rx[0].cbd_datlen = 0;
180 rx[0].cbd_bufaddr = dpram + CPM_USB_DR0_BASE;
182 rx[1].cbd_sc = 0xA000;
183 rx[1].cbd_datlen = 0;
184 rx[1].cbd_bufaddr = dpram + CPM_USB_DR1_BASE;
187 *(volatile int *) (dpram + CPM_USB_DT0_BASE) = 0x69856000;
188 *(volatile int *) (dpram + CPM_USB_DT1_BASE) = 0xABCD1234;
190 *(volatile int *) (dpram + CPM_USB_DR0_BASE) = 0;
191 *(volatile int *) (dpram + CPM_USB_DR1_BASE) = 0;
194 ep0->rbase = DPRAM + CPM_USB_RX0_BASE;
195 ep0->tbase = DPRAM + CPM_USB_TX0_BASE;
199 ep0->rbptr = DPRAM + CPM_USB_RX0_BASE;
200 ep0->tbptr = DPRAM + CPM_USB_TX0_BASE;
204 ep1->rbase = DPRAM + CPM_USB_RX1_BASE;
205 ep1->tbase = DPRAM + CPM_USB_TX1_BASE;
209 ep1->rbptr = DPRAM + CPM_USB_RX1_BASE;
210 ep1->tbptr = DPRAM + CPM_USB_TX1_BASE;
214 usbr->usep[0] = 0x0000;
215 usbr->usep[1] = 0x1100;
216 usbr->usep[2] = 0x2200;
217 usbr->usep[3] = 0x3300;
236 /* Wait for the data packet to be transmitted */
237 for (j = 0; j < TOUT_LOOP; j++) {
238 if (tx[1].cbd_sc & (ushort) 0x8000)
244 USB_EXPECT (j < TOUT_LOOP);
246 USB_EXPECT (tx[0].cbd_sc == 0x3800);
247 USB_EXPECT (tx[0].cbd_datlen == 3);
249 USB_EXPECT (tx[1].cbd_sc == 0x3C80);
250 USB_EXPECT (tx[1].cbd_datlen == 3);
252 USB_EXPECT (rx[0].cbd_sc == 0x2C00);
253 USB_EXPECT (rx[0].cbd_datlen == 5);
255 USB_EXPECT (*(volatile int *) (dpram + CPM_USB_DR0_BASE) ==
257 USB_EXPECT (*(volatile char *) (dpram + CPM_USB_DR0_BASE + 4) == 0x42);
265 #endif /* CONFIG_POST & CONFIG_SYS_POST_USB */