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)
118 r8a66597_write(r8a66597, SCKE, SYSCFG0);
119 tmp = r8a66597_read(r8a66597, SYSCFG0);
121 printk(KERN_ERR "r8a66597: register access fail.\n");
124 } while ((tmp & SCKE) != SCKE);
125 r8a66597_write(r8a66597, 0x04, 0x02);
128 r8a66597_write(r8a66597, USBE, SYSCFG0);
129 tmp = r8a66597_read(r8a66597, SYSCFG0);
131 printk(KERN_ERR "r8a66597: register access fail.\n");
134 } while ((tmp & USBE) != USBE);
135 r8a66597_bclr(r8a66597, USBE, SYSCFG0);
136 r8a66597_mdfy(r8a66597, clock, XTAL, SYSCFG0);
139 r8a66597_bset(r8a66597, XCKE, SYSCFG0);
142 tmp = r8a66597_read(r8a66597, SYSCFG0);
144 printk(KERN_ERR "r8a66597: register access fail.\n");
147 } while ((tmp & SCKE) != SCKE);
148 #endif /* #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) */
153 static void r8a66597_clock_disable(struct r8a66597 *r8a66597)
155 r8a66597_bclr(r8a66597, SCKE, SYSCFG0);
157 #if !defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
158 r8a66597_bclr(r8a66597, PLLC, SYSCFG0);
159 r8a66597_bclr(r8a66597, XCKE, SYSCFG0);
160 r8a66597_bclr(r8a66597, USBE, SYSCFG0);
164 static void r8a66597_enable_port(struct r8a66597 *r8a66597, int port)
168 val = port ? DRPD : DCFM | DRPD;
169 r8a66597_bset(r8a66597, val, get_syscfg_reg(port));
170 r8a66597_bset(r8a66597, HSE, get_syscfg_reg(port));
172 r8a66597_write(r8a66597, BURST | CPU_ADR_RD_WR, get_dmacfg_reg(port));
173 r8a66597_bclr(r8a66597, DTCHE, get_intenb_reg(port));
174 r8a66597_bset(r8a66597, ATTCHE, get_intenb_reg(port));
177 static void r8a66597_disable_port(struct r8a66597 *r8a66597, int port)
181 r8a66597_write(r8a66597, 0, get_intenb_reg(port));
182 r8a66597_write(r8a66597, 0, get_intsts_reg(port));
184 r8a66597_port_power(r8a66597, port, 0);
187 tmp = r8a66597_read(r8a66597, SOFCFG) & EDGESTS;
189 } while (tmp == EDGESTS);
191 val = port ? DRPD : DCFM | DRPD;
192 r8a66597_bclr(r8a66597, val, get_syscfg_reg(port));
193 r8a66597_bclr(r8a66597, HSE, get_syscfg_reg(port));
196 static int enable_controller(struct r8a66597 *r8a66597)
200 ret = r8a66597_clock_enable(r8a66597);
204 r8a66597_bset(r8a66597, vif & LDRV, PINCFG);
205 r8a66597_bset(r8a66597, USBE, SYSCFG0);
207 r8a66597_bset(r8a66597, BEMPE | NRDYE | BRDYE, INTENB0);
208 r8a66597_bset(r8a66597, irq_sense & INTL, SOFCFG);
209 r8a66597_bset(r8a66597, BRDY0, BRDYENB);
210 r8a66597_bset(r8a66597, BEMP0, BEMPENB);
212 r8a66597_bset(r8a66597, endian & BIGEND, CFIFOSEL);
213 r8a66597_bset(r8a66597, endian & BIGEND, D0FIFOSEL);
214 r8a66597_bset(r8a66597, endian & BIGEND, D1FIFOSEL);
215 r8a66597_bset(r8a66597, TRNENSEL, SOFCFG);
217 r8a66597_bset(r8a66597, SIGNE | SACKE, INTENB1);
219 for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++)
220 r8a66597_enable_port(r8a66597, port);
225 static void disable_controller(struct r8a66597 *r8a66597)
229 r8a66597_write(r8a66597, 0, INTENB0);
230 r8a66597_write(r8a66597, 0, INTSTS0);
232 for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++)
233 r8a66597_disable_port(r8a66597, port);
235 r8a66597_clock_disable(r8a66597);
238 static int get_parent_r8a66597_address(struct r8a66597 *r8a66597,
239 struct usb_device *udev)
241 struct r8a66597_device *dev;
243 if (udev->parent && udev->parent->devnum != 1)
246 dev = dev_get_drvdata(&udev->dev);
253 static int is_child_device(char *devpath)
255 return (devpath[2] ? 1 : 0);
258 static int is_hub_limit(char *devpath)
260 return ((strlen(devpath) >= 4) ? 1 : 0);
263 static void get_port_number(char *devpath, u16 *root_port, u16 *hub_port)
266 *root_port = (devpath[0] & 0x0F) - 1;
267 if (*root_port >= R8A66597_MAX_ROOT_HUB)
268 printk(KERN_ERR "r8a66597: Illegal root port number.\n");
271 *hub_port = devpath[2] & 0x0F;
274 static u16 get_r8a66597_usb_speed(enum usb_device_speed speed)
289 printk(KERN_ERR "r8a66597: unknown speed\n");
296 static void set_child_connect_map(struct r8a66597 *r8a66597, int address)
301 r8a66597->child_connect_map[idx] |= 1 << (address % 32);
304 static void put_child_connect_map(struct r8a66597 *r8a66597, int address)
309 r8a66597->child_connect_map[idx] &= ~(1 << (address % 32));
312 static void set_pipe_reg_addr(struct r8a66597_pipe *pipe, u8 dma_ch)
314 u16 pipenum = pipe->info.pipenum;
315 const unsigned long fifoaddr[] = {D0FIFO, D1FIFO, CFIFO};
316 const unsigned long fifosel[] = {D0FIFOSEL, D1FIFOSEL, CFIFOSEL};
317 const unsigned long fifoctr[] = {D0FIFOCTR, D1FIFOCTR, CFIFOCTR};
319 if (dma_ch > R8A66597_PIPE_NO_DMA) /* dma fifo not use? */
320 dma_ch = R8A66597_PIPE_NO_DMA;
322 pipe->fifoaddr = fifoaddr[dma_ch];
323 pipe->fifosel = fifosel[dma_ch];
324 pipe->fifoctr = fifoctr[dma_ch];
327 pipe->pipectr = DCPCTR;
329 pipe->pipectr = get_pipectr_addr(pipenum);
331 if (check_bulk_or_isoc(pipenum)) {
332 pipe->pipetre = get_pipetre_addr(pipenum);
333 pipe->pipetrn = get_pipetrn_addr(pipenum);
340 static struct r8a66597_device *
341 get_urb_to_r8a66597_dev(struct r8a66597 *r8a66597, struct urb *urb)
343 if (usb_pipedevice(urb->pipe) == 0)
344 return &r8a66597->device0;
346 return dev_get_drvdata(&urb->dev->dev);
349 static int make_r8a66597_device(struct r8a66597 *r8a66597,
350 struct urb *urb, u8 addr)
352 struct r8a66597_device *dev;
353 int usb_address = urb->setup_packet[2]; /* urb->pipe is address 0 */
355 dev = kzalloc(sizeof(struct r8a66597_device), GFP_ATOMIC);
359 dev_set_drvdata(&urb->dev->dev, dev);
360 dev->udev = urb->dev;
362 dev->usb_address = usb_address;
363 dev->state = USB_STATE_ADDRESS;
364 dev->ep_in_toggle = 0;
365 dev->ep_out_toggle = 0;
366 INIT_LIST_HEAD(&dev->device_list);
367 list_add_tail(&dev->device_list, &r8a66597->child_device);
369 get_port_number(urb->dev->devpath, &dev->root_port, &dev->hub_port);
370 if (!is_child_device(urb->dev->devpath))
371 r8a66597->root_hub[dev->root_port].dev = dev;
373 set_devadd_reg(r8a66597, dev->address,
374 get_r8a66597_usb_speed(urb->dev->speed),
375 get_parent_r8a66597_address(r8a66597, urb->dev),
376 dev->hub_port, dev->root_port);
381 /* this function must be called with interrupt disabled */
382 static u8 alloc_usb_address(struct r8a66597 *r8a66597, struct urb *urb)
384 u8 addr; /* R8A66597's address */
385 struct r8a66597_device *dev;
387 if (is_hub_limit(urb->dev->devpath)) {
388 dev_err(&urb->dev->dev, "External hub limit reached.\n");
392 dev = get_urb_to_r8a66597_dev(r8a66597, urb);
393 if (dev && dev->state >= USB_STATE_ADDRESS)
396 for (addr = 1; addr <= R8A66597_MAX_DEVICE; addr++) {
397 if (r8a66597->address_map & (1 << addr))
400 dbg("alloc_address: r8a66597_addr=%d", addr);
401 r8a66597->address_map |= 1 << addr;
403 if (make_r8a66597_device(r8a66597, urb, addr) < 0)
409 dev_err(&urb->dev->dev,
410 "cannot communicate with a USB device more than 10.(%x)\n",
411 r8a66597->address_map);
416 /* this function must be called with interrupt disabled */
417 static void free_usb_address(struct r8a66597 *r8a66597,
418 struct r8a66597_device *dev)
425 dbg("free_addr: addr=%d", dev->address);
427 dev->state = USB_STATE_DEFAULT;
428 r8a66597->address_map &= ~(1 << dev->address);
430 dev_set_drvdata(&dev->udev->dev, NULL);
431 list_del(&dev->device_list);
434 for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++) {
435 if (r8a66597->root_hub[port].dev == dev) {
436 r8a66597->root_hub[port].dev = NULL;
442 static void r8a66597_reg_wait(struct r8a66597 *r8a66597, unsigned long reg,
449 tmp = r8a66597_read(r8a66597, reg);
451 printk(KERN_ERR "r8a66597: register%lx, loop %x "
452 "is timeout\n", reg, loop);
456 } while ((tmp & mask) != loop);
459 /* this function must be called with interrupt disabled */
460 static void pipe_start(struct r8a66597 *r8a66597, struct r8a66597_pipe *pipe)
464 tmp = r8a66597_read(r8a66597, pipe->pipectr) & PID;
465 if ((pipe->info.pipenum != 0) & ((tmp & PID_STALL) != 0)) /* stall? */
466 r8a66597_mdfy(r8a66597, PID_NAK, PID, pipe->pipectr);
467 r8a66597_mdfy(r8a66597, PID_BUF, PID, pipe->pipectr);
470 /* this function must be called with interrupt disabled */
471 static void pipe_stop(struct r8a66597 *r8a66597, struct r8a66597_pipe *pipe)
475 tmp = r8a66597_read(r8a66597, pipe->pipectr) & PID;
476 if ((tmp & PID_STALL11) != PID_STALL11) /* force stall? */
477 r8a66597_mdfy(r8a66597, PID_STALL, PID, pipe->pipectr);
478 r8a66597_mdfy(r8a66597, PID_NAK, PID, pipe->pipectr);
479 r8a66597_reg_wait(r8a66597, pipe->pipectr, PBUSY, 0);
482 /* this function must be called with interrupt disabled */
483 static void clear_all_buffer(struct r8a66597 *r8a66597,
484 struct r8a66597_pipe *pipe)
488 if (!pipe || pipe->info.pipenum == 0)
491 pipe_stop(r8a66597, pipe);
492 r8a66597_bset(r8a66597, ACLRM, pipe->pipectr);
493 tmp = r8a66597_read(r8a66597, pipe->pipectr);
494 tmp = r8a66597_read(r8a66597, pipe->pipectr);
495 tmp = r8a66597_read(r8a66597, pipe->pipectr);
496 r8a66597_bclr(r8a66597, ACLRM, pipe->pipectr);
499 /* this function must be called with interrupt disabled */
500 static void r8a66597_pipe_toggle(struct r8a66597 *r8a66597,
501 struct r8a66597_pipe *pipe, int toggle)
504 r8a66597_bset(r8a66597, SQSET, pipe->pipectr);
506 r8a66597_bset(r8a66597, SQCLR, pipe->pipectr);
509 /* this function must be called with interrupt disabled */
510 static inline void cfifo_change(struct r8a66597 *r8a66597, u16 pipenum)
512 r8a66597_mdfy(r8a66597, MBW | pipenum, MBW | CURPIPE, CFIFOSEL);
513 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, pipenum);
516 /* this function must be called with interrupt disabled */
517 static inline void fifo_change_from_pipe(struct r8a66597 *r8a66597,
518 struct r8a66597_pipe *pipe)
520 cfifo_change(r8a66597, 0);
521 r8a66597_mdfy(r8a66597, MBW | 0, MBW | CURPIPE, D0FIFOSEL);
522 r8a66597_mdfy(r8a66597, MBW | 0, MBW | CURPIPE, D1FIFOSEL);
524 r8a66597_mdfy(r8a66597, MBW | pipe->info.pipenum, MBW | CURPIPE,
526 r8a66597_reg_wait(r8a66597, pipe->fifosel, CURPIPE, pipe->info.pipenum);
529 static u16 r8a66597_get_pipenum(struct urb *urb, struct usb_host_endpoint *hep)
531 struct r8a66597_pipe *pipe = hep->hcpriv;
533 if (usb_pipeendpoint(urb->pipe) == 0)
536 return pipe->info.pipenum;
539 static u16 get_urb_to_r8a66597_addr(struct r8a66597 *r8a66597, struct urb *urb)
541 struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb);
543 return (usb_pipedevice(urb->pipe) == 0) ? 0 : dev->address;
546 static unsigned short *get_toggle_pointer(struct r8a66597_device *dev,
552 return usb_pipein(urb_pipe) ? &dev->ep_in_toggle : &dev->ep_out_toggle;
555 /* this function must be called with interrupt disabled */
556 static void pipe_toggle_set(struct r8a66597 *r8a66597,
557 struct r8a66597_pipe *pipe,
558 struct urb *urb, int set)
560 struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb);
561 unsigned char endpoint = usb_pipeendpoint(urb->pipe);
562 unsigned short *toggle = get_toggle_pointer(dev, urb->pipe);
568 *toggle |= 1 << endpoint;
570 *toggle &= ~(1 << endpoint);
573 /* this function must be called with interrupt disabled */
574 static void pipe_toggle_save(struct r8a66597 *r8a66597,
575 struct r8a66597_pipe *pipe,
578 if (r8a66597_read(r8a66597, pipe->pipectr) & SQMON)
579 pipe_toggle_set(r8a66597, pipe, urb, 1);
581 pipe_toggle_set(r8a66597, pipe, urb, 0);
584 /* this function must be called with interrupt disabled */
585 static void pipe_toggle_restore(struct r8a66597 *r8a66597,
586 struct r8a66597_pipe *pipe,
589 struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb);
590 unsigned char endpoint = usb_pipeendpoint(urb->pipe);
591 unsigned short *toggle = get_toggle_pointer(dev, urb->pipe);
596 r8a66597_pipe_toggle(r8a66597, pipe, *toggle & (1 << endpoint));
599 /* this function must be called with interrupt disabled */
600 static void pipe_buffer_setting(struct r8a66597 *r8a66597,
601 struct r8a66597_pipe_info *info)
605 if (info->pipenum == 0)
608 r8a66597_bset(r8a66597, ACLRM, get_pipectr_addr(info->pipenum));
609 r8a66597_bclr(r8a66597, ACLRM, get_pipectr_addr(info->pipenum));
610 r8a66597_write(r8a66597, info->pipenum, PIPESEL);
613 if (info->type == R8A66597_BULK && info->dir_in)
614 val |= R8A66597_DBLB | R8A66597_SHTNAK;
615 val |= info->type | info->epnum;
616 r8a66597_write(r8a66597, val, PIPECFG);
618 r8a66597_write(r8a66597, (info->buf_bsize << 10) | (info->bufnum),
620 r8a66597_write(r8a66597, make_devsel(info->address) | info->maxpacket,
622 r8a66597_write(r8a66597, info->interval, PIPEPERI);
625 /* this function must be called with interrupt disabled */
626 static void pipe_setting(struct r8a66597 *r8a66597, struct r8a66597_td *td)
628 struct r8a66597_pipe_info *info;
629 struct urb *urb = td->urb;
631 if (td->pipenum > 0) {
632 info = &td->pipe->info;
633 cfifo_change(r8a66597, 0);
634 pipe_buffer_setting(r8a66597, info);
636 if (!usb_gettoggle(urb->dev, usb_pipeendpoint(urb->pipe),
637 usb_pipeout(urb->pipe)) &&
638 !usb_pipecontrol(urb->pipe)) {
639 r8a66597_pipe_toggle(r8a66597, td->pipe, 0);
640 pipe_toggle_set(r8a66597, td->pipe, urb, 0);
641 clear_all_buffer(r8a66597, td->pipe);
642 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
643 usb_pipeout(urb->pipe), 1);
645 pipe_toggle_restore(r8a66597, td->pipe, urb);
649 /* this function must be called with interrupt disabled */
650 static u16 get_empty_pipenum(struct r8a66597 *r8a66597,
651 struct usb_endpoint_descriptor *ep)
653 u16 array[R8A66597_MAX_NUM_PIPE], i = 0, min;
655 memset(array, 0, sizeof(array));
656 switch (ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
657 case USB_ENDPOINT_XFER_BULK:
658 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
665 case USB_ENDPOINT_XFER_INT:
666 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) {
673 case USB_ENDPOINT_XFER_ISOC:
674 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
680 printk(KERN_ERR "r8a66597: Illegal type\n");
686 while (array[i] != 0) {
687 if (r8a66597->pipe_cnt[min] > r8a66597->pipe_cnt[array[i]])
695 static u16 get_r8a66597_type(__u8 type)
700 case USB_ENDPOINT_XFER_BULK:
701 r8a66597_type = R8A66597_BULK;
703 case USB_ENDPOINT_XFER_INT:
704 r8a66597_type = R8A66597_INT;
706 case USB_ENDPOINT_XFER_ISOC:
707 r8a66597_type = R8A66597_ISO;
710 printk(KERN_ERR "r8a66597: Illegal type\n");
711 r8a66597_type = 0x0000;
715 return r8a66597_type;
718 static u16 get_bufnum(u16 pipenum)
724 else if (check_bulk_or_isoc(pipenum))
725 bufnum = 8 + (pipenum - 1) * R8A66597_BUF_BSIZE*2;
726 else if (check_interrupt(pipenum))
727 bufnum = 4 + (pipenum - 6);
729 printk(KERN_ERR "r8a66597: Illegal pipenum (%d)\n", pipenum);
734 static u16 get_buf_bsize(u16 pipenum)
740 else if (check_bulk_or_isoc(pipenum))
741 buf_bsize = R8A66597_BUF_BSIZE - 1;
742 else if (check_interrupt(pipenum))
745 printk(KERN_ERR "r8a66597: Illegal pipenum (%d)\n", pipenum);
750 /* this function must be called with interrupt disabled */
751 static void enable_r8a66597_pipe_dma(struct r8a66597 *r8a66597,
752 struct r8a66597_device *dev,
753 struct r8a66597_pipe *pipe,
756 #if !defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
758 struct r8a66597_pipe_info *info = &pipe->info;
760 if ((pipe->info.pipenum != 0) && (info->type != R8A66597_INT)) {
761 for (i = 0; i < R8A66597_MAX_DMA_CHANNEL; i++) {
762 if ((r8a66597->dma_map & (1 << i)) != 0)
765 dev_info(&dev->udev->dev,
766 "address %d, EndpointAddress 0x%02x use "
767 "DMA FIFO\n", usb_pipedevice(urb->pipe),
769 USB_ENDPOINT_DIR_MASK + info->epnum
772 r8a66597->dma_map |= 1 << i;
773 dev->dma_map |= 1 << i;
774 set_pipe_reg_addr(pipe, i);
776 cfifo_change(r8a66597, 0);
777 r8a66597_mdfy(r8a66597, MBW | pipe->info.pipenum,
778 MBW | CURPIPE, pipe->fifosel);
780 r8a66597_reg_wait(r8a66597, pipe->fifosel, CURPIPE,
782 r8a66597_bset(r8a66597, BCLR, pipe->fifoctr);
786 #endif /* #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) */
789 /* this function must be called with interrupt disabled */
790 static void enable_r8a66597_pipe(struct r8a66597 *r8a66597, struct urb *urb,
791 struct usb_host_endpoint *hep,
792 struct r8a66597_pipe_info *info)
794 struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb);
795 struct r8a66597_pipe *pipe = hep->hcpriv;
800 set_pipe_reg_addr(pipe, R8A66597_PIPE_NO_DMA);
801 r8a66597->pipe_cnt[pipe->info.pipenum]++;
802 dev->pipe_cnt[pipe->info.pipenum]++;
804 enable_r8a66597_pipe_dma(r8a66597, dev, pipe, urb);
807 /* this function must be called with interrupt disabled */
808 static void force_dequeue(struct r8a66597 *r8a66597, u16 pipenum, u16 address)
810 struct r8a66597_td *td, *next;
812 struct list_head *list = &r8a66597->pipe_queue[pipenum];
814 if (list_empty(list))
817 list_for_each_entry_safe(td, next, list, queue) {
820 if (td->address != address)
824 list_del(&td->queue);
828 usb_hcd_unlink_urb_from_ep(r8a66597_to_hcd(r8a66597),
831 spin_unlock(&r8a66597->lock);
832 usb_hcd_giveback_urb(r8a66597_to_hcd(r8a66597), urb,
834 spin_lock(&r8a66597->lock);
840 /* this function must be called with interrupt disabled */
841 static void disable_r8a66597_pipe_all(struct r8a66597 *r8a66597,
842 struct r8a66597_device *dev)
850 for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
851 if (!dev->pipe_cnt[pipenum])
856 force_dequeue(r8a66597, 0, dev->address);
859 r8a66597->pipe_cnt[pipenum] -= dev->pipe_cnt[pipenum];
860 dev->pipe_cnt[pipenum] = 0;
861 force_dequeue(r8a66597, pipenum, dev->address);
866 r8a66597->dma_map &= ~(dev->dma_map);
870 static u16 get_interval(struct urb *urb, __u8 interval)
875 if (urb->dev->speed == USB_SPEED_HIGH) {
879 time = interval ? interval - 1 : 0;
881 if (interval > 128) {
884 /* calculate the nearest value for PIPEPERI */
885 for (i = 0; i < 7; i++) {
886 if ((1 << i) < interval &&
887 (1 << (i + 1) > interval))
896 static unsigned long get_timer_interval(struct urb *urb, __u8 interval)
899 unsigned long time = 1;
901 if (usb_pipeisoc(urb->pipe))
904 if (get_r8a66597_usb_speed(urb->dev->speed) == HSMODE) {
905 for (i = 0; i < (interval - 1); i++)
907 time = time * 125 / 1000; /* uSOF -> msec */
915 /* this function must be called with interrupt disabled */
916 static void init_pipe_info(struct r8a66597 *r8a66597, struct urb *urb,
917 struct usb_host_endpoint *hep,
918 struct usb_endpoint_descriptor *ep)
920 struct r8a66597_pipe_info info;
922 info.pipenum = get_empty_pipenum(r8a66597, ep);
923 info.address = get_urb_to_r8a66597_addr(r8a66597, urb);
924 info.epnum = ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
925 info.maxpacket = le16_to_cpu(ep->wMaxPacketSize);
926 info.type = get_r8a66597_type(ep->bmAttributes
927 & USB_ENDPOINT_XFERTYPE_MASK);
928 info.bufnum = get_bufnum(info.pipenum);
929 info.buf_bsize = get_buf_bsize(info.pipenum);
930 if (info.type == R8A66597_BULK) {
932 info.timer_interval = 0;
934 info.interval = get_interval(urb, ep->bInterval);
935 info.timer_interval = get_timer_interval(urb, ep->bInterval);
937 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
942 enable_r8a66597_pipe(r8a66597, urb, hep, &info);
945 static void init_pipe_config(struct r8a66597 *r8a66597, struct urb *urb)
947 struct r8a66597_device *dev;
949 dev = get_urb_to_r8a66597_dev(r8a66597, urb);
950 dev->state = USB_STATE_CONFIGURED;
953 static void pipe_irq_enable(struct r8a66597 *r8a66597, struct urb *urb,
956 if (pipenum == 0 && usb_pipeout(urb->pipe))
957 enable_irq_empty(r8a66597, pipenum);
959 enable_irq_ready(r8a66597, pipenum);
961 if (!usb_pipeisoc(urb->pipe))
962 enable_irq_nrdy(r8a66597, pipenum);
965 static void pipe_irq_disable(struct r8a66597 *r8a66597, u16 pipenum)
967 disable_irq_ready(r8a66597, pipenum);
968 disable_irq_nrdy(r8a66597, pipenum);
971 static void r8a66597_root_hub_start_polling(struct r8a66597 *r8a66597)
973 mod_timer(&r8a66597->rh_timer,
974 jiffies + msecs_to_jiffies(R8A66597_RH_POLL_TIME));
977 static void start_root_hub_sampling(struct r8a66597 *r8a66597, int port,
980 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
982 rh->old_syssts = r8a66597_read(r8a66597, get_syssts_reg(port)) & LNST;
983 rh->scount = R8A66597_MAX_SAMPLING;
985 rh->port |= 1 << USB_PORT_FEAT_CONNECTION;
987 rh->port &= ~(1 << USB_PORT_FEAT_CONNECTION);
988 rh->port |= 1 << USB_PORT_FEAT_C_CONNECTION;
990 r8a66597_root_hub_start_polling(r8a66597);
993 /* this function must be called with interrupt disabled */
994 static void r8a66597_check_syssts(struct r8a66597 *r8a66597, int port,
998 r8a66597_write(r8a66597, ~ATTCH, get_intsts_reg(port));
999 r8a66597_bset(r8a66597, ATTCHE, get_intenb_reg(port));
1003 if (syssts == FS_JSTS)
1004 r8a66597_bset(r8a66597, HSE, get_syscfg_reg(port));
1005 else if (syssts == LS_JSTS)
1006 r8a66597_bclr(r8a66597, HSE, get_syscfg_reg(port));
1008 r8a66597_write(r8a66597, ~DTCH, get_intsts_reg(port));
1009 r8a66597_bset(r8a66597, DTCHE, get_intenb_reg(port));
1012 /* this function must be called with interrupt disabled */
1013 static void r8a66597_usb_connect(struct r8a66597 *r8a66597, int port)
1015 u16 speed = get_rh_usb_speed(r8a66597, port);
1016 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
1018 if (speed == HSMODE)
1019 rh->port |= (1 << USB_PORT_FEAT_HIGHSPEED);
1020 else if (speed == LSMODE)
1021 rh->port |= (1 << USB_PORT_FEAT_LOWSPEED);
1023 rh->port &= ~(1 << USB_PORT_FEAT_RESET);
1024 rh->port |= 1 << USB_PORT_FEAT_ENABLE;
1027 /* this function must be called with interrupt disabled */
1028 static void r8a66597_usb_disconnect(struct r8a66597 *r8a66597, int port)
1030 struct r8a66597_device *dev = r8a66597->root_hub[port].dev;
1032 disable_r8a66597_pipe_all(r8a66597, dev);
1033 free_usb_address(r8a66597, dev);
1035 start_root_hub_sampling(r8a66597, port, 0);
1038 /* this function must be called with interrupt disabled */
1039 static void prepare_setup_packet(struct r8a66597 *r8a66597,
1040 struct r8a66597_td *td)
1043 __le16 *p = (__le16 *)td->urb->setup_packet;
1044 unsigned long setup_addr = USBREQ;
1046 r8a66597_write(r8a66597, make_devsel(td->address) | td->maxpacket,
1048 r8a66597_write(r8a66597, ~(SIGN | SACK), INTSTS1);
1050 for (i = 0; i < 4; i++) {
1051 r8a66597_write(r8a66597, le16_to_cpu(p[i]), setup_addr);
1054 r8a66597_write(r8a66597, SUREQ, DCPCTR);
1057 /* this function must be called with interrupt disabled */
1058 static void prepare_packet_read(struct r8a66597 *r8a66597,
1059 struct r8a66597_td *td)
1061 struct urb *urb = td->urb;
1063 if (usb_pipecontrol(urb->pipe)) {
1064 r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG);
1065 r8a66597_mdfy(r8a66597, 0, ISEL | CURPIPE, CFIFOSEL);
1066 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
1067 if (urb->actual_length == 0) {
1068 r8a66597_pipe_toggle(r8a66597, td->pipe, 1);
1069 r8a66597_write(r8a66597, BCLR, CFIFOCTR);
1071 pipe_irq_disable(r8a66597, td->pipenum);
1072 pipe_start(r8a66597, td->pipe);
1073 pipe_irq_enable(r8a66597, urb, td->pipenum);
1075 if (urb->actual_length == 0) {
1076 pipe_irq_disable(r8a66597, td->pipenum);
1077 pipe_setting(r8a66597, td);
1078 pipe_stop(r8a66597, td->pipe);
1079 r8a66597_write(r8a66597, ~(1 << td->pipenum), BRDYSTS);
1081 if (td->pipe->pipetre) {
1082 r8a66597_write(r8a66597, TRCLR,
1084 r8a66597_write(r8a66597,
1086 (urb->transfer_buffer_length,
1089 r8a66597_bset(r8a66597, TRENB,
1093 pipe_start(r8a66597, td->pipe);
1094 pipe_irq_enable(r8a66597, urb, td->pipenum);
1099 /* this function must be called with interrupt disabled */
1100 static void prepare_packet_write(struct r8a66597 *r8a66597,
1101 struct r8a66597_td *td)
1104 struct urb *urb = td->urb;
1106 if (usb_pipecontrol(urb->pipe)) {
1107 pipe_stop(r8a66597, td->pipe);
1108 r8a66597_bset(r8a66597, R8A66597_DIR, DCPCFG);
1109 r8a66597_mdfy(r8a66597, ISEL, ISEL | CURPIPE, CFIFOSEL);
1110 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
1111 if (urb->actual_length == 0) {
1112 r8a66597_pipe_toggle(r8a66597, td->pipe, 1);
1113 r8a66597_write(r8a66597, BCLR, CFIFOCTR);
1116 if (urb->actual_length == 0)
1117 pipe_setting(r8a66597, td);
1118 if (td->pipe->pipetre)
1119 r8a66597_bclr(r8a66597, TRENB, td->pipe->pipetre);
1121 r8a66597_write(r8a66597, ~(1 << td->pipenum), BRDYSTS);
1123 fifo_change_from_pipe(r8a66597, td->pipe);
1124 tmp = r8a66597_read(r8a66597, td->pipe->fifoctr);
1125 if (unlikely((tmp & FRDY) == 0))
1126 pipe_irq_enable(r8a66597, urb, td->pipenum);
1128 packet_write(r8a66597, td->pipenum);
1129 pipe_start(r8a66597, td->pipe);
1132 /* this function must be called with interrupt disabled */
1133 static void prepare_status_packet(struct r8a66597 *r8a66597,
1134 struct r8a66597_td *td)
1136 struct urb *urb = td->urb;
1138 r8a66597_pipe_toggle(r8a66597, td->pipe, 1);
1139 pipe_stop(r8a66597, td->pipe);
1141 if (urb->setup_packet[0] & USB_ENDPOINT_DIR_MASK) {
1142 r8a66597_bset(r8a66597, R8A66597_DIR, DCPCFG);
1143 r8a66597_mdfy(r8a66597, ISEL, ISEL | CURPIPE, CFIFOSEL);
1144 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
1145 r8a66597_write(r8a66597, ~BEMP0, BEMPSTS);
1146 r8a66597_write(r8a66597, BCLR | BVAL, CFIFOCTR);
1147 enable_irq_empty(r8a66597, 0);
1149 r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG);
1150 r8a66597_mdfy(r8a66597, 0, ISEL | CURPIPE, CFIFOSEL);
1151 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
1152 r8a66597_write(r8a66597, BCLR, CFIFOCTR);
1153 enable_irq_ready(r8a66597, 0);
1155 enable_irq_nrdy(r8a66597, 0);
1156 pipe_start(r8a66597, td->pipe);
1159 static int is_set_address(unsigned char *setup_packet)
1161 if (((setup_packet[0] & USB_TYPE_MASK) == USB_TYPE_STANDARD) &&
1162 setup_packet[1] == USB_REQ_SET_ADDRESS)
1168 /* this function must be called with interrupt disabled */
1169 static int start_transfer(struct r8a66597 *r8a66597, struct r8a66597_td *td)
1175 if (is_set_address(td->urb->setup_packet)) {
1176 td->set_address = 1;
1177 td->urb->setup_packet[2] = alloc_usb_address(r8a66597,
1179 if (td->urb->setup_packet[2] == 0)
1182 prepare_setup_packet(r8a66597, td);
1185 prepare_packet_read(r8a66597, td);
1188 prepare_packet_write(r8a66597, td);
1191 prepare_status_packet(r8a66597, td);
1194 printk(KERN_ERR "r8a66597: invalid type.\n");
1201 static int check_transfer_finish(struct r8a66597_td *td, struct urb *urb)
1203 if (usb_pipeisoc(urb->pipe)) {
1204 if (urb->number_of_packets == td->iso_cnt)
1208 /* control or bulk or interrupt */
1209 if ((urb->transfer_buffer_length <= urb->actual_length) ||
1210 (td->short_packet) || (td->zero_packet))
1216 /* this function must be called with interrupt disabled */
1217 static void set_td_timer(struct r8a66597 *r8a66597, struct r8a66597_td *td)
1223 if (!list_empty(&r8a66597->pipe_queue[td->pipenum]) &&
1224 !usb_pipecontrol(td->urb->pipe) && usb_pipein(td->urb->pipe)) {
1225 r8a66597->timeout_map |= 1 << td->pipenum;
1226 switch (usb_pipetype(td->urb->pipe)) {
1227 case PIPE_INTERRUPT:
1228 case PIPE_ISOCHRONOUS:
1236 mod_timer(&r8a66597->td_timer[td->pipenum],
1237 jiffies + msecs_to_jiffies(time));
1241 /* this function must be called with interrupt disabled */
1242 static void finish_request(struct r8a66597 *r8a66597, struct r8a66597_td *td,
1243 u16 pipenum, struct urb *urb, int status)
1244 __releases(r8a66597->lock) __acquires(r8a66597->lock)
1247 struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597);
1249 r8a66597->timeout_map &= ~(1 << pipenum);
1252 if (td->set_address && (status != 0 || urb->unlinked))
1253 r8a66597->address_map &= ~(1 << urb->setup_packet[2]);
1255 pipe_toggle_save(r8a66597, td->pipe, urb);
1256 list_del(&td->queue);
1260 if (!list_empty(&r8a66597->pipe_queue[pipenum]))
1264 if (usb_pipeisoc(urb->pipe))
1265 urb->start_frame = r8a66597_get_frame(hcd);
1267 usb_hcd_unlink_urb_from_ep(r8a66597_to_hcd(r8a66597), urb);
1268 spin_unlock(&r8a66597->lock);
1269 usb_hcd_giveback_urb(hcd, urb, status);
1270 spin_lock(&r8a66597->lock);
1274 td = r8a66597_get_td(r8a66597, pipenum);
1278 start_transfer(r8a66597, td);
1279 set_td_timer(r8a66597, td);
1283 static void packet_read(struct r8a66597 *r8a66597, u16 pipenum)
1286 int rcv_len, bufsize, urb_len, size;
1288 struct r8a66597_td *td = r8a66597_get_td(r8a66597, pipenum);
1297 fifo_change_from_pipe(r8a66597, td->pipe);
1298 tmp = r8a66597_read(r8a66597, td->pipe->fifoctr);
1299 if (unlikely((tmp & FRDY) == 0)) {
1300 pipe_stop(r8a66597, td->pipe);
1301 pipe_irq_disable(r8a66597, pipenum);
1302 printk(KERN_ERR "r8a66597: in fifo not ready (%d)\n", pipenum);
1303 finish_request(r8a66597, td, pipenum, td->urb, -EPIPE);
1307 /* prepare parameters */
1308 rcv_len = tmp & DTLN;
1309 if (usb_pipeisoc(urb->pipe)) {
1310 buf = (u16 *)(urb->transfer_buffer +
1311 urb->iso_frame_desc[td->iso_cnt].offset);
1312 urb_len = urb->iso_frame_desc[td->iso_cnt].length;
1314 buf = (void *)urb->transfer_buffer + urb->actual_length;
1315 urb_len = urb->transfer_buffer_length - urb->actual_length;
1317 bufsize = min(urb_len, (int) td->maxpacket);
1318 if (rcv_len <= bufsize) {
1322 status = -EOVERFLOW;
1326 /* update parameters */
1327 urb->actual_length += size;
1329 td->zero_packet = 1;
1330 if (rcv_len < bufsize) {
1331 td->short_packet = 1;
1333 if (usb_pipeisoc(urb->pipe)) {
1334 urb->iso_frame_desc[td->iso_cnt].actual_length = size;
1335 urb->iso_frame_desc[td->iso_cnt].status = status;
1340 /* check transfer finish */
1341 if (finish || check_transfer_finish(td, urb)) {
1342 pipe_stop(r8a66597, td->pipe);
1343 pipe_irq_disable(r8a66597, pipenum);
1348 if (urb->transfer_buffer) {
1350 r8a66597_write(r8a66597, BCLR, td->pipe->fifoctr);
1352 r8a66597_read_fifo(r8a66597, td->pipe->fifoaddr,
1356 if (finish && pipenum != 0)
1357 finish_request(r8a66597, td, pipenum, urb, status);
1360 static void packet_write(struct r8a66597 *r8a66597, u16 pipenum)
1365 struct r8a66597_td *td = r8a66597_get_td(r8a66597, pipenum);
1372 fifo_change_from_pipe(r8a66597, td->pipe);
1373 tmp = r8a66597_read(r8a66597, td->pipe->fifoctr);
1374 if (unlikely((tmp & FRDY) == 0)) {
1375 pipe_stop(r8a66597, td->pipe);
1376 pipe_irq_disable(r8a66597, pipenum);
1377 printk(KERN_ERR "r8a66597: out fifo not ready (%d)\n", pipenum);
1378 finish_request(r8a66597, td, pipenum, urb, -EPIPE);
1382 /* prepare parameters */
1383 bufsize = td->maxpacket;
1384 if (usb_pipeisoc(urb->pipe)) {
1385 buf = (u16 *)(urb->transfer_buffer +
1386 urb->iso_frame_desc[td->iso_cnt].offset);
1388 (int)urb->iso_frame_desc[td->iso_cnt].length);
1390 buf = (u16 *)(urb->transfer_buffer + urb->actual_length);
1391 size = min((int)bufsize,
1392 urb->transfer_buffer_length - urb->actual_length);
1397 r8a66597_write(r8a66597, ~(1 << pipenum), BEMPSTS);
1398 if (urb->transfer_buffer) {
1399 r8a66597_write_fifo(r8a66597, td->pipe->fifoaddr, buf, size);
1400 if (!usb_pipebulk(urb->pipe) || td->maxpacket != size)
1401 r8a66597_write(r8a66597, BVAL, td->pipe->fifoctr);
1404 /* update parameters */
1405 urb->actual_length += size;
1406 if (usb_pipeisoc(urb->pipe)) {
1407 urb->iso_frame_desc[td->iso_cnt].actual_length = size;
1408 urb->iso_frame_desc[td->iso_cnt].status = 0;
1412 /* check transfer finish */
1413 if (check_transfer_finish(td, urb)) {
1414 disable_irq_ready(r8a66597, pipenum);
1415 enable_irq_empty(r8a66597, pipenum);
1416 if (!usb_pipeisoc(urb->pipe))
1417 enable_irq_nrdy(r8a66597, pipenum);
1419 pipe_irq_enable(r8a66597, urb, pipenum);
1423 static void check_next_phase(struct r8a66597 *r8a66597, int status)
1425 struct r8a66597_td *td = r8a66597_get_td(r8a66597, 0);
1436 if (check_transfer_finish(td, urb))
1437 td->type = USB_PID_ACK;
1440 if (urb->transfer_buffer_length == urb->actual_length)
1441 td->type = USB_PID_ACK;
1442 else if (usb_pipeout(urb->pipe))
1443 td->type = USB_PID_OUT;
1445 td->type = USB_PID_IN;
1452 if (finish || status != 0 || urb->unlinked)
1453 finish_request(r8a66597, td, 0, urb, status);
1455 start_transfer(r8a66597, td);
1458 static int get_urb_error(struct r8a66597 *r8a66597, u16 pipenum)
1460 struct r8a66597_td *td = r8a66597_get_td(r8a66597, pipenum);
1463 u16 pid = r8a66597_read(r8a66597, td->pipe->pipectr) & PID;
1473 static void irq_pipe_ready(struct r8a66597 *r8a66597)
1478 struct r8a66597_td *td;
1480 mask = r8a66597_read(r8a66597, BRDYSTS)
1481 & r8a66597_read(r8a66597, BRDYENB);
1482 r8a66597_write(r8a66597, ~mask, BRDYSTS);
1484 td = r8a66597_get_td(r8a66597, 0);
1485 if (td && td->type == USB_PID_IN)
1486 packet_read(r8a66597, 0);
1488 pipe_irq_disable(r8a66597, 0);
1489 check_next_phase(r8a66597, 0);
1492 for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
1493 check = 1 << pipenum;
1495 td = r8a66597_get_td(r8a66597, pipenum);
1499 if (td->type == USB_PID_IN)
1500 packet_read(r8a66597, pipenum);
1501 else if (td->type == USB_PID_OUT)
1502 packet_write(r8a66597, pipenum);
1507 static void irq_pipe_empty(struct r8a66597 *r8a66597)
1513 struct r8a66597_td *td;
1515 mask = r8a66597_read(r8a66597, BEMPSTS)
1516 & r8a66597_read(r8a66597, BEMPENB);
1517 r8a66597_write(r8a66597, ~mask, BEMPSTS);
1519 cfifo_change(r8a66597, 0);
1520 td = r8a66597_get_td(r8a66597, 0);
1521 if (td && td->type != USB_PID_OUT)
1522 disable_irq_empty(r8a66597, 0);
1523 check_next_phase(r8a66597, 0);
1526 for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
1527 check = 1 << pipenum;
1529 struct r8a66597_td *td;
1530 td = r8a66597_get_td(r8a66597, pipenum);
1534 tmp = r8a66597_read(r8a66597, td->pipe->pipectr);
1535 if ((tmp & INBUFM) == 0) {
1536 disable_irq_empty(r8a66597, pipenum);
1537 pipe_irq_disable(r8a66597, pipenum);
1538 finish_request(r8a66597, td, pipenum, td->urb,
1545 static void irq_pipe_nrdy(struct r8a66597 *r8a66597)
1552 mask = r8a66597_read(r8a66597, NRDYSTS)
1553 & r8a66597_read(r8a66597, NRDYENB);
1554 r8a66597_write(r8a66597, ~mask, NRDYSTS);
1556 cfifo_change(r8a66597, 0);
1557 status = get_urb_error(r8a66597, 0);
1558 pipe_irq_disable(r8a66597, 0);
1559 check_next_phase(r8a66597, status);
1562 for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
1563 check = 1 << pipenum;
1565 struct r8a66597_td *td;
1566 td = r8a66597_get_td(r8a66597, pipenum);
1570 status = get_urb_error(r8a66597, pipenum);
1571 pipe_irq_disable(r8a66597, pipenum);
1572 pipe_stop(r8a66597, td->pipe);
1573 finish_request(r8a66597, td, pipenum, td->urb, status);
1578 static irqreturn_t r8a66597_irq(struct usb_hcd *hcd)
1580 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
1581 u16 intsts0, intsts1, intsts2;
1582 u16 intenb0, intenb1, intenb2;
1583 u16 mask0, mask1, mask2;
1586 spin_lock(&r8a66597->lock);
1588 intsts0 = r8a66597_read(r8a66597, INTSTS0);
1589 intsts1 = r8a66597_read(r8a66597, INTSTS1);
1590 intsts2 = r8a66597_read(r8a66597, INTSTS2);
1591 intenb0 = r8a66597_read(r8a66597, INTENB0);
1592 intenb1 = r8a66597_read(r8a66597, INTENB1);
1593 intenb2 = r8a66597_read(r8a66597, INTENB2);
1595 mask2 = intsts2 & intenb2;
1596 mask1 = intsts1 & intenb1;
1597 mask0 = intsts0 & intenb0 & (BEMP | NRDY | BRDY);
1599 if (mask2 & ATTCH) {
1600 r8a66597_write(r8a66597, ~ATTCH, INTSTS2);
1601 r8a66597_bclr(r8a66597, ATTCHE, INTENB2);
1603 /* start usb bus sampling */
1604 start_root_hub_sampling(r8a66597, 1, 1);
1607 r8a66597_write(r8a66597, ~DTCH, INTSTS2);
1608 r8a66597_bclr(r8a66597, DTCHE, INTENB2);
1609 r8a66597_usb_disconnect(r8a66597, 1);
1614 if (mask1 & ATTCH) {
1615 r8a66597_write(r8a66597, ~ATTCH, INTSTS1);
1616 r8a66597_bclr(r8a66597, ATTCHE, INTENB1);
1618 /* start usb bus sampling */
1619 start_root_hub_sampling(r8a66597, 0, 1);
1622 r8a66597_write(r8a66597, ~DTCH, INTSTS1);
1623 r8a66597_bclr(r8a66597, DTCHE, INTENB1);
1624 r8a66597_usb_disconnect(r8a66597, 0);
1627 r8a66597_write(r8a66597, ~SIGN, INTSTS1);
1628 status = get_urb_error(r8a66597, 0);
1629 check_next_phase(r8a66597, status);
1632 r8a66597_write(r8a66597, ~SACK, INTSTS1);
1633 check_next_phase(r8a66597, 0);
1638 irq_pipe_ready(r8a66597);
1640 irq_pipe_empty(r8a66597);
1642 irq_pipe_nrdy(r8a66597);
1645 spin_unlock(&r8a66597->lock);
1649 /* this function must be called with interrupt disabled */
1650 static void r8a66597_root_hub_control(struct r8a66597 *r8a66597, int port)
1653 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
1655 if (rh->port & (1 << USB_PORT_FEAT_RESET)) {
1656 unsigned long dvstctr_reg = get_dvstctr_reg(port);
1658 tmp = r8a66597_read(r8a66597, dvstctr_reg);
1659 if ((tmp & USBRST) == USBRST) {
1660 r8a66597_mdfy(r8a66597, UACT, USBRST | UACT,
1662 r8a66597_root_hub_start_polling(r8a66597);
1664 r8a66597_usb_connect(r8a66597, port);
1667 if (!(rh->port & (1 << USB_PORT_FEAT_CONNECTION))) {
1668 r8a66597_write(r8a66597, ~ATTCH, get_intsts_reg(port));
1669 r8a66597_bset(r8a66597, ATTCHE, get_intenb_reg(port));
1672 if (rh->scount > 0) {
1673 tmp = r8a66597_read(r8a66597, get_syssts_reg(port)) & LNST;
1674 if (tmp == rh->old_syssts) {
1676 if (rh->scount == 0)
1677 r8a66597_check_syssts(r8a66597, port, tmp);
1679 r8a66597_root_hub_start_polling(r8a66597);
1681 rh->scount = R8A66597_MAX_SAMPLING;
1682 rh->old_syssts = tmp;
1683 r8a66597_root_hub_start_polling(r8a66597);
1688 static void r8a66597_interval_timer(unsigned long _r8a66597)
1690 struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597;
1691 unsigned long flags;
1693 struct r8a66597_td *td;
1695 spin_lock_irqsave(&r8a66597->lock, flags);
1697 for (pipenum = 0; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
1698 if (!(r8a66597->interval_map & (1 << pipenum)))
1700 if (timer_pending(&r8a66597->interval_timer[pipenum]))
1703 td = r8a66597_get_td(r8a66597, pipenum);
1705 start_transfer(r8a66597, td);
1708 spin_unlock_irqrestore(&r8a66597->lock, flags);
1711 static void r8a66597_td_timer(unsigned long _r8a66597)
1713 struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597;
1714 unsigned long flags;
1716 struct r8a66597_td *td, *new_td = NULL;
1717 struct r8a66597_pipe *pipe;
1719 spin_lock_irqsave(&r8a66597->lock, flags);
1720 for (pipenum = 0; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) {
1721 if (!(r8a66597->timeout_map & (1 << pipenum)))
1723 if (timer_pending(&r8a66597->td_timer[pipenum]))
1726 td = r8a66597_get_td(r8a66597, pipenum);
1728 r8a66597->timeout_map &= ~(1 << pipenum);
1732 if (td->urb->actual_length) {
1733 set_td_timer(r8a66597, td);
1738 pipe_stop(r8a66597, pipe);
1742 list_move_tail(&new_td->queue,
1743 &r8a66597->pipe_queue[pipenum]);
1744 new_td = r8a66597_get_td(r8a66597, pipenum);
1749 } while (td != new_td && td->address == new_td->address);
1751 start_transfer(r8a66597, new_td);
1754 r8a66597->timeout_map &= ~(1 << pipenum);
1756 set_td_timer(r8a66597, new_td);
1759 spin_unlock_irqrestore(&r8a66597->lock, flags);
1762 static void r8a66597_timer(unsigned long _r8a66597)
1764 struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597;
1765 unsigned long flags;
1767 spin_lock_irqsave(&r8a66597->lock, flags);
1769 r8a66597_root_hub_control(r8a66597, 0);
1770 r8a66597_root_hub_control(r8a66597, 1);
1772 spin_unlock_irqrestore(&r8a66597->lock, flags);
1775 static int check_pipe_config(struct r8a66597 *r8a66597, struct urb *urb)
1777 struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb);
1779 if (dev && dev->address && dev->state != USB_STATE_CONFIGURED &&
1780 (urb->dev->state == USB_STATE_CONFIGURED))
1786 static int r8a66597_start(struct usb_hcd *hcd)
1788 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
1790 hcd->state = HC_STATE_RUNNING;
1791 return enable_controller(r8a66597);
1794 static void r8a66597_stop(struct usb_hcd *hcd)
1796 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
1798 disable_controller(r8a66597);
1801 static void set_address_zero(struct r8a66597 *r8a66597, struct urb *urb)
1803 unsigned int usb_address = usb_pipedevice(urb->pipe);
1804 u16 root_port, hub_port;
1806 if (usb_address == 0) {
1807 get_port_number(urb->dev->devpath,
1808 &root_port, &hub_port);
1809 set_devadd_reg(r8a66597, 0,
1810 get_r8a66597_usb_speed(urb->dev->speed),
1811 get_parent_r8a66597_address(r8a66597, urb->dev),
1812 hub_port, root_port);
1816 static struct r8a66597_td *r8a66597_make_td(struct r8a66597 *r8a66597,
1818 struct usb_host_endpoint *hep)
1820 struct r8a66597_td *td;
1823 td = kzalloc(sizeof(struct r8a66597_td), GFP_ATOMIC);
1827 pipenum = r8a66597_get_pipenum(urb, hep);
1828 td->pipenum = pipenum;
1829 td->pipe = hep->hcpriv;
1831 td->address = get_urb_to_r8a66597_addr(r8a66597, urb);
1832 td->maxpacket = usb_maxpacket(urb->dev, urb->pipe,
1833 !usb_pipein(urb->pipe));
1834 if (usb_pipecontrol(urb->pipe))
1835 td->type = USB_PID_SETUP;
1836 else if (usb_pipein(urb->pipe))
1837 td->type = USB_PID_IN;
1839 td->type = USB_PID_OUT;
1840 INIT_LIST_HEAD(&td->queue);
1845 static int r8a66597_urb_enqueue(struct usb_hcd *hcd,
1849 struct usb_host_endpoint *hep = urb->ep;
1850 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
1851 struct r8a66597_td *td = NULL;
1852 int ret, request = 0;
1853 unsigned long flags;
1855 spin_lock_irqsave(&r8a66597->lock, flags);
1856 if (!get_urb_to_r8a66597_dev(r8a66597, urb)) {
1858 goto error_not_linked;
1861 ret = usb_hcd_link_urb_to_ep(hcd, urb);
1863 goto error_not_linked;
1866 hep->hcpriv = kzalloc(sizeof(struct r8a66597_pipe),
1872 set_pipe_reg_addr(hep->hcpriv, R8A66597_PIPE_NO_DMA);
1873 if (usb_pipeendpoint(urb->pipe))
1874 init_pipe_info(r8a66597, urb, hep, &hep->desc);
1877 if (unlikely(check_pipe_config(r8a66597, urb)))
1878 init_pipe_config(r8a66597, urb);
1880 set_address_zero(r8a66597, urb);
1881 td = r8a66597_make_td(r8a66597, urb, hep);
1886 if (list_empty(&r8a66597->pipe_queue[td->pipenum]))
1888 list_add_tail(&td->queue, &r8a66597->pipe_queue[td->pipenum]);
1892 if (td->pipe->info.timer_interval) {
1893 r8a66597->interval_map |= 1 << td->pipenum;
1894 mod_timer(&r8a66597->interval_timer[td->pipenum],
1895 jiffies + msecs_to_jiffies(
1896 td->pipe->info.timer_interval));
1898 ret = start_transfer(r8a66597, td);
1900 list_del(&td->queue);
1905 set_td_timer(r8a66597, td);
1909 usb_hcd_unlink_urb_from_ep(hcd, urb);
1911 spin_unlock_irqrestore(&r8a66597->lock, flags);
1915 static int r8a66597_urb_dequeue(struct usb_hcd *hcd, struct urb *urb,
1918 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
1919 struct r8a66597_td *td;
1920 unsigned long flags;
1923 spin_lock_irqsave(&r8a66597->lock, flags);
1924 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
1930 pipe_stop(r8a66597, td->pipe);
1931 pipe_irq_disable(r8a66597, td->pipenum);
1932 disable_irq_empty(r8a66597, td->pipenum);
1933 finish_request(r8a66597, td, td->pipenum, urb, status);
1936 spin_unlock_irqrestore(&r8a66597->lock, flags);
1940 static void r8a66597_endpoint_disable(struct usb_hcd *hcd,
1941 struct usb_host_endpoint *hep)
1943 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
1944 struct r8a66597_pipe *pipe = (struct r8a66597_pipe *)hep->hcpriv;
1945 struct r8a66597_td *td;
1946 struct urb *urb = NULL;
1948 unsigned long flags;
1952 pipenum = pipe->info.pipenum;
1960 spin_lock_irqsave(&r8a66597->lock, flags);
1961 pipe_stop(r8a66597, pipe);
1962 pipe_irq_disable(r8a66597, pipenum);
1963 disable_irq_empty(r8a66597, pipenum);
1964 td = r8a66597_get_td(r8a66597, pipenum);
1967 finish_request(r8a66597, td, pipenum, urb, -ESHUTDOWN);
1970 spin_unlock_irqrestore(&r8a66597->lock, flags);
1973 static int r8a66597_get_frame(struct usb_hcd *hcd)
1975 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
1976 return r8a66597_read(r8a66597, FRMNUM) & 0x03FF;
1979 static void collect_usb_address_map(struct usb_device *udev, unsigned long *map)
1983 if (udev->state == USB_STATE_CONFIGURED &&
1984 udev->parent && udev->parent->devnum > 1 &&
1985 udev->parent->descriptor.bDeviceClass == USB_CLASS_HUB)
1986 map[udev->devnum/32] |= (1 << (udev->devnum % 32));
1988 for (chix = 0; chix < udev->maxchild; chix++) {
1989 struct usb_device *childdev = udev->children[chix];
1992 collect_usb_address_map(childdev, map);
1996 /* this function must be called with interrupt disabled */
1997 static struct r8a66597_device *get_r8a66597_device(struct r8a66597 *r8a66597,
2000 struct r8a66597_device *dev;
2001 struct list_head *list = &r8a66597->child_device;
2003 list_for_each_entry(dev, list, device_list) {
2006 if (dev->usb_address != addr)
2012 printk(KERN_ERR "r8a66597: get_r8a66597_device fail.(%d)\n", addr);
2016 static void update_usb_address_map(struct r8a66597 *r8a66597,
2017 struct usb_device *root_hub,
2022 unsigned long flags;
2024 for (i = 0; i < 4; i++) {
2025 diff = r8a66597->child_connect_map[i] ^ map[i];
2029 for (j = 0; j < 32; j++) {
2030 if (!(diff & (1 << j)))
2034 if (map[i] & (1 << j))
2035 set_child_connect_map(r8a66597, addr);
2037 struct r8a66597_device *dev;
2039 spin_lock_irqsave(&r8a66597->lock, flags);
2040 dev = get_r8a66597_device(r8a66597, addr);
2041 disable_r8a66597_pipe_all(r8a66597, dev);
2042 free_usb_address(r8a66597, dev);
2043 put_child_connect_map(r8a66597, addr);
2044 spin_unlock_irqrestore(&r8a66597->lock, flags);
2050 static void r8a66597_check_detect_child(struct r8a66597 *r8a66597,
2051 struct usb_hcd *hcd)
2053 struct usb_bus *bus;
2054 unsigned long now_map[4];
2056 memset(now_map, 0, sizeof(now_map));
2058 list_for_each_entry(bus, &usb_bus_list, bus_list) {
2062 if (bus->busnum != hcd->self.busnum)
2065 collect_usb_address_map(bus->root_hub, now_map);
2066 update_usb_address_map(r8a66597, bus->root_hub, now_map);
2070 static int r8a66597_hub_status_data(struct usb_hcd *hcd, char *buf)
2072 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
2073 unsigned long flags;
2076 r8a66597_check_detect_child(r8a66597, hcd);
2078 spin_lock_irqsave(&r8a66597->lock, flags);
2080 *buf = 0; /* initialize (no change) */
2082 for (i = 0; i < R8A66597_MAX_ROOT_HUB; i++) {
2083 if (r8a66597->root_hub[i].port & 0xffff0000)
2084 *buf |= 1 << (i + 1);
2087 spin_unlock_irqrestore(&r8a66597->lock, flags);
2092 static void r8a66597_hub_descriptor(struct r8a66597 *r8a66597,
2093 struct usb_hub_descriptor *desc)
2095 desc->bDescriptorType = 0x29;
2096 desc->bHubContrCurrent = 0;
2097 desc->bNbrPorts = R8A66597_MAX_ROOT_HUB;
2098 desc->bDescLength = 9;
2099 desc->bPwrOn2PwrGood = 0;
2100 desc->wHubCharacteristics = cpu_to_le16(0x0011);
2101 desc->bitmap[0] = ((1 << R8A66597_MAX_ROOT_HUB) - 1) << 1;
2102 desc->bitmap[1] = ~0;
2105 static int r8a66597_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2106 u16 wIndex, char *buf, u16 wLength)
2108 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
2110 int port = (wIndex & 0x00FF) - 1;
2111 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
2112 unsigned long flags;
2116 spin_lock_irqsave(&r8a66597->lock, flags);
2118 case ClearHubFeature:
2121 case C_HUB_OVER_CURRENT:
2122 case C_HUB_LOCAL_POWER:
2128 case ClearPortFeature:
2129 if (wIndex > R8A66597_MAX_ROOT_HUB)
2135 case USB_PORT_FEAT_ENABLE:
2136 rh->port &= (1 << USB_PORT_FEAT_POWER);
2138 case USB_PORT_FEAT_SUSPEND:
2140 case USB_PORT_FEAT_POWER:
2141 r8a66597_port_power(r8a66597, port, 0);
2143 case USB_PORT_FEAT_C_ENABLE:
2144 case USB_PORT_FEAT_C_SUSPEND:
2145 case USB_PORT_FEAT_C_CONNECTION:
2146 case USB_PORT_FEAT_C_OVER_CURRENT:
2147 case USB_PORT_FEAT_C_RESET:
2152 rh->port &= ~(1 << wValue);
2154 case GetHubDescriptor:
2155 r8a66597_hub_descriptor(r8a66597,
2156 (struct usb_hub_descriptor *)buf);
2162 if (wIndex > R8A66597_MAX_ROOT_HUB)
2164 *(__le32 *)buf = cpu_to_le32(rh->port);
2166 case SetPortFeature:
2167 if (wIndex > R8A66597_MAX_ROOT_HUB)
2173 case USB_PORT_FEAT_SUSPEND:
2175 case USB_PORT_FEAT_POWER:
2176 r8a66597_port_power(r8a66597, port, 1);
2177 rh->port |= (1 << USB_PORT_FEAT_POWER);
2179 case USB_PORT_FEAT_RESET: {
2180 struct r8a66597_device *dev = rh->dev;
2182 rh->port |= (1 << USB_PORT_FEAT_RESET);
2184 disable_r8a66597_pipe_all(r8a66597, dev);
2185 free_usb_address(r8a66597, dev);
2187 r8a66597_mdfy(r8a66597, USBRST, USBRST | UACT,
2188 get_dvstctr_reg(port));
2189 mod_timer(&r8a66597->rh_timer,
2190 jiffies + msecs_to_jiffies(50));
2196 rh->port |= 1 << wValue;
2204 spin_unlock_irqrestore(&r8a66597->lock, flags);
2208 static struct hc_driver r8a66597_hc_driver = {
2209 .description = hcd_name,
2210 .hcd_priv_size = sizeof(struct r8a66597),
2211 .irq = r8a66597_irq,
2214 * generic hardware linkage
2218 .start = r8a66597_start,
2219 .stop = r8a66597_stop,
2222 * managing i/o requests and associated device resources
2224 .urb_enqueue = r8a66597_urb_enqueue,
2225 .urb_dequeue = r8a66597_urb_dequeue,
2226 .endpoint_disable = r8a66597_endpoint_disable,
2229 * periodic schedule support
2231 .get_frame_number = r8a66597_get_frame,
2236 .hub_status_data = r8a66597_hub_status_data,
2237 .hub_control = r8a66597_hub_control,
2240 #if defined(CONFIG_PM)
2241 static int r8a66597_suspend(struct platform_device *pdev, pm_message_t state)
2246 static int r8a66597_resume(struct platform_device *pdev)
2250 #else /* if defined(CONFIG_PM) */
2251 #define r8a66597_suspend NULL
2252 #define r8a66597_resume NULL
2255 static int __init_or_module r8a66597_remove(struct platform_device *pdev)
2257 struct r8a66597 *r8a66597 = dev_get_drvdata(&pdev->dev);
2258 struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597);
2260 del_timer_sync(&r8a66597->rh_timer);
2261 usb_remove_hcd(hcd);
2262 iounmap((void *)r8a66597->reg);
2267 #define resource_len(r) (((r)->end - (r)->start) + 1)
2268 static int __init r8a66597_probe(struct platform_device *pdev)
2270 struct resource *res = NULL, *ires;
2272 void __iomem *reg = NULL;
2273 struct usb_hcd *hcd = NULL;
2274 struct r8a66597 *r8a66597;
2277 unsigned long irq_trigger;
2279 if (pdev->dev.dma_mask) {
2281 dev_err(&pdev->dev, "dma not supported\n");
2285 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
2289 dev_err(&pdev->dev, "platform_get_resource_byname error.\n");
2293 ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
2297 "platform_get_resource IORESOURCE_IRQ error.\n");
2302 irq_trigger = ires->flags & IRQF_TRIGGER_MASK;
2304 reg = ioremap(res->start, resource_len(res));
2307 dev_err(&pdev->dev, "ioremap error.\n");
2311 /* initialize hcd */
2312 hcd = usb_create_hcd(&r8a66597_hc_driver, &pdev->dev, (char *)hcd_name);
2315 dev_err(&pdev->dev, "Failed to create hcd\n");
2318 r8a66597 = hcd_to_r8a66597(hcd);
2319 memset(r8a66597, 0, sizeof(struct r8a66597));
2320 dev_set_drvdata(&pdev->dev, r8a66597);
2322 spin_lock_init(&r8a66597->lock);
2323 init_timer(&r8a66597->rh_timer);
2324 r8a66597->rh_timer.function = r8a66597_timer;
2325 r8a66597->rh_timer.data = (unsigned long)r8a66597;
2326 r8a66597->reg = (unsigned long)reg;
2328 for (i = 0; i < R8A66597_MAX_NUM_PIPE; i++) {
2329 INIT_LIST_HEAD(&r8a66597->pipe_queue[i]);
2330 init_timer(&r8a66597->td_timer[i]);
2331 r8a66597->td_timer[i].function = r8a66597_td_timer;
2332 r8a66597->td_timer[i].data = (unsigned long)r8a66597;
2333 setup_timer(&r8a66597->interval_timer[i],
2334 r8a66597_interval_timer,
2335 (unsigned long)r8a66597);
2337 INIT_LIST_HEAD(&r8a66597->child_device);
2339 hcd->rsrc_start = res->start;
2341 /* irq_sense setting on cmdline takes precedence over resource
2342 * settings, so the introduction of irqflags in IRQ resourse
2343 * won't disturb existing setups */
2344 switch (irq_sense) {
2346 irq_trigger = IRQF_TRIGGER_LOW;
2349 irq_trigger = IRQF_TRIGGER_FALLING;
2353 irq_sense = (irq_trigger & IRQF_TRIGGER_LOW) ?
2357 irq_trigger = IRQF_TRIGGER_LOW;
2361 dev_err(&pdev->dev, "Unknown irq_sense value.\n");
2364 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | irq_trigger);
2366 dev_err(&pdev->dev, "Failed to add hcd\n");
2379 static struct platform_driver r8a66597_driver = {
2380 .probe = r8a66597_probe,
2381 .remove = r8a66597_remove,
2382 .suspend = r8a66597_suspend,
2383 .resume = r8a66597_resume,
2385 .name = (char *) hcd_name,
2386 .owner = THIS_MODULE,
2390 static int __init r8a66597_init(void)
2395 printk(KERN_INFO KBUILD_MODNAME ": driver %s, %s\n", hcd_name,
2397 return platform_driver_register(&r8a66597_driver);
2399 module_init(r8a66597_init);
2401 static void __exit r8a66597_cleanup(void)
2403 platform_driver_unregister(&r8a66597_driver);
2405 module_exit(r8a66597_cleanup);