linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Adrien Grassein <adrien.grassein@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: fugang.duan@nxp.com, davem@davemloft.net, kuba@kernel.org,
	robh+dt@kernel.org, netdev@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	Adrien Grassein <adrien.grassein@gmail.com>
Subject: [PATCH 2/3] net: fsl: fec: add mdc/mdio bitbang option
Date: Sat, 28 Nov 2020 23:54:24 +0100	[thread overview]
Message-ID: <20201128225425.19300-2-adrien.grassein@gmail.com> (raw)
In-Reply-To: <20201128225425.19300-1-adrien.grassein@gmail.com>

This patch adds the ability for the fec to use the
mdc/mdio bitbang protocol to communicate with its phy.

It adds two new optional parameters in the
devicetree definition for the two needed GPIO (mdc and mdio).

It uses the mdio-bitbang generic implementation.

Signed-off-by: Adrien Grassein <adrien.grassein@gmail.com>
---
 drivers/net/ethernet/freescale/fec.h      |  5 ++
 drivers/net/ethernet/freescale/fec_main.c | 91 ++++++++++++++++++++---
 2 files changed, 87 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h
index c527f4ee1d3a..84bf9be4c6f5 100644
--- a/drivers/net/ethernet/freescale/fec.h
+++ b/drivers/net/ethernet/freescale/fec.h
@@ -15,6 +15,7 @@
 /****************************************************************************/
 
 #include <linux/clocksource.h>
+#include <linux/mdio-bitbang.h>
 #include <linux/net_tstamp.h>
 #include <linux/ptp_clock_kernel.h>
 #include <linux/timecounter.h>
@@ -590,6 +591,10 @@ struct fec_enet_private {
 	int pps_enable;
 	unsigned int next_counter;
 
+	struct mdiobb_ctrl fec_main_bb_ctrl;
+	struct gpio_desc *gd_mdc;
+	struct gpio_desc *gd_mdio;
+
 	u64 ethtool_stats[];
 };
 
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 04f24c66cf36..e5c0a5da9965 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -2050,6 +2050,48 @@ static int fec_enet_mii_probe(struct net_device *ndev)
 	return 0;
 }
 
+static void fec_main_bb_ctrl_set_mdc(struct mdiobb_ctrl *ctrl, int level)
+{
+	struct fec_enet_private *fep = container_of(ctrl,
+							struct fec_enet_private, fec_main_bb_ctrl);
+	if (level)
+		gpiod_direction_input(fep->gd_mdc);
+	else
+		gpiod_direction_output(fep->gd_mdc, 0);
+}
+
+static void fec_main_bb_ctrl_set_mdio_dir(struct mdiobb_ctrl *ctrl, int output)
+{
+	struct fec_enet_private *fep = container_of(ctrl,
+							struct fec_enet_private, fec_main_bb_ctrl);
+	if (output)
+		gpiod_direction_output(fep->gd_mdio, 0);
+	else
+		gpiod_direction_input(fep->gd_mdio);
+}
+
+static void fec_main_bb_ctrl_set_mdio_data(struct mdiobb_ctrl *ctrl, int value)
+{
+	struct fec_enet_private *fep = container_of(ctrl,
+							struct fec_enet_private, fec_main_bb_ctrl);
+	gpiod_direction_output(fep->gd_mdio, value);
+}
+
+static int fec_main_bb_ctrl_get_mdio_data(struct mdiobb_ctrl *ctrl)
+{
+	struct fec_enet_private *fep = container_of(ctrl,
+							struct fec_enet_private, fec_main_bb_ctrl);
+	return gpiod_get_value(fep->gd_mdio);
+}
+
+static const struct mdiobb_ops fec_main_bb_ops = {
+	.owner = THIS_MODULE,
+	.set_mdc = fec_main_bb_ctrl_set_mdc,
+	.set_mdio_dir = fec_main_bb_ctrl_set_mdio_dir,
+	.set_mdio_data = fec_main_bb_ctrl_set_mdio_data,
+	.get_mdio_data = fec_main_bb_ctrl_get_mdio_data,
+};
+
 static int fec_enet_mii_init(struct platform_device *pdev)
 {
 	static struct mii_bus *fec0_mii_bus;
@@ -2150,18 +2192,27 @@ static int fec_enet_mii_init(struct platform_device *pdev)
 	/* Clear any pending transaction complete indication */
 	writel(FEC_ENET_MII, fep->hwp + FEC_IEVENT);
 
-	fep->mii_bus = mdiobus_alloc();
-	if (fep->mii_bus == NULL) {
-		err = -ENOMEM;
-		goto err_out;
-	}
+	if (fep->gd_mdc && fep->gd_mdio) {
+		fep->fec_main_bb_ctrl.ops = &fec_main_bb_ops;
+		fep->mii_bus = alloc_mdio_bitbang(&fep->fec_main_bb_ctrl);
+		if (!fep->mii_bus) {
+			err = -ENOMEM;
+			goto err_out;
+		}
+	} else {
+		fep->mii_bus = mdiobus_alloc();
+		if (!fep->mii_bus) {
+			err = -ENOMEM;
+			goto err_out;
+		}
+		fep->mii_bus->read = fec_enet_mdio_read;
+		fep->mii_bus->write = fec_enet_mdio_write;
 
-	fep->mii_bus->name = "fec_enet_mii_bus";
-	fep->mii_bus->read = fec_enet_mdio_read;
-	fep->mii_bus->write = fec_enet_mdio_write;
+		fep->mii_bus->priv = fep;
+	}
 	snprintf(fep->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
 		pdev->name, fep->dev_id + 1);
-	fep->mii_bus->priv = fep;
+	fep->mii_bus->name = "fec_enet_mii_bus";
 	fep->mii_bus->parent = &pdev->dev;
 
 	err = of_mdiobus_register(fep->mii_bus, node);
@@ -3525,6 +3576,8 @@ fec_probe(struct platform_device *pdev)
 	char irq_name[8];
 	int irq_cnt;
 	struct fec_devinfo *dev_info;
+	struct gpio_desc *gd;
+
 
 	fec_enet_get_queue_num(pdev, &num_tx_qs, &num_rx_qs);
 
@@ -3575,6 +3628,26 @@ fec_probe(struct platform_device *pdev)
 	    !of_property_read_bool(np, "fsl,err006687-workaround-present"))
 		fep->quirks |= FEC_QUIRK_ERR006687;
 
+	gd = devm_gpiod_get_optional(&pdev->dev, "mdc", GPIOD_IN);
+	if (IS_ERR(gd)) {
+		if (PTR_ERR(gd) != -EPROBE_DEFER)
+			dev_err(&pdev->dev, "Failed to get mdc gpio: %ld\n",
+				PTR_ERR(gd));
+		ret = PTR_ERR(gd);
+		goto failed_ioremap;
+	}
+	fep->gd_mdc = gd;
+
+	gd = devm_gpiod_get_optional(&pdev->dev, "mdio", GPIOD_IN);
+	if (IS_ERR(gd)) {
+		if (PTR_ERR(gd) != -EPROBE_DEFER)
+			dev_err(&pdev->dev, "Failed to get mdio gpio: %ld\n",
+				PTR_ERR(gd));
+		ret = PTR_ERR(gd);
+		goto failed_ioremap;
+	}
+	fep->gd_mdio = gd;
+
 	if (of_get_property(np, "fsl,magic-packet", NULL))
 		fep->wol_flag |= FEC_WOL_HAS_MAGIC_PACKET;
 
-- 
2.20.1


  reply	other threads:[~2020-11-28 22:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-28 22:54 [PATCH 1/3] dt-bindings: net: fsl-fec " Adrien Grassein
2020-11-28 22:54 ` Adrien Grassein [this message]
2020-11-28 22:54 ` [PATCH 3/3] net: fsl: fec: add imx8mq support Adrien Grassein
2020-11-29 21:59 ` [PATCH v2 1/3] dt-bindings: net: fsl-fec add mdc/mdio bitbang option Adrien Grassein
2020-11-29 21:59   ` [PATCH v2 2/3] net: fsl: fec: " Adrien Grassein
2020-11-29 22:00   ` [PATCH v2 3/3] net: fsl: fec: add imx8mq support Adrien Grassein
     [not found]   ` <20201129224113.GS2234159@lunn.ch>
     [not found]     ` <CABkfQAFcSNMeYEepsx0Z6tuaif-dQhE2YBMK54t1hikAvzdASg@mail.gmail.com>
2020-11-29 23:04       ` [PATCH v2 1/3] dt-bindings: net: fsl-fec add mdc/mdio bitbang option Andrew Lunn
2020-11-30 22:08         ` Florian Fainelli
2020-11-30 22:26           ` Andrew Lunn
2020-12-04 20:09             ` Adrien Grassein

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=20201128225425.19300-2-adrien.grassein@gmail.com \
    --to=adrien.grassein@gmail.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=fugang.duan@nxp.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --subject='Re: [PATCH 2/3] net: fsl: fec: add mdc/mdio bitbang option' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).