xref: /freebsd/sys/dev/usb/uftdiio.h (revision a0465416233e9c948e8c8d5d05d7fa89aab5f188)
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  *  $FreeBSD$
27a9d84a2bSIan Lepore  */
28a9d84a2bSIan Lepore 
29a9d84a2bSIan Lepore /*
30a9d84a2bSIan Lepore  * FTDI USB serial converter chip ioctl commands.
31a9d84a2bSIan Lepore  */
32a9d84a2bSIan Lepore 
33a9d84a2bSIan Lepore #ifndef _USB_UFTDIIO_H_
34a9d84a2bSIan Lepore #define _USB_UFTDIIO_H_
35a9d84a2bSIan Lepore 
36a9d84a2bSIan Lepore #include <sys/ioccom.h>
37a9d84a2bSIan Lepore 
38a9d84a2bSIan Lepore enum uftdi_bitmodes
39a9d84a2bSIan Lepore {
40a9d84a2bSIan Lepore 	UFTDI_BITMODE_ASYNC = 0,
41a9d84a2bSIan Lepore 	UFTDI_BITMODE_MPSSE = 1,
42a9d84a2bSIan Lepore 	UFTDI_BITMODE_SYNC = 2,
43a9d84a2bSIan Lepore 	UFTDI_BITMODE_CPU_EMUL = 3,
44a9d84a2bSIan Lepore 	UFTDI_BITMODE_FAST_SERIAL = 4,
45a9d84a2bSIan Lepore 	UFTDI_BITMODE_CBUS = 5,
46*a0465416SIan Lepore 	UFTDI_BITMODE_NONE = 0xff,	/* aka UART mode. */
47a9d84a2bSIan Lepore };
48a9d84a2bSIan Lepore 
49a9d84a2bSIan Lepore /*
50a9d84a2bSIan Lepore  * For UFTDIIOC_SET_BITMODE:
51a9d84a2bSIan Lepore  *   mode   = One of the uftdi_bitmodes enum values.
52a9d84a2bSIan Lepore  *   iomask = Mask of bits enabled for bitbang output.
53a9d84a2bSIan Lepore  *
54a9d84a2bSIan Lepore  * For UFTDIIOC_GET_BITMODE:
55*a0465416SIan Lepore  *   mode   = Mode most recently set using UFTDIIOC_SET_BITMODE.
56*a0465416SIan Lepore  *   iomask = Returned snapshot of DBUS0..DBUS7 pin states at time of call.
57*a0465416SIan Lepore  *            Pin states can be read in any mode, not just bitbang modes.
58a9d84a2bSIan Lepore  */
59a9d84a2bSIan Lepore struct uftdi_bitmode
60a9d84a2bSIan Lepore {
61a9d84a2bSIan Lepore 	uint8_t mode;
62a9d84a2bSIan Lepore 	uint8_t iomask;
63a9d84a2bSIan Lepore };
64a9d84a2bSIan Lepore 
65fc43ff08SIan Lepore /*
66fc43ff08SIan Lepore  * For UFTDIIOC_READ_EEPROM, UFTDIIOC_WRITE_EEPROM:
67fc43ff08SIan Lepore  *
68fc43ff08SIan Lepore  * IO is done in 16-bit words at the chip level; offset and length are in bytes,
69fc43ff08SIan Lepore  * but must each be evenly divisible by two.
70fc43ff08SIan Lepore  *
71fc43ff08SIan Lepore  * It is not necessary to erase before writing.  For the FT232R device (only)
72fc43ff08SIan Lepore  * you must set the latency timer to 0x77 before doing a series of eeprom writes
73fc43ff08SIan Lepore  * (and restore it to the prior value when done).
74fc43ff08SIan Lepore  */
75fc43ff08SIan Lepore struct uftdi_eeio
76fc43ff08SIan Lepore {
77fc43ff08SIan Lepore 	uint16_t offset;
78fc43ff08SIan Lepore 	uint16_t length;
79fc43ff08SIan Lepore 	uint16_t data[64];
80fc43ff08SIan Lepore };
81fc43ff08SIan Lepore 
82fc43ff08SIan Lepore /* Pass this value to confirm that eeprom erase request is not accidental. */
83fc43ff08SIan Lepore #define	UFTDI_CONFIRM_ERASE	0x26139108
84fc43ff08SIan Lepore 
85a9d84a2bSIan Lepore #define	UFTDIIOC_RESET_IO	_IO('c', 0)	/* Reset config, flush fifos.*/
86a9d84a2bSIan Lepore #define	UFTDIIOC_RESET_RX	_IO('c', 1)	/* Flush input fifo. */
87a9d84a2bSIan Lepore #define	UFTDIIOC_RESET_TX	_IO('c', 2)	/* Flush output fifo. */
88a9d84a2bSIan Lepore #define	UFTDIIOC_SET_BITMODE	_IOW('c', 3, struct uftdi_bitmode)
89a9d84a2bSIan Lepore #define	UFTDIIOC_GET_BITMODE	_IOR('c', 4, struct uftdi_bitmode)
90a9d84a2bSIan Lepore #define	UFTDIIOC_SET_ERROR_CHAR	_IOW('c', 5, int)	/* -1 to disable */
91a9d84a2bSIan Lepore #define	UFTDIIOC_SET_EVENT_CHAR	_IOW('c', 6, int)	/* -1 to disable */
92a9d84a2bSIan Lepore #define	UFTDIIOC_SET_LATENCY	_IOW('c', 7, int)	/* 1-255 ms */
93a9d84a2bSIan Lepore #define	UFTDIIOC_GET_LATENCY	_IOR('c', 8, int)
94a9d84a2bSIan Lepore #define	UFTDIIOC_GET_HWREV	_IOR('c', 9, int)
95fc43ff08SIan Lepore #define	UFTDIIOC_READ_EEPROM	_IOWR('c', 10, struct uftdi_eeio)
96fc43ff08SIan Lepore #define	UFTDIIOC_WRITE_EEPROM	_IOW('c', 11, struct uftdi_eeio)
97fc43ff08SIan Lepore #define	UFTDIIOC_ERASE_EEPROM	_IOW('c', 12, int)
98a9d84a2bSIan Lepore 
99a9d84a2bSIan Lepore #endif
100