Led PCA9533 from user space

I need to use I2C led component PCA9533/02
In a first try, i have activated “Device Drivers → Led Support → LED driver for PCA9532 dimmer” and added to device tree file “imx7-colibri-eval-v3.dtsi” following code:

	leds: pca9530@63 {
		compatible = "nxp,pca9533";
		reg = <0x63>;
		red-power {
			label = "pca:red:power";
			type = <PCA9532_TYPE_LED>;
		};
		green-power {
			label = "pca:green:power";
			type = <PCA9532_TYPE_LED>;
		};
	};

Also added file leds-pca9532.h in “/home/guest/linux-toradex/arch/arm/boot/dts/include/dt-bindings/leds” where are defined the definition used in device tree.
(I have added it in section “&i2c4”, the same i2c of capacitive touch because i need them on the same bus).
Both kernel and device tree are compiled correctly.
After that I was stuck because I’m not able to access kernel driver from user space and my qt app. How to do that?

Second try, I have activated “Device Drivers → Led Support → Enable GPIO support for PCA9532” because i see that some people use it from user space accessing “/sys/class/leds” using it as gpio.
Kernel compiled correctly but I don’t have any led in “/sys"class/leds”, only “mmc0”.

How can I do to make It work?

Is there a particular reason you set this question to private? Usually the whole community may profit from you asking and us answering any such questions. If you don’t mind we therefore would set it to public. OK?

I’m sorry, just a mistake! Now I set to public :slight_smile:

How about the driver debug logs ? Did you see any debug messages ? h/w connections good ? Can you see the slave device addr getting detected with ‘i2c tools’ ?

Hi

I assume you are using the toradex_4.1-2.0.x-imx-next kernel branch.
The PCA9532 device tree integration has only been added to the kernel around kernel version 4.8. So your device tree nodes are not evaluated by the PCA9532 driver.

So you would either have to:

  • instantiate and register platform data for your PCA9532

or

  • backport the device tree integration

Max

Using i2cdetect, component is correctly detected at address 0x63.
I’m able to turn on and off RGB led using i2cset command.

Yesterday, following example in this page as i2c communication from user space, I’m able to open i2c bus and access to the slave, but not to write or read to i2c bus (RGB led don’t turn on and off).

Today i modify the write routine, removing the slave address from the buffer (following this example):

    uint8_t data[3];
    //data[0] = 0x63;
    data[0] = 0x05;
    data[1] = (int)strtol(argv[1],NULL,16);

    if(write(file,data,2) != 2) {
        /* ERROR HANDLING: i2c transaction failed */
        printf("Failed to write to the i2c bus.\n");
        printf("\n\n");
        exit(1);
    }

The component start to work and actually I’m able to use RGB led from my Qt app.

But there are two questions that need an answer:

  1. Accessing i2c directly from user space, kernel driver and device tree modification are not needed, right? (I did some tests and it looks like this)

  2. Accessing i2c directly from Qt app (or even user space) is the right way or there are more correct solutions?

While answering to bhuvan I did not see your answer.

Actually for kernel I’m using toradex_imx_4.1.15_1.0.0.ga.

Currently I’ve found a method that work (maybe not the best), but now I’m going to try the backport of the device tree integration.

I will give you a feedback.

Thanks.