drivers/input/keyboard/opencores-kbd.c
Source file repositories/reference/linux-study-clean/drivers/input/keyboard/opencores-kbd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/keyboard/opencores-kbd.c- Extension
.c- Size
- 2875 bytes
- Lines
- 117
- Domain
- Driver Families
- Bucket
- drivers/input
- 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.
- 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/input.hlinux/interrupt.hlinux/io.hlinux/ioport.hlinux/kernel.hlinux/module.hlinux/platform_device.hlinux/slab.h
Detected Declarations
struct opencores_kbdfunction opencores_kbd_isrfunction opencores_kbd_probe
Annotated Snippet
struct opencores_kbd {
struct input_dev *input;
void __iomem *addr;
int irq;
unsigned short keycodes[128];
};
static irqreturn_t opencores_kbd_isr(int irq, void *dev_id)
{
struct opencores_kbd *opencores_kbd = dev_id;
struct input_dev *input = opencores_kbd->input;
unsigned char c;
c = readb(opencores_kbd->addr);
input_report_key(input, c & 0x7f, c & 0x80 ? 0 : 1);
input_sync(input);
return IRQ_HANDLED;
}
static int opencores_kbd_probe(struct platform_device *pdev)
{
struct input_dev *input;
struct opencores_kbd *opencores_kbd;
int irq, i, error;
irq = platform_get_irq(pdev, 0);
if (irq < 0)
return -EINVAL;
opencores_kbd = devm_kzalloc(&pdev->dev, sizeof(*opencores_kbd),
GFP_KERNEL);
if (!opencores_kbd)
return -ENOMEM;
input = devm_input_allocate_device(&pdev->dev);
if (!input) {
dev_err(&pdev->dev, "failed to allocate input device\n");
return -ENOMEM;
}
opencores_kbd->input = input;
opencores_kbd->addr = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(opencores_kbd->addr))
return PTR_ERR(opencores_kbd->addr);
input->name = pdev->name;
input->phys = "opencores-kbd/input0";
input->id.bustype = BUS_HOST;
input->id.vendor = 0x0001;
input->id.product = 0x0001;
input->id.version = 0x0100;
input->keycode = opencores_kbd->keycodes;
input->keycodesize = sizeof(opencores_kbd->keycodes[0]);
input->keycodemax = ARRAY_SIZE(opencores_kbd->keycodes);
__set_bit(EV_KEY, input->evbit);
for (i = 0; i < ARRAY_SIZE(opencores_kbd->keycodes); i++) {
/*
* OpenCores controller happens to have scancodes match
* our KEY_* definitions.
*/
opencores_kbd->keycodes[i] = i;
__set_bit(opencores_kbd->keycodes[i], input->keybit);
}
__clear_bit(KEY_RESERVED, input->keybit);
error = devm_request_irq(&pdev->dev, irq, &opencores_kbd_isr,
IRQF_TRIGGER_RISING,
pdev->name, opencores_kbd);
if (error) {
dev_err(&pdev->dev, "unable to claim irq %d\n", irq);
return error;
}
error = input_register_device(input);
if (error) {
dev_err(&pdev->dev, "unable to register input device\n");
return error;
}
return 0;
}
static struct platform_driver opencores_kbd_device_driver = {
.probe = opencores_kbd_probe,
Annotation
- Immediate include surface: `linux/input.h`, `linux/interrupt.h`, `linux/io.h`, `linux/ioport.h`, `linux/kernel.h`, `linux/module.h`, `linux/platform_device.h`, `linux/slab.h`.
- Detected declarations: `struct opencores_kbd`, `function opencores_kbd_isr`, `function opencores_kbd_probe`.
- Atlas domain: Driver Families / drivers/input.
- Implementation status: source implementation candidate.
- 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.