blob: a6ab5b58d9ca5c6456a9a56eb7606e4fb18c4b0e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * USB Empeg empeg-car player driver
3 *
4 * Copyright (C) 2000, 2001
5 * Gary Brubaker (xavyer@ix.netcom.com)
6 *
7 * Copyright (C) 1999 - 2001
8 * Greg Kroah-Hartman (greg@kroah.com)
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License, as published by
12 * the Free Software Foundation, version 2.
13 *
Alan Cox93c46792008-07-22 11:11:11 +010014 * See Documentation/usb/usb-serial.txt for more information on using this
15 * driver
16 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 * (07/16/2001) gb
Alan Cox93c46792008-07-22 11:11:11 +010018 * remove unused code in empeg_close() (thanks to Oliver Neukum for
19 * pointing this out) and rewrote empeg_set_termios().
20 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 * (05/30/2001) gkh
Alan Cox93c46792008-07-22 11:11:11 +010022 * switched from using spinlock to a semaphore, which fixes lots of
23 * problems.
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 *
25 * (04/08/2001) gb
26 * Identify version on module load.
Alan Cox93c46792008-07-22 11:11:11 +010027 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 * (01/22/2001) gb
Alan Cox93c46792008-07-22 11:11:11 +010029 * Added write_room() and chars_in_buffer() support.
30 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 * (12/21/2000) gb
32 * Moved termio stuff inside the port->active check.
33 * Moved MOD_DEC_USE_COUNT to end of empeg_close().
Alan Cox93c46792008-07-22 11:11:11 +010034 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 * (12/03/2000) gb
Alan Cox93c46792008-07-22 11:11:11 +010036 * Added port->port.tty->ldisc.set_termios(port->port.tty, NULL) to
37 * empeg_open(). This notifies the tty driver that the termios have
38 * changed.
39 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 * (11/13/2000) gb
Alan Cox93c46792008-07-22 11:11:11 +010041 * Moved tty->low_latency = 1 from empeg_read_bulk_callback() to
42 * empeg_open() (It only needs to be set once - Doh!)
43 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 * (11/11/2000) gb
45 * Updated to work with id_table structure.
Alan Cox93c46792008-07-22 11:11:11 +010046 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 * (11/04/2000) gb
48 * Forked this from visor.c, and hacked it up to work with an
49 * Empeg ltd. empeg-car player. Constructive criticism welcomed.
50 * I would like to say, 'Thank You' to Greg Kroah-Hartman for the
51 * use of his code, and for his guidance, advice and patience. :)
52 * A 'Thank You' is in order for John Ripley of Empeg ltd for his
53 * advice, and patience too.
Alan Cox93c46792008-07-22 11:11:11 +010054 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 */
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#include <linux/kernel.h>
58#include <linux/errno.h>
59#include <linux/init.h>
60#include <linux/slab.h>
61#include <linux/tty.h>
62#include <linux/tty_driver.h>
63#include <linux/tty_flip.h>
64#include <linux/module.h>
65#include <linux/spinlock.h>
Alan Cox93c46792008-07-22 11:11:11 +010066#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#include <linux/usb.h>
Greg Kroah-Hartmana9698882006-07-11 21:22:58 -070068#include <linux/usb/serial.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70static int debug;
71
72/*
73 * Version Information
74 */
75#define DRIVER_VERSION "v1.2"
76#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Gary Brubaker <xavyer@ix.netcom.com>"
77#define DRIVER_DESC "USB Empeg Mark I/II Driver"
78
79#define EMPEG_VENDOR_ID 0x084f
80#define EMPEG_PRODUCT_ID 0x0001
81
82/* function prototypes for an empeg-car player */
Alan Cox93c46792008-07-22 11:11:11 +010083static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port,
84 struct file *filp);
85static void empeg_close(struct tty_struct *tty, struct usb_serial_port *port,
86 struct file *filp);
87static int empeg_write(struct tty_struct *tty, struct usb_serial_port *port,
88 const unsigned char *buf,
89 int count);
90static int empeg_write_room(struct tty_struct *tty);
91static int empeg_chars_in_buffer(struct tty_struct *tty);
92static void empeg_throttle(struct tty_struct *tty);
93static void empeg_unthrottle(struct tty_struct *tty);
94static int empeg_startup(struct usb_serial *serial);
95static void empeg_shutdown(struct usb_serial *serial);
96static void empeg_set_termios(struct tty_struct *tty,
97 struct usb_serial_port *port, struct ktermios *old_termios);
98static void empeg_write_bulk_callback(struct urb *urb);
99static void empeg_read_bulk_callback(struct urb *urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101static struct usb_device_id id_table [] = {
102 { USB_DEVICE(EMPEG_VENDOR_ID, EMPEG_PRODUCT_ID) },
103 { } /* Terminating entry */
104};
105
Alan Cox93c46792008-07-22 11:11:11 +0100106MODULE_DEVICE_TABLE(usb, id_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108static struct usb_driver empeg_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 .name = "empeg",
110 .probe = usb_serial_probe,
111 .disconnect = usb_serial_disconnect,
112 .id_table = id_table,
Greg Kroah-Hartmanba9dc652005-11-16 13:41:28 -0800113 .no_dynamic_id = 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114};
115
Greg Kroah-Hartmanea653702005-06-20 21:15:16 -0700116static struct usb_serial_driver empeg_device = {
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -0700117 .driver = {
118 .owner = THIS_MODULE,
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700119 .name = "empeg",
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -0700120 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 .id_table = id_table,
Johannes Hölzld9b1b782006-12-17 21:50:24 +0100122 .usb_driver = &empeg_driver,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 .num_ports = 1,
124 .open = empeg_open,
125 .close = empeg_close,
126 .throttle = empeg_throttle,
127 .unthrottle = empeg_unthrottle,
128 .attach = empeg_startup,
129 .shutdown = empeg_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 .set_termios = empeg_set_termios,
131 .write = empeg_write,
132 .write_room = empeg_write_room,
133 .chars_in_buffer = empeg_chars_in_buffer,
134 .write_bulk_callback = empeg_write_bulk_callback,
135 .read_bulk_callback = empeg_read_bulk_callback,
136};
137
138#define NUM_URBS 16
139#define URB_TRANSFER_BUFFER_SIZE 4096
140
141static struct urb *write_urb_pool[NUM_URBS];
142static spinlock_t write_urb_pool_lock;
143static int bytes_in;
144static int bytes_out;
145
146/******************************************************************************
147 * Empeg specific driver functions
148 ******************************************************************************/
Alan Cox95da3102008-07-22 11:09:07 +0100149static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port,
150 struct file *filp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151{
152 struct usb_serial *serial = port->serial;
153 int result = 0;
154
Harvey Harrison441b62c2008-03-03 16:08:34 -0800155 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
157 /* Force default termio settings */
Alan Cox93c46792008-07-22 11:11:11 +0100158 empeg_set_termios(tty, port, NULL) ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160 bytes_in = 0;
161 bytes_out = 0;
162
163 /* Start reading from the device */
164 usb_fill_bulk_urb(
165 port->read_urb,
Alan Cox93c46792008-07-22 11:11:11 +0100166 serial->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 usb_rcvbulkpipe(serial->dev,
168 port->bulk_in_endpointAddress),
169 port->read_urb->transfer_buffer,
170 port->read_urb->transfer_buffer_length,
171 empeg_read_bulk_callback,
172 port);
173
174 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
175
176 if (result)
Alan Cox93c46792008-07-22 11:11:11 +0100177 dev_err(&port->dev,
178 "%s - failed submitting read urb, error %d\n",
179 __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181 return result;
182}
183
184
Alan Cox95da3102008-07-22 11:09:07 +0100185static void empeg_close(struct tty_struct *tty, struct usb_serial_port *port,
Alan Cox93c46792008-07-22 11:11:11 +0100186 struct file *filp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
Harvey Harrison441b62c2008-03-03 16:08:34 -0800188 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190 /* shutdown our bulk read */
191 usb_kill_urb(port->read_urb);
192 /* Uncomment the following line if you want to see some statistics in your syslog */
193 /* dev_info (&port->dev, "Bytes In = %d Bytes Out = %d\n", bytes_in, bytes_out); */
194}
195
196
Alan Cox93c46792008-07-22 11:11:11 +0100197static int empeg_write(struct tty_struct *tty, struct usb_serial_port *port,
198 const unsigned char *buf, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199{
200 struct usb_serial *serial = port->serial;
201 struct urb *urb;
202 const unsigned char *current_position = buf;
203 unsigned long flags;
204 int status;
205 int i;
206 int bytes_sent = 0;
207 int transfer_size;
208
Harvey Harrison441b62c2008-03-03 16:08:34 -0800209 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211 while (count > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 /* try to find a free urb in our list of them */
213 urb = NULL;
214
Alan Cox93c46792008-07-22 11:11:11 +0100215 spin_lock_irqsave(&write_urb_pool_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 for (i = 0; i < NUM_URBS; ++i) {
218 if (write_urb_pool[i]->status != -EINPROGRESS) {
219 urb = write_urb_pool[i];
220 break;
221 }
222 }
223
Alan Cox93c46792008-07-22 11:11:11 +0100224 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226 if (urb == NULL) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800227 dbg("%s - no more free urbs", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 goto exit;
229 }
230
231 if (urb->transfer_buffer == NULL) {
Alan Cox93c46792008-07-22 11:11:11 +0100232 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 if (urb->transfer_buffer == NULL) {
Alan Cox93c46792008-07-22 11:11:11 +0100234 dev_err(&port->dev,
235 "%s no more kernel memory...\n",
236 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 goto exit;
238 }
239 }
240
Alan Cox93c46792008-07-22 11:11:11 +0100241 transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Alan Cox93c46792008-07-22 11:11:11 +0100243 memcpy(urb->transfer_buffer, current_position, transfer_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Harvey Harrison441b62c2008-03-03 16:08:34 -0800245 usb_serial_debug_data(debug, &port->dev, __func__, transfer_size, urb->transfer_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
247 /* build up our urb */
Alan Cox93c46792008-07-22 11:11:11 +0100248 usb_fill_bulk_urb(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 urb,
250 serial->dev,
251 usb_sndbulkpipe(serial->dev,
Alan Cox93c46792008-07-22 11:11:11 +0100252 port->bulk_out_endpointAddress),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 urb->transfer_buffer,
254 transfer_size,
255 empeg_write_bulk_callback,
256 port);
257
258 /* send it down the pipe */
259 status = usb_submit_urb(urb, GFP_ATOMIC);
260 if (status) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800261 dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed with status = %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 bytes_sent = status;
263 break;
264 }
265
266 current_position += transfer_size;
267 bytes_sent += transfer_size;
268 count -= transfer_size;
269 bytes_out += transfer_size;
270
271 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272exit:
273 return bytes_sent;
Alan Cox93c46792008-07-22 11:11:11 +0100274}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
276
Alan Cox95da3102008-07-22 11:09:07 +0100277static int empeg_write_room(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
Alan Cox95da3102008-07-22 11:09:07 +0100279 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 unsigned long flags;
281 int i;
282 int room = 0;
283
Harvey Harrison441b62c2008-03-03 16:08:34 -0800284 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Alan Cox93c46792008-07-22 11:11:11 +0100286 spin_lock_irqsave(&write_urb_pool_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 /* tally up the number of bytes available */
288 for (i = 0; i < NUM_URBS; ++i) {
Alan Cox93c46792008-07-22 11:11:11 +0100289 if (write_urb_pool[i]->status != -EINPROGRESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 room += URB_TRANSFER_BUFFER_SIZE;
Alan Cox93c46792008-07-22 11:11:11 +0100291 }
292 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
Harvey Harrison441b62c2008-03-03 16:08:34 -0800293 dbg("%s - returns %d", __func__, room);
Alan Cox95da3102008-07-22 11:09:07 +0100294 return room;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296}
297
298
Alan Cox95da3102008-07-22 11:09:07 +0100299static int empeg_chars_in_buffer(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
Alan Cox95da3102008-07-22 11:09:07 +0100301 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 unsigned long flags;
303 int i;
304 int chars = 0;
305
Harvey Harrison441b62c2008-03-03 16:08:34 -0800306 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
Alan Cox93c46792008-07-22 11:11:11 +0100308 spin_lock_irqsave(&write_urb_pool_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
310 /* tally up the number of bytes waiting */
311 for (i = 0; i < NUM_URBS; ++i) {
Alan Cox93c46792008-07-22 11:11:11 +0100312 if (write_urb_pool[i]->status == -EINPROGRESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 chars += URB_TRANSFER_BUFFER_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 }
315
Alan Cox93c46792008-07-22 11:11:11 +0100316 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
Harvey Harrison441b62c2008-03-03 16:08:34 -0800317 dbg("%s - returns %d", __func__, chars);
Alan Cox93c46792008-07-22 11:11:11 +0100318 return chars;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319}
320
321
Alan Cox93c46792008-07-22 11:11:11 +0100322static void empeg_write_bulk_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323{
Greg Kroah-Hartman335202f2007-06-15 15:44:13 -0700324 struct usb_serial_port *port = urb->context;
325 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Harvey Harrison441b62c2008-03-03 16:08:34 -0800327 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Greg Kroah-Hartman335202f2007-06-15 15:44:13 -0700329 if (status) {
330 dbg("%s - nonzero write bulk status received: %d",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800331 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 return;
333 }
334
Pete Zaitcevcf2c7482006-05-22 21:58:49 -0700335 usb_serial_port_softint(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336}
337
338
Alan Cox93c46792008-07-22 11:11:11 +0100339static void empeg_read_bulk_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
Ming Leicdc97792008-02-24 18:41:47 +0800341 struct usb_serial_port *port = urb->context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 struct tty_struct *tty;
343 unsigned char *data = urb->transfer_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 int result;
Greg Kroah-Hartman335202f2007-06-15 15:44:13 -0700345 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
Harvey Harrison441b62c2008-03-03 16:08:34 -0800347 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
Greg Kroah-Hartman335202f2007-06-15 15:44:13 -0700349 if (status) {
350 dbg("%s - nonzero read bulk status received: %d",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800351 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 return;
353 }
354
Alan Cox93c46792008-07-22 11:11:11 +0100355 usb_serial_debug_data(debug, &port->dev, __func__,
356 urb->actual_length, data);
Alan Cox95da3102008-07-22 11:09:07 +0100357 tty = port->port.tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
359 if (urb->actual_length) {
Alan Cox33f0f882006-01-09 20:54:13 -0800360 tty_buffer_request_room(tty, urb->actual_length);
361 tty_insert_flip_string(tty, data, urb->actual_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 tty_flip_buffer_push(tty);
363 bytes_in += urb->actual_length;
364 }
365
366 /* Continue trying to always read */
367 usb_fill_bulk_urb(
368 port->read_urb,
Alan Cox93c46792008-07-22 11:11:11 +0100369 port->serial->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 usb_rcvbulkpipe(port->serial->dev,
371 port->bulk_in_endpointAddress),
372 port->read_urb->transfer_buffer,
373 port->read_urb->transfer_buffer_length,
374 empeg_read_bulk_callback,
375 port);
376
377 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
378
379 if (result)
Alan Cox93c46792008-07-22 11:11:11 +0100380 dev_err(&urb->dev->dev,
381 "%s - failed resubmitting read urb, error %d\n",
382 __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
384 return;
385
386}
387
388
Alan Cox95da3102008-07-22 11:09:07 +0100389static void empeg_throttle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390{
Alan Cox95da3102008-07-22 11:09:07 +0100391 struct usb_serial_port *port = tty->driver_data;
Harvey Harrison441b62c2008-03-03 16:08:34 -0800392 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 usb_kill_urb(port->read_urb);
394}
395
396
Alan Cox95da3102008-07-22 11:09:07 +0100397static void empeg_unthrottle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
Alan Cox95da3102008-07-22 11:09:07 +0100399 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 int result;
Harvey Harrison441b62c2008-03-03 16:08:34 -0800401 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
403 port->read_urb->dev = port->serial->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 if (result)
Alan Cox93c46792008-07-22 11:11:11 +0100406 dev_err(&port->dev,
407 "%s - failed submitting read urb, error %d\n",
408 __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409}
410
411
Alan Cox93c46792008-07-22 11:11:11 +0100412static int empeg_startup(struct usb_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413{
414 int r;
415
Harvey Harrison441b62c2008-03-03 16:08:34 -0800416 dbg("%s", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
418 if (serial->dev->actconfig->desc.bConfigurationValue != 1) {
419 err("active config #%d != 1 ??",
420 serial->dev->actconfig->desc.bConfigurationValue);
421 return -ENODEV;
422 }
Harvey Harrison441b62c2008-03-03 16:08:34 -0800423 dbg("%s - reset config", __func__);
Alan Cox93c46792008-07-22 11:11:11 +0100424 r = usb_reset_configuration(serial->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
426 /* continue on with initialization */
427 return r;
428
429}
430
431
Alan Cox93c46792008-07-22 11:11:11 +0100432static void empeg_shutdown(struct usb_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433{
Alan Cox93c46792008-07-22 11:11:11 +0100434 dbg("%s", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435}
436
437
Alan Cox95da3102008-07-22 11:09:07 +0100438static void empeg_set_termios(struct tty_struct *tty,
439 struct usb_serial_port *port, struct ktermios *old_termios)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
Alan Cox95da3102008-07-22 11:09:07 +0100441 struct ktermios *termios = tty->termios;
Harvey Harrison441b62c2008-03-03 16:08:34 -0800442 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 /*
Alan Cox93c46792008-07-22 11:11:11 +0100445 * The empeg-car player wants these particular tty settings.
446 * You could, for example, change the baud rate, however the
447 * player only supports 115200 (currently), so there is really
448 * no point in support for changes to the tty settings.
449 * (at least for now)
450 *
451 * The default requirements for this device are:
452 */
Alan Cox998e8632007-10-18 01:24:19 -0700453 termios->c_iflag
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 &= ~(IGNBRK /* disable ignore break */
455 | BRKINT /* disable break causes interrupt */
456 | PARMRK /* disable mark parity errors */
457 | ISTRIP /* disable clear high bit of input characters */
458 | INLCR /* disable translate NL to CR */
459 | IGNCR /* disable ignore CR */
460 | ICRNL /* disable translate CR to NL */
461 | IXON); /* disable enable XON/XOFF flow control */
462
Alan Cox998e8632007-10-18 01:24:19 -0700463 termios->c_oflag
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 &= ~OPOST; /* disable postprocess output characters */
465
Alan Cox998e8632007-10-18 01:24:19 -0700466 termios->c_lflag
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 &= ~(ECHO /* disable echo input characters */
468 | ECHONL /* disable echo new line */
469 | ICANON /* disable erase, kill, werase, and rprnt special characters */
470 | ISIG /* disable interrupt, quit, and suspend special characters */
471 | IEXTEN); /* disable non-POSIX special characters */
472
Alan Cox998e8632007-10-18 01:24:19 -0700473 termios->c_cflag
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 &= ~(CSIZE /* no size */
475 | PARENB /* disable parity bit */
476 | CBAUD); /* clear current baud rate */
477
Alan Cox998e8632007-10-18 01:24:19 -0700478 termios->c_cflag
479 |= CS8; /* character size 8 bits */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
481 /*
482 * Force low_latency on; otherwise the pushes are scheduled;
483 * this is bad as it opens up the possibility of dropping bytes
484 * on the floor. We don't want to drop bytes on the floor. :)
485 */
Alan Cox95da3102008-07-22 11:09:07 +0100486 tty->low_latency = 1;
487 tty_encode_baud_rate(tty, 115200, 115200);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488}
489
490
Alan Cox93c46792008-07-22 11:11:11 +0100491static int __init empeg_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492{
493 struct urb *urb;
494 int i, retval;
495
Alan Cox93c46792008-07-22 11:11:11 +0100496 /* create our write urb pool and transfer buffers */
497 spin_lock_init(&write_urb_pool_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 for (i = 0; i < NUM_URBS; ++i) {
499 urb = usb_alloc_urb(0, GFP_KERNEL);
500 write_urb_pool[i] = urb;
501 if (urb == NULL) {
502 err("No more urbs???");
503 continue;
504 }
505
Alan Cox93c46792008-07-22 11:11:11 +0100506 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE,
507 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 if (!urb->transfer_buffer) {
Alan Cox93c46792008-07-22 11:11:11 +0100509 err("%s - out of memory for urb buffers.",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800510 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 continue;
512 }
513 }
514
515 retval = usb_serial_register(&empeg_device);
516 if (retval)
517 goto failed_usb_serial_register;
518 retval = usb_register(&empeg_driver);
519 if (retval)
520 goto failed_usb_register;
521
522 info(DRIVER_VERSION ":" DRIVER_DESC);
523
524 return 0;
525failed_usb_register:
526 usb_serial_deregister(&empeg_device);
527failed_usb_serial_register:
528 for (i = 0; i < NUM_URBS; ++i) {
529 if (write_urb_pool[i]) {
Jesper Juhl1bc3c9e2005-04-18 17:39:34 -0700530 kfree(write_urb_pool[i]->transfer_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 usb_free_urb(write_urb_pool[i]);
532 }
533 }
534 return retval;
535}
536
537
Alan Cox93c46792008-07-22 11:11:11 +0100538static void __exit empeg_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539{
540 int i;
541 unsigned long flags;
542
543 usb_deregister(&empeg_driver);
Alan Cox93c46792008-07-22 11:11:11 +0100544 usb_serial_deregister(&empeg_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Alan Cox93c46792008-07-22 11:11:11 +0100546 spin_lock_irqsave(&write_urb_pool_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
548 for (i = 0; i < NUM_URBS; ++i) {
549 if (write_urb_pool[i]) {
Alan Cox93c46792008-07-22 11:11:11 +0100550 /* FIXME - uncomment the following usb_kill_urb call
551 * when the host controllers get fixed to set urb->dev
552 * = NULL after the urb is finished. Otherwise this
553 * call oopses. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 /* usb_kill_urb(write_urb_pool[i]); */
Jesper Juhl1bc3c9e2005-04-18 17:39:34 -0700555 kfree(write_urb_pool[i]->transfer_buffer);
Alan Cox93c46792008-07-22 11:11:11 +0100556 usb_free_urb(write_urb_pool[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 }
558 }
Alan Cox93c46792008-07-22 11:11:11 +0100559 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560}
561
562
563module_init(empeg_init);
564module_exit(empeg_exit);
565
Alan Cox93c46792008-07-22 11:11:11 +0100566MODULE_AUTHOR(DRIVER_AUTHOR);
567MODULE_DESCRIPTION(DRIVER_DESC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568MODULE_LICENSE("GPL");
569
570module_param(debug, bool, S_IRUGO | S_IWUSR);
571MODULE_PARM_DESC(debug, "Debug enabled or not");