serial_core.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * linux/drivers/char/serial_core.h
  4. *
  5. * Copyright (C) 2000 Deep Blue Solutions Ltd.
  6. */
  7. #ifndef LINUX_SERIAL_CORE_H
  8. #define LINUX_SERIAL_CORE_H
  9. #include <linux/bitops.h>
  10. #include <linux/compiler.h>
  11. #include <linux/console.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/circ_buf.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/sched.h>
  16. #include <linux/tty.h>
  17. #include <linux/mutex.h>
  18. #include <linux/sysrq.h>
  19. #include <linux/android_kabi.h>
  20. #include <uapi/linux/serial_core.h>
  21. #ifdef CONFIG_SERIAL_CORE_CONSOLE
  22. #define uart_console(port) \
  23. ((port)->cons && (port)->cons->index == (port)->line)
  24. #else
  25. #define uart_console(port) ({ (void)port; 0; })
  26. #endif
  27. struct uart_port;
  28. struct serial_struct;
  29. struct device;
  30. struct gpio_desc;
  31. /*
  32. * This structure describes all the operations that can be done on the
  33. * physical hardware. See Documentation/driver-api/serial/driver.rst for details.
  34. */
  35. struct uart_ops {
  36. unsigned int (*tx_empty)(struct uart_port *);
  37. void (*set_mctrl)(struct uart_port *, unsigned int mctrl);
  38. unsigned int (*get_mctrl)(struct uart_port *);
  39. void (*stop_tx)(struct uart_port *);
  40. void (*start_tx)(struct uart_port *);
  41. void (*throttle)(struct uart_port *);
  42. void (*unthrottle)(struct uart_port *);
  43. void (*send_xchar)(struct uart_port *, char ch);
  44. void (*stop_rx)(struct uart_port *);
  45. void (*enable_ms)(struct uart_port *);
  46. void (*break_ctl)(struct uart_port *, int ctl);
  47. int (*startup)(struct uart_port *);
  48. void (*shutdown)(struct uart_port *);
  49. void (*flush_buffer)(struct uart_port *);
  50. void (*set_termios)(struct uart_port *, struct ktermios *new,
  51. struct ktermios *old);
  52. void (*set_ldisc)(struct uart_port *, struct ktermios *);
  53. void (*pm)(struct uart_port *, unsigned int state,
  54. unsigned int oldstate);
  55. /*
  56. * Return a string describing the type of the port
  57. */
  58. const char *(*type)(struct uart_port *);
  59. /*
  60. * Release IO and memory resources used by the port.
  61. * This includes iounmap if necessary.
  62. */
  63. void (*release_port)(struct uart_port *);
  64. /*
  65. * Request IO and memory resources used by the port.
  66. * This includes iomapping the port if necessary.
  67. */
  68. int (*request_port)(struct uart_port *);
  69. void (*config_port)(struct uart_port *, int);
  70. int (*verify_port)(struct uart_port *, struct serial_struct *);
  71. int (*ioctl)(struct uart_port *, unsigned int, unsigned long);
  72. #ifdef CONFIG_CONSOLE_POLL
  73. int (*poll_init)(struct uart_port *);
  74. void (*poll_put_char)(struct uart_port *, unsigned char);
  75. int (*poll_get_char)(struct uart_port *);
  76. #endif
  77. ANDROID_KABI_RESERVE(1);
  78. ANDROID_KABI_RESERVE(2);
  79. };
  80. #define NO_POLL_CHAR 0x00ff0000
  81. #define UART_CONFIG_TYPE (1 << 0)
  82. #define UART_CONFIG_IRQ (1 << 1)
  83. struct uart_icount {
  84. __u32 cts;
  85. __u32 dsr;
  86. __u32 rng;
  87. __u32 dcd;
  88. __u32 rx;
  89. __u32 tx;
  90. __u32 frame;
  91. __u32 overrun;
  92. __u32 parity;
  93. __u32 brk;
  94. __u32 buf_overrun;
  95. };
  96. typedef unsigned int __bitwise upf_t;
  97. typedef unsigned int __bitwise upstat_t;
  98. struct uart_port {
  99. spinlock_t lock; /* port lock */
  100. unsigned long iobase; /* in/out[bwl] */
  101. unsigned char __iomem *membase; /* read/write[bwl] */
  102. unsigned int (*serial_in)(struct uart_port *, int);
  103. void (*serial_out)(struct uart_port *, int, int);
  104. void (*set_termios)(struct uart_port *,
  105. struct ktermios *new,
  106. struct ktermios *old);
  107. void (*set_ldisc)(struct uart_port *,
  108. struct ktermios *);
  109. unsigned int (*get_mctrl)(struct uart_port *);
  110. void (*set_mctrl)(struct uart_port *, unsigned int);
  111. unsigned int (*get_divisor)(struct uart_port *,
  112. unsigned int baud,
  113. unsigned int *frac);
  114. void (*set_divisor)(struct uart_port *,
  115. unsigned int baud,
  116. unsigned int quot,
  117. unsigned int quot_frac);
  118. int (*startup)(struct uart_port *port);
  119. void (*shutdown)(struct uart_port *port);
  120. void (*throttle)(struct uart_port *port);
  121. void (*unthrottle)(struct uart_port *port);
  122. int (*handle_irq)(struct uart_port *);
  123. void (*pm)(struct uart_port *, unsigned int state,
  124. unsigned int old);
  125. void (*handle_break)(struct uart_port *);
  126. int (*rs485_config)(struct uart_port *,
  127. struct serial_rs485 *rs485);
  128. int (*iso7816_config)(struct uart_port *,
  129. struct serial_iso7816 *iso7816);
  130. unsigned int irq; /* irq number */
  131. unsigned long irqflags; /* irq flags */
  132. unsigned int uartclk; /* base uart clock */
  133. unsigned int fifosize; /* tx fifo size */
  134. unsigned char x_char; /* xon/xoff char */
  135. unsigned char regshift; /* reg offset shift */
  136. unsigned char iotype; /* io access style */
  137. unsigned char quirks; /* internal quirks */
  138. #define UPIO_PORT (SERIAL_IO_PORT) /* 8b I/O port access */
  139. #define UPIO_HUB6 (SERIAL_IO_HUB6) /* Hub6 ISA card */
  140. #define UPIO_MEM (SERIAL_IO_MEM) /* driver-specific */
  141. #define UPIO_MEM32 (SERIAL_IO_MEM32) /* 32b little endian */
  142. #define UPIO_AU (SERIAL_IO_AU) /* Au1x00 and RT288x type IO */
  143. #define UPIO_TSI (SERIAL_IO_TSI) /* Tsi108/109 type IO */
  144. #define UPIO_MEM32BE (SERIAL_IO_MEM32BE) /* 32b big endian */
  145. #define UPIO_MEM16 (SERIAL_IO_MEM16) /* 16b little endian */
  146. /* quirks must be updated while holding port mutex */
  147. #define UPQ_NO_TXEN_TEST BIT(0)
  148. unsigned int read_status_mask; /* driver specific */
  149. unsigned int ignore_status_mask; /* driver specific */
  150. struct uart_state *state; /* pointer to parent state */
  151. struct uart_icount icount; /* statistics */
  152. struct console *cons; /* struct console, if any */
  153. /* flags must be updated while holding port mutex */
  154. upf_t flags;
  155. /*
  156. * These flags must be equivalent to the flags defined in
  157. * include/uapi/linux/tty_flags.h which are the userspace definitions
  158. * assigned from the serial_struct flags in uart_set_info()
  159. * [for bit definitions in the UPF_CHANGE_MASK]
  160. *
  161. * Bits [0..UPF_LAST_USER] are userspace defined/visible/changeable
  162. * The remaining bits are serial-core specific and not modifiable by
  163. * userspace.
  164. */
  165. #define UPF_FOURPORT ((__force upf_t) ASYNC_FOURPORT /* 1 */ )
  166. #define UPF_SAK ((__force upf_t) ASYNC_SAK /* 2 */ )
  167. #define UPF_SPD_HI ((__force upf_t) ASYNC_SPD_HI /* 4 */ )
  168. #define UPF_SPD_VHI ((__force upf_t) ASYNC_SPD_VHI /* 5 */ )
  169. #define UPF_SPD_CUST ((__force upf_t) ASYNC_SPD_CUST /* 0x0030 */ )
  170. #define UPF_SPD_WARP ((__force upf_t) ASYNC_SPD_WARP /* 0x1010 */ )
  171. #define UPF_SPD_MASK ((__force upf_t) ASYNC_SPD_MASK /* 0x1030 */ )
  172. #define UPF_SKIP_TEST ((__force upf_t) ASYNC_SKIP_TEST /* 6 */ )
  173. #define UPF_AUTO_IRQ ((__force upf_t) ASYNC_AUTO_IRQ /* 7 */ )
  174. #define UPF_HARDPPS_CD ((__force upf_t) ASYNC_HARDPPS_CD /* 11 */ )
  175. #define UPF_SPD_SHI ((__force upf_t) ASYNC_SPD_SHI /* 12 */ )
  176. #define UPF_LOW_LATENCY ((__force upf_t) ASYNC_LOW_LATENCY /* 13 */ )
  177. #define UPF_BUGGY_UART ((__force upf_t) ASYNC_BUGGY_UART /* 14 */ )
  178. #define UPF_MAGIC_MULTIPLIER ((__force upf_t) ASYNC_MAGIC_MULTIPLIER /* 16 */ )
  179. #define UPF_NO_THRE_TEST ((__force upf_t) (1 << 19))
  180. /* Port has hardware-assisted h/w flow control */
  181. #define UPF_AUTO_CTS ((__force upf_t) (1 << 20))
  182. #define UPF_AUTO_RTS ((__force upf_t) (1 << 21))
  183. #define UPF_HARD_FLOW ((__force upf_t) (UPF_AUTO_CTS | UPF_AUTO_RTS))
  184. /* Port has hardware-assisted s/w flow control */
  185. #define UPF_SOFT_FLOW ((__force upf_t) (1 << 22))
  186. #define UPF_CONS_FLOW ((__force upf_t) (1 << 23))
  187. #define UPF_SHARE_IRQ ((__force upf_t) (1 << 24))
  188. #define UPF_EXAR_EFR ((__force upf_t) (1 << 25))
  189. #define UPF_BUG_THRE ((__force upf_t) (1 << 26))
  190. /* The exact UART type is known and should not be probed. */
  191. #define UPF_FIXED_TYPE ((__force upf_t) (1 << 27))
  192. #define UPF_BOOT_AUTOCONF ((__force upf_t) (1 << 28))
  193. #define UPF_FIXED_PORT ((__force upf_t) (1 << 29))
  194. #define UPF_DEAD ((__force upf_t) (1 << 30))
  195. #define UPF_IOREMAP ((__force upf_t) (1 << 31))
  196. #define __UPF_CHANGE_MASK 0x17fff
  197. #define UPF_CHANGE_MASK ((__force upf_t) __UPF_CHANGE_MASK)
  198. #define UPF_USR_MASK ((__force upf_t) (UPF_SPD_MASK|UPF_LOW_LATENCY))
  199. #if __UPF_CHANGE_MASK > ASYNC_FLAGS
  200. #error Change mask not equivalent to userspace-visible bit defines
  201. #endif
  202. /*
  203. * Must hold termios_rwsem, port mutex and port lock to change;
  204. * can hold any one lock to read.
  205. */
  206. upstat_t status;
  207. #define UPSTAT_CTS_ENABLE ((__force upstat_t) (1 << 0))
  208. #define UPSTAT_DCD_ENABLE ((__force upstat_t) (1 << 1))
  209. #define UPSTAT_AUTORTS ((__force upstat_t) (1 << 2))
  210. #define UPSTAT_AUTOCTS ((__force upstat_t) (1 << 3))
  211. #define UPSTAT_AUTOXOFF ((__force upstat_t) (1 << 4))
  212. #define UPSTAT_SYNC_FIFO ((__force upstat_t) (1 << 5))
  213. int hw_stopped; /* sw-assisted CTS flow state */
  214. unsigned int mctrl; /* current modem ctrl settings */
  215. unsigned int timeout; /* character-based timeout */
  216. unsigned int type; /* port type */
  217. const struct uart_ops *ops;
  218. unsigned int custom_divisor;
  219. unsigned int line; /* port index */
  220. unsigned int minor;
  221. resource_size_t mapbase; /* for ioremap */
  222. resource_size_t mapsize;
  223. struct device *dev; /* parent device */
  224. unsigned long sysrq; /* sysrq timeout */
  225. unsigned int sysrq_ch; /* char for sysrq */
  226. unsigned char has_sysrq;
  227. unsigned char sysrq_seq; /* index in sysrq_toggle_seq */
  228. unsigned char hub6; /* this should be in the 8250 driver */
  229. unsigned char suspended;
  230. unsigned char console_reinit;
  231. const char *name; /* port name */
  232. struct attribute_group *attr_group; /* port specific attributes */
  233. const struct attribute_group **tty_groups; /* all attributes (serial core use only) */
  234. struct serial_rs485 rs485;
  235. struct gpio_desc *rs485_term_gpio; /* enable RS485 bus termination */
  236. struct serial_iso7816 iso7816;
  237. void *private_data; /* generic platform data pointer */
  238. ANDROID_KABI_RESERVE(1);
  239. ANDROID_KABI_RESERVE(2);
  240. };
  241. static inline int serial_port_in(struct uart_port *up, int offset)
  242. {
  243. return up->serial_in(up, offset);
  244. }
  245. static inline void serial_port_out(struct uart_port *up, int offset, int value)
  246. {
  247. up->serial_out(up, offset, value);
  248. }
  249. /**
  250. * enum uart_pm_state - power states for UARTs
  251. * @UART_PM_STATE_ON: UART is powered, up and operational
  252. * @UART_PM_STATE_OFF: UART is powered off
  253. * @UART_PM_STATE_UNDEFINED: sentinel
  254. */
  255. enum uart_pm_state {
  256. UART_PM_STATE_ON = 0,
  257. UART_PM_STATE_OFF = 3, /* number taken from ACPI */
  258. UART_PM_STATE_UNDEFINED,
  259. };
  260. /*
  261. * This is the state information which is persistent across opens.
  262. */
  263. struct uart_state {
  264. struct tty_port port;
  265. enum uart_pm_state pm_state;
  266. struct circ_buf xmit;
  267. atomic_t refcount;
  268. wait_queue_head_t remove_wait;
  269. struct uart_port *uart_port;
  270. };
  271. #define UART_XMIT_SIZE PAGE_SIZE
  272. /* number of characters left in xmit buffer before we ask for more */
  273. #define WAKEUP_CHARS 256
  274. struct module;
  275. struct tty_driver;
  276. struct uart_driver {
  277. struct module *owner;
  278. const char *driver_name;
  279. const char *dev_name;
  280. int major;
  281. int minor;
  282. int nr;
  283. struct console *cons;
  284. /*
  285. * these are private; the low level driver should not
  286. * touch these; they should be initialised to NULL
  287. */
  288. struct uart_state *state;
  289. struct tty_driver *tty_driver;
  290. ANDROID_KABI_RESERVE(1);
  291. };
  292. void uart_write_wakeup(struct uart_port *port);
  293. /*
  294. * Baud rate helpers.
  295. */
  296. void uart_update_timeout(struct uart_port *port, unsigned int cflag,
  297. unsigned int baud);
  298. unsigned int uart_get_baud_rate(struct uart_port *port, struct ktermios *termios,
  299. struct ktermios *old, unsigned int min,
  300. unsigned int max);
  301. unsigned int uart_get_divisor(struct uart_port *port, unsigned int baud);
  302. /* Base timer interval for polling */
  303. static inline int uart_poll_timeout(struct uart_port *port)
  304. {
  305. int timeout = port->timeout;
  306. return timeout > 6 ? (timeout / 2 - 2) : 1;
  307. }
  308. /*
  309. * Console helpers.
  310. */
  311. struct earlycon_device {
  312. struct console *con;
  313. struct uart_port port;
  314. char options[16]; /* e.g., 115200n8 */
  315. unsigned int baud;
  316. };
  317. struct earlycon_id {
  318. char name[15];
  319. char name_term; /* In case compiler didn't '\0' term name */
  320. char compatible[128];
  321. int (*setup)(struct earlycon_device *, const char *options);
  322. };
  323. extern const struct earlycon_id *__earlycon_table[];
  324. extern const struct earlycon_id *__earlycon_table_end[];
  325. #if defined(CONFIG_SERIAL_EARLYCON) && !defined(MODULE)
  326. #define EARLYCON_USED_OR_UNUSED __used
  327. #else
  328. #define EARLYCON_USED_OR_UNUSED __maybe_unused
  329. #endif
  330. #define _OF_EARLYCON_DECLARE(_name, compat, fn, unique_id) \
  331. static const struct earlycon_id unique_id \
  332. EARLYCON_USED_OR_UNUSED __initconst \
  333. = { .name = __stringify(_name), \
  334. .compatible = compat, \
  335. .setup = fn }; \
  336. static const struct earlycon_id EARLYCON_USED_OR_UNUSED \
  337. __section("__earlycon_table") \
  338. * const __PASTE(__p, unique_id) = &unique_id
  339. #define OF_EARLYCON_DECLARE(_name, compat, fn) \
  340. _OF_EARLYCON_DECLARE(_name, compat, fn, \
  341. __UNIQUE_ID(__earlycon_##_name))
  342. #define EARLYCON_DECLARE(_name, fn) OF_EARLYCON_DECLARE(_name, "", fn)
  343. extern int of_setup_earlycon(const struct earlycon_id *match,
  344. unsigned long node,
  345. const char *options);
  346. #ifdef CONFIG_SERIAL_EARLYCON
  347. extern bool earlycon_acpi_spcr_enable __initdata;
  348. int setup_earlycon(char *buf);
  349. #else
  350. static const bool earlycon_acpi_spcr_enable EARLYCON_USED_OR_UNUSED;
  351. static inline int setup_earlycon(char *buf) { return 0; }
  352. #endif
  353. struct uart_port *uart_get_console(struct uart_port *ports, int nr,
  354. struct console *c);
  355. int uart_parse_earlycon(char *p, unsigned char *iotype, resource_size_t *addr,
  356. char **options);
  357. void uart_parse_options(const char *options, int *baud, int *parity, int *bits,
  358. int *flow);
  359. int uart_set_options(struct uart_port *port, struct console *co, int baud,
  360. int parity, int bits, int flow);
  361. struct tty_driver *uart_console_device(struct console *co, int *index);
  362. void uart_console_write(struct uart_port *port, const char *s,
  363. unsigned int count,
  364. void (*putchar)(struct uart_port *, int));
  365. /*
  366. * Port/driver registration/removal
  367. */
  368. int uart_register_driver(struct uart_driver *uart);
  369. void uart_unregister_driver(struct uart_driver *uart);
  370. int uart_add_one_port(struct uart_driver *reg, struct uart_port *port);
  371. int uart_remove_one_port(struct uart_driver *reg, struct uart_port *port);
  372. int uart_match_port(struct uart_port *port1, struct uart_port *port2);
  373. /*
  374. * Power Management
  375. */
  376. int uart_suspend_port(struct uart_driver *reg, struct uart_port *port);
  377. int uart_resume_port(struct uart_driver *reg, struct uart_port *port);
  378. #define uart_circ_empty(circ) ((circ)->head == (circ)->tail)
  379. #define uart_circ_clear(circ) ((circ)->head = (circ)->tail = 0)
  380. #define uart_circ_chars_pending(circ) \
  381. (CIRC_CNT((circ)->head, (circ)->tail, UART_XMIT_SIZE))
  382. #define uart_circ_chars_free(circ) \
  383. (CIRC_SPACE((circ)->head, (circ)->tail, UART_XMIT_SIZE))
  384. static inline int uart_tx_stopped(struct uart_port *port)
  385. {
  386. struct tty_struct *tty = port->state->port.tty;
  387. if ((tty && tty->stopped) || port->hw_stopped)
  388. return 1;
  389. return 0;
  390. }
  391. static inline bool uart_cts_enabled(struct uart_port *uport)
  392. {
  393. return !!(uport->status & UPSTAT_CTS_ENABLE);
  394. }
  395. static inline bool uart_softcts_mode(struct uart_port *uport)
  396. {
  397. upstat_t mask = UPSTAT_CTS_ENABLE | UPSTAT_AUTOCTS;
  398. return ((uport->status & mask) == UPSTAT_CTS_ENABLE);
  399. }
  400. /*
  401. * The following are helper functions for the low level drivers.
  402. */
  403. extern void uart_handle_dcd_change(struct uart_port *uport,
  404. unsigned int status);
  405. extern void uart_handle_cts_change(struct uart_port *uport,
  406. unsigned int status);
  407. extern void uart_insert_char(struct uart_port *port, unsigned int status,
  408. unsigned int overrun, unsigned int ch, unsigned int flag);
  409. void uart_xchar_out(struct uart_port *uport, int offset);
  410. #ifdef CONFIG_MAGIC_SYSRQ_SERIAL
  411. #define SYSRQ_TIMEOUT (HZ * 5)
  412. bool uart_try_toggle_sysrq(struct uart_port *port, unsigned int ch);
  413. static inline int uart_handle_sysrq_char(struct uart_port *port, unsigned int ch)
  414. {
  415. if (!port->sysrq)
  416. return 0;
  417. if (ch && time_before(jiffies, port->sysrq)) {
  418. if (sysrq_mask()) {
  419. handle_sysrq(ch);
  420. port->sysrq = 0;
  421. return 1;
  422. }
  423. if (uart_try_toggle_sysrq(port, ch))
  424. return 1;
  425. }
  426. port->sysrq = 0;
  427. return 0;
  428. }
  429. static inline int uart_prepare_sysrq_char(struct uart_port *port, unsigned int ch)
  430. {
  431. if (!port->sysrq)
  432. return 0;
  433. if (ch && time_before(jiffies, port->sysrq)) {
  434. if (sysrq_mask()) {
  435. port->sysrq_ch = ch;
  436. port->sysrq = 0;
  437. return 1;
  438. }
  439. if (uart_try_toggle_sysrq(port, ch))
  440. return 1;
  441. }
  442. port->sysrq = 0;
  443. return 0;
  444. }
  445. static inline void uart_unlock_and_check_sysrq(struct uart_port *port, unsigned long irqflags)
  446. {
  447. int sysrq_ch;
  448. if (!port->has_sysrq) {
  449. spin_unlock_irqrestore(&port->lock, irqflags);
  450. return;
  451. }
  452. sysrq_ch = port->sysrq_ch;
  453. port->sysrq_ch = 0;
  454. spin_unlock_irqrestore(&port->lock, irqflags);
  455. if (sysrq_ch)
  456. handle_sysrq(sysrq_ch);
  457. }
  458. #else /* CONFIG_MAGIC_SYSRQ_SERIAL */
  459. static inline int uart_handle_sysrq_char(struct uart_port *port, unsigned int ch)
  460. {
  461. return 0;
  462. }
  463. static inline int uart_prepare_sysrq_char(struct uart_port *port, unsigned int ch)
  464. {
  465. return 0;
  466. }
  467. static inline void uart_unlock_and_check_sysrq(struct uart_port *port, unsigned long irqflags)
  468. {
  469. spin_unlock_irqrestore(&port->lock, irqflags);
  470. }
  471. #endif /* CONFIG_MAGIC_SYSRQ_SERIAL */
  472. /*
  473. * We do the SysRQ and SAK checking like this...
  474. */
  475. static inline int uart_handle_break(struct uart_port *port)
  476. {
  477. struct uart_state *state = port->state;
  478. if (port->handle_break)
  479. port->handle_break(port);
  480. #ifdef CONFIG_MAGIC_SYSRQ_SERIAL
  481. if (port->has_sysrq && uart_console(port)) {
  482. if (!port->sysrq) {
  483. port->sysrq = jiffies + SYSRQ_TIMEOUT;
  484. return 1;
  485. }
  486. port->sysrq = 0;
  487. }
  488. #endif
  489. if (port->flags & UPF_SAK)
  490. do_SAK(state->port.tty);
  491. return 0;
  492. }
  493. /*
  494. * UART_ENABLE_MS - determine if port should enable modem status irqs
  495. */
  496. #define UART_ENABLE_MS(port,cflag) ((port)->flags & UPF_HARDPPS_CD || \
  497. (cflag) & CRTSCTS || \
  498. !((cflag) & CLOCAL))
  499. int uart_get_rs485_mode(struct uart_port *port);
  500. #endif /* LINUX_SERIAL_CORE_H */