Re: query on [PATCH 2/3] usb: otg: add device tree support to otg library

2012-09-25 Thread Marc Kleine-Budde
Hi Afzal,

On 09/25/2012 10:47 AM, Mohammed, Afzal wrote:
 This is a query regarding patch,
 usb: otg: add device tree support to otg library [1]
 
 It seems there is so far no consensus on this change.

After I have posted this patch, Kishon had posted a better solution [2].
We discussed the patch, but he has not posted any updates since then.

 Do you have ideas to proceed on this ? is there something
 that I can help you to proceed on this ?

I'm interested in to get these patches into the kernel soon. Kishon any
news on this patch?

 Something like this would be required for USB support
 on beagle bone (AM335X), which has 2 phy's of same type.
 
 Or is the plan to use generic phy framework instead ?

Yes, Kishon's patches look more generic than mine.

Marc

[2] https://patchwork.kernel.org/patch/1457801/
-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: query on [PATCH 2/3] usb: otg: add device tree support to otg library

2012-09-25 Thread ABRAHAM, KISHON VIJAY
Hi,

On Tue, Sep 25, 2012 at 2:24 PM, Marc Kleine-Budde m...@pengutronix.de wrote:
 Hi Afzal,

 On 09/25/2012 10:47 AM, Mohammed, Afzal wrote:
 This is a query regarding patch,
 usb: otg: add device tree support to otg library [1]

 It seems there is so far no consensus on this change.

 After I have posted this patch, Kishon had posted a better solution [2].
 We discussed the patch, but he has not posted any updates since then.

 Do you have ideas to proceed on this ? is there something
 that I can help you to proceed on this ?

 I'm interested in to get these patches into the kernel soon. Kishon any
 news on this patch?

 Something like this would be required for USB support
 on beagle bone (AM335X), which has 2 phy's of same type.

 Or is the plan to use generic phy framework instead ?

 Yes, Kishon's patches look more generic than mine.
Will post the next version by this week.

Thanks
Kishon
--
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: query on [PATCH 2/3] usb: otg: add device tree support to otg library

2012-09-25 Thread Mohammed, Afzal
On Tue, Sep 25, 2012 at 16:21:39, ABRAHAM, KISHON VIJAY wrote:
 On Tue, Sep 25, 2012 at 2:24 PM, Marc Kleine-Budde m...@pengutronix.de 
 wrote:

  I'm interested in to get these patches into the kernel soon. Kishon any
  news on this patch?
 
  Something like this would be required for USB support
  on beagle bone (AM335X), which has 2 phy's of same type.
 
  Or is the plan to use generic phy framework instead ?
 
  Yes, Kishon's patches look more generic than mine.
 Will post the next version by this week.

Thanks Marc and Kishon

Regards
Afzal


Re: [PATCH 2/3] usb: otg: add device tree support to otg library

2012-09-12 Thread Marc Kleine-Budde
On 09/06/2012 05:27 PM, Marc Kleine-Budde wrote:
 We can use something like -phy as the phandle name. And the
 users can get the phy by using
 devm_usb_get_phy_by_phandle(dev, ).
 (So the frwrk appends *-phy* to the name and searches). Or we don't
 have any  restriction on the phandle naming conventions and search for
 the phandle by the name the user passes in devm_usb_get_phy_by_phandle
 directly.

 Maintainer, I need a Maintainer. Can someone please decide what we want
 to have here. I can code all that, but please someone has to make a
 decision. Now, please.

 Like I said on another reply:

 phyN (phy1, phy2, ... phyN) is better since eventually we want to turn
 this into a kernel-wide PHY layer.
 I think Marc is wondering how to handle the below two case in such way.
  - how to get the port number the phy is attached to
  - how to describe it if a port has two phys.

 Would something like below work ?

  phy = phy1 0 phy2 1;

 where the first attribute is a phandle to the phy and the second is a
 port number ?
 
 We have two (and some brain damaged) use cases:
 a) USB2/USB3:
One USB controller has two phys, one for USB2 the other for USB3.
The hardware has only one USB jack.
 
 b) IMHO poorly abstracted USB devices, where there are actually two
USB ports per device, there are two USB jacks on the hardware.
 
 c) mixture of a)+b)
 
 My current code (patch not yet published) implements:
 
 struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
   int index)
 
 With a hard coded phy phandle string and a index to that phandle. Your
 above example looks like this (taking 0 as base):
 
 DT:
 phy = phy0 phy1;
 
 c-code:
 phy0 = *devm_usb_get_phy_by_phandle(struct device *dev, 0)
 phy1 = *devm_usb_get_phy_by_phandle(struct device *dev, 1)
 
 This solves use case:
 a) The driver must know index 0 - USB2 phy, index 1 - USB3 phy
 b) The driver must know index 0 - phy of 1st usb port,
index 1 - phy of 2nd USB port
 
 But c) is not so easy:
 c) driver must know how many combined USB2/USB3 jacks and USB2 only
jack the hardware has.
 
 My solution fails for b) and thus c) if one of the ports (e.g. the first
 one is/should not be used). In my ideal world of proper abstracted
 devices each USB port would have its own device entry in the DT and
 would just stay disabled. Your solution is superior here. But
 struggles at c), too.
 
 Both solutions lack to describe what kind of phy it is.
 
 I'm now off for holidays, and back in the office on the 12th of September.

I'm back in the office ;) Comments?

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 2/3] usb: otg: add device tree support to otg library

2012-09-06 Thread Felipe Balbi
On Tue, Sep 04, 2012 at 09:32:06PM +0200, Marc Kleine-Budde wrote:
 On 09/04/2012 07:51 PM, ABRAHAM, KISHON VIJAY wrote:
  Since it's already a common function, we may give phandler 
  property
  a common name too. So we will not need phandle argument.
  Please also don't forget to document the devm_xxx and dt binding.
 
  I don't think this is a good idea. If we hardcode the phandle 
  name, we
  introduce a limit of one phy per usb device. The usb3 controllers
  alreadyt use two phys (one for usb2, the othere for usb3) for one
  controller. So I think we should not make the same mistake again.
  That only means current binding is not good enough. Rather not, means
  it should not be in common code.
  Maybe something like:
  usbport0-phys = phy0;
  usbport1-phys = phy1 phy2; /* usb2  usb3 */
 
  Granted. Do we need strings that describe the phys, like in pinctrl or
  is a index enough? What about this?
 
  struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
int index)
 
 
  Comments? The phandle_name string will be usbphy.
 
  I don't think phandle_name should be usbphy. Eventually we want to turn
  this into a kernel-wide phy subsystem and if we use usbphy, we will just
  have to patch a bunch of dts files once we make the move.
  Coud you please give a link of kernel-wide phy subsystem discussion?
 
  Is just phy better?
  If the property name don't include port number, how do we know what
  port the phy is attached to?
  
  We can use something like -phy as the phandle name. And the
  users can get the phy by using
  devm_usb_get_phy_by_phandle(dev, ).
  (So the frwrk appends *-phy* to the name and searches). Or we don't
  have any  restriction on the phandle naming conventions and search for
  the phandle by the name the user passes in devm_usb_get_phy_by_phandle
  directly.
 
 Maintainer, I need a Maintainer. Can someone please decide what we want
 to have here. I can code all that, but please someone has to make a
 decision. Now, please.

Like I said on another reply:

phyN (phy1, phy2, ... phyN) is better since eventually we want to turn
this into a kernel-wide PHY layer.

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH 2/3] usb: otg: add device tree support to otg library

2012-09-06 Thread Richard Zhao
On Thu, Sep 06, 2012 at 05:30:02PM +0300, Felipe Balbi wrote:
 On Tue, Sep 04, 2012 at 09:32:06PM +0200, Marc Kleine-Budde wrote:
  On 09/04/2012 07:51 PM, ABRAHAM, KISHON VIJAY wrote:
   Since it's already a common function, we may give phandler 
   property
   a common name too. So we will not need phandle argument.
   Please also don't forget to document the devm_xxx and dt 
   binding.
  
   I don't think this is a good idea. If we hardcode the phandle 
   name, we
   introduce a limit of one phy per usb device. The usb3 controllers
   alreadyt use two phys (one for usb2, the othere for usb3) for one
   controller. So I think we should not make the same mistake again.
   That only means current binding is not good enough. Rather not, 
   means
   it should not be in common code.
   Maybe something like:
   usbport0-phys = phy0;
   usbport1-phys = phy1 phy2; /* usb2  usb3 */
  
   Granted. Do we need strings that describe the phys, like in pinctrl 
   or
   is a index enough? What about this?
  
   struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
 int index)
  
  
   Comments? The phandle_name string will be usbphy.
  
   I don't think phandle_name should be usbphy. Eventually we want to 
   turn
   this into a kernel-wide phy subsystem and if we use usbphy, we will 
   just
   have to patch a bunch of dts files once we make the move.
   Coud you please give a link of kernel-wide phy subsystem discussion?
  
   Is just phy better?
   If the property name don't include port number, how do we know what
   port the phy is attached to?
   
   We can use something like -phy as the phandle name. And the
   users can get the phy by using
   devm_usb_get_phy_by_phandle(dev, ).
   (So the frwrk appends *-phy* to the name and searches). Or we don't
   have any  restriction on the phandle naming conventions and search for
   the phandle by the name the user passes in devm_usb_get_phy_by_phandle
   directly.
  
  Maintainer, I need a Maintainer. Can someone please decide what we want
  to have here. I can code all that, but please someone has to make a
  decision. Now, please.
 
 Like I said on another reply:
 
 phyN (phy1, phy2, ... phyN) is better since eventually we want to turn
 this into a kernel-wide PHY layer.
I think Marc is wondering how to handle the below two case in such way.
 - how to get the port number the phy is attached to
 - how to describe it if a port has two phys.

Thanks
Richard
 
 -- 
 balbi


--
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 2/3] usb: otg: add device tree support to otg library

2012-09-06 Thread Felipe Balbi
Hi,

We should at least add Grant to the loop, I guess.

On Thu, Sep 06, 2012 at 10:46:13PM +0800, Richard Zhao wrote:
 On Thu, Sep 06, 2012 at 05:30:02PM +0300, Felipe Balbi wrote:
  On Tue, Sep 04, 2012 at 09:32:06PM +0200, Marc Kleine-Budde wrote:
   On 09/04/2012 07:51 PM, ABRAHAM, KISHON VIJAY wrote:
Since it's already a common function, we may give phandler 
property
a common name too. So we will not need phandle argument.
Please also don't forget to document the devm_xxx and dt 
binding.
   
I don't think this is a good idea. If we hardcode the phandle 
name, we
introduce a limit of one phy per usb device. The usb3 
controllers
alreadyt use two phys (one for usb2, the othere for usb3) for 
one
controller. So I think we should not make the same mistake 
again.
That only means current binding is not good enough. Rather not, 
means
it should not be in common code.
Maybe something like:
usbport0-phys = phy0;
usbport1-phys = phy1 phy2; /* usb2  usb3 */
   
Granted. Do we need strings that describe the phys, like in 
pinctrl or
is a index enough? What about this?
   
struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
  int index)
   
   
Comments? The phandle_name string will be usbphy.
   
I don't think phandle_name should be usbphy. Eventually we want to 
turn
this into a kernel-wide phy subsystem and if we use usbphy, we will 
just
have to patch a bunch of dts files once we make the move.
Coud you please give a link of kernel-wide phy subsystem discussion?
   
Is just phy better?
If the property name don't include port number, how do we know what
port the phy is attached to?

We can use something like -phy as the phandle name. And the
users can get the phy by using
devm_usb_get_phy_by_phandle(dev, ).
(So the frwrk appends *-phy* to the name and searches). Or we don't
have any  restriction on the phandle naming conventions and search for
the phandle by the name the user passes in devm_usb_get_phy_by_phandle
directly.
   
   Maintainer, I need a Maintainer. Can someone please decide what we want
   to have here. I can code all that, but please someone has to make a
   decision. Now, please.
  
  Like I said on another reply:
  
  phyN (phy1, phy2, ... phyN) is better since eventually we want to turn
  this into a kernel-wide PHY layer.
 I think Marc is wondering how to handle the below two case in such way.
  - how to get the port number the phy is attached to
  - how to describe it if a port has two phys.

Would something like below work ?

phy = phy1 0 phy2 1;

where the first attribute is a phandle to the phy and the second is a
port number ?

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH 2/3] usb: otg: add device tree support to otg library

2012-09-06 Thread Marc Kleine-Budde
On 09/06/2012 04:46 PM, Felipe Balbi wrote:
 Hi,
 
 We should at least add Grant to the loop, I guess.
 
 On Thu, Sep 06, 2012 at 10:46:13PM +0800, Richard Zhao wrote:
 On Thu, Sep 06, 2012 at 05:30:02PM +0300, Felipe Balbi wrote:
 On Tue, Sep 04, 2012 at 09:32:06PM +0200, Marc Kleine-Budde wrote:
 On 09/04/2012 07:51 PM, ABRAHAM, KISHON VIJAY wrote:
 Since it's already a common function, we may give phandler 
 property
 a common name too. So we will not need phandle argument.
 Please also don't forget to document the devm_xxx and dt 
 binding.

 I don't think this is a good idea. If we hardcode the phandle 
 name, we
 introduce a limit of one phy per usb device. The usb3 controllers
 alreadyt use two phys (one for usb2, the othere for usb3) for one
 controller. So I think we should not make the same mistake again.
 That only means current binding is not good enough. Rather not, 
 means
 it should not be in common code.
 Maybe something like:
 usbport0-phys = phy0;
 usbport1-phys = phy1 phy2; /* usb2  usb3 */

 Granted. Do we need strings that describe the phys, like in pinctrl 
 or
 is a index enough? What about this?

 struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
   int index)


 Comments? The phandle_name string will be usbphy.

 I don't think phandle_name should be usbphy. Eventually we want to 
 turn
 this into a kernel-wide phy subsystem and if we use usbphy, we will 
 just
 have to patch a bunch of dts files once we make the move.
 Coud you please give a link of kernel-wide phy subsystem discussion?

 Is just phy better?
 If the property name don't include port number, how do we know what
 port the phy is attached to?

 We can use something like -phy as the phandle name. And the
 users can get the phy by using
 devm_usb_get_phy_by_phandle(dev, ).
 (So the frwrk appends *-phy* to the name and searches). Or we don't
 have any  restriction on the phandle naming conventions and search for
 the phandle by the name the user passes in devm_usb_get_phy_by_phandle
 directly.

 Maintainer, I need a Maintainer. Can someone please decide what we want
 to have here. I can code all that, but please someone has to make a
 decision. Now, please.

 Like I said on another reply:

 phyN (phy1, phy2, ... phyN) is better since eventually we want to turn
 this into a kernel-wide PHY layer.
 I think Marc is wondering how to handle the below two case in such way.
  - how to get the port number the phy is attached to
  - how to describe it if a port has two phys.
 
 Would something like below work ?
 
   phy = phy1 0 phy2 1;
 
 where the first attribute is a phandle to the phy and the second is a
 port number ?

We have two (and some brain damaged) use cases:
a) USB2/USB3:
   One USB controller has two phys, one for USB2 the other for USB3.
   The hardware has only one USB jack.

b) IMHO poorly abstracted USB devices, where there are actually two
   USB ports per device, there are two USB jacks on the hardware.

c) mixture of a)+b)

My current code (patch not yet published) implements:

struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
int index)

With a hard coded phy phandle string and a index to that phandle. Your
above example looks like this (taking 0 as base):

DT:
phy = phy0 phy1;

c-code:
phy0 = *devm_usb_get_phy_by_phandle(struct device *dev, 0)
phy1 = *devm_usb_get_phy_by_phandle(struct device *dev, 1)

This solves use case:
a) The driver must know index 0 - USB2 phy, index 1 - USB3 phy
b) The driver must know index 0 - phy of 1st usb port,
   index 1 - phy of 2nd USB port

But c) is not so easy:
c) driver must know how many combined USB2/USB3 jacks and USB2 only
   jack the hardware has.

My solution fails for b) and thus c) if one of the ports (e.g. the first
one is/should not be used). In my ideal world of proper abstracted
devices each USB port would have its own device entry in the DT and
would just stay disabled. Your solution is superior here. But
struggles at c), too.

Both solutions lack to describe what kind of phy it is.

I'm now off for holidays, and back in the office on the 12th of September.

Regards,
Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 2/3] usb: otg: add device tree support to otg library

2012-09-04 Thread Marc Kleine-Budde
On 08/29/2012 10:11 PM, Marc Kleine-Budde wrote:
[...]

 +struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
 +const char *phandle)

 Since it's already a common function, we may give phandler property
 a common name too. So we will not need phandle argument.
 Please also don't forget to document the devm_xxx and dt binding.

 I don't think this is a good idea. If we hardcode the phandle name, we
 introduce a limit of one phy per usb device. The usb3 controllers
 alreadyt use two phys (one for usb2, the othere for usb3) for one
 controller. So I think we should not make the same mistake again.
 That only means current binding is not good enough. Rather not, means
 it should not be in common code.
 Maybe something like:
 usbport0-phys = phy0;
 usbport1-phys = phy1 phy2; /* usb2  usb3 */
 
 Granted. Do we need strings that describe the phys, like in pinctrl or
 is a index enough? What about this?
 
 struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
   int index)


Comments? The phandle_name string will be usbphy.

 +{
 +struct usb_phy  *phy = NULL, **ptr;
 +unsigned long   flags;
 +struct device_node *node;
 +
 +if (!dev-of_node) {
 +dev_dbg(dev, device does not have a device node entry\n);
 +return ERR_PTR(-EINVAL);
 +}
 +
 +node = of_parse_phandle(dev-of_node, phandle, 0);
 +if (!node) {
 +dev_dbg(dev, failed to get %s phandle in %s node\n, 
 phandle,
 +dev-of_node-full_name);
 +return ERR_PTR(-ENODEV);
 +}
 +
 +ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL);
 +if (!ptr) {
 +dev_dbg(dev, failed to allocate memory for devres\n);
 +return ERR_PTR(-ENOMEM);
 +}
 +
 +spin_lock_irqsave(phy_lock, flags);
 +
 +phy = __of_usb_find_phy(phy_list, node);
 +if (IS_ERR(phy) || !try_module_get(phy-dev-driver-owner)) {
 +phy = ERR_PTR(-EPROBE_DEFER);
 +devres_free(ptr);
 +goto err0;
 +}
 +
 +*ptr = phy;
 +devres_add(dev, ptr);
 +
 +get_device(phy-dev);
 +
 +err0:
 +spin_unlock_irqrestore(phy_lock, flags);
 +
 +return phy;
 +}
 +EXPORT_SYMBOL(devm_usb_get_phy_by_phandle);
 +
 +/**
   * devm_usb_put_phy - release the USB PHY
   * @dev - device that wants to release this phy
   * @phy - the phy returned by devm_usb_get_phy()
 @@ -158,32 +234,24 @@ EXPORT_SYMBOL(usb_put_phy);
   */
  int usb_add_phy(struct usb_phy *x, enum usb_phy_type type)
  {
 -int ret = 0;
  unsigned long   flags;
  struct usb_phy  *phy;

 -if (x  x-type != USB_PHY_TYPE_UNDEFINED) {
 -dev_err(x-dev, not accepting initialized PHY %s\n, 
 x-label);
 -return -EINVAL;

 how about having
 if (x  !x-dev.of_node  x-type != USB_PHY_TYPE_UNDEFINED) {
 dev_err(x-dev, not accepting initialized PHY %s\n, x-label);
 return -EINVAL;
 }

 By using this we'll return error if the phy device does not have an
 of_node. (So it can't get back the phy by phandle).
 Maybe it worth to create a new set functions. When using DT, the way to
 add and get phy is totally different.
 
 Getting already will be (get_by_phandle). Do we need a seperate List for
 DT and non DT phys? usb_add_of_phy()? usb_add_dt_phy()?

comments?

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 2/3] usb: otg: add device tree support to otg library

2012-09-04 Thread Marc Kleine-Budde
On 09/04/2012 03:45 PM, Felipe Balbi wrote:
 On Tue, Sep 04, 2012 at 12:31:14PM +0200, Marc Kleine-Budde wrote:
 On 08/29/2012 10:11 PM, Marc Kleine-Budde wrote:
 [...]

 +struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
 +const char *phandle)

 Since it's already a common function, we may give phandler property
 a common name too. So we will not need phandle argument.
 Please also don't forget to document the devm_xxx and dt binding.

 I don't think this is a good idea. If we hardcode the phandle name, we
 introduce a limit of one phy per usb device. The usb3 controllers
 alreadyt use two phys (one for usb2, the othere for usb3) for one
 controller. So I think we should not make the same mistake again.
 That only means current binding is not good enough. Rather not, means
 it should not be in common code.
 Maybe something like:
 usbport0-phys = phy0;
 usbport1-phys = phy1 phy2; /* usb2  usb3 */

 Granted. Do we need strings that describe the phys, like in pinctrl or
 is a index enough? What about this?

 struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
 int index)


 Comments? The phandle_name string will be usbphy.
 
 I don't think phandle_name should be usbphy. Eventually we want to turn
 this into a kernel-wide phy subsystem and if we use usbphy, we will just
 have to patch a bunch of dts files once we make the move.

Is just phy better?

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 2/3] usb: otg: add device tree support to otg library

2012-09-04 Thread Richard Zhao
On Tue, Sep 04, 2012 at 03:58:50PM +0200, Marc Kleine-Budde wrote:
 On 09/04/2012 03:45 PM, Felipe Balbi wrote:
  On Tue, Sep 04, 2012 at 12:31:14PM +0200, Marc Kleine-Budde wrote:
  On 08/29/2012 10:11 PM, Marc Kleine-Budde wrote:
  [...]
 
  +struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
  +const char *phandle)
 
  Since it's already a common function, we may give phandler property
  a common name too. So we will not need phandle argument.
  Please also don't forget to document the devm_xxx and dt binding.
 
  I don't think this is a good idea. If we hardcode the phandle name, we
  introduce a limit of one phy per usb device. The usb3 controllers
  alreadyt use two phys (one for usb2, the othere for usb3) for one
  controller. So I think we should not make the same mistake again.
  That only means current binding is not good enough. Rather not, means
  it should not be in common code.
  Maybe something like:
  usbport0-phys = phy0;
  usbport1-phys = phy1 phy2; /* usb2  usb3 */
 
  Granted. Do we need strings that describe the phys, like in pinctrl or
  is a index enough? What about this?
 
  struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
int index)
 
 
  Comments? The phandle_name string will be usbphy.
  
  I don't think phandle_name should be usbphy. Eventually we want to turn
  this into a kernel-wide phy subsystem and if we use usbphy, we will just
  have to patch a bunch of dts files once we make the move.
Coud you please give a link of kernel-wide phy subsystem discussion?
 
 Is just phy better?
If the property name don't include port number, how do we know what
port the phy is attached to?

Thanks
Richard
 
 Marc
 
 -- 
 Pengutronix e.K.  | Marc Kleine-Budde   |
 Industrial Linux Solutions| Phone: +49-231-2826-924 |
 Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
 Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
 


--
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 2/3] usb: otg: add device tree support to otg library

2012-09-04 Thread Marc Kleine-Budde
On 09/04/2012 04:07 PM, Richard Zhao wrote:
 +struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
 +const char *phandle)

 Since it's already a common function, we may give phandler property
 a common name too. So we will not need phandle argument.
 Please also don't forget to document the devm_xxx and dt binding.

 I don't think this is a good idea. If we hardcode the phandle name, we
 introduce a limit of one phy per usb device. The usb3 controllers
 alreadyt use two phys (one for usb2, the othere for usb3) for one
 controller. So I think we should not make the same mistake again.
 That only means current binding is not good enough. Rather not, means
 it should not be in common code.
 Maybe something like:
 usbport0-phys = phy0;
 usbport1-phys = phy1 phy2; /* usb2  usb3 */

 Granted. Do we need strings that describe the phys, like in pinctrl or
 is a index enough? What about this?

 struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
   int index)


 Comments? The phandle_name string will be usbphy.

 I don't think phandle_name should be usbphy. Eventually we want to turn
 this into a kernel-wide phy subsystem and if we use usbphy, we will just
 have to patch a bunch of dts files once we make the move.
 Coud you please give a link of kernel-wide phy subsystem discussion?

 Is just phy better?
 If the property name don't include port number, how do we know what
 port the phy is attached to?

Take this ci13xxx-imx dts snippet for example:

usb@02184000 { /* USB OTG */
compatible = fsl,imx6q-usb, fsl,imx27-usb;
reg = 0x02184000 0x200;
interrupts = 0 43 0x04;
phy = usbphy1;
};

The existing fsl,usbphy will be renamed into just phy. If a usb/otg
device needs more than one phy the dts will look like this:

usb@02184000 { /* USB OTG */
compatible = fsl,imx6q-usb, fsl,imx27-usb;
reg = 0x02184000 0x200;
interrupts = 0 43 0x04;
phy = usbphy1 usbphy2;
};

The driver will get a reference to the usb_phy with:

struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
int index)

Where the index specifies with (usb) phy it wants to use.

This covers TI's usecase with an USB2 and an USB3 phy for one otg device.

Marc
-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 2/3] usb: otg: add device tree support to otg library

2012-09-04 Thread ABRAHAM, KISHON VIJAY
Hi,

On Tue, Sep 4, 2012 at 7:46 PM, Marc Kleine-Budde m...@pengutronix.de wrote:
 On 09/04/2012 04:07 PM, Richard Zhao wrote:
 +struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
 +const char *phandle)

 Since it's already a common function, we may give phandler property
 a common name too. So we will not need phandle argument.
 Please also don't forget to document the devm_xxx and dt binding.

 I don't think this is a good idea. If we hardcode the phandle name, we
 introduce a limit of one phy per usb device. The usb3 controllers
 alreadyt use two phys (one for usb2, the othere for usb3) for one
 controller. So I think we should not make the same mistake again.
 That only means current binding is not good enough. Rather not, means
 it should not be in common code.
 Maybe something like:
 usbport0-phys = phy0;
 usbport1-phys = phy1 phy2; /* usb2  usb3 */

 Granted. Do we need strings that describe the phys, like in pinctrl or
 is a index enough? What about this?

 struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
   int index)


 Comments? The phandle_name string will be usbphy.

 I don't think phandle_name should be usbphy. Eventually we want to turn
 this into a kernel-wide phy subsystem and if we use usbphy, we will just
 have to patch a bunch of dts files once we make the move.
 Coud you please give a link of kernel-wide phy subsystem discussion?

 Is just phy better?
 If the property name don't include port number, how do we know what
 port the phy is attached to?

We can use something like -phy as the phandle name. And the
users can get the phy by using
devm_usb_get_phy_by_phandle(dev, ).
(So the frwrk appends *-phy* to the name and searches). Or we don't
have any  restriction on the phandle naming conventions and search for
the phandle by the name the user passes in devm_usb_get_phy_by_phandle
directly.
Btw the regulator framework uses something like -supply and it
took me sometime to figure out the regulator phandle name should be
appended with -supply.

+   const char *phandle)

 Take this ci13xxx-imx dts snippet for example:

 usb@02184000 { /* USB OTG */
 compatible = fsl,imx6q-usb, fsl,imx27-usb;
 reg = 0x02184000 0x200;
 interrupts = 0 43 0x04;
 phy = usbphy1;
 };

 The existing fsl,usbphy will be renamed into just phy. If a usb/otg
 device needs more than one phy the dts will look like this:

 usb@02184000 { /* USB OTG */
 compatible = fsl,imx6q-usb, fsl,imx27-usb;
 reg = 0x02184000 0x200;
 interrupts = 0 43 0x04;
 phy = usbphy1 usbphy2;

Will this work? Can we return two phandles for a single phandle name?

Thanks
Kishon
--
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 2/3] usb: otg: add device tree support to otg library

2012-09-04 Thread Marc Kleine-Budde
On 09/04/2012 07:51 PM, ABRAHAM, KISHON VIJAY wrote:
 Since it's already a common function, we may give phandler property
 a common name too. So we will not need phandle argument.
 Please also don't forget to document the devm_xxx and dt binding.

 I don't think this is a good idea. If we hardcode the phandle name, 
 we
 introduce a limit of one phy per usb device. The usb3 controllers
 alreadyt use two phys (one for usb2, the othere for usb3) for one
 controller. So I think we should not make the same mistake again.
 That only means current binding is not good enough. Rather not, means
 it should not be in common code.
 Maybe something like:
 usbport0-phys = phy0;
 usbport1-phys = phy1 phy2; /* usb2  usb3 */

 Granted. Do we need strings that describe the phys, like in pinctrl or
 is a index enough? What about this?

 struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
   int index)


 Comments? The phandle_name string will be usbphy.

 I don't think phandle_name should be usbphy. Eventually we want to turn
 this into a kernel-wide phy subsystem and if we use usbphy, we will just
 have to patch a bunch of dts files once we make the move.
 Coud you please give a link of kernel-wide phy subsystem discussion?

 Is just phy better?
 If the property name don't include port number, how do we know what
 port the phy is attached to?
 
 We can use something like -phy as the phandle name. And the
 users can get the phy by using
 devm_usb_get_phy_by_phandle(dev, ).
 (So the frwrk appends *-phy* to the name and searches). Or we don't
 have any  restriction on the phandle naming conventions and search for
 the phandle by the name the user passes in devm_usb_get_phy_by_phandle
 directly.

Maintainer, I need a Maintainer. Can someone please decide what we want
to have here. I can code all that, but please someone has to make a
decision. Now, please.

 Btw the regulator framework uses something like -supply and it
 took me sometime to figure out the regulator phandle name should be
 appended with -supply.
 
 +   const char *phandle)

 Take this ci13xxx-imx dts snippet for example:

 usb@02184000 { /* USB OTG */
 compatible = fsl,imx6q-usb, fsl,imx27-usb;
 reg = 0x02184000 0x200;
 interrupts = 0 43 0x04;
 phy = usbphy1;
 };

 The existing fsl,usbphy will be renamed into just phy. If a usb/otg
 device needs more than one phy the dts will look like this:

 usb@02184000 { /* USB OTG */
 compatible = fsl,imx6q-usb, fsl,imx27-usb;
 reg = 0x02184000 0x200;
 interrupts = 0 43 0x04;
 phy = usbphy1 usbphy2;
 
 Will this work? Can we return two phandles for a single phandle name?

Not two handles with one devm_usb_get_phy_by_phandle call :), but if you
want to get both you do:

phy0 = devm_usb_get_phy_by_phandle(dev, 0);
phy1 = devm_usb_get_phy_by_phandle(dev, 1);

The magic lies in the third parameter of the of_parse_phandle():

of_parse_phandle(dev-of_node, phy, index);

This even fits into Ravi Babu's use case, two phys are attached to one
device (at least at the DT abstraction level).

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 2/3] usb: otg: add device tree support to otg library

2012-08-29 Thread Marc Kleine-Budde
On 08/29/2012 05:14 AM, Richard Zhao wrote:
 On Tue, Aug 28, 2012 at 07:43:11PM +0530, ABRAHAM, KISHON VIJAY wrote:
 Hi,

 On Tue, Aug 28, 2012 at 7:11 PM, Marc Kleine-Budde m...@pengutronix.de 
 wrote:
 On 08/24/2012 08:46 AM, Richard Zhao wrote:
 [...]
  /**
 + * devm_usb_get_phy_by_phandle - find the USB PHY by phandle
 + * @dev - device that requests this phy
 + * @phandle - name of the property holding the phy phandle value
 + *
 + * Returns the phy driver associated with the given phandle value,
 + * after getting a refcount to it, -ENODEV if there is no such phy or
 + * -EPROBE_DEFER if there is a phandle to the phy, but the device is
 + * not yet loaded. While at that, it also associates the device with
 + * the phy using devres. On driver detach, release function is invoked
 + * on the devres data, then, devres data is freed.
 + *
 + * For use by USB host and peripheral drivers.
 + */
 +struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
 +const char *phandle)

 Since it's already a common function, we may give phandler property
 a common name too. So we will not need phandle argument.
 Please also don't forget to document the devm_xxx and dt binding.

 I don't think this is a good idea. If we hardcode the phandle name, we
 introduce a limit of one phy per usb device. The usb3 controllers
 alreadyt use two phys (one for usb2, the othere for usb3) for one
 controller. So I think we should not make the same mistake again.
 That only means current binding is not good enough. Rather not, means
 it should not be in common code.
 Maybe something like:
 usbport0-phys = phy0;
 usbport1-phys = phy1 phy2; /* usb2  usb3 */

Granted. Do we need strings that describe the phys, like in pinctrl or
is a index enough? What about this?

struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
int index)


 +{
 +struct usb_phy  *phy = NULL, **ptr;
 +unsigned long   flags;
 +struct device_node *node;
 +
 +if (!dev-of_node) {
 +dev_dbg(dev, device does not have a device node entry\n);
 +return ERR_PTR(-EINVAL);
 +}
 +
 +node = of_parse_phandle(dev-of_node, phandle, 0);
 +if (!node) {
 +dev_dbg(dev, failed to get %s phandle in %s node\n, 
 phandle,
 +dev-of_node-full_name);
 +return ERR_PTR(-ENODEV);
 +}
 +
 +ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL);
 +if (!ptr) {
 +dev_dbg(dev, failed to allocate memory for devres\n);
 +return ERR_PTR(-ENOMEM);
 +}
 +
 +spin_lock_irqsave(phy_lock, flags);
 +
 +phy = __of_usb_find_phy(phy_list, node);
 +if (IS_ERR(phy) || !try_module_get(phy-dev-driver-owner)) {
 +phy = ERR_PTR(-EPROBE_DEFER);
 +devres_free(ptr);
 +goto err0;
 +}
 +
 +*ptr = phy;
 +devres_add(dev, ptr);
 +
 +get_device(phy-dev);
 +
 +err0:
 +spin_unlock_irqrestore(phy_lock, flags);
 +
 +return phy;
 +}
 +EXPORT_SYMBOL(devm_usb_get_phy_by_phandle);
 +
 +/**
   * devm_usb_put_phy - release the USB PHY
   * @dev - device that wants to release this phy
   * @phy - the phy returned by devm_usb_get_phy()
 @@ -158,32 +234,24 @@ EXPORT_SYMBOL(usb_put_phy);
   */
  int usb_add_phy(struct usb_phy *x, enum usb_phy_type type)
  {
 -int ret = 0;
  unsigned long   flags;
  struct usb_phy  *phy;

 -if (x  x-type != USB_PHY_TYPE_UNDEFINED) {
 -dev_err(x-dev, not accepting initialized PHY %s\n, 
 x-label);
 -return -EINVAL;

 how about having
 if (x  !x-dev.of_node  x-type != USB_PHY_TYPE_UNDEFINED) {
 dev_err(x-dev, not accepting initialized PHY %s\n, x-label);
 return -EINVAL;
 }

 By using this we'll return error if the phy device does not have an
 of_node. (So it can't get back the phy by phandle).
 Maybe it worth to create a new set functions. When using DT, the way to
 add and get phy is totally different.

Getting already will be (get_by_phandle). Do we need a seperate List for
DT and non DT phys? usb_add_of_phy()? usb_add_dt_phy()?

Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 2/3] usb: otg: add device tree support to otg library

2012-08-28 Thread ABRAHAM, KISHON VIJAY
Hi,

On Tue, Aug 28, 2012 at 7:11 PM, Marc Kleine-Budde m...@pengutronix.de wrote:
 On 08/24/2012 08:46 AM, Richard Zhao wrote:
 [...]
  /**
 + * devm_usb_get_phy_by_phandle - find the USB PHY by phandle
 + * @dev - device that requests this phy
 + * @phandle - name of the property holding the phy phandle value
 + *
 + * Returns the phy driver associated with the given phandle value,
 + * after getting a refcount to it, -ENODEV if there is no such phy or
 + * -EPROBE_DEFER if there is a phandle to the phy, but the device is
 + * not yet loaded. While at that, it also associates the device with
 + * the phy using devres. On driver detach, release function is invoked
 + * on the devres data, then, devres data is freed.
 + *
 + * For use by USB host and peripheral drivers.
 + */
 +struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
 +const char *phandle)

 Since it's already a common function, we may give phandler property
 a common name too. So we will not need phandle argument.
 Please also don't forget to document the devm_xxx and dt binding.

 I don't think this is a good idea. If we hardcode the phandle name, we
 introduce a limit of one phy per usb device. The usb3 controllers
 alreadyt use two phys (one for usb2, the othere for usb3) for one
 controller. So I think we should not make the same mistake again.

 +{
 +struct usb_phy  *phy = NULL, **ptr;
 +unsigned long   flags;
 +struct device_node *node;
 +
 +if (!dev-of_node) {
 +dev_dbg(dev, device does not have a device node entry\n);
 +return ERR_PTR(-EINVAL);
 +}
 +
 +node = of_parse_phandle(dev-of_node, phandle, 0);
 +if (!node) {
 +dev_dbg(dev, failed to get %s phandle in %s node\n, phandle,
 +dev-of_node-full_name);
 +return ERR_PTR(-ENODEV);
 +}
 +
 +ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL);
 +if (!ptr) {
 +dev_dbg(dev, failed to allocate memory for devres\n);
 +return ERR_PTR(-ENOMEM);
 +}
 +
 +spin_lock_irqsave(phy_lock, flags);
 +
 +phy = __of_usb_find_phy(phy_list, node);
 +if (IS_ERR(phy) || !try_module_get(phy-dev-driver-owner)) {
 +phy = ERR_PTR(-EPROBE_DEFER);
 +devres_free(ptr);
 +goto err0;
 +}
 +
 +*ptr = phy;
 +devres_add(dev, ptr);
 +
 +get_device(phy-dev);
 +
 +err0:
 +spin_unlock_irqrestore(phy_lock, flags);
 +
 +return phy;
 +}
 +EXPORT_SYMBOL(devm_usb_get_phy_by_phandle);
 +
 +/**
   * devm_usb_put_phy - release the USB PHY
   * @dev - device that wants to release this phy
   * @phy - the phy returned by devm_usb_get_phy()
 @@ -158,32 +234,24 @@ EXPORT_SYMBOL(usb_put_phy);
   */
  int usb_add_phy(struct usb_phy *x, enum usb_phy_type type)
  {
 -int ret = 0;
  unsigned long   flags;
  struct usb_phy  *phy;

 -if (x  x-type != USB_PHY_TYPE_UNDEFINED) {
 -dev_err(x-dev, not accepting initialized PHY %s\n, 
 x-label);
 -return -EINVAL;

how about having
if (x  !x-dev.of_node  x-type != USB_PHY_TYPE_UNDEFINED) {
dev_err(x-dev, not accepting initialized PHY %s\n, x-label);
return -EINVAL;
}

By using this we'll return error if the phy device does not have an
of_node. (So it can't get back the phy by phandle).

Thanks
Kishon
--
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 2/3] usb: otg: add device tree support to otg library

2012-08-26 Thread ABRAHAM, KISHON VIJAY
Hi,

On Sat, Aug 25, 2012 at 11:43 PM, Marc Kleine-Budde m...@pengutronix.de wrote:
 On 08/24/2012 08:46 AM, Richard Zhao wrote:
 Did you try both enableing and disabing DT pass build?

 Impossible on mx28 :) The platform always selects USE_DT, but on imx it
 builds without DT support.

 On Thu, Aug 23, 2012 at 07:22:53PM +0200, Marc Kleine-Budde wrote:
 From: Kishon Vijay Abraham I kis...@ti.com

 This patch adds an API to get usb phy by passing a device node phandle 
 value.
 The new added devm_usb_get_phy_by_phandle() function will return a pointer 
 to
 the phy on success, -EPROBE_DEFER if there is a device_node for the phandle,
 but the phy has not been added, or a ERR_PTR() otherwise.

 Since it's possible to obtain a phy by phandle, the checks in usb_add_phy() 
 for
 a valid phy type is removed (now it's just a debug message if a user tries 
 to
 add a phy with undefined type). This also allows to add multiple phys of 
 same
 type.

 Cc: Richard Zhao richard.z...@freescale.com
 Cc: Marek Vasut ma...@denx.de
 Signed-off-by: Kishon Vijay Abraham I kis...@ti.com
 Signed-off-by: Marc Kleine-Budde m...@pengutronix.de
 ---
  drivers/usb/otg/otg.c   |   96 
 ---
  include/linux/usb/otg.h |8 
  2 files changed, 90 insertions(+), 14 deletions(-)

 diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
 index 98c430e..23618de 100644
 --- a/drivers/usb/otg/otg.c
 +++ b/drivers/usb/otg/otg.c
 @@ -15,6 +15,7 @@
  #include linux/device.h
  #include linux/module.h
  #include linux/slab.h
 +#include linux/of.h

  #include linux/usb/otg.h

 @@ -36,6 +37,21 @@ static struct usb_phy *__usb_find_phy(struct list_head 
 *list,
  return ERR_PTR(-ENODEV);
  }

 +static struct usb_phy *__of_usb_find_phy(struct list_head *list,
 +struct device_node *node)
 +{
 +struct usb_phy  *phy;
 +
 +list_for_each_entry(phy, list, head) {
 +if (node != phy-dev-of_node)
 +continue;
 +
 +return phy;
 +}
 +
 +return ERR_PTR(-ENODEV);
 +}
 +
  static void devm_usb_phy_release(struct device *dev, void *res)
  {
  struct usb_phy *phy = *(struct usb_phy **)res;
 @@ -112,6 +128,66 @@ err0:
  EXPORT_SYMBOL(usb_get_phy);

  /**
 + * devm_usb_get_phy_by_phandle - find the USB PHY by phandle
 + * @dev - device that requests this phy
 + * @phandle - name of the property holding the phy phandle value
 + *
 + * Returns the phy driver associated with the given phandle value,
 + * after getting a refcount to it, -ENODEV if there is no such phy or
 + * -EPROBE_DEFER if there is a phandle to the phy, but the device is
 + * not yet loaded. While at that, it also associates the device with
 + * the phy using devres. On driver detach, release function is invoked
 + * on the devres data, then, devres data is freed.
 + *
 + * For use by USB host and peripheral drivers.
 + */
 +struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
 +const char *phandle)

 Since it's already a common function, we may give phandler property
 a common name too. So we will not need phandle argument.
 Please also don't forget to document the devm_xxx and dt binding.

 Good point. This is the device tree snippet from imx28.dtsi:

 usb0: usb@8008 {
 compatible = fsl,imx28-usb, fsl,imx27-usb;
 reg = 0x8008 0x1;
 interrupts = 93;
 fsl,usbphy = usbphy0;
   

 What about removing the fsl,, so it just would be usbphy.

 status = disabled;
 };

 +{
 +struct usb_phy  *phy = NULL, **ptr;
 +unsigned long   flags;
 +struct device_node *node;
 +
 +if (!dev-of_node) {
 +dev_dbg(dev, device does not have a device node entry\n);
 +return ERR_PTR(-EINVAL);
 +}
 +
 +node = of_parse_phandle(dev-of_node, phandle, 0);
 +if (!node) {
 +dev_dbg(dev, failed to get %s phandle in %s node\n, phandle,
 +dev-of_node-full_name);
 +return ERR_PTR(-ENODEV);
 +}
 +
 +ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL);
 +if (!ptr) {
 +dev_dbg(dev, failed to allocate memory for devres\n);
 +return ERR_PTR(-ENOMEM);
 +}
 +
 +spin_lock_irqsave(phy_lock, flags);
 +
 +phy = __of_usb_find_phy(phy_list, node);
 +if (IS_ERR(phy) || !try_module_get(phy-dev-driver-owner)) {
 +phy = ERR_PTR(-EPROBE_DEFER);
 +devres_free(ptr);
 +goto err0;
 +}
 +
 +*ptr = phy;
 +devres_add(dev, ptr);
 +
 +get_device(phy-dev);
 +
 +err0:
 +spin_unlock_irqrestore(phy_lock, flags);
 +
 +return phy;
 +}
 +EXPORT_SYMBOL(devm_usb_get_phy_by_phandle);
 +
 +/**
   * devm_usb_put_phy - release the USB PHY
   * @dev - device that wants to release this phy
   * @phy - the phy returned by devm_usb_get_phy()
 @@ -158,32 +234,24 @@ EXPORT_SYMBOL(usb_put_phy);
   */
  int 

Re: [PATCH 2/3] usb: otg: add device tree support to otg library

2012-08-25 Thread Marc Kleine-Budde
On 08/24/2012 08:46 AM, Richard Zhao wrote:
 Did you try both enableing and disabing DT pass build?

Impossible on mx28 :) The platform always selects USE_DT, but on imx it
builds without DT support.

 On Thu, Aug 23, 2012 at 07:22:53PM +0200, Marc Kleine-Budde wrote:
 From: Kishon Vijay Abraham I kis...@ti.com

 This patch adds an API to get usb phy by passing a device node phandle value.
 The new added devm_usb_get_phy_by_phandle() function will return a pointer to
 the phy on success, -EPROBE_DEFER if there is a device_node for the phandle,
 but the phy has not been added, or a ERR_PTR() otherwise.

 Since it's possible to obtain a phy by phandle, the checks in usb_add_phy() 
 for
 a valid phy type is removed (now it's just a debug message if a user tries to
 add a phy with undefined type). This also allows to add multiple phys of same
 type.

 Cc: Richard Zhao richard.z...@freescale.com
 Cc: Marek Vasut ma...@denx.de
 Signed-off-by: Kishon Vijay Abraham I kis...@ti.com
 Signed-off-by: Marc Kleine-Budde m...@pengutronix.de
 ---
  drivers/usb/otg/otg.c   |   96 
 ---
  include/linux/usb/otg.h |8 
  2 files changed, 90 insertions(+), 14 deletions(-)

 diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
 index 98c430e..23618de 100644
 --- a/drivers/usb/otg/otg.c
 +++ b/drivers/usb/otg/otg.c
 @@ -15,6 +15,7 @@
  #include linux/device.h
  #include linux/module.h
  #include linux/slab.h
 +#include linux/of.h
  
  #include linux/usb/otg.h
  
 @@ -36,6 +37,21 @@ static struct usb_phy *__usb_find_phy(struct list_head 
 *list,
  return ERR_PTR(-ENODEV);
  }
  
 +static struct usb_phy *__of_usb_find_phy(struct list_head *list,
 +struct device_node *node)
 +{
 +struct usb_phy  *phy;
 +
 +list_for_each_entry(phy, list, head) {
 +if (node != phy-dev-of_node)
 +continue;
 +
 +return phy;
 +}
 +
 +return ERR_PTR(-ENODEV);
 +}
 +
  static void devm_usb_phy_release(struct device *dev, void *res)
  {
  struct usb_phy *phy = *(struct usb_phy **)res;
 @@ -112,6 +128,66 @@ err0:
  EXPORT_SYMBOL(usb_get_phy);
  
  /**
 + * devm_usb_get_phy_by_phandle - find the USB PHY by phandle
 + * @dev - device that requests this phy
 + * @phandle - name of the property holding the phy phandle value
 + *
 + * Returns the phy driver associated with the given phandle value,
 + * after getting a refcount to it, -ENODEV if there is no such phy or
 + * -EPROBE_DEFER if there is a phandle to the phy, but the device is
 + * not yet loaded. While at that, it also associates the device with
 + * the phy using devres. On driver detach, release function is invoked
 + * on the devres data, then, devres data is freed.
 + *
 + * For use by USB host and peripheral drivers.
 + */
 +struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
 +const char *phandle)

 Since it's already a common function, we may give phandler property
 a common name too. So we will not need phandle argument.
 Please also don't forget to document the devm_xxx and dt binding.

Good point. This is the device tree snippet from imx28.dtsi:

 usb0: usb@8008 {
 compatible = fsl,imx28-usb, fsl,imx27-usb;
 reg = 0x8008 0x1;
 interrupts = 93;
 fsl,usbphy = usbphy0;
  

What about removing the fsl,, so it just would be usbphy.

 status = disabled;
 };

 +{
 +struct usb_phy  *phy = NULL, **ptr;
 +unsigned long   flags;
 +struct device_node *node;
 +
 +if (!dev-of_node) {
 +dev_dbg(dev, device does not have a device node entry\n);
 +return ERR_PTR(-EINVAL);
 +}
 +
 +node = of_parse_phandle(dev-of_node, phandle, 0);
 +if (!node) {
 +dev_dbg(dev, failed to get %s phandle in %s node\n, phandle,
 +dev-of_node-full_name);
 +return ERR_PTR(-ENODEV);
 +}
 +
 +ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL);
 +if (!ptr) {
 +dev_dbg(dev, failed to allocate memory for devres\n);
 +return ERR_PTR(-ENOMEM);
 +}
 +
 +spin_lock_irqsave(phy_lock, flags);
 +
 +phy = __of_usb_find_phy(phy_list, node);
 +if (IS_ERR(phy) || !try_module_get(phy-dev-driver-owner)) {
 +phy = ERR_PTR(-EPROBE_DEFER);
 +devres_free(ptr);
 +goto err0;
 +}
 +
 +*ptr = phy;
 +devres_add(dev, ptr);
 +
 +get_device(phy-dev);
 +
 +err0:
 +spin_unlock_irqrestore(phy_lock, flags);
 +
 +return phy;
 +}
 +EXPORT_SYMBOL(devm_usb_get_phy_by_phandle);
 +
 +/**
   * devm_usb_put_phy - release the USB PHY
   * @dev - device that wants to release this phy
   * @phy - the phy returned by devm_usb_get_phy()
 @@ -158,32 +234,24 @@ EXPORT_SYMBOL(usb_put_phy);
   */
  int usb_add_phy(struct usb_phy *x, enum usb_phy_type type)
  {
 -int ret = 0;