提交 fbe38a8b 编写于 作者: H H Hartley Sweeten 提交者: Greg Kroah-Hartman

staging: comedi: usbduxfast: consolidate the firmware upload

Absorb the usbduxfastsub_stop(), usbduxfastsub_upload(), and
usbduxfastsub_start() functions into usbduxfast_upload_firmware().

Each of them just do a usb_control_msg() to the device and output
an error message if it fails. A similar message is also output by
usbduxfast_upload_firmware() so the extra messages are redundant.

We can also share the malloc'ed local buffer needed for the
usb_control_msg().
Signed-off-by: NH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 dcd29f56
......@@ -326,90 +326,6 @@ static void usbduxfast_ai_interrupt(struct urb *urb)
}
}
static int usbduxfastsub_start(struct comedi_device *dev)
{
struct usb_interface *intf = comedi_to_usb_interface(dev);
struct usb_device *usb = interface_to_usbdev(intf);
unsigned char *local_transfer_buffer;
int ret;
local_transfer_buffer = kmalloc(1, GFP_KERNEL);
if (!local_transfer_buffer)
return -ENOMEM;
/* 7f92 to zero */
*local_transfer_buffer = 0;
/* bRequest, "Firmware" */
ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0),
USBDUXFASTSUB_FIRMWARE,
VENDOR_DIR_OUT, /* bmRequestType */
USBDUXFASTSUB_CPUCS, /* Value */
0x0000, /* Index */
/* address of the transfer buffer */
local_transfer_buffer,
1, /* Length */
EZTIMEOUT); /* Timeout */
if (ret < 0)
dev_err(dev->class_dev, "control msg failed (start)\n");
kfree(local_transfer_buffer);
return ret;
}
static int usbduxfastsub_stop(struct comedi_device *dev)
{
struct usb_interface *intf = comedi_to_usb_interface(dev);
struct usb_device *usb = interface_to_usbdev(intf);
unsigned char *local_transfer_buffer;
int ret;
local_transfer_buffer = kmalloc(1, GFP_KERNEL);
if (!local_transfer_buffer)
return -ENOMEM;
/* 7f92 to one */
*local_transfer_buffer = 1;
/* bRequest, "Firmware" */
ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0),
USBDUXFASTSUB_FIRMWARE,
VENDOR_DIR_OUT, /* bmRequestType */
USBDUXFASTSUB_CPUCS, /* Value */
0x0000, /* Index */
local_transfer_buffer, 1, /* Length */
EZTIMEOUT); /* Timeout */
if (ret < 0)
dev_err(dev->class_dev, "control msg failed (stop)\n");
kfree(local_transfer_buffer);
return ret;
}
static int usbduxfastsub_upload(struct comedi_device *dev,
unsigned char *local_transfer_buffer,
unsigned int startAddr, unsigned int len)
{
struct usb_interface *intf = comedi_to_usb_interface(dev);
struct usb_device *usb = interface_to_usbdev(intf);
int ret;
/* brequest, firmware */
ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0),
USBDUXFASTSUB_FIRMWARE,
VENDOR_DIR_OUT, /* bmRequestType */
startAddr, /* value */
0x0000, /* index */
/* our local safe buffer */
local_transfer_buffer,
len, /* length */
EZTIMEOUT); /* timeout */
if (ret < 0) {
dev_err(dev->class_dev, "uppload failed\n");
return ret;
}
return 0;
}
static int usbduxfastsub_submit_InURBs(struct comedi_device *dev)
{
struct usb_interface *intf = comedi_to_usb_interface(dev);
......@@ -1158,7 +1074,10 @@ static int usbduxfast_attach_common(struct comedi_device *dev)
static int usbduxfast_upload_firmware(struct comedi_device *dev,
const struct firmware *fw)
{
struct usb_interface *intf = comedi_to_usb_interface(dev);
struct usb_device *usb = interface_to_usbdev(intf);
uint8_t *buf;
unsigned char *tmp;
int ret;
if (!fw->data)
......@@ -1174,22 +1093,51 @@ static int usbduxfast_upload_firmware(struct comedi_device *dev,
if (!buf)
return -ENOMEM;
ret = usbduxfastsub_stop(dev);
/* we need a malloc'ed buffer for usb_control_msg() */
tmp = kmalloc(1, GFP_KERNEL);
if (!tmp) {
kfree(buf);
return -ENOMEM;
}
/* stop the current firmware on the device */
*tmp = 1; /* 7f92 to one */
ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0),
USBDUXFASTSUB_FIRMWARE,
VENDOR_DIR_OUT,
USBDUXFASTSUB_CPUCS, 0x0000,
tmp, 1,
EZTIMEOUT);
if (ret < 0) {
dev_err(dev->class_dev, "can not stop firmware\n");
goto done;
}
ret = usbduxfastsub_upload(dev, buf, 0, fw->size);
/* upload the new firmware to the device */
ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0),
USBDUXFASTSUB_FIRMWARE,
VENDOR_DIR_OUT,
0, 0x0000,
buf, fw->size,
EZTIMEOUT);
if (ret < 0) {
dev_err(dev->class_dev, "firmware upload failed\n");
goto done;
}
ret = usbduxfastsub_start(dev);
/* start the new firmware on the device */
*tmp = 0; /* 7f92 to zero */
ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0),
USBDUXFASTSUB_FIRMWARE,
VENDOR_DIR_OUT,
USBDUXFASTSUB_CPUCS, 0x0000,
tmp, 1,
EZTIMEOUT);
if (ret < 0)
dev_err(dev->class_dev, "can not start firmware\n");
done:
kfree(tmp);
kfree(buf);
return ret;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册