drivers/i2c/busses/i2c-sprd.c
Source file repositories/reference/linux-study-clean/drivers/i2c/busses/i2c-sprd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/busses/i2c-sprd.c- Extension
.c- Size
- 16370 bytes
- Lines
- 655
- 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/delay.hlinux/err.hlinux/io.hlinux/i2c.hlinux/init.hlinux/interrupt.hlinux/kernel.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/pm_runtime.h
Detected Declarations
struct sprd_i2cfunction sprd_i2c_set_countfunction sprd_i2c_send_stopfunction sprd_i2c_clear_startfunction sprd_i2c_clear_ackfunction sprd_i2c_clear_irqfunction sprd_i2c_reset_fifofunction sprd_i2c_set_devaddrfunction sprd_i2c_write_bytesfunction sprd_i2c_read_bytesfunction sprd_i2c_set_full_thldfunction sprd_i2c_set_empty_thldfunction sprd_i2c_set_fifo_full_intfunction sprd_i2c_set_fifo_empty_intfunction sprd_i2c_opt_startfunction sprd_i2c_opt_modefunction sprd_i2c_data_transferfunction sprd_i2c_handle_msgfunction sprd_i2c_xferfunction sprd_i2c_funcfunction sprd_i2c_set_clkfunction sprd_i2c_enablefunction sprd_i2c_isr_threadfunction transmissionfunction sprd_i2c_isrfunction sprd_i2c_clk_initfunction sprd_i2c_probefunction sprd_i2c_removefunction sprd_i2c_suspend_noirqfunction sprd_i2c_resume_noirqfunction sprd_i2c_runtime_suspendfunction sprd_i2c_runtime_resume
Annotated Snippet
struct sprd_i2c {
struct i2c_adapter adap;
struct device *dev;
void __iomem *base;
struct i2c_msg *msg;
struct clk *clk;
u32 src_clk;
u32 bus_freq;
struct completion complete;
u8 *buf;
u32 count;
int irq;
int err;
};
static void sprd_i2c_set_count(struct sprd_i2c *i2c_dev, u32 count)
{
writel(count, i2c_dev->base + I2C_COUNT);
}
static void sprd_i2c_send_stop(struct sprd_i2c *i2c_dev, int stop)
{
u32 tmp = readl(i2c_dev->base + I2C_CTL);
if (stop)
writel(tmp & ~STP_EN, i2c_dev->base + I2C_CTL);
else
writel(tmp | STP_EN, i2c_dev->base + I2C_CTL);
}
static void sprd_i2c_clear_start(struct sprd_i2c *i2c_dev)
{
u32 tmp = readl(i2c_dev->base + I2C_CTL);
writel(tmp & ~I2C_START, i2c_dev->base + I2C_CTL);
}
static void sprd_i2c_clear_ack(struct sprd_i2c *i2c_dev)
{
u32 tmp = readl(i2c_dev->base + I2C_STATUS);
writel(tmp & ~I2C_RX_ACK, i2c_dev->base + I2C_STATUS);
}
static void sprd_i2c_clear_irq(struct sprd_i2c *i2c_dev)
{
u32 tmp = readl(i2c_dev->base + I2C_STATUS);
writel(tmp & ~I2C_INT, i2c_dev->base + I2C_STATUS);
}
static void sprd_i2c_reset_fifo(struct sprd_i2c *i2c_dev)
{
writel(I2C_RST, i2c_dev->base + ADDR_RST);
}
static void sprd_i2c_set_devaddr(struct sprd_i2c *i2c_dev, struct i2c_msg *m)
{
writel(m->addr << 1, i2c_dev->base + I2C_ADDR_CFG);
}
static void sprd_i2c_write_bytes(struct sprd_i2c *i2c_dev, u8 *buf, u32 len)
{
u32 i;
for (i = 0; i < len; i++)
writeb(buf[i], i2c_dev->base + I2C_TX);
}
static void sprd_i2c_read_bytes(struct sprd_i2c *i2c_dev, u8 *buf, u32 len)
{
u32 i;
for (i = 0; i < len; i++)
buf[i] = readb(i2c_dev->base + I2C_RX);
}
static void sprd_i2c_set_full_thld(struct sprd_i2c *i2c_dev, u32 full_thld)
{
u32 tmp = readl(i2c_dev->base + I2C_CTL);
tmp &= ~FIFO_AF_LVL_MASK;
tmp |= full_thld << FIFO_AF_LVL;
writel(tmp, i2c_dev->base + I2C_CTL);
};
static void sprd_i2c_set_empty_thld(struct sprd_i2c *i2c_dev, u32 empty_thld)
{
u32 tmp = readl(i2c_dev->base + I2C_CTL);
Annotation
- Immediate include surface: `linux/clk.h`, `linux/delay.h`, `linux/err.h`, `linux/io.h`, `linux/i2c.h`, `linux/init.h`, `linux/interrupt.h`, `linux/kernel.h`.
- Detected declarations: `struct sprd_i2c`, `function sprd_i2c_set_count`, `function sprd_i2c_send_stop`, `function sprd_i2c_clear_start`, `function sprd_i2c_clear_ack`, `function sprd_i2c_clear_irq`, `function sprd_i2c_reset_fifo`, `function sprd_i2c_set_devaddr`, `function sprd_i2c_write_bytes`, `function sprd_i2c_read_bytes`.
- 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.