drivers/i2c/algos/i2c-algo-pcf.c
Source file repositories/reference/linux-study-clean/drivers/i2c/algos/i2c-algo-pcf.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/algos/i2c-algo-pcf.c- Extension
.c- Size
- 8523 bytes
- Lines
- 370
- Domain
- Driver Families
- Bucket
- drivers/i2c
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/module.hlinux/delay.hlinux/errno.hlinux/i2c.hlinux/i2c-algo-pcf.hlinux/string_choices.hi2c-algo-pcf.h
Detected Declarations
function Copyrightfunction i2c_repstartfunction i2c_stopfunction handle_labfunction wait_for_bbfunction wait_for_pinfunction bookfunction pcf_sendbytesfunction pcf_readbytesfunction pcf_send_addressfunction pcf_xferfunction pcf_funcfunction i2c_pcf_add_busexport i2c_pcf_add_bus
Annotated Snippet
if (timeout) {
if (timeout == -EINTR)
return -EINTR; /* arbitration lost */
i2c_stop(adap);
dev_err(&i2c_adap->dev, "i2c_write: error - timeout.\n");
return -EREMOTEIO; /* got a better one ?? */
}
if (status & I2C_PCF_LRB) {
i2c_stop(adap);
dev_err(&i2c_adap->dev, "i2c_write: error - no ack.\n");
return -EREMOTEIO; /* got a better one ?? */
}
}
if (last)
i2c_stop(adap);
else
i2c_repstart(adap);
return wrcount;
}
static int pcf_readbytes(struct i2c_adapter *i2c_adap, char *buf,
int count, int last)
{
int i, status;
struct i2c_algo_pcf_data *adap = i2c_adap->algo_data;
int wfp;
/* increment number of bytes to read by one -- read dummy byte */
for (i = 0; i <= count; i++) {
wfp = wait_for_pin(adap, &status);
if (wfp) {
if (wfp == -EINTR)
return -EINTR; /* arbitration lost */
i2c_stop(adap);
dev_err(&i2c_adap->dev, "pcf_readbytes timed out.\n");
return -1;
}
if ((status & I2C_PCF_LRB) && (i != count)) {
i2c_stop(adap);
dev_err(&i2c_adap->dev, "i2c_read: i2c_inb, No ack.\n");
return -1;
}
if (i == count - 1) {
set_pcf(adap, 1, I2C_PCF_ESO);
} else if (i == count) {
if (last)
i2c_stop(adap);
else
i2c_repstart(adap);
}
if (i)
buf[i - 1] = i2c_inb(adap);
else
i2c_inb(adap); /* dummy read */
}
return i - 1;
}
static void pcf_send_address(struct i2c_algo_pcf_data *adap,
struct i2c_msg *msg)
{
unsigned char addr = i2c_8bit_addr_from_msg(msg);
if (msg->flags & I2C_M_REV_DIR_ADDR)
addr ^= 1;
i2c_outb(adap, addr);
}
static int pcf_xfer(struct i2c_adapter *i2c_adap,
struct i2c_msg *msgs,
int num)
{
struct i2c_algo_pcf_data *adap = i2c_adap->algo_data;
struct i2c_msg *pmsg;
int i;
int timeout, status;
if (adap->xfer_begin)
adap->xfer_begin(adap->data);
/* Check for bus busy */
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/delay.h`, `linux/errno.h`, `linux/i2c.h`, `linux/i2c-algo-pcf.h`, `linux/string_choices.h`, `i2c-algo-pcf.h`.
- Detected declarations: `function Copyright`, `function i2c_repstart`, `function i2c_stop`, `function handle_lab`, `function wait_for_bb`, `function wait_for_pin`, `function book`, `function pcf_sendbytes`, `function pcf_readbytes`, `function pcf_send_address`.
- Atlas domain: Driver Families / drivers/i2c.
- Implementation status: integration 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.