From patchwork Tue Dec 24 22:24:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 3404691 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5AEB39F169 for ; Tue, 24 Dec 2013 22:26:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5A5C72015A for ; Tue, 24 Dec 2013 22:26:30 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4AFC220158 for ; Tue, 24 Dec 2013 22:26:29 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VvaPj-0005VZ-9c; Tue, 24 Dec 2013 22:25:24 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VvaPV-0006hM-IV; Tue, 24 Dec 2013 22:25:09 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VvaP0-0006eV-Qk for linux-arm-kernel@lists.infradead.org; Tue, 24 Dec 2013 22:24:41 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rBOMOFUq015623 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 24 Dec 2013 17:24:15 -0500 Received: from shalem.localdomain.com (vpn1-6-210.ams2.redhat.com [10.36.6.210]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rBOMO82J019675; Tue, 24 Dec 2013 17:24:13 -0500 From: Hans de Goede To: Dmitry Torokhov Subject: [PATCH 2/5] input: sun4i-ts: Add support for temperature sensor Date: Tue, 24 Dec 2013 23:24:04 +0100 Message-Id: <1387923847-1294-3-git-send-email-hdegoede@redhat.com> In-Reply-To: <1387923847-1294-1-git-send-email-hdegoede@redhat.com> References: <1387923847-1294-1-git-send-email-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131224_172439_095927_C2BE624B X-CRM114-Status: GOOD ( 23.46 ) X-Spam-Score: -7.5 (-------) Cc: LM Sensors , Hans de Goede , linux-sunxi@googlegroups.com, linux-input@vger.kernel.org, Maxime Ripard , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 sun4i resisitive touchscreen controller also comes with a built-in temperature sensor. This commit adds support for it. This commit also introduces a new "ts-attached" device-tree attribute, when this is not set, the input part of the driver won't register. This way the internal temperature sensor can be used to measure the SoC temperature independent of there actually being a touchscreen attached to the controller. Signed-off-by: Hans de Goede --- drivers/input/touchscreen/sun4i-ts.c | 106 +++++++++++++++++++++++++++++++++-- 1 file changed, 102 insertions(+), 4 deletions(-) diff --git a/drivers/input/touchscreen/sun4i-ts.c b/drivers/input/touchscreen/sun4i-ts.c index b3f01c0..15a486d 100644 --- a/drivers/input/touchscreen/sun4i-ts.c +++ b/drivers/input/touchscreen/sun4i-ts.c @@ -3,6 +3,9 @@ * * Copyright (C) 2013 - 2014 Hans de Goede * + * The hwmon parts are based on work by Corentin LABBE which is: + * Copyright (C) 2013 Corentin LABBE + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -31,6 +34,7 @@ #include #include +#include #include #include #include @@ -97,10 +101,16 @@ #define TP_UP_PENDING (1 << 1) #define TP_DOWN_PENDING (1 << 0) +/* TP_TPR bits */ +#define TEMP_ENABLE(x) ((x) << 16) +#define TEMP_PERIOD(x) ((x) << 0) /* t = x * 256 * 16 / clkin */ + struct sun4i_ts_data { struct device *dev; void __iomem *base; struct input_dev *input; + struct device *hwmon; + atomic_t temp_data; int ignore_fifo_data; }; @@ -111,6 +121,12 @@ static irqreturn_t sun4i_ts_irq(int irq, void *dev_id) reg_val = readl(ts->base + TP_INT_FIFOS); + if (reg_val & TEMP_DATA_PENDING) + atomic_set(&ts->temp_data, readl(ts->base + TEMP_DATA)); + + if (!ts->input) + goto leave; + if (reg_val & FIFO_DATA_PENDING) { x = readl(ts->base + TP_DATA); y = readl(ts->base + TP_DATA); @@ -135,6 +151,7 @@ static irqreturn_t sun4i_ts_irq(int irq, void *dev_id) input_sync(ts->input); } +leave: writel(reg_val, ts->base + TP_INT_FIFOS); return IRQ_HANDLED; @@ -170,6 +187,66 @@ static int sun4i_ts_register_input(struct sun4i_ts_data *ts, return 0; } +static ssize_t show_name(struct device *dev, struct device_attribute *devattr, + char *buf) +{ + return sprintf(buf, "sun4i_ts\n"); +} + +static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, + char *buf) +{ + struct sun4i_ts_data *ts = dev_get_drvdata(dev); + int temp_data; + + temp_data = atomic_read(&ts->temp_data); + /* No temp_data until the first irq */ + if (temp_data == -1) + return -EAGAIN; + + return sprintf(buf, "%d\n", (temp_data - 1447) * 100); +} + +static ssize_t show_temp_label(struct device *dev, + struct device_attribute *devattr, char *buf) +{ + return sprintf(buf, "SoC temperature\n"); +} + +static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); +static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL); +static DEVICE_ATTR(temp1_label, S_IRUGO, show_temp_label, NULL); + +static struct attribute *sun4i_ts_attributes[] = { + &dev_attr_name.attr, + &dev_attr_temp1_input.attr, + &dev_attr_temp1_label.attr, + NULL +}; + +static const struct attribute_group sun4i_ts_attr_group = { + .attrs = sun4i_ts_attributes, +}; + +static int sun4i_ts_register_hwmon(struct sun4i_ts_data *ts) +{ + int ret; + + atomic_set(&ts->temp_data, -1); + + ret = sysfs_create_group(&ts->dev->kobj, &sun4i_ts_attr_group); + if (ret) + return ret; + + ts->hwmon = hwmon_device_register(ts->dev); + if (IS_ERR(ts->hwmon)) { + ret = PTR_ERR(ts->hwmon); + ts->hwmon = NULL; + } + + return ret; +} + static int sun4i_ts_remove(struct platform_device *pdev) { struct sun4i_ts_data *ts = platform_get_drvdata(pdev); @@ -178,9 +255,13 @@ static int sun4i_ts_remove(struct platform_device *pdev) writel(0, ts->base + TP_INT_FIFOC); msleep(20); + if (ts->hwmon) + hwmon_device_unregister(ts->hwmon); + if (ts->input) input_unregister_device(ts->input); + sysfs_remove_group(&ts->dev->kobj, &sun4i_ts_attr_group); kfree(ts); return 0; @@ -189,7 +270,11 @@ static int sun4i_ts_remove(struct platform_device *pdev) static int sun4i_ts_probe(struct platform_device *pdev) { struct sun4i_ts_data *ts; + struct device_node *np = pdev->dev.of_node; int ret = -ENOMEM; + u32 ts_attached = 0; + + of_property_read_u32(np, "ts-attached", &ts_attached); ts = kzalloc(sizeof(struct sun4i_ts_data), GFP_KERNEL); if (!ts) @@ -210,7 +295,13 @@ static int sun4i_ts_probe(struct platform_device *pdev) if (ret) goto error; - ret = sun4i_ts_register_input(ts, pdev->name); + if (ts_attached) { + ret = sun4i_ts_register_input(ts, pdev->name); + if (ret) + goto error; + } + + ret = sun4i_ts_register_hwmon(ts); if (ret) goto error; @@ -231,9 +322,16 @@ static int sun4i_ts_probe(struct platform_device *pdev) /* Enable median filter, type 1 : 5/3 */ writel(FILTER_EN(1) | FILTER_TYPE(1), ts->base + TP_CTRL3); - /* Flush fifo, set trig level to 1, enable data and pen up irqs */ - writel(DATA_IRQ_EN(1) | FIFO_TRIG(1) | FIFO_FLUSH(1) | TP_UP_IRQ_EN(1), - ts->base + TP_INT_FIFOC); + if (ts_attached) { + /* Flush, set trig level to 1, enable temp, data and up irqs */ + writel(TEMP_IRQ_EN(1) | DATA_IRQ_EN(1) | FIFO_TRIG(1) | + FIFO_FLUSH(1) | TP_UP_IRQ_EN(1), + ts->base + TP_INT_FIFOC); + } else + writel(TEMP_IRQ_EN(1), ts->base + TP_INT_FIFOC); + + /* Enable temperature measurement, period 1953 (2 seconds) */ + writel(TEMP_ENABLE(1) | TEMP_PERIOD(1953), ts->base + TP_TPR); /* * Set stylus up debounce to aprox 10 ms, enable debounce, and