MDIO via GPIO

Hi,
we have connected a marvel switch 88E6352 to some GPIOs of the Apalis. The Apalis shall drive the mdio protocol in order to configure the switch. Basically we want to have an interface in C (in userspace) like:

read_phy_register(u8 phyAddr, u8 phyReg)

write_phy_register(u8 phyAddr, u8 phyReg, u16 data)

I have noticed the that there is a kernel driver called MDIO_BITBANG. Could this driver be used for this purpose? I have tried to configure it in DTS:

mdio0: mdio {
    pinctrl-0 = <&pinctrl_mdio_bitbang>;
    compatible = "virtual,mdio-gpio";
    #address-cells = <1>;
    #size-cells = <0>;
    gpios = <&gpio5 18 GPIO_ACTIVE_LOW
         &gpio6 15 GPIO_ACTIVE_LOW>;
    status = "okay";
};

after that:

find -name mdio
./bus/platform/devices/mdio
./devices/soc0/mdio
./firmware/devicetree/base/soc/aips-bus@02100000/ethernet@02188000/mdio
./firmware/devicetree/base/mdio

/sys/bus/mdio_bus/devices# ls
2188000.ethernet:07

What 's the interface of this driver? I currently do not know enough about the linux phy implementation.
Could the marvel kernel driver also be used together with the mdio-bitbang driver?
What would be the DTS configuration?
Actually I would prefer to use a manual read/write interface, as I already have code available what to write to the registers.
Sorry, this is not really a Toradex specific question, but maybe you could point me into the right direction.

Best,
Matthias

Dear @mkock,

Thank you for contacting support. I am looking into this, would like to get back you in a couple of days. Could you wait till that?

Dear @mkock,

Could you share a schematic of this connection with iMX6? It will help us to understand the interface and provide a solution for you.

Also, Could you share software version(uname -a) and carrier board details?

I found a few links related to this, meanwhile you go through it may help you.

https://community.nxp.com/thread/454977
https://forums.xilinx.com/t5/Embedded-Linux/zynq-and-marvell-dsa-88e6352-integration-device-tree/td-p/779400

Hi,
thanks. Carrier board is custom design.

uname -a
Linux apalis-imx6-prodigy 4.1.44-00005-gb97724d-dirty #16 SMP Mon Aug 12 15:22:57 CEST 2019 armv7l GNU/Linux

We also need to use the network interface of the apalis, so as I understand there is no way to use the onboard PHY to control the external marvel switch. MDC pin of the apalis is also not accessible. Thus we need to use GPIO bitbang. Thats 's why ETH.MDC and MDIO etc. of the switch are now connected to the GPIOs as can be seen in the image. The question is, if I can use the bitbang kernel driver for this purpose.
Maybe even implementing the MDIO protocol in bitbang from userspace could do it?

Dear @mkock,

Thank you for your reply. Please correct me if understood wrong, Ethernet MAC layer didn’t connect between iMX6 and marvel switch, only MDIO interface is connected.

At the moment I don’t have concrete information for your use case. We are guessing below suggestions would work

Option #1: First, you would try on-module PHY with the bitbang driver to test that on here. you need to enable CONFIG_MDIO_BITBANG.

We saw documentation for the compatible switch here: Documentation/devicetree/bindings/net/dsa/marvell.txt. This you would try, please refer an example on below links

http://git.toradex.com/cgit/linux-toradex.git/tree/arch/arm/boot/dts/imx6qdl-zii-rdu2.dtsi?h=toradex_4.14-2.0.x-imx-next#n54

http://git.toradex.com/cgit/linux-toradex.git/tree/arch/arm/boot/dts/imx6qdl-zii-rdu2.dtsi?h=toradex_4.14-2.0.x-imx-next#n622

Option #2: Write Kernel module GPIO to MDIO bit bang e.g. : https://osdn.net/projects/android-x86/scm/git/kernel/blobs/fcdcc79628a1919bde9acf239e364f65bab6327c/arch/powerpc/platforms/pasemi/gpio_mdio.c

Option #3: Write userspace GPIO to MDIO bit-bang by using Sysfs or Libsoc, please refer following documentation for various methods of accessing GPIO :
https://developer.toradex.com/knowledge-base/gpio-(linux)
https://www.toradex.com/community/questions/8573/acces-gpio-in-a-different-way.html

We are working on option 1, let you know the update as soon as we have something to share with you.

If you are looking 2nd Ethernet interface then Apalis iMX8 will be the first module in the Apalis form factor which features a second Ethernet MAC. This module has a second RGMII/RMII (including MDIO/MDC) interface on the module edge connector. This allows having a secondary Ethernet PHY on the carrier board.

Dear @raja.tx,
thank you very much for your support!
Yesterday I already successfully implemented option 2, GPIO to MDIO bit-bang from userspace via Sysfs. It works and the switch now also works.
Of course this solution is not very efficient or fast, but performance is not so critical. Anyway, using a Kernel driver would be nicer, thanks for the link to the android driver. So if you have information how to make this driver work with linux, I would be happy to try it out.
Best,
Matthias

Perfect that you found a solution.

Regarding the android driver, I think you just need to customise it for linux and then it should work. General Information about writing kernel module is described here.

Best regards,
Jaski