Add i2c device to dts

Hi,

I am using jetson nano 2gb dev kit.

What I want to do is to add i2c device(ad7991, PmodAD2) in dts. However, if the added an i2c device needs to be monitored , I am not sure I need to add i2c device under “i2cmux@70” which seems to monitor voltage/current of child i2c devices.

  1. De-compiling dtb
  • configured pin3,5 (7000c400, i2c bu1) for SDA/SCLK.
  1. Add a node of i2c regulators above the node of i2c@7000c400
/* add i2c regulator for vcc and vref */ 
	i2c_regulators {
		compatible = "simple-bus";
		#address-cells = <0x1>;
		#size-cells = <0x0>;

		fixedregulator@0 {
			status = "okay";
			compatible = "regulator-fixed";
			regulator-name = "fixed-supply";
			regulator-min-microvolt = <0x325aa0>;	/*3.3V */
			regulator-max-microvolt = <0x325aa0>;
			phandle = <0x122>;
		};

		fixedregulator@1 {
			status = "okay";
			compatible = "regulator-fixed";
			regulator-name = "fixed-supply";
			regulator-min-microvolt = <0x2625a0>;	/* 2.5V */
			regulator-max-microvolt = <0x2625a0>;
			phandle = <0x123>;
		};
	};
  1. add a node of i2c device (ad7991) under i2c@7000c400
ad7991@28 {
			compatible = "adi,ad7991";
			reg = <0x28>;
			vcc-supply = <0x122>;
			vref-supply = <0x123>;
		};

here is my modified dts.
output_30_1.dts (308.1 KB)

  1. Compile the changed dts to dtb.

  2. Check the configuration that I have changed.

/sys/bus/i2c/devices/i2c-1$ ls
1-0028        delete_device  i2c-dev  new_device  power      uevent
bus_clk_rate  device         name     of_node     subsystem
/sys/bus/i2c/devices/i2c-1/of_node$ ls
 ad7991@28         clock-names   dma-names   icm20628@68   linux,phandle   reset-names        status
'#address-cells'   clocks        dmas        interrupts    name            resets
 ak8963@0d         cm32180@48    gpio@20     iommus        phandle         rt5659.1-001a@1a
 clock-frequency   compatible    i2cmux@70   iqs263@44     reg            '#size-cells'

I am looking forward to hearing any feedback.

Thanks,
Jin

Any problem for your modification? Have a check the kernel message for checking the ad7991 device driver probe message.

Hi @ShaneCCC ,
I am pretty new to the Linux kernel, so I’m not sure how to use the ad7991 driver.
I found the driver here, [ad7991 driver](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/iio/adc/ad799x.c?id=HEAD).
Do I need to put this driver somewhere in the kernel or compile it? otherwise ,it is just the same as using other libs.
Thanks,

Hi,

I am not sure how to configure the ad7991 driver in the kernel. I see the driver in the downloaded source codes of kernel (kernel-4.9/drivers/iio/adc/).

What I have done so far:

  1. Once I configured dts and dtsi (from xsl sheet), I was able to check something about i2c-1.
    However, as I checked with “lsmod”, it does not show i2c driver(ad7991).
Module                  Size  Used by
binfmt_misc            13103  1
xt_conntrack            3609  1
ipt_MASQUERADE          2346  1
nf_nat_masquerade_ipv4     3111  1 ipt_MASQUERADE
nf_conntrack_netlink    29413  0
nfnetlink               7959  2 nf_conntrack_netlink
fuse                  104554  3
xt_addrtype             3670  2
iptable_filter          2481  1
iptable_nat             2882  1
nf_conntrack_ipv4      11992  2
nf_defrag_ipv4          1836  1 nf_conntrack_ipv4
nf_nat_ipv4             6712  1 iptable_nat
nf_nat                 20406  2 nf_nat_masquerade_ipv4,nf_nat_ipv4
nf_conntrack          106659  6 nf_conntrack_ipv4,nf_conntrack_netlink,nf_nat_masquerade_ipv4,xt_conntrack,nf_nat_ipv4,nf_nat
br_netfilter           16216  0
zram                   25920  4
overlay                48718  0
userspace_alert         5828  0
nvgpu                1589200  13
ip_tables              19441  2 iptable_filter,iptable_nat
x_tables               28951  5 ip_tables,iptable_filter,ipt_MASQUERADE,xt_addrtype,xt_conntrack

  1. Since I thought the i2c driver is not configured in the kernel, I have tried to configure the driver using

menuconfig

Navigated to “Device Drivers->Staging drivers->Analog to digital converters

[modified]

I found that # CONFIG_AD799X is not set

  1. check .config
#
# IIO staging drivers
#

# Analog to digital converters
#
# CONFIG_AD7266 is not set
# CONFIG_AD7291 is not set
# CONFIG_AD7298 is not set
# CONFIG_AD7476 is not set
# CONFIG_AD7791 is not set
# CONFIG_AD7793 is not set
# CONFIG_AD7887 is not set
# CONFIG_AD7923 is not set
# CONFIG_AD799X is not set <--here
# CONFIG_CC10001_ADC is not set
# CONFIG_HI8435 is not set
# CONFIG_INA2XX_ADC is not set
# CONFIG_LTC2485 is not set
# CONFIG_MAX1027 is not set
# CONFIG_MAX1363 is not set
# CONFIG_MCP320X is not set
# CONFIG_MCP3422 is not set
# CONFIG_NAU7802 is not set
# CONFIG_QCOM_SPMI_IADC is not set
# CONFIG_QCOM_SPMI_VADC is not set
# CONFIG_TI_ADC081C is not set
# CONFIG_TI_ADC0832 is not set
# CONFIG_TI_ADC12138 is not set
# CONFIG_TI_ADC128S052 is not set
# CONFIG_TI_ADC161S626 is not set
# CONFIG_TI_ADS1015 is not set
# CONFIG_TI_ADS8688 is not set
# CONFIG_VF610_ADC is not set

This is all the list of drivers in the .config

Do I just manually need to add “CONFIG_AD7991” in the .config?

Thanks,

You can add CONFIG_AD7291 to the …/kernel/kernel-4.9/arch/arm64/configs/tegra_defconfig to rebuild the kernel to enable it.

Hi @ShaneCCC

Thank you for your answer.
As I followed the instruction of u boot porting
I copied configs/_defconfig and created my defconfig, which is p3541_defconfig(sources/u-boot/configs/)
I am not sure if I can add CONFIG_AD799X=y or m in p3541_defconfig.
Otherwise, I must add CONFIG_AD799X to tegra_defconfig?

Thanks,
Jin

Why do you add it to u boot? You should add the driver to kernel.

Hi @ShaneCCC

I changed pinmux and I exported my pinmux to u-boot according to “Jetson Nano Platform Adaptation and Bring-up guide.pdf” and “Jetson Nano Developer kit 4-=pin Expansion Header Configuration.pdf”

In the section of “porting u-boot”, I created my own directory, “u-boot/board/nvidia/p3541”, that contains p3541.c and pinmux-config-p3541.h. Also, I created my own defconfig, "configs/p3541_defconfig ‘’. After all done, I thought I might use my own defconfig instead of tegra_defconfig

However, it seems only I could configure drivers in tegra_defconfig rather than my own defconfig in u-boot.

Thanks,

Yes, you should configure it by kernel configure.

@ShaneCCC Thank you for answering my question.
One more thing I have noticed is that I wanted to add an i2c device(ad799x) in the dts.

Since I had my own dts copied from tegra2010-p3541-0000 in “u-boot/arch/arm/dts/my own dts”, I thought I could use it to add an i2c device. However it did not work, so I guess it is also the same as above that I can only add a node of i2c device into dts in the kernel which is “/hardware/nvidia/platform/t210/batuu/kernel-dts/tegra210-p3448-0003-p3542-0000.dts” in my case. Once I added the node of i2c device, it seemed to work. I just configured the ad799x driver in tegra_defconfig, so I could see something in “/sys/bus/iio/devices/iio:device0”, but I’m not sure how I can verify my configuration of i2c driver is correct.

Thanks,