hts221_i2c.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * STMicroelectronics hts221 i2c driver
  3. *
  4. * Copyright 2016 STMicroelectronics Inc.
  5. *
  6. * Lorenzo Bianconi <lorenzo.bianconi@st.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 "hts221.h"
  17. #define HTS221_I2C_AUTO_INCREMENT BIT(7)
  18. static const struct regmap_config hts221_i2c_regmap_config = {
  19. .reg_bits = 8,
  20. .val_bits = 8,
  21. .write_flag_mask = HTS221_I2C_AUTO_INCREMENT,
  22. .read_flag_mask = HTS221_I2C_AUTO_INCREMENT,
  23. };
  24. static int hts221_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, &hts221_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 hts221_probe(&client->dev, client->irq,
  35. client->name, regmap);
  36. }
  37. static const struct acpi_device_id hts221_acpi_match[] = {
  38. {"SMO9100", 0},
  39. { },
  40. };
  41. MODULE_DEVICE_TABLE(acpi, hts221_acpi_match);
  42. static const struct of_device_id hts221_i2c_of_match[] = {
  43. { .compatible = "st,hts221", },
  44. {},
  45. };
  46. MODULE_DEVICE_TABLE(of, hts221_i2c_of_match);
  47. static const struct i2c_device_id hts221_i2c_id_table[] = {
  48. { HTS221_DEV_NAME },
  49. {},
  50. };
  51. MODULE_DEVICE_TABLE(i2c, hts221_i2c_id_table);
  52. static struct i2c_driver hts221_driver = {
  53. .driver = {
  54. .name = "hts221_i2c",
  55. .pm = &hts221_pm_ops,
  56. .of_match_table = of_match_ptr(hts221_i2c_of_match),
  57. .acpi_match_table = ACPI_PTR(hts221_acpi_match),
  58. },
  59. .probe = hts221_i2c_probe,
  60. .id_table = hts221_i2c_id_table,
  61. };
  62. module_i2c_driver(hts221_driver);
  63. MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>");
  64. MODULE_DESCRIPTION("STMicroelectronics hts221 i2c driver");
  65. MODULE_LICENSE("GPL v2");