kxsd9-i2c.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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/mod_devicetable.h>
  6. #include <linux/slab.h>
  7. #include <linux/i2c.h>
  8. #include <linux/delay.h>
  9. #include <linux/regmap.h>
  10. #include "kxsd9.h"
  11. static int kxsd9_i2c_probe(struct i2c_client *i2c,
  12. const struct i2c_device_id *id)
  13. {
  14. static const struct regmap_config config = {
  15. .reg_bits = 8,
  16. .val_bits = 8,
  17. .max_register = 0x0e,
  18. };
  19. struct regmap *regmap;
  20. regmap = devm_regmap_init_i2c(i2c, &config);
  21. if (IS_ERR(regmap)) {
  22. dev_err(&i2c->dev, "Failed to register i2c regmap: %pe\n",
  23. regmap);
  24. return PTR_ERR(regmap);
  25. }
  26. return kxsd9_common_probe(&i2c->dev,
  27. regmap,
  28. i2c->name);
  29. }
  30. static void kxsd9_i2c_remove(struct i2c_client *client)
  31. {
  32. kxsd9_common_remove(&client->dev);
  33. }
  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. static const struct i2c_device_id kxsd9_i2c_id[] = {
  40. {"kxsd9", 0},
  41. { },
  42. };
  43. MODULE_DEVICE_TABLE(i2c, kxsd9_i2c_id);
  44. static struct i2c_driver kxsd9_i2c_driver = {
  45. .driver = {
  46. .name = "kxsd9",
  47. .of_match_table = kxsd9_of_match,
  48. .pm = pm_ptr(&kxsd9_dev_pm_ops),
  49. },
  50. .probe = kxsd9_i2c_probe,
  51. .remove = kxsd9_i2c_remove,
  52. .id_table = kxsd9_i2c_id,
  53. };
  54. module_i2c_driver(kxsd9_i2c_driver);
  55. MODULE_LICENSE("GPL v2");
  56. MODULE_DESCRIPTION("KXSD9 accelerometer I2C interface");
  57. MODULE_IMPORT_NS(IIO_KXSD9);