drivers/input/keyboard/applespi.c
Source file repositories/reference/linux-study-clean/drivers/input/keyboard/applespi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/keyboard/applespi.c- Extension
.c- Size
- 56066 bytes
- Lines
- 1934
- Domain
- Driver Families
- Bucket
- drivers/input
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/acpi.hlinux/crc16.hlinux/debugfs.hlinux/delay.hlinux/efi.hlinux/input.hlinux/input/mt.hlinux/ktime.hlinux/leds.hlinux/module.hlinux/spinlock.hlinux/spi/spi.hlinux/wait.hlinux/workqueue.hasm/barrier.hlinux/unaligned.happlespi.happlespi_trace.h
Detected Declarations
struct keyboard_protocolstruct tp_fingerstruct touchpad_protocolstruct command_protocol_tp_infostruct touchpad_info_protocolstruct command_protocol_mt_initstruct command_protocol_capslstruct command_protocol_blstruct messagestruct spi_packetstruct spi_settingsstruct applespi_tp_infostruct applespi_datastruct applespi_key_translationstruct applespi_tp_model_infofunction applespi_get_trace_funfunction applespi_setup_read_txfrsfunction applespi_setup_write_txfrsfunction applespi_asyncfunction applespi_check_write_statusfunction applespi_get_spi_settingsfunction applespi_setup_spifunction applespi_enable_spifunction applespi_msg_completefunction applespi_async_write_completefunction applespi_send_cmd_msgfunction applespi_initfunction applespi_set_capsl_ledfunction applespi_set_bl_levelfunction applespi_eventfunction le16_to_intfunction applespi_debug_update_dimensionsfunction applespi_tp_dim_openfunction applespi_tp_dim_readfunction report_finger_datafunction report_tp_statefunction applespi_find_translationfunction applespi_translate_fn_keyfunction applespi_translate_iso_layoutfunction applespi_code_to_keyfunction applespi_remap_fn_keyfunction applespi_handle_keyboard_eventfunction applespi_register_touchpad_devicefunction applespi_workerfunction applespi_handle_cmd_responsefunction applespi_verify_crcfunction applespi_debug_print_read_packetfunction applespi_got_data
Annotated Snippet
static const struct file_operations applespi_tp_dim_fops = {
.owner = THIS_MODULE,
.open = applespi_tp_dim_open,
.read = applespi_tp_dim_read,
};
static void report_finger_data(struct input_dev *input, int slot,
const struct input_mt_pos *pos,
const struct tp_finger *f)
{
input_mt_slot(input, slot);
input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
input_report_abs(input, ABS_MT_TOUCH_MAJOR,
le16_to_int(f->touch_major) << 1);
input_report_abs(input, ABS_MT_TOUCH_MINOR,
le16_to_int(f->touch_minor) << 1);
input_report_abs(input, ABS_MT_WIDTH_MAJOR,
le16_to_int(f->tool_major) << 1);
input_report_abs(input, ABS_MT_WIDTH_MINOR,
le16_to_int(f->tool_minor) << 1);
input_report_abs(input, ABS_MT_ORIENTATION,
MAX_FINGER_ORIENTATION - le16_to_int(f->orientation));
input_report_abs(input, ABS_MT_POSITION_X, pos->x);
input_report_abs(input, ABS_MT_POSITION_Y, pos->y);
}
static void report_tp_state(struct applespi_data *applespi,
struct touchpad_protocol *t)
{
const struct tp_finger *f;
struct input_dev *input;
const struct applespi_tp_info *tp_info = &applespi->tp_info;
int i, n;
/* touchpad_input_dev is set async in worker */
input = smp_load_acquire(&applespi->touchpad_input_dev);
if (!input)
return; /* touchpad isn't initialized yet */
n = 0;
for (i = 0; i < t->number_of_fingers; i++) {
f = &t->fingers[i];
if (le16_to_int(f->touch_major) == 0)
continue;
applespi->pos[n].x = le16_to_int(f->abs_x);
applespi->pos[n].y = tp_info->y_min + tp_info->y_max -
le16_to_int(f->abs_y);
n++;
if (applespi->debug_tp_dim)
applespi_debug_update_dimensions(applespi, f);
}
input_mt_assign_slots(input, applespi->slots, applespi->pos, n, 0);
for (i = 0; i < n; i++)
report_finger_data(input, applespi->slots[i],
&applespi->pos[i], &t->fingers[i]);
input_mt_sync_frame(input);
input_report_key(input, BTN_LEFT, t->clicked);
input_sync(input);
}
static const struct applespi_key_translation *
applespi_find_translation(const struct applespi_key_translation *table, u16 key)
{
const struct applespi_key_translation *trans;
for (trans = table; trans->from; trans++)
if (trans->from == key)
return trans;
return NULL;
}
static unsigned int applespi_translate_fn_key(unsigned int key, int fn_pressed)
{
const struct applespi_key_translation *trans;
int do_translate;
trans = applespi_find_translation(applespi_fn_codes, key);
if (trans) {
if (trans->flags & APPLE_FLAG_FKEY)
do_translate = (fnmode == 2 && fn_pressed) ||
(fnmode == 1 && !fn_pressed);
else
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/crc16.h`, `linux/debugfs.h`, `linux/delay.h`, `linux/efi.h`, `linux/input.h`, `linux/input/mt.h`, `linux/ktime.h`.
- Detected declarations: `struct keyboard_protocol`, `struct tp_finger`, `struct touchpad_protocol`, `struct command_protocol_tp_info`, `struct touchpad_info_protocol`, `struct command_protocol_mt_init`, `struct command_protocol_capsl`, `struct command_protocol_bl`, `struct message`, `struct spi_packet`.
- Atlas domain: Driver Families / drivers/input.
- Implementation status: pattern 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.