Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1329356ybv; Thu, 6 Feb 2020 02:06:54 -0800 (PST) X-Google-Smtp-Source: APXvYqzC7hygGOtbiAaemxVNg4B07EMC2op6Z3hVI0PHJ9M+NTbMRU1reGWSfBZaBs7dEb6aznuM X-Received: by 2002:aca:4ace:: with SMTP id x197mr6487993oia.23.1580983614876; Thu, 06 Feb 2020 02:06:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580983614; cv=none; d=google.com; s=arc-20160816; b=R3DM3+z6SsI/7d9eVRARQVYRe+OqaVEDDdWg4NghQkVyXVtEI7WlX3TdMMeUdLR9sr WdFfT+e7Xtfnf8DnU8JYU342xW+MHjdltZFyMLVIiQ6fzQSRLlavPDfEZTooNehQ3aOZ XZeNyxZCucoCtXani46aDQjDn6mgWHy0DCnZ7W9uAsZO85Oy2CaHhEBXbPp9QkRpw1tF /MJ0izB7erBa3zD3bOVX+fdzLz2CwWYLW2iUbyP3u9MI28cvgxgDtHl/3g8udVBXV41V B/9/5BQvk1ZwfgPFm82aCklBcwzZOuYFsf43DxSPVRLUgip/rtnoZB33Ncr2osy4lCVL xBvQ== 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=V2h26CRGGvKD+UFesrwD+LXOipqMaaQmJTd0DkUgVaU=; b=cs6/e8V9Z127otmcEtUN8E04/tz9b/TjHekctjxfNCMN5Dv9iL2MbAxyBZPW7BPLe0 ITQzXj9brn93V/4QQDHZNIojV9equwOCSutb40RhR0egnN16L09PiTUJ2nuUiJNfpZA3 QIDukcgXrWLiyHdC00hLPUVy1pANPJtoTfSVYjsAw3WDOu8JTWo3eZBRy+hBh2flfwec uYkjb/2weI6neEuw+piarPEtDJ9zNxHEuixwjXIxmDdFA1w1vnXzxSjIBlRpYDFaEu93 mm3tkYUKP5P9Y7h9tUja4vGO6nISkXpCOc4YjtXh2YYybO/Y7/59bnK0ocXwF0Vi5Y0F uW5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JhxhdK1c; 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 f23si1573927oti.283.2020.02.06.02.06.40; Thu, 06 Feb 2020 02:06:54 -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=JhxhdK1c; 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 S1728349AbgBFKBY (ORCPT + 99 others); Thu, 6 Feb 2020 05:01:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:36170 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728146AbgBFKBY (ORCPT ); Thu, 6 Feb 2020 05:01:24 -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 6E230214AF; Thu, 6 Feb 2020 10:01:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580983283; bh=At5VW7ePgEnZMtBFcDpO/YmpFI56dpz5ypoLKjKah/I=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=JhxhdK1cVS6pvBV+/q8jFMikQOmDQjbYKfu73XGZwT3X8ryTcbw3NKc1EjvUQeiOA 8t5Nu/Yy+BBY3c5/qfE22LKJ7AS3AZb45cpnqB80BJ2xSP6d90mY5fL1nWHK0B3deZ qjUobCcgYt/i3vOUB9CGcUU4kMXphJSIKMhh8Z7c= Date: Thu, 6 Feb 2020 10:01:19 +0000 From: Jonathan Cameron To: Alexandru Tachici Cc: , Subject: Re: [PATCH 2/5 V2] staging: iio: adc: ad7192: modify iio_chan_spec array Message-ID: <20200206100119.0ad268a2@archlinux> In-Reply-To: <20200205171511.25912-3-alexandru.tachici@analog.com> References: <20200202162215.50915c83@archlinux> <20200205171511.25912-1-alexandru.tachici@analog.com> <20200205171511.25912-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, 5 Feb 2020 19:15:08 +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 Great. Not directly related to this patch, but a question about docs inline. Thanks, Jonathan > --- > 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 4780ddf99b13..8f2fa154876a 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) Just to check, is this one documented? It will result in new ABI afterall. > + > +#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; > } >