drivers/tty/serdev/serdev-ttyport.c
Source file repositories/reference/linux-study-clean/drivers/tty/serdev/serdev-ttyport.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/tty/serdev/serdev-ttyport.c- Extension
.c- Size
- 7986 bytes
- Lines
- 321
- Domain
- Driver Families
- Bucket
- drivers/tty
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/serdev.hlinux/tty.hlinux/tty_driver.hlinux/poll.h
Detected Declarations
struct serportfunction ttyport_receive_buffunction ttyport_write_wakeupfunction ttyport_write_buffunction ttyport_write_flushfunction ttyport_openfunction ttyport_closefunction ttyport_set_baudratefunction ttyport_set_flow_controlfunction ttyport_set_parityfunction ttyport_wait_until_sentfunction ttyport_get_tiocmfunction ttyport_set_tiocmfunction ttyport_break_ctlfunction serdev_tty_port_unregister
Annotated Snippet
struct serport {
struct tty_port *port;
struct tty_struct *tty;
struct tty_driver *tty_drv;
int tty_idx;
unsigned long flags;
};
/*
* Callback functions from the tty port.
*/
static size_t ttyport_receive_buf(struct tty_port *port, const u8 *cp,
const u8 *fp, size_t count)
{
struct serdev_controller *ctrl = port->client_data;
struct serport *serport = serdev_controller_get_drvdata(ctrl);
size_t ret;
if (!test_bit(SERPORT_ACTIVE, &serport->flags))
return 0;
ret = serdev_controller_receive_buf(ctrl, cp, count);
dev_WARN_ONCE(&ctrl->dev, ret > count,
"receive_buf returns %zu (count = %zu)\n",
ret, count);
if (ret > count)
return count;
return ret;
}
static void ttyport_write_wakeup(struct tty_port *port)
{
struct serdev_controller *ctrl = port->client_data;
struct serport *serport = serdev_controller_get_drvdata(ctrl);
struct tty_struct *tty;
tty = tty_port_tty_get(port);
if (!tty)
return;
if (test_and_clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags) &&
test_bit(SERPORT_ACTIVE, &serport->flags))
serdev_controller_write_wakeup(ctrl);
/* Wake up any tty_wait_until_sent() */
wake_up_interruptible(&tty->write_wait);
tty_kref_put(tty);
}
static const struct tty_port_client_operations client_ops = {
.receive_buf = ttyport_receive_buf,
.write_wakeup = ttyport_write_wakeup,
};
/*
* Callback functions from the serdev core.
*/
static ssize_t ttyport_write_buf(struct serdev_controller *ctrl, const u8 *data, size_t len)
{
struct serport *serport = serdev_controller_get_drvdata(ctrl);
struct tty_struct *tty = serport->tty;
if (!test_bit(SERPORT_ACTIVE, &serport->flags))
return 0;
set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
return tty->ops->write(serport->tty, data, len);
}
static void ttyport_write_flush(struct serdev_controller *ctrl)
{
struct serport *serport = serdev_controller_get_drvdata(ctrl);
struct tty_struct *tty = serport->tty;
tty_driver_flush_buffer(tty);
}
static int ttyport_open(struct serdev_controller *ctrl)
{
struct serport *serport = serdev_controller_get_drvdata(ctrl);
struct tty_struct *tty;
struct ktermios ktermios;
int ret;
tty = tty_init_dev(serport->tty_drv, serport->tty_idx);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/serdev.h`, `linux/tty.h`, `linux/tty_driver.h`, `linux/poll.h`.
- Detected declarations: `struct serport`, `function ttyport_receive_buf`, `function ttyport_write_wakeup`, `function ttyport_write_buf`, `function ttyport_write_flush`, `function ttyport_open`, `function ttyport_close`, `function ttyport_set_baudrate`, `function ttyport_set_flow_control`, `function ttyport_set_parity`.
- Atlas domain: Driver Families / drivers/tty.
- Implementation status: source implementation candidate.
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.