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.

Linux/AM5718: U-Boot does not see more than one I2C

Part Number: AM5718

Tool/software: Linux

Dear Sir or Madame

We have a custom board and own custom .dts and .dtsi files (based on TI's evm and idk files)

Our PMIC (we use TPS6590379ZWSR) is connected to i2c4 (and not to i2c1 as in the original code)

Our problem is that when the palmas code try to find i2c4 it only find the first i2c and do not find the other i2c in it's device tree.

in function "palmas_i2c_write_u8" in file palmas.c we have changed the line from

ret = i2c_get_chip_for_busnum(0, chip_no, 1, &dev);

into

ret = i2c_get_chip_for_busnum(3, chip_no, 1, &dev);

and we get the following messages in the terminal (I have added some extra debug prints)

uclass_get_device_by_seq: id 31   seq 3
uclass_find_device_by_seq: id 31   seq_or_req_seq 3  find_req_seq 0
uclass_find_device_by_seq: 0 3
uclass_find_device_by_seq: name i2c
   - 0 -1 'i2c@48070000'
uclass_find_device_by_seq:    - not found
uclass_find_device_by_seq: id 31   seq_or_req_seq 3  find_req_seq 1
uclass_find_device_by_seq: 1 3
uclass_find_device_by_seq: name i2c
   - 0 -1 'i2c@48070000'
uclass_find_device_by_seq:    - not found
i2c_get_chip_for_busnum: Cannot find I2C bus 3
palmas_i2c_write_u8: unable to get I2C bus. ret -19
tps65903x: 3 could not set LDO1 voltage.

Why does it not find the other three i2c's when searching for the class UCLASS_I2C?

Do they need to be probed in the code somehow ?

Our .dtsi file look like this

&i2c1 {
	status = "okay";
    pinctrl-names = "default";
};


&i2c2 {
	status = "okay";
    pinctrl-names = "default";
};


&i2c3 {
	status = "okay";
    pinctrl-names = "default";
	clock-frequency = <400000>;

	mcp_rtc: rtc@Df {
		compatible = "microchip,mcp7941x";
		reg = <0xDf>;
		interrupts-extended = <&crossbar_mpu GIC_SPI 2 IRQ_TYPE_EDGE_RISING>,
				      <&dra7_pmx_core 0x424>;
		interrupt-names = "irq", "wakeup";

		wakeup-source;
	};

	eeprom@a0{
		compatible = "atmel,24c256";
		reg = <0xA0>;
	};
};



&i2c4 {
	status = "okay";
    pinctrl-names = "default";
	clock-frequency = <400000>;

	tps659038: tps659038@48 {
		compatible = "ti,tps659038";
		reg = <0x48>;
		interrupts-extended = <&gpio2 19 IRQ_TYPE_LEVEL_HIGH
			       &dra7_pmx_core 0x418>;
		#interrupt-cells = <2>;
		interrupt-controller;
		ti,system-power-controller;
		ti,palmas-override-powerhold;

		tps659038_rtc: tps659038_rtc {
			compatible = "ti,palmas-rtc";
			interrupt-parent = <&tps659038>;
			interrupts = <8 IRQ_TYPE_EDGE_FALLING>;
			wakeup-source;
		};
	};
};

  • Hello Stefan,

    Can you apply this patch and retry?

    cd <Processor SDK>/board-support/u-boot-<version>/
    git apply 0001-AM57xx-Enable-i2c2-i2c3-i2c4-clocks.patch

    Best regards,
    Kemal

  • Hi Kemal

    Thanks for the patch, your patch switch on the clocks for the i2c but it wont mae the MLO to discover the i2c.

    I am not sure how the MLO sets ups it internal device tree (where it only adds the i2c1, I need to add i2c4 as well)

    The problem manifests it like this

    We changed the function call from 

     ret = i2c_get_chip_for_busnum(0, chip_no, 1, &dev);

    to

     ret = i2c_get_chip_for_busnum(3, chip_no, 1, &dev);

    in the function "int palmas_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp)" in file palmas.c

    This will make palmas to look for i2c bus 3 (i2c4) but if you follow the code deeper down

    -> i2c_get_chip_for_busnum in i2c-uclass.c

    -> uclass_get_device_by_seq in uclass.c

    -> uclass_find_device_by_seq in uclass.c

    This function will iterate over all aviable i2c's via the macro "uclass_foreach_dev"

    This maco will only find one i2c, that is i2c1 (dev->name'i2c@48070000)

    I guess the MLO adds i2c1 somewhere, so I guess i2c4 should be added at the same place as well.

    Regards Stefan

  • The following needs to be changed to use i2c4 instead of i2c1

    Switch on the Clocks, file arch/arm/mach-omap2/omap5/hw_data.c   stuct u32 const clk_modules_explicit_en_essential[] = {

    replace

    		(*prcm)->cm_l4per_i2c1_clkctrl,
    with
    		(*prcm)->cm_l4per_i2c1_clkctrl,
    		(*prcm)->cm_l4per_i2c2_clkctrl,
    		(*prcm)->cm_l4per_i2c3_clkctrl,
    		(*prcm)->cm_l4per_i2c4_clkctrl,
    

    Change palmas so it look for i2c4

    file drivers/power/palmas.c   function palmas_i2c_write_u8

    ret = i2c_get_chip_for_busnum(3, chip_no, 1, &dev);

    file drivers/power/palmas.c   function palmas_i2c_read_u8

    ret = i2c_get_chip_for_busnum(3, chip_no, 1, &dev);

    Change file arch/arm/dts/omap5-u-boot.dtsi

    so i2c4 is included

    &i2c1 {
    	u-boot,dm-spl;
    };
    
    &i2c2 {
    	u-boot,dm-spl;
    };
    
    &i2c3 {
    	u-boot,dm-spl;
    };
    
    &i2c4 {
    	u-boot,dm-spl;
    };
    

    Change in the (custom) board dtsi file so the pmic information is included for the i2c4

    &i2c4 {
    	status = "okay";
    	clock-frequency = <400000>;
    
    	tps659038: tps659038@58 {
    		compatible = "ti,tps659038";
    		reg = <0x58>;
    		interrupts-extended = <&gpio6 16 IRQ_TYPE_LEVEL_HIGH
    			       &dra7_pmx_core 0x418>;
    		#interrupt-cells = <2>;
    		interrupt-controller;
    		ti,system-power-controller;
    		ti,palmas-override-powerhold;
    
    		tps659038_pmic {
    			compatible = "ti,tps659038-pmic";
    

  • Hello Stefan,

    Thank you for providing the solution, but unfortunately I cannot find the palmas_i2c_read_u8 within drivers/power/palmas.c and also cannot find &i2c1 defined within the arch/arm/dts/omap5-u-boot.dtsi. Which Processor SDK version you are using? If you are fine with that, can you attach the changes you made as a patch?

    cd <Processor SDK>/board-support/u-boot-<version>/
    git diff > 0001-AM57xx-PMIC-on-i2c4.patch

    Best regards,
    Kemal

  • Hi

    I have some difficult to give you a patch at the moment, all our other Changes will be included, or is it possible to create patches on specific files ?

    $ pwd
    /home/bomill/project/u-boot

    $ find . | grep "palmas\.c"
    ./drivers/power/palmas.c
    ./drivers/power/pmic/palmas.c

    It is the first file

    $ pwd
    /home/bomill/project/u-boot

    $ find . | grep "omap5-u-boot\.dtsi"
    ./arch/arm/dts/omap5-u-boot.dtsi

    Compiler

    export CROSS_COMPILE=arm-linux-gnueabihf-
    export ARCH=arm

    u-boot

    downloaded from (www.denx.de/.../ ) 3 weeks ago

  • The changes in the ./drivers/power/palmas.c and ./drivers/power/pmic/palmas.c will be sufficient too. The command to generate the patch for specific files will be.

    cd /home/bomill/project/u-boot
    git diff drivers/power/palmas.c drivers/power/pmic/palmas.c > 0001-AM57xx-PMIC-on-i2c4-palmas.patch
  • Here it is

    I hope I got everything in it, I did not include the .dtsi file change because it is so custom specific

    Regards

    PS

    I had to add the patch as text, the texas "insert file" tool refuxes to add a file attachement with the file ending .patch

    diff --git a/arch/arm/dts/omap5-u-boot.dtsi b/arch/arm/dts/omap5-u-boot.dtsi
    index 1b1d765fae..035199b684 100644
    --- a/arch/arm/dts/omap5-u-boot.dtsi
    +++ b/arch/arm/dts/omap5-u-boot.dtsi
    @@ -104,3 +104,15 @@
     &i2c1 {
     	u-boot,dm-spl;
     };
    +
    +&i2c2 {
    +	u-boot,dm-spl;
    +};
    +
    +&i2c3 {
    +	u-boot,dm-spl;
    +};
    +
    +&i2c4 {
    +	u-boot,dm-spl;
    +};
    diff --git a/arch/arm/mach-omap2/omap5/hw_data.c b/arch/arm/mach-omap2/omap5/hw_data.c
    index c4a41db92a..25d122a13f 100644
    --- a/arch/arm/mach-omap2/omap5/hw_data.c
    +++ b/arch/arm/mach-omap2/omap5/hw_data.c
    @@ -416,10 +416,14 @@ void enable_basic_clocks(void)
     		(*prcm)->cm_wkup_gptimer1_clkctrl,
     		(*prcm)->cm_l3init_hsmmc1_clkctrl,
     		(*prcm)->cm_l3init_hsmmc2_clkctrl,
     		(*prcm)->cm_l4per_gptimer2_clkctrl,
     		(*prcm)->cm_wkup_wdtimer2_clkctrl,
     		(*prcm)->cm_l4per_uart3_clkctrl,
     		(*prcm)->cm_l4per_i2c1_clkctrl,
    +		(*prcm)->cm_l4per_i2c2_clkctrl,
    +		(*prcm)->cm_l4per_i2c3_clkctrl,
    +		(*prcm)->cm_l4per_i2c4_clkctrl,
     #ifdef CONFIG_DRIVER_TI_CPSW
     		(*prcm)->cm_gmac_gmac_clkctrl,
     #endif
    diff --git a/drivers/power/palmas.c b/drivers/power/palmas.c
    index 2584bea38d..98737e082f 100644
    --- a/drivers/power/palmas.c
    +++ b/drivers/power/palmas.c
    @@ -182,14 +182,14 @@ int palmas_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
     	struct udevice *dev;
     	int ret;
     
    -	ret = i2c_get_chip_for_busnum(0, chip_no, 1, &dev);
    +	ret = i2c_get_chip_for_busnum(3, chip_no, 1, &dev);
     	if (ret) {
    -		pr_err("unable to get I2C bus. ret %d\n", ret);
    +		pr_err("%s: unable to get I2C bus. ret %d\n", __func__, ret);
     		return ret;
     	}
     	ret = dm_i2c_reg_write(dev, reg, val);
     	if (ret) {
    -		pr_err("writing to palmas failed. ret %d\n", ret);
    +		pr_err("%s: writing to palmas failed. ret %d\n", __func__, ret);
     		return ret;
     	}
     	return 0;
    @@ -200,14 +200,14 @@ int palmas_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp)
     	struct udevice *dev;
     	int ret;
     
    -	ret = i2c_get_chip_for_busnum(0, chip_no, 1, &dev);
    +	ret = i2c_get_chip_for_busnum(3, chip_no, 1, &dev);
     	if (ret) {
    -		pr_err("unable to get I2C bus. ret %d\n", ret);
    +		pr_err("%s: unable to get I2C bus. ret %d\n", __func__, ret);
     		return ret;
     	}
     	ret = dm_i2c_reg_read(dev, reg);
     	if (ret < 0) {
    -		pr_err("reading from palmas failed. ret %d\n", ret);
    +		pr_err("%s: reading from palmas failed. ret %d\n", __func__, ret);
     		return ret;
     	}
     	*valp = (u8)ret;
    
    

  • Thank you very much! The changes you provide will be very useful for the others who has connected the PMIC to i2c4 line.