linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Antoine Tenart <antoine.tenart@free-electrons.com>
To: davem@davemloft.net, kishon@ti.com, andrew@lunn.ch,
	jason@lakedaemon.net, sebastian.hesselbarth@gmail.com,
	gregory.clement@free-electrons.com
Cc: Antoine Tenart <antoine.tenart@free-electrons.com>,
	thomas.petazzoni@free-electrons.com, nadavh@marvell.com,
	linux@armlinux.org.uk, linux-kernel@vger.kernel.org,
	mw@semihalf.com, stefanc@marvell.com,
	miquel.raynal@free-electrons.com, netdev@vger.kernel.org
Subject: [PATCH net-next v2 04/14] net: mvpp2: initialize the comphy
Date: Fri, 25 Aug 2017 16:48:11 +0200	[thread overview]
Message-ID: <20170825144821.31129-5-antoine.tenart@free-electrons.com> (raw)
In-Reply-To: <20170825144821.31129-1-antoine.tenart@free-electrons.com>

On some platforms, the comphy is between the MAC GoP and the PHYs. The
mvpp2 driver currently relies on the firmware/bootloader to configure
the comphy. As a comphy driver was added to the generic PHY framework,
this patch uses it in the mvpp2 driver to configure the comphy at boot
time to avoid relying on the bootloader.

Signed-off-by: Antoine Tenart <antoine.tenart@free-electrons.com>
---
 drivers/net/ethernet/marvell/mvpp2.c | 44 +++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2.c b/drivers/net/ethernet/marvell/mvpp2.c
index e312dfc3555b..fab231858a41 100644
--- a/drivers/net/ethernet/marvell/mvpp2.c
+++ b/drivers/net/ethernet/marvell/mvpp2.c
@@ -28,6 +28,7 @@
 #include <linux/of_address.h>
 #include <linux/of_device.h>
 #include <linux/phy.h>
+#include <linux/phy/phy.h>
 #include <linux/clk.h>
 #include <linux/hrtimer.h>
 #include <linux/ktime.h>
@@ -861,6 +862,7 @@ struct mvpp2_port {
 
 	phy_interface_t phy_interface;
 	struct device_node *phy_node;
+	struct phy *comphy;
 	unsigned int link;
 	unsigned int duplex;
 	unsigned int speed;
@@ -4420,6 +4422,32 @@ static int mvpp22_gop_init(struct mvpp2_port *port)
 	return -EINVAL;
 }
 
+static int mvpp22_comphy_init(struct mvpp2_port *port)
+{
+	enum phy_mode mode;
+	int ret;
+
+	if (!port->comphy)
+		return 0;
+
+	switch (port->phy_interface) {
+	case PHY_INTERFACE_MODE_SGMII:
+		mode = PHY_MODE_SGMII;
+		break;
+	case PHY_INTERFACE_MODE_10GKR:
+		mode = PHY_MODE_10GKR;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	ret = phy_set_mode(port->comphy, mode);
+	if (ret)
+		return ret;
+
+	return phy_power_on(port->comphy);
+}
+
 static void mvpp2_port_mii_gmac_configure_mode(struct mvpp2_port *port)
 {
 	u32 val;
@@ -6404,8 +6432,10 @@ static void mvpp2_start_dev(struct mvpp2_port *port)
 	/* Enable interrupts on all CPUs */
 	mvpp2_interrupts_enable(port);
 
-	if (port->priv->hw_version == MVPP22)
+	if (port->priv->hw_version == MVPP22) {
+		mvpp22_comphy_init(port);
 		mvpp22_gop_init(port);
+	}
 
 	mvpp2_port_mii_set(port);
 	mvpp2_port_enable(port);
@@ -6436,6 +6466,7 @@ static void mvpp2_stop_dev(struct mvpp2_port *port)
 	mvpp2_egress_disable(port);
 	mvpp2_port_disable(port);
 	phy_stop(ndev->phydev);
+	phy_power_off(port->comphy);
 }
 
 static int mvpp2_check_ringparam_valid(struct net_device *dev,
@@ -7270,6 +7301,7 @@ static int mvpp2_port_probe(struct platform_device *pdev,
 			    struct mvpp2 *priv)
 {
 	struct device_node *phy_node;
+	struct phy *comphy;
 	struct mvpp2_port *port;
 	struct mvpp2_port_pcpu *port_pcpu;
 	struct net_device *dev;
@@ -7311,6 +7343,15 @@ static int mvpp2_port_probe(struct platform_device *pdev,
 		goto err_free_netdev;
 	}
 
+	comphy = devm_of_phy_get(&pdev->dev, port_node, NULL);
+	if (IS_ERR(comphy)) {
+		if (PTR_ERR(comphy) == -EPROBE_DEFER) {
+			err = -EPROBE_DEFER;
+			goto err_free_netdev;
+		}
+		comphy = NULL;
+	}
+
 	if (of_property_read_u32(port_node, "port-id", &id)) {
 		err = -EINVAL;
 		dev_err(&pdev->dev, "missing port-id value\n");
@@ -7344,6 +7385,7 @@ static int mvpp2_port_probe(struct platform_device *pdev,
 
 	port->phy_node = phy_node;
 	port->phy_interface = phy_mode;
+	port->comphy = comphy;
 
 	if (priv->hw_version == MVPP21) {
 		res = platform_get_resource(pdev, IORESOURCE_MEM, 2 + id);
-- 
2.13.5

  parent reply	other threads:[~2017-08-25 14:50 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-25 14:48 [PATCH net-next v2 00/14] net: mvpp2: comphy configuration Antoine Tenart
2017-08-25 14:48 ` [PATCH net-next v2 01/14] phy: add sgmii and 10gkr modes to the phy_mode enum Antoine Tenart
2017-08-25 14:48 ` [PATCH net-next v2 02/14] phy: add the mvebu cp110 comphy driver Antoine Tenart
2017-08-25 14:48 ` [PATCH net-next v2 03/14] Documentation/bindings: phy: document the Marvell " Antoine Tenart
2017-08-25 14:48 ` Antoine Tenart [this message]
2017-08-25 14:48 ` [PATCH net-next v2 05/14] net: mvpp2: do not force the link mode Antoine Tenart
2017-08-25 22:43   ` Russell King - ARM Linux
2017-08-28  6:55     ` Antoine Tenart
2017-08-28  8:38       ` Marcin Wojtas
2017-08-28  8:51         ` Russell King - ARM Linux
2017-08-28  9:40           ` Antoine Tenart
2017-08-28 11:06             ` Russell King - ARM Linux
2017-08-28 11:32               ` Antoine Tenart
2017-08-25 14:48 ` [PATCH net-next v2 06/14] net: mvpp2: simplify the link_event function Antoine Tenart
2017-08-25 14:48 ` [PATCH net-next v2 07/14] net: mvpp2: improve the link management function Antoine Tenart
2017-08-25 14:48 ` [PATCH net-next v2 08/14] net: mvpp2: check the netif is running in the link_event function Antoine Tenart
2017-08-25 16:49   ` Florian Fainelli
2017-08-25 17:09     ` Antoine Tenart
2017-08-25 14:48 ` [PATCH net-next v2 09/14] net: mvpp2: dynamic reconfiguration of the PHY mode Antoine Tenart
2017-08-25 22:46   ` Russell King - ARM Linux
2017-08-28  6:52     ` Antoine Tenart
2017-08-25 14:48 ` [PATCH net-next v2 10/14] arm64: dts: marvell: extend the cp110 syscon register area length Antoine Tenart
2017-08-25 14:48 ` [PATCH net-next v2 11/14] arm64: dts: marvell: add comphy nodes on cp110 master and slave Antoine Tenart
2017-08-25 14:48 ` [PATCH net-next v2 12/14] arm64: dts: marvell: mcbin: add comphy references to Ethernet ports Antoine Tenart
2017-08-25 14:48 ` [PATCH net-next v2 13/14] arm64: dts: marvell: 7040-db: " Antoine Tenart
2017-08-25 14:48 ` [PATCH net-next v2 14/14] arm64: defconfig: enable Marvell CP110 comphy Antoine Tenart
2017-08-25 15:51 ` [PATCH net-next v2 00/14] net: mvpp2: comphy configuration Andrew Lunn
2017-08-25 15:56   ` Antoine Tenart

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=20170825144821.31129-5-antoine.tenart@free-electrons.com \
    --to=antoine.tenart@free-electrons.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=gregory.clement@free-electrons.com \
    --cc=jason@lakedaemon.net \
    --cc=kishon@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=miquel.raynal@free-electrons.com \
    --cc=mw@semihalf.com \
    --cc=nadavh@marvell.com \
    --cc=netdev@vger.kernel.org \
    --cc=sebastian.hesselbarth@gmail.com \
    --cc=stefanc@marvell.com \
    --cc=thomas.petazzoni@free-electrons.com \
    /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 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).