drivers/iio/accel/mma9553.c
Source file repositories/reference/linux-study-clean/drivers/iio/accel/mma9553.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/accel/mma9553.c- Extension
.c- Size
- 32158 bytes
- Lines
- 1245
- Domain
- Driver Families
- Bucket
- drivers/iio
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/i2c.hlinux/interrupt.hlinux/mod_devicetable.hlinux/module.hlinux/slab.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/events.hlinux/pm_runtime.hmma9551_core.h
Detected Declarations
struct mma9553_eventstruct mma9553_conf_regsstruct mma9553_dataenum activity_levelfunction mma9553_get_bitsfunction mma9553_set_bitsfunction mma9553_activity_to_modfunction mma9553_init_eventsfunction mma9553_is_any_event_enabledfunction mma9553_set_configfunction mma9553_read_activity_stepcntfunction mma9553_conf_gpiofunction mma9553_initfunction mma9553_read_status_wordfunction mma9553_read_rawfunction mma9553_write_rawfunction mma9553_read_event_configfunction mma9553_write_event_configfunction mma9553_read_event_valuefunction mma9553_write_event_valuefunction mma9553_get_calibgender_modefunction mma9553_set_calibgender_modefunction BITfunction mma9553_irq_handlerfunction mma9553_event_handlerfunction mma9553_probefunction mma9553_removefunction mma9553_runtime_suspendfunction mma9553_runtime_resumefunction mma9553_suspendfunction mma9553_resume
Annotated Snippet
struct mma9553_event {
const struct mma9553_event_info *info;
bool enabled;
};
struct mma9553_conf_regs {
u16 sleepmin;
u16 sleepmax;
u16 sleepthd;
u16 config;
u16 height_weight;
u16 filter;
u16 speed_step;
u16 actthd;
} __packed;
struct mma9553_data {
struct i2c_client *client;
/*
* 1. Serialize access to HW (requested by mma9551_core API).
* 2. Serialize sequences that power on/off the device and access HW.
*/
struct mutex mutex;
struct mma9553_conf_regs conf;
struct mma9553_event events[MMA9553_EVENTS_INFO_SIZE];
int num_events;
u8 gpio_bitnum;
/*
* This is used for all features that depend on step count:
* step count, distance, speed, calories.
*/
bool stepcnt_enabled;
u16 stepcnt;
u8 activity;
s64 timestamp;
};
static u8 mma9553_get_bits(u16 val, u16 mask)
{
return (val & mask) >> (ffs(mask) - 1);
}
static u16 mma9553_set_bits(u16 current_val, u16 val, u16 mask)
{
return (current_val & ~mask) | (val << (ffs(mask) - 1));
}
static enum iio_modifier mma9553_activity_to_mod(enum activity_level activity)
{
switch (activity) {
case ACTIVITY_RUNNING:
return IIO_MOD_RUNNING;
case ACTIVITY_JOGGING:
return IIO_MOD_JOGGING;
case ACTIVITY_WALKING:
return IIO_MOD_WALKING;
case ACTIVITY_REST:
return IIO_MOD_STILL;
case ACTIVITY_UNKNOWN:
default:
return IIO_NO_MOD;
}
}
static void mma9553_init_events(struct mma9553_data *data)
{
int i;
data->num_events = MMA9553_EVENTS_INFO_SIZE;
for (i = 0; i < data->num_events; i++) {
data->events[i].info = &mma9553_events_info[i];
data->events[i].enabled = false;
}
}
static struct mma9553_event *mma9553_get_event(struct mma9553_data *data,
enum iio_chan_type type,
enum iio_modifier mod,
enum iio_event_direction dir)
{
int i;
for (i = 0; i < data->num_events; i++)
if (data->events[i].info->type == type &&
data->events[i].info->mod == mod &&
data->events[i].info->dir == dir)
return &data->events[i];
return NULL;
}
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/interrupt.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/slab.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`, `linux/iio/events.h`.
- Detected declarations: `struct mma9553_event`, `struct mma9553_conf_regs`, `struct mma9553_data`, `enum activity_level`, `function mma9553_get_bits`, `function mma9553_set_bits`, `function mma9553_activity_to_mod`, `function mma9553_init_events`, `function mma9553_is_any_event_enabled`, `function mma9553_set_config`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.