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.

Dependency Surface

Detected Declarations

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

Implementation Notes