Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / bluetooth / bluecard_cs.c
index e481cc4..473a13b 100644 (file)
@@ -40,7 +40,6 @@
 #include <linux/skbuff.h>
 #include <asm/io.h>
 
-#include <pcmcia/version.h>
 #include <pcmcia/cs_types.h>
 #include <pcmcia/cs.h>
 #include <pcmcia/cistpl.h>
@@ -66,7 +65,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;
@@ -86,16 +85,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 */
@@ -169,7 +162,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;
@@ -186,7 +179,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;
@@ -242,7 +235,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;
@@ -251,7 +244,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))) {
@@ -271,7 +264,7 @@ static void bluecard_write_wakeup(bluecard_info_t *info)
                if (!(skb = skb_dequeue(&(info->txq))))
                        break;
 
-               if (skb->pkt_type & 0x80) {
+               if (bt_cb(skb)->pkt_type & 0x80) {
                        /* Disable RTS */
                        info->ctrl_reg |= REG_CONTROL_RTS;
                        outb(info->ctrl_reg, iobase + REG_CONTROL);
@@ -289,13 +282,13 @@ static void bluecard_write_wakeup(bluecard_info_t *info)
                /* Mark the buffer as dirty */
                clear_bit(ready_bit, &(info->tx_state));
 
-               if (skb->pkt_type & 0x80) {
+               if (bt_cb(skb)->pkt_type & 0x80) {
                        DECLARE_WAIT_QUEUE_HEAD(wq);
                        DEFINE_WAIT(wait);
 
                        unsigned char baud_reg;
 
-                       switch (skb->pkt_type) {
+                       switch (bt_cb(skb)->pkt_type) {
                        case PKT_BAUD_RATE_460800:
                                baud_reg = REG_CONTROL_BAUD_RATE_460800;
                                break;
@@ -389,7 +382,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);
@@ -411,9 +404,9 @@ static void bluecard_receive(bluecard_info_t *info, unsigned int offset)
                if (info->rx_state == RECV_WAIT_PACKET_TYPE) {
 
                        info->rx_skb->dev = (void *) info->hdev;
-                       info->rx_skb->pkt_type = buf[i];
+                       bt_cb(info->rx_skb)->pkt_type = buf[i];
 
-                       switch (info->rx_skb->pkt_type) {
+                       switch (bt_cb(info->rx_skb)->pkt_type) {
 
                        case 0x00:
                                /* init packet */
@@ -445,7 +438,7 @@ static void bluecard_receive(bluecard_info_t *info, unsigned int offset)
 
                        default:
                                /* unknown packet */
-                               BT_ERR("Unknown HCI packet with type 0x%02x received", info->rx_skb->pkt_type);
+                               BT_ERR("Unknown HCI packet with type 0x%02x received", bt_cb(info->rx_skb)->pkt_type);
                                info->hdev->stat.err_rx++;
 
                                kfree_skb(info->rx_skb);
@@ -519,7 +512,7 @@ static irqreturn_t bluecard_interrupt(int irq, void *dev_inst, struct pt_regs *r
        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));
 
@@ -587,21 +580,21 @@ static int bluecard_hci_set_baud_rate(struct hci_dev *hdev, int baud)
        switch (baud) {
        case 460800:
                cmd[4] = 0x00;
-               skb->pkt_type = PKT_BAUD_RATE_460800;
+               bt_cb(skb)->pkt_type = PKT_BAUD_RATE_460800;
                break;
        case 230400:
                cmd[4] = 0x01;
-               skb->pkt_type = PKT_BAUD_RATE_230400;
+               bt_cb(skb)->pkt_type = PKT_BAUD_RATE_230400;
                break;
        case 115200:
                cmd[4] = 0x02;
-               skb->pkt_type = PKT_BAUD_RATE_115200;
+               bt_cb(skb)->pkt_type = PKT_BAUD_RATE_115200;
                break;
        case 57600:
                /* Fall through... */
        default:
                cmd[4] = 0x03;
-               skb->pkt_type = PKT_BAUD_RATE_57600;
+               bt_cb(skb)->pkt_type = PKT_BAUD_RATE_57600;
                break;
        }
 
@@ -633,7 +626,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);
@@ -653,7 +646,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;
@@ -681,7 +674,7 @@ static int bluecard_hci_send_frame(struct sk_buff *skb)
 
        info = (bluecard_info_t *)(hdev->driver_data);
 
-       switch (skb->pkt_type) {
+       switch (bt_cb(skb)->pkt_type) {
        case HCI_COMMAND_PKT:
                hdev->stat.cmd_tx++;
                break;
@@ -694,7 +687,7 @@ static int bluecard_hci_send_frame(struct sk_buff *skb)
        };
 
        /* Prepend skb with frame type */
-       memcpy(skb_push(skb, 1), &(skb->pkt_type), 1);
+       memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1);
        skb_queue_tail(&(info->txq), skb);
 
        bluecard_write_wakeup(info);
@@ -720,7 +713,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;
 
@@ -838,7 +831,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)
@@ -863,20 +856,16 @@ 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 = kmalloc(sizeof(*info), GFP_KERNEL);
+       info = kzalloc(sizeof(*info), GFP_KERNEL);
        if (!info)
-               return NULL;
-       memset(info, 0, sizeof(*info));
+               return -ENOMEM;
 
-       link = &info->link;
+       info->p_dev = link;
        link->priv = info;
 
        link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
@@ -888,63 +877,22 @@ static dev_link_t *bluecard_attach(void)
        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.EventMask =
-               CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
-               CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
-               CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
-       client_reg.event_handler = &bluecard_event;
-       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)
+static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
 {
        int i;
 
@@ -959,14 +907,12 @@ static int first_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse
        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;
@@ -976,7 +922,7 @@ static void bluecard_config(dev_link_t *link)
 
        /* Get configuration register information */
        tuple.DesiredTuple = CISTPL_CONFIG;
-       last_ret = first_tuple(handle, &tuple, &parse);
+       last_ret = first_tuple(link, &tuple, &parse);
        if (last_ret != CS_SUCCESS) {
                last_fn = ParseTuple;
                goto cs_failed;
@@ -984,36 +930,31 @@ static void bluecard_config(dev_link_t *link)
        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;
-
        link->conf.ConfigIndex = 0x20;
        link->io.NumPorts1 = 64;
        link->io.IOAddrLines = 6;
 
        for (n = 0; n < 0x400; n += 0x40) {
                link->io.BasePort1 = n ^ 0x300;
-               i = pcmcia_request_io(link->handle, &link->io);
+               i = pcmcia_request_io(link, &link->io);
                if (i == CS_SUCCESS)
                        break;
        }
 
        if (i != CS_SUCCESS) {
-               cs_error(link->handle, RequestIO, i);
+               cs_error(link, RequestIO, i);
                goto failed;
        }
 
-       i = pcmcia_request_irq(link->handle, &link->irq);
+       i = pcmcia_request_irq(link, &link->irq);
        if (i != CS_SUCCESS) {
-               cs_error(link->handle, RequestIRQ, i);
+               cs_error(link, RequestIRQ, i);
                link->irq.AssignedIRQ = 0;
        }
 
-       i = pcmcia_request_configuration(link->handle, &link->conf);
+       i = pcmcia_request_configuration(link, &link->conf);
        if (i != CS_SUCCESS) {
-               cs_error(link->handle, RequestConfiguration, i);
+               cs_error(link, RequestConfiguration, i);
                goto failed;
        }
 
@@ -1021,81 +962,46 @@ 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;
+       link->dev_node = &info->node;
 
-       return;
+       return 0;
 
 cs_failed:
-       cs_error(link->handle, last_fn, last_ret);
+       cs_error(link, last_fn, last_ret);
 
 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;
+       pcmcia_disable_device(link);
 }
 
-
-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;
-       case CS_EVENT_PM_SUSPEND:
-               link->state |= DEV_SUSPEND;
-               /* Fall through... */
-       case CS_EVENT_RESET_PHYSICAL:
-               if (link->state & DEV_CONFIG)
-                       pcmcia_release_configuration(link->handle);
-               break;
-       case CS_EVENT_PM_RESUME:
-               link->state &= ~DEV_SUSPEND;
-               /* Fall through... */
-       case CS_EVENT_CARD_RESET:
-               if (DEV_OK(link))
-                       pcmcia_request_configuration(link->handle, &link->conf);
-               break;
-       }
-
-       return 0;
-}
+static struct pcmcia_device_id bluecard_ids[] = {
+       PCMCIA_DEVICE_PROD_ID12("BlueCard", "LSE041", 0xbaf16fbf, 0x657cc15e),
+       PCMCIA_DEVICE_PROD_ID12("BTCFCARD", "LSE139", 0xe3987764, 0x2524b59c),
+       PCMCIA_DEVICE_PROD_ID12("WSS", "LSE039", 0x0a0736ec, 0x24e6dfab),
+       PCMCIA_DEVICE_NULL
+};
+MODULE_DEVICE_TABLE(pcmcia, bluecard_ids);
 
 static struct pcmcia_driver bluecard_driver = {
        .owner          = THIS_MODULE,
        .drv            = {
                .name   = "bluecard_cs",
        },
-       .attach         = bluecard_attach,
-       .detach         = bluecard_detach,
+       .probe          = bluecard_probe,
+       .remove         = bluecard_detach,
+       .id_table       = bluecard_ids,
 };
 
 static int __init init_bluecard_cs(void)
@@ -1107,7 +1013,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);