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: 616937 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F06CCC43217 for ; Thu, 20 Oct 2022 09:41:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229864AbiJTJl2 (ORCPT ); Thu, 20 Oct 2022 05:41:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229868AbiJTJl0 (ORCPT ); Thu, 20 Oct 2022 05:41:26 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1B2C183E03 for ; Thu, 20 Oct 2022 02:41:16 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id p6so557711plr.7 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=H/xzciBNCe5I+nA5mZ3rQ2D5nRlinYPGSOnkJbuovFIJtgvRbdD8nu+Jm2BP06E2H6 iWftZluHkUo/DjRIgZThzv18T3SKUb/DlPXO30UQAEGxx852QH5Fh8KNL06imnTsUlVF /dOTf/DT7WMbfFlja7qLTnTP1EpepDVY5RgccpmdHIinAmjzW1pO0spvl/pINcdczFkg fyfTLrGNAtdAECh3ZKyp+fFFq0jw8GDR6Bl3PH9ke4ABFKBgY/s7fwsb4ygnZpOy0njL VBwe2T104+8yUHUop4uOWvffZ98bpZx5at2uGI8d5vjKWX6JLx1kNt8vIh0n8ZsjMB7B EQEQ== X-Gm-Message-State: ACrzQf3TzvJBi7BzHvnf9fxiKdMXcqGNBW6azCwZoRgitCger93P7zFW Yipur06MLh+KKPqLJeuwUtrCuQ== 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 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.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",