drivers/media/dvb-frontends/cx22700.c

Source file repositories/reference/linux-study-clean/drivers/media/dvb-frontends/cx22700.c

File Facts

System
Linux kernel
Corpus path
drivers/media/dvb-frontends/cx22700.c
Extension
.c
Size
10451 bytes
Lines
436
Domain
Driver Families
Bucket
drivers/media
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

struct cx22700_state {

	struct i2c_adapter* i2c;

	const struct cx22700_config* config;

	struct dvb_frontend frontend;
};


static int debug;
#define dprintk(args...) \
	do { \
		if (debug) printk(KERN_DEBUG "cx22700: " args); \
	} while (0)

static u8 init_tab [] = {
	0x04, 0x10,
	0x05, 0x09,
	0x06, 0x00,
	0x08, 0x04,
	0x09, 0x00,
	0x0a, 0x01,
	0x15, 0x40,
	0x16, 0x10,
	0x17, 0x87,
	0x18, 0x17,
	0x1a, 0x10,
	0x25, 0x04,
	0x2e, 0x00,
	0x39, 0x00,
	0x3a, 0x04,
	0x45, 0x08,
	0x46, 0x02,
	0x47, 0x05,
};


static int cx22700_writereg (struct cx22700_state* state, u8 reg, u8 data)
{
	int ret;
	u8 buf [] = { reg, data };
	struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf, .len = 2 };

	dprintk ("%s\n", __func__);

	ret = i2c_transfer (state->i2c, &msg, 1);

	if (ret != 1)
		printk("%s: writereg error (reg == 0x%02x, val == 0x%02x, ret == %i)\n",
			__func__, reg, data, ret);

	return (ret != 1) ? -1 : 0;
}

static int cx22700_readreg (struct cx22700_state* state, u8 reg)
{
	int ret;
	u8 b0 [] = { reg };
	u8 b1 [] = { 0 };
	struct i2c_msg msg [] = { { .addr = state->config->demod_address, .flags = 0, .buf = b0, .len = 1 },
			   { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = b1, .len = 1 } };

	dprintk ("%s\n", __func__);

	ret = i2c_transfer (state->i2c, msg, 2);

	if (ret != 2) return -EIO;

	return b1[0];
}

static int cx22700_set_inversion (struct cx22700_state* state, int inversion)
{
	u8 val;

	dprintk ("%s\n", __func__);

	switch (inversion) {
	case INVERSION_AUTO:
		return -EOPNOTSUPP;
	case INVERSION_ON:
		val = cx22700_readreg (state, 0x09);
		return cx22700_writereg (state, 0x09, val | 0x01);
	case INVERSION_OFF:
		val = cx22700_readreg (state, 0x09);
		return cx22700_writereg (state, 0x09, val & 0xfe);
	default:
		return -EINVAL;
	}

Annotation

Implementation Notes