fxas21002c_i2c.c 1.6 KB

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