[PATCH] Char: timers cleanup
[powerpc.git] / drivers / char / specialix.c
index d0b88d0..baf7234 100644 (file)
@@ -183,11 +183,6 @@ static int sx_poll = HZ;
 
 static struct tty_driver *specialix_driver;
 
-static unsigned long baud_table[] =  {
-       0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
-       9600, 19200, 38400, 57600, 115200, 0,
-};
-
 static struct specialix_board sx_board[SX_NBOARD] =  {
        { 0, SX_IOBASE1,  9, },
        { 0, SX_IOBASE2, 11, },
@@ -464,10 +459,9 @@ void missed_irq (unsigned long data)
        if (irq) {
                printk (KERN_INFO "Missed interrupt... Calling int from timer. \n");
                sx_interrupt (((struct specialix_board *)data)->irq,
-                             (void*)data, NULL);
+                               (void*)data);
        }
-       missed_irq_timer.expires = jiffies + sx_poll;
-       add_timer (&missed_irq_timer);
+       mod_timer(&missed_irq_timer, jiffies + sx_poll);
 }
 #endif
 
@@ -602,11 +596,8 @@ static int sx_probe(struct specialix_board *bp)
        dprintk (SX_DEBUG_INIT, " GFCR = 0x%02x\n", sx_in_off(bp, CD186x_GFRCR) );
 
 #ifdef SPECIALIX_TIMER
-       init_timer (&missed_irq_timer);
-       missed_irq_timer.function = missed_irq;
-       missed_irq_timer.data = (unsigned long) bp;
-       missed_irq_timer.expires = jiffies + sx_poll;
-       add_timer (&missed_irq_timer);
+       setup_timer(&missed_irq_timer, missed_irq, (unsigned long)bp);
+       mod_timer(&missed_irq_timer, jiffies + sx_poll);
 #endif
 
        printk(KERN_INFO"sx%d: specialix IO8+ board detected at 0x%03x, IRQ %d, CD%d Rev. %c.\n",
@@ -1090,9 +1081,9 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
 
        if (baud == 38400) {
                if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
-                       baud ++;
+                       baud = 57600;
                if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
-                       baud += 2;
+                       baud = 115200;
        }
 
        if (!baud) {
@@ -1150,11 +1141,9 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
        sx_out(bp, CD186x_RBPRL, tmp & 0xff);
        sx_out(bp, CD186x_TBPRL, tmp & 0xff);
        spin_unlock_irqrestore(&bp->lock, flags);
-       if (port->custom_divisor) {
+       if (port->custom_divisor)
                baud = (SX_OSCFREQ + port->custom_divisor/2) / port->custom_divisor;
-               baud = ( baud + 5 ) / 10;
-       } else
-               baud = (baud_table[baud] + 5) / 10;   /* Estimated CPS */
+       baud = (baud + 5) / 10;         /* Estimated CPS */
 
        /* Two timer ticks seems enough to wakeup something like SLIP driver */
        tmp = ((baud + HZ/2) / HZ) * 2 - CD186x_NFIFO;
@@ -2268,9 +2257,10 @@ static void sx_start(struct tty_struct * tty)
  *     do_sx_hangup() -> tty->hangup() -> sx_hangup()
  *
  */
-static void do_sx_hangup(void *private_)
+static void do_sx_hangup(struct work_struct *work)
 {
-       struct specialix_port   *port = (struct specialix_port *) private_;
+       struct specialix_port   *port =
+               container_of(work, struct specialix_port, tqueue_hangup);
        struct tty_struct       *tty;
 
        func_enter();
@@ -2317,7 +2307,7 @@ static void sx_hangup(struct tty_struct * tty)
 }
 
 
-static void sx_set_termios(struct tty_struct * tty, struct termios * old_termios)
+static void sx_set_termios(struct tty_struct * tty, struct ktermios * old_termios)
 {
        struct specialix_port *port = (struct specialix_port *)tty->driver_data;
        unsigned long flags;
@@ -2343,9 +2333,10 @@ static void sx_set_termios(struct tty_struct * tty, struct termios * old_termios
 }
 
 
-static void do_softint(void *private_)
+static void do_softint(struct work_struct *work)
 {
-       struct specialix_port   *port = (struct specialix_port *) private_;
+       struct specialix_port   *port =
+               container_of(work, struct specialix_port, tqueue);
        struct tty_struct       *tty;
 
        func_enter();
@@ -2355,10 +2346,8 @@ static void do_softint(void *private_)
                return;
        }
 
-       if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &port->event)) {
+       if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &port->event))
                tty_wakeup(tty);
-               //wake_up_interruptible(&tty->write_wait);
-       }
 
        func_exit();
 }
@@ -2405,6 +2394,8 @@ static int sx_init_drivers(void)
        specialix_driver->init_termios = tty_std_termios;
        specialix_driver->init_termios.c_cflag =
                B9600 | CS8 | CREAD | HUPCL | CLOCAL;
+       specialix_driver->init_termios.c_ispeed = 9600;
+       specialix_driver->init_termios.c_ospeed = 9600;
        specialix_driver->flags = TTY_DRIVER_REAL_RAW;
        tty_set_operations(specialix_driver, &sx_ops);
 
@@ -2418,8 +2409,8 @@ static int sx_init_drivers(void)
        memset(sx_port, 0, sizeof(sx_port));
        for (i = 0; i < SX_NPORT * SX_NBOARD; i++) {
                sx_port[i].magic = SPECIALIX_MAGIC;
-               INIT_WORK(&sx_port[i].tqueue, do_softint, &sx_port[i]);
-               INIT_WORK(&sx_port[i].tqueue_hangup, do_sx_hangup, &sx_port[i]);
+               INIT_WORK(&sx_port[i].tqueue, do_softint);
+               INIT_WORK(&sx_port[i].tqueue_hangup, do_sx_hangup);
                sx_port[i].close_delay = 50 * HZ/100;
                sx_port[i].closing_wait = 3000 * HZ/100;
                init_waitqueue_head(&sx_port[i].open_wait);
@@ -2480,7 +2471,7 @@ static int __init specialix_init(void)
                                i++;
                                continue;
                        }
-                       pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX,
+                       pdev = pci_get_device (PCI_VENDOR_ID_SPECIALIX,
                                                PCI_DEVICE_ID_SPECIALIX_IO8,
                                                pdev);
                        if (!pdev) break;
@@ -2496,6 +2487,9 @@ static int __init specialix_init(void)
                        if (!sx_probe(&sx_board[i]))
                                found ++;
                }
+               /* May exit pci_get sequence early with lots of boards */
+               if (pdev != NULL)
+                       pci_dev_put(pdev);
        }
 #endif
 
@@ -2561,7 +2555,7 @@ static void __exit specialix_exit_module(void)
                if (sx_board[i].flags & SX_BOARD_PRESENT)
                        sx_release_io_range(&sx_board[i]);
 #ifdef SPECIALIX_TIMER
-       del_timer (&missed_irq_timer);
+       del_timer_sync(&missed_irq_timer);
 #endif
 
        func_exit();