pietrushnic / rpi-dt-linux

This repository aims to handle all patches required for Raspberry Pi support in upstream Linux kernel.
Other
2 stars 0 forks source link

GPIO chip is named 202 instead of 0 #7

Open matthiasklein opened 9 years ago

matthiasklein commented 9 years ago

Does anyone know why the gpiochip is called 202 at /sys/class/gpiochip202 instead of /sys/class/gpiochip0 as in the old 3.12 kernel?

I am wondering that it works that the gpio-leds driver in the device tree use numbers starting at 0.

notro commented 9 years ago

That's because bcm2835_gpio_chip.base = -1 bcm2835_pinctrl_probe->gpiochip_add->gpiochip_find_base returns base = ARCH_NR_GPIOS - ngpio which is 256 - 54 = 202 This is used for absolute gpio numbering. In the Device Tree, relative numbering is used. Relative to the gpio controller referred to, where 0 is the first gpio on the controller.

There is a "gpio-base" property mentioned in Documentation/devicetree/bindings/gpio/gpio.txt, but this isn't implemented in pinctrl-bcm2835.

On ARCH_BCM2708, chip->base is set to zero, hence the absolute numbers starting at zero: https://github.com/raspberrypi/linux/blob/rpi-3.12.y/arch/arm/mach-bcm2708/bcm2708_gpio.c#L344

pietrushnic commented 9 years ago

@matthiasklein if I corrctly understand @notro this should be retreive this information from device tree and avoid to hardcode this value in code.

Ok, you get the correct answer on ML.

matthiasklein commented 9 years ago

I think a dynamic nummber or a number from device tree makes only sense if the bcm2835 can have multiple gpio chips.

I will implement the "gpio-base" property if ML requires it for upstreaming ...

notro commented 9 years ago

Yes, I think the gpio-base property is the way to go here. The DT property already exists, it's more flexible and it doesn't alter the current default behaviour of the driver. Another argument in a Linux maintanence perspective, is to try and make all the drivers behave as similar as possible, thus having base = -1.

I can see the need for zero based gpios on such a widely used newbie platform. It's important to avoid breaking current documentation (and tools).

There are all kinds of gpio extenders that can be connected (i2c, spi, usb).

matthiasklein commented 9 years ago

It looks like the "gpio-base" property is deprecated: https://github.com/pietrushnic/rpi-dt-linux/blob/rpi-3.17.y/drivers/gpio/gpio-pca953x.c#L611

That is the onyl place where it exist.

matthiasklein commented 9 years ago

See also: https://patches.linaro.org/14422/

notro commented 9 years ago

Yes, so it seems. This one is crystal clear: http://www.spinics.net/lists/linux-gpio/msg01387.html

Which means the doc (gpio.txt) is wrong:

2.1) gpio- and pin-controller interaction
-----------------------------------------
<snip>
    gpio-base : Base GPIO ID in the GPIO controller
    pinctrl-base : Base pinctrl pin ID in the pin controller
pietrushnic commented 9 years ago

What "automaticly assigned gpio" means ?

pietrushnic commented 9 years ago

@matthiasklein what is the state of this issue ? Did it get to upstream or we expect different solution ?

matthiasklein commented 9 years ago

Upstream does not accept a patch for fixed gpio numbers.

Details and possible solutions: http://lists.infradead.org/pipermail/linux-rpi-kernel/2014-October/001045.html