EMAC on port H Allwinner A20

Started by stocky, April 25, 2016, 11:37:40 AM

Previous topic - Next topic

stocky

Hi guys. I'm trying to enable EMAC on portH pins (8-11, 14-27) but with no success. This is my script.fex with the emac_para part:

[emac_para]
emac_used = 1
emac_rxd3 = port:PH08<3><default><default><default>
emac_rxd2 = port:PH09<3><default><default><default>
emac_rxd1 = port:PH10<3><default><default><default>
emac_rxd0 = port:PH11<3><default><default><default>
emac_txd3 = port:PH14<3><default><default><default>
emac_txd2 = port:PH15<3><default><default><default>
emac_txd1 = port:PH16<3><default><default><default>
emac_txd0 = port:PH17<3><default><default><default>
emac_rxclk = port:PH18<3><default><default><default>
emac_rxerr = port:PH19<3><default><default><default>
emac_rxdV = port:PH20<3><default><default><default>
emac_mdc = port:PH21<3><default><default><default>
emac_mdio = port:PH22<3><default><default><default>
emac_txen = port:PH23<3><default><default><default>
emac_txclk = port:PH24<3><default><default><default>
emac_crs = port:PH25<3><default><default><default>
emac_col = port:PH26<3><default><default><default>
emac_reset = port:PH27<1><default><default><default>


Even with these settings, during boot, the board says: "starting emac using mii phy ot portA". Anyone succeeded with enabling EMAC on portH?

corkz

It doesn't work because the driver isn't set up to use port H.  You need to modify sunxi_emac.c and sunxi_emac.h to support it.

sunxi_emac.c at line 373 add this:

/* Set function for PH, if emac_used == 3 configure PH for emac, else
   make sure it is *not* set for emac */

        for (i = 8; i <= 11; i++)
                emac_gpio_pin_function(db, PH_CFG0_REG, i, 3, emac_used == 3);

        for (i = 14; i <= 27; i++)
                emac_gpio_pin_function(db, PH_CFG0_REG, i, 3, emac_used == 3);


At 1831ish (my spacing might be off) you'll find:


if (emac_used != 1 && emac_used != 2) {

Change to:

if (emac_used != 1 && emac_used != 2 && emac_used != 3) {


To support the new emac_used you added.

Now we need to add register define in sunxi_emac.h.  At line 87 add:


#define PH_CFG0_REG (0xfc)


In your fex file emac_used set to 3.  By setting it to 1 you've told the sunxi_emac driver to use portA.
That will start you off on getting the code support in the sunxi 3.4 branch to support portH for what you want, assuming you got the rest of the fex definitions right.  I didn't bother to look them up.

corkz

plagri

Hi,
I'm using EMAC on portH too.
I've made all in previous post, but when I boot and use command "dmesg | grep emac" I receive following:
root@A20:~# dmesg | grep emac
   sunxi_emac Using mii phy on PortC
   sunxi_emac Using MAC from SID: 02:18:06:81:e3:0c

As you see sunxi emac try to use portC, no portH
Please help me to resolve this problem!

Best Regards,
Plamen Gribachev


plagri

Hi Corkz,
I would like to note that I'm not succeeded in starting eth0.
I received following error after ifup eth0:

<3>sunxi_emac sunxi_emac.0: tx time out, resetting emac

In spite of all I can see eth0 after command:
ls /sys/class/net/
eth0  lo  tunl0


Regarding my previous post, I checked sunxi_emac driver code and  noticed that "portC" is result of simple debug message and don't determine exactly used port.

Please help me to use port H successfully!

Regards,
Plamen

corkz

It's been a while since I looked into this.  If I remember correctly there is something in sunxi_emac.c about setting up a delay before bringing up the device to deal with device limiting to 10mbps instead of 100mbps.  I know I ran into that issue when setting it up originally.  I also think I had to manually bring up the device, it wouldn't initialize by itself.  I know I ran into a few bugs trying to get it to work on port H but I was successful.  I just don't remember what/if I had to change in sunxi_emac.c.  When I posted my first reply it had already been months since I first worked on this.  I would look into some of the delays in that file and try increasing them.  The one work around for 10/100 initialization and the delay on phy power on maybe?

If you don't have any luck, or if you do let me know so we can put the problem to rest.  I will likely be returning to this project shortly any ways for a project I have to get back to work on.

corkz

Jonathan Fether

Just to note this, I am encountering similar issues with the A20-SOM204-1Ge16Gs16M-MC.

To try to resolve this issue, I made my script.fex use this:

[emac_para]
emac_used = 1
emac_rxd3 = port:PH08<3><default><default><default>
emac_rxd2 = port:PH09<3><default><default><default>
emac_rxd1 = port:PH10<3><default><default><default>
emac_rxd0 = port:PH11<3><default><default><default>
emac_txd3 = port:PH14<3><default><default><default>
emac_txd2 = port:PH15<3><default><default><default>
emac_txd1 = port:PH16<3><default><default><default>
emac_txd0 = port:PH17<3><default><default><default>
emac_rxclk = port:PH18<3><default><default><default>
emac_rxerr = port:PH19<3><default><default><default>
emac_rxdV = port:PH20<3><default><default><default>
emac_mdc = port:PH21<3><default><default><default>
emac_mdio = port:PH22<3><default><default><default>
emac_txen = port:PH23<3><default><default><default>
emac_txclk = port:PH24<3><default><default><default>
emac_crs = port:PH25<3><default><default><default>
emac_col = port:PH26<3><default><default><default>
emac_reset = port:PC18<1><default><default><default>


(on the SOM204, the reset pin for the LAN8710A PHY is on PC18; PH27 is connected to METXERR on this particular board)

If I get this to work I'll generate a pull request to https://github.com/linux-sunxi/linux-sunxi.

Looks like I'll have to rebuild the kernel via the main build system as well.

-Jon

JohnS

They will almost for sure want a DT solution, not fex.

John

Jonathan Fether

John,

  I did get a device tree overlay that works under mainline with the A20-SOM204's EMAC port. This is it:

/dts-v1/;
/plugin/;

/ {
compatible = "allwinner,sun7i-a20";

fragment@0 {
target = <&pio>;
__overlay__ {
emac_pins_b: emac0@1 {
pins = "PH8", "PH9", "PH10", "PH11",
       "PH14", "PH15", "PH16", "PH17",
       "PH18", "PH19", "PH20",
       "PH21", "PH22", "PH23", "PH24",
       "PH25", "PH26", "PH27";
function = "emac";
};
};
};

fragment@1 {
target = <&can0>;
__overlay__ {
pinctrl-0 = <>;
status = "disabled";
};
};

fragment@2 {
target = <&emac_sram>;
__overlay__ {
status = "okay";
};
};

fragment@3 {
target = <&mdio>;
__overlay__ {
status = "okay";
            phy1: ethernet-phy@1 {
            reset-gpios = <&pio 2 18 1>; // GPIO_ACTIVE_LOW
                reset-assert-us = <1000>;
            reset-deassert-us = <2000>;
        reg = <1>;
        };
};
};

fragment@4 {
target = <&emac>;
__overlay__ {
        pinctrl-names = "default";
        pinctrl-0 = <&emac_pins_b>;
        phy = <&phy1>;
        phy-supply = <&reg_vcc3v3>;
        status = "okay";
};
};

fragment@5 {
target = <&gmac>;
__overlay__ {
        status = "disabled";
};
};
};


Technically fragment #5 isn't necessary, but I've read about the A20's gmac and emac ports having operational conflict with each other. I don't need gmac on this particular board; it only has a port H emac. I didn't go far on testing the two together.

I still am having a problem with the link dying after being up a few minutes. Typing "ifconfig eth0 down;ifconfig eth0 up" brings connectivity back temporarily. Resetting the PHY has no effect on this, so the issue must be in the MAC.

I was using the Allwinner kernel (FEX based) because I am trying to use an LCD (LCD-OLinuXino-7TS) on this project and haven't yet gotten that to work on mainline. I would prefer to stay on mainline due to it having less quirkiness than the Allwinner kernel.

JohnS

I wonder if any of the mainlining places (er, linux-sunxi? armbian?) would be able to help.

You look close!

John