Commit a4ab91f4 authored by Paolo Abeni's avatar Paolo Abeni
Browse files

Merge branch 'add-ethernet-mac-support-for-spacemit-k1'

Vivian Wang says:

====================
Add Ethernet MAC support for SpacemiT K1

SpacemiT K1 has two gigabit Ethernet MACs with RGMII and RMII support.
Add devicetree bindings, driver, and DTS for it.

Tested primarily on BananaPi BPI-F3. Basic TX/RX functionality also
tested on Milk-V Jupiter.

I would like to note that even though some bit field names superficially
resemble that of DesignWare MAC, all other differences point to it in
fact being a custom design.

Based on SpacemiT drivers [1]. These patches are also available at:

https://github.com/dramforever/linux/tree/k1/ethernet/v12

[1]: https://github.com/spacemit-com/linux-k1x
====================

Link: https://patch.msgid.link/20250914-net-k1-emac-v12-0-65b31b398f44@iscas.ac.cn


Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parents 29fa7f9e e32dc7a9
Loading
Loading
Loading
Loading
+81 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
%YAML 1.2
---
$id: http://devicetree.org/schemas/net/spacemit,k1-emac.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: SpacemiT K1 Ethernet MAC

allOf:
  - $ref: ethernet-controller.yaml#

maintainers:
  - Vivian Wang <wangruikang@iscas.ac.cn>

properties:
  compatible:
    const: spacemit,k1-emac

  reg:
    maxItems: 1

  clocks:
    maxItems: 1

  interrupts:
    maxItems: 1

  mdio-bus:
    $ref: mdio.yaml#
    unevaluatedProperties: false

  resets:
    maxItems: 1

  spacemit,apmu:
    $ref: /schemas/types.yaml#/definitions/phandle-array
    items:
      - items:
          - description: phandle to syscon that controls this MAC
          - description: offset of control registers
    description:
      A phandle to syscon with byte offset to control registers for this MAC

required:
  - compatible
  - reg
  - clocks
  - interrupts
  - resets
  - spacemit,apmu

unevaluatedProperties: false

examples:
  - |
    #include <dt-bindings/clock/spacemit,k1-syscon.h>

    ethernet@cac80000 {
        compatible = "spacemit,k1-emac";
        reg = <0xcac80000 0x00000420>;
        clocks = <&syscon_apmu CLK_EMAC0_BUS>;
        interrupts = <131>;
        mac-address = [ 00 00 00 00 00 00 ];
        phy-handle = <&rgmii0>;
        phy-mode = "rgmii-id";
        pinctrl-names = "default";
        pinctrl-0 = <&gmac0_cfg>;
        resets = <&syscon_apmu RESET_EMAC0>;
        rx-internal-delay-ps = <0>;
        tx-internal-delay-ps = <0>;
        spacemit,apmu = <&syscon_apmu 0x3e4>;

        mdio-bus {
            #address-cells = <0x1>;
            #size-cells = <0x0>;

            rgmii0: phy@1 {
                reg = <0x1>;
            };
        };
    };
+48 −0
Original line number Diff line number Diff line
@@ -11,6 +11,8 @@ / {
	compatible = "bananapi,bpi-f3", "spacemit,k1";

	aliases {
		ethernet0 = &eth0;
		ethernet1 = &eth1;
		serial0 = &uart0;
	};

@@ -40,6 +42,52 @@ &emmc {
	status = "okay";
};

&eth0 {
	phy-handle = <&rgmii0>;
	phy-mode = "rgmii-id";
	pinctrl-names = "default";
	pinctrl-0 = <&gmac0_cfg>;
	rx-internal-delay-ps = <0>;
	tx-internal-delay-ps = <0>;
	status = "okay";

	mdio-bus {
		#address-cells = <0x1>;
		#size-cells = <0x0>;

		reset-gpios = <&gpio K1_GPIO(110) GPIO_ACTIVE_LOW>;
		reset-delay-us = <10000>;
		reset-post-delay-us = <100000>;

		rgmii0: phy@1 {
			reg = <0x1>;
		};
	};
};

&eth1 {
	phy-handle = <&rgmii1>;
	phy-mode = "rgmii-id";
	pinctrl-names = "default";
	pinctrl-0 = <&gmac1_cfg>;
	rx-internal-delay-ps = <0>;
	tx-internal-delay-ps = <250>;
	status = "okay";

	mdio-bus {
		#address-cells = <0x1>;
		#size-cells = <0x0>;

		reset-gpios = <&gpio K1_GPIO(115) GPIO_ACTIVE_LOW>;
		reset-delay-us = <10000>;
		reset-post-delay-us = <100000>;

		rgmii1: phy@1 {
			reg = <0x1>;
		};
	};
};

&uart0 {
	pinctrl-names = "default";
	pinctrl-0 = <&uart0_2_cfg>;
+48 −0
Original line number Diff line number Diff line
@@ -12,6 +12,8 @@ / {
	compatible = "milkv,jupiter", "spacemit,k1";

	aliases {
		ethernet0 = &eth0;
		ethernet1 = &eth1;
		serial0 = &uart0;
	};

@@ -20,6 +22,52 @@ chosen {
	};
};

&eth0 {
	phy-handle = <&rgmii0>;
	phy-mode = "rgmii-id";
	pinctrl-names = "default";
	pinctrl-0 = <&gmac0_cfg>;
	rx-internal-delay-ps = <0>;
	tx-internal-delay-ps = <0>;
	status = "okay";

	mdio-bus {
		#address-cells = <0x1>;
		#size-cells = <0x0>;

		reset-gpios = <&gpio K1_GPIO(110) GPIO_ACTIVE_LOW>;
		reset-delay-us = <10000>;
		reset-post-delay-us = <100000>;

		rgmii0: phy@1 {
			reg = <0x1>;
		};
	};
};

&eth1 {
	phy-handle = <&rgmii1>;
	phy-mode = "rgmii-id";
	pinctrl-names = "default";
	pinctrl-0 = <&gmac1_cfg>;
	rx-internal-delay-ps = <0>;
	tx-internal-delay-ps = <250>;
	status = "okay";

	mdio-bus {
		#address-cells = <0x1>;
		#size-cells = <0x0>;

		reset-gpios = <&gpio K1_GPIO(115) GPIO_ACTIVE_LOW>;
		reset-delay-us = <10000>;
		reset-post-delay-us = <100000>;

		rgmii1: phy@1 {
			reg = <0x1>;
		};
	};
};

&uart0 {
	pinctrl-names = "default";
	pinctrl-0 = <&uart0_2_cfg>;
+48 −0
Original line number Diff line number Diff line
@@ -11,6 +11,54 @@
#define K1_GPIO(x)	(x / 32) (x % 32)

&pinctrl {
	gmac0_cfg: gmac0-cfg {
		gmac0-pins {
			pinmux = <K1_PADCONF(0, 1)>,	/* gmac0_rxdv */
				 <K1_PADCONF(1, 1)>,	/* gmac0_rx_d0 */
				 <K1_PADCONF(2, 1)>,	/* gmac0_rx_d1 */
				 <K1_PADCONF(3, 1)>,	/* gmac0_rx_clk */
				 <K1_PADCONF(4, 1)>,	/* gmac0_rx_d2 */
				 <K1_PADCONF(5, 1)>,	/* gmac0_rx_d3 */
				 <K1_PADCONF(6, 1)>,	/* gmac0_tx_d0 */
				 <K1_PADCONF(7, 1)>,	/* gmac0_tx_d1 */
				 <K1_PADCONF(8, 1)>,	/* gmac0_tx */
				 <K1_PADCONF(9, 1)>,	/* gmac0_tx_d2 */
				 <K1_PADCONF(10, 1)>,	/* gmac0_tx_d3 */
				 <K1_PADCONF(11, 1)>,	/* gmac0_tx_en */
				 <K1_PADCONF(12, 1)>,	/* gmac0_mdc */
				 <K1_PADCONF(13, 1)>,	/* gmac0_mdio */
				 <K1_PADCONF(14, 1)>,	/* gmac0_int_n */
				 <K1_PADCONF(45, 1)>;	/* gmac0_clk_ref */

			bias-pull-up = <0>;
			drive-strength = <21>;
		};
	};

	gmac1_cfg: gmac1-cfg {
		gmac1-pins {
			pinmux = <K1_PADCONF(29, 1)>,	/* gmac1_rxdv */
				 <K1_PADCONF(30, 1)>,	/* gmac1_rx_d0 */
				 <K1_PADCONF(31, 1)>,	/* gmac1_rx_d1 */
				 <K1_PADCONF(32, 1)>,	/* gmac1_rx_clk */
				 <K1_PADCONF(33, 1)>,	/* gmac1_rx_d2 */
				 <K1_PADCONF(34, 1)>,	/* gmac1_rx_d3 */
				 <K1_PADCONF(35, 1)>,	/* gmac1_tx_d0 */
				 <K1_PADCONF(36, 1)>,	/* gmac1_tx_d1 */
				 <K1_PADCONF(37, 1)>,	/* gmac1_tx */
				 <K1_PADCONF(38, 1)>,	/* gmac1_tx_d2 */
				 <K1_PADCONF(39, 1)>,	/* gmac1_tx_d3 */
				 <K1_PADCONF(40, 1)>,	/* gmac1_tx_en */
				 <K1_PADCONF(41, 1)>,	/* gmac1_mdc */
				 <K1_PADCONF(42, 1)>,	/* gmac1_mdio */
				 <K1_PADCONF(43, 1)>,	/* gmac1_int_n */
				 <K1_PADCONF(46, 1)>;	/* gmac1_clk_ref */

			bias-pull-up = <0>;
			drive-strength = <21>;
		};
	};

	uart0_2_cfg: uart0-2-cfg {
		uart0-2-pins {
			pinmux = <K1_PADCONF(68, 2)>,
+22 −0
Original line number Diff line number Diff line
@@ -805,6 +805,28 @@ network-bus {
			#size-cells = <2>;
			dma-ranges = <0x0 0x00000000 0x0 0x00000000 0x0 0x80000000>,
				     <0x0 0x80000000 0x1 0x00000000 0x0 0x80000000>;

			eth0: ethernet@cac80000 {
				compatible = "spacemit,k1-emac";
				reg = <0x0 0xcac80000 0x0 0x420>;
				clocks = <&syscon_apmu CLK_EMAC0_BUS>;
				interrupts = <131>;
				mac-address = [ 00 00 00 00 00 00 ];
				resets = <&syscon_apmu RESET_EMAC0>;
				spacemit,apmu = <&syscon_apmu 0x3e4>;
				status = "disabled";
			};

			eth1: ethernet@cac81000 {
				compatible = "spacemit,k1-emac";
				reg = <0x0 0xcac81000 0x0 0x420>;
				clocks = <&syscon_apmu CLK_EMAC1_BUS>;
				interrupts = <133>;
				mac-address = [ 00 00 00 00 00 00 ];
				resets = <&syscon_apmu RESET_EMAC1>;
				spacemit,apmu = <&syscon_apmu 0x3ec>;
				status = "disabled";
			};
		};

		pcie-bus {
Loading