drivers/i2c/busses/i2c-jz4780.c
Source file repositories/reference/linux-study-clean/drivers/i2c/busses/i2c-jz4780.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/busses/i2c-jz4780.c- Extension
.c- Size
- 21613 bytes
- Lines
- 862
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/bitops.hlinux/clk.hlinux/completion.hlinux/delay.hlinux/errno.hlinux/i2c.hlinux/init.hlinux/interrupt.hlinux/io.hlinux/kernel.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/sched.hlinux/slab.hlinux/time.h
Detected Declarations
struct ingenic_i2c_configstruct jz4780_i2cenum ingenic_i2c_versionfunction jz4780_i2c_readwfunction jz4780_i2c_writewfunction jz4780_i2c_disablefunction jz4780_i2c_enablefunction jz4780_i2c_set_targetfunction jz4780_i2c_set_speedfunction Piscesfunction jz4780_i2c_cleanupfunction jz4780_i2c_preparefunction jz4780_i2c_send_rcmdfunction jz4780_i2c_trans_donefunction jz4780_i2c_irqfunction jz4780_i2c_txabrtfunction jz4780_i2c_xfer_readfunction jz4780_i2c_xfer_writefunction jz4780_i2c_xferfunction jz4780_i2c_functionalityfunction jz4780_i2c_probefunction jz4780_i2c_remove
Annotated Snippet
struct ingenic_i2c_config {
enum ingenic_i2c_version version;
int fifosize;
int tx_level;
int rx_level;
};
struct jz4780_i2c {
void __iomem *iomem;
int irq;
struct clk *clk;
struct i2c_adapter adap;
const struct ingenic_i2c_config *cdata;
/* lock to protect rbuf and wbuf between xfer_rd/wr and irq handler */
spinlock_t lock;
/* beginning of lock scope */
unsigned char *rbuf;
int rd_total_len;
int rd_data_xfered;
int rd_cmd_xfered;
unsigned char *wbuf;
int wt_len;
int is_write;
int stop_hold;
int speed;
int data_buf[BUFSIZE];
int cmd_buf[BUFSIZE];
int cmd;
/* end of lock scope */
struct completion trans_waitq;
};
static inline unsigned short jz4780_i2c_readw(struct jz4780_i2c *i2c,
unsigned long offset)
{
return readw(i2c->iomem + offset);
}
static inline void jz4780_i2c_writew(struct jz4780_i2c *i2c,
unsigned long offset, unsigned short val)
{
writew(val, i2c->iomem + offset);
}
static int jz4780_i2c_disable(struct jz4780_i2c *i2c)
{
unsigned short regval;
unsigned long loops = 5;
jz4780_i2c_writew(i2c, JZ4780_I2C_ENB, 0);
do {
regval = jz4780_i2c_readw(i2c, JZ4780_I2C_ENSTA);
if (!(regval & JZ4780_I2C_ENB_I2C))
return 0;
usleep_range(5000, 15000);
} while (--loops);
dev_err(&i2c->adap.dev, "disable failed: ENSTA=0x%04x\n", regval);
return -ETIMEDOUT;
}
static int jz4780_i2c_enable(struct jz4780_i2c *i2c)
{
unsigned short regval;
unsigned long loops = 5;
jz4780_i2c_writew(i2c, JZ4780_I2C_ENB, 1);
do {
regval = jz4780_i2c_readw(i2c, JZ4780_I2C_ENSTA);
if (regval & JZ4780_I2C_ENB_I2C)
return 0;
usleep_range(5000, 15000);
} while (--loops);
dev_err(&i2c->adap.dev, "enable failed: ENSTA=0x%04x\n", regval);
return -ETIMEDOUT;
}
static int jz4780_i2c_set_target(struct jz4780_i2c *i2c, unsigned char address)
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/clk.h`, `linux/completion.h`, `linux/delay.h`, `linux/errno.h`, `linux/i2c.h`, `linux/init.h`, `linux/interrupt.h`.
- Detected declarations: `struct ingenic_i2c_config`, `struct jz4780_i2c`, `enum ingenic_i2c_version`, `function jz4780_i2c_readw`, `function jz4780_i2c_writew`, `function jz4780_i2c_disable`, `function jz4780_i2c_enable`, `function jz4780_i2c_set_target`, `function jz4780_i2c_set_speed`, `function Pisces`.
- Atlas domain: Driver Families / drivers/i2c.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- 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.