From patchwork Mon Dec 4 10:08:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13478062 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b="ArBkAWX5" Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DF2DCC for ; Mon, 4 Dec 2023 02:08:25 -0800 (PST) Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-50bfa5a6cffso652247e87.0 for ; Mon, 04 Dec 2023 02:08:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1701684504; x=1702289304; darn=vger.kernel.org; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=Nx9WOIwGojr3XHm97vyDaAcWYuGy4RnKZZSPft3u0+s=; b=ArBkAWX5oBdSuteY7cHqObSEF3vnSDapsWTJ7dHHaEwng5Bh8Jer+QUvOKFTx5Chtv XKb2s5WQojbpUHs+xgxeJxqQ5ZROLip7d/LZ0wwsc04alv/cZhL2XyA0Fr02czkkJpyd i8LdCV6U73A+awIe4GWJXI+vZhi0XS1UK6QJLwIxGp6Bktc9/0l5EtQOryLr0VCQ+3MH KkCAmokDuf8jRd5hG7mgm6/iYXzbIoSxhuox7HI0CQGr8yIKIwpjfvvjFJBsmFc11NAJ EYCqCtQJaHFO5HFDnXuVnQpZyQdH0C+m0nmnA7dJYLinOs8aAj3wh3KunQyibAwlmIpQ VLrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701684504; x=1702289304; h=content-transfer-encoding:organization: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=Nx9WOIwGojr3XHm97vyDaAcWYuGy4RnKZZSPft3u0+s=; b=B/e6sNceXOC7Qhz7bk50K4uaXPemdJ9hCRiJFEcHP07Kv/5aWgATd9c/5Ym/iIXIeo X9e21/npiz1WqCR3q81CJdfpbJfiPTMh9CUeoeHixjIWJr7t1Y5dtnpDegE+T+RY/E50 dJ9Erj3mPmDZQIfp8/2/5M6FasNLgKCfpiX7X7n+iRyFZVD6URXOc1kGiyFdQLMrBtgD 9Pmp8ZAym56tUbYsj0U3P0kPGlJV9n7DIcK3iEKLwjaNI2NbzZCQmBMPorDECjElgbw9 N5F02Czh98A7sKY2u5b8oj0eSHrFJz6zDcM0IIvfQ6sI0sWyibndR7o33ttA7bpnDeZ5 szTg== X-Gm-Message-State: AOJu0YyTJ5WQ1MczUMh8CC5bxlunV3aLJcWvDyJzU8yFZ3a62mDxl9uu K3HSWxnM0/DCwWq7LClw9f6pqA== X-Google-Smtp-Source: AGHT+IEMnfPrYtWP0ptniVE06oR9DmKFVJAKnlPlvkCRslcOQFmNHCNA0+lv3WcYKBsQcuKMc7mx+Q== X-Received: by 2002:ac2:4424:0:b0:50b:f509:a2e1 with SMTP id w4-20020ac24424000000b0050bf509a2e1mr607452lfl.0.1701684503845; Mon, 04 Dec 2023 02:08:23 -0800 (PST) Received: from wkz-x13.addiva.ad (a124.broadband3.quicknet.se. [46.17.184.124]) by smtp.gmail.com with ESMTPSA id u29-20020a19791d000000b0050beead375bsm553643lfc.57.2023.12.04.02.08.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 02:08:22 -0800 (PST) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: andrew@lunn.ch, gregory.clement@bootlin.com, sebastian.hesselbarth@gmail.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, netdev@vger.kernel.org Subject: [PATCH v2 net-next 1/3] arm64: dts: marvell: cp11x: Provide clock names for MDIO controllers Date: Mon, 4 Dec 2023 11:08:09 +0100 Message-Id: <20231204100811.2708884-2-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231204100811.2708884-1-tobias@waldekranz.com> References: <20231204100811.2708884-1-tobias@waldekranz.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik X-Patchwork-Delegate: kuba@kernel.org This will let the driver figure out the rate of the core clk, such that custom MDC frequencies can be supported. Signed-off-by: Tobias Waldekranz Reviewed-by: Andrew Lunn --- arch/arm64/boot/dts/marvell/armada-cp11x.dtsi | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi b/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi index 4ec1aae0a3a9..f268017498a9 100644 --- a/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi +++ b/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi @@ -180,6 +180,8 @@ CP11X_LABEL(mdio): mdio@12a200 { reg = <0x12a200 0x10>; clocks = <&CP11X_LABEL(clk) 1 9>, <&CP11X_LABEL(clk) 1 5>, <&CP11X_LABEL(clk) 1 6>, <&CP11X_LABEL(clk) 1 18>; + clock-names = "gop_clk", "mg_clk", + "mg_core_clk", "axi_clk"; status = "disabled"; }; @@ -190,6 +192,8 @@ CP11X_LABEL(xmdio): mdio@12a600 { reg = <0x12a600 0x10>; clocks = <&CP11X_LABEL(clk) 1 5>, <&CP11X_LABEL(clk) 1 6>, <&CP11X_LABEL(clk) 1 18>; + clock-names = "mg_clk", + "mg_core_clk", "axi_clk"; status = "disabled"; }; From patchwork Mon Dec 4 10:08:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13478063 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b="JgVEDQjg" Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A590FB6 for ; Mon, 4 Dec 2023 02:08:26 -0800 (PST) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-50bc22c836bso5666189e87.0 for ; Mon, 04 Dec 2023 02:08:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1701684505; x=1702289305; darn=vger.kernel.org; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=eupC3o2v88nkyvmlhi7dfTAJJixZuJxhtsJieZvcVs4=; b=JgVEDQjgse/LYYtQOd6Y6R1uqZQt+ZD34hIr5+zNdNdDlZ4Iyf5ju6JUZzk+MrqVh7 E2GWmQs8U9+mqjvzjKO4Xm+HR1I+rq9fXNkt4GotvBRLXKN8yBOnXiTI4Qzaf/lVjnGr mRbmwI5E36G+ENH4sWaskKbeSYE3Ybjn9En/aBnKLX8WHZbPyGwaPkkn9EdJvscH1SfR B+zxYE0h4ClTxzfGCdrvpvPD0zRYi7Ty2IL2lRaICoPoKoGeBiuV0k+pqDEyQs8U0wsk Af8Kb4viuHMaeGzY+XFj67HMrTfwkBKCsnkGAiCF4IxSgekwHwh7JK4W+fsOZpCV8fES p3/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701684505; x=1702289305; h=content-transfer-encoding:organization: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=eupC3o2v88nkyvmlhi7dfTAJJixZuJxhtsJieZvcVs4=; b=jQz2EDyxD5ybQeszrhvgcG7cJQ4qb2xhR0GR/wopgru3D4tBghFvcKmG6WBPx/nA5Q U11Fpf80IXRU7yye3kUsxTzAh+OI3WpHvYcxOkySmKVOH6JkpgUsrOi/l6zJkgZsKEuI UGOoFXcjbW5Yh7uUxJliDWNjmksxYg45uZZdlh37bPQlFJrEGLWYblABJwDdVI82tEps gZO+Z8Vjny5ItUD9PtYZTJrm+XY0mbBaLtDa/Kgzt2DDysb2zQnFH/OIDv2m/HN2Pv97 mqsC/ulvInsI635CkL0DIIWsKW5Cf5Lzijm8H0dWSfi474dEBWWM8F974tpOImsoZMLo Iegg== X-Gm-Message-State: AOJu0Yzrs4taVBYBIA8DWxSr2O5fUY4p3u9IwBfSSrWYbugQpwLTQ5DS dmZAu6M8D18pkr89mwG0N2HaPgep+HfUaRaEdgk= X-Google-Smtp-Source: AGHT+IE/N2VQf5IgRHPQlqZw8f/J2Jpsiwa/nIx+x0CTNzxyWV0S1gZ5ZscCubKe9pBllkeLWypXqg== X-Received: by 2002:a05:6512:3b0e:b0:50b:f351:6fb7 with SMTP id f14-20020a0565123b0e00b0050bf3516fb7mr1126850lfv.0.1701684505045; Mon, 04 Dec 2023 02:08:25 -0800 (PST) Received: from wkz-x13.addiva.ad (a124.broadband3.quicknet.se. [46.17.184.124]) by smtp.gmail.com with ESMTPSA id u29-20020a19791d000000b0050beead375bsm553643lfc.57.2023.12.04.02.08.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 02:08:24 -0800 (PST) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: andrew@lunn.ch, gregory.clement@bootlin.com, sebastian.hesselbarth@gmail.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, netdev@vger.kernel.org Subject: [PATCH v2 net-next 2/3] net: mvmdio: Avoid excessive sleeps in polled mode Date: Mon, 4 Dec 2023 11:08:10 +0100 Message-Id: <20231204100811.2708884-3-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231204100811.2708884-1-tobias@waldekranz.com> References: <20231204100811.2708884-1-tobias@waldekranz.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik X-Patchwork-Delegate: kuba@kernel.org Before this change, when operating in polled mode, i.e. no IRQ is available, every individual C45 access would be hit with a 150us sleep after the bus access. For example, on a board with a CN9130 SoC connected to an MV88X3310 PHY, a single C45 read would take around 165us: root@infix:~$ mdio f212a600.mdio-mii mmd 4:1 bench 0xc003 Performed 1000 reads in 165ms By replacing the long sleep with a tighter poll loop, we observe a 10x increase in bus throughput: root@infix:~$ mdio f212a600.mdio-mii mmd 4:1 bench 0xc003 Performed 1000 reads in 15ms Signed-off-by: Tobias Waldekranz Reviewed-by: Andrew Lunn --- drivers/net/ethernet/marvell/mvmdio.c | 53 ++++++++------------------- 1 file changed, 16 insertions(+), 37 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvmdio.c b/drivers/net/ethernet/marvell/mvmdio.c index 89f26402f8fb..5f66f779e56f 100644 --- a/drivers/net/ethernet/marvell/mvmdio.c +++ b/drivers/net/ethernet/marvell/mvmdio.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -58,11 +59,6 @@ * - Armada 370 (Globalscale Mirabox): 41us to 43us (Polled) */ #define MVMDIO_SMI_TIMEOUT 1000 /* 1000us = 1ms */ -#define MVMDIO_SMI_POLL_INTERVAL_MIN 45 -#define MVMDIO_SMI_POLL_INTERVAL_MAX 55 - -#define MVMDIO_XSMI_POLL_INTERVAL_MIN 150 -#define MVMDIO_XSMI_POLL_INTERVAL_MAX 160 struct orion_mdio_dev { void __iomem *regs; @@ -84,8 +80,6 @@ enum orion_mdio_bus_type { struct orion_mdio_ops { int (*is_done)(struct orion_mdio_dev *); - unsigned int poll_interval_min; - unsigned int poll_interval_max; }; /* Wait for the SMI unit to be ready for another operation @@ -94,34 +88,23 @@ static int orion_mdio_wait_ready(const struct orion_mdio_ops *ops, struct mii_bus *bus) { struct orion_mdio_dev *dev = bus->priv; - unsigned long timeout = usecs_to_jiffies(MVMDIO_SMI_TIMEOUT); - unsigned long end = jiffies + timeout; - int timedout = 0; + unsigned long timeout; + int done; - while (1) { - if (ops->is_done(dev)) + if (dev->err_interrupt <= 0) { + if (!read_poll_timeout_atomic(ops->is_done, done, done, 2, + MVMDIO_SMI_TIMEOUT, false, dev)) + return 0; + } else { + /* wait_event_timeout does not guarantee a delay of at + * least one whole jiffie, so timeout must be no less + * than two. + */ + timeout = max(usecs_to_jiffies(MVMDIO_SMI_TIMEOUT), 2); + + if (wait_event_timeout(dev->smi_busy_wait, + ops->is_done(dev), timeout)) return 0; - else if (timedout) - break; - - if (dev->err_interrupt <= 0) { - usleep_range(ops->poll_interval_min, - ops->poll_interval_max); - - if (time_is_before_jiffies(end)) - ++timedout; - } else { - /* wait_event_timeout does not guarantee a delay of at - * least one whole jiffie, so timeout must be no less - * than two. - */ - if (timeout < 2) - timeout = 2; - wait_event_timeout(dev->smi_busy_wait, - ops->is_done(dev), timeout); - - ++timedout; - } } dev_err(bus->parent, "Timeout: SMI busy for too long\n"); @@ -135,8 +118,6 @@ static int orion_mdio_smi_is_done(struct orion_mdio_dev *dev) static const struct orion_mdio_ops orion_mdio_smi_ops = { .is_done = orion_mdio_smi_is_done, - .poll_interval_min = MVMDIO_SMI_POLL_INTERVAL_MIN, - .poll_interval_max = MVMDIO_SMI_POLL_INTERVAL_MAX, }; static int orion_mdio_smi_read(struct mii_bus *bus, int mii_id, @@ -194,8 +175,6 @@ static int orion_mdio_xsmi_is_done(struct orion_mdio_dev *dev) static const struct orion_mdio_ops orion_mdio_xsmi_ops = { .is_done = orion_mdio_xsmi_is_done, - .poll_interval_min = MVMDIO_XSMI_POLL_INTERVAL_MIN, - .poll_interval_max = MVMDIO_XSMI_POLL_INTERVAL_MAX, }; static int orion_mdio_xsmi_read_c45(struct mii_bus *bus, int mii_id, From patchwork Mon Dec 4 10:08:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13478064 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b="L6fId/4L" Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FFD099 for ; Mon, 4 Dec 2023 02:08:28 -0800 (PST) Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-50bce78f145so5000332e87.0 for ; Mon, 04 Dec 2023 02:08:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1701684506; x=1702289306; darn=vger.kernel.org; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=NupAADUjLojjcNqZenMNhCx0/lE8c7FM0G/tbESSkUc=; b=L6fId/4LDvqXBNRgzxvCxkLWTn/CFLZb3XHEio+K6iTmuDK3RiYjH6J9G8dKy7Zdl2 rRv8hn3X2KggHWVV3V9TczqvYi3BzGg9qxGsLtm5WSlwl2gH52xFkuab8be6TkUJru48 vDrQVxOSVoaAQ2SAlF2t0C+qfVkxn9/lYC7c06rXA0ND9i8j1NeumsvFSaw5VFnXcb+j 9SiVYJXkL4Pnh1t/4qQkId4DHYCeZU2v+5C/cr1orEulJ7EDBt4RiVnHMhuebOtI1dNk 23KoQ0ICMK0lsPHa1W4C0OO0T7XFGJhA24SIflhhQ7VeHiQdO4Q2BjAqg9MlPLqGReA+ g/0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701684506; x=1702289306; h=content-transfer-encoding:organization: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=NupAADUjLojjcNqZenMNhCx0/lE8c7FM0G/tbESSkUc=; b=rkwEoYF7b6l9j0Tf4BS88aWhYK+7WWHvwQUsosbEwJtQllVqIjKzNneINJZ705h3qy WunGWsamS1Jx6vkikMbHSVM/bbOOjnn8PXYsPUsTJprSS97CYwa8B3/z+thfX5ITrZzV jRfTLBnaWPt4Zf1qekWqGVdIxBK2g7MN9aAaYb5+ZbXZuhEqgWX9aF7qryqE+ZrEuu46 V0g50YXVjm0HSrx89mBqZcy86/w/g/6gJRe1rYX1sAWRbtU+oMD+SU+7ZxnSIcNA+4rx H20lcDz/jbC7uhzLRGMH8Ne89xT/ph184x0NrAb7nCSZuUoB8ueEY3cwYwdZCn4IP4E2 rruw== X-Gm-Message-State: AOJu0YwC9GVc1OrCqKtE5FV82fh+PGGMyGrJY0sKZZqr/YUS5UucuVDV rHmsTP8VHK/TI8pK2N5nZMWrBw== X-Google-Smtp-Source: AGHT+IFnKHddgyeXxCxSsPyAvJkBdc+uBF4j3NvlvRO9tK7ilBqh7o/xm9UEOxQdtfjYVRvqCCdX2A== X-Received: by 2002:ac2:4d07:0:b0:50b:f822:eac7 with SMTP id r7-20020ac24d07000000b0050bf822eac7mr262516lfi.171.1701684506188; Mon, 04 Dec 2023 02:08:26 -0800 (PST) Received: from wkz-x13.addiva.ad (a124.broadband3.quicknet.se. [46.17.184.124]) by smtp.gmail.com with ESMTPSA id u29-20020a19791d000000b0050beead375bsm553643lfc.57.2023.12.04.02.08.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 02:08:25 -0800 (PST) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: andrew@lunn.ch, gregory.clement@bootlin.com, sebastian.hesselbarth@gmail.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, netdev@vger.kernel.org Subject: [PATCH v2 net-next 3/3] net: mvmdio: Support setting the MDC frequency on XSMI controllers Date: Mon, 4 Dec 2023 11:08:11 +0100 Message-Id: <20231204100811.2708884-4-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231204100811.2708884-1-tobias@waldekranz.com> References: <20231204100811.2708884-1-tobias@waldekranz.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik X-Patchwork-Delegate: kuba@kernel.org Support the standard "clock-frequency" attribute to set the generated MDC frequency. If not specified, the driver will leave the divisor untouched. Signed-off-by: Tobias Waldekranz Reviewed-by: Andrew Lunn --- drivers/net/ethernet/marvell/mvmdio.c | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/net/ethernet/marvell/mvmdio.c b/drivers/net/ethernet/marvell/mvmdio.c index 5f66f779e56f..9190eff6c0bb 100644 --- a/drivers/net/ethernet/marvell/mvmdio.c +++ b/drivers/net/ethernet/marvell/mvmdio.c @@ -53,6 +53,13 @@ #define MVMDIO_XSMI_BUSY BIT(30) #define MVMDIO_XSMI_ADDR_REG 0x8 +#define MVMDIO_XSMI_CFG_REG 0xc +#define MVMDIO_XSMI_CLKDIV_MASK 0x3 +#define MVMDIO_XSMI_CLKDIV_256 0x0 +#define MVMDIO_XSMI_CLKDIV_64 0x1 +#define MVMDIO_XSMI_CLKDIV_32 0x2 +#define MVMDIO_XSMI_CLKDIV_8 0x3 + /* * SMI Timeout measurements: * - Kirkwood 88F6281 (Globalscale Dreamplug): 45us to 95us (Interrupt) @@ -225,6 +232,40 @@ static int orion_mdio_xsmi_write_c45(struct mii_bus *bus, int mii_id, return 0; } +static void orion_mdio_xsmi_set_mdc_freq(struct mii_bus *bus) +{ + struct orion_mdio_dev *dev = bus->priv; + struct clk *mg_core; + u32 div, freq, cfg; + + if (device_property_read_u32(bus->parent, "clock-frequency", &freq)) + return; + + mg_core = of_clk_get_by_name(bus->parent->of_node, "mg_core_clk"); + if (IS_ERR(mg_core)) { + dev_err(bus->parent, + "MG core clock unknown, not changing MDC frequency"); + return; + } + + div = clk_get_rate(mg_core) / (freq + 1) + 1; + clk_put(mg_core); + + if (div <= 8) + div = MVMDIO_XSMI_CLKDIV_8; + else if (div <= 32) + div = MVMDIO_XSMI_CLKDIV_32; + else if (div <= 64) + div = MVMDIO_XSMI_CLKDIV_64; + else + div = MVMDIO_XSMI_CLKDIV_256; + + cfg = readl(dev->regs + MVMDIO_XSMI_CFG_REG); + cfg &= ~MVMDIO_XSMI_CLKDIV_MASK; + cfg |= div; + writel(cfg, dev->regs + MVMDIO_XSMI_CFG_REG); +} + static irqreturn_t orion_mdio_err_irq(int irq, void *dev_id) { struct orion_mdio_dev *dev = dev_id; @@ -303,6 +344,9 @@ static int orion_mdio_probe(struct platform_device *pdev) dev_warn(&pdev->dev, "unsupported number of clocks, limiting to the first " __stringify(ARRAY_SIZE(dev->clk)) "\n"); + + if (type == BUS_TYPE_XSMI) + orion_mdio_xsmi_set_mdc_freq(bus); } else { dev->clk[0] = clk_get(&pdev->dev, NULL); if (PTR_ERR(dev->clk[0]) == -EPROBE_DEFER) {