[BPI-R64] OpenWRT | I2C | i2c-gpio-custom | Kernel 4.19

I tried to use I2C for Kernel 4.19 and found this:

make menuconfig (line with Depends on: !LINUX_4_19 [=y] && GPIO_SUPPORT [=y])

Symbol: PACKAGE_kmod-i2c-gpio-custom [=n]
Type  : tristate
Prompt: kmod-i2c-gpio-custom   Custom GPIO-based I2C device
  Location:
    -> Kernel modules
(1)   -> I2C support
  Defined at tmp/.config-package.in:10447
  Depends on: !LINUX_4_19 [=y] && GPIO_SUPPORT [=y]
  Selects: PACKAGE_kmod-i2c-gpio [=y] && PACKAGE_kmod-i2c-core [=y]
  Selected by: MODULE_DEFAULT_kmod-i2c-gpio-custom [=n] && TARGET_PER_DEVICE_ROOTFS [=n] && m && MODULES [=y]

How to resolve that?

Well… This commit explain why gpio-custom has been removed:

I have not found the solution yet. Still cannot understand how to work with custom i2c sensors on a Kernel 4.19.

There is a schema of GPIO Pins: http://wiki.banana-pi.org/Getting_Started_with_R64#GPIO

Also I found this information in the kernel documentation (https://www.kernel.org/doc/Documentation/devicetree/bindings/i2c/i2c-gpio.txt):

Device-Tree bindings for i2c gpio driver

Required properties:
	- compatible = "i2c-gpio";
	- sda-gpios: gpio used for the sda signal, this should be flagged as
	  active high using open drain with (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)
	  from <dt-bindings/gpio/gpio.h> since the signal is by definition
	  open drain.
	- scl-gpios: gpio used for the scl signal, this should be flagged as
	  active high using open drain with (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)
	  from <dt-bindings/gpio/gpio.h> since the signal is by definition
	  open drain.

Optional properties:
	- i2c-gpio,scl-output-only: scl as output only
	- i2c-gpio,delay-us: delay between GPIO operations (may depend on each platform)
	- i2c-gpio,timeout-ms: timeout to get data

Deprecated properties, do not use in new device tree sources:
	- gpios: sda and scl gpio, alternative for {sda,scl}-gpios
	- i2c-gpio,sda-open-drain: this means that something outside of our
	  control has put the GPIO line used for SDA into open drain mode, and
	  that something is not the GPIO chip. It is essentially an
	  inconsistency flag.
	- i2c-gpio,scl-open-drain: this means that something outside of our
	  control has put the GPIO line used for SCL into open drain mode, and
	  that something is not the GPIO chip. It is essentially an
	  inconsistency flag.

Example nodes:

#include <dt-bindings/gpio/gpio.h>

i2c@0 {
	compatible = "i2c-gpio";
	sda-gpios = <&pioA 23 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
	scl-gpios = <&pioA 24 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
	i2c-gpio,delay-us = <2>;	/* ~100 kHz */
	#address-cells = <1>;
	#size-cells = <0>;

	rv3029c2@56 {
		compatible = "rv3029c2";
		reg = <0x56>;
	};
};

As I understand based on schema some strings should be corrected for the R64 like this:

sda-gpios = <&pioA 3 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
scl-gpios = <&pioA 5 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;

But I don’t understand what source file (or files) should be modified?

As document is named devicetree bindings you need to add this to dts(i) of board…here mt7622.dtsi or mt7622*bpi-r64.dts

I found all files you mentioned here:

target/linux/mediatek/files-4.19/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts
target/linux/mediatek/files-4.19/arch/arm64/boot/dts/mediatek/mt7622.dtsi

But I am completely not familiar with DTS and DTSI files and do not understand where I have to modify them…

@frank-w, could you explain me step by step what I have to change?

i have not written new nodes…only changed some nodes or ported from 1 kernel version to another…you need some more info about the gpio-device (i don’t have it)

at least you need something like this in dtsi

i2c0 {
  compatible = "i2c-gpio";
  reg= <address size>; //memory address and size for driver
  sda-gpios = <&pio 3 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>; //which gpio should  be used and which mode (active high or opendrain) for sda
  scl-gpios = <&pio 5 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>; //like sda now for scl
  status = "okay";
};

@Ivan_Revyakin,Have you successfully used I2C?

I can’t find the kmod-i2c-gpio-custom under “Kernel modules”–>“I2C support”.

{} kmod-i2c-core. I2C support
-
- kmod-i2c-algo-bit. I2C bit-banging interfaces
kmod-i2c-algo-pca. I2C PCA 9564 interfaces
kmod-i2c-algo-pcf. I2C PCF 8584 interfaces
<*> kmod-i2c-gpio. GPIO-based bitbanging I2C
kmod-i2c-mux. I2C bus multiplexing support
kmod-i2c-mux-gpio. GPIO-based I2C mux/switches
kmod-i2c-mux-pca9541. Philips PCA9541 I2C mux/switches
kmod-i2c-mux-pca954x. Philips PCA954x I2C mux/switches
kmod-i2c-pxa. Intel PXA I2C bus driver
kmod-i2c-smbus. SMBus-specific protocols helper
kmod-i2c-tiny-usb. I2C Tiny USB adaptor

As far as i see here

https://openwrt.org/packages/pkgdata/kmod-i2c-gpio-custom

You need to enable i2c-core and i2c-gpio before…then i2c-gpio-custom should be available

I got i2c working now. kmod-i2c-gpio-custom was removed from kernel 4.19, and not need that module anymore. Just enable i2c-core and i2c-gpio from “I2C support”, and enable I2C and mediatek I2C device from kernel_menuconfig.

Not need to modify dts, the i2c config from the default dts for bpi-r64 is correct.