diff mbox

[v5,2/2] phy: rockchip-inno-usb2: add a new driver for Rockchip usb2phy

Message ID 24acf224-e792-6648-fcdb-8729ded6df84@rock-chips.com (mailing list archive)
State New, archived
Headers show

Commit Message

Frank Wang June 15, 2016, 1:14 a.m. UTC
Hi Heiko & Guenter,

On 2016/6/14 22:00, Heiko Stübner wrote:
> Am Dienstag, 14. Juni 2016, 06:50:31 schrieb Guenter Roeck:
>> On Tue, Jun 14, 2016 at 6:27 AM, Heiko Stübner <heiko@sntech.de> wrote:
>>> Am Montag, 13. Juni 2016, 10:10:10 schrieb Frank Wang:
>>>> The newer SoCs (rk3366, rk3399) take a different usb-phy IP block
>>>> than rk3288 and before, and most of phy-related registers are also
>>>> different from the past, so a new phy driver is required necessarily.
>>>>
>>>> Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
>>>> ---
> [...]
>
>>>> +static int rockchip_usb2phy_init(struct phy *phy)
>>>> +{
>>>> +     struct rockchip_usb2phy_port *rport = phy_get_drvdata(phy);
>>>> +     struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent);
>>>> +     int ret;
>>>> +
>>>>
>>>          if (!rport->port_cfg)
>>>          
>>>                  return 0;
>>>
>>> Otherwise the currently empty otg-port will cause null-pointer
>>> dereferences
>>> when it gets assigned in the devicetree already.
>> Not really, at least not here - that port should not have port_id set
>> to USB2PHY_PORT_HOST.
>>
>> Does it even make sense to instantiate the otg port ? Is it going to
>> do anything without port configuration ?
> Ok, that would be the other option - not creating the phy in the driver.

Well, I will put this conditional inside *_host_port_init(), if it is an 
empty, the phy-device should not be created.
Something like the following:

> initially as well most likely, supplying the additional otg-parts later on.

@Guenter, just as Heiko said, the otg-parts is not ready now, it will be 
supplied later.


BR.
Frank

Comments

Guenter Roeck June 15, 2016, 3:47 p.m. UTC | #1
On Tue, Jun 14, 2016 at 6:14 PM, Frank Wang <frank.wang@rock-chips.com> wrote:
> Hi Heiko & Guenter,
>
>
> On 2016/6/14 22:00, Heiko Stübner wrote:
>>
>> Am Dienstag, 14. Juni 2016, 06:50:31 schrieb Guenter Roeck:
>>>
>>> On Tue, Jun 14, 2016 at 6:27 AM, Heiko Stübner <heiko@sntech.de> wrote:
>>>>
>>>> Am Montag, 13. Juni 2016, 10:10:10 schrieb Frank Wang:
>>>>>
>>>>> The newer SoCs (rk3366, rk3399) take a different usb-phy IP block
>>>>> than rk3288 and before, and most of phy-related registers are also
>>>>> different from the past, so a new phy driver is required necessarily.
>>>>>
>>>>> Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
>>>>> ---
>>
>> [...]
>>
>>>>> +static int rockchip_usb2phy_init(struct phy *phy)
>>>>> +{
>>>>> +     struct rockchip_usb2phy_port *rport = phy_get_drvdata(phy);
>>>>> +     struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent);
>>>>> +     int ret;
>>>>> +
>>>>>
>>>>          if (!rport->port_cfg)
>>>>                           return 0;
>>>>
>>>> Otherwise the currently empty otg-port will cause null-pointer
>>>> dereferences
>>>> when it gets assigned in the devicetree already.
>>>
>>> Not really, at least not here - that port should not have port_id set
>>> to USB2PHY_PORT_HOST.
>>>
>>> Does it even make sense to instantiate the otg port ? Is it going to
>>> do anything without port configuration ?
>>
>> Ok, that would be the other option - not creating the phy in the driver.
>
>
> Well, I will put this conditional inside *_host_port_init(), if it is an
> empty, the phy-device should not be created.
> Something like the following:
>
> --- a/drivers/phy/phy-rockchip-inno-usb2.c
> +++ b/drivers/phy/phy-rockchip-inno-usb2.c
> @@ -483,9 +483,13 @@ static int rockchip_usb2phy_host_port_init(struct
> rockchip_usb2phy *rphy,
>  {
>         int ret;
>
> -       rport->port_id = USB2PHY_PORT_HOST;
>         rport->port_cfg = &rphy->phy_cfg->port_cfgs[USB2PHY_PORT_HOST];
> +       if (!rport->port_cfg) {
> +               dev_err(rphy->dev, "no host port-config provided.\n");
> +               return -EINVAL;
> +       }

This would never be NULL. At issue is that you don't assign port_cfg
if the port is _not_ a host port.

Guenter

>
> +       rport->port_id = USB2PHY_PORT_HOST;
>
>> Or from what I've seen, handling it as similar to the host-port should
>> work
>> initially as well most likely, supplying the additional otg-parts later
>> on.
>
>
> @Guenter, just as Heiko said, the otg-parts is not ready now, it will be
> supplied later.
>
>
> BR.
> Frank
>
Frank Wang June 16, 2016, 1:47 a.m. UTC | #2
Hi Guenter & Heiko,

On 2016/6/15 23:47, Guenter Roeck wrote:
> On Tue, Jun 14, 2016 at 6:14 PM, Frank Wang <frank.wang@rock-chips.com> wrote:
>> Hi Heiko & Guenter,
>>
>>
>> On 2016/6/14 22:00, Heiko Stübner wrote:
>>> Am Dienstag, 14. Juni 2016, 06:50:31 schrieb Guenter Roeck:
>>>> On Tue, Jun 14, 2016 at 6:27 AM, Heiko Stübner <heiko@sntech.de> wrote:
>>>>> Am Montag, 13. Juni 2016, 10:10:10 schrieb Frank Wang:
>>>>>> The newer SoCs (rk3366, rk3399) take a different usb-phy IP block
>>>>>> than rk3288 and before, and most of phy-related registers are also
>>>>>> different from the past, so a new phy driver is required necessarily.
>>>>>>
>>>>>> Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
>>>>>> ---
>>> [...]
>>>
>>>>>> +static int rockchip_usb2phy_init(struct phy *phy)
>>>>>> +{
>>>>>> +     struct rockchip_usb2phy_port *rport = phy_get_drvdata(phy);
>>>>>> +     struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent);
>>>>>> +     int ret;
>>>>>> +
>>>>>>
>>>>>           if (!rport->port_cfg)
>>>>>                            return 0;
>>>>>
>>>>> Otherwise the currently empty otg-port will cause null-pointer
>>>>> dereferences
>>>>> when it gets assigned in the devicetree already.
>>>> Not really, at least not here - that port should not have port_id set
>>>> to USB2PHY_PORT_HOST.
>>>>
>>>> Does it even make sense to instantiate the otg port ? Is it going to
>>>> do anything without port configuration ?
>>> Ok, that would be the other option - not creating the phy in the driver.
>>
>> Well, I will put this conditional inside *_host_port_init(), if it is an
>> empty, the phy-device should not be created.
>> Something like the following:
>>
>> --- a/drivers/phy/phy-rockchip-inno-usb2.c
>> +++ b/drivers/phy/phy-rockchip-inno-usb2.c
>> @@ -483,9 +483,13 @@ static int rockchip_usb2phy_host_port_init(struct
>> rockchip_usb2phy *rphy,
>>   {
>>          int ret;
>>
>> -       rport->port_id = USB2PHY_PORT_HOST;
>>          rport->port_cfg = &rphy->phy_cfg->port_cfgs[USB2PHY_PORT_HOST];
>> +       if (!rport->port_cfg) {
>> +               dev_err(rphy->dev, "no host port-config provided.\n");
>> +               return -EINVAL;
>> +       }
> This would never be NULL. At issue is that you don't assign port_cfg
> if the port is _not_ a host port.

Sorry, I made a mistake. How about something like the following:

@@ -574,6 +579,15 @@ static int rockchip_usb2phy_probe(struct 
platform_device *pdev)
                 struct rockchip_usb2phy_port *rport = &rphy->ports[index];
                 struct phy *phy;

+               /*
+                * This driver aim to support both otg-port and host-port,
+                * but unfortunately, the otg part is not ready in current,
+                * so this comments and below codes are interim, which 
should
+                * be removed after otg-port is supplied soon.
+                */
+               if (of_node_cmp(child_np->name, "host-port"))
+                       goto next_child;
+
                 phy = devm_phy_create(dev, child_np, 
&rockchip_usb2phy_ops);
                 if (IS_ERR(phy)) {
                         dev_err(dev, "failed to create phy\n");
@@ -582,17 +596,13 @@ static int rockchip_usb2phy_probe(struct 
platform_device *pdev)
                 }

                 rport->phy = phy;
-
-               /* initialize otg/host port separately */
-               if (!of_node_cmp(child_np->name, "host-port")) {
-                       ret = rockchip_usb2phy_host_port_init(rphy, rport,
- child_np);
-                       if (ret)
-                               goto put_child;
-               }
-
                 phy_set_drvdata(rport->phy, rport);

+               ret = rockchip_usb2phy_host_port_init(rphy, rport, 
child_np);
+               if (ret)
+                       goto put_child;
+
+next_child:
                 /* to prevent out of boundary */
                 if (++index >= rphy->phy_cfg->num_ports)
                         break;


BR.
Frank
Guenter Roeck June 16, 2016, 1:12 p.m. UTC | #3
On 06/15/2016 06:47 PM, Frank Wang wrote:
> Hi Guenter & Heiko,
>
> On 2016/6/15 23:47, Guenter Roeck wrote:
>> On Tue, Jun 14, 2016 at 6:14 PM, Frank Wang <frank.wang@rock-chips.com> wrote:
>>> Hi Heiko & Guenter,
>>>
>>>
>>> On 2016/6/14 22:00, Heiko Stübner wrote:
>>>> Am Dienstag, 14. Juni 2016, 06:50:31 schrieb Guenter Roeck:
>>>>> On Tue, Jun 14, 2016 at 6:27 AM, Heiko Stübner <heiko@sntech.de> wrote:
>>>>>> Am Montag, 13. Juni 2016, 10:10:10 schrieb Frank Wang:
>>>>>>> The newer SoCs (rk3366, rk3399) take a different usb-phy IP block
>>>>>>> than rk3288 and before, and most of phy-related registers are also
>>>>>>> different from the past, so a new phy driver is required necessarily.
>>>>>>>
>>>>>>> Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
>>>>>>> ---
>>>> [...]
>>>>
>>>>>>> +static int rockchip_usb2phy_init(struct phy *phy)
>>>>>>> +{
>>>>>>> +     struct rockchip_usb2phy_port *rport = phy_get_drvdata(phy);
>>>>>>> +     struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent);
>>>>>>> +     int ret;
>>>>>>> +
>>>>>>>
>>>>>>           if (!rport->port_cfg)
>>>>>>                            return 0;
>>>>>>
>>>>>> Otherwise the currently empty otg-port will cause null-pointer
>>>>>> dereferences
>>>>>> when it gets assigned in the devicetree already.
>>>>> Not really, at least not here - that port should not have port_id set
>>>>> to USB2PHY_PORT_HOST.
>>>>>
>>>>> Does it even make sense to instantiate the otg port ? Is it going to
>>>>> do anything without port configuration ?
>>>> Ok, that would be the other option - not creating the phy in the driver.
>>>
>>> Well, I will put this conditional inside *_host_port_init(), if it is an
>>> empty, the phy-device should not be created.
>>> Something like the following:
>>>
>>> --- a/drivers/phy/phy-rockchip-inno-usb2.c
>>> +++ b/drivers/phy/phy-rockchip-inno-usb2.c
>>> @@ -483,9 +483,13 @@ static int rockchip_usb2phy_host_port_init(struct
>>> rockchip_usb2phy *rphy,
>>>   {
>>>          int ret;
>>>
>>> -       rport->port_id = USB2PHY_PORT_HOST;
>>>          rport->port_cfg = &rphy->phy_cfg->port_cfgs[USB2PHY_PORT_HOST];
>>> +       if (!rport->port_cfg) {
>>> +               dev_err(rphy->dev, "no host port-config provided.\n");
>>> +               return -EINVAL;
>>> +       }
>> This would never be NULL. At issue is that you don't assign port_cfg
>> if the port is _not_ a host port.
>
> Sorry, I made a mistake. How about something like the following:
>
Yes, that should work. Just keep in mind that there could always be
a port named "something-port", so you'll always need some kind of check
(and possibly return an error if a port with a wrong name is provided).

Thanks,
Guenter

> @@ -574,6 +579,15 @@ static int rockchip_usb2phy_probe(struct platform_device *pdev)
>                  struct rockchip_usb2phy_port *rport = &rphy->ports[index];
>                  struct phy *phy;
>
> +               /*
> +                * This driver aim to support both otg-port and host-port,
> +                * but unfortunately, the otg part is not ready in current,
> +                * so this comments and below codes are interim, which should
> +                * be removed after otg-port is supplied soon.
> +                */
> +               if (of_node_cmp(child_np->name, "host-port"))
> +                       goto next_child;
> +
>                  phy = devm_phy_create(dev, child_np, &rockchip_usb2phy_ops);
>                  if (IS_ERR(phy)) {
>                          dev_err(dev, "failed to create phy\n");
> @@ -582,17 +596,13 @@ static int rockchip_usb2phy_probe(struct platform_device *pdev)
>                  }
>
>                  rport->phy = phy;
> -
> -               /* initialize otg/host port separately */
> -               if (!of_node_cmp(child_np->name, "host-port")) {
> -                       ret = rockchip_usb2phy_host_port_init(rphy, rport,
> - child_np);
> -                       if (ret)
> -                               goto put_child;
> -               }
> -
>                  phy_set_drvdata(rport->phy, rport);
>
> +               ret = rockchip_usb2phy_host_port_init(rphy, rport, child_np);
> +               if (ret)
> +                       goto put_child;
> +
> +next_child:
>                  /* to prevent out of boundary */
>                  if (++index >= rphy->phy_cfg->num_ports)
>                          break;
>
>
> BR.
> Frank
>
>
Frank Wang June 17, 2016, 12:57 a.m. UTC | #4
Hi Guenter,

On 2016/6/16 21:12, Guenter Roeck wrote:
> On 06/15/2016 06:47 PM, Frank Wang wrote:
>> Hi Guenter & Heiko,
>>
>> On 2016/6/15 23:47, Guenter Roeck wrote:
>>> On Tue, Jun 14, 2016 at 6:14 PM, Frank Wang 
>>> <frank.wang@rock-chips.com> wrote:
>>>> Hi Heiko & Guenter,
>>>>
>>>>
>>>> On 2016/6/14 22:00, Heiko Stübner wrote:
>>>>> Am Dienstag, 14. Juni 2016, 06:50:31 schrieb Guenter Roeck:
>>>>>> On Tue, Jun 14, 2016 at 6:27 AM, Heiko Stübner <heiko@sntech.de> 
>>>>>> wrote:
>>>>>>> Am Montag, 13. Juni 2016, 10:10:10 schrieb Frank Wang:
>>>>>>>> The newer SoCs (rk3366, rk3399) take a different usb-phy IP block
>>>>>>>> than rk3288 and before, and most of phy-related registers are also
>>>>>>>> different from the past, so a new phy driver is required 
>>>>>>>> necessarily.
>>>>>>>>
>>>>>>>> Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
>>>>>>>> ---
>>>>> [...]
>>>>>
>>>>>>>> +static int rockchip_usb2phy_init(struct phy *phy)
>>>>>>>> +{
>>>>>>>> +     struct rockchip_usb2phy_port *rport = phy_get_drvdata(phy);
>>>>>>>> +     struct rockchip_usb2phy *rphy = 
>>>>>>>> dev_get_drvdata(phy->dev.parent);
>>>>>>>> +     int ret;
>>>>>>>> +
>>>>>>>>
>>>>>>>           if (!rport->port_cfg)
>>>>>>>                            return 0;
>>>>>>>
>>>>>>> Otherwise the currently empty otg-port will cause null-pointer
>>>>>>> dereferences
>>>>>>> when it gets assigned in the devicetree already.
>>>>>> Not really, at least not here - that port should not have port_id 
>>>>>> set
>>>>>> to USB2PHY_PORT_HOST.
>>>>>>
>>>>>> Does it even make sense to instantiate the otg port ? Is it going to
>>>>>> do anything without port configuration ?
>>>>> Ok, that would be the other option - not creating the phy in the 
>>>>> driver.
>>>>
>>>> Well, I will put this conditional inside *_host_port_init(), if it 
>>>> is an
>>>> empty, the phy-device should not be created.
>>>> Something like the following:
>>>>
>>>> --- a/drivers/phy/phy-rockchip-inno-usb2.c
>>>> +++ b/drivers/phy/phy-rockchip-inno-usb2.c
>>>> @@ -483,9 +483,13 @@ static int rockchip_usb2phy_host_port_init(struct
>>>> rockchip_usb2phy *rphy,
>>>>   {
>>>>          int ret;
>>>>
>>>> -       rport->port_id = USB2PHY_PORT_HOST;
>>>>          rport->port_cfg = 
>>>> &rphy->phy_cfg->port_cfgs[USB2PHY_PORT_HOST];
>>>> +       if (!rport->port_cfg) {
>>>> +               dev_err(rphy->dev, "no host port-config provided.\n");
>>>> +               return -EINVAL;
>>>> +       }
>>> This would never be NULL. At issue is that you don't assign port_cfg
>>> if the port is _not_ a host port.
>>
>> Sorry, I made a mistake. How about something like the following:
>>
> Yes, that should work. Just keep in mind that there could always be
> a port named "something-port", so you'll always need some kind of check
> (and possibly return an error if a port with a wrong name is provided).
>
>

OK, thanks for your reminding, I am going to send out it with a new 
version later.

BR.
Frank

>
>> @@ -574,6 +579,15 @@ static int rockchip_usb2phy_probe(struct 
>> platform_device *pdev)
>>                  struct rockchip_usb2phy_port *rport = 
>> &rphy->ports[index];
>>                  struct phy *phy;
>>
>> +               /*
>> +                * This driver aim to support both otg-port and 
>> host-port,
>> +                * but unfortunately, the otg part is not ready in 
>> current,
>> +                * so this comments and below codes are interim, 
>> which should
>> +                * be removed after otg-port is supplied soon.
>> +                */
>> +               if (of_node_cmp(child_np->name, "host-port"))
>> +                       goto next_child;
>> +
>>                  phy = devm_phy_create(dev, child_np, 
>> &rockchip_usb2phy_ops);
>>                  if (IS_ERR(phy)) {
>>                          dev_err(dev, "failed to create phy\n");
>> @@ -582,17 +596,13 @@ static int rockchip_usb2phy_probe(struct 
>> platform_device *pdev)
>>                  }
>>
>>                  rport->phy = phy;
>> -
>> -               /* initialize otg/host port separately */
>> -               if (!of_node_cmp(child_np->name, "host-port")) {
>> -                       ret = rockchip_usb2phy_host_port_init(rphy, 
>> rport,
>> - child_np);
>> -                       if (ret)
>> -                               goto put_child;
>> -               }
>> -
>>                  phy_set_drvdata(rport->phy, rport);
>>
>> +               ret = rockchip_usb2phy_host_port_init(rphy, rport, 
>> child_np);
>> +               if (ret)
>> +                       goto put_child;
>> +
>> +next_child:
>>                  /* to prevent out of boundary */
>>                  if (++index >= rphy->phy_cfg->num_ports)
>>                          break;
>>
>>
>>
>
diff mbox

Patch

--- a/drivers/phy/phy-rockchip-inno-usb2.c
+++ b/drivers/phy/phy-rockchip-inno-usb2.c
@@ -483,9 +483,13 @@  static int rockchip_usb2phy_host_port_init(struct 
rockchip_usb2phy *rphy,
  {
         int ret;

-       rport->port_id = USB2PHY_PORT_HOST;
         rport->port_cfg = &rphy->phy_cfg->port_cfgs[USB2PHY_PORT_HOST];
+       if (!rport->port_cfg) {
+               dev_err(rphy->dev, "no host port-config provided.\n");
+               return -EINVAL;
+       }

+       rport->port_id = USB2PHY_PORT_HOST;

> Or from what I've seen, handling it as similar to the host-port should work