diff options
Diffstat (limited to 'drivers/usb/serial/ch341.c')
-rw-r--r-- | drivers/usb/serial/ch341.c | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c index 2830766f5b39..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 | |||
59 | static int debug; | 71 | static int debug; |
60 | 72 | ||
61 | static struct usb_device_id id_table [] = { | 73 | static struct usb_device_id id_table [] = { |
@@ -300,8 +312,7 @@ static void ch341_close(struct usb_serial_port *port) | |||
300 | 312 | ||
301 | 313 | ||
302 | /* open this device, set default parameters */ | 314 | /* open this device, set default parameters */ |
303 | static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port, | 315 | static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port) |
304 | struct file *filp) | ||
305 | { | 316 | { |
306 | struct usb_serial *serial = port->serial; | 317 | struct usb_serial *serial = port->serial; |
307 | struct ch341_private *priv = usb_get_serial_port_data(serial->port[0]); | 318 | struct ch341_private *priv = usb_get_serial_port_data(serial->port[0]); |
@@ -333,7 +344,7 @@ static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
333 | return -EPROTO; | 344 | return -EPROTO; |
334 | } | 345 | } |
335 | 346 | ||
336 | r = usb_serial_generic_open(tty, port, filp); | 347 | r = usb_serial_generic_open(tty, port); |
337 | 348 | ||
338 | out: return r; | 349 | out: return r; |
339 | } | 350 | } |
@@ -374,6 +385,45 @@ static void ch341_set_termios(struct tty_struct *tty, | |||
374 | */ | 385 | */ |
375 | } | 386 | } |
376 | 387 | ||
388 | static 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 | |||
377 | static int ch341_tiocmset(struct tty_struct *tty, struct file *file, | 427 | static int ch341_tiocmset(struct tty_struct *tty, struct file *file, |
378 | unsigned int set, unsigned int clear) | 428 | unsigned int set, unsigned int clear) |
379 | { | 429 | { |
@@ -577,6 +627,7 @@ static struct usb_serial_driver ch341_device = { | |||
577 | .close = ch341_close, | 627 | .close = ch341_close, |
578 | .ioctl = ch341_ioctl, | 628 | .ioctl = ch341_ioctl, |
579 | .set_termios = ch341_set_termios, | 629 | .set_termios = ch341_set_termios, |
630 | .break_ctl = ch341_break_ctl, | ||
580 | .tiocmget = ch341_tiocmget, | 631 | .tiocmget = ch341_tiocmget, |
581 | .tiocmset = ch341_tiocmset, | 632 | .tiocmset = ch341_tiocmset, |
582 | .read_int_callback = ch341_read_int_callback, | 633 | .read_int_callback = ch341_read_int_callback, |