Skip to contentSkip to conversation

clk: hisilicon: support stub clock

PATCH Applied Leo Yan 3 participants 11 messages Aug 3, 2015 – Sep 2, 2015

Subsystems (3)

v3 of 4 Applied Latest is v4 →

lore
Share & tools
lore

Leo Yan

author
#0 lore raw

v3 cover clk: hisilicon: support stub clock

This series adds support for hisilicon stub clock driver. On hi6220, the bootloader needs load the firmware image and set info for OPPs; after run into kernel, the stub clock driver is used to communicate w/t firmware for cpu dynamic frequency scaling.

In patch series v1/v2, the stub clock driver simply writes request in sram and send ipc to firmware; For patch series v3, the firmware has been upgraded to use mailbox, so stub clock driver will call standard mailbox APIs to request mailbox channel and send message to firmware.

These patches have been tested on 96board hikey and is used by cpufreq driver.

Changes from v2:
* Use platform_device's probe for clock's initialization
* Use mailbox channel for clock frequency change

Changes from v1:
* Refine parameter checking for init flow
* Remove unnecessary debugging info
* Modify to check spinlock pointer when register clocks

Leo Yan (5):
clk: hisi: refine parameter checking for init
dt-bindings: arm: Hi6220: add doc for SRAM controller
dt-bindings: clk: Hi6220: Document stub clock driver
clk: Hi6220: add stub clock driver
arm64: dts: add Hi6220's stub clock node

 .../bindings/arm/hisilicon/hisilicon.txt           |  18 ++
 .../devicetree/bindings/clock/hi6220-clock.txt     |  19 +-
 arch/arm64/boot/dts/hisilicon/hi6220.dtsi          |  23 ++
 drivers/clk/hisilicon/Kconfig                      |   2 +-
 drivers/clk/hisilicon/Makefile                     |   2 +-
 drivers/clk/hisilicon/clk-hi6220-stub.c            | 279 +++++++++++++++++++++
 drivers/clk/hisilicon/clk.c                        |  11 +-
 7 files changed, 343 insertions(+), 11 deletions(-)
 create mode 100644 drivers/clk/hisilicon/clk-hi6220-stub.c
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH v3 1/5 clk: hisi: refine parameter checking for init

*of_iomap()* will check the device node pointer, and if the pointer is NULL it will return error code. So refine clock's init flow by checking the device node with this simple way; and polish a little for the print out message.

---
 drivers/clk/hisilicon/clk.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/clk/hisilicon/clk.c +3 -8
index c90a897..156435d 100644
@@ -45,14 +45,9 @@ struct hisi_clock_data __init *hisi_clk_init(struct device_node *np,
 	struct clk **clk_table;
 	void __iomem *base;
 
-	if (np) {
-		base = of_iomap(np, 0);
-		if (!base) {
-			pr_err("failed to map Hisilicon clock registers\n");
-			goto err;
-		}
-	} else {
-		pr_err("failed to find Hisilicon clock node in DTS\n");
+	base = of_iomap(np, 0);
+	if (!base) {
+		pr_err("%s: failed to map clock registers\n", __func__);
 		goto err;
 	}
 
Signature · 1 line
1.9.1
Applied
#2 lore raw

Re: [PATCH v3 1/5] clk: hisi: refine parameter checking for init

Quoted 7 lines · Leo Yan

*of_iomap()* will check the device node pointer, and if the pointer is NULL it will return error code. So refine clock's init flow by checking the device node with this simple way; and polish a little for the print out message.

---

Applied to clk-next

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

PATCH v3 2/5 dt-bindings: arm: Hi6220: add doc for SRAM controller

In reply to Leo Yan

Document "hisilicon,hi6220-sramctrl" for SRAM controller.

---
 .../devicetree/bindings/arm/hisilicon/hisilicon.txt    | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
Documentation/devicetree/bindings/arm/hisilicon/hisilicon.txt +18 -0
index c431c67..c733e28 100644
@@ -127,6 +127,24 @@ Example:
 		#clock-cells = <1>;
 	};
 
+
+Hisilicon Hi6220 SRAM controller
+
+Required properties:
+- compatible : "hisilicon,hi6220-sramctrl", "syscon"
+- reg : Register address and size
+
+Hisilicon's SoCs use sram for multiple purpose; on Hi6220 there have several
+SRAM banks for power management, modem, security, etc. Further, use "syscon"
+managing the common sram which can be shared by multiple modules.
+
+Example:
+	/*for Hi6220*/
+	sram: sram at fff80000 {
+		compatible = "hisilicon,hi6220-sramctrl", "syscon";
+		reg = <0x0 0xfff80000 0x0 0x12000>;
+	};
+
 -----------------------------------------------------------------------
 Hisilicon HiP01 system controller
 
Signature · 1 line
1.9.1
author
#4 lore raw

PATCH v3 3/5 dt-bindings: clk: Hi6220: Document stub clock driver

In reply to Leo Yan

Document the new compatible for stub clock driver which is used for CPU and DDR's dynamic frequency scaling.

---
 .../devicetree/bindings/clock/hi6220-clock.txt        | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/clock/hi6220-clock.txt +18 -1
index 259e30a..e4d5fea 100644
@@ -15,19 +15,36 @@ Required Properties:
 	- "hisilicon,hi6220-sysctrl"
 	- "hisilicon,hi6220-mediactrl"
 	- "hisilicon,hi6220-pmctrl"
+	- "hisilicon,hi6220-stub-clk"
 
 - reg: physical base address of the controller and length of memory mapped
   region.
 
 - #clock-cells: should be 1.
 
-For example:
+Optional Properties:
+
+- hisilicon,hi6220-clk-sram: phandle to the syscon managing the SoC internal sram;
+  the driver need use the sram to pass parameters for frequency change.
+
+- mboxes: use the label reference for the mailbox as the first parameter, the
+  second parameter is the channel number.
+
+Example 1:
 	sys_ctrl: sys_ctrl at f7030000 {
 		compatible = "hisilicon,hi6220-sysctrl", "syscon";
 		reg = <0x0 0xf7030000 0x0 0x2000>;
 		#clock-cells = <1>;
 	};
 
+Example 2:
+	stub_clock: stub_clock {
+		compatible = "hisilicon,hi6220-stub-clk";
+		hisilicon,hi6220-clk-sram = <&sram>;
+		#clock-cells = <1>;
+		mboxes = <&mailbox 1>;
+	};
+
 Each clock is assigned an identifier and client nodes use this identifier
 to specify the clock which they consume.
 
Signature · 1 line
1.9.1
author
#5 lore raw

PATCH v3 4/5 clk: Hi6220: add stub clock driver

In reply to Leo Yan

On Hi6220, there have some clocks which can use mailbox channel to send messages to power controller to change frequency; this includes CPU, GPU and DDR clocks.

For dynamic frequency scaling, firstly need write the frequency value to SRAM region, and then send message to mailbox to trigger power controller to handle this requirement. This driver will use syscon APIs to pass SRAM memory region and use common mailbox APIs for channels accessing.

This init driver will support cpu frequency change firstly.

---
 drivers/clk/hisilicon/Kconfig           |   2 +-
 drivers/clk/hisilicon/Makefile          |   2 +-
 drivers/clk/hisilicon/clk-hi6220-stub.c | 279 ++++++++++++++++++++++++++++++++
 3 files changed, 281 insertions(+), 2 deletions(-)
 create mode 100644 drivers/clk/hisilicon/clk-hi6220-stub.c
drivers/clk/hisilicon/Kconfig +1 -1
index b4165ba..2c16807 100644
@@ -1,6 +1,6 @@
 config COMMON_CLK_HI6220
 	bool "Hi6220 Clock Driver"
-	depends on ARCH_HISI || COMPILE_TEST
+	depends on (ARCH_HISI || COMPILE_TEST) && MAILBOX
 	default ARCH_HISI
 	help
 	  Build the Hisilicon Hi6220 clock driver based on the common clock framework.
drivers/clk/hisilicon/Makefile +1 -1
index 48f0116..4a1001a 100644
@@ -7,4 +7,4 @@ obj-y	+= clk.o clkgate-separated.o clkdivider-hi6220.o
 obj-$(CONFIG_ARCH_HI3xxx)	+= clk-hi3620.o
 obj-$(CONFIG_ARCH_HIP04)	+= clk-hip04.o
 obj-$(CONFIG_ARCH_HIX5HD2)	+= clk-hix5hd2.o
-obj-$(CONFIG_COMMON_CLK_HI6220)	+= clk-hi6220.o
+obj-$(CONFIG_COMMON_CLK_HI6220)	+= clk-hi6220.o clk-hi6220-stub.o
drivers/clk/hisilicon/clk-hi6220-stub.c new file +279 -0

279 lines not on this page · raw message

Signature · 1 line
1.9.1
#6 lore raw

Re: [PATCH v3 4/5] clk: Hi6220: add stub clock driver

Quoted 11 lines · Leo Yan
drivers/clk/hisilicon/clk-hi6220-stub.c new file +5 -0
new file mode 100644
index 0000000..0931666
@@ -0,0 +1,279 @@
+/*
+ * Hi6220 stub clock driver
+ *
+ * Copyright (c) 2015 Hisilicon Limited.
+ * Copyright (c) 2015 Linaro Limited.

drivers/clk/hisilicon/clk-hi6220-stub.c line 15

Quoted 10 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +10 -0
+ *
+ * Author: Leo Yan <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/clkdev.h>

Is this include used?

drivers/clk/hisilicon/clk-hi6220-stub.c line 17

Quoted 2 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +2 -0
+#include <linux/clk-provider.h>
+#include <linux/clk.h>

Is this include used?

Quoted 21 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +21 -0
+#include <linux/err.h>
+#include <linux/mfd/syscon.h>
+#include <linux/mailbox_client.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+#include <linux/kernel.h>
+
+#include <dt-bindings/clock/hi6220-clock.h>
+
+/* Stub clocks id */
+#define HI6220_STUB_ACPU0		0
+#define HI6220_STUB_ACPU1		1
+#define HI6220_STUB_GPU			2
+#define HI6220_STUB_DDR			5
+
+/* Mailbox message */
+#define HI6220_MBOX_MSG_LEN		8
+
+#define HI6220_MBOX_FREQ		(0xA)

drivers/clk/hisilicon/clk-hi6220-stub.c line 48

Quoted 10 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +10 -0
+#define HI6220_MBOX_CMD_SET		(0x3)
+#define HI6220_MBOX_OBJ_AP		(0x0)
+
+/* CPU dynamic frequency scaling */
+#define ACPU_DFS_FREQ_MAX		(0x1724)
+#define ACPU_DFS_CUR_FREQ		(0x17CC)
+#define ACPU_DFS_FLAG			(0x1B30)
+#define ACPU_DFS_FREQ_REQ		(0x1B34)
+#define ACPU_DFS_FREQ_LMT		(0x1B38)
+#define ACPU_DFS_LOCK_FLAG		(0xAEAEAEAE)

We don't need parenthesis around single values in these macros.

Quoted 32 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +32 -0
+
+#define to_stub_clk(hw) container_of(hw, struct hi6220_stub_clk, hw)
+
+struct hi6220_stub_clk {
+	u32 id;
+	u32 rate;
+
+	struct device *dev;
+	struct clk_hw hw;
+
+	struct regmap *dfs_map;
+	struct mbox_client cl;
+	struct mbox_chan *mbox;
+};
+
+struct hi6220_mbox_msg {
+	unsigned char type;
+	unsigned char cmd;
+	unsigned char obj;
+	unsigned char src;
+	unsigned char para[4];
+};
+
+union hi6220_mbox_data {
+	unsigned int data[HI6220_MBOX_MSG_LEN];
+	struct hi6220_mbox_msg msg;
+};
+
+static unsigned int hi6220_acpu_get_freq(struct hi6220_stub_clk *stub_clk)
+{
+	unsigned int freq;
+

drivers/clk/hisilicon/clk-hi6220-stub.c line 90

Quoted 10 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +10 -0
+	regmap_read(stub_clk->dfs_map, ACPU_DFS_CUR_FREQ, &freq);
+	return freq;
+}
+
+static int hi6220_acpu_set_freq(struct hi6220_stub_clk *stub_clk,
+				unsigned int freq)
+{
+	union hi6220_mbox_data data;
+
+	stub_clk->mbox = mbox_request_channel(&stub_clk->cl, 0);

Why not request the channel once in probe?

Quoted 16 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +16 -0
+	if (IS_ERR(stub_clk->mbox)) {
+		dev_err(stub_clk->dev, "failed get mailbox channel\n");
+		return PTR_ERR(stub_clk->mbox);
+	};
+
+	/* set the frequency in sram */
+	regmap_write(stub_clk->dfs_map, ACPU_DFS_FREQ_REQ, freq);
+
+	/* compound mailbox message */
+	data.msg.type = HI6220_MBOX_FREQ;
+	data.msg.cmd  = HI6220_MBOX_CMD_SET;
+	data.msg.obj  = HI6220_MBOX_OBJ_AP;
+	data.msg.src  = HI6220_MBOX_OBJ_AP;
+
+	mbox_send_message(stub_clk->mbox, &data);
+	mbox_free_channel(stub_clk->mbox);

drivers/clk/hisilicon/clk-hi6220-stub.c line 116

Quoted 10 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +10 -0
+	return 0;
+}
+
+static int hi6220_acpu_round_freq(struct hi6220_stub_clk *stub_clk,
+				  unsigned int freq)
+{
+	unsigned int limit_flag, limit_freq = UINT_MAX;
+	unsigned int max_freq;
+
+	/* check the constrainted frequency */

s/constrainted/constrained/ ?

Quoted 17 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +17 -0
+	regmap_read(stub_clk->dfs_map, ACPU_DFS_FLAG, &limit_flag);
+	if (limit_flag == ACPU_DFS_LOCK_FLAG)
+		regmap_read(stub_clk->dfs_map, ACPU_DFS_FREQ_LMT, &limit_freq);
+
+	/* check the supported maximum frequency */
+	regmap_read(stub_clk->dfs_map, ACPU_DFS_FREQ_MAX, &max_freq);
+
+	/* calculate the real maximum frequency */
+	max_freq = min(max_freq, limit_freq);
+
+	if (WARN_ON(freq > max_freq))
+		freq = max_freq;
+
+	return freq;
+}
+
+static unsigned long hi6220_stub_clk_recalc_rate(struct clk_hw *hw,

drivers/clk/hisilicon/clk-hi6220-stub.c line 143

Quoted 10 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +10 -0
+		unsigned long parent_rate)
+{
+	u32 rate = 0;
+	struct hi6220_stub_clk *stub_clk = to_stub_clk(hw);
+
+	switch (stub_clk->id) {
+	case HI6220_STUB_ACPU0:
+		rate = hi6220_acpu_get_freq(stub_clk);
+
+		/* convert from KHz to Hz */

s/KHz/kHz/ ?

Quoted 7 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +7 -0
+		rate *= 1000;
+		break;
+
+	default:
+		dev_err(stub_clk->dev, "%s: un-supported clock id %d\n",
+			__func__, stub_clk->id);
+		break;

drivers/clk/hisilicon/clk-hi6220-stub.c line 160

Quoted 10 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +10 -0
+	}
+
+	return rate;
+}
+
+static int hi6220_stub_clk_set_rate(struct clk_hw *hw, unsigned long rate,
+                    unsigned long parent_rate)
+{
+	struct hi6220_stub_clk *stub_clk = to_stub_clk(hw);
+	unsigned long new_rate = rate / 1000;  /* Khz */

s/KHz/kHz/ ?

Quoted 7 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +7 -0
+	int ret = 0;
+
+	switch (stub_clk->id) {
+	case HI6220_STUB_ACPU0:
+		ret = hi6220_acpu_set_freq(stub_clk, new_rate);
+		if (ret < 0)
+			return ret;

drivers/clk/hisilicon/clk-hi6220-stub.c line 177

Quoted 10 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +10 -0
+
+		break;
+
+	default:
+		dev_err(stub_clk->dev, "%s: un-supported clock id %d\n",
+			__func__, stub_clk->id);
+		break;
+	}
+
+	stub_clk->rate = new_rate;

Why do we store away the rate? Is this used anywhere?

drivers/clk/hisilicon/clk-hi6220-stub.c line 187

Quoted 10 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +10 -0
+
+	pr_debug("%s: set rate=%ldKhz\n", __func__, new_rate);
+	return ret;
+}
+
+static long hi6220_stub_clk_round_rate(struct clk_hw *hw, unsigned long rate,
+		unsigned long *parent_rate)
+{
+	struct hi6220_stub_clk *stub_clk = to_stub_clk(hw);
+	unsigned long new_rate = rate / 1000;  /* Khz */

s/KHz/kHz/ ?

drivers/clk/hisilicon/clk-hi6220-stub.c line 193

Quoted 6 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +6 -0
+
+	switch (stub_clk->id) {
+	case HI6220_STUB_ACPU0:
+		new_rate = hi6220_acpu_round_freq(stub_clk, new_rate);
+
+		/* convert from KHz to Hz */

s/KHz/kHz/ ?

drivers/clk/hisilicon/clk-hi6220-stub.c line 206

Quoted 13 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +13 -0
+		new_rate *= 1000;
+		break;
+
+	default:
+		dev_err(stub_clk->dev, "%s: un-supported clock id %d\n",
+			__func__, stub_clk->id);
+		break;
+	}
+
+	return new_rate;
+}
+
+static struct clk_ops hi6220_stub_clk_ops = {

const?

Quoted 4 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +4 -0
+	.recalc_rate	= hi6220_stub_clk_recalc_rate,
+	.round_rate	= hi6220_stub_clk_round_rate,
+	.set_rate	= hi6220_stub_clk_set_rate,
+};

drivers/clk/hisilicon/clk-hi6220-stub.c line 220

Quoted 10 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +10 -0
+
+static int hi6220_stub_clk_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct clk_init_data init;
+	struct hi6220_stub_clk *stub_clk;
+	struct clk *clk;
+	struct device_node *np = pdev->dev.of_node;
+
+	stub_clk = devm_kzalloc(&pdev->dev, sizeof(*stub_clk), GFP_KERNEL);

just use dev?

Quoted 6 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +6 -0
+	if (!stub_clk)
+		return -ENOMEM;
+
+	stub_clk->dfs_map = syscon_regmap_lookup_by_phandle(np,
+				"hisilicon,hi6220-clk-sram");
+	if (IS_ERR(stub_clk->dfs_map)) {

drivers/clk/hisilicon/clk-hi6220-stub.c line 236

Quoted 10 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +10 -0
+		dev_err(dev, "failed to get sram regmap\n");
+		return PTR_ERR(stub_clk->dfs_map);
+	}
+
+	stub_clk->hw.init = &init;
+	stub_clk->dev = dev;
+	stub_clk->id = HI6220_STUB_ACPU0;
+
+	/* Use mailbox client with blocking mode */
+	stub_clk->cl.dev = &pdev->dev;

just use dev?

drivers/clk/hisilicon/clk-hi6220-stub.c line 247

Quoted 11 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +11 -0
+	stub_clk->cl.tx_done = NULL;
+	stub_clk->cl.tx_block = true;
+	stub_clk->cl.tx_tout = 500;
+	stub_clk->cl.knows_txdone = false;
+
+	init.name = "acpu0";
+	init.ops = &hi6220_stub_clk_ops;
+	init.num_parents = 0;
+	init.flags = CLK_IS_ROOT;
+
+	clk = clk_register(NULL, &stub_clk->hw);

why not devm_clk_register?

drivers/clk/hisilicon/clk-hi6220-stub.c line 251

Quoted 4 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +4 -0
+	if (IS_ERR(clk))
+		return PTR_ERR(clk);
+
+	of_clk_add_provider(pdev->dev.of_node, of_clk_src_simple_get, clk);

And check this for an error return value? Also, just use dev?

drivers/clk/hisilicon/clk-hi6220-stub.c line 258

Quoted 7 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +7 -0
+
+	/* initialize buffer to zero */
+	regmap_write(stub_clk->dfs_map, ACPU_DFS_FLAG, 0x0);
+	regmap_write(stub_clk->dfs_map, ACPU_DFS_FREQ_REQ, 0x0);
+	regmap_write(stub_clk->dfs_map, ACPU_DFS_FREQ_LMT, 0x0);
+
+	dev_dbg(&pdev->dev, "Registered clock '%s'\n", init.name);

just use dev?

drivers/clk/hisilicon/clk-hi6220-stub.c line 270

Quoted 12 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +12 -0
+	return 0;
+}
+
+static const struct of_device_id hi6220_stub_clk_of_match[] = {
+	{ .compatible = "hisilicon,hi6220-stub-clk", },
+	{}
+};
+
+static struct platform_driver hi6220_stub_clk_driver = {
+	.driver	= {
+		.name = "hi6220-stub-clk",
+		.of_match_table = of_match_ptr(hi6220_stub_clk_of_match),

We can leave off of_match_ptr() here.

Quoted 3 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +3 -0
+	},
+	.probe = hi6220_stub_clk_probe,
+};
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
author
#7 lore raw

Re: [PATCH v3 4/5] clk: Hi6220: add stub clock driver

Hi Stephen,

Quoted 328 lines · Stephen Boyd
Quoted 11 lines · Leo Yan
drivers/clk/hisilicon/clk-hi6220-stub.c new file +5 -0
new file mode 100644
index 0000000..0931666
@@ -0,0 +1,279 @@
+/*
+ * Hi6220 stub clock driver
+ *
+ * Copyright (c) 2015 Hisilicon Limited.
+ * Copyright (c) 2015 Linaro Limited.

drivers/clk/hisilicon/clk-hi6220-stub.c line 15

Quoted 10 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +10 -0
+ *
+ * Author: Leo Yan <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/clkdev.h>

Is this include used?

drivers/clk/hisilicon/clk-hi6220-stub.c line 17

Quoted 2 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +2 -0
+#include <linux/clk-provider.h>
+#include <linux/clk.h>

Is this include used?

Quoted 21 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +21 -0
+#include <linux/err.h>
+#include <linux/mfd/syscon.h>
+#include <linux/mailbox_client.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+#include <linux/kernel.h>
+
+#include <dt-bindings/clock/hi6220-clock.h>
+
+/* Stub clocks id */
+#define HI6220_STUB_ACPU0		0
+#define HI6220_STUB_ACPU1		1
+#define HI6220_STUB_GPU			2
+#define HI6220_STUB_DDR			5
+
+/* Mailbox message */
+#define HI6220_MBOX_MSG_LEN		8
+
+#define HI6220_MBOX_FREQ		(0xA)

drivers/clk/hisilicon/clk-hi6220-stub.c line 48

Quoted 10 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +10 -0
+#define HI6220_MBOX_CMD_SET		(0x3)
+#define HI6220_MBOX_OBJ_AP		(0x0)
+
+/* CPU dynamic frequency scaling */
+#define ACPU_DFS_FREQ_MAX		(0x1724)
+#define ACPU_DFS_CUR_FREQ		(0x17CC)
+#define ACPU_DFS_FLAG			(0x1B30)
+#define ACPU_DFS_FREQ_REQ		(0x1B34)
+#define ACPU_DFS_FREQ_LMT		(0x1B38)
+#define ACPU_DFS_LOCK_FLAG		(0xAEAEAEAE)

We don't need parenthesis around single values in these macros.

Quoted 32 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +32 -0
+
+#define to_stub_clk(hw) container_of(hw, struct hi6220_stub_clk, hw)
+
+struct hi6220_stub_clk {
+	u32 id;
+	u32 rate;
+
+	struct device *dev;
+	struct clk_hw hw;
+
+	struct regmap *dfs_map;
+	struct mbox_client cl;
+	struct mbox_chan *mbox;
+};
+
+struct hi6220_mbox_msg {
+	unsigned char type;
+	unsigned char cmd;
+	unsigned char obj;
+	unsigned char src;
+	unsigned char para[4];
+};
+
+union hi6220_mbox_data {
+	unsigned int data[HI6220_MBOX_MSG_LEN];
+	struct hi6220_mbox_msg msg;
+};
+
+static unsigned int hi6220_acpu_get_freq(struct hi6220_stub_clk *stub_clk)
+{
+	unsigned int freq;
+

drivers/clk/hisilicon/clk-hi6220-stub.c line 90

Quoted 10 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +10 -0
+	regmap_read(stub_clk->dfs_map, ACPU_DFS_CUR_FREQ, &freq);
+	return freq;
+}
+
+static int hi6220_acpu_set_freq(struct hi6220_stub_clk *stub_clk,
+				unsigned int freq)
+{
+	union hi6220_mbox_data data;
+
+	stub_clk->mbox = mbox_request_channel(&stub_clk->cl, 0);

Why not request the channel once in probe?

Quoted 16 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +16 -0
+	if (IS_ERR(stub_clk->mbox)) {
+		dev_err(stub_clk->dev, "failed get mailbox channel\n");
+		return PTR_ERR(stub_clk->mbox);
+	};
+
+	/* set the frequency in sram */
+	regmap_write(stub_clk->dfs_map, ACPU_DFS_FREQ_REQ, freq);
+
+	/* compound mailbox message */
+	data.msg.type = HI6220_MBOX_FREQ;
+	data.msg.cmd  = HI6220_MBOX_CMD_SET;
+	data.msg.obj  = HI6220_MBOX_OBJ_AP;
+	data.msg.src  = HI6220_MBOX_OBJ_AP;
+
+	mbox_send_message(stub_clk->mbox, &data);
+	mbox_free_channel(stub_clk->mbox);

drivers/clk/hisilicon/clk-hi6220-stub.c line 116

Quoted 10 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +10 -0
+	return 0;
+}
+
+static int hi6220_acpu_round_freq(struct hi6220_stub_clk *stub_clk,
+				  unsigned int freq)
+{
+	unsigned int limit_flag, limit_freq = UINT_MAX;
+	unsigned int max_freq;
+
+	/* check the constrainted frequency */

s/constrainted/constrained/ ?

Quoted 17 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +17 -0
+	regmap_read(stub_clk->dfs_map, ACPU_DFS_FLAG, &limit_flag);
+	if (limit_flag == ACPU_DFS_LOCK_FLAG)
+		regmap_read(stub_clk->dfs_map, ACPU_DFS_FREQ_LMT, &limit_freq);
+
+	/* check the supported maximum frequency */
+	regmap_read(stub_clk->dfs_map, ACPU_DFS_FREQ_MAX, &max_freq);
+
+	/* calculate the real maximum frequency */
+	max_freq = min(max_freq, limit_freq);
+
+	if (WARN_ON(freq > max_freq))
+		freq = max_freq;
+
+	return freq;
+}
+
+static unsigned long hi6220_stub_clk_recalc_rate(struct clk_hw *hw,

drivers/clk/hisilicon/clk-hi6220-stub.c line 143

Quoted 10 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +10 -0
+		unsigned long parent_rate)
+{
+	u32 rate = 0;
+	struct hi6220_stub_clk *stub_clk = to_stub_clk(hw);
+
+	switch (stub_clk->id) {
+	case HI6220_STUB_ACPU0:
+		rate = hi6220_acpu_get_freq(stub_clk);
+
+		/* convert from KHz to Hz */

s/KHz/kHz/ ?

Quoted 7 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +7 -0
+		rate *= 1000;
+		break;
+
+	default:
+		dev_err(stub_clk->dev, "%s: un-supported clock id %d\n",
+			__func__, stub_clk->id);
+		break;

drivers/clk/hisilicon/clk-hi6220-stub.c line 160

Quoted 10 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +10 -0
+	}
+
+	return rate;
+}
+
+static int hi6220_stub_clk_set_rate(struct clk_hw *hw, unsigned long rate,
+                    unsigned long parent_rate)
+{
+	struct hi6220_stub_clk *stub_clk = to_stub_clk(hw);
+	unsigned long new_rate = rate / 1000;  /* Khz */

s/KHz/kHz/ ?

Quoted 7 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +7 -0
+	int ret = 0;
+
+	switch (stub_clk->id) {
+	case HI6220_STUB_ACPU0:
+		ret = hi6220_acpu_set_freq(stub_clk, new_rate);
+		if (ret < 0)
+			return ret;

drivers/clk/hisilicon/clk-hi6220-stub.c line 177

Quoted 10 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +10 -0
+
+		break;
+
+	default:
+		dev_err(stub_clk->dev, "%s: un-supported clock id %d\n",
+			__func__, stub_clk->id);
+		break;
+	}
+
+	stub_clk->rate = new_rate;

Why do we store away the rate? Is this used anywhere?

drivers/clk/hisilicon/clk-hi6220-stub.c line 187

Quoted 10 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +10 -0
+
+	pr_debug("%s: set rate=%ldKhz\n", __func__, new_rate);
+	return ret;
+}
+
+static long hi6220_stub_clk_round_rate(struct clk_hw *hw, unsigned long rate,
+		unsigned long *parent_rate)
+{
+	struct hi6220_stub_clk *stub_clk = to_stub_clk(hw);
+	unsigned long new_rate = rate / 1000;  /* Khz */

s/KHz/kHz/ ?

drivers/clk/hisilicon/clk-hi6220-stub.c line 193

Quoted 6 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +6 -0
+
+	switch (stub_clk->id) {
+	case HI6220_STUB_ACPU0:
+		new_rate = hi6220_acpu_round_freq(stub_clk, new_rate);
+
+		/* convert from KHz to Hz */

s/KHz/kHz/ ?

drivers/clk/hisilicon/clk-hi6220-stub.c line 206

Quoted 13 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +13 -0
+		new_rate *= 1000;
+		break;
+
+	default:
+		dev_err(stub_clk->dev, "%s: un-supported clock id %d\n",
+			__func__, stub_clk->id);
+		break;
+	}
+
+	return new_rate;
+}
+
+static struct clk_ops hi6220_stub_clk_ops = {

const?

Quoted 4 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +4 -0
+	.recalc_rate	= hi6220_stub_clk_recalc_rate,
+	.round_rate	= hi6220_stub_clk_round_rate,
+	.set_rate	= hi6220_stub_clk_set_rate,
+};

drivers/clk/hisilicon/clk-hi6220-stub.c line 220

Quoted 10 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +10 -0
+
+static int hi6220_stub_clk_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct clk_init_data init;
+	struct hi6220_stub_clk *stub_clk;
+	struct clk *clk;
+	struct device_node *np = pdev->dev.of_node;
+
+	stub_clk = devm_kzalloc(&pdev->dev, sizeof(*stub_clk), GFP_KERNEL);

just use dev?

Quoted 6 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +6 -0
+	if (!stub_clk)
+		return -ENOMEM;
+
+	stub_clk->dfs_map = syscon_regmap_lookup_by_phandle(np,
+				"hisilicon,hi6220-clk-sram");
+	if (IS_ERR(stub_clk->dfs_map)) {

drivers/clk/hisilicon/clk-hi6220-stub.c line 236

Quoted 10 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +10 -0
+		dev_err(dev, "failed to get sram regmap\n");
+		return PTR_ERR(stub_clk->dfs_map);
+	}
+
+	stub_clk->hw.init = &init;
+	stub_clk->dev = dev;
+	stub_clk->id = HI6220_STUB_ACPU0;
+
+	/* Use mailbox client with blocking mode */
+	stub_clk->cl.dev = &pdev->dev;

just use dev?

drivers/clk/hisilicon/clk-hi6220-stub.c line 247

Quoted 11 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +11 -0
+	stub_clk->cl.tx_done = NULL;
+	stub_clk->cl.tx_block = true;
+	stub_clk->cl.tx_tout = 500;
+	stub_clk->cl.knows_txdone = false;
+
+	init.name = "acpu0";
+	init.ops = &hi6220_stub_clk_ops;
+	init.num_parents = 0;
+	init.flags = CLK_IS_ROOT;
+
+	clk = clk_register(NULL, &stub_clk->hw);

why not devm_clk_register?

drivers/clk/hisilicon/clk-hi6220-stub.c line 251

Quoted 4 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +4 -0
+	if (IS_ERR(clk))
+		return PTR_ERR(clk);
+
+	of_clk_add_provider(pdev->dev.of_node, of_clk_src_simple_get, clk);

And check this for an error return value? Also, just use dev?

drivers/clk/hisilicon/clk-hi6220-stub.c line 258

Quoted 7 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +7 -0
+
+	/* initialize buffer to zero */
+	regmap_write(stub_clk->dfs_map, ACPU_DFS_FLAG, 0x0);
+	regmap_write(stub_clk->dfs_map, ACPU_DFS_FREQ_REQ, 0x0);
+	regmap_write(stub_clk->dfs_map, ACPU_DFS_FREQ_LMT, 0x0);
+
+	dev_dbg(&pdev->dev, "Registered clock '%s'\n", init.name);

just use dev?

drivers/clk/hisilicon/clk-hi6220-stub.c line 270

Quoted 12 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +12 -0
+	return 0;
+}
+
+static const struct of_device_id hi6220_stub_clk_of_match[] = {
+	{ .compatible = "hisilicon,hi6220-stub-clk", },
+	{}
+};
+
+static struct platform_driver hi6220_stub_clk_driver = {
+	.driver	= {
+		.name = "hi6220-stub-clk",
+		.of_match_table = of_match_ptr(hi6220_stub_clk_of_match),

We can leave off of_match_ptr() here.

Quoted 3 lines

drivers/clk/hisilicon/clk-hi6220-stub.c line 273

Quoted 3 lines
drivers/clk/hisilicon/clk-hi6220-stub.c new file +3 -0
+	},
+	.probe = hi6220_stub_clk_probe,
+};

Thanks for review; Accept all comments and will refine for them :)

Thanks,
Leo Yan

#8 lore raw

Re: [PATCH v3 4/5] clk: Hi6220: add stub clock driver

In reply to Leo Yan
Quoted 4 lines · Leo Yan

On Hi6220, there have some clocks which can use mailbox channel to send messages to power controller to change frequency; this includes CPU, GPU and DDR clocks.

Quoted 8 lines

For dynamic frequency scaling, firstly need write the frequency value to SRAM region, and then send message to mailbox to trigger power controller to handle this requirement. This driver will use syscon APIs to pass SRAM memory region and use common mailbox APIs for channels accessing.

This init driver will support cpu frequency change firstly.

The kernelci.org build/boot bot detected boot failures in linux-next[1], and the failure was bisected down to this patch (landed in linux-next as commit c1628a2c416da947f5afac615d53189250fa49cb.

I verifed that reverting this commit on top of next-20150901 gets the hikey booting again.

Kevin

[1] http://kernelci.org/boot/hi6220-hikey/

author
#9 lore raw

Re: [PATCH v3 4/5] clk: Hi6220: add stub clock driver

Hi Kevin,

Quoted 12 lines · Kevin Hilman
Quoted 11 lines · Leo Yan

On Hi6220, there have some clocks which can use mailbox channel to send messages to power controller to change frequency; this includes CPU, GPU and DDR clocks.

For dynamic frequency scaling, firstly need write the frequency value to SRAM region, and then send message to mailbox to trigger power controller to handle this requirement. This driver will use syscon APIs to pass SRAM memory region and use common mailbox APIs for channels accessing.

This init driver will support cpu frequency change firstly.

Quoted 8 lines
Quoted 1 line

The kernelci.org build/boot bot detected boot failures in linux-next[1], and the failure was bisected down to this patch (landed in linux-next as commit c1628a2c416da947f5afac615d53189250fa49cb.

I verifed that reverting this commit on top of next-20150901 gets the hikey booting again.

Thanks for reporting. This issue has been confirmed at my side, it's caused by the patch have added dependency with MAILBOX, will fix this issue and send patch.

Thanks,
Leo Yan

author
#10 lore raw

PATCH v3 5/5 arm64: dts: add Hi6220's stub clock node

In reply to Leo Yan

Enable SRAM node and stub clock node for Hi6220; furthermore add the CPU's clock so it will be used by cpufreq-dt driver.

---
 arch/arm64/boot/dts/hisilicon/hi6220.dtsi | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
arch/arm64/boot/dts/hisilicon/hi6220.dtsi +23 -0
index b42a9b7..94b8310 100644
@@ -57,6 +57,17 @@
 			device_type = "cpu";
 			reg = <0x0 0x0>;
 			enable-method = "psci";
+			clocks = <&stub_clock 0>;
+			clock-latency = <0>;
+			operating-points = <
+				/* kHz */
+				1200000  0
+				960000   0
+				729000   0
+				432000   0
+				208000   0
+			>;
+			#cooling-cells = <2>; /* min followed by max */
 		};
 
 		cpu1: cpu at 1 {
@@ -136,6 +147,11 @@
 		#size-cells = <2>;
 		ranges;
 
+		sram: sram at fff80000 {
+			compatible = "hisilicon,hi6220-sramctrl", "syscon";
+			reg = <0x0 0xfff80000 0x0 0x12000>;
+		};
+
 		ao_ctrl: ao_ctrl at f7800000 {
 			compatible = "hisilicon,hi6220-aoctrl", "syscon";
 			reg = <0x0 0xf7800000 0x0 0x2000>;
@@ -160,6 +176,13 @@
 			#clock-cells = <1>;
 		};
 
+		stub_clock: stub_clock {
+			compatible = "hisilicon,hi6220-stub-clk";
+			hisilicon,hi6220-clk-sram = <&sram>;
+			#clock-cells = <1>;
+			mboxes = <&mailbox 1>;
+		};
+
 		uart0: uart at f8015000 {	/* console */
 			compatible = "arm,pl011", "arm,primecell";
 			reg = <0x0 0xf8015000 0x0 0x1000>;
Signature · 1 line
1.9.1