Adding I2C GPIO (PCF857x) to Devicetree

Discussion of your EDM baseboard, your add-on boards or other peripherals for your wandboard.

Adding I2C GPIO (PCF857x) to Devicetree

Postby rsmith » Mon Aug 10, 2015 3:48 pm

Hello,
We are currently using Wandboard in one of our products (it was developed before the migration to Devicetree). The product integrated a number of peripherals, including I2C GPIO.
We are now developing a new product that will have similar features, however I am starting fresh with a more recent repo / kernel, etc - and this means moving to Devicetree.

I am in the process of getting I2C GPIOs (PCF8575 expander) properly configured. I will also be adding analog I2C expanders as well.
On the previous version - I had to add the chips to the Kernel configuration and the board file.
I also had to give the GPIO more space - so I had to increase the total number of GPIO to 512 (to provide more 'headroom' to the additional gpio).
I also wanted these GPIOs to start enumeration at GPIO 256.

What I ended up with was the following changes (before Devicetree...)
board-wand.c:
Code: Select all
 /* I2C Expander Setup */
/* Various examples of setup can be found by searching under arch/arm for 857x includes */

#if 1
#define IOEXP_1_ADDR 0x20
#define IOEXP_2_ADDR 0x21
#define IOEXP_3_ADDR 0x22
#define IOEXP_BUS 1
//I2C Physical Bus 2
#define IOEXP_GPIOBASE (8*32)
// This number will have to be the offset of where CHIP gpio ends.
   
static struct pcf857x_platform_data pcf857x_data[] = {
   {
           .gpio_base = IOEXP_GPIOBASE,
   },
        {
           .gpio_base = IOEXP_GPIOBASE + 16,
   },
        {
           .gpio_base = IOEXP_GPIOBASE + 32,
   }
};

static struct i2c_board_info ioexpander_i2c_info[] = {
   {
      I2C_BOARD_INFO("pcf8575", IOEXP_1_ADDR),
      .platform_data = &pcf857x_data[0],
   },
   {
      I2C_BOARD_INFO("pcf8575", IOEXP_2_ADDR),
      .platform_data = &pcf857x_data[1],
   },
   {
      I2C_BOARD_INFO("pcf8575", IOEXP_3_ADDR),
      .platform_data = &pcf857x_data[2],
   },
};

static void __init ioexpander_init(void)
{
   /* I2C */

   printk(KERN_INFO "Initializing IO Expander\n");
   i2c_register_board_info(IOEXP_BUS, ioexpander_i2c_info,
                              ARRAY_SIZE(ioexpander_i2c_info)); 
   //imx1_add_imx_i2c(&mx1ads_i2c_data);
}

#endif


I also hacked the gpio.h file to provide more headroom for the GPIOs (I'm sure that there was a better way to override this value - but it worked).

gpio.h:

#define ARCH_NR_GPIOS 512


Now that things are moving to Devicetree - I am in the process of making similar changes...

I turned on the chip support in the Kernel.
I have been able to get the chips to register with the kernel and map to the virtual file system. However because the ARCH_NR_GPIOS has not been expanded (and gpio_base is not set) - I run out of room to enumerate the chips (as expected).

So far I have added the following lines the the Devicetree file...
imx6qdl-wandboard.dtsi:
Code: Select all
&i2c2 {
....       
        pcf8575_1: gpio@20 {
           compatible = "nxp,pcf8575";
           reg = <0x20>;
           /*
           interrupt-parent = <&irqpin2>;
           interrupts = <3 0>;
           */
           gpio-controller;
           #gpio-cells = <2>;
           /*
           interrupt-controller;
           #interrupt-cells = <2>;
           */
        };   

        pcf8575_2: gpio@21 {
           compatible = "nxp,pcf8575";
           reg = <0x21>;
           /*
           interrupt-parent = <&irqpin2>;
           interrupts = <3 0>;
           */
           gpio-controller;
           #gpio-cells = <2>;
           /*
           interrupt-controller;
           #interrupt-cells = <2>;
           */
        };   
        pcf8575_3: gpio@22 {
           compatible = "nxp,pcf8575";
           reg = <0x22>;
           /*
           interrupt-parent = <&irqpin2>;
           interrupts = <3 0>;
           */
           gpio-controller;
           #gpio-cells = <2>;
           /*
           interrupt-controller;
           #interrupt-cells = <2>;
           */
        };   
}


The question I have - is: What is the proper way to adjust the ARCH_NR_GPIO and the gpio_base now that the world is in Devicetree. I see hints but have not found any clear answers in Devicetree docs, code, etc. I'm guessing the gpio_base might be a parameter in DeviceTree - but want to see if anyone has any suggestions of how to specify these parameters (platform data related things).

Thanks,

Ryan
rsmith
 
Posts: 3
Joined: Wed Mar 19, 2014 2:03 pm

Return to Hardware and peripherals

Who is online

Users browsing this forum: No registered users and 5 guests

cron