Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-21 Thread Sascha Hauer
On Sat, Jul 20, 2013 at 07:59:10PM -0700, Greg KH wrote:
 On Sat, Jul 20, 2013 at 10:32:26PM -0400, Alan Stern wrote:
  On Sat, 20 Jul 2013, Greg KH wrote:
  
That should be passed using platform data.

Ick, don't pass strings around, pass pointers.  If you have platform
data you can get to, then put the pointer there, don't use a name.

I don't think I understood you here :-s We wont have phy pointer
when we create the device for the controller no?(it'll be done in
board file). Probably I'm missing something.
   
   Why will you not have that pointer?  You can't rely on the name as the
   device id will not match up, so you should be able to rely on the
   pointer being in the structure that the board sets up, right?
   
   Don't use names, especially as ids can, and will, change, that is going
   to cause big problems.  Use pointers, this is C, we are supposed to be
   doing that :)
  
  Kishon, I think what Greg means is this:  The name you are using must
  be stored somewhere in a data structure constructed by the board file,
  right?  Or at least, associated with some data structure somehow.  
  Otherwise the platform code wouldn't know which PHY hardware
  corresponded to a particular name.
  
  Greg's suggestion is that you store the address of that data structure 
  in the platform data instead of storing the name string.  Have the 
  consumer pass the data structure's address when it calls phy_create, 
  instead of passing the name.  Then you don't have to worry about two 
  PHYs accidentally ending up with the same name or any other similar 
  problems.
 
 Close, but the issue is that whatever returns from phy_create() should
 then be used, no need to call any find functions, as you can just use
 the pointer that phy_create() returns.  Much like all other class api
 functions in the kernel work.

I think the problem here is to connect two from the bus structure
completely independent devices. Several frameworks (ASoC, soc-camera)
had this problem and this wasn't solved until the advent of devicetrees
and their phandles.
phy_create might be called from the probe function of some i2c device
(the phy device) and the resulting pointer is then needed in some other
platform devices (the user of the phy) probe function.
The best solution we have right now is implemented in the clk framework
which uses a string matching of the device names in clk_get() (at least
in the non-dt case).

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-21 Thread Tomasz Figa
Hi,

On Saturday 20 of July 2013 19:59:10 Greg KH wrote:
 On Sat, Jul 20, 2013 at 10:32:26PM -0400, Alan Stern wrote:
  On Sat, 20 Jul 2013, Greg KH wrote:
That should be passed using platform data.

Ick, don't pass strings around, pass pointers.  If you have
platform
data you can get to, then put the pointer there, don't use a
name.

I don't think I understood you here :-s We wont have phy pointer
when we create the device for the controller no?(it'll be done in
board file). Probably I'm missing something.
   
   Why will you not have that pointer?  You can't rely on the name as
   the device id will not match up, so you should be able to rely on
   the pointer being in the structure that the board sets up, right?
   
   Don't use names, especially as ids can, and will, change, that is
   going
   to cause big problems.  Use pointers, this is C, we are supposed to
   be
   doing that :)
  
  Kishon, I think what Greg means is this:  The name you are using must
  be stored somewhere in a data structure constructed by the board file,
  right?  Or at least, associated with some data structure somehow.
  Otherwise the platform code wouldn't know which PHY hardware
  corresponded to a particular name.
  
  Greg's suggestion is that you store the address of that data structure
  in the platform data instead of storing the name string.  Have the
  consumer pass the data structure's address when it calls phy_create,
  instead of passing the name.  Then you don't have to worry about two
  PHYs accidentally ending up with the same name or any other similar
  problems.
 
 Close, but the issue is that whatever returns from phy_create() should
 then be used, no need to call any find functions, as you can just use
 the pointer that phy_create() returns.  Much like all other class api
 functions in the kernel work.

I think there is a confusion here about who registers the PHYs.

All platform code does is registering a platform/i2c/whatever device, 
which causes a driver (located in drivers/phy/) to be instantiated. Such 
drivers call phy_create(), usually in their probe() callbacks, so 
platform_code has no way (and should have no way, for the sake of 
layering) to get what phy_create() returns.

IMHO we need a lookup method for PHYs, just like for clocks, regulators, 
PWMs or even i2c busses because there are complex cases when passing just 
a name using platform data will not work. I would second what Stephen said 
[1] and define a structure doing things in a DT-like way.

Example;

[platform code]

static const struct phy_lookup my_phy_lookup[] = {
PHY_LOOKUP(s3c-hsotg.0, otg, samsung-usbphy.1, phy.2),
/* etc... */
};

static void my_machine_init(void)
{
/* ... */
phy_register_lookup(my_phy_lookup, ARRAY_SIZE(my_phy_lookup));
/* ... */
}

/* Notice nothing stuffed in platform data. */

[provider code - samsung-usbphy driver]

static int samsung_usbphy_probe(...)
{
/* ... */
for (i = 0; i  PHY_COUNT; ++i) {
usbphy-phy[i].name = phy;
usbphy-phy[i].id = i;
/* ... */
ret = phy_create(usbphy-phy);
/* err handling */
}
/* ... */
}

[consumer code - s3c-hsotg driver]

static int s3c_hsotg_probe(...)
{
/* ... */
phy = phy_get(pdev-dev, otg);
/* ... */
}

[1] http://thread.gmane.org/gmane.linux.ports.arm.kernel/252813

Best regards,
Tomasz

___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-21 Thread Kishon Vijay Abraham I

Hi,

On Sunday 21 July 2013 04:01 PM, Tomasz Figa wrote:

Hi,

On Saturday 20 of July 2013 19:59:10 Greg KH wrote:

On Sat, Jul 20, 2013 at 10:32:26PM -0400, Alan Stern wrote:

On Sat, 20 Jul 2013, Greg KH wrote:

That should be passed using platform data.


Ick, don't pass strings around, pass pointers.  If you have
platform
data you can get to, then put the pointer there, don't use a
name.


I don't think I understood you here :-s We wont have phy pointer
when we create the device for the controller no?(it'll be done in
board file). Probably I'm missing something.


Why will you not have that pointer?  You can't rely on the name as
the device id will not match up, so you should be able to rely on
the pointer being in the structure that the board sets up, right?

Don't use names, especially as ids can, and will, change, that is
going
to cause big problems.  Use pointers, this is C, we are supposed to
be
doing that :)


Kishon, I think what Greg means is this:  The name you are using must
be stored somewhere in a data structure constructed by the board file,
right?  Or at least, associated with some data structure somehow.
Otherwise the platform code wouldn't know which PHY hardware
corresponded to a particular name.

Greg's suggestion is that you store the address of that data structure
in the platform data instead of storing the name string.  Have the
consumer pass the data structure's address when it calls phy_create,
instead of passing the name.  Then you don't have to worry about two
PHYs accidentally ending up with the same name or any other similar
problems.


Close, but the issue is that whatever returns from phy_create() should
then be used, no need to call any find functions, as you can just use
the pointer that phy_create() returns.  Much like all other class api
functions in the kernel work.


I think there is a confusion here about who registers the PHYs.

All platform code does is registering a platform/i2c/whatever device,
which causes a driver (located in drivers/phy/) to be instantiated. Such
drivers call phy_create(), usually in their probe() callbacks, so
platform_code has no way (and should have no way, for the sake of
layering) to get what phy_create() returns.


right.


IMHO we need a lookup method for PHYs, just like for clocks, regulators,
PWMs or even i2c busses because there are complex cases when passing just
a name using platform data will not work. I would second what Stephen said
[1] and define a structure doing things in a DT-like way.

Example;

[platform code]

static const struct phy_lookup my_phy_lookup[] = {
PHY_LOOKUP(s3c-hsotg.0, otg, samsung-usbphy.1, phy.2),


The only problem here is that if *PLATFORM_DEVID_AUTO* is used while 
creating the device, the ids in the device name would change and 
PHY_LOOKUP wont be useful.


Thanks
Kishon
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-21 Thread Tomasz Figa
On Sunday 21 of July 2013 16:37:33 Kishon Vijay Abraham I wrote:
 Hi,
 
 On Sunday 21 July 2013 04:01 PM, Tomasz Figa wrote:
  Hi,
  
  On Saturday 20 of July 2013 19:59:10 Greg KH wrote:
  On Sat, Jul 20, 2013 at 10:32:26PM -0400, Alan Stern wrote:
  On Sat, 20 Jul 2013, Greg KH wrote:
  That should be passed using platform data.
  
  Ick, don't pass strings around, pass pointers.  If you have
  platform
  data you can get to, then put the pointer there, don't use a
  name.
  
  I don't think I understood you here :-s We wont have phy pointer
  when we create the device for the controller no?(it'll be done in
  board file). Probably I'm missing something.
  
  Why will you not have that pointer?  You can't rely on the name
  as
  the device id will not match up, so you should be able to rely on
  the pointer being in the structure that the board sets up, right?
  
  Don't use names, especially as ids can, and will, change, that is
  going
  to cause big problems.  Use pointers, this is C, we are supposed to
  be
  doing that :)
  
  Kishon, I think what Greg means is this:  The name you are using
  must
  be stored somewhere in a data structure constructed by the board
  file,
  right?  Or at least, associated with some data structure somehow.
  Otherwise the platform code wouldn't know which PHY hardware
  corresponded to a particular name.
  
  Greg's suggestion is that you store the address of that data
  structure
  in the platform data instead of storing the name string.  Have the
  consumer pass the data structure's address when it calls phy_create,
  instead of passing the name.  Then you don't have to worry about two
  PHYs accidentally ending up with the same name or any other similar
  problems.
  
  Close, but the issue is that whatever returns from phy_create()
  should
  then be used, no need to call any find functions, as you can just
  use
  the pointer that phy_create() returns.  Much like all other class api
  functions in the kernel work.
  
  I think there is a confusion here about who registers the PHYs.
  
  All platform code does is registering a platform/i2c/whatever device,
  which causes a driver (located in drivers/phy/) to be instantiated.
  Such drivers call phy_create(), usually in their probe() callbacks,
  so platform_code has no way (and should have no way, for the sake of
  layering) to get what phy_create() returns.
 
 right.
 
  IMHO we need a lookup method for PHYs, just like for clocks,
  regulators, PWMs or even i2c busses because there are complex cases
  when passing just a name using platform data will not work. I would
  second what Stephen said [1] and define a structure doing things in a
  DT-like way.
  
  Example;
  
  [platform code]
  
  static const struct phy_lookup my_phy_lookup[] = {
  
  PHY_LOOKUP(s3c-hsotg.0, otg, samsung-usbphy.1, phy.2),
 
 The only problem here is that if *PLATFORM_DEVID_AUTO* is used while
 creating the device, the ids in the device name would change and
 PHY_LOOKUP wont be useful.

I don't think this is a problem. All the existing lookup methods already 
use ID to identify devices (see regulators, clkdev, PWMs, i2c, ...). You 
can simply add a requirement that the ID must be assigned manually, 
without using PLATFORM_DEVID_AUTO to use PHY lookup.

Best regards,
Tomasz

___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-21 Thread Greg KH
On Sun, Jul 21, 2013 at 01:12:07PM +0200, Tomasz Figa wrote:
 On Sunday 21 of July 2013 16:37:33 Kishon Vijay Abraham I wrote:
  Hi,
  
  On Sunday 21 July 2013 04:01 PM, Tomasz Figa wrote:
   Hi,
   
   On Saturday 20 of July 2013 19:59:10 Greg KH wrote:
   On Sat, Jul 20, 2013 at 10:32:26PM -0400, Alan Stern wrote:
   On Sat, 20 Jul 2013, Greg KH wrote:
   That should be passed using platform data.
   
   Ick, don't pass strings around, pass pointers.  If you have
   platform
   data you can get to, then put the pointer there, don't use a
   name.
   
   I don't think I understood you here :-s We wont have phy pointer
   when we create the device for the controller no?(it'll be done in
   board file). Probably I'm missing something.
   
   Why will you not have that pointer?  You can't rely on the name
   as
   the device id will not match up, so you should be able to rely on
   the pointer being in the structure that the board sets up, right?
   
   Don't use names, especially as ids can, and will, change, that is
   going
   to cause big problems.  Use pointers, this is C, we are supposed to
   be
   doing that :)
   
   Kishon, I think what Greg means is this:  The name you are using
   must
   be stored somewhere in a data structure constructed by the board
   file,
   right?  Or at least, associated with some data structure somehow.
   Otherwise the platform code wouldn't know which PHY hardware
   corresponded to a particular name.
   
   Greg's suggestion is that you store the address of that data
   structure
   in the platform data instead of storing the name string.  Have the
   consumer pass the data structure's address when it calls phy_create,
   instead of passing the name.  Then you don't have to worry about two
   PHYs accidentally ending up with the same name or any other similar
   problems.
   
   Close, but the issue is that whatever returns from phy_create()
   should
   then be used, no need to call any find functions, as you can just
   use
   the pointer that phy_create() returns.  Much like all other class api
   functions in the kernel work.
   
   I think there is a confusion here about who registers the PHYs.
   
   All platform code does is registering a platform/i2c/whatever device,
   which causes a driver (located in drivers/phy/) to be instantiated.
   Such drivers call phy_create(), usually in their probe() callbacks,
   so platform_code has no way (and should have no way, for the sake of
   layering) to get what phy_create() returns.

Why not put pointers in the platform data structure that can hold these
pointers?  I thought that is why we created those structures in the
first place.  If not, what are they there for?

   IMHO we need a lookup method for PHYs, just like for clocks,
   regulators, PWMs or even i2c busses because there are complex cases
   when passing just a name using platform data will not work. I would
   second what Stephen said [1] and define a structure doing things in a
   DT-like way.
   
   Example;
   
   [platform code]
   
   static const struct phy_lookup my_phy_lookup[] = {
   
 PHY_LOOKUP(s3c-hsotg.0, otg, samsung-usbphy.1, phy.2),
  
  The only problem here is that if *PLATFORM_DEVID_AUTO* is used while
  creating the device, the ids in the device name would change and
  PHY_LOOKUP wont be useful.
 
 I don't think this is a problem. All the existing lookup methods already 
 use ID to identify devices (see regulators, clkdev, PWMs, i2c, ...). You 
 can simply add a requirement that the ID must be assigned manually, 
 without using PLATFORM_DEVID_AUTO to use PHY lookup.

And I'm saying that this idea, of using a specific name and id, is
frought with fragility and will break in the future in various ways when
devices get added to systems, making these strings constantly have to be
kept up to date with different board configurations.

People, NEVER, hardcode something like an id.  The fact that this
happens today with the clock code, doesn't make it right, it makes the
clock code wrong.  Others have already said that this is wrong there as
well, as systems change and dynamic ids get used more and more.

Let's not repeat the same mistakes of the past just because we refuse to
learn from them...

So again, the find a phy by a string functions should be removed, the
device id should be automatically created by the phy core just to make
things unique in sysfs, and no driver code should _ever_ be reliant on
the number that is being created, and the pointer to the phy structure
should be used everywhere instead.

With those types of changes, I will consider merging this subsystem, but
without them, sorry, I will not.

thanks,

greg k-h
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-21 Thread Greg KH
On Sun, Jul 21, 2013 at 12:22:48PM +0200, Sascha Hauer wrote:
 On Sat, Jul 20, 2013 at 07:59:10PM -0700, Greg KH wrote:
  On Sat, Jul 20, 2013 at 10:32:26PM -0400, Alan Stern wrote:
   On Sat, 20 Jul 2013, Greg KH wrote:
   
 That should be passed using platform data.
 
 Ick, don't pass strings around, pass pointers.  If you have platform
 data you can get to, then put the pointer there, don't use a name.
 
 I don't think I understood you here :-s We wont have phy pointer
 when we create the device for the controller no?(it'll be done in
 board file). Probably I'm missing something.

Why will you not have that pointer?  You can't rely on the name as the
device id will not match up, so you should be able to rely on the
pointer being in the structure that the board sets up, right?

Don't use names, especially as ids can, and will, change, that is going
to cause big problems.  Use pointers, this is C, we are supposed to be
doing that :)
   
   Kishon, I think what Greg means is this:  The name you are using must
   be stored somewhere in a data structure constructed by the board file,
   right?  Or at least, associated with some data structure somehow.  
   Otherwise the platform code wouldn't know which PHY hardware
   corresponded to a particular name.
   
   Greg's suggestion is that you store the address of that data structure 
   in the platform data instead of storing the name string.  Have the 
   consumer pass the data structure's address when it calls phy_create, 
   instead of passing the name.  Then you don't have to worry about two 
   PHYs accidentally ending up with the same name or any other similar 
   problems.
  
  Close, but the issue is that whatever returns from phy_create() should
  then be used, no need to call any find functions, as you can just use
  the pointer that phy_create() returns.  Much like all other class api
  functions in the kernel work.
 
 I think the problem here is to connect two from the bus structure
 completely independent devices. Several frameworks (ASoC, soc-camera)
 had this problem and this wasn't solved until the advent of devicetrees
 and their phandles.
 phy_create might be called from the probe function of some i2c device
 (the phy device) and the resulting pointer is then needed in some other
 platform devices (the user of the phy) probe function.
 The best solution we have right now is implemented in the clk framework
 which uses a string matching of the device names in clk_get() (at least
 in the non-dt case).

I would argue that clocks are wrong here as well, as others have already
pointed out.

What's wrong with the platform_data structure, why can't that be used
for this?

Or, if not, we can always add pointers to the platform device structure,
or even the main 'struct device' as well, that's what it is there for.

thanks,

greg k-h
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-21 Thread Sylwester Nawrocki

On 07/21/2013 05:48 PM, Greg KH wrote:

On Sun, Jul 21, 2013 at 12:22:48PM +0200, Sascha Hauer wrote:

On Sat, Jul 20, 2013 at 07:59:10PM -0700, Greg KH wrote:

On Sat, Jul 20, 2013 at 10:32:26PM -0400, Alan Stern wrote:

On Sat, 20 Jul 2013, Greg KH wrote:


That should be passed using platform data.


Ick, don't pass strings around, pass pointers.  If you have platform
data you can get to, then put the pointer there, don't use a name.


I don't think I understood you here :-s We wont have phy pointer
when we create the device for the controller no?(it'll be done in
board file). Probably I'm missing something.


Why will you not have that pointer?  You can't rely on the name as the
device id will not match up, so you should be able to rely on the
pointer being in the structure that the board sets up, right?

Don't use names, especially as ids can, and will, change, that is going
to cause big problems.  Use pointers, this is C, we are supposed to be
doing that :)


Kishon, I think what Greg means is this:  The name you are using must
be stored somewhere in a data structure constructed by the board file,
right?  Or at least, associated with some data structure somehow.
Otherwise the platform code wouldn't know which PHY hardware
corresponded to a particular name.

Greg's suggestion is that you store the address of that data structure
in the platform data instead of storing the name string.  Have the
consumer pass the data structure's address when it calls phy_create,
instead of passing the name.  Then you don't have to worry about two
PHYs accidentally ending up with the same name or any other similar
problems.


Close, but the issue is that whatever returns from phy_create() should
then be used, no need to call any find functions, as you can just use
the pointer that phy_create() returns.  Much like all other class api
functions in the kernel work.


I think the problem here is to connect two from the bus structure
completely independent devices. Several frameworks (ASoC, soc-camera)
had this problem and this wasn't solved until the advent of devicetrees
and their phandles.
phy_create might be called from the probe function of some i2c device
(the phy device) and the resulting pointer is then needed in some other
platform devices (the user of the phy) probe function.
The best solution we have right now is implemented in the clk framework
which uses a string matching of the device names in clk_get() (at least
in the non-dt case).


I would argue that clocks are wrong here as well, as others have already
pointed out.

What's wrong with the platform_data structure, why can't that be used
for this?


At the point the platform data of some driver is initialized, e.g. in
board setup code the PHY pointer is not known, since the PHY supplier
driver has not initialized yet.  Even though we wanted to pass pointer
to a PHY through some notifier call, it would have been not clear
which PHY user driver should match on such notifier.  A single PHY
supplier driver can create M PHY objects and this needs to be mapped
to N PHY user drivers.  This mapping needs to be defined somewhere by
the system integrator.  It works well with device tree, but except that
there seems to be no other reliable infrastructure in the kernel to
define links/dependencies between devices, since device identifiers are
not known in advance in all cases.

What Tomasz proposed seems currently most reasonable to me for non-dt.


Or, if not, we can always add pointers to the platform device structure,
or even the main 'struct device' as well, that's what it is there for.


Still we would need to solve a problem which platform device structure
gets which PHY pointer.

--
Regards,
Sylwester
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-21 Thread Alan Stern
On Sun, 21 Jul 2013, Sylwester Nawrocki wrote:

  What's wrong with the platform_data structure, why can't that be used
  for this?
 
 At the point the platform data of some driver is initialized, e.g. in
 board setup code the PHY pointer is not known, since the PHY supplier
 driver has not initialized yet.  Even though we wanted to pass pointer
 to a PHY through some notifier call, it would have been not clear
 which PHY user driver should match on such notifier.  A single PHY
 supplier driver can create M PHY objects and this needs to be mapped
 to N PHY user drivers.  This mapping needs to be defined somewhere by
 the system integrator.  It works well with device tree, but except that
 there seems to be no other reliable infrastructure in the kernel to
 define links/dependencies between devices, since device identifiers are
 not known in advance in all cases.
 
 What Tomasz proposed seems currently most reasonable to me for non-dt.
 
  Or, if not, we can always add pointers to the platform device structure,
  or even the main 'struct device' as well, that's what it is there for.
 
 Still we would need to solve a problem which platform device structure
 gets which PHY pointer.

Can you explain the issues in more detail?  I don't fully understand 
the situation.

Here's what I think I know:

The PHY and the controller it is attached to are both physical
devices.

The connection between them is hardwired by the system
manufacturer and cannot be changed by software.

PHYs are generally described by fixed system-specific board
files or by Device Tree information.  Are they ever discovered
dynamically?

Is the same true for the controllers attached to the PHYs?
If not -- if both a PHY and a controller are discovered 
dynamically -- how does the kernel know whether they are 
connected to each other?

The kernel needs to know which controller is attached to which
PHY.  Currently this information is represented by name or ID
strings embedded in platform data.

The PHY's driver (the supplier) uses the platform data to 
construct a platform_device structure that represents the PHY.  
Until this is done, the controller's driver (the client) cannot 
use the PHY.

Since there is no parent-child relation between the PHY and the 
controller, there is no guarantee that the PHY's driver will be
ready when the controller's driver wants to use it.  A deferred
probe may be needed.

The issue (or one of the issues) in this discussion is that 
Greg does not like the idea of using names or IDs to associate
PHYs with controllers, because they are too prone to
duplications or other errors.  Pointers are more reliable.

But pointers to what?  Since the only data known to be 
available to both the PHY driver and controller driver is the
platform data, the obvious answer is a pointer to platform data
(either for the PHY or for the controller, or maybe both).

Probably some of the details above are wrong; please indicate where I
have gone astray.  Also, I'm not clear about the role played by various 
APIs.  For example, where does phy_create() fit into this picture?

Alan Stern

___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-20 Thread Greg KH
On Sat, Jul 20, 2013 at 08:49:32AM +0530, Kishon Vijay Abraham I wrote:
 Hi,
 
 On Saturday 20 July 2013 05:20 AM, Greg KH wrote:
 On Fri, Jul 19, 2013 at 12:06:01PM +0530, Kishon Vijay Abraham I wrote:
 Hi,
 
 On Friday 19 July 2013 11:59 AM, Greg KH wrote:
 On Fri, Jul 19, 2013 at 11:25:44AM +0530, Kishon Vijay Abraham I wrote:
 Hi,
 
 On Friday 19 July 2013 11:13 AM, Greg KH wrote:
 On Fri, Jul 19, 2013 at 11:07:10AM +0530, Kishon Vijay Abraham I wrote:
 +   ret = dev_set_name(phy-dev, %s.%d, dev_name(dev), id);
 
 Your naming is odd, no phy anywhere in it?  You rely on the sender 
 to
 never send a duplicate name.id pair?  Why not create your own ids 
 based
 on the number of phys in the system, like almost all other classes 
 and
 subsystems do?
 
 hmm.. some PHY drivers use the id they provide to perform some of 
 their
 internal operation as in [1] (This is used only if a single PHY 
 provider
 implements multiple PHYS). Probably I'll add an option like 
 PLATFORM_DEVID_AUTO
 to give the PHY drivers an option to use auto id.
 
 [1] -
 http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html
 
 No, who cares about the id?  No one outside of the phy core ever 
 should,
 because you pass back the only pointer that they really do care about,
 if they need to do anything with the device.  Use that, and then you 
 can
 
 hmm.. ok.
 
 rip out all of the search for a phy by a string logic, as that's not
 
 Actually this is needed for non-dt boot case. In the case of dt boot, 
 we use a
 phandle by which the controller can get a reference to the phy. But in 
 the case
 of non-dt boot, the controller can get a reference to the phy only by 
 label.
 
 I don't understand.  They registered the phy, and got back a pointer to
 it.  Why can't they save it in their local structure to use it again
 later if needed?  They should never have to ask for the device, as the
 
 One is a *PHY provider* driver which is a driver for some PHY device. 
 This will
 use phy_create to create the phy.
 The other is a *PHY consumer* driver which might be any controller driver 
 (can
 be USB/SATA/PCIE). The PHY consumer will use phy_get to get a reference 
 to the
 phy (by *phandle* in the case of dt boot and *label* in the case of 
 non-dt boot).
 device id might be unknown if there are multiple devices in the system.
 
 I agree with you on the device id part. That need not be known to the PHY 
 driver.
 
 How does a consumer know which label to use in a non-dt system if
 there are multiple PHYs in the system?
 
 That should be passed using platform data.
 
 Ick, don't pass strings around, pass pointers.  If you have platform
 data you can get to, then put the pointer there, don't use a name.
 
 I don't think I understood you here :-s We wont have phy pointer
 when we create the device for the controller no?(it'll be done in
 board file). Probably I'm missing something.

Why will you not have that pointer?  You can't rely on the name as the
device id will not match up, so you should be able to rely on the
pointer being in the structure that the board sets up, right?

Don't use names, especially as ids can, and will, change, that is going
to cause big problems.  Use pointers, this is C, we are supposed to be
doing that :)

thanks,

greg k-h
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-20 Thread Alan Stern
On Sat, 20 Jul 2013, Greg KH wrote:

  That should be passed using platform data.
  
  Ick, don't pass strings around, pass pointers.  If you have platform
  data you can get to, then put the pointer there, don't use a name.
  
  I don't think I understood you here :-s We wont have phy pointer
  when we create the device for the controller no?(it'll be done in
  board file). Probably I'm missing something.
 
 Why will you not have that pointer?  You can't rely on the name as the
 device id will not match up, so you should be able to rely on the
 pointer being in the structure that the board sets up, right?
 
 Don't use names, especially as ids can, and will, change, that is going
 to cause big problems.  Use pointers, this is C, we are supposed to be
 doing that :)

Kishon, I think what Greg means is this:  The name you are using must
be stored somewhere in a data structure constructed by the board file,
right?  Or at least, associated with some data structure somehow.  
Otherwise the platform code wouldn't know which PHY hardware
corresponded to a particular name.

Greg's suggestion is that you store the address of that data structure 
in the platform data instead of storing the name string.  Have the 
consumer pass the data structure's address when it calls phy_create, 
instead of passing the name.  Then you don't have to worry about two 
PHYs accidentally ending up with the same name or any other similar 
problems.

Alan Stern

___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-20 Thread Greg KH
On Sat, Jul 20, 2013 at 10:32:26PM -0400, Alan Stern wrote:
 On Sat, 20 Jul 2013, Greg KH wrote:
 
   That should be passed using platform data.
   
   Ick, don't pass strings around, pass pointers.  If you have platform
   data you can get to, then put the pointer there, don't use a name.
   
   I don't think I understood you here :-s We wont have phy pointer
   when we create the device for the controller no?(it'll be done in
   board file). Probably I'm missing something.
  
  Why will you not have that pointer?  You can't rely on the name as the
  device id will not match up, so you should be able to rely on the
  pointer being in the structure that the board sets up, right?
  
  Don't use names, especially as ids can, and will, change, that is going
  to cause big problems.  Use pointers, this is C, we are supposed to be
  doing that :)
 
 Kishon, I think what Greg means is this:  The name you are using must
 be stored somewhere in a data structure constructed by the board file,
 right?  Or at least, associated with some data structure somehow.  
 Otherwise the platform code wouldn't know which PHY hardware
 corresponded to a particular name.
 
 Greg's suggestion is that you store the address of that data structure 
 in the platform data instead of storing the name string.  Have the 
 consumer pass the data structure's address when it calls phy_create, 
 instead of passing the name.  Then you don't have to worry about two 
 PHYs accidentally ending up with the same name or any other similar 
 problems.

Close, but the issue is that whatever returns from phy_create() should
then be used, no need to call any find functions, as you can just use
the pointer that phy_create() returns.  Much like all other class api
functions in the kernel work.

thanks,

greg k-h
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-19 Thread Greg KH
On Fri, Jul 19, 2013 at 11:25:44AM +0530, Kishon Vijay Abraham I wrote:
 Hi,
 
 On Friday 19 July 2013 11:13 AM, Greg KH wrote:
  On Fri, Jul 19, 2013 at 11:07:10AM +0530, Kishon Vijay Abraham I wrote:
  +  ret = dev_set_name(phy-dev, %s.%d, dev_name(dev), id);
 
  Your naming is odd, no phy anywhere in it?  You rely on the sender to
  never send a duplicate name.id pair?  Why not create your own ids based
  on the number of phys in the system, like almost all other classes and
  subsystems do?
 
  hmm.. some PHY drivers use the id they provide to perform some of their
  internal operation as in [1] (This is used only if a single PHY provider
  implements multiple PHYS). Probably I'll add an option like 
  PLATFORM_DEVID_AUTO
  to give the PHY drivers an option to use auto id.
 
  [1] -
  http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html
 
  No, who cares about the id?  No one outside of the phy core ever should,
  because you pass back the only pointer that they really do care about,
  if they need to do anything with the device.  Use that, and then you can
 
  hmm.. ok.
 
  rip out all of the search for a phy by a string logic, as that's not
 
  Actually this is needed for non-dt boot case. In the case of dt boot, we 
  use a
  phandle by which the controller can get a reference to the phy. But in the 
  case
  of non-dt boot, the controller can get a reference to the phy only by 
  label.
  
  I don't understand.  They registered the phy, and got back a pointer to
  it.  Why can't they save it in their local structure to use it again
  later if needed?  They should never have to ask for the device, as the
 
 One is a *PHY provider* driver which is a driver for some PHY device. This 
 will
 use phy_create to create the phy.
 The other is a *PHY consumer* driver which might be any controller driver (can
 be USB/SATA/PCIE). The PHY consumer will use phy_get to get a reference to the
 phy (by *phandle* in the case of dt boot and *label* in the case of non-dt 
 boot).
  device id might be unknown if there are multiple devices in the system.
 
 I agree with you on the device id part. That need not be known to the PHY 
 driver.

How does a consumer know which label to use in a non-dt system if
there are multiple PHYs in the system?

Do you have any drivers that are non-dt using this yet?

greg k-h
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-19 Thread Kishon Vijay Abraham I
Hi,

On Friday 19 July 2013 11:59 AM, Greg KH wrote:
 On Fri, Jul 19, 2013 at 11:25:44AM +0530, Kishon Vijay Abraham I wrote:
 Hi,

 On Friday 19 July 2013 11:13 AM, Greg KH wrote:
 On Fri, Jul 19, 2013 at 11:07:10AM +0530, Kishon Vijay Abraham I wrote:
 +  ret = dev_set_name(phy-dev, %s.%d, dev_name(dev), id);

 Your naming is odd, no phy anywhere in it?  You rely on the sender to
 never send a duplicate name.id pair?  Why not create your own ids based
 on the number of phys in the system, like almost all other classes and
 subsystems do?

 hmm.. some PHY drivers use the id they provide to perform some of their
 internal operation as in [1] (This is used only if a single PHY provider
 implements multiple PHYS). Probably I'll add an option like 
 PLATFORM_DEVID_AUTO
 to give the PHY drivers an option to use auto id.

 [1] -
 http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html

 No, who cares about the id?  No one outside of the phy core ever should,
 because you pass back the only pointer that they really do care about,
 if they need to do anything with the device.  Use that, and then you can

 hmm.. ok.

 rip out all of the search for a phy by a string logic, as that's not

 Actually this is needed for non-dt boot case. In the case of dt boot, we 
 use a
 phandle by which the controller can get a reference to the phy. But in the 
 case
 of non-dt boot, the controller can get a reference to the phy only by 
 label.

 I don't understand.  They registered the phy, and got back a pointer to
 it.  Why can't they save it in their local structure to use it again
 later if needed?  They should never have to ask for the device, as the

 One is a *PHY provider* driver which is a driver for some PHY device. This 
 will
 use phy_create to create the phy.
 The other is a *PHY consumer* driver which might be any controller driver 
 (can
 be USB/SATA/PCIE). The PHY consumer will use phy_get to get a reference to 
 the
 phy (by *phandle* in the case of dt boot and *label* in the case of non-dt 
 boot).
 device id might be unknown if there are multiple devices in the system.

 I agree with you on the device id part. That need not be known to the PHY 
 driver.
 
 How does a consumer know which label to use in a non-dt system if
 there are multiple PHYs in the system?

That should be passed using platform data.
 
 Do you have any drivers that are non-dt using this yet?

yes. tw4030 (used in OMAP3) supports non-dt.
[PATCH 04/15] ARM: OMAP: USB: Add phy binding information
[PATCH 06/15] usb: musb: omap2430: use the new generic PHY framework
of this patch series shows how it's used.

Thanks
Kishon
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-19 Thread Stephen Warren
On 07/19/2013 12:36 AM, Kishon Vijay Abraham I wrote:
 Hi,
 
 On Friday 19 July 2013 11:59 AM, Greg KH wrote:
 On Fri, Jul 19, 2013 at 11:25:44AM +0530, Kishon Vijay Abraham I wrote:
 Hi,

 On Friday 19 July 2013 11:13 AM, Greg KH wrote:
 On Fri, Jul 19, 2013 at 11:07:10AM +0530, Kishon Vijay Abraham I wrote:
 + ret = dev_set_name(phy-dev, %s.%d, dev_name(dev), id);

 Your naming is odd, no phy anywhere in it?  You rely on the sender to
 never send a duplicate name.id pair?  Why not create your own ids based
 on the number of phys in the system, like almost all other classes and
 subsystems do?

 hmm.. some PHY drivers use the id they provide to perform some of their
 internal operation as in [1] (This is used only if a single PHY provider
 implements multiple PHYS). Probably I'll add an option like 
 PLATFORM_DEVID_AUTO
 to give the PHY drivers an option to use auto id.

 [1] -
 http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html

 No, who cares about the id?  No one outside of the phy core ever should,
 because you pass back the only pointer that they really do care about,
 if they need to do anything with the device.  Use that, and then you can

 hmm.. ok.

 rip out all of the search for a phy by a string logic, as that's not

 Actually this is needed for non-dt boot case. In the case of dt boot, we 
 use a
 phandle by which the controller can get a reference to the phy. But in 
 the case
 of non-dt boot, the controller can get a reference to the phy only by 
 label.

 I don't understand.  They registered the phy, and got back a pointer to
 it.  Why can't they save it in their local structure to use it again
 later if needed?  They should never have to ask for the device, as the

 One is a *PHY provider* driver which is a driver for some PHY device. This 
 will
 use phy_create to create the phy.
 The other is a *PHY consumer* driver which might be any controller driver 
 (can
 be USB/SATA/PCIE). The PHY consumer will use phy_get to get a reference to 
 the
 phy (by *phandle* in the case of dt boot and *label* in the case of non-dt 
 boot).
 device id might be unknown if there are multiple devices in the system.

 I agree with you on the device id part. That need not be known to the PHY 
 driver.

 How does a consumer know which label to use in a non-dt system if
 there are multiple PHYs in the system?
 
 That should be passed using platform data.

I don't think that's right. That's just like passing clock names in
platform data, which I believe is frowned upon.

Instead, why not take the approach that e.g. regulators have taken? Each
driver defines the names of the objects that it requires. There is a
table (registered by a board file) that has lookup key (device name,
regulator name), and the output is the regulator device (or global
regulator name).

This is almost the same way that DT works, except that in DT, the table
is represented as properties in the DT. The DT binding defines the names
of those properties, or the strings that must be in the foo-names
properties, just like a driver in non-DT Linux is going to define the
names it expects to be provided with.

That way, you don't need platform data to define the names.
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-19 Thread Greg KH
On Fri, Jul 19, 2013 at 12:06:01PM +0530, Kishon Vijay Abraham I wrote:
 Hi,
 
 On Friday 19 July 2013 11:59 AM, Greg KH wrote:
  On Fri, Jul 19, 2013 at 11:25:44AM +0530, Kishon Vijay Abraham I wrote:
  Hi,
 
  On Friday 19 July 2013 11:13 AM, Greg KH wrote:
  On Fri, Jul 19, 2013 at 11:07:10AM +0530, Kishon Vijay Abraham I wrote:
  +ret = dev_set_name(phy-dev, %s.%d, dev_name(dev), id);
 
  Your naming is odd, no phy anywhere in it?  You rely on the sender 
  to
  never send a duplicate name.id pair?  Why not create your own ids 
  based
  on the number of phys in the system, like almost all other classes and
  subsystems do?
 
  hmm.. some PHY drivers use the id they provide to perform some of their
  internal operation as in [1] (This is used only if a single PHY 
  provider
  implements multiple PHYS). Probably I'll add an option like 
  PLATFORM_DEVID_AUTO
  to give the PHY drivers an option to use auto id.
 
  [1] -
  http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html
 
  No, who cares about the id?  No one outside of the phy core ever should,
  because you pass back the only pointer that they really do care about,
  if they need to do anything with the device.  Use that, and then you can
 
  hmm.. ok.
 
  rip out all of the search for a phy by a string logic, as that's not
 
  Actually this is needed for non-dt boot case. In the case of dt boot, we 
  use a
  phandle by which the controller can get a reference to the phy. But in 
  the case
  of non-dt boot, the controller can get a reference to the phy only by 
  label.
 
  I don't understand.  They registered the phy, and got back a pointer to
  it.  Why can't they save it in their local structure to use it again
  later if needed?  They should never have to ask for the device, as the
 
  One is a *PHY provider* driver which is a driver for some PHY device. This 
  will
  use phy_create to create the phy.
  The other is a *PHY consumer* driver which might be any controller driver 
  (can
  be USB/SATA/PCIE). The PHY consumer will use phy_get to get a reference to 
  the
  phy (by *phandle* in the case of dt boot and *label* in the case of non-dt 
  boot).
  device id might be unknown if there are multiple devices in the system.
 
  I agree with you on the device id part. That need not be known to the PHY 
  driver.
  
  How does a consumer know which label to use in a non-dt system if
  there are multiple PHYs in the system?
 
 That should be passed using platform data.

Ick, don't pass strings around, pass pointers.  If you have platform
data you can get to, then put the pointer there, don't use a name.

thanks,

greg k-h
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-19 Thread Kishon Vijay Abraham I

Hi,

On Friday 19 July 2013 09:24 PM, Stephen Warren wrote:

On 07/19/2013 12:36 AM, Kishon Vijay Abraham I wrote:

Hi,

On Friday 19 July 2013 11:59 AM, Greg KH wrote:

On Fri, Jul 19, 2013 at 11:25:44AM +0530, Kishon Vijay Abraham I wrote:

Hi,

On Friday 19 July 2013 11:13 AM, Greg KH wrote:

On Fri, Jul 19, 2013 at 11:07:10AM +0530, Kishon Vijay Abraham I wrote:

+   ret = dev_set_name(phy-dev, %s.%d, dev_name(dev), id);


Your naming is odd, no phy anywhere in it?  You rely on the sender to
never send a duplicate name.id pair?  Why not create your own ids based
on the number of phys in the system, like almost all other classes and
subsystems do?


hmm.. some PHY drivers use the id they provide to perform some of their
internal operation as in [1] (This is used only if a single PHY provider
implements multiple PHYS). Probably I'll add an option like PLATFORM_DEVID_AUTO
to give the PHY drivers an option to use auto id.

[1] -
http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html


No, who cares about the id?  No one outside of the phy core ever should,
because you pass back the only pointer that they really do care about,
if they need to do anything with the device.  Use that, and then you can


hmm.. ok.


rip out all of the search for a phy by a string logic, as that's not


Actually this is needed for non-dt boot case. In the case of dt boot, we use a
phandle by which the controller can get a reference to the phy. But in the case
of non-dt boot, the controller can get a reference to the phy only by label.


I don't understand.  They registered the phy, and got back a pointer to
it.  Why can't they save it in their local structure to use it again
later if needed?  They should never have to ask for the device, as the


One is a *PHY provider* driver which is a driver for some PHY device. This will
use phy_create to create the phy.
The other is a *PHY consumer* driver which might be any controller driver (can
be USB/SATA/PCIE). The PHY consumer will use phy_get to get a reference to the
phy (by *phandle* in the case of dt boot and *label* in the case of non-dt 
boot).

device id might be unknown if there are multiple devices in the system.


I agree with you on the device id part. That need not be known to the PHY 
driver.


How does a consumer know which label to use in a non-dt system if
there are multiple PHYs in the system?


That should be passed using platform data.


I don't think that's right. That's just like passing clock names in
platform data, which I believe is frowned upon.

Instead, why not take the approach that e.g. regulators have taken? Each
driver defines the names of the objects that it requires. There is a
table (registered by a board file) that has lookup key (device name,


We were using a similar approach with USB PHY layer but things started 
breaking after the device names are created using PLATFORM_DEVID_AUTO. 
Now theres no way to reliably know the device names in advance.
Btw I had such device name binding in my v3 of this patch series [1] and 
had some discussion with Grant during that time [2].


[1] - 
http://archive.arm.linux.org.uk/lurker/message/20130320.091200.721a6fb5.hu.html

[2] - https://lkml.org/lkml/2013/4/22/26

Thanks
Kishon
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-19 Thread Kishon Vijay Abraham I

Hi,

On Saturday 20 July 2013 05:20 AM, Greg KH wrote:

On Fri, Jul 19, 2013 at 12:06:01PM +0530, Kishon Vijay Abraham I wrote:

Hi,

On Friday 19 July 2013 11:59 AM, Greg KH wrote:

On Fri, Jul 19, 2013 at 11:25:44AM +0530, Kishon Vijay Abraham I wrote:

Hi,

On Friday 19 July 2013 11:13 AM, Greg KH wrote:

On Fri, Jul 19, 2013 at 11:07:10AM +0530, Kishon Vijay Abraham I wrote:

+   ret = dev_set_name(phy-dev, %s.%d, dev_name(dev), id);


Your naming is odd, no phy anywhere in it?  You rely on the sender to
never send a duplicate name.id pair?  Why not create your own ids based
on the number of phys in the system, like almost all other classes and
subsystems do?


hmm.. some PHY drivers use the id they provide to perform some of their
internal operation as in [1] (This is used only if a single PHY provider
implements multiple PHYS). Probably I'll add an option like PLATFORM_DEVID_AUTO
to give the PHY drivers an option to use auto id.

[1] -
http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html


No, who cares about the id?  No one outside of the phy core ever should,
because you pass back the only pointer that they really do care about,
if they need to do anything with the device.  Use that, and then you can


hmm.. ok.


rip out all of the search for a phy by a string logic, as that's not


Actually this is needed for non-dt boot case. In the case of dt boot, we use a
phandle by which the controller can get a reference to the phy. But in the case
of non-dt boot, the controller can get a reference to the phy only by label.


I don't understand.  They registered the phy, and got back a pointer to
it.  Why can't they save it in their local structure to use it again
later if needed?  They should never have to ask for the device, as the


One is a *PHY provider* driver which is a driver for some PHY device. This will
use phy_create to create the phy.
The other is a *PHY consumer* driver which might be any controller driver (can
be USB/SATA/PCIE). The PHY consumer will use phy_get to get a reference to the
phy (by *phandle* in the case of dt boot and *label* in the case of non-dt 
boot).

device id might be unknown if there are multiple devices in the system.


I agree with you on the device id part. That need not be known to the PHY 
driver.


How does a consumer know which label to use in a non-dt system if
there are multiple PHYs in the system?


That should be passed using platform data.


Ick, don't pass strings around, pass pointers.  If you have platform
data you can get to, then put the pointer there, don't use a name.


I don't think I understood you here :-s We wont have phy pointer when we 
create the device for the controller no?(it'll be done in board file). 
Probably I'm missing something.


Thanks
Kishon
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-18 Thread Greg KH
On Thu, Jul 18, 2013 at 12:16:10PM +0530, Kishon Vijay Abraham I wrote:
 +struct phy_provider *__of_phy_provider_register(struct device *dev,
 + struct module *owner, struct phy * (*of_xlate)(struct device *dev,
 + struct of_phandle_args *args));
 +struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
 + struct module *owner, struct phy * (*of_xlate)(struct device *dev,
 + struct of_phandle_args *args))
 +
 +__of_phy_provider_register and __devm_of_phy_provider_register can be used to
 +register the phy_provider and it takes device, owner and of_xlate as
 +arguments. For the dt boot case, all PHY providers should use one of the 
 above
 +2 APIs to register the PHY provider.

Why do you have __ for the prefix of a public function?  Is that really
the way that OF handles this type of thing?

 --- /dev/null
 +++ b/drivers/phy/Kconfig
 @@ -0,0 +1,13 @@
 +#
 +# PHY
 +#
 +
 +menuconfig GENERIC_PHY
 + tristate PHY Subsystem
 + help
 +   Generic PHY support.
 +
 +   This framework is designed to provide a generic interface for PHY
 +   devices present in the kernel. This layer will have the generic
 +   API by which phy drivers can create PHY using the phy framework and
 +   phy users can obtain reference to the PHY.

Again, please reverse this.  The drivers that use it should select it,
not depend on it, which will then enable this option.  I will never know
if I need to enable it, and based on your follow-on patches, if I don't,
drivers that were working just fine, now disappeared from my build,
which isn't nice, and a pain to notice and fix up.

 +/**
 + * phy_create() - create a new phy
 + * @dev: device that is creating the new phy
 + * @id: id of the phy
 + * @ops: function pointers for performing phy operations
 + * @label: label given to the phy
 + *
 + * Called to create a phy using phy framework.
 + */
 +struct phy *phy_create(struct device *dev, u8 id, const struct phy_ops *ops,
 + const char *label)
 +{
 + int ret;
 + struct phy *phy;
 +
 + if (!dev) {
 + dev_WARN(dev, no device provided for PHY\n);
 + ret = -EINVAL;
 + goto err0;
 + }
 +
 + phy = kzalloc(sizeof(*phy), GFP_KERNEL);
 + if (!phy) {
 + ret = -ENOMEM;
 + goto err0;
 + }
 +
 + device_initialize(phy-dev);
 + mutex_init(phy-mutex);
 +
 + phy-dev.class = phy_class;
 + phy-dev.parent = dev;
 + phy-dev.of_node = dev-of_node;
 + phy-id = id;
 + phy-ops = ops;
 + phy-label = kstrdup(label, GFP_KERNEL);
 +
 + ret = dev_set_name(phy-dev, %s.%d, dev_name(dev), id);

Your naming is odd, no phy anywhere in it?  You rely on the sender to
never send a duplicate name.id pair?  Why not create your own ids based
on the number of phys in the system, like almost all other classes and
subsystems do?

 +static inline int phy_pm_runtime_get(struct phy *phy)
 +{
 + if (WARN(IS_ERR(phy), Invalid PHY reference\n))
 + return -EINVAL;

Why would phy ever not be valid and a error pointer?  And why dump the
stack if that happens, that seems really extreme.

 +
 + if (!pm_runtime_enabled(phy-dev))
 + return -ENOTSUPP;
 +
 + return pm_runtime_get(phy-dev);
 +}

This, and the other inline functions in this .h file seem huge, why are
they inline and not in the .c file?  There's no speed issues, and it
should save space overall in the .c file.  Please move them.


 +static inline int phy_init(struct phy *phy)
 +{
 + int ret;
 +
 + ret = phy_pm_runtime_get_sync(phy);
 + if (ret  0  ret != -ENOTSUPP)
 + return ret;
 +
 + mutex_lock(phy-mutex);
 + if (phy-init_count++ == 0  phy-ops-init) {
 + ret = phy-ops-init(phy);
 + if (ret  0) {
 + dev_err(phy-dev, phy init failed -- %d\n, ret);
 + goto out;
 + }
 + }
 +
 +out:
 + mutex_unlock(phy-mutex);
 + phy_pm_runtime_put(phy);
 + return ret;
 +}
 +
 +static inline int phy_exit(struct phy *phy)
 +{
 + int ret;
 +
 + ret = phy_pm_runtime_get_sync(phy);
 + if (ret  0  ret != -ENOTSUPP)
 + return ret;
 +
 + mutex_lock(phy-mutex);
 + if (--phy-init_count == 0  phy-ops-exit) {
 + ret = phy-ops-exit(phy);
 + if (ret  0) {
 + dev_err(phy-dev, phy exit failed -- %d\n, ret);
 + goto out;
 + }
 + }
 +
 +out:
 + mutex_unlock(phy-mutex);
 + phy_pm_runtime_put(phy);
 + return ret;
 +}
 +
 +static inline int phy_power_on(struct phy *phy)
 +{
 + int ret = -ENOTSUPP;
 +
 + ret = phy_pm_runtime_get_sync(phy);
 + if (ret  0  ret != -ENOTSUPP)
 + return ret;
 +
 + mutex_lock(phy-mutex);
 + if (phy-power_count++ == 0  phy-ops-power_on) {
 + ret = phy-ops-power_on(phy);
 + if (ret  0) {
 + dev_err(phy-dev, phy 

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-18 Thread Kishon Vijay Abraham I
Hi,

On Thursday 18 July 2013 12:50 PM, Greg KH wrote:
 On Thu, Jul 18, 2013 at 12:16:10PM +0530, Kishon Vijay Abraham I wrote:
 +struct phy_provider *__of_phy_provider_register(struct device *dev,
 +struct module *owner, struct phy * (*of_xlate)(struct device *dev,
 +struct of_phandle_args *args));
 +struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
 +struct module *owner, struct phy * (*of_xlate)(struct device *dev,
 +struct of_phandle_args *args))
 +
 +__of_phy_provider_register and __devm_of_phy_provider_register can be used 
 to
 +register the phy_provider and it takes device, owner and of_xlate as
 +arguments. For the dt boot case, all PHY providers should use one of the 
 above
 +2 APIs to register the PHY provider.
 
 Why do you have __ for the prefix of a public function?  Is that really
 the way that OF handles this type of thing?

I have a macro of_phy_provider_register/devm_of_phy_provider_register that
calls these functions and should be used by the PHY drivers. Probably I should
make a mention of it in the Documentation.
 
 --- /dev/null
 +++ b/drivers/phy/Kconfig
 @@ -0,0 +1,13 @@
 +#
 +# PHY
 +#
 +
 +menuconfig GENERIC_PHY
 +tristate PHY Subsystem
 +help
 +  Generic PHY support.
 +
 +  This framework is designed to provide a generic interface for PHY
 +  devices present in the kernel. This layer will have the generic
 +  API by which phy drivers can create PHY using the phy framework and
 +  phy users can obtain reference to the PHY.
 
 Again, please reverse this.  The drivers that use it should select it,
 not depend on it, which will then enable this option.  I will never know
 if I need to enable it, and based on your follow-on patches, if I don't,
 drivers that were working just fine, now disappeared from my build,
 which isn't nice, and a pain to notice and fix up.

ok.
 
 +/**
 + * phy_create() - create a new phy
 + * @dev: device that is creating the new phy
 + * @id: id of the phy
 + * @ops: function pointers for performing phy operations
 + * @label: label given to the phy
 + *
 + * Called to create a phy using phy framework.
 + */
 +struct phy *phy_create(struct device *dev, u8 id, const struct phy_ops *ops,
 +const char *label)
 +{
 +int ret;
 +struct phy *phy;
 +
 +if (!dev) {
 +dev_WARN(dev, no device provided for PHY\n);
 +ret = -EINVAL;
 +goto err0;
 +}
 +
 +phy = kzalloc(sizeof(*phy), GFP_KERNEL);
 +if (!phy) {
 +ret = -ENOMEM;
 +goto err0;
 +}
 +
 +device_initialize(phy-dev);
 +mutex_init(phy-mutex);
 +
 +phy-dev.class = phy_class;
 +phy-dev.parent = dev;
 +phy-dev.of_node = dev-of_node;
 +phy-id = id;
 +phy-ops = ops;
 +phy-label = kstrdup(label, GFP_KERNEL);
 +
 +ret = dev_set_name(phy-dev, %s.%d, dev_name(dev), id);
 
 Your naming is odd, no phy anywhere in it?  You rely on the sender to
 never send a duplicate name.id pair?  Why not create your own ids based
 on the number of phys in the system, like almost all other classes and
 subsystems do?

hmm.. some PHY drivers use the id they provide to perform some of their
internal operation as in [1] (This is used only if a single PHY provider
implements multiple PHYS). Probably I'll add an option like PLATFORM_DEVID_AUTO
to give the PHY drivers an option to use auto id.

[1] -
http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html
 
 +static inline int phy_pm_runtime_get(struct phy *phy)
 +{
 +if (WARN(IS_ERR(phy), Invalid PHY reference\n))
 +return -EINVAL;
 
 Why would phy ever not be valid and a error pointer?  And why dump the
 stack if that happens, that seems really extreme.

hmm.. there might be cases where the same controller in one soc needs PHY
control and in some other soc does not need PHY control. In such cases, we
might get error pointer here.
I'll change WARN to dev_err.
 
 +
 +if (!pm_runtime_enabled(phy-dev))
 +return -ENOTSUPP;
 +
 +return pm_runtime_get(phy-dev);
 +}
 
 This, and the other inline functions in this .h file seem huge, why are
 they inline and not in the .c file?  There's no speed issues, and it
 should save space overall in the .c file.  Please move them.

ok
 
 
 +static inline int phy_init(struct phy *phy)
 +{
 +int ret;
 +
 +ret = phy_pm_runtime_get_sync(phy);
 +if (ret  0  ret != -ENOTSUPP)
 +return ret;
 +
 +mutex_lock(phy-mutex);
 +if (phy-init_count++ == 0  phy-ops-init) {
 +ret = phy-ops-init(phy);
 +if (ret  0) {
 +dev_err(phy-dev, phy init failed -- %d\n, ret);
 +goto out;
 +}
 +}
 +
 +out:
 +mutex_unlock(phy-mutex);
 +phy_pm_runtime_put(phy);
 +return ret;
 +}
 +
 +static inline int phy_exit(struct phy *phy)
 +{
 +int ret;
 +
 +ret = phy_pm_runtime_get_sync(phy);
 +if (ret  0  ret != -ENOTSUPP)
 

Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-18 Thread Greg KH
On Thu, Jul 18, 2013 at 02:29:52PM +0530, Kishon Vijay Abraham I wrote:
 Hi,
 
 On Thursday 18 July 2013 12:50 PM, Greg KH wrote:
  On Thu, Jul 18, 2013 at 12:16:10PM +0530, Kishon Vijay Abraham I wrote:
  +struct phy_provider *__of_phy_provider_register(struct device *dev,
  +  struct module *owner, struct phy * (*of_xlate)(struct device *dev,
  +  struct of_phandle_args *args));
  +struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
  +  struct module *owner, struct phy * (*of_xlate)(struct device *dev,
  +  struct of_phandle_args *args))
  +
  +__of_phy_provider_register and __devm_of_phy_provider_register can be 
  used to
  +register the phy_provider and it takes device, owner and of_xlate as
  +arguments. For the dt boot case, all PHY providers should use one of the 
  above
  +2 APIs to register the PHY provider.
  
  Why do you have __ for the prefix of a public function?  Is that really
  the way that OF handles this type of thing?
 
 I have a macro of_phy_provider_register/devm_of_phy_provider_register that
 calls these functions and should be used by the PHY drivers. Probably I should
 make a mention of it in the Documentation.

Yes, mention those as you never want to be calling __* functions
directly, right?

  +  ret = dev_set_name(phy-dev, %s.%d, dev_name(dev), id);
  
  Your naming is odd, no phy anywhere in it?  You rely on the sender to
  never send a duplicate name.id pair?  Why not create your own ids based
  on the number of phys in the system, like almost all other classes and
  subsystems do?
 
 hmm.. some PHY drivers use the id they provide to perform some of their
 internal operation as in [1] (This is used only if a single PHY provider
 implements multiple PHYS). Probably I'll add an option like 
 PLATFORM_DEVID_AUTO
 to give the PHY drivers an option to use auto id.
 
 [1] -
 http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html

No, who cares about the id?  No one outside of the phy core ever should,
because you pass back the only pointer that they really do care about,
if they need to do anything with the device.  Use that, and then you can
rip out all of the search for a phy by a string logic, as that's not
needed either.  Just stick to the pointer, it's easier, and safer that
way.

  +static inline int phy_pm_runtime_get(struct phy *phy)
  +{
  +  if (WARN(IS_ERR(phy), Invalid PHY reference\n))
  +  return -EINVAL;
  
  Why would phy ever not be valid and a error pointer?  And why dump the
  stack if that happens, that seems really extreme.
 
 hmm.. there might be cases where the same controller in one soc needs PHY
 control and in some other soc does not need PHY control. In such cases, we
 might get error pointer here.
 I'll change WARN to dev_err.

I still don't understand.  You have control over the code that calls
these functions, just ensure that they pass in a valid pointer, it's
that simple.  Or am I missing something?

thanks,

greg k-h
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-18 Thread Kishon Vijay Abraham I
Hi,

On Thursday 18 July 2013 09:19 PM, Greg KH wrote:
 On Thu, Jul 18, 2013 at 02:29:52PM +0530, Kishon Vijay Abraham I wrote:
 Hi,

 On Thursday 18 July 2013 12:50 PM, Greg KH wrote:
 On Thu, Jul 18, 2013 at 12:16:10PM +0530, Kishon Vijay Abraham I wrote:
 +struct phy_provider *__of_phy_provider_register(struct device *dev,
 +  struct module *owner, struct phy * (*of_xlate)(struct device *dev,
 +  struct of_phandle_args *args));
 +struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
 +  struct module *owner, struct phy * (*of_xlate)(struct device *dev,
 +  struct of_phandle_args *args))
 +
 +__of_phy_provider_register and __devm_of_phy_provider_register can be 
 used to
 +register the phy_provider and it takes device, owner and of_xlate as
 +arguments. For the dt boot case, all PHY providers should use one of the 
 above
 +2 APIs to register the PHY provider.

 Why do you have __ for the prefix of a public function?  Is that really
 the way that OF handles this type of thing?

 I have a macro of_phy_provider_register/devm_of_phy_provider_register that
 calls these functions and should be used by the PHY drivers. Probably I 
 should
 make a mention of it in the Documentation.
 
 Yes, mention those as you never want to be calling __* functions
 directly, right?

correct.
 
 +  ret = dev_set_name(phy-dev, %s.%d, dev_name(dev), id);

 Your naming is odd, no phy anywhere in it?  You rely on the sender to
 never send a duplicate name.id pair?  Why not create your own ids based
 on the number of phys in the system, like almost all other classes and
 subsystems do?

 hmm.. some PHY drivers use the id they provide to perform some of their
 internal operation as in [1] (This is used only if a single PHY provider
 implements multiple PHYS). Probably I'll add an option like 
 PLATFORM_DEVID_AUTO
 to give the PHY drivers an option to use auto id.

 [1] -
 http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html
 
 No, who cares about the id?  No one outside of the phy core ever should,
 because you pass back the only pointer that they really do care about,
 if they need to do anything with the device.  Use that, and then you can

hmm.. ok.

 rip out all of the search for a phy by a string logic, as that's not

Actually this is needed for non-dt boot case. In the case of dt boot, we use a
phandle by which the controller can get a reference to the phy. But in the case
of non-dt boot, the controller can get a reference to the phy only by label.
 needed either.  Just stick to the pointer, it's easier, and safer that
 way.
 
 +static inline int phy_pm_runtime_get(struct phy *phy)
 +{
 +  if (WARN(IS_ERR(phy), Invalid PHY reference\n))
 +  return -EINVAL;

 Why would phy ever not be valid and a error pointer?  And why dump the
 stack if that happens, that seems really extreme.

 hmm.. there might be cases where the same controller in one soc needs PHY
 control and in some other soc does not need PHY control. In such cases, we
 might get error pointer here.
 I'll change WARN to dev_err.
 
 I still don't understand.  You have control over the code that calls
 these functions, just ensure that they pass in a valid pointer, it's
 that simple.  Or am I missing something?

You are right. Valid pointer check can be done in controller code as well.

Thanks
Kishon
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-18 Thread Greg KH
On Fri, Jul 19, 2013 at 11:07:10AM +0530, Kishon Vijay Abraham I wrote:
  +ret = dev_set_name(phy-dev, %s.%d, dev_name(dev), id);
 
  Your naming is odd, no phy anywhere in it?  You rely on the sender to
  never send a duplicate name.id pair?  Why not create your own ids based
  on the number of phys in the system, like almost all other classes and
  subsystems do?
 
  hmm.. some PHY drivers use the id they provide to perform some of their
  internal operation as in [1] (This is used only if a single PHY provider
  implements multiple PHYS). Probably I'll add an option like 
  PLATFORM_DEVID_AUTO
  to give the PHY drivers an option to use auto id.
 
  [1] -
  http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html
  
  No, who cares about the id?  No one outside of the phy core ever should,
  because you pass back the only pointer that they really do care about,
  if they need to do anything with the device.  Use that, and then you can
 
 hmm.. ok.
 
  rip out all of the search for a phy by a string logic, as that's not
 
 Actually this is needed for non-dt boot case. In the case of dt boot, we use a
 phandle by which the controller can get a reference to the phy. But in the 
 case
 of non-dt boot, the controller can get a reference to the phy only by label.

I don't understand.  They registered the phy, and got back a pointer to
it.  Why can't they save it in their local structure to use it again
later if needed?  They should never have to ask for the device, as the
device id might be unknown if there are multiple devices in the system.

Or am I missing something?

thanks,

greg k-h
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


Re: [PATCH 01/15] drivers: phy: add generic PHY framework

2013-07-18 Thread Kishon Vijay Abraham I
Hi,

On Friday 19 July 2013 11:13 AM, Greg KH wrote:
 On Fri, Jul 19, 2013 at 11:07:10AM +0530, Kishon Vijay Abraham I wrote:
 +ret = dev_set_name(phy-dev, %s.%d, dev_name(dev), id);

 Your naming is odd, no phy anywhere in it?  You rely on the sender to
 never send a duplicate name.id pair?  Why not create your own ids based
 on the number of phys in the system, like almost all other classes and
 subsystems do?

 hmm.. some PHY drivers use the id they provide to perform some of their
 internal operation as in [1] (This is used only if a single PHY provider
 implements multiple PHYS). Probably I'll add an option like 
 PLATFORM_DEVID_AUTO
 to give the PHY drivers an option to use auto id.

 [1] -
 http://archive.arm.linux.org.uk/lurker/message/20130628.134308.4a8f7668.ca.html

 No, who cares about the id?  No one outside of the phy core ever should,
 because you pass back the only pointer that they really do care about,
 if they need to do anything with the device.  Use that, and then you can

 hmm.. ok.

 rip out all of the search for a phy by a string logic, as that's not

 Actually this is needed for non-dt boot case. In the case of dt boot, we use 
 a
 phandle by which the controller can get a reference to the phy. But in the 
 case
 of non-dt boot, the controller can get a reference to the phy only by label.
 
 I don't understand.  They registered the phy, and got back a pointer to
 it.  Why can't they save it in their local structure to use it again
 later if needed?  They should never have to ask for the device, as the

One is a *PHY provider* driver which is a driver for some PHY device. This will
use phy_create to create the phy.
The other is a *PHY consumer* driver which might be any controller driver (can
be USB/SATA/PCIE). The PHY consumer will use phy_get to get a reference to the
phy (by *phandle* in the case of dt boot and *label* in the case of non-dt 
boot).
 device id might be unknown if there are multiple devices in the system.

I agree with you on the device id part. That need not be known to the PHY 
driver.

Thanks
Kishon
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss