staging/ft1000-usb: fix problems found by sparse
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / ft1000 / ft1000-usb / ft1000_usb.c
blob4aef1c43e61f6668c28dbf74bbc597fa95fba02d
1 //=====================================================
2 // CopyRight (C) 2007 Qualcomm Inc. All Rights Reserved.
3 //
4 //
5 // This file is part of Express Card USB Driver
6 //
7 // $Id:
8 //====================================================
9 // 20090926; aelias; removed all compiler warnings; ubuntu 9.04; 2.6.28-15-generic
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 "ft1000_usb.h"
18 //#include <linux/sched.h>
19 //#include <linux/ptrace.h>
20 //#include <linux/slab.h>
21 //#include <linux/string.h>
22 //#include <linux/timer.h>
23 //#include <linux/netdevice.h>
24 //#include <linux/ioport.h>
25 //#include <linux/delay.h>
26 //#include <asm/io.h>
27 //#include <asm/system.h>
28 #include <linux/kthread.h>
30 MODULE_DESCRIPTION("FT1000 EXPRESS CARD DRIVER");
31 MODULE_LICENSE("Dual MPL/GPL");
32 MODULE_SUPPORTED_DEVICE("QFT FT1000 Express Cards");
35 void *pFileStart;
36 size_t FileLength;
38 #define VENDOR_ID 0x1291 /* Qualcomm vendor id */
39 #define PRODUCT_ID 0x11 /* fake product id */
41 /* table of devices that work with this driver */
42 static struct usb_device_id id_table[] = {
43 {USB_DEVICE(VENDOR_ID, PRODUCT_ID) },
44 { },
47 MODULE_DEVICE_TABLE (usb, id_table);
49 static BOOLEAN gPollingfailed = FALSE;
50 int ft1000_poll_thread(void *arg)
52 int ret = STATUS_SUCCESS;
54 while(!kthread_should_stop() )
56 msleep(10);
57 if ( ! gPollingfailed )
59 ret = ft1000_poll(arg);
60 if ( ret != STATUS_SUCCESS )
62 DEBUG("ft1000_poll_thread: polling failed\n");
63 gPollingfailed = TRUE;
67 //DEBUG("returned from polling thread\n");
68 return STATUS_SUCCESS;
73 //---------------------------------------------------------------------------
74 // Function: ft1000_probe
76 // Parameters: struct usb_interface *interface - passed by USB core
77 // struct usb_device_id *id - passed by USB core
78 // Returns: 0 - success
80 // Description: This function is invoked when the express card is plugged in
82 // Notes:
84 //---------------------------------------------------------------------------
85 static int ft1000_probe(struct usb_interface *interface, const struct usb_device_id *id)
87 struct usb_host_interface *iface_desc;
88 struct usb_endpoint_descriptor *endpoint;
89 struct usb_device *dev;
90 unsigned numaltsetting;
91 int i;
93 struct ft1000_device *ft1000dev;
94 FT1000_INFO *pft1000info;
96 if(!(ft1000dev = kmalloc(sizeof(struct ft1000_device), GFP_KERNEL)))
98 printk("out of memory allocating device structure\n");
99 return 0;
102 memset(ft1000dev, 0, sizeof(*ft1000dev));
104 //get usb device
105 dev = interface_to_usbdev(interface);
106 DEBUG("ft1000_probe: usb device descriptor info:\n");
107 DEBUG("ft1000_probe: number of configuration is %d\n", dev->descriptor.bNumConfigurations);
109 ft1000dev->dev = dev;
110 ft1000dev->status = 0;
111 ft1000dev->net = NULL;
112 //ft1000dev->device_lock = SPIN_LOCK_UNLOCKED;
113 spin_lock_init(&ft1000dev->device_lock);
114 ft1000dev->tx_urb = usb_alloc_urb(0, GFP_ATOMIC);
115 ft1000dev->rx_urb = usb_alloc_urb(0, GFP_ATOMIC);
118 DEBUG("ft1000_probe is called\n");
119 numaltsetting = interface->num_altsetting;
120 DEBUG("ft1000_probe: number of alt settings is :%d\n",numaltsetting);
121 iface_desc = interface->cur_altsetting;
122 DEBUG("ft1000_probe: number of endpoints is %d\n", iface_desc->desc.bNumEndpoints);
123 DEBUG("ft1000_probe: descriptor type is %d\n", iface_desc->desc.bDescriptorType);
124 DEBUG("ft1000_probe: interface number is %d\n", iface_desc->desc.bInterfaceNumber);
125 DEBUG("ft1000_probe: alternatesetting is %d\n", iface_desc->desc.bAlternateSetting);
126 DEBUG("ft1000_probe: interface class is %d\n", iface_desc->desc.bInterfaceClass);
127 DEBUG("ft1000_probe: control endpoint info:\n");
128 DEBUG("ft1000_probe: descriptor0 type -- %d\n", iface_desc->endpoint[0].desc.bmAttributes);
129 DEBUG("ft1000_probe: descriptor1 type -- %d\n", iface_desc->endpoint[1].desc.bmAttributes);
130 DEBUG("ft1000_probe: descriptor2 type -- %d\n", iface_desc->endpoint[2].desc.bmAttributes);
132 for (i=0; i< iface_desc->desc.bNumEndpoints;i++ )
134 endpoint = (struct usb_endpoint_descriptor *)&iface_desc->endpoint[i].desc;
135 DEBUG("endpoint %d\n", i);
136 DEBUG("bEndpointAddress=%x, bmAttributes=%x\n", endpoint->bEndpointAddress, endpoint->bmAttributes);
137 if ( (endpoint->bEndpointAddress & USB_DIR_IN) && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK))
139 ft1000dev->bulk_in_endpointAddr = endpoint->bEndpointAddress;
140 DEBUG("ft1000_probe: in: %d\n", endpoint->bEndpointAddress);
143 if (!(endpoint->bEndpointAddress & USB_DIR_IN) && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK))
145 ft1000dev->bulk_out_endpointAddr = endpoint->bEndpointAddress;
146 DEBUG("ft1000_probe: out: %d\n", endpoint->bEndpointAddress);
150 DEBUG("bulk_in=%d, bulk_out=%d\n", ft1000dev->bulk_in_endpointAddr, ft1000dev->bulk_out_endpointAddr);
152 //read DSP image
153 pFileStart = (void*)getfw("/etc/flarion/ft3000.img", &FileLength);
155 if (pFileStart == NULL )
157 DEBUG ("ft1000_probe: Read DSP image failed\n");
158 return 0;
161 //for ( i=0; i< MAX_NUM_CARDS+2; i++)
162 // pdevobj[i] = NULL;
164 //download dsp image
165 DEBUG("ft1000_probe: start downloading dsp image...\n");
166 init_ft1000_netdev(ft1000dev);
167 pft1000info = (FT1000_INFO *) netdev_priv (ft1000dev->net);
169 // DEBUG("In probe: pft1000info=%x\n", pft1000info); // aelias [-] reason: warning: format ???%x??? expects type ???unsigned int???, but argument 2 has type ???struct FT1000_INFO *???
170 DEBUG("In probe: pft1000info=%p\n", pft1000info); // aelias [+] reason: up
172 dsp_reload(ft1000dev);
173 gPollingfailed = FALSE; //mbelian
174 pft1000info->pPollThread = kthread_run(ft1000_poll_thread, ft1000dev, "ft1000_poll");
175 msleep(500); //mbelian
178 if ( pft1000info->DSP_loading )
180 DEBUG("ERROR!!!! RETURN FROM ft1000_probe **********************\n");
181 return 0;
184 while (!pft1000info->CardReady)
186 if ( gPollingfailed )
188 if ( pft1000info->pPollThread )
190 kthread_stop(pft1000info->pPollThread );
192 return 0;
194 msleep(100);
195 DEBUG("ft1000_probe::Waiting for Card Ready\n");
199 //initialize network device
200 DEBUG("ft1000_probe::Card Ready!!!! Registering network device\n");
202 reg_ft1000_netdev(ft1000dev, interface);
204 pft1000info->NetDevRegDone = 1;
206 ft1000InitProc(ft1000dev->net);// +mbelian
208 return 0;
211 //---------------------------------------------------------------------------
212 // Function: ft1000_disconnect
214 // Parameters: struct usb_interface *interface - passed by USB core
216 // Returns: 0 - success
218 // Description: This function is invoked when the express card is plugged out
220 // Notes:
222 //---------------------------------------------------------------------------
223 static void ft1000_disconnect(struct usb_interface *interface)
225 FT1000_INFO *pft1000info;
227 DEBUG("ft1000_disconnect is called\n");
229 pft1000info = (PFT1000_INFO)usb_get_intfdata(interface);
230 // DEBUG("In disconnect pft1000info=%x\n", pft1000info); // aelias [-] reason: warning: format ???%x??? expects type ???unsigned int???, but argument 2 has type ???struct FT1000_INFO *???
231 DEBUG("In disconnect pft1000info=%p\n", pft1000info); // aelias [+] reason: up
235 if (pft1000info)
237 ft1000CleanupProc(pft1000info); //+mbelian
238 if ( pft1000info->pPollThread )
240 kthread_stop(pft1000info->pPollThread );
243 DEBUG("ft1000_disconnect: threads are terminated\n");
245 if (pft1000info->pFt1000Dev->net)
247 DEBUG("ft1000_disconnect: destroy char driver\n");
248 ft1000_DestroyDevice(pft1000info->pFt1000Dev->net);
249 //DEBUG("ft1000_disconnect: calling ft1000_close\n");
250 //ft1000_close(pft1000info->pFt1000Dev->net);
251 //DEBUG("ft1000_disconnect: ft1000_close is called\n");
252 unregister_netdev(pft1000info->pFt1000Dev->net);
253 DEBUG("ft1000_disconnect: network device unregisterd\n");
254 free_netdev(pft1000info->pFt1000Dev->net);
258 usb_free_urb(pft1000info->pFt1000Dev->rx_urb);
259 usb_free_urb(pft1000info->pFt1000Dev->tx_urb);
261 DEBUG("ft1000_disconnect: urb freed\n");
263 kfree(pft1000info->pFt1000Dev); //+mbelian
266 //terminate other kernel threads
267 //in multiple instances case, first find the device
268 //in the link list
269 /**if (pPollThread)
271 kthread_stop(pPollThread);
272 DEBUG("Polling thread is killed \n");
273 }**/
275 return;
278 static struct usb_driver ft1000_usb_driver = {
279 //.owner = THIS_MODULE,
280 .name = "ft1000usb",
281 .probe = ft1000_probe,
282 .disconnect = ft1000_disconnect,
283 .id_table = id_table,
286 //---------------------------------------------------------------------------
287 // Function: usb_ft1000_init
289 // Parameters: none
291 // Returns: 0 - success
293 // Description: The entry point of the module, register the usb driver
295 // Notes:
297 //---------------------------------------------------------------------------
298 static int __init usb_ft1000_init(void)
300 int ret = 0;
302 DEBUG("Initialize and register the driver\n");
304 ret = usb_register(&ft1000_usb_driver);
305 if (ret)
306 err("usb_register failed. Error number %d", ret);
308 return ret;
311 //---------------------------------------------------------------------------
312 // Function: usb_ft1000_exit
314 // Parameters:
316 // Returns:
318 // Description: Moudle unload function, deregister usb driver
320 // Notes:
322 //---------------------------------------------------------------------------
323 static void __exit usb_ft1000_exit(void)
325 DEBUG("Deregister the driver\n");
326 usb_deregister(&ft1000_usb_driver);
329 module_init (usb_ft1000_init);
330 module_exit (usb_ft1000_exit);