drivers/i2c/busses/i2c-emev2.c
Source file repositories/reference/linux-study-clean/drivers/i2c/busses/i2c-emev2.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/busses/i2c-emev2.c- Extension
.c- Size
- 10598 bytes
- Lines
- 441
- 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/completion.hlinux/device.hlinux/i2c.hlinux/init.hlinux/interrupt.hlinux/io.hlinux/kernel.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/sched.h
Detected Declarations
struct em_i2c_devicefunction em_clear_set_bitfunction em_i2c_wait_for_eventfunction em_i2c_stopfunction em_i2c_resetfunction __em_i2c_xferfunction em_i2c_xferfunction em_i2c_slave_irqfunction em_i2c_irq_handlerfunction em_i2c_funcfunction em_i2c_reg_slavefunction em_i2c_unreg_slavefunction em_i2c_probefunction em_i2c_remove
Annotated Snippet
struct em_i2c_device {
void __iomem *base;
struct i2c_adapter adap;
struct completion msg_done;
struct i2c_client *slave;
int irq;
};
static inline void em_clear_set_bit(struct em_i2c_device *priv, u8 clear, u8 set, u8 reg)
{
writeb((readb(priv->base + reg) & ~clear) | set, priv->base + reg);
}
static int em_i2c_wait_for_event(struct em_i2c_device *priv)
{
unsigned long time_left;
int status;
reinit_completion(&priv->msg_done);
time_left = wait_for_completion_timeout(&priv->msg_done, priv->adap.timeout);
if (!time_left)
return -ETIMEDOUT;
status = readb(priv->base + I2C_OFS_IICSE0);
return status & I2C_BIT_ALD0 ? -EAGAIN : status;
}
static void em_i2c_stop(struct em_i2c_device *priv)
{
/* Send Stop condition */
em_clear_set_bit(priv, 0, I2C_BIT_SPT0 | I2C_BIT_SPIE0, I2C_OFS_IICC0);
/* Wait for stop condition */
em_i2c_wait_for_event(priv);
}
static void em_i2c_reset(struct i2c_adapter *adap)
{
struct em_i2c_device *priv = i2c_get_adapdata(adap);
int retr;
/* If I2C active */
if (readb(priv->base + I2C_OFS_IICACT0) & I2C_BIT_IICE0) {
/* Disable I2C operation */
writeb(0, priv->base + I2C_OFS_IICACT0);
retr = 1000;
while (readb(priv->base + I2C_OFS_IICACT0) == 1 && retr)
retr--;
WARN_ON(retr == 0);
}
/* Transfer mode set */
writeb(I2C_BIT_DFC0, priv->base + I2C_OFS_IICCL0);
/* Can Issue start without detecting a stop, Reservation disabled. */
writeb(I2C_BIT_STCEN | I2C_BIT_IICRSV, priv->base + I2C_OFS_IICF0);
/* I2C enable, 9 bit interrupt mode */
writeb(I2C_BIT_WTIM0, priv->base + I2C_OFS_IICC0);
/* Enable I2C operation */
writeb(I2C_BIT_IICE0, priv->base + I2C_OFS_IICACT0);
retr = 1000;
while (readb(priv->base + I2C_OFS_IICACT0) == 0 && retr)
retr--;
WARN_ON(retr == 0);
}
static int __em_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
int stop)
{
struct em_i2c_device *priv = i2c_get_adapdata(adap);
int count, status, read = !!(msg->flags & I2C_M_RD);
/* Send start condition */
em_clear_set_bit(priv, 0, I2C_BIT_ACKE0 | I2C_BIT_WTIM0, I2C_OFS_IICC0);
em_clear_set_bit(priv, 0, I2C_BIT_STT0, I2C_OFS_IICC0);
/* Send slave address and R/W type */
writeb(i2c_8bit_addr_from_msg(msg), priv->base + I2C_OFS_IIC0);
/* Wait for transaction */
status = em_i2c_wait_for_event(priv);
if (status < 0)
goto out_reset;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/completion.h`, `linux/device.h`, `linux/i2c.h`, `linux/init.h`, `linux/interrupt.h`, `linux/io.h`, `linux/kernel.h`.
- Detected declarations: `struct em_i2c_device`, `function em_clear_set_bit`, `function em_i2c_wait_for_event`, `function em_i2c_stop`, `function em_i2c_reset`, `function __em_i2c_xfer`, `function em_i2c_xfer`, `function em_i2c_slave_irq`, `function em_i2c_irq_handler`, `function em_i2c_func`.
- 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.