19f90fd65SNuno Sá // SPDX-License-Identifier: GPL-2.0
29f90fd65SNuno Sá /*
39f90fd65SNuno Sá * Analog Devices LTC2947 high precision power and energy monitor over SPI
49f90fd65SNuno Sá *
59f90fd65SNuno Sá * Copyright 2019 Analog Devices Inc.
69f90fd65SNuno Sá */
79f90fd65SNuno Sá #include <linux/module.h>
89f90fd65SNuno Sá #include <linux/of.h>
99f90fd65SNuno Sá #include <linux/regmap.h>
109f90fd65SNuno Sá #include <linux/spi/spi.h>
119f90fd65SNuno Sá
129f90fd65SNuno Sá #include "ltc2947.h"
139f90fd65SNuno Sá
149f90fd65SNuno Sá static const struct regmap_config ltc2947_regmap_config = {
159f90fd65SNuno Sá .reg_bits = 16,
169f90fd65SNuno Sá .val_bits = 8,
179f90fd65SNuno Sá .read_flag_mask = BIT(0),
189f90fd65SNuno Sá };
199f90fd65SNuno Sá
ltc2947_probe(struct spi_device * spi)209f90fd65SNuno Sá static int ltc2947_probe(struct spi_device *spi)
219f90fd65SNuno Sá {
229f90fd65SNuno Sá struct regmap *map;
239f90fd65SNuno Sá
249f90fd65SNuno Sá map = devm_regmap_init_spi(spi, <c2947_regmap_config);
259f90fd65SNuno Sá if (IS_ERR(map))
269f90fd65SNuno Sá return PTR_ERR(map);
279f90fd65SNuno Sá
289f90fd65SNuno Sá return ltc2947_core_probe(map, spi_get_device_id(spi)->name);
299f90fd65SNuno Sá }
309f90fd65SNuno Sá
319f90fd65SNuno Sá static const struct spi_device_id ltc2947_id[] = {
329f90fd65SNuno Sá {"ltc2947", 0},
339f90fd65SNuno Sá {}
349f90fd65SNuno Sá };
359f90fd65SNuno Sá MODULE_DEVICE_TABLE(spi, ltc2947_id);
369f90fd65SNuno Sá
379f90fd65SNuno Sá static struct spi_driver ltc2947_driver = {
389f90fd65SNuno Sá .driver = {
399f90fd65SNuno Sá .name = "ltc2947",
409f90fd65SNuno Sá .of_match_table = ltc2947_of_match,
41*ca19f965SJonathan Cameron .pm = pm_sleep_ptr(<c2947_pm_ops),
429f90fd65SNuno Sá },
439f90fd65SNuno Sá .probe = ltc2947_probe,
449f90fd65SNuno Sá .id_table = ltc2947_id,
459f90fd65SNuno Sá };
469f90fd65SNuno Sá module_spi_driver(ltc2947_driver);
479f90fd65SNuno Sá
489f90fd65SNuno Sá MODULE_AUTHOR("Nuno Sa <nuno.sa@analog.com>");
499f90fd65SNuno Sá MODULE_DESCRIPTION("LTC2947 SPI power and energy monitor driver");
509f90fd65SNuno Sá MODULE_LICENSE("GPL");
51