Version:  2.0.40 2.2.26 2.4.37 3.4 3.5 3.6 3.7 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

Linux/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c

  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  */
 10 
 11 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 12 
 13 #include <linux/kernel.h>
 14 #include <linux/module.h>
 15 #include <linux/usb.h>
 16 #include <linux/netdevice.h>
 17 #include <linux/etherdevice.h>
 18 #include <linux/firmware.h>
 19 #include "ft1000_usb.h"
 20 
 21 #include <linux/kthread.h>
 22 
 23 MODULE_DESCRIPTION("FT1000 EXPRESS CARD DRIVER");
 24 MODULE_LICENSE("Dual MPL/GPL");
 25 MODULE_SUPPORTED_DEVICE("QFT FT1000 Express Cards");
 26 
 27 void *pFileStart;
 28 size_t FileLength;
 29 
 30 #define VENDOR_ID 0x1291        /* Qualcomm vendor id */
 31 #define PRODUCT_ID 0x11         /* fake product id */
 32 
 33 /* table of devices that work with this driver */
 34 static struct usb_device_id id_table[] = {
 35         {USB_DEVICE(VENDOR_ID, PRODUCT_ID)},
 36         {},
 37 };
 38 
 39 MODULE_DEVICE_TABLE(usb, id_table);
 40 
 41 static bool gPollingfailed;
 42 static int ft1000_poll_thread(void *arg)
 43 {
 44         int ret;
 45 
 46         while (!kthread_should_stop()) {
 47                 usleep_range(10000, 11000);
 48                 if (!gPollingfailed) {
 49                         ret = ft1000_poll(arg);
 50                         if (ret != 0) {
 51                                 pr_debug("polling failed\n");
 52                                 gPollingfailed = true;
 53                         }
 54                 }
 55         }
 56         return 0;
 57 }
 58 
 59 static int ft1000_probe(struct usb_interface *interface,
 60                         const struct usb_device_id *id)
 61 {
 62         struct usb_host_interface *iface_desc;
 63         struct usb_endpoint_descriptor *endpoint;
 64         struct usb_device *dev;
 65         unsigned numaltsetting;
 66         int i, ret = 0, size;
 67 
 68         struct ft1000_usb *ft1000dev;
 69         struct ft1000_info *pft1000info = NULL;
 70         const struct firmware *dsp_fw;
 71 
 72         ft1000dev = kzalloc(sizeof(struct ft1000_usb), GFP_KERNEL);
 73         if (!ft1000dev)
 74                 return -ENOMEM;
 75 
 76         dev = interface_to_usbdev(interface);
 77         pr_debug("usb device descriptor info - number of configuration is %d\n",
 78                  dev->descriptor.bNumConfigurations);
 79 
 80         ft1000dev->dev = dev;
 81         ft1000dev->status = 0;
 82         ft1000dev->net = NULL;
 83         ft1000dev->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
 84         ft1000dev->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
 85         if (!ft1000dev->tx_urb || !ft1000dev->rx_urb) {
 86                 ret = -ENOMEM;
 87                 goto err_fw;
 88         }
 89 
 90         numaltsetting = interface->num_altsetting;
 91         pr_debug("number of alt settings is: %d\n", numaltsetting);
 92         iface_desc = interface->cur_altsetting;
 93         pr_debug("number of endpoints is: %d\n",
 94                  iface_desc->desc.bNumEndpoints);
 95         pr_debug("descriptor type is: %d\n", iface_desc->desc.bDescriptorType);
 96         pr_debug("interface number is: %d\n",
 97                  iface_desc->desc.bInterfaceNumber);
 98         pr_debug("alternatesetting is: %d\n",
 99                  iface_desc->desc.bAlternateSetting);
100         pr_debug("interface class is: %d\n", iface_desc->desc.bInterfaceClass);
101         pr_debug("control endpoint info:\n");
102         pr_debug("descriptor0 type -- %d\n",
103                  iface_desc->endpoint[0].desc.bmAttributes);
104         pr_debug("descriptor1 type -- %d\n",
105                  iface_desc->endpoint[1].desc.bmAttributes);
106         pr_debug("descriptor2 type -- %d\n",
107                  iface_desc->endpoint[2].desc.bmAttributes);
108 
109         for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
110                 endpoint =
111                         (struct usb_endpoint_descriptor *)&iface_desc->
112                         endpoint[i].desc;
113                 pr_debug("endpoint %d\n", i);
114                 pr_debug("bEndpointAddress=%x, bmAttributes=%x\n",
115                          endpoint->bEndpointAddress, endpoint->bmAttributes);
116                 if ((endpoint->bEndpointAddress & USB_DIR_IN)
117                     && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
118                         USB_ENDPOINT_XFER_BULK)) {
119                         ft1000dev->bulk_in_endpointAddr =
120                                 endpoint->bEndpointAddress;
121                         pr_debug("in: %d\n", endpoint->bEndpointAddress);
122                 }
123 
124                 if (!(endpoint->bEndpointAddress & USB_DIR_IN)
125                     && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
126                         USB_ENDPOINT_XFER_BULK)) {
127                         ft1000dev->bulk_out_endpointAddr =
128                                 endpoint->bEndpointAddress;
129                         pr_debug("out: %d\n", endpoint->bEndpointAddress);
130                 }
131         }
132 
133         pr_debug("bulk_in=%d, bulk_out=%d\n",
134                  ft1000dev->bulk_in_endpointAddr,
135                  ft1000dev->bulk_out_endpointAddr);
136 
137         ret = request_firmware(&dsp_fw, "ft3000.img", &dev->dev);
138         if (ret < 0) {
139                 pr_err("Error request_firmware()\n");
140                 goto err_fw;
141         }
142 
143         size = max_t(uint, dsp_fw->size, 4096);
144         pFileStart = kmalloc(size, GFP_KERNEL);
145 
146         if (!pFileStart) {
147                 release_firmware(dsp_fw);
148                 ret = -ENOMEM;
149                 goto err_fw;
150         }
151 
152         memcpy(pFileStart, dsp_fw->data, dsp_fw->size);
153         FileLength = dsp_fw->size;
154         release_firmware(dsp_fw);
155 
156         pr_debug("start downloading dsp image...\n");
157 
158         ret = init_ft1000_netdev(ft1000dev);
159         if (ret)
160                 goto err_load;
161 
162         pft1000info = netdev_priv(ft1000dev->net);
163 
164         pr_debug("pft1000info=%p\n", pft1000info);
165         ret = dsp_reload(ft1000dev);
166         if (ret) {
167                 pr_err("Problem with DSP image loading\n");
168                 goto err_load;
169         }
170 
171         gPollingfailed = false;
172         ft1000dev->pPollThread =
173                 kthread_run(ft1000_poll_thread, ft1000dev, "ft1000_poll");
174 
175         if (IS_ERR(ft1000dev->pPollThread)) {
176                 ret = PTR_ERR(ft1000dev->pPollThread);
177                 goto err_load;
178         }
179 
180         msleep(500);
181 
182         while (!pft1000info->CardReady) {
183                 if (gPollingfailed) {
184                         ret = -EIO;
185                         goto err_thread;
186                 }
187                 msleep(100);
188                 pr_debug("Waiting for Card Ready\n");
189         }
190 
191         pr_debug("Card Ready!!!! Registering network device\n");
192 
193         ret = reg_ft1000_netdev(ft1000dev, interface);
194         if (ret)
195                 goto err_thread;
196 
197         ft1000dev->NetDevRegDone = 1;
198 
199         return 0;
200 
201 err_thread:
202         kthread_stop(ft1000dev->pPollThread);
203 err_load:
204         kfree(pFileStart);
205 err_fw:
206         usb_free_urb(ft1000dev->rx_urb);
207         usb_free_urb(ft1000dev->tx_urb);
208         kfree(ft1000dev);
209         return ret;
210 }
211 
212 static void ft1000_disconnect(struct usb_interface *interface)
213 {
214         struct ft1000_info *pft1000info;
215         struct ft1000_usb *ft1000dev;
216 
217         pft1000info = (struct ft1000_info *)usb_get_intfdata(interface);
218         pr_debug("In disconnect pft1000info=%p\n", pft1000info);
219 
220         if (pft1000info) {
221                 ft1000dev = pft1000info->priv;
222                 if (ft1000dev->pPollThread)
223                         kthread_stop(ft1000dev->pPollThread);
224 
225                 pr_debug("threads are terminated\n");
226 
227                 if (ft1000dev->net) {
228                         pr_debug("destroy char driver\n");
229                         ft1000_destroy_dev(ft1000dev->net);
230                         unregister_netdev(ft1000dev->net);
231                         pr_debug("network device unregistered\n");
232                         free_netdev(ft1000dev->net);
233 
234                 }
235 
236                 usb_free_urb(ft1000dev->rx_urb);
237                 usb_free_urb(ft1000dev->tx_urb);
238 
239                 pr_debug("urb freed\n");
240 
241                 kfree(ft1000dev);
242         }
243         kfree(pFileStart);
244 }
245 
246 static struct usb_driver ft1000_usb_driver = {
247         .name = "ft1000usb",
248         .probe = ft1000_probe,
249         .disconnect = ft1000_disconnect,
250         .id_table = id_table,
251 };
252 
253 module_usb_driver(ft1000_usb_driver);
254 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us