kxsd9-i2c.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/device.h>
  3. #include <linux/kernel.h>
  4. #include <linux/module.h>
  5. #include <linux/slab.h>
  6. #include <linux/i2c.h>
  7. #include <linux/delay.h>
  8. #include <linux/regmap.h>
  9. #include "kxsd9.h"
  10. static int kxsd9_i2c_probe(struct i2c_client *i2c,
  11. const struct i2c_device_id *id)
  12. {
  13. static const struct regmap_config config = {
  14. .reg_bits = 8,
  15. .val_bits = 8,
  16. .max_register = 0x0e,
  17. };
  18. struct regmap *regmap;
  19. regmap = devm_regmap_init_i2c(i2c, &config);
  20. if (IS_ERR(regmap)) {
  21. dev_err(&i2c->dev, "Failed to register i2c regmap %d\n",
  22. (int)PTR_ERR(regmap));
  23. return PTR_ERR(regmap);
  24. }
  25. return kxsd9_common_probe(&i2c->dev,
  26. regmap,
  27. i2c->name);
  28. }
  29. static int kxsd9_i2c_remove(struct i2c_client *client)
  30. {
  31. return kxsd9_common_remove(&client->dev);
  32. }
  33. #ifdef CONFIG_OF
  34. static const struct of_device_id kxsd9_of_match[] = {
  35. { .compatible = "kionix,kxsd9", },
  36. { },
  37. };
  38. MODULE_DEVICE_TABLE(of, kxsd9_of_match);
  39. #else
  40. #define kxsd9_of_match NULL
  41. #endif
  42. static const struct i2c_device_id kxsd9_i2c_id[] = {
  43. {"kxsd9", 0},
  44. { },
  45. };
  46. MODULE_DEVICE_TABLE(i2c, kxsd9_i2c_id);
  47. static struct i2c_driver kxsd9_i2c_driver = {
  48. .driver = {
  49. .name = "kxsd9",
  50. .of_match_table = of_match_ptr(kxsd9_of_match),
  51. .pm = &kxsd9_dev_pm_ops,
  52. },
  53. .probe = kxsd9_i2c_probe,
  54. .remove = kxsd9_i2c_remove,
  55. .id_table = kxsd9_i2c_id,
  56. };
  57. module_i2c_driver(kxsd9_i2c_driver);
  58. MODULE_LICENSE("GPL v2");
  59. MODULE_DESCRIPTION("KXSD9 accelerometer I2C interface");