drivers/iio/accel/bma220_i2c.c
Source file repositories/reference/linux-study-clean/drivers/iio/accel/bma220_i2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/accel/bma220_i2c.c- Extension
.c- Size
- 1785 bytes
- Lines
- 70
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitfield.hlinux/i2c.hlinux/mod_devicetable.hlinux/module.hlinux/regmap.hlinux/types.hbma220.h
Detected Declarations
function Copyrightfunction bma220_i2c_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Bosch triaxial acceleration sensor
*
* Copyright (c) 2025 Petre Rodan <petre.rodan@subdimension.ro>
*
* Datasheet: https://media.digikey.com/pdf/Data%20Sheets/Bosch/BMA220.pdf
* I2C address is either 0x0b or 0x0a depending on CSB (pin 10)
*/
#include <linux/bitfield.h>
#include <linux/i2c.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/regmap.h>
#include <linux/types.h>
#include "bma220.h"
static int bma220_set_wdt(struct regmap *regmap, const u8 val)
{
return regmap_update_bits(regmap, BMA220_REG_WDT, BMA220_WDT_MASK,
FIELD_PREP(BMA220_WDT_MASK, val));
}
static int bma220_i2c_probe(struct i2c_client *client)
{
struct regmap *regmap;
int ret;
regmap = devm_regmap_init_i2c(client, &bma220_i2c_regmap_config);
if (IS_ERR(regmap))
return dev_err_probe(&client->dev, PTR_ERR(regmap),
"failed to create regmap\n");
ret = bma220_common_probe(&client->dev, regmap, client->irq);
if (ret)
return ret;
return bma220_set_wdt(regmap, BMA220_WDT_1MS);
}
static const struct of_device_id bma220_i2c_match[] = {
{ .compatible = "bosch,bma220" },
{ }
};
MODULE_DEVICE_TABLE(of, bma220_i2c_match);
static const struct i2c_device_id bma220_i2c_id[] = {
{ "bma220" },
{ }
};
MODULE_DEVICE_TABLE(i2c, bma220_i2c_id);
static struct i2c_driver bma220_i2c_driver = {
.driver = {
.name = "bma220_i2c",
.pm = pm_sleep_ptr(&bma220_pm_ops),
.of_match_table = bma220_i2c_match,
},
.probe = bma220_i2c_probe,
.id_table = bma220_i2c_id,
};
module_i2c_driver(bma220_i2c_driver);
MODULE_AUTHOR("Petre Rodan <petre.rodan@subdimension.ro>");
MODULE_DESCRIPTION("Bosch triaxial acceleration sensor i2c driver");
MODULE_LICENSE("GPL");
MODULE_IMPORT_NS("IIO_BOSCH_BMA220");
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/i2c.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/regmap.h`, `linux/types.h`, `bma220.h`.
- Detected declarations: `function Copyright`, `function bma220_i2c_probe`.
- Atlas domain: Driver Families / drivers/iio.
- 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.