How to Enable I2C on AML-S905X-CC Le Potato

Now that I’ve got home and checked it out, smbus2 seems to be just what I was looking for as I take those next few steps away from micro-controller land. Thanks for all the help!

Just for anybody else who runs into this issue, when I enable i2c-ao it is /dev/i2c-1, when it is merged it shows up as /dev/i2c-0. I had to switch it in my code when I merged.

1 Like

How can this be setup on boot, so I don’t need to enter it every time. Preferably with an accompanying chmod 666 to allow non root user access.

See the libretech-wiring-tool readme. You can use udev rules to change permissions for enumerated devices.

When I do sudo ldto enable i2c-b then i2cdetect shows my two connected devices at address 0d and 68. Everything works great. I have been doing this by hand and python commands for quite a while.

If I do sudo ldto merge i2c-b and reboot i2cdetect shows one device at addr 30. Nothing works. ldto active yields #Overlays active: with nothing listed. ldto active i2c-b just brings back the prompt. Then doing sudo ldto enable i2c-b , then ldto active shows i2c-b as active. However i2cdetect -y 1 shows only one device at location 30. nothing works, Reboot and i2cdetect shows one device at 30.

sudo ldto reset and reboot, then sudo ldto enable i2c-b, then i2cdetect -y now shows the two devices at 68 and 0d. Everything works.

All righty then… sudo ldto merge i2c-b then sudo ldto diff yields:
— CURRENT
+++ NEXT
@@ -8,6 +8,7 @@
model = “Libre Computer AML-S905X-CC”;

    aliases {
  •           i2c2 = "/soc/cbus@c1100000/i2c@87c0";
              mmc0 = "/soc/apb@d0000000/mmc@74000";
              mmc1 = "/soc/apb@d0000000/mmc@72000";
              mmc2 = "/soc/apb@d0000000/mmc@70000";
    

@@ -405,12 +406,14 @@
};

                    i2c@87c0 {
  •                           pinctrl-names = "default";
    
  •                           pinctrl-0 = <0x7f>;
                              compatible = "amlogic,meson-gxbb-i2c";
                              reg = <0x00 0x87c0 0x00 0x20>;
                              interrupts = <0x00 0xd6 0x01>;
                              #address-cells = <0x01>;
                              #size-cells = <0x00>;
    
  •                           status = "disabled";
    
  •                           status = "okay";
                              clocks = <0x03 0x16>;
                              phandle = <0x52>;
                      };
    

@@ -1037,6 +1040,11 @@
i2c_b {
phandle = <0x7f>;

  •                                   cfg {
    
  •                                           bias-pull-up;
    
  •                                           pins = "GPIODV_26\0GPIODV_27";
    
  •                                   };
    
  •                                   mux {
                                              groups = "i2c_sck_b\0i2c_sda_b";
                                              function = "i2c_b";
    

lines with @@ are blue
lines with + are green
line with - is red.

After merge, the I2C devices are detected in sequence relative to the device tree so I2C-1 becomes I2C-0 as the numbering is incremented.

interesting… so after the merge i2cdetect -y 0 does show the devices at 68 and 0d.
However still both my devices don’t work with an Input/output error. But they do work just fine if I remove the merge and do the sudo ltdo enable i2c-b

EDIT: So I had to go and edit my libs to use bus 0 now instead of 1. Now we are back to working. Those that follow should know the correct sequence is:

  1. Sudo ldto enable i2c-b
  2. sudo ldto merge i2c-b
  3. Reboot and test for permission denied i2cdetect -y 0
  4. sudo vi /lib/udev/rules.d/60-i2c-tools.rules
  5. KERNEL==“i2c-[0-9]*”, GROUP=“i2c”, MODE=“0666”
  6. Reboot and test for successful i2cdetect -y 0
  7. Change programs to use bus 0

You don’t need the enable. Just merge and use it.

I use a variable to set the bus number now to deal with this behavior. Only have to change it once. This is the issue that made me start taking advice about keeping “magic numbers” out of the code more seriously.

Raspberry Pi OS includes the raspi-config utility which has options for enabling/disabling I2C (as well as SPI, Serial Port, and 1-Wire). Do these selections have any effect on Libre boards like LePotato, or are they simply ignored?

I am guessing that these settings just set something in the config.txt file which Libre boards currently ignore, but Raspberry Pi boards read at power-up (and I’m also guessing that this entry in the config file just tells the Raspberry Pi to load a device tree overlay).

I am therefore guessing that the ldto commands referred to at the top of this thread are all that is needed to enable the I2C bus and the raspi-config utility should not be used for this purpose with LePotato. But, hoping someone can confirm this.

Yes, search for config.txt.

I can find no way to modify the buadrate for i2c. Once I’ve done ldto merged and rebooted, scope shows SCL at 100kHz. I’d like to up it possibly to 400kHz, but none of the rpi totorials seem to help.

I’m expecting something maybe like this:

sudo modprobe -r i2c_bcm2708
sudo modprobe i2c_bcm2708 baudrate=400000
sudo sh -c 'echo "options i2c_bcm2708 baudrate=400000\n" > /etc/modprobe.d/custom.conf

but I can’t seem to figure out the correct module for the aml-S905X-cc-V1.0-A

Clone the libretech-wiring-tool and add the clock-frequency field to the i2c node.

Ahh, thanks for the clues. For anyone looking for this topic, these are the steps I followed, some may possibly be able to be left out.

clone libretech-wiring-tool
cd libretech-wiring-tool
make
edit libre-computer/aml-s905x-cc/dt/i2c-ao.dts
add “clock-frequency = <400000>;” to overlay section in the fragment with target = <&i2c_AO>;
make
sudo ./ldto remove i2c-ao
sudo reboot
sudo ./ldto merge i2c-ao

and with that, the scope shows 400kHz clock on my connected i2c device when sudo i2cdetect -y 0

2 Likes

The remove command doesn’t appear to exist in the current library, what do I do?

There’s enable/disable that does not persist on reboot.

There’s reset which goes to default. There’s no concept of remove since you cannot remove a merge overlay.

Reset, reboot, merge again.

So I modified the device tree file in the wiring-tool folder after calling make, I just want to load this modified device tree. Do I still need to do a reset? I want to keep the other settings the same.

Yes, without a reset, it only merges which can be an issue if the nodes are not the same anymore. The old nodes will still exist from your previous version.

If I reset won’t that disable the I2C device I enabled by the top post?

Please read the libretech-overlay portion of the wiring tool documentation:

You are not understanding some concepts and sequences correctly and mixing the terms.

There’s a fundamental difference between enable/disable and merge/reset.