drivers/staging/greybus/i2c.c
Source file repositories/reference/linux-study-clean/drivers/staging/greybus/i2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/staging/greybus/i2c.c- Extension
.c- Size
- 7814 bytes
- Lines
- 323
- Domain
- Driver Families
- Bucket
- drivers/staging
- 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/kernel.hlinux/module.hlinux/slab.hlinux/i2c.hlinux/greybus.hgbphy.h
Detected Declarations
struct gb_i2c_devicefunction gb_i2c_functionality_mapfunction itfunction gb_i2c_transfer_op_flags_mapfunction gb_i2c_fill_transfer_opfunction gb_i2c_operation_createfunction gb_i2c_decode_responsefunction gb_i2c_expected_transfer_errorfunction gb_i2c_transfer_operationfunction gb_i2c_master_xferfunction gb_i2c_functionalityfunction gb_i2c_probefunction gb_i2c_remove
Annotated Snippet
struct gb_i2c_device {
struct gb_connection *connection;
struct gbphy_device *gbphy_dev;
u32 functionality;
struct i2c_adapter adapter;
};
/*
* Map Greybus i2c functionality bits into Linux ones
*/
static u32 gb_i2c_functionality_map(u32 gb_i2c_functionality)
{
return gb_i2c_functionality; /* All bits the same for now */
}
/*
* Do initial setup of the i2c device. This includes verifying we
* can support it (based on the protocol version it advertises).
* If that's OK, we get and cached its functionality bits.
*
* Note: gb_i2c_dev->connection is assumed to have been valid.
*/
static int gb_i2c_device_setup(struct gb_i2c_device *gb_i2c_dev)
{
struct gb_i2c_functionality_response response;
u32 functionality;
int ret;
ret = gb_operation_sync(gb_i2c_dev->connection,
GB_I2C_TYPE_FUNCTIONALITY,
NULL, 0, &response, sizeof(response));
if (ret)
return ret;
functionality = le32_to_cpu(response.functionality);
gb_i2c_dev->functionality = gb_i2c_functionality_map(functionality);
return 0;
}
/*
* Map Linux i2c_msg flags into Greybus i2c transfer op flags.
*/
static u16 gb_i2c_transfer_op_flags_map(u16 flags)
{
return flags; /* All flags the same for now */
}
static void
gb_i2c_fill_transfer_op(struct gb_i2c_transfer_op *op, struct i2c_msg *msg)
{
u16 flags = gb_i2c_transfer_op_flags_map(msg->flags);
op->addr = cpu_to_le16(msg->addr);
op->flags = cpu_to_le16(flags);
op->size = cpu_to_le16(msg->len);
}
static struct gb_operation *
gb_i2c_operation_create(struct gb_connection *connection,
struct i2c_msg *msgs, u32 msg_count)
{
struct gb_i2c_device *gb_i2c_dev = gb_connection_get_data(connection);
struct gb_i2c_transfer_request *request;
struct gb_operation *operation;
struct gb_i2c_transfer_op *op;
struct i2c_msg *msg;
u32 data_out_size = 0;
u32 data_in_size = 0;
size_t request_size;
void *data;
u16 op_count;
u32 i;
if (msg_count > (u32)U16_MAX) {
dev_err(&gb_i2c_dev->gbphy_dev->dev, "msg_count (%u) too big\n",
msg_count);
return NULL;
}
op_count = (u16)msg_count;
/*
* In addition to space for all message descriptors we need
* to have enough to hold all outbound message data.
*/
msg = msgs;
for (i = 0; i < msg_count; i++, msg++)
if (msg->flags & I2C_M_RD)
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/slab.h`, `linux/i2c.h`, `linux/greybus.h`, `gbphy.h`.
- Detected declarations: `struct gb_i2c_device`, `function gb_i2c_functionality_map`, `function it`, `function gb_i2c_transfer_op_flags_map`, `function gb_i2c_fill_transfer_op`, `function gb_i2c_operation_create`, `function gb_i2c_decode_response`, `function gb_i2c_expected_transfer_error`, `function gb_i2c_transfer_operation`, `function gb_i2c_master_xfer`.
- Atlas domain: Driver Families / drivers/staging.
- 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.