linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Preston <thomas.preston@codethink.co.uk>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Rob Herring <robh+dt@kernel.org>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	devicetree <devicetree@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/3] pinctrl: mcp23s08: Fixup mcp23x17 regmap_config
Date: Fri, 28 Aug 2020 20:19:54 +0100	[thread overview]
Message-ID: <f8368c71-33cf-46d7-d361-6c76cfb3b66e@codethink.co.uk> (raw)
In-Reply-To: <CAHp75Vefo6djXk0x9OLiqJ=jZV8dkTEoPBRwBfcr41txfSGyRw@mail.gmail.com>

Hey Andy, Linus,
Thanks for looking at this.

On 28/08/2020 11:09, Andy Shevchenko wrote:
> On Fri, Aug 14, 2020 at 1:35 PM Thomas Preston
> <thomas.preston@codethink.co.uk> wrote:
>>
>> - Fix a typo where mcp23x17 configs are referred to as mcp23x16.
> 
> I'm not sure it's correct. MPC23016 is an existing I²C IO expander.
> 

The MCP23016 device is not mentioned anywhere else in this driver. The 
only place this string is used is in `struct regmap_config 
mcp23x17_regmap` (another device). It seems to me that this is a typo 
but I might be wrong.

~/w/linux$ git grep -h compatible drivers/pinctrl/pinctrl-mcp23s08*
                 .compatible = "microchip,mcp23008",
                 .compatible = "microchip,mcp23017",
                 .compatible = "microchip,mcp23018",
                 .compatible = "mcp,mcp23008",
                 .compatible = "mcp,mcp23017",
                 .compatible = "microchip,mcp23s08",
                 .compatible = "microchip,mcp23s17",
                 .compatible = "microchip,mcp23s18",
                 .compatible = "mcp,mcp23s08",
                 .compatible = "mcp,mcp23s17",

Also I don't have an MC23016, so I can't test configuration for it.

>> - Fix precious range to include INTCAP{A,B}, which clear on read.
>> - Fix precious range to include GPIOB, which clears on read.
>> - Fix volatile range to include GPIOB, to fix debugfs registers
>>    reporting different values than `gpioget gpiochip2 {0..15}`.
> 
> I'm wondering if you read all the datasheets before doing these changes.
> MPC2308
> MPC23016
> MPC23017
> ...
> 

I did not! I was only changing configuration for MCP23017 devices.
What have I missed?

For reference, I think you are referring to [0], [1], [2]. I'm familiar 
with the last one.

>> -static const struct regmap_range mcp23x16_volatile_range = {
>> +static const struct regmap_range mcp23x17_volatile_range = {
>>          .range_min = MCP_INTF << 1,
>> -       .range_max = MCP_GPIO << 1,
>> +       .range_max = (MCP_GPIO << 1) + 1,
> 
> This looks weird. Usually we do a mask or a bit based mask, like (1 << x) - 1.
> 

I don't think these are masks, they're addresses.

I believe the author has doubled the register indexing using a 1 bit 
shift, because the MCP23017 device is configured with sequential 
addresses (IOCON.BANK = 0). On page 12 of the datasheet [2] this looks like:

0x00 IODIRA, MCP_IODIR << 1
0x01 IODIRB
0x02 IPOLA,  MCP_IPOL << 1
0x03 IPOLB
...
0x12 GPIOA,  MCP_GPIO << 1
0x13 GPIOB

This means you can read 16 bits from MCP_GPIO << 1 and get the register 
values for both banks, or even use this for .range_min.

However, this trick doesn't work for .range_max:

	.range_max = MCP_GPIO << 1; /* 0x12 */

But I think it needs to be 0x13 to include GPIOB. Now that I'm looking 
into it, how does `mcp23x17_regmap.val_bits = 16` affect this? Perhaps 
`MCP_GPIO << 1` is fine after all.

I will whip up a v2 and test this. I'll split the changes across patches 
and fix the typo last patch - in case you don't agree with me.

Many thanks,
Thomas

[0] MCP23008 https://ww1.microchip.com/downloads/en/DeviceDoc/21919e.pdf
[1] MCP23016 http://ww1.microchip.com/downloads/en/devicedoc/20090c.pdf
[2] MCP23017 https://ww1.microchip.com/downloads/en/DeviceDoc/20001952C.pdf

  reply	other threads:[~2020-08-28 19:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-14 10:03 [PATCH 0/3] pinctrl: mcp23s08: Fixups for mcp23x17 Thomas Preston
2020-08-14 10:03 ` [PATCH 1/3] pinctrl: mcp23s08: Fixup mcp23x17 regmap_config Thomas Preston
2020-08-28  9:06   ` Linus Walleij
2020-08-28  9:28     ` Andy Shevchenko
2020-08-28 17:30       ` Thomas Preston
2020-08-28 10:09   ` Andy Shevchenko
2020-08-28 19:19     ` Thomas Preston [this message]
2020-08-14 10:03 ` [PATCH 2/3] pinctrl: mcp23s08: Remove interrupt-controller Thomas Preston
2020-08-14 10:03 ` [PATCH 3/3] devicetree: " Thomas Preston
2020-08-14 13:56 ` [PATCH 0/3] pinctrl: mcp23s08: Fixups for mcp23x17 Thomas Preston
2020-08-17 19:29   ` Rob Herring
2020-08-18 11:09     ` Thomas Preston

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=f8368c71-33cf-46d7-d361-6c76cfb3b66e@codethink.co.uk \
    --to=thomas.preston@codethink.co.uk \
    --cc=andy.shevchenko@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.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 NNTP newsgroup(s).