aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/moxa.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/moxa.c')
-rw-r--r--drivers/char/moxa.c97
1 files changed, 46 insertions, 51 deletions
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index d57d3a61919b..2bba250ffc8e 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -130,17 +130,13 @@ struct moxaq_str {
130}; 130};
131 131
132struct moxa_port { 132struct moxa_port {
133 struct tty_port port;
133 struct moxa_board_conf *board; 134 struct moxa_board_conf *board;
134 struct tty_struct *tty;
135 void __iomem *tableAddr; 135 void __iomem *tableAddr;
136 136
137 int type; 137 int type;
138 int close_delay;
139 unsigned int count;
140 int asyncflags;
141 int cflag; 138 int cflag;
142 unsigned long statusflags; 139 unsigned long statusflags;
143 wait_queue_head_t open_wait;
144 140
145 u8 DCDState; 141 u8 DCDState;
146 u8 lineCtrl; 142 u8 lineCtrl;
@@ -348,10 +344,10 @@ static int moxa_ioctl(struct tty_struct *tty, struct file *file,
348 if (status & 4) 344 if (status & 4)
349 tmp.dcd = 1; 345 tmp.dcd = 1;
350 346
351 if (!p->tty || !p->tty->termios) 347 if (!p->port.tty || !p->port.tty->termios)
352 tmp.cflag = p->cflag; 348 tmp.cflag = p->cflag;
353 else 349 else
354 tmp.cflag = p->tty->termios->c_cflag; 350 tmp.cflag = p->port.tty->termios->c_cflag;
355copy: 351copy:
356 if (copy_to_user(argm, &tmp, sizeof(tmp))) { 352 if (copy_to_user(argm, &tmp, sizeof(tmp))) {
357 mutex_unlock(&moxa_openlock); 353 mutex_unlock(&moxa_openlock);
@@ -721,7 +717,7 @@ static int moxa_load_code(struct moxa_board_conf *brd, const void *ptr,
721 717
722static int moxa_load_fw(struct moxa_board_conf *brd, const struct firmware *fw) 718static int moxa_load_fw(struct moxa_board_conf *brd, const struct firmware *fw)
723{ 719{
724 void *ptr = fw->data; 720 const void *ptr = fw->data;
725 char rsn[64]; 721 char rsn[64];
726 u16 lens[5]; 722 u16 lens[5];
727 size_t len; 723 size_t len;
@@ -734,7 +730,7 @@ static int moxa_load_fw(struct moxa_board_conf *brd, const struct firmware *fw)
734 u8 model; /* C218T=1, C320T=2, CP204=3 */ 730 u8 model; /* C218T=1, C320T=2, CP204=3 */
735 u8 reserved2[8]; 731 u8 reserved2[8];
736 __le16 len[5]; 732 __le16 len[5];
737 } *hdr = ptr; 733 } const *hdr = ptr;
738 734
739 BUILD_BUG_ON(ARRAY_SIZE(hdr->len) != ARRAY_SIZE(lens)); 735 BUILD_BUG_ON(ARRAY_SIZE(hdr->len) != ARRAY_SIZE(lens));
740 736
@@ -825,10 +821,9 @@ static int moxa_init_board(struct moxa_board_conf *brd, struct device *dev)
825 } 821 }
826 822
827 for (i = 0, p = brd->ports; i < MAX_PORTS_PER_BOARD; i++, p++) { 823 for (i = 0, p = brd->ports; i < MAX_PORTS_PER_BOARD; i++, p++) {
824 tty_port_init(&p->port);
828 p->type = PORT_16550A; 825 p->type = PORT_16550A;
829 p->close_delay = 5 * HZ / 10;
830 p->cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; 826 p->cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
831 init_waitqueue_head(&p->open_wait);
832 } 827 }
833 828
834 switch (brd->boardType) { 829 switch (brd->boardType) {
@@ -884,12 +879,12 @@ static void moxa_board_deinit(struct moxa_board_conf *brd)
884 879
885 /* pci hot-un-plug support */ 880 /* pci hot-un-plug support */
886 for (a = 0; a < brd->numPorts; a++) 881 for (a = 0; a < brd->numPorts; a++)
887 if (brd->ports[a].asyncflags & ASYNC_INITIALIZED) 882 if (brd->ports[a].port.flags & ASYNC_INITIALIZED)
888 tty_hangup(brd->ports[a].tty); 883 tty_hangup(brd->ports[a].port.tty);
889 while (1) { 884 while (1) {
890 opened = 0; 885 opened = 0;
891 for (a = 0; a < brd->numPorts; a++) 886 for (a = 0; a < brd->numPorts; a++)
892 if (brd->ports[a].asyncflags & ASYNC_INITIALIZED) 887 if (brd->ports[a].port.flags & ASYNC_INITIALIZED)
893 opened++; 888 opened++;
894 mutex_unlock(&moxa_openlock); 889 mutex_unlock(&moxa_openlock);
895 if (!opened) 890 if (!opened)
@@ -1104,9 +1099,9 @@ static void moxa_close_port(struct moxa_port *ch)
1104{ 1099{
1105 moxa_shut_down(ch); 1100 moxa_shut_down(ch);
1106 MoxaPortFlushData(ch, 2); 1101 MoxaPortFlushData(ch, 2);
1107 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE; 1102 ch->port.flags &= ~ASYNC_NORMAL_ACTIVE;
1108 ch->tty->driver_data = NULL; 1103 ch->port.tty->driver_data = NULL;
1109 ch->tty = NULL; 1104 ch->port.tty = NULL;
1110} 1105}
1111 1106
1112static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp, 1107static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp,
@@ -1117,7 +1112,7 @@ static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp,
1117 u8 dcd; 1112 u8 dcd;
1118 1113
1119 while (1) { 1114 while (1) {
1120 prepare_to_wait(&ch->open_wait, &wait, TASK_INTERRUPTIBLE); 1115 prepare_to_wait(&ch->port.open_wait, &wait, TASK_INTERRUPTIBLE);
1121 if (tty_hung_up_p(filp)) { 1116 if (tty_hung_up_p(filp)) {
1122#ifdef SERIAL_DO_RESTART 1117#ifdef SERIAL_DO_RESTART
1123 retval = -ERESTARTSYS; 1118 retval = -ERESTARTSYS;
@@ -1138,7 +1133,7 @@ static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp,
1138 } 1133 }
1139 schedule(); 1134 schedule();
1140 } 1135 }
1141 finish_wait(&ch->open_wait, &wait); 1136 finish_wait(&ch->port.open_wait, &wait);
1142 1137
1143 return retval; 1138 return retval;
1144} 1139}
@@ -1163,16 +1158,16 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
1163 } 1158 }
1164 1159
1165 ch = &brd->ports[port % MAX_PORTS_PER_BOARD]; 1160 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
1166 ch->count++; 1161 ch->port.count++;
1167 tty->driver_data = ch; 1162 tty->driver_data = ch;
1168 ch->tty = tty; 1163 ch->port.tty = tty;
1169 if (!(ch->asyncflags & ASYNC_INITIALIZED)) { 1164 if (!(ch->port.flags & ASYNC_INITIALIZED)) {
1170 ch->statusflags = 0; 1165 ch->statusflags = 0;
1171 moxa_set_tty_param(tty, tty->termios); 1166 moxa_set_tty_param(tty, tty->termios);
1172 MoxaPortLineCtrl(ch, 1, 1); 1167 MoxaPortLineCtrl(ch, 1, 1);
1173 MoxaPortEnable(ch); 1168 MoxaPortEnable(ch);
1174 MoxaSetFifo(ch, ch->type == PORT_16550A); 1169 MoxaSetFifo(ch, ch->type == PORT_16550A);
1175 ch->asyncflags |= ASYNC_INITIALIZED; 1170 ch->port.flags |= ASYNC_INITIALIZED;
1176 } 1171 }
1177 mutex_unlock(&moxa_openlock); 1172 mutex_unlock(&moxa_openlock);
1178 1173
@@ -1181,11 +1176,11 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
1181 retval = moxa_block_till_ready(tty, filp, ch); 1176 retval = moxa_block_till_ready(tty, filp, ch);
1182 mutex_lock(&moxa_openlock); 1177 mutex_lock(&moxa_openlock);
1183 if (retval) { 1178 if (retval) {
1184 if (ch->count) /* 0 means already hung up... */ 1179 if (ch->port.count) /* 0 means already hung up... */
1185 if (--ch->count == 0) 1180 if (--ch->port.count == 0)
1186 moxa_close_port(ch); 1181 moxa_close_port(ch);
1187 } else 1182 } else
1188 ch->asyncflags |= ASYNC_NORMAL_ACTIVE; 1183 ch->port.flags |= ASYNC_NORMAL_ACTIVE;
1189 mutex_unlock(&moxa_openlock); 1184 mutex_unlock(&moxa_openlock);
1190 1185
1191 return retval; 1186 return retval;
@@ -1204,21 +1199,21 @@ static void moxa_close(struct tty_struct *tty, struct file *filp)
1204 ch = tty->driver_data; 1199 ch = tty->driver_data;
1205 if (ch == NULL) 1200 if (ch == NULL)
1206 goto unlock; 1201 goto unlock;
1207 if (tty->count == 1 && ch->count != 1) { 1202 if (tty->count == 1 && ch->port.count != 1) {
1208 printk(KERN_WARNING "moxa_close: bad serial port count; " 1203 printk(KERN_WARNING "moxa_close: bad serial port count; "
1209 "tty->count is 1, ch->count is %d\n", ch->count); 1204 "tty->count is 1, ch->port.count is %d\n", ch->port.count);
1210 ch->count = 1; 1205 ch->port.count = 1;
1211 } 1206 }
1212 if (--ch->count < 0) { 1207 if (--ch->port.count < 0) {
1213 printk(KERN_WARNING "moxa_close: bad serial port count, " 1208 printk(KERN_WARNING "moxa_close: bad serial port count, "
1214 "device=%s\n", tty->name); 1209 "device=%s\n", tty->name);
1215 ch->count = 0; 1210 ch->port.count = 0;
1216 } 1211 }
1217 if (ch->count) 1212 if (ch->port.count)
1218 goto unlock; 1213 goto unlock;
1219 1214
1220 ch->cflag = tty->termios->c_cflag; 1215 ch->cflag = tty->termios->c_cflag;
1221 if (ch->asyncflags & ASYNC_INITIALIZED) { 1216 if (ch->port.flags & ASYNC_INITIALIZED) {
1222 moxa_setup_empty_event(tty); 1217 moxa_setup_empty_event(tty);
1223 tty_wait_until_sent(tty, 30 * HZ); /* 30 seconds timeout */ 1218 tty_wait_until_sent(tty, 30 * HZ); /* 30 seconds timeout */
1224 } 1219 }
@@ -1374,7 +1369,7 @@ static void moxa_set_termios(struct tty_struct *tty,
1374 return; 1369 return;
1375 moxa_set_tty_param(tty, old_termios); 1370 moxa_set_tty_param(tty, old_termios);
1376 if (!(old_termios->c_cflag & CLOCAL) && C_CLOCAL(tty)) 1371 if (!(old_termios->c_cflag & CLOCAL) && C_CLOCAL(tty))
1377 wake_up_interruptible(&ch->open_wait); 1372 wake_up_interruptible(&ch->port.open_wait);
1378} 1373}
1379 1374
1380static void moxa_stop(struct tty_struct *tty) 1375static void moxa_stop(struct tty_struct *tty)
@@ -1412,20 +1407,20 @@ static void moxa_hangup(struct tty_struct *tty)
1412 mutex_unlock(&moxa_openlock); 1407 mutex_unlock(&moxa_openlock);
1413 return; 1408 return;
1414 } 1409 }
1415 ch->count = 0; 1410 ch->port.count = 0;
1416 moxa_close_port(ch); 1411 moxa_close_port(ch);
1417 mutex_unlock(&moxa_openlock); 1412 mutex_unlock(&moxa_openlock);
1418 1413
1419 wake_up_interruptible(&ch->open_wait); 1414 wake_up_interruptible(&ch->port.open_wait);
1420} 1415}
1421 1416
1422static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd) 1417static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd)
1423{ 1418{
1424 dcd = !!dcd; 1419 dcd = !!dcd;
1425 1420
1426 if (dcd != p->DCDState && p->tty && C_CLOCAL(p->tty)) { 1421 if (dcd != p->DCDState && p->port.tty && C_CLOCAL(p->port.tty)) {
1427 if (!dcd) 1422 if (!dcd)
1428 tty_hangup(p->tty); 1423 tty_hangup(p->port.tty);
1429 } 1424 }
1430 p->DCDState = dcd; 1425 p->DCDState = dcd;
1431} 1426}
@@ -1433,9 +1428,9 @@ static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd)
1433static int moxa_poll_port(struct moxa_port *p, unsigned int handle, 1428static int moxa_poll_port(struct moxa_port *p, unsigned int handle,
1434 u16 __iomem *ip) 1429 u16 __iomem *ip)
1435{ 1430{
1436 struct tty_struct *tty = p->tty; 1431 struct tty_struct *tty = p->port.tty;
1437 void __iomem *ofsAddr; 1432 void __iomem *ofsAddr;
1438 unsigned int inited = p->asyncflags & ASYNC_INITIALIZED; 1433 unsigned int inited = p->port.flags & ASYNC_INITIALIZED;
1439 u16 intr; 1434 u16 intr;
1440 1435
1441 if (tty) { 1436 if (tty) {
@@ -1566,9 +1561,9 @@ static void moxa_setup_empty_event(struct tty_struct *tty)
1566 1561
1567static void moxa_shut_down(struct moxa_port *ch) 1562static void moxa_shut_down(struct moxa_port *ch)
1568{ 1563{
1569 struct tty_struct *tp = ch->tty; 1564 struct tty_struct *tp = ch->port.tty;
1570 1565
1571 if (!(ch->asyncflags & ASYNC_INITIALIZED)) 1566 if (!(ch->port.flags & ASYNC_INITIALIZED))
1572 return; 1567 return;
1573 1568
1574 MoxaPortDisable(ch); 1569 MoxaPortDisable(ch);
@@ -1580,7 +1575,7 @@ static void moxa_shut_down(struct moxa_port *ch)
1580 MoxaPortLineCtrl(ch, 0, 0); 1575 MoxaPortLineCtrl(ch, 0, 0);
1581 1576
1582 spin_lock_bh(&moxa_lock); 1577 spin_lock_bh(&moxa_lock);
1583 ch->asyncflags &= ~ASYNC_INITIALIZED; 1578 ch->port.flags &= ~ASYNC_INITIALIZED;
1584 spin_unlock_bh(&moxa_lock); 1579 spin_unlock_bh(&moxa_lock);
1585} 1580}
1586 1581
@@ -1975,7 +1970,7 @@ static int MoxaPortWriteData(struct moxa_port *port,
1975 c = (head > tail) ? (head - tail - 1) : (head - tail + tx_mask); 1970 c = (head > tail) ? (head - tail - 1) : (head - tail + tx_mask);
1976 if (c > len) 1971 if (c > len)
1977 c = len; 1972 c = len;
1978 moxaLog.txcnt[port->tty->index] += c; 1973 moxaLog.txcnt[port->port.tty->index] += c;
1979 total = c; 1974 total = c;
1980 if (spage == epage) { 1975 if (spage == epage) {
1981 bufhead = readw(ofsAddr + Ofs_txb); 1976 bufhead = readw(ofsAddr + Ofs_txb);
@@ -2017,7 +2012,7 @@ static int MoxaPortWriteData(struct moxa_port *port,
2017 2012
2018static int MoxaPortReadData(struct moxa_port *port) 2013static int MoxaPortReadData(struct moxa_port *port)
2019{ 2014{
2020 struct tty_struct *tty = port->tty; 2015 struct tty_struct *tty = port->port.tty;
2021 unsigned char *dst; 2016 unsigned char *dst;
2022 void __iomem *baseAddr, *ofsAddr, *ofs; 2017 void __iomem *baseAddr, *ofsAddr, *ofs;
2023 unsigned int count, len, total; 2018 unsigned int count, len, total;
@@ -2124,10 +2119,10 @@ static int moxa_get_serial_info(struct moxa_port *info,
2124{ 2119{
2125 struct serial_struct tmp = { 2120 struct serial_struct tmp = {
2126 .type = info->type, 2121 .type = info->type,
2127 .line = info->tty->index, 2122 .line = info->port.tty->index,
2128 .flags = info->asyncflags, 2123 .flags = info->port.flags,
2129 .baud_base = 921600, 2124 .baud_base = 921600,
2130 .close_delay = info->close_delay 2125 .close_delay = info->port.close_delay
2131 }; 2126 };
2132 return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0; 2127 return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
2133} 2128}
@@ -2148,13 +2143,13 @@ static int moxa_set_serial_info(struct moxa_port *info,
2148 2143
2149 if (!capable(CAP_SYS_ADMIN)) { 2144 if (!capable(CAP_SYS_ADMIN)) {
2150 if (((new_serial.flags & ~ASYNC_USR_MASK) != 2145 if (((new_serial.flags & ~ASYNC_USR_MASK) !=
2151 (info->asyncflags & ~ASYNC_USR_MASK))) 2146 (info->port.flags & ~ASYNC_USR_MASK)))
2152 return -EPERM; 2147 return -EPERM;
2153 } else 2148 } else
2154 info->close_delay = new_serial.close_delay * HZ / 100; 2149 info->port.close_delay = new_serial.close_delay * HZ / 100;
2155 2150
2156 new_serial.flags = (new_serial.flags & ~ASYNC_FLAGS); 2151 new_serial.flags = (new_serial.flags & ~ASYNC_FLAGS);
2157 new_serial.flags |= (info->asyncflags & ASYNC_FLAGS); 2152 new_serial.flags |= (info->port.flags & ASYNC_FLAGS);
2158 2153
2159 MoxaSetFifo(info, new_serial.type == PORT_16550A); 2154 MoxaSetFifo(info, new_serial.type == PORT_16550A);
2160 2155