Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp885388lqa; Sun, 28 Apr 2024 08:26:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUFFa0w9bdt3Nl7pcjZ9GPJ0f04cgQBUfES54i1ep2CqIdgxNoP/uOKNr5JaRjZPd1TnkEmUY3YSew8ORENr7d4gJ52pGwHd+VfUJCxWQ== X-Google-Smtp-Source: AGHT+IEQIlq5Jg4G9WFngfDLKMFFWXzDpqGH6WWxPdoR+DITVsoWjfQ68kZhyzLKgyXYWPqIN2CT X-Received: by 2002:a05:6a20:1053:b0:1a9:867b:c064 with SMTP id gt19-20020a056a20105300b001a9867bc064mr7834664pzc.41.1714317980632; Sun, 28 Apr 2024 08:26:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714317980; cv=pass; d=google.com; s=arc-20160816; b=eLkSbO+9T4M8H7KUfDEAmYj31B3Opw0RYkMvQ8NjWqVhSwuBWNj3G9TD+9Pq/BXd8P PLEGx+JTSsM54f7uQE0ua6gw+L6DE6pLXcoCRwjy7VsN6lLTPHC0B3BEqVrDMyrve6yO cIt1F5Q6B815Ok0OSfyB05b+jxhF/fcuqMVMseZIlXCI8RqT/HRTL6B0l3bdqvwtpAdy F0VlNhgQofp50D4lpNH7T6XSC++xRbBUxAxPzwtIBczrd00F8dbeZDoql4jj+cmyD4yt 6xtLvbyhAFF1ZL5qzJThh9+zfAE49AldbqM5UK0rAYBh4TookJdPo82d07K0RuXBjnQQ OTnA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=C8ujRkA8QhqiKQpT/7eP1dWvw/eyvMYlxvC59EjdGRk=; fh=6yRClT4KRKIgEOHpIEsjx5X2wd2aXSR6/HeRExWV4EY=; b=VDm85baj3sDT7aGtsy4XCapKO764JhZIIgtRk0kS2tNVwLY/nrjClSKyeRkIdbbNwv 4CfngICtfqraMBlWtoUPu+coS9CIOXHS6IOdC+ilWTLe2AcVgnuaRGBdqVW0yn/rkJsv fPQJsh0E9CFVzvHTTAYJJsosESs8360eXO3gqELDrsxvFkPd1dvf9WxakJ/tUQm+XtjA /emJKrYzZN7/J1trKeaBZhPt8aedn1xnEDBv822HShFX759zcQp7yH8nWdmhHQhTE00P aWGZ2LeG4IqpcWz+tIuTtsyIP7gbbZlm6fpuzx4alzbNofLDI3yrOx27dG3ykCABkgdx 7MNA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iTKl7RpH; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-161465-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161465-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id r68-20020a632b47000000b0060141262d2esi11564956pgr.42.2024.04.28.08.26.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Apr 2024 08:26:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-161465-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iTKl7RpH; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-161465-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161465-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3E4DB2818AA for ; Sun, 28 Apr 2024 15:26:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2A8716F065; Sun, 28 Apr 2024 15:26:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iTKl7RpH" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 290746E616; Sun, 28 Apr 2024 15:26:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714317969; cv=none; b=VKuSD3aD4Za56vI1uC7og/69QJL553gQniuHZSmgXV9a1e61WrxDIoUs66Glm8czis6ol2qnQqRKVxpc5vfq0pzSjXgAXzTULjMFzfZrneOud/r+Y4+5o5qcT1r50nziPgD/1LidaaK9iEyQZUZKXk2Vd+3k0ueNOjwLCqCq4mo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714317969; c=relaxed/simple; bh=7ovo8rsd82tkHk6P6i/ksXhOuXVKwHzQD4qs3EERarA=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=G6V1blaHOn+GqmjrOtTuZgo8GqFj5g96ICaWdsoPnKpNmJlO2ZA5qPURzMOQFNclV3HZKmNwHzu0oQbEbFV9i3FMoa5tG2fFOIGhpp9iz8iuISDDikFXxaxwUOskwYpf3QpKTY9FxQq8AlEKDW2WIvwRZcKxJZ4PlXB2P8cKzA0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iTKl7RpH; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BCA48C113CC; Sun, 28 Apr 2024 15:26:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714317968; bh=7ovo8rsd82tkHk6P6i/ksXhOuXVKwHzQD4qs3EERarA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=iTKl7RpHY8krA3pNcehJIOymFdvWn8r3BIzglF7UZvIEIhwSk6rMYM2zBphX32e+j qK9IUG9Vw1mZr+w70QO0VlbVt6s+fWbpPbuYfCs1rMDJMQAZ5Ucmmwr9UlXjt//wvj myyVmuh3SpIm46Lmc3Ac5jTRmgVFrfF7RQfnTn7bIFn7ogh6V3B7qVBXtSAbmXXFVE f4zGU+VfV6oHaEIECIHfVmygEDri4RHAjpj9t/IoxxN5BmFKo0afHlMBIfedAVeQih USsa2/B4Psw059MTH6KpIOacWA155BcVRnMkCRB7RF2DgNVywAK2hqwgdLo3Hv58Ao KTS6bDgzoXG6g== Date: Sun, 28 Apr 2024 16:25:55 +0100 From: Jonathan Cameron To: Ramona Gradinariu Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-doc@vger.kernel.org, devicetree@vger.kernel.org, corbet@lwn.net, conor+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, robh@kernel.org, Ramona Gradinariu , Nuno =?UTF-8?B?U8Oh?= Subject: Re: [PATCH 4/5] iio: adis16480: add support for adis16545/7 families Message-ID: <20240428162555.3ddf31ea@jic23-huawei> In-Reply-To: <20240423084210.191987-5-ramona.gradinariu@analog.com> References: <20240423084210.191987-1-ramona.gradinariu@analog.com> <20240423084210.191987-5-ramona.gradinariu@analog.com> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Tue, 23 Apr 2024 11:42:09 +0300 Ramona Gradinariu wrote: > The ADIS16545 and ADIS16547 are a complete inertial system that > includes a triaxis gyroscope and a triaxis accelerometer. > The serial peripheral interface (SPI) and register structure provide a > simple interface for data collection and configuration control. >=20 > These devices are similar to the ones already supported in the driver, > with changes in the scales, timings and the max spi speed in burst > mode. > Also, they support delta angle and delta velocity readings in burst > mode, for which support was added in the trigger handler. >=20 > Signed-off-by: Nuno S=C3=A1 What is Nuno's relationship to this patch? You are author and the sender which is fine, but in that case you need to make Nuno's involvement explici= t. Perhaps a Co-developed-by or similar is appropriate? > Signed-off-by: Ramona Gradinariu A few comments inline. Biggest one is I'd like a clear statement of why you can't do a burst of one type, then a burst of other. My guess is that the transition is very time consuming? If so, that is fine, but you should be = able to let available_scan_masks handle the disjoint channel sets. =46rom what I recall a similar case was why that got added in the first place. The uses in optimizing for devices that 'want' to grab lots of channels was a later use case. Jonathan > =20 > static bool adis16480_validate_crc(const u16 *buf, const u8 n_elem, cons= t u32 crc) > @@ -1200,7 +1355,7 @@ static irqreturn_t adis16480_trigger_handler(int ir= q, void *p) > struct adis16480 *st =3D iio_priv(indio_dev); > struct adis *adis =3D &st->adis; > struct device *dev =3D &adis->spi->dev; > - int ret, bit, offset, i =3D 0; > + int ret, bit, offset, i =3D 0, buff_offset =3D 0; > __be16 *buffer; > u32 crc; > bool valid; > @@ -1233,8 +1388,8 @@ static irqreturn_t adis16480_trigger_handler(int ir= q, void *p) > * 16-bit responses containing the BURST_ID depending on the sclk. If > * clk > 3.6MHz, then we will have two BURST_ID in a row. If clk < 3MHZ, > * we have only one. To manage that variation, we use the transition fr= om the > - * BURST_ID to the SYS_E_FLAG register, which will not be equal to 0xA5= A5. If > - * we not find this variation in the first 4 segments, then the data sh= ould > + * BURST_ID to the SYS_E_FLAG register, which will not be equal to 0xA5= A5/0xC3C3. > + * If we not find this variation in the first 4 segments, then the data= should > * not be valid. > */ > buffer =3D adis->buffer; > @@ -1242,7 +1397,7 @@ static irqreturn_t adis16480_trigger_handler(int ir= q, void *p) > u16 curr =3D be16_to_cpu(buffer[offset]); > u16 next =3D be16_to_cpu(buffer[offset + 1]); > =20 > - if (curr =3D=3D ADIS16495_BURST_ID && next !=3D ADIS16495_BURST_ID) { > + if (curr =3D=3D st->burst_id && next !=3D st->burst_id) { > offset++; > break; > } > @@ -1269,11 +1424,22 @@ static irqreturn_t adis16480_trigger_handler(int = irq, void *p) > switch (bit) { > case ADIS16480_SCAN_TEMP: > st->data[i++] =3D buffer[offset + 1]; > + /* > + * The temperature channel has 16-bit storage size. > + * We need to perform the padding to have the buffer > + * elements naturally aligned in case there are any > + * 32-bit storage size channels enabled which have a > + * scan index higher than the temperature channel scan > + * index. > + */ > + if (*indio_dev->active_scan_mask & > + GENMASK(ADIS16480_SCAN_DELTVEL_Z, ADIS16480_SCAN_DELTANG_X)) > + st->data[i++] =3D 0; I think it is harmless to always do this. If there is no data after this ch= annel then we are writing data that won't be copied anywhere. If there is data af= ter it is needed. So I think you can drop the condition but do add a comment on it being nece= ssary if there is data afterwards and harmless if there isn't. =09 > break; > case ADIS16480_SCAN_GYRO_X ... ADIS16480_SCAN_ACCEL_Z: > /* The lower register data is sequenced first */ > - st->data[i++] =3D buffer[2 * bit + offset + 3]; > - st->data[i++] =3D buffer[2 * bit + offset + 2]; > + st->data[i++] =3D buffer[2 * (bit - buff_offset) + offset + 3]; > + st->data[i++] =3D buffer[2 * (bit - buff_offset) + offset + 2]; > break; > } > } > @@ -1285,10 +1451,38 @@ static irqreturn_t adis16480_trigger_handler(int = irq, void *p) > return IRQ_HANDLED; > } > =20 > +static int adis16480_update_scan_mode(struct iio_dev *indio_dev, > + const unsigned long *scan_mask) > +{ > + u16 en; > + int ret; > + struct adis16480 *st =3D iio_priv(indio_dev); > + > + if (st->chip_info->has_burst_delta_data) { > + if ((*scan_mask & ADIS16545_BURST_DATA_SEL_0_CHN_MASK) && > + (*scan_mask & ADIS16545_BURST_DATA_SEL_1_CHN_MASK)) > + return -EINVAL; Use available scan_masks to enforce this. That can have mutually exclusive sets like you have here. However, what stops 2 burst reads - so do them one after the other if neede= d. You'd still want available_scan_masks to have the subsets though but added to that the combination of the two. > + if (*scan_mask & ADIS16545_BURST_DATA_SEL_0_CHN_MASK) { > + en =3D FIELD_PREP(ADIS16545_BURST_DATA_SEL_MASK, 0); > + st->burst_id =3D 0xA5A5; Give the magic value a name via a define. > + } else { > + en =3D FIELD_PREP(ADIS16545_BURST_DATA_SEL_MASK, 1); > + st->burst_id =3D 0xC3C3; > + } > + > + ret =3D __adis_update_bits(&st->adis, ADIS16480_REG_CONFIG, > + ADIS16545_BURST_DATA_SEL_MASK, en); > + if (ret) > + return ret; > + } > + > + return adis_update_scan_mode(indio_dev, scan_mask); > +} > =20 > @@ -1498,6 +1692,8 @@ static int adis16480_probe(struct spi_device *spi) > if (ret) > return ret; > =20 > + st->burst_id =3D ADIS16495_BURST_ID; Why this default? Probably wants an explanatory comment. > +