drivers/i2c/busses/i2c-axxia.c
Source file repositories/reference/linux-study-clean/drivers/i2c/busses/i2c-axxia.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/busses/i2c-axxia.c- Extension
.c- Size
- 23168 bytes
- Lines
- 824
- Domain
- Driver Families
- Bucket
- drivers/i2c
- 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 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/clk.hlinux/clkdev.hlinux/delay.hlinux/err.hlinux/i2c.hlinux/init.hlinux/interrupt.hlinux/module.hlinux/io.hlinux/kernel.hlinux/platform_device.h
Detected Declarations
struct axxia_i2c_devfunction i2c_int_disablefunction i2c_int_enablefunction ns_to_clkfunction axxia_i2c_initfunction i2c_m_rdfunction i2c_m_recv_lenfunction axxia_i2c_empty_rx_fifofunction axxia_i2c_fill_tx_fifofunction axxia_i2c_slv_fifo_eventfunction axxia_i2c_slv_isrfunction axxia_i2c_isrfunction axxia_i2c_set_addrfunction axxia_i2c_handle_seq_nakfunction axxia_i2c_xfer_seqfunction axxia_i2c_xfer_msgfunction axxia_i2c_sequence_okfunction axxia_i2c_xferfunction axxia_i2c_get_sclfunction axxia_i2c_set_sclfunction axxia_i2c_get_sdafunction axxia_i2c_funcfunction axxia_i2c_reg_slavefunction axxia_i2c_unreg_slavefunction axxia_i2c_probefunction axxia_i2c_remove
Annotated Snippet
struct axxia_i2c_dev {
void __iomem *base;
struct i2c_msg *msg;
struct i2c_msg *msg_r;
size_t msg_xfrd;
size_t msg_xfrd_r;
int msg_err;
struct completion msg_complete;
struct device *dev;
struct i2c_adapter adapter;
struct clk *i2c_clk;
u32 bus_clk_rate;
bool last;
struct i2c_client *slave;
int irq;
};
static void i2c_int_disable(struct axxia_i2c_dev *idev, u32 mask)
{
u32 int_en;
int_en = readl(idev->base + MST_INT_ENABLE);
writel(int_en & ~mask, idev->base + MST_INT_ENABLE);
}
static void i2c_int_enable(struct axxia_i2c_dev *idev, u32 mask)
{
u32 int_en;
int_en = readl(idev->base + MST_INT_ENABLE);
writel(int_en | mask, idev->base + MST_INT_ENABLE);
}
/*
* ns_to_clk - Convert time (ns) to clock cycles for the given clock frequency.
*/
static u32 ns_to_clk(u64 ns, u32 clk_mhz)
{
return div_u64(ns * clk_mhz, 1000);
}
static int axxia_i2c_init(struct axxia_i2c_dev *idev)
{
u32 divisor = clk_get_rate(idev->i2c_clk) / idev->bus_clk_rate;
u32 clk_mhz = clk_get_rate(idev->i2c_clk) / 1000000;
u32 t_setup;
u32 t_high, t_low;
u32 tmo_clk;
u32 prescale;
unsigned long timeout;
dev_dbg(idev->dev, "rate=%uHz per_clk=%uMHz -> ratio=1:%u\n",
idev->bus_clk_rate, clk_mhz, divisor);
/* Reset controller */
writel(0x01, idev->base + SOFT_RESET);
timeout = jiffies + msecs_to_jiffies(100);
while (readl(idev->base + SOFT_RESET) & 1) {
if (time_after(jiffies, timeout)) {
dev_warn(idev->dev, "Soft reset failed\n");
break;
}
}
/* Enable Master Mode */
writel(0x1, idev->base + GLOBAL_CONTROL);
if (idev->bus_clk_rate <= I2C_MAX_STANDARD_MODE_FREQ) {
/* Standard mode SCL 50/50, tSU:DAT = 250 ns */
t_high = divisor * 1 / 2;
t_low = divisor * 1 / 2;
t_setup = ns_to_clk(250, clk_mhz);
} else {
/* Fast mode SCL 33/66, tSU:DAT = 100 ns */
t_high = divisor * 1 / 3;
t_low = divisor * 2 / 3;
t_setup = ns_to_clk(100, clk_mhz);
}
/* SCL High Time */
writel(t_high, idev->base + SCL_HIGH_PERIOD);
/* SCL Low Time */
writel(t_low, idev->base + SCL_LOW_PERIOD);
/* SDA Setup Time */
writel(t_setup, idev->base + SDA_SETUP_TIME);
/* SDA Hold Time, 300ns */
writel(ns_to_clk(300, clk_mhz), idev->base + SDA_HOLD_TIME);
/* Filter <50ns spikes */
writel(ns_to_clk(50, clk_mhz), idev->base + SPIKE_FLTR_LEN);
Annotation
- Immediate include surface: `linux/clk.h`, `linux/clkdev.h`, `linux/delay.h`, `linux/err.h`, `linux/i2c.h`, `linux/init.h`, `linux/interrupt.h`, `linux/module.h`.
- Detected declarations: `struct axxia_i2c_dev`, `function i2c_int_disable`, `function i2c_int_enable`, `function ns_to_clk`, `function axxia_i2c_init`, `function i2c_m_rd`, `function i2c_m_recv_len`, `function axxia_i2c_empty_rx_fifo`, `function axxia_i2c_fill_tx_fifo`, `function axxia_i2c_slv_fifo_event`.
- Atlas domain: Driver Families / drivers/i2c.
- Implementation status: source implementation candidate.
- 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.