drivers/hid/hid-rmi.c
Source file repositories/reference/linux-study-clean/drivers/hid/hid-rmi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hid/hid-rmi.c- Extension
.c- Size
- 19283 bytes
- Lines
- 785
- Domain
- Driver Families
- Bucket
- drivers/hid
- 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.
- 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/hid.hlinux/input.hlinux/input/mt.hlinux/irq.hlinux/irqdomain.hlinux/module.hlinux/pm.hlinux/slab.hlinux/wait.hlinux/sched.hlinux/rmi.hhid-ids.h
Detected Declarations
struct rmi_dataenum rmi_mode_typefunction implementationsfunction rmi_set_modefunction rmi_write_reportfunction rmi_hid_read_blockfunction rmi_hid_write_blockfunction rmi_reset_attn_modefunction rmi_reset_workfunction rmi_input_eventfunction rmi_read_data_eventfunction rmi_check_sanityfunction rmi_raw_eventfunction rmi_eventfunction rmi_reportfunction rmi_suspendfunction rmi_post_resumefunction rmi_hid_resetfunction rmi_input_configuredfunction rmi_input_mappingfunction rmi_check_valid_report_idfunction rmi_irq_teardownfunction rmi_irq_mapfunction rmi_setup_irq_domainfunction rmi_probefunction rmi_remove
Annotated Snippet
struct rmi_data {
struct mutex page_mutex;
int page;
struct rmi_transport_dev xport;
wait_queue_head_t wait;
u8 *writeReport;
u8 *readReport;
u32 input_report_size;
u32 output_report_size;
unsigned long flags;
struct work_struct reset_work;
struct hid_device *hdev;
unsigned long device_flags;
struct irq_domain *domain;
int rmi_irq;
};
#define RMI_PAGE(addr) (((addr) >> 8) & 0xff)
static int rmi_write_report(struct hid_device *hdev, u8 *report, int len);
/**
* rmi_set_page - Set RMI page
* @hdev: The pointer to the hid_device struct
* @page: The new page address.
*
* RMI devices have 16-bit addressing, but some of the physical
* implementations (like SMBus) only have 8-bit addressing. So RMI implements
* a page address at 0xff of every page so we can reliable page addresses
* every 256 registers.
*
* The page_mutex lock must be held when this function is entered.
*
* Returns zero on success, non-zero on failure.
*/
static int rmi_set_page(struct hid_device *hdev, u8 page)
{
struct rmi_data *data = hid_get_drvdata(hdev);
int retval;
data->writeReport[0] = RMI_WRITE_REPORT_ID;
data->writeReport[1] = 1;
data->writeReport[2] = 0xFF;
data->writeReport[4] = page;
retval = rmi_write_report(hdev, data->writeReport,
data->output_report_size);
if (retval != data->output_report_size) {
dev_err(&hdev->dev,
"%s: set page failed: %d.", __func__, retval);
return retval;
}
data->page = page;
return 0;
}
static int rmi_set_mode(struct hid_device *hdev, u8 mode)
{
int ret;
const u8 txbuf[2] = {RMI_SET_RMI_MODE_REPORT_ID, mode};
u8 *buf;
buf = kmemdup(txbuf, sizeof(txbuf), GFP_KERNEL);
if (!buf)
return -ENOMEM;
ret = hid_hw_raw_request(hdev, RMI_SET_RMI_MODE_REPORT_ID, buf,
sizeof(txbuf), HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
kfree(buf);
if (ret < 0) {
dev_err(&hdev->dev, "unable to set rmi mode to %d (%d)\n", mode,
ret);
return ret;
}
return 0;
}
static int rmi_write_report(struct hid_device *hdev, u8 *report, int len)
{
struct rmi_data *data = hid_get_drvdata(hdev);
int ret;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/hid.h`, `linux/input.h`, `linux/input/mt.h`, `linux/irq.h`, `linux/irqdomain.h`, `linux/module.h`, `linux/pm.h`.
- Detected declarations: `struct rmi_data`, `enum rmi_mode_type`, `function implementations`, `function rmi_set_mode`, `function rmi_write_report`, `function rmi_hid_read_block`, `function rmi_hid_write_block`, `function rmi_reset_attn_mode`, `function rmi_reset_work`, `function rmi_input_event`.
- Atlas domain: Driver Families / drivers/hid.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.