drivers/macintosh/ams/ams-input.c
Source file repositories/reference/linux-study-clean/drivers/macintosh/ams/ams-input.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/macintosh/ams/ams-input.c- Extension
.c- Size
- 3210 bytes
- Lines
- 157
- Domain
- Driver Families
- Bucket
- drivers/macintosh
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/types.hlinux/errno.hlinux/init.hlinux/delay.hams.h
Detected Declarations
function ams_idev_pollfunction ams_input_enablefunction ams_input_disablefunction ams_input_show_joystickfunction ams_input_store_joystickfunction ams_input_initfunction ams_input_exit
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Apple Motion Sensor driver (joystick emulation)
*
* Copyright (C) 2005 Stelian Pop (stelian@popies.net)
* Copyright (C) 2006 Michael Hanselmann (linux-kernel@hansmi.ch)
*/
#include <linux/module.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/delay.h>
#include "ams.h"
static bool joystick;
module_param(joystick, bool, S_IRUGO);
MODULE_PARM_DESC(joystick, "Enable the input class device on module load");
static bool invert;
module_param(invert, bool, S_IWUSR | S_IRUGO);
MODULE_PARM_DESC(invert, "Invert input data on X and Y axis");
static DEFINE_MUTEX(ams_input_mutex);
static void ams_idev_poll(struct input_dev *idev)
{
s8 x, y, z;
mutex_lock(&ams_info.lock);
ams_sensors(&x, &y, &z);
x -= ams_info.xcalib;
y -= ams_info.ycalib;
z -= ams_info.zcalib;
input_report_abs(idev, ABS_X, invert ? -x : x);
input_report_abs(idev, ABS_Y, invert ? -y : y);
input_report_abs(idev, ABS_Z, z);
input_sync(idev);
mutex_unlock(&ams_info.lock);
}
/* Call with ams_info.lock held! */
static int ams_input_enable(void)
{
struct input_dev *input;
s8 x, y, z;
int error;
ams_sensors(&x, &y, &z);
ams_info.xcalib = x;
ams_info.ycalib = y;
ams_info.zcalib = z;
input = input_allocate_device();
if (!input)
return -ENOMEM;
input->name = "Apple Motion Sensor";
input->id.bustype = ams_info.bustype;
input->id.vendor = 0;
input->dev.parent = &ams_info.of_dev->dev;
input_set_abs_params(input, ABS_X, -50, 50, 3, 0);
input_set_abs_params(input, ABS_Y, -50, 50, 3, 0);
input_set_abs_params(input, ABS_Z, -50, 50, 3, 0);
input_set_capability(input, EV_KEY, BTN_TOUCH);
error = input_setup_polling(input, ams_idev_poll);
if (error)
goto err_free_input;
input_set_poll_interval(input, 25);
error = input_register_device(input);
if (error)
goto err_free_input;
ams_info.idev = input;
joystick = true;
return 0;
err_free_input:
Annotation
- Immediate include surface: `linux/module.h`, `linux/types.h`, `linux/errno.h`, `linux/init.h`, `linux/delay.h`, `ams.h`.
- Detected declarations: `function ams_idev_poll`, `function ams_input_enable`, `function ams_input_disable`, `function ams_input_show_joystick`, `function ams_input_store_joystick`, `function ams_input_init`, `function ams_input_exit`.
- Atlas domain: Driver Families / drivers/macintosh.
- 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.