Bluetooth: Convert BCM92035 support to driver setup callback
[linux-3.10.git] / drivers / bluetooth / dtl1_cs.c
index dae45cd..036cb36 100644 (file)
 #include <linux/serial.h>
 #include <linux/serial_reg.h>
 #include <linux/bitops.h>
-#include <asm/system.h>
 #include <asm/io.h>
 
-#include <pcmcia/cs_types.h>
-#include <pcmcia/cs.h>
 #include <pcmcia/cistpl.h>
 #include <pcmcia/ciscode.h>
 #include <pcmcia/ds.h>
@@ -67,7 +64,6 @@ MODULE_LICENSE("GPL");
 
 typedef struct dtl1_info_t {
        struct pcmcia_device *p_dev;
-       dev_node_t node;
 
        struct hci_dev *hdev;
 
@@ -86,9 +82,6 @@ typedef struct dtl1_info_t {
 
 
 static int dtl1_config(struct pcmcia_device *link);
-static void dtl1_release(struct pcmcia_device *link);
-
-static void dtl1_detach(struct pcmcia_device *p_dev);
 
 
 /* Transmit states  */
@@ -105,7 +98,7 @@ typedef struct {
        u8 type;
        u8 zero;
        u16 len;
-} __attribute__ ((packed)) nsh_t;      /* Nokia Specific Header */
+} __packed nsh_t;      /* Nokia Specific Header */
 
 #define NSHL  4                                /* Nokia Specific Header Length */
 
@@ -151,9 +144,9 @@ static void dtl1_write_wakeup(dtl1_info_t *info)
        }
 
        do {
-               register unsigned int iobase = info->p_dev->io.BasePort1;
+               unsigned int iobase = info->p_dev->resource[0]->start;
                register struct sk_buff *skb;
-               register int len;
+               int len;
 
                clear_bit(XMIT_WAKEUP, &(info->tx_state));
 
@@ -216,7 +209,7 @@ static void dtl1_receive(dtl1_info_t *info)
                return;
        }
 
-       iobase = info->p_dev->io.BasePort1;
+       iobase = info->p_dev->resource[0]->start;
 
        do {
                info->hdev->stat.byte_rx++;
@@ -297,16 +290,20 @@ static irqreturn_t dtl1_interrupt(int irq, void *dev_inst)
        unsigned char msr;
        int boguscount = 0;
        int iir, lsr;
+       irqreturn_t r = IRQ_NONE;
 
-       BUG_ON(!info->hdev);
+       if (!info || !info->hdev)
+               /* our irq handler is shared */
+               return IRQ_NONE;
 
-       iobase = info->p_dev->io.BasePort1;
+       iobase = info->p_dev->resource[0]->start;
 
        spin_lock(&(info->lock));
 
        iir = inb(iobase + UART_IIR) & UART_IIR_ID;
        while (iir) {
 
+               r = IRQ_HANDLED;
                /* Clear interrupt */
                lsr = inb(iobase + UART_LSR);
 
@@ -343,11 +340,12 @@ static irqreturn_t dtl1_interrupt(int irq, void *dev_inst)
                info->ri_latch = msr & UART_MSR_RI;
                clear_bit(XMIT_WAITING, &(info->tx_state));
                dtl1_write_wakeup(info);
+               r = IRQ_HANDLED;
        }
 
        spin_unlock(&(info->lock));
 
-       return IRQ_HANDLED;
+       return r;
 }
 
 
@@ -365,7 +363,7 @@ static int dtl1_hci_open(struct hci_dev *hdev)
 
 static int dtl1_hci_flush(struct hci_dev *hdev)
 {
-       dtl1_info_t *info = (dtl1_info_t *)(hdev->driver_data);
+       dtl1_info_t *info = hci_get_drvdata(hdev);
 
        /* Drop TX queue */
        skb_queue_purge(&(info->txq));
@@ -397,7 +395,7 @@ static int dtl1_hci_send_frame(struct sk_buff *skb)
                return -ENODEV;
        }
 
-       info = (dtl1_info_t *)(hdev->driver_data);
+       info = hci_get_drvdata(hdev);
 
        switch (bt_cb(skb)->pkt_type) {
        case HCI_COMMAND_PKT:
@@ -412,6 +410,8 @@ static int dtl1_hci_send_frame(struct sk_buff *skb)
                hdev->stat.sco_tx++;
                nsh.type = 0x83;
                break;
+       default:
+               return -EILSEQ;
        };
 
        nsh.zero = 0;
@@ -438,11 +438,6 @@ static int dtl1_hci_send_frame(struct sk_buff *skb)
 }
 
 
-static void dtl1_hci_destruct(struct hci_dev *hdev)
-{
-}
-
-
 static int dtl1_hci_ioctl(struct hci_dev *hdev, unsigned int cmd,  unsigned long arg)
 {
        return -ENOIOCTLCMD;
@@ -456,7 +451,7 @@ static int dtl1_hci_ioctl(struct hci_dev *hdev, unsigned int cmd,  unsigned long
 static int dtl1_open(dtl1_info_t *info)
 {
        unsigned long flags;
-       unsigned int iobase = info->p_dev->io.BasePort1;
+       unsigned int iobase = info->p_dev->resource[0]->start;
        struct hci_dev *hdev;
 
        spin_lock_init(&(info->lock));
@@ -478,19 +473,16 @@ static int dtl1_open(dtl1_info_t *info)
 
        info->hdev = hdev;
 
-       hdev->type = HCI_PCCARD;
-       hdev->driver_data = info;
+       hdev->bus = HCI_PCCARD;
+       hci_set_drvdata(hdev, info);
        SET_HCIDEV_DEV(hdev, &info->p_dev->dev);
 
        hdev->open     = dtl1_hci_open;
        hdev->close    = dtl1_hci_close;
        hdev->flush    = dtl1_hci_flush;
        hdev->send     = dtl1_hci_send_frame;
-       hdev->destruct = dtl1_hci_destruct;
        hdev->ioctl    = dtl1_hci_ioctl;
 
-       hdev->owner = THIS_MODULE;
-
        spin_lock_irqsave(&(info->lock), flags);
 
        /* Reset UART */
@@ -503,7 +495,8 @@ static int dtl1_open(dtl1_info_t *info)
        outb(UART_LCR_WLEN8, iobase + UART_LCR);        /* Reset DLAB */
        outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), iobase + UART_MCR);
 
-       info->ri_latch = inb(info->p_dev->io.BasePort1 + UART_MSR) & UART_MSR_RI;
+       info->ri_latch = inb(info->p_dev->resource[0]->start + UART_MSR)
+                               & UART_MSR_RI;
 
        /* Turn on interrupts */
        outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
@@ -528,7 +521,7 @@ static int dtl1_open(dtl1_info_t *info)
 static int dtl1_close(dtl1_info_t *info)
 {
        unsigned long flags;
-       unsigned int iobase = info->p_dev->io.BasePort1;
+       unsigned int iobase = info->p_dev->resource[0]->start;
        struct hci_dev *hdev = info->hdev;
 
        if (!hdev)
@@ -546,9 +539,7 @@ static int dtl1_close(dtl1_info_t *info)
 
        spin_unlock_irqrestore(&(info->lock), flags);
 
-       if (hci_unregister_dev(hdev) < 0)
-               BT_ERR("Can't unregister HCI device %s", hdev->name);
-
+       hci_unregister_dev(hdev);
        hci_free_dev(hdev);
 
        return 0;
@@ -559,23 +550,14 @@ static int dtl1_probe(struct pcmcia_device *link)
        dtl1_info_t *info;
 
        /* Create new info device */
-       info = kzalloc(sizeof(*info), GFP_KERNEL);
+       info = devm_kzalloc(&link->dev, sizeof(*info), GFP_KERNEL);
        if (!info)
                return -ENOMEM;
 
        info->p_dev = link;
        link->priv = info;
 
-       link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
-       link->io.NumPorts1 = 8;
-       link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
-       link->irq.IRQInfo1 = IRQ_LEVEL_ID;
-
-       link->irq.Handler = dtl1_interrupt;
-       link->irq.Instance = info;
-
-       link->conf.Attributes = CONF_ENABLE_IRQ;
-       link->conf.IntType = INT_MEMORY_AND_IO;
+       link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
 
        return dtl1_config(link);
 }
@@ -585,109 +567,52 @@ static void dtl1_detach(struct pcmcia_device *link)
 {
        dtl1_info_t *info = link->priv;
 
-       dtl1_release(link);
-
-       kfree(info);
+       dtl1_close(info);
+       pcmcia_disable_device(link);
 }
 
-static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
+static int dtl1_confcheck(struct pcmcia_device *p_dev, void *priv_data)
 {
-       int i;
-
-       i = pcmcia_get_tuple_data(handle, tuple);
-       if (i != CS_SUCCESS)
-               return i;
-
-       return pcmcia_parse_tuple(handle, tuple, parse);
-}
+       if ((p_dev->resource[1]->end) || (p_dev->resource[1]->end < 8))
+               return -ENODEV;
 
-static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
-{
-       if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS)
-               return CS_NO_MORE_ITEMS;
-       return get_tuple(handle, tuple, parse);
-}
+       p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
+       p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
 
-static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
-{
-       if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS)
-               return CS_NO_MORE_ITEMS;
-       return get_tuple(handle, tuple, parse);
+       return pcmcia_request_io(p_dev);
 }
 
 static int dtl1_config(struct pcmcia_device *link)
 {
        dtl1_info_t *info = link->priv;
-       tuple_t tuple;
-       u_short buf[256];
-       cisparse_t parse;
-       cistpl_cftable_entry_t *cf = &parse.cftable_entry;
-       int i;
-
-       tuple.TupleData = (cisdata_t *)buf;
-       tuple.TupleOffset = 0;
-       tuple.TupleDataMax = 255;
-       tuple.Attributes = 0;
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
+       int ret;
 
        /* Look for a generic full-sized window */
-       link->io.NumPorts1 = 8;
-       i = first_tuple(link, &tuple, &parse);
-       while (i != CS_NO_MORE_ITEMS) {
-               if ((i == CS_SUCCESS) && (cf->io.nwin == 1) && (cf->io.win[0].len > 8)) {
-                       link->conf.ConfigIndex = cf->index;
-                       link->io.BasePort1 = cf->io.win[0].base;
-                       link->io.NumPorts1 = cf->io.win[0].len; /*yo */
-                       link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
-                       i = pcmcia_request_io(link, &link->io);
-                       if (i == CS_SUCCESS)
-                               break;
-               }
-               i = next_tuple(link, &tuple, &parse);
-       }
-
-       if (i != CS_SUCCESS) {
-               cs_error(link, RequestIO, i);
+       link->resource[0]->end = 8;
+       ret = pcmcia_loop_config(link, dtl1_confcheck, NULL);
+       if (ret)
                goto failed;
-       }
-
-       i = pcmcia_request_irq(link, &link->irq);
-       if (i != CS_SUCCESS) {
-               cs_error(link, RequestIRQ, i);
-               link->irq.AssignedIRQ = 0;
-       }
 
-       i = pcmcia_request_configuration(link, &link->conf);
-       if (i != CS_SUCCESS) {
-               cs_error(link, RequestConfiguration, i);
+       ret = pcmcia_request_irq(link, dtl1_interrupt);
+       if (ret)
                goto failed;
-       }
 
-       if (dtl1_open(info) != 0)
+       ret = pcmcia_enable_device(link);
+       if (ret)
                goto failed;
 
-       strcpy(info->node.dev_name, info->hdev->name);
-       link->dev_node = &info->node;
+       ret = dtl1_open(info);
+       if (ret)
+               goto failed;
 
        return 0;
 
 failed:
-       dtl1_release(link);
-       return -ENODEV;
+       dtl1_detach(link);
+       return ret;
 }
 
-
-static void dtl1_release(struct pcmcia_device *link)
-{
-       dtl1_info_t *info = link->priv;
-
-       dtl1_close(info);
-
-       pcmcia_disable_device(link);
-}
-
-
-static struct pcmcia_device_id dtl1_ids[] = {
+static const struct pcmcia_device_id dtl1_ids[] = {
        PCMCIA_DEVICE_PROD_ID12("Nokia Mobile Phones", "DTL-1", 0xe1bfdd64, 0xe168480d),
        PCMCIA_DEVICE_PROD_ID12("Nokia Mobile Phones", "DTL-4", 0xe1bfdd64, 0x9102bc82),
        PCMCIA_DEVICE_PROD_ID12("Socket", "CF", 0xb38bcc2e, 0x44ebf863),
@@ -698,9 +623,7 @@ MODULE_DEVICE_TABLE(pcmcia, dtl1_ids);
 
 static struct pcmcia_driver dtl1_driver = {
        .owner          = THIS_MODULE,
-       .drv            = {
-               .name   = "dtl1_cs",
-       },
+       .name           = "dtl1_cs",
        .probe          = dtl1_probe,
        .remove         = dtl1_detach,
        .id_table       = dtl1_ids,