From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id A8EC11BF983 for ; Fri, 29 Mar 2019 03:06:25 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id A584F21FA9 for ; Fri, 29 Mar 2019 03:06:25 +0000 (UTC) Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id E4kIxdR7rhhT for ; Fri, 29 Mar 2019 03:06:24 +0000 (UTC) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by silver.osuosl.org (Postfix) with ESMTPS id 5B8EF2152F for ; Fri, 29 Mar 2019 03:06:24 +0000 (UTC) From: NeilBrown Date: Fri, 29 Mar 2019 14:06:15 +1100 Subject: Re: [PATCH 3/3] staging: mt7621-pci-phy: change driver to don't use child nodes In-Reply-To: <20190328175531.30844-4-sergio.paracuellos@gmail.com> References: <20190328175531.30844-1-sergio.paracuellos@gmail.com> <20190328175531.30844-4-sergio.paracuellos@gmail.com> Message-ID: <87mule2xco.fsf@notabene.neil.brown.name> MIME-Version: 1.0 List-Id: Linux Driver Project Developer List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============8109073452168296508==" Errors-To: driverdev-devel-bounces@linuxdriverproject.org Sender: "devel" To: Sergio Paracuellos Cc: gregkh@linuxfoundation.org, driverdev-devel@linuxdriverproject.org --===============8109073452168296508== Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Thu, Mar 28 2019, Sergio Paracuellos wrote: > Device tree has been simplified to don't use child nodes and use > the #phy-cells property instead. Change the driver accordly implementing > custom 'xlate' function to return the correct phy for each port. > > Signed-off-by: Sergio Paracuellos > --- > .../staging/mt7621-pci-phy/pci-mt7621-phy.c | 26 ++++++++++++++++--- > 1 file changed, 22 insertions(+), 4 deletions(-) > > diff --git a/drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c b/drivers/st= aging/mt7621-pci-phy/pci-mt7621-phy.c > index 98c06308143c..557e6a53fc1e 100644 > --- a/drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c > +++ b/drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c > @@ -78,6 +78,8 @@ >=20=20 > #define RG_PE1_FRC_MSTCKDIV BIT(5) >=20=20 > +#define MAX_PHYS 2 > + > /** > * struct mt7621_pci_phy_instance - Mt7621 Pcie PHY device > * @phy: pointer to the kernel PHY device > @@ -289,6 +291,20 @@ static const struct phy_ops mt7621_pci_phy_ops =3D { > .owner =3D THIS_MODULE, > }; >=20=20 > +static struct phy *mt7621_pcie_phy_of_xlate(struct device *dev, > + struct of_phandle_args *args) > +{ > + struct mt7621_pci_phy *mt7621_phy =3D dev_get_drvdata(dev); > + > + if (args->args_count =3D=3D 0) > + return mt7621_phy->phys[0]->phy; > + > + if (WARN_ON(args->args[0] >=3D MAX_PHYS)) > + return ERR_PTR(-ENODEV); > + > + return mt7621_phy->phys[args->args[0]]->phy; > +} > + > static int mt7621_pci_phy_probe(struct platform_device *pdev) > { > struct device *dev =3D &pdev->dev; > @@ -299,6 +315,7 @@ static int mt7621_pci_phy_probe(struct platform_devic= e *pdev) > struct resource res; > int port, ret; > void __iomem *port_base; > + u32 phy_num; >=20=20 > phy =3D devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); > if (!phy) > @@ -325,8 +342,9 @@ static int mt7621_pci_phy_probe(struct platform_devic= e *pdev) > return PTR_ERR(port_base); > } >=20=20 > - port =3D 0; > - for_each_child_of_node(np, child_np) { This isn't the old place that you depend on the children nodes. A little earlier, you have phy->nphys =3D of_get_child_count(np); which now sets nphys to zero. I changed this to phy->nphys =3D MAX_PHYS; > + of_property_read_u32(dev->of_node, "#phy-cells", &phy_num); > + > + for (port =3D 0; port < phy_num + 1; port++) { I don't think it is correct to use #phy-cells as the number of phys. #phy-cells is the number of arguments - the args_count seen in mt7621_pci_phy_probe. I think you should either assume phy_num is MAX_PHYS, or have built-in knowledge of when it is 1 and when it is too. There is minimal cost to allocating an extra phy, so I would go with MAX_PHYS. > struct mt7621_pci_phy_instance *instance; > struct phy *pphy; >=20=20 > @@ -338,7 +356,7 @@ static int mt7621_pci_phy_probe(struct platform_devic= e *pdev) >=20=20 > phy->phys[port] =3D instance; >=20=20 > - pphy =3D devm_phy_create(dev, child_np, &mt7621_pci_phy_ops); > + pphy =3D devm_phy_create(dev, dev->of_node, &mt7621_pci_phy_ops); > if (IS_ERR(phy)) { > dev_err(dev, "failed to create phy\n"); > ret =3D PTR_ERR(phy); > @@ -352,7 +370,7 @@ static int mt7621_pci_phy_probe(struct platform_devic= e *pdev) > port++; This "port++" duplicates the "port++" that you introduced in the "for" loop above. Thanks, NeilBrown > } >=20=20 > - provider =3D devm_of_phy_provider_register(dev, of_phy_simple_xlate); > + provider =3D devm_of_phy_provider_register(dev, mt7621_pcie_phy_of_xlat= e); >=20=20 > return PTR_ERR_OR_ZERO(provider); >=20=20 > --=20 > 2.19.1 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEG8Yp69OQ2HB7X0l6Oeye3VZigbkFAlydi6cACgkQOeye3VZi gblRDw/+J6Cp1GjQUd0Yns+LKACjC5h+Q6pCTwZIIo0wuxqf/Z1OI8cUOsn3gaF/ OpE4MmQ06TFY+AGoJ2aJmxyOIcmsuCd4J48NLlnbx8IWT6RJwYTVWDzhMHvVxGSs hLm8aihuPIm/FoO/rDiDjy3qf+OlIffsgHMR0XHlga7saz74lJRnI+rwYGuM+p/2 pS9gTzFVxUsSnG2V/pPNfAmVaHLSjIc0dX1I4v2utgdIAvcTT0tiHxIC/VBmEezL K3z7QOGdpaqBHjfF3X69U7eeOJIqZhZwH2WnisENMNBHNpiHZ8qaq/Sk+PlaOLvL rwQxN5MVWyLOVnC5pE1zfK/vcdPhkKNsDHtB40EqzYwHK5LT5/gP5RDFt1SL6lJ7 vzqVKRq9q9/l2B6LpG0pqmjasXRDCjLLrsz/ryRCfG/+trWChw+KXM9A0mhhMQga ytFT/sKHOsKRPXdUsLxB6PgxJ7TaSAxVeVXtWSYpAKjHwImrZ3kth/jRq8UipQFW QBY1RKrgnB4nEbiifA2B0bcT/H3QKrXfQQ8TeFA7PTmtcOtmDqJoQjS5WtcK2eJF kLj+AGNwUcsk3GXLIy60mGiDBFpUi/WcRHAH2Tf4r29XcEn4e4ATckaxDM/nQpoX LNW7MYgx/XnNaazY7IjqDIa6e+6o2IN/aHUo6usUQNoS2MWHq4Y= =tUKp -----END PGP SIGNATURE----- --=-=-=-- --===============8109073452168296508== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ devel mailing list devel@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel --===============8109073452168296508==--