xref: /openbmc/linux/drivers/usb/serial/empeg.c (revision 32078f915d1acab356080b144aa89fe3487f3979)
1 /*
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  *
14  * See Documentation/usb/usb-serial.txt for more information on using this
15  * driver
16  */
17 
18 #include <linux/kernel.h>
19 #include <linux/errno.h>
20 #include <linux/init.h>
21 #include <linux/slab.h>
22 #include <linux/tty.h>
23 #include <linux/tty_driver.h>
24 #include <linux/tty_flip.h>
25 #include <linux/module.h>
26 #include <linux/spinlock.h>
27 #include <linux/uaccess.h>
28 #include <linux/usb.h>
29 #include <linux/usb/serial.h>
30 
31 static bool debug;
32 
33 /*
34  * Version Information
35  */
36 #define DRIVER_VERSION "v1.3"
37 #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Gary Brubaker <xavyer@ix.netcom.com>"
38 #define DRIVER_DESC "USB Empeg Mark I/II Driver"
39 
40 #define EMPEG_VENDOR_ID			0x084f
41 #define EMPEG_PRODUCT_ID		0x0001
42 
43 /* function prototypes for an empeg-car player */
44 static int  empeg_startup(struct usb_serial *serial);
45 static void empeg_init_termios(struct tty_struct *tty);
46 
47 static const struct usb_device_id id_table[] = {
48 	{ USB_DEVICE(EMPEG_VENDOR_ID, EMPEG_PRODUCT_ID) },
49 	{ }					/* Terminating entry */
50 };
51 
52 MODULE_DEVICE_TABLE(usb, id_table);
53 
54 static struct usb_driver empeg_driver = {
55 	.name =		"empeg",
56 	.id_table =	id_table,
57 };
58 
59 static struct usb_serial_driver empeg_device = {
60 	.driver = {
61 		.owner =	THIS_MODULE,
62 		.name =		"empeg",
63 	},
64 	.id_table =		id_table,
65 	.num_ports =		1,
66 	.bulk_out_size =	256,
67 	.throttle =		usb_serial_generic_throttle,
68 	.unthrottle =		usb_serial_generic_unthrottle,
69 	.attach =		empeg_startup,
70 	.init_termios =		empeg_init_termios,
71 };
72 
73 static struct usb_serial_driver * const serial_drivers[] = {
74 	&empeg_device, NULL
75 };
76 
77 static int empeg_startup(struct usb_serial *serial)
78 {
79 	int r;
80 
81 	if (serial->dev->actconfig->desc.bConfigurationValue != 1) {
82 		dev_err(&serial->dev->dev, "active config #%d != 1 ??\n",
83 			serial->dev->actconfig->desc.bConfigurationValue);
84 		return -ENODEV;
85 	}
86 
87 	r = usb_reset_configuration(serial->dev);
88 
89 	/* continue on with initialization */
90 	return r;
91 }
92 
93 static void empeg_init_termios(struct tty_struct *tty)
94 {
95 	struct ktermios *termios = tty->termios;
96 
97 	/*
98 	 * The empeg-car player wants these particular tty settings.
99 	 * You could, for example, change the baud rate, however the
100 	 * player only supports 115200 (currently), so there is really
101 	 * no point in support for changes to the tty settings.
102 	 * (at least for now)
103 	 *
104 	 * The default requirements for this device are:
105 	 */
106 	termios->c_iflag
107 		&= ~(IGNBRK	/* disable ignore break */
108 		| BRKINT	/* disable break causes interrupt */
109 		| PARMRK	/* disable mark parity errors */
110 		| ISTRIP	/* disable clear high bit of input characters */
111 		| INLCR		/* disable translate NL to CR */
112 		| IGNCR		/* disable ignore CR */
113 		| ICRNL		/* disable translate CR to NL */
114 		| IXON);	/* disable enable XON/XOFF flow control */
115 
116 	termios->c_oflag
117 		&= ~OPOST;	/* disable postprocess output characters */
118 
119 	termios->c_lflag
120 		&= ~(ECHO	/* disable echo input characters */
121 		| ECHONL	/* disable echo new line */
122 		| ICANON	/* disable erase, kill, werase, and rprnt special characters */
123 		| ISIG		/* disable interrupt, quit, and suspend special characters */
124 		| IEXTEN);	/* disable non-POSIX special characters */
125 
126 	termios->c_cflag
127 		&= ~(CSIZE	/* no size */
128 		| PARENB	/* disable parity bit */
129 		| CBAUD);	/* clear current baud rate */
130 
131 	termios->c_cflag
132 		|= CS8;		/* character size 8 bits */
133 
134 	tty_encode_baud_rate(tty, 115200, 115200);
135 }
136 
137 module_usb_serial_driver(empeg_driver, serial_drivers);
138 
139 MODULE_AUTHOR(DRIVER_AUTHOR);
140 MODULE_DESCRIPTION(DRIVER_DESC);
141 MODULE_LICENSE("GPL");
142 
143 module_param(debug, bool, S_IRUGO | S_IWUSR);
144 MODULE_PARM_DESC(debug, "Debug enabled or not");
145