1815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman/* 2149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * Copyright (C) 2009 by Bart Hartgers (bart.hartgers+ark3116@gmail.com) 3149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * Original version: 42f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg * Copyright (C) 2006 52f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg * Simon Schulz (ark3116_driver <at> auctionant.de) 62f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg * 7815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman * ark3116 8815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman * - implements a driver for the arkmicro ark3116 chipset (vendor=0x6547, 9815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman * productid=0x0232) (used in a datacable called KQ-U8A) 10815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman * 11149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * Supports full modem status lines, break, hardware flow control. Does not 12149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * support software flow control, since I do not know how to enable it in hw. 13815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman * 14149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * This driver is a essentially new implementation. I initially dug 15149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * into the old ark3116.c driver and suddenly realized the ark3116 is 16149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * a 16450 with a USB interface glued to it. See comments at the 17149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * bottom of this file. 18815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman * 19815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman * This program is free software; you can redistribute it and/or modify it 20815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman * under the terms of the GNU General Public License as published by the 21815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman * Free Software Foundation; either version 2 of the License, or (at your 22815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman * option) any later version. 23815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman */ 24815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 25815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman#include <linux/kernel.h> 26815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman#include <linux/init.h> 27149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com#include <linux/ioctl.h> 28815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman#include <linux/tty.h> 295a0e3ad6af8660be21ca98a971cd00f331318c05Tejun Heo#include <linux/slab.h> 30149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com#include <linux/tty_flip.h> 31815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman#include <linux/module.h> 32815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman#include <linux/usb.h> 33a969888ce91673c7f4b86520d851a6f0d5a5fa7dGreg Kroah-Hartman#include <linux/usb/serial.h> 342f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg#include <linux/serial.h> 35149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com#include <linux/serial_reg.h> 36c4d0f8cbca3a97900f85b082064a63c7a5928bd7Alan Cox#include <linux/uaccess.h> 37149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com#include <linux/mutex.h> 38149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com#include <linux/spinlock.h> 39815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 4090ab5ee94171b3e28de6bb42ee30b527014e0be7Rusty Russellstatic bool debug; 41149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com/* 42149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * Version information 43149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com */ 44149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com 45583182ba5f02c8c9be82ea550f2051eaec15b975Bart Hartgers#define DRIVER_VERSION "v0.7" 46149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com#define DRIVER_AUTHOR "Bart Hartgers <bart.hartgers+ark3116@gmail.com>" 47149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com#define DRIVER_DESC "USB ARK3116 serial/IrDA driver" 48149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com#define DRIVER_DEV_DESC "ARK3116 RS232/IrDA" 49149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com#define DRIVER_NAME "ark3116" 50149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com 51149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com/* usb timeout of 1 second */ 52149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com#define ARK_TIMEOUT (1*HZ) 53815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 547d40d7e85a25e01948bcb4dc3eda1355af318337Németh Mártonstatic const struct usb_device_id id_table[] = { 55815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman { USB_DEVICE(0x6547, 0x0232) }, 565128a66c6605d8178f69b7a8f2a70060933a26b4Ondrej Zary { USB_DEVICE(0x18ec, 0x3118) }, /* USB to IrDA adapter */ 57815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman { }, 58815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman}; 59815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-HartmanMODULE_DEVICE_TABLE(usb, id_table); 60815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 615128a66c6605d8178f69b7a8f2a70060933a26b4Ondrej Zarystatic int is_irda(struct usb_serial *serial) 625128a66c6605d8178f69b7a8f2a70060933a26b4Ondrej Zary{ 635128a66c6605d8178f69b7a8f2a70060933a26b4Ondrej Zary struct usb_device *dev = serial->dev; 645128a66c6605d8178f69b7a8f2a70060933a26b4Ondrej Zary if (le16_to_cpu(dev->descriptor.idVendor) == 0x18ec && 655128a66c6605d8178f69b7a8f2a70060933a26b4Ondrej Zary le16_to_cpu(dev->descriptor.idProduct) == 0x3118) 665128a66c6605d8178f69b7a8f2a70060933a26b4Ondrej Zary return 1; 675128a66c6605d8178f69b7a8f2a70060933a26b4Ondrej Zary return 0; 685128a66c6605d8178f69b7a8f2a70060933a26b4Ondrej Zary} 695128a66c6605d8178f69b7a8f2a70060933a26b4Ondrej Zary 70149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.comstruct ark3116_private { 71149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com wait_queue_head_t delta_msr_wait; 72149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com struct async_icount icount; 73149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com int irda; /* 1 for irda device */ 74149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com 75149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com /* protects hw register updates */ 76149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com struct mutex hw_lock; 77149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com 78149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com int quot; /* baudrate divisor */ 79149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com __u32 lcr; /* line control register value */ 80149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com __u32 hcr; /* handshake control register (0x8) 81149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * value */ 82149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com __u32 mcr; /* modem contol register value */ 83149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com 84149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com /* protects the status values below */ 85149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com spinlock_t status_lock; 86149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com __u32 msr; /* modem status register value */ 87149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com __u32 lsr; /* line status register value */ 88149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com}; 89149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com 90149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.comstatic int ark3116_write_reg(struct usb_serial *serial, 91149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com unsigned reg, __u8 val) 92149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com{ 93149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com int result; 94149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com /* 0xfe 0x40 are magic values taken from original driver */ 95149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com result = usb_control_msg(serial->dev, 96149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com usb_sndctrlpipe(serial->dev, 0), 97149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com 0xfe, 0x40, val, reg, 98149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com NULL, 0, ARK_TIMEOUT); 99149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com return result; 100149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com} 101149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com 102149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.comstatic int ark3116_read_reg(struct usb_serial *serial, 103149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com unsigned reg, unsigned char *buf) 104149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com{ 105149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com int result; 106149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com /* 0xfe 0xc0 are magic values taken from original driver */ 107149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com result = usb_control_msg(serial->dev, 108149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com usb_rcvctrlpipe(serial->dev, 0), 109149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com 0xfe, 0xc0, 0, reg, 110149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com buf, 1, ARK_TIMEOUT); 111149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com if (result < 0) 112149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com return result; 113149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com else 114149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com return buf[0]; 115149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com} 116149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com 117f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.comstatic inline int calc_divisor(int bps) 118f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com{ 119f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* Original ark3116 made some exceptions in rounding here 120f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com * because windows did the same. Assume that is not really 121f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com * necessary. 122f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com * Crystal is 12MHz, probably because of USB, but we divide by 4? 123f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com */ 124f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com return (12000000 + 2*bps) / (4*bps); 125f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com} 126f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com 127815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartmanstatic int ark3116_attach(struct usb_serial *serial) 128815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman{ 129f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com struct usb_serial_port *port = serial->port[0]; 130f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com struct ark3116_private *priv; 131f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com 132f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* make sure we have our end-points */ 133f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com if ((serial->num_bulk_in == 0) || 134f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com (serial->num_bulk_out == 0) || 135f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com (serial->num_interrupt_in == 0)) { 136f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com dev_err(&serial->dev->dev, 137f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com "%s - missing endpoint - " 138f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com "bulk in: %d, bulk out: %d, int in %d\n", 139f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com KBUILD_MODNAME, 140f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com serial->num_bulk_in, 141f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com serial->num_bulk_out, 142f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com serial->num_interrupt_in); 143f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com return -EINVAL; 144f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com } 145815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 146f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com priv = kzalloc(sizeof(struct ark3116_private), 147f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com GFP_KERNEL); 148f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com if (!priv) 149fe1ae7fdd2ee603f2d95f04e09a68f7f79045127Alan Cox return -ENOMEM; 150815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 151f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com init_waitqueue_head(&priv->delta_msr_wait); 152f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com mutex_init(&priv->hw_lock); 153f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com spin_lock_init(&priv->status_lock); 154f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com 155f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com priv->irda = is_irda(serial); 156f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com 157f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com usb_set_serial_port_data(port, priv); 1585128a66c6605d8178f69b7a8f2a70060933a26b4Ondrej Zary 159f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* setup the hardware */ 160f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, UART_IER, 0); 161f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* disable DMA */ 162f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, UART_FCR, 0); 163f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* handshake control */ 164f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com priv->hcr = 0; 165f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, 0x8 , 0); 166f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* modem control */ 167f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com priv->mcr = 0; 168f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, UART_MCR, 0); 1695128a66c6605d8178f69b7a8f2a70060933a26b4Ondrej Zary 170f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com if (!(priv->irda)) { 171f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, 0xb , 0); 172f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com } else { 173f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, 0xb , 1); 174f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, 0xc , 0); 175f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, 0xd , 0x41); 176f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, 0xa , 1); 1775128a66c6605d8178f69b7a8f2a70060933a26b4Ondrej Zary } 178815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 179f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* setup baudrate */ 180f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, UART_LCR, UART_LCR_DLAB); 181815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 182f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* setup for 9600 8N1 */ 183f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com priv->quot = calc_divisor(9600); 184f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, UART_DLL, priv->quot & 0xff); 185f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, UART_DLM, (priv->quot>>8) & 0xff); 186f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com 187f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com priv->lcr = UART_LCR_WLEN8; 188f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, UART_LCR, UART_LCR_WLEN8); 189f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com 190f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, 0xe, 0); 191f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com 192f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com if (priv->irda) 193f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, 0x9, 0); 194f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com 195f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com dev_info(&serial->dev->dev, 196f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com "%s using %s mode\n", 197f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com KBUILD_MODNAME, 198f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com priv->irda ? "IrDA" : "RS232"); 199988440e7e51c6f8061c98d03d618ba090e7b84efWerner Lemberg return 0; 200fe1ae7fdd2ee603f2d95f04e09a68f7f79045127Alan Cox} 201815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 202f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.comstatic void ark3116_release(struct usb_serial *serial) 203f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com{ 204f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com struct usb_serial_port *port = serial->port[0]; 205f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com struct ark3116_private *priv = usb_get_serial_port_data(port); 206f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com 207f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* device is closed, so URBs and DMA should be down */ 208f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com 209f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com usb_set_serial_port_data(port, NULL); 210f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com 211f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com mutex_destroy(&priv->hw_lock); 212f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com 213f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com kfree(priv); 214f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com} 215f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com 216fe1ae7fdd2ee603f2d95f04e09a68f7f79045127Alan Coxstatic void ark3116_init_termios(struct tty_struct *tty) 217fe1ae7fdd2ee603f2d95f04e09a68f7f79045127Alan Cox{ 218fe1ae7fdd2ee603f2d95f04e09a68f7f79045127Alan Cox struct ktermios *termios = tty->termios; 219fe1ae7fdd2ee603f2d95f04e09a68f7f79045127Alan Cox *termios = tty_std_termios; 220fe1ae7fdd2ee603f2d95f04e09a68f7f79045127Alan Cox termios->c_cflag = B9600 | CS8 221fe1ae7fdd2ee603f2d95f04e09a68f7f79045127Alan Cox | CREAD | HUPCL | CLOCAL; 222fe1ae7fdd2ee603f2d95f04e09a68f7f79045127Alan Cox termios->c_ispeed = 9600; 223fe1ae7fdd2ee603f2d95f04e09a68f7f79045127Alan Cox termios->c_ospeed = 9600; 224815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman} 225815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 22695da310e66ee8090119596c70ca8432e57f9a97fAlan Coxstatic void ark3116_set_termios(struct tty_struct *tty, 22795da310e66ee8090119596c70ca8432e57f9a97fAlan Cox struct usb_serial_port *port, 228606d099cdd1080bbb50ea50dc52d98252f8f10a1Alan Cox struct ktermios *old_termios) 229815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman{ 230815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman struct usb_serial *serial = port->serial; 231f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com struct ark3116_private *priv = usb_get_serial_port_data(port); 23295da310e66ee8090119596c70ca8432e57f9a97fAlan Cox struct ktermios *termios = tty->termios; 233adb5dca17dde297b685d57ec68fa0e5490feee8bAlan Cox unsigned int cflag = termios->c_cflag; 234f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com int bps = tty_get_baud_rate(tty); 235f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com int quot; 236f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com __u8 lcr, hcr, eval; 237f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com 238f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* set data bit count */ 239f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com switch (cflag & CSIZE) { 240f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com case CS5: 241f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com lcr = UART_LCR_WLEN5; 242f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com break; 243f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com case CS6: 244f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com lcr = UART_LCR_WLEN6; 245f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com break; 246f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com case CS7: 247f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com lcr = UART_LCR_WLEN7; 248f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com break; 249f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com default: 250f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com case CS8: 251f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com lcr = UART_LCR_WLEN8; 252f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com break; 253f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com } 254f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com if (cflag & CSTOPB) 255f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com lcr |= UART_LCR_STOP; 256f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com if (cflag & PARENB) 257f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com lcr |= UART_LCR_PARITY; 258f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com if (!(cflag & PARODD)) 259f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com lcr |= UART_LCR_EPAR; 260f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com#ifdef CMSPAR 261f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com if (cflag & CMSPAR) 262f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com lcr |= UART_LCR_SPAR; 263f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com#endif 264f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* handshake control */ 265f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com hcr = (cflag & CRTSCTS) ? 0x03 : 0x00; 266f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com 267f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* calc baudrate */ 268f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com dbg("%s - setting bps to %d", __func__, bps); 269f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com eval = 0; 270f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com switch (bps) { 271f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com case 0: 272f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com quot = calc_divisor(9600); 273f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com break; 274f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com default: 275f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com if ((bps < 75) || (bps > 3000000)) 276f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com bps = 9600; 277f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com quot = calc_divisor(bps); 278f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com break; 279f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com case 460800: 280f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com eval = 1; 281f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com quot = calc_divisor(bps); 282f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com break; 283f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com case 921600: 284f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com eval = 2; 285f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com quot = calc_divisor(bps); 286f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com break; 287f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com } 288815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 289f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* Update state: synchronize */ 290f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com mutex_lock(&priv->hw_lock); 291815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 292f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* keep old LCR_SBC bit */ 293f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com lcr |= (priv->lcr & UART_LCR_SBC); 294815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 295f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com dbg("%s - setting hcr:0x%02x,lcr:0x%02x,quot:%d", 296f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com __func__, hcr, lcr, quot); 297815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 298f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* handshake control */ 299f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com if (priv->hcr != hcr) { 300f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com priv->hcr = hcr; 301f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, 0x8, hcr); 302815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman } 303815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 304f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* baudrate */ 305f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com if (priv->quot != quot) { 306f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com priv->quot = quot; 307f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com priv->lcr = lcr; /* need to write lcr anyway */ 308f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com 309f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* disable DMA since transmit/receive is 310f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com * shadowed by UART_DLL 311f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com */ 312f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, UART_FCR, 0); 313f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com 314f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, UART_LCR, 315f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com lcr|UART_LCR_DLAB); 316f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, UART_DLL, quot & 0xff); 317f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, UART_DLM, (quot>>8) & 0xff); 318f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com 319f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* restore lcr */ 320f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, UART_LCR, lcr); 321f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* magic baudrate thingy: not sure what it does, 322f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com * but windows does this as well. 323f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com */ 324f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, 0xe, eval); 325f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com 326f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* enable DMA */ 327f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, UART_FCR, UART_FCR_DMA_SELECT); 328f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com } else if (priv->lcr != lcr) { 329f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com priv->lcr = lcr; 330f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, UART_LCR, lcr); 331815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman } 332815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 333f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com mutex_unlock(&priv->hw_lock); 334815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 335f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* check for software flow control */ 336f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com if (I_IXOFF(tty) || I_IXON(tty)) { 337f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com dev_warn(&serial->dev->dev, 338f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com "%s: don't know how to do software flow control\n", 339f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com KBUILD_MODNAME); 340815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman } 341815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 342f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* Don't rewrite B0 */ 343f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com if (tty_termios_baud_rate(termios)) 344f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com tty_termios_encode_baud_rate(termios, bps, bps); 345f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com} 346815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 347f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.comstatic void ark3116_close(struct usb_serial_port *port) 348f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com{ 349f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com struct usb_serial *serial = port->serial; 350815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 351f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com if (serial->dev) { 352f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* disable DMA */ 353f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, UART_FCR, 0); 354815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 355f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* deactivate interrupts */ 356f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(serial, UART_IER, 0); 357adb5dca17dde297b685d57ec68fa0e5490feee8bAlan Cox 358f26788da3b342099d2b02d99ba1cb7f154d6ef7bJohan Hovold usb_serial_generic_close(port); 359f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com if (serial->num_interrupt_in) 360f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com usb_kill_urb(port->interrupt_in_urb); 361f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com } 362f26788da3b342099d2b02d99ba1cb7f154d6ef7bJohan Hovold 363815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman} 364815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 365a509a7e478e4766114d69f12d19d644ac63e9765Alan Coxstatic int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port) 366815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman{ 367f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com struct ark3116_private *priv = usb_get_serial_port_data(port); 368815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman struct usb_serial *serial = port->serial; 369f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com unsigned char *buf; 370f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com int result; 371815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 372815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman buf = kmalloc(1, GFP_KERNEL); 373f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com if (buf == NULL) 374815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman return -ENOMEM; 375815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 376a509a7e478e4766114d69f12d19d644ac63e9765Alan Cox result = usb_serial_generic_open(tty, port); 377f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com if (result) { 378f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com dbg("%s - usb_serial_generic_open failed: %d", 379f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com __func__, result); 3804edf2c83637b9e9db771cc5629de036fe4488564Oliver Neukum goto err_out; 381f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com } 382815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 383f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* remove any data still left: also clears error state */ 384f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_read_reg(serial, UART_RX, buf); 385815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 386f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* read modem status */ 387f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com priv->msr = ark3116_read_reg(serial, UART_MSR, buf); 388f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* read line status */ 389f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com priv->lsr = ark3116_read_reg(serial, UART_LSR, buf); 390815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 391f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 392f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com if (result) { 393f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com dev_err(&port->dev, "submit irq_in urb failed %d\n", 394f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com result); 395f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_close(port); 396f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com goto err_out; 397f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com } 398815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 399f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* activate interrupts */ 400f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(port->serial, UART_IER, UART_IER_MSI|UART_IER_RLSI); 401815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 402f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* enable DMA */ 403f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com ark3116_write_reg(port->serial, UART_FCR, UART_FCR_DMA_SELECT); 404815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 405583182ba5f02c8c9be82ea550f2051eaec15b975Bart Hartgers /* setup termios */ 406583182ba5f02c8c9be82ea550f2051eaec15b975Bart Hartgers if (tty) 407583182ba5f02c8c9be82ea550f2051eaec15b975Bart Hartgers ark3116_set_termios(tty, port, NULL); 408583182ba5f02c8c9be82ea550f2051eaec15b975Bart Hartgers 4094edf2c83637b9e9db771cc5629de036fe4488564Oliver Neukumerr_out: 410815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman kfree(buf); 411815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman return result; 412815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman} 413815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 4140bca1b913affbd7e2fdaffee62a499659a466eb5Alan Coxstatic int ark3116_get_icount(struct tty_struct *tty, 4150bca1b913affbd7e2fdaffee62a499659a466eb5Alan Cox struct serial_icounter_struct *icount) 4160bca1b913affbd7e2fdaffee62a499659a466eb5Alan Cox{ 4170bca1b913affbd7e2fdaffee62a499659a466eb5Alan Cox struct usb_serial_port *port = tty->driver_data; 4180bca1b913affbd7e2fdaffee62a499659a466eb5Alan Cox struct ark3116_private *priv = usb_get_serial_port_data(port); 4190bca1b913affbd7e2fdaffee62a499659a466eb5Alan Cox struct async_icount cnow = priv->icount; 4200bca1b913affbd7e2fdaffee62a499659a466eb5Alan Cox icount->cts = cnow.cts; 4210bca1b913affbd7e2fdaffee62a499659a466eb5Alan Cox icount->dsr = cnow.dsr; 4220bca1b913affbd7e2fdaffee62a499659a466eb5Alan Cox icount->rng = cnow.rng; 4230bca1b913affbd7e2fdaffee62a499659a466eb5Alan Cox icount->dcd = cnow.dcd; 4240bca1b913affbd7e2fdaffee62a499659a466eb5Alan Cox icount->rx = cnow.rx; 4250bca1b913affbd7e2fdaffee62a499659a466eb5Alan Cox icount->tx = cnow.tx; 4260bca1b913affbd7e2fdaffee62a499659a466eb5Alan Cox icount->frame = cnow.frame; 4270bca1b913affbd7e2fdaffee62a499659a466eb5Alan Cox icount->overrun = cnow.overrun; 4280bca1b913affbd7e2fdaffee62a499659a466eb5Alan Cox icount->parity = cnow.parity; 4290bca1b913affbd7e2fdaffee62a499659a466eb5Alan Cox icount->brk = cnow.brk; 4300bca1b913affbd7e2fdaffee62a499659a466eb5Alan Cox icount->buf_overrun = cnow.buf_overrun; 4310bca1b913affbd7e2fdaffee62a499659a466eb5Alan Cox return 0; 4320bca1b913affbd7e2fdaffee62a499659a466eb5Alan Cox} 4330bca1b913affbd7e2fdaffee62a499659a466eb5Alan Cox 43400a0d0d65b61241a718d0aee96f46b9a2d93bf26Alan Coxstatic int ark3116_ioctl(struct tty_struct *tty, 435815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman unsigned int cmd, unsigned long arg) 436815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman{ 43795da310e66ee8090119596c70ca8432e57f9a97fAlan Cox struct usb_serial_port *port = tty->driver_data; 438f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com struct ark3116_private *priv = usb_get_serial_port_data(port); 4392f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg struct serial_struct serstruct; 4402f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg void __user *user_arg = (void __user *)arg; 4412f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg 4422f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg switch (cmd) { 4432f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg case TIOCGSERIAL: 4442f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg /* XXX: Some of these values are probably wrong. */ 445c4d0f8cbca3a97900f85b082064a63c7a5928bd7Alan Cox memset(&serstruct, 0, sizeof(serstruct)); 4462f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg serstruct.type = PORT_16654; 4472f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg serstruct.line = port->serial->minor; 4482f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg serstruct.port = port->number; 4492f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg serstruct.custom_divisor = 0; 4502f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg serstruct.baud_base = 460800; 4512f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg 452c4d0f8cbca3a97900f85b082064a63c7a5928bd7Alan Cox if (copy_to_user(user_arg, &serstruct, sizeof(serstruct))) 4532f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg return -EFAULT; 4542f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg 4552f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg return 0; 4562f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg case TIOCSSERIAL: 457c4d0f8cbca3a97900f85b082064a63c7a5928bd7Alan Cox if (copy_from_user(&serstruct, user_arg, sizeof(serstruct))) 4582f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg return -EFAULT; 4592f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg return 0; 460f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com case TIOCMIWAIT: 461f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com for (;;) { 462f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com struct async_icount prev = priv->icount; 463f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com interruptible_sleep_on(&priv->delta_msr_wait); 464f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com /* see if a signal did it */ 465f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com if (signal_pending(current)) 466f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com return -ERESTARTSYS; 467f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com if ((prev.rng == priv->icount.rng) && 468f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com (prev.dsr == priv->icount.dsr) && 469f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com (prev.dcd == priv->icount.dcd) && 470f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com (prev.cts == priv->icount.cts)) 471f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com return -EIO; 472f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com if ((arg & TIOCM_RNG && 473f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com (prev.rng != priv->icount.rng)) || 474f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com (arg & TIOCM_DSR && 475f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com (prev.dsr != priv->icount.dsr)) || 476f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com (arg & TIOCM_CD && 477f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com (prev.dcd != priv->icount.dcd)) || 478f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com (arg & TIOCM_CTS && 479f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com (prev.cts != priv->icount.cts))) 480f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com return 0; 481f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com } 4822f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg break; 4832f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg } 4842f430b4bbae7faa167730f954252eb7db4ac58ddWerner Lemberg 485815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman return -ENOIOCTLCMD; 486815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman} 487815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 48860b33c133ca0b7c0b6072c87234b63fee6e80558Alan Coxstatic int ark3116_tiocmget(struct tty_struct *tty) 489815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman{ 49095da310e66ee8090119596c70ca8432e57f9a97fAlan Cox struct usb_serial_port *port = tty->driver_data; 4911f719105131010cdb9a4b5a3bace21f6b2e095eabart.hartgers@gmail.com struct ark3116_private *priv = usb_get_serial_port_data(port); 4921f719105131010cdb9a4b5a3bace21f6b2e095eabart.hartgers@gmail.com __u32 status; 4931f719105131010cdb9a4b5a3bace21f6b2e095eabart.hartgers@gmail.com __u32 ctrl; 4941f719105131010cdb9a4b5a3bace21f6b2e095eabart.hartgers@gmail.com unsigned long flags; 495815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 4961f719105131010cdb9a4b5a3bace21f6b2e095eabart.hartgers@gmail.com mutex_lock(&priv->hw_lock); 4971f719105131010cdb9a4b5a3bace21f6b2e095eabart.hartgers@gmail.com ctrl = priv->mcr; 4981f719105131010cdb9a4b5a3bace21f6b2e095eabart.hartgers@gmail.com mutex_unlock(&priv->hw_lock); 499815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 5001f719105131010cdb9a4b5a3bace21f6b2e095eabart.hartgers@gmail.com spin_lock_irqsave(&priv->status_lock, flags); 5011f719105131010cdb9a4b5a3bace21f6b2e095eabart.hartgers@gmail.com status = priv->msr; 5021f719105131010cdb9a4b5a3bace21f6b2e095eabart.hartgers@gmail.com spin_unlock_irqrestore(&priv->status_lock, flags); 5031f719105131010cdb9a4b5a3bace21f6b2e095eabart.hartgers@gmail.com 5041f719105131010cdb9a4b5a3bace21f6b2e095eabart.hartgers@gmail.com return (status & UART_MSR_DSR ? TIOCM_DSR : 0) | 5051f719105131010cdb9a4b5a3bace21f6b2e095eabart.hartgers@gmail.com (status & UART_MSR_CTS ? TIOCM_CTS : 0) | 5061f719105131010cdb9a4b5a3bace21f6b2e095eabart.hartgers@gmail.com (status & UART_MSR_RI ? TIOCM_RI : 0) | 5071f719105131010cdb9a4b5a3bace21f6b2e095eabart.hartgers@gmail.com (status & UART_MSR_DCD ? TIOCM_CD : 0) | 5081f719105131010cdb9a4b5a3bace21f6b2e095eabart.hartgers@gmail.com (ctrl & UART_MCR_DTR ? TIOCM_DTR : 0) | 5091f719105131010cdb9a4b5a3bace21f6b2e095eabart.hartgers@gmail.com (ctrl & UART_MCR_RTS ? TIOCM_RTS : 0) | 5101f719105131010cdb9a4b5a3bace21f6b2e095eabart.hartgers@gmail.com (ctrl & UART_MCR_OUT1 ? TIOCM_OUT1 : 0) | 5111f719105131010cdb9a4b5a3bace21f6b2e095eabart.hartgers@gmail.com (ctrl & UART_MCR_OUT2 ? TIOCM_OUT2 : 0); 512815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman} 513815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 51420b9d17715017ae4dd4ec87fabc36d33b9de708eAlan Coxstatic int ark3116_tiocmset(struct tty_struct *tty, 515546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com unsigned set, unsigned clr) 516546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com{ 517546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com struct usb_serial_port *port = tty->driver_data; 518546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com struct ark3116_private *priv = usb_get_serial_port_data(port); 519546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com 520546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com /* we need to take the mutex here, to make sure that the value 521546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com * in priv->mcr is actually the one that is in the hardware 522546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com */ 523546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com 524546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com mutex_lock(&priv->hw_lock); 525546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com 526546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com if (set & TIOCM_RTS) 527546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com priv->mcr |= UART_MCR_RTS; 528546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com if (set & TIOCM_DTR) 529546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com priv->mcr |= UART_MCR_DTR; 530546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com if (set & TIOCM_OUT1) 531546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com priv->mcr |= UART_MCR_OUT1; 532546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com if (set & TIOCM_OUT2) 533546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com priv->mcr |= UART_MCR_OUT2; 534546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com if (clr & TIOCM_RTS) 535546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com priv->mcr &= ~UART_MCR_RTS; 536546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com if (clr & TIOCM_DTR) 537546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com priv->mcr &= ~UART_MCR_DTR; 538546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com if (clr & TIOCM_OUT1) 539546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com priv->mcr &= ~UART_MCR_OUT1; 540546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com if (clr & TIOCM_OUT2) 541546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com priv->mcr &= ~UART_MCR_OUT2; 542546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com 543546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com ark3116_write_reg(port->serial, UART_MCR, priv->mcr); 544546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com 545546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com mutex_unlock(&priv->hw_lock); 546546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com 547546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com return 0; 548546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com} 549546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com 550546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.comstatic void ark3116_break_ctl(struct tty_struct *tty, int break_state) 551546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com{ 552546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com struct usb_serial_port *port = tty->driver_data; 553546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com struct ark3116_private *priv = usb_get_serial_port_data(port); 554546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com 555546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com /* LCR is also used for other things: protect access */ 556546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com mutex_lock(&priv->hw_lock); 557546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com 558546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com if (break_state) 559546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com priv->lcr |= UART_LCR_SBC; 560546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com else 561546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com priv->lcr &= ~UART_LCR_SBC; 562546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com 563546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com ark3116_write_reg(port->serial, UART_LCR, priv->lcr); 564546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com 565546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com mutex_unlock(&priv->hw_lock); 566546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com} 567546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com 56862d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.comstatic void ark3116_update_msr(struct usb_serial_port *port, __u8 msr) 56962d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com{ 57062d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com struct ark3116_private *priv = usb_get_serial_port_data(port); 57162d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com unsigned long flags; 57262d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com 57362d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com spin_lock_irqsave(&priv->status_lock, flags); 57462d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com priv->msr = msr; 57562d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com spin_unlock_irqrestore(&priv->status_lock, flags); 57662d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com 57762d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com if (msr & UART_MSR_ANY_DELTA) { 57862d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com /* update input line counters */ 57962d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com if (msr & UART_MSR_DCTS) 58062d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com priv->icount.cts++; 58162d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com if (msr & UART_MSR_DDSR) 58262d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com priv->icount.dsr++; 58362d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com if (msr & UART_MSR_DDCD) 58462d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com priv->icount.dcd++; 58562d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com if (msr & UART_MSR_TERI) 58662d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com priv->icount.rng++; 58762d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com wake_up_interruptible(&priv->delta_msr_wait); 58862d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com } 58962d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com} 59062d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com 59162d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.comstatic void ark3116_update_lsr(struct usb_serial_port *port, __u8 lsr) 59262d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com{ 59362d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com struct ark3116_private *priv = usb_get_serial_port_data(port); 59462d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com unsigned long flags; 59562d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com 59662d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com spin_lock_irqsave(&priv->status_lock, flags); 59762d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com /* combine bits */ 59862d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com priv->lsr |= lsr; 59962d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com spin_unlock_irqrestore(&priv->status_lock, flags); 60062d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com 60162d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com if (lsr&UART_LSR_BRK_ERROR_BITS) { 60262d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com if (lsr & UART_LSR_BI) 60362d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com priv->icount.brk++; 60462d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com if (lsr & UART_LSR_FE) 60562d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com priv->icount.frame++; 60662d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com if (lsr & UART_LSR_PE) 60762d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com priv->icount.parity++; 60862d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com if (lsr & UART_LSR_OE) 60962d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com priv->icount.overrun++; 61062d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com } 61162d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com} 61262d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com 61362d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.comstatic void ark3116_read_int_callback(struct urb *urb) 61462d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com{ 61562d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com struct usb_serial_port *port = urb->context; 61662d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com int status = urb->status; 61762d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com const __u8 *data = urb->transfer_buffer; 61862d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com int result; 61962d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com 62062d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com switch (status) { 62162d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com case -ECONNRESET: 62262d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com case -ENOENT: 62362d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com case -ESHUTDOWN: 62462d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com /* this urb is terminated, clean up */ 62562d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com dbg("%s - urb shutting down with status: %d", 62662d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com __func__, status); 62762d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com return; 62862d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com default: 62962d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com dbg("%s - nonzero urb status received: %d", 63062d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com __func__, status); 63162d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com break; 63262d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com case 0: /* success */ 63362d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com /* discovered this by trail and error... */ 63462d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com if ((urb->actual_length == 4) && (data[0] == 0xe8)) { 63562d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com const __u8 id = data[1]&UART_IIR_ID; 63662d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com dbg("%s: iir=%02x", __func__, data[1]); 63762d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com if (id == UART_IIR_MSI) { 63862d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com dbg("%s: msr=%02x", __func__, data[3]); 63962d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com ark3116_update_msr(port, data[3]); 64062d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com break; 64162d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com } else if (id == UART_IIR_RLSI) { 64262d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com dbg("%s: lsr=%02x", __func__, data[2]); 64362d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com ark3116_update_lsr(port, data[2]); 64462d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com break; 64562d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com } 64662d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com } 64762d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com /* 64862d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com * Not sure what this data meant... 64962d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com */ 65062d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com usb_serial_debug_data(debug, &port->dev, 65162d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com __func__, 65262d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com urb->actual_length, 65362d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com urb->transfer_buffer); 65462d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com break; 65562d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com } 65662d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com 65762d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com result = usb_submit_urb(urb, GFP_ATOMIC); 65862d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com if (result) 65962d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com dev_err(&urb->dev->dev, 66062d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com "%s - Error %d submitting interrupt urb\n", 66162d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com __func__, result); 66262d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com} 66362d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com 66462d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com 66562d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com/* Data comes in via the bulk (data) URB, erors/interrupts via the int URB. 66662d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com * This means that we cannot be sure which data byte has an associated error 66762d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com * condition, so we report an error for all data in the next bulk read. 66862d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com * 66962d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com * Actually, there might even be a window between the bulk data leaving the 67062d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com * ark and reading/resetting the lsr in the read_bulk_callback where an 67162d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com * interrupt for the next data block could come in. 67262d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com * Without somekind of ordering on the ark, we would have to report the 67362d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com * error for the next block of data as well... 67462d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com * For now, let's pretend this can't happen. 67562d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com */ 67682b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovoldstatic void ark3116_process_read_urb(struct urb *urb) 67762d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com{ 67882b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold struct usb_serial_port *port = urb->context; 67962d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com struct ark3116_private *priv = usb_get_serial_port_data(port); 68062d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com struct tty_struct *tty; 68182b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold unsigned char *data = urb->transfer_buffer; 68282b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold char tty_flag = TTY_NORMAL; 68362d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com unsigned long flags; 68462d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com __u32 lsr; 68562d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com 68682b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold /* update line status */ 68782b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold spin_lock_irqsave(&priv->status_lock, flags); 68882b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold lsr = priv->lsr; 68982b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold priv->lsr &= ~UART_LSR_BRK_ERROR_BITS; 69082b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold spin_unlock_irqrestore(&priv->status_lock, flags); 69182b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold 69282b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold if (!urb->actual_length) 69362d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com return; 69462d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com 69582b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold tty = tty_port_tty_get(&port->port); 69682b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold if (!tty) 69782b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold return; 69882b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold 69982b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold if (lsr & UART_LSR_BRK_ERROR_BITS) { 70082b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold if (lsr & UART_LSR_BI) 70182b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold tty_flag = TTY_BREAK; 70282b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold else if (lsr & UART_LSR_PE) 70382b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold tty_flag = TTY_PARITY; 70482b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold else if (lsr & UART_LSR_FE) 70582b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold tty_flag = TTY_FRAME; 70662d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com 70782b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold /* overrun is special, not associated with a char */ 70882b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold if (lsr & UART_LSR_OE) 70982b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold tty_insert_flip_char(tty, 0, TTY_OVERRUN); 71062d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com } 71182b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold tty_insert_flip_string_fixed_flag(tty, data, tty_flag, 71282b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold urb->actual_length); 71382b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold tty_flip_buffer_push(tty); 71482b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold tty_kref_put(tty); 71562d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com} 71662d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com 717815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartmanstatic struct usb_driver ark3116_driver = { 718815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman .name = "ark3116", 719815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman .probe = usb_serial_probe, 720815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman .disconnect = usb_serial_disconnect, 721815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman .id_table = id_table, 722815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman}; 723815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 724815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartmanstatic struct usb_serial_driver ark3116_device = { 725815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman .driver = { 726815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman .owner = THIS_MODULE, 727815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman .name = "ark3116", 728815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman }, 729815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman .id_table = id_table, 730815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman .num_ports = 1, 731815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman .attach = ark3116_attach, 732f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com .release = ark3116_release, 733815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman .set_termios = ark3116_set_termios, 734fe1ae7fdd2ee603f2d95f04e09a68f7f79045127Alan Cox .init_termios = ark3116_init_termios, 735815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman .ioctl = ark3116_ioctl, 736815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman .tiocmget = ark3116_tiocmget, 737546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com .tiocmset = ark3116_tiocmset, 7380bca1b913affbd7e2fdaffee62a499659a466eb5Alan Cox .get_icount = ark3116_get_icount, 739815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman .open = ark3116_open, 740f4c1e8d597d1a440175db0d709c921cf3a49cfe7bart.hartgers@gmail.com .close = ark3116_close, 741546b742968e7789c60efe0eec71896c45eeb6893bart.hartgers@gmail.com .break_ctl = ark3116_break_ctl, 74262d826c8ddafb0a55eb6c5255779ddb782dc5507bart.hartgers@gmail.com .read_int_callback = ark3116_read_int_callback, 74382b71cfdf36d568c7a2e44efd705471c3c2caaa2Johan Hovold .process_read_urb = ark3116_process_read_urb, 744815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman}; 745815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 74608a4f6bc2e7046ce50849d7589b7d0763926d808Alan Sternstatic struct usb_serial_driver * const serial_drivers[] = { 74708a4f6bc2e7046ce50849d7589b7d0763926d808Alan Stern &ark3116_device, NULL 74808a4f6bc2e7046ce50849d7589b7d0763926d808Alan Stern}; 74908a4f6bc2e7046ce50849d7589b7d0763926d808Alan Stern 750a9a535d35844044e3df56e49df5176db26bbb487Greg Kroah-Hartmanmodule_usb_serial_driver(ark3116_driver, serial_drivers); 751815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 752815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-HartmanMODULE_LICENSE("GPL"); 753815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 754149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.comMODULE_AUTHOR(DRIVER_AUTHOR); 755149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.comMODULE_DESCRIPTION(DRIVER_DESC); 756149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com 757815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartmanmodule_param(debug, bool, S_IRUGO | S_IWUSR); 758149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.comMODULE_PARM_DESC(debug, "Enable debug"); 759815ddc99dd8108908d14c699a37d0f5974da6defGreg Kroah-Hartman 760149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com/* 761149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * The following describes what I learned from studying the old 762149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * ark3116.c driver, disassembling the windows driver, and some lucky 763149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * guesses. Since I do not have any datasheet or other 764149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * documentation, inaccuracies are almost guaranteed. 765149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 766149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * Some specs for the ARK3116 can be found here: 767149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * http://web.archive.org/web/20060318000438/ 768149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * www.arkmicro.com/en/products/view.php?id=10 769149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * On that page, 2 GPIO pins are mentioned: I assume these are the 770149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * OUT1 and OUT2 pins of the UART, so I added support for those 771149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * through the MCR. Since the pins are not available on my hardware, 772149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * I could not verify this. 773149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * Also, it states there is "on-chip hardware flow control". I have 774149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * discovered how to enable that. Unfortunately, I do not know how to 775149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * enable XON/XOFF (software) flow control, which would need support 776149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * from the chip as well to work. Because of the wording on the web 777149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * page there is a real possibility the chip simply does not support 778149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * software flow control. 779149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 780149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * I got my ark3116 as part of a mobile phone adapter cable. On the 781149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * PCB, the following numbered contacts are present: 782149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 783149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 1:- +5V 784149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 2:o DTR 785149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 3:i RX 786149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 4:i DCD 787149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 5:o RTS 788149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 6:o TX 789149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 7:i RI 790149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 8:i DSR 791149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 10:- 0V 792149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 11:i CTS 793149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 794149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * On my chip, all signals seem to be 3.3V, but 5V tolerant. But that 795149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * may be different for the one you have ;-). 796149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 797149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * The windows driver limits the registers to 0-F, so I assume there 798149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * are actually 16 present on the device. 799149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 800149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * On an UART interrupt, 4 bytes of data come in on the interrupt 801149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * endpoint. The bytes are 0xe8 IIR LSR MSR. 802149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 803149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * The baudrate seems to be generated from the 12MHz crystal, using 804149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 4-times subsampling. So quot=12e6/(4*baud). Also see description 805149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * of register E. 806149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 807149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * Registers 0-7: 808149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * These seem to be the same as for a regular 16450. The FCR is set 809149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * to UART_FCR_DMA_SELECT (0x8), I guess to enable transfers between 810149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * the UART and the USB bridge/DMA engine. 811149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 812149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * Register 8: 813149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * By trial and error, I found out that bit 0 enables hardware CTS, 814149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * stopping TX when CTS is +5V. Bit 1 does the same for RTS, making 815149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * RTS +5V when the 3116 cannot transfer the data to the USB bus 816149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * (verified by disabling the reading URB). Note that as far as I can 817149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * tell, the windows driver does NOT use this, so there might be some 818149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * hardware bug or something. 819149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 820149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * According to a patch provided here 821149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * (http://lkml.org/lkml/2009/7/26/56), the ARK3116 can also be used 822149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * as an IrDA dongle. Since I do not have such a thing, I could not 823149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * investigate that aspect. However, I can speculate ;-). 824149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 825149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * - IrDA encodes data differently than RS232. Most likely, one of 826149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * the bits in registers 9..E enables the IR ENDEC (encoder/decoder). 827149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * - Depending on the IR transceiver, the input and output need to be 828149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * inverted, so there are probably bits for that as well. 829149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * - IrDA is half-duplex, so there should be a bit for selecting that. 830149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 831149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * This still leaves at least two registers unaccounted for. Perhaps 832149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * The chip can do XON/XOFF or CRC in HW? 833149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 834149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * Register 9: 835149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * Set to 0x00 for IrDA, when the baudrate is initialised. 836149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 837149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * Register A: 838149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * Set to 0x01 for IrDA, at init. 839149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 840149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * Register B: 841149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * Set to 0x01 for IrDA, 0x00 for RS232, at init. 842149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 843149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * Register C: 844149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * Set to 00 for IrDA, at init. 845149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 846149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * Register D: 847149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * Set to 0x41 for IrDA, at init. 848149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 849149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * Register E: 850149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * Somekind of baudrate override. The windows driver seems to set 851149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * this to 0x00 for normal baudrates, 0x01 for 460800, 0x02 for 921600. 852149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * Since 460800 and 921600 cannot be obtained by dividing 3MHz by an integer, 853149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * it could be somekind of subdivisor thingy. 854149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * However,it does not seem to do anything: selecting 921600 (divisor 3, 855149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * reg E=2), still gets 1 MHz. I also checked if registers 9, C or F would 856149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * work, but they don't. 857149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * 858149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com * Register F: unknown 859149fc791a452df5e8fa155f553b3027a874adf62bart.hartgers@gmail.com */ 860