[RFT PATCH 3/3] hwmon: (spd5118) Add PEC support

From: Guenter Roeck
Date: Wed May 29 2024 - 16:52:52 EST


Add support for configuring PEC (Packet Error Checking).

Signed-off-by: Guenter Roeck <linux@xxxxxxxxxxxx>
---
This patch depends on the patch series at
https://patchwork.kernel.org/project/linux-hwmon/list/?series=857097

drivers/hwmon/spd5118.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/spd5118.c b/drivers/hwmon/spd5118.c
index 440503d09d13..eb21bf3dffd7 100644
--- a/drivers/hwmon/spd5118.c
+++ b/drivers/hwmon/spd5118.c
@@ -33,6 +33,7 @@ static const unsigned short normal_i2c[] = {
#define SPD5118_REG_VENDOR 0x03 /* MR3:MR4 */
#define SPD5118_REG_CAPABILITY 0x05 /* MR5 */
#define SPD5118_REG_I2C_LEGACY_MODE 0x0B /* MR11 */
+#define SPD5118_REG_DEV_CONFIG 0x12 /* MR18 */
#define SPD5118_REG_TEMP_CLR 0x13 /* MR19 */
#define SPD5118_REG_ERROR_CLR 0x14 /* MR20 */
#define SPD5118_REG_TEMP_CONFIG 0x1A /* MR26 */
@@ -50,6 +51,8 @@ static const unsigned short normal_i2c[] = {

#define SPD5118_CAP_TS_SUPPORT BIT(1) /* temperature sensor support */

+#define SPD5118_PEC_ENABLE BIT(7) /* PEC enable */
+
#define SPD5118_TS_DISABLE BIT(0) /* temperature sensor disable */

/* Temperature unit in millicelsius */
@@ -217,6 +220,18 @@ static int spd5118_write_enable(struct regmap *regmap, u32 attr, long val)
val ? 0 : SPD5118_TS_DISABLE);
}

+static int spd5118_chip_write(struct regmap *regmap, u32 attr, long val)
+{
+ switch (attr) {
+ case hwmon_chip_pec:
+ return regmap_update_bits(regmap, SPD5118_REG_DEV_CONFIG,
+ SPD5118_PEC_ENABLE,
+ val ? SPD5118_PEC_ENABLE : 0);
+ default:
+ return -EOPNOTSUPP;
+ }
+}
+
static int spd5118_temp_write(struct regmap *regmap, u32 attr, long val)
{
switch (attr) {
@@ -238,6 +253,8 @@ static int spd5118_write(struct device *dev, enum hwmon_sensor_types type,
struct regmap *regmap = dev_get_drvdata(dev);

switch (type) {
+ case hwmon_chip:
+ return spd5118_chip_write(regmap, attr, val);
case hwmon_temp:
return spd5118_temp_write(regmap, attr, val);
default:
@@ -338,7 +355,7 @@ static int spd5118_detect(struct i2c_client *client, struct i2c_board_info *info

static const struct hwmon_channel_info *spd5118_info[] = {
HWMON_CHANNEL_INFO(chip,
- HWMON_C_REGISTER_TZ),
+ HWMON_C_REGISTER_TZ | HWMON_C_PEC),
HWMON_CHANNEL_INFO(temp,
HWMON_T_INPUT |
HWMON_T_LCRIT | HWMON_T_LCRIT_ALARM |
--
2.39.2