vserver 1.9.5.x5
[linux-2.6.git] / drivers / bluetooth / bt3c_cs.c
index 8cd5d0e..f71e5c7 100644 (file)
 #include <linux/module.h>
 
 #include <linux/kernel.h>
-#include <linux/kmod.h>
 #include <linux/init.h>
 #include <linux/slab.h>
-#include <linux/delay.h>
 #include <linux/types.h>
 #include <linux/sched.h>
+#include <linux/delay.h>
 #include <linux/errno.h>
 #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>
 /* ======================== 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");
@@ -96,14 +89,14 @@ 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 void bt3c_config(dev_link_t *link);
+static void bt3c_release(dev_link_t *link);
+static int bt3c_event(event_t event, int priority, event_callback_args_t *args);
 
 static dev_info_t dev_info = "bt3c_cs";
 
-dev_link_t *bt3c_attach(void);
-void bt3c_detach(dev_link_t *);
+static dev_link_t *bt3c_attach(void);
+static void bt3c_detach(dev_link_t *);
 
 static dev_link_t *dev_list = NULL;
 
@@ -132,28 +125,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);
 
@@ -163,7 +156,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);
 
@@ -194,10 +187,8 @@ static int bt3c_write(unsigned int iobase, int fifo_size, __u8 *buf, int len)
 }
 
 
-static void bt3c_write_wakeup(bt3c_info_t *info, int from)
+static void bt3c_write_wakeup(bt3c_info_t *info)
 {
-       unsigned long flags;
-
        if (!info) {
                BT_ERR("Unknown device");
                return;
@@ -206,8 +197,6 @@ static void bt3c_write_wakeup(bt3c_info_t *info, int from)
        if (test_and_set_bit(XMIT_SENDING, &(info->tx_state)))
                return;
 
-       spin_lock_irqsave(&(info->lock), flags);
-
        do {
                register unsigned int iobase = info->link.io.BasePort1;
                register struct sk_buff *skb;
@@ -234,8 +223,6 @@ static void bt3c_write_wakeup(bt3c_info_t *info, int from)
                info->hdev->stat.byte_tx += len;
 
        } while (0);
-
-       spin_unlock_irqrestore(&(info->lock), flags);
 }
 
 
@@ -391,7 +378,7 @@ static irqreturn_t bt3c_interrupt(int irq, void *dev_inst, struct pt_regs *regs)
                        if (stat & 0x0002) {
                                //BT_ERR("Ack (stat=0x%04x)", stat);
                                clear_bit(XMIT_SENDING, &(info->tx_state));
-                               bt3c_write_wakeup(info, 1);
+                               bt3c_write_wakeup(info);
                        }
 
                        bt3c_io_write(iobase, 0x7001, 0x0000);
@@ -444,6 +431,7 @@ static int bt3c_hci_send_frame(struct sk_buff *skb)
 {
        bt3c_info_t *info;
        struct hci_dev *hdev = (struct hci_dev *)(skb->dev);
+       unsigned long flags;
 
        if (!hdev) {
                BT_ERR("Frame for unknown HCI device (hdev=NULL)");
@@ -468,7 +456,11 @@ static int bt3c_hci_send_frame(struct sk_buff *skb)
        memcpy(skb_push(skb, 1), &(skb->pkt_type), 1);
        skb_queue_tail(&(info->txq), skb);
 
-       bt3c_write_wakeup(info, 0);
+       spin_lock_irqsave(&(info->lock), flags);
+
+       bt3c_write_wakeup(info);
+
+       spin_unlock_irqrestore(&(info->lock), flags);
 
        return 0;
 }
@@ -489,9 +481,16 @@ static int bt3c_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long
 /* ======================== Card services HCI interaction ======================== */
 
 
-static struct device bt3c_device = {
-       .bus_id = "pcmcia",
-};
+static struct device *bt3c_device(void)
+{
+       static struct device dev = {
+               .bus_id = "pcmcia",
+       };
+       kobject_set_name(&dev.kobj, "bt3c");
+       kobject_init(&dev.kobj);
+
+       return &dev;
+}
 
 
 static int bt3c_load_firmware(bt3c_info_t *info, unsigned char *firmware, int count)
@@ -578,7 +577,7 @@ error:
 }
 
 
-int bt3c_open(bt3c_info_t *info)
+static int bt3c_open(bt3c_info_t *info)
 {
        const struct firmware *firmware;
        struct hci_dev *hdev;
@@ -614,7 +613,7 @@ int bt3c_open(bt3c_info_t *info)
        hdev->owner = THIS_MODULE;
 
        /* Load firmware */
-       err = request_firmware(&firmware, "BT3CPCC.bin", &bt3c_device);
+       err = request_firmware(&firmware, "BT3CPCC.bin", bt3c_device());
        if (err < 0) {
                BT_ERR("Firmware request failed");
                goto error;
@@ -630,8 +629,7 @@ int bt3c_open(bt3c_info_t *info)
        }
 
        /* Timeout before it is safe to send the first HCI packet */
-       set_current_state(TASK_INTERRUPTIBLE);
-       schedule_timeout(HZ);
+       msleep(1000);
 
        /* Register HCI device */
        err = hci_register_dev(hdev);
@@ -649,7 +647,7 @@ error:
 }
 
 
-int bt3c_close(bt3c_info_t *info)
+static int bt3c_close(bt3c_info_t *info)
 {
        struct hci_dev *hdev = info->hdev;
 
@@ -666,12 +664,12 @@ int bt3c_close(bt3c_info_t *info)
        return 0;
 }
 
-dev_link_t *bt3c_attach(void)
+static dev_link_t *bt3c_attach(void)
 {
        bt3c_info_t *info;
        client_reg_t client_reg;
        dev_link_t *link;
-       int i, ret;
+       int ret;
 
        /* Create new info device */
        info = kmalloc(sizeof(*info), GFP_KERNEL);
@@ -685,13 +683,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;
@@ -704,7 +696,6 @@ dev_link_t *bt3c_attach(void)
        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 |
@@ -724,7 +715,7 @@ dev_link_t *bt3c_attach(void)
 }
 
 
-void bt3c_detach(dev_link_t *link)
+static void bt3c_detach(dev_link_t *link)
 {
        bt3c_info_t *info = link->priv;
        dev_link_t **linkp;
@@ -778,9 +769,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;
@@ -891,7 +882,7 @@ failed:
 }
 
 
-void bt3c_release(dev_link_t *link)
+static void bt3c_release(dev_link_t *link)
 {
        bt3c_info_t *info = link->priv;
 
@@ -908,7 +899,7 @@ void bt3c_release(dev_link_t *link)
 }
 
 
-int bt3c_event(event_t event, int priority, event_callback_args_t *args)
+static int bt3c_event(event_t event, int priority, event_callback_args_t *args)
 {
        dev_link_t *link = args->client_data;
        bt3c_info_t *info = link->priv;
@@ -962,10 +953,7 @@ 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);
+       BUG_ON(dev_list != NULL);
 }
 
 module_init(init_bt3c_cs);