102ac6454SAndrew Thompson /* $NetBSD: ucomvar.h,v 1.9 2001/01/23 21:56:17 augustss Exp $ */ 202ac6454SAndrew Thompson /* $FreeBSD$ */ 302ac6454SAndrew Thompson 402ac6454SAndrew Thompson /*- 502ac6454SAndrew Thompson * Copyright (c) 2001-2002, Shunsuke Akiyama <akiyama@jp.FreeBSD.org>. 602ac6454SAndrew Thompson * All rights reserved. 702ac6454SAndrew Thompson * 802ac6454SAndrew Thompson * Redistribution and use in source and binary forms, with or without 902ac6454SAndrew Thompson * modification, are permitted provided that the following conditions 1002ac6454SAndrew Thompson * are met: 1102ac6454SAndrew Thompson * 1. Redistributions of source code must retain the above copyright 1202ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer. 1302ac6454SAndrew Thompson * 2. Redistributions in binary form must reproduce the above copyright 1402ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer in the 1502ac6454SAndrew Thompson * documentation and/or other materials provided with the distribution. 1602ac6454SAndrew Thompson * 1702ac6454SAndrew Thompson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1802ac6454SAndrew Thompson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1902ac6454SAndrew Thompson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2002ac6454SAndrew Thompson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2102ac6454SAndrew Thompson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2202ac6454SAndrew Thompson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2302ac6454SAndrew Thompson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2402ac6454SAndrew Thompson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2502ac6454SAndrew Thompson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2602ac6454SAndrew Thompson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2702ac6454SAndrew Thompson * SUCH DAMAGE. 2802ac6454SAndrew Thompson */ 2902ac6454SAndrew Thompson 3002ac6454SAndrew Thompson /*- 3102ac6454SAndrew Thompson * Copyright (c) 1999 The NetBSD Foundation, Inc. 3202ac6454SAndrew Thompson * All rights reserved. 3302ac6454SAndrew Thompson * 3402ac6454SAndrew Thompson * This code is derived from software contributed to The NetBSD Foundation 3502ac6454SAndrew Thompson * by Lennart Augustsson (lennart@augustsson.net) at 3602ac6454SAndrew Thompson * Carlstedt Research & Technology. 3702ac6454SAndrew Thompson * 3802ac6454SAndrew Thompson * Redistribution and use in source and binary forms, with or without 3902ac6454SAndrew Thompson * modification, are permitted provided that the following conditions 4002ac6454SAndrew Thompson * are met: 4102ac6454SAndrew Thompson * 1. Redistributions of source code must retain the above copyright 4202ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer. 4302ac6454SAndrew Thompson * 2. Redistributions in binary form must reproduce the above copyright 4402ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer in the 4502ac6454SAndrew Thompson * documentation and/or other materials provided with the distribution. 4602ac6454SAndrew Thompson * 3. All advertising materials mentioning features or use of this software 4702ac6454SAndrew Thompson * must display the following acknowledgement: 4802ac6454SAndrew Thompson * This product includes software developed by the NetBSD 4902ac6454SAndrew Thompson * Foundation, Inc. and its contributors. 5002ac6454SAndrew Thompson * 4. Neither the name of The NetBSD Foundation nor the names of its 5102ac6454SAndrew Thompson * contributors may be used to endorse or promote products derived 5202ac6454SAndrew Thompson * from this software without specific prior written permission. 5302ac6454SAndrew Thompson * 5402ac6454SAndrew Thompson * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 5502ac6454SAndrew Thompson * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 5602ac6454SAndrew Thompson * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 5702ac6454SAndrew Thompson * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 5802ac6454SAndrew Thompson * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 5902ac6454SAndrew Thompson * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 6002ac6454SAndrew Thompson * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 6102ac6454SAndrew Thompson * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 6202ac6454SAndrew Thompson * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 6302ac6454SAndrew Thompson * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 6402ac6454SAndrew Thompson * POSSIBILITY OF SUCH DAMAGE. 6502ac6454SAndrew Thompson */ 6602ac6454SAndrew Thompson 6775973647SAndrew Thompson #ifndef _USB_SERIAL_H_ 6875973647SAndrew Thompson #define _USB_SERIAL_H_ 6902ac6454SAndrew Thompson 7002ac6454SAndrew Thompson #include <sys/tty.h> 7102ac6454SAndrew Thompson #include <sys/serial.h> 7202ac6454SAndrew Thompson #include <sys/fcntl.h> 733a4a1a7fSHans Petter Selasky #include <sys/sysctl.h> 7402ac6454SAndrew Thompson 7502ac6454SAndrew Thompson /* Module interface related macros */ 7602ac6454SAndrew Thompson #define UCOM_MODVER 1 7702ac6454SAndrew Thompson 7802ac6454SAndrew Thompson #define UCOM_MINVER 1 7902ac6454SAndrew Thompson #define UCOM_PREFVER UCOM_MODVER 8002ac6454SAndrew Thompson #define UCOM_MAXVER 1 8102ac6454SAndrew Thompson 82760bc48eSAndrew Thompson struct usb_device; 83760bc48eSAndrew Thompson struct ucom_softc; 84760bc48eSAndrew Thompson struct usb_device_request; 8502ac6454SAndrew Thompson struct thread; 8602ac6454SAndrew Thompson 8702ac6454SAndrew Thompson /* 88a593f6b8SAndrew Thompson * NOTE: There is no guarantee that "ucom_cfg_close()" will 89a593f6b8SAndrew Thompson * be called after "ucom_cfg_open()" if the device is detached 9002ac6454SAndrew Thompson * while it is open! 9102ac6454SAndrew Thompson */ 92760bc48eSAndrew Thompson struct ucom_callback { 93a593f6b8SAndrew Thompson void (*ucom_cfg_get_status) (struct ucom_softc *, uint8_t *plsr, uint8_t *pmsr); 94a593f6b8SAndrew Thompson void (*ucom_cfg_set_dtr) (struct ucom_softc *, uint8_t); 95a593f6b8SAndrew Thompson void (*ucom_cfg_set_rts) (struct ucom_softc *, uint8_t); 96a593f6b8SAndrew Thompson void (*ucom_cfg_set_break) (struct ucom_softc *, uint8_t); 97655dc9d0SAndrew Thompson void (*ucom_cfg_set_ring) (struct ucom_softc *, uint8_t); 98a593f6b8SAndrew Thompson void (*ucom_cfg_param) (struct ucom_softc *, struct termios *); 99a593f6b8SAndrew Thompson void (*ucom_cfg_open) (struct ucom_softc *); 100a593f6b8SAndrew Thompson void (*ucom_cfg_close) (struct ucom_softc *); 101a593f6b8SAndrew Thompson int (*ucom_pre_open) (struct ucom_softc *); 102a593f6b8SAndrew Thompson int (*ucom_pre_param) (struct ucom_softc *, struct termios *); 103a593f6b8SAndrew Thompson int (*ucom_ioctl) (struct ucom_softc *, uint32_t, caddr_t, int, struct thread *); 104a593f6b8SAndrew Thompson void (*ucom_start_read) (struct ucom_softc *); 105a593f6b8SAndrew Thompson void (*ucom_stop_read) (struct ucom_softc *); 106a593f6b8SAndrew Thompson void (*ucom_start_write) (struct ucom_softc *); 107a593f6b8SAndrew Thompson void (*ucom_stop_write) (struct ucom_softc *); 108015bb88fSNick Hibma void (*ucom_tty_name) (struct ucom_softc *, char *pbuf, uint16_t buflen, uint16_t unit, uint16_t subunit); 109655dc9d0SAndrew Thompson void (*ucom_poll) (struct ucom_softc *); 1108f42c748SHans Petter Selasky void (*ucom_free) (struct ucom_softc *); 11102ac6454SAndrew Thompson }; 11202ac6454SAndrew Thompson 11302ac6454SAndrew Thompson /* Line status register */ 11402ac6454SAndrew Thompson #define ULSR_RCV_FIFO 0x80 11502ac6454SAndrew Thompson #define ULSR_TSRE 0x40 /* Transmitter empty: byte sent */ 11602ac6454SAndrew Thompson #define ULSR_TXRDY 0x20 /* Transmitter buffer empty */ 11702ac6454SAndrew Thompson #define ULSR_BI 0x10 /* Break detected */ 11802ac6454SAndrew Thompson #define ULSR_FE 0x08 /* Framing error: bad stop bit */ 11902ac6454SAndrew Thompson #define ULSR_PE 0x04 /* Parity error */ 12002ac6454SAndrew Thompson #define ULSR_OE 0x02 /* Overrun, lost incoming byte */ 12102ac6454SAndrew Thompson #define ULSR_RXRDY 0x01 /* Byte ready in Receive Buffer */ 12202ac6454SAndrew Thompson #define ULSR_RCV_MASK 0x1f /* Mask for incoming data or error */ 12302ac6454SAndrew Thompson 124760bc48eSAndrew Thompson struct ucom_cfg_task { 125760bc48eSAndrew Thompson struct usb_proc_msg hdr; 126760bc48eSAndrew Thompson struct ucom_softc *sc; 12702ac6454SAndrew Thompson }; 12802ac6454SAndrew Thompson 129760bc48eSAndrew Thompson struct ucom_param_task { 130760bc48eSAndrew Thompson struct usb_proc_msg hdr; 131760bc48eSAndrew Thompson struct ucom_softc *sc; 13202ac6454SAndrew Thompson struct termios termios_copy; 13302ac6454SAndrew Thompson }; 13402ac6454SAndrew Thompson 135760bc48eSAndrew Thompson struct ucom_super_softc { 136760bc48eSAndrew Thompson struct usb_process sc_tq; 1373a4a1a7fSHans Petter Selasky int sc_unit; 1383a4a1a7fSHans Petter Selasky int sc_subunits; 1398f42c748SHans Petter Selasky int sc_refs; 140*c01fc06eSHans Petter Selasky int sc_flag; /* see UCOM_FLAG_XXX */ 14196d87d2bSHans Petter Selasky struct sysctl_oid *sc_sysctl_ttyname; 1423a4a1a7fSHans Petter Selasky struct sysctl_oid *sc_sysctl_ttyports; 14396d87d2bSHans Petter Selasky char sc_ttyname[16]; 14402ac6454SAndrew Thompson }; 14502ac6454SAndrew Thompson 146760bc48eSAndrew Thompson struct ucom_softc { 14702ac6454SAndrew Thompson /* 14802ac6454SAndrew Thompson * NOTE: To avoid loosing level change information we use two 14902ac6454SAndrew Thompson * tasks instead of one for all commands. 15002ac6454SAndrew Thompson * 15102ac6454SAndrew Thompson * Level changes are transitions like: 15202ac6454SAndrew Thompson * 15302ac6454SAndrew Thompson * ON->OFF 15402ac6454SAndrew Thompson * OFF->ON 15502ac6454SAndrew Thompson * OPEN->CLOSE 15602ac6454SAndrew Thompson * CLOSE->OPEN 15702ac6454SAndrew Thompson */ 158760bc48eSAndrew Thompson struct ucom_cfg_task sc_start_task[2]; 159760bc48eSAndrew Thompson struct ucom_cfg_task sc_open_task[2]; 160760bc48eSAndrew Thompson struct ucom_cfg_task sc_close_task[2]; 161760bc48eSAndrew Thompson struct ucom_cfg_task sc_line_state_task[2]; 162760bc48eSAndrew Thompson struct ucom_cfg_task sc_status_task[2]; 163760bc48eSAndrew Thompson struct ucom_param_task sc_param_task[2]; 164afa07055SAndrew Thompson /* Used to set "UCOM_FLAG_GP_DATA" flag: */ 165760bc48eSAndrew Thompson struct usb_proc_msg *sc_last_start_xfer; 166760bc48eSAndrew Thompson const struct ucom_callback *sc_callback; 167760bc48eSAndrew Thompson struct ucom_super_softc *sc_super; 16802ac6454SAndrew Thompson struct tty *sc_tty; 16902ac6454SAndrew Thompson struct mtx *sc_mtx; 17002ac6454SAndrew Thompson void *sc_parent; 1716d917491SHans Petter Selasky int sc_subunit; 17202ac6454SAndrew Thompson uint16_t sc_portno; 173655dc9d0SAndrew Thompson uint16_t sc_flag; 17402ac6454SAndrew Thompson #define UCOM_FLAG_RTS_IFLOW 0x01 /* use RTS input flow control */ 17502ac6454SAndrew Thompson #define UCOM_FLAG_GONE 0x02 /* the device is gone */ 17602ac6454SAndrew Thompson #define UCOM_FLAG_ATTACHED 0x04 /* set if attached */ 17702ac6454SAndrew Thompson #define UCOM_FLAG_GP_DATA 0x08 /* set if get and put data is possible */ 17802ac6454SAndrew Thompson #define UCOM_FLAG_LL_READY 0x20 /* set if low layer is ready */ 17902ac6454SAndrew Thompson #define UCOM_FLAG_HL_READY 0x40 /* set if high layer is ready */ 180655dc9d0SAndrew Thompson #define UCOM_FLAG_CONSOLE 0x80 /* set if device is a console */ 181*c01fc06eSHans Petter Selasky #define UCOM_FLAG_WAIT_REFS 0x0100 /* set if we must wait for refs */ 182*c01fc06eSHans Petter Selasky #define UCOM_FLAG_FREE_UNIT 0x0200 /* set if we must free the unit */ 18302ac6454SAndrew Thompson uint8_t sc_lsr; 18402ac6454SAndrew Thompson uint8_t sc_msr; 18502ac6454SAndrew Thompson uint8_t sc_mcr; 18602ac6454SAndrew Thompson /* programmed line state bits */ 18702ac6454SAndrew Thompson uint8_t sc_pls_set; /* set bits */ 18802ac6454SAndrew Thompson uint8_t sc_pls_clr; /* cleared bits */ 18902ac6454SAndrew Thompson uint8_t sc_pls_curr; /* last state */ 19002ac6454SAndrew Thompson #define UCOM_LS_DTR 0x01 19102ac6454SAndrew Thompson #define UCOM_LS_RTS 0x02 19202ac6454SAndrew Thompson #define UCOM_LS_BREAK 0x04 193655dc9d0SAndrew Thompson #define UCOM_LS_RING 0x08 19402ac6454SAndrew Thompson }; 19502ac6454SAndrew Thompson 1968f42c748SHans Petter Selasky #define UCOM_MTX_ASSERT(sc, what) mtx_assert((sc)->sc_mtx, what) 1978f42c748SHans Petter Selasky #define UCOM_MTX_LOCK(sc) mtx_lock((sc)->sc_mtx) 1988f42c748SHans Petter Selasky #define UCOM_MTX_UNLOCK(sc) mtx_unlock((sc)->sc_mtx) 1998f42c748SHans Petter Selasky #define UCOM_UNLOAD_DRAIN(x) \ 2008f42c748SHans Petter Selasky SYSUNINIT(var, SI_SUB_KLD - 3, SI_ORDER_ANY, ucom_drain_all, 0) 2018f42c748SHans Petter Selasky 202a593f6b8SAndrew Thompson #define ucom_cfg_do_request(udev,com,req,ptr,flags,timo) \ 203a593f6b8SAndrew Thompson usbd_do_request_proc(udev,&(com)->sc_super->sc_tq,req,ptr,flags,NULL,timo) 20402ac6454SAndrew Thompson 205a593f6b8SAndrew Thompson int ucom_attach(struct ucom_super_softc *, 2066d917491SHans Petter Selasky struct ucom_softc *, int, void *, 207760bc48eSAndrew Thompson const struct ucom_callback *callback, struct mtx *); 208015bb88fSNick Hibma void ucom_detach(struct ucom_super_softc *, struct ucom_softc *); 2096416c259SNick Hibma void ucom_set_pnpinfo_usb(struct ucom_super_softc *, device_t); 210a593f6b8SAndrew Thompson void ucom_status_change(struct ucom_softc *); 211a593f6b8SAndrew Thompson uint8_t ucom_get_data(struct ucom_softc *, struct usb_page_cache *, 21202ac6454SAndrew Thompson uint32_t, uint32_t, uint32_t *); 213a593f6b8SAndrew Thompson void ucom_put_data(struct ucom_softc *, struct usb_page_cache *, 21402ac6454SAndrew Thompson uint32_t, uint32_t); 215a593f6b8SAndrew Thompson uint8_t ucom_cfg_is_gone(struct ucom_softc *); 2168f42c748SHans Petter Selasky void ucom_drain(struct ucom_super_softc *); 2178f42c748SHans Petter Selasky void ucom_drain_all(void *); 2188f42c748SHans Petter Selasky void ucom_ref(struct ucom_super_softc *); 2198f42c748SHans Petter Selasky int ucom_unref(struct ucom_super_softc *); 22075973647SAndrew Thompson #endif /* _USB_SERIAL_H_ */ 221