drivers/input/misc/mma8450.c
Source file repositories/reference/linux-study-clean/drivers/input/misc/mma8450.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/misc/mma8450.c- Extension
.c- Size
- 5142 bytes
- Lines
- 228
- Domain
- Driver Families
- Bucket
- drivers/input
- 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/kernel.hlinux/module.hlinux/slab.hlinux/delay.hlinux/i2c.hlinux/input.hlinux/mod_devicetable.h
Detected Declarations
function Copyrightfunction mma8450_writefunction mma8450_read_blockfunction mma8450_pollfunction mma8450_openfunction mma8450_closefunction mma8450_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Driver for Freescale's 3-Axis Accelerometer MMA8450
*
* Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/input.h>
#include <linux/mod_devicetable.h>
#define MMA8450_DRV_NAME "mma8450"
#define MODE_CHANGE_DELAY_MS 100
#define POLL_INTERVAL 100
#define POLL_INTERVAL_MAX 500
/* register definitions */
#define MMA8450_STATUS 0x00
#define MMA8450_STATUS_ZXYDR 0x08
#define MMA8450_OUT_X8 0x01
#define MMA8450_OUT_Y8 0x02
#define MMA8450_OUT_Z8 0x03
#define MMA8450_OUT_X_LSB 0x05
#define MMA8450_OUT_X_MSB 0x06
#define MMA8450_OUT_Y_LSB 0x07
#define MMA8450_OUT_Y_MSB 0x08
#define MMA8450_OUT_Z_LSB 0x09
#define MMA8450_OUT_Z_MSB 0x0a
#define MMA8450_XYZ_DATA_CFG 0x16
#define MMA8450_CTRL_REG1 0x38
#define MMA8450_CTRL_REG2 0x39
#define MMA8450_ID 0xc6
#define MMA8450_WHO_AM_I 0x0f
static int mma8450_read(struct i2c_client *c, unsigned int off)
{
int ret;
ret = i2c_smbus_read_byte_data(c, off);
if (ret < 0)
dev_err(&c->dev,
"failed to read register 0x%02x, error %d\n",
off, ret);
return ret;
}
static int mma8450_write(struct i2c_client *c, unsigned int off, u8 v)
{
int error;
error = i2c_smbus_write_byte_data(c, off, v);
if (error < 0) {
dev_err(&c->dev,
"failed to write to register 0x%02x, error %d\n",
off, error);
return error;
}
return 0;
}
static int mma8450_read_block(struct i2c_client *c, unsigned int off,
u8 *buf, size_t size)
{
int err;
err = i2c_smbus_read_i2c_block_data(c, off, size, buf);
if (err < 0) {
dev_err(&c->dev,
"failed to read block data at 0x%02x, error %d\n",
MMA8450_OUT_X_LSB, err);
return err;
}
return 0;
}
static void mma8450_poll(struct input_dev *input)
{
struct i2c_client *c = input_get_drvdata(input);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/slab.h`, `linux/delay.h`, `linux/i2c.h`, `linux/input.h`, `linux/mod_devicetable.h`.
- Detected declarations: `function Copyright`, `function mma8450_write`, `function mma8450_read_block`, `function mma8450_poll`, `function mma8450_open`, `function mma8450_close`, `function mma8450_probe`.
- Atlas domain: Driver Families / drivers/input.
- 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.