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