usb_serial.h revision 184610
1217309Snwhitehorn/* $NetBSD: ucomvar.h,v 1.9 2001/01/23 21:56:17 augustss Exp $ */ 2217309Snwhitehorn/* $FreeBSD: head/sys/dev/usb2/serial/usb2_serial.h 184610 2008-11-04 02:31:03Z alfred $ */ 3217309Snwhitehorn 4217309Snwhitehorn/*- 5217309Snwhitehorn * Copyright (c) 2001-2002, Shunsuke Akiyama <akiyama@jp.FreeBSD.org>. 6217309Snwhitehorn * All rights reserved. 7217309Snwhitehorn * 8217309Snwhitehorn * Redistribution and use in source and binary forms, with or without 9217309Snwhitehorn * modification, are permitted provided that the following conditions 10217309Snwhitehorn * are met: 11217309Snwhitehorn * 1. Redistributions of source code must retain the above copyright 12217309Snwhitehorn * notice, this list of conditions and the following disclaimer. 13217309Snwhitehorn * 2. Redistributions in binary form must reproduce the above copyright 14217309Snwhitehorn * notice, this list of conditions and the following disclaimer in the 15217309Snwhitehorn * documentation and/or other materials provided with the distribution. 16217309Snwhitehorn * 17217309Snwhitehorn * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18217309Snwhitehorn * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19217309Snwhitehorn * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30/*- 31 * Copyright (c) 1999 The NetBSD Foundation, Inc. 32 * All rights reserved. 33 * 34 * This code is derived from software contributed to The NetBSD Foundation 35 * by Lennart Augustsson (lennart@augustsson.net) at 36 * Carlstedt Research & Technology. 37 * 38 * Redistribution and use in source and binary forms, with or without 39 * modification, are permitted provided that the following conditions 40 * are met: 41 * 1. Redistributions of source code must retain the above copyright 42 * notice, this list of conditions and the following disclaimer. 43 * 2. Redistributions in binary form must reproduce the above copyright 44 * notice, this list of conditions and the following disclaimer in the 45 * documentation and/or other materials provided with the distribution. 46 * 3. All advertising materials mentioning features or use of this software 47 * must display the following acknowledgement: 48 * This product includes software developed by the NetBSD 49 * Foundation, Inc. and its contributors. 50 * 4. Neither the name of The NetBSD Foundation nor the names of its 51 * contributors may be used to endorse or promote products derived 52 * from this software without specific prior written permission. 53 * 54 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 55 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 56 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 57 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 58 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 59 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 60 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 61 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 62 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 63 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 64 * POSSIBILITY OF SUCH DAMAGE. 65 */ 66 67#ifndef _USB2_SERIAL_H_ 68#define _USB2_SERIAL_H_ 69 70#include <sys/tty.h> 71#include <sys/serial.h> 72#include <sys/fcntl.h> 73#include <sys/termios.h> 74 75/* Module interface related macros */ 76#define UCOM_MODVER 1 77 78#define UCOM_MINVER 1 79#define UCOM_PREFVER UCOM_MODVER 80#define UCOM_MAXVER 1 81 82struct usb2_com_softc; 83struct thread; 84 85/* NOTE: Only callbacks with "_cfg_" in its name are called 86 * from a config thread, and are allowed to sleep! The other 87 * callbacks are _not_ allowed to sleep! 88 * 89 * NOTE: There is no guarantee that "usb2_com_cfg_close()" will 90 * be called after "usb2_com_cfg_open()" if the device is detached 91 * while it is open! 92 */ 93struct usb2_com_callback { 94 void (*usb2_com_cfg_get_status) (struct usb2_com_softc *, uint8_t *plsr, uint8_t *pmsr); 95 void (*usb2_com_cfg_set_dtr) (struct usb2_com_softc *, uint8_t); 96 void (*usb2_com_cfg_set_rts) (struct usb2_com_softc *, uint8_t); 97 void (*usb2_com_cfg_set_break) (struct usb2_com_softc *, uint8_t); 98 void (*usb2_com_cfg_param) (struct usb2_com_softc *, struct termios *); 99 void (*usb2_com_cfg_open) (struct usb2_com_softc *); 100 void (*usb2_com_cfg_close) (struct usb2_com_softc *); 101 int (*usb2_com_pre_open) (struct usb2_com_softc *); 102 int (*usb2_com_pre_param) (struct usb2_com_softc *, struct termios *); 103 int (*usb2_com_ioctl) (struct usb2_com_softc *, uint32_t, caddr_t, int, struct thread *); 104 void (*usb2_com_start_read) (struct usb2_com_softc *); 105 void (*usb2_com_stop_read) (struct usb2_com_softc *); 106 void (*usb2_com_start_write) (struct usb2_com_softc *); 107 void (*usb2_com_stop_write) (struct usb2_com_softc *); 108 void (*usb2_com_tty_name) (struct usb2_com_softc *, char *pbuf, uint16_t buflen, uint16_t local_subunit); 109}; 110 111/* Line status register */ 112#define ULSR_RCV_FIFO 0x80 113#define ULSR_TSRE 0x40 /* Transmitter empty: byte sent */ 114#define ULSR_TXRDY 0x20 /* Transmitter buffer empty */ 115#define ULSR_BI 0x10 /* Break detected */ 116#define ULSR_FE 0x08 /* Framing error: bad stop bit */ 117#define ULSR_PE 0x04 /* Parity error */ 118#define ULSR_OE 0x02 /* Overrun, lost incoming byte */ 119#define ULSR_RXRDY 0x01 /* Byte ready in Receive Buffer */ 120#define ULSR_RCV_MASK 0x1f /* Mask for incoming data or error */ 121 122struct usb2_com_super_softc { 123 struct usb2_config_td sc_config_td; 124}; 125 126struct usb2_com_softc { 127 struct termios sc_termios_copy; 128 struct cv sc_cv; 129 const struct usb2_com_callback *sc_callback; 130 struct usb2_com_super_softc *sc_super; 131 struct tty *sc_tty; 132 struct mtx *sc_parent_mtx; 133 void *sc_parent; 134 uint32_t sc_unit; 135 uint32_t sc_local_unit; 136 uint16_t sc_portno; 137 uint8_t sc_flag; 138#define UCOM_FLAG_RTS_IFLOW 0x01 /* use RTS input flow control */ 139#define UCOM_FLAG_GONE 0x02 /* the device is gone */ 140#define UCOM_FLAG_ATTACHED 0x04 /* set if attached */ 141#define UCOM_FLAG_GP_DATA 0x08 /* set if get and put data is possible */ 142#define UCOM_FLAG_WR_START 0x10 /* set if write start was issued */ 143#define UCOM_FLAG_LL_READY 0x20 /* set if low layer is ready */ 144#define UCOM_FLAG_HL_READY 0x40 /* set if high layer is ready */ 145 uint8_t sc_lsr; 146 uint8_t sc_msr; 147 uint8_t sc_mcr; 148 uint8_t sc_ttyfreed; /* set when TTY has been freed */ 149}; 150 151int usb2_com_attach(struct usb2_com_super_softc *ssc, struct usb2_com_softc *sc, uint32_t sub_units, void *parent, const struct usb2_com_callback *callback, struct mtx *p_mtx); 152void usb2_com_detach(struct usb2_com_super_softc *ssc, struct usb2_com_softc *sc, uint32_t sub_units); 153void usb2_com_status_change(struct usb2_com_softc *); 154uint8_t usb2_com_get_data(struct usb2_com_softc *sc, struct usb2_page_cache *pc, uint32_t offset, uint32_t len, uint32_t *actlen); 155void usb2_com_put_data(struct usb2_com_softc *sc, struct usb2_page_cache *pc, uint32_t offset, uint32_t len); 156uint8_t usb2_com_cfg_sleep(struct usb2_com_softc *sc, uint32_t timeout); 157uint8_t usb2_com_cfg_is_gone(struct usb2_com_softc *sc); 158 159#endif /* _USB2_SERIAL_H_ */ 160