|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
| 2 | +/* |
| 3 | + * Hardware monitoring driver for Analog Devices MAX17616/MAX17616A |
| 4 | + * |
| 5 | + * Copyright (C) 2025 Analog Devices, Inc. |
| 6 | + */ |
| 7 | + |
| 8 | +#include <linux/err.h> |
| 9 | +#include <linux/i2c.h> |
| 10 | +#include <linux/mod_devicetable.h> |
| 11 | +#include <linux/module.h> |
| 12 | + |
| 13 | +#include "pmbus.h" |
| 14 | + |
| 15 | +static struct pmbus_driver_info max17616_info = { |
| 16 | + .pages = 1, |
| 17 | + .format[PSC_VOLTAGE_IN] = direct, |
| 18 | + .m[PSC_VOLTAGE_IN] = 512, |
| 19 | + .b[PSC_VOLTAGE_IN] = -18, |
| 20 | + .R[PSC_VOLTAGE_IN] = -1, |
| 21 | + |
| 22 | + .format[PSC_VOLTAGE_OUT] = direct, |
| 23 | + .m[PSC_VOLTAGE_OUT] = 512, |
| 24 | + .b[PSC_VOLTAGE_OUT] = -18, |
| 25 | + .R[PSC_VOLTAGE_OUT] = -1, |
| 26 | + |
| 27 | + .format[PSC_CURRENT_OUT] = direct, |
| 28 | + .m[PSC_CURRENT_OUT] = 5845, |
| 29 | + .b[PSC_CURRENT_OUT] = 80, |
| 30 | + .R[PSC_CURRENT_OUT] = -1, |
| 31 | + |
| 32 | + .format[PSC_TEMPERATURE] = direct, |
| 33 | + .m[PSC_TEMPERATURE] = 71, |
| 34 | + .b[PSC_TEMPERATURE] = 19653, |
| 35 | + .R[PSC_TEMPERATURE] = -1, |
| 36 | + |
| 37 | + .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_IOUT | |
| 38 | + PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_VOUT | |
| 39 | + PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_STATUS_INPUT | |
| 40 | + PMBUS_HAVE_STATUS_TEMP, |
| 41 | +}; |
| 42 | + |
| 43 | +static int max17616_probe(struct i2c_client *client) |
| 44 | +{ |
| 45 | + struct device *dev = &client->dev; |
| 46 | + u8 buf[I2C_SMBUS_BLOCK_MAX]; |
| 47 | + int ret; |
| 48 | + |
| 49 | + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) |
| 50 | + return -ENODEV; |
| 51 | + |
| 52 | + ret = i2c_smbus_read_i2c_block_data(client, PMBUS_MFR_MODEL, sizeof(buf), buf); |
| 53 | + if (ret < 0) |
| 54 | + return dev_err_probe(dev, ret, "Failed to read MFR_MODEL\n"); |
| 55 | + |
| 56 | + if ((strncmp(buf + 1, "MAX17616", 8) && strncmp(buf + 1, "MAX17616A", 9))) |
| 57 | + return dev_err_probe(dev, -ENODEV, "Unsupported device\n"); |
| 58 | + |
| 59 | + return pmbus_do_probe(client, &max17616_info); |
| 60 | +} |
| 61 | + |
| 62 | +static const struct i2c_device_id max17616_id[] = { |
| 63 | + { "max17616" }, |
| 64 | + { "max17616a" }, |
| 65 | + { } |
| 66 | +}; |
| 67 | +MODULE_DEVICE_TABLE(i2c, max17616_id); |
| 68 | + |
| 69 | +static const struct of_device_id __maybe_unused max17616_of_match[] = { |
| 70 | + { .compatible = "adi,max17616" }, |
| 71 | + { .compatible = "adi,max17616a" }, |
| 72 | + { } |
| 73 | +}; |
| 74 | +MODULE_DEVICE_TABLE(of, max17616_of_match); |
| 75 | + |
| 76 | +static struct i2c_driver max17616_driver = { |
| 77 | + .driver = { |
| 78 | + .name = "max17616", |
| 79 | + .of_match_table = of_match_ptr(max17616_of_match), |
| 80 | + }, |
| 81 | + .probe = max17616_probe, |
| 82 | + .id_table = max17616_id, |
| 83 | +}; |
| 84 | +module_i2c_driver(max17616_driver); |
| 85 | + |
| 86 | +MODULE_AUTHOR("Kim Seer Paller <kim.seer.paller@analog.com>"); |
| 87 | +MODULE_DESCRIPTION("PMBus driver for Analog Devices MAX17616/MAX17616A"); |
| 88 | +MODULE_LICENSE("GPL"); |
| 89 | +MODULE_IMPORT_NS(PMBUS); |
0 commit comments