hmc5843_spi.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. * */
  11. #include <linux/module.h>
  12. #include <linux/spi/spi.h>
  13. #include <linux/iio/iio.h>
  14. #include "hmc5843.h"
  15. static const struct regmap_range hmc5843_readable_ranges[] = {
  16. regmap_reg_range(0, HMC5843_ID_END),
  17. };
  18. static const struct regmap_access_table hmc5843_readable_table = {
  19. .yes_ranges = hmc5843_readable_ranges,
  20. .n_yes_ranges = ARRAY_SIZE(hmc5843_readable_ranges),
  21. };
  22. static const struct regmap_range hmc5843_writable_ranges[] = {
  23. regmap_reg_range(0, HMC5843_MODE_REG),
  24. };
  25. static const struct regmap_access_table hmc5843_writable_table = {
  26. .yes_ranges = hmc5843_writable_ranges,
  27. .n_yes_ranges = ARRAY_SIZE(hmc5843_writable_ranges),
  28. };
  29. static const struct regmap_range hmc5843_volatile_ranges[] = {
  30. regmap_reg_range(HMC5843_DATA_OUT_MSB_REGS, HMC5843_STATUS_REG),
  31. };
  32. static const struct regmap_access_table hmc5843_volatile_table = {
  33. .yes_ranges = hmc5843_volatile_ranges,
  34. .n_yes_ranges = ARRAY_SIZE(hmc5843_volatile_ranges),
  35. };
  36. static const struct regmap_config hmc5843_spi_regmap_config = {
  37. .reg_bits = 8,
  38. .val_bits = 8,
  39. .rd_table = &hmc5843_readable_table,
  40. .wr_table = &hmc5843_writable_table,
  41. .volatile_table = &hmc5843_volatile_table,
  42. /* Autoincrement address pointer */
  43. .read_flag_mask = 0xc0,
  44. .cache_type = REGCACHE_RBTREE,
  45. };
  46. static int hmc5843_spi_probe(struct spi_device *spi)
  47. {
  48. int ret;
  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. return hmc5843_common_probe(&spi->dev,
  57. devm_regmap_init_spi(spi, &hmc5843_spi_regmap_config),
  58. id->driver_data, id->name);
  59. }
  60. static int hmc5843_spi_remove(struct spi_device *spi)
  61. {
  62. return hmc5843_common_remove(&spi->dev);
  63. }
  64. static const struct spi_device_id hmc5843_id[] = {
  65. { "hmc5983", HMC5983_ID },
  66. { }
  67. };
  68. MODULE_DEVICE_TABLE(spi, hmc5843_id);
  69. static struct spi_driver hmc5843_driver = {
  70. .driver = {
  71. .name = "hmc5843",
  72. .pm = HMC5843_PM_OPS,
  73. },
  74. .id_table = hmc5843_id,
  75. .probe = hmc5843_spi_probe,
  76. .remove = hmc5843_spi_remove,
  77. };
  78. module_spi_driver(hmc5843_driver);
  79. MODULE_AUTHOR("Josef Gajdusek <atx@atx.name>");
  80. MODULE_DESCRIPTION("HMC5983 SPI driver");
  81. MODULE_LICENSE("GPL");