From patchwork Thu Oct 20 09:41:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13012925 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 73AD2C433FE for ; Thu, 20 Oct 2022 09:45:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=j4Nr8Bt8kKt6y8gP2SIdpf9F1l2zVU/urPYbgyf4gyo=; b=qg9PIKbq09i10r 1Wkq1OGOrTCTFzY6Ei1vW6C8mltiwodJfw4AwDfrUKB10f82OHJMaxvUckB7ZHat9SSkqB331Wr31 ou7Pzy+zot3iYBqvcUPc/Q3Kew404zqbu3tmi4eY2w0T2hhPQx/lHdyF9plS0fQ1FyELwbssMkOr1 RoF+flT0kReJQ5vw6naQukKp6hf9ASV/6mjJzpVnp/GBl8kqyoadaowCLNnoFqBL0W08q83etnIqd FxXMsKhU5dBGlapY/IvkF0OinkT7ImH/EFd+RRyqG7GsksQZSFbukw5yJaW8uftFpumEyhKfmBv6s zCB2ofq817sdGu++OXog==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1olS60-00D7rn-Ev; Thu, 20 Oct 2022 09:44:12 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1olS3C-00D5zr-LC for linux-arm-kernel@lists.infradead.org; Thu, 20 Oct 2022 09:41:20 +0000 Received: by mail-pl1-x62a.google.com with SMTP id c24so19817602plo.3 for ; Thu, 20 Oct 2022 02:41:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MAk1sPj8uS6Y5Snv3u/+4VG4lGdBQLp4u90+6Vwe3Fs=; b=EqeKkMQaubuaNVKiFCjJArFycc4ci1OODQUmEfJsLBvRxzOw28iOY9im71XWU3pau6 63CFElZmmhg2vXi1tqKXARyZna0lDrY8DrDSkzeyNiG0FcUYodXzgqJAxCNytanYG5wK H5wvbtEg0KgAdlTA5pAeQubjbTKN85Ztk9vjh0wj6XExO8OhhcKbmqWL2jIV0N0YF8/N hRpGhuMvszEbtO2mJfF5aY4iRLE0TnSiFxUQSwR9KOtdQIMqq9zG6yL5/MNBJCvlam/w 08eL1Y8GHZy1E3FNTh+3qQ+lLW56Sya4aYiKxyCY5XjM77tVdc/50QofSHHthZbPskbJ d5sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MAk1sPj8uS6Y5Snv3u/+4VG4lGdBQLp4u90+6Vwe3Fs=; b=6I0B+VN5/PLkbjAqyPd8xw8OL7gvxfcItimYG6i2tOMHiM26d+FKQahuXpJsIMcIw3 3WqemYv04i14QBlRGCAv4SO2U9IyKzw47o/5nn8l0NrlK4uw1+agfk0OwVj6VFp+JI4N GmaLdOyN4dC2yjyuUq97eQ+7qpK/HxwEuWbdZpoL+4g+nDkBjr3yQ9vPL5nPF+O5ID56 Fb+F7+NWiEju4op0BwqrsvBQ4G0bce5DJ/Ez7P0XG0pUo3jOOOE01mBIdm02zT/jqj9V UrqzINx1ucnJe0RJjG8kh8H0KpVxjFMPeEU4fH76VH+mHiVYviF3D0lpKI9P1jjZRCWj 1Fxg== X-Gm-Message-State: ACrzQf3aAjk1qz7e5MpNOjsZT14YstKheMtAUBvEF8dIDEvkIDmWwE/a yx2dxs18xD6jywzsT+qsa5mQLA== X-Google-Smtp-Source: AMsMyM4P3IKsg2wslCeJuhY4BUsKVntSp9uAuDJJtrhkPakUF6JHjXjj8ZoviVt6up2m7pnVUUMdMQ== X-Received: by 2002:a17:90a:c306:b0:211:8e5e:9a66 with SMTP id g6-20020a17090ac30600b002118e5e9a66mr3753662pjt.152.1666258875668; Thu, 20 Oct 2022 02:41:15 -0700 (PDT) Received: from archlinux.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id o12-20020a170902d4cc00b0016d9d6d05f7sm12425675plg.273.2022.10.20.02.41.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 02:41:15 -0700 (PDT) From: Andy Chiu To: davem@davemloft.net, kuba@kernel.org, michal.simek@xilinx.com, radhey.shyam.pandey@xilinx.com Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, krzysztof.kozlowski+dt@linaro.org, robh+dt@kernel.org, pabeni@redhat.com, edumazet@google.com, andy.chiu@sifive.com, greentime.hu@sifive.com Subject: [PATCH net-next 1/2] net:xilinx_axi: set mdio frequency according to DT Date: Thu, 20 Oct 2022 17:41:05 +0800 Message-Id: <20221020094106.559266-2-andy.chiu@sifive.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20221020094106.559266-1-andy.chiu@sifive.com> References: <20221020094106.559266-1-andy.chiu@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221020_024118_737459_1865A75C X-CRM114-Status: GOOD ( 17.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Some FPGA platforms has 80KHz MDIO bus frequency constraint when conecting Ethernet to its on-board external Marvell PHY. Thus, we may have to set MDIO clock according to the DT. Otherwise, use the default 2.5 MHz, as specified by 802.3, if the entry is not present. Signed-off-by: Andy Chiu Reviewed-by: Greentime Hu --- .../net/ethernet/xilinx/xilinx_axienet_mdio.c | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c b/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c index 0b3b6935c558..d07c39d3bcf0 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c @@ -18,6 +18,7 @@ #include "xilinx_axienet.h" #define MAX_MDIO_FREQ 2500000 /* 2.5 MHz */ +#define MDIO_CLK_DIV_MASK 0x3f /* bits[5:0] */ #define DEFAULT_HOST_CLOCK 150000000 /* 150 MHz */ /* Wait till MDIO interface is ready to accept a new transaction.*/ @@ -155,7 +156,9 @@ static int axienet_mdio_write(struct mii_bus *bus, int phy_id, int reg, **/ int axienet_mdio_enable(struct axienet_local *lp) { + u32 clk_div; u32 host_clock; + u32 mdio_freq; lp->mii_clk_div = 0; @@ -184,6 +187,13 @@ int axienet_mdio_enable(struct axienet_local *lp) host_clock); } + if (of_property_read_u32(lp->dev->of_node, "xlnx,mdio-freq", + &mdio_freq)) { + mdio_freq = MAX_MDIO_FREQ; + netdev_info(lp->ndev, "Setting default mdio clock to %u\n", + mdio_freq); + } + /* clk_div can be calculated by deriving it from the equation: * fMDIO = fHOST / ((1 + clk_div) * 2) * @@ -209,13 +219,20 @@ int axienet_mdio_enable(struct axienet_local *lp) * "clock-frequency" from the CPU */ - lp->mii_clk_div = (host_clock / (MAX_MDIO_FREQ * 2)) - 1; + clk_div = (host_clock / (mdio_freq * 2)) - 1; /* If there is any remainder from the division of - * fHOST / (MAX_MDIO_FREQ * 2), then we need to add + * fHOST / (mdio_freq * 2), then we need to add * 1 to the clock divisor or we will surely be above 2.5 MHz */ - if (host_clock % (MAX_MDIO_FREQ * 2)) - lp->mii_clk_div++; + if (host_clock % (mdio_freq * 2)) + clk_div++; + + /* Check for overflow of mii_clk_div */ + if (clk_div & ~MDIO_CLK_DIV_MASK) { + netdev_dbg(lp->ndev, "MDIO clock divisor overflow, setting to maximum value\n"); + clk_div = MDIO_CLK_DIV_MASK; + } + lp->mii_clk_div = (u8)clk_div; netdev_dbg(lp->ndev, "Setting MDIO clock divisor to %u/%u Hz host clock.\n", From patchwork Thu Oct 20 09:41:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13012926 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BA72DC4332F for ; Thu, 20 Oct 2022 09:46:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=99gz4SUekcYl/uAKKmLsHD48jJSjd6MzquC4Hn4JF4o=; b=BXj7JTgyCjKTyF aHdEfOGNBn9yqj8GQ+FTDli0w52Sms0IMFhSVSqbMmL0fdj5iYu/QK1ijouWaxHJAVIcWVWsc1fK1 8493ic45VKeIIP2uibN5enof3QoAHapt+6lceTRIK7ISqO0pK2lt6wtugKQWN4aavZZ3fQkROsfVL OzlFj4mtWch7/v6Y8hOIhiUrrwhimUk12YDiTc2MuXViSveEBPuhujYkxtMc/slNRUgLRtjfBKSWa XIWgK7HkvV+TvIJuyVVJdfPP38jtlcNHnETkI8QMY5v5OYY04aJQCtY2tO7SJXiRITxBKZHjcb2XP w8EumETZyIzPxaUXfy1A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1olS6e-00D84q-Gz; Thu, 20 Oct 2022 09:44:53 +0000 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1olS3D-00D63K-VD for linux-arm-kernel@lists.infradead.org; Thu, 20 Oct 2022 09:41:21 +0000 Received: by mail-pj1-x1036.google.com with SMTP id t10-20020a17090a4e4a00b0020af4bcae10so2526550pjl.3 for ; Thu, 20 Oct 2022 02:41:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lu/Q+My0d0ZJp0MXkrJy5vys7anyhTLA0nDtYHB/OvM=; b=MiQBa8dSIOH7lGMIZBxpa/IvxMnz2uilvJw1Kj18eKcdSUsIWkBVa/lrpjUqS0Y8DM 1uI5PcezLwNguOyeofuwoTBlMhNH2MsNh4YkOyYkO9EPls54jmHXADSZ4pa7nwQvMas0 WKGlyFbjrsIDfFUKOrN6Tz8cSZBO7pE+c1GCcxkO++9NCN2AcpezGwB6ZnEs7rfDEyBt cxiEIE1MC8w5qaGkt5kIsvmqNBrDDCv1LYiF7HjmAHYggCkJfuG9sLphm+6QJj51Hxb2 aaIFxNYDxECx94C7eTRy5dWr0QdjTvt5pNkECQy8hRor8ARz8SbT2UML0Tlb+/rXYz0/ DNmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lu/Q+My0d0ZJp0MXkrJy5vys7anyhTLA0nDtYHB/OvM=; b=sAok73EntkIg6m8KYpQSTgyMk/mySneHfL2WfF4jvy34eUJy9MU2xyOpHDnvhwpQIA QRsq1/16XQJJrmd3ZH0kt9kvENqcRrHLKxuHnuYpG2ipmTbeopG6KShoOB60q/rP8KoZ YRxE2jqYAAeAN+QzE7d+Esgal3GpZOxD4vD2gyG/otb7u+YK5ywp2Y3lZErM5vMcZVOA /pRXKU5BBQ7fUQk4nBvFnLe0LM3WTZ9ee7HVfM+JrbvPHFO2PNS2WC9eCsKNJCW1uDC9 u9SjCZlfyP+i8bafZ9sePaiYNQaDYgCbtqRmUhpSLx1xAAoITZMd3bYyIB+LFxTUZd5o Xljw== X-Gm-Message-State: ACrzQf3b1vXqWEkKsH+VYwG76OzC4SARF6k9gNIOqfWtwkaBfbs6v8nr b1n+sdT6kSFeD6LoczpZVMw6bA== X-Google-Smtp-Source: AMsMyM5yclQegyW9oOtG584tPYotVoNT59Ds9iM06q8wifMIcgH0xMo6fym+G8TEFKV/xTR+zIOlGg== X-Received: by 2002:a17:90a:e548:b0:211:2c0c:cb74 with SMTP id ei8-20020a17090ae54800b002112c0ccb74mr4631912pjb.69.1666258878720; Thu, 20 Oct 2022 02:41:18 -0700 (PDT) Received: from archlinux.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id o12-20020a170902d4cc00b0016d9d6d05f7sm12425675plg.273.2022.10.20.02.41.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 02:41:18 -0700 (PDT) From: Andy Chiu To: davem@davemloft.net, kuba@kernel.org, michal.simek@xilinx.com, radhey.shyam.pandey@xilinx.com Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, krzysztof.kozlowski+dt@linaro.org, robh+dt@kernel.org, pabeni@redhat.com, edumazet@google.com, andy.chiu@sifive.com, greentime.hu@sifive.com Subject: [PATCH net-next 2/2] dt-bindings: add mdio frequency description Date: Thu, 20 Oct 2022 17:41:06 +0800 Message-Id: <20221020094106.559266-3-andy.chiu@sifive.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20221020094106.559266-1-andy.chiu@sifive.com> References: <20221020094106.559266-1-andy.chiu@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221020_024120_043659_2847789A X-CRM114-Status: GOOD ( 11.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a property to set mdio bus frequency at runtime by DT. Signed-off-by: Andy Chiu Reviewed-by: Greentime Hu --- Documentation/devicetree/bindings/net/xilinx_axienet.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/net/xilinx_axienet.txt b/Documentation/devicetree/bindings/net/xilinx_axienet.txt index 1aa4c6006cd0..d78cf402aa2a 100644 --- a/Documentation/devicetree/bindings/net/xilinx_axienet.txt +++ b/Documentation/devicetree/bindings/net/xilinx_axienet.txt @@ -43,6 +43,9 @@ Optional properties: support both 1000BaseX and SGMII modes. If set, the phy-mode should be set to match the mode selected on core reset (i.e. by the basex_or_sgmii core input line). +- xlnx,mdio-freq: Define the clock frequency of the MDIO bus. If the property + does not pressent on the DT, then the mdio driver would use + the default 2.5 MHz clock, as mentioned on 802.3 spc. - clock-names: Tuple listing input clock names. Possible clocks: s_axi_lite_clk: Clock for AXI register slave interface axis_clk: AXI4-Stream clock for TXD RXD TXC and RXS interfaces