forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 958e46acc8e900e8569dd467c1af9b8d2d019394
kernel/drivers/tty/serial/8250/8250.h
....@@ -1,4 +1,4 @@
1
-// SPDX-License-Identifier: GPL-2.0+
1
+/* SPDX-License-Identifier: GPL-2.0+ */
22 /*
33 * Driver for 8250/16550-type serial ports
44 *
....@@ -10,6 +10,8 @@
1010 #include <linux/serial_8250.h>
1111 #include <linux/serial_reg.h>
1212 #include <linux/dmaengine.h>
13
+
14
+#include "../serial_mctrl_gpio.h"
1315
1416 struct uart_8250_dma {
1517 int (*tx_dma)(struct uart_8250_port *p);
....@@ -46,7 +48,7 @@
4648 unsigned char tx_running;
4749 unsigned char tx_err;
4850 unsigned char rx_running;
49
-#ifdef CONFIG_ARCH_ROCKCHIP
51
+#if defined(CONFIG_ARCH_ROCKCHIP) && defined(CONFIG_NO_GKI)
5052 size_t rx_index;
5153 #endif
5254 };
....@@ -89,6 +91,7 @@
8991 #define UART_BUG_NOMSR (1 << 2) /* UART has buggy MSR status bits (Au1x00) */
9092 #define UART_BUG_THRE (1 << 3) /* UART has buggy THRE reassertion */
9193 #define UART_BUG_PARITY (1 << 4) /* UART mishandles parity if FIFO enabled */
94
+#define UART_BUG_TXRACE (1 << 5) /* UART Tx fails to set remote DR */
9295
9396
9497 #ifdef CONFIG_SERIAL_8250_SHARE_IRQ
....@@ -119,6 +122,28 @@
119122 up->port.serial_out(&up->port, offset, value);
120123 }
121124
125
+/*
126
+ * For the 16C950
127
+ */
128
+static void serial_icr_write(struct uart_8250_port *up, int offset, int value)
129
+{
130
+ serial_out(up, UART_SCR, offset);
131
+ serial_out(up, UART_ICR, value);
132
+}
133
+
134
+static unsigned int __maybe_unused serial_icr_read(struct uart_8250_port *up,
135
+ int offset)
136
+{
137
+ unsigned int value;
138
+
139
+ serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD);
140
+ serial_out(up, UART_SCR, offset);
141
+ value = serial_in(up, UART_ICR);
142
+ serial_icr_write(up, UART_ACR, up->acr);
143
+
144
+ return value;
145
+}
146
+
122147 void serial8250_clear_and_reinit_fifos(struct uart_8250_port *p);
123148
124149 static inline int serial_dl_read(struct uart_8250_port *up)
....@@ -131,6 +156,73 @@
131156 up->dl_write(up, value);
132157 }
133158
159
+static inline void serial8250_set_IER(struct uart_8250_port *up,
160
+ unsigned char ier)
161
+{
162
+ struct uart_port *port = &up->port;
163
+ unsigned int flags;
164
+ bool is_console;
165
+
166
+ is_console = uart_console(port);
167
+
168
+ if (is_console)
169
+ console_atomic_lock(&flags);
170
+
171
+ serial_out(up, UART_IER, ier);
172
+
173
+ if (is_console)
174
+ console_atomic_unlock(flags);
175
+}
176
+
177
+static inline unsigned char serial8250_clear_IER(struct uart_8250_port *up)
178
+{
179
+ struct uart_port *port = &up->port;
180
+ unsigned int clearval = 0;
181
+ unsigned int prior;
182
+ unsigned int flags;
183
+ bool is_console;
184
+
185
+ is_console = uart_console(port);
186
+
187
+ if (up->capabilities & UART_CAP_UUE)
188
+ clearval = UART_IER_UUE;
189
+
190
+ if (is_console)
191
+ console_atomic_lock(&flags);
192
+
193
+ prior = serial_port_in(port, UART_IER);
194
+ serial_port_out(port, UART_IER, clearval);
195
+
196
+ if (is_console)
197
+ console_atomic_unlock(flags);
198
+
199
+ return prior;
200
+}
201
+
202
+static inline bool serial8250_set_THRI(struct uart_8250_port *up)
203
+{
204
+ if (up->ier & UART_IER_THRI)
205
+ return false;
206
+ up->ier |= UART_IER_THRI;
207
+#if defined(CONFIG_ARCH_ROCKCHIP) && defined(CONFIG_NO_GKI)
208
+ up->ier |= UART_IER_PTIME;
209
+#endif
210
+ serial8250_set_IER(up, up->ier);
211
+ return true;
212
+}
213
+
214
+static inline bool serial8250_clear_THRI(struct uart_8250_port *up)
215
+{
216
+ if (!(up->ier & UART_IER_THRI))
217
+ return false;
218
+ up->ier &= ~UART_IER_THRI;
219
+#if defined(CONFIG_ARCH_ROCKCHIP) && defined(CONFIG_NO_GKI)
220
+ up->ier &= ~UART_IER_PTIME;
221
+#endif
222
+ serial8250_set_IER(up, up->ier);
223
+ return true;
224
+}
225
+
134226 struct uart_8250_port *serial8250_get_port(int line);
135227
136228 void serial8250_rpm_get(struct uart_8250_port *p);
....@@ -139,17 +231,87 @@
139231 void serial8250_rpm_get_tx(struct uart_8250_port *p);
140232 void serial8250_rpm_put_tx(struct uart_8250_port *p);
141233
142
-int serial8250_em485_init(struct uart_8250_port *p);
234
+int serial8250_em485_config(struct uart_port *port, struct serial_rs485 *rs485);
235
+void serial8250_em485_start_tx(struct uart_8250_port *p);
236
+void serial8250_em485_stop_tx(struct uart_8250_port *p);
143237 void serial8250_em485_destroy(struct uart_8250_port *p);
238
+
239
+/* MCR <-> TIOCM conversion */
240
+static inline int serial8250_TIOCM_to_MCR(int tiocm)
241
+{
242
+ int mcr = 0;
243
+
244
+ if (tiocm & TIOCM_RTS)
245
+ mcr |= UART_MCR_RTS;
246
+ if (tiocm & TIOCM_DTR)
247
+ mcr |= UART_MCR_DTR;
248
+ if (tiocm & TIOCM_OUT1)
249
+ mcr |= UART_MCR_OUT1;
250
+ if (tiocm & TIOCM_OUT2)
251
+ mcr |= UART_MCR_OUT2;
252
+ if (tiocm & TIOCM_LOOP)
253
+ mcr |= UART_MCR_LOOP;
254
+
255
+ return mcr;
256
+}
257
+
258
+static inline int serial8250_MCR_to_TIOCM(int mcr)
259
+{
260
+ int tiocm = 0;
261
+
262
+ if (mcr & UART_MCR_RTS)
263
+ tiocm |= TIOCM_RTS;
264
+ if (mcr & UART_MCR_DTR)
265
+ tiocm |= TIOCM_DTR;
266
+ if (mcr & UART_MCR_OUT1)
267
+ tiocm |= TIOCM_OUT1;
268
+ if (mcr & UART_MCR_OUT2)
269
+ tiocm |= TIOCM_OUT2;
270
+ if (mcr & UART_MCR_LOOP)
271
+ tiocm |= TIOCM_LOOP;
272
+
273
+ return tiocm;
274
+}
275
+
276
+/* MSR <-> TIOCM conversion */
277
+static inline int serial8250_MSR_to_TIOCM(int msr)
278
+{
279
+ int tiocm = 0;
280
+
281
+ if (msr & UART_MSR_DCD)
282
+ tiocm |= TIOCM_CAR;
283
+ if (msr & UART_MSR_RI)
284
+ tiocm |= TIOCM_RNG;
285
+ if (msr & UART_MSR_DSR)
286
+ tiocm |= TIOCM_DSR;
287
+ if (msr & UART_MSR_CTS)
288
+ tiocm |= TIOCM_CTS;
289
+
290
+ return tiocm;
291
+}
144292
145293 static inline void serial8250_out_MCR(struct uart_8250_port *up, int value)
146294 {
147295 serial_out(up, UART_MCR, value);
296
+
297
+ if (up->gpios)
298
+ mctrl_gpio_set(up->gpios, serial8250_MCR_to_TIOCM(value));
148299 }
149300
150301 static inline int serial8250_in_MCR(struct uart_8250_port *up)
151302 {
152
- return serial_in(up, UART_MCR);
303
+ int mctrl;
304
+
305
+ mctrl = serial_in(up, UART_MCR);
306
+
307
+ if (up->gpios) {
308
+ unsigned int mctrl_gpio = 0;
309
+
310
+ mctrl_gpio = mctrl_gpio_get_outputs(up->gpios, &mctrl_gpio);
311
+ mctrl |= serial8250_TIOCM_to_MCR(mctrl_gpio);
312
+ }
313
+
314
+ return mctrl;
153315 }
154316
155317 #if defined(__alpha__) && !defined(CONFIG_PCI)
....@@ -217,6 +379,9 @@
217379 #ifdef CONFIG_SERIAL_8250_DMA
218380 extern int serial8250_tx_dma(struct uart_8250_port *);
219381 extern int serial8250_rx_dma(struct uart_8250_port *);
382
+#if defined(CONFIG_ARCH_ROCKCHIP) && defined(CONFIG_NO_GKI)
383
+extern int serial8250_start_rx_dma(struct uart_8250_port *);
384
+#endif
220385 extern void serial8250_rx_dma_flush(struct uart_8250_port *);
221386 extern int serial8250_request_dma(struct uart_8250_port *);
222387 extern void serial8250_release_dma(struct uart_8250_port *);
....@@ -229,6 +394,12 @@
229394 {
230395 return -1;
231396 }
397
+#if defined(CONFIG_ARCH_ROCKCHIP) && defined(CONFIG_NO_GKI)
398
+static inline int serial8250_start_rx_dma(struct uart_8250_port *p)
399
+{
400
+ return -1;
401
+}
402
+#endif
232403 static inline void serial8250_rx_dma_flush(struct uart_8250_port *p) { }
233404 static inline int serial8250_request_dma(struct uart_8250_port *p)
234405 {