From patchwork Sun Jan 28 23:29:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Rossak X-Patchwork-Id: 10188539 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 C417C6056A for ; Sun, 28 Jan 2018 23:30:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB299286CD for ; Sun, 28 Jan 2018 23:30:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE751286D1; Sun, 28 Jan 2018 23:30:38 +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=ham 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 22B9C286CD for ; Sun, 28 Jan 2018 23:30:38 +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=9Q2vphdvBEPCMUqQ97Oc4sqKNd6WYzrADe3OkzMG0V0=; b=U8faS716Fj6YFjkN5Hqg4tgWzk aCEk2DGcWigPaowmu5tqFE4s/QuqMuJaBJjyEehLyRpabD6E4VlSDRZFVGOuOPkyPJY+3SXULkl46 MbpN8ov80uCikVVVkMhniKq7S4Tvk3yVBcpy9tAoKFx/JUD/QTTnXv3F59smyxYtOru3fghj8GcLd sPqwiEQ7X+PPaI876aR29T11xER9FcncouoGh1NNRStSPOyLSp1BRq8OvKFdVTrAvePpR4AVH7qPg 3BVTjqh8n4IwhOC86Va+BoCO0jv0OjH+t7a9U5U/oYxYCL1MgrMhhOr8TR+7H3XKHaG5e7tG4nMR2 k/Ux7DAw==; 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 1efwPD-0006Qh-Fc; Sun, 28 Jan 2018 23:30:35 +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-0004Jx-MM for linux-arm-kernel@lists.infradead.org; Sun, 28 Jan 2018 23:29:45 +0000 Received: by mail-wr0-x242.google.com with SMTP id s5so5306436wra.0 for ; Sun, 28 Jan 2018 15:29:36 -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=pPYR0Y/nZ79b0A6GeWWZiX8+agY5TWmVCo6sbrC2oR7VUofnwPOL4ehDWkAaVVNiCN 2rNF9GVeINLbfYOsHPx6HdsRBbHNQBBEQLdzB3A0cUwvMcruSo8/d1T5NmYWOAOE/I0i /ylJMGWkBg6IN+ff0jYQ2ql2cG5kKvuYKb0iI5KvCqqdmz9rGUmJjuGqmczdmdgzSef9 2dzVPpOYSvAZIZvkLyqYeAgCl/qm4zFlB7PEHWcNNVp1uDOz1cH+ifX+PHLlUsgl4lBd 9iCCVGG6j45kLTnPEI4x28V/KUXRClz/AXVwaa4vQBp57JlmTd4BelSi2ejHHHJvhI2h R2pQ== X-Gm-Message-State: AKwxytcz/VxpiM21SllX7sv/AenqwUWxE9mdPJ4wzCbxjdwk0ripFTlH 8DfwFkqv2uFlqVhcfk8bDNc= X-Google-Smtp-Source: AH8x226UzoHRlgFU1x0Okdok+Up8FocfjUs4uSuiBhI2kJ1iLU8L/9q0eXC3mBZfyf0HSRr93jhWZw== 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 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> 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 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)) {