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/errno.h>
30 #include <linux/init.h>
31 #include <linux/timer.h>
32 #include <linux/delay.h>
33 #include <linux/list.h>
34 #include <linux/interrupt.h>
35 #include <linux/usb.h>
36 #include <linux/platform_device.h>
38 #include <linux/irq.h>
40 #include "../core/hcd.h"
43 MODULE_DESCRIPTION("R8A66597 USB Host Controller Driver");
44 MODULE_LICENSE("GPL");
45 MODULE_AUTHOR("Yoshihiro Shimoda");
46 MODULE_ALIAS("platform:r8a66597_hcd");
48 #define DRIVER_VERSION "2009-05-26"
50 static const char hcd_name
[] = "r8a66597_hcd";
52 static void packet_write(struct r8a66597
*r8a66597
, u16 pipenum
);
53 static int r8a66597_get_frame(struct usb_hcd
*hcd
);
55 /* this function must be called with interrupt disabled */
56 static void enable_pipe_irq(struct r8a66597
*r8a66597
, u16 pipenum
,
61 tmp
= r8a66597_read(r8a66597
, INTENB0
);
62 r8a66597_bclr(r8a66597
, BEMPE
| NRDYE
| BRDYE
, INTENB0
);
63 r8a66597_bset(r8a66597
, 1 << pipenum
, reg
);
64 r8a66597_write(r8a66597
, tmp
, INTENB0
);
67 /* this function must be called with interrupt disabled */
68 static void disable_pipe_irq(struct r8a66597
*r8a66597
, u16 pipenum
,
73 tmp
= r8a66597_read(r8a66597
, INTENB0
);
74 r8a66597_bclr(r8a66597
, BEMPE
| NRDYE
| BRDYE
, INTENB0
);
75 r8a66597_bclr(r8a66597
, 1 << pipenum
, reg
);
76 r8a66597_write(r8a66597
, tmp
, INTENB0
);
79 static void set_devadd_reg(struct r8a66597
*r8a66597
, u8 r8a66597_address
,
80 u16 usbspd
, u8 upphub
, u8 hubport
, int port
)
83 unsigned long devadd_reg
= get_devadd_addr(r8a66597_address
);
85 val
= (upphub
<< 11) | (hubport
<< 8) | (usbspd
<< 6) | (port
& 0x0001);
86 r8a66597_write(r8a66597
, val
, devadd_reg
);
89 static int r8a66597_clock_enable(struct r8a66597
*r8a66597
)
94 #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
95 #if defined(CONFIG_HAVE_CLK)
96 clk_enable(r8a66597
->clk
);
99 r8a66597_write(r8a66597
, SCKE
, SYSCFG0
);
100 tmp
= r8a66597_read(r8a66597
, SYSCFG0
);
102 printk(KERN_ERR
"r8a66597: register access fail.\n");
105 } while ((tmp
& SCKE
) != SCKE
);
106 r8a66597_write(r8a66597
, 0x04, 0x02);
109 r8a66597_write(r8a66597
, USBE
, SYSCFG0
);
110 tmp
= r8a66597_read(r8a66597
, SYSCFG0
);
112 printk(KERN_ERR
"r8a66597: register access fail.\n");
115 } while ((tmp
& USBE
) != USBE
);
116 r8a66597_bclr(r8a66597
, USBE
, SYSCFG0
);
117 r8a66597_mdfy(r8a66597
, get_xtal_from_pdata(r8a66597
->pdata
), XTAL
,
121 r8a66597_bset(r8a66597
, XCKE
, SYSCFG0
);
124 tmp
= r8a66597_read(r8a66597
, SYSCFG0
);
126 printk(KERN_ERR
"r8a66597: register access fail.\n");
129 } while ((tmp
& SCKE
) != SCKE
);
130 #endif /* #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) */
135 static void r8a66597_clock_disable(struct r8a66597
*r8a66597
)
137 r8a66597_bclr(r8a66597
, SCKE
, SYSCFG0
);
139 #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
140 #if defined(CONFIG_HAVE_CLK)
141 clk_disable(r8a66597
->clk
);
144 r8a66597_bclr(r8a66597
, PLLC
, SYSCFG0
);
145 r8a66597_bclr(r8a66597
, XCKE
, SYSCFG0
);
146 r8a66597_bclr(r8a66597
, USBE
, SYSCFG0
);
150 static void r8a66597_enable_port(struct r8a66597
*r8a66597
, int port
)
154 val
= port
? DRPD
: DCFM
| DRPD
;
155 r8a66597_bset(r8a66597
, val
, get_syscfg_reg(port
));
156 r8a66597_bset(r8a66597
, HSE
, get_syscfg_reg(port
));
158 r8a66597_write(r8a66597
, BURST
| CPU_ADR_RD_WR
, get_dmacfg_reg(port
));
159 r8a66597_bclr(r8a66597
, DTCHE
, get_intenb_reg(port
));
160 r8a66597_bset(r8a66597
, ATTCHE
, get_intenb_reg(port
));
163 static void r8a66597_disable_port(struct r8a66597
*r8a66597
, int port
)
167 r8a66597_write(r8a66597
, 0, get_intenb_reg(port
));
168 r8a66597_write(r8a66597
, 0, get_intsts_reg(port
));
170 r8a66597_port_power(r8a66597
, port
, 0);
173 tmp
= r8a66597_read(r8a66597
, SOFCFG
) & EDGESTS
;
175 } while (tmp
== EDGESTS
);
177 val
= port
? DRPD
: DCFM
| DRPD
;
178 r8a66597_bclr(r8a66597
, val
, get_syscfg_reg(port
));
179 r8a66597_bclr(r8a66597
, HSE
, get_syscfg_reg(port
));
182 static int enable_controller(struct r8a66597
*r8a66597
)
185 u16 vif
= r8a66597
->pdata
->vif
? LDRV
: 0;
186 u16 irq_sense
= r8a66597
->irq_sense_low
? INTL
: 0;
187 u16 endian
= r8a66597
->pdata
->endian
? BIGEND
: 0;
189 ret
= r8a66597_clock_enable(r8a66597
);
193 r8a66597_bset(r8a66597
, vif
& LDRV
, PINCFG
);
194 r8a66597_bset(r8a66597
, USBE
, SYSCFG0
);
196 r8a66597_bset(r8a66597
, BEMPE
| NRDYE
| BRDYE
, INTENB0
);
197 r8a66597_bset(r8a66597
, irq_sense
& INTL
, SOFCFG
);
198 r8a66597_bset(r8a66597
, BRDY0
, BRDYENB
);
199 r8a66597_bset(r8a66597
, BEMP0
, BEMPENB
);
201 r8a66597_bset(r8a66597
, endian
& BIGEND
, CFIFOSEL
);
202 r8a66597_bset(r8a66597
, endian
& BIGEND
, D0FIFOSEL
);
203 r8a66597_bset(r8a66597
, endian
& BIGEND
, D1FIFOSEL
);
204 r8a66597_bset(r8a66597
, TRNENSEL
, SOFCFG
);
206 r8a66597_bset(r8a66597
, SIGNE
| SACKE
, INTENB1
);
208 for (port
= 0; port
< R8A66597_MAX_ROOT_HUB
; port
++)
209 r8a66597_enable_port(r8a66597
, port
);
214 static void disable_controller(struct r8a66597
*r8a66597
)
218 r8a66597_write(r8a66597
, 0, INTENB0
);
219 r8a66597_write(r8a66597
, 0, INTSTS0
);
221 for (port
= 0; port
< R8A66597_MAX_ROOT_HUB
; port
++)
222 r8a66597_disable_port(r8a66597
, port
);
224 r8a66597_clock_disable(r8a66597
);
227 static int get_parent_r8a66597_address(struct r8a66597
*r8a66597
,
228 struct usb_device
*udev
)
230 struct r8a66597_device
*dev
;
232 if (udev
->parent
&& udev
->parent
->devnum
!= 1)
235 dev
= dev_get_drvdata(&udev
->dev
);
242 static int is_child_device(char *devpath
)
244 return (devpath
[2] ? 1 : 0);
247 static int is_hub_limit(char *devpath
)
249 return ((strlen(devpath
) >= 4) ? 1 : 0);
252 static void get_port_number(char *devpath
, u16
*root_port
, u16
*hub_port
)
255 *root_port
= (devpath
[0] & 0x0F) - 1;
256 if (*root_port
>= R8A66597_MAX_ROOT_HUB
)
257 printk(KERN_ERR
"r8a66597: Illegal root port number.\n");
260 *hub_port
= devpath
[2] & 0x0F;
263 static u16
get_r8a66597_usb_speed(enum usb_device_speed speed
)
278 printk(KERN_ERR
"r8a66597: unknown speed\n");
285 static void set_child_connect_map(struct r8a66597
*r8a66597
, int address
)
290 r8a66597
->child_connect_map
[idx
] |= 1 << (address
% 32);
293 static void put_child_connect_map(struct r8a66597
*r8a66597
, int address
)
298 r8a66597
->child_connect_map
[idx
] &= ~(1 << (address
% 32));
301 static void set_pipe_reg_addr(struct r8a66597_pipe
*pipe
, u8 dma_ch
)
303 u16 pipenum
= pipe
->info
.pipenum
;
304 const unsigned long fifoaddr
[] = {D0FIFO
, D1FIFO
, CFIFO
};
305 const unsigned long fifosel
[] = {D0FIFOSEL
, D1FIFOSEL
, CFIFOSEL
};
306 const unsigned long fifoctr
[] = {D0FIFOCTR
, D1FIFOCTR
, CFIFOCTR
};
308 if (dma_ch
> R8A66597_PIPE_NO_DMA
) /* dma fifo not use? */
309 dma_ch
= R8A66597_PIPE_NO_DMA
;
311 pipe
->fifoaddr
= fifoaddr
[dma_ch
];
312 pipe
->fifosel
= fifosel
[dma_ch
];
313 pipe
->fifoctr
= fifoctr
[dma_ch
];
316 pipe
->pipectr
= DCPCTR
;
318 pipe
->pipectr
= get_pipectr_addr(pipenum
);
320 if (check_bulk_or_isoc(pipenum
)) {
321 pipe
->pipetre
= get_pipetre_addr(pipenum
);
322 pipe
->pipetrn
= get_pipetrn_addr(pipenum
);
329 static struct r8a66597_device
*
330 get_urb_to_r8a66597_dev(struct r8a66597
*r8a66597
, struct urb
*urb
)
332 if (usb_pipedevice(urb
->pipe
) == 0)
333 return &r8a66597
->device0
;
335 return dev_get_drvdata(&urb
->dev
->dev
);
338 static int make_r8a66597_device(struct r8a66597
*r8a66597
,
339 struct urb
*urb
, u8 addr
)
341 struct r8a66597_device
*dev
;
342 int usb_address
= urb
->setup_packet
[2]; /* urb->pipe is address 0 */
344 dev
= kzalloc(sizeof(struct r8a66597_device
), GFP_ATOMIC
);
348 dev_set_drvdata(&urb
->dev
->dev
, dev
);
349 dev
->udev
= urb
->dev
;
351 dev
->usb_address
= usb_address
;
352 dev
->state
= USB_STATE_ADDRESS
;
353 dev
->ep_in_toggle
= 0;
354 dev
->ep_out_toggle
= 0;
355 INIT_LIST_HEAD(&dev
->device_list
);
356 list_add_tail(&dev
->device_list
, &r8a66597
->child_device
);
358 get_port_number(urb
->dev
->devpath
, &dev
->root_port
, &dev
->hub_port
);
359 if (!is_child_device(urb
->dev
->devpath
))
360 r8a66597
->root_hub
[dev
->root_port
].dev
= dev
;
362 set_devadd_reg(r8a66597
, dev
->address
,
363 get_r8a66597_usb_speed(urb
->dev
->speed
),
364 get_parent_r8a66597_address(r8a66597
, urb
->dev
),
365 dev
->hub_port
, dev
->root_port
);
370 /* this function must be called with interrupt disabled */
371 static u8
alloc_usb_address(struct r8a66597
*r8a66597
, struct urb
*urb
)
373 u8 addr
; /* R8A66597's address */
374 struct r8a66597_device
*dev
;
376 if (is_hub_limit(urb
->dev
->devpath
)) {
377 dev_err(&urb
->dev
->dev
, "External hub limit reached.\n");
381 dev
= get_urb_to_r8a66597_dev(r8a66597
, urb
);
382 if (dev
&& dev
->state
>= USB_STATE_ADDRESS
)
385 for (addr
= 1; addr
<= R8A66597_MAX_DEVICE
; addr
++) {
386 if (r8a66597
->address_map
& (1 << addr
))
389 dbg("alloc_address: r8a66597_addr=%d", addr
);
390 r8a66597
->address_map
|= 1 << addr
;
392 if (make_r8a66597_device(r8a66597
, urb
, addr
) < 0)
398 dev_err(&urb
->dev
->dev
,
399 "cannot communicate with a USB device more than 10.(%x)\n",
400 r8a66597
->address_map
);
405 /* this function must be called with interrupt disabled */
406 static void free_usb_address(struct r8a66597
*r8a66597
,
407 struct r8a66597_device
*dev
)
414 dbg("free_addr: addr=%d", dev
->address
);
416 dev
->state
= USB_STATE_DEFAULT
;
417 r8a66597
->address_map
&= ~(1 << dev
->address
);
419 dev_set_drvdata(&dev
->udev
->dev
, NULL
);
420 list_del(&dev
->device_list
);
423 for (port
= 0; port
< R8A66597_MAX_ROOT_HUB
; port
++) {
424 if (r8a66597
->root_hub
[port
].dev
== dev
) {
425 r8a66597
->root_hub
[port
].dev
= NULL
;
431 static void r8a66597_reg_wait(struct r8a66597
*r8a66597
, unsigned long reg
,
438 tmp
= r8a66597_read(r8a66597
, reg
);
440 printk(KERN_ERR
"r8a66597: register%lx, loop %x "
441 "is timeout\n", reg
, loop
);
445 } while ((tmp
& mask
) != loop
);
448 /* this function must be called with interrupt disabled */
449 static void pipe_start(struct r8a66597
*r8a66597
, struct r8a66597_pipe
*pipe
)
453 tmp
= r8a66597_read(r8a66597
, pipe
->pipectr
) & PID
;
454 if ((pipe
->info
.pipenum
!= 0) & ((tmp
& PID_STALL
) != 0)) /* stall? */
455 r8a66597_mdfy(r8a66597
, PID_NAK
, PID
, pipe
->pipectr
);
456 r8a66597_mdfy(r8a66597
, PID_BUF
, PID
, pipe
->pipectr
);
459 /* this function must be called with interrupt disabled */
460 static void pipe_stop(struct r8a66597
*r8a66597
, struct r8a66597_pipe
*pipe
)
464 tmp
= r8a66597_read(r8a66597
, pipe
->pipectr
) & PID
;
465 if ((tmp
& PID_STALL11
) != PID_STALL11
) /* force stall? */
466 r8a66597_mdfy(r8a66597
, PID_STALL
, PID
, pipe
->pipectr
);
467 r8a66597_mdfy(r8a66597
, PID_NAK
, PID
, pipe
->pipectr
);
468 r8a66597_reg_wait(r8a66597
, pipe
->pipectr
, PBUSY
, 0);
471 /* this function must be called with interrupt disabled */
472 static void clear_all_buffer(struct r8a66597
*r8a66597
,
473 struct r8a66597_pipe
*pipe
)
477 if (!pipe
|| pipe
->info
.pipenum
== 0)
480 pipe_stop(r8a66597
, pipe
);
481 r8a66597_bset(r8a66597
, ACLRM
, pipe
->pipectr
);
482 tmp
= r8a66597_read(r8a66597
, pipe
->pipectr
);
483 tmp
= r8a66597_read(r8a66597
, pipe
->pipectr
);
484 tmp
= r8a66597_read(r8a66597
, pipe
->pipectr
);
485 r8a66597_bclr(r8a66597
, ACLRM
, pipe
->pipectr
);
488 /* this function must be called with interrupt disabled */
489 static void r8a66597_pipe_toggle(struct r8a66597
*r8a66597
,
490 struct r8a66597_pipe
*pipe
, int toggle
)
493 r8a66597_bset(r8a66597
, SQSET
, pipe
->pipectr
);
495 r8a66597_bset(r8a66597
, SQCLR
, pipe
->pipectr
);
498 /* this function must be called with interrupt disabled */
499 static inline void cfifo_change(struct r8a66597
*r8a66597
, u16 pipenum
)
501 r8a66597_mdfy(r8a66597
, MBW
| pipenum
, MBW
| CURPIPE
, CFIFOSEL
);
502 r8a66597_reg_wait(r8a66597
, CFIFOSEL
, CURPIPE
, pipenum
);
505 /* this function must be called with interrupt disabled */
506 static inline void fifo_change_from_pipe(struct r8a66597
*r8a66597
,
507 struct r8a66597_pipe
*pipe
)
509 cfifo_change(r8a66597
, 0);
510 r8a66597_mdfy(r8a66597
, MBW
| 0, MBW
| CURPIPE
, D0FIFOSEL
);
511 r8a66597_mdfy(r8a66597
, MBW
| 0, MBW
| CURPIPE
, D1FIFOSEL
);
513 r8a66597_mdfy(r8a66597
, MBW
| pipe
->info
.pipenum
, MBW
| CURPIPE
,
515 r8a66597_reg_wait(r8a66597
, pipe
->fifosel
, CURPIPE
, pipe
->info
.pipenum
);
518 static u16
r8a66597_get_pipenum(struct urb
*urb
, struct usb_host_endpoint
*hep
)
520 struct r8a66597_pipe
*pipe
= hep
->hcpriv
;
522 if (usb_pipeendpoint(urb
->pipe
) == 0)
525 return pipe
->info
.pipenum
;
528 static u16
get_urb_to_r8a66597_addr(struct r8a66597
*r8a66597
, struct urb
*urb
)
530 struct r8a66597_device
*dev
= get_urb_to_r8a66597_dev(r8a66597
, urb
);
532 return (usb_pipedevice(urb
->pipe
) == 0) ? 0 : dev
->address
;
535 static unsigned short *get_toggle_pointer(struct r8a66597_device
*dev
,
541 return usb_pipein(urb_pipe
) ? &dev
->ep_in_toggle
: &dev
->ep_out_toggle
;
544 /* this function must be called with interrupt disabled */
545 static void pipe_toggle_set(struct r8a66597
*r8a66597
,
546 struct r8a66597_pipe
*pipe
,
547 struct urb
*urb
, int set
)
549 struct r8a66597_device
*dev
= get_urb_to_r8a66597_dev(r8a66597
, urb
);
550 unsigned char endpoint
= usb_pipeendpoint(urb
->pipe
);
551 unsigned short *toggle
= get_toggle_pointer(dev
, urb
->pipe
);
557 *toggle
|= 1 << endpoint
;
559 *toggle
&= ~(1 << endpoint
);
562 /* this function must be called with interrupt disabled */
563 static void pipe_toggle_save(struct r8a66597
*r8a66597
,
564 struct r8a66597_pipe
*pipe
,
567 if (r8a66597_read(r8a66597
, pipe
->pipectr
) & SQMON
)
568 pipe_toggle_set(r8a66597
, pipe
, urb
, 1);
570 pipe_toggle_set(r8a66597
, pipe
, urb
, 0);
573 /* this function must be called with interrupt disabled */
574 static void pipe_toggle_restore(struct r8a66597
*r8a66597
,
575 struct r8a66597_pipe
*pipe
,
578 struct r8a66597_device
*dev
= get_urb_to_r8a66597_dev(r8a66597
, urb
);
579 unsigned char endpoint
= usb_pipeendpoint(urb
->pipe
);
580 unsigned short *toggle
= get_toggle_pointer(dev
, urb
->pipe
);
585 r8a66597_pipe_toggle(r8a66597
, pipe
, *toggle
& (1 << endpoint
));
588 /* this function must be called with interrupt disabled */
589 static void pipe_buffer_setting(struct r8a66597
*r8a66597
,
590 struct r8a66597_pipe_info
*info
)
594 if (info
->pipenum
== 0)
597 r8a66597_bset(r8a66597
, ACLRM
, get_pipectr_addr(info
->pipenum
));
598 r8a66597_bclr(r8a66597
, ACLRM
, get_pipectr_addr(info
->pipenum
));
599 r8a66597_write(r8a66597
, info
->pipenum
, PIPESEL
);
602 if (info
->type
== R8A66597_BULK
&& info
->dir_in
)
603 val
|= R8A66597_DBLB
| R8A66597_SHTNAK
;
604 val
|= info
->type
| info
->epnum
;
605 r8a66597_write(r8a66597
, val
, PIPECFG
);
607 r8a66597_write(r8a66597
, (info
->buf_bsize
<< 10) | (info
->bufnum
),
609 r8a66597_write(r8a66597
, make_devsel(info
->address
) | info
->maxpacket
,
611 r8a66597_write(r8a66597
, info
->interval
, PIPEPERI
);
614 /* this function must be called with interrupt disabled */
615 static void pipe_setting(struct r8a66597
*r8a66597
, struct r8a66597_td
*td
)
617 struct r8a66597_pipe_info
*info
;
618 struct urb
*urb
= td
->urb
;
620 if (td
->pipenum
> 0) {
621 info
= &td
->pipe
->info
;
622 cfifo_change(r8a66597
, 0);
623 pipe_buffer_setting(r8a66597
, info
);
625 if (!usb_gettoggle(urb
->dev
, usb_pipeendpoint(urb
->pipe
),
626 usb_pipeout(urb
->pipe
)) &&
627 !usb_pipecontrol(urb
->pipe
)) {
628 r8a66597_pipe_toggle(r8a66597
, td
->pipe
, 0);
629 pipe_toggle_set(r8a66597
, td
->pipe
, urb
, 0);
630 clear_all_buffer(r8a66597
, td
->pipe
);
631 usb_settoggle(urb
->dev
, usb_pipeendpoint(urb
->pipe
),
632 usb_pipeout(urb
->pipe
), 1);
634 pipe_toggle_restore(r8a66597
, td
->pipe
, urb
);
638 /* this function must be called with interrupt disabled */
639 static u16
get_empty_pipenum(struct r8a66597
*r8a66597
,
640 struct usb_endpoint_descriptor
*ep
)
642 u16 array
[R8A66597_MAX_NUM_PIPE
], i
= 0, min
;
644 memset(array
, 0, sizeof(array
));
645 switch (usb_endpoint_type(ep
)) {
646 case USB_ENDPOINT_XFER_BULK
:
647 if (usb_endpoint_dir_in(ep
))
654 case USB_ENDPOINT_XFER_INT
:
655 if (usb_endpoint_dir_in(ep
)) {
662 case USB_ENDPOINT_XFER_ISOC
:
663 if (usb_endpoint_dir_in(ep
))
669 printk(KERN_ERR
"r8a66597: Illegal type\n");
675 while (array
[i
] != 0) {
676 if (r8a66597
->pipe_cnt
[min
] > r8a66597
->pipe_cnt
[array
[i
]])
684 static u16
get_r8a66597_type(__u8 type
)
689 case USB_ENDPOINT_XFER_BULK
:
690 r8a66597_type
= R8A66597_BULK
;
692 case USB_ENDPOINT_XFER_INT
:
693 r8a66597_type
= R8A66597_INT
;
695 case USB_ENDPOINT_XFER_ISOC
:
696 r8a66597_type
= R8A66597_ISO
;
699 printk(KERN_ERR
"r8a66597: Illegal type\n");
700 r8a66597_type
= 0x0000;
704 return r8a66597_type
;
707 static u16
get_bufnum(u16 pipenum
)
713 else if (check_bulk_or_isoc(pipenum
))
714 bufnum
= 8 + (pipenum
- 1) * R8A66597_BUF_BSIZE
*2;
715 else if (check_interrupt(pipenum
))
716 bufnum
= 4 + (pipenum
- 6);
718 printk(KERN_ERR
"r8a66597: Illegal pipenum (%d)\n", pipenum
);
723 static u16
get_buf_bsize(u16 pipenum
)
729 else if (check_bulk_or_isoc(pipenum
))
730 buf_bsize
= R8A66597_BUF_BSIZE
- 1;
731 else if (check_interrupt(pipenum
))
734 printk(KERN_ERR
"r8a66597: Illegal pipenum (%d)\n", pipenum
);
739 /* this function must be called with interrupt disabled */
740 static void enable_r8a66597_pipe_dma(struct r8a66597
*r8a66597
,
741 struct r8a66597_device
*dev
,
742 struct r8a66597_pipe
*pipe
,
745 #if !defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
747 struct r8a66597_pipe_info
*info
= &pipe
->info
;
749 if ((pipe
->info
.pipenum
!= 0) && (info
->type
!= R8A66597_INT
)) {
750 for (i
= 0; i
< R8A66597_MAX_DMA_CHANNEL
; i
++) {
751 if ((r8a66597
->dma_map
& (1 << i
)) != 0)
754 dev_info(&dev
->udev
->dev
,
755 "address %d, EndpointAddress 0x%02x use "
756 "DMA FIFO\n", usb_pipedevice(urb
->pipe
),
758 USB_ENDPOINT_DIR_MASK
+ info
->epnum
761 r8a66597
->dma_map
|= 1 << i
;
762 dev
->dma_map
|= 1 << i
;
763 set_pipe_reg_addr(pipe
, i
);
765 cfifo_change(r8a66597
, 0);
766 r8a66597_mdfy(r8a66597
, MBW
| pipe
->info
.pipenum
,
767 MBW
| CURPIPE
, pipe
->fifosel
);
769 r8a66597_reg_wait(r8a66597
, pipe
->fifosel
, CURPIPE
,
771 r8a66597_bset(r8a66597
, BCLR
, pipe
->fifoctr
);
775 #endif /* #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) */
778 /* this function must be called with interrupt disabled */
779 static void enable_r8a66597_pipe(struct r8a66597
*r8a66597
, struct urb
*urb
,
780 struct usb_host_endpoint
*hep
,
781 struct r8a66597_pipe_info
*info
)
783 struct r8a66597_device
*dev
= get_urb_to_r8a66597_dev(r8a66597
, urb
);
784 struct r8a66597_pipe
*pipe
= hep
->hcpriv
;
789 set_pipe_reg_addr(pipe
, R8A66597_PIPE_NO_DMA
);
790 r8a66597
->pipe_cnt
[pipe
->info
.pipenum
]++;
791 dev
->pipe_cnt
[pipe
->info
.pipenum
]++;
793 enable_r8a66597_pipe_dma(r8a66597
, dev
, pipe
, urb
);
796 /* this function must be called with interrupt disabled */
797 static void force_dequeue(struct r8a66597
*r8a66597
, u16 pipenum
, u16 address
)
799 struct r8a66597_td
*td
, *next
;
801 struct list_head
*list
= &r8a66597
->pipe_queue
[pipenum
];
803 if (list_empty(list
))
806 list_for_each_entry_safe(td
, next
, list
, queue
) {
809 if (td
->address
!= address
)
813 list_del(&td
->queue
);
817 usb_hcd_unlink_urb_from_ep(r8a66597_to_hcd(r8a66597
),
820 spin_unlock(&r8a66597
->lock
);
821 usb_hcd_giveback_urb(r8a66597_to_hcd(r8a66597
), urb
,
823 spin_lock(&r8a66597
->lock
);
829 /* this function must be called with interrupt disabled */
830 static void disable_r8a66597_pipe_all(struct r8a66597
*r8a66597
,
831 struct r8a66597_device
*dev
)
839 for (pipenum
= 1; pipenum
< R8A66597_MAX_NUM_PIPE
; pipenum
++) {
840 if (!dev
->pipe_cnt
[pipenum
])
845 force_dequeue(r8a66597
, 0, dev
->address
);
848 r8a66597
->pipe_cnt
[pipenum
] -= dev
->pipe_cnt
[pipenum
];
849 dev
->pipe_cnt
[pipenum
] = 0;
850 force_dequeue(r8a66597
, pipenum
, dev
->address
);
855 r8a66597
->dma_map
&= ~(dev
->dma_map
);
859 static u16
get_interval(struct urb
*urb
, __u8 interval
)
864 if (urb
->dev
->speed
== USB_SPEED_HIGH
) {
868 time
= interval
? interval
- 1 : 0;
870 if (interval
> 128) {
873 /* calculate the nearest value for PIPEPERI */
874 for (i
= 0; i
< 7; i
++) {
875 if ((1 << i
) < interval
&&
876 (1 << (i
+ 1) > interval
))
885 static unsigned long get_timer_interval(struct urb
*urb
, __u8 interval
)
888 unsigned long time
= 1;
890 if (usb_pipeisoc(urb
->pipe
))
893 if (get_r8a66597_usb_speed(urb
->dev
->speed
) == HSMODE
) {
894 for (i
= 0; i
< (interval
- 1); i
++)
896 time
= time
* 125 / 1000; /* uSOF -> msec */
904 /* this function must be called with interrupt disabled */
905 static void init_pipe_info(struct r8a66597
*r8a66597
, struct urb
*urb
,
906 struct usb_host_endpoint
*hep
,
907 struct usb_endpoint_descriptor
*ep
)
909 struct r8a66597_pipe_info info
;
911 info
.pipenum
= get_empty_pipenum(r8a66597
, ep
);
912 info
.address
= get_urb_to_r8a66597_addr(r8a66597
, urb
);
913 info
.epnum
= usb_endpoint_num(ep
);
914 info
.maxpacket
= le16_to_cpu(ep
->wMaxPacketSize
);
915 info
.type
= get_r8a66597_type(usb_endpoint_type(ep
));
916 info
.bufnum
= get_bufnum(info
.pipenum
);
917 info
.buf_bsize
= get_buf_bsize(info
.pipenum
);
918 if (info
.type
== R8A66597_BULK
) {
920 info
.timer_interval
= 0;
922 info
.interval
= get_interval(urb
, ep
->bInterval
);
923 info
.timer_interval
= get_timer_interval(urb
, ep
->bInterval
);
925 if (usb_endpoint_dir_in(ep
))
930 enable_r8a66597_pipe(r8a66597
, urb
, hep
, &info
);
933 static void init_pipe_config(struct r8a66597
*r8a66597
, struct urb
*urb
)
935 struct r8a66597_device
*dev
;
937 dev
= get_urb_to_r8a66597_dev(r8a66597
, urb
);
938 dev
->state
= USB_STATE_CONFIGURED
;
941 static void pipe_irq_enable(struct r8a66597
*r8a66597
, struct urb
*urb
,
944 if (pipenum
== 0 && usb_pipeout(urb
->pipe
))
945 enable_irq_empty(r8a66597
, pipenum
);
947 enable_irq_ready(r8a66597
, pipenum
);
949 if (!usb_pipeisoc(urb
->pipe
))
950 enable_irq_nrdy(r8a66597
, pipenum
);
953 static void pipe_irq_disable(struct r8a66597
*r8a66597
, u16 pipenum
)
955 disable_irq_ready(r8a66597
, pipenum
);
956 disable_irq_nrdy(r8a66597
, pipenum
);
959 static void r8a66597_root_hub_start_polling(struct r8a66597
*r8a66597
)
961 mod_timer(&r8a66597
->rh_timer
,
962 jiffies
+ msecs_to_jiffies(R8A66597_RH_POLL_TIME
));
965 static void start_root_hub_sampling(struct r8a66597
*r8a66597
, int port
,
968 struct r8a66597_root_hub
*rh
= &r8a66597
->root_hub
[port
];
970 rh
->old_syssts
= r8a66597_read(r8a66597
, get_syssts_reg(port
)) & LNST
;
971 rh
->scount
= R8A66597_MAX_SAMPLING
;
973 rh
->port
|= 1 << USB_PORT_FEAT_CONNECTION
;
975 rh
->port
&= ~(1 << USB_PORT_FEAT_CONNECTION
);
976 rh
->port
|= 1 << USB_PORT_FEAT_C_CONNECTION
;
978 r8a66597_root_hub_start_polling(r8a66597
);
981 /* this function must be called with interrupt disabled */
982 static void r8a66597_check_syssts(struct r8a66597
*r8a66597
, int port
,
986 r8a66597_write(r8a66597
, ~ATTCH
, get_intsts_reg(port
));
987 r8a66597_bset(r8a66597
, ATTCHE
, get_intenb_reg(port
));
991 if (syssts
== FS_JSTS
)
992 r8a66597_bset(r8a66597
, HSE
, get_syscfg_reg(port
));
993 else if (syssts
== LS_JSTS
)
994 r8a66597_bclr(r8a66597
, HSE
, get_syscfg_reg(port
));
996 r8a66597_write(r8a66597
, ~DTCH
, get_intsts_reg(port
));
997 r8a66597_bset(r8a66597
, DTCHE
, get_intenb_reg(port
));
999 if (r8a66597
->bus_suspended
)
1000 usb_hcd_resume_root_hub(r8a66597_to_hcd(r8a66597
));
1003 /* this function must be called with interrupt disabled */
1004 static void r8a66597_usb_connect(struct r8a66597
*r8a66597
, int port
)
1006 u16 speed
= get_rh_usb_speed(r8a66597
, port
);
1007 struct r8a66597_root_hub
*rh
= &r8a66597
->root_hub
[port
];
1009 if (speed
== HSMODE
)
1010 rh
->port
|= (1 << USB_PORT_FEAT_HIGHSPEED
);
1011 else if (speed
== LSMODE
)
1012 rh
->port
|= (1 << USB_PORT_FEAT_LOWSPEED
);
1014 rh
->port
&= ~(1 << USB_PORT_FEAT_RESET
);
1015 rh
->port
|= 1 << USB_PORT_FEAT_ENABLE
;
1018 /* this function must be called with interrupt disabled */
1019 static void r8a66597_usb_disconnect(struct r8a66597
*r8a66597
, int port
)
1021 struct r8a66597_device
*dev
= r8a66597
->root_hub
[port
].dev
;
1023 disable_r8a66597_pipe_all(r8a66597
, dev
);
1024 free_usb_address(r8a66597
, dev
);
1026 start_root_hub_sampling(r8a66597
, port
, 0);
1029 /* this function must be called with interrupt disabled */
1030 static void prepare_setup_packet(struct r8a66597
*r8a66597
,
1031 struct r8a66597_td
*td
)
1034 __le16
*p
= (__le16
*)td
->urb
->setup_packet
;
1035 unsigned long setup_addr
= USBREQ
;
1037 r8a66597_write(r8a66597
, make_devsel(td
->address
) | td
->maxpacket
,
1039 r8a66597_write(r8a66597
, ~(SIGN
| SACK
), INTSTS1
);
1041 for (i
= 0; i
< 4; i
++) {
1042 r8a66597_write(r8a66597
, le16_to_cpu(p
[i
]), setup_addr
);
1045 r8a66597_write(r8a66597
, SUREQ
, DCPCTR
);
1048 /* this function must be called with interrupt disabled */
1049 static void prepare_packet_read(struct r8a66597
*r8a66597
,
1050 struct r8a66597_td
*td
)
1052 struct urb
*urb
= td
->urb
;
1054 if (usb_pipecontrol(urb
->pipe
)) {
1055 r8a66597_bclr(r8a66597
, R8A66597_DIR
, DCPCFG
);
1056 r8a66597_mdfy(r8a66597
, 0, ISEL
| CURPIPE
, CFIFOSEL
);
1057 r8a66597_reg_wait(r8a66597
, CFIFOSEL
, CURPIPE
, 0);
1058 if (urb
->actual_length
== 0) {
1059 r8a66597_pipe_toggle(r8a66597
, td
->pipe
, 1);
1060 r8a66597_write(r8a66597
, BCLR
, CFIFOCTR
);
1062 pipe_irq_disable(r8a66597
, td
->pipenum
);
1063 pipe_start(r8a66597
, td
->pipe
);
1064 pipe_irq_enable(r8a66597
, urb
, td
->pipenum
);
1066 if (urb
->actual_length
== 0) {
1067 pipe_irq_disable(r8a66597
, td
->pipenum
);
1068 pipe_setting(r8a66597
, td
);
1069 pipe_stop(r8a66597
, td
->pipe
);
1070 r8a66597_write(r8a66597
, ~(1 << td
->pipenum
), BRDYSTS
);
1072 if (td
->pipe
->pipetre
) {
1073 r8a66597_write(r8a66597
, TRCLR
,
1075 r8a66597_write(r8a66597
,
1077 (urb
->transfer_buffer_length
,
1080 r8a66597_bset(r8a66597
, TRENB
,
1084 pipe_start(r8a66597
, td
->pipe
);
1085 pipe_irq_enable(r8a66597
, urb
, td
->pipenum
);
1090 /* this function must be called with interrupt disabled */
1091 static void prepare_packet_write(struct r8a66597
*r8a66597
,
1092 struct r8a66597_td
*td
)
1095 struct urb
*urb
= td
->urb
;
1097 if (usb_pipecontrol(urb
->pipe
)) {
1098 pipe_stop(r8a66597
, td
->pipe
);
1099 r8a66597_bset(r8a66597
, R8A66597_DIR
, DCPCFG
);
1100 r8a66597_mdfy(r8a66597
, ISEL
, ISEL
| CURPIPE
, CFIFOSEL
);
1101 r8a66597_reg_wait(r8a66597
, CFIFOSEL
, CURPIPE
, 0);
1102 if (urb
->actual_length
== 0) {
1103 r8a66597_pipe_toggle(r8a66597
, td
->pipe
, 1);
1104 r8a66597_write(r8a66597
, BCLR
, CFIFOCTR
);
1107 if (urb
->actual_length
== 0)
1108 pipe_setting(r8a66597
, td
);
1109 if (td
->pipe
->pipetre
)
1110 r8a66597_bclr(r8a66597
, TRENB
, td
->pipe
->pipetre
);
1112 r8a66597_write(r8a66597
, ~(1 << td
->pipenum
), BRDYSTS
);
1114 fifo_change_from_pipe(r8a66597
, td
->pipe
);
1115 tmp
= r8a66597_read(r8a66597
, td
->pipe
->fifoctr
);
1116 if (unlikely((tmp
& FRDY
) == 0))
1117 pipe_irq_enable(r8a66597
, urb
, td
->pipenum
);
1119 packet_write(r8a66597
, td
->pipenum
);
1120 pipe_start(r8a66597
, td
->pipe
);
1123 /* this function must be called with interrupt disabled */
1124 static void prepare_status_packet(struct r8a66597
*r8a66597
,
1125 struct r8a66597_td
*td
)
1127 struct urb
*urb
= td
->urb
;
1129 r8a66597_pipe_toggle(r8a66597
, td
->pipe
, 1);
1130 pipe_stop(r8a66597
, td
->pipe
);
1132 if (urb
->setup_packet
[0] & USB_ENDPOINT_DIR_MASK
) {
1133 r8a66597_bset(r8a66597
, R8A66597_DIR
, DCPCFG
);
1134 r8a66597_mdfy(r8a66597
, ISEL
, ISEL
| CURPIPE
, CFIFOSEL
);
1135 r8a66597_reg_wait(r8a66597
, CFIFOSEL
, CURPIPE
, 0);
1136 r8a66597_write(r8a66597
, ~BEMP0
, BEMPSTS
);
1137 r8a66597_write(r8a66597
, BCLR
| BVAL
, CFIFOCTR
);
1138 enable_irq_empty(r8a66597
, 0);
1140 r8a66597_bclr(r8a66597
, R8A66597_DIR
, DCPCFG
);
1141 r8a66597_mdfy(r8a66597
, 0, ISEL
| CURPIPE
, CFIFOSEL
);
1142 r8a66597_reg_wait(r8a66597
, CFIFOSEL
, CURPIPE
, 0);
1143 r8a66597_write(r8a66597
, BCLR
, CFIFOCTR
);
1144 enable_irq_ready(r8a66597
, 0);
1146 enable_irq_nrdy(r8a66597
, 0);
1147 pipe_start(r8a66597
, td
->pipe
);
1150 static int is_set_address(unsigned char *setup_packet
)
1152 if (((setup_packet
[0] & USB_TYPE_MASK
) == USB_TYPE_STANDARD
) &&
1153 setup_packet
[1] == USB_REQ_SET_ADDRESS
)
1159 /* this function must be called with interrupt disabled */
1160 static int start_transfer(struct r8a66597
*r8a66597
, struct r8a66597_td
*td
)
1166 if (is_set_address(td
->urb
->setup_packet
)) {
1167 td
->set_address
= 1;
1168 td
->urb
->setup_packet
[2] = alloc_usb_address(r8a66597
,
1170 if (td
->urb
->setup_packet
[2] == 0)
1173 prepare_setup_packet(r8a66597
, td
);
1176 prepare_packet_read(r8a66597
, td
);
1179 prepare_packet_write(r8a66597
, td
);
1182 prepare_status_packet(r8a66597
, td
);
1185 printk(KERN_ERR
"r8a66597: invalid type.\n");
1192 static int check_transfer_finish(struct r8a66597_td
*td
, struct urb
*urb
)
1194 if (usb_pipeisoc(urb
->pipe
)) {
1195 if (urb
->number_of_packets
== td
->iso_cnt
)
1199 /* control or bulk or interrupt */
1200 if ((urb
->transfer_buffer_length
<= urb
->actual_length
) ||
1201 (td
->short_packet
) || (td
->zero_packet
))
1207 /* this function must be called with interrupt disabled */
1208 static void set_td_timer(struct r8a66597
*r8a66597
, struct r8a66597_td
*td
)
1214 if (!list_empty(&r8a66597
->pipe_queue
[td
->pipenum
]) &&
1215 !usb_pipecontrol(td
->urb
->pipe
) && usb_pipein(td
->urb
->pipe
)) {
1216 r8a66597
->timeout_map
|= 1 << td
->pipenum
;
1217 switch (usb_pipetype(td
->urb
->pipe
)) {
1218 case PIPE_INTERRUPT
:
1219 case PIPE_ISOCHRONOUS
:
1227 mod_timer(&r8a66597
->td_timer
[td
->pipenum
],
1228 jiffies
+ msecs_to_jiffies(time
));
1232 /* this function must be called with interrupt disabled */
1233 static void finish_request(struct r8a66597
*r8a66597
, struct r8a66597_td
*td
,
1234 u16 pipenum
, struct urb
*urb
, int status
)
1235 __releases(r8a66597
->lock
) __acquires(r8a66597
->lock
)
1238 struct usb_hcd
*hcd
= r8a66597_to_hcd(r8a66597
);
1240 r8a66597
->timeout_map
&= ~(1 << pipenum
);
1243 if (td
->set_address
&& (status
!= 0 || urb
->unlinked
))
1244 r8a66597
->address_map
&= ~(1 << urb
->setup_packet
[2]);
1246 pipe_toggle_save(r8a66597
, td
->pipe
, urb
);
1247 list_del(&td
->queue
);
1251 if (!list_empty(&r8a66597
->pipe_queue
[pipenum
]))
1255 if (usb_pipeisoc(urb
->pipe
))
1256 urb
->start_frame
= r8a66597_get_frame(hcd
);
1258 usb_hcd_unlink_urb_from_ep(r8a66597_to_hcd(r8a66597
), urb
);
1259 spin_unlock(&r8a66597
->lock
);
1260 usb_hcd_giveback_urb(hcd
, urb
, status
);
1261 spin_lock(&r8a66597
->lock
);
1265 td
= r8a66597_get_td(r8a66597
, pipenum
);
1269 start_transfer(r8a66597
, td
);
1270 set_td_timer(r8a66597
, td
);
1274 static void packet_read(struct r8a66597
*r8a66597
, u16 pipenum
)
1277 int rcv_len
, bufsize
, urb_len
, size
;
1279 struct r8a66597_td
*td
= r8a66597_get_td(r8a66597
, pipenum
);
1288 fifo_change_from_pipe(r8a66597
, td
->pipe
);
1289 tmp
= r8a66597_read(r8a66597
, td
->pipe
->fifoctr
);
1290 if (unlikely((tmp
& FRDY
) == 0)) {
1291 pipe_stop(r8a66597
, td
->pipe
);
1292 pipe_irq_disable(r8a66597
, pipenum
);
1293 printk(KERN_ERR
"r8a66597: in fifo not ready (%d)\n", pipenum
);
1294 finish_request(r8a66597
, td
, pipenum
, td
->urb
, -EPIPE
);
1298 /* prepare parameters */
1299 rcv_len
= tmp
& DTLN
;
1300 if (usb_pipeisoc(urb
->pipe
)) {
1301 buf
= (u16
*)(urb
->transfer_buffer
+
1302 urb
->iso_frame_desc
[td
->iso_cnt
].offset
);
1303 urb_len
= urb
->iso_frame_desc
[td
->iso_cnt
].length
;
1305 buf
= (void *)urb
->transfer_buffer
+ urb
->actual_length
;
1306 urb_len
= urb
->transfer_buffer_length
- urb
->actual_length
;
1308 bufsize
= min(urb_len
, (int) td
->maxpacket
);
1309 if (rcv_len
<= bufsize
) {
1313 status
= -EOVERFLOW
;
1317 /* update parameters */
1318 urb
->actual_length
+= size
;
1320 td
->zero_packet
= 1;
1321 if (rcv_len
< bufsize
) {
1322 td
->short_packet
= 1;
1324 if (usb_pipeisoc(urb
->pipe
)) {
1325 urb
->iso_frame_desc
[td
->iso_cnt
].actual_length
= size
;
1326 urb
->iso_frame_desc
[td
->iso_cnt
].status
= status
;
1331 /* check transfer finish */
1332 if (finish
|| check_transfer_finish(td
, urb
)) {
1333 pipe_stop(r8a66597
, td
->pipe
);
1334 pipe_irq_disable(r8a66597
, pipenum
);
1339 if (urb
->transfer_buffer
) {
1341 r8a66597_write(r8a66597
, BCLR
, td
->pipe
->fifoctr
);
1343 r8a66597_read_fifo(r8a66597
, td
->pipe
->fifoaddr
,
1347 if (finish
&& pipenum
!= 0)
1348 finish_request(r8a66597
, td
, pipenum
, urb
, status
);
1351 static void packet_write(struct r8a66597
*r8a66597
, u16 pipenum
)
1356 struct r8a66597_td
*td
= r8a66597_get_td(r8a66597
, pipenum
);
1363 fifo_change_from_pipe(r8a66597
, td
->pipe
);
1364 tmp
= r8a66597_read(r8a66597
, td
->pipe
->fifoctr
);
1365 if (unlikely((tmp
& FRDY
) == 0)) {
1366 pipe_stop(r8a66597
, td
->pipe
);
1367 pipe_irq_disable(r8a66597
, pipenum
);
1368 printk(KERN_ERR
"r8a66597: out fifo not ready (%d)\n", pipenum
);
1369 finish_request(r8a66597
, td
, pipenum
, urb
, -EPIPE
);
1373 /* prepare parameters */
1374 bufsize
= td
->maxpacket
;
1375 if (usb_pipeisoc(urb
->pipe
)) {
1376 buf
= (u16
*)(urb
->transfer_buffer
+
1377 urb
->iso_frame_desc
[td
->iso_cnt
].offset
);
1379 (int)urb
->iso_frame_desc
[td
->iso_cnt
].length
);
1381 buf
= (u16
*)(urb
->transfer_buffer
+ urb
->actual_length
);
1382 size
= min_t(u32
, bufsize
,
1383 urb
->transfer_buffer_length
- urb
->actual_length
);
1388 r8a66597_write(r8a66597
, ~(1 << pipenum
), BEMPSTS
);
1389 if (urb
->transfer_buffer
) {
1390 r8a66597_write_fifo(r8a66597
, td
->pipe
->fifoaddr
, buf
, size
);
1391 if (!usb_pipebulk(urb
->pipe
) || td
->maxpacket
!= size
)
1392 r8a66597_write(r8a66597
, BVAL
, td
->pipe
->fifoctr
);
1395 /* update parameters */
1396 urb
->actual_length
+= size
;
1397 if (usb_pipeisoc(urb
->pipe
)) {
1398 urb
->iso_frame_desc
[td
->iso_cnt
].actual_length
= size
;
1399 urb
->iso_frame_desc
[td
->iso_cnt
].status
= 0;
1403 /* check transfer finish */
1404 if (check_transfer_finish(td
, urb
)) {
1405 disable_irq_ready(r8a66597
, pipenum
);
1406 enable_irq_empty(r8a66597
, pipenum
);
1407 if (!usb_pipeisoc(urb
->pipe
))
1408 enable_irq_nrdy(r8a66597
, pipenum
);
1410 pipe_irq_enable(r8a66597
, urb
, pipenum
);
1414 static void check_next_phase(struct r8a66597
*r8a66597
, int status
)
1416 struct r8a66597_td
*td
= r8a66597_get_td(r8a66597
, 0);
1427 if (check_transfer_finish(td
, urb
))
1428 td
->type
= USB_PID_ACK
;
1431 if (urb
->transfer_buffer_length
== urb
->actual_length
)
1432 td
->type
= USB_PID_ACK
;
1433 else if (usb_pipeout(urb
->pipe
))
1434 td
->type
= USB_PID_OUT
;
1436 td
->type
= USB_PID_IN
;
1443 if (finish
|| status
!= 0 || urb
->unlinked
)
1444 finish_request(r8a66597
, td
, 0, urb
, status
);
1446 start_transfer(r8a66597
, td
);
1449 static int get_urb_error(struct r8a66597
*r8a66597
, u16 pipenum
)
1451 struct r8a66597_td
*td
= r8a66597_get_td(r8a66597
, pipenum
);
1454 u16 pid
= r8a66597_read(r8a66597
, td
->pipe
->pipectr
) & PID
;
1464 static void irq_pipe_ready(struct r8a66597
*r8a66597
)
1469 struct r8a66597_td
*td
;
1471 mask
= r8a66597_read(r8a66597
, BRDYSTS
)
1472 & r8a66597_read(r8a66597
, BRDYENB
);
1473 r8a66597_write(r8a66597
, ~mask
, BRDYSTS
);
1475 td
= r8a66597_get_td(r8a66597
, 0);
1476 if (td
&& td
->type
== USB_PID_IN
)
1477 packet_read(r8a66597
, 0);
1479 pipe_irq_disable(r8a66597
, 0);
1480 check_next_phase(r8a66597
, 0);
1483 for (pipenum
= 1; pipenum
< R8A66597_MAX_NUM_PIPE
; pipenum
++) {
1484 check
= 1 << pipenum
;
1486 td
= r8a66597_get_td(r8a66597
, pipenum
);
1490 if (td
->type
== USB_PID_IN
)
1491 packet_read(r8a66597
, pipenum
);
1492 else if (td
->type
== USB_PID_OUT
)
1493 packet_write(r8a66597
, pipenum
);
1498 static void irq_pipe_empty(struct r8a66597
*r8a66597
)
1504 struct r8a66597_td
*td
;
1506 mask
= r8a66597_read(r8a66597
, BEMPSTS
)
1507 & r8a66597_read(r8a66597
, BEMPENB
);
1508 r8a66597_write(r8a66597
, ~mask
, BEMPSTS
);
1510 cfifo_change(r8a66597
, 0);
1511 td
= r8a66597_get_td(r8a66597
, 0);
1512 if (td
&& td
->type
!= USB_PID_OUT
)
1513 disable_irq_empty(r8a66597
, 0);
1514 check_next_phase(r8a66597
, 0);
1517 for (pipenum
= 1; pipenum
< R8A66597_MAX_NUM_PIPE
; pipenum
++) {
1518 check
= 1 << pipenum
;
1520 struct r8a66597_td
*td
;
1521 td
= r8a66597_get_td(r8a66597
, pipenum
);
1525 tmp
= r8a66597_read(r8a66597
, td
->pipe
->pipectr
);
1526 if ((tmp
& INBUFM
) == 0) {
1527 disable_irq_empty(r8a66597
, pipenum
);
1528 pipe_irq_disable(r8a66597
, pipenum
);
1529 finish_request(r8a66597
, td
, pipenum
, td
->urb
,
1536 static void irq_pipe_nrdy(struct r8a66597
*r8a66597
)
1543 mask
= r8a66597_read(r8a66597
, NRDYSTS
)
1544 & r8a66597_read(r8a66597
, NRDYENB
);
1545 r8a66597_write(r8a66597
, ~mask
, NRDYSTS
);
1547 cfifo_change(r8a66597
, 0);
1548 status
= get_urb_error(r8a66597
, 0);
1549 pipe_irq_disable(r8a66597
, 0);
1550 check_next_phase(r8a66597
, status
);
1553 for (pipenum
= 1; pipenum
< R8A66597_MAX_NUM_PIPE
; pipenum
++) {
1554 check
= 1 << pipenum
;
1556 struct r8a66597_td
*td
;
1557 td
= r8a66597_get_td(r8a66597
, pipenum
);
1561 status
= get_urb_error(r8a66597
, pipenum
);
1562 pipe_irq_disable(r8a66597
, pipenum
);
1563 pipe_stop(r8a66597
, td
->pipe
);
1564 finish_request(r8a66597
, td
, pipenum
, td
->urb
, status
);
1569 static irqreturn_t
r8a66597_irq(struct usb_hcd
*hcd
)
1571 struct r8a66597
*r8a66597
= hcd_to_r8a66597(hcd
);
1572 u16 intsts0
, intsts1
, intsts2
;
1573 u16 intenb0
, intenb1
, intenb2
;
1574 u16 mask0
, mask1
, mask2
;
1577 spin_lock(&r8a66597
->lock
);
1579 intsts0
= r8a66597_read(r8a66597
, INTSTS0
);
1580 intsts1
= r8a66597_read(r8a66597
, INTSTS1
);
1581 intsts2
= r8a66597_read(r8a66597
, INTSTS2
);
1582 intenb0
= r8a66597_read(r8a66597
, INTENB0
);
1583 intenb1
= r8a66597_read(r8a66597
, INTENB1
);
1584 intenb2
= r8a66597_read(r8a66597
, INTENB2
);
1586 mask2
= intsts2
& intenb2
;
1587 mask1
= intsts1
& intenb1
;
1588 mask0
= intsts0
& intenb0
& (BEMP
| NRDY
| BRDY
);
1590 if (mask2
& ATTCH
) {
1591 r8a66597_write(r8a66597
, ~ATTCH
, INTSTS2
);
1592 r8a66597_bclr(r8a66597
, ATTCHE
, INTENB2
);
1594 /* start usb bus sampling */
1595 start_root_hub_sampling(r8a66597
, 1, 1);
1598 r8a66597_write(r8a66597
, ~DTCH
, INTSTS2
);
1599 r8a66597_bclr(r8a66597
, DTCHE
, INTENB2
);
1600 r8a66597_usb_disconnect(r8a66597
, 1);
1603 r8a66597_write(r8a66597
, ~BCHG
, INTSTS2
);
1604 r8a66597_bclr(r8a66597
, BCHGE
, INTENB2
);
1605 usb_hcd_resume_root_hub(r8a66597_to_hcd(r8a66597
));
1610 if (mask1
& ATTCH
) {
1611 r8a66597_write(r8a66597
, ~ATTCH
, INTSTS1
);
1612 r8a66597_bclr(r8a66597
, ATTCHE
, INTENB1
);
1614 /* start usb bus sampling */
1615 start_root_hub_sampling(r8a66597
, 0, 1);
1618 r8a66597_write(r8a66597
, ~DTCH
, INTSTS1
);
1619 r8a66597_bclr(r8a66597
, DTCHE
, INTENB1
);
1620 r8a66597_usb_disconnect(r8a66597
, 0);
1623 r8a66597_write(r8a66597
, ~BCHG
, INTSTS1
);
1624 r8a66597_bclr(r8a66597
, BCHGE
, INTENB1
);
1625 usb_hcd_resume_root_hub(r8a66597_to_hcd(r8a66597
));
1629 r8a66597_write(r8a66597
, ~SIGN
, INTSTS1
);
1630 status
= get_urb_error(r8a66597
, 0);
1631 check_next_phase(r8a66597
, status
);
1634 r8a66597_write(r8a66597
, ~SACK
, INTSTS1
);
1635 check_next_phase(r8a66597
, 0);
1640 irq_pipe_ready(r8a66597
);
1642 irq_pipe_empty(r8a66597
);
1644 irq_pipe_nrdy(r8a66597
);
1647 spin_unlock(&r8a66597
->lock
);
1651 /* this function must be called with interrupt disabled */
1652 static void r8a66597_root_hub_control(struct r8a66597
*r8a66597
, int port
)
1655 struct r8a66597_root_hub
*rh
= &r8a66597
->root_hub
[port
];
1657 if (rh
->port
& (1 << USB_PORT_FEAT_RESET
)) {
1658 unsigned long dvstctr_reg
= get_dvstctr_reg(port
);
1660 tmp
= r8a66597_read(r8a66597
, dvstctr_reg
);
1661 if ((tmp
& USBRST
) == USBRST
) {
1662 r8a66597_mdfy(r8a66597
, UACT
, USBRST
| UACT
,
1664 r8a66597_root_hub_start_polling(r8a66597
);
1666 r8a66597_usb_connect(r8a66597
, port
);
1669 if (!(rh
->port
& (1 << USB_PORT_FEAT_CONNECTION
))) {
1670 r8a66597_write(r8a66597
, ~ATTCH
, get_intsts_reg(port
));
1671 r8a66597_bset(r8a66597
, ATTCHE
, get_intenb_reg(port
));
1674 if (rh
->scount
> 0) {
1675 tmp
= r8a66597_read(r8a66597
, get_syssts_reg(port
)) & LNST
;
1676 if (tmp
== rh
->old_syssts
) {
1678 if (rh
->scount
== 0)
1679 r8a66597_check_syssts(r8a66597
, port
, tmp
);
1681 r8a66597_root_hub_start_polling(r8a66597
);
1683 rh
->scount
= R8A66597_MAX_SAMPLING
;
1684 rh
->old_syssts
= tmp
;
1685 r8a66597_root_hub_start_polling(r8a66597
);
1690 static void r8a66597_interval_timer(unsigned long _r8a66597
)
1692 struct r8a66597
*r8a66597
= (struct r8a66597
*)_r8a66597
;
1693 unsigned long flags
;
1695 struct r8a66597_td
*td
;
1697 spin_lock_irqsave(&r8a66597
->lock
, flags
);
1699 for (pipenum
= 0; pipenum
< R8A66597_MAX_NUM_PIPE
; pipenum
++) {
1700 if (!(r8a66597
->interval_map
& (1 << pipenum
)))
1702 if (timer_pending(&r8a66597
->interval_timer
[pipenum
]))
1705 td
= r8a66597_get_td(r8a66597
, pipenum
);
1707 start_transfer(r8a66597
, td
);
1710 spin_unlock_irqrestore(&r8a66597
->lock
, flags
);
1713 static void r8a66597_td_timer(unsigned long _r8a66597
)
1715 struct r8a66597
*r8a66597
= (struct r8a66597
*)_r8a66597
;
1716 unsigned long flags
;
1718 struct r8a66597_td
*td
, *new_td
= NULL
;
1719 struct r8a66597_pipe
*pipe
;
1721 spin_lock_irqsave(&r8a66597
->lock
, flags
);
1722 for (pipenum
= 0; pipenum
< R8A66597_MAX_NUM_PIPE
; pipenum
++) {
1723 if (!(r8a66597
->timeout_map
& (1 << pipenum
)))
1725 if (timer_pending(&r8a66597
->td_timer
[pipenum
]))
1728 td
= r8a66597_get_td(r8a66597
, pipenum
);
1730 r8a66597
->timeout_map
&= ~(1 << pipenum
);
1734 if (td
->urb
->actual_length
) {
1735 set_td_timer(r8a66597
, td
);
1740 pipe_stop(r8a66597
, pipe
);
1744 list_move_tail(&new_td
->queue
,
1745 &r8a66597
->pipe_queue
[pipenum
]);
1746 new_td
= r8a66597_get_td(r8a66597
, pipenum
);
1751 } while (td
!= new_td
&& td
->address
== new_td
->address
);
1753 start_transfer(r8a66597
, new_td
);
1756 r8a66597
->timeout_map
&= ~(1 << pipenum
);
1758 set_td_timer(r8a66597
, new_td
);
1761 spin_unlock_irqrestore(&r8a66597
->lock
, flags
);
1764 static void r8a66597_timer(unsigned long _r8a66597
)
1766 struct r8a66597
*r8a66597
= (struct r8a66597
*)_r8a66597
;
1767 unsigned long flags
;
1770 spin_lock_irqsave(&r8a66597
->lock
, flags
);
1772 for (port
= 0; port
< R8A66597_MAX_ROOT_HUB
; port
++)
1773 r8a66597_root_hub_control(r8a66597
, port
);
1775 spin_unlock_irqrestore(&r8a66597
->lock
, flags
);
1778 static int check_pipe_config(struct r8a66597
*r8a66597
, struct urb
*urb
)
1780 struct r8a66597_device
*dev
= get_urb_to_r8a66597_dev(r8a66597
, urb
);
1782 if (dev
&& dev
->address
&& dev
->state
!= USB_STATE_CONFIGURED
&&
1783 (urb
->dev
->state
== USB_STATE_CONFIGURED
))
1789 static int r8a66597_start(struct usb_hcd
*hcd
)
1791 struct r8a66597
*r8a66597
= hcd_to_r8a66597(hcd
);
1793 hcd
->state
= HC_STATE_RUNNING
;
1794 return enable_controller(r8a66597
);
1797 static void r8a66597_stop(struct usb_hcd
*hcd
)
1799 struct r8a66597
*r8a66597
= hcd_to_r8a66597(hcd
);
1801 disable_controller(r8a66597
);
1804 static void set_address_zero(struct r8a66597
*r8a66597
, struct urb
*urb
)
1806 unsigned int usb_address
= usb_pipedevice(urb
->pipe
);
1807 u16 root_port
, hub_port
;
1809 if (usb_address
== 0) {
1810 get_port_number(urb
->dev
->devpath
,
1811 &root_port
, &hub_port
);
1812 set_devadd_reg(r8a66597
, 0,
1813 get_r8a66597_usb_speed(urb
->dev
->speed
),
1814 get_parent_r8a66597_address(r8a66597
, urb
->dev
),
1815 hub_port
, root_port
);
1819 static struct r8a66597_td
*r8a66597_make_td(struct r8a66597
*r8a66597
,
1821 struct usb_host_endpoint
*hep
)
1823 struct r8a66597_td
*td
;
1826 td
= kzalloc(sizeof(struct r8a66597_td
), GFP_ATOMIC
);
1830 pipenum
= r8a66597_get_pipenum(urb
, hep
);
1831 td
->pipenum
= pipenum
;
1832 td
->pipe
= hep
->hcpriv
;
1834 td
->address
= get_urb_to_r8a66597_addr(r8a66597
, urb
);
1835 td
->maxpacket
= usb_maxpacket(urb
->dev
, urb
->pipe
,
1836 !usb_pipein(urb
->pipe
));
1837 if (usb_pipecontrol(urb
->pipe
))
1838 td
->type
= USB_PID_SETUP
;
1839 else if (usb_pipein(urb
->pipe
))
1840 td
->type
= USB_PID_IN
;
1842 td
->type
= USB_PID_OUT
;
1843 INIT_LIST_HEAD(&td
->queue
);
1848 static int r8a66597_urb_enqueue(struct usb_hcd
*hcd
,
1852 struct usb_host_endpoint
*hep
= urb
->ep
;
1853 struct r8a66597
*r8a66597
= hcd_to_r8a66597(hcd
);
1854 struct r8a66597_td
*td
= NULL
;
1855 int ret
, request
= 0;
1856 unsigned long flags
;
1858 spin_lock_irqsave(&r8a66597
->lock
, flags
);
1859 if (!get_urb_to_r8a66597_dev(r8a66597
, urb
)) {
1861 goto error_not_linked
;
1864 ret
= usb_hcd_link_urb_to_ep(hcd
, urb
);
1866 goto error_not_linked
;
1869 hep
->hcpriv
= kzalloc(sizeof(struct r8a66597_pipe
),
1875 set_pipe_reg_addr(hep
->hcpriv
, R8A66597_PIPE_NO_DMA
);
1876 if (usb_pipeendpoint(urb
->pipe
))
1877 init_pipe_info(r8a66597
, urb
, hep
, &hep
->desc
);
1880 if (unlikely(check_pipe_config(r8a66597
, urb
)))
1881 init_pipe_config(r8a66597
, urb
);
1883 set_address_zero(r8a66597
, urb
);
1884 td
= r8a66597_make_td(r8a66597
, urb
, hep
);
1889 if (list_empty(&r8a66597
->pipe_queue
[td
->pipenum
]))
1891 list_add_tail(&td
->queue
, &r8a66597
->pipe_queue
[td
->pipenum
]);
1895 if (td
->pipe
->info
.timer_interval
) {
1896 r8a66597
->interval_map
|= 1 << td
->pipenum
;
1897 mod_timer(&r8a66597
->interval_timer
[td
->pipenum
],
1898 jiffies
+ msecs_to_jiffies(
1899 td
->pipe
->info
.timer_interval
));
1901 ret
= start_transfer(r8a66597
, td
);
1903 list_del(&td
->queue
);
1908 set_td_timer(r8a66597
, td
);
1912 usb_hcd_unlink_urb_from_ep(hcd
, urb
);
1914 spin_unlock_irqrestore(&r8a66597
->lock
, flags
);
1918 static int r8a66597_urb_dequeue(struct usb_hcd
*hcd
, struct urb
*urb
,
1921 struct r8a66597
*r8a66597
= hcd_to_r8a66597(hcd
);
1922 struct r8a66597_td
*td
;
1923 unsigned long flags
;
1926 spin_lock_irqsave(&r8a66597
->lock
, flags
);
1927 rc
= usb_hcd_check_unlink_urb(hcd
, urb
, status
);
1933 pipe_stop(r8a66597
, td
->pipe
);
1934 pipe_irq_disable(r8a66597
, td
->pipenum
);
1935 disable_irq_empty(r8a66597
, td
->pipenum
);
1936 finish_request(r8a66597
, td
, td
->pipenum
, urb
, status
);
1939 spin_unlock_irqrestore(&r8a66597
->lock
, flags
);
1943 static void r8a66597_endpoint_disable(struct usb_hcd
*hcd
,
1944 struct usb_host_endpoint
*hep
)
1946 struct r8a66597
*r8a66597
= hcd_to_r8a66597(hcd
);
1947 struct r8a66597_pipe
*pipe
= (struct r8a66597_pipe
*)hep
->hcpriv
;
1948 struct r8a66597_td
*td
;
1949 struct urb
*urb
= NULL
;
1951 unsigned long flags
;
1955 pipenum
= pipe
->info
.pipenum
;
1963 spin_lock_irqsave(&r8a66597
->lock
, flags
);
1964 pipe_stop(r8a66597
, pipe
);
1965 pipe_irq_disable(r8a66597
, pipenum
);
1966 disable_irq_empty(r8a66597
, pipenum
);
1967 td
= r8a66597_get_td(r8a66597
, pipenum
);
1970 finish_request(r8a66597
, td
, pipenum
, urb
, -ESHUTDOWN
);
1973 spin_unlock_irqrestore(&r8a66597
->lock
, flags
);
1976 static int r8a66597_get_frame(struct usb_hcd
*hcd
)
1978 struct r8a66597
*r8a66597
= hcd_to_r8a66597(hcd
);
1979 return r8a66597_read(r8a66597
, FRMNUM
) & 0x03FF;
1982 static void collect_usb_address_map(struct usb_device
*udev
, unsigned long *map
)
1986 if (udev
->state
== USB_STATE_CONFIGURED
&&
1987 udev
->parent
&& udev
->parent
->devnum
> 1 &&
1988 udev
->parent
->descriptor
.bDeviceClass
== USB_CLASS_HUB
)
1989 map
[udev
->devnum
/32] |= (1 << (udev
->devnum
% 32));
1991 for (chix
= 0; chix
< udev
->maxchild
; chix
++) {
1992 struct usb_device
*childdev
= udev
->children
[chix
];
1995 collect_usb_address_map(childdev
, map
);
1999 /* this function must be called with interrupt disabled */
2000 static struct r8a66597_device
*get_r8a66597_device(struct r8a66597
*r8a66597
,
2003 struct r8a66597_device
*dev
;
2004 struct list_head
*list
= &r8a66597
->child_device
;
2006 list_for_each_entry(dev
, list
, device_list
) {
2009 if (dev
->usb_address
!= addr
)
2015 printk(KERN_ERR
"r8a66597: get_r8a66597_device fail.(%d)\n", addr
);
2019 static void update_usb_address_map(struct r8a66597
*r8a66597
,
2020 struct usb_device
*root_hub
,
2025 unsigned long flags
;
2027 for (i
= 0; i
< 4; i
++) {
2028 diff
= r8a66597
->child_connect_map
[i
] ^ map
[i
];
2032 for (j
= 0; j
< 32; j
++) {
2033 if (!(diff
& (1 << j
)))
2037 if (map
[i
] & (1 << j
))
2038 set_child_connect_map(r8a66597
, addr
);
2040 struct r8a66597_device
*dev
;
2042 spin_lock_irqsave(&r8a66597
->lock
, flags
);
2043 dev
= get_r8a66597_device(r8a66597
, addr
);
2044 disable_r8a66597_pipe_all(r8a66597
, dev
);
2045 free_usb_address(r8a66597
, dev
);
2046 put_child_connect_map(r8a66597
, addr
);
2047 spin_unlock_irqrestore(&r8a66597
->lock
, flags
);
2053 static void r8a66597_check_detect_child(struct r8a66597
*r8a66597
,
2054 struct usb_hcd
*hcd
)
2056 struct usb_bus
*bus
;
2057 unsigned long now_map
[4];
2059 memset(now_map
, 0, sizeof(now_map
));
2061 list_for_each_entry(bus
, &usb_bus_list
, bus_list
) {
2065 if (bus
->busnum
!= hcd
->self
.busnum
)
2068 collect_usb_address_map(bus
->root_hub
, now_map
);
2069 update_usb_address_map(r8a66597
, bus
->root_hub
, now_map
);
2073 static int r8a66597_hub_status_data(struct usb_hcd
*hcd
, char *buf
)
2075 struct r8a66597
*r8a66597
= hcd_to_r8a66597(hcd
);
2076 unsigned long flags
;
2079 r8a66597_check_detect_child(r8a66597
, hcd
);
2081 spin_lock_irqsave(&r8a66597
->lock
, flags
);
2083 *buf
= 0; /* initialize (no change) */
2085 for (i
= 0; i
< R8A66597_MAX_ROOT_HUB
; i
++) {
2086 if (r8a66597
->root_hub
[i
].port
& 0xffff0000)
2087 *buf
|= 1 << (i
+ 1);
2090 spin_unlock_irqrestore(&r8a66597
->lock
, flags
);
2095 static void r8a66597_hub_descriptor(struct r8a66597
*r8a66597
,
2096 struct usb_hub_descriptor
*desc
)
2098 desc
->bDescriptorType
= 0x29;
2099 desc
->bHubContrCurrent
= 0;
2100 desc
->bNbrPorts
= R8A66597_MAX_ROOT_HUB
;
2101 desc
->bDescLength
= 9;
2102 desc
->bPwrOn2PwrGood
= 0;
2103 desc
->wHubCharacteristics
= cpu_to_le16(0x0011);
2104 desc
->bitmap
[0] = ((1 << R8A66597_MAX_ROOT_HUB
) - 1) << 1;
2105 desc
->bitmap
[1] = ~0;
2108 static int r8a66597_hub_control(struct usb_hcd
*hcd
, u16 typeReq
, u16 wValue
,
2109 u16 wIndex
, char *buf
, u16 wLength
)
2111 struct r8a66597
*r8a66597
= hcd_to_r8a66597(hcd
);
2113 int port
= (wIndex
& 0x00FF) - 1;
2114 struct r8a66597_root_hub
*rh
= &r8a66597
->root_hub
[port
];
2115 unsigned long flags
;
2119 spin_lock_irqsave(&r8a66597
->lock
, flags
);
2121 case ClearHubFeature
:
2124 case C_HUB_OVER_CURRENT
:
2125 case C_HUB_LOCAL_POWER
:
2131 case ClearPortFeature
:
2132 if (wIndex
> R8A66597_MAX_ROOT_HUB
)
2138 case USB_PORT_FEAT_ENABLE
:
2139 rh
->port
&= ~(1 << USB_PORT_FEAT_POWER
);
2141 case USB_PORT_FEAT_SUSPEND
:
2143 case USB_PORT_FEAT_POWER
:
2144 r8a66597_port_power(r8a66597
, port
, 0);
2146 case USB_PORT_FEAT_C_ENABLE
:
2147 case USB_PORT_FEAT_C_SUSPEND
:
2148 case USB_PORT_FEAT_C_CONNECTION
:
2149 case USB_PORT_FEAT_C_OVER_CURRENT
:
2150 case USB_PORT_FEAT_C_RESET
:
2155 rh
->port
&= ~(1 << wValue
);
2157 case GetHubDescriptor
:
2158 r8a66597_hub_descriptor(r8a66597
,
2159 (struct usb_hub_descriptor
*)buf
);
2165 if (wIndex
> R8A66597_MAX_ROOT_HUB
)
2167 *(__le32
*)buf
= cpu_to_le32(rh
->port
);
2169 case SetPortFeature
:
2170 if (wIndex
> R8A66597_MAX_ROOT_HUB
)
2176 case USB_PORT_FEAT_SUSPEND
:
2178 case USB_PORT_FEAT_POWER
:
2179 r8a66597_port_power(r8a66597
, port
, 1);
2180 rh
->port
|= (1 << USB_PORT_FEAT_POWER
);
2182 case USB_PORT_FEAT_RESET
: {
2183 struct r8a66597_device
*dev
= rh
->dev
;
2185 rh
->port
|= (1 << USB_PORT_FEAT_RESET
);
2187 disable_r8a66597_pipe_all(r8a66597
, dev
);
2188 free_usb_address(r8a66597
, dev
);
2190 r8a66597_mdfy(r8a66597
, USBRST
, USBRST
| UACT
,
2191 get_dvstctr_reg(port
));
2192 mod_timer(&r8a66597
->rh_timer
,
2193 jiffies
+ msecs_to_jiffies(50));
2199 rh
->port
|= 1 << wValue
;
2207 spin_unlock_irqrestore(&r8a66597
->lock
, flags
);
2211 #if defined(CONFIG_PM)
2212 static int r8a66597_bus_suspend(struct usb_hcd
*hcd
)
2214 struct r8a66597
*r8a66597
= hcd_to_r8a66597(hcd
);
2217 dbg("%s", __func__
);
2219 for (port
= 0; port
< R8A66597_MAX_ROOT_HUB
; port
++) {
2220 struct r8a66597_root_hub
*rh
= &r8a66597
->root_hub
[port
];
2221 unsigned long dvstctr_reg
= get_dvstctr_reg(port
);
2223 if (!(rh
->port
& (1 << USB_PORT_FEAT_ENABLE
)))
2226 dbg("suspend port = %d", port
);
2227 r8a66597_bclr(r8a66597
, UACT
, dvstctr_reg
); /* suspend */
2228 rh
->port
|= 1 << USB_PORT_FEAT_SUSPEND
;
2230 if (rh
->dev
->udev
->do_remote_wakeup
) {
2231 msleep(3); /* waiting last SOF */
2232 r8a66597_bset(r8a66597
, RWUPE
, dvstctr_reg
);
2233 r8a66597_write(r8a66597
, ~BCHG
, get_intsts_reg(port
));
2234 r8a66597_bset(r8a66597
, BCHGE
, get_intenb_reg(port
));
2238 r8a66597
->bus_suspended
= 1;
2243 static int r8a66597_bus_resume(struct usb_hcd
*hcd
)
2245 struct r8a66597
*r8a66597
= hcd_to_r8a66597(hcd
);
2248 dbg("%s", __func__
);
2250 for (port
= 0; port
< R8A66597_MAX_ROOT_HUB
; port
++) {
2251 struct r8a66597_root_hub
*rh
= &r8a66597
->root_hub
[port
];
2252 unsigned long dvstctr_reg
= get_dvstctr_reg(port
);
2254 if (!(rh
->port
& (1 << USB_PORT_FEAT_SUSPEND
)))
2257 dbg("resume port = %d", port
);
2258 rh
->port
&= ~(1 << USB_PORT_FEAT_SUSPEND
);
2259 rh
->port
|= 1 << USB_PORT_FEAT_C_SUSPEND
;
2260 r8a66597_mdfy(r8a66597
, RESUME
, RESUME
| UACT
, dvstctr_reg
);
2262 r8a66597_mdfy(r8a66597
, UACT
, RESUME
| UACT
, dvstctr_reg
);
2269 #define r8a66597_bus_suspend NULL
2270 #define r8a66597_bus_resume NULL
2273 static struct hc_driver r8a66597_hc_driver
= {
2274 .description
= hcd_name
,
2275 .hcd_priv_size
= sizeof(struct r8a66597
),
2276 .irq
= r8a66597_irq
,
2279 * generic hardware linkage
2283 .start
= r8a66597_start
,
2284 .stop
= r8a66597_stop
,
2287 * managing i/o requests and associated device resources
2289 .urb_enqueue
= r8a66597_urb_enqueue
,
2290 .urb_dequeue
= r8a66597_urb_dequeue
,
2291 .endpoint_disable
= r8a66597_endpoint_disable
,
2294 * periodic schedule support
2296 .get_frame_number
= r8a66597_get_frame
,
2301 .hub_status_data
= r8a66597_hub_status_data
,
2302 .hub_control
= r8a66597_hub_control
,
2303 .bus_suspend
= r8a66597_bus_suspend
,
2304 .bus_resume
= r8a66597_bus_resume
,
2307 #if defined(CONFIG_PM)
2308 static int r8a66597_suspend(struct platform_device
*pdev
, pm_message_t state
)
2310 struct r8a66597
*r8a66597
= dev_get_drvdata(&pdev
->dev
);
2313 dbg("%s", __func__
);
2315 disable_controller(r8a66597
);
2317 for (port
= 0; port
< R8A66597_MAX_ROOT_HUB
; port
++) {
2318 struct r8a66597_root_hub
*rh
= &r8a66597
->root_hub
[port
];
2320 rh
->port
= 0x00000000;
2326 static int r8a66597_resume(struct platform_device
*pdev
)
2328 struct r8a66597
*r8a66597
= dev_get_drvdata(&pdev
->dev
);
2329 struct usb_hcd
*hcd
= r8a66597_to_hcd(r8a66597
);
2331 dbg("%s", __func__
);
2333 enable_controller(r8a66597
);
2334 usb_root_hub_lost_power(hcd
->self
.root_hub
);
2338 #else /* if defined(CONFIG_PM) */
2339 #define r8a66597_suspend NULL
2340 #define r8a66597_resume NULL
2343 static int __init_or_module
r8a66597_remove(struct platform_device
*pdev
)
2345 struct r8a66597
*r8a66597
= dev_get_drvdata(&pdev
->dev
);
2346 struct usb_hcd
*hcd
= r8a66597_to_hcd(r8a66597
);
2348 del_timer_sync(&r8a66597
->rh_timer
);
2349 usb_remove_hcd(hcd
);
2350 iounmap((void *)r8a66597
->reg
);
2351 #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) && defined(CONFIG_HAVE_CLK)
2352 clk_put(r8a66597
->clk
);
2358 static int __devinit
r8a66597_probe(struct platform_device
*pdev
)
2360 #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) && defined(CONFIG_HAVE_CLK)
2363 struct resource
*res
= NULL
, *ires
;
2365 void __iomem
*reg
= NULL
;
2366 struct usb_hcd
*hcd
= NULL
;
2367 struct r8a66597
*r8a66597
;
2370 unsigned long irq_trigger
;
2372 if (pdev
->dev
.dma_mask
) {
2374 dev_err(&pdev
->dev
, "dma not supported\n");
2378 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
2381 dev_err(&pdev
->dev
, "platform_get_resource error.\n");
2385 ires
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
2389 "platform_get_resource IORESOURCE_IRQ error.\n");
2394 irq_trigger
= ires
->flags
& IRQF_TRIGGER_MASK
;
2396 reg
= ioremap(res
->start
, resource_size(res
));
2399 dev_err(&pdev
->dev
, "ioremap error.\n");
2403 if (pdev
->dev
.platform_data
== NULL
) {
2404 dev_err(&pdev
->dev
, "no platform data\n");
2409 /* initialize hcd */
2410 hcd
= usb_create_hcd(&r8a66597_hc_driver
, &pdev
->dev
, (char *)hcd_name
);
2413 dev_err(&pdev
->dev
, "Failed to create hcd\n");
2416 r8a66597
= hcd_to_r8a66597(hcd
);
2417 memset(r8a66597
, 0, sizeof(struct r8a66597
));
2418 dev_set_drvdata(&pdev
->dev
, r8a66597
);
2419 r8a66597
->pdata
= pdev
->dev
.platform_data
;
2420 r8a66597
->irq_sense_low
= irq_trigger
== IRQF_TRIGGER_LOW
;
2422 #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) && defined(CONFIG_HAVE_CLK)
2423 snprintf(clk_name
, sizeof(clk_name
), "usb%d", pdev
->id
);
2424 r8a66597
->clk
= clk_get(&pdev
->dev
, clk_name
);
2425 if (IS_ERR(r8a66597
->clk
)) {
2426 dev_err(&pdev
->dev
, "cannot get clock \"%s\"\n", clk_name
);
2427 ret
= PTR_ERR(r8a66597
->clk
);
2432 spin_lock_init(&r8a66597
->lock
);
2433 init_timer(&r8a66597
->rh_timer
);
2434 r8a66597
->rh_timer
.function
= r8a66597_timer
;
2435 r8a66597
->rh_timer
.data
= (unsigned long)r8a66597
;
2436 r8a66597
->reg
= (unsigned long)reg
;
2438 for (i
= 0; i
< R8A66597_MAX_NUM_PIPE
; i
++) {
2439 INIT_LIST_HEAD(&r8a66597
->pipe_queue
[i
]);
2440 init_timer(&r8a66597
->td_timer
[i
]);
2441 r8a66597
->td_timer
[i
].function
= r8a66597_td_timer
;
2442 r8a66597
->td_timer
[i
].data
= (unsigned long)r8a66597
;
2443 setup_timer(&r8a66597
->interval_timer
[i
],
2444 r8a66597_interval_timer
,
2445 (unsigned long)r8a66597
);
2447 INIT_LIST_HEAD(&r8a66597
->child_device
);
2449 hcd
->rsrc_start
= res
->start
;
2451 ret
= usb_add_hcd(hcd
, irq
, IRQF_DISABLED
| irq_trigger
);
2453 dev_err(&pdev
->dev
, "Failed to add hcd\n");
2460 #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) && defined(CONFIG_HAVE_CLK)
2461 clk_put(r8a66597
->clk
);
2473 static struct platform_driver r8a66597_driver
= {
2474 .probe
= r8a66597_probe
,
2475 .remove
= r8a66597_remove
,
2476 .suspend
= r8a66597_suspend
,
2477 .resume
= r8a66597_resume
,
2479 .name
= (char *) hcd_name
,
2480 .owner
= THIS_MODULE
,
2484 static int __init
r8a66597_init(void)
2489 printk(KERN_INFO KBUILD_MODNAME
": driver %s, %s\n", hcd_name
,
2491 return platform_driver_register(&r8a66597_driver
);
2493 module_init(r8a66597_init
);
2495 static void __exit
r8a66597_cleanup(void)
2497 platform_driver_unregister(&r8a66597_driver
);
2499 module_exit(r8a66597_cleanup
);