From patchwork Sun Jan 28 23:29:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Rossak X-Patchwork-Id: 10188593 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 34CC260383 for ; Sun, 28 Jan 2018 23:32:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2ECCA286D1 for ; Sun, 28 Jan 2018 23:32:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 23BC4286DA; Sun, 28 Jan 2018 23:32:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8A8D9286D1 for ; Sun, 28 Jan 2018 23:32:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=BzBgxdDcJD2N/AkItQN4LuxBKFClOMUqP1615h3p4kg=; b=NvH2gJm8KVfmlhQpOPuClT1dSO 1S6SyqUo04D9at93jArVFPM56EyMv+7Bazaoq4UQJDqiyDmBJreWFFedynvJ/Dy2Udq1YPKdl1/lT AC0QswUV3v7PX6I7eh3ElAwFWpknXtzZNur1exyxBTJXdtbu4C51+tZuxNBo4S4u7o2yZQW4vl7/k Y7AZW+f392d4krVcUrNkb6Xr7MspuFfMSCAobvlmlWLDoOgbpG+Xe2Mdoe3s6ejM+D8bs6AF8ARRz Rui46ojhq53gHLBAsqbteetTMQIgPXmV/voPWF2yWkz992Zfe+hLIHWkQ3MKAKxnicAwgQk1LKsoe DAuVknWA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1efwRH-0008S5-6m; Sun, 28 Jan 2018 23:32:43 +0000 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1efwOJ-0004KA-MY for linux-arm-kernel@lists.infradead.org; Sun, 28 Jan 2018 23:29:46 +0000 Received: by mail-wr0-x242.google.com with SMTP id v15so5284368wrb.8 for ; Sun, 28 Jan 2018 15:29:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0fB9keSrkLUbGLRmQj6r7CeTeR3Nyvvo0htxNWYxU90=; b=rSTSskoe8gXObRANZT+VRo3DwFhfozNQZwTdffPW3q/aowDWx9FmjQX1+nwk/7/PsL HbsSqeldsfac6awZhTxSuIMlr0OvdkuFw7zj1gVYwNkGNj3KJQhPhjJK88BaI+dkJZFZ yFEqV2lDomtWL7T7KW178alSkjqFMjUem9mBO59ofVSBTHS6bp98MkSgz5V3DHv6L8LC bG9v3i6haTqfFa5259/18wb8jimDFwPTf9J0Wkv28S+2jPYLwqiRntX8VGph3EL2H3ml sPgWgDWu/QS+2TAVVi3rrtIgI1eC8kC2lQyfsk7BTGPnH9QLb43rHDJ+aLKGILE4C9LS FZuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0fB9keSrkLUbGLRmQj6r7CeTeR3Nyvvo0htxNWYxU90=; b=dPnsFh5dyPp3Nq3LpzYf3ysNGTiHrV0IYGsXa8YiDJ2DWqcxyRcoqZPMcY9rioGDqb dNtur+rdYzlaSHLAyYupYff703HOL2kk8Q1z1gWlEcX+I65ZMiKYrb7yh+BT16EQWZcm 6X/tYYLmYuj3NGlYZxOyrJ9mOjZ6G+oUCxvwdkr8V8zWISF4Mq+aTiULl6OsZ7xoxrWJ 6WXuOFfJ1rNnL99GegmbUwzv+RS1g0k0x7SuBJCWUt02j/vArxcQ3bFDoq+T/lMl9mmZ 0ngvncT2jqaKxZ7nkjFCQcnSMnShdhIOi8U+iySuMpdeJNXnw6fWaRmd7W6GrVPcsmuh kTcQ== X-Gm-Message-State: AKwxyteMWkZszGBgyHD9LjjvCowFv9VtT4jWoiSdMbaz3TY1vaUK7fYU N6oME9PP1LKcwOEK5PxqY2w= X-Google-Smtp-Source: AH8x225UYyc86CIQai3ORBZE5vL4lCF7VdaCQW06Bd+LN1Of2hDgQ2250e3hyw/7qVemDnngv4qCfA== X-Received: by 10.223.139.147 with SMTP id o19mr16859632wra.66.1517182177240; Sun, 28 Jan 2018 15:29:37 -0800 (PST) Received: from debian-laptop.fritz.box (p578F04D2.dip0.t-ipconnect.de. [87.143.4.210]) by smtp.gmail.com with ESMTPSA id m86sm11839223wmi.40.2018.01.28.15.29.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jan 2018 15:29:36 -0800 (PST) From: Philipp Rossak To: lee.jones@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@free-electrons.com, wens@csie.org, linux@armlinux.org.uk, jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, davem@davemloft.net, hans.verkuil@cisco.com, mchehab@kernel.org, rask@formelder.dk, clabbe.montjoie@gmail.com, sean@mess.org, krzk@kernel.org, quentin.schulz@free-electrons.com, icenowy@aosc.io, edu.molinas@gmail.com, singhalsimran0@gmail.com Subject: [PATCH v2 08/16] iio: adc: sun4i-gpadc-iio: rework: add interrupt support Date: Mon, 29 Jan 2018 00:29:11 +0100 Message-Id: <20180128232919.12639-9-embed3d@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180128232919.12639-1-embed3d@gmail.com> References: <20180128232919.12639-1-embed3d@gmail.com> X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-sunxi@googlegroups.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch rewors the driver to support interrupts for the thermal part of the sensor. This is only available for the newer sensor (currently H3 and A83T). The interrupt will be trigerd on data available and triggers the update for the thermal sensors. All newer sensors have different amount of sensors and different interrupts for each device the reset of the interrupts need to be done different For the newer sensors is the autosuspend disabled. Signed-off-by: Philipp Rossak Acked-by: Jonathan Cameron --- drivers/iio/adc/sun4i-gpadc-iio.c | 60 +++++++++++++++++++++++++++++++++++---- include/linux/mfd/sun4i-gpadc.h | 2 ++ 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c index 74eeb5cd5218..b7b5451226b0 100644 --- a/drivers/iio/adc/sun4i-gpadc-iio.c +++ b/drivers/iio/adc/sun4i-gpadc-iio.c @@ -71,11 +71,14 @@ struct gpadc_data { unsigned int temp_data[MAX_SENSOR_COUNT]; int (*sample_start)(struct sun4i_gpadc_iio *info); int (*sample_end)(struct sun4i_gpadc_iio *info); + u32 irq_clear_map; + u32 irq_control_map; bool has_bus_clk; bool has_bus_rst; bool has_mod_clk; int sensor_count; bool supports_nvmem; + bool support_irq; }; static const struct gpadc_data sun4i_gpadc_data = { @@ -90,6 +93,7 @@ static const struct gpadc_data sun4i_gpadc_data = { .sample_end = sun4i_gpadc_sample_end, .sensor_count = 1, .supports_nvmem = false, + .support_irq = false, }; static const struct gpadc_data sun5i_gpadc_data = { @@ -104,6 +108,7 @@ static const struct gpadc_data sun5i_gpadc_data = { .sample_end = sun4i_gpadc_sample_end, .sensor_count = 1, .supports_nvmem = false, + .support_irq = false, }; static const struct gpadc_data sun6i_gpadc_data = { @@ -118,6 +123,7 @@ static const struct gpadc_data sun6i_gpadc_data = { .sample_end = sun4i_gpadc_sample_end, .sensor_count = 1, .supports_nvmem = false, + .support_irq = false, }; static const struct gpadc_data sun8i_a33_gpadc_data = { @@ -129,6 +135,7 @@ static const struct gpadc_data sun8i_a33_gpadc_data = { .sample_end = sun4i_gpadc_sample_end, .sensor_count = 1, .supports_nvmem = false, + .support_irq = false, }; struct sun4i_gpadc_iio { @@ -332,6 +339,11 @@ static int sun4i_gpadc_temp_read(struct iio_dev *indio_dev, int *val, return 0; } + if (info->data->support_irq) { + regmap_read(info->regmap, info->data->temp_data[sensor], val); + return 0; + } + return sun4i_gpadc_read(indio_dev, 0, val, info->temp_data_irq); } @@ -429,6 +441,17 @@ static irqreturn_t sun4i_gpadc_fifo_data_irq_handler(int irq, void *dev_id) return IRQ_HANDLED; } +static irqreturn_t sunxi_irq_thread(int irq, void *data) +{ + struct sun4i_gpadc_iio *info = data; + + regmap_write(info->regmap, SUN8I_H3_THS_STAT, info->data->irq_clear_map); + + thermal_zone_device_update(info->tzd, THERMAL_EVENT_TEMP_SAMPLE); + + return IRQ_HANDLED; +} + static int sun4i_gpadc_sample_end(struct sun4i_gpadc_iio *info) { /* Disable the ADC on IP */ @@ -572,12 +595,29 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev, struct nvmem_cell *cell; ssize_t cell_size; u64 *cell_data; + int irq; info->data = of_device_get_match_data(&pdev->dev); if (!info->data) return -ENODEV; - info->no_irq = true; + if (info->data->support_irq) { + /* only the new versions of ths support right now irqs */ + irq = platform_get_irq(pdev, 0); + if (irq < 0) { + dev_err(&pdev->dev, "failed to get IRQ: %d\n", irq); + return irq; + } + + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, + sunxi_irq_thread, IRQF_ONESHOT, + dev_name(&pdev->dev), info); + if (ret) + return ret; + + } else + info->no_irq = true; + indio_dev->num_channels = ARRAY_SIZE(sun8i_a33_gpadc_channels); indio_dev->channels = sun8i_a33_gpadc_channels; @@ -789,11 +829,13 @@ static int sun4i_gpadc_probe(struct platform_device *pdev) if (ret) return ret; - pm_runtime_set_autosuspend_delay(&pdev->dev, - SUN4I_GPADC_AUTOSUSPEND_DELAY); - pm_runtime_use_autosuspend(&pdev->dev); - pm_runtime_set_suspended(&pdev->dev); - pm_runtime_enable(&pdev->dev); + if (!info->data->support_irq) { + pm_runtime_set_autosuspend_delay(&pdev->dev, + SUN4I_GPADC_AUTOSUSPEND_DELAY); + pm_runtime_use_autosuspend(&pdev->dev); + pm_runtime_set_suspended(&pdev->dev); + pm_runtime_enable(&pdev->dev); + } if (IS_ENABLED(CONFIG_THERMAL_OF)) { for (i = 0; i < info->data->sensor_count; i++) { @@ -814,6 +856,9 @@ static int sun4i_gpadc_probe(struct platform_device *pdev) } } + if (info->data->support_irq) + info->data->sample_start(info); + ret = devm_iio_device_register(&pdev->dev, indio_dev); if (ret < 0) { dev_err(&pdev->dev, "could not register the device\n"); @@ -843,6 +888,9 @@ static int sun4i_gpadc_remove(struct platform_device *pdev) if (!IS_ENABLED(CONFIG_THERMAL_OF)) return 0; + if (info->data->support_irq) + info->data->sample_end(info); + thermal_zone_of_sensor_unregister(info->sensor_device, info->tzd); if (!info->no_irq) diff --git a/include/linux/mfd/sun4i-gpadc.h b/include/linux/mfd/sun4i-gpadc.h index 20fa02040007..458f2159a95a 100644 --- a/include/linux/mfd/sun4i-gpadc.h +++ b/include/linux/mfd/sun4i-gpadc.h @@ -91,6 +91,8 @@ #define SUN4I_GPADC_AUTOSUSPEND_DELAY 10000 /* SUNXI_THS COMMON REGISTERS + DEFINES */ +#define SUN8I_H3_THS_INTC 0x44 + #define MAX_SENSOR_COUNT 4 struct sun4i_gpadc_dev {