From patchwork Mon Sep 24 22:13:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10612903 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 53BE3112B for ; Mon, 24 Sep 2018 22:13:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4653A297C4 for ; Mon, 24 Sep 2018 22:13:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3ABD6297F2; Mon, 24 Sep 2018 22:13:35 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B6085297C4 for ; Mon, 24 Sep 2018 22:13:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727570AbeIYERz (ORCPT ); Tue, 25 Sep 2018 00:17:55 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:54084 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725743AbeIYERz (ORCPT ); Tue, 25 Sep 2018 00:17:55 -0400 Received: by mail-wm1-f67.google.com with SMTP id b19-v6so11300346wme.3 for ; Mon, 24 Sep 2018 15:13:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7ho9deNcXvRLN1dQAk7CXtq6XRP5w/ndcy9kHDIlozc=; b=BWThFenkgyEGDUsp26CT+IVHXhNtis0dDm2jzvtB/KtFEBdvhOBrZAtmU4TIoNJJ3x NtTGcGP7TL6TCtAzK5WbYRKghXu4j8U7s5nAzarzRIsBSGXx7aTjy+AMMLWOW1eMU7pj lZfqjlO0HuB5APFkZSueGZ1owyvV8JG0V2Ex+c8Nt5dPwmxOtOXBfqqelOw0wtZ8n15i MCv2TQ9OFDyluq304TYMfsgsfuJqEjCN3YIoSgeq/etQiBnW0yOk142IDBsvKlE2cWZs 2Q9XM/2VX/mDEhQlNt/9IaJrMA4Z36lhn6ibf5qXp/TkzsquOKmokxBvZ/1f2fTOVXO7 y0NA== 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:mime-version:content-transfer-encoding; bh=7ho9deNcXvRLN1dQAk7CXtq6XRP5w/ndcy9kHDIlozc=; b=jBt2WkDBuI5pPXbxILK6XNc5lfx9RrzHZrhZkOomCmbwNh9X+zmqTAc8k80+1iKeMX NJ7rl0NMGODdTV9h/KmIr9HOfs3O5hzGaUaeujw0f9K38fMyGDHExld5iZuIlnuxQMIm aAYiYWA6bu/6qv9DIjXSKLs2ag/fnw4LNE7nRl3mnKKVLMDyyAKZvociDTmvMIOvGOoC HGqF234+TaIohFlY+fpfBHb93C5RGtGDKdGW4ZgMR0P+yVDSSX9x9Y+aGSTGJ4AOcJMU XoZkBnhheso6zvMEInCsIcg+dq/lRZH8G2giE4b8aVTKkJIRFH3a0HHG6PUlilrgiH34 9gng== X-Gm-Message-State: ABuFfoheFyHxy1PW5sXH+iNbuEmlzb7J9lTuMbano6Emfcz1qcfYA9AE Qj8xG7Nb5o9/6jLPa/sXIq4= X-Google-Smtp-Source: ACcGV62fXXQS3wGee87g4da35q6IgPIjl0YWtiuh0bbeITMoMgJgBKqCbohvsDRgck4P9xFeS/h/cQ== X-Received: by 2002:a1c:f11a:: with SMTP id p26-v6mr239970wmh.92.1537827211545; Mon, 24 Sep 2018 15:13:31 -0700 (PDT) Received: from blackbox.darklights.net (p200300DCD74AC3003CB4EEA9EBE1F156.dip0.t-ipconnect.de. [2003:dc:d74a:c300:3cb4:eea9:ebe1:f156]) by smtp.googlemail.com with ESMTPSA id 139-v6sm464742wmp.4.2018.09.24.15.13.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Sep 2018 15:13:30 -0700 (PDT) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, linux-iio@vger.kernel.org Cc: jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, Martin Blumenstingl Subject: [PATCH 2/2] iio: adc: meson-saradc: use the address attribute from iio_chan_spec Date: Tue, 25 Sep 2018 00:13:26 +0200 Message-Id: <20180924221326.2871-3-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180924221326.2871-1-martin.blumenstingl@googlemail.com> References: <20180924221326.2871-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Until now the "channel" number is identical to how the channel is identified inside the (FIFO) registers. In our case we have eight channels and the hardware also has eight inputs. However, there are two special inputs: - channel 6 can select between the SAR_ADC_CH6 pad and the chip's internal temperature sensor - channel 7 can select between SAR_ADC_CH7 and VSS, VDD / 4, VDD / 2, VDD * 3 / 4 and VDD. When programming the registers to read for example the temperature sensor we have to select FIFO channel 6, set the correct bit which muxes channel 6 to the temperature sensor and then start the ADC measurement for channel 6 as usual. When we add support for the temperature sensor the driver has to know about that it has to use FIFO channel 6 to measure using the chip's internal temperature sensor. However, in that case the iio_chan_spec channel will not be 6 because this is already used for the SAR_ADC_CH6 pad input. Thus we use iio_chan_spec's address field to store the FIFO channel number for each channel. Signed-off-by: Martin Blumenstingl --- drivers/iio/adc/meson_saradc.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c index 809d1230be34..028ccd218f82 100644 --- a/drivers/iio/adc/meson_saradc.c +++ b/drivers/iio/adc/meson_saradc.c @@ -172,6 +172,7 @@ .type = IIO_VOLTAGE, \ .indexed = 1, \ .channel = _chan, \ + .address = _chan, \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ BIT(IIO_CHAN_INFO_AVERAGE_RAW), \ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ @@ -323,10 +324,10 @@ static int meson_sar_adc_read_raw_sample(struct iio_dev *indio_dev, regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, ®val); fifo_chan = FIELD_GET(MESON_SAR_ADC_FIFO_RD_CHAN_ID_MASK, regval); - if (fifo_chan != chan->channel) { + if (fifo_chan != chan->address) { dev_err(&indio_dev->dev, - "ADC FIFO entry belongs to channel %d instead of %d\n", - fifo_chan, chan->channel); + "ADC FIFO entry belongs to channel %d instead of %lu\n", + fifo_chan, chan->address); return -EINVAL; } @@ -343,16 +344,16 @@ static void meson_sar_adc_set_averaging(struct iio_dev *indio_dev, enum meson_sar_adc_num_samples samples) { struct meson_sar_adc_priv *priv = iio_priv(indio_dev); - int val, channel = chan->channel; + int val, address = chan->address; - val = samples << MESON_SAR_ADC_AVG_CNTL_NUM_SAMPLES_SHIFT(channel); + val = samples << MESON_SAR_ADC_AVG_CNTL_NUM_SAMPLES_SHIFT(address); regmap_update_bits(priv->regmap, MESON_SAR_ADC_AVG_CNTL, - MESON_SAR_ADC_AVG_CNTL_NUM_SAMPLES_MASK(channel), + MESON_SAR_ADC_AVG_CNTL_NUM_SAMPLES_MASK(address), val); - val = mode << MESON_SAR_ADC_AVG_CNTL_AVG_MODE_SHIFT(channel); + val = mode << MESON_SAR_ADC_AVG_CNTL_AVG_MODE_SHIFT(address); regmap_update_bits(priv->regmap, MESON_SAR_ADC_AVG_CNTL, - MESON_SAR_ADC_AVG_CNTL_AVG_MODE_MASK(channel), val); + MESON_SAR_ADC_AVG_CNTL_AVG_MODE_MASK(address), val); } static void meson_sar_adc_enable_channel(struct iio_dev *indio_dev, @@ -372,23 +373,23 @@ static void meson_sar_adc_enable_channel(struct iio_dev *indio_dev, /* map channel index 0 to the channel which we want to read */ regval = FIELD_PREP(MESON_SAR_ADC_CHAN_LIST_ENTRY_MASK(0), - chan->channel); + chan->address); regmap_update_bits(priv->regmap, MESON_SAR_ADC_CHAN_LIST, MESON_SAR_ADC_CHAN_LIST_ENTRY_MASK(0), regval); regval = FIELD_PREP(MESON_SAR_ADC_DETECT_IDLE_SW_DETECT_MUX_MASK, - chan->channel); + chan->address); regmap_update_bits(priv->regmap, MESON_SAR_ADC_DETECT_IDLE_SW, MESON_SAR_ADC_DETECT_IDLE_SW_DETECT_MUX_MASK, regval); regval = FIELD_PREP(MESON_SAR_ADC_DETECT_IDLE_SW_IDLE_MUX_SEL_MASK, - chan->channel); + chan->address); regmap_update_bits(priv->regmap, MESON_SAR_ADC_DETECT_IDLE_SW, MESON_SAR_ADC_DETECT_IDLE_SW_IDLE_MUX_SEL_MASK, regval); - if (chan->channel == 6) + if (chan->address == 6) regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELTA_10, MESON_SAR_ADC_DELTA_10_TEMP_SEL, 0); } @@ -526,8 +527,8 @@ static int meson_sar_adc_get_sample(struct iio_dev *indio_dev, if (ret) { dev_warn(indio_dev->dev.parent, - "failed to read sample for channel %d: %d\n", - chan->channel, ret); + "failed to read sample for channel %lu: %d\n", + chan->address, ret); return ret; }