2 * R8A66597 HCD (Host Controller Driver)
4 * Copyright (C) 2006-2007 Renesas Solutions Corp.
5 * Portions Copyright (C) 2004 Psion Teklogix (for NetBook PRO)
6 * Portions Copyright (C) 2004-2005 David Brownell
7 * Portions Copyright (C) 1999 Roman Weissgaerber
9 * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/sched.h>
29 #include <linux/smp_lock.h>
30 #include <linux/errno.h>
31 #include <linux/init.h>
32 #include <linux/timer.h>
33 #include <linux/delay.h>
34 #include <linux/list.h>
35 #include <linux/interrupt.h>
36 #include <linux/usb.h>
37 #include <linux/platform_device.h>
39 #include <linux/irq.h>
41 #include "../core/hcd.h"
44 MODULE_DESCRIPTION("R8A66597 USB Host Controller Driver");
45 MODULE_LICENSE("GPL");
46 MODULE_AUTHOR("Yoshihiro Shimoda");
47 MODULE_ALIAS("platform:r8a66597_hcd");
49 #define DRIVER_VERSION "10 Apr 2008"
51 static const char hcd_name[] = "r8a66597_hcd";
53 /* module parameters */
54 #if !defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
55 static unsigned short clock = XTAL12;
56 module_param(clock, ushort, 0644);
57 MODULE_PARM_DESC(clock, "input clock: 48MHz=32768, 24MHz=16384, 12MHz=0 "
61 static unsigned short vif = LDRV;
62 module_param(vif, ushort, 0644);
63 MODULE_PARM_DESC(vif, "input VIF: 3.3V=32768, 1.5V=0(default=32768)");
65 static unsigned short endian;
66 module_param(endian, ushort, 0644);
67 MODULE_PARM_DESC(endian, "data endian: big=256, little=0 (default=0)");
69 static unsigned short irq_sense = 0xff;
70 module_param(irq_sense, ushort, 0644);
71 MODULE_PARM_DESC(irq_sense, "IRQ sense: low level=32, falling edge=0 "
74 static void packet_write(struct r8a66597 *r8a66597, u16 pipenum);
75 static int r8a66597_get_frame(struct usb_hcd *hcd);
77 /* this function must be called with interrupt disabled */
78 static void enable_pipe_irq(struct r8a66597 *r8a66597, u16 pipenum,
83 tmp = r8a66597_read(r8a66597, INTENB0);
84 r8a66597_bclr(r8a66597, BEMPE | NRDYE | BRDYE, INTENB0);
85 r8a66597_bset(r8a66597, 1 << pipenum, reg);
86 r8a66597_write(r8a66597, tmp, INTENB0);
89 /* this function must be called with interrupt disabled */
90 static void disable_pipe_irq(struct r8a66597 *r8a66597, u16 pipenum,
95 tmp = r8a66597_read(r8a66597, INTENB0);
96 r8a66597_bclr(r8a66597, BEMPE | NRDYE | BRDYE, INTENB0);
97 r8a66597_bclr(r8a66597, 1 << pipenum, reg);
98 r8a66597_write(r8a66597, tmp, INTENB0);
101 static void set_devadd_reg(struct r8a66597 *r8a66597, u8 r8a66597_address,
102 u16 usbspd, u8 upphub, u8 hubport, int port)
105 unsigned long devadd_reg = get_devadd_addr(r8a66597_address);
107 val = (upphub << 11) | (hubport << 8) | (usbspd << 6) | (port & 0x0001);
108 r8a66597_write(r8a66597, val, devadd_reg);
111 static int r8a66597_clock_enable(struct r8a66597 *r8a66597)
116 #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
117 #if defined(CONFIG_HAVE_CLK)
118 clk_enable(r8a66597->clk);
121 r8a66597_write(r8a66597, SCKE, SYSCFG0);
122 tmp = r8a66597_read(r8a66597, SYSCFG0);
124 printk(KERN_ERR "r8a66597: register access fail.\n");
127 } while ((tmp & SCKE) != SCKE);
128 r8a66597_write(r8a66597, 0x04, 0x02);
131 r8a66597_write(r8a66597, USBE, SYSCFG0);
132 tmp = r8a66597_read(r8a66597, SYSCFG0);
134 printk(KERN_ERR "r8a66597: register access fail.\n");
137 } while ((tmp & USBE) != USBE);
138 r8a66597_bclr(r8a66597, USBE, SYSCFG0);
139 r8a66597_mdfy(r8a66597, clock, XTAL, SYSCFG0);
142 r8a66597_bset(r8a66597, XCKE, SYSCFG0);
145 tmp = r8a66597_read(r8a66597, SYSCFG0);
147 printk(KERN_ERR "r8a66597: register access fail.\n");
150 } while ((tmp & SCKE) != SCKE);
151 #endif /* #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) */
156 static void r8a66597_clock_disable(struct r8a66597 *r8a66597)
158 r8a66597_bclr(r8a66597, SCKE, SYSCFG0);
160 #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
161 #if defined(CONFIG_HAVE_CLK)
162 clk_disable(r8a66597->clk);
165 r8a66597_bclr(r8a66597, PLLC, SYSCFG0);
166 r8a66597_bclr(r8a66597, XCKE, SYSCFG0);
167 r8a66597_bclr(r8a66597, USBE, SYSCFG0);
171 static void r8a66597_enable_port(struct r8a66597 *r8a66597, int port)
175 val = port ? DRPD : DCFM | DRPD;
176 r8a66597_bset(r8a66597, val, get_syscfg_reg(port));
177 r8a66597_bset(r8a66597, HSE, get_syscfg_reg(port));
179 r8a66597_write(r8a66597, BURST | CPU_ADR_RD_WR, get_dmacfg_reg(port));
180 r8a66597_bclr(r8a66597, DTCHE, get_intenb_reg(port));
181 r8a66597_bset(r8a66597, ATTCHE, get_intenb_reg(port));
184 static void r8a66597_disable_port(struct r8a66597 *r8a66597, int port)
188 r8a66597_write(r8a66597, 0, get_intenb_reg(port));
189 r8a66597_write(r8a66597, 0, get_intsts_reg(port));
191 r8a66597_port_power(r8a66597, port, 0);
194 tmp = r8a66597_read(r8a66597, SOFCFG) & EDGESTS;
196 } while (tmp == EDGESTS);
198 val = port ? DRPD : DCFM | DRPD;
199 r8a66597_bclr(r8a66597, val, get_syscfg_reg(port));
200 r8a66597_bclr(r8a66597, HSE, get_syscfg_reg(port));
203 static int enable_controller(struct r8a66597 *r8a66597)
207 ret = r8a66597_clock_enable(r8a66597);
211 r8a66597_bset(r8a66597, vif & LDRV, PINCFG);
212 r8a66597_bset(r8a66597, USBE, SYSCFG0);
214 r8a66597_bset(r8a66597, BEMPE | NRDYE | BRDYE, INTENB0);
215 r8a66597_bset(r8a66597, irq_sense & INTL, SOFCFG);
216 r8a66597_bset(r8a66597, BRDY0, BRDYENB);
217 r8a66597_bset(r8a66597, BEMP0, BEMPENB);
219 r8a66597_bset(r8a66597, endian & BIGEND, CFIFOSEL);
220 r8a66597_bset(r8a66597, endian & BIGEND, D0FIFOSEL);
221 r8a66597_bset(r8a66597, endian & BIGEND, D1FIFOSEL);
222 r8a66597_bset(r8a66597, TRNENSEL, SOFCFG);
224 r8a66597_bset(r8a66597, SIGNE | SACKE, INTENB1);
226 for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++)
227 r8a66597_enable_port(r8a66597, port);
232 static void disable_controller(struct r8a66597 *r8a66597)
236 r8a66597_write(r8a66597, 0, INTENB0);
237 r8a66597_write(r8a66597, 0, INTSTS0);
239 for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++)
240 r8a66597_disable_port(r8a66597, port);
242 r8a66597_clock_disable(r8a66597);
245 static int get_parent_r8a66597_address(struct r8a66597 *r8a66597,
246 struct usb_device *udev)
248 struct r8a66597_device *dev;
250 if (udev->parent && udev->parent->devnum != 1)
253 dev = dev_get_drvdata(&udev->dev);
260 static int is_child_device(char *devpath)
262 return (devpath[2] ? 1 : 0);
265 static int is_hub_limit(char *devpath)
267 return ((strlen(devpath) >= 4) ? 1 : 0);
270 static void get_port_number(char *devpath, u16 *root_port, u16 *hub_port)
273 *root_port = (devpath[0] & 0x0F) - 1;
274 if (*root_port >= R8A66597_MAX_ROOT_HUB)
275 printk(KERN_ERR "r8a66597: Illegal root port number.\n");
278 *hub_port = devpath[2] & 0x0F;
281 static u16 get_r8a66597_usb_speed(enum usb_device_speed speed)
296 printk(KERN_ERR "r8a66597: unknown speed\n");
303 static void set_child_connect_map(struct r8a66597 *r8a66597, int address)
308 r8a66597->child_connect_map[idx] |= 1 << (address % 32);
311 static void put_child_connect_map(struct r8a66597 *r8a66597, int address)
316 r8a66597->child_connect_map[idx] &= ~(1 << (address % 32));
319 static void set_pipe_reg_addr(struct r8a66597_pipe *pipe, u8 dma_ch)
321 u16 pipenum = pipe->info.pipenum;
322 const unsigned long fifoaddr[] = {D0FIFO, D1FIFO, CFIFO};
323 const unsigned long fifosel[] = {D0FIFOSEL, D1FIFOSEL, CFIFOSEL};
324 const unsigned long fifoctr[] = {D0FIFOCTR, D1FIFOCTR, CFIFOCTR};
326 if (dma_ch > R8A66597_PIPE_NO_DMA) /* dma fifo not use? */
327 dma_ch = R8A66597_PIPE_NO_DMA;
329 pipe->fifoaddr = fifoaddr[dma_ch];
330 pipe->fifosel = fifosel[dma_ch];
331 pipe->fifoctr = fifoctr[dma_ch];
334 pipe->pipectr = DCPCTR;
336 pipe->pipectr = get_pipectr_addr(pipenum);
338 if (check_bulk_or_isoc(pipenum)) {
339 pipe->pipetre = get_pipetre_addr(pipenum);
340 pipe->pipetrn = get_pipetrn_addr(pipenum);
347 static struct r8a66597_device *
348 get_urb_to_r8a66597_dev(struct r8a66597 *r8a66597, struct urb *urb)
350 if (usb_pipedevice(urb->pipe) == 0)
351 return &r8a66597->device0;
353 return dev_get_drvdata(&urb->dev->dev);
356 static int make_r8a66597_device(struct r8a66597 *r8a66597,
357 struct urb *urb, u8 addr)
359 struct r8a66597_device *dev;
360 int usb_address = urb->setup_packet[2]; /* urb->pipe is address 0 */
362 dev = kzalloc(sizeof(struct r8a66597_device), GFP_ATOMIC);
366 dev_set_drvdata(&urb->dev->dev, dev);
367 dev->udev = urb->dev;
369 dev->usb_address = usb_address;
370 dev->state = USB_STATE_ADDRESS;
371 dev->ep_in_toggle = 0;
372 dev->ep_out_toggle = 0;
373 INIT_LIST_HEAD(&dev->device_list);
374 list_add_tail(&dev->device_list, &r8a66597->child_device);
376 get_port_number(urb->dev->devpath, &dev->root_port, &dev->hub_port);
377 if (!is_child_device(urb->dev->devpath))
378 r8a66597->root_hub[dev->root_port].dev = dev;
380 set_devadd_reg(r8a66597, dev->address,
381 get_r8a66597_usb_speed(urb->dev->speed),
382 get_parent_r8a66597_address(r8a66597, urb->dev),
383 dev->hub_port, dev->root_port);
388 /* this function must be called with interrupt disabled */
389 static u8 alloc_usb_address(struct r8a66597 *r8a66597, struct urb *urb)
391 u8 addr; /* R8A66597's address */
392 struct r8a66597_device *dev;
394 if (is_hub_limit(urb->dev->devpath)) {
395 dev_err(&urb->dev->dev, "External hub limit reached.\n");
399 dev = get_urb_to_r8a66597_dev(r8a66597, urb);
400 if (dev && dev->state >= USB_STATE_ADDRESS)
403 for (addr = 1; addr <= R8A66597_MAX_DEVICE; addr++) {
404 if (r8a66597->address_map & (1 << addr))
407 dbg("alloc_address: r8a66597_addr=%d", addr);
408 r8a66597->address_map |= 1 << addr;
410 if (make_r8a66597_device(r8a66597, urb, addr) < 0)
416 dev_err(&urb->dev->dev,
417 "cannot communicate with a USB device more than 10.(%x)\n",
418 r8a66597->address_map);
423 /* this function must be called with interrupt disabled */
424 static void free_usb_address(struct r8a66597 *r8a66597,
425 struct r8a66597_device *dev)
432 dbg("free_addr: addr=%d", dev->address);
434 dev->state = USB_STATE_DEFAULT;
435 r8a66597->address_map &= ~(1 << dev->address);
437 dev_set_drvdata(&dev->udev->dev, NULL);
438 list_del(&dev->device_list);
441 for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++) {
442 if (r8a66597->root_hub[port].dev == dev) {
443 r8a66597->root_hub[port].dev = NULL;
449 static void r8a66597_reg_wait(struct r8a66597 *r8a66597, unsigned long reg,
456 tmp = r8a66597_read(r8a66597, reg);
458 printk(KERN_ERR "r8a66597: register%lx, loop %x "
459 "is timeout\n", reg, loop);
463 } while ((tmp & mask) != loop);
466 /* this function must be called with interrupt disabled */
467 static void pipe_start(struct r8a66597 *r8a66597, struct r8a66597_pipe *pipe)
471 tmp = r8a66597_read(r8a66597, pipe->pipectr) & PID;
472 if ((pipe->info.pipenum != 0) & ((tmp & PID_STALL) != 0)) /* stall? */
473 r8a66597_mdfy(r8a66597, PID_NAK, PID, pipe->pipectr);
474 r8a66597_mdfy(r8a66597, PID_BUF, PID, pipe->pipectr);
477 /* this function must be called with interrupt disabled */
478 static void pipe_stop(struct r8a66597 *r8a66597, struct r8a66597_pipe *pipe)
482 tmp = r8a66597_read(r8a66597, pipe->pipectr) & PID;
483 if ((tmp & PID_STALL11) != PID_STALL11) /* force stall? */
484 r8a66597_mdfy(r8a66597, PID_STALL, PID, pipe->pipectr);
485 r8a66597_mdfy(r8a66597, PID_NAK, PID, pipe->pipectr);
486 r8a66597_reg_wait(r8a66597, pipe->pipectr, PBUSY, 0);
489 /* this function must be called with interrupt disabled */
490 static void clear_all_buffer(struct r8a66597 *r8a66597,
491 struct r8a66597_pipe *pipe)
495 if (!pipe || pipe->info.pipenum == 0)
498 pipe_stop(r8a66597, pipe);
499 r8a66597_bset(r8a66597, ACLRM, pipe->pipectr);
500 tmp = r8a66597_read(r8a66597, pipe->pipectr);
501 tmp = r8a66597_read(r8a66597, pipe->pipectr);
502 tmp = r8a66597_read(r8a66597, pipe->pipectr);
503 r8a66597_bclr(r8a66597, ACLRM, pipe->pipectr);
506 /* this function must be called with interrupt disabled */
507 static void r8a66597_pipe_toggle(struct r8a66597 *r8a66597,
508 struct r8a66597_pipe *pipe, int toggle)
511 r8a66597_bset(r8a66597, SQSET, pipe->pipectr);
513 r8a66597_bset(r8a66597, SQCLR, pipe->pipectr);
516 /* this function must be called with interrupt disabled */
517 static inline void cfifo_change(struct r8a66597 *r8a66597, u16 pipenum)
519 r8a66597_mdfy(r8a66597, MBW | pipenum, MBW | CURPIPE, CFIFOSEL);
520 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, pipenum);
523 /* this function must be called with interrupt disabled */
524 static inline void fifo_change_from_pipe(struct r8a66597 *r8a66597,
525 struct r8a66597_pipe *pipe)
527 cfifo_change(r8a66597, 0);
528 r8a66597_mdfy(r8a66597, MBW | 0, MBW | CURPIPE, D0FIFOSEL);
529 r8a66597_mdfy(r8a66597, MBW | 0, MBW | CURPIPE, D1FIFOSEL);
531 r8a66597_mdfy(r8a66597, MBW | pipe->info.pipenum, MBW | CURPIPE,
533 r8a66597_reg_wait(r8a66597, pipe->fifosel, CURPIPE, pipe->info.pipenum);
536 static u16 r8a66597_get_pipenum(struct urb *urb, struct usb_host_endpoint *hep)
538 struct r8a66597_pipe *pipe = hep->hcpriv;
540 if (usb_pipeendpoint(urb->pipe) == 0)
543 return pipe->info.pipenum;
546 static u16 get_urb_to_r8a66597_addr(struct r8a66597 *r8a66597, struct urb *urb)
548 struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb);
550 return (usb_pipedevice(urb->pipe) == 0) ? 0 : dev->address;
553 static unsigned short *get_toggle_pointer(struct r8a66597_device *dev,
559 return usb_pipein(urb_pipe) ? &dev->ep_in_toggle : &dev->ep_out_toggle;
562 /* this function must be called with interrupt disabled */
563 static void pipe_toggle_set(struct r8a66597 *r8a66597,
564 struct r8a66597_pipe *pipe,
565 struct urb *urb, int set)
567 struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb);
568 unsigned char endpoint = usb_pipeendpoint(urb->pipe);
569 unsigned short *toggle = get_toggle_pointer(dev, urb->pipe);
575 *toggle |= 1 << endpoint;
577 *toggle &= ~(1 << endpoint);
580 /* this function must be called with interrupt disabled */
581 static void pipe_toggle_save(struct r8a66597 *r8a66597,
582 struct r8a66597_pipe *pipe,
585 if (r8a66597_read(r8a66597, pipe->pipectr) & SQMON)
586 pipe_toggle_set(r8a66597, pipe, urb, 1);
588 pipe_toggle_set(r8a66597, pipe, urb, 0);
591 /* this function must be called with interrupt disabled */
592 static void pipe_toggle_restore(struct r8a66597 *r8a66597,
593 struct r8a66597_pipe *pipe,
596 struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb);
597 unsigned char endpoint = usb_pipeendpoint(urb->pipe);
598 unsigned short *toggle = get_toggle_pointer(dev, urb->pipe);
603 r8a66597_pipe_toggle(r8a66597, pipe, *toggle & (1 << endpoint));
606 /* this function must be called with interrupt disabled */
607 static void pipe_buffer_setting(struct r8a66597 *r8a66597,
608 struct r8a66597_pipe_info *info)
612 if (info->pipenum == 0)
615 r8a66597_bset(r8a66597, ACLRM, get_pipectr_addr(info->pipenum));
616 r8a66597_bclr(r8a66597, ACLRM, get_pipectr_addr(info->pipenum));
617 r8a66597_write(r8a66597, info->pipenum, PIPESEL);
620 if (info->type == R8A66597_BULK && info->dir_in)
621 val |= R8A66597_DBLB | R8A66597_SHTNAK;
622 val |= info->type | info->epnum;
623 r8a66597_write(r8a66597, val, PIPECFG);
625 r8a66597_write(r8a66597, (info->buf_bsize << 10) | (info->bufnum),
627 r8a66597_write(r8a66597, make_devsel(info->address) | info->maxpacket,
629 r8a66597_write(r8a66597, info->interval, PIPEPERI);
632 /* this function must be called with interrupt disabled */
633 static void pipe_setting(struct r8a66597 *r8a66597, struct r8a66597_td *td)
635 struct r8a66597_pipe_info *info;
636 struct urb *urb = td->urb;
638 if (td->pipenum > 0) {
639 info = &td->pipe->info;
640 cfifo_change(r8a66597, 0);
641 pipe_buffer_setting(r8a66597, info);
643 if (!usb_gettoggle(urb->dev, usb_pipeendpoint(urb->pipe),
644 usb_pipeout(urb->pipe)) &&
645 !usb_pipecontrol(urb->pipe)) {
646 r8a66597_pipe_toggle(r8a66597, td->pipe, 0);
647 pipe_toggle_set(r8a66597, td->pipe, urb, 0);
648 clear_all_buffer(r8a66597, td->pipe);
649 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
650 usb_pipeout(urb->pipe), 1);
652 pipe_toggle_restore(r8a66597, td->pipe, urb);
656 /* this function must be called with interrupt disabled */
657 static u16 get_empty_pipenum(struct r8a66597 *r8a66597,
658 struct usb_endpoint_descriptor *ep)
660 u16 array[R8A66597_MAX_NUM_PIPE], i = 0, min;
662 memset(array, 0, sizeof(array));
663 switch (usb_endpoint_type(ep)) {
664 case USB_ENDPOINT_XFER_BULK:
665 if (usb_endpoint_dir_in(ep))
672 case USB_ENDPOINT_XFER_INT:
673 if (usb_endpoint_dir_in(ep)) {
680 case USB_ENDPOINT_XFER_ISOC:
681 if (usb_endpoint_dir_in(ep))
687 printk(KERN_ERR "r8a66597: Illegal type\n");
693 while (array[i] != 0) {
694 if (r8a66597->pipe_cnt[min] > r8a66597->pipe_cnt[array[i]])
702 static u16 get_r8a66597_type(__u8 type)
707 case USB_ENDPOINT_XFER_BULK:
708 r8a66597_type = R8A66597_BULK;
710 case USB_ENDPOINT_XFER_INT:
711 r8a66597_type = R8A66597_INT;
713 case USB_ENDPOINT_XFER_ISOC:
714 r8a66597_type = R8A66597_ISO;
717 printk(KERN_ERR "r8a66597: Illegal type\n");
718 r8a66597_type = 0x0000;
722 return r8a66597_type;
725 static u16 get_bufnum(u16 pipenum)
731 else if (check_bulk_or_isoc(pipenum))
732 bufnum = 8 + (pipenum - 1) * R8A66597_BUF_BSIZE*2;
733 else if (check_interrupt(pipenum))
734 bufnum = 4 + (pipenum - 6);
736 printk(KERN_ERR "r8a66597: Illegal pipenum (%d)\n", pipenum);
741 static u16 get_buf_bsize(u16 pipenum)
747 else if (check_bulk_or_isoc(pipenum))
748 buf_bsize = R8A66597_BUF_BSIZE - 1;
749 else if (check_interrupt(pipenum))
752 printk(KERN_ERR "r8a66597: Illegal pipenum (%d)\n", pipenum);
757 /* this function must be called with interrupt disabled */
758 static void enable_r8a66597_pipe_dma(struct r8a66597 *r8a66597,
759 struct r8a66597_device *dev,
760 struct r8a66597_pipe *pipe,
763 #if !defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
765 struct r8a66597_pipe_info *info = &pipe->info;
767 if ((pipe->info.pipenum != 0) && (info->type != R8A66597_INT)) {
768 for (i = 0; i < R8A66597_MAX_DMA_CHANNEL; i++) {
769 if ((r8a66597->dma_map & (1 << i)) != 0)
772 dev_info(&dev->udev->dev,
773 "address %d, EndpointAddress 0x%02x use "
774 "DMA FIFO\n", usb_pipedevice(urb->pipe),
776 USB_ENDPOINT_DIR_MASK + info->epnum
779 r8a66597->dma_map |= 1 << i;
780 dev->dma_map |= 1 << i;
781 set_pipe_reg_addr(pipe, i);
783 cfifo_change(r8a66597, 0);
784 r8a66597_mdfy(r8a66597, MBW | pipe->info.pipenum,
785 MBW | CURPIPE, pipe->fifosel);
787 r8a66597_reg_wait(r8a66597, pipe->fifosel, CURPIPE,
789 r8a66597_bset(r8a66597, BCLR, pipe->fifoctr);
793 #endif /* #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) */
796 /* this function must be called with interrupt disabled */
797 static void enable_r8a66597_pipe(struct r8a66597 *r8a66597, struct urb *urb,
798 struct usb_host_endpoint *hep,
799 struct r8a66597_pipe_info *info)
801 struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb);
802 struct r8a66597_pipe *pipe = hep->hcpriv;
807 set_pipe_reg_addr(pipe, R8A66597_PIPE_NO_DMA);
808 r8a66597->pipe_cnt[pipe->info.pipenum]++;
809 dev->pipe_cnt[pipe->info.pipenum]++;
811 enable_r8a66597_pipe_dma(r8a66597, dev, pipe, urb);
814 /* this function must be called with interrupt disabled */
815 static void force_dequeue(struct r8a66597 *r8a66597, u16 pipenum, u16 address)
817 struct r8a66597_td *td, *next;
819 struct list_head *list = &r8a66597->pipe_queue[pipenum];
821 if (list_empty(list))
824 list_for_each_entry_safe(td, next, list, queue) {
827 if (td->address != address)
831 list_del(&td->queue);
835 usb_hcd_unlink_urb_from_ep(r8a66597_to_hcd(r8a66597),
838 spin_unlock(&r8a66597->lock);
839 usb_hcd_giveback_urb(r8a66597_to_hcd(r8a66597), urb,
841 spin_lock(&r8a66597->lock);
847 /* this function must be called with interrupt disabled */
848 static void disable_r8a66597_pipe_all(struct r8a66597 *r8a66597,
849 struct r8a66597_device *dev)
857 for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
858 if (!dev->pipe_cnt[pipenum])
863 force_dequeue(r8a66597, 0, dev->address);
866 r8a66597->pipe_cnt[pipenum] -= dev->pipe_cnt[pipenum];
867 dev->pipe_cnt[pipenum] = 0;
868 force_dequeue(r8a66597, pipenum, dev->address);
873 r8a66597->dma_map &= ~(dev->dma_map);
877 static u16 get_interval(struct urb *urb, __u8 interval)
882 if (urb->dev->speed == USB_SPEED_HIGH) {
886 time = interval ? interval - 1 : 0;
888 if (interval > 128) {
891 /* calculate the nearest value for PIPEPERI */
892 for (i = 0; i < 7; i++) {
893 if ((1 << i) < interval &&
894 (1 << (i + 1) > interval))
903 static unsigned long get_timer_interval(struct urb *urb, __u8 interval)
906 unsigned long time = 1;
908 if (usb_pipeisoc(urb->pipe))
911 if (get_r8a66597_usb_speed(urb->dev->speed) == HSMODE) {
912 for (i = 0; i < (interval - 1); i++)
914 time = time * 125 / 1000; /* uSOF -> msec */
922 /* this function must be called with interrupt disabled */
923 static void init_pipe_info(struct r8a66597 *r8a66597, struct urb *urb,
924 struct usb_host_endpoint *hep,
925 struct usb_endpoint_descriptor *ep)
927 struct r8a66597_pipe_info info;
929 info.pipenum = get_empty_pipenum(r8a66597, ep);
930 info.address = get_urb_to_r8a66597_addr(r8a66597, urb);
931 info.epnum = usb_endpoint_num(ep);
932 info.maxpacket = le16_to_cpu(ep->wMaxPacketSize);
933 info.type = get_r8a66597_type(usb_endpoint_type(ep));
934 info.bufnum = get_bufnum(info.pipenum);
935 info.buf_bsize = get_buf_bsize(info.pipenum);
936 if (info.type == R8A66597_BULK) {
938 info.timer_interval = 0;
940 info.interval = get_interval(urb, ep->bInterval);
941 info.timer_interval = get_timer_interval(urb, ep->bInterval);
943 if (usb_endpoint_dir_in(ep))
948 enable_r8a66597_pipe(r8a66597, urb, hep, &info);
951 static void init_pipe_config(struct r8a66597 *r8a66597, struct urb *urb)
953 struct r8a66597_device *dev;
955 dev = get_urb_to_r8a66597_dev(r8a66597, urb);
956 dev->state = USB_STATE_CONFIGURED;
959 static void pipe_irq_enable(struct r8a66597 *r8a66597, struct urb *urb,
962 if (pipenum == 0 && usb_pipeout(urb->pipe))
963 enable_irq_empty(r8a66597, pipenum);
965 enable_irq_ready(r8a66597, pipenum);
967 if (!usb_pipeisoc(urb->pipe))
968 enable_irq_nrdy(r8a66597, pipenum);
971 static void pipe_irq_disable(struct r8a66597 *r8a66597, u16 pipenum)
973 disable_irq_ready(r8a66597, pipenum);
974 disable_irq_nrdy(r8a66597, pipenum);
977 static void r8a66597_root_hub_start_polling(struct r8a66597 *r8a66597)
979 mod_timer(&r8a66597->rh_timer,
980 jiffies + msecs_to_jiffies(R8A66597_RH_POLL_TIME));
983 static void start_root_hub_sampling(struct r8a66597 *r8a66597, int port,
986 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
988 rh->old_syssts = r8a66597_read(r8a66597, get_syssts_reg(port)) & LNST;
989 rh->scount = R8A66597_MAX_SAMPLING;
991 rh->port |= 1 << USB_PORT_FEAT_CONNECTION;
993 rh->port &= ~(1 << USB_PORT_FEAT_CONNECTION);
994 rh->port |= 1 << USB_PORT_FEAT_C_CONNECTION;
996 r8a66597_root_hub_start_polling(r8a66597);
999 /* this function must be called with interrupt disabled */
1000 static void r8a66597_check_syssts(struct r8a66597 *r8a66597, int port,
1003 if (syssts == SE0) {
1004 r8a66597_write(r8a66597, ~ATTCH, get_intsts_reg(port));
1005 r8a66597_bset(r8a66597, ATTCHE, get_intenb_reg(port));
1009 if (syssts == FS_JSTS)
1010 r8a66597_bset(r8a66597, HSE, get_syscfg_reg(port));
1011 else if (syssts == LS_JSTS)
1012 r8a66597_bclr(r8a66597, HSE, get_syscfg_reg(port));
1014 r8a66597_write(r8a66597, ~DTCH, get_intsts_reg(port));
1015 r8a66597_bset(r8a66597, DTCHE, get_intenb_reg(port));
1018 /* this function must be called with interrupt disabled */
1019 static void r8a66597_usb_connect(struct r8a66597 *r8a66597, int port)
1021 u16 speed = get_rh_usb_speed(r8a66597, port);
1022 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
1024 if (speed == HSMODE)
1025 rh->port |= (1 << USB_PORT_FEAT_HIGHSPEED);
1026 else if (speed == LSMODE)
1027 rh->port |= (1 << USB_PORT_FEAT_LOWSPEED);
1029 rh->port &= ~(1 << USB_PORT_FEAT_RESET);
1030 rh->port |= 1 << USB_PORT_FEAT_ENABLE;
1033 /* this function must be called with interrupt disabled */
1034 static void r8a66597_usb_disconnect(struct r8a66597 *r8a66597, int port)
1036 struct r8a66597_device *dev = r8a66597->root_hub[port].dev;
1038 disable_r8a66597_pipe_all(r8a66597, dev);
1039 free_usb_address(r8a66597, dev);
1041 start_root_hub_sampling(r8a66597, port, 0);
1044 /* this function must be called with interrupt disabled */
1045 static void prepare_setup_packet(struct r8a66597 *r8a66597,
1046 struct r8a66597_td *td)
1049 __le16 *p = (__le16 *)td->urb->setup_packet;
1050 unsigned long setup_addr = USBREQ;
1052 r8a66597_write(r8a66597, make_devsel(td->address) | td->maxpacket,
1054 r8a66597_write(r8a66597, ~(SIGN | SACK), INTSTS1);
1056 for (i = 0; i < 4; i++) {
1057 r8a66597_write(r8a66597, le16_to_cpu(p[i]), setup_addr);
1060 r8a66597_write(r8a66597, SUREQ, DCPCTR);
1063 /* this function must be called with interrupt disabled */
1064 static void prepare_packet_read(struct r8a66597 *r8a66597,
1065 struct r8a66597_td *td)
1067 struct urb *urb = td->urb;
1069 if (usb_pipecontrol(urb->pipe)) {
1070 r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG);
1071 r8a66597_mdfy(r8a66597, 0, ISEL | CURPIPE, CFIFOSEL);
1072 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
1073 if (urb->actual_length == 0) {
1074 r8a66597_pipe_toggle(r8a66597, td->pipe, 1);
1075 r8a66597_write(r8a66597, BCLR, CFIFOCTR);
1077 pipe_irq_disable(r8a66597, td->pipenum);
1078 pipe_start(r8a66597, td->pipe);
1079 pipe_irq_enable(r8a66597, urb, td->pipenum);
1081 if (urb->actual_length == 0) {
1082 pipe_irq_disable(r8a66597, td->pipenum);
1083 pipe_setting(r8a66597, td);
1084 pipe_stop(r8a66597, td->pipe);
1085 r8a66597_write(r8a66597, ~(1 << td->pipenum), BRDYSTS);
1087 if (td->pipe->pipetre) {
1088 r8a66597_write(r8a66597, TRCLR,
1090 r8a66597_write(r8a66597,
1092 (urb->transfer_buffer_length,
1095 r8a66597_bset(r8a66597, TRENB,
1099 pipe_start(r8a66597, td->pipe);
1100 pipe_irq_enable(r8a66597, urb, td->pipenum);
1105 /* this function must be called with interrupt disabled */
1106 static void prepare_packet_write(struct r8a66597 *r8a66597,
1107 struct r8a66597_td *td)
1110 struct urb *urb = td->urb;
1112 if (usb_pipecontrol(urb->pipe)) {
1113 pipe_stop(r8a66597, td->pipe);
1114 r8a66597_bset(r8a66597, R8A66597_DIR, DCPCFG);
1115 r8a66597_mdfy(r8a66597, ISEL, ISEL | CURPIPE, CFIFOSEL);
1116 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
1117 if (urb->actual_length == 0) {
1118 r8a66597_pipe_toggle(r8a66597, td->pipe, 1);
1119 r8a66597_write(r8a66597, BCLR, CFIFOCTR);
1122 if (urb->actual_length == 0)
1123 pipe_setting(r8a66597, td);
1124 if (td->pipe->pipetre)
1125 r8a66597_bclr(r8a66597, TRENB, td->pipe->pipetre);
1127 r8a66597_write(r8a66597, ~(1 << td->pipenum), BRDYSTS);
1129 fifo_change_from_pipe(r8a66597, td->pipe);
1130 tmp = r8a66597_read(r8a66597, td->pipe->fifoctr);
1131 if (unlikely((tmp & FRDY) == 0))
1132 pipe_irq_enable(r8a66597, urb, td->pipenum);
1134 packet_write(r8a66597, td->pipenum);
1135 pipe_start(r8a66597, td->pipe);
1138 /* this function must be called with interrupt disabled */
1139 static void prepare_status_packet(struct r8a66597 *r8a66597,
1140 struct r8a66597_td *td)
1142 struct urb *urb = td->urb;
1144 r8a66597_pipe_toggle(r8a66597, td->pipe, 1);
1145 pipe_stop(r8a66597, td->pipe);
1147 if (urb->setup_packet[0] & USB_ENDPOINT_DIR_MASK) {
1148 r8a66597_bset(r8a66597, R8A66597_DIR, DCPCFG);
1149 r8a66597_mdfy(r8a66597, ISEL, ISEL | CURPIPE, CFIFOSEL);
1150 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
1151 r8a66597_write(r8a66597, ~BEMP0, BEMPSTS);
1152 r8a66597_write(r8a66597, BCLR | BVAL, CFIFOCTR);
1153 enable_irq_empty(r8a66597, 0);
1155 r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG);
1156 r8a66597_mdfy(r8a66597, 0, ISEL | CURPIPE, CFIFOSEL);
1157 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
1158 r8a66597_write(r8a66597, BCLR, CFIFOCTR);
1159 enable_irq_ready(r8a66597, 0);
1161 enable_irq_nrdy(r8a66597, 0);
1162 pipe_start(r8a66597, td->pipe);
1165 static int is_set_address(unsigned char *setup_packet)
1167 if (((setup_packet[0] & USB_TYPE_MASK) == USB_TYPE_STANDARD) &&
1168 setup_packet[1] == USB_REQ_SET_ADDRESS)
1174 /* this function must be called with interrupt disabled */
1175 static int start_transfer(struct r8a66597 *r8a66597, struct r8a66597_td *td)
1181 if (is_set_address(td->urb->setup_packet)) {
1182 td->set_address = 1;
1183 td->urb->setup_packet[2] = alloc_usb_address(r8a66597,
1185 if (td->urb->setup_packet[2] == 0)
1188 prepare_setup_packet(r8a66597, td);
1191 prepare_packet_read(r8a66597, td);
1194 prepare_packet_write(r8a66597, td);
1197 prepare_status_packet(r8a66597, td);
1200 printk(KERN_ERR "r8a66597: invalid type.\n");
1207 static int check_transfer_finish(struct r8a66597_td *td, struct urb *urb)
1209 if (usb_pipeisoc(urb->pipe)) {
1210 if (urb->number_of_packets == td->iso_cnt)
1214 /* control or bulk or interrupt */
1215 if ((urb->transfer_buffer_length <= urb->actual_length) ||
1216 (td->short_packet) || (td->zero_packet))
1222 /* this function must be called with interrupt disabled */
1223 static void set_td_timer(struct r8a66597 *r8a66597, struct r8a66597_td *td)
1229 if (!list_empty(&r8a66597->pipe_queue[td->pipenum]) &&
1230 !usb_pipecontrol(td->urb->pipe) && usb_pipein(td->urb->pipe)) {
1231 r8a66597->timeout_map |= 1 << td->pipenum;
1232 switch (usb_pipetype(td->urb->pipe)) {
1233 case PIPE_INTERRUPT:
1234 case PIPE_ISOCHRONOUS:
1242 mod_timer(&r8a66597->td_timer[td->pipenum],
1243 jiffies + msecs_to_jiffies(time));
1247 /* this function must be called with interrupt disabled */
1248 static void finish_request(struct r8a66597 *r8a66597, struct r8a66597_td *td,
1249 u16 pipenum, struct urb *urb, int status)
1250 __releases(r8a66597->lock) __acquires(r8a66597->lock)
1253 struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597);
1255 r8a66597->timeout_map &= ~(1 << pipenum);
1258 if (td->set_address && (status != 0 || urb->unlinked))
1259 r8a66597->address_map &= ~(1 << urb->setup_packet[2]);
1261 pipe_toggle_save(r8a66597, td->pipe, urb);
1262 list_del(&td->queue);
1266 if (!list_empty(&r8a66597->pipe_queue[pipenum]))
1270 if (usb_pipeisoc(urb->pipe))
1271 urb->start_frame = r8a66597_get_frame(hcd);
1273 usb_hcd_unlink_urb_from_ep(r8a66597_to_hcd(r8a66597), urb);
1274 spin_unlock(&r8a66597->lock);
1275 usb_hcd_giveback_urb(hcd, urb, status);
1276 spin_lock(&r8a66597->lock);
1280 td = r8a66597_get_td(r8a66597, pipenum);
1284 start_transfer(r8a66597, td);
1285 set_td_timer(r8a66597, td);
1289 static void packet_read(struct r8a66597 *r8a66597, u16 pipenum)
1292 int rcv_len, bufsize, urb_len, size;
1294 struct r8a66597_td *td = r8a66597_get_td(r8a66597, pipenum);
1303 fifo_change_from_pipe(r8a66597, td->pipe);
1304 tmp = r8a66597_read(r8a66597, td->pipe->fifoctr);
1305 if (unlikely((tmp & FRDY) == 0)) {
1306 pipe_stop(r8a66597, td->pipe);
1307 pipe_irq_disable(r8a66597, pipenum);
1308 printk(KERN_ERR "r8a66597: in fifo not ready (%d)\n", pipenum);
1309 finish_request(r8a66597, td, pipenum, td->urb, -EPIPE);
1313 /* prepare parameters */
1314 rcv_len = tmp & DTLN;
1315 if (usb_pipeisoc(urb->pipe)) {
1316 buf = (u16 *)(urb->transfer_buffer +
1317 urb->iso_frame_desc[td->iso_cnt].offset);
1318 urb_len = urb->iso_frame_desc[td->iso_cnt].length;
1320 buf = (void *)urb->transfer_buffer + urb->actual_length;
1321 urb_len = urb->transfer_buffer_length - urb->actual_length;
1323 bufsize = min(urb_len, (int) td->maxpacket);
1324 if (rcv_len <= bufsize) {
1328 status = -EOVERFLOW;
1332 /* update parameters */
1333 urb->actual_length += size;
1335 td->zero_packet = 1;
1336 if (rcv_len < bufsize) {
1337 td->short_packet = 1;
1339 if (usb_pipeisoc(urb->pipe)) {
1340 urb->iso_frame_desc[td->iso_cnt].actual_length = size;
1341 urb->iso_frame_desc[td->iso_cnt].status = status;
1346 /* check transfer finish */
1347 if (finish || check_transfer_finish(td, urb)) {
1348 pipe_stop(r8a66597, td->pipe);
1349 pipe_irq_disable(r8a66597, pipenum);
1354 if (urb->transfer_buffer) {
1356 r8a66597_write(r8a66597, BCLR, td->pipe->fifoctr);
1358 r8a66597_read_fifo(r8a66597, td->pipe->fifoaddr,
1362 if (finish && pipenum != 0)
1363 finish_request(r8a66597, td, pipenum, urb, status);
1366 static void packet_write(struct r8a66597 *r8a66597, u16 pipenum)
1371 struct r8a66597_td *td = r8a66597_get_td(r8a66597, pipenum);
1378 fifo_change_from_pipe(r8a66597, td->pipe);
1379 tmp = r8a66597_read(r8a66597, td->pipe->fifoctr);
1380 if (unlikely((tmp & FRDY) == 0)) {
1381 pipe_stop(r8a66597, td->pipe);
1382 pipe_irq_disable(r8a66597, pipenum);
1383 printk(KERN_ERR "r8a66597: out fifo not ready (%d)\n", pipenum);
1384 finish_request(r8a66597, td, pipenum, urb, -EPIPE);
1388 /* prepare parameters */
1389 bufsize = td->maxpacket;
1390 if (usb_pipeisoc(urb->pipe)) {
1391 buf = (u16 *)(urb->transfer_buffer +
1392 urb->iso_frame_desc[td->iso_cnt].offset);
1394 (int)urb->iso_frame_desc[td->iso_cnt].length);
1396 buf = (u16 *)(urb->transfer_buffer + urb->actual_length);
1397 size = min_t(u32, bufsize,
1398 urb->transfer_buffer_length - urb->actual_length);
1403 r8a66597_write(r8a66597, ~(1 << pipenum), BEMPSTS);
1404 if (urb->transfer_buffer) {
1405 r8a66597_write_fifo(r8a66597, td->pipe->fifoaddr, buf, size);
1406 if (!usb_pipebulk(urb->pipe) || td->maxpacket != size)
1407 r8a66597_write(r8a66597, BVAL, td->pipe->fifoctr);
1410 /* update parameters */
1411 urb->actual_length += size;
1412 if (usb_pipeisoc(urb->pipe)) {
1413 urb->iso_frame_desc[td->iso_cnt].actual_length = size;
1414 urb->iso_frame_desc[td->iso_cnt].status = 0;
1418 /* check transfer finish */
1419 if (check_transfer_finish(td, urb)) {
1420 disable_irq_ready(r8a66597, pipenum);
1421 enable_irq_empty(r8a66597, pipenum);
1422 if (!usb_pipeisoc(urb->pipe))
1423 enable_irq_nrdy(r8a66597, pipenum);
1425 pipe_irq_enable(r8a66597, urb, pipenum);
1429 static void check_next_phase(struct r8a66597 *r8a66597, int status)
1431 struct r8a66597_td *td = r8a66597_get_td(r8a66597, 0);
1442 if (check_transfer_finish(td, urb))
1443 td->type = USB_PID_ACK;
1446 if (urb->transfer_buffer_length == urb->actual_length)
1447 td->type = USB_PID_ACK;
1448 else if (usb_pipeout(urb->pipe))
1449 td->type = USB_PID_OUT;
1451 td->type = USB_PID_IN;
1458 if (finish || status != 0 || urb->unlinked)
1459 finish_request(r8a66597, td, 0, urb, status);
1461 start_transfer(r8a66597, td);
1464 static int get_urb_error(struct r8a66597 *r8a66597, u16 pipenum)
1466 struct r8a66597_td *td = r8a66597_get_td(r8a66597, pipenum);
1469 u16 pid = r8a66597_read(r8a66597, td->pipe->pipectr) & PID;
1479 static void irq_pipe_ready(struct r8a66597 *r8a66597)
1484 struct r8a66597_td *td;
1486 mask = r8a66597_read(r8a66597, BRDYSTS)
1487 & r8a66597_read(r8a66597, BRDYENB);
1488 r8a66597_write(r8a66597, ~mask, BRDYSTS);
1490 td = r8a66597_get_td(r8a66597, 0);
1491 if (td && td->type == USB_PID_IN)
1492 packet_read(r8a66597, 0);
1494 pipe_irq_disable(r8a66597, 0);
1495 check_next_phase(r8a66597, 0);
1498 for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
1499 check = 1 << pipenum;
1501 td = r8a66597_get_td(r8a66597, pipenum);
1505 if (td->type == USB_PID_IN)
1506 packet_read(r8a66597, pipenum);
1507 else if (td->type == USB_PID_OUT)
1508 packet_write(r8a66597, pipenum);
1513 static void irq_pipe_empty(struct r8a66597 *r8a66597)
1519 struct r8a66597_td *td;
1521 mask = r8a66597_read(r8a66597, BEMPSTS)
1522 & r8a66597_read(r8a66597, BEMPENB);
1523 r8a66597_write(r8a66597, ~mask, BEMPSTS);
1525 cfifo_change(r8a66597, 0);
1526 td = r8a66597_get_td(r8a66597, 0);
1527 if (td && td->type != USB_PID_OUT)
1528 disable_irq_empty(r8a66597, 0);
1529 check_next_phase(r8a66597, 0);
1532 for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
1533 check = 1 << pipenum;
1535 struct r8a66597_td *td;
1536 td = r8a66597_get_td(r8a66597, pipenum);
1540 tmp = r8a66597_read(r8a66597, td->pipe->pipectr);
1541 if ((tmp & INBUFM) == 0) {
1542 disable_irq_empty(r8a66597, pipenum);
1543 pipe_irq_disable(r8a66597, pipenum);
1544 finish_request(r8a66597, td, pipenum, td->urb,
1551 static void irq_pipe_nrdy(struct r8a66597 *r8a66597)
1558 mask = r8a66597_read(r8a66597, NRDYSTS)
1559 & r8a66597_read(r8a66597, NRDYENB);
1560 r8a66597_write(r8a66597, ~mask, NRDYSTS);
1562 cfifo_change(r8a66597, 0);
1563 status = get_urb_error(r8a66597, 0);
1564 pipe_irq_disable(r8a66597, 0);
1565 check_next_phase(r8a66597, status);
1568 for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
1569 check = 1 << pipenum;
1571 struct r8a66597_td *td;
1572 td = r8a66597_get_td(r8a66597, pipenum);
1576 status = get_urb_error(r8a66597, pipenum);
1577 pipe_irq_disable(r8a66597, pipenum);
1578 pipe_stop(r8a66597, td->pipe);
1579 finish_request(r8a66597, td, pipenum, td->urb, status);
1584 static irqreturn_t r8a66597_irq(struct usb_hcd *hcd)
1586 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
1587 u16 intsts0, intsts1, intsts2;
1588 u16 intenb0, intenb1, intenb2;
1589 u16 mask0, mask1, mask2;
1592 spin_lock(&r8a66597->lock);
1594 intsts0 = r8a66597_read(r8a66597, INTSTS0);
1595 intsts1 = r8a66597_read(r8a66597, INTSTS1);
1596 intsts2 = r8a66597_read(r8a66597, INTSTS2);
1597 intenb0 = r8a66597_read(r8a66597, INTENB0);
1598 intenb1 = r8a66597_read(r8a66597, INTENB1);
1599 intenb2 = r8a66597_read(r8a66597, INTENB2);
1601 mask2 = intsts2 & intenb2;
1602 mask1 = intsts1 & intenb1;
1603 mask0 = intsts0 & intenb0 & (BEMP | NRDY | BRDY);
1605 if (mask2 & ATTCH) {
1606 r8a66597_write(r8a66597, ~ATTCH, INTSTS2);
1607 r8a66597_bclr(r8a66597, ATTCHE, INTENB2);
1609 /* start usb bus sampling */
1610 start_root_hub_sampling(r8a66597, 1, 1);
1613 r8a66597_write(r8a66597, ~DTCH, INTSTS2);
1614 r8a66597_bclr(r8a66597, DTCHE, INTENB2);
1615 r8a66597_usb_disconnect(r8a66597, 1);
1620 if (mask1 & ATTCH) {
1621 r8a66597_write(r8a66597, ~ATTCH, INTSTS1);
1622 r8a66597_bclr(r8a66597, ATTCHE, INTENB1);
1624 /* start usb bus sampling */
1625 start_root_hub_sampling(r8a66597, 0, 1);
1628 r8a66597_write(r8a66597, ~DTCH, INTSTS1);
1629 r8a66597_bclr(r8a66597, DTCHE, INTENB1);
1630 r8a66597_usb_disconnect(r8a66597, 0);
1633 r8a66597_write(r8a66597, ~SIGN, INTSTS1);
1634 status = get_urb_error(r8a66597, 0);
1635 check_next_phase(r8a66597, status);
1638 r8a66597_write(r8a66597, ~SACK, INTSTS1);
1639 check_next_phase(r8a66597, 0);
1644 irq_pipe_ready(r8a66597);
1646 irq_pipe_empty(r8a66597);
1648 irq_pipe_nrdy(r8a66597);
1651 spin_unlock(&r8a66597->lock);
1655 /* this function must be called with interrupt disabled */
1656 static void r8a66597_root_hub_control(struct r8a66597 *r8a66597, int port)
1659 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
1661 if (rh->port & (1 << USB_PORT_FEAT_RESET)) {
1662 unsigned long dvstctr_reg = get_dvstctr_reg(port);
1664 tmp = r8a66597_read(r8a66597, dvstctr_reg);
1665 if ((tmp & USBRST) == USBRST) {
1666 r8a66597_mdfy(r8a66597, UACT, USBRST | UACT,
1668 r8a66597_root_hub_start_polling(r8a66597);
1670 r8a66597_usb_connect(r8a66597, port);
1673 if (!(rh->port & (1 << USB_PORT_FEAT_CONNECTION))) {
1674 r8a66597_write(r8a66597, ~ATTCH, get_intsts_reg(port));
1675 r8a66597_bset(r8a66597, ATTCHE, get_intenb_reg(port));
1678 if (rh->scount > 0) {
1679 tmp = r8a66597_read(r8a66597, get_syssts_reg(port)) & LNST;
1680 if (tmp == rh->old_syssts) {
1682 if (rh->scount == 0)
1683 r8a66597_check_syssts(r8a66597, port, tmp);
1685 r8a66597_root_hub_start_polling(r8a66597);
1687 rh->scount = R8A66597_MAX_SAMPLING;
1688 rh->old_syssts = tmp;
1689 r8a66597_root_hub_start_polling(r8a66597);
1694 static void r8a66597_interval_timer(unsigned long _r8a66597)
1696 struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597;
1697 unsigned long flags;
1699 struct r8a66597_td *td;
1701 spin_lock_irqsave(&r8a66597->lock, flags);
1703 for (pipenum = 0; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
1704 if (!(r8a66597->interval_map & (1 << pipenum)))
1706 if (timer_pending(&r8a66597->interval_timer[pipenum]))
1709 td = r8a66597_get_td(r8a66597, pipenum);
1711 start_transfer(r8a66597, td);
1714 spin_unlock_irqrestore(&r8a66597->lock, flags);
1717 static void r8a66597_td_timer(unsigned long _r8a66597)
1719 struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597;
1720 unsigned long flags;
1722 struct r8a66597_td *td, *new_td = NULL;
1723 struct r8a66597_pipe *pipe;
1725 spin_lock_irqsave(&r8a66597->lock, flags);
1726 for (pipenum = 0; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
1727 if (!(r8a66597->timeout_map & (1 << pipenum)))
1729 if (timer_pending(&r8a66597->td_timer[pipenum]))
1732 td = r8a66597_get_td(r8a66597, pipenum);
1734 r8a66597->timeout_map &= ~(1 << pipenum);
1738 if (td->urb->actual_length) {
1739 set_td_timer(r8a66597, td);
1744 pipe_stop(r8a66597, pipe);
1748 list_move_tail(&new_td->queue,
1749 &r8a66597->pipe_queue[pipenum]);
1750 new_td = r8a66597_get_td(r8a66597, pipenum);
1755 } while (td != new_td && td->address == new_td->address);
1757 start_transfer(r8a66597, new_td);
1760 r8a66597->timeout_map &= ~(1 << pipenum);
1762 set_td_timer(r8a66597, new_td);
1765 spin_unlock_irqrestore(&r8a66597->lock, flags);
1768 static void r8a66597_timer(unsigned long _r8a66597)
1770 struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597;
1771 unsigned long flags;
1774 spin_lock_irqsave(&r8a66597->lock, flags);
1776 for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++)
1777 r8a66597_root_hub_control(r8a66597, port);
1779 spin_unlock_irqrestore(&r8a66597->lock, flags);
1782 static int check_pipe_config(struct r8a66597 *r8a66597, struct urb *urb)
1784 struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb);
1786 if (dev && dev->address && dev->state != USB_STATE_CONFIGURED &&
1787 (urb->dev->state == USB_STATE_CONFIGURED))
1793 static int r8a66597_start(struct usb_hcd *hcd)
1795 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
1797 hcd->state = HC_STATE_RUNNING;
1798 return enable_controller(r8a66597);
1801 static void r8a66597_stop(struct usb_hcd *hcd)
1803 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
1805 disable_controller(r8a66597);
1808 static void set_address_zero(struct r8a66597 *r8a66597, struct urb *urb)
1810 unsigned int usb_address = usb_pipedevice(urb->pipe);
1811 u16 root_port, hub_port;
1813 if (usb_address == 0) {
1814 get_port_number(urb->dev->devpath,
1815 &root_port, &hub_port);
1816 set_devadd_reg(r8a66597, 0,
1817 get_r8a66597_usb_speed(urb->dev->speed),
1818 get_parent_r8a66597_address(r8a66597, urb->dev),
1819 hub_port, root_port);
1823 static struct r8a66597_td *r8a66597_make_td(struct r8a66597 *r8a66597,
1825 struct usb_host_endpoint *hep)
1827 struct r8a66597_td *td;
1830 td = kzalloc(sizeof(struct r8a66597_td), GFP_ATOMIC);
1834 pipenum = r8a66597_get_pipenum(urb, hep);
1835 td->pipenum = pipenum;
1836 td->pipe = hep->hcpriv;
1838 td->address = get_urb_to_r8a66597_addr(r8a66597, urb);
1839 td->maxpacket = usb_maxpacket(urb->dev, urb->pipe,
1840 !usb_pipein(urb->pipe));
1841 if (usb_pipecontrol(urb->pipe))
1842 td->type = USB_PID_SETUP;
1843 else if (usb_pipein(urb->pipe))
1844 td->type = USB_PID_IN;
1846 td->type = USB_PID_OUT;
1847 INIT_LIST_HEAD(&td->queue);
1852 static int r8a66597_urb_enqueue(struct usb_hcd *hcd,
1856 struct usb_host_endpoint *hep = urb->ep;
1857 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
1858 struct r8a66597_td *td = NULL;
1859 int ret, request = 0;
1860 unsigned long flags;
1862 spin_lock_irqsave(&r8a66597->lock, flags);
1863 if (!get_urb_to_r8a66597_dev(r8a66597, urb)) {
1865 goto error_not_linked;
1868 ret = usb_hcd_link_urb_to_ep(hcd, urb);
1870 goto error_not_linked;
1873 hep->hcpriv = kzalloc(sizeof(struct r8a66597_pipe),
1879 set_pipe_reg_addr(hep->hcpriv, R8A66597_PIPE_NO_DMA);
1880 if (usb_pipeendpoint(urb->pipe))
1881 init_pipe_info(r8a66597, urb, hep, &hep->desc);
1884 if (unlikely(check_pipe_config(r8a66597, urb)))
1885 init_pipe_config(r8a66597, urb);
1887 set_address_zero(r8a66597, urb);
1888 td = r8a66597_make_td(r8a66597, urb, hep);
1893 if (list_empty(&r8a66597->pipe_queue[td->pipenum]))
1895 list_add_tail(&td->queue, &r8a66597->pipe_queue[td->pipenum]);
1899 if (td->pipe->info.timer_interval) {
1900 r8a66597->interval_map |= 1 << td->pipenum;
1901 mod_timer(&r8a66597->interval_timer[td->pipenum],
1902 jiffies + msecs_to_jiffies(
1903 td->pipe->info.timer_interval));
1905 ret = start_transfer(r8a66597, td);
1907 list_del(&td->queue);
1912 set_td_timer(r8a66597, td);
1916 usb_hcd_unlink_urb_from_ep(hcd, urb);
1918 spin_unlock_irqrestore(&r8a66597->lock, flags);
1922 static int r8a66597_urb_dequeue(struct usb_hcd *hcd, struct urb *urb,
1925 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
1926 struct r8a66597_td *td;
1927 unsigned long flags;
1930 spin_lock_irqsave(&r8a66597->lock, flags);
1931 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
1937 pipe_stop(r8a66597, td->pipe);
1938 pipe_irq_disable(r8a66597, td->pipenum);
1939 disable_irq_empty(r8a66597, td->pipenum);
1940 finish_request(r8a66597, td, td->pipenum, urb, status);
1943 spin_unlock_irqrestore(&r8a66597->lock, flags);
1947 static void r8a66597_endpoint_disable(struct usb_hcd *hcd,
1948 struct usb_host_endpoint *hep)
1950 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
1951 struct r8a66597_pipe *pipe = (struct r8a66597_pipe *)hep->hcpriv;
1952 struct r8a66597_td *td;
1953 struct urb *urb = NULL;
1955 unsigned long flags;
1959 pipenum = pipe->info.pipenum;
1967 spin_lock_irqsave(&r8a66597->lock, flags);
1968 pipe_stop(r8a66597, pipe);
1969 pipe_irq_disable(r8a66597, pipenum);
1970 disable_irq_empty(r8a66597, pipenum);
1971 td = r8a66597_get_td(r8a66597, pipenum);
1974 finish_request(r8a66597, td, pipenum, urb, -ESHUTDOWN);
1977 spin_unlock_irqrestore(&r8a66597->lock, flags);
1980 static int r8a66597_get_frame(struct usb_hcd *hcd)
1982 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
1983 return r8a66597_read(r8a66597, FRMNUM) & 0x03FF;
1986 static void collect_usb_address_map(struct usb_device *udev, unsigned long *map)
1990 if (udev->state == USB_STATE_CONFIGURED &&
1991 udev->parent && udev->parent->devnum > 1 &&
1992 udev->parent->descriptor.bDeviceClass == USB_CLASS_HUB)
1993 map[udev->devnum/32] |= (1 << (udev->devnum % 32));
1995 for (chix = 0; chix < udev->maxchild; chix++) {
1996 struct usb_device *childdev = udev->children[chix];
1999 collect_usb_address_map(childdev, map);
2003 /* this function must be called with interrupt disabled */
2004 static struct r8a66597_device *get_r8a66597_device(struct r8a66597 *r8a66597,
2007 struct r8a66597_device *dev;
2008 struct list_head *list = &r8a66597->child_device;
2010 list_for_each_entry(dev, list, device_list) {
2013 if (dev->usb_address != addr)
2019 printk(KERN_ERR "r8a66597: get_r8a66597_device fail.(%d)\n", addr);
2023 static void update_usb_address_map(struct r8a66597 *r8a66597,
2024 struct usb_device *root_hub,
2029 unsigned long flags;
2031 for (i = 0; i < 4; i++) {
2032 diff = r8a66597->child_connect_map[i] ^ map[i];
2036 for (j = 0; j < 32; j++) {
2037 if (!(diff & (1 << j)))
2041 if (map[i] & (1 << j))
2042 set_child_connect_map(r8a66597, addr);
2044 struct r8a66597_device *dev;
2046 spin_lock_irqsave(&r8a66597->lock, flags);
2047 dev = get_r8a66597_device(r8a66597, addr);
2048 disable_r8a66597_pipe_all(r8a66597, dev);
2049 free_usb_address(r8a66597, dev);
2050 put_child_connect_map(r8a66597, addr);
2051 spin_unlock_irqrestore(&r8a66597->lock, flags);
2057 static void r8a66597_check_detect_child(struct r8a66597 *r8a66597,
2058 struct usb_hcd *hcd)
2060 struct usb_bus *bus;
2061 unsigned long now_map[4];
2063 memset(now_map, 0, sizeof(now_map));
2065 list_for_each_entry(bus, &usb_bus_list, bus_list) {
2069 if (bus->busnum != hcd->self.busnum)
2072 collect_usb_address_map(bus->root_hub, now_map);
2073 update_usb_address_map(r8a66597, bus->root_hub, now_map);
2077 static int r8a66597_hub_status_data(struct usb_hcd *hcd, char *buf)
2079 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
2080 unsigned long flags;
2083 r8a66597_check_detect_child(r8a66597, hcd);
2085 spin_lock_irqsave(&r8a66597->lock, flags);
2087 *buf = 0; /* initialize (no change) */
2089 for (i = 0; i < R8A66597_MAX_ROOT_HUB; i++) {
2090 if (r8a66597->root_hub[i].port & 0xffff0000)
2091 *buf |= 1 << (i + 1);
2094 spin_unlock_irqrestore(&r8a66597->lock, flags);
2099 static void r8a66597_hub_descriptor(struct r8a66597 *r8a66597,
2100 struct usb_hub_descriptor *desc)
2102 desc->bDescriptorType = 0x29;
2103 desc->bHubContrCurrent = 0;
2104 desc->bNbrPorts = R8A66597_MAX_ROOT_HUB;
2105 desc->bDescLength = 9;
2106 desc->bPwrOn2PwrGood = 0;
2107 desc->wHubCharacteristics = cpu_to_le16(0x0011);
2108 desc->bitmap[0] = ((1 << R8A66597_MAX_ROOT_HUB) - 1) << 1;
2109 desc->bitmap[1] = ~0;
2112 static int r8a66597_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2113 u16 wIndex, char *buf, u16 wLength)
2115 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
2117 int port = (wIndex & 0x00FF) - 1;
2118 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
2119 unsigned long flags;
2123 spin_lock_irqsave(&r8a66597->lock, flags);
2125 case ClearHubFeature:
2128 case C_HUB_OVER_CURRENT:
2129 case C_HUB_LOCAL_POWER:
2135 case ClearPortFeature:
2136 if (wIndex > R8A66597_MAX_ROOT_HUB)
2142 case USB_PORT_FEAT_ENABLE:
2143 rh->port &= (1 << USB_PORT_FEAT_POWER);
2145 case USB_PORT_FEAT_SUSPEND:
2147 case USB_PORT_FEAT_POWER:
2148 r8a66597_port_power(r8a66597, port, 0);
2150 case USB_PORT_FEAT_C_ENABLE:
2151 case USB_PORT_FEAT_C_SUSPEND:
2152 case USB_PORT_FEAT_C_CONNECTION:
2153 case USB_PORT_FEAT_C_OVER_CURRENT:
2154 case USB_PORT_FEAT_C_RESET:
2159 rh->port &= ~(1 << wValue);
2161 case GetHubDescriptor:
2162 r8a66597_hub_descriptor(r8a66597,
2163 (struct usb_hub_descriptor *)buf);
2169 if (wIndex > R8A66597_MAX_ROOT_HUB)
2171 *(__le32 *)buf = cpu_to_le32(rh->port);
2173 case SetPortFeature:
2174 if (wIndex > R8A66597_MAX_ROOT_HUB)
2180 case USB_PORT_FEAT_SUSPEND:
2182 case USB_PORT_FEAT_POWER:
2183 r8a66597_port_power(r8a66597, port, 1);
2184 rh->port |= (1 << USB_PORT_FEAT_POWER);
2186 case USB_PORT_FEAT_RESET: {
2187 struct r8a66597_device *dev = rh->dev;
2189 rh->port |= (1 << USB_PORT_FEAT_RESET);
2191 disable_r8a66597_pipe_all(r8a66597, dev);
2192 free_usb_address(r8a66597, dev);
2194 r8a66597_mdfy(r8a66597, USBRST, USBRST | UACT,
2195 get_dvstctr_reg(port));
2196 mod_timer(&r8a66597->rh_timer,
2197 jiffies + msecs_to_jiffies(50));
2203 rh->port |= 1 << wValue;
2211 spin_unlock_irqrestore(&r8a66597->lock, flags);
2215 static struct hc_driver r8a66597_hc_driver = {
2216 .description = hcd_name,
2217 .hcd_priv_size = sizeof(struct r8a66597),
2218 .irq = r8a66597_irq,
2221 * generic hardware linkage
2225 .start = r8a66597_start,
2226 .stop = r8a66597_stop,
2229 * managing i/o requests and associated device resources
2231 .urb_enqueue = r8a66597_urb_enqueue,
2232 .urb_dequeue = r8a66597_urb_dequeue,
2233 .endpoint_disable = r8a66597_endpoint_disable,
2236 * periodic schedule support
2238 .get_frame_number = r8a66597_get_frame,
2243 .hub_status_data = r8a66597_hub_status_data,
2244 .hub_control = r8a66597_hub_control,
2247 #if defined(CONFIG_PM)
2248 static int r8a66597_suspend(struct platform_device *pdev, pm_message_t state)
2253 static int r8a66597_resume(struct platform_device *pdev)
2257 #else /* if defined(CONFIG_PM) */
2258 #define r8a66597_suspend NULL
2259 #define r8a66597_resume NULL
2262 static int __init_or_module r8a66597_remove(struct platform_device *pdev)
2264 struct r8a66597 *r8a66597 = dev_get_drvdata(&pdev->dev);
2265 struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597);
2267 del_timer_sync(&r8a66597->rh_timer);
2268 usb_remove_hcd(hcd);
2269 iounmap((void *)r8a66597->reg);
2270 #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) && defined(CONFIG_HAVE_CLK)
2271 clk_put(r8a66597->clk);
2277 static int __init r8a66597_probe(struct platform_device *pdev)
2279 #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) && defined(CONFIG_HAVE_CLK)
2282 struct resource *res = NULL, *ires;
2284 void __iomem *reg = NULL;
2285 struct usb_hcd *hcd = NULL;
2286 struct r8a66597 *r8a66597;
2289 unsigned long irq_trigger;
2291 if (pdev->dev.dma_mask) {
2293 dev_err(&pdev->dev, "dma not supported\n");
2297 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2300 dev_err(&pdev->dev, "platform_get_resource error.\n");
2304 ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
2308 "platform_get_resource IORESOURCE_IRQ error.\n");
2313 irq_trigger = ires->flags & IRQF_TRIGGER_MASK;
2315 reg = ioremap(res->start, resource_size(res));
2318 dev_err(&pdev->dev, "ioremap error.\n");
2322 /* initialize hcd */
2323 hcd = usb_create_hcd(&r8a66597_hc_driver, &pdev->dev, (char *)hcd_name);
2326 dev_err(&pdev->dev, "Failed to create hcd\n");
2329 r8a66597 = hcd_to_r8a66597(hcd);
2330 memset(r8a66597, 0, sizeof(struct r8a66597));
2331 dev_set_drvdata(&pdev->dev, r8a66597);
2333 #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) && defined(CONFIG_HAVE_CLK)
2334 snprintf(clk_name, sizeof(clk_name), "usb%d", pdev->id);
2335 r8a66597->clk = clk_get(&pdev->dev, clk_name);
2336 if (IS_ERR(r8a66597->clk)) {
2337 dev_err(&pdev->dev, "cannot get clock \"%s\"\n", clk_name);
2338 ret = PTR_ERR(r8a66597->clk);
2343 spin_lock_init(&r8a66597->lock);
2344 init_timer(&r8a66597->rh_timer);
2345 r8a66597->rh_timer.function = r8a66597_timer;
2346 r8a66597->rh_timer.data = (unsigned long)r8a66597;
2347 r8a66597->reg = (unsigned long)reg;
2349 for (i = 0; i < R8A66597_MAX_NUM_PIPE; i++) {
2350 INIT_LIST_HEAD(&r8a66597->pipe_queue[i]);
2351 init_timer(&r8a66597->td_timer[i]);
2352 r8a66597->td_timer[i].function = r8a66597_td_timer;
2353 r8a66597->td_timer[i].data = (unsigned long)r8a66597;
2354 setup_timer(&r8a66597->interval_timer[i],
2355 r8a66597_interval_timer,
2356 (unsigned long)r8a66597);
2358 INIT_LIST_HEAD(&r8a66597->child_device);
2360 hcd->rsrc_start = res->start;
2362 /* irq_sense setting on cmdline takes precedence over resource
2363 * settings, so the introduction of irqflags in IRQ resourse
2364 * won't disturb existing setups */
2365 switch (irq_sense) {
2367 irq_trigger = IRQF_TRIGGER_LOW;
2370 irq_trigger = IRQF_TRIGGER_FALLING;
2374 irq_sense = (irq_trigger & IRQF_TRIGGER_LOW) ?
2378 irq_trigger = IRQF_TRIGGER_LOW;
2382 dev_err(&pdev->dev, "Unknown irq_sense value.\n");
2385 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | irq_trigger);
2387 dev_err(&pdev->dev, "Failed to add hcd\n");
2394 #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) && defined(CONFIG_HAVE_CLK)
2395 clk_put(r8a66597->clk);
2407 static struct platform_driver r8a66597_driver = {
2408 .probe = r8a66597_probe,
2409 .remove = r8a66597_remove,
2410 .suspend = r8a66597_suspend,
2411 .resume = r8a66597_resume,
2413 .name = (char *) hcd_name,
2414 .owner = THIS_MODULE,
2418 static int __init r8a66597_init(void)
2423 printk(KERN_INFO KBUILD_MODNAME ": driver %s, %s\n", hcd_name,
2425 return platform_driver_register(&r8a66597_driver);
2427 module_init(r8a66597_init);
2429 static void __exit r8a66597_cleanup(void)
2431 platform_driver_unregister(&r8a66597_driver);
2433 module_exit(r8a66597_cleanup);