Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  *  linux/include/linux/serial_8250.h
0004  *
0005  *  Copyright (C) 2004 Russell King
0006  */
0007 #ifndef _LINUX_SERIAL_8250_H
0008 #define _LINUX_SERIAL_8250_H
0009 
0010 #include <linux/serial_core.h>
0011 #include <linux/serial_reg.h>
0012 #include <linux/platform_device.h>
0013 
0014 /*
0015  * This is the platform device platform_data structure
0016  */
0017 struct plat_serial8250_port {
0018     unsigned long   iobase;     /* io base address */
0019     void __iomem    *membase;   /* ioremap cookie or NULL */
0020     resource_size_t mapbase;    /* resource base */
0021     unsigned int    irq;        /* interrupt number */
0022     unsigned long   irqflags;   /* request_irq flags */
0023     unsigned int    uartclk;    /* UART clock rate */
0024     void            *private_data;
0025     unsigned char   regshift;   /* register shift */
0026     unsigned char   iotype;     /* UPIO_* */
0027     unsigned char   hub6;
0028     unsigned char   has_sysrq;  /* supports magic SysRq */
0029     upf_t       flags;      /* UPF_* flags */
0030     unsigned int    type;       /* If UPF_FIXED_TYPE */
0031     unsigned int    (*serial_in)(struct uart_port *, int);
0032     void        (*serial_out)(struct uart_port *, int, int);
0033     void        (*set_termios)(struct uart_port *,
0034                            struct ktermios *new,
0035                            struct ktermios *old);
0036     void        (*set_ldisc)(struct uart_port *,
0037                      struct ktermios *);
0038     unsigned int    (*get_mctrl)(struct uart_port *);
0039     int     (*handle_irq)(struct uart_port *);
0040     void        (*pm)(struct uart_port *, unsigned int state,
0041                   unsigned old);
0042     void        (*handle_break)(struct uart_port *);
0043 };
0044 
0045 /*
0046  * Allocate 8250 platform device IDs.  Nothing is implied by
0047  * the numbering here, except for the legacy entry being -1.
0048  */
0049 enum {
0050     PLAT8250_DEV_LEGACY = -1,
0051     PLAT8250_DEV_PLATFORM,
0052     PLAT8250_DEV_PLATFORM1,
0053     PLAT8250_DEV_PLATFORM2,
0054     PLAT8250_DEV_FOURPORT,
0055     PLAT8250_DEV_ACCENT,
0056     PLAT8250_DEV_BOCA,
0057     PLAT8250_DEV_EXAR_ST16C554,
0058     PLAT8250_DEV_HUB6,
0059     PLAT8250_DEV_AU1X00,
0060     PLAT8250_DEV_SM501,
0061 };
0062 
0063 struct uart_8250_dma;
0064 struct uart_8250_port;
0065 
0066 /**
0067  * 8250 core driver operations
0068  *
0069  * @setup_irq()     Setup irq handling. The universal 8250 driver links this
0070  *          port to the irq chain. Other drivers may @request_irq().
0071  * @release_irq()   Undo irq handling. The universal 8250 driver unlinks
0072  *          the port from the irq chain.
0073  */
0074 struct uart_8250_ops {
0075     int     (*setup_irq)(struct uart_8250_port *);
0076     void        (*release_irq)(struct uart_8250_port *);
0077 };
0078 
0079 struct uart_8250_em485 {
0080     struct hrtimer      start_tx_timer; /* "rs485 start tx" timer */
0081     struct hrtimer      stop_tx_timer;  /* "rs485 stop tx" timer */
0082     struct hrtimer      *active_timer;  /* pointer to active timer */
0083     struct uart_8250_port   *port;          /* for hrtimer callbacks */
0084     unsigned int        tx_stopped:1;   /* tx is currently stopped */
0085 };
0086 
0087 /*
0088  * This should be used by drivers which want to register
0089  * their own 8250 ports without registering their own
0090  * platform device.  Using these will make your driver
0091  * dependent on the 8250 driver.
0092  */
0093 
0094 struct uart_8250_port {
0095     struct uart_port    port;
0096     struct timer_list   timer;      /* "no irq" timer */
0097     struct list_head    list;       /* ports on this IRQ */
0098     u32         capabilities;   /* port capabilities */
0099     unsigned short      bugs;       /* port bugs */
0100     bool            fifo_bug;   /* min RX trigger if enabled */
0101     unsigned int        tx_loadsz;  /* transmit fifo load size */
0102     unsigned char       acr;
0103     unsigned char       fcr;
0104     unsigned char       ier;
0105     unsigned char       lcr;
0106     unsigned char       mcr;
0107     unsigned char       cur_iotype; /* Running I/O type */
0108     unsigned int        rpm_tx_active;
0109     unsigned char       canary;     /* non-zero during system sleep
0110                          *   if no_console_suspend
0111                          */
0112     unsigned char       probe;
0113     struct mctrl_gpios  *gpios;
0114 #define UART_PROBE_RSA  (1 << 0)
0115 
0116     /*
0117      * Some bits in registers are cleared on a read, so they must
0118      * be saved whenever the register is read but the bits will not
0119      * be immediately processed.
0120      */
0121 #define LSR_SAVE_FLAGS UART_LSR_BRK_ERROR_BITS
0122     u16         lsr_saved_flags;
0123     u16         lsr_save_mask;
0124 #define MSR_SAVE_FLAGS UART_MSR_ANY_DELTA
0125     unsigned char       msr_saved_flags;
0126 
0127     struct uart_8250_dma    *dma;
0128     const struct uart_8250_ops *ops;
0129 
0130     /* 8250 specific callbacks */
0131     int         (*dl_read)(struct uart_8250_port *);
0132     void            (*dl_write)(struct uart_8250_port *, int);
0133 
0134     struct uart_8250_em485 *em485;
0135     void            (*rs485_start_tx)(struct uart_8250_port *);
0136     void            (*rs485_stop_tx)(struct uart_8250_port *);
0137 
0138     /* Serial port overrun backoff */
0139     struct delayed_work overrun_backoff;
0140     u32 overrun_backoff_time_ms;
0141 };
0142 
0143 static inline struct uart_8250_port *up_to_u8250p(struct uart_port *up)
0144 {
0145     return container_of(up, struct uart_8250_port, port);
0146 }
0147 
0148 int serial8250_register_8250_port(const struct uart_8250_port *);
0149 void serial8250_unregister_port(int line);
0150 void serial8250_suspend_port(int line);
0151 void serial8250_resume_port(int line);
0152 
0153 extern int early_serial_setup(struct uart_port *port);
0154 
0155 extern int early_serial8250_setup(struct earlycon_device *device,
0156                      const char *options);
0157 extern void serial8250_update_uartclk(struct uart_port *port,
0158                       unsigned int uartclk);
0159 extern void serial8250_do_set_termios(struct uart_port *port,
0160         struct ktermios *termios, struct ktermios *old);
0161 extern void serial8250_do_set_ldisc(struct uart_port *port,
0162                     struct ktermios *termios);
0163 extern unsigned int serial8250_do_get_mctrl(struct uart_port *port);
0164 extern int serial8250_do_startup(struct uart_port *port);
0165 extern void serial8250_do_shutdown(struct uart_port *port);
0166 extern void serial8250_do_pm(struct uart_port *port, unsigned int state,
0167                  unsigned int oldstate);
0168 extern void serial8250_do_set_mctrl(struct uart_port *port, unsigned int mctrl);
0169 extern void serial8250_do_set_divisor(struct uart_port *port, unsigned int baud,
0170                       unsigned int quot,
0171                       unsigned int quot_frac);
0172 extern int fsl8250_handle_irq(struct uart_port *port);
0173 int serial8250_handle_irq(struct uart_port *port, unsigned int iir);
0174 u16 serial8250_rx_chars(struct uart_8250_port *up, u16 lsr);
0175 void serial8250_read_char(struct uart_8250_port *up, u16 lsr);
0176 void serial8250_tx_chars(struct uart_8250_port *up);
0177 unsigned int serial8250_modem_status(struct uart_8250_port *up);
0178 void serial8250_init_port(struct uart_8250_port *up);
0179 void serial8250_set_defaults(struct uart_8250_port *up);
0180 void serial8250_console_write(struct uart_8250_port *up, const char *s,
0181                   unsigned int count);
0182 int serial8250_console_setup(struct uart_port *port, char *options, bool probe);
0183 int serial8250_console_exit(struct uart_port *port);
0184 
0185 extern void serial8250_set_isa_configurator(void (*v)
0186                     (int port, struct uart_port *up,
0187                         u32 *capabilities));
0188 
0189 #ifdef CONFIG_SERIAL_8250_RT288X
0190 unsigned int au_serial_in(struct uart_port *p, int offset);
0191 void au_serial_out(struct uart_port *p, int offset, int value);
0192 #endif
0193 
0194 #endif