usb: gadget: renesas_usbhs: cleanup complicated ureq alloc/free
[linux-2.6-block.git] / drivers / usb / renesas_usbhs / mod_host.c
CommitLineData
034d7c13
KM
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
48 * +--------+ | | target device was changed
49 * +- [uep 1 (bulk)] --|---+ +--------------+
50 * | +--------------> | pipe0 (dcp) |
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)] ------+ | | .... |
62 * | |
63 * +- [uep 2 (bulk)]-----------+
64 */
65
66
67/*
68 * struct
69 */
70struct usbhsh_pipe_info {
71 unsigned int usr_cnt; /* see usbhsh_endpoint_alloc() */
72};
73
74struct usbhsh_request {
75 struct urb *urb;
76 struct usbhs_pkt pkt;
77 struct list_head ureq_link; /* see hpriv :: ureq_link_xxx */
78};
79
80struct usbhsh_device {
81 struct usb_device *usbv;
82 struct list_head ep_list_head; /* list of usbhsh_ep */
83};
84
85struct usbhsh_ep {
86 struct usbhs_pipe *pipe;
87 struct usbhsh_device *udev; /* attached udev */
88 struct list_head ep_list; /* list to usbhsh_device */
89
90 int maxp;
91};
92
93#define USBHSH_DEVICE_MAX 10 /* see DEVADDn / DCPMAXP / PIPEMAXP */
94#define USBHSH_PORT_MAX 7 /* see DEVADDn :: HUBPORT */
95struct usbhsh_hpriv {
96 struct usbhs_mod mod;
97 struct usbhs_pipe *dcp;
98
99 struct usbhsh_device udev[USBHSH_DEVICE_MAX];
100
101 struct usbhsh_pipe_info *pipe_info;
102 int pipe_size;
103
104 u32 port_stat; /* USB_PORT_STAT_xxx */
105
7fccd480 106 struct completion setup_ack_done;
034d7c13
KM
107
108 /* see usbhsh_req_alloc/free */
109 struct list_head ureq_link_active;
110 struct list_head ureq_link_free;
111};
112
113
114static const char usbhsh_hcd_name[] = "renesas_usbhs host";
115
116/*
117 * macro
118 */
119#define usbhsh_priv_to_hpriv(priv) \
120 container_of(usbhs_mod_get(priv, USBHS_HOST), struct usbhsh_hpriv, mod)
121
122#define __usbhsh_for_each_hpipe(start, pos, h, i) \
123 for (i = start, pos = (h)->hpipe + i; \
124 i < (h)->hpipe_size; \
125 i++, pos = (h)->hpipe + i)
126
127#define usbhsh_for_each_hpipe(pos, hpriv, i) \
128 __usbhsh_for_each_hpipe(1, pos, hpriv, i)
129
130#define usbhsh_for_each_hpipe_with_dcp(pos, hpriv, i) \
131 __usbhsh_for_each_hpipe(0, pos, hpriv, i)
132
133#define __usbhsh_for_each_udev(start, pos, h, i) \
134 for (i = start, pos = (h)->udev + i; \
135 i < USBHSH_DEVICE_MAX; \
136 i++, pos = (h)->udev + i)
137
138#define usbhsh_for_each_udev(pos, hpriv, i) \
139 __usbhsh_for_each_udev(1, pos, hpriv, i)
140
141#define usbhsh_for_each_udev_with_dev0(pos, hpriv, i) \
142 __usbhsh_for_each_udev(0, pos, hpriv, i)
143
144#define usbhsh_hcd_to_hpriv(h) (struct usbhsh_hpriv *)((h)->hcd_priv)
145#define usbhsh_hcd_to_dev(h) ((h)->self.controller)
146
147#define usbhsh_hpriv_to_priv(h) ((h)->mod.priv)
148#define usbhsh_hpriv_to_dcp(h) ((h)->dcp)
149#define usbhsh_hpriv_to_hcd(h) \
150 container_of((void *)h, struct usb_hcd, hcd_priv)
151
152#define usbhsh_ep_to_uep(u) ((u)->hcpriv)
153#define usbhsh_uep_to_pipe(u) ((u)->pipe)
154#define usbhsh_uep_to_udev(u) ((u)->udev)
155#define usbhsh_urb_to_ureq(u) ((u)->hcpriv)
156#define usbhsh_urb_to_usbv(u) ((u)->dev)
157
158#define usbhsh_usbv_to_udev(d) dev_get_drvdata(&(d)->dev)
159
160#define usbhsh_udev_to_usbv(h) ((h)->usbv)
161
162#define usbhsh_pipe_info(p) ((p)->mod_private)
163
164#define usbhsh_device_number(h, d) ((int)((d) - (h)->udev))
165#define usbhsh_device_nth(h, d) ((h)->udev + d)
166#define usbhsh_device0(h) usbhsh_device_nth(h, 0)
167
168#define usbhsh_port_stat_init(h) ((h)->port_stat = 0)
169#define usbhsh_port_stat_set(h, s) ((h)->port_stat |= (s))
170#define usbhsh_port_stat_clear(h, s) ((h)->port_stat &= ~(s))
171#define usbhsh_port_stat_get(h) ((h)->port_stat)
172
25234b46 173#define usbhsh_pkt_to_ureq(p) \
034d7c13
KM
174 container_of((void *)p, struct usbhsh_request, pkt)
175
176/*
177 * req alloc/free
178 */
25234b46 179static void usbhsh_ureq_list_init(struct usbhsh_hpriv *hpriv)
034d7c13
KM
180{
181 INIT_LIST_HEAD(&hpriv->ureq_link_active);
182 INIT_LIST_HEAD(&hpriv->ureq_link_free);
183}
184
25234b46 185static void usbhsh_ureq_list_quit(struct usbhsh_hpriv *hpriv)
034d7c13
KM
186{
187 struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv);
188 struct device *dev = usbhsh_hcd_to_dev(hcd);
189 struct usbhsh_request *ureq, *next;
190
191 /* kfree all active ureq */
192 list_for_each_entry_safe(ureq, next,
193 &hpriv->ureq_link_active,
194 ureq_link) {
195 dev_err(dev, "active ureq (%p) is force freed\n", ureq);
196 kfree(ureq);
197 }
198
199 /* kfree all free ureq */
200 list_for_each_entry_safe(ureq, next, &hpriv->ureq_link_free, ureq_link)
201 kfree(ureq);
202}
203
25234b46 204static struct usbhsh_request *usbhsh_ureq_alloc(struct usbhsh_hpriv *hpriv,
034d7c13
KM
205 struct urb *urb,
206 gfp_t mem_flags)
207{
208 struct usbhsh_request *ureq;
209 struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
210 struct device *dev = usbhs_priv_to_dev(priv);
211
212 if (list_empty(&hpriv->ureq_link_free)) {
213 /*
214 * create new one if there is no free ureq
215 */
216 ureq = kzalloc(sizeof(struct usbhsh_request), mem_flags);
217 if (ureq)
218 INIT_LIST_HEAD(&ureq->ureq_link);
219 } else {
220 /*
221 * reuse "free" ureq if exist
222 */
223 ureq = list_entry(hpriv->ureq_link_free.next,
224 struct usbhsh_request,
225 ureq_link);
226 if (ureq)
227 list_del_init(&ureq->ureq_link);
228 }
229
230 if (!ureq) {
231 dev_err(dev, "ureq alloc fail\n");
232 return NULL;
233 }
234
235 usbhs_pkt_init(&ureq->pkt);
236
237 /*
238 * push it to "active" list
239 */
240 list_add_tail(&ureq->ureq_link, &hpriv->ureq_link_active);
241 ureq->urb = urb;
242
243 return ureq;
244}
245
25234b46 246static void usbhsh_ureq_free(struct usbhsh_hpriv *hpriv,
034d7c13
KM
247 struct usbhsh_request *ureq)
248{
249 struct usbhs_pkt *pkt = &ureq->pkt;
250
251 usbhs_pkt_init(pkt);
252
253 /*
254 * removed from "active" list,
255 * and push it to "free" list
256 */
257 ureq->urb = NULL;
258 list_del_init(&ureq->ureq_link);
259 list_add_tail(&ureq->ureq_link, &hpriv->ureq_link_free);
260}
261
262/*
263 * device control
264 */
265
266static int usbhsh_device_has_endpoint(struct usbhsh_device *udev)
267{
268 return !list_empty(&udev->ep_list_head);
269}
270
271static struct usbhsh_device *usbhsh_device_alloc(struct usbhsh_hpriv *hpriv,
272 struct urb *urb)
273{
274 struct usbhsh_device *udev = NULL;
275 struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv);
276 struct device *dev = usbhsh_hcd_to_dev(hcd);
277 struct usb_device *usbv = usbhsh_urb_to_usbv(urb);
278 struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
279 int i;
280
281 /*
282 * device 0
283 */
284 if (0 == usb_pipedevice(urb->pipe)) {
285 udev = usbhsh_device0(hpriv);
286 goto usbhsh_device_find;
287 }
288
289 /*
290 * find unused device
291 */
292 usbhsh_for_each_udev(udev, hpriv, i) {
293 if (usbhsh_udev_to_usbv(udev))
294 continue;
295 goto usbhsh_device_find;
296 }
297
298 dev_err(dev, "no free usbhsh_device\n");
299
300 return NULL;
301
302usbhsh_device_find:
303 if (usbhsh_device_has_endpoint(udev))
304 dev_warn(dev, "udev have old endpoint\n");
305
306 /* uep will be attached */
307 INIT_LIST_HEAD(&udev->ep_list_head);
308
309 /*
310 * usbhsh_usbv_to_udev()
311 * usbhsh_udev_to_usbv()
312 * will be enable
313 */
314 dev_set_drvdata(&usbv->dev, udev);
315 udev->usbv = usbv;
316
317 /* set device config */
318 usbhs_set_device_speed(priv,
319 usbhsh_device_number(hpriv, udev),
320 usbhsh_device_number(hpriv, udev),
321 0, /* FIXME no parent */
322 usbv->speed);
323
324 dev_dbg(dev, "%s [%d](%p)\n", __func__,
325 usbhsh_device_number(hpriv, udev), udev);
326
327 return udev;
328}
329
330static void usbhsh_device_free(struct usbhsh_hpriv *hpriv,
331 struct usbhsh_device *udev)
332{
333 struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv);
334 struct device *dev = usbhsh_hcd_to_dev(hcd);
335 struct usb_device *usbv = usbhsh_udev_to_usbv(udev);
336
337 dev_dbg(dev, "%s [%d](%p)\n", __func__,
338 usbhsh_device_number(hpriv, udev), udev);
339
340 if (usbhsh_device_has_endpoint(udev))
341 dev_warn(dev, "udev still have endpoint\n");
342
343 /*
344 * usbhsh_usbv_to_udev()
345 * usbhsh_udev_to_usbv()
346 * will be disable
347 */
348 dev_set_drvdata(&usbv->dev, NULL);
349 udev->usbv = NULL;
350}
351
352/*
353 * end-point control
354 */
355struct usbhsh_ep *usbhsh_endpoint_alloc(struct usbhsh_hpriv *hpriv,
356 struct usbhsh_device *udev,
357 struct usb_host_endpoint *ep,
73ef635a 358 int dir_in_req,
034d7c13
KM
359 gfp_t mem_flags)
360{
361 struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
362 struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv);
363 struct usbhsh_ep *uep;
364 struct usbhsh_pipe_info *info;
365 struct usbhs_pipe *pipe, *best_pipe;
366 struct device *dev = usbhsh_hcd_to_dev(hcd);
367 struct usb_endpoint_descriptor *desc = &ep->desc;
73ef635a 368 int type, i, dir_in;
034d7c13
KM
369 unsigned int min_usr;
370
73ef635a
KM
371 dir_in_req = !!dir_in_req;
372
034d7c13
KM
373 uep = kzalloc(sizeof(struct usbhsh_ep), mem_flags);
374 if (!uep) {
375 dev_err(dev, "usbhsh_ep alloc fail\n");
376 return NULL;
377 }
73ef635a
KM
378
379 if (usb_endpoint_xfer_control(desc)) {
380 best_pipe = usbhsh_hpriv_to_dcp(hpriv);
381 goto usbhsh_endpoint_alloc_find_pipe;
382 }
034d7c13
KM
383
384 /*
385 * find best pipe for endpoint
386 * see
387 * HARDWARE LIMITATION
388 */
73ef635a 389 type = usb_endpoint_type(desc);
034d7c13
KM
390 min_usr = ~0;
391 best_pipe = NULL;
73ef635a 392 usbhs_for_each_pipe(pipe, priv, i) {
034d7c13
KM
393 if (!usbhs_pipe_type_is(pipe, type))
394 continue;
395
73ef635a
KM
396 dir_in = !!usbhs_pipe_is_dir_in(pipe);
397 if (0 != (dir_in - dir_in_req))
398 continue;
399
034d7c13
KM
400 info = usbhsh_pipe_info(pipe);
401
402 if (min_usr > info->usr_cnt) {
403 min_usr = info->usr_cnt;
404 best_pipe = pipe;
405 }
406 }
407
408 if (unlikely(!best_pipe)) {
409 dev_err(dev, "couldn't find best pipe\n");
410 kfree(uep);
411 return NULL;
412 }
73ef635a 413usbhsh_endpoint_alloc_find_pipe:
034d7c13
KM
414 /*
415 * init uep
416 */
417 uep->pipe = best_pipe;
418 uep->maxp = usb_endpoint_maxp(desc);
419 usbhsh_uep_to_udev(uep) = udev;
420 usbhsh_ep_to_uep(ep) = uep;
421
422 /*
423 * update pipe user count
424 */
425 info = usbhsh_pipe_info(best_pipe);
426 info->usr_cnt++;
427
428 /* init this endpoint, and attach it to udev */
429 INIT_LIST_HEAD(&uep->ep_list);
430 list_add_tail(&uep->ep_list, &udev->ep_list_head);
431
432 /*
433 * usbhs_pipe_config_update() should be called after
434 * usbhs_device_config()
435 * see
436 * DCPMAXP/PIPEMAXP
437 */
d7a00ec1 438 usbhs_pipe_sequence_data0(uep->pipe);
034d7c13
KM
439 usbhs_pipe_config_update(uep->pipe,
440 usbhsh_device_number(hpriv, udev),
441 usb_endpoint_num(desc),
442 uep->maxp);
443
444 dev_dbg(dev, "%s [%d-%s](%p)\n", __func__,
445 usbhsh_device_number(hpriv, udev),
73ef635a 446 usbhs_pipe_name(uep->pipe), uep);
034d7c13
KM
447
448 return uep;
449}
450
451void usbhsh_endpoint_free(struct usbhsh_hpriv *hpriv,
452 struct usb_host_endpoint *ep)
453{
454 struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
455 struct device *dev = usbhs_priv_to_dev(priv);
456 struct usbhsh_ep *uep = usbhsh_ep_to_uep(ep);
034d7c13
KM
457 struct usbhsh_pipe_info *info;
458
459 if (!uep)
460 return;
461
462 dev_dbg(dev, "%s [%d-%s](%p)\n", __func__,
55b5a624 463 usbhsh_device_number(hpriv, usbhsh_uep_to_udev(uep)),
034d7c13
KM
464 usbhs_pipe_name(uep->pipe), uep);
465
466 info = usbhsh_pipe_info(uep->pipe);
467 info->usr_cnt--;
468
469 /* remove this endpoint from udev */
470 list_del_init(&uep->ep_list);
471
472 usbhsh_uep_to_udev(uep) = NULL;
473 usbhsh_ep_to_uep(ep) = NULL;
474
475 kfree(uep);
476}
477
478/*
479 * queue push/pop
480 */
481static void usbhsh_queue_done(struct usbhs_priv *priv, struct usbhs_pkt *pkt)
482{
25234b46 483 struct usbhsh_request *ureq = usbhsh_pkt_to_ureq(pkt);
034d7c13
KM
484 struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
485 struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv);
486 struct urb *urb = ureq->urb;
487 struct device *dev = usbhs_priv_to_dev(priv);
488
489 dev_dbg(dev, "%s\n", __func__);
490
491 if (!urb) {
492 dev_warn(dev, "pkt doesn't have urb\n");
493 return;
494 }
495
496 urb->actual_length = pkt->actual;
25234b46 497 usbhsh_ureq_free(hpriv, ureq);
034d7c13
KM
498 usbhsh_urb_to_ureq(urb) = NULL;
499
500 usb_hcd_unlink_urb_from_ep(hcd, urb);
501 usb_hcd_giveback_urb(hcd, urb, 0);
502}
503
504static int usbhsh_queue_push(struct usb_hcd *hcd,
505 struct usbhs_pipe *pipe,
ee8a0bf5
KM
506 struct urb *urb,
507 gfp_t mem_flags)
034d7c13 508{
ee8a0bf5 509 struct usbhsh_hpriv *hpriv = usbhsh_hcd_to_hpriv(hcd);
034d7c13 510 struct device *dev = usbhsh_hcd_to_dev(hcd);
ee8a0bf5 511 struct usbhsh_request *ureq;
034d7c13
KM
512 void *buf;
513 int len;
514
515 if (usb_pipeisoc(urb->pipe)) {
516 dev_err(dev, "pipe iso is not supported now\n");
517 return -EIO;
518 }
519
ee8a0bf5
KM
520 /* this ureq will be freed on usbhsh_queue_done() */
521 ureq = usbhsh_ureq_alloc(hpriv, urb, mem_flags);
522 if (unlikely(!ureq)) {
523 dev_err(dev, "ureq alloc fail\n");
524 return -ENOMEM;
525 }
526 usbhsh_urb_to_ureq(urb) = ureq;
527
034d7c13
KM
528 if (usb_pipein(urb->pipe))
529 pipe->handler = &usbhs_fifo_pio_pop_handler;
530 else
531 pipe->handler = &usbhs_fifo_pio_push_handler;
532
533 buf = (void *)(urb->transfer_buffer + urb->actual_length);
534 len = urb->transfer_buffer_length - urb->actual_length;
535
536 dev_dbg(dev, "%s\n", __func__);
ee8a0bf5 537 usbhs_pkt_push(pipe, &ureq->pkt, usbhsh_queue_done,
034d7c13
KM
538 buf, len, (urb->transfer_flags & URB_ZERO_PACKET));
539 usbhs_pkt_start(pipe);
540
541 return 0;
542}
543
544/*
545 * DCP setup stage
546 */
547static int usbhsh_is_request_address(struct urb *urb)
548{
25234b46 549 struct usb_ctrlrequest *req;
034d7c13 550
25234b46 551 req = (struct usb_ctrlrequest *)urb->setup_packet;
034d7c13 552
25234b46
KM
553 if ((DeviceOutRequest == req->bRequestType << 8) &&
554 (USB_REQ_SET_ADDRESS == req->bRequest))
034d7c13
KM
555 return 1;
556 else
557 return 0;
558}
559
560static void usbhsh_setup_stage_packet_push(struct usbhsh_hpriv *hpriv,
561 struct urb *urb,
562 struct usbhs_pipe *pipe)
563{
564 struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
565 struct usb_ctrlrequest req;
566 struct device *dev = usbhs_priv_to_dev(priv);
567
568 /*
569 * wait setup packet ACK
570 * see
571 * usbhsh_irq_setup_ack()
572 * usbhsh_irq_setup_err()
573 */
7fccd480 574 init_completion(&hpriv->setup_ack_done);
034d7c13
KM
575
576 /* copy original request */
577 memcpy(&req, urb->setup_packet, sizeof(struct usb_ctrlrequest));
578
579 /*
580 * renesas_usbhs can not use original usb address.
581 * see HARDWARE LIMITATION.
582 * modify usb address here.
583 */
584 if (usbhsh_is_request_address(urb)) {
585 /* FIXME */
586 req.wValue = 1;
587 dev_dbg(dev, "create new address - %d\n", req.wValue);
588 }
589
590 /* set request */
591 usbhs_usbreq_set_val(priv, &req);
592
593 /*
594 * wait setup packet ACK
595 */
7fccd480 596 wait_for_completion(&hpriv->setup_ack_done);
034d7c13
KM
597
598 dev_dbg(dev, "%s done\n", __func__);
599}
600
601/*
602 * DCP data stage
603 */
604static void usbhsh_data_stage_packet_done(struct usbhs_priv *priv,
605 struct usbhs_pkt *pkt)
606{
25234b46 607 struct usbhsh_request *ureq = usbhsh_pkt_to_ureq(pkt);
034d7c13
KM
608 struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
609 struct urb *urb = ureq->urb;
610
611 /* this ureq was connected to urb when usbhsh_urb_enqueue() */
612
25234b46 613 usbhsh_ureq_free(hpriv, ureq);
034d7c13
KM
614 usbhsh_urb_to_ureq(urb) = NULL;
615}
616
ee8a0bf5
KM
617static int usbhsh_data_stage_packet_push(struct usbhsh_hpriv *hpriv,
618 struct urb *urb,
619 struct usbhs_pipe *pipe,
620 gfp_t mem_flags)
621
034d7c13
KM
622{
623 struct usbhsh_request *ureq;
034d7c13 624
ee8a0bf5
KM
625 /* this ureq will be freed on usbhsh_data_stage_packet_done() */
626 ureq = usbhsh_ureq_alloc(hpriv, urb, mem_flags);
627 if (unlikely(!ureq))
628 return -ENOMEM;
629 usbhsh_urb_to_ureq(urb) = ureq;
034d7c13
KM
630
631 if (usb_pipein(urb->pipe))
632 pipe->handler = &usbhs_dcp_data_stage_in_handler;
633 else
634 pipe->handler = &usbhs_dcp_data_stage_out_handler;
635
ee8a0bf5 636 usbhs_pkt_push(pipe, &ureq->pkt,
034d7c13
KM
637 usbhsh_data_stage_packet_done,
638 urb->transfer_buffer,
639 urb->transfer_buffer_length,
640 (urb->transfer_flags & URB_ZERO_PACKET));
ee8a0bf5
KM
641
642 return 0;
034d7c13
KM
643}
644
645/*
646 * DCP status stage
647 */
ee8a0bf5 648static int usbhsh_status_stage_packet_push(struct usbhsh_hpriv *hpriv,
034d7c13 649 struct urb *urb,
ee8a0bf5
KM
650 struct usbhs_pipe *pipe,
651 gfp_t mem_flags)
034d7c13
KM
652{
653 struct usbhsh_request *ureq;
034d7c13 654
ee8a0bf5
KM
655 /* This ureq will be freed on usbhsh_queue_done() */
656 ureq = usbhsh_ureq_alloc(hpriv, urb, mem_flags);
657 if (unlikely(!ureq))
658 return -ENOMEM;
659 usbhsh_urb_to_ureq(urb) = ureq;
034d7c13
KM
660
661 if (usb_pipein(urb->pipe))
662 pipe->handler = &usbhs_dcp_status_stage_in_handler;
663 else
664 pipe->handler = &usbhs_dcp_status_stage_out_handler;
665
ee8a0bf5 666 usbhs_pkt_push(pipe, &ureq->pkt,
034d7c13
KM
667 usbhsh_queue_done,
668 NULL,
669 urb->transfer_buffer_length,
670 0);
ee8a0bf5
KM
671
672 return 0;
034d7c13
KM
673}
674
675static int usbhsh_dcp_queue_push(struct usb_hcd *hcd,
034d7c13 676 struct usbhs_pipe *pipe,
ee8a0bf5
KM
677 struct urb *urb,
678 gfp_t mflags)
034d7c13 679{
ee8a0bf5 680 struct usbhsh_hpriv *hpriv = usbhsh_hcd_to_hpriv(hcd);
034d7c13 681 struct device *dev = usbhsh_hcd_to_dev(hcd);
ee8a0bf5 682 int ret;
034d7c13
KM
683
684 dev_dbg(dev, "%s\n", __func__);
685
686 /*
687 * setup stage
688 *
689 * usbhsh_send_setup_stage_packet() wait SACK/SIGN
690 */
691 usbhsh_setup_stage_packet_push(hpriv, urb, pipe);
692
693 /*
694 * data stage
695 *
696 * It is pushed only when urb has buffer.
697 */
ee8a0bf5
KM
698 if (urb->transfer_buffer_length) {
699 ret = usbhsh_data_stage_packet_push(hpriv, urb, pipe, mflags);
700 if (ret < 0) {
701 dev_err(dev, "data stage failed\n");
702 return ret;
703 }
704 }
034d7c13
KM
705
706 /*
707 * status stage
708 */
ee8a0bf5
KM
709 ret = usbhsh_status_stage_packet_push(hpriv, urb, pipe, mflags);
710 if (ret < 0) {
711 dev_err(dev, "status stage failed\n");
712 return ret;
713 }
034d7c13
KM
714
715 /*
716 * start pushed packets
717 */
718 usbhs_pkt_start(pipe);
719
720 return 0;
721}
722
723/*
724 * dma map functions
725 */
726static int usbhsh_dma_map_ctrl(struct usbhs_pkt *pkt, int map)
727{
728 return 0;
729}
730
731/*
732 * for hc_driver
733 */
734static int usbhsh_host_start(struct usb_hcd *hcd)
735{
736 return 0;
737}
738
739static void usbhsh_host_stop(struct usb_hcd *hcd)
740{
741}
742
743static int usbhsh_urb_enqueue(struct usb_hcd *hcd,
744 struct urb *urb,
745 gfp_t mem_flags)
746{
747 struct usbhsh_hpriv *hpriv = usbhsh_hcd_to_hpriv(hcd);
748 struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
749 struct device *dev = usbhs_priv_to_dev(priv);
750 struct usb_device *usbv = usbhsh_urb_to_usbv(urb);
751 struct usb_host_endpoint *ep = urb->ep;
034d7c13
KM
752 struct usbhsh_device *udev, *new_udev = NULL;
753 struct usbhs_pipe *pipe;
754 struct usbhsh_ep *uep;
73ef635a 755 int is_dir_in = usb_pipein(urb->pipe);
034d7c13
KM
756
757 int ret;
758
73ef635a 759 dev_dbg(dev, "%s (%s)\n", __func__, is_dir_in ? "in" : "out");
034d7c13
KM
760
761 ret = usb_hcd_link_urb_to_ep(hcd, urb);
762 if (ret)
763 goto usbhsh_urb_enqueue_error_not_linked;
764
765 /*
766 * get udev
767 */
768 udev = usbhsh_usbv_to_udev(usbv);
769 if (!udev) {
770 new_udev = usbhsh_device_alloc(hpriv, urb);
771 if (!new_udev)
772 goto usbhsh_urb_enqueue_error_not_linked;
773
774 udev = new_udev;
775 }
776
777 /*
778 * get uep
779 */
780 uep = usbhsh_ep_to_uep(ep);
781 if (!uep) {
73ef635a
KM
782 uep = usbhsh_endpoint_alloc(hpriv, udev, ep,
783 is_dir_in, mem_flags);
034d7c13
KM
784 if (!uep)
785 goto usbhsh_urb_enqueue_error_free_device;
786 }
787 pipe = usbhsh_uep_to_pipe(uep);
788
034d7c13
KM
789 /*
790 * push packet
791 */
792 if (usb_pipecontrol(urb->pipe))
ee8a0bf5 793 ret = usbhsh_dcp_queue_push(hcd, pipe, urb, mem_flags);
034d7c13 794 else
ee8a0bf5 795 ret = usbhsh_queue_push(hcd, pipe, urb, mem_flags);
034d7c13 796
ee8a0bf5 797 return ret;
034d7c13 798
034d7c13
KM
799usbhsh_urb_enqueue_error_free_device:
800 if (new_udev)
801 usbhsh_device_free(hpriv, new_udev);
802usbhsh_urb_enqueue_error_not_linked:
803
804 dev_dbg(dev, "%s error\n", __func__);
805
806 return ret;
807}
808
809static int usbhsh_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
810{
811 struct usbhsh_hpriv *hpriv = usbhsh_hcd_to_hpriv(hcd);
812 struct usbhsh_request *ureq = usbhsh_urb_to_ureq(urb);
813
814 if (ureq) {
25234b46 815 usbhsh_ureq_free(hpriv, ureq);
034d7c13
KM
816 usbhsh_urb_to_ureq(urb) = NULL;
817 }
818
819 return 0;
820}
821
822static void usbhsh_endpoint_disable(struct usb_hcd *hcd,
823 struct usb_host_endpoint *ep)
824{
825 struct usbhsh_ep *uep = usbhsh_ep_to_uep(ep);
826 struct usbhsh_device *udev;
827 struct usbhsh_hpriv *hpriv;
828
829 /*
830 * this function might be called manytimes by same hcd/ep
831 * in-endpoitn == out-endpoint if ep == dcp.
832 */
833 if (!uep)
834 return;
835
836 udev = usbhsh_uep_to_udev(uep);
837 hpriv = usbhsh_hcd_to_hpriv(hcd);
838
839 usbhsh_endpoint_free(hpriv, ep);
840 ep->hcpriv = NULL;
841
842 /*
843 * if there is no endpoint,
844 * free device
845 */
846 if (!usbhsh_device_has_endpoint(udev))
847 usbhsh_device_free(hpriv, udev);
848}
849
850static int usbhsh_hub_status_data(struct usb_hcd *hcd, char *buf)
851{
852 struct usbhsh_hpriv *hpriv = usbhsh_hcd_to_hpriv(hcd);
853 struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
854 struct device *dev = usbhs_priv_to_dev(priv);
855 int roothub_id = 1; /* only 1 root hub */
856
857 /*
858 * does port stat was changed ?
859 * check USB_PORT_STAT_C_xxx << 16
860 */
861 if (usbhsh_port_stat_get(hpriv) & 0xFFFF0000)
862 *buf = (1 << roothub_id);
863 else
864 *buf = 0;
865
866 dev_dbg(dev, "%s (%02x)\n", __func__, *buf);
867
868 return !!(*buf);
869}
870
871static int __usbhsh_hub_hub_feature(struct usbhsh_hpriv *hpriv,
872 u16 typeReq, u16 wValue,
873 u16 wIndex, char *buf, u16 wLength)
874{
875 struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
876 struct device *dev = usbhs_priv_to_dev(priv);
877
878 switch (wValue) {
879 case C_HUB_OVER_CURRENT:
880 case C_HUB_LOCAL_POWER:
881 dev_dbg(dev, "%s :: C_HUB_xx\n", __func__);
882 return 0;
883 }
884
885 return -EPIPE;
886}
887
888static int __usbhsh_hub_port_feature(struct usbhsh_hpriv *hpriv,
889 u16 typeReq, u16 wValue,
890 u16 wIndex, char *buf, u16 wLength)
891{
892 struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
893 struct device *dev = usbhs_priv_to_dev(priv);
894 int enable = (typeReq == SetPortFeature);
895 int speed, i, timeout = 128;
896 int roothub_id = 1; /* only 1 root hub */
897
898 /* common error */
899 if (wIndex > roothub_id || wLength != 0)
900 return -EPIPE;
901
902 /* check wValue */
903 switch (wValue) {
904 case USB_PORT_FEAT_POWER:
905 usbhs_vbus_ctrl(priv, enable);
906 dev_dbg(dev, "%s :: USB_PORT_FEAT_POWER\n", __func__);
907 break;
908
909 case USB_PORT_FEAT_ENABLE:
910 case USB_PORT_FEAT_SUSPEND:
911 case USB_PORT_FEAT_C_ENABLE:
912 case USB_PORT_FEAT_C_SUSPEND:
913 case USB_PORT_FEAT_C_CONNECTION:
914 case USB_PORT_FEAT_C_OVER_CURRENT:
915 case USB_PORT_FEAT_C_RESET:
916 dev_dbg(dev, "%s :: USB_PORT_FEAT_xxx\n", __func__);
917 break;
918
919 case USB_PORT_FEAT_RESET:
920 if (!enable)
921 break;
922
923 usbhsh_port_stat_clear(hpriv,
924 USB_PORT_STAT_HIGH_SPEED |
925 USB_PORT_STAT_LOW_SPEED);
926
927 usbhs_bus_send_reset(priv);
928 msleep(20);
929 usbhs_bus_send_sof_enable(priv);
930
931 for (i = 0; i < timeout ; i++) {
932 switch (usbhs_bus_get_speed(priv)) {
933 case USB_SPEED_LOW:
934 speed = USB_PORT_STAT_LOW_SPEED;
935 goto got_usb_bus_speed;
936 case USB_SPEED_HIGH:
937 speed = USB_PORT_STAT_HIGH_SPEED;
938 goto got_usb_bus_speed;
939 case USB_SPEED_FULL:
940 speed = 0;
941 goto got_usb_bus_speed;
942 }
943
944 msleep(20);
945 }
946 return -EPIPE;
947
948got_usb_bus_speed:
949 usbhsh_port_stat_set(hpriv, speed);
950 usbhsh_port_stat_set(hpriv, USB_PORT_STAT_ENABLE);
951
952 dev_dbg(dev, "%s :: USB_PORT_FEAT_RESET (speed = %d)\n",
953 __func__, speed);
954
955 /* status change is not needed */
956 return 0;
957
958 default:
959 return -EPIPE;
960 }
961
962 /* set/clear status */
963 if (enable)
964 usbhsh_port_stat_set(hpriv, (1 << wValue));
965 else
966 usbhsh_port_stat_clear(hpriv, (1 << wValue));
967
968 return 0;
969}
970
971static int __usbhsh_hub_get_status(struct usbhsh_hpriv *hpriv,
972 u16 typeReq, u16 wValue,
973 u16 wIndex, char *buf, u16 wLength)
974{
975 struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
976 struct usb_hub_descriptor *desc = (struct usb_hub_descriptor *)buf;
977 struct device *dev = usbhs_priv_to_dev(priv);
978 int roothub_id = 1; /* only 1 root hub */
979
980 switch (typeReq) {
981 case GetHubStatus:
982 dev_dbg(dev, "%s :: GetHubStatus\n", __func__);
983
984 *buf = 0x00;
985 break;
986
987 case GetPortStatus:
988 if (wIndex != roothub_id)
989 return -EPIPE;
990
991 dev_dbg(dev, "%s :: GetPortStatus\n", __func__);
992 *(__le32 *)buf = cpu_to_le32(usbhsh_port_stat_get(hpriv));
993 break;
994
995 case GetHubDescriptor:
996 desc->bDescriptorType = 0x29;
997 desc->bHubContrCurrent = 0;
998 desc->bNbrPorts = roothub_id;
999 desc->bDescLength = 9;
1000 desc->bPwrOn2PwrGood = 0;
1001 desc->wHubCharacteristics = cpu_to_le16(0x0011);
1002 desc->u.hs.DeviceRemovable[0] = (roothub_id << 1);
1003 desc->u.hs.DeviceRemovable[1] = ~0;
1004 dev_dbg(dev, "%s :: GetHubDescriptor\n", __func__);
1005 break;
1006 }
1007
1008 return 0;
1009}
1010
1011static int usbhsh_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
1012 u16 wIndex, char *buf, u16 wLength)
1013{
1014 struct usbhsh_hpriv *hpriv = usbhsh_hcd_to_hpriv(hcd);
1015 struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
1016 struct device *dev = usbhs_priv_to_dev(priv);
1017 int ret = -EPIPE;
1018
1019 switch (typeReq) {
1020
1021 /* Hub Feature */
1022 case ClearHubFeature:
1023 case SetHubFeature:
1024 ret = __usbhsh_hub_hub_feature(hpriv, typeReq,
1025 wValue, wIndex, buf, wLength);
1026 break;
1027
1028 /* Port Feature */
1029 case SetPortFeature:
1030 case ClearPortFeature:
1031 ret = __usbhsh_hub_port_feature(hpriv, typeReq,
1032 wValue, wIndex, buf, wLength);
1033 break;
1034
1035 /* Get status */
1036 case GetHubStatus:
1037 case GetPortStatus:
1038 case GetHubDescriptor:
1039 ret = __usbhsh_hub_get_status(hpriv, typeReq,
1040 wValue, wIndex, buf, wLength);
1041 break;
1042 }
1043
1044 dev_dbg(dev, "typeReq = %x, ret = %d, port_stat = %x\n",
1045 typeReq, ret, usbhsh_port_stat_get(hpriv));
1046
1047 return ret;
1048}
1049
1050static struct hc_driver usbhsh_driver = {
1051 .description = usbhsh_hcd_name,
1052 .hcd_priv_size = sizeof(struct usbhsh_hpriv),
1053
1054 /*
1055 * generic hardware linkage
1056 */
1057 .flags = HCD_USB2,
1058
1059 .start = usbhsh_host_start,
1060 .stop = usbhsh_host_stop,
1061
1062 /*
1063 * managing i/o requests and associated device resources
1064 */
1065 .urb_enqueue = usbhsh_urb_enqueue,
1066 .urb_dequeue = usbhsh_urb_dequeue,
1067 .endpoint_disable = usbhsh_endpoint_disable,
1068
1069 /*
1070 * root hub
1071 */
1072 .hub_status_data = usbhsh_hub_status_data,
1073 .hub_control = usbhsh_hub_control,
1074};
1075
1076/*
1077 * interrupt functions
1078 */
1079static int usbhsh_irq_attch(struct usbhs_priv *priv,
1080 struct usbhs_irq_state *irq_state)
1081{
1082 struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
1083 struct device *dev = usbhs_priv_to_dev(priv);
1084
1085 dev_dbg(dev, "device attached\n");
1086
1087 usbhsh_port_stat_set(hpriv, USB_PORT_STAT_CONNECTION);
1088 usbhsh_port_stat_set(hpriv, USB_PORT_STAT_C_CONNECTION << 16);
1089
1090 return 0;
1091}
1092
1093static int usbhsh_irq_dtch(struct usbhs_priv *priv,
1094 struct usbhs_irq_state *irq_state)
1095{
1096 struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
1097 struct device *dev = usbhs_priv_to_dev(priv);
1098
1099 dev_dbg(dev, "device detached\n");
1100
1101 usbhsh_port_stat_clear(hpriv, USB_PORT_STAT_CONNECTION);
1102 usbhsh_port_stat_set(hpriv, USB_PORT_STAT_C_CONNECTION << 16);
1103
1104 return 0;
1105}
1106
1107static int usbhsh_irq_setup_ack(struct usbhs_priv *priv,
1108 struct usbhs_irq_state *irq_state)
1109{
1110 struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
1111 struct device *dev = usbhs_priv_to_dev(priv);
1112
1113 dev_dbg(dev, "setup packet OK\n");
1114
7fccd480 1115 complete(&hpriv->setup_ack_done); /* see usbhsh_urb_enqueue() */
034d7c13
KM
1116
1117 return 0;
1118}
1119
1120static int usbhsh_irq_setup_err(struct usbhs_priv *priv,
1121 struct usbhs_irq_state *irq_state)
1122{
1123 struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
1124 struct device *dev = usbhs_priv_to_dev(priv);
1125
1126 dev_dbg(dev, "setup packet Err\n");
1127
7fccd480 1128 complete(&hpriv->setup_ack_done); /* see usbhsh_urb_enqueue() */
034d7c13
KM
1129
1130 return 0;
1131}
1132
1133/*
1134 * module start/stop
1135 */
1136static void usbhsh_pipe_init_for_host(struct usbhs_priv *priv)
1137{
1138 struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
1139 struct usbhsh_pipe_info *pipe_info = hpriv->pipe_info;
1140 struct usbhs_pipe *pipe;
1141 u32 *pipe_type = usbhs_get_dparam(priv, pipe_type);
1142 int pipe_size = usbhs_get_dparam(priv, pipe_size);
1143 int old_type, dir_in, i;
1144
1145 /* init all pipe */
1146 old_type = USB_ENDPOINT_XFER_CONTROL;
1147 for (i = 0; i < pipe_size; i++) {
1148 pipe_info[i].usr_cnt = 0;
1149
1150 /*
1151 * data "output" will be finished as soon as possible,
1152 * but there is no guaranty at data "input" case.
1153 *
1154 * "input" needs "standby" pipe.
1155 * So, "input" direction pipe > "output" direction pipe
1156 * is good idea.
1157 *
1158 * 1st USB_ENDPOINT_XFER_xxx will be output direction,
1159 * and the other will be input direction here.
1160 *
1161 * ex)
1162 * ...
1163 * USB_ENDPOINT_XFER_ISOC -> dir out
1164 * USB_ENDPOINT_XFER_ISOC -> dir in
1165 * USB_ENDPOINT_XFER_BULK -> dir out
1166 * USB_ENDPOINT_XFER_BULK -> dir in
1167 * USB_ENDPOINT_XFER_BULK -> dir in
1168 * ...
1169 */
1170 dir_in = (pipe_type[i] == old_type);
1171 old_type = pipe_type[i];
1172
1173 if (USB_ENDPOINT_XFER_CONTROL == pipe_type[i]) {
1174 pipe = usbhs_dcp_malloc(priv);
1175 usbhsh_hpriv_to_dcp(hpriv) = pipe;
1176 } else {
1177 pipe = usbhs_pipe_malloc(priv,
1178 pipe_type[i],
1179 dir_in);
1180 }
1181
1182 pipe->mod_private = pipe_info + i;
1183 }
1184}
1185
1186static int usbhsh_start(struct usbhs_priv *priv)
1187{
1188 struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
1189 struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv);
1190 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
1191 struct device *dev = usbhs_priv_to_dev(priv);
1192 int ret;
1193
1194 /* add hcd */
1195 ret = usb_add_hcd(hcd, 0, 0);
1196 if (ret < 0)
1197 return 0;
1198
1199 /*
1200 * pipe initialize and enable DCP
1201 */
1202 usbhs_pipe_init(priv,
1203 usbhsh_dma_map_ctrl);
1204 usbhs_fifo_init(priv);
1205 usbhsh_pipe_init_for_host(priv);
1206
1207 /*
1208 * system config enble
1209 * - HI speed
1210 * - host
1211 * - usb module
1212 */
034d7c13 1213 usbhs_sys_host_ctrl(priv, 1);
034d7c13
KM
1214
1215 /*
1216 * enable irq callback
1217 */
1218 mod->irq_attch = usbhsh_irq_attch;
1219 mod->irq_dtch = usbhsh_irq_dtch;
1220 mod->irq_sack = usbhsh_irq_setup_ack;
1221 mod->irq_sign = usbhsh_irq_setup_err;
1222 usbhs_irq_callback_update(priv, mod);
1223
1224 dev_dbg(dev, "start host\n");
1225
1226 return ret;
1227}
1228
1229static int usbhsh_stop(struct usbhs_priv *priv)
1230{
1231 struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
1232 struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv);
146ee50a 1233 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
034d7c13
KM
1234 struct device *dev = usbhs_priv_to_dev(priv);
1235
146ee50a
KM
1236 /*
1237 * disable irq callback
1238 */
1239 mod->irq_attch = NULL;
1240 mod->irq_dtch = NULL;
1241 mod->irq_sack = NULL;
1242 mod->irq_sign = NULL;
1243 usbhs_irq_callback_update(priv, mod);
1244
034d7c13
KM
1245 usb_remove_hcd(hcd);
1246
1247 /* disable sys */
034d7c13 1248 usbhs_sys_host_ctrl(priv, 0);
034d7c13
KM
1249
1250 dev_dbg(dev, "quit host\n");
1251
1252 return 0;
1253}
1254
b7a8d17d 1255int usbhs_mod_host_probe(struct usbhs_priv *priv)
034d7c13
KM
1256{
1257 struct usbhsh_hpriv *hpriv;
1258 struct usb_hcd *hcd;
1259 struct usbhsh_pipe_info *pipe_info;
1260 struct usbhsh_device *udev;
1261 struct device *dev = usbhs_priv_to_dev(priv);
1262 int pipe_size = usbhs_get_dparam(priv, pipe_size);
1263 int i;
1264
1265 /* initialize hcd */
1266 hcd = usb_create_hcd(&usbhsh_driver, dev, usbhsh_hcd_name);
1267 if (!hcd) {
1268 dev_err(dev, "Failed to create hcd\n");
1269 return -ENOMEM;
1270 }
1271
1272 pipe_info = kzalloc(sizeof(*pipe_info) * pipe_size, GFP_KERNEL);
1273 if (!pipe_info) {
1274 dev_err(dev, "Could not allocate pipe_info\n");
1275 goto usbhs_mod_host_probe_err;
1276 }
1277
1278 /*
1279 * CAUTION
1280 *
1281 * There is no guarantee that it is possible to access usb module here.
1282 * Don't accesses to it.
1283 * The accesse will be enable after "usbhsh_start"
1284 */
1285
1286 hpriv = usbhsh_hcd_to_hpriv(hcd);
1287
1288 /*
1289 * register itself
1290 */
1291 usbhs_mod_register(priv, &hpriv->mod, USBHS_HOST);
1292
1293 /* init hpriv */
1294 hpriv->mod.name = "host";
1295 hpriv->mod.start = usbhsh_start;
1296 hpriv->mod.stop = usbhsh_stop;
1297 hpriv->pipe_info = pipe_info;
1298 hpriv->pipe_size = pipe_size;
25234b46 1299 usbhsh_ureq_list_init(hpriv);
034d7c13
KM
1300 usbhsh_port_stat_init(hpriv);
1301
1302 /* init all device */
1303 usbhsh_for_each_udev_with_dev0(udev, hpriv, i) {
1304 udev->usbv = NULL;
1305 INIT_LIST_HEAD(&udev->ep_list_head);
1306 }
1307
1308 dev_info(dev, "host probed\n");
1309
1310 return 0;
1311
1312usbhs_mod_host_probe_err:
1313 usb_put_hcd(hcd);
1314
1315 return -ENOMEM;
1316}
1317
b7a8d17d 1318int usbhs_mod_host_remove(struct usbhs_priv *priv)
034d7c13
KM
1319{
1320 struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
1321 struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv);
1322
25234b46 1323 usbhsh_ureq_list_quit(hpriv);
034d7c13
KM
1324
1325 usb_put_hcd(hcd);
1326
1327 return 0;
1328}