devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Leo Yan <leo.yan-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
To: Julien Thierry <julien.thierry-5wv7dgnIgG8@public.gmane.org>
Cc: Kaihua Zhong
	<zhongkaihua-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>,
	mturquette-rdvid1DuHRBWk0Htik3J/w@public.gmane.org,
	sboyd-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	mark.rutland-5wv7dgnIgG8@public.gmane.org,
	xuwei5-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org,
	catalin.marinas-5wv7dgnIgG8@public.gmane.org,
	will.deacon-5wv7dgnIgG8@public.gmane.org,
	xuejiancheng-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org,
	wenpan-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org,
	zhangfei.gao-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
	guodong.xu-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
	chenjun14-hv44wF8Li93QT0dZR+AlfA@public.gmane.org,
	linux-clk-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	suzhuangluan-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org,
	xuezhiliang-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org,
	kevin.wangtao-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org
Subject: Re: [PATCH 2/3] clk: hisilicon: Add support for Hi3660 stub clocks
Date: Fri, 10 Nov 2017 12:08:31 +0800	[thread overview]
Message-ID: <20171110040831.GA30162@leoy-linaro> (raw)
In-Reply-To: <f67c976f-12bc-185b-fe12-6a8e761dc392-5wv7dgnIgG8@public.gmane.org>

Hi Julien,

On Fri, Nov 03, 2017 at 05:37:34PM +0000, Julien Thierry wrote:
> Hi Kaihua,
> 
> On 03/11/17 07:25, Kaihua Zhong wrote:
> >Hi3660 has four stub clocks, which are big and LITTLE cluster clocks,
> >GPU clock and DDR clock.  These clocks ask MCU for frequency scaling
> >by sending message through mailbox.
> >
> >This commit adds support for stub clocks, it requests the dedicated
> >mailbox channel at initialization; then later uses this channel to send
> >message to MCU to execute frequency scaling. The four stub clocks share
> >the same mailbox channel, but every stub clock has its own command id so
> >MCU can distinguish the requirement coming for which clock.
> >
> >A shared memory is used to present effective frequency value, so the
> >clock driver uses I/O mapping for the memory and reads back rate value.
> >
> >Reviewed-by: Leo Yan <leo.yan-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> >Signed-off-by: Kai Zhao <zhaokai1-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org>
> >Signed-off-by: Kevin Wang <kevin.wangtao-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org>
> >Signed-off-by: Ruyi Wang <wangruyi-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
> >Signed-off-by: Kaihua Zhong <zhongkaihua-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
> >---
> >  drivers/clk/hisilicon/Kconfig            |   6 +
> >  drivers/clk/hisilicon/Makefile           |   1 +
> >  drivers/clk/hisilicon/clk-hi3660-stub.c  | 195 +++++++++++++++++++++++++++++++
> >  include/dt-bindings/clock/hi3660-clock.h |   7 ++
> >  4 files changed, 209 insertions(+)
> >  create mode 100644 drivers/clk/hisilicon/clk-hi3660-stub.c
> >
> >diff --git a/drivers/clk/hisilicon/Kconfig b/drivers/clk/hisilicon/Kconfig
> >index 7098bfd..1bd4355 100644
> >--- a/drivers/clk/hisilicon/Kconfig
> >+++ b/drivers/clk/hisilicon/Kconfig
> >@@ -49,3 +49,9 @@ config STUB_CLK_HI6220
> >  	default ARCH_HISI
> >  	help
> >  	  Build the Hisilicon Hi6220 stub clock driver.
> >+
> >+config STUB_CLK_HI3660
> >+	bool "Hi3660 Stub Clock Driver"
> >+	depends on COMMON_CLK_HI3660 && MAILBOX
> >+	help
> >+	  Build the Hisilicon Hi3660 stub clock driver.
> >diff --git a/drivers/clk/hisilicon/Makefile b/drivers/clk/hisilicon/Makefile
> >index 1e4c3dd..0a5b499 100644
> >--- a/drivers/clk/hisilicon/Makefile
> >+++ b/drivers/clk/hisilicon/Makefile
> >@@ -14,3 +14,4 @@ obj-$(CONFIG_COMMON_CLK_HI3798CV200)	+= crg-hi3798cv200.o
> >  obj-$(CONFIG_COMMON_CLK_HI6220)	+= clk-hi6220.o
> >  obj-$(CONFIG_RESET_HISI)	+= reset.o
> >  obj-$(CONFIG_STUB_CLK_HI6220)	+= clk-hi6220-stub.o
> >+obj-$(CONFIG_STUB_CLK_HI3660)	+= clk-hi3660-stub.o
> >diff --git a/drivers/clk/hisilicon/clk-hi3660-stub.c b/drivers/clk/hisilicon/clk-hi3660-stub.c
> >new file mode 100644
> >index 0000000..0a21c91
> >--- /dev/null
> >+++ b/drivers/clk/hisilicon/clk-hi3660-stub.c
> >@@ -0,0 +1,195 @@
> >+/*
> >+ * Hisilicon clock driver
> >+ *
> >+ * Copyright (c) 2013-2017 Hisilicon Limited.
> >+ * Copyright (c) 2017 Linaro Limited.
> >+ *
> >+ * Author: Kai Zhao <zhaokai1-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org>
> >+ * Author: Tao Wang <kevin.wangtao-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org>
> >+ * Author: Leo Yan <leo.yan-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> >+ *
> >+ * This program is free software; you can redistribute it and/or modify
> >+ * it under the terms of the GNU General Public License as published by
> >+ * the Free Software Foundation; either version 2 of the License, or
> >+ * (at your option) any later version.
> >+ *
> >+ * This program is distributed in the hope that it will be useful,
> >+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
> >+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> >+ * GNU General Public License for more details.
> >+ *
> >+ */
> >+
> >+#include <linux/clk-provider.h>
> >+#include <linux/device.h>
> >+#include <linux/err.h>
> >+#include <linux/init.h>
> >+#include <linux/mailbox_client.h>
> >+#include <linux/module.h>
> >+#include <linux/of.h>
> >+#include <linux/platform_device.h>
> >+#include <dt-bindings/clock/hi3660-clock.h>
> >+
> >+#define HI3660_STUB_CLOCK_DATA		(0x70)
> >+#define MHZ				(1000 * 1000)
> >+
> >+#define DEFINE_CLK_STUB(_id, _cmd, _name)			\
> >+	{							\
> >+		.id = (_id),					\
> >+		.cmd = (_cmd),					\
> >+		.hw.init = &(struct clk_init_data) {		\
> >+			.name = #_name,				\
> >+			.ops = &hi3660_stub_clk_ops,		\
> >+			.num_parents = 0,			\
> >+			.flags = CLK_GET_RATE_NOCACHE,		\
> >+		},						\
> >+	},
> >+
> >+#define to_stub_clk(_hw) container_of(_hw, struct hi3660_stub_clk, hw)
> >+
> >+struct hi3660_stub_clk_chan {
> >+	struct mbox_client cl;
> >+	struct mbox_chan *mbox;
> >+};
> >+
> >+struct hi3660_stub_clk {
> >+	unsigned int id;
> >+	struct device *dev;
> 
> I don't understand why you need to keep this. The only place it is used it
> for the debug message in hi3660_stub_clk_set_rate and you could get the
> device pointer by doing chan->cl.dev since all the stub_clk point to the
> same device.

Kaihua might miss this email, so I checked all your comments; accept
these comments and will spin for next version patch.

Thank you for good suggestions.

Thanks,
Leo Yan

> >+	struct clk_hw hw;
> >+	unsigned int cmd;
> >+	unsigned int msg[8];
> >+	unsigned int rate;
> >+};
> >+
> >+static void __iomem *freq_reg;
> >+static struct hi3660_stub_clk_chan *chan;
> 
> I would suggest having a slightly longer name than "chan" as this can easily
> get shadowed which is bad for a non-local variable.
> 
> Also, maybe you could not declare it as a pointer and avoid the need for
> kzalloc in the probe function.
> 
> >+
> >+static unsigned long hi3660_stub_clk_recalc_rate(struct clk_hw *hw,
> >+						 unsigned long parent_rate)
> >+{
> >+	struct hi3660_stub_clk *stub_clk = to_stub_clk(hw);
> >+
> >+	/*
> >+	 * LPM3 writes back the CPU frequency in shared SRAM so read
> >+	 * back the frequency.
> >+	 */
> >+	stub_clk->rate = readl(freq_reg + (stub_clk->id << 2)) * MHZ;
> >+	return stub_clk->rate;
> >+}
> >+
> >+static long hi3660_stub_clk_round_rate(struct clk_hw *hw, unsigned long rate,
> >+				       unsigned long *prate)
> >+{
> >+	/*
> >+	 * LPM3 handles rate rounding so just return whatever
> >+	 * rate is requested.
> >+	 */
> >+	return rate;
> >+}
> >+
> >+static int hi3660_stub_clk_set_rate(struct clk_hw *hw, unsigned long rate,
> >+				    unsigned long parent_rate)
> >+{
> >+	struct hi3660_stub_clk *stub_clk = to_stub_clk(hw);
> >+
> >+	stub_clk->msg[0] = stub_clk->cmd;
> >+	stub_clk->msg[1] = rate / MHZ;
> >+
> >+	dev_dbg(stub_clk->dev, "set rate msg[0]=0x%x msg[1]=0x%x\n",
> >+		stub_clk->msg[0], stub_clk->msg[1]);
> >+
> >+	mbox_send_message(chan->mbox, stub_clk->msg);
> >+	mbox_client_txdone(chan->mbox, 0);
> >+
> >+	stub_clk->rate = rate;
> >+	return 0;
> >+}
> >+
> >+static const struct clk_ops hi3660_stub_clk_ops = {
> >+	.recalc_rate    = hi3660_stub_clk_recalc_rate,
> >+	.round_rate     = hi3660_stub_clk_round_rate,
> >+	.set_rate       = hi3660_stub_clk_set_rate,
> >+};
> >+
> >+static struct hi3660_stub_clk hi3660_stub_clks[HI3660_CLK_STUB_NUM] = {
> >+	DEFINE_CLK_STUB(HI3660_CLK_STUB_CLUSTER0, 0x0001030A, "cpu-cluster.0")
> >+	DEFINE_CLK_STUB(HI3660_CLK_STUB_CLUSTER1, 0x0002030A, "cpu-cluster.1")
> >+	DEFINE_CLK_STUB(HI3660_CLK_STUB_GPU, 0x0003030A, "clk-g3d")
> >+	DEFINE_CLK_STUB(HI3660_CLK_STUB_DDR, 0x00040309, "clk-ddrc")
> >+};
> >+
> >+static struct clk_hw *hi3660_stub_clk_hw_get(struct of_phandle_args *clkspec,
> >+					     void *data)
> >+{
> >+	unsigned int idx = clkspec->args[0];
> >+
> >+	if (idx > HI3660_CLK_STUB_NUM) {
> >+		pr_err("%s: invalid index %u\n", __func__, idx);
> >+		return ERR_PTR(-EINVAL);
> >+	}
> >+
> >+	return &hi3660_stub_clks[idx].hw;
> >+}
> >+
> >+static int hi3660_stub_clk_probe(struct platform_device *pdev)
> >+{
> >+	struct device *dev = &pdev->dev;
> >+	struct resource *res;
> >+	unsigned int i;
> >+	int ret;
> >+
> >+	chan = devm_kzalloc(dev, sizeof(*chan), GFP_KERNEL);
> >+	if (!chan)
> >+		return -ENOMEM;
> >+
> >+	/* Use mailbox client without blocking */
> >+	chan->cl.dev = dev;
> >+	chan->cl.tx_done = NULL;
> >+	chan->cl.tx_block = false;
> >+	chan->cl.knows_txdone = false;
> >+
> >+	/* Allocate mailbox channel */
> >+	chan->mbox = mbox_request_channel(&chan->cl, 0);
> >+	if (IS_ERR(chan->mbox))
> >+		return PTR_ERR(chan->mbox);
> >+
> >+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> >+	freq_reg = devm_ioremap(dev, res->start, resource_size(res));
> >+	if (IS_ERR(freq_reg))
> >+		return -ENOMEM;
> >+
> >+	freq_reg += HI3660_STUB_CLOCK_DATA;
> >+
> >+	for (i = 0; i < HI3660_CLK_STUB_NUM; i++) {
> >+		hi3660_stub_clks[i].dev = dev;
> >+		ret = devm_clk_hw_register(&pdev->dev, &hi3660_stub_clks[i].hw);
> >+		if (ret)
> >+			return ret;
> >+	}
> >+
> >+	ret = of_clk_add_hw_provider(pdev->dev.of_node, hi3660_stub_clk_hw_get,
> >+				     hi3660_stub_clks);
> >+	if (ret)
> >+		return ret;
> >+
> >+	return 0;
> 
> Hmmm, you could just return ret here without needing the branch.
> 
> Cheers,
> 
> -- 
> Julien Thierry
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2017-11-10  4:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-03  7:25 [PATCH 0/3] Hi3660 stubclock drivers Kaihua Zhong
2017-11-03  7:25 ` [PATCH 1/3] dt-bindings: clk: Hi3660: Document stub clock Kaihua Zhong
2017-11-06 22:13   ` Rob Herring
2017-11-07  7:54     ` Leo Yan
2017-11-03  7:25 ` [PATCH 2/3] clk: hisilicon: Add support for Hi3660 stub clocks Kaihua Zhong
     [not found]   ` <1509693907-90682-3-git-send-email-zhongkaihua-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2017-11-03 17:37     ` Julien Thierry
     [not found]       ` <f67c976f-12bc-185b-fe12-6a8e761dc392-5wv7dgnIgG8@public.gmane.org>
2017-11-10  4:08         ` Leo Yan [this message]
2017-11-06 22:15   ` Rob Herring
2017-11-03  7:25 ` [PATCH 3/3] arm64: dts: Hi3660: Add binding for stub clock Kaihua Zhong

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=20171110040831.GA30162@leoy-linaro \
    --to=leo.yan-qsej5fyqhm4dnm+yrofe0a@public.gmane.org \
    --cc=catalin.marinas-5wv7dgnIgG8@public.gmane.org \
    --cc=chenjun14-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=guodong.xu-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=julien.thierry-5wv7dgnIgG8@public.gmane.org \
    --cc=kevin.wangtao-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-clk-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
    --cc=mturquette-rdvid1DuHRBWk0Htik3J/w@public.gmane.org \
    --cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=sboyd-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
    --cc=suzhuangluan-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org \
    --cc=wenpan-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org \
    --cc=will.deacon-5wv7dgnIgG8@public.gmane.org \
    --cc=xuejiancheng-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org \
    --cc=xuezhiliang-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org \
    --cc=xuwei5-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org \
    --cc=zhangfei.gao-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=zhongkaihua-hv44wF8Li93QT0dZR+AlfA@public.gmane.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).