Received: by 10.223.176.5 with SMTP id f5csp2364143wra; Sun, 28 Jan 2018 18:57:03 -0800 (PST) X-Google-Smtp-Source: AH8x224zhIqh/y+m0Lk0bCfXmrbKqt/5U2jEF4ET8je3t7hTuulBYyMPtKRZPijIaK305flG7Lvx X-Received: by 10.99.4.198 with SMTP id 189mr20918737pge.210.1517194622893; Sun, 28 Jan 2018 18:57:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517194622; cv=none; d=google.com; s=arc-20160816; b=oOBW4O0y1+4mz1klNS9+1VbQIIxiTd2yPxzyDlQxKBNrom90R7WF2zxl45cJnK8jGU AIvJ2ruxWbS/SBox7W8plF5WrbGevKoP+HtaEt1uLQyUneUrbOzEVxC4eJy9l38nqlPK MRdaC+d2aBJ68qdbH/IhhrkP1fSwGoAJGkEfCOnFFpr2djUhL9hIHYei3qD+VjjdRvrn lUBtLIXIZ7BMjy+0LuKXkm9D86MWKfbn8SKeLyFJ6uZqlgqSvTh2z6eAoZ+TGMw6xUlh uUlxEg4WRtvigF+ETxFjxVu0XXOczq+dhNuRw0wl84LhMA/yadlRCHT6CUE7BggQCiCX D3IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=0fB9keSrkLUbGLRmQj6r7CeTeR3Nyvvo0htxNWYxU90=; b=gG0Zng5NdBESbDh8CICPN3RMD4awlnLPwSd9BVXhN1VZJ/uFWpQWrvr8ig9Xu704/A /1Hjc/EFTdTAI76xctgvYXjPneJJlvL2NlQjExvJAlu/g/0gsFzpDLssBmordhbM0iZc 6HVF0X317PQpi1f8nO/VdcKLCGM51eqTVXRvWRFAfemJ7+UTQ+IUgUWECKbcgWoR74oJ zbEhwLNc12GTz2u55uiZTK8zBxn4BBKWAEABNkqoP8y87Mehhxa3Rxd6ehbYB7ZIeFq2 v3mWkbmo7uRJpP37K8kR5dtFRe+o6OSvO2I4T6lbreOnjZOGf+TIJRzBqhajzrccaAY/ fbiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rSTSskoe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 30-v6si8221218plc.548.2018.01.28.18.56.49; Sun, 28 Jan 2018 18:57:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rSTSskoe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753543AbeA1X3o (ORCPT + 99 others); Sun, 28 Jan 2018 18:29:44 -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-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 { -- 2.11.0