1 1.2 jakllsch /* $NetBSD: uslsareg.h,v 1.2 2025/02/16 18:31:37 jakllsch Exp $ */ 2 1.1 jakllsch 3 1.1 jakllsch /* 4 1.1 jakllsch * Copyright (c) 2011 Jonathan A. Kollasch. 5 1.1 jakllsch * All rights reserved. 6 1.1 jakllsch * 7 1.1 jakllsch * Redistribution and use in source and binary forms, with or without 8 1.1 jakllsch * modification, are permitted provided that the following conditions 9 1.1 jakllsch * are met: 10 1.1 jakllsch * 1. Redistributions of source code must retain the above copyright 11 1.1 jakllsch * notice, this list of conditions and the following disclaimer. 12 1.1 jakllsch * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 jakllsch * notice, this list of conditions and the following disclaimer in the 14 1.1 jakllsch * documentation and/or other materials provided with the distribution. 15 1.1 jakllsch * 16 1.1 jakllsch * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 1.1 jakllsch * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 1.1 jakllsch * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 1.1 jakllsch * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 1.1 jakllsch * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 1.1 jakllsch * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 1.1 jakllsch * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 1.1 jakllsch * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 1.1 jakllsch * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 1.1 jakllsch * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 1.1 jakllsch * 27 1.1 jakllsch */ 28 1.1 jakllsch 29 1.1 jakllsch #ifndef _SLSAREG_H_ 30 1.1 jakllsch #define _SLSAREG_H_ 31 1.1 jakllsch 32 1.1 jakllsch #include <lib/libkern/libkern.h> 33 1.1 jakllsch #include <sys/systm.h> 34 1.1 jakllsch #include <sys/types.h> 35 1.1 jakllsch 36 1.1 jakllsch /* From Silicon Laboratories Application Note AN571 */ 37 1.1 jakllsch 38 1.1 jakllsch #define SLSA_FREQ 3686400 39 1.1 jakllsch 40 1.1 jakllsch /* USB Control Requests */ 41 1.1 jakllsch #define SLSA_R_IFC_ENABLE 0x00 42 1.1 jakllsch #define SLSA_R_SET_BAUDDIV 0x01 43 1.1 jakllsch #define SLSA_R_GET_BAUDDIV 0x02 44 1.1 jakllsch #define SLSA_R_SET_LINE_CTL 0x03 45 1.1 jakllsch #define SLSA_R_GET_LINE_CTL 0x04 46 1.1 jakllsch #define SLSA_R_SET_BREAK 0x05 47 1.1 jakllsch #define SLSA_R_IMM_CHAR 0x06 48 1.1 jakllsch #define SLSA_R_SET_MHS 0x07 49 1.1 jakllsch #define SLSA_R_GET_MDMSTS 0x08 50 1.1 jakllsch #define SLSA_R_SET_XON 0x09 51 1.1 jakllsch #define SLSA_R_SET_XOFF 0x0a 52 1.1 jakllsch #define SLSA_R_SET_EVENTMASK 0x0b 53 1.1 jakllsch #define SLSA_R_GET_EVENTMASK 0x0c 54 1.1 jakllsch #define SLSA_R_SET_CHAR 0x0d 55 1.1 jakllsch #define SLSA_R_GET_CHARS 0x0e 56 1.1 jakllsch #define SLSA_R_GET_PROPS 0x0f 57 1.1 jakllsch #define SLSA_R_GET_COMM_STATUS 0x10 58 1.1 jakllsch #define SLSA_R_RESET 0x11 59 1.1 jakllsch #define SLSA_R_PURGE 0x12 60 1.1 jakllsch #define SLSA_R_SET_FLOW 0x13 61 1.1 jakllsch #define SLSA_R_GET_FLOW 0x14 62 1.1 jakllsch #define SLSA_R_EMBED_EVENTS 0x15 63 1.2 jakllsch #define SLSA_R_GET_EVENTSTATE 0x16 64 1.2 jakllsch #define SLSA_R_SET_RECEIVE 0x17 65 1.2 jakllsch #define SLSA_R_GET_RECEIVE 0x18 66 1.1 jakllsch #define SLSA_R_SET_CHARS 0x19 67 1.1 jakllsch #define SLSA_R_GET_BAUDRATE 0x1d 68 1.1 jakllsch #define SLSA_R_SET_BAUDRATE 0x1e 69 1.1 jakllsch #define SLSA_R_VENDOR_SPECIFIC 0xff 70 1.1 jakllsch 71 1.1 jakllsch 72 1.1 jakllsch #define SLSA_RV_IFC_ENABLE_DISABLE 0x0000 73 1.1 jakllsch #define SLSA_RV_IFC_ENABLE_ENABLE 0x0001 74 1.1 jakllsch 75 1.1 jakllsch 76 1.1 jakllsch #define SLSA_RV_BAUDDIV(b) (SLSA_FREQ/(b)) 77 1.1 jakllsch 78 1.1 jakllsch 79 1.1 jakllsch #define SLSA_RV_LINE_CTL_STOP __BITS(3,0) 80 1.1 jakllsch #define SLSA_RV_LINE_CTL_PARITY __BITS(7,4) 81 1.1 jakllsch #define SLSA_RV_LINE_CTL_LEN __BITS(15,8) 82 1.1 jakllsch 83 1.1 jakllsch #define SLSA_RV_LINE_CTL_STOP_1 __SHIFTIN(0, SLSA_RV_LINE_CTL_STOP) 84 1.1 jakllsch #define SLSA_RV_LINE_CTL_STOP_1_5 __SHIFTIN(1, SLSA_RV_LINE_CTL_STOP) 85 1.1 jakllsch #define SLSA_RV_LINE_CTL_STOP_2 __SHIFTIN(2, SLSA_RV_LINE_CTL_STOP) 86 1.1 jakllsch 87 1.1 jakllsch #define SLSA_RV_LINE_CTL_PARITY_NONE __SHIFTIN(0, SLSA_RV_LINE_CTL_PARITY) 88 1.1 jakllsch #define SLSA_RV_LINE_CTL_PARITY_ODD __SHIFTIN(1, SLSA_RV_LINE_CTL_PARITY) 89 1.1 jakllsch #define SLSA_RV_LINE_CTL_PARITY_EVEN __SHIFTIN(2, SLSA_RV_LINE_CTL_PARITY) 90 1.1 jakllsch #define SLSA_RV_LINE_CTL_PARITY_MARK __SHIFTIN(3, SLSA_RV_LINE_CTL_PARITY) 91 1.1 jakllsch #define SLSA_RV_LINE_CTL_PARITY_SPACE __SHIFTIN(4, SLSA_RV_LINE_CTL_PARITY) 92 1.1 jakllsch 93 1.1 jakllsch #define SLSA_RV_LINE_CTL_LEN_5 __SHIFTIN(5, SLSA_RV_LINE_CTL_LEN) 94 1.1 jakllsch #define SLSA_RV_LINE_CTL_LEN_6 __SHIFTIN(6, SLSA_RV_LINE_CTL_LEN) 95 1.1 jakllsch #define SLSA_RV_LINE_CTL_LEN_7 __SHIFTIN(7, SLSA_RV_LINE_CTL_LEN) 96 1.1 jakllsch #define SLSA_RV_LINE_CTL_LEN_8 __SHIFTIN(8, SLSA_RV_LINE_CTL_LEN) 97 1.1 jakllsch 98 1.1 jakllsch 99 1.1 jakllsch #define SLSA_RV_SET_BREAK_DISABLE 0x0000 100 1.1 jakllsch #define SLSA_RV_SET_BREAK_ENABLE 0x0001 101 1.1 jakllsch 102 1.1 jakllsch 103 1.1 jakllsch #define SLSA_RV_SET_MHS_DTR __BIT(0) 104 1.1 jakllsch #define SLSA_RV_SET_MHS_RTS __BIT(1) 105 1.1 jakllsch /* AN571 calls these next two masks, they're more like change-enables */ 106 1.1 jakllsch #define SLSA_RV_SET_MHS_DTR_MASK __BIT(8) 107 1.1 jakllsch #define SLSA_RV_SET_MHS_RTS_MASK __BIT(9) 108 1.1 jakllsch 109 1.1 jakllsch 110 1.1 jakllsch #define SLSA_RL_GET_MDMSTS 1 111 1.1 jakllsch /* data in uint8_t returned from GET_MDMSTS */ 112 1.1 jakllsch #define SLSA_MDMSTS_DTR __BIT(0) 113 1.1 jakllsch #define SLSA_MDMSTS_RTS __BIT(1) 114 1.1 jakllsch #define SLSA_MDMSTS_CTS __BIT(4) 115 1.1 jakllsch #define SLSA_MDMSTS_DSR __BIT(5) 116 1.1 jakllsch #define SLSA_MDMSTS_RI __BIT(6) 117 1.1 jakllsch #define SLSA_MDMSTS_DCD __BIT(7) 118 1.1 jakllsch 119 1.1 jakllsch 120 1.1 jakllsch #define SLSA_RL_SET_EVENTMASK 0 121 1.1 jakllsch #define SLSA_RL_GET_EVENTMASK 2 122 1.1 jakllsch #define SLSA_RL_GET_EVENTSTATE 2 123 1.1 jakllsch #define SLSA_EVENT_TERI __BIT(0) /* RI trailing edge */ 124 1.1 jakllsch #define SLSA_EVENT_RB80 __BIT(2) /* Rx buf 80% full */ 125 1.1 jakllsch #define SLSA_EVENT_CR __BIT(8) /* char received */ 126 1.1 jakllsch #define SLSA_EVENT_SCR __BIT(9) /* special char received */ 127 1.1 jakllsch #define SLSA_EVENT_TQE __BIT(10) /* Tx queue empty */ 128 1.1 jakllsch #define SLSA_EVENT_DCTS __BIT(11) /* CTS changed */ 129 1.1 jakllsch #define SLSA_EVENT_DDSR __BIT(12) /* DSR changed */ 130 1.1 jakllsch #define SLSA_EVENT_DDCD __BIT(13) /* DCD changed */ 131 1.1 jakllsch #define SLSA_EVENT_BI __BIT(14) /* line break received */ 132 1.1 jakllsch #define SLSA_EVENT_LSE __BIT(15) /* line status error */ 133 1.1 jakllsch 134 1.1 jakllsch 135 1.1 jakllsch /* USETW2(wValue, char, index) */ 136 1.1 jakllsch #define SLSA_RV_SET_CHAR_EofChar 0 137 1.1 jakllsch #define SLSA_RV_SET_CHAR_ErrorChar 1 138 1.1 jakllsch #define SLSA_RV_SET_CHAR_BreakChar 2 139 1.1 jakllsch #define SLSA_RV_SET_CHAR_EventChar 3 140 1.1 jakllsch #define SLSA_RV_SET_CHAR_XonChar 4 141 1.1 jakllsch #define SLSA_RV_SET_CHAR_XoffChar 5 142 1.1 jakllsch 143 1.1 jakllsch 144 1.1 jakllsch #define SLSA_RV_PURGE_TX __BIT(0) 145 1.1 jakllsch #define SLSA_RV_PURGE_RX __BIT(1) 146 1.1 jakllsch #define SLSA_RV_PURGE_TX1 __BIT(2) /* what's the second set for? */ 147 1.1 jakllsch #define SLSA_RV_PURGE_RX1 __BIT(3) 148 1.1 jakllsch 149 1.1 jakllsch 150 1.1 jakllsch /* Communication Properties Response Table 7. */ 151 1.1 jakllsch struct slsa_cpr { 152 1.1 jakllsch uint16_t wLength; 153 1.1 jakllsch uint16_t bcdVersion; 154 1.1 jakllsch uint32_t ulServiceMask; 155 1.1 jakllsch uint32_t _reserved8; 156 1.1 jakllsch uint32_t ulMaxTxQueue; 157 1.1 jakllsch uint32_t ulMaxRxQueue; 158 1.1 jakllsch uint32_t ulMaxBaud; 159 1.1 jakllsch uint32_t ulProvSubType; 160 1.1 jakllsch uint32_t ulProvCapabilities; 161 1.1 jakllsch uint32_t ulSettableParams; 162 1.1 jakllsch uint32_t ulSettableBaud; 163 1.1 jakllsch uint16_t wSettableData; 164 1.1 jakllsch uint16_t _reserved42; 165 1.1 jakllsch uint32_t ulCurrentTxQueue; 166 1.1 jakllsch uint32_t ulCurrentRxQueue; 167 1.1 jakllsch uint32_t _reserved52; 168 1.1 jakllsch uint32_t _reserved56; 169 1.1 jakllsch uint16_t uniProvName[0]; 170 1.1 jakllsch }; 171 1.1 jakllsch CTASSERT(offsetof(struct slsa_cpr, _reserved8) == 8); 172 1.1 jakllsch CTASSERT(offsetof(struct slsa_cpr, _reserved42) == 42); 173 1.1 jakllsch CTASSERT(offsetof(struct slsa_cpr, uniProvName[0]) == 60); 174 1.1 jakllsch #define SLSA_CPR_MINLEN 60 175 1.1 jakllsch 176 1.1 jakllsch #define SLSA_RL_GET_COMM_STATUS 19 177 1.1 jakllsch /* Serial Status Response Table 8. */ 178 1.1 jakllsch struct slsa_ssr { 179 1.1 jakllsch uint32_t ulErrors; 180 1.1 jakllsch uint32_t ulHoldReasons; 181 1.1 jakllsch uint32_t ulAmountInInQueue; 182 1.1 jakllsch uint32_t ulAmountInOutQueue; 183 1.1 jakllsch uint8_t bEofReceived; 184 1.1 jakllsch uint8_t bWaitForImmediate; 185 1.1 jakllsch uint8_t bReserved; 186 1.1 jakllsch }; 187 1.1 jakllsch CTASSERT(offsetof(struct slsa_ssr, bReserved) == 18); 188 1.1 jakllsch CTASSERT(sizeof(struct slsa_ssr) >= SLSA_RL_GET_COMM_STATUS); 189 1.1 jakllsch 190 1.1 jakllsch #define SLSA_RL_SET_FLOW 16 191 1.1 jakllsch #define SLSA_RL_GET_FLOW 16 192 1.1 jakllsch /* Flow Control State Setting/Response Table 9. */ 193 1.1 jakllsch struct slsa_fcs { 194 1.1 jakllsch uint32_t ulControlHandshake; 195 1.1 jakllsch #define SERIAL_DTR_MASK __BITS(0, 1) 196 1.1 jakllsch #define SERIAL_CTS_HANDSHAKE __BIT(3) 197 1.1 jakllsch #define SERIAL_DSR_HANDSHAKE __BIT(4) 198 1.1 jakllsch #define SERIAL_DCD_HANDSHAKE __BIT(5) 199 1.1 jakllsch #define SERIAL_DSR_SENSITIVITY __BIT(6) 200 1.1 jakllsch uint32_t ulFlowReplace; 201 1.1 jakllsch #define SERIAL_AUTO_TRANSMIT __BIT(0) 202 1.1 jakllsch #define SERIAL_AUTO_RECEIVE __BIT(1) 203 1.1 jakllsch #define SERIAL_ERROR_CHAR __BIT(2) 204 1.1 jakllsch #define SERIAL_NULL_STRIPPING __BIT(3) 205 1.1 jakllsch #define SERIAL_BREAK_CHAR __BIT(4) 206 1.1 jakllsch #define SERIAL_RTS_MASK __BITS(6, 7) 207 1.1 jakllsch #define SERIAL_XOFF_CONTINUE __BIT(31) 208 1.1 jakllsch uint32_t ulXonLimit; 209 1.1 jakllsch uint32_t ulXoffLimit; 210 1.1 jakllsch }; 211 1.1 jakllsch CTASSERT(sizeof(struct slsa_fcs) == SLSA_RL_SET_FLOW); 212 1.1 jakllsch CTASSERT(sizeof(struct slsa_fcs) == SLSA_RL_GET_FLOW); 213 1.1 jakllsch 214 1.1 jakllsch #define SLSA_RL_SET_CHARS 6 215 1.1 jakllsch #define SLSA_RL_GET_CHARS 6 216 1.1 jakllsch /* Special Characters Response Table 12. */ 217 1.1 jakllsch struct slsa_scr { 218 1.1 jakllsch uint8_t bEofChar; 219 1.1 jakllsch uint8_t bErrorChar; 220 1.1 jakllsch uint8_t bBreakChar; 221 1.1 jakllsch uint8_t bEventChar; 222 1.1 jakllsch uint8_t bXonChar; 223 1.1 jakllsch uint8_t bXoffChar; 224 1.1 jakllsch }; 225 1.1 jakllsch CTASSERT(sizeof(struct slsa_scr) == SLSA_RL_SET_CHARS); 226 1.1 jakllsch CTASSERT(sizeof(struct slsa_scr) == SLSA_RL_GET_CHARS); 227 1.1 jakllsch 228 1.1 jakllsch 229 1.1 jakllsch #define SLSA_RV_VENDOR_SPECIFIC_READ_LATCH 0x00c2 230 1.1 jakllsch #define SLSA_RL_VENDOR_SPECIFIC_READ_LATCH 1 231 1.1 jakllsch 232 1.1 jakllsch #define SLSA_RV_VENDOR_SPECIFIC_WRITE_LATCH 0x37e1 233 1.1 jakllsch /* 234 1.1 jakllsch * on CP2103/CP2104 the latch state and latch mask are 235 1.1 jakllsch * written in the high and low bytes of wIndex respectively 236 1.1 jakllsch * 237 1.1 jakllsch * on CP2105, wIndex is the interface number, and the same 238 1.1 jakllsch * latch/mask is written as data instead. 239 1.1 jakllsch */ 240 1.1 jakllsch #define SLSA_RL_VENDOR_SPECIFIC_WRITE_LATCH_CP2103 0 241 1.1 jakllsch #define SLSA_RL_VENDOR_SPECIFIC_WRITE_LATCH_CP2105 2 242 1.1 jakllsch 243 1.1 jakllsch #endif /* _SLSAREG_H_ */ 244