|
10 | 10 | #undef DEFAULT_SYMBOL_NAMESPACE
|
11 | 11 | #define DEFAULT_SYMBOL_NAMESPACE SERIAL_NXP_SC16IS7XX
|
12 | 12 |
|
| 13 | +#include <linux/bits.h> |
13 | 14 | #include <linux/clk.h>
|
14 | 15 | #include <linux/delay.h>
|
15 | 16 | #include <linux/device.h>
|
|
78 | 79 | #define SC16IS7XX_XOFF2_REG (0x07) /* Xoff2 word */
|
79 | 80 |
|
80 | 81 | /* IER register bits */
|
81 |
| -#define SC16IS7XX_IER_RDI_BIT (1 << 0) /* Enable RX data interrupt */ |
82 |
| -#define SC16IS7XX_IER_THRI_BIT (1 << 1) /* Enable TX holding register |
| 82 | +#define SC16IS7XX_IER_RDI_BIT BIT(0) /* Enable RX data interrupt */ |
| 83 | +#define SC16IS7XX_IER_THRI_BIT BIT(1) /* Enable TX holding register |
83 | 84 | * interrupt */
|
84 |
| -#define SC16IS7XX_IER_RLSI_BIT (1 << 2) /* Enable RX line status |
| 85 | +#define SC16IS7XX_IER_RLSI_BIT BIT(2) /* Enable RX line status |
85 | 86 | * interrupt */
|
86 |
| -#define SC16IS7XX_IER_MSI_BIT (1 << 3) /* Enable Modem status |
| 87 | +#define SC16IS7XX_IER_MSI_BIT BIT(3) /* Enable Modem status |
87 | 88 | * interrupt */
|
88 | 89 |
|
89 | 90 | /* IER register bits - write only if (EFR[4] == 1) */
|
90 |
| -#define SC16IS7XX_IER_SLEEP_BIT (1 << 4) /* Enable Sleep mode */ |
91 |
| -#define SC16IS7XX_IER_XOFFI_BIT (1 << 5) /* Enable Xoff interrupt */ |
92 |
| -#define SC16IS7XX_IER_RTSI_BIT (1 << 6) /* Enable nRTS interrupt */ |
93 |
| -#define SC16IS7XX_IER_CTSI_BIT (1 << 7) /* Enable nCTS interrupt */ |
| 91 | +#define SC16IS7XX_IER_SLEEP_BIT BIT(4) /* Enable Sleep mode */ |
| 92 | +#define SC16IS7XX_IER_XOFFI_BIT BIT(5) /* Enable Xoff interrupt */ |
| 93 | +#define SC16IS7XX_IER_RTSI_BIT BIT(6) /* Enable nRTS interrupt */ |
| 94 | +#define SC16IS7XX_IER_CTSI_BIT BIT(7) /* Enable nCTS interrupt */ |
94 | 95 |
|
95 | 96 | /* FCR register bits */
|
96 |
| -#define SC16IS7XX_FCR_FIFO_BIT (1 << 0) /* Enable FIFO */ |
97 |
| -#define SC16IS7XX_FCR_RXRESET_BIT (1 << 1) /* Reset RX FIFO */ |
98 |
| -#define SC16IS7XX_FCR_TXRESET_BIT (1 << 2) /* Reset TX FIFO */ |
99 |
| -#define SC16IS7XX_FCR_RXLVLL_BIT (1 << 6) /* RX Trigger level LSB */ |
100 |
| -#define SC16IS7XX_FCR_RXLVLH_BIT (1 << 7) /* RX Trigger level MSB */ |
| 97 | +#define SC16IS7XX_FCR_FIFO_BIT BIT(0) /* Enable FIFO */ |
| 98 | +#define SC16IS7XX_FCR_RXRESET_BIT BIT(1) /* Reset RX FIFO */ |
| 99 | +#define SC16IS7XX_FCR_TXRESET_BIT BIT(2) /* Reset TX FIFO */ |
| 100 | +#define SC16IS7XX_FCR_RXLVLL_BIT BIT(6) /* RX Trigger level LSB */ |
| 101 | +#define SC16IS7XX_FCR_RXLVLH_BIT BIT(7) /* RX Trigger level MSB */ |
101 | 102 |
|
102 | 103 | /* FCR register bits - write only if (EFR[4] == 1) */
|
103 |
| -#define SC16IS7XX_FCR_TXLVLL_BIT (1 << 4) /* TX Trigger level LSB */ |
104 |
| -#define SC16IS7XX_FCR_TXLVLH_BIT (1 << 5) /* TX Trigger level MSB */ |
| 104 | +#define SC16IS7XX_FCR_TXLVLL_BIT BIT(4) /* TX Trigger level LSB */ |
| 105 | +#define SC16IS7XX_FCR_TXLVLH_BIT BIT(5) /* TX Trigger level MSB */ |
105 | 106 |
|
106 | 107 | /* IIR register bits */
|
107 |
| -#define SC16IS7XX_IIR_NO_INT_BIT (1 << 0) /* No interrupts pending */ |
108 |
| -#define SC16IS7XX_IIR_ID_MASK 0x3e /* Mask for the interrupt ID */ |
109 |
| -#define SC16IS7XX_IIR_THRI_SRC 0x02 /* TX holding register empty */ |
110 |
| -#define SC16IS7XX_IIR_RDI_SRC 0x04 /* RX data interrupt */ |
111 |
| -#define SC16IS7XX_IIR_RLSE_SRC 0x06 /* RX line status error */ |
112 |
| -#define SC16IS7XX_IIR_RTOI_SRC 0x0c /* RX time-out interrupt */ |
113 |
| -#define SC16IS7XX_IIR_MSI_SRC 0x00 /* Modem status interrupt |
114 |
| - * - only on 75x/76x |
115 |
| - */ |
116 |
| -#define SC16IS7XX_IIR_INPIN_SRC 0x30 /* Input pin change of state |
117 |
| - * - only on 75x/76x |
118 |
| - */ |
119 |
| -#define SC16IS7XX_IIR_XOFFI_SRC 0x10 /* Received Xoff */ |
120 |
| -#define SC16IS7XX_IIR_CTSRTS_SRC 0x20 /* nCTS,nRTS change of state |
121 |
| - * from active (LOW) |
122 |
| - * to inactive (HIGH) |
123 |
| - */ |
| 108 | +#define SC16IS7XX_IIR_NO_INT_BIT 0x01 /* No interrupts pending */ |
| 109 | +#define SC16IS7XX_IIR_ID_MASK GENMASK(5, 1) /* Mask for the interrupt ID */ |
| 110 | +#define SC16IS7XX_IIR_THRI_SRC 0x02 /* TX holding register empty */ |
| 111 | +#define SC16IS7XX_IIR_RDI_SRC 0x04 /* RX data interrupt */ |
| 112 | +#define SC16IS7XX_IIR_RLSE_SRC 0x06 /* RX line status error */ |
| 113 | +#define SC16IS7XX_IIR_RTOI_SRC 0x0c /* RX time-out interrupt */ |
| 114 | +#define SC16IS7XX_IIR_MSI_SRC 0x00 /* Modem status interrupt |
| 115 | + * - only on 75x/76x |
| 116 | + */ |
| 117 | +#define SC16IS7XX_IIR_INPIN_SRC 0x30 /* Input pin change of state |
| 118 | + * - only on 75x/76x |
| 119 | + */ |
| 120 | +#define SC16IS7XX_IIR_XOFFI_SRC 0x10 /* Received Xoff */ |
| 121 | +#define SC16IS7XX_IIR_CTSRTS_SRC 0x20 /* nCTS,nRTS change of state |
| 122 | + * from active (LOW) |
| 123 | + * to inactive (HIGH) |
| 124 | + */ |
124 | 125 | /* LCR register bits */
|
125 |
| -#define SC16IS7XX_LCR_LENGTH0_BIT (1 << 0) /* Word length bit 0 */ |
126 |
| -#define SC16IS7XX_LCR_LENGTH1_BIT (1 << 1) /* Word length bit 1 |
| 126 | +#define SC16IS7XX_LCR_LENGTH0_BIT BIT(0) /* Word length bit 0 */ |
| 127 | +#define SC16IS7XX_LCR_LENGTH1_BIT BIT(1) /* Word length bit 1 |
127 | 128 | *
|
128 | 129 | * Word length bits table:
|
129 | 130 | * 00 -> 5 bit words
|
130 | 131 | * 01 -> 6 bit words
|
131 | 132 | * 10 -> 7 bit words
|
132 | 133 | * 11 -> 8 bit words
|
133 | 134 | */
|
134 |
| -#define SC16IS7XX_LCR_STOPLEN_BIT (1 << 2) /* STOP length bit |
| 135 | +#define SC16IS7XX_LCR_STOPLEN_BIT BIT(2) /* STOP length bit |
135 | 136 | *
|
136 | 137 | * STOP length bit table:
|
137 | 138 | * 0 -> 1 stop bit
|
138 | 139 | * 1 -> 1-1.5 stop bits if
|
139 | 140 | * word length is 5,
|
140 | 141 | * 2 stop bits otherwise
|
141 | 142 | */
|
142 |
| -#define SC16IS7XX_LCR_PARITY_BIT (1 << 3) /* Parity bit enable */ |
143 |
| -#define SC16IS7XX_LCR_EVENPARITY_BIT (1 << 4) /* Even parity bit enable */ |
144 |
| -#define SC16IS7XX_LCR_FORCEPARITY_BIT (1 << 5) /* 9-bit multidrop parity */ |
145 |
| -#define SC16IS7XX_LCR_TXBREAK_BIT (1 << 6) /* TX break enable */ |
146 |
| -#define SC16IS7XX_LCR_DLAB_BIT (1 << 7) /* Divisor Latch enable */ |
| 143 | +#define SC16IS7XX_LCR_PARITY_BIT BIT(3) /* Parity bit enable */ |
| 144 | +#define SC16IS7XX_LCR_EVENPARITY_BIT BIT(4) /* Even parity bit enable */ |
| 145 | +#define SC16IS7XX_LCR_FORCEPARITY_BIT BIT(5) /* 9-bit multidrop parity */ |
| 146 | +#define SC16IS7XX_LCR_TXBREAK_BIT BIT(6) /* TX break enable */ |
| 147 | +#define SC16IS7XX_LCR_DLAB_BIT BIT(7) /* Divisor Latch enable */ |
147 | 148 | #define SC16IS7XX_LCR_WORD_LEN_5 (0x00)
|
148 | 149 | #define SC16IS7XX_LCR_WORD_LEN_6 (0x01)
|
149 | 150 | #define SC16IS7XX_LCR_WORD_LEN_7 (0x02)
|
|
154 | 155 | * reg set */
|
155 | 156 |
|
156 | 157 | /* MCR register bits */
|
157 |
| -#define SC16IS7XX_MCR_DTR_BIT (1 << 0) /* DTR complement |
| 158 | +#define SC16IS7XX_MCR_DTR_BIT BIT(0) /* DTR complement |
158 | 159 | * - only on 75x/76x
|
159 | 160 | */
|
160 |
| -#define SC16IS7XX_MCR_RTS_BIT (1 << 1) /* RTS complement */ |
161 |
| -#define SC16IS7XX_MCR_TCRTLR_BIT (1 << 2) /* TCR/TLR register enable */ |
162 |
| -#define SC16IS7XX_MCR_LOOP_BIT (1 << 4) /* Enable loopback test mode */ |
163 |
| -#define SC16IS7XX_MCR_XONANY_BIT (1 << 5) /* Enable Xon Any |
| 161 | +#define SC16IS7XX_MCR_RTS_BIT BIT(1) /* RTS complement */ |
| 162 | +#define SC16IS7XX_MCR_TCRTLR_BIT BIT(2) /* TCR/TLR register enable */ |
| 163 | +#define SC16IS7XX_MCR_LOOP_BIT BIT(4) /* Enable loopback test mode */ |
| 164 | +#define SC16IS7XX_MCR_XONANY_BIT BIT(5) /* Enable Xon Any |
164 | 165 | * - write enabled
|
165 | 166 | * if (EFR[4] == 1)
|
166 | 167 | */
|
167 |
| -#define SC16IS7XX_MCR_IRDA_BIT (1 << 6) /* Enable IrDA mode |
| 168 | +#define SC16IS7XX_MCR_IRDA_BIT BIT(6) /* Enable IrDA mode |
168 | 169 | * - write enabled
|
169 | 170 | * if (EFR[4] == 1)
|
170 | 171 | */
|
171 |
| -#define SC16IS7XX_MCR_CLKSEL_BIT (1 << 7) /* Divide clock by 4 |
| 172 | +#define SC16IS7XX_MCR_CLKSEL_BIT BIT(7) /* Divide clock by 4 |
172 | 173 | * - write enabled
|
173 | 174 | * if (EFR[4] == 1)
|
174 | 175 | */
|
175 | 176 |
|
176 | 177 | /* LSR register bits */
|
177 |
| -#define SC16IS7XX_LSR_DR_BIT (1 << 0) /* Receiver data ready */ |
178 |
| -#define SC16IS7XX_LSR_OE_BIT (1 << 1) /* Overrun Error */ |
179 |
| -#define SC16IS7XX_LSR_PE_BIT (1 << 2) /* Parity Error */ |
180 |
| -#define SC16IS7XX_LSR_FE_BIT (1 << 3) /* Frame Error */ |
181 |
| -#define SC16IS7XX_LSR_BI_BIT (1 << 4) /* Break Interrupt */ |
182 |
| -#define SC16IS7XX_LSR_BRK_ERROR_MASK 0x1E /* BI, FE, PE, OE bits */ |
183 |
| -#define SC16IS7XX_LSR_THRE_BIT (1 << 5) /* TX holding register empty */ |
184 |
| -#define SC16IS7XX_LSR_TEMT_BIT (1 << 6) /* Transmitter empty */ |
185 |
| -#define SC16IS7XX_LSR_FIFOE_BIT (1 << 7) /* Fifo Error */ |
| 178 | +#define SC16IS7XX_LSR_DR_BIT BIT(0) /* Receiver data ready */ |
| 179 | +#define SC16IS7XX_LSR_OE_BIT BIT(1) /* Overrun Error */ |
| 180 | +#define SC16IS7XX_LSR_PE_BIT BIT(2) /* Parity Error */ |
| 181 | +#define SC16IS7XX_LSR_FE_BIT BIT(3) /* Frame Error */ |
| 182 | +#define SC16IS7XX_LSR_BI_BIT BIT(4) /* Break Interrupt */ |
| 183 | +#define SC16IS7XX_LSR_BRK_ERROR_MASK \ |
| 184 | + (SC16IS7XX_LSR_OE_BIT | \ |
| 185 | + SC16IS7XX_LSR_PE_BIT | \ |
| 186 | + SC16IS7XX_LSR_FE_BIT | \ |
| 187 | + SC16IS7XX_LSR_BI_BIT) |
| 188 | + |
| 189 | +#define SC16IS7XX_LSR_THRE_BIT BIT(5) /* TX holding register empty */ |
| 190 | +#define SC16IS7XX_LSR_TEMT_BIT BIT(6) /* Transmitter empty */ |
| 191 | +#define SC16IS7XX_LSR_FIFOE_BIT BIT(7) /* Fifo Error */ |
186 | 192 |
|
187 | 193 | /* MSR register bits */
|
188 |
| -#define SC16IS7XX_MSR_DCTS_BIT (1 << 0) /* Delta CTS Clear To Send */ |
189 |
| -#define SC16IS7XX_MSR_DDSR_BIT (1 << 1) /* Delta DSR Data Set Ready |
| 194 | +#define SC16IS7XX_MSR_DCTS_BIT BIT(0) /* Delta CTS Clear To Send */ |
| 195 | +#define SC16IS7XX_MSR_DDSR_BIT BIT(1) /* Delta DSR Data Set Ready |
190 | 196 | * or (IO4)
|
191 | 197 | * - only on 75x/76x
|
192 | 198 | */
|
193 |
| -#define SC16IS7XX_MSR_DRI_BIT (1 << 2) /* Delta RI Ring Indicator |
| 199 | +#define SC16IS7XX_MSR_DRI_BIT BIT(2) /* Delta RI Ring Indicator |
194 | 200 | * or (IO7)
|
195 | 201 | * - only on 75x/76x
|
196 | 202 | */
|
197 |
| -#define SC16IS7XX_MSR_DCD_BIT (1 << 3) /* Delta CD Carrier Detect |
| 203 | +#define SC16IS7XX_MSR_DCD_BIT BIT(3) /* Delta CD Carrier Detect |
198 | 204 | * or (IO6)
|
199 | 205 | * - only on 75x/76x
|
200 | 206 | */
|
201 |
| -#define SC16IS7XX_MSR_CTS_BIT (1 << 4) /* CTS */ |
202 |
| -#define SC16IS7XX_MSR_DSR_BIT (1 << 5) /* DSR (IO4) |
| 207 | +#define SC16IS7XX_MSR_CTS_BIT BIT(4) /* CTS */ |
| 208 | +#define SC16IS7XX_MSR_DSR_BIT BIT(5) /* DSR (IO4) |
203 | 209 | * - only on 75x/76x
|
204 | 210 | */
|
205 |
| -#define SC16IS7XX_MSR_RI_BIT (1 << 6) /* RI (IO7) |
| 211 | +#define SC16IS7XX_MSR_RI_BIT BIT(6) /* RI (IO7) |
206 | 212 | * - only on 75x/76x
|
207 | 213 | */
|
208 |
| -#define SC16IS7XX_MSR_CD_BIT (1 << 7) /* CD (IO6) |
| 214 | +#define SC16IS7XX_MSR_CD_BIT BIT(7) /* CD (IO6) |
209 | 215 | * - only on 75x/76x
|
210 | 216 | */
|
211 | 217 |
|
|
240 | 246 | #define SC16IS7XX_TLR_RX_TRIGGER(words) ((((words) / 4) & 0x0f) << 4)
|
241 | 247 |
|
242 | 248 | /* IOControl register bits (Only 75x/76x) */
|
243 |
| -#define SC16IS7XX_IOCONTROL_LATCH_BIT (1 << 0) /* Enable input latching */ |
244 |
| -#define SC16IS7XX_IOCONTROL_MODEM_A_BIT (1 << 1) /* Enable GPIO[7:4] as modem A pins */ |
245 |
| -#define SC16IS7XX_IOCONTROL_MODEM_B_BIT (1 << 2) /* Enable GPIO[3:0] as modem B pins */ |
246 |
| -#define SC16IS7XX_IOCONTROL_SRESET_BIT (1 << 3) /* Software Reset */ |
| 249 | +#define SC16IS7XX_IOCONTROL_LATCH_BIT BIT(0) /* Enable input latching */ |
| 250 | +#define SC16IS7XX_IOCONTROL_MODEM_A_BIT BIT(1) /* Enable GPIO[7:4] as modem A pins */ |
| 251 | +#define SC16IS7XX_IOCONTROL_MODEM_B_BIT BIT(2) /* Enable GPIO[3:0] as modem B pins */ |
| 252 | +#define SC16IS7XX_IOCONTROL_SRESET_BIT BIT(3) /* Software Reset */ |
247 | 253 |
|
248 | 254 | /* EFCR register bits */
|
249 |
| -#define SC16IS7XX_EFCR_9BIT_MODE_BIT (1 << 0) /* Enable 9-bit or Multidrop |
| 255 | +#define SC16IS7XX_EFCR_9BIT_MODE_BIT BIT(0) /* Enable 9-bit or Multidrop |
250 | 256 | * mode (RS485) */
|
251 |
| -#define SC16IS7XX_EFCR_RXDISABLE_BIT (1 << 1) /* Disable receiver */ |
252 |
| -#define SC16IS7XX_EFCR_TXDISABLE_BIT (1 << 2) /* Disable transmitter */ |
253 |
| -#define SC16IS7XX_EFCR_AUTO_RS485_BIT (1 << 4) /* Auto RS485 RTS direction */ |
254 |
| -#define SC16IS7XX_EFCR_RTS_INVERT_BIT (1 << 5) /* RTS output inversion */ |
255 |
| -#define SC16IS7XX_EFCR_IRDA_MODE_BIT (1 << 7) /* IrDA mode |
| 257 | +#define SC16IS7XX_EFCR_RXDISABLE_BIT BIT(1) /* Disable receiver */ |
| 258 | +#define SC16IS7XX_EFCR_TXDISABLE_BIT BIT(2) /* Disable transmitter */ |
| 259 | +#define SC16IS7XX_EFCR_AUTO_RS485_BIT BIT(4) /* Auto RS485 RTS direction */ |
| 260 | +#define SC16IS7XX_EFCR_RTS_INVERT_BIT BIT(5) /* RTS output inversion */ |
| 261 | +#define SC16IS7XX_EFCR_IRDA_MODE_BIT BIT(7) /* IrDA mode |
256 | 262 | * 0 = rate upto 115.2 kbit/s
|
257 | 263 | * - Only 75x/76x
|
258 | 264 | * 1 = rate upto 1.152 Mbit/s
|
259 | 265 | * - Only 76x
|
260 | 266 | */
|
261 | 267 |
|
262 | 268 | /* EFR register bits */
|
263 |
| -#define SC16IS7XX_EFR_AUTORTS_BIT (1 << 6) /* Auto RTS flow ctrl enable */ |
264 |
| -#define SC16IS7XX_EFR_AUTOCTS_BIT (1 << 7) /* Auto CTS flow ctrl enable */ |
265 |
| -#define SC16IS7XX_EFR_XOFF2_DETECT_BIT (1 << 5) /* Enable Xoff2 detection */ |
266 |
| -#define SC16IS7XX_EFR_ENABLE_BIT (1 << 4) /* Enable enhanced functions |
| 269 | +#define SC16IS7XX_EFR_AUTORTS_BIT BIT(6) /* Auto RTS flow ctrl enable */ |
| 270 | +#define SC16IS7XX_EFR_AUTOCTS_BIT BIT(7) /* Auto CTS flow ctrl enable */ |
| 271 | +#define SC16IS7XX_EFR_XOFF2_DETECT_BIT BIT(5) /* Enable Xoff2 detection */ |
| 272 | +#define SC16IS7XX_EFR_ENABLE_BIT BIT(4) /* Enable enhanced functions |
267 | 273 | * and writing to IER[7:4],
|
268 | 274 | * FCR[5:4], MCR[7:5]
|
269 | 275 | */
|
270 |
| -#define SC16IS7XX_EFR_SWFLOW3_BIT (1 << 3) |
271 |
| -#define SC16IS7XX_EFR_SWFLOW2_BIT (1 << 2) |
| 276 | +#define SC16IS7XX_EFR_SWFLOW3_BIT BIT(3) |
| 277 | +#define SC16IS7XX_EFR_SWFLOW2_BIT BIT(2) |
272 | 278 | /*
|
273 | 279 | * SWFLOW bits 3 & 2 table:
|
274 | 280 | * 00 -> no transmitter flow
|
|
281 | 287 | * XON1, XON2, XOFF1 and
|
282 | 288 | * XOFF2
|
283 | 289 | */
|
284 |
| -#define SC16IS7XX_EFR_SWFLOW1_BIT (1 << 1) |
285 |
| -#define SC16IS7XX_EFR_SWFLOW0_BIT (1 << 0) |
| 290 | +#define SC16IS7XX_EFR_SWFLOW1_BIT BIT(1) |
| 291 | +#define SC16IS7XX_EFR_SWFLOW0_BIT BIT(0) |
286 | 292 | /*
|
287 | 293 | * SWFLOW bits 1 & 0 table:
|
288 | 294 | * 00 -> no received flow
|
|
308 | 314 | #define SC16IS7XX_FIFO_SIZE (64)
|
309 | 315 | #define SC16IS7XX_GPIOS_PER_BANK 4
|
310 | 316 |
|
311 |
| -#define SC16IS7XX_RECONF_MD (1 << 0) |
312 |
| -#define SC16IS7XX_RECONF_IER (1 << 1) |
313 |
| -#define SC16IS7XX_RECONF_RS485 (1 << 2) |
| 317 | +#define SC16IS7XX_RECONF_MD BIT(0) |
| 318 | +#define SC16IS7XX_RECONF_IER BIT(1) |
| 319 | +#define SC16IS7XX_RECONF_RS485 BIT(2) |
314 | 320 |
|
315 | 321 | struct sc16is7xx_one_config {
|
316 | 322 | unsigned int flags;
|
|
0 commit comments