Linux-Hwmon Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] hwmon: (pmbus) add VR12/VR13 mode support write paths
@ 2019-10-01 16:03 Patrick Williams
       [not found] ` <20191001230210.GA15354@roeck-us.net>
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Williams @ 2019-10-01 16:03 UTC (permalink / raw)
  To: unlisted-recipients:; (no To-header on input)
  Cc: Patrick Williams, Patrick Williams, Guenter Roeck, Jean Delvare,
	linux-hwmon, linux-kernel

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)


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] hwmon: (pmbus) add VR12/VR13 mode support write paths
       [not found] ` <20191001230210.GA15354@roeck-us.net>
@ 2019-10-02  2:45   ` Patrick Williams
  0 siblings, 0 replies; 2+ messages in thread
From: Patrick Williams @ 2019-10-02  2:45 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Patrick Williams, Jean Delvare, linux-hwmon, linux-kernel

---- On Tue, 01 Oct 2019 16:02:10 -0700 Guenter Roeck <linux@roeck-us.net> wrote ----
 
 > > -    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; 
 >  
 > Both vr12 and vr13 converts low values into negative values, 
 > which are then converted into more or less random register 
 > values. That can not be correct. The resulting register values 
 > must always be valid. 
 >  
 > Guenter 

Thanks for catching this.  It may be as simple as me adjusting the lower
bound on the clamp_val.  I’ll check with one of the device specs and
confirm the appropriate behavior on the lower bounds.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-01 16:03 [PATCH] hwmon: (pmbus) add VR12/VR13 mode support write paths Patrick Williams
     [not found] ` <20191001230210.GA15354@roeck-us.net>
2019-10-02  2:45   ` Patrick Williams

Linux-Hwmon Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-hwmon/0 linux-hwmon/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-hwmon linux-hwmon/ https://lore.kernel.org/linux-hwmon \
		linux-hwmon@vger.kernel.org
	public-inbox-index linux-hwmon

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-hwmon


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git