1 1.23 mrg /* $NetBSD: ucomvar.h,v 1.23 2019/05/09 02:43:35 mrg Exp $ */ 2 1.1 augustss 3 1.1 augustss /* 4 1.1 augustss * Copyright (c) 1999 The NetBSD Foundation, Inc. 5 1.1 augustss * All rights reserved. 6 1.1 augustss * 7 1.1 augustss * This code is derived from software contributed to The NetBSD Foundation 8 1.6 augustss * by Lennart Augustsson (lennart (at) augustsson.net) at 9 1.1 augustss * Carlstedt Research & Technology. 10 1.1 augustss * 11 1.1 augustss * Redistribution and use in source and binary forms, with or without 12 1.1 augustss * modification, are permitted provided that the following conditions 13 1.1 augustss * are met: 14 1.1 augustss * 1. Redistributions of source code must retain the above copyright 15 1.1 augustss * notice, this list of conditions and the following disclaimer. 16 1.1 augustss * 2. Redistributions in binary form must reproduce the above copyright 17 1.1 augustss * notice, this list of conditions and the following disclaimer in the 18 1.1 augustss * documentation and/or other materials provided with the distribution. 19 1.1 augustss * 20 1.1 augustss * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 1.1 augustss * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 1.1 augustss * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 1.1 augustss * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 1.1 augustss * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 1.1 augustss * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 1.1 augustss * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 1.1 augustss * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 1.1 augustss * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 1.1 augustss * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 1.1 augustss * POSSIBILITY OF SUCH DAMAGE. 31 1.1 augustss */ 32 1.1 augustss 33 1.1 augustss 34 1.11 drochner /* just for ucom_attach_args, not in the config namespace */ 35 1.11 drochner #define UCOM_UNK_PORTNO (-1) 36 1.1 augustss 37 1.1 augustss struct ucom_softc; 38 1.1 augustss 39 1.22 mrg /* 40 1.23 mrg * USB detach requires ensuring that outstanding operations and 41 1.23 mrg * open devices are properly closed before detach can return. 42 1.23 mrg * 43 1.23 mrg * ucom parents rely upon ucom(4) itself doing any safety here. 44 1.23 mrg * The standard method is: 45 1.23 mrg * 46 1.23 mrg * 1. device softc has a "bool sc_dying" member, that may be set 47 1.23 mrg * in attach or other run-time for general failure, and set 48 1.23 mrg * early in the detach callback 49 1.23 mrg * 50 1.23 mrg * 2. if sc_dying is set, most functions should perform as close 51 1.23 mrg * to zero operations as possible 52 1.23 mrg * 53 1.23 mrg * 3. detach callback sets sc_dying to true and then cleans up 54 1.23 mrg * any local state and calls config_detach() on each child 55 1.23 mrg */ 56 1.23 mrg 57 1.23 mrg /* 58 1.22 mrg * The first argument to the ucom callbacks is the passed in ucaa_arg 59 1.22 mrg * member of the attach args, typically the parent softc pointer. 60 1.22 mrg * 61 1.22 mrg * All of these are optional. 62 1.22 mrg */ 63 1.1 augustss struct ucom_methods { 64 1.22 mrg /* 65 1.22 mrg * arg2: port number 66 1.22 mrg * arg3: pointer to lsr (always non NULL) 67 1.22 mrg * arg4: pointer to msr (always non NULL) 68 1.22 mrg */ 69 1.21 skrll void (*ucom_get_status)(void *, int, u_char *, u_char *); 70 1.22 mrg /* 71 1.22 mrg * arg2: port number 72 1.22 mrg * arg3: value to turn on or off (DTR, RTS, BREAK) 73 1.22 mrg * arg4: onoff 74 1.22 mrg */ 75 1.21 skrll void (*ucom_set)(void *, int, int, int); 76 1.1 augustss #define UCOM_SET_DTR 1 77 1.1 augustss #define UCOM_SET_RTS 2 78 1.1 augustss #define UCOM_SET_BREAK 3 79 1.22 mrg /* 80 1.22 mrg * arg2: port number 81 1.22 mrg * arg3: termios structure to set parameters from 82 1.22 mrg */ 83 1.21 skrll int (*ucom_param)(void *, int, struct termios *); 84 1.22 mrg /* 85 1.22 mrg * arg2: port number 86 1.22 mrg * arg3: ioctl command 87 1.22 mrg * arg4: ioctl data 88 1.22 mrg * arg5: ioctl flags 89 1.22 mrg * arg6: process calling ioctl 90 1.22 mrg */ 91 1.21 skrll int (*ucom_ioctl)(void *, int, u_long, void *, int, proc_t *); 92 1.22 mrg /* arg2: port number */ 93 1.21 skrll int (*ucom_open)(void *, int); 94 1.22 mrg /* arg2: port number */ 95 1.21 skrll void (*ucom_close)(void *, int); 96 1.18 scw /* 97 1.22 mrg * arg2: port number 98 1.22 mrg * arg3: pointer to buffer pointer 99 1.22 mrg * arg4: pointer to buffer count 100 1.22 mrg * 101 1.22 mrg * Note: The 'ptr' (3nd arg) and 'count' (4rd arg) pointers can be 102 1.21 skrll * adjusted as follows: 103 1.21 skrll * 104 1.21 skrll * ptr: If consuming characters from the start of the buffer, 105 1.21 skrll * advance '*ptr' to skip the data consumed. 106 1.21 skrll * 107 1.21 skrll * count: If consuming characters at the end of the buffer, 108 1.21 skrll * decrement '*count' by the number of characters 109 1.21 skrll * consumed. 110 1.21 skrll * 111 1.18 scw * If consuming all characters, set '*count' to zero. 112 1.18 scw */ 113 1.21 skrll void (*ucom_read)(void *, int, u_char **, uint32_t *); 114 1.22 mrg /* 115 1.22 mrg * arg2: port number 116 1.22 mrg * arg3: pointer to source buffer 117 1.22 mrg * arg4: pointer to destination buffer 118 1.22 mrg * arg5: pointer to buffer count 119 1.22 mrg */ 120 1.21 skrll void (*ucom_write)(void *, int, u_char *, u_char *, uint32_t *); 121 1.1 augustss }; 122 1.1 augustss 123 1.1 augustss /* modem control register */ 124 1.1 augustss #define UMCR_RTS 0x02 /* Request To Send */ 125 1.1 augustss #define UMCR_DTR 0x01 /* Data Terminal Ready */ 126 1.1 augustss 127 1.1 augustss /* line status register */ 128 1.1 augustss #define ULSR_RCV_FIFO 0x80 129 1.1 augustss #define ULSR_TSRE 0x40 /* Transmitter empty: byte sent */ 130 1.1 augustss #define ULSR_TXRDY 0x20 /* Transmitter buffer empty */ 131 1.1 augustss #define ULSR_BI 0x10 /* Break detected */ 132 1.1 augustss #define ULSR_FE 0x08 /* Framing error: bad stop bit */ 133 1.1 augustss #define ULSR_PE 0x04 /* Parity error */ 134 1.1 augustss #define ULSR_OE 0x02 /* Overrun, lost incoming byte */ 135 1.1 augustss #define ULSR_RXRDY 0x01 /* Byte ready in Receive Buffer */ 136 1.1 augustss #define ULSR_RCV_MASK 0x1f /* Mask for incoming data or error */ 137 1.1 augustss 138 1.1 augustss /* modem status register */ 139 1.1 augustss /* All deltas are from the last read of the MSR. */ 140 1.1 augustss #define UMSR_DCD 0x80 /* Current Data Carrier Detect */ 141 1.1 augustss #define UMSR_RI 0x40 /* Current Ring Indicator */ 142 1.1 augustss #define UMSR_DSR 0x20 /* Current Data Set Ready */ 143 1.1 augustss #define UMSR_CTS 0x10 /* Current Clear to Send */ 144 1.1 augustss #define UMSR_DDCD 0x08 /* DCD has changed state */ 145 1.1 augustss #define UMSR_TERI 0x04 /* RI has toggled low to high */ 146 1.1 augustss #define UMSR_DDSR 0x02 /* DSR has changed state */ 147 1.1 augustss #define UMSR_DCTS 0x01 /* CTS has changed state */ 148 1.1 augustss 149 1.1 augustss struct ucom_attach_args { 150 1.21 skrll int ucaa_portno; 151 1.21 skrll int ucaa_bulkin; 152 1.21 skrll int ucaa_bulkout; 153 1.21 skrll u_int ucaa_ibufsize; 154 1.21 skrll u_int ucaa_ibufsizepad; 155 1.21 skrll u_int ucaa_obufsize; 156 1.21 skrll u_int ucaa_opkthdrlen; 157 1.21 skrll const char *ucaa_info; /* attach message */ 158 1.21 skrll struct usbd_device *ucaa_device; 159 1.21 skrll struct usbd_interface *ucaa_iface; 160 1.21 skrll const struct ucom_methods *ucaa_methods; 161 1.21 skrll void *ucaa_arg; 162 1.1 augustss }; 163 1.1 augustss 164 1.12 drochner int ucomprint(void *, const char *); 165 1.17 cube int ucomsubmatch(device_t t, cfdata_t, const int *, void *); 166 1.7 augustss void ucom_status_change(struct ucom_softc *); 167