From: Chen-Yu Tsai <wens@csie.org>
To: Maxime Ripard <maxime.ripard@bootlin.com>,
Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>,
Giuseppe Cavallaro <peppe.cavallaro@st.com>,
Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Mark Brown <broonie@kernel.org>
Cc: Chen-Yu Tsai <wens@csie.org>,
linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org,
devicetree@vger.kernel.org, netdev@vger.kernel.org,
Corentin Labbe <clabbe.montjoie@gmail.com>,
Icenowy Zheng <icenowy@aosc.io>
Subject: [PATCH net-next 07/12] net: stmmac: dwmac-sun8i: Allow getting syscon regmap from CCU device
Date: Sat, 17 Mar 2018 17:28:52 +0800 [thread overview]
Message-ID: <20180317092857.4396-8-wens@csie.org> (raw)
In-Reply-To: <20180317092857.4396-1-wens@csie.org>
On the Allwinner R40 SoC, the "GMAC clock" register is in the CCU
address space. Using a standard syscon to access it provides no
coordination with the CCU driver for register access. Neither does
it prevent this and other drivers from accessing other, maybe critical,
clock control registers.
Instead, for these types of setups, we let the CCU register a proper
device and a regmap tied to it. We can then get the device from the
phandle, and retrieve the regmap with dev_get_regmap().
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 38 ++++++++++++++++++++++-
1 file changed, 37 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index de93f0faf58d..a51175bcfd11 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -43,6 +43,9 @@
* and used as a good starting value in case of the
* boot process(uboot) leave some stuff.
* @syscon_field reg_field for the syscon's gmac register
+ * @syscon_from_dev syscon regmap is in ccu address space and
+ * needs to be retrieved using dev_get_regmap()
+ * instead of syscon_regmap_lookup_by_phandle()
* @soc_has_internal_phy: Does the MAC embed an internal PHY
* @support_mii: Does the MAC handle MII
* @support_rmii: Does the MAC handle RMII
@@ -51,6 +54,7 @@
struct emac_variant {
u32 default_syscon_value;
const struct reg_field *syscon_field;
+ bool syscon_from_dev;
bool soc_has_internal_phy;
bool support_mii;
bool support_rmii;
@@ -983,6 +987,34 @@ static struct mac_device_info *sun8i_dwmac_setup(void *ppriv)
return mac;
}
+static struct regmap *sun8i_dwmac_get_syscon_from_dev(struct device_node *node)
+{
+ struct device_node *syscon_node;
+ struct platform_device *syscon_pdev;
+ struct regmap *regmap = NULL;
+
+ syscon_node = of_parse_phandle(node, "syscon", 0);
+ if (!syscon_node)
+ return ERR_PTR(-ENODEV);
+
+ syscon_pdev = of_find_device_by_node(syscon_node);
+ if (!syscon_pdev) {
+ /* platform device might not be probed yet */
+ regmap = ERR_PTR(-EPROBE_DEFER);
+ goto out_put_node;
+ }
+
+ /* If no regmap is found then the other device driver is at fault */
+ regmap = dev_get_regmap(&syscon_pdev->dev, NULL);
+ if (!regmap)
+ regmap = ERR_PTR(-EINVAL);
+
+ platform_device_put(syscon_pdev);
+out_put_node:
+ of_node_put(syscon_node);
+ return regmap;
+}
+
static int sun8i_dwmac_probe(struct platform_device *pdev)
{
struct plat_stmmacenet_data *plat_dat;
@@ -1027,7 +1059,11 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
gmac->regulator = NULL;
}
- regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, "syscon");
+ if (gmac->variant->syscon_from_dev)
+ regmap = sun8i_dwmac_get_syscon_from_dev(pdev->dev.of_node);
+ else
+ regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
+ "syscon");
if (IS_ERR(regmap)) {
ret = PTR_ERR(regmap);
dev_err(&pdev->dev, "Unable to map syscon: %d\n", ret);
--
2.16.2
next prev parent reply other threads:[~2018-03-17 9:28 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-17 9:28 [PATCH net-next 00/12] ARM: sun8i: r40: Add Ethernet support Chen-Yu Tsai
2018-03-17 9:28 ` [PATCH net-next 01/12] clk: sunxi-ng: r40: rewrite init code to a platform driver Chen-Yu Tsai
2018-03-17 9:28 ` [PATCH net-next 02/12] clk: sunxi-ng: r40: export a regmap to access the GMAC register Chen-Yu Tsai
2018-03-18 21:31 ` Maxime Ripard
2018-03-20 7:15 ` Chen-Yu Tsai
2018-04-03 9:48 ` Maxime Ripard
2018-04-03 9:50 ` Maxime Ripard
2018-04-03 9:52 ` Icenowy Zheng
2018-04-03 9:53 ` Chen-Yu Tsai
2018-04-03 9:54 ` Icenowy Zheng
2018-04-03 9:58 ` Chen-Yu Tsai
2018-04-03 11:36 ` Maxime Ripard
2018-04-04 6:45 ` Icenowy Zheng
2018-04-04 7:00 ` Chen-Yu Tsai
2018-03-17 9:28 ` [PATCH net-next 03/12] dt-bindings: net: dwmac-sun8i: Clean up clock delay chain descriptions Chen-Yu Tsai
2018-03-18 9:21 ` Sergei Shtylyov
2018-03-30 9:13 ` Chen-Yu Tsai
2018-03-17 9:28 ` [PATCH net-next 04/12] dt-bindings: net: dwmac-sun8i: Sort syscon compatibles by alphabetical order Chen-Yu Tsai
2018-03-26 22:23 ` Rob Herring
2018-03-17 9:28 ` [PATCH net-next 05/12] dt-bindings: net: dwmac-sun8i: Add binding for GMAC on Allwinner R40 SoC Chen-Yu Tsai
2018-03-17 9:28 ` [PATCH net-next 06/12] net: stmmac: dwmac-sun8i: Use regmap_field for syscon register access Chen-Yu Tsai
2018-03-22 7:42 ` kbuild test robot
2018-03-22 7:42 ` [RFC PATCH] net: stmmac: dwmac-sun8i: sun8i_syscon_reg_field can be static kbuild test robot
2018-03-22 19:07 ` David Miller
2018-03-17 9:28 ` Chen-Yu Tsai [this message]
2018-03-17 9:28 ` [PATCH net-next 08/12] net: stmmac: dwmac-sun8i: Support different ranges for TX/RX delay chains Chen-Yu Tsai
2018-03-17 9:28 ` [PATCH net-next 09/12] net: stmmac: dwmac-sun8i: Add support for GMAC on Allwinner R40 SoC Chen-Yu Tsai
2018-03-22 8:41 ` [RFC PATCH] net: stmmac: dwmac-sun8i: sun8i_ccu_reg_field can be static kbuild test robot
2018-03-22 8:41 ` [PATCH net-next 09/12] net: stmmac: dwmac-sun8i: Add support for GMAC on Allwinner R40 SoC kbuild test robot
2018-03-17 9:28 ` [PATCH net-next 10/12] ARM: dts: sun8i: r40: bananapi-m2-ultra: Sort device node dereferences Chen-Yu Tsai
2018-03-17 9:28 ` [PATCH net-next 11/12] ARM: dts: sun8i: r40: Add device node and RGMII pinmux node for GMAC Chen-Yu Tsai
2018-03-17 9:28 ` [PATCH net-next 12/12] ARM: dts: sun8i: r40: bananapi-m2-ultra: Enable GMAC ethernet controller Chen-Yu Tsai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180317092857.4396-8-wens@csie.org \
--to=wens@csie.org \
--cc=broonie@kernel.org \
--cc=clabbe.montjoie@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=icenowy@aosc.io \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maxime.ripard@bootlin.com \
--cc=mturquette@baylibre.com \
--cc=netdev@vger.kernel.org \
--cc=peppe.cavallaro@st.com \
--cc=robh+dt@kernel.org \
--cc=sboyd@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox