]> Pileus Git - ~andy/linux/blobdiff - drivers/char/amiserial.c
Merge branch 'for-linus' of git://neil.brown.name/md
[~andy/linux] / drivers / char / amiserial.c
index 56b27671adc46b23c80ca24425241048d0cae7ea..a11c8c9ca3d4b858029205f9a265b6ee96b04fdb 100644 (file)
@@ -84,6 +84,7 @@ static char *serial_version = "4.30";
 #include <linux/smp_lock.h>
 #include <linux/init.h>
 #include <linux/bitops.h>
+#include <linux/platform_device.h>
 
 #include <asm/setup.h>
 
@@ -1071,7 +1072,7 @@ static int get_serial_info(struct async_struct * info,
        if (!retinfo)
                return -EFAULT;
        memset(&tmp, 0, sizeof(tmp));
-       lock_kernel();
+       tty_lock();
        tmp.type = state->type;
        tmp.line = state->line;
        tmp.port = state->port;
@@ -1082,7 +1083,7 @@ static int get_serial_info(struct async_struct * info,
        tmp.close_delay = state->close_delay;
        tmp.closing_wait = state->closing_wait;
        tmp.custom_divisor = state->custom_divisor;
-       unlock_kernel();
+       tty_unlock();
        if (copy_to_user(retinfo,&tmp,sizeof(*retinfo)))
                return -EFAULT;
        return 0;
@@ -1099,14 +1100,14 @@ static int set_serial_info(struct async_struct * info,
        if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
                return -EFAULT;
 
-       lock_kernel();
+       tty_lock();
        state = info->state;
        old_state = *state;
   
        change_irq = new_serial.irq != state->irq;
        change_port = (new_serial.port != state->port);
        if(change_irq || change_port || (new_serial.xmit_fifo_size != state->xmit_fifo_size)) {
-         unlock_kernel();
+         tty_unlock();
          return -EINVAL;
        }
   
@@ -1126,7 +1127,7 @@ static int set_serial_info(struct async_struct * info,
        }
 
        if (new_serial.baud_base < 9600) {
-               unlock_kernel();
+               tty_unlock();
                return -EINVAL;
        }
 
@@ -1162,7 +1163,7 @@ check_and_exit:
                }
        } else
                retval = startup(info);
-       unlock_kernel();
+       tty_unlock();
        return retval;
 }
 
@@ -1527,6 +1528,7 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
 {
        struct async_struct * info = tty->driver_data;
        unsigned long orig_jiffies, char_time;
+       int tty_was_locked = tty_locked();
        int lsr;
 
        if (serial_paranoia_check(info, tty->name, "rs_wait_until_sent"))
@@ -1537,7 +1539,12 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
 
        orig_jiffies = jiffies;
 
-       lock_kernel();
+       /*
+        * tty_wait_until_sent is called from lots of places,
+        * with or without the BTM.
+        */
+       if (!tty_was_locked)
+               tty_lock();
        /*
         * Set the check interval to be 1/5 of the estimated time to
         * send a single character, and make it at least 1.  The check
@@ -1578,7 +1585,8 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
                        break;
        }
        __set_current_state(TASK_RUNNING);
-       unlock_kernel();
+       if (!tty_was_locked)
+               tty_unlock();
 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
        printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
 #endif
@@ -1702,7 +1710,9 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
                printk("block_til_ready blocking: ttys%d, count = %d\n",
                       info->line, state->count);
 #endif
+               tty_unlock();
                schedule();
+               tty_lock();
        }
        __set_current_state(TASK_RUNNING);
        remove_wait_queue(&info->open_wait, &wait);
@@ -1954,29 +1964,16 @@ static const struct tty_operations serial_ops = {
 /*
  * The serial driver boot-time initialization code!
  */
-static int __init rs_init(void)
+static int __init amiga_serial_probe(struct platform_device *pdev)
 {
        unsigned long flags;
        struct serial_state * state;
        int error;
 
-       if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(AMI_SERIAL))
-               return -ENODEV;
-
        serial_driver = alloc_tty_driver(1);
        if (!serial_driver)
                return -ENOMEM;
 
-       /*
-        *  We request SERDAT and SERPER only, because the serial registers are
-        *  too spreaded over the custom register space
-        */
-       if (!request_mem_region(CUSTOM_PHYSADDR+0x30, 4,
-                               "amiserial [Paula]")) {
-               error = -EBUSY;
-               goto fail_put_tty_driver;
-       }
-
        IRQ_ports = NULL;
 
        show_serial_version();
@@ -1998,7 +1995,7 @@ static int __init rs_init(void)
 
        error = tty_register_driver(serial_driver);
        if (error)
-               goto fail_release_mem_region;
+               goto fail_put_tty_driver;
 
        state = rs_table;
        state->magic = SSTATE_MAGIC;
@@ -2050,23 +2047,24 @@ static int __init rs_init(void)
        ciab.ddra |= (SER_DTR | SER_RTS);   /* outputs */
        ciab.ddra &= ~(SER_DCD | SER_CTS | SER_DSR);  /* inputs */
 
+       platform_set_drvdata(pdev, state);
+
        return 0;
 
 fail_free_irq:
        free_irq(IRQ_AMIGA_TBE, state);
 fail_unregister:
        tty_unregister_driver(serial_driver);
-fail_release_mem_region:
-       release_mem_region(CUSTOM_PHYSADDR+0x30, 4);
 fail_put_tty_driver:
        put_tty_driver(serial_driver);
        return error;
 }
 
-static __exit void rs_exit(void) 
+static int __exit amiga_serial_remove(struct platform_device *pdev)
 {
        int error;
-       struct async_struct *info = rs_table[0].info;
+       struct serial_state *state = platform_get_drvdata(pdev);
+       struct async_struct *info = state->info;
 
        /* printk("Unloading %s: version %s\n", serial_name, serial_version); */
        tasklet_kill(&info->tlet);
@@ -2075,19 +2073,38 @@ static __exit void rs_exit(void)
                       error);
        put_tty_driver(serial_driver);
 
-       if (info) {
-         rs_table[0].info = NULL;
-         kfree(info);
-       }
+       rs_table[0].info = NULL;
+       kfree(info);
 
        free_irq(IRQ_AMIGA_TBE, rs_table);
        free_irq(IRQ_AMIGA_RBF, rs_table);
 
-       release_mem_region(CUSTOM_PHYSADDR+0x30, 4);
+       platform_set_drvdata(pdev, NULL);
+
+       return error;
+}
+
+static struct platform_driver amiga_serial_driver = {
+       .remove = __exit_p(amiga_serial_remove),
+       .driver   = {
+               .name   = "amiga-serial",
+               .owner  = THIS_MODULE,
+       },
+};
+
+static int __init amiga_serial_init(void)
+{
+       return platform_driver_probe(&amiga_serial_driver, amiga_serial_probe);
+}
+
+module_init(amiga_serial_init);
+
+static void __exit amiga_serial_exit(void)
+{
+       platform_driver_unregister(&amiga_serial_driver);
 }
 
-module_init(rs_init)
-module_exit(rs_exit)
+module_exit(amiga_serial_exit);
 
 
 #if defined(CONFIG_SERIAL_CONSOLE) && !defined(MODULE)
@@ -2154,3 +2171,4 @@ console_initcall(amiserial_console_init);
 #endif /* CONFIG_SERIAL_CONSOLE && !MODULE */
 
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:amiga-serial");