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.

Enabling I2C2 in Linux

Other Parts Discussed in Thread: DM388, PCF8575, DM385

Hi,

We are trying to establish a command channel between our image sensor and the DM388 using I2C via wires connecting to I2C2_SDA and I2C2_SCL pins (with the sensor assigned a slave address of 0x04 and clock at 100kHz). 

Using IPNC RDK 3.8 as the code base, we followed the instructions in the TI81xx PSP Porting Guide, in an attempt to enable I2C2. 

More specifically, the following lines of code were inserted into board-ti8148evm.c and board-dm385ipnc.c.

static struct i2c_board_info __initdata ti814x_i2c_boardinfo2[] = {

    {

    I2C_BOARD_INFO("s100_command", 0x04),

    },

};

static void __init ti814x_evm_i2c_init(void)

{

    omap_register_i2c_bus(1, 100, ti814x_i2c_boardinfo,

        ARRAY_SIZE(ti814x_i2c_boardinfo));

    omap_register_i2c_bus(2, 100, ti814x_i2c_boardinfo2,

       ARRAY_SIZE(ti814x_i2c_boardinfo2));

}

 

We leave i2c.c unchanged since the original code looks okay for our purpose.

void __init omap2_i2c_mux_pins(int bus_id)

....

    if (cpu_is_ti814x() && bus_id == 3) {

        sprintf(mux_name, "uart0_dcdn.i2c2_scl_mux0");

        omap_mux_init_signal(mux_name, OMAP_PIN_INPUT);

        sprintf(mux_name, "uart0_dsrn.i2c2_sda_mux0");

        omap_mux_init_signal(mux_name, OMAP_PIN_INPUT);

    } else {

        sprintf(mux_name, "i2c%i_scl.i2c%i_scl", bus_id, bus_id);

        omap_mux_init_signal(mux_name, OMAP_PIN_INPUT);

        sprintf(mux_name, "i2c%i_sda.i2c%i_sda", bus_id, bus_id);

        omap_mux_init_signal(mux_name, OMAP_PIN_INPUT);

    }

}

After a clean build and update of binaries, the only i2c bus available when rebooting to linux is still /dev/i2c-1, which is enabled by default. And obviously running i2cdetect -l only generates i2c-1 as result. 

This is our first attempt at using I2C2, so we probably have missed something obvious. Any pointer would be greatly appreciated.

  • Hello,

    user4165218 said:

    More specifically, the following lines of code were inserted into board-ti8148evm.c and board-dm385ipnc.c.

    static struct i2c_board_info __initdata ti814x_i2c_boardinfo2[] = {

        {

        I2C_BOARD_INFO("s100_command", 0x04),

        },

    };

    static void __init ti814x_evm_i2c_init(void)

    {

        omap_register_i2c_bus(1, 100, ti814x_i2c_boardinfo,

            ARRAY_SIZE(ti814x_i2c_boardinfo));

        omap_register_i2c_bus(2, 100, ti814x_i2c_boardinfo2,

           ARRAY_SIZE(ti814x_i2c_boardinfo2));

    }

    For DM388 device, I think you should modify the board-dm385evm.c file:

    static struct i2c_board_info __initdata dm813x_i2c_boardinfo1[] = {
        {
            I2C_BOARD_INFO("pcf8575_1_dm813x", 0x20),
        },

    };

    static void __init ti814x_evm_i2c_init(void)
    {
        /* There are 4 instances of I2C in TI814X but currently only one
         * instance is being used on the TI8148 EVM
         */
        omap_register_i2c_bus(1, 100, ti814x_i2c_boardinfo,
                    ARRAY_SIZE(ti814x_i2c_boardinfo));
        omap_register_i2c_bus(3, 100, dm813x_i2c_boardinfo1,
                    ARRAY_SIZE(dm813x_i2c_boardinfo1));

    }

    See also if the below links will be in help:

    BR
    Pavel


  • More specifically, the following lines of code were inserted into board-ti8148evm.c and board-dm385ipnc.c.

    What is your processor ?
    DM8148 or DM385 (DM388) ?

    Why are you changing the both board files ?
    Able to see any signal transitions on I2C2 bus (CRO probing) ?
  • Hi Pavel,

    Thanks for the suggestion.

    We modified those 2 source code files because the makefile was configured to compile only those two board .c files when Appro turned over the code to us. The board-dm385evm.c was not compiled in the make process.

    I will go over the links you recommended and see if any provides applicable information to the issue. Thanks!
  • Hi Titus,

    We are using DM388, and as I explained in another post, those 2 board files were modified because they were the only ones that were compiled during the make process. I first modified board-dm385ipnc.c but it didn't work, so I simply tried the only other board file that got compiled.

    We did see the signal transitions on both cables (of I2C2) showing correctly.

    The most immediate issue we're facing here is that Linux doesn't seem to recognize this additional i2c bus, so it doesn't show up in /dev or /sys/class. I am wondering if you might think of any code or configuration change needed that we might have missed to make that happen.

    Thanks.
  • Hi Pavel,

    Thanks for providing all the additional information.

    After going through all the links, and incorporated the modifications to devices.c (adding ti814x_enable_i2c1();) we saw from one of the links, we were still unable to see any i2c bus other than i2c-1 in /dev or /sys/class.

    Any other ideas or thoughts? Thanks in advance.

  • We modified those 2 source code files because the makefile was configured to compile only those two board .c files when Appro turned over the code to us. The board-dm385evm.c was not compiled in the make process.


    DM8148 uses the OMAP arch and would be "mach-omap2" but DM388 uses davinci arch & it would be "mach-davinci"
    Which machine folder are you using for your board ?

    Attach the original Makefile (arch/arm/mach-davinci folder's) and .config here.

    Just put some priintks in 2 board file and check which file is used by the kernel and also put printks in devices.c, dm3XX.c
    If possible, attach complete mach-davinci folder.
  • Hi Titus,

    Thanks a lot for the help.

    In the source code tree I have access to, board-dm385evm.c and board-dm385ipnc.c are both in mach-omap2 folder. We can only find board-dm355, board-dm365, board-dm644x and board-dm646x under mach-davinci. So it did not even occur to us that we need to modify anything in mach-davinci. Should we modify mach-omap2 or mach-davinci?

    We have verified that it is board-dm385ipnc.c that is in use in the kernel. Removing board-ti8148evm from defconfig does not affect the functionality of IPNC app.

    I have uploaded the Makefile form mach-omap2 (We didn't change anything in the mach-davinci folder), along with the kernel .config, and the defconfig. A gz file of the entire mach-omap2 folder is also uploaded to https://drive.google.com/folderview?id=0ByUeMB5A_r1QaXA3ZjFQNS04MVE&usp=sharing.

    Any issue you may spot from the uploaded materials will be appreciated. Thanks in advance!
  • Ohh.
    Then better you can use "mach-omap2" folder.
    I will look into it your attachments.
  • Hi User,

    I am working with DM814x device. By default I have i2c-1 and i2c-3 enabled:

    root@dm814x-evm:~# i2cdetect -l
    i2c-1 i2c OMAP I2C adapter I2C adapter
    i2c-3 i2c OMAP I2C adapter I2C adapter

    And I enable i2c-2 by just updating the board-ti8148evm.c file like below:

    +static struct i2c_board_info __initdata ti814x_i2c_boardinfo2[] = {
    + {
    + I2C_BOARD_INFO("test_i2c", 0x21),
    + },
    +
    +};

    static void __init ti814x_evm_i2c_init(void)
    {
    /* There are 4 instances of I2C in TI814X but currently only one
    * instance is being used on the TI8148 EVM
    */
    omap_register_i2c_bus(1, 100, ti814x_i2c_boardinfo,
    ARRAY_SIZE(ti814x_i2c_boardinfo));
    omap_register_i2c_bus(3, 100, ti814x_i2c_boardinfo1,
    ARRAY_SIZE(ti814x_i2c_boardinfo1));
    +omap_register_i2c_bus(2, 100, ti814x_i2c_boardinfo2,
    + ARRAY_SIZE(ti814x_i2c_boardinfo2));
    }

    During boot up I have:
    omap_i2c omap_i2c.1: bus 1 rev4.0 at 100 kHz
    omap_i2c omap_i2c.3: bus 3 rev4.0 at 100 kHz
    omap_i2c omap_i2c.2: bus 2 rev4.0 at 100 kHz

    And after boot up:
    root@dm814x-evm:~# i2cdetect -l
    i2c-1 i2c OMAP I2C adapter I2C adapter
    i2c-3 i2c OMAP I2C adapter I2C adapter
    i2c-2 i2c OMAP I2C adapter I2C adapter

    I think you should modify the board-dm385evm.c file for DM388 device (which is also known as DM813x/TI813x) like below:

    static struct i2c_board_info __initdata dm813x_i2c_boardinfo2[] = {
    {
    I2C_BOARD_INFO("i2c_test", 0x20),
    },

    };

    static void __init ti814x_evm_i2c_init(void)
    {
    /* There are 4 instances of I2C in TI814X but currently only one
    * instance is being used on the TI8148 EVM
    */
    omap_register_i2c_bus(1, 100, ti814x_i2c_boardinfo,
    ARRAY_SIZE(ti814x_i2c_boardinfo));
    omap_register_i2c_bus(3, 100, dm813x_i2c_boardinfo1,
    ARRAY_SIZE(dm813x_i2c_boardinfo1));
    omap_register_i2c_bus(2, 100, dm813x_i2c_boardinfo2,
    ARRAY_SIZE(dm813x_i2c_boardinfo2));

    }

    Have you tried this? Please note I am using dm813x (not ti814x) in the board-dm385evm.c file.

    BR
    Pavel
  • Hi Pavel,

    Thanks for sharing your code. It sort of gives us a confirmation that we are on the right track, as our modification is almost identical to the code you posted (except the board information that is programmed to take our own slave device instead).

    Before our modification, DM388 has i2c-1 enabled by default. After modification, we still only get i2c-1 when executing i2cdetect -l. What we were hoping for is to see a new i2c-x bus device node that grants us access to the slave device connecting to I2C2_SCL and I2C2_SDA.

    I am wondering if it is not too much to ask, would you take a peak at our code? I have uploaded the defconfig, .config, kernel Makefile and the tar ball of the entire mach-omap2 directory to https://drive.google.com/folderview?id=0ByUeMB5A_r1QaXA3ZjFQNS04MVE&usp=sharing. In mach-omap2 directory, I only made changes to board-dm385ipnc.c (to add ti814x_i2c_boardinfo2[] and to modify ti814x_evm_i2c_init()) and devices.c (to add ti814x_enable_i2c1() and to modify omap2_init_devices(), which we only modified after going through one of the links included in your very first response).

    Best regards,
    Henry
  • Henry,

    Could you please provide me (as attachment here) your board-dm385ipnc.c file. Could you also check if you have board-dm385evm.c file in your mach-omap2 folder or it is only board-dm385ipnc.c? Also attach a log file of your kernel boot up process.

    BR
    Pavel
  • Also make sure you are building the linux kernel with dm385_evm_defconfig, see below wiki page for more info:

    http://processors.wiki.ti.com/index.php/TI81XX_PSP_User_Guide#TI813X

    BR
    Pavel
  • Hi Pavel,.

    What is the easiest way to attach non-media files in this forum? I couldn't find the "attach file" option, only insert media and stylized code, but the files are too big to be pasted as stylized text. Before I find out the best way to attach files to a post/reply, here are the links to the two uploaded files you requested: board-dm385ipnc.c and ipnc.log.

    There is indeed a board-dm385evm.c in mach-omap2 folder, but it was not set in the defconfig I am using, so it was not compiled during the build process. We didn't make any change to that source code file.

    We will try to use the defconfig for dm385 evm and see what happens there.

    Thanks.

  • Hi Pavel,

    We have just completed the switching to dm385_evm_defconfig for building the kernel. We still only got i2c-1, and the boot console log shows only a single entry for i2c-1 too.

    We didn't make any modification to board-dm385evm.c, while board-ti8148evm.c has the omap_register_i2c_bus(2...) and ti814x_i2c_boardinfo2[] we inserted while using dm388_ipnc_defconfig. (dm385_evm_defconfig was unmodified, original code from IPND_RDK ver. 3.8, which specifies board-dm385evm.c and board-ti8148evm.c are the board source code to be compiled for this configuration).

    We will next try modifying board-dm385evm.c to insert additional omap_register_i2c_bus and boardinfo and see what happens. But if it doesn't work, we're almost out of ideas. Anything other thoughts about that we could try that might fix this?

    Thanks.

    Best regards,
    Henry
  • Hi Henry,
    Maybe we have the same question.
    After modified the code ,I can get the I2C-2.But it always shows "omap_i2c omap_i2c.2: controller timed out".

    root@dm814x-evm:/# i2cdetect -l
    i2c-1 i2c OMAP I2C adapter I2C adapter
    i2c-2 i2c OMAP I2C adapter I2C adapter
    i2c-3 i2c OMAP I2C adapter I2C adapter

    BR
    Bob
  • Hey Bob,

    I think you're ahead of me. I am still attempting to get either /dev/i2c-2 or /dev/i2c-3 device node to appear in Linux.

    May I ask what did you modify to get those i2c buses? Did you do anything different from what I did in the post above?

    Best regards,
    Henry
  • Hi Henry,

    I modified the struct ti816x_i2c2_hwmod in omap_hwmod_81xx_data.c file as below,

    .omap_chip      = OMAP_CHIP_INIT(CHIP_IS_TI816X),------->.omap_chip      = OMAP_CHIP_INIT(CHIP_IS_TI814X |CHIP_IS_TI816X),

    You can try it.

    BR

    Bob

  • Hi Henry,

    But it shows "omap_i2c omap_i2c.2: controller timed out" during the boot up.

    Now I still don't know why.

    BR

    Bob

  • Dear all,

    In order to pinpoint the problem, I have 2 questions:

    1. Is it true that the invocation of omap_register_i2c_bus() is the only line needed to put i2c bus as a node on the device tree in Linux? Is there anything else that needs to be added or modified to make /dev/i2c-x appear?

    2. My understanding is that correctly setting pin_mux values is necessary to make the /dev/i2c-x function properly, in order to engage the slave devices. Is it correct to say that even if it is not setup correctly, the /dev/i2c-x device node should still appear, it just won't do anything when called upon?

    BR
    Henry
  • Hey Bob,

    Unfortunately I already had OMAP_CHIP_INIT(CHIP_IS_TI816X | CHIP_IS_TI814X | CHIP_IS_DM385) in my original code base. So it's got to be something else.

    Thanks for the suggestion though.

    BR
    Henry
  • Hey Bob,

    This is a thread I came upon when I was researching for the solution to my I2C2 issue. Maybe it will be of help.

    BR

    Henry

  • Henry,

    user4165218 said:
    What is the easiest way to attach non-media files in this forum? I couldn't find the "attach file" option, only insert media and stylized code, but the files are too big to be pasted as stylized text.

    You should first click on the "Use rich formatting" button (located in the right bottom corner in the Reply window) then drag and drop the file to be attached.

    user4165218 said:
    here are the links to the two uploaded files you requested: board-dm385ipnc.c 

    Regarding this board-dm385ipnc.c file, I see two issues:

    1. i2c-2 corresponds to i2c1 in datasheet and i2c1_scl/sda pins. But you enable i2c-3 pins (i2c2_scl/sda). See the below e2e thread for more info:

    2. You are still using ti814x instead of dm813x as I suggest you in the below post:

    BR
    Pavel

  • Henry,

    user4165218 said:
    1. Is it true that the invocation of omap_register_i2c_bus() is the only line needed to put i2c bus as a node on the device tree in Linux? Is there anything else that needs to be added or modified to make /dev/i2c-x appear?

    Please check how i2c-1 is registered in the kernel. See also instruction files in linux-kernel/Documentation/i2c/ See files like dev-interface

    user4165218 said:
    2. My understanding is that correctly setting pin_mux values is necessary to make the /dev/i2c-x function properly, in order to engage the slave devices. Is it correct to say that even if it is not setup correctly, the /dev/i2c-x device node should still appear, it just won't do anything when called upon?

    Yes, /dev/i2c-x appear even pins are not set correctly (tried on the DM814x TI EVM).

    BR
    Pavel

  • Hi Pavel,

    Thanks for the clarifications and the instructions.

    As our I2C device is connected to the i2c2_scl/sda pins, I guess that means what we really want to enable is /dev/i2c-3 instead of i2c-2. Thanks for pointing that out.

    I did rename ti814x boardinfo to dm813x boardinfo, but still got the same result, that's why I changed it back.

    BR
    Henry