Bit-Banging for sofware i2c: which gpios to choose in HiKey960?

96boards

#1

My goal is to make a software i2c channel using gpios in HiKey960.
I cannot find any gpios with pull-up mode(not sure how to set it).
Also if I’m to use existing i2c SCL/SDA line for bit-banging, how to set the register configuration in .dtsi ?
From the Hi3660 spec, I can see that “I2C3 can be multiplexed as the common GPIO function” but unable to find the register config to enable for our purpose.

Any help appreciated . Thanks in advance.


#2

@guodong @Loic Any insight on this ?


#3

Hi @arjuntj,

First of all I’m curious to know why you are going for bit banging I2C :wink:

I’m not really sure about which pins support pull up mode, but for using the existing i2c lines for bitbanging you can use the following node in device tree [1]

i2c@0 {
compatible = "i2c-gpio";
gpios = <&gpio23 0 0 /* I2C0_SDA - GPIO_184*/
	     &gpio22 7 0 /* I2C0_SCL - GPIO_183*/
	     >;
i2c-gpio,sda-open-drain;
i2c-gpio,scl-open-drain;
i2c-gpio,delay-us = <2>;	/* ~100 kHz */
#address-cells = <1>;
#size-cells = <0>;
}

Note: Make sure to remove the existing I2C node to avoid conflict.

Hope this helps!

Thanks,
Mani

[1] https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/hisilicon/hi3660.dtsi


#4

Sorry, I stayed out of this one since I don’t know the specifics about how the hikey960 GPIO driver maps onto the LS connector. However, since @Mani has filled in that bit I’ll bite…

To be honest I doubt there is any GPIO on hikey960 that has suitable pull ups. Even if the GPIO unit itself does offer a pull up modes there’s no guarantee that these are of the correct strength for robust I2C. I’d recommend the simpler approach of using external pull ups.


#5

Thanks a lot for the update.
As I was facing some difficulty in getting the existing i2c lines to work on High speed mode, I thought of giving it a try with Bit-banging.
Now that I’m able to get the existing i2c lines to run on High-Speed mode, still would want to finish the bit-banging code I wrote.
I will give it a try with your settings for once and let you know the result. Once again Thanks.