hmc5843_spi.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * SPI driver for hmc5983
  3. *
  4. * Copyright (C) Josef Gajdusek <atx@atx.name>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/spi/spi.h>
  12. #include <linux/iio/iio.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_spi_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. /* Autoincrement address pointer */
  42. .read_flag_mask = 0xc0,
  43. .cache_type = REGCACHE_RBTREE,
  44. };
  45. static int hmc5843_spi_probe(struct spi_device *spi)
  46. {
  47. int ret;
  48. struct regmap *regmap;
  49. const struct spi_device_id *id = spi_get_device_id(spi);
  50. spi->mode = SPI_MODE_3;
  51. spi->max_speed_hz = 8000000;
  52. spi->bits_per_word = 8;
  53. ret = spi_setup(spi);
  54. if (ret)
  55. return ret;
  56. regmap = devm_regmap_init_spi(spi, &hmc5843_spi_regmap_config);
  57. if (IS_ERR(regmap))
  58. return PTR_ERR(regmap);
  59. return hmc5843_common_probe(&spi->dev,
  60. regmap,
  61. id->driver_data, id->name);
  62. }
  63. static int hmc5843_spi_remove(struct spi_device *spi)
  64. {
  65. return hmc5843_common_remove(&spi->dev);
  66. }
  67. static const struct spi_device_id hmc5843_id[] = {
  68. { "hmc5983", HMC5983_ID },
  69. { }
  70. };
  71. MODULE_DEVICE_TABLE(spi, hmc5843_id);
  72. static struct spi_driver hmc5843_driver = {
  73. .driver = {
  74. .name = "hmc5843",
  75. .pm = HMC5843_PM_OPS,
  76. },
  77. .id_table = hmc5843_id,
  78. .probe = hmc5843_spi_probe,
  79. .remove = hmc5843_spi_remove,
  80. };
  81. module_spi_driver(hmc5843_driver);
  82. MODULE_AUTHOR("Josef Gajdusek <atx@atx.name>");
  83. MODULE_DESCRIPTION("HMC5983 SPI driver");
  84. MODULE_LICENSE("GPL");