Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1 | /* |
| 2 | * R8A66597 HCD (Host Controller Driver) |
| 3 | * |
| 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 |
| 8 | * |
| 9 | * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com> |
| 10 | * |
| 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. |
| 14 | * |
| 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. |
| 19 | * |
| 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 |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/sched.h> |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 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> |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 37 | #include <linux/io.h> |
Paul Mundt | 2717568 | 2010-02-04 06:57:58 +0000 | [diff] [blame^] | 38 | #include <linux/mm.h> |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 39 | #include <linux/irq.h> |
Paul Mundt | 2717568 | 2010-02-04 06:57:58 +0000 | [diff] [blame^] | 40 | #include <asm/cacheflush.h> |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 41 | |
| 42 | #include "../core/hcd.h" |
| 43 | #include "r8a66597.h" |
| 44 | |
| 45 | MODULE_DESCRIPTION("R8A66597 USB Host Controller Driver"); |
| 46 | MODULE_LICENSE("GPL"); |
| 47 | MODULE_AUTHOR("Yoshihiro Shimoda"); |
Kay Sievers | f4fce61 | 2008-04-10 21:29:22 -0700 | [diff] [blame] | 48 | MODULE_ALIAS("platform:r8a66597_hcd"); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 49 | |
Yoshihiro Shimoda | 5effabb | 2009-05-26 18:24:34 +0900 | [diff] [blame] | 50 | #define DRIVER_VERSION "2009-05-26" |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 51 | |
| 52 | static const char hcd_name[] = "r8a66597_hcd"; |
| 53 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 54 | static void packet_write(struct r8a66597 *r8a66597, u16 pipenum); |
| 55 | static int r8a66597_get_frame(struct usb_hcd *hcd); |
| 56 | |
| 57 | /* this function must be called with interrupt disabled */ |
| 58 | static void enable_pipe_irq(struct r8a66597 *r8a66597, u16 pipenum, |
| 59 | unsigned long reg) |
| 60 | { |
| 61 | u16 tmp; |
| 62 | |
| 63 | tmp = r8a66597_read(r8a66597, INTENB0); |
| 64 | r8a66597_bclr(r8a66597, BEMPE | NRDYE | BRDYE, INTENB0); |
| 65 | r8a66597_bset(r8a66597, 1 << pipenum, reg); |
| 66 | r8a66597_write(r8a66597, tmp, INTENB0); |
| 67 | } |
| 68 | |
| 69 | /* this function must be called with interrupt disabled */ |
| 70 | static void disable_pipe_irq(struct r8a66597 *r8a66597, u16 pipenum, |
| 71 | unsigned long reg) |
| 72 | { |
| 73 | u16 tmp; |
| 74 | |
| 75 | tmp = r8a66597_read(r8a66597, INTENB0); |
| 76 | r8a66597_bclr(r8a66597, BEMPE | NRDYE | BRDYE, INTENB0); |
| 77 | r8a66597_bclr(r8a66597, 1 << pipenum, reg); |
| 78 | r8a66597_write(r8a66597, tmp, INTENB0); |
| 79 | } |
| 80 | |
| 81 | static void set_devadd_reg(struct r8a66597 *r8a66597, u8 r8a66597_address, |
| 82 | u16 usbspd, u8 upphub, u8 hubport, int port) |
| 83 | { |
| 84 | u16 val; |
| 85 | unsigned long devadd_reg = get_devadd_addr(r8a66597_address); |
| 86 | |
| 87 | val = (upphub << 11) | (hubport << 8) | (usbspd << 6) | (port & 0x0001); |
| 88 | r8a66597_write(r8a66597, val, devadd_reg); |
| 89 | } |
| 90 | |
Yoshihiro Shimoda | 9424ea2 | 2008-04-10 21:05:58 +0900 | [diff] [blame] | 91 | static int r8a66597_clock_enable(struct r8a66597 *r8a66597) |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 92 | { |
| 93 | u16 tmp; |
| 94 | int i = 0; |
| 95 | |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 96 | if (r8a66597->pdata->on_chip) { |
| 97 | #ifdef CONFIG_HAVE_CLK |
| 98 | clk_enable(r8a66597->clk); |
Magnus Damm | 765786e | 2008-10-31 20:22:38 +0900 | [diff] [blame] | 99 | #endif |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 100 | do { |
| 101 | r8a66597_write(r8a66597, SCKE, SYSCFG0); |
| 102 | tmp = r8a66597_read(r8a66597, SYSCFG0); |
| 103 | if (i++ > 1000) { |
| 104 | printk(KERN_ERR "r8a66597: reg access fail.\n"); |
| 105 | return -ENXIO; |
| 106 | } |
| 107 | } while ((tmp & SCKE) != SCKE); |
| 108 | r8a66597_write(r8a66597, 0x04, 0x02); |
| 109 | } else { |
| 110 | do { |
| 111 | r8a66597_write(r8a66597, USBE, SYSCFG0); |
| 112 | tmp = r8a66597_read(r8a66597, SYSCFG0); |
| 113 | if (i++ > 1000) { |
| 114 | printk(KERN_ERR "r8a66597: reg access fail.\n"); |
| 115 | return -ENXIO; |
| 116 | } |
| 117 | } while ((tmp & USBE) != USBE); |
| 118 | r8a66597_bclr(r8a66597, USBE, SYSCFG0); |
| 119 | r8a66597_mdfy(r8a66597, get_xtal_from_pdata(r8a66597->pdata), |
| 120 | XTAL, SYSCFG0); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 121 | |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 122 | i = 0; |
| 123 | r8a66597_bset(r8a66597, XCKE, SYSCFG0); |
| 124 | do { |
| 125 | msleep(1); |
| 126 | tmp = r8a66597_read(r8a66597, SYSCFG0); |
| 127 | if (i++ > 500) { |
| 128 | printk(KERN_ERR "r8a66597: reg access fail.\n"); |
| 129 | return -ENXIO; |
| 130 | } |
| 131 | } while ((tmp & SCKE) != SCKE); |
| 132 | } |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 133 | |
Yoshihiro Shimoda | 9424ea2 | 2008-04-10 21:05:58 +0900 | [diff] [blame] | 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | static void r8a66597_clock_disable(struct r8a66597 *r8a66597) |
| 138 | { |
| 139 | r8a66597_bclr(r8a66597, SCKE, SYSCFG0); |
| 140 | udelay(1); |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 141 | |
| 142 | if (r8a66597->pdata->on_chip) { |
| 143 | #ifdef CONFIG_HAVE_CLK |
| 144 | clk_disable(r8a66597->clk); |
Magnus Damm | 765786e | 2008-10-31 20:22:38 +0900 | [diff] [blame] | 145 | #endif |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 146 | } else { |
| 147 | r8a66597_bclr(r8a66597, PLLC, SYSCFG0); |
| 148 | r8a66597_bclr(r8a66597, XCKE, SYSCFG0); |
| 149 | r8a66597_bclr(r8a66597, USBE, SYSCFG0); |
| 150 | } |
Yoshihiro Shimoda | 9424ea2 | 2008-04-10 21:05:58 +0900 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | static void r8a66597_enable_port(struct r8a66597 *r8a66597, int port) |
| 154 | { |
| 155 | u16 val; |
| 156 | |
| 157 | val = port ? DRPD : DCFM | DRPD; |
| 158 | r8a66597_bset(r8a66597, val, get_syscfg_reg(port)); |
| 159 | r8a66597_bset(r8a66597, HSE, get_syscfg_reg(port)); |
| 160 | |
| 161 | r8a66597_write(r8a66597, BURST | CPU_ADR_RD_WR, get_dmacfg_reg(port)); |
| 162 | r8a66597_bclr(r8a66597, DTCHE, get_intenb_reg(port)); |
| 163 | r8a66597_bset(r8a66597, ATTCHE, get_intenb_reg(port)); |
| 164 | } |
| 165 | |
| 166 | static void r8a66597_disable_port(struct r8a66597 *r8a66597, int port) |
| 167 | { |
| 168 | u16 val, tmp; |
| 169 | |
| 170 | r8a66597_write(r8a66597, 0, get_intenb_reg(port)); |
| 171 | r8a66597_write(r8a66597, 0, get_intsts_reg(port)); |
| 172 | |
| 173 | r8a66597_port_power(r8a66597, port, 0); |
| 174 | |
| 175 | do { |
| 176 | tmp = r8a66597_read(r8a66597, SOFCFG) & EDGESTS; |
| 177 | udelay(640); |
| 178 | } while (tmp == EDGESTS); |
| 179 | |
| 180 | val = port ? DRPD : DCFM | DRPD; |
| 181 | r8a66597_bclr(r8a66597, val, get_syscfg_reg(port)); |
| 182 | r8a66597_bclr(r8a66597, HSE, get_syscfg_reg(port)); |
| 183 | } |
| 184 | |
| 185 | static int enable_controller(struct r8a66597 *r8a66597) |
| 186 | { |
| 187 | int ret, port; |
Yoshihiro Shimoda | 5effabb | 2009-05-26 18:24:34 +0900 | [diff] [blame] | 188 | u16 vif = r8a66597->pdata->vif ? LDRV : 0; |
| 189 | u16 irq_sense = r8a66597->irq_sense_low ? INTL : 0; |
| 190 | u16 endian = r8a66597->pdata->endian ? BIGEND : 0; |
Yoshihiro Shimoda | 9424ea2 | 2008-04-10 21:05:58 +0900 | [diff] [blame] | 191 | |
| 192 | ret = r8a66597_clock_enable(r8a66597); |
| 193 | if (ret < 0) |
| 194 | return ret; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 195 | |
| 196 | r8a66597_bset(r8a66597, vif & LDRV, PINCFG); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 197 | r8a66597_bset(r8a66597, USBE, SYSCFG0); |
| 198 | |
| 199 | r8a66597_bset(r8a66597, BEMPE | NRDYE | BRDYE, INTENB0); |
| 200 | r8a66597_bset(r8a66597, irq_sense & INTL, SOFCFG); |
| 201 | r8a66597_bset(r8a66597, BRDY0, BRDYENB); |
| 202 | r8a66597_bset(r8a66597, BEMP0, BEMPENB); |
| 203 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 204 | r8a66597_bset(r8a66597, endian & BIGEND, CFIFOSEL); |
| 205 | r8a66597_bset(r8a66597, endian & BIGEND, D0FIFOSEL); |
| 206 | r8a66597_bset(r8a66597, endian & BIGEND, D1FIFOSEL); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 207 | r8a66597_bset(r8a66597, TRNENSEL, SOFCFG); |
| 208 | |
| 209 | r8a66597_bset(r8a66597, SIGNE | SACKE, INTENB1); |
Yoshihiro Shimoda | 9424ea2 | 2008-04-10 21:05:58 +0900 | [diff] [blame] | 210 | |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 211 | for (port = 0; port < r8a66597->max_root_hub; port++) |
Yoshihiro Shimoda | 9424ea2 | 2008-04-10 21:05:58 +0900 | [diff] [blame] | 212 | r8a66597_enable_port(r8a66597, port); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 213 | |
| 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | static void disable_controller(struct r8a66597 *r8a66597) |
| 218 | { |
Yoshihiro Shimoda | 9424ea2 | 2008-04-10 21:05:58 +0900 | [diff] [blame] | 219 | int port; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 220 | |
Magnus Damm | e5ff15b | 2010-01-27 07:41:19 +0000 | [diff] [blame] | 221 | /* disable interrupts */ |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 222 | r8a66597_write(r8a66597, 0, INTENB0); |
Magnus Damm | e5ff15b | 2010-01-27 07:41:19 +0000 | [diff] [blame] | 223 | r8a66597_write(r8a66597, 0, INTENB1); |
| 224 | r8a66597_write(r8a66597, 0, BRDYENB); |
| 225 | r8a66597_write(r8a66597, 0, BEMPENB); |
| 226 | r8a66597_write(r8a66597, 0, NRDYENB); |
| 227 | |
| 228 | /* clear status */ |
| 229 | r8a66597_write(r8a66597, 0, BRDYSTS); |
| 230 | r8a66597_write(r8a66597, 0, NRDYSTS); |
| 231 | r8a66597_write(r8a66597, 0, BEMPSTS); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 232 | |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 233 | for (port = 0; port < r8a66597->max_root_hub; port++) |
Yoshihiro Shimoda | 9424ea2 | 2008-04-10 21:05:58 +0900 | [diff] [blame] | 234 | r8a66597_disable_port(r8a66597, port); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 235 | |
Yoshihiro Shimoda | 9424ea2 | 2008-04-10 21:05:58 +0900 | [diff] [blame] | 236 | r8a66597_clock_disable(r8a66597); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | static int get_parent_r8a66597_address(struct r8a66597 *r8a66597, |
| 240 | struct usb_device *udev) |
| 241 | { |
| 242 | struct r8a66597_device *dev; |
| 243 | |
| 244 | if (udev->parent && udev->parent->devnum != 1) |
| 245 | udev = udev->parent; |
| 246 | |
| 247 | dev = dev_get_drvdata(&udev->dev); |
| 248 | if (dev) |
| 249 | return dev->address; |
| 250 | else |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | static int is_child_device(char *devpath) |
| 255 | { |
| 256 | return (devpath[2] ? 1 : 0); |
| 257 | } |
| 258 | |
| 259 | static int is_hub_limit(char *devpath) |
| 260 | { |
| 261 | return ((strlen(devpath) >= 4) ? 1 : 0); |
| 262 | } |
| 263 | |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 264 | static void get_port_number(struct r8a66597 *r8a66597, |
| 265 | char *devpath, u16 *root_port, u16 *hub_port) |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 266 | { |
| 267 | if (root_port) { |
| 268 | *root_port = (devpath[0] & 0x0F) - 1; |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 269 | if (*root_port >= r8a66597->max_root_hub) |
Greg Kroah-Hartman | 802f389 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 270 | printk(KERN_ERR "r8a66597: Illegal root port number.\n"); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 271 | } |
| 272 | if (hub_port) |
| 273 | *hub_port = devpath[2] & 0x0F; |
| 274 | } |
| 275 | |
| 276 | static u16 get_r8a66597_usb_speed(enum usb_device_speed speed) |
| 277 | { |
| 278 | u16 usbspd = 0; |
| 279 | |
| 280 | switch (speed) { |
| 281 | case USB_SPEED_LOW: |
| 282 | usbspd = LSMODE; |
| 283 | break; |
| 284 | case USB_SPEED_FULL: |
| 285 | usbspd = FSMODE; |
| 286 | break; |
| 287 | case USB_SPEED_HIGH: |
| 288 | usbspd = HSMODE; |
| 289 | break; |
| 290 | default: |
Greg Kroah-Hartman | 802f389 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 291 | printk(KERN_ERR "r8a66597: unknown speed\n"); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 292 | break; |
| 293 | } |
| 294 | |
| 295 | return usbspd; |
| 296 | } |
| 297 | |
| 298 | static void set_child_connect_map(struct r8a66597 *r8a66597, int address) |
| 299 | { |
| 300 | int idx; |
| 301 | |
| 302 | idx = address / 32; |
| 303 | r8a66597->child_connect_map[idx] |= 1 << (address % 32); |
| 304 | } |
| 305 | |
| 306 | static void put_child_connect_map(struct r8a66597 *r8a66597, int address) |
| 307 | { |
| 308 | int idx; |
| 309 | |
| 310 | idx = address / 32; |
| 311 | r8a66597->child_connect_map[idx] &= ~(1 << (address % 32)); |
| 312 | } |
| 313 | |
| 314 | static void set_pipe_reg_addr(struct r8a66597_pipe *pipe, u8 dma_ch) |
| 315 | { |
| 316 | u16 pipenum = pipe->info.pipenum; |
Ming Lei | fe9b903 | 2008-06-08 16:13:03 +0800 | [diff] [blame] | 317 | const unsigned long fifoaddr[] = {D0FIFO, D1FIFO, CFIFO}; |
| 318 | const unsigned long fifosel[] = {D0FIFOSEL, D1FIFOSEL, CFIFOSEL}; |
| 319 | const unsigned long fifoctr[] = {D0FIFOCTR, D1FIFOCTR, CFIFOCTR}; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 320 | |
| 321 | if (dma_ch > R8A66597_PIPE_NO_DMA) /* dma fifo not use? */ |
| 322 | dma_ch = R8A66597_PIPE_NO_DMA; |
| 323 | |
| 324 | pipe->fifoaddr = fifoaddr[dma_ch]; |
| 325 | pipe->fifosel = fifosel[dma_ch]; |
| 326 | pipe->fifoctr = fifoctr[dma_ch]; |
| 327 | |
| 328 | if (pipenum == 0) |
| 329 | pipe->pipectr = DCPCTR; |
| 330 | else |
| 331 | pipe->pipectr = get_pipectr_addr(pipenum); |
| 332 | |
| 333 | if (check_bulk_or_isoc(pipenum)) { |
| 334 | pipe->pipetre = get_pipetre_addr(pipenum); |
| 335 | pipe->pipetrn = get_pipetrn_addr(pipenum); |
| 336 | } else { |
| 337 | pipe->pipetre = 0; |
| 338 | pipe->pipetrn = 0; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | static struct r8a66597_device * |
| 343 | get_urb_to_r8a66597_dev(struct r8a66597 *r8a66597, struct urb *urb) |
| 344 | { |
| 345 | if (usb_pipedevice(urb->pipe) == 0) |
| 346 | return &r8a66597->device0; |
| 347 | |
| 348 | return dev_get_drvdata(&urb->dev->dev); |
| 349 | } |
| 350 | |
| 351 | static int make_r8a66597_device(struct r8a66597 *r8a66597, |
| 352 | struct urb *urb, u8 addr) |
| 353 | { |
| 354 | struct r8a66597_device *dev; |
| 355 | int usb_address = urb->setup_packet[2]; /* urb->pipe is address 0 */ |
| 356 | |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 357 | dev = kzalloc(sizeof(struct r8a66597_device), GFP_ATOMIC); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 358 | if (dev == NULL) |
| 359 | return -ENOMEM; |
| 360 | |
| 361 | dev_set_drvdata(&urb->dev->dev, dev); |
| 362 | dev->udev = urb->dev; |
| 363 | dev->address = addr; |
| 364 | dev->usb_address = usb_address; |
| 365 | dev->state = USB_STATE_ADDRESS; |
| 366 | dev->ep_in_toggle = 0; |
| 367 | dev->ep_out_toggle = 0; |
| 368 | INIT_LIST_HEAD(&dev->device_list); |
| 369 | list_add_tail(&dev->device_list, &r8a66597->child_device); |
| 370 | |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 371 | get_port_number(r8a66597, urb->dev->devpath, |
| 372 | &dev->root_port, &dev->hub_port); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 373 | if (!is_child_device(urb->dev->devpath)) |
| 374 | r8a66597->root_hub[dev->root_port].dev = dev; |
| 375 | |
| 376 | set_devadd_reg(r8a66597, dev->address, |
| 377 | get_r8a66597_usb_speed(urb->dev->speed), |
| 378 | get_parent_r8a66597_address(r8a66597, urb->dev), |
| 379 | dev->hub_port, dev->root_port); |
| 380 | |
| 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | /* this function must be called with interrupt disabled */ |
| 385 | static u8 alloc_usb_address(struct r8a66597 *r8a66597, struct urb *urb) |
| 386 | { |
| 387 | u8 addr; /* R8A66597's address */ |
| 388 | struct r8a66597_device *dev; |
| 389 | |
| 390 | if (is_hub_limit(urb->dev->devpath)) { |
Greg Kroah-Hartman | 802f389 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 391 | dev_err(&urb->dev->dev, "External hub limit reached.\n"); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 392 | return 0; |
| 393 | } |
| 394 | |
| 395 | dev = get_urb_to_r8a66597_dev(r8a66597, urb); |
| 396 | if (dev && dev->state >= USB_STATE_ADDRESS) |
| 397 | return dev->address; |
| 398 | |
| 399 | for (addr = 1; addr <= R8A66597_MAX_DEVICE; addr++) { |
| 400 | if (r8a66597->address_map & (1 << addr)) |
| 401 | continue; |
| 402 | |
| 403 | dbg("alloc_address: r8a66597_addr=%d", addr); |
| 404 | r8a66597->address_map |= 1 << addr; |
| 405 | |
| 406 | if (make_r8a66597_device(r8a66597, urb, addr) < 0) |
| 407 | return 0; |
| 408 | |
| 409 | return addr; |
| 410 | } |
| 411 | |
Greg Kroah-Hartman | 802f389 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 412 | dev_err(&urb->dev->dev, |
| 413 | "cannot communicate with a USB device more than 10.(%x)\n", |
| 414 | r8a66597->address_map); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 415 | |
| 416 | return 0; |
| 417 | } |
| 418 | |
| 419 | /* this function must be called with interrupt disabled */ |
| 420 | static void free_usb_address(struct r8a66597 *r8a66597, |
| 421 | struct r8a66597_device *dev) |
| 422 | { |
| 423 | int port; |
| 424 | |
| 425 | if (!dev) |
| 426 | return; |
| 427 | |
| 428 | dbg("free_addr: addr=%d", dev->address); |
| 429 | |
| 430 | dev->state = USB_STATE_DEFAULT; |
| 431 | r8a66597->address_map &= ~(1 << dev->address); |
| 432 | dev->address = 0; |
| 433 | dev_set_drvdata(&dev->udev->dev, NULL); |
| 434 | list_del(&dev->device_list); |
| 435 | kfree(dev); |
| 436 | |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 437 | for (port = 0; port < r8a66597->max_root_hub; port++) { |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 438 | if (r8a66597->root_hub[port].dev == dev) { |
| 439 | r8a66597->root_hub[port].dev = NULL; |
| 440 | break; |
| 441 | } |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | static void r8a66597_reg_wait(struct r8a66597 *r8a66597, unsigned long reg, |
| 446 | u16 mask, u16 loop) |
| 447 | { |
| 448 | u16 tmp; |
| 449 | int i = 0; |
| 450 | |
| 451 | do { |
| 452 | tmp = r8a66597_read(r8a66597, reg); |
| 453 | if (i++ > 1000000) { |
Greg Kroah-Hartman | 802f389 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 454 | printk(KERN_ERR "r8a66597: register%lx, loop %x " |
| 455 | "is timeout\n", reg, loop); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 456 | break; |
| 457 | } |
| 458 | ndelay(1); |
| 459 | } while ((tmp & mask) != loop); |
| 460 | } |
| 461 | |
| 462 | /* this function must be called with interrupt disabled */ |
| 463 | static void pipe_start(struct r8a66597 *r8a66597, struct r8a66597_pipe *pipe) |
| 464 | { |
| 465 | u16 tmp; |
| 466 | |
| 467 | tmp = r8a66597_read(r8a66597, pipe->pipectr) & PID; |
| 468 | if ((pipe->info.pipenum != 0) & ((tmp & PID_STALL) != 0)) /* stall? */ |
| 469 | r8a66597_mdfy(r8a66597, PID_NAK, PID, pipe->pipectr); |
| 470 | r8a66597_mdfy(r8a66597, PID_BUF, PID, pipe->pipectr); |
| 471 | } |
| 472 | |
| 473 | /* this function must be called with interrupt disabled */ |
| 474 | static void pipe_stop(struct r8a66597 *r8a66597, struct r8a66597_pipe *pipe) |
| 475 | { |
| 476 | u16 tmp; |
| 477 | |
| 478 | tmp = r8a66597_read(r8a66597, pipe->pipectr) & PID; |
| 479 | if ((tmp & PID_STALL11) != PID_STALL11) /* force stall? */ |
| 480 | r8a66597_mdfy(r8a66597, PID_STALL, PID, pipe->pipectr); |
| 481 | r8a66597_mdfy(r8a66597, PID_NAK, PID, pipe->pipectr); |
| 482 | r8a66597_reg_wait(r8a66597, pipe->pipectr, PBUSY, 0); |
| 483 | } |
| 484 | |
| 485 | /* this function must be called with interrupt disabled */ |
| 486 | static void clear_all_buffer(struct r8a66597 *r8a66597, |
| 487 | struct r8a66597_pipe *pipe) |
| 488 | { |
| 489 | u16 tmp; |
| 490 | |
| 491 | if (!pipe || pipe->info.pipenum == 0) |
| 492 | return; |
| 493 | |
| 494 | pipe_stop(r8a66597, pipe); |
| 495 | r8a66597_bset(r8a66597, ACLRM, pipe->pipectr); |
| 496 | tmp = r8a66597_read(r8a66597, pipe->pipectr); |
| 497 | tmp = r8a66597_read(r8a66597, pipe->pipectr); |
| 498 | tmp = r8a66597_read(r8a66597, pipe->pipectr); |
| 499 | r8a66597_bclr(r8a66597, ACLRM, pipe->pipectr); |
| 500 | } |
| 501 | |
| 502 | /* this function must be called with interrupt disabled */ |
| 503 | static void r8a66597_pipe_toggle(struct r8a66597 *r8a66597, |
| 504 | struct r8a66597_pipe *pipe, int toggle) |
| 505 | { |
| 506 | if (toggle) |
| 507 | r8a66597_bset(r8a66597, SQSET, pipe->pipectr); |
| 508 | else |
| 509 | r8a66597_bset(r8a66597, SQCLR, pipe->pipectr); |
| 510 | } |
| 511 | |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 512 | static inline unsigned short mbw_value(struct r8a66597 *r8a66597) |
| 513 | { |
| 514 | if (r8a66597->pdata->on_chip) |
| 515 | return MBW_32; |
| 516 | else |
| 517 | return MBW_16; |
| 518 | } |
| 519 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 520 | /* this function must be called with interrupt disabled */ |
| 521 | static inline void cfifo_change(struct r8a66597 *r8a66597, u16 pipenum) |
| 522 | { |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 523 | unsigned short mbw = mbw_value(r8a66597); |
| 524 | |
| 525 | r8a66597_mdfy(r8a66597, mbw | pipenum, mbw | CURPIPE, CFIFOSEL); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 526 | r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, pipenum); |
| 527 | } |
| 528 | |
| 529 | /* this function must be called with interrupt disabled */ |
| 530 | static inline void fifo_change_from_pipe(struct r8a66597 *r8a66597, |
| 531 | struct r8a66597_pipe *pipe) |
| 532 | { |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 533 | unsigned short mbw = mbw_value(r8a66597); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 534 | |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 535 | cfifo_change(r8a66597, 0); |
| 536 | r8a66597_mdfy(r8a66597, mbw | 0, mbw | CURPIPE, D0FIFOSEL); |
| 537 | r8a66597_mdfy(r8a66597, mbw | 0, mbw | CURPIPE, D1FIFOSEL); |
| 538 | |
| 539 | r8a66597_mdfy(r8a66597, mbw | pipe->info.pipenum, mbw | CURPIPE, |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 540 | pipe->fifosel); |
| 541 | r8a66597_reg_wait(r8a66597, pipe->fifosel, CURPIPE, pipe->info.pipenum); |
| 542 | } |
| 543 | |
| 544 | static u16 r8a66597_get_pipenum(struct urb *urb, struct usb_host_endpoint *hep) |
| 545 | { |
| 546 | struct r8a66597_pipe *pipe = hep->hcpriv; |
| 547 | |
| 548 | if (usb_pipeendpoint(urb->pipe) == 0) |
| 549 | return 0; |
| 550 | else |
| 551 | return pipe->info.pipenum; |
| 552 | } |
| 553 | |
| 554 | static u16 get_urb_to_r8a66597_addr(struct r8a66597 *r8a66597, struct urb *urb) |
| 555 | { |
| 556 | struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb); |
| 557 | |
| 558 | return (usb_pipedevice(urb->pipe) == 0) ? 0 : dev->address; |
| 559 | } |
| 560 | |
| 561 | static unsigned short *get_toggle_pointer(struct r8a66597_device *dev, |
| 562 | int urb_pipe) |
| 563 | { |
| 564 | if (!dev) |
| 565 | return NULL; |
| 566 | |
| 567 | return usb_pipein(urb_pipe) ? &dev->ep_in_toggle : &dev->ep_out_toggle; |
| 568 | } |
| 569 | |
| 570 | /* this function must be called with interrupt disabled */ |
| 571 | static void pipe_toggle_set(struct r8a66597 *r8a66597, |
| 572 | struct r8a66597_pipe *pipe, |
| 573 | struct urb *urb, int set) |
| 574 | { |
| 575 | struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb); |
| 576 | unsigned char endpoint = usb_pipeendpoint(urb->pipe); |
| 577 | unsigned short *toggle = get_toggle_pointer(dev, urb->pipe); |
| 578 | |
| 579 | if (!toggle) |
| 580 | return; |
| 581 | |
| 582 | if (set) |
| 583 | *toggle |= 1 << endpoint; |
| 584 | else |
| 585 | *toggle &= ~(1 << endpoint); |
| 586 | } |
| 587 | |
| 588 | /* this function must be called with interrupt disabled */ |
| 589 | static void pipe_toggle_save(struct r8a66597 *r8a66597, |
| 590 | struct r8a66597_pipe *pipe, |
| 591 | struct urb *urb) |
| 592 | { |
| 593 | if (r8a66597_read(r8a66597, pipe->pipectr) & SQMON) |
| 594 | pipe_toggle_set(r8a66597, pipe, urb, 1); |
| 595 | else |
| 596 | pipe_toggle_set(r8a66597, pipe, urb, 0); |
| 597 | } |
| 598 | |
| 599 | /* this function must be called with interrupt disabled */ |
| 600 | static void pipe_toggle_restore(struct r8a66597 *r8a66597, |
| 601 | struct r8a66597_pipe *pipe, |
| 602 | struct urb *urb) |
| 603 | { |
| 604 | struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb); |
| 605 | unsigned char endpoint = usb_pipeendpoint(urb->pipe); |
| 606 | unsigned short *toggle = get_toggle_pointer(dev, urb->pipe); |
| 607 | |
Yoshihiro Shimoda | f6ace2c | 2007-05-30 20:42:41 +0900 | [diff] [blame] | 608 | if (!toggle) |
| 609 | return; |
| 610 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 611 | r8a66597_pipe_toggle(r8a66597, pipe, *toggle & (1 << endpoint)); |
| 612 | } |
| 613 | |
| 614 | /* this function must be called with interrupt disabled */ |
| 615 | static void pipe_buffer_setting(struct r8a66597 *r8a66597, |
| 616 | struct r8a66597_pipe_info *info) |
| 617 | { |
| 618 | u16 val = 0; |
| 619 | |
| 620 | if (info->pipenum == 0) |
| 621 | return; |
| 622 | |
| 623 | r8a66597_bset(r8a66597, ACLRM, get_pipectr_addr(info->pipenum)); |
| 624 | r8a66597_bclr(r8a66597, ACLRM, get_pipectr_addr(info->pipenum)); |
| 625 | r8a66597_write(r8a66597, info->pipenum, PIPESEL); |
| 626 | if (!info->dir_in) |
| 627 | val |= R8A66597_DIR; |
| 628 | if (info->type == R8A66597_BULK && info->dir_in) |
| 629 | val |= R8A66597_DBLB | R8A66597_SHTNAK; |
| 630 | val |= info->type | info->epnum; |
| 631 | r8a66597_write(r8a66597, val, PIPECFG); |
| 632 | |
| 633 | r8a66597_write(r8a66597, (info->buf_bsize << 10) | (info->bufnum), |
| 634 | PIPEBUF); |
| 635 | r8a66597_write(r8a66597, make_devsel(info->address) | info->maxpacket, |
| 636 | PIPEMAXP); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 637 | r8a66597_write(r8a66597, info->interval, PIPEPERI); |
| 638 | } |
| 639 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 640 | /* this function must be called with interrupt disabled */ |
| 641 | static void pipe_setting(struct r8a66597 *r8a66597, struct r8a66597_td *td) |
| 642 | { |
| 643 | struct r8a66597_pipe_info *info; |
| 644 | struct urb *urb = td->urb; |
| 645 | |
| 646 | if (td->pipenum > 0) { |
| 647 | info = &td->pipe->info; |
| 648 | cfifo_change(r8a66597, 0); |
| 649 | pipe_buffer_setting(r8a66597, info); |
| 650 | |
| 651 | if (!usb_gettoggle(urb->dev, usb_pipeendpoint(urb->pipe), |
| 652 | usb_pipeout(urb->pipe)) && |
| 653 | !usb_pipecontrol(urb->pipe)) { |
| 654 | r8a66597_pipe_toggle(r8a66597, td->pipe, 0); |
| 655 | pipe_toggle_set(r8a66597, td->pipe, urb, 0); |
| 656 | clear_all_buffer(r8a66597, td->pipe); |
| 657 | usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), |
| 658 | usb_pipeout(urb->pipe), 1); |
| 659 | } |
| 660 | pipe_toggle_restore(r8a66597, td->pipe, urb); |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | /* this function must be called with interrupt disabled */ |
| 665 | static u16 get_empty_pipenum(struct r8a66597 *r8a66597, |
| 666 | struct usb_endpoint_descriptor *ep) |
| 667 | { |
| 668 | u16 array[R8A66597_MAX_NUM_PIPE], i = 0, min; |
| 669 | |
| 670 | memset(array, 0, sizeof(array)); |
Julia Lawall | 2e0fe70 | 2008-12-29 11:22:14 +0100 | [diff] [blame] | 671 | switch (usb_endpoint_type(ep)) { |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 672 | case USB_ENDPOINT_XFER_BULK: |
Julia Lawall | 2e0fe70 | 2008-12-29 11:22:14 +0100 | [diff] [blame] | 673 | if (usb_endpoint_dir_in(ep)) |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 674 | array[i++] = 4; |
| 675 | else { |
| 676 | array[i++] = 3; |
| 677 | array[i++] = 5; |
| 678 | } |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 679 | break; |
| 680 | case USB_ENDPOINT_XFER_INT: |
Julia Lawall | 2e0fe70 | 2008-12-29 11:22:14 +0100 | [diff] [blame] | 681 | if (usb_endpoint_dir_in(ep)) { |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 682 | array[i++] = 6; |
| 683 | array[i++] = 7; |
| 684 | array[i++] = 8; |
| 685 | } else |
| 686 | array[i++] = 9; |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 687 | break; |
| 688 | case USB_ENDPOINT_XFER_ISOC: |
Julia Lawall | 2e0fe70 | 2008-12-29 11:22:14 +0100 | [diff] [blame] | 689 | if (usb_endpoint_dir_in(ep)) |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 690 | array[i++] = 2; |
| 691 | else |
| 692 | array[i++] = 1; |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 693 | break; |
| 694 | default: |
Greg Kroah-Hartman | 802f389 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 695 | printk(KERN_ERR "r8a66597: Illegal type\n"); |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 696 | return 0; |
| 697 | } |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 698 | |
| 699 | i = 1; |
| 700 | min = array[0]; |
| 701 | while (array[i] != 0) { |
| 702 | if (r8a66597->pipe_cnt[min] > r8a66597->pipe_cnt[array[i]]) |
| 703 | min = array[i]; |
| 704 | i++; |
| 705 | } |
| 706 | |
| 707 | return min; |
| 708 | } |
| 709 | |
| 710 | static u16 get_r8a66597_type(__u8 type) |
| 711 | { |
| 712 | u16 r8a66597_type; |
| 713 | |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 714 | switch (type) { |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 715 | case USB_ENDPOINT_XFER_BULK: |
| 716 | r8a66597_type = R8A66597_BULK; |
| 717 | break; |
| 718 | case USB_ENDPOINT_XFER_INT: |
| 719 | r8a66597_type = R8A66597_INT; |
| 720 | break; |
| 721 | case USB_ENDPOINT_XFER_ISOC: |
| 722 | r8a66597_type = R8A66597_ISO; |
| 723 | break; |
| 724 | default: |
Greg Kroah-Hartman | 802f389 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 725 | printk(KERN_ERR "r8a66597: Illegal type\n"); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 726 | r8a66597_type = 0x0000; |
| 727 | break; |
| 728 | } |
| 729 | |
| 730 | return r8a66597_type; |
| 731 | } |
| 732 | |
| 733 | static u16 get_bufnum(u16 pipenum) |
| 734 | { |
| 735 | u16 bufnum = 0; |
| 736 | |
| 737 | if (pipenum == 0) |
| 738 | bufnum = 0; |
| 739 | else if (check_bulk_or_isoc(pipenum)) |
| 740 | bufnum = 8 + (pipenum - 1) * R8A66597_BUF_BSIZE*2; |
| 741 | else if (check_interrupt(pipenum)) |
| 742 | bufnum = 4 + (pipenum - 6); |
| 743 | else |
Greg Kroah-Hartman | 802f389 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 744 | printk(KERN_ERR "r8a66597: Illegal pipenum (%d)\n", pipenum); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 745 | |
| 746 | return bufnum; |
| 747 | } |
| 748 | |
| 749 | static u16 get_buf_bsize(u16 pipenum) |
| 750 | { |
| 751 | u16 buf_bsize = 0; |
| 752 | |
| 753 | if (pipenum == 0) |
| 754 | buf_bsize = 3; |
| 755 | else if (check_bulk_or_isoc(pipenum)) |
| 756 | buf_bsize = R8A66597_BUF_BSIZE - 1; |
| 757 | else if (check_interrupt(pipenum)) |
| 758 | buf_bsize = 0; |
| 759 | else |
Greg Kroah-Hartman | 802f389 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 760 | printk(KERN_ERR "r8a66597: Illegal pipenum (%d)\n", pipenum); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 761 | |
| 762 | return buf_bsize; |
| 763 | } |
| 764 | |
| 765 | /* this function must be called with interrupt disabled */ |
| 766 | static void enable_r8a66597_pipe_dma(struct r8a66597 *r8a66597, |
| 767 | struct r8a66597_device *dev, |
| 768 | struct r8a66597_pipe *pipe, |
| 769 | struct urb *urb) |
| 770 | { |
| 771 | int i; |
| 772 | struct r8a66597_pipe_info *info = &pipe->info; |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 773 | unsigned short mbw = mbw_value(r8a66597); |
| 774 | |
| 775 | /* pipe dma is only for external controlles */ |
| 776 | if (r8a66597->pdata->on_chip) |
| 777 | return; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 778 | |
| 779 | if ((pipe->info.pipenum != 0) && (info->type != R8A66597_INT)) { |
| 780 | for (i = 0; i < R8A66597_MAX_DMA_CHANNEL; i++) { |
| 781 | if ((r8a66597->dma_map & (1 << i)) != 0) |
| 782 | continue; |
| 783 | |
Greg Kroah-Hartman | 5909f6e | 2008-08-18 13:21:04 -0700 | [diff] [blame] | 784 | dev_info(&dev->udev->dev, |
| 785 | "address %d, EndpointAddress 0x%02x use " |
| 786 | "DMA FIFO\n", usb_pipedevice(urb->pipe), |
| 787 | info->dir_in ? |
| 788 | USB_ENDPOINT_DIR_MASK + info->epnum |
| 789 | : info->epnum); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 790 | |
| 791 | r8a66597->dma_map |= 1 << i; |
| 792 | dev->dma_map |= 1 << i; |
| 793 | set_pipe_reg_addr(pipe, i); |
| 794 | |
| 795 | cfifo_change(r8a66597, 0); |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 796 | r8a66597_mdfy(r8a66597, mbw | pipe->info.pipenum, |
| 797 | mbw | CURPIPE, pipe->fifosel); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 798 | |
| 799 | r8a66597_reg_wait(r8a66597, pipe->fifosel, CURPIPE, |
| 800 | pipe->info.pipenum); |
| 801 | r8a66597_bset(r8a66597, BCLR, pipe->fifoctr); |
| 802 | break; |
| 803 | } |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | /* this function must be called with interrupt disabled */ |
| 808 | static void enable_r8a66597_pipe(struct r8a66597 *r8a66597, struct urb *urb, |
| 809 | struct usb_host_endpoint *hep, |
| 810 | struct r8a66597_pipe_info *info) |
| 811 | { |
| 812 | struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb); |
| 813 | struct r8a66597_pipe *pipe = hep->hcpriv; |
| 814 | |
| 815 | dbg("enable_pipe:"); |
| 816 | |
| 817 | pipe->info = *info; |
| 818 | set_pipe_reg_addr(pipe, R8A66597_PIPE_NO_DMA); |
| 819 | r8a66597->pipe_cnt[pipe->info.pipenum]++; |
| 820 | dev->pipe_cnt[pipe->info.pipenum]++; |
| 821 | |
| 822 | enable_r8a66597_pipe_dma(r8a66597, dev, pipe, urb); |
| 823 | } |
| 824 | |
Paul Mundt | 2717568 | 2010-02-04 06:57:58 +0000 | [diff] [blame^] | 825 | static void r8a66597_urb_done(struct r8a66597 *r8a66597, struct urb *urb, |
| 826 | int status) |
| 827 | __releases(r8a66597->lock) |
| 828 | __acquires(r8a66597->lock) |
| 829 | { |
| 830 | if (usb_pipein(urb->pipe) && usb_pipetype(urb->pipe) != PIPE_CONTROL) { |
| 831 | void *ptr; |
| 832 | |
| 833 | for (ptr = urb->transfer_buffer; |
| 834 | ptr < urb->transfer_buffer + urb->transfer_buffer_length; |
| 835 | ptr += PAGE_SIZE) |
| 836 | flush_dcache_page(virt_to_page(ptr)); |
| 837 | } |
| 838 | |
| 839 | usb_hcd_unlink_urb_from_ep(r8a66597_to_hcd(r8a66597), urb); |
| 840 | spin_unlock(&r8a66597->lock); |
| 841 | usb_hcd_giveback_urb(r8a66597_to_hcd(r8a66597), urb, status); |
| 842 | spin_lock(&r8a66597->lock); |
| 843 | } |
| 844 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 845 | /* this function must be called with interrupt disabled */ |
| 846 | static void force_dequeue(struct r8a66597 *r8a66597, u16 pipenum, u16 address) |
| 847 | { |
| 848 | struct r8a66597_td *td, *next; |
| 849 | struct urb *urb; |
| 850 | struct list_head *list = &r8a66597->pipe_queue[pipenum]; |
| 851 | |
| 852 | if (list_empty(list)) |
| 853 | return; |
| 854 | |
| 855 | list_for_each_entry_safe(td, next, list, queue) { |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 856 | if (td->address != address) |
| 857 | continue; |
| 858 | |
| 859 | urb = td->urb; |
| 860 | list_del(&td->queue); |
| 861 | kfree(td); |
| 862 | |
Paul Mundt | 2717568 | 2010-02-04 06:57:58 +0000 | [diff] [blame^] | 863 | if (urb) |
| 864 | r8a66597_urb_done(r8a66597, urb, -ENODEV); |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 865 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 866 | break; |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | /* this function must be called with interrupt disabled */ |
| 871 | static void disable_r8a66597_pipe_all(struct r8a66597 *r8a66597, |
| 872 | struct r8a66597_device *dev) |
| 873 | { |
| 874 | int check_ep0 = 0; |
| 875 | u16 pipenum; |
| 876 | |
| 877 | if (!dev) |
| 878 | return; |
| 879 | |
| 880 | for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) { |
| 881 | if (!dev->pipe_cnt[pipenum]) |
| 882 | continue; |
| 883 | |
| 884 | if (!check_ep0) { |
| 885 | check_ep0 = 1; |
| 886 | force_dequeue(r8a66597, 0, dev->address); |
| 887 | } |
| 888 | |
| 889 | r8a66597->pipe_cnt[pipenum] -= dev->pipe_cnt[pipenum]; |
| 890 | dev->pipe_cnt[pipenum] = 0; |
| 891 | force_dequeue(r8a66597, pipenum, dev->address); |
| 892 | } |
| 893 | |
| 894 | dbg("disable_pipe"); |
| 895 | |
| 896 | r8a66597->dma_map &= ~(dev->dma_map); |
| 897 | dev->dma_map = 0; |
| 898 | } |
| 899 | |
Yoshihiro Shimoda | 397f519 | 2008-06-27 19:09:58 +0900 | [diff] [blame] | 900 | static u16 get_interval(struct urb *urb, __u8 interval) |
| 901 | { |
| 902 | u16 time = 1; |
| 903 | int i; |
| 904 | |
| 905 | if (urb->dev->speed == USB_SPEED_HIGH) { |
| 906 | if (interval > IITV) |
| 907 | time = IITV; |
| 908 | else |
| 909 | time = interval ? interval - 1 : 0; |
| 910 | } else { |
| 911 | if (interval > 128) { |
| 912 | time = IITV; |
| 913 | } else { |
| 914 | /* calculate the nearest value for PIPEPERI */ |
| 915 | for (i = 0; i < 7; i++) { |
| 916 | if ((1 << i) < interval && |
| 917 | (1 << (i + 1) > interval)) |
| 918 | time = 1 << i; |
| 919 | } |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | return time; |
| 924 | } |
| 925 | |
Yoshihiro Shimoda | 6d87910 | 2008-04-10 21:05:47 +0900 | [diff] [blame] | 926 | static unsigned long get_timer_interval(struct urb *urb, __u8 interval) |
| 927 | { |
| 928 | __u8 i; |
| 929 | unsigned long time = 1; |
| 930 | |
| 931 | if (usb_pipeisoc(urb->pipe)) |
| 932 | return 0; |
| 933 | |
| 934 | if (get_r8a66597_usb_speed(urb->dev->speed) == HSMODE) { |
| 935 | for (i = 0; i < (interval - 1); i++) |
| 936 | time *= 2; |
| 937 | time = time * 125 / 1000; /* uSOF -> msec */ |
| 938 | } else { |
| 939 | time = interval; |
| 940 | } |
| 941 | |
| 942 | return time; |
| 943 | } |
| 944 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 945 | /* this function must be called with interrupt disabled */ |
| 946 | static void init_pipe_info(struct r8a66597 *r8a66597, struct urb *urb, |
| 947 | struct usb_host_endpoint *hep, |
| 948 | struct usb_endpoint_descriptor *ep) |
| 949 | { |
| 950 | struct r8a66597_pipe_info info; |
| 951 | |
| 952 | info.pipenum = get_empty_pipenum(r8a66597, ep); |
| 953 | info.address = get_urb_to_r8a66597_addr(r8a66597, urb); |
Julia Lawall | 2e0fe70 | 2008-12-29 11:22:14 +0100 | [diff] [blame] | 954 | info.epnum = usb_endpoint_num(ep); |
Yoshihiro Shimoda | 05eac91 | 2007-10-03 18:53:28 +0900 | [diff] [blame] | 955 | info.maxpacket = le16_to_cpu(ep->wMaxPacketSize); |
Julia Lawall | 2e0fe70 | 2008-12-29 11:22:14 +0100 | [diff] [blame] | 956 | info.type = get_r8a66597_type(usb_endpoint_type(ep)); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 957 | info.bufnum = get_bufnum(info.pipenum); |
| 958 | info.buf_bsize = get_buf_bsize(info.pipenum); |
Yoshihiro Shimoda | 6d87910 | 2008-04-10 21:05:47 +0900 | [diff] [blame] | 959 | if (info.type == R8A66597_BULK) { |
| 960 | info.interval = 0; |
| 961 | info.timer_interval = 0; |
| 962 | } else { |
Yoshihiro Shimoda | 397f519 | 2008-06-27 19:09:58 +0900 | [diff] [blame] | 963 | info.interval = get_interval(urb, ep->bInterval); |
Yoshihiro Shimoda | 6d87910 | 2008-04-10 21:05:47 +0900 | [diff] [blame] | 964 | info.timer_interval = get_timer_interval(urb, ep->bInterval); |
| 965 | } |
Julia Lawall | 2e0fe70 | 2008-12-29 11:22:14 +0100 | [diff] [blame] | 966 | if (usb_endpoint_dir_in(ep)) |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 967 | info.dir_in = 1; |
| 968 | else |
| 969 | info.dir_in = 0; |
| 970 | |
| 971 | enable_r8a66597_pipe(r8a66597, urb, hep, &info); |
| 972 | } |
| 973 | |
| 974 | static void init_pipe_config(struct r8a66597 *r8a66597, struct urb *urb) |
| 975 | { |
| 976 | struct r8a66597_device *dev; |
| 977 | |
| 978 | dev = get_urb_to_r8a66597_dev(r8a66597, urb); |
| 979 | dev->state = USB_STATE_CONFIGURED; |
| 980 | } |
| 981 | |
| 982 | static void pipe_irq_enable(struct r8a66597 *r8a66597, struct urb *urb, |
| 983 | u16 pipenum) |
| 984 | { |
| 985 | if (pipenum == 0 && usb_pipeout(urb->pipe)) |
| 986 | enable_irq_empty(r8a66597, pipenum); |
| 987 | else |
| 988 | enable_irq_ready(r8a66597, pipenum); |
| 989 | |
| 990 | if (!usb_pipeisoc(urb->pipe)) |
| 991 | enable_irq_nrdy(r8a66597, pipenum); |
| 992 | } |
| 993 | |
| 994 | static void pipe_irq_disable(struct r8a66597 *r8a66597, u16 pipenum) |
| 995 | { |
| 996 | disable_irq_ready(r8a66597, pipenum); |
| 997 | disable_irq_nrdy(r8a66597, pipenum); |
| 998 | } |
| 999 | |
Yoshihiro Shimoda | 54d0be9 | 2008-07-11 18:53:45 +0900 | [diff] [blame] | 1000 | static void r8a66597_root_hub_start_polling(struct r8a66597 *r8a66597) |
| 1001 | { |
| 1002 | mod_timer(&r8a66597->rh_timer, |
| 1003 | jiffies + msecs_to_jiffies(R8A66597_RH_POLL_TIME)); |
| 1004 | } |
| 1005 | |
| 1006 | static void start_root_hub_sampling(struct r8a66597 *r8a66597, int port, |
| 1007 | int connect) |
| 1008 | { |
| 1009 | struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; |
| 1010 | |
| 1011 | rh->old_syssts = r8a66597_read(r8a66597, get_syssts_reg(port)) & LNST; |
| 1012 | rh->scount = R8A66597_MAX_SAMPLING; |
| 1013 | if (connect) |
| 1014 | rh->port |= 1 << USB_PORT_FEAT_CONNECTION; |
| 1015 | else |
| 1016 | rh->port &= ~(1 << USB_PORT_FEAT_CONNECTION); |
| 1017 | rh->port |= 1 << USB_PORT_FEAT_C_CONNECTION; |
| 1018 | |
| 1019 | r8a66597_root_hub_start_polling(r8a66597); |
| 1020 | } |
| 1021 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1022 | /* this function must be called with interrupt disabled */ |
Yoshihiro Shimoda | 29fab0c | 2008-04-10 21:05:55 +0900 | [diff] [blame] | 1023 | static void r8a66597_check_syssts(struct r8a66597 *r8a66597, int port, |
| 1024 | u16 syssts) |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1025 | { |
Yoshihiro Shimoda | 29fab0c | 2008-04-10 21:05:55 +0900 | [diff] [blame] | 1026 | if (syssts == SE0) { |
Yoshihiro Shimoda | 54d0be9 | 2008-07-11 18:53:45 +0900 | [diff] [blame] | 1027 | r8a66597_write(r8a66597, ~ATTCH, get_intsts_reg(port)); |
Yoshihiro Shimoda | 29fab0c | 2008-04-10 21:05:55 +0900 | [diff] [blame] | 1028 | r8a66597_bset(r8a66597, ATTCHE, get_intenb_reg(port)); |
Yoshihiro Shimoda | 1e6159f | 2009-10-21 20:33:39 +0900 | [diff] [blame] | 1029 | } else { |
| 1030 | if (syssts == FS_JSTS) |
| 1031 | r8a66597_bset(r8a66597, HSE, get_syscfg_reg(port)); |
| 1032 | else if (syssts == LS_JSTS) |
| 1033 | r8a66597_bclr(r8a66597, HSE, get_syscfg_reg(port)); |
| 1034 | |
| 1035 | r8a66597_write(r8a66597, ~DTCH, get_intsts_reg(port)); |
| 1036 | r8a66597_bset(r8a66597, DTCHE, get_intenb_reg(port)); |
| 1037 | |
| 1038 | if (r8a66597->bus_suspended) |
| 1039 | usb_hcd_resume_root_hub(r8a66597_to_hcd(r8a66597)); |
Yoshihiro Shimoda | 29fab0c | 2008-04-10 21:05:55 +0900 | [diff] [blame] | 1040 | } |
| 1041 | |
Yoshihiro Shimoda | 1e6159f | 2009-10-21 20:33:39 +0900 | [diff] [blame] | 1042 | usb_hcd_poll_rh_status(r8a66597_to_hcd(r8a66597)); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | /* this function must be called with interrupt disabled */ |
| 1046 | static void r8a66597_usb_connect(struct r8a66597 *r8a66597, int port) |
| 1047 | { |
| 1048 | u16 speed = get_rh_usb_speed(r8a66597, port); |
| 1049 | struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; |
| 1050 | |
Yoshihiro Shimoda | 1e6159f | 2009-10-21 20:33:39 +0900 | [diff] [blame] | 1051 | rh->port &= ~((1 << USB_PORT_FEAT_HIGHSPEED) | |
| 1052 | (1 << USB_PORT_FEAT_LOWSPEED)); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1053 | if (speed == HSMODE) |
| 1054 | rh->port |= (1 << USB_PORT_FEAT_HIGHSPEED); |
| 1055 | else if (speed == LSMODE) |
| 1056 | rh->port |= (1 << USB_PORT_FEAT_LOWSPEED); |
| 1057 | |
| 1058 | rh->port &= ~(1 << USB_PORT_FEAT_RESET); |
| 1059 | rh->port |= 1 << USB_PORT_FEAT_ENABLE; |
| 1060 | } |
| 1061 | |
| 1062 | /* this function must be called with interrupt disabled */ |
| 1063 | static void r8a66597_usb_disconnect(struct r8a66597 *r8a66597, int port) |
| 1064 | { |
| 1065 | struct r8a66597_device *dev = r8a66597->root_hub[port].dev; |
| 1066 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1067 | disable_r8a66597_pipe_all(r8a66597, dev); |
| 1068 | free_usb_address(r8a66597, dev); |
| 1069 | |
Yoshihiro Shimoda | 54d0be9 | 2008-07-11 18:53:45 +0900 | [diff] [blame] | 1070 | start_root_hub_sampling(r8a66597, port, 0); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | /* this function must be called with interrupt disabled */ |
| 1074 | static void prepare_setup_packet(struct r8a66597 *r8a66597, |
| 1075 | struct r8a66597_td *td) |
| 1076 | { |
| 1077 | int i; |
Al Viro | fd05e72 | 2008-04-28 07:00:16 +0100 | [diff] [blame] | 1078 | __le16 *p = (__le16 *)td->urb->setup_packet; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1079 | unsigned long setup_addr = USBREQ; |
| 1080 | |
| 1081 | r8a66597_write(r8a66597, make_devsel(td->address) | td->maxpacket, |
| 1082 | DCPMAXP); |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 1083 | r8a66597_write(r8a66597, ~(SIGN | SACK), INTSTS1); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1084 | |
| 1085 | for (i = 0; i < 4; i++) { |
Al Viro | fd05e72 | 2008-04-28 07:00:16 +0100 | [diff] [blame] | 1086 | r8a66597_write(r8a66597, le16_to_cpu(p[i]), setup_addr); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1087 | setup_addr += 2; |
| 1088 | } |
| 1089 | r8a66597_write(r8a66597, SUREQ, DCPCTR); |
| 1090 | } |
| 1091 | |
| 1092 | /* this function must be called with interrupt disabled */ |
| 1093 | static void prepare_packet_read(struct r8a66597 *r8a66597, |
| 1094 | struct r8a66597_td *td) |
| 1095 | { |
| 1096 | struct urb *urb = td->urb; |
| 1097 | |
| 1098 | if (usb_pipecontrol(urb->pipe)) { |
| 1099 | r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG); |
| 1100 | r8a66597_mdfy(r8a66597, 0, 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); |
| 1105 | } |
| 1106 | pipe_irq_disable(r8a66597, td->pipenum); |
| 1107 | pipe_start(r8a66597, td->pipe); |
| 1108 | pipe_irq_enable(r8a66597, urb, td->pipenum); |
| 1109 | } else { |
| 1110 | if (urb->actual_length == 0) { |
| 1111 | pipe_irq_disable(r8a66597, td->pipenum); |
| 1112 | pipe_setting(r8a66597, td); |
| 1113 | pipe_stop(r8a66597, td->pipe); |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 1114 | r8a66597_write(r8a66597, ~(1 << td->pipenum), BRDYSTS); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1115 | |
| 1116 | if (td->pipe->pipetre) { |
| 1117 | r8a66597_write(r8a66597, TRCLR, |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 1118 | td->pipe->pipetre); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1119 | r8a66597_write(r8a66597, |
Julia Lawall | dfa5ec7 | 2008-03-04 15:25:11 -0800 | [diff] [blame] | 1120 | DIV_ROUND_UP |
| 1121 | (urb->transfer_buffer_length, |
| 1122 | td->maxpacket), |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 1123 | td->pipe->pipetrn); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1124 | r8a66597_bset(r8a66597, TRENB, |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 1125 | td->pipe->pipetre); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | pipe_start(r8a66597, td->pipe); |
| 1129 | pipe_irq_enable(r8a66597, urb, td->pipenum); |
| 1130 | } |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | /* this function must be called with interrupt disabled */ |
| 1135 | static void prepare_packet_write(struct r8a66597 *r8a66597, |
| 1136 | struct r8a66597_td *td) |
| 1137 | { |
| 1138 | u16 tmp; |
| 1139 | struct urb *urb = td->urb; |
| 1140 | |
| 1141 | if (usb_pipecontrol(urb->pipe)) { |
| 1142 | pipe_stop(r8a66597, td->pipe); |
| 1143 | r8a66597_bset(r8a66597, R8A66597_DIR, DCPCFG); |
| 1144 | r8a66597_mdfy(r8a66597, ISEL, ISEL | CURPIPE, CFIFOSEL); |
| 1145 | r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0); |
| 1146 | if (urb->actual_length == 0) { |
| 1147 | r8a66597_pipe_toggle(r8a66597, td->pipe, 1); |
| 1148 | r8a66597_write(r8a66597, BCLR, CFIFOCTR); |
| 1149 | } |
| 1150 | } else { |
| 1151 | if (urb->actual_length == 0) |
| 1152 | pipe_setting(r8a66597, td); |
| 1153 | if (td->pipe->pipetre) |
| 1154 | r8a66597_bclr(r8a66597, TRENB, td->pipe->pipetre); |
| 1155 | } |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 1156 | r8a66597_write(r8a66597, ~(1 << td->pipenum), BRDYSTS); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1157 | |
| 1158 | fifo_change_from_pipe(r8a66597, td->pipe); |
| 1159 | tmp = r8a66597_read(r8a66597, td->pipe->fifoctr); |
| 1160 | if (unlikely((tmp & FRDY) == 0)) |
| 1161 | pipe_irq_enable(r8a66597, urb, td->pipenum); |
| 1162 | else |
| 1163 | packet_write(r8a66597, td->pipenum); |
| 1164 | pipe_start(r8a66597, td->pipe); |
| 1165 | } |
| 1166 | |
| 1167 | /* this function must be called with interrupt disabled */ |
| 1168 | static void prepare_status_packet(struct r8a66597 *r8a66597, |
| 1169 | struct r8a66597_td *td) |
| 1170 | { |
| 1171 | struct urb *urb = td->urb; |
| 1172 | |
| 1173 | r8a66597_pipe_toggle(r8a66597, td->pipe, 1); |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 1174 | pipe_stop(r8a66597, td->pipe); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1175 | |
| 1176 | if (urb->setup_packet[0] & USB_ENDPOINT_DIR_MASK) { |
| 1177 | r8a66597_bset(r8a66597, R8A66597_DIR, DCPCFG); |
| 1178 | r8a66597_mdfy(r8a66597, ISEL, ISEL | CURPIPE, CFIFOSEL); |
| 1179 | r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0); |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 1180 | r8a66597_write(r8a66597, ~BEMP0, BEMPSTS); |
Yoshihiro Shimoda | 9424ea2 | 2008-04-10 21:05:58 +0900 | [diff] [blame] | 1181 | r8a66597_write(r8a66597, BCLR | BVAL, CFIFOCTR); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1182 | enable_irq_empty(r8a66597, 0); |
| 1183 | } else { |
| 1184 | r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG); |
| 1185 | r8a66597_mdfy(r8a66597, 0, ISEL | CURPIPE, CFIFOSEL); |
| 1186 | r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0); |
| 1187 | r8a66597_write(r8a66597, BCLR, CFIFOCTR); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1188 | enable_irq_ready(r8a66597, 0); |
| 1189 | } |
| 1190 | enable_irq_nrdy(r8a66597, 0); |
| 1191 | pipe_start(r8a66597, td->pipe); |
| 1192 | } |
| 1193 | |
Yoshihiro Shimoda | e3a0905 | 2007-10-03 18:53:13 +0900 | [diff] [blame] | 1194 | static int is_set_address(unsigned char *setup_packet) |
| 1195 | { |
| 1196 | if (((setup_packet[0] & USB_TYPE_MASK) == USB_TYPE_STANDARD) && |
| 1197 | setup_packet[1] == USB_REQ_SET_ADDRESS) |
| 1198 | return 1; |
| 1199 | else |
| 1200 | return 0; |
| 1201 | } |
| 1202 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1203 | /* this function must be called with interrupt disabled */ |
| 1204 | static int start_transfer(struct r8a66597 *r8a66597, struct r8a66597_td *td) |
| 1205 | { |
| 1206 | BUG_ON(!td); |
| 1207 | |
| 1208 | switch (td->type) { |
| 1209 | case USB_PID_SETUP: |
Yoshihiro Shimoda | e3a0905 | 2007-10-03 18:53:13 +0900 | [diff] [blame] | 1210 | if (is_set_address(td->urb->setup_packet)) { |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1211 | td->set_address = 1; |
| 1212 | td->urb->setup_packet[2] = alloc_usb_address(r8a66597, |
| 1213 | td->urb); |
| 1214 | if (td->urb->setup_packet[2] == 0) |
| 1215 | return -EPIPE; |
| 1216 | } |
| 1217 | prepare_setup_packet(r8a66597, td); |
| 1218 | break; |
| 1219 | case USB_PID_IN: |
| 1220 | prepare_packet_read(r8a66597, td); |
| 1221 | break; |
| 1222 | case USB_PID_OUT: |
| 1223 | prepare_packet_write(r8a66597, td); |
| 1224 | break; |
| 1225 | case USB_PID_ACK: |
| 1226 | prepare_status_packet(r8a66597, td); |
| 1227 | break; |
| 1228 | default: |
Greg Kroah-Hartman | 802f389 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 1229 | printk(KERN_ERR "r8a66597: invalid type.\n"); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1230 | break; |
| 1231 | } |
| 1232 | |
| 1233 | return 0; |
| 1234 | } |
| 1235 | |
| 1236 | static int check_transfer_finish(struct r8a66597_td *td, struct urb *urb) |
| 1237 | { |
| 1238 | if (usb_pipeisoc(urb->pipe)) { |
| 1239 | if (urb->number_of_packets == td->iso_cnt) |
| 1240 | return 1; |
| 1241 | } |
| 1242 | |
| 1243 | /* control or bulk or interrupt */ |
| 1244 | if ((urb->transfer_buffer_length <= urb->actual_length) || |
| 1245 | (td->short_packet) || (td->zero_packet)) |
| 1246 | return 1; |
| 1247 | |
| 1248 | return 0; |
| 1249 | } |
| 1250 | |
| 1251 | /* this function must be called with interrupt disabled */ |
| 1252 | static void set_td_timer(struct r8a66597 *r8a66597, struct r8a66597_td *td) |
| 1253 | { |
| 1254 | unsigned long time; |
| 1255 | |
| 1256 | BUG_ON(!td); |
| 1257 | |
| 1258 | if (!list_empty(&r8a66597->pipe_queue[td->pipenum]) && |
| 1259 | !usb_pipecontrol(td->urb->pipe) && usb_pipein(td->urb->pipe)) { |
| 1260 | r8a66597->timeout_map |= 1 << td->pipenum; |
| 1261 | switch (usb_pipetype(td->urb->pipe)) { |
| 1262 | case PIPE_INTERRUPT: |
| 1263 | case PIPE_ISOCHRONOUS: |
| 1264 | time = 30; |
| 1265 | break; |
| 1266 | default: |
| 1267 | time = 300; |
| 1268 | break; |
| 1269 | } |
| 1270 | |
| 1271 | mod_timer(&r8a66597->td_timer[td->pipenum], |
| 1272 | jiffies + msecs_to_jiffies(time)); |
| 1273 | } |
| 1274 | } |
| 1275 | |
| 1276 | /* this function must be called with interrupt disabled */ |
Alan Stern | dfd1e53 | 2007-08-21 15:36:52 -0400 | [diff] [blame] | 1277 | static void finish_request(struct r8a66597 *r8a66597, struct r8a66597_td *td, |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1278 | u16 pipenum, struct urb *urb, int status) |
Alan Stern | dfd1e53 | 2007-08-21 15:36:52 -0400 | [diff] [blame] | 1279 | __releases(r8a66597->lock) __acquires(r8a66597->lock) |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1280 | { |
| 1281 | int restart = 0; |
| 1282 | struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597); |
| 1283 | |
| 1284 | r8a66597->timeout_map &= ~(1 << pipenum); |
| 1285 | |
| 1286 | if (likely(td)) { |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1287 | if (td->set_address && (status != 0 || urb->unlinked)) |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1288 | r8a66597->address_map &= ~(1 << urb->setup_packet[2]); |
| 1289 | |
| 1290 | pipe_toggle_save(r8a66597, td->pipe, urb); |
| 1291 | list_del(&td->queue); |
| 1292 | kfree(td); |
| 1293 | } |
| 1294 | |
| 1295 | if (!list_empty(&r8a66597->pipe_queue[pipenum])) |
| 1296 | restart = 1; |
| 1297 | |
| 1298 | if (likely(urb)) { |
| 1299 | if (usb_pipeisoc(urb->pipe)) |
| 1300 | urb->start_frame = r8a66597_get_frame(hcd); |
| 1301 | |
Paul Mundt | 2717568 | 2010-02-04 06:57:58 +0000 | [diff] [blame^] | 1302 | r8a66597_urb_done(r8a66597, urb, status); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | if (restart) { |
| 1306 | td = r8a66597_get_td(r8a66597, pipenum); |
| 1307 | if (unlikely(!td)) |
| 1308 | return; |
| 1309 | |
| 1310 | start_transfer(r8a66597, td); |
| 1311 | set_td_timer(r8a66597, td); |
| 1312 | } |
| 1313 | } |
| 1314 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1315 | static void packet_read(struct r8a66597 *r8a66597, u16 pipenum) |
| 1316 | { |
| 1317 | u16 tmp; |
| 1318 | int rcv_len, bufsize, urb_len, size; |
| 1319 | u16 *buf; |
| 1320 | struct r8a66597_td *td = r8a66597_get_td(r8a66597, pipenum); |
| 1321 | struct urb *urb; |
| 1322 | int finish = 0; |
Alan Stern | dfd1e53 | 2007-08-21 15:36:52 -0400 | [diff] [blame] | 1323 | int status = 0; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1324 | |
| 1325 | if (unlikely(!td)) |
| 1326 | return; |
| 1327 | urb = td->urb; |
| 1328 | |
| 1329 | fifo_change_from_pipe(r8a66597, td->pipe); |
| 1330 | tmp = r8a66597_read(r8a66597, td->pipe->fifoctr); |
| 1331 | if (unlikely((tmp & FRDY) == 0)) { |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1332 | pipe_stop(r8a66597, td->pipe); |
| 1333 | pipe_irq_disable(r8a66597, pipenum); |
Greg Kroah-Hartman | 802f389 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 1334 | printk(KERN_ERR "r8a66597: in fifo not ready (%d)\n", pipenum); |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1335 | finish_request(r8a66597, td, pipenum, td->urb, -EPIPE); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1336 | return; |
| 1337 | } |
| 1338 | |
| 1339 | /* prepare parameters */ |
| 1340 | rcv_len = tmp & DTLN; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1341 | if (usb_pipeisoc(urb->pipe)) { |
| 1342 | buf = (u16 *)(urb->transfer_buffer + |
| 1343 | urb->iso_frame_desc[td->iso_cnt].offset); |
| 1344 | urb_len = urb->iso_frame_desc[td->iso_cnt].length; |
| 1345 | } else { |
| 1346 | buf = (void *)urb->transfer_buffer + urb->actual_length; |
| 1347 | urb_len = urb->transfer_buffer_length - urb->actual_length; |
| 1348 | } |
Alan Stern | dfd1e53 | 2007-08-21 15:36:52 -0400 | [diff] [blame] | 1349 | bufsize = min(urb_len, (int) td->maxpacket); |
| 1350 | if (rcv_len <= bufsize) { |
| 1351 | size = rcv_len; |
| 1352 | } else { |
| 1353 | size = bufsize; |
| 1354 | status = -EOVERFLOW; |
| 1355 | finish = 1; |
| 1356 | } |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1357 | |
| 1358 | /* update parameters */ |
| 1359 | urb->actual_length += size; |
| 1360 | if (rcv_len == 0) |
| 1361 | td->zero_packet = 1; |
Alan Stern | dfd1e53 | 2007-08-21 15:36:52 -0400 | [diff] [blame] | 1362 | if (rcv_len < bufsize) { |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1363 | td->short_packet = 1; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1364 | } |
| 1365 | if (usb_pipeisoc(urb->pipe)) { |
| 1366 | urb->iso_frame_desc[td->iso_cnt].actual_length = size; |
Alan Stern | dfd1e53 | 2007-08-21 15:36:52 -0400 | [diff] [blame] | 1367 | urb->iso_frame_desc[td->iso_cnt].status = status; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1368 | td->iso_cnt++; |
Alan Stern | dfd1e53 | 2007-08-21 15:36:52 -0400 | [diff] [blame] | 1369 | finish = 0; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | /* check transfer finish */ |
Alan Stern | b0d9efb | 2007-08-21 15:39:21 -0400 | [diff] [blame] | 1373 | if (finish || check_transfer_finish(td, urb)) { |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1374 | pipe_stop(r8a66597, td->pipe); |
| 1375 | pipe_irq_disable(r8a66597, pipenum); |
| 1376 | finish = 1; |
| 1377 | } |
| 1378 | |
| 1379 | /* read fifo */ |
| 1380 | if (urb->transfer_buffer) { |
| 1381 | if (size == 0) |
| 1382 | r8a66597_write(r8a66597, BCLR, td->pipe->fifoctr); |
| 1383 | else |
| 1384 | r8a66597_read_fifo(r8a66597, td->pipe->fifoaddr, |
| 1385 | buf, size); |
| 1386 | } |
| 1387 | |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1388 | if (finish && pipenum != 0) |
| 1389 | finish_request(r8a66597, td, pipenum, urb, status); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | static void packet_write(struct r8a66597 *r8a66597, u16 pipenum) |
| 1393 | { |
| 1394 | u16 tmp; |
| 1395 | int bufsize, size; |
| 1396 | u16 *buf; |
| 1397 | struct r8a66597_td *td = r8a66597_get_td(r8a66597, pipenum); |
| 1398 | struct urb *urb; |
| 1399 | |
| 1400 | if (unlikely(!td)) |
| 1401 | return; |
| 1402 | urb = td->urb; |
| 1403 | |
| 1404 | fifo_change_from_pipe(r8a66597, td->pipe); |
| 1405 | tmp = r8a66597_read(r8a66597, td->pipe->fifoctr); |
| 1406 | if (unlikely((tmp & FRDY) == 0)) { |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1407 | pipe_stop(r8a66597, td->pipe); |
| 1408 | pipe_irq_disable(r8a66597, pipenum); |
Greg Kroah-Hartman | 802f389 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 1409 | printk(KERN_ERR "r8a66597: out fifo not ready (%d)\n", pipenum); |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1410 | finish_request(r8a66597, td, pipenum, urb, -EPIPE); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1411 | return; |
| 1412 | } |
| 1413 | |
| 1414 | /* prepare parameters */ |
| 1415 | bufsize = td->maxpacket; |
| 1416 | if (usb_pipeisoc(urb->pipe)) { |
| 1417 | buf = (u16 *)(urb->transfer_buffer + |
| 1418 | urb->iso_frame_desc[td->iso_cnt].offset); |
| 1419 | size = min(bufsize, |
| 1420 | (int)urb->iso_frame_desc[td->iso_cnt].length); |
| 1421 | } else { |
| 1422 | buf = (u16 *)(urb->transfer_buffer + urb->actual_length); |
Greg Kroah-Hartman | 16e2e5f | 2009-03-03 16:44:13 -0800 | [diff] [blame] | 1423 | size = min_t(u32, bufsize, |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1424 | urb->transfer_buffer_length - urb->actual_length); |
| 1425 | } |
| 1426 | |
| 1427 | /* write fifo */ |
| 1428 | if (pipenum > 0) |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 1429 | r8a66597_write(r8a66597, ~(1 << pipenum), BEMPSTS); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1430 | if (urb->transfer_buffer) { |
| 1431 | r8a66597_write_fifo(r8a66597, td->pipe->fifoaddr, buf, size); |
| 1432 | if (!usb_pipebulk(urb->pipe) || td->maxpacket != size) |
| 1433 | r8a66597_write(r8a66597, BVAL, td->pipe->fifoctr); |
| 1434 | } |
| 1435 | |
| 1436 | /* update parameters */ |
| 1437 | urb->actual_length += size; |
| 1438 | if (usb_pipeisoc(urb->pipe)) { |
| 1439 | urb->iso_frame_desc[td->iso_cnt].actual_length = size; |
| 1440 | urb->iso_frame_desc[td->iso_cnt].status = 0; |
| 1441 | td->iso_cnt++; |
| 1442 | } |
| 1443 | |
| 1444 | /* check transfer finish */ |
| 1445 | if (check_transfer_finish(td, urb)) { |
| 1446 | disable_irq_ready(r8a66597, pipenum); |
| 1447 | enable_irq_empty(r8a66597, pipenum); |
| 1448 | if (!usb_pipeisoc(urb->pipe)) |
| 1449 | enable_irq_nrdy(r8a66597, pipenum); |
| 1450 | } else |
| 1451 | pipe_irq_enable(r8a66597, urb, pipenum); |
| 1452 | } |
| 1453 | |
| 1454 | |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1455 | static void check_next_phase(struct r8a66597 *r8a66597, int status) |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1456 | { |
| 1457 | struct r8a66597_td *td = r8a66597_get_td(r8a66597, 0); |
| 1458 | struct urb *urb; |
| 1459 | u8 finish = 0; |
| 1460 | |
| 1461 | if (unlikely(!td)) |
| 1462 | return; |
| 1463 | urb = td->urb; |
| 1464 | |
| 1465 | switch (td->type) { |
| 1466 | case USB_PID_IN: |
| 1467 | case USB_PID_OUT: |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1468 | if (check_transfer_finish(td, urb)) |
| 1469 | td->type = USB_PID_ACK; |
| 1470 | break; |
| 1471 | case USB_PID_SETUP: |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 1472 | if (urb->transfer_buffer_length == urb->actual_length) |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1473 | td->type = USB_PID_ACK; |
Alan Stern | eb23105 | 2007-08-21 15:40:36 -0400 | [diff] [blame] | 1474 | else if (usb_pipeout(urb->pipe)) |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1475 | td->type = USB_PID_OUT; |
| 1476 | else |
| 1477 | td->type = USB_PID_IN; |
| 1478 | break; |
| 1479 | case USB_PID_ACK: |
| 1480 | finish = 1; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1481 | break; |
| 1482 | } |
| 1483 | |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1484 | if (finish || status != 0 || urb->unlinked) |
| 1485 | finish_request(r8a66597, td, 0, urb, status); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1486 | else |
| 1487 | start_transfer(r8a66597, td); |
| 1488 | } |
| 1489 | |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1490 | static int get_urb_error(struct r8a66597 *r8a66597, u16 pipenum) |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1491 | { |
| 1492 | struct r8a66597_td *td = r8a66597_get_td(r8a66597, pipenum); |
| 1493 | |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1494 | if (td) { |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1495 | u16 pid = r8a66597_read(r8a66597, td->pipe->pipectr) & PID; |
| 1496 | |
| 1497 | if (pid == PID_NAK) |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1498 | return -ECONNRESET; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1499 | else |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1500 | return -EPIPE; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1501 | } |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1502 | return 0; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | static void irq_pipe_ready(struct r8a66597 *r8a66597) |
| 1506 | { |
| 1507 | u16 check; |
| 1508 | u16 pipenum; |
| 1509 | u16 mask; |
| 1510 | struct r8a66597_td *td; |
| 1511 | |
| 1512 | mask = r8a66597_read(r8a66597, BRDYSTS) |
| 1513 | & r8a66597_read(r8a66597, BRDYENB); |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 1514 | r8a66597_write(r8a66597, ~mask, BRDYSTS); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1515 | if (mask & BRDY0) { |
| 1516 | td = r8a66597_get_td(r8a66597, 0); |
| 1517 | if (td && td->type == USB_PID_IN) |
| 1518 | packet_read(r8a66597, 0); |
| 1519 | else |
| 1520 | pipe_irq_disable(r8a66597, 0); |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1521 | check_next_phase(r8a66597, 0); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) { |
| 1525 | check = 1 << pipenum; |
| 1526 | if (mask & check) { |
| 1527 | td = r8a66597_get_td(r8a66597, pipenum); |
| 1528 | if (unlikely(!td)) |
| 1529 | continue; |
| 1530 | |
| 1531 | if (td->type == USB_PID_IN) |
| 1532 | packet_read(r8a66597, pipenum); |
| 1533 | else if (td->type == USB_PID_OUT) |
| 1534 | packet_write(r8a66597, pipenum); |
| 1535 | } |
| 1536 | } |
| 1537 | } |
| 1538 | |
| 1539 | static void irq_pipe_empty(struct r8a66597 *r8a66597) |
| 1540 | { |
| 1541 | u16 tmp; |
| 1542 | u16 check; |
| 1543 | u16 pipenum; |
| 1544 | u16 mask; |
| 1545 | struct r8a66597_td *td; |
| 1546 | |
| 1547 | mask = r8a66597_read(r8a66597, BEMPSTS) |
| 1548 | & r8a66597_read(r8a66597, BEMPENB); |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 1549 | r8a66597_write(r8a66597, ~mask, BEMPSTS); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1550 | if (mask & BEMP0) { |
| 1551 | cfifo_change(r8a66597, 0); |
| 1552 | td = r8a66597_get_td(r8a66597, 0); |
| 1553 | if (td && td->type != USB_PID_OUT) |
| 1554 | disable_irq_empty(r8a66597, 0); |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1555 | check_next_phase(r8a66597, 0); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) { |
| 1559 | check = 1 << pipenum; |
| 1560 | if (mask & check) { |
| 1561 | struct r8a66597_td *td; |
| 1562 | td = r8a66597_get_td(r8a66597, pipenum); |
| 1563 | if (unlikely(!td)) |
| 1564 | continue; |
| 1565 | |
| 1566 | tmp = r8a66597_read(r8a66597, td->pipe->pipectr); |
| 1567 | if ((tmp & INBUFM) == 0) { |
| 1568 | disable_irq_empty(r8a66597, pipenum); |
| 1569 | pipe_irq_disable(r8a66597, pipenum); |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1570 | finish_request(r8a66597, td, pipenum, td->urb, |
| 1571 | 0); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1572 | } |
| 1573 | } |
| 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | static void irq_pipe_nrdy(struct r8a66597 *r8a66597) |
| 1578 | { |
| 1579 | u16 check; |
| 1580 | u16 pipenum; |
| 1581 | u16 mask; |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1582 | int status; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1583 | |
| 1584 | mask = r8a66597_read(r8a66597, NRDYSTS) |
| 1585 | & r8a66597_read(r8a66597, NRDYENB); |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 1586 | r8a66597_write(r8a66597, ~mask, NRDYSTS); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1587 | if (mask & NRDY0) { |
| 1588 | cfifo_change(r8a66597, 0); |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1589 | status = get_urb_error(r8a66597, 0); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1590 | pipe_irq_disable(r8a66597, 0); |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1591 | check_next_phase(r8a66597, status); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) { |
| 1595 | check = 1 << pipenum; |
| 1596 | if (mask & check) { |
| 1597 | struct r8a66597_td *td; |
| 1598 | td = r8a66597_get_td(r8a66597, pipenum); |
| 1599 | if (unlikely(!td)) |
| 1600 | continue; |
| 1601 | |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1602 | status = get_urb_error(r8a66597, pipenum); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1603 | pipe_irq_disable(r8a66597, pipenum); |
| 1604 | pipe_stop(r8a66597, td->pipe); |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1605 | finish_request(r8a66597, td, pipenum, td->urb, status); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1606 | } |
| 1607 | } |
| 1608 | } |
| 1609 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1610 | static irqreturn_t r8a66597_irq(struct usb_hcd *hcd) |
| 1611 | { |
| 1612 | struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); |
| 1613 | u16 intsts0, intsts1, intsts2; |
| 1614 | u16 intenb0, intenb1, intenb2; |
| 1615 | u16 mask0, mask1, mask2; |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1616 | int status; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1617 | |
| 1618 | spin_lock(&r8a66597->lock); |
| 1619 | |
| 1620 | intsts0 = r8a66597_read(r8a66597, INTSTS0); |
| 1621 | intsts1 = r8a66597_read(r8a66597, INTSTS1); |
| 1622 | intsts2 = r8a66597_read(r8a66597, INTSTS2); |
| 1623 | intenb0 = r8a66597_read(r8a66597, INTENB0); |
| 1624 | intenb1 = r8a66597_read(r8a66597, INTENB1); |
| 1625 | intenb2 = r8a66597_read(r8a66597, INTENB2); |
| 1626 | |
| 1627 | mask2 = intsts2 & intenb2; |
| 1628 | mask1 = intsts1 & intenb1; |
| 1629 | mask0 = intsts0 & intenb0 & (BEMP | NRDY | BRDY); |
| 1630 | if (mask2) { |
| 1631 | if (mask2 & ATTCH) { |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 1632 | r8a66597_write(r8a66597, ~ATTCH, INTSTS2); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1633 | r8a66597_bclr(r8a66597, ATTCHE, INTENB2); |
| 1634 | |
| 1635 | /* start usb bus sampling */ |
Yoshihiro Shimoda | 54d0be9 | 2008-07-11 18:53:45 +0900 | [diff] [blame] | 1636 | start_root_hub_sampling(r8a66597, 1, 1); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1637 | } |
| 1638 | if (mask2 & DTCH) { |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 1639 | r8a66597_write(r8a66597, ~DTCH, INTSTS2); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1640 | r8a66597_bclr(r8a66597, DTCHE, INTENB2); |
| 1641 | r8a66597_usb_disconnect(r8a66597, 1); |
| 1642 | } |
Yoshihiro Shimoda | e1e609b | 2009-03-19 14:18:15 +0900 | [diff] [blame] | 1643 | if (mask2 & BCHG) { |
| 1644 | r8a66597_write(r8a66597, ~BCHG, INTSTS2); |
| 1645 | r8a66597_bclr(r8a66597, BCHGE, INTENB2); |
| 1646 | usb_hcd_resume_root_hub(r8a66597_to_hcd(r8a66597)); |
| 1647 | } |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1648 | } |
| 1649 | |
| 1650 | if (mask1) { |
| 1651 | if (mask1 & ATTCH) { |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 1652 | r8a66597_write(r8a66597, ~ATTCH, INTSTS1); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1653 | r8a66597_bclr(r8a66597, ATTCHE, INTENB1); |
| 1654 | |
| 1655 | /* start usb bus sampling */ |
Yoshihiro Shimoda | 54d0be9 | 2008-07-11 18:53:45 +0900 | [diff] [blame] | 1656 | start_root_hub_sampling(r8a66597, 0, 1); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1657 | } |
| 1658 | if (mask1 & DTCH) { |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 1659 | r8a66597_write(r8a66597, ~DTCH, INTSTS1); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1660 | r8a66597_bclr(r8a66597, DTCHE, INTENB1); |
| 1661 | r8a66597_usb_disconnect(r8a66597, 0); |
| 1662 | } |
Yoshihiro Shimoda | e1e609b | 2009-03-19 14:18:15 +0900 | [diff] [blame] | 1663 | if (mask1 & BCHG) { |
| 1664 | r8a66597_write(r8a66597, ~BCHG, INTSTS1); |
| 1665 | r8a66597_bclr(r8a66597, BCHGE, INTENB1); |
| 1666 | usb_hcd_resume_root_hub(r8a66597_to_hcd(r8a66597)); |
| 1667 | } |
| 1668 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1669 | if (mask1 & SIGN) { |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 1670 | r8a66597_write(r8a66597, ~SIGN, INTSTS1); |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1671 | status = get_urb_error(r8a66597, 0); |
| 1672 | check_next_phase(r8a66597, status); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1673 | } |
| 1674 | if (mask1 & SACK) { |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 1675 | r8a66597_write(r8a66597, ~SACK, INTSTS1); |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1676 | check_next_phase(r8a66597, 0); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1677 | } |
| 1678 | } |
| 1679 | if (mask0) { |
| 1680 | if (mask0 & BRDY) |
| 1681 | irq_pipe_ready(r8a66597); |
| 1682 | if (mask0 & BEMP) |
| 1683 | irq_pipe_empty(r8a66597); |
| 1684 | if (mask0 & NRDY) |
| 1685 | irq_pipe_nrdy(r8a66597); |
| 1686 | } |
| 1687 | |
| 1688 | spin_unlock(&r8a66597->lock); |
| 1689 | return IRQ_HANDLED; |
| 1690 | } |
| 1691 | |
| 1692 | /* this function must be called with interrupt disabled */ |
| 1693 | static void r8a66597_root_hub_control(struct r8a66597 *r8a66597, int port) |
| 1694 | { |
| 1695 | u16 tmp; |
| 1696 | struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; |
| 1697 | |
| 1698 | if (rh->port & (1 << USB_PORT_FEAT_RESET)) { |
| 1699 | unsigned long dvstctr_reg = get_dvstctr_reg(port); |
| 1700 | |
| 1701 | tmp = r8a66597_read(r8a66597, dvstctr_reg); |
| 1702 | if ((tmp & USBRST) == USBRST) { |
| 1703 | r8a66597_mdfy(r8a66597, UACT, USBRST | UACT, |
| 1704 | dvstctr_reg); |
Yoshihiro Shimoda | 29fab0c | 2008-04-10 21:05:55 +0900 | [diff] [blame] | 1705 | r8a66597_root_hub_start_polling(r8a66597); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1706 | } else |
| 1707 | r8a66597_usb_connect(r8a66597, port); |
| 1708 | } |
| 1709 | |
Yoshihiro Shimoda | 29fab0c | 2008-04-10 21:05:55 +0900 | [diff] [blame] | 1710 | if (!(rh->port & (1 << USB_PORT_FEAT_CONNECTION))) { |
| 1711 | r8a66597_write(r8a66597, ~ATTCH, get_intsts_reg(port)); |
| 1712 | r8a66597_bset(r8a66597, ATTCHE, get_intenb_reg(port)); |
| 1713 | } |
| 1714 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1715 | if (rh->scount > 0) { |
| 1716 | tmp = r8a66597_read(r8a66597, get_syssts_reg(port)) & LNST; |
| 1717 | if (tmp == rh->old_syssts) { |
| 1718 | rh->scount--; |
Yoshihiro Shimoda | 29fab0c | 2008-04-10 21:05:55 +0900 | [diff] [blame] | 1719 | if (rh->scount == 0) |
| 1720 | r8a66597_check_syssts(r8a66597, port, tmp); |
| 1721 | else |
| 1722 | r8a66597_root_hub_start_polling(r8a66597); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1723 | } else { |
| 1724 | rh->scount = R8A66597_MAX_SAMPLING; |
| 1725 | rh->old_syssts = tmp; |
Yoshihiro Shimoda | 29fab0c | 2008-04-10 21:05:55 +0900 | [diff] [blame] | 1726 | r8a66597_root_hub_start_polling(r8a66597); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1727 | } |
| 1728 | } |
| 1729 | } |
| 1730 | |
Yoshihiro Shimoda | 6d87910 | 2008-04-10 21:05:47 +0900 | [diff] [blame] | 1731 | static void r8a66597_interval_timer(unsigned long _r8a66597) |
| 1732 | { |
| 1733 | struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597; |
| 1734 | unsigned long flags; |
| 1735 | u16 pipenum; |
| 1736 | struct r8a66597_td *td; |
| 1737 | |
| 1738 | spin_lock_irqsave(&r8a66597->lock, flags); |
| 1739 | |
| 1740 | for (pipenum = 0; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) { |
| 1741 | if (!(r8a66597->interval_map & (1 << pipenum))) |
| 1742 | continue; |
| 1743 | if (timer_pending(&r8a66597->interval_timer[pipenum])) |
| 1744 | continue; |
| 1745 | |
| 1746 | td = r8a66597_get_td(r8a66597, pipenum); |
| 1747 | if (td) |
| 1748 | start_transfer(r8a66597, td); |
| 1749 | } |
| 1750 | |
| 1751 | spin_unlock_irqrestore(&r8a66597->lock, flags); |
| 1752 | } |
| 1753 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1754 | static void r8a66597_td_timer(unsigned long _r8a66597) |
| 1755 | { |
| 1756 | struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597; |
| 1757 | unsigned long flags; |
| 1758 | u16 pipenum; |
| 1759 | struct r8a66597_td *td, *new_td = NULL; |
| 1760 | struct r8a66597_pipe *pipe; |
| 1761 | |
| 1762 | spin_lock_irqsave(&r8a66597->lock, flags); |
| 1763 | for (pipenum = 0; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) { |
| 1764 | if (!(r8a66597->timeout_map & (1 << pipenum))) |
| 1765 | continue; |
| 1766 | if (timer_pending(&r8a66597->td_timer[pipenum])) |
| 1767 | continue; |
| 1768 | |
| 1769 | td = r8a66597_get_td(r8a66597, pipenum); |
| 1770 | if (!td) { |
| 1771 | r8a66597->timeout_map &= ~(1 << pipenum); |
| 1772 | continue; |
| 1773 | } |
| 1774 | |
| 1775 | if (td->urb->actual_length) { |
| 1776 | set_td_timer(r8a66597, td); |
| 1777 | break; |
| 1778 | } |
| 1779 | |
| 1780 | pipe = td->pipe; |
| 1781 | pipe_stop(r8a66597, pipe); |
| 1782 | |
| 1783 | new_td = td; |
| 1784 | do { |
| 1785 | list_move_tail(&new_td->queue, |
| 1786 | &r8a66597->pipe_queue[pipenum]); |
| 1787 | new_td = r8a66597_get_td(r8a66597, pipenum); |
| 1788 | if (!new_td) { |
| 1789 | new_td = td; |
| 1790 | break; |
| 1791 | } |
| 1792 | } while (td != new_td && td->address == new_td->address); |
| 1793 | |
| 1794 | start_transfer(r8a66597, new_td); |
| 1795 | |
| 1796 | if (td == new_td) |
| 1797 | r8a66597->timeout_map &= ~(1 << pipenum); |
| 1798 | else |
| 1799 | set_td_timer(r8a66597, new_td); |
| 1800 | break; |
| 1801 | } |
| 1802 | spin_unlock_irqrestore(&r8a66597->lock, flags); |
| 1803 | } |
| 1804 | |
| 1805 | static void r8a66597_timer(unsigned long _r8a66597) |
| 1806 | { |
| 1807 | struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597; |
| 1808 | unsigned long flags; |
Yoshihiro Shimoda | 5863964 | 2008-11-11 16:47:21 +0900 | [diff] [blame] | 1809 | int port; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1810 | |
| 1811 | spin_lock_irqsave(&r8a66597->lock, flags); |
| 1812 | |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 1813 | for (port = 0; port < r8a66597->max_root_hub; port++) |
Yoshihiro Shimoda | 5863964 | 2008-11-11 16:47:21 +0900 | [diff] [blame] | 1814 | r8a66597_root_hub_control(r8a66597, port); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1815 | |
| 1816 | spin_unlock_irqrestore(&r8a66597->lock, flags); |
| 1817 | } |
| 1818 | |
| 1819 | static int check_pipe_config(struct r8a66597 *r8a66597, struct urb *urb) |
| 1820 | { |
| 1821 | struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb); |
| 1822 | |
| 1823 | if (dev && dev->address && dev->state != USB_STATE_CONFIGURED && |
| 1824 | (urb->dev->state == USB_STATE_CONFIGURED)) |
| 1825 | return 1; |
| 1826 | else |
| 1827 | return 0; |
| 1828 | } |
| 1829 | |
| 1830 | static int r8a66597_start(struct usb_hcd *hcd) |
| 1831 | { |
| 1832 | struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1833 | |
| 1834 | hcd->state = HC_STATE_RUNNING; |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 1835 | return enable_controller(r8a66597); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1836 | } |
| 1837 | |
| 1838 | static void r8a66597_stop(struct usb_hcd *hcd) |
| 1839 | { |
| 1840 | struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); |
| 1841 | |
| 1842 | disable_controller(r8a66597); |
| 1843 | } |
| 1844 | |
| 1845 | static void set_address_zero(struct r8a66597 *r8a66597, struct urb *urb) |
| 1846 | { |
| 1847 | unsigned int usb_address = usb_pipedevice(urb->pipe); |
| 1848 | u16 root_port, hub_port; |
| 1849 | |
| 1850 | if (usb_address == 0) { |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 1851 | get_port_number(r8a66597, urb->dev->devpath, |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1852 | &root_port, &hub_port); |
| 1853 | set_devadd_reg(r8a66597, 0, |
| 1854 | get_r8a66597_usb_speed(urb->dev->speed), |
| 1855 | get_parent_r8a66597_address(r8a66597, urb->dev), |
| 1856 | hub_port, root_port); |
| 1857 | } |
| 1858 | } |
| 1859 | |
| 1860 | static struct r8a66597_td *r8a66597_make_td(struct r8a66597 *r8a66597, |
| 1861 | struct urb *urb, |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 1862 | struct usb_host_endpoint *hep) |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1863 | { |
| 1864 | struct r8a66597_td *td; |
| 1865 | u16 pipenum; |
| 1866 | |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 1867 | td = kzalloc(sizeof(struct r8a66597_td), GFP_ATOMIC); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1868 | if (td == NULL) |
| 1869 | return NULL; |
| 1870 | |
| 1871 | pipenum = r8a66597_get_pipenum(urb, hep); |
| 1872 | td->pipenum = pipenum; |
| 1873 | td->pipe = hep->hcpriv; |
| 1874 | td->urb = urb; |
| 1875 | td->address = get_urb_to_r8a66597_addr(r8a66597, urb); |
| 1876 | td->maxpacket = usb_maxpacket(urb->dev, urb->pipe, |
| 1877 | !usb_pipein(urb->pipe)); |
| 1878 | if (usb_pipecontrol(urb->pipe)) |
| 1879 | td->type = USB_PID_SETUP; |
| 1880 | else if (usb_pipein(urb->pipe)) |
| 1881 | td->type = USB_PID_IN; |
| 1882 | else |
| 1883 | td->type = USB_PID_OUT; |
| 1884 | INIT_LIST_HEAD(&td->queue); |
| 1885 | |
| 1886 | return td; |
| 1887 | } |
| 1888 | |
| 1889 | static int r8a66597_urb_enqueue(struct usb_hcd *hcd, |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1890 | struct urb *urb, |
| 1891 | gfp_t mem_flags) |
| 1892 | { |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 1893 | struct usb_host_endpoint *hep = urb->ep; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1894 | struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); |
| 1895 | struct r8a66597_td *td = NULL; |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 1896 | int ret, request = 0; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1897 | unsigned long flags; |
| 1898 | |
| 1899 | spin_lock_irqsave(&r8a66597->lock, flags); |
| 1900 | if (!get_urb_to_r8a66597_dev(r8a66597, urb)) { |
| 1901 | ret = -ENODEV; |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 1902 | goto error_not_linked; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1903 | } |
| 1904 | |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 1905 | ret = usb_hcd_link_urb_to_ep(hcd, urb); |
| 1906 | if (ret) |
| 1907 | goto error_not_linked; |
| 1908 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1909 | if (!hep->hcpriv) { |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 1910 | hep->hcpriv = kzalloc(sizeof(struct r8a66597_pipe), |
| 1911 | GFP_ATOMIC); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1912 | if (!hep->hcpriv) { |
| 1913 | ret = -ENOMEM; |
| 1914 | goto error; |
| 1915 | } |
| 1916 | set_pipe_reg_addr(hep->hcpriv, R8A66597_PIPE_NO_DMA); |
| 1917 | if (usb_pipeendpoint(urb->pipe)) |
| 1918 | init_pipe_info(r8a66597, urb, hep, &hep->desc); |
| 1919 | } |
| 1920 | |
| 1921 | if (unlikely(check_pipe_config(r8a66597, urb))) |
| 1922 | init_pipe_config(r8a66597, urb); |
| 1923 | |
| 1924 | set_address_zero(r8a66597, urb); |
Yoshihiro Shimoda | e294531 | 2007-07-18 23:10:34 +0900 | [diff] [blame] | 1925 | td = r8a66597_make_td(r8a66597, urb, hep); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1926 | if (td == NULL) { |
| 1927 | ret = -ENOMEM; |
| 1928 | goto error; |
| 1929 | } |
| 1930 | if (list_empty(&r8a66597->pipe_queue[td->pipenum])) |
| 1931 | request = 1; |
| 1932 | list_add_tail(&td->queue, &r8a66597->pipe_queue[td->pipenum]); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1933 | urb->hcpriv = td; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1934 | |
| 1935 | if (request) { |
Yoshihiro Shimoda | 6d87910 | 2008-04-10 21:05:47 +0900 | [diff] [blame] | 1936 | if (td->pipe->info.timer_interval) { |
| 1937 | r8a66597->interval_map |= 1 << td->pipenum; |
| 1938 | mod_timer(&r8a66597->interval_timer[td->pipenum], |
| 1939 | jiffies + msecs_to_jiffies( |
| 1940 | td->pipe->info.timer_interval)); |
| 1941 | } else { |
| 1942 | ret = start_transfer(r8a66597, td); |
| 1943 | if (ret < 0) { |
| 1944 | list_del(&td->queue); |
| 1945 | kfree(td); |
| 1946 | } |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1947 | } |
| 1948 | } else |
| 1949 | set_td_timer(r8a66597, td); |
| 1950 | |
| 1951 | error: |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 1952 | if (ret) |
| 1953 | usb_hcd_unlink_urb_from_ep(hcd, urb); |
| 1954 | error_not_linked: |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1955 | spin_unlock_irqrestore(&r8a66597->lock, flags); |
| 1956 | return ret; |
| 1957 | } |
| 1958 | |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 1959 | static int r8a66597_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, |
| 1960 | int status) |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1961 | { |
| 1962 | struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); |
| 1963 | struct r8a66597_td *td; |
| 1964 | unsigned long flags; |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 1965 | int rc; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1966 | |
| 1967 | spin_lock_irqsave(&r8a66597->lock, flags); |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 1968 | rc = usb_hcd_check_unlink_urb(hcd, urb, status); |
| 1969 | if (rc) |
| 1970 | goto done; |
| 1971 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1972 | if (urb->hcpriv) { |
| 1973 | td = urb->hcpriv; |
| 1974 | pipe_stop(r8a66597, td->pipe); |
| 1975 | pipe_irq_disable(r8a66597, td->pipenum); |
| 1976 | disable_irq_empty(r8a66597, td->pipenum); |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 1977 | finish_request(r8a66597, td, td->pipenum, urb, status); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1978 | } |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 1979 | done: |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1980 | spin_unlock_irqrestore(&r8a66597->lock, flags); |
Alan Stern | e9df41c | 2007-08-08 11:48:02 -0400 | [diff] [blame] | 1981 | return rc; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 1982 | } |
| 1983 | |
| 1984 | static void r8a66597_endpoint_disable(struct usb_hcd *hcd, |
| 1985 | struct usb_host_endpoint *hep) |
| 1986 | { |
| 1987 | struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); |
| 1988 | struct r8a66597_pipe *pipe = (struct r8a66597_pipe *)hep->hcpriv; |
| 1989 | struct r8a66597_td *td; |
| 1990 | struct urb *urb = NULL; |
| 1991 | u16 pipenum; |
| 1992 | unsigned long flags; |
| 1993 | |
| 1994 | if (pipe == NULL) |
| 1995 | return; |
| 1996 | pipenum = pipe->info.pipenum; |
| 1997 | |
| 1998 | if (pipenum == 0) { |
| 1999 | kfree(hep->hcpriv); |
| 2000 | hep->hcpriv = NULL; |
| 2001 | return; |
| 2002 | } |
| 2003 | |
| 2004 | spin_lock_irqsave(&r8a66597->lock, flags); |
| 2005 | pipe_stop(r8a66597, pipe); |
| 2006 | pipe_irq_disable(r8a66597, pipenum); |
| 2007 | disable_irq_empty(r8a66597, pipenum); |
| 2008 | td = r8a66597_get_td(r8a66597, pipenum); |
| 2009 | if (td) |
| 2010 | urb = td->urb; |
Alan Stern | 888fda4 | 2007-08-24 15:41:18 -0400 | [diff] [blame] | 2011 | finish_request(r8a66597, td, pipenum, urb, -ESHUTDOWN); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2012 | kfree(hep->hcpriv); |
| 2013 | hep->hcpriv = NULL; |
| 2014 | spin_unlock_irqrestore(&r8a66597->lock, flags); |
| 2015 | } |
| 2016 | |
| 2017 | static int r8a66597_get_frame(struct usb_hcd *hcd) |
| 2018 | { |
| 2019 | struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); |
| 2020 | return r8a66597_read(r8a66597, FRMNUM) & 0x03FF; |
| 2021 | } |
| 2022 | |
| 2023 | static void collect_usb_address_map(struct usb_device *udev, unsigned long *map) |
| 2024 | { |
| 2025 | int chix; |
| 2026 | |
| 2027 | if (udev->state == USB_STATE_CONFIGURED && |
| 2028 | udev->parent && udev->parent->devnum > 1 && |
| 2029 | udev->parent->descriptor.bDeviceClass == USB_CLASS_HUB) |
| 2030 | map[udev->devnum/32] |= (1 << (udev->devnum % 32)); |
| 2031 | |
| 2032 | for (chix = 0; chix < udev->maxchild; chix++) { |
| 2033 | struct usb_device *childdev = udev->children[chix]; |
| 2034 | |
| 2035 | if (childdev) |
| 2036 | collect_usb_address_map(childdev, map); |
| 2037 | } |
| 2038 | } |
| 2039 | |
| 2040 | /* this function must be called with interrupt disabled */ |
| 2041 | static struct r8a66597_device *get_r8a66597_device(struct r8a66597 *r8a66597, |
| 2042 | int addr) |
| 2043 | { |
| 2044 | struct r8a66597_device *dev; |
| 2045 | struct list_head *list = &r8a66597->child_device; |
| 2046 | |
| 2047 | list_for_each_entry(dev, list, device_list) { |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2048 | if (dev->usb_address != addr) |
| 2049 | continue; |
| 2050 | |
| 2051 | return dev; |
| 2052 | } |
| 2053 | |
Greg Kroah-Hartman | 802f389 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 2054 | printk(KERN_ERR "r8a66597: get_r8a66597_device fail.(%d)\n", addr); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2055 | return NULL; |
| 2056 | } |
| 2057 | |
| 2058 | static void update_usb_address_map(struct r8a66597 *r8a66597, |
| 2059 | struct usb_device *root_hub, |
| 2060 | unsigned long *map) |
| 2061 | { |
| 2062 | int i, j, addr; |
| 2063 | unsigned long diff; |
| 2064 | unsigned long flags; |
| 2065 | |
| 2066 | for (i = 0; i < 4; i++) { |
| 2067 | diff = r8a66597->child_connect_map[i] ^ map[i]; |
| 2068 | if (!diff) |
| 2069 | continue; |
| 2070 | |
| 2071 | for (j = 0; j < 32; j++) { |
| 2072 | if (!(diff & (1 << j))) |
| 2073 | continue; |
| 2074 | |
| 2075 | addr = i * 32 + j; |
| 2076 | if (map[i] & (1 << j)) |
| 2077 | set_child_connect_map(r8a66597, addr); |
| 2078 | else { |
| 2079 | struct r8a66597_device *dev; |
| 2080 | |
| 2081 | spin_lock_irqsave(&r8a66597->lock, flags); |
| 2082 | dev = get_r8a66597_device(r8a66597, addr); |
| 2083 | disable_r8a66597_pipe_all(r8a66597, dev); |
| 2084 | free_usb_address(r8a66597, dev); |
| 2085 | put_child_connect_map(r8a66597, addr); |
| 2086 | spin_unlock_irqrestore(&r8a66597->lock, flags); |
| 2087 | } |
| 2088 | } |
| 2089 | } |
| 2090 | } |
| 2091 | |
| 2092 | static void r8a66597_check_detect_child(struct r8a66597 *r8a66597, |
| 2093 | struct usb_hcd *hcd) |
| 2094 | { |
| 2095 | struct usb_bus *bus; |
| 2096 | unsigned long now_map[4]; |
| 2097 | |
| 2098 | memset(now_map, 0, sizeof(now_map)); |
| 2099 | |
| 2100 | list_for_each_entry(bus, &usb_bus_list, bus_list) { |
| 2101 | if (!bus->root_hub) |
| 2102 | continue; |
| 2103 | |
| 2104 | if (bus->busnum != hcd->self.busnum) |
| 2105 | continue; |
| 2106 | |
| 2107 | collect_usb_address_map(bus->root_hub, now_map); |
| 2108 | update_usb_address_map(r8a66597, bus->root_hub, now_map); |
| 2109 | } |
| 2110 | } |
| 2111 | |
| 2112 | static int r8a66597_hub_status_data(struct usb_hcd *hcd, char *buf) |
| 2113 | { |
| 2114 | struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); |
| 2115 | unsigned long flags; |
| 2116 | int i; |
| 2117 | |
| 2118 | r8a66597_check_detect_child(r8a66597, hcd); |
| 2119 | |
| 2120 | spin_lock_irqsave(&r8a66597->lock, flags); |
| 2121 | |
| 2122 | *buf = 0; /* initialize (no change) */ |
| 2123 | |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 2124 | for (i = 0; i < r8a66597->max_root_hub; i++) { |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2125 | if (r8a66597->root_hub[i].port & 0xffff0000) |
| 2126 | *buf |= 1 << (i + 1); |
| 2127 | } |
| 2128 | |
| 2129 | spin_unlock_irqrestore(&r8a66597->lock, flags); |
| 2130 | |
| 2131 | return (*buf != 0); |
| 2132 | } |
| 2133 | |
| 2134 | static void r8a66597_hub_descriptor(struct r8a66597 *r8a66597, |
| 2135 | struct usb_hub_descriptor *desc) |
| 2136 | { |
| 2137 | desc->bDescriptorType = 0x29; |
| 2138 | desc->bHubContrCurrent = 0; |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 2139 | desc->bNbrPorts = r8a66597->max_root_hub; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2140 | desc->bDescLength = 9; |
| 2141 | desc->bPwrOn2PwrGood = 0; |
| 2142 | desc->wHubCharacteristics = cpu_to_le16(0x0011); |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 2143 | desc->bitmap[0] = ((1 << r8a66597->max_root_hub) - 1) << 1; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2144 | desc->bitmap[1] = ~0; |
| 2145 | } |
| 2146 | |
| 2147 | static int r8a66597_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, |
| 2148 | u16 wIndex, char *buf, u16 wLength) |
| 2149 | { |
| 2150 | struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); |
| 2151 | int ret; |
| 2152 | int port = (wIndex & 0x00FF) - 1; |
| 2153 | struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; |
| 2154 | unsigned long flags; |
| 2155 | |
| 2156 | ret = 0; |
| 2157 | |
| 2158 | spin_lock_irqsave(&r8a66597->lock, flags); |
| 2159 | switch (typeReq) { |
| 2160 | case ClearHubFeature: |
| 2161 | case SetHubFeature: |
| 2162 | switch (wValue) { |
| 2163 | case C_HUB_OVER_CURRENT: |
| 2164 | case C_HUB_LOCAL_POWER: |
| 2165 | break; |
| 2166 | default: |
| 2167 | goto error; |
| 2168 | } |
| 2169 | break; |
| 2170 | case ClearPortFeature: |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 2171 | if (wIndex > r8a66597->max_root_hub) |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2172 | goto error; |
| 2173 | if (wLength != 0) |
| 2174 | goto error; |
| 2175 | |
| 2176 | switch (wValue) { |
| 2177 | case USB_PORT_FEAT_ENABLE: |
Yoshihiro Shimoda | e1e609b | 2009-03-19 14:18:15 +0900 | [diff] [blame] | 2178 | rh->port &= ~(1 << USB_PORT_FEAT_POWER); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2179 | break; |
| 2180 | case USB_PORT_FEAT_SUSPEND: |
| 2181 | break; |
| 2182 | case USB_PORT_FEAT_POWER: |
| 2183 | r8a66597_port_power(r8a66597, port, 0); |
| 2184 | break; |
| 2185 | case USB_PORT_FEAT_C_ENABLE: |
| 2186 | case USB_PORT_FEAT_C_SUSPEND: |
| 2187 | case USB_PORT_FEAT_C_CONNECTION: |
| 2188 | case USB_PORT_FEAT_C_OVER_CURRENT: |
| 2189 | case USB_PORT_FEAT_C_RESET: |
| 2190 | break; |
| 2191 | default: |
| 2192 | goto error; |
| 2193 | } |
| 2194 | rh->port &= ~(1 << wValue); |
| 2195 | break; |
| 2196 | case GetHubDescriptor: |
| 2197 | r8a66597_hub_descriptor(r8a66597, |
| 2198 | (struct usb_hub_descriptor *)buf); |
| 2199 | break; |
| 2200 | case GetHubStatus: |
| 2201 | *buf = 0x00; |
| 2202 | break; |
| 2203 | case GetPortStatus: |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 2204 | if (wIndex > r8a66597->max_root_hub) |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2205 | goto error; |
Al Viro | fd05e72 | 2008-04-28 07:00:16 +0100 | [diff] [blame] | 2206 | *(__le32 *)buf = cpu_to_le32(rh->port); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2207 | break; |
| 2208 | case SetPortFeature: |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 2209 | if (wIndex > r8a66597->max_root_hub) |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2210 | goto error; |
| 2211 | if (wLength != 0) |
| 2212 | goto error; |
| 2213 | |
| 2214 | switch (wValue) { |
| 2215 | case USB_PORT_FEAT_SUSPEND: |
| 2216 | break; |
| 2217 | case USB_PORT_FEAT_POWER: |
| 2218 | r8a66597_port_power(r8a66597, port, 1); |
| 2219 | rh->port |= (1 << USB_PORT_FEAT_POWER); |
| 2220 | break; |
| 2221 | case USB_PORT_FEAT_RESET: { |
| 2222 | struct r8a66597_device *dev = rh->dev; |
| 2223 | |
| 2224 | rh->port |= (1 << USB_PORT_FEAT_RESET); |
| 2225 | |
| 2226 | disable_r8a66597_pipe_all(r8a66597, dev); |
| 2227 | free_usb_address(r8a66597, dev); |
| 2228 | |
| 2229 | r8a66597_mdfy(r8a66597, USBRST, USBRST | UACT, |
| 2230 | get_dvstctr_reg(port)); |
| 2231 | mod_timer(&r8a66597->rh_timer, |
| 2232 | jiffies + msecs_to_jiffies(50)); |
| 2233 | } |
| 2234 | break; |
| 2235 | default: |
| 2236 | goto error; |
| 2237 | } |
| 2238 | rh->port |= 1 << wValue; |
| 2239 | break; |
| 2240 | default: |
| 2241 | error: |
| 2242 | ret = -EPIPE; |
| 2243 | break; |
| 2244 | } |
| 2245 | |
| 2246 | spin_unlock_irqrestore(&r8a66597->lock, flags); |
| 2247 | return ret; |
| 2248 | } |
| 2249 | |
Yoshihiro Shimoda | e1e609b | 2009-03-19 14:18:15 +0900 | [diff] [blame] | 2250 | #if defined(CONFIG_PM) |
| 2251 | static int r8a66597_bus_suspend(struct usb_hcd *hcd) |
| 2252 | { |
| 2253 | struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); |
| 2254 | int port; |
| 2255 | |
| 2256 | dbg("%s", __func__); |
| 2257 | |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 2258 | for (port = 0; port < r8a66597->max_root_hub; port++) { |
Yoshihiro Shimoda | e1e609b | 2009-03-19 14:18:15 +0900 | [diff] [blame] | 2259 | struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; |
| 2260 | unsigned long dvstctr_reg = get_dvstctr_reg(port); |
| 2261 | |
| 2262 | if (!(rh->port & (1 << USB_PORT_FEAT_ENABLE))) |
| 2263 | continue; |
| 2264 | |
| 2265 | dbg("suspend port = %d", port); |
| 2266 | r8a66597_bclr(r8a66597, UACT, dvstctr_reg); /* suspend */ |
| 2267 | rh->port |= 1 << USB_PORT_FEAT_SUSPEND; |
| 2268 | |
| 2269 | if (rh->dev->udev->do_remote_wakeup) { |
| 2270 | msleep(3); /* waiting last SOF */ |
| 2271 | r8a66597_bset(r8a66597, RWUPE, dvstctr_reg); |
| 2272 | r8a66597_write(r8a66597, ~BCHG, get_intsts_reg(port)); |
| 2273 | r8a66597_bset(r8a66597, BCHGE, get_intenb_reg(port)); |
| 2274 | } |
| 2275 | } |
| 2276 | |
| 2277 | r8a66597->bus_suspended = 1; |
| 2278 | |
| 2279 | return 0; |
| 2280 | } |
| 2281 | |
| 2282 | static int r8a66597_bus_resume(struct usb_hcd *hcd) |
| 2283 | { |
| 2284 | struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); |
| 2285 | int port; |
| 2286 | |
| 2287 | dbg("%s", __func__); |
| 2288 | |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 2289 | for (port = 0; port < r8a66597->max_root_hub; port++) { |
Yoshihiro Shimoda | e1e609b | 2009-03-19 14:18:15 +0900 | [diff] [blame] | 2290 | struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; |
| 2291 | unsigned long dvstctr_reg = get_dvstctr_reg(port); |
| 2292 | |
| 2293 | if (!(rh->port & (1 << USB_PORT_FEAT_SUSPEND))) |
| 2294 | continue; |
| 2295 | |
| 2296 | dbg("resume port = %d", port); |
| 2297 | rh->port &= ~(1 << USB_PORT_FEAT_SUSPEND); |
| 2298 | rh->port |= 1 << USB_PORT_FEAT_C_SUSPEND; |
| 2299 | r8a66597_mdfy(r8a66597, RESUME, RESUME | UACT, dvstctr_reg); |
| 2300 | msleep(50); |
| 2301 | r8a66597_mdfy(r8a66597, UACT, RESUME | UACT, dvstctr_reg); |
| 2302 | } |
| 2303 | |
| 2304 | return 0; |
| 2305 | |
| 2306 | } |
| 2307 | #else |
| 2308 | #define r8a66597_bus_suspend NULL |
| 2309 | #define r8a66597_bus_resume NULL |
| 2310 | #endif |
| 2311 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2312 | static struct hc_driver r8a66597_hc_driver = { |
| 2313 | .description = hcd_name, |
| 2314 | .hcd_priv_size = sizeof(struct r8a66597), |
| 2315 | .irq = r8a66597_irq, |
| 2316 | |
| 2317 | /* |
| 2318 | * generic hardware linkage |
| 2319 | */ |
| 2320 | .flags = HCD_USB2, |
| 2321 | |
| 2322 | .start = r8a66597_start, |
| 2323 | .stop = r8a66597_stop, |
| 2324 | |
| 2325 | /* |
| 2326 | * managing i/o requests and associated device resources |
| 2327 | */ |
| 2328 | .urb_enqueue = r8a66597_urb_enqueue, |
| 2329 | .urb_dequeue = r8a66597_urb_dequeue, |
| 2330 | .endpoint_disable = r8a66597_endpoint_disable, |
| 2331 | |
| 2332 | /* |
| 2333 | * periodic schedule support |
| 2334 | */ |
| 2335 | .get_frame_number = r8a66597_get_frame, |
| 2336 | |
| 2337 | /* |
| 2338 | * root hub support |
| 2339 | */ |
| 2340 | .hub_status_data = r8a66597_hub_status_data, |
| 2341 | .hub_control = r8a66597_hub_control, |
Yoshihiro Shimoda | e1e609b | 2009-03-19 14:18:15 +0900 | [diff] [blame] | 2342 | .bus_suspend = r8a66597_bus_suspend, |
| 2343 | .bus_resume = r8a66597_bus_resume, |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2344 | }; |
| 2345 | |
| 2346 | #if defined(CONFIG_PM) |
Magnus Damm | ae1cef6 | 2009-07-17 14:52:05 +0000 | [diff] [blame] | 2347 | static int r8a66597_suspend(struct device *dev) |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2348 | { |
Magnus Damm | ae1cef6 | 2009-07-17 14:52:05 +0000 | [diff] [blame] | 2349 | struct r8a66597 *r8a66597 = dev_get_drvdata(dev); |
Yoshihiro Shimoda | e1e609b | 2009-03-19 14:18:15 +0900 | [diff] [blame] | 2350 | int port; |
| 2351 | |
| 2352 | dbg("%s", __func__); |
| 2353 | |
| 2354 | disable_controller(r8a66597); |
| 2355 | |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 2356 | for (port = 0; port < r8a66597->max_root_hub; port++) { |
Yoshihiro Shimoda | e1e609b | 2009-03-19 14:18:15 +0900 | [diff] [blame] | 2357 | struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; |
| 2358 | |
| 2359 | rh->port = 0x00000000; |
| 2360 | } |
| 2361 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2362 | return 0; |
| 2363 | } |
| 2364 | |
Magnus Damm | ae1cef6 | 2009-07-17 14:52:05 +0000 | [diff] [blame] | 2365 | static int r8a66597_resume(struct device *dev) |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2366 | { |
Magnus Damm | ae1cef6 | 2009-07-17 14:52:05 +0000 | [diff] [blame] | 2367 | struct r8a66597 *r8a66597 = dev_get_drvdata(dev); |
Yoshihiro Shimoda | e1e609b | 2009-03-19 14:18:15 +0900 | [diff] [blame] | 2368 | struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597); |
| 2369 | |
| 2370 | dbg("%s", __func__); |
| 2371 | |
| 2372 | enable_controller(r8a66597); |
| 2373 | usb_root_hub_lost_power(hcd->self.root_hub); |
| 2374 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2375 | return 0; |
| 2376 | } |
Magnus Damm | ae1cef6 | 2009-07-17 14:52:05 +0000 | [diff] [blame] | 2377 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 2378 | static const struct dev_pm_ops r8a66597_dev_pm_ops = { |
Magnus Damm | ae1cef6 | 2009-07-17 14:52:05 +0000 | [diff] [blame] | 2379 | .suspend = r8a66597_suspend, |
| 2380 | .resume = r8a66597_resume, |
Yoshihiro Shimoda | 3725f28 | 2009-07-29 09:24:41 +0000 | [diff] [blame] | 2381 | .poweroff = r8a66597_suspend, |
| 2382 | .restore = r8a66597_resume, |
Magnus Damm | ae1cef6 | 2009-07-17 14:52:05 +0000 | [diff] [blame] | 2383 | }; |
| 2384 | |
| 2385 | #define R8A66597_DEV_PM_OPS (&r8a66597_dev_pm_ops) |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2386 | #else /* if defined(CONFIG_PM) */ |
Magnus Damm | ae1cef6 | 2009-07-17 14:52:05 +0000 | [diff] [blame] | 2387 | #define R8A66597_DEV_PM_OPS NULL |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2388 | #endif |
| 2389 | |
| 2390 | static int __init_or_module r8a66597_remove(struct platform_device *pdev) |
| 2391 | { |
| 2392 | struct r8a66597 *r8a66597 = dev_get_drvdata(&pdev->dev); |
| 2393 | struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597); |
| 2394 | |
| 2395 | del_timer_sync(&r8a66597->rh_timer); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2396 | usb_remove_hcd(hcd); |
Yoshihiro Shimoda | ca0677a | 2007-10-05 15:53:12 +0900 | [diff] [blame] | 2397 | iounmap((void *)r8a66597->reg); |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 2398 | #ifdef CONFIG_HAVE_CLK |
| 2399 | if (r8a66597->pdata->on_chip) |
| 2400 | clk_put(r8a66597->clk); |
Magnus Damm | 765786e | 2008-10-31 20:22:38 +0900 | [diff] [blame] | 2401 | #endif |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2402 | usb_put_hcd(hcd); |
| 2403 | return 0; |
| 2404 | } |
| 2405 | |
Uwe Kleine-König | 8864bd8 | 2009-03-28 00:27:00 +0100 | [diff] [blame] | 2406 | static int __devinit r8a66597_probe(struct platform_device *pdev) |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2407 | { |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 2408 | #ifdef CONFIG_HAVE_CLK |
Magnus Damm | 765786e | 2008-10-31 20:22:38 +0900 | [diff] [blame] | 2409 | char clk_name[8]; |
| 2410 | #endif |
Marc Zyngier | 2714021 | 2008-08-18 13:08:42 +0200 | [diff] [blame] | 2411 | struct resource *res = NULL, *ires; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2412 | int irq = -1; |
| 2413 | void __iomem *reg = NULL; |
| 2414 | struct usb_hcd *hcd = NULL; |
| 2415 | struct r8a66597 *r8a66597; |
| 2416 | int ret = 0; |
| 2417 | int i; |
Yoshihiro Shimoda | 0bf32b8 | 2008-06-27 19:09:55 +0900 | [diff] [blame] | 2418 | unsigned long irq_trigger; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2419 | |
| 2420 | if (pdev->dev.dma_mask) { |
| 2421 | ret = -EINVAL; |
Greg Kroah-Hartman | 802f389 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 2422 | dev_err(&pdev->dev, "dma not supported\n"); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2423 | goto clean_up; |
| 2424 | } |
| 2425 | |
Magnus Damm | 0a2e5b9 | 2008-11-13 15:46:37 +0900 | [diff] [blame] | 2426 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2427 | if (!res) { |
| 2428 | ret = -ENODEV; |
Magnus Damm | 0a2e5b9 | 2008-11-13 15:46:37 +0900 | [diff] [blame] | 2429 | dev_err(&pdev->dev, "platform_get_resource error.\n"); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2430 | goto clean_up; |
| 2431 | } |
| 2432 | |
Marc Zyngier | 2714021 | 2008-08-18 13:08:42 +0200 | [diff] [blame] | 2433 | ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 2434 | if (!ires) { |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2435 | ret = -ENODEV; |
Greg Kroah-Hartman | 802f389 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 2436 | dev_err(&pdev->dev, |
| 2437 | "platform_get_resource IORESOURCE_IRQ error.\n"); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2438 | goto clean_up; |
| 2439 | } |
| 2440 | |
Marc Zyngier | 2714021 | 2008-08-18 13:08:42 +0200 | [diff] [blame] | 2441 | irq = ires->start; |
| 2442 | irq_trigger = ires->flags & IRQF_TRIGGER_MASK; |
| 2443 | |
Magnus Damm | 0a2e5b9 | 2008-11-13 15:46:37 +0900 | [diff] [blame] | 2444 | reg = ioremap(res->start, resource_size(res)); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2445 | if (reg == NULL) { |
| 2446 | ret = -ENOMEM; |
Greg Kroah-Hartman | 802f389 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 2447 | dev_err(&pdev->dev, "ioremap error.\n"); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2448 | goto clean_up; |
| 2449 | } |
| 2450 | |
Yoshihiro Shimoda | 5effabb | 2009-05-26 18:24:34 +0900 | [diff] [blame] | 2451 | if (pdev->dev.platform_data == NULL) { |
| 2452 | dev_err(&pdev->dev, "no platform data\n"); |
| 2453 | ret = -ENODEV; |
| 2454 | goto clean_up; |
| 2455 | } |
| 2456 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2457 | /* initialize hcd */ |
| 2458 | hcd = usb_create_hcd(&r8a66597_hc_driver, &pdev->dev, (char *)hcd_name); |
| 2459 | if (!hcd) { |
| 2460 | ret = -ENOMEM; |
Greg Kroah-Hartman | 802f389 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 2461 | dev_err(&pdev->dev, "Failed to create hcd\n"); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2462 | goto clean_up; |
| 2463 | } |
| 2464 | r8a66597 = hcd_to_r8a66597(hcd); |
| 2465 | memset(r8a66597, 0, sizeof(struct r8a66597)); |
| 2466 | dev_set_drvdata(&pdev->dev, r8a66597); |
Yoshihiro Shimoda | 5effabb | 2009-05-26 18:24:34 +0900 | [diff] [blame] | 2467 | r8a66597->pdata = pdev->dev.platform_data; |
| 2468 | r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2469 | |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 2470 | if (r8a66597->pdata->on_chip) { |
| 2471 | #ifdef CONFIG_HAVE_CLK |
| 2472 | snprintf(clk_name, sizeof(clk_name), "usb%d", pdev->id); |
| 2473 | r8a66597->clk = clk_get(&pdev->dev, clk_name); |
| 2474 | if (IS_ERR(r8a66597->clk)) { |
| 2475 | dev_err(&pdev->dev, "cannot get clock \"%s\"\n", |
| 2476 | clk_name); |
| 2477 | ret = PTR_ERR(r8a66597->clk); |
| 2478 | goto clean_up2; |
| 2479 | } |
Magnus Damm | 765786e | 2008-10-31 20:22:38 +0900 | [diff] [blame] | 2480 | #endif |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 2481 | r8a66597->max_root_hub = 1; |
| 2482 | } else |
| 2483 | r8a66597->max_root_hub = 2; |
Magnus Damm | 765786e | 2008-10-31 20:22:38 +0900 | [diff] [blame] | 2484 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2485 | spin_lock_init(&r8a66597->lock); |
| 2486 | init_timer(&r8a66597->rh_timer); |
| 2487 | r8a66597->rh_timer.function = r8a66597_timer; |
| 2488 | r8a66597->rh_timer.data = (unsigned long)r8a66597; |
| 2489 | r8a66597->reg = (unsigned long)reg; |
| 2490 | |
Magnus Damm | e5ff15b | 2010-01-27 07:41:19 +0000 | [diff] [blame] | 2491 | /* make sure no interrupts are pending */ |
| 2492 | ret = r8a66597_clock_enable(r8a66597); |
| 2493 | if (ret < 0) |
| 2494 | goto clean_up3; |
| 2495 | disable_controller(r8a66597); |
| 2496 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2497 | for (i = 0; i < R8A66597_MAX_NUM_PIPE; i++) { |
| 2498 | INIT_LIST_HEAD(&r8a66597->pipe_queue[i]); |
| 2499 | init_timer(&r8a66597->td_timer[i]); |
| 2500 | r8a66597->td_timer[i].function = r8a66597_td_timer; |
| 2501 | r8a66597->td_timer[i].data = (unsigned long)r8a66597; |
Yoshihiro Shimoda | 6d87910 | 2008-04-10 21:05:47 +0900 | [diff] [blame] | 2502 | setup_timer(&r8a66597->interval_timer[i], |
| 2503 | r8a66597_interval_timer, |
| 2504 | (unsigned long)r8a66597); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2505 | } |
| 2506 | INIT_LIST_HEAD(&r8a66597->child_device); |
| 2507 | |
| 2508 | hcd->rsrc_start = res->start; |
Marc Zyngier | 2714021 | 2008-08-18 13:08:42 +0200 | [diff] [blame] | 2509 | |
Yoshihiro Shimoda | 0bf32b8 | 2008-06-27 19:09:55 +0900 | [diff] [blame] | 2510 | ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | irq_trigger); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2511 | if (ret != 0) { |
Greg Kroah-Hartman | 802f389 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 2512 | dev_err(&pdev->dev, "Failed to add hcd\n"); |
Magnus Damm | 765786e | 2008-10-31 20:22:38 +0900 | [diff] [blame] | 2513 | goto clean_up3; |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2514 | } |
| 2515 | |
| 2516 | return 0; |
| 2517 | |
Magnus Damm | 765786e | 2008-10-31 20:22:38 +0900 | [diff] [blame] | 2518 | clean_up3: |
Magnus Damm | 719a72b | 2009-07-17 14:59:55 +0000 | [diff] [blame] | 2519 | #ifdef CONFIG_HAVE_CLK |
| 2520 | if (r8a66597->pdata->on_chip) |
| 2521 | clk_put(r8a66597->clk); |
Magnus Damm | 765786e | 2008-10-31 20:22:38 +0900 | [diff] [blame] | 2522 | clean_up2: |
Paul Mundt | d643510 | 2008-11-18 12:40:39 +0900 | [diff] [blame] | 2523 | #endif |
Magnus Damm | 765786e | 2008-10-31 20:22:38 +0900 | [diff] [blame] | 2524 | usb_put_hcd(hcd); |
| 2525 | |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2526 | clean_up: |
| 2527 | if (reg) |
| 2528 | iounmap(reg); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2529 | |
| 2530 | return ret; |
| 2531 | } |
| 2532 | |
| 2533 | static struct platform_driver r8a66597_driver = { |
| 2534 | .probe = r8a66597_probe, |
| 2535 | .remove = r8a66597_remove, |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2536 | .driver = { |
| 2537 | .name = (char *) hcd_name, |
Kay Sievers | f4fce61 | 2008-04-10 21:29:22 -0700 | [diff] [blame] | 2538 | .owner = THIS_MODULE, |
Magnus Damm | ae1cef6 | 2009-07-17 14:52:05 +0000 | [diff] [blame] | 2539 | .pm = R8A66597_DEV_PM_OPS, |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2540 | }, |
| 2541 | }; |
| 2542 | |
| 2543 | static int __init r8a66597_init(void) |
| 2544 | { |
| 2545 | if (usb_disabled()) |
| 2546 | return -ENODEV; |
| 2547 | |
Greg Kroah-Hartman | 5909f6e | 2008-08-18 13:21:04 -0700 | [diff] [blame] | 2548 | printk(KERN_INFO KBUILD_MODNAME ": driver %s, %s\n", hcd_name, |
| 2549 | DRIVER_VERSION); |
Yoshihiro Shimoda | 5d30435 | 2007-05-10 13:18:19 +0900 | [diff] [blame] | 2550 | return platform_driver_register(&r8a66597_driver); |
| 2551 | } |
| 2552 | module_init(r8a66597_init); |
| 2553 | |
| 2554 | static void __exit r8a66597_cleanup(void) |
| 2555 | { |
| 2556 | platform_driver_unregister(&r8a66597_driver); |
| 2557 | } |
| 2558 | module_exit(r8a66597_cleanup); |
| 2559 | |