drivers/media/dvb-frontends/dib3000mc.c

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

File Facts

System
Linux kernel
Corpus path
drivers/media/dvb-frontends/dib3000mc.c
Extension
.c
Size
26764 bytes
Lines
976
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 dib3000mc_state {
	struct dvb_frontend demod;
	struct dib3000mc_config *cfg;

	u8 i2c_addr;
	struct i2c_adapter *i2c_adap;

	struct dibx000_i2c_master i2c_master;

	u32 timf;

	u32 current_bandwidth;

	u16 dev_id;

	u8 sfn_workaround_active :1;
};

static u16 dib3000mc_read_word(struct dib3000mc_state *state, u16 reg)
{
	struct i2c_msg msg[2] = {
		{ .addr = state->i2c_addr >> 1, .flags = 0,        .len = 2 },
		{ .addr = state->i2c_addr >> 1, .flags = I2C_M_RD, .len = 2 },
	};
	u16 word;
	u8 *b;

	b = kmalloc(4, GFP_KERNEL);
	if (!b)
		return 0;

	b[0] = (reg >> 8) | 0x80;
	b[1] = reg;
	b[2] = 0;
	b[3] = 0;

	msg[0].buf = b;
	msg[1].buf = b + 2;

	if (i2c_transfer(state->i2c_adap, msg, 2) != 2)
		dprintk("i2c read error on %d\n",reg);

	word = (b[2] << 8) | b[3];
	kfree(b);

	return word;
}

static int dib3000mc_write_word(struct dib3000mc_state *state, u16 reg, u16 val)
{
	struct i2c_msg msg = {
		.addr = state->i2c_addr >> 1, .flags = 0, .len = 4
	};
	int rc;
	u8 *b;

	b = kmalloc(4, GFP_KERNEL);
	if (!b)
		return -ENOMEM;

	b[0] = reg >> 8;
	b[1] = reg;
	b[2] = val >> 8;
	b[3] = val;

	msg.buf = b;

	rc = i2c_transfer(state->i2c_adap, &msg, 1) != 1 ? -EREMOTEIO : 0;
	kfree(b);

	return rc;
}

static int dib3000mc_identify(struct dib3000mc_state *state)
{
	u16 value;
	if ((value = dib3000mc_read_word(state, 1025)) != 0x01b3) {
		dprintk("-E-  DiB3000MC/P: wrong Vendor ID (read=0x%x)\n",value);
		return -EREMOTEIO;
	}

	value = dib3000mc_read_word(state, 1026);
	if (value != 0x3001 && value != 0x3002) {
		dprintk("-E-  DiB3000MC/P: wrong Device ID (%x)\n",value);
		return -EREMOTEIO;
	}
	state->dev_id = value;

	dprintk("-I-  found DiB3000MC/P: %x\n",state->dev_id);

Annotation

Implementation Notes