diff mbox series

[V4,04/13] phy: rcar-gen3-usb2: Add support for r8a77470

Message ID 1554883715-41725-5-git-send-email-biju.das@bp.renesas.com (mailing list archive)
State Superseded
Delegated to: Geert Uytterhoeven
Headers show
Series Add USB2.0 support | expand

Commit Message

Biju Das April 10, 2019, 8:08 a.m. UTC
This patch adds support for r8a77470 (RZ/G1C). We can reuse this driver for
initializing timing/interrupt generation registers.

Signed-off-by: Biju Das <biju.das@bp.renesas.com>
---
V3-->V4
 * Incorporated Kishan and Shimoda-san's review comment
  https://patchwork.kernel.org/patch/10883265/
V2-->V3
 * Incorporated shimoda-san's review comment
 Ref: https://patchwork.kernel.org/patch/10655855/
---
 drivers/phy/renesas/Kconfig              |  2 +-
 drivers/phy/renesas/phy-rcar-gen3-usb2.c | 38 +++++++++++++++++++++++++++-----
 2 files changed, 33 insertions(+), 7 deletions(-)

Comments

Yoshihiro Shimoda April 10, 2019, 9:42 a.m. UTC | #1
Hi Biju-san,

Thank you for the patch!

> From: Biju Das, Sent: Wednesday, April 10, 2019 5:08 PM
> 
> This patch adds support for r8a77470 (RZ/G1C). We can reuse this driver for
> initializing timing/interrupt generation registers.
> 
> Signed-off-by: Biju Das <biju.das@bp.renesas.com>
> ---
<snip>
> diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
> index 0a34782..5a8e673 100644
> --- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c
> +++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
> @@ -22,6 +22,7 @@
>  #include <linux/regulator/consumer.h>
>  #include <linux/usb/of.h>
>  #include <linux/workqueue.h>
> +#include <linux/sys_soc.h>

We don't need it.

>  /******* USB2.0 Host registers (original offset is +0x200) *******/
>  #define USB2_INT_ENABLE		0x000
> @@ -393,6 +394,12 @@ static const struct phy_ops rcar_gen3_phy_usb2_ops = {
>  	.owner		= THIS_MODULE,
>  };
> 
> +static const struct phy_ops rz_g1c_phy_usb2_ops = {
> +	.init		= rcar_gen3_phy_usb2_init,
> +	.exit		= rcar_gen3_phy_usb2_exit,
> +	.owner		= THIS_MODULE,
> +};
> +
>  static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)
>  {
>  	struct rcar_gen3_chan *ch = _ch;
> @@ -411,11 +418,27 @@ static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)
>  }
> 
>  static const struct of_device_id rcar_gen3_phy_usb2_match_table[] = {
> -	{ .compatible = "renesas,usb2-phy-r8a7795" },
> -	{ .compatible = "renesas,usb2-phy-r8a7796" },
> -	{ .compatible = "renesas,usb2-phy-r8a77965" },
> -	{ .compatible = "renesas,rcar-gen3-usb2-phy" },
> -	{ }
> +	{
> +		.compatible = "renesas,usb2-phy-r8a77470",
> +		.data = &rz_g1c_phy_usb2_ops,
> +	},
> +	{
> +		.compatible = "renesas,usb2-phy-r8a7795",
> +		.data = &rcar_gen3_phy_usb2_ops,
> +	},
> +	{
> +		.compatible = "renesas,usb2-phy-r8a7796",
> +		.data = &rcar_gen3_phy_usb2_ops,
> +	},
> +	{
> +		.compatible = "renesas,usb2-phy-r8a77965",
> +		.data = &rcar_gen3_phy_usb2_ops,
> +	},
> +	{
> +		.compatible = "renesas,rcar-gen3-usb2-phy",
> +		.data = &rcar_gen3_phy_usb2_ops,
> +	},
> +	{ /* sentinel */ },
>  };
>  MODULE_DEVICE_TABLE(of, rcar_gen3_phy_usb2_match_table);
> 
> @@ -431,6 +454,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
>  	struct rcar_gen3_chan *channel;
>  	struct phy_provider *provider;
>  	struct resource *res;
> +	const struct phy_ops *phy_usb2_ops;
>  	int irq, ret = 0;
> 
>  	if (!dev->of_node) {
> @@ -481,7 +505,9 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
>  	 * And then, phy-core will manage runtime pm for this device.
>  	 */
>  	pm_runtime_enable(dev);
> -	channel->phy = devm_phy_create(dev, NULL, &rcar_gen3_phy_usb2_ops);
> +	phy_usb2_ops = (const struct phy_ops *) of_device_get_match_data(dev);

We don't need the cast. Also, I think we have to check the phy_usb2_ops is not NULL.

After they are fixed:

Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>

Best regards,
Yoshihiro Shimoda

> +	channel->phy = devm_phy_create(dev, NULL, phy_usb2_ops);
>  	if (IS_ERR(channel->phy)) {
>  		dev_err(dev, "Failed to create USB2 PHY\n");
>  		ret = PTR_ERR(channel->phy);
> --
> 2.7.4
Biju Das April 10, 2019, 10:29 a.m. UTC | #2
Hi Shimoda-San,

Thanks for the feedback.

> Subject: RE: [PATCH V4 04/13] phy: rcar-gen3-usb2: Add support for r8a77470
> 
> Hi Biju-san,
> 
> Thank you for the patch!
> 
> > From: Biju Das, Sent: Wednesday, April 10, 2019 5:08 PM
> >
> > This patch adds support for r8a77470 (RZ/G1C). We can reuse this
> > driver for initializing timing/interrupt generation registers.
> >
> > Signed-off-by: Biju Das <biju.das@bp.renesas.com>
> > ---
> <snip>
> > diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c
> > b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
> > index 0a34782..5a8e673 100644
> > --- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c
> > +++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
> > @@ -22,6 +22,7 @@
> >  #include <linux/regulator/consumer.h>  #include <linux/usb/of.h>
> > #include <linux/workqueue.h>
> > +#include <linux/sys_soc.h>
> 
> We don't need it.

OK . will take this out.

> >  /******* USB2.0 Host registers (original offset is +0x200) *******/
> >  #define USB2_INT_ENABLE		0x000
> > @@ -393,6 +394,12 @@ static const struct phy_ops
> rcar_gen3_phy_usb2_ops = {
> >  	.owner		= THIS_MODULE,
> >  };
> >
> > +static const struct phy_ops rz_g1c_phy_usb2_ops = {
> > +	.init		= rcar_gen3_phy_usb2_init,
> > +	.exit		= rcar_gen3_phy_usb2_exit,
> > +	.owner		= THIS_MODULE,
> > +};
> > +
> >  static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)
> >  {
> >  	struct rcar_gen3_chan *ch = _ch;
> > @@ -411,11 +418,27 @@ static irqreturn_t rcar_gen3_phy_usb2_irq(int irq,
> void *_ch)
> >  }
> >
> >  static const struct of_device_id rcar_gen3_phy_usb2_match_table[] = {
> > -	{ .compatible = "renesas,usb2-phy-r8a7795" },
> > -	{ .compatible = "renesas,usb2-phy-r8a7796" },
> > -	{ .compatible = "renesas,usb2-phy-r8a77965" },
> > -	{ .compatible = "renesas,rcar-gen3-usb2-phy" },
> > -	{ }
> > +	{
> > +		.compatible = "renesas,usb2-phy-r8a77470",
> > +		.data = &rz_g1c_phy_usb2_ops,
> > +	},
> > +	{
> > +		.compatible = "renesas,usb2-phy-r8a7795",
> > +		.data = &rcar_gen3_phy_usb2_ops,
> > +	},
> > +	{
> > +		.compatible = "renesas,usb2-phy-r8a7796",
> > +		.data = &rcar_gen3_phy_usb2_ops,
> > +	},
> > +	{
> > +		.compatible = "renesas,usb2-phy-r8a77965",
> > +		.data = &rcar_gen3_phy_usb2_ops,
> > +	},
> > +	{
> > +		.compatible = "renesas,rcar-gen3-usb2-phy",
> > +		.data = &rcar_gen3_phy_usb2_ops,
> > +	},
> > +	{ /* sentinel */ },
> >  };
> >  MODULE_DEVICE_TABLE(of, rcar_gen3_phy_usb2_match_table);
> >
> > @@ -431,6 +454,7 @@ static int rcar_gen3_phy_usb2_probe(struct
> platform_device *pdev)
> >  	struct rcar_gen3_chan *channel;
> >  	struct phy_provider *provider;
> >  	struct resource *res;
> > +	const struct phy_ops *phy_usb2_ops;
> >  	int irq, ret = 0;
> >
> >  	if (!dev->of_node) {
> > @@ -481,7 +505,9 @@ static int rcar_gen3_phy_usb2_probe(struct
> platform_device *pdev)
> >  	 * And then, phy-core will manage runtime pm for this device.
> >  	 */
> >  	pm_runtime_enable(dev);
> > -	channel->phy = devm_phy_create(dev, NULL,
> &rcar_gen3_phy_usb2_ops);
> > +	phy_usb2_ops = (const struct phy_ops *)
> of_device_get_match_data(dev);
> 
> We don't need the cast. Also, I think we have to check the phy_usb2_ops is
> not NULL.

OK. I have checked other rcar drivers and came to the conclusion that there is need for Null check(for eg:- renesas-cpg-mssr.c, gpio-rcar.c)
Any way there is no harm in adding  this check, since the api can return null value.

I will send V5 As you suggested.  ie, will remove the cast and will add check for not  NULL.
if (!phy_usb2_ops)
	return -EINVAL;

> After they are fixed:
> 
> Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> 
> Best regards,
> Yoshihiro Shimoda
> 
> > +	channel->phy = devm_phy_create(dev, NULL, phy_usb2_ops);
> >  	if (IS_ERR(channel->phy)) {
> >  		dev_err(dev, "Failed to create USB2 PHY\n");
> >  		ret = PTR_ERR(channel->phy);
> > --
Regards,
Biju
diff mbox series

Patch

diff --git a/drivers/phy/renesas/Kconfig b/drivers/phy/renesas/Kconfig
index e340a92..111bdca 100644
--- a/drivers/phy/renesas/Kconfig
+++ b/drivers/phy/renesas/Kconfig
@@ -19,7 +19,7 @@  config PHY_RCAR_GEN3_PCIE
 config PHY_RCAR_GEN3_USB2
 	tristate "Renesas R-Car generation 3 USB 2.0 PHY driver"
 	depends on ARCH_RENESAS
-	depends on EXTCON
+	depends on EXTCON || !EXTCON # if EXTCON=m, this cannot be built-in
 	depends on USB_SUPPORT
 	select GENERIC_PHY
 	select USB_COMMON
diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
index 0a34782..5a8e673 100644
--- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
@@ -22,6 +22,7 @@ 
 #include <linux/regulator/consumer.h>
 #include <linux/usb/of.h>
 #include <linux/workqueue.h>
+#include <linux/sys_soc.h>
 
 /******* USB2.0 Host registers (original offset is +0x200) *******/
 #define USB2_INT_ENABLE		0x000
@@ -393,6 +394,12 @@  static const struct phy_ops rcar_gen3_phy_usb2_ops = {
 	.owner		= THIS_MODULE,
 };
 
+static const struct phy_ops rz_g1c_phy_usb2_ops = {
+	.init		= rcar_gen3_phy_usb2_init,
+	.exit		= rcar_gen3_phy_usb2_exit,
+	.owner		= THIS_MODULE,
+};
+
 static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)
 {
 	struct rcar_gen3_chan *ch = _ch;
@@ -411,11 +418,27 @@  static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)
 }
 
 static const struct of_device_id rcar_gen3_phy_usb2_match_table[] = {
-	{ .compatible = "renesas,usb2-phy-r8a7795" },
-	{ .compatible = "renesas,usb2-phy-r8a7796" },
-	{ .compatible = "renesas,usb2-phy-r8a77965" },
-	{ .compatible = "renesas,rcar-gen3-usb2-phy" },
-	{ }
+	{
+		.compatible = "renesas,usb2-phy-r8a77470",
+		.data = &rz_g1c_phy_usb2_ops,
+	},
+	{
+		.compatible = "renesas,usb2-phy-r8a7795",
+		.data = &rcar_gen3_phy_usb2_ops,
+	},
+	{
+		.compatible = "renesas,usb2-phy-r8a7796",
+		.data = &rcar_gen3_phy_usb2_ops,
+	},
+	{
+		.compatible = "renesas,usb2-phy-r8a77965",
+		.data = &rcar_gen3_phy_usb2_ops,
+	},
+	{
+		.compatible = "renesas,rcar-gen3-usb2-phy",
+		.data = &rcar_gen3_phy_usb2_ops,
+	},
+	{ /* sentinel */ },
 };
 MODULE_DEVICE_TABLE(of, rcar_gen3_phy_usb2_match_table);
 
@@ -431,6 +454,7 @@  static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
 	struct rcar_gen3_chan *channel;
 	struct phy_provider *provider;
 	struct resource *res;
+	const struct phy_ops *phy_usb2_ops;
 	int irq, ret = 0;
 
 	if (!dev->of_node) {
@@ -481,7 +505,9 @@  static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
 	 * And then, phy-core will manage runtime pm for this device.
 	 */
 	pm_runtime_enable(dev);
-	channel->phy = devm_phy_create(dev, NULL, &rcar_gen3_phy_usb2_ops);
+	phy_usb2_ops = (const struct phy_ops *) of_device_get_match_data(dev);
+
+	channel->phy = devm_phy_create(dev, NULL, phy_usb2_ops);
 	if (IS_ERR(channel->phy)) {
 		dev_err(dev, "Failed to create USB2 PHY\n");
 		ret = PTR_ERR(channel->phy);