drivers/media/rc/ir_toy.c
Source file repositories/reference/linux-study-clean/drivers/media/rc/ir_toy.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/rc/ir_toy.c- Extension
.c- Size
- 13064 bytes
- Lines
- 553
- 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/unaligned.hlinux/completion.hlinux/kernel.hlinux/module.hlinux/usb.hlinux/slab.hlinux/usb/input.hmedia/rc-core.h
Detected Declarations
struct irtoyenum statefunction irtoy_responsefunction irtoy_out_callbackfunction irtoy_in_callbackfunction irtoy_commandfunction irtoy_setupfunction irtoy_txfunction irtoy_tx_carrierfunction irtoy_probefunction usb_endpoint_maxpfunction irtoy_disconnect
Annotated Snippet
struct irtoy {
struct device *dev;
struct usb_device *usbdev;
struct rc_dev *rc;
struct urb *urb_in, *urb_out;
u8 *in;
u8 *out;
struct completion command_done;
bool pulse;
enum state state;
void *tx_buf;
uint tx_len;
uint emitted;
uint hw_version;
uint sw_version;
uint proto_version;
char phys[64];
};
static void irtoy_response(struct irtoy *irtoy, u32 len)
{
switch (irtoy->state) {
case STATE_COMMAND:
if (len == LEN_VERSION && irtoy->in[0] == REPLY_VERSION) {
uint version;
irtoy->in[LEN_VERSION] = 0;
if (kstrtouint(irtoy->in + 1, 10, &version)) {
dev_err(irtoy->dev, "invalid version %*phN. Please make sure you are using firmware v20 or higher",
LEN_VERSION, irtoy->in);
break;
}
dev_dbg(irtoy->dev, "version %s\n", irtoy->in);
irtoy->hw_version = version / 100;
irtoy->sw_version = version % 100;
irtoy->state = STATE_IRDATA;
complete(&irtoy->command_done);
} else if (len == LEN_SAMPLEMODEPROTO &&
irtoy->in[0] == REPLY_SAMPLEMODEPROTO) {
uint version;
irtoy->in[LEN_SAMPLEMODEPROTO] = 0;
if (kstrtouint(irtoy->in + 1, 10, &version)) {
dev_err(irtoy->dev, "invalid sample mode response %*phN",
LEN_SAMPLEMODEPROTO, irtoy->in);
return;
}
dev_dbg(irtoy->dev, "protocol %s\n", irtoy->in);
irtoy->proto_version = version;
irtoy->state = STATE_IRDATA;
complete(&irtoy->command_done);
} else {
dev_err(irtoy->dev, "unexpected response to command: %*phN\n",
len, irtoy->in);
}
break;
case STATE_COMMAND_NO_RESP:
case STATE_IRDATA: {
struct ir_raw_event rawir = { .pulse = irtoy->pulse };
__be16 *in = (__be16 *)irtoy->in;
int i;
for (i = 0; i < len / sizeof(__be16); i++) {
u16 v = be16_to_cpu(in[i]);
if (v == 0xffff) {
rawir.pulse = false;
} else {
rawir.duration = v * UNIT_US;
ir_raw_event_store_with_timeout(irtoy->rc,
&rawir);
}
rawir.pulse = !rawir.pulse;
}
Annotation
- Immediate include surface: `linux/unaligned.h`, `linux/completion.h`, `linux/kernel.h`, `linux/module.h`, `linux/usb.h`, `linux/slab.h`, `linux/usb/input.h`, `media/rc-core.h`.
- Detected declarations: `struct irtoy`, `enum state`, `function irtoy_response`, `function irtoy_out_callback`, `function irtoy_in_callback`, `function irtoy_command`, `function irtoy_setup`, `function irtoy_tx`, `function irtoy_tx_carrier`, `function irtoy_probe`.
- 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.