drivers/input/misc/qnap-mcu-input.c
Source file repositories/reference/linux-study-clean/drivers/input/misc/qnap-mcu-input.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/misc/qnap-mcu-input.c- Extension
.c- Size
- 3766 bytes
- Lines
- 154
- 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.
- 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/mfd/qnap-mcu.hlinux/module.hlinux/platform_device.hlinux/slab.huapi/linux/input-event-codes.h
Detected Declarations
struct qnap_mcu_input_devfunction qnap_mcu_input_pollfunction qnap_mcu_input_beeper_workfunction qnap_mcu_input_eventfunction qnap_mcu_input_closefunction qnap_mcu_input_probe
Annotated Snippet
struct qnap_mcu_input_dev {
struct input_dev *input;
struct qnap_mcu *mcu;
struct device *dev;
struct work_struct beep_work;
int beep_type;
};
static void qnap_mcu_input_poll(struct input_dev *input)
{
struct qnap_mcu_input_dev *idev = input_get_drvdata(input);
static const u8 cmd[] = { '@', 'C', 'V' };
u8 reply[4];
int state, ret;
/* poll the power button */
ret = qnap_mcu_exec(idev->mcu, cmd, sizeof(cmd), reply, sizeof(reply));
if (ret)
return;
/* First bytes must mirror the sent command */
if (memcmp(cmd, reply, sizeof(cmd))) {
dev_err(idev->dev, "malformed data received\n");
return;
}
state = reply[3] - 0x30;
input_event(input, EV_KEY, KEY_POWER, state);
input_sync(input);
}
static void qnap_mcu_input_beeper_work(struct work_struct *work)
{
struct qnap_mcu_input_dev *idev =
container_of(work, struct qnap_mcu_input_dev, beep_work);
const u8 cmd[] = { '@', 'C', (idev->beep_type == SND_TONE) ? '3' : '2' };
qnap_mcu_exec_with_ack(idev->mcu, cmd, sizeof(cmd));
}
static int qnap_mcu_input_event(struct input_dev *input, unsigned int type,
unsigned int code, int value)
{
struct qnap_mcu_input_dev *idev = input_get_drvdata(input);
if (type != EV_SND || (code != SND_BELL && code != SND_TONE))
return -EOPNOTSUPP;
if (value < 0)
return -EINVAL;
/* beep runtime is determined by the MCU */
if (value == 0)
return 0;
/* Schedule work to actually turn the beeper on */
idev->beep_type = code;
schedule_work(&idev->beep_work);
return 0;
}
static void qnap_mcu_input_close(struct input_dev *input)
{
struct qnap_mcu_input_dev *idev = input_get_drvdata(input);
cancel_work_sync(&idev->beep_work);
}
static int qnap_mcu_input_probe(struct platform_device *pdev)
{
struct qnap_mcu *mcu = dev_get_drvdata(pdev->dev.parent);
struct qnap_mcu_input_dev *idev;
struct device *dev = &pdev->dev;
struct input_dev *input;
int ret;
idev = devm_kzalloc(dev, sizeof(*idev), GFP_KERNEL);
if (!idev)
return -ENOMEM;
input = devm_input_allocate_device(dev);
if (!input)
return -ENOMEM;
idev->input = input;
idev->dev = dev;
idev->mcu = mcu;
Annotation
- Immediate include surface: `linux/input.h`, `linux/mfd/qnap-mcu.h`, `linux/module.h`, `linux/platform_device.h`, `linux/slab.h`, `uapi/linux/input-event-codes.h`.
- Detected declarations: `struct qnap_mcu_input_dev`, `function qnap_mcu_input_poll`, `function qnap_mcu_input_beeper_work`, `function qnap_mcu_input_event`, `function qnap_mcu_input_close`, `function qnap_mcu_input_probe`.
- Atlas domain: Driver Families / drivers/input.
- 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.