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