Bluetooth: Add debugfs support to btmrvl driver
[linux-2.6.git] / drivers / bluetooth / bluecard_cs.c
index 5b24131..b0e569b 100644 (file)
@@ -20,7 +20,6 @@
  *
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 
 #include <linux/kernel.h>
@@ -65,7 +64,7 @@ MODULE_LICENSE("GPL");
 
 
 typedef struct bluecard_info_t {
-       dev_link_t link;
+       struct pcmcia_device *p_dev;
        dev_node_t node;
 
        struct hci_dev *hdev;
@@ -85,16 +84,10 @@ typedef struct bluecard_info_t {
 } bluecard_info_t;
 
 
-static void bluecard_config(dev_link_t *link);
-static void bluecard_release(dev_link_t *link);
-static int bluecard_event(event_t event, int priority, event_callback_args_t *args);
+static int bluecard_config(struct pcmcia_device *link);
+static void bluecard_release(struct pcmcia_device *link);
 
-static dev_info_t dev_info = "bluecard_cs";
-
-static dev_link_t *bluecard_attach(void);
-static void bluecard_detach(dev_link_t *);
-
-static dev_link_t *dev_list = NULL;
+static void bluecard_detach(struct pcmcia_device *p_dev);
 
 
 /* Default baud rate: 57600, 115200, 230400 or 460800 */
@@ -168,7 +161,7 @@ static dev_link_t *dev_list = NULL;
 static void bluecard_activity_led_timeout(u_long arg)
 {
        bluecard_info_t *info = (bluecard_info_t *)arg;
-       unsigned int iobase = info->link.io.BasePort1;
+       unsigned int iobase = info->p_dev->io.BasePort1;
 
        if (!test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state)))
                return;
@@ -185,7 +178,7 @@ static void bluecard_activity_led_timeout(u_long arg)
 
 static void bluecard_enable_activity_led(bluecard_info_t *info)
 {
-       unsigned int iobase = info->link.io.BasePort1;
+       unsigned int iobase = info->p_dev->io.BasePort1;
 
        if (!test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state)))
                return;
@@ -241,7 +234,7 @@ static void bluecard_write_wakeup(bluecard_info_t *info)
        }
 
        do {
-               register unsigned int iobase = info->link.io.BasePort1;
+               register unsigned int iobase = info->p_dev->io.BasePort1;
                register unsigned int offset;
                register unsigned char command;
                register unsigned long ready_bit;
@@ -250,7 +243,7 @@ static void bluecard_write_wakeup(bluecard_info_t *info)
 
                clear_bit(XMIT_WAKEUP, &(info->tx_state));
 
-               if (!(info->link.state & DEV_PRESENT))
+               if (!pcmcia_dev_present(info->p_dev))
                        return;
 
                if (test_bit(XMIT_BUFFER_NUMBER, &(info->tx_state))) {
@@ -289,7 +282,7 @@ static void bluecard_write_wakeup(bluecard_info_t *info)
                clear_bit(ready_bit, &(info->tx_state));
 
                if (bt_cb(skb)->pkt_type & 0x80) {
-                       DECLARE_WAIT_QUEUE_HEAD(wq);
+                       DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
                        DEFINE_WAIT(wait);
 
                        unsigned char baud_reg;
@@ -388,7 +381,7 @@ static void bluecard_receive(bluecard_info_t *info, unsigned int offset)
                return;
        }
 
-       iobase = info->link.io.BasePort1;
+       iobase = info->p_dev->io.BasePort1;
 
        if (test_bit(XMIT_SENDING_READY, &(info->tx_state)))
                bluecard_enable_activity_led(info);
@@ -468,20 +461,20 @@ static void bluecard_receive(bluecard_info_t *info, unsigned int offset)
                                switch (info->rx_state) {
 
                                case RECV_WAIT_EVENT_HEADER:
-                                       eh = (struct hci_event_hdr *)(info->rx_skb->data);
+                                       eh = hci_event_hdr(info->rx_skb);
                                        info->rx_state = RECV_WAIT_DATA;
                                        info->rx_count = eh->plen;
                                        break;
 
                                case RECV_WAIT_ACL_HEADER:
-                                       ah = (struct hci_acl_hdr *)(info->rx_skb->data);
+                                       ah = hci_acl_hdr(info->rx_skb);
                                        dlen = __le16_to_cpu(ah->dlen);
                                        info->rx_state = RECV_WAIT_DATA;
                                        info->rx_count = dlen;
                                        break;
 
                                case RECV_WAIT_SCO_HEADER:
-                                       sh = (struct hci_sco_hdr *)(info->rx_skb->data);
+                                       sh = hci_sco_hdr(info->rx_skb);
                                        info->rx_state = RECV_WAIT_DATA;
                                        info->rx_count = sh->dlen;
                                        break;
@@ -504,21 +497,18 @@ static void bluecard_receive(bluecard_info_t *info, unsigned int offset)
 }
 
 
-static irqreturn_t bluecard_interrupt(int irq, void *dev_inst, struct pt_regs *regs)
+static irqreturn_t bluecard_interrupt(int irq, void *dev_inst)
 {
        bluecard_info_t *info = dev_inst;
        unsigned int iobase;
        unsigned char reg;
 
-       if (!info || !info->hdev) {
-               BT_ERR("Call of irq %d for unknown device", irq);
-               return IRQ_NONE;
-       }
+       BUG_ON(!info->hdev);
 
        if (!test_bit(CARD_READY, &(info->hw_state)))
                return IRQ_HANDLED;
 
-       iobase = info->link.io.BasePort1;
+       iobase = info->p_dev->io.BasePort1;
 
        spin_lock(&(info->lock));
 
@@ -632,7 +622,7 @@ static int bluecard_hci_flush(struct hci_dev *hdev)
 static int bluecard_hci_open(struct hci_dev *hdev)
 {
        bluecard_info_t *info = (bluecard_info_t *)(hdev->driver_data);
-       unsigned int iobase = info->link.io.BasePort1;
+       unsigned int iobase = info->p_dev->io.BasePort1;
 
        if (test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state)))
                bluecard_hci_set_baud_rate(hdev, DEFAULT_BAUD_RATE);
@@ -652,7 +642,7 @@ static int bluecard_hci_open(struct hci_dev *hdev)
 static int bluecard_hci_close(struct hci_dev *hdev)
 {
        bluecard_info_t *info = (bluecard_info_t *)(hdev->driver_data);
-       unsigned int iobase = info->link.io.BasePort1;
+       unsigned int iobase = info->p_dev->io.BasePort1;
 
        if (!test_and_clear_bit(HCI_RUNNING, &(hdev->flags)))
                return 0;
@@ -719,7 +709,7 @@ static int bluecard_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned l
 
 static int bluecard_open(bluecard_info_t *info)
 {
-       unsigned int iobase = info->link.io.BasePort1;
+       unsigned int iobase = info->p_dev->io.BasePort1;
        struct hci_dev *hdev;
        unsigned char id;
 
@@ -746,6 +736,7 @@ static int bluecard_open(bluecard_info_t *info)
 
        hdev->type = HCI_PCCARD;
        hdev->driver_data = info;
+       SET_HCIDEV_DEV(hdev, &info->p_dev->dev);
 
        hdev->open     = bluecard_hci_open;
        hdev->close    = bluecard_hci_close;
@@ -837,7 +828,7 @@ static int bluecard_open(bluecard_info_t *info)
 
 static int bluecard_close(bluecard_info_t *info)
 {
-       unsigned int iobase = info->link.io.BasePort1;
+       unsigned int iobase = info->p_dev->io.BasePort1;
        struct hci_dev *hdev = info->hdev;
 
        if (!hdev)
@@ -862,125 +853,46 @@ static int bluecard_close(bluecard_info_t *info)
        return 0;
 }
 
-static dev_link_t *bluecard_attach(void)
+static int bluecard_probe(struct pcmcia_device *link)
 {
        bluecard_info_t *info;
-       client_reg_t client_reg;
-       dev_link_t *link;
-       int ret;
 
        /* Create new info device */
        info = kzalloc(sizeof(*info), GFP_KERNEL);
        if (!info)
-               return NULL;
+               return -ENOMEM;
 
-       link = &info->link;
+       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.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT;
        link->irq.IRQInfo1 = IRQ_LEVEL_ID;
 
        link->irq.Handler = bluecard_interrupt;
        link->irq.Instance = info;
 
        link->conf.Attributes = CONF_ENABLE_IRQ;
-       link->conf.Vcc = 50;
        link->conf.IntType = INT_MEMORY_AND_IO;
 
-       /* Register with Card Services */
-       link->next = dev_list;
-       dev_list = link;
-       client_reg.dev_info = &dev_info;
-       client_reg.Version = 0x0210;
-       client_reg.event_callback_args.client_data = link;
-
-       ret = pcmcia_register_client(&link->handle, &client_reg);
-       if (ret != CS_SUCCESS) {
-               cs_error(link->handle, RegisterClient, ret);
-               bluecard_detach(link);
-               return NULL;
-       }
-
-       return link;
+       return bluecard_config(link);
 }
 
 
-static void bluecard_detach(dev_link_t *link)
+static void bluecard_detach(struct pcmcia_device *link)
 {
        bluecard_info_t *info = link->priv;
-       dev_link_t **linkp;
-       int ret;
-
-       /* Locate device structure */
-       for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
-               if (*linkp == link)
-                       break;
-
-       if (*linkp == NULL)
-               return;
-
-       if (link->state & DEV_CONFIG)
-               bluecard_release(link);
-
-       if (link->handle) {
-               ret = pcmcia_deregister_client(link->handle);
-               if (ret != CS_SUCCESS)
-                       cs_error(link->handle, DeregisterClient, ret);
-       }
-
-       /* Unlink device structure, free bits */
-       *linkp = link->next;
 
+       bluecard_release(link);
        kfree(info);
 }
 
 
-static int first_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
-{
-       int i;
-
-       i = pcmcia_get_first_tuple(handle, tuple);
-       if (i != CS_SUCCESS)
-               return CS_NO_MORE_ITEMS;
-
-       i = pcmcia_get_tuple_data(handle, tuple);
-       if (i != CS_SUCCESS)
-               return i;
-
-       return pcmcia_parse_tuple(handle, tuple, parse);
-}
-
-static void bluecard_config(dev_link_t *link)
+static int bluecard_config(struct pcmcia_device *link)
 {
-       client_handle_t handle = link->handle;
        bluecard_info_t *info = link->priv;
-       tuple_t tuple;
-       u_short buf[256];
-       cisparse_t parse;
-       config_info_t config;
-       int i, n, last_ret, last_fn;
-
-       tuple.TupleData = (cisdata_t *)buf;
-       tuple.TupleOffset = 0;
-       tuple.TupleDataMax = 255;
-       tuple.Attributes = 0;
-
-       /* Get configuration register information */
-       tuple.DesiredTuple = CISTPL_CONFIG;
-       last_ret = first_tuple(handle, &tuple, &parse);
-       if (last_ret != CS_SUCCESS) {
-               last_fn = ParseTuple;
-               goto cs_failed;
-       }
-       link->conf.ConfigBase = parse.config.base;
-       link->conf.Present = parse.config.rmask[0];
-
-       /* Configure card */
-       link->state |= DEV_CONFIG;
-       i = pcmcia_get_configuration_info(handle, &config);
-       link->conf.Vcc = config.Vcc;
+       int i, n;
 
        link->conf.ConfigIndex = 0x20;
        link->io.NumPorts1 = 64;
@@ -988,25 +900,25 @@ static void bluecard_config(dev_link_t *link)
 
        for (n = 0; n < 0x400; n += 0x40) {
                link->io.BasePort1 = n ^ 0x300;
-               i = pcmcia_request_io(link->handle, &link->io);
-               if (i == CS_SUCCESS)
+               i = pcmcia_request_io(link, &link->io);
+               if (i == 0)
                        break;
        }
 
-       if (i != CS_SUCCESS) {
-               cs_error(link->handle, RequestIO, i);
+       if (i != 0) {
+               cs_error(link, RequestIO, i);
                goto failed;
        }
 
-       i = pcmcia_request_irq(link->handle, &link->irq);
-       if (i != CS_SUCCESS) {
-               cs_error(link->handle, RequestIRQ, i);
+       i = pcmcia_request_irq(link, &link->irq);
+       if (i != 0) {
+               cs_error(link, RequestIRQ, i);
                link->irq.AssignedIRQ = 0;
        }
 
-       i = pcmcia_request_configuration(link->handle, &link->conf);
-       if (i != CS_SUCCESS) {
-               cs_error(link->handle, RequestConfiguration, i);
+       i = pcmcia_request_configuration(link, &link->conf);
+       if (i != 0) {
+               cs_error(link, RequestConfiguration, i);
                goto failed;
        }
 
@@ -1014,79 +926,25 @@ static void bluecard_config(dev_link_t *link)
                goto failed;
 
        strcpy(info->node.dev_name, info->hdev->name);
-       link->dev = &info->node;
-       link->state &= ~DEV_CONFIG_PENDING;
-
-       return;
+       link->dev_node = &info->node;
 
-cs_failed:
-       cs_error(link->handle, last_fn, last_ret);
+       return 0;
 
 failed:
        bluecard_release(link);
+       return -ENODEV;
 }
 
 
-static void bluecard_release(dev_link_t *link)
+static void bluecard_release(struct pcmcia_device *link)
 {
        bluecard_info_t *info = link->priv;
 
-       if (link->state & DEV_PRESENT)
-               bluecard_close(info);
+       bluecard_close(info);
 
        del_timer(&(info->timer));
 
-       link->dev = NULL;
-
-       pcmcia_release_configuration(link->handle);
-       pcmcia_release_io(link->handle, &link->io);
-       pcmcia_release_irq(link->handle, &link->irq);
-
-       link->state &= ~DEV_CONFIG;
-}
-
-static int bluecard_suspend(struct pcmcia_device *dev)
-{
-       dev_link_t *link = dev_to_instance(dev);
-
-       link->state |= DEV_SUSPEND;
-       if (link->state & DEV_CONFIG)
-               pcmcia_release_configuration(link->handle);
-
-       return 0;
-}
-
-static int bluecard_resume(struct pcmcia_device *dev)
-{
-       dev_link_t *link = dev_to_instance(dev);
-
-       link->state &= ~DEV_SUSPEND;
-       if (DEV_OK(link))
-               pcmcia_request_configuration(link->handle, &link->conf);
-
-       return 0;
-}
-
-static int bluecard_event(event_t event, int priority, event_callback_args_t *args)
-{
-       dev_link_t *link = args->client_data;
-       bluecard_info_t *info = link->priv;
-
-       switch (event) {
-       case CS_EVENT_CARD_REMOVAL:
-               link->state &= ~DEV_PRESENT;
-               if (link->state & DEV_CONFIG) {
-                       bluecard_close(info);
-                       bluecard_release(link);
-               }
-               break;
-       case CS_EVENT_CARD_INSERTION:
-               link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
-               bluecard_config(link);
-               break;
-       }
-
-       return 0;
+       pcmcia_disable_device(link);
 }
 
 static struct pcmcia_device_id bluecard_ids[] = {
@@ -1102,12 +960,9 @@ static struct pcmcia_driver bluecard_driver = {
        .drv            = {
                .name   = "bluecard_cs",
        },
-       .attach         = bluecard_attach,
-       .event          = bluecard_event,
-       .detach         = bluecard_detach,
+       .probe          = bluecard_probe,
+       .remove         = bluecard_detach,
        .id_table       = bluecard_ids,
-       .suspend        = bluecard_suspend,
-       .resume         = bluecard_resume,
 };
 
 static int __init init_bluecard_cs(void)
@@ -1119,7 +974,6 @@ static int __init init_bluecard_cs(void)
 static void __exit exit_bluecard_cs(void)
 {
        pcmcia_unregister_driver(&bluecard_driver);
-       BUG_ON(dev_list != NULL);
 }
 
 module_init(init_bluecard_cs);