Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3911940imm; Mon, 30 Jul 2018 05:45:59 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdBq/y0jYVIXYxhu+UeisssyRFc1qPgGa7UsDY913NxtzcoWursyNmsAJOsL6Xz+ylB0NMb X-Received: by 2002:a17:902:142:: with SMTP id 60-v6mr16609581plb.330.1532954759515; Mon, 30 Jul 2018 05:45:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532954759; cv=none; d=google.com; s=arc-20160816; b=OEv7OdQ32NfYAbn6PPlp4oNuOTR6fbIMpzw/HxrKqhNuqS9jksWJuoEvlGvARkgiP8 tNw5ZnA5RqntQje6QUxfcrq7G/7SQTR6VSB3S6mSzWvgF64wg5Mv1ZxBm3E8TqjtgzHe FDYw1c1dIp9aBGoxZa/o6Vws0y+zkRJkcEARzeETPQB9e5nmNZhJaGU7HRDKTuin3/ZL 3/Tq9YZ0826iBWEiU52L037W936qff+MOzmwpiaRJt+0QjJtp0KSa5yPnZELsIgnxIaw sjh+/PLLeDUiZkE2rKh56zr71y3uHqlgbkbN0jl9y0x2HHqYwYYgzArAu5pHQDuKaFKQ +Oaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=1wKoQprZBDm5PDiRhX9AjiKQ9tudabJeymkuUtG2n00=; b=o56aRuFWtBhl7thtJJ0MnPnOPVTg1+xDGoOlIPMDgBQ2MENpxIU/nff+vb4geSMPyC wylg+WrkqlDweuJnbf5vjQGOW2XJS+mOAHhnZHfV6O6gOUarjo+USsQfU5eOc5jyJv3r TDUnTnwgPCZrJ4WzXrQ7aLu6+hRTfh8Soj106tdLLiZxScHJkZduARu7sTzQsbu+u1ou uTIvPx3pmBjGp/6KUOOJjz2Njc5RxQBaS6gg0ddOvIaFhQhgmJvcKAggAIl+NRRKkbB+ 2pvi0qw4CqEiXQNvLvWc+qZYE6TPQfSjODxnTH2y312+yU1/+Vbgj671I+LweREGizrG JB3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y1-v6si10235597pgf.146.2018.07.30.05.45.45; Mon, 30 Jul 2018 05:45:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731859AbeG3OTU (ORCPT + 99 others); Mon, 30 Jul 2018 10:19:20 -0400 Received: from mail.bootlin.com ([62.4.15.54]:58471 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729283AbeG3OTT (ORCPT ); Mon, 30 Jul 2018 10:19:19 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id F2B7B207BD; Mon, 30 Jul 2018 14:44:26 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost.localdomain (AAubervilliers-681-1-89-120.w90-88.abo.wanadoo.fr [90.88.30.120]) by mail.bootlin.com (Postfix) with ESMTPSA id 8EC2B20765; Mon, 30 Jul 2018 14:44:26 +0200 (CEST) From: Quentin Schulz To: alexandre.belloni@bootlin.com, ralf@linux-mips.org, paul.burton@mips.com, jhogan@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com, davem@davemloft.net Cc: kishon@ti.com, andrew@lunn.ch, f.fainelli@gmail.com, linux-mips@linux-mips.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, allan.nielsen@microsemi.com, thomas.petazzoni@bootlin.com, Quentin Schulz Subject: [PATCH net-next 10/10] net: mscc: ocelot: make use of SerDes PHYs for handling their configuration Date: Mon, 30 Jul 2018 14:43:55 +0200 Message-Id: <0ce1b3e8466064741dc6e484f87bbe48542cb978.1532954208.git-series.quentin.schulz@bootlin.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Previously, the SerDes muxing was hardcoded to a given mode in the MAC controller driver. Now, the SerDes muxing is configured within the Device Tree and is enforced in the MAC controller driver so we can have a lot of different SerDes configurations. Make use of the SerDes PHYs in the MAC controller to set up the SerDes according to the SerDes<->switch port mapping and the communication mode with the Ethernet PHY. Signed-off-by: Quentin Schulz --- drivers/net/ethernet/mscc/Kconfig | 2 +- drivers/net/ethernet/mscc/ocelot.c | 16 ++++++++- drivers/net/ethernet/mscc/ocelot.h | 5 +++- drivers/net/ethernet/mscc/ocelot_board.c | 43 +++++++++++++++++++------ 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/mscc/Kconfig b/drivers/net/ethernet/mscc/Kconfig index 36c8462..bcec058 100644 --- a/drivers/net/ethernet/mscc/Kconfig +++ b/drivers/net/ethernet/mscc/Kconfig @@ -23,6 +23,8 @@ config MSCC_OCELOT_SWITCH config MSCC_OCELOT_SWITCH_OCELOT tristate "Ocelot switch driver on Ocelot" depends on MSCC_OCELOT_SWITCH + depends on GENERIC_PHY + depends on OF_NET help This driver supports the Ocelot network switch device as present on the Ocelot SoCs. diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index 1a4f2bb..8f11fdb 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -472,6 +472,7 @@ static int ocelot_port_open(struct net_device *dev) { struct ocelot_port *port = netdev_priv(dev); struct ocelot *ocelot = port->ocelot; + enum phy_mode phy_mode; int err; /* Enable receiving frames on the port, and activate auto-learning of @@ -482,8 +483,21 @@ static int ocelot_port_open(struct net_device *dev) ANA_PORT_PORT_CFG_PORTID_VAL(port->chip_port), ANA_PORT_PORT_CFG, port->chip_port); + if (port->serdes) { + if (port->phy_mode == PHY_INTERFACE_MODE_SGMII) + phy_mode = PHY_MODE_SGMII; + else + phy_mode = PHY_MODE_QSGMII; + + err = phy_set_mode(port->serdes, phy_mode); + if (err) { + netdev_err(dev, "Could not set mode of SerDes\n"); + return err; + } + } + err = phy_connect_direct(dev, port->phy, &ocelot_port_adjust_link, - PHY_INTERFACE_MODE_NA); + port->phy_mode); if (err) { netdev_err(dev, "Could not attach to PHY\n"); return err; diff --git a/drivers/net/ethernet/mscc/ocelot.h b/drivers/net/ethernet/mscc/ocelot.h index 3720e51..62c7c8e 100644 --- a/drivers/net/ethernet/mscc/ocelot.h +++ b/drivers/net/ethernet/mscc/ocelot.h @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include #include @@ -453,6 +455,9 @@ struct ocelot_port { u8 vlan_aware; u64 *stats; + + phy_interface_t phy_mode; + struct phy *serdes; }; u32 __ocelot_read_ix(struct ocelot *ocelot, u32 reg, u32 offset); diff --git a/drivers/net/ethernet/mscc/ocelot_board.c b/drivers/net/ethernet/mscc/ocelot_board.c index b7d755b..3bb71b7 100644 --- a/drivers/net/ethernet/mscc/ocelot_board.c +++ b/drivers/net/ethernet/mscc/ocelot_board.c @@ -6,6 +6,7 @@ */ #include #include +#include #include #include #include @@ -247,18 +248,12 @@ static int mscc_ocelot_probe(struct platform_device *pdev) INIT_LIST_HEAD(&ocelot->multicast); ocelot_init(ocelot); - ocelot_rmw(ocelot, HSIO_HW_CFG_DEV1G_4_MODE | - HSIO_HW_CFG_DEV1G_6_MODE | - HSIO_HW_CFG_DEV1G_9_MODE, - HSIO_HW_CFG_DEV1G_4_MODE | - HSIO_HW_CFG_DEV1G_6_MODE | - HSIO_HW_CFG_DEV1G_9_MODE, - HSIO_HW_CFG); - for_each_available_child_of_node(ports, portnp) { struct device_node *phy_node; struct phy_device *phy; struct resource *res; + struct phy *serdes; + enum phy_mode phy_mode; void __iomem *regs; char res_name[8]; u32 port; @@ -283,10 +278,38 @@ static int mscc_ocelot_probe(struct platform_device *pdev) continue; err = ocelot_probe_port(ocelot, port, regs, phy); - if (err) { - dev_err(&pdev->dev, "failed to probe ports\n"); + if (err) + return err; + + err = of_get_phy_mode(portnp); + if (err < 0) + ocelot->ports[port]->phy_mode = PHY_INTERFACE_MODE_NA; + else + ocelot->ports[port]->phy_mode = err; + + if (ocelot->ports[port]->phy_mode == PHY_INTERFACE_MODE_NA) + continue; + + if (ocelot->ports[port]->phy_mode == PHY_INTERFACE_MODE_SGMII) + phy_mode = PHY_MODE_SGMII; + else + phy_mode = PHY_MODE_QSGMII; + + serdes = devm_of_phy_get(ocelot->dev, portnp, NULL); + if (IS_ERR(serdes)) { + if (PTR_ERR(serdes) == -EPROBE_DEFER) { + dev_err(ocelot->dev, "deferring probe\n"); + err = -EPROBE_DEFER; + goto err_probe_ports; + } + + dev_err(ocelot->dev, "missing SerDes phys for port%d\n", + port); + err = -ENODEV; goto err_probe_ports; } + + ocelot->ports[port]->serdes = serdes; } register_netdevice_notifier(&ocelot_netdevice_nb); -- git-series 0.9.1