Commit 236dd4d1 authored by Anton Vorontsov's avatar Anton Vorontsov Committed by Greg Kroah-Hartman

USB: Driver for Freescale QUICC Engine USB Host Controller

This patch adds support for the FHCI USB controller, as found
in the Freescale MPC836x and MPC832x processors. It can support
Full or Low speed modes.

Quite a lot the hardware is doing by itself (SOF generation, CRC
generation and checking), though scheduling and retransmission is on
software's shoulders.

This controller does not integrate the root hub, so this driver also
fakes one-port hub. External hub is required to support more than
one device.
Signed-off-by: default avatarAnton Vorontsov <avorontsov@ru.mvista.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent fc91be2a
...@@ -13,6 +13,7 @@ obj-$(CONFIG_USB_EHCI_HCD) += host/ ...@@ -13,6 +13,7 @@ obj-$(CONFIG_USB_EHCI_HCD) += host/
obj-$(CONFIG_USB_ISP116X_HCD) += host/ obj-$(CONFIG_USB_ISP116X_HCD) += host/
obj-$(CONFIG_USB_OHCI_HCD) += host/ obj-$(CONFIG_USB_OHCI_HCD) += host/
obj-$(CONFIG_USB_UHCI_HCD) += host/ obj-$(CONFIG_USB_UHCI_HCD) += host/
obj-$(CONFIG_USB_FHCI_HCD) += host/
obj-$(CONFIG_USB_SL811_HCD) += host/ obj-$(CONFIG_USB_SL811_HCD) += host/
obj-$(CONFIG_USB_U132_HCD) += host/ obj-$(CONFIG_USB_U132_HCD) += host/
obj-$(CONFIG_USB_R8A66597_HCD) += host/ obj-$(CONFIG_USB_R8A66597_HCD) += host/
......
...@@ -239,6 +239,23 @@ config USB_UHCI_HCD ...@@ -239,6 +239,23 @@ config USB_UHCI_HCD
To compile this driver as a module, choose M here: the To compile this driver as a module, choose M here: the
module will be called uhci-hcd. module will be called uhci-hcd.
config USB_FHCI_HCD
tristate "Freescale QE USB Host Controller support"
depends on USB && OF_GPIO && QE_GPIO && QUICC_ENGINE
select FSL_GTM
select QE_USB
help
This driver enables support for Freescale QE USB Host Controller
(as found on MPC8360 and MPC8323 processors), the driver supports
Full and Low Speed USB.
config FHCI_DEBUG
bool "Freescale QE USB Host Controller debug support"
depends on USB_FHCI_HCD && DEBUG_FS
help
Say "y" to see some FHCI debug information and statistics
throught debugfs.
config USB_U132_HCD config USB_U132_HCD
tristate "Elan U132 Adapter Host Controller" tristate "Elan U132 Adapter Host Controller"
depends on USB && USB_FTDI_ELAN depends on USB && USB_FTDI_ELAN
......
...@@ -7,6 +7,11 @@ ifeq ($(CONFIG_USB_DEBUG),y) ...@@ -7,6 +7,11 @@ ifeq ($(CONFIG_USB_DEBUG),y)
endif endif
isp1760-objs := isp1760-hcd.o isp1760-if.o isp1760-objs := isp1760-hcd.o isp1760-if.o
fhci-objs := fhci-hcd.o fhci-hub.o fhci-q.o fhci-mem.o \
fhci-tds.o fhci-sched.o
ifeq ($(CONFIG_FHCI_DEBUG),y)
fhci-objs += fhci-dbg.o
endif
obj-$(CONFIG_USB_WHCI_HCD) += whci/ obj-$(CONFIG_USB_WHCI_HCD) += whci/
...@@ -17,6 +22,7 @@ obj-$(CONFIG_USB_OXU210HP_HCD) += oxu210hp-hcd.o ...@@ -17,6 +22,7 @@ obj-$(CONFIG_USB_OXU210HP_HCD) += oxu210hp-hcd.o
obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o
obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o
obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o
obj-$(CONFIG_USB_FHCI_HCD) += fhci.o
obj-$(CONFIG_USB_SL811_HCD) += sl811-hcd.o obj-$(CONFIG_USB_SL811_HCD) += sl811-hcd.o
obj-$(CONFIG_USB_SL811_CS) += sl811_cs.o obj-$(CONFIG_USB_SL811_CS) += sl811_cs.o
obj-$(CONFIG_USB_U132_HCD) += u132-hcd.o obj-$(CONFIG_USB_U132_HCD) += u132-hcd.o
......
/*
* Freescale QUICC Engine USB Host Controller Driver
*
* Copyright (c) Freescale Semicondutor, Inc. 2006.
* Shlomi Gridish <gridish@freescale.com>
* Jerry Huang <Chang-Ming.Huang@freescale.com>
* Copyright (c) Logic Product Development, Inc. 2007
* Peter Barada <peterb@logicpd.com>
* Copyright (c) MontaVista Software, Inc. 2008.
* Anton Vorontsov <avorontsov@ru.mvista.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*/
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/debugfs.h>
#include <linux/seq_file.h>
#include <linux/usb.h>
#include "../core/hcd.h"
#include "fhci.h"
void fhci_dbg_isr(struct fhci_hcd *fhci, int usb_er)
{
int i;
if (usb_er == -1) {
fhci->usb_irq_stat[12]++;
return;
}
for (i = 0; i < 12; ++i) {
if (usb_er & (1 << i))
fhci->usb_irq_stat[i]++;
}
}
static int fhci_dfs_regs_show(struct seq_file *s, void *v)
{
struct fhci_hcd *fhci = s->private;
struct fhci_regs __iomem *regs = fhci->regs;
seq_printf(s,
"mode: 0x%x\n" "addr: 0x%x\n"
"command: 0x%x\n" "ep0: 0x%x\n"
"event: 0x%x\n" "mask: 0x%x\n"
"status: 0x%x\n" "SOF timer: %d\n"
"frame number: %d\n"
"lines status: 0x%x\n",
in_8(&regs->usb_mod), in_8(&regs->usb_addr),
in_8(&regs->usb_comm), in_be16(&regs->usb_ep[0]),
in_be16(&regs->usb_event), in_be16(&regs->usb_mask),
in_8(&regs->usb_status), in_be16(&regs->usb_sof_tmr),
in_be16(&regs->usb_frame_num),
fhci_ioports_check_bus_state(fhci));
return 0;
}
static int fhci_dfs_irq_stat_show(struct seq_file *s, void *v)
{
struct fhci_hcd *fhci = s->private;
int *usb_irq_stat = fhci->usb_irq_stat;
seq_printf(s,
"RXB: %d\n" "TXB: %d\n" "BSY: %d\n"
"SOF: %d\n" "TXE0: %d\n" "TXE1: %d\n"
"TXE2: %d\n" "TXE3: %d\n" "IDLE: %d\n"
"RESET: %d\n" "SFT: %d\n" "MSF: %d\n"
"IDLE_ONLY: %d\n",
usb_irq_stat[0], usb_irq_stat[1], usb_irq_stat[2],
usb_irq_stat[3], usb_irq_stat[4], usb_irq_stat[5],
usb_irq_stat[6], usb_irq_stat[7], usb_irq_stat[8],
usb_irq_stat[9], usb_irq_stat[10], usb_irq_stat[11],
usb_irq_stat[12]);
return 0;
}
static int fhci_dfs_regs_open(struct inode *inode, struct file *file)
{
return single_open(file, fhci_dfs_regs_show, inode->i_private);
}
static int fhci_dfs_irq_stat_open(struct inode *inode, struct file *file)
{
return single_open(file, fhci_dfs_irq_stat_show, inode->i_private);
}
static const struct file_operations fhci_dfs_regs_fops = {
.open = fhci_dfs_regs_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static const struct file_operations fhci_dfs_irq_stat_fops = {
.open = fhci_dfs_irq_stat_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
void fhci_dfs_create(struct fhci_hcd *fhci)
{
struct device *dev = fhci_to_hcd(fhci)->self.controller;
fhci->dfs_root = debugfs_create_dir(dev->bus_id, NULL);
if (!fhci->dfs_root) {
WARN_ON(1);
return;
}
fhci->dfs_regs = debugfs_create_file("regs", S_IFREG | S_IRUGO,
fhci->dfs_root, fhci, &fhci_dfs_regs_fops);
fhci->dfs_irq_stat = debugfs_create_file("irq_stat",
S_IFREG | S_IRUGO, fhci->dfs_root, fhci,
&fhci_dfs_irq_stat_fops);
WARN_ON(!fhci->dfs_regs || !fhci->dfs_irq_stat);
}
void fhci_dfs_destroy(struct fhci_hcd *fhci)
{
if (!fhci->dfs_root)
return;
if (fhci->dfs_irq_stat)
debugfs_remove(fhci->dfs_irq_stat);
if (fhci->dfs_regs)
debugfs_remove(fhci->dfs_regs);
debugfs_remove(fhci->dfs_root);
}
This diff is collapsed.
/*
* Freescale QUICC Engine USB Host Controller Driver
*
* Copyright (c) Freescale Semicondutor, Inc. 2006.
* Shlomi Gridish <gridish@freescale.com>
* Jerry Huang <Chang-Ming.Huang@freescale.com>
* Copyright (c) Logic Product Development, Inc. 2007
* Peter Barada <peterb@logicpd.com>
* Copyright (c) MontaVista Software, Inc. 2008.
* Anton Vorontsov <avorontsov@ru.mvista.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*/
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/spinlock.h>
#include <linux/delay.h>
#include <linux/errno.h>
#include <linux/io.h>
#include <linux/usb.h>
#include <linux/gpio.h>
#include <asm/qe.h>
#include "../core/hcd.h"
#include "fhci.h"
/* virtual root hub specific descriptor */
static u8 root_hub_des[] = {
0x09, /* blength */
0x29, /* bDescriptorType;hub-descriptor */
0x01, /* bNbrPorts */
0x00, /* wHubCharacteristics */
0x00,
0x01, /* bPwrOn2pwrGood;2ms */
0x00, /* bHubContrCurrent;0mA */
0x00, /* DeviceRemoveable */
0xff, /* PortPwrCtrlMask */
};
static void fhci_gpio_set_value(struct fhci_hcd *fhci, int gpio_nr, bool on)
{
int gpio = fhci->gpios[gpio_nr];
bool alow = fhci->alow_gpios[gpio_nr];
if (!gpio_is_valid(gpio))
return;
gpio_set_value(gpio, on ^ alow);
mdelay(5);
}
void fhci_config_transceiver(struct fhci_hcd *fhci,
enum fhci_port_status status)
{
fhci_dbg(fhci, "-> %s: %d\n", __func__, status);
switch (status) {
case FHCI_PORT_POWER_OFF:
fhci_gpio_set_value(fhci, GPIO_POWER, false);
break;
case FHCI_PORT_DISABLED:
case FHCI_PORT_WAITING:
fhci_gpio_set_value(fhci, GPIO_POWER, true);
break;
case FHCI_PORT_LOW:
fhci_gpio_set_value(fhci, GPIO_SPEED, false);
break;
case FHCI_PORT_FULL:
fhci_gpio_set_value(fhci, GPIO_SPEED, true);
break;
default:
WARN_ON(1);
break;
}
fhci_dbg(fhci, "<- %s: %d\n", __func__, status);
}
/* disable the USB port by clearing the EN bit in the USBMOD register */
void fhci_port_disable(struct fhci_hcd *fhci)
{
struct fhci_usb *usb = (struct fhci_usb *)fhci->usb_lld;
enum fhci_port_status port_status;
fhci_dbg(fhci, "-> %s\n", __func__);
fhci_stop_sof_timer(fhci);
fhci_flush_all_transmissions(usb);
fhci_usb_disable_interrupt((struct fhci_usb *)fhci->usb_lld);
port_status = usb->port_status;
usb->port_status = FHCI_PORT_DISABLED;
/* Enable IDLE since we want to know if something comes along */
usb->saved_msk |= USB_E_IDLE_MASK;
out_be16(&usb->fhci->regs->usb_mask, usb->saved_msk);
/* check if during the disconnection process attached new device */
if (port_status == FHCI_PORT_WAITING)
fhci_device_connected_interrupt(fhci);
usb->vroot_hub->port.wPortStatus &= ~USB_PORT_STAT_ENABLE;
usb->vroot_hub->port.wPortChange |= USB_PORT_STAT_C_ENABLE;
fhci_usb_enable_interrupt((struct fhci_usb *)fhci->usb_lld);
fhci_dbg(fhci, "<- %s\n", __func__);
}
/* enable the USB port by setting the EN bit in the USBMOD register */
void fhci_port_enable(void *lld)
{
struct fhci_usb *usb = (struct fhci_usb *)lld;
struct fhci_hcd *fhci = usb->fhci;
fhci_dbg(fhci, "-> %s\n", __func__);
fhci_config_transceiver(fhci, usb->port_status);
if ((usb->port_status != FHCI_PORT_FULL) &&
(usb->port_status != FHCI_PORT_LOW))
fhci_start_sof_timer(fhci);
usb->vroot_hub->port.wPortStatus |= USB_PORT_STAT_ENABLE;
usb->vroot_hub->port.wPortChange |= USB_PORT_STAT_C_ENABLE;
fhci_dbg(fhci, "<- %s\n", __func__);
}
void fhci_io_port_generate_reset(struct fhci_hcd *fhci)
{
fhci_dbg(fhci, "-> %s\n", __func__);
gpio_direction_output(fhci->gpios[GPIO_USBOE], 0);
gpio_direction_output(fhci->gpios[GPIO_USBTP], 0);
gpio_direction_output(fhci->gpios[GPIO_USBTN], 0);
mdelay(5);
qe_pin_set_dedicated(fhci->pins[PIN_USBOE]);
qe_pin_set_dedicated(fhci->pins[PIN_USBTP]);
qe_pin_set_dedicated(fhci->pins[PIN_USBTN]);
fhci_dbg(fhci, "<- %s\n", __func__);
}
/* generate the RESET condition on the bus */
void fhci_port_reset(void *lld)
{
struct fhci_usb *usb = (struct fhci_usb *)lld;
struct fhci_hcd *fhci = usb->fhci;
u8 mode;
u16 mask;
fhci_dbg(fhci, "-> %s\n", __func__);
fhci_stop_sof_timer(fhci);
/* disable the USB controller */
mode = in_8(&fhci->regs->usb_mod);
out_8(&fhci->regs->usb_mod, mode & (~USB_MODE_EN));
/* disable idle interrupts */
mask = in_be16(&fhci->regs->usb_mask);
out_be16(&fhci->regs->usb_mask, mask & (~USB_E_IDLE_MASK));
fhci_io_port_generate_reset(fhci);
/* enable interrupt on this endpoint */
out_be16(&fhci->regs->usb_mask, mask);
/* enable the USB controller */
mode = in_8(&fhci->regs->usb_mod);
out_8(&fhci->regs->usb_mod, mode | USB_MODE_EN);
fhci_start_sof_timer(fhci);
fhci_dbg(fhci, "<- %s\n", __func__);
}
int fhci_hub_status_data(struct usb_hcd *hcd, char *buf)
{
struct fhci_hcd *fhci = hcd_to_fhci(hcd);
int ret = 0;
unsigned long flags;
fhci_dbg(fhci, "-> %s\n", __func__);
spin_lock_irqsave(&fhci->lock, flags);
if (fhci->vroot_hub->port.wPortChange & (USB_PORT_STAT_C_CONNECTION |
USB_PORT_STAT_C_ENABLE | USB_PORT_STAT_C_SUSPEND |
USB_PORT_STAT_C_RESET | USB_PORT_STAT_C_OVERCURRENT)) {
*buf = 1 << 1;
ret = 1;
fhci_dbg(fhci, "-- %s\n", __func__);
}
spin_unlock_irqrestore(&fhci->lock, flags);
fhci_dbg(fhci, "<- %s\n", __func__);
return ret;
}
int fhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
u16 wIndex, char *buf, u16 wLength)
{
struct fhci_hcd *fhci = hcd_to_fhci(hcd);
int retval = 0;
int len = 0;
struct usb_hub_status *hub_status;
struct usb_port_status *port_status;
unsigned long flags;
spin_lock_irqsave(&fhci->lock, flags);
fhci_dbg(fhci, "-> %s\n", __func__);
switch (typeReq) {
case ClearHubFeature:
switch (wValue) {
case C_HUB_LOCAL_POWER:
case C_HUB_OVER_CURRENT:
break;
default:
goto error;
}
break;
case ClearPortFeature:
fhci->vroot_hub->feature &= (1 << wValue);
switch (wValue) {
case USB_PORT_FEAT_ENABLE:
fhci->vroot_hub->port.wPortStatus &=
~USB_PORT_STAT_ENABLE;
fhci_port_disable(fhci);
break;
case USB_PORT_FEAT_C_ENABLE:
fhci->vroot_hub->port.wPortChange &=
~USB_PORT_STAT_C_ENABLE;
break;
case USB_PORT_FEAT_SUSPEND:
fhci->vroot_hub->port.wPortStatus &=
~USB_PORT_STAT_SUSPEND;
fhci_stop_sof_timer(fhci);
break;
case USB_PORT_FEAT_C_SUSPEND:
fhci->vroot_hub->port.wPortChange &=
~USB_PORT_STAT_C_SUSPEND;
break;
case USB_PORT_FEAT_POWER:
fhci->vroot_hub->port.wPortStatus &=
~USB_PORT_STAT_POWER;
fhci_config_transceiver(fhci, FHCI_PORT_POWER_OFF);
break;
case USB_PORT_FEAT_C_CONNECTION:
fhci->vroot_hub->port.wPortChange &=
~USB_PORT_STAT_C_CONNECTION;
break;
case USB_PORT_FEAT_C_OVER_CURRENT:
fhci->vroot_hub->port.wPortChange &=
~USB_PORT_STAT_C_OVERCURRENT;
break;
case USB_PORT_FEAT_C_RESET:
fhci->vroot_hub->port.wPortChange &=
~USB_PORT_STAT_C_RESET;
break;
default:
goto error;
}
break;
case GetHubDescriptor:
memcpy(buf, root_hub_des, sizeof(root_hub_des));
buf[3] = 0x11; /* per-port power, no ovrcrnt */
len = (buf[0] < wLength) ? buf[0] : wLength;
break;
case GetHubStatus:
hub_status = (struct usb_hub_status *)buf;
hub_status->wHubStatus =
cpu_to_le16(fhci->vroot_hub->hub.wHubStatus);
hub_status->wHubChange =
cpu_to_le16(fhci->vroot_hub->hub.wHubChange);
len = 4;
break;
case GetPortStatus:
port_status = (struct usb_port_status *)buf;
port_status->wPortStatus =
cpu_to_le16(fhci->vroot_hub->port.wPortStatus);
port_status->wPortChange =
cpu_to_le16(fhci->vroot_hub->port.wPortChange);
len = 4;
break;
case SetHubFeature:
switch (wValue) {
case C_HUB_OVER_CURRENT:
case C_HUB_LOCAL_POWER:
break;
default:
goto error;
}
break;
case SetPortFeature:
fhci->vroot_hub->feature |= (1 << wValue);
switch (wValue) {
case USB_PORT_FEAT_ENABLE:
fhci->vroot_hub->port.wPortStatus |=
USB_PORT_STAT_ENABLE;
fhci_port_enable(fhci->usb_lld);
break;
case USB_PORT_FEAT_SUSPEND:
fhci->vroot_hub->port.wPortStatus |=
USB_PORT_STAT_SUSPEND;
fhci_stop_sof_timer(fhci);
break;
case USB_PORT_FEAT_RESET:
fhci->vroot_hub->port.wPortStatus |=
USB_PORT_STAT_RESET;
fhci_port_reset(fhci->usb_lld);
fhci->vroot_hub->port.wPortStatus |=
USB_PORT_STAT_ENABLE;
fhci->vroot_hub->port.wPortStatus &=
~USB_PORT_STAT_RESET;
break;
case USB_PORT_FEAT_POWER:
fhci->vroot_hub->port.wPortStatus |=
USB_PORT_STAT_POWER;
fhci_config_transceiver(fhci, FHCI_PORT_WAITING);
break;
default:
goto error;
}
break;
default:
error:
retval = -EPIPE;
}
fhci_dbg(fhci, "<- %s\n", __func__);
spin_unlock_irqrestore(&fhci->lock, flags);
return retval;
}
/*
* Freescale QUICC Engine USB Host Controller Driver
*
* Copyright (c) Freescale Semicondutor, Inc. 2006.
* Shlomi Gridish <gridish@freescale.com>
* Jerry Huang <Chang-Ming.Huang@freescale.com>
* Copyright (c) Logic Product Development, Inc. 2007
* Peter Barada <peterb@logicpd.com>
* Copyright (c) MontaVista Software, Inc. 2008.
* Anton Vorontsov <avorontsov@ru.mvista.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*/
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/list.h>
#include <linux/usb.h>
#include "../core/hcd.h"
#include "fhci.h"
static void init_td(struct td *td)
{
memset(td, 0, sizeof(*td));
INIT_LIST_HEAD(&td->node);
INIT_LIST_HEAD(&td->frame_lh);
}
static void init_ed(struct ed *ed)
{
memset(ed, 0, sizeof(*ed));
INIT_LIST_HEAD(&ed->td_list);
INIT_LIST_HEAD(&ed->node);
}
static struct td *get_empty_td(struct fhci_hcd *fhci)
{
struct td *td;
if (!list_empty(&fhci->empty_tds)) {
td = list_entry(fhci->empty_tds.next, struct td, node);
list_del(fhci->empty_tds.next);
} else {
td = kmalloc(sizeof(*td), GFP_ATOMIC);
if (!td)
fhci_err(fhci, "No memory to allocate to TD\n");
else
init_td(td);
}
return td;
}
void fhci_recycle_empty_td(struct fhci_hcd *fhci, struct td *td)
{
init_td(td);
list_add(&td->node, &fhci->empty_tds);
}
struct ed *fhci_get_empty_ed(struct fhci_hcd *fhci)
{
struct ed *ed;
if (!list_empty(&fhci->empty_eds)) {
ed = list_entry(fhci->empty_eds.next, struct ed, node);
list_del(fhci->empty_eds.next);
} else {
ed = kmalloc(sizeof(*ed), GFP_ATOMIC);
if (!ed)
fhci_err(fhci, "No memory to allocate to ED\n");
else
init_ed(ed);
}
return ed;
}
void fhci_recycle_empty_ed(struct fhci_hcd *fhci, struct ed *ed)
{
init_ed(ed);
list_add(&ed->node, &fhci->empty_eds);
}
struct td *fhci_td_fill(struct fhci_hcd *fhci, struct urb *urb,
struct urb_priv *urb_priv, struct ed *ed, u16 index,
enum fhci_ta_type type, int toggle, u8 *data, u32 len,
u16 interval, u16 start_frame, bool ioc)
{
struct td *td = get_empty_td(fhci);
if (!td)
return NULL;
td->urb = urb;
td->ed = ed;
td->type = type;
td->toggle = toggle;
td->data = data;
td->len = len;
td->iso_index = index;
td->interval = interval;
td->start_frame = start_frame;
td->ioc = ioc;
td->status = USB_TD_OK;
urb_priv->tds[index] = td;
return td;
}
/*
* Freescale QUICC Engine USB Host Controller Driver
*
* Copyright (c) Freescale Semicondutor, Inc. 2006.
* Shlomi Gridish <gridish@freescale.com>
* Jerry Huang <Chang-Ming.Huang@freescale.com>
* Copyright (c) Logic Product Development, Inc. 2007
* Peter Barada <peterb@logicpd.com>
* Copyright (c) MontaVista Software, Inc. 2008.
* Anton Vorontsov <avorontsov@ru.mvista.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*/
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/spinlock.h>
#include <linux/errno.h>
#include <linux/list.h>
#include <linux/usb.h>
#include "../core/hcd.h"
#include "fhci.h"
/* maps the hardware error code to the USB error code */
static int status_to_error(u32 status)
{
if (status == USB_TD_OK)
return 0;
else if (status & USB_TD_RX_ER_CRC)
return -EILSEQ;
else if (status & USB_TD_RX_ER_NONOCT)
return -EPROTO;
else if (status & USB_TD_RX_ER_OVERUN)
return -ECOMM;
else if (status & USB_TD_RX_ER_BITSTUFF)
return -EPROTO;
else if (status & USB_TD_RX_ER_PID)
return -EILSEQ;
else if (status & (USB_TD_TX_ER_NAK | USB_TD_TX_ER_TIMEOUT))
return -ETIMEDOUT;
else if (status & USB_TD_TX_ER_STALL)
return -EPIPE;
else if (status & USB_TD_TX_ER_UNDERUN)
return -ENOSR;
else if (status & USB_TD_RX_DATA_UNDERUN)
return -EREMOTEIO;
else if (status & USB_TD_RX_DATA_OVERUN)
return -EOVERFLOW;
else
return -EINVAL;
}
void fhci_add_td_to_frame(struct fhci_time_frame *frame, struct td *td)
{
list_add_tail(&td->frame_lh, &frame->tds_list);
}
void fhci_add_tds_to_ed(struct ed *ed, struct td **td_list, int number)
{
int i;
for (i = 0; i < number; i++) {
struct td *td = td_list[i];
list_add_tail(&td->node, &ed->td_list);
}
if (ed->td_head == NULL)
ed->td_head = td_list[0];
}
static struct td *peek_td_from_ed(struct ed *ed)
{
struct td *td;
if (!list_empty(&ed->td_list))
td = list_entry(ed->td_list.next, struct td, node);
else
td = NULL;
return td;
}
struct td *fhci_remove_td_from_frame(struct fhci_time_frame *frame)
{
struct td *td;
if (!list_empty(&frame->tds_list)) {
td = list_entry(frame->tds_list.next, struct td, frame_lh);
list_del_init(frame->tds_list.next);
} else
td = NULL;
return td;
}
struct td *fhci_peek_td_from_frame(struct fhci_time_frame *frame)
{
struct td *td;
if (!list_empty(&frame->tds_list))
td = list_entry(frame->tds_list.next, struct td, frame_lh);
else
td = NULL;
return td;
}
struct td *fhci_remove_td_from_ed(struct ed *ed)
{
struct td *td;
if (!list_empty(&ed->td_list)) {
td = list_entry(ed->td_list.next, struct td, node);
list_del_init(ed->td_list.next);
/* if this TD was the ED's head, find next TD */
if (!list_empty(&ed->td_list))
ed->td_head = list_entry(ed->td_list.next, struct td,
node);
else
ed->td_head = NULL;
} else
td = NULL;
return td;
}
struct td *fhci_remove_td_from_done_list(struct fhci_controller_list *p_list)
{
struct td *td;
if (!list_empty(&p_list->done_list)) {
td = list_entry(p_list->done_list.next, struct td, node);
list_del_init(p_list->done_list.next);
} else
td = NULL;
return td;
}
void fhci_move_td_from_ed_to_done_list(struct fhci_usb *usb, struct ed *ed)
{
struct td *td;
td = ed->td_head;
list_del_init(&td->node);
/* If this TD was the ED's head,find next TD */
if (!list_empty(&ed->td_list))
ed->td_head = list_entry(ed->td_list.next, struct td, node);
else {
ed->td_head = NULL;
ed->state = FHCI_ED_SKIP;
}
ed->toggle_carry = td->toggle;
list_add_tail(&td->node, &usb->hc_list->done_list);
if (td->ioc)
usb->transfer_confirm(usb->fhci);
}
/* free done FHCI URB resource such as ED and TD */
static void free_urb_priv(struct fhci_hcd *fhci, struct urb *urb)
{
int i;
struct urb_priv *urb_priv = urb->hcpriv;
struct ed *ed = urb_priv->ed;
for (i = 0; i < urb_priv->num_of_tds; i++) {
list_del_init(&urb_priv->tds[i]->node);
fhci_recycle_empty_td(fhci, urb_priv->tds[i]);
}
/* if this TD was the ED's head,find the next TD */
if (!list_empty(&ed->td_list))
ed->td_head = list_entry(ed->td_list.next, struct td, node);
else
ed->td_head = NULL;
kfree(urb_priv->tds);
kfree(urb_priv);
urb->hcpriv = NULL;
/* if this TD was the ED's head,find next TD */
if (ed->td_head == NULL)
list_del_init(&ed->node);
fhci->active_urbs--;
}
/* this routine called to complete and free done URB */
void fhci_urb_complete_free(struct fhci_hcd *fhci, struct urb *urb)
{
free_urb_priv(fhci, urb);
if (urb->status == -EINPROGRESS) {
if (urb->actual_length != urb->transfer_buffer_length &&
urb->transfer_flags & URB_SHORT_NOT_OK)
urb->status = -EREMOTEIO;
else
urb->status = 0;
}
usb_hcd_unlink_urb_from_ep(fhci_to_hcd(fhci), urb);
spin_unlock(&fhci->lock);
usb_hcd_giveback_urb(fhci_to_hcd(fhci), urb, urb->status);
spin_lock(&fhci->lock);
}
/*
* caculate transfer length/stats and update the urb
* Precondition: irqsafe(only for urb-?status locking)
*/
void fhci_done_td(struct urb *urb, struct td *td)
{
struct ed *ed = td->ed;
u32 cc = td->status;
/* ISO...drivers see per-TD length/status */
if (ed->mode == FHCI_TF_ISO) {
u32 len;
if (!(urb->transfer_flags & URB_SHORT_NOT_OK &&
cc == USB_TD_RX_DATA_UNDERUN))
cc = USB_TD_OK;
if (usb_pipeout(urb->pipe))
len = urb->iso_frame_desc[td->iso_index].length;
else
len = td->actual_len;
urb->actual_length += len;
urb->iso_frame_desc[td->iso_index].actual_length = len;
urb->iso_frame_desc[td->iso_index].status =
status_to_error(cc);
}
/* BULK,INT,CONTROL... drivers see aggregate length/status,
* except that "setup" bytes aren't counted and "short" transfers
* might not be reported as errors.
*/
else {
if (td->error_cnt >= 3)
urb->error_count = 3;
/* control endpoint only have soft stalls */
/* update packet status if needed(short may be ok) */
if (!(urb->transfer_flags & URB_SHORT_NOT_OK) &&
cc == USB_TD_RX_DATA_UNDERUN) {
ed->state = FHCI_ED_OPER;
cc = USB_TD_OK;
}
if (cc != USB_TD_OK) {
if (urb->status == -EINPROGRESS)
urb->status = status_to_error(cc);
}
/* count all non-empty packets except control SETUP packet */
if (td->type != FHCI_TA_SETUP || td->iso_index != 0)
urb->actual_length += td->actual_len;
}
}
/* there are some pedning request to unlink */
void fhci_del_ed_list(struct fhci_hcd *fhci, struct ed *ed)
{
struct td *td = peek_td_from_ed(ed);
struct urb *urb = td->urb;
struct urb_priv *urb_priv = urb->hcpriv;
if (urb_priv->state == URB_DEL) {
td = fhci_remove_td_from_ed(ed);
/* HC may have partly processed this TD */
if (td->status != USB_TD_INPROGRESS)
fhci_done_td(urb, td);
/* URB is done;clean up */
if (++(urb_priv->tds_cnt) == urb_priv->num_of_tds)
fhci_urb_complete_free(fhci, urb);
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment