st_uvis25_i2c.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * STMicroelectronics uvis25 i2c driver
  3. *
  4. * Copyright 2017 STMicroelectronics Inc.
  5. *
  6. * Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
  7. *
  8. * Licensed under the GPL-2.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/acpi.h>
  13. #include <linux/i2c.h>
  14. #include <linux/slab.h>
  15. #include <linux/regmap.h>
  16. #include "st_uvis25.h"
  17. #define UVIS25_I2C_AUTO_INCREMENT BIT(7)
  18. static const struct regmap_config st_uvis25_i2c_regmap_config = {
  19. .reg_bits = 8,
  20. .val_bits = 8,
  21. .write_flag_mask = UVIS25_I2C_AUTO_INCREMENT,
  22. .read_flag_mask = UVIS25_I2C_AUTO_INCREMENT,
  23. };
  24. static int st_uvis25_i2c_probe(struct i2c_client *client,
  25. const struct i2c_device_id *id)
  26. {
  27. struct regmap *regmap;
  28. regmap = devm_regmap_init_i2c(client, &st_uvis25_i2c_regmap_config);
  29. if (IS_ERR(regmap)) {
  30. dev_err(&client->dev, "Failed to register i2c regmap %d\n",
  31. (int)PTR_ERR(regmap));
  32. return PTR_ERR(regmap);
  33. }
  34. return st_uvis25_probe(&client->dev, client->irq, regmap);
  35. }
  36. static const struct of_device_id st_uvis25_i2c_of_match[] = {
  37. { .compatible = "st,uvis25", },
  38. {},
  39. };
  40. MODULE_DEVICE_TABLE(of, st_uvis25_i2c_of_match);
  41. static const struct i2c_device_id st_uvis25_i2c_id_table[] = {
  42. { ST_UVIS25_DEV_NAME },
  43. {},
  44. };
  45. MODULE_DEVICE_TABLE(i2c, st_uvis25_i2c_id_table);
  46. static struct i2c_driver st_uvis25_driver = {
  47. .driver = {
  48. .name = "st_uvis25_i2c",
  49. .pm = &st_uvis25_pm_ops,
  50. .of_match_table = of_match_ptr(st_uvis25_i2c_of_match),
  51. },
  52. .probe = st_uvis25_i2c_probe,
  53. .id_table = st_uvis25_i2c_id_table,
  54. };
  55. module_i2c_driver(st_uvis25_driver);
  56. MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>");
  57. MODULE_DESCRIPTION("STMicroelectronics uvis25 i2c driver");
  58. MODULE_LICENSE("GPL v2");