On 9/22/20 1:37 AM, xiao.mx.ma wrote: > From: Delta <xiao.mx.ma@xxxxxxxxxxx> > > The <drivers/hwmon/pmbus/delta.c> provides a driver for Delta's modules. > Currently supports Q54SJ108A2 series and other series will continue to be > added in the future. > > Signed-off-by: Delta <xiao.mx.ma@xxxxxxxxxxx> > > Add delta.rst to Documentation/hwmon/index.rst. > Tristate "DELTA_POWER_SUPPLIES" in Kconfig is changed to "Delta Power > Supplies". Nit: This should go after '---', and you should list the v2 changes as well. Now that I can actually look at the code, I wonder if the driver is even needed. Adding something like {"q54Sj108a2", (kernel_ulong_t)&pmbus_info_one}, (or uppercase, if you prefer) to drivers/hwmon/pmbus/pmbus.c should accomplish the same. Can you explain ? If the separate driver is indeed needed, that explanation will have to be in the commit description for reference. Thanks, Guenter > --- > Documentation/hwmon/delta.rst | 52 +++++++++++++ > Documentation/hwmon/index.rst | 1 + > drivers/hwmon/pmbus/Kconfig | 9 +++ > drivers/hwmon/pmbus/Makefile | 1 + > drivers/hwmon/pmbus/delta.c | 136 ++++++++++++++++++++++++++++++++++ > 5 files changed, 199 insertions(+) > create mode 100644 Documentation/hwmon/delta.rst > create mode 100644 drivers/hwmon/pmbus/delta.c > > diff --git a/Documentation/hwmon/delta.rst b/Documentation/hwmon/delta.rst > new file mode 100644 > index 000000000000..ee63b3b9b86d > --- /dev/null > +++ b/Documentation/hwmon/delta.rst > @@ -0,0 +1,52 @@ > +Kernel driver delta > +===================== > + > +Supported chips: > + > + * DELTA Q54SJ108A2NCAH, Q54SJ108A2NCDH, Q54SJ108A2NCPG, Q54SJ108A2NCPH > + > + Prefix: 'Q54SJ108A2' > + > + Addresses scanned: - > + > + Datasheet: https://filecenter.delta-china.com.cn/products/download/01/0102/datasheet/DS_Q54SJ108A2.pdf > + > +Authors: > + Delta <xiao.mx.ma@xxxxxxxxxxx> > + > + > +Description > +----------- > + > +This driver implements support for DELTA Q54SJ108A2NCAH, Q54SJ108A2NCDH, > +Q54SJ108A2NCPG, and Q54SJ108A2NCPH 1/4 Brick DC/DC Regulated Power Module > +with PMBus support. > + > +The driver is a client driver to the core PMBus driver. > +Please see Documentation/hwmon/pmbus.rst for details on PMBus client drivers. > + > + > +Usage Notes > +----------- > + > +This driver does not auto-detect devices. You will have to instantiate the > +devices explicitly. Please see Documentation/i2c/instantiating-devices.rst for > +details. > + > + > +Sysfs entries > +------------- > + > +=================== ===== ======================================================= > +curr1_alarm RO Output current alarm > +curr1_input RO Output current > +curr1_label RO 'iout1' > +in1_alarm RO Input voltage alarm > +in1_input RO Input voltage > +in1_label RO 'vin' > +in2_alarm RO Output voltage alarm > +in2_input RO Output voltage > +in2_label RO 'vout1' > +temp1_alarm RO Temeperature alarm Nit: Temperature > +temp1_input RO Chip temperature > +=================== ===== ======================================================= > diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst > index 750d3a975d82..31c51545df72 100644 > --- a/Documentation/hwmon/index.rst > +++ b/Documentation/hwmon/index.rst > @@ -51,6 +51,7 @@ Hardware Monitoring Kernel Drivers > da9052 > da9055 > dell-smm-hwmon > + delta > dme1737 > drivetemp > ds1621 > diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig > index e35db489b76f..9b1863bfa946 100644 > --- a/drivers/hwmon/pmbus/Kconfig > +++ b/drivers/hwmon/pmbus/Kconfig > @@ -44,6 +44,15 @@ config SENSORS_BEL_PFE > > This driver can also be built as a module. If so, the module will > be called bel-pfe. > + > +config SENSORS_DELTA > + tristate "Delta Power Supplies" > + help > + If you say yes here you get hardware monitoring support for Delta > + Q54SJ108A2 series Power Supplies. > + > + This driver can also be built as a module. If so, the module will > + be called delta. > > config SENSORS_IBM_CFFPS > tristate "IBM Common Form Factor Power Supply" > diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile > index c4b15db996ad..8957f5337002 100644 > --- a/drivers/hwmon/pmbus/Makefile > +++ b/drivers/hwmon/pmbus/Makefile > @@ -7,6 +7,7 @@ obj-$(CONFIG_PMBUS) += pmbus_core.o > obj-$(CONFIG_SENSORS_PMBUS) += pmbus.o > obj-$(CONFIG_SENSORS_ADM1275) += adm1275.o > obj-$(CONFIG_SENSORS_BEL_PFE) += bel-pfe.o > +obj-$(CONFIG_SENSORS_DELTA) += delta.o > obj-$(CONFIG_SENSORS_IBM_CFFPS) += ibm-cffps.o > obj-$(CONFIG_SENSORS_INSPUR_IPSPS) += inspur-ipsps.o > obj-$(CONFIG_SENSORS_IR35221) += ir35221.o > diff --git a/drivers/hwmon/pmbus/delta.c b/drivers/hwmon/pmbus/delta.c > new file mode 100644 > index 000000000000..9fea3a3c460a > --- /dev/null > +++ b/drivers/hwmon/pmbus/delta.c > @@ -0,0 +1,136 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Driver for Delta modules, Q54SJ108A2 series 1/4 Brick DC/DC > + * Regulated Power Module > + * > + * Copyright 2020 Delta LLC. > + */ > + > +#include <linux/bits.h> > +#include <linux/err.h> > +#include <linux/i2c.h> > +#include <linux/init.h> > +#include <linux/kernel.h> > +#include <linux/module.h> > +#include <linux/mutex.h> > +#include <linux/of_device.h> > +#include <linux/pmbus.h> > +#include <linux/util_macros.h> > +#include "pmbus.h" > + > +enum chips { > + Q54SJ108A2 > +}; > + > +static const struct pmbus_driver_info delta_info[] = { > + [Q54SJ108A2] = { > + .pages = 1, > + > + /* Source : Delta Q54SJ108A2 */ > + .format[PSC_TEMPERATURE] = linear, > + .format[PSC_VOLTAGE_IN] = linear, > + .format[PSC_CURRENT_OUT] = linear, > + > + .func[0] = PMBUS_HAVE_VIN | > + PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | > + PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | > + PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP | > + PMBUS_HAVE_STATUS_INPUT, > + }, > +}; > + > + > + > +static int delta_probe(struct i2c_client *client, const struct i2c_device_id *id) > +{ > + struct device *dev = &client->dev; > + u8 buf[I2C_SMBUS_BLOCK_MAX + 1]; > + struct pmbus_driver_info *info; > + enum chips chip_id; > + int ret; > + > + if (!i2c_check_functionality(client->adapter, > + I2C_FUNC_SMBUS_BYTE_DATA | > + I2C_FUNC_SMBUS_WORD_DATA | > + I2C_FUNC_SMBUS_BLOCK_DATA)) > + return -ENODEV; > + > + if (client->dev.of_node) > + chip_id = (enum chips)of_device_get_match_data(dev); > + else > + chip_id = id->driver_data; > + > + ret = i2c_smbus_read_block_data(client, PMBUS_MFR_ID, buf); > + if (ret < 0) { > + dev_err(&client->dev, "Failed to read Manufacturer ID\n"); > + return ret; > + } > + if (ret != 5 || strncmp(buf, "DELTA", 5)) { > + buf[ret] = '\0'; > + dev_err(dev, "Unsupported Manufacturer ID '%s'\n", buf); > + return -ENODEV; > + } > + > + /* > + * The chips support reading PMBUS_MFR_MODEL. > + */ > + ret = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, buf); > + if (ret < 0) { > + dev_err(dev, "Failed to read Manufacturer Model\n"); > + return ret; > + } > + if (ret != 14 || strncmp(buf, "Q54SJ108A2", 10)) { > + buf[ret] = '\0'; > + dev_err(dev, "Unsupported Manufacturer Model '%s'\n", buf); > + return -ENODEV; > + } > + > + ret = i2c_smbus_read_block_data(client, PMBUS_MFR_REVISION, buf); > + if (ret < 0) { > + dev_err(dev, "Failed to read Manufacturer Revision\n"); > + return ret; > + } > + if (ret != 4 || buf[0] != 'S') { > + buf[ret] = '\0'; > + dev_err(dev, "Unsupported Manufacturer Revision '%s'\n", buf); > + return -ENODEV; > + } > + > + info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); > + if (!info) > + return -ENOMEM; > + > + memcpy(info, &delta_info[chip_id], sizeof(*info)); > + > + return pmbus_do_probe(client, id, info); > +} > + > +static const struct i2c_device_id delta_id[] = { > + { "Q54SJ108A2", Q54SJ108A2 }, > + { }, > +}; > + > +MODULE_DEVICE_TABLE(i2c, delta_id); > + > +static const struct of_device_id delta_of_match[] = { > + { .compatible = "delta,Q54SJ108A2", .data = (void *)Q54SJ108A2 }, > + { }, > +}; > + > +MODULE_DEVICE_TABLE(of, delta_of_match); > + > +static struct i2c_driver delta_driver = { > + .driver = { > + .name = "Q54SJ108A2", > + .of_match_table = delta_of_match, > + }, > + .probe = delta_probe, > + .remove = pmbus_do_remove, > + .id_table = delta_id, > +}; > + > +module_i2c_driver(delta_driver); > + > +MODULE_AUTHOR("Delta <xiao.mx.ma@xxxxxxxxxxx>"); > +MODULE_DESCRIPTION("PMBus driver for Delta Q54SJ108A2 series modules"); > +MODULE_LICENSE("GPL"); >