aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorTim Small <tim@buttersideup.com>2009-08-17 08:21:57 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2009-09-23 09:46:35 -0400
commit492896f011a411d17d02e696adbc4a9b4ff68e7f (patch)
tree97c7f314f175e8d4e431aa30f2f58679d056a66b /drivers/usb
parent823c3fd9cc71714fe22ea415a68da746800d5a9a (diff)
USb: Break support for WinChipHead CH341 340 USB->Serial "chip"
Here is a patch to the ch341 driver which adds serial break support. Signed-off-by: Tim Small <tim@seoss.co.uk> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/serial/ch341.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index 8c894a7d5dcf..59eff721fcc5 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -56,6 +56,18 @@
56#define CH341_BAUDBASE_FACTOR 1532620800 56#define CH341_BAUDBASE_FACTOR 1532620800
57#define CH341_BAUDBASE_DIVMAX 3 57#define CH341_BAUDBASE_DIVMAX 3
58 58
59/* Break support - the information used to implement this was gleaned from
60 * the Net/FreeBSD uchcom.c driver by Takanori Watanabe. Domo arigato.
61 */
62
63#define CH341_REQ_WRITE_REG 0x9A
64#define CH341_REQ_READ_REG 0x95
65#define CH341_REG_BREAK1 0x05
66#define CH341_REG_BREAK2 0x18
67#define CH341_NBREAK_BITS_REG1 0x01
68#define CH341_NBREAK_BITS_REG2 0x40
69
70
59static int debug; 71static int debug;
60 72
61static struct usb_device_id id_table [] = { 73static struct usb_device_id id_table [] = {
@@ -373,6 +385,45 @@ static void ch341_set_termios(struct tty_struct *tty,
373 */ 385 */
374} 386}
375 387
388static void ch341_break_ctl(struct tty_struct *tty, int break_state)
389{
390 const uint16_t ch341_break_reg =
391 CH341_REG_BREAK1 | ((uint16_t) CH341_REG_BREAK2 << 8);
392 struct usb_serial_port *port = tty->driver_data;
393 int r;
394 uint16_t reg_contents;
395 uint8_t break_reg[2];
396
397 dbg("%s()", __func__);
398
399 r = ch341_control_in(port->serial->dev, CH341_REQ_READ_REG,
400 ch341_break_reg, 0, break_reg, sizeof(break_reg));
401 if (r < 0) {
402 printk(KERN_WARNING "%s: USB control read error whilst getting"
403 " break register contents.\n", __FILE__);
404 return;
405 }
406 dbg("%s - initial ch341 break register contents - reg1: %x, reg2: %x",
407 __func__, break_reg[0], break_reg[1]);
408 if (break_state != 0) {
409 dbg("%s - Enter break state requested", __func__);
410 break_reg[0] &= ~CH341_NBREAK_BITS_REG1;
411 break_reg[1] &= ~CH341_NBREAK_BITS_REG2;
412 } else {
413 dbg("%s - Leave break state requested", __func__);
414 break_reg[0] |= CH341_NBREAK_BITS_REG1;
415 break_reg[1] |= CH341_NBREAK_BITS_REG2;
416 }
417 dbg("%s - New ch341 break register contents - reg1: %x, reg2: %x",
418 __func__, break_reg[0], break_reg[1]);
419 reg_contents = (uint16_t)break_reg[0] | ((uint16_t)break_reg[1] << 8);
420 r = ch341_control_out(port->serial->dev, CH341_REQ_WRITE_REG,
421 ch341_break_reg, reg_contents);
422 if (r < 0)
423 printk(KERN_WARNING "%s: USB control write error whilst setting"
424 " break register contents.\n", __FILE__);
425}
426
376static int ch341_tiocmset(struct tty_struct *tty, struct file *file, 427static int ch341_tiocmset(struct tty_struct *tty, struct file *file,
377 unsigned int set, unsigned int clear) 428 unsigned int set, unsigned int clear)
378{ 429{
@@ -576,6 +627,7 @@ static struct usb_serial_driver ch341_device = {
576 .close = ch341_close, 627 .close = ch341_close,
577 .ioctl = ch341_ioctl, 628 .ioctl = ch341_ioctl,
578 .set_termios = ch341_set_termios, 629 .set_termios = ch341_set_termios,
630 .break_ctl = ch341_break_ctl,
579 .tiocmget = ch341_tiocmget, 631 .tiocmget = ch341_tiocmget,
580 .tiocmset = ch341_tiocmset, 632 .tiocmset = ch341_tiocmset,
581 .read_int_callback = ch341_read_int_callback, 633 .read_int_callback = ch341_read_int_callback,