Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3730990imm; Sat, 25 Aug 2018 01:20:57 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY7e573ZOcJ4vlG/InjDqSXRmcA7Izaa6CoyPf2RC/ysZZMCXXxFj3scme692Y5UwhR0kid X-Received: by 2002:a63:ad07:: with SMTP id g7-v6mr4907821pgf.19.1535185257181; Sat, 25 Aug 2018 01:20:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535185257; cv=none; d=google.com; s=arc-20160816; b=u6ZoDLiAQ1DDIbYwNfqa9NTqmqY9q1rQc9gg94PUpcTW7BQOUd9cg2xn/eHgpTtyUd w5vqgd40tPpWWIWx2WIWvCqocqYtlV+mD+cYdrRa7KWyb8z8yV5XollmB1IQFBVhVKe+ EUJf2hA9/SagDLi4buHtuJu5duARRtp3eSrBCu6LwtqH9QImBZsKvMkyV+J3SJiCxfz0 WDoPQsxhjcxXLX6ec5hzPNpmRle7oztsp5c1ynwTtXCBeNFXDV7ryHOQPB59+fX947pM F8gQS1LoDUn1o162ZDM8P50csQMKx449a0+fA0yDCqZ0DMQsGr+r8kxyrezYLjlk+ypn t4pg== 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:arc-authentication-results; bh=DJ6rH5+e7givDF7QslOudQk8fUW5HYuaalfX9U5gWtg=; b=Sy0uPMNV413FGlUTJU/meKV/lsptl+d6T2GjvUfLDOox00+ddz5+50HEmIzJIciPgL VTLImh7rlu9kv38K/8gLBMbwvuO6xspWiu5po0A4aO31N3dtJSjz6SH4c181BCFBdWye 1lZokzFrJDwcZEqw4Xl0GAHDY7VncTplbsyCQzhqIty8Z4Ky9Cub4am3+vOt7SlnakOA hKBTD7+14TWhVAnw2Smrs3YmNmMgllSU/xIPR/pVua2lRSmbiQ2WcPIvqHUP4d3wCHos hZ1/VKc7/KUeJLf8lBG0LWv/PInj5O8c9KWbv2Nf7HoJWO2P2QeRkpDenhkHPJIJtn/2 LGKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0iKN3HuR; 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 3-v6si9174388plv.314.2018.08.25.01.20.42; Sat, 25 Aug 2018 01:20:57 -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=@kernel.org header.s=default header.b=0iKN3HuR; 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 S1727023AbeHYL5R (ORCPT + 99 others); Sat, 25 Aug 2018 07:57:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:58810 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726412AbeHYL5R (ORCPT ); Sat, 25 Aug 2018 07:57:17 -0400 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (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 A644120C51; Sat, 25 Aug 2018 08:19:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1535185144; bh=Wn3LI40pv5xkaC04Z756xdZZlBnZE4XvhhEBBCVPzl8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=0iKN3HuR+cjAgyLzjWrf6Hutq56SK1U0k5fE/THhaUJYTZpYjxLvBXYzzUw6zqSLh 3LXthiMAXmAr0BlWenDoVAu2TnKLrmhxHbL+eOE0EitGY5TuZZaeTPX5m9wV7fO93Q YHQZ92343L4qvhVUsuZFFreQK8Hp8JUPsD8L0Bs0= Date: Sat, 25 Aug 2018 09:19:00 +0100 From: Jonathan Cameron To: Stefan Popa Cc: , , , , , Subject: Re: [PATCH 2/3] iio:adxl372: Add sampling frequency support Message-ID: <20180825091900.11ad9597@archlinux> In-Reply-To: <1534776867-18812-1-git-send-email-stefan.popa@analog.com> References: <1534776867-18812-1-git-send-email-stefan.popa@analog.com> X-Mailer: Claws Mail 3.16.0 (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 Mon, 20 Aug 2018 17:54:27 +0300 Stefan Popa wrote: > This patch adds the option for the user to select the sampling frequency. > Also, the user can read the available frequencies and read the currently > set frequency via the read_raw function. The frequency can be set via the > write_raw function. > > When the frequency is set, the bandwidth is also checked and ensured > that it is constrained to at most half of the sampling frequency. Also, the > activity and inactivity timers have to be updated because they depend on > the selected ODR. > > Signed-off-by: Stefan Popa Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it. Thanks, Jonathan > --- > drivers/iio/accel/adxl372.c | 74 ++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 73 insertions(+), 1 deletion(-) > > diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c > index 5a039ba..6281e4a 100644 > --- a/drivers/iio/accel/adxl372.c > +++ b/drivers/iio/accel/adxl372.c > @@ -223,7 +223,8 @@ static const struct adxl372_axis_lookup adxl372_axis_lookup_table[] = { > .modified = 1, \ > .channel2 = IIO_MOD_##axis, \ > .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ > - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ > + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ > + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ > .scan_index = index, \ > .scan_type = { \ > .sign = 's', \ > @@ -311,6 +312,19 @@ static int adxl372_set_odr(struct adxl372_state *st, > return ret; > } > > +static int adxl372_find_closest_match(const int *array, > + unsigned int size, int val) > +{ > + int i; > + > + for (i = 0; i < size; i++) { > + if (val <= array[i]) > + return i; > + } > + > + return size - 1; > +} > + > static int adxl372_set_bandwidth(struct adxl372_state *st, > enum adxl372_bandwidth bw) > { > @@ -631,6 +645,51 @@ static int adxl372_read_raw(struct iio_dev *indio_dev, > *val = 0; > *val2 = ADXL372_USCALE; > return IIO_VAL_INT_PLUS_MICRO; > + case IIO_CHAN_INFO_SAMP_FREQ: > + *val = adxl372_samp_freq_tbl[st->odr]; > + return IIO_VAL_INT; > + } > + > + return -EINVAL; > +} > + > +static int adxl372_write_raw(struct iio_dev *indio_dev, > + struct iio_chan_spec const *chan, > + int val, int val2, long info) > +{ > + struct adxl372_state *st = iio_priv(indio_dev); > + int odr_index, ret; > + > + switch (info) { > + case IIO_CHAN_INFO_SAMP_FREQ: > + odr_index = adxl372_find_closest_match(adxl372_samp_freq_tbl, > + ARRAY_SIZE(adxl372_samp_freq_tbl), > + val); > + ret = adxl372_set_odr(st, odr_index); > + if (ret < 0) > + return ret; > + /* > + * The timer period depends on the ODR selected. > + * At 3200 Hz and below, it is 6.6 ms; at 6400 Hz, it is 3.3 ms > + */ > + ret = adxl372_set_activity_time_ms(st, st->act_time_ms); > + if (ret < 0) > + return ret; > + /* > + * The timer period depends on the ODR selected. > + * At 3200 Hz and below, it is 26 ms; at 6400 Hz, it is 13 ms > + */ > + ret = adxl372_set_inactivity_time_ms(st, st->inact_time_ms); > + if (ret < 0) > + return ret; > + /* > + * The maximum bandwidth is constrained to at most half of > + * the ODR to ensure that the Nyquist criteria is not violated > + */ > + if (st->bw > odr_index) > + ret = adxl372_set_bandwidth(st, odr_index); > + > + return ret; > default: > return -EINVAL; > } > @@ -778,9 +837,22 @@ static const struct iio_trigger_ops adxl372_trigger_ops = { > .set_trigger_state = adxl372_dready_trig_set_state, > }; > > +static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("400 800 1600 3200 6400"); > + > +static struct attribute *adxl372_attributes[] = { > + &iio_const_attr_sampling_frequency_available.dev_attr.attr, > + NULL, > +}; > + > +static const struct attribute_group adxl372_attrs_group = { > + .attrs = adxl372_attributes, > +}; > + > static const struct iio_info adxl372_info = { > .validate_trigger = &adxl372_validate_trigger, > + .attrs = &adxl372_attrs_group, > .read_raw = adxl372_read_raw, > + .write_raw = adxl372_write_raw, > .debugfs_reg_access = &adxl372_reg_access, > .hwfifo_set_watermark = adxl372_set_watermark, > };