Merge with /home/shaggy/git/linus-clean/
[linux-2.6] / 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         .name =         "anydata",
31         .probe =        usb_serial_probe,
32         .disconnect =   usb_serial_disconnect,
33         .id_table =     id_table,
34         .no_dynamic_id =        1,
35 };
36
37 static int anydata_open(struct usb_serial_port *port, struct file *filp)
38 {
39         char *buffer;
40         int result = 0;
41
42         dbg("%s - port %d", __FUNCTION__, port->number);
43
44         if (buffer_size) {
45                 /* override the default buffer sizes */
46                 buffer = kmalloc(buffer_size, GFP_KERNEL);
47                 if (!buffer) {
48                         dev_err(&port->dev, "%s - out of memory.\n",
49                                 __FUNCTION__);
50                         return -ENOMEM;
51                 }
52                 kfree (port->read_urb->transfer_buffer);
53                 port->read_urb->transfer_buffer = buffer;
54                 port->read_urb->transfer_buffer_length = buffer_size;
55
56                 buffer = kmalloc(buffer_size, GFP_KERNEL);
57                 if (!buffer) {
58                         dev_err(&port->dev, "%s - out of memory.\n",
59                                 __FUNCTION__);
60                         return -ENOMEM;
61                 }
62                 kfree (port->write_urb->transfer_buffer);
63                 port->write_urb->transfer_buffer = buffer;
64                 port->write_urb->transfer_buffer_length = buffer_size;
65                 port->bulk_out_size = buffer_size;
66         }
67
68         /* Start reading from the device */
69         usb_fill_bulk_urb(port->read_urb, port->serial->dev,
70                           usb_rcvbulkpipe(port->serial->dev,
71                                           port->bulk_in_endpointAddress),
72                           port->read_urb->transfer_buffer,
73                           port->read_urb->transfer_buffer_length,
74                           usb_serial_generic_write_bulk_callback, port);
75         result = usb_submit_urb(port->read_urb, GFP_KERNEL);
76         if (result)
77                 dev_err(&port->dev,
78                         "%s - failed submitting read urb, error %d\n",
79                         __FUNCTION__, result);
80
81         return result;
82 }
83
84 static struct usb_serial_driver anydata_device = {
85         .driver = {
86                 .owner =        THIS_MODULE,
87                 .name =         "anydata",
88         },
89         .id_table =             id_table,
90         .num_interrupt_in =     NUM_DONT_CARE,
91         .num_bulk_in =          NUM_DONT_CARE,
92         .num_bulk_out =         NUM_DONT_CARE,
93         .num_ports =            1,
94         .open =                 anydata_open,
95 };
96
97 static int __init anydata_init(void)
98 {
99         int retval;
100
101         retval = usb_serial_register(&anydata_device);
102         if (retval)
103                 return retval;
104         retval = usb_register(&anydata_driver);
105         if (retval)
106                 usb_serial_deregister(&anydata_device);
107         return retval;
108 }
109
110 static void __exit anydata_exit(void)
111 {
112         usb_deregister(&anydata_driver);
113         usb_serial_deregister(&anydata_device);
114 }
115
116 module_init(anydata_init);
117 module_exit(anydata_exit);
118 MODULE_LICENSE("GPL");
119
120 module_param(debug, bool, S_IRUGO | S_IWUSR);
121 MODULE_PARM_DESC(debug, "Debug enabled or not");
122 module_param(buffer_size, int, 0);
123 MODULE_PARM_DESC(buffer_size, "Size of the transfer buffers");