Skip to contentSkip to conversation

hwmon:Driver for Delta power supplies Q54SJ108A2

PATCH Superseded xiao.ma 3 participants 3 messages Nov 9, 2020 – Nov 22, 2020

Subsystems (2)

v8 of 11 Superseded Latest is v11 →

lore
Share & tools
lore

xiao.ma

author
#0 lore raw

PATCH v8 1/1 hwmon:Driver for Delta power supplies Q54SJ108A2

From: "xiao.ma" <[email protected]>

The driver supports Q54SJ108A2 series modules of Delta.
Standard attributes are in the sysfs, and other attributes are in the debugfs.

---

Notes:
Patch v2 changelog:
Add delta.rst in Documentation/hwmon.
Tristate "DELTA" in Kconfig is changed to "DELTA_POWER_SUPPLIED".
Modify code: drop the excessive empty lines, correct the comment content, adjust indent, remove extra brackets.
Patch v3 changelog:
Add delta.rst to Documentation/hwmon/index.rst.
Tristate "DELTA_POWER_SUPPLES" in Kconfig is changed to "Delta Power Supplies".
Patch v4 changelog:
Correct the spelling "Temperature" in the delta.rst.
Add Write_protect when write command VOUT_OV_RESPONSE and IOUT_OC_FAULT_RESPONSE.
Patch v5 changelog:
Add some non-standard attributes in sysfs system.
Patch v6 changelog:
delta.c and delta.rst are renamed to q54sj108a2.c and q54sj108a2.rst.
Add q54sj108a2 to index.rst.
Tristate in Kconfig is changed to "Delta Power Supplies Q54SJ108A2".
The non-standard attributes are added to debugfs.
Patch v7 changelog:
Use standard fuctions bin2hex and hex2bin.
The return of debugfs write is changed to count.
Drop the error checking of debugfs functions.
Use probe_new fuction.
Remove the .remove fuction.
Patch v8 changelog:
Use kstrtou8_from_user instead of hex2bin.
Remove included head files which are not used.
Done label in debugfs_read fuction is deleted.
Change email to send the patch.

 Documentation/hwmon/index.rst      |   1 +
 Documentation/hwmon/q54sj108a2.rst |  52 ++++
 drivers/hwmon/pmbus/Kconfig        |   9 +
 drivers/hwmon/pmbus/Makefile       |   1 +
 drivers/hwmon/pmbus/q54sj108a2.c   | 422 +++++++++++++++++++++++++++++
 5 files changed, 485 insertions(+)
 create mode 100644 Documentation/hwmon/q54sj108a2.rst
 create mode 100755 drivers/hwmon/pmbus/q54sj108a2.c
Documentation/hwmon/index.rst +1 -0
index b797db738225..4bb680b3c7ea 100644
@@ -148,6 +148,7 @@ Hardware Monitoring Kernel Drivers
    powr1220
    pxe1610
    pwm-fan
+   q54sj108a2
    raspberrypi-hwmon
    sch5627
    sch5636
Documentation/hwmon/q54sj108a2.rst new file +52 -0

52 lines not on this page · raw message

drivers/hwmon/pmbus/Kconfig +9 -0
index a25faf69fce3..01de280820ee 100644
@@ -229,6 +229,15 @@ config SENSORS_PXE1610
 	  This driver can also be built as a module. If so, the module will
 	  be called pxe1610.
 
+config SENSORS_Q54SJ108A2
+	tristate "Delta Power Supplies Q54SJ108A2"
+	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 q54sj108a2.
+
 config SENSORS_TPS40422
 	tristate "TI TPS40422"
 	help
drivers/hwmon/pmbus/Makefile +1 -0
index 4c97ad0bd791..a50122cd455b 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_SENSORS_MAX34440)	+= max34440.o
 obj-$(CONFIG_SENSORS_MAX8688)	+= max8688.o
 obj-$(CONFIG_SENSORS_MP2975)	+= mp2975.o
 obj-$(CONFIG_SENSORS_PXE1610)	+= pxe1610.o
+obj-$(CONFIG_SENSORS_Q54SJ108A2)	+= q54sj108a2.o
 obj-$(CONFIG_SENSORS_TPS40422)	+= tps40422.o
 obj-$(CONFIG_SENSORS_TPS53679)	+= tps53679.o
 obj-$(CONFIG_SENSORS_UCD9000)	+= ucd9000.o
drivers/hwmon/pmbus/q54sj108a2.c new file +422 -0

422 lines not on this page · raw message

Signature · 1 line
2.25.1
#1 lore raw
Thank you for the patch! Perhaps something to improve:

Hi "xiao.ma",

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on hwmon/hwmon-next]
[also build test WARNING on v5.10-rc3 next-20201110]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/xiao-ma/hwmon-Driver-for-Delta-power-supplies-Q54SJ108A2/20201109-153125
base:   https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git hwmon-next
config: powerpc-randconfig-r024-20201110 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 4d81c8adb6ed9840257f6cb6b93f60856d422a15)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install powerpc cross compiling tool for clang build
# apt-get install binutils-powerpc-linux-gnu
# https://github.com/0day-ci/linux/commit/f47495409701f52f17c950668c73b20ba8ab3f66
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review xiao-ma/hwmon-Driver-for-Delta-power-supplies-Q54SJ108A2/20201109-153125 git checkout f47495409701f52f17c950668c73b20ba8ab3f66
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=powerpc

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

In file included from include/linux/kernel_stat.h:9:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:10:
In file included from arch/powerpc/include/asm/hardirq.h:6:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/powerpc/include/asm/io.h:604:
arch/powerpc/include/asm/io-defs.h:47:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] DEF_PCI_AC_NORET(insl, (unsigned long p, void *b, unsigned long c), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/powerpc/include/asm/io.h:601:3: note: expanded from macro 'DEF_PCI_AC_NORET'

                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:127:1: note: expanded from here
   __do_insl
   ^
   arch/powerpc/include/asm/io.h:543:56: note: expanded from macro '__do_insl'
   #define __do_insl(p, b, n)      readsl((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
                                          ~~~~~~~~~~~~~~~~~~~~~^
   In file included from drivers/hwmon/pmbus/q54sj108a2.c:13:
   In file included from drivers/hwmon/pmbus/pmbus.h:13:
   In file included from include/linux/regulator/driver.h:18:
   In file included from include/linux/regulator/consumer.h:35:
   In file included from include/linux/suspend.h:5:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:10:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:604:
   arch/powerpc/include/asm/io-defs.h:49:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(outsb, (unsigned long p, const void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:601:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:129:1: note: expanded from here
   __do_outsb
   ^
   arch/powerpc/include/asm/io.h:544:58: note: expanded from macro '__do_outsb'
   #define __do_outsb(p, b, n)     writesb((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
                                           ~~~~~~~~~~~~~~~~~~~~~^
   In file included from drivers/hwmon/pmbus/q54sj108a2.c:13:
   In file included from drivers/hwmon/pmbus/pmbus.h:13:
   In file included from include/linux/regulator/driver.h:18:
   In file included from include/linux/regulator/consumer.h:35:
   In file included from include/linux/suspend.h:5:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:10:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:604:
   arch/powerpc/include/asm/io-defs.h:51:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(outsw, (unsigned long p, const void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:601:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:131:1: note: expanded from here
   __do_outsw
   ^
   arch/powerpc/include/asm/io.h:545:58: note: expanded from macro '__do_outsw'
   #define __do_outsw(p, b, n)     writesw((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
                                           ~~~~~~~~~~~~~~~~~~~~~^
   In file included from drivers/hwmon/pmbus/q54sj108a2.c:13:
   In file included from drivers/hwmon/pmbus/pmbus.h:13:
   In file included from include/linux/regulator/driver.h:18:
   In file included from include/linux/regulator/consumer.h:35:
   In file included from include/linux/suspend.h:5:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:10:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:604:
   arch/powerpc/include/asm/io-defs.h:53:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(outsl, (unsigned long p, const void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:601:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:133:1: note: expanded from here
   __do_outsl
   ^
   arch/powerpc/include/asm/io.h:546:58: note: expanded from macro '__do_outsl'
   #define __do_outsl(p, b, n)     writesl((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
                                           ~~~~~~~~~~~~~~~~~~~~~^
>> drivers/hwmon/pmbus/q54sj108a2.c:293:13: warning: cast to smaller integer type 'enum chips' from 'const void *' [-Wvoid-pointer-to-enum-cast]
                   chip_id = (enum chips)of_device_get_match_data(dev);
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/hwmon/pmbus/q54sj108a2.c:333:56: error: too many arguments to function call, expected 2, have 3
           ret = pmbus_do_probe(client, &q54sj108a2_id[chip_id], &q54sj108a2_info[chip_id]);
                 ~~~~~~~~~~~~~~                                  ^~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/hwmon/pmbus/pmbus.h:492:5: note: 'pmbus_do_probe' declared here
   int pmbus_do_probe(struct i2c_client *client, struct pmbus_driver_info *info);
       ^

13 warnings and 1 error generated.

vim +293 drivers/hwmon/pmbus/q54sj108a2.c

275
276 static int q54sj108a2_probe(struct i2c_client *client)
277 {
278 struct device *dev = &client->dev;
279 u8 buf[I2C_SMBUS_BLOCK_MAX + 1];
280 enum chips chip_id;
281 int ret, i;
282 struct dentry *debugfs;
283 struct dentry *q54sj108a2_dir;
284 struct q54sj108a2_data *psu;
285
286 if (!i2c_check_functionality(client->adapter,

   287					     I2C_FUNC_SMBUS_BYTE_DATA |
   288					     I2C_FUNC_SMBUS_WORD_DATA |
   289					     I2C_FUNC_SMBUS_BLOCK_DATA))
   290			return -ENODEV;
   291	
   292		if (client->dev.of_node)
 > 293			chip_id = (enum chips)of_device_get_match_data(dev);

294 else
295 chip_id = i2c_match_id(q54sj108a2_id, client)->driver_data;
296
297 ret = i2c_smbus_read_block_data(client, PMBUS_MFR_ID, buf);
298 if (ret < 0) {
299 dev_err(&client->dev, "Failed to read Manufacturer ID\n");
300 return ret;
301 }
302 if (ret != 5 || strncmp(buf, "DELTA", 5)) {
303 buf[ret] = '\0';
304 dev_err(dev, "Unsupported Manufacturer ID '%s'\n", buf);
305 return -ENODEV;
306 }
307
308 /*
309 * The chips support reading PMBUS_MFR_MODEL.
310 */
311 ret = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, buf);
312 if (ret < 0) {
313 dev_err(dev, "Failed to read Manufacturer Model\n");
314 return ret;
315 }
316 if (ret != 14 || strncmp(buf, "Q54SJ108A2", 10)) {
317 buf[ret] = '\0';
318 dev_err(dev, "Unsupported Manufacturer Model '%s'\n", buf);
319 return -ENODEV;
320 }
321
322 ret = i2c_smbus_read_block_data(client, PMBUS_MFR_REVISION, buf);
323 if (ret < 0) {
324 dev_err(dev, "Failed to read Manufacturer Revision\n");
325 return ret;
326 }
327 if (ret != 4 || buf[0] != 'S') {
328 buf[ret] = '\0';
329 dev_err(dev, "Unsupported Manufacturer Revision '%s'\n", buf);
330 return -ENODEV;
331 }
332
333 ret = pmbus_do_probe(client, &q54sj108a2_id[chip_id], &q54sj108a2_info[chip_id]);
334 if (ret)
335 return ret;
336
337 psu = devm_kzalloc(&client->dev, sizeof(*psu), GFP_KERNEL);
338 if (!psu)
339 return 0;
340
341 psu->client = client;
342
343 debugfs = pmbus_get_debugfs_dir(client);
344
345 q54sj108a2_dir = debugfs_create_dir(client->name, debugfs);
346
347 for (i = 0; i < Q54SJ108A2_DEBUGFS_NUM_ENTRIES; ++i)
348 psu->debugfs_entries[i] = i;
349
350 debugfs_create_file("operation", 0644, q54sj108a2_dir,
351 &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_OPERATION],
352 &q54sj108a2_fops);
353 debugfs_create_file("clear_fault", 0200, q54sj108a2_dir,
354 &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_CLEARFAULT],
355 &q54sj108a2_fops);
356 debugfs_create_file("write_protect", 0444, q54sj108a2_dir,
357 &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_WRITEPROTECT],
358 &q54sj108a2_fops);
359 debugfs_create_file("store_default", 0200, q54sj108a2_dir,
360 &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_STOREDEFAULT],
361 &q54sj108a2_fops);
362 debugfs_create_file("vo_ov_response", 0644, q54sj108a2_dir,
363 &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_VOOV_RESPONSE],
364 &q54sj108a2_fops);
365 debugfs_create_file("io_oc_response", 0644, q54sj108a2_dir,
366 &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_IOOC_RESPONSE],
367 &q54sj108a2_fops);
368 debugfs_create_file("pmbus_revision", 0444, q54sj108a2_dir,
369 &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_PMBUS_VERSION],
370 &q54sj108a2_fops);
371 debugfs_create_file("mfr_id", 0444, q54sj108a2_dir,
372 &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_MFR_ID],
373 &q54sj108a2_fops);
374 debugfs_create_file("mfr_model", 0444, q54sj108a2_dir,
375 &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_MFR_MODEL],
376 &q54sj108a2_fops);
377 debugfs_create_file("mfr_revision", 0444, q54sj108a2_dir,
378 &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_MFR_REVISION],
379 &q54sj108a2_fops);
380 debugfs_create_file("mfr_location", 0444, q54sj108a2_dir,
381 &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_MFR_LOCATION],
382 &q54sj108a2_fops);
383 debugfs_create_file("blackbox_erase", 0200, q54sj108a2_dir,
384 &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_BLACKBOX_ERASE],
385 &q54sj108a2_fops);
386 debugfs_create_file("blackbox_read_offset", 0444, q54sj108a2_dir,
387 &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_BLACKBOX_READ_OFFSET],
388 &q54sj108a2_fops);
389 debugfs_create_file("blackbox_set_offset", 0200, q54sj108a2_dir,
390 &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_BLACKBOX_SET_OFFSET],
391 &q54sj108a2_fops);
392 debugfs_create_file("blackbox_read", 0444, q54sj108a2_dir,
393 &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_BLACKBOX_READ],
394 &q54sj108a2_fops);
395 debugfs_create_file("flash_key", 0444, q54sj108a2_dir,
396 &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_FLASH_KEY],
397 &q54sj108a2_fops);
398
399 return 0;
400 }
401

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

maintainer
#2 lore raw
In reply to xiao.ma
Quoted 6 lines · xiao.ma

From: "xiao.ma" <[email protected]>

The driver supports Q54SJ108A2 series modules of Delta.
Standard attributes are in the sysfs, and other attributes are in the debugfs.

Please fix all checkpatch errors and warnings before resubmitting. Additional comments below.

Guenter

Quoted 432 lines

---

Notes:
Patch v2 changelog:
Add delta.rst in Documentation/hwmon.
Tristate "DELTA" in Kconfig is changed to "DELTA_POWER_SUPPLIED".
Modify code: drop the excessive empty lines, correct the comment content, adjust indent, remove extra brackets.
Patch v3 changelog:
Add delta.rst to Documentation/hwmon/index.rst.
Tristate "DELTA_POWER_SUPPLES" in Kconfig is changed to "Delta Power Supplies".
Patch v4 changelog:
Correct the spelling "Temperature" in the delta.rst.
Add Write_protect when write command VOUT_OV_RESPONSE and IOUT_OC_FAULT_RESPONSE.
Patch v5 changelog:
Add some non-standard attributes in sysfs system.
Patch v6 changelog:
delta.c and delta.rst are renamed to q54sj108a2.c and q54sj108a2.rst.
Add q54sj108a2 to index.rst.
Tristate in Kconfig is changed to "Delta Power Supplies Q54SJ108A2".
The non-standard attributes are added to debugfs.
Patch v7 changelog:
Use standard fuctions bin2hex and hex2bin.
The return of debugfs write is changed to count.
Drop the error checking of debugfs functions.
Use probe_new fuction.
Remove the .remove fuction.
Patch v8 changelog:
Use kstrtou8_from_user instead of hex2bin.
Remove included head files which are not used.
Done label in debugfs_read fuction is deleted.
Change email to send the patch.

 Documentation/hwmon/index.rst      |   1 +
 Documentation/hwmon/q54sj108a2.rst |  52 ++++
 drivers/hwmon/pmbus/Kconfig        |   9 +
 drivers/hwmon/pmbus/Makefile       |   1 +
 drivers/hwmon/pmbus/q54sj108a2.c   | 422 +++++++++++++++++++++++++++++
 5 files changed, 485 insertions(+)
 create mode 100644 Documentation/hwmon/q54sj108a2.rst
 create mode 100755 drivers/hwmon/pmbus/q54sj108a2.c
Documentation/hwmon/index.rst +1 -0
index b797db738225..4bb680b3c7ea 100644
@@ -148,6 +148,7 @@ Hardware Monitoring Kernel Drivers
    powr1220
    pxe1610
    pwm-fan
+   q54sj108a2
    raspberrypi-hwmon
    sch5627
    sch5636
Documentation/hwmon/q54sj108a2.rst new file +52 -0
new file mode 100644
index 000000000000..a575bdfa7c18
@@ -0,0 +1,52 @@
+Kernel driver q54sj108a2
+=====================
+
+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:
+    Xiao.ma <[email protected]>
+
+
+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    Temperature alarm
+temp1_input           RO    Chip temperature
+===================== ===== ==================================================
drivers/hwmon/pmbus/Kconfig +9 -0
index a25faf69fce3..01de280820ee 100644
@@ -229,6 +229,15 @@ config SENSORS_PXE1610
 	  This driver can also be built as a module. If so, the module will
 	  be called pxe1610.
 
+config SENSORS_Q54SJ108A2
+	tristate "Delta Power Supplies Q54SJ108A2"
+	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 q54sj108a2.
+
 config SENSORS_TPS40422
 	tristate "TI TPS40422"
 	help
drivers/hwmon/pmbus/Makefile +1 -0
index 4c97ad0bd791..a50122cd455b 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_SENSORS_MAX34440)	+= max34440.o
 obj-$(CONFIG_SENSORS_MAX8688)	+= max8688.o
 obj-$(CONFIG_SENSORS_MP2975)	+= mp2975.o
 obj-$(CONFIG_SENSORS_PXE1610)	+= pxe1610.o
+obj-$(CONFIG_SENSORS_Q54SJ108A2)	+= q54sj108a2.o
 obj-$(CONFIG_SENSORS_TPS40422)	+= tps40422.o
 obj-$(CONFIG_SENSORS_TPS53679)	+= tps53679.o
 obj-$(CONFIG_SENSORS_UCD9000)	+= ucd9000.o
drivers/hwmon/pmbus/q54sj108a2.c new file +283 -0
new file mode 100755
index 000000000000..f25a5c8c2a2b
@@ -0,0 +1,422 @@
+// 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/debugfs.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include "pmbus.h"
+
+#define STORE_DEFAULT_ALL         0x11
+#define ERASE_BLACKBOX_DATA       0xD1
+#define READ_HISTORY_EVENT_NUMBER 0xD2
+#define READ_HISTORY_EVENTS       0xE0
+#define SET_HISTORY_EVENT_OFFSET  0xE1
+#define PMBUS_CMD_FLASH_KEY_WRITE 0xEC
+
+enum chips {
+	Q54SJ108A2
+};
+
+enum {
+	Q54SJ108A2_DEBUGFS_OPERATION = 0,
+	Q54SJ108A2_DEBUGFS_CLEARFAULT,
+	Q54SJ108A2_DEBUGFS_WRITEPROTECT,
+	Q54SJ108A2_DEBUGFS_STOREDEFAULT,
+	Q54SJ108A2_DEBUGFS_VOOV_RESPONSE,
+	Q54SJ108A2_DEBUGFS_IOOC_RESPONSE,
+	Q54SJ108A2_DEBUGFS_PMBUS_VERSION,
+	Q54SJ108A2_DEBUGFS_MFR_ID,
+	Q54SJ108A2_DEBUGFS_MFR_MODEL,
+	Q54SJ108A2_DEBUGFS_MFR_REVISION,
+	Q54SJ108A2_DEBUGFS_MFR_LOCATION,
+	Q54SJ108A2_DEBUGFS_BLACKBOX_ERASE,
+	Q54SJ108A2_DEBUGFS_BLACKBOX_READ_OFFSET,
+	Q54SJ108A2_DEBUGFS_BLACKBOX_SET_OFFSET,
+	Q54SJ108A2_DEBUGFS_BLACKBOX_READ,
+	Q54SJ108A2_DEBUGFS_FLASH_KEY,
+	Q54SJ108A2_DEBUGFS_NUM_ENTRIES
+};
+
+struct q54sj108a2_data {
+	enum chips chip;
+	struct i2c_client *client;
+
+	int debugfs_entries[Q54SJ108A2_DEBUGFS_NUM_ENTRIES];
+};
+
+#define to_psu(x, y) container_of((x), struct q54sj108a2_data, debugfs_entries[(y)])
+
+static struct pmbus_driver_info q54sj108a2_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 ssize_t q54sj108a2_debugfs_read(struct file *file, char __user *buf,
+				      size_t count, loff_t *ppos)
+{
+	int rc;
+	int *idxp = file->private_data;
+	int idx = *idxp;
+	struct q54sj108a2_data *psu = to_psu(idxp, idx);
+	char data[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };
+	char data_char[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };
+	char *res;
+
+	switch (idx) {
+	case Q54SJ108A2_DEBUGFS_OPERATION:
+		rc = i2c_smbus_read_byte_data(psu->client, PMBUS_OPERATION);
+		if (rc < 0)
+			return rc;
+
+		rc = snprintf(data, 3, "%02x", rc);
+		break;
+	case Q54SJ108A2_DEBUGFS_WRITEPROTECT:
+		rc = i2c_smbus_read_byte_data(psu->client, PMBUS_WRITE_PROTECT);
+		if (rc < 0)
+			return rc;
+
+		rc = snprintf(data, 3, "%02x", rc);
+		break;
+	case Q54SJ108A2_DEBUGFS_VOOV_RESPONSE:
+		rc = i2c_smbus_read_byte_data(psu->client, PMBUS_VOUT_OV_FAULT_RESPONSE);
+		if (rc < 0)
+			return rc;
+
+		rc = snprintf(data, 3, "%02x", rc);
+		break;
+	case Q54SJ108A2_DEBUGFS_IOOC_RESPONSE:
+		rc = i2c_smbus_read_byte_data(psu->client, PMBUS_IOUT_OC_FAULT_RESPONSE);
+		if (rc < 0)
+			return rc;
+
+		rc = snprintf(data, 3, "%02x", rc);
+		break;
+	case Q54SJ108A2_DEBUGFS_PMBUS_VERSION:
+		rc = i2c_smbus_read_byte_data(psu->client, PMBUS_REVISION);
+		if (rc < 0)
+			return rc;
+
+		rc = snprintf(data, 3, "%02x", rc);
+		break;
+	case Q54SJ108A2_DEBUGFS_MFR_ID:
+		rc = i2c_smbus_read_block_data(psu->client, PMBUS_MFR_ID, data);
+		if (rc < 0)
+			return rc;
+		break;
+	case Q54SJ108A2_DEBUGFS_MFR_MODEL:
+		rc = i2c_smbus_read_block_data(psu->client, PMBUS_MFR_MODEL, data);
+		if (rc < 0)
+			return rc;
+		break;
+	case Q54SJ108A2_DEBUGFS_MFR_REVISION:
+		rc = i2c_smbus_read_block_data(psu->client, PMBUS_MFR_REVISION, data);
+		if (rc < 0)
+			return rc;
+		break;
+	case Q54SJ108A2_DEBUGFS_MFR_LOCATION:
+		rc = i2c_smbus_read_block_data(psu->client, PMBUS_MFR_LOCATION, data);
+		if (rc < 0)
+			return rc;
+		break;
+	case Q54SJ108A2_DEBUGFS_BLACKBOX_READ_OFFSET:
+		rc = i2c_smbus_read_byte_data(psu->client, READ_HISTORY_EVENT_NUMBER);
+		if (rc < 0)
+			return rc;
+
+		rc = snprintf(data, 3, "%02x", rc);
+		break;
+	case Q54SJ108A2_DEBUGFS_BLACKBOX_READ:
+		rc = i2c_smbus_read_block_data(psu->client, READ_HISTORY_EVENTS, data);
+		if (rc < 0)
+			return rc;
+
+		res = bin2hex(data, data_char, 32);
+		rc = res - data;
+
+		break;
+	case Q54SJ108A2_DEBUGFS_FLASH_KEY:
+		rc = i2c_smbus_read_block_data(psu->client, PMBUS_CMD_FLASH_KEY_WRITE, data);
+		if (rc < 0)
+			return rc;
+
+		res = bin2hex(data, data_char, 4);
+		rc = res - data;
+
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	data[rc] = '\n';
+	rc += 2;
+
+	return simple_read_from_buffer(buf, count, ppos, data, rc);
+}
+
+static ssize_t q54sj108a2_debugfs_write(struct file *file, const char __user *buf,
+					size_t count, loff_t *ppos)
+{
+	u8 flash_key[4];
+	u8 dst_data;
+	ssize_t rc;
+	int *idxp = file->private_data;
+	int idx = *idxp;
+	struct q54sj108a2_data *psu = to_psu(idxp, idx);
+
+	rc = i2c_smbus_write_byte_data(psu->client, PMBUS_WRITE_PROTECT, 0);
+	if (rc)
+		return rc;
+
+	switch (idx) {
+	case Q54SJ108A2_DEBUGFS_OPERATION:
+		rc = kstrtou8_from_user(buf, count, 0, &dst_data);
+		if (rc < 0)
+			return rc;
+
+		rc = i2c_smbus_write_byte_data(psu->client, PMBUS_OPERATION, dst_data);
+		if (rc < 0)
+			return rc;
+
+		break;
+	case Q54SJ108A2_DEBUGFS_CLEARFAULT:
+		rc = i2c_smbus_write_byte(psu->client, PMBUS_CLEAR_FAULTS);
+		if (rc < 0)
+			return rc;
+
+		break;
+	case Q54SJ108A2_DEBUGFS_STOREDEFAULT:
+		flash_key[0] = 0x7E;
+		flash_key[1] = 0x15;
+		flash_key[2] = 0xDC;
+		flash_key[3] = 0x42;
+		rc = i2c_smbus_write_block_data(psu->client, PMBUS_CMD_FLASH_KEY_WRITE, 4, flash_key);
+		if (rc < 0)
+			return rc;
+
+		rc = i2c_smbus_write_byte(psu->client, STORE_DEFAULT_ALL);
+		if (rc < 0)
+			return rc;
+
+		break;
+	case Q54SJ108A2_DEBUGFS_VOOV_RESPONSE:
+		rc = kstrtou8_from_user(buf, count, 0, &dst_data);
+		if (rc < 0)
+			return rc;
+
+		rc = i2c_smbus_write_byte_data(psu->client, PMBUS_VOUT_OV_FAULT_RESPONSE, dst_data);
+		if (rc < 0)
+			return rc;
+
+		break;
+	case Q54SJ108A2_DEBUGFS_IOOC_RESPONSE:
+		rc = kstrtou8_from_user(buf, count, 0, &dst_data);
+		if (rc < 0)
+			return rc;
+
+		rc = i2c_smbus_write_byte_data(psu->client, PMBUS_IOUT_OC_FAULT_RESPONSE, dst_data);
+		if (rc < 0)
+			return rc;
+
+		break;
+	case Q54SJ108A2_DEBUGFS_BLACKBOX_ERASE:
+		rc = i2c_smbus_write_byte(psu->client, ERASE_BLACKBOX_DATA);
+		if (rc < 0)
+			return rc;
+
+		break;
+	case Q54SJ108A2_DEBUGFS_BLACKBOX_SET_OFFSET:
+		rc = kstrtou8_from_user(buf, count, 0, &dst_data);
+		if (rc < 0)
+			return rc;
+
+		rc = i2c_smbus_write_byte_data(psu->client, SET_HISTORY_EVENT_OFFSET, dst_data);
+		if (rc < 0)
+			return rc;
+
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return count;
+}
+
+static const struct file_operations q54sj108a2_fops = {
+	.llseek = noop_llseek,
+	.read = q54sj108a2_debugfs_read,
+	.write = q54sj108a2_debugfs_write,
+	.open = simple_open,
+};
+
+static const struct i2c_device_id q54sj108a2_id[] = {
+	{ "Q54SJ108A2", Q54SJ108A2 },
+	{ },
+};
+
+MODULE_DEVICE_TABLE(i2c, q54sj108a2_id);
+
+static int q54sj108a2_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	u8 buf[I2C_SMBUS_BLOCK_MAX + 1];
+	enum chips chip_id;
+	int ret, i;
+	struct dentry *debugfs;
+	struct dentry *q54sj108a2_dir;

drivers/hwmon/pmbus/q54sj108a2.c line 293

Quoted 10 lines
drivers/hwmon/pmbus/q54sj108a2.c new file +10 -0
+	struct q54sj108a2_data *psu;
+
+	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);

As reported by 0-day, this doesn't work. It needs a cast to unsigned long, or a double cast, such as

		chip_id = (enum chips)(unsigned long)of_device_get_match_data(dev);
Quoted 30 lines
drivers/hwmon/pmbus/q54sj108a2.c new file +30 -0
+	else
+		chip_id = i2c_match_id(q54sj108a2_id, client)->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) {

drivers/hwmon/pmbus/q54sj108a2.c line 333

Quoted 10 lines
drivers/hwmon/pmbus/q54sj108a2.c new file +10 -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;
+	}
+
+	ret = pmbus_do_probe(client, &q54sj108a2_id[chip_id], &q54sj108a2_info[chip_id]);

The parameters for this function have changed. Please rebase your patch.

Quoted 89 lines
drivers/hwmon/pmbus/q54sj108a2.c new file +89 -0
+	if (ret)
+		return ret;
+
+	psu = devm_kzalloc(&client->dev, sizeof(*psu), GFP_KERNEL);
+	if (!psu)
+		return 0;
+
+	psu->client = client;
+
+	debugfs = pmbus_get_debugfs_dir(client);
+
+	q54sj108a2_dir = debugfs_create_dir(client->name, debugfs);
+
+	for (i = 0; i < Q54SJ108A2_DEBUGFS_NUM_ENTRIES; ++i)
+		psu->debugfs_entries[i] = i;
+
+	debugfs_create_file("operation", 0644, q54sj108a2_dir,
+			    &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_OPERATION],
+			    &q54sj108a2_fops);
+	debugfs_create_file("clear_fault", 0200, q54sj108a2_dir,
+			    &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_CLEARFAULT],
+			    &q54sj108a2_fops);
+	debugfs_create_file("write_protect", 0444, q54sj108a2_dir,
+			    &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_WRITEPROTECT],
+			    &q54sj108a2_fops);
+	debugfs_create_file("store_default", 0200, q54sj108a2_dir,
+			    &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_STOREDEFAULT],
+			    &q54sj108a2_fops);
+	debugfs_create_file("vo_ov_response", 0644, q54sj108a2_dir,
+			    &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_VOOV_RESPONSE],
+			    &q54sj108a2_fops);
+	debugfs_create_file("io_oc_response", 0644, q54sj108a2_dir,
+			    &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_IOOC_RESPONSE],
+			    &q54sj108a2_fops);
+	debugfs_create_file("pmbus_revision", 0444, q54sj108a2_dir,
+			    &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_PMBUS_VERSION],
+			    &q54sj108a2_fops);
+	debugfs_create_file("mfr_id", 0444, q54sj108a2_dir,
+			    &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_MFR_ID],
+			    &q54sj108a2_fops);
+	debugfs_create_file("mfr_model", 0444, q54sj108a2_dir,
+			    &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_MFR_MODEL],
+			    &q54sj108a2_fops);
+	debugfs_create_file("mfr_revision", 0444, q54sj108a2_dir,
+			    &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_MFR_REVISION],
+			    &q54sj108a2_fops);
+	debugfs_create_file("mfr_location", 0444, q54sj108a2_dir,
+			    &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_MFR_LOCATION],
+			    &q54sj108a2_fops);
+	debugfs_create_file("blackbox_erase", 0200, q54sj108a2_dir,
+			    &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_BLACKBOX_ERASE],
+			    &q54sj108a2_fops);
+	debugfs_create_file("blackbox_read_offset", 0444, q54sj108a2_dir,
+			    &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_BLACKBOX_READ_OFFSET],
+			    &q54sj108a2_fops);
+	debugfs_create_file("blackbox_set_offset", 0200, q54sj108a2_dir,
+			    &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_BLACKBOX_SET_OFFSET],
+			    &q54sj108a2_fops);
+	debugfs_create_file("blackbox_read", 0444, q54sj108a2_dir,
+			    &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_BLACKBOX_READ],
+			    &q54sj108a2_fops);
+	debugfs_create_file("flash_key", 0444, q54sj108a2_dir,
+			    &psu->debugfs_entries[Q54SJ108A2_DEBUGFS_FLASH_KEY],
+			    &q54sj108a2_fops);
+
+	return 0;
+}
+
+static const struct of_device_id q54sj108a2_of_match[] = {
+	{ .compatible = "delta,Q54SJ108A2", .data = (void *)Q54SJ108A2 },
+	{ },
+};
+
+MODULE_DEVICE_TABLE(of, q54sj108a2_of_match);
+
+static struct i2c_driver q54sj108a2_driver = {
+	.driver = {
+		.name = "Q54SJ108A2",
+		.of_match_table = q54sj108a2_of_match,
+	},
+	.probe_new = q54sj108a2_probe,
+	.id_table = q54sj108a2_id,
+};
+
+module_i2c_driver(q54sj108a2_driver);
+
+MODULE_AUTHOR("Xiao.Ma <[email protected]>");
+MODULE_DESCRIPTION("PMBus driver for Delta Q54SJ108A2 series modules");
+MODULE_LICENSE("GPL");