^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * I2C IIO driver for Bosch BMA400 triaxial acceleration sensor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2019 Dan Robertson <dan@dlrobertson.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * I2C address is either 0x14 or 0x15 depending on SDO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/mod_devicetable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "bma400.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) static int bma400_i2c_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) regmap = devm_regmap_init_i2c(client, &bma400_regmap_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) if (IS_ERR(regmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) dev_err(&client->dev, "failed to create regmap\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) return PTR_ERR(regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) return bma400_probe(&client->dev, regmap, id->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static int bma400_i2c_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) return bma400_remove(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static const struct i2c_device_id bma400_i2c_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) { "bma400", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) MODULE_DEVICE_TABLE(i2c, bma400_i2c_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static const struct of_device_id bma400_of_i2c_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) { .compatible = "bosch,bma400" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) MODULE_DEVICE_TABLE(of, bma400_of_i2c_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static struct i2c_driver bma400_i2c_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) .name = "bma400",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) .of_match_table = bma400_of_i2c_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .probe = bma400_i2c_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) .remove = bma400_i2c_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) .id_table = bma400_i2c_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) module_i2c_driver(bma400_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) MODULE_AUTHOR("Dan Robertson <dan@dlrobertson.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) MODULE_DESCRIPTION("Bosch BMA400 triaxial acceleration sensor (I2C)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) MODULE_LICENSE("GPL");