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