jsm: correctly support multiple 4/8-port boards
authorAlexander Y. Fomichev <git.user@gmail.com>
Thu, 11 Jun 2009 11:56:00 +0000 (12:56 +0100)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 11 Jun 2009 15:51:02 +0000 (08:51 -0700)
If there are more then one 4/8-port board jsm_uart_port_init
allocate a line numbers of the second and further boards
from range of previous one.

This patch fixed the problem.

Signed-off-by: Alexander Y. Fomichev <git.user@gmail.com>
[printks fixed to add jsm: ]

Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/serial/jsm/jsm.h
drivers/serial/jsm/jsm_tty.c

index c0a3e2734e240c02dd6e5a0b4da8a2f66800df86..4e5f3bde0461ca4c8eb4638bcc11643466c697ab 100644 (file)
@@ -61,6 +61,7 @@ enum {
        if ((DBG_##nlevel & jsm_debug))                 \
        dev_printk(KERN_##klevel, pdev->dev, fmt, ## args)
 
+#define        MAXLINES        256
 #define MAXPORTS       8
 #define MAX_STOPS_SENT 5
 
index 31496dc0a0d17d65206cb14ba280a6a5ffe29229..107ce2e187b8fc1c1773530a74b0779fdce283de 100644 (file)
@@ -33,6 +33,8 @@
 
 #include "jsm.h"
 
+static DECLARE_BITMAP(linemap, MAXLINES);
+
 static void jsm_carrier(struct jsm_channel *ch);
 
 static inline int jsm_get_mstat(struct jsm_channel *ch)
@@ -433,6 +435,7 @@ int __devinit jsm_tty_init(struct jsm_board *brd)
 int __devinit jsm_uart_port_init(struct jsm_board *brd)
 {
        int i;
+       unsigned int line;
        struct jsm_channel *ch;
 
        if (!brd)
@@ -459,9 +462,15 @@ int __devinit jsm_uart_port_init(struct jsm_board *brd)
                brd->channels[i]->uart_port.membase = brd->re_map_membase;
                brd->channels[i]->uart_port.fifosize = 16;
                brd->channels[i]->uart_port.ops = &jsm_ops;
-               brd->channels[i]->uart_port.line = brd->channels[i]->ch_portnum + brd->boardnum * 2;
+               line = find_first_zero_bit(linemap, MAXLINES);
+               if (line >= MAXLINES) {
+                       printk(KERN_INFO "jsm: linemap is full, added device failed\n");
+                       continue;
+               } else
+                       set_bit((int)line, linemap);
+               brd->channels[i]->uart_port.line = line;
                if (uart_add_one_port (&jsm_uart_driver, &brd->channels[i]->uart_port))
-                       printk(KERN_INFO "Added device failed\n");
+                       printk(KERN_INFO "jsm: add device failed\n");
                else
                        printk(KERN_INFO "Added device \n");
        }
@@ -494,6 +503,7 @@ int jsm_remove_uart_port(struct jsm_board *brd)
 
                ch = brd->channels[i];
 
+               clear_bit((int)(ch->uart_port.line), linemap);
                uart_remove_one_port(&jsm_uart_driver, &brd->channels[i]->uart_port);
        }