X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/00549f6de02bdb40a6470fe998edcbd3e048357e..d60ce1b40f304758df396ea08f5eae1a9a43d8b0:/target/linux/adm5120/files/drivers/usb/host/adm5120-hcd.c diff --git a/target/linux/adm5120/files/drivers/usb/host/adm5120-hcd.c b/target/linux/adm5120/files/drivers/usb/host/adm5120-hcd.c index 14fd0f96f..041254647 100644 --- a/target/linux/adm5120/files/drivers/usb/host/adm5120-hcd.c +++ b/target/linux/adm5120/files/drivers/usb/host/adm5120-hcd.c @@ -1,21 +1,21 @@ /* - * OHCI HCD (Host Controller Driver) for USB. + * ADM5120 HCD (Host Controller Driver) for USB * - * (C) Copyright 1999 Roman Weissgaerber - * (C) Copyright 2000-2004 David Brownell + * Copyright (C) 2007-2008 Gabor Juhos * - * [ Initialisation is based on Linus' ] - * [ uhci code and gregs ahcd fragments ] - * [ (C) Copyright 1999 Linus Torvalds ] - * [ (C) Copyright 1999 Gregory P. Smith] + * This file was derived from: drivers/usb/host/ohci-hcd.c + * (C) Copyright 1999 Roman Weissgaerber + * (C) Copyright 2000-2004 David Brownell * + * [ Initialisation is based on Linus' ] + * [ uhci code and gregs ahcd fragments ] + * [ (C) Copyright 1999 Linus Torvalds ] + * [ (C) Copyright 1999 Gregory P. Smith] * - * OHCI is the main "non-Intel/VIA" standard for USB 1.1 host controller - * interfaces (though some non-x86 Intel chips use it). It supports - * smarter hardware than UHCI. A download link for the spec available - * through the http://www.usb.org website. + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. * - * This file is licenced under the GPL. */ #include @@ -35,8 +35,9 @@ #include #include #include +#include +#include -#include #include #include #include @@ -45,26 +46,24 @@ #include "../core/hcd.h" #include "../core/hub.h" -#define DRIVER_VERSION "v0.04" -#define DRIVER_AUTHOR "Gabor Juhos " +#define DRIVER_VERSION "0.27.0" +#define DRIVER_AUTHOR "Gabor Juhos " #define DRIVER_DESC "ADMtek USB 1.1 Host Controller Driver" /*-------------------------------------------------------------------------*/ -#define ADMHC_VERBOSE_DEBUG /* not always helpful */ -#define ADMHC_POLL_RH -#undef ADMHC_LOCK_DMA +#undef ADMHC_VERBOSE_DEBUG /* not always helpful */ /* For initializing controller (mask in an HCFS mode too) */ #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR #define ADMHC_INTR_INIT \ - ( ADMHC_INTR_MIE | ADMHC_INTR_INSM | ADMHC_INTR_FATI \ - | ADMHC_INTR_RESI | ADMHC_INTR_TDC | ADMHC_INTR_BABI ) + (ADMHC_INTR_MIE | ADMHC_INTR_INSM | ADMHC_INTR_FATI \ + | ADMHC_INTR_RESI | ADMHC_INTR_TDC | ADMHC_INTR_BABI) /*-------------------------------------------------------------------------*/ -static const char hcd_name [] = "admhc-hcd"; +static const char hcd_name[] = "admhc-hcd"; #define STATECHANGE_DELAY msecs_to_jiffies(300) @@ -85,8 +84,8 @@ static void admhc_stop(struct usb_hcd *hcd); /* * queue up an urb for anything except the root hub */ -static int admhc_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *ep, - struct urb *urb, gfp_t mem_flags) +static int admhc_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, + gfp_t mem_flags) { struct admhcd *ahcd = hcd_to_admhcd(hcd); struct ed *ed; @@ -98,12 +97,12 @@ static int admhc_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *ep, #ifdef ADMHC_VERBOSE_DEBUG spin_lock_irqsave(&ahcd->lock, flags); - urb_print(ahcd, urb, "ENQEUE", usb_pipein(pipe)); + urb_print(ahcd, urb, "ENQEUE", usb_pipein(pipe), -EINPROGRESS); spin_unlock_irqrestore(&ahcd->lock, flags); #endif /* every endpoint has an ed, locate and maybe (re)initialize it */ - ed = ed_get(ahcd, ep, urb->dev, pipe, urb->interval); + ed = ed_get(ahcd, urb->ep, urb->dev, pipe, urb->interval); if (!ed) return -ENOMEM; @@ -116,12 +115,10 @@ static int admhc_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *ep, /* 1 TD for setup, 1 for ACK, plus ... */ td_cnt = 2; - if (urb->transfer_buffer_length) - td_cnt++; - break; + /* FALLTHROUGH */ case PIPE_BULK: /* one TD for every 4096 Bytes (can be upto 8K) */ - td_cnt = urb->transfer_buffer_length / TD_DATALEN_MAX; + td_cnt += urb->transfer_buffer_length / TD_DATALEN_MAX; /* ... and for any remaining bytes ... */ if ((urb->transfer_buffer_length % TD_DATALEN_MAX) != 0) td_cnt++; @@ -131,7 +128,7 @@ static int admhc_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *ep, else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0 && (urb->transfer_buffer_length % usb_maxpacket(urb->dev, pipe, - usb_pipeout (pipe))) == 0) + usb_pipeout(pipe))) == 0) td_cnt++; break; case PIPE_INTERRUPT: @@ -146,10 +143,6 @@ static int admhc_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *ep, /* number of packets from URB */ td_cnt = urb->number_of_packets; break; - default: - /* paranoia */ - admhc_err(ahcd, "bad EP type %d", ed->type); - return -EINVAL; } urb_priv = urb_priv_alloc(ahcd, td_cnt, mem_flags); @@ -157,7 +150,6 @@ static int admhc_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *ep, return -ENOMEM; urb_priv->ed = ed; - urb_priv->urb = urb; spin_lock_irqsave(&ahcd->lock, flags); /* don't submit to a dead HC */ @@ -170,18 +162,18 @@ static int admhc_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *ep, goto fail; } - /* in case of unlink-during-submit */ - spin_lock(&urb->lock); - if (urb->status != -EINPROGRESS) { - spin_unlock(&urb->lock); - urb->hcpriv = urb_priv; - finish_urb(ahcd, urb); - ret = 0; + ret = usb_hcd_link_urb_to_ep(hcd, urb); + if (ret) goto fail; - } - if (ed->type == PIPE_ISOCHRONOUS) { - if (ed->state == ED_NEW) { + /* schedule the ed if needed */ + if (ed->state == ED_IDLE) { + ret = ed_schedule(ahcd, ed); + if (ret < 0) { + usb_hcd_unlink_urb_from_ep(hcd, urb); + goto fail; + } + if (ed->type == PIPE_ISOCHRONOUS) { u16 frame = admhc_frame_no(ahcd); /* delay a few frames before the first TD */ @@ -193,81 +185,74 @@ static int admhc_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *ep, /* yes, only URB_ISO_ASAP is supported, and * urb->start_frame is never used as input. */ - } else - urb->start_frame = ed->last_iso + ed->interval; - } + } + } else if (ed->type == PIPE_ISOCHRONOUS) + urb->start_frame = ed->last_iso + ed->interval; + /* fill the TDs and link them to the ed; and + * enable that part of the schedule, if needed + * and update count of queued periodic urbs + */ urb->hcpriv = urb_priv; - td_submit_urb(ahcd, urb_priv->urb); + td_submit_urb(ahcd, urb); - /* append it to the ED's queue */ - list_add_tail(&urb_priv->pending, &ed->urb_pending); - - /* schedule the ED */ - ret = ed_schedule(ahcd, ed); +#ifdef ADMHC_VERBOSE_DEBUG + admhc_dump_ed(ahcd, "admhc_urb_enqueue", urb_priv->ed, 1); +#endif -fail0: - spin_unlock(&urb->lock); fail: - if (ret) { - urb_priv = urb->hcpriv; + if (ret) urb_priv_free(ahcd, urb_priv); - } spin_unlock_irqrestore(&ahcd->lock, flags); return ret; } /* - * decouple the URB from the HC queues (TDs, urb_priv); it's - * already marked using urb->status. reporting is always done + * decouple the URB from the HC queues (TDs, urb_priv); + * reporting is always done * asynchronously, and we might be dealing with an urb that's * partially transferred, or an ED with other urbs being unlinked. */ -static int admhc_urb_dequeue(struct usb_hcd *hcd, struct urb *urb) +static int admhc_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, + int status) { struct admhcd *ahcd = hcd_to_admhcd(hcd); - struct urb_priv *up; unsigned long flags; - - up = urb->hcpriv; - if (!up) - return 0; + int ret; spin_lock_irqsave(&ahcd->lock, flags); #ifdef ADMHC_VERBOSE_DEBUG - urb_print(ahcd, urb, "DEQEUE", 1); + urb_print(ahcd, urb, "DEQUEUE", 1, status); #endif + ret = usb_hcd_check_unlink_urb(hcd, urb, status); + if (ret) { + /* Do nothing */ + ; + } else if (HC_IS_RUNNING(hcd->state)) { + struct urb_priv *urb_priv; - if (HC_IS_RUNNING(hcd->state)) { /* Unless an IRQ completed the unlink while it was being * handed to us, flag it for unlink and giveback, and force * some upcoming INTR_SF to call finish_unlinks() */ - if (up->ed->urb_active != up) { - list_del(&up->pending); - finish_urb(ahcd, urb); - } else { - ed_start_deschedule(ahcd, up->ed); + urb_priv = urb->hcpriv; + if (urb_priv) { + if (urb_priv->ed->state == ED_OPER) + start_ed_unlink(ahcd, urb_priv->ed); } } else { /* * with HC dead, we won't respect hc queue pointers * any more ... just clean up every urb's memory. */ - if (up->ed->urb_active != up) { - list_del(&up->pending); - finish_urb(ahcd, urb); - } else { - finish_urb(ahcd, urb); - up->ed->urb_active = NULL; - up->ed->state = ED_IDLE; - } + if (urb->hcpriv) + finish_urb(ahcd, urb, status); } spin_unlock_irqrestore(&ahcd->lock, flags); - return 0; + return ret; } /*-------------------------------------------------------------------------*/ @@ -275,6 +260,7 @@ static int admhc_urb_dequeue(struct usb_hcd *hcd, struct urb *urb) /* frees config/altsetting state for endpoints, * including ED memory, dummy TD, and bulk/intr data toggle */ + static void admhc_endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep) { @@ -300,8 +286,8 @@ rescan: if (!HC_IS_RUNNING(hcd->state)) { sanitize: - ed->state = ED_UNLINK; - admhc_finish_unlinks(ahcd, 0); + ed->state = ED_IDLE; + finish_unlinks(ahcd, 0); } switch (ed->state) { @@ -314,9 +300,8 @@ sanitize: spin_unlock_irqrestore(&ahcd->lock, flags); schedule_timeout_uninterruptible(1); goto rescan; - case ED_IDLE: - case ED_NEW: /* fully unlinked */ - if (list_empty(&ed->urb_pending)) { + case ED_IDLE: /* fully unlinked */ + if (list_empty(&ed->td_list)) { td_free(ahcd, ed->dummy); ed_free(ahcd, ed); break; @@ -326,11 +311,10 @@ sanitize: /* caller was supposed to have unlinked any requests; * that's not our job. can't recover; must leak ed. */ - admhc_err(ahcd, "leak ed %p (#%02x) %s act %p%s\n", - ed, ep->desc.bEndpointAddress, - ed_statestring(ed->state), - ed->urb_active, - list_empty(&ed->urb_pending) ? "" : " (has urbs)"); + admhc_err(ahcd, "leak ed %p (#%02x) state %d%s\n", + ed, ep->desc.bEndpointAddress, ed->state, + list_empty(&ed->td_list) ? "" : " (has tds)"); + td_free(ahcd, ed->dummy); break; } @@ -349,8 +333,15 @@ static int admhc_get_frame_number(struct usb_hcd *hcd) static void admhc_usb_reset(struct admhcd *ahcd) { +#if 0 + ahcd->hc_control = admhc_readl(ahcd, &ahcd->regs->control); + ahcd->hc_control &= OHCI_CTRL_RWC; + admhc_writel(ahcd, ahcd->hc_control, &ahcd->regs->control); +#else + /* FIXME */ ahcd->host_control = ADMHC_BUSS_RESET; admhc_writel(ahcd, ahcd->host_control, &ahcd->regs->host_control); +#endif } /* admhc_shutdown forcibly disables IRQs and DMA, helping kexec and @@ -366,6 +357,8 @@ admhc_shutdown(struct usb_hcd *hcd) admhc_intr_disable(ahcd, ADMHC_INTR_MIE); admhc_dma_disable(ahcd); admhc_usb_reset(ahcd); + /* flush the writes */ + admhc_writel_flush(ahcd); } /*-------------------------------------------------------------------------* @@ -513,6 +506,17 @@ static int admhc_run(struct admhcd *ahcd) /* also: power/overcurrent flags in rhdesc */ } +#if 0 /* TODO: not applicable */ + /* Reset USB nearly "by the book". RemoteWakeupConnected was + * saved if boot firmware (BIOS/SMM/...) told us it's connected, + * or if bus glue did the same (e.g. for PCI add-in cards with + * PCI PM support). + */ + if ((ahcd->hc_control & OHCI_CTRL_RWC) != 0 + && !device_may_wakeup(hcd->self.controller)) + device_init_wakeup(hcd->self.controller, 1); +#endif + switch (ahcd->host_control & ADMHC_HC_BUSS) { case ADMHC_BUSS_OPER: temp = 0; @@ -531,6 +535,9 @@ static int admhc_run(struct admhcd *ahcd) } admhc_writel(ahcd, ahcd->host_control, &ahcd->regs->host_control); + /* flush the writes */ + admhc_writel_flush(ahcd); + msleep(temp); temp = admhc_read_rhdesc(ahcd); if (!(temp & ADMHC_RH_NPS)) { @@ -538,6 +545,8 @@ static int admhc_run(struct admhcd *ahcd) for (temp = 0; temp < ahcd->num_ports; temp++) admhc_write_portstatus(ahcd, temp, ADMHC_PS_CPP); } + /* flush those writes */ + admhc_writel_flush(ahcd); /* 2msec timelimit here means no irqs/preempt */ spin_lock_irq(&ahcd->lock); @@ -550,7 +559,7 @@ static int admhc_run(struct admhcd *ahcd) admhc_err(ahcd, "USB HC reset timed out!\n"); return -1; } - udelay (1); + udelay(1); } /* enable HOST mode, before access any host specific register */ @@ -578,6 +587,9 @@ static int admhc_run(struct admhcd *ahcd) admhc_writel(ahcd, ADMHC_RH_NPS | ADMHC_RH_LPSC, &ahcd->regs->rhdesc); + /* flush those writes */ + admhc_writel_flush(ahcd); + /* start controller operations */ ahcd->host_control = ADMHC_BUSS_OPER; admhc_writel(ahcd, ahcd->host_control, &ahcd->regs->host_control); @@ -594,8 +606,27 @@ static int admhc_run(struct admhcd *ahcd) } hcd->state = HC_STATE_RUNNING; + ahcd->next_statechange = jiffies + STATECHANGE_DELAY; +#if 0 + /* FIXME: enabling DMA is always failed here for an unknown reason */ + admhc_dma_enable(ahcd); + + temp = 200; + while ((admhc_readl(ahcd, &ahcd->regs->host_control) + & ADMHC_HC_DMAE) != ADMHC_HC_DMAE) { + if (--temp == 0) { + spin_unlock_irq(&ahcd->lock); + admhc_err(ahcd, "unable to enable DMA!\n"); + admhc_dump(ahcd, 1); + return -1; + } + mdelay(1); + } + +#endif + spin_unlock_irq(&ahcd->lock); mdelay(ADMHC_POTPGT); @@ -611,27 +642,28 @@ static irqreturn_t admhc_irq(struct usb_hcd *hcd) { struct admhcd *ahcd = hcd_to_admhcd(hcd); struct admhcd_regs __iomem *regs = ahcd->regs; - u32 ints; + u32 ints; ints = admhc_readl(ahcd, ®s->int_status); - if (!(ints & ADMHC_INTR_INTA)) + if ((ints & ADMHC_INTR_INTA) == 0) { /* no unmasked interrupt status is set */ return IRQ_NONE; + } ints &= admhc_readl(ahcd, ®s->int_enable); - if (!ints) - return IRQ_NONE; if (ints & ADMHC_INTR_FATI) { + /* e.g. due to PCI Master/Target Abort */ admhc_disable(ahcd); admhc_err(ahcd, "Fatal Error, controller disabled\n"); + admhc_dump(ahcd, 1); admhc_usb_reset(ahcd); } if (ints & ADMHC_INTR_BABI) { - admhc_disable(ahcd); + admhc_intr_disable(ahcd, ADMHC_INTR_BABI); + admhc_intr_ack(ahcd, ADMHC_INTR_BABI); admhc_err(ahcd, "Babble Detected\n"); - admhc_usb_reset(ahcd); } if (ints & ADMHC_INTR_INSM) { @@ -658,16 +690,18 @@ static irqreturn_t admhc_irq(struct usb_hcd *hcd) admhc_intr_ack(ahcd, ADMHC_INTR_RESI); hcd->poll_rh = 1; if (ahcd->autostop) { + spin_lock(&ahcd->lock); admhc_rh_resume(ahcd); + spin_unlock(&ahcd->lock); } else usb_hcd_resume_root_hub(hcd); } if (ints & ADMHC_INTR_TDC) { + admhc_vdbg(ahcd, "Transfer Descriptor Complete\n"); admhc_intr_ack(ahcd, ADMHC_INTR_TDC); if (HC_IS_RUNNING(hcd->state)) admhc_intr_disable(ahcd, ADMHC_INTR_TDC); - admhc_vdbg(ahcd, "Transfer Descriptor Complete\n"); spin_lock(&ahcd->lock); admhc_td_complete(ahcd); spin_unlock(&ahcd->lock); @@ -680,18 +714,42 @@ static irqreturn_t admhc_irq(struct usb_hcd *hcd) admhc_vdbg(ahcd, "Schedule Overrun\n"); } +#if 1 + spin_lock(&ahcd->lock); + if (ahcd->ed_rm_list) + finish_unlinks(ahcd, admhc_frame_no(ahcd)); + + if ((ints & ADMHC_INTR_SOFI) != 0 && !ahcd->ed_rm_list + && HC_IS_RUNNING(hcd->state)) + admhc_intr_disable(ahcd, ADMHC_INTR_SOFI); + spin_unlock(&ahcd->lock); +#else if (ints & ADMHC_INTR_SOFI) { - admhc_intr_ack(ahcd, ADMHC_INTR_SOFI); - /* handle any pending ED removes */ - admhc_finish_unlinks(ahcd, admhc_frame_no(ahcd)); + admhc_vdbg(ahcd, "Start Of Frame\n"); spin_lock(&ahcd->lock); - admhc_sof_refill(ahcd); + + /* handle any pending ED removes */ + finish_unlinks(ahcd, admhc_frameno(ahcd)); + + /* leaving INTR_SOFI enabled when there's still unlinking + * to be done in the (next frame). + */ + if ((ahcd->ed_rm_list == NULL) || + HC_IS_RUNNING(hcd->state) == 0) + /* + * disable INTR_SOFI if there are no unlinking to be + * done (in the next frame) + */ + admhc_intr_disable(ahcd, ADMHC_INTR_SOFI); + spin_unlock(&ahcd->lock); } +#endif if (HC_IS_RUNNING(hcd->state)) { admhc_intr_ack(ahcd, ints); admhc_intr_enable(ahcd, ADMHC_INTR_MIE); + admhc_writel_flush(ahcd); } return IRQ_HANDLED; @@ -708,7 +766,7 @@ static void admhc_stop(struct usb_hcd *hcd) flush_scheduled_work(); admhc_usb_reset(ahcd); - admhc_intr_disable(ahcd, ~0); + admhc_intr_disable(ahcd, ADMHC_INTR_MIE); free_irq(hcd->irq, hcd); hcd->irq = -1; @@ -720,7 +778,7 @@ static void admhc_stop(struct usb_hcd *hcd) /*-------------------------------------------------------------------------*/ -#ifdef CONFIG_MIPS_ADM5120 +#ifdef CONFIG_ADM5120 #include "adm5120-drv.c" #define PLATFORM_DRIVER usb_hcd_adm5120_driver #endif @@ -729,7 +787,7 @@ static void admhc_stop(struct usb_hcd *hcd) #error "missing bus glue for admhc-hcd" #endif -#define DRIVER_INFO DRIVER_DESC " " DRIVER_VERSION +#define DRIVER_INFO DRIVER_DESC " version " DRIVER_VERSION static int __init admhc_hcd_mod_init(void) { @@ -740,7 +798,15 @@ static int __init admhc_hcd_mod_init(void) pr_info("%s: " DRIVER_INFO "\n", hcd_name); pr_info("%s: block sizes: ed %Zd td %Zd\n", hcd_name, - sizeof (struct ed), sizeof (struct td)); + sizeof(struct ed), sizeof(struct td)); + +#ifdef DEBUG + admhc_debug_root = debugfs_create_dir("admhc", NULL); + if (!admhc_debug_root) { + ret = -ENOENT; + goto error_debug; + } +#endif #ifdef PLATFORM_DRIVER ret = platform_driver_register(&PLATFORM_DRIVER); @@ -753,6 +819,12 @@ static int __init admhc_hcd_mod_init(void) #ifdef PLATFORM_DRIVER platform_driver_unregister(&PLATFORM_DRIVER); error_platform: +#endif + +#ifdef DEBUG + debugfs_remove(admhc_debug_root); + admhc_debug_root = NULL; +error_debug: #endif return ret; } @@ -761,9 +833,13 @@ module_init(admhc_hcd_mod_init); static void __exit admhc_hcd_mod_exit(void) { platform_driver_unregister(&PLATFORM_DRIVER); +#ifdef DEBUG + debugfs_remove(admhc_debug_root); +#endif } module_exit(admhc_hcd_mod_exit); MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_INFO); -MODULE_LICENSE("GPL"); +MODULE_VERSION(DRIVER_VERSION); +MODULE_LICENSE("GPL v2");