Received: by 10.192.165.156 with SMTP id m28csp797185imm; Wed, 11 Apr 2018 07:25:55 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/h5OJoLdC9smQQ1xBSAdyVlcXH8DXyMlRSeqHJizu6hWpxPsIeCc/UfL8w2Z/EQekD53gF X-Received: by 2002:a17:902:778e:: with SMTP id o14-v6mr5388147pll.294.1523456755077; Wed, 11 Apr 2018 07:25:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523456755; cv=none; d=google.com; s=arc-20160816; b=Vauft/lWfquYAR4J2tLymgNOMZHdlGYbW1pv1Owkhn3Jo2Lb+X2bUzPzypPssF89XK Dh5wA6fTgPhZ9hDSMH3EMqEqShBYNfVuZFEbMvtd+dyjVRUsk6oGmO24caF35sO9huPk 1YJWw24GemAmH3CHtCuIJZCrMYLJdR9c1OvumCnoVK86MxEXG5fR7qXfJcPQjJIOYCej JHCyKONQFIQC98Xsw7YUk/XqBEgtuCAnD2EWjSX/t8XO4Z90kpHx2PitWDXf4Cs87vaa WJ6XGrpxPXiYpLLfktl7KK++KOQXeTtf2dLNmo60XMZPzFfWzZVjw7kbUr4IG/Bthesl GSqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=TGqMAZjkndrHPE0AWRFX5qZ5xOl/ZMbq1sLMFN4Jz74=; b=Z8l9nnTm2t4/8KhBcB1A5EIUklwvLoO32xndQgZlvaCL0ENzt1+Y9wnykhhnR1dY1h 1OA3vL6WV6P3Wk3mlrNoBHLK93V9bYlIqHZaaUbxWfE0GIMXLVOt6+3dADQgkX7tYOB2 Mq4eVy79VdsctfqwFGuJEDjbN09mf67AxWVlPyLNlgDBAOX3+JBiQnn4KXyh6hv6V3vK 8EpeS/0YxUYmGr4iQumU15GSxY5JLIjfA05xbUORBGwjEAzKo2yhII2NeDJqrm8pOA+T mlbJYH+mURscd3enpDLeYS8JMaaOHtyYah7cpG8V3Vq9Rw+n9huwaXB1P8UO+7rYVtLw NCpQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b59-v6si1155434plb.530.2018.04.11.07.25.17; Wed, 11 Apr 2018 07:25:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753668AbeDKOVU (ORCPT + 99 others); Wed, 11 Apr 2018 10:21:20 -0400 Received: from hermes.aosc.io ([199.195.250.187]:48396 "EHLO hermes.aosc.io" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753107AbeDKOVS (ORCPT ); Wed, 11 Apr 2018 10:21:18 -0400 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 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 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.15.1