This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

EEPROM M24128, and IO expander PCF8575 on I2C

Other Parts Discussed in Thread: PCF8575, AM3352, AM3517

Hello

i have a custom board based on ARM AM3352; i have an i2c bus to drive EEPROM M24128, and IO expander PCF8575.

1) What must i do to be able to address these chips under linux ?

2) Is there available code example for that ?

3) should i in arch\arm\mach-omap2\board-am335xevm.c make a call to i2c1_init

4) is there procedure in linux to discover automatically i2c device ?

5) are there other ways to drive these device than to use the following functions : open("/dev/i2c-1",O_RDWR)); ioctl(dev_i2c,I2C_SLAVE,eepromAddr); write(dev_i2c, i2c_ptr, 1);...

best regards

Christophe

  • Hi,

    At Which buses you have connected your PCF8575 & EEPROM like i2c-0 or i2c-1 ?

    Ex:

    If you connected your EEPROM and PCF8575 devices connected to i2c-1 then the code should like this in board file.

    please change your platform data as per your eeprom data sheet.

    /* PCF8575 GPIO expander platform data */
    static struct pcf857x_platform_data pcf857x_data[] = {
            {
                    .gpio_base = 6 * 32,
            },
    };

    /* EEPROM platform data */
    static struct at24_platform_data m24128 = {
            .byte_len       = SZ_xK / 8, --> byte size
            .page_size      = xx,  --> mention your page size here
    };


    static struct i2c_board_info am335x_i2c1_boardinfo[] = {
        {
            I2C_BOARD_INFO("pcf857x", 0x20),
                    .type = "pcf8575",
                    .platform_data = &pcf857x_data[0],
            },

            {
                    I2C_BOARD_INFO("m24128", 0xYY), /* EEPROM */  -->YY  give your eeprom i2c slave address
                    .platform_data  = &m24128,
            },
    };

  • Thank you for your reply

    the i2c is on

    I2C0_SCL/TIMER7/UART2_RTSN/ECAP1_IN_PWM1_OUT////GPIO3_6
    I2C0_SDA/TIMER4/UART2_CTSN/ECAP2_IN_PWM2_OUT////GPIO3_5

    1) How do you set .gpio_base ? what do it stand for ?

    2) if i define the structure above i can use i2c function under linux as

    i2cdetect –l

    i2cget 1 0x20 ?

    Best regards

  • Hi,

    the i2c is on

    I2C0_SCL/TIMER7/UART2_RTSN/ECAP1_IN_PWM1_OUT////GPIO3_6
    I2C0_SDA/TIMER4/UART2_CTSN/ECAP2_IN_PWM2_OUT////GPIO3_5

    then use static struct i2c_board_info am335x_i2c0_boardinfo[] = {

    1) How do you set .gpio_base ? what do it stand for ?

    I forgot to mention that include "#include <linux/i2c/pcf857x.h>" in your board file.

    plz refer that include file & pcf8575 data sheet.

    2) if i define the structure above i can use i2c function under linux as

    Yes you can,

    i2cget -f -y 1 0x20 1 w

  • Hello,

    thank you very much for your reply, but i still don't understand the .gpio_base structure.

    The pcf857x.h mentions "number of the chip's first GPIO" : what does it means ?

     

    Best regards

  • Hi Christophe,

    AM35x

    I have used this "PCF 8575" used  my AM35x board;

    ".gpio_base" structure for mentioning the base address (starting address ) of GPIO of pcf8575  in other words starting address of your PCF8575 from generated gpios by pcf8575

    As per PCF8575 data sheet , PCF8575 provides 16 GPIO outputs then ,

    A per AM3517 data sheet , the total GPIO supported is    2 * 16

    the starting address of gpio of pcf8575 is = 16*2 => 192

    the last address of gpio of pcf8575 is = 192 + 16 - 1  => 207

    Log from AM3517 board

    [    0.452301] print_constraints: LDO2: 1750 <--> 1850 mV at 1800 mV
    [    0.469177] omap_i2c omap_i2c.2: bus 2 rev1.3.12 at 400 kHz
    [    0.484558] omap_i2c omap_i2c.3: bus 3 rev1.3.12 at 400 kHz
    [    0.489105] pcf857x 3-0020: gpios 192..207 on a pcf8575
    [    0.497161] Advanced Linux Sound Architecture Driver Version 1.0.24.

    Platform data used in pcf857x.c (which is inserted in board file ):

    drivers/gpio/pcf857x.c

        dev_info(&client->dev, "gpios %d..%d on a %s%s\n",
                gpio->chip.base,                                            //16*2 => 192
                gpio->chip.base + gpio->chip.ngpio - 1,      // 192 + 16 -1 => 207
                client->name,
                client->irq ? " (irq ignored)" : "");

    AM335x

    So please refer your AM3352 reference manual and find out how many GPIO s provided by AM335x SOC and use that is starting address of your "base address"

    So.

    As per your AM335x board,  your pcf8575 base address should be  "4 * 32"

    Please refer Chapter 25.1.1 in AM335x technical reference manual,

    http://www.phytec.com/wiki/images/7/72/AM335x_techincal_reference_manual.pdf

    /* PCF8575 GPIO expander platform data */
    static struct pcf857x_platform_data pcf857x_data[] = {
            {
                    .gpio_base = 4 * 32,
            },
    };

    static struct i2c_board_info am335x_i2c1_boardinfo[] = {
        {
            I2C_BOARD_INFO("pcf857x", 0x20),
                    .type = "pcf8575",
                    .platform_data = &pcf857x_data[0],
            },

            {
                    I2C_BOARD_INFO("m24128", 0xYY), /* EEPROM */  -->YY  give your eeprom i2c slave address
                    .platform_data  = &m24128,
            },
    };

     

    i hope it helps,

  • Hello

    thank you a lot.

    if i want to read GPIO from P00 to P07 of PCF8575  (@0x20 on i2c,) the correct command is

    i2cget -y 0 0x20 0x00 b

    if i want to read GPIO from P10 to P17 of PCF8575  (@0x20 on i2c,) the correct command is

    i2cget -y 0 0x20 0x01 b

     

    Best regards

  • Hi,

    What are you trying to do?

    If pcf8575 driver initialized and loaded by linux kernel then it will provide 16 GPIOs then then you can export those GPIOs as a normal gpio no and access from userspace.

    Need to access the GPIO which is provided by pcf8575 IC ?

    then,

    To bring out the gpio to userspace:

    echo 125 > /sys/class/gpio/export

    To set as an output:

    echo out > /sys/class/gpio/gpio125/direction

    To set high:

    echo 1 > /sys/class/gpio/gpio125/value

    To set low:

    echo 0 > /sys/class/gpio/gpio125/value

    Refer the TI wikis to know more,

    http://www.omappedia.com/wiki/GPIO

    http://processors.wiki.ti.com/index.php/GPIO_Driver_Guide

  • Hello

    thank you for your reply

    I have declared the following structure in the board-am335xevm.c :

    static struct i2c_board_info __initdata am335x_i2c0_boardinfo[] = {
        {
            
            I2C_BOARD_INFO("24c256", BASEBOARD_I2C_ADDR),
            .platform_data  = &am335x_baseboard_eeprom_info,
        },
            {
                    I2C_BOARD_INFO("pcf857x", 0x40),
                    .type = "pcf8575",
                    .platform_data = &pcf857x_data[0],
            },
            {
                    I2C_BOARD_INFO("m24128", 0xA0), /* EEPROM   -->0xA0 = RUR  eeprom i2c slave address*/
                    .platform_data  = &m24128,
            },
            {
                    I2C_BOARD_INFO("m24128", 0xAE), /* EEPROM   -->0xAE = UCR  eeprom i2c slave address*/
                    .platform_data  = &m24128,
            },
    };

    Is it mandatory to have this kind of declaration to have access to I2c components of the board under linux ?

    For example, is it possible to use  the following functions  if am335x_i2c0_boardinfo[] structure is not defined ?

    open("/dev/i2c-1",O_RDWR))
     (ioctl(dev_i2c,I2C_SLAVE,eepromAddr) < 0)
      write(dev_i2c, i2c_ptr, 2)  

    thanks

    Best regards

  • Hi,

    For example, is it possible to use  the following functions  if am335x_i2c0_boardinfo[] structure is not defined ?

    open("/dev/i2c-1",O_RDWR))
     (ioctl(dev_i2c,I2C_SLAVE,eepromAddr) < 0)
      write(dev_i2c, i2c_ptr, 2)  

    This is application code for i2c access in user space.

    Is it mandatory to have this kind of declaration to have access to I2c components of the board under linux ?

    Yes,

    This is the format for declaring the platform specific data which is used by pcf8575.c driver file

  • Hello

    thanks

    Ok the structure is mandatory for pcf8575.c, but for my 2 EEPROM devices 24c128, can i have access to them even if they are not declared in am335x_i2c0_boardinfo[] structure ?

    regards

  • Hi,

    but for my 2 EEPROM devices 24c128, can i have access to them even if they are not declared in

    No,

    If you are adding any I2C devices into board then you need to mention those slave addr (chip address) & platform data  in board file for accessing from user space.

    Please refer sample board bringup given in TI wiki link,

    http://processors.wiki.ti.com/index.php/Android_Sensor_PortingGuide#Driver_porting