Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp941007imm; Fri, 3 Aug 2018 14:33:08 -0700 (PDT) X-Google-Smtp-Source: AAOMgpev7Tmspmc+T+ahMRI8QZdgtN1Cdng5V/97+ZPEZ7AGEYGFbXVkx6O9LOBbhMpKK1TJZkzw X-Received: by 2002:a63:6b03:: with SMTP id g3-v6mr5393942pgc.57.1533331987968; Fri, 03 Aug 2018 14:33:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533331987; cv=none; d=google.com; s=arc-20160816; b=S89Y57SfKNjUFoCBm0ofnEGXDcIe0/xBsy5sQep8lGQX+8o1qswHGOMZmgysb46HtO xsFn9KrnxNCeNp6RFO7VQh+/W2KfEb3dAYUmVPtyr/wCVCmq4HuF8WJaC1h8xrXCLdBS UXa7sqHzmT/k71KCJpQfzs+RTkZJlJDMcb/Itug+FYpRx+44CptwvOi8NT1PVFr1S1uC rtGpYcQRZ/D1gA99cb3Kme8K8L5yabnuaLwy8x8Th/NBK8FP7L5QPetBfPhkvwViTlPS rjebtJjQ0xMeub0ck67kpyK6ubawYuyBspfemBnB/kgCpYkkFjMEokUn6Qmd5PcWxyta O+Uw== 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=vimho8HSsOYdHXqzuJIOlGTYlac37QErxPeeaeGp8RE=; b=fJZwGhOlxFG8r9NeLaYdD/lA7r28Lr83UOiCFcQ5tuquNcEM4ekN39QjAd/lRGD7aq j9DlqmgJIQACKGnNS4pxy3HjBilm7ErQOGGW4vQvTK3gzoZRgsoxB91yv9Rr/dwwSaQJ 2wO1T67TOyyF66oxSVT94e6KTOfZibTRep5xL1okFI/Gu02BLd4mZXqjm+V+bYVB7zVN TFTNbYuCUklkuwzrgS4e+VZtv4fJ5EGPgQWZzLRrQvarPnpL8cQsrjRSz+HKQFUm55uo lenoVRWFttAoCaiYntOezopXWk1VmQvXYJ+MOXsdDhBqpJOXKmvM6r1FYoZ7AFGPH8lg di9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lAATuLJj; 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 83-v6si6828152pgg.588.2018.08.03.14.32.52; Fri, 03 Aug 2018 14:33:07 -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=lAATuLJj; 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 S1732090AbeHCXaG (ORCPT + 99 others); Fri, 3 Aug 2018 19:30:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:33982 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729985AbeHCXaG (ORCPT ); Fri, 3 Aug 2018 19:30:06 -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 A939B2178D; Fri, 3 Aug 2018 21:32:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1533331923; bh=niDOM7N3Q0lhyHwqdBcGNVW9PKYr6Hn6JcPfOkCbjUk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=lAATuLJj9YxpvLEaKn1uqL7iN4zLcTPXKUdF8448ar25BRc9nbv/eo6M54IS2UTg5 bzLyhaBQPk+c7/eOHYfzF45OON6oLnDWBLRicw5f5A6mEzCFST7tz4ozNSxYXUMLzn ok3+J/DLjZJgjsNNyd0PnYaXgfx0rgJLuWWRFy7Q= Date: Fri, 3 Aug 2018 22:31:58 +0100 From: Jonathan Cameron To: Stefan Popa Cc: , , , , , , , , , , , , , Subject: Re: [PATCH v3 5/6] iio:adxl372: Add sampling frequency support Message-ID: <20180803223158.13435a88@archlinux> In-Reply-To: <1533301341-26560-6-git-send-email-stefan.popa@analog.com> References: <1533301341-26560-1-git-send-email-stefan.popa@analog.com> <1533301341-26560-6-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 Fri, 3 Aug 2018 16:02:20 +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 This one is good. Will pick up with the others unless someone finds an issue in the meantime. 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 e31e096..80b1838 100644 > --- a/drivers/iio/accel/adxl372.c > +++ b/drivers/iio/accel/adxl372.c > @@ -217,7 +217,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) > { > @@ -639,6 +653,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; > } > @@ -766,8 +825,21 @@ 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 = { > + .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, > };