Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Renesas USB driver |
| 3 | * |
| 4 | * Copyright (C) 2011 Renesas Solutions Corp. |
| 5 | * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | * You should have received a copy of the GNU General Public License |
| 13 | * along with this program; if not, write to the Free Software |
| 14 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 15 | * |
| 16 | */ |
| 17 | #include <linux/io.h> |
| 18 | #include <linux/list.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/slab.h> |
| 22 | #include <linux/usb.h> |
| 23 | #include <linux/usb/hcd.h> |
| 24 | #include "common.h" |
| 25 | |
| 26 | /* |
| 27 | *** HARDWARE LIMITATION *** |
| 28 | * |
| 29 | * 1) renesas_usbhs has a limited number of controllable devices. |
| 30 | * it can control only 9 devices in generally. |
| 31 | * see DEVADDn / DCPMAXP / PIPEMAXP. |
| 32 | * |
| 33 | * 2) renesas_usbhs pipe number is limited. |
| 34 | * the pipe will be re-used for each devices. |
| 35 | * so, software should control DATA0/1 sequence of each devices. |
| 36 | */ |
| 37 | |
| 38 | |
| 39 | /* |
| 40 | * image of mod_host |
| 41 | * |
| 42 | * +--------+ |
| 43 | * | udev 0 | --> it is used when set address |
| 44 | * +--------+ |
| 45 | * |
| 46 | * +--------+ pipes are reused for each uep. |
| 47 | * | udev 1 |-+- [uep 0 (dcp) ] --+ pipe will be switched when |
Kuninori Morimoto | e5679d0 | 2011-12-08 18:28:24 -0800 | [diff] [blame] | 48 | * +--------+ | | other device requested |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 49 | * +- [uep 1 (bulk)] --|---+ +--------------+ |
| 50 | * | +--------------> | pipe0 (dcp) | |
Kuninori Morimoto | e5679d0 | 2011-12-08 18:28:24 -0800 | [diff] [blame] | 51 | * +- [uep 2 (bulk)] -@ | +--------------+ |
| 52 | * | | pipe1 (isoc) | |
| 53 | * +--------+ | +--------------+ |
| 54 | * | udev 2 |-+- [uep 0 (dcp) ] -@ +----------> | pipe2 (bulk) | |
| 55 | * +--------+ | +--------------+ |
| 56 | * +- [uep 1 (int) ] ----+ +------> | pipe3 (bulk) | |
| 57 | * | | +--------------+ |
| 58 | * +--------+ +-----|------> | pipe4 (int) | |
| 59 | * | udev 3 |-+- [uep 0 (dcp) ] -@ | +--------------+ |
| 60 | * +--------+ | | | .... | |
| 61 | * +- [uep 1 (bulk)] -@ | | .... | |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 62 | * | | |
| 63 | * +- [uep 2 (bulk)]-----------+ |
Kuninori Morimoto | e5679d0 | 2011-12-08 18:28:24 -0800 | [diff] [blame] | 64 | * |
| 65 | * @ : uep requested free pipe, but all have been used. |
| 66 | * now it is waiting for free pipe |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 67 | */ |
| 68 | |
| 69 | |
| 70 | /* |
| 71 | * struct |
| 72 | */ |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 73 | struct usbhsh_request { |
| 74 | struct urb *urb; |
| 75 | struct usbhs_pkt pkt; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | struct usbhsh_device { |
| 79 | struct usb_device *usbv; |
| 80 | struct list_head ep_list_head; /* list of usbhsh_ep */ |
| 81 | }; |
| 82 | |
| 83 | struct usbhsh_ep { |
Kuninori Morimoto | e5679d0 | 2011-12-08 18:28:24 -0800 | [diff] [blame] | 84 | struct usbhs_pipe *pipe; /* attached pipe */ |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 85 | struct usbhsh_device *udev; /* attached udev */ |
Kuninori Morimoto | e4c57de | 2011-12-08 18:27:49 -0800 | [diff] [blame] | 86 | struct usb_host_endpoint *ep; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 87 | struct list_head ep_list; /* list to usbhsh_device */ |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | #define USBHSH_DEVICE_MAX 10 /* see DEVADDn / DCPMAXP / PIPEMAXP */ |
| 91 | #define USBHSH_PORT_MAX 7 /* see DEVADDn :: HUBPORT */ |
| 92 | struct usbhsh_hpriv { |
| 93 | struct usbhs_mod mod; |
| 94 | struct usbhs_pipe *dcp; |
| 95 | |
| 96 | struct usbhsh_device udev[USBHSH_DEVICE_MAX]; |
| 97 | |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 98 | u32 port_stat; /* USB_PORT_STAT_xxx */ |
| 99 | |
Kuninori Morimoto | 7fccd48 | 2011-10-23 22:55:54 -0700 | [diff] [blame] | 100 | struct completion setup_ack_done; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | |
| 104 | static const char usbhsh_hcd_name[] = "renesas_usbhs host"; |
| 105 | |
| 106 | /* |
| 107 | * macro |
| 108 | */ |
| 109 | #define usbhsh_priv_to_hpriv(priv) \ |
| 110 | container_of(usbhs_mod_get(priv, USBHS_HOST), struct usbhsh_hpriv, mod) |
| 111 | |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 112 | #define __usbhsh_for_each_udev(start, pos, h, i) \ |
| 113 | for (i = start, pos = (h)->udev + i; \ |
| 114 | i < USBHSH_DEVICE_MAX; \ |
| 115 | i++, pos = (h)->udev + i) |
| 116 | |
| 117 | #define usbhsh_for_each_udev(pos, hpriv, i) \ |
| 118 | __usbhsh_for_each_udev(1, pos, hpriv, i) |
| 119 | |
| 120 | #define usbhsh_for_each_udev_with_dev0(pos, hpriv, i) \ |
| 121 | __usbhsh_for_each_udev(0, pos, hpriv, i) |
| 122 | |
| 123 | #define usbhsh_hcd_to_hpriv(h) (struct usbhsh_hpriv *)((h)->hcd_priv) |
| 124 | #define usbhsh_hcd_to_dev(h) ((h)->self.controller) |
| 125 | |
| 126 | #define usbhsh_hpriv_to_priv(h) ((h)->mod.priv) |
| 127 | #define usbhsh_hpriv_to_dcp(h) ((h)->dcp) |
| 128 | #define usbhsh_hpriv_to_hcd(h) \ |
| 129 | container_of((void *)h, struct usb_hcd, hcd_priv) |
| 130 | |
| 131 | #define usbhsh_ep_to_uep(u) ((u)->hcpriv) |
| 132 | #define usbhsh_uep_to_pipe(u) ((u)->pipe) |
| 133 | #define usbhsh_uep_to_udev(u) ((u)->udev) |
Kuninori Morimoto | e4c57de | 2011-12-08 18:27:49 -0800 | [diff] [blame] | 134 | #define usbhsh_uep_to_ep(u) ((u)->ep) |
| 135 | |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 136 | #define usbhsh_urb_to_ureq(u) ((u)->hcpriv) |
| 137 | #define usbhsh_urb_to_usbv(u) ((u)->dev) |
| 138 | |
| 139 | #define usbhsh_usbv_to_udev(d) dev_get_drvdata(&(d)->dev) |
| 140 | |
| 141 | #define usbhsh_udev_to_usbv(h) ((h)->usbv) |
Kuninori Morimoto | ab14230 | 2011-10-31 00:48:00 -0700 | [diff] [blame] | 142 | #define usbhsh_udev_is_used(h) usbhsh_udev_to_usbv(h) |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 143 | |
Kuninori Morimoto | e5679d0 | 2011-12-08 18:28:24 -0800 | [diff] [blame] | 144 | #define usbhsh_pipe_to_uep(p) ((p)->mod_private) |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 145 | |
Kuninori Morimoto | 9c67365 | 2011-10-31 00:47:34 -0700 | [diff] [blame] | 146 | #define usbhsh_device_parent(d) (usbhsh_usbv_to_udev((d)->usbv->parent)) |
| 147 | #define usbhsh_device_hubport(d) ((d)->usbv->portnum) |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 148 | #define usbhsh_device_number(h, d) ((int)((d) - (h)->udev)) |
| 149 | #define usbhsh_device_nth(h, d) ((h)->udev + d) |
| 150 | #define usbhsh_device0(h) usbhsh_device_nth(h, 0) |
| 151 | |
| 152 | #define usbhsh_port_stat_init(h) ((h)->port_stat = 0) |
| 153 | #define usbhsh_port_stat_set(h, s) ((h)->port_stat |= (s)) |
| 154 | #define usbhsh_port_stat_clear(h, s) ((h)->port_stat &= ~(s)) |
| 155 | #define usbhsh_port_stat_get(h) ((h)->port_stat) |
| 156 | |
Kuninori Morimoto | 25234b4 | 2011-10-23 19:56:53 -0700 | [diff] [blame] | 157 | #define usbhsh_pkt_to_ureq(p) \ |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 158 | container_of((void *)p, struct usbhsh_request, pkt) |
| 159 | |
| 160 | /* |
| 161 | * req alloc/free |
| 162 | */ |
Kuninori Morimoto | 25234b4 | 2011-10-23 19:56:53 -0700 | [diff] [blame] | 163 | static struct usbhsh_request *usbhsh_ureq_alloc(struct usbhsh_hpriv *hpriv, |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 164 | struct urb *urb, |
| 165 | gfp_t mem_flags) |
| 166 | { |
| 167 | struct usbhsh_request *ureq; |
| 168 | struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv); |
| 169 | struct device *dev = usbhs_priv_to_dev(priv); |
| 170 | |
Kuninori Morimoto | c5b963f | 2011-10-31 00:47:44 -0700 | [diff] [blame] | 171 | ureq = kzalloc(sizeof(struct usbhsh_request), mem_flags); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 172 | if (!ureq) { |
| 173 | dev_err(dev, "ureq alloc fail\n"); |
| 174 | return NULL; |
| 175 | } |
| 176 | |
| 177 | usbhs_pkt_init(&ureq->pkt); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 178 | ureq->urb = urb; |
Kuninori Morimoto | fc9d5c7 | 2011-10-31 00:47:01 -0700 | [diff] [blame] | 179 | usbhsh_urb_to_ureq(urb) = ureq; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 180 | |
| 181 | return ureq; |
| 182 | } |
| 183 | |
Kuninori Morimoto | 25234b4 | 2011-10-23 19:56:53 -0700 | [diff] [blame] | 184 | static void usbhsh_ureq_free(struct usbhsh_hpriv *hpriv, |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 185 | struct usbhsh_request *ureq) |
| 186 | { |
Kuninori Morimoto | fc9d5c7 | 2011-10-31 00:47:01 -0700 | [diff] [blame] | 187 | usbhsh_urb_to_ureq(ureq->urb) = NULL; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 188 | ureq->urb = NULL; |
Kuninori Morimoto | c5b963f | 2011-10-31 00:47:44 -0700 | [diff] [blame] | 189 | |
| 190 | kfree(ureq); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | /* |
Kuninori Morimoto | b1930da | 2011-12-08 18:30:23 -0800 | [diff] [blame^] | 194 | * status |
| 195 | */ |
| 196 | static int usbhsh_is_running(struct usbhsh_hpriv *hpriv) |
| 197 | { |
| 198 | /* |
| 199 | * we can decide some device is attached or not |
| 200 | * by checking mod.irq_attch |
| 201 | * see |
| 202 | * usbhsh_irq_attch() |
| 203 | * usbhsh_irq_dtch() |
| 204 | */ |
| 205 | return (hpriv->mod.irq_attch == NULL); |
| 206 | } |
| 207 | |
| 208 | /* |
Kuninori Morimoto | e5679d0 | 2011-12-08 18:28:24 -0800 | [diff] [blame] | 209 | * pipe control |
Kuninori Morimoto | e4c57de | 2011-12-08 18:27:49 -0800 | [diff] [blame] | 210 | */ |
Kuninori Morimoto | 3edeee3 | 2011-12-08 18:28:54 -0800 | [diff] [blame] | 211 | static void usbhsh_endpoint_sequence_save(struct usbhsh_hpriv *hpriv, |
| 212 | struct urb *urb, |
| 213 | struct usbhs_pkt *pkt) |
| 214 | { |
| 215 | int len = urb->actual_length; |
| 216 | int maxp = usb_endpoint_maxp(&urb->ep->desc); |
| 217 | int t = 0; |
| 218 | |
| 219 | /* DCP is out of sequence control */ |
| 220 | if (usb_pipecontrol(urb->pipe)) |
| 221 | return; |
| 222 | |
| 223 | /* |
| 224 | * renesas_usbhs pipe has a limitation in a number. |
| 225 | * So, driver should re-use the limited pipe for each device/endpoint. |
| 226 | * DATA0/1 sequence should be saved for it. |
| 227 | * see [image of mod_host] |
| 228 | * [HARDWARE LIMITATION] |
| 229 | */ |
| 230 | |
| 231 | /* |
| 232 | * next sequence depends on actual_length |
| 233 | * |
| 234 | * ex) actual_length = 1147, maxp = 512 |
| 235 | * data0 : 512 |
| 236 | * data1 : 512 |
| 237 | * data0 : 123 |
| 238 | * data1 is the next sequence |
| 239 | */ |
| 240 | t = len / maxp; |
| 241 | if (len % maxp) |
| 242 | t++; |
| 243 | if (pkt->zero) |
| 244 | t++; |
| 245 | t %= 2; |
| 246 | |
| 247 | if (t) |
| 248 | usb_dotoggle(urb->dev, |
| 249 | usb_pipeendpoint(urb->pipe), |
| 250 | usb_pipeout(urb->pipe)); |
| 251 | } |
| 252 | |
Kuninori Morimoto | e4c57de | 2011-12-08 18:27:49 -0800 | [diff] [blame] | 253 | static struct usbhsh_device *usbhsh_device_get(struct usbhsh_hpriv *hpriv, |
| 254 | struct urb *urb); |
Kuninori Morimoto | e5679d0 | 2011-12-08 18:28:24 -0800 | [diff] [blame] | 255 | |
| 256 | static int usbhsh_pipe_attach(struct usbhsh_hpriv *hpriv, |
| 257 | struct urb *urb) |
| 258 | { |
| 259 | struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv); |
| 260 | struct usbhsh_ep *uep = usbhsh_ep_to_uep(urb->ep); |
| 261 | struct usbhsh_device *udev = usbhsh_device_get(hpriv, urb); |
| 262 | struct usbhs_pipe *pipe; |
| 263 | struct usb_endpoint_descriptor *desc = &urb->ep->desc; |
| 264 | struct device *dev = usbhs_priv_to_dev(priv); |
| 265 | unsigned long flags; |
| 266 | int dir_in_req = !!usb_pipein(urb->pipe); |
| 267 | int is_dcp = usb_endpoint_xfer_control(desc); |
| 268 | int i, dir_in; |
| 269 | int ret = -EBUSY; |
| 270 | |
| 271 | /******************** spin lock ********************/ |
| 272 | usbhs_lock(priv, flags); |
| 273 | |
| 274 | if (unlikely(usbhsh_uep_to_pipe(uep))) { |
| 275 | dev_err(dev, "uep already has pipe\n"); |
| 276 | goto usbhsh_pipe_attach_done; |
| 277 | } |
| 278 | |
| 279 | usbhs_for_each_pipe_with_dcp(pipe, priv, i) { |
| 280 | |
| 281 | /* check pipe type */ |
| 282 | if (!usbhs_pipe_type_is(pipe, usb_endpoint_type(desc))) |
| 283 | continue; |
| 284 | |
| 285 | /* check pipe direction if normal pipe */ |
| 286 | if (!is_dcp) { |
| 287 | dir_in = !!usbhs_pipe_is_dir_in(pipe); |
| 288 | if (0 != (dir_in - dir_in_req)) |
| 289 | continue; |
| 290 | } |
| 291 | |
| 292 | /* check pipe is free */ |
| 293 | if (usbhsh_pipe_to_uep(pipe)) |
| 294 | continue; |
| 295 | |
| 296 | /* |
| 297 | * attach pipe to uep |
| 298 | * |
| 299 | * usbhs_pipe_config_update() should be called after |
| 300 | * usbhs_set_device_config() |
| 301 | * see |
| 302 | * DCPMAXP/PIPEMAXP |
| 303 | */ |
| 304 | usbhsh_uep_to_pipe(uep) = pipe; |
| 305 | usbhsh_pipe_to_uep(pipe) = uep; |
| 306 | |
Kuninori Morimoto | e5679d0 | 2011-12-08 18:28:24 -0800 | [diff] [blame] | 307 | usbhs_pipe_config_update(pipe, |
| 308 | usbhsh_device_number(hpriv, udev), |
| 309 | usb_endpoint_num(desc), |
| 310 | usb_endpoint_maxp(desc)); |
| 311 | |
| 312 | dev_dbg(dev, "%s [%d-%d(%s:%s)]\n", __func__, |
| 313 | usbhsh_device_number(hpriv, udev), |
| 314 | usb_endpoint_num(desc), |
| 315 | usbhs_pipe_name(pipe), |
| 316 | dir_in_req ? "in" : "out"); |
| 317 | |
| 318 | ret = 0; |
| 319 | break; |
| 320 | } |
| 321 | |
| 322 | usbhsh_pipe_attach_done: |
| 323 | usbhs_unlock(priv, flags); |
| 324 | /******************** spin unlock ******************/ |
| 325 | |
| 326 | return ret; |
| 327 | } |
| 328 | |
| 329 | static void usbhsh_pipe_detach(struct usbhsh_hpriv *hpriv, |
| 330 | struct usbhsh_ep *uep) |
| 331 | { |
| 332 | struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv); |
| 333 | struct usbhs_pipe *pipe; |
| 334 | struct device *dev = usbhs_priv_to_dev(priv); |
| 335 | unsigned long flags; |
| 336 | |
| 337 | /******************** spin lock ********************/ |
| 338 | usbhs_lock(priv, flags); |
| 339 | |
| 340 | pipe = usbhsh_uep_to_pipe(uep); |
| 341 | |
| 342 | if (unlikely(!pipe)) { |
| 343 | dev_err(dev, "uep doens't have pipe\n"); |
| 344 | } else { |
| 345 | struct usb_host_endpoint *ep = usbhsh_uep_to_ep(uep); |
| 346 | struct usbhsh_device *udev = usbhsh_uep_to_udev(uep); |
| 347 | |
| 348 | /* detach pipe from uep */ |
| 349 | usbhsh_uep_to_pipe(uep) = NULL; |
| 350 | usbhsh_pipe_to_uep(pipe) = NULL; |
| 351 | |
| 352 | dev_dbg(dev, "%s [%d-%d(%s)]\n", __func__, |
| 353 | usbhsh_device_number(hpriv, udev), |
| 354 | usb_endpoint_num(&ep->desc), |
| 355 | usbhs_pipe_name(pipe)); |
| 356 | } |
| 357 | |
| 358 | usbhs_unlock(priv, flags); |
| 359 | /******************** spin unlock ******************/ |
| 360 | } |
| 361 | |
| 362 | /* |
| 363 | * endpoint control |
| 364 | */ |
Kuninori Morimoto | e4c57de | 2011-12-08 18:27:49 -0800 | [diff] [blame] | 365 | static int usbhsh_endpoint_attach(struct usbhsh_hpriv *hpriv, |
| 366 | struct urb *urb, |
| 367 | gfp_t mem_flags) |
| 368 | { |
| 369 | struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv); |
| 370 | struct usbhsh_device *udev = usbhsh_device_get(hpriv, urb); |
| 371 | struct usb_host_endpoint *ep = urb->ep; |
| 372 | struct usbhsh_ep *uep; |
Kuninori Morimoto | e4c57de | 2011-12-08 18:27:49 -0800 | [diff] [blame] | 373 | struct device *dev = usbhs_priv_to_dev(priv); |
| 374 | struct usb_endpoint_descriptor *desc = &ep->desc; |
| 375 | unsigned long flags; |
| 376 | |
| 377 | uep = kzalloc(sizeof(struct usbhsh_ep), mem_flags); |
| 378 | if (!uep) { |
| 379 | dev_err(dev, "usbhsh_ep alloc fail\n"); |
| 380 | return -ENOMEM; |
| 381 | } |
| 382 | |
| 383 | /******************** spin lock ********************/ |
| 384 | usbhs_lock(priv, flags); |
| 385 | |
| 386 | /* |
Kuninori Morimoto | e5679d0 | 2011-12-08 18:28:24 -0800 | [diff] [blame] | 387 | * init endpoint |
Kuninori Morimoto | e4c57de | 2011-12-08 18:27:49 -0800 | [diff] [blame] | 388 | */ |
Kuninori Morimoto | e5679d0 | 2011-12-08 18:28:24 -0800 | [diff] [blame] | 389 | INIT_LIST_HEAD(&uep->ep_list); |
| 390 | list_add_tail(&uep->ep_list, &udev->ep_list_head); |
Kuninori Morimoto | e4c57de | 2011-12-08 18:27:49 -0800 | [diff] [blame] | 391 | |
Kuninori Morimoto | e4c57de | 2011-12-08 18:27:49 -0800 | [diff] [blame] | 392 | usbhsh_uep_to_udev(uep) = udev; |
| 393 | usbhsh_uep_to_ep(uep) = ep; |
| 394 | usbhsh_ep_to_uep(ep) = uep; |
| 395 | |
Kuninori Morimoto | e5679d0 | 2011-12-08 18:28:24 -0800 | [diff] [blame] | 396 | usbhs_unlock(priv, flags); |
| 397 | /******************** spin unlock ******************/ |
Kuninori Morimoto | e4c57de | 2011-12-08 18:27:49 -0800 | [diff] [blame] | 398 | |
Kuninori Morimoto | e5679d0 | 2011-12-08 18:28:24 -0800 | [diff] [blame] | 399 | dev_dbg(dev, "%s [%d-%d]\n", __func__, |
Kuninori Morimoto | e4c57de | 2011-12-08 18:27:49 -0800 | [diff] [blame] | 400 | usbhsh_device_number(hpriv, udev), |
Kuninori Morimoto | e5679d0 | 2011-12-08 18:28:24 -0800 | [diff] [blame] | 401 | usb_endpoint_num(desc)); |
Kuninori Morimoto | e4c57de | 2011-12-08 18:27:49 -0800 | [diff] [blame] | 402 | |
| 403 | return 0; |
| 404 | } |
| 405 | |
| 406 | static void usbhsh_endpoint_detach(struct usbhsh_hpriv *hpriv, |
| 407 | struct usb_host_endpoint *ep) |
| 408 | { |
| 409 | struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv); |
| 410 | struct device *dev = usbhs_priv_to_dev(priv); |
| 411 | struct usbhsh_ep *uep = usbhsh_ep_to_uep(ep); |
Kuninori Morimoto | e4c57de | 2011-12-08 18:27:49 -0800 | [diff] [blame] | 412 | unsigned long flags; |
| 413 | |
| 414 | if (!uep) |
| 415 | return; |
| 416 | |
Kuninori Morimoto | e5679d0 | 2011-12-08 18:28:24 -0800 | [diff] [blame] | 417 | dev_dbg(dev, "%s [%d-%d]\n", __func__, |
Kuninori Morimoto | e4c57de | 2011-12-08 18:27:49 -0800 | [diff] [blame] | 418 | usbhsh_device_number(hpriv, usbhsh_uep_to_udev(uep)), |
Kuninori Morimoto | e5679d0 | 2011-12-08 18:28:24 -0800 | [diff] [blame] | 419 | usb_endpoint_num(&ep->desc)); |
| 420 | |
| 421 | if (usbhsh_uep_to_pipe(uep)) |
| 422 | usbhsh_pipe_detach(hpriv, uep); |
Kuninori Morimoto | e4c57de | 2011-12-08 18:27:49 -0800 | [diff] [blame] | 423 | |
| 424 | /******************** spin lock ********************/ |
| 425 | usbhs_lock(priv, flags); |
| 426 | |
Kuninori Morimoto | e4c57de | 2011-12-08 18:27:49 -0800 | [diff] [blame] | 427 | /* remove this endpoint from udev */ |
| 428 | list_del_init(&uep->ep_list); |
| 429 | |
Kuninori Morimoto | e4c57de | 2011-12-08 18:27:49 -0800 | [diff] [blame] | 430 | usbhsh_uep_to_udev(uep) = NULL; |
| 431 | usbhsh_uep_to_ep(uep) = NULL; |
| 432 | usbhsh_ep_to_uep(ep) = NULL; |
| 433 | |
| 434 | usbhs_unlock(priv, flags); |
| 435 | /******************** spin unlock ******************/ |
| 436 | |
| 437 | kfree(uep); |
| 438 | } |
| 439 | |
| 440 | static void usbhsh_endpoint_detach_all(struct usbhsh_hpriv *hpriv, |
| 441 | struct usbhsh_device *udev) |
| 442 | { |
| 443 | struct usbhsh_ep *uep, *next; |
| 444 | |
| 445 | list_for_each_entry_safe(uep, next, &udev->ep_list_head, ep_list) |
| 446 | usbhsh_endpoint_detach(hpriv, usbhsh_uep_to_ep(uep)); |
| 447 | } |
| 448 | |
| 449 | /* |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 450 | * device control |
| 451 | */ |
Kuninori Morimoto | 9c67365 | 2011-10-31 00:47:34 -0700 | [diff] [blame] | 452 | static int usbhsh_connected_to_rhdev(struct usb_hcd *hcd, |
| 453 | struct usbhsh_device *udev) |
| 454 | { |
| 455 | struct usb_device *usbv = usbhsh_udev_to_usbv(udev); |
| 456 | |
| 457 | return hcd->self.root_hub == usbv->parent; |
| 458 | } |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 459 | |
| 460 | static int usbhsh_device_has_endpoint(struct usbhsh_device *udev) |
| 461 | { |
| 462 | return !list_empty(&udev->ep_list_head); |
| 463 | } |
| 464 | |
Kuninori Morimoto | c1e4877 | 2011-12-08 18:27:21 -0800 | [diff] [blame] | 465 | static struct usbhsh_device *usbhsh_device_get(struct usbhsh_hpriv *hpriv, |
| 466 | struct urb *urb) |
| 467 | { |
| 468 | struct usb_device *usbv = usbhsh_urb_to_usbv(urb); |
| 469 | struct usbhsh_device *udev = usbhsh_usbv_to_udev(usbv); |
| 470 | |
| 471 | /* usbhsh_device_attach() is still not called */ |
| 472 | if (!udev) |
| 473 | return NULL; |
| 474 | |
| 475 | /* if it is device0, return it */ |
| 476 | if (0 == usb_pipedevice(urb->pipe)) |
| 477 | return usbhsh_device0(hpriv); |
| 478 | |
| 479 | /* return attached device */ |
| 480 | return udev; |
| 481 | } |
| 482 | |
Kuninori Morimoto | 7aac8d1 | 2011-10-31 00:49:09 -0700 | [diff] [blame] | 483 | static struct usbhsh_device *usbhsh_device_attach(struct usbhsh_hpriv *hpriv, |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 484 | struct urb *urb) |
| 485 | { |
| 486 | struct usbhsh_device *udev = NULL; |
Kuninori Morimoto | c1e4877 | 2011-12-08 18:27:21 -0800 | [diff] [blame] | 487 | struct usbhsh_device *udev0 = usbhsh_device0(hpriv); |
| 488 | struct usbhsh_device *pos; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 489 | struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv); |
| 490 | struct device *dev = usbhsh_hcd_to_dev(hcd); |
| 491 | struct usb_device *usbv = usbhsh_urb_to_usbv(urb); |
| 492 | struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv); |
Kuninori Morimoto | d399f90 | 2011-10-31 00:48:35 -0700 | [diff] [blame] | 493 | unsigned long flags; |
Kuninori Morimoto | 9c67365 | 2011-10-31 00:47:34 -0700 | [diff] [blame] | 494 | u16 upphub, hubport; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 495 | int i; |
| 496 | |
Kuninori Morimoto | c1e4877 | 2011-12-08 18:27:21 -0800 | [diff] [blame] | 497 | /* |
| 498 | * This function should be called only while urb is pointing to device0. |
| 499 | * It will attach unused usbhsh_device to urb (usbv), |
| 500 | * and initialize device0. |
| 501 | * You can use usbhsh_device_get() to get "current" udev, |
| 502 | * and usbhsh_usbv_to_udev() is for "attached" udev. |
| 503 | */ |
| 504 | if (0 != usb_pipedevice(urb->pipe)) { |
| 505 | dev_err(dev, "%s fail: urb isn't pointing device0\n", __func__); |
| 506 | return NULL; |
| 507 | } |
| 508 | |
Kuninori Morimoto | d399f90 | 2011-10-31 00:48:35 -0700 | [diff] [blame] | 509 | /******************** spin lock ********************/ |
| 510 | usbhs_lock(priv, flags); |
| 511 | |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 512 | /* |
Kuninori Morimoto | c1e4877 | 2011-12-08 18:27:21 -0800 | [diff] [blame] | 513 | * find unused device |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 514 | */ |
Kuninori Morimoto | c1e4877 | 2011-12-08 18:27:21 -0800 | [diff] [blame] | 515 | usbhsh_for_each_udev(pos, hpriv, i) { |
| 516 | if (usbhsh_udev_is_used(pos)) |
| 517 | continue; |
| 518 | udev = pos; |
| 519 | break; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Kuninori Morimoto | d399f90 | 2011-10-31 00:48:35 -0700 | [diff] [blame] | 522 | if (udev) { |
| 523 | /* |
| 524 | * usbhsh_usbv_to_udev() |
| 525 | * usbhsh_udev_to_usbv() |
| 526 | * will be enable |
| 527 | */ |
| 528 | dev_set_drvdata(&usbv->dev, udev); |
| 529 | udev->usbv = usbv; |
| 530 | } |
| 531 | |
| 532 | usbhs_unlock(priv, flags); |
| 533 | /******************** spin unlock ******************/ |
| 534 | |
Kuninori Morimoto | ab14230 | 2011-10-31 00:48:00 -0700 | [diff] [blame] | 535 | if (!udev) { |
| 536 | dev_err(dev, "no free usbhsh_device\n"); |
| 537 | return NULL; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 538 | } |
| 539 | |
Kuninori Morimoto | e4c57de | 2011-12-08 18:27:49 -0800 | [diff] [blame] | 540 | if (usbhsh_device_has_endpoint(udev)) { |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 541 | dev_warn(dev, "udev have old endpoint\n"); |
Kuninori Morimoto | e4c57de | 2011-12-08 18:27:49 -0800 | [diff] [blame] | 542 | usbhsh_endpoint_detach_all(hpriv, udev); |
| 543 | } |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 544 | |
Kuninori Morimoto | e4c57de | 2011-12-08 18:27:49 -0800 | [diff] [blame] | 545 | if (usbhsh_device_has_endpoint(udev0)) { |
Kuninori Morimoto | c1e4877 | 2011-12-08 18:27:21 -0800 | [diff] [blame] | 546 | dev_warn(dev, "udev0 have old endpoint\n"); |
Kuninori Morimoto | e4c57de | 2011-12-08 18:27:49 -0800 | [diff] [blame] | 547 | usbhsh_endpoint_detach_all(hpriv, udev0); |
| 548 | } |
Kuninori Morimoto | c1e4877 | 2011-12-08 18:27:21 -0800 | [diff] [blame] | 549 | |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 550 | /* uep will be attached */ |
Kuninori Morimoto | c1e4877 | 2011-12-08 18:27:21 -0800 | [diff] [blame] | 551 | INIT_LIST_HEAD(&udev0->ep_list_head); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 552 | INIT_LIST_HEAD(&udev->ep_list_head); |
| 553 | |
Kuninori Morimoto | c1e4877 | 2011-12-08 18:27:21 -0800 | [diff] [blame] | 554 | /* |
| 555 | * set device0 config |
| 556 | */ |
| 557 | usbhs_set_device_config(priv, |
| 558 | 0, 0, 0, usbv->speed); |
| 559 | |
| 560 | /* |
| 561 | * set new device config |
| 562 | */ |
Kuninori Morimoto | 9c67365 | 2011-10-31 00:47:34 -0700 | [diff] [blame] | 563 | upphub = 0; |
| 564 | hubport = 0; |
| 565 | if (!usbhsh_connected_to_rhdev(hcd, udev)) { |
| 566 | /* if udev is not connected to rhdev, it means parent is Hub */ |
| 567 | struct usbhsh_device *parent = usbhsh_device_parent(udev); |
| 568 | |
| 569 | upphub = usbhsh_device_number(hpriv, parent); |
| 570 | hubport = usbhsh_device_hubport(udev); |
| 571 | |
| 572 | dev_dbg(dev, "%s connecte to Hub [%d:%d](%p)\n", __func__, |
| 573 | upphub, hubport, parent); |
| 574 | } |
| 575 | |
Kuninori Morimoto | 3dd4926 | 2011-10-31 00:47:13 -0700 | [diff] [blame] | 576 | usbhs_set_device_config(priv, |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 577 | usbhsh_device_number(hpriv, udev), |
Kuninori Morimoto | 9c67365 | 2011-10-31 00:47:34 -0700 | [diff] [blame] | 578 | upphub, hubport, usbv->speed); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 579 | |
| 580 | dev_dbg(dev, "%s [%d](%p)\n", __func__, |
| 581 | usbhsh_device_number(hpriv, udev), udev); |
| 582 | |
| 583 | return udev; |
| 584 | } |
| 585 | |
Kuninori Morimoto | 7aac8d1 | 2011-10-31 00:49:09 -0700 | [diff] [blame] | 586 | static void usbhsh_device_detach(struct usbhsh_hpriv *hpriv, |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 587 | struct usbhsh_device *udev) |
| 588 | { |
| 589 | struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv); |
Kuninori Morimoto | d399f90 | 2011-10-31 00:48:35 -0700 | [diff] [blame] | 590 | struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 591 | struct device *dev = usbhsh_hcd_to_dev(hcd); |
| 592 | struct usb_device *usbv = usbhsh_udev_to_usbv(udev); |
Kuninori Morimoto | d399f90 | 2011-10-31 00:48:35 -0700 | [diff] [blame] | 593 | unsigned long flags; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 594 | |
| 595 | dev_dbg(dev, "%s [%d](%p)\n", __func__, |
| 596 | usbhsh_device_number(hpriv, udev), udev); |
| 597 | |
Kuninori Morimoto | e4c57de | 2011-12-08 18:27:49 -0800 | [diff] [blame] | 598 | if (usbhsh_device_has_endpoint(udev)) { |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 599 | dev_warn(dev, "udev still have endpoint\n"); |
Kuninori Morimoto | e4c57de | 2011-12-08 18:27:49 -0800 | [diff] [blame] | 600 | usbhsh_endpoint_detach_all(hpriv, udev); |
| 601 | } |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 602 | |
Kuninori Morimoto | c1e4877 | 2011-12-08 18:27:21 -0800 | [diff] [blame] | 603 | /* |
| 604 | * There is nothing to do if it is device0. |
| 605 | * see |
| 606 | * usbhsh_device_attach() |
| 607 | * usbhsh_device_get() |
| 608 | */ |
| 609 | if (0 == usbhsh_device_number(hpriv, udev)) |
| 610 | return; |
| 611 | |
Kuninori Morimoto | d399f90 | 2011-10-31 00:48:35 -0700 | [diff] [blame] | 612 | /******************** spin lock ********************/ |
| 613 | usbhs_lock(priv, flags); |
| 614 | |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 615 | /* |
| 616 | * usbhsh_usbv_to_udev() |
| 617 | * usbhsh_udev_to_usbv() |
| 618 | * will be disable |
| 619 | */ |
| 620 | dev_set_drvdata(&usbv->dev, NULL); |
| 621 | udev->usbv = NULL; |
Kuninori Morimoto | d399f90 | 2011-10-31 00:48:35 -0700 | [diff] [blame] | 622 | |
| 623 | usbhs_unlock(priv, flags); |
| 624 | /******************** spin unlock ******************/ |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | /* |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 628 | * queue push/pop |
| 629 | */ |
| 630 | static void usbhsh_queue_done(struct usbhs_priv *priv, struct usbhs_pkt *pkt) |
| 631 | { |
Kuninori Morimoto | 25234b4 | 2011-10-23 19:56:53 -0700 | [diff] [blame] | 632 | struct usbhsh_request *ureq = usbhsh_pkt_to_ureq(pkt); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 633 | struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv); |
| 634 | struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv); |
| 635 | struct urb *urb = ureq->urb; |
Kuninori Morimoto | e5679d0 | 2011-12-08 18:28:24 -0800 | [diff] [blame] | 636 | struct usbhsh_ep *uep = usbhsh_ep_to_uep(urb->ep); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 637 | struct device *dev = usbhs_priv_to_dev(priv); |
| 638 | |
| 639 | dev_dbg(dev, "%s\n", __func__); |
| 640 | |
| 641 | if (!urb) { |
| 642 | dev_warn(dev, "pkt doesn't have urb\n"); |
| 643 | return; |
| 644 | } |
| 645 | |
| 646 | urb->actual_length = pkt->actual; |
Kuninori Morimoto | 25234b4 | 2011-10-23 19:56:53 -0700 | [diff] [blame] | 647 | usbhsh_ureq_free(hpriv, ureq); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 648 | |
Kuninori Morimoto | 3edeee3 | 2011-12-08 18:28:54 -0800 | [diff] [blame] | 649 | usbhsh_endpoint_sequence_save(hpriv, urb, pkt); |
| 650 | usbhsh_pipe_detach(hpriv, uep); |
| 651 | |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 652 | usb_hcd_unlink_urb_from_ep(hcd, urb); |
| 653 | usb_hcd_giveback_urb(hcd, urb, 0); |
| 654 | } |
| 655 | |
| 656 | static int usbhsh_queue_push(struct usb_hcd *hcd, |
Kuninori Morimoto | ee8a0bf | 2011-10-31 00:46:50 -0700 | [diff] [blame] | 657 | struct urb *urb, |
| 658 | gfp_t mem_flags) |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 659 | { |
Kuninori Morimoto | ee8a0bf | 2011-10-31 00:46:50 -0700 | [diff] [blame] | 660 | struct usbhsh_hpriv *hpriv = usbhsh_hcd_to_hpriv(hcd); |
Kuninori Morimoto | 3eddc9e | 2011-10-31 00:48:46 -0700 | [diff] [blame] | 661 | struct usbhsh_ep *uep = usbhsh_ep_to_uep(urb->ep); |
| 662 | struct usbhs_pipe *pipe = usbhsh_uep_to_pipe(uep); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 663 | struct device *dev = usbhsh_hcd_to_dev(hcd); |
Kuninori Morimoto | ee8a0bf | 2011-10-31 00:46:50 -0700 | [diff] [blame] | 664 | struct usbhsh_request *ureq; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 665 | void *buf; |
Kuninori Morimoto | 3edeee3 | 2011-12-08 18:28:54 -0800 | [diff] [blame] | 666 | int len, sequence; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 667 | |
| 668 | if (usb_pipeisoc(urb->pipe)) { |
| 669 | dev_err(dev, "pipe iso is not supported now\n"); |
| 670 | return -EIO; |
| 671 | } |
| 672 | |
Kuninori Morimoto | ee8a0bf | 2011-10-31 00:46:50 -0700 | [diff] [blame] | 673 | /* this ureq will be freed on usbhsh_queue_done() */ |
| 674 | ureq = usbhsh_ureq_alloc(hpriv, urb, mem_flags); |
| 675 | if (unlikely(!ureq)) { |
| 676 | dev_err(dev, "ureq alloc fail\n"); |
| 677 | return -ENOMEM; |
| 678 | } |
Kuninori Morimoto | ee8a0bf | 2011-10-31 00:46:50 -0700 | [diff] [blame] | 679 | |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 680 | if (usb_pipein(urb->pipe)) |
| 681 | pipe->handler = &usbhs_fifo_pio_pop_handler; |
| 682 | else |
| 683 | pipe->handler = &usbhs_fifo_pio_push_handler; |
| 684 | |
| 685 | buf = (void *)(urb->transfer_buffer + urb->actual_length); |
| 686 | len = urb->transfer_buffer_length - urb->actual_length; |
| 687 | |
Kuninori Morimoto | 3edeee3 | 2011-12-08 18:28:54 -0800 | [diff] [blame] | 688 | sequence = usb_gettoggle(urb->dev, |
| 689 | usb_pipeendpoint(urb->pipe), |
| 690 | usb_pipeout(urb->pipe)); |
| 691 | |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 692 | dev_dbg(dev, "%s\n", __func__); |
Kuninori Morimoto | ee8a0bf | 2011-10-31 00:46:50 -0700 | [diff] [blame] | 693 | usbhs_pkt_push(pipe, &ureq->pkt, usbhsh_queue_done, |
Kuninori Morimoto | 3edeee3 | 2011-12-08 18:28:54 -0800 | [diff] [blame] | 694 | buf, len, (urb->transfer_flags & URB_ZERO_PACKET), |
| 695 | sequence); |
| 696 | |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 697 | usbhs_pkt_start(pipe); |
| 698 | |
| 699 | return 0; |
| 700 | } |
| 701 | |
| 702 | /* |
| 703 | * DCP setup stage |
| 704 | */ |
| 705 | static int usbhsh_is_request_address(struct urb *urb) |
| 706 | { |
Kuninori Morimoto | 25234b4 | 2011-10-23 19:56:53 -0700 | [diff] [blame] | 707 | struct usb_ctrlrequest *req; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 708 | |
Kuninori Morimoto | 25234b4 | 2011-10-23 19:56:53 -0700 | [diff] [blame] | 709 | req = (struct usb_ctrlrequest *)urb->setup_packet; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 710 | |
Kuninori Morimoto | 25234b4 | 2011-10-23 19:56:53 -0700 | [diff] [blame] | 711 | if ((DeviceOutRequest == req->bRequestType << 8) && |
| 712 | (USB_REQ_SET_ADDRESS == req->bRequest)) |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 713 | return 1; |
| 714 | else |
| 715 | return 0; |
| 716 | } |
| 717 | |
| 718 | static void usbhsh_setup_stage_packet_push(struct usbhsh_hpriv *hpriv, |
| 719 | struct urb *urb, |
| 720 | struct usbhs_pipe *pipe) |
| 721 | { |
| 722 | struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv); |
| 723 | struct usb_ctrlrequest req; |
| 724 | struct device *dev = usbhs_priv_to_dev(priv); |
| 725 | |
| 726 | /* |
| 727 | * wait setup packet ACK |
| 728 | * see |
| 729 | * usbhsh_irq_setup_ack() |
| 730 | * usbhsh_irq_setup_err() |
| 731 | */ |
Kuninori Morimoto | 7fccd48 | 2011-10-23 22:55:54 -0700 | [diff] [blame] | 732 | init_completion(&hpriv->setup_ack_done); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 733 | |
| 734 | /* copy original request */ |
| 735 | memcpy(&req, urb->setup_packet, sizeof(struct usb_ctrlrequest)); |
| 736 | |
| 737 | /* |
| 738 | * renesas_usbhs can not use original usb address. |
| 739 | * see HARDWARE LIMITATION. |
Kuninori Morimoto | c1e4877 | 2011-12-08 18:27:21 -0800 | [diff] [blame] | 740 | * modify usb address here to use attached device. |
| 741 | * see usbhsh_device_attach() |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 742 | */ |
| 743 | if (usbhsh_is_request_address(urb)) { |
Kuninori Morimoto | c1e4877 | 2011-12-08 18:27:21 -0800 | [diff] [blame] | 744 | struct usb_device *usbv = usbhsh_urb_to_usbv(urb); |
| 745 | struct usbhsh_device *udev = usbhsh_usbv_to_udev(usbv); |
| 746 | |
| 747 | /* udev is a attached device */ |
| 748 | req.wValue = usbhsh_device_number(hpriv, udev); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 749 | dev_dbg(dev, "create new address - %d\n", req.wValue); |
| 750 | } |
| 751 | |
| 752 | /* set request */ |
| 753 | usbhs_usbreq_set_val(priv, &req); |
| 754 | |
| 755 | /* |
| 756 | * wait setup packet ACK |
| 757 | */ |
Kuninori Morimoto | 7fccd48 | 2011-10-23 22:55:54 -0700 | [diff] [blame] | 758 | wait_for_completion(&hpriv->setup_ack_done); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 759 | |
| 760 | dev_dbg(dev, "%s done\n", __func__); |
| 761 | } |
| 762 | |
| 763 | /* |
| 764 | * DCP data stage |
| 765 | */ |
| 766 | static void usbhsh_data_stage_packet_done(struct usbhs_priv *priv, |
| 767 | struct usbhs_pkt *pkt) |
| 768 | { |
Kuninori Morimoto | 25234b4 | 2011-10-23 19:56:53 -0700 | [diff] [blame] | 769 | struct usbhsh_request *ureq = usbhsh_pkt_to_ureq(pkt); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 770 | struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 771 | |
| 772 | /* this ureq was connected to urb when usbhsh_urb_enqueue() */ |
| 773 | |
Kuninori Morimoto | 25234b4 | 2011-10-23 19:56:53 -0700 | [diff] [blame] | 774 | usbhsh_ureq_free(hpriv, ureq); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 775 | } |
| 776 | |
Kuninori Morimoto | ee8a0bf | 2011-10-31 00:46:50 -0700 | [diff] [blame] | 777 | static int usbhsh_data_stage_packet_push(struct usbhsh_hpriv *hpriv, |
| 778 | struct urb *urb, |
| 779 | struct usbhs_pipe *pipe, |
| 780 | gfp_t mem_flags) |
| 781 | |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 782 | { |
| 783 | struct usbhsh_request *ureq; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 784 | |
Kuninori Morimoto | ee8a0bf | 2011-10-31 00:46:50 -0700 | [diff] [blame] | 785 | /* this ureq will be freed on usbhsh_data_stage_packet_done() */ |
| 786 | ureq = usbhsh_ureq_alloc(hpriv, urb, mem_flags); |
| 787 | if (unlikely(!ureq)) |
| 788 | return -ENOMEM; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 789 | |
| 790 | if (usb_pipein(urb->pipe)) |
| 791 | pipe->handler = &usbhs_dcp_data_stage_in_handler; |
| 792 | else |
| 793 | pipe->handler = &usbhs_dcp_data_stage_out_handler; |
| 794 | |
Kuninori Morimoto | ee8a0bf | 2011-10-31 00:46:50 -0700 | [diff] [blame] | 795 | usbhs_pkt_push(pipe, &ureq->pkt, |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 796 | usbhsh_data_stage_packet_done, |
| 797 | urb->transfer_buffer, |
| 798 | urb->transfer_buffer_length, |
Kuninori Morimoto | 3edeee3 | 2011-12-08 18:28:54 -0800 | [diff] [blame] | 799 | (urb->transfer_flags & URB_ZERO_PACKET), |
| 800 | -1); |
Kuninori Morimoto | ee8a0bf | 2011-10-31 00:46:50 -0700 | [diff] [blame] | 801 | |
| 802 | return 0; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | /* |
| 806 | * DCP status stage |
| 807 | */ |
Kuninori Morimoto | ee8a0bf | 2011-10-31 00:46:50 -0700 | [diff] [blame] | 808 | static int usbhsh_status_stage_packet_push(struct usbhsh_hpriv *hpriv, |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 809 | struct urb *urb, |
Kuninori Morimoto | ee8a0bf | 2011-10-31 00:46:50 -0700 | [diff] [blame] | 810 | struct usbhs_pipe *pipe, |
| 811 | gfp_t mem_flags) |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 812 | { |
| 813 | struct usbhsh_request *ureq; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 814 | |
Kuninori Morimoto | ee8a0bf | 2011-10-31 00:46:50 -0700 | [diff] [blame] | 815 | /* This ureq will be freed on usbhsh_queue_done() */ |
| 816 | ureq = usbhsh_ureq_alloc(hpriv, urb, mem_flags); |
| 817 | if (unlikely(!ureq)) |
| 818 | return -ENOMEM; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 819 | |
| 820 | if (usb_pipein(urb->pipe)) |
| 821 | pipe->handler = &usbhs_dcp_status_stage_in_handler; |
| 822 | else |
| 823 | pipe->handler = &usbhs_dcp_status_stage_out_handler; |
| 824 | |
Kuninori Morimoto | ee8a0bf | 2011-10-31 00:46:50 -0700 | [diff] [blame] | 825 | usbhs_pkt_push(pipe, &ureq->pkt, |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 826 | usbhsh_queue_done, |
| 827 | NULL, |
| 828 | urb->transfer_buffer_length, |
Kuninori Morimoto | 3edeee3 | 2011-12-08 18:28:54 -0800 | [diff] [blame] | 829 | 0, -1); |
Kuninori Morimoto | ee8a0bf | 2011-10-31 00:46:50 -0700 | [diff] [blame] | 830 | |
| 831 | return 0; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | static int usbhsh_dcp_queue_push(struct usb_hcd *hcd, |
Kuninori Morimoto | ee8a0bf | 2011-10-31 00:46:50 -0700 | [diff] [blame] | 835 | struct urb *urb, |
| 836 | gfp_t mflags) |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 837 | { |
Kuninori Morimoto | ee8a0bf | 2011-10-31 00:46:50 -0700 | [diff] [blame] | 838 | struct usbhsh_hpriv *hpriv = usbhsh_hcd_to_hpriv(hcd); |
Kuninori Morimoto | 3eddc9e | 2011-10-31 00:48:46 -0700 | [diff] [blame] | 839 | struct usbhsh_ep *uep = usbhsh_ep_to_uep(urb->ep); |
| 840 | struct usbhs_pipe *pipe = usbhsh_uep_to_pipe(uep); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 841 | struct device *dev = usbhsh_hcd_to_dev(hcd); |
Kuninori Morimoto | ee8a0bf | 2011-10-31 00:46:50 -0700 | [diff] [blame] | 842 | int ret; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 843 | |
| 844 | dev_dbg(dev, "%s\n", __func__); |
| 845 | |
| 846 | /* |
| 847 | * setup stage |
| 848 | * |
| 849 | * usbhsh_send_setup_stage_packet() wait SACK/SIGN |
| 850 | */ |
| 851 | usbhsh_setup_stage_packet_push(hpriv, urb, pipe); |
| 852 | |
| 853 | /* |
| 854 | * data stage |
| 855 | * |
| 856 | * It is pushed only when urb has buffer. |
| 857 | */ |
Kuninori Morimoto | ee8a0bf | 2011-10-31 00:46:50 -0700 | [diff] [blame] | 858 | if (urb->transfer_buffer_length) { |
| 859 | ret = usbhsh_data_stage_packet_push(hpriv, urb, pipe, mflags); |
| 860 | if (ret < 0) { |
| 861 | dev_err(dev, "data stage failed\n"); |
| 862 | return ret; |
| 863 | } |
| 864 | } |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 865 | |
| 866 | /* |
| 867 | * status stage |
| 868 | */ |
Kuninori Morimoto | ee8a0bf | 2011-10-31 00:46:50 -0700 | [diff] [blame] | 869 | ret = usbhsh_status_stage_packet_push(hpriv, urb, pipe, mflags); |
| 870 | if (ret < 0) { |
| 871 | dev_err(dev, "status stage failed\n"); |
| 872 | return ret; |
| 873 | } |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 874 | |
| 875 | /* |
| 876 | * start pushed packets |
| 877 | */ |
| 878 | usbhs_pkt_start(pipe); |
| 879 | |
| 880 | return 0; |
| 881 | } |
| 882 | |
| 883 | /* |
| 884 | * dma map functions |
| 885 | */ |
| 886 | static int usbhsh_dma_map_ctrl(struct usbhs_pkt *pkt, int map) |
| 887 | { |
| 888 | return 0; |
| 889 | } |
| 890 | |
| 891 | /* |
| 892 | * for hc_driver |
| 893 | */ |
| 894 | static int usbhsh_host_start(struct usb_hcd *hcd) |
| 895 | { |
| 896 | return 0; |
| 897 | } |
| 898 | |
| 899 | static void usbhsh_host_stop(struct usb_hcd *hcd) |
| 900 | { |
| 901 | } |
| 902 | |
| 903 | static int usbhsh_urb_enqueue(struct usb_hcd *hcd, |
| 904 | struct urb *urb, |
| 905 | gfp_t mem_flags) |
| 906 | { |
| 907 | struct usbhsh_hpriv *hpriv = usbhsh_hcd_to_hpriv(hcd); |
| 908 | struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv); |
| 909 | struct device *dev = usbhs_priv_to_dev(priv); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 910 | struct usb_host_endpoint *ep = urb->ep; |
Kuninori Morimoto | 7aac8d1 | 2011-10-31 00:49:09 -0700 | [diff] [blame] | 911 | struct usbhsh_device *new_udev = NULL; |
Kuninori Morimoto | 73ef635 | 2011-10-24 02:24:49 -0700 | [diff] [blame] | 912 | int is_dir_in = usb_pipein(urb->pipe); |
Kuninori Morimoto | e5679d0 | 2011-12-08 18:28:24 -0800 | [diff] [blame] | 913 | int i; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 914 | int ret; |
| 915 | |
Kuninori Morimoto | 73ef635 | 2011-10-24 02:24:49 -0700 | [diff] [blame] | 916 | dev_dbg(dev, "%s (%s)\n", __func__, is_dir_in ? "in" : "out"); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 917 | |
Kuninori Morimoto | b1930da | 2011-12-08 18:30:23 -0800 | [diff] [blame^] | 918 | if (!usbhsh_is_running(hpriv)) { |
| 919 | ret = -EIO; |
| 920 | goto usbhsh_urb_enqueue_error_not_linked; |
| 921 | } |
| 922 | |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 923 | ret = usb_hcd_link_urb_to_ep(hcd, urb); |
| 924 | if (ret) |
| 925 | goto usbhsh_urb_enqueue_error_not_linked; |
| 926 | |
| 927 | /* |
Kuninori Morimoto | 7aac8d1 | 2011-10-31 00:49:09 -0700 | [diff] [blame] | 928 | * attach udev if needed |
Kuninori Morimoto | e5679d0 | 2011-12-08 18:28:24 -0800 | [diff] [blame] | 929 | * see [image of mod_host] |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 930 | */ |
Kuninori Morimoto | c1e4877 | 2011-12-08 18:27:21 -0800 | [diff] [blame] | 931 | if (!usbhsh_device_get(hpriv, urb)) { |
Kuninori Morimoto | 7aac8d1 | 2011-10-31 00:49:09 -0700 | [diff] [blame] | 932 | new_udev = usbhsh_device_attach(hpriv, urb); |
Kuninori Morimoto | 37332ee | 2011-12-08 18:25:37 -0800 | [diff] [blame] | 933 | if (!new_udev) { |
| 934 | ret = -EIO; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 935 | goto usbhsh_urb_enqueue_error_not_linked; |
Kuninori Morimoto | 37332ee | 2011-12-08 18:25:37 -0800 | [diff] [blame] | 936 | } |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | /* |
Kuninori Morimoto | 4825093 | 2011-10-31 00:48:59 -0700 | [diff] [blame] | 940 | * attach endpoint if needed |
Kuninori Morimoto | e5679d0 | 2011-12-08 18:28:24 -0800 | [diff] [blame] | 941 | * see [image of mod_host] |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 942 | */ |
Kuninori Morimoto | 4825093 | 2011-10-31 00:48:59 -0700 | [diff] [blame] | 943 | if (!usbhsh_ep_to_uep(ep)) { |
| 944 | ret = usbhsh_endpoint_attach(hpriv, urb, mem_flags); |
| 945 | if (ret < 0) |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 946 | goto usbhsh_urb_enqueue_error_free_device; |
| 947 | } |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 948 | |
| 949 | /* |
Kuninori Morimoto | e5679d0 | 2011-12-08 18:28:24 -0800 | [diff] [blame] | 950 | * attach pipe to endpoint |
| 951 | * see [image of mod_host] |
| 952 | */ |
| 953 | for (i = 0; i < 1024; i++) { |
| 954 | ret = usbhsh_pipe_attach(hpriv, urb); |
| 955 | if (ret < 0) |
| 956 | msleep(100); |
| 957 | else |
| 958 | break; |
| 959 | } |
| 960 | if (ret < 0) |
| 961 | goto usbhsh_urb_enqueue_error_free_endpoint; |
| 962 | |
| 963 | /* |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 964 | * push packet |
| 965 | */ |
| 966 | if (usb_pipecontrol(urb->pipe)) |
Kuninori Morimoto | 3eddc9e | 2011-10-31 00:48:46 -0700 | [diff] [blame] | 967 | ret = usbhsh_dcp_queue_push(hcd, urb, mem_flags); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 968 | else |
Kuninori Morimoto | 3eddc9e | 2011-10-31 00:48:46 -0700 | [diff] [blame] | 969 | ret = usbhsh_queue_push(hcd, urb, mem_flags); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 970 | |
Kuninori Morimoto | ee8a0bf | 2011-10-31 00:46:50 -0700 | [diff] [blame] | 971 | return ret; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 972 | |
Kuninori Morimoto | e5679d0 | 2011-12-08 18:28:24 -0800 | [diff] [blame] | 973 | usbhsh_urb_enqueue_error_free_endpoint: |
| 974 | usbhsh_endpoint_detach(hpriv, ep); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 975 | usbhsh_urb_enqueue_error_free_device: |
| 976 | if (new_udev) |
Kuninori Morimoto | 7aac8d1 | 2011-10-31 00:49:09 -0700 | [diff] [blame] | 977 | usbhsh_device_detach(hpriv, new_udev); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 978 | usbhsh_urb_enqueue_error_not_linked: |
| 979 | |
| 980 | dev_dbg(dev, "%s error\n", __func__); |
| 981 | |
| 982 | return ret; |
| 983 | } |
| 984 | |
| 985 | static int usbhsh_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) |
| 986 | { |
| 987 | struct usbhsh_hpriv *hpriv = usbhsh_hcd_to_hpriv(hcd); |
| 988 | struct usbhsh_request *ureq = usbhsh_urb_to_ureq(urb); |
| 989 | |
Kuninori Morimoto | 5479654 | 2011-12-08 18:26:07 -0800 | [diff] [blame] | 990 | if (ureq) { |
| 991 | struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv); |
| 992 | struct usbhs_pkt *pkt = &ureq->pkt; |
| 993 | |
| 994 | usbhs_pkt_pop(pkt->pipe, pkt); |
| 995 | usbhsh_queue_done(priv, pkt); |
| 996 | } |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 997 | |
| 998 | return 0; |
| 999 | } |
| 1000 | |
| 1001 | static void usbhsh_endpoint_disable(struct usb_hcd *hcd, |
| 1002 | struct usb_host_endpoint *ep) |
| 1003 | { |
| 1004 | struct usbhsh_ep *uep = usbhsh_ep_to_uep(ep); |
| 1005 | struct usbhsh_device *udev; |
| 1006 | struct usbhsh_hpriv *hpriv; |
| 1007 | |
| 1008 | /* |
| 1009 | * this function might be called manytimes by same hcd/ep |
Kuninori Morimoto | fca8ab7 | 2011-10-31 00:47:24 -0700 | [diff] [blame] | 1010 | * in-endpoint == out-endpoint if ep == dcp. |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1011 | */ |
| 1012 | if (!uep) |
| 1013 | return; |
| 1014 | |
| 1015 | udev = usbhsh_uep_to_udev(uep); |
| 1016 | hpriv = usbhsh_hcd_to_hpriv(hcd); |
| 1017 | |
Kuninori Morimoto | 4825093 | 2011-10-31 00:48:59 -0700 | [diff] [blame] | 1018 | usbhsh_endpoint_detach(hpriv, ep); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1019 | |
| 1020 | /* |
| 1021 | * if there is no endpoint, |
| 1022 | * free device |
| 1023 | */ |
| 1024 | if (!usbhsh_device_has_endpoint(udev)) |
Kuninori Morimoto | 7aac8d1 | 2011-10-31 00:49:09 -0700 | [diff] [blame] | 1025 | usbhsh_device_detach(hpriv, udev); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | static int usbhsh_hub_status_data(struct usb_hcd *hcd, char *buf) |
| 1029 | { |
| 1030 | struct usbhsh_hpriv *hpriv = usbhsh_hcd_to_hpriv(hcd); |
| 1031 | struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv); |
| 1032 | struct device *dev = usbhs_priv_to_dev(priv); |
| 1033 | int roothub_id = 1; /* only 1 root hub */ |
| 1034 | |
| 1035 | /* |
| 1036 | * does port stat was changed ? |
| 1037 | * check USB_PORT_STAT_C_xxx << 16 |
| 1038 | */ |
| 1039 | if (usbhsh_port_stat_get(hpriv) & 0xFFFF0000) |
| 1040 | *buf = (1 << roothub_id); |
| 1041 | else |
| 1042 | *buf = 0; |
| 1043 | |
| 1044 | dev_dbg(dev, "%s (%02x)\n", __func__, *buf); |
| 1045 | |
| 1046 | return !!(*buf); |
| 1047 | } |
| 1048 | |
| 1049 | static int __usbhsh_hub_hub_feature(struct usbhsh_hpriv *hpriv, |
| 1050 | u16 typeReq, u16 wValue, |
| 1051 | u16 wIndex, char *buf, u16 wLength) |
| 1052 | { |
| 1053 | struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv); |
| 1054 | struct device *dev = usbhs_priv_to_dev(priv); |
| 1055 | |
| 1056 | switch (wValue) { |
| 1057 | case C_HUB_OVER_CURRENT: |
| 1058 | case C_HUB_LOCAL_POWER: |
| 1059 | dev_dbg(dev, "%s :: C_HUB_xx\n", __func__); |
| 1060 | return 0; |
| 1061 | } |
| 1062 | |
| 1063 | return -EPIPE; |
| 1064 | } |
| 1065 | |
| 1066 | static int __usbhsh_hub_port_feature(struct usbhsh_hpriv *hpriv, |
| 1067 | u16 typeReq, u16 wValue, |
| 1068 | u16 wIndex, char *buf, u16 wLength) |
| 1069 | { |
| 1070 | struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv); |
| 1071 | struct device *dev = usbhs_priv_to_dev(priv); |
| 1072 | int enable = (typeReq == SetPortFeature); |
| 1073 | int speed, i, timeout = 128; |
| 1074 | int roothub_id = 1; /* only 1 root hub */ |
| 1075 | |
| 1076 | /* common error */ |
| 1077 | if (wIndex > roothub_id || wLength != 0) |
| 1078 | return -EPIPE; |
| 1079 | |
| 1080 | /* check wValue */ |
| 1081 | switch (wValue) { |
| 1082 | case USB_PORT_FEAT_POWER: |
| 1083 | usbhs_vbus_ctrl(priv, enable); |
| 1084 | dev_dbg(dev, "%s :: USB_PORT_FEAT_POWER\n", __func__); |
| 1085 | break; |
| 1086 | |
| 1087 | case USB_PORT_FEAT_ENABLE: |
| 1088 | case USB_PORT_FEAT_SUSPEND: |
| 1089 | case USB_PORT_FEAT_C_ENABLE: |
| 1090 | case USB_PORT_FEAT_C_SUSPEND: |
| 1091 | case USB_PORT_FEAT_C_CONNECTION: |
| 1092 | case USB_PORT_FEAT_C_OVER_CURRENT: |
| 1093 | case USB_PORT_FEAT_C_RESET: |
| 1094 | dev_dbg(dev, "%s :: USB_PORT_FEAT_xxx\n", __func__); |
| 1095 | break; |
| 1096 | |
| 1097 | case USB_PORT_FEAT_RESET: |
| 1098 | if (!enable) |
| 1099 | break; |
| 1100 | |
| 1101 | usbhsh_port_stat_clear(hpriv, |
| 1102 | USB_PORT_STAT_HIGH_SPEED | |
| 1103 | USB_PORT_STAT_LOW_SPEED); |
| 1104 | |
| 1105 | usbhs_bus_send_reset(priv); |
| 1106 | msleep(20); |
| 1107 | usbhs_bus_send_sof_enable(priv); |
| 1108 | |
| 1109 | for (i = 0; i < timeout ; i++) { |
| 1110 | switch (usbhs_bus_get_speed(priv)) { |
| 1111 | case USB_SPEED_LOW: |
| 1112 | speed = USB_PORT_STAT_LOW_SPEED; |
| 1113 | goto got_usb_bus_speed; |
| 1114 | case USB_SPEED_HIGH: |
| 1115 | speed = USB_PORT_STAT_HIGH_SPEED; |
| 1116 | goto got_usb_bus_speed; |
| 1117 | case USB_SPEED_FULL: |
| 1118 | speed = 0; |
| 1119 | goto got_usb_bus_speed; |
| 1120 | } |
| 1121 | |
| 1122 | msleep(20); |
| 1123 | } |
| 1124 | return -EPIPE; |
| 1125 | |
| 1126 | got_usb_bus_speed: |
| 1127 | usbhsh_port_stat_set(hpriv, speed); |
| 1128 | usbhsh_port_stat_set(hpriv, USB_PORT_STAT_ENABLE); |
| 1129 | |
| 1130 | dev_dbg(dev, "%s :: USB_PORT_FEAT_RESET (speed = %d)\n", |
| 1131 | __func__, speed); |
| 1132 | |
| 1133 | /* status change is not needed */ |
| 1134 | return 0; |
| 1135 | |
| 1136 | default: |
| 1137 | return -EPIPE; |
| 1138 | } |
| 1139 | |
| 1140 | /* set/clear status */ |
| 1141 | if (enable) |
| 1142 | usbhsh_port_stat_set(hpriv, (1 << wValue)); |
| 1143 | else |
| 1144 | usbhsh_port_stat_clear(hpriv, (1 << wValue)); |
| 1145 | |
| 1146 | return 0; |
| 1147 | } |
| 1148 | |
| 1149 | static int __usbhsh_hub_get_status(struct usbhsh_hpriv *hpriv, |
| 1150 | u16 typeReq, u16 wValue, |
| 1151 | u16 wIndex, char *buf, u16 wLength) |
| 1152 | { |
| 1153 | struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv); |
| 1154 | struct usb_hub_descriptor *desc = (struct usb_hub_descriptor *)buf; |
| 1155 | struct device *dev = usbhs_priv_to_dev(priv); |
| 1156 | int roothub_id = 1; /* only 1 root hub */ |
| 1157 | |
| 1158 | switch (typeReq) { |
| 1159 | case GetHubStatus: |
| 1160 | dev_dbg(dev, "%s :: GetHubStatus\n", __func__); |
| 1161 | |
| 1162 | *buf = 0x00; |
| 1163 | break; |
| 1164 | |
| 1165 | case GetPortStatus: |
| 1166 | if (wIndex != roothub_id) |
| 1167 | return -EPIPE; |
| 1168 | |
| 1169 | dev_dbg(dev, "%s :: GetPortStatus\n", __func__); |
| 1170 | *(__le32 *)buf = cpu_to_le32(usbhsh_port_stat_get(hpriv)); |
| 1171 | break; |
| 1172 | |
| 1173 | case GetHubDescriptor: |
| 1174 | desc->bDescriptorType = 0x29; |
| 1175 | desc->bHubContrCurrent = 0; |
| 1176 | desc->bNbrPorts = roothub_id; |
| 1177 | desc->bDescLength = 9; |
| 1178 | desc->bPwrOn2PwrGood = 0; |
| 1179 | desc->wHubCharacteristics = cpu_to_le16(0x0011); |
| 1180 | desc->u.hs.DeviceRemovable[0] = (roothub_id << 1); |
| 1181 | desc->u.hs.DeviceRemovable[1] = ~0; |
| 1182 | dev_dbg(dev, "%s :: GetHubDescriptor\n", __func__); |
| 1183 | break; |
| 1184 | } |
| 1185 | |
| 1186 | return 0; |
| 1187 | } |
| 1188 | |
| 1189 | static int usbhsh_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, |
| 1190 | u16 wIndex, char *buf, u16 wLength) |
| 1191 | { |
| 1192 | struct usbhsh_hpriv *hpriv = usbhsh_hcd_to_hpriv(hcd); |
| 1193 | struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv); |
| 1194 | struct device *dev = usbhs_priv_to_dev(priv); |
| 1195 | int ret = -EPIPE; |
| 1196 | |
| 1197 | switch (typeReq) { |
| 1198 | |
| 1199 | /* Hub Feature */ |
| 1200 | case ClearHubFeature: |
| 1201 | case SetHubFeature: |
| 1202 | ret = __usbhsh_hub_hub_feature(hpriv, typeReq, |
| 1203 | wValue, wIndex, buf, wLength); |
| 1204 | break; |
| 1205 | |
| 1206 | /* Port Feature */ |
| 1207 | case SetPortFeature: |
| 1208 | case ClearPortFeature: |
| 1209 | ret = __usbhsh_hub_port_feature(hpriv, typeReq, |
| 1210 | wValue, wIndex, buf, wLength); |
| 1211 | break; |
| 1212 | |
| 1213 | /* Get status */ |
| 1214 | case GetHubStatus: |
| 1215 | case GetPortStatus: |
| 1216 | case GetHubDescriptor: |
| 1217 | ret = __usbhsh_hub_get_status(hpriv, typeReq, |
| 1218 | wValue, wIndex, buf, wLength); |
| 1219 | break; |
| 1220 | } |
| 1221 | |
| 1222 | dev_dbg(dev, "typeReq = %x, ret = %d, port_stat = %x\n", |
| 1223 | typeReq, ret, usbhsh_port_stat_get(hpriv)); |
| 1224 | |
| 1225 | return ret; |
| 1226 | } |
| 1227 | |
| 1228 | static struct hc_driver usbhsh_driver = { |
| 1229 | .description = usbhsh_hcd_name, |
| 1230 | .hcd_priv_size = sizeof(struct usbhsh_hpriv), |
| 1231 | |
| 1232 | /* |
| 1233 | * generic hardware linkage |
| 1234 | */ |
| 1235 | .flags = HCD_USB2, |
| 1236 | |
| 1237 | .start = usbhsh_host_start, |
| 1238 | .stop = usbhsh_host_stop, |
| 1239 | |
| 1240 | /* |
| 1241 | * managing i/o requests and associated device resources |
| 1242 | */ |
| 1243 | .urb_enqueue = usbhsh_urb_enqueue, |
| 1244 | .urb_dequeue = usbhsh_urb_dequeue, |
| 1245 | .endpoint_disable = usbhsh_endpoint_disable, |
| 1246 | |
| 1247 | /* |
| 1248 | * root hub |
| 1249 | */ |
| 1250 | .hub_status_data = usbhsh_hub_status_data, |
| 1251 | .hub_control = usbhsh_hub_control, |
| 1252 | }; |
| 1253 | |
| 1254 | /* |
| 1255 | * interrupt functions |
| 1256 | */ |
| 1257 | static int usbhsh_irq_attch(struct usbhs_priv *priv, |
| 1258 | struct usbhs_irq_state *irq_state) |
| 1259 | { |
| 1260 | struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv); |
| 1261 | struct device *dev = usbhs_priv_to_dev(priv); |
| 1262 | |
| 1263 | dev_dbg(dev, "device attached\n"); |
| 1264 | |
| 1265 | usbhsh_port_stat_set(hpriv, USB_PORT_STAT_CONNECTION); |
| 1266 | usbhsh_port_stat_set(hpriv, USB_PORT_STAT_C_CONNECTION << 16); |
| 1267 | |
Kuninori Morimoto | 31e00fd | 2011-12-08 18:29:22 -0800 | [diff] [blame] | 1268 | /* |
| 1269 | * attch interrupt might happen infinitely on some device |
| 1270 | * (on self power USB hub ?) |
| 1271 | * disable it here. |
Kuninori Morimoto | b1930da | 2011-12-08 18:30:23 -0800 | [diff] [blame^] | 1272 | * |
| 1273 | * usbhsh_is_running() becomes effective |
| 1274 | * according to this process. |
| 1275 | * see |
| 1276 | * usbhsh_is_running() |
| 1277 | * usbhsh_urb_enqueue() |
Kuninori Morimoto | 31e00fd | 2011-12-08 18:29:22 -0800 | [diff] [blame] | 1278 | */ |
| 1279 | hpriv->mod.irq_attch = NULL; |
| 1280 | usbhs_irq_callback_update(priv, &hpriv->mod); |
| 1281 | |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1282 | return 0; |
| 1283 | } |
| 1284 | |
| 1285 | static int usbhsh_irq_dtch(struct usbhs_priv *priv, |
| 1286 | struct usbhs_irq_state *irq_state) |
| 1287 | { |
| 1288 | struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv); |
| 1289 | struct device *dev = usbhs_priv_to_dev(priv); |
| 1290 | |
| 1291 | dev_dbg(dev, "device detached\n"); |
| 1292 | |
| 1293 | usbhsh_port_stat_clear(hpriv, USB_PORT_STAT_CONNECTION); |
| 1294 | usbhsh_port_stat_set(hpriv, USB_PORT_STAT_C_CONNECTION << 16); |
| 1295 | |
Kuninori Morimoto | 31e00fd | 2011-12-08 18:29:22 -0800 | [diff] [blame] | 1296 | /* |
| 1297 | * enable attch interrupt again |
Kuninori Morimoto | b1930da | 2011-12-08 18:30:23 -0800 | [diff] [blame^] | 1298 | * |
| 1299 | * usbhsh_is_running() becomes invalid |
| 1300 | * according to this process. |
| 1301 | * see |
| 1302 | * usbhsh_is_running() |
| 1303 | * usbhsh_urb_enqueue() |
Kuninori Morimoto | 31e00fd | 2011-12-08 18:29:22 -0800 | [diff] [blame] | 1304 | */ |
| 1305 | hpriv->mod.irq_attch = usbhsh_irq_attch; |
| 1306 | usbhs_irq_callback_update(priv, &hpriv->mod); |
| 1307 | |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1308 | return 0; |
| 1309 | } |
| 1310 | |
| 1311 | static int usbhsh_irq_setup_ack(struct usbhs_priv *priv, |
| 1312 | struct usbhs_irq_state *irq_state) |
| 1313 | { |
| 1314 | struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv); |
| 1315 | struct device *dev = usbhs_priv_to_dev(priv); |
| 1316 | |
| 1317 | dev_dbg(dev, "setup packet OK\n"); |
| 1318 | |
Kuninori Morimoto | 7fccd48 | 2011-10-23 22:55:54 -0700 | [diff] [blame] | 1319 | complete(&hpriv->setup_ack_done); /* see usbhsh_urb_enqueue() */ |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1320 | |
| 1321 | return 0; |
| 1322 | } |
| 1323 | |
| 1324 | static int usbhsh_irq_setup_err(struct usbhs_priv *priv, |
| 1325 | struct usbhs_irq_state *irq_state) |
| 1326 | { |
| 1327 | struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv); |
| 1328 | struct device *dev = usbhs_priv_to_dev(priv); |
| 1329 | |
| 1330 | dev_dbg(dev, "setup packet Err\n"); |
| 1331 | |
Kuninori Morimoto | 7fccd48 | 2011-10-23 22:55:54 -0700 | [diff] [blame] | 1332 | complete(&hpriv->setup_ack_done); /* see usbhsh_urb_enqueue() */ |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1333 | |
| 1334 | return 0; |
| 1335 | } |
| 1336 | |
| 1337 | /* |
| 1338 | * module start/stop |
| 1339 | */ |
| 1340 | static void usbhsh_pipe_init_for_host(struct usbhs_priv *priv) |
| 1341 | { |
| 1342 | struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1343 | struct usbhs_pipe *pipe; |
| 1344 | u32 *pipe_type = usbhs_get_dparam(priv, pipe_type); |
| 1345 | int pipe_size = usbhs_get_dparam(priv, pipe_size); |
| 1346 | int old_type, dir_in, i; |
| 1347 | |
| 1348 | /* init all pipe */ |
| 1349 | old_type = USB_ENDPOINT_XFER_CONTROL; |
| 1350 | for (i = 0; i < pipe_size; i++) { |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1351 | |
| 1352 | /* |
| 1353 | * data "output" will be finished as soon as possible, |
| 1354 | * but there is no guaranty at data "input" case. |
| 1355 | * |
| 1356 | * "input" needs "standby" pipe. |
| 1357 | * So, "input" direction pipe > "output" direction pipe |
| 1358 | * is good idea. |
| 1359 | * |
| 1360 | * 1st USB_ENDPOINT_XFER_xxx will be output direction, |
| 1361 | * and the other will be input direction here. |
| 1362 | * |
| 1363 | * ex) |
| 1364 | * ... |
| 1365 | * USB_ENDPOINT_XFER_ISOC -> dir out |
| 1366 | * USB_ENDPOINT_XFER_ISOC -> dir in |
| 1367 | * USB_ENDPOINT_XFER_BULK -> dir out |
| 1368 | * USB_ENDPOINT_XFER_BULK -> dir in |
| 1369 | * USB_ENDPOINT_XFER_BULK -> dir in |
| 1370 | * ... |
| 1371 | */ |
| 1372 | dir_in = (pipe_type[i] == old_type); |
| 1373 | old_type = pipe_type[i]; |
| 1374 | |
| 1375 | if (USB_ENDPOINT_XFER_CONTROL == pipe_type[i]) { |
| 1376 | pipe = usbhs_dcp_malloc(priv); |
| 1377 | usbhsh_hpriv_to_dcp(hpriv) = pipe; |
| 1378 | } else { |
| 1379 | pipe = usbhs_pipe_malloc(priv, |
| 1380 | pipe_type[i], |
| 1381 | dir_in); |
| 1382 | } |
| 1383 | |
Kuninori Morimoto | e5679d0 | 2011-12-08 18:28:24 -0800 | [diff] [blame] | 1384 | pipe->mod_private = NULL; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1385 | } |
| 1386 | } |
| 1387 | |
| 1388 | static int usbhsh_start(struct usbhs_priv *priv) |
| 1389 | { |
| 1390 | struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv); |
| 1391 | struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv); |
| 1392 | struct usbhs_mod *mod = usbhs_mod_get_current(priv); |
| 1393 | struct device *dev = usbhs_priv_to_dev(priv); |
| 1394 | int ret; |
| 1395 | |
| 1396 | /* add hcd */ |
| 1397 | ret = usb_add_hcd(hcd, 0, 0); |
| 1398 | if (ret < 0) |
| 1399 | return 0; |
| 1400 | |
| 1401 | /* |
| 1402 | * pipe initialize and enable DCP |
| 1403 | */ |
| 1404 | usbhs_pipe_init(priv, |
| 1405 | usbhsh_dma_map_ctrl); |
| 1406 | usbhs_fifo_init(priv); |
| 1407 | usbhsh_pipe_init_for_host(priv); |
| 1408 | |
| 1409 | /* |
| 1410 | * system config enble |
| 1411 | * - HI speed |
| 1412 | * - host |
| 1413 | * - usb module |
| 1414 | */ |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1415 | usbhs_sys_host_ctrl(priv, 1); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1416 | |
| 1417 | /* |
| 1418 | * enable irq callback |
| 1419 | */ |
| 1420 | mod->irq_attch = usbhsh_irq_attch; |
| 1421 | mod->irq_dtch = usbhsh_irq_dtch; |
| 1422 | mod->irq_sack = usbhsh_irq_setup_ack; |
| 1423 | mod->irq_sign = usbhsh_irq_setup_err; |
| 1424 | usbhs_irq_callback_update(priv, mod); |
| 1425 | |
| 1426 | dev_dbg(dev, "start host\n"); |
| 1427 | |
| 1428 | return ret; |
| 1429 | } |
| 1430 | |
| 1431 | static int usbhsh_stop(struct usbhs_priv *priv) |
| 1432 | { |
| 1433 | struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv); |
| 1434 | struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv); |
Kuninori Morimoto | 146ee50 | 2011-10-24 02:25:07 -0700 | [diff] [blame] | 1435 | struct usbhs_mod *mod = usbhs_mod_get_current(priv); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1436 | struct device *dev = usbhs_priv_to_dev(priv); |
| 1437 | |
Kuninori Morimoto | 146ee50 | 2011-10-24 02:25:07 -0700 | [diff] [blame] | 1438 | /* |
| 1439 | * disable irq callback |
| 1440 | */ |
| 1441 | mod->irq_attch = NULL; |
| 1442 | mod->irq_dtch = NULL; |
| 1443 | mod->irq_sack = NULL; |
| 1444 | mod->irq_sign = NULL; |
| 1445 | usbhs_irq_callback_update(priv, mod); |
| 1446 | |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1447 | usb_remove_hcd(hcd); |
| 1448 | |
| 1449 | /* disable sys */ |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1450 | usbhs_sys_host_ctrl(priv, 0); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1451 | |
| 1452 | dev_dbg(dev, "quit host\n"); |
| 1453 | |
| 1454 | return 0; |
| 1455 | } |
| 1456 | |
Kuninori Morimoto | b7a8d17 | 2011-10-26 19:33:49 -0700 | [diff] [blame] | 1457 | int usbhs_mod_host_probe(struct usbhs_priv *priv) |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1458 | { |
| 1459 | struct usbhsh_hpriv *hpriv; |
| 1460 | struct usb_hcd *hcd; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1461 | struct usbhsh_device *udev; |
| 1462 | struct device *dev = usbhs_priv_to_dev(priv); |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1463 | int i; |
| 1464 | |
| 1465 | /* initialize hcd */ |
| 1466 | hcd = usb_create_hcd(&usbhsh_driver, dev, usbhsh_hcd_name); |
| 1467 | if (!hcd) { |
| 1468 | dev_err(dev, "Failed to create hcd\n"); |
| 1469 | return -ENOMEM; |
| 1470 | } |
| 1471 | |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1472 | /* |
| 1473 | * CAUTION |
| 1474 | * |
| 1475 | * There is no guarantee that it is possible to access usb module here. |
| 1476 | * Don't accesses to it. |
| 1477 | * The accesse will be enable after "usbhsh_start" |
| 1478 | */ |
| 1479 | |
| 1480 | hpriv = usbhsh_hcd_to_hpriv(hcd); |
| 1481 | |
| 1482 | /* |
| 1483 | * register itself |
| 1484 | */ |
| 1485 | usbhs_mod_register(priv, &hpriv->mod, USBHS_HOST); |
| 1486 | |
| 1487 | /* init hpriv */ |
| 1488 | hpriv->mod.name = "host"; |
| 1489 | hpriv->mod.start = usbhsh_start; |
| 1490 | hpriv->mod.stop = usbhsh_stop; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1491 | usbhsh_port_stat_init(hpriv); |
| 1492 | |
| 1493 | /* init all device */ |
| 1494 | usbhsh_for_each_udev_with_dev0(udev, hpriv, i) { |
| 1495 | udev->usbv = NULL; |
| 1496 | INIT_LIST_HEAD(&udev->ep_list_head); |
| 1497 | } |
| 1498 | |
| 1499 | dev_info(dev, "host probed\n"); |
| 1500 | |
| 1501 | return 0; |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1502 | } |
| 1503 | |
Kuninori Morimoto | b7a8d17 | 2011-10-26 19:33:49 -0700 | [diff] [blame] | 1504 | int usbhs_mod_host_remove(struct usbhs_priv *priv) |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1505 | { |
| 1506 | struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv); |
| 1507 | struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv); |
| 1508 | |
Kuninori Morimoto | 034d7c1 | 2011-10-10 22:07:40 -0700 | [diff] [blame] | 1509 | usb_put_hcd(hcd); |
| 1510 | |
| 1511 | return 0; |
| 1512 | } |