Version:  2.0.40 2.2.26 2.4.37 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19 4.0 4.1 4.2 4.3 4.4

Linux/drivers/usb/misc/ftdi-elan.c

  1 /*
  2  * USB FTDI client driver for Elan Digital Systems's Uxxx adapters
  3  *
  4  * Copyright(C) 2006 Elan Digital Systems Limited
  5  * http://www.elandigitalsystems.com
  6  *
  7  * Author and Maintainer - Tony Olech - Elan Digital Systems
  8  * tony.olech@elandigitalsystems.com
  9  *
 10  * This program is free software;you can redistribute it and/or
 11  * modify it under the terms of the GNU General Public License as
 12  * published by the Free Software Foundation, version 2.
 13  *
 14  *
 15  * This driver was written by Tony Olech(tony.olech@elandigitalsystems.com)
 16  * based on various USB client drivers in the 2.6.15 linux kernel
 17  * with constant reference to the 3rd Edition of Linux Device Drivers
 18  * published by O'Reilly
 19  *
 20  * The U132 adapter is a USB to CardBus adapter specifically designed
 21  * for PC cards that contain an OHCI host controller. Typical PC cards
 22  * are the Orange Mobile 3G Option GlobeTrotter Fusion card.
 23  *
 24  * The U132 adapter will *NOT *work with PC cards that do not contain
 25  * an OHCI controller. A simple way to test whether a PC card has an
 26  * OHCI controller as an interface is to insert the PC card directly
 27  * into a laptop(or desktop) with a CardBus slot and if "lspci" shows
 28  * a new USB controller and "lsusb -v" shows a new OHCI Host Controller
 29  * then there is a good chance that the U132 adapter will support the
 30  * PC card.(you also need the specific client driver for the PC card)
 31  *
 32  * Please inform the Author and Maintainer about any PC cards that
 33  * contain OHCI Host Controller and work when directly connected to
 34  * an embedded CardBus slot but do not work when they are connected
 35  * via an ELAN U132 adapter.
 36  *
 37  */
 38 
 39 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 40 
 41 #include <linux/kernel.h>
 42 #include <linux/errno.h>
 43 #include <linux/init.h>
 44 #include <linux/list.h>
 45 #include <linux/ioctl.h>
 46 #include <linux/pci_ids.h>
 47 #include <linux/slab.h>
 48 #include <linux/module.h>
 49 #include <linux/kref.h>
 50 #include <linux/mutex.h>
 51 #include <asm/uaccess.h>
 52 #include <linux/usb.h>
 53 #include <linux/workqueue.h>
 54 #include <linux/platform_device.h>
 55 MODULE_AUTHOR("Tony Olech");
 56 MODULE_DESCRIPTION("FTDI ELAN driver");
 57 MODULE_LICENSE("GPL");
 58 #define INT_MODULE_PARM(n, v) static int n = v;module_param(n, int, 0444)
 59 static bool distrust_firmware = 1;
 60 module_param(distrust_firmware, bool, 0);
 61 MODULE_PARM_DESC(distrust_firmware,
 62                  "true to distrust firmware power/overcurrent setup");
 63 extern struct platform_driver u132_platform_driver;
 64 static struct workqueue_struct *status_queue;
 65 static struct workqueue_struct *command_queue;
 66 static struct workqueue_struct *respond_queue;
 67 /*
 68  * ftdi_module_lock exists to protect access to global variables
 69  *
 70  */
 71 static struct mutex ftdi_module_lock;
 72 static int ftdi_instances = 0;
 73 static struct list_head ftdi_static_list;
 74 /*
 75  * end of the global variables protected by ftdi_module_lock
 76  */
 77 #include "usb_u132.h"
 78 #include <asm/io.h>
 79 #include <linux/usb/hcd.h>
 80 
 81 /* FIXME ohci.h is ONLY for internal use by the OHCI driver.
 82  * If you're going to try stuff like this, you need to split
 83  * out shareable stuff (register declarations?) into its own
 84  * file, maybe name <linux/usb/ohci.h>
 85  */
 86 
 87 #include "../host/ohci.h"
 88 /* Define these values to match your devices*/
 89 #define USB_FTDI_ELAN_VENDOR_ID 0x0403
 90 #define USB_FTDI_ELAN_PRODUCT_ID 0xd6ea
 91 /* table of devices that work with this driver*/
 92 static const struct usb_device_id ftdi_elan_table[] = {
 93         {USB_DEVICE(USB_FTDI_ELAN_VENDOR_ID, USB_FTDI_ELAN_PRODUCT_ID)},
 94         { /* Terminating entry */ }
 95 };
 96 
 97 MODULE_DEVICE_TABLE(usb, ftdi_elan_table);
 98 /* only the jtag(firmware upgrade device) interface requires
 99  * a device file and corresponding minor number, but the
100  * interface is created unconditionally - I suppose it could
101  * be configured or not according to a module parameter.
102  * But since we(now) require one interface per device,
103  * and since it unlikely that a normal installation would
104  * require more than a couple of elan-ftdi devices, 8 seems
105  * like a reasonable limit to have here, and if someone
106  * really requires more than 8 devices, then they can frig the
107  * code and recompile
108  */
109 #define USB_FTDI_ELAN_MINOR_BASE 192
110 #define COMMAND_BITS 5
111 #define COMMAND_SIZE (1<<COMMAND_BITS)
112 #define COMMAND_MASK (COMMAND_SIZE-1)
113 struct u132_command {
114         u8 header;
115         u16 length;
116         u8 address;
117         u8 width;
118         u32 value;
119         int follows;
120         void *buffer;
121 };
122 #define RESPOND_BITS 5
123 #define RESPOND_SIZE (1<<RESPOND_BITS)
124 #define RESPOND_MASK (RESPOND_SIZE-1)
125 struct u132_respond {
126         u8 header;
127         u8 address;
128         u32 *value;
129         int *result;
130         struct completion wait_completion;
131 };
132 struct u132_target {
133         void *endp;
134         struct urb *urb;
135         int toggle_bits;
136         int error_count;
137         int condition_code;
138         int repeat_number;
139         int halted;
140         int skipped;
141         int actual;
142         int non_null;
143         int active;
144         int abandoning;
145         void (*callback)(void *endp, struct urb *urb, u8 *buf, int len,
146                          int toggle_bits, int error_count, int condition_code,
147                          int repeat_number, int halted, int skipped, int actual,
148                          int non_null);
149 };
150 /* Structure to hold all of our device specific stuff*/
151 struct usb_ftdi {
152         struct list_head ftdi_list;
153         struct mutex u132_lock;
154         int command_next;
155         int command_head;
156         struct u132_command command[COMMAND_SIZE];
157         int respond_next;
158         int respond_head;
159         struct u132_respond respond[RESPOND_SIZE];
160         struct u132_target target[4];
161         char device_name[16];
162         unsigned synchronized:1;
163         unsigned enumerated:1;
164         unsigned registered:1;
165         unsigned initialized:1;