[BPI-R2 Pro] mainline u-boot

Hi,

just a warning to no more use defconfig/DTS from evaluation board (evb) in upstream uboot because io-domain driver is about to be merged and EVB has different settings. Booting up this u-boot on R2Pro with the io-domains from EVB enabled will brick the hardware!

i sent a R2 specific DTS/defconfig to ML which should be used instead (already part of my uboot repo in 2023-10-bpi tree) which supports USB and SATA too.

[v2] board: rockchip: Add Bananapi R2Pro Board - Patchwork

Commits · frank-w/u-boot · GitHub

but we have also good news: there is upcoming network-support :wink: but i have not yet tested it as i need to look if mtk switch driver works here (because of port5 as cpu).

Wan-port needs iodomain vccio6 set to 1v8 and lan-ports can be left on 3v3 (vccio4), all other can be left on 3v3.

@hackpascal: i see that mac and switch driver are both in drivers/net/mtk_eth.c, is it possible to get mt7531BE working on rockchip board? the compatible matching is done with the ethernet-mac of the soc and not with the switch itself. then property “mediatek,switch” is read to determine the switch

edit: sent v2 without the mtk switch for now

regards Fank

I don’t have this board. But I believe you can copy only the mt7531 related code from mtk-eth for rockchip board to verify if it can work.

So there is no limit on port6 of switch like it was on linux and driver is able to setup port 5?

I’m not that deep in u-boot drivers,but it should be possible to separate switch driver from mac and match it via own compatible like in linux,or am i wrong? Currently switch init is triggered by mac init at the end.

but it looks like the switch currently needs some functions from soc/gmac (mii_read/write), so it is not that easy to separate the switch driver from the mac

currently i struggle on mtk_mii_rw which uses mtk_gmac_write / mtk_gmac_read and wait_for_bit_le32(priv->gmac_base + GMAC_PIAC_REG, ...

so access over the mtk gmac…is it possible to transform this to mtk_gsw_write/mtk_gsw_read (which do direct access)? or convert all mtk_mii_read/write to the gsw_read/write

mtk_mii_rw is just an implementation of mdio bus access. This mdio controller is part of the gmac.

mtk_mii_rw-based mtk_mii_{read,write}/mtk_mmd_{read,write} access to the CPU’s MDIO bus. These are the lowlevel mdio access that should be replaced with rockchip’s own implementation in your case.

mtk_mmd_ind_read/mtk_mmd_ind_write access to switch’s MDIO controller (mainly for early mtk’s soc which doesn’t support cl45 access on CPU’s mdio controller). You can just ignore these two functions.

mt7531_mii_rw and related mt7531_mii_ind_{read,write}/mt7531_mmd_ind_{read,write} are used to access switch’s internal PHYs, and external PHYs connected directly to mt7531’s mdio bus.
This is because mt7531’s mdio slave connected to the CPU only supports accessing to mt7531’s switch core registers. mt7531 has another mdio master to access these PHYs.
Since mt7531_mii_rw relies on CPU’s mdio access, there’s nothing to do for porting.

mt7530 mt7531

1 Like

My plan was separating the switch driver so it can be used independ of the mac, u-boot contains some functions to register the mdio bus (to be done in mtk_eth and rockchip gmac/eqos driver)

https://elixir.bootlin.com/u-boot/latest/source/common/miiphyutil.c#L90

And the switch driver should be able to use this bus somehow.

Register mdio in mac-driver (mtk and rockchip):

int read_callback(struct mii_dev *bus, int addr, int devad, int reg){}
int write_callback(struct mii_dev *bus, int addr, int devad, int reg, u16 value){}

priv->bus = mdio_alloc();
priv->bus->read = read_callback;
priv->bus->write = write_callback;
priv->bus->priv = priv->iobase;
//Maybe set a name: strcpy(priv->bus->name, "switch-mdio");
ret = mdio_register(priv->bus);

And access it from switch driver

 priv->bus = dev_get_parent_platdata(dev);

Access seems to be done directly via the priv member

u32 *reg = bus->priv;
setbits_le32(reg, ZYNQ_GEM_MDIO_NWCTRL_MDEN_MASK);

ret = bus->read(bus, addr, MDIO_DEVAD_NONE, reg);
if (ret < 0)
    return 1;

return bus->write(bus, addr, MDIO_DEVAD_NONE, reg, value);

Where i took this: https://marc.info/?l=u-boot&m=152286594411360&w=2 and https://elixir.bootlin.com/u-boot/latest/source/common/miiphyutil.c

seems like the rockchip driver (gmac_rockchip.c,dwc_eth_qos.c) not yet have any mdio bus defined.

gpio bitbang based mdio bus is also ok

https://elixir.bootlin.com/linux/latest/source/arch/arm64/boot/dts/rockchip/rk3568.dtsi#L193 https://elixir.bootlin.com/linux/latest/source/arch/arm64/boot/dts/rockchip/rk356x.dtsi#L674

	gmac0: ethernet@fe2a0000 {
	compatible = "rockchip,rk3568-gmac", "snps,dwmac-4.20a";
	reg = <0x0 0xfe2a0000 0x0 0x10000>;
	......

	mdio0: mdio {
		compatible = "snps,dwmac-mdio";
		#address-cells = <0x1>;
		#size-cells = <0x0>;
	};

	......
};

	gmac1: ethernet@fe010000 {
	compatible = "rockchip,rk3568-gmac", "snps,dwmac-4.20a";
	reg = <0x0 0xfe010000 0x0 0x10000>;
	......

	mdio1: mdio {
		compatible = "snps,dwmac-mdio";
		#address-cells = <0x1>;
		#size-cells = <0x0>;
	};

	......
};

I believe this is the mdio bus inside the gmac for rockchip

Yes it is in dts,but i do not see any code related to it to attach read/write function an register global mdio bus and read it back in switch driver

It’s created in: https://elixir.bootlin.com/linux/latest/source/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c#L333

and registered in: https://elixir.bootlin.com/linux/latest/source/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c#L531

1 Like

This is linux…but thx for looking into it

in uboot it seems to be done here

https://elixir.bootlin.com/u-boot/latest/source/drivers/net/dwc_eth_qos.c#L1585

I will try to attach to this mdio when i’m back home next weekend.

If interested this is my current state:

https://github.com/frank-w/u-boot/commits/2023-10-bpi-r2pro

Is mt753x c22 or c45?

for mtk_mii_rw path, cl22.
for mt7531_mii_rw, both

I can help to split the switch driver for upstream

R2pro gets support in mainline uboot 2024.01 with ethernet,sata and usb support

https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Pcie looks also good,but needs manual enabling of regulators before running pci enum

https://www.mail-archive.com/[email protected]/msg488399.html

Have not found time to look into switch driver yet, but wan-port is working as direct connected to gmac so not highest priority

I did this a year ago, port mt7531 driver for stock u-boot, it work perfect. I remember I took a screenshot in our QQ group

@frank-w you can try this sample code. mt753x.c (30.1 KB)

hi,

how do you trigger the code as the probe-function seems to be not linked (no full driver).

main problem is triggering the switch driver on probing the mdio bus…

edit: r2pro patch is now in u-boot/master

regards Frank