Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp644151lqb; Fri, 24 May 2024 08:57:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXbU0U8y6V0PNN1nKG2fPXmYUCfUowM2bj2QFFxPyuzRwK/0e1SYJj9QhlnJHFl/DhAwOkRf+GBvV/wkPU8W4OnpyPQ14C5PIq+RZlPrg== X-Google-Smtp-Source: AGHT+IHaiiEIavy3r66ND+ijnCD9Mv0GjHJ2zNP4J82OdNcGg51BXdXgLybs0o/5XBpycgcBhnBp X-Received: by 2002:a17:906:3896:b0:a62:1347:ad40 with SMTP id a640c23a62f3a-a62641c6eb2mr172412366b.16.1716566228509; Fri, 24 May 2024 08:57:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716566228; cv=pass; d=google.com; s=arc-20160816; b=xt7AU53n+IDQo2Wp+VIKSBJF+tkx7FKwQDsSgwI8FytCvDskKSA2nelbviGcSDkluL CJI8cU6sOUcWeEPWkY56OugP5MbI6nNxxFS3VTNNzsy3jArhdVqKxt0983VVA9bqyi2J 8924bHrRrryoR1dOWk2Q61rkM+DWTTr3n4cOTbMYTDA2guSBg3AgKJDSX8zdzlhcjUyv p3qEWk7pc3zGBigTHC+5zybkcCkyyqNywVQvDoYvT1ARjTr9O0p6yRBSHm6kVV2WBuc9 7pU1EMMTL82N8OHwpfeG9ui9p9IfMNauFMbm3JTEwDdlW8ZkSLBprUn7uVGOpyu9wMho 6kDA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=pAHpfkkCR92bCHuVeFb4Gd0c4Ft15svLHWynuFWFQ0Y=; fh=8ERwtg/qpRNIvlj07Djbb0n8lvkjxgdDx5aGhEOY6dA=; b=02IQik1tFSmE40UVcjy3WyBItloRIfLKETfW5HEIwJNS9tvbBkZNDXmYAQn3JRprVu yiV66p7YqpZncJG3T72LnrBX72gNzcak5pPvtSoCZ1RtBLNb3p9TfzCKO9cQ99eQWHek zWTcSDWKWmXEdh6Xd+gmtHpn/NGzLxBd9/joetZwPXoo3ESsK+oO3tqSL2/SELRisuOQ WDvDyxUb6XP8LOk1yQtOVUEVOorM50ujiYFoHQoYfDJjEp9IpBBydnTuMQteuWyDsgeX xv8vsmguU1ls5nMJzrkJUNa0LDyFUUDfFaIFso20ccquRH+rKDMc2BDxgzF4y0LtatER wltg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=S6kZt8fg; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-188902-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188902-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a626cc65211si94029766b.594.2024.05.24.08.57.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 08:57:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-188902-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=S6kZt8fg; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-188902-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188902-linux.lists.archive=gmail.com@vger.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 11B4A1F224F1 for ; Fri, 24 May 2024 15:57:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A70E12E1D9; Fri, 24 May 2024 15:57:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="S6kZt8fg" Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18A056E5ED for ; Fri, 24 May 2024 15:56:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716566220; cv=none; b=phqUs816HQ6P/4435KU/fkgiqSmTtLEmP9mpIw5gEROVQKxYcKmd19qMuSV90CUvLwitfvEwdmCIqTI3uKRNRc/3K8n4SjdpRcA7BhZEJFaSdNRov2aBxd4kHfiWJd1yNQwH1ulViIUQFCAM+KuSXskJBp0GsmwkXtV2z08JYNg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716566220; c=relaxed/simple; bh=f/jxpUwz/FQOHV/5vg4nxEyI+NJdfbQEy5Bdkdr5fys=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=qB1cmujnlbiDZqpnUzZGi+/7ENSOxqXCiSs85stiOIEzy2mYJGvWuVSja8FUNRhRFy7y6NxGyAGmm0Vx2pnVSmAQF5o/TFvVt7lV2qOT6aVvSXdP67WkZtMFnqA8bABOhVKshWNIp320VTh+Szfl1lVZYvhUkP4vB6jbR9ASAhM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=S6kZt8fg; arc=none smtp.client-ip=209.85.161.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-oo1-f49.google.com with SMTP id 006d021491bc7-5b2ed25b337so4873390eaf.0 for ; Fri, 24 May 2024 08:56:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1716566217; x=1717171017; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=pAHpfkkCR92bCHuVeFb4Gd0c4Ft15svLHWynuFWFQ0Y=; b=S6kZt8fgs8xTEX5bf8nZrzMLr59wmtxWO0bsiq+JoAjaMZBFU2MLZ9C9yqreLPla0r QBG6c1tns8AN4wqjI8Fh+Io8Zx8fphvDAGyyfQ6nByL6LkXCp4x+M80fthzNqDtYsd+5 1UbMOf9XJAXOR+mgKQeSweJMoQRglxx4X1EPLs1I+y9XqEHleBdOQ+e9OYb6QO+D4hqg JBK9vzumjlkjxWiMNjgFcTNXIQSoyKpargtO9uK3m1g/plMopiDqRU/BSlH2DMT23hOA RnZSvHml85Se1N8eQRHA2dHw0xCsXCJbDLgwMThP+ndfUOsCwkHSkgmZNqgN/Ys8dQTY oMWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716566217; x=1717171017; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pAHpfkkCR92bCHuVeFb4Gd0c4Ft15svLHWynuFWFQ0Y=; b=M1wIXKt1TDOAgK31EFbWiX/uYsDGJkj4XMWbKaJ91sFAlCPgJIkzKM0Ps6TkI9so9J itf4353dmcInwxjh9S+NIeQXXOxcy9w+ryg/fsqCMzQwTm1J6QSDKPCyRRNnN5MmNfRk bA3jzAJa82sH80PcMegAy0+xEuzXfxrQ/NKwPHrOkHpppVw4spYMXXvmwYUCoYedh2x5 dM3ua2Uhy63hWEpcgCuw3ssPnLK3dUEHQabbB9qfEXVd7CvnDn5lzN4s90AOZTsxg+CJ +dTg0AyIe2xKbWCKWAWOniUZ19VOep+dgOTzg+2jpJQnreMafFE2WsbKKuRb43PK+Xlw ep/w== X-Forwarded-Encrypted: i=1; AJvYcCWcHRD8NioKE6GaNsDDOF9ZhG3PpGAy83EWogeT0+sK/9B2nV9I0Bw+oxH6nuGo1fV1ZKrjbolDy4gFriQWBI1ZqZ0fYygITz8ZbHtK X-Gm-Message-State: AOJu0YwlAUF5AcijSvtrs6CGcXAxjxdmdLyLFktQeLXhDXnK54xtEyAK /8THdu8h02I724YBoRNJYyGOnrqmuzLsJLb+tPTz36zVYS8SPLVR2AHsW+FUaxI= X-Received: by 2002:a05:6820:1606:b0:5b2:72e5:c12d with SMTP id 006d021491bc7-5b961b5dda1mr3688565eaf.5.1716566216830; Fri, 24 May 2024 08:56:56 -0700 (PDT) Received: from [192.168.0.142] (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5b96c699953sm358875eaf.31.2024.05.24.08.56.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 May 2024 08:56:56 -0700 (PDT) Message-ID: <5cf036d5-1eb3-4f63-82f9-d01b79b7fe47@baylibre.com> Date: Fri, 24 May 2024 10:56:55 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC 3/4] iio: add support for multiple scan types per channel To: Jonathan Cameron Cc: Jonathan Cameron , Michael Hennerich , =?UTF-8?Q?Nuno_S=C3=A1?= , Julien Stephan , Esteban Blanc , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org References: <20240507-iio-add-support-for-multiple-scan-types-v1-0-95ac33ee51e9@baylibre.com> <20240507-iio-add-support-for-multiple-scan-types-v1-3-95ac33ee51e9@baylibre.com> <20240519201241.7c60abac@jic23-huawei> <20240520171205.000035b0@Huawei.com> Content-Language: en-US From: David Lechner In-Reply-To: <20240520171205.000035b0@Huawei.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 5/20/24 11:12 AM, Jonathan Cameron wrote: > On Mon, 20 May 2024 08:51:52 -0500 > David Lechner wrote: > >> On 5/19/24 2:12 PM, Jonathan Cameron wrote: >>> On Tue, 7 May 2024 14:02:07 -0500 >>> David Lechner wrote: >>> >>>> This adds new fields to the iio_channel structure to support multiple >>>> scan types per channel. This is useful for devices that support multiple >>>> resolution modes or other modes that require different data formats of >>>> the raw data. >>>> >>>> To make use of this, drivers can still use the old scan_type field for >>>> the "default" scan type and use the new scan_type_ext field for any >>>> additional scan types. >>> >>> Comment inline says that you should commit scan_type if scan_type_ext >>> is provided. That makes sense to me rather that a default no one reads. >>> >>> The example that follows in patch 4 uses both the scan_type and >>> the scan_type_ext which is even more confusing. >>> >>>> And they must implement the new callback >>>> get_current_scan_type() to return the current scan type based on the >>>> current state of the device. >>>> >>>> The buffer code is the only code in the IIO core code that is using the >>>> scan_type field. This patch updates the buffer code to use the new >>>> iio_channel_validate_scan_type() function to ensure it is returning the >>>> correct scan type for the current state of the device when reading the >>>> sysfs attributes. The buffer validation code is also update to validate >>>> any additional scan types that are set in the scan_type_ext field. Part >>>> of that code is refactored to a new function to avoid duplication. >>>> >>>> Signed-off-by: David Lechner >>>> --- >>> >>>> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h >>>> index 19de573a944a..66f0b4c68f53 100644 >>>> --- a/include/linux/iio/iio.h >>>> +++ b/include/linux/iio/iio.h >>>> @@ -205,6 +205,9 @@ struct iio_scan_type { >>>> * @scan_index: Monotonic index to give ordering in scans when read >>>> * from a buffer. >>>> * @scan_type: struct describing the scan type >>>> + * @ext_scan_type: Used in rare cases where there is more than one scan >>>> + * format for a channel. When this is used, omit scan_type. >>> >>> Here is the disagreement with the patch description. >>> >>>> + * @num_ext_scan_type: Number of elements in ext_scan_type. >>>> * @info_mask_separate: What information is to be exported that is specific to >>>> * this channel. >>>> * @info_mask_separate_available: What availability information is to be >>>> @@ -256,6 +259,8 @@ struct iio_chan_spec { >>>> unsigned long address; >>>> int scan_index; >>>> struct iio_scan_type scan_type; >>>> + const struct iio_scan_type *ext_scan_type; >>>> + unsigned int num_ext_scan_type; >>> >>> Let's make it explicit that you can't do both. >>> >>> union { >>> struct iio_scan_type scan_type; >>> struct { >>> const struct iio_scan_type *ext_scan_type; >>> unsigned int num_ext_scan_type; >>> }; >>> }; >>> should work for that I think. >>> >>> However this is I think only used for validation. If that's the case >>> do we care about values not in use? Can we move the validation to >>> be runtime if the get_current_scan_type() callback is used. >> >> I like the suggestion of the union to use one or the other. But I'm not >> sure I understand the comments about validation. >> >> If you are referring to iio_channel_validate_scan_type(), it only checks >> for programmer error of realbits > storagebits, so it seems better to >> keep it where it is to fail as early as possible. > > That requires the possible scan masks to be listed here but there is > nothing enforcing the callback returning one from here. Maybe make it > return an index instead? > Sorry, still not understanding what we are trying to catch here. Why would the scan mask have any effect of checking if realbits > storagebits?