1 #include <linux/wait.h>
3 #define UART_CONFIG_TYPE (1 << 0)
4 #define UART_CONFIG_IRQ (1 << 1)
9 #define UPIO_AU (4) /* Au1x00 type IO */
10 #define UPIO_TSI (5) /* Tsi108/109 type IO */
11 #define UPF_FOURPORT (1 << 1)
12 #define UPF_SAK (1 << 2)
13 #define UPF_SPD_MASK (0x1030)
14 #define UPF_SPD_HI (0x0010)
15 #define UPF_SPD_VHI (0x0020)
16 #define UPF_SPD_CUST (0x0030)
17 #define UPF_SPD_SHI (0x1000)
18 #define UPF_SPD_WARP (0x1010)
19 #define UPF_SKIP_TEST (1 << 6)
20 #define UPF_AUTO_IRQ (1 << 7)
21 #define UPF_HARDPPS_CD (1 << 11)
22 #define UPF_LOW_LATENCY (1 << 13)
23 #define UPF_BUGGY_UART (1 << 14)
24 #define UPF_MAGIC_MULTIPLIER (1 << 16)
25 #define UPF_CONS_FLOW (1 << 23)
26 #define UPF_SHARE_IRQ (1 << 24)
27 #define UPF_BOOT_AUTOCONF (1 << 28)
28 #define UPF_DEAD (1 << 30)
29 #define UPF_IOREMAP (1 << 31)
30 #define UPF_CHANGE_MASK (0x17fff)
31 #define UPF_USR_MASK (UPF_SPD_MASK|UPF_LOW_LATENCY)
32 #define USF_CLOSING_WAIT_INF (0)
33 #define USF_CLOSING_WAIT_NONE (~0U)
35 #define UART_XMIT_SIZE PAGE_SIZE
37 #define UIF_CHECK_CD (1 << 25)
38 #define UIF_CTS_FLOW (1 << 26)
39 #define UIF_NORMAL_ACTIVE (1 << 29)
40 #define UIF_INITIALIZED (1 << 31)
41 #define UIF_SUSPENDED (1 << 30)
43 #define WAKEUP_CHARS 256
45 #define uart_circ_empty(circ) ((circ)->head == (circ)->tail)
46 #define uart_circ_clear(circ) ((circ)->head = (circ)->tail = 0)
48 #define uart_circ_chars_pending(circ) \
49 (CIRC_CNT((circ)->head, (circ)->tail, UART_XMIT_SIZE))
51 #define uart_circ_chars_free(circ) \
52 (CIRC_SPACE((circ)->head, (circ)->tail, UART_XMIT_SIZE))
54 #define uart_tx_stopped(port) \
55 ((port)->info->tty->stopped || (port)->info->tty->hw_stopped)
57 #define UART_ENABLE_MS(port,cflag) ((port)->flags & UPF_HARDPPS_CD || \
58 (cflag) & CRTSCTS || \
68 unsigned int (*tx_empty
)(struct sb_uart_port
*);
69 void (*set_mctrl
)(struct sb_uart_port
*, unsigned int mctrl
);
70 unsigned int (*get_mctrl
)(struct sb_uart_port
*);
71 void (*stop_tx
)(struct sb_uart_port
*);
72 void (*start_tx
)(struct sb_uart_port
*);
73 void (*send_xchar
)(struct sb_uart_port
*, char ch
);
74 void (*stop_rx
)(struct sb_uart_port
*);
75 void (*enable_ms
)(struct sb_uart_port
*);
76 void (*break_ctl
)(struct sb_uart_port
*, int ctl
);
77 int (*startup
)(struct sb_uart_port
*);
78 void (*shutdown
)(struct sb_uart_port
*);
79 void (*set_termios
)(struct sb_uart_port
*, struct MP_TERMIOS
*new,
80 struct MP_TERMIOS
*old
);
81 void (*pm
)(struct sb_uart_port
*, unsigned int state
,
82 unsigned int oldstate
);
83 int (*set_wake
)(struct sb_uart_port
*, unsigned int state
);
85 const char *(*type
)(struct sb_uart_port
*);
87 void (*release_port
)(struct sb_uart_port
*);
89 int (*request_port
)(struct sb_uart_port
*);
90 void (*config_port
)(struct sb_uart_port
*, int);
91 int (*verify_port
)(struct sb_uart_port
*, struct serial_struct
*);
92 int (*ioctl
)(struct sb_uart_port
*, unsigned int, unsigned long);
96 struct sb_uart_icount
{
109 typedef unsigned int upf_t
;
111 struct sb_uart_port
{
112 spinlock_t lock
; /* port lock */
113 unsigned int iobase
; /* in/out[bwl] */
114 unsigned char __iomem
*membase
; /* read/write[bwl] */
115 unsigned int irq
; /* irq number */
116 unsigned int uartclk
; /* base uart clock */
117 unsigned int fifosize
; /* tx fifo size */
118 unsigned char x_char
; /* xon/xoff char */
119 unsigned char regshift
; /* reg offset shift */
120 unsigned char iotype
; /* io access style */
121 unsigned char unused1
;
124 unsigned int read_status_mask
; /* driver specific */
125 unsigned int ignore_status_mask
; /* driver specific */
126 struct sb_uart_info
*info
; /* pointer to parent info */
127 struct sb_uart_icount icount
; /* statistics */
129 struct console
*cons
; /* struct console, if any */
130 #ifdef CONFIG_SERIAL_CORE_CONSOLE
131 unsigned long sysrq
; /* sysrq timeout */
136 unsigned int mctrl
; /* current modem ctrl settings */
137 unsigned int timeout
; /* character-based timeout */
138 unsigned int type
; /* port type */
139 const struct sb_uart_ops
*ops
;
140 unsigned int custom_divisor
;
141 unsigned int line
; /* port index */
142 unsigned long mapbase
; /* for ioremap */
143 struct device
*dev
; /* parent device */
144 unsigned char hub6
; /* this should be in the 8250 driver */
145 unsigned char unused
[3];
148 #define mdmode unused[2]
149 #define MDMODE_ADDR 0x1
150 #define MDMODE_ENABLE 0x2
151 #define MDMODE_AUTO 0x4
152 #define MDMODE_ADDRSEND 0x8
154 struct sb_uart_state
{
155 unsigned int close_delay
; /* msec */
156 unsigned int closing_wait
; /* msec */
161 struct sb_uart_info
*info
;
162 struct sb_uart_port
*port
;
167 typedef unsigned int uif_t
;
169 struct sb_uart_info
{
170 struct tty_struct
*tty
;
171 struct circ_buf xmit
;
176 struct tasklet_struct tlet
;
178 wait_queue_head_t open_wait
;
179 wait_queue_head_t delta_msr_wait
;
187 struct module
*owner
;
188 const char *driver_name
;
189 const char *dev_name
;
193 struct console
*cons
;
195 struct sb_uart_state
*state
;
196 struct tty_driver
*tty_driver
;
199 void sb_uart_write_wakeup(struct sb_uart_port
*port
)
201 struct sb_uart_info
*info
= port
->info
;
202 tasklet_schedule(&info
->tlet
);
205 void sb_uart_update_timeout(struct sb_uart_port
*port
, unsigned int cflag
,
210 switch (cflag
& CSIZE
)
239 bits
= bits
* port
->fifosize
;
241 port
->timeout
= (HZ
* bits
) / baud
+ HZ
/50;
243 unsigned int sb_uart_get_baud_rate(struct sb_uart_port
*port
, struct MP_TERMIOS
*termios
,
244 struct MP_TERMIOS
*old
, unsigned int min
,
247 unsigned int try, baud
, altbaud
= 38400;
248 upf_t flags
= port
->flags
& UPF_SPD_MASK
;
250 if (flags
== UPF_SPD_HI
)
252 if (flags
== UPF_SPD_VHI
)
254 if (flags
== UPF_SPD_SHI
)
256 if (flags
== UPF_SPD_WARP
)
259 for (try = 0; try < 2; try++) {
261 switch (termios
->c_cflag
& (CBAUD
| CBAUDEX
))
263 case B921600
: baud
= 921600; break;
264 case B460800
: baud
= 460800; break;
265 case B230400
: baud
= 230400; break;
266 case B115200
: baud
= 115200; break;
267 case B57600
: baud
= 57600; break;
268 case B38400
: baud
= 38400; break;
269 case B19200
: baud
= 19200; break;
270 case B9600
: baud
= 9600; break;
271 case B4800
: baud
= 4800; break;
272 case B2400
: baud
= 2400; break;
273 case B1800
: baud
= 1800; break;
274 case B1200
: baud
= 1200; break;
275 case B600
: baud
= 600; break;
276 case B300
: baud
= 300; break;
277 case B200
: baud
= 200; break;
278 case B150
: baud
= 150; break;
279 case B134
: baud
= 134; break;
280 case B110
: baud
= 110; break;
281 case B75
: baud
= 75; break;
282 case B50
: baud
= 50; break;
283 default : baud
= 9600; break;
292 if (baud
>= min
&& baud
<= max
)
295 termios
->c_cflag
&= ~CBAUD
;
297 termios
->c_cflag
|= old
->c_cflag
& CBAUD
;
302 termios
->c_cflag
|= B9600
;
307 unsigned int sb_uart_get_divisor(struct sb_uart_port
*port
, unsigned int baud
)
311 if (baud
== 38400 && (port
->flags
& UPF_SPD_MASK
) == UPF_SPD_CUST
)
312 quot
= port
->custom_divisor
;
314 quot
= (port
->uartclk
+ (8 * baud
)) / (16 * baud
);
321 static inline int sb_uart_handle_break(struct sb_uart_port
*port
)
323 struct sb_uart_info
*info
= port
->info
;
325 if (port
->flags
& UPF_SAK
)
330 static inline void sb_uart_handle_dcd_change(struct sb_uart_port
*port
, unsigned int status
)
332 struct sb_uart_info
*info
= port
->info
;
336 if (info
->flags
& UIF_CHECK_CD
) {
338 wake_up_interruptible(&info
->open_wait
);
340 tty_hangup(info
->tty
);
344 static inline void sb_uart_handle_cts_change(struct sb_uart_port
*port
, unsigned int status
)
346 struct sb_uart_info
*info
= port
->info
;
347 struct tty_struct
*tty
= info
->tty
;
351 if (info
->flags
& UIF_CTS_FLOW
) {
352 if (tty
->hw_stopped
) {
355 port
->ops
->start_tx(port
);
356 sb_uart_write_wakeup(port
);
361 port
->ops
->stop_tx(port
);