drivers/media/tuners/qm1d1b0004.c
Source file repositories/reference/linux-study-clean/drivers/media/tuners/qm1d1b0004.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/tuners/qm1d1b0004.c- Extension
.c- Size
- 6124 bytes
- Lines
- 266
- 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.
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/module.hmedia/dvb_frontend.hqm1d1b0004.h
Detected Declarations
struct qm1d1b0004_statestruct qm1d1b0004_cb_mapfunction lookup_cbfunction qm1d1b0004_set_paramsfunction qm1d1b0004_set_configfunction qm1d1b0004_initfunction qm1d1b0004_probefunction qm1d1b0004_remove
Annotated Snippet
struct qm1d1b0004_state {
struct qm1d1b0004_config cfg;
struct i2c_client *i2c;
};
struct qm1d1b0004_cb_map {
u32 frequency;
u8 cb;
};
static const struct qm1d1b0004_cb_map cb_maps[] = {
{ 986000, 0xb2 },
{ 1072000, 0xd2 },
{ 1154000, 0xe2 },
{ 1291000, 0x20 },
{ 1447000, 0x40 },
{ 1615000, 0x60 },
{ 1791000, 0x80 },
{ 1972000, 0xa0 },
};
static u8 lookup_cb(u32 frequency)
{
int i;
const struct qm1d1b0004_cb_map *map;
for (i = 0; i < ARRAY_SIZE(cb_maps); i++) {
map = &cb_maps[i];
if (frequency < map->frequency)
return map->cb;
}
return 0xc0;
}
static int qm1d1b0004_set_params(struct dvb_frontend *fe)
{
struct qm1d1b0004_state *state;
u32 frequency, pll, lpf_freq;
u16 word;
u8 buf[4], cb, lpf;
int ret;
state = fe->tuner_priv;
frequency = fe->dtv_property_cache.frequency;
pll = QM1D1B0004_XTL_FREQ / 4;
if (state->cfg.half_step)
pll /= 2;
word = DIV_ROUND_CLOSEST(frequency, pll);
cb = lookup_cb(frequency);
if (cb & QM1D1B0004_PSC_MASK)
word = (word << 1 & ~0x1f) | (word & 0x0f);
/* step.1: set frequency with BG:2, TM:0(4MHZ), LPF:4MHz */
buf[0] = 0x40 | word >> 8;
buf[1] = word;
/* inconsisnten with the above I/F doc. maybe the doc is wrong */
buf[2] = 0xe0 | state->cfg.half_step;
buf[3] = cb;
ret = i2c_master_send(state->i2c, buf, 4);
if (ret < 0)
return ret;
/* step.2: set TM:1 */
buf[0] = 0xe4 | state->cfg.half_step;
ret = i2c_master_send(state->i2c, buf, 1);
if (ret < 0)
return ret;
msleep(20);
/* step.3: set LPF */
lpf_freq = state->cfg.lpf_freq;
if (lpf_freq == QM1D1B0004_CFG_LPF_DFLT)
lpf_freq = fe->dtv_property_cache.symbol_rate / 1000;
if (lpf_freq == 0)
lpf_freq = QM1D1B0004_LPF_FALLBACK;
lpf = DIV_ROUND_UP(lpf_freq, 2000) - 2;
buf[0] = 0xe4 | ((lpf & 0x0c) << 1) | state->cfg.half_step;
buf[1] = cb | ((lpf & 0x03) << 2);
ret = i2c_master_send(state->i2c, buf, 2);
if (ret < 0)
return ret;
/* step.4: read PLL lock? */
buf[0] = 0;
ret = i2c_master_recv(state->i2c, buf, 1);
if (ret < 0)
return ret;
return 0;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `media/dvb_frontend.h`, `qm1d1b0004.h`.
- Detected declarations: `struct qm1d1b0004_state`, `struct qm1d1b0004_cb_map`, `function lookup_cb`, `function qm1d1b0004_set_params`, `function qm1d1b0004_set_config`, `function qm1d1b0004_init`, `function qm1d1b0004_probe`, `function qm1d1b0004_remove`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.