aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Slaby <jslaby@suse.cz>2012-08-07 15:47:55 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-08-13 19:50:20 -0400
commit793be8984fb979ae8887609862842cbb1f60bfaf (patch)
tree8e1df3802d07fad16b0e5928e003667a9f956146
parentcc93441eed0d39af9d99ba1642b9f733b195435c (diff)
TTY: moxa, convert to dynamic device
This allows us to provide the tty layer with information about tty_port for each link. We also provide a tty_port for the service port. For this one we allow only ioctl, so this is pretty ugly. Signed-off-by: Jiri Slaby <jslaby@suse.cz> Acked-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/tty/moxa.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
index 89cc9344325b..9dffc724d46f 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");
@@ -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);
@@ -1031,7 +1041,12 @@ static int __init moxa_init(void)
1031 1041
1032 printk(KERN_INFO "MOXA Intellio family driver version %s\n", 1042 printk(KERN_INFO "MOXA Intellio family driver version %s\n",
1033 MOXA_VERSION); 1043 MOXA_VERSION);
1034 moxaDriver = alloc_tty_driver(MAX_PORTS + 1); 1044
1045 tty_port_init(&moxa_service_port);
1046
1047 moxaDriver = tty_alloc_driver(MAX_PORTS + 1,
1048 TTY_DRIVER_REAL_RAW |
1049 TTY_DRIVER_DYNAMIC_DEV);
1035 if (!moxaDriver) 1050 if (!moxaDriver)
1036 return -ENOMEM; 1051 return -ENOMEM;
1037 1052
@@ -1044,8 +1059,9 @@ static int __init moxa_init(void)
1044 moxaDriver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; 1059 moxaDriver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1045 moxaDriver->init_termios.c_ispeed = 9600; 1060 moxaDriver->init_termios.c_ispeed = 9600;
1046 moxaDriver->init_termios.c_ospeed = 9600; 1061 moxaDriver->init_termios.c_ospeed = 9600;
1047 moxaDriver->flags = TTY_DRIVER_REAL_RAW;
1048 tty_set_operations(moxaDriver, &moxa_ops); 1062 tty_set_operations(moxaDriver, &moxa_ops);
1063 /* Having one more port only for ioctls is ugly */
1064 tty_port_link_device(&moxa_service_port, moxaDriver, MAX_PORTS);
1049 1065
1050 if (tty_register_driver(moxaDriver)) { 1066 if (tty_register_driver(moxaDriver)) {
1051 printk(KERN_ERR "can't register MOXA Smartio tty driver!\n"); 1067 printk(KERN_ERR "can't register MOXA Smartio tty driver!\n");