// SPDX-License-Identifier: GPL-2.0+ /* * Copyright (C) 2009 by Bart Hartgers ([email protected]) * Original version: * Copyright (C) 2006 * Simon Schulz (ark3116_driver <at> auctionant.de) * * ark3116 * - implements a driver for the arkmicro ark3116 chipset (vendor=0x6547, * productid=0x0232) (used in a datacable called KQ-U8A) * * Supports full modem status lines, break, hardware flow control. Does not * support software flow control, since I do not know how to enable it in hw. * * This driver is a essentially new implementation. I initially dug * into the old ark3116.c driver and suddenly realized the ark3116 is * a 16450 with a USB interface glued to it. See comments at the * bottom of this file. */ #include <linux/kernel.h> #include <linux/ioctl.h> #include <linux/tty.h> #include <linux/slab.h> #include <linux/tty_flip.h> #include <linux/module.h> #include <linux/usb.h> #include <linux/usb/serial.h> #include <linux/serial.h> #include <linux/serial_reg.h> #include <linux/uaccess.h> #include <linux/mutex.h> #include <linux/spinlock.h> #define DRIVER_AUTHOR … #define DRIVER_DESC … #define DRIVER_DEV_DESC … #define DRIVER_NAME … /* usb timeout of 1 second */ #define ARK_TIMEOUT … static const struct usb_device_id id_table[] = …; MODULE_DEVICE_TABLE(usb, id_table); static int is_irda(struct usb_serial *serial) { … } struct ark3116_private { … }; static int ark3116_write_reg(struct usb_serial *serial, unsigned reg, __u8 val) { … } static int ark3116_read_reg(struct usb_serial *serial, unsigned reg, unsigned char *buf) { … } static inline int calc_divisor(int bps) { … } static int ark3116_port_probe(struct usb_serial_port *port) { … } static void ark3116_port_remove(struct usb_serial_port *port) { … } static void ark3116_set_termios(struct tty_struct *tty, struct usb_serial_port *port, const struct ktermios *old_termios) { … } static void ark3116_close(struct usb_serial_port *port) { … } static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port) { … } static int ark3116_tiocmget(struct tty_struct *tty) { … } static int ark3116_tiocmset(struct tty_struct *tty, unsigned set, unsigned clr) { … } static int ark3116_break_ctl(struct tty_struct *tty, int break_state) { … } static void ark3116_update_msr(struct usb_serial_port *port, __u8 msr) { … } static void ark3116_update_lsr(struct usb_serial_port *port, __u8 lsr) { … } static void ark3116_read_int_callback(struct urb *urb) { … } /* Data comes in via the bulk (data) URB, errors/interrupts via the int URB. * This means that we cannot be sure which data byte has an associated error * condition, so we report an error for all data in the next bulk read. * * Actually, there might even be a window between the bulk data leaving the * ark and reading/resetting the lsr in the read_bulk_callback where an * interrupt for the next data block could come in. * Without somekind of ordering on the ark, we would have to report the * error for the next block of data as well... * For now, let's pretend this can't happen. */ static void ark3116_process_read_urb(struct urb *urb) { … } static struct usb_serial_driver ark3116_device = …; static struct usb_serial_driver * const serial_drivers[] = …; module_usb_serial_driver(…); MODULE_LICENSE(…) …; MODULE_AUTHOR(…); MODULE_DESCRIPTION(…); /* * The following describes what I learned from studying the old * ark3116.c driver, disassembling the windows driver, and some lucky * guesses. Since I do not have any datasheet or other * documentation, inaccuracies are almost guaranteed. * * Some specs for the ARK3116 can be found here: * http://web.archive.org/web/20060318000438/ * www.arkmicro.com/en/products/view.php?id=10 * On that page, 2 GPIO pins are mentioned: I assume these are the * OUT1 and OUT2 pins of the UART, so I added support for those * through the MCR. Since the pins are not available on my hardware, * I could not verify this. * Also, it states there is "on-chip hardware flow control". I have * discovered how to enable that. Unfortunately, I do not know how to * enable XON/XOFF (software) flow control, which would need support * from the chip as well to work. Because of the wording on the web * page there is a real possibility the chip simply does not support * software flow control. * * I got my ark3116 as part of a mobile phone adapter cable. On the * PCB, the following numbered contacts are present: * * 1:- +5V * 2:o DTR * 3:i RX * 4:i DCD * 5:o RTS * 6:o TX * 7:i RI * 8:i DSR * 10:- 0V * 11:i CTS * * On my chip, all signals seem to be 3.3V, but 5V tolerant. But that * may be different for the one you have ;-). * * The windows driver limits the registers to 0-F, so I assume there * are actually 16 present on the device. * * On an UART interrupt, 4 bytes of data come in on the interrupt * endpoint. The bytes are 0xe8 IIR LSR MSR. * * The baudrate seems to be generated from the 12MHz crystal, using * 4-times subsampling. So quot=12e6/(4*baud). Also see description * of register E. * * Registers 0-7: * These seem to be the same as for a regular 16450. The FCR is set * to UART_FCR_DMA_SELECT (0x8), I guess to enable transfers between * the UART and the USB bridge/DMA engine. * * Register 8: * By trial and error, I found out that bit 0 enables hardware CTS, * stopping TX when CTS is +5V. Bit 1 does the same for RTS, making * RTS +5V when the 3116 cannot transfer the data to the USB bus * (verified by disabling the reading URB). Note that as far as I can * tell, the windows driver does NOT use this, so there might be some * hardware bug or something. * * According to a patch provided here * https://lore.kernel.org/lkml/[email protected] * the ARK3116 can also be used as an IrDA dongle. Since I do not have * such a thing, I could not investigate that aspect. However, I can * speculate ;-). * * - IrDA encodes data differently than RS232. Most likely, one of * the bits in registers 9..E enables the IR ENDEC (encoder/decoder). * - Depending on the IR transceiver, the input and output need to be * inverted, so there are probably bits for that as well. * - IrDA is half-duplex, so there should be a bit for selecting that. * * This still leaves at least two registers unaccounted for. Perhaps * The chip can do XON/XOFF or CRC in HW? * * Register 9: * Set to 0x00 for IrDA, when the baudrate is initialised. * * Register A: * Set to 0x01 for IrDA, at init. * * Register B: * Set to 0x01 for IrDA, 0x00 for RS232, at init. * * Register C: * Set to 00 for IrDA, at init. * * Register D: * Set to 0x41 for IrDA, at init. * * Register E: * Somekind of baudrate override. The windows driver seems to set * this to 0x00 for normal baudrates, 0x01 for 460800, 0x02 for 921600. * Since 460800 and 921600 cannot be obtained by dividing 3MHz by an integer, * it could be somekind of subdivisor thingy. * However,it does not seem to do anything: selecting 921600 (divisor 3, * reg E=2), still gets 1 MHz. I also checked if registers 9, C or F would * work, but they don't. * * Register F: unknown */