moxa.c (b300fb26c59a749bf49559932fa8a85eb916b5a7) | moxa.c (5d420399073770134d2b03e004b2c0201c7fa26f) |
---|---|
1// SPDX-License-Identifier: GPL-2.0+ 2/*****************************************************************************/ 3/* 4 * moxa.c -- MOXA Intellio family multiport serial driver. 5 * 6 * Copyright (C) 1999-2000 Moxa Technologies (support@moxa.com). 7 * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com> 8 * --- 488 unchanged lines hidden (view full) --- 497static void moxa_hangup(struct tty_struct *); 498static int moxa_tiocmget(struct tty_struct *tty); 499static int moxa_tiocmset(struct tty_struct *tty, 500 unsigned int set, unsigned int clear); 501static void moxa_poll(struct timer_list *); 502static void moxa_set_tty_param(struct tty_struct *, const struct ktermios *); 503static void moxa_shutdown(struct tty_port *); 504static bool moxa_carrier_raised(struct tty_port *); | 1// SPDX-License-Identifier: GPL-2.0+ 2/*****************************************************************************/ 3/* 4 * moxa.c -- MOXA Intellio family multiport serial driver. 5 * 6 * Copyright (C) 1999-2000 Moxa Technologies (support@moxa.com). 7 * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com> 8 * --- 488 unchanged lines hidden (view full) --- 497static void moxa_hangup(struct tty_struct *); 498static int moxa_tiocmget(struct tty_struct *tty); 499static int moxa_tiocmset(struct tty_struct *tty, 500 unsigned int set, unsigned int clear); 501static void moxa_poll(struct timer_list *); 502static void moxa_set_tty_param(struct tty_struct *, const struct ktermios *); 503static void moxa_shutdown(struct tty_port *); 504static bool moxa_carrier_raised(struct tty_port *); |
505static void moxa_dtr_rts(struct tty_port *, int); | 505static void moxa_dtr_rts(struct tty_port *, bool); |
506/* 507 * moxa board interface functions: 508 */ 509static void MoxaPortEnable(struct moxa_port *); 510static void MoxaPortDisable(struct moxa_port *); 511static int MoxaPortSetTermio(struct moxa_port *, struct ktermios *, speed_t); | 506/* 507 * moxa board interface functions: 508 */ 509static void MoxaPortEnable(struct moxa_port *); 510static void MoxaPortDisable(struct moxa_port *); 511static int MoxaPortSetTermio(struct moxa_port *, struct ktermios *, speed_t); |
512static int MoxaPortGetLineOut(struct moxa_port *, int *, int *); 513static void MoxaPortLineCtrl(struct moxa_port *, int, int); | 512static int MoxaPortGetLineOut(struct moxa_port *, bool *, bool *); 513static void MoxaPortLineCtrl(struct moxa_port *, bool, bool); |
514static void MoxaPortFlowCtrl(struct moxa_port *, int, int, int, int, int); 515static int MoxaPortLineStatus(struct moxa_port *); 516static void MoxaPortFlushData(struct moxa_port *, int); 517static int MoxaPortWriteData(struct tty_struct *, const unsigned char *, int); 518static int MoxaPortReadData(struct moxa_port *); 519static unsigned int MoxaPortTxQueue(struct moxa_port *); 520static int MoxaPortRxQueue(struct moxa_port *); 521static unsigned int MoxaPortTxFree(struct moxa_port *); --- 916 unchanged lines hidden (view full) --- 1438 int dcd; 1439 1440 spin_lock_irq(&port->lock); 1441 dcd = ch->DCDState; 1442 spin_unlock_irq(&port->lock); 1443 return dcd; 1444} 1445 | 514static void MoxaPortFlowCtrl(struct moxa_port *, int, int, int, int, int); 515static int MoxaPortLineStatus(struct moxa_port *); 516static void MoxaPortFlushData(struct moxa_port *, int); 517static int MoxaPortWriteData(struct tty_struct *, const unsigned char *, int); 518static int MoxaPortReadData(struct moxa_port *); 519static unsigned int MoxaPortTxQueue(struct moxa_port *); 520static int MoxaPortRxQueue(struct moxa_port *); 521static unsigned int MoxaPortTxFree(struct moxa_port *); --- 916 unchanged lines hidden (view full) --- 1438 int dcd; 1439 1440 spin_lock_irq(&port->lock); 1441 dcd = ch->DCDState; 1442 spin_unlock_irq(&port->lock); 1443 return dcd; 1444} 1445 |
1446static void moxa_dtr_rts(struct tty_port *port, int onoff) | 1446static void moxa_dtr_rts(struct tty_port *port, bool onoff) |
1447{ 1448 struct moxa_port *ch = container_of(port, struct moxa_port, port); 1449 MoxaPortLineCtrl(ch, onoff, onoff); 1450} 1451 1452 1453static int moxa_open(struct tty_struct *tty, struct file *filp) 1454{ --- 21 unchanged lines hidden (view full) --- 1476 ch = &brd->ports[port % MAX_PORTS_PER_BOARD]; 1477 ch->port.count++; 1478 tty->driver_data = ch; 1479 tty_port_tty_set(&ch->port, tty); 1480 mutex_lock(&ch->port.mutex); 1481 if (!tty_port_initialized(&ch->port)) { 1482 ch->statusflags = 0; 1483 moxa_set_tty_param(tty, &tty->termios); | 1447{ 1448 struct moxa_port *ch = container_of(port, struct moxa_port, port); 1449 MoxaPortLineCtrl(ch, onoff, onoff); 1450} 1451 1452 1453static int moxa_open(struct tty_struct *tty, struct file *filp) 1454{ --- 21 unchanged lines hidden (view full) --- 1476 ch = &brd->ports[port % MAX_PORTS_PER_BOARD]; 1477 ch->port.count++; 1478 tty->driver_data = ch; 1479 tty_port_tty_set(&ch->port, tty); 1480 mutex_lock(&ch->port.mutex); 1481 if (!tty_port_initialized(&ch->port)) { 1482 ch->statusflags = 0; 1483 moxa_set_tty_param(tty, &tty->termios); |
1484 MoxaPortLineCtrl(ch, 1, 1); | 1484 MoxaPortLineCtrl(ch, true, true); |
1485 MoxaPortEnable(ch); 1486 MoxaSetFifo(ch, ch->type == PORT_16550A); 1487 tty_port_set_initialized(&ch->port, true); 1488 } 1489 mutex_unlock(&ch->port.mutex); 1490 mutex_unlock(&moxa_openlock); 1491 1492 return tty_port_block_til_ready(&ch->port, tty, filp); --- 59 unchanged lines hidden (view full) --- 1552 */ 1553 set_bit(EMPTYWAIT, &ch->statusflags); 1554 return chars; 1555} 1556 1557static int moxa_tiocmget(struct tty_struct *tty) 1558{ 1559 struct moxa_port *ch = tty->driver_data; | 1485 MoxaPortEnable(ch); 1486 MoxaSetFifo(ch, ch->type == PORT_16550A); 1487 tty_port_set_initialized(&ch->port, true); 1488 } 1489 mutex_unlock(&ch->port.mutex); 1490 mutex_unlock(&moxa_openlock); 1491 1492 return tty_port_block_til_ready(&ch->port, tty, filp); --- 59 unchanged lines hidden (view full) --- 1552 */ 1553 set_bit(EMPTYWAIT, &ch->statusflags); 1554 return chars; 1555} 1556 1557static int moxa_tiocmget(struct tty_struct *tty) 1558{ 1559 struct moxa_port *ch = tty->driver_data; |
1560 int flag = 0, dtr, rts; | 1560 bool dtr, rts; 1561 int flag = 0; 1562 int status; |
1561 1562 MoxaPortGetLineOut(ch, &dtr, &rts); 1563 if (dtr) 1564 flag |= TIOCM_DTR; 1565 if (rts) 1566 flag |= TIOCM_RTS; | 1563 1564 MoxaPortGetLineOut(ch, &dtr, &rts); 1565 if (dtr) 1566 flag |= TIOCM_DTR; 1567 if (rts) 1568 flag |= TIOCM_RTS; |
1567 dtr = MoxaPortLineStatus(ch); 1568 if (dtr & 1) | 1569 status = MoxaPortLineStatus(ch); 1570 if (status & 1) |
1569 flag |= TIOCM_CTS; | 1571 flag |= TIOCM_CTS; |
1570 if (dtr & 2) | 1572 if (status & 2) |
1571 flag |= TIOCM_DSR; | 1573 flag |= TIOCM_DSR; |
1572 if (dtr & 4) | 1574 if (status & 4) |
1573 flag |= TIOCM_CD; 1574 return flag; 1575} 1576 1577static int moxa_tiocmset(struct tty_struct *tty, 1578 unsigned int set, unsigned int clear) 1579{ 1580 struct moxa_port *ch; | 1575 flag |= TIOCM_CD; 1576 return flag; 1577} 1578 1579static int moxa_tiocmset(struct tty_struct *tty, 1580 unsigned int set, unsigned int clear) 1581{ 1582 struct moxa_port *ch; |
1581 int dtr, rts; | 1583 bool dtr, rts; |
1582 1583 mutex_lock(&moxa_openlock); 1584 ch = tty->driver_data; 1585 if (!ch) { 1586 mutex_unlock(&moxa_openlock); 1587 return -EINVAL; 1588 } 1589 1590 MoxaPortGetLineOut(ch, &dtr, &rts); 1591 if (set & TIOCM_RTS) | 1584 1585 mutex_lock(&moxa_openlock); 1586 ch = tty->driver_data; 1587 if (!ch) { 1588 mutex_unlock(&moxa_openlock); 1589 return -EINVAL; 1590 } 1591 1592 MoxaPortGetLineOut(ch, &dtr, &rts); 1593 if (set & TIOCM_RTS) |
1592 rts = 1; | 1594 rts = true; |
1593 if (set & TIOCM_DTR) | 1595 if (set & TIOCM_DTR) |
1594 dtr = 1; | 1596 dtr = true; |
1595 if (clear & TIOCM_RTS) | 1597 if (clear & TIOCM_RTS) |
1596 rts = 0; | 1598 rts = false; |
1597 if (clear & TIOCM_DTR) | 1599 if (clear & TIOCM_DTR) |
1598 dtr = 0; | 1600 dtr = false; |
1599 MoxaPortLineCtrl(ch, dtr, rts); 1600 mutex_unlock(&moxa_openlock); 1601 return 0; 1602} 1603 1604static void moxa_set_termios(struct tty_struct *tty, 1605 const struct ktermios *old_termios) 1606{ --- 265 unchanged lines hidden (view full) --- 1872 * speed_t baud : baud rate 1873 * 1874 * return: -1 : this port is invalid or termio == NULL 1875 * 0 : setting O.K. 1876 * 1877 * 1878 * Function 13: Get the DTR/RTS state of this port. 1879 * Syntax: | 1601 MoxaPortLineCtrl(ch, dtr, rts); 1602 mutex_unlock(&moxa_openlock); 1603 return 0; 1604} 1605 1606static void moxa_set_termios(struct tty_struct *tty, 1607 const struct ktermios *old_termios) 1608{ --- 265 unchanged lines hidden (view full) --- 1874 * speed_t baud : baud rate 1875 * 1876 * return: -1 : this port is invalid or termio == NULL 1877 * 0 : setting O.K. 1878 * 1879 * 1880 * Function 13: Get the DTR/RTS state of this port. 1881 * Syntax: |
1880 * int MoxaPortGetLineOut(int port, int *dtrState, int *rtsState); | 1882 * int MoxaPortGetLineOut(int port, bool *dtrState, bool *rtsState); |
1881 * int port : port number (0 - 127) | 1883 * int port : port number (0 - 127) |
1882 * int * dtrState : pointer to INT to receive the current DTR | 1884 * bool * dtrState : pointer to bool to receive the current DTR |
1883 * state. (if NULL, this function will not 1884 * write to this address) | 1885 * state. (if NULL, this function will not 1886 * write to this address) |
1885 * int * rtsState : pointer to INT to receive the current RTS | 1887 * bool * rtsState : pointer to bool to receive the current RTS |
1886 * state. (if NULL, this function will not 1887 * write to this address) 1888 * 1889 * return: -1 : this port is invalid 1890 * 0 : O.K. 1891 * 1892 * 1893 * Function 14: Setting the DTR/RTS output state of this port. 1894 * Syntax: | 1888 * state. (if NULL, this function will not 1889 * write to this address) 1890 * 1891 * return: -1 : this port is invalid 1892 * 0 : O.K. 1893 * 1894 * 1895 * Function 14: Setting the DTR/RTS output state of this port. 1896 * Syntax: |
1895 * void MoxaPortLineCtrl(int port, int dtrState, int rtsState); | 1897 * void MoxaPortLineCtrl(int port, bool dtrState, bool rtsState); |
1896 * int port : port number (0 - 127) | 1898 * int port : port number (0 - 127) |
1897 * int dtrState : DTR output state (0: off, 1: on) 1898 * int rtsState : RTS output state (0: off, 1: on) | 1899 * bool dtrState : DTR output state 1900 * bool rtsState : RTS output state |
1899 * 1900 * 1901 * Function 15: Setting the flow control of this port. 1902 * Syntax: 1903 * void MoxaPortFlowCtrl(int port, int rtsFlow, int ctsFlow, int rxFlow, 1904 * int txFlow,int xany); 1905 * int port : port number (0 - 127) 1906 * int rtsFlow : H/W RTS flow control (0: no, 1: yes) --- 191 unchanged lines hidden (view full) --- 2098 writeb(FC_SetXonXoff, ofsAddr + FuncCode); 2099 moxa_wait_finish(ofsAddr); 2100 spin_unlock_irq(&moxafunc_lock); 2101 2102 } 2103 return baud; 2104} 2105 | 1901 * 1902 * 1903 * Function 15: Setting the flow control of this port. 1904 * Syntax: 1905 * void MoxaPortFlowCtrl(int port, int rtsFlow, int ctsFlow, int rxFlow, 1906 * int txFlow,int xany); 1907 * int port : port number (0 - 127) 1908 * int rtsFlow : H/W RTS flow control (0: no, 1: yes) --- 191 unchanged lines hidden (view full) --- 2100 writeb(FC_SetXonXoff, ofsAddr + FuncCode); 2101 moxa_wait_finish(ofsAddr); 2102 spin_unlock_irq(&moxafunc_lock); 2103 2104 } 2105 return baud; 2106} 2107 |
2106static int MoxaPortGetLineOut(struct moxa_port *port, int *dtrState, 2107 int *rtsState) | 2108static int MoxaPortGetLineOut(struct moxa_port *port, bool *dtrState, 2109 bool *rtsState) |
2108{ 2109 if (dtrState) | 2110{ 2111 if (dtrState) |
2110 *dtrState = !!(port->lineCtrl & DTR_ON); | 2112 *dtrState = port->lineCtrl & DTR_ON; |
2111 if (rtsState) | 2113 if (rtsState) |
2112 *rtsState = !!(port->lineCtrl & RTS_ON); | 2114 *rtsState = port->lineCtrl & RTS_ON; |
2113 2114 return 0; 2115} 2116 | 2115 2116 return 0; 2117} 2118 |
2117static void MoxaPortLineCtrl(struct moxa_port *port, int dtr, int rts) | 2119static void MoxaPortLineCtrl(struct moxa_port *port, bool dtr, bool rts) |
2118{ 2119 u8 mode = 0; 2120 2121 if (dtr) 2122 mode |= DTR_ON; 2123 if (rts) 2124 mode |= RTS_ON; 2125 port->lineCtrl = mode; --- 273 unchanged lines hidden --- | 2120{ 2121 u8 mode = 0; 2122 2123 if (dtr) 2124 mode |= DTR_ON; 2125 if (rts) 2126 mode |= RTS_ON; 2127 port->lineCtrl = mode; --- 273 unchanged lines hidden --- |