18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Driver for NXP FXAS21002C Gyroscope - I2C
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2018 Linaro Ltd.
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <linux/err.h>
98c2ecf20Sopenharmony_ci#include <linux/i2c.h>
108c2ecf20Sopenharmony_ci#include <linux/mod_devicetable.h>
118c2ecf20Sopenharmony_ci#include <linux/module.h>
128c2ecf20Sopenharmony_ci#include <linux/regmap.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include "fxas21002c.h"
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_cistatic const struct regmap_config fxas21002c_regmap_i2c_conf = {
178c2ecf20Sopenharmony_ci	.reg_bits = 8,
188c2ecf20Sopenharmony_ci	.val_bits = 8,
198c2ecf20Sopenharmony_ci	.max_register = FXAS21002C_REG_CTRL3,
208c2ecf20Sopenharmony_ci};
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_cistatic int fxas21002c_i2c_probe(struct i2c_client *i2c)
238c2ecf20Sopenharmony_ci{
248c2ecf20Sopenharmony_ci	struct regmap *regmap;
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci	regmap = devm_regmap_init_i2c(i2c, &fxas21002c_regmap_i2c_conf);
278c2ecf20Sopenharmony_ci	if (IS_ERR(regmap)) {
288c2ecf20Sopenharmony_ci		dev_err(&i2c->dev, "Failed to register i2c regmap: %ld\n",
298c2ecf20Sopenharmony_ci			PTR_ERR(regmap));
308c2ecf20Sopenharmony_ci		return PTR_ERR(regmap);
318c2ecf20Sopenharmony_ci	}
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	return fxas21002c_core_probe(&i2c->dev, regmap, i2c->irq, i2c->name);
348c2ecf20Sopenharmony_ci}
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_cistatic int fxas21002c_i2c_remove(struct i2c_client *i2c)
378c2ecf20Sopenharmony_ci{
388c2ecf20Sopenharmony_ci	fxas21002c_core_remove(&i2c->dev);
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci	return 0;
418c2ecf20Sopenharmony_ci}
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cistatic const struct i2c_device_id fxas21002c_i2c_id[] = {
448c2ecf20Sopenharmony_ci	{ "fxas21002c", 0 },
458c2ecf20Sopenharmony_ci	{ }
468c2ecf20Sopenharmony_ci};
478c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, fxas21002c_i2c_id);
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_cistatic const struct of_device_id fxas21002c_i2c_of_match[] = {
508c2ecf20Sopenharmony_ci	{ .compatible = "nxp,fxas21002c", },
518c2ecf20Sopenharmony_ci	{ }
528c2ecf20Sopenharmony_ci};
538c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, fxas21002c_i2c_of_match);
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_cistatic struct i2c_driver fxas21002c_i2c_driver = {
568c2ecf20Sopenharmony_ci	.driver = {
578c2ecf20Sopenharmony_ci		.name = "fxas21002c_i2c",
588c2ecf20Sopenharmony_ci		.pm = &fxas21002c_pm_ops,
598c2ecf20Sopenharmony_ci		.of_match_table = fxas21002c_i2c_of_match,
608c2ecf20Sopenharmony_ci	},
618c2ecf20Sopenharmony_ci	.probe_new	= fxas21002c_i2c_probe,
628c2ecf20Sopenharmony_ci	.remove		= fxas21002c_i2c_remove,
638c2ecf20Sopenharmony_ci	.id_table	= fxas21002c_i2c_id,
648c2ecf20Sopenharmony_ci};
658c2ecf20Sopenharmony_cimodule_i2c_driver(fxas21002c_i2c_driver);
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ciMODULE_AUTHOR("Rui Miguel Silva <rui.silva@linaro.org>");
688c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2");
698c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("FXAS21002C I2C Gyro driver");
70