drivers/tty/serial/8250/8250_mtk.c
Source file repositories/reference/linux-study-clean/drivers/tty/serial/8250/8250_mtk.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/tty/serial/8250/8250_mtk.c- Extension
.c- Size
- 18626 bytes
- Lines
- 682
- 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.
- 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/clk.hlinux/io.hlinux/module.hlinux/of_irq.hlinux/of_platform.hlinux/pinctrl/consumer.hlinux/platform_device.hlinux/pm_runtime.hlinux/serial_8250.hlinux/serial_reg.hlinux/console.hlinux/dma-mapping.hlinux/tty.hlinux/tty_flip.h8250.h
Detected Declarations
struct mtk8250_dataenum dma_rx_statusfunction mtk8250_dma_rx_completefunction mtk8250_rx_dmafunction mtk8250_dma_enablefunction mtk8250_startupfunction mtk8250_shutdownfunction mtk8250_disable_intrsfunction mtk8250_enable_intrsfunction mtk8250_set_flow_ctrlfunction mtk8250_set_termiosfunction mtk8250_runtime_suspendfunction mtk8250_runtime_resumefunction mtk8250_do_pmfunction mtk8250_dma_filterfunction mtk8250_probe_offunction mtk8250_probefunction mtk8250_removefunction mtk8250_suspendfunction mtk8250_resumefunction early_mtk8250_setup
Annotated Snippet
struct mtk8250_data {
int line;
unsigned int rx_pos;
unsigned int clk_count;
struct clk *uart_clk;
struct clk *bus_clk;
struct uart_8250_dma *dma;
#ifdef CONFIG_SERIAL_8250_DMA
enum dma_rx_status rx_status;
#endif
int rx_wakeup_irq;
};
/* flow control mode */
enum {
MTK_UART_FC_NONE,
MTK_UART_FC_SW,
MTK_UART_FC_HW,
};
#ifdef CONFIG_SERIAL_8250_DMA
static void mtk8250_rx_dma(struct uart_8250_port *up);
static void mtk8250_dma_rx_complete(void *param)
{
struct uart_8250_port *up = param;
struct uart_8250_dma *dma = up->dma;
struct mtk8250_data *data = up->port.private_data;
struct tty_port *tty_port = &up->port.state->port;
struct dma_tx_state state;
int copied, total, cnt;
unsigned char *ptr;
unsigned long flags;
if (data->rx_status == DMA_RX_SHUTDOWN)
return;
uart_port_lock_irqsave(&up->port, &flags);
dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state);
total = dma->rx_size - state.residue;
cnt = total;
if ((data->rx_pos + cnt) > dma->rx_size)
cnt = dma->rx_size - data->rx_pos;
ptr = (unsigned char *)(data->rx_pos + dma->rx_buf);
copied = tty_insert_flip_string(tty_port, ptr, cnt);
data->rx_pos += cnt;
if (total > cnt) {
ptr = (unsigned char *)(dma->rx_buf);
cnt = total - cnt;
copied += tty_insert_flip_string(tty_port, ptr, cnt);
data->rx_pos = cnt;
}
up->port.icount.rx += copied;
tty_flip_buffer_push(tty_port);
mtk8250_rx_dma(up);
uart_port_unlock_irqrestore(&up->port, flags);
}
static void mtk8250_rx_dma(struct uart_8250_port *up)
{
struct uart_8250_dma *dma = up->dma;
struct dma_async_tx_descriptor *desc;
desc = dmaengine_prep_slave_single(dma->rxchan, dma->rx_addr,
dma->rx_size, DMA_DEV_TO_MEM,
DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
if (!desc) {
pr_err("failed to prepare rx slave single\n");
return;
}
desc->callback = mtk8250_dma_rx_complete;
desc->callback_param = up;
dma->rx_cookie = dmaengine_submit(desc);
dma_async_issue_pending(dma->rxchan);
}
static void mtk8250_dma_enable(struct uart_8250_port *up)
{
struct uart_8250_dma *dma = up->dma;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/io.h`, `linux/module.h`, `linux/of_irq.h`, `linux/of_platform.h`, `linux/pinctrl/consumer.h`, `linux/platform_device.h`, `linux/pm_runtime.h`.
- Detected declarations: `struct mtk8250_data`, `enum dma_rx_status`, `function mtk8250_dma_rx_complete`, `function mtk8250_rx_dma`, `function mtk8250_dma_enable`, `function mtk8250_startup`, `function mtk8250_shutdown`, `function mtk8250_disable_intrs`, `function mtk8250_enable_intrs`, `function mtk8250_set_flow_ctrl`.
- Atlas domain: Driver Families / drivers/tty.
- Implementation status: source implementation candidate.
- 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.