diff options
author | Alan Cox <alan@redhat.com> | 2008-07-16 16:56:02 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-07-20 20:12:37 -0400 |
commit | 9de6a51fee08f9e7020074738150441305e83af2 (patch) | |
tree | 1a27d854d60f439982a6f1d8c779753ad54e4cf5 /drivers/char/moxa.c | |
parent | b02f5ad6a3ff5a1ee2a7b8ec6eee338de553b060 (diff) |
moxa: use tty_port
Switch MOXA to use the new tty_port structure
Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/char/moxa.c')
-rw-r--r-- | drivers/char/moxa.c | 87 |
1 files changed, 42 insertions, 45 deletions
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c index e21346da3101..dd10f143d96f 100644 --- a/drivers/char/moxa.c +++ b/drivers/char/moxa.c | |||
@@ -130,17 +130,14 @@ struct moxaq_str { | |||
130 | }; | 130 | }; |
131 | 131 | ||
132 | struct moxa_port { | 132 | struct 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; | 138 | int close_delay; |
139 | unsigned int count; | ||
140 | int asyncflags; | ||
141 | int cflag; | 139 | int cflag; |
142 | unsigned long statusflags; | 140 | unsigned long statusflags; |
143 | wait_queue_head_t open_wait; | ||
144 | 141 | ||
145 | u8 DCDState; | 142 | u8 DCDState; |
146 | u8 lineCtrl; | 143 | u8 lineCtrl; |
@@ -348,10 +345,10 @@ static int moxa_ioctl(struct tty_struct *tty, struct file *file, | |||
348 | if (status & 4) | 345 | if (status & 4) |
349 | tmp.dcd = 1; | 346 | tmp.dcd = 1; |
350 | 347 | ||
351 | if (!p->tty || !p->tty->termios) | 348 | if (!p->port.tty || !p->port.tty->termios) |
352 | tmp.cflag = p->cflag; | 349 | tmp.cflag = p->cflag; |
353 | else | 350 | else |
354 | tmp.cflag = p->tty->termios->c_cflag; | 351 | tmp.cflag = p->port.tty->termios->c_cflag; |
355 | copy: | 352 | copy: |
356 | if (copy_to_user(argm, &tmp, sizeof(tmp))) { | 353 | if (copy_to_user(argm, &tmp, sizeof(tmp))) { |
357 | mutex_unlock(&moxa_openlock); | 354 | mutex_unlock(&moxa_openlock); |
@@ -828,7 +825,7 @@ static int moxa_init_board(struct moxa_board_conf *brd, struct device *dev) | |||
828 | p->type = PORT_16550A; | 825 | p->type = PORT_16550A; |
829 | p->close_delay = 5 * HZ / 10; | 826 | p->close_delay = 5 * HZ / 10; |
830 | p->cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; | 827 | p->cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; |
831 | init_waitqueue_head(&p->open_wait); | 828 | tty_port_init(&p->port); |
832 | } | 829 | } |
833 | 830 | ||
834 | switch (brd->boardType) { | 831 | switch (brd->boardType) { |
@@ -884,12 +881,12 @@ static void moxa_board_deinit(struct moxa_board_conf *brd) | |||
884 | 881 | ||
885 | /* pci hot-un-plug support */ | 882 | /* pci hot-un-plug support */ |
886 | for (a = 0; a < brd->numPorts; a++) | 883 | for (a = 0; a < brd->numPorts; a++) |
887 | if (brd->ports[a].asyncflags & ASYNC_INITIALIZED) | 884 | if (brd->ports[a].port.flags & ASYNC_INITIALIZED) |
888 | tty_hangup(brd->ports[a].tty); | 885 | tty_hangup(brd->ports[a].port.tty); |
889 | while (1) { | 886 | while (1) { |
890 | opened = 0; | 887 | opened = 0; |
891 | for (a = 0; a < brd->numPorts; a++) | 888 | for (a = 0; a < brd->numPorts; a++) |
892 | if (brd->ports[a].asyncflags & ASYNC_INITIALIZED) | 889 | if (brd->ports[a].port.flags & ASYNC_INITIALIZED) |
893 | opened++; | 890 | opened++; |
894 | mutex_unlock(&moxa_openlock); | 891 | mutex_unlock(&moxa_openlock); |
895 | if (!opened) | 892 | if (!opened) |
@@ -1104,9 +1101,9 @@ static void moxa_close_port(struct moxa_port *ch) | |||
1104 | { | 1101 | { |
1105 | moxa_shut_down(ch); | 1102 | moxa_shut_down(ch); |
1106 | MoxaPortFlushData(ch, 2); | 1103 | MoxaPortFlushData(ch, 2); |
1107 | ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE; | 1104 | ch->port.flags &= ~ASYNC_NORMAL_ACTIVE; |
1108 | ch->tty->driver_data = NULL; | 1105 | ch->port.tty->driver_data = NULL; |
1109 | ch->tty = NULL; | 1106 | ch->port.tty = NULL; |
1110 | } | 1107 | } |
1111 | 1108 | ||
1112 | static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp, | 1109 | static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp, |
@@ -1117,7 +1114,7 @@ static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp, | |||
1117 | u8 dcd; | 1114 | u8 dcd; |
1118 | 1115 | ||
1119 | while (1) { | 1116 | while (1) { |
1120 | prepare_to_wait(&ch->open_wait, &wait, TASK_INTERRUPTIBLE); | 1117 | prepare_to_wait(&ch->port.open_wait, &wait, TASK_INTERRUPTIBLE); |
1121 | if (tty_hung_up_p(filp)) { | 1118 | if (tty_hung_up_p(filp)) { |
1122 | #ifdef SERIAL_DO_RESTART | 1119 | #ifdef SERIAL_DO_RESTART |
1123 | retval = -ERESTARTSYS; | 1120 | retval = -ERESTARTSYS; |
@@ -1138,7 +1135,7 @@ static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp, | |||
1138 | } | 1135 | } |
1139 | schedule(); | 1136 | schedule(); |
1140 | } | 1137 | } |
1141 | finish_wait(&ch->open_wait, &wait); | 1138 | finish_wait(&ch->port.open_wait, &wait); |
1142 | 1139 | ||
1143 | return retval; | 1140 | return retval; |
1144 | } | 1141 | } |
@@ -1163,16 +1160,16 @@ static int moxa_open(struct tty_struct *tty, struct file *filp) | |||
1163 | } | 1160 | } |
1164 | 1161 | ||
1165 | ch = &brd->ports[port % MAX_PORTS_PER_BOARD]; | 1162 | ch = &brd->ports[port % MAX_PORTS_PER_BOARD]; |
1166 | ch->count++; | 1163 | ch->port.count++; |
1167 | tty->driver_data = ch; | 1164 | tty->driver_data = ch; |
1168 | ch->tty = tty; | 1165 | ch->port.tty = tty; |
1169 | if (!(ch->asyncflags & ASYNC_INITIALIZED)) { | 1166 | if (!(ch->port.flags & ASYNC_INITIALIZED)) { |
1170 | ch->statusflags = 0; | 1167 | ch->statusflags = 0; |
1171 | moxa_set_tty_param(tty, tty->termios); | 1168 | moxa_set_tty_param(tty, tty->termios); |
1172 | MoxaPortLineCtrl(ch, 1, 1); | 1169 | MoxaPortLineCtrl(ch, 1, 1); |
1173 | MoxaPortEnable(ch); | 1170 | MoxaPortEnable(ch); |
1174 | MoxaSetFifo(ch, ch->type == PORT_16550A); | 1171 | MoxaSetFifo(ch, ch->type == PORT_16550A); |
1175 | ch->asyncflags |= ASYNC_INITIALIZED; | 1172 | ch->port.flags |= ASYNC_INITIALIZED; |
1176 | } | 1173 | } |
1177 | mutex_unlock(&moxa_openlock); | 1174 | mutex_unlock(&moxa_openlock); |
1178 | 1175 | ||
@@ -1181,11 +1178,11 @@ static int moxa_open(struct tty_struct *tty, struct file *filp) | |||
1181 | retval = moxa_block_till_ready(tty, filp, ch); | 1178 | retval = moxa_block_till_ready(tty, filp, ch); |
1182 | mutex_lock(&moxa_openlock); | 1179 | mutex_lock(&moxa_openlock); |
1183 | if (retval) { | 1180 | if (retval) { |
1184 | if (ch->count) /* 0 means already hung up... */ | 1181 | if (ch->port.count) /* 0 means already hung up... */ |
1185 | if (--ch->count == 0) | 1182 | if (--ch->port.count == 0) |
1186 | moxa_close_port(ch); | 1183 | moxa_close_port(ch); |
1187 | } else | 1184 | } else |
1188 | ch->asyncflags |= ASYNC_NORMAL_ACTIVE; | 1185 | ch->port.flags |= ASYNC_NORMAL_ACTIVE; |
1189 | mutex_unlock(&moxa_openlock); | 1186 | mutex_unlock(&moxa_openlock); |
1190 | 1187 | ||
1191 | return retval; | 1188 | return retval; |
@@ -1204,21 +1201,21 @@ static void moxa_close(struct tty_struct *tty, struct file *filp) | |||
1204 | ch = tty->driver_data; | 1201 | ch = tty->driver_data; |
1205 | if (ch == NULL) | 1202 | if (ch == NULL) |
1206 | goto unlock; | 1203 | goto unlock; |
1207 | if (tty->count == 1 && ch->count != 1) { | 1204 | if (tty->count == 1 && ch->port.count != 1) { |
1208 | printk(KERN_WARNING "moxa_close: bad serial port count; " | 1205 | printk(KERN_WARNING "moxa_close: bad serial port count; " |
1209 | "tty->count is 1, ch->count is %d\n", ch->count); | 1206 | "tty->count is 1, ch->port.count is %d\n", ch->port.count); |
1210 | ch->count = 1; | 1207 | ch->port.count = 1; |
1211 | } | 1208 | } |
1212 | if (--ch->count < 0) { | 1209 | if (--ch->port.count < 0) { |
1213 | printk(KERN_WARNING "moxa_close: bad serial port count, " | 1210 | printk(KERN_WARNING "moxa_close: bad serial port count, " |
1214 | "device=%s\n", tty->name); | 1211 | "device=%s\n", tty->name); |
1215 | ch->count = 0; | 1212 | ch->port.count = 0; |
1216 | } | 1213 | } |
1217 | if (ch->count) | 1214 | if (ch->port.count) |
1218 | goto unlock; | 1215 | goto unlock; |
1219 | 1216 | ||
1220 | ch->cflag = tty->termios->c_cflag; | 1217 | ch->cflag = tty->termios->c_cflag; |
1221 | if (ch->asyncflags & ASYNC_INITIALIZED) { | 1218 | if (ch->port.flags & ASYNC_INITIALIZED) { |
1222 | moxa_setup_empty_event(tty); | 1219 | moxa_setup_empty_event(tty); |
1223 | tty_wait_until_sent(tty, 30 * HZ); /* 30 seconds timeout */ | 1220 | tty_wait_until_sent(tty, 30 * HZ); /* 30 seconds timeout */ |
1224 | } | 1221 | } |
@@ -1374,7 +1371,7 @@ static void moxa_set_termios(struct tty_struct *tty, | |||
1374 | return; | 1371 | return; |
1375 | moxa_set_tty_param(tty, old_termios); | 1372 | moxa_set_tty_param(tty, old_termios); |
1376 | if (!(old_termios->c_cflag & CLOCAL) && C_CLOCAL(tty)) | 1373 | if (!(old_termios->c_cflag & CLOCAL) && C_CLOCAL(tty)) |
1377 | wake_up_interruptible(&ch->open_wait); | 1374 | wake_up_interruptible(&ch->port.open_wait); |
1378 | } | 1375 | } |
1379 | 1376 | ||
1380 | static void moxa_stop(struct tty_struct *tty) | 1377 | static void moxa_stop(struct tty_struct *tty) |
@@ -1412,20 +1409,20 @@ static void moxa_hangup(struct tty_struct *tty) | |||
1412 | mutex_unlock(&moxa_openlock); | 1409 | mutex_unlock(&moxa_openlock); |
1413 | return; | 1410 | return; |
1414 | } | 1411 | } |
1415 | ch->count = 0; | 1412 | ch->port.count = 0; |
1416 | moxa_close_port(ch); | 1413 | moxa_close_port(ch); |
1417 | mutex_unlock(&moxa_openlock); | 1414 | mutex_unlock(&moxa_openlock); |
1418 | 1415 | ||
1419 | wake_up_interruptible(&ch->open_wait); | 1416 | wake_up_interruptible(&ch->port.open_wait); |
1420 | } | 1417 | } |
1421 | 1418 | ||
1422 | static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd) | 1419 | static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd) |
1423 | { | 1420 | { |
1424 | dcd = !!dcd; | 1421 | dcd = !!dcd; |
1425 | 1422 | ||
1426 | if (dcd != p->DCDState && p->tty && C_CLOCAL(p->tty)) { | 1423 | if (dcd != p->DCDState && p->port.tty && C_CLOCAL(p->port.tty)) { |
1427 | if (!dcd) | 1424 | if (!dcd) |
1428 | tty_hangup(p->tty); | 1425 | tty_hangup(p->port.tty); |
1429 | } | 1426 | } |
1430 | p->DCDState = dcd; | 1427 | p->DCDState = dcd; |
1431 | } | 1428 | } |
@@ -1433,9 +1430,9 @@ static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd) | |||
1433 | static int moxa_poll_port(struct moxa_port *p, unsigned int handle, | 1430 | static int moxa_poll_port(struct moxa_port *p, unsigned int handle, |
1434 | u16 __iomem *ip) | 1431 | u16 __iomem *ip) |
1435 | { | 1432 | { |
1436 | struct tty_struct *tty = p->tty; | 1433 | struct tty_struct *tty = p->port.tty; |
1437 | void __iomem *ofsAddr; | 1434 | void __iomem *ofsAddr; |
1438 | unsigned int inited = p->asyncflags & ASYNC_INITIALIZED; | 1435 | unsigned int inited = p->port.flags & ASYNC_INITIALIZED; |
1439 | u16 intr; | 1436 | u16 intr; |
1440 | 1437 | ||
1441 | if (tty) { | 1438 | if (tty) { |
@@ -1566,9 +1563,9 @@ static void moxa_setup_empty_event(struct tty_struct *tty) | |||
1566 | 1563 | ||
1567 | static void moxa_shut_down(struct moxa_port *ch) | 1564 | static void moxa_shut_down(struct moxa_port *ch) |
1568 | { | 1565 | { |
1569 | struct tty_struct *tp = ch->tty; | 1566 | struct tty_struct *tp = ch->port.tty; |
1570 | 1567 | ||
1571 | if (!(ch->asyncflags & ASYNC_INITIALIZED)) | 1568 | if (!(ch->port.flags & ASYNC_INITIALIZED)) |
1572 | return; | 1569 | return; |
1573 | 1570 | ||
1574 | MoxaPortDisable(ch); | 1571 | MoxaPortDisable(ch); |
@@ -1580,7 +1577,7 @@ static void moxa_shut_down(struct moxa_port *ch) | |||
1580 | MoxaPortLineCtrl(ch, 0, 0); | 1577 | MoxaPortLineCtrl(ch, 0, 0); |
1581 | 1578 | ||
1582 | spin_lock_bh(&moxa_lock); | 1579 | spin_lock_bh(&moxa_lock); |
1583 | ch->asyncflags &= ~ASYNC_INITIALIZED; | 1580 | ch->port.flags &= ~ASYNC_INITIALIZED; |
1584 | spin_unlock_bh(&moxa_lock); | 1581 | spin_unlock_bh(&moxa_lock); |
1585 | } | 1582 | } |
1586 | 1583 | ||
@@ -1975,7 +1972,7 @@ static int MoxaPortWriteData(struct moxa_port *port, | |||
1975 | c = (head > tail) ? (head - tail - 1) : (head - tail + tx_mask); | 1972 | c = (head > tail) ? (head - tail - 1) : (head - tail + tx_mask); |
1976 | if (c > len) | 1973 | if (c > len) |
1977 | c = len; | 1974 | c = len; |
1978 | moxaLog.txcnt[port->tty->index] += c; | 1975 | moxaLog.txcnt[port->port.tty->index] += c; |
1979 | total = c; | 1976 | total = c; |
1980 | if (spage == epage) { | 1977 | if (spage == epage) { |
1981 | bufhead = readw(ofsAddr + Ofs_txb); | 1978 | bufhead = readw(ofsAddr + Ofs_txb); |
@@ -2017,7 +2014,7 @@ static int MoxaPortWriteData(struct moxa_port *port, | |||
2017 | 2014 | ||
2018 | static int MoxaPortReadData(struct moxa_port *port) | 2015 | static int MoxaPortReadData(struct moxa_port *port) |
2019 | { | 2016 | { |
2020 | struct tty_struct *tty = port->tty; | 2017 | struct tty_struct *tty = port->port.tty; |
2021 | unsigned char *dst; | 2018 | unsigned char *dst; |
2022 | void __iomem *baseAddr, *ofsAddr, *ofs; | 2019 | void __iomem *baseAddr, *ofsAddr, *ofs; |
2023 | unsigned int count, len, total; | 2020 | unsigned int count, len, total; |
@@ -2124,8 +2121,8 @@ static int moxa_get_serial_info(struct moxa_port *info, | |||
2124 | { | 2121 | { |
2125 | struct serial_struct tmp = { | 2122 | struct serial_struct tmp = { |
2126 | .type = info->type, | 2123 | .type = info->type, |
2127 | .line = info->tty->index, | 2124 | .line = info->port.tty->index, |
2128 | .flags = info->asyncflags, | 2125 | .flags = info->port.flags, |
2129 | .baud_base = 921600, | 2126 | .baud_base = 921600, |
2130 | .close_delay = info->close_delay | 2127 | .close_delay = info->close_delay |
2131 | }; | 2128 | }; |
@@ -2148,13 +2145,13 @@ static int moxa_set_serial_info(struct moxa_port *info, | |||
2148 | 2145 | ||
2149 | if (!capable(CAP_SYS_ADMIN)) { | 2146 | if (!capable(CAP_SYS_ADMIN)) { |
2150 | if (((new_serial.flags & ~ASYNC_USR_MASK) != | 2147 | if (((new_serial.flags & ~ASYNC_USR_MASK) != |
2151 | (info->asyncflags & ~ASYNC_USR_MASK))) | 2148 | (info->port.flags & ~ASYNC_USR_MASK))) |
2152 | return -EPERM; | 2149 | return -EPERM; |
2153 | } else | 2150 | } else |
2154 | info->close_delay = new_serial.close_delay * HZ / 100; | 2151 | info->close_delay = new_serial.close_delay * HZ / 100; |
2155 | 2152 | ||
2156 | new_serial.flags = (new_serial.flags & ~ASYNC_FLAGS); | 2153 | new_serial.flags = (new_serial.flags & ~ASYNC_FLAGS); |
2157 | new_serial.flags |= (info->asyncflags & ASYNC_FLAGS); | 2154 | new_serial.flags |= (info->port.flags & ASYNC_FLAGS); |
2158 | 2155 | ||
2159 | MoxaSetFifo(info, new_serial.type == PORT_16550A); | 2156 | MoxaSetFifo(info, new_serial.type == PORT_16550A); |
2160 | 2157 | ||