drivers/usb/serial/ark3116.c
Source file repositories/reference/linux-study-clean/drivers/usb/serial/ark3116.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/serial/ark3116.c- Extension
.c- Size
- 20097 bytes
- Lines
- 735
- Domain
- Driver Families
- Bucket
- drivers/usb
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/ioctl.hlinux/tty.hlinux/slab.hlinux/tty_flip.hlinux/module.hlinux/usb.hlinux/usb/serial.hlinux/serial.hlinux/serial_reg.hlinux/uaccess.hlinux/mutex.hlinux/spinlock.h
Detected Declarations
struct ark3116_privatefunction is_irdafunction ark3116_write_regfunction ark3116_read_regfunction calc_divisorfunction ark3116_port_probefunction ark3116_port_removefunction ark3116_set_termiosfunction ark3116_closefunction ark3116_openfunction ark3116_tiocmgetfunction ark3116_tiocmsetfunction ark3116_break_ctlfunction ark3116_update_msrfunction ark3116_update_lsrfunction ark3116_read_int_callbackfunction ark3116_process_read_urb
Annotated Snippet
struct ark3116_private {
int irda; /* 1 for irda device */
/* protects hw register updates */
struct mutex hw_lock;
int quot; /* baudrate divisor */
__u32 lcr; /* line control register value */
__u32 hcr; /* handshake control register (0x8)
* value */
__u32 mcr; /* modem control register value */
/* protects the status values below */
spinlock_t status_lock;
__u32 msr; /* modem status register value */
__u32 lsr; /* line status register value */
};
static int ark3116_write_reg(struct usb_serial *serial,
unsigned reg, __u8 val)
{
int result;
/* 0xfe 0x40 are magic values taken from original driver */
result = usb_control_msg(serial->dev,
usb_sndctrlpipe(serial->dev, 0),
0xfe, 0x40, val, reg,
NULL, 0, ARK_TIMEOUT);
if (result)
return result;
return 0;
}
static int ark3116_read_reg(struct usb_serial *serial,
unsigned reg, unsigned char *buf)
{
int result;
/* 0xfe 0xc0 are magic values taken from original driver */
result = usb_control_msg(serial->dev,
usb_rcvctrlpipe(serial->dev, 0),
0xfe, 0xc0, 0, reg,
buf, 1, ARK_TIMEOUT);
if (result < 1) {
dev_err(&serial->interface->dev,
"failed to read register %u: %d\n",
reg, result);
if (result >= 0)
result = -EIO;
return result;
}
return 0;
}
static inline int calc_divisor(int bps)
{
/* Original ark3116 made some exceptions in rounding here
* because windows did the same. Assume that is not really
* necessary.
* Crystal is 12MHz, probably because of USB, but we divide by 4?
*/
return (12000000 + 2*bps) / (4*bps);
}
static int ark3116_port_probe(struct usb_serial_port *port)
{
struct usb_serial *serial = port->serial;
struct ark3116_private *priv;
priv = kzalloc_obj(*priv);
if (!priv)
return -ENOMEM;
mutex_init(&priv->hw_lock);
spin_lock_init(&priv->status_lock);
priv->irda = is_irda(serial);
usb_set_serial_port_data(port, priv);
/* setup the hardware */
ark3116_write_reg(serial, UART_IER, 0);
/* disable DMA */
ark3116_write_reg(serial, UART_FCR, 0);
/* handshake control */
priv->hcr = 0;
ark3116_write_reg(serial, 0x8 , 0);
/* modem control */
priv->mcr = 0;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/ioctl.h`, `linux/tty.h`, `linux/slab.h`, `linux/tty_flip.h`, `linux/module.h`, `linux/usb.h`, `linux/usb/serial.h`.
- Detected declarations: `struct ark3116_private`, `function is_irda`, `function ark3116_write_reg`, `function ark3116_read_reg`, `function calc_divisor`, `function ark3116_port_probe`, `function ark3116_port_remove`, `function ark3116_set_termios`, `function ark3116_close`, `function ark3116_open`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.