linux-clk.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 1/5] clk: sunxi: Add a driver for the PLL2 on A31/23/33
@ 2016-06-28 10:13 Icenowy Zheng
  2016-06-28 10:13 ` [RFC PATCH 2/5] dt: bindings: add bindings for allwinner a23/33 ths Icenowy Zheng
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Icenowy Zheng @ 2016-06-28 10:13 UTC (permalink / raw)
  To: rui.zhang, edubezval, robh+dt, maxime.ripard, wens, emilio
  Cc: mark.rutland, linux, mturquette, sboyd, linux-pm, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, Icenowy Zheng

This is based on the PLL2 driver for A10/20.

Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
---
 drivers/clk/sunxi/Makefile       |   1 +
 drivers/clk/sunxi/clk-a31-pll2.c | 194 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 195 insertions(+)
 create mode 100644 drivers/clk/sunxi/clk-a31-pll2.c

diff --git a/drivers/clk/sunxi/Makefile b/drivers/clk/sunxi/Makefile
index 39d2044..951992e 100644
--- a/drivers/clk/sunxi/Makefile
+++ b/drivers/clk/sunxi/Makefile
@@ -9,6 +9,7 @@ obj-y += clk-a10-mod1.o
 obj-y += clk-a10-pll2.o
 obj-y += clk-a10-ve.o
 obj-y += clk-a20-gmac.o
+obj-y += clk-a31-pll2.o
 obj-y += clk-mod0.o
 obj-y += clk-simple-gates.o
 obj-y += clk-sun4i-display.o
diff --git a/drivers/clk/sunxi/clk-a31-pll2.c b/drivers/clk/sunxi/clk-a31-pll2.c
new file mode 100644
index 0000000..3fdd98b
--- /dev/null
+++ b/drivers/clk/sunxi/clk-a31-pll2.c
@@ -0,0 +1,194 @@
+/*
+ * Copyright 2013 Emilio López
+ * Emilio López <emilio@elopez.com.ar>
+ *
+ * Copyright 2015 Maxime Ripard
+ * Maxime Ripard <maxime.ripard@free-electrons.com>
+ *
+ * Copyright 2016 Icenowy Zheng
+ * Icenowy Zheng <icenowy@aosc.xyz>
+ *
+ * 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/of.h>
+#include <linux/of_address.h>
+#include <linux/slab.h>
+
+#include <dt-bindings/clock/sun4i-a10-pll2.h>
+
+#define SUN6I_A31_PLL2_ENABLE		31
+
+#define SUN6I_A31_PLL2_PRE_DIV_SHIFT	0
+#define SUN6I_A31_PLL2_PRE_DIV_WIDTH	5
+#define SUN6I_A31_PLL2_PRE_DIV_MASK	GENMASK(SUN6I_A31_PLL2_PRE_DIV_WIDTH - 1, 0)
+
+#define SUN6I_A31_PLL2_N_SHIFT		8
+#define SUN6I_A31_PLL2_N_WIDTH		7
+#define SUN6I_A31_PLL2_N_MASK		GENMASK(SUN6I_A31_PLL2_N_WIDTH - 1, 0)
+
+#define SUN6I_A31_PLL2_POST_DIV_SHIFT	16
+#define SUN6I_A31_PLL2_POST_DIV_WIDTH	4
+#define SUN6I_A31_PLL2_POST_DIV_MASK	GENMASK(SUN6I_A31_PLL2_POST_DIV_WIDTH - 1, 0)
+
+#define SUN6I_A31_PLL2_POST_DIV_VALUE	4
+
+#define SUN6I_A31_PLL2_OUTPUTS		4
+
+static DEFINE_SPINLOCK(sun6i_a31_pll2_lock);
+
+static void __init sun6i_a31_pll2_setup(struct device_node *node)
+{
+	const char *clk_name = node->name, *parent;
+	struct clk **clks, *base_clk, *prediv_clk;
+	struct clk_onecell_data *clk_data;
+	struct clk_multiplier *mult;
+	struct clk_gate *gate;
+	void __iomem *reg;
+	u32 val;
+
+	reg = of_io_request_and_map(node, 0, of_node_full_name(node));
+	if (IS_ERR(reg))
+		return;
+
+	clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
+	if (!clk_data)
+		goto err_unmap;
+
+	clks = kcalloc(SUN6I_A31_PLL2_OUTPUTS, sizeof(struct clk *), GFP_KERNEL);
+	if (!clks)
+		goto err_free_data;
+
+	parent = of_clk_get_parent_name(node, 0);
+	prediv_clk = clk_register_divider(NULL, "pll2-prediv",
+					  parent, 0, reg,
+					  SUN6I_A31_PLL2_PRE_DIV_SHIFT,
+					  SUN6I_A31_PLL2_PRE_DIV_WIDTH,
+					  CLK_DIVIDER_ONE_BASED |
+					  CLK_DIVIDER_ALLOW_ZERO,
+					  &sun6i_a31_pll2_lock);
+	if (!prediv_clk) {
+		pr_err("Couldn't register the prediv clock\n");
+		goto err_free_array;
+	}
+
+	/* Setup the gate part of the PLL2 */
+	gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
+	if (!gate)
+		goto err_unregister_prediv;
+
+	gate->reg = reg;
+	gate->bit_idx = SUN6I_A31_PLL2_ENABLE;
+	gate->lock = &sun6i_a31_pll2_lock;
+
+	/* Setup the multiplier part of the PLL2 */
+	mult = kzalloc(sizeof(struct clk_multiplier), GFP_KERNEL);
+	if (!mult)
+		goto err_free_gate;
+
+	mult->reg = reg;
+	mult->shift = SUN6I_A31_PLL2_N_SHIFT;
+	mult->width = 7;
+	mult->flags = CLK_MULTIPLIER_ZERO_BYPASS |
+			CLK_MULTIPLIER_ROUND_CLOSEST;
+	mult->lock = &sun6i_a31_pll2_lock;
+
+	parent = __clk_get_name(prediv_clk);
+	base_clk = clk_register_composite(NULL, "pll2-base",
+					  &parent, 1,
+					  NULL, NULL,
+					  &mult->hw, &clk_multiplier_ops,
+					  &gate->hw, &clk_gate_ops,
+					  CLK_SET_RATE_PARENT);
+	if (!base_clk) {
+		pr_err("Couldn't register the base multiplier clock\n");
+		goto err_free_multiplier;
+	}
+
+	parent = __clk_get_name(base_clk);
+
+	/*
+	 * PLL2-1x
+	 *
+	 * This is supposed to have a post divider, but we won't need
+	 * to use it, we just need to initialise it to 4, and use a
+	 * fixed divider.
+	 */
+	val = readl(reg);
+	val &= ~(SUN6I_A31_PLL2_POST_DIV_MASK << SUN6I_A31_PLL2_POST_DIV_SHIFT);
+	val |= (SUN6I_A31_PLL2_POST_DIV_VALUE - 1)
+	       << SUN6I_A31_PLL2_POST_DIV_SHIFT;
+	writel(val, reg);
+
+	of_property_read_string_index(node, "clock-output-names",
+				      SUN4I_A10_PLL2_1X, &clk_name);
+	clks[SUN4I_A10_PLL2_1X] = clk_register_fixed_factor(NULL, clk_name,
+							    parent,
+							    CLK_SET_RATE_PARENT,
+							    1,
+							    SUN6I_A31_PLL2_POST_DIV_VALUE);
+	WARN_ON(IS_ERR(clks[SUN4I_A10_PLL2_1X]));
+
+	/*
+	 * PLL2-2x
+	 *
+	 * This clock doesn't use the post divider, and really is just
+	 * a fixed divider from the PLL2 base clock.
+	 */
+	of_property_read_string_index(node, "clock-output-names",
+				      SUN4I_A10_PLL2_2X, &clk_name);
+	clks[SUN4I_A10_PLL2_2X] = clk_register_fixed_factor(NULL, clk_name,
+							    parent,
+							    CLK_SET_RATE_PARENT,
+							    1, 2);
+	WARN_ON(IS_ERR(clks[SUN4I_A10_PLL2_2X]));
+
+	/* PLL2-4x */
+	of_property_read_string_index(node, "clock-output-names",
+				      SUN4I_A10_PLL2_4X, &clk_name);
+	clks[SUN4I_A10_PLL2_4X] = clk_register_fixed_factor(NULL, clk_name,
+							    parent,
+							    CLK_SET_RATE_PARENT,
+							    1, 1);
+	WARN_ON(IS_ERR(clks[SUN4I_A10_PLL2_4X]));
+
+	/* PLL2-8x */
+	of_property_read_string_index(node, "clock-output-names",
+				      SUN4I_A10_PLL2_8X, &clk_name);
+	clks[SUN4I_A10_PLL2_8X] = clk_register_fixed_factor(NULL, clk_name,
+							    parent,
+							    CLK_SET_RATE_PARENT,
+							    2, 1);
+	WARN_ON(IS_ERR(clks[SUN4I_A10_PLL2_8X]));
+
+	clk_data->clks = clks;
+	clk_data->clk_num = SUN6I_A31_PLL2_OUTPUTS;
+	of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
+
+	return;
+
+err_free_multiplier:
+	kfree(mult);
+err_free_gate:
+	kfree(gate);
+err_unregister_prediv:
+	clk_unregister_divider(prediv_clk);
+err_free_array:
+	kfree(clks);
+err_free_data:
+	kfree(clk_data);
+err_unmap:
+	iounmap(reg);
+}
+
+CLK_OF_DECLARE(sun6i_a31_pll2, "allwinner,sun6i-a31-pll2-clk",
+	       sun6i_a31_pll2_setup);
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [RFC PATCH 2/5] dt: bindings: add bindings for allwinner a23/33 ths
  2016-06-28 10:13 [RFC PATCH 1/5] clk: sunxi: Add a driver for the PLL2 on A31/23/33 Icenowy Zheng
@ 2016-06-28 10:13 ` Icenowy Zheng
  2016-06-28 10:13 ` [RFC PATCH 3/5] thermal: Add support for the thermal sensor on A23/33 Icenowy Zheng
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 15+ messages in thread
From: Icenowy Zheng @ 2016-06-28 10:13 UTC (permalink / raw)
  To: rui.zhang, edubezval, robh+dt, maxime.ripard, wens, emilio
  Cc: mark.rutland, linux, mturquette, sboyd, linux-pm, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, Icenowy Zheng

Document the THS on A23/33 SoCs.

Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
---
 .../devicetree/bindings/thermal/sun8iw3-thermal.txt  | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/sun8iw3-thermal.txt

diff --git a/Documentation/devicetree/bindings/thermal/sun8iw3-thermal.txt b/Documentation/devicetree/bindings/thermal/sun8iw3-thermal.txt
new file mode 100644
index 0000000..0cdcb9a
--- /dev/null
+++ b/Documentation/devicetree/bindings/thermal/sun8iw3-thermal.txt
@@ -0,0 +1,20 @@
+* Thermal Sensor (THS) on Allwinner sun8i A23/33 SoCs
+
+Required properties:
+- compatible : should be "allwinner,sun8i-<name>-ths"
+   "allwinner,sun8i-a23-ths": found on A23 SoCs
+   "allwinner,sun8i-a33-ths": found on A33 SoCs
+- reg : physical base address of the controller and length of memory mapped
+	region.
+- clocks : Must contain an entry for each entry in clock-names.
+- clock-names : Shall be "pll2", since the THS on A23/33 is using audio PLL (PLL2).
+- #thermal-sensor-cells : Should be 0. See ./thermal.txt for a description.
+
+Example:
+ths: ths@01c25000 {
+	#thermal-sensor-cells = <0>;
+	compatible = "allwinner,sun8i-a23-ths";
+	reg = <0x01c25000 0x44>;
+	clocks = <&pll2 0>;
+	clock-names = "pll2";
+};
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [RFC PATCH 3/5] thermal: Add support for the thermal sensor on A23/33
  2016-06-28 10:13 [RFC PATCH 1/5] clk: sunxi: Add a driver for the PLL2 on A31/23/33 Icenowy Zheng
  2016-06-28 10:13 ` [RFC PATCH 2/5] dt: bindings: add bindings for allwinner a23/33 ths Icenowy Zheng
@ 2016-06-28 10:13 ` Icenowy Zheng
  2016-06-28 11:46   ` Maxime Ripard
  2016-06-28 10:13 ` [RFC PATCH 4/5] ARM: sun8i: enable PLL2 on a23/33 Icenowy Zheng
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 15+ messages in thread
From: Icenowy Zheng @ 2016-06-28 10:13 UTC (permalink / raw)
  To: rui.zhang, edubezval, robh+dt, maxime.ripard, wens, emilio
  Cc: mark.rutland, linux, mturquette, sboyd, linux-pm, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, Icenowy Zheng

This patch adds support for the sun8iw3 thermal sensor on
Allwinner A23/33 SoCs.

Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
---
 drivers/thermal/Kconfig           |   7 ++
 drivers/thermal/Makefile          |   1 +
 drivers/thermal/sun8iw3_thermal.c | 191 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 199 insertions(+)
 create mode 100644 drivers/thermal/sun8iw3_thermal.c

diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
index 2d702ca..2f29ad7 100644
--- a/drivers/thermal/Kconfig
+++ b/drivers/thermal/Kconfig
@@ -351,6 +351,13 @@ config MTK_THERMAL
 	  Enable this option if you want to have support for thermal management
 	  controller present in Mediatek SoCs
 
+config SUN8IW3_THERMAL
+	tristate "Temperature sensor driver for Allwinner A23/33 SoCs"
+	depends on MACH_SUN8I
+	depends on OF
+	help
+	  Enable this to support thermal reporting on Allwinner A23/33 SoCs.
+
 menu "Texas Instruments thermal drivers"
 depends on ARCH_HAS_BANDGAP || COMPILE_TEST
 depends on HAS_IOMEM
diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
index 10b07c1..a4b0072 100644
--- a/drivers/thermal/Makefile
+++ b/drivers/thermal/Makefile
@@ -50,4 +50,5 @@ obj-$(CONFIG_ST_THERMAL)	+= st/
 obj-$(CONFIG_TEGRA_SOCTHERM)	+= tegra/
 obj-$(CONFIG_HISI_THERMAL)     += hisi_thermal.o
 obj-$(CONFIG_MTK_THERMAL)	+= mtk_thermal.o
+obj-$(CONFIG_SUN8IW3_THERMAL)	+= sun8iw3_thermal.o
 obj-$(CONFIG_GENERIC_ADC_THERMAL)	+= thermal-generic-adc.o
diff --git a/drivers/thermal/sun8iw3_thermal.c b/drivers/thermal/sun8iw3_thermal.c
new file mode 100644
index 0000000..332359f
--- /dev/null
+++ b/drivers/thermal/sun8iw3_thermal.c
@@ -0,0 +1,191 @@
+/*
+ * sun8iw3 THS driver
+ * Based on the work of Li Ming <liming@allwinnertech.com>>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/thermal.h>
+#include <linux/printk.h>
+
+#define THERMAL_DATA_DELAY      (100)
+
+#define THERMAL_BASSADDRESS     (0xf1c25000)
+
+#define THS_CTRL_REG0           (0x00)
+#define THS_CTRL_REG1           (0x04)
+#define THS_PRO_CTRL_REG        (0x18)
+
+#define THS_CTRL_REG0_VALUE_SUN8IW3     (0x00a300ff)
+#define THS_CTRL_REG0_VALUE_SUN8IW5     (0x002000ff)
+#define THS_CTRL_REG1_VALUE     (0x120)
+#define THS_PRO_CTRL_REG_VALUE  (0x1005f)
+
+#define THS_DATA_REG            (0x20)
+
+struct sun8iw3_ths_data {
+	void __iomem *regs;
+	struct platform_device *pdev;
+	struct clk *clk;
+	struct thermal_zone_device *tzd;
+	struct device_node *np;
+	struct delayed_work work;
+	u32 temp;
+	int divisor, minus;
+	u32 ctrl0_value;
+};
+
+static const struct of_device_id sun8iw3_ths_dt_ids[] = {
+	{ .compatible = "allwinner,sun8i-a23-ths", },
+	{ .compatible = "allwinner,sun8i-a33-ths", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, sun8iw3_ths_dt_ids);
+
+static int sun8iw3_ths_get_temp(void *_data, int *out)
+{
+	struct sun8iw3_ths_data *data = _data;
+
+	if (data->temp == 0)
+		return -EINVAL;
+
+	/* According to Allwinner's 3.4 kernel */
+	*out = (data->temp * 100) / data->divisor - data->minus;
+
+	/* Convert from Celsius to millidegree Celsius */
+	*out *= 1000;
+
+	return 0;
+}
+
+static struct thermal_zone_of_device_ops sun8iw3_of_thermal_ops = {
+	.get_temp = sun8iw3_ths_get_temp,
+};
+
+static void sun8iw3_ths_work(struct work_struct *work)
+{
+	struct sun8iw3_ths_data *data;
+
+	data = container_of(work, struct sun8iw3_ths_data, work.work);
+
+	data->temp = readl(data->regs + THS_DATA_REG);
+	if (data->temp)
+		thermal_zone_device_update(data->tzd);
+
+	schedule_delayed_work(&data->work, msecs_to_jiffies(1000));
+}
+
+static int sun8iw3_ths_init(struct platform_device *pdev,
+			    struct sun8iw3_ths_data *data)
+{
+	struct resource *r;
+	int ret;
+
+	data->np = pdev->dev.of_node;
+
+	/* divisor and minus data are from Allwinner's 3.4 kernel */
+	if (of_device_is_compatible(data->np, "allwinner,sun8i-a23-ths")) {
+		data->ctrl0_value = THS_CTRL_REG0_VALUE_SUN8IW3;
+		data->divisor = 625;
+		data->minus = 265;
+	} else if (of_device_is_compatible(data->np, "allwinner,sun8i-a33-ths")) {
+		data->ctrl0_value = THS_CTRL_REG0_VALUE_SUN8IW5;
+		data->divisor = 618;
+		data->minus = 269;
+	}
+
+	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	data->regs = devm_ioremap_resource(&pdev->dev, r);
+	if (IS_ERR(data->regs))
+		return PTR_ERR(data->regs);
+
+	data->clk = devm_clk_get(&pdev->dev, "pll2");
+	if (IS_ERR(data->clk)) {
+		ret = PTR_ERR(data->clk);
+		dev_err(&pdev->dev, "failed to get pll2 clk: %d\n", ret);
+		return ret;
+	}
+
+	data->tzd = devm_thermal_zone_of_sensor_register(
+				&pdev->dev, 0, data, &sun8iw3_of_thermal_ops);
+	if (IS_ERR(data->tzd)) {
+		ret = PTR_ERR(data->tzd);
+		dev_err(&pdev->dev, "can't register thermal zone: %d\n", ret);
+		return ret;
+	}
+
+	ret = clk_prepare_enable(data->clk);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to enable pll2 clk: %d\n", ret);
+		return ret;
+	}
+
+	writel(data->ctrl0_value, data->regs + THS_CTRL_REG0);
+	writel(THS_CTRL_REG1_VALUE, data->regs + THS_CTRL_REG1);
+	writel(THS_PRO_CTRL_REG_VALUE, data->regs + THS_PRO_CTRL_REG);
+
+	INIT_DELAYED_WORK(&data->work, sun8iw3_ths_work);
+	schedule_delayed_work(&data->work, msecs_to_jiffies(1000));
+
+	return 0;
+}
+
+static int sun8iw3_ths_exit(struct platform_device *pdev,
+			      struct sun8iw3_ths_data *data)
+{
+	thermal_zone_device_unregister(data->tzd);
+	cancel_delayed_work(&data->work);
+	clk_disable_unprepare(data->clk);
+	writel(0, data->regs + THS_CTRL_REG0);
+	writel(0, data->regs + THS_CTRL_REG1);
+	writel(0, data->regs + THS_PRO_CTRL_REG);
+	return 0;
+}
+
+static int sun8iw3_ths_probe(struct platform_device *pdev)
+{
+	struct sun8iw3_ths_data *data;
+
+	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, data);
+
+	return sun8iw3_ths_init(pdev, data);
+}
+
+static int sun8iw3_ths_remove(struct platform_device *pdev)
+{
+	struct sun8iw3_ths_data *data = platform_get_drvdata(pdev);
+
+	return sun8iw3_ths_exit(pdev, data);
+}
+
+static struct platform_driver sun8iw3_ths_driver = {
+	.driver	= {
+		.name	= "sun8iw3-ths",
+		.of_match_table = sun8iw3_ths_dt_ids,
+	},
+	.probe		= sun8iw3_ths_probe,
+	.remove		= sun8iw3_ths_remove,
+};
+
+module_platform_driver(sun8iw3_ths_driver);
+MODULE_AUTHOR("Icenowy Zheng <icenowy@aosc.xyz>");
+MODULE_DESCRIPTION("Allwinner A23/33 SoC thermal driver");
+MODULE_LICENSE("GPL v2");
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [RFC PATCH 4/5] ARM: sun8i: enable PLL2 on a23/33
  2016-06-28 10:13 [RFC PATCH 1/5] clk: sunxi: Add a driver for the PLL2 on A31/23/33 Icenowy Zheng
  2016-06-28 10:13 ` [RFC PATCH 2/5] dt: bindings: add bindings for allwinner a23/33 ths Icenowy Zheng
  2016-06-28 10:13 ` [RFC PATCH 3/5] thermal: Add support for the thermal sensor on A23/33 Icenowy Zheng
@ 2016-06-28 10:13 ` Icenowy Zheng
  2016-06-28 10:13 ` [RFC PATCH 5/5] ARM: sun8i: enable ths node for A23/33 Icenowy Zheng
  2016-07-05  6:12 ` [RFC PATCH 1/5] clk: sunxi: Add a driver for the PLL2 on A31/23/33 Maxime Ripard
  4 siblings, 0 replies; 15+ messages in thread
From: Icenowy Zheng @ 2016-06-28 10:13 UTC (permalink / raw)
  To: rui.zhang, edubezval, robh+dt, maxime.ripard, wens, emilio
  Cc: mark.rutland, linux, mturquette, sboyd, linux-pm, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, Icenowy Zheng

Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
---
 arch/arm/boot/dts/sun8i-a23-a33.dtsi | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm/boot/dts/sun8i-a23-a33.dtsi b/arch/arm/boot/dts/sun8i-a23-a33.dtsi
index 7e05e09..a340cea 100644
--- a/arch/arm/boot/dts/sun8i-a23-a33.dtsi
+++ b/arch/arm/boot/dts/sun8i-a23-a33.dtsi
@@ -46,6 +46,7 @@
 
 #include <dt-bindings/interrupt-controller/arm-gic.h>
 
+#include <dt-bindings/clock/sun4i-a10-pll2.h>
 #include <dt-bindings/pinctrl/sun4i-a10.h>
 
 / {
@@ -120,6 +121,15 @@
 			clock-output-names = "pll1";
 		};
 
+		pll2: clk@01c20008 {
+			#clock-cells = <1>;
+			compatible = "allwinner,sun6i-a31-pll2-clk";
+			reg = <0x01c20008 0x8>;
+			clocks = <&osc24M>;
+			clock-output-names = "pll2-1x", "pll2-2x",
+					     "pll2-4x", "pll2-8x";
+		};
+
 		/* dummy clock until actually implemented */
 		pll5: pll5_clk {
 			#clock-cells = <0>;
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [RFC PATCH 5/5] ARM: sun8i: enable ths node for A23/33
  2016-06-28 10:13 [RFC PATCH 1/5] clk: sunxi: Add a driver for the PLL2 on A31/23/33 Icenowy Zheng
                   ` (2 preceding siblings ...)
  2016-06-28 10:13 ` [RFC PATCH 4/5] ARM: sun8i: enable PLL2 on a23/33 Icenowy Zheng
@ 2016-06-28 10:13 ` Icenowy Zheng
  2016-07-05  6:12 ` [RFC PATCH 1/5] clk: sunxi: Add a driver for the PLL2 on A31/23/33 Maxime Ripard
  4 siblings, 0 replies; 15+ messages in thread
From: Icenowy Zheng @ 2016-06-28 10:13 UTC (permalink / raw)
  To: rui.zhang, edubezval, robh+dt, maxime.ripard, wens, emilio
  Cc: mark.rutland, linux, mturquette, sboyd, linux-pm, devicetree,
	linux-arm-kernel, linux-kernel, linux-clk, Icenowy Zheng

Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
---
 arch/arm/boot/dts/sun8i-a23-a33.dtsi | 16 ++++++++++++++++
 arch/arm/boot/dts/sun8i-a23.dtsi     |  4 ++++
 arch/arm/boot/dts/sun8i-a33.dtsi     |  4 ++++
 3 files changed, 24 insertions(+)

diff --git a/arch/arm/boot/dts/sun8i-a23-a33.dtsi b/arch/arm/boot/dts/sun8i-a23-a33.dtsi
index a340cea..04df1ca 100644
--- a/arch/arm/boot/dts/sun8i-a23-a33.dtsi
+++ b/arch/arm/boot/dts/sun8i-a23-a33.dtsi
@@ -66,6 +66,14 @@
 		};
 	};
 
+	thermal-zones {
+		cpu_thermal: cpu_thermal {
+			polling-delay-passive = <330>;
+			polling-delay = <1000>;
+			thermal-sensors = <&ths 0>;
+		};
+	};
+
 	timer {
 		compatible = "arm,armv7-timer";
 		interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_LOW)>,
@@ -473,6 +481,14 @@
 			status = "disabled";
 		};
 
+		ths: ths@01c25000 {
+			#thermal-sensor-cells = <0>;
+			/* compatible is in per-cpu dtsi file */
+			reg = <0x01c25000 0x44>;
+			clocks = <&pll2 0>;
+			clock-names = "pll2";
+		};
+
 		uart0: serial@01c28000 {
 			compatible = "snps,dw-apb-uart";
 			reg = <0x01c28000 0x400>;
diff --git a/arch/arm/boot/dts/sun8i-a23.dtsi b/arch/arm/boot/dts/sun8i-a23.dtsi
index 92e6616..41f0d9e 100644
--- a/arch/arm/boot/dts/sun8i-a23.dtsi
+++ b/arch/arm/boot/dts/sun8i-a23.dtsi
@@ -124,3 +124,7 @@
 		     <GIC_SPI 15 IRQ_TYPE_LEVEL_HIGH>,
 		     <GIC_SPI 17 IRQ_TYPE_LEVEL_HIGH>;
 };
+
+&ths {
+	compatible = "allwinner,sun8i-a23-ths";
+};
diff --git a/arch/arm/boot/dts/sun8i-a33.dtsi b/arch/arm/boot/dts/sun8i-a33.dtsi
index 001d840..2273124 100644
--- a/arch/arm/boot/dts/sun8i-a33.dtsi
+++ b/arch/arm/boot/dts/sun8i-a33.dtsi
@@ -173,3 +173,7 @@
 	};
 
 };
+
+&ths {
+	compatible = "allwinner,sun8i-a33-ths";
+};
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH 3/5] thermal: Add support for the thermal sensor on A23/33
  2016-06-28 10:13 ` [RFC PATCH 3/5] thermal: Add support for the thermal sensor on A23/33 Icenowy Zheng
@ 2016-06-28 11:46   ` Maxime Ripard
  2016-06-28 13:56     ` Icenowy Zheng
  2016-06-28 14:03     ` Icenowy Zheng
  0 siblings, 2 replies; 15+ messages in thread
From: Maxime Ripard @ 2016-06-28 11:46 UTC (permalink / raw)
  To: Icenowy Zheng
  Cc: rui.zhang, edubezval, robh+dt, wens, emilio, mark.rutland, linux,
	mturquette, sboyd, linux-pm, devicetree, linux-arm-kernel,
	linux-kernel, linux-clk

[-- Attachment #1: Type: text/plain, Size: 531 bytes --]

Hi,

Thanks for working on this.

On Tue, Jun 28, 2016 at 06:13:23PM +0800, Icenowy Zheng wrote:
> This patch adds support for the sun8iw3 thermal sensor on
> Allwinner A23/33 SoCs.
> 
> Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>

The IP is awfully similar to the A31's, which already has a driver
(drivers/input/touchscreen/sun4i-ts.c).

There's no reason to add a new one here.

Thanks,
Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH 3/5] thermal: Add support for the thermal sensor on A23/33
  2016-06-28 11:46   ` Maxime Ripard
@ 2016-06-28 13:56     ` Icenowy Zheng
  2016-06-29 12:10       ` Maxime Ripard
  2016-06-28 14:03     ` Icenowy Zheng
  1 sibling, 1 reply; 15+ messages in thread
From: Icenowy Zheng @ 2016-06-28 13:56 UTC (permalink / raw)
  To: Maxime Ripard
  Cc: rui.zhang, edubezval, robh+dt, wens, emilio, mark.rutland, linux,
	mturquette, sboyd, linux-pm, devicetree, linux-arm-kernel,
	linux-kernel, linux-clk



28.06.2016, 19:46, "Maxime Ripard" <maxime.ripard@free-electrons.com>:
> Hi,
>
> Thanks for working on this.
>
> On Tue, Jun 28, 2016 at 06:13:23PM +0800, Icenowy Zheng wrote:
>>  This patch adds support for the sun8iw3 thermal sensor on
>>  Allwinner A23/33 SoCs.
>>
>>  Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
>
> The IP is awfully similar to the A31's, which already has a driver
> (drivers/input/touchscreen/sun4i-ts.c).
>
> There's no reason to add a new one here.
>
> Thanks,
> Maxime
>
> --
> Maxime Ripard, Free Electrons
> Embedded Linux, Kernel and Android engineering
> http://free-electrons.com

The reason for a dedicate driver is:
1. This IP have only thermal function, so it's not suitable to use a driver at drivers/input/touchscreen/.
2. Control Register are quite different.
3. This IP uses AUDIO PLL (PLL2) as its clock!

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH 3/5] thermal: Add support for the thermal sensor on A23/33
  2016-06-28 11:46   ` Maxime Ripard
  2016-06-28 13:56     ` Icenowy Zheng
@ 2016-06-28 14:03     ` Icenowy Zheng
  1 sibling, 0 replies; 15+ messages in thread
From: Icenowy Zheng @ 2016-06-28 14:03 UTC (permalink / raw)
  To: Maxime Ripard
  Cc: rui.zhang, edubezval, robh+dt, wens, emilio, mark.rutland, linux,
	mturquette, sboyd, linux-pm, devicetree, linux-arm-kernel,
	linux-kernel, linux-clk



28.06.2016, 19:46, "Maxime Ripard" <maxime.ripard@free-electrons.com>:
> Hi,
>
> Thanks for working on this.
>
> On Tue, Jun 28, 2016 at 06:13:23PM +0800, Icenowy Zheng wrote:
>>  This patch adds support for the sun8iw3 thermal sensor on
>>  Allwinner A23/33 SoCs.
>>
>>  Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
>
> The IP is awfully similar to the A31's, which already has a driver
> (drivers/input/touchscreen/sun4i-ts.c).
>
> There's no reason to add a new one here.
>
> Thanks,
> Maxime
>
> --
> Maxime Ripard, Free Electrons
> Embedded Linux, Kernel and Android engineering
> http://free-electrons.com

Or... should I split the PLL2 driver into another patch set?

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH 3/5] thermal: Add support for the thermal sensor on A23/33
  2016-06-28 13:56     ` Icenowy Zheng
@ 2016-06-29 12:10       ` Maxime Ripard
  2016-06-29 13:31         ` Icenowy Zheng
                           ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Maxime Ripard @ 2016-06-29 12:10 UTC (permalink / raw)
  To: Icenowy Zheng
  Cc: rui.zhang, edubezval, robh+dt, wens, emilio, mark.rutland, linux,
	mturquette, sboyd, linux-pm, devicetree, linux-arm-kernel,
	linux-kernel, linux-clk

[-- Attachment #1: Type: text/plain, Size: 955 bytes --]

Hi,

On Tue, Jun 28, 2016 at 09:56:22PM +0800, Icenowy Zheng wrote:
> The reason for a dedicate driver is:
> 1. This IP have only thermal function, so it's not suitable to use a
> driver at drivers/input/touchscreen/.

That's not a problem, and it's being worked on [1].

> 2. Control Register are quite different.

That's not a problem either, there's just a bit that you don't need to
set in the control 1 register, and that's pretty much it. It doesn't
justify a whole new driver.

> 3. This IP uses AUDIO PLL (PLL2) as its clock!

It's listed as the input, but all the rest of the documentation refers
only to 24MHz, which seems to indicate that it's only running on the
oscillator, which would make much more sense.

Thanks,
Maxime

1: http://lists.infradead.org/pipermail/linux-arm-kernel/2016-June/439487.html

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH 3/5] thermal: Add support for the thermal sensor on A23/33
  2016-06-29 12:10       ` Maxime Ripard
@ 2016-06-29 13:31         ` Icenowy Zheng
  2016-06-29 13:42           ` Maxime Ripard
  2016-06-29 13:33         ` Icenowy Zheng
  2016-06-29 13:42         ` Icenowy Zheng
  2 siblings, 1 reply; 15+ messages in thread
From: Icenowy Zheng @ 2016-06-29 13:31 UTC (permalink / raw)
  To: Maxime Ripard
  Cc: rui.zhang, edubezval, robh+dt, wens, emilio, mark.rutland, linux,
	mturquette, sboyd, linux-pm, devicetree, linux-arm-kernel,
	linux-kernel, linux-clk



29.06.2016, 20:10, "Maxime Ripard" <maxime.ripard@free-electrons.com>:
> Hi,
>
> On Tue, Jun 28, 2016 at 09:56:22PM +0800, Icenowy Zheng wrote:
>>  The reason for a dedicate driver is:
>>  1. This IP have only thermal function, so it's not suitable to use a
>>  driver at drivers/input/touchscreen/.
>
> That's not a problem, and it's being worked on [1].
>
>>  2. Control Register are quite different.
>
> That's not a problem either, there's just a bit that you don't need to
> set in the control 1 register, and that's pretty much it. It doesn't
> justify a whole new driver.
>
>>  3. This IP uses AUDIO PLL (PLL2) as its clock!
>
> It's listed as the input, but all the rest of the documentation refers
> only to 24MHz, which seems to indicate that it's only running on the
> oscillator, which would make much more sense.
>
> Thanks,
> Maxime
>
> 1: http://lists.infradead.org/pipermail/linux-arm-kernel/2016-June/439487.html
>
> --
> Maxime Ripard, Free Electrons
> Embedded Linux, Kernel and Android engineering
> http://free-electrons.com

Thanks.

However, sun8iw3/5 ths is not even a GPADC... It's a specified IP, only used as an ADC suitable for temperature sensor.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH 3/5] thermal: Add support for the thermal sensor on A23/33
  2016-06-29 12:10       ` Maxime Ripard
  2016-06-29 13:31         ` Icenowy Zheng
@ 2016-06-29 13:33         ` Icenowy Zheng
  2016-06-29 13:42         ` Icenowy Zheng
  2 siblings, 0 replies; 15+ messages in thread
From: Icenowy Zheng @ 2016-06-29 13:33 UTC (permalink / raw)
  To: Maxime Ripard
  Cc: rui.zhang, edubezval, robh+dt, wens, emilio, mark.rutland, linux,
	mturquette, sboyd, linux-pm, devicetree, linux-arm-kernel,
	linux-kernel, linux-clk



29.06.2016, 20:10, "Maxime Ripard" <maxime.ripard@free-electrons.com>:
> Hi,
>
> On Tue, Jun 28, 2016 at 09:56:22PM +0800, Icenowy Zheng wrote:
>>  The reason for a dedicate driver is:
>>  1. This IP have only thermal function, so it's not suitable to use a
>>  driver at drivers/input/touchscreen/.
>
> That's not a problem, and it's being worked on [1].
>
>>  2. Control Register are quite different.
>
> That's not a problem either, there's just a bit that you don't need to
> set in the control 1 register, and that's pretty much it. It doesn't
> justify a whole new driver.
>
>>  3. This IP uses AUDIO PLL (PLL2) as its clock!
>
> It's listed as the input, but all the rest of the documentation refers
> only to 24MHz, which seems to indicate that it's only running on the
> oscillator, which would make much more sense.
>
> Thanks,
> Maxime
>
> 1: http://lists.infradead.org/pipermail/linux-arm-kernel/2016-June/439487.html
>
> --
> Maxime Ripard, Free Electrons
> Embedded Linux, Kernel and Android engineering
> http://free-electrons.com

I will try to use it without pll2 enabled.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH 3/5] thermal: Add support for the thermal sensor on A23/33
  2016-06-29 13:31         ` Icenowy Zheng
@ 2016-06-29 13:42           ` Maxime Ripard
  2016-06-29 13:52             ` Icenowy Zheng
  0 siblings, 1 reply; 15+ messages in thread
From: Maxime Ripard @ 2016-06-29 13:42 UTC (permalink / raw)
  To: Icenowy Zheng
  Cc: rui.zhang, edubezval, robh+dt, wens, emilio, mark.rutland, linux,
	mturquette, sboyd, linux-pm, devicetree, linux-arm-kernel,
	linux-kernel, linux-clk

[-- Attachment #1: Type: text/plain, Size: 375 bytes --]

On Wed, Jun 29, 2016 at 09:31:39PM +0800, Icenowy Zheng wrote:
> However, sun8iw3/5 ths is not even a GPADC... It's a specified IP,
> only used as an ADC suitable for temperature sensor.

It doesn't matter. It's the same IP, labelled differently.

Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH 3/5] thermal: Add support for the thermal sensor on A23/33
  2016-06-29 12:10       ` Maxime Ripard
  2016-06-29 13:31         ` Icenowy Zheng
  2016-06-29 13:33         ` Icenowy Zheng
@ 2016-06-29 13:42         ` Icenowy Zheng
  2 siblings, 0 replies; 15+ messages in thread
From: Icenowy Zheng @ 2016-06-29 13:42 UTC (permalink / raw)
  To: Maxime Ripard
  Cc: rui.zhang, edubezval, robh+dt, wens, emilio, mark.rutland, linux,
	mturquette, sboyd, linux-pm, devicetree, linux-arm-kernel,
	linux-kernel, linux-clk



29.06.2016, 20:10, "Maxime Ripard" <maxime.ripard@free-electrons.com>:
> Hi,
>
> On Tue, Jun 28, 2016 at 09:56:22PM +0800, Icenowy Zheng wrote:
>>  The reason for a dedicate driver is:
>>  1. This IP have only thermal function, so it's not suitable to use a
>>  driver at drivers/input/touchscreen/.
>
> That's not a problem, and it's being worked on [1].
>
>>  2. Control Register are quite different.
>
> That's not a problem either, there's just a bit that you don't need to
> set in the control 1 register, and that's pretty much it. It doesn't
> justify a whole new driver.
>
>>  3. This IP uses AUDIO PLL (PLL2) as its clock!
>
> It's listed as the input, but all the rest of the documentation refers
> only to 24MHz, which seems to indicate that it's only running on the
> oscillator, which would make much more sense.
>
> Thanks,
> Maxime
>
> 1: http://lists.infradead.org/pipermail/linux-arm-kernel/2016-June/439487.html
>
> --
> Maxime Ripard, Free Electrons
> Embedded Linux, Kernel and Android engineering
> http://free-electrons.com

Oh it works properly with PLL2 set as a dummy pll.

Maybe only osc24M is required...

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH 3/5] thermal: Add support for the thermal sensor on A23/33
  2016-06-29 13:42           ` Maxime Ripard
@ 2016-06-29 13:52             ` Icenowy Zheng
  0 siblings, 0 replies; 15+ messages in thread
From: Icenowy Zheng @ 2016-06-29 13:52 UTC (permalink / raw)
  To: Maxime Ripard
  Cc: rui.zhang, edubezval, robh+dt, wens, emilio, mark.rutland, linux,
	mturquette, sboyd, linux-pm, devicetree, linux-arm-kernel,
	linux-kernel, linux-clk



29.06.2016, 21:42, "Maxime Ripard" <maxime.ripard@free-electrons.com>:
> On Wed, Jun 29, 2016 at 09:31:39PM +0800, Icenowy Zheng wrote:
>>  However, sun8iw3/5 ths is not even a GPADC... It's a specified IP,
>>  only used as an ADC suitable for temperature sensor.
>
> It doesn't matter. It's the same IP, labelled differently.
>
> Maxime
>
> --
> Maxime Ripard, Free Electrons
> Embedded Linux, Kernel and Android engineering
> http://free-electrons.com

OK, now I will send only PLL2 driver.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH 1/5] clk: sunxi: Add a driver for the PLL2 on A31/23/33
  2016-06-28 10:13 [RFC PATCH 1/5] clk: sunxi: Add a driver for the PLL2 on A31/23/33 Icenowy Zheng
                   ` (3 preceding siblings ...)
  2016-06-28 10:13 ` [RFC PATCH 5/5] ARM: sun8i: enable ths node for A23/33 Icenowy Zheng
@ 2016-07-05  6:12 ` Maxime Ripard
  4 siblings, 0 replies; 15+ messages in thread
From: Maxime Ripard @ 2016-07-05  6:12 UTC (permalink / raw)
  To: Icenowy Zheng
  Cc: rui.zhang, edubezval, robh+dt, wens, emilio, mark.rutland, linux,
	mturquette, sboyd, linux-pm, devicetree, linux-arm-kernel,
	linux-kernel, linux-clk

[-- Attachment #1: Type: text/plain, Size: 694 bytes --]

Hi,

On Tue, Jun 28, 2016 at 06:13:21PM +0800, Icenowy Zheng wrote:
> This is based on the PLL2 driver for A10/20.

Thanks for this patch.

However, as you might have seen, we're switching to a new clock code
base, so it would be great if you could use that instead.

http://lists.infradead.org/pipermail/linux-arm-kernel/2016-June/440077.html

While we declared all the clocks for the H3, nothing really mandates
that for the existing platforms we don't introduce a few clocks as
they are needed. That will probably even smoothen the transition.

Thanks,
Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2016-07-05  6:12 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-28 10:13 [RFC PATCH 1/5] clk: sunxi: Add a driver for the PLL2 on A31/23/33 Icenowy Zheng
2016-06-28 10:13 ` [RFC PATCH 2/5] dt: bindings: add bindings for allwinner a23/33 ths Icenowy Zheng
2016-06-28 10:13 ` [RFC PATCH 3/5] thermal: Add support for the thermal sensor on A23/33 Icenowy Zheng
2016-06-28 11:46   ` Maxime Ripard
2016-06-28 13:56     ` Icenowy Zheng
2016-06-29 12:10       ` Maxime Ripard
2016-06-29 13:31         ` Icenowy Zheng
2016-06-29 13:42           ` Maxime Ripard
2016-06-29 13:52             ` Icenowy Zheng
2016-06-29 13:33         ` Icenowy Zheng
2016-06-29 13:42         ` Icenowy Zheng
2016-06-28 14:03     ` Icenowy Zheng
2016-06-28 10:13 ` [RFC PATCH 4/5] ARM: sun8i: enable PLL2 on a23/33 Icenowy Zheng
2016-06-28 10:13 ` [RFC PATCH 5/5] ARM: sun8i: enable ths node for A23/33 Icenowy Zheng
2016-07-05  6:12 ` [RFC PATCH 1/5] clk: sunxi: Add a driver for the PLL2 on A31/23/33 Maxime Ripard

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).