drivers/macintosh/ams/ams-pmu.c
Source file repositories/reference/linux-study-clean/drivers/macintosh/ams/ams-pmu.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/macintosh/ams/ams-pmu.c- Extension
.c- Size
- 4282 bytes
- Lines
- 198
- 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.
- 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/adb.hlinux/pmu.hams.h
Detected Declarations
function ams_pmu_req_completefunction ams_pmu_set_registerfunction ams_pmu_get_registerfunction ams_pmu_set_irqfunction ams_pmu_clear_irqfunction ams_pmu_get_vendorfunction ams_pmu_get_xyzfunction ams_pmu_exitfunction ams_pmu_init
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Apple Motion Sensor driver (PMU variant)
*
* 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/adb.h>
#include <linux/pmu.h>
#include "ams.h"
/* Attitude */
#define AMS_X 0x00
#define AMS_Y 0x01
#define AMS_Z 0x02
/* Not exactly known, maybe chip vendor */
#define AMS_VENDOR 0x03
/* Freefall registers */
#define AMS_FF_CLEAR 0x04
#define AMS_FF_ENABLE 0x05
#define AMS_FF_LOW_LIMIT 0x06
#define AMS_FF_DEBOUNCE 0x07
/* Shock registers */
#define AMS_SHOCK_CLEAR 0x08
#define AMS_SHOCK_ENABLE 0x09
#define AMS_SHOCK_HIGH_LIMIT 0x0a
#define AMS_SHOCK_DEBOUNCE 0x0b
/* Global interrupt and power control register */
#define AMS_CONTROL 0x0c
static u8 ams_pmu_cmd;
static void ams_pmu_req_complete(struct adb_request *req)
{
complete((struct completion *)req->arg);
}
/* Only call this function from task context */
static void ams_pmu_set_register(u8 reg, u8 value)
{
static struct adb_request req;
DECLARE_COMPLETION(req_complete);
req.arg = &req_complete;
if (pmu_request(&req, ams_pmu_req_complete, 4, ams_pmu_cmd, 0x00, reg, value))
return;
wait_for_completion(&req_complete);
}
/* Only call this function from task context */
static u8 ams_pmu_get_register(u8 reg)
{
static struct adb_request req;
DECLARE_COMPLETION(req_complete);
req.arg = &req_complete;
if (pmu_request(&req, ams_pmu_req_complete, 3, ams_pmu_cmd, 0x01, reg))
return 0;
wait_for_completion(&req_complete);
if (req.reply_len > 0)
return req.reply[0];
else
return 0;
}
/* Enables or disables the specified interrupts */
static void ams_pmu_set_irq(enum ams_irq reg, char enable)
{
if (reg & AMS_IRQ_FREEFALL) {
u8 val = ams_pmu_get_register(AMS_FF_ENABLE);
if (enable)
val |= 0x80;
else
val &= ~0x80;
ams_pmu_set_register(AMS_FF_ENABLE, val);
}
if (reg & AMS_IRQ_SHOCK) {
Annotation
- Immediate include surface: `linux/module.h`, `linux/types.h`, `linux/errno.h`, `linux/init.h`, `linux/adb.h`, `linux/pmu.h`, `ams.h`.
- Detected declarations: `function ams_pmu_req_complete`, `function ams_pmu_set_register`, `function ams_pmu_get_register`, `function ams_pmu_set_irq`, `function ams_pmu_clear_irq`, `function ams_pmu_get_vendor`, `function ams_pmu_get_xyz`, `function ams_pmu_exit`, `function ams_pmu_init`.
- Atlas domain: Driver Families / drivers/macintosh.
- 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.