From patchwork Fri Jan 9 10:17:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 5597621 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A15A69FB36 for ; Fri, 9 Jan 2015 10:18:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B481F20353 for ; Fri, 9 Jan 2015 10:18:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A92592038C for ; Fri, 9 Jan 2015 10:18:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756794AbbAIKSL (ORCPT ); Fri, 9 Jan 2015 05:18:11 -0500 Received: from smtp.csie.ntu.edu.tw ([140.112.30.61]:47056 "EHLO smtp.csie.ntu.edu.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756357AbbAIKSE (ORCPT ); Fri, 9 Jan 2015 05:18:04 -0500 Received: from mirror2.csie.ntu.edu.tw (mirror2.csie.ntu.edu.tw [140.112.30.76]) (Authenticated sender: b93043) by smtp.csie.ntu.edu.tw (Postfix) with ESMTPSA id 1EC9A2089D; Fri, 9 Jan 2015 18:17:59 +0800 (CST) Received: by mirror2.csie.ntu.edu.tw (Postfix, from userid 1000) id F1C715F74F; Fri, 9 Jan 2015 18:17:58 +0800 (CST) From: Chen-Yu Tsai To: Maxime Ripard , Dmitry Torokhov , Zhang Rui , Eduardo Valentin Cc: Chen-Yu Tsai , Hans de Goede , linux-input@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org Subject: [PATCH v2 1/9] Input: sun4i-ts: Add thermal zone sensor support Date: Fri, 9 Jan 2015 18:17:48 +0800 Message-Id: <1420798676-22856-2-git-send-email-wens@csie.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1420798676-22856-1-git-send-email-wens@csie.org> References: <1420798676-22856-1-git-send-email-wens@csie.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 #include +#include #include #include #include @@ -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);