drivers/i2c/busses/i2c-hisi.c
Source file repositories/reference/linux-study-clean/drivers/i2c/busses/i2c-hisi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/busses/i2c-hisi.c- Extension
.c- Size
- 15797 bytes
- Lines
- 544
- 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/bits.hlinux/bitfield.hlinux/clk.hlinux/completion.hlinux/i2c.hlinux/interrupt.hlinux/io.hlinux/module.hlinux/mod_devicetable.hlinux/platform_device.hlinux/property.hlinux/units.h
Detected Declarations
struct hisi_i2c_controllerfunction hisi_i2c_enable_intfunction hisi_i2c_disable_intfunction hisi_i2c_clear_intfunction hisi_i2c_clear_tx_intfunction hisi_i2c_handle_errorsfunction hisi_i2c_start_xferfunction hisi_i2c_reset_xferfunction hisi_i2c_xferfunction hisi_i2c_functionalityfunction hisi_i2c_read_rx_fifofunction hisi_i2c_xfer_msgfunction hisi_i2c_irqfunction countsfunction hisi_i2c_configure_busfunction hisi_i2c_probe
Annotated Snippet
struct hisi_i2c_controller {
struct i2c_adapter adapter;
void __iomem *iobase;
struct device *dev;
struct clk *clk;
int irq;
/* Intermediates for recording the transfer process */
struct completion *completion;
struct i2c_msg *msgs;
int msg_num;
int msg_tx_idx;
int buf_tx_idx;
int msg_rx_idx;
int buf_rx_idx;
u16 tar_addr;
u32 xfer_err;
/* I2C bus configuration */
struct i2c_timings t;
u32 clk_rate_khz;
u32 spk_len;
};
static void hisi_i2c_enable_int(struct hisi_i2c_controller *ctlr, u32 mask)
{
writel_relaxed(mask, ctlr->iobase + HISI_I2C_INT_MASK);
}
static void hisi_i2c_disable_int(struct hisi_i2c_controller *ctlr, u32 mask)
{
writel_relaxed((~mask) & HISI_I2C_INT_ALL, ctlr->iobase + HISI_I2C_INT_MASK);
}
static void hisi_i2c_clear_int(struct hisi_i2c_controller *ctlr, u32 mask)
{
writel_relaxed(mask, ctlr->iobase + HISI_I2C_INT_CLR);
}
static void hisi_i2c_clear_tx_int(struct hisi_i2c_controller *ctlr, u32 mask)
{
writel_relaxed(mask, ctlr->iobase + HISI_I2C_TX_INT_CLR);
}
static void hisi_i2c_handle_errors(struct hisi_i2c_controller *ctlr)
{
u32 int_err = ctlr->xfer_err, reg;
if (int_err & HISI_I2C_INT_FIFO_ERR) {
reg = readl(ctlr->iobase + HISI_I2C_FIFO_STATE);
if (reg & HISI_I2C_FIFO_STATE_RX_RERR)
dev_err(ctlr->dev, "rx fifo error read\n");
if (reg & HISI_I2C_FIFO_STATE_RX_WERR)
dev_err(ctlr->dev, "rx fifo error write\n");
if (reg & HISI_I2C_FIFO_STATE_TX_RERR)
dev_err(ctlr->dev, "tx fifo error read\n");
if (reg & HISI_I2C_FIFO_STATE_TX_WERR)
dev_err(ctlr->dev, "tx fifo error write\n");
}
}
static int hisi_i2c_start_xfer(struct hisi_i2c_controller *ctlr)
{
struct i2c_msg *msg = ctlr->msgs;
u32 reg;
reg = readl(ctlr->iobase + HISI_I2C_FRAME_CTRL);
reg &= ~HISI_I2C_FRAME_CTRL_ADDR_TEN;
if (msg->flags & I2C_M_TEN)
reg |= HISI_I2C_FRAME_CTRL_ADDR_TEN;
writel(reg, ctlr->iobase + HISI_I2C_FRAME_CTRL);
reg = readl(ctlr->iobase + HISI_I2C_SLV_ADDR);
reg &= ~HISI_I2C_SLV_ADDR_VAL;
reg |= FIELD_PREP(HISI_I2C_SLV_ADDR_VAL, msg->addr);
writel(reg, ctlr->iobase + HISI_I2C_SLV_ADDR);
reg = readl(ctlr->iobase + HISI_I2C_FIFO_CTRL);
reg |= HISI_I2C_FIFO_RX_CLR | HISI_I2C_FIFO_TX_CLR;
writel(reg, ctlr->iobase + HISI_I2C_FIFO_CTRL);
reg &= ~(HISI_I2C_FIFO_RX_CLR | HISI_I2C_FIFO_TX_CLR);
writel(reg, ctlr->iobase + HISI_I2C_FIFO_CTRL);
hisi_i2c_clear_int(ctlr, HISI_I2C_INT_ALL);
hisi_i2c_clear_tx_int(ctlr, HISI_I2C_TX_AEMPTY_INT);
hisi_i2c_enable_int(ctlr, HISI_I2C_INT_ALL);
Annotation
- Immediate include surface: `linux/bits.h`, `linux/bitfield.h`, `linux/clk.h`, `linux/completion.h`, `linux/i2c.h`, `linux/interrupt.h`, `linux/io.h`, `linux/module.h`.
- Detected declarations: `struct hisi_i2c_controller`, `function hisi_i2c_enable_int`, `function hisi_i2c_disable_int`, `function hisi_i2c_clear_int`, `function hisi_i2c_clear_tx_int`, `function hisi_i2c_handle_errors`, `function hisi_i2c_start_xfer`, `function hisi_i2c_reset_xfer`, `function hisi_i2c_xfer`, `function hisi_i2c_functionality`.
- 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.