2008-09-17 15:34:28 +00:00
|
|
|
/*
|
|
|
|
* Wireless Host Controller (WHC) driver.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Cambridge Silicon Radio Ltd.
|
|
|
|
*
|
|
|
|
* 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 program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
2011-07-03 20:09:31 +00:00
|
|
|
#include <linux/module.h>
|
2008-09-17 15:34:28 +00:00
|
|
|
#include <linux/uwb/umc.h>
|
|
|
|
|
|
|
|
#include "../../wusbcore/wusbhc.h"
|
|
|
|
|
|
|
|
#include "whcd.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* One time initialization.
|
|
|
|
*
|
|
|
|
* Nothing to do here.
|
|
|
|
*/
|
|
|
|
static int whc_reset(struct usb_hcd *usb_hcd)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start the wireless host controller.
|
|
|
|
*
|
|
|
|
* Start device notification.
|
|
|
|
*
|
|
|
|
* Put hc into run state, set DNTS parameters.
|
|
|
|
*/
|
|
|
|
static int whc_start(struct usb_hcd *usb_hcd)
|
|
|
|
{
|
|
|
|
struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
|
|
|
|
struct whc *whc = wusbhc_to_whc(wusbhc);
|
|
|
|
u8 bcid;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&wusbhc->mutex);
|
|
|
|
|
|
|
|
le_writel(WUSBINTR_GEN_CMD_DONE
|
|
|
|
| WUSBINTR_HOST_ERR
|
|
|
|
| WUSBINTR_ASYNC_SCHED_SYNCED
|
|
|
|
| WUSBINTR_DNTS_INT
|
|
|
|
| WUSBINTR_ERR_INT
|
|
|
|
| WUSBINTR_INT,
|
|
|
|
whc->base + WUSBINTR);
|
|
|
|
|
|
|
|
/* set cluster ID */
|
|
|
|
bcid = wusb_cluster_id_get();
|
|
|
|
ret = whc_set_cluster_id(whc, bcid);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
wusbhc->cluster_id = bcid;
|
|
|
|
|
|
|
|
/* start HC */
|
|
|
|
whc_write_wusbcmd(whc, WUSBCMD_RUN, WUSBCMD_RUN);
|
|
|
|
|
|
|
|
usb_hcd->uses_new_polling = 1;
|
2010-06-22 20:39:10 +00:00
|
|
|
set_bit(HCD_FLAG_POLL_RH, &usb_hcd->flags);
|
2008-09-17 15:34:28 +00:00
|
|
|
usb_hcd->state = HC_STATE_RUNNING;
|
|
|
|
|
|
|
|
out:
|
|
|
|
mutex_unlock(&wusbhc->mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop the wireless host controller.
|
|
|
|
*
|
|
|
|
* Stop device notification.
|
|
|
|
*
|
|
|
|
* Wait for pending transfer to stop? Put hc into stop state?
|
|
|
|
*/
|
|
|
|
static void whc_stop(struct usb_hcd *usb_hcd)
|
|
|
|
{
|
|
|
|
struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
|
|
|
|
struct whc *whc = wusbhc_to_whc(wusbhc);
|
|
|
|
|
|
|
|
mutex_lock(&wusbhc->mutex);
|
|
|
|
|
|
|
|
/* stop HC */
|
|
|
|
le_writel(0, whc->base + WUSBINTR);
|
|
|
|
whc_write_wusbcmd(whc, WUSBCMD_RUN, 0);
|
|
|
|
whci_wait_for(&whc->umc->dev, whc->base + WUSBSTS,
|
|
|
|
WUSBSTS_HCHALTED, WUSBSTS_HCHALTED,
|
|
|
|
100, "HC to halt");
|
|
|
|
|
|
|
|
wusb_cluster_id_put(wusbhc->cluster_id);
|
|
|
|
|
|
|
|
mutex_unlock(&wusbhc->mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int whc_get_frame_number(struct usb_hcd *usb_hcd)
|
|
|
|
{
|
|
|
|
/* Frame numbers are not applicable to WUSB. */
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Queue an URB to the ASL or PZL
|
|
|
|
*/
|
|
|
|
static int whc_urb_enqueue(struct usb_hcd *usb_hcd, struct urb *urb,
|
|
|
|
gfp_t mem_flags)
|
|
|
|
{
|
|
|
|
struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
|
|
|
|
struct whc *whc = wusbhc_to_whc(wusbhc);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
switch (usb_pipetype(urb->pipe)) {
|
|
|
|
case PIPE_INTERRUPT:
|
|
|
|
ret = pzl_urb_enqueue(whc, urb, mem_flags);
|
|
|
|
break;
|
|
|
|
case PIPE_ISOCHRONOUS:
|
|
|
|
dev_err(&whc->umc->dev, "isochronous transfers unsupported\n");
|
|
|
|
ret = -ENOTSUPP;
|
|
|
|
break;
|
|
|
|
case PIPE_CONTROL:
|
|
|
|
case PIPE_BULK:
|
|
|
|
default:
|
|
|
|
ret = asl_urb_enqueue(whc, urb, mem_flags);
|
|
|
|
break;
|
2013-10-08 23:01:37 +00:00
|
|
|
}
|
2008-09-17 15:34:28 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove a queued URB from the ASL or PZL.
|
|
|
|
*/
|
|
|
|
static int whc_urb_dequeue(struct usb_hcd *usb_hcd, struct urb *urb, int status)
|
|
|
|
{
|
|
|
|
struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
|
|
|
|
struct whc *whc = wusbhc_to_whc(wusbhc);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
switch (usb_pipetype(urb->pipe)) {
|
|
|
|
case PIPE_INTERRUPT:
|
|
|
|
ret = pzl_urb_dequeue(whc, urb, status);
|
|
|
|
break;
|
|
|
|
case PIPE_ISOCHRONOUS:
|
|
|
|
ret = -ENOTSUPP;
|
|
|
|
break;
|
|
|
|
case PIPE_CONTROL:
|
|
|
|
case PIPE_BULK:
|
|
|
|
default:
|
|
|
|
ret = asl_urb_dequeue(whc, urb, status);
|
|
|
|
break;
|
2013-10-08 23:01:37 +00:00
|
|
|
}
|
2008-09-17 15:34:28 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for all URBs to the endpoint to be completed, then delete the
|
|
|
|
* qset.
|
|
|
|
*/
|
|
|
|
static void whc_endpoint_disable(struct usb_hcd *usb_hcd,
|
|
|
|
struct usb_host_endpoint *ep)
|
|
|
|
{
|
|
|
|
struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
|
|
|
|
struct whc *whc = wusbhc_to_whc(wusbhc);
|
|
|
|
struct whc_qset *qset;
|
|
|
|
|
|
|
|
qset = ep->hcpriv;
|
|
|
|
if (qset) {
|
|
|
|
ep->hcpriv = NULL;
|
|
|
|
if (usb_endpoint_xfer_bulk(&ep->desc)
|
|
|
|
|| usb_endpoint_xfer_control(&ep->desc))
|
|
|
|
asl_qset_delete(whc, qset);
|
|
|
|
else
|
|
|
|
pzl_qset_delete(whc, qset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-08 17:36:29 +00:00
|
|
|
static void whc_endpoint_reset(struct usb_hcd *usb_hcd,
|
|
|
|
struct usb_host_endpoint *ep)
|
|
|
|
{
|
|
|
|
struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
|
|
|
|
struct whc *whc = wusbhc_to_whc(wusbhc);
|
|
|
|
struct whc_qset *qset;
|
2009-06-24 17:26:40 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&whc->lock, flags);
|
2009-04-08 17:36:29 +00:00
|
|
|
|
|
|
|
qset = ep->hcpriv;
|
|
|
|
if (qset) {
|
|
|
|
qset->remove = 1;
|
2009-06-24 17:26:40 +00:00
|
|
|
qset->reset = 1;
|
2009-04-08 17:36:29 +00:00
|
|
|
|
|
|
|
if (usb_endpoint_xfer_bulk(&ep->desc)
|
|
|
|
|| usb_endpoint_xfer_control(&ep->desc))
|
|
|
|
queue_work(whc->workqueue, &whc->async_work);
|
|
|
|
else
|
|
|
|
queue_work(whc->workqueue, &whc->periodic_work);
|
|
|
|
}
|
2009-06-24 17:26:40 +00:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&whc->lock, flags);
|
2009-04-08 17:36:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-17 15:34:28 +00:00
|
|
|
static struct hc_driver whc_hc_driver = {
|
|
|
|
.description = "whci-hcd",
|
|
|
|
.product_desc = "Wireless host controller",
|
|
|
|
.hcd_priv_size = sizeof(struct whc) - sizeof(struct usb_hcd),
|
|
|
|
.irq = whc_int_handler,
|
|
|
|
.flags = HCD_USB2,
|
|
|
|
|
|
|
|
.reset = whc_reset,
|
|
|
|
.start = whc_start,
|
|
|
|
.stop = whc_stop,
|
|
|
|
.get_frame_number = whc_get_frame_number,
|
|
|
|
.urb_enqueue = whc_urb_enqueue,
|
|
|
|
.urb_dequeue = whc_urb_dequeue,
|
|
|
|
.endpoint_disable = whc_endpoint_disable,
|
2009-04-08 17:36:29 +00:00
|
|
|
.endpoint_reset = whc_endpoint_reset,
|
2008-09-17 15:34:28 +00:00
|
|
|
|
|
|
|
.hub_status_data = wusbhc_rh_status_data,
|
|
|
|
.hub_control = wusbhc_rh_control,
|
|
|
|
.start_port_reset = wusbhc_rh_start_port_reset,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int whc_probe(struct umc_dev *umc)
|
|
|
|
{
|
2012-07-20 06:58:16 +00:00
|
|
|
int ret;
|
2008-09-17 15:34:28 +00:00
|
|
|
struct usb_hcd *usb_hcd;
|
2012-07-20 06:58:16 +00:00
|
|
|
struct wusbhc *wusbhc;
|
|
|
|
struct whc *whc;
|
2008-09-17 15:34:28 +00:00
|
|
|
struct device *dev = &umc->dev;
|
|
|
|
|
|
|
|
usb_hcd = usb_create_hcd(&whc_hc_driver, dev, "whci");
|
|
|
|
if (usb_hcd == NULL) {
|
|
|
|
dev_err(dev, "unable to create hcd\n");
|
2012-07-20 06:58:16 +00:00
|
|
|
return -ENOMEM;
|
2008-09-17 15:34:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
usb_hcd->wireless = 1;
|
2009-08-24 14:02:27 +00:00
|
|
|
usb_hcd->self.sg_tablesize = 2048; /* somewhat arbitrary */
|
2008-09-17 15:34:28 +00:00
|
|
|
|
|
|
|
wusbhc = usb_hcd_to_wusbhc(usb_hcd);
|
|
|
|
whc = wusbhc_to_whc(wusbhc);
|
|
|
|
whc->umc = umc;
|
|
|
|
|
|
|
|
ret = whc_init(whc);
|
|
|
|
if (ret)
|
2016-03-26 21:03:53 +00:00
|
|
|
goto error_whc_init;
|
2008-09-17 15:34:28 +00:00
|
|
|
|
|
|
|
wusbhc->dev = dev;
|
|
|
|
wusbhc->uwb_rc = uwb_rc_get_by_grandpa(umc->dev.parent);
|
|
|
|
if (!wusbhc->uwb_rc) {
|
|
|
|
ret = -ENODEV;
|
|
|
|
dev_err(dev, "cannot get radio controller\n");
|
2016-03-26 21:03:53 +00:00
|
|
|
goto error_uwb_rc;
|
2008-09-17 15:34:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (whc->n_devices > USB_MAXCHILDREN) {
|
|
|
|
dev_warn(dev, "USB_MAXCHILDREN too low for WUSB adapter (%u ports)\n",
|
|
|
|
whc->n_devices);
|
|
|
|
wusbhc->ports_max = USB_MAXCHILDREN;
|
|
|
|
} else
|
|
|
|
wusbhc->ports_max = whc->n_devices;
|
|
|
|
wusbhc->mmcies_max = whc->n_mmc_ies;
|
|
|
|
wusbhc->start = whc_wusbhc_start;
|
|
|
|
wusbhc->stop = whc_wusbhc_stop;
|
|
|
|
wusbhc->mmcie_add = whc_mmcie_add;
|
|
|
|
wusbhc->mmcie_rm = whc_mmcie_rm;
|
|
|
|
wusbhc->dev_info_set = whc_dev_info_set;
|
|
|
|
wusbhc->bwa_set = whc_bwa_set;
|
|
|
|
wusbhc->set_num_dnts = whc_set_num_dnts;
|
|
|
|
wusbhc->set_ptk = whc_set_ptk;
|
|
|
|
wusbhc->set_gtk = whc_set_gtk;
|
|
|
|
|
|
|
|
ret = wusbhc_create(wusbhc);
|
|
|
|
if (ret)
|
|
|
|
goto error_wusbhc_create;
|
|
|
|
|
|
|
|
ret = usb_add_hcd(usb_hcd, whc->umc->irq, IRQF_SHARED);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "cannot add HCD: %d\n", ret);
|
|
|
|
goto error_usb_add_hcd;
|
|
|
|
}
|
2013-11-05 02:46:02 +00:00
|
|
|
device_wakeup_enable(usb_hcd->self.controller);
|
2008-09-17 15:34:28 +00:00
|
|
|
|
|
|
|
ret = wusbhc_b_create(wusbhc);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "WUSBHC phase B setup failed: %d\n", ret);
|
|
|
|
goto error_wusbhc_b_create;
|
|
|
|
}
|
|
|
|
|
2008-11-26 13:36:59 +00:00
|
|
|
whc_dbg_init(whc);
|
|
|
|
|
2008-09-17 15:34:28 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
error_wusbhc_b_create:
|
|
|
|
usb_remove_hcd(usb_hcd);
|
|
|
|
error_usb_add_hcd:
|
|
|
|
wusbhc_destroy(wusbhc);
|
|
|
|
error_wusbhc_create:
|
|
|
|
uwb_rc_put(wusbhc->uwb_rc);
|
2016-03-26 21:03:53 +00:00
|
|
|
error_uwb_rc:
|
2008-09-17 15:34:28 +00:00
|
|
|
whc_clean_up(whc);
|
2016-03-26 21:03:53 +00:00
|
|
|
error_whc_init:
|
2015-02-05 15:54:12 +00:00
|
|
|
usb_put_hcd(usb_hcd);
|
2008-09-17 15:34:28 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void whc_remove(struct umc_dev *umc)
|
|
|
|
{
|
|
|
|
struct usb_hcd *usb_hcd = dev_get_drvdata(&umc->dev);
|
|
|
|
struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
|
|
|
|
struct whc *whc = wusbhc_to_whc(wusbhc);
|
|
|
|
|
|
|
|
if (usb_hcd) {
|
2008-11-26 13:36:59 +00:00
|
|
|
whc_dbg_clean_up(whc);
|
2008-09-17 15:34:28 +00:00
|
|
|
wusbhc_b_destroy(wusbhc);
|
|
|
|
usb_remove_hcd(usb_hcd);
|
|
|
|
wusbhc_destroy(wusbhc);
|
|
|
|
uwb_rc_put(wusbhc->uwb_rc);
|
|
|
|
whc_clean_up(whc);
|
|
|
|
usb_put_hcd(usb_hcd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct umc_driver whci_hc_driver = {
|
|
|
|
.name = "whci-hcd",
|
|
|
|
.cap_id = UMC_CAP_ID_WHCI_WUSB_HC,
|
|
|
|
.probe = whc_probe,
|
|
|
|
.remove = whc_remove,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init whci_hc_driver_init(void)
|
|
|
|
{
|
|
|
|
return umc_driver_register(&whci_hc_driver);
|
|
|
|
}
|
|
|
|
module_init(whci_hc_driver_init);
|
|
|
|
|
|
|
|
static void __exit whci_hc_driver_exit(void)
|
|
|
|
{
|
|
|
|
umc_driver_unregister(&whci_hc_driver);
|
|
|
|
}
|
|
|
|
module_exit(whci_hc_driver_exit);
|
|
|
|
|
|
|
|
/* PCI device ID's that we handle (so it gets loaded) */
|
2010-12-06 16:03:32 +00:00
|
|
|
static struct pci_device_id __used whci_hcd_id_table[] = {
|
2008-09-17 15:34:28 +00:00
|
|
|
{ PCI_DEVICE_CLASS(PCI_CLASS_WIRELESS_WHCI, ~0) },
|
|
|
|
{ /* empty last entry */ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(pci, whci_hcd_id_table);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("WHCI Wireless USB host controller driver");
|
|
|
|
MODULE_AUTHOR("Cambridge Silicon Radio Ltd.");
|
|
|
|
MODULE_LICENSE("GPL");
|