Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5527826pxb; Wed, 26 Jan 2022 14:12:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJyLNi4+5L6z+Vq9zLCpQ+mwjEud4NnOAq0AGjyTZ2pF+7jgs5bP54ujXdVrP16S3czY1B00 X-Received: by 2002:a17:906:c10a:: with SMTP id do10mr676312ejc.420.1643235121615; Wed, 26 Jan 2022 14:12:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643235121; cv=none; d=google.com; s=arc-20160816; b=ubxltvOF7gLPqosySXG9WXPd36Mb6cIqmBdwh4Rk2YoT7ktwXAwM64S8bq4Q7MRPfl gREeaDQRlorczUOYL0j8SkHWTSCs/9ANtp7oqP6a1cUOCYRLadwEeU8HnMBGqaUKCPFl +UfyBmXaf84ub/SxFwJnykJQ3f8p6oOHrvIiBtvqk0CmqTT0olnZk81Je9dqzzJ6LKIa qwNxl8hHAjSPbrkc0Qvapqbig4ovkzQcLMADOp/gX6yA8gbEWeHOysXYtuitXtOY+dIl CwsYsVKk56cPWlYlTHNX7Am939c9s0kf51SNq7IywcfLbQp66lqFVaywSrHyb3f4T81C QIng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:organization :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OzEeuZgMHaNDafKJqIpkWG17qaJ2UOqQemoazwwORiY=; b=weG4Cyc+3IoYXMr3bLeY0i2om3tieJvw65I2ZTGErtQ/y9gCl+dUlwGpai6xYOAamh vPqJb3/Qu1xK2qmYPx3JghXdF3v6AMDb72QHfzXeTHC9XUJwLfdcZaYLnJqB2kbBJi1A Y1wNvbsUEzFR7FRYn4FiqyFRxkMrectROMjNiGYBfoy7nmB6l0iBSBP1a77qB2ipn8zy lagkYFoZap5idWvqI1yV5e/HcjMxYXBo45edBIwdVSUsd3lU7UcRc7vQCtPiRKfgQSOQ 1ctmK6YGZIoIC1Xron8Z+ef1ij0QocXdBXc/ss3gHgP+igd3Tq5KBTSbka4Qi59Ze+Y6 UX3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@waldekranz-com.20210112.gappssmtp.com header.s=20210112 header.b=nyPML2cc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dm3si265449ejc.792.2022.01.26.14.11.35; Wed, 26 Jan 2022 14:12:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@waldekranz-com.20210112.gappssmtp.com header.s=20210112 header.b=nyPML2cc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236856AbiAZQGD (ORCPT + 99 others); Wed, 26 Jan 2022 11:06:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236114AbiAZQF6 (ORCPT ); Wed, 26 Jan 2022 11:05:58 -0500 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03175C06174E for ; Wed, 26 Jan 2022 08:05:58 -0800 (PST) Received: by mail-lj1-x22e.google.com with SMTP id c15so255640ljf.11 for ; Wed, 26 Jan 2022 08:05:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:organization:content-transfer-encoding; bh=OzEeuZgMHaNDafKJqIpkWG17qaJ2UOqQemoazwwORiY=; b=nyPML2ccn1BWm+ZemB9S9F/SL44O3rVpa4RJVTcNeUjr8dIJ+7JvOcTax8PLfSQ2q7 gTwTbXF1RbOWpdpmopsANH3R7kXmaE28Hn7zIPHX9Moa3DySziFLk1IRQUeQUaehmP8x sALLLaqXvNWZIYA+8BWMzlF+wheq5ir8EB506EZh1hMfkM1/VRZJxQm5iH4CiyyG40xk p6RVxAfADix1OtG8DI1lVcRxz/aX9ABIeaXYfuV8PD3eXpuzeyonAkk5kUqgyqbaXqPB h27KZ8SRN5a3HK7XnbrlB4wxZ2jhtjBeHErmEDqynEIYb5HuY1+T25bjzX5VTosGP9Ej 7QoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:organization:content-transfer-encoding; bh=OzEeuZgMHaNDafKJqIpkWG17qaJ2UOqQemoazwwORiY=; b=CVfzdxeQiiDVUcseYHAiraS+iOimapoELbiTZiGX5Yt4RXmXmBsL/hDQaEH4huCqnC Qg2QnesjsnyNcY5Jn0nH0i1ZWygcuefPC68XJOP+ZNP7WTVOe/y9aeDexV/AcstHWn6k gDWAYlVMAhaNoLpzftnfV+nA/r2JTCyLLr/BJdZ7nZzprnvWGDO74C+QA3IALtED2dRA CrqWG2rU/B5GEOMYfM5Cn+A6nUT1oEfyZiK0ELOScqEJcjMI1ZWo2S+BC7zxYhsiX2Xg Lew8x/SZ7lhxmlpyGGaAxOTBSyMoWIm3uBFgsk5inPtAe/oiQQQsKFkc2Mvg7BH7YDP+ DCrQ== X-Gm-Message-State: AOAM5311hd07U6OBI/PokqFzkv8YxRf7igPKrIzgUI/N4o9tXuaQv4fC s/mQl60Mbd3or60F0yFWEgmZPw== X-Received: by 2002:a2e:3305:: with SMTP id d5mr9996554ljc.184.1643213156240; Wed, 26 Jan 2022 08:05:56 -0800 (PST) Received: from veiron.westermo.com (static-193-12-47-89.cust.tele2.se. [193.12.47.89]) by smtp.gmail.com with ESMTPSA id p6sm1869984lfa.241.2022.01.26.08.05.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 08:05:55 -0800 (PST) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: netdev@vger.kernel.org, Andrew Lunn , Marcin Wojtas , Markus Koch , Calvin Johnson , linux-kernel@vger.kernel.org Subject: [PATCH v2 net-next 4/5] net/fsl: xgmac_mdio: Support setting the MDC frequency Date: Wed, 26 Jan 2022 17:05:42 +0100 Message-Id: <20220126160544.1179489-5-tobias@waldekranz.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220126160544.1179489-1-tobias@waldekranz.com> References: <20220126160544.1179489-1-tobias@waldekranz.com> MIME-Version: 1.0 Organization: Westermo Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Support the standard "clock-frequency" attribute to set the generated MDC frequency. If not specified, the driver will leave the divisor bits untouched. Signed-off-by: Tobias Waldekranz --- drivers/net/ethernet/freescale/xgmac_mdio.c | 38 ++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/freescale/xgmac_mdio.c b/drivers/net/ethernet/freescale/xgmac_mdio.c index 18bf2370d45a..d38d0c372585 100644 --- a/drivers/net/ethernet/freescale/xgmac_mdio.c +++ b/drivers/net/ethernet/freescale/xgmac_mdio.c @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -36,7 +37,7 @@ struct tgec_mdio_controller { } __packed; #define MDIO_STAT_ENC BIT(6) -#define MDIO_STAT_CLKDIV(x) (((x>>1) & 0xff) << 8) +#define MDIO_STAT_CLKDIV(x) (((x) & 0x1ff) << 7) #define MDIO_STAT_BSY BIT(0) #define MDIO_STAT_RD_ER BIT(1) #define MDIO_STAT_PRE_DIS BIT(5) @@ -51,6 +52,8 @@ struct tgec_mdio_controller { struct mdio_fsl_priv { struct tgec_mdio_controller __iomem *mdio_base; + struct clk *enet_clk; + u32 mdc_freq; bool is_little_endian; bool has_a009885; bool has_a011043; @@ -255,6 +258,35 @@ static int xgmac_mdio_read(struct mii_bus *bus, int phy_id, int regnum) return ret; } +static int xgmac_mdio_set_mdc_freq(struct mii_bus *bus) +{ + struct mdio_fsl_priv *priv = (struct mdio_fsl_priv *)bus->priv; + struct tgec_mdio_controller __iomem *regs = priv->mdio_base; + struct device *dev = bus->parent; + u32 mdio_stat, div; + + if (device_property_read_u32(dev, "clock-frequency", &priv->mdc_freq)) + return 0; + + priv->enet_clk = devm_clk_get(dev, NULL); + if (IS_ERR(priv->enet_clk)) { + dev_err(dev, "Input clock unknown, not changing MDC frequency"); + return PTR_ERR(priv->enet_clk); + } + + div = ((clk_get_rate(priv->enet_clk) / priv->mdc_freq) - 1) / 2; + if (div < 5 || div > 0x1ff) { + dev_err(dev, "Requested MDC frequecy is out of range, ignoring"); + return -EINVAL; + } + + mdio_stat = xgmac_read32(®s->mdio_stat, priv->is_little_endian); + mdio_stat &= ~MDIO_STAT_CLKDIV(0x1ff); + mdio_stat |= MDIO_STAT_CLKDIV(div); + xgmac_write32(mdio_stat, ®s->mdio_stat, priv->is_little_endian); + return 0; +} + static void xgmac_mdio_set_suppress_preamble(struct mii_bus *bus) { struct mdio_fsl_priv *priv = (struct mdio_fsl_priv *)bus->priv; @@ -319,6 +351,10 @@ static int xgmac_mdio_probe(struct platform_device *pdev) xgmac_mdio_set_suppress_preamble(bus); + ret = xgmac_mdio_set_mdc_freq(bus); + if (ret) + return ret; + fwnode = pdev->dev.fwnode; if (is_of_node(fwnode)) ret = of_mdiobus_register(bus, to_of_node(fwnode)); -- 2.25.1