From patchwork Tue Jan 21 13:50:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Jensen X-Patchwork-Id: 3518251 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 07DBF9F2D6 for ; Tue, 21 Jan 2014 13:59:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BDF7C20160 for ; Tue, 21 Jan 2014 13:59:45 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 584CE2015E for ; Tue, 21 Jan 2014 13:59:44 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W5brZ-0003c9-TR; Tue, 21 Jan 2014 13:59:34 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1W5brV-0006nM-CU; Tue, 21 Jan 2014 13:59:29 +0000 Received: from mail-la0-x232.google.com ([2a00:1450:4010:c03::232]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W5brR-0006lf-VA for linux-arm-kernel@lists.infradead.org; Tue, 21 Jan 2014 13:59:27 +0000 Received: by mail-la0-f50.google.com with SMTP id ec20so6701376lab.9 for ; Tue, 21 Jan 2014 05:59:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WHiuvtBgZE6NulMF5ExSB4Ve7/BMAwcy3FuHbYVQs1E=; b=Ajj6030KxuDm/vPMcDiaB2+5cHYNkko4bjuREIDN22fMqIwTjtx8TcZXrO+W9vGKqb W+mF2S55YDcidg2LIq/196MWRDfeaIMByh0eRq/Zi3YETudnNWeSR2IfdHqw8RV0zEEr +ENt/CSPqE5grmKfEsBt1YstQ6BMF/+mJjQL5/reP8QSZhPkRe3wgzHI+8IaYOtpmk8S bOckcM/uB4CqCq+69n8Svkv01iPek5AgXPm+q2mevkwmqW5WfHxNp+3c+VsNMGuUjuQm nfQshFnvmzSAi4oU1LsQssb8zxW25qPswK+psRf1B2A9jiiKHAD3w0LPE/ZsxDUccSl5 UwUQ== X-Received: by 10.112.151.42 with SMTP id un10mr15594810lbb.7.1390312272794; Tue, 21 Jan 2014 05:51:12 -0800 (PST) Received: from Ildjarn.ath.cx (static-213-115-41-10.sme.bredbandsbolaget.se. [213.115.41.10]) by mx.google.com with ESMTPSA id s9sm5580387laj.0.2014.01.21.05.51.10 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 21 Jan 2014 05:51:11 -0800 (PST) From: Jonas Jensen To: netdev@vger.kernel.org Subject: [PATCH v3 3/7] net: moxa: connect to PHY Date: Tue, 21 Jan 2014 14:50:48 +0100 Message-Id: <1390312248-5453-1-git-send-email-jonas.jensen@gmail.com> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140121_085926_341702_8A0497EE X-CRM114-Status: GOOD ( 18.18 ) X-Spam-Score: -2.0 (--) Cc: f.fainelli@gmail.com, linux-kernel@vger.kernel.org, Jonas Jensen , bhutchings@solarflare.com, davem@davemloft.net, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The kernel now has a MDIO bus driver and a phy_driver (RTL8201CP), connect to this PHY using OF. Signed-off-by: Jonas Jensen --- Notes: Thanks for reviewing, This time I'll avoid sending out the entire set, attaching it here directly to my reply. Because the DT example is directly imported from files in arch/arm/ those must be updated too. I'll submit those in a separate fixup patch. Changes since v3: 1. drop device_type property from DT example 2. replace "mac@" with "ethernet@" in DT example Applies to next-20140121 .../devicetree/bindings/net/moxa,moxart-mac.txt | 49 +++++++++++- drivers/net/ethernet/moxa/moxart_ether.c | 92 +++++++++++++++++++++- drivers/net/ethernet/moxa/moxart_ether.h | 2 + 3 files changed, 138 insertions(+), 5 deletions(-) diff --git a/Documentation/devicetree/bindings/net/moxa,moxart-mac.txt b/Documentation/devicetree/bindings/net/moxa,moxart-mac.txt index 583418b..36d5185 100644 --- a/Documentation/devicetree/bindings/net/moxa,moxart-mac.txt +++ b/Documentation/devicetree/bindings/net/moxa,moxart-mac.txt @@ -1,21 +1,62 @@ MOXA ART Ethernet Controller +Integrated MDIO bus node: + +- compatible: "moxa,moxart-mdio" +- Inherits from MDIO bus node binding[1] + +[1] Documentation/devicetree/bindings/net/phy.txt + + +Ethernet node: + Required properties: - compatible : Must be "moxa,moxart-mac" - reg : Should contain register location and length - interrupts : Should contain the mac interrupt number +Optional Properties: + +- phy-handle : the phandle to a PHY node + + Example: - mac0: mac@90900000 { + mdio0: mdio@90900090 { + compatible = "moxa,moxart-mdio"; + reg = <0x90900090 0x8>; + #address-cells = <1>; + #size-cells = <0>; + + ethphy0: ethernet-phy@1 { + compatible = "moxa,moxart-rtl8201cp", "ethernet-phy-ieee802.3-c22"; + reg = <1>; + }; + }; + + mdio1: mdio@92000090 { + compatible = "moxa,moxart-mdio"; + reg = <0x92000090 0x8>; + #address-cells = <1>; + #size-cells = <0>; + + ethphy1: ethernet-phy@1 { + compatible = "moxa,moxart-rtl8201cp", "ethernet-phy-ieee802.3-c22"; + reg = <1>; + }; + }; + + mac0: ethernet@90900000 { compatible = "moxa,moxart-mac"; - reg = <0x90900000 0x100>; + reg = <0x90900000 0x90>; interrupts = <25 0>; + phy-handle = <ðphy0>; }; - mac1: mac@92000000 { + mac1: ethernet@92000000 { compatible = "moxa,moxart-mac"; - reg = <0x92000000 0x100>; + reg = <0x92000000 0x90>; interrupts = <27 0>; + phy-handle = <ðphy1>; }; diff --git a/drivers/net/ethernet/moxa/moxart_ether.c b/drivers/net/ethernet/moxa/moxart_ether.c index 17c9f0e..c19bff2 100644 --- a/drivers/net/ethernet/moxa/moxart_ether.c +++ b/drivers/net/ethernet/moxa/moxart_ether.c @@ -25,6 +25,9 @@ #include #include #include +#include +#include +#include #include "moxart_ether.h" @@ -60,6 +63,16 @@ static int moxart_set_mac_address(struct net_device *ndev, void *addr) return 0; } +static int moxart_do_ioctl(struct net_device *ndev, struct ifreq *ir, int cmd) +{ + struct moxart_mac_priv_t *priv = netdev_priv(ndev); + + if (!netif_running(ndev)) + return -EINVAL; + + return phy_mii_ioctl(priv->phy_dev, ir, cmd); +} + static void moxart_mac_free_memory(struct net_device *ndev) { struct moxart_mac_priv_t *priv = netdev_priv(ndev); @@ -109,6 +122,19 @@ static void moxart_mac_enable(struct net_device *ndev) writel(priv->reg_maccr, priv->base + REG_MAC_CTRL); } +static void moxart_mac_update_duplex(struct net_device *ndev) +{ + struct moxart_mac_priv_t *priv = netdev_priv(ndev); + + priv->reg_maccr &= ~(FULLDUP | ENRX_IN_HALFTX); + if (priv->duplex) + priv->reg_maccr |= FULLDUP; + else + priv->reg_maccr |= ENRX_IN_HALFTX; + + writel(priv->reg_maccr, priv->base + REG_MAC_CTRL); +} + static void moxart_mac_setup_desc_ring(struct net_device *ndev) { struct moxart_mac_priv_t *priv = netdev_priv(ndev); @@ -168,6 +194,9 @@ static int moxart_mac_open(struct net_device *ndev) moxart_update_mac_address(ndev); moxart_mac_setup_desc_ring(ndev); moxart_mac_enable(ndev); + + phy_start(priv->phy_dev); + netif_start_queue(ndev); netdev_dbg(ndev, "%s: IMR=0x%x, MACCR=0x%x\n", @@ -183,6 +212,8 @@ static int moxart_mac_stop(struct net_device *ndev) napi_disable(&priv->napi); + phy_stop(priv->phy_dev); + netif_stop_queue(ndev); /* disable all interrupts */ @@ -435,12 +466,49 @@ static struct net_device_ops moxart_netdev_ops = { .ndo_set_mac_address = moxart_set_mac_address, .ndo_validate_addr = eth_validate_addr, .ndo_change_mtu = eth_change_mtu, + .ndo_do_ioctl = moxart_do_ioctl, }; +static void moxart_adjust_link(struct net_device *ndev) +{ + struct moxart_mac_priv_t *priv = netdev_priv(ndev); + unsigned long flags; + int status_change = 0; + + if (priv->phy_dev->link) { + if (priv->speed != priv->phy_dev->speed) { + priv->speed = priv->phy_dev->speed; + status_change = 1; + } + + if (priv->duplex != priv->phy_dev->duplex) { + spin_lock_irqsave(&priv->txlock, flags); + + priv->duplex = priv->phy_dev->duplex; + moxart_mac_update_duplex(ndev); + + spin_unlock_irqrestore(&priv->txlock, flags); + status_change = 1; + } + } + + if (priv->link != priv->phy_dev->link) { + if (!priv->phy_dev->link) { + priv->speed = 0; + priv->duplex = -1; + } + priv->link = priv->phy_dev->link; + status_change = 1; + } + + if (status_change) + phy_print_status(priv->phy_dev); +} + static int moxart_mac_probe(struct platform_device *pdev) { struct device *p_dev = &pdev->dev; - struct device_node *node = p_dev->of_node; + struct device_node *node = p_dev->of_node, *phy_node; struct net_device *ndev; struct moxart_mac_priv_t *priv; struct resource *res; @@ -461,6 +529,28 @@ static int moxart_mac_probe(struct platform_device *pdev) priv = netdev_priv(ndev); priv->ndev = ndev; + priv->link = 0; + priv->speed = 0; + priv->duplex = -1; + + phy_node = of_parse_phandle(node, "phy-handle", 0); + if (!phy_node) { + dev_err(p_dev, "of_parse_phandle failed\n"); + ret = -ENODEV; + goto init_fail; + } + + if (phy_node) { + priv->phy_dev = of_phy_connect(priv->ndev, phy_node, + &moxart_adjust_link, + 0, of_get_phy_mode(node)); + if (!priv->phy_dev) { + dev_err(p_dev, "of_phy_connect failed\n"); + ret = -ENODEV; + goto init_fail; + } + } + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); ndev->base_addr = res->start; priv->base = devm_ioremap_resource(p_dev, res); diff --git a/drivers/net/ethernet/moxa/moxart_ether.h b/drivers/net/ethernet/moxa/moxart_ether.h index 2be9280..b8877bf 100644 --- a/drivers/net/ethernet/moxa/moxart_ether.h +++ b/drivers/net/ethernet/moxa/moxart_ether.h @@ -297,6 +297,8 @@ struct moxart_mac_priv_t { unsigned int reg_imr; struct napi_struct napi; struct net_device *ndev; + struct phy_device *phy_dev; + int speed, duplex, link; dma_addr_t rx_base; dma_addr_t rx_mapping[RX_DESC_NUM];