Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4230068pxu; Mon, 21 Dec 2020 07:21:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJwHrCE2/WQkdkBcr+vvb2wTqIKJE7yHEzFop4rs994RPufA0Qcd9PhfkYJ2YtgL7wjaZJHA X-Received: by 2002:a17:907:2111:: with SMTP id qn17mr15323477ejb.525.1608564082584; Mon, 21 Dec 2020 07:21:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608564082; cv=none; d=google.com; s=arc-20160816; b=ZFgzh/oV/u5LkATqeW/7pDU9Swx8LcZlK0nmHs46ukF871n1w6fw+i2+TO15+eebGU KeHe+oqYhBTf0EuKJyFmI5AD/+vRs/jMXX8t4u6DNBJthHLcsZlnAWJzrR+RkKMe9oAk PxEgdocNSHllcBBWO7Vk5agOk2S/LLcvv1C3NDjClcc5wqgmRoRPr/UAZYWfrfv6f/89 3QHD8UOeHmlGC7fM8Y3gAhDhlCZ0AKICo4LJuaa0VIMv7NamV2Xu5e4yY/aiS1nUOHFx 05UHu60jCwWWBm5v9Gd6ph32mF2saMhTsDeY2Gx/VHhLSJwU3WzhJmrqBqDkBAyNAbsn YZbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=HyXU+qqTigSSfTNKU247NVs2xrV4x4TwijL8KxJtCJE=; b=p5C0heElf0pX0dmEsXuSl44RdoT9yvCRXyCZhJLMDYZmY+rbwgLRo5xjfmgDSmxe29 anJUy/9UdrSzs+/NFoUOPKqQ/vr0xWtwD0L0YhK0KI0YAHJZKutN6Bkh1tYWsL1oYH83 Q2vVbDg6W4irRH0ILjocQxvUmI97e++V3s1vy36ulzZB8o7Rt0rGrylIsNBAbLdcOdGy 4M1Pvp9kwH2Ft+p49jaCM20F3un8cgcx1sxC0F3Y+J2TiEIsbmIaMe0Lop/KnJeP4ElG C/qWR548R/rka6ir3Cymhki3hr5+zVYkgxShqv3ZhiJyYHubPbdXkfaUBOWzdOyycQqF 8gvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@lechnology.com header.s=default header.b=Q0cQhNK0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b24si8690459eju.531.2020.12.21.07.20.59; Mon, 21 Dec 2020 07:21:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@lechnology.com header.s=default header.b=Q0cQhNK0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725878AbgLUPUF (ORCPT + 99 others); Mon, 21 Dec 2020 10:20:05 -0500 Received: from vern.gendns.com ([98.142.107.122]:42174 "EHLO vern.gendns.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725807AbgLUPUF (ORCPT ); Mon, 21 Dec 2020 10:20:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lechnology.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=HyXU+qqTigSSfTNKU247NVs2xrV4x4TwijL8KxJtCJE=; b=Q0cQhNK07CVmJlrps4f2k5T62O 1vWcCXeQ+kbVSdqdONMPcWPdgbf8pMZG8NrlmR+Ukd02FXQq6K7BjnEsmsEtEI4cpqUvLsAtZmt0Q Bt8tUvd6QyID7n1Tw/eCRK1AYX+1pFP2kLrTBTk910cTTKkN4AQbjqT7vDk2+ND5wKUoRePYjZgNj hNKwAu2PUKoLAWKnH+nh/uTK5V2GDQECWJYcMO5eomWcgPBhK7lJXeuN/DoNEnEM2hLm+jGBATWCM zWREh8whhVMbXBLjG17ozE1pXyFlku3Dyotp2GkBZKwkcIKIxqjQbzftpIIAXp3V0wHpjx0tOwRVd o2LZqupA==; Received: from 108-198-5-147.lightspeed.okcbok.sbcglobal.net ([108.198.5.147]:51306 helo=[192.168.0.134]) by vern.gendns.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1krMxz-00055Y-VB; Mon, 21 Dec 2020 10:19:20 -0500 Subject: Re: [PATCH v6 0/5] Introduce the Counter character device interface To: William Breathitt Gray , David.Laight@ACULAB.COM Cc: jic23@kernel.org, kernel@pengutronix.de, linux-stm32@st-md-mailman.stormreply.com, a.fatoum@pengutronix.de, kamel.bouhara@bootlin.com, gwendal@chromium.org, alexandre.belloni@bootlin.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, syednwaris@gmail.com, patrick.havelange@essensium.com, fabrice.gasnier@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com References: <6f0d78ae-9724-f67f-f133-a1148a5f1688@lechnology.com> From: David Lechner Message-ID: Date: Mon, 21 Dec 2020 09:19:17 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vern.gendns.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lechnology.com X-Get-Message-Sender-Via: vern.gendns.com: authenticated_id: davidmain+lechnology.com/only user confirmed/virtual account not confirmed X-Authenticated-Sender: vern.gendns.com: davidmain@lechnology.com X-Source: X-Source-Args: X-Source-Dir: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/20/20 3:44 PM, William Breathitt Gray wrote: > On Sun, Dec 13, 2020 at 05:15:14PM -0600, David Lechner wrote: >> On 11/22/20 2:29 PM, William Breathitt Gray wrote: >>> >>> 1. Should standard Counter component data types be defined as u8 or u32? >>> >>> Many standard Counter component types such COUNTER_COMP_SIGNAL_LEVEL >>> have standard values defined (e.g. COUNTER_SIGNAL_LEVEL_LOW and >>> COUNTER_SIGNAL_LEVEL_HIGH). These values are currently handled by the >>> Counter subsystem code as u8 data types. >>> >>> If u32 is used for these values instead, C enum structures could be >>> used by driver authors to implicitly cast these values via the driver >>> callback parameters. >>> >>> This question is primarily addressed to David Lechner. I'm somewhat >>> confused about how this setup would look in device drivers. I've gone >>> ahead and refactored the code to support u32 enums, and pushed it to >>> a separate branch on my repository called counter_chrdev_v6_u32_enum: >>> https://gitlab.com/vilhelmgray/iio/-/tree/counter_chrdev_v6_u32_enum >>> >>> Please check it out and let me know what you think. Is this the >>> support you had in mind? I'm curious to see an example of how would >>> your driver callback functions would look in this case. If everything >>> works out fine, then I'll submit this branch as v7 of this patchset. >> >> I haven't had time to look at this in depth, but just superficially looking >> at it, it is mostly there. The driver callback would just use the enum type >> in place of u32. For example: >> >> static int ti_eqep_function_write(struct counter_device *counter, >> struct counter_count *count, >> enum counter_function function) >> >> and the COUNTER_FUNCTION_* constants would be defined as: >> >> enum counter_function { >> COUNTER_FUNCTION_INCREASE, >> ... >> }; >> >> instead of using #define macros. >> >> One advantage I see to using u8, at least in the user API data structures, >> is that it increases the number of events that fit in the kfifo buffer by >> a significant factor. >> >> And that is not to say that we couldn't do both: have the user API structs >> use u8 for enum values and still use u32/strong enum types internally in >> the callback functions. > > I'm including David Laight because he initially opposed enums in favor > of fixed size types when we discussed this in an earlier revision: > https://lkml.org/lkml/2020/5/3/159 > > However, there have been significant changes to this patchset so the > context now is different than those earlier discussions (i.e. we're no > longer discussing ioctl calls). > > I think reimplementing these constants as enums as described could work. > If we do so, should the enum constants be given specific values? For > example: > > enum counter_function { > COUNTER_FUNCTION_INCREASE = 0, > COUNTER_FUNCTION_DECREASE = 1, > ... > }; I would say no on the explicit values since they don't have any significant meaning.