macb: straighten out macb_mii_probe function
[safe/jmp/linux-2.6] / drivers / serial / icom.c
index ad1e753..0028b6f 100644 (file)
@@ -27,7 +27,6 @@
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/signal.h>
-#include <linux/sched.h>
 #include <linux/timer.h>
 #include <linux/interrupt.h>
 #include <linux/tty.h>
@@ -48,9 +47,8 @@
 #include <linux/pci.h>
 #include <linux/vmalloc.h>
 #include <linux/smp.h>
-#include <linux/smp_lock.h>
 #include <linux/spinlock.h>
-#include <linux/kobject.h>
+#include <linux/kref.h>
 #include <linux/firmware.h>
 #include <linux/bitops.h>
 
 #define ICOM_VERSION_STR "1.3.1"
 #define NR_PORTS              128
 #define ICOM_PORT ((struct icom_port *)port)
-#define to_icom_adapter(d) container_of(d, struct icom_adapter, kobj)
+#define to_icom_adapter(d) container_of(d, struct icom_adapter, kref)
 
 static const struct pci_device_id icom_pci_table[] = {
        {
-             .vendor = PCI_VENDOR_ID_IBM,
-             .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_1,
-             .subvendor = PCI_ANY_ID,
-             .subdevice = PCI_ANY_ID,
-             .driver_data = ADAPTER_V1,
-        },
+               .vendor = PCI_VENDOR_ID_IBM,
+               .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_1,
+               .subvendor = PCI_ANY_ID,
+               .subdevice = PCI_ANY_ID,
+               .driver_data = ADAPTER_V1,
+       },
        {
-             .vendor = PCI_VENDOR_ID_IBM,
-             .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
-             .subvendor = PCI_VENDOR_ID_IBM,
-             .subdevice = PCI_DEVICE_ID_IBM_ICOM_V2_TWO_PORTS_RVX,
-             .driver_data = ADAPTER_V2,
-        },
+               .vendor = PCI_VENDOR_ID_IBM,
+               .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
+               .subvendor = PCI_VENDOR_ID_IBM,
+               .subdevice = PCI_DEVICE_ID_IBM_ICOM_V2_TWO_PORTS_RVX,
+               .driver_data = ADAPTER_V2,
+       },
        {
-             .vendor = PCI_VENDOR_ID_IBM,
-             .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
-             .subvendor = PCI_VENDOR_ID_IBM,
-             .subdevice = PCI_DEVICE_ID_IBM_ICOM_V2_ONE_PORT_RVX_ONE_PORT_MDM,
-             .driver_data = ADAPTER_V2,
-        },
+               .vendor = PCI_VENDOR_ID_IBM,
+               .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
+               .subvendor = PCI_VENDOR_ID_IBM,
+               .subdevice = PCI_DEVICE_ID_IBM_ICOM_V2_ONE_PORT_RVX_ONE_PORT_MDM,
+               .driver_data = ADAPTER_V2,
+       },
        {
-             .vendor = PCI_VENDOR_ID_IBM,
-             .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
-             .subvendor = PCI_VENDOR_ID_IBM,
-             .subdevice = PCI_DEVICE_ID_IBM_ICOM_FOUR_PORT_MODEL,
-             .driver_data = ADAPTER_V2,
-        },
+               .vendor = PCI_VENDOR_ID_IBM,
+               .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
+               .subvendor = PCI_VENDOR_ID_IBM,
+               .subdevice = PCI_DEVICE_ID_IBM_ICOM_FOUR_PORT_MODEL,
+               .driver_data = ADAPTER_V2,
+       },
+       {
+               .vendor = PCI_VENDOR_ID_IBM,
+               .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
+               .subvendor = PCI_VENDOR_ID_IBM,
+               .subdevice = PCI_DEVICE_ID_IBM_ICOM_V2_ONE_PORT_RVX_ONE_PORT_MDM_PCIE,
+               .driver_data = ADAPTER_V2,
+       },
        {}
 };
 
@@ -132,10 +137,16 @@ static LIST_HEAD(icom_adapter_head);
 static spinlock_t icom_lock;
 
 #ifdef ICOM_TRACE
-static inline void trace(struct icom_port *, char *, unsigned long) {};
+static inline void trace(struct icom_port *icom_port, char *trace_pt,
+                       unsigned long trace_data)
+{
+       dev_info(&icom_port->adapter->pci_dev->dev, ":%d:%s - %lx\n",
+       icom_port->port, trace_pt, trace_data);
+}
 #else
 static inline void trace(struct icom_port *icom_port, char *trace_pt, unsigned long trace_data) {};
 #endif
+static void icom_kref_release(struct kref *kref);
 
 static void free_port_memory(struct icom_port *icom_port)
 {
@@ -165,7 +176,7 @@ static void free_port_memory(struct icom_port *icom_port)
        }
 }
 
-static int __init get_port_memory(struct icom_port *icom_port)
+static int __devinit get_port_memory(struct icom_port *icom_port)
 {
        int index;
        unsigned long stgAddr;
@@ -296,7 +307,7 @@ static void stop_processor(struct icom_port *icom_port)
        if (port < 4) {
                temp = readl(stop_proc[port].global_control_reg);
                temp =
-                       (temp & ~start_proc[port].processor_id) | stop_proc[port].processor_id;
+                       (temp & ~start_proc[port].processor_id) | stop_proc[port].processor_id;
                writel(temp, stop_proc[port].global_control_reg);
 
                /* write flush */
@@ -325,7 +336,7 @@ static void start_processor(struct icom_port *icom_port)
        if (port < 4) {
                temp = readl(start_proc[port].global_control_reg);
                temp =
-                       (temp & ~stop_proc[port].processor_id) | start_proc[port].processor_id;
+                       (temp & ~stop_proc[port].processor_id) | start_proc[port].processor_id;
                writel(temp, start_proc[port].global_control_reg);
 
                /* write flush */
@@ -402,7 +413,7 @@ static void load_code(struct icom_port *icom_port)
        release_firmware(fw);
 
        /* Set Hardware level */
-       if ((icom_port->adapter->version | ADAPTER_V2) == ADAPTER_V2)
+       if (icom_port->adapter->version == ADAPTER_V2)
                writeb(V2_HARDWARE, &(icom_port->dram->misc_flags));
 
        /* Start the processor in Adapter */
@@ -498,8 +509,8 @@ static void load_code(struct icom_port *icom_port)
                dev_err(&icom_port->adapter->pci_dev->dev,"Port not opertional\n");
        }
 
-      if (new_page != NULL)
-             pci_free_consistent(dev, 4096, new_page, temp_pci);
+       if (new_page != NULL)
+               pci_free_consistent(dev, 4096, new_page, temp_pci);
 }
 
 static int startup(struct icom_port *icom_port)
@@ -606,7 +617,7 @@ static void shutdown(struct icom_port *icom_port)
         * disable break condition
         */
        cmdReg = readb(&icom_port->dram->CmdReg);
-       if ((cmdReg | CMD_SND_BREAK) == CMD_SND_BREAK) {
+       if (cmdReg & CMD_SND_BREAK) {
                writeb(cmdReg & ~CMD_SND_BREAK, &icom_port->dram->CmdReg);
        }
 }
@@ -616,7 +627,7 @@ static int icom_write(struct uart_port *port)
        unsigned long data_count;
        unsigned char cmdReg;
        unsigned long offset;
-       int temp_tail = port->info->xmit.tail;
+       int temp_tail = port->state->xmit.tail;
 
        trace(ICOM_PORT, "WRITE", 0);
 
@@ -627,11 +638,11 @@ static int icom_write(struct uart_port *port)
        }
 
        data_count = 0;
-       while ((port->info->xmit.head != temp_tail) &&
+       while ((port->state->xmit.head != temp_tail) &&
               (data_count <= XMIT_BUFF_SZ)) {
 
                ICOM_PORT->xmit_buf[data_count++] =
-                   port->info->xmit.buf[temp_tail];
+                   port->state->xmit.buf[temp_tail];
 
                temp_tail++;
                temp_tail &= (UART_XMIT_SIZE - 1);
@@ -683,8 +694,8 @@ static inline void check_modem_status(struct icom_port *icom_port)
                        uart_handle_cts_change(&icom_port->uart_port,
                                               delta_status & ICOM_CTS);
 
-               wake_up_interruptible(&icom_port->uart_port.info->
-                                     delta_msr_wait);
+               wake_up_interruptible(&icom_port->uart_port.state->
+                                     port.delta_msr_wait);
                old_status = status;
        }
        spin_unlock(&icom_port->uart_port.lock);
@@ -707,10 +718,10 @@ static void xmit_interrupt(u16 port_int_reg, struct icom_port *icom_port)
                icom_port->uart_port.icount.tx += count;
 
                for (i=0; i<count &&
-                       !uart_circ_empty(&icom_port->uart_port.info->xmit); i++) {
+                       !uart_circ_empty(&icom_port->uart_port.state->xmit); i++) {
 
-                       icom_port->uart_port.info->xmit.tail++;
-                       icom_port->uart_port.info->xmit.tail &=
+                       icom_port->uart_port.state->xmit.tail++;
+                       icom_port->uart_port.state->xmit.tail &=
                                (UART_XMIT_SIZE - 1);
                }
 
@@ -724,7 +735,7 @@ static void xmit_interrupt(u16 port_int_reg, struct icom_port *icom_port)
 static void recv_interrupt(u16 port_int_reg, struct icom_port *icom_port)
 {
        short int count, rcv_buff;
-       struct tty_struct *tty = icom_port->uart_port.info->tty;
+       struct tty_struct *tty = icom_port->uart_port.state->port.tty;
        unsigned short int status;
        struct uart_icount *icount;
        unsigned long offset;
@@ -844,8 +855,7 @@ static void process_interrupt(u16 port_int_reg,
        spin_unlock(&icom_port->uart_port.lock);
 }
 
-static irqreturn_t icom_interrupt(int irq, void *dev_id,
-                                 struct pt_regs *regs)
+static irqreturn_t icom_interrupt(int irq, void *dev_id)
 {
        void __iomem * int_reg;
        u32 adapter_interrupts;
@@ -856,7 +866,7 @@ static irqreturn_t icom_interrupt(int irq, void *dev_id,
        /* find icom_port for this interrupt */
        icom_adapter = (struct icom_adapter *) dev_id;
 
-       if ((icom_adapter->version | ADAPTER_V2) == ADAPTER_V2) {
+       if (icom_adapter->version == ADAPTER_V2) {
                int_reg = icom_adapter->base_addr + 0x8024;
 
                adapter_interrupts = readl(int_reg);
@@ -1059,11 +1069,11 @@ static int icom_open(struct uart_port *port)
 {
        int retval;
 
-       kobject_get(&ICOM_PORT->adapter->kobj);
+       kref_get(&ICOM_PORT->adapter->kref);
        retval = startup(ICOM_PORT);
 
        if (retval) {
-               kobject_put(&ICOM_PORT->adapter->kobj);
+               kref_put(&ICOM_PORT->adapter->kref, icom_kref_release);
                trace(ICOM_PORT, "STARTUP_ERROR", 0);
                return retval;
        }
@@ -1084,16 +1094,15 @@ static void icom_close(struct uart_port *port)
 
        shutdown(ICOM_PORT);
 
-       kobject_put(&ICOM_PORT->adapter->kobj);
+       kref_put(&ICOM_PORT->adapter->kref, icom_kref_release);
 }
 
 static void icom_set_termios(struct uart_port *port,
-                            struct termios *termios,
-                            struct termios *old_termios)
+                            struct ktermios *termios,
+                            struct ktermios *old_termios)
 {
        int baud;
        unsigned cflag, iflag;
-       int bits;
        char new_config2;
        char new_config3 = 0;
        char tmp_byte;
@@ -1114,34 +1123,27 @@ static void icom_set_termios(struct uart_port *port,
        switch (cflag & CSIZE) {
        case CS5:               /* 5 bits/char */
                new_config2 |= ICOM_ACFG_5BPC;
-               bits = 7;
                break;
        case CS6:               /* 6 bits/char */
                new_config2 |= ICOM_ACFG_6BPC;
-               bits = 8;
                break;
        case CS7:               /* 7 bits/char */
                new_config2 |= ICOM_ACFG_7BPC;
-               bits = 9;
                break;
        case CS8:               /* 8 bits/char */
                new_config2 |= ICOM_ACFG_8BPC;
-               bits = 10;
                break;
        default:
-               bits = 10;
                break;
        }
        if (cflag & CSTOPB) {
                /* 2 stop bits */
                new_config2 |= ICOM_ACFG_2STOP_BIT;
-               bits++;
        }
        if (cflag & PARENB) {
                /* parity bit enabled */
                new_config2 |= ICOM_ACFG_PARITY_ENAB;
                trace(ICOM_PORT, "PARENB", 0);
-               bits++;
        }
        if (cflag & PARODD) {
                /* odd parity */
@@ -1317,7 +1319,6 @@ static struct uart_driver icom_uart_driver = {
 static int __devinit icom_init_ports(struct icom_adapter *icom_adapter)
 {
        u32 subsystem_id = icom_adapter->subsystem_id;
-       int retval = 0;
        int i;
        struct icom_port *icom_port;
 
@@ -1363,7 +1364,7 @@ static int __devinit icom_init_ports(struct icom_adapter *icom_adapter)
                }
        }
 
-       return retval;
+       return 0;
 }
 
 static void icom_port_active(struct icom_port *icom_port, struct icom_adapter *icom_adapter, int port_num)
@@ -1382,11 +1383,10 @@ static void icom_port_active(struct icom_port *icom_port, struct icom_adapter *i
                            0x8024 + 2 - 2 * (icom_port->port - 2);
        }
 }
-static int __init icom_load_ports(struct icom_adapter *icom_adapter)
+static int __devinit icom_load_ports(struct icom_adapter *icom_adapter)
 {
        struct icom_port *icom_port;
        int port_num;
-       int retval;
 
        for (port_num = 0; port_num < icom_adapter->numb_ports; port_num++) {
 
@@ -1400,7 +1400,7 @@ static int __init icom_load_ports(struct icom_adapter *icom_adapter)
                        icom_port->adapter = icom_adapter;
 
                        /* get port memory */
-                       if ((retval = get_port_memory(icom_port)) != 0) {
+                       if (get_port_memory(icom_port) != 0) {
                                dev_err(&icom_port->adapter->pci_dev->dev,
                                        "Memory allocation for port FAILED\n");
                        }
@@ -1418,14 +1418,12 @@ static int __devinit icom_alloc_adapter(struct icom_adapter
        struct list_head *tmp;
 
        icom_adapter = (struct icom_adapter *)
-           kmalloc(sizeof(struct icom_adapter), GFP_KERNEL);
+           kzalloc(sizeof(struct icom_adapter), GFP_KERNEL);
 
        if (!icom_adapter) {
                return -ENOMEM;
        }
 
-       memset(icom_adapter, 0, sizeof(struct icom_adapter));
-
        list_for_each(tmp, &icom_adapter_head) {
                cur_adapter_entry =
                    list_entry(tmp, struct icom_adapter,
@@ -1477,62 +1475,58 @@ static void icom_remove_adapter(struct icom_adapter *icom_adapter)
                }
        }
 
-       free_irq(icom_adapter->irq_number, (void *) icom_adapter);
+       free_irq(icom_adapter->pci_dev->irq, (void *) icom_adapter);
        iounmap(icom_adapter->base_addr);
-       icom_free_adapter(icom_adapter);
        pci_release_regions(icom_adapter->pci_dev);
+       icom_free_adapter(icom_adapter);
 }
 
-static void icom_kobj_release(struct kobject *kobj)
+static void icom_kref_release(struct kref *kref)
 {
        struct icom_adapter *icom_adapter;
 
-       icom_adapter = to_icom_adapter(kobj);
+       icom_adapter = to_icom_adapter(kref);
        icom_remove_adapter(icom_adapter);
 }
 
-static struct kobj_type icom_kobj_type = {
-       .release = icom_kobj_release,
-};
-
 static int __devinit icom_probe(struct pci_dev *dev,
                                const struct pci_device_id *ent)
 {
        int index;
-        unsigned int command_reg;
-        int retval;
-        struct icom_adapter *icom_adapter;
-        struct icom_port *icom_port;
+       unsigned int command_reg;
+       int retval;
+       struct icom_adapter *icom_adapter;
+       struct icom_port *icom_port;
 
-        retval = pci_enable_device(dev);
-        if (retval) {
+       retval = pci_enable_device(dev);
+       if (retval) {
                dev_err(&dev->dev, "Device enable FAILED\n");
-                return retval;
+               return retval;
        }
 
        if ( (retval = pci_request_regions(dev, "icom"))) {
-                dev_err(&dev->dev, "pci_request_region FAILED\n");
+                dev_err(&dev->dev, "pci_request_regions FAILED\n");
                 pci_disable_device(dev);
                 return retval;
         }
 
-        pci_set_master(dev);
+       pci_set_master(dev);
 
-        if ( (retval = pci_read_config_dword(dev, PCI_COMMAND, &command_reg))) {
+       if ( (retval = pci_read_config_dword(dev, PCI_COMMAND, &command_reg))) {
                dev_err(&dev->dev, "PCI Config read FAILED\n");
-                return retval;
-        }
+               return retval;
+       }
 
        pci_write_config_dword(dev, PCI_COMMAND,
                command_reg | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
                | PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
 
-        if (ent->driver_data == ADAPTER_V1) {
+       if (ent->driver_data == ADAPTER_V1) {
                pci_write_config_dword(dev, 0x44, 0x8300830A);
-        } else {
+       } else {
                pci_write_config_dword(dev, 0x44, 0x42004200);
                pci_write_config_dword(dev, 0x48, 0x42004200);
-         }
+       }
 
 
        retval = icom_alloc_adapter(&icom_adapter);
@@ -1542,11 +1536,10 @@ static int __devinit icom_probe(struct pci_dev *dev,
                 goto probe_exit0;
        }
 
-        icom_adapter->base_addr_pci = pci_resource_start(dev, 0);
-        icom_adapter->irq_number = dev->irq;
-        icom_adapter->pci_dev = dev;
-        icom_adapter->version = ent->driver_data;
-        icom_adapter->subsystem_id = ent->subdevice;
+       icom_adapter->base_addr_pci = pci_resource_start(dev, 0);
+       icom_adapter->pci_dev = dev;
+       icom_adapter->version = ent->driver_data;
+       icom_adapter->subsystem_id = ent->subdevice;
 
 
        retval = icom_init_ports(icom_adapter);
@@ -1555,26 +1548,25 @@ static int __devinit icom_probe(struct pci_dev *dev,
                goto probe_exit1;
        }
 
-        icom_adapter->base_addr = ioremap(icom_adapter->base_addr_pci,
-                                               pci_resource_len(dev, 0));
+       icom_adapter->base_addr = pci_ioremap_bar(dev, 0);
 
        if (!icom_adapter->base_addr)
                goto probe_exit1;
 
         /* save off irq and request irq line */
         if ( (retval = request_irq(dev->irq, icom_interrupt,
-                                  SA_INTERRUPT | SA_SHIRQ, ICOM_DRIVER_NAME,
+                                  IRQF_DISABLED | IRQF_SHARED, ICOM_DRIVER_NAME,
                                   (void *) icom_adapter))) {
                  goto probe_exit2;
         }
 
        retval = icom_load_ports(icom_adapter);
 
-        for (index = 0; index < icom_adapter->numb_ports; index++) {
+       for (index = 0; index < icom_adapter->numb_ports; index++) {
                icom_port = &icom_adapter->port_info[index];
 
                if (icom_port->status == ICOM_PORT_ACTIVE) {
-                       icom_port->uart_port.irq = icom_port->adapter->irq_number;
+                       icom_port->uart_port.irq = icom_port->adapter->pci_dev->irq;
                        icom_port->uart_port.type = PORT_ICOM;
                        icom_port->uart_port.iotype = UPIO_MEM;
                        icom_port->uart_port.membase =
@@ -1587,12 +1579,11 @@ static int __devinit icom_probe(struct pci_dev *dev,
                                icom_port->status = ICOM_PORT_OFF;
                                dev_err(&dev->dev, "Device add failed\n");
                         } else
-                               dev_info(&dev->dev, "Device added\n");
+                               dev_info(&dev->dev, "Device added\n");
                }
        }
 
-       kobject_init(&icom_adapter->kobj);
-       icom_adapter->kobj.ktype = &icom_kobj_type;
+       kref_init(&icom_adapter->kref);
        return 0;
 
 probe_exit2:
@@ -1604,9 +1595,7 @@ probe_exit0:
        pci_release_regions(dev);
        pci_disable_device(dev);
 
-        return retval;
-
-
+       return retval;
 }
 
 static void __devexit icom_remove(struct pci_dev *dev)
@@ -1618,7 +1607,7 @@ static void __devexit icom_remove(struct pci_dev *dev)
                icom_adapter = list_entry(tmp, struct icom_adapter,
                                          icom_adapter_entry);
                if (icom_adapter->pci_dev == dev) {
-                       kobject_put(&icom_adapter->kobj);
+                       kref_put(&icom_adapter->kref, icom_kref_release);
                        return;
                }
        }
@@ -1660,15 +1649,6 @@ static void __exit icom_exit(void)
 module_init(icom_init);
 module_exit(icom_exit);
 
-#ifdef ICOM_TRACE
-static inline void trace(struct icom_port *icom_port, char *trace_pt,
-                 unsigned long trace_data)
-{
-       dev_info(&icom_port->adapter->pci_dev->dev, ":%d:%s - %lx\n",
-                icom_port->port, trace_pt, trace_data);
-}
-#endif
-
 MODULE_AUTHOR("Michael Anderson <mjanders@us.ibm.com>");
 MODULE_DESCRIPTION("IBM iSeries Serial IOA driver");
 MODULE_SUPPORTED_DEVICE