2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Broadcom Blutonium firmware driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003 Maxim Krasnyansky <maxk@qualcomm.com>
|
|
|
|
* Copyright (C) 2003 Marcel Holtmann <marcel@holtmann.org>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
2011-10-26 03:13:13 -06:00
|
|
|
#include <linux/atomic.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/firmware.h>
|
|
|
|
|
|
|
|
#include <linux/usb.h>
|
|
|
|
|
|
|
|
#include <net/bluetooth/bluetooth.h>
|
|
|
|
|
2008-08-07 14:26:55 -06:00
|
|
|
#define VERSION "1.2"
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-01-10 05:39:15 -07:00
|
|
|
static const struct usb_device_id bcm203x_table[] = {
|
2005-04-16 16:20:36 -06:00
|
|
|
/* Broadcom Blutonium (BCM2033) */
|
|
|
|
{ USB_DEVICE(0x0a5c, 0x2033) },
|
|
|
|
|
|
|
|
{ } /* Terminating entry */
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(usb, bcm203x_table);
|
|
|
|
|
|
|
|
#define BCM203X_ERROR 0
|
|
|
|
#define BCM203X_RESET 1
|
|
|
|
#define BCM203X_LOAD_MINIDRV 2
|
|
|
|
#define BCM203X_SELECT_MEMORY 3
|
|
|
|
#define BCM203X_CHECK_MEMORY 4
|
|
|
|
#define BCM203X_LOAD_FIRMWARE 5
|
|
|
|
#define BCM203X_CHECK_FIRMWARE 6
|
|
|
|
|
|
|
|
#define BCM203X_IN_EP 0x81
|
|
|
|
#define BCM203X_OUT_EP 0x02
|
|
|
|
|
|
|
|
struct bcm203x_data {
|
|
|
|
struct usb_device *udev;
|
|
|
|
|
|
|
|
unsigned long state;
|
|
|
|
|
2006-10-15 09:31:19 -06:00
|
|
|
struct work_struct work;
|
2011-10-26 03:13:13 -06:00
|
|
|
atomic_t shutdown;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
struct urb *urb;
|
|
|
|
unsigned char *buffer;
|
|
|
|
|
|
|
|
unsigned char *fw_data;
|
|
|
|
unsigned int fw_size;
|
|
|
|
unsigned int fw_sent;
|
|
|
|
};
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 07:55:46 -06:00
|
|
|
static void bcm203x_complete(struct urb *urb)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct bcm203x_data *data = urb->context;
|
|
|
|
struct usb_device *udev = urb->dev;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
BT_DBG("udev %p urb %p", udev, urb);
|
|
|
|
|
|
|
|
if (urb->status) {
|
|
|
|
BT_ERR("URB failed with status %d", urb->status);
|
|
|
|
data->state = BCM203X_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (data->state) {
|
|
|
|
case BCM203X_LOAD_MINIDRV:
|
|
|
|
memcpy(data->buffer, "#", 1);
|
|
|
|
|
|
|
|
usb_fill_bulk_urb(urb, udev, usb_sndbulkpipe(udev, BCM203X_OUT_EP),
|
|
|
|
data->buffer, 1, bcm203x_complete, data);
|
|
|
|
|
|
|
|
data->state = BCM203X_SELECT_MEMORY;
|
|
|
|
|
2011-10-26 03:13:13 -06:00
|
|
|
/* use workqueue to have a small delay */
|
2006-10-15 09:31:19 -06:00
|
|
|
schedule_work(&data->work);
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BCM203X_SELECT_MEMORY:
|
|
|
|
usb_fill_int_urb(urb, udev, usb_rcvintpipe(udev, BCM203X_IN_EP),
|
|
|
|
data->buffer, 32, bcm203x_complete, data, 1);
|
|
|
|
|
|
|
|
data->state = BCM203X_CHECK_MEMORY;
|
|
|
|
|
|
|
|
if (usb_submit_urb(data->urb, GFP_ATOMIC) < 0)
|
|
|
|
BT_ERR("Can't submit URB");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BCM203X_CHECK_MEMORY:
|
|
|
|
if (data->buffer[0] != '#') {
|
|
|
|
BT_ERR("Memory select failed");
|
|
|
|
data->state = BCM203X_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->state = BCM203X_LOAD_FIRMWARE;
|
|
|
|
|
|
|
|
case BCM203X_LOAD_FIRMWARE:
|
|
|
|
if (data->fw_sent == data->fw_size) {
|
|
|
|
usb_fill_int_urb(urb, udev, usb_rcvintpipe(udev, BCM203X_IN_EP),
|
|
|
|
data->buffer, 32, bcm203x_complete, data, 1);
|
|
|
|
|
|
|
|
data->state = BCM203X_CHECK_FIRMWARE;
|
|
|
|
} else {
|
|
|
|
len = min_t(uint, data->fw_size - data->fw_sent, 4096);
|
|
|
|
|
|
|
|
usb_fill_bulk_urb(urb, udev, usb_sndbulkpipe(udev, BCM203X_OUT_EP),
|
|
|
|
data->fw_data + data->fw_sent, len, bcm203x_complete, data);
|
|
|
|
|
|
|
|
data->fw_sent += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (usb_submit_urb(data->urb, GFP_ATOMIC) < 0)
|
|
|
|
BT_ERR("Can't submit URB");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BCM203X_CHECK_FIRMWARE:
|
|
|
|
if (data->buffer[0] != '.') {
|
|
|
|
BT_ERR("Firmware loading failed");
|
|
|
|
data->state = BCM203X_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->state = BCM203X_RESET;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-22 07:57:56 -07:00
|
|
|
static void bcm203x_work(struct work_struct *work)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-11-22 07:57:56 -07:00
|
|
|
struct bcm203x_data *data =
|
|
|
|
container_of(work, struct bcm203x_data, work);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2011-10-26 03:13:13 -06:00
|
|
|
if (atomic_read(&data->shutdown))
|
|
|
|
return;
|
|
|
|
|
2011-10-25 13:13:36 -06:00
|
|
|
if (usb_submit_urb(data->urb, GFP_KERNEL) < 0)
|
2005-04-16 16:20:36 -06:00
|
|
|
BT_ERR("Can't submit URB");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bcm203x_probe(struct usb_interface *intf, const struct usb_device_id *id)
|
|
|
|
{
|
|
|
|
const struct firmware *firmware;
|
|
|
|
struct usb_device *udev = interface_to_usbdev(intf);
|
|
|
|
struct bcm203x_data *data;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
BT_DBG("intf %p id %p", intf, id);
|
|
|
|
|
2008-08-07 14:26:55 -06:00
|
|
|
if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
|
2005-04-16 16:20:36 -06:00
|
|
|
return -ENODEV;
|
|
|
|
|
2005-11-07 02:01:26 -07:00
|
|
|
data = kzalloc(sizeof(*data), GFP_KERNEL);
|
2005-04-16 16:20:36 -06:00
|
|
|
if (!data) {
|
|
|
|
BT_ERR("Can't allocate memory for data structure");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->udev = udev;
|
|
|
|
data->state = BCM203X_LOAD_MINIDRV;
|
|
|
|
|
|
|
|
data->urb = usb_alloc_urb(0, GFP_KERNEL);
|
|
|
|
if (!data->urb) {
|
|
|
|
BT_ERR("Can't allocate URB");
|
|
|
|
kfree(data);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (request_firmware(&firmware, "BCM2033-MD.hex", &udev->dev) < 0) {
|
|
|
|
BT_ERR("Mini driver request failed");
|
|
|
|
usb_free_urb(data->urb);
|
|
|
|
kfree(data);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2008-11-30 04:17:28 -07:00
|
|
|
BT_DBG("minidrv data %p size %zu", firmware->data, firmware->size);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
size = max_t(uint, firmware->size, 4096);
|
|
|
|
|
|
|
|
data->buffer = kmalloc(size, GFP_KERNEL);
|
|
|
|
if (!data->buffer) {
|
|
|
|
BT_ERR("Can't allocate memory for mini driver");
|
|
|
|
release_firmware(firmware);
|
|
|
|
usb_free_urb(data->urb);
|
|
|
|
kfree(data);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(data->buffer, firmware->data, firmware->size);
|
|
|
|
|
|
|
|
usb_fill_bulk_urb(data->urb, udev, usb_sndbulkpipe(udev, BCM203X_OUT_EP),
|
|
|
|
data->buffer, firmware->size, bcm203x_complete, data);
|
|
|
|
|
|
|
|
release_firmware(firmware);
|
|
|
|
|
|
|
|
if (request_firmware(&firmware, "BCM2033-FW.bin", &udev->dev) < 0) {
|
|
|
|
BT_ERR("Firmware request failed");
|
|
|
|
usb_free_urb(data->urb);
|
|
|
|
kfree(data->buffer);
|
|
|
|
kfree(data);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2008-11-30 04:17:28 -07:00
|
|
|
BT_DBG("firmware data %p size %zu", firmware->data, firmware->size);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-05-15 15:19:15 -06:00
|
|
|
data->fw_data = kmemdup(firmware->data, firmware->size, GFP_KERNEL);
|
2005-04-16 16:20:36 -06:00
|
|
|
if (!data->fw_data) {
|
|
|
|
BT_ERR("Can't allocate memory for firmware image");
|
2006-07-10 05:44:09 -06:00
|
|
|
release_firmware(firmware);
|
2005-04-16 16:20:36 -06:00
|
|
|
usb_free_urb(data->urb);
|
|
|
|
kfree(data->buffer);
|
|
|
|
kfree(data);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->fw_size = firmware->size;
|
|
|
|
data->fw_sent = 0;
|
|
|
|
|
|
|
|
release_firmware(firmware);
|
|
|
|
|
2006-11-22 07:57:56 -07:00
|
|
|
INIT_WORK(&data->work, bcm203x_work);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
usb_set_intfdata(intf, data);
|
|
|
|
|
2011-10-26 03:13:13 -06:00
|
|
|
/* use workqueue to have a small delay */
|
2006-10-15 09:31:19 -06:00
|
|
|
schedule_work(&data->work);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bcm203x_disconnect(struct usb_interface *intf)
|
|
|
|
{
|
|
|
|
struct bcm203x_data *data = usb_get_intfdata(intf);
|
|
|
|
|
|
|
|
BT_DBG("intf %p", intf);
|
|
|
|
|
2011-10-26 03:13:13 -06:00
|
|
|
atomic_inc(&data->shutdown);
|
|
|
|
cancel_work_sync(&data->work);
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
usb_kill_urb(data->urb);
|
|
|
|
|
|
|
|
usb_set_intfdata(intf, NULL);
|
|
|
|
|
|
|
|
usb_free_urb(data->urb);
|
|
|
|
kfree(data->fw_data);
|
|
|
|
kfree(data->buffer);
|
|
|
|
kfree(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct usb_driver bcm203x_driver = {
|
|
|
|
.name = "bcm203x",
|
|
|
|
.probe = bcm203x_probe,
|
|
|
|
.disconnect = bcm203x_disconnect,
|
|
|
|
.id_table = bcm203x_table,
|
|
|
|
};
|
|
|
|
|
2011-11-18 10:47:34 -07:00
|
|
|
module_usb_driver(bcm203x_driver);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
|
|
|
|
MODULE_DESCRIPTION("Broadcom Blutonium firmware driver ver " VERSION);
|
|
|
|
MODULE_VERSION(VERSION);
|
|
|
|
MODULE_LICENSE("GPL");
|
2007-02-17 15:59:02 -07:00
|
|
|
MODULE_FIRMWARE("BCM2033-MD.hex");
|
|
|
|
MODULE_FIRMWARE("BCM2033-FW.bin");
|