ARM Sunxi Platform Development
 help / color / mirror / Atom feed
From: John Watts <contact@jookia.org>
To: Andre Przywara <andre.przywara@arm.com>
Cc: Chen-Yu Tsai <wens@csie.org>, Lee Jones <lee@kernel.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>, Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-sunxi@lists.linux.dev,
	Jernej Skrabec <jernej.skrabec@gmail.com>,
	Samuel Holland <samuel@sholland.org>,
	Ryan Walklin <ryan@testtoast.com>,
	Chris Morgan <macroalpha82@gmail.com>
Subject: Re: [PATCH 1/4] regulator: axp20x: AXP717: fix LDO supply rails and off-by-ones
Date: Tue, 16 Apr 2024 23:30:43 +1000	[thread overview]
Message-ID: <Zh59gzEB61lNdmMh@titan> (raw)
In-Reply-To: <20240416122305.3ffc2bda@donnerap.manchester.arm.com>

On Tue, Apr 16, 2024 at 12:23:05PM +0100, Andre Przywara wrote:
> On Sun, 14 Apr 2024 18:00:09 +1000
> John Watts <contact@jookia.org> wrote:
> 
> Hi John,
> 
> many thanks for the detailed review (also on the other two patches), much
> appreciated!

No problem!

> I see what you mean, though I actually looked at the number of steps
> mentioned in the first part of the register description. Now
> triple-checking this I came up with this table (generated by a spreadsheet
> to minimise human error):
> voltage	decimal	binary	
> 1600	88	1011000
> 1700	89	1011001
> 1800	90	1011010
> 1900	91	1011011
> 2000	92	1011100
> 2100	93	1011101
> 2200	94	1011110
> 2300	95	1011111
> 2400	96	1100000
> 2500	97	1100001
> 2600	98	1100010
> 2700	99	1100011
> 2800	100	1100100
> 2900	101	1100101
> 3000	102	1100110
> 3100	103	1100111
> 3200	104	1101000
> 3300	105	1101001
> 3400	106	1101010
> 
> Which means the final binary value in the datasheet is wrong, as 1101011
> would mean 3.5V.
> Also  1101010 = 106
>      -1011000 = 88
> =============
>       0010010 = 18
> and 18 * 100 + 1600 = 3400, right?
> 
> This *is* admittedly quite bonkers, especially since the representations
> between the manual and the code are so different, but can you check that
> this makes sense?

I wrote a program in Python that steps through each range and prints its
value, and according to it value 106 is 3.4V. I dumped it at the end of
this email for anyone curious. Your math checks out too.

So the datasheet must be wrong. Maybe it originally supported up to 3.5V
and someone who doesn't know binary updated the sheet.

I think you should add a note saying that the datasheet is wrong, to
show people this isn't a bug and also save time of others trying to
write their own drivers and check their logic. Something like this:

Warning, the datasheet specifies that 3.40V is 107, which is incorrect:
- There are only 107 steps in total, making the highest step value 106
- 1.60V is listed as 1011000 (88 in decimal), with 18 steps after that 
- Adding 100mV for each of the 18 steps past 1.60V gives 3.4V

I think this logic convinces me at least. :)

John.

> I discovered some other issue in the original patch (missed declaring the
> range of IRQ acknowledge registers in the MFD part), so I will send a v2 of
> this series soonish.
> 
> > For DCDC3 after applying this patch we get:
> > 
> > #define AXP717_DCDC3_NUM_VOLTAGES	103
> > static const struct linear_range axp717_dcdc3_ranges[] = {
> > 	REGULATOR_LINEAR_RANGE(500000,   0,  70, 10000),
> > 	REGULATOR_LINEAR_RANGE(1220000, 71, 102, 20000),
> > };
> > 
> > The datasheet marks the maximum value as 1100110: 1.84V, which is 102.
> > So this patch to correct the AXP717_DCDC3_NUM_VOLTAGES is correct here.
> 
> I agree ;-) thanks for checking!
> 
> Cheers,
> Andre

---

Python program:

reg = 0
value = 500
for x in range(71):
	print("%i: %imV" % (reg, value))
	value += 10
	reg += 1
value = 1220
for x in range(17):
	print("%i: %imV" % (reg, value))
	value += 20
	reg += 1
value = 1600
for x in range(19):
	print("%i: %imV" % (reg, value))
	value += 100
	reg += 1

  reply	other threads:[~2024-04-16 13:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-29 23:50 [PATCH 0/4] regulator: Fix AXP717 PMIC support Andre Przywara
2024-03-29 23:50 ` [PATCH 1/4] regulator: axp20x: AXP717: fix LDO supply rails and off-by-ones Andre Przywara
2024-04-14  8:00   ` John Watts
2024-04-16 11:23     ` Andre Przywara
2024-04-16 13:30       ` John Watts [this message]
2024-03-29 23:50 ` [PATCH 2/4] dt-bindings: mfd: x-powers,axp152: add boost regulator Andre Przywara
2024-03-30  9:30   ` Krzysztof Kozlowski
2024-03-30 21:40     ` Andre Przywara
2024-03-30 21:40       ` Andre Przywara
2024-03-29 23:50 ` [PATCH 3/4] mfd: axp20x: AXP717: Add support for " Andre Przywara
2024-04-14  7:47   ` John Watts
2024-03-29 23:50 ` [PATCH 4/4] regulator: axp20x: AXP717: Add " Andre Przywara
2024-04-14  7:47   ` John Watts
2024-04-11 11:22 ` [PATCH 0/4] regulator: Fix AXP717 PMIC support Lee Jones

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=Zh59gzEB61lNdmMh@titan \
    --to=contact@jookia.org \
    --cc=andre.przywara@arm.com \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jernej.skrabec@gmail.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lee@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=macroalpha82@gmail.com \
    --cc=robh@kernel.org \
    --cc=ryan@testtoast.com \
    --cc=samuel@sholland.org \
    --cc=wens@csie.org \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).