X-Git-Url: https://oss.titaniummirror.com/gitweb?a=blobdiff_plain;f=src%2Fcp210x.h;h=14a13f422da4291f7585774d9acf8ac815907b0c;hb=e1a0c29481c23a33bdf7dcbfb052cd5b9b440286;hp=9892464a93961a8a472097af290e7895308f3558;hpb=a50a97ae61aefa7a7795e46c71c1eee09ac951b6;p=cp210x.git diff --git a/src/cp210x.h b/src/cp210x.h index 9892464..14a13f4 100644 --- a/src/cp210x.h +++ b/src/cp210x.h @@ -7,47 +7,127 @@ * modify it under the terms of the GNU General Public License version * 2 as published by the Free Software Foundation. * - * Definitions usable by both the cp210x kernel module and userspace. + * Header file shared by both the cp210x kernel module and userspace. * */ #if !defined(CP210X_H) #define CP210X_H +#if defined(__KERNEL__) +#include +#else +#include +#include +#endif + /* CP2103 GPIO ioctls */ -#define IOCTL_GPIOGET 0x8000 /* Get gpio bits */ -#define IOCTL_GPIOSET 0x8001 /* Set gpio bits */ -#define IOCTL_GPIOBIC 0x8002 /* Clear specific gpio bit(s) */ -#define IOCTL_GPIOBIS 0x8003 /* Set specific gpio bit(s) */ +#define CP210x_IOCTL_GPIOGET (SIOCDEVPRIVATE + 0) +#define CP210x_IOCTL_GPIOSET (SIOCDEVPRIVATE + 1) +#define CP210x_IOCTL_GPIOBIC (SIOCDEVPRIVATE + 2) +#define CP210x_IOCTL_GPIOBIS (SIOCDEVPRIVATE + 3) /* CP210x ioctls principally used during initial device configuration */ -#define IOCTL_DEVICERESET 0x8004 /* Reset the cp210x */ -#define IOCTL_PORTCONFGET 0x8005 /* Get port configuration */ -#define IOCTL_PORTCONFSET 0x8006 /* Set port configuration */ -#define IOCTL_SETVID 0x8007 /* Set vendor id */ -#define IOCTL_SETPID 0x8008 /* Set product id */ -#define IOCTL_SETMFG 0x8009 /* Set manufacturer string */ -#define IOCTL_SETPRODUCT 0x800a /* Set product string */ -#define IOCTL_SETSERIAL 0x800b /* Set serial number string */ -#define IOCTL_SETDEVVER 0x800c /* Set device version id */ +#define CP210x_IOCTL_DEVICERESET (SIOCDEVPRIVATE + 4) +#define CP210x_IOCTL_PORTCONFGET (SIOCDEVPRIVATE + 5) +#define CP210x_IOCTL_PORTCONFSET (SIOCDEVPRIVATE + 6) +#define CP210x_IOCTL_SETVID (SIOCDEVPRIVATE + 7) +#define CP210x_IOCTL_SETPID (SIOCDEVPRIVATE + 8) +#define CP210x_IOCTL_SETMFG (SIOCDEVPRIVATE + 9) +#define CP210x_IOCTL_SETPRODUCT (SIOCDEVPRIVATE + 10) +#define CP210x_IOCTL_SETSERIAL (SIOCDEVPRIVATE + 11) +#define CP210x_IOCTL_SETDEVVER (SIOCDEVPRIVATE + 12) /* CP2103 GPIO bit positions */ #define GPIO_0 0x01 #define GPIO_1 0x02 #define GPIO_2 0x04 #define GPIO_3 0x08 -#define GPIO_MASK (GPIO_0|GPIO_1|GPIO_2|GPIO_3) +#define GPIO_MASK (GPIO_3|GPIO_2|GPIO_1|GPIO_0) /* USB descriptor sizes */ #define CP210x_MAX_MFG_STRLEN 255 #define CP210x_MAX_PRODUCT_STRLEN 126 #define CP210x_MAX_SERIAL_STRLEN 63 -/* Used to pass variable sized buffers between user and kernel space (ioctls) */ +#if !defined(__KERNEL__) +/* Mode and latch bit to pin assignments. See AN223 from SiLabs: + * https://www.silabs.com/Support Documents/TechnicalDocs/an223.pdf + * + * 15 - /SUSPEND Can't configure latch + * 14 - SUSPEND Can't configure latch + * 13 - unused + * 12 - unused + * 11 - GPIO_3 + * 10 - GPIO_2 + * 9 - GPIO_1 + * 8 - GPIO_0 + * 7 - /CTS + * 6 - /RTS + * 5 - RXD Note: set latch value to '1' for proper operation. + * 4 - TXD + * 3 - /DSR + * 2 - /DTR + * 1 - /DCD + * 0 - /RI + * + * Mode bit values: + * 1 - A value of one in a bit places the corresponding IO pin in push- + * pull output mode. + * 0 - A value of zero in a bit places the corresponding IO pin in open- + * drain output mode. + * + * Latch bit values: + * 1 - A value of one in a bit sets the corresponding IO pin's value to + * output high. If the mode is push-pull, the pin sources current + * from VIO. If the mode is open-drain, the pin driver is in high + * impedance. + * 0 - A value of zero in a bit sets the corresponding IO pin's value to + * output low. In either mode, push-pull or open-drain, the pin + * driver sinks current to ground. + */ +#define CP210x_CFG_nSUSPEND 0x8000 +#define CP210x_CFG_SUSPEND 0x4000 +#define CP210x_CFG_UNUSED13 0x2000 +#define CP210x_CFG_UNUSED12 0x1000 +#define CP210x_CFG_GPIO_3 0x0800 +#define CP210x_CFG_GPIO_2 0x0400 +#define CP210x_CFG_GPIO_1 0x0200 +#define CP210x_CFG_GPIO_0 0x0100 +#define CP210x_CFG_nCTS 0x0080 +#define CP210x_CFG_nRTS 0x0040 +#define CP210x_CFG_RXD 0x0020 +#define CP210x_CFG_TXD 0x0010 +#define CP210x_CFG_nDSR 0x0008 +#define CP210x_CFG_nDTR 0x0004 +#define CP210x_CFG_nDCD 0x0002 +#define CP210x_CFG_nRI 0x0001 + +/* Enhanced function bits: + * 7 - GPIO dynamic suspend, for 4 GPIO signals + * 6 - Serial dynamic suspend, for 8 UART/Modem signals + * 5 - unused, leave zero + * 4 - Enable weak pull-ups + * 3 - unused, leave zero + * 2 - /RS485_TX on GPIO_2 + * 1 - /RXLED on GPIO_1 + * 0 - /TXLED on GPIO_0 +*/ +#define CP210x_ENH_GPIO_DYNSUSP 0x80 +#define CP210x_ENH_SERIAL_DYNSUSP 0x40 +#define CP210x_ENH_UNUSED5 0x20 +#define CP210x_ENH_PULLUPS 0x10 +#define CP210x_ENH_UNUSED3 0x08 +#define CP210x_ENH_nRS485_TX 0x04 +#define CP210x_ENH_nRXLED 0x02 +#define CP210x_ENH_nTXLED 0x01 +#endif /* __KERNEL__ */ + +/* Used to pass variable size buffers between user and kernel space (ioctls) */ struct cp210x_buffer { __u8 *buf; __s32 len; -} __attribute__((packed)); +}; /* Port config definitions */ struct cp210x_port_state {