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",