Opened 5 years ago

Closed 5 years ago

#13455 closed defect (fixed)

sysfs GPIO and DTS

Reported by: michel.stempin@… Owned by: blogic
Priority: high Milestone: Chaos Calmer 15.05
Component: kernel Version: Trunk
Keywords: GPIO DTS sysfs Cc:


It looks like the sysfs GPIO is broken since the introduction of DTS.

In the DTS include file ("target/linux/ramips/dts/rt3050.dtsi" in my case, by this is also true for the other ones), only the number of GPIOs for each gpio-controller is defined, but not the GPIO base number for each chip. For example:

		gpio0: gpio@600 {
			compatible = "ralink,rt3052-gpio", "ralink,rt2880-gpio";
			reg = <0x600 0x34>;

			#gpio-cells = <2>;

			ralink,num-gpios = <24>;
			ralink,register-map = [ 00 04 08 0c
						20 24 28 2c
						30 34 ];

This part of DTS is handled by the ralink_gpio_probe() function added by the "0130-GPIO-MIPS-ralink-adds-ralink-gpio-support.patch" file for the ramips architecture, which sets the GPIO base number to -1 to get a dynamically-allocated base GPIO number.

This feature was introduced in Linux kernel 2.6.26-rc1, but unfortunately, it is not working as expected here, since to avoid using any numbers that may have been explicitly assigned but not yet registered, this dynamic allocation assigns GPIO numbers from the biggest number on down, instead of from the smallest on up.

This assignment is performed by function gpiochip_find_base() in the kernel's "drivers/gpio/gpiolib.c" file, and as the same patch above defines ARCH_NR_GPIOS to 128, this results in a base GPIO number of 128 - 24 = 104, which is brought to the user by sysfs as a chip entry "/sys/class/gpio/gpiochip104" instead of the expected "/sys/class/gpio/gpiochip0", breaking the userspace ABIs.

Since changing the dynamic GPIO number feature order in the kernel is out of question as it would also break the userspace ABIs, what is the best option to get the GPIOs back to working as before?

Attachments (0)

Change History (3)

comment:1 Changed 5 years ago by blogic

  • Owner changed from developers to blogic
  • Status changed from new to assigned

comment:2 Changed 5 years ago by blogic

fixed in current head, please try r36561 or newer

comment:3 Changed 5 years ago by blogic

  • Resolution set to fixed
  • Status changed from assigned to closed

Add Comment

Modify Ticket

as closed .
The resolution will be deleted. Next status will be 'reopened'.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.