drivers/i2c/busses/i2c-gxp.c
Source file repositories/reference/linux-study-clean/drivers/i2c/busses/i2c-gxp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/busses/i2c-gxp.c- Extension
.c- Size
- 15593 bytes
- Lines
- 609
- 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/err.hlinux/io.hlinux/i2c.hlinux/mod_devicetable.hlinux/module.hlinux/platform_device.hlinux/regmap.hlinux/mfd/syscon.h
Detected Declarations
struct gxp_i2c_drvdatafunction gxp_i2c_startfunction gxp_i2c_master_xferfunction gxp_i2c_funcfunction gxp_i2c_reg_slavefunction gxp_i2c_unreg_slavefunction gxp_i2c_stopfunction gxp_i2c_restartfunction gxp_i2c_chk_addr_ackfunction gxp_i2c_ack_datafunction gxp_i2c_chk_data_ackfunction gxp_i2c_slave_irq_handlerfunction gxp_i2c_irq_handlerfunction gxp_i2c_initfunction gxp_i2c_probefunction gxp_i2c_remove
Annotated Snippet
struct gxp_i2c_drvdata {
struct device *dev;
void __iomem *base;
struct i2c_timings t;
u32 engine;
int irq;
struct completion completion;
struct i2c_adapter adapter;
struct i2c_msg *curr_msg;
int msgs_remaining;
int msgs_num;
u8 *buf;
size_t buf_remaining;
unsigned char state;
struct i2c_client *slave;
unsigned char stopped;
};
static struct regmap *i2cg_map;
static void gxp_i2c_start(struct gxp_i2c_drvdata *drvdata)
{
u16 value;
drvdata->buf = drvdata->curr_msg->buf;
drvdata->buf_remaining = drvdata->curr_msg->len;
/* Note: Address in struct i2c_msg is 7 bits */
value = drvdata->curr_msg->addr << 9;
/* Read or Write */
value |= drvdata->curr_msg->flags & I2C_M_RD ? RW_CMD | START_CMD : START_CMD;
drvdata->state = GXP_I2C_ADDR_PHASE;
writew(value, drvdata->base + GXP_I2CMCMD);
}
static int gxp_i2c_master_xfer(struct i2c_adapter *adapter,
struct i2c_msg *msgs, int num)
{
int ret;
struct gxp_i2c_drvdata *drvdata = i2c_get_adapdata(adapter);
unsigned long time_left;
drvdata->msgs_remaining = num;
drvdata->curr_msg = msgs;
drvdata->msgs_num = num;
reinit_completion(&drvdata->completion);
gxp_i2c_start(drvdata);
time_left = wait_for_completion_timeout(&drvdata->completion,
adapter->timeout);
ret = num - drvdata->msgs_remaining;
if (time_left == 0)
return -ETIMEDOUT;
if (drvdata->state == GXP_I2C_ADDR_NACK)
return -ENXIO;
if (drvdata->state == GXP_I2C_DATA_NACK)
return -EIO;
return ret;
}
static u32 gxp_i2c_func(struct i2c_adapter *adap)
{
if (IS_ENABLED(CONFIG_I2C_SLAVE))
return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_SLAVE;
return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
}
#if IS_ENABLED(CONFIG_I2C_SLAVE)
static int gxp_i2c_reg_slave(struct i2c_client *slave)
{
struct gxp_i2c_drvdata *drvdata = i2c_get_adapdata(slave->adapter);
if (drvdata->slave)
return -EBUSY;
if (slave->flags & I2C_CLIENT_TEN)
return -EAFNOSUPPORT;
drvdata->slave = slave;
writeb(slave->addr << 1, drvdata->base + GXP_I2COWNADR);
writeb(SLAVE_EVT_CLR | SNOOP_EVT_MASK | SLAVE_ACK_ENAB |
SLAVE_EVT_STALL, drvdata->base + GXP_I2CSCMD);
Annotation
- Immediate include surface: `linux/err.h`, `linux/io.h`, `linux/i2c.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/platform_device.h`, `linux/regmap.h`, `linux/mfd/syscon.h`.
- Detected declarations: `struct gxp_i2c_drvdata`, `function gxp_i2c_start`, `function gxp_i2c_master_xfer`, `function gxp_i2c_func`, `function gxp_i2c_reg_slave`, `function gxp_i2c_unreg_slave`, `function gxp_i2c_stop`, `function gxp_i2c_restart`, `function gxp_i2c_chk_addr_ack`, `function gxp_i2c_ack_data`.
- 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.