For aesthetics, move this function closer to the (*auto_attach). Also, rename some of the defined constants that are used by the firmware upload. Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx> Cc: Ian Abbott <abbotti@xxxxxxxxx> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxx> --- drivers/staging/comedi/drivers/usbdux.c | 170 +++++++++++++++----------------- 1 file changed, 82 insertions(+), 88 deletions(-) diff --git a/drivers/staging/comedi/drivers/usbdux.c b/drivers/staging/comedi/drivers/usbdux.c index 6991e85..92d740a 100644 --- a/drivers/staging/comedi/drivers/usbdux.c +++ b/drivers/staging/comedi/drivers/usbdux.c @@ -91,17 +91,16 @@ sampling rate. If you sample two channels you get 4kHz and so on. #include "comedi_fc.h" -/* timeout for the USB-transfer in ms*/ -#define BULK_TIMEOUT 1000 +/* constants for firmware upload and download */ +#define USBDUX_FIRMWARE "usbdux_firmware.bin" +#define USBDUX_FIRMWARE_MAX_LEN 0x2000 +#define USBDUX_FIRMWARE_CMD 0xa0 +#define VENDOR_DIR_IN 0xc0 +#define VENDOR_DIR_OUT 0x40 +#define USBDUX_CPU_CS 0xe600 -/* constants for "firmware" upload and download */ -#define FIRMWARE "usbdux_firmware.bin" -#define USBDUXSUB_FIRMWARE 0xA0 -#define VENDOR_DIR_IN 0xC0 -#define VENDOR_DIR_OUT 0x40 - -/* internal addresses of the 8051 processor */ -#define USBDUXSUB_CPUCS 0xE600 +/* timeout for the USB-transfer in ms */ +#define BULK_TIMEOUT 1000 /* 300Hz max frequ under PWM */ #define MIN_PWM_PERIOD ((long)(1E9/300)) @@ -539,80 +538,6 @@ static void usbduxsub_ao_isoc_irq(struct urb *urb) } } -#define FIRMWARE_MAX_LEN 0x2000 - -static int usbdux_firmware_upload(struct comedi_device *dev, - const u8 *data, size_t size, - unsigned long context) -{ - struct usb_device *usb = comedi_to_usb_dev(dev); - uint8_t *buf; - uint8_t *tmp; - int ret; - - if (!data) - return 0; - - if (size > FIRMWARE_MAX_LEN) { - dev_err(dev->class_dev, - "usbdux firmware binary it too large for FX2.\n"); - return -ENOMEM; - } - - /* we generate a local buffer for the firmware */ - buf = kmemdup(data, size, GFP_KERNEL); - if (!buf) - return -ENOMEM; - - /* 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), - USBDUXSUB_FIRMWARE, - VENDOR_DIR_OUT, - USBDUXSUB_CPUCS, 0x0000, - tmp, 1, - BULK_TIMEOUT); - if (ret < 0) { - dev_err(dev->class_dev, "can not stop firmware\n"); - goto done; - } - - /* upload the new firmware to the device */ - ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0), - USBDUXSUB_FIRMWARE, - VENDOR_DIR_OUT, - 0, 0x0000, - buf, size, - BULK_TIMEOUT); - if (ret < 0) { - dev_err(dev->class_dev, "firmware upload failed\n"); - goto done; - } - - /* start the new firmware on the device */ - *tmp = 0; /* 7f92 to zero */ - ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0), - USBDUXSUB_FIRMWARE, - VENDOR_DIR_OUT, - USBDUXSUB_CPUCS, 0x0000, - tmp, 1, - BULK_TIMEOUT); - if (ret < 0) - dev_err(dev->class_dev, "can not start firmware\n"); - -done: - kfree(tmp); - kfree(buf); - return ret; -} - static int usbduxsub_submit_inurbs(struct comedi_device *dev) { struct usb_device *usb = comedi_to_usb_dev(dev); @@ -1635,8 +1560,77 @@ static int usbdux_pwm_config(struct comedi_device *dev, return -EINVAL; } -/* end of PWM */ -/*****************************************************************/ +static int usbdux_firmware_upload(struct comedi_device *dev, + const u8 *data, size_t size, + unsigned long context) +{ + struct usb_device *usb = comedi_to_usb_dev(dev); + uint8_t *buf; + uint8_t *tmp; + int ret; + + if (!data) + return 0; + + if (size > USBDUX_FIRMWARE_MAX_LEN) { + dev_err(dev->class_dev, + "usbdux firmware binary it too large for FX2.\n"); + return -ENOMEM; + } + + /* we generate a local buffer for the firmware */ + buf = kmemdup(data, size, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + /* 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), + USBDUX_FIRMWARE_CMD, + VENDOR_DIR_OUT, + USBDUX_CPU_CS, 0x0000, + tmp, 1, + BULK_TIMEOUT); + if (ret < 0) { + dev_err(dev->class_dev, "can not stop firmware\n"); + goto done; + } + + /* upload the new firmware to the device */ + ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0), + USBDUX_FIRMWARE_CMD, + VENDOR_DIR_OUT, + 0, 0x0000, + buf, size, + BULK_TIMEOUT); + if (ret < 0) { + dev_err(dev->class_dev, "firmware upload failed\n"); + goto done; + } + + /* start the new firmware on the device */ + *tmp = 0; /* 7f92 to zero */ + ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0), + USBDUX_FIRMWARE_CMD, + VENDOR_DIR_OUT, + USBDUX_CPU_CS, 0x0000, + tmp, 1, + BULK_TIMEOUT); + if (ret < 0) + dev_err(dev->class_dev, "can not start firmware\n"); + +done: + kfree(tmp); + kfree(buf); + return ret; +} static int usbdux_alloc_usb_buffers(struct comedi_device *dev) { @@ -1831,7 +1825,7 @@ static int usbdux_auto_attach(struct comedi_device *dev, return ret; } - ret = comedi_load_firmware(dev, &usb->dev, FIRMWARE, + ret = comedi_load_firmware(dev, &usb->dev, USBDUX_FIRMWARE, usbdux_firmware_upload, 0); if (ret < 0) return ret; @@ -1958,4 +1952,4 @@ module_comedi_usb_driver(usbdux_driver, usbdux_usb_driver); MODULE_AUTHOR("Bernd Porr, BerndPorr@xxxxxxx"); MODULE_DESCRIPTION("Stirling/ITL USB-DUX -- Bernd.Porr@xxxxxxx"); MODULE_LICENSE("GPL"); -MODULE_FIRMWARE(FIRMWARE); +MODULE_FIRMWARE(USBDUX_FIRMWARE); -- 1.8.3.2 _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel