aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty/serial/8250.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-01-09 15:09:24 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2012-01-09 15:09:24 -0500
commit5983faf942f260023e547f3c5f38c1033c35cc9b (patch)
treef54ce89de5d9f7a05e99948937ac5456df09df30 /drivers/tty/serial/8250.c
parent21a2cb565a74bf794d343ce22300c5f6c1568ae1 (diff)
parent995234da19b927f42722d796e8270384f33be11c (diff)
Merge branch 'tty-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty
* 'tty-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: (65 commits) tty: serial: imx: move del_timer_sync() to avoid potential deadlock imx: add polled io uart methods imx: Add save/restore functions for UART control regs serial/imx: let probing fail for the dt case without a valid alias serial/imx: propagate error from of_alias_get_id instead of using -ENODEV tty: serial: imx: Allow UART to be a source for wakeup serial: driver for m32 arch should not have DEC alpha errata serial/documentation: fix documented name of DCD cpp symbol atmel_serial: fix spinlock lockup in RS485 code tty: Fix memory leak in virtual console when enable unicode translation serial: use DIV_ROUND_CLOSEST instead of open coding it serial: add support for 400 and 800 v3 series Titan cards serial: bfin-uart: Remove ASYNC_CTS_FLOW flag for hardware automatic CTS. serial: bfin-uart: Enable hardware automatic CTS only when CTS pin is available. serial: make FSL errata depend on 8250_CONSOLE, not just 8250 serial: add irq handler for Freescale 16550 errata. serial: manually inline serial8250_handle_port serial: make 8250 timeout use the specified IRQ handler serial: export the key functions for an 8250 IRQ handler serial: clean up parameter passing for 8250 Rx IRQ handling ...
Diffstat (limited to 'drivers/tty/serial/8250.c')
-rw-r--r--drivers/tty/serial/8250.c98
1 files changed, 35 insertions, 63 deletions
diff --git a/drivers/tty/serial/8250.c b/drivers/tty/serial/8250.c
index eeadf1b8e093..9f50c4e3c2be 100644
--- a/drivers/tty/serial/8250.c
+++ b/drivers/tty/serial/8250.c
@@ -129,32 +129,6 @@ static unsigned long probe_rsa[PORT_RSA_MAX];
129static unsigned int probe_rsa_count; 129static unsigned int probe_rsa_count;
130#endif /* CONFIG_SERIAL_8250_RSA */ 130#endif /* CONFIG_SERIAL_8250_RSA */
131 131
132struct uart_8250_port {
133 struct uart_port port;
134 struct timer_list timer; /* "no irq" timer */
135 struct list_head list; /* ports on this IRQ */
136 unsigned short capabilities; /* port capabilities */
137 unsigned short bugs; /* port bugs */
138 unsigned int tx_loadsz; /* transmit fifo load size */
139 unsigned char acr;
140 unsigned char ier;
141 unsigned char lcr;
142 unsigned char mcr;
143 unsigned char mcr_mask; /* mask of user bits */
144 unsigned char mcr_force; /* mask of forced bits */
145 unsigned char cur_iotype; /* Running I/O type */
146
147 /*
148 * Some bits in registers are cleared on a read, so they must
149 * be saved whenever the register is read but the bits will not
150 * be immediately processed.
151 */
152#define LSR_SAVE_FLAGS UART_LSR_BRK_ERROR_BITS
153 unsigned char lsr_saved_flags;
154#define MSR_SAVE_FLAGS UART_MSR_ANY_DELTA
155 unsigned char msr_saved_flags;
156};
157
158struct irq_info { 132struct irq_info {
159 struct hlist_node node; 133 struct hlist_node node;
160 int irq; 134 int irq;
@@ -1326,8 +1300,6 @@ static void serial8250_stop_tx(struct uart_port *port)
1326 } 1300 }
1327} 1301}
1328 1302
1329static void transmit_chars(struct uart_8250_port *up);
1330
1331static void serial8250_start_tx(struct uart_port *port) 1303static void serial8250_start_tx(struct uart_port *port)
1332{ 1304{
1333 struct uart_8250_port *up = 1305 struct uart_8250_port *up =
@@ -1344,7 +1316,7 @@ static void serial8250_start_tx(struct uart_port *port)
1344 if ((up->port.type == PORT_RM9000) ? 1316 if ((up->port.type == PORT_RM9000) ?
1345 (lsr & UART_LSR_THRE) : 1317 (lsr & UART_LSR_THRE) :
1346 (lsr & UART_LSR_TEMT)) 1318 (lsr & UART_LSR_TEMT))
1347 transmit_chars(up); 1319 serial8250_tx_chars(up);
1348 } 1320 }
1349 } 1321 }
1350 1322
@@ -1401,11 +1373,16 @@ static void clear_rx_fifo(struct uart_8250_port *up)
1401 } while (1); 1373 } while (1);
1402} 1374}
1403 1375
1404static void 1376/*
1405receive_chars(struct uart_8250_port *up, unsigned int *status) 1377 * serial8250_rx_chars: processes according to the passed in LSR
1378 * value, and returns the remaining LSR bits not handled
1379 * by this Rx routine.
1380 */
1381unsigned char
1382serial8250_rx_chars(struct uart_8250_port *up, unsigned char lsr)
1406{ 1383{
1407 struct tty_struct *tty = up->port.state->port.tty; 1384 struct tty_struct *tty = up->port.state->port.tty;
1408 unsigned char ch, lsr = *status; 1385 unsigned char ch;
1409 int max_count = 256; 1386 int max_count = 256;
1410 char flag; 1387 char flag;
1411 1388
@@ -1481,10 +1458,11 @@ ignore_char:
1481 spin_unlock(&up->port.lock); 1458 spin_unlock(&up->port.lock);
1482 tty_flip_buffer_push(tty); 1459 tty_flip_buffer_push(tty);
1483 spin_lock(&up->port.lock); 1460 spin_lock(&up->port.lock);
1484 *status = lsr; 1461 return lsr;
1485} 1462}
1463EXPORT_SYMBOL_GPL(serial8250_rx_chars);
1486 1464
1487static void transmit_chars(struct uart_8250_port *up) 1465void serial8250_tx_chars(struct uart_8250_port *up)
1488{ 1466{
1489 struct circ_buf *xmit = &up->port.state->xmit; 1467 struct circ_buf *xmit = &up->port.state->xmit;
1490 int count; 1468 int count;
@@ -1521,8 +1499,9 @@ static void transmit_chars(struct uart_8250_port *up)
1521 if (uart_circ_empty(xmit)) 1499 if (uart_circ_empty(xmit))
1522 __stop_tx(up); 1500 __stop_tx(up);
1523} 1501}
1502EXPORT_SYMBOL_GPL(serial8250_tx_chars);
1524 1503
1525static unsigned int check_modem_status(struct uart_8250_port *up) 1504unsigned int serial8250_modem_status(struct uart_8250_port *up)
1526{ 1505{
1527 unsigned int status = serial_in(up, UART_MSR); 1506 unsigned int status = serial_in(up, UART_MSR);
1528 1507
@@ -1544,14 +1523,20 @@ static unsigned int check_modem_status(struct uart_8250_port *up)
1544 1523
1545 return status; 1524 return status;
1546} 1525}
1526EXPORT_SYMBOL_GPL(serial8250_modem_status);
1547 1527
1548/* 1528/*
1549 * This handles the interrupt from one port. 1529 * This handles the interrupt from one port.
1550 */ 1530 */
1551static void serial8250_handle_port(struct uart_8250_port *up) 1531int serial8250_handle_irq(struct uart_port *port, unsigned int iir)
1552{ 1532{
1553 unsigned int status; 1533 unsigned char status;
1554 unsigned long flags; 1534 unsigned long flags;
1535 struct uart_8250_port *up =
1536 container_of(port, struct uart_8250_port, port);
1537
1538 if (iir & UART_IIR_NO_INT)
1539 return 0;
1555 1540
1556 spin_lock_irqsave(&up->port.lock, flags); 1541 spin_lock_irqsave(&up->port.lock, flags);
1557 1542
@@ -1560,25 +1545,13 @@ static void serial8250_handle_port(struct uart_8250_port *up)
1560 DEBUG_INTR("status = %x...", status); 1545 DEBUG_INTR("status = %x...", status);
1561 1546
1562 if (status & (UART_LSR_DR | UART_LSR_BI)) 1547 if (status & (UART_LSR_DR | UART_LSR_BI))
1563 receive_chars(up, &status); 1548 status = serial8250_rx_chars(up, status);
1564 check_modem_status(up); 1549 serial8250_modem_status(up);
1565 if (status & UART_LSR_THRE) 1550 if (status & UART_LSR_THRE)
1566 transmit_chars(up); 1551 serial8250_tx_chars(up);
1567 1552
1568 spin_unlock_irqrestore(&up->port.lock, flags); 1553 spin_unlock_irqrestore(&up->port.lock, flags);
1569} 1554 return 1;
1570
1571int serial8250_handle_irq(struct uart_port *port, unsigned int iir)
1572{
1573 struct uart_8250_port *up =
1574 container_of(port, struct uart_8250_port, port);
1575
1576 if (!(iir & UART_IIR_NO_INT)) {
1577 serial8250_handle_port(up);
1578 return 1;
1579 }
1580
1581 return 0;
1582} 1555}
1583EXPORT_SYMBOL_GPL(serial8250_handle_irq); 1556EXPORT_SYMBOL_GPL(serial8250_handle_irq);
1584 1557
@@ -1619,11 +1592,13 @@ static irqreturn_t serial8250_interrupt(int irq, void *dev_id)
1619 do { 1592 do {
1620 struct uart_8250_port *up; 1593 struct uart_8250_port *up;
1621 struct uart_port *port; 1594 struct uart_port *port;
1595 bool skip;
1622 1596
1623 up = list_entry(l, struct uart_8250_port, list); 1597 up = list_entry(l, struct uart_8250_port, list);
1624 port = &up->port; 1598 port = &up->port;
1599 skip = pass_counter && up->port.flags & UPF_IIR_ONCE;
1625 1600
1626 if (port->handle_irq(port)) { 1601 if (!skip && port->handle_irq(port)) {
1627 handled = 1; 1602 handled = 1;
1628 end = NULL; 1603 end = NULL;
1629 } else if (end == NULL) 1604 } else if (end == NULL)
@@ -1758,11 +1733,8 @@ static void serial_unlink_irq_chain(struct uart_8250_port *up)
1758static void serial8250_timeout(unsigned long data) 1733static void serial8250_timeout(unsigned long data)
1759{ 1734{
1760 struct uart_8250_port *up = (struct uart_8250_port *)data; 1735 struct uart_8250_port *up = (struct uart_8250_port *)data;
1761 unsigned int iir;
1762 1736
1763 iir = serial_in(up, UART_IIR); 1737 up->port.handle_irq(&up->port);
1764 if (!(iir & UART_IIR_NO_INT))
1765 serial8250_handle_port(up);
1766 mod_timer(&up->timer, jiffies + uart_poll_timeout(&up->port)); 1738 mod_timer(&up->timer, jiffies + uart_poll_timeout(&up->port));
1767} 1739}
1768 1740
@@ -1801,7 +1773,7 @@ static void serial8250_backup_timeout(unsigned long data)
1801 } 1773 }
1802 1774
1803 if (!(iir & UART_IIR_NO_INT)) 1775 if (!(iir & UART_IIR_NO_INT))
1804 transmit_chars(up); 1776 serial8250_tx_chars(up);
1805 1777
1806 if (is_real_interrupt(up->port.irq)) 1778 if (is_real_interrupt(up->port.irq))
1807 serial_out(up, UART_IER, ier); 1779 serial_out(up, UART_IER, ier);
@@ -1835,7 +1807,7 @@ static unsigned int serial8250_get_mctrl(struct uart_port *port)
1835 unsigned int status; 1807 unsigned int status;
1836 unsigned int ret; 1808 unsigned int ret;
1837 1809
1838 status = check_modem_status(up); 1810 status = serial8250_modem_status(up);
1839 1811
1840 ret = 0; 1812 ret = 0;
1841 if (status & UART_MSR_DCD) 1813 if (status & UART_MSR_DCD)
@@ -2000,7 +1972,7 @@ static int serial8250_startup(struct uart_port *port)
2000 serial_outp(up, UART_IER, 0); 1972 serial_outp(up, UART_IER, 0);
2001 serial_outp(up, UART_LCR, 0); 1973 serial_outp(up, UART_LCR, 0);
2002 serial_icr_write(up, UART_CSR, 0); /* Reset the UART */ 1974 serial_icr_write(up, UART_CSR, 0); /* Reset the UART */
2003 serial_outp(up, UART_LCR, 0xBF); 1975 serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_B);
2004 serial_outp(up, UART_EFR, UART_EFR_ECB); 1976 serial_outp(up, UART_EFR, UART_EFR_ECB);
2005 serial_outp(up, UART_LCR, 0); 1977 serial_outp(up, UART_LCR, 0);
2006 } 1978 }
@@ -2848,7 +2820,7 @@ serial8250_console_write(struct console *co, const char *s, unsigned int count)
2848 2820
2849 local_irq_save(flags); 2821 local_irq_save(flags);
2850 if (up->port.sysrq) { 2822 if (up->port.sysrq) {
2851 /* serial8250_handle_port() already took the lock */ 2823 /* serial8250_handle_irq() already took the lock */
2852 locked = 0; 2824 locked = 0;
2853 } else if (oops_in_progress) { 2825 } else if (oops_in_progress) {
2854 locked = spin_trylock(&up->port.lock); 2826 locked = spin_trylock(&up->port.lock);
@@ -2882,7 +2854,7 @@ serial8250_console_write(struct console *co, const char *s, unsigned int count)
2882 * while processing with interrupts off. 2854 * while processing with interrupts off.
2883 */ 2855 */
2884 if (up->msr_saved_flags) 2856 if (up->msr_saved_flags)
2885 check_modem_status(up); 2857 serial8250_modem_status(up);
2886 2858
2887 if (locked) 2859 if (locked)
2888 spin_unlock(&up->port.lock); 2860 spin_unlock(&up->port.lock);