2 * R8A66597 HCD (Host Controller Driver) for u-boot
4 * Copyright (C) 2008 Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #define R8A66597_DPRINT printf
30 #define R8A66597_DPRINT(...)
33 static const char hcd_name[] = "r8a66597_hcd";
34 static unsigned short clock = CONFIG_R8A66597_XTAL;
35 static unsigned short vif = CONFIG_R8A66597_LDRV;
36 static unsigned short endian = CONFIG_R8A66597_ENDIAN;
37 static struct r8a66597 gr8a66597;
39 static void get_hub_data(struct usb_device *dev, u16 *hub_devnum, u16 *hubport)
46 /* check a device connected to root_hub */
47 if ((dev->parent && dev->parent->devnum == 1) ||
51 for (i = 0; i < USB_MAXCHILDREN; i++) {
52 if (dev->parent->children[i] == dev) {
53 *hub_devnum = (u8)dev->parent->devnum;
59 printf("get_hub_data error.\n");
62 static void set_devadd(struct r8a66597 *r8a66597, u8 r8a66597_address,
63 struct usb_device *dev, int port)
65 u16 val, usbspd, upphub, hubport;
66 unsigned long devadd_reg = get_devadd_addr(r8a66597_address);
68 get_hub_data(dev, &upphub, &hubport);
69 usbspd = r8a66597->speed;
70 val = (upphub << 11) | (hubport << 8) | (usbspd << 6) | (port & 0x0001);
71 r8a66597_write(r8a66597, val, devadd_reg);
74 static int r8a66597_clock_enable(struct r8a66597 *r8a66597)
79 #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
81 r8a66597_write(r8a66597, SCKE, SYSCFG0);
82 tmp = r8a66597_read(r8a66597, SYSCFG0);
84 printf("register access fail.\n");
87 } while ((tmp & SCKE) != SCKE);
88 r8a66597_write(r8a66597, 0x04, 0x02);
91 r8a66597_write(r8a66597, USBE, SYSCFG0);
92 tmp = r8a66597_read(r8a66597, SYSCFG0);
94 printf("register access fail.\n");
97 } while ((tmp & USBE) != USBE);
98 r8a66597_bclr(r8a66597, USBE, SYSCFG0);
99 r8a66597_mdfy(r8a66597, clock, XTAL, SYSCFG0);
102 r8a66597_bset(r8a66597, XCKE, SYSCFG0);
105 tmp = r8a66597_read(r8a66597, SYSCFG0);
107 printf("register access fail.\n");
110 } while ((tmp & SCKE) != SCKE);
111 #endif /* #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) */
116 static void r8a66597_clock_disable(struct r8a66597 *r8a66597)
118 r8a66597_bclr(r8a66597, SCKE, SYSCFG0);
120 #if !defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
121 r8a66597_bclr(r8a66597, PLLC, SYSCFG0);
122 r8a66597_bclr(r8a66597, XCKE, SYSCFG0);
123 r8a66597_bclr(r8a66597, USBE, SYSCFG0);
127 static void r8a66597_enable_port(struct r8a66597 *r8a66597, int port)
131 val = port ? DRPD : DCFM | DRPD;
132 r8a66597_bset(r8a66597, val, get_syscfg_reg(port));
133 r8a66597_bset(r8a66597, HSE, get_syscfg_reg(port));
135 r8a66597_write(r8a66597, BURST | CPU_ADR_RD_WR, get_dmacfg_reg(port));
138 static void r8a66597_disable_port(struct r8a66597 *r8a66597, int port)
142 r8a66597_write(r8a66597, 0, get_intenb_reg(port));
143 r8a66597_write(r8a66597, 0, get_intsts_reg(port));
145 r8a66597_port_power(r8a66597, port, 0);
148 tmp = r8a66597_read(r8a66597, SOFCFG) & EDGESTS;
150 } while (tmp == EDGESTS);
152 val = port ? DRPD : DCFM | DRPD;
153 r8a66597_bclr(r8a66597, val, get_syscfg_reg(port));
154 r8a66597_bclr(r8a66597, HSE, get_syscfg_reg(port));
157 static int enable_controller(struct r8a66597 *r8a66597)
161 ret = r8a66597_clock_enable(r8a66597);
165 r8a66597_bset(r8a66597, vif & LDRV, PINCFG);
166 r8a66597_bset(r8a66597, USBE, SYSCFG0);
168 r8a66597_bset(r8a66597, INTL, SOFCFG);
169 r8a66597_write(r8a66597, 0, INTENB0);
170 r8a66597_write(r8a66597, 0, INTENB1);
171 r8a66597_write(r8a66597, 0, INTENB2);
173 r8a66597_bset(r8a66597, endian & BIGEND, CFIFOSEL);
174 r8a66597_bset(r8a66597, endian & BIGEND, D0FIFOSEL);
175 r8a66597_bset(r8a66597, endian & BIGEND, D1FIFOSEL);
176 r8a66597_bset(r8a66597, TRNENSEL, SOFCFG);
178 for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++)
179 r8a66597_enable_port(r8a66597, port);
184 static void disable_controller(struct r8a66597 *r8a66597)
188 if (!(r8a66597_read(r8a66597, SYSCFG0) & USBE))
191 r8a66597_write(r8a66597, 0, INTENB0);
192 r8a66597_write(r8a66597, 0, INTSTS0);
194 r8a66597_write(r8a66597, 0, D0FIFOSEL);
195 r8a66597_write(r8a66597, 0, D1FIFOSEL);
196 r8a66597_write(r8a66597, 0, DCPCFG);
197 r8a66597_write(r8a66597, 0x40, DCPMAXP);
198 r8a66597_write(r8a66597, 0, DCPCTR);
200 for (i = 0; i <= 10; i++)
201 r8a66597_write(r8a66597, 0, get_devadd_addr(i));
202 for (i = 1; i <= 5; i++) {
203 r8a66597_write(r8a66597, 0, get_pipetre_addr(i));
204 r8a66597_write(r8a66597, 0, get_pipetrn_addr(i));
206 for (i = 1; i < R8A66597_MAX_NUM_PIPE; i++) {
207 r8a66597_write(r8a66597, 0, get_pipectr_addr(i));
208 r8a66597_write(r8a66597, i, PIPESEL);
209 r8a66597_write(r8a66597, 0, PIPECFG);
210 r8a66597_write(r8a66597, 0, PIPEBUF);
211 r8a66597_write(r8a66597, 0, PIPEMAXP);
212 r8a66597_write(r8a66597, 0, PIPEPERI);
215 for (i = 0; i < R8A66597_MAX_ROOT_HUB; i++)
216 r8a66597_disable_port(r8a66597, i);
218 r8a66597_clock_disable(r8a66597);
221 static void r8a66597_reg_wait(struct r8a66597 *r8a66597, unsigned long reg,
228 tmp = r8a66597_read(r8a66597, reg);
230 printf("register%lx, loop %x is timeout\n", reg, loop);
233 } while ((tmp & mask) != loop);
236 static void pipe_buffer_setting(struct r8a66597 *r8a66597,
237 struct usb_device *dev, unsigned long pipe)
240 u16 pipenum, bufnum, maxpacket;
242 if (usb_pipein(pipe)) {
243 pipenum = BULK_IN_PIPENUM;
244 bufnum = BULK_IN_BUFNUM;
245 maxpacket = dev->epmaxpacketin[usb_pipeendpoint(pipe)];
247 pipenum = BULK_OUT_PIPENUM;
248 bufnum = BULK_OUT_BUFNUM;
249 maxpacket = dev->epmaxpacketout[usb_pipeendpoint(pipe)];
252 if (r8a66597->pipe_config & (1 << pipenum))
254 r8a66597->pipe_config |= (1 << pipenum);
256 r8a66597_bset(r8a66597, ACLRM, get_pipectr_addr(pipenum));
257 r8a66597_bclr(r8a66597, ACLRM, get_pipectr_addr(pipenum));
258 r8a66597_write(r8a66597, pipenum, PIPESEL);
260 /* FIXME: This driver support bulk transfer only. */
261 if (!usb_pipein(pipe))
264 val |= R8A66597_SHTNAK;
265 val |= R8A66597_BULK | R8A66597_DBLB | usb_pipeendpoint(pipe);
266 r8a66597_write(r8a66597, val, PIPECFG);
268 r8a66597_write(r8a66597, (8 << 10) | bufnum, PIPEBUF);
269 r8a66597_write(r8a66597, make_devsel(usb_pipedevice(pipe)) |
270 maxpacket, PIPEMAXP);
271 r8a66597_write(r8a66597, 0, PIPEPERI);
272 r8a66597_write(r8a66597, SQCLR, get_pipectr_addr(pipenum));
275 static int send_setup_packet(struct r8a66597 *r8a66597, struct usb_device *dev,
276 struct devrequest *setup)
279 unsigned short *p = (unsigned short *)setup;
280 unsigned long setup_addr = USBREQ;
283 u16 devsel = setup->request == USB_REQ_SET_ADDRESS ? 0 : dev->devnum;
285 r8a66597_write(r8a66597, make_devsel(devsel) |
286 (8 << dev->maxpacketsize), DCPMAXP);
287 r8a66597_write(r8a66597, ~(SIGN | SACK), INTSTS1);
289 for (i = 0; i < 4; i++) {
290 r8a66597_write(r8a66597, le16_to_cpu(p[i]), setup_addr);
293 r8a66597_write(r8a66597, ~0x0001, BRDYSTS);
294 r8a66597_write(r8a66597, SUREQ, DCPCTR);
297 intsts1 = r8a66597_read(r8a66597, INTSTS1);
300 if (intsts1 & SIGN) {
301 printf("setup packet send error\n");
305 printf("setup packet timeout\n");
314 static int send_bulk_packet(struct r8a66597 *r8a66597, struct usb_device *dev,
315 unsigned long pipe, void *buffer, int transfer_len)
321 R8A66597_DPRINT("%s\n", __func__);
323 r8a66597_mdfy(r8a66597, MBW | BULK_OUT_PIPENUM,
324 MBW | CURPIPE, CFIFOSEL);
325 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, BULK_OUT_PIPENUM);
326 tmp = r8a66597_read(r8a66597, CFIFOCTR);
327 if ((tmp & FRDY) == 0) {
328 printf("%s FRDY is not set (%x)\n", __func__, tmp);
332 /* prepare parameters */
333 bufsize = dev->epmaxpacketout[usb_pipeendpoint(pipe)];
334 buf = (u16 *)(buffer + dev->act_len);
335 size = min((int)bufsize, transfer_len - dev->act_len);
338 r8a66597_write(r8a66597, ~(1 << BULK_OUT_PIPENUM), BEMPSTS);
340 r8a66597_write_fifo(r8a66597, CFIFO, buf, size);
341 r8a66597_write(r8a66597, BVAL, CFIFOCTR);
344 /* update parameters */
345 dev->act_len += size;
347 r8a66597_mdfy(r8a66597, PID_BUF, PID,
348 get_pipectr_addr(BULK_OUT_PIPENUM));
350 while (!(r8a66597_read(r8a66597, BEMPSTS) & (1 << BULK_OUT_PIPENUM)))
353 r8a66597_write(r8a66597, ~(1 << BULK_OUT_PIPENUM), BEMPSTS);
355 if (dev->act_len >= transfer_len)
356 r8a66597_mdfy(r8a66597, PID_NAK, PID,
357 get_pipectr_addr(BULK_OUT_PIPENUM));
362 static int receive_bulk_packet(struct r8a66597 *r8a66597,
363 struct usb_device *dev,
365 void *buffer, int transfer_len)
369 const u16 pipenum = BULK_IN_PIPENUM;
371 int maxpacket = dev->epmaxpacketin[usb_pipeendpoint(pipe)];
373 R8A66597_DPRINT("%s\n", __func__);
376 if (dev->act_len == 0) {
377 r8a66597_mdfy(r8a66597, PID_NAK, PID,
378 get_pipectr_addr(pipenum));
379 r8a66597_write(r8a66597, ~(1 << pipenum), BRDYSTS);
381 r8a66597_write(r8a66597, TRCLR, get_pipetre_addr(pipenum));
382 r8a66597_write(r8a66597,
383 (transfer_len + maxpacket - 1) / maxpacket,
384 get_pipetrn_addr(pipenum));
385 r8a66597_bset(r8a66597, TRENB, get_pipetre_addr(pipenum));
387 r8a66597_mdfy(r8a66597, PID_BUF, PID,
388 get_pipectr_addr(pipenum));
391 r8a66597_mdfy(r8a66597, MBW | pipenum, MBW | CURPIPE, CFIFOSEL);
392 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, pipenum);
394 while (!(r8a66597_read(r8a66597, BRDYSTS) & (1 << pipenum)))
397 r8a66597_write(r8a66597, ~(1 << pipenum), BRDYSTS);
399 tmp = r8a66597_read(r8a66597, CFIFOCTR);
400 if ((tmp & FRDY) == 0) {
401 printf("%s FRDY is not set. (%x)\n", __func__, tmp);
405 buf = (u16 *)(buffer + dev->act_len);
406 rcv_len = tmp & DTLN;
407 dev->act_len += rcv_len;
411 r8a66597_write(r8a66597, BCLR, CFIFOCTR);
413 r8a66597_read_fifo(r8a66597, CFIFO, buf, rcv_len);
419 static int receive_control_packet(struct r8a66597 *r8a66597,
420 struct usb_device *dev,
421 void *buffer, int transfer_len)
426 /* FIXME: limit transfer size : 64byte or less */
428 r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG);
429 r8a66597_mdfy(r8a66597, 0, ISEL | CURPIPE, CFIFOSEL);
430 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
431 r8a66597_bset(r8a66597, SQSET, DCPCTR);
432 r8a66597_write(r8a66597, BCLR, CFIFOCTR);
433 r8a66597_mdfy(r8a66597, PID_BUF, PID, DCPCTR);
435 while (!(r8a66597_read(r8a66597, BRDYSTS) & 0x0001))
438 r8a66597_write(r8a66597, ~0x0001, BRDYSTS);
440 r8a66597_mdfy(r8a66597, MBW, MBW | CURPIPE, CFIFOSEL);
441 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
443 tmp = r8a66597_read(r8a66597, CFIFOCTR);
444 if ((tmp & FRDY) == 0) {
445 printf("%s FRDY is not set. (%x)\n", __func__, tmp);
449 rcv_len = tmp & DTLN;
450 dev->act_len += rcv_len;
452 r8a66597_mdfy(r8a66597, PID_NAK, PID, DCPCTR);
456 r8a66597_write(r8a66597, BCLR, DCPCTR);
458 r8a66597_read_fifo(r8a66597, CFIFO, buffer, rcv_len);
464 static int send_status_packet(struct r8a66597 *r8a66597,
467 r8a66597_bset(r8a66597, SQSET, DCPCTR);
468 r8a66597_mdfy(r8a66597, PID_NAK, PID, DCPCTR);
470 if (usb_pipein(pipe)) {
471 r8a66597_bset(r8a66597, R8A66597_DIR, DCPCFG);
472 r8a66597_mdfy(r8a66597, ISEL, ISEL | CURPIPE, CFIFOSEL);
473 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
474 r8a66597_write(r8a66597, ~BEMP0, BEMPSTS);
475 r8a66597_write(r8a66597, BCLR | BVAL, CFIFOCTR);
477 r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG);
478 r8a66597_mdfy(r8a66597, 0, ISEL | CURPIPE, CFIFOSEL);
479 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
480 r8a66597_write(r8a66597, BCLR, CFIFOCTR);
482 r8a66597_mdfy(r8a66597, PID_BUF, PID, DCPCTR);
484 while (!(r8a66597_read(r8a66597, BEMPSTS) & 0x0001))
491 static void r8a66597_check_syssts(struct r8a66597 *r8a66597, int port)
493 int count = R8A66597_MAX_SAMPLING;
494 unsigned short syssts, old_syssts;
496 R8A66597_DPRINT("%s\n", __func__);
498 old_syssts = r8a66597_read(r8a66597, get_syssts_reg(port) & LNST);
500 wait_ms(R8A66597_RH_POLL_TIME);
502 syssts = r8a66597_read(r8a66597, get_syssts_reg(port) & LNST);
503 if (syssts == old_syssts) {
506 count = R8A66597_MAX_SAMPLING;
512 static void r8a66597_bus_reset(struct r8a66597 *r8a66597, int port)
515 r8a66597_mdfy(r8a66597, USBRST, USBRST | UACT, get_dvstctr_reg(port));
517 r8a66597_mdfy(r8a66597, UACT, USBRST | UACT, get_dvstctr_reg(port));
521 static int check_usb_device_connecting(struct r8a66597 *r8a66597)
523 int timeout = 10000; /* 100usec * 10000 = 1sec */
526 for (i = 0; i < 5; i++) {
527 /* check a usb cable connect */
528 while (!(r8a66597_read(r8a66597, INTSTS1) & ATTCH)) {
530 printf("%s timeout.\n", __func__);
536 /* check a data line */
537 r8a66597_check_syssts(r8a66597, 0);
539 r8a66597_bus_reset(r8a66597, 0);
540 r8a66597->speed = get_rh_usb_speed(r8a66597, 0);
542 if (!(r8a66597_read(r8a66597, INTSTS1) & DTCH)) {
543 r8a66597->port_change = USB_PORT_STAT_C_CONNECTION;
544 r8a66597->port_status = USB_PORT_STAT_CONNECTION |
545 USB_PORT_STAT_ENABLE;
546 return 0; /* success */
549 R8A66597_DPRINT("USB device has detached. retry = %d\n", i);
550 r8a66597_write(r8a66597, ~DTCH, INTSTS1);
553 return -1; /* fail */
556 /* based on usb_ohci.c */
557 #define min_t(type, x, y) \
558 ({ type __x = (x); type __y = (y); __x < __y ? __x : __y; })
559 /*-------------------------------------------------------------------------*
561 *-------------------------------------------------------------------------*/
563 /* Device descriptor */
564 static __u8 root_hub_dev_des[] =
566 0x12, /* __u8 bLength; */
567 0x01, /* __u8 bDescriptorType; Device */
568 0x10, /* __u16 bcdUSB; v1.1 */
570 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
571 0x00, /* __u8 bDeviceSubClass; */
572 0x00, /* __u8 bDeviceProtocol; */
573 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
574 0x00, /* __u16 idVendor; */
576 0x00, /* __u16 idProduct; */
578 0x00, /* __u16 bcdDevice; */
580 0x00, /* __u8 iManufacturer; */
581 0x01, /* __u8 iProduct; */
582 0x00, /* __u8 iSerialNumber; */
583 0x01 /* __u8 bNumConfigurations; */
586 /* Configuration descriptor */
587 static __u8 root_hub_config_des[] =
589 0x09, /* __u8 bLength; */
590 0x02, /* __u8 bDescriptorType; Configuration */
591 0x19, /* __u16 wTotalLength; */
593 0x01, /* __u8 bNumInterfaces; */
594 0x01, /* __u8 bConfigurationValue; */
595 0x00, /* __u8 iConfiguration; */
596 0x40, /* __u8 bmAttributes; */
598 0x00, /* __u8 MaxPower; */
601 0x09, /* __u8 if_bLength; */
602 0x04, /* __u8 if_bDescriptorType; Interface */
603 0x00, /* __u8 if_bInterfaceNumber; */
604 0x00, /* __u8 if_bAlternateSetting; */
605 0x01, /* __u8 if_bNumEndpoints; */
606 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
607 0x00, /* __u8 if_bInterfaceSubClass; */
608 0x00, /* __u8 if_bInterfaceProtocol; */
609 0x00, /* __u8 if_iInterface; */
612 0x07, /* __u8 ep_bLength; */
613 0x05, /* __u8 ep_bDescriptorType; Endpoint */
614 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
615 0x03, /* __u8 ep_bmAttributes; Interrupt */
616 0x02, /* __u16 ep_wMaxPacketSize; ((MAX_ROOT_PORTS + 1) / 8 */
618 0xff /* __u8 ep_bInterval; 255 ms */
621 static unsigned char root_hub_str_index0[] =
623 0x04, /* __u8 bLength; */
624 0x03, /* __u8 bDescriptorType; String-descriptor */
625 0x09, /* __u8 lang ID */
626 0x04, /* __u8 lang ID */
629 static unsigned char root_hub_str_index1[] =
631 34, /* __u8 bLength; */
632 0x03, /* __u8 bDescriptorType; String-descriptor */
633 'R', /* __u8 Unicode */
634 0, /* __u8 Unicode */
635 '8', /* __u8 Unicode */
636 0, /* __u8 Unicode */
637 'A', /* __u8 Unicode */
638 0, /* __u8 Unicode */
639 '6', /* __u8 Unicode */
640 0, /* __u8 Unicode */
641 '6', /* __u8 Unicode */
642 0, /* __u8 Unicode */
643 '5', /* __u8 Unicode */
644 0, /* __u8 Unicode */
645 '9', /* __u8 Unicode */
646 0, /* __u8 Unicode */
647 '7', /* __u8 Unicode */
648 0, /* __u8 Unicode */
649 ' ', /* __u8 Unicode */
650 0, /* __u8 Unicode */
651 'R', /* __u8 Unicode */
652 0, /* __u8 Unicode */
653 'o', /* __u8 Unicode */
654 0, /* __u8 Unicode */
655 'o', /* __u8 Unicode */
656 0, /* __u8 Unicode */
657 't', /* __u8 Unicode */
658 0, /* __u8 Unicode */
659 'H', /* __u8 Unicode */
660 0, /* __u8 Unicode */
661 'u', /* __u8 Unicode */
662 0, /* __u8 Unicode */
663 'b', /* __u8 Unicode */
664 0, /* __u8 Unicode */
667 static int r8a66597_submit_rh_msg(struct usb_device *dev, unsigned long pipe,
668 void *buffer, int transfer_len, struct devrequest *cmd)
670 struct r8a66597 *r8a66597 = &gr8a66597;
671 int leni = transfer_len;
678 unsigned char data[32];
680 R8A66597_DPRINT("%s\n", __func__);
682 if (usb_pipeint(pipe)) {
683 printf("Root-Hub submit IRQ: NOT implemented");
687 bmRType_bReq = cmd->requesttype | (cmd->request << 8);
688 wValue = cpu_to_le16 (cmd->value);
689 wIndex = cpu_to_le16 (cmd->index);
690 wLength = cpu_to_le16 (cmd->length);
692 switch (bmRType_bReq) {
694 *(__u16 *)buffer = cpu_to_le16(1);
697 case RH_GET_STATUS | RH_INTERFACE:
698 *(__u16 *)buffer = cpu_to_le16(0);
701 case RH_GET_STATUS | RH_ENDPOINT:
702 *(__u16 *)buffer = cpu_to_le16(0);
705 case RH_GET_STATUS | RH_CLASS:
706 *(__u32 *)buffer = cpu_to_le32(0);
709 case RH_GET_STATUS | RH_OTHER | RH_CLASS:
710 *(__u32 *)buffer = cpu_to_le32(r8a66597->port_status |
711 (r8a66597->port_change << 16));
714 case RH_CLEAR_FEATURE | RH_ENDPOINT:
715 case RH_CLEAR_FEATURE | RH_CLASS:
718 case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
720 case RH_C_PORT_CONNECTION:
721 r8a66597->port_change &= ~USB_PORT_STAT_C_CONNECTION;
726 case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
728 case (RH_PORT_SUSPEND):
730 case (RH_PORT_RESET):
731 r8a66597_bus_reset(r8a66597, 0);
733 case (RH_PORT_POWER):
735 case (RH_PORT_ENABLE):
740 gr8a66597.rh_devnum = wValue;
742 case RH_GET_DESCRIPTOR:
743 switch ((wValue & 0xff00) >> 8) {
744 case (0x01): /* device descriptor */
745 len = min_t(unsigned int,
748 sizeof(root_hub_dev_des),
750 memcpy(buffer, root_hub_dev_des, len);
752 case (0x02): /* configuration descriptor */
753 len = min_t(unsigned int,
756 sizeof(root_hub_config_des),
758 memcpy(buffer, root_hub_config_des, len);
760 case (0x03): /* string descriptors */
761 if (wValue == 0x0300) {
762 len = min_t(unsigned int,
765 sizeof(root_hub_str_index0),
767 memcpy(buffer, root_hub_str_index0, len);
769 if (wValue == 0x0301) {
770 len = min_t(unsigned int,
773 sizeof(root_hub_str_index1),
775 memcpy(buffer, root_hub_str_index1, len);
779 stat = USB_ST_STALLED;
783 case RH_GET_DESCRIPTOR | RH_CLASS:
785 __u32 temp = 0x00000001;
787 data[0] = 9; /* min length; */
789 data[2] = temp & RH_A_NDP;
793 if (temp & RH_A_NOCP)
795 else if (temp & RH_A_OCPM)
798 /* corresponds to data[4-7] */
799 data[5] = (temp & RH_A_POTPGT) >> 24;
800 data[7] = temp & RH_B_DR;
805 data[8] = (temp & RH_B_DR) >> 8;
806 data[10] = data[9] = 0xff;
809 len = min_t(unsigned int, leni,
810 min_t(unsigned int, data[0], wLength));
811 memcpy(buffer, data, len);
815 case RH_GET_CONFIGURATION:
816 *(__u8 *) buffer = 0x01;
819 case RH_SET_CONFIGURATION:
822 R8A66597_DPRINT("unsupported root hub command");
823 stat = USB_ST_STALLED;
828 len = min_t(int, len, leni);
836 int submit_bulk_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
839 struct r8a66597 *r8a66597 = &gr8a66597;
842 R8A66597_DPRINT("%s\n", __func__);
843 R8A66597_DPRINT("pipe = %08x, buffer = %p, len = %d, devnum = %d\n",
844 pipe, buffer, transfer_len, dev->devnum);
846 set_devadd(r8a66597, dev->devnum, dev, 0);
848 pipe_buffer_setting(r8a66597, dev, pipe);
851 while (dev->act_len < transfer_len && ret == 0) {
855 if (usb_pipein(pipe))
856 ret = receive_bulk_packet(r8a66597, dev, pipe, buffer,
859 ret = send_bulk_packet(r8a66597, dev, pipe, buffer,
869 int submit_control_msg(struct usb_device *dev, unsigned long pipe,
870 void *buffer, int transfer_len, struct devrequest *setup)
872 struct r8a66597 *r8a66597 = &gr8a66597;
873 u16 r8a66597_address = setup->request == USB_REQ_SET_ADDRESS ?
876 R8A66597_DPRINT("%s\n", __func__);
877 if (usb_pipedevice(pipe) == r8a66597->rh_devnum)
878 return r8a66597_submit_rh_msg(dev, pipe, buffer, transfer_len,
881 R8A66597_DPRINT("%s: setup\n", __func__);
882 set_devadd(r8a66597, r8a66597_address, dev, 0);
884 if (send_setup_packet(r8a66597, dev, setup) < 0) {
885 printf("setup packet send error\n");
890 if (usb_pipein(pipe))
891 if (receive_control_packet(r8a66597, dev, buffer,
895 if (send_status_packet(r8a66597, pipe) < 0)
903 int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
904 int transfer_len, int interval)
907 R8A66597_DPRINT("%s\n", __func__);
911 void usb_event_poll(void)
914 R8A66597_DPRINT("%s\n", __func__);
917 int usb_lowlevel_init(void)
919 struct r8a66597 *r8a66597 = &gr8a66597;
921 R8A66597_DPRINT("%s\n", __func__);
923 memset(r8a66597, 0, sizeof(r8a66597));
924 r8a66597->reg = CONFIG_R8A66597_BASE_ADDR;
926 disable_controller(r8a66597);
929 enable_controller(r8a66597);
930 r8a66597_port_power(r8a66597, 0 , 1);
932 /* check usb device */
933 check_usb_device_connecting(r8a66597);
940 int usb_lowlevel_stop(void)
942 disable_controller(&gr8a66597);