drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.c

Source file repositories/reference/linux-study-clean/drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.c

File Facts

System
Linux kernel
Corpus path
drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.c
Extension
.c
Size
17842 bytes
Lines
829
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 (mxl_fail(ret)) {
			mxl111sf_i2c_stop(state);
			goto fail;
		}

		for (i = 0; i < msg->len; i++) {
			ret = mxl111sf_i2c_bitbang_recvbyte(state,
							    &msg->buf[i]);
			if (mxl_fail(ret)) {
				mxl111sf_i2c_stop(state);
				goto fail;
			}

			if (i < msg->len - 1)
				mxl111sf_i2c_ack(state);
		}

		mxl111sf_i2c_nack(state);

		ret = mxl111sf_i2c_stop(state);
		if (mxl_fail(ret))
			goto fail;

	} else {

		ret = mxl111sf_i2c_start(state);
		if (mxl_fail(ret))
			goto fail;

		ret = mxl111sf_i2c_bitbang_sendbyte(state,
						    (msg->addr << 1) & 0xfe);
		if (mxl_fail(ret)) {
			mxl111sf_i2c_stop(state);
			goto fail;
		}

		for (i = 0; i < msg->len; i++) {
			ret = mxl111sf_i2c_bitbang_sendbyte(state,
							    msg->buf[i]);
			if (mxl_fail(ret)) {
				mxl111sf_i2c_stop(state);
				goto fail;
			}
		}

		/* FIXME: we only want to do this on the last transaction */
		mxl111sf_i2c_stop(state);
	}
fail:
	return ret;
}

/* HW-I2C ----------------------------------------------------------------- */

#define USB_WRITE_I2C_CMD     0x99
#define USB_READ_I2C_CMD      0xdd
#define USB_END_I2C_CMD       0xfe

#define USB_WRITE_I2C_CMD_LEN   26
#define USB_READ_I2C_CMD_LEN    24

#define I2C_MUX_REG           0x30
#define I2C_CONTROL_REG       0x00
#define I2C_SLAVE_ADDR_REG    0x08
#define I2C_DATA_REG          0x0c
#define I2C_INT_STATUS_REG    0x10

static int mxl111sf_i2c_send_data(struct mxl111sf_state *state,
				  u8 index, u8 *wdata)
{
	int ret = mxl111sf_ctrl_msg(state, wdata[0],
				    &wdata[1], 25, NULL, 0);
	mxl_fail(ret);

	return ret;
}

static int mxl111sf_i2c_get_data(struct mxl111sf_state *state,
				 u8 index, u8 *wdata, u8 *rdata)
{
	int ret = mxl111sf_ctrl_msg(state, wdata[0],
				    &wdata[1], 25, rdata, 24);
	mxl_fail(ret);

	return ret;
}

static u8 mxl111sf_i2c_check_status(struct mxl111sf_state *state)
{
	u8 status = 0;

Annotation

Implementation Notes