drivers/hwmon/occ/p8_i2c.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/occ/p8_i2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/occ/p8_i2c.c- Extension
.c- Size
- 5810 bytes
- Lines
- 257
- Domain
- Driver Families
- Bucket
- drivers/hwmon
- 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/device.hlinux/errno.hlinux/fsi-occ.hlinux/i2c.hlinux/jiffies.hlinux/module.hlinux/sched.hlinux/unaligned.hcommon.h
Detected Declarations
struct p8_i2c_occfunction p8_i2c_occ_getscomfunction p8_i2c_occ_putscomfunction p8_i2c_occ_putscom_u32function p8_i2c_occ_putscom_befunction p8_i2c_occ_send_cmdfunction p8_i2c_occ_probefunction p8_i2c_occ_remove
Annotated Snippet
struct p8_i2c_occ {
struct occ occ;
struct i2c_client *client;
};
#define to_p8_i2c_occ(x) container_of((x), struct p8_i2c_occ, occ)
static int p8_i2c_occ_getscom(struct i2c_client *client, u32 address, u8 *data)
{
ssize_t rc;
__be64 buf;
struct i2c_msg msgs[2];
/* p8 i2c slave requires shift */
address <<= 1;
msgs[0].addr = client->addr;
msgs[0].flags = client->flags & I2C_M_TEN;
msgs[0].len = sizeof(u32);
/* address is a scom address; bus-endian */
msgs[0].buf = (char *)&address;
/* data from OCC is big-endian */
msgs[1].addr = client->addr;
msgs[1].flags = (client->flags & I2C_M_TEN) | I2C_M_RD;
msgs[1].len = sizeof(u64);
msgs[1].buf = (char *)&buf;
rc = i2c_transfer(client->adapter, msgs, 2);
if (rc < 0)
return rc;
*(u64 *)data = be64_to_cpu(buf);
return 0;
}
static int p8_i2c_occ_putscom(struct i2c_client *client, u32 address, u8 *data)
{
u32 buf[3];
ssize_t rc;
/* p8 i2c slave requires shift */
address <<= 1;
/* address is bus-endian; data passed through from user as-is */
buf[0] = address;
memcpy(&buf[1], &data[4], sizeof(u32));
memcpy(&buf[2], data, sizeof(u32));
rc = i2c_master_send(client, (const char *)buf, sizeof(buf));
if (rc < 0)
return rc;
else if (rc != sizeof(buf))
return -EIO;
return 0;
}
static int p8_i2c_occ_putscom_u32(struct i2c_client *client, u32 address,
u32 data0, u32 data1)
{
u8 buf[8];
memcpy(buf, &data0, 4);
memcpy(buf + 4, &data1, 4);
return p8_i2c_occ_putscom(client, address, buf);
}
static int p8_i2c_occ_putscom_be(struct i2c_client *client, u32 address,
u8 *data, size_t len)
{
__be32 data0 = 0, data1 = 0;
memcpy(&data0, data, min_t(size_t, len, 4));
if (len > 4) {
len -= 4;
memcpy(&data1, data + 4, min_t(size_t, len, 4));
}
return p8_i2c_occ_putscom_u32(client, address, be32_to_cpu(data0),
be32_to_cpu(data1));
}
static int p8_i2c_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len,
void *resp, size_t resp_len)
{
int i, rc;
unsigned long start;
Annotation
- Immediate include surface: `linux/device.h`, `linux/errno.h`, `linux/fsi-occ.h`, `linux/i2c.h`, `linux/jiffies.h`, `linux/module.h`, `linux/sched.h`, `linux/unaligned.h`.
- Detected declarations: `struct p8_i2c_occ`, `function p8_i2c_occ_getscom`, `function p8_i2c_occ_putscom`, `function p8_i2c_occ_putscom_u32`, `function p8_i2c_occ_putscom_be`, `function p8_i2c_occ_send_cmd`, `function p8_i2c_occ_probe`, `function p8_i2c_occ_remove`.
- Atlas domain: Driver Families / drivers/hwmon.
- 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.