xref: /linux/drivers/iio/imu/bmi270/bmi270_i2c.c (revision cdd30ebb1b9f36159d66f088b61aee264e649d7a)
13ea51548SAlex Lanzano // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
23ea51548SAlex Lanzano 
33ea51548SAlex Lanzano #include <linux/i2c.h>
43ea51548SAlex Lanzano #include <linux/iio/iio.h>
53ea51548SAlex Lanzano #include <linux/module.h>
63ea51548SAlex Lanzano #include <linux/mod_devicetable.h>
73ea51548SAlex Lanzano #include <linux/regmap.h>
83ea51548SAlex Lanzano 
93ea51548SAlex Lanzano #include "bmi270.h"
103ea51548SAlex Lanzano 
1192cc50a0SAlex Lanzano static const struct regmap_config bmi270_i2c_regmap_config = {
1292cc50a0SAlex Lanzano 	.reg_bits = 8,
1392cc50a0SAlex Lanzano 	.val_bits = 8,
1492cc50a0SAlex Lanzano };
1592cc50a0SAlex Lanzano 
bmi270_i2c_probe(struct i2c_client * client)163ea51548SAlex Lanzano static int bmi270_i2c_probe(struct i2c_client *client)
173ea51548SAlex Lanzano {
183ea51548SAlex Lanzano 	struct regmap *regmap;
193ea51548SAlex Lanzano 	struct device *dev = &client->dev;
20bb372ac2SJustin Weiss 	const struct bmi270_chip_info *chip_info;
21bb372ac2SJustin Weiss 
22bb372ac2SJustin Weiss 	chip_info = i2c_get_match_data(client);
23bb372ac2SJustin Weiss 	if (!chip_info)
24bb372ac2SJustin Weiss 		return -ENODEV;
253ea51548SAlex Lanzano 
2692cc50a0SAlex Lanzano 	regmap = devm_regmap_init_i2c(client, &bmi270_i2c_regmap_config);
273ea51548SAlex Lanzano 	if (IS_ERR(regmap))
283ea51548SAlex Lanzano 		return dev_err_probe(dev, PTR_ERR(regmap),
293ea51548SAlex Lanzano 				     "Failed to init i2c regmap");
303ea51548SAlex Lanzano 
31bb372ac2SJustin Weiss 	return bmi270_core_probe(dev, regmap, chip_info);
323ea51548SAlex Lanzano }
333ea51548SAlex Lanzano 
343ea51548SAlex Lanzano static const struct i2c_device_id bmi270_i2c_id[] = {
35f35f3c83SJustin Weiss 	{ "bmi260", (kernel_ulong_t)&bmi260_chip_info },
36bb372ac2SJustin Weiss 	{ "bmi270", (kernel_ulong_t)&bmi270_chip_info },
373ea51548SAlex Lanzano 	{ }
383ea51548SAlex Lanzano };
393ea51548SAlex Lanzano 
40f35f3c83SJustin Weiss static const struct acpi_device_id bmi270_acpi_match[] = {
41f35f3c83SJustin Weiss 	/* GPD Win Mini, Aya Neo AIR Pro, OXP Mini Pro, etc. */
42f35f3c83SJustin Weiss 	{ "BMI0160",  (kernel_ulong_t)&bmi260_chip_info },
43f35f3c83SJustin Weiss 	{ }
44f35f3c83SJustin Weiss };
45f35f3c83SJustin Weiss 
463ea51548SAlex Lanzano static const struct of_device_id bmi270_of_match[] = {
47f35f3c83SJustin Weiss 	{ .compatible = "bosch,bmi260", .data = &bmi260_chip_info },
48bb372ac2SJustin Weiss 	{ .compatible = "bosch,bmi270", .data = &bmi270_chip_info },
493ea51548SAlex Lanzano 	{ }
503ea51548SAlex Lanzano };
513ea51548SAlex Lanzano 
523ea51548SAlex Lanzano static struct i2c_driver bmi270_i2c_driver = {
533ea51548SAlex Lanzano 	.driver = {
543ea51548SAlex Lanzano 		.name = "bmi270_i2c",
55f35f3c83SJustin Weiss 		.acpi_match_table = bmi270_acpi_match,
563ea51548SAlex Lanzano 		.of_match_table = bmi270_of_match,
573ea51548SAlex Lanzano 	},
583ea51548SAlex Lanzano 	.probe = bmi270_i2c_probe,
593ea51548SAlex Lanzano 	.id_table = bmi270_i2c_id,
603ea51548SAlex Lanzano };
613ea51548SAlex Lanzano module_i2c_driver(bmi270_i2c_driver);
623ea51548SAlex Lanzano 
633ea51548SAlex Lanzano MODULE_AUTHOR("Alex Lanzano");
643ea51548SAlex Lanzano MODULE_DESCRIPTION("BMI270 driver");
653ea51548SAlex Lanzano MODULE_LICENSE("GPL");
66*cdd30ebbSPeter Zijlstra MODULE_IMPORT_NS("IIO_BMI270");
67