xref: /freebsd/sys/dev/usb/uftdiio.h (revision 2ff63af9b88c7413b7d71715b5532625752a248e)
1a9d84a2bSIan Lepore /*-
2a9d84a2bSIan Lepore  * Copyright 2008-2012 - Symmetricom, Inc.
3a9d84a2bSIan Lepore  * All rights reserved.
4a9d84a2bSIan Lepore  *
5a9d84a2bSIan Lepore  * Redistribution and use in source and binary forms, with or without
6a9d84a2bSIan Lepore  * modification, are permitted provided that the following conditions
7a9d84a2bSIan Lepore  * are met:
8a9d84a2bSIan Lepore  * 1. Redistributions of source code must retain the above copyright
9a9d84a2bSIan Lepore  *    notice, this list of conditions, and the following disclaimer.
10a9d84a2bSIan Lepore  * 2. Redistributions in binary form must reproduce the above copyright
11a9d84a2bSIan Lepore  *    notice, this list of conditions and the following disclaimer in the
12a9d84a2bSIan Lepore  *    documentation and/or other materials provided with the distribution.
13a9d84a2bSIan Lepore  *
14a9d84a2bSIan Lepore  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15a9d84a2bSIan Lepore  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16a9d84a2bSIan Lepore  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17a9d84a2bSIan Lepore  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
18a9d84a2bSIan Lepore  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19a9d84a2bSIan Lepore  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20a9d84a2bSIan Lepore  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21a9d84a2bSIan Lepore  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22a9d84a2bSIan Lepore  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23a9d84a2bSIan Lepore  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24a9d84a2bSIan Lepore  * SUCH DAMAGE.
25a9d84a2bSIan Lepore  *
26a9d84a2bSIan Lepore  */
27a9d84a2bSIan Lepore 
28a9d84a2bSIan Lepore /*
29a9d84a2bSIan Lepore  * FTDI USB serial converter chip ioctl commands.
30a9d84a2bSIan Lepore  */
31a9d84a2bSIan Lepore 
32a9d84a2bSIan Lepore #ifndef _USB_UFTDIIO_H_
33a9d84a2bSIan Lepore #define _USB_UFTDIIO_H_
34a9d84a2bSIan Lepore 
35a9d84a2bSIan Lepore #include <sys/ioccom.h>
36a9d84a2bSIan Lepore 
37a9d84a2bSIan Lepore enum uftdi_bitmodes
38a9d84a2bSIan Lepore {
39a9d84a2bSIan Lepore 	UFTDI_BITMODE_ASYNC = 0,
40a9d84a2bSIan Lepore 	UFTDI_BITMODE_MPSSE = 1,
41a9d84a2bSIan Lepore 	UFTDI_BITMODE_SYNC = 2,
42a9d84a2bSIan Lepore 	UFTDI_BITMODE_CPU_EMUL = 3,
43a9d84a2bSIan Lepore 	UFTDI_BITMODE_FAST_SERIAL = 4,
44a9d84a2bSIan Lepore 	UFTDI_BITMODE_CBUS = 5,
45*a0465416SIan Lepore 	UFTDI_BITMODE_NONE = 0xff,	/* aka UART mode. */
46a9d84a2bSIan Lepore };
47a9d84a2bSIan Lepore 
48a9d84a2bSIan Lepore /*
49a9d84a2bSIan Lepore  * For UFTDIIOC_SET_BITMODE:
50a9d84a2bSIan Lepore  *   mode   = One of the uftdi_bitmodes enum values.
51a9d84a2bSIan Lepore  *   iomask = Mask of bits enabled for bitbang output.
52a9d84a2bSIan Lepore  *
53a9d84a2bSIan Lepore  * For UFTDIIOC_GET_BITMODE:
54*a0465416SIan Lepore  *   mode   = Mode most recently set using UFTDIIOC_SET_BITMODE.
55*a0465416SIan Lepore  *   iomask = Returned snapshot of DBUS0..DBUS7 pin states at time of call.
56*a0465416SIan Lepore  *            Pin states can be read in any mode, not just bitbang modes.
57a9d84a2bSIan Lepore  */
58a9d84a2bSIan Lepore struct uftdi_bitmode
59a9d84a2bSIan Lepore {
60a9d84a2bSIan Lepore 	uint8_t mode;
61a9d84a2bSIan Lepore 	uint8_t iomask;
62a9d84a2bSIan Lepore };
63a9d84a2bSIan Lepore 
64fc43ff08SIan Lepore /*
65fc43ff08SIan Lepore  * For UFTDIIOC_READ_EEPROM, UFTDIIOC_WRITE_EEPROM:
66fc43ff08SIan Lepore  *
67fc43ff08SIan Lepore  * IO is done in 16-bit words at the chip level; offset and length are in bytes,
68fc43ff08SIan Lepore  * but must each be evenly divisible by two.
69fc43ff08SIan Lepore  *
70fc43ff08SIan Lepore  * It is not necessary to erase before writing.  For the FT232R device (only)
71fc43ff08SIan Lepore  * you must set the latency timer to 0x77 before doing a series of eeprom writes
72fc43ff08SIan Lepore  * (and restore it to the prior value when done).
73fc43ff08SIan Lepore  */
74fc43ff08SIan Lepore struct uftdi_eeio
75fc43ff08SIan Lepore {
76fc43ff08SIan Lepore 	uint16_t offset;
77fc43ff08SIan Lepore 	uint16_t length;
78fc43ff08SIan Lepore 	uint16_t data[64];
79fc43ff08SIan Lepore };
80fc43ff08SIan Lepore 
81fc43ff08SIan Lepore /* Pass this value to confirm that eeprom erase request is not accidental. */
82fc43ff08SIan Lepore #define	UFTDI_CONFIRM_ERASE	0x26139108
83fc43ff08SIan Lepore 
84a9d84a2bSIan Lepore #define	UFTDIIOC_RESET_IO	_IO('c', 0)	/* Reset config, flush fifos.*/
85a9d84a2bSIan Lepore #define	UFTDIIOC_RESET_RX	_IO('c', 1)	/* Flush input fifo. */
86a9d84a2bSIan Lepore #define	UFTDIIOC_RESET_TX	_IO('c', 2)	/* Flush output fifo. */
87a9d84a2bSIan Lepore #define	UFTDIIOC_SET_BITMODE	_IOW('c', 3, struct uftdi_bitmode)
88a9d84a2bSIan Lepore #define	UFTDIIOC_GET_BITMODE	_IOR('c', 4, struct uftdi_bitmode)
89a9d84a2bSIan Lepore #define	UFTDIIOC_SET_ERROR_CHAR	_IOW('c', 5, int)	/* -1 to disable */
90a9d84a2bSIan Lepore #define	UFTDIIOC_SET_EVENT_CHAR	_IOW('c', 6, int)	/* -1 to disable */
91a9d84a2bSIan Lepore #define	UFTDIIOC_SET_LATENCY	_IOW('c', 7, int)	/* 1-255 ms */
92a9d84a2bSIan Lepore #define	UFTDIIOC_GET_LATENCY	_IOR('c', 8, int)
93a9d84a2bSIan Lepore #define	UFTDIIOC_GET_HWREV	_IOR('c', 9, int)
94fc43ff08SIan Lepore #define	UFTDIIOC_READ_EEPROM	_IOWR('c', 10, struct uftdi_eeio)
95fc43ff08SIan Lepore #define	UFTDIIOC_WRITE_EEPROM	_IOW('c', 11, struct uftdi_eeio)
96fc43ff08SIan Lepore #define	UFTDIIOC_ERASE_EEPROM	_IOW('c', 12, int)
97a9d84a2bSIan Lepore 
98a9d84a2bSIan Lepore #endif
99