Skip to contentSkip to conversation

reset: Add API to count number of reset available with device

PATCH Superseded Vivek Gautam 3 participants 10 messages Feb 22, 2017 – Mar 16, 2017

Subsystems (4)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 reset: Add API to count number of reset available with device

Count number of reset phandles available with the device node to know the resets a given device has.

---

Based on torvald's master branch.

 include/linux/reset.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
include/linux/reset.h +16 -0
index 5daff15722d3..88f63a640153 100644
@@ -2,6 +2,7 @@
 #define _LINUX_RESET_H_
 
 #include <linux/device.h>
+#include <linux/of.h>
 
 struct reset_control;
 
@@ -234,6 +235,21 @@ static inline struct reset_control *of_reset_control_get_shared_by_index(
 }
 
 /**
+ * of_reset_control_get_count - Count number of resets available with a device
+ * @node: device to be reset by the controller
+ */
+static inline unsigned int of_reset_control_get_count(struct device_node *node)
+{
+	int count;
+
+	count = of_count_phandle_with_args(node, "resets", "#reset-cells");
+	if (count < 0)
+		return 0;
+
+	return count;
+}
+
+/**
  * devm_reset_control_get_exclusive - resource managed
  *                                    reset_control_get_exclusive()
  * @dev: device to be reset by the controller
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#1 lore raw

PATCH 2/2 usb; dwc3: of-simple: Add support to get resets for the device

Add support to get a list of resets available for the device. These resets must be kept de-asserted until the device is in use.

---

Based on torvald's master branch.

 drivers/usb/dwc3/dwc3-of-simple.c | 49 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
drivers/usb/dwc3/dwc3-of-simple.c +49 -0
index fe414e7a9c78..025de7342d28 100644
@@ -29,13 +29,52 @@
 #include <linux/of.h>
 #include <linux/of_platform.h>
 #include <linux/pm_runtime.h>
+#include <linux/reset.h>
 
 struct dwc3_of_simple {
 	struct device		*dev;
 	struct clk		**clks;
 	int			num_clocks;
+	struct reset_control	**resets;
+	int			num_resets;
 };
 
+static int dwc3_of_simple_reset_init(struct dwc3_of_simple *simple, int count)
+{
+	struct device		*dev = simple->dev;
+	int			i;
+
+	simple->num_resets = count;
+
+	if (!count)
+		return 0;
+
+	simple->resets = devm_kcalloc(dev, simple->num_resets,
+				sizeof(struct reset_control *), GFP_KERNEL);
+	if (!simple->resets)
+		return -ENOMEM;
+
+	for (i = 0; i < simple->num_resets; i++) {
+		struct reset_control *reset;
+		int ret;
+
+		reset = devm_reset_control_get_by_index(dev, i);
+		if (IS_ERR(reset))
+			return PTR_ERR(reset);
+
+		simple->resets[i] = reset;
+
+		ret = reset_control_deassert(reset);
+		if (ret) {
+			while (--i >= 0)
+				reset_control_assert(reset);
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
 static int dwc3_of_simple_clk_init(struct dwc3_of_simple *simple, int count)
 {
 	struct device		*dev = simple->dev;
@@ -100,6 +139,10 @@ static int dwc3_of_simple_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	ret = dwc3_of_simple_reset_init(simple, of_reset_control_get_count(np));
+	if (ret)
+		return ret;
+
 	ret = of_platform_populate(np, NULL, NULL, dev);
 	if (ret) {
 		for (i = 0; i < simple->num_clocks; i++) {
@@ -107,6 +150,9 @@ static int dwc3_of_simple_probe(struct platform_device *pdev)
 			clk_put(simple->clks[i]);
 		}
 
+		for (i = 0; i < simple->num_resets; i++)
+			reset_control_assert(simple->resets[i]);
+
 		return ret;
 	}
 
@@ -128,6 +174,9 @@ static int dwc3_of_simple_remove(struct platform_device *pdev)
 		clk_put(simple->clks[i]);
 	}
 
+	for (i = 0; i < simple->num_resets; i++)
+		reset_control_assert(simple->resets[i]);
+
 	of_platform_depopulate(dev);
 
 	pm_runtime_put_sync(dev);
Signature · 7 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw

Re: [PATCH 2/2] usb; dwc3: of-simple: Add support to get resets for the device

Quoted 6 lines · Vivek Gautam

Add support to get a list of resets available for the device. These resets must be kept de-asserted until the device is in use.

how do you plan on merging this since it depends on previous patch?

Signature · 1 line
balbi
#3 lore raw

Re: [PATCH 2/2] usb; dwc3: of-simple: Add support to get resets for the device

Quoted 10 lines · Felipe Balbi
Quoted 6 lines · Vivek Gautam

Add support to get a list of resets available for the device. These resets must be kept de-asserted until the device is in use.

how do you plan on merging this since it depends on previous patch?

Will ask Phillip if he is fine with the previous patch. He can then consider giving an ack so that both patches can be pulled in together.

Will it be okay to do that ?

Regards
Vivek

Quoted 3 lines

--
balbi

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#4 lore raw

Re: [PATCH 2/2] usb; dwc3: of-simple: Add support to get resets for the device

Hi,

Quoted 10 lines · Vivek Gautam
Quoted 9 lines · Felipe Balbi
Quoted 6 lines · Vivek Gautam

Add support to get a list of resets available for the device. These resets must be kept de-asserted until the device is in use.

Quoted 6 lines
Quoted 1 line

how do you plan on merging this since it depends on previous patch?

Will ask Phillip if he is fine with the previous patch. He can then consider giving an ack so that both patches can be pulled in together.

Will it be okay to do that ?

sounds like a plan :-)

Signature · 1 line
balbi
maintainer
#5 lore raw

Re: [PATCH 2/2] usb; dwc3: of-simple: Add support to get resets for the device

In reply to Vivek Gautam
Quoted 41 lines · Vivek Gautam

Add support to get a list of resets available for the device. These resets must be kept de-asserted until the device is in use.

---

Based on torvald's master branch.

 drivers/usb/dwc3/dwc3-of-simple.c | 49 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
drivers/usb/dwc3/dwc3-of-simple.c +13 -0
index fe414e7a9c78..025de7342d28 100644
@@ -29,13 +29,52 @@
 #include <linux/of.h>
 #include <linux/of_platform.h>
 #include <linux/pm_runtime.h>
+#include <linux/reset.h>
 
 struct dwc3_of_simple {
 	struct device		*dev;
 	struct clk		**clks;
 	int			num_clocks;
+	struct reset_control	**resets;
+	int			num_resets;
 };
 
+static int dwc3_of_simple_reset_init(struct dwc3_of_simple *simple, int count)
+{
+	struct device		*dev = simple->dev;
+	int			i;
+
+	simple->num_resets = count;
+
+	if (!count)
+		return 0;
+

drivers/usb/dwc3/dwc3-of-simple.c line 61

Quoted 10 lines
drivers/usb/dwc3/dwc3-of-simple.c +10 -0
+	simple->resets = devm_kcalloc(dev, simple->num_resets,
+				sizeof(struct reset_control *), GFP_KERNEL);
+	if (!simple->resets)
+		return -ENOMEM;
+
+	for (i = 0; i < simple->num_resets; i++) {
+		struct reset_control *reset;
+		int ret;
+
+		reset = devm_reset_control_get_by_index(dev, i);

Please use devm_reset_control_get_exclusive_by_index instead. See include/linux/reset.h for details.

Quoted 5 lines
drivers/usb/dwc3/dwc3-of-simple.c +5 -0
+		if (IS_ERR(reset))
+			return PTR_ERR(reset);
+
+		simple->resets[i] = reset;
+

drivers/usb/dwc3/dwc3-of-simple.c line 76

Quoted 10 lines
drivers/usb/dwc3/dwc3-of-simple.c +10 -0
+		ret = reset_control_deassert(reset);
+		if (ret) {
+			while (--i >= 0)
+				reset_control_assert(reset);
+			return ret;
+		}
+	}
+
+	return 0;
+}

This looks rather generic. Should we have a reset_control_get/assert/deassert_array functionality at the reset API level?

drivers/usb/dwc3/dwc3-of-simple.c static int dwc3_of_simple_probe(struct platform_device *pdev) · line 145

Quoted 11 lines
drivers/usb/dwc3/dwc3-of-simple.c +4 -0
 static int dwc3_of_simple_clk_init(struct dwc3_of_simple *simple, int count)
 {
 	struct device		*dev = simple->dev;
@@ -100,6 +139,10 @@ static int dwc3_of_simple_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	ret = dwc3_of_simple_reset_init(simple, of_reset_control_get_count(np));
+	if (ret)
+		return ret;
+

Not a blocker, but it seems a bit inconsistent to count the reset controls via the device node (of_...), but then get them via the device (devm_reset_control_get_... instead of of_reset_control_get_...).

regards
Philipp

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

#6 lore raw

Re: [PATCH 2/2] usb; dwc3: of-simple: Add support to get resets for the device

Hi,

Quoted 46 lines · Philipp Zabel
Quoted 45 lines · Vivek Gautam

Add support to get a list of resets available for the device. These resets must be kept de-asserted until the device is in use.

---

Based on torvald's master branch.

  drivers/usb/dwc3/dwc3-of-simple.c | 49 +++++++++++++++++++++++++++++++++++++++
  1 file changed, 49 insertions(+)
drivers/usb/dwc3/dwc3-of-simple.c +17 -0
index fe414e7a9c78..025de7342d28 100644
@@ -29,13 +29,52 @@
  #include <linux/of.h>
  #include <linux/of_platform.h>
  #include <linux/pm_runtime.h>
+#include <linux/reset.h>
 
  struct dwc3_of_simple {
  	struct device		*dev;
  	struct clk		**clks;
  	int			num_clocks;
+	struct reset_control	**resets;
+	int			num_resets;
  };
 
+static int dwc3_of_simple_reset_init(struct dwc3_of_simple *simple, int count)
+{
+	struct device		*dev = simple->dev;
+	int			i;
+
+	simple->num_resets = count;
+
+	if (!count)
+		return 0;
+
+	simple->resets = devm_kcalloc(dev, simple->num_resets,
+				sizeof(struct reset_control *), GFP_KERNEL);
+	if (!simple->resets)
+		return -ENOMEM;
Quoted 8 lines

drivers/usb/dwc3/dwc3-of-simple.c line 61

Quoted 6 lines
drivers/usb/dwc3/dwc3-of-simple.c +6 -0
+
+	for (i = 0; i < simple->num_resets; i++) {
+		struct reset_control *reset;
+		int ret;
+
+		reset = devm_reset_control_get_by_index(dev, i);

Please use devm_reset_control_get_exclusive_by_index instead. See include/linux/reset.h for details.

Sure, will make use of *exclusive version of the api.

Quoted 11 lines
Quoted 11 lines
drivers/usb/dwc3/dwc3-of-simple.c +10 -0
+		if (IS_ERR(reset))
+			return PTR_ERR(reset);
+
+		simple->resets[i] = reset;
+
+		ret = reset_control_deassert(reset);
+		if (ret) {
+			while (--i >= 0)
+				reset_control_assert(reset);
+			return ret;
Quoted 8 lines

drivers/usb/dwc3/dwc3-of-simple.c line 76

Quoted 5 lines
drivers/usb/dwc3/dwc3-of-simple.c +5 -0
+		}
+	}
+
+	return 0;
+}

This looks rather generic. Should we have a reset_control_get/assert/deassert_array functionality at the reset API level?

Yes, i think we should. Something on the lines of 'regulator_bulk_*' interface?

Quoted 8 lines
Quoted 8 lines
drivers/usb/dwc3/dwc3-of-simple.c +0 -0
  static int dwc3_of_simple_clk_init(struct dwc3_of_simple *simple, int count)
  {
  	struct device		*dev = simple->dev;
@@ -100,6 +139,10 @@ static int dwc3_of_simple_probe(struct platform_device *pdev)
  	if (ret)
  		return ret;
 
Quoted 7 lines

drivers/usb/dwc3/dwc3-of-simple.c static int dwc3_of_simple_probe(struct platform_device *pdev) · line 145

Quoted 4 lines
drivers/usb/dwc3/dwc3-of-simple.c +4 -0
+	ret = dwc3_of_simple_reset_init(simple, of_reset_control_get_count(np));
+	if (ret)
+		return ret;
+

Not a blocker, but it seems a bit inconsistent to count the reset controls via the device node (of_...), but then get them via the device (devm_reset_control_get_... instead of of_reset_control_get_...).

You are right, it looks inconsistent. I thought of using a resource managed API. But now i think it doesn't make much sense.

Best Regards
Vivek

Quoted 4 lines

regards
Philipp

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#7 lore raw
In reply to Vivek Gautam

Hi Philipp,

Quoted 6 lines · Vivek Gautam

Count number of reset phandles available with the device node to know the resets a given device has.

---

Any thoughts on this change?
A small addition that seems useful.

Quoted 44 lines

Based on torvald's master branch.

 include/linux/reset.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
include/linux/reset.h +16 -1
index 5daff15722d3..88f63a640153 100644
@@ -2,6 +2,7 @@
 #define _LINUX_RESET_H_
 
 #include <linux/device.h>
+#include <linux/of.h>
 
 struct reset_control;
 
@@ -234,6 +235,21 @@ static inline struct reset_control *of_reset_control_get_shared_by_index(
 }
 
 /**
+ * of_reset_control_get_count - Count number of resets available with a device
+ * @node: device to be reset by the controller
+ */
+static inline unsigned int of_reset_control_get_count(struct device_node *node)
+{
+       int count;
+
+       count = of_count_phandle_with_args(node, "resets", "#reset-cells");
+       if (count < 0)
+               return 0;
+
+       return count;
+}
+
+/**
  * devm_reset_control_get_exclusive - resource managed
  *                                    reset_control_get_exclusive()
  * @dev: device to be reset by the controller
--

The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Regards
Vivek

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
maintainer
#8 lore raw

Hi Vivek,

Quoted 8 lines · Vivek Gautam

Hi Philipp,

Quoted 3 lines · Vivek Gautam

Count number of reset phandles available with the device node to know the resets a given device has.

Quoted 6 lines
Quoted 3 lines

---

Any thoughts on this change?
A small addition that seems useful.

Sorry I missed this one earlier.

Quoted 21 lines
Quoted 21 lines

Based on torvald's master branch.

 include/linux/reset.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
include/linux/reset.h +1 -0
index 5daff15722d3..88f63a640153 100644
@@ -2,6 +2,7 @@
 #define _LINUX_RESET_H_
 
 #include <linux/device.h>
+#include <linux/of.h>
 
 struct reset_control;
 
@@ -234,6 +235,21 @@ static inline struct reset_control *of_reset_control_get_shared_by_index(
 }
 
Quoted 11 lines

include/linux/reset.h static inline struct reset_control *of_reset_control_get_shared_by_index( · line 247

Quoted 11 lines
include/linux/reset.h +10 -0
 /**
+ * of_reset_control_get_count - Count number of resets available with a device
+ * @node: device to be reset by the controller
+ */
+static inline unsigned int of_reset_control_get_count(struct device_node *node)
+{
+       int count;
+
+       count = of_count_phandle_with_args(node, "resets", "#reset-cells");
+       if (count < 0)
+               return 0;

Please don't silently ignore errors. gpiod_count doesn't ignore errors either. tegra_powergate_of_resets in drivers/soc/tegra/pmc.c open codes this, too. This should be changed so it can be used there, too.

regards
Philipp

#9 lore raw

Hi Philipp,

Quoted 41 lines · Philipp Zabel

Hi Vivek,

Quoted 8 lines · Vivek Gautam

Hi Philipp,

Quoted 3 lines · Vivek Gautam

Count number of reset phandles available with the device node to know the resets a given device has.

Quoted 6 lines
Quoted 3 lines

---

Any thoughts on this change?
A small addition that seems useful.

Sorry I missed this one earlier.

Quoted 21 lines
Quoted 21 lines

Based on torvald's master branch.

 include/linux/reset.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
include/linux/reset.h +1 -0
index 5daff15722d3..88f63a640153 100644
@@ -2,6 +2,7 @@
 #define _LINUX_RESET_H_
 
 #include <linux/device.h>
+#include <linux/of.h>
 
 struct reset_control;
 
@@ -234,6 +235,21 @@ static inline struct reset_control *of_reset_control_get_shared_by_index(
 }
 
Quoted 15 lines
Quoted 11 lines

include/linux/reset.h static inline struct reset_control *of_reset_control_get_shared_by_index( · line 247

Quoted 11 lines
include/linux/reset.h +10 -0
 /**
+ * of_reset_control_get_count - Count number of resets available with a device
+ * @node: device to be reset by the controller
+ */
+static inline unsigned int of_reset_control_get_count(struct device_node *node)
+{
+       int count;
+
+       count = of_count_phandle_with_args(node, "resets", "#reset-cells");
+       if (count < 0)
+               return 0;

Please don't silently ignore errors. gpiod_count doesn't ignore errors either. tegra_powergate_of_resets in drivers/soc/tegra/pmc.c open codes this, too. This should be changed so it can be used there, too.

Sure, will change this. I can prepare a patch for tegra/pmc.c as well using this.

Best regards
Vivek

Quoted 8 lines

regards
Philipp

--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project