st_uvis25_i2c.c 1.7 KB

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