hts221_i2c.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * STMicroelectronics hts221 i2c driver
  4. *
  5. * Copyright 2016 STMicroelectronics Inc.
  6. *
  7. * Lorenzo Bianconi <lorenzo.bianconi@st.com>
  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 "hts221.h"
  16. #define HTS221_I2C_AUTO_INCREMENT BIT(7)
  17. static const struct regmap_config hts221_i2c_regmap_config = {
  18. .reg_bits = 8,
  19. .val_bits = 8,
  20. .write_flag_mask = HTS221_I2C_AUTO_INCREMENT,
  21. .read_flag_mask = HTS221_I2C_AUTO_INCREMENT,
  22. };
  23. static int hts221_i2c_probe(struct i2c_client *client)
  24. {
  25. struct regmap *regmap;
  26. regmap = devm_regmap_init_i2c(client, &hts221_i2c_regmap_config);
  27. if (IS_ERR(regmap)) {
  28. dev_err(&client->dev, "Failed to register i2c regmap %ld\n",
  29. PTR_ERR(regmap));
  30. return PTR_ERR(regmap);
  31. }
  32. return hts221_probe(&client->dev, client->irq,
  33. client->name, regmap);
  34. }
  35. static const struct acpi_device_id hts221_acpi_match[] = {
  36. {"SMO9100", 0},
  37. { },
  38. };
  39. MODULE_DEVICE_TABLE(acpi, hts221_acpi_match);
  40. static const struct of_device_id hts221_i2c_of_match[] = {
  41. { .compatible = "st,hts221", },
  42. {},
  43. };
  44. MODULE_DEVICE_TABLE(of, hts221_i2c_of_match);
  45. static const struct i2c_device_id hts221_i2c_id_table[] = {
  46. { HTS221_DEV_NAME },
  47. {},
  48. };
  49. MODULE_DEVICE_TABLE(i2c, hts221_i2c_id_table);
  50. static struct i2c_driver hts221_driver = {
  51. .driver = {
  52. .name = "hts221_i2c",
  53. .pm = pm_sleep_ptr(&hts221_pm_ops),
  54. .of_match_table = hts221_i2c_of_match,
  55. .acpi_match_table = hts221_acpi_match,
  56. },
  57. .probe = hts221_i2c_probe,
  58. .id_table = hts221_i2c_id_table,
  59. };
  60. module_i2c_driver(hts221_driver);
  61. MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>");
  62. MODULE_DESCRIPTION("STMicroelectronics hts221 i2c driver");
  63. MODULE_LICENSE("GPL v2");
  64. MODULE_IMPORT_NS(IIO_HTS221);