linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / bluetooth / bt3c_cs.c
index d67d038..7e21b1f 100644 (file)
 #include <linux/ptrace.h>
 #include <linux/ioport.h>
 #include <linux/spinlock.h>
+#include <linux/moduleparam.h>
 
 #include <linux/skbuff.h>
 #include <linux/string.h>
 #include <linux/serial.h>
 #include <linux/serial_reg.h>
+#include <linux/bitops.h>
 #include <asm/system.h>
-#include <asm/bitops.h>
 #include <asm/io.h>
 
 #include <linux/device.h>
 #include <linux/firmware.h>
 
-#include <pcmcia/version.h>
 #include <pcmcia/cs_types.h>
 #include <pcmcia/cs.h>
 #include <pcmcia/cistpl.h>
 /* ======================== Module parameters ======================== */
 
 
-/* Bit map of interrupts to choose from */
-static u_int irq_mask = 0xffff;
-static int irq_list[4] = { -1 };
-
-MODULE_PARM(irq_mask, "i");
-MODULE_PARM(irq_list, "1-4i");
-
 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>, Jose Orlando Pereira <jop@di.uminho.pt>");
 MODULE_DESCRIPTION("Bluetooth driver for the 3Com Bluetooth PCMCIA card");
 MODULE_LICENSE("GPL");
@@ -95,16 +88,10 @@ typedef struct bt3c_info_t {
 } bt3c_info_t;
 
 
-void bt3c_config(dev_link_t *link);
-void bt3c_release(dev_link_t *link);
-int bt3c_event(event_t event, int priority, event_callback_args_t *args);
-
-static dev_info_t dev_info = "bt3c_cs";
+static void bt3c_config(dev_link_t *link);
+static void bt3c_release(dev_link_t *link);
 
-dev_link_t *bt3c_attach(void);
-void bt3c_detach(dev_link_t *);
-
-static dev_link_t *dev_list = NULL;
+static void bt3c_detach(struct pcmcia_device *p_dev);
 
 
 /* Transmit states  */
@@ -131,28 +118,28 @@ static dev_link_t *dev_list = NULL;
 #define CONTROL  4
 
 
-inline void bt3c_address(unsigned int iobase, unsigned short addr)
+static inline void bt3c_address(unsigned int iobase, unsigned short addr)
 {
        outb(addr & 0xff, iobase + ADDR_L);
        outb((addr >> 8) & 0xff, iobase + ADDR_H);
 }
 
 
-inline void bt3c_put(unsigned int iobase, unsigned short value)
+static inline void bt3c_put(unsigned int iobase, unsigned short value)
 {
        outb(value & 0xff, iobase + DATA_L);
        outb((value >> 8) & 0xff, iobase + DATA_H);
 }
 
 
-inline void bt3c_io_write(unsigned int iobase, unsigned short addr, unsigned short value)
+static inline void bt3c_io_write(unsigned int iobase, unsigned short addr, unsigned short value)
 {
        bt3c_address(iobase, addr);
        bt3c_put(iobase, value);
 }
 
 
-inline unsigned short bt3c_get(unsigned int iobase)
+static inline unsigned short bt3c_get(unsigned int iobase)
 {
        unsigned short value = inb(iobase + DATA_L);
 
@@ -162,7 +149,7 @@ inline unsigned short bt3c_get(unsigned int iobase)
 }
 
 
-inline unsigned short bt3c_read(unsigned int iobase, unsigned short addr)
+static inline unsigned short bt3c_read(unsigned int iobase, unsigned short addr)
 {
        bt3c_address(iobase, addr);
 
@@ -266,11 +253,11 @@ static void bt3c_receive(bt3c_info_t *info)
                if (info->rx_state == RECV_WAIT_PACKET_TYPE) {
 
                        info->rx_skb->dev = (void *) info->hdev;
-                       info->rx_skb->pkt_type = inb(iobase + DATA_L);
+                       bt_cb(info->rx_skb)->pkt_type = inb(iobase + DATA_L);
                        inb(iobase + DATA_H);
-                       //printk("bt3c: PACKET_TYPE=%02x\n", info->rx_skb->pkt_type);
+                       //printk("bt3c: PACKET_TYPE=%02x\n", bt_cb(info->rx_skb)->pkt_type);
 
-                       switch (info->rx_skb->pkt_type) {
+                       switch (bt_cb(info->rx_skb)->pkt_type) {
 
                        case HCI_EVENT_PKT:
                                info->rx_state = RECV_WAIT_EVENT_HEADER;
@@ -289,7 +276,7 @@ static void bt3c_receive(bt3c_info_t *info)
 
                        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++;
                                clear_bit(HCI_RUNNING, &(info->hdev->flags));
 
@@ -446,7 +433,7 @@ static int bt3c_hci_send_frame(struct sk_buff *skb)
 
        info = (bt3c_info_t *) (hdev->driver_data);
 
-       switch (skb->pkt_type) {
+       switch (bt_cb(skb)->pkt_type) {
        case HCI_COMMAND_PKT:
                hdev->stat.cmd_tx++;
                break;
@@ -459,7 +446,7 @@ static int bt3c_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);
 
        spin_lock_irqsave(&(info->lock), flags);
@@ -487,21 +474,6 @@ static int bt3c_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long
 /* ======================== Card services HCI interaction ======================== */
 
 
-static struct device *bt3c_device(void)
-{
-       static char *kobj_name = "bt3c";
-
-       static struct device dev = {
-               .bus_id = "pcmcia",
-       };
-       dev.kobj.k_name = kmalloc(strlen(kobj_name) + 1, GFP_KERNEL);
-       strcpy(dev.kobj.k_name, kobj_name);
-       kobject_init(&dev.kobj);
-
-       return &dev;
-}
-
-
 static int bt3c_load_firmware(bt3c_info_t *info, unsigned char *firmware, int count)
 {
        char *ptr = (char *) firmware;
@@ -586,10 +558,11 @@ error:
 }
 
 
-int bt3c_open(bt3c_info_t *info)
+static int bt3c_open(bt3c_info_t *info)
 {
        const struct firmware *firmware;
        struct hci_dev *hdev;
+       client_handle_t handle;
        int err;
 
        spin_lock_init(&(info->lock));
@@ -621,8 +594,10 @@ int bt3c_open(bt3c_info_t *info)
 
        hdev->owner = THIS_MODULE;
 
+       handle = info->link.handle;
+
        /* Load firmware */
-       err = request_firmware(&firmware, "BT3CPCC.bin", bt3c_device());
+       err = request_firmware(&firmware, "BT3CPCC.bin", &handle_to_dev(handle));
        if (err < 0) {
                BT_ERR("Firmware request failed");
                goto error;
@@ -656,7 +631,7 @@ error:
 }
 
 
-int bt3c_close(bt3c_info_t *info)
+static int bt3c_close(bt3c_info_t *info)
 {
        struct hci_dev *hdev = info->hdev;
 
@@ -673,18 +648,15 @@ int bt3c_close(bt3c_info_t *info)
        return 0;
 }
 
-dev_link_t *bt3c_attach(void)
+static int bt3c_attach(struct pcmcia_device *p_dev)
 {
        bt3c_info_t *info;
-       client_reg_t client_reg;
        dev_link_t *link;
-       int i, 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;
        link->priv = info;
@@ -692,13 +664,7 @@ dev_link_t *bt3c_attach(void)
        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_INFO2_VALID | IRQ_LEVEL_ID;
-
-       if (irq_list[0] == -1)
-               link->irq.IRQInfo2 = irq_mask;
-       else
-               for (i = 0; i < 4; i++)
-                       link->irq.IRQInfo2 |= 1 << irq_list[i];
+       link->irq.IRQInfo1 = IRQ_LEVEL_ID;
 
        link->irq.Handler = bt3c_interrupt;
        link->irq.Instance = info;
@@ -707,56 +673,24 @@ dev_link_t *bt3c_attach(void)
        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.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
-       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 = &bt3c_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);
-               bt3c_detach(link);
-               return NULL;
-       }
+       link->handle = p_dev;
+       p_dev->instance = link;
+
+       link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
+       bt3c_config(link);
 
-       return link;
+       return 0;
 }
 
 
-void bt3c_detach(dev_link_t *link)
+static void bt3c_detach(struct pcmcia_device *p_dev)
 {
+       dev_link_t *link = dev_to_instance(p_dev);
        bt3c_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)
                bt3c_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;
-
        kfree(info);
 }
 
@@ -785,9 +719,9 @@ static int next_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
        return get_tuple(handle, tuple, parse);
 }
 
-void bt3c_config(dev_link_t *link)
+static void bt3c_config(dev_link_t *link)
 {
-       static ioaddr_t base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
+       static kio_addr_t base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
        client_handle_t handle = link->handle;
        bt3c_info_t *info = link->priv;
        tuple_t tuple;
@@ -898,7 +832,7 @@ failed:
 }
 
 
-void bt3c_release(dev_link_t *link)
+static void bt3c_release(dev_link_t *link)
 {
        bt3c_info_t *info = link->priv;
 
@@ -914,50 +848,45 @@ void bt3c_release(dev_link_t *link)
        link->state &= ~DEV_CONFIG;
 }
 
+static int bt3c_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);
 
-int bt3c_event(event_t event, int priority, event_callback_args_t *args)
+       return 0;
+}
+
+static int bt3c_resume(struct pcmcia_device *dev)
 {
-       dev_link_t *link = args->client_data;
-       bt3c_info_t *info = link->priv;
+       dev_link_t *link = dev_to_instance(dev);
 
-       switch (event) {
-       case CS_EVENT_CARD_REMOVAL:
-               link->state &= ~DEV_PRESENT;
-               if (link->state & DEV_CONFIG) {
-                       bt3c_close(info);
-                       bt3c_release(link);
-               }
-               break;
-       case CS_EVENT_CARD_INSERTION:
-               link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
-               bt3c_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;
-       }
+       link->state &= ~DEV_SUSPEND;
+       if (DEV_OK(link))
+               pcmcia_request_configuration(link->handle, &link->conf);
 
        return 0;
 }
 
+
+static struct pcmcia_device_id bt3c_ids[] = {
+       PCMCIA_DEVICE_PROD_ID13("3COM", "Bluetooth PC Card", 0xefce0a31, 0xd4ce9b02),
+       PCMCIA_DEVICE_NULL
+};
+MODULE_DEVICE_TABLE(pcmcia, bt3c_ids);
+
 static struct pcmcia_driver bt3c_driver = {
        .owner          = THIS_MODULE,
        .drv            = {
                .name   = "bt3c_cs",
        },
-       .attach         = bt3c_attach,
-       .detach         = bt3c_detach,
+       .probe          = bt3c_attach,
+       .remove         = bt3c_detach,
+       .id_table       = bt3c_ids,
+       .suspend        = bt3c_suspend,
+       .resume         = bt3c_resume,
 };
 
 static int __init init_bt3c_cs(void)
@@ -969,10 +898,6 @@ static int __init init_bt3c_cs(void)
 static void __exit exit_bt3c_cs(void)
 {
        pcmcia_unregister_driver(&bt3c_driver);
-
-       /* XXX: this really needs to move into generic code.. */
-       while (dev_list != NULL)
-               bt3c_detach(dev_list);
 }
 
 module_init(init_bt3c_cs);