Setting I2C bus bit rate on Jetson TK1

I am trying to do some experiments to see how fast I can send data over an I2C line and still get reliable communications. According to the TRM I should be able to set the bit rate for the hardware I2C systems up to 1 Mhz using FM+. I have an logic analyzer hooked up to monitor the output of the some of the I2C lines. Specifically IC2-1 and IC2-4. I generated out the tegra123-pm375.dts from the dtb file on the jetson and saw that these settings for IC2-1 and IC2-4:

i2c@7000c400 {
	#address-cells = <0x1>;
	#size-cells = <0x0>;
	compatible = "nvidia,tegra124-i2c";
	reg = <0x7000c400 0x100>;
	interrupts = <0x0 0x54 0x4>;
	scl-gpio = <0x8 0x9d 0x0>;
	sda-gpio = <0x8 0x9e 0x0>;
	nvidia,memory-clients = <0xe>;
	status = "okay";
	clock-frequency = <0x186a0>;
};

i2c@7000d000 {
	#address-cells = <0x1>;
	#size-cells = <0x0>;
	compatible = "nvidia,tegra124-i2c";
	reg = <0x7000d000 0x100>;
	interrupts = <0x0 0x35 0x4>;
	nvidia,require-cldvfs-clock;
	scl-gpio = <0x8 0xce 0x0>;
	sda-gpio = <0x8 0xcf 0x0>;
	nvidia,memory-clients = <0xe>;
	status = "okay";
	clock-frequency = <0x61a80>;
	nvidia,bit-banging-xfer-after-shutdown;
};

The clock frequency for IC2-1 is set to 0x186a0=100000, and for IC2-4 it is 0x61a80=400000. I am opening up these ports and sending out a byte of data and measuring the time between clock pulses on the logic analyzer.


if ((deviceHandle = open(“/dev/i2c-1”, O_RDWR)) < 0) {
printf(“Error: Couldn’t open device! %d\n”, deviceHandle);
return 1;
}

// connect to arduino as i2c slave
if (ioctl(deviceHandle, I2C_SLAVE, deviceI2CAddress) < 0) {
	printf("Error: Couldn't find arduino on address!\n");
	return 1;
}

// begin transmission and request acknowledgement
readBytes = write(deviceHandle, buffer, 1);

When I measure the signal sent for both IC2-1 and IC2-4 they both match the set clock frequency in the dtb file. So I tried changing the frequency. At first I tried setting IC2-1 to be 400Khz. I regenerated the dtb file, rebooted and tried again, but I still got 100Khz. I then tried a couple of other changes, but nothing I do seems to change the frequency. I am still learning how to get around in linux, so it is entirely possible I am misunderstanding something here, but I thought the DTB was where you configured things like the bitrate of the I2C bus? Does anyone have any pointers on what I am doing wrong, because I am a bit stumped?

Thanks

Disclaimer: I might be totally wrong here…if so please correct/update me!

I do think that if you are using fastboot as bootloader, the dtb-files are stored in a partition that is read by fastboot (or perhaps the kernel) during booting. I.e. if you change them in /boot nothing is changed for fastboot as the partion with the dtb contents is not changed. I also think that this is not the way for u-boot, i.e. in the u-boot case, the files are read from /boot. Hence this is why some people change to u-boot (including me). With u-boot installed you can change what kernel you load, the dtb-files you use etc without a full re-flash.

I did change some DTB-files on another ARM-board I used in order to use several serial ports, and as far as I can remember this was a board with u-boot and I just changed the contents of the DTB-files (unpack/change/repack).

Maybe you are running u-boot already and my thoughts here are all wrong?

If not, I posted a way for how it could be changed without having to re-install all things you might have added after you flashed. Please have a look here: https://devtalk.nvidia.com/default/topic/784124/?comment=4344511

I am using fastboot. I actually tried to do what you discuss in the other post and switch to uboot using my cloned system.img, but I did not notice that forum post and it obviously did not work. So thanks for pointing that out to me. I had been worried about something like this because it seems as if my changes to the dtb were simply being ignored, but I was not sure why. I even tried re-flashing just my kernel with fastboot and since one of the first lines in its output is that it is copying the dtb I thought it should be okay. Now that I can see what I messed up when trying to switch to uboot I will give that a shot and see if it makes any difference. I wanted to switch to uboot anyway. I will post up what happens.

Switching to uboot worked. Once I did that I was able to run the exact same code and this time the I2C clock frequency was changed. Thanks for your help.

Perfect! Then we know this for fact. Glad I could help.