drivers/usb/serial/ftdi_sio.c
Source file repositories/reference/linux-study-clean/drivers/usb/serial/ftdi_sio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/serial/ftdi_sio.c- Extension
.c- Size
- 98875 bytes
- Lines
- 2878
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/errno.hlinux/slab.hlinux/tty.hlinux/tty_driver.hlinux/tty_flip.hlinux/module.hlinux/spinlock.hlinux/mutex.hlinux/uaccess.hlinux/usb.hlinux/serial.hlinux/gpio/driver.hlinux/usb/serial.hftdi_sio.hftdi_sio_ids.h
Detected Declarations
struct ftdi_privatestruct ftdi_quirkenum ftdi_chip_typefunction ftdi_232am_baud_base_to_divisorfunction ftdi_232am_baud_to_divisorfunction ftdi_232bm_baud_base_to_divisorfunction ftdi_232bm_baud_to_divisorfunction ftdi_2232h_baud_base_to_divisorfunction ftdi_2232h_baud_to_divisorfunction update_mctrlfunction get_ftdi_divisorfunction change_speedfunction write_latency_timerfunction _read_latency_timerfunction read_latency_timerfunction get_serial_infofunction set_serial_infofunction get_lsr_infofunction ftdi_determine_typefunction ftdi_set_max_packet_sizefunction latency_timer_showfunction latency_timer_storefunction event_char_storefunction ftdi_is_visiblefunction ftdi_set_bitmodefunction ftdi_set_cbus_pinsfunction ftdi_exit_cbus_modefunction ftdi_gpio_requestfunction ftdi_read_cbus_pinsfunction ftdi_gpio_getfunction ftdi_gpio_setfunction ftdi_gpio_get_multiplefunction ftdi_gpio_set_multiplefunction ftdi_gpio_direction_getfunction ftdi_gpio_direction_inputfunction ftdi_gpio_direction_outputfunction ftdi_gpio_init_valid_maskfunction ftdi_read_eepromfunction ftdi_gpio_init_ft232hfunction ftdi_gpio_init_ft232rfunction ftdi_gpio_init_ftxfunction ftdi_gpio_initfunction ftdi_gpio_removefunction ftdi_gpio_initfunction ftdi_gpio_removefunction ftdi_port_probefunction ftdi_usb_uirt_setupfunction ftdi_he_tira1_setup
Annotated Snippet
struct ftdi_private {
enum ftdi_chip_type chip_type;
int baud_base; /* baud base clock for divisor setting */
int custom_divisor; /* custom_divisor kludge, this is for
baud_base (different from what goes to the
chip!) */
u16 last_set_data_value; /* the last data state set - needed for doing
* a break
*/
int flags; /* some ASYNC_xxxx flags are supported */
unsigned long last_dtr_rts; /* saved modem control outputs */
char prev_status; /* Used for TIOCMIWAIT */
char transmit_empty; /* If transmitter is empty or not */
u16 channel; /* channel index, or 0 for legacy types */
speed_t force_baud; /* if non-zero, force the baud rate to
this value */
int force_rtscts; /* if non-zero, force RTS-CTS to always
be enabled */
unsigned int latency; /* latency setting in use */
unsigned short max_packet_size;
struct mutex cfg_lock; /* Avoid mess by parallel calls of config ioctl() and change_speed() */
#ifdef CONFIG_GPIOLIB
struct gpio_chip gc;
struct mutex gpio_lock; /* protects GPIO state */
bool gpio_registered; /* is the gpiochip in kernel registered */
bool gpio_used; /* true if the user requested a gpio */
u8 gpio_altfunc; /* which pins are in gpio mode */
u8 gpio_output; /* pin directions cache */
u8 gpio_value; /* pin value for outputs */
#endif
};
struct ftdi_quirk {
int (*probe)(struct usb_serial *);
/* Special settings for probed ports. */
void (*port_probe)(struct ftdi_private *);
};
static int ftdi_jtag_probe(struct usb_serial *serial);
static int ftdi_stmclite_probe(struct usb_serial *serial);
static int ftdi_8u2232c_probe(struct usb_serial *serial);
static void ftdi_usb_uirt_setup(struct ftdi_private *priv);
static void ftdi_he_tira1_setup(struct ftdi_private *priv);
static const struct ftdi_quirk ftdi_jtag_quirk = {
.probe = ftdi_jtag_probe,
};
static const struct ftdi_quirk ftdi_ndi_quirk = {
};
static const struct ftdi_quirk ftdi_usb_uirt_quirk = {
.port_probe = ftdi_usb_uirt_setup,
};
static const struct ftdi_quirk ftdi_he_tira1_quirk = {
.port_probe = ftdi_he_tira1_setup,
};
static const struct ftdi_quirk ftdi_stmclite_quirk = {
.probe = ftdi_stmclite_probe,
};
static const struct ftdi_quirk ftdi_8u2232c_quirk = {
.probe = ftdi_8u2232c_probe,
};
/*
* The 8U232AM has the same API as the sio except for:
* - it can support MUCH higher baudrates; up to:
* o 921600 for RS232 and 2000000 for RS422/485 at 48MHz
* o 230400 at 12MHz
* so .. 8U232AM's baudrate setting codes are different
* - it has a two byte status code.
* - it returns characters every 16ms (the FTDI does it every 40ms)
*
* the bcdDevice value is used to differentiate FT232BM and FT245BM from
* the earlier FT8U232AM and FT8U232BM. For now, include all known VID/PID
* combinations in both tables.
* FIXME: perhaps bcdDevice can also identify 12MHz FT8U232AM devices,
* but I don't know if those ever went into mass production. [Ian Abbott]
*/
/*
* Device ID not listed? Test it using
* /sys/bus/usb-serial/drivers/ftdi_sio/new_id and send a patch or report.
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/errno.h`, `linux/slab.h`, `linux/tty.h`, `linux/tty_driver.h`, `linux/tty_flip.h`, `linux/module.h`, `linux/spinlock.h`.
- Detected declarations: `struct ftdi_private`, `struct ftdi_quirk`, `enum ftdi_chip_type`, `function ftdi_232am_baud_base_to_divisor`, `function ftdi_232am_baud_to_divisor`, `function ftdi_232bm_baud_base_to_divisor`, `function ftdi_232bm_baud_to_divisor`, `function ftdi_2232h_baud_base_to_divisor`, `function ftdi_2232h_baud_to_divisor`, `function update_mctrl`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.