From: Eduardo Valentin <edubezval@gmail.com>
To: Chen-Yu Tsai <wens@csie.org>
Cc: Maxime Ripard <maxime.ripard@free-electrons.com>,
Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Zhang Rui <rui.zhang@intel.com>,
Hans de Goede <hdegoede@redhat.com>,
linux-input@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org
Subject: Re: [PATCH v3 1/9] Input: sun4i-ts: Add thermal zone sensor support
Date: Mon, 12 Jan 2015 08:08:05 -0400 [thread overview]
Message-ID: <20150112120803.GB24190@developer> (raw)
In-Reply-To: <1421037249-28461-2-git-send-email-wens@csie.org>
[-- Attachment #1: Type: text/plain, Size: 5364 bytes --]
On Mon, Jan 12, 2015 at 12:34:01PM +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>
Acked-by: Eduardo Valentin <edubezval@gmail.com>
> ---
>
> changes since v2:
>
> - Use common function for temperature calculation
>
> 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 | 54 ++++++++++++++++++++--
> 2 files changed, 52 insertions(+), 4 deletions(-)
>
> 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..5851aa0bd78b 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,16 +182,48 @@ static void sun4i_ts_close(struct input_dev *dev)
> writel(TEMP_IRQ_EN(1), ts->base + TP_INT_FIFOC);
> }
>
> +static int get_temp(const struct sun4i_ts_data *ts, long *temp)
> +{
> + /* 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 int get_tz_temp(void *data, long *temp)
> +{
> + return get_temp(data, temp);
> +}
> +
> +static struct thermal_zone_of_device_ops sun4i_ts_tz_ops = {
> + .get_temp = get_tz_temp,
> +};
> +
> static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
> char *buf)
> {
> struct sun4i_ts_data *ts = dev_get_drvdata(dev);
> + long temp;
> + int ret;
>
> - /* No temp_data until the first irq */
> - if (ts->temp_data == -1)
> - return -EAGAIN;
> + ret = get_temp(ts, &temp);
> + if (ret)
> + return ret;
>
> - return sprintf(buf, "%d\n", (ts->temp_data - 1447) * 100);
> + return sprintf(buf, "%ld\n", temp);
> }
>
> static ssize_t show_temp_label(struct device *dev,
> @@ -283,17 +317,27 @@ static int sun4i_ts_probe(struct platform_device *pdev)
> writel(STYLUS_UP_DEBOUN(5) | STYLUS_UP_DEBOUN_EN(1) | TP_MODE_EN(1),
> ts->base + TP_CTRL1);
>
> + /*
> + * The thermal core does not register hwmon devices for DT-based
> + * thermal zone sensors, such as this one.
> + */
> hwmon = devm_hwmon_device_register_with_groups(ts->dev, "sun4i_ts",
> ts, sun4i_ts_groups);
> 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 +354,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
>
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
next prev parent reply other threads:[~2015-01-12 12:08 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-12 4:34 [PATCH v3 0/9] ARM: sunxi: Support cpufreq on sun[457]i Chen-Yu Tsai
2015-01-12 4:34 ` [PATCH v3 1/9] Input: sun4i-ts: Add thermal zone sensor support Chen-Yu Tsai
2015-01-12 12:08 ` Eduardo Valentin [this message]
2015-01-12 4:34 ` [PATCH v3 2/9] ARM: dts: sunxi: Add dtsi for AXP209 PMIC Chen-Yu Tsai
2015-01-12 4:34 ` [PATCH v3 3/9] ARM: dts: sun7i: Add cpu thermal zones to dtsi Chen-Yu Tsai
2015-01-12 4:34 ` [PATCH v3 4/9] ARM: dts: sun7i: cubieboard2: add axp209 regulator nodes Chen-Yu Tsai
2015-01-12 9:06 ` Maxime Ripard
2015-01-12 9:38 ` Chen-Yu Tsai
2015-01-13 9:40 ` Maxime Ripard
2015-01-13 10:30 ` Chen-Yu Tsai
2015-01-14 19:30 ` Maxime Ripard
2015-01-12 4:34 ` [PATCH v3 5/9] ARM: dts: sun7i: cubietruck: " Chen-Yu Tsai
2015-01-12 4:34 ` [PATCH v3 6/9] ARM: dts: sun5i: Add cpu thermal zones to dtsi Chen-Yu Tsai
2015-01-12 4:34 ` [PATCH v3 7/9] ARM: dts: sun5i: hsg-h702: add axp209 regulator nodes Chen-Yu Tsai
2015-01-12 4:34 ` [PATCH v3 8/9] ARM: dts: sun4i: Add cpu thermal zones to dtsi Chen-Yu Tsai
2015-01-12 4:34 ` [PATCH v3 9/9] ARM: dts: sun4i: cubieboard: add axp209 regulator nodes Chen-Yu Tsai
2015-01-12 9:10 ` [PATCH v3 0/9] ARM: sunxi: Support cpufreq on sun[457]i Maxime Ripard
2015-01-13 13:53 ` Maxime Ripard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150112120803.GB24190@developer \
--to=edubezval@gmail.com \
--cc=dmitry.torokhov@gmail.com \
--cc=hdegoede@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=maxime.ripard@free-electrons.com \
--cc=rui.zhang@intel.com \
--cc=wens@csie.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).