hmc5843_i2c.c 2.9 KB

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