Re: [RESEND PATCH v10 1/8] drivers: phy: add generic PHY framework

2013-08-01 Thread Greg KH
On Fri, Jul 26, 2013 at 06:19:16PM +0530, Kishon Vijay Abraham I wrote:
> +static int phy_get_id(void)
> +{
> + int ret;
> + int id;
> +
> + ret = ida_pre_get(&phy_ida, GFP_KERNEL);
> + if (!ret)
> + return -ENOMEM;
> +
> + ret = ida_get_new(&phy_ida, &id);
> + if (ret < 0)
> + return ret;
> +
> + return id;
> +}

ida_simple_get() instead?  And if you do that, you can get rid of this
function entirely.

thanks,

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


Re: [RESEND PATCH v10 1/8] drivers: phy: add generic PHY framework

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

On Monday 29 July 2013 09:21 PM, Sylwester Nawrocki wrote:
> On 07/26/2013 02:49 PM, Kishon Vijay Abraham I wrote:
>> The PHY framework provides a set of APIs for the PHY drivers to
>> create/destroy a PHY and APIs for the PHY users to obtain a reference to the
>> PHY with or without using phandle. For dt-boot, the PHY drivers should
>> also register *PHY provider* with the framework.
>>
>> PHY drivers should create the PHY by passing id and ops like init, exit,
>> power_on and power_off. This framework is also pm runtime enabled.
>>
>> The documentation for the generic PHY framework is added in
>> Documentation/phy.txt and the documentation for dt binding can be found at
>> Documentation/devicetree/bindings/phy/phy-bindings.txt
>>
>> Cc: Tomasz Figa 
>> Cc: Greg Kroah-Hartman 
>> Signed-off-by: Kishon Vijay Abraham I 
>> Acked-by: Felipe Balbi 
>> Tested-by: Sylwester Nawrocki 
>> ---
>>  .../devicetree/bindings/phy/phy-bindings.txt   |   66 ++
>>  Documentation/phy.txt  |  166 +
>>  MAINTAINERS|8 +
>>  drivers/Kconfig|2 +
>>  drivers/Makefile   |2 +
>>  drivers/phy/Kconfig|   18 +
>>  drivers/phy/Makefile   |5 +
>>  drivers/phy/phy-core.c |  714 
>> 
>>  include/linux/phy/phy.h|  270 
>>  9 files changed, 1251 insertions(+)
>>  create mode 100644 Documentation/devicetree/bindings/phy/phy-bindings.txt
>>  create mode 100644 Documentation/phy.txt
>>  create mode 100644 drivers/phy/Kconfig
>>  create mode 100644 drivers/phy/Makefile
>>  create mode 100644 drivers/phy/phy-core.c
>>  create mode 100644 include/linux/phy/phy.h
>>
>> diff --git a/Documentation/devicetree/bindings/phy/phy-bindings.txt 
>> b/Documentation/devicetree/bindings/phy/phy-bindings.txt
>> new file mode 100644
>> index 000..8ae844f
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/phy/phy-bindings.txt
>> @@ -0,0 +1,66 @@
>> +This document explains only the device tree data binding. For general
>> +information about PHY subsystem refer to Documentation/phy.txt
> [...]
>> @@ -0,0 +1,166 @@
>> +PHY SUBSYSTEM
>> +  Kishon Vijay Abraham I 
>> +
>> +This document explains the Generic PHY Framework along with the APIs 
>> provided,
>> +and how-to-use.
>> +
>> +1. Introduction
>> +
>> +*PHY* is the abbreviation for physical layer. It is used to connect a device
>> +to the physical medium e.g., the USB controller has a PHY to provide 
>> functions
>> +such as serialization, de-serialization, encoding, decoding and is 
>> responsible
>> +for obtaining the required data transmission rate. Note that some USB
>> +controllers have PHY functionality embedded into it and others use an 
>> external
>> +PHY. Other peripherals that use PHY include Wireless LAN, Ethernet,
>> +SATA etc.
>> +
>> +The intention of creating this framework is to bring the PHY drivers spread
>> +all over the Linux kernel to drivers/phy to increase code re-use and for
>> +better code maintainability.
>> +
>> +This framework will be of use only to devices that use external PHY (PHY
>> +functionality is not embedded within the controller).
>> +
>> +2. Registering/Unregistering the PHY provider
>> +
>> +PHY provider refers to an entity that implements one or more PHY instances.
>> +For the simple case where the PHY provider implements only a single 
>> instance of
>> +the PHY, the framework provides its own implementation of of_xlate in
>> +of_phy_simple_xlate. If the PHY provider implements multiple instances, it
>> +should provide its own implementation of of_xlate. of_xlate is used only for
>> +dt boot case.
>> +
>> +#define of_phy_provider_register(dev, xlate)\
>> +__of_phy_provider_register((dev), THIS_MODULE, (xlate))
>> +
>> +#define devm_of_phy_provider_register(dev, xlate)   \
>> +__of_phy_provider_register((dev), THIS_MODULE, (xlate))
> 
> This needs to be:
> 
>   __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate))
> 
> as Kamil pointed out. We've tested it here with v9 and it makes
> Bad Things happen. ;)
> 
>> +of_phy_provider_register and devm_of_phy_provider_register macros can be 
>> used to
>> +register the phy_provider and it takes device and of_xlate as
>> +arguments. For the dt boot case, all PHY providers should use one of the 
>> above
>> +2 macros to register the PHY provider.
>> +
>> +void devm_of_phy_provider_unregister(struct device *dev,
>> +struct phy_provider *phy_provider);
>> +void of_phy_provider_unregister(struct phy_provider *phy_provider);
>> +
>> +devm_of_phy_provider_unregister and of_phy_provider_unregister can be used 
>> to
>> +unregister the PHY.
>> +
> [...]
>> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
>> new file mode 100644
>> ind

Re: [RESEND PATCH v10 1/8] drivers: phy: add generic PHY framework

2013-07-29 Thread Sylwester Nawrocki
On 07/26/2013 02:49 PM, Kishon Vijay Abraham I wrote:
> The PHY framework provides a set of APIs for the PHY drivers to
> create/destroy a PHY and APIs for the PHY users to obtain a reference to the
> PHY with or without using phandle. For dt-boot, the PHY drivers should
> also register *PHY provider* with the framework.
> 
> PHY drivers should create the PHY by passing id and ops like init, exit,
> power_on and power_off. This framework is also pm runtime enabled.
> 
> The documentation for the generic PHY framework is added in
> Documentation/phy.txt and the documentation for dt binding can be found at
> Documentation/devicetree/bindings/phy/phy-bindings.txt
> 
> Cc: Tomasz Figa 
> Cc: Greg Kroah-Hartman 
> Signed-off-by: Kishon Vijay Abraham I 
> Acked-by: Felipe Balbi 
> Tested-by: Sylwester Nawrocki 
> ---
>  .../devicetree/bindings/phy/phy-bindings.txt   |   66 ++
>  Documentation/phy.txt  |  166 +
>  MAINTAINERS|8 +
>  drivers/Kconfig|2 +
>  drivers/Makefile   |2 +
>  drivers/phy/Kconfig|   18 +
>  drivers/phy/Makefile   |5 +
>  drivers/phy/phy-core.c |  714 
> 
>  include/linux/phy/phy.h|  270 
>  9 files changed, 1251 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/phy/phy-bindings.txt
>  create mode 100644 Documentation/phy.txt
>  create mode 100644 drivers/phy/Kconfig
>  create mode 100644 drivers/phy/Makefile
>  create mode 100644 drivers/phy/phy-core.c
>  create mode 100644 include/linux/phy/phy.h
> 
> diff --git a/Documentation/devicetree/bindings/phy/phy-bindings.txt 
> b/Documentation/devicetree/bindings/phy/phy-bindings.txt
> new file mode 100644
> index 000..8ae844f
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/phy/phy-bindings.txt
> @@ -0,0 +1,66 @@
> +This document explains only the device tree data binding. For general
> +information about PHY subsystem refer to Documentation/phy.txt
[...]
> @@ -0,0 +1,166 @@
> + PHY SUBSYSTEM
> +   Kishon Vijay Abraham I 
> +
> +This document explains the Generic PHY Framework along with the APIs 
> provided,
> +and how-to-use.
> +
> +1. Introduction
> +
> +*PHY* is the abbreviation for physical layer. It is used to connect a device
> +to the physical medium e.g., the USB controller has a PHY to provide 
> functions
> +such as serialization, de-serialization, encoding, decoding and is 
> responsible
> +for obtaining the required data transmission rate. Note that some USB
> +controllers have PHY functionality embedded into it and others use an 
> external
> +PHY. Other peripherals that use PHY include Wireless LAN, Ethernet,
> +SATA etc.
> +
> +The intention of creating this framework is to bring the PHY drivers spread
> +all over the Linux kernel to drivers/phy to increase code re-use and for
> +better code maintainability.
> +
> +This framework will be of use only to devices that use external PHY (PHY
> +functionality is not embedded within the controller).
> +
> +2. Registering/Unregistering the PHY provider
> +
> +PHY provider refers to an entity that implements one or more PHY instances.
> +For the simple case where the PHY provider implements only a single instance 
> of
> +the PHY, the framework provides its own implementation of of_xlate in
> +of_phy_simple_xlate. If the PHY provider implements multiple instances, it
> +should provide its own implementation of of_xlate. of_xlate is used only for
> +dt boot case.
> +
> +#define of_phy_provider_register(dev, xlate)\
> +__of_phy_provider_register((dev), THIS_MODULE, (xlate))
> +
> +#define devm_of_phy_provider_register(dev, xlate)   \
> +__of_phy_provider_register((dev), THIS_MODULE, (xlate))

This needs to be:

__devm_of_phy_provider_register((dev), THIS_MODULE, (xlate))

as Kamil pointed out. We've tested it here with v9 and it makes
Bad Things happen. ;)

> +of_phy_provider_register and devm_of_phy_provider_register macros can be 
> used to
> +register the phy_provider and it takes device and of_xlate as
> +arguments. For the dt boot case, all PHY providers should use one of the 
> above
> +2 macros to register the PHY provider.
> +
> +void devm_of_phy_provider_unregister(struct device *dev,
> + struct phy_provider *phy_provider);
> +void of_phy_provider_unregister(struct phy_provider *phy_provider);
> +
> +devm_of_phy_provider_unregister and of_phy_provider_unregister can be used to
> +unregister the PHY.
> +
[...]
> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> new file mode 100644
> index 000..f1d15e5
> --- /dev/null
> +++ b/drivers/phy/phy-core.c
> @@ -0,0 +1,714 @@
[...]
> +static struct phy *phy_lookup(struct device *device, const char *port)
> +{
> + unsign

Re: [RESEND PATCH v10 1/8] drivers: phy: add generic PHY framework

2013-07-29 Thread Kishon Vijay Abraham I
On Monday 29 July 2013 08:58 PM, Kamil Debski wrote:
> Hi Kishon,
> 
> A small fix follows inline.
> 
>> From: linux-media-ow...@vger.kernel.org [mailto:linux-media-
>> ow...@vger.kernel.org] On Behalf Of Kishon Vijay Abraham I
>> Sent: Friday, July 26, 2013 2:49 PM
>>
>> The PHY framework provides a set of APIs for the PHY drivers to
>> create/destroy a PHY and APIs for the PHY users to obtain a reference
>> to the PHY with or without using phandle. For dt-boot, the PHY drivers
>> should also register *PHY provider* with the framework.
>>
>> PHY drivers should create the PHY by passing id and ops like init, exit,
>> power_on and power_off. This framework is also pm runtime enabled.
>>
>> The documentation for the generic PHY framework is added in
>> Documentation/phy.txt and the documentation for dt binding can be found
>> at Documentation/devicetree/bindings/phy/phy-bindings.txt
>>
>> Cc: Tomasz Figa 
>> Cc: Greg Kroah-Hartman 
>> Signed-off-by: Kishon Vijay Abraham I 
>> Acked-by: Felipe Balbi 
>> Tested-by: Sylwester Nawrocki 
>> ---
>>  .../devicetree/bindings/phy/phy-bindings.txt   |   66 ++
>>  Documentation/phy.txt  |  166 +
>>  MAINTAINERS|8 +
>>  drivers/Kconfig|2 +
>>  drivers/Makefile   |2 +
>>  drivers/phy/Kconfig|   18 +
>>  drivers/phy/Makefile   |5 +
>>  drivers/phy/phy-core.c |  714
>> 
>>  include/linux/phy/phy.h|  270 
>>  9 files changed, 1251 insertions(+)
>>  create mode 100644 Documentation/devicetree/bindings/phy/phy-
>> bindings.txt
>>  create mode 100644 Documentation/phy.txt  create mode 100644
>> drivers/phy/Kconfig  create mode 100644 drivers/phy/Makefile  create
>> mode 100644 drivers/phy/phy-core.c  create mode 100644
>> include/linux/phy/phy.h
>>
> 
> [snip]
> 
>> diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h new file
>> mode 100644 index 000..e444b23
>> --- /dev/null
>> +++ b/include/linux/phy/phy.h
>> @@ -0,0 +1,270 @@
> 
> [snip]
> 
>> +struct phy_init_data {
>> +unsigned int num_consumers;
>> +struct phy_consumer *consumers;
>> +};
>> +
>> +#define PHY_CONSUMER(_dev_name, _port)  \
>> +{   \
>> +.dev_name   = _dev_name,\
>> +.port   = _port,\
>> +}
>> +
>> +#define to_phy(dev) (container_of((dev), struct phy, dev))
>> +
>> +#define of_phy_provider_register(dev, xlate)\
>> +__of_phy_provider_register((dev), THIS_MODULE, (xlate))
>> +
>> +#define devm_of_phy_provider_register(dev, xlate)   \
>> +__of_phy_provider_register((dev), THIS_MODULE, (xlate))
> 
> I think this should be:
> + __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate))
> Right?

right.. thanks for spotting this.

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


RE: [RESEND PATCH v10 1/8] drivers: phy: add generic PHY framework

2013-07-29 Thread Kamil Debski
Hi Kishon,

A small fix follows inline.

> From: linux-media-ow...@vger.kernel.org [mailto:linux-media-
> ow...@vger.kernel.org] On Behalf Of Kishon Vijay Abraham I
> Sent: Friday, July 26, 2013 2:49 PM
> 
> The PHY framework provides a set of APIs for the PHY drivers to
> create/destroy a PHY and APIs for the PHY users to obtain a reference
> to the PHY with or without using phandle. For dt-boot, the PHY drivers
> should also register *PHY provider* with the framework.
> 
> PHY drivers should create the PHY by passing id and ops like init, exit,
> power_on and power_off. This framework is also pm runtime enabled.
> 
> The documentation for the generic PHY framework is added in
> Documentation/phy.txt and the documentation for dt binding can be found
> at Documentation/devicetree/bindings/phy/phy-bindings.txt
> 
> Cc: Tomasz Figa 
> Cc: Greg Kroah-Hartman 
> Signed-off-by: Kishon Vijay Abraham I 
> Acked-by: Felipe Balbi 
> Tested-by: Sylwester Nawrocki 
> ---
>  .../devicetree/bindings/phy/phy-bindings.txt   |   66 ++
>  Documentation/phy.txt  |  166 +
>  MAINTAINERS|8 +
>  drivers/Kconfig|2 +
>  drivers/Makefile   |2 +
>  drivers/phy/Kconfig|   18 +
>  drivers/phy/Makefile   |5 +
>  drivers/phy/phy-core.c |  714
> 
>  include/linux/phy/phy.h|  270 
>  9 files changed, 1251 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/phy/phy-
> bindings.txt
>  create mode 100644 Documentation/phy.txt  create mode 100644
> drivers/phy/Kconfig  create mode 100644 drivers/phy/Makefile  create
> mode 100644 drivers/phy/phy-core.c  create mode 100644
> include/linux/phy/phy.h
> 

[snip]

> diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h new file
> mode 100644 index 000..e444b23
> --- /dev/null
> +++ b/include/linux/phy/phy.h
> @@ -0,0 +1,270 @@

[snip]

> +struct phy_init_data {
> + unsigned int num_consumers;
> + struct phy_consumer *consumers;
> +};
> +
> +#define PHY_CONSUMER(_dev_name, _port)   \
> +{\
> + .dev_name   = _dev_name,\
> + .port   = _port,\
> +}
> +
> +#define  to_phy(dev) (container_of((dev), struct phy, dev))
> +
> +#define  of_phy_provider_register(dev, xlate)\
> + __of_phy_provider_register((dev), THIS_MODULE, (xlate))
> +
> +#define  devm_of_phy_provider_register(dev, xlate)   \
> + __of_phy_provider_register((dev), THIS_MODULE, (xlate))

I think this should be:
+   __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate))
Right?

> +
> +static inline void phy_set_drvdata(struct phy *phy, void *data) {
> + dev_set_drvdata(&phy->dev, data);
> +}
> +
> +static inline void *phy_get_drvdata(struct phy *phy) {
> + return dev_get_drvdata(&phy->dev);
> +}
> +

[snip]

Best wishes,
-- 
Kamil Debski
Linux Kernel Developer
Samsung R&D Institute Poland




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


[RESEND PATCH v10 1/8] drivers: phy: add generic PHY framework

2013-07-26 Thread Kishon Vijay Abraham I
The PHY framework provides a set of APIs for the PHY drivers to
create/destroy a PHY and APIs for the PHY users to obtain a reference to the
PHY with or without using phandle. For dt-boot, the PHY drivers should
also register *PHY provider* with the framework.

PHY drivers should create the PHY by passing id and ops like init, exit,
power_on and power_off. This framework is also pm runtime enabled.

The documentation for the generic PHY framework is added in
Documentation/phy.txt and the documentation for dt binding can be found at
Documentation/devicetree/bindings/phy/phy-bindings.txt

Cc: Tomasz Figa 
Cc: Greg Kroah-Hartman 
Signed-off-by: Kishon Vijay Abraham I 
Acked-by: Felipe Balbi 
Tested-by: Sylwester Nawrocki 
---
 .../devicetree/bindings/phy/phy-bindings.txt   |   66 ++
 Documentation/phy.txt  |  166 +
 MAINTAINERS|8 +
 drivers/Kconfig|2 +
 drivers/Makefile   |2 +
 drivers/phy/Kconfig|   18 +
 drivers/phy/Makefile   |5 +
 drivers/phy/phy-core.c |  714 
 include/linux/phy/phy.h|  270 
 9 files changed, 1251 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-bindings.txt
 create mode 100644 Documentation/phy.txt
 create mode 100644 drivers/phy/Kconfig
 create mode 100644 drivers/phy/Makefile
 create mode 100644 drivers/phy/phy-core.c
 create mode 100644 include/linux/phy/phy.h

diff --git a/Documentation/devicetree/bindings/phy/phy-bindings.txt 
b/Documentation/devicetree/bindings/phy/phy-bindings.txt
new file mode 100644
index 000..8ae844f
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/phy-bindings.txt
@@ -0,0 +1,66 @@
+This document explains only the device tree data binding. For general
+information about PHY subsystem refer to Documentation/phy.txt
+
+PHY device node
+===
+
+Required Properties:
+#phy-cells:Number of cells in a PHY specifier;  The meaning of all those
+   cells is defined by the binding for the phy node. The PHY
+   provider can use the values in cells to find the appropriate
+   PHY.
+
+For example:
+
+phys: phy {
+compatible = "xxx";
+reg = <...>;
+.
+.
+#phy-cells = <1>;
+.
+.
+};
+
+That node describes an IP block (PHY provider) that implements 2 different 
PHYs.
+In order to differentiate between these 2 PHYs, an additonal specifier should 
be
+given while trying to get a reference to it.
+
+PHY user node
+=
+
+Required Properties:
+phys : the phandle for the PHY device (used by the PHY subsystem)
+phy-names : the names of the PHY corresponding to the PHYs present in the
+   *phys* phandle
+
+Example 1:
+usb1: usb_otg_ss@xxx {
+compatible = "xxx";
+reg = ;
+.
+.
+phys = <&usb2_phy>, <&usb3_phy>;
+phy-names = "usb2phy", "usb3phy";
+.
+.
+};
+
+This node represents a controller that uses two PHYs, one for usb2 and one for
+usb3.
+
+Example 2:
+usb2: usb_otg_ss@xxx {
+compatible = "xxx";
+reg = ;
+.
+.
+phys = <&phys 1>;
+phy-names = "usbphy";
+.
+.
+};
+
+This node represents a controller that uses one of the PHYs of the PHY provider
+device defined previously. Note that the phy handle has an additional specifier
+"1" to differentiate between the two PHYs.
diff --git a/Documentation/phy.txt b/Documentation/phy.txt
new file mode 100644
index 000..4e056c4
--- /dev/null
+++ b/Documentation/phy.txt
@@ -0,0 +1,166 @@
+   PHY SUBSYSTEM
+ Kishon Vijay Abraham I 
+
+This document explains the Generic PHY Framework along with the APIs provided,
+and how-to-use.
+
+1. Introduction
+
+*PHY* is the abbreviation for physical layer. It is used to connect a device
+to the physical medium e.g., the USB controller has a PHY to provide functions
+such as serialization, de-serialization, encoding, decoding and is responsible
+for obtaining the required data transmission rate. Note that some USB
+controllers have PHY functionality embedded into it and others use an external
+PHY. Other peripherals that use PHY include Wireless LAN, Ethernet,
+SATA etc.
+
+The intention of creating this framework is to bring the PHY drivers spread
+all over the Linux kernel to drivers/phy to increase code re-use and for
+better code maintainability.
+
+This framework will be of use only to devices that use external PHY (PHY
+functionality is not embedded within the controller).
+
+2. Registering/Unregistering the PHY provider
+
+PHY provider refers to an entity that implements one or more PHY instances.
+For the simple case where the PHY provider implements only a single instance of
+the PHY, the framework provides its own implementation of of_xlate in
+of_phy_simple_xla