aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty/moxa.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/tty/moxa.c')
-rw-r--r--drivers/tty/moxa.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
index 324467d28a54..56e616b9109a 100644
--- a/drivers/tty/moxa.c
+++ b/drivers/tty/moxa.c
@@ -169,6 +169,7 @@ static DEFINE_SPINLOCK(moxa_lock);
169static unsigned long baseaddr[MAX_BOARDS]; 169static unsigned long baseaddr[MAX_BOARDS];
170static unsigned int type[MAX_BOARDS]; 170static unsigned int type[MAX_BOARDS];
171static unsigned int numports[MAX_BOARDS]; 171static unsigned int numports[MAX_BOARDS];
172static struct tty_port moxa_service_port;
172 173
173MODULE_AUTHOR("William Chen"); 174MODULE_AUTHOR("William Chen");
174MODULE_DESCRIPTION("MOXA Intellio Family Multiport Board Device Driver"); 175MODULE_DESCRIPTION("MOXA Intellio Family Multiport Board Device Driver");
@@ -367,10 +368,10 @@ static int moxa_ioctl(struct tty_struct *tty,
367 tmp.dcd = 1; 368 tmp.dcd = 1;
368 369
369 ttyp = tty_port_tty_get(&p->port); 370 ttyp = tty_port_tty_get(&p->port);
370 if (!ttyp || !ttyp->termios) 371 if (!ttyp)
371 tmp.cflag = p->cflag; 372 tmp.cflag = p->cflag;
372 else 373 else
373 tmp.cflag = ttyp->termios->c_cflag; 374 tmp.cflag = ttyp->termios.c_cflag;
374 tty_kref_put(ttyp); 375 tty_kref_put(ttyp);
375copy: 376copy:
376 if (copy_to_user(argm, &tmp, sizeof(tmp))) 377 if (copy_to_user(argm, &tmp, sizeof(tmp)))
@@ -834,7 +835,7 @@ static int moxa_init_board(struct moxa_board_conf *brd, struct device *dev)
834 const struct firmware *fw; 835 const struct firmware *fw;
835 const char *file; 836 const char *file;
836 struct moxa_port *p; 837 struct moxa_port *p;
837 unsigned int i; 838 unsigned int i, first_idx;
838 int ret; 839 int ret;
839 840
840 brd->ports = kcalloc(MAX_PORTS_PER_BOARD, sizeof(*brd->ports), 841 brd->ports = kcalloc(MAX_PORTS_PER_BOARD, sizeof(*brd->ports),
@@ -887,6 +888,11 @@ static int moxa_init_board(struct moxa_board_conf *brd, struct device *dev)
887 mod_timer(&moxaTimer, jiffies + HZ / 50); 888 mod_timer(&moxaTimer, jiffies + HZ / 50);
888 spin_unlock_bh(&moxa_lock); 889 spin_unlock_bh(&moxa_lock);
889 890
891 first_idx = (brd - moxa_boards) * MAX_PORTS_PER_BOARD;
892 for (i = 0; i < brd->numPorts; i++)
893 tty_port_register_device(&brd->ports[i].port, moxaDriver,
894 first_idx + i, dev);
895
890 return 0; 896 return 0;
891err_free: 897err_free:
892 kfree(brd->ports); 898 kfree(brd->ports);
@@ -896,7 +902,7 @@ err:
896 902
897static void moxa_board_deinit(struct moxa_board_conf *brd) 903static void moxa_board_deinit(struct moxa_board_conf *brd)
898{ 904{
899 unsigned int a, opened; 905 unsigned int a, opened, first_idx;
900 906
901 mutex_lock(&moxa_openlock); 907 mutex_lock(&moxa_openlock);
902 spin_lock_bh(&moxa_lock); 908 spin_lock_bh(&moxa_lock);
@@ -925,6 +931,10 @@ static void moxa_board_deinit(struct moxa_board_conf *brd)
925 mutex_lock(&moxa_openlock); 931 mutex_lock(&moxa_openlock);
926 } 932 }
927 933
934 first_idx = (brd - moxa_boards) * MAX_PORTS_PER_BOARD;
935 for (a = 0; a < brd->numPorts; a++)
936 tty_unregister_device(moxaDriver, first_idx + a);
937
928 iounmap(brd->basemem); 938 iounmap(brd->basemem);
929 brd->basemem = NULL; 939 brd->basemem = NULL;
930 kfree(brd->ports); 940 kfree(brd->ports);
@@ -967,6 +977,7 @@ static int __devinit moxa_pci_probe(struct pci_dev *pdev,
967 board->basemem = ioremap_nocache(pci_resource_start(pdev, 2), 0x4000); 977 board->basemem = ioremap_nocache(pci_resource_start(pdev, 2), 0x4000);
968 if (board->basemem == NULL) { 978 if (board->basemem == NULL) {
969 dev_err(&pdev->dev, "can't remap io space 2\n"); 979 dev_err(&pdev->dev, "can't remap io space 2\n");
980 retval = -ENOMEM;
970 goto err_reg; 981 goto err_reg;
971 } 982 }
972 983
@@ -1031,9 +1042,14 @@ static int __init moxa_init(void)
1031 1042
1032 printk(KERN_INFO "MOXA Intellio family driver version %s\n", 1043 printk(KERN_INFO "MOXA Intellio family driver version %s\n",
1033 MOXA_VERSION); 1044 MOXA_VERSION);
1034 moxaDriver = alloc_tty_driver(MAX_PORTS + 1); 1045
1035 if (!moxaDriver) 1046 tty_port_init(&moxa_service_port);
1036 return -ENOMEM; 1047
1048 moxaDriver = tty_alloc_driver(MAX_PORTS + 1,
1049 TTY_DRIVER_REAL_RAW |
1050 TTY_DRIVER_DYNAMIC_DEV);
1051 if (IS_ERR(moxaDriver))
1052 return PTR_ERR(moxaDriver);
1037 1053
1038 moxaDriver->name = "ttyMX"; 1054 moxaDriver->name = "ttyMX";
1039 moxaDriver->major = ttymajor; 1055 moxaDriver->major = ttymajor;
@@ -1044,8 +1060,9 @@ static int __init moxa_init(void)
1044 moxaDriver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; 1060 moxaDriver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1045 moxaDriver->init_termios.c_ispeed = 9600; 1061 moxaDriver->init_termios.c_ispeed = 9600;
1046 moxaDriver->init_termios.c_ospeed = 9600; 1062 moxaDriver->init_termios.c_ospeed = 9600;
1047 moxaDriver->flags = TTY_DRIVER_REAL_RAW;
1048 tty_set_operations(moxaDriver, &moxa_ops); 1063 tty_set_operations(moxaDriver, &moxa_ops);
1064 /* Having one more port only for ioctls is ugly */
1065 tty_port_link_device(&moxa_service_port, moxaDriver, MAX_PORTS);
1049 1066
1050 if (tty_register_driver(moxaDriver)) { 1067 if (tty_register_driver(moxaDriver)) {
1051 printk(KERN_ERR "can't register MOXA Smartio tty driver!\n"); 1068 printk(KERN_ERR "can't register MOXA Smartio tty driver!\n");
@@ -1178,7 +1195,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
1178 mutex_lock(&ch->port.mutex); 1195 mutex_lock(&ch->port.mutex);
1179 if (!(ch->port.flags & ASYNC_INITIALIZED)) { 1196 if (!(ch->port.flags & ASYNC_INITIALIZED)) {
1180 ch->statusflags = 0; 1197 ch->statusflags = 0;
1181 moxa_set_tty_param(tty, tty->termios); 1198 moxa_set_tty_param(tty, &tty->termios);
1182 MoxaPortLineCtrl(ch, 1, 1); 1199 MoxaPortLineCtrl(ch, 1, 1);
1183 MoxaPortEnable(ch); 1200 MoxaPortEnable(ch);
1184 MoxaSetFifo(ch, ch->type == PORT_16550A); 1201 MoxaSetFifo(ch, ch->type == PORT_16550A);
@@ -1193,7 +1210,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
1193static void moxa_close(struct tty_struct *tty, struct file *filp) 1210static void moxa_close(struct tty_struct *tty, struct file *filp)
1194{ 1211{
1195 struct moxa_port *ch = tty->driver_data; 1212 struct moxa_port *ch = tty->driver_data;
1196 ch->cflag = tty->termios->c_cflag; 1213 ch->cflag = tty->termios.c_cflag;
1197 tty_port_close(&ch->port, tty, filp); 1214 tty_port_close(&ch->port, tty, filp);
1198} 1215}
1199 1216
@@ -1464,7 +1481,7 @@ static void moxa_poll(unsigned long ignored)
1464 1481
1465static void moxa_set_tty_param(struct tty_struct *tty, struct ktermios *old_termios) 1482static void moxa_set_tty_param(struct tty_struct *tty, struct ktermios *old_termios)
1466{ 1483{
1467 register struct ktermios *ts = tty->termios; 1484 register struct ktermios *ts = &tty->termios;
1468 struct moxa_port *ch = tty->driver_data; 1485 struct moxa_port *ch = tty->driver_data;
1469 int rts, cts, txflow, rxflow, xany, baud; 1486 int rts, cts, txflow, rxflow, xany, baud;
1470 1487