18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * BMI160 - Bosch IMU, I2C bits
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (c) 2016, Intel Corporation.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * 7-bit I2C slave address is:
88c2ecf20Sopenharmony_ci *      - 0x68 if SDO is pulled to GND
98c2ecf20Sopenharmony_ci *      - 0x69 if SDO is pulled to VDDIO
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci#include <linux/acpi.h>
128c2ecf20Sopenharmony_ci#include <linux/i2c.h>
138c2ecf20Sopenharmony_ci#include <linux/module.h>
148c2ecf20Sopenharmony_ci#include <linux/of.h>
158c2ecf20Sopenharmony_ci#include <linux/regmap.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include "bmi160.h"
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cistatic int bmi160_i2c_probe(struct i2c_client *client,
208c2ecf20Sopenharmony_ci			    const struct i2c_device_id *id)
218c2ecf20Sopenharmony_ci{
228c2ecf20Sopenharmony_ci	struct regmap *regmap;
238c2ecf20Sopenharmony_ci	const char *name = NULL;
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci	regmap = devm_regmap_init_i2c(client, &bmi160_regmap_config);
268c2ecf20Sopenharmony_ci	if (IS_ERR(regmap)) {
278c2ecf20Sopenharmony_ci		dev_err(&client->dev, "Failed to register i2c regmap: %pe\n",
288c2ecf20Sopenharmony_ci			regmap);
298c2ecf20Sopenharmony_ci		return PTR_ERR(regmap);
308c2ecf20Sopenharmony_ci	}
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci	if (id)
338c2ecf20Sopenharmony_ci		name = id->name;
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci	return bmi160_core_probe(&client->dev, regmap, name, false);
368c2ecf20Sopenharmony_ci}
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_cistatic const struct i2c_device_id bmi160_i2c_id[] = {
398c2ecf20Sopenharmony_ci	{"bmi160", 0},
408c2ecf20Sopenharmony_ci	{}
418c2ecf20Sopenharmony_ci};
428c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, bmi160_i2c_id);
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistatic const struct acpi_device_id bmi160_acpi_match[] = {
458c2ecf20Sopenharmony_ci	{"BMI0160", 0},
468c2ecf20Sopenharmony_ci	{ },
478c2ecf20Sopenharmony_ci};
488c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(acpi, bmi160_acpi_match);
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci#ifdef CONFIG_OF
518c2ecf20Sopenharmony_cistatic const struct of_device_id bmi160_of_match[] = {
528c2ecf20Sopenharmony_ci	{ .compatible = "bosch,bmi160" },
538c2ecf20Sopenharmony_ci	{ },
548c2ecf20Sopenharmony_ci};
558c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, bmi160_of_match);
568c2ecf20Sopenharmony_ci#endif
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistatic struct i2c_driver bmi160_i2c_driver = {
598c2ecf20Sopenharmony_ci	.driver = {
608c2ecf20Sopenharmony_ci		.name			= "bmi160_i2c",
618c2ecf20Sopenharmony_ci		.acpi_match_table	= ACPI_PTR(bmi160_acpi_match),
628c2ecf20Sopenharmony_ci		.of_match_table		= of_match_ptr(bmi160_of_match),
638c2ecf20Sopenharmony_ci	},
648c2ecf20Sopenharmony_ci	.probe		= bmi160_i2c_probe,
658c2ecf20Sopenharmony_ci	.id_table	= bmi160_i2c_id,
668c2ecf20Sopenharmony_ci};
678c2ecf20Sopenharmony_cimodule_i2c_driver(bmi160_i2c_driver);
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ciMODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com>");
708c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("BMI160 I2C driver");
718c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2");
72