linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Williams <alpawi@amazon.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Patrick Williams <alpawi@amazon.com>,
	Patrick Williams <patrick@stwcx.xyz>,
	Guenter Roeck <linux@roeck-us.net>,
	Jean Delvare <jdelvare@suse.com>, <linux-hwmon@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH] hwmon: (pmbus) add VR12/VR13 mode support write paths
Date: Tue, 1 Oct 2019 11:03:41 -0500	[thread overview]
Message-ID: <20191001160407.6265-1-alpawi@amazon.com> (raw)

pmbus_core supported VR11/VR12/VR13 modes when reading
VID-formatted registers, but the write path only supported
VR11 translations.  Add support for VR12 and VR13 to
'data2reg_vid' for translating these formats.  This is the
inverse of 'reg2data_vid'.

Signed-off-by: Patrick Williams <alpawi@amazon.com>
---
 drivers/hwmon/pmbus/pmbus_core.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 8470097907bc..f0d696552142 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -845,9 +845,19 @@ static u16 pmbus_data2reg_direct(struct pmbus_data *data,
 static u16 pmbus_data2reg_vid(struct pmbus_data *data,
 			      struct pmbus_sensor *sensor, long val)
 {
-	val = clamp_val(val, 500, 1600);
+	switch (data->info->vrm_version) {
+	case vr11:
+		val = clamp_val(val, 500, 1600);
+		return 2 + DIV_ROUND_CLOSEST((1600 - val) * 100, 625);
+	case vr12:
+		val = clamp_val(val, 0, 1520);
+		return ((val - 250) / 5) + 1;
+	case vr13:
+		val = clamp_val(val, 0, 2500);
+		return ((val - 500) / 10) + 1;
+	}
 
-	return 2 + DIV_ROUND_CLOSEST((1600 - val) * 100, 625);
+	return 0;
 }
 
 static u16 pmbus_data2reg(struct pmbus_data *data,
-- 
2.17.2 (Apple Git-113)


             reply	other threads:[~2019-10-01 16:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-01 16:03 Patrick Williams [this message]
     [not found] ` <20191001230210.GA15354@roeck-us.net>
2019-10-02  2:45   ` [PATCH] hwmon: (pmbus) add VR12/VR13 mode support write paths Patrick Williams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191001160407.6265-1-alpawi@amazon.com \
    --to=alpawi@amazon.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=patrick@stwcx.xyz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).