Hi,
Here's a small patch against 2.4.5-pre1 that moves the ezusb_* functions
out of the usb-serial core code and into the usb core. This is needed
as more drivers outside of the usb-serial tree are needing to write data
to a EZUSB device (2 were mentioned last week on the mailing list).
I also added documentation to the functions so it shows up in the
kernel-api.* document.
thanks,
greg k-h
diff -Naur -X /home/greg/linux/dontdiff linux-2.4.5-pre1/drivers/usb/serial/keyspan.c
linux-2.4.5-pre1-greg/drivers/usb/serial/keyspan.c
--- linux-2.4.5-pre1/drivers/usb/serial/keyspan.c Thu May 3 13:21:46 2001
+++ linux-2.4.5-pre1-greg/drivers/usb/serial/keyspan.c Mon May 7 17:45:56 2001
@@ -968,14 +968,14 @@
dbg("Uploading Keyspan %s firmware.", fw_name);
/* download the firmware image */
- response = ezusb_set_reset(serial, 1);
+ response = usb_ezusb_set_reset(serial, 1);
while(record->address != 0xffff) {
- response = ezusb_writememory(serial, record->address,
+ response = usb_ezusb_writememory(serial, record->address,
(unsigned char *)record->data,
record->data_size, 0xa0);
if (response < 0) {
- err("ezusb_writememory failed for Keyspan"
+ err("usb_ezusb_writememory failed for Keyspan"
"firmware (%d %04X %p %d)",
response,
record->address, record->data, record->data_size);
@@ -985,7 +985,7 @@
}
/* bring device out of reset. Renumeration will occur in a
moment and the new device will bind to the real driver */
- response = ezusb_set_reset(serial, 0);
+ response = usb_ezusb_set_reset(serial, 0);
/* we don't want this device to have a driver assigned to it. */
return (1);
diff -Naur -X /home/greg/linux/dontdiff linux-2.4.5-pre1/drivers/usb/serial/keyspan.h
linux-2.4.5-pre1-greg/drivers/usb/serial/keyspan.h
--- linux-2.4.5-pre1/drivers/usb/serial/keyspan.h Thu Jan 4 13:15:32 2001
+++ linux-2.4.5-pre1-greg/drivers/usb/serial/keyspan.h Mon May 7 17:11:56 2001
@@ -84,9 +84,6 @@
static int keyspan_usa49_send_setup (struct usb_serial *serial,
struct usb_serial_port *port);
- /* Functions from usbserial.c for ezusb firmware handling */
-extern int ezusb_set_reset (struct usb_serial *serial, unsigned char reset_bit);
-extern int ezusb_writememory (struct usb_serial *serial, int address, unsigned char
*data, int length, __u8 bRequest);
/* Struct used for firmware */
struct ezusb_hex_record {
diff -Naur -X /home/greg/linux/dontdiff
linux-2.4.5-pre1/drivers/usb/serial/keyspan_pda.c
linux-2.4.5-pre1-greg/drivers/usb/serial/keyspan_pda.c
--- linux-2.4.5-pre1/drivers/usb/serial/keyspan_pda.c Thu May 3 13:21:46 2001
+++ linux-2.4.5-pre1-greg/drivers/usb/serial/keyspan_pda.c Mon May 7 17:11:56
+2001
@@ -705,15 +705,15 @@
const struct ezusb_hex_record *record;
/* download the firmware here ... */
- response = ezusb_set_reset(serial, 1);
+ response = usb_ezusb_set_reset(serial, 1);
record = &keyspan_pda_firmware[0];
while(record->address != 0xffff) {
- response = ezusb_writememory(serial, record->address,
+ response = usb_ezusb_writememory(serial, record->address,
(unsigned char *)record->data,
record->data_size, 0xa0);
if (response < 0) {
- err("ezusb_writememory failed for Keyspan PDA "
+ err("usb_ezusb_writememory failed for Keyspan PDA "
"firmware (%d %04X %p %d)",
response,
record->address, record->data, record->data_size);
@@ -723,7 +723,7 @@
}
/* bring device out of reset. Renumeration will occur in a moment
and the new device will bind to the real driver */
- response = ezusb_set_reset(serial, 0);
+ response = usb_ezusb_set_reset(serial, 0);
/* we want this device to fail to have a driver assigned to it. */
return (1);
diff -Naur -X /home/greg/linux/dontdiff
linux-2.4.5-pre1/drivers/usb/serial/usb-serial.h
linux-2.4.5-pre1-greg/drivers/usb/serial/usb-serial.h
--- linux-2.4.5-pre1/drivers/usb/serial/usb-serial.h Thu May 3 13:21:46 2001
+++ linux-2.4.5-pre1-greg/drivers/usb/serial/usb-serial.h Mon May 7 15:11:26
+2001
@@ -149,15 +149,6 @@
extern int usb_serial_register(struct usb_serial_device_type *new_device);
extern void usb_serial_deregister(struct usb_serial_device_type *device);
-/* determine if we should include the EzUSB loader functions */
-#if defined(CONFIG_USB_SERIAL_KEYSPAN_PDA) || defined(CONFIG_USB_SERIAL_WHITEHEAT) ||
defined(CONFIG_USB_SERIAL_KEYSPAN) || defined(CONFIG_USB_SERIAL_KEYSPAN_PDA_MODULE) ||
defined(CONFIG_USB_SERIAL_WHITEHEAT_MODULE) ||
defined(CONFIG_USB_SERIAL_KEYSPAN_MODULE)
- #define USES_EZUSB_FUNCTIONS
- extern int ezusb_writememory (struct usb_serial *serial, int address, unsigned
char *data, int length, __u8 bRequest);
- extern int ezusb_set_reset (struct usb_serial *serial, unsigned char
reset_bit);
-#else
- #undef USES_EZUSB_FUNCTIONS
-#endif
-
/* Inline functions to check the sanity of a pointer that is passed to us */
static inline int serial_paranoia_check (struct usb_serial *serial, const char
*function)
diff -Naur -X /home/greg/linux/dontdiff
linux-2.4.5-pre1/drivers/usb/serial/usbserial.c
linux-2.4.5-pre1-greg/drivers/usb/serial/usbserial.c
--- linux-2.4.5-pre1/drivers/usb/serial/usbserial.c Thu May 3 13:21:46 2001
+++ linux-2.4.5-pre1-greg/drivers/usb/serial/usbserial.c Mon May 7 17:09:50
+2001
@@ -434,42 +434,6 @@
}
-#ifdef USES_EZUSB_FUNCTIONS
-/* EZ-USB Control and Status Register. Bit 0 controls 8051 reset */
-#define CPUCS_REG 0x7F92
-
-int ezusb_writememory (struct usb_serial *serial, int address, unsigned char *data,
int length, __u8 bRequest)
-{
- int result;
- unsigned char *transfer_buffer = kmalloc (length, GFP_KERNEL);
-
-// dbg("ezusb_writememory %x, %d", address, length);
-
- if (!transfer_buffer) {
- err(__FUNCTION__ " - kmalloc(%d) failed.", length);
- return -ENOMEM;
- }
- memcpy (transfer_buffer, data, length);
- result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0),
bRequest, 0x40, address, 0, transfer_buffer, length, 300);
- kfree (transfer_buffer);
- return result;
-}
-
-
-int ezusb_set_reset (struct usb_serial *serial, unsigned char reset_bit)
-{
- int response;
- dbg(__FUNCTION__ " - %d", reset_bit);
- response = ezusb_writememory (serial, CPUCS_REG, &reset_bit, 1, 0xa0);
- if (response < 0) {
- err(__FUNCTION__ "- %d failed", reset_bit);
- }
- return response;
-}
-
-#endif /* USES_EZUSB_FUNCTIONS */
-
-
/*****************************************************************************
* Driver tty interface functions
*****************************************************************************/
@@ -1459,8 +1423,4 @@
need these symbols to load properly as modules. */
EXPORT_SYMBOL(usb_serial_register);
EXPORT_SYMBOL(usb_serial_deregister);
-#ifdef USES_EZUSB_FUNCTIONS
- EXPORT_SYMBOL(ezusb_writememory);
- EXPORT_SYMBOL(ezusb_set_reset);
-#endif
diff -Naur -X /home/greg/linux/dontdiff
linux-2.4.5-pre1/drivers/usb/serial/whiteheat.c
linux-2.4.5-pre1-greg/drivers/usb/serial/whiteheat.c
--- linux-2.4.5-pre1/drivers/usb/serial/whiteheat.c Thu May 3 13:21:46 2001
+++ linux-2.4.5-pre1-greg/drivers/usb/serial/whiteheat.c Mon May 7 17:11:56
+2001
@@ -502,52 +502,52 @@
dbg(__FUNCTION__);
- response = ezusb_set_reset (serial, 1);
+ response = usb_ezusb_set_reset (serial, 1);
record = &whiteheat_loader[0];
while (record->address != 0xffff) {
- response = ezusb_writememory (serial, record->address,
+ response = usb_ezusb_writememory (serial, record->address,
(unsigned char *)record->data, record->data_size,
0xa0);
if (response < 0) {
- err(__FUNCTION__ " - ezusb_writememory failed for loader (%d
%04X %p %d)",
+ err(__FUNCTION__ " - usb_ezusb_writememory failed for loader
+(%d %04X %p %d)",
response, record->address, record->data,
record->data_size);
break;
}
++record;
}
- response = ezusb_set_reset (serial, 0);
+ response = usb_ezusb_set_reset (serial, 0);
record = &whiteheat_firmware[0];
while (record->address < 0x1b40) {
++record;
}
while (record->address != 0xffff) {
- response = ezusb_writememory (serial, record->address,
+ response = usb_ezusb_writememory (serial, record->address,
(unsigned char *)record->data, record->data_size,
0xa3);
if (response < 0) {
- err(__FUNCTION__ " - ezusb_writememory failed for first
firmware step (%d %04X %p %d)",
+ err(__FUNCTION__ " - usb_ezusb_writememory failed for first
+firmware step (%d %04X %p %d)",
response, record->address, record->data,
record->data_size);
break;
}
++record;
}
- response = ezusb_set_reset (serial, 1);
+ response = usb_ezusb_set_reset (serial, 1);
record = &whiteheat_firmware[0];
while (record->address < 0x1b40) {
- response = ezusb_writememory (serial, record->address,
+ response = usb_ezusb_writememory (serial, record->address,
(unsigned char *)record->data, record->data_size,
0xa0);
if (response < 0) {
- err(__FUNCTION__" - ezusb_writememory failed for second
firmware step (%d %04X %p %d)",
+ err(__FUNCTION__" - usb_ezusb_writememory failed for second
+firmware step (%d %04X %p %d)",
response, record->address, record->data,
record->data_size);
break;
}
++record;
}
- response = ezusb_set_reset (serial, 0);
+ response = usb_ezusb_set_reset (serial, 0);
/* we want this device to fail to have a driver assigned to it. */
return 1;
diff -Naur -X /home/greg/linux/dontdiff linux-2.4.5-pre1/drivers/usb/usb.c
linux-2.4.5-pre1-greg/drivers/usb/usb.c
--- linux-2.4.5-pre1/drivers/usb/usb.c Thu May 3 13:21:52 2001
+++ linux-2.4.5-pre1-greg/drivers/usb/usb.c Mon May 7 17:44:41 2001
@@ -2119,6 +2119,61 @@
return err;
}
+/**
+ * usb_ezusb_writememory - Writes a chunk of memory to a ezusb device at the
+specified address
+ * @dev: the usb device to write to.
+ * @address: the memory location to write to on the device
+ * @data: a pointer to the data to write to the device
+ * @length: the length of data to write to the device
+ * @bRequest: the command to send to the device to write the data.
+ *
+ * Writes a chunk of memory to a EZ-USB device with the specified command.
+ * Returns a negative error code on failure and 0 on success.
+ */
+int usb_ezusb_writememory (struct usb_device *dev, int address, unsigned char *data,
+int length, __u8 bRequest)
+{
+ int result;
+ unsigned char *transfer_buffer = kmalloc (length, GFP_KERNEL);
+
+#if 0
+ dbg("ezusb_writememory %x, %d", address, length);
+#endif
+
+ if (!transfer_buffer) {
+ err(__FUNCTION__ " - kmalloc(%d) failed.", length);
+ return -ENOMEM;
+ }
+ memcpy (transfer_buffer, data, length);
+ result = usb_control_msg (dev, usb_sndctrlpipe(dev, 0), bRequest, 0x40,
+address, 0, transfer_buffer, length, 300);
+ kfree (transfer_buffer);
+ return result;
+}
+
+
+/**
+ * usb_ezusb_set_reset - Sets the reset bit on a EZ-USB device to the specified
+value
+ * @dev: the usb device to write to.
+ * @reset_bit: the value to write to the reset port on the device.
+ *
+ * Writes a specified value to the EZ-USB device's reset port.
+ * Used when downloading new firmware to a EZ-USB device.
+ * Returns a negative error code on failure and 0 on success.
+ */
+int usb_ezusb_set_reset (struct usb_device *dev, unsigned char reset_bit)
+{
+ int response;
+
+ /* EZ-USB Control and Status Register. Bit 0 controls 8051 reset */
+ #define CPUCS_REG 0x7F92
+
+ dbg(__FUNCTION__ " - %d", reset_bit);
+ response = usb_ezusb_writememory (dev, CPUCS_REG, &reset_bit, 1, 0xa0);
+ if (response < 0) {
+ err(__FUNCTION__ "- %d failed", reset_bit);
+ }
+ return response;
+}
+
/*
* By the time we get here, the device has gotten a new device ID
* and is in the default state. We need to identify the thing and
@@ -2368,3 +2423,7 @@
EXPORT_SYMBOL(usb_bulk_msg);
EXPORT_SYMBOL(usb_devfs_handle);
+
+EXPORT_SYMBOL(usb_ezusb_writememory);
+EXPORT_SYMBOL(usb_ezusb_set_reset);
+
diff -Naur -X /home/greg/linux/dontdiff linux-2.4.5-pre1/include/linux/usb.h
linux-2.4.5-pre1-greg/include/linux/usb.h
--- linux-2.4.5-pre1/include/linux/usb.h Thu May 3 13:21:47 2001
+++ linux-2.4.5-pre1-greg/include/linux/usb.h Mon May 7 17:22:26 2001
@@ -869,6 +869,9 @@
#endif /* CONFIG_USB_DEVICEFS */
+extern int usb_ezusb_writememory (struct usb_device *dev, int address, unsigned char
+*data, int length, __u8 bRequest);
+extern int usb_ezusb_set_reset (struct usb_device *dev, unsigned char reset_bit);
+
#endif /* __KERNEL__ */
#endif