drivers/input/misc/bma150.c
Source file repositories/reference/linux-study-clean/drivers/input/misc/bma150.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/misc/bma150.c- Extension
.c- Size
- 13682 bytes
- Lines
- 563
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/kernel.hlinux/module.hlinux/i2c.hlinux/input.hlinux/interrupt.hlinux/delay.hlinux/slab.hlinux/pm.hlinux/pm_runtime.hlinux/bma150.h
Detected Declarations
struct bma150_datafunction bma150_write_bytefunction bma150_set_reg_bitsfunction bma150_set_modefunction bma150_soft_resetfunction bma150_set_rangefunction bma150_set_bandwidthfunction bma150_set_low_g_interruptfunction bma150_set_high_g_interruptfunction bma150_set_any_motion_interruptfunction bma150_report_xyzfunction bma150_irq_threadfunction bma150_pollfunction bma150_openfunction bma150_closefunction bma150_initializefunction bma150_probefunction bma150_removefunction bma150_suspendfunction bma150_resume
Annotated Snippet
struct bma150_data {
struct i2c_client *client;
struct input_dev *input;
u8 mode;
};
/*
* The settings for the given range, bandwidth and interrupt features
* are stated and verified by Bosch Sensortec where they are configured
* to provide a generic sensitivity performance.
*/
static const struct bma150_cfg default_cfg = {
.any_motion_int = 1,
.hg_int = 1,
.lg_int = 1,
.any_motion_dur = 0,
.any_motion_thres = 0,
.hg_hyst = 0,
.hg_dur = 150,
.hg_thres = 160,
.lg_hyst = 0,
.lg_dur = 150,
.lg_thres = 20,
.range = BMA150_RANGE_2G,
.bandwidth = BMA150_BW_50HZ
};
static int bma150_write_byte(struct i2c_client *client, u8 reg, u8 val)
{
s32 ret;
/* As per specification, disable irq in between register writes */
if (client->irq)
disable_irq_nosync(client->irq);
ret = i2c_smbus_write_byte_data(client, reg, val);
if (client->irq)
enable_irq(client->irq);
return ret;
}
static int bma150_set_reg_bits(struct i2c_client *client,
int val, int shift, u8 mask, u8 reg)
{
int data;
data = i2c_smbus_read_byte_data(client, reg);
if (data < 0)
return data;
data = (data & ~mask) | ((val << shift) & mask);
return bma150_write_byte(client, reg, data);
}
static int bma150_set_mode(struct bma150_data *bma150, u8 mode)
{
int error;
error = bma150_set_reg_bits(bma150->client, mode, BMA150_WAKE_UP_POS,
BMA150_WAKE_UP_MSK, BMA150_WAKE_UP_REG);
if (error)
return error;
error = bma150_set_reg_bits(bma150->client, mode, BMA150_SLEEP_POS,
BMA150_SLEEP_MSK, BMA150_SLEEP_REG);
if (error)
return error;
if (mode == BMA150_MODE_NORMAL)
usleep_range(2000, 2100);
bma150->mode = mode;
return 0;
}
static int bma150_soft_reset(struct bma150_data *bma150)
{
int error;
error = bma150_set_reg_bits(bma150->client, 1, BMA150_SW_RES_POS,
BMA150_SW_RES_MSK, BMA150_SW_RES_REG);
if (error)
return error;
usleep_range(2000, 2100);
return 0;
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/i2c.h`, `linux/input.h`, `linux/interrupt.h`, `linux/delay.h`, `linux/slab.h`, `linux/pm.h`.
- Detected declarations: `struct bma150_data`, `function bma150_write_byte`, `function bma150_set_reg_bits`, `function bma150_set_mode`, `function bma150_soft_reset`, `function bma150_set_range`, `function bma150_set_bandwidth`, `function bma150_set_low_g_interrupt`, `function bma150_set_high_g_interrupt`, `function bma150_set_any_motion_interrupt`.
- Atlas domain: Driver Families / drivers/input.
- Implementation status: source implementation candidate.
- 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.