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: 10188567 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 4101D60383 for ; Sun, 28 Jan 2018 23:31:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39758286CD for ; Sun, 28 Jan 2018 23:31:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D7E9286D2; Sun, 28 Jan 2018 23:31:31 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8BEFB286CD for ; Sun, 28 Jan 2018 23:31:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753489AbeA1X3n (ORCPT ); Sun, 28 Jan 2018 18:29:43 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:46747 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752759AbeA1X3i (ORCPT ); Sun, 28 Jan 2018 18:29:38 -0500 Received: by mail-wr0-f196.google.com with SMTP id g21so5272490wrb.13; Sun, 28 Jan 2018 15:29:37 -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=JDrQofTXuR65S63dNC2bXnRxARla4DqMmLhw7ttwi4qQcVdnigRjNFvw+nHF/8Qi0t QFNLOaCYcT5GmgUTBpqNXbtNK9xZ1BHs54iyBGXPo7BzKzOxX8Qj0JjKm2iSQ4IhVl1m MvlIcuQiA/iVnizUqgB+FmvmIixwDAqL/G1j0lpP+B8fUTkZnJxMeOq2lZK3RAp9KEEt j6I1SiCGt22P8c0qDcp9KYN7FzxePpA49f7Ch7S1ZMPWYPwF8KSD+LfVFmRxAfQnWOWn o/KOv3ASUrl242L4Ufu5FtS4OwLGKuqM8cf0/3C41oiVj6BXlusZBl/Jqifa1ke05rZP 9fOw== X-Gm-Message-State: AKwxytfc4RuoAi1MRkeVsN3y3D25Y/hNSq2ERz1SipAub4eYfkNh88tG sIXMBOKaJRh7EMW3+bynYd4= 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 Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.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> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.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 {