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.
41 #if CONFIG_POST & CFG_POST_USB
48 #define PROFF_USB ((uint)0x0000)
50 #define CPM_USB_EP0_BASE 0x0a00
51 #define CPM_USB_EP1_BASE 0x0a20
53 #define CPM_USB_DT0_BASE 0x0a80
54 #define CPM_USB_DT1_BASE 0x0a90
55 #define CPM_USB_DR0_BASE 0x0aa0
56 #define CPM_USB_DR1_BASE 0x0ab0
58 #define CPM_USB_RX0_BASE 0x0b00
59 #define CPM_USB_RX1_BASE 0x0b08
60 #define CPM_USB_TX0_BASE 0x0b20
61 #define CPM_USB_TX1_BASE 0x0b28
63 #define USB_EXPECT(x) if (!(x)) goto Done;
65 typedef struct usb_param {
77 typedef struct usb_param_block {
107 int usb_post_test (int flags)
110 volatile immap_t *im = (immap_t *) CFG_IMMR;
111 volatile cpm8xx_t *cp = &(im->im_cpm);
112 volatile usb_param_t *pram_ptr;
117 volatile usb_t *usbr;
118 volatile usb_param_block_t *ep0;
119 volatile usb_param_block_t *ep1;
122 pram_ptr = (usb_param_t *) & (im->im_cpm.cp_dparam[PROFF_USB]);
123 dpram = (uint) im->im_cpm.cp_dpmem;
125 tx = (cbd_t *) (dpram + CPM_USB_TX0_BASE);
126 rx = (cbd_t *) (dpram + CPM_USB_RX0_BASE);
127 ep0 = (usb_param_block_t *) (dpram + CPM_USB_EP0_BASE);
128 ep1 = (usb_param_block_t *) (dpram + CPM_USB_EP1_BASE);
129 usbr = (usb_t *) & (im->im_cpm.cp_scc[0]);
132 im->im_ioport.iop_padir &= ~(ushort) 0x0200;
133 im->im_ioport.iop_papar |= (ushort) 0x0200;
135 cp->cp_sicr &= ~0x000000FF;
136 cp->cp_sicr |= 0x00000018;
138 cp->cp_brgc4 = 0x00010001;
141 im->im_ioport.iop_padir &= ~(ushort) 0x0002;
142 im->im_ioport.iop_padir &= ~(ushort) 0x0001;
144 im->im_ioport.iop_papar |= (ushort) 0x0002;
145 im->im_ioport.iop_papar |= (ushort) 0x0001;
148 im->im_ioport.iop_pcdir &= ~(ushort) 0x0020;
149 im->im_ioport.iop_pcdir &= ~(ushort) 0x0010;
151 im->im_ioport.iop_pcpar &= ~(ushort) 0x0020;
152 im->im_ioport.iop_pcpar &= ~(ushort) 0x0010;
154 im->im_ioport.iop_pcso |= (ushort) 0x0020;
155 im->im_ioport.iop_pcso |= (ushort) 0x0010;
158 im->im_ioport.iop_pcdir |= (ushort) 0x0200;
159 im->im_ioport.iop_pcdir |= (ushort) 0x0100;
161 im->im_ioport.iop_pcpar |= (ushort) 0x0200;
162 im->im_ioport.iop_pcpar |= (ushort) 0x0100;
165 pram_ptr->frame_n = 0;
168 pram_ptr->ep0ptr = DPRAM + CPM_USB_EP0_BASE;
169 pram_ptr->ep1ptr = DPRAM + CPM_USB_EP1_BASE;
172 tx[0].cbd_sc = 0xB800;
173 tx[0].cbd_datlen = 3;
174 tx[0].cbd_bufaddr = dpram + CPM_USB_DT0_BASE;
176 tx[1].cbd_sc = 0xBC80;
177 tx[1].cbd_datlen = 3;
178 tx[1].cbd_bufaddr = dpram + CPM_USB_DT1_BASE;
180 rx[0].cbd_sc = 0xA000;
181 rx[0].cbd_datlen = 0;
182 rx[0].cbd_bufaddr = dpram + CPM_USB_DR0_BASE;
184 rx[1].cbd_sc = 0xA000;
185 rx[1].cbd_datlen = 0;
186 rx[1].cbd_bufaddr = dpram + CPM_USB_DR1_BASE;
189 *(volatile int *) (dpram + CPM_USB_DT0_BASE) = 0x69856000;
190 *(volatile int *) (dpram + CPM_USB_DT1_BASE) = 0xABCD1234;
192 *(volatile int *) (dpram + CPM_USB_DR0_BASE) = 0;
193 *(volatile int *) (dpram + CPM_USB_DR1_BASE) = 0;
196 ep0->rbase = DPRAM + CPM_USB_RX0_BASE;
197 ep0->tbase = DPRAM + CPM_USB_TX0_BASE;
201 ep0->rbptr = DPRAM + CPM_USB_RX0_BASE;
202 ep0->tbptr = DPRAM + CPM_USB_TX0_BASE;
206 ep1->rbase = DPRAM + CPM_USB_RX1_BASE;
207 ep1->tbase = DPRAM + CPM_USB_TX1_BASE;
211 ep1->rbptr = DPRAM + CPM_USB_RX1_BASE;
212 ep1->tbptr = DPRAM + CPM_USB_TX1_BASE;
216 usbr->usep[0] = 0x0000;
217 usbr->usep[1] = 0x1100;
218 usbr->usep[2] = 0x2200;
219 usbr->usep[3] = 0x3300;
238 /* Wait for the data packet to be transmitted */
239 for (j = 0; j < TOUT_LOOP; j++) {
240 if (tx[1].cbd_sc & (ushort) 0x8000)
246 USB_EXPECT (j < TOUT_LOOP);
248 USB_EXPECT (tx[0].cbd_sc == 0x3800);
249 USB_EXPECT (tx[0].cbd_datlen == 3);
251 USB_EXPECT (tx[1].cbd_sc == 0x3C80);
252 USB_EXPECT (tx[1].cbd_datlen == 3);
254 USB_EXPECT (rx[0].cbd_sc == 0x2C00);
255 USB_EXPECT (rx[0].cbd_datlen == 5);
257 USB_EXPECT (*(volatile int *) (dpram + CPM_USB_DR0_BASE) ==
259 USB_EXPECT (*(volatile char *) (dpram + CPM_USB_DR0_BASE + 4) == 0x42);
267 #endif /* CONFIG_POST & CFG_POST_USB */
269 #endif /* CONFIG_POST */