LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Icenowy Zheng <icenowy@aosc.io>
To: Rob Herring <robh+dt@kernel.org>,
	Maxime Ripard <maxime.ripard@bootlin.com>,
	Chen-Yu Tsai <wens@csie.org>,
	Giuseppe Cavallaro <peppe.cavallaro@st.com>,
	Corentin Labbe <clabbe.montjoie@gmail.com>
Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com,
	Icenowy Zheng <icenowy@aosc.io>
Subject: [PATCH 3/5] net: stmmac: dwmac-sun8i: Allow getting syscon regmap from device
Date: Wed, 11 Apr 2018 22:16:39 +0800	[thread overview]
Message-ID: <20180411141641.14675-4-icenowy@aosc.io> (raw)
In-Reply-To: <20180411141641.14675-1-icenowy@aosc.io>

From: Chen-Yu Tsai <wens@csie.org>

On the Allwinner R40 SoC, the "GMAC clock" register is in the CCU
address space; on the A64 SoC this register is in the SRAM controller
address space, and with a different offset.

To access the register from another device and hide the internal
difference between the device, let it register a regmap named
"emac-clock". We can then get the device from the phandle, and
retrieve the regmap with dev_get_regmap(); in this situation the
regmap_field will be set up to access the only register in the regmap.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
[Icenowy: change to use regmaps with single register, change commit
 message]
Signed-off-by: Icenowy Zheng <icenowy@aosc.io>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 48 ++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index 1037f6c78bca..b61210c0d415 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -85,6 +85,13 @@ const struct reg_field old_syscon_reg_field = {
 	.msb = 31,
 };
 
+/* Specially exported regmap which contains only EMAC register */
+const struct reg_field single_reg_field = {
+	.reg = 0,
+	.lsb = 0,
+	.msb = 31,
+};
+
 static const struct emac_variant emac_variant_h3 = {
 	.default_syscon_value = 0x58000,
 	.soc_has_internal_phy = true,
@@ -979,6 +986,44 @@ static struct mac_device_info *sun8i_dwmac_setup(void *ppriv)
 	return mac;
 }
 
+static struct regmap *sun8i_dwmac_get_emac_regmap(struct sunxi_priv_data *emac,
+						  struct device_node *node)
+{
+	struct device_node *syscon_node;
+	struct platform_device *syscon_pdev = NULL;
+	struct regmap *regmap = NULL;
+
+	syscon_node = of_parse_phandle(node, "syscon", 0);
+	if (!syscon_node)
+		return ERR_PTR(-ENODEV);
+
+	if (of_device_is_compatible(syscon_node, "syscon")) {
+		regmap = syscon_regmap_lookup_by_phandle(node, "syscon");
+
+		emac->emac_reg_field = &old_syscon_reg_field;
+	} else {
+		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 trap into error */
+		regmap = dev_get_regmap(&syscon_pdev->dev, "emac-clock");
+		if (!regmap)
+			regmap = ERR_PTR(-EINVAL);
+
+		emac->emac_reg_field = &single_reg_field;
+	}
+
+	if (syscon_pdev)
+		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;
@@ -1023,13 +1068,12 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
 		gmac->regulator = NULL;
 	}
 
-	regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, "syscon");
+	regmap = sun8i_dwmac_get_emac_regmap(gmac, pdev->dev.of_node);
 	if (IS_ERR(regmap)) {
 		ret = PTR_ERR(regmap);
 		dev_err(&pdev->dev, "Unable to map syscon: %d\n", ret);
 		return ret;
 	}
-	gmac->emac_reg_field = old_syscon_reg_field;
 
 	gmac->regmap_field = devm_regmap_field_alloc(dev, regmap,
 						     *gmac->emac_reg_field);
-- 
2.15.1

  parent reply	other threads:[~2018-04-11 14:21 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-11 14:16 [PATCH 0/5] Add support in dwmac-sun8i for accessing EMAC clock Icenowy Zheng
2018-04-11 14:16 ` [PATCH 1/5] dt-bindings: allow dwmac-sun8i to use other devices' exported regmap Icenowy Zheng
2018-04-11 14:36   ` [linux-sunxi] " Brüns, Stefan
2018-04-16 18:47   ` Rob Herring
2018-04-16 23:17     ` Icenowy Zheng
2018-04-28 13:42       ` [linux-sunxi] " Chen-Yu Tsai
2018-04-11 14:16 ` [PATCH 2/5] net: stmmac: dwmac-sun8i: Use regmap_field for syscon register access Icenowy Zheng
2018-04-11 14:16 ` Icenowy Zheng [this message]
2018-04-12 14:56   ` [PATCH 3/5] net: stmmac: dwmac-sun8i: Allow getting syscon regmap from device Maxime Ripard
2018-04-12 15:11     ` Icenowy Zheng
2018-04-12 15:23       ` [linux-sunxi] " Chen-Yu Tsai
2018-04-16 14:31         ` Maxime Ripard
2018-04-16 14:34           ` Icenowy Zheng
2018-04-16 14:51           ` Chen-Yu Tsai
2018-04-17 11:52             ` Maxime Ripard
2018-04-17 11:59               ` Chen-Yu Tsai
2018-04-17 12:06                 ` Icenowy Zheng
2018-04-13  6:03   ` [RFC PATCH] net: stmmac: dwmac-sun8i: single_reg_field can be static kbuild test robot
2018-04-13  6:03   ` [PATCH 3/5] net: stmmac: dwmac-sun8i: Allow getting syscon regmap from device kbuild test robot
2018-04-11 14:16 ` [PATCH 4/5] drivers: soc: sunxi: export a regmap for EMAC clock reg on A64 Icenowy Zheng
2018-04-11 14:16 ` [PATCH 5/5] arm64: allwinner: a64: add SRAM controller device tree node Icenowy Zheng
2018-04-12 14:58   ` Maxime Ripard

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=20180411141641.14675-4-icenowy@aosc.io \
    --to=icenowy@aosc.io \
    --cc=clabbe.montjoie@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sunxi@googlegroups.com \
    --cc=maxime.ripard@bootlin.com \
    --cc=netdev@vger.kernel.org \
    --cc=peppe.cavallaro@st.com \
    --cc=robh+dt@kernel.org \
    --cc=wens@csie.org \
    --subject='Re: [PATCH 3/5] net: stmmac: dwmac-sun8i: Allow getting syscon regmap from device' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).