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