1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Driver for NXP FXAS21002C Gyroscope - I2C
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2018 Linaro Ltd.
6*4882a593Smuzhiyun */
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun #include <linux/err.h>
9*4882a593Smuzhiyun #include <linux/i2c.h>
10*4882a593Smuzhiyun #include <linux/mod_devicetable.h>
11*4882a593Smuzhiyun #include <linux/module.h>
12*4882a593Smuzhiyun #include <linux/regmap.h>
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun #include "fxas21002c.h"
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun static const struct regmap_config fxas21002c_regmap_i2c_conf = {
17*4882a593Smuzhiyun .reg_bits = 8,
18*4882a593Smuzhiyun .val_bits = 8,
19*4882a593Smuzhiyun .max_register = FXAS21002C_REG_CTRL3,
20*4882a593Smuzhiyun };
21*4882a593Smuzhiyun
fxas21002c_i2c_probe(struct i2c_client * i2c)22*4882a593Smuzhiyun static int fxas21002c_i2c_probe(struct i2c_client *i2c)
23*4882a593Smuzhiyun {
24*4882a593Smuzhiyun struct regmap *regmap;
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun regmap = devm_regmap_init_i2c(i2c, &fxas21002c_regmap_i2c_conf);
27*4882a593Smuzhiyun if (IS_ERR(regmap)) {
28*4882a593Smuzhiyun dev_err(&i2c->dev, "Failed to register i2c regmap: %ld\n",
29*4882a593Smuzhiyun PTR_ERR(regmap));
30*4882a593Smuzhiyun return PTR_ERR(regmap);
31*4882a593Smuzhiyun }
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun return fxas21002c_core_probe(&i2c->dev, regmap, i2c->irq, i2c->name);
34*4882a593Smuzhiyun }
35*4882a593Smuzhiyun
fxas21002c_i2c_remove(struct i2c_client * i2c)36*4882a593Smuzhiyun static int fxas21002c_i2c_remove(struct i2c_client *i2c)
37*4882a593Smuzhiyun {
38*4882a593Smuzhiyun fxas21002c_core_remove(&i2c->dev);
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun return 0;
41*4882a593Smuzhiyun }
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun static const struct i2c_device_id fxas21002c_i2c_id[] = {
44*4882a593Smuzhiyun { "fxas21002c", 0 },
45*4882a593Smuzhiyun { }
46*4882a593Smuzhiyun };
47*4882a593Smuzhiyun MODULE_DEVICE_TABLE(i2c, fxas21002c_i2c_id);
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun static const struct of_device_id fxas21002c_i2c_of_match[] = {
50*4882a593Smuzhiyun { .compatible = "nxp,fxas21002c", },
51*4882a593Smuzhiyun { }
52*4882a593Smuzhiyun };
53*4882a593Smuzhiyun MODULE_DEVICE_TABLE(of, fxas21002c_i2c_of_match);
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun static struct i2c_driver fxas21002c_i2c_driver = {
56*4882a593Smuzhiyun .driver = {
57*4882a593Smuzhiyun .name = "fxas21002c_i2c",
58*4882a593Smuzhiyun .pm = &fxas21002c_pm_ops,
59*4882a593Smuzhiyun .of_match_table = fxas21002c_i2c_of_match,
60*4882a593Smuzhiyun },
61*4882a593Smuzhiyun .probe_new = fxas21002c_i2c_probe,
62*4882a593Smuzhiyun .remove = fxas21002c_i2c_remove,
63*4882a593Smuzhiyun .id_table = fxas21002c_i2c_id,
64*4882a593Smuzhiyun };
65*4882a593Smuzhiyun module_i2c_driver(fxas21002c_i2c_driver);
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun MODULE_AUTHOR("Rui Miguel Silva <rui.silva@linaro.org>");
68*4882a593Smuzhiyun MODULE_LICENSE("GPL v2");
69*4882a593Smuzhiyun MODULE_DESCRIPTION("FXAS21002C I2C Gyro driver");
70