From patchwork Fri Dec 1 17:35:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13476225 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="Qfnfntxa" Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72644D40 for ; Fri, 1 Dec 2023 09:36:10 -0800 (PST) Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2c9c82a976bso30240941fa.3 for ; Fri, 01 Dec 2023 09:36:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1701452168; x=1702056968; 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=Qfnfntxab/ga5GPX2MCaKsARsFrVOV9VG+T9fwSJAW7NpI/6y8YmsJOa6KbrKCpC7k kCyuilOQcG0Fm6hsV3LXHoduv8QhlG6bhB1xamyRvEdem9B1P4Ru4NmZs55hyFduhlfk 8jxY2jvw+Y2q3+ExEYnEx7CZnLfUwSkF/svu8cKQ7Yjg++/7F0blffYw1JJXNa5pDqwW GtwgkY9G5K0qaK/CBqOyTroLxT0AFKOwmudSevdP0hLzZZzvnHmKKvp2SvGwZoeUfQbb wkkHhuwUqnkt/3xdP73eLQB6t618pvKOfzItxpuXlvBHh7EZrXp6DW8aWt214SD1lFZF rqjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701452168; x=1702056968; 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=EprOItWqWrYb/i3/IKmWj8rUZTMOMMFF5Gkvh7rrjUE1VNSZK2djHSUyPmUStDmccU hglXe6cxX+Fs0wyj13nA2/OMh0VTl0/M+qIX6UtsLHoyhXnSA6xkXWmU2/y3nyw1vlCZ +DxTeTpSlRgYKL42pOmL/lGesFO498L1DJFhymim41eoiZt2ZijFI/w17h5DlzfFVrm3 GYc0l3KRLIFIn5Oo25D2SxJBOGdcYKdHrlP5p+nV3F+m7xwec8oxOk1YaQbuIjhWTlFx Uu5m9b2SCq238zxNXJ1xQ1x5Mtc2XglMRkUYU75bWCzgssIZQsRGv+NmMWSJBhLrKn+x greA== X-Gm-Message-State: AOJu0Yw0jGc8LfZmzX9Aq9u7BySaiBaLmB2dbcc1CBlEUhQxoGOmjZNE I06AQshfjnxBM5ksH+iwRJKnKg== X-Google-Smtp-Source: AGHT+IFinpOyTubfZclV9z5rQA4LeOo8mpjRd6hue0YchpTznWYq1vNOthrjg3UPav/x34o9bUoWpg== X-Received: by 2002:a2e:a202:0:b0:2c9:d874:20dd with SMTP id h2-20020a2ea202000000b002c9d87420ddmr1199216ljm.103.1701452168551; Fri, 01 Dec 2023 09:36:08 -0800 (PST) Received: from wkz-x13.addiva.ad (h-176-10-137-178.NA.cust.bahnhof.se. [176.10.137.178]) by smtp.gmail.com with ESMTPSA id y9-20020a2eb009000000b002c120b99f8csm470327ljk.134.2023.12.01.09.36.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 09:36:07 -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 net-next 1/3] arm64: dts: marvell: cp11x: Provide clock names for MDIO controllers Date: Fri, 1 Dec 2023 18:35:43 +0100 Message-Id: <20231201173545.1215940-2-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231201173545.1215940-1-tobias@waldekranz.com> References: <20231201173545.1215940-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 --- 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 Fri Dec 1 17:35:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13476226 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="VH+jQzel" Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD33CD54 for ; Fri, 1 Dec 2023 09:36:11 -0800 (PST) Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2c9b8aa4fc7so32627471fa.1 for ; Fri, 01 Dec 2023 09:36:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1701452170; x=1702056970; 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=x57p+X/w2tEsd6GdWAN+PVlTIs+rxhmRjLrPaMCJ7rk=; b=VH+jQzelM3qGPNA+5OPUzpU0hbhv1ykhn6i6GzS79vgC2Mv4+avagxrDzzs6aMT6u5 aSMaEE015IXq4XJcLr0WCTXq5MOme/ccD2Ym4wWAl/qUAuolZ1KJV9G7VZ2PkTEicS0F RXCoWszeBIkdRiUCLnt4TE1B+otEdPN7nZXPUNNw1fzUpLgCFNUogQMek4I9BtEHTvSl 1VfppIO+fWPu9b4mp1fDZ+qaRe7ltPF/lA8bjaSo4zyMgrJjpFUdhnuubrh2g2LPNHWh GEVN927p4Hngh0X/4A5tiqg5qcfwYz88INBFUGwdXxQrc8R5Wd0cUK8W+Q06CPOJ2+FQ bNAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701452170; x=1702056970; 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=x57p+X/w2tEsd6GdWAN+PVlTIs+rxhmRjLrPaMCJ7rk=; b=OABfGtvqf9U+Jsd3kLyz0PW5XeVg6umpk+6QA7wtoVvKQMHssRijMP9LEghd5p4eJM eMIFv81LkRxEkfFSD70SZjrz+S8CQ4fvCD9+XrNdysgI0ifm14RwFEqdNRWmiJVYJb8Z ytWKgI4Tu6lsYVuJT5GF9PstPqgNTCBWAzNXMsA3HyQycETpJ51dD8pfNpdo/Wg/iRWB 17jWADjYBuycHPiAxTSpPb4jlj0Y4mclYHjH62yUVUhFrFiIWWH4C57m7b9rbisSFMYs qYg9D0M99PabVfXAhUXpaY8lIXxZlDeuOVEVC1go7M56iB8vEW0/absyWd07Srxd8E9E zMVQ== X-Gm-Message-State: AOJu0Yx268SpJgAz09CBqM07SDacuBo04D5BR5BilXH4J9OuwPvOiQBe zxKN+42ZymTaQ0VxLyUnTVHN5A== X-Google-Smtp-Source: AGHT+IEKyCG3+Kp1SnQHbaz/AXf+7pmVpJFrvQpacq30S+mGG66HXCcGNasKl1UsRsvOU3SvoMgooQ== X-Received: by 2002:a2e:b0d6:0:b0:2c9:c24e:19fe with SMTP id g22-20020a2eb0d6000000b002c9c24e19femr987118ljl.26.1701452169836; Fri, 01 Dec 2023 09:36:09 -0800 (PST) Received: from wkz-x13.addiva.ad (h-176-10-137-178.NA.cust.bahnhof.se. [176.10.137.178]) by smtp.gmail.com with ESMTPSA id y9-20020a2eb009000000b002c120b99f8csm470327ljk.134.2023.12.01.09.36.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 09:36:09 -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 net-next 2/3] net: mvmdio: Avoid excessive sleeps in polled mode Date: Fri, 1 Dec 2023 18:35:44 +0100 Message-Id: <20231201173545.1215940-3-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231201173545.1215940-1-tobias@waldekranz.com> References: <20231201173545.1215940-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 --- drivers/net/ethernet/marvell/mvmdio.c | 41 +++++++++++---------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvmdio.c b/drivers/net/ethernet/marvell/mvmdio.c index 89f26402f8fb..1de2175269bf 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,23 +88,24 @@ 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 end, timeout; + int done, timedout; - 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 if (timedout) - break; - - if (dev->err_interrupt <= 0) { - usleep_range(ops->poll_interval_min, - ops->poll_interval_max); + } else { + timeout = usecs_to_jiffies(MVMDIO_SMI_TIMEOUT); + end = jiffies + timeout; + timedout = 0; + + while (1) { + if (ops->is_done(dev)) + return 0; + else if (timedout) + break; - 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. @@ -135,8 +130,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 +187,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 Fri Dec 1 17:35:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13476227 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="C7BO8hoa" Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE78F1A8 for ; Fri, 1 Dec 2023 09:36:12 -0800 (PST) Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2c9bbb30c34so30285181fa.1 for ; Fri, 01 Dec 2023 09:36:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1701452171; x=1702056971; 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=62Xb/t0WXbU4fDk0OR1toLDrHS6G4bi3D72m+zt9Jb4=; b=C7BO8hoaP0Urbr1ItuWkOFPgOejTzYmQwaAItuWK4tTFgZg86O9HO7NdKPZyT0YTNR CHrFQbPMpyMJEmujgcTk9qYpqedvCj+rXMWh+/oyc2ILif3reUSATLDAkqrEGB+8P8DI 1jmGP8Uh3u01od5T/RYCe6oxA0XasSIcL2/wtYFokiEVbls1W89rsdQiGtH6BQygkCgd QQL8Vz3qL7ToAxMKSTcdwHFplPaPxSYSQ1W/HZEtrh5SFkbK24BS0r0STnmdiKNubUme tSg7x7bybQUiYqCi5ZjAPQA2qrrn6MbB+jwQvX5Q34pGC17oiYCN9aOKCB9xsStRY116 fCiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701452171; x=1702056971; 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=62Xb/t0WXbU4fDk0OR1toLDrHS6G4bi3D72m+zt9Jb4=; b=Qb1oLSTHFUCNfKZhHpMNxd1Hzhs3fp3pBIjEsUdfTUaLVTrVRMGBIdRkzQ4Yn/kC3I MOlvBLWchChQ0EapdXn5mr9Iii4pmnSG4ga2alDZN+skeipCMyAR5CL5I8doDg21N7re 8T56Wbxf5PeRUddyf7tZMLn+spaMT7TRq1NTMBOrK8Hkfgvn3tZOyjwb53XGpqk4dwUT 91zBihhYprDBwx6g9g2I0AfG7LaXs4yaqNiAFrFzoBwTu+iIPygcjXxzNZUdKjMzkbNL x5Mpu001zGfbgtlaWRP5Y+hCkiBbovneBRRIxkYsxm+ECa2uvv0h5eBWPoKbBB2B29Vr pCag== X-Gm-Message-State: AOJu0YyTFf6J/8H56LmtjRmbNbzDaHreNDVrJs9gF6Pje3hvKz+Mq23D N5mGAFLuedLpcRX/gO2izHTsCg== X-Google-Smtp-Source: AGHT+IEplCSmIjKdrlEkQyJ/P3ctkeYH+24Sdg1W1dfa3j+SKWZx5gC8SOeMLv1FOaRq6827ZT09uQ== X-Received: by 2002:a2e:8796:0:b0:2c9:d874:4b53 with SMTP id n22-20020a2e8796000000b002c9d8744b53mr989880lji.67.1701452171147; Fri, 01 Dec 2023 09:36:11 -0800 (PST) Received: from wkz-x13.addiva.ad (h-176-10-137-178.NA.cust.bahnhof.se. [176.10.137.178]) by smtp.gmail.com with ESMTPSA id y9-20020a2eb009000000b002c120b99f8csm470327ljk.134.2023.12.01.09.36.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 09:36:10 -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 net-next 3/3] net: mvmdio: Support setting the MDC frequency on XSMI controllers Date: Fri, 1 Dec 2023 18:35:45 +0100 Message-Id: <20231201173545.1215940-4-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231201173545.1215940-1-tobias@waldekranz.com> References: <20231201173545.1215940-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 --- 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 1de2175269bf..69d5e73be8fe 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) @@ -237,6 +244,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; @@ -315,6 +356,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) {