drivers/hid/hid-creative-sb0540.c
Source file repositories/reference/linux-study-clean/drivers/hid/hid-creative-sb0540.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hid/hid-creative-sb0540.c- Extension
.c- Size
- 5810 bytes
- Lines
- 269
- 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.
- 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/device.hlinux/hid.hlinux/module.hhid-ids.h
Detected Declarations
struct creative_sb0540function reversefunction get_keyfunction creative_sb0540_raw_eventfunction creative_sb0540_input_configuredfunction creative_sb0540_input_mappingfunction creative_sb0540_probe
Annotated Snippet
struct creative_sb0540 {
struct input_dev *input_dev;
struct hid_device *hid;
unsigned short keymap[ARRAY_SIZE(creative_sb0540_key_table)];
};
static inline u64 reverse(u64 data, int bits)
{
int i;
u64 c;
c = 0;
for (i = 0; i < bits; i++) {
c |= (u64) (((data & (((u64) 1) << i)) ? 1 : 0))
<< (bits - 1 - i);
}
return (c);
}
static int get_key(struct creative_sb0540 *creative_sb0540, u64 keycode)
{
int i;
for (i = 0; i < ARRAY_SIZE(creative_sb0540_codes); i++) {
if (creative_sb0540_codes[i] == keycode)
return creative_sb0540->keymap[i];
}
return 0;
}
static int creative_sb0540_raw_event(struct hid_device *hid,
struct hid_report *report, u8 *data, int len)
{
struct creative_sb0540 *creative_sb0540 = hid_get_drvdata(hid);
u64 code, main_code;
int key;
if (len != 6 || !(hid->claimed & HID_CLAIMED_INPUT))
return 0;
/* From daemons/hw_hiddev.c sb0540_rec() in lirc */
code = reverse(data[5], 8);
main_code = (code << 8) + ((~code) & 0xff);
/*
* Flip to get values in the same format as
* remotes/creative/lircd.conf.alsa_usb in lirc
*/
main_code = ((main_code & 0xff) << 8) +
((main_code & 0xff00) >> 8);
key = get_key(creative_sb0540, main_code);
if (key == 0 || key == KEY_RESERVED) {
hid_err(hid, "Could not get a key for main_code %llX\n",
main_code);
return 0;
}
input_report_key(creative_sb0540->input_dev, key, 1);
input_report_key(creative_sb0540->input_dev, key, 0);
input_sync(creative_sb0540->input_dev);
/* let hidraw and hiddev handle the report */
return 0;
}
static int creative_sb0540_input_configured(struct hid_device *hid,
struct hid_input *hidinput)
{
struct input_dev *input_dev = hidinput->input;
struct creative_sb0540 *creative_sb0540 = hid_get_drvdata(hid);
int i;
creative_sb0540->input_dev = input_dev;
input_dev->keycode = creative_sb0540->keymap;
input_dev->keycodesize = sizeof(unsigned short);
input_dev->keycodemax = ARRAY_SIZE(creative_sb0540->keymap);
input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
memcpy(creative_sb0540->keymap, creative_sb0540_key_table,
sizeof(creative_sb0540->keymap));
for (i = 0; i < ARRAY_SIZE(creative_sb0540_key_table); i++)
set_bit(creative_sb0540->keymap[i], input_dev->keybit);
clear_bit(KEY_RESERVED, input_dev->keybit);
return 0;
Annotation
- Immediate include surface: `linux/device.h`, `linux/hid.h`, `linux/module.h`, `hid-ids.h`.
- Detected declarations: `struct creative_sb0540`, `function reverse`, `function get_key`, `function creative_sb0540_raw_event`, `function creative_sb0540_input_configured`, `function creative_sb0540_input_mapping`, `function creative_sb0540_probe`.
- Atlas domain: Driver Families / drivers/hid.
- 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.