1 /*=====================================================
2 * CopyRight (C) 2007 Qualcomm Inc. All Rights Reserved.
5 * This file is part of Express Card USB Driver
8 *====================================================
10 #include <linux/init.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/usb.h>
14 #include <linux/netdevice.h>
15 #include <linux/etherdevice.h>
16 #include <linux/firmware.h>
17 #include "ft1000_usb.h"
19 #include <linux/kthread.h>
21 MODULE_DESCRIPTION("FT1000 EXPRESS CARD DRIVER");
22 MODULE_LICENSE("Dual MPL/GPL");
23 MODULE_SUPPORTED_DEVICE("QFT FT1000 Express Cards");
28 #define VENDOR_ID 0x1291 /* Qualcomm vendor id */
29 #define PRODUCT_ID 0x11 /* fake product id */
31 /* table of devices that work with this driver */
32 static struct usb_device_id id_table[] = {
33 {USB_DEVICE(VENDOR_ID, PRODUCT_ID)},
37 MODULE_DEVICE_TABLE(usb, id_table);
39 static BOOLEAN gPollingfailed = FALSE;
40 int ft1000_poll_thread(void *arg)
42 int ret = STATUS_SUCCESS;
44 while (!kthread_should_stop()) {
46 if (!gPollingfailed) {
47 ret = ft1000_poll(arg);
48 if (ret != STATUS_SUCCESS) {
49 DEBUG("ft1000_poll_thread: polling failed\n");
50 gPollingfailed = TRUE;
54 return STATUS_SUCCESS;
57 static int ft1000_probe(struct usb_interface *interface,
58 const struct usb_device_id *id)
60 struct usb_host_interface *iface_desc;
61 struct usb_endpoint_descriptor *endpoint;
62 struct usb_device *dev;
63 unsigned numaltsetting;
66 struct ft1000_device *ft1000dev;
67 struct ft1000_info *pft1000info;
68 const struct firmware *dsp_fw;
70 ft1000dev = kmalloc(sizeof(struct ft1000_device), GFP_KERNEL);
73 printk(KERN_ERR "out of memory allocating device structure\n");
77 memset(ft1000dev, 0, sizeof(*ft1000dev));
79 dev = interface_to_usbdev(interface);
80 DEBUG("ft1000_probe: usb device descriptor info:\n");
81 DEBUG("ft1000_probe: number of configuration is %d\n",
82 dev->descriptor.bNumConfigurations);
85 ft1000dev->status = 0;
86 ft1000dev->net = NULL;
87 spin_lock_init(&ft1000dev->device_lock);
88 ft1000dev->tx_urb = usb_alloc_urb(0, GFP_ATOMIC);
89 ft1000dev->rx_urb = usb_alloc_urb(0, GFP_ATOMIC);
91 DEBUG("ft1000_probe is called\n");
92 numaltsetting = interface->num_altsetting;
93 DEBUG("ft1000_probe: number of alt settings is :%d\n", numaltsetting);
94 iface_desc = interface->cur_altsetting;
95 DEBUG("ft1000_probe: number of endpoints is %d\n",
96 iface_desc->desc.bNumEndpoints);
97 DEBUG("ft1000_probe: descriptor type is %d\n",
98 iface_desc->desc.bDescriptorType);
99 DEBUG("ft1000_probe: interface number is %d\n",
100 iface_desc->desc.bInterfaceNumber);
101 DEBUG("ft1000_probe: alternatesetting is %d\n",
102 iface_desc->desc.bAlternateSetting);
103 DEBUG("ft1000_probe: interface class is %d\n",
104 iface_desc->desc.bInterfaceClass);
105 DEBUG("ft1000_probe: control endpoint info:\n");
106 DEBUG("ft1000_probe: descriptor0 type -- %d\n",
107 iface_desc->endpoint[0].desc.bmAttributes);
108 DEBUG("ft1000_probe: descriptor1 type -- %d\n",
109 iface_desc->endpoint[1].desc.bmAttributes);
110 DEBUG("ft1000_probe: descriptor2 type -- %d\n",
111 iface_desc->endpoint[2].desc.bmAttributes);
113 for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
115 (struct usb_endpoint_descriptor *)&iface_desc->
117 DEBUG("endpoint %d\n", i);
118 DEBUG("bEndpointAddress=%x, bmAttributes=%x\n",
119 endpoint->bEndpointAddress, endpoint->bmAttributes);
120 if ((endpoint->bEndpointAddress & USB_DIR_IN)
121 && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
122 USB_ENDPOINT_XFER_BULK)) {
123 ft1000dev->bulk_in_endpointAddr =
124 endpoint->bEndpointAddress;
125 DEBUG("ft1000_probe: in: %d\n",
126 endpoint->bEndpointAddress);
129 if (!(endpoint->bEndpointAddress & USB_DIR_IN)
130 && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
131 USB_ENDPOINT_XFER_BULK)) {
132 ft1000dev->bulk_out_endpointAddr =
133 endpoint->bEndpointAddress;
134 DEBUG("ft1000_probe: out: %d\n",
135 endpoint->bEndpointAddress);
139 DEBUG("bulk_in=%d, bulk_out=%d\n", ft1000dev->bulk_in_endpointAddr,
140 ft1000dev->bulk_out_endpointAddr);
142 ret = request_firmware(&dsp_fw, "ft3000.img", &dev->dev);
144 printk(KERN_ERR "Error request_firmware().\n");
148 size = max_t(uint, dsp_fw->size, 4096);
149 pFileStart = kmalloc(size, GFP_KERNEL);
152 release_firmware(dsp_fw);
157 memcpy(pFileStart, dsp_fw->data, dsp_fw->size);
158 FileLength = dsp_fw->size;
159 release_firmware(dsp_fw);
161 DEBUG("ft1000_probe: start downloading dsp image...\n");
163 ret = init_ft1000_netdev(ft1000dev);
167 pft1000info = (struct ft1000_info *) netdev_priv(ft1000dev->net);
169 DEBUG("In probe: pft1000info=%p\n", pft1000info);
170 ret = dsp_reload(ft1000dev);
172 printk(KERN_ERR "Problem with DSP image loading\n");
176 gPollingfailed = FALSE;
177 pft1000info->pPollThread =
178 kthread_run(ft1000_poll_thread, ft1000dev, "ft1000_poll");
181 while (!pft1000info->CardReady) {
182 if (gPollingfailed) {
183 if (pft1000info->pPollThread)
184 kthread_stop(pft1000info->pPollThread);
189 DEBUG("ft1000_probe::Waiting for Card Ready\n");
192 DEBUG("ft1000_probe::Card Ready!!!! Registering network device\n");
194 ret = reg_ft1000_netdev(ft1000dev, interface);
198 pft1000info->NetDevRegDone = 1;
200 ft1000InitProc(ft1000dev->net);
211 static void ft1000_disconnect(struct usb_interface *interface)
213 struct ft1000_info *pft1000info;
215 DEBUG("ft1000_disconnect is called\n");
217 pft1000info = (struct ft1000_info *) usb_get_intfdata(interface);
218 DEBUG("In disconnect pft1000info=%p\n", pft1000info);
221 ft1000CleanupProc(pft1000info);
222 if (pft1000info->pPollThread)
223 kthread_stop(pft1000info->pPollThread);
225 DEBUG("ft1000_disconnect: threads are terminated\n");
227 if (pft1000info->pFt1000Dev->net) {
228 DEBUG("ft1000_disconnect: destroy char driver\n");
229 ft1000_DestroyDevice(pft1000info->pFt1000Dev->net);
230 unregister_netdev(pft1000info->pFt1000Dev->net);
232 ("ft1000_disconnect: network device unregisterd\n");
233 free_netdev(pft1000info->pFt1000Dev->net);
237 usb_free_urb(pft1000info->pFt1000Dev->rx_urb);
238 usb_free_urb(pft1000info->pFt1000Dev->tx_urb);
240 DEBUG("ft1000_disconnect: urb freed\n");
242 kfree(pft1000info->pFt1000Dev);
249 static struct usb_driver ft1000_usb_driver = {
251 .probe = ft1000_probe,
252 .disconnect = ft1000_disconnect,
253 .id_table = id_table,
256 static int __init usb_ft1000_init(void)
260 DEBUG("Initialize and register the driver\n");
262 ret = usb_register(&ft1000_usb_driver);
264 err("usb_register failed. Error number %d", ret);
269 static void __exit usb_ft1000_exit(void)
271 DEBUG("Deregister the driver\n");
272 usb_deregister(&ft1000_usb_driver);
275 module_init(usb_ft1000_init);
276 module_exit(usb_ft1000_exit);