The Acme Systems shipping office will be closed for holidays from 14 august to 22 august

Acqua technical documentation

Set a unique eth0 MAC address on Acqua reading the on-board Microchip AT24MAC402 EEPROM

This article illustrates how to get the access to the Microchip at24mac402 I2C EEPROM chip available on the Acqua A5 SOM to get and set the unique eth0 MAC address using just the device tree binding

An Microchip AT24MAC402 chip is mounted by default on each Acqua A5 SoM.

This provides:

  • An unique 128-bit serial number
  • An unique and valid EUI-48 address
  • 2-Kbit of EEPROM

Here is where is located the chip:

and this is how is wired at the SAMA5D3x MPU:

To implements the I2C bus used to talk with the chip we have used some generic GPIO thus leaving the hardware I2C bus free for the user application.

This are the GPIO lines used:

Signal Description Atmel Line Acqua pin
SDA I2C data PE1 N.A.
SCK I2C clock PE2 N.A.
WP Write protect PE7 N.A.

The I2C bus is managed by a bit banging Linux driver and activated by the device tree file in that way:

/* Bit banging I2C wired on the Atmel MAC chip */

i2c3@ {
    compatible = "i2c-gpio";
    gpios = <&pioE 1 0 /* SDA */
             &pioE 2 0 /* SCK */
            >;
    i2c-gpio,delay-us = <4>;    /* ~178 kHz */
    #address-cells = <1>;
    #size-cells = <0>;
};

The I2C address is: 0x58

On this repository are available two simple utilities written in C language to read the MAC address and the Serial Number from user space:

Here is an example to use them:

    sudo ./at24mac
    FC:C2:3D:0D:A6:EB

    sudo ./at24serial
    0A70080064100460746CA000A0000000

Set the MAC address at bootstrap using a dts definition

With this method is possible to set the MAC address on eth0 during the boot time using just a device tree binding. When this method is active the EEPROM is not available from user space.

macb1: ethernet@f802c000 {
    compatible = "atmel,sama5d3-macb", "cdns,at91sam9260-macb", "cdns,macb";

    status = "okay";
    phy-mode = "rmii";
    #address-cells = <1>;
    #size-cells = <0>;

    nvmem-cells = <&eth0_addr>;
    nvmem-cell-names = "mac-address";

    phy0: ethernet-phy@1 {
        interrupt-parent = <&pioE>;
        interrupts = <30 IRQ_TYPE_EDGE_FALLING>;
        reg = <1>;
    };

    /*ethernet-phy@1 {
        reg = <0x1>;
    };*/
};

/* Bit banging internal I2C to manage the AT24MAC402 chip */

i2c3@ {
    compatible = "i2c-gpio";
    gpios = <&pioE 1 0 /* SDA */
             &pioE 2 0 /* SCK */
            >;
    i2c-gpio,delay-us = <4>;    /* ~178 kHz */
    #address-cells = <1>;
    #size-cells = <0>;

    /* EEPROM contains the eth0 MAC address */

    eeprom@58 {
        compatible = "atmel,24mac402";
        pagesize = <256>;
        read-only;
        reg = <0x58>;
        #address-cells = <1>;
        #size-cells = <1>;

        eth0_addr: eth-mac-addr@9A {
            reg = <0x0 0x06>;
        };
    };
};

Inside the Kernel menuconfig these two driver are requested:

CONFIG_EEPROM_AT24=y
CONFIG_I2C_GPIO=y

Links

Credits

Many thanks to Antonio Galea for his help to find this solution https://github.com/ant9000

Sergio Tanzilli
System designer, webmaster and Acme Systems co-founder

Personal email: tanzilli@acmesystems.it
Webpage: https://www.acmesystems.it
Github repositories: https://github.com/tanzilli and https://github.com/acmesystems
Telegram group dedicated to the Acme Systems boards: https://t.me/acmesystemssrl

Acqua technical documentation