Skip to contentSkip to conversation

phy: extend APIs of the generic phy framework

PATCH Kishon Vijay Abraham I 2 participants 4 messages Aug 4, 2014 – Aug 5, 2014 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Hi,

Quoted 2 lines · Yaniv Gardi

This change adds a few more APIs to the phy_ops structure:
advertise_quirks - API for setting the phy quirks

What are these phy quirks? An explanation on what you are are planning to do with these quirks might help.

Quoted 2 lines

suspend - API for the implementation of phy suspend sequence resume - API for the implementation of phy resume sequence

Why not use the existing pm_runtime's suspend/resume callbacks?

Quoted 2 lines

Change-Id: I44dd77f2603d20acb02ccb0cc0d20ade884f97c2

Remove this..

Quoted 98 lines
---
 Documentation/phy.txt   |  6 ++---
 drivers/phy/phy-core.c  | 58 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/phy/phy.h | 33 ++++++++++++++++++++++++++++
 3 files changed, 94 insertions(+), 3 deletions(-)
Documentation/phy.txt +3 -3
index c6594af..f0dc28e 100644
@@ -63,9 +63,9 @@ struct phy *devm_phy_create(struct device *dev, struct device_node *node,
 The PHY drivers can use one of the above 2 APIs to create the PHY by passing
 the device pointer, phy ops and init_data.
 phy_ops is a set of function pointers for performing PHY operations such as
-init, exit, power_on and power_off. *init_data* is mandatory to get a reference
-to the PHY in the case of non-dt boot. See section *Board File Initialization*
-on how init_data should be used.
+init, exit, power_on and power_off, , suspend, resume and advertise_quirks.
+*init_data* is mandatory to get a reference to the PHY in the case of non-dt
+boot. See section *Board File Initialization* on how init_data should be used.
 
 Inorder to dereference the private data (in phy_ops), the phy provider driver
 can use phy_set_drvdata() after creating the PHY and use phy_get_drvdata() in
drivers/phy/phy-core.c +58 -0
index ff5eec5..77abaab 100644
@@ -293,6 +293,64 @@ int phy_power_off(struct phy *phy)
 }
 EXPORT_SYMBOL_GPL(phy_power_off);
 
+int phy_suspend(struct phy *phy)
+{
+	int ret = 0;
+
+	if (!phy->ops->suspend)
+		return -ENOTSUPP;
+
+	mutex_lock(&phy->mutex);
+
+	if (--phy->resume_count == 0) {
+		ret =  phy->ops->suspend(phy);
+		if (ret) {
+			dev_err(&phy->dev, "phy suspend failed --> %d\n", ret);
+			/* reverting the resume_count since suspend failed */
+			phy->resume_count++;
+			goto out;
+		}
+	}
+out:
+	mutex_unlock(&phy->mutex);
+	return ret;
+}
+EXPORT_SYMBOL(phy_suspend);
+
+int phy_resume(struct phy *phy)
+{
+	int ret = 0;
+
+	if (!phy->ops->resume)
+		return -ENOTSUPP;
+
+	mutex_lock(&phy->mutex);
+
+	if (phy->resume_count++ == 0) {
+		ret =  phy->ops->resume(phy);
+		if (ret) {
+			dev_err(&phy->dev, "phy resume failed --> %d\n", ret);
+			/* reverting the resume_count since resume failed */
+			phy->resume_count--;
+			goto out;
+		}
+	}
+out:
+	mutex_unlock(&phy->mutex);
+	return ret;
+}
+EXPORT_SYMBOL(phy_resume);
+
+void phy_advertise_quirks(struct phy *phy)
+{
+	if (phy->ops->advertise_quirks) {
+		mutex_lock(&phy->mutex);
+		phy->ops->advertise_quirks(phy);
+		mutex_unlock(&phy->mutex);
+	}
+}
+EXPORT_SYMBOL(phy_advertise_quirks);
+
 /**
  * _of_phy_get() - lookup and obtain a reference to a phy by phandle
  * @np: device_node for which to get the phy
include/linux/phy/phy.h +0 -0
index 8cb6f81..5b96d65 100644

include/linux/phy/phy.h struct phy; · line 36

Quoted 9 lines
include/linux/phy/phy.h +6 -0
@@ -28,6 +28,14 @@ struct phy;
  * @exit: operation to be performed while exiting
  * @power_on: powering on the phy
  * @power_off: powering off the phy
+ * @advertise_quirks: setting specific phy quirks. this api is for an
+		      internal use of the device driver, and its
+		      purpose is to exteriorize the driver's phy quirks
+		      according to phy version (or other parameters),
+		      so further behaviour of the driver's phy is based
+		      on those quirks.

Can you be more specific on what you do with this? This looks more like a candidate for flags than callback to me?

Thanks
Kishon

#2 lore raw
Quoted 9 lines

Hi,

Quoted 2 lines · Yaniv Gardi

This change adds a few more APIs to the phy_ops structure:
advertise_quirks - API for setting the phy quirks

What are these phy quirks? An explanation on what you are are planning to do
with these quirks might help.

A phy HW might have a specific behavior that should be exposed to the phy SW structure by calling this callback. This is the reason behind this callback. does it make more sense now ?

Quoted 5 lines
Quoted 2 lines

suspend - API for the implementation of phy suspend sequence resume - API for the implementation of phy resume sequence

Why not use the existing pm_runtime's suspend/resume callbacks?

Like we observed in our case, often there are need to be extra operations in the suspend/resume sequence. those specific operations include turning off/on specific clocks, disabling/enabling regulators etc. the specific implementation must give enough flexibility to add whatever needed to be done in suspend/resume sequences.

Quoted 129 lines
Quoted 2 lines

Change-Id: I44dd77f2603d20acb02ccb0cc0d20ade884f97c2

Remove this..

Quoted 109 lines
---
 Documentation/phy.txt   |  6 ++---
 drivers/phy/phy-core.c  | 58
+++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/phy/phy.h | 33 ++++++++++++++++++++++++++++
 3 files changed, 94 insertions(+), 3 deletions(-)
Documentation/phy.txt +0 -0
index c6594af..f0dc28e 100644
@@ -63,9 +63,9 @@ struct phy *devm_phy_create(struct device *dev, struct
 device_node *node,
 The PHY drivers can use one of the above 2 APIs to create the PHY by

passing
the device pointer, phy ops and init_data.
phy_ops is a set of function pointers for performing PHY operations
such as
-init, exit, power_on and power_off. *init_data* is mandatory to get a reference
-to the PHY in the case of non-dt boot. See section *Board File Initialization*

Documentation/phy.txt +1 -1
-on how init_data should be used.
+init, exit, power_on and power_off, , suspend, resume and

advertise_quirks.
+*init_data* is mandatory to get a reference to the PHY in the case of non-dt
+boot. See section *Board File Initialization* on how init_data should be used.

Inorder to dereference the private data (in phy_ops), the phy provider
driver
can use phy_set_drvdata() after creating the PHY and use
phy_get_drvdata() in

drivers/phy/phy-core.c +58 -0
index ff5eec5..77abaab 100644
@@ -293,6 +293,64 @@ int phy_power_off(struct phy *phy)
 }
 EXPORT_SYMBOL_GPL(phy_power_off);
 
+int phy_suspend(struct phy *phy)
+{
+	int ret = 0;
+
+	if (!phy->ops->suspend)
+		return -ENOTSUPP;
+
+	mutex_lock(&phy->mutex);
+
+	if (--phy->resume_count == 0) {
+		ret =  phy->ops->suspend(phy);
+		if (ret) {
+			dev_err(&phy->dev, "phy suspend failed --> %d\n", ret);
+			/* reverting the resume_count since suspend failed */
+			phy->resume_count++;
+			goto out;
+		}
+	}
+out:
+	mutex_unlock(&phy->mutex);
+	return ret;
+}
+EXPORT_SYMBOL(phy_suspend);
+
+int phy_resume(struct phy *phy)
+{
+	int ret = 0;
+
+	if (!phy->ops->resume)
+		return -ENOTSUPP;
+
+	mutex_lock(&phy->mutex);
+
+	if (phy->resume_count++ == 0) {
+		ret =  phy->ops->resume(phy);
+		if (ret) {
+			dev_err(&phy->dev, "phy resume failed --> %d\n", ret);
+			/* reverting the resume_count since resume failed */
+			phy->resume_count--;
+			goto out;
+		}
+	}
+out:
+	mutex_unlock(&phy->mutex);
+	return ret;
+}
+EXPORT_SYMBOL(phy_resume);
+
+void phy_advertise_quirks(struct phy *phy)
+{
+	if (phy->ops->advertise_quirks) {
+		mutex_lock(&phy->mutex);
+		phy->ops->advertise_quirks(phy);
+		mutex_unlock(&phy->mutex);
+	}
+}
+EXPORT_SYMBOL(phy_advertise_quirks);
+
 /**
  * _of_phy_get() - lookup and obtain a reference to a phy by phandle
  * @np: device_node for which to get the phy
include/linux/phy/phy.h +0 -0
index 8cb6f81..5b96d65 100644

include/linux/phy/phy.h struct phy; · line 36

Quoted 9 lines
include/linux/phy/phy.h +6 -0
@@ -28,6 +28,14 @@ struct phy;
  * @exit: operation to be performed while exiting
  * @power_on: powering on the phy
  * @power_off: powering off the phy
+ * @advertise_quirks: setting specific phy quirks. this api is for an
+		      internal use of the device driver, and its
+		      purpose is to exteriorize the driver's phy quirks
+		      according to phy version (or other parameters),
+		      so further behaviour of the driver's phy is based
+		      on those quirks.

Can you be more specific on what you do with this? This looks more like a candidate for flags than callback to me?

Thanks
Kishon

#3 lore raw

Hi,

Quoted 6 lines · On Tuesday 05 August 2014 12:03 AM, [email protected] wrote:
Quoted 6 lines

Hi,

Quoted 2 lines · Yaniv Gardi

This change adds a few more APIs to the phy_ops structure:
advertise_quirks - API for setting the phy quirks

Quoted 7 lines
Quoted 3 lines

What are these phy quirks? An explanation on what you are are planning to do
with these quirks might help.

A phy HW might have a specific behavior that should be exposed to the phy SW structure by calling this callback. This is the reason behind this callback. does it make more sense now ?

I'm more interested in the _specific_ behaviour you are talking about. Such callbacks can be abused easily.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

suspend - API for the implementation of phy suspend sequence resume - API for the implementation of phy resume sequence

Quoted 7 lines
Quoted 2 lines

Why not use the existing pm_runtime's suspend/resume callbacks?

Like we observed in our case, often there are need to be extra operations in the suspend/resume sequence. those specific operations include turning off/on specific clocks, disabling/enabling regulators etc. the specific implementation must give enough flexibility to add whatever needed to be done in suspend/resume sequences.

All these can be done in suspend and resume callbacks of pm_runtime.

Thanks
Kishon

Quoted 135 lines
Quoted 133 lines
Quoted 6 lines

Change-Id: I44dd77f2603d20acb02ccb0cc0d20ade884f97c2

Remove this..

Quoted 109 lines
---
 Documentation/phy.txt   |  6 ++---
 drivers/phy/phy-core.c  | 58
+++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/phy/phy.h | 33 ++++++++++++++++++++++++++++
 3 files changed, 94 insertions(+), 3 deletions(-)
Documentation/phy.txt +0 -0
index c6594af..f0dc28e 100644
@@ -63,9 +63,9 @@ struct phy *devm_phy_create(struct device *dev, struct
 device_node *node,
 The PHY drivers can use one of the above 2 APIs to create the PHY by

passing
the device pointer, phy ops and init_data.
phy_ops is a set of function pointers for performing PHY operations
such as
-init, exit, power_on and power_off. *init_data* is mandatory to get a reference
-to the PHY in the case of non-dt boot. See section *Board File Initialization*

Documentation/phy.txt +1 -1
-on how init_data should be used.
+init, exit, power_on and power_off, , suspend, resume and

advertise_quirks.
+*init_data* is mandatory to get a reference to the PHY in the case of non-dt
+boot. See section *Board File Initialization* on how init_data should be used.

Inorder to dereference the private data (in phy_ops), the phy provider
driver
can use phy_set_drvdata() after creating the PHY and use
phy_get_drvdata() in

drivers/phy/phy-core.c +58 -0
index ff5eec5..77abaab 100644
@@ -293,6 +293,64 @@ int phy_power_off(struct phy *phy)
 }
 EXPORT_SYMBOL_GPL(phy_power_off);
 
+int phy_suspend(struct phy *phy)
+{
+	int ret = 0;
+
+	if (!phy->ops->suspend)
+		return -ENOTSUPP;
+
+	mutex_lock(&phy->mutex);
+
+	if (--phy->resume_count == 0) {
+		ret =  phy->ops->suspend(phy);
+		if (ret) {
+			dev_err(&phy->dev, "phy suspend failed --> %d\n", ret);
+			/* reverting the resume_count since suspend failed */
+			phy->resume_count++;
+			goto out;
+		}
+	}
+out:
+	mutex_unlock(&phy->mutex);
+	return ret;
+}
+EXPORT_SYMBOL(phy_suspend);
+
+int phy_resume(struct phy *phy)
+{
+	int ret = 0;
+
+	if (!phy->ops->resume)
+		return -ENOTSUPP;
+
+	mutex_lock(&phy->mutex);
+
+	if (phy->resume_count++ == 0) {
+		ret =  phy->ops->resume(phy);
+		if (ret) {
+			dev_err(&phy->dev, "phy resume failed --> %d\n", ret);
+			/* reverting the resume_count since resume failed */
+			phy->resume_count--;
+			goto out;
+		}
+	}
+out:
+	mutex_unlock(&phy->mutex);
+	return ret;
+}
+EXPORT_SYMBOL(phy_resume);
+
+void phy_advertise_quirks(struct phy *phy)
+{
+	if (phy->ops->advertise_quirks) {
+		mutex_lock(&phy->mutex);
+		phy->ops->advertise_quirks(phy);
+		mutex_unlock(&phy->mutex);
+	}
+}
+EXPORT_SYMBOL(phy_advertise_quirks);
+
 /**
  * _of_phy_get() - lookup and obtain a reference to a phy by phandle
  * @np: device_node for which to get the phy
include/linux/phy/phy.h +0 -0
index 8cb6f81..5b96d65 100644

include/linux/phy/phy.h struct phy; · line 36

Quoted 9 lines
include/linux/phy/phy.h +6 -0
@@ -28,6 +28,14 @@ struct phy;
  * @exit: operation to be performed while exiting
  * @power_on: powering on the phy
  * @power_off: powering off the phy
+ * @advertise_quirks: setting specific phy quirks. this api is for an
+		      internal use of the device driver, and its
+		      purpose is to exteriorize the driver's phy quirks
+		      according to phy version (or other parameters),
+		      so further behaviour of the driver's phy is based
+		      on those quirks.

Can you be more specific on what you do with this? This looks more like a candidate for flags than callback to me?

Thanks
Kishon

#4 lore raw
Quoted 14 lines

Hi,

Quoted 11 lines · On Tuesday 05 August 2014 12:03 AM, [email protected] wrote:
Quoted 10 lines

Hi,

Quoted 2 lines · Yaniv Gardi

This change adds a few more APIs to the phy_ops structure:
advertise_quirks - API for setting the phy quirks

What are these phy quirks? An explanation on what you are are planning to
do
with these quirks might help.

Quoted 8 lines
Quoted 4 lines

A phy HW might have a specific behavior that should be exposed to the phy
SW structure by calling this callback. This is the reason behind this callback. does it make more sense now ?

I'm more interested in the _specific_ behaviour you are talking about. Such
callbacks can be abused easily.

I'm not sure I understand how this callback can be abused more than any other callback. however, specific behaviour of PHY can be, for example, different configuration of attributes during power_on power_off when a quirk of hibern8_exit is advertised etc.

Quoted 160 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

suspend - API for the implementation of phy suspend sequence resume - API for the implementation of phy resume sequence

Why not use the existing pm_runtime's suspend/resume callbacks?

Quoted 7 lines

Like we observed in our case, often there are need to be extra operations
in the suspend/resume sequence. those specific operations include turning
off/on specific clocks, disabling/enabling regulators etc. the specific implementation must give enough flexibility to add whatever needed to be done in suspend/resume sequences.

All these can be done in suspend and resume callbacks of pm_runtime.

Thanks
Kishon

Quoted 138 lines
Quoted 136 lines
Quoted 6 lines

Change-Id: I44dd77f2603d20acb02ccb0cc0d20ade884f97c2

Remove this..

Quoted 111 lines
---
 Documentation/phy.txt   |  6 ++---
 drivers/phy/phy-core.c  | 58
+++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/phy/phy.h | 33 ++++++++++++++++++++++++++++
 3 files changed, 94 insertions(+), 3 deletions(-)
Documentation/phy.txt +0 -0
index c6594af..f0dc28e 100644
@@ -63,9 +63,9 @@ struct phy *devm_phy_create(struct device *dev,

struct
device_node *node,
The PHY drivers can use one of the above 2 APIs to create the PHY by
passing
the device pointer, phy ops and init_data.
phy_ops is a set of function pointers for performing PHY operations
such as
-init, exit, power_on and power_off. *init_data* is mandatory to get a reference
-to the PHY in the case of non-dt boot. See section *Board File Initialization*

Documentation/phy.txt +1 -1
-on how init_data should be used.
+init, exit, power_on and power_off, , suspend, resume and

advertise_quirks.
+*init_data* is mandatory to get a reference to the PHY in the case of non-dt
+boot. See section *Board File Initialization* on how init_data should be used.

Inorder to dereference the private data (in phy_ops), the phy
provider
driver
can use phy_set_drvdata() after creating the PHY and use
phy_get_drvdata() in

drivers/phy/phy-core.c +58 -0
index ff5eec5..77abaab 100644
@@ -293,6 +293,64 @@ int phy_power_off(struct phy *phy)
 }
 EXPORT_SYMBOL_GPL(phy_power_off);
 
+int phy_suspend(struct phy *phy)
+{
+	int ret = 0;
+
+	if (!phy->ops->suspend)
+		return -ENOTSUPP;
+
+	mutex_lock(&phy->mutex);
+
+	if (--phy->resume_count == 0) {
+		ret =  phy->ops->suspend(phy);
+		if (ret) {
+			dev_err(&phy->dev, "phy suspend failed --> %d\n", ret);
+			/* reverting the resume_count since suspend failed */
+			phy->resume_count++;
+			goto out;
+		}
+	}
+out:
+	mutex_unlock(&phy->mutex);
+	return ret;
+}
+EXPORT_SYMBOL(phy_suspend);
+
+int phy_resume(struct phy *phy)
+{
+	int ret = 0;
+
+	if (!phy->ops->resume)
+		return -ENOTSUPP;
+
+	mutex_lock(&phy->mutex);
+
+	if (phy->resume_count++ == 0) {
+		ret =  phy->ops->resume(phy);
+		if (ret) {
+			dev_err(&phy->dev, "phy resume failed --> %d\n", ret);
+			/* reverting the resume_count since resume failed */
+			phy->resume_count--;
+			goto out;
+		}
+	}
+out:
+	mutex_unlock(&phy->mutex);
+	return ret;
+}
+EXPORT_SYMBOL(phy_resume);
+
+void phy_advertise_quirks(struct phy *phy)
+{
+	if (phy->ops->advertise_quirks) {
+		mutex_lock(&phy->mutex);
+		phy->ops->advertise_quirks(phy);
+		mutex_unlock(&phy->mutex);
+	}
+}
+EXPORT_SYMBOL(phy_advertise_quirks);
+
 /**
  * _of_phy_get() - lookup and obtain a reference to a phy by phandle
  * @np: device_node for which to get the phy
include/linux/phy/phy.h +0 -0
index 8cb6f81..5b96d65 100644

include/linux/phy/phy.h struct phy; · line 36

Quoted 9 lines
include/linux/phy/phy.h +6 -0
@@ -28,6 +28,14 @@ struct phy;
  * @exit: operation to be performed while exiting
  * @power_on: powering on the phy
  * @power_off: powering off the phy
+ * @advertise_quirks: setting specific phy quirks. this api is for an
+		      internal use of the device driver, and its
+		      purpose is to exteriorize the driver's phy quirks
+		      according to phy version (or other parameters),
+		      so further behaviour of the driver's phy is based
+		      on those quirks.

Can you be more specific on what you do with this? This looks more like a
candidate for flags than callback to me?

Thanks
Kishon