mma7455_i2c.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * IIO accel I2C driver for Freescale MMA7455L 3-axis 10-bit accelerometer
  3. * Copyright 2015 Joachim Eastwood <manabian@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #include <linux/i2c.h>
  10. #include <linux/module.h>
  11. #include <linux/regmap.h>
  12. #include "mma7455.h"
  13. static int mma7455_i2c_probe(struct i2c_client *i2c,
  14. const struct i2c_device_id *id)
  15. {
  16. struct regmap *regmap;
  17. const char *name = NULL;
  18. regmap = devm_regmap_init_i2c(i2c, &mma7455_core_regmap);
  19. if (IS_ERR(regmap))
  20. return PTR_ERR(regmap);
  21. if (id)
  22. name = id->name;
  23. return mma7455_core_probe(&i2c->dev, regmap, name);
  24. }
  25. static int mma7455_i2c_remove(struct i2c_client *i2c)
  26. {
  27. return mma7455_core_remove(&i2c->dev);
  28. }
  29. static const struct i2c_device_id mma7455_i2c_ids[] = {
  30. { "mma7455", 0 },
  31. { "mma7456", 0 },
  32. { }
  33. };
  34. MODULE_DEVICE_TABLE(i2c, mma7455_i2c_ids);
  35. static const struct of_device_id mma7455_of_match[] = {
  36. { .compatible = "fsl,mma7455" },
  37. { .compatible = "fsl,mma7456" },
  38. { }
  39. };
  40. MODULE_DEVICE_TABLE(of, mma7455_of_match);
  41. static struct i2c_driver mma7455_i2c_driver = {
  42. .probe = mma7455_i2c_probe,
  43. .remove = mma7455_i2c_remove,
  44. .id_table = mma7455_i2c_ids,
  45. .driver = {
  46. .name = "mma7455-i2c",
  47. .of_match_table = mma7455_of_match,
  48. },
  49. };
  50. module_i2c_driver(mma7455_i2c_driver);
  51. MODULE_AUTHOR("Joachim Eastwood <manabian@gmail.com>");
  52. MODULE_DESCRIPTION("Freescale MMA7455L I2C accelerometer driver");
  53. MODULE_LICENSE("GPL v2");