All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chen-Yu Tsai <wens@csie.org>
To: Eduardo Valentin <edubezval@gmail.com>
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-input@vger.kernel.org>,
	linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
	linux-pm@vger.kernel.org
Subject: Re: [PATCH 03/17] Input: sun4i-ts: Add thermal zone sensor support
Date: Thu, 8 Jan 2015 21:33:54 +0800	[thread overview]
Message-ID: <CAGb2v64F8mQRka=L1qWKe=WNOUYtiC5RSZUDORr3Ynd3Djf20g@mail.gmail.com> (raw)
In-Reply-To: <CAGb2v66L-ZD1Ep-rnKXKP7PuJH+dA=26tV35KyKCNnKHgM4Hmg@mail.gmail.com>

On Thu, Jan 8, 2015 at 12:24 AM, Chen-Yu Tsai <wens@csie.org> wrote:
> Hi,
>
> On Tue, Jan 6, 2015 at 11:24 PM, Eduardo Valentin <edubezval@gmail.com> wrote:
>> Hello Chen-Yu,
>>
>>
>> On Tue, Jan 06, 2015 at 10:35:13AM +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.
>>>
>>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
>>> ---
>>>  .../bindings/input/touchscreen/sun4i.txt           |  1 +
>>>  drivers/input/touchscreen/sun4i-ts.c               | 27 ++++++++++++++++++++++
>>>  2 files changed, 28 insertions(+)
>>>
>>> diff --git a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
>>> index aef57791f40b..7f1110adbd24 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
>>>
>>
>> You may want to update your Example section too, below.
>> Example:
>>
>>         rtp: rtp@01c25000 {
>>                 compatible = "allwinner,sun4i-a10-ts";
>>                 reg = <0x01c25000 0x100>;
>>                 interrupts = <29>;
>>                 allwinner,ts-attached;
>>                 #thermal-sensor-cells = <0>;
>>         };
>
> Ok.
>
>>
>>
>>>  Optional properties:
>>>   - allwinner,ts-attached: boolean indicating that an actual touchscreen is
>>> diff --git a/drivers/input/touchscreen/sun4i-ts.c b/drivers/input/touchscreen/sun4i-ts.c
>>> index 28a06749ae42..b6e9043446d6 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,23 @@ 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;
>>> +
>>> +     *temp = (ts->temp_data - 1447) * 100;
>>> +
>>
>> Care to explain the formula in a simple comment?
>
> This was just copied from the hwmon section. AFAIK there is no documentation
> for the formula. It was probably copied from Allwinner's SDK code.
>
> Hans? Do you remember where you got this?

So this is from the AXP209 datasheet. The Allwinner SoC datasheets don't
mention the formula to calculate the temperature. But since Allwinner
and X-powers are affiliated, it's possible they use the same formula.

http://comments.gmane.org/gmane.comp.hardware.netbook.arm.sunxi/3838

>>> +     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)
>>>  {
>>> @@ -288,6 +307,11 @@ 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) {
>>
>> here.. if input_register_device fails, you will keep an orphan thermal zone
>> registered in your system:
>>
>>                 error = input_register_device(ts->input);
>>                 if (error) {
>>                         writel(0, ts->base + TP_INT_FIFOC);
>
> Will add an unregister call here.
>
>
> Thanks for the review.
>
> ChenYu
>
>>                         return error;
>>                 }
>>                 ...
>>
>>
>>> @@ -310,6 +334,9 @@ static int sun4i_ts_remove(struct platform_device *pdev)
>>>       if (ts->input)
>>>               input_unregister_device(ts->input);
>>>
>>> +     if (ts->tz)
>>> +             thermal_zone_of_sensor_unregister(ts->dev, ts->tz);
>>> +
>>>       /* Deactivate all IRQs */
>>>       writel(0, ts->base + TP_INT_FIFOC);
>>>
>>> --
>>> 2.1.4
>>>

WARNING: multiple messages have this Message-ID (diff)
From: wens@csie.org (Chen-Yu Tsai)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 03/17] Input: sun4i-ts: Add thermal zone sensor support
Date: Thu, 8 Jan 2015 21:33:54 +0800	[thread overview]
Message-ID: <CAGb2v64F8mQRka=L1qWKe=WNOUYtiC5RSZUDORr3Ynd3Djf20g@mail.gmail.com> (raw)
In-Reply-To: <CAGb2v66L-ZD1Ep-rnKXKP7PuJH+dA=26tV35KyKCNnKHgM4Hmg@mail.gmail.com>

On Thu, Jan 8, 2015 at 12:24 AM, Chen-Yu Tsai <wens@csie.org> wrote:
> Hi,
>
> On Tue, Jan 6, 2015 at 11:24 PM, Eduardo Valentin <edubezval@gmail.com> wrote:
>> Hello Chen-Yu,
>>
>>
>> On Tue, Jan 06, 2015 at 10:35:13AM +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.
>>>
>>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
>>> ---
>>>  .../bindings/input/touchscreen/sun4i.txt           |  1 +
>>>  drivers/input/touchscreen/sun4i-ts.c               | 27 ++++++++++++++++++++++
>>>  2 files changed, 28 insertions(+)
>>>
>>> diff --git a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
>>> index aef57791f40b..7f1110adbd24 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
>>>
>>
>> You may want to update your Example section too, below.
>> Example:
>>
>>         rtp: rtp at 01c25000 {
>>                 compatible = "allwinner,sun4i-a10-ts";
>>                 reg = <0x01c25000 0x100>;
>>                 interrupts = <29>;
>>                 allwinner,ts-attached;
>>                 #thermal-sensor-cells = <0>;
>>         };
>
> Ok.
>
>>
>>
>>>  Optional properties:
>>>   - allwinner,ts-attached: boolean indicating that an actual touchscreen is
>>> diff --git a/drivers/input/touchscreen/sun4i-ts.c b/drivers/input/touchscreen/sun4i-ts.c
>>> index 28a06749ae42..b6e9043446d6 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,23 @@ 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;
>>> +
>>> +     *temp = (ts->temp_data - 1447) * 100;
>>> +
>>
>> Care to explain the formula in a simple comment?
>
> This was just copied from the hwmon section. AFAIK there is no documentation
> for the formula. It was probably copied from Allwinner's SDK code.
>
> Hans? Do you remember where you got this?

So this is from the AXP209 datasheet. The Allwinner SoC datasheets don't
mention the formula to calculate the temperature. But since Allwinner
and X-powers are affiliated, it's possible they use the same formula.

http://comments.gmane.org/gmane.comp.hardware.netbook.arm.sunxi/3838

>>> +     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)
>>>  {
>>> @@ -288,6 +307,11 @@ 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) {
>>
>> here.. if input_register_device fails, you will keep an orphan thermal zone
>> registered in your system:
>>
>>                 error = input_register_device(ts->input);
>>                 if (error) {
>>                         writel(0, ts->base + TP_INT_FIFOC);
>
> Will add an unregister call here.
>
>
> Thanks for the review.
>
> ChenYu
>
>>                         return error;
>>                 }
>>                 ...
>>
>>
>>> @@ -310,6 +334,9 @@ static int sun4i_ts_remove(struct platform_device *pdev)
>>>       if (ts->input)
>>>               input_unregister_device(ts->input);
>>>
>>> +     if (ts->tz)
>>> +             thermal_zone_of_sensor_unregister(ts->dev, ts->tz);
>>> +
>>>       /* Deactivate all IRQs */
>>>       writel(0, ts->base + TP_INT_FIFOC);
>>>
>>> --
>>> 2.1.4
>>>

  reply	other threads:[~2015-01-08 13:34 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-06  2:35 [PATCH 00/17] ARM: sunxi: Support cpufreq on sun[457]i Chen-Yu Tsai
2015-01-06  2:35 ` Chen-Yu Tsai
2015-01-06  2:35 ` [PATCH 01/17] ARM: sunxi: Register cpufreq-dt for sun[45678]i Chen-Yu Tsai
2015-01-06  2:35   ` Chen-Yu Tsai
2015-01-06 15:55   ` Maxime Ripard
2015-01-06 15:55     ` Maxime Ripard
2015-01-07  9:07     ` Chen-Yu Tsai
2015-01-07  9:07       ` Chen-Yu Tsai
2015-01-07 10:01       ` Viresh Kumar
2015-01-07 10:01         ` Viresh Kumar
2015-01-07 10:23   ` Maxime Ripard
2015-01-07 10:23     ` Maxime Ripard
2015-01-06  2:35 ` [PATCH 02/17] clk: sunxi: Propagate rate changes to parent for mux clocks Chen-Yu Tsai
2015-01-06  2:35   ` Chen-Yu Tsai
2015-01-06 16:00   ` Maxime Ripard
2015-01-06 16:00     ` Maxime Ripard
2015-01-06  2:35 ` [PATCH 03/17] Input: sun4i-ts: Add thermal zone sensor support Chen-Yu Tsai
2015-01-06  2:35   ` Chen-Yu Tsai
2015-01-06 15:24   ` Eduardo Valentin
2015-01-06 15:24     ` Eduardo Valentin
2015-01-07 16:24     ` Chen-Yu Tsai
2015-01-07 16:24       ` Chen-Yu Tsai
2015-01-08 13:33       ` Chen-Yu Tsai [this message]
2015-01-08 13:33         ` Chen-Yu Tsai
2015-01-09 18:07         ` Eduardo Valentin
2015-01-09 18:07           ` Eduardo Valentin
2015-01-09 18:24           ` Chen-Yu Tsai
2015-01-09 18:24             ` Chen-Yu Tsai
2015-01-06  2:35 ` [PATCH 04/17] ARM: dts: sunxi: Add dtsi for AXP209 PMIC Chen-Yu Tsai
2015-01-06  2:35   ` Chen-Yu Tsai
2015-01-06 15:58   ` Maxime Ripard
2015-01-06 15:58     ` Maxime Ripard
2015-01-06 19:09     ` Chen-Yu Tsai
2015-01-06 19:09       ` Chen-Yu Tsai
2015-01-06  2:35 ` [PATCH 05/17] ARM: dts: sunxi: Enable thermal sensor support for RTP on sun[457]i Chen-Yu Tsai
2015-01-06  2:35   ` Chen-Yu Tsai
2015-01-06 15:25   ` Eduardo Valentin
2015-01-06 15:25     ` Eduardo Valentin
2015-01-06 15:52   ` Maxime Ripard
2015-01-06 15:52     ` Maxime Ripard
2015-01-06  2:35 ` [PATCH 06/17] ARM: dts: sun7i: Add cpu clock reference and operating points to dtsi Chen-Yu Tsai
2015-01-06  2:35   ` Chen-Yu Tsai
2015-01-06 16:07   ` Maxime Ripard
2015-01-06 16:07     ` Maxime Ripard
2015-01-06  2:35 ` [PATCH 07/17] ARM: dts: sun7i: Add cpu thermal zones " Chen-Yu Tsai
2015-01-06  2:35   ` Chen-Yu Tsai
2015-01-06 15:28   ` Eduardo Valentin
2015-01-06 15:28     ` Eduardo Valentin
2015-01-06  2:35 ` [PATCH 08/17] ARM: dts: sun7i: cubieboard2: add axp209 regulator nodes Chen-Yu Tsai
2015-01-06  2:35   ` Chen-Yu Tsai
2015-01-06 16:11   ` Maxime Ripard
2015-01-06 16:11     ` Maxime Ripard
2015-01-06  2:35 ` [PATCH 09/17] ARM: dts: sun7i: cubietruck: " Chen-Yu Tsai
2015-01-06  2:35   ` Chen-Yu Tsai
2015-01-06  2:35 ` [PATCH 10/17] ARM: dts: sun5i: Add cpu clock reference and operating points to dtsi Chen-Yu Tsai
2015-01-06  2:35   ` Chen-Yu Tsai
2015-01-06  2:35 ` [PATCH 11/17] ARM: dts: sun5i: Add cpu thermal zones " Chen-Yu Tsai
2015-01-06  2:35   ` Chen-Yu Tsai
2015-01-06 15:30   ` Eduardo Valentin
2015-01-06 15:30     ` Eduardo Valentin
2015-01-06  2:35 ` [PATCH 12/17] ARM: dts: sun5i: hsg-h702: add axp209 regulator nodes Chen-Yu Tsai
2015-01-06  2:35   ` Chen-Yu Tsai
2015-01-06  2:35 ` [PATCH 13/17] ARM: dts: sun4i: Add cpu clock reference and operating points to dtsi Chen-Yu Tsai
2015-01-06  2:35   ` Chen-Yu Tsai
2015-01-06  2:35 ` [PATCH 14/17] ARM: dts: sun4i: Add cpu thermal zones " Chen-Yu Tsai
2015-01-06  2:35   ` Chen-Yu Tsai
2015-01-06 15:29   ` Eduardo Valentin
2015-01-06 15:29     ` Eduardo Valentin
2015-01-06  2:35 ` [PATCH 15/17] ARM: dts: sun4i: cubieboard: add axp209 regulator nodes Chen-Yu Tsai
2015-01-06  2:35   ` Chen-Yu Tsai
2015-01-06  2:35 ` [PATCH 16/17] ARM: sunxi_defconfig: Enable TOUCHSCREEN_SUN4I, CPUFREQ_DT, CPU_THERMAL Chen-Yu Tsai
2015-01-06  2:35   ` Chen-Yu Tsai
2015-01-06 15:32   ` Eduardo Valentin
2015-01-06 15:32     ` Eduardo Valentin
2015-01-06 16:13   ` Maxime Ripard
2015-01-06 16:13     ` Maxime Ripard
2015-01-06  2:35 ` [PATCH 17/17] ARM: multi_v7_defconfig: Enable TOUCHSCREEN_SUN4I, CPU_THERMAL Chen-Yu Tsai
2015-01-06  2:35   ` Chen-Yu Tsai
2015-01-06 15:31   ` Eduardo Valentin
2015-01-06 15:31     ` Eduardo Valentin
2015-01-06 16:12   ` Maxime Ripard
2015-01-06 16:12     ` 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='CAGb2v64F8mQRka=L1qWKe=WNOUYtiC5RSZUDORr3Ynd3Djf20g@mail.gmail.com' \
    --to=wens@csie.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=edubezval@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 \
    /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 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.