summaryrefslogtreecommitdiff
path: root/drivers/iio/imu/bmi270/bmi270_i2c.c
blob: 44699ab589097eaa0eec5f2172245496ed031185 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)

#include <linux/i2c.h>
#include <linux/iio/iio.h>
#include <linux/module.h>
#include <linux/mod_devicetable.h>
#include <linux/regmap.h>

#include "bmi270.h"

static const struct regmap_config bmi270_i2c_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,
};

static int bmi270_i2c_probe(struct i2c_client *client)
{
	struct regmap *regmap;
	struct device *dev = &client->dev;
	const struct bmi270_chip_info *chip_info;

	chip_info = i2c_get_match_data(client);
	if (!chip_info)
		return -ENODEV;

	regmap = devm_regmap_init_i2c(client, &bmi270_i2c_regmap_config);
	if (IS_ERR(regmap))
		return dev_err_probe(dev, PTR_ERR(regmap),
				     "Failed to init i2c regmap");

	return bmi270_core_probe(dev, regmap, chip_info);
}

static const struct i2c_device_id bmi270_i2c_id[] = {
	{ "bmi260", (kernel_ulong_t)&bmi260_chip_info },
	{ "bmi270", (kernel_ulong_t)&bmi270_chip_info },
	{ }
};

static const struct acpi_device_id bmi270_acpi_match[] = {
	/* GPD Win Mini, Aya Neo AIR Pro, OXP Mini Pro, etc. */
	{ "BMI0160",  (kernel_ulong_t)&bmi260_chip_info },
	{ }
};

static const struct of_device_id bmi270_of_match[] = {
	{ .compatible = "bosch,bmi260", .data = &bmi260_chip_info },
	{ .compatible = "bosch,bmi270", .data = &bmi270_chip_info },
	{ }
};

static struct i2c_driver bmi270_i2c_driver = {
	.driver = {
		.name = "bmi270_i2c",
		.acpi_match_table = bmi270_acpi_match,
		.of_match_table = bmi270_of_match,
	},
	.probe = bmi270_i2c_probe,
	.id_table = bmi270_i2c_id,
};
module_i2c_driver(bmi270_i2c_driver);

MODULE_AUTHOR("Alex Lanzano");
MODULE_DESCRIPTION("BMI270 driver");
MODULE_LICENSE("GPL");
MODULE_IMPORT_NS("IIO_BMI270");