Merge tag 'tty-3.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty
[pandora-kernel.git] / drivers / ipack / devices / ipoctal.c
similarity index 86%
rename from drivers/staging/ipack/devices/ipoctal.c
rename to drivers/ipack/devices/ipoctal.c
index 729cb64..576d53d 100644 (file)
@@ -2,9 +2,10 @@
  * ipoctal.c
  *
  * driver for the GE IP-OCTAL boards
- * Copyright (c) 2009 Nicolas Serafini, EIC2 SA
- * Copyright (c) 2010,2011 Samuel Iglesias Gonsalvez <siglesia@cern.ch>, CERN
- * Copyright (c) 2012 Samuel Iglesias Gonsalvez <siglesias@igalia.com>, Igalia
+ *
+ * Copyright (C) 2009-2012 CERN (www.cern.ch)
+ * Author: Nicolas Serafini, EIC2 SA
+ * Author: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the Free
@@ -21,7 +22,7 @@
 #include <linux/slab.h>
 #include <linux/atomic.h>
 #include <linux/io.h>
-#include "../ipack.h"
+#include <linux/ipack.h>
 #include "ipoctal.h"
 #include "scc2698.h"
 
@@ -53,6 +54,8 @@ struct ipoctal {
        struct ipoctal_channel          channel[NR_CHANNELS];
        unsigned char                   write;
        struct tty_driver               *tty_drv;
+       u8 __iomem                      *mem8_space;
+       u8 __iomem                      *int_space;
 };
 
 static int ipoctal_port_activate(struct tty_port *port, struct tty_struct *tty)
@@ -252,35 +255,12 @@ static irqreturn_t ipoctal_irq_handler(void *arg)
                ipoctal_irq_channel(&ipoctal->channel[i]);
 
        /* Clear the IPack device interrupt */
-       readw(ipoctal->dev->int_space.address + ACK_INT_REQ0);
-       readw(ipoctal->dev->int_space.address + ACK_INT_REQ1);
+       readw(ipoctal->int_space + ACK_INT_REQ0);
+       readw(ipoctal->int_space + ACK_INT_REQ1);
 
        return IRQ_HANDLED;
 }
 
-static int ipoctal_check_model(struct ipack_device *dev, unsigned char *id)
-{
-       unsigned char manufacturerID;
-       unsigned char board_id;
-
-
-       manufacturerID = ioread8(dev->id_space.address + IPACK_IDPROM_OFFSET_MANUFACTURER_ID);
-       if (manufacturerID != IPACK1_VENDOR_ID_SBS)
-               return -ENODEV;
-       board_id = ioread8(dev->id_space.address + IPACK_IDPROM_OFFSET_MODEL);
-       switch (board_id) {
-       case IPACK1_DEVICE_ID_SBS_OCTAL_232:
-       case IPACK1_DEVICE_ID_SBS_OCTAL_422:
-       case IPACK1_DEVICE_ID_SBS_OCTAL_485:
-               *id = board_id;
-               break;
-       default:
-               return -ENODEV;
-       }
-
-       return 0;
-}
-
 static const struct tty_port_operations ipoctal_tty_port_ops = {
        .dtr_rts = NULL,
        .activate = ipoctal_port_activate,
@@ -289,64 +269,55 @@ static const struct tty_port_operations ipoctal_tty_port_ops = {
 static int ipoctal_inst_slot(struct ipoctal *ipoctal, unsigned int bus_nr,
                             unsigned int slot)
 {
-       int res = 0;
+       int res;
        int i;
        struct tty_driver *tty;
        char name[20];
-       unsigned char board_id;
        struct ipoctal_channel *channel;
+       struct ipack_region *region;
+       void __iomem *addr;
        union scc2698_channel __iomem *chan_regs;
        union scc2698_block __iomem *block_regs;
 
-       res = ipoctal->dev->bus->ops->map_space(ipoctal->dev, 0,
-                                               IPACK_ID_SPACE);
-       if (res) {
-               dev_err(&ipoctal->dev->dev,
-                       "Unable to map slot [%d:%d] ID space!\n",
-                       bus_nr, slot);
-               return res;
-       }
-
-       res = ipoctal_check_model(ipoctal->dev, &board_id);
-       if (res) {
-               ipoctal->dev->bus->ops->unmap_space(ipoctal->dev,
-                                                   IPACK_ID_SPACE);
-               goto out_unregister_id_space;
-       }
-       ipoctal->board_id = board_id;
+       ipoctal->board_id = ipoctal->dev->id_device;
 
-       res = ipoctal->dev->bus->ops->map_space(ipoctal->dev, 0,
-                                               IPACK_IO_SPACE);
-       if (res) {
+       region = &ipoctal->dev->region[IPACK_IO_SPACE];
+       addr = devm_ioremap_nocache(&ipoctal->dev->dev,
+                                   region->start, region->size);
+       if (!addr) {
                dev_err(&ipoctal->dev->dev,
                        "Unable to map slot [%d:%d] IO space!\n",
                        bus_nr, slot);
-               goto out_unregister_id_space;
+               return -EADDRNOTAVAIL;
        }
+       /* Save the virtual address to access the registers easily */
+       chan_regs =
+               (union scc2698_channel __iomem *) addr;
+       block_regs =
+               (union scc2698_block __iomem *) addr;
 
-       res = ipoctal->dev->bus->ops->map_space(ipoctal->dev, 0,
-                                               IPACK_INT_SPACE);
-       if (res) {
+       region = &ipoctal->dev->region[IPACK_INT_SPACE];
+       ipoctal->int_space =
+               devm_ioremap_nocache(&ipoctal->dev->dev,
+                                    region->start, region->size);
+       if (!ipoctal->int_space) {
                dev_err(&ipoctal->dev->dev,
                        "Unable to map slot [%d:%d] INT space!\n",
                        bus_nr, slot);
-               goto out_unregister_io_space;
+               return -EADDRNOTAVAIL;
        }
 
-       res = ipoctal->dev->bus->ops->map_space(ipoctal->dev,
-                                          0x8000, IPACK_MEM_SPACE);
-       if (res) {
+       region = &ipoctal->dev->region[IPACK_MEM8_SPACE];
+       ipoctal->mem8_space =
+               devm_ioremap_nocache(&ipoctal->dev->dev,
+                                    region->start, 0x8000);
+       if (!addr) {
                dev_err(&ipoctal->dev->dev,
-                       "Unable to map slot [%d:%d] MEM space!\n",
+                       "Unable to map slot [%d:%d] MEM8 space!\n",
                        bus_nr, slot);
-               goto out_unregister_int_space;
+               return -EADDRNOTAVAIL;
        }
 
-       /* Save the virtual address to access the registers easily */
-       chan_regs =
-               (union scc2698_channel __iomem *) ipoctal->dev->io_space.address;
-       block_regs =
-               (union scc2698_block __iomem *) ipoctal->dev->io_space.address;
 
        /* Disable RX and TX before touching anything */
        for (i = 0; i < NR_CHANNELS ; i++) {
@@ -389,17 +360,15 @@ static int ipoctal_inst_slot(struct ipoctal *ipoctal, unsigned int bus_nr,
        ipoctal->dev->bus->ops->request_irq(ipoctal->dev,
                                       ipoctal_irq_handler, ipoctal);
        /* Dummy write */
-       iowrite8(1, ipoctal->dev->mem_space.address + 1);
+       iowrite8(1, ipoctal->mem8_space + 1);
 
        /* Register the TTY device */
 
        /* Each IP-OCTAL channel is a TTY port */
        tty = alloc_tty_driver(NR_CHANNELS);
 
-       if (!tty) {
-               res = -ENOMEM;
-               goto out_unregister_slot_unmap;
-       }
+       if (!tty)
+               return -ENOMEM;
 
        /* Fill struct tty_driver with ipoctal data */
        tty->owner = THIS_MODULE;
@@ -422,7 +391,7 @@ static int ipoctal_inst_slot(struct ipoctal *ipoctal, unsigned int bus_nr,
        if (res) {
                dev_err(&ipoctal->dev->dev, "Can't register tty driver.\n");
                put_tty_driver(tty);
-               goto out_unregister_slot_unmap;
+               return res;
        }
 
        /* Save struct tty_driver for use it when uninstalling the device */
@@ -459,16 +428,6 @@ static int ipoctal_inst_slot(struct ipoctal *ipoctal, unsigned int bus_nr,
        }
 
        return 0;
-
-out_unregister_slot_unmap:
-       ipoctal->dev->bus->ops->unmap_space(ipoctal->dev, IPACK_ID_SPACE);
-out_unregister_int_space:
-       ipoctal->dev->bus->ops->unmap_space(ipoctal->dev, IPACK_INT_SPACE);
-out_unregister_io_space:
-       ipoctal->dev->bus->ops->unmap_space(ipoctal->dev, IPACK_IO_SPACE);
-out_unregister_id_space:
-       ipoctal->dev->bus->ops->unmap_space(ipoctal->dev, IPACK_MEM_SPACE);
-       return res;
 }
 
 static inline int ipoctal_copy_write_buffer(struct ipoctal_channel *channel,
@@ -720,7 +679,7 @@ static int ipoctal_probe(struct ipack_device *dev)
                return -ENOMEM;
 
        ipoctal->dev = dev;
-       res = ipoctal_inst_slot(ipoctal, dev->bus_nr, dev->slot);
+       res = ipoctal_inst_slot(ipoctal, dev->bus->bus_nr, dev->slot);
        if (res)
                goto out_uninst;
 
@@ -747,10 +706,6 @@ static void __ipoctal_remove(struct ipoctal *ipoctal)
 
        tty_unregister_driver(ipoctal->tty_drv);
        put_tty_driver(ipoctal->tty_drv);
-       ipoctal->dev->bus->ops->unmap_space(ipoctal->dev, IPACK_MEM_SPACE);
-       ipoctal->dev->bus->ops->unmap_space(ipoctal->dev, IPACK_INT_SPACE);
-       ipoctal->dev->bus->ops->unmap_space(ipoctal->dev, IPACK_IO_SPACE);
-       ipoctal->dev->bus->ops->unmap_space(ipoctal->dev, IPACK_ID_SPACE);
        kfree(ipoctal);
 }