Re: [PATCH 0/2] gpio: gpio-sim: read property 'gpio-base' from dtb

From: Bartosz Golaszewski
Date: Thu Jun 23 2022 - 11:00:07 EST


On Wed, Jun 22, 2022 at 5:54 PM Menglong Wu <menglongwoo@xxxxxxxxxx> wrote:
>
> The first GPIO number of the gpio-sim module is dynamic.
>
> gpio_chip.base = -1.
>
> ```
> gpio-sim {
> compatible = "gpio-simulator";
> bank0 {
> gpio-controller;
> #gpio-cells = <2>;
> ngpios = <16>;
> gpio-sim,label = "dt-bank0";
> gpio-line-names = "", "sim-foo", "", "sim-bar";
> };
> };
> ```
>
> If I want to export GPIO from user space. I have to confirm the number
> from the debugfs filesystem. The 16 GPIO be map to 2032-2047.
>

I find it ironic that you're trying to use sysfs to play with the
module whose sole purpose is to facilitate the move away from it. I'd
like to hear a very good reason to add this option because otherwise
you're exposing information that should very much be hidden from
user-space.

Bart

>
> ```
> [root@QEMU-ARM ~]# cat /sys/kernel/debug/gpio
> gpiochip0: GPIOs 2032-2047, parent: platform/gpio-sim, dt-bank0:
>
> gpio-2033 (sim-foo )
> gpio-2035 (sim-bar )
> ```
>
> Change
>
> Then add the property 'gpio-base' to fix the base number.
> Although the method is be DEPRECATED (include/linux/gpio/driver.h)
>
> ```
> gpio-sim {
> compatible = "gpio-simulator";
> bank0 {
> gpio-controller;
> #gpio-cells = <2>;
> gpio-base = <300>;
> ngpios = <16>;
> gpio-sim,label = "dt-bank0";
> gpio-line-names = "", "sim-foo", "", "sim-bar";
> };
> };
> ```
>
> This base number is always 300.
>
> ```
> [root@QEMU-ARM ~]# cat /sys/kernel/debug/gpio
> gpiochip0: GPIOs 300-315, parent: platform/gpio-sim, dt-bank0:
> gpio-301 (sim-foo )
> gpio-303 (sim-bar )
> [root@QEMU-ARM ~]# echo 300 > /sys/class/gpio/export
> ```
>
>
>
>
> Menglong Wu (2):
> gpio: gpio-sim: initialize gpio_chip->base from dtb
> docs: gpio-sim device-tree example with gpio-base
>
> Documentation/admin-guide/gpio/gpio-sim.rst | 3 +++
> drivers/gpio/gpio-sim.c | 7 ++++++-
> 2 files changed, 9 insertions(+), 1 deletion(-)
>
> --
> 2.30.2
>