Received: by 10.223.176.5 with SMTP id f5csp2364849wra; Sun, 28 Jan 2018 18:58:15 -0800 (PST) X-Google-Smtp-Source: AH8x224J2mycMfRMy3iteRv86tVNosYwpRq07DG5LrJh37XtgmctoyN4erM9fs/jjYRs/Z+BuGG5 X-Received: by 2002:a17:902:2bc5:: with SMTP id l63-v6mr13360535plb.108.1517194695677; Sun, 28 Jan 2018 18:58:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517194695; cv=none; d=google.com; s=arc-20160816; b=ncPtseAE0v+w+H0te1bUh/kH+kkMMvde6mUanp09VZVVri0FkpeBgc0ubYeQIMvPeO vbbxtgkO4d6MA3RbAx8PmptZbF23YMHDMF7d+uQV4BDipeTUlW+84QjM4kwBd/V0hyG8 uu42O78D1rzXcSSXGg/PBtxkZFqe/A0BzD7sagsMxoG/NLPjrOuj2hsuJ8CrEYOR8ZH7 /6wQqbKrxMoEUy9/7oCrfTimlYzEckya9zQGe62w9D8sWcW63XNz6v7KtNmdk0fPHn/C IIz2tTLQvgqNNV7C//ufVz+l7crAI65yQE5C6IqD+IiGQCGTQezbQwFQtFea8Aek8kWU qV4A== 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=xuo+CZOt4GMTWf1HfTsZ70nCAz0D6z2SDpOkmxJBz/A=; b=gG7sMf07PlyADdBaAYH17sPVk6f0yeROPa9bWzDf8V1677IqctkyF+wWesGMlzM1q/ n6c6mLYo+hkq0EITKCee0E3Y00bohDuSm0J7yXmvZ7uFP+8vvpF753NiTRqMFjoKD6gm qXWYEMU3vM8kXdwhFBLP2JRApJx8jdFLxP8haWeVQacMIvf1thnGQMNlaGgv/Pa6ve/Q b6eY3XoWrTZCO+0Ar/IGslBNAgFjb8NMAE1kDDMsn0NR/Ve5GYRdf1TOt8GAFwGbjx1z vvih7oy5dRFMMtlGb//1FaZfL8yHeGK/4qpT570jHt8/JSkexg5Zd/cPmgbgLQYB5QuJ 1P1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uA657wjr; 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 x141si6527088pgx.601.2018.01.28.18.58.01; Sun, 28 Jan 2018 18:58:15 -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=uA657wjr; 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 S1754465AbeA1Xb4 (ORCPT + 99 others); Sun, 28 Jan 2018 18:31:56 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:44981 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752661AbeA1X3l (ORCPT ); Sun, 28 Jan 2018 18:29:41 -0500 Received: by mail-wr0-f194.google.com with SMTP id v31so5281103wrc.11; Sun, 28 Jan 2018 15:29:39 -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=xuo+CZOt4GMTWf1HfTsZ70nCAz0D6z2SDpOkmxJBz/A=; b=uA657wjrrO1mJTa0YUSOrTD/AD6rvfs0Sk6cCWkBwPDpLUI56UOCnPlfbLesPWjAh3 jtdp/bvMjT0A/iVAL243uwJCSeoNx3Kw6TL/sYY3A500M6mFIpFOOaF0NF9knj18LNiy uOUv+62I9/a6r+IwqrBlqztikJ3NT0Dw0CWh7PWzPUu85amo1cpgmhH7U3JDUGcNUewo z0qFIB4rsQg2dsJyC9X1+PZ53h+wz3Cjdu61p6rjTgJPIYjS8bfENbwyskRUwbXk5AQa XWwp1WN1UjbqIgZHQOWGBJxpbQ/s2LXaVCtRf/43zyxA/Rys6fViH0UcmBYBu2++NVQy tlUw== 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=xuo+CZOt4GMTWf1HfTsZ70nCAz0D6z2SDpOkmxJBz/A=; b=By7mD2pC72Pn8gsfVqOkGI92/M76qof8rG6K6QT7ByR1Pu4iV/MmPx3M8sV4d03vEz teqbVovtyOyG4YZ0aed+RyQgb05jbc0o3G5wFUkPk2FutCqvK9ApVE/GEAHXm4RYfP54 aTlTc6itd8mgLxuXb+Xy2ZPCrnCCOxLIGlm1PjNPlY6Z5RR6Bhzx7KZq/q6qvnZ2gjxQ tEZaOPIadgh/uT8M8/0VC90N3Knh10bhHxBbEY/TzARVfYSUt0PIEXvBw85GLFFrUMJB yC6LjuioTFCBIE9XMH447bO6TmN0u9hj7ovyTk5AxgWcEsdZouog/o6nvGBV+AaG7Kjl L18A== X-Gm-Message-State: AKwxytfkZEy22B3hB85NvbQCFwkpyFpzFB8hY+7xQFGV4LU1gEt7hIVr BJvXFJWyYb2cTbqQfMOcSVo= X-Received: by 10.223.192.139 with SMTP id d11mr16474250wrf.260.1517182179069; Sun, 28 Jan 2018 15:29:39 -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.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jan 2018 15:29:38 -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 09/16] iio: adc: sun4i-gpadc-iio: add support for H3 thermal sensor Date: Mon, 29 Jan 2018 00:29:12 +0100 Message-Id: <20180128232919.12639-10-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 adds support for the H3 ths sensor. The H3 supports interrupts. The interrupt is configured to update the the sensor values every second. The calibration data is writen at the begin of the init process. Signed-off-by: Philipp Rossak --- drivers/iio/adc/sun4i-gpadc-iio.c | 86 +++++++++++++++++++++++++++++++++++++++ include/linux/mfd/sun4i-gpadc.h | 22 ++++++++++ 2 files changed, 108 insertions(+) diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c index b7b5451226b0..8196203d65fe 100644 --- a/drivers/iio/adc/sun4i-gpadc-iio.c +++ b/drivers/iio/adc/sun4i-gpadc-iio.c @@ -61,6 +61,9 @@ struct sun4i_gpadc_iio; static int sun4i_gpadc_sample_start(struct sun4i_gpadc_iio *info); static int sun4i_gpadc_sample_end(struct sun4i_gpadc_iio *info); +static int sunxi_ths_sample_start(struct sun4i_gpadc_iio *info); +static int sunxi_ths_sample_end(struct sun4i_gpadc_iio *info); + struct gpadc_data { int temp_offset; int temp_scale; @@ -71,6 +74,10 @@ 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 ctrl0_map; + u32 ctrl2_map; + u32 sensor_en_map; + u32 filter_map; u32 irq_clear_map; u32 irq_control_map; bool has_bus_clk; @@ -138,6 +145,31 @@ static const struct gpadc_data sun8i_a33_gpadc_data = { .support_irq = false, }; +static const struct gpadc_data sun8i_h3_ths_data = { + .temp_offset = -1791, + .temp_scale = -121, + .temp_data = {SUN8I_H3_THS_TDATA0, 0, 0, 0}, + .sample_start = sunxi_ths_sample_start, + .sample_end = sunxi_ths_sample_end, + .has_bus_clk = true, + .has_bus_rst = true, + .has_mod_clk = true, + .sensor_count = 1, + .supports_nvmem = true, + .support_irq = true, + .ctrl0_map = SUN4I_GPADC_CTRL0_T_ACQ(0xff), + .ctrl2_map = SUN8I_H3_THS_ACQ1(0x3f), + .sensor_en_map = SUN8I_H3_THS_TEMP_SENSE_EN0, + .filter_map = SUN4I_GPADC_CTRL3_FILTER_EN | + SUN4I_GPADC_CTRL3_FILTER_TYPE(0x2), + .irq_clear_map = SUN8I_H3_THS_INTS_ALARM_INT_0 | + SUN8I_H3_THS_INTS_SHUT_INT_0 | + SUN8I_H3_THS_INTS_TDATA_IRQ_0 | + SUN8I_H3_THS_INTS_ALARM_OFF_0, + .irq_control_map = SUN8I_H3_THS_INTC_TDATA_IRQ_EN0 | + SUN8I_H3_THS_TEMP_PERIOD(0x7), +}; + struct sun4i_gpadc_iio { struct iio_dev *indio_dev; struct completion completion; @@ -462,6 +494,16 @@ static int sun4i_gpadc_sample_end(struct sun4i_gpadc_iio *info) return 0; } +static int sunxi_ths_sample_end(struct sun4i_gpadc_iio *info) +{ + /* Disable ths interrupt */ + regmap_write(info->regmap, SUN8I_H3_THS_INTC, 0x0); + /* Disable temperature sensor */ + regmap_write(info->regmap, SUN8I_H3_THS_CTRL2, 0x0); + + return 0; +} + static int sun4i_gpadc_runtime_suspend(struct device *dev) { struct sun4i_gpadc_iio *info = iio_priv(dev_get_drvdata(dev)); @@ -473,6 +515,17 @@ static int sun4i_gpadc_runtime_suspend(struct device *dev) return info->data->sample_end(info); } +static void sunxi_calibrate(struct sun4i_gpadc_iio *info) +{ + if (info->has_calibration_data[0]) + regmap_write(info->regmap, SUNXI_THS_CDATA_0_1, + info->calibration_data[0]); + + if (info->has_calibration_data[1]) + regmap_write(info->regmap, SUNXI_THS_CDATA_2_3, + info->calibration_data[1]); +} + static int sun4i_gpadc_sample_start(struct sun4i_gpadc_iio *info) { /* clkin = 6MHz */ @@ -492,6 +545,35 @@ static int sun4i_gpadc_sample_start(struct sun4i_gpadc_iio *info) return 0; } +static int sunxi_ths_sample_start(struct sun4i_gpadc_iio *info) +{ + u32 value; + sunxi_calibrate(info); + + if (info->data->ctrl0_map) + regmap_write(info->regmap, SUN8I_H3_THS_CTRL0, + info->data->ctrl0_map); + + regmap_write(info->regmap, SUN8I_H3_THS_CTRL2, + info->data->ctrl2_map); + + regmap_write(info->regmap, SUN8I_H3_THS_STAT, + info->data->irq_clear_map); + + regmap_write(info->regmap, SUN8I_H3_THS_FILTER, + info->data->filter_map); + + regmap_write(info->regmap, SUN8I_H3_THS_INTC, + info->data->irq_control_map); + + regmap_read(info->regmap, SUN8I_H3_THS_CTRL2, &value); + + regmap_write(info->regmap, SUN8I_H3_THS_CTRL2, + info->data->sensor_en_map | value); + + return 0; +} + static int sun4i_gpadc_runtime_resume(struct device *dev) { struct sun4i_gpadc_iio *info = iio_priv(dev_get_drvdata(dev)); @@ -582,6 +664,10 @@ static const struct of_device_id sun4i_gpadc_of_id[] = { .compatible = "allwinner,sun8i-a33-ths", .data = &sun8i_a33_gpadc_data, }, + { + .compatible = "allwinner,sun8i-h3-ths", + .data = &sun8i_h3_ths_data, + }, { /* sentinel */ } }; diff --git a/include/linux/mfd/sun4i-gpadc.h b/include/linux/mfd/sun4i-gpadc.h index 458f2159a95a..80b79c31cea3 100644 --- a/include/linux/mfd/sun4i-gpadc.h +++ b/include/linux/mfd/sun4i-gpadc.h @@ -91,7 +91,29 @@ #define SUN4I_GPADC_AUTOSUSPEND_DELAY 10000 /* SUNXI_THS COMMON REGISTERS + DEFINES */ +#define SUN8I_H3_THS_CTRL0 0x00 +#define SUN8I_H3_THS_CTRL2 0x40 #define SUN8I_H3_THS_INTC 0x44 +#define SUN8I_H3_THS_STAT 0x48 +#define SUN8I_H3_THS_FILTER 0x70 +#define SUNXI_THS_CDATA_0_1 0x74 +#define SUNXI_THS_CDATA_2_3 0x78 +#define SUN8I_H3_THS_TDATA0 0x80 + +#define SUN8I_H3_THS_ACQ1(x) (GENMASK(31, 16) & ((x) << 16)) + +#define SUN8I_H3_THS_TEMP_SENSE_EN0 BIT(0) + +#define SUN8I_H3_THS_TEMP_PERIOD(x) (GENMASK(31, 12) & ((x) << 12)) + +#define SUN8I_H3_THS_INTS_ALARM_INT_0 BIT(0) +#define SUN8I_H3_THS_INTS_SHUT_INT_0 BIT(4) +#define SUN8I_H3_THS_INTS_TDATA_IRQ_0 BIT(8) +#define SUN8I_H3_THS_INTS_ALARM_OFF_0 BIT(12) + +#define SUN8I_H3_THS_INTC_ALARM_INT_EN0 BIT(0) +#define SUN8I_H3_THS_INTC_SHUT_INT_EN0 BIT(4) +#define SUN8I_H3_THS_INTC_TDATA_IRQ_EN0 BIT(8) #define MAX_SENSOR_COUNT 4 -- 2.11.0