ODROID-N2/C4 I2C Controller(Device Node) Information

In ODROID-N2/C4, there are 2 I2C controller, I2C-2 and I2C-3.

Here is the I2C controller information for our Ubuntu image.

Net Name I2C Register PCB Location SDA(#GPIO) SCL(#GPIO) Default Speed Device Node
I2C-2 0xFFD1D000 J2 (2×20 pins) GPIOX.17(#493) GPIOX.18(#494) 400 KHz /dev/i2c-2
I2C-3 0xFFD1C000 J2 (2×20 pins) GPIOA.14(#474) GPIOA.15(#475) 100 KHz /dev/i2c-3

By default, ODROID-N2/C4 are configured to load I2C drivers and you can find two I2C buses, I2C-2 and I2C-3, In order to switch them to generic GPIOs, fdtput command is required and this command can be installed with the package device-tree-compiler.

root@odroid:~# apt install device-tree-compiler

Checking current mode

The default configuration is for I2C buses and can be checked with fdtget command. In order to apply the change, the changed device tree file must be located in the boot directory and ODROID-N2/C4 must be rebooted.

ODROID-N2

I2C-2

root@odroid:~# fdtget /media/boot/meson64_odroidn2.dtb /soc/cbus@ffd00000/i2c@1d000 status
okay

I2C-3

root@odroid:~# fdtget /media/boot/meson64_odroidn2.dtb /soc/cbus@ffd00000/i2c@1c000 status
okay

They can be switched to GPIO from I2C when the value of status is disabled.

I2C bus -> GPIO pins

I2C-2

root@odroid:~# fdtput -t s /media/boot/meson64_odroidn2.dtb /soc/cbus@ffd00000/i2c@1d000 status disabled

I2C-3

root@odroid:~# fdtput -t s /media/boot/meson64_odroidn2.dtb /soc/cbus@ffd00000/i2c@1c000 status disabled

GPIO pins -> I2C bus

I2C-2

root@odroid:~# fdtput -t s /media/boot/meson64_odroidn2.dtb /soc/cbus@ffd00000/i2c@1d000 status okay

I2C-3

root@odroid:~# fdtput -t s /media/boot/meson64_odroidn2.dtb /soc/cbus@ffd00000/i2c@1c000 status okay
ODROID-C4

I2C-2

root@odroid:~# fdtget /media/boot/meson64_odroidc4.dtb /soc/cbus@ffd00000/i2c@1d000 status
okay

I2C-3

root@odroid:~# fdtget /media/boot/meson64_odroidc4.dtb /soc/cbus@ffd00000/i2c@1c000 status
okay

They can be switched to GPIO from I2C when the value of status is disabled.

I2C bus -> GPIO pins

I2C-2

root@odroid:~# fdtput -t s /media/boot/meson64_odroidc4.dtb /soc/cbus@ffd00000/i2c@1d000 status disabled

I2C-3

root@odroid:~# fdtput -t s /media/boot/meson64_odroidc4.dtb /soc/cbus@ffd00000/i2c@1c000 status disabled

GPIO pins -> I2C bus

I2C-2

root@odroid:~# fdtput -t s /media/boot/meson64_odroidc4.dtb /soc/cbus@ffd00000/i2c@1d000 status okay

I2C-3

root@odroid:~# fdtput -t s /media/boot/meson64_odroidc4.dtb /soc/cbus@ffd00000/i2c@1c000 status okay

After rebooting, your change will be applied and if i2c_meson_master is loaded then I2C bus 2 or 3 are running as I2C buses, this can be checked with the command lsmod command.

root@odroid:~# lsmod | grep i2c
i2c_meson_master       20480  0

You can unload the module if you want to use I2C gripped pins as on GPIO mode.

# Unload
root@odroid:~# modprobe -r i2c_meson_master
root@odroid:~# ll /dev/i2c*
ls: cannot access '/dev/i2c*': No such file or directory
 
# Load
root@odroid:~# modprobe i2c_meson_master
root@odroid:~# ll /dev/i2c*
crw-rw---- 1 root i2c 89, 2 Jan 11 12:09 /dev/i2c-2
crw-rw---- 1 root i2c 89, 3 Jan 11 12:09 /dev/i2c-3

In ODROID-N2/C4, I2C devices are mapped in /sys/bus/i2c/devices directory.

root@odroid:~# ll /sys/bus/i2c/devices
total 0
drwxr-xr-x 2 root root 0 Jan  1  1970 ./
drwxr-xr-x 4 root root 0 Jan  1  1970 ../
lrwxrwxrwx 1 root root 0 Jan 29  2018 3-0051 -> ../../../devices/platform/soc/ffd00000.cbus/ffd1c000.i2c/i2c-3/3-0051/
lrwxrwxrwx 1 root root 0 Jan 11 10:00 i2c-2 -> ../../../devices/platform/soc/ffd00000.cbus/ffd1d000.i2c/i2c-2/
lrwxrwxrwx 1 root root 0 Jan 11 10:01 i2c-3 -> ../../../devices/platform/soc/ffd00000.cbus/ffd1c000.i2c/i2c-3/

As an example, see the files in /sys/bus/i2c/devices/i2c-2 directory.

root@odroid:~# ll /sys/bus/i2c/devices/i2c-2/
total 0
drwxr-xr-x 4 root root    0 Jan 29  2018 ./
drwxr-xr-x 4 root root    0 Jan  1  1970 ../
--w------- 1 root root 4096 Jan 11 10:01 delete_device
lrwxrwxrwx 1 root root    0 Jan 11 10:00 device -> ../../ffd1d000.i2c/
drwxr-xr-x 3 root root    0 Jan 29  2018 i2c-dev/
-r--r--r-- 1 root root 4096 Jan 10 15:52 name
--w------- 1 root root 4096 Jan 11 10:01 new_device
lrwxrwxrwx 1 root root    0 Jan 11 10:01 of_node -> '../../../../../../firmware/devicetree/base/soc/cbus@ffd00000/i2c@1d000'/
drwxr-xr-x 2 root root    0 Jan 11 10:01 power/
lrwxrwxrwx 1 root root    0 Jan 29  2018 subsystem -> ../../../../../../bus/i2c/
-rw-r--r-- 1 root root 4096 Jan 29  2018 uevent

To know its properties in device tree, see of_node directory.

root@odroid:~# ll /sys/bus/i2c/devices/i2c-2/of_node/
total 0
-r--r--r--  1 root root  4 Jan 11 10:07 '#address-cells'
-r--r--r--  1 root root  4 Jan 11 10:07 '#size-cells'
drwxr-xr-x  2 root root  0 Jan 11 10:01  ./
drwxr-xr-x 13 root root  0 Jan 11 10:01  ../
-r--r--r--  1 root root  4 Jan 11 10:07  clock-frequency
-r--r--r--  1 root root  8 Jan 11 10:07  clock-names
-r--r--r--  1 root root  8 Jan 11 10:07  clocks
-r--r--r--  1 root root 23 Jan 11 10:07  compatible
-r--r--r--  1 root root 24 Jan 11 10:07  interrupts
-r--r--r--  1 root root  4 Jan 11 10:07  name
-r--r--r--  1 root root  4 Jan 11 10:07  phandle
-r--r--r--  1 root root  4 Jan 11 10:07  pinctrl-0
-r--r--r--  1 root root  4 Jan 11 10:07  pinctrl-1
-r--r--r--  1 root root 21 Jan 11 10:07  pinctrl-names
-r--r--r--  1 root root 16 Jan 11 10:07  reg
-r--r--r--  1 root root  5 Jan 11 10:07  status

You can change speed of each I2C node by editing /sys/bus/i2c/devices/i2c-{2,3}/device/speed file.

# To change I2C-2 clock from 400KHz to 100KHz
root@odroid:~# cat /sys/bus/i2c/devices/i2c-2/device/speed
400000
root@odroid:~# echo 100000 > /sys/bus/i2c/devices/i2c-2/device/speed
root@odroid:~# cat /sys/bus/i2c/devices/i2c-2/device/speed
100000
# To change I2C-3 clock from 100KHz to 400KHz
root@odroid:~# cat /sys/bus/i2c/devices/i2c-3/device/speed
100000
root@odroid:~# echo 400000 > /sys/bus/i2c/devices/i2c-3/device/speed
root@odroid:~# cat /sys/bus/i2c/devices/i2c-3/device/speed
400000
2020/03/19 11:27 · luke.go