[CV1][TX1] Ds2777 battery ic porting problem.

precondition:

ROM version R24.2.1
Customized carriy board
Customized kernel

Operational:

  1. Porting the ds2777 i2c driver to the TX1.

Problem:
The ds2777 driver can’t be detected successly.

logs:

May  7 03:23:06 tegra-ubuntu kernel: [    5.822141] tegra-i2c 7000c400.i2c: no acknowledge from address 0x42
May  7 03:23:06 tegra-ubuntu kernel: [    5.822204] ina3221x 1-0042: ina3221 reset failure status: 0xffffff87
May  7 03:23:06 tegra-ubuntu kernel: [    5.822341] ina3221x: probe of 1-0042 failed with error -121
May  7 03:23:06 tegra-ubuntu kernel: [    5.822645] tegra-i2c 7000c400.i2c: no acknowledge from address 0x43
May  7 03:23:06 tegra-ubuntu kernel: [    5.822704] ina3221x 1-0043: ina3221 reset failure status: 0xffffff87
May  7 03:23:06 tegra-ubuntu kernel: [    5.822818] ina3221x: probe of 1-0043 failed with error -121
<b>May  7 03:23:06 tegra-ubuntu kernel: [    5.822913] Error: Driver 'ds2777' is already registered, aborting...</b>
May  7 03:23:06 tegra-ubuntu kernel: [    5.823131] max77620-power-off max77620-power-off.4: Event recorder REG_NVERC : 0x0
May  7 03:23:06 tegra-ubuntu kernel: [    5.823505] FAN: coudln't get the regulator

tegra210-jetson-cv-power-tree-p2597-2180-a00.dtsi

i2c@7000c500 {
		battery_gauge: battery-gauge@34 {
			status = "okey";
			compatible = "maxim,ds2777";
			reg = <0x34>;
			maxim,design-capacity = <2500>;
			maxim,design-energy = <9500>;
			maxim,taper-rate = <50>;
			maxim,terminate-voltage = <3400>;
			maxim,v-at-chg-term = <4350>;
			maxim,tz-name = "Battery";
		};
	};

ds2777_battery.c

#ifdef CONFIG_OF
static const struct of_device_id ds2777_dt_match[] = {
	{ .compatible = "maxim,ds2777" },
	{ },
};
MODULE_DEVICE_TABLE(of, ds2777_dt_match);
#endif

static const struct i2c_device_id ds2777_id[] = {
	{ "ds2777", 0 },
	{ }
};
MODULE_DEVICE_TABLE(i2c, ds2777_id);

static struct i2c_driver ds2777_i2c_driver = {
	.driver	= {
		.name	= "ds2777",
		.of_match_table = of_match_ptr(ds2777_dt_match),
		.pm = &ds2777_pm_ops,
	},
	.probe		= ds2777_probe,
	.remove		= ds2777_remove,
	.id_table	= ds2777_id,
	.shutdown	= ds2777_shutdown,
};


static int __init ds2777_init(void)
{
	return i2c_add_driver(&ds2777_i2c_driver);
}

fs_initcall_sync(ds2777_init);

static void __exit ds2777_exit(void)
{
	i2c_del_driver(&ds2777_i2c_driver);
}


module_init(ds2777_init);
module_exit(ds2777_exit);

Hi
You may have other driver use the same name “ds2777”, try modify the ds2777 to any others string to try.

hi ShaneCCC:

Is that problem? there are two init declaration in the driver.

module_init(ds2777_init);
and
fs_initcall_sync(ds2777_init);

hi ShaneCCC:

What is the register address of the i2c bus3.
Is it 7000c500 or 7000c700?

thanks.

hi ShaneCCC:

Is that mean PM using i2c bus 3?

I2C_PM_CLK A6 GEN3_I2C_SCL L32 J31 unused_GEN3_I2C_SCL
I2C_PM_DAT B6 GEN3_I2C_SDA N36 L34 unused_GEN3_I2C_SDA

    aliases {
            i2c0 = "/i2c@7000c000";
            i2c1 = "/i2c@7000c400";
            i2c2 = "/i2c@7000c500";
            i2c3 = "/i2c@7000c700";
            i2c4 = "/i2c@7000d000";
            i2c5 = "/i2c@7000d100";

The GEN3 should be the i2c2

hi ShaneCCC:

In my dtb file the i2c aliases is like that.
Does Nv have registers dataseet could release to OEM?

18 “arch/arm64/boot/dts/tegra210-soc-shield.dtsi” 2

/ {
aliases {
i2c0 = &i2c1;
i2c1 = &i2c2;
i2c2 = &i2c3;
i2c3 = &i2c4;
i2c4 = &i2c5;
i2c5 = &i2c6;
i2c6 = &i2c7;
spi0 = &spi0;
spi1 = &spi1;
spi2 = &spi2;
spi3 = &spi3;
qspi6 = &qspi6;

I’m reference to below file.

u-boot/arch/arm/dts/tegra210-p2571.dts

hi ShaneCCC:

I found max77620 probe sucessfully.
May 6 05:40:13 tegra-ubuntu kernel: [ 1.030410] max77620 4-003c: max77620 probe successfully.

And My ds2777 init function is called, but probe function is not called.

May 6 05:40:13 tegra-ubuntu kernel: [ 1.729348] [CV1] ds2777_init entry

static int __init ds2777_init(void)
{
	printk(KERN_ERR "[CV1] ds2777_init entry\n");
	return i2c_add_driver(&ds2777_i2c_driver);
}

hi ShaneCCC:

Do you know why that the bq27441 is not defined in tegra210-jetson-cv-base-p2597-2180-a00.dtb
But the of_register have its info.

I define the ds2777 in the dtb, but there is not this trace?

4319 [0271.615] of_register: registering tegra_udc to of_hal
4320 [0271.620] of_register: registering inv20628-driver to of_hal
4321 [0271.626] of_register: registering ads1015-driver to of_hal
4322 [0271.631] of_register: registering lp8557-bl-driver to of_hal
4323 [0271.637] of_register: registering bq2419x_charger to of_hal
4324 [0271.642] of_register: registering cpc to of_hal
4325 [0271.647] of_register: registering bq27441_fuel_gauge to of_hal
4327 [0271.665] of_register: registering tca9539_gpio to of_hal
4328 [0271.670] of_register: registering tca9539_gpio to of_hal
4329 [0271.676] of_register: registering i2c_bus_driver to of_hal
4330 [0271.681] of_register: registering i2c_bus_driver to of_hal
4331 [0271.687] of_register: registering i2c_bus_driver to of_hal
4333 [0271.696] of_register: registering max77620_pmic to of_hal
4335 [0271.705] of_register: registering tps65132_bl_driver to of_hal
4336 [0271.711] of_register: registering tegra_xhci to of_hal

hi ShaneCCC:

Could you tell me how to add a i2c device on TX1?

Hi ShaneCCC:

The i2c driver detection problem reason is status keyword wrote wrongly.
Please keep support this case for porting ds2777.

i2c@7000c700 {
		ds2777: ds2777@34 {
			compatible = "maxim,ds2777";
			reg = <0x34>;
			maxim,design-capacity = <2500>;
			maxim,design-energy = <9500>;
			maxim,taper-rate = <50>;
			maxim,terminate-voltage = <3400>;
			maxim,v-at-chg-term = <4350>;
			maxim,tz-name = "Battery";
			status = "<b>okay</b>";
		};
	};

Hi ShaneCCC:

Could you please help us confirm the i2c3 register?

I found the define in the dtb file

.tegra210-jetson-cv-base-p2597-2180-a00.dtb.dts

i2c3: i2c@7000c500 {
  #address-cells = <1>;
  #size-cells = <0>;
  compatible = "nvidia,tegra210-i2c";
  reg = <0x0 0x7000c500 0x0 0x100>;
  interrupts = <0 92 0x04>;
  iommus = <&smmu 14>;
  status = "disabled";
  clock-frequency = <400000>;
 };

Hi zuoqiang
This should be the i2c2 = “/i2c@7000c500” that means it should be i2c-2 for the linux system.
The “i2c3:” it’s from 1 - 6 and sysfs is from 0 - 5, I guess the i2c3: only a label that should be disappear after compile to DTB file.

Hi shaneccc:

Thanks I had captured the single shows 0x34 on the i2c_pm_gen3 with i2c@7000c500 setting.

Hi ShaneCCC:

Could you tell me how to config i2c freq. I had tried this , but not working.

i2c3: i2c@7000c500 {
  #address-cells = <1>;
  #size-cells = <0>;
  compatible = "nvidia,tegra210-i2c";
  reg = <0x0 0x7000c500 0x0 0x100>;
  interrupts = <0 92 0x04>;
  iommus = <&smmu 14>;
  status = "disabled";
  clock-frequency = <<b>100000</b>>;
 };

hi ShaneCCC:

Should I config it like this?

i2c3: i2c@7000c500 {
#address-cells = <1>;
#size-cells = <0>;
compatible = “nvidia,tegra210-i2c”;
reg = <0x0 0x7000c500 0x0 0x100>;
interrupts = <0 92 0x04>;
iommus = <&smmu 14>;
status = “okay”;
clock-frequency = <100000>;
};

Double checked. it is working.

Gen1 i2c number