Skip to contentSkip to conversation

clk: hi6220: Add the hi655x's pmic clock

PATCH Superseded Daniel Lezcano 3 participants 13 messages Apr 8, 2017 – Apr 24, 2017

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 clk: hi6220: Add the hi655x's pmic clock

The hi655x multi function device is a PMIC providing regulators.

The PMIC also provides a clock for the WiFi and the Bluetooth, let's implement this clock in order to add it in the hi655x MFD and allow proper wireless initialization.

---

Changelog:

V2:
- Added COMPILE_TEST option, compiled on x86
- Removed useless parenthesis
- Used of_clk_hw_simple_get() instead of deref dance
- Do bailout if the clock-names is not specified
- Rollback on error
- Folded mfd line change and binding
- Added #clock-cells binding documentation
- Added #clock-cells in the DT

V1: initial post
---

---
 .../devicetree/bindings/mfd/hisilicon,hi655x.txt   |   6 +
 arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts     |   1 +
 drivers/clk/Kconfig                                |   8 ++
 drivers/clk/Makefile                               |   1 +
 drivers/clk/clk-hi655x.c                           | 140 +++++++++++++++++++++
 drivers/mfd/hi655x-pmic.c                          |   3 +-
 6 files changed, 158 insertions(+), 1 deletion(-)
 create mode 100644 drivers/clk/clk-hi655x.c
Documentation/devicetree/bindings/mfd/hisilicon,hi655x.txt +6 -0
index 0548569..194e2a9fd 100644
@@ -16,6 +16,11 @@ Required properties:
 - reg:                  Base address of PMIC on Hi6220 SoC.
 - interrupt-controller: Hi655x has internal IRQs (has own IRQ domain).
 - pmic-gpios:           The GPIO used by PMIC IRQ.
+- #clock-cells:		From common clock binding; shall be set to 0
+
+Optional properties:
+- clock-output-names: From common clock binding to override the
+  default output clock name
 
 Example:
 	pmic: pmic at f8000000 {
@@ -24,4 +29,5 @@ Example:
 		interrupt-controller;
 		#interrupt-cells = <2>;
 		pmic-gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>;
+		clock-cells = <0>;
 	}
arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts +1 -0
index dba3c13..bb9afb1 100644
@@ -328,6 +328,7 @@
 		interrupt-controller;
 		#interrupt-cells = <2>;
 		pmic-gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>;
+		#clock-cells = <0>;
 
 		regulators {
 			ldo2: LDO2 {
drivers/clk/Kconfig +8 -0
index 9356ab4..36cfea3 100644
@@ -47,6 +47,14 @@ config COMMON_CLK_RK808
 	  clocked at 32KHz each. Clkout1 is always on, Clkout2 can off
 	  by control register.
 
+config COMMON_CLK_HI655X
+	tristate "Clock driver for Hi655x"
+	depends on MFD_HI655X_PMIC || COMPILE_TEST
+	---help---
+	  This driver supports the hi655x PMIC clock. This
+	  multi-function device has one fixed-rate oscillator, clocked
+	  at 32KHz.
+
 config COMMON_CLK_SCPI
 	tristate "Clock driver controlled via SCPI interface"
 	depends on ARM_SCPI_PROTOCOL || COMPILE_TEST
drivers/clk/Makefile +1 -0
index 92c12b8..c19983a 100644
@@ -36,6 +36,7 @@ obj-$(CONFIG_COMMON_CLK_PALMAS)		+= clk-palmas.o
 obj-$(CONFIG_COMMON_CLK_PWM)		+= clk-pwm.o
 obj-$(CONFIG_CLK_QORIQ)			+= clk-qoriq.o
 obj-$(CONFIG_COMMON_CLK_RK808)		+= clk-rk808.o
+obj-$(CONFIG_COMMON_CLK_HI655X)		+= clk-hi655x.o
 obj-$(CONFIG_COMMON_CLK_S2MPS11)	+= clk-s2mps11.o
 obj-$(CONFIG_COMMON_CLK_SCPI)           += clk-scpi.o
 obj-$(CONFIG_COMMON_CLK_SI5351)		+= clk-si5351.o
drivers/clk/clk-hi655x.c new file +140 -0

140 lines not on this page · raw message

drivers/mfd/hi655x-pmic.c +2 -1
index ba706ad..c37ccbf 100644
@@ -77,7 +77,8 @@
 		.num_resources	= ARRAY_SIZE(pwrkey_resources),
 		.resources	= &pwrkey_resources[0],
 	},
-	{	.name		= "hi655x-regulator", },
+	{	.name		= "hi655x-regulator",	},
+	{	.name		= "hi655x-clk",		},
 };
 
 static void hi655x_local_irq_clear(struct regmap *map)
Signature · 1 line
1.9.1
#1 lore raw
Quoted 11 lines · Daniel Lezcano

The hi655x multi function device is a PMIC providing regulators.

The PMIC also provides a clock for the WiFi and the Bluetooth, let's implement this clock in order to add it in the hi655x MFD and allow proper wireless initialization.

---

Changelog:

Quoted 7 lines

V2:
- Added COMPILE_TEST option, compiled on x86
- Removed useless parenthesis
- Used of_clk_hw_simple_get() instead of deref dance
- Do bailout if the clock-names is not specified
- Rollback on error
- Folded mfd line change and binding

Why did you do that?

Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#2 lore raw
Quoted 21 lines · Lee Jones
Quoted 11 lines · Daniel Lezcano

The hi655x multi function device is a PMIC providing regulators.

The PMIC also provides a clock for the WiFi and the Bluetooth, let's implement this clock in order to add it in the hi655x MFD and allow proper wireless initialization.

---

Changelog:

Quoted 7 lines

V2:
- Added COMPILE_TEST option, compiled on x86
- Removed useless parenthesis
- Used of_clk_hw_simple_get() instead of deref dance
- Do bailout if the clock-names is not specified
- Rollback on error
- Folded mfd line change and binding

Quoted 1 line

Why did you do that?

I thought as the V1 had comments you would have waited for the V2 and as it was trivial enough, it could be folded and picked up via the clk tree via with your acked-by.

I realize it was not a good idea.

Do you want to drop it from your tree or shall I resubmit a V3 without the mfd change?

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org ? Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#3 lore raw
Quoted 22 lines · Daniel Lezcano
Quoted 21 lines · Lee Jones
Quoted 18 lines · Daniel Lezcano

The hi655x multi function device is a PMIC providing regulators.

The PMIC also provides a clock for the WiFi and the Bluetooth, let's implement this clock in order to add it in the hi655x MFD and allow proper wireless initialization.

---

Changelog:

V2:
- Added COMPILE_TEST option, compiled on x86
- Removed useless parenthesis
- Used of_clk_hw_simple_get() instead of deref dance
- Do bailout if the clock-names is not specified
- Rollback on error
- Folded mfd line change and binding

Quoted 5 lines
Quoted 1 line

Why did you do that?

I thought as the V1 had comments you would have waited for the V2 and as it was trivial enough, it could be folded and picked up via the clk tree via with your acked-by.

It's *always* a good idea to keep patches subsystem orthogonal if at all possible.

Quoted 4 lines

I realize it was not a good idea.

Do you want to drop it from your tree or shall I resubmit a V3 without the mfd change?

The latter please.

Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#4 lore raw
Quoted 12 lines · Lee Jones
Quoted 10 lines · Daniel Lezcano
Quoted 9 lines · Lee Jones
Quoted 7 lines · Daniel Lezcano

The hi655x multi function device is a PMIC providing regulators.

The PMIC also provides a clock for the WiFi and the Bluetooth, let's implement this clock in order to add it in the hi655x MFD and allow proper wireless initialization.

[ ... ]

Quoted 4 lines
Quoted 2 lines

Do you want to drop it from your tree or shall I resubmit a V3 without the mfd change?

The latter please.

Ok.

What about the DT binding change?

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org ? Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#5 lore raw
Quoted 16 lines · Daniel Lezcano
Quoted 12 lines · Lee Jones
Quoted 10 lines · Daniel Lezcano
Quoted 9 lines · Lee Jones
Quoted 7 lines · Daniel Lezcano

The hi655x multi function device is a PMIC providing regulators.

The PMIC also provides a clock for the WiFi and the Bluetooth, let's implement this clock in order to add it in the hi655x MFD and allow proper wireless initialization.

[ ... ]

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Do you want to drop it from your tree or shall I resubmit a V3 without the mfd change?

The latter please.

Ok.

What about the DT binding change?

If I haven't merged it already, you'll need to re-send that (separately) too.

Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#6 lore raw
In reply to Daniel Lezcano

Documentation/devicetree/bindings/mfd/hisilicon,hi655x.txt Example: · line 32

Quoted 8 lines · Daniel Lezcano

Example:

Documentation/devicetree/bindings/mfd/hisilicon,hi655x.txt +1 -0
 	pmic: pmic at f8000000 {
@@ -24,4 +29,5 @@ Example:
 		interrupt-controller;
 		#interrupt-cells = <2>;
 		pmic-gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>;
+		clock-cells = <0>;

Should be #clock-cells instead.

Quoted 19 lines
(quoted diff) +0 -0
 	}
drivers/clk/Makefile +1 -0
index 92c12b8..c19983a 100644
@@ -36,6 +36,7 @@ obj-$(CONFIG_COMMON_CLK_PALMAS)		+= clk-palmas.o
 obj-$(CONFIG_COMMON_CLK_PWM)		+= clk-pwm.o
 obj-$(CONFIG_CLK_QORIQ)			+= clk-qoriq.o
 obj-$(CONFIG_COMMON_CLK_RK808)		+= clk-rk808.o
+obj-$(CONFIG_COMMON_CLK_HI655X)		+= clk-hi655x.o
 obj-$(CONFIG_COMMON_CLK_S2MPS11)	+= clk-s2mps11.o
 obj-$(CONFIG_COMMON_CLK_SCPI)           += clk-scpi.o
 obj-$(CONFIG_COMMON_CLK_SI5351)		+= clk-si5351.o
drivers/clk/clk-hi655x.c new file +0 -0
new file mode 100644
index 0000000..b2bea32

drivers/clk/clk-hi655x.c line 6

Quoted 6 lines
drivers/clk/clk-hi655x.c new file +6 -0
@@ -0,0 +1,140 @@
+
+static int hi655x_clk_probe(struct platform_device *pdev)
+{
+	struct device *parent = pdev->dev.parent;
+	struct hi655x_pmic *hi655x = dev_get_drvdata(parent);
+	struct clk_init_data *hi655x_clk_init;

This can just go onto the stack? We don't need it around after probe.

Quoted 24 lines
drivers/clk/clk-hi655x.c new file +24 -0
+	struct hi655x_clk *hi655x_clk;
+	const char *clk_name = "hi655x-clk";
+	int ret;
+
+	hi655x_clk = devm_kzalloc(&pdev->dev, sizeof(*hi655x_clk), GFP_KERNEL);
+	if (!hi655x_clk)
+		return -ENOMEM;
+
+	hi655x_clk_init = devm_kzalloc(&pdev->dev, sizeof(*hi655x_clk_init),
+				       GFP_KERNEL);
+	if (!hi655x_clk_init)
+		return -ENOMEM;
+
+	of_property_read_string_index(parent->of_node, "clock-output-names",
+				      0, &clk_name);
+
+	hi655x_clk_init->name	= clk_name;
+	hi655x_clk_init->ops	= &hi655x_clk_ops;
+
+	hi655x_clk->clk_hw.init	= hi655x_clk_init;
+	hi655x_clk->hi655x	= hi655x;
+
+	platform_set_drvdata(pdev, hi655x_clk);
+

drivers/clk/clk-hi655x.c line 121

Quoted 10 lines
drivers/clk/clk-hi655x.c new file +10 -0
+	ret = devm_clk_hw_register(&pdev->dev, &hi655x_clk->clk_hw);
+	if (ret)
+		return ret;
+
+	ret = of_clk_add_hw_provider(parent->of_node, of_clk_hw_simple_get,
+				     &hi655x_clk->clk_hw);
+	if (ret)
+		return ret;
+
+	ret = clk_hw_register_clkdev(&hi655x_clk->clk_hw, clk_name, NULL);

Missed this last time. Do you use this clkdev lookup? The name is usually supposed to be based on what the device is expecting, instead of clk_name, and we would want some device name for the third argument here.

Quoted 4 lines
drivers/clk/clk-hi655x.c new file +4 -0
+	if (ret)
+		of_clk_del_provider(parent->of_node);
+
+	return ret;
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#7 lore raw
Quoted 11 lines · Stephen Boyd

Documentation/devicetree/bindings/mfd/hisilicon,hi655x.txt Example: · line 32

Quoted 8 lines · Daniel Lezcano

Example:

Documentation/devicetree/bindings/mfd/hisilicon,hi655x.txt +1 -0
 	pmic: pmic at f8000000 {
@@ -24,4 +29,5 @@ Example:
 		interrupt-controller;
 		#interrupt-cells = <2>;
 		pmic-gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>;
+		clock-cells = <0>;

Should be #clock-cells instead.

Ok.

Quoted 8 lines

drivers/clk/clk-hi655x.c line 87

Quoted 5 lines
drivers/clk/clk-hi655x.c new file +5 -0
+static int hi655x_clk_probe(struct platform_device *pdev)
+{
+	struct device *parent = pdev->dev.parent;
+	struct hi655x_pmic *hi655x = dev_get_drvdata(parent);
+	struct clk_init_data *hi655x_clk_init;

This can just go onto the stack? We don't need it around after probe.

Agree.

Quoted 31 lines
Quoted 31 lines
drivers/clk/clk-hi655x.c new file +31 -0
+	struct hi655x_clk *hi655x_clk;
+	const char *clk_name = "hi655x-clk";
+	int ret;
+
+	hi655x_clk = devm_kzalloc(&pdev->dev, sizeof(*hi655x_clk), GFP_KERNEL);
+	if (!hi655x_clk)
+		return -ENOMEM;
+
+	hi655x_clk_init = devm_kzalloc(&pdev->dev, sizeof(*hi655x_clk_init),
+				       GFP_KERNEL);
+	if (!hi655x_clk_init)
+		return -ENOMEM;
+
+	of_property_read_string_index(parent->of_node, "clock-output-names",
+				      0, &clk_name);
+
+	hi655x_clk_init->name	= clk_name;
+	hi655x_clk_init->ops	= &hi655x_clk_ops;
+
+	hi655x_clk->clk_hw.init	= hi655x_clk_init;
+	hi655x_clk->hi655x	= hi655x;
+
+	platform_set_drvdata(pdev, hi655x_clk);
+
+	ret = devm_clk_hw_register(&pdev->dev, &hi655x_clk->clk_hw);
+	if (ret)
+		return ret;
+
+	ret = of_clk_add_hw_provider(parent->of_node, of_clk_hw_simple_get,
+				     &hi655x_clk->clk_hw);
+	if (ret)
Quoted 8 lines

drivers/clk/clk-hi655x.c line 121

Quoted 3 lines
drivers/clk/clk-hi655x.c new file +3 -0
+		return ret;
+
+	ret = clk_hw_register_clkdev(&hi655x_clk->clk_hw, clk_name, NULL);

Missed this last time. Do you use this clkdev lookup? The name is usually supposed to be based on what the device is expecting, instead of clk_name, and we would want some device name for the third argument here.

I'm not sure to get your comment. Are you saying the clk_name should be the third argument?

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org ? Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#8 lore raw
Quoted 43 lines · Daniel Lezcano
Quoted 33 lines · Stephen Boyd
Quoted 31 lines · Daniel Lezcano
drivers/clk/clk-hi655x.c new file +31 -0
+	struct hi655x_clk *hi655x_clk;
+	const char *clk_name = "hi655x-clk";
+	int ret;
+
+	hi655x_clk = devm_kzalloc(&pdev->dev, sizeof(*hi655x_clk), GFP_KERNEL);
+	if (!hi655x_clk)
+		return -ENOMEM;
+
+	hi655x_clk_init = devm_kzalloc(&pdev->dev, sizeof(*hi655x_clk_init),
+				       GFP_KERNEL);
+	if (!hi655x_clk_init)
+		return -ENOMEM;
+
+	of_property_read_string_index(parent->of_node, "clock-output-names",
+				      0, &clk_name);
+
+	hi655x_clk_init->name	= clk_name;
+	hi655x_clk_init->ops	= &hi655x_clk_ops;
+
+	hi655x_clk->clk_hw.init	= hi655x_clk_init;
+	hi655x_clk->hi655x	= hi655x;
+
+	platform_set_drvdata(pdev, hi655x_clk);
+
+	ret = devm_clk_hw_register(&pdev->dev, &hi655x_clk->clk_hw);
+	if (ret)
+		return ret;
+
+	ret = of_clk_add_hw_provider(parent->of_node, of_clk_hw_simple_get,
+				     &hi655x_clk->clk_hw);
+	if (ret)
Quoted 8 lines

drivers/clk/clk-hi655x.c line 121

Quoted 3 lines
drivers/clk/clk-hi655x.c new file +3 -0
+		return ret;
+
+	ret = clk_hw_register_clkdev(&hi655x_clk->clk_hw, clk_name, NULL);

Missed this last time. Do you use this clkdev lookup? The name is usually supposed to be based on what the device is expecting, instead of clk_name, and we would want some device name for the third argument here.

Quoted 4 lines

I'm not sure to get your comment. Are you saying the clk_name should be the third argument?

Sorry, no. I meant that con_id is typically something like "core" or "ahb" or something like that, and dev_id is something like "a456002.pmic_device" or whatever dev_name(pmic_dev) would return for the consuming device. That way when we call clk_get(dev, "core") it will find the lookup with "core" and "a456002.pmic_device" to match up the clk lookup.

If anything, the clk_name should just go into the con_id for now, and then it will need to be a globally unique identifier for the clk. But that is going against how clkdev is supposed to be used. Hence the question if you even need to use it. If not, just don't add it. I can fix up v3 of this patch to put clk_name back at con_id if you like. No need to resend.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#9 lore raw
Quoted 3 lines · Stephen Boyd
Quoted 2 lines · Daniel Lezcano
Quoted 1 line · Stephen Boyd

On 04/08, Daniel Lezcano wrote:

[ ... ]

Quoted 19 lines
Quoted 11 lines
Quoted 6 lines

drivers/clk/clk-hi655x.c line 121

Quoted 1 line
drivers/clk/clk-hi655x.c new file +1 -0
+	ret = clk_hw_register_clkdev(&hi655x_clk->clk_hw, clk_name, NULL);

Missed this last time. Do you use this clkdev lookup? The name is usually supposed to be based on what the device is expecting, instead of clk_name, and we would want some device name for the third argument here.

I'm not sure to get your comment. Are you saying the clk_name should be the third argument?

Sorry, no. I meant that con_id is typically something like "core" or "ahb" or something like that, and dev_id is something like "a456002.pmic_device" or whatever dev_name(pmic_dev) would return for the consuming device. That way when we call clk_get(dev, "core") it will find the lookup with "core" and "a456002.pmic_device" to match up the clk lookup.

Quoted 6 lines

If anything, the clk_name should just go into the con_id for now, and then it will need to be a globally unique identifier for the clk. But that is going against how clkdev is supposed to be used. Hence the question if you even need to use it. If not, just don't add it. I can fix up v3 of this patch to put clk_name back at con_id if you like. No need to resend.

Ok, I'm not very used with the CCF, so perhaps clk_name is not needed at all. I gave a try with the following combination:

- con_id = NULL, dev_id = clk_name
- con_id = clk_name, dev_id = NULL
- con_id = NULL, dev_id = NULL

All worked.

And finally I removed the clk_hw_register_clkdev() call and it worked also.

So I'm not sure about this function.

Any idea ?

Quoted 3 lines
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
Signature · 5 lines
 <http://www.linaro.org/> Linaro.org ? Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#10 lore raw
Quoted 40 lines · Daniel Lezcano
Quoted 3 lines · Stephen Boyd
Quoted 2 lines · Daniel Lezcano
Quoted 1 line · Stephen Boyd

On 04/08, Daniel Lezcano wrote:

[ ... ]

Quoted 19 lines
Quoted 11 lines
Quoted 6 lines

drivers/clk/clk-hi655x.c line 121

Quoted 1 line
drivers/clk/clk-hi655x.c new file +1 -0
+	ret = clk_hw_register_clkdev(&hi655x_clk->clk_hw, clk_name, NULL);

Missed this last time. Do you use this clkdev lookup? The name is usually supposed to be based on what the device is expecting, instead of clk_name, and we would want some device name for the third argument here.

I'm not sure to get your comment. Are you saying the clk_name should be the third argument?

Sorry, no. I meant that con_id is typically something like "core" or "ahb" or something like that, and dev_id is something like "a456002.pmic_device" or whatever dev_name(pmic_dev) would return for the consuming device. That way when we call clk_get(dev, "core") it will find the lookup with "core" and "a456002.pmic_device" to match up the clk lookup.

Quoted 6 lines

If anything, the clk_name should just go into the con_id for now, and then it will need to be a globally unique identifier for the clk. But that is going against how clkdev is supposed to be used. Hence the question if you even need to use it. If not, just don't add it. I can fix up v3 of this patch to put clk_name back at con_id if you like. No need to resend.

Ok, I'm not very used with the CCF, so perhaps clk_name is not needed at all. I gave a try with the following combination:

- con_id = NULL, dev_id = clk_name
- con_id = clk_name, dev_id = NULL
- con_id = NULL, dev_id = NULL

Quoted 6 lines

All worked.

And finally I removed the clk_hw_register_clkdev() call and it worked also.

So I'm not sure about this function.

If you've removed it and it still works, then it means you're using DT and you don't need clkdev at all. That's the of_clk provider thing that you're using. So I'll go remove this clkdev lookup because it's not used. If someone needs it they can add it later.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#11 lore raw
In reply to Daniel Lezcano
Quoted 21 lines · Daniel Lezcano

The hi655x multi function device is a PMIC providing regulators.

The PMIC also provides a clock for the WiFi and the Bluetooth, let's implement this clock in order to add it in the hi655x MFD and allow proper wireless initialization.

---

Changelog:

V2:
- Added COMPILE_TEST option, compiled on x86
- Removed useless parenthesis
- Used of_clk_hw_simple_get() instead of deref dance
- Do bailout if the clock-names is not specified
- Rollback on error
- Folded mfd line change and binding
- Added #clock-cells binding documentation
- Added #clock-cells in the DT

Quoted 2 lines

V1: initial post
---

??

Quoted 1 line

---

I'm unsure if this as been mentioned before, but bundling; driver & architecture changes and documentation into a single patch is very seldom a good idea. In this case, you should split this into at least 3, perhaps 4 patches.

Quoted 1 line
 .../devicetree/bindings/mfd/hisilicon,hi655x.txt   |   6 +

Patch 1

Quoted 1 line
 arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts     |   1 +

Patch 2

Quoted 3 lines
 drivers/clk/Kconfig                                |   8 ++
 drivers/clk/Makefile                               |   1 +
 drivers/clk/clk-hi655x.c                           | 140 +++++++++++++++++++++

Patch 3

Quoted 1 line
 drivers/mfd/hi655x-pmic.c                          |   3 +-

Patch 4

[...]

Quoted 228 lines
 6 files changed, 158 insertions(+), 1 deletion(-)
 create mode 100644 drivers/clk/clk-hi655x.c
Documentation/devicetree/bindings/mfd/hisilicon,hi655x.txt +6 -0
index 0548569..194e2a9fd 100644
@@ -16,6 +16,11 @@ Required properties:
 - reg:                  Base address of PMIC on Hi6220 SoC.
 - interrupt-controller: Hi655x has internal IRQs (has own IRQ domain).
 - pmic-gpios:           The GPIO used by PMIC IRQ.
+- #clock-cells:		From common clock binding; shall be set to 0
+
+Optional properties:
+- clock-output-names: From common clock binding to override the
+  default output clock name
 
 Example:
 	pmic: pmic at f8000000 {
@@ -24,4 +29,5 @@ Example:
 		interrupt-controller;
 		#interrupt-cells = <2>;
 		pmic-gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>;
+		clock-cells = <0>;
 	}
arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts +1 -0
index dba3c13..bb9afb1 100644
@@ -328,6 +328,7 @@
 		interrupt-controller;
 		#interrupt-cells = <2>;
 		pmic-gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>;
+		#clock-cells = <0>;
 
 		regulators {
 			ldo2: LDO2 {
drivers/clk/Kconfig +8 -0
index 9356ab4..36cfea3 100644
@@ -47,6 +47,14 @@ config COMMON_CLK_RK808
 	  clocked at 32KHz each. Clkout1 is always on, Clkout2 can off
 	  by control register.
 
+config COMMON_CLK_HI655X
+	tristate "Clock driver for Hi655x"
+	depends on MFD_HI655X_PMIC || COMPILE_TEST
+	---help---
+	  This driver supports the hi655x PMIC clock. This
+	  multi-function device has one fixed-rate oscillator, clocked
+	  at 32KHz.
+
 config COMMON_CLK_SCPI
 	tristate "Clock driver controlled via SCPI interface"
 	depends on ARM_SCPI_PROTOCOL || COMPILE_TEST
drivers/clk/Makefile +1 -0
index 92c12b8..c19983a 100644
@@ -36,6 +36,7 @@ obj-$(CONFIG_COMMON_CLK_PALMAS)		+= clk-palmas.o
 obj-$(CONFIG_COMMON_CLK_PWM)		+= clk-pwm.o
 obj-$(CONFIG_CLK_QORIQ)			+= clk-qoriq.o
 obj-$(CONFIG_COMMON_CLK_RK808)		+= clk-rk808.o
+obj-$(CONFIG_COMMON_CLK_HI655X)		+= clk-hi655x.o
 obj-$(CONFIG_COMMON_CLK_S2MPS11)	+= clk-s2mps11.o
 obj-$(CONFIG_COMMON_CLK_SCPI)           += clk-scpi.o
 obj-$(CONFIG_COMMON_CLK_SI5351)		+= clk-si5351.o
drivers/clk/clk-hi655x.c new file +140 -0
new file mode 100644
index 0000000..b2bea32
@@ -0,0 +1,140 @@
+/*
+ * Clock driver for Hi655x
+ *
+ * Copyright (c) 2016, Linaro Ltd.
+ *
+ * Author: Daniel Lezcano <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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/clkdev.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+#include <linux/mfd/core.h>
+#include <linux/mfd/hi655x-pmic.h>
+
+#define HI655X_CLK_BASE	HI655X_BUS_ADDR(0x1c)
+#define HI655X_CLK_SET	BIT(6)
+
+struct hi655x_clk {
+	struct hi655x_pmic *hi655x;
+	struct clk_hw       clk_hw;
+};
+
+static unsigned long hi655x_clk_recalc_rate(struct clk_hw *hw,
+					    unsigned long parent_rate)
+{
+	return 32768;
+}
+
+static int hi655x_clk_enable(struct clk_hw *hw, bool enable)
+{
+	struct hi655x_clk *hi655x_clk =
+		container_of(hw, struct hi655x_clk, clk_hw);
+
+	struct hi655x_pmic *hi655x = hi655x_clk->hi655x;
+
+	return regmap_update_bits(hi655x->regmap, HI655X_CLK_BASE,
+				  HI655X_CLK_SET, enable ? HI655X_CLK_SET : 0);
+}
+
+static int hi655x_clk_prepare(struct clk_hw *hw)
+{
+	return hi655x_clk_enable(hw, true);
+}
+
+static void hi655x_clk_unprepare(struct clk_hw *hw)
+{
+	hi655x_clk_enable(hw, false);
+}
+
+static int hi655x_clk_is_prepared(struct clk_hw *hw)
+{
+	struct hi655x_clk *hi655x_clk =
+		container_of(hw, struct hi655x_clk, clk_hw);
+	struct hi655x_pmic *hi655x = hi655x_clk->hi655x;
+	int ret;
+	uint32_t val;
+
+	ret = regmap_read(hi655x->regmap, HI655X_CLK_BASE, &val);
+	if (ret < 0)
+		return ret;
+
+	return val & HI655X_CLK_BASE;
+}
+
+static const struct clk_ops hi655x_clk_ops = {
+	.prepare     = hi655x_clk_prepare,
+	.unprepare   = hi655x_clk_unprepare,
+	.is_prepared = hi655x_clk_is_prepared,
+	.recalc_rate = hi655x_clk_recalc_rate,
+};
+
+static int hi655x_clk_probe(struct platform_device *pdev)
+{
+	struct device *parent = pdev->dev.parent;
+	struct hi655x_pmic *hi655x = dev_get_drvdata(parent);
+	struct clk_init_data *hi655x_clk_init;
+	struct hi655x_clk *hi655x_clk;
+	const char *clk_name = "hi655x-clk";
+	int ret;
+
+	hi655x_clk = devm_kzalloc(&pdev->dev, sizeof(*hi655x_clk), GFP_KERNEL);
+	if (!hi655x_clk)
+		return -ENOMEM;
+
+	hi655x_clk_init = devm_kzalloc(&pdev->dev, sizeof(*hi655x_clk_init),
+				       GFP_KERNEL);
+	if (!hi655x_clk_init)
+		return -ENOMEM;
+
+	of_property_read_string_index(parent->of_node, "clock-output-names",
+				      0, &clk_name);
+
+	hi655x_clk_init->name	= clk_name;
+	hi655x_clk_init->ops	= &hi655x_clk_ops;
+
+	hi655x_clk->clk_hw.init	= hi655x_clk_init;
+	hi655x_clk->hi655x	= hi655x;
+
+	platform_set_drvdata(pdev, hi655x_clk);
+
+	ret = devm_clk_hw_register(&pdev->dev, &hi655x_clk->clk_hw);
+	if (ret)
+		return ret;
+
+	ret = of_clk_add_hw_provider(parent->of_node, of_clk_hw_simple_get,
+				     &hi655x_clk->clk_hw);
+	if (ret)
+		return ret;
+
+	ret = clk_hw_register_clkdev(&hi655x_clk->clk_hw, clk_name, NULL);
+	if (ret)
+		of_clk_del_provider(parent->of_node);
+
+	return ret;
+}
+
+static struct platform_driver hi655x_clk_driver = {
+	.probe =  hi655x_clk_probe,
+	.driver		= {
+		.name	= "hi655x-clk",
+	},
+};
+
+module_platform_driver(hi655x_clk_driver);
+
+MODULE_DESCRIPTION("Clk driver for the hi655x series PMICs");
+MODULE_AUTHOR("Daniel Lezcano <[email protected]>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:hi655x-clk");
drivers/mfd/hi655x-pmic.c +2 -1
index ba706ad..c37ccbf 100644
@@ -77,7 +77,8 @@
 		.num_resources	= ARRAY_SIZE(pwrkey_resources),
 		.resources	= &pwrkey_resources[0],
 	},
-	{	.name		= "hi655x-regulator", },
+	{	.name		= "hi655x-regulator",	},
+	{	.name		= "hi655x-clk",		},
 };
 
 static void hi655x_local_irq_clear(struct regmap *map)
Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#12 lore raw
Quoted 47 lines · Lee Jones
Quoted 21 lines · Daniel Lezcano

The hi655x multi function device is a PMIC providing regulators.

The PMIC also provides a clock for the WiFi and the Bluetooth, let's implement this clock in order to add it in the hi655x MFD and allow proper wireless initialization.

---

Changelog:

V2:
- Added COMPILE_TEST option, compiled on x86
- Removed useless parenthesis
- Used of_clk_hw_simple_get() instead of deref dance
- Do bailout if the clock-names is not specified
- Rollback on error
- Folded mfd line change and binding
- Added #clock-cells binding documentation
- Added #clock-cells in the DT

Quoted 2 lines

V1: initial post
---

??

Quoted 1 line

---

I'm unsure if this as been mentioned before, but bundling; driver & architecture changes and documentation into a single patch is very seldom a good idea. In this case, you should split this into at least 3, perhaps 4 patches.

Quoted 1 line
 .../devicetree/bindings/mfd/hisilicon,hi655x.txt   |   6 +

Patch 1

Quoted 1 line
 arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts     |   1 +

Patch 2

Quoted 3 lines
 drivers/clk/Kconfig                                |   8 ++
 drivers/clk/Makefile                               |   1 +
 drivers/clk/clk-hi655x.c                           | 140 +++++++++++++++++++++
Quoted 7 lines

Patch 3

Quoted 1 line
 drivers/mfd/hi655x-pmic.c                          |   3 +-

Patch 4

[...]

Yep. Will do that next time.

Thanks.

-- Daniel