7a171e034b59633416232aeff6eb0508ef7c7b5c
[linux-2.6.git] / drivers / usb / serial / anydata.c
1 /*
2  * AnyData CDMA Serial USB driver
3  *
4  * Copyright (C) 2005 Greg Kroah-Hartman <gregkh@suse.de>
5  *
6  *      This program is free software; you can redistribute it and/or
7  *      modify it under the terms of the GNU General Public License version
8  *      2 as published by the Free Software Foundation.
9  */
10
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/tty.h>
14 #include <linux/module.h>
15 #include <linux/usb.h>
16 #include "usb-serial.h"
17
18 static struct usb_device_id id_table [] = {
19         { USB_DEVICE(0x16d5, 0x6501) }, /* AirData CDMA device */
20         { },
21 };
22 MODULE_DEVICE_TABLE(usb, id_table);
23
24 /* if overridden by the user, then use their value for the size of the
25  * read and write urbs */
26 static int buffer_size;
27 static int debug;
28
29 static struct usb_driver anydata_driver = {
30         .owner =        THIS_MODULE,
31         .name =         "anydata",
32         .probe =        usb_serial_probe,
33         .disconnect =   usb_serial_disconnect,
34         .id_table =     id_table,
35         .no_dynamic_id =        1,
36 };
37
38 static int anydata_open(struct usb_serial_port *port, struct file *filp)
39 {
40         char *buffer;
41         int result = 0;
42
43         dbg("%s - port %d", __FUNCTION__, port->number);
44
45         if (buffer_size) {
46                 /* override the default buffer sizes */
47                 buffer = kmalloc(buffer_size, GFP_KERNEL);
48                 if (!buffer) {
49                         dev_err(&port->dev, "%s - out of memory.\n",
50                                 __FUNCTION__);
51                         return -ENOMEM;
52                 }
53                 kfree (port->read_urb->transfer_buffer);
54                 port->read_urb->transfer_buffer = buffer;
55                 port->read_urb->transfer_buffer_length = buffer_size;
56
57                 buffer = kmalloc(buffer_size, GFP_KERNEL);
58                 if (!buffer) {
59                         dev_err(&port->dev, "%s - out of memory.\n",
60                                 __FUNCTION__);
61                         return -ENOMEM;
62                 }
63                 kfree (port->write_urb->transfer_buffer);
64                 port->write_urb->transfer_buffer = buffer;
65                 port->write_urb->transfer_buffer_length = buffer_size;
66                 port->bulk_out_size = buffer_size;
67         }
68
69         /* Start reading from the device */
70         usb_fill_bulk_urb(port->read_urb, port->serial->dev,
71                           usb_rcvbulkpipe(port->serial->dev,
72                                           port->bulk_in_endpointAddress),
73                           port->read_urb->transfer_buffer,
74                           port->read_urb->transfer_buffer_length,
75                           usb_serial_generic_write_bulk_callback, port);
76         result = usb_submit_urb(port->read_urb, GFP_KERNEL);
77         if (result)
78                 dev_err(&port->dev,
79                         "%s - failed submitting read urb, error %d\n",
80                         __FUNCTION__, result);
81
82         return result;
83 }
84
85 static struct usb_serial_driver anydata_device = {
86         .driver = {
87                 .owner =        THIS_MODULE,
88                 .name =         "anydata",
89         },
90         .id_table =             id_table,
91         .num_interrupt_in =     NUM_DONT_CARE,
92         .num_bulk_in =          NUM_DONT_CARE,
93         .num_bulk_out =         NUM_DONT_CARE,
94         .num_ports =            1,
95         .open =                 anydata_open,
96 };
97
98 static int __init anydata_init(void)
99 {
100         int retval;
101
102         retval = usb_serial_register(&anydata_device);
103         if (retval)
104                 return retval;
105         retval = usb_register(&anydata_driver);
106         if (retval)
107                 usb_serial_deregister(&anydata_device);
108         return retval;
109 }
110
111 static void __exit anydata_exit(void)
112 {
113         usb_deregister(&anydata_driver);
114         usb_serial_deregister(&anydata_device);
115 }
116
117 module_init(anydata_init);
118 module_exit(anydata_exit);
119 MODULE_LICENSE("GPL");
120
121 module_param(debug, bool, S_IRUGO | S_IWUSR);
122 MODULE_PARM_DESC(debug, "Debug enabled or not");
123 module_param(buffer_size, int, 0);
124 MODULE_PARM_DESC(buffer_size, "Size of the transfer buffers");