X-Git-Url: http://git.rohieb.name/openwrt.git/blobdiff_plain/15331876847019b1a3cdec43dcc19073b6b41dd2..59dc59994cc0f7837e5cb8a6982d7cef06e5ce87:/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 3365a1d0a..2d2604aa7 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 @@ -45,14 +45,13 @@ #include "../core/hcd.h" #include "../core/hub.h" -#define DRIVER_VERSION "v0.01" +#define DRIVER_VERSION "0.16.3" #define DRIVER_AUTHOR "Gabor Juhos " #define DRIVER_DESC "ADMtek USB 1.1 Host Controller Driver" /*-------------------------------------------------------------------------*/ -#define ADMHC_VERBOSE_DEBUG /* not always helpful */ -#undef LATE_ED_SCHEDULE +#undef ADMHC_VERBOSE_DEBUG /* not always helpful */ /* For initializing controller (mask in an HCFS mode too) */ #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR @@ -73,9 +72,10 @@ static void admhc_dump(struct admhcd *ahcd, int verbose); static int admhc_init(struct admhcd *ahcd); static void admhc_stop(struct usb_hcd *hcd); -#include "adm5120-hub.c" #include "adm5120-dbg.c" #include "adm5120-mem.c" +#include "adm5120-pm.c" +#include "adm5120-hub.c" #include "adm5120-q.c" /*-------------------------------------------------------------------------*/ @@ -90,12 +90,14 @@ static int admhc_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *ep, struct ed *ed; struct urb_priv *urb_priv; unsigned int pipe = urb->pipe; - int i, td_cnt = 0; + int td_cnt = 0; unsigned long flags; - int retval = 0; + int ret = 0; #ifdef ADMHC_VERBOSE_DEBUG - urb_print(urb, "ENQ", usb_pipein(pipe)); + spin_lock_irqsave(&ahcd->lock, flags); + urb_print(ahcd, urb, "ENQEUE", usb_pipein(pipe)); + spin_unlock_irqrestore(&ahcd->lock, flags); #endif /* every endpoint has an ed, locate and maybe (re)initialize it */ @@ -140,10 +142,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); @@ -155,11 +153,11 @@ static int admhc_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *ep, spin_lock_irqsave(&ahcd->lock, flags); /* don't submit to a dead HC */ if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { - retval = -ENODEV; + ret = -ENODEV; goto fail; } if (!HC_IS_RUNNING(hcd->state)) { - retval = -ENODEV; + ret = -ENODEV; goto fail; } @@ -169,17 +167,16 @@ static int admhc_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *ep, spin_unlock(&urb->lock); urb->hcpriv = urb_priv; finish_urb(ahcd, urb); - retval = 0; + ret = 0; goto fail; } /* schedule the ed if needed */ if (ed->state == ED_IDLE) { -#ifndef LATE_ED_SCHEDULE - retval = ed_schedule(ahcd, ed); - if (retval < 0) + ret = ed_schedule(ahcd, ed); + if (ret < 0) goto fail0; -#endif + if (ed->type == PIPE_ISOCHRONOUS) { u16 frame = admhc_frame_no(ahcd); @@ -203,21 +200,18 @@ static int admhc_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *ep, urb->hcpriv = urb_priv; td_submit_urb(ahcd, urb); -#ifdef LATE_ED_SCHEDULE - if (ed->state == ED_IDLE) - retval = ed_schedule(ahcd, ed); -#endif - +#ifdef ADMHC_VERBOSE_DEBUG admhc_dump_ed(ahcd, "admhc_urb_enqueue", urb_priv->ed, 1); +#endif fail0: spin_unlock(&urb->lock); fail: - if (retval) + if (ret) urb_priv_free(ahcd, urb_priv); spin_unlock_irqrestore(&ahcd->lock, flags); - return retval; + return ret; } /* @@ -228,14 +222,15 @@ fail: */ static int admhc_urb_dequeue(struct usb_hcd *hcd, struct urb *urb) { - struct admhcd *ahcd = hcd_to_admhcd(hcd); - unsigned long flags; + struct admhcd *ahcd = hcd_to_admhcd(hcd); + unsigned long flags; + + spin_lock_irqsave(&ahcd->lock, flags); #ifdef ADMHC_VERBOSE_DEBUG - urb_print(urb, "DEQ", 1); + urb_print(ahcd, urb, "DEQUEUE", 1); #endif - spin_lock_irqsave(&ahcd->lock, flags); if (HC_IS_RUNNING(hcd->state)) { struct urb_priv *urb_priv; @@ -267,8 +262,8 @@ static int admhc_urb_dequeue(struct usb_hcd *hcd, struct urb *urb) * including ED memory, dummy TD, and bulk/intr data toggle */ -static void -admhc_endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep) +static void admhc_endpoint_disable(struct usb_hcd *hcd, + struct usb_host_endpoint *ep) { struct admhcd *ahcd = hcd_to_admhcd(hcd); unsigned long flags; @@ -283,7 +278,7 @@ admhc_endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep) #ifdef ADMHC_VERBOSE_DEBUG spin_lock_irqsave(&ahcd->lock, flags); - admhc_dump_ed(ahcd, "ep_disable", ed, 1); + admhc_dump_ed(ahcd, "EP-DISABLE", ed, 1); spin_unlock_irqrestore(&ahcd->lock, flags); #endif @@ -323,12 +318,14 @@ sanitize: td_free(ahcd, ed->dummy); break; } + ep->hcpriv = NULL; + spin_unlock_irqrestore(&ahcd->lock, flags); return; } -static int admhc_get_frame(struct usb_hcd *hcd) +static int admhc_get_frame_number(struct usb_hcd *hcd) { struct admhcd *ahcd = hcd_to_admhcd(hcd); @@ -464,7 +461,7 @@ static int admhc_init(struct admhcd *ahcd) /* Read the number of ports unless overridden */ if (ahcd->num_ports == 0) - ahcd->num_ports = admhc_get_rhdesc(ahcd) & ADMHC_RH_NUMP; + ahcd->num_ports = admhc_read_rhdesc(ahcd) & ADMHC_RH_NUMP; ret = admhc_mem_init(ahcd); if (ret) @@ -506,7 +503,7 @@ static int admhc_run(struct admhcd *ahcd) admhc_dbg(ahcd, "fminterval delta %d\n", ahcd->fminterval - FI); ahcd->fminterval |= - (FSLDP (ahcd->fminterval) << ADMHC_SFI_FSLDP_SHIFT); + (FSLDP(ahcd->fminterval) << ADMHC_SFI_FSLDP_SHIFT); /* also: power/overcurrent flags in rhdesc */ } @@ -543,12 +540,11 @@ static int admhc_run(struct admhcd *ahcd) admhc_writel_flush(ahcd); msleep(temp); - temp = admhc_get_rhdesc(ahcd); + temp = admhc_read_rhdesc(ahcd); if (!(temp & ADMHC_RH_NPS)) { /* power down each port */ for (temp = 0; temp < ahcd->num_ports; temp++) - admhc_writel(ahcd, ADMHC_PS_CPP, - &ahcd->regs->portstatus[temp]); + admhc_write_portstatus(ahcd, temp, ADMHC_PS_CPP); } /* flush those writes */ admhc_writel_flush(ahcd); @@ -556,7 +552,6 @@ static int admhc_run(struct admhcd *ahcd) /* 2msec timelimit here means no irqs/preempt */ spin_lock_irq(&ahcd->lock); -retry: admhc_writel(ahcd, ADMHC_CTRL_SR, &ahcd->regs->gencontrol); temp = 30; /* ... allow extra time */ while ((admhc_readl(ahcd, &ahcd->regs->gencontrol) & ADMHC_CTRL_SR) != 0) { @@ -565,7 +560,7 @@ retry: admhc_err(ahcd, "USB HC reset timed out!\n"); return -1; } - udelay (1); + udelay(1); } /* enable HOST mode, before access any host specific register */ @@ -666,6 +661,12 @@ static irqreturn_t admhc_irq(struct usb_hcd *hcd) admhc_usb_reset(ahcd); } + if (ints & ADMHC_INTR_BABI) { + admhc_intr_disable(ahcd, ADMHC_INTR_BABI); + admhc_intr_ack(ahcd, ADMHC_INTR_BABI); + admhc_err(ahcd, "Babble Detected\n"); + } + if (ints & ADMHC_INTR_INSM) { admhc_vdbg(ahcd, "Root Hub Status Change\n"); ahcd->next_statechange = jiffies + STATECHANGE_DELAY; @@ -714,12 +715,6 @@ static irqreturn_t admhc_irq(struct usb_hcd *hcd) admhc_vdbg(ahcd, "Schedule Overrun\n"); } - if (ints & ADMHC_INTR_BABI) { - admhc_intr_disable(ahcd, ADMHC_INTR_BABI); - admhc_intr_ack(ahcd, ADMHC_INTR_BABI); - admhc_err(ahcd, "Babble Detected\n"); - } - #if 1 spin_lock(&ahcd->lock); if (ahcd->ed_rm_list) @@ -784,87 +779,6 @@ static void admhc_stop(struct usb_hcd *hcd) /*-------------------------------------------------------------------------*/ -/* must not be called from interrupt context */ - -#ifdef CONFIG_PM - -static int admhc_restart(struct admhcd *ahcd) -{ - int temp; - int i; - struct urb_priv *priv; - - /* mark any devices gone, so they do nothing till khubd disconnects. - * recycle any "live" eds/tds (and urbs) right away. - * later, khubd disconnect processing will recycle the other state, - * (either as disconnect/reconnect, or maybe someday as a reset). - */ - spin_lock_irq(&ahcd->lock); - admhc_disable(ahcd); - usb_root_hub_lost_power(admhcd_to_hcd(ahcd)->self.root_hub); - if (!list_empty(&ahcd->pending)) - admhc_dbg(ahcd, "abort schedule...\n"); - list_for_each_entry (priv, &ahcd->pending, pending) { - struct urb *urb = priv->td[0]->urb; - struct ed *ed = priv->ed; - - switch (ed->state) { - case ED_OPER: - ed->state = ED_UNLINK; - ed->hwINFO |= cpu_to_hc32(ahcd, ED_DEQUEUE); - ed_deschedule (ahcd, ed); - - ed->ed_next = ahcd->ed_rm_list; - ed->ed_prev = NULL; - ahcd->ed_rm_list = ed; - /* FALLTHROUGH */ - case ED_UNLINK: - break; - default: - admhc_dbg(ahcd, "bogus ed %p state %d\n", - ed, ed->state); - } - - spin_lock(&urb->lock); - urb->status = -ESHUTDOWN; - spin_unlock(&urb->lock); - } - finish_unlinks (ahcd, 0); - spin_unlock_irq(&ahcd->lock); - - /* paranoia, in case that didn't work: */ - - /* empty the interrupt branches */ - for (i = 0; i < NUM_INTS; i++) ahcd->load[i] = 0; - for (i = 0; i < NUM_INTS; i++) ahcd->hcca->int_table[i] = 0; - - /* no EDs to remove */ - ahcd->ed_rm_list = NULL; - - /* empty control and bulk lists */ - ahcd->ed_controltail = NULL; - ahcd->ed_bulktail = NULL; - - if ((temp = admhc_run(ahcd)) < 0) { - admhc_err(ahcd, "can't restart, %d\n", temp); - return temp; - } else { - /* here we "know" root ports should always stay powered, - * and that if we try to turn them back on the root hub - * will respond to CSC processing. - */ - i = ahcd->num_ports; - while (i--) - admhc_writel(ahcd, RH_PS_PSS, - &ahcd->regs->portstatus[i]); - admhc_dbg(ahcd, "restart complete\n"); - } - return 0; -} -#endif - -/*-------------------------------------------------------------------------*/ - #ifdef CONFIG_MIPS_ADM5120 #include "adm5120-drv.c" #define PLATFORM_DRIVER usb_hcd_adm5120_driver @@ -874,11 +788,11 @@ static int admhc_restart(struct admhcd *ahcd) #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) { - int retval = 0; + int ret = 0; if (usb_disabled()) return -ENODEV; @@ -888,18 +802,18 @@ static int __init admhc_hcd_mod_init(void) sizeof (struct ed), sizeof (struct td)); #ifdef PLATFORM_DRIVER - retval = platform_driver_register(&PLATFORM_DRIVER); - if (retval < 0) + ret = platform_driver_register(&PLATFORM_DRIVER); + if (ret < 0) goto error_platform; #endif - return retval; + return ret; #ifdef PLATFORM_DRIVER platform_driver_unregister(&PLATFORM_DRIVER); error_platform: #endif - return retval; + return ret; } module_init(admhc_hcd_mod_init); @@ -911,4 +825,5 @@ 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");