linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Linus Walleij <linus.walleij@linaro.org>, Arnd Bergmann <arnd@arndb.de>
Cc: Alexandre Courbot <gnurou@gmail.com>,
	Alexandre Courbot <acourbot@nvidia.com>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	Jonathan Corbet <corbet@lwn.net>,
	Russell King <linux@armlinux.org.uk>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
	<x86@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	"moderated list:ARM PORT" <linux-arm-kernel@lists.infradead.org>,
	"open list:GENERIC INCLUDE/ASM HEADER FILES" 
	<linux-arch@vger.kernel.org>
Subject: Re: [PATCH] gpio: Allow user to customise maximum number of GPIOs
Date: Thu, 25 Aug 2022 14:00:32 +0000	[thread overview]
Message-ID: <87f2ff4c-3426-201c-df86-2d06d3587a20@csgroup.eu> (raw)
In-Reply-To: <CACRpkdb5ow4hD3td6agCuKWvuxptm5AV4rsCrcxNStNdXnBzrA@mail.gmail.com>



Le 25/08/2022 à 15:36, Linus Walleij a écrit :
> On Thu, Aug 18, 2022 at 2:46 PM Arnd Bergmann <arnd@arndb.de> wrote:
>> On Thu, Aug 18, 2022 at 2:25 PM Linus Walleij <linus.walleij@linaro.org> wrote:
> 
>>> git grep 'base = -1' yields these suspects:
>>>
>>> arch/arm/common/sa1111.c:       sachip->gc.base = -1;
>>> arch/arm/common/scoop.c:        devptr->gpio.base = -1;
>>> arch/powerpc/platforms/52xx/mpc52xx_gpt.c:      gpt->gc.base = -1;
>>> arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c: gc->base = -1;
>>>
>>> That's all! We could just calculate these to 512-ngpios and
>>> hardcode that instead.
>>
>> How do the consumers find the numbers for these four?
> 
> For SA1111 the chip gets named "sa1111" and some consumers actually
> use proper machine descriptions, maybe all?
> 
> arch/arm/mach-sa1100/jornada720.c:              GPIO_LOOKUP("sa1111",
> 0, "s0-power", GPIO_ACTIVE_HIGH),
> arch/arm/mach-sa1100/jornada720.c:              GPIO_LOOKUP("sa1111",
> 1, "s1-power", GPIO_ACTIVE_HIGH),
> (...)
> 
> For Scoop it is conditionally overridden in the code. I guess always
> overridden.
> 
> For powerpc these seem to be using (old but working) device tree
> lookups, so should not be an issue.
> 
> Sadly I'm not 100% sure that there are no random hard-coded
> GPIO numbers referring to whatever the framework gave them
> at the time the code was written :(

On my PPC board, the one before the last looks suspicious ....

[    0.573261] gpio gpiochip0: registered GPIOs 496 to 511 on 
/soc@ff000000/cpm@9c0/gpio-controller@950
[    0.577460] gpio gpiochip1: registered GPIOs 464 to 495 on 
/soc@ff000000/cpm@9c0/gpio-controller@ab8
[    0.586011] gpio gpiochip2: registered GPIOs 448 to 463 on 
/soc@ff000000/cpm@9c0/gpio-controller@960
[    0.591057] gpio gpiochip3: registered GPIOs 432 to 447 on 
/soc@ff000000/cpm@9c0/gpio-controller@970
[    0.595979] gpio gpiochip4: registered GPIOs 400 to 431 on 
/soc@ff000000/cpm@9c0/gpio-controller@ac8
[    0.629292] gpio_stub_drv gpiochip5: registered GPIOs 384 to 399 on 
/localbus@ff000100/cpld-cmpc@5,0000000/gpio-controller@2
[    0.636556] gpio_stub_drv gpiochip6: registered GPIOs 368 to 383 on 
/localbus@ff000100/fpga-m@4,0000000/gpio-controller@00
[    0.639503] gpio_stub_drv gpiochip7: registered GPIOs 352 to 367 on 
/localbus@ff000100/fpga-m@4,0000000/gpio-controller@02
[    0.642434] gpio_stub_drv gpiochip8: registered GPIOs 336 to 351 on 
/localbus@ff000100/fpga-m@4,0000000/gpio-controller@04
[    0.645257] gpio_stub_drv gpiochip9: registered GPIOs 320 to 335 on 
/localbus@ff000100/fpga-m@4,0000000/gpio-controller@10
[    0.648230] gpio_stub_drv gpiochip10: registered GPIOs 304 to 319 on 
/localbus@ff000100/fpga-m@4,0000000/gpio-controller@20
[    0.651070] gpio_stub_drv gpiochip11: registered GPIOs 288 to 303 on 
/localbus@ff000100/fpga-m@4,0000000/gpio-controller@22
[    0.653986] gpio_stub_drv gpiochip12: registered GPIOs 272 to 287 on 
/localbus@ff000100/fpga-m@4,0000000/gpio-controller@24
[    0.656807] gpio_stub_drv gpiochip13: registered GPIOs 256 to 271 on 
/localbus@ff000100/fpga-m@4,0000000/gpio-controller@26
[    0.659761] gpio_stub_drv gpiochip14: registered GPIOs 240 to 255 on 
/localbus@ff000100/fpga-m@4,0000000/gpio-controller@28
[    0.662622] gpio_stub_drv gpiochip15: registered GPIOs 224 to 239 on 
/localbus@ff000100/fpga-m@4,0000000/gpio-controller@2A
[    0.665454] gpio_stub_drv gpiochip16: registered GPIOs 208 to 223 on 
/localbus@ff000100/fpga-m@4,0000000/gpio-controller@2C
[    0.673552] gpio_stub_drv gpiochip17: registered GPIOs 192 to 207 on 
/localbus@ff000100/fpga-m@4,0000000/gpio-controller@30
[    0.677281] gpio_stub_drv gpiochip18: registered GPIOs 176 to 191 on 
/localbus@ff000100/fpga-m@4,0000000/gpio-controller@32
[    0.680235] gpio_stub_drv gpiochip19: registered GPIOs 160 to 175 on 
/localbus@ff000100/fpga-m@4,0000000/gpio-controller@40
[    0.685876] gpio_stub_drv gpiochip20: registered GPIOs 144 to 159 on 
/localbus@ff000100/fpga-m@4,0000000/gpio-controller@42
[    0.694431] gpio_stub_drv gpiochip21: registered GPIOs 128 to 143 on 
/localbus@ff000100/fpga-m@4,0000000/gpio-controller@44
[    0.697257] gpio_stub_drv gpiochip22: registered GPIOs 112 to 127 on 
/localbus@ff000100/fpga-m@4,0000000/gpio-controller@50
[    0.700220] gpio_stub_drv gpiochip23: registered GPIOs 96 to 111 on 
/localbus@ff000100/fpga-m@4,0000000/gpio-controller@52
[    0.703183] gpio_stub_drv gpiochip24: registered GPIOs 80 to 95 on 
/localbus@ff000100/fpga-m@4,0000000/gpio-controller@54
[    0.708226] gpio_stub_drv gpiochip25: registered GPIOs 64 to 79 on 
/localbus@ff000100/fpga-m@4,0000000/gpio-controller@34
[    0.756817] gpio gpiochip26: registered GPIOs 0 to 2 on generic
[    4.530397] gpio gpiochip27: registered GPIOs 36 to 63 on max7301


> 
> Another reason the base is assigned from above (usually
> from 512 and downward) is that the primary SoC GPIO usually
> want to be at base 0 and there is no guarantee that it will
> get probed first. So hard-coded GPIO bases go from 0 -> n
> and dynamically allocateed GPIO bases from n <- 512.
> 
> Then we hope they don't meet and overlap in the middle...
> 
>>> and in that case it is better to delete the use of this function
>>> altogether since it can not fail.
>>
>> S32_MAX might be a better upper bound. That allows to
>> just have no number assigned to a gpio chip. Any driver
>> code calling desc_to_gpio() could then get back -1
>> or a negative error code.
>>
>> Making the ones that are invalid today valid sounds like
>> a step backwards to me if the goal is to stop using
>> gpio numbers and most consumers no longer need them.
> 
> OK I get it...
> 
> Now: who wants to write this patch? :)
> 
> Christophe? Will you take a stab at it?
> 


Which patch should I write ?

Christophe

  reply	other threads:[~2022-08-25 14:00 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-09 10:40 [PATCH] gpio: Allow user to customise maximum number of GPIOs Christophe Leroy
2022-08-11 19:57 ` H. Peter Anvin
2022-08-12 21:58   ` Andy Shevchenko
2022-08-12 23:21     ` H. Peter Anvin
2022-08-17 17:21   ` Christophe Leroy
2022-08-17 17:46 ` Arnd Bergmann
2022-08-18  6:00   ` Christophe Leroy
2022-08-18  8:25     ` Arnd Bergmann
2022-08-18  9:33 ` Linus Walleij
2022-08-18  9:47   ` Arnd Bergmann
2022-08-18 11:13     ` Linus Walleij
2022-08-18 11:33       ` Arnd Bergmann
2022-08-18 12:25         ` Linus Walleij
2022-08-18 12:46           ` Arnd Bergmann
2022-08-18 13:11             ` Christophe Leroy
2022-08-25 13:36             ` Linus Walleij
2022-08-25 14:00               ` Christophe Leroy [this message]
2022-08-26 13:49                 ` Linus Walleij
2022-08-26 15:08                   ` Christophe Leroy
2022-08-26 21:54                     ` Linus Walleij
2022-08-28  9:06                       ` Christophe Leroy
2022-08-28 10:04                         ` Arnd Bergmann
2022-08-30  7:58                           ` Davide Ciminaghi
2022-08-31 13:32                             ` Linus Walleij
2022-08-31 14:12                               ` Davide Ciminaghi
2022-08-31 21:07                                 ` Andy Shevchenko
2022-08-31 21:48                                   ` Davide Ciminaghi
2022-08-30  8:33                           ` Alessandro Rubini
2022-08-30  9:03                             ` Christophe Leroy
2022-08-28 11:35                         ` Linus Walleij

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=87f2ff4c-3426-201c-df86-2d06d3587a20@csgroup.eu \
    --to=christophe.leroy@csgroup.eu \
    --cc=acourbot@nvidia.com \
    --cc=arnd@arndb.de \
    --cc=bp@alien8.de \
    --cc=brgl@bgdev.pl \
    --cc=corbet@lwn.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=gnurou@gmail.com \
    --cc=hpa@zytor.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@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).