All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dong Aisheng <aisheng.dong@nxp.com>
To: <linux-clk@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>, <aisheng.dong@nxp.com>,
	<kernel@pengutronix.de>, <broonie@kernel.org>,
	<yibin.gong@nxp.com>, <rjw@rjwysocki.net>,
	<viresh.kumar@linaro.org>, <mturquette@baylibre.com>,
	<sboyd@codeaurora.org>, <shawnguo@kernel.org>,
	<fabio.estevam@nxp.com>, <anson.huang@nxp.com>,
	<ping.bai@nxp.com>, <leonard.crestez@nxp.com>,
	<octavian.purdila@nxp.com>
Subject: [RFC PATCH 0/3] clk: introduce clk_bulk_get accessories
Date: Wed, 12 Apr 2017 12:03:26 +0800	[thread overview]
Message-ID: <1491969809-20154-1-git-send-email-aisheng.dong@nxp.com> (raw)

These helper function allows drivers to get several clk consumers in
one operation.  If any of the clk cannot be acquired then any clks
that were got will be put before returning to the caller.

The idea firstly came out when i wanted to clean up and optimize
imx6q-cpufreq driver which needs to handle a lot of clocks as it
becomes a bit mess.

e.g. drivers/cpufreq/imx6q-cpufreq.c

You will see we need get 7 clocks during driver probe.
(Add there will be more, e.g. pll1, pll1_bypass, pll1_bypass_src,
in the future when adding busfreq support).

static int imx6q_cpufreq_probe(struct platform_device *pdev)
{
....
	arm_clk = clk_get(cpu_dev, "arm");
	pll1_sys_clk = clk_get(cpu_dev, "pll1_sys");
	pll1_sw_clk = clk_get(cpu_dev, "pll1_sw");
	step_clk = clk_get(cpu_dev, "step");
	pll2_pfd2_396m_clk = clk_get(cpu_dev, "pll2_pfd2_396m");
	if (IS_ERR(arm_clk) || IS_ERR(pll1_sys_clk) || IS_ERR(pll1_sw_clk) ||
	    IS_ERR(step_clk) || IS_ERR(pll2_pfd2_396m_clk)) {
		dev_err(cpu_dev, "failed to get clocks\n");
		ret = -ENOENT;
		goto put_clk;
	}

	if (of_machine_is_compatible("fsl,imx6ul")) {
		pll2_bus_clk = clk_get(cpu_dev, "pll2_bus");
		secondary_sel_clk = clk_get(cpu_dev, "secondary_sel");
		if (IS_ERR(pll2_bus_clk) || IS_ERR(secondary_sel_clk)) {
			dev_err(cpu_dev, "failed to get clocks specific to imx6ul\n");
			ret = -ENOENT;
			goto put_clk;
		}
	}
....
put_clk: 
        if (!IS_ERR(arm_clk))
                clk_put(arm_clk);
        if (!IS_ERR(pll1_sys_clk))
                clk_put(pll1_sys_clk);
	...........
}

Together with the err path handling for each clocks, it does make
things a bit ugly.

Since we already have regulator_bulk_get accessories, i thought we
probably could introduce clk_bulk_get as well to handle such case to
ease the driver owners' life. 

Besides IMX cpufreq driver, there is also some similar cases
in kernel which could befinit from this api as well.
e.g.
drivers/cpufreq/tegra124-cpufreq.c
drivers/cpufreq/s3c2412-cpufreq.c
sound/soc/samsung/smdk_spdif.c
arch/arm/mach-omap1/serial.c
...

And actually, if we handle clocks more than 3, then it might be
worthy to try, which there is quite many manay in kernel and
that probably could save a lot codes.

This is a RFC patch intending to bring up the idea to discuss.

Comments are welcome and appreciated!

Dong Aisheng (3):
  clk: add clk_bulk_get accessories
  clk: add managed version of clk_bulk_get
  cpufreq: imx6q: refine clk operations

 drivers/clk/clk-devres.c        |  36 +++++++++++
 drivers/clk/clk.c               |  99 +++++++++++++++++++++++++++++
 drivers/clk/clkdev.c            |  42 +++++++++++++
 drivers/cpufreq/imx6q-cpufreq.c | 119 ++++++++++++++++-------------------
 include/linux/clk.h             | 135 ++++++++++++++++++++++++++++++++++++++++
 5 files changed, 365 insertions(+), 66 deletions(-)

-- 
2.7.4

WARNING: multiple messages have this Message-ID (diff)
From: aisheng.dong@nxp.com (Dong Aisheng)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH 0/3] clk: introduce clk_bulk_get accessories
Date: Wed, 12 Apr 2017 12:03:26 +0800	[thread overview]
Message-ID: <1491969809-20154-1-git-send-email-aisheng.dong@nxp.com> (raw)

These helper function allows drivers to get several clk consumers in
one operation.  If any of the clk cannot be acquired then any clks
that were got will be put before returning to the caller.

The idea firstly came out when i wanted to clean up and optimize
imx6q-cpufreq driver which needs to handle a lot of clocks as it
becomes a bit mess.

e.g. drivers/cpufreq/imx6q-cpufreq.c

You will see we need get 7 clocks during driver probe.
(Add there will be more, e.g. pll1, pll1_bypass, pll1_bypass_src,
in the future when adding busfreq support).

static int imx6q_cpufreq_probe(struct platform_device *pdev)
{
....
	arm_clk = clk_get(cpu_dev, "arm");
	pll1_sys_clk = clk_get(cpu_dev, "pll1_sys");
	pll1_sw_clk = clk_get(cpu_dev, "pll1_sw");
	step_clk = clk_get(cpu_dev, "step");
	pll2_pfd2_396m_clk = clk_get(cpu_dev, "pll2_pfd2_396m");
	if (IS_ERR(arm_clk) || IS_ERR(pll1_sys_clk) || IS_ERR(pll1_sw_clk) ||
	    IS_ERR(step_clk) || IS_ERR(pll2_pfd2_396m_clk)) {
		dev_err(cpu_dev, "failed to get clocks\n");
		ret = -ENOENT;
		goto put_clk;
	}

	if (of_machine_is_compatible("fsl,imx6ul")) {
		pll2_bus_clk = clk_get(cpu_dev, "pll2_bus");
		secondary_sel_clk = clk_get(cpu_dev, "secondary_sel");
		if (IS_ERR(pll2_bus_clk) || IS_ERR(secondary_sel_clk)) {
			dev_err(cpu_dev, "failed to get clocks specific to imx6ul\n");
			ret = -ENOENT;
			goto put_clk;
		}
	}
....
put_clk: 
        if (!IS_ERR(arm_clk))
                clk_put(arm_clk);
        if (!IS_ERR(pll1_sys_clk))
                clk_put(pll1_sys_clk);
	...........
}

Together with the err path handling for each clocks, it does make
things a bit ugly.

Since we already have regulator_bulk_get accessories, i thought we
probably could introduce clk_bulk_get as well to handle such case to
ease the driver owners' life. 

Besides IMX cpufreq driver, there is also some similar cases
in kernel which could befinit from this api as well.
e.g.
drivers/cpufreq/tegra124-cpufreq.c
drivers/cpufreq/s3c2412-cpufreq.c
sound/soc/samsung/smdk_spdif.c
arch/arm/mach-omap1/serial.c
...

And actually, if we handle clocks more than 3, then it might be
worthy to try, which there is quite many manay in kernel and
that probably could save a lot codes.

This is a RFC patch intending to bring up the idea to discuss.

Comments are welcome and appreciated!

Dong Aisheng (3):
  clk: add clk_bulk_get accessories
  clk: add managed version of clk_bulk_get
  cpufreq: imx6q: refine clk operations

 drivers/clk/clk-devres.c        |  36 +++++++++++
 drivers/clk/clk.c               |  99 +++++++++++++++++++++++++++++
 drivers/clk/clkdev.c            |  42 +++++++++++++
 drivers/cpufreq/imx6q-cpufreq.c | 119 ++++++++++++++++-------------------
 include/linux/clk.h             | 135 ++++++++++++++++++++++++++++++++++++++++
 5 files changed, 365 insertions(+), 66 deletions(-)

-- 
2.7.4

             reply	other threads:[~2017-04-11 12:06 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-12  4:03 Dong Aisheng [this message]
2017-04-12  4:03 ` [RFC PATCH 0/3] clk: introduce clk_bulk_get accessories Dong Aisheng
2017-04-11 17:01 ` Florian Fainelli
2017-04-11 17:01   ` Florian Fainelli
2017-04-13 13:58   ` Dong Aisheng
2017-04-13 13:58     ` Dong Aisheng
2017-04-12  4:03 ` [RFC PATCH 1/3] clk: add " Dong Aisheng
2017-04-12  4:03   ` Dong Aisheng
2017-04-11 17:19   ` Leonard Crestez
2017-04-11 17:19     ` Leonard Crestez
2017-04-13 14:02     ` Dong Aisheng
2017-04-13 14:02       ` Dong Aisheng
2017-04-13 19:57     ` Geert Uytterhoeven
2017-04-13 19:57       ` Geert Uytterhoeven
2017-04-13 19:57       ` Geert Uytterhoeven
2017-04-13 14:25   ` Dong Aisheng
2017-04-13 14:25     ` Dong Aisheng
2017-04-13 19:56   ` Geert Uytterhoeven
2017-04-13 19:56     ` Geert Uytterhoeven
2017-04-13 19:56     ` Geert Uytterhoeven
2017-04-14 16:14     ` Dong Aisheng
2017-04-14 16:14       ` Dong Aisheng
2017-04-14 16:14       ` Dong Aisheng
2017-04-22  3:16   ` Stephen Boyd
2017-04-22  3:16     ` Stephen Boyd
2017-05-08 11:34     ` Dong Aisheng
2017-05-08 11:34       ` Dong Aisheng
2017-04-12  4:03 ` [RFC PATCH 2/3] clk: add managed version of clk_bulk_get Dong Aisheng
2017-04-12  4:03   ` Dong Aisheng
2017-04-13 14:37   ` Dong Aisheng
2017-04-13 14:37     ` Dong Aisheng
2017-04-22  2:58     ` Stephen Boyd
2017-04-22  2:58       ` Stephen Boyd
2017-05-08 11:41       ` Dong Aisheng
2017-05-08 11:41         ` Dong Aisheng
2017-04-22  2:55   ` Stephen Boyd
2017-04-22  2:55     ` Stephen Boyd
2017-05-08 11:37     ` Dong Aisheng
2017-05-08 11:37       ` Dong Aisheng
2017-04-12  4:03 ` [RFC PATCH 3/3] cpufreq: imx6q: refine clk operations Dong Aisheng
2017-04-12  4:03   ` Dong Aisheng
2017-04-11 17:48   ` Leonard Crestez
2017-04-11 17:48     ` Leonard Crestez
2017-04-13 14:21     ` Dong Aisheng
2017-04-13 14:21       ` Dong Aisheng
2017-04-22  3:04 ` [RFC PATCH 0/3] clk: introduce clk_bulk_get accessories Stephen Boyd
2017-04-22  3:04   ` Stephen Boyd
2017-05-08 11:07   ` Dong Aisheng
2017-05-08 11:07     ` Dong Aisheng

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=1491969809-20154-1-git-send-email-aisheng.dong@nxp.com \
    --to=aisheng.dong@nxp.com \
    --cc=anson.huang@nxp.com \
    --cc=broonie@kernel.org \
    --cc=fabio.estevam@nxp.com \
    --cc=kernel@pengutronix.de \
    --cc=leonard.crestez@nxp.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=octavian.purdila@nxp.com \
    --cc=ping.bai@nxp.com \
    --cc=rjw@rjwysocki.net \
    --cc=sboyd@codeaurora.org \
    --cc=shawnguo@kernel.org \
    --cc=viresh.kumar@linaro.org \
    --cc=yibin.gong@nxp.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.