> On Fri, Feb 21, 2003 at 10:04:14PM +0100, Thomas Jarosch wrote:
> > This is a patch against the ftdi_sio 1.3.0 driver + interim patch.
> > The new driver should be out soon...
>
> Can you post it not compressed so we can read it?
Sure. I compressed it to save bandwith...
Thomas
diff -u -r -b driver.clean/ftdi_sio.c driver.new/ftdi_sio.c
--- driver.clean/ftdi_sio.c 2003-02-19 18:42:20.000000000 +0100
+++ driver.new/ftdi_sio.c 2003-02-19 20:08:14.000000000 +0100
@@ -932,7 +932,7 @@
int user_bytes_sent = 0 ; /* amount of user data sent */
/* Variables for urb pool management */
- unsigned char *current_position = buf;
+ unsigned char *current_position = (unsigned char *)buf;
int i;
struct urb *urb; /* pointer to urb from urb pool */
unsigned long flags;
@@ -1051,7 +1051,6 @@
{
struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
- unsigned long flags;
dbg("%s", __FUNCTION__);
@@ -1417,9 +1416,12 @@
struct usb_serial *serial = port->serial;
struct ftdi_private *priv = (struct ftdi_private *)port->private;
+ ftdi_bitbang_t bitbang;
+ ftdi_eeprom_t eeprom;
+
__u16 urb_value=0; /* Will hold the new flags */
char buf[2];
- int ret, mask;
+ int ret, mask, i;
dbg("%s cmd 0x%04x", __FUNCTION__, cmd);
@@ -1572,17 +1574,157 @@
*/
}
}
- /* NOTREACHED */
+ }
+
+ if (_IOC_TYPE(cmd) == FTDI_IOCTL_CHAR) {
+ switch (_IOC_NR (cmd)) {
+
+ case _IOC_NR(FTDI_IOCTL_SET_BITBANG_MODE):
+ copy_from_user (&bitbang, (void *)arg, sizeof (ftdi_bitbang_t));
+
+ urb_value = bitbang.bitmask;
+ urb_value += bitbang.enable << 8;
+
+ if ((ret = usb_control_msg(serial->dev,
+ usb_sndctrlpipe(serial->dev, 0),
+ FTDI_SET_BITBANG_MODE_REQUEST,
+ FTDI_SET_BITBANG_MODE_REQUEST_TYPE,
+ urb_value, 0,
+ buf, 0, WDR_TIMEOUT)) < 0 ) {
+ err("%s: Could not set Bit Bang mode - err: %d",
+ __FUNCTION__, ret);
+ return(ret);
+ }
+
+ if (bitbang.enable)
+ dbg ("%s: Enabled Bit Bang mode\n", __FUNCTION__);
+ else
+ dbg ("%s: Disabled Bit Bang mode\n", __FUNCTION__);
+
+ return 0;
+ break;
+ case _IOC_NR(FTDI_IOCTL_GET_DATAPINS):
+ if ((ret = usb_control_msg(serial->dev,
+ usb_rcvctrlpipe(serial->dev, 0),
+ FTDI_GET_DATAPINS_REQUEST,
+ FTDI_GET_DATAPINS_REQUEST_TYPE,
+ 0, 0,
+ buf, 1, WDR_TIMEOUT)) < 0 ) {
+ err("%s: Could not read pins directly - err: %d",
+ __FUNCTION__, ret);
+ return(ret);
+ }
+
+ dbg ("%s: Read pins: %d\n", __FUNCTION__, (unsigned char)buf[0]);
+
+ if (copy_to_user((void *)arg, &buf, 1))
+ return -EFAULT;
+ return 0;
+ break;
+ case _IOC_NR(FTDI_IOCTL_GET_EEPROM):
+ for (i = 0; i < 64; i++) {
+ if ((ret = usb_control_msg(serial->dev,
+ usb_rcvctrlpipe(serial->dev, 0),
+ FTDI_E2_READ_REQUEST,
+ FTDI_E2_READ_REQUEST_TYPE,
+ 0, i,
+ buf, 2, WDR_TIMEOUT)) < 0 ) {
+ err("%s: Could not read pins directly - err: %d",
+ __FUNCTION__, ret);
+ return(ret);
+ }
+
+ eeprom.data[i*2] = buf[0];
+ eeprom.data[(i*2)+1] = buf[1];
+ }
+
+ if (copy_to_user((void *)arg, &eeprom, sizeof(ftdi_eeprom_t)))
+ return -EFAULT;
+
+ return 0;
+ break;
+
+ case _IOC_NR(FTDI_IOCTL_SET_EEPROM):
+ copy_from_user (&eeprom, (void *)arg, sizeof (ftdi_eeprom_t));
+
+ for (i = 0; i < 64; i++) {
+ urb_value = eeprom.data[i*2];
+ urb_value += eeprom.data[(i*2)+1] << 8;
+
+ if ((ret = usb_control_msg(serial->dev,
+ usb_sndctrlpipe(serial->dev, 0),
+ FTDI_E2_WRITE_REQUEST,
+ FTDI_E2_WRITE_REQUEST_TYPE,
+ urb_value, i,
+ buf, 0, WDR_TIMEOUT)) < 0 ) {
+ err("%s: Could write eeprom - err: %d",
+ __FUNCTION__, ret);
+ return(ret);
+ }
+
+ }
+
+ return 0;
+ break;
+ case _IOC_NR(FTDI_IOCTL_ERASE_EEPROM):
+ info ("Erasing eeprom!");
+
+ if ((ret = usb_control_msg(serial->dev,
+ usb_sndctrlpipe(serial->dev, 0),
+ FTDI_E2_ERASE_REQUEST,
+ FTDI_E2_ERASE_REQUEST_TYPE,
+ 0, 0,
+ buf, 0, WDR_TIMEOUT)) < 0 ) {
+ err("%s: Could not erase eeprom - err: %d",
+ __FUNCTION__, ret);
+ return(ret);
+ }
+
+ return 0;
+ break;
+ case _IOC_NR(FTDI_IOCTL_SET_LATENCY):
+ urb_value = 0;
+ copy_from_user (&urb_value, (void *)arg, 1);
+
+ if ((ret = usb_control_msg(serial->dev,
+ usb_sndctrlpipe(serial->dev, 0),
+ FTDI_SET_LATENCY_REQUEST,
+ FTDI_SET_LATENCY_REQUEST_TYPE,
+ urb_value, 0,
+ buf, 0, WDR_TIMEOUT)) < 0 ) {
+ err("%s: Could not set latency - err: %d",
+ __FUNCTION__, ret);
+ return(ret);
+ }
+ return 0;
+ break;
+ case _IOC_NR(FTDI_IOCTL_GET_LATENCY):
+ if ((ret = usb_control_msg(serial->dev,
+ usb_rcvctrlpipe(serial->dev, 0),
+ FTDI_GET_LATENCY_REQUEST,
+ FTDI_GET_LATENCY_REQUEST_TYPE,
+ 0, 0,
+ buf, 1, WDR_TIMEOUT)) < 0 ) {
+ err("%s: Could not get latency - err: %d",
+ __FUNCTION__, ret);
+ return(ret);
+ }
+
+ dbg ("%s: Read latency: %d", __FUNCTION__, (unsigned char)buf[0]);
+
+ if (copy_to_user((void *)arg, &buf, 1))
+ return -EFAULT;
+ return 0;
+ break;
+ }
+
+ }
- default:
/* This is not an error - turns out the higher layers will do
* some ioctls itself (see comment above)
*/
- dbg("%s arg not supported - it was 0x%04x", __FUNCTION__,cmd);
+ dbg("%s arg not supported - it was 0x%04x", __FUNCTION__, cmd);
return(-ENOIOCTLCMD);
- break;
- }
- return 0;
} /* ftdi_ioctl */
diff -u -r -b driver.clean/ftdi_sio.h driver.new/ftdi_sio.h
--- driver.clean/ftdi_sio.h 2003-02-19 18:42:20.000000000 +0100
+++ driver.new/ftdi_sio.h 2003-02-19 19:58:19.000000000 +0100
@@ -41,6 +41,16 @@
#define FTDI_SIO_SET_EVENT_CHAR 6 /* Set the event character */
#define FTDI_SIO_SET_ERROR_CHAR 7 /* Set the error character */
+#define FTDI_SET_BITBANG_MODE 0xB /* Set the Bit Bang mode of BM type chips */
+#define FTDI_GET_DATAPINS 0xC /* Read the current status of the pins directly */
+
+#define FTDI_E2_READ 0x90 /* Read a word of data from eeprom */
+#define FTDI_E2_WRITE 0x91 /* Write a word of data to eeprom */
+#define FTDI_E2_ERASE 0x92 /* Erase the whole eeprom */
+
+#define FTDI_SET_LATENCY 0x9 /* Set latency of the FTDI input buffer */
+#define FTDI_GET_LATENCY 0x9 /* Get latency of the FTDI input buffer */
+
/* Port Identifier Table */
#define PIT_DEFAULT 0 /* SIOA */
#define PIT_SIOA 1 /* SIOA */
@@ -83,7 +93,7 @@
/* FTDI_SIO_SET_BAUDRATE */
#define FTDI_SIO_SET_BAUDRATE_REQUEST_TYPE 0x40
-#define FTDI_SIO_SET_BAUDRATE_REQUEST 3
+#define FTDI_SIO_SET_BAUDRATE_REQUEST FTDI_SIO_SET_BAUD_RATE
/*
* BmRequestType: 0100 0000B
@@ -362,6 +372,159 @@
* 1 = active
*/
+/* FTDI_SET_BITBANG_MODE
+ * Enables or disables the Bit Bang Mode of BM type chips
+ * This mode replaces the normal function of the chip and turns
+ * the 8 pins to an 8-bit bi-directional bus.
+ *
+ * The clock for the Bit Bang mode is actually 16 times the baudrate.
+ A value of 9600 baud would transfer the data at (9600 x 16) = 153600 bytes
+ per second or 1 every 6,5 uS
+*/
+
+#define FTDI_SET_BITBANG_MODE_REQUEST_TYPE 0x40
+#define FTDI_SET_BITBANG_MODE_REQUEST FTDI_SET_BITBANG_MODE
+
+/*
+ * BmRequestType: 0100 0000b
+ * bRequest: FTDI_SET_BITBANG_MODE
+ * wValue: lValue: Bit Mask, hValue: Enable
+ * wIndex: 0
+ * wLength: 0
+ * Data: None
+ *
+ * lValue: Bitmask: The bitmask byte sets the direction of the pins.
+ * A '1' means the corresponding bit is to be an output,
+ * a '0' means the corresponding bit is to be an input.
+ *
+ * hValue: 1 turns Bit Bang mode on, 0 turns Bit Bang mode off
+ *
+ */
+
+/* FTDI_GET_DATAPINS */
+/* Immediate read of the 8 data pins
+ * This function is very useful in combination with the Bit Bang mode
+ *
+ * Note: Data in the read pipe can be older than this as it is
+ continuously sample the pins until its buffers become full
+ *
+*/
+
+#define FTDI_GET_DATAPINS_REQUEST_TYPE 0x40
+#define FTDI_GET_DATAPINS_REQUEST FTDI_GET_DATAPINS
+
+/*
+ * BmRequestType: 1100 0000b
+ * bRequest: FTDI_GET_DATAPINS
+ * wValue: 0
+ * wIndex: 0
+ * wLength: 1
+ * Data: Current status of the pins
+ *
+ */
+
+
+#define FTDI_E2_READ_REQUEST_TYPE 0xC0
+#define FTDI_E2_READ_REQUEST FTDI_E2_READ
+
+/*
+ * BmRequestType: 1100 0000b
+ * bRequest: FTDI_E2_READ
+ * wValue: 0
+ * wIndex: Address of word to read
+ * wLength: 2
+ * Data: Will return a word of data from E2Address
+ *
+ */
+
+#define FTDI_E2_WRITE_REQUEST_TYPE 0x40
+#define FTDI_E2_WRITE_REQUEST FTDI_E2_WRITE
+
+/*
+ * BmRequestType: 1100 0000b
+ * bRequest: FTDI_E2_WRITE
+ * wValue: Word to write
+ * wIndex: Address of word to read
+ * wLength: 0
+ * Data: None
+ *
+ */
+
+#define FTDI_E2_ERASE_REQUEST_TYPE 0x40
+#define FTDI_E2_ERASE_REQUEST FTDI_E2_ERASE
+
+/*
+ * BmRequestType: 1100 0000b
+ * bRequest: FTDI_E2_ERASE
+ * wValue: 0
+ * wIndex: 0
+ * wLength: 0
+ * Data: None
+ *
+ */
+
+/* FTDI_SET_LATENCY
+ * Value is the time in milliseconds between sending data back
+ * to the PC when there is less than a full buffer. It should
+ * be in the range 1-255. The default value is 16ms for compatibility.
+*/
+
+#define FTDI_SET_LATENCY_REQUEST_TYPE 0x40
+#define FTDI_SET_LATENCY_REQUEST FTDI_SET_LATENCY
+
+/*
+ * BmRequestType: 0100 0000b
+ * bRequest: FTDI_SET_LATENCY
+ * wValue: lValue: Value, hValue: 0
+ * wIndex: 0
+ * wLength: 0
+ * Data: None
+ *
+ */
+
+/* FTDI_GET_LATENCY
+ * Get the latency of the FTDI chip input buffer.
+ See above for a more detailed explanation.
+*/
+
+#define FTDI_GET_LATENCY_REQUEST_TYPE 0xC0
+#define FTDI_GET_LATENCY_REQUEST FTDI_GET_LATENCY
+
+/*
+ * BmRequestType: 1100 0000b
+ * bRequest: FTDI_GET_LATENCY
+ * wValue: 0
+ * wIndex: 0
+ * wLength: 1
+ * Data: Current latency of the FTDI chip input buffer
+ *
+ */
+
+
+/*
+ Special FTDI ioctls like Bit Bang Mode (BM type chips)
+ or eeprom reading/writing/erasing
+*/
+
+#define FTDI_IOCTL_CHAR 'N'
+#define FTDI_IOCTL_BASE 0x20
+
+typedef struct {
+ unsigned char enable;
+ unsigned char bitmask; /* description of bitmask: see above */
+} ftdi_bitbang_t;
+
+typedef struct {
+ unsigned char data[128]; /* eeprom size is fixed to 128 bytes by hardware */
+} ftdi_eeprom_t;
+
+#define FTDI_IOCTL_SET_BITBANG_MODE _IOW (FTDI_IOCTL_CHAR, FTDI_IOCTL_BASE,
ftdi_bitbang_t)
+#define FTDI_IOCTL_GET_DATAPINS _IOR (FTDI_IOCTL_CHAR, FTDI_IOCTL_BASE+1, unsigned
char)
+#define FTDI_IOCTL_GET_EEPROM _IOWR (FTDI_IOCTL_CHAR, FTDI_IOCTL_BASE+2,
ftdi_eeprom_t)
+#define FTDI_IOCTL_SET_EEPROM _IOW (FTDI_IOCTL_CHAR, FTDI_IOCTL_BASE+3, ftdi_eeprom_t)
+#define FTDI_IOCTL_ERASE_EEPROM _IO (FTDI_IOCTL_CHAR, FTDI_IOCTL_BASE+4)
+#define FTDI_IOCTL_SET_LATENCY _IOW (FTDI_IOCTL_CHAR, FTDI_IOCTL_BASE+5, unsigned
char)
+#define FTDI_IOCTL_GET_LATENCY _IOR (FTDI_IOCTL_CHAR, FTDI_IOCTL_BASE+6, unsigned
char)
/* Descriptors returned by the device
-------------------------------------------------------
This SF.net email is sponsored by: SlickEdit Inc. Develop an edge.
The most comprehensive and flexible code editor you can use.
Code faster. C/C++, C#, Java, HTML, XML, many more. FREE 30-Day Trial.
www.slickedit.com/sourceforge
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel