drivers/i2c/busses/i2c-ljca.c
Source file repositories/reference/linux-study-clean/drivers/i2c/busses/i2c-ljca.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/busses/i2c-ljca.c- Extension
.c- Size
- 9166 bytes
- Lines
- 344
- 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.
- 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/acpi.hlinux/auxiliary_bus.hlinux/bitfield.hlinux/bits.hlinux/dev_printk.hlinux/i2c.hlinux/module.hlinux/usb/ljca.h
Detected Declarations
struct ljca_i2c_rw_packetstruct ljca_i2c_devenum ljca_i2c_cmdenum ljca_xfer_typefunction ljca_i2c_initfunction ljca_i2c_startfunction ljca_i2c_stopfunction ljca_i2c_pure_readfunction ljca_i2c_readfunction ljca_i2c_pure_writefunction ljca_i2c_writefunction ljca_i2c_xferfunction ljca_i2c_funcfunction ljca_i2c_probefunction ljca_i2c_remove
Annotated Snippet
struct ljca_i2c_rw_packet {
u8 id;
__le16 len;
u8 data[] __counted_by(len);
} __packed;
struct ljca_i2c_dev {
struct ljca_client *ljca;
struct ljca_i2c_info *i2c_info;
struct i2c_adapter adap;
u8 obuf[LJCA_I2C_BUF_SIZE];
u8 ibuf[LJCA_I2C_BUF_SIZE];
};
static int ljca_i2c_init(struct ljca_i2c_dev *ljca_i2c, u8 id)
{
struct ljca_i2c_rw_packet *w_packet =
(struct ljca_i2c_rw_packet *)ljca_i2c->obuf;
int ret;
w_packet->id = id;
w_packet->len = cpu_to_le16(sizeof(*w_packet->data));
w_packet->data[0] = LJCA_I2C_INIT_FLAG_FREQ_400K;
ret = ljca_transfer(ljca_i2c->ljca, LJCA_I2C_INIT, (u8 *)w_packet,
struct_size(w_packet, data, 1), NULL, 0);
return ret < 0 ? ret : 0;
}
static int ljca_i2c_start(struct ljca_i2c_dev *ljca_i2c, u8 target_addr,
enum ljca_xfer_type type)
{
struct ljca_i2c_rw_packet *w_packet =
(struct ljca_i2c_rw_packet *)ljca_i2c->obuf;
struct ljca_i2c_rw_packet *r_packet =
(struct ljca_i2c_rw_packet *)ljca_i2c->ibuf;
s16 rp_len;
int ret;
w_packet->id = ljca_i2c->i2c_info->id;
w_packet->len = cpu_to_le16(sizeof(*w_packet->data));
w_packet->data[0] = (target_addr << 1) | type;
ret = ljca_transfer(ljca_i2c->ljca, LJCA_I2C_START, (u8 *)w_packet,
struct_size(w_packet, data, 1), (u8 *)r_packet,
LJCA_I2C_BUF_SIZE);
if (ret < 0 || ret < sizeof(*r_packet))
return ret < 0 ? ret : -EIO;
rp_len = le16_to_cpu(r_packet->len);
if (rp_len < 0 || r_packet->id != w_packet->id) {
dev_dbg(&ljca_i2c->adap.dev,
"i2c start failed len: %d id: %d %d\n",
rp_len, r_packet->id, w_packet->id);
return -EIO;
}
return 0;
}
static void ljca_i2c_stop(struct ljca_i2c_dev *ljca_i2c)
{
struct ljca_i2c_rw_packet *w_packet =
(struct ljca_i2c_rw_packet *)ljca_i2c->obuf;
struct ljca_i2c_rw_packet *r_packet =
(struct ljca_i2c_rw_packet *)ljca_i2c->ibuf;
s16 rp_len;
int ret;
w_packet->id = ljca_i2c->i2c_info->id;
w_packet->len = cpu_to_le16(sizeof(*w_packet->data));
w_packet->data[0] = 0;
ret = ljca_transfer(ljca_i2c->ljca, LJCA_I2C_STOP, (u8 *)w_packet,
struct_size(w_packet, data, 1), (u8 *)r_packet,
LJCA_I2C_BUF_SIZE);
if (ret < 0 || ret < sizeof(*r_packet)) {
dev_dbg(&ljca_i2c->adap.dev,
"i2c stop failed ret: %d id: %d\n",
ret, w_packet->id);
return;
}
rp_len = le16_to_cpu(r_packet->len);
if (rp_len < 0 || r_packet->id != w_packet->id)
dev_dbg(&ljca_i2c->adap.dev,
"i2c stop failed len: %d id: %d %d\n",
rp_len, r_packet->id, w_packet->id);
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/auxiliary_bus.h`, `linux/bitfield.h`, `linux/bits.h`, `linux/dev_printk.h`, `linux/i2c.h`, `linux/module.h`, `linux/usb/ljca.h`.
- Detected declarations: `struct ljca_i2c_rw_packet`, `struct ljca_i2c_dev`, `enum ljca_i2c_cmd`, `enum ljca_xfer_type`, `function ljca_i2c_init`, `function ljca_i2c_start`, `function ljca_i2c_stop`, `function ljca_i2c_pure_read`, `function ljca_i2c_read`, `function ljca_i2c_pure_write`.
- Atlas domain: Driver Families / drivers/i2c.
- Implementation status: source implementation candidate.
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.