diff options
author | Felipe Balbi <me@felipebalbi.com> | 2008-06-03 07:47:52 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2008-07-21 18:16:27 -0400 |
commit | e0d795e4f36c2d8949c1355b497fc5425dbb9437 (patch) | |
tree | 28bbd3b97fa7924c9f4c406f908fa0d51c0f08af /drivers | |
parent | b963801164618e25fbdc0cd452ce49c3628b46c8 (diff) |
usb: irda: cleanup on ir-usb module
General cleanup on ir-usb module. Introduced
a common header that could be used also on
usb gadget framework.
Lot's of cleanups and now using macros from the header
file.
Signed-off-by: Felipe Balbi <me@felipebalbi.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/usb/serial/ir-usb.c | 490 |
1 files changed, 270 insertions, 220 deletions
diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c index 004d57385a75..0063c11c8081 100644 --- a/drivers/usb/serial/ir-usb.c +++ b/drivers/usb/serial/ir-usb.c | |||
@@ -19,7 +19,12 @@ | |||
19 | * was written by Roman Weissgaerber <weissg@vienna.at>, Dag Brattli | 19 | * was written by Roman Weissgaerber <weissg@vienna.at>, Dag Brattli |
20 | * <dag@brattli.net>, and Jean Tourrilhes <jt@hpl.hp.com> | 20 | * <dag@brattli.net>, and Jean Tourrilhes <jt@hpl.hp.com> |
21 | * | 21 | * |
22 | * See Documentation/usb/usb-serial.txt for more information on using this driver | 22 | * See Documentation/usb/usb-serial.txt for more information on using this |
23 | * driver | ||
24 | * | ||
25 | * 2008_Jun_02 Felipe Balbi <me@felipebalbi.com> | ||
26 | * Introduced common header to be used also in USB Gadget Framework. | ||
27 | * Still needs some other style fixes. | ||
23 | * | 28 | * |
24 | * 2007_Jun_21 Alan Cox <alan@redhat.com> | 29 | * 2007_Jun_21 Alan Cox <alan@redhat.com> |
25 | * Minimal cleanups for some of the driver problens and tty layer abuse. | 30 | * Minimal cleanups for some of the driver problens and tty layer abuse. |
@@ -59,9 +64,10 @@ | |||
59 | #include <linux/tty_flip.h> | 64 | #include <linux/tty_flip.h> |
60 | #include <linux/module.h> | 65 | #include <linux/module.h> |
61 | #include <linux/spinlock.h> | 66 | #include <linux/spinlock.h> |
62 | #include <asm/uaccess.h> | 67 | #include <linux/uaccess.h> |
63 | #include <linux/usb.h> | 68 | #include <linux/usb.h> |
64 | #include <linux/usb/serial.h> | 69 | #include <linux/usb/serial.h> |
70 | #include <linux/usb/irda.h> | ||
65 | 71 | ||
66 | /* | 72 | /* |
67 | * Version Information | 73 | * Version Information |
@@ -70,100 +76,75 @@ | |||
70 | #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>" | 76 | #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>" |
71 | #define DRIVER_DESC "USB IR Dongle driver" | 77 | #define DRIVER_DESC "USB IR Dongle driver" |
72 | 78 | ||
73 | /* USB IrDA class spec information */ | ||
74 | #define USB_CLASS_IRDA 0x02 | ||
75 | #define USB_DT_IRDA 0x21 | ||
76 | #define IU_REQ_GET_CLASS_DESC 0x06 | ||
77 | #define SPEED_2400 0x01 | ||
78 | #define SPEED_9600 0x02 | ||
79 | #define SPEED_19200 0x03 | ||
80 | #define SPEED_38400 0x04 | ||
81 | #define SPEED_57600 0x05 | ||
82 | #define SPEED_115200 0x06 | ||
83 | #define SPEED_576000 0x07 | ||
84 | #define SPEED_1152000 0x08 | ||
85 | #define SPEED_4000000 0x09 | ||
86 | |||
87 | struct irda_class_desc { | ||
88 | u8 bLength; | ||
89 | u8 bDescriptorType; | ||
90 | u16 bcdSpecRevision; | ||
91 | u8 bmDataSize; | ||
92 | u8 bmWindowSize; | ||
93 | u8 bmMinTurnaroundTime; | ||
94 | u16 wBaudRate; | ||
95 | u8 bmAdditionalBOFs; | ||
96 | u8 bIrdaRateSniff; | ||
97 | u8 bMaxUnicastList; | ||
98 | } __attribute__ ((packed)); | ||
99 | |||
100 | static int debug; | 79 | static int debug; |
101 | 80 | ||
102 | /* if overridden by the user, then use their value for the size of the read and | 81 | /* if overridden by the user, then use their value for the size of the read and |
103 | * write urbs */ | 82 | * write urbs */ |
104 | static int buffer_size; | 83 | static int buffer_size; |
84 | |||
105 | /* if overridden by the user, then use the specified number of XBOFs */ | 85 | /* if overridden by the user, then use the specified number of XBOFs */ |
106 | static int xbof = -1; | 86 | static int xbof = -1; |
107 | 87 | ||
108 | static int ir_startup (struct usb_serial *serial); | 88 | static int ir_startup(struct usb_serial *serial); |
109 | static int ir_open (struct usb_serial_port *port, struct file *filep); | 89 | static int ir_open(struct usb_serial_port *port, struct file *filep); |
110 | static void ir_close (struct usb_serial_port *port, struct file *filep); | 90 | static void ir_close(struct usb_serial_port *port, struct file *filep); |
111 | static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int count); | 91 | static int ir_write(struct usb_serial_port *port, |
112 | static void ir_write_bulk_callback (struct urb *urb); | 92 | const unsigned char *buf, int count); |
113 | static void ir_read_bulk_callback (struct urb *urb); | 93 | static void ir_write_bulk_callback(struct urb *urb); |
114 | static void ir_set_termios (struct usb_serial_port *port, struct ktermios *old_termios); | 94 | static void ir_read_bulk_callback(struct urb *urb); |
95 | static void ir_set_termios(struct usb_serial_port *port, | ||
96 | struct ktermios *old_termios); | ||
115 | 97 | ||
116 | /* Not that this lot means you can only have one per system */ | 98 | /* Not that this lot means you can only have one per system */ |
117 | static u8 ir_baud = 0; | 99 | static u8 ir_baud; |
118 | static u8 ir_xbof = 0; | 100 | static u8 ir_xbof; |
119 | static u8 ir_add_bof = 0; | 101 | static u8 ir_add_bof; |
120 | 102 | ||
121 | static struct usb_device_id id_table [] = { | 103 | static struct usb_device_id ir_id_table[] = { |
122 | { USB_DEVICE(0x050f, 0x0180) }, /* KC Technology, KC-180 */ | 104 | { USB_DEVICE(0x050f, 0x0180) }, /* KC Technology, KC-180 */ |
123 | { USB_DEVICE(0x08e9, 0x0100) }, /* XTNDAccess */ | 105 | { USB_DEVICE(0x08e9, 0x0100) }, /* XTNDAccess */ |
124 | { USB_DEVICE(0x09c4, 0x0011) }, /* ACTiSys ACT-IR2000U */ | 106 | { USB_DEVICE(0x09c4, 0x0011) }, /* ACTiSys ACT-IR2000U */ |
125 | { USB_INTERFACE_INFO (USB_CLASS_APP_SPEC, USB_CLASS_IRDA, 0) }, | 107 | { USB_INTERFACE_INFO(USB_CLASS_APP_SPEC, USB_SUBCLASS_IRDA, 0) }, |
126 | { } /* Terminating entry */ | 108 | { } /* Terminating entry */ |
127 | }; | 109 | }; |
128 | 110 | ||
129 | MODULE_DEVICE_TABLE (usb, id_table); | 111 | MODULE_DEVICE_TABLE(usb, ir_id_table); |
130 | 112 | ||
131 | static struct usb_driver ir_driver = { | 113 | static struct usb_driver ir_driver = { |
132 | .name = "ir-usb", | 114 | .name = "ir-usb", |
133 | .probe = usb_serial_probe, | 115 | .probe = usb_serial_probe, |
134 | .disconnect = usb_serial_disconnect, | 116 | .disconnect = usb_serial_disconnect, |
135 | .id_table = id_table, | 117 | .id_table = ir_id_table, |
136 | .no_dynamic_id = 1, | 118 | .no_dynamic_id = 1, |
137 | }; | 119 | }; |
138 | 120 | ||
139 | |||
140 | static struct usb_serial_driver ir_device = { | 121 | static struct usb_serial_driver ir_device = { |
141 | .driver = { | 122 | .driver = { |
142 | .owner = THIS_MODULE, | 123 | .owner = THIS_MODULE, |
143 | .name = "ir-usb", | 124 | .name = "ir-usb", |
144 | }, | 125 | }, |
145 | .description = "IR Dongle", | 126 | .description = "IR Dongle", |
146 | .usb_driver = &ir_driver, | 127 | .usb_driver = &ir_driver, |
147 | .id_table = id_table, | 128 | .id_table = ir_id_table, |
148 | .num_ports = 1, | 129 | .num_ports = 1, |
149 | .set_termios = ir_set_termios, | 130 | .set_termios = ir_set_termios, |
150 | .attach = ir_startup, | 131 | .attach = ir_startup, |
151 | .open = ir_open, | 132 | .open = ir_open, |
152 | .close = ir_close, | 133 | .close = ir_close, |
153 | .write = ir_write, | 134 | .write = ir_write, |
154 | .write_bulk_callback = ir_write_bulk_callback, | 135 | .write_bulk_callback = ir_write_bulk_callback, |
155 | .read_bulk_callback = ir_read_bulk_callback, | 136 | .read_bulk_callback = ir_read_bulk_callback, |
156 | }; | 137 | }; |
157 | 138 | ||
158 | static inline void irda_usb_dump_class_desc(struct irda_class_desc *desc) | 139 | static inline void irda_usb_dump_class_desc(struct usb_irda_cs_descriptor *desc) |
159 | { | 140 | { |
160 | dbg("bLength=%x", desc->bLength); | 141 | dbg("bLength=%x", desc->bLength); |
161 | dbg("bDescriptorType=%x", desc->bDescriptorType); | 142 | dbg("bDescriptorType=%x", desc->bDescriptorType); |
162 | dbg("bcdSpecRevision=%x", desc->bcdSpecRevision); | 143 | dbg("bcdSpecRevision=%x", __le16_to_cpu(desc->bcdSpecRevision)); |
163 | dbg("bmDataSize=%x", desc->bmDataSize); | 144 | dbg("bmDataSize=%x", desc->bmDataSize); |
164 | dbg("bmWindowSize=%x", desc->bmWindowSize); | 145 | dbg("bmWindowSize=%x", desc->bmWindowSize); |
165 | dbg("bmMinTurnaroundTime=%d", desc->bmMinTurnaroundTime); | 146 | dbg("bmMinTurnaroundTime=%d", desc->bmMinTurnaroundTime); |
166 | dbg("wBaudRate=%x", desc->wBaudRate); | 147 | dbg("wBaudRate=%x", __le16_to_cpu(desc->wBaudRate)); |
167 | dbg("bmAdditionalBOFs=%x", desc->bmAdditionalBOFs); | 148 | dbg("bmAdditionalBOFs=%x", desc->bmAdditionalBOFs); |
168 | dbg("bIrdaRateSniff=%x", desc->bIrdaRateSniff); | 149 | dbg("bIrdaRateSniff=%x", desc->bIrdaRateSniff); |
169 | dbg("bMaxUnicastList=%x", desc->bMaxUnicastList); | 150 | dbg("bMaxUnicastList=%x", desc->bMaxUnicastList); |
@@ -181,35 +162,37 @@ static inline void irda_usb_dump_class_desc(struct irda_class_desc *desc) | |||
181 | * | 162 | * |
182 | * Based on the same function in drivers/net/irda/irda-usb.c | 163 | * Based on the same function in drivers/net/irda/irda-usb.c |
183 | */ | 164 | */ |
184 | static struct irda_class_desc *irda_usb_find_class_desc(struct usb_device *dev, unsigned int ifnum) | 165 | static struct usb_irda_cs_descriptor * |
166 | irda_usb_find_class_desc(struct usb_device *dev, unsigned int ifnum) | ||
185 | { | 167 | { |
186 | struct irda_class_desc *desc; | 168 | struct usb_irda_cs_descriptor *desc; |
187 | int ret; | 169 | int ret; |
188 | 170 | ||
189 | desc = kzalloc(sizeof (struct irda_class_desc), GFP_KERNEL); | 171 | desc = kzalloc(sizeof(*desc), GFP_KERNEL); |
190 | if (desc == NULL) | 172 | if (!desc) |
191 | return NULL; | 173 | return NULL; |
192 | 174 | ||
193 | ret = usb_control_msg(dev, usb_rcvctrlpipe(dev,0), | 175 | ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), |
194 | IU_REQ_GET_CLASS_DESC, | 176 | USB_REQ_CS_IRDA_GET_CLASS_DESC, |
195 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | 177 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
196 | 0, ifnum, desc, sizeof(*desc), 1000); | 178 | 0, ifnum, desc, sizeof(*desc), 1000); |
197 | 179 | ||
198 | dbg("%s - ret=%d", __func__, ret); | 180 | dbg("%s - ret=%d", __func__, ret); |
199 | if (ret < sizeof(*desc)) { | 181 | if (ret < sizeof(*desc)) { |
200 | dbg("%s - class descriptor read %s (%d)", | 182 | dbg("%s - class descriptor read %s (%d)", |
201 | __func__, | 183 | __func__, |
202 | (ret<0) ? "failed" : "too short", | 184 | (ret < 0) ? "failed" : "too short", |
203 | ret); | 185 | ret); |
204 | goto error; | 186 | goto error; |
205 | } | 187 | } |
206 | if (desc->bDescriptorType != USB_DT_IRDA) { | 188 | if (desc->bDescriptorType != USB_DT_CS_IRDA) { |
207 | dbg("%s - bad class descriptor type", __func__); | 189 | dbg("%s - bad class descriptor type", __func__); |
208 | goto error; | 190 | goto error; |
209 | } | 191 | } |
210 | 192 | ||
211 | irda_usb_dump_class_desc(desc); | 193 | irda_usb_dump_class_desc(desc); |
212 | return desc; | 194 | return desc; |
195 | |||
213 | error: | 196 | error: |
214 | kfree(desc); | 197 | kfree(desc); |
215 | return NULL; | 198 | return NULL; |
@@ -219,64 +202,100 @@ error: | |||
219 | static u8 ir_xbof_change(u8 xbof) | 202 | static u8 ir_xbof_change(u8 xbof) |
220 | { | 203 | { |
221 | u8 result; | 204 | u8 result; |
205 | |||
222 | /* reference irda-usb.c */ | 206 | /* reference irda-usb.c */ |
223 | switch(xbof) { | 207 | switch (xbof) { |
224 | case 48: result = 0x10; break; | 208 | case 48: |
225 | case 28: | 209 | result = 0x10; |
226 | case 24: result = 0x20; break; | 210 | break; |
227 | default: | 211 | case 28: |
228 | case 12: result = 0x30; break; | 212 | case 24: |
229 | case 5: | 213 | result = 0x20; |
230 | case 6: result = 0x40; break; | 214 | break; |
231 | case 3: result = 0x50; break; | 215 | default: |
232 | case 2: result = 0x60; break; | 216 | case 12: |
233 | case 1: result = 0x70; break; | 217 | result = 0x30; |
234 | case 0: result = 0x80; break; | 218 | break; |
219 | case 5: | ||
220 | case 6: | ||
221 | result = 0x40; | ||
222 | break; | ||
223 | case 3: | ||
224 | result = 0x50; | ||
225 | break; | ||
226 | case 2: | ||
227 | result = 0x60; | ||
228 | break; | ||
229 | case 1: | ||
230 | result = 0x70; | ||
231 | break; | ||
232 | case 0: | ||
233 | result = 0x80; | ||
234 | break; | ||
235 | } | 235 | } |
236 | |||
236 | return(result); | 237 | return(result); |
237 | } | 238 | } |
238 | 239 | ||
239 | 240 | ||
240 | static int ir_startup (struct usb_serial *serial) | 241 | static int ir_startup(struct usb_serial *serial) |
241 | { | 242 | { |
242 | struct irda_class_desc *irda_desc; | 243 | struct usb_irda_cs_descriptor *irda_desc; |
243 | 244 | ||
244 | irda_desc = irda_usb_find_class_desc (serial->dev, 0); | 245 | irda_desc = irda_usb_find_class_desc(serial->dev, 0); |
245 | if (irda_desc == NULL) { | 246 | if (!irda_desc) { |
246 | dev_err (&serial->dev->dev, "IRDA class descriptor not found, device not bound\n"); | 247 | dev_err(&serial->dev->dev, |
248 | "IRDA class descriptor not found, device not bound\n"); | ||
247 | return -ENODEV; | 249 | return -ENODEV; |
248 | } | 250 | } |
249 | 251 | ||
250 | dbg ("%s - Baud rates supported:%s%s%s%s%s%s%s%s%s", | 252 | dbg("%s - Baud rates supported:%s%s%s%s%s%s%s%s%s", |
251 | __func__, | 253 | __func__, |
252 | (irda_desc->wBaudRate & 0x0001) ? " 2400" : "", | 254 | (irda_desc->wBaudRate & USB_IRDA_BR_2400) ? " 2400" : "", |
253 | (irda_desc->wBaudRate & 0x0002) ? " 9600" : "", | 255 | (irda_desc->wBaudRate & USB_IRDA_BR_9600) ? " 9600" : "", |
254 | (irda_desc->wBaudRate & 0x0004) ? " 19200" : "", | 256 | (irda_desc->wBaudRate & USB_IRDA_BR_19200) ? " 19200" : "", |
255 | (irda_desc->wBaudRate & 0x0008) ? " 38400" : "", | 257 | (irda_desc->wBaudRate & USB_IRDA_BR_38400) ? " 38400" : "", |
256 | (irda_desc->wBaudRate & 0x0010) ? " 57600" : "", | 258 | (irda_desc->wBaudRate & USB_IRDA_BR_57600) ? " 57600" : "", |
257 | (irda_desc->wBaudRate & 0x0020) ? " 115200" : "", | 259 | (irda_desc->wBaudRate & USB_IRDA_BR_115200) ? " 115200" : "", |
258 | (irda_desc->wBaudRate & 0x0040) ? " 576000" : "", | 260 | (irda_desc->wBaudRate & USB_IRDA_BR_576000) ? " 576000" : "", |
259 | (irda_desc->wBaudRate & 0x0080) ? " 1152000" : "", | 261 | (irda_desc->wBaudRate & USB_IRDA_BR_1152000) ? " 1152000" : "", |
260 | (irda_desc->wBaudRate & 0x0100) ? " 4000000" : ""); | 262 | (irda_desc->wBaudRate & USB_IRDA_BR_4000000) ? " 4000000" : ""); |
261 | 263 | ||
262 | switch( irda_desc->bmAdditionalBOFs ) { | 264 | switch (irda_desc->bmAdditionalBOFs) { |
263 | case 0x01: ir_add_bof = 48; break; | 265 | case USB_IRDA_AB_48: |
264 | case 0x02: ir_add_bof = 24; break; | 266 | ir_add_bof = 48; |
265 | case 0x04: ir_add_bof = 12; break; | 267 | break; |
266 | case 0x08: ir_add_bof = 6; break; | 268 | case USB_IRDA_AB_24: |
267 | case 0x10: ir_add_bof = 3; break; | 269 | ir_add_bof = 24; |
268 | case 0x20: ir_add_bof = 2; break; | 270 | break; |
269 | case 0x40: ir_add_bof = 1; break; | 271 | case USB_IRDA_AB_12: |
270 | case 0x80: ir_add_bof = 0; break; | 272 | ir_add_bof = 12; |
271 | default:; | 273 | break; |
274 | case USB_IRDA_AB_6: | ||
275 | ir_add_bof = 6; | ||
276 | break; | ||
277 | case USB_IRDA_AB_3: | ||
278 | ir_add_bof = 3; | ||
279 | break; | ||
280 | case USB_IRDA_AB_2: | ||
281 | ir_add_bof = 2; | ||
282 | break; | ||
283 | case USB_IRDA_AB_1: | ||
284 | ir_add_bof = 1; | ||
285 | break; | ||
286 | case USB_IRDA_AB_0: | ||
287 | ir_add_bof = 0; | ||
288 | break; | ||
289 | default: | ||
290 | break; | ||
272 | } | 291 | } |
273 | 292 | ||
274 | kfree (irda_desc); | 293 | kfree(irda_desc); |
275 | 294 | ||
276 | return 0; | 295 | return 0; |
277 | } | 296 | } |
278 | 297 | ||
279 | static int ir_open (struct usb_serial_port *port, struct file *filp) | 298 | static int ir_open(struct usb_serial_port *port, struct file *filp) |
280 | { | 299 | { |
281 | char *buffer; | 300 | char *buffer; |
282 | int result = 0; | 301 | int result = 0; |
@@ -285,51 +304,55 @@ static int ir_open (struct usb_serial_port *port, struct file *filp) | |||
285 | 304 | ||
286 | if (buffer_size) { | 305 | if (buffer_size) { |
287 | /* override the default buffer sizes */ | 306 | /* override the default buffer sizes */ |
288 | buffer = kmalloc (buffer_size, GFP_KERNEL); | 307 | buffer = kmalloc(buffer_size, GFP_KERNEL); |
289 | if (!buffer) { | 308 | if (!buffer) { |
290 | dev_err (&port->dev, "%s - out of memory.\n", __func__); | 309 | dev_err(&port->dev, "%s - out of memory.\n", __func__); |
291 | return -ENOMEM; | 310 | return -ENOMEM; |
292 | } | 311 | } |
293 | kfree (port->read_urb->transfer_buffer); | 312 | kfree(port->read_urb->transfer_buffer); |
294 | port->read_urb->transfer_buffer = buffer; | 313 | port->read_urb->transfer_buffer = buffer; |
295 | port->read_urb->transfer_buffer_length = buffer_size; | 314 | port->read_urb->transfer_buffer_length = buffer_size; |
296 | 315 | ||
297 | buffer = kmalloc (buffer_size, GFP_KERNEL); | 316 | buffer = kmalloc(buffer_size, GFP_KERNEL); |
298 | if (!buffer) { | 317 | if (!buffer) { |
299 | dev_err (&port->dev, "%s - out of memory.\n", __func__); | 318 | dev_err(&port->dev, "%s - out of memory.\n", __func__); |
300 | return -ENOMEM; | 319 | return -ENOMEM; |
301 | } | 320 | } |
302 | kfree (port->write_urb->transfer_buffer); | 321 | kfree(port->write_urb->transfer_buffer); |
303 | port->write_urb->transfer_buffer = buffer; | 322 | port->write_urb->transfer_buffer = buffer; |
304 | port->write_urb->transfer_buffer_length = buffer_size; | 323 | port->write_urb->transfer_buffer_length = buffer_size; |
305 | port->bulk_out_size = buffer_size; | 324 | port->bulk_out_size = buffer_size; |
306 | } | 325 | } |
307 | 326 | ||
308 | /* Start reading from the device */ | 327 | /* Start reading from the device */ |
309 | usb_fill_bulk_urb ( | 328 | usb_fill_bulk_urb( |
310 | port->read_urb, | 329 | port->read_urb, |
311 | port->serial->dev, | 330 | port->serial->dev, |
312 | usb_rcvbulkpipe(port->serial->dev, port->bulk_in_endpointAddress), | 331 | usb_rcvbulkpipe(port->serial->dev, |
332 | port->bulk_in_endpointAddress), | ||
313 | port->read_urb->transfer_buffer, | 333 | port->read_urb->transfer_buffer, |
314 | port->read_urb->transfer_buffer_length, | 334 | port->read_urb->transfer_buffer_length, |
315 | ir_read_bulk_callback, | 335 | ir_read_bulk_callback, |
316 | port); | 336 | port); |
317 | result = usb_submit_urb(port->read_urb, GFP_KERNEL); | 337 | result = usb_submit_urb(port->read_urb, GFP_KERNEL); |
318 | if (result) | 338 | if (result) |
319 | dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __func__, result); | 339 | dev_err(&port->dev, |
340 | "%s - failed submitting read urb, error %d\n", | ||
341 | __func__, result); | ||
320 | 342 | ||
321 | return result; | 343 | return result; |
322 | } | 344 | } |
323 | 345 | ||
324 | static void ir_close (struct usb_serial_port *port, struct file * filp) | 346 | static void ir_close(struct usb_serial_port *port, struct file *filp) |
325 | { | 347 | { |
326 | dbg("%s - port %d", __func__, port->number); | 348 | dbg("%s - port %d", __func__, port->number); |
327 | 349 | ||
328 | /* shutdown our bulk read */ | 350 | /* shutdown our bulk read */ |
329 | usb_kill_urb(port->read_urb); | 351 | usb_kill_urb(port->read_urb); |
330 | } | 352 | } |
331 | 353 | ||
332 | static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int count) | 354 | static int ir_write(struct usb_serial_port *port, |
355 | const unsigned char *buf, int count) | ||
333 | { | 356 | { |
334 | unsigned char *transfer_buffer; | 357 | unsigned char *transfer_buffer; |
335 | int result; | 358 | int result; |
@@ -338,7 +361,7 @@ static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int | |||
338 | dbg("%s - port = %d, count = %d", __func__, port->number, count); | 361 | dbg("%s - port = %d, count = %d", __func__, port->number, count); |
339 | 362 | ||
340 | if (!port->tty) { | 363 | if (!port->tty) { |
341 | dev_err (&port->dev, "%s - no tty???\n", __func__); | 364 | dev_err(&port->dev, "%s - no tty???\n", __func__); |
342 | return 0; | 365 | return 0; |
343 | } | 366 | } |
344 | 367 | ||
@@ -359,7 +382,7 @@ static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int | |||
359 | 382 | ||
360 | /* | 383 | /* |
361 | * The first byte of the packet we send to the device contains an | 384 | * The first byte of the packet we send to the device contains an |
362 | * inband header which indicates an additional number of BOFs and | 385 | * inbound header which indicates an additional number of BOFs and |
363 | * a baud rate change. | 386 | * a baud rate change. |
364 | * | 387 | * |
365 | * See section 5.4.2.2 of the USB IrDA spec. | 388 | * See section 5.4.2.2 of the USB IrDA spec. |
@@ -367,9 +390,9 @@ static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int | |||
367 | *transfer_buffer = ir_xbof | ir_baud; | 390 | *transfer_buffer = ir_xbof | ir_baud; |
368 | ++transfer_buffer; | 391 | ++transfer_buffer; |
369 | 392 | ||
370 | memcpy (transfer_buffer, buf, transfer_size); | 393 | memcpy(transfer_buffer, buf, transfer_size); |
371 | 394 | ||
372 | usb_fill_bulk_urb ( | 395 | usb_fill_bulk_urb( |
373 | port->write_urb, | 396 | port->write_urb, |
374 | port->serial->dev, | 397 | port->serial->dev, |
375 | usb_sndbulkpipe(port->serial->dev, | 398 | usb_sndbulkpipe(port->serial->dev, |
@@ -381,17 +404,19 @@ static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int | |||
381 | 404 | ||
382 | port->write_urb->transfer_flags = URB_ZERO_PACKET; | 405 | port->write_urb->transfer_flags = URB_ZERO_PACKET; |
383 | 406 | ||
384 | result = usb_submit_urb (port->write_urb, GFP_ATOMIC); | 407 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); |
385 | if (result) { | 408 | if (result) { |
386 | port->write_urb_busy = 0; | 409 | port->write_urb_busy = 0; |
387 | dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result); | 410 | dev_err(&port->dev, |
411 | "%s - failed submitting write urb, error %d\n", | ||
412 | __func__, result); | ||
388 | } else | 413 | } else |
389 | result = transfer_size; | 414 | result = transfer_size; |
390 | 415 | ||
391 | return result; | 416 | return result; |
392 | } | 417 | } |
393 | 418 | ||
394 | static void ir_write_bulk_callback (struct urb *urb) | 419 | static void ir_write_bulk_callback(struct urb *urb) |
395 | { | 420 | { |
396 | struct usb_serial_port *port = urb->context; | 421 | struct usb_serial_port *port = urb->context; |
397 | int status = urb->status; | 422 | int status = urb->status; |
@@ -405,7 +430,7 @@ static void ir_write_bulk_callback (struct urb *urb) | |||
405 | return; | 430 | return; |
406 | } | 431 | } |
407 | 432 | ||
408 | usb_serial_debug_data ( | 433 | usb_serial_debug_data( |
409 | debug, | 434 | debug, |
410 | &port->dev, | 435 | &port->dev, |
411 | __func__, | 436 | __func__, |
@@ -415,7 +440,7 @@ static void ir_write_bulk_callback (struct urb *urb) | |||
415 | usb_serial_port_softint(port); | 440 | usb_serial_port_softint(port); |
416 | } | 441 | } |
417 | 442 | ||
418 | static void ir_read_bulk_callback (struct urb *urb) | 443 | static void ir_read_bulk_callback(struct urb *urb) |
419 | { | 444 | { |
420 | struct usb_serial_port *port = urb->context; | 445 | struct usb_serial_port *port = urb->context; |
421 | struct tty_struct *tty; | 446 | struct tty_struct *tty; |
@@ -431,68 +456,69 @@ static void ir_read_bulk_callback (struct urb *urb) | |||
431 | } | 456 | } |
432 | 457 | ||
433 | switch (status) { | 458 | switch (status) { |
434 | case 0: /* Successful */ | 459 | case 0: /* Successful */ |
435 | 460 | ||
436 | /* | 461 | /* |
437 | * The first byte of the packet we get from the device | 462 | * The first byte of the packet we get from the device |
438 | * contains a busy indicator and baud rate change. | 463 | * contains a busy indicator and baud rate change. |
439 | * See section 5.4.1.2 of the USB IrDA spec. | 464 | * See section 5.4.1.2 of the USB IrDA spec. |
440 | */ | 465 | */ |
441 | if ((*data & 0x0f) > 0) | 466 | if ((*data & 0x0f) > 0) |
442 | ir_baud = *data & 0x0f; | 467 | ir_baud = *data & 0x0f; |
443 | 468 | ||
444 | usb_serial_debug_data ( | 469 | usb_serial_debug_data( |
445 | debug, | 470 | debug, |
446 | &port->dev, | 471 | &port->dev, |
447 | __func__, | 472 | __func__, |
448 | urb->actual_length, | 473 | urb->actual_length, |
449 | data); | 474 | data); |
450 | 475 | ||
451 | tty = port->tty; | 476 | tty = port->tty; |
452 | 477 | ||
453 | if (tty_buffer_request_room(tty, urb->actual_length - 1)) { | 478 | if (tty_buffer_request_room(tty, urb->actual_length - 1)) { |
454 | tty_insert_flip_string(tty, data+1, urb->actual_length - 1); | 479 | tty_insert_flip_string(tty, data + 1, |
455 | tty_flip_buffer_push(tty); | 480 | urb->actual_length - 1); |
456 | } | 481 | tty_flip_buffer_push(tty); |
457 | 482 | } | |
458 | /* | ||
459 | * No break here. | ||
460 | * We want to resubmit the urb so we can read | ||
461 | * again. | ||
462 | */ | ||
463 | |||
464 | case -EPROTO: /* taking inspiration from pl2303.c */ | ||
465 | |||
466 | /* Continue trying to always read */ | ||
467 | usb_fill_bulk_urb ( | ||
468 | port->read_urb, | ||
469 | port->serial->dev, | ||
470 | usb_rcvbulkpipe(port->serial->dev, | ||
471 | port->bulk_in_endpointAddress), | ||
472 | port->read_urb->transfer_buffer, | ||
473 | port->read_urb->transfer_buffer_length, | ||
474 | ir_read_bulk_callback, | ||
475 | port); | ||
476 | |||
477 | result = usb_submit_urb(port->read_urb, GFP_ATOMIC); | ||
478 | if (result) | ||
479 | dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", | ||
480 | __func__, result); | ||
481 | |||
482 | break ; | ||
483 | |||
484 | default: | ||
485 | dbg("%s - nonzero read bulk status received: %d", | ||
486 | __func__, | ||
487 | status); | ||
488 | break ; | ||
489 | 483 | ||
484 | /* | ||
485 | * No break here. | ||
486 | * We want to resubmit the urb so we can read | ||
487 | * again. | ||
488 | */ | ||
489 | |||
490 | case -EPROTO: /* taking inspiration from pl2303.c */ | ||
491 | |||
492 | /* Continue trying to always read */ | ||
493 | usb_fill_bulk_urb( | ||
494 | port->read_urb, | ||
495 | port->serial->dev, | ||
496 | usb_rcvbulkpipe(port->serial->dev, | ||
497 | port->bulk_in_endpointAddress), | ||
498 | port->read_urb->transfer_buffer, | ||
499 | port->read_urb->transfer_buffer_length, | ||
500 | ir_read_bulk_callback, | ||
501 | port); | ||
502 | |||
503 | result = usb_submit_urb(port->read_urb, GFP_ATOMIC); | ||
504 | if (result) | ||
505 | dev_err(&port->dev, | ||
506 | "%s - failed resubmitting read urb, error %d\n", | ||
507 | __func__, result); | ||
508 | break; | ||
509 | |||
510 | default: | ||
511 | dbg("%s - nonzero read bulk status received: %d", | ||
512 | __func__, | ||
513 | status); | ||
514 | break; | ||
490 | } | 515 | } |
491 | 516 | ||
492 | return; | 517 | return; |
493 | } | 518 | } |
494 | 519 | ||
495 | static void ir_set_termios (struct usb_serial_port *port, struct ktermios *old_termios) | 520 | static void ir_set_termios(struct usb_serial_port *port, |
521 | struct ktermios *old_termios) | ||
496 | { | 522 | { |
497 | unsigned char *transfer_buffer; | 523 | unsigned char *transfer_buffer; |
498 | int result; | 524 | int result; |
@@ -510,19 +536,36 @@ static void ir_set_termios (struct usb_serial_port *port, struct ktermios *old_t | |||
510 | */ | 536 | */ |
511 | 537 | ||
512 | switch (baud) { | 538 | switch (baud) { |
513 | case 2400: ir_baud = SPEED_2400; break; | 539 | case 2400: |
514 | case 9600: ir_baud = SPEED_9600; break; | 540 | ir_baud = USB_IRDA_BR_2400; |
515 | case 19200: ir_baud = SPEED_19200; break; | 541 | break; |
516 | case 38400: ir_baud = SPEED_38400; break; | 542 | case 9600: |
517 | case 57600: ir_baud = SPEED_57600; break; | 543 | ir_baud = USB_IRDA_BR_9600; |
518 | case 115200: ir_baud = SPEED_115200; break; | 544 | break; |
519 | case 576000: ir_baud = SPEED_576000; break; | 545 | case 19200: |
520 | case 1152000: ir_baud = SPEED_1152000; break; | 546 | ir_baud = USB_IRDA_BR_19200; |
521 | case 4000000: ir_baud = SPEED_4000000; break; | 547 | break; |
522 | break; | 548 | case 38400: |
523 | default: | 549 | ir_baud = USB_IRDA_BR_38400; |
524 | ir_baud = SPEED_9600; | 550 | break; |
525 | baud = 9600; | 551 | case 57600: |
552 | ir_baud = USB_IRDA_BR_57600; | ||
553 | break; | ||
554 | case 115200: | ||
555 | ir_baud = USB_IRDA_BR_115200; | ||
556 | break; | ||
557 | case 576000: | ||
558 | ir_baud = USB_IRDA_BR_576000; | ||
559 | break; | ||
560 | case 1152000: | ||
561 | ir_baud = USB_IRDA_BR_1152000; | ||
562 | break; | ||
563 | case 4000000: | ||
564 | ir_baud = USB_IRDA_BR_4000000; | ||
565 | break; | ||
566 | default: | ||
567 | ir_baud = USB_IRDA_BR_9600; | ||
568 | baud = 9600; | ||
526 | } | 569 | } |
527 | 570 | ||
528 | if (xbof == -1) | 571 | if (xbof == -1) |
@@ -538,10 +581,11 @@ static void ir_set_termios (struct usb_serial_port *port, struct ktermios *old_t | |||
538 | transfer_buffer = port->write_urb->transfer_buffer; | 581 | transfer_buffer = port->write_urb->transfer_buffer; |
539 | *transfer_buffer = ir_xbof | ir_baud; | 582 | *transfer_buffer = ir_xbof | ir_baud; |
540 | 583 | ||
541 | usb_fill_bulk_urb ( | 584 | usb_fill_bulk_urb( |
542 | port->write_urb, | 585 | port->write_urb, |
543 | port->serial->dev, | 586 | port->serial->dev, |
544 | usb_sndbulkpipe(port->serial->dev, port->bulk_out_endpointAddress), | 587 | usb_sndbulkpipe(port->serial->dev, |
588 | port->bulk_out_endpointAddress), | ||
545 | port->write_urb->transfer_buffer, | 589 | port->write_urb->transfer_buffer, |
546 | 1, | 590 | 1, |
547 | ir_write_bulk_callback, | 591 | ir_write_bulk_callback, |
@@ -549,38 +593,44 @@ static void ir_set_termios (struct usb_serial_port *port, struct ktermios *old_t | |||
549 | 593 | ||
550 | port->write_urb->transfer_flags = URB_ZERO_PACKET; | 594 | port->write_urb->transfer_flags = URB_ZERO_PACKET; |
551 | 595 | ||
552 | result = usb_submit_urb (port->write_urb, GFP_KERNEL); | 596 | result = usb_submit_urb(port->write_urb, GFP_KERNEL); |
553 | if (result) | 597 | if (result) |
554 | dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result); | 598 | dev_err(&port->dev, |
599 | "%s - failed submitting write urb, error %d\n", | ||
600 | __func__, result); | ||
555 | 601 | ||
556 | /* Only speed changes are supported */ | 602 | /* Only speed changes are supported */ |
557 | tty_termios_copy_hw(port->tty->termios, old_termios); | 603 | tty_termios_copy_hw(port->tty->termios, old_termios); |
558 | tty_encode_baud_rate(port->tty, baud, baud); | 604 | tty_encode_baud_rate(port->tty, baud, baud); |
559 | } | 605 | } |
560 | 606 | ||
561 | 607 | static int __init ir_init(void) | |
562 | static int __init ir_init (void) | ||
563 | { | 608 | { |
564 | int retval; | 609 | int retval; |
610 | |||
565 | retval = usb_serial_register(&ir_device); | 611 | retval = usb_serial_register(&ir_device); |
566 | if (retval) | 612 | if (retval) |
567 | goto failed_usb_serial_register; | 613 | goto failed_usb_serial_register; |
614 | |||
568 | retval = usb_register(&ir_driver); | 615 | retval = usb_register(&ir_driver); |
569 | if (retval) | 616 | if (retval) |
570 | goto failed_usb_register; | 617 | goto failed_usb_register; |
618 | |||
571 | info(DRIVER_DESC " " DRIVER_VERSION); | 619 | info(DRIVER_DESC " " DRIVER_VERSION); |
620 | |||
572 | return 0; | 621 | return 0; |
622 | |||
573 | failed_usb_register: | 623 | failed_usb_register: |
574 | usb_serial_deregister(&ir_device); | 624 | usb_serial_deregister(&ir_device); |
625 | |||
575 | failed_usb_serial_register: | 626 | failed_usb_serial_register: |
576 | return retval; | 627 | return retval; |
577 | } | 628 | } |
578 | 629 | ||
579 | 630 | static void __exit ir_exit(void) | |
580 | static void __exit ir_exit (void) | ||
581 | { | 631 | { |
582 | usb_deregister (&ir_driver); | 632 | usb_deregister(&ir_driver); |
583 | usb_serial_deregister (&ir_device); | 633 | usb_serial_deregister(&ir_device); |
584 | } | 634 | } |
585 | 635 | ||
586 | 636 | ||