I2C / TWI support in u-boot to read EEPROM on efusA9X

  • Hello,


    I need to read out a EEPROM-IC via I2C in u-boot. I noticed that there is no I2C support for the efusA9X module, see "No I2C used in U-Boot on F&S i.MX6 SoloX boards" (UBOOT/include/configs/fsimx6sx.h).


    Is there a other board with the imx6sx processor or a source that provided support for the I2C bus, or what else can I do to communicate in u-boot with the EEPROM?



    Thanks.

  • Yes, we currently do not need I2C in U-Boot and therefore we haven't activated it, yet. But there are quite a few drivers available, so you do not write the driver from scratch.


    When you are on a dedicated I2C bus, then you can use drivers/i2c/mxc_i2c.c. This is the driver for all i.MX6 CPU variants. If you only can use regular GPIOs and need a bitbanging I2C, then drivers/i2c/soft_i2c.c may help. These drivers register with the generic i2C framework in drivers/i2c/i2c_core.c. This is the file that also provides the functions to be used from outside to access I2C.


    Unfortunately I'm not exactly sure how I2C works in U-Boot. If there is some board-specific initialization required, you can add this function to board/F+S/fsimx6sx/fsimx6sx.c, where all our i.MX6-SoloX specific stuff is located. There you have to configure the pads used for I2C. I think the best way to learn how this works on i.MX6 is by looking at the NXP code itself, which is for example in board/freescale/mx6sabresd/mx6sabresd.c. Here they seem to initialize the I2C pads and then they call a function setup_i2c() which is defined in arch/arm/imx-common/i2c-mxv7.c.


    Your own code that actually reads from I2C EEPROM can also be added to fsimx6sx.c, maybe in board_init() or board_late_init().


    Your F&S Support Team

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Hello,


    I edited board/F+S/fsimx6sx/fsimx6sx.c according board/freescale/mx6sabresd/mx6sabresd.c and arch/arm/include/asm/arch/mx6sx_pins.h (for the PADs).


    I also enabled the i2c and the eeprom command in uboot for debugging.


    I am able to compile UBOOT. But there is no way to access the I2C bus. Please give me a hint what is wrong or how I can check/debug my errors.


    The hardware is fine. In LINUX the EEPROM can be read and write out of the box.



    COMMANDS:


    Code
    1. setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x53, &i2c_pad_info0); (in board/F+S/fsimx6sx/fsimx6sx.c)
    2. force_idle_bus: sda=1 scl=0 sda.gp=0x3 scl.gp=0x2
    3. force_idle_bus: failed to clear bus, sda=1 scl=0


    Code
    1. efusA9X # i2c probe 0x53 ( in UBOOT)
    2. Valid chip addresses:wait_for_sr_state: failed sr=81 cr=0 state=2020
    3. i2c_init_transfer: failed for chip 0x53 retry=0
    4. wait_for_sr_state: failed sr=81 cr=0 state=2020
    5. i2c_init_transfer: failed for chip 0x53 retry=1
    6. i2c_init_transfer: give up i2c_regs=021a0000



    FILES:



    ---------------------------------------------


  • UPDATE:


    After changing the addr to 0x7F (see https://github.com/boundarydev…rogen6x/nitrogen6x.c#L915) I was able to access the i2c bus 0 and 2:
    setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info0);



    The error from bus 0 (I2C_C) is still present. But the bus works:

    Code
    1. force_idle_bus: sda=1 scl=0 sda.gp=0x3 scl.gp=0x2
    2. force_idle_bus: failed to clear bus, sda=1 scl=0



    The bus number 1 is still not working, but the error message has changed to:

    Code
    1. efusA9X # i2c dev 1
    2. efusA9X # i2c probe 0x53
    3. Valid chip addresses:wait_for_sr_state: Arbitration lost sr=93 cr=80 state=2020
    4. i2c_init_transfer: failed for chip 0x53 retry=0
    5. wait_for_sr_state: Arbitration lost sr=93 cr=80 state=2020
    6. i2c_init_transfer: failed for chip 0x53 retry=1
    7. i2c_init_transfer: give up i2c_regs=021a4000
  • I2C_B alias I2C3 is correct, this is on pads KEY_ROW4 and KEY_COL4. This is why this port works.
    I2C_C alias I2C1 is correct, this is on pads GPIO1_IO00 and GPIO1_IO01. This is why this port works. Only your comment is wrong where you name this as I2C_A.
    But I2C_A alias I2C2 is wrong. On our board this is on pads QSPI1B_DATA2 and QSPI1B_DATA3. This is why this port does not work. The pins that you defined are actually used for other signals on our board.


    Your F&S Support Team

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Thanks for your help. Now every thing is working great.


    I configured all PADs as recommended. The error "force_idle_bus: sda=1 scl=0 sda.gp=0x3 scl.gp=0x2" and "force_idle_bus: failed to clear bus, sda=1 scl=0" are gone.
    All i2c buses works in UBOOT.


    Below the needed changed to enable I2C in UBOOT for the efusA9X / fsimx6sx: (NOTE that the 5µs delay is specific for my EEPROM)



  • Thanks for sharing your code with us.


    Your F&S Support Team

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.