hmc5843_i2c.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. return hmc5843_common_probe(&cli->dev,
  50. devm_regmap_init_i2c(cli, &hmc5843_i2c_regmap_config),
  51. id->driver_data, id->name);
  52. }
  53. static int hmc5843_i2c_remove(struct i2c_client *client)
  54. {
  55. return hmc5843_common_remove(&client->dev);
  56. }
  57. static const struct i2c_device_id hmc5843_id[] = {
  58. { "hmc5843", HMC5843_ID },
  59. { "hmc5883", HMC5883_ID },
  60. { "hmc5883l", HMC5883L_ID },
  61. { "hmc5983", HMC5983_ID },
  62. { }
  63. };
  64. MODULE_DEVICE_TABLE(i2c, hmc5843_id);
  65. static const struct of_device_id hmc5843_of_match[] = {
  66. { .compatible = "honeywell,hmc5843", .data = (void *)HMC5843_ID },
  67. { .compatible = "honeywell,hmc5883", .data = (void *)HMC5883_ID },
  68. { .compatible = "honeywell,hmc5883l", .data = (void *)HMC5883L_ID },
  69. { .compatible = "honeywell,hmc5983", .data = (void *)HMC5983_ID },
  70. {}
  71. };
  72. MODULE_DEVICE_TABLE(of, hmc5843_of_match);
  73. static struct i2c_driver hmc5843_driver = {
  74. .driver = {
  75. .name = "hmc5843",
  76. .pm = HMC5843_PM_OPS,
  77. .of_match_table = hmc5843_of_match,
  78. },
  79. .id_table = hmc5843_id,
  80. .probe = hmc5843_i2c_probe,
  81. .remove = hmc5843_i2c_remove,
  82. };
  83. module_i2c_driver(hmc5843_driver);
  84. MODULE_AUTHOR("Josef Gajdusek <atx@atx.name>");
  85. MODULE_DESCRIPTION("HMC5843/5883/5883L/5983 i2c driver");
  86. MODULE_LICENSE("GPL");