diff mbox

[v2,3/4] usb: dwc3: of-simple: Add support to get resets for the device

Message ID 1491226922-20307-4-git-send-email-vivek.gautam@codeaurora.org
State Superseded
Headers show

Commit Message

Vivek Gautam April 3, 2017, 1:42 p.m. UTC
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.

Cc: Felipe Balbi <balbi@kernel.org>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Vivek Gautam <vivek.gautam@codeaurora.org>
---

Changes since v1:
 - Using new APIs for reset control array.
 - Using the *_get_exclusive() API.
 - Added reset_control_array_put() to error and driver removal path.

 drivers/usb/dwc3/dwc3-of-simple.c | 45 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

Comments

kernel test robot April 4, 2017, 5:20 a.m. UTC | #1
Hi Vivek,

[auto build test WARNING on balbi-usb/next]
[also build test WARNING on v4.11-rc5 next-20170403]
[cannot apply to pza/reset/next]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Vivek-Gautam/reset-APIs-to-manage-a-list-of-resets/20170404-111639
base:   https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next


coccinelle warnings: (new ones prefixed by >>)

>> drivers/usb/dwc3/dwc3-of-simple.c:53:43-49: ERROR: application of sizeof to pointer

Please review and possibly fold the followup patch.

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
--
To unsubscribe from this list: send the line "unsubscribe linux-tegra" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
kernel test robot April 4, 2017, 5:34 a.m. UTC | #2
Hi Vivek,

[auto build test WARNING on balbi-usb/next]
[also build test WARNING on v4.11-rc5 next-20170403]
[cannot apply to pza/reset/next]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Vivek-Gautam/reset-APIs-to-manage-a-list-of-resets/20170404-111639
base:   https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next
config: i386-randconfig-r0-201714 (attached as .config)
compiler: gcc-5 (Debian 5.4.1-2) 5.4.1 20160904
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All warnings (new ones prefixed by >>):

   In file included from drivers/usb/dwc3/dwc3-of-simple.c:32:0:
   include/linux/reset.h:106:1: error: expected identifier or '(' before '{' token
    {
    ^
   include/linux/reset.h: In function 'devm_reset_control_array_get':
   include/linux/reset.h:127:9: warning: return makes integer from pointer without a cast [-Wint-conversion]
     return optional ? NULL : ERR_PTR(-ENOTSUPP);
            ^
   include/linux/reset.h: In function 'of_reset_control_array_get':
   include/linux/reset.h:135:9: warning: return makes integer from pointer without a cast [-Wint-conversion]
     return optional ? NULL : ERR_PTR(-ENOTSUPP);
            ^
   drivers/usb/dwc3/dwc3-of-simple.c: At top level:
>> include/linux/reset.h:105:19: warning: 'of_reset_control_get_count' used but never defined
    static inline int of_reset_control_get_count(struct device_node *node);
                      ^

vim +/of_reset_control_get_count +105 include/linux/reset.h

bb475230 Ramiro Oliveira 2017-01-13   99  					struct device *dev, const char *id,
bb475230 Ramiro Oliveira 2017-01-13  100  					int index, bool shared, bool optional)
5bcd0b7f Axel Lin        2015-09-01  101  {
0ca10b60 Philipp Zabel   2017-03-20  102  	return optional ? NULL : ERR_PTR(-ENOTSUPP);
5bcd0b7f Axel Lin        2015-09-01  103  }
5bcd0b7f Axel Lin        2015-09-01  104  
045cc544 Vivek Gautam    2017-04-03 @105  static inline int of_reset_control_get_count(struct device_node *node);
045cc544 Vivek Gautam    2017-04-03  106  {
045cc544 Vivek Gautam    2017-04-03  107  	return -ENOTSUPP;
045cc544 Vivek Gautam    2017-04-03  108  }
045cc544 Vivek Gautam    2017-04-03  109  
d5652c65 Vivek Gautam    2017-04-03  110  static inline int reset_control_array_assert(int num_rsts,
d5652c65 Vivek Gautam    2017-04-03  111  				struct reset_control_array *resets)
d5652c65 Vivek Gautam    2017-04-03  112  {
d5652c65 Vivek Gautam    2017-04-03  113  	return 0;
d5652c65 Vivek Gautam    2017-04-03  114  }
d5652c65 Vivek Gautam    2017-04-03  115  
d5652c65 Vivek Gautam    2017-04-03  116  static inline int reset_control_array_deassert(int num_rsts,
d5652c65 Vivek Gautam    2017-04-03  117  				struct reset_control_array *resets)
d5652c65 Vivek Gautam    2017-04-03  118  {
d5652c65 Vivek Gautam    2017-04-03  119  	return 0;
d5652c65 Vivek Gautam    2017-04-03  120  }
d5652c65 Vivek Gautam    2017-04-03  121  
d5652c65 Vivek Gautam    2017-04-03  122  static inline
d5652c65 Vivek Gautam    2017-04-03  123  int devm_reset_control_array_get(struct device *dev, int num_rsts,
d5652c65 Vivek Gautam    2017-04-03  124  				struct reset_control_array *resets,
d5652c65 Vivek Gautam    2017-04-03  125  				bool shared, bool optional)
d5652c65 Vivek Gautam    2017-04-03  126  {
d5652c65 Vivek Gautam    2017-04-03 @127  	return optional ? NULL : ERR_PTR(-ENOTSUPP);
d5652c65 Vivek Gautam    2017-04-03  128  }
d5652c65 Vivek Gautam    2017-04-03  129  
d5652c65 Vivek Gautam    2017-04-03  130  static inline

:::::: The code at line 105 was first introduced by commit
:::::: 045cc544119a744cda92da0644066f18cb3760b4 reset: Add API to count number of reset available with device

:::::: TO: Vivek Gautam <vivek.gautam@codeaurora.org>
:::::: CC: 0day robot <fengguang.wu@intel.com>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox

Patch

diff --git a/drivers/usb/dwc3/dwc3-of-simple.c b/drivers/usb/dwc3/dwc3-of-simple.c
index fe414e7a9c78..96786f5ede0b 100644
--- a/drivers/usb/dwc3/dwc3-of-simple.c
+++ b/drivers/usb/dwc3/dwc3-of-simple.c
@@ -29,13 +29,48 @@ 
 #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;
+	int			num_resets;
+	struct reset_control_array *resets;
 };
 
+static int dwc3_of_simple_reset_init(struct dwc3_of_simple *simple, int count)
+{
+	struct device		*dev = simple->dev;
+	int			ret;
+
+	/* Not all platforms have resets, so don't return a failure */
+	if (count < 0)
+		return 0;
+
+	simple->num_resets = count;
+
+	simple->resets = devm_kcalloc(dev, count, sizeof(simple->resets),
+							GFP_KERNEL);
+	if (!simple->resets)
+		return -ENOMEM;
+
+	ret = of_reset_control_array_get_exclusive(dev->of_node, count,
+							simple->resets);
+	if (ret) {
+		dev_err(dev, "failed to get device resets\n");
+		return ret;
+	}
+
+	ret = reset_control_array_deassert(count, simple->resets);
+	if (ret) {
+		reset_control_array_put(count, simple->resets);
+		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 +135,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 +146,9 @@  static int dwc3_of_simple_probe(struct platform_device *pdev)
 			clk_put(simple->clks[i]);
 		}
 
+		reset_control_array_assert(simple->num_resets, simple->resets);
+		reset_control_array_put(simple->num_resets, simple->resets);
+
 		return ret;
 	}
 
@@ -128,6 +170,9 @@  static int dwc3_of_simple_remove(struct platform_device *pdev)
 		clk_put(simple->clks[i]);
 	}
 
+	reset_control_array_assert(simple->num_resets, simple->resets);
+	reset_control_array_put(simple->num_resets, simple->resets);
+
 	of_platform_depopulate(dev);
 
 	pm_runtime_put_sync(dev);