hts221_i2c.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * STMicroelectronics hts221 i2c driver
  4. *
  5. * Copyright 2016 STMicroelectronics Inc.
  6. *
  7. * Lorenzo Bianconi <[email protected]>
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/acpi.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. const struct i2c_device_id *id)
  25. {
  26. struct regmap *regmap;
  27. regmap = devm_regmap_init_i2c(client, &hts221_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 hts221_probe(&client->dev, client->irq,
  34. client->name, regmap);
  35. }
  36. static const struct acpi_device_id hts221_acpi_match[] = {
  37. {"SMO9100", 0},
  38. { },
  39. };
  40. MODULE_DEVICE_TABLE(acpi, hts221_acpi_match);
  41. static const struct of_device_id hts221_i2c_of_match[] = {
  42. { .compatible = "st,hts221", },
  43. {},
  44. };
  45. MODULE_DEVICE_TABLE(of, hts221_i2c_of_match);
  46. static const struct i2c_device_id hts221_i2c_id_table[] = {
  47. { HTS221_DEV_NAME },
  48. {},
  49. };
  50. MODULE_DEVICE_TABLE(i2c, hts221_i2c_id_table);
  51. static struct i2c_driver hts221_driver = {
  52. .driver = {
  53. .name = "hts221_i2c",
  54. .pm = pm_sleep_ptr(&hts221_pm_ops),
  55. .of_match_table = hts221_i2c_of_match,
  56. .acpi_match_table = ACPI_PTR(hts221_acpi_match),
  57. },
  58. .probe = hts221_i2c_probe,
  59. .id_table = hts221_i2c_id_table,
  60. };
  61. module_i2c_driver(hts221_driver);
  62. MODULE_AUTHOR("Lorenzo Bianconi <[email protected]>");
  63. MODULE_DESCRIPTION("STMicroelectronics hts221 i2c driver");
  64. MODULE_LICENSE("GPL v2");
  65. MODULE_IMPORT_NS(IIO_HTS221);