devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Chen <hzpeterchen@gmail.com>
To: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Cc: Peter Chen <peter.chen@nxp.com>,
	gregkh@linuxfoundation.org, stern@rowland.harvard.edu,
	ulf.hansson@linaro.org, broonie@kernel.org, sre@kernel.org,
	robh+dt@kernel.org, shawnguo@kernel.org, dbaryshkov@gmail.com,
	dwmw3@infradead.org, mark.rutland@arm.com,
	devicetree@vger.kernel.org, k.kozlowski@samsung.com,
	stephen.boyd@linaro.org, oscar@naiandei.net, arnd@arndb.de,
	pawel.moll@arm.com, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org, s.hauer@pengutronix.de,
	linux-usb@vger.kernel.org, mail@maciej.szmigiero.name,
	troy.kisky@boundarydevices.com, stillcompiling@gmail.com,
	p.zabel@pengutronix.de, festevam@gmail.com, mka@chromium.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v6 2/8] power: add power sequence library
Date: Fri, 2 Sep 2016 09:29:57 +0800	[thread overview]
Message-ID: <20160902012957.GC11262@shlinux2> (raw)
In-Reply-To: <4a08d6f8-1c6a-fa1b-0dfe-657afa4e8a90@linaro.org>

On Thu, Sep 01, 2016 at 01:32:56PM +0530, Vaibhav Hiremath wrote:
> >+static void pwrseq_generic_put(struct pwrseq *pwrseq)
> >+{
> >+	struct pwrseq_generic *pwrseq_gen = to_generic_pwrseq(pwrseq);
> >+	int clk;
> >+
> >+	if (pwrseq_gen->gpiod_reset)
> >+		gpiod_put(pwrseq_gen->gpiod_reset);
> >+
> >+	for (clk = 0; clk < PWRSEQ_MAX_CLKS; clk++)
> >+		clk_put(pwrseq_gen->clks[clk]);
> >+}
> >+
> >+static void pwrseq_generic_off(struct pwrseq *pwrseq)
> >+{
> >+	struct pwrseq_generic *pwrseq_gen = to_generic_pwrseq(pwrseq);
> >+	int clk;
> >+
> >+	for (clk = PWRSEQ_MAX_CLKS - 1; clk >= 0; clk--)
> >+		clk_disable_unprepare(pwrseq_gen->clks[clk]);
> >+}
> >+
> >+static int pwrseq_generic_on(struct device_node *np, struct pwrseq *pwrseq)
> Ideally you shouldn't need device_node here at this stage.
> I expect to extract all the resource information in _get() itself.
> 

Agree, I will move reset-duration-us property handling to pwrseq_get.

> >+{
> >+	struct pwrseq_generic *pwrseq_gen = to_generic_pwrseq(pwrseq);
> >+	int clk, ret = 0;
> >+	struct gpio_desc *gpiod_reset = pwrseq_gen->gpiod_reset;
> >+
> >+	for (clk = 0; clk < PWRSEQ_MAX_CLKS && pwrseq_gen->clks[clk]; clk++) {
> >+		ret = clk_prepare_enable(pwrseq_gen->clks[clk]);
> >+		if (ret) {
> >+			pr_err("Can't enable clock on %s: %d\n",
> >+				np->full_name, ret);
> >+			goto err_disable_clks;
> >+		}
> >+	}
> >+
> >+	if (gpiod_reset) {
> >+		u32 duration_us = 50;
> Why initialize to 50 ??
> 

This active duration is default value, and should work for most of
devices. If your device needs longer, you can change it at dts.

> >+
> >+		of_property_read_u32(np, "reset-duration-us",
> >+				&duration_us);
> >+		if (duration_us <= 10)
> >+			udelay(10);
> >+		else
> >+			usleep_range(duration_us, duration_us + 100);
> >+		gpiod_set_value(gpiod_reset, 0);
> >+	}
> >+
> >+	return ret;
> >+
> >+err_disable_clks:
> >+	while (--clk >= 0)
> >+		clk_disable_unprepare(pwrseq_gen->clks[clk]);
> >+
> >+	return ret;
> >+}
> >+
> >+static int pwrseq_generic_get(struct device_node *np, struct pwrseq *pwrseq)
> >+{
> >+	struct pwrseq_generic *pwrseq_gen = to_generic_pwrseq(pwrseq);
> >+	enum of_gpio_flags flags;
> >+	int reset_gpio, clk, ret = 0;
> >+
> >+	for (clk = 0; clk < PWRSEQ_MAX_CLKS; clk++) {
> >+		pwrseq_gen->clks[clk] = of_clk_get(np, clk);
> >+		if (IS_ERR(pwrseq_gen->clks[clk])) {
> >+			ret = PTR_ERR(pwrseq_gen->clks[clk]);
> >+			if (ret == -EPROBE_DEFER)
> >+				goto err_put_clks;
> >+			pwrseq_gen->clks[clk] = NULL;
> >+			break;
> 
> Do we really want to continue here, even we failed to get the clock ?

Ok, if it is -ENOENT, I set clk as NULL, for other error cases, I go to
error path.

> 
> >+		}
> >+	}
> >+
> >+	reset_gpio = of_get_named_gpio_flags(np, "reset-gpios", 0, &flags);
> >+	if (gpio_is_valid(reset_gpio)) {
> >+		unsigned long gpio_flags;
> >+
> >+		if (flags & OF_GPIO_ACTIVE_LOW)
> >+			gpio_flags = GPIOF_ACTIVE_LOW | GPIOF_OUT_INIT_LOW;
> >+		else
> >+			gpio_flags = GPIOF_OUT_INIT_HIGH;
> >+
> >+		ret = gpio_request_one(reset_gpio, gpio_flags,
> >+				"pwrseq-reset-gpios");
> >+		if (ret)
> >+			goto err_put_clks;
> >+
> >+		pwrseq_gen->gpiod_reset = gpio_to_desc(reset_gpio);
> >+	} else {
> >+		if (reset_gpio == -ENOENT)
> >+			return 0;
> 
> Why are we returning success here ?
> 

The property "reset-gpios" is optional, it can be nonexistent.

> >+
> >+		ret = reset_gpio;
> >+		pr_err("Failed to get reset gpio on %s, err = %d\n",
> >+				np->full_name, reset_gpio);
> >+		goto err_put_clks;
> >+	}
> >+
> >+	return ret;
> >+
> >+err_put_clks:
> >+	while (--clk >= 0)
> >+		clk_put(pwrseq_gen->clks[clk]);
> >+	return ret;
> >+}
> >+
> >+struct pwrseq *pwrseq_alloc_generic(void)
> >+{
> >+	struct pwrseq_generic *pwrseq_gen;
> >+
> >+	pwrseq_gen = kzalloc(sizeof(*pwrseq_gen), GFP_KERNEL);
> >+	if (!pwrseq_gen)
> >+		return ERR_PTR(-ENOMEM);
> >+
> >+	pwrseq_gen->pwrseq.get = pwrseq_generic_get;
> >+	pwrseq_gen->pwrseq.on = pwrseq_generic_on;
> >+	pwrseq_gen->pwrseq.off = pwrseq_generic_off;
> >+	pwrseq_gen->pwrseq.put = pwrseq_generic_put;
> >+	pwrseq_gen->pwrseq.free = pwrseq_generic_free;
> >+
> >+	return &pwrseq_gen->pwrseq;
> >+}
> >+EXPORT_SYMBOL_GPL(pwrseq_alloc_generic);
> 
> With recent discussion on postcore_initcall, we probably can merge
> _get() and _alloc() fns.
> 

At postcore_initcall, I plan to allocate individual pwrseq library, and
add it to pwrseq list. The consumer tries to get the resources.

Peter

> Thanks,
> Vaibhav
> >diff --git a/include/linux/power/pwrseq.h b/include/linux/power/pwrseq.h
> >new file mode 100644
> >index 0000000..ebb2280
> >--- /dev/null
> >+++ b/include/linux/power/pwrseq.h
> >@@ -0,0 +1,47 @@
> >+#ifndef __LINUX_PWRSEQ_H
> >+#define __LINUX_PWRSEQ_H
> >+
> >+#include <linux/of.h>
> >+
> >+#define PWRSEQ_MAX_CLKS		3
> >+
> >+struct pwrseq {
> >+	char *name;
> >+	struct list_head node;
> >+	int (*get)(struct device_node *np, struct pwrseq *p);
> >+	int (*on)(struct device_node *np, struct pwrseq *p);
> >+	void (*off)(struct pwrseq *p);
> >+	void (*put)(struct pwrseq *p);
> >+	void (*free)(struct pwrseq *p);
> >+};
> >+
> >+#if IS_ENABLED(CONFIG_POWER_SEQUENCE)
> >+int pwrseq_get(struct device_node *np, struct pwrseq *p);
> >+int pwrseq_on(struct device_node *np, struct pwrseq *p);
> >+void pwrseq_off(struct pwrseq *p);
> >+void pwrseq_put(struct pwrseq *p);
> >+void pwrseq_free(struct pwrseq *p);
> >+#else
> >+static inline int pwrseq_get(struct device_node *np, struct pwrseq *p)
> >+{
> >+	return 0;
> >+}
> >+static inline int pwrseq_on(struct device_node *np, struct pwrseq *p)
> >+{
> >+	return 0;
> >+}
> >+static inline void pwrseq_off(struct pwrseq *p) {}
> >+static inline void pwrseq_put(struct pwrseq *p) {}
> >+static inline void pwrseq_free(struct pwrseq *p) {}
> >+#endif /* CONFIG_POWER_SEQUENCE */
> >+
> >+#if IS_ENABLED(CONFIG_PWRSEQ_GENERIC)
> >+struct pwrseq *pwrseq_alloc_generic(void);
> >+#else
> >+static inline struct pwrseq *pwrseq_alloc_generic(void)
> >+{
> >+	return NULL;
> >+}
> >+#endif /* CONFIG_PWRSEQ_GENERIC */
> >+
> >+#endif  /* __LINUX_PWRSEQ_H */
> 
> -- 
> Thanks,
> Vaibhav
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 

Best Regards,
Peter Chen

  reply	other threads:[~2016-09-02  1:29 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-15  9:13 [PATCH v6 0/8] power: add power sequence library Peter Chen
2016-08-15  9:13 ` [PATCH v6 1/8] binding-doc: power: pwrseq-generic: add binding doc for generic " Peter Chen
     [not found]   ` <1471252398-957-2-git-send-email-peter.chen-3arQi8VN3Tc@public.gmane.org>
2016-09-01  8:03     ` Vaibhav Hiremath
     [not found]       ` <6832cc55-831a-1188-4878-bbbf0b3c3be8-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-09-02  1:00         ` Peter Chen
2016-09-06  6:04           ` Vaibhav Hiremath
2016-08-15  9:13 ` [PATCH v6 2/8] power: add " Peter Chen
2016-08-22  6:51   ` Peter Chen
2016-08-22 10:23     ` Sebastian Reichel
2016-08-23  1:25       ` Peter Chen
2016-09-01  8:02   ` Vaibhav Hiremath
2016-09-02  1:29     ` Peter Chen [this message]
     [not found] ` <1471252398-957-1-git-send-email-peter.chen-3arQi8VN3Tc@public.gmane.org>
2016-08-15  9:13   ` [PATCH v6 3/8] binding-doc: usb: usb-device: add optional properties for power sequence Peter Chen
2016-08-15  9:13   ` [PATCH v6 7/8] ARM: dts: imx6qdl-udoo.dtsi: fix onboard USB HUB property Peter Chen
2016-08-15  9:13   ` [PATCH v6 8/8] ARM: dts: imx6q-evi: Fix onboard hub reset line Peter Chen
2016-08-15  9:13 ` [PATCH v6 4/8] usb: core: add power sequence handling for USB devices Peter Chen
2016-08-22  6:53   ` Peter Chen
2016-08-22 16:09     ` Alan Stern
2016-08-23  3:10       ` Peter Chen
2016-08-23 15:37         ` Alan Stern
2016-09-01  8:02   ` Vaibhav Hiremath
2016-09-02  1:30     ` Peter Chen
2016-08-15  9:13 ` [PATCH v6 5/8] usb: chipidea: let chipidea core device of_node equal's glue layer device of_node Peter Chen
2016-08-15  9:13 ` [PATCH v6 6/8] ARM: dts: imx6qdl: Enable usb node children with <reg> Peter Chen
2016-08-23 10:32 ` [PATCH v6 0/8] power: add power sequence library Vaibhav Hiremath
     [not found]   ` <b1848eb2-9298-9089-ee4d-5356998c6c08-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-08-24  8:53     ` Peter Chen
2016-08-29 11:10       ` Peter Chen
2016-08-31  8:16         ` Vaibhav Hiremath
     [not found]           ` <3a45793f-18d9-0688-d2ab-ef79432c473c-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-08-31  9:52             ` Peter Chen
2016-08-31 16:58               ` Vaibhav Hiremath
2016-09-02  1:10                 ` Peter Chen
2016-09-06 10:18                   ` Vaibhav Hiremath
2016-09-09  8:47                     ` Ulf Hansson
2016-09-19  7:39                       ` Vaibhav Hiremath
     [not found]                         ` <ecbc3c0d-4ce7-758d-7f7d-4b3f3003c1ac-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-09-19  7:46                           ` Peter Chen
2016-09-19  8:17                             ` Vaibhav Hiremath

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160902012957.GC11262@shlinux2 \
    --to=hzpeterchen@gmail.com \
    --cc=arnd@arndb.de \
    --cc=broonie@kernel.org \
    --cc=dbaryshkov@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dwmw3@infradead.org \
    --cc=festevam@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=k.kozlowski@samsung.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mail@maciej.szmigiero.name \
    --cc=mark.rutland@arm.com \
    --cc=mka@chromium.org \
    --cc=oscar@naiandei.net \
    --cc=p.zabel@pengutronix.de \
    --cc=pawel.moll@arm.com \
    --cc=peter.chen@nxp.com \
    --cc=robh+dt@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=sre@kernel.org \
    --cc=stephen.boyd@linaro.org \
    --cc=stern@rowland.harvard.edu \
    --cc=stillcompiling@gmail.com \
    --cc=troy.kisky@boundarydevices.com \
    --cc=ulf.hansson@linaro.org \
    --cc=vaibhav.hiremath@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).