drivers/i2c/busses/i2c-cros-ec-tunnel.c
Source file repositories/reference/linux-study-clean/drivers/i2c/busses/i2c-cros-ec-tunnel.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/busses/i2c-cros-ec-tunnel.c- Extension
.c- Size
- 8144 bytes
- Lines
- 323
- 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/module.hlinux/i2c.hlinux/platform_data/cros_ec_commands.hlinux/platform_data/cros_ec_proto.hlinux/platform_device.hlinux/slab.h
Detected Declarations
struct ec_i2c_devicefunction ec_i2c_count_messagefunction ec_i2c_construct_messagefunction ec_i2c_count_responsefunction ec_i2c_parse_responsefunction ec_i2c_xferfunction ec_i2c_functionalityfunction ec_i2c_probefunction ec_i2c_remove
Annotated Snippet
struct ec_i2c_device {
struct device *dev;
struct i2c_adapter adap;
struct cros_ec_device *ec;
u16 remote_bus;
u8 request_buf[256];
u8 response_buf[256];
};
/**
* ec_i2c_count_message - Count bytes needed for ec_i2c_construct_message
*
* @i2c_msgs: The i2c messages to read
* @num: The number of i2c messages.
*
* Returns the number of bytes the messages will take up.
*/
static int ec_i2c_count_message(const struct i2c_msg i2c_msgs[], int num)
{
int i;
int size;
size = sizeof(struct ec_params_i2c_passthru);
size += num * sizeof(struct ec_params_i2c_passthru_msg);
for (i = 0; i < num; i++)
if (!(i2c_msgs[i].flags & I2C_M_RD))
size += i2c_msgs[i].len;
return size;
}
/**
* ec_i2c_construct_message - construct a message to go to the EC
*
* This function effectively stuffs the standard i2c_msg format of Linux into
* a format that the EC understands.
*
* @buf: The buffer to fill. We assume that the buffer is big enough.
* @i2c_msgs: The i2c messages to read.
* @num: The number of i2c messages.
* @bus_num: The remote bus number we want to talk to.
*
* Returns 0 or a negative error number.
*/
static int ec_i2c_construct_message(u8 *buf, const struct i2c_msg i2c_msgs[],
int num, u16 bus_num)
{
struct ec_params_i2c_passthru *params;
u8 *out_data;
int i;
out_data = buf + sizeof(struct ec_params_i2c_passthru) +
num * sizeof(struct ec_params_i2c_passthru_msg);
params = (struct ec_params_i2c_passthru *)buf;
params->port = bus_num;
params->num_msgs = num;
for (i = 0; i < num; i++) {
const struct i2c_msg *i2c_msg = &i2c_msgs[i];
struct ec_params_i2c_passthru_msg *msg = ¶ms->msg[i];
msg->len = i2c_msg->len;
msg->addr_flags = i2c_msg->addr;
if (i2c_msg->flags & I2C_M_TEN)
return -EINVAL;
if (i2c_msg->flags & I2C_M_RD) {
msg->addr_flags |= EC_I2C_FLAG_READ;
} else {
memcpy(out_data, i2c_msg->buf, msg->len);
out_data += msg->len;
}
}
return 0;
}
/**
* ec_i2c_count_response - Count bytes needed for ec_i2c_parse_response
*
* @i2c_msgs: The i2c messages to fill up.
* @num: The number of i2c messages expected.
*
* Returns the number of response bytes expeced.
*/
static int ec_i2c_count_response(struct i2c_msg i2c_msgs[], int num)
{
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/module.h`, `linux/i2c.h`, `linux/platform_data/cros_ec_commands.h`, `linux/platform_data/cros_ec_proto.h`, `linux/platform_device.h`, `linux/slab.h`.
- Detected declarations: `struct ec_i2c_device`, `function ec_i2c_count_message`, `function ec_i2c_construct_message`, `function ec_i2c_count_response`, `function ec_i2c_parse_response`, `function ec_i2c_xfer`, `function ec_i2c_functionality`, `function ec_i2c_probe`, `function ec_i2c_remove`.
- 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.