hmc5843_i2c.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * i2c driver for hmc5843/5843/5883/5883l/5983
  4. *
  5. * Split from hmc5843.c
  6. * Copyright (C) Josef Gajdusek <atx@atx.name>
  7. */
  8. #include <linux/module.h>
  9. #include <linux/i2c.h>
  10. #include <linux/regmap.h>
  11. #include <linux/iio/iio.h>
  12. #include <linux/iio/triggered_buffer.h>
  13. #include "hmc5843.h"
  14. static const struct regmap_range hmc5843_readable_ranges[] = {
  15. regmap_reg_range(0, HMC5843_ID_END),
  16. };
  17. static const struct regmap_access_table hmc5843_readable_table = {
  18. .yes_ranges = hmc5843_readable_ranges,
  19. .n_yes_ranges = ARRAY_SIZE(hmc5843_readable_ranges),
  20. };
  21. static const struct regmap_range hmc5843_writable_ranges[] = {
  22. regmap_reg_range(0, HMC5843_MODE_REG),
  23. };
  24. static const struct regmap_access_table hmc5843_writable_table = {
  25. .yes_ranges = hmc5843_writable_ranges,
  26. .n_yes_ranges = ARRAY_SIZE(hmc5843_writable_ranges),
  27. };
  28. static const struct regmap_range hmc5843_volatile_ranges[] = {
  29. regmap_reg_range(HMC5843_DATA_OUT_MSB_REGS, HMC5843_STATUS_REG),
  30. };
  31. static const struct regmap_access_table hmc5843_volatile_table = {
  32. .yes_ranges = hmc5843_volatile_ranges,
  33. .n_yes_ranges = ARRAY_SIZE(hmc5843_volatile_ranges),
  34. };
  35. static const struct regmap_config hmc5843_i2c_regmap_config = {
  36. .reg_bits = 8,
  37. .val_bits = 8,
  38. .rd_table = &hmc5843_readable_table,
  39. .wr_table = &hmc5843_writable_table,
  40. .volatile_table = &hmc5843_volatile_table,
  41. .cache_type = REGCACHE_RBTREE,
  42. };
  43. static int hmc5843_i2c_probe(struct i2c_client *cli,
  44. const struct i2c_device_id *id)
  45. {
  46. struct regmap *regmap = devm_regmap_init_i2c(cli,
  47. &hmc5843_i2c_regmap_config);
  48. if (IS_ERR(regmap))
  49. return PTR_ERR(regmap);
  50. return hmc5843_common_probe(&cli->dev,
  51. regmap,
  52. id->driver_data, id->name);
  53. }
  54. static int hmc5843_i2c_remove(struct i2c_client *client)
  55. {
  56. return hmc5843_common_remove(&client->dev);
  57. }
  58. static const struct i2c_device_id hmc5843_id[] = {
  59. { "hmc5843", HMC5843_ID },
  60. { "hmc5883", HMC5883_ID },
  61. { "hmc5883l", HMC5883L_ID },
  62. { "hmc5983", HMC5983_ID },
  63. { }
  64. };
  65. MODULE_DEVICE_TABLE(i2c, hmc5843_id);
  66. static const struct of_device_id hmc5843_of_match[] = {
  67. { .compatible = "honeywell,hmc5843", .data = (void *)HMC5843_ID },
  68. { .compatible = "honeywell,hmc5883", .data = (void *)HMC5883_ID },
  69. { .compatible = "honeywell,hmc5883l", .data = (void *)HMC5883L_ID },
  70. { .compatible = "honeywell,hmc5983", .data = (void *)HMC5983_ID },
  71. {}
  72. };
  73. MODULE_DEVICE_TABLE(of, hmc5843_of_match);
  74. static struct i2c_driver hmc5843_driver = {
  75. .driver = {
  76. .name = "hmc5843",
  77. .pm = HMC5843_PM_OPS,
  78. .of_match_table = hmc5843_of_match,
  79. },
  80. .id_table = hmc5843_id,
  81. .probe = hmc5843_i2c_probe,
  82. .remove = hmc5843_i2c_remove,
  83. };
  84. module_i2c_driver(hmc5843_driver);
  85. MODULE_AUTHOR("Josef Gajdusek <atx@atx.name>");
  86. MODULE_DESCRIPTION("HMC5843/5883/5883L/5983 i2c driver");
  87. MODULE_LICENSE("GPL");