18 #include <linux/module.h>
19 #include <linux/types.h>
21 #include <linux/kernel.h>
23 #include <linux/errno.h>
24 #include <linux/list.h>
31 #include <linux/slab.h>
97 fhci_info(fhci,
"unbalanced USB interrupts nesting\n");
169 static void fhci_mem_free(
struct fhci_hcd *fhci)
193 static int fhci_mem_init(
struct fhci_hcd *fhci)
201 INIT_LIST_HEAD(&fhci->
hc_list->ctrl_list);
202 INIT_LIST_HEAD(&fhci->
hc_list->bulk_list);
203 INIT_LIST_HEAD(&fhci->
hc_list->iso_list);
204 INIT_LIST_HEAD(&fhci->
hc_list->intr_list);
205 INIT_LIST_HEAD(&fhci->
hc_list->done_list);
218 for (i = 0; i <
MAX_TDS; i++) {
226 for (i = 0; i <
MAX_EDS; i++) {
243 static void fhci_usb_free(
void *lld)
258 static int fhci_usb_init(
struct fhci_hcd *fhci)
312 fhci_err(fhci,
"no memory for SCC data struct\n");
325 static int fhci_start(
struct usb_hcd *hcd)
328 struct fhci_hcd *fhci = hcd_to_fhci(hcd);
330 ret = fhci_mem_init(fhci);
332 fhci_err(fhci,
"failed to allocate memory\n");
336 fhci->
usb_lld = fhci_create_lld(fhci);
338 fhci_err(fhci,
"low level driver config failed\n");
343 ret = fhci_usb_init(fhci);
345 fhci_err(fhci,
"low level driver initialize failed\n");
358 hcd->state = HC_STATE_RUNNING;
369 fhci_usb_enable(fhci);
376 static void fhci_stop(
struct usb_hcd *hcd)
378 struct fhci_hcd *fhci = hcd_to_fhci(hcd);
381 fhci_usb_disable(fhci);
388 static int fhci_urb_enqueue(
struct usb_hcd *hcd,
struct urb *
urb,
391 struct fhci_hcd *fhci = hcd_to_fhci(hcd);
399 switch (usb_pipetype(pipe)) {
405 size += urb->transfer_buffer_length / 4096;
407 if ((urb->transfer_buffer_length % 4096) != 0)
412 else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0
413 && (urb->transfer_buffer_length
414 % usb_maxpacket(urb->dev, pipe,
415 usb_pipeout(pipe))) != 0)
418 case PIPE_ISOCHRONOUS:
419 size = urb->number_of_packets;
422 for (i = 0; i < urb->number_of_packets; i++) {
423 urb->iso_frame_desc[
i].actual_length = 0;
424 urb->iso_frame_desc[
i].status = (
u32) (-
EXDEV);
432 urb_priv = kzalloc(
sizeof(*urb_priv), mem_flags);
437 urb_priv->
tds = kcalloc(size,
sizeof(*urb_priv->
tds), mem_flags);
438 if (!urb_priv->
tds) {
453 urb->actual_length = 0;
454 urb->error_count = 0;
455 urb->hcpriv = urb_priv;
463 spin_unlock_irqrestore(&fhci->
lock, flags);
468 static int fhci_urb_dequeue(
struct usb_hcd *hcd,
struct urb *urb,
int status)
470 struct fhci_hcd *fhci = hcd_to_fhci(hcd);
475 if (!urb || !urb->dev || !urb->dev->bus)
485 struct urb_priv *urb_priv;
491 urb_priv = urb->hcpriv;
505 spin_unlock_irqrestore(&fhci->
lock, flags);
510 static void fhci_endpoint_disable(
struct usb_hcd *hcd,
511 struct usb_host_endpoint *
ep)
517 fhci = hcd_to_fhci(hcd);
528 spin_unlock_irqrestore(&fhci->
lock, flags);
531 static int fhci_get_frame_number(
struct usb_hcd *hcd)
533 struct fhci_hcd *fhci = hcd_to_fhci(hcd);
535 return get_frame_num(fhci);
538 static const struct hc_driver fhci_driver = {
539 .description =
"fsl,usb-fhci",
540 .product_desc =
"FHCI HOST Controller",
541 .hcd_priv_size =
sizeof(
struct fhci_hcd),
545 .flags = HCD_USB11 | HCD_MEMORY,
552 .urb_enqueue = fhci_urb_enqueue,
553 .urb_dequeue = fhci_urb_dequeue,
554 .endpoint_disable = fhci_endpoint_disable,
557 .get_frame_number = fhci_get_frame_number,
571 unsigned long pram_addr;
572 unsigned int usb_irq;
584 if (sprop &&
strcmp(sprop,
"host"))
589 dev_err(dev,
"could not create hcd\n");
593 fhci = hcd_to_fhci(hcd);
594 hcd->self.controller =
dev;
598 if (iprop && size ==
sizeof(*iprop))
599 hcd->power_budget = *iprop;
604 dev_err(dev,
"could not get regs\n");
608 hcd->regs =
ioremap(usb_regs.start, resource_size(&usb_regs));
610 dev_err(dev,
"could not ioremap regs\n");
614 fhci->
regs = hcd->regs;
618 if (!iprop || size <
sizeof(*iprop) * 4) {
619 dev_err(dev,
"can't get pram offset\n");
626 dev_err(dev,
"failed to allocate usb pram\n");
631 qe_issue_cmd(QE_ASSIGN_PAGE_TO_DEVICE, QE_CR_SUBBLOCK_USB,
632 QE_CR_PROTOCOL_UNSPECIFIED, pram_addr);
640 gpio = of_get_gpio_flags(node, i, &flags);
644 if (!gpio_is_valid(gpio)) {
646 dev_err(dev,
"incorrect GPIO%d: %d\n",
650 dev_info(dev,
"assuming board doesn't have "
659 dev_err(dev,
"failed to request gpio %d", i);
666 dev_err(dev,
"failed to set gpio %d as "
676 if (IS_ERR(fhci->
pins[j])) {
677 ret = PTR_ERR(fhci->
pins[j]);
678 dev_err(dev,
"can't get pin %d: %d\n", j, ret);
685 if (IS_ERR(fhci->
timer)) {
686 ret = PTR_ERR(fhci->
timer);
687 dev_err(dev,
"failed to request qe timer: %i", ret);
692 0,
"qe timer (usb)", hcd);
694 dev_err(dev,
"failed to request timer irq");
701 dev_err(dev,
"could not get usb irq\n");
711 dev_err(dev,
"wrong fullspeed-clock\n");
721 dev_err(dev,
"wrong lowspeed-clock\n");
729 dev_err(dev,
"no clocks specified\n");
734 dev_info(dev,
"at 0x%p, irq %d\n", hcd->regs, usb_irq);
772 if (gpio_is_valid(fhci->
gpios[i]))
786 struct fhci_hcd *fhci = hcd_to_fhci(hcd);
795 if (!gpio_is_valid(fhci->
gpios[i]))
808 return fhci_remove(&ofdev->
dev);
812 { .compatible =
"fsl,mpc8323-qe-usb", },
819 .name =
"fsl,usb-fhci",
821 .of_match_table = of_fhci_match,
823 .probe = of_fhci_probe,