Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[9f1646]: cp210x.patch Maximize Restore History

Download this file

cp210x.patch    103 lines (97 with data), 3.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
--- a/cp210x.c 2013-10-30 18:43:43.000000000 -0600
+++ b/cp210x.c 2013-10-30 19:23:02.410147064 -0600
@@ -31,6 +31,8 @@
*/
static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *);
static void cp210x_close(struct usb_serial_port *);
+static int cp210x_ioctl(struct tty_struct *tty,
+ unsigned int cmd, unsigned long arg);
static void cp210x_get_termios(struct tty_struct *, struct usb_serial_port *);
static void cp210x_get_termios_port(struct usb_serial_port *port,
unsigned int *cflagp, unsigned int *baudp);
@@ -174,6 +176,7 @@
.bulk_out_size = 256,
.open = cp210x_open,
.close = cp210x_close,
+ .ioctl = cp210x_ioctl,
.break_ctl = cp210x_break_ctl,
.set_termios = cp210x_set_termios,
.tiocmget = cp210x_tiocmget,
@@ -187,6 +190,10 @@
&cp210x_device, NULL
};
+/* IOCTLs */
+#define IOCTL_GPIOGET 0x8000
+#define IOCTL_GPIOSET 0x8001
+
/* Config request types */
#define REQTYPE_HOST_TO_INTERFACE 0x41
#define REQTYPE_INTERFACE_TO_HOST 0xc1
@@ -220,11 +227,16 @@
#define CP210X_SET_CHARS 0x19
#define CP210X_GET_BAUDRATE 0x1D
#define CP210X_SET_BAUDRATE 0x1E
+#define CP210X_VENDOR_SPECIFIC 0xFF
/* CP210X_IFC_ENABLE */
#define UART_ENABLE 0x0001
#define UART_DISABLE 0x0000
+/* CP210X_VENDOR_SPECIFIC */
+#define CP210X_WRITE_LATCH 0x37E1
+#define CP210X_READ_LATCH 0x00C2
+
/* CP210X_(SET|GET)_BAUDDIV */
#define BAUD_RATE_GEN_FREQ 0x384000
@@ -449,6 +461,54 @@
mutex_unlock(&port->serial->disc_mutex);
}
+static int cp210x_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
+{
+ struct usb_serial_port *port = tty->driver_data;
+ struct usb_serial *serial = port->serial;
+ int result = 0;
+ struct cp210x_serial_private *spriv = usb_get_serial_data(serial);
+ unsigned int latch_setting = 0;
+
+ switch (cmd) {
+ case IOCTL_GPIOGET:
+ result = usb_control_msg(
+ serial->dev,
+ usb_rcvctrlpipe(serial->dev, 0),
+ CP210X_VENDOR_SPECIFIC,
+ REQTYPE_DEVICE_TO_HOST,
+ CP210X_READ_LATCH,
+ spriv->bInterfaceNumber,
+ &latch_setting, 1,
+ USB_CTRL_GET_TIMEOUT);
+ if (result != 1)
+ return -EPROTO;
+ *(unsigned long *)arg = (unsigned long)latch_setting;
+ return 0;
+ break;
+ case IOCTL_GPIOSET:
+ latch_setting = *(unsigned int *)arg & 0x000000FF;
+ //why [23:16] bits are taken for value is unknown
+ latch_setting |= (*(unsigned int *)arg & 0x00FF0000) >> 8;
+
+ result = usb_control_msg(
+ serial->dev,
+ usb_sndctrlpipe(serial->dev, 0),
+ CP210X_VENDOR_SPECIFIC,
+ REQTYPE_HOST_TO_DEVICE,
+ CP210X_WRITE_LATCH,
+ latch_setting,
+ NULL, 0,
+ USB_CTRL_SET_TIMEOUT);
+ if (result != 0)
+ return -EPROTO;
+ return 0;
+ break;
+ default:
+ break;
+ }
+ return -ENOIOCTLCMD;
+}
+
/*
* cp210x_get_termios
* Reads the baud rate, data bits, parity, stop bits and flow control mode