blob: 80cb3471adbe0fe64cae662184aef149180a942b [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 Cox4a90f092008-10-13 10:39:46 +010036 * Added tty->ldisc.set_termios(port, tty, NULL) to empeg_open().
37 * This notifies the tty driver that the termios have changed.
Alan Cox93c46792008-07-22 11:11:11 +010038 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 * (11/13/2000) gb
Alan Cox93c46792008-07-22 11:11:11 +010040 * Moved tty->low_latency = 1 from empeg_read_bulk_callback() to
41 * empeg_open() (It only needs to be set once - Doh!)
42 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 * (11/11/2000) gb
44 * Updated to work with id_table structure.
Alan Cox93c46792008-07-22 11:11:11 +010045 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 * (11/04/2000) gb
47 * Forked this from visor.c, and hacked it up to work with an
48 * Empeg ltd. empeg-car player. Constructive criticism welcomed.
49 * I would like to say, 'Thank You' to Greg Kroah-Hartman for the
50 * use of his code, and for his guidance, advice and patience. :)
51 * A 'Thank You' is in order for John Ripley of Empeg ltd for his
52 * advice, and patience too.
Alan Cox93c46792008-07-22 11:11:11 +010053 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 */
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#include <linux/kernel.h>
57#include <linux/errno.h>
58#include <linux/init.h>
59#include <linux/slab.h>
60#include <linux/tty.h>
61#include <linux/tty_driver.h>
62#include <linux/tty_flip.h>
63#include <linux/module.h>
64#include <linux/spinlock.h>
Alan Cox93c46792008-07-22 11:11:11 +010065#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#include <linux/usb.h>
Greg Kroah-Hartmana9698882006-07-11 21:22:58 -070067#include <linux/usb/serial.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69static int debug;
70
71/*
72 * Version Information
73 */
74#define DRIVER_VERSION "v1.2"
75#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Gary Brubaker <xavyer@ix.netcom.com>"
76#define DRIVER_DESC "USB Empeg Mark I/II Driver"
77
78#define EMPEG_VENDOR_ID 0x084f
79#define EMPEG_PRODUCT_ID 0x0001
80
81/* function prototypes for an empeg-car player */
Alan Cox93c46792008-07-22 11:11:11 +010082static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port,
83 struct file *filp);
Alan Cox335f8512009-06-11 12:26:29 +010084static void empeg_close(struct usb_serial_port *port);
Alan Cox93c46792008-07-22 11:11:11 +010085static int empeg_write(struct tty_struct *tty, struct usb_serial_port *port,
86 const unsigned char *buf,
87 int count);
88static int empeg_write_room(struct tty_struct *tty);
89static int empeg_chars_in_buffer(struct tty_struct *tty);
90static void empeg_throttle(struct tty_struct *tty);
91static void empeg_unthrottle(struct tty_struct *tty);
92static int empeg_startup(struct usb_serial *serial);
Alan Cox93c46792008-07-22 11:11:11 +010093static void empeg_set_termios(struct tty_struct *tty,
94 struct usb_serial_port *port, struct ktermios *old_termios);
95static void empeg_write_bulk_callback(struct urb *urb);
96static void empeg_read_bulk_callback(struct urb *urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98static struct usb_device_id id_table [] = {
99 { USB_DEVICE(EMPEG_VENDOR_ID, EMPEG_PRODUCT_ID) },
100 { } /* Terminating entry */
101};
102
Alan Cox93c46792008-07-22 11:11:11 +0100103MODULE_DEVICE_TABLE(usb, id_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105static struct usb_driver empeg_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 .name = "empeg",
107 .probe = usb_serial_probe,
108 .disconnect = usb_serial_disconnect,
109 .id_table = id_table,
Greg Kroah-Hartmanba9dc652005-11-16 13:41:28 -0800110 .no_dynamic_id = 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111};
112
Greg Kroah-Hartmanea653702005-06-20 21:15:16 -0700113static struct usb_serial_driver empeg_device = {
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -0700114 .driver = {
115 .owner = THIS_MODULE,
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700116 .name = "empeg",
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -0700117 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 .id_table = id_table,
Johannes Hölzld9b1b782006-12-17 21:50:24 +0100119 .usb_driver = &empeg_driver,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 .num_ports = 1,
121 .open = empeg_open,
122 .close = empeg_close,
123 .throttle = empeg_throttle,
124 .unthrottle = empeg_unthrottle,
125 .attach = empeg_startup,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 .set_termios = empeg_set_termios,
127 .write = empeg_write,
128 .write_room = empeg_write_room,
129 .chars_in_buffer = empeg_chars_in_buffer,
130 .write_bulk_callback = empeg_write_bulk_callback,
131 .read_bulk_callback = empeg_read_bulk_callback,
132};
133
134#define NUM_URBS 16
135#define URB_TRANSFER_BUFFER_SIZE 4096
136
137static struct urb *write_urb_pool[NUM_URBS];
138static spinlock_t write_urb_pool_lock;
139static int bytes_in;
140static int bytes_out;
141
142/******************************************************************************
143 * Empeg specific driver functions
144 ******************************************************************************/
Alan Cox95da3102008-07-22 11:09:07 +0100145static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port,
146 struct file *filp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
148 struct usb_serial *serial = port->serial;
149 int result = 0;
150
Harvey Harrison441b62c2008-03-03 16:08:34 -0800151 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153 /* Force default termio settings */
Alan Cox93c46792008-07-22 11:11:11 +0100154 empeg_set_termios(tty, port, NULL) ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
156 bytes_in = 0;
157 bytes_out = 0;
158
159 /* Start reading from the device */
160 usb_fill_bulk_urb(
161 port->read_urb,
Alan Cox93c46792008-07-22 11:11:11 +0100162 serial->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 usb_rcvbulkpipe(serial->dev,
164 port->bulk_in_endpointAddress),
165 port->read_urb->transfer_buffer,
166 port->read_urb->transfer_buffer_length,
167 empeg_read_bulk_callback,
168 port);
169
170 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
171
172 if (result)
Alan Cox93c46792008-07-22 11:11:11 +0100173 dev_err(&port->dev,
174 "%s - failed submitting read urb, error %d\n",
175 __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
177 return result;
178}
179
180
Alan Cox335f8512009-06-11 12:26:29 +0100181static void empeg_close(struct usb_serial_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182{
Harvey Harrison441b62c2008-03-03 16:08:34 -0800183 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185 /* shutdown our bulk read */
186 usb_kill_urb(port->read_urb);
187 /* Uncomment the following line if you want to see some statistics in your syslog */
188 /* dev_info (&port->dev, "Bytes In = %d Bytes Out = %d\n", bytes_in, bytes_out); */
189}
190
191
Alan Cox93c46792008-07-22 11:11:11 +0100192static int empeg_write(struct tty_struct *tty, struct usb_serial_port *port,
193 const unsigned char *buf, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
195 struct usb_serial *serial = port->serial;
196 struct urb *urb;
197 const unsigned char *current_position = buf;
198 unsigned long flags;
199 int status;
200 int i;
201 int bytes_sent = 0;
202 int transfer_size;
203
Harvey Harrison441b62c2008-03-03 16:08:34 -0800204 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206 while (count > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 /* try to find a free urb in our list of them */
208 urb = NULL;
209
Alan Cox93c46792008-07-22 11:11:11 +0100210 spin_lock_irqsave(&write_urb_pool_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212 for (i = 0; i < NUM_URBS; ++i) {
213 if (write_urb_pool[i]->status != -EINPROGRESS) {
214 urb = write_urb_pool[i];
215 break;
216 }
217 }
218
Alan Cox93c46792008-07-22 11:11:11 +0100219 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221 if (urb == NULL) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800222 dbg("%s - no more free urbs", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 goto exit;
224 }
225
226 if (urb->transfer_buffer == NULL) {
Alan Cox93c46792008-07-22 11:11:11 +0100227 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 if (urb->transfer_buffer == NULL) {
Alan Cox93c46792008-07-22 11:11:11 +0100229 dev_err(&port->dev,
230 "%s no more kernel memory...\n",
231 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 goto exit;
233 }
234 }
235
Alan Cox93c46792008-07-22 11:11:11 +0100236 transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Alan Cox93c46792008-07-22 11:11:11 +0100238 memcpy(urb->transfer_buffer, current_position, transfer_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Harvey Harrison441b62c2008-03-03 16:08:34 -0800240 usb_serial_debug_data(debug, &port->dev, __func__, transfer_size, urb->transfer_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
242 /* build up our urb */
Alan Cox93c46792008-07-22 11:11:11 +0100243 usb_fill_bulk_urb(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 urb,
245 serial->dev,
246 usb_sndbulkpipe(serial->dev,
Alan Cox93c46792008-07-22 11:11:11 +0100247 port->bulk_out_endpointAddress),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 urb->transfer_buffer,
249 transfer_size,
250 empeg_write_bulk_callback,
251 port);
252
253 /* send it down the pipe */
254 status = usb_submit_urb(urb, GFP_ATOMIC);
255 if (status) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800256 dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed with status = %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 bytes_sent = status;
258 break;
259 }
260
261 current_position += transfer_size;
262 bytes_sent += transfer_size;
263 count -= transfer_size;
264 bytes_out += transfer_size;
265
266 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267exit:
268 return bytes_sent;
Alan Cox93c46792008-07-22 11:11:11 +0100269}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
271
Alan Cox95da3102008-07-22 11:09:07 +0100272static int empeg_write_room(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273{
Alan Cox95da3102008-07-22 11:09:07 +0100274 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 unsigned long flags;
276 int i;
277 int room = 0;
278
Harvey Harrison441b62c2008-03-03 16:08:34 -0800279 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
Alan Cox93c46792008-07-22 11:11:11 +0100281 spin_lock_irqsave(&write_urb_pool_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 /* tally up the number of bytes available */
283 for (i = 0; i < NUM_URBS; ++i) {
Alan Cox93c46792008-07-22 11:11:11 +0100284 if (write_urb_pool[i]->status != -EINPROGRESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 room += URB_TRANSFER_BUFFER_SIZE;
Alan Cox93c46792008-07-22 11:11:11 +0100286 }
287 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
Harvey Harrison441b62c2008-03-03 16:08:34 -0800288 dbg("%s - returns %d", __func__, room);
Alan Cox95da3102008-07-22 11:09:07 +0100289 return room;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
291}
292
293
Alan Cox95da3102008-07-22 11:09:07 +0100294static int empeg_chars_in_buffer(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
Alan Cox95da3102008-07-22 11:09:07 +0100296 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 unsigned long flags;
298 int i;
299 int chars = 0;
300
Harvey Harrison441b62c2008-03-03 16:08:34 -0800301 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Alan Cox93c46792008-07-22 11:11:11 +0100303 spin_lock_irqsave(&write_urb_pool_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
305 /* tally up the number of bytes waiting */
306 for (i = 0; i < NUM_URBS; ++i) {
Alan Cox93c46792008-07-22 11:11:11 +0100307 if (write_urb_pool[i]->status == -EINPROGRESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 chars += URB_TRANSFER_BUFFER_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 }
310
Alan Cox93c46792008-07-22 11:11:11 +0100311 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
Harvey Harrison441b62c2008-03-03 16:08:34 -0800312 dbg("%s - returns %d", __func__, chars);
Alan Cox93c46792008-07-22 11:11:11 +0100313 return chars;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314}
315
316
Alan Cox93c46792008-07-22 11:11:11 +0100317static void empeg_write_bulk_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318{
Greg Kroah-Hartman335202f2007-06-15 15:44:13 -0700319 struct usb_serial_port *port = urb->context;
320 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
Harvey Harrison441b62c2008-03-03 16:08:34 -0800322 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Greg Kroah-Hartman335202f2007-06-15 15:44:13 -0700324 if (status) {
325 dbg("%s - nonzero write bulk status received: %d",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800326 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 return;
328 }
329
Pete Zaitcevcf2c7482006-05-22 21:58:49 -0700330 usb_serial_port_softint(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331}
332
333
Alan Cox93c46792008-07-22 11:11:11 +0100334static void empeg_read_bulk_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335{
Ming Leicdc97792008-02-24 18:41:47 +0800336 struct usb_serial_port *port = urb->context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 struct tty_struct *tty;
338 unsigned char *data = urb->transfer_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 int result;
Greg Kroah-Hartman335202f2007-06-15 15:44:13 -0700340 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Harvey Harrison441b62c2008-03-03 16:08:34 -0800342 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Greg Kroah-Hartman335202f2007-06-15 15:44:13 -0700344 if (status) {
345 dbg("%s - nonzero read bulk status received: %d",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800346 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 return;
348 }
349
Alan Cox93c46792008-07-22 11:11:11 +0100350 usb_serial_debug_data(debug, &port->dev, __func__,
351 urb->actual_length, data);
Alan Cox4a90f092008-10-13 10:39:46 +0100352 tty = tty_port_tty_get(&port->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
354 if (urb->actual_length) {
Alan Cox33f0f882006-01-09 20:54:13 -0800355 tty_buffer_request_room(tty, urb->actual_length);
356 tty_insert_flip_string(tty, data, urb->actual_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 tty_flip_buffer_push(tty);
358 bytes_in += urb->actual_length;
359 }
Alan Cox4a90f092008-10-13 10:39:46 +0100360 tty_kref_put(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362 /* Continue trying to always read */
363 usb_fill_bulk_urb(
364 port->read_urb,
Alan Cox93c46792008-07-22 11:11:11 +0100365 port->serial->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 usb_rcvbulkpipe(port->serial->dev,
367 port->bulk_in_endpointAddress),
368 port->read_urb->transfer_buffer,
369 port->read_urb->transfer_buffer_length,
370 empeg_read_bulk_callback,
371 port);
372
373 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
374
375 if (result)
Alan Cox93c46792008-07-22 11:11:11 +0100376 dev_err(&urb->dev->dev,
377 "%s - failed resubmitting read urb, error %d\n",
378 __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
380 return;
381
382}
383
384
Alan Cox95da3102008-07-22 11:09:07 +0100385static void empeg_throttle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386{
Alan Cox95da3102008-07-22 11:09:07 +0100387 struct usb_serial_port *port = tty->driver_data;
Harvey Harrison441b62c2008-03-03 16:08:34 -0800388 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 usb_kill_urb(port->read_urb);
390}
391
392
Alan Cox95da3102008-07-22 11:09:07 +0100393static void empeg_unthrottle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394{
Alan Cox95da3102008-07-22 11:09:07 +0100395 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 int result;
Harvey Harrison441b62c2008-03-03 16:08:34 -0800397 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
399 port->read_urb->dev = port->serial->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 if (result)
Alan Cox93c46792008-07-22 11:11:11 +0100402 dev_err(&port->dev,
403 "%s - failed submitting read urb, error %d\n",
404 __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405}
406
407
Alan Cox93c46792008-07-22 11:11:11 +0100408static int empeg_startup(struct usb_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409{
410 int r;
411
Harvey Harrison441b62c2008-03-03 16:08:34 -0800412 dbg("%s", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
414 if (serial->dev->actconfig->desc.bConfigurationValue != 1) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700415 dev_err(&serial->dev->dev, "active config #%d != 1 ??\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 serial->dev->actconfig->desc.bConfigurationValue);
417 return -ENODEV;
418 }
Harvey Harrison441b62c2008-03-03 16:08:34 -0800419 dbg("%s - reset config", __func__);
Alan Cox93c46792008-07-22 11:11:11 +0100420 r = usb_reset_configuration(serial->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
422 /* continue on with initialization */
423 return r;
424
425}
426
427
Alan Cox95da3102008-07-22 11:09:07 +0100428static void empeg_set_termios(struct tty_struct *tty,
429 struct usb_serial_port *port, struct ktermios *old_termios)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
Alan Cox95da3102008-07-22 11:09:07 +0100431 struct ktermios *termios = tty->termios;
Harvey Harrison441b62c2008-03-03 16:08:34 -0800432 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 /*
Alan Cox93c46792008-07-22 11:11:11 +0100435 * The empeg-car player wants these particular tty settings.
436 * You could, for example, change the baud rate, however the
437 * player only supports 115200 (currently), so there is really
438 * no point in support for changes to the tty settings.
439 * (at least for now)
440 *
441 * The default requirements for this device are:
442 */
Alan Cox998e8632007-10-18 01:24:19 -0700443 termios->c_iflag
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 &= ~(IGNBRK /* disable ignore break */
445 | BRKINT /* disable break causes interrupt */
446 | PARMRK /* disable mark parity errors */
447 | ISTRIP /* disable clear high bit of input characters */
448 | INLCR /* disable translate NL to CR */
449 | IGNCR /* disable ignore CR */
450 | ICRNL /* disable translate CR to NL */
451 | IXON); /* disable enable XON/XOFF flow control */
452
Alan Cox998e8632007-10-18 01:24:19 -0700453 termios->c_oflag
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 &= ~OPOST; /* disable postprocess output characters */
455
Alan Cox998e8632007-10-18 01:24:19 -0700456 termios->c_lflag
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 &= ~(ECHO /* disable echo input characters */
458 | ECHONL /* disable echo new line */
459 | ICANON /* disable erase, kill, werase, and rprnt special characters */
460 | ISIG /* disable interrupt, quit, and suspend special characters */
461 | IEXTEN); /* disable non-POSIX special characters */
462
Alan Cox998e8632007-10-18 01:24:19 -0700463 termios->c_cflag
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 &= ~(CSIZE /* no size */
465 | PARENB /* disable parity bit */
466 | CBAUD); /* clear current baud rate */
467
Alan Cox998e8632007-10-18 01:24:19 -0700468 termios->c_cflag
469 |= CS8; /* character size 8 bits */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
Alan Cox95da3102008-07-22 11:09:07 +0100471 tty_encode_baud_rate(tty, 115200, 115200);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472}
473
474
Alan Cox93c46792008-07-22 11:11:11 +0100475static int __init empeg_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476{
477 struct urb *urb;
478 int i, retval;
479
Alan Cox93c46792008-07-22 11:11:11 +0100480 /* create our write urb pool and transfer buffers */
481 spin_lock_init(&write_urb_pool_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 for (i = 0; i < NUM_URBS; ++i) {
483 urb = usb_alloc_urb(0, GFP_KERNEL);
484 write_urb_pool[i] = urb;
485 if (urb == NULL) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700486 printk(KERN_ERR "empeg: No more urbs???\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 continue;
488 }
489
Alan Cox93c46792008-07-22 11:11:11 +0100490 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE,
491 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 if (!urb->transfer_buffer) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700493 printk(KERN_ERR "empeg: %s - out of memory for urb "
494 "buffers.", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 continue;
496 }
497 }
498
499 retval = usb_serial_register(&empeg_device);
500 if (retval)
501 goto failed_usb_serial_register;
502 retval = usb_register(&empeg_driver);
503 if (retval)
504 goto failed_usb_register;
505
Greg Kroah-Hartmanc197a8d2008-08-18 13:21:04 -0700506 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
507 DRIVER_DESC "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
509 return 0;
510failed_usb_register:
511 usb_serial_deregister(&empeg_device);
512failed_usb_serial_register:
513 for (i = 0; i < NUM_URBS; ++i) {
514 if (write_urb_pool[i]) {
Jesper Juhl1bc3c9e2005-04-18 17:39:34 -0700515 kfree(write_urb_pool[i]->transfer_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 usb_free_urb(write_urb_pool[i]);
517 }
518 }
519 return retval;
520}
521
522
Alan Cox93c46792008-07-22 11:11:11 +0100523static void __exit empeg_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524{
525 int i;
526 unsigned long flags;
527
528 usb_deregister(&empeg_driver);
Alan Cox93c46792008-07-22 11:11:11 +0100529 usb_serial_deregister(&empeg_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
Alan Cox93c46792008-07-22 11:11:11 +0100531 spin_lock_irqsave(&write_urb_pool_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
533 for (i = 0; i < NUM_URBS; ++i) {
534 if (write_urb_pool[i]) {
Alan Cox93c46792008-07-22 11:11:11 +0100535 /* FIXME - uncomment the following usb_kill_urb call
536 * when the host controllers get fixed to set urb->dev
537 * = NULL after the urb is finished. Otherwise this
538 * call oopses. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 /* usb_kill_urb(write_urb_pool[i]); */
Jesper Juhl1bc3c9e2005-04-18 17:39:34 -0700540 kfree(write_urb_pool[i]->transfer_buffer);
Alan Cox93c46792008-07-22 11:11:11 +0100541 usb_free_urb(write_urb_pool[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 }
543 }
Alan Cox93c46792008-07-22 11:11:11 +0100544 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545}
546
547
548module_init(empeg_init);
549module_exit(empeg_exit);
550
Alan Cox93c46792008-07-22 11:11:11 +0100551MODULE_AUTHOR(DRIVER_AUTHOR);
552MODULE_DESCRIPTION(DRIVER_DESC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553MODULE_LICENSE("GPL");
554
555module_param(debug, bool, S_IRUGO | S_IWUSR);
556MODULE_PARM_DESC(debug, "Debug enabled or not");