Re: [PATCH v4] usb: of: add an api to get dr_mode by the phy node

2015-10-06 Thread Heikki Krogerus
Hi,

> How about add a new function as follows to convert dr_mode from string to
> enum, then both Keikki's and my function will be shorter by calling it?
> 
> static enum usb_dr_mode of_usb_get_dr_mode_from_string(char *string)
> {
>  for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++)
>  if (!strcmp(string, usb_dr_modes[i]))
>  return i;
>  return USB_DR_MODE_UNKNOWN;
> }

I was thinking the same. Why not imlement the patch like so:

diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
index 673d530..cd9f6e9 100644
--- a/drivers/usb/common/common.c
+++ b/drivers/usb/common/common.c
@@ -106,25 +106,67 @@ static const char *const usb_dr_modes[] = {
[USB_DR_MODE_OTG]   = "otg",
 };
 
+static enum usb_dr_mode find_dr_mode(const char *name)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++)
+   if (!strcmp(name, usb_dr_modes[i]))
+   return i;
+   return USB_DR_MODE_UNKNOWN;
+}
+
 enum usb_dr_mode usb_get_dr_mode(struct device *dev)
 {
const char *dr_mode;
-   int err, i;
+   int err;
 
err = device_property_read_string(dev, "dr_mode", _mode);
if (err < 0)
return USB_DR_MODE_UNKNOWN;
-
-   for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++)
-   if (!strcmp(dr_mode, usb_dr_modes[i]))
-   return i;
-
-   return USB_DR_MODE_UNKNOWN;
+   return find_dr_mode(dr_mode);
 }
 EXPORT_SYMBOL_GPL(usb_get_dr_mode);
 
 #ifdef CONFIG_OF
 /**
+ * of_usb_get_dr_mode_by_phy - Get dual role mode for the controller device
+ * which is associated with the given phy device_node
+ * @np:Pointer to the given phy device_node
+ *
+ * In dts a usb controller associates with phy devices.  The function gets
+ * the string from property 'dr_mode' of the controller associated with the
+ * given phy device node, and returns the correspondig enum usb_dr_mode.
+ */
+enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *phy_np)
+{
+   struct device_node *controller = NULL;
+   struct device_node *phy;
+   const char *dr_mode;
+   int index;
+   int err;
+
+   do {
+   controller = of_find_node_with_property(controller, "phys");
+   index = 0;
+   do {
+   phy = of_parse_phandle(controller, "phys", index);
+   of_node_put(phy);
+   if (phy == phy_np)
+   goto finish;
+   index++;
+   } while (phy);
+   } while (controller);
+
+finish:
+   err = of_property_read_string(controller, "dr_mode", _mode);
+   if (err < 0)
+   return USB_DR_MODE_UNKNOWN;
+   return find_dr_mode(dr_mode);
+}
+EXPORT_SYMBOL_GPL(of_usb_get_dr_mode_by_phy);
+
+/**
  * of_usb_host_tpl_support - to get if Targeted Peripheral List is supported
  * for given targeted hosts (non-PC hosts)
  * @np: Pointer to the given device_node


Cheers,

-- 
heikki
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4] usb: of: add an api to get dr_mode by the phy node

2015-10-05 Thread Felipe Balbi
Bin Liu  writes:

> Hi Felipe,
>
> On 09/24/2015 03:37 AM, Hans de Goede wrote:
>> Hi,
>>
>> On 23-09-15 22:59, Bin Liu wrote:
>>> Hi,
>>>
>>> On 09/23/2015 02:53 PM, Hans de Goede wrote:
 Hi,

 On 23-09-15 19:10, Bin Liu wrote:
> Hi,
>
> On 09/22/2015 04:18 PM, Felipe Balbi wrote:
>> On Tue, Sep 22, 2015 at 02:31:18PM -0500, Bin Liu wrote:
>>> Hi,
>>>
>>> On 09/22/2015 09:40 AM, Felipe Balbi wrote:
 On Mon, Sep 21, 2015 at 10:50:56AM -0500, Bin Liu wrote:
> Some USB phy drivers have different handling for the controller in
> each
> dr_mode. But the phy driver does not have visibility to the
> dr_mode of
> the controller.
>
> This adds an api to return the dr_mode of the controller which
> associates the given phy node.
>
> Signed-off-by: Bin Liu 


 doesn't apply anymore. Probably because of Heikki's series which I
 just
 added to testing/next.

 Please rebase there.

>>> I have to rewrite my patch. Before Heikki's patch
>>> of_usb_get_dr_mode() takes
>>> parameter 'struct *device_node', but now usb_get_dr_mode() takes
>>> parameter
>>> 'struct *device'. The logic in my patch iterates over of nodes, I am
>>> not
>>> sure how to get the 'struct *device' from a of node yet...
>>
>> okay.
>>
> There is no way to get the 'struct *device' to the controller in the
> phy driver, because the controller device might not be registered yet
> by the time the phy probe is called.
>
> So I have to put back the implementation of the removed
> of_usb_get_dr_mode() into this new of_usb_get_dr_mode_by_phy()
> function. Please let me know if this is acceptable then I will send
> the v5.

 Sounds to me like it is better to revert the API change / removal of
 of_usb_get_dr_mode()
 as a separate patch and then stick with your v4 patch.
>>>
>>> +1
>>
>> If you agree, then the best way to do this is probably to send a patch
>> series with the actual revert + your v4 patch. Probably best to call
>> that series v5.
>
> Since Heikki's patch is only in your testing/next branch, do you want to 
> just drop that patch and take my v4 patch, or you want me to send the 
> revert patch?

I'm not sure that's the way we want to go. Heikki's patch is doing a
cleanup which is necessary for the USB layer to be able to use device
properties instead of relying exclusively on DT or PCI. Device
properties is the unification of the two.

Heikki, any comments

-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH v4] usb: of: add an api to get dr_mode by the phy node

2015-10-05 Thread Bin Liu

Hi,

On 10/05/2015 02:54 PM, Felipe Balbi wrote:

Bin Liu  writes:


Hi Felipe,

On 09/24/2015 03:37 AM, Hans de Goede wrote:

Hi,

On 23-09-15 22:59, Bin Liu wrote:

Hi,

On 09/23/2015 02:53 PM, Hans de Goede wrote:

Hi,

On 23-09-15 19:10, Bin Liu wrote:

Hi,

On 09/22/2015 04:18 PM, Felipe Balbi wrote:

On Tue, Sep 22, 2015 at 02:31:18PM -0500, Bin Liu wrote:

Hi,

On 09/22/2015 09:40 AM, Felipe Balbi wrote:

On Mon, Sep 21, 2015 at 10:50:56AM -0500, Bin Liu wrote:

Some USB phy drivers have different handling for the controller in
each
dr_mode. But the phy driver does not have visibility to the
dr_mode of
the controller.

This adds an api to return the dr_mode of the controller which
associates the given phy node.

Signed-off-by: Bin Liu 



doesn't apply anymore. Probably because of Heikki's series which I
just
added to testing/next.

Please rebase there.


I have to rewrite my patch. Before Heikki's patch
of_usb_get_dr_mode() takes
parameter 'struct *device_node', but now usb_get_dr_mode() takes
parameter
'struct *device'. The logic in my patch iterates over of nodes, I am
not
sure how to get the 'struct *device' from a of node yet...


okay.


There is no way to get the 'struct *device' to the controller in the
phy driver, because the controller device might not be registered yet
by the time the phy probe is called.

So I have to put back the implementation of the removed
of_usb_get_dr_mode() into this new of_usb_get_dr_mode_by_phy()
function. Please let me know if this is acceptable then I will send
the v5.


Sounds to me like it is better to revert the API change / removal of
of_usb_get_dr_mode()
as a separate patch and then stick with your v4 patch.


+1


If you agree, then the best way to do this is probably to send a patch
series with the actual revert + your v4 patch. Probably best to call
that series v5.


Since Heikki's patch is only in your testing/next branch, do you want to
just drop that patch and take my v4 patch, or you want me to send the
revert patch?


I'm not sure that's the way we want to go. Heikki's patch is doing a
cleanup which is necessary for the USB layer to be able to use device
properties instead of relying exclusively on DT or PCI. Device
properties is the unification of the two.


How about add a new function as follows to convert dr_mode from string 
to enum, then both Keikki's and my function will be shorter by calling it?


static enum usb_dr_mode of_usb_get_dr_mode_from_string(char *string)
{
 for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++)
 if (!strcmp(string, usb_dr_modes[i]))
 return i;
 return USB_DR_MODE_UNKNOWN;
}

Thanks,
-Bin.



Heikki, any comments


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4] usb: of: add an api to get dr_mode by the phy node

2015-09-24 Thread Hans de Goede

Hi,

On 23-09-15 22:59, Bin Liu wrote:

Hi,

On 09/23/2015 02:53 PM, Hans de Goede wrote:

Hi,

On 23-09-15 19:10, Bin Liu wrote:

Hi,

On 09/22/2015 04:18 PM, Felipe Balbi wrote:

On Tue, Sep 22, 2015 at 02:31:18PM -0500, Bin Liu wrote:

Hi,

On 09/22/2015 09:40 AM, Felipe Balbi wrote:

On Mon, Sep 21, 2015 at 10:50:56AM -0500, Bin Liu wrote:

Some USB phy drivers have different handling for the controller in
each
dr_mode. But the phy driver does not have visibility to the
dr_mode of
the controller.

This adds an api to return the dr_mode of the controller which
associates the given phy node.

Signed-off-by: Bin Liu 



doesn't apply anymore. Probably because of Heikki's series which I
just
added to testing/next.

Please rebase there.


I have to rewrite my patch. Before Heikki's patch
of_usb_get_dr_mode() takes
parameter 'struct *device_node', but now usb_get_dr_mode() takes
parameter
'struct *device'. The logic in my patch iterates over of nodes, I am
not
sure how to get the 'struct *device' from a of node yet...


okay.


There is no way to get the 'struct *device' to the controller in the
phy driver, because the controller device might not be registered yet
by the time the phy probe is called.

So I have to put back the implementation of the removed
of_usb_get_dr_mode() into this new of_usb_get_dr_mode_by_phy()
function. Please let me know if this is acceptable then I will send
the v5.


Sounds to me like it is better to revert the API change / removal of
of_usb_get_dr_mode()
as a separate patch and then stick with your v4 patch.


+1


If you agree, then the best way to do this is probably to send a patch
series with the actual revert + your v4 patch. Probably best to call
that series v5.

Regards,

Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4] usb: of: add an api to get dr_mode by the phy node

2015-09-24 Thread Bin Liu

Hi Felipe,

On 09/24/2015 03:37 AM, Hans de Goede wrote:

Hi,

On 23-09-15 22:59, Bin Liu wrote:

Hi,

On 09/23/2015 02:53 PM, Hans de Goede wrote:

Hi,

On 23-09-15 19:10, Bin Liu wrote:

Hi,

On 09/22/2015 04:18 PM, Felipe Balbi wrote:

On Tue, Sep 22, 2015 at 02:31:18PM -0500, Bin Liu wrote:

Hi,

On 09/22/2015 09:40 AM, Felipe Balbi wrote:

On Mon, Sep 21, 2015 at 10:50:56AM -0500, Bin Liu wrote:

Some USB phy drivers have different handling for the controller in
each
dr_mode. But the phy driver does not have visibility to the
dr_mode of
the controller.

This adds an api to return the dr_mode of the controller which
associates the given phy node.

Signed-off-by: Bin Liu 



doesn't apply anymore. Probably because of Heikki's series which I
just
added to testing/next.

Please rebase there.


I have to rewrite my patch. Before Heikki's patch
of_usb_get_dr_mode() takes
parameter 'struct *device_node', but now usb_get_dr_mode() takes
parameter
'struct *device'. The logic in my patch iterates over of nodes, I am
not
sure how to get the 'struct *device' from a of node yet...


okay.


There is no way to get the 'struct *device' to the controller in the
phy driver, because the controller device might not be registered yet
by the time the phy probe is called.

So I have to put back the implementation of the removed
of_usb_get_dr_mode() into this new of_usb_get_dr_mode_by_phy()
function. Please let me know if this is acceptable then I will send
the v5.


Sounds to me like it is better to revert the API change / removal of
of_usb_get_dr_mode()
as a separate patch and then stick with your v4 patch.


+1


If you agree, then the best way to do this is probably to send a patch
series with the actual revert + your v4 patch. Probably best to call
that series v5.


Since Heikki's patch is only in your testing/next branch, do you want to 
just drop that patch and take my v4 patch, or you want me to send the 
revert patch?


Thanks,
-Bin.



Regards,

Hans

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4] usb: of: add an api to get dr_mode by the phy node

2015-09-23 Thread Bin Liu

Hi,

On 09/22/2015 04:18 PM, Felipe Balbi wrote:

On Tue, Sep 22, 2015 at 02:31:18PM -0500, Bin Liu wrote:

Hi,

On 09/22/2015 09:40 AM, Felipe Balbi wrote:

On Mon, Sep 21, 2015 at 10:50:56AM -0500, Bin Liu wrote:

Some USB phy drivers have different handling for the controller in each
dr_mode. But the phy driver does not have visibility to the dr_mode of
the controller.

This adds an api to return the dr_mode of the controller which
associates the given phy node.

Signed-off-by: Bin Liu 



doesn't apply anymore. Probably because of Heikki's series which I just
added to testing/next.

Please rebase there.


I have to rewrite my patch. Before Heikki's patch of_usb_get_dr_mode() takes
parameter 'struct *device_node', but now usb_get_dr_mode() takes parameter
'struct *device'. The logic in my patch iterates over of nodes, I am not
sure how to get the 'struct *device' from a of node yet...


okay.

There is no way to get the 'struct *device' to the controller in the phy 
driver, because the controller device might not be registered yet by the 
time the phy probe is called.


So I have to put back the implementation of the removed 
of_usb_get_dr_mode() into this new of_usb_get_dr_mode_by_phy() function. 
Please let me know if this is acceptable then I will send the v5.


Thanks,
-Bin.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4] usb: of: add an api to get dr_mode by the phy node

2015-09-23 Thread Bin Liu

Hi,

On 09/23/2015 02:53 PM, Hans de Goede wrote:

Hi,

On 23-09-15 19:10, Bin Liu wrote:

Hi,

On 09/22/2015 04:18 PM, Felipe Balbi wrote:

On Tue, Sep 22, 2015 at 02:31:18PM -0500, Bin Liu wrote:

Hi,

On 09/22/2015 09:40 AM, Felipe Balbi wrote:

On Mon, Sep 21, 2015 at 10:50:56AM -0500, Bin Liu wrote:

Some USB phy drivers have different handling for the controller in
each
dr_mode. But the phy driver does not have visibility to the
dr_mode of
the controller.

This adds an api to return the dr_mode of the controller which
associates the given phy node.

Signed-off-by: Bin Liu 



doesn't apply anymore. Probably because of Heikki's series which I
just
added to testing/next.

Please rebase there.


I have to rewrite my patch. Before Heikki's patch
of_usb_get_dr_mode() takes
parameter 'struct *device_node', but now usb_get_dr_mode() takes
parameter
'struct *device'. The logic in my patch iterates over of nodes, I am
not
sure how to get the 'struct *device' from a of node yet...


okay.


There is no way to get the 'struct *device' to the controller in the
phy driver, because the controller device might not be registered yet
by the time the phy probe is called.

So I have to put back the implementation of the removed
of_usb_get_dr_mode() into this new of_usb_get_dr_mode_by_phy()
function. Please let me know if this is acceptable then I will send
the v5.


Sounds to me like it is better to revert the API change / removal of
of_usb_get_dr_mode()
as a separate patch and then stick with your v4 patch.


+1

Regards,
-Bin.



Regards,

Hans

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4] usb: of: add an api to get dr_mode by the phy node

2015-09-23 Thread Hans de Goede

Hi,

On 23-09-15 19:10, Bin Liu wrote:

Hi,

On 09/22/2015 04:18 PM, Felipe Balbi wrote:

On Tue, Sep 22, 2015 at 02:31:18PM -0500, Bin Liu wrote:

Hi,

On 09/22/2015 09:40 AM, Felipe Balbi wrote:

On Mon, Sep 21, 2015 at 10:50:56AM -0500, Bin Liu wrote:

Some USB phy drivers have different handling for the controller in each
dr_mode. But the phy driver does not have visibility to the dr_mode of
the controller.

This adds an api to return the dr_mode of the controller which
associates the given phy node.

Signed-off-by: Bin Liu 



doesn't apply anymore. Probably because of Heikki's series which I just
added to testing/next.

Please rebase there.


I have to rewrite my patch. Before Heikki's patch of_usb_get_dr_mode() takes
parameter 'struct *device_node', but now usb_get_dr_mode() takes parameter
'struct *device'. The logic in my patch iterates over of nodes, I am not
sure how to get the 'struct *device' from a of node yet...


okay.


There is no way to get the 'struct *device' to the controller in the phy 
driver, because the controller device might not be registered yet by the time 
the phy probe is called.

So I have to put back the implementation of the removed of_usb_get_dr_mode() 
into this new of_usb_get_dr_mode_by_phy() function. Please let me know if this 
is acceptable then I will send the v5.


Sounds to me like it is better to revert the API change / removal of 
of_usb_get_dr_mode()
as a separate patch and then stick with your v4 patch.

Regards,

Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4] usb: of: add an api to get dr_mode by the phy node

2015-09-22 Thread Bin Liu

Hi,

On 09/22/2015 09:40 AM, Felipe Balbi wrote:

On Mon, Sep 21, 2015 at 10:50:56AM -0500, Bin Liu wrote:

Some USB phy drivers have different handling for the controller in each
dr_mode. But the phy driver does not have visibility to the dr_mode of
the controller.

This adds an api to return the dr_mode of the controller which
associates the given phy node.

Signed-off-by: Bin Liu 



doesn't apply anymore. Probably because of Heikki's series which I just
added to testing/next.

Please rebase there.

I have to rewrite my patch. Before Heikki's patch of_usb_get_dr_mode() 
takes parameter 'struct *device_node', but now usb_get_dr_mode() takes 
parameter 'struct *device'. The logic in my patch iterates over of 
nodes, I am not sure how to get the 'struct *device' from a of node yet...


Regards,
-Bin.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4] usb: of: add an api to get dr_mode by the phy node

2015-09-22 Thread Felipe Balbi
On Mon, Sep 21, 2015 at 10:50:56AM -0500, Bin Liu wrote:
> Some USB phy drivers have different handling for the controller in each
> dr_mode. But the phy driver does not have visibility to the dr_mode of
> the controller.
> 
> This adds an api to return the dr_mode of the controller which
> associates the given phy node.
> 
> Signed-off-by: Bin Liu 


doesn't apply anymore. Probably because of Heikki's series which I just
added to testing/next.

Please rebase there.

-- 
balbi


signature.asc
Description: PGP signature


[PATCH v4] usb: of: add an api to get dr_mode by the phy node

2015-09-21 Thread Bin Liu
Some USB phy drivers have different handling for the controller in each
dr_mode. But the phy driver does not have visibility to the dr_mode of
the controller.

This adds an api to return the dr_mode of the controller which
associates the given phy node.

Signed-off-by: Bin Liu 
---
v4: - iterating all phy nodes in the associated controller
- add of_node_put() to decrement refcount

v3: search controller node from dt root, as the phy and controller nodes
might not have the same parent.

v2: move drivers/usb/phy/phy-am335x.c changes into patch 3/3.

 drivers/usb/common/common.c | 36 
 include/linux/usb/of.h  |  6 ++
 2 files changed, 42 insertions(+)

diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
index b530fd4..e3da800 100644
--- a/drivers/usb/common/common.c
+++ b/drivers/usb/common/common.c
@@ -114,6 +114,42 @@ enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np)
 EXPORT_SYMBOL_GPL(of_usb_get_dr_mode);
 
 /**
+ * of_usb_get_dr_mode_by_phy - Get dual role mode for the controller device
+ * which is associated with the given phy device_node
+ * @np:Pointer to the given phy device_node
+ *
+ * In dts a usb controller associates with phy devices.  The function gets
+ * the string from property 'dr_mode' of the controller associated with the
+ * given phy device node, and returns the correspondig enum usb_dr_mode.
+ */
+enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *phy_np)
+{
+   struct device_node *controller = NULL;
+   struct device_node *phy;
+   enum usb_dr_mode dr_mode;
+   int index;
+
+   do {
+   controller = of_find_node_with_property(controller, "phys");
+   index = 0;
+   do {
+   phy = of_parse_phandle(controller, "phys", index);
+   of_node_put(phy);
+   if (phy == phy_np)
+   goto finish;
+   index++;
+   } while (phy);
+   } while (controller);
+
+finish:
+   dr_mode = of_usb_get_dr_mode(controller);
+   of_node_put(controller);
+
+   return dr_mode;
+}
+EXPORT_SYMBOL_GPL(of_usb_get_dr_mode_by_phy);
+
+/**
  * of_usb_get_maximum_speed - Get maximum requested speed for a given USB
  * controller.
  * @np: Pointer to the given device_node
diff --git a/include/linux/usb/of.h b/include/linux/usb/of.h
index cfe0528..14ebd5a 100644
--- a/include/linux/usb/of.h
+++ b/include/linux/usb/of.h
@@ -13,6 +13,7 @@
 
 #if IS_ENABLED(CONFIG_OF)
 enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np);
+enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *phy_np);
 enum usb_device_speed of_usb_get_maximum_speed(struct device_node *np);
 bool of_usb_host_tpl_support(struct device_node *np);
 #else
@@ -21,6 +22,11 @@ static inline enum usb_dr_mode of_usb_get_dr_mode(struct 
device_node *np)
return USB_DR_MODE_UNKNOWN;
 }
 
+enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *phy_np)
+{
+   return USB_DR_MODE_UNKNOWN;
+}
+
 static inline enum usb_device_speed
 of_usb_get_maximum_speed(struct device_node *np)
 {
-- 
1.8.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html