Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1892847ybv; Fri, 14 Feb 2020 07:49:31 -0800 (PST) X-Google-Smtp-Source: APXvYqwMv2oMSf6/FC2V0muZa2vWB3tdq1PcF3hV6dPBVtSZHk6lQpLJw+q3l+sJcLKvWONJbBbD X-Received: by 2002:a9d:7842:: with SMTP id c2mr2615359otm.252.1581695370912; Fri, 14 Feb 2020 07:49:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581695370; cv=none; d=google.com; s=arc-20160816; b=j0fmI6jKIebqCV9QntEsH3Ekx0NZqEGXdKoLJfeGckte1rKS7gQgICCt00qe+15l6J nT+x6mU/M7ieiL/Ng7CDLv1ssOM2kSAuqVUEAG5h2+I8rxCzkwnVswxN+rinJtbKLKsW w6kCkzCoOJed6XVffP7O5m4Ohaxk8zBZ2ukO0BH5LmMjxyQtDduIDJeGIWvra9EekVvZ Z1BcuuoF2Q07015uvwxuxgJxYqIOHhe8J+FRJLMp2QAVgYsqqkV7hRB6OKw0YbD+K2I7 tBLN52cw+6BDxyxytHvrWjmmtjhu6w2k/8wzN7z5PzOdbZbqtdGakLXghf7XBSGYArlp q63g== 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:subject:cc:to:from:date :dkim-signature; bh=f+VJidMgbilBQLXCaI6f/VQaTRVnV9c0jPq90AZGxQI=; b=A0yJiqywzHDIIUVoRTHrf6QKPTJ02ZBddyLLW2NylE6uuOx7gSxlCBTBejeNBTDZZQ gdlGmbsP8ehPnu6mh4809qkcXOsQ/W+K0DTd84PvEO+fAvJ0y/rXT9+iu2bWvs/6dDBD PrKFBwDLNehI1iC1GIilW7EvG9U8I9jqtBOBEgZJFybF0aOW68BERJtzpcLfoKtjQMjp DWfGS85xwMay3eTZzDvdNKYuUslXg924krzOAOcC5p+HlM9+nX7UBnrutSb/sfnWWX42 5lADkIYXvJdIef7wfyOlup7ITH3w4+pSiTear0bGebryOQFzrCg4DzWAuukRD6CZQLKv rKMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XOlOtbYN; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p13si3004599otq.210.2020.02.14.07.49.18; Fri, 14 Feb 2020 07:49:30 -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=@kernel.org header.s=default header.b=XOlOtbYN; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729688AbgBNPtE (ORCPT + 99 others); Fri, 14 Feb 2020 10:49:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:51334 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729661AbgBNPtC (ORCPT ); Fri, 14 Feb 2020 10:49:02 -0500 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D0E4722314; Fri, 14 Feb 2020 15:49:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581695341; bh=iPSMz9m+b6TUU1rBeRiiINPLup/BJ2uTJt5Gu19G7Ts=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=XOlOtbYN91NTX5WQtG7fSL9pK17AEigsLWFVC3TJd5igmif76Upsz7OR9d8zNfCIF 2NmiiQTvlPqirtxwTVxkMiGH2MdyTFsO+cUV+xGpE52QnnaTFf5Ryzsf7IGvYnkcbV oaKuCWEGKACKRRlJlS1Wfb+UnP1PYFCtRGxLTJRs= Date: Fri, 14 Feb 2020 15:47:48 +0000 From: Jonathan Cameron To: Alexandru Tachici Cc: , Subject: Re: [PATCH v3 2/5] staging: iio: adc: ad7192: modify iio_chan_spec array Message-ID: <20200214154748.3f977906@archlinux> In-Reply-To: <20200212161721.16200-3-alexandru.tachici@analog.com> References: <20200212161721.16200-1-alexandru.tachici@analog.com> <20200212161721.16200-3-alexandru.tachici@analog.com> X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 12 Feb 2020 18:17:18 +0200 Alexandru Tachici wrote: > This patch changes the static const struct iio_chan_spec arrays > in a way that all the necessary attributes are set at > compile time. Now ad7192_channels_config only makes the > channels attribute of iio_dev point to the right array depending > on the chip. > > Signed-off-by: Alexandru Tachici Applied, thanks > --- > drivers/staging/iio/adc/ad7192.c | 112 ++++++++++++++++++------------- > 1 file changed, 66 insertions(+), 46 deletions(-) > > diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c > index 41da8b4cdc48..8fca8915543d 100644 > --- a/drivers/staging/iio/adc/ad7192.c > +++ b/drivers/staging/iio/adc/ad7192.c > @@ -786,73 +786,93 @@ static const struct iio_info ad7195_info = { > .validate_trigger = ad_sd_validate_trigger, > }; > > +#define __AD719x_CHANNEL(_si, _channel1, _channel2, _address, _extend_name, \ > + _type, _mask_type_av, _ext_info) \ > + { \ > + .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 = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ > + BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \ > + .info_mask_shared_by_type_available = (_mask_type_av), \ > + .ext_info = (_ext_info), \ > + .scan_index = (_si), \ > + .scan_type = { \ > + .sign = 'u', \ > + .realbits = 24, \ > + .storagebits = 32, \ > + .endianness = IIO_BE, \ > + }, \ > + } > + > +#define AD719x_DIFF_CHANNEL(_si, _channel1, _channel2, _address) \ > + __AD719x_CHANNEL(_si, _channel1, _channel2, _address, NULL, \ > + IIO_VOLTAGE, BIT(IIO_CHAN_INFO_SCALE), \ > + ad7192_calibsys_ext_info) > + > +#define AD719x_CHANNEL(_si, _channel1, _address) \ > + __AD719x_CHANNEL(_si, _channel1, -1, _address, NULL, IIO_VOLTAGE, \ > + BIT(IIO_CHAN_INFO_SCALE), ad7192_calibsys_ext_info) > + > +#define AD719x_SHORTED_CHANNEL(_si, _channel1, _address) \ > + __AD719x_CHANNEL(_si, _channel1, -1, _address, "shorted", IIO_VOLTAGE, \ > + BIT(IIO_CHAN_INFO_SCALE), ad7192_calibsys_ext_info) > + > +#define AD719x_TEMP_CHANNEL(_si, _address) \ > + __AD719x_CHANNEL(_si, 0, -1, _address, NULL, IIO_TEMP, 0, NULL) > + > static const struct iio_chan_spec ad7192_channels[] = { > - AD_SD_DIFF_CHANNEL(0, 1, 2, AD7192_CH_AIN1P_AIN2M, 24, 32, 0), > - AD_SD_DIFF_CHANNEL(1, 3, 4, AD7192_CH_AIN3P_AIN4M, 24, 32, 0), > - AD_SD_TEMP_CHANNEL(2, AD7192_CH_TEMP, 24, 32, 0), > - AD_SD_SHORTED_CHANNEL(3, 2, AD7192_CH_AIN2P_AIN2M, 24, 32, 0), > - AD_SD_CHANNEL(4, 1, AD7192_CH_AIN1, 24, 32, 0), > - AD_SD_CHANNEL(5, 2, AD7192_CH_AIN2, 24, 32, 0), > - AD_SD_CHANNEL(6, 3, AD7192_CH_AIN3, 24, 32, 0), > - AD_SD_CHANNEL(7, 4, AD7192_CH_AIN4, 24, 32, 0), > + AD719x_DIFF_CHANNEL(0, 1, 2, AD7192_CH_AIN1P_AIN2M), > + AD719x_DIFF_CHANNEL(1, 3, 4, AD7192_CH_AIN3P_AIN4M), > + AD719x_TEMP_CHANNEL(2, AD7192_CH_TEMP), > + AD719x_SHORTED_CHANNEL(3, 2, AD7192_CH_AIN2P_AIN2M), > + AD719x_CHANNEL(4, 1, AD7192_CH_AIN1), > + AD719x_CHANNEL(5, 2, AD7192_CH_AIN2), > + AD719x_CHANNEL(6, 3, AD7192_CH_AIN3), > + AD719x_CHANNEL(7, 4, AD7192_CH_AIN4), > IIO_CHAN_SOFT_TIMESTAMP(8), > }; > > static const struct iio_chan_spec ad7193_channels[] = { > - AD_SD_DIFF_CHANNEL(0, 1, 2, AD7193_CH_AIN1P_AIN2M, 24, 32, 0), > - AD_SD_DIFF_CHANNEL(1, 3, 4, AD7193_CH_AIN3P_AIN4M, 24, 32, 0), > - AD_SD_DIFF_CHANNEL(2, 5, 6, AD7193_CH_AIN5P_AIN6M, 24, 32, 0), > - AD_SD_DIFF_CHANNEL(3, 7, 8, AD7193_CH_AIN7P_AIN8M, 24, 32, 0), > - AD_SD_TEMP_CHANNEL(4, AD7193_CH_TEMP, 24, 32, 0), > - AD_SD_SHORTED_CHANNEL(5, 2, AD7193_CH_AIN2P_AIN2M, 24, 32, 0), > - AD_SD_CHANNEL(6, 1, AD7193_CH_AIN1, 24, 32, 0), > - AD_SD_CHANNEL(7, 2, AD7193_CH_AIN2, 24, 32, 0), > - AD_SD_CHANNEL(8, 3, AD7193_CH_AIN3, 24, 32, 0), > - AD_SD_CHANNEL(9, 4, AD7193_CH_AIN4, 24, 32, 0), > - AD_SD_CHANNEL(10, 5, AD7193_CH_AIN5, 24, 32, 0), > - AD_SD_CHANNEL(11, 6, AD7193_CH_AIN6, 24, 32, 0), > - AD_SD_CHANNEL(12, 7, AD7193_CH_AIN7, 24, 32, 0), > - AD_SD_CHANNEL(13, 8, AD7193_CH_AIN8, 24, 32, 0), > + AD719x_DIFF_CHANNEL(0, 1, 2, AD7193_CH_AIN1P_AIN2M), > + AD719x_DIFF_CHANNEL(1, 3, 4, AD7193_CH_AIN3P_AIN4M), > + AD719x_DIFF_CHANNEL(2, 5, 6, AD7193_CH_AIN5P_AIN6M), > + AD719x_DIFF_CHANNEL(3, 7, 8, AD7193_CH_AIN7P_AIN8M), > + AD719x_TEMP_CHANNEL(4, AD7193_CH_TEMP), > + AD719x_SHORTED_CHANNEL(5, 2, AD7193_CH_AIN2P_AIN2M), > + AD719x_CHANNEL(6, 1, AD7193_CH_AIN1), > + AD719x_CHANNEL(7, 2, AD7193_CH_AIN2), > + AD719x_CHANNEL(8, 3, AD7193_CH_AIN3), > + AD719x_CHANNEL(9, 4, AD7193_CH_AIN4), > + AD719x_CHANNEL(10, 5, AD7193_CH_AIN5), > + AD719x_CHANNEL(11, 6, AD7193_CH_AIN6), > + AD719x_CHANNEL(12, 7, AD7193_CH_AIN7), > + AD719x_CHANNEL(13, 8, AD7193_CH_AIN8), > IIO_CHAN_SOFT_TIMESTAMP(14), > }; > > static int ad7192_channels_config(struct iio_dev *indio_dev) > { > struct ad7192_state *st = iio_priv(indio_dev); > - const struct iio_chan_spec *channels; > - struct iio_chan_spec *chan; > - int i; > > switch (st->devid) { > case ID_AD7193: > - channels = ad7193_channels; > + indio_dev->channels = ad7193_channels; > indio_dev->num_channels = ARRAY_SIZE(ad7193_channels); > break; > default: > - channels = ad7192_channels; > + indio_dev->channels = ad7192_channels; > indio_dev->num_channels = ARRAY_SIZE(ad7192_channels); > break; > } > > - chan = devm_kcalloc(indio_dev->dev.parent, indio_dev->num_channels, > - sizeof(*chan), GFP_KERNEL); > - if (!chan) > - return -ENOMEM; > - > - indio_dev->channels = chan; > - > - for (i = 0; i < indio_dev->num_channels; i++) { > - *chan = channels[i]; > - chan->info_mask_shared_by_all |= > - BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY); > - if (chan->type != IIO_TEMP) { > - chan->info_mask_shared_by_type_available |= > - BIT(IIO_CHAN_INFO_SCALE); > - chan->ext_info = ad7192_calibsys_ext_info; > - } > - chan++; > - } > - > return 0; > } >