doubleodoug
Posts: 4
Joined: Sat Sep 05, 2015 1:08 am

pca9533 overlay with gpio

Sat Sep 23, 2017 5:48 pm

Hello,

I'm trying to add an overlay for a pca9533 LED driver, which I've got (mostly) working. LED0 is driving a backlight and LED1/2/3 are connected to some signals I'd like to read. The official linux documentation at http://elixir.free-electrons.com/linux/ ... ca9532.txt and http://elixir.free-electrons.com/linux/ ... -pca9532.h says that you can declare PCA9532_TYPE_GPIO to use the other pins as gpio. But when I load my overlay (https://pastebin.com/raw/3JyVHue4) I get this in dmesg:

[ 7856.703573] leds-pca953x 1-0062: setting platform data
[ 7856.706740] gpio gpiochip3: GPIO integer space overlap, cannot add chip
[ 7856.706750] gpiochip_add_data: GPIOs 0..3 (gpio-pca9532) failed to register
[ 7856.706755] leds-pca953x 1-0062: could not add gpiochip

and nothing works. Here's my kernel config: https://pastebin.com/raw/Wg7sbkED, it's the stock kernel with the following changes:

Device Drivers > LED Support > LED driver for PCA9532 dimmer > M
Device Drivers > LED Support > LED driver for PCA9532 dimmer > Enable GPIO support for PCA9352 > Y
Device Drivers > LED Support > LED support for LEDs on system controllers > Y
Device Drivers > LED Support > Userspace LED support > M
Device Drivers > LED Support > LED Class brightness_hw_changed attribute support > Y
Device Drivers > GPIO Support > I2C GPIO expanders > PCA95[357]x, PCA9698, TCA64xx, and MAX7310 I/O ports > M
Device Drivers > GPIO Support > Debug GPIO calls > Y

Anyone have any ideas? I've exhausted my options on google. Thanks in advance.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1419
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: pca9533 overlay with gpio

Sat Sep 23, 2017 9:15 pm

It looks to me like a fault in the pca9532 driver. If the "base" field in the gpiochip structure passed to gpiochip_add_data is negative, Linux will automatically allocate a contiguous range that doesn't clash with any existing GPIOs; otherwise, "base" specifies the required base number. The problem is that the driver copies this value from the gpio_base field of the pca9532_platform_data structure, but apart from an initial zeroing, this field is never initialised in the case that the platform data is coming from Device Tree.

I suggest adding a line to the end of pca9532_of_populate_pdata setting pdata->gpio_base to -1:

Code: Select all

		if (++i >= maxleds) {
			of_node_put(child);
			break;
		}
	}

	pdata->gpio_base = -1;

	return pdata;
}
If that has the desired effect then we can consider making the base configurable via a Device Tree property.

doubleodoug
Posts: 4
Joined: Sat Sep 05, 2015 1:08 am

Re: pca9533 overlay with gpio

Sat Sep 30, 2017 4:15 pm

Hey Phil, thanks for the help and sorry for the delay, real life is a pain sometimes.

With this fix I can get the modules loaded and get led1, led2, and led3 working as inputs (these are the pin names according to datasheet). They don't seem to work as outputs though (led0 in LED mode still works though)... I'm going to try another chip rather than spend any more time on this one but if you need me to test anything let me know.

Thanks again.

Return to “Device Tree”

Who is online

Users browsing this forum: No registered users and 3 guests