Received: by 10.223.176.5 with SMTP id f5csp2365524wra; Sun, 28 Jan 2018 18:59:28 -0800 (PST) X-Google-Smtp-Source: AH8x224nB0mXq8xcbD/sVEplC/Yg1MSLzjDdbM3udu3GOufPzafPYQhS30rhb341sDLJ02+VIaQV X-Received: by 2002:a17:902:b2c1:: with SMTP id x1-v6mr20487956plw.85.1517194768877; Sun, 28 Jan 2018 18:59:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517194768; cv=none; d=google.com; s=arc-20160816; b=0keIC+TBGHp4qR2J/kZspEVe0+dXLEErG8Z6EnwRui9vz0g+n5WYjtsm86p8O3GwVX RzfNMyVXL7xCsDUlEzAUGVN0fau+cgM+Mh2NFJRwy5ak/HNHXjbOl0mP038vV95Wwmji uR3EwAmw3TJwyDT9NT1/SYgOnc1gXDzZUuUS9T063HyjnQg6M8PIbbI6xCzBun49Sf8g z5CUW9J8VTVZbepEcRuCpJ8a2aK0u1JoZZdXIvRal6waA50l3Kz8ZpqO3gZKFGFSz/zs kTD7s6DkBpgocv4rAl6szwzPbjMfJOhJYrMGDN4zFjJ1U3/V7P5kPVusjg4lo1m7RzNr wf/Q== 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=OSiqwjHl+ayBEHixd9QMovfIWoFxwVmHOXyZ2hef6tE=; b=FgIqEc/fOaEM/WF1V1m3O9ksK5KxIL1QInt01AwZR3hkVy0W5RAt013X+uk7IVOVnz e8MILPakXXAY269ICIzKY5KO5B25hsTd8pQIW2dPdEGnhpuQ2/y6oYcdMK8cvN4BTxvi l8LBZLdHAktau7hOuq3L4bdxe9wkbCy6yk82jrM8oU4CmOKmqcy3GlxqtXjJRbePu2oA xnx8pFKdyJZfZ0QkLE8ucE25btUndjEMD3NFQdpDCXcR975hYvmUCixXmEC64NJ6WkIs 1ro29yaysl8c9tK9DoNZvCA8xc828FaWOIIDJs3e3BzPmZsmTXD/OS81PdWf1EoLFUUF u+9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ffoRxOEv; 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 z190si6581125pgb.808.2018.01.28.18.59.14; Sun, 28 Jan 2018 18:59:28 -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=ffoRxOEv; 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 S1753101AbeA1Xca (ORCPT + 99 others); Sun, 28 Jan 2018 18:32:30 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:43129 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752738AbeA1X3h (ORCPT ); Sun, 28 Jan 2018 18:29:37 -0500 Received: by mail-wr0-f195.google.com with SMTP id t16so5282240wrc.10; Sun, 28 Jan 2018 15:29:35 -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=OSiqwjHl+ayBEHixd9QMovfIWoFxwVmHOXyZ2hef6tE=; b=ffoRxOEvIVNK6Xca5rHttauiPUvz+CYj/OhOz0U4x3OPrKf/PuXVYnwdWZCV3dD3DU 6gmdjSFqsqo/rtISeURGSx0wfI54uYbRSZHT4i92mvWevWN8Nqq84SCwMEgBWvPOjcHR 41qve0gHQCQi44ffGc3Ij18h9gNtqDPEdWb+xthFb0cnh9DRdTOGp2DuVyA3tAfEgQex nxkcdjE/8JLVJkhU3LxrpNOr1+TXE8tJEP27+mG8ah/zMVTkBTHrL2QyO5yIFc8UOLnl uvkjrtOD7sgvpN3lRRC74JHxNDXp4mteLBWCAr80afmUk37LvOeGCZxe3cBoKIgK4rKQ SboQ== 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=OSiqwjHl+ayBEHixd9QMovfIWoFxwVmHOXyZ2hef6tE=; b=iOOTaQxdM8r+g39UtmNEDrJlQqqXoGekbTJ7MKNDZRToHYKOyJoYkNsDEhmCFssEqg 2vjFzsirvHoge/X2fv3JDJhE9dcGqUrfgaBB+T0c9xCyDu6PVTRaLTkFHoF5x1ECdVlm 9oKmw5y1NM9J8RmTQzXmkxEehC6y8plIfK9F4emTOeRdCUQ/bvgXMxc7y/6BpzaFzQ1G hj4t70N83cTxeD2NffPynirhRoUUR6+6Fs63R8fr3VGp4MG8gUkeamlC1tXsMubBDrSq N9nF8L+VnRcCWYIfXkZucnPbPgGl0brKzrsGEeuelwou7EojH8Tb9fx+DpMEBLhrkPUG rf5w== X-Gm-Message-State: AKwxytdRQ7hMZIsGmFfC4tu9w5I83v8LwVkYFW5C17KfCIv1rnLQghGJ tjrU+LHNw4z7PwTwX1rkw5A= X-Received: by 10.223.139.214 with SMTP id w22mr1944418wra.186.1517182175344; Sun, 28 Jan 2018 15:29:35 -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.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jan 2018 15:29:34 -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 07/16] iio: adc: sun4i-gpadc-iio: rework: support nvmem calibration data Date: Mon, 29 Jan 2018 00:29:10 +0100 Message-Id: <20180128232919.12639-8-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 reworks the driver to support nvmem calibration cells. The driver checks if the nvmem calibration is supported and reads out the nvmem. Signed-off-by: Philipp Rossak --- drivers/iio/adc/sun4i-gpadc-iio.c | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c index ac9ad2f8232f..74eeb5cd5218 100644 --- a/drivers/iio/adc/sun4i-gpadc-iio.c +++ b/drivers/iio/adc/sun4i-gpadc-iio.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -74,6 +75,7 @@ struct gpadc_data { bool has_bus_rst; bool has_mod_clk; int sensor_count; + bool supports_nvmem; }; static const struct gpadc_data sun4i_gpadc_data = { @@ -87,6 +89,7 @@ static const struct gpadc_data sun4i_gpadc_data = { .sample_start = sun4i_gpadc_sample_start, .sample_end = sun4i_gpadc_sample_end, .sensor_count = 1, + .supports_nvmem = false, }; static const struct gpadc_data sun5i_gpadc_data = { @@ -100,6 +103,7 @@ static const struct gpadc_data sun5i_gpadc_data = { .sample_start = sun4i_gpadc_sample_start, .sample_end = sun4i_gpadc_sample_end, .sensor_count = 1, + .supports_nvmem = false, }; static const struct gpadc_data sun6i_gpadc_data = { @@ -113,6 +117,7 @@ static const struct gpadc_data sun6i_gpadc_data = { .sample_start = sun4i_gpadc_sample_start, .sample_end = sun4i_gpadc_sample_end, .sensor_count = 1, + .supports_nvmem = false, }; static const struct gpadc_data sun8i_a33_gpadc_data = { @@ -123,6 +128,7 @@ static const struct gpadc_data sun8i_a33_gpadc_data = { .sample_start = sun4i_gpadc_sample_start, .sample_end = sun4i_gpadc_sample_end, .sensor_count = 1, + .supports_nvmem = false, }; struct sun4i_gpadc_iio { @@ -141,6 +147,8 @@ struct sun4i_gpadc_iio { struct clk *mod_clk; struct reset_control *reset; int sensor_id; + u32 calibration_data[2]; + bool has_calibration_data[2]; /* prevents concurrent reads of temperature and ADC */ struct mutex mutex; struct thermal_zone_device *tzd; @@ -561,6 +569,9 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev, struct resource *mem; void __iomem *base; int ret; + struct nvmem_cell *cell; + ssize_t cell_size; + u64 *cell_data; info->data = of_device_get_match_data(&pdev->dev); if (!info->data) @@ -575,6 +586,39 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev, if (IS_ERR(base)) return PTR_ERR(base); + info->has_calibration_data[0] = false; + info->has_calibration_data[1] = false; + + if (!info->data->supports_nvmem) + goto no_nvmem; + + cell = nvmem_cell_get(&pdev->dev, "calibration"); + if (IS_ERR(cell)) { + if (PTR_ERR(cell) == -EPROBE_DEFER) + return PTR_ERR(cell); + goto no_nvmem; + } + + cell_data = (u64 *)nvmem_cell_read(cell, &cell_size); + nvmem_cell_put(cell); + switch (cell_size) { + case 8: + case 6: + info->has_calibration_data[1] = true; + info->calibration_data[1] = be32_to_cpu( + upper_32_bits(cell_data[0])); + case 4: + case 2: + info->has_calibration_data[0] = true; + info->calibration_data[0] = be32_to_cpu( + lower_32_bits(cell_data[0])); + break; + default: + break; + } + +no_nvmem: + info->regmap = devm_regmap_init_mmio(&pdev->dev, base, &sun4i_gpadc_regmap_config); if (IS_ERR(info->regmap)) { -- 2.11.0