xref: /freebsd/sys/dev/usb/uftdiio.h (revision fc43ff0865d8aa624ad8512e377dc9891197c307)
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,
46a9d84a2bSIan Lepore 	UFTDI_BITMODE_NONE = 0xff,
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:
55a9d84a2bSIan Lepore  *   mode   = Unused.
56a9d84a2bSIan Lepore  *   iomask = Returned snapshot of bitbang pin states at time of call.
57a9d84a2bSIan Lepore  */
58a9d84a2bSIan Lepore struct uftdi_bitmode
59a9d84a2bSIan Lepore {
60a9d84a2bSIan Lepore 	uint8_t mode;
61a9d84a2bSIan Lepore 	uint8_t iomask;
62a9d84a2bSIan Lepore };
63a9d84a2bSIan Lepore 
64*fc43ff08SIan Lepore /*
65*fc43ff08SIan Lepore  * For UFTDIIOC_READ_EEPROM, UFTDIIOC_WRITE_EEPROM:
66*fc43ff08SIan Lepore  *
67*fc43ff08SIan Lepore  * IO is done in 16-bit words at the chip level; offset and length are in bytes,
68*fc43ff08SIan Lepore  * but must each be evenly divisible by two.
69*fc43ff08SIan Lepore  *
70*fc43ff08SIan Lepore  * It is not necessary to erase before writing.  For the FT232R device (only)
71*fc43ff08SIan Lepore  * you must set the latency timer to 0x77 before doing a series of eeprom writes
72*fc43ff08SIan Lepore  * (and restore it to the prior value when done).
73*fc43ff08SIan Lepore  */
74*fc43ff08SIan Lepore struct uftdi_eeio
75*fc43ff08SIan Lepore {
76*fc43ff08SIan Lepore 	uint16_t offset;
77*fc43ff08SIan Lepore 	uint16_t length;
78*fc43ff08SIan Lepore 	uint16_t data[64];
79*fc43ff08SIan Lepore };
80*fc43ff08SIan Lepore 
81*fc43ff08SIan Lepore /* Pass this value to confirm that eeprom erase request is not accidental. */
82*fc43ff08SIan Lepore #define	UFTDI_CONFIRM_ERASE	0x26139108
83*fc43ff08SIan 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)
94*fc43ff08SIan Lepore #define	UFTDIIOC_READ_EEPROM	_IOWR('c', 10, struct uftdi_eeio)
95*fc43ff08SIan Lepore #define	UFTDIIOC_WRITE_EEPROM	_IOW('c', 11, struct uftdi_eeio)
96*fc43ff08SIan Lepore #define	UFTDIIOC_ERASE_EEPROM	_IOW('c', 12, int)
97a9d84a2bSIan Lepore 
98a9d84a2bSIan Lepore #endif
99