From patchwork Thu Aug 30 15:45:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Rossak X-Patchwork-Id: 10582203 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 514BF920 for ; Thu, 30 Aug 2018 16:01:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3CD492C0F5 for ; Thu, 30 Aug 2018 16:01:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F4DC2C0F8; Thu, 30 Aug 2018 16:01:08 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 B55002C0F6 for ; Thu, 30 Aug 2018 16:01:07 +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=yVf7PrwVrAD9n3KyirleTmQEgQFiwhI98QmttNxscI0=; b=lyp9EDrDtqTOhrnKt5w4Wd12xg kfrKzQZ7DL5rLvskzcRiMI3YXRj4j/Od+OHvyomkOwHFrBXVSzZdMAYmBQ56QwSfWTFVh8E+50vrD RwvGIXXxvv0xmvt/xCP4RgL7mjDBR0XDyHY6o8O57khChmudEjZ7qQA9nWovhoJ48IwsSLs2nCQPB 9js1g0GrcpDS3HCGP45ilvZZ9/K66y/+oMfMq76vK2Ct80B7aR1QYMSXmUUDCfGHyTzlf85kCZDhO LcCEQuVurbsxlyBW+LAb6oxGfjdAe3J/g1zto4sTNVuMX0euHb4iw78k6OBuSU6J8de+I7QvxsEFn 0seHeB0Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fvPNT-000319-Kj; Thu, 30 Aug 2018 16:00:59 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fvP8o-0001gl-Tc for linux-arm-kernel@lists.infradead.org; Thu, 30 Aug 2018 15:45:52 +0000 Received: by mail-wr1-x443.google.com with SMTP id u12-v6so8499650wrr.4 for ; Thu, 30 Aug 2018 08:45:40 -0700 (PDT) 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=pQqP9NLkOkVzk7D1LMI8Y+J0UMHbo42I8dLSpZuhXRc=; b=ifjRSj4labF3yu/ZzTuSbrT/tXp0Y94XnTmFsd7hGvpHksuOTJFkstfQyLwsdSeuhg 2cQOsLTCbSQ/peuCBn+Scy3WOGD6UqaEAOfoOFyy6ImZdzy0LMrgYMDLGIZKkcZ426J2 fytPVBhEHAqXxCS9LJdkT7br17YVBn8152BzGmYR7hbvRwVS0KMevexNN3I3XIFUSiKa QgmXIUaFF9bqwtBDZ80VEBYG9mmhI6CLG+A2QdbWAmIM+vVoTZpiGLwvy5HsQavSNFIH CTHaCqDSkjNf6oBEX367tVx3X/lizfdCeNa7ftNg8Aa2J/WAfRJjgvkqJJtJOky876zo fRAg== 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=pQqP9NLkOkVzk7D1LMI8Y+J0UMHbo42I8dLSpZuhXRc=; b=G3L9tGAdj+R+yELmtg90saIDElxSDtTE8N54dlkHYfLiIqE273h9AlIhU+ODW72BTW XBiayCLOdnqBZZEq0PkRt7x74kqWmVIUHLCcsw6tEB5kXhIL0fdA26ayfQnqAcvlZ6Gp byzzw2WbLN8BIZAu3J8eR/pnmKlJGjn0kDCHI6IaqjeABmKRcGYrVoRXlAysDkY/UEdb yW/ytWRMIwPoBO7IoNa/iV4XlsR21On7He5ENFmBJOGEKu2CcArRhUcFICtgJGwFlwHa JHPAknSnpPtd8qsVTPQ/XQ2ZhmjZPLRHQV+Btkmpsxxr6Q5jxApxY2F7Z2ewhzSgkcc8 gqcQ== X-Gm-Message-State: APzg51AeaTw+z2pD6yP8TVAfSAEuGJUUAmucB3f/7w7lw+yRXifPZ+ob Va3bWsp8BizXgdHrRumIyH0= X-Google-Smtp-Source: ANB0VdbPUje7m+TY75vPDhE9sYa/+ktpN26Akzo30ji9NJssK0h+wSx/ea7ItLTibVU6zFY3qvT0gw== X-Received: by 2002:adf:bb41:: with SMTP id x1-v6mr7702826wrg.24.1535643939495; Thu, 30 Aug 2018 08:45:39 -0700 (PDT) Received: from debian-hp.wlan.uni-ulm.de (eduroam170-020.wlan.uni-ulm.de. [134.60.170.20]) by smtp.gmail.com with ESMTPSA id j20-v6sm1362759wmh.9.2018.08.30.08.45.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Aug 2018 08:45:38 -0700 (PDT) From: Philipp Rossak To: lee.jones@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@bootlin.com, wens@csie.org, linux@armlinux.org.uk, jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, eugen.hristev@microchip.com, rdunlap@infradead.org, vilhelm.gray@gmail.com, clabbe.montjoie@gmail.com, quentin.schulz@bootlin.com, geert+renesas@glider.be, lukas@wunner.de, icenowy@aosc.io, arnd@arndb.de, broonie@kernel.org, arnaud.pouliquen@st.com Subject: [PATCH v3 19/30] iio: adc: sun4i-gpadc-iio: rework: support nvmem calibration data Date: Thu, 30 Aug 2018 17:45:07 +0200 Message-Id: <20180830154518.29507-20-embed3d@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180830154518.29507-1-embed3d@gmail.com> References: <20180830154518.29507-1-embed3d@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180830_084551_083537_7A998048 X-CRM114-Status: GOOD ( 15.93 ) 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 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c index 18ab72e52d78..2fd73d143815 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 @@ -70,6 +71,7 @@ struct gpadc_data { bool has_mod_clk; u32 temp_data_base; int sensor_count; + bool supports_nvmem; }; static irqreturn_t sun4i_gpadc_data_irq_handler(int irq, void *dev_id); @@ -146,6 +148,7 @@ struct sun4i_gpadc_iio { struct clk *bus_clk; struct clk *mod_clk; struct reset_control *reset; + u32 calibration_data[2]; }; static const struct iio_chan_spec sun4i_gpadc_channels[] = { @@ -484,6 +487,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; + u32 *cell_data; info->data = of_device_get_match_data(&pdev->dev); if (!info->data) @@ -494,6 +500,24 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev, if (IS_ERR(base)) return PTR_ERR(base); + if (info->data->supports_nvmem) { + + cell = nvmem_cell_get(&pdev->dev, "calibration"); + if (IS_ERR(cell)) { + if (PTR_ERR(cell) == -EPROBE_DEFER) + return PTR_ERR(cell); + } else { + cell_data = (u32 *)nvmem_cell_read(cell, &cell_size); + if (cell_size != 8) + dev_err(&pdev->dev, + "Calibration data has wrong size\n"); + else { + info->calibration_data[0] = cell_data[0]; + info->calibration_data[1] = cell_data[1]; + } + } + } + if (info->data->has_bus_clk) info->regmap = devm_regmap_init_mmio_clk(&pdev->dev, "bus", base, &sun4i_gpadc_regmap_config);