drivers/media/usb/stk1160/stk1160-i2c.c

Source file repositories/reference/linux-study-clean/drivers/media/usb/stk1160/stk1160-i2c.c

File Facts

System
Linux kernel
Corpus path
drivers/media/usb/stk1160/stk1160-i2c.c
Extension
.c
Size
5859 bytes
Lines
285
Domain
Driver Families
Bucket
drivers/media
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.

Dependency Surface

Detected Declarations

Annotated Snippet

if (!msgs[i].len) {
			/* no len: check only for device presence */
			rc = stk1160_i2c_check_for_device(dev, addr);
			if (rc < 0) {
				dprintk_i2c(" no device\n");
				return rc;
			}

		} else if (msgs[i].flags & I2C_M_RD) {
			/* read request without preceding register selection */
			dprintk_i2c(" subaddr not selected");
			rc = -EOPNOTSUPP;
			goto err;

		} else if (i + 1 < num && msgs[i].len <= 2 &&
			   (msgs[i + 1].flags & I2C_M_RD) &&
			   msgs[i].addr == msgs[i + 1].addr) {

			if (msgs[i].len != 1 || msgs[i + 1].len != 1) {
				dprintk_i2c(" len not supported");
				rc = -EOPNOTSUPP;
				goto err;
			}

			dprintk_i2c(" subaddr=%x", msgs[i].buf[0]);

			rc = stk1160_i2c_read_reg(dev, addr, msgs[i].buf[0],
				msgs[i + 1].buf);

			dprintk_i2c(" read=%x", *msgs[i + 1].buf);

			/* consumed two msgs, so we skip one of them */
			i++;

		} else {
			if (msgs[i].len != 2) {
				dprintk_i2c(" len not supported");
				rc = -EOPNOTSUPP;
				goto err;
			}

			dprintk_i2c(" subaddr=%x write=%x",
				msgs[i].buf[0],  msgs[i].buf[1]);

			rc = stk1160_i2c_write_reg(dev, addr, msgs[i].buf[0],
				msgs[i].buf[1]);
		}

		if (rc < 0)
			goto err;
		dprintk_i2c(" OK\n");
	}

	return num;
err:
	dprintk_i2c(" ERROR: %d\n", rc);
	return num;
}

/*
 * functionality(), what da heck is this?
 */
static u32 functionality(struct i2c_adapter *adap)
{
	return I2C_FUNC_SMBUS_EMUL;
}

static const struct i2c_algorithm algo = {
	.master_xfer   = stk1160_i2c_xfer,
	.functionality = functionality,
};

static const struct i2c_adapter adap_template = {
	.owner = THIS_MODULE,
	.name = "stk1160",
	.algo = &algo,
};

static const struct i2c_client client_template = {
	.name = "stk1160 internal",
};

/*
 * stk1160_i2c_register()
 * register i2c bus
 */
int stk1160_i2c_register(struct stk1160 *dev)
{
	int rc;

Annotation

Implementation Notes