Skip to content

Commit a2981c2

Browse files
cpackham-atlnzgroeck
authored andcommitted
hwmon: pmbus: Add support for Sony APS-379
Add pmbus support for Sony APS-379 power supplies. There are a few PMBUS commands that return data that is undocumented/invalid so these need to be rejected with -ENXIO. The READ_VOUT command returns data in linear11 format instead of linear16 so we need to workaround this. Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz> Link: https://lore.kernel.org/r/20260410012414.2818829-3-chris.packham@alliedtelesis.co.nz [groeck: Dropped empty line from documentation; added module name to Kconfig] Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent 502a498 commit a2981c2

5 files changed

Lines changed: 223 additions & 0 deletions

File tree

Documentation/hwmon/aps-379.rst

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Kernel driver aps-379
2+
=====================
3+
4+
Supported chips:
5+
6+
* Sony APS-379
7+
8+
Prefix: 'aps-379'
9+
10+
Addresses scanned: -
11+
12+
Authors:
13+
- Chris Packham
14+
15+
Description
16+
-----------
17+
18+
This driver implements support for the PMBus monitor on the Sony APS-379
19+
modular power supply. The APS-379 deviates from the PMBus standard for the
20+
READ_VOUT command by using the linear11 format instead of linear16.
21+
22+
The known supported PMBus commands are:
23+
24+
=== ============================= ========= ======= =====
25+
Cmd Function Protocol Scaling Bytes
26+
=== ============================= ========= ======= =====
27+
01 On / Off Command (OPERATION) Byte R/W -- 1
28+
10 WRITE_PROTECT Byte R/W -- 1
29+
3B FAN_COMMAND_1 Word R/W -- 2
30+
46 Current Limit (in percent) Word R/W 2^0 2
31+
47 Current Limit Fault Response Byte R/W -- 1
32+
79 Alarm Data Bits (STATUS_WORD) Word Rd -- 2
33+
8B Output Voltage (READ_VOUT) Word Rd 2^-4 2
34+
8C Output Current (READ_IOUT) Word Rd 2^-2 2
35+
8D Power Supply Ambient Temp Word Rd 2^0 2
36+
90 READ_FAN_SPEED_1 Word Rd 2^6 2
37+
91 READ_FAN_SPEED_2 Word Rd 2^6 2
38+
96 Output Wattage (READ_POUT) Word Rd 2^1 2
39+
97 Input Wattage (READ_PIN) Word Rd 2^1 2
40+
9A Unit Model Number (MFR_MODEL) Block R/W -- 10
41+
9B Unit Revision Number Block R/W -- 10
42+
9E Unit Serial Number Block R/W -- 8
43+
99 Unit Manufacturer ID (MFR_ID) Block R/W -- 8
44+
D0 Unit Run Time Information Block Rd -- 4
45+
D5 Firmware Version Rd cust -- 8
46+
B0 User Data 1 (USER_DATA_00) Block R/W -- 4
47+
B1 User Data 2 (USER_DATA_01) Block R/W -- 4
48+
B2 User Data 3 (USER_DATA_02) Block R/W -- 4
49+
B3 User Data 4 (USER_DATA_03) Block R/W -- 4
50+
B4 User Data 5 (USER_DATA_04) Block R/W -- 4
51+
B5 User Data 6 (USER_DATA_05) Block R/W -- 4
52+
B6 User Data 7 (USER_DATA_06) Block R/W -- 4
53+
B7 User Data 8 (USER_DATA_07) Block R/W -- 4
54+
F0 Calibration command Byte R/W -- 1
55+
F1 Calibration data Word Wr 2^9 2
56+
F2 Unlock Calibration Byte Wr -- 1
57+
=== ============================= ========= ======= =====

Documentation/hwmon/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Hardware Monitoring Kernel Drivers
4141
adt7475
4242
aht10
4343
amc6821
44+
aps-379
4445
aquacomputer_d5next
4546
asb100
4647
asc7621

drivers/hwmon/pmbus/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ config SENSORS_ADP1050_REGULATOR
7777
µModule regulators that can provide microprocessor power from 54V
7878
power distribution architecture.
7979

80+
config SENSORS_APS_379
81+
tristate "Sony APS-379 Power Supplies"
82+
help
83+
If you say yes here you get hardware monitoring support for Sony
84+
APS-379 Power Supplies.
85+
86+
This driver can also be built as a module. If so, the module will
87+
be called aps-379.
88+
8089
config SENSORS_BEL_PFE
8190
tristate "Bel PFE Compatible Power Supplies"
8291
help

drivers/hwmon/pmbus/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ obj-$(CONFIG_SENSORS_ACBEL_FSG032) += acbel-fsg032.o
99
obj-$(CONFIG_SENSORS_ADM1266) += adm1266.o
1010
obj-$(CONFIG_SENSORS_ADM1275) += adm1275.o
1111
obj-$(CONFIG_SENSORS_ADP1050) += adp1050.o
12+
obj-$(CONFIG_SENSORS_APS_379) += aps-379.o
1213
obj-$(CONFIG_SENSORS_BEL_PFE) += bel-pfe.o
1314
obj-$(CONFIG_SENSORS_BPA_RS600) += bpa-rs600.o
1415
obj-$(CONFIG_SENSORS_DELTA_AHE50DC_FAN) += delta-ahe50dc-fan.o

drivers/hwmon/pmbus/aps-379.c

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* Hardware monitoring driver for Sony APS-379 Power Supplies
4+
*
5+
* Copyright 2026 Allied Telesis Labs
6+
*/
7+
8+
#include <linux/i2c.h>
9+
#include <linux/init.h>
10+
#include <linux/kernel.h>
11+
#include <linux/module.h>
12+
#include <linux/pmbus.h>
13+
#include "pmbus.h"
14+
15+
/*
16+
* The VOUT format used by the chip is linear11, not linear16. Provide a hard
17+
* coded VOUT_MODE that says VOUT is in linear mode with a fixed exponent of
18+
* 2^-4.
19+
*/
20+
#define APS_379_VOUT_MODE ((u8)(-4 & 0x1f))
21+
22+
static int aps_379_read_byte_data(struct i2c_client *client, int page, int reg)
23+
{
24+
switch (reg) {
25+
case PMBUS_VOUT_MODE:
26+
return APS_379_VOUT_MODE;
27+
default:
28+
return -ENODATA;
29+
}
30+
}
31+
32+
/*
33+
* The APS-379 uses linear11 format instead of linear16. We've reported the exponent
34+
* via the PMBUS_VOUT_MODE so we just return the mantissa here.
35+
*/
36+
static int aps_379_read_vout(struct i2c_client *client)
37+
{
38+
int ret;
39+
40+
ret = pmbus_read_word_data(client, 0, 0xff, PMBUS_READ_VOUT);
41+
if (ret < 0)
42+
return ret;
43+
44+
return clamp_val(sign_extend32(ret & 0x7ff, 10), 0, 0x3ff);
45+
}
46+
47+
static int aps_379_read_word_data(struct i2c_client *client, int page, int phase, int reg)
48+
{
49+
switch (reg) {
50+
case PMBUS_VOUT_UV_WARN_LIMIT:
51+
case PMBUS_VOUT_OV_WARN_LIMIT:
52+
case PMBUS_VOUT_UV_FAULT_LIMIT:
53+
case PMBUS_VOUT_OV_FAULT_LIMIT:
54+
case PMBUS_IOUT_OC_WARN_LIMIT:
55+
case PMBUS_IOUT_UC_FAULT_LIMIT:
56+
case PMBUS_UT_WARN_LIMIT:
57+
case PMBUS_UT_FAULT_LIMIT:
58+
case PMBUS_OT_WARN_LIMIT:
59+
case PMBUS_OT_FAULT_LIMIT:
60+
case PMBUS_PIN_OP_WARN_LIMIT:
61+
case PMBUS_POUT_OP_WARN_LIMIT:
62+
case PMBUS_MFR_IIN_MAX:
63+
case PMBUS_MFR_PIN_MAX:
64+
case PMBUS_MFR_VOUT_MIN:
65+
case PMBUS_MFR_VOUT_MAX:
66+
case PMBUS_MFR_IOUT_MAX:
67+
case PMBUS_MFR_POUT_MAX:
68+
case PMBUS_MFR_MAX_TEMP_1:
69+
/* These commands return data but it is invalid/un-documented */
70+
return -ENXIO;
71+
case PMBUS_IOUT_OC_FAULT_LIMIT:
72+
/*
73+
* The standard requires this to be a value in Amps but it's
74+
* actually a percentage of the rated output (123A for
75+
* 110-240Vac, 110A for 90-100Vac) which we don't know. Ignore
76+
* it rather than guessing.
77+
*/
78+
return -ENXIO;
79+
case PMBUS_READ_VOUT:
80+
return aps_379_read_vout(client);
81+
default:
82+
return -ENODATA;
83+
}
84+
}
85+
86+
static struct pmbus_driver_info aps_379_info = {
87+
.pages = 1,
88+
.format[PSC_VOLTAGE_OUT] = linear,
89+
.format[PSC_CURRENT_OUT] = linear,
90+
.format[PSC_POWER] = linear,
91+
.format[PSC_TEMPERATURE] = linear,
92+
.format[PSC_FAN] = linear,
93+
.func[0] = PMBUS_HAVE_VOUT |
94+
PMBUS_HAVE_IOUT |
95+
PMBUS_HAVE_PIN | PMBUS_HAVE_POUT |
96+
PMBUS_HAVE_TEMP |
97+
PMBUS_HAVE_FAN12,
98+
.read_byte_data = aps_379_read_byte_data,
99+
.read_word_data = aps_379_read_word_data,
100+
};
101+
102+
static const struct i2c_device_id aps_379_id[] = {
103+
{ "aps-379", 0 },
104+
{},
105+
};
106+
MODULE_DEVICE_TABLE(i2c, aps_379_id);
107+
108+
static int aps_379_probe(struct i2c_client *client)
109+
{
110+
struct device *dev = &client->dev;
111+
u8 buf[I2C_SMBUS_BLOCK_MAX + 1] = { 0 };
112+
int ret;
113+
114+
if (!i2c_check_functionality(client->adapter,
115+
I2C_FUNC_SMBUS_READ_BYTE_DATA
116+
| I2C_FUNC_SMBUS_READ_WORD_DATA
117+
| I2C_FUNC_SMBUS_READ_BLOCK_DATA))
118+
return -ENODEV;
119+
120+
ret = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, buf);
121+
if (ret < 0) {
122+
dev_err(dev, "Failed to read Manufacturer Model\n");
123+
return ret;
124+
}
125+
126+
if (strncasecmp(buf, aps_379_id[0].name, strlen(aps_379_id[0].name)) != 0) {
127+
buf[ret] = '\0';
128+
dev_err(dev, "Unsupported Manufacturer Model '%s'\n", buf);
129+
return -ENODEV;
130+
}
131+
132+
return pmbus_do_probe(client, &aps_379_info);
133+
}
134+
135+
static const struct of_device_id __maybe_unused aps_379_of_match[] = {
136+
{ .compatible = "sony,aps-379" },
137+
{},
138+
};
139+
MODULE_DEVICE_TABLE(of, aps_379_of_match);
140+
141+
static struct i2c_driver aps_379_driver = {
142+
.driver = {
143+
.name = "aps-379",
144+
.of_match_table = of_match_ptr(aps_379_of_match),
145+
},
146+
.probe = aps_379_probe,
147+
.id_table = aps_379_id,
148+
};
149+
150+
module_i2c_driver(aps_379_driver);
151+
152+
MODULE_AUTHOR("Chris Packham");
153+
MODULE_DESCRIPTION("PMBus driver for Sony APS-379");
154+
MODULE_LICENSE("GPL");
155+
MODULE_IMPORT_NS("PMBUS");

0 commit comments

Comments
 (0)