blob: 7dd0e3eadbe64ce3fab049ed2af23e1ba7e424f4 [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 Coxa509a7e2009-09-19 13:13:26 -070082static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port);
Alan Cox335f8512009-06-11 12:26:29 +010083static void empeg_close(struct usb_serial_port *port);
Alan Cox93c46792008-07-22 11:11:11 +010084static int empeg_write(struct tty_struct *tty, struct usb_serial_port *port,
85 const unsigned char *buf,
86 int count);
87static int empeg_write_room(struct tty_struct *tty);
88static int empeg_chars_in_buffer(struct tty_struct *tty);
89static void empeg_throttle(struct tty_struct *tty);
90static void empeg_unthrottle(struct tty_struct *tty);
91static int empeg_startup(struct usb_serial *serial);
Alan Coxfe1ae7f2009-09-19 13:13:33 -070092static void empeg_init_termios(struct tty_struct *tty);
Alan Cox93c46792008-07-22 11:11:11 +010093static void empeg_write_bulk_callback(struct urb *urb);
94static void empeg_read_bulk_callback(struct urb *urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96static struct usb_device_id id_table [] = {
97 { USB_DEVICE(EMPEG_VENDOR_ID, EMPEG_PRODUCT_ID) },
98 { } /* Terminating entry */
99};
100
Alan Cox93c46792008-07-22 11:11:11 +0100101MODULE_DEVICE_TABLE(usb, id_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103static struct usb_driver empeg_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 .name = "empeg",
105 .probe = usb_serial_probe,
106 .disconnect = usb_serial_disconnect,
107 .id_table = id_table,
Greg Kroah-Hartmanba9dc652005-11-16 13:41:28 -0800108 .no_dynamic_id = 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109};
110
Greg Kroah-Hartmanea653702005-06-20 21:15:16 -0700111static struct usb_serial_driver empeg_device = {
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -0700112 .driver = {
113 .owner = THIS_MODULE,
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700114 .name = "empeg",
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -0700115 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 .id_table = id_table,
Johannes Hölzld9b1b782006-12-17 21:50:24 +0100117 .usb_driver = &empeg_driver,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 .num_ports = 1,
119 .open = empeg_open,
120 .close = empeg_close,
121 .throttle = empeg_throttle,
122 .unthrottle = empeg_unthrottle,
123 .attach = empeg_startup,
Alan Coxfe1ae7f2009-09-19 13:13:33 -0700124 .init_termios = empeg_init_termios,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 .write = empeg_write,
126 .write_room = empeg_write_room,
127 .chars_in_buffer = empeg_chars_in_buffer,
128 .write_bulk_callback = empeg_write_bulk_callback,
129 .read_bulk_callback = empeg_read_bulk_callback,
130};
131
132#define NUM_URBS 16
133#define URB_TRANSFER_BUFFER_SIZE 4096
134
135static struct urb *write_urb_pool[NUM_URBS];
136static spinlock_t write_urb_pool_lock;
137static int bytes_in;
138static int bytes_out;
139
140/******************************************************************************
141 * Empeg specific driver functions
142 ******************************************************************************/
Alan Coxa509a7e2009-09-19 13:13:26 -0700143static int empeg_open(struct tty_struct *tty,struct usb_serial_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144{
145 struct usb_serial *serial = port->serial;
146 int result = 0;
147
Harvey Harrison441b62c2008-03-03 16:08:34 -0800148 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 bytes_in = 0;
151 bytes_out = 0;
152
153 /* Start reading from the device */
154 usb_fill_bulk_urb(
155 port->read_urb,
Alan Cox93c46792008-07-22 11:11:11 +0100156 serial->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 usb_rcvbulkpipe(serial->dev,
158 port->bulk_in_endpointAddress),
159 port->read_urb->transfer_buffer,
160 port->read_urb->transfer_buffer_length,
161 empeg_read_bulk_callback,
162 port);
163
164 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
165
166 if (result)
Alan Cox93c46792008-07-22 11:11:11 +0100167 dev_err(&port->dev,
168 "%s - failed submitting read urb, error %d\n",
169 __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171 return result;
172}
173
174
Alan Cox335f8512009-06-11 12:26:29 +0100175static void empeg_close(struct usb_serial_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176{
Harvey Harrison441b62c2008-03-03 16:08:34 -0800177 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
179 /* shutdown our bulk read */
180 usb_kill_urb(port->read_urb);
181 /* Uncomment the following line if you want to see some statistics in your syslog */
182 /* dev_info (&port->dev, "Bytes In = %d Bytes Out = %d\n", bytes_in, bytes_out); */
183}
184
185
Alan Cox93c46792008-07-22 11:11:11 +0100186static int empeg_write(struct tty_struct *tty, struct usb_serial_port *port,
187 const unsigned char *buf, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188{
189 struct usb_serial *serial = port->serial;
190 struct urb *urb;
191 const unsigned char *current_position = buf;
192 unsigned long flags;
193 int status;
194 int i;
195 int bytes_sent = 0;
196 int transfer_size;
197
Harvey Harrison441b62c2008-03-03 16:08:34 -0800198 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200 while (count > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 /* try to find a free urb in our list of them */
202 urb = NULL;
203
Alan Cox93c46792008-07-22 11:11:11 +0100204 spin_lock_irqsave(&write_urb_pool_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206 for (i = 0; i < NUM_URBS; ++i) {
207 if (write_urb_pool[i]->status != -EINPROGRESS) {
208 urb = write_urb_pool[i];
209 break;
210 }
211 }
212
Alan Cox93c46792008-07-22 11:11:11 +0100213 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215 if (urb == NULL) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800216 dbg("%s - no more free urbs", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 goto exit;
218 }
219
220 if (urb->transfer_buffer == NULL) {
Alan Cox93c46792008-07-22 11:11:11 +0100221 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 if (urb->transfer_buffer == NULL) {
Alan Cox93c46792008-07-22 11:11:11 +0100223 dev_err(&port->dev,
224 "%s no more kernel memory...\n",
225 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 goto exit;
227 }
228 }
229
Alan Cox93c46792008-07-22 11:11:11 +0100230 transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
Alan Cox93c46792008-07-22 11:11:11 +0100232 memcpy(urb->transfer_buffer, current_position, transfer_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
Harvey Harrison441b62c2008-03-03 16:08:34 -0800234 usb_serial_debug_data(debug, &port->dev, __func__, transfer_size, urb->transfer_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
236 /* build up our urb */
Alan Cox93c46792008-07-22 11:11:11 +0100237 usb_fill_bulk_urb(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 urb,
239 serial->dev,
240 usb_sndbulkpipe(serial->dev,
Alan Cox93c46792008-07-22 11:11:11 +0100241 port->bulk_out_endpointAddress),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 urb->transfer_buffer,
243 transfer_size,
244 empeg_write_bulk_callback,
245 port);
246
247 /* send it down the pipe */
248 status = usb_submit_urb(urb, GFP_ATOMIC);
249 if (status) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800250 dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed with status = %d\n", __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 bytes_sent = status;
252 break;
253 }
254
255 current_position += transfer_size;
256 bytes_sent += transfer_size;
257 count -= transfer_size;
258 bytes_out += transfer_size;
259
260 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261exit:
262 return bytes_sent;
Alan Cox93c46792008-07-22 11:11:11 +0100263}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265
Alan Cox95da3102008-07-22 11:09:07 +0100266static int empeg_write_room(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267{
Alan Cox95da3102008-07-22 11:09:07 +0100268 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 unsigned long flags;
270 int i;
271 int room = 0;
272
Harvey Harrison441b62c2008-03-03 16:08:34 -0800273 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
Alan Cox93c46792008-07-22 11:11:11 +0100275 spin_lock_irqsave(&write_urb_pool_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 /* tally up the number of bytes available */
277 for (i = 0; i < NUM_URBS; ++i) {
Alan Cox93c46792008-07-22 11:11:11 +0100278 if (write_urb_pool[i]->status != -EINPROGRESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 room += URB_TRANSFER_BUFFER_SIZE;
Alan Cox93c46792008-07-22 11:11:11 +0100280 }
281 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
Harvey Harrison441b62c2008-03-03 16:08:34 -0800282 dbg("%s - returns %d", __func__, room);
Alan Cox95da3102008-07-22 11:09:07 +0100283 return room;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285}
286
287
Alan Cox95da3102008-07-22 11:09:07 +0100288static int empeg_chars_in_buffer(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
Alan Cox95da3102008-07-22 11:09:07 +0100290 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 unsigned long flags;
292 int i;
293 int chars = 0;
294
Harvey Harrison441b62c2008-03-03 16:08:34 -0800295 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Alan Cox93c46792008-07-22 11:11:11 +0100297 spin_lock_irqsave(&write_urb_pool_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
299 /* tally up the number of bytes waiting */
300 for (i = 0; i < NUM_URBS; ++i) {
Alan Cox93c46792008-07-22 11:11:11 +0100301 if (write_urb_pool[i]->status == -EINPROGRESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 chars += URB_TRANSFER_BUFFER_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 }
304
Alan Cox93c46792008-07-22 11:11:11 +0100305 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
Harvey Harrison441b62c2008-03-03 16:08:34 -0800306 dbg("%s - returns %d", __func__, chars);
Alan Cox93c46792008-07-22 11:11:11 +0100307 return chars;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308}
309
310
Alan Cox93c46792008-07-22 11:11:11 +0100311static void empeg_write_bulk_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312{
Greg Kroah-Hartman335202f2007-06-15 15:44:13 -0700313 struct usb_serial_port *port = urb->context;
314 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Harvey Harrison441b62c2008-03-03 16:08:34 -0800316 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Greg Kroah-Hartman335202f2007-06-15 15:44:13 -0700318 if (status) {
319 dbg("%s - nonzero write bulk status received: %d",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800320 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 return;
322 }
323
Pete Zaitcevcf2c7482006-05-22 21:58:49 -0700324 usb_serial_port_softint(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325}
326
327
Alan Cox93c46792008-07-22 11:11:11 +0100328static void empeg_read_bulk_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329{
Ming Leicdc97792008-02-24 18:41:47 +0800330 struct usb_serial_port *port = urb->context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 struct tty_struct *tty;
332 unsigned char *data = urb->transfer_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 int result;
Greg Kroah-Hartman335202f2007-06-15 15:44:13 -0700334 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
Harvey Harrison441b62c2008-03-03 16:08:34 -0800336 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
Greg Kroah-Hartman335202f2007-06-15 15:44:13 -0700338 if (status) {
339 dbg("%s - nonzero read bulk status received: %d",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800340 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 return;
342 }
343
Alan Cox93c46792008-07-22 11:11:11 +0100344 usb_serial_debug_data(debug, &port->dev, __func__,
345 urb->actual_length, data);
Alan Cox4a90f092008-10-13 10:39:46 +0100346 tty = tty_port_tty_get(&port->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
348 if (urb->actual_length) {
Alan Cox33f0f882006-01-09 20:54:13 -0800349 tty_buffer_request_room(tty, urb->actual_length);
350 tty_insert_flip_string(tty, data, urb->actual_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 tty_flip_buffer_push(tty);
352 bytes_in += urb->actual_length;
353 }
Alan Cox4a90f092008-10-13 10:39:46 +0100354 tty_kref_put(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
356 /* Continue trying to always read */
357 usb_fill_bulk_urb(
358 port->read_urb,
Alan Cox93c46792008-07-22 11:11:11 +0100359 port->serial->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 usb_rcvbulkpipe(port->serial->dev,
361 port->bulk_in_endpointAddress),
362 port->read_urb->transfer_buffer,
363 port->read_urb->transfer_buffer_length,
364 empeg_read_bulk_callback,
365 port);
366
367 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
368
369 if (result)
Alan Cox93c46792008-07-22 11:11:11 +0100370 dev_err(&urb->dev->dev,
371 "%s - failed resubmitting read urb, error %d\n",
372 __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374 return;
375
376}
377
378
Alan Cox95da3102008-07-22 11:09:07 +0100379static void empeg_throttle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380{
Alan Cox95da3102008-07-22 11:09:07 +0100381 struct usb_serial_port *port = tty->driver_data;
Harvey Harrison441b62c2008-03-03 16:08:34 -0800382 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 usb_kill_urb(port->read_urb);
384}
385
386
Alan Cox95da3102008-07-22 11:09:07 +0100387static void empeg_unthrottle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388{
Alan Cox95da3102008-07-22 11:09:07 +0100389 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 int result;
Harvey Harrison441b62c2008-03-03 16:08:34 -0800391 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
393 port->read_urb->dev = port->serial->dev;
Oliver Neukum63832512009-10-07 10:50:23 +0200394 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 if (result)
Alan Cox93c46792008-07-22 11:11:11 +0100396 dev_err(&port->dev,
397 "%s - failed submitting read urb, error %d\n",
398 __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399}
400
401
Alan Cox93c46792008-07-22 11:11:11 +0100402static int empeg_startup(struct usb_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
404 int r;
405
Harvey Harrison441b62c2008-03-03 16:08:34 -0800406 dbg("%s", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
408 if (serial->dev->actconfig->desc.bConfigurationValue != 1) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700409 dev_err(&serial->dev->dev, "active config #%d != 1 ??\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 serial->dev->actconfig->desc.bConfigurationValue);
411 return -ENODEV;
412 }
Harvey Harrison441b62c2008-03-03 16:08:34 -0800413 dbg("%s - reset config", __func__);
Alan Cox93c46792008-07-22 11:11:11 +0100414 r = usb_reset_configuration(serial->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
416 /* continue on with initialization */
417 return r;
418
419}
420
421
Alan Coxfe1ae7f2009-09-19 13:13:33 -0700422static void empeg_init_termios(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423{
Alan Cox95da3102008-07-22 11:09:07 +0100424 struct ktermios *termios = tty->termios;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 /*
Alan Cox93c46792008-07-22 11:11:11 +0100427 * The empeg-car player wants these particular tty settings.
428 * You could, for example, change the baud rate, however the
429 * player only supports 115200 (currently), so there is really
430 * no point in support for changes to the tty settings.
431 * (at least for now)
432 *
433 * The default requirements for this device are:
434 */
Alan Cox998e8632007-10-18 01:24:19 -0700435 termios->c_iflag
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 &= ~(IGNBRK /* disable ignore break */
437 | BRKINT /* disable break causes interrupt */
438 | PARMRK /* disable mark parity errors */
439 | ISTRIP /* disable clear high bit of input characters */
440 | INLCR /* disable translate NL to CR */
441 | IGNCR /* disable ignore CR */
442 | ICRNL /* disable translate CR to NL */
443 | IXON); /* disable enable XON/XOFF flow control */
444
Alan Cox998e8632007-10-18 01:24:19 -0700445 termios->c_oflag
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 &= ~OPOST; /* disable postprocess output characters */
447
Alan Cox998e8632007-10-18 01:24:19 -0700448 termios->c_lflag
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 &= ~(ECHO /* disable echo input characters */
450 | ECHONL /* disable echo new line */
451 | ICANON /* disable erase, kill, werase, and rprnt special characters */
452 | ISIG /* disable interrupt, quit, and suspend special characters */
453 | IEXTEN); /* disable non-POSIX special characters */
454
Alan Cox998e8632007-10-18 01:24:19 -0700455 termios->c_cflag
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 &= ~(CSIZE /* no size */
457 | PARENB /* disable parity bit */
458 | CBAUD); /* clear current baud rate */
459
Alan Cox998e8632007-10-18 01:24:19 -0700460 termios->c_cflag
461 |= CS8; /* character size 8 bits */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
Alan Cox95da3102008-07-22 11:09:07 +0100463 tty_encode_baud_rate(tty, 115200, 115200);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464}
465
466
Alan Cox93c46792008-07-22 11:11:11 +0100467static int __init empeg_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468{
469 struct urb *urb;
470 int i, retval;
471
Alan Cox93c46792008-07-22 11:11:11 +0100472 /* create our write urb pool and transfer buffers */
473 spin_lock_init(&write_urb_pool_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 for (i = 0; i < NUM_URBS; ++i) {
475 urb = usb_alloc_urb(0, GFP_KERNEL);
476 write_urb_pool[i] = urb;
477 if (urb == NULL) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700478 printk(KERN_ERR "empeg: No more urbs???\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 continue;
480 }
481
Alan Cox93c46792008-07-22 11:11:11 +0100482 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE,
483 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 if (!urb->transfer_buffer) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700485 printk(KERN_ERR "empeg: %s - out of memory for urb "
486 "buffers.", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 continue;
488 }
489 }
490
491 retval = usb_serial_register(&empeg_device);
492 if (retval)
493 goto failed_usb_serial_register;
494 retval = usb_register(&empeg_driver);
495 if (retval)
496 goto failed_usb_register;
497
Greg Kroah-Hartmanc197a8d2008-08-18 13:21:04 -0700498 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
499 DRIVER_DESC "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
501 return 0;
502failed_usb_register:
503 usb_serial_deregister(&empeg_device);
504failed_usb_serial_register:
505 for (i = 0; i < NUM_URBS; ++i) {
506 if (write_urb_pool[i]) {
Jesper Juhl1bc3c9e2005-04-18 17:39:34 -0700507 kfree(write_urb_pool[i]->transfer_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 usb_free_urb(write_urb_pool[i]);
509 }
510 }
511 return retval;
512}
513
514
Alan Cox93c46792008-07-22 11:11:11 +0100515static void __exit empeg_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516{
517 int i;
518 unsigned long flags;
519
520 usb_deregister(&empeg_driver);
Alan Cox93c46792008-07-22 11:11:11 +0100521 usb_serial_deregister(&empeg_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
Alan Cox93c46792008-07-22 11:11:11 +0100523 spin_lock_irqsave(&write_urb_pool_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
525 for (i = 0; i < NUM_URBS; ++i) {
526 if (write_urb_pool[i]) {
Alan Cox93c46792008-07-22 11:11:11 +0100527 /* FIXME - uncomment the following usb_kill_urb call
528 * when the host controllers get fixed to set urb->dev
529 * = NULL after the urb is finished. Otherwise this
530 * call oopses. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 /* usb_kill_urb(write_urb_pool[i]); */
Jesper Juhl1bc3c9e2005-04-18 17:39:34 -0700532 kfree(write_urb_pool[i]->transfer_buffer);
Alan Cox93c46792008-07-22 11:11:11 +0100533 usb_free_urb(write_urb_pool[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 }
535 }
Alan Cox93c46792008-07-22 11:11:11 +0100536 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537}
538
539
540module_init(empeg_init);
541module_exit(empeg_exit);
542
Alan Cox93c46792008-07-22 11:11:11 +0100543MODULE_AUTHOR(DRIVER_AUTHOR);
544MODULE_DESCRIPTION(DRIVER_DESC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545MODULE_LICENSE("GPL");
546
547module_param(debug, bool, S_IRUGO | S_IWUSR);
548MODULE_PARM_DESC(debug, "Debug enabled or not");