All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/9] ARM: sunxi: Support cpufreq on sun[457]i
@ 2015-01-09 10:17 ` Chen-Yu Tsai
  0 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-09 10:17 UTC (permalink / raw)
  To: Maxime Ripard, Dmitry Torokhov, Zhang Rui, Eduardo Valentin
  Cc: Chen-Yu Tsai, Hans de Goede, linux-input, linux-arm-kernel, linux-pm

Hi,

This is v2 of the cpufreq support series for sunxi. The series has been
rebased onto the latest sunxi-next. I've dropped all the patches Maxime
merged. This includes "ARM: sunxi: Register cpufreq-dt for sun[45678]i"
which was merged but not published yet.

Individual changes since v1 are listed within each patch.


Original cover letter follows:

This series adds support cpufreq support for sun[457]i using cpufreq-dt.
This also supports passive cpu cooling (thermal throttling) using thermal
zones with the temperature sensor in the SoC.

The operating points for the supported platforms were taken from the
linux-sunxi FEX files repository. The majority of boards use the same
settings. Only with sun7i do we see slight variations, either disabling
some frequencies, or bumping up the voltage a bit. In either case this
can be done by limiting the constraints for the supply regulator, or 
overriding the OPP table in the board dts file.

On sun7i, there is an additional operating point not found in the FEX
files, 960 MHz @ 1.4V, which is the full speed setting in both u-boot-sunxi
and mainline u-boot.

The series has been tested on the 4 boards I have. With cpufreq active,
the effects are visible as a decrease in SoC internal temperature.
Stability for the operating points has been tested using:

  http://linux-sunxi.org/Hardware_Reliability_Tests#Reliability_of_cpufreq_voltage.2Ffrequency_settings

More real world usage feedback is appreciated. Thermal throttling hasn't
been tested much, due to not being able to generate enough load without
the GPU for the SoC to heat up. Also on sun4i, the temperature sensor
still hasn't been calibrated, so the readings are highly inaccurate.


Chen-Yu Tsai (9):
  Input: sun4i-ts: Add thermal zone sensor support
  ARM: dts: sunxi: Add dtsi for AXP209 PMIC
  ARM: dts: sun7i: Add cpu thermal zones to dtsi
  ARM: dts: sun7i: cubieboard2: add axp209 regulator nodes
  ARM: dts: sun7i: cubietruck: add axp209 regulator nodes
  ARM: dts: sun5i: Add cpu thermal zones to dtsi
  ARM: dts: sun5i: hsg-h702: add axp209 regulator nodes
  ARM: dts: sun4i: Add cpu thermal zones to dtsi
  ARM: dts: sun4i: cubieboard: add axp209 regulator nodes

 .../bindings/input/touchscreen/sun4i.txt           |  2 +
 arch/arm/boot/dts/axp209.dtsi                      | 97 ++++++++++++++++++++++
 arch/arm/boot/dts/sun4i-a10-cubieboard.dts         | 35 +++++++-
 arch/arm/boot/dts/sun4i-a10.dtsi                   | 34 ++++++++
 arch/arm/boot/dts/sun5i-a13-hsg-h702.dts           | 46 ++++++++--
 arch/arm/boot/dts/sun5i-a13.dtsi                   | 34 ++++++++
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts        | 35 +++++++-
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts         | 35 +++++++-
 arch/arm/boot/dts/sun7i-a20.dtsi                   | 33 ++++++++
 drivers/input/touchscreen/sun4i-ts.c               | 47 +++++++++++
 10 files changed, 378 insertions(+), 20 deletions(-)
 create mode 100644 arch/arm/boot/dts/axp209.dtsi

-- 
2.1.4


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

* [PATCH v2 0/9] ARM: sunxi: Support cpufreq on sun[457]i
@ 2015-01-09 10:17 ` Chen-Yu Tsai
  0 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-09 10:17 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

This is v2 of the cpufreq support series for sunxi. The series has been
rebased onto the latest sunxi-next. I've dropped all the patches Maxime
merged. This includes "ARM: sunxi: Register cpufreq-dt for sun[45678]i"
which was merged but not published yet.

Individual changes since v1 are listed within each patch.


Original cover letter follows:

This series adds support cpufreq support for sun[457]i using cpufreq-dt.
This also supports passive cpu cooling (thermal throttling) using thermal
zones with the temperature sensor in the SoC.

The operating points for the supported platforms were taken from the
linux-sunxi FEX files repository. The majority of boards use the same
settings. Only with sun7i do we see slight variations, either disabling
some frequencies, or bumping up the voltage a bit. In either case this
can be done by limiting the constraints for the supply regulator, or 
overriding the OPP table in the board dts file.

On sun7i, there is an additional operating point not found in the FEX
files, 960 MHz @ 1.4V, which is the full speed setting in both u-boot-sunxi
and mainline u-boot.

The series has been tested on the 4 boards I have. With cpufreq active,
the effects are visible as a decrease in SoC internal temperature.
Stability for the operating points has been tested using:

  http://linux-sunxi.org/Hardware_Reliability_Tests#Reliability_of_cpufreq_voltage.2Ffrequency_settings

More real world usage feedback is appreciated. Thermal throttling hasn't
been tested much, due to not being able to generate enough load without
the GPU for the SoC to heat up. Also on sun4i, the temperature sensor
still hasn't been calibrated, so the readings are highly inaccurate.


Chen-Yu Tsai (9):
  Input: sun4i-ts: Add thermal zone sensor support
  ARM: dts: sunxi: Add dtsi for AXP209 PMIC
  ARM: dts: sun7i: Add cpu thermal zones to dtsi
  ARM: dts: sun7i: cubieboard2: add axp209 regulator nodes
  ARM: dts: sun7i: cubietruck: add axp209 regulator nodes
  ARM: dts: sun5i: Add cpu thermal zones to dtsi
  ARM: dts: sun5i: hsg-h702: add axp209 regulator nodes
  ARM: dts: sun4i: Add cpu thermal zones to dtsi
  ARM: dts: sun4i: cubieboard: add axp209 regulator nodes

 .../bindings/input/touchscreen/sun4i.txt           |  2 +
 arch/arm/boot/dts/axp209.dtsi                      | 97 ++++++++++++++++++++++
 arch/arm/boot/dts/sun4i-a10-cubieboard.dts         | 35 +++++++-
 arch/arm/boot/dts/sun4i-a10.dtsi                   | 34 ++++++++
 arch/arm/boot/dts/sun5i-a13-hsg-h702.dts           | 46 ++++++++--
 arch/arm/boot/dts/sun5i-a13.dtsi                   | 34 ++++++++
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts        | 35 +++++++-
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts         | 35 +++++++-
 arch/arm/boot/dts/sun7i-a20.dtsi                   | 33 ++++++++
 drivers/input/touchscreen/sun4i-ts.c               | 47 +++++++++++
 10 files changed, 378 insertions(+), 20 deletions(-)
 create mode 100644 arch/arm/boot/dts/axp209.dtsi

-- 
2.1.4

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

* [PATCH v2 1/9] Input: sun4i-ts: Add thermal zone sensor support
  2015-01-09 10:17 ` Chen-Yu Tsai
@ 2015-01-09 10:17   ` Chen-Yu Tsai
  -1 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-09 10:17 UTC (permalink / raw)
  To: Maxime Ripard, Dmitry Torokhov, Zhang Rui, Eduardo Valentin
  Cc: Chen-Yu Tsai, Hans de Goede, linux-input, linux-arm-kernel, linux-pm

The touchscreen controller has a temperature sensor embedded in the SoC,
which already has hwmon support in the driver.

Add DT thermal zone support so we can use it with cpufreq for thermal
throttling.

This also adds a comment stating that we do not know the actual formula
for calculating the temperature.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---

changes since v1:

    - clean up thermal zone sensor when input device register fails
    - unconditionally unregister thermal zone sensor on removal.
      the unregister function checks the pointers passed in.
    - add comment explaining the lack of documents for the temperature
      calculation formula

---
 .../bindings/input/touchscreen/sun4i.txt           |  2 +
 drivers/input/touchscreen/sun4i-ts.c               | 47 ++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
index aef57791f40b..a8405bab6c00 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
+++ b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
@@ -5,6 +5,7 @@ Required properties:
  - compatible: "allwinner,sun4i-a10-ts"
  - reg: mmio address range of the chip
  - interrupts: interrupt to which the chip is connected
+ - #thermal-sensor-cells: shall be 0
 
 Optional properties:
  - allwinner,ts-attached: boolean indicating that an actual touchscreen is
@@ -17,4 +18,5 @@ Example:
 		reg = <0x01c25000 0x100>;
 		interrupts = <29>;
 		allwinner,ts-attached;
+		#thermal-sensor-cells = <0>;
 	};
diff --git a/drivers/input/touchscreen/sun4i-ts.c b/drivers/input/touchscreen/sun4i-ts.c
index 28a06749ae42..aac49db0b09d 100644
--- a/drivers/input/touchscreen/sun4i-ts.c
+++ b/drivers/input/touchscreen/sun4i-ts.c
@@ -34,6 +34,7 @@
 
 #include <linux/err.h>
 #include <linux/hwmon.h>
+#include <linux/thermal.h>
 #include <linux/init.h>
 #include <linux/input.h>
 #include <linux/interrupt.h>
@@ -107,6 +108,7 @@
 struct sun4i_ts_data {
 	struct device *dev;
 	struct input_dev *input;
+	struct thermal_zone_device *tz;
 	void __iomem *base;
 	unsigned int irq;
 	bool ignore_fifo_data;
@@ -180,6 +182,33 @@ static void sun4i_ts_close(struct input_dev *dev)
 	writel(TEMP_IRQ_EN(1), ts->base + TP_INT_FIFOC);
 }
 
+static int get_temp(void *data, long *temp)
+{
+	struct sun4i_ts_data *ts = data;
+
+	/* No temp_data until the first irq */
+	if (ts->temp_data == -1)
+		return -EAGAIN;
+
+	/*
+	 * The user manuals do not contain the formula for calculating
+	 * the temperature. The formula used here is from the AXP209,
+	 * which is designed by X-Powers, an affiliate of Allwinner:
+	 *
+	 *     temperature = -144.7 + (value * 0.1)
+	 *
+	 * This should be replaced with the correct one if such information
+	 * becomes available.
+	 */
+	*temp = (ts->temp_data - 1447) * 100;
+
+	return 0;
+}
+
+static struct thermal_zone_of_device_ops sun4i_ts_tz_ops = {
+	.get_temp = get_temp,
+};
+
 static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
 			 char *buf)
 {
@@ -189,6 +218,16 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
 	if (ts->temp_data == -1)
 		return -EAGAIN;
 
+	/*
+	 * The user manuals do not contain the formula for calculating
+	 * the temperature. The formula used here is from the AXP209,
+	 * which is designed by X-Powers, an affiliate of Allwinner:
+	 *
+	 *     temperature = -144.7 + (value * 0.1)
+	 *
+	 * This should be replaced with the correct one if such information
+	 * becomes available.
+	 */
 	return sprintf(buf, "%d\n", (ts->temp_data - 1447) * 100);
 }
 
@@ -288,12 +327,18 @@ static int sun4i_ts_probe(struct platform_device *pdev)
 	if (IS_ERR(hwmon))
 		return PTR_ERR(hwmon);
 
+	ts->tz = thermal_zone_of_sensor_register(ts->dev, 0, ts,
+						 &sun4i_ts_tz_ops);
+	if (IS_ERR(ts->tz))
+		ts->tz = NULL;
+
 	writel(TEMP_IRQ_EN(1), ts->base + TP_INT_FIFOC);
 
 	if (ts_attached) {
 		error = input_register_device(ts->input);
 		if (error) {
 			writel(0, ts->base + TP_INT_FIFOC);
+			thermal_zone_of_sensor_unregister(ts->dev, ts->tz);
 			return error;
 		}
 	}
@@ -310,6 +355,8 @@ static int sun4i_ts_remove(struct platform_device *pdev)
 	if (ts->input)
 		input_unregister_device(ts->input);
 
+	thermal_zone_of_sensor_unregister(ts->dev, ts->tz);
+
 	/* Deactivate all IRQs */
 	writel(0, ts->base + TP_INT_FIFOC);
 
-- 
2.1.4


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

* [PATCH v2 1/9] Input: sun4i-ts: Add thermal zone sensor support
@ 2015-01-09 10:17   ` Chen-Yu Tsai
  0 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-09 10:17 UTC (permalink / raw)
  To: linux-arm-kernel

The touchscreen controller has a temperature sensor embedded in the SoC,
which already has hwmon support in the driver.

Add DT thermal zone support so we can use it with cpufreq for thermal
throttling.

This also adds a comment stating that we do not know the actual formula
for calculating the temperature.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---

changes since v1:

    - clean up thermal zone sensor when input device register fails
    - unconditionally unregister thermal zone sensor on removal.
      the unregister function checks the pointers passed in.
    - add comment explaining the lack of documents for the temperature
      calculation formula

---
 .../bindings/input/touchscreen/sun4i.txt           |  2 +
 drivers/input/touchscreen/sun4i-ts.c               | 47 ++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
index aef57791f40b..a8405bab6c00 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
+++ b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
@@ -5,6 +5,7 @@ Required properties:
  - compatible: "allwinner,sun4i-a10-ts"
  - reg: mmio address range of the chip
  - interrupts: interrupt to which the chip is connected
+ - #thermal-sensor-cells: shall be 0
 
 Optional properties:
  - allwinner,ts-attached: boolean indicating that an actual touchscreen is
@@ -17,4 +18,5 @@ Example:
 		reg = <0x01c25000 0x100>;
 		interrupts = <29>;
 		allwinner,ts-attached;
+		#thermal-sensor-cells = <0>;
 	};
diff --git a/drivers/input/touchscreen/sun4i-ts.c b/drivers/input/touchscreen/sun4i-ts.c
index 28a06749ae42..aac49db0b09d 100644
--- a/drivers/input/touchscreen/sun4i-ts.c
+++ b/drivers/input/touchscreen/sun4i-ts.c
@@ -34,6 +34,7 @@
 
 #include <linux/err.h>
 #include <linux/hwmon.h>
+#include <linux/thermal.h>
 #include <linux/init.h>
 #include <linux/input.h>
 #include <linux/interrupt.h>
@@ -107,6 +108,7 @@
 struct sun4i_ts_data {
 	struct device *dev;
 	struct input_dev *input;
+	struct thermal_zone_device *tz;
 	void __iomem *base;
 	unsigned int irq;
 	bool ignore_fifo_data;
@@ -180,6 +182,33 @@ static void sun4i_ts_close(struct input_dev *dev)
 	writel(TEMP_IRQ_EN(1), ts->base + TP_INT_FIFOC);
 }
 
+static int get_temp(void *data, long *temp)
+{
+	struct sun4i_ts_data *ts = data;
+
+	/* No temp_data until the first irq */
+	if (ts->temp_data == -1)
+		return -EAGAIN;
+
+	/*
+	 * The user manuals do not contain the formula for calculating
+	 * the temperature. The formula used here is from the AXP209,
+	 * which is designed by X-Powers, an affiliate of Allwinner:
+	 *
+	 *     temperature = -144.7 + (value * 0.1)
+	 *
+	 * This should be replaced with the correct one if such information
+	 * becomes available.
+	 */
+	*temp = (ts->temp_data - 1447) * 100;
+
+	return 0;
+}
+
+static struct thermal_zone_of_device_ops sun4i_ts_tz_ops = {
+	.get_temp = get_temp,
+};
+
 static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
 			 char *buf)
 {
@@ -189,6 +218,16 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
 	if (ts->temp_data == -1)
 		return -EAGAIN;
 
+	/*
+	 * The user manuals do not contain the formula for calculating
+	 * the temperature. The formula used here is from the AXP209,
+	 * which is designed by X-Powers, an affiliate of Allwinner:
+	 *
+	 *     temperature = -144.7 + (value * 0.1)
+	 *
+	 * This should be replaced with the correct one if such information
+	 * becomes available.
+	 */
 	return sprintf(buf, "%d\n", (ts->temp_data - 1447) * 100);
 }
 
@@ -288,12 +327,18 @@ static int sun4i_ts_probe(struct platform_device *pdev)
 	if (IS_ERR(hwmon))
 		return PTR_ERR(hwmon);
 
+	ts->tz = thermal_zone_of_sensor_register(ts->dev, 0, ts,
+						 &sun4i_ts_tz_ops);
+	if (IS_ERR(ts->tz))
+		ts->tz = NULL;
+
 	writel(TEMP_IRQ_EN(1), ts->base + TP_INT_FIFOC);
 
 	if (ts_attached) {
 		error = input_register_device(ts->input);
 		if (error) {
 			writel(0, ts->base + TP_INT_FIFOC);
+			thermal_zone_of_sensor_unregister(ts->dev, ts->tz);
 			return error;
 		}
 	}
@@ -310,6 +355,8 @@ static int sun4i_ts_remove(struct platform_device *pdev)
 	if (ts->input)
 		input_unregister_device(ts->input);
 
+	thermal_zone_of_sensor_unregister(ts->dev, ts->tz);
+
 	/* Deactivate all IRQs */
 	writel(0, ts->base + TP_INT_FIFOC);
 
-- 
2.1.4

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

* [PATCH v2 2/9] ARM: dts: sunxi: Add dtsi for AXP209 PMIC
  2015-01-09 10:17 ` Chen-Yu Tsai
@ 2015-01-09 10:17   ` Chen-Yu Tsai
  -1 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-09 10:17 UTC (permalink / raw)
  To: Maxime Ripard, Dmitry Torokhov, Zhang Rui, Eduardo Valentin
  Cc: Chen-Yu Tsai, Hans de Goede, linux-input, linux-arm-kernel, linux-pm

The AXP209 PMIC is used with some Allwinner SoCs. This patch adds
a dtsi file listing all the regulator nodes. The regulators are
initialized based on their device node names.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---

changes since v1:

    - Moved interrupt controller properties to this patch
    - Added default names for all the regulators
    - Removed needless comment above regulators section

---
 arch/arm/boot/dts/axp209.dtsi | 97 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)
 create mode 100644 arch/arm/boot/dts/axp209.dtsi

diff --git a/arch/arm/boot/dts/axp209.dtsi b/arch/arm/boot/dts/axp209.dtsi
new file mode 100644
index 000000000000..c20cf537f5a5
--- /dev/null
+++ b/arch/arm/boot/dts/axp209.dtsi
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2015 Chen-Yu Tsai
+ *
+ * Chen-Yu Tsai <wens@csie.org>
+ *
+ * This file is dual-licensed: you can use it either under the terms
+ * of the GPL or the X11 license, at your option. Note that this dual
+ * licensing only applies to this file, and not this project as a
+ * whole.
+ *
+ *  a) This file 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 file 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.
+ *
+ *     You should have received a copy of the GNU General Public
+ *     License along with this file; if not, write to the Free
+ *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ *     MA 02110-1301 USA
+ *
+ * Or, alternatively,
+ *
+ *  b) Permission is hereby granted, free of charge, to any person
+ *     obtaining a copy of this software and associated documentation
+ *     files (the "Software"), to deal in the Software without
+ *     restriction, including without limitation the rights to use,
+ *     copy, modify, merge, publish, distribute, sublicense, and/or
+ *     sell copies of the Software, and to permit persons to whom the
+ *     Software is furnished to do so, subject to the following
+ *     conditions:
+ *
+ *     The above copyright notice and this permission notice shall be
+ *     included in all copies or substantial portions of the Software.
+ *
+ *     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *     OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * AXP202/209 Integrated Power Management Chip
+ * http://www.x-powers.com/product/AXP20X.php
+ * http://dl.linux-sunxi.org/AXP/AXP209%20Datasheet%20v1.0_cn.pdf
+ */
+
+&axp209 {
+	compatible = "x-powers,axp209";
+	interrupt-controller;
+	#interrupt-cells = <1>;
+
+	regulators {
+		/* Default work frequency for buck regulators */
+		x-powers,dcdc-freq = <1500>;
+
+		reg_dcdc2: dcdc2 {
+			regulator-name = "dcdc2";
+		};
+
+		reg_dcdc3: dcdc3 {
+			regulator-name = "dcdc3";
+		};
+
+		reg_ldo1: ldo1 {
+			/* LDO1 is a fixed output regulator */
+			regulator-always-on;
+			regulator-min-microvolt = <1300000>;
+			regulator-max-microvolt = <1300000>;
+			regulator-name = "ldo1";
+		};
+
+		reg_ldo2: ldo2 {
+			regulator-name = "ldo2";
+		};
+
+		reg_ldo3: ldo3 {
+			regulator-name = "ldo3";
+		};
+
+		reg_ldo4: ldo4 {
+			regulator-name = "ldo4";
+		};
+
+		reg_ldo5: ldo5 {
+			regulator-name = "ldo5";
+		};
+	};
+};
-- 
2.1.4


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

* [PATCH v2 2/9] ARM: dts: sunxi: Add dtsi for AXP209 PMIC
@ 2015-01-09 10:17   ` Chen-Yu Tsai
  0 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-09 10:17 UTC (permalink / raw)
  To: linux-arm-kernel

The AXP209 PMIC is used with some Allwinner SoCs. This patch adds
a dtsi file listing all the regulator nodes. The regulators are
initialized based on their device node names.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---

changes since v1:

    - Moved interrupt controller properties to this patch
    - Added default names for all the regulators
    - Removed needless comment above regulators section

---
 arch/arm/boot/dts/axp209.dtsi | 97 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)
 create mode 100644 arch/arm/boot/dts/axp209.dtsi

diff --git a/arch/arm/boot/dts/axp209.dtsi b/arch/arm/boot/dts/axp209.dtsi
new file mode 100644
index 000000000000..c20cf537f5a5
--- /dev/null
+++ b/arch/arm/boot/dts/axp209.dtsi
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2015 Chen-Yu Tsai
+ *
+ * Chen-Yu Tsai <wens@csie.org>
+ *
+ * This file is dual-licensed: you can use it either under the terms
+ * of the GPL or the X11 license, at your option. Note that this dual
+ * licensing only applies to this file, and not this project as a
+ * whole.
+ *
+ *  a) This file 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 file 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.
+ *
+ *     You should have received a copy of the GNU General Public
+ *     License along with this file; if not, write to the Free
+ *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ *     MA 02110-1301 USA
+ *
+ * Or, alternatively,
+ *
+ *  b) Permission is hereby granted, free of charge, to any person
+ *     obtaining a copy of this software and associated documentation
+ *     files (the "Software"), to deal in the Software without
+ *     restriction, including without limitation the rights to use,
+ *     copy, modify, merge, publish, distribute, sublicense, and/or
+ *     sell copies of the Software, and to permit persons to whom the
+ *     Software is furnished to do so, subject to the following
+ *     conditions:
+ *
+ *     The above copyright notice and this permission notice shall be
+ *     included in all copies or substantial portions of the Software.
+ *
+ *     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *     OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * AXP202/209 Integrated Power Management Chip
+ * http://www.x-powers.com/product/AXP20X.php
+ * http://dl.linux-sunxi.org/AXP/AXP209%20Datasheet%20v1.0_cn.pdf
+ */
+
+&axp209 {
+	compatible = "x-powers,axp209";
+	interrupt-controller;
+	#interrupt-cells = <1>;
+
+	regulators {
+		/* Default work frequency for buck regulators */
+		x-powers,dcdc-freq = <1500>;
+
+		reg_dcdc2: dcdc2 {
+			regulator-name = "dcdc2";
+		};
+
+		reg_dcdc3: dcdc3 {
+			regulator-name = "dcdc3";
+		};
+
+		reg_ldo1: ldo1 {
+			/* LDO1 is a fixed output regulator */
+			regulator-always-on;
+			regulator-min-microvolt = <1300000>;
+			regulator-max-microvolt = <1300000>;
+			regulator-name = "ldo1";
+		};
+
+		reg_ldo2: ldo2 {
+			regulator-name = "ldo2";
+		};
+
+		reg_ldo3: ldo3 {
+			regulator-name = "ldo3";
+		};
+
+		reg_ldo4: ldo4 {
+			regulator-name = "ldo4";
+		};
+
+		reg_ldo5: ldo5 {
+			regulator-name = "ldo5";
+		};
+	};
+};
-- 
2.1.4

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

* [PATCH v2 3/9] ARM: dts: sun7i: Add cpu thermal zones to dtsi
  2015-01-09 10:17 ` Chen-Yu Tsai
@ 2015-01-09 10:17   ` Chen-Yu Tsai
  -1 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-09 10:17 UTC (permalink / raw)
  To: Maxime Ripard, Dmitry Torokhov, Zhang Rui, Eduardo Valentin
  Cc: Chen-Yu Tsai, Hans de Goede, linux-input, linux-arm-kernel, linux-pm

The core temperature sensor now supports thermal zones. Add a thermal
zone mapping for the cpus with passive cooling (cpufreq throttling).

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---

changes since v1:

    - Use thermal dt bindings macros in cooling-device

---
 arch/arm/boot/dts/sun7i-a20.dtsi | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index c2e964939991..61780b144745 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -50,6 +50,7 @@
 #include "skeleton.dtsi"
 
 #include <dt-bindings/interrupt-controller/arm-gic.h>
+#include <dt-bindings/thermal/thermal.h>
 
 #include <dt-bindings/dma/sun4i-a10.h>
 #include <dt-bindings/pinctrl/sun4i-a10.h>
@@ -116,6 +117,38 @@
 		};
 	};
 
+	thermal-zones {
+		cpu_thermal {
+			/* milliseconds */
+			polling-delay-passive = <250>;
+			polling-delay = <1000>;
+			thermal-sensors = <&rtp>;
+
+			cooling-maps {
+				map0 {
+					trip = <&cpu_alert0>;
+					cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
+				};
+			};
+
+			trips {
+				cpu_alert0: cpu_alert0 {
+					/* milliCelsius */
+					temperature = <75000>;
+					hysteresis = <2000>;
+					type = "passive";
+				};
+
+				cpu_crit: cpu_crit {
+					/* milliCelsius */
+					temperature = <100000>;
+					hysteresis = <2000>;
+					type = "critical";
+				};
+			};
+		};
+	};
+
 	memory {
 		reg = <0x40000000 0x80000000>;
 	};
-- 
2.1.4


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

* [PATCH v2 3/9] ARM: dts: sun7i: Add cpu thermal zones to dtsi
@ 2015-01-09 10:17   ` Chen-Yu Tsai
  0 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-09 10:17 UTC (permalink / raw)
  To: linux-arm-kernel

The core temperature sensor now supports thermal zones. Add a thermal
zone mapping for the cpus with passive cooling (cpufreq throttling).

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---

changes since v1:

    - Use thermal dt bindings macros in cooling-device

---
 arch/arm/boot/dts/sun7i-a20.dtsi | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index c2e964939991..61780b144745 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -50,6 +50,7 @@
 #include "skeleton.dtsi"
 
 #include <dt-bindings/interrupt-controller/arm-gic.h>
+#include <dt-bindings/thermal/thermal.h>
 
 #include <dt-bindings/dma/sun4i-a10.h>
 #include <dt-bindings/pinctrl/sun4i-a10.h>
@@ -116,6 +117,38 @@
 		};
 	};
 
+	thermal-zones {
+		cpu_thermal {
+			/* milliseconds */
+			polling-delay-passive = <250>;
+			polling-delay = <1000>;
+			thermal-sensors = <&rtp>;
+
+			cooling-maps {
+				map0 {
+					trip = <&cpu_alert0>;
+					cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
+				};
+			};
+
+			trips {
+				cpu_alert0: cpu_alert0 {
+					/* milliCelsius */
+					temperature = <75000>;
+					hysteresis = <2000>;
+					type = "passive";
+				};
+
+				cpu_crit: cpu_crit {
+					/* milliCelsius */
+					temperature = <100000>;
+					hysteresis = <2000>;
+					type = "critical";
+				};
+			};
+		};
+	};
+
 	memory {
 		reg = <0x40000000 0x80000000>;
 	};
-- 
2.1.4

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

* [PATCH v2 4/9] ARM: dts: sun7i: cubieboard2: add axp209 regulator nodes
  2015-01-09 10:17 ` Chen-Yu Tsai
@ 2015-01-09 10:17   ` Chen-Yu Tsai
  -1 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-09 10:17 UTC (permalink / raw)
  To: Maxime Ripard, Dmitry Torokhov, Zhang Rui, Eduardo Valentin
  Cc: Hans de Goede, Chen-Yu Tsai, linux-pm, linux-arm-kernel, linux-input

This patch adds the regulator nodes for the axp209 by including
the axp209 dtsi. As the inputs of these regulators are from the
axp209's PS output, which is basically just a mux over the 2
inputs, it is considered to be unregulated. Thus we do not provide
input supply properties for them.

The regulator names and constraints are based on the board
schematics and the SoC datasheet.

DCDC2 is used as the cpu power supply. This patch also references
it from the cpu node.

Also get rid of axp209 properties already set in axp209.dtsi.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---

changes since v1:

    - Use preprocessor include for axp209.dtsi
    - Remove incorrectly squashed axp209.dtsi patch

---
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts | 35 +++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
index 18fc5db9c976..ec1fc2c8b3e3 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
@@ -88,13 +88,9 @@
 			status = "okay";
 
 			axp209: pmic@34 {
-				compatible = "x-powers,axp209";
 				reg = <0x34>;
 				interrupt-parent = <&nmi_intc>;
 				interrupts = <0 IRQ_TYPE_LEVEL_LOW>;
-
-				interrupt-controller;
-				#interrupt-cells = <1>;
 			};
 		};
 
@@ -145,3 +141,34 @@
 		status = "okay";
 	};
 };
+
+#include "axp209.dtsi"
+
+&cpu0 {
+	cpu-supply = <&reg_dcdc2>;
+};
+
+&reg_dcdc2 {
+	regulator-always-on;
+	regulator-min-microvolt = <1000000>;
+	regulator-max-microvolt = <1450000>;
+	regulator-name = "vdd-cpu";
+};
+
+&reg_dcdc3 {
+	regulator-always-on;
+	regulator-min-microvolt = <1000000>;
+	regulator-max-microvolt = <1400000>;
+	regulator-name = "vdd-int-dll";
+};
+
+&reg_ldo1 {
+	regulator-name = "vdd-rtc";
+};
+
+&reg_ldo2 {
+	regulator-always-on;
+	regulator-min-microvolt = <3000000>;
+	regulator-max-microvolt = <3000000>;
+	regulator-name = "avcc";
+};
-- 
2.1.4

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

* [PATCH v2 4/9] ARM: dts: sun7i: cubieboard2: add axp209 regulator nodes
@ 2015-01-09 10:17   ` Chen-Yu Tsai
  0 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-09 10:17 UTC (permalink / raw)
  To: linux-arm-kernel

This patch adds the regulator nodes for the axp209 by including
the axp209 dtsi. As the inputs of these regulators are from the
axp209's PS output, which is basically just a mux over the 2
inputs, it is considered to be unregulated. Thus we do not provide
input supply properties for them.

The regulator names and constraints are based on the board
schematics and the SoC datasheet.

DCDC2 is used as the cpu power supply. This patch also references
it from the cpu node.

Also get rid of axp209 properties already set in axp209.dtsi.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---

changes since v1:

    - Use preprocessor include for axp209.dtsi
    - Remove incorrectly squashed axp209.dtsi patch

---
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts | 35 +++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
index 18fc5db9c976..ec1fc2c8b3e3 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
@@ -88,13 +88,9 @@
 			status = "okay";
 
 			axp209: pmic at 34 {
-				compatible = "x-powers,axp209";
 				reg = <0x34>;
 				interrupt-parent = <&nmi_intc>;
 				interrupts = <0 IRQ_TYPE_LEVEL_LOW>;
-
-				interrupt-controller;
-				#interrupt-cells = <1>;
 			};
 		};
 
@@ -145,3 +141,34 @@
 		status = "okay";
 	};
 };
+
+#include "axp209.dtsi"
+
+&cpu0 {
+	cpu-supply = <&reg_dcdc2>;
+};
+
+&reg_dcdc2 {
+	regulator-always-on;
+	regulator-min-microvolt = <1000000>;
+	regulator-max-microvolt = <1450000>;
+	regulator-name = "vdd-cpu";
+};
+
+&reg_dcdc3 {
+	regulator-always-on;
+	regulator-min-microvolt = <1000000>;
+	regulator-max-microvolt = <1400000>;
+	regulator-name = "vdd-int-dll";
+};
+
+&reg_ldo1 {
+	regulator-name = "vdd-rtc";
+};
+
+&reg_ldo2 {
+	regulator-always-on;
+	regulator-min-microvolt = <3000000>;
+	regulator-max-microvolt = <3000000>;
+	regulator-name = "avcc";
+};
-- 
2.1.4

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

* [PATCH v2 5/9] ARM: dts: sun7i: cubietruck: add axp209 regulator nodes
  2015-01-09 10:17 ` Chen-Yu Tsai
@ 2015-01-09 10:17   ` Chen-Yu Tsai
  -1 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-09 10:17 UTC (permalink / raw)
  To: Maxime Ripard, Dmitry Torokhov, Zhang Rui, Eduardo Valentin
  Cc: Chen-Yu Tsai, Hans de Goede, linux-input, linux-arm-kernel, linux-pm

This patch adds the regulator nodes for the axp209 by including
the axp209 dtsi. As the inputs of these regulators are from the
axp209's PS output, which is basically just a mux over the 2
inputs, it is considered to be unregulated. Thus we do not provide
input supply properties for them.

The regulator names and constraints are based on the board
schematics and the SoC datasheet.

DCDC2 is used as the cpu power supply. This patch also references
it from the cpu node.

Also get rid of axp209 properties already set in axp209.dtsi.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---

changes since v1:

    - Use preprocessor include for axp209.dtsi

---
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts | 35 ++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
index 77bc7e79cab9..5f817b65ceea 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
@@ -130,13 +130,9 @@
 			status = "okay";
 
 			axp209: pmic@34 {
-				compatible = "x-powers,axp209";
 				reg = <0x34>;
 				interrupt-parent = <&nmi_intc>;
 				interrupts = <0 IRQ_TYPE_LEVEL_LOW>;
-
-				interrupt-controller;
-				#interrupt-cells = <1>;
 			};
 		};
 
@@ -222,3 +218,34 @@
 		gpio = <&pio 7 9 GPIO_ACTIVE_HIGH>;
 	};
 };
+
+#include "axp209.dtsi"
+
+&cpu0 {
+	cpu-supply = <&reg_dcdc2>;
+};
+
+&reg_dcdc2 {
+	regulator-always-on;
+	regulator-min-microvolt = <1000000>;
+	regulator-max-microvolt = <1450000>;
+	regulator-name = "vdd-cpu";
+};
+
+&reg_dcdc3 {
+	regulator-always-on;
+	regulator-min-microvolt = <1000000>;
+	regulator-max-microvolt = <1400000>;
+	regulator-name = "vdd-int-dll";
+};
+
+&reg_ldo1 {
+	regulator-name = "vdd-rtc";
+};
+
+&reg_ldo2 {
+	regulator-always-on;
+	regulator-min-microvolt = <3000000>;
+	regulator-max-microvolt = <3000000>;
+	regulator-name = "avcc";
+};
-- 
2.1.4


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

* [PATCH v2 5/9] ARM: dts: sun7i: cubietruck: add axp209 regulator nodes
@ 2015-01-09 10:17   ` Chen-Yu Tsai
  0 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-09 10:17 UTC (permalink / raw)
  To: linux-arm-kernel

This patch adds the regulator nodes for the axp209 by including
the axp209 dtsi. As the inputs of these regulators are from the
axp209's PS output, which is basically just a mux over the 2
inputs, it is considered to be unregulated. Thus we do not provide
input supply properties for them.

The regulator names and constraints are based on the board
schematics and the SoC datasheet.

DCDC2 is used as the cpu power supply. This patch also references
it from the cpu node.

Also get rid of axp209 properties already set in axp209.dtsi.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---

changes since v1:

    - Use preprocessor include for axp209.dtsi

---
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts | 35 ++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
index 77bc7e79cab9..5f817b65ceea 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
@@ -130,13 +130,9 @@
 			status = "okay";
 
 			axp209: pmic at 34 {
-				compatible = "x-powers,axp209";
 				reg = <0x34>;
 				interrupt-parent = <&nmi_intc>;
 				interrupts = <0 IRQ_TYPE_LEVEL_LOW>;
-
-				interrupt-controller;
-				#interrupt-cells = <1>;
 			};
 		};
 
@@ -222,3 +218,34 @@
 		gpio = <&pio 7 9 GPIO_ACTIVE_HIGH>;
 	};
 };
+
+#include "axp209.dtsi"
+
+&cpu0 {
+	cpu-supply = <&reg_dcdc2>;
+};
+
+&reg_dcdc2 {
+	regulator-always-on;
+	regulator-min-microvolt = <1000000>;
+	regulator-max-microvolt = <1450000>;
+	regulator-name = "vdd-cpu";
+};
+
+&reg_dcdc3 {
+	regulator-always-on;
+	regulator-min-microvolt = <1000000>;
+	regulator-max-microvolt = <1400000>;
+	regulator-name = "vdd-int-dll";
+};
+
+&reg_ldo1 {
+	regulator-name = "vdd-rtc";
+};
+
+&reg_ldo2 {
+	regulator-always-on;
+	regulator-min-microvolt = <3000000>;
+	regulator-max-microvolt = <3000000>;
+	regulator-name = "avcc";
+};
-- 
2.1.4

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

* [PATCH v2 6/9] ARM: dts: sun5i: Add cpu thermal zones to dtsi
  2015-01-09 10:17 ` Chen-Yu Tsai
@ 2015-01-09 10:17   ` Chen-Yu Tsai
  -1 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-09 10:17 UTC (permalink / raw)
  To: Maxime Ripard, Dmitry Torokhov, Zhang Rui, Eduardo Valentin
  Cc: Chen-Yu Tsai, Hans de Goede, linux-input, linux-arm-kernel, linux-pm

The core temperature sensor now supports thermal zones. Add a thermal
zone mapping for the cpus with passive cooling (cpufreq throttling).

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---

changes since v1:

    - Use thermal dt bindings macros in cooling-device

---
 arch/arm/boot/dts/sun5i-a13.dtsi | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/arch/arm/boot/dts/sun5i-a13.dtsi b/arch/arm/boot/dts/sun5i-a13.dtsi
index dee2aa5bc9ed..c26f58ea0850 100644
--- a/arch/arm/boot/dts/sun5i-a13.dtsi
+++ b/arch/arm/boot/dts/sun5i-a13.dtsi
@@ -13,6 +13,8 @@
 
 #include "skeleton.dtsi"
 
+#include <dt-bindings/thermal/thermal.h>
+
 #include <dt-bindings/dma/sun4i-a10.h>
 #include <dt-bindings/pinctrl/sun4i-a10.h>
 
@@ -50,6 +52,38 @@
 		};
 	};
 
+	thermal-zones {
+		cpu_thermal {
+			/* milliseconds */
+			polling-delay-passive = <250>;
+			polling-delay = <1000>;
+			thermal-sensors = <&rtp>;
+
+			cooling-maps {
+				map0 {
+					trip = <&cpu_alert0>;
+					cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
+				};
+			};
+
+			trips {
+				cpu_alert0: cpu_alert0 {
+					/* milliCelsius */
+					temperature = <850000>;
+					hysteresis = <2000>;
+					type = "passive";
+				};
+
+				cpu_crit: cpu_crit {
+					/* milliCelsius */
+					temperature = <100000>;
+					hysteresis = <2000>;
+					type = "critical";
+				};
+			};
+		};
+	};
+
 	memory {
 		reg = <0x40000000 0x20000000>;
 	};
-- 
2.1.4


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

* [PATCH v2 6/9] ARM: dts: sun5i: Add cpu thermal zones to dtsi
@ 2015-01-09 10:17   ` Chen-Yu Tsai
  0 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-09 10:17 UTC (permalink / raw)
  To: linux-arm-kernel

The core temperature sensor now supports thermal zones. Add a thermal
zone mapping for the cpus with passive cooling (cpufreq throttling).

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---

changes since v1:

    - Use thermal dt bindings macros in cooling-device

---
 arch/arm/boot/dts/sun5i-a13.dtsi | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/arch/arm/boot/dts/sun5i-a13.dtsi b/arch/arm/boot/dts/sun5i-a13.dtsi
index dee2aa5bc9ed..c26f58ea0850 100644
--- a/arch/arm/boot/dts/sun5i-a13.dtsi
+++ b/arch/arm/boot/dts/sun5i-a13.dtsi
@@ -13,6 +13,8 @@
 
 #include "skeleton.dtsi"
 
+#include <dt-bindings/thermal/thermal.h>
+
 #include <dt-bindings/dma/sun4i-a10.h>
 #include <dt-bindings/pinctrl/sun4i-a10.h>
 
@@ -50,6 +52,38 @@
 		};
 	};
 
+	thermal-zones {
+		cpu_thermal {
+			/* milliseconds */
+			polling-delay-passive = <250>;
+			polling-delay = <1000>;
+			thermal-sensors = <&rtp>;
+
+			cooling-maps {
+				map0 {
+					trip = <&cpu_alert0>;
+					cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
+				};
+			};
+
+			trips {
+				cpu_alert0: cpu_alert0 {
+					/* milliCelsius */
+					temperature = <850000>;
+					hysteresis = <2000>;
+					type = "passive";
+				};
+
+				cpu_crit: cpu_crit {
+					/* milliCelsius */
+					temperature = <100000>;
+					hysteresis = <2000>;
+					type = "critical";
+				};
+			};
+		};
+	};
+
 	memory {
 		reg = <0x40000000 0x20000000>;
 	};
-- 
2.1.4

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

* [PATCH v2 7/9] ARM: dts: sun5i: hsg-h702: add axp209 regulator nodes
  2015-01-09 10:17 ` Chen-Yu Tsai
@ 2015-01-09 10:17   ` Chen-Yu Tsai
  -1 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-09 10:17 UTC (permalink / raw)
  To: Maxime Ripard, Dmitry Torokhov, Zhang Rui, Eduardo Valentin
  Cc: Chen-Yu Tsai, Hans de Goede, linux-input, linux-arm-kernel, linux-pm

This patch adds the regulator nodes for the axp209 by including
the axp209 dtsi. As the inputs of these regulators are from the
axp209's PS output, which is basically just a mux over the 2
inputs, it is considered to be unregulated. Thus we do not provide
input supply properties for them.

The regulator names and constraints are based on the board
schematics and the SoC datasheet.

DCDC2 is used as the cpu power supply. This patch also references
it from the cpu node.

LDO3 powers the USB WiFi module. This patch also references it
from the usb-phy node.

Also get rid of axp209 properties already set in axp209.dtsi.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---

changes since v1:

    - Use preprocessor include for axp209.dtsi

---
 arch/arm/boot/dts/sun5i-a13-hsg-h702.dts | 46 ++++++++++++++++++++++++++------
 1 file changed, 38 insertions(+), 8 deletions(-)

diff --git a/arch/arm/boot/dts/sun5i-a13-hsg-h702.dts b/arch/arm/boot/dts/sun5i-a13-hsg-h702.dts
index 99a5968720b4..82637db1c55a 100644
--- a/arch/arm/boot/dts/sun5i-a13-hsg-h702.dts
+++ b/arch/arm/boot/dts/sun5i-a13-hsg-h702.dts
@@ -68,11 +68,7 @@
 		};
 
 		usbphy: phy@01c13400 {
-			/*
-			 * There doesn't seem to be a GPIO for controlling
-			 * usb1 vbus, despite the fex file saying otherwise.
-			 */
-			usb1_vbus-supply = <&reg_vcc5v0>;
+			usb1_vbus-supply = <&reg_ldo3>;
 			status = "okay";
 		};
 
@@ -105,11 +101,8 @@
 			status = "okay";
 
 			axp209: pmic@34 {
-				compatible = "x-powers,axp209";
 				reg = <0x34>;
 				interrupts = <0>;
-				interrupt-controller;
-				#interrupt-cells = <1>;
 			};
 		};
 
@@ -131,3 +124,40 @@
 		};
 	};
 };
+
+#include "axp209.dtsi"
+
+&cpu0 {
+	cpu-supply = <&reg_dcdc2>;
+};
+
+&reg_dcdc2 {
+	regulator-always-on;
+	regulator-min-microvolt = <1000000>;
+	regulator-max-microvolt = <1500000>;
+	regulator-name = "vdd-cpu";
+};
+
+&reg_dcdc3 {
+	regulator-always-on;
+	regulator-min-microvolt = <1000000>;
+	regulator-max-microvolt = <1400000>;
+	regulator-name = "vdd-int-dll";
+};
+
+&reg_ldo1 {
+	regulator-name = "vdd-rtc";
+};
+
+&reg_ldo2 {
+	regulator-always-on;
+	regulator-min-microvolt = <3000000>;
+	regulator-max-microvolt = <3000000>;
+	regulator-name = "avcc";
+};
+
+&reg_ldo3 {
+	regulator-min-microvolt = <3300000>;
+	regulator-max-microvolt = <3300000>;
+	regulator-name = "vcc-wifi";
+};
-- 
2.1.4


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

* [PATCH v2 7/9] ARM: dts: sun5i: hsg-h702: add axp209 regulator nodes
@ 2015-01-09 10:17   ` Chen-Yu Tsai
  0 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-09 10:17 UTC (permalink / raw)
  To: linux-arm-kernel

This patch adds the regulator nodes for the axp209 by including
the axp209 dtsi. As the inputs of these regulators are from the
axp209's PS output, which is basically just a mux over the 2
inputs, it is considered to be unregulated. Thus we do not provide
input supply properties for them.

The regulator names and constraints are based on the board
schematics and the SoC datasheet.

DCDC2 is used as the cpu power supply. This patch also references
it from the cpu node.

LDO3 powers the USB WiFi module. This patch also references it
from the usb-phy node.

Also get rid of axp209 properties already set in axp209.dtsi.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---

changes since v1:

    - Use preprocessor include for axp209.dtsi

---
 arch/arm/boot/dts/sun5i-a13-hsg-h702.dts | 46 ++++++++++++++++++++++++++------
 1 file changed, 38 insertions(+), 8 deletions(-)

diff --git a/arch/arm/boot/dts/sun5i-a13-hsg-h702.dts b/arch/arm/boot/dts/sun5i-a13-hsg-h702.dts
index 99a5968720b4..82637db1c55a 100644
--- a/arch/arm/boot/dts/sun5i-a13-hsg-h702.dts
+++ b/arch/arm/boot/dts/sun5i-a13-hsg-h702.dts
@@ -68,11 +68,7 @@
 		};
 
 		usbphy: phy at 01c13400 {
-			/*
-			 * There doesn't seem to be a GPIO for controlling
-			 * usb1 vbus, despite the fex file saying otherwise.
-			 */
-			usb1_vbus-supply = <&reg_vcc5v0>;
+			usb1_vbus-supply = <&reg_ldo3>;
 			status = "okay";
 		};
 
@@ -105,11 +101,8 @@
 			status = "okay";
 
 			axp209: pmic at 34 {
-				compatible = "x-powers,axp209";
 				reg = <0x34>;
 				interrupts = <0>;
-				interrupt-controller;
-				#interrupt-cells = <1>;
 			};
 		};
 
@@ -131,3 +124,40 @@
 		};
 	};
 };
+
+#include "axp209.dtsi"
+
+&cpu0 {
+	cpu-supply = <&reg_dcdc2>;
+};
+
+&reg_dcdc2 {
+	regulator-always-on;
+	regulator-min-microvolt = <1000000>;
+	regulator-max-microvolt = <1500000>;
+	regulator-name = "vdd-cpu";
+};
+
+&reg_dcdc3 {
+	regulator-always-on;
+	regulator-min-microvolt = <1000000>;
+	regulator-max-microvolt = <1400000>;
+	regulator-name = "vdd-int-dll";
+};
+
+&reg_ldo1 {
+	regulator-name = "vdd-rtc";
+};
+
+&reg_ldo2 {
+	regulator-always-on;
+	regulator-min-microvolt = <3000000>;
+	regulator-max-microvolt = <3000000>;
+	regulator-name = "avcc";
+};
+
+&reg_ldo3 {
+	regulator-min-microvolt = <3300000>;
+	regulator-max-microvolt = <3300000>;
+	regulator-name = "vcc-wifi";
+};
-- 
2.1.4

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

* [PATCH v2 8/9] ARM: dts: sun4i: Add cpu thermal zones to dtsi
  2015-01-09 10:17 ` Chen-Yu Tsai
@ 2015-01-09 10:17   ` Chen-Yu Tsai
  -1 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-09 10:17 UTC (permalink / raw)
  To: Maxime Ripard, Dmitry Torokhov, Zhang Rui, Eduardo Valentin
  Cc: Chen-Yu Tsai, Hans de Goede, linux-input, linux-arm-kernel, linux-pm

The core temperature sensor now supports thermal zones. Add a thermal
zone mapping for the cpus with passive cooling (cpufreq throttling).

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---

changes since v1:

    - Use thermal dt bindings macros in cooling-device

---
 arch/arm/boot/dts/sun4i-a10.dtsi | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/arch/arm/boot/dts/sun4i-a10.dtsi b/arch/arm/boot/dts/sun4i-a10.dtsi
index 7fb4e912f510..f0dc246dc69e 100644
--- a/arch/arm/boot/dts/sun4i-a10.dtsi
+++ b/arch/arm/boot/dts/sun4i-a10.dtsi
@@ -12,6 +12,8 @@
 
 #include "skeleton.dtsi"
 
+#include <dt-bindings/thermal/thermal.h>
+
 #include <dt-bindings/dma/sun4i-a10.h>
 #include <dt-bindings/pinctrl/sun4i-a10.h>
 
@@ -67,6 +69,38 @@
 		};
 	};
 
+	thermal-zones {
+		cpu_thermal {
+			/* milliseconds */
+			polling-delay-passive = <250>;
+			polling-delay = <1000>;
+			thermal-sensors = <&rtp>;
+
+			cooling-maps {
+				map0 {
+					trip = <&cpu_alert0>;
+					cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
+				};
+			};
+
+			trips {
+				cpu_alert0: cpu_alert0 {
+					/* milliCelsius */
+					temperature = <850000>;
+					hysteresis = <2000>;
+					type = "passive";
+				};
+
+				cpu_crit: cpu_crit {
+					/* milliCelsius */
+					temperature = <100000>;
+					hysteresis = <2000>;
+					type = "critical";
+				};
+			};
+		};
+	};
+
 	memory {
 		reg = <0x40000000 0x80000000>;
 	};
-- 
2.1.4


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

* [PATCH v2 8/9] ARM: dts: sun4i: Add cpu thermal zones to dtsi
@ 2015-01-09 10:17   ` Chen-Yu Tsai
  0 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-09 10:17 UTC (permalink / raw)
  To: linux-arm-kernel

The core temperature sensor now supports thermal zones. Add a thermal
zone mapping for the cpus with passive cooling (cpufreq throttling).

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---

changes since v1:

    - Use thermal dt bindings macros in cooling-device

---
 arch/arm/boot/dts/sun4i-a10.dtsi | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/arch/arm/boot/dts/sun4i-a10.dtsi b/arch/arm/boot/dts/sun4i-a10.dtsi
index 7fb4e912f510..f0dc246dc69e 100644
--- a/arch/arm/boot/dts/sun4i-a10.dtsi
+++ b/arch/arm/boot/dts/sun4i-a10.dtsi
@@ -12,6 +12,8 @@
 
 #include "skeleton.dtsi"
 
+#include <dt-bindings/thermal/thermal.h>
+
 #include <dt-bindings/dma/sun4i-a10.h>
 #include <dt-bindings/pinctrl/sun4i-a10.h>
 
@@ -67,6 +69,38 @@
 		};
 	};
 
+	thermal-zones {
+		cpu_thermal {
+			/* milliseconds */
+			polling-delay-passive = <250>;
+			polling-delay = <1000>;
+			thermal-sensors = <&rtp>;
+
+			cooling-maps {
+				map0 {
+					trip = <&cpu_alert0>;
+					cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
+				};
+			};
+
+			trips {
+				cpu_alert0: cpu_alert0 {
+					/* milliCelsius */
+					temperature = <850000>;
+					hysteresis = <2000>;
+					type = "passive";
+				};
+
+				cpu_crit: cpu_crit {
+					/* milliCelsius */
+					temperature = <100000>;
+					hysteresis = <2000>;
+					type = "critical";
+				};
+			};
+		};
+	};
+
 	memory {
 		reg = <0x40000000 0x80000000>;
 	};
-- 
2.1.4

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

* [PATCH v2 9/9] ARM: dts: sun4i: cubieboard: add axp209 regulator nodes
  2015-01-09 10:17 ` Chen-Yu Tsai
@ 2015-01-09 10:17   ` Chen-Yu Tsai
  -1 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-09 10:17 UTC (permalink / raw)
  To: Maxime Ripard, Dmitry Torokhov, Zhang Rui, Eduardo Valentin
  Cc: Chen-Yu Tsai, Hans de Goede, linux-input, linux-arm-kernel, linux-pm

This patch adds the regulator nodes for the axp209 by including
the axp209 dtsi. As the inputs of these regulators are from the
axp209's PS output, which is basically just a mux over the 2
inputs, it is considered to be unregulated. Thus we do not provide
input supply properties for them.

The regulator names and constraints are based on the board
schematics and the SoC datasheet.

DCDC2 is used as the cpu power supply. This patch also references
it from the cpu node.

Also get rid of axp209 properties already set in axp209.dtsi.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---

changes since v1:

    - Use preprocessor include for axp209.dtsi

---
 arch/arm/boot/dts/sun4i-a10-cubieboard.dts | 35 ++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boot/dts/sun4i-a10-cubieboard.dts b/arch/arm/boot/dts/sun4i-a10-cubieboard.dts
index 87ac84db836d..4260c2b47607 100644
--- a/arch/arm/boot/dts/sun4i-a10-cubieboard.dts
+++ b/arch/arm/boot/dts/sun4i-a10-cubieboard.dts
@@ -137,12 +137,8 @@
 			status = "okay";
 
 			axp209: pmic@34 {
-				compatible = "x-powers,axp209";
 				reg = <0x34>;
 				interrupts = <0>;
-
-				interrupt-controller;
-				#interrupt-cells = <1>;
 			};
 		};
 
@@ -188,3 +184,34 @@
 		status = "okay";
 	};
 };
+
+#include "axp209.dtsi"
+
+&cpu0 {
+	cpu-supply = <&reg_dcdc2>;
+};
+
+&reg_dcdc2 {
+	regulator-always-on;
+	regulator-min-microvolt = <1000000>;
+	regulator-max-microvolt = <1450000>;
+	regulator-name = "vdd-cpu";
+};
+
+&reg_dcdc3 {
+	regulator-always-on;
+	regulator-min-microvolt = <1000000>;
+	regulator-max-microvolt = <1400000>;
+	regulator-name = "vdd-int-dll";
+};
+
+&reg_ldo1 {
+	regulator-name = "vdd-rtc";
+};
+
+&reg_ldo2 {
+	regulator-always-on;
+	regulator-min-microvolt = <3000000>;
+	regulator-max-microvolt = <3000000>;
+	regulator-name = "avcc";
+};
-- 
2.1.4


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

* [PATCH v2 9/9] ARM: dts: sun4i: cubieboard: add axp209 regulator nodes
@ 2015-01-09 10:17   ` Chen-Yu Tsai
  0 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-09 10:17 UTC (permalink / raw)
  To: linux-arm-kernel

This patch adds the regulator nodes for the axp209 by including
the axp209 dtsi. As the inputs of these regulators are from the
axp209's PS output, which is basically just a mux over the 2
inputs, it is considered to be unregulated. Thus we do not provide
input supply properties for them.

The regulator names and constraints are based on the board
schematics and the SoC datasheet.

DCDC2 is used as the cpu power supply. This patch also references
it from the cpu node.

Also get rid of axp209 properties already set in axp209.dtsi.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---

changes since v1:

    - Use preprocessor include for axp209.dtsi

---
 arch/arm/boot/dts/sun4i-a10-cubieboard.dts | 35 ++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boot/dts/sun4i-a10-cubieboard.dts b/arch/arm/boot/dts/sun4i-a10-cubieboard.dts
index 87ac84db836d..4260c2b47607 100644
--- a/arch/arm/boot/dts/sun4i-a10-cubieboard.dts
+++ b/arch/arm/boot/dts/sun4i-a10-cubieboard.dts
@@ -137,12 +137,8 @@
 			status = "okay";
 
 			axp209: pmic at 34 {
-				compatible = "x-powers,axp209";
 				reg = <0x34>;
 				interrupts = <0>;
-
-				interrupt-controller;
-				#interrupt-cells = <1>;
 			};
 		};
 
@@ -188,3 +184,34 @@
 		status = "okay";
 	};
 };
+
+#include "axp209.dtsi"
+
+&cpu0 {
+	cpu-supply = <&reg_dcdc2>;
+};
+
+&reg_dcdc2 {
+	regulator-always-on;
+	regulator-min-microvolt = <1000000>;
+	regulator-max-microvolt = <1450000>;
+	regulator-name = "vdd-cpu";
+};
+
+&reg_dcdc3 {
+	regulator-always-on;
+	regulator-min-microvolt = <1000000>;
+	regulator-max-microvolt = <1400000>;
+	regulator-name = "vdd-int-dll";
+};
+
+&reg_ldo1 {
+	regulator-name = "vdd-rtc";
+};
+
+&reg_ldo2 {
+	regulator-always-on;
+	regulator-min-microvolt = <3000000>;
+	regulator-max-microvolt = <3000000>;
+	regulator-name = "avcc";
+};
-- 
2.1.4

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

* Re: [PATCH v2 1/9] Input: sun4i-ts: Add thermal zone sensor support
  2015-01-09 10:17   ` Chen-Yu Tsai
@ 2015-01-09 17:23     ` Dmitry Torokhov
  -1 siblings, 0 replies; 36+ messages in thread
From: Dmitry Torokhov @ 2015-01-09 17:23 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: Maxime Ripard, Zhang Rui, Eduardo Valentin, Hans de Goede,
	linux-input, linux-arm-kernel, linux-pm

On Fri, Jan 09, 2015 at 06:17:48PM +0800, Chen-Yu Tsai wrote:
> The touchscreen controller has a temperature sensor embedded in the SoC,
> which already has hwmon support in the driver.
> 
> Add DT thermal zone support so we can use it with cpufreq for thermal
> throttling.
> 
> This also adds a comment stating that we do not know the actual formula
> for calculating the temperature.
> 
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
> ---


  CC [M]  drivers/input/touchscreen/sun4i-ts.o
drivers/input/touchscreen/sun4i-ts.c:208:15: error: variable
‘sun4i_ts_tz_ops’ has initializer but incomplete type
 static struct thermal_zone_of_device_ops sun4i_ts_tz_ops = {
               ^
drivers/input/touchscreen/sun4i-ts.c:209:2: error: unknown field
‘get_temp’ specified in initializer
  .get_temp = get_temp,
  ^
drivers/input/touchscreen/sun4i-ts.c:209:2: warning: excess elements in
struct initializer [enabled by default]
drivers/input/touchscreen/sun4i-ts.c:209:2: warning: (near
initialization for ‘sun4i_ts_tz_ops’) [enabled by default]
drivers/input/touchscreen/sun4i-ts.c: In function ‘sun4i_ts_probe’:
drivers/input/touchscreen/sun4i-ts.c:331:8: warning: passing argument 4
of ‘thermal_zone_of_sensor_register’ from incompatible pointer type
[enabled by default]
        &sun4i_ts_tz_ops);
        ^
In file included from drivers/input/touchscreen/sun4i-ts.c:37:0:
include/linux/thermal.h:302:1: note: expected ‘int (*)(void *, long int
*)’ but argument is of type ‘struct thermal_zone_of_device_ops *’
 thermal_zone_of_sensor_register(struct device *dev, int id,
 ^
drivers/input/touchscreen/sun4i-ts.c:331:8: error: too few arguments to
function ‘thermal_zone_of_sensor_register’
        &sun4i_ts_tz_ops);
        ^
In file included from drivers/input/touchscreen/sun4i-ts.c:37:0:
include/linux/thermal.h:302:1: note: declared here
 thermal_zone_of_sensor_register(struct device *dev, int id,
 ^
make[1]: *** [drivers/input/touchscreen/sun4i-ts.o] Error 1
make: *** [drivers/input/touchscreen/sun4i-ts.o] Error 2

> 
> changes since v1:
> 
>     - clean up thermal zone sensor when input device register fails
>     - unconditionally unregister thermal zone sensor on removal.
>       the unregister function checks the pointers passed in.
>     - add comment explaining the lack of documents for the temperature
>       calculation formula
> 
> ---
>  .../bindings/input/touchscreen/sun4i.txt           |  2 +
>  drivers/input/touchscreen/sun4i-ts.c               | 47 ++++++++++++++++++++++
>  2 files changed, 49 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
> index aef57791f40b..a8405bab6c00 100644
> --- a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
> +++ b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
> @@ -5,6 +5,7 @@ Required properties:
>   - compatible: "allwinner,sun4i-a10-ts"
>   - reg: mmio address range of the chip
>   - interrupts: interrupt to which the chip is connected
> + - #thermal-sensor-cells: shall be 0
>  
>  Optional properties:
>   - allwinner,ts-attached: boolean indicating that an actual touchscreen is
> @@ -17,4 +18,5 @@ Example:
>  		reg = <0x01c25000 0x100>;
>  		interrupts = <29>;
>  		allwinner,ts-attached;
> +		#thermal-sensor-cells = <0>;
>  	};
> diff --git a/drivers/input/touchscreen/sun4i-ts.c b/drivers/input/touchscreen/sun4i-ts.c
> index 28a06749ae42..aac49db0b09d 100644
> --- a/drivers/input/touchscreen/sun4i-ts.c
> +++ b/drivers/input/touchscreen/sun4i-ts.c
> @@ -34,6 +34,7 @@
>  
>  #include <linux/err.h>
>  #include <linux/hwmon.h>
> +#include <linux/thermal.h>
>  #include <linux/init.h>
>  #include <linux/input.h>
>  #include <linux/interrupt.h>
> @@ -107,6 +108,7 @@
>  struct sun4i_ts_data {
>  	struct device *dev;
>  	struct input_dev *input;
> +	struct thermal_zone_device *tz;
>  	void __iomem *base;
>  	unsigned int irq;
>  	bool ignore_fifo_data;
> @@ -180,6 +182,33 @@ static void sun4i_ts_close(struct input_dev *dev)
>  	writel(TEMP_IRQ_EN(1), ts->base + TP_INT_FIFOC);
>  }
>  
> +static int get_temp(void *data, long *temp)
> +{
> +	struct sun4i_ts_data *ts = data;
> +
> +	/* No temp_data until the first irq */
> +	if (ts->temp_data == -1)
> +		return -EAGAIN;
> +
> +	/*
> +	 * The user manuals do not contain the formula for calculating
> +	 * the temperature. The formula used here is from the AXP209,
> +	 * which is designed by X-Powers, an affiliate of Allwinner:
> +	 *
> +	 *     temperature = -144.7 + (value * 0.1)
> +	 *
> +	 * This should be replaced with the correct one if such information
> +	 * becomes available.
> +	 */
> +	*temp = (ts->temp_data - 1447) * 100;
> +
> +	return 0;
> +}
> +
> +static struct thermal_zone_of_device_ops sun4i_ts_tz_ops = {
> +	.get_temp = get_temp,
> +};
> +
>  static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
>  			 char *buf)
>  {
> @@ -189,6 +218,16 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
>  	if (ts->temp_data == -1)
>  		return -EAGAIN;
>  
> +	/*
> +	 * The user manuals do not contain the formula for calculating
> +	 * the temperature. The formula used here is from the AXP209,
> +	 * which is designed by X-Powers, an affiliate of Allwinner:
> +	 *
> +	 *     temperature = -144.7 + (value * 0.1)
> +	 *
> +	 * This should be replaced with the correct one if such information
> +	 * becomes available.
> +	 */
>  	return sprintf(buf, "%d\n", (ts->temp_data - 1447) * 100);

Why duplicate it here, instead of doing:

static int sun4i_get_temp(struct sun4i_ts_data *ts, int *temp)
{
	if (ts->temp_data == -1)
		return -EAGAIN;

	/* comment */
	*temp = (ts->temp_data - 1447) * 100);

	return 0;
}

static int sun4i_tz_get_temp(void *data, long *temp)
{
	return sun4i_get_temp(data, temp);
}

static ssize_t sun4i_show_temp(...)
{
	error = sun4i_get_temp(ts, &temp);
	if (error)
		return error;

	return sprintf(buf, "%d\n", temp);
}

Also, thermal core seems to allow creating hwmon devices for thermal
zones, can we use this feature?

Thanks.

-- 
Dmitry

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

* [PATCH v2 1/9] Input: sun4i-ts: Add thermal zone sensor support
@ 2015-01-09 17:23     ` Dmitry Torokhov
  0 siblings, 0 replies; 36+ messages in thread
From: Dmitry Torokhov @ 2015-01-09 17:23 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Jan 09, 2015 at 06:17:48PM +0800, Chen-Yu Tsai wrote:
> The touchscreen controller has a temperature sensor embedded in the SoC,
> which already has hwmon support in the driver.
> 
> Add DT thermal zone support so we can use it with cpufreq for thermal
> throttling.
> 
> This also adds a comment stating that we do not know the actual formula
> for calculating the temperature.
> 
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
> ---


  CC [M]  drivers/input/touchscreen/sun4i-ts.o
drivers/input/touchscreen/sun4i-ts.c:208:15: error: variable
?sun4i_ts_tz_ops? has initializer but incomplete type
 static struct thermal_zone_of_device_ops sun4i_ts_tz_ops = {
               ^
drivers/input/touchscreen/sun4i-ts.c:209:2: error: unknown field
?get_temp? specified in initializer
  .get_temp = get_temp,
  ^
drivers/input/touchscreen/sun4i-ts.c:209:2: warning: excess elements in
struct initializer [enabled by default]
drivers/input/touchscreen/sun4i-ts.c:209:2: warning: (near
initialization for ?sun4i_ts_tz_ops?) [enabled by default]
drivers/input/touchscreen/sun4i-ts.c: In function ?sun4i_ts_probe?:
drivers/input/touchscreen/sun4i-ts.c:331:8: warning: passing argument 4
of ?thermal_zone_of_sensor_register? from incompatible pointer type
[enabled by default]
        &sun4i_ts_tz_ops);
        ^
In file included from drivers/input/touchscreen/sun4i-ts.c:37:0:
include/linux/thermal.h:302:1: note: expected ?int (*)(void *, long int
*)? but argument is of type ?struct thermal_zone_of_device_ops *?
 thermal_zone_of_sensor_register(struct device *dev, int id,
 ^
drivers/input/touchscreen/sun4i-ts.c:331:8: error: too few arguments to
function ?thermal_zone_of_sensor_register?
        &sun4i_ts_tz_ops);
        ^
In file included from drivers/input/touchscreen/sun4i-ts.c:37:0:
include/linux/thermal.h:302:1: note: declared here
 thermal_zone_of_sensor_register(struct device *dev, int id,
 ^
make[1]: *** [drivers/input/touchscreen/sun4i-ts.o] Error 1
make: *** [drivers/input/touchscreen/sun4i-ts.o] Error 2

> 
> changes since v1:
> 
>     - clean up thermal zone sensor when input device register fails
>     - unconditionally unregister thermal zone sensor on removal.
>       the unregister function checks the pointers passed in.
>     - add comment explaining the lack of documents for the temperature
>       calculation formula
> 
> ---
>  .../bindings/input/touchscreen/sun4i.txt           |  2 +
>  drivers/input/touchscreen/sun4i-ts.c               | 47 ++++++++++++++++++++++
>  2 files changed, 49 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
> index aef57791f40b..a8405bab6c00 100644
> --- a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
> +++ b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
> @@ -5,6 +5,7 @@ Required properties:
>   - compatible: "allwinner,sun4i-a10-ts"
>   - reg: mmio address range of the chip
>   - interrupts: interrupt to which the chip is connected
> + - #thermal-sensor-cells: shall be 0
>  
>  Optional properties:
>   - allwinner,ts-attached: boolean indicating that an actual touchscreen is
> @@ -17,4 +18,5 @@ Example:
>  		reg = <0x01c25000 0x100>;
>  		interrupts = <29>;
>  		allwinner,ts-attached;
> +		#thermal-sensor-cells = <0>;
>  	};
> diff --git a/drivers/input/touchscreen/sun4i-ts.c b/drivers/input/touchscreen/sun4i-ts.c
> index 28a06749ae42..aac49db0b09d 100644
> --- a/drivers/input/touchscreen/sun4i-ts.c
> +++ b/drivers/input/touchscreen/sun4i-ts.c
> @@ -34,6 +34,7 @@
>  
>  #include <linux/err.h>
>  #include <linux/hwmon.h>
> +#include <linux/thermal.h>
>  #include <linux/init.h>
>  #include <linux/input.h>
>  #include <linux/interrupt.h>
> @@ -107,6 +108,7 @@
>  struct sun4i_ts_data {
>  	struct device *dev;
>  	struct input_dev *input;
> +	struct thermal_zone_device *tz;
>  	void __iomem *base;
>  	unsigned int irq;
>  	bool ignore_fifo_data;
> @@ -180,6 +182,33 @@ static void sun4i_ts_close(struct input_dev *dev)
>  	writel(TEMP_IRQ_EN(1), ts->base + TP_INT_FIFOC);
>  }
>  
> +static int get_temp(void *data, long *temp)
> +{
> +	struct sun4i_ts_data *ts = data;
> +
> +	/* No temp_data until the first irq */
> +	if (ts->temp_data == -1)
> +		return -EAGAIN;
> +
> +	/*
> +	 * The user manuals do not contain the formula for calculating
> +	 * the temperature. The formula used here is from the AXP209,
> +	 * which is designed by X-Powers, an affiliate of Allwinner:
> +	 *
> +	 *     temperature = -144.7 + (value * 0.1)
> +	 *
> +	 * This should be replaced with the correct one if such information
> +	 * becomes available.
> +	 */
> +	*temp = (ts->temp_data - 1447) * 100;
> +
> +	return 0;
> +}
> +
> +static struct thermal_zone_of_device_ops sun4i_ts_tz_ops = {
> +	.get_temp = get_temp,
> +};
> +
>  static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
>  			 char *buf)
>  {
> @@ -189,6 +218,16 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
>  	if (ts->temp_data == -1)
>  		return -EAGAIN;
>  
> +	/*
> +	 * The user manuals do not contain the formula for calculating
> +	 * the temperature. The formula used here is from the AXP209,
> +	 * which is designed by X-Powers, an affiliate of Allwinner:
> +	 *
> +	 *     temperature = -144.7 + (value * 0.1)
> +	 *
> +	 * This should be replaced with the correct one if such information
> +	 * becomes available.
> +	 */
>  	return sprintf(buf, "%d\n", (ts->temp_data - 1447) * 100);

Why duplicate it here, instead of doing:

static int sun4i_get_temp(struct sun4i_ts_data *ts, int *temp)
{
	if (ts->temp_data == -1)
		return -EAGAIN;

	/* comment */
	*temp = (ts->temp_data - 1447) * 100);

	return 0;
}

static int sun4i_tz_get_temp(void *data, long *temp)
{
	return sun4i_get_temp(data, temp);
}

static ssize_t sun4i_show_temp(...)
{
	error = sun4i_get_temp(ts, &temp);
	if (error)
		return error;

	return sprintf(buf, "%d\n", temp);
}

Also, thermal core seems to allow creating hwmon devices for thermal
zones, can we use this feature?

Thanks.

-- 
Dmitry

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

* Re: [PATCH v2 3/9] ARM: dts: sun7i: Add cpu thermal zones to dtsi
  2015-01-09 10:17   ` Chen-Yu Tsai
@ 2015-01-09 18:10     ` Eduardo Valentin
  -1 siblings, 0 replies; 36+ messages in thread
From: Eduardo Valentin @ 2015-01-09 18:10 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: Maxime Ripard, Dmitry Torokhov, Zhang Rui, Hans de Goede,
	linux-input, linux-arm-kernel, linux-pm

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

On Fri, Jan 09, 2015 at 06:17:50PM +0800, Chen-Yu Tsai wrote:
> The core temperature sensor now supports thermal zones. Add a thermal
> zone mapping for the cpus with passive cooling (cpufreq throttling).
> 
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>

This patch looks fine to me:

Acked-by: Eduardo Valentin <edubezval@gmail.com>

> ---
> 
> changes since v1:
> 
>     - Use thermal dt bindings macros in cooling-device
> 
> ---
>  arch/arm/boot/dts/sun7i-a20.dtsi | 33 +++++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)
> 
> diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
> index c2e964939991..61780b144745 100644
> --- a/arch/arm/boot/dts/sun7i-a20.dtsi
> +++ b/arch/arm/boot/dts/sun7i-a20.dtsi
> @@ -50,6 +50,7 @@
>  #include "skeleton.dtsi"
>  
>  #include <dt-bindings/interrupt-controller/arm-gic.h>
> +#include <dt-bindings/thermal/thermal.h>
>  
>  #include <dt-bindings/dma/sun4i-a10.h>
>  #include <dt-bindings/pinctrl/sun4i-a10.h>
> @@ -116,6 +117,38 @@
>  		};
>  	};
>  
> +	thermal-zones {
> +		cpu_thermal {
> +			/* milliseconds */
> +			polling-delay-passive = <250>;
> +			polling-delay = <1000>;
> +			thermal-sensors = <&rtp>;
> +
> +			cooling-maps {
> +				map0 {
> +					trip = <&cpu_alert0>;
> +					cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
> +				};
> +			};
> +
> +			trips {
> +				cpu_alert0: cpu_alert0 {
> +					/* milliCelsius */
> +					temperature = <75000>;
> +					hysteresis = <2000>;
> +					type = "passive";
> +				};
> +
> +				cpu_crit: cpu_crit {
> +					/* milliCelsius */
> +					temperature = <100000>;
> +					hysteresis = <2000>;
> +					type = "critical";
> +				};
> +			};
> +		};
> +	};
> +
>  	memory {
>  		reg = <0x40000000 0x80000000>;
>  	};
> -- 
> 2.1.4
> 

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

* [PATCH v2 3/9] ARM: dts: sun7i: Add cpu thermal zones to dtsi
@ 2015-01-09 18:10     ` Eduardo Valentin
  0 siblings, 0 replies; 36+ messages in thread
From: Eduardo Valentin @ 2015-01-09 18:10 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Jan 09, 2015 at 06:17:50PM +0800, Chen-Yu Tsai wrote:
> The core temperature sensor now supports thermal zones. Add a thermal
> zone mapping for the cpus with passive cooling (cpufreq throttling).
> 
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>

This patch looks fine to me:

Acked-by: Eduardo Valentin <edubezval@gmail.com>

> ---
> 
> changes since v1:
> 
>     - Use thermal dt bindings macros in cooling-device
> 
> ---
>  arch/arm/boot/dts/sun7i-a20.dtsi | 33 +++++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)
> 
> diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
> index c2e964939991..61780b144745 100644
> --- a/arch/arm/boot/dts/sun7i-a20.dtsi
> +++ b/arch/arm/boot/dts/sun7i-a20.dtsi
> @@ -50,6 +50,7 @@
>  #include "skeleton.dtsi"
>  
>  #include <dt-bindings/interrupt-controller/arm-gic.h>
> +#include <dt-bindings/thermal/thermal.h>
>  
>  #include <dt-bindings/dma/sun4i-a10.h>
>  #include <dt-bindings/pinctrl/sun4i-a10.h>
> @@ -116,6 +117,38 @@
>  		};
>  	};
>  
> +	thermal-zones {
> +		cpu_thermal {
> +			/* milliseconds */
> +			polling-delay-passive = <250>;
> +			polling-delay = <1000>;
> +			thermal-sensors = <&rtp>;
> +
> +			cooling-maps {
> +				map0 {
> +					trip = <&cpu_alert0>;
> +					cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
> +				};
> +			};
> +
> +			trips {
> +				cpu_alert0: cpu_alert0 {
> +					/* milliCelsius */
> +					temperature = <75000>;
> +					hysteresis = <2000>;
> +					type = "passive";
> +				};
> +
> +				cpu_crit: cpu_crit {
> +					/* milliCelsius */
> +					temperature = <100000>;
> +					hysteresis = <2000>;
> +					type = "critical";
> +				};
> +			};
> +		};
> +	};
> +
>  	memory {
>  		reg = <0x40000000 0x80000000>;
>  	};
> -- 
> 2.1.4
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150109/c497d679/attachment.sig>

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

* Re: [PATCH v2 6/9] ARM: dts: sun5i: Add cpu thermal zones to dtsi
  2015-01-09 10:17   ` Chen-Yu Tsai
@ 2015-01-09 18:10     ` Eduardo Valentin
  -1 siblings, 0 replies; 36+ messages in thread
From: Eduardo Valentin @ 2015-01-09 18:10 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: Maxime Ripard, Dmitry Torokhov, Zhang Rui, Hans de Goede,
	linux-input, linux-arm-kernel, linux-pm

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

On Fri, Jan 09, 2015 at 06:17:53PM +0800, Chen-Yu Tsai wrote:
> The core temperature sensor now supports thermal zones. Add a thermal
> zone mapping for the cpus with passive cooling (cpufreq throttling).
> 
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>

This patch looks fine to me:

Acked-by: Eduardo Valentin <edubezval@gmail.com>

> ---
> 
> changes since v1:
> 
>     - Use thermal dt bindings macros in cooling-device
> 
> ---
>  arch/arm/boot/dts/sun5i-a13.dtsi | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/arch/arm/boot/dts/sun5i-a13.dtsi b/arch/arm/boot/dts/sun5i-a13.dtsi
> index dee2aa5bc9ed..c26f58ea0850 100644
> --- a/arch/arm/boot/dts/sun5i-a13.dtsi
> +++ b/arch/arm/boot/dts/sun5i-a13.dtsi
> @@ -13,6 +13,8 @@
>  
>  #include "skeleton.dtsi"
>  
> +#include <dt-bindings/thermal/thermal.h>
> +
>  #include <dt-bindings/dma/sun4i-a10.h>
>  #include <dt-bindings/pinctrl/sun4i-a10.h>
>  
> @@ -50,6 +52,38 @@
>  		};
>  	};
>  
> +	thermal-zones {
> +		cpu_thermal {
> +			/* milliseconds */
> +			polling-delay-passive = <250>;
> +			polling-delay = <1000>;
> +			thermal-sensors = <&rtp>;
> +
> +			cooling-maps {
> +				map0 {
> +					trip = <&cpu_alert0>;
> +					cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
> +				};
> +			};
> +
> +			trips {
> +				cpu_alert0: cpu_alert0 {
> +					/* milliCelsius */
> +					temperature = <850000>;
> +					hysteresis = <2000>;
> +					type = "passive";
> +				};
> +
> +				cpu_crit: cpu_crit {
> +					/* milliCelsius */
> +					temperature = <100000>;
> +					hysteresis = <2000>;
> +					type = "critical";
> +				};
> +			};
> +		};
> +	};
> +
>  	memory {
>  		reg = <0x40000000 0x20000000>;
>  	};
> -- 
> 2.1.4
> 

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

* [PATCH v2 6/9] ARM: dts: sun5i: Add cpu thermal zones to dtsi
@ 2015-01-09 18:10     ` Eduardo Valentin
  0 siblings, 0 replies; 36+ messages in thread
From: Eduardo Valentin @ 2015-01-09 18:10 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Jan 09, 2015 at 06:17:53PM +0800, Chen-Yu Tsai wrote:
> The core temperature sensor now supports thermal zones. Add a thermal
> zone mapping for the cpus with passive cooling (cpufreq throttling).
> 
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>

This patch looks fine to me:

Acked-by: Eduardo Valentin <edubezval@gmail.com>

> ---
> 
> changes since v1:
> 
>     - Use thermal dt bindings macros in cooling-device
> 
> ---
>  arch/arm/boot/dts/sun5i-a13.dtsi | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/arch/arm/boot/dts/sun5i-a13.dtsi b/arch/arm/boot/dts/sun5i-a13.dtsi
> index dee2aa5bc9ed..c26f58ea0850 100644
> --- a/arch/arm/boot/dts/sun5i-a13.dtsi
> +++ b/arch/arm/boot/dts/sun5i-a13.dtsi
> @@ -13,6 +13,8 @@
>  
>  #include "skeleton.dtsi"
>  
> +#include <dt-bindings/thermal/thermal.h>
> +
>  #include <dt-bindings/dma/sun4i-a10.h>
>  #include <dt-bindings/pinctrl/sun4i-a10.h>
>  
> @@ -50,6 +52,38 @@
>  		};
>  	};
>  
> +	thermal-zones {
> +		cpu_thermal {
> +			/* milliseconds */
> +			polling-delay-passive = <250>;
> +			polling-delay = <1000>;
> +			thermal-sensors = <&rtp>;
> +
> +			cooling-maps {
> +				map0 {
> +					trip = <&cpu_alert0>;
> +					cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
> +				};
> +			};
> +
> +			trips {
> +				cpu_alert0: cpu_alert0 {
> +					/* milliCelsius */
> +					temperature = <850000>;
> +					hysteresis = <2000>;
> +					type = "passive";
> +				};
> +
> +				cpu_crit: cpu_crit {
> +					/* milliCelsius */
> +					temperature = <100000>;
> +					hysteresis = <2000>;
> +					type = "critical";
> +				};
> +			};
> +		};
> +	};
> +
>  	memory {
>  		reg = <0x40000000 0x20000000>;
>  	};
> -- 
> 2.1.4
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150109/0b6ad1ff/attachment.sig>

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

* Re: [PATCH v2 6/9] ARM: dts: sun5i: Add cpu thermal zones to dtsi
  2015-01-09 10:17   ` Chen-Yu Tsai
@ 2015-01-09 18:11     ` Eduardo Valentin
  -1 siblings, 0 replies; 36+ messages in thread
From: Eduardo Valentin @ 2015-01-09 18:11 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: linux-pm, Dmitry Torokhov, Hans de Goede, linux-input,
	Maxime Ripard, Zhang Rui, linux-arm-kernel


[-- Attachment #1.1: Type: text/plain, Size: 1819 bytes --]

On Fri, Jan 09, 2015 at 06:17:53PM +0800, Chen-Yu Tsai wrote:
> The core temperature sensor now supports thermal zones. Add a thermal
> zone mapping for the cpus with passive cooling (cpufreq throttling).
> 
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>


This patch looks fine to me:

Acked-by: Eduardo Valentin <edubezval@gmail.com>

> ---
> 
> changes since v1:
> 
>     - Use thermal dt bindings macros in cooling-device
> 
> ---
>  arch/arm/boot/dts/sun5i-a13.dtsi | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/arch/arm/boot/dts/sun5i-a13.dtsi b/arch/arm/boot/dts/sun5i-a13.dtsi
> index dee2aa5bc9ed..c26f58ea0850 100644
> --- a/arch/arm/boot/dts/sun5i-a13.dtsi
> +++ b/arch/arm/boot/dts/sun5i-a13.dtsi
> @@ -13,6 +13,8 @@
>  
>  #include "skeleton.dtsi"
>  
> +#include <dt-bindings/thermal/thermal.h>
> +
>  #include <dt-bindings/dma/sun4i-a10.h>
>  #include <dt-bindings/pinctrl/sun4i-a10.h>
>  
> @@ -50,6 +52,38 @@
>  		};
>  	};
>  
> +	thermal-zones {
> +		cpu_thermal {
> +			/* milliseconds */
> +			polling-delay-passive = <250>;
> +			polling-delay = <1000>;
> +			thermal-sensors = <&rtp>;
> +
> +			cooling-maps {
> +				map0 {
> +					trip = <&cpu_alert0>;
> +					cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
> +				};
> +			};
> +
> +			trips {
> +				cpu_alert0: cpu_alert0 {
> +					/* milliCelsius */
> +					temperature = <850000>;
> +					hysteresis = <2000>;
> +					type = "passive";
> +				};
> +
> +				cpu_crit: cpu_crit {
> +					/* milliCelsius */
> +					temperature = <100000>;
> +					hysteresis = <2000>;
> +					type = "critical";
> +				};
> +			};
> +		};
> +	};
> +
>  	memory {
>  		reg = <0x40000000 0x20000000>;
>  	};
> -- 
> 2.1.4
> 

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 6/9] ARM: dts: sun5i: Add cpu thermal zones to dtsi
@ 2015-01-09 18:11     ` Eduardo Valentin
  0 siblings, 0 replies; 36+ messages in thread
From: Eduardo Valentin @ 2015-01-09 18:11 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Jan 09, 2015 at 06:17:53PM +0800, Chen-Yu Tsai wrote:
> The core temperature sensor now supports thermal zones. Add a thermal
> zone mapping for the cpus with passive cooling (cpufreq throttling).
> 
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>


This patch looks fine to me:

Acked-by: Eduardo Valentin <edubezval@gmail.com>

> ---
> 
> changes since v1:
> 
>     - Use thermal dt bindings macros in cooling-device
> 
> ---
>  arch/arm/boot/dts/sun5i-a13.dtsi | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/arch/arm/boot/dts/sun5i-a13.dtsi b/arch/arm/boot/dts/sun5i-a13.dtsi
> index dee2aa5bc9ed..c26f58ea0850 100644
> --- a/arch/arm/boot/dts/sun5i-a13.dtsi
> +++ b/arch/arm/boot/dts/sun5i-a13.dtsi
> @@ -13,6 +13,8 @@
>  
>  #include "skeleton.dtsi"
>  
> +#include <dt-bindings/thermal/thermal.h>
> +
>  #include <dt-bindings/dma/sun4i-a10.h>
>  #include <dt-bindings/pinctrl/sun4i-a10.h>
>  
> @@ -50,6 +52,38 @@
>  		};
>  	};
>  
> +	thermal-zones {
> +		cpu_thermal {
> +			/* milliseconds */
> +			polling-delay-passive = <250>;
> +			polling-delay = <1000>;
> +			thermal-sensors = <&rtp>;
> +
> +			cooling-maps {
> +				map0 {
> +					trip = <&cpu_alert0>;
> +					cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
> +				};
> +			};
> +
> +			trips {
> +				cpu_alert0: cpu_alert0 {
> +					/* milliCelsius */
> +					temperature = <850000>;
> +					hysteresis = <2000>;
> +					type = "passive";
> +				};
> +
> +				cpu_crit: cpu_crit {
> +					/* milliCelsius */
> +					temperature = <100000>;
> +					hysteresis = <2000>;
> +					type = "critical";
> +				};
> +			};
> +		};
> +	};
> +
>  	memory {
>  		reg = <0x40000000 0x20000000>;
>  	};
> -- 
> 2.1.4
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150109/a571101e/attachment.sig>

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

* Re: [PATCH v2 1/9] Input: sun4i-ts: Add thermal zone sensor support
  2015-01-09 17:23     ` Dmitry Torokhov
@ 2015-01-09 18:28       ` Chen-Yu Tsai
  -1 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-09 18:28 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Maxime Ripard, Zhang Rui, Eduardo Valentin, Hans de Goede,
	linux-input, linux-arm-kernel, linux-pm

On Sat, Jan 10, 2015 at 1:23 AM, Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> On Fri, Jan 09, 2015 at 06:17:48PM +0800, Chen-Yu Tsai wrote:
>> The touchscreen controller has a temperature sensor embedded in the SoC,
>> which already has hwmon support in the driver.
>>
>> Add DT thermal zone support so we can use it with cpufreq for thermal
>> throttling.
>>
>> This also adds a comment stating that we do not know the actual formula
>> for calculating the temperature.
>>
>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
>> ---
>
>
>   CC [M]  drivers/input/touchscreen/sun4i-ts.o
> drivers/input/touchscreen/sun4i-ts.c:208:15: error: variable
> ‘sun4i_ts_tz_ops’ has initializer but incomplete type
>  static struct thermal_zone_of_device_ops sun4i_ts_tz_ops = {
>                ^
> drivers/input/touchscreen/sun4i-ts.c:209:2: error: unknown field
> ‘get_temp’ specified in initializer
>   .get_temp = get_temp,
>   ^
> drivers/input/touchscreen/sun4i-ts.c:209:2: warning: excess elements in
> struct initializer [enabled by default]
> drivers/input/touchscreen/sun4i-ts.c:209:2: warning: (near
> initialization for ‘sun4i_ts_tz_ops’) [enabled by default]
> drivers/input/touchscreen/sun4i-ts.c: In function ‘sun4i_ts_probe’:
> drivers/input/touchscreen/sun4i-ts.c:331:8: warning: passing argument 4
> of ‘thermal_zone_of_sensor_register’ from incompatible pointer type
> [enabled by default]
>         &sun4i_ts_tz_ops);
>         ^
> In file included from drivers/input/touchscreen/sun4i-ts.c:37:0:
> include/linux/thermal.h:302:1: note: expected ‘int (*)(void *, long int
> *)’ but argument is of type ‘struct thermal_zone_of_device_ops *’
>  thermal_zone_of_sensor_register(struct device *dev, int id,
>  ^
> drivers/input/touchscreen/sun4i-ts.c:331:8: error: too few arguments to
> function ‘thermal_zone_of_sensor_register’
>         &sun4i_ts_tz_ops);
>         ^
> In file included from drivers/input/touchscreen/sun4i-ts.c:37:0:
> include/linux/thermal.h:302:1: note: declared here
>  thermal_zone_of_sensor_register(struct device *dev, int id,
>  ^
> make[1]: *** [drivers/input/touchscreen/sun4i-ts.o] Error 1
> make: *** [drivers/input/touchscreen/sun4i-ts.o] Error 2
>

struct thermal_zone_of_device_ops was introduced in 3.19-rc1 in

    184a4bf623fa thermal: of: Extend current of-thermal.c code to
allow setting emulated temp

>>
>> changes since v1:
>>
>>     - clean up thermal zone sensor when input device register fails
>>     - unconditionally unregister thermal zone sensor on removal.
>>       the unregister function checks the pointers passed in.
>>     - add comment explaining the lack of documents for the temperature
>>       calculation formula
>>
>> ---
>>  .../bindings/input/touchscreen/sun4i.txt           |  2 +
>>  drivers/input/touchscreen/sun4i-ts.c               | 47 ++++++++++++++++++++++
>>  2 files changed, 49 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
>> index aef57791f40b..a8405bab6c00 100644
>> --- a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
>> +++ b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
>> @@ -5,6 +5,7 @@ Required properties:
>>   - compatible: "allwinner,sun4i-a10-ts"
>>   - reg: mmio address range of the chip
>>   - interrupts: interrupt to which the chip is connected
>> + - #thermal-sensor-cells: shall be 0
>>
>>  Optional properties:
>>   - allwinner,ts-attached: boolean indicating that an actual touchscreen is
>> @@ -17,4 +18,5 @@ Example:
>>               reg = <0x01c25000 0x100>;
>>               interrupts = <29>;
>>               allwinner,ts-attached;
>> +             #thermal-sensor-cells = <0>;
>>       };
>> diff --git a/drivers/input/touchscreen/sun4i-ts.c b/drivers/input/touchscreen/sun4i-ts.c
>> index 28a06749ae42..aac49db0b09d 100644
>> --- a/drivers/input/touchscreen/sun4i-ts.c
>> +++ b/drivers/input/touchscreen/sun4i-ts.c
>> @@ -34,6 +34,7 @@
>>
>>  #include <linux/err.h>
>>  #include <linux/hwmon.h>
>> +#include <linux/thermal.h>
>>  #include <linux/init.h>
>>  #include <linux/input.h>
>>  #include <linux/interrupt.h>
>> @@ -107,6 +108,7 @@
>>  struct sun4i_ts_data {
>>       struct device *dev;
>>       struct input_dev *input;
>> +     struct thermal_zone_device *tz;
>>       void __iomem *base;
>>       unsigned int irq;
>>       bool ignore_fifo_data;
>> @@ -180,6 +182,33 @@ static void sun4i_ts_close(struct input_dev *dev)
>>       writel(TEMP_IRQ_EN(1), ts->base + TP_INT_FIFOC);
>>  }
>>
>> +static int get_temp(void *data, long *temp)
>> +{
>> +     struct sun4i_ts_data *ts = data;
>> +
>> +     /* No temp_data until the first irq */
>> +     if (ts->temp_data == -1)
>> +             return -EAGAIN;
>> +
>> +     /*
>> +      * The user manuals do not contain the formula for calculating
>> +      * the temperature. The formula used here is from the AXP209,
>> +      * which is designed by X-Powers, an affiliate of Allwinner:
>> +      *
>> +      *     temperature = -144.7 + (value * 0.1)
>> +      *
>> +      * This should be replaced with the correct one if such information
>> +      * becomes available.
>> +      */
>> +     *temp = (ts->temp_data - 1447) * 100;
>> +
>> +     return 0;
>> +}
>> +
>> +static struct thermal_zone_of_device_ops sun4i_ts_tz_ops = {
>> +     .get_temp = get_temp,
>> +};
>> +
>>  static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
>>                        char *buf)
>>  {
>> @@ -189,6 +218,16 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
>>       if (ts->temp_data == -1)
>>               return -EAGAIN;
>>
>> +     /*
>> +      * The user manuals do not contain the formula for calculating
>> +      * the temperature. The formula used here is from the AXP209,
>> +      * which is designed by X-Powers, an affiliate of Allwinner:
>> +      *
>> +      *     temperature = -144.7 + (value * 0.1)
>> +      *
>> +      * This should be replaced with the correct one if such information
>> +      * becomes available.
>> +      */
>>       return sprintf(buf, "%d\n", (ts->temp_data - 1447) * 100);
>
> Why duplicate it here, instead of doing:
>
> static int sun4i_get_temp(struct sun4i_ts_data *ts, int *temp)
> {
>         if (ts->temp_data == -1)
>                 return -EAGAIN;
>
>         /* comment */
>         *temp = (ts->temp_data - 1447) * 100);
>
>         return 0;
> }
>
> static int sun4i_tz_get_temp(void *data, long *temp)
> {
>         return sun4i_get_temp(data, temp);
> }
>
> static ssize_t sun4i_show_temp(...)
> {
>         error = sun4i_get_temp(ts, &temp);
>         if (error)
>                 return error;
>
>         return sprintf(buf, "%d\n", temp);
> }

I suppose that would be better, especially after I added the large comment.

> Also, thermal core seems to allow creating hwmon devices for thermal
> zones, can we use this feature?

For thermal sensors that also have hwmon devices registered, that step is
skipped.

I sort of like having separate hwmon bits, just for a nicer, more informative
label. But I am not opposed to removing the bits from the driver and having
it go through the thermal core. We could also remove the build dependency
on HWMON as a result.

If you prefer this, I will do so in v3.


Thanks
ChenYu

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

* [PATCH v2 1/9] Input: sun4i-ts: Add thermal zone sensor support
@ 2015-01-09 18:28       ` Chen-Yu Tsai
  0 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-09 18:28 UTC (permalink / raw)
  To: linux-arm-kernel

On Sat, Jan 10, 2015 at 1:23 AM, Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> On Fri, Jan 09, 2015 at 06:17:48PM +0800, Chen-Yu Tsai wrote:
>> The touchscreen controller has a temperature sensor embedded in the SoC,
>> which already has hwmon support in the driver.
>>
>> Add DT thermal zone support so we can use it with cpufreq for thermal
>> throttling.
>>
>> This also adds a comment stating that we do not know the actual formula
>> for calculating the temperature.
>>
>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
>> ---
>
>
>   CC [M]  drivers/input/touchscreen/sun4i-ts.o
> drivers/input/touchscreen/sun4i-ts.c:208:15: error: variable
> ?sun4i_ts_tz_ops? has initializer but incomplete type
>  static struct thermal_zone_of_device_ops sun4i_ts_tz_ops = {
>                ^
> drivers/input/touchscreen/sun4i-ts.c:209:2: error: unknown field
> ?get_temp? specified in initializer
>   .get_temp = get_temp,
>   ^
> drivers/input/touchscreen/sun4i-ts.c:209:2: warning: excess elements in
> struct initializer [enabled by default]
> drivers/input/touchscreen/sun4i-ts.c:209:2: warning: (near
> initialization for ?sun4i_ts_tz_ops?) [enabled by default]
> drivers/input/touchscreen/sun4i-ts.c: In function ?sun4i_ts_probe?:
> drivers/input/touchscreen/sun4i-ts.c:331:8: warning: passing argument 4
> of ?thermal_zone_of_sensor_register? from incompatible pointer type
> [enabled by default]
>         &sun4i_ts_tz_ops);
>         ^
> In file included from drivers/input/touchscreen/sun4i-ts.c:37:0:
> include/linux/thermal.h:302:1: note: expected ?int (*)(void *, long int
> *)? but argument is of type ?struct thermal_zone_of_device_ops *?
>  thermal_zone_of_sensor_register(struct device *dev, int id,
>  ^
> drivers/input/touchscreen/sun4i-ts.c:331:8: error: too few arguments to
> function ?thermal_zone_of_sensor_register?
>         &sun4i_ts_tz_ops);
>         ^
> In file included from drivers/input/touchscreen/sun4i-ts.c:37:0:
> include/linux/thermal.h:302:1: note: declared here
>  thermal_zone_of_sensor_register(struct device *dev, int id,
>  ^
> make[1]: *** [drivers/input/touchscreen/sun4i-ts.o] Error 1
> make: *** [drivers/input/touchscreen/sun4i-ts.o] Error 2
>

struct thermal_zone_of_device_ops was introduced in 3.19-rc1 in

    184a4bf623fa thermal: of: Extend current of-thermal.c code to
allow setting emulated temp

>>
>> changes since v1:
>>
>>     - clean up thermal zone sensor when input device register fails
>>     - unconditionally unregister thermal zone sensor on removal.
>>       the unregister function checks the pointers passed in.
>>     - add comment explaining the lack of documents for the temperature
>>       calculation formula
>>
>> ---
>>  .../bindings/input/touchscreen/sun4i.txt           |  2 +
>>  drivers/input/touchscreen/sun4i-ts.c               | 47 ++++++++++++++++++++++
>>  2 files changed, 49 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
>> index aef57791f40b..a8405bab6c00 100644
>> --- a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
>> +++ b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
>> @@ -5,6 +5,7 @@ Required properties:
>>   - compatible: "allwinner,sun4i-a10-ts"
>>   - reg: mmio address range of the chip
>>   - interrupts: interrupt to which the chip is connected
>> + - #thermal-sensor-cells: shall be 0
>>
>>  Optional properties:
>>   - allwinner,ts-attached: boolean indicating that an actual touchscreen is
>> @@ -17,4 +18,5 @@ Example:
>>               reg = <0x01c25000 0x100>;
>>               interrupts = <29>;
>>               allwinner,ts-attached;
>> +             #thermal-sensor-cells = <0>;
>>       };
>> diff --git a/drivers/input/touchscreen/sun4i-ts.c b/drivers/input/touchscreen/sun4i-ts.c
>> index 28a06749ae42..aac49db0b09d 100644
>> --- a/drivers/input/touchscreen/sun4i-ts.c
>> +++ b/drivers/input/touchscreen/sun4i-ts.c
>> @@ -34,6 +34,7 @@
>>
>>  #include <linux/err.h>
>>  #include <linux/hwmon.h>
>> +#include <linux/thermal.h>
>>  #include <linux/init.h>
>>  #include <linux/input.h>
>>  #include <linux/interrupt.h>
>> @@ -107,6 +108,7 @@
>>  struct sun4i_ts_data {
>>       struct device *dev;
>>       struct input_dev *input;
>> +     struct thermal_zone_device *tz;
>>       void __iomem *base;
>>       unsigned int irq;
>>       bool ignore_fifo_data;
>> @@ -180,6 +182,33 @@ static void sun4i_ts_close(struct input_dev *dev)
>>       writel(TEMP_IRQ_EN(1), ts->base + TP_INT_FIFOC);
>>  }
>>
>> +static int get_temp(void *data, long *temp)
>> +{
>> +     struct sun4i_ts_data *ts = data;
>> +
>> +     /* No temp_data until the first irq */
>> +     if (ts->temp_data == -1)
>> +             return -EAGAIN;
>> +
>> +     /*
>> +      * The user manuals do not contain the formula for calculating
>> +      * the temperature. The formula used here is from the AXP209,
>> +      * which is designed by X-Powers, an affiliate of Allwinner:
>> +      *
>> +      *     temperature = -144.7 + (value * 0.1)
>> +      *
>> +      * This should be replaced with the correct one if such information
>> +      * becomes available.
>> +      */
>> +     *temp = (ts->temp_data - 1447) * 100;
>> +
>> +     return 0;
>> +}
>> +
>> +static struct thermal_zone_of_device_ops sun4i_ts_tz_ops = {
>> +     .get_temp = get_temp,
>> +};
>> +
>>  static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
>>                        char *buf)
>>  {
>> @@ -189,6 +218,16 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
>>       if (ts->temp_data == -1)
>>               return -EAGAIN;
>>
>> +     /*
>> +      * The user manuals do not contain the formula for calculating
>> +      * the temperature. The formula used here is from the AXP209,
>> +      * which is designed by X-Powers, an affiliate of Allwinner:
>> +      *
>> +      *     temperature = -144.7 + (value * 0.1)
>> +      *
>> +      * This should be replaced with the correct one if such information
>> +      * becomes available.
>> +      */
>>       return sprintf(buf, "%d\n", (ts->temp_data - 1447) * 100);
>
> Why duplicate it here, instead of doing:
>
> static int sun4i_get_temp(struct sun4i_ts_data *ts, int *temp)
> {
>         if (ts->temp_data == -1)
>                 return -EAGAIN;
>
>         /* comment */
>         *temp = (ts->temp_data - 1447) * 100);
>
>         return 0;
> }
>
> static int sun4i_tz_get_temp(void *data, long *temp)
> {
>         return sun4i_get_temp(data, temp);
> }
>
> static ssize_t sun4i_show_temp(...)
> {
>         error = sun4i_get_temp(ts, &temp);
>         if (error)
>                 return error;
>
>         return sprintf(buf, "%d\n", temp);
> }

I suppose that would be better, especially after I added the large comment.

> Also, thermal core seems to allow creating hwmon devices for thermal
> zones, can we use this feature?

For thermal sensors that also have hwmon devices registered, that step is
skipped.

I sort of like having separate hwmon bits, just for a nicer, more informative
label. But I am not opposed to removing the bits from the driver and having
it go through the thermal core. We could also remove the build dependency
on HWMON as a result.

If you prefer this, I will do so in v3.


Thanks
ChenYu

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

* Re: [PATCH v2 1/9] Input: sun4i-ts: Add thermal zone sensor support
  2015-01-09 17:23     ` Dmitry Torokhov
@ 2015-01-09 18:33       ` Eduardo Valentin
  -1 siblings, 0 replies; 36+ messages in thread
From: Eduardo Valentin @ 2015-01-09 18:33 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Chen-Yu Tsai, Maxime Ripard, Zhang Rui, Hans de Goede,
	linux-input, linux-arm-kernel, linux-pm

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

Dmitry,

On Fri, Jan 09, 2015 at 09:23:18AM -0800, Dmitry Torokhov wrote:
> On Fri, Jan 09, 2015 at 06:17:48PM +0800, Chen-Yu Tsai wrote:
> > The touchscreen controller has a temperature sensor embedded in the SoC,
> > which already has hwmon support in the driver.
> > 
> > Add DT thermal zone support so we can use it with cpufreq for thermal
> > throttling.
> > 
> > This also adds a comment stating that we do not know the actual formula
> > for calculating the temperature.
> > 
> > Signed-off-by: Chen-Yu Tsai <wens@csie.org>
> > ---
> 
> 
>   CC [M]  drivers/input/touchscreen/sun4i-ts.o
> drivers/input/touchscreen/sun4i-ts.c:208:15: error: variable
> ‘sun4i_ts_tz_ops’ has initializer but incomplete type
>  static struct thermal_zone_of_device_ops sun4i_ts_tz_ops = {
>                ^
> drivers/input/touchscreen/sun4i-ts.c:209:2: error: unknown field
> ‘get_temp’ specified in initializer
>   .get_temp = get_temp,
>   ^
> drivers/input/touchscreen/sun4i-ts.c:209:2: warning: excess elements in
> struct initializer [enabled by default]
> drivers/input/touchscreen/sun4i-ts.c:209:2: warning: (near
> initialization for ‘sun4i_ts_tz_ops’) [enabled by default]
> drivers/input/touchscreen/sun4i-ts.c: In function ‘sun4i_ts_probe’:
> drivers/input/touchscreen/sun4i-ts.c:331:8: warning: passing argument 4
> of ‘thermal_zone_of_sensor_register’ from incompatible pointer type
> [enabled by default]
>         &sun4i_ts_tz_ops);
>         ^
> In file included from drivers/input/touchscreen/sun4i-ts.c:37:0:
> include/linux/thermal.h:302:1: note: expected ‘int (*)(void *, long int
> *)’ but argument is of type ‘struct thermal_zone_of_device_ops *’
>  thermal_zone_of_sensor_register(struct device *dev, int id,
>  ^
> drivers/input/touchscreen/sun4i-ts.c:331:8: error: too few arguments to
> function ‘thermal_zone_of_sensor_register’
>         &sun4i_ts_tz_ops);
>         ^
> In file included from drivers/input/touchscreen/sun4i-ts.c:37:0:
> include/linux/thermal.h:302:1: note: declared here
>  thermal_zone_of_sensor_register(struct device *dev, int id,
>  ^
> make[1]: *** [drivers/input/touchscreen/sun4i-ts.o] Error 1
> make: *** [drivers/input/touchscreen/sun4i-ts.o] Error 2
> 

What kernel version are you using?

It looks like you are missing the of thermal ops commit.


> > 
> > changes since v1:
> > 
> >     - clean up thermal zone sensor when input device register fails
> >     - unconditionally unregister thermal zone sensor on removal.
> >       the unregister function checks the pointers passed in.
> >     - add comment explaining the lack of documents for the temperature
> >       calculation formula
> > 
> > ---
> >  .../bindings/input/touchscreen/sun4i.txt           |  2 +
> >  drivers/input/touchscreen/sun4i-ts.c               | 47 ++++++++++++++++++++++
> >  2 files changed, 49 insertions(+)
> > 
> > diff --git a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
> > index aef57791f40b..a8405bab6c00 100644
> > --- a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
> > +++ b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
> > @@ -5,6 +5,7 @@ Required properties:
> >   - compatible: "allwinner,sun4i-a10-ts"
> >   - reg: mmio address range of the chip
> >   - interrupts: interrupt to which the chip is connected
> > + - #thermal-sensor-cells: shall be 0
> >  
> >  Optional properties:
> >   - allwinner,ts-attached: boolean indicating that an actual touchscreen is
> > @@ -17,4 +18,5 @@ Example:
> >  		reg = <0x01c25000 0x100>;
> >  		interrupts = <29>;
> >  		allwinner,ts-attached;
> > +		#thermal-sensor-cells = <0>;
> >  	};
> > diff --git a/drivers/input/touchscreen/sun4i-ts.c b/drivers/input/touchscreen/sun4i-ts.c
> > index 28a06749ae42..aac49db0b09d 100644
> > --- a/drivers/input/touchscreen/sun4i-ts.c
> > +++ b/drivers/input/touchscreen/sun4i-ts.c
> > @@ -34,6 +34,7 @@
> >  
> >  #include <linux/err.h>
> >  #include <linux/hwmon.h>
> > +#include <linux/thermal.h>
> >  #include <linux/init.h>
> >  #include <linux/input.h>
> >  #include <linux/interrupt.h>
> > @@ -107,6 +108,7 @@
> >  struct sun4i_ts_data {
> >  	struct device *dev;
> >  	struct input_dev *input;
> > +	struct thermal_zone_device *tz;
> >  	void __iomem *base;
> >  	unsigned int irq;
> >  	bool ignore_fifo_data;
> > @@ -180,6 +182,33 @@ static void sun4i_ts_close(struct input_dev *dev)
> >  	writel(TEMP_IRQ_EN(1), ts->base + TP_INT_FIFOC);
> >  }
> >  
> > +static int get_temp(void *data, long *temp)
> > +{
> > +	struct sun4i_ts_data *ts = data;
> > +
> > +	/* No temp_data until the first irq */
> > +	if (ts->temp_data == -1)
> > +		return -EAGAIN;
> > +
> > +	/*
> > +	 * The user manuals do not contain the formula for calculating
> > +	 * the temperature. The formula used here is from the AXP209,
> > +	 * which is designed by X-Powers, an affiliate of Allwinner:
> > +	 *
> > +	 *     temperature = -144.7 + (value * 0.1)
> > +	 *
> > +	 * This should be replaced with the correct one if such information
> > +	 * becomes available.
> > +	 */
> > +	*temp = (ts->temp_data - 1447) * 100;
> > +
> > +	return 0;
> > +}
> > +
> > +static struct thermal_zone_of_device_ops sun4i_ts_tz_ops = {
> > +	.get_temp = get_temp,
> > +};
> > +
> >  static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
> >  			 char *buf)
> >  {
> > @@ -189,6 +218,16 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
> >  	if (ts->temp_data == -1)
> >  		return -EAGAIN;
> >  
> > +	/*
> > +	 * The user manuals do not contain the formula for calculating
> > +	 * the temperature. The formula used here is from the AXP209,
> > +	 * which is designed by X-Powers, an affiliate of Allwinner:
> > +	 *
> > +	 *     temperature = -144.7 + (value * 0.1)
> > +	 *
> > +	 * This should be replaced with the correct one if such information
> > +	 * becomes available.
> > +	 */
> >  	return sprintf(buf, "%d\n", (ts->temp_data - 1447) * 100);
> 
> Why duplicate it here, instead of doing:
> 
> static int sun4i_get_temp(struct sun4i_ts_data *ts, int *temp)
> {
> 	if (ts->temp_data == -1)
> 		return -EAGAIN;
> 
> 	/* comment */
> 	*temp = (ts->temp_data - 1447) * 100);
> 
> 	return 0;
> }
> 
> static int sun4i_tz_get_temp(void *data, long *temp)
> {
> 	return sun4i_get_temp(data, temp);
> }
> 
> static ssize_t sun4i_show_temp(...)
> {
> 	error = sun4i_get_temp(ts, &temp);
> 	if (error)
> 		return error;
> 
> 	return sprintf(buf, "%d\n", temp);
> }
> 
> Also, thermal core seems to allow creating hwmon devices for thermal
> zones, can we use this feature?
> 
> Thanks.
> 
> -- 
> Dmitry

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

* [PATCH v2 1/9] Input: sun4i-ts: Add thermal zone sensor support
@ 2015-01-09 18:33       ` Eduardo Valentin
  0 siblings, 0 replies; 36+ messages in thread
From: Eduardo Valentin @ 2015-01-09 18:33 UTC (permalink / raw)
  To: linux-arm-kernel

Dmitry,

On Fri, Jan 09, 2015 at 09:23:18AM -0800, Dmitry Torokhov wrote:
> On Fri, Jan 09, 2015 at 06:17:48PM +0800, Chen-Yu Tsai wrote:
> > The touchscreen controller has a temperature sensor embedded in the SoC,
> > which already has hwmon support in the driver.
> > 
> > Add DT thermal zone support so we can use it with cpufreq for thermal
> > throttling.
> > 
> > This also adds a comment stating that we do not know the actual formula
> > for calculating the temperature.
> > 
> > Signed-off-by: Chen-Yu Tsai <wens@csie.org>
> > ---
> 
> 
>   CC [M]  drivers/input/touchscreen/sun4i-ts.o
> drivers/input/touchscreen/sun4i-ts.c:208:15: error: variable
> ?sun4i_ts_tz_ops? has initializer but incomplete type
>  static struct thermal_zone_of_device_ops sun4i_ts_tz_ops = {
>                ^
> drivers/input/touchscreen/sun4i-ts.c:209:2: error: unknown field
> ?get_temp? specified in initializer
>   .get_temp = get_temp,
>   ^
> drivers/input/touchscreen/sun4i-ts.c:209:2: warning: excess elements in
> struct initializer [enabled by default]
> drivers/input/touchscreen/sun4i-ts.c:209:2: warning: (near
> initialization for ?sun4i_ts_tz_ops?) [enabled by default]
> drivers/input/touchscreen/sun4i-ts.c: In function ?sun4i_ts_probe?:
> drivers/input/touchscreen/sun4i-ts.c:331:8: warning: passing argument 4
> of ?thermal_zone_of_sensor_register? from incompatible pointer type
> [enabled by default]
>         &sun4i_ts_tz_ops);
>         ^
> In file included from drivers/input/touchscreen/sun4i-ts.c:37:0:
> include/linux/thermal.h:302:1: note: expected ?int (*)(void *, long int
> *)? but argument is of type ?struct thermal_zone_of_device_ops *?
>  thermal_zone_of_sensor_register(struct device *dev, int id,
>  ^
> drivers/input/touchscreen/sun4i-ts.c:331:8: error: too few arguments to
> function ?thermal_zone_of_sensor_register?
>         &sun4i_ts_tz_ops);
>         ^
> In file included from drivers/input/touchscreen/sun4i-ts.c:37:0:
> include/linux/thermal.h:302:1: note: declared here
>  thermal_zone_of_sensor_register(struct device *dev, int id,
>  ^
> make[1]: *** [drivers/input/touchscreen/sun4i-ts.o] Error 1
> make: *** [drivers/input/touchscreen/sun4i-ts.o] Error 2
> 

What kernel version are you using?

It looks like you are missing the of thermal ops commit.


> > 
> > changes since v1:
> > 
> >     - clean up thermal zone sensor when input device register fails
> >     - unconditionally unregister thermal zone sensor on removal.
> >       the unregister function checks the pointers passed in.
> >     - add comment explaining the lack of documents for the temperature
> >       calculation formula
> > 
> > ---
> >  .../bindings/input/touchscreen/sun4i.txt           |  2 +
> >  drivers/input/touchscreen/sun4i-ts.c               | 47 ++++++++++++++++++++++
> >  2 files changed, 49 insertions(+)
> > 
> > diff --git a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
> > index aef57791f40b..a8405bab6c00 100644
> > --- a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
> > +++ b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
> > @@ -5,6 +5,7 @@ Required properties:
> >   - compatible: "allwinner,sun4i-a10-ts"
> >   - reg: mmio address range of the chip
> >   - interrupts: interrupt to which the chip is connected
> > + - #thermal-sensor-cells: shall be 0
> >  
> >  Optional properties:
> >   - allwinner,ts-attached: boolean indicating that an actual touchscreen is
> > @@ -17,4 +18,5 @@ Example:
> >  		reg = <0x01c25000 0x100>;
> >  		interrupts = <29>;
> >  		allwinner,ts-attached;
> > +		#thermal-sensor-cells = <0>;
> >  	};
> > diff --git a/drivers/input/touchscreen/sun4i-ts.c b/drivers/input/touchscreen/sun4i-ts.c
> > index 28a06749ae42..aac49db0b09d 100644
> > --- a/drivers/input/touchscreen/sun4i-ts.c
> > +++ b/drivers/input/touchscreen/sun4i-ts.c
> > @@ -34,6 +34,7 @@
> >  
> >  #include <linux/err.h>
> >  #include <linux/hwmon.h>
> > +#include <linux/thermal.h>
> >  #include <linux/init.h>
> >  #include <linux/input.h>
> >  #include <linux/interrupt.h>
> > @@ -107,6 +108,7 @@
> >  struct sun4i_ts_data {
> >  	struct device *dev;
> >  	struct input_dev *input;
> > +	struct thermal_zone_device *tz;
> >  	void __iomem *base;
> >  	unsigned int irq;
> >  	bool ignore_fifo_data;
> > @@ -180,6 +182,33 @@ static void sun4i_ts_close(struct input_dev *dev)
> >  	writel(TEMP_IRQ_EN(1), ts->base + TP_INT_FIFOC);
> >  }
> >  
> > +static int get_temp(void *data, long *temp)
> > +{
> > +	struct sun4i_ts_data *ts = data;
> > +
> > +	/* No temp_data until the first irq */
> > +	if (ts->temp_data == -1)
> > +		return -EAGAIN;
> > +
> > +	/*
> > +	 * The user manuals do not contain the formula for calculating
> > +	 * the temperature. The formula used here is from the AXP209,
> > +	 * which is designed by X-Powers, an affiliate of Allwinner:
> > +	 *
> > +	 *     temperature = -144.7 + (value * 0.1)
> > +	 *
> > +	 * This should be replaced with the correct one if such information
> > +	 * becomes available.
> > +	 */
> > +	*temp = (ts->temp_data - 1447) * 100;
> > +
> > +	return 0;
> > +}
> > +
> > +static struct thermal_zone_of_device_ops sun4i_ts_tz_ops = {
> > +	.get_temp = get_temp,
> > +};
> > +
> >  static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
> >  			 char *buf)
> >  {
> > @@ -189,6 +218,16 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
> >  	if (ts->temp_data == -1)
> >  		return -EAGAIN;
> >  
> > +	/*
> > +	 * The user manuals do not contain the formula for calculating
> > +	 * the temperature. The formula used here is from the AXP209,
> > +	 * which is designed by X-Powers, an affiliate of Allwinner:
> > +	 *
> > +	 *     temperature = -144.7 + (value * 0.1)
> > +	 *
> > +	 * This should be replaced with the correct one if such information
> > +	 * becomes available.
> > +	 */
> >  	return sprintf(buf, "%d\n", (ts->temp_data - 1447) * 100);
> 
> Why duplicate it here, instead of doing:
> 
> static int sun4i_get_temp(struct sun4i_ts_data *ts, int *temp)
> {
> 	if (ts->temp_data == -1)
> 		return -EAGAIN;
> 
> 	/* comment */
> 	*temp = (ts->temp_data - 1447) * 100);
> 
> 	return 0;
> }
> 
> static int sun4i_tz_get_temp(void *data, long *temp)
> {
> 	return sun4i_get_temp(data, temp);
> }
> 
> static ssize_t sun4i_show_temp(...)
> {
> 	error = sun4i_get_temp(ts, &temp);
> 	if (error)
> 		return error;
> 
> 	return sprintf(buf, "%d\n", temp);
> }
> 
> Also, thermal core seems to allow creating hwmon devices for thermal
> zones, can we use this feature?
> 
> Thanks.
> 
> -- 
> Dmitry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150109/832619b8/attachment-0001.sig>

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

* Re: [PATCH v2 1/9] Input: sun4i-ts: Add thermal zone sensor support
  2015-01-09 18:33       ` Eduardo Valentin
@ 2015-01-09 18:42         ` Dmitry Torokhov
  -1 siblings, 0 replies; 36+ messages in thread
From: Dmitry Torokhov @ 2015-01-09 18:42 UTC (permalink / raw)
  To: Eduardo Valentin
  Cc: Chen-Yu Tsai, Maxime Ripard, Zhang Rui, Hans de Goede,
	linux-input, linux-arm-kernel, linux-pm

On Fri, Jan 09, 2015 at 02:33:15PM -0400, Eduardo Valentin wrote:
> Dmitry,
> 
> On Fri, Jan 09, 2015 at 09:23:18AM -0800, Dmitry Torokhov wrote:
> > On Fri, Jan 09, 2015 at 06:17:48PM +0800, Chen-Yu Tsai wrote:
> > > The touchscreen controller has a temperature sensor embedded in the SoC,
> > > which already has hwmon support in the driver.
> > > 
> > > Add DT thermal zone support so we can use it with cpufreq for thermal
> > > throttling.
> > > 
> > > This also adds a comment stating that we do not know the actual formula
> > > for calculating the temperature.
> > > 
> > > Signed-off-by: Chen-Yu Tsai <wens@csie.org>
> > > ---
> > 
> > 
> >   CC [M]  drivers/input/touchscreen/sun4i-ts.o
> > drivers/input/touchscreen/sun4i-ts.c:208:15: error: variable
> > ‘sun4i_ts_tz_ops’ has initializer but incomplete type
> >  static struct thermal_zone_of_device_ops sun4i_ts_tz_ops = {
> >                ^
> > drivers/input/touchscreen/sun4i-ts.c:209:2: error: unknown field
> > ‘get_temp’ specified in initializer
> >   .get_temp = get_temp,
> >   ^
> > drivers/input/touchscreen/sun4i-ts.c:209:2: warning: excess elements in
> > struct initializer [enabled by default]
> > drivers/input/touchscreen/sun4i-ts.c:209:2: warning: (near
> > initialization for ‘sun4i_ts_tz_ops’) [enabled by default]
> > drivers/input/touchscreen/sun4i-ts.c: In function ‘sun4i_ts_probe’:
> > drivers/input/touchscreen/sun4i-ts.c:331:8: warning: passing argument 4
> > of ‘thermal_zone_of_sensor_register’ from incompatible pointer type
> > [enabled by default]
> >         &sun4i_ts_tz_ops);
> >         ^
> > In file included from drivers/input/touchscreen/sun4i-ts.c:37:0:
> > include/linux/thermal.h:302:1: note: expected ‘int (*)(void *, long int
> > *)’ but argument is of type ‘struct thermal_zone_of_device_ops *’
> >  thermal_zone_of_sensor_register(struct device *dev, int id,
> >  ^
> > drivers/input/touchscreen/sun4i-ts.c:331:8: error: too few arguments to
> > function ‘thermal_zone_of_sensor_register’
> >         &sun4i_ts_tz_ops);
> >         ^
> > In file included from drivers/input/touchscreen/sun4i-ts.c:37:0:
> > include/linux/thermal.h:302:1: note: declared here
> >  thermal_zone_of_sensor_register(struct device *dev, int id,
> >  ^
> > make[1]: *** [drivers/input/touchscreen/sun4i-ts.o] Error 1
> > make: *** [drivers/input/touchscreen/sun4i-ts.o] Error 2
> > 
> 
> What kernel version are you using?
> 
> It looks like you are missing the of thermal ops commit.

Ah, OK, I have not uprevved my branches with 3.19 stuff yet.

-- 
Dmitry

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

* [PATCH v2 1/9] Input: sun4i-ts: Add thermal zone sensor support
@ 2015-01-09 18:42         ` Dmitry Torokhov
  0 siblings, 0 replies; 36+ messages in thread
From: Dmitry Torokhov @ 2015-01-09 18:42 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Jan 09, 2015 at 02:33:15PM -0400, Eduardo Valentin wrote:
> Dmitry,
> 
> On Fri, Jan 09, 2015 at 09:23:18AM -0800, Dmitry Torokhov wrote:
> > On Fri, Jan 09, 2015 at 06:17:48PM +0800, Chen-Yu Tsai wrote:
> > > The touchscreen controller has a temperature sensor embedded in the SoC,
> > > which already has hwmon support in the driver.
> > > 
> > > Add DT thermal zone support so we can use it with cpufreq for thermal
> > > throttling.
> > > 
> > > This also adds a comment stating that we do not know the actual formula
> > > for calculating the temperature.
> > > 
> > > Signed-off-by: Chen-Yu Tsai <wens@csie.org>
> > > ---
> > 
> > 
> >   CC [M]  drivers/input/touchscreen/sun4i-ts.o
> > drivers/input/touchscreen/sun4i-ts.c:208:15: error: variable
> > ?sun4i_ts_tz_ops? has initializer but incomplete type
> >  static struct thermal_zone_of_device_ops sun4i_ts_tz_ops = {
> >                ^
> > drivers/input/touchscreen/sun4i-ts.c:209:2: error: unknown field
> > ?get_temp? specified in initializer
> >   .get_temp = get_temp,
> >   ^
> > drivers/input/touchscreen/sun4i-ts.c:209:2: warning: excess elements in
> > struct initializer [enabled by default]
> > drivers/input/touchscreen/sun4i-ts.c:209:2: warning: (near
> > initialization for ?sun4i_ts_tz_ops?) [enabled by default]
> > drivers/input/touchscreen/sun4i-ts.c: In function ?sun4i_ts_probe?:
> > drivers/input/touchscreen/sun4i-ts.c:331:8: warning: passing argument 4
> > of ?thermal_zone_of_sensor_register? from incompatible pointer type
> > [enabled by default]
> >         &sun4i_ts_tz_ops);
> >         ^
> > In file included from drivers/input/touchscreen/sun4i-ts.c:37:0:
> > include/linux/thermal.h:302:1: note: expected ?int (*)(void *, long int
> > *)? but argument is of type ?struct thermal_zone_of_device_ops *?
> >  thermal_zone_of_sensor_register(struct device *dev, int id,
> >  ^
> > drivers/input/touchscreen/sun4i-ts.c:331:8: error: too few arguments to
> > function ?thermal_zone_of_sensor_register?
> >         &sun4i_ts_tz_ops);
> >         ^
> > In file included from drivers/input/touchscreen/sun4i-ts.c:37:0:
> > include/linux/thermal.h:302:1: note: declared here
> >  thermal_zone_of_sensor_register(struct device *dev, int id,
> >  ^
> > make[1]: *** [drivers/input/touchscreen/sun4i-ts.o] Error 1
> > make: *** [drivers/input/touchscreen/sun4i-ts.o] Error 2
> > 
> 
> What kernel version are you using?
> 
> It looks like you are missing the of thermal ops commit.

Ah, OK, I have not uprevved my branches with 3.19 stuff yet.

-- 
Dmitry

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

* Re: [PATCH v2 1/9] Input: sun4i-ts: Add thermal zone sensor support
  2015-01-09 18:28       ` Chen-Yu Tsai
@ 2015-01-11  1:59         ` Chen-Yu Tsai
  -1 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-11  1:59 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Maxime Ripard, Zhang Rui, Eduardo Valentin, Hans de Goede,
	linux-input, linux-arm-kernel, linux-pm

On Sat, Jan 10, 2015 at 2:28 AM, Chen-Yu Tsai <wens@csie.org> wrote:
> On Sat, Jan 10, 2015 at 1:23 AM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
>> On Fri, Jan 09, 2015 at 06:17:48PM +0800, Chen-Yu Tsai wrote:
>>> The touchscreen controller has a temperature sensor embedded in the SoC,
>>> which already has hwmon support in the driver.
>>>
>>> Add DT thermal zone support so we can use it with cpufreq for thermal
>>> throttling.
>>>
>>> This also adds a comment stating that we do not know the actual formula
>>> for calculating the temperature.
>>>
>>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
>>> ---
>>
>>
>>   CC [M]  drivers/input/touchscreen/sun4i-ts.o
>> drivers/input/touchscreen/sun4i-ts.c:208:15: error: variable
>> ‘sun4i_ts_tz_ops’ has initializer but incomplete type
>>  static struct thermal_zone_of_device_ops sun4i_ts_tz_ops = {
>>                ^
>> drivers/input/touchscreen/sun4i-ts.c:209:2: error: unknown field
>> ‘get_temp’ specified in initializer
>>   .get_temp = get_temp,
>>   ^
>> drivers/input/touchscreen/sun4i-ts.c:209:2: warning: excess elements in
>> struct initializer [enabled by default]
>> drivers/input/touchscreen/sun4i-ts.c:209:2: warning: (near
>> initialization for ‘sun4i_ts_tz_ops’) [enabled by default]
>> drivers/input/touchscreen/sun4i-ts.c: In function ‘sun4i_ts_probe’:
>> drivers/input/touchscreen/sun4i-ts.c:331:8: warning: passing argument 4
>> of ‘thermal_zone_of_sensor_register’ from incompatible pointer type
>> [enabled by default]
>>         &sun4i_ts_tz_ops);
>>         ^
>> In file included from drivers/input/touchscreen/sun4i-ts.c:37:0:
>> include/linux/thermal.h:302:1: note: expected ‘int (*)(void *, long int
>> *)’ but argument is of type ‘struct thermal_zone_of_device_ops *’
>>  thermal_zone_of_sensor_register(struct device *dev, int id,
>>  ^
>> drivers/input/touchscreen/sun4i-ts.c:331:8: error: too few arguments to
>> function ‘thermal_zone_of_sensor_register’
>>         &sun4i_ts_tz_ops);
>>         ^
>> In file included from drivers/input/touchscreen/sun4i-ts.c:37:0:
>> include/linux/thermal.h:302:1: note: declared here
>>  thermal_zone_of_sensor_register(struct device *dev, int id,
>>  ^
>> make[1]: *** [drivers/input/touchscreen/sun4i-ts.o] Error 1
>> make: *** [drivers/input/touchscreen/sun4i-ts.o] Error 2
>>
>
> struct thermal_zone_of_device_ops was introduced in 3.19-rc1 in
>
>     184a4bf623fa thermal: of: Extend current of-thermal.c code to
> allow setting emulated temp
>
>>>
>>> changes since v1:
>>>
>>>     - clean up thermal zone sensor when input device register fails
>>>     - unconditionally unregister thermal zone sensor on removal.
>>>       the unregister function checks the pointers passed in.
>>>     - add comment explaining the lack of documents for the temperature
>>>       calculation formula
>>>
>>> ---
>>>  .../bindings/input/touchscreen/sun4i.txt           |  2 +
>>>  drivers/input/touchscreen/sun4i-ts.c               | 47 ++++++++++++++++++++++
>>>  2 files changed, 49 insertions(+)
>>>
>>> diff --git a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
>>> index aef57791f40b..a8405bab6c00 100644
>>> --- a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
>>> +++ b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
>>> @@ -5,6 +5,7 @@ Required properties:
>>>   - compatible: "allwinner,sun4i-a10-ts"
>>>   - reg: mmio address range of the chip
>>>   - interrupts: interrupt to which the chip is connected
>>> + - #thermal-sensor-cells: shall be 0
>>>
>>>  Optional properties:
>>>   - allwinner,ts-attached: boolean indicating that an actual touchscreen is
>>> @@ -17,4 +18,5 @@ Example:
>>>               reg = <0x01c25000 0x100>;
>>>               interrupts = <29>;
>>>               allwinner,ts-attached;
>>> +             #thermal-sensor-cells = <0>;
>>>       };
>>> diff --git a/drivers/input/touchscreen/sun4i-ts.c b/drivers/input/touchscreen/sun4i-ts.c
>>> index 28a06749ae42..aac49db0b09d 100644
>>> --- a/drivers/input/touchscreen/sun4i-ts.c
>>> +++ b/drivers/input/touchscreen/sun4i-ts.c
>>> @@ -34,6 +34,7 @@
>>>
>>>  #include <linux/err.h>
>>>  #include <linux/hwmon.h>
>>> +#include <linux/thermal.h>
>>>  #include <linux/init.h>
>>>  #include <linux/input.h>
>>>  #include <linux/interrupt.h>
>>> @@ -107,6 +108,7 @@
>>>  struct sun4i_ts_data {
>>>       struct device *dev;
>>>       struct input_dev *input;
>>> +     struct thermal_zone_device *tz;
>>>       void __iomem *base;
>>>       unsigned int irq;
>>>       bool ignore_fifo_data;
>>> @@ -180,6 +182,33 @@ static void sun4i_ts_close(struct input_dev *dev)
>>>       writel(TEMP_IRQ_EN(1), ts->base + TP_INT_FIFOC);
>>>  }
>>>
>>> +static int get_temp(void *data, long *temp)
>>> +{
>>> +     struct sun4i_ts_data *ts = data;
>>> +
>>> +     /* No temp_data until the first irq */
>>> +     if (ts->temp_data == -1)
>>> +             return -EAGAIN;
>>> +
>>> +     /*
>>> +      * The user manuals do not contain the formula for calculating
>>> +      * the temperature. The formula used here is from the AXP209,
>>> +      * which is designed by X-Powers, an affiliate of Allwinner:
>>> +      *
>>> +      *     temperature = -144.7 + (value * 0.1)
>>> +      *
>>> +      * This should be replaced with the correct one if such information
>>> +      * becomes available.
>>> +      */
>>> +     *temp = (ts->temp_data - 1447) * 100;
>>> +
>>> +     return 0;
>>> +}
>>> +
>>> +static struct thermal_zone_of_device_ops sun4i_ts_tz_ops = {
>>> +     .get_temp = get_temp,
>>> +};
>>> +
>>>  static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
>>>                        char *buf)
>>>  {
>>> @@ -189,6 +218,16 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
>>>       if (ts->temp_data == -1)
>>>               return -EAGAIN;
>>>
>>> +     /*
>>> +      * The user manuals do not contain the formula for calculating
>>> +      * the temperature. The formula used here is from the AXP209,
>>> +      * which is designed by X-Powers, an affiliate of Allwinner:
>>> +      *
>>> +      *     temperature = -144.7 + (value * 0.1)
>>> +      *
>>> +      * This should be replaced with the correct one if such information
>>> +      * becomes available.
>>> +      */
>>>       return sprintf(buf, "%d\n", (ts->temp_data - 1447) * 100);
>>
>> Why duplicate it here, instead of doing:
>>
>> static int sun4i_get_temp(struct sun4i_ts_data *ts, int *temp)
>> {
>>         if (ts->temp_data == -1)
>>                 return -EAGAIN;
>>
>>         /* comment */
>>         *temp = (ts->temp_data - 1447) * 100);
>>
>>         return 0;
>> }
>>
>> static int sun4i_tz_get_temp(void *data, long *temp)
>> {
>>         return sun4i_get_temp(data, temp);
>> }
>>
>> static ssize_t sun4i_show_temp(...)
>> {
>>         error = sun4i_get_temp(ts, &temp);
>>         if (error)
>>                 return error;
>>
>>         return sprintf(buf, "%d\n", temp);
>> }
>
> I suppose that would be better, especially after I added the large comment.
>
>> Also, thermal core seems to allow creating hwmon devices for thermal
>> zones, can we use this feature?
>
> For thermal sensors that also have hwmon devices registered, that step is
> skipped.
>
> I sort of like having separate hwmon bits, just for a nicer, more informative
> label. But I am not opposed to removing the bits from the driver and having
> it go through the thermal core. We could also remove the build dependency
> on HWMON as a result.

OK. Just took a look at the thermal core. For DT based thermal zones, it
does not create hwmon devices at all, possible to avoid duplicate devices
which it cannot know about.

I'll clean up the duplicate code and send v3.


ChenYu

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

* [PATCH v2 1/9] Input: sun4i-ts: Add thermal zone sensor support
@ 2015-01-11  1:59         ` Chen-Yu Tsai
  0 siblings, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2015-01-11  1:59 UTC (permalink / raw)
  To: linux-arm-kernel

On Sat, Jan 10, 2015 at 2:28 AM, Chen-Yu Tsai <wens@csie.org> wrote:
> On Sat, Jan 10, 2015 at 1:23 AM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
>> On Fri, Jan 09, 2015 at 06:17:48PM +0800, Chen-Yu Tsai wrote:
>>> The touchscreen controller has a temperature sensor embedded in the SoC,
>>> which already has hwmon support in the driver.
>>>
>>> Add DT thermal zone support so we can use it with cpufreq for thermal
>>> throttling.
>>>
>>> This also adds a comment stating that we do not know the actual formula
>>> for calculating the temperature.
>>>
>>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
>>> ---
>>
>>
>>   CC [M]  drivers/input/touchscreen/sun4i-ts.o
>> drivers/input/touchscreen/sun4i-ts.c:208:15: error: variable
>> ?sun4i_ts_tz_ops? has initializer but incomplete type
>>  static struct thermal_zone_of_device_ops sun4i_ts_tz_ops = {
>>                ^
>> drivers/input/touchscreen/sun4i-ts.c:209:2: error: unknown field
>> ?get_temp? specified in initializer
>>   .get_temp = get_temp,
>>   ^
>> drivers/input/touchscreen/sun4i-ts.c:209:2: warning: excess elements in
>> struct initializer [enabled by default]
>> drivers/input/touchscreen/sun4i-ts.c:209:2: warning: (near
>> initialization for ?sun4i_ts_tz_ops?) [enabled by default]
>> drivers/input/touchscreen/sun4i-ts.c: In function ?sun4i_ts_probe?:
>> drivers/input/touchscreen/sun4i-ts.c:331:8: warning: passing argument 4
>> of ?thermal_zone_of_sensor_register? from incompatible pointer type
>> [enabled by default]
>>         &sun4i_ts_tz_ops);
>>         ^
>> In file included from drivers/input/touchscreen/sun4i-ts.c:37:0:
>> include/linux/thermal.h:302:1: note: expected ?int (*)(void *, long int
>> *)? but argument is of type ?struct thermal_zone_of_device_ops *?
>>  thermal_zone_of_sensor_register(struct device *dev, int id,
>>  ^
>> drivers/input/touchscreen/sun4i-ts.c:331:8: error: too few arguments to
>> function ?thermal_zone_of_sensor_register?
>>         &sun4i_ts_tz_ops);
>>         ^
>> In file included from drivers/input/touchscreen/sun4i-ts.c:37:0:
>> include/linux/thermal.h:302:1: note: declared here
>>  thermal_zone_of_sensor_register(struct device *dev, int id,
>>  ^
>> make[1]: *** [drivers/input/touchscreen/sun4i-ts.o] Error 1
>> make: *** [drivers/input/touchscreen/sun4i-ts.o] Error 2
>>
>
> struct thermal_zone_of_device_ops was introduced in 3.19-rc1 in
>
>     184a4bf623fa thermal: of: Extend current of-thermal.c code to
> allow setting emulated temp
>
>>>
>>> changes since v1:
>>>
>>>     - clean up thermal zone sensor when input device register fails
>>>     - unconditionally unregister thermal zone sensor on removal.
>>>       the unregister function checks the pointers passed in.
>>>     - add comment explaining the lack of documents for the temperature
>>>       calculation formula
>>>
>>> ---
>>>  .../bindings/input/touchscreen/sun4i.txt           |  2 +
>>>  drivers/input/touchscreen/sun4i-ts.c               | 47 ++++++++++++++++++++++
>>>  2 files changed, 49 insertions(+)
>>>
>>> diff --git a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
>>> index aef57791f40b..a8405bab6c00 100644
>>> --- a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
>>> +++ b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
>>> @@ -5,6 +5,7 @@ Required properties:
>>>   - compatible: "allwinner,sun4i-a10-ts"
>>>   - reg: mmio address range of the chip
>>>   - interrupts: interrupt to which the chip is connected
>>> + - #thermal-sensor-cells: shall be 0
>>>
>>>  Optional properties:
>>>   - allwinner,ts-attached: boolean indicating that an actual touchscreen is
>>> @@ -17,4 +18,5 @@ Example:
>>>               reg = <0x01c25000 0x100>;
>>>               interrupts = <29>;
>>>               allwinner,ts-attached;
>>> +             #thermal-sensor-cells = <0>;
>>>       };
>>> diff --git a/drivers/input/touchscreen/sun4i-ts.c b/drivers/input/touchscreen/sun4i-ts.c
>>> index 28a06749ae42..aac49db0b09d 100644
>>> --- a/drivers/input/touchscreen/sun4i-ts.c
>>> +++ b/drivers/input/touchscreen/sun4i-ts.c
>>> @@ -34,6 +34,7 @@
>>>
>>>  #include <linux/err.h>
>>>  #include <linux/hwmon.h>
>>> +#include <linux/thermal.h>
>>>  #include <linux/init.h>
>>>  #include <linux/input.h>
>>>  #include <linux/interrupt.h>
>>> @@ -107,6 +108,7 @@
>>>  struct sun4i_ts_data {
>>>       struct device *dev;
>>>       struct input_dev *input;
>>> +     struct thermal_zone_device *tz;
>>>       void __iomem *base;
>>>       unsigned int irq;
>>>       bool ignore_fifo_data;
>>> @@ -180,6 +182,33 @@ static void sun4i_ts_close(struct input_dev *dev)
>>>       writel(TEMP_IRQ_EN(1), ts->base + TP_INT_FIFOC);
>>>  }
>>>
>>> +static int get_temp(void *data, long *temp)
>>> +{
>>> +     struct sun4i_ts_data *ts = data;
>>> +
>>> +     /* No temp_data until the first irq */
>>> +     if (ts->temp_data == -1)
>>> +             return -EAGAIN;
>>> +
>>> +     /*
>>> +      * The user manuals do not contain the formula for calculating
>>> +      * the temperature. The formula used here is from the AXP209,
>>> +      * which is designed by X-Powers, an affiliate of Allwinner:
>>> +      *
>>> +      *     temperature = -144.7 + (value * 0.1)
>>> +      *
>>> +      * This should be replaced with the correct one if such information
>>> +      * becomes available.
>>> +      */
>>> +     *temp = (ts->temp_data - 1447) * 100;
>>> +
>>> +     return 0;
>>> +}
>>> +
>>> +static struct thermal_zone_of_device_ops sun4i_ts_tz_ops = {
>>> +     .get_temp = get_temp,
>>> +};
>>> +
>>>  static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
>>>                        char *buf)
>>>  {
>>> @@ -189,6 +218,16 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
>>>       if (ts->temp_data == -1)
>>>               return -EAGAIN;
>>>
>>> +     /*
>>> +      * The user manuals do not contain the formula for calculating
>>> +      * the temperature. The formula used here is from the AXP209,
>>> +      * which is designed by X-Powers, an affiliate of Allwinner:
>>> +      *
>>> +      *     temperature = -144.7 + (value * 0.1)
>>> +      *
>>> +      * This should be replaced with the correct one if such information
>>> +      * becomes available.
>>> +      */
>>>       return sprintf(buf, "%d\n", (ts->temp_data - 1447) * 100);
>>
>> Why duplicate it here, instead of doing:
>>
>> static int sun4i_get_temp(struct sun4i_ts_data *ts, int *temp)
>> {
>>         if (ts->temp_data == -1)
>>                 return -EAGAIN;
>>
>>         /* comment */
>>         *temp = (ts->temp_data - 1447) * 100);
>>
>>         return 0;
>> }
>>
>> static int sun4i_tz_get_temp(void *data, long *temp)
>> {
>>         return sun4i_get_temp(data, temp);
>> }
>>
>> static ssize_t sun4i_show_temp(...)
>> {
>>         error = sun4i_get_temp(ts, &temp);
>>         if (error)
>>                 return error;
>>
>>         return sprintf(buf, "%d\n", temp);
>> }
>
> I suppose that would be better, especially after I added the large comment.
>
>> Also, thermal core seems to allow creating hwmon devices for thermal
>> zones, can we use this feature?
>
> For thermal sensors that also have hwmon devices registered, that step is
> skipped.
>
> I sort of like having separate hwmon bits, just for a nicer, more informative
> label. But I am not opposed to removing the bits from the driver and having
> it go through the thermal core. We could also remove the build dependency
> on HWMON as a result.

OK. Just took a look at the thermal core. For DT based thermal zones, it
does not create hwmon devices at all, possible to avoid duplicate devices
which it cannot know about.

I'll clean up the duplicate code and send v3.


ChenYu

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

end of thread, other threads:[~2015-01-11  1:59 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-09 10:17 [PATCH v2 0/9] ARM: sunxi: Support cpufreq on sun[457]i Chen-Yu Tsai
2015-01-09 10:17 ` Chen-Yu Tsai
2015-01-09 10:17 ` [PATCH v2 1/9] Input: sun4i-ts: Add thermal zone sensor support Chen-Yu Tsai
2015-01-09 10:17   ` Chen-Yu Tsai
2015-01-09 17:23   ` Dmitry Torokhov
2015-01-09 17:23     ` Dmitry Torokhov
2015-01-09 18:28     ` Chen-Yu Tsai
2015-01-09 18:28       ` Chen-Yu Tsai
2015-01-11  1:59       ` Chen-Yu Tsai
2015-01-11  1:59         ` Chen-Yu Tsai
2015-01-09 18:33     ` Eduardo Valentin
2015-01-09 18:33       ` Eduardo Valentin
2015-01-09 18:42       ` Dmitry Torokhov
2015-01-09 18:42         ` Dmitry Torokhov
2015-01-09 10:17 ` [PATCH v2 2/9] ARM: dts: sunxi: Add dtsi for AXP209 PMIC Chen-Yu Tsai
2015-01-09 10:17   ` Chen-Yu Tsai
2015-01-09 10:17 ` [PATCH v2 3/9] ARM: dts: sun7i: Add cpu thermal zones to dtsi Chen-Yu Tsai
2015-01-09 10:17   ` Chen-Yu Tsai
2015-01-09 18:10   ` Eduardo Valentin
2015-01-09 18:10     ` Eduardo Valentin
2015-01-09 10:17 ` [PATCH v2 4/9] ARM: dts: sun7i: cubieboard2: add axp209 regulator nodes Chen-Yu Tsai
2015-01-09 10:17   ` Chen-Yu Tsai
2015-01-09 10:17 ` [PATCH v2 5/9] ARM: dts: sun7i: cubietruck: " Chen-Yu Tsai
2015-01-09 10:17   ` Chen-Yu Tsai
2015-01-09 10:17 ` [PATCH v2 6/9] ARM: dts: sun5i: Add cpu thermal zones to dtsi Chen-Yu Tsai
2015-01-09 10:17   ` Chen-Yu Tsai
2015-01-09 18:10   ` Eduardo Valentin
2015-01-09 18:10     ` Eduardo Valentin
2015-01-09 18:11   ` Eduardo Valentin
2015-01-09 18:11     ` Eduardo Valentin
2015-01-09 10:17 ` [PATCH v2 7/9] ARM: dts: sun5i: hsg-h702: add axp209 regulator nodes Chen-Yu Tsai
2015-01-09 10:17   ` Chen-Yu Tsai
2015-01-09 10:17 ` [PATCH v2 8/9] ARM: dts: sun4i: Add cpu thermal zones to dtsi Chen-Yu Tsai
2015-01-09 10:17   ` Chen-Yu Tsai
2015-01-09 10:17 ` [PATCH v2 9/9] ARM: dts: sun4i: cubieboard: add axp209 regulator nodes Chen-Yu Tsai
2015-01-09 10:17   ` Chen-Yu Tsai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.