From patchwork Wed Apr 11 14:16:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Icenowy Zheng X-Patchwork-Id: 10335589 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8707760134 for ; Wed, 11 Apr 2018 14:22:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B6EE289A7 for ; Wed, 11 Apr 2018 14:22:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A06C289B8; Wed, 11 Apr 2018 14:22:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 56E1228A1A for ; Wed, 11 Apr 2018 14:22:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=hlF/tfMrtoroGE1JYcK97ZGYvf/5kHxXGRAP6M6HF5A=; b=qclEeXhzAFFdVsyY05mYpykDdl DT9jNWgUboj2MsDo8PeUaO66fLncsTgKX9B4aN7xDaxukMnC2Pn1N2nUghxYMnm4SDPS0XNtreztT 8pTyLZrpldrZZQKcaG7zCHA6ksjUYYPAMXBtuZDMU14NrnrPq0uU8kSDyscSvvhWKzOxtv3tMe7Vf xTmLo3WV0bamSAO/YGCWXHjWPTKCFt9GiABZUXeQnGzTY/qHB6nuGufgrCXvaOGn5G1/IDfdmXXPx OESCrCLMUSjL6D21Ynb3uMhhvSzyMghIArgFUbyYrwQT5JgqOequVPK2fP4etHG5ftJjwSNohlNxf h53wC08A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f6GdR-0007LI-0E; Wed, 11 Apr 2018 14:22:05 +0000 Received: from catfish.maple.relay.mailchannels.net ([23.83.214.32]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f6Gcy-0006zP-MB for linux-arm-kernel@lists.infradead.org; Wed, 11 Apr 2018 14:21:46 +0000 X-Sender-Id: lmn-tzduiowcrqmw|x-authsender|icenowy@aosc.io Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 78E435E19C7; Wed, 11 Apr 2018 14:21:20 +0000 (UTC) Received: from hermes.aosc.io (unknown [100.96.13.37]) (Authenticated sender: lmn-TZDUIOWCRQMW) by relay.mailchannels.net (Postfix) with ESMTPA id 739845E1CFC; Wed, 11 Apr 2018 14:21:19 +0000 (UTC) X-Sender-Id: lmn-tzduiowcrqmw|x-authsender|icenowy@aosc.io Received: from hermes.aosc.io (hermes.aosc.io [172.19.42.59]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.14.1); Wed, 11 Apr 2018 14:21:20 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: lmn-tzduiowcrqmw|x-authsender|icenowy@aosc.io X-MailChannels-Auth-Id: lmn-TZDUIOWCRQMW X-Turn-Unite: 4d8d9cbe5d695479_1523456480310_1040083291 X-MC-Loop-Signature: 1523456480310:4262970575 X-MC-Ingress-Time: 1523456480309 Received: from localhost (localhost [127.0.0.1]) (Authenticated sender: icenowy@aosc.io) by hermes.aosc.io (Postfix) with ESMTPSA id D01D55A743; Wed, 11 Apr 2018 14:21:13 +0000 (UTC) From: Icenowy Zheng To: Rob Herring , Maxime Ripard , Chen-Yu Tsai , Giuseppe Cavallaro , Corentin Labbe Subject: [PATCH 3/5] net: stmmac: dwmac-sun8i: Allow getting syscon regmap from device Date: Wed, 11 Apr 2018 22:16:39 +0800 Message-Id: <20180411141641.14675-4-icenowy@aosc.io> In-Reply-To: <20180411141641.14675-1-icenowy@aosc.io> References: <20180411141641.14675-1-icenowy@aosc.io> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180411_072136_886115_68CDD3C9 X-CRM114-Status: GOOD ( 21.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, linux-arm-kernel@lists.infradead.org, Icenowy Zheng MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Chen-Yu Tsai 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 [Icenowy: change to use regmaps with single register, change commit message] Signed-off-by: Icenowy Zheng --- 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);