kxsd9-i2c.c 1.3 KB

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