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