ltc2947-spi.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Analog Devices LTC2947 high precision power and energy monitor over SPI
  4. *
  5. * Copyright 2019 Analog Devices Inc.
  6. */
  7. #include <linux/module.h>
  8. #include <linux/of.h>
  9. #include <linux/regmap.h>
  10. #include <linux/spi/spi.h>
  11. #include "ltc2947.h"
  12. static const struct regmap_config ltc2947_regmap_config = {
  13. .reg_bits = 16,
  14. .val_bits = 8,
  15. .read_flag_mask = BIT(0),
  16. };
  17. static int ltc2947_probe(struct spi_device *spi)
  18. {
  19. struct regmap *map;
  20. map = devm_regmap_init_spi(spi, &ltc2947_regmap_config);
  21. if (IS_ERR(map))
  22. return PTR_ERR(map);
  23. return ltc2947_core_probe(map, spi_get_device_id(spi)->name);
  24. }
  25. static const struct spi_device_id ltc2947_id[] = {
  26. {"ltc2947", 0},
  27. {}
  28. };
  29. MODULE_DEVICE_TABLE(spi, ltc2947_id);
  30. static struct spi_driver ltc2947_driver = {
  31. .driver = {
  32. .name = "ltc2947",
  33. .of_match_table = ltc2947_of_match,
  34. .pm = &ltc2947_pm_ops,
  35. },
  36. .probe = ltc2947_probe,
  37. .id_table = ltc2947_id,
  38. };
  39. module_spi_driver(ltc2947_driver);
  40. MODULE_AUTHOR("Nuno Sa <nuno.sa@analog.com>");
  41. MODULE_DESCRIPTION("LTC2947 SPI power and energy monitor driver");
  42. MODULE_LICENSE("GPL");