Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp645238ybh; Wed, 18 Mar 2020 06:38:15 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuss34PiaEM/LX4wUmUAnga7xTHmqAcF8goqlPpRTXHUWXH1i8QJx1f+dPnAXVUJrKet9DK X-Received: by 2002:aca:4444:: with SMTP id r65mr3260767oia.76.1584538695499; Wed, 18 Mar 2020 06:38:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584538695; cv=none; d=google.com; s=arc-20160816; b=AGNIO+VErq3rjO/kZHGu5J5pJZ5B2v1wGqarWb7QVURCn/EXc+PO5MfZPTteBMJ91h 27nfL1RCxNsTeeeX8W9Ote/9zoLbUI75DWpsFa8qfBxMN8lgUacP0uo9nU4qrb3rG7ZX 0CHU7Fvlz9UO/lqQgRMtcaolumX7poJASbKpZxggfOnYKBZ4oFqTJqNNrSdSkjxqXzVI mhroSLgtaUxXdMCMPpRjmctkGK6zX+1kINSK3ihk4qkfbBplGA1hd7PbewHFl4n5HrNH r1UYqFX4S+PkMOGF+RdvQ8OYwcP1NX8UhLgQCoJbWRhDMV2Czcj5HqKjgHSRSYej+7hM 1tXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=O3t2fRa2PJe34Peod55apFClQDGZv5u9o9GW8ycI9VA=; b=CamZ1UgRqwmcZkpL+XJvHsdZTPztvjvWCGBDRgKs1KmgpQUe8pcKxCxI+MV+MjuWCT pDrlTivFn5E0zN/jsW8+DVxGb1JEP1XZHuT9w0G9W+9so1emIu33KMObzCmGjNGXK6VX 5yQX5M3CLarrro7+nXQhnuAsKYN/1CYK8htXGs3w6e6xZQN0mx5eIkPLLmscB+u2LIJR kfOLhkjmageiuxGly5F9GwpKLvUXUTFRj2LWW94EHdBD0AeYllqrNyiT6MM1n0CoraEd WcuURyS8og7VFr2BJclHrHyi1Rh2qAyiCl5NLEtYMWX4CkkZH/jtJesGr5l1NNcIBsEr 5fjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Z1MxHCUG; 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=QUARANTINE 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 v142si3434654oie.217.2020.03.18.06.38.04; Wed, 18 Mar 2020 06:38:15 -0700 (PDT) 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=Z1MxHCUG; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727056AbgCRNhk (ORCPT + 99 others); Wed, 18 Mar 2020 09:37:40 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:35673 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727024AbgCRNhi (ORCPT ); Wed, 18 Mar 2020 09:37:38 -0400 Received: by mail-wm1-f65.google.com with SMTP id m3so3408719wmi.0; Wed, 18 Mar 2020 06:37:37 -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 :mime-version:content-transfer-encoding; bh=O3t2fRa2PJe34Peod55apFClQDGZv5u9o9GW8ycI9VA=; b=Z1MxHCUG7EwfhY5eR75sRxLc8oEd2odfeRlFX++H4ApBql1MNNQrNqBv15ybNQSkLz L80V4D+N8TgqpHHO1AnZH7QLUN0XJFPIps1LS9Z/5aSn90pTwD71vTiiGgLMiwOhaVNl H6KuXqn7fg5NYPzpwFtmE1dt2MWwqpWhg1DQN5c+m/urPTBlZmOix2qsbGdQsnS7OaIy qqd2TZMAalB7UNZR8fp9Yxm1lNKG2VAF7lP33Y2y2AAoDf+luGeuq4hwPWS6ePamcxvn MfJ0oYEyCyaQJgoEPVl9Q25JtSRTLjEQ959l1MwSdAdZwU3eWa4acbKAYfe5b5ZrdPYO ZnCQ== 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=O3t2fRa2PJe34Peod55apFClQDGZv5u9o9GW8ycI9VA=; b=bsesBzSpT3TVhFg4hZwPZxL8BOLrZbOPlAd1hudk+H/yXK23BzetDqK23n+rT9Cefs zbI/6T+0zREc+/WLgLeHreN4USq1C08DMjq0dyW4xANLLamJGSEO3/9mzIaH3JPcu5zr ZGtxkWS1+KP1IZQbe+QwmM97Q3OD2yEYZ5X0Y2B/NhouRY7YJIZoawFz2EhB4fI4rfkh ecnj6pBQwrL3fNno4DL7b8uHmpRE3ndckk39KyI5WljJbcxGHDY4lA7QAlVix1MFZfjA B1IzRf1YCozqdR91IcAkR/qRgUo2sBYk+n4K8jZ77O6pZuxT+LXMHFouXWwzFdKqbZjl kPbw== X-Gm-Message-State: ANhLgQ0Fn2V5JmCqtvYQbGrx7g7vxFolb9DCxsE5pZxi+qY1d5u/NYfQ F5M0hWfca45wwLSHGPkvLOVNnLaM X-Received: by 2002:a1c:23c8:: with SMTP id j191mr3719141wmj.117.1584538656208; Wed, 18 Mar 2020 06:37:36 -0700 (PDT) Received: from saturn.lan ([188.26.73.247]) by smtp.gmail.com with ESMTPSA id f15sm9444002wru.83.2020.03.18.06.37.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2020 06:37:35 -0700 (PDT) From: Alexandru Ardelean X-Google-Original-From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Michael.Hennerich@analog.com, renatogeh@gmail.com, lars@metafoo.de, jic23@kernel.org, mircea.caprioru@analog.com, Alexandru Ardelean Subject: [PATCH 2/5] iio: adc: ad7791: define/use own IIO channel macros Date: Wed, 18 Mar 2020 15:40:39 +0200 Message-Id: <20200318134042.30133-3-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200318134042.30133-1-alexandru.ardelean@analog.com> References: <20200318134042.30133-1-alexandru.ardelean@analog.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This driver seems to use most of the AD_SD_*_CHANNEL. This change will move them in the driver. The intent is that if a new part comes along which would require tweaks per IIO channel, these should be doable in the driver. Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7791.c | 62 +++++++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 7 deletions(-) diff --git a/drivers/iio/adc/ad7791.c b/drivers/iio/adc/ad7791.c index abb239392631..ba22808507d0 100644 --- a/drivers/iio/adc/ad7791.c +++ b/drivers/iio/adc/ad7791.c @@ -64,25 +64,73 @@ #define AD7791_MODE_SEL_MASK (0x3 << 6) #define AD7791_MODE_SEL(x) ((x) << 6) +#define __AD7991_CHANNEL(_si, _channel1, _channel2, _address, _bits, \ + _storagebits, _shift, _extend_name, _type, _mask_all) \ + { \ + .type = (_type), \ + .differential = (_channel2 == -1 ? 0 : 1), \ + .indexed = 1, \ + .channel = (_channel1), \ + .channel2 = (_channel2), \ + .address = (_address), \ + .extend_name = (_extend_name), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_OFFSET), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_all = _mask_all, \ + .scan_index = (_si), \ + .scan_type = { \ + .sign = 'u', \ + .realbits = (_bits), \ + .storagebits = (_storagebits), \ + .shift = (_shift), \ + .endianness = IIO_BE, \ + }, \ + } + +#define AD7991_SHORTED_CHANNEL(_si, _channel, _address, _bits, \ + _storagebits, _shift) \ + __AD7991_CHANNEL(_si, _channel, _channel, _address, _bits, \ + _storagebits, _shift, "shorted", IIO_VOLTAGE, \ + BIT(IIO_CHAN_INFO_SAMP_FREQ)) + +#define AD7991_CHANNEL(_si, _channel, _address, _bits, \ + _storagebits, _shift) \ + __AD7991_CHANNEL(_si, _channel, -1, _address, _bits, \ + _storagebits, _shift, NULL, IIO_VOLTAGE, \ + BIT(IIO_CHAN_INFO_SAMP_FREQ)) + +#define AD7991_DIFF_CHANNEL(_si, _channel1, _channel2, _address, _bits, \ + _storagebits, _shift) \ + __AD7991_CHANNEL(_si, _channel1, _channel2, _address, _bits, \ + _storagebits, _shift, NULL, IIO_VOLTAGE, \ + BIT(IIO_CHAN_INFO_SAMP_FREQ)) + +#define AD7991_SUPPLY_CHANNEL(_si, _channel, _address, _bits, _storagebits, \ + _shift) \ + __AD7991_CHANNEL(_si, _channel, -1, _address, _bits, \ + _storagebits, _shift, "supply", IIO_VOLTAGE, \ + BIT(IIO_CHAN_INFO_SAMP_FREQ)) + #define DECLARE_AD7787_CHANNELS(name, bits, storagebits) \ const struct iio_chan_spec name[] = { \ - AD_SD_DIFF_CHANNEL(0, 0, 0, AD7791_CH_AIN1P_AIN1N, \ + AD7991_DIFF_CHANNEL(0, 0, 0, AD7791_CH_AIN1P_AIN1N, \ (bits), (storagebits), 0), \ - AD_SD_CHANNEL(1, 1, AD7791_CH_AIN2, (bits), (storagebits), 0), \ - AD_SD_SHORTED_CHANNEL(2, 0, AD7791_CH_AIN1N_AIN1N, \ + AD7991_CHANNEL(1, 1, AD7791_CH_AIN2, (bits), (storagebits), 0), \ + AD7991_SHORTED_CHANNEL(2, 0, AD7791_CH_AIN1N_AIN1N, \ (bits), (storagebits), 0), \ - AD_SD_SUPPLY_CHANNEL(3, 2, AD7791_CH_AVDD_MONITOR, \ + AD7991_SUPPLY_CHANNEL(3, 2, AD7791_CH_AVDD_MONITOR, \ (bits), (storagebits), 0), \ IIO_CHAN_SOFT_TIMESTAMP(4), \ } #define DECLARE_AD7791_CHANNELS(name, bits, storagebits) \ const struct iio_chan_spec name[] = { \ - AD_SD_DIFF_CHANNEL(0, 0, 0, AD7791_CH_AIN1P_AIN1N, \ + AD7991_DIFF_CHANNEL(0, 0, 0, AD7791_CH_AIN1P_AIN1N, \ (bits), (storagebits), 0), \ - AD_SD_SHORTED_CHANNEL(1, 0, AD7791_CH_AIN1N_AIN1N, \ + AD7991_SHORTED_CHANNEL(1, 0, AD7791_CH_AIN1N_AIN1N, \ (bits), (storagebits), 0), \ - AD_SD_SUPPLY_CHANNEL(2, 1, AD7791_CH_AVDD_MONITOR, \ + AD7991_SUPPLY_CHANNEL(2, 1, AD7791_CH_AVDD_MONITOR, \ (bits), (storagebits), 0), \ IIO_CHAN_SOFT_TIMESTAMP(3), \ } -- 2.20.1