Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1932220ybz; Thu, 30 Apr 2020 08:00:15 -0700 (PDT) X-Google-Smtp-Source: APiQypJT6Uv6g4p0WfF5sYWkAvRWeFRvbodwZYvoO/wV//vI989EPNb9PEFg7QdOBHqPvSL/0OLd X-Received: by 2002:a17:906:200a:: with SMTP id 10mr2928792ejo.294.1588258814785; Thu, 30 Apr 2020 08:00:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588258814; cv=none; d=google.com; s=arc-20160816; b=lUytFGMrLv2vUwcTOurz0GiYP6aAcgr/FLIcNGP3J3qqV0WHAWKN3MeLe82hYVnwQN gEqDAIYCjq1otjFciVQTYh9U2w/5tXGbAGyjuPJrZOrgOB9Rx7Ym/ViZ42xVlWHrMnHP cqS+k5W/p8zfl7CTVrW/fiwtFTYpK6i/OsrDIXd1Flj03bkCIFa4jnjNEU7gL/rivAil NhHe/+P6SN9tDCcLMr+bSVrF1kAkt0NXgX1e3kFwDKANrkyAo66nnGGkjTDtXwZI47/5 OeGZc6bhFHDmDMGISkDaKeVhTaYzta/zr+RiC0V2jsQKzW/d3EzAYPGF3K6/8YM+a1Rf rSqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:dkim-signature; bh=Ak+6sr0EdSMe3A9inDGvwJSeZxZIogcefCgeBSV8VR0=; b=xpl86jURpo4tQFT9yiAci2vBTsXlL7DHaa2q/wLXivnsRbmuYqWepPdQ2FbZt9ay1d on+VOK0+ALbdzcaRD2twwtXuRC4gC6e6TeDVrlgJx9QCKV0XzmHw00ztzepPmOEeAI1O rsvs41qFTKMoUCs63vj7nWG6xSIH2MUe0n0moPy16PJDgAS83Y8VXAbJzxhwL2X/sCT8 Jl0MKPaPo6CKEfvOZd9mwLtmQw+biuYLmpS50+RsIIF3RVdiZ2pxe57fmG3PvgO+UX2g QWL1GkIH+xljlpSTXMMGbKD3Y75sS9cd+gVWTQC07HDhvUV6L2VAfihdRsl7ywaYFnuf 8Ebg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm2 header.b="XQAV9/kR"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=3yeCPvZy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cm8si5508608edb.417.2020.04.30.07.59.50; Thu, 30 Apr 2020 08:00:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm2 header.b="XQAV9/kR"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=3yeCPvZy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726688AbgD3O6Y (ORCPT + 99 others); Thu, 30 Apr 2020 10:58:24 -0400 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]:33167 "EHLO wout5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726436AbgD3O6X (ORCPT ); Thu, 30 Apr 2020 10:58:23 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 8D9458A2; Thu, 30 Apr 2020 10:58:22 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 30 Apr 2020 10:58:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=Ak+6sr0EdSMe3A9inDGvwJSeZxZ IogcefCgeBSV8VR0=; b=XQAV9/kRBmRyGAocCw4OPv0FgLqOY+7u4SYFjXEElPn puY5XUBWU3DhYpF62WzXhacU1tvWgLIk0L65DysYnDmfSpv8jhSMiAdvj/Yvhbrw 15qC1LoptX4yyI1aVcjvNckN8ir9yfuSY5+kFvTLKzKLwtusC3wrKPi5LgKG25dM Ct+hQQAX4jeWxAmaJzLTecpmp9mIswSOaXO9v9I0yJ/pE6+k9HyRBzsdUBYKcx8y Yf5np2aaO7vmsHpN9a9RNxyCEf6AEcka0p22EU34N+ZMzuZqFtOd7w7dtOF0S0mJ 8CBRahhhSnSuk/nN37gwGPEl+zxVrn4UIa3gaYVrh7Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=Ak+6sr 0EdSMe3A9inDGvwJSeZxZIogcefCgeBSV8VR0=; b=3yeCPvZyx+ICx+H4qFKXKw mIAPI8F5eRzBzwx7nbu76Gj+5u/Qtb60mqF8vdSRvqm34hdXj7KMelpz0CHuG50A GQN1UOV0BOpluxE5huMKFKxAW9ZrSJFQynQW+8r33JAUOIeuFkoA5/VLksWPhWLb hwwjvl6LseFebXRh7MGNK951l4XROIlXItct7E1b7dFNQkU8Tj/qnItZXiHESvR0 6q5L+IsQiXD6uRLSAVmNPiaMb7MMBUBW0WQmlNi2nBCJhhnmG7ghThhwdYz441fp Vrnu732c4Aju18AHAui4OJ+hDeajkEh8fTKisxy1JsjcZ80QIQVFk29hFz15yy1A == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrieehgdekvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujgesghdtreertddtvdenucfhrhhomhepofgrgihimhgv ucftihhprghrugcuoehmrgigihhmvgestggvrhhnohdrthgvtghhqeenucggtffrrghtth gvrhhnpeelkeeghefhuddtleejgfeljeffheffgfeijefhgfeufefhtdevteegheeiheeg udenucfkphepledtrdekledrieekrdejieenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehmrgigihhmvgestggvrhhnohdrthgvtghh X-ME-Proxy: Received: from localhost (lfbn-tou-1-1502-76.w90-89.abo.wanadoo.fr [90.89.68.76]) by mail.messagingengine.com (Postfix) with ESMTPA id 3E2913280065; Thu, 30 Apr 2020 10:58:19 -0400 (EDT) Date: Thu, 30 Apr 2020 16:58:17 +0200 From: Maxime Ripard To: Priit Laes Cc: Chen-Yu Tsai , Rob Herring , linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-sunxi@googlegroups.com Subject: Re: [PATCH v3 3/6] net: stmmac: dwmac-sunxi: Implement syscon-based clock handling Message-ID: <20200430145817.5cqa542jncomcklt@gilmour.lan> References: <20200430115702.5768-1-plaes@plaes.org> <20200430115702.5768-4-plaes@plaes.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="putviyvqcoxcobld" Content-Disposition: inline In-Reply-To: <20200430115702.5768-4-plaes@plaes.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --putviyvqcoxcobld Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Apr 30, 2020 at 02:56:59PM +0300, Priit Laes wrote: > Convert the sun7i-gmac driver to use a regmap-based driver, > instead of relying on the custom clock implementation. >=20 > This allows to get rid of the last custom clock in the sun7i > device tree making the sun7i fully CCU-compatible. >=20 > Compatibility with existing devicetrees is retained. >=20 > Signed-off-by: Priit Laes > --- > .../net/ethernet/stmicro/stmmac/dwmac-sunxi.c | 130 ++++++++++++++++-- > 1 file changed, 122 insertions(+), 8 deletions(-) >=20 > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c b/drivers/= net/ethernet/stmicro/stmmac/dwmac-sunxi.c > index 0e1ca2cba3c7..206398f7a2af 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c > @@ -12,8 +12,11 @@ > #include > #include > #include > +#include > #include > #include > +#include > +#include > =20 > #include "stmmac_platform.h" > =20 > @@ -22,11 +25,23 @@ struct sunxi_priv_data { > int clk_enabled; > struct clk *tx_clk; > struct regulator *regulator; > + struct regmap_field *regmap_field; > +}; > + > +/* EMAC clock register @ 0x164 in the CCU address range */ > +static const struct reg_field ccu_reg_field =3D { > + .reg =3D 0x164, > + .lsb =3D 0, > + .msb =3D 31, > }; > =20 > #define SUN7I_GMAC_GMII_RGMII_RATE 125000000 > #define SUN7I_GMAC_MII_RATE 25000000 > =20 > +#define SUN7I_A20_CLK_MASK GENMASK(2, 0) > +#define SUN7I_A20_RGMII_CLK (BIT(2) | BIT(1)) > +#define SUN7I_A20_MII_CLK 0 > + > static int sun7i_gmac_init(struct platform_device *pdev, void *priv) > { > struct sunxi_priv_data *gmac =3D priv; > @@ -38,7 +53,20 @@ static int sun7i_gmac_init(struct platform_device *pde= v, void *priv) > return ret; > } > =20 > - /* Set GMAC interface port mode > + if (gmac->regmap_field) { > + if (phy_interface_mode_is_rgmii(gmac->interface)) { > + regmap_field_update_bits(gmac->regmap_field, > + SUN7I_A20_CLK_MASK, > + SUN7I_A20_RGMII_CLK); > + return clk_prepare_enable(gmac->tx_clk); > + } Why do you prepare and enable the clock here? ... > + regmap_field_update_bits(gmac->regmap_field, > + SUN7I_A20_CLK_MASK, > + SUN7I_A20_MII_CLK); > + return clk_enable(gmac->tx_clk); > + } =2E.. while you only enable it here ... > + /* Legacy devicetree clock (allwinner,sun7i-a20-gmac-clk) support: > * > * The GMAC TX clock lines are configured by setting the clock > * rate, which then uses the auto-reparenting feature of the > @@ -62,9 +90,16 @@ static void sun7i_gmac_exit(struct platform_device *pd= ev, void *priv) > { > struct sunxi_priv_data *gmac =3D priv; > =20 > - if (gmac->clk_enabled) { > + if (gmac->regmap_field) { > + regmap_field_update_bits(gmac->regmap_field, > + SUN7I_A20_CLK_MASK, 0); > clk_disable(gmac->tx_clk); > - gmac->clk_enabled =3D 0; > + } else { > + /* Handle legacy devicetree clock (sun7i-a20-gmac-clk) */ > + if (gmac->clk_enabled) { > + clk_disable(gmac->tx_clk); > + gmac->clk_enabled =3D 0; > + } > } > clk_unprepare(gmac->tx_clk); =2E... and disable and unprepare it here? > @@ -72,10 +107,55 @@ static void sun7i_gmac_exit(struct platform_device *= pdev, void *priv) > regulator_disable(gmac->regulator); > } > =20 > +static struct regmap *sun7i_gmac_get_syscon_from_dev(struct device_node = *node) > +{ > + struct device_node *syscon_node; > + struct platform_device *syscon_pdev; > + struct regmap *regmap =3D NULL; > + > + syscon_node =3D of_parse_phandle(node, "syscon", 0); > + if (!syscon_node) > + return ERR_PTR(-ENODEV); > + > + syscon_pdev =3D of_find_device_by_node(syscon_node); > + if (!syscon_pdev) { > + /* platform device might not be probed yet */ > + regmap =3D ERR_PTR(-EPROBE_DEFER); > + goto out_put_node; > + } > + > + /* If no regmap is found then the other device driver is at fault */ > + regmap =3D dev_get_regmap(&syscon_pdev->dev, NULL); > + if (!regmap) > + regmap =3D ERR_PTR(-EINVAL); > + > + platform_device_put(syscon_pdev); > +out_put_node: > + of_node_put(syscon_node); > + return regmap; > +} > + > static void sun7i_fix_speed(void *priv, unsigned int speed) > { > struct sunxi_priv_data *gmac =3D priv; > =20 > + if (gmac->regmap_field) { > + clk_disable(gmac->tx_clk); > + clk_unprepare(gmac->tx_clk); > + if (speed =3D=3D 1000) > + regmap_field_update_bits(gmac->regmap_field, > + SUN7I_A20_CLK_MASK, > + SUN7I_A20_RGMII_CLK); > + else > + regmap_field_update_bits(gmac->regmap_field, > + SUN7I_A20_CLK_MASK, > + SUN7I_A20_MII_CLK); > + clk_prepare_enable(gmac->tx_clk); If were going to use clk_prepare_enable, we might as well use clk_disable_unprepare > + return; > + } > + > + /* Handle legacy devicetree clock (sun7i-a20-gmac-clk) */ That doesn't say much, you should rather explain what the situation is exac= tly. > + > /* only GMII mode requires us to reconfigure the clock lines */ > if (gmac->interface !=3D PHY_INTERFACE_MODE_GMII) > return; > @@ -102,6 +182,8 @@ static int sun7i_gmac_probe(struct platform_device *p= dev) > struct stmmac_resources stmmac_res; > struct sunxi_priv_data *gmac; > struct device *dev =3D &pdev->dev; > + struct device_node *syscon_node; > + struct regmap *regmap =3D NULL; > int ret; > =20 > ret =3D stmmac_get_platform_resources(pdev, &stmmac_res); > @@ -124,11 +206,43 @@ static int sun7i_gmac_probe(struct platform_device = *pdev) > goto err_remove_config_dt; > } > =20 > - gmac->tx_clk =3D devm_clk_get(dev, "allwinner_gmac_tx"); > - if (IS_ERR(gmac->tx_clk)) { > - dev_err(dev, "could not get tx clock\n"); > - ret =3D PTR_ERR(gmac->tx_clk); > - goto err_remove_config_dt; > + /* Attempt to fetch syscon node... */ > + syscon_node =3D of_parse_phandle(dev->of_node, "syscon", 0); > + if (syscon_node) { > + gmac->tx_clk =3D devm_clk_get(dev, "stmmaceth"); > + if (IS_ERR(gmac->tx_clk)) { > + dev_err(dev, "Could not get TX clock\n"); > + ret =3D PTR_ERR(gmac->tx_clk); > + goto err_remove_config_dt; > + } I'm not quite sure why you added this clock lookup here? Wasn't it here alr= eady? Maxime --putviyvqcoxcobld Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRcEzekXsqa64kGDp7j7w1vZxhRxQUCXqrniQAKCRDj7w1vZxhR xZyaAQDsoPEZO+RMAghgqFiaZgAIxVjUOPbVNuYyKb7pEwGGCQEA7VGSYNwkBDzN PWU3lUz+NIedfeEMtoNHCeq3266+hg8= =L/+p -----END PGP SIGNATURE----- --putviyvqcoxcobld--