drivers/media/i2c/ir-kbd-i2c.c
Source file repositories/reference/linux-study-clean/drivers/media/i2c/ir-kbd-i2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/i2c/ir-kbd-i2c.c- Extension
.c- Size
- 24168 bytes
- Lines
- 1005
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/unaligned.hlinux/module.hlinux/init.hlinux/kernel.hlinux/string.hlinux/timer.hlinux/delay.hlinux/errno.hlinux/slab.hlinux/i2c.hlinux/workqueue.hmedia/rc-core.hmedia/i2c/ir-kbd-i2c.h
Detected Declarations
struct code_blockfunction get_key_haup_commonfunction get_key_haupfunction get_key_haup_xvrfunction get_key_pixelviewfunction get_key_fusionhdtvfunction get_key_knc1function get_key_geniatechfunction get_key_avermedia_cardbusfunction ir_key_pollfunction ir_workfunction ir_openfunction ir_closefunction send_data_blockfunction zilog_initfunction copy_codesfunction cmp_no_trailfunction find_slotfunction zilog_ir_formatfunction zilog_txfunction zilog_tx_carrierfunction zilog_tx_duty_cyclefunction ir_probefunction ir_remove
Annotated Snippet
struct code_block {
u8 length;
u16 pulse[7]; /* not aligned */
u8 carrier_pulse;
u8 carrier_space;
u16 space[8]; /* not aligned */
u8 codes[61];
u8 csum[2];
} __packed;
static int send_data_block(struct IR_i2c *ir, int cmd,
struct code_block *code_block)
{
int i, j, ret;
u8 buf[5], *p;
p = &code_block->length;
for (i = 0; p < code_block->csum; i++)
code_block->csum[i & 1] ^= *p++;
p = &code_block->length;
for (i = 0; i < sizeof(*code_block);) {
int tosend = sizeof(*code_block) - i;
if (tosend > 4)
tosend = 4;
buf[0] = i + 1;
for (j = 0; j < tosend; ++j)
buf[1 + j] = p[i + j];
dev_dbg(&ir->rc->dev, "%*ph", tosend + 1, buf);
ret = i2c_master_send(ir->tx_c, buf, tosend + 1);
if (ret != tosend + 1) {
dev_dbg(&ir->rc->dev,
"i2c_master_send failed with %d\n", ret);
return ret < 0 ? ret : -EIO;
}
i += tosend;
}
buf[0] = 0;
buf[1] = cmd;
ret = i2c_master_send(ir->tx_c, buf, 2);
if (ret != 2) {
dev_err(&ir->rc->dev, "i2c_master_send failed with %d\n", ret);
return ret < 0 ? ret : -EIO;
}
usleep_range(2000, 5000);
ret = i2c_master_send(ir->tx_c, buf, 1);
if (ret != 1) {
dev_err(&ir->rc->dev, "i2c_master_send failed with %d\n", ret);
return ret < 0 ? ret : -EIO;
}
return 0;
}
static int zilog_init(struct IR_i2c *ir)
{
struct code_block code_block = { .length = sizeof(code_block) };
u8 buf[4];
int ret;
put_unaligned_be16(0x1000, &code_block.pulse[3]);
ret = send_data_block(ir, ZILOG_INIT_END, &code_block);
if (ret)
return ret;
ret = i2c_master_recv(ir->tx_c, buf, 4);
if (ret != 4) {
dev_err(&ir->c->dev, "failed to retrieve firmware version: %d\n",
ret);
return ret < 0 ? ret : -EIO;
}
dev_info(&ir->c->dev, "Zilog/Hauppauge IR blaster firmware version %d.%d.%d\n",
buf[1], buf[2], buf[3]);
return 0;
}
/*
* If the last slot for pulse is the same as the current slot for pulse,
* then use slot no 7.
*/
static void copy_codes(u8 *dst, u8 *src, unsigned int count)
{
Annotation
- Immediate include surface: `linux/unaligned.h`, `linux/module.h`, `linux/init.h`, `linux/kernel.h`, `linux/string.h`, `linux/timer.h`, `linux/delay.h`, `linux/errno.h`.
- Detected declarations: `struct code_block`, `function get_key_haup_common`, `function get_key_haup`, `function get_key_haup_xvr`, `function get_key_pixelview`, `function get_key_fusionhdtv`, `function get_key_knc1`, `function get_key_geniatech`, `function get_key_avermedia_cardbus`, `function ir_key_poll`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.