Message ID | 20240130175140.3834889-1-naresh.solanki@9elements.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-45060-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1392708dyb; Tue, 30 Jan 2024 09:52:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IHz7yn2pmL9r3ZTapbPAD67Nl2L1pl2q91SjarXADtY8CUh8s5kujP1ctLmzk6bI9xi4/rG X-Received: by 2002:a9d:74d2:0:b0:6e1:7b0:fb99 with SMTP id a18-20020a9d74d2000000b006e107b0fb99mr5192362otl.21.1706637126672; Tue, 30 Jan 2024 09:52:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706637126; cv=pass; d=google.com; s=arc-20160816; b=dagonfo4pAR012onzoGnkbWT6er5x7khYNIwxlwYVXmLWy5xsPdtUXvZEuWrNUwg56 5MlF1coSwhyi0E9ZnIRzV1vNsO0SbgcUd2GEYI2QjPC4WRNON5LUT3j8gm2Ws5TYYUzg Nm1eldDxRIMrUtP5wVMnmSFXDCX2lm3mbV97gPkl+/EpGVWl2/zs6xS8CLCbJFNzIIbI 5FosOZVVU2vFl7+sojDI8QCf+83YKK967kMl/z8144885k9sdNXR+4sG9O5B3bpgHX85 hoPY3zC77gX2Dpx3yu+7J6D1vGfqwI65YZuibFo3xOBaeq/Db04QZidKe9fdfwF9n6b5 ZNUA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=bQgZSjsUgd4Ba/M69hqq/7iyLw1vdKJRuphfN6JZy2M=; fh=+erEFNyRoxoxliM3d6sLLptQyYs8GwGGfIC99190lfc=; b=FWJQ8DefeoVG4O+zNjnphce5OrjLZ3VidKz09cZh074k2NWd7RuhC9n3lTNLjMI8Mg pB2Wckixh0XGhBp69zIpvU9FtAnVD18HEn6jyXgU/PGajkuUf+cCC533A97L8e89OMT/ fcEqyKfiiquP2X/glXvi7p8eNcEGK3U6T8te/gO2DDcpbT1QOoE6lLMrGhWPvRz+IRrS XNQHuOmeqoScQkwsad/8meq1rGco3TdltcT3iWLoKSq/zyWrJosviyECSb+cdN/Vw81P kXtJxIgB30m0gAGUEv75WyBcUjgMWcMJC6LPzOXRKjZVJOPvcUmP33M72RKAzLlM6L+l II/g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@9elements.com header.s=google header.b=FXo8Lo5X; arc=pass (i=1 spf=pass spfdomain=9elements.com dkim=pass dkdomain=9elements.com dmarc=pass fromdomain=9elements.com); spf=pass (google.com: domain of linux-kernel+bounces-45060-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45060-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=9elements.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id c19-20020ac87dd3000000b0042b3fb09de9si1306359qte.209.2024.01.30.09.52.06 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 09:52:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45060-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@9elements.com header.s=google header.b=FXo8Lo5X; arc=pass (i=1 spf=pass spfdomain=9elements.com dkim=pass dkdomain=9elements.com dmarc=pass fromdomain=9elements.com); spf=pass (google.com: domain of linux-kernel+bounces-45060-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45060-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=9elements.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 6323F1C23DC7 for <ouuuleilei@gmail.com>; Tue, 30 Jan 2024 17:52:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C1A55151CE0; Tue, 30 Jan 2024 17:51:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=9elements.com header.i=@9elements.com header.b="FXo8Lo5X" Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0705150984 for <linux-kernel@vger.kernel.org>; Tue, 30 Jan 2024 17:51:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706637110; cv=none; b=QYF5ftddGTBgIuys0MP/BXm9fsW+t4AjBgHSgONwXfo9KB0Cra3ejfeI4lmID+acBPrwI6uGOf3oNyTMhk2mhl8xXwG8/14WTVViRyuy6/ZlF2442tf5djRvJVAhaV/zdtPN0NDLOA5Dqaxonnbvn/nyZ61jZXAkdWyjw57M6Qg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706637110; c=relaxed/simple; bh=E9+T3tYBO9u11qhS/NZ3oeL/SZ6kNpAatlkb1dP5uHE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ErwaQa1Ko/NTliJrlk9ZSy1KN4AD8zajsGFhdxEDnE09CpwZA5tpj3CDZLKyL5P0kPiwlpPHIkC70qrNokf4L3t2YRdKP6e1OIi45s2YdBdkTBje/elqCdQuY8kPXOU57kb4T/WYqIHeHMYOAEhB7G3xUbtC9tZBVr3Z4R5HbcA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=9elements.com; spf=pass smtp.mailfrom=9elements.com; dkim=pass (2048-bit key) header.d=9elements.com header.i=@9elements.com header.b=FXo8Lo5X; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=9elements.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=9elements.com Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-40ef6bbb61fso20808135e9.1 for <linux-kernel@vger.kernel.org>; Tue, 30 Jan 2024 09:51:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1706637107; x=1707241907; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=bQgZSjsUgd4Ba/M69hqq/7iyLw1vdKJRuphfN6JZy2M=; b=FXo8Lo5XHFPArGH7XdNbSeG6m94wLBWkS0cMlR5Qxxztn55JwrKn8foaxG0mf1HD5E FAMepnGfq7DrAGl8SaVc17bMxfQzDHytrXRhivcTGYUoUMOOVGWQoH0EEhbxgq1/JFbf 0IlH2aj9vQi05pPlE3tDxJrMxoKYYcSzGxk1jfsxyM/4SdpYARB11z2yNdlDlk0m81zJ hFs/aGgMpoMD2e/2LqV6vROuFutevastZJ/z7bTkbflwjDi1LAkiNrBwMTj4mrJPzMoV eJOeG4B3zebvl1DV2FGESTpdDmFtiapM1IclW/hPXQqqasdYXHf/gxsr6CbK+gJ1tSN4 nHkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706637107; x=1707241907; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bQgZSjsUgd4Ba/M69hqq/7iyLw1vdKJRuphfN6JZy2M=; b=R1NS0eKVO8nWQcDppZV3D7YvYTRMpvzjbpL0kYanW7t/LpALank+zI/P23FHBTlTa0 alg+Jjy9zBnogvSTSuRfbT2OC4yz9HCr/Kc2Lk9TqsXetIhNuLVbuch8glINvZJNAowy wnOQlZqwIlkIt2sR6OD7nPqq5Xn3dUcjSZWvFQxPBKxk0iYwAeie1X+nc4lkiUVYfd1Y NmFzi/xdB/qMUGwdWSCgqnOWJNAYTOsFosto5P0uOCuobTwI8FlFxkwilvUnydMGDWnE Tgljbb0eD7U98HPyYOb1uZDEDrh973BkB3cHHGm0wwr1fMqWJbeJ0OAeTcDcnd2hTZhX 7PiA== X-Gm-Message-State: AOJu0YytiExUfH/V5eyZrAP1wVcuahY0vYw0mXhCG8Y9ZlrMElSxpGvS Xq6pkRPLfDt8Nfc8qN2quoIqxj0Tv31GW5T6gugoqqZxQJMKFuD/r1GXKLfazM4= X-Received: by 2002:a5d:6548:0:b0:33a:ff6f:744e with SMTP id z8-20020a5d6548000000b0033aff6f744emr251359wrv.18.1706637106872; Tue, 30 Jan 2024 09:51:46 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXe027gc5jc7b7mo5fZ7+wqLld2L87UtaW+lp4OjMxnTSjXWMWLUAtL5y5akavrqFrHLMXNHo2RgESd5wfzS7pimRcRYX5ia3+MwlfQwvlAljqyOvWDWzqXMapHMGZO0pKYf4gqjixpovVSPvp2lyPgPMJEdDUBo6Rq/okJ9nMVh8LtR/pqTrpXvwlvnEWuHB5pijzHIjA1WFO2GsmD86QhikLuodMROUp0Y/4zKb3VP/33VF/PAz4R2A== Received: from stroh80.sec.9e.network (ip-078-094-000-051.um19.pools.vodafone-ip.de. [78.94.0.51]) by smtp.gmail.com with ESMTPSA id fm25-20020a05600c0c1900b0040e3bdff98asm17788748wmb.23.2024.01.30.09.51.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 09:51:46 -0800 (PST) From: Naresh Solanki <naresh.solanki@9elements.com> To: Guenter Roeck <linux@roeck-us.net>, Jean Delvare <jdelvare@suse.com> Cc: mazziesaccount@gmail.com, Patrick Rudolph <patrick.rudolph@9elements.com>, Naresh Solanki <naresh.solanki@9elements.com>, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] hwmon: (pmbus/mp2975) Fix IRQ masking Date: Tue, 30 Jan 2024 23:21:39 +0530 Message-ID: <20240130175140.3834889-1-naresh.solanki@9elements.com> X-Mailer: git-send-email 2.42.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789538731686044291 X-GMAIL-MSGID: 1789538731686044291 |
Series |
hwmon: (pmbus/mp2975) Fix IRQ masking
|
|
Commit Message
Naresh Solanki
Jan. 30, 2024, 5:51 p.m. UTC
From: Patrick Rudolph <patrick.rudolph@9elements.com> The MP2971/MP2973 use a custom 16bit register format for SMBALERT_MASK which doesn't follow the PMBUS specification. Map the PMBUS defined bits used by the common code onto the custom format used by MPS and since the SMBALERT_MASK is currently never read by common code only implement the mapping for write transactions. Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com> Signed-off-by: Naresh Solanki <naresh.solanki@9elements.com> --- drivers/hwmon/pmbus/mp2975.c | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) base-commit: 909d8d33f8b4664c9b6c7fd585114921af77fc2b
Comments
On Tue, Jan 30, 2024 at 11:21:39PM +0530, Naresh Solanki wrote: > From: Patrick Rudolph <patrick.rudolph@9elements.com> > > The MP2971/MP2973 use a custom 16bit register format for > SMBALERT_MASK which doesn't follow the PMBUS specification. > > Map the PMBUS defined bits used by the common code onto the custom > format used by MPS and since the SMBALERT_MASK is currently never read > by common code only implement the mapping for write transactions. > > Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com> > Signed-off-by: Naresh Solanki <naresh.solanki@9elements.com> > --- > drivers/hwmon/pmbus/mp2975.c | 57 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 57 insertions(+) > > > base-commit: 909d8d33f8b4664c9b6c7fd585114921af77fc2b > > diff --git a/drivers/hwmon/pmbus/mp2975.c b/drivers/hwmon/pmbus/mp2975.c > index b9bb469e2d8f..788ec2c5a45f 100644 > --- a/drivers/hwmon/pmbus/mp2975.c > +++ b/drivers/hwmon/pmbus/mp2975.c > @@ -377,6 +377,62 @@ static int mp2973_read_word_data(struct i2c_client *client, int page, > return ret; > } > > +static int mp2973_write_word_data(struct i2c_client *client, int page, > + int reg, u16 word) > +{ > + u8 target, mask; > + int ret; > + > + if (reg != PMBUS_SMBALERT_MASK) > + return -ENODATA; > + > + /* > + * Vendor-specific SMBALERT_MASK register with 16 maskable bits. > + */ > + ret = pmbus_read_word_data(client, 0, 0, PMBUS_SMBALERT_MASK); > + if (ret < 0) > + return ret; > + > + target = word & 0xff; > + mask = word >> 8; > + > +#define SWAP(cond, bit) (ret = (cond) ? (ret & ~BIT(bit)) : (ret | BIT(bit))) This isn't really a "SWAP", but setting or clearing of bits in "ret" depending on a bit set in "cond". I don't have a good idea for a better name, but either case I think a comment describing what it does would be useful. "ret" use is implied, but "mask" is always provided as parameter. Please either provide both as arguments, or make both implied. Also, the first parameter is a bit mask, while the second parameter is a bit position. Please used defines for the second parameter and make it a mask as well. > + switch (target) { > + case PMBUS_STATUS_CML: > + SWAP(mask & PB_CML_FAULT_INVALID_DATA, 8); > + SWAP(mask & PB_CML_FAULT_INVALID_COMMAND, 9); > + SWAP(mask & PB_CML_FAULT_OTHER_COMM, 5); > + SWAP(mask & PB_CML_FAULT_PACKET_ERROR, 7); > + break; > + case PMBUS_STATUS_VOUT: > + SWAP(mask & PB_VOLTAGE_UV_FAULT, 13); > + SWAP(mask & PB_VOLTAGE_OV_FAULT, 14); > + break; > + case PMBUS_STATUS_IOUT: > + SWAP(mask & PB_IOUT_OC_FAULT, 11); > + SWAP(mask & PB_IOUT_OC_LV_FAULT, 10); > + break; > + case PMBUS_STATUS_TEMPERATURE: > + SWAP(mask & PB_TEMP_OT_FAULT, 0); > + break; > + /* > + * Map remaining bits to MFR specific to let the PMBUS core mask > + * those bits by default. > + */ > + case PMBUS_STATUS_MFR_SPECIFIC: > + SWAP(mask & BIT(1), 1); > + SWAP(mask & BIT(3), 3); > + SWAP(mask & BIT(4), 4); > + SWAP(mask & BIT(6), 6); > + break; Coming back to using defines for the second parameter: The above bit positions appear to be purely random. Having defines for those bits will at least explain what is being masked (and hopefully explain why bit 2, 12, and 15 are not covered at all). For example, at least one other chip from the same vendor defines bit 6 as CRC_ERROR, and the matching status register bit is bit 4 (memory fault detected) in STATUS_CML. Also, it is unclear why the chip would not issue any alerts when warning limits are exceeded. Without knowing what the bits in SMBALERT_MASK mean it is impossible to validate if the above is correct and/or complete. Thanks, Guenter
Hi Guenter, On Wed, 31 Jan 2024 at 03:30, Guenter Roeck <linux@roeck-us.net> wrote: > > On Tue, Jan 30, 2024 at 11:21:39PM +0530, Naresh Solanki wrote: > > From: Patrick Rudolph <patrick.rudolph@9elements.com> > > > > The MP2971/MP2973 use a custom 16bit register format for > > SMBALERT_MASK which doesn't follow the PMBUS specification. > > > > Map the PMBUS defined bits used by the common code onto the custom > > format used by MPS and since the SMBALERT_MASK is currently never read > > by common code only implement the mapping for write transactions. > > > > Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com> > > Signed-off-by: Naresh Solanki <naresh.solanki@9elements.com> > > --- > > drivers/hwmon/pmbus/mp2975.c | 57 ++++++++++++++++++++++++++++++++++++ > > 1 file changed, 57 insertions(+) > > > > > > base-commit: 909d8d33f8b4664c9b6c7fd585114921af77fc2b > > > > diff --git a/drivers/hwmon/pmbus/mp2975.c b/drivers/hwmon/pmbus/mp2975.c > > index b9bb469e2d8f..788ec2c5a45f 100644 > > --- a/drivers/hwmon/pmbus/mp2975.c > > +++ b/drivers/hwmon/pmbus/mp2975.c > > @@ -377,6 +377,62 @@ static int mp2973_read_word_data(struct i2c_client *client, int page, > > return ret; > > } > > > > +static int mp2973_write_word_data(struct i2c_client *client, int page, > > + int reg, u16 word) > > +{ > > + u8 target, mask; > > + int ret; > > + > > + if (reg != PMBUS_SMBALERT_MASK) > > + return -ENODATA; > > + > > + /* > > + * Vendor-specific SMBALERT_MASK register with 16 maskable bits. > > + */ > > + ret = pmbus_read_word_data(client, 0, 0, PMBUS_SMBALERT_MASK); > > + if (ret < 0) > > + return ret; > > + > > + target = word & 0xff; > > + mask = word >> 8; > > + > > +#define SWAP(cond, bit) (ret = (cond) ? (ret & ~BIT(bit)) : (ret | BIT(bit))) > > This isn't really a "SWAP", but setting or clearing of bits in "ret" > depending on a bit set in "cond". I don't have a good idea for a > better name, but either case I think a comment describing what it > does would be useful. Yes. will add below comment /* * Set/Clear 'bit' in 'ret' based on condition */ > > "ret" use is implied, but "mask" is always provided as parameter. > Please either provide both as arguments, or make both implied. Sure. Will update as: #define SWAP(cond, bit) ret = (mask & cond) ? (ret & ~BIT(bit)) : (ret | BIT(bit)) > > Also, the first parameter is a bit mask, while the second parameter > is a bit position. Please used defines for the second parameter > and make it a mask as well. Sure will be adding defines for second parameter as well. #define MP2973_INVALID_DATA 8 #define MP2973_INVALID_COMMAND 9 #define MP2973_OTHER_COMM 5 #define MP2973_PACKET_ERROR 7 #define MP2973_VOLTAGE_UV 13 #define MP2973_VOLTAGE_OV 14 #define MP2973_IOUT_OC 11 #define MP2973_IOUT_OC_LV 10 #define MP2973_TEMP_OT 0 > > > + switch (target) { > > + case PMBUS_STATUS_CML: > > + SWAP(mask & PB_CML_FAULT_INVALID_DATA, 8); > > + SWAP(mask & PB_CML_FAULT_INVALID_COMMAND, 9); > > + SWAP(mask & PB_CML_FAULT_OTHER_COMM, 5); > > + SWAP(mask & PB_CML_FAULT_PACKET_ERROR, 7); > > + break; > > + case PMBUS_STATUS_VOUT: > > + SWAP(mask & PB_VOLTAGE_UV_FAULT, 13); > > + SWAP(mask & PB_VOLTAGE_OV_FAULT, 14); > > + break; > > + case PMBUS_STATUS_IOUT: > > + SWAP(mask & PB_IOUT_OC_FAULT, 11); > > + SWAP(mask & PB_IOUT_OC_LV_FAULT, 10); > > + break; > > + case PMBUS_STATUS_TEMPERATURE: > > + SWAP(mask & PB_TEMP_OT_FAULT, 0); > > + break; > > + /* > > + * Map remaining bits to MFR specific to let the PMBUS core mask > > + * those bits by default. > > + */ > > + case PMBUS_STATUS_MFR_SPECIFIC: > > + SWAP(mask & BIT(1), 1); > > + SWAP(mask & BIT(3), 3); > > + SWAP(mask & BIT(4), 4); > > + SWAP(mask & BIT(6), 6); > > + break; > > Coming back to using defines for the second parameter: The > above bit positions appear to be purely random. Having defines for > those bits will at least explain what is being masked (and hopefully > explain why bit 2, 12, and 15 are not covered at all). > For example, at least one other chip from the same vendor defines > bit 6 as CRC_ERROR, and the matching status register bit is bit > 4 (memory fault detected) in STATUS_CML. Also, it is unclear why > the chip would not issue any alerts when warning limits are exceeded. > Without knowing what the bits in SMBALERT_MASK mean it is impossible > to validate if the above is correct and/or complete. Agree. Bit 2 & 15 are reserved & will add a comment to mention that. For others, I will add #define as below.. #define MP2973_VIN_UVLO 1 #define MP2973_VIN_OVP 3 #define MP2973_MTP_FAULT 4 #define MP2973_MTP_BLK_TRIG 6 #define MP2973_VOUT_MAX_MIN_WARNING 12 Regards, Naresh > > Thanks, > Guenter
diff --git a/drivers/hwmon/pmbus/mp2975.c b/drivers/hwmon/pmbus/mp2975.c index b9bb469e2d8f..788ec2c5a45f 100644 --- a/drivers/hwmon/pmbus/mp2975.c +++ b/drivers/hwmon/pmbus/mp2975.c @@ -377,6 +377,62 @@ static int mp2973_read_word_data(struct i2c_client *client, int page, return ret; } +static int mp2973_write_word_data(struct i2c_client *client, int page, + int reg, u16 word) +{ + u8 target, mask; + int ret; + + if (reg != PMBUS_SMBALERT_MASK) + return -ENODATA; + + /* + * Vendor-specific SMBALERT_MASK register with 16 maskable bits. + */ + ret = pmbus_read_word_data(client, 0, 0, PMBUS_SMBALERT_MASK); + if (ret < 0) + return ret; + + target = word & 0xff; + mask = word >> 8; + +#define SWAP(cond, bit) (ret = (cond) ? (ret & ~BIT(bit)) : (ret | BIT(bit))) + switch (target) { + case PMBUS_STATUS_CML: + SWAP(mask & PB_CML_FAULT_INVALID_DATA, 8); + SWAP(mask & PB_CML_FAULT_INVALID_COMMAND, 9); + SWAP(mask & PB_CML_FAULT_OTHER_COMM, 5); + SWAP(mask & PB_CML_FAULT_PACKET_ERROR, 7); + break; + case PMBUS_STATUS_VOUT: + SWAP(mask & PB_VOLTAGE_UV_FAULT, 13); + SWAP(mask & PB_VOLTAGE_OV_FAULT, 14); + break; + case PMBUS_STATUS_IOUT: + SWAP(mask & PB_IOUT_OC_FAULT, 11); + SWAP(mask & PB_IOUT_OC_LV_FAULT, 10); + break; + case PMBUS_STATUS_TEMPERATURE: + SWAP(mask & PB_TEMP_OT_FAULT, 0); + break; + /* + * Map remaining bits to MFR specific to let the PMBUS core mask + * those bits by default. + */ + case PMBUS_STATUS_MFR_SPECIFIC: + SWAP(mask & BIT(1), 1); + SWAP(mask & BIT(3), 3); + SWAP(mask & BIT(4), 4); + SWAP(mask & BIT(6), 6); + break; + default: + return 0; + } +#undef SWAP + + return pmbus_write_word_data(client, 0, PMBUS_SMBALERT_MASK, ret); +} + static int mp2975_read_word_data(struct i2c_client *client, int page, int phase, int reg) { @@ -891,6 +947,7 @@ static struct pmbus_driver_info mp2973_info = { PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP | PMBUS_HAVE_POUT | PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT, .read_word_data = mp2973_read_word_data, + .write_word_data = mp2973_write_word_data, #if IS_ENABLED(CONFIG_SENSORS_MP2975_REGULATOR) .num_regulators = 1, .reg_desc = mp2975_reg_desc,