All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marek Behún" <kabel@kernel.org>
To: Stefan Roese <sr@denx.de>
Cc: "Robert Marko" <robert.marko@sartura.hr>,
	"Pali Rohár" <pali@kernel.org>,
	U-Boot-Denx <u-boot@lists.denx.de>,
	"Ramon Fried" <rfried.dev@gmail.com>,
	"Joe Hershberger" <joe.hershberger@ni.com>,
	"Marek Behún" <marek.behun@nic.cz>
Subject: [PATCH u-boot-marvell 07/19] arm: mvebu: turris_mox: Use DM registered MDIO
Date: Wed, 27 Apr 2022 12:41:50 +0200	[thread overview]
Message-ID: <20220427104202.1205-8-kabel@kernel.org> (raw)
In-Reply-To: <20220427104202.1205-1-kabel@kernel.org>

From: Marek Behún <marek.behun@nic.cz>

In order to be able to get rid of the non-DM MDIO bus registered in
mvneta driver, start using the DM registered one in Turris MOX board
code.

This also allows us to drop the hack introduced in MOX' -u-boot.dtsi
file.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
---
 .../dts/armada-3720-turris-mox-u-boot.dtsi    | 19 ----
 board/CZ.NIC/turris_mox/turris_mox.c          | 88 +++++++++----------
 2 files changed, 44 insertions(+), 63 deletions(-)

diff --git a/arch/arm/dts/armada-3720-turris-mox-u-boot.dtsi b/arch/arm/dts/armada-3720-turris-mox-u-boot.dtsi
index 28a36a6103..71d5e70ca4 100644
--- a/arch/arm/dts/armada-3720-turris-mox-u-boot.dtsi
+++ b/arch/arm/dts/armada-3720-turris-mox-u-boot.dtsi
@@ -3,25 +3,6 @@
  * 2022 by Marek Behún <kabel@kernel.org>
  */
 
-/ {
-	mdio {
-		#address-cells = <1>;
-		#size-cells = <0>;
-
-		old_binding_phy1: ethernet-phy@1 {
-			reg = <1>;
-		};
-	};
-};
-
-&eth0 {
-	pinctrl-0 = <&rgmii_pins>, <&smi_pins>;
-	/delete-property/ phy-handle;
-	phy = <&old_binding_phy1>;
-};
-
-/delete-node/ &mdio;
-
 &usb3 {
 	vbus-supply = <&exp_usb3_vbus>;
 };
diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c
index 9702d1fc78..a4738b3a3c 100644
--- a/board/CZ.NIC/turris_mox/turris_mox.c
+++ b/board/CZ.NIC/turris_mox/turris_mox.c
@@ -13,6 +13,7 @@
 #include <button.h>
 #include <clk.h>
 #include <dm.h>
+#include <dm/of_extra.h>
 #include <env.h>
 #include <fdt_support.h>
 #include <init.h>
@@ -216,35 +217,35 @@ static int mox_get_topology(const u8 **ptopology, int *psize, int *pis_sd)
 #define SW_SMI_CMD_R(d, r)	(0x9800 | (((d) & 0x1f) << 5) | ((r) & 0x1f))
 #define SW_SMI_CMD_W(d, r)	(0x9400 | (((d) & 0x1f) << 5) | ((r) & 0x1f))
 
-static int sw_multi_read(struct mii_dev *bus, int sw, int dev, int reg)
+static int sw_multi_read(struct udevice *bus, int sw, int dev, int reg)
 {
-	bus->write(bus, sw, 0, 0, SW_SMI_CMD_R(dev, reg));
+	dm_mdio_write(bus, sw, MDIO_DEVAD_NONE, 0, SW_SMI_CMD_R(dev, reg));
 	mdelay(5);
-	return bus->read(bus, sw, 0, 1);
+	return dm_mdio_read(bus, sw, MDIO_DEVAD_NONE, 1);
 }
 
-static void sw_multi_write(struct mii_dev *bus, int sw, int dev, int reg,
+static void sw_multi_write(struct udevice *bus, int sw, int dev, int reg,
 			   u16 val)
 {
-	bus->write(bus, sw, 0, 1, val);
-	bus->write(bus, sw, 0, 0, SW_SMI_CMD_W(dev, reg));
+	dm_mdio_write(bus, sw, MDIO_DEVAD_NONE, 1, val);
+	dm_mdio_write(bus, sw, MDIO_DEVAD_NONE, 0, SW_SMI_CMD_W(dev, reg));
 	mdelay(5);
 }
 
-static int sw_scratch_read(struct mii_dev *bus, int sw, int reg)
+static int sw_scratch_read(struct udevice *bus, int sw, int reg)
 {
 	sw_multi_write(bus, sw, 0x1c, 0x1a, (reg & 0x7f) << 8);
 	return sw_multi_read(bus, sw, 0x1c, 0x1a) & 0xff;
 }
 
-static void sw_led_write(struct mii_dev *bus, int sw, int port, int reg,
+static void sw_led_write(struct udevice *bus, int sw, int port, int reg,
 			 u16 val)
 {
 	sw_multi_write(bus, sw, port, 0x16, 0x8000 | ((reg & 7) << 12)
 					    | (val & 0x7ff));
 }
 
-static void sw_blink_leds(struct mii_dev *bus, int peridot, int topaz)
+static void sw_blink_leds(struct udevice *bus, int peridot, int topaz)
 {
 	int i, p;
 	struct {
@@ -275,7 +276,7 @@ static void sw_blink_leds(struct mii_dev *bus, int peridot, int topaz)
 	}
 }
 
-static void check_switch_address(struct mii_dev *bus, int addr)
+static void check_switch_address(struct udevice *bus, int addr)
 {
 	if (sw_scratch_read(bus, addr, 0x70) >> 3 != addr)
 		printf("Check of switch MDIO address failed for 0x%02x\n",
@@ -374,36 +375,22 @@ static void mox_phy_modify(struct phy_device *phydev, int page, int reg,
 static void mox_phy_leds_start_blinking(void)
 {
 	struct phy_device *phydev;
-	struct mii_dev *bus;
-	const char *node_name;
-	int node;
+	ofnode phy_node;
 
-	node = fdt_path_offset(gd->fdt_blob, "ethernet0");
-	if (node < 0) {
-		printf("Cannot get eth0!\n");
-		return;
-	}
+	phy_node = ofnode_get_phy_node(ofnode_path("ethernet0"));
+	if (!ofnode_valid(phy_node))
+		goto err;
 
-	node_name = fdt_get_name(gd->fdt_blob, node, NULL);
-	if (!node_name) {
-		printf("Cannot get eth0 node name!\n");
-		return;
-	}
-
-	bus = miiphy_get_dev_by_name(node_name);
-	if (!bus) {
-		printf("Cannot get MDIO bus device!\n");
-		return;
-	}
-
-	phydev = phy_find_by_mask(bus, BIT(1));
-	if (!phydev) {
-		printf("Cannot get ethernet PHY!\n");
-		return;
-	}
+	phydev = dm_phy_find_by_ofnode(phy_node);
+	if (!phydev)
+		goto err;
 
 	mox_phy_modify(phydev, 3, 0x12, 0x700, 0x400);
 	mox_phy_modify(phydev, 3, 0x10, 0xff, 0xbb);
+
+	return;
+err:
+	printf("Cannot get ethernet PHY!\n");
 }
 
 static bool read_reset_button(void)
@@ -611,6 +598,26 @@ int show_board_info(void)
 	return 0;
 }
 
+static struct udevice *mox_mdio_bus(void)
+{
+	struct udevice *bus;
+	ofnode node;
+
+	node = ofnode_by_compatible(ofnode_null(), "marvell,orion-mdio");
+	if (!ofnode_valid(node))
+		goto err;
+
+	dm_mdio_probe_devices();
+
+	if (uclass_get_device_by_ofnode(UCLASS_MDIO, node, &bus))
+		goto err;
+
+	return bus;
+err:
+	printf("Cannot get MDIO bus device!\n");
+	return NULL;
+}
+
 int last_stage_init(void)
 {
 	struct gpio_desc reset_gpio = {};
@@ -636,16 +643,9 @@ int last_stage_init(void)
 	 * 0x70 of Peridot (and potentially Topaz) modules
 	 */
 	if (peridot || topaz) {
-		struct mii_dev *bus;
-		const char *node_name;
-		int node;
+		struct udevice *bus = mox_mdio_bus();
 
-		node = fdt_path_offset(gd->fdt_blob, "ethernet0");
-		node_name = (node >= 0) ? fdt_get_name(gd->fdt_blob, node, NULL) : NULL;
-		bus = node_name ? miiphy_get_dev_by_name(node_name) : NULL;
-		if (!bus) {
-			printf("Cannot get MDIO bus device!\n");
-		} else {
+		if (bus) {
 			int i;
 
 			for (i = 0; i < peridot; ++i)
-- 
2.35.1


  parent reply	other threads:[~2022-04-27 10:44 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-27 10:41 [PATCH u-boot-marvell 00/19] some mvneta changes, cleanups, fixes Marek Behún
2022-04-27 10:41 ` [PATCH u-boot-marvell 01/19] net: mvneta: Get rid of platdata Marek Behún
2022-04-30 23:28   ` Ramon Fried
2022-05-02  6:48   ` Stefan Roese
2022-04-27 10:41 ` [PATCH u-boot-marvell 02/19] net: mvneta: Fix 10Mbps speed Marek Behún
2022-04-30 23:28   ` Ramon Fried
2022-05-02  6:48   ` Stefan Roese
2022-04-27 10:41 ` [PATCH u-boot-marvell 03/19] net: mvneta: Use DM MDIO API for connecting PHY Marek Behún
2022-04-30 23:28   ` Ramon Fried
2022-05-02  6:48   ` Stefan Roese
2022-04-27 10:41 ` [PATCH u-boot-marvell 04/19] net: mvneta: Remember fixed link instead of PHY address in priv data Marek Behún
2022-04-30 23:28   ` Ramon Fried
2022-05-02  6:48   ` Stefan Roese
2022-04-27 10:41 ` [PATCH u-boot-marvell 05/19] arm: mvebu: Espressobin: Use DM registered MDIO to configure switch Marek Behún
2022-05-02  6:48   ` Stefan Roese
2022-04-27 10:41 ` [PATCH u-boot-marvell 06/19] net: mdio-uclass: add dm_phy_find_by_ofnode() helper Marek Behún
2022-04-30 23:28   ` Ramon Fried
2022-05-02  7:00   ` Stefan Roese
2022-04-27 10:41 ` Marek Behún [this message]
2022-05-02  7:00   ` [PATCH u-boot-marvell 07/19] arm: mvebu: turris_mox: Use DM registered MDIO Stefan Roese
2022-04-27 10:41 ` [PATCH u-boot-marvell 08/19] net: mvneta: Don't register MDIO bus Marek Behún
2022-04-30 23:29   ` Ramon Fried
2022-05-02  7:01   ` Stefan Roese
2022-04-27 10:41 ` [PATCH u-boot-marvell 09/19] net: mvneta: Fix unused variable warning if DM_GPIO is disabled Marek Behún
2022-04-30 23:29   ` Ramon Fried
2022-05-02  7:01   ` Stefan Roese
2022-04-27 10:41 ` [PATCH u-boot-marvell 10/19] net: mvneta: Drop one indentation level in mvneta_adjust_link() Marek Behún
2022-04-30 23:29   ` Ramon Fried
2022-05-02  7:01   ` Stefan Roese
2022-04-27 10:41 ` [PATCH u-boot-marvell 11/19] net: mvneta: Use bool instead of int for boolean variable Marek Behún
2022-04-30 23:29   ` Ramon Fried
2022-05-02  7:01   ` Stefan Roese
2022-04-27 10:41 ` [PATCH u-boot-marvell 12/19] net: mvneta: Drop unnecessary space Marek Behún
2022-04-30 23:30   ` Ramon Fried
2022-05-02  7:01   ` Stefan Roese
2022-04-27 10:41 ` [PATCH u-boot-marvell 13/19] net: mvneta: Don't check for CONFIG_PHYLIB Marek Behún
2022-04-30 23:30   ` Ramon Fried
2022-05-02  7:02   ` Stefan Roese
2022-04-27 10:41 ` [PATCH u-boot-marvell 14/19] net: mvneta: Rename CONFIG_NR_CPUS to MVNETA_NR_CPUS Marek Behún
2022-04-30 23:30   ` Ramon Fried
2022-05-02  7:02   ` Stefan Roese
2022-04-27 10:41 ` [PATCH u-boot-marvell 15/19] net: mvneta: Convert to use PHY_FIXED for fixed-link Marek Behún
2022-04-30 23:31   ` Ramon Fried
2022-05-02  7:02   ` Stefan Roese
2022-04-27 10:41 ` [PATCH u-boot-marvell 16/19] net: mvneta: Write PHY address just before enabling HW polling Marek Behún
2022-04-30 23:31   ` Ramon Fried
2022-05-02  7:03   ` Stefan Roese
2022-04-27 10:42 ` [PATCH u-boot-marvell 17/19] net: mvneta: Drop fixed_link member from private struct Marek Behún
2022-04-30 23:31   ` Ramon Fried
2022-05-02  7:03   ` Stefan Roese
2022-04-27 10:42 ` [PATCH u-boot-marvell 18/19] net: mvneta: Disable fixed PHY code if PHY_FIXED is not compiled in Marek Behún
2022-04-30 23:32   ` Ramon Fried
2022-05-02  7:03   ` Stefan Roese
2022-04-27 10:42 ` [PATCH u-boot-marvell 19/19] net: mvneta: Drop unneeded macro Marek Behún
2022-04-30 23:32   ` Ramon Fried
2022-05-02  7:03   ` Stefan Roese
2022-05-02  5:39 ` [PATCH u-boot-marvell 00/19] some mvneta changes, cleanups, fixes Stefan Roese
2022-05-04  9:25 ` Stefan Roese

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220427104202.1205-8-kabel@kernel.org \
    --to=kabel@kernel.org \
    --cc=joe.hershberger@ni.com \
    --cc=marek.behun@nic.cz \
    --cc=pali@kernel.org \
    --cc=rfried.dev@gmail.com \
    --cc=robert.marko@sartura.hr \
    --cc=sr@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.