From nobody Thu Apr 2 21:38:45 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DACF1C54EE9 for ; Tue, 20 Sep 2022 20:01:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229962AbiITUBr (ORCPT ); Tue, 20 Sep 2022 16:01:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230362AbiITUBm (ORCPT ); Tue, 20 Sep 2022 16:01:42 -0400 Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E40148E81 for ; Tue, 20 Sep 2022 13:01:41 -0700 (PDT) Received: by mail-oi1-x22f.google.com with SMTP id o64so5135339oib.12 for ; Tue, 20 Sep 2022 13:01:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=jb0x3oefFjLbH36GFSoVoseYWbwa162cAGUOYR/16hU=; b=vT/Z2M/J4YcUX+Lb4aBnpyaEhnKQ0UOr5GcJZqUt3OmRZa2nj1e/ayw/DfgfU7wBRA oElu2QCpwPSzxqPqF+yH1mWRRa/vdzkf7rfWeAYAZKkiehdgdhO7AfJ+g0N2TnSTaFbR f6dgKtAb5R/X0spDV+K/sKTJSmi0q8bjwcGQc87ZIgwFFL9o2nBBGHFtv1vgyMGwb8C9 vnok/nsv6v0MABRQD2NI+cCzbOYAHxZvvG8//GHZ5NGVo6SHtlHrM52BZGYlh5oXO8M2 dhhpaamwq3MmBAyI66onfB3Vd/z4Sqk93/HDCm+/zX7SJ7cJX4+oLTO/v7jupjqFu0Hl +AvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=jb0x3oefFjLbH36GFSoVoseYWbwa162cAGUOYR/16hU=; b=YhCRKoSjocu26Bvc8qE+q+N7kT1vQQ0FwPMKj8/UwkNk9URRSpVbKVKGX/lqyYHMoA ZQ+jLOty7mfmA0qBa/LbEbyyoAKUt3I8DovTJVz4YDL4FAK5m4uHocl7f9uauHqjBaDC UtGXqGXH6zRyV9xFHTdjegGt8oDVW14Lw3i9BvRToAqWvoiiBH3D2ystW6Dau5Te27D0 AgD1+4qPmhdr/LUaNNstVilz4/fwqouoobyhL89o6Oc8Gi3Kl0IOtqezQ1Um1Fa7fdlh 0VxBlp4VGwOmwi4CCvqWkQpk/TODPR2sp+UEJuVCfPtOeFe3wGdUKWBMZuRzmzlLw/i3 CaLw== X-Gm-Message-State: ACrzQf3G10BQ/cbopJSB0smvAEMaVjke8M433/di19FpRRfajZDPH7YM Sf+W0hCJeu0tnIHS/vsXpf0+jg== X-Google-Smtp-Source: AMsMyM5SZFDBS973nB/mzz9zuuJcW08LqW85E2Y2POWkzACezKRTK0kiU0x8w6qMxFveGLz+s1oSPA== X-Received: by 2002:a05:6808:181e:b0:350:7776:9059 with SMTP id bh30-20020a056808181e00b0035077769059mr2397390oib.83.1663704100687; Tue, 20 Sep 2022 13:01:40 -0700 (PDT) Received: from fedora.attlocal.net (69-109-179-158.lightspeed.dybhfl.sbcglobal.net. [69.109.179.158]) by smtp.gmail.com with ESMTPSA id bm43-20020a0568081aab00b0034d14c6ce3dsm325634oib.16.2022.09.20.13.01.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 13:01:40 -0700 (PDT) From: William Breathitt Gray To: linux-iio@vger.kernel.org Cc: linux-kernel@vger.kernel.org, mranostay@ti.com, jpanis@baylibre.com, gwendal@chromium.org, bleung@chromium.org, groeck@chromium.org, jic23@kernel.org, david@lechnology.com, robertcnelson@gmail.com, William Breathitt Gray Subject: [PATCH v5 1/5] counter: Introduce the Signal polarity component Date: Tue, 20 Sep 2022 13:21:25 -0400 Message-Id: X-Mailer: git-send-email 2.37.3 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The Signal polarity component represents the active level of a respective Signal. There are two possible states: positive (rising edge) and negative (falling edge); enum counter_signal_polarity represents these states. A convenience macro COUNTER_COMP_POLARITY() is provided for driver authors to declare a Signal polarity component. Cc: Julien Panis Signed-off-by: William Breathitt Gray Tested-by: Julien Panis --- Documentation/ABI/testing/sysfs-bus-counter | 13 +++++++++++++ drivers/counter/counter-chrdev.c | 1 + drivers/counter/counter-sysfs.c | 12 ++++++++++++ include/linux/counter.h | 10 ++++++++++ include/uapi/linux/counter.h | 6 ++++++ 5 files changed, 42 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-counter b/Documentation/AB= I/testing/sysfs-bus-counter index 06c2b3e27e0b..a234022f9add 100644 --- a/Documentation/ABI/testing/sysfs-bus-counter +++ b/Documentation/ABI/testing/sysfs-bus-counter @@ -303,6 +303,19 @@ Description: Discrete set of available values for the respective Signal Y configuration are listed in this file. =20 +What: /sys/bus/counter/devices/counterX/signalY/polarity +KernelVersion: 6.1 +Contact: linux-iio@vger.kernel.org +Description: + Active level of Signal Y. The following polarity values are + available: + + positive: + Signal high state considered active level (rising edge). + + negative: + Signal low state considered active level (falling edge). + What: /sys/bus/counter/devices/counterX/signalY/name KernelVersion: 5.2 Contact: linux-iio@vger.kernel.org diff --git a/drivers/counter/counter-chrdev.c b/drivers/counter/counter-chr= dev.c index 4e71a19d7e6a..120879ee2e87 100644 --- a/drivers/counter/counter-chrdev.c +++ b/drivers/counter/counter-chrdev.c @@ -487,6 +487,7 @@ static int counter_get_data(struct counter_device *cons= t counter, case COUNTER_COMP_ENUM: case COUNTER_COMP_COUNT_DIRECTION: case COUNTER_COMP_COUNT_MODE: + case COUNTER_COMP_SIGNAL_POLARITY: switch (comp_node->component.scope) { case COUNTER_SCOPE_DEVICE: ret =3D comp->device_u32_read(counter, &value_u32); diff --git a/drivers/counter/counter-sysfs.c b/drivers/counter/counter-sysf= s.c index 04eac41dad33..e5dd36e1a45f 100644 --- a/drivers/counter/counter-sysfs.c +++ b/drivers/counter/counter-sysfs.c @@ -91,6 +91,11 @@ static const char *const counter_count_mode_str[] =3D { [COUNTER_COUNT_MODE_MODULO_N] =3D "modulo-n" }; =20 +static const char *const counter_signal_polarity_str[] =3D { + [COUNTER_SIGNAL_POLARITY_POSITIVE] =3D "positive", + [COUNTER_SIGNAL_POLARITY_NEGATIVE] =3D "negative" +}; + static ssize_t counter_comp_u8_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -201,6 +206,8 @@ static ssize_t counter_comp_u32_show(struct device *dev, return sysfs_emit(buf, "%s\n", counter_count_direction_str[data]); case COUNTER_COMP_COUNT_MODE: return sysfs_emit(buf, "%s\n", counter_count_mode_str[data]); + case COUNTER_COMP_SIGNAL_POLARITY: + return sysfs_emit(buf, "%s\n", counter_signal_polarity_str[data]); default: return sysfs_emit(buf, "%u\n", (unsigned int)data); } @@ -252,6 +259,10 @@ static ssize_t counter_comp_u32_store(struct device *d= ev, err =3D counter_find_enum(&data, avail->enums, avail->num_items, buf, counter_count_mode_str); break; + case COUNTER_COMP_SIGNAL_POLARITY: + err =3D counter_find_enum(&data, avail->enums, avail->num_items, + buf, counter_signal_polarity_str); + break; default: err =3D kstrtou32(buf, 0, &data); break; @@ -469,6 +480,7 @@ static int counter_attr_create(struct device *const dev, case COUNTER_COMP_ENUM: case COUNTER_COMP_COUNT_DIRECTION: case COUNTER_COMP_COUNT_MODE: + case COUNTER_COMP_SIGNAL_POLARITY: if (comp->device_u32_read) { dev_attr->attr.mode |=3D 0444; dev_attr->show =3D counter_comp_u32_show; diff --git a/include/linux/counter.h b/include/linux/counter.h index 1fe17f5adb09..60428d06915d 100644 --- a/include/linux/counter.h +++ b/include/linux/counter.h @@ -31,6 +31,7 @@ enum counter_comp_type { COUNTER_COMP_ENUM, COUNTER_COMP_COUNT_DIRECTION, COUNTER_COMP_COUNT_MODE, + COUNTER_COMP_SIGNAL_POLARITY, }; =20 /** @@ -477,6 +478,15 @@ struct counter_available { #define COUNTER_COMP_FLOOR(_read, _write) \ COUNTER_COMP_COUNT_U64("floor", _read, _write) =20 +#define COUNTER_COMP_POLARITY(_read, _write, _available) \ +{ \ + .type =3D COUNTER_COMP_SIGNAL_POLARITY, \ + .name =3D "polarity", \ + .signal_u32_read =3D (_read), \ + .signal_u32_write =3D (_write), \ + .priv =3D &(_available), \ +} + #define COUNTER_COMP_PRESET(_read, _write) \ COUNTER_COMP_COUNT_U64("preset", _read, _write) =20 diff --git a/include/uapi/linux/counter.h b/include/uapi/linux/counter.h index 96c5ffd368ad..e9610e1944dc 100644 --- a/include/uapi/linux/counter.h +++ b/include/uapi/linux/counter.h @@ -153,4 +153,10 @@ enum counter_synapse_action { COUNTER_SYNAPSE_ACTION_BOTH_EDGES, }; =20 +/* Signal polarity values */ +enum counter_signal_polarity { + COUNTER_SIGNAL_POLARITY_POSITIVE, + COUNTER_SIGNAL_POLARITY_NEGATIVE, +}; + #endif /* _UAPI_COUNTER_H_ */ --=20 2.37.3 From nobody Thu Apr 2 21:38:45 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D60E2C54EE9 for ; Tue, 20 Sep 2022 20:01:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231167AbiITUBv (ORCPT ); Tue, 20 Sep 2022 16:01:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230382AbiITUBn (ORCPT ); Tue, 20 Sep 2022 16:01:43 -0400 Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99ACC52DE3 for ; Tue, 20 Sep 2022 13:01:42 -0700 (PDT) Received: by mail-oi1-x22d.google.com with SMTP id o184so5131053oif.13 for ; Tue, 20 Sep 2022 13:01:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=WopcYcPly2clGQMko18Z5Oo2qU5OZoDnJ7KQZMk3xww=; b=UvCzFRz2NVVkWyo1c0vM20+OTK1RHradyaDAIZcS02QmdlJiM6aZIJeS1GkO7RVPIv Gsp/MxAPYfj70si1NaVa8j5wtwbyP5Ka0j1gQoM35l2ZCHWurQW/eAK1uzOOmxonyITj K7YXixBh9+JQ43SzVROPMAo7J+CbD/Bp+K3lX0kDffFZdLlMhM5ZUuBFQI/P5D+uNGfg wYkBPOyUWLHFoj/MZzIzpr/1foC2XijSln4oIrtu1Hy1HQ3NL5ZOYI3epX42drdZTjZa Z4bjtaiwlMuOCGDROpokAtgqSJU7f8vEzcMo+Db6RMXoHYxTxbuiW5dAVZAC2lY/0lhe jfFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=WopcYcPly2clGQMko18Z5Oo2qU5OZoDnJ7KQZMk3xww=; b=Xp/pz8J8qCuT7biGA2y0pgnANNvpNOtZ3+5QoKAEznHUWneJ5sg6BpZZbc4vcgUVsC a/dFWwoDoJXyeEn3mKFfLR52kLOXHeQWodIeBJXYvCcJpsrz5RACmD6DDA79FVRnJV8K bFoGIufs52N/au907UyeiLhT1S2RXe8tkyPyhlYGTplvBFLQvW1yTxXzEhBuIlhjN2RK PF9VqpOKXyVAEz20rgxmDPAqcQLGD1LFJH0KLgQ3gjarXQnVK2WPbdHFiwzFknDCrQqx J9yb58G+Yrmys5JctP2A64zsxsiYLPGg6ugcxcA0ct47X77SoDf//RsJcckI/hC7TOYJ 3+Tw== X-Gm-Message-State: ACrzQf0ik0hw/On7n84w0TljpaCrKmIsRUn+OG7EiItF2Vxli6p0KDlh SSMQ2TH1yGIa0hwTGmrpm/QYJQ== X-Google-Smtp-Source: AMsMyM5kp/MxdnFF28P45v7t/0Ki1JDF05paDTrbPHa0Gr8RJh4a7QwTvH+z10O9+UuFQSEFhihSzg== X-Received: by 2002:aca:2319:0:b0:34b:a8d2:c604 with SMTP id e25-20020aca2319000000b0034ba8d2c604mr2440194oie.244.1663704101866; Tue, 20 Sep 2022 13:01:41 -0700 (PDT) Received: from fedora.attlocal.net (69-109-179-158.lightspeed.dybhfl.sbcglobal.net. [69.109.179.158]) by smtp.gmail.com with ESMTPSA id bm43-20020a0568081aab00b0034d14c6ce3dsm325634oib.16.2022.09.20.13.01.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 13:01:41 -0700 (PDT) From: William Breathitt Gray To: linux-iio@vger.kernel.org Cc: linux-kernel@vger.kernel.org, mranostay@ti.com, jpanis@baylibre.com, gwendal@chromium.org, bleung@chromium.org, groeck@chromium.org, jic23@kernel.org, david@lechnology.com, robertcnelson@gmail.com, William Breathitt Gray Subject: [PATCH v5 2/5] counter: 104-quad-8: Add Signal polarity component Date: Tue, 20 Sep 2022 13:21:26 -0400 Message-Id: <8b10f4718e17169dffd7b957e11b02257d91230e.1663693757.git.william.gray@linaro.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The 104-quad-8 driver provides support for Index signal polarity modes via the "index_polarity" Signal component. This patch exposes the same functionality through the more standard "polarity" Signal component. Signed-off-by: William Breathitt Gray Tested-by: Julien Panis --- drivers/counter/104-quad-8.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c index 1323edfbe40c..2a9d8259ed4b 100644 --- a/drivers/counter/104-quad-8.c +++ b/drivers/counter/104-quad-8.c @@ -549,6 +549,32 @@ static int quad8_index_polarity_set(struct counter_dev= ice *counter, return 0; } =20 +static int quad8_polarity_read(struct counter_device *counter, + struct counter_signal *signal, + enum counter_signal_polarity *polarity) +{ + int err; + u32 index_polarity; + + err =3D quad8_index_polarity_get(counter, signal, &index_polarity); + if (err) + return err; + + *polarity =3D (index_polarity) ? COUNTER_SIGNAL_POLARITY_POSITIVE : + COUNTER_SIGNAL_POLARITY_NEGATIVE; + + return 0; +} + +static int quad8_polarity_write(struct counter_device *counter, + struct counter_signal *signal, + enum counter_signal_polarity polarity) +{ + const u32 pol =3D (polarity =3D=3D COUNTER_SIGNAL_POLARITY_POSITIVE) ? 1 = : 0; + + return quad8_index_polarity_set(counter, signal, pol); +} + static const char *const quad8_synchronous_modes[] =3D { "non-synchronous", "synchronous" @@ -977,6 +1003,13 @@ static struct counter_comp quad8_signal_ext[] =3D { quad8_signal_fck_prescaler_write) }; =20 +static const enum counter_signal_polarity quad8_polarities[] =3D { + COUNTER_SIGNAL_POLARITY_POSITIVE, + COUNTER_SIGNAL_POLARITY_NEGATIVE, +}; + +static DEFINE_COUNTER_AVAILABLE(quad8_polarity_available, quad8_polarities= ); + static DEFINE_COUNTER_ENUM(quad8_index_pol_enum, quad8_index_polarity_mode= s); static DEFINE_COUNTER_ENUM(quad8_synch_mode_enum, quad8_synchronous_modes); =20 @@ -984,6 +1017,8 @@ static struct counter_comp quad8_index_ext[] =3D { COUNTER_COMP_SIGNAL_ENUM("index_polarity", quad8_index_polarity_get, quad8_index_polarity_set, quad8_index_pol_enum), + COUNTER_COMP_POLARITY(quad8_polarity_read, quad8_polarity_write, + quad8_polarity_available), COUNTER_COMP_SIGNAL_ENUM("synchronous_mode", quad8_synchronous_mode_get, quad8_synchronous_mode_set, quad8_synch_mode_enum), --=20 2.37.3 From nobody Thu Apr 2 21:38:45 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC11BC6FA82 for ; Tue, 20 Sep 2022 20:02:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231282AbiITUB6 (ORCPT ); Tue, 20 Sep 2022 16:01:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231137AbiITUBp (ORCPT ); Tue, 20 Sep 2022 16:01:45 -0400 Received: from mail-oa1-x2f.google.com (mail-oa1-x2f.google.com [IPv6:2001:4860:4864:20::2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5303452FD2 for ; Tue, 20 Sep 2022 13:01:44 -0700 (PDT) Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-12b542cb1d3so5836899fac.13 for ; Tue, 20 Sep 2022 13:01:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=lP9Jf81Swn6HKhzeqSgb5dx7kwZ1I6PvW+Qk6QnaJIM=; b=mn+XocFI9IgOzLf24JS8tHEgsTnBgE4LGh8VUQUZ/PdLXavL5/96BlY/5O437ZmoNj Ms1IbUvflE+mIMbwlxolfk8SsZg6frg4TgbF2e12wT+b8mQrgn+kBBPDMJr/2dv6D2JL Ey5Am5OPOuZdbFXYRCpk2h7eUd+ybr6y7vlyU8O0OdStNfKYfwC5lwXNBD3BgTYcFtkr lO0euV7UOctGTgyN1owGgZd9BFXLf1jfmEkOu0NDN274EcG/xaNfyNvWsQZSrxeY7fQ2 AuK2sMuGetebvnRi1HkKdG8Il5brmy+sFp9WTJNzYoco9/knhBTMPQM4ojA5Hk7EQU4T 7vAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=lP9Jf81Swn6HKhzeqSgb5dx7kwZ1I6PvW+Qk6QnaJIM=; b=J6J9WERCwNvAoLmoaZvDAr9cArkCFQ/rJy16aaVKz8KwIDqGAWoCEToRsJJify8Cku q2dBlavqpIBAhmhicE1Q/NNZVvuzI5MSskJOwz/aY4GZlVAn71IqGFpPBwI2WdGVkqyr doxt9oEHpFHqH73wZiWfbkJVZjoWG66YzGVkYgSPB1+catQ+6ZbGDYUyj28uJ5MdKYRL YlERfOWMUpkKkX2EOgjv7ZozdbdHdtJpIZ6AnIjrlzmjmVsVIoG9E8OaDUuOd94zUVat MPT6oQbSTY2W67fDHm+w1z1meFuSxBUtJTprSK2c4AMP9fWxeIbtvwiQYvrhrgI8LkiG Gqiw== X-Gm-Message-State: ACrzQf2PcSDJurbbV+0YVY8h7ce8E98JPc3AUNq07I15Q/RYq+cIIKPO DnONJflsz3FndVbjAABEgD+FQg== X-Google-Smtp-Source: AMsMyM6dx12VbH4+QCIEnfs+y56iuqMWJieydWsURcHHZvh8hsscCTrigL/e0w7CpvmWC06fgaRsLQ== X-Received: by 2002:a05:6870:352:b0:10e:d4ee:a3f2 with SMTP id n18-20020a056870035200b0010ed4eea3f2mr3094146oaf.172.1663704103435; Tue, 20 Sep 2022 13:01:43 -0700 (PDT) Received: from fedora.attlocal.net (69-109-179-158.lightspeed.dybhfl.sbcglobal.net. [69.109.179.158]) by smtp.gmail.com with ESMTPSA id bm43-20020a0568081aab00b0034d14c6ce3dsm325634oib.16.2022.09.20.13.01.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 13:01:43 -0700 (PDT) From: William Breathitt Gray To: linux-iio@vger.kernel.org Cc: linux-kernel@vger.kernel.org, mranostay@ti.com, jpanis@baylibre.com, gwendal@chromium.org, bleung@chromium.org, groeck@chromium.org, jic23@kernel.org, david@lechnology.com, robertcnelson@gmail.com, William Breathitt Gray Subject: [PATCH v5 3/5] counter: Introduce the Count capture component Date: Tue, 20 Sep 2022 13:21:27 -0400 Message-Id: X-Mailer: git-send-email 2.37.3 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Some devices provide a latch function to save historic Count values. This patch standardizes exposure of such functionality as Count capture components. A COUNTER_COMP_CAPTURE macro is provided for driver authors to define a capture component. A new event COUNTER_EVENT_CAPTURE is introduced to represent Count value capture events. Cc: Julien Panis Signed-off-by: William Breathitt Gray Tested-by: Julien Panis --- Documentation/ABI/testing/sysfs-bus-counter | 6 ++++++ include/linux/counter.h | 3 +++ include/uapi/linux/counter.h | 2 ++ 3 files changed, 11 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-counter b/Documentation/AB= I/testing/sysfs-bus-counter index a234022f9add..30b6e1faa6f6 100644 --- a/Documentation/ABI/testing/sysfs-bus-counter +++ b/Documentation/ABI/testing/sysfs-bus-counter @@ -4,6 +4,12 @@ Contact: linux-iio@vger.kernel.org Description: Count data of Count Y represented as a string. =20 +What: /sys/bus/counter/devices/counterX/countY/capture +KernelVersion: 6.1 +Contact: linux-iio@vger.kernel.org +Description: + Historical capture of the Count Y count data. + What: /sys/bus/counter/devices/counterX/countY/ceiling KernelVersion: 5.2 Contact: linux-iio@vger.kernel.org diff --git a/include/linux/counter.h b/include/linux/counter.h index 60428d06915d..2c6594c240d4 100644 --- a/include/linux/counter.h +++ b/include/linux/counter.h @@ -453,6 +453,9 @@ struct counter_available { .priv =3D &(_available), \ } =20 +#define COUNTER_COMP_CAPTURE(_read, _write) \ + COUNTER_COMP_COUNT_U64("capture", _read, _write) + #define COUNTER_COMP_CEILING(_read, _write) \ COUNTER_COMP_COUNT_U64("ceiling", _read, _write) =20 diff --git a/include/uapi/linux/counter.h b/include/uapi/linux/counter.h index e9610e1944dc..8ab12d731e3b 100644 --- a/include/uapi/linux/counter.h +++ b/include/uapi/linux/counter.h @@ -63,6 +63,8 @@ enum counter_event_type { COUNTER_EVENT_INDEX, /* State of counter is changed */ COUNTER_EVENT_CHANGE_OF_STATE, + /* Count value captured */ + COUNTER_EVENT_CAPTURE, }; =20 /** --=20 2.37.3 From nobody Thu Apr 2 21:38:45 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C45EC6FA91 for ; Tue, 20 Sep 2022 20:02:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231203AbiITUCC (ORCPT ); Tue, 20 Sep 2022 16:02:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231185AbiITUBw (ORCPT ); Tue, 20 Sep 2022 16:01:52 -0400 Received: from mail-oa1-x34.google.com (mail-oa1-x34.google.com [IPv6:2001:4860:4864:20::34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BB2952474 for ; Tue, 20 Sep 2022 13:01:45 -0700 (PDT) Received: by mail-oa1-x34.google.com with SMTP id 586e51a60fabf-1279948d93dso5874381fac.10 for ; Tue, 20 Sep 2022 13:01:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=B1QW5eCktyNKF1Kabrt/RgSIFVK+r7/SbP4DaTVv7K4=; b=CFtR9BmF/mRW3nRk8Fi0CTXIhc6ljBmuJPicWV16FOX/DcrG5bd5Xp7WKC34SqFRUF w1HC1d+7orsPsY5UIhG+6gq3wBT4/hCA1f7+5F8AEL4TZPakrdS2IYMIgaI/AYt6xVPK cMWNjErvdvZFch0+w4r9yGo1nnoJEx2grPtoxplFsoyajdlKE6Hf330LujxSsfv2VfEJ WQUUk/Nq89WsA2iIyf/PxjK+8EhXQ5Uep/Bd589gsdYG3UADxiIC3csqH1GzQSCrcix+ SoftkyB5dVVJoXZTX/PXsCCLz+20gNuhWp7bTExmcTZZeo3mCyQQdSGqGuH39+5wF/6a 4hmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=B1QW5eCktyNKF1Kabrt/RgSIFVK+r7/SbP4DaTVv7K4=; b=tBbNx1a3ph+3kWE5BpPEhGCr8vHLqJoHxu8waAnoRXDe2/PwX0gO14lTa2cbW2Bncq iL6u5BsGgE+lzMm8R9J2s79sCWsLsjfpCKnzWfZF3U1dgFEo08dJ9RZ6gPE/oYoNbgcI NVkr1QMp/foTbs7qnnQ7gNGATyx5CxXWnF7fRcq6oey1W7EhGOdNauPNYzskXrFTqBfw roDMxGJhLlXnqaGV4TQRozTzVwDpYznZ2Cfd2xcS6wO+E8Hs496MCboDPUFHnrwLC3gB eHm+FVdpnkEore+I1XOzkVlBApXllGRj+MdiBZP5vDq2IAxIAGzb2seT4BIlbVdob1QP PNLw== X-Gm-Message-State: ACrzQf115D4cUKgEuX4kz2pja11boY10vUWQDvdN4aMm7ex5fmMlbNJv ye4oYs9GUbi1RUpwXvKKu3gam80dgnBKOA== X-Google-Smtp-Source: AMsMyM5GtwOU/1tVl60AV9oj0dltona29WAUwji3TKeTc1p2ogvO1P54+2ujmc7IamK5+DeQ82tF6Q== X-Received: by 2002:a05:6870:9a1a:b0:120:8d35:c740 with SMTP id fo26-20020a0568709a1a00b001208d35c740mr3183927oab.166.1663704104876; Tue, 20 Sep 2022 13:01:44 -0700 (PDT) Received: from fedora.attlocal.net (69-109-179-158.lightspeed.dybhfl.sbcglobal.net. [69.109.179.158]) by smtp.gmail.com with ESMTPSA id bm43-20020a0568081aab00b0034d14c6ce3dsm325634oib.16.2022.09.20.13.01.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 13:01:44 -0700 (PDT) From: William Breathitt Gray To: linux-iio@vger.kernel.org Cc: linux-kernel@vger.kernel.org, mranostay@ti.com, jpanis@baylibre.com, gwendal@chromium.org, bleung@chromium.org, groeck@chromium.org, jic23@kernel.org, david@lechnology.com, robertcnelson@gmail.com, William Breathitt Gray Subject: [PATCH v5 4/5] counter: Consolidate Counter extension sysfs attribute creation Date: Tue, 20 Sep 2022 13:21:28 -0400 Message-Id: <58e248e11fa839ef12ca883883c92bedddd8de77.1663693757.git.william.gray@linaro.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Counter extensions are handled for the Device, Counts, and Signals. The code loops through each Counter extension and creates the expected sysfs attributes. This patch consolidates that code into functions to reduce redundancy and make the intention of the code clearer. Signed-off-by: William Breathitt Gray Tested-by: Julien Panis --- drivers/counter/counter-sysfs.c | 98 ++++++++++++++++----------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/drivers/counter/counter-sysfs.c b/drivers/counter/counter-sysf= s.c index e5dd36e1a45f..b393da402e0b 100644 --- a/drivers/counter/counter-sysfs.c +++ b/drivers/counter/counter-sysfs.c @@ -592,6 +592,46 @@ static int counter_comp_id_attr_create(struct device *= const dev, return 0; } =20 +static int counter_ext_attrs_create(struct device *const dev, + struct counter_attribute_group *const group, + const struct counter_comp *const ext, + const enum counter_scope scope, + void *const parent, const size_t id) +{ + int err; + + /* Create main extension attribute */ + err =3D counter_attr_create(dev, group, ext, scope, parent); + if (err < 0) + return err; + + /* Create extension id attribute */ + return counter_comp_id_attr_create(dev, group, ext->name, id); +} + +static int counter_sysfs_exts_add(struct device *const dev, + struct counter_attribute_group *const group, + const struct counter_comp *const exts, + const size_t num_ext, + const enum counter_scope scope, + void *const parent) +{ + size_t i; + const struct counter_comp *ext; + int err; + + /* Create attributes for each extension */ + for (i =3D 0; i < num_ext; i++) { + ext =3D &exts[i]; + err =3D counter_ext_attrs_create(dev, group, ext, scope, parent, + i); + if (err < 0) + return err; + } + + return 0; +} + static struct counter_comp counter_signal_comp =3D { .type =3D COUNTER_COMP_SIGNAL_LEVEL, .name =3D "signal", @@ -605,8 +645,6 @@ static int counter_signal_attrs_create(struct counter_d= evice *const counter, struct device *const dev =3D &counter->dev; int err; struct counter_comp comp; - size_t i; - struct counter_comp *ext; =20 /* Create main Signal attribute */ comp =3D counter_signal_comp; @@ -620,21 +658,9 @@ static int counter_signal_attrs_create(struct counter_= device *const counter, if (err < 0) return err; =20 - /* Create an attribute for each extension */ - for (i =3D 0; i < signal->num_ext; i++) { - ext =3D &signal->ext[i]; - - err =3D counter_attr_create(dev, cattr_group, ext, scope, signal); - if (err < 0) - return err; - - err =3D counter_comp_id_attr_create(dev, cattr_group, ext->name, - i); - if (err < 0) - return err; - } - - return 0; + /* Add Signal extensions */ + return counter_sysfs_exts_add(dev, cattr_group, signal->ext, + signal->num_ext, scope, signal); } =20 static int counter_sysfs_signals_add(struct counter_device *const counter, @@ -719,8 +745,6 @@ static int counter_count_attrs_create(struct counter_de= vice *const counter, struct device *const dev =3D &counter->dev; int err; struct counter_comp comp; - size_t i; - struct counter_comp *ext; =20 /* Create main Count attribute */ comp =3D counter_count_comp; @@ -743,21 +767,9 @@ static int counter_count_attrs_create(struct counter_d= evice *const counter, if (err < 0) return err; =20 - /* Create an attribute for each extension */ - for (i =3D 0; i < count->num_ext; i++) { - ext =3D &count->ext[i]; - - err =3D counter_attr_create(dev, cattr_group, ext, scope, count); - if (err < 0) - return err; - - err =3D counter_comp_id_attr_create(dev, cattr_group, ext->name, - i); - if (err < 0) - return err; - } - - return 0; + /* Add Count extensions */ + return counter_sysfs_exts_add(dev, cattr_group, count->ext, + count->num_ext, scope, count); } =20 static int counter_sysfs_counts_add(struct counter_device *const counter, @@ -850,8 +862,6 @@ static int counter_sysfs_attr_add(struct counter_device= *const counter, const enum counter_scope scope =3D COUNTER_SCOPE_DEVICE; struct device *const dev =3D &counter->dev; int err; - size_t i; - struct counter_comp *ext; =20 /* Add Signals sysfs attributes */ err =3D counter_sysfs_signals_add(counter, cattr_group); @@ -888,19 +898,9 @@ static int counter_sysfs_attr_add(struct counter_devic= e *const counter, if (err < 0) return err; =20 - /* Create an attribute for each extension */ - for (i =3D 0; i < counter->num_ext; i++) { - ext =3D &counter->ext[i]; - - err =3D counter_attr_create(dev, cattr_group, ext, scope, NULL); - if (err < 0) - return err; - - err =3D counter_comp_id_attr_create(dev, cattr_group, ext->name, - i); - if (err < 0) - return err; - } + /* Add device extensions */ + return counter_sysfs_exts_add(dev, cattr_group, counter->ext, + counter->num_ext, scope, NULL); =20 return 0; } --=20 2.37.3 From nobody Thu Apr 2 21:38:45 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4FCF2C54EE9 for ; Tue, 20 Sep 2022 20:02:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231478AbiITUCG (ORCPT ); Tue, 20 Sep 2022 16:02:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231254AbiITUBy (ORCPT ); Tue, 20 Sep 2022 16:01:54 -0400 Received: from mail-oa1-x31.google.com (mail-oa1-x31.google.com [IPv6:2001:4860:4864:20::31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 069A65B79E for ; Tue, 20 Sep 2022 13:01:46 -0700 (PDT) Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-11eab59db71so5862009fac.11 for ; Tue, 20 Sep 2022 13:01:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=yGF5JgvQ8ZJIL1SqTUp8L/aOCQ0AR2H4mstGI+qgJdg=; b=ufbQ1reW8kF15zWCoCf+ICEIez9O3Bt9iktBZxoxwGrSxVdbkNz6yTH9zAbYft+W8D 4Ajd6IfNZ7H3pVUEmtvl8Er6hmyPZZPbpGQaXOdnKnh+CsA11vOD5IgzjTI9qLAGbsZp uOcTygKI+14t8ykjKNYBlfaqb+ddhPMo5Tf8XMEaIfM470JpyY9Mlmw5vj0YhIdPS2qR iYzw6KgU5Tfw+cp75szxD5tU5HLECupPmvQyYFNRJPubsraqO++63vMjsDuXnefCnAn7 3vZzxB2at7gSLdm8MyKq8PsqfNWQHa5kgBCvsbTPbIXpMTsw2k7B6AWG29WeikqzjjqH wKqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=yGF5JgvQ8ZJIL1SqTUp8L/aOCQ0AR2H4mstGI+qgJdg=; b=jwILSwb4c9guPuSVxl1A7F9HjYfSXUj+Atw9PaKloQyuW6KcwkzjRFMhzLms48CJLZ kj94geDc4/7i8xqzVE9NGaOIIbwdO3IBRCuwYqB67r+YeEZ/Z7822worRq7mIBgRWzwf 098m7dHr502frPCG2d8glbGwcE4nWMWURy2H30nYLxkS3yQDQKJDpIiyD82qn+tRnMfC TDuGgdzb0630LnINLQ7eFdjU7LmWwaUVz0Dvk//FF3Vb6x3i9uYnSb7ZKd4fS5T9NsvY Tj1I6N3MVoJf7dJ2UY3PJLmBebVJ5W8SajCfjRuzWzS3LNrj3Brl9MHHLvjsOPRsgrTV jgJA== X-Gm-Message-State: ACrzQf3D7O3rqGFmLkdUGQ5GZf696EsCGJX/AWnjUO2m9MNULOLyWuaK IuWA3o1FpN2l3vBb0NDFvGsPgg== X-Google-Smtp-Source: AMsMyM6/SNdxyfeG/XlixPUOfRZww2U2RWAKpG74JXSJTDsciTHuIBedK6AurYyvJe4GLuZi8K8dww== X-Received: by 2002:a05:6871:725:b0:127:96e8:21c with SMTP id f37-20020a056871072500b0012796e8021cmr3118973oap.104.1663704106079; Tue, 20 Sep 2022 13:01:46 -0700 (PDT) Received: from fedora.attlocal.net (69-109-179-158.lightspeed.dybhfl.sbcglobal.net. [69.109.179.158]) by smtp.gmail.com with ESMTPSA id bm43-20020a0568081aab00b0034d14c6ce3dsm325634oib.16.2022.09.20.13.01.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 13:01:45 -0700 (PDT) From: William Breathitt Gray To: linux-iio@vger.kernel.org Cc: linux-kernel@vger.kernel.org, mranostay@ti.com, jpanis@baylibre.com, gwendal@chromium.org, bleung@chromium.org, groeck@chromium.org, jic23@kernel.org, david@lechnology.com, robertcnelson@gmail.com, William Breathitt Gray Subject: [PATCH v5 5/5] counter: Introduce the COUNTER_COMP_ARRAY component type Date: Tue, 20 Sep 2022 13:21:29 -0400 Message-Id: <8a1490580658cbd9c9f0f65ba075c518fb60ba2b.1663693757.git.william.gray@linaro.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The COUNTER_COMP_ARRAY Counter component type is introduced to enable support for Counter array components. With Counter array components, exposure for buffers on counter devices can be defined via new Counter array component macros. This should simplify code for driver authors who would otherwise need to define individual Counter components for each array element. Eight Counter array component macros are introduced:: DEFINE_COUNTER_ARRAY_U64(_name, _length) DEFINE_COUNTER_ARRAY_CAPTURE(_name, _length) DEFINE_COUNTER_ARRAY_POLARITY(_name, _enums, _length) COUNTER_COMP_DEVICE_ARRAY_U64(_name, _read, _write, _array) COUNTER_COMP_COUNT_ARRAY_U64(_name, _read, _write, _array) COUNTER_COMP_SIGNAL_ARRAY_U64(_name, _read, _write, _array) COUNTER_COMP_ARRAY_CAPTURE(_read, _write, _array) COUNTER_COMP_ARRAY_POLARITY(_read, _write, _array) Eight Counter array callbacks are introduced as well:: int (*signal_array_u32_read)(struct counter_device *counter, struct counter_signal *signal, size_t idx, u32 *val); int (*signal_array_u32_write)(struct counter_device *counter, struct counter_signal *signal, size_t idx, u32 val); int (*device_array_u64_read)(struct counter_device *counter, size_t idx, u64 *val); int (*count_array_u64_read)(struct counter_device *counter, struct counter_count *count, size_t idx, u64 *val); int (*signal_array_u64_read)(struct counter_device *counter, struct counter_signal *signal, size_t idx, u64 *val); int (*device_array_u64_write)(struct counter_device *counter, size_t idx, u64 val); int (*count_array_u64_write)(struct counter_device *counter, struct counter_count *count, size_t idx, u64 val); int (*signal_array_u64_write)(struct counter_device *counter, struct counter_signal *signal, size_t idx, u64 val); Driver authors can handle reads/writes for an array component by receiving an element index via the `idx` parameter and processing the respective value via the `val` parameter. For example, suppose a driver wants to expose a Count's read-only capture buffer of four elements using a callback `foobar_capture_read()`:: DEFINE_COUNTER_ARRAY_CAPTURE(foobar_capture_array, 4); COUNTER_COMP_ARRAY_CAPTURE(foobar_capture_read, NULL, foobar_capture_array) Respective sysfs attributes for each array element would appear for the respective Count: * /sys/bus/counter/devices/counterX/countY/capture0 * /sys/bus/counter/devices/counterX/countY/capture1 * /sys/bus/counter/devices/counterX/countY/capture2 * /sys/bus/counter/devices/counterX/countY/capture3 If a user tries to read _capture2_ for example, `idx` will be `2` when passed to the `foobar_capture_read()` callback, and thus the driver knows which array element to handle. Counter arrays for polarity elements can be defined in a similar manner:: const enum counter_signal_polarity foobar_polarity_states[] =3D { COUNTER_SIGNAL_POLARITY_POSITIVE, COUNTER_SIGNAL_POLARITY_NEGATIVE, }; DEFINE_COUNTER_ARRAY_POLARITY(foobar_polarity_array, foobar_polarity_states, 4); COUNTER_COMP_ARRAY_POLARITY(foobar_polarity_read, foobar_polarity_write, foobar_polarity_array) Cc: Julien Panis Signed-off-by: William Breathitt Gray Tested-by: Julien Panis --- drivers/counter/counter-chrdev.c | 134 ++++++++++++++++++--- drivers/counter/counter-sysfs.c | 198 ++++++++++++++++++++++++++++++- include/linux/counter.h | 134 +++++++++++++++++++++ 3 files changed, 446 insertions(+), 20 deletions(-) diff --git a/drivers/counter/counter-chrdev.c b/drivers/counter/counter-chr= dev.c index 120879ee2e87..80acdf62794a 100644 --- a/drivers/counter/counter-chrdev.c +++ b/drivers/counter/counter-chrdev.c @@ -40,7 +40,11 @@ struct counter_comp_node { a.signal_u32_read =3D=3D b.signal_u32_read || \ a.device_u64_read =3D=3D b.device_u64_read || \ a.count_u64_read =3D=3D b.count_u64_read || \ - a.signal_u64_read =3D=3D b.signal_u64_read) + a.signal_u64_read =3D=3D b.signal_u64_read || \ + a.signal_array_u32_read =3D=3D b.signal_array_u32_read || \ + a.device_array_u64_read =3D=3D b.device_array_u64_read || \ + a.count_array_u64_read =3D=3D b.count_array_u64_read || \ + a.signal_array_u64_read =3D=3D b.signal_array_u64_read) =20 #define counter_comp_read_is_set(comp) \ (comp.action_read || \ @@ -52,7 +56,11 @@ struct counter_comp_node { comp.signal_u32_read || \ comp.device_u64_read || \ comp.count_u64_read || \ - comp.signal_u64_read) + comp.signal_u64_read || \ + comp.signal_array_u32_read || \ + comp.device_array_u64_read || \ + comp.count_array_u64_read || \ + comp.signal_array_u64_read) =20 static ssize_t counter_chrdev_read(struct file *filp, char __user *buf, size_t len, loff_t *f_ps) @@ -228,6 +236,31 @@ static int counter_disable_events(struct counter_devic= e *const counter) return err; } =20 +static int counter_get_ext(const struct counter_comp *const ext, + const size_t num_ext, const size_t component_id, + size_t *const ext_idx, size_t *const id) +{ + struct counter_array *element; + + *id =3D 0; + for (*ext_idx =3D 0; *ext_idx < num_ext; (*ext_idx)++) { + if (*id =3D=3D component_id) + return 0; + + if (ext->type =3D=3D COUNTER_COMP_ARRAY) { + element =3D ext->priv; + + if (component_id - *id < element->length) + return 0; + + *id +=3D element->length; + } else + (*id)++; + } + + return -EINVAL; +} + static int counter_add_watch(struct counter_device *const counter, const unsigned long arg) { @@ -237,6 +270,7 @@ static int counter_add_watch(struct counter_device *con= st counter, size_t parent, id; struct counter_comp *ext; size_t num_ext; + size_t ext_idx, ext_id; int err =3D 0; =20 if (copy_from_user(&watch, uwatch, sizeof(watch))) @@ -314,11 +348,11 @@ static int counter_add_watch(struct counter_device *c= onst counter, comp_node.comp.priv =3D counter->counts[parent].synapses + id; break; case COUNTER_COMPONENT_EXTENSION: - if (id >=3D num_ext) - return -EINVAL; - id =3D array_index_nospec(id, num_ext); + err =3D counter_get_ext(ext, num_ext, id, &ext_idx, &ext_id); + if (err < 0) + return err; =20 - comp_node.comp =3D ext[id]; + comp_node.comp =3D ext[ext_idx]; break; default: return -EINVAL; @@ -451,14 +485,56 @@ void counter_chrdev_remove(struct counter_device *con= st counter) kfifo_free(&counter->events); } =20 +static int counter_get_array_data(struct counter_device *const counter, + const enum counter_scope scope, + void *const parent, + const struct counter_comp *const comp, + const size_t idx, u64 *const value) +{ + const struct counter_array *const element =3D comp->priv; + u32 value_u32 =3D 0; + int ret; + + switch (element->type) { + case COUNTER_COMP_SIGNAL_POLARITY: + if (scope !=3D COUNTER_SCOPE_SIGNAL) + return -EINVAL; + ret =3D comp->signal_array_u32_read(counter, parent, idx, + &value_u32); + *value =3D value_u32; + return ret; + case COUNTER_COMP_U64: + switch (scope) { + case COUNTER_SCOPE_DEVICE: + return comp->device_array_u64_read(counter, idx, value); + case COUNTER_SCOPE_SIGNAL: + return comp->signal_array_u64_read(counter, parent, idx, + value); + case COUNTER_SCOPE_COUNT: + return comp->count_array_u64_read(counter, parent, idx, + value); + default: + return -EINVAL; + } + default: + return -EINVAL; + } +} + static int counter_get_data(struct counter_device *const counter, const struct counter_comp_node *const comp_node, u64 *const value) { const struct counter_comp *const comp =3D &comp_node->comp; - void *const parent =3D comp_node->parent; + const enum counter_scope scope =3D comp_node->component.scope; + const size_t id =3D comp_node->component.id; + struct counter_signal *const signal =3D comp_node->parent; + struct counter_count *const count =3D comp_node->parent; u8 value_u8 =3D 0; u32 value_u32 =3D 0; + const struct counter_comp *ext; + size_t num_ext; + size_t ext_idx, ext_id; int ret; =20 if (comp_node->component.type =3D=3D COUNTER_COMPONENT_NONE) @@ -467,15 +543,15 @@ static int counter_get_data(struct counter_device *co= nst counter, switch (comp->type) { case COUNTER_COMP_U8: case COUNTER_COMP_BOOL: - switch (comp_node->component.scope) { + switch (scope) { case COUNTER_SCOPE_DEVICE: ret =3D comp->device_u8_read(counter, &value_u8); break; case COUNTER_SCOPE_SIGNAL: - ret =3D comp->signal_u8_read(counter, parent, &value_u8); + ret =3D comp->signal_u8_read(counter, signal, &value_u8); break; case COUNTER_SCOPE_COUNT: - ret =3D comp->count_u8_read(counter, parent, &value_u8); + ret =3D comp->count_u8_read(counter, count, &value_u8); break; default: return -EINVAL; @@ -488,16 +564,16 @@ static int counter_get_data(struct counter_device *co= nst counter, case COUNTER_COMP_COUNT_DIRECTION: case COUNTER_COMP_COUNT_MODE: case COUNTER_COMP_SIGNAL_POLARITY: - switch (comp_node->component.scope) { + switch (scope) { case COUNTER_SCOPE_DEVICE: ret =3D comp->device_u32_read(counter, &value_u32); break; case COUNTER_SCOPE_SIGNAL: - ret =3D comp->signal_u32_read(counter, parent, + ret =3D comp->signal_u32_read(counter, signal, &value_u32); break; case COUNTER_SCOPE_COUNT: - ret =3D comp->count_u32_read(counter, parent, &value_u32); + ret =3D comp->count_u32_read(counter, count, &value_u32); break; default: return -EINVAL; @@ -505,21 +581,43 @@ static int counter_get_data(struct counter_device *co= nst counter, *value =3D value_u32; return ret; case COUNTER_COMP_U64: - switch (comp_node->component.scope) { + switch (scope) { case COUNTER_SCOPE_DEVICE: return comp->device_u64_read(counter, value); case COUNTER_SCOPE_SIGNAL: - return comp->signal_u64_read(counter, parent, value); + return comp->signal_u64_read(counter, signal, value); case COUNTER_SCOPE_COUNT: - return comp->count_u64_read(counter, parent, value); + return comp->count_u64_read(counter, count, value); default: return -EINVAL; } case COUNTER_COMP_SYNAPSE_ACTION: - ret =3D comp->action_read(counter, parent, comp->priv, - &value_u32); + ret =3D comp->action_read(counter, count, comp->priv, &value_u32); *value =3D value_u32; return ret; + case COUNTER_COMP_ARRAY: + switch (scope) { + case COUNTER_SCOPE_DEVICE: + ext =3D counter->ext; + num_ext =3D counter->num_ext; + break; + case COUNTER_SCOPE_SIGNAL: + ext =3D signal->ext; + num_ext =3D signal->num_ext; + break; + case COUNTER_SCOPE_COUNT: + ext =3D count->ext; + num_ext =3D count->num_ext; + break; + default: + return -EINVAL; + } + ret =3D counter_get_ext(ext, num_ext, id, &ext_idx, &ext_id); + if (ret < 0) + return ret; + + return counter_get_array_data(counter, scope, comp_node->parent, + comp, id - ext_id, value); default: return -EINVAL; } diff --git a/drivers/counter/counter-sysfs.c b/drivers/counter/counter-sysf= s.c index b393da402e0b..b9efe66f9f8d 100644 --- a/drivers/counter/counter-sysfs.c +++ b/drivers/counter/counter-sysfs.c @@ -352,6 +352,124 @@ static ssize_t counter_comp_u64_store(struct device *= dev, return len; } =20 +static ssize_t counter_comp_array_u32_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + const struct counter_attribute *const a =3D to_counter_attribute(attr); + struct counter_device *const counter =3D counter_from_dev(dev); + const struct counter_array *const element =3D a->comp.priv; + int err; + u32 data =3D 0; + + if (a->scope !=3D COUNTER_SCOPE_SIGNAL || + element->type !=3D COUNTER_COMP_SIGNAL_POLARITY) + return -EINVAL; + + err =3D a->comp.signal_array_u32_read(counter, a->parent, element->idx, + &data); + if (err < 0) + return err; + + return sysfs_emit(buf, "%s\n", counter_signal_polarity_str[data]); +} + +static ssize_t counter_comp_array_u32_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + const struct counter_attribute *const a =3D to_counter_attribute(attr); + struct counter_device *const counter =3D counter_from_dev(dev); + const struct counter_array *const element =3D a->comp.priv; + int err; + u32 data =3D 0; + + if (element->type !=3D COUNTER_COMP_SIGNAL_POLARITY || + a->scope !=3D COUNTER_SCOPE_SIGNAL) + return -EINVAL; + + err =3D counter_find_enum(&data, element->avail->enums, + element->avail->num_items, buf, + counter_signal_polarity_str); + if (err < 0) + return err; + + err =3D a->comp.signal_array_u32_write(counter, a->parent, element->idx, + data); + if (err < 0) + return err; + + return len; +} + +static ssize_t counter_comp_array_u64_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + const struct counter_attribute *const a =3D to_counter_attribute(attr); + struct counter_device *const counter =3D counter_from_dev(dev); + const struct counter_array *const element =3D a->comp.priv; + int err; + u64 data =3D 0; + + switch (a->scope) { + case COUNTER_SCOPE_DEVICE: + err =3D a->comp.device_array_u64_read(counter, element->idx, + &data); + break; + case COUNTER_SCOPE_SIGNAL: + err =3D a->comp.signal_array_u64_read(counter, a->parent, + element->idx, &data); + break; + case COUNTER_SCOPE_COUNT: + err =3D a->comp.count_array_u64_read(counter, a->parent, + element->idx, &data); + break; + default: + return -EINVAL; + } + if (err < 0) + return err; + + return sysfs_emit(buf, "%llu\n", (unsigned long long)data); +} + +static ssize_t counter_comp_array_u64_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + const struct counter_attribute *const a =3D to_counter_attribute(attr); + struct counter_device *const counter =3D counter_from_dev(dev); + const struct counter_array *const element =3D a->comp.priv; + int err; + u64 data =3D 0; + + err =3D kstrtou64(buf, 0, &data); + if (err < 0) + return err; + + switch (a->scope) { + case COUNTER_SCOPE_DEVICE: + err =3D a->comp.device_array_u64_write(counter, element->idx, + data); + break; + case COUNTER_SCOPE_SIGNAL: + err =3D a->comp.signal_array_u64_write(counter, a->parent, + element->idx, data); + break; + case COUNTER_SCOPE_COUNT: + err =3D a->comp.count_array_u64_write(counter, a->parent, + element->idx, data); + break; + default: + return -EINVAL; + } + if (err < 0) + return err; + + return len; +} + static ssize_t enums_available_show(const u32 *const enums, const size_t num_enums, const char *const strs[], char *buf) @@ -446,6 +564,7 @@ static int counter_attr_create(struct device *const dev, const enum counter_scope scope, void *const parent) { + const struct counter_array *const array =3D comp->priv; struct counter_attribute *counter_attr; struct device_attribute *dev_attr; =20 @@ -500,6 +619,32 @@ static int counter_attr_create(struct device *const de= v, dev_attr->store =3D counter_comp_u64_store; } break; + case COUNTER_COMP_ARRAY: + switch (array->type) { + case COUNTER_COMP_SIGNAL_POLARITY: + if (comp->signal_array_u32_read) { + dev_attr->attr.mode |=3D 0444; + dev_attr->show =3D counter_comp_array_u32_show; + } + if (comp->signal_array_u32_write) { + dev_attr->attr.mode |=3D 0200; + dev_attr->store =3D counter_comp_array_u32_store; + } + break; + case COUNTER_COMP_U64: + if (comp->device_array_u64_read) { + dev_attr->attr.mode |=3D 0444; + dev_attr->show =3D counter_comp_array_u64_show; + } + if (comp->device_array_u64_write) { + dev_attr->attr.mode |=3D 0200; + dev_attr->store =3D counter_comp_array_u64_store; + } + break; + default: + return -EINVAL; + } + break; default: return -EINVAL; } @@ -609,6 +754,45 @@ static int counter_ext_attrs_create(struct device *con= st dev, return counter_comp_id_attr_create(dev, group, ext->name, id); } =20 +static int counter_array_attrs_create(struct device *const dev, + struct counter_attribute_group *const group, + const struct counter_comp *const comp, + const enum counter_scope scope, + void *const parent, const size_t id) +{ + const struct counter_array *const array =3D comp->priv; + struct counter_comp ext =3D *comp; + struct counter_array *element; + size_t idx; + int err; + + /* Create an attribute for each array element */ + for (idx =3D 0; idx < array->length; idx++) { + /* Generate array element attribute name */ + ext.name =3D devm_kasprintf(dev, GFP_KERNEL, "%s%zu", comp->name, + idx); + if (!ext.name) + return -ENOMEM; + + /* Allocate and configure array element */ + element =3D devm_kzalloc(dev, sizeof(*element), GFP_KERNEL); + if (!element) + return -ENOMEM; + element->type =3D array->type; + element->avail =3D array->avail; + element->idx =3D idx; + ext.priv =3D element; + + /* Create all attributes associated with the array element */ + err =3D counter_ext_attrs_create(dev, group, &ext, scope, parent, + id + idx); + if (err < 0) + return err; + } + + return 0; +} + static int counter_sysfs_exts_add(struct device *const dev, struct counter_attribute_group *const group, const struct counter_comp *const exts, @@ -619,12 +803,22 @@ static int counter_sysfs_exts_add(struct device *cons= t dev, size_t i; const struct counter_comp *ext; int err; + size_t id =3D 0; + const struct counter_array *array; =20 /* Create attributes for each extension */ for (i =3D 0; i < num_ext; i++) { ext =3D &exts[i]; - err =3D counter_ext_attrs_create(dev, group, ext, scope, parent, - i); + if (ext->type =3D=3D COUNTER_COMP_ARRAY) { + err =3D counter_array_attrs_create(dev, group, ext, scope, + parent, id); + array =3D ext->priv; + id +=3D array->length; + } else { + err =3D counter_ext_attrs_create(dev, group, ext, scope, + parent, id); + id++; + } if (err < 0) return err; } diff --git a/include/linux/counter.h b/include/linux/counter.h index 2c6594c240d4..6eb3ae7b4fcb 100644 --- a/include/linux/counter.h +++ b/include/linux/counter.h @@ -32,6 +32,7 @@ enum counter_comp_type { COUNTER_COMP_COUNT_DIRECTION, COUNTER_COMP_COUNT_MODE, COUNTER_COMP_SIGNAL_POLARITY, + COUNTER_COMP_ARRAY, }; =20 /** @@ -69,6 +70,30 @@ enum counter_comp_type { * @signal_u64_read: Signal u64 component read callback. The read value of * the respective Signal u64 component should be passed * back via the val parameter. + * @signal_array_u32_read: Signal u32 array component read callback. The + * index of the respective Count u32 array + * component element is passed via the idx + * parameter. The read value of the respective + * Count u32 array component element should be + * passed back via the val parameter. + * @device_array_u64_read: Device u64 array component read callback. The + * index of the respective Device u64 array + * component element is passed via the idx + * parameter. The read value of the respective + * Device u64 array component element should be + * passed back via the val parameter. + * @count_array_u64_read: Count u64 array component read callback. The + * index of the respective Count u64 array + * component element is passed via the idx + * parameter. The read value of the respective + * Count u64 array component element should be + * passed back via the val parameter. + * @signal_array_u64_read: Signal u64 array component read callback. The + * index of the respective Count u64 array + * component element is passed via the idx + * parameter. The read value of the respective + * Count u64 array component element should be + * passed back via the val parameter. * @action_write: Synapse action mode write callback. The write value of * the respective Synapse action mode is passed via the * action parameter. @@ -99,6 +124,30 @@ enum counter_comp_type { * @signal_u64_write: Signal u64 component write callback. The write valu= e of * the respective Signal u64 component is passed via the * val parameter. + * @signal_array_u32_write: Signal u32 array component write callback. The + * index of the respective Signal u32 array + * component element is passed via the idx + * parameter. The write value of the respective + * Signal u32 array component element is passed via + * the val parameter. + * @device_array_u64_write: Device u64 array component write callback. The + * index of the respective Device u64 array + * component element is passed via the idx + * parameter. The write value of the respective + * Device u64 array component element is passed via + * the val parameter. + * @count_array_u64_write: Count u64 array component write callback. The + * index of the respective Count u64 array + * component element is passed via the idx + * parameter. The write value of the respective + * Count u64 array component element is passed via + * the val parameter. + * @signal_array_u64_write: Signal u64 array component write callback. The + * index of the respective Signal u64 array + * component element is passed via the idx + * parameter. The write value of the respective + * Signal u64 array component element is passed via + * the val parameter. */ struct counter_comp { enum counter_comp_type type; @@ -126,6 +175,17 @@ struct counter_comp { struct counter_count *count, u64 *val); int (*signal_u64_read)(struct counter_device *counter, struct counter_signal *signal, u64 *val); + int (*signal_array_u32_read)(struct counter_device *counter, + struct counter_signal *signal, + size_t idx, u32 *val); + int (*device_array_u64_read)(struct counter_device *counter, + size_t idx, u64 *val); + int (*count_array_u64_read)(struct counter_device *counter, + struct counter_count *count, + size_t idx, u64 *val); + int (*signal_array_u64_read)(struct counter_device *counter, + struct counter_signal *signal, + size_t idx, u64 *val); }; union { int (*action_write)(struct counter_device *counter, @@ -149,6 +209,17 @@ struct counter_comp { struct counter_count *count, u64 val); int (*signal_u64_write)(struct counter_device *counter, struct counter_signal *signal, u64 val); + int (*signal_array_u32_write)(struct counter_device *counter, + struct counter_signal *signal, + size_t idx, u32 val); + int (*device_array_u64_write)(struct counter_device *counter, + size_t idx, u64 val); + int (*count_array_u64_write)(struct counter_device *counter, + struct counter_count *count, + size_t idx, u64 val); + int (*signal_array_u64_write)(struct counter_device *counter, + struct counter_signal *signal, + size_t idx, u64 val); }; }; =20 @@ -453,6 +524,57 @@ struct counter_available { .priv =3D &(_available), \ } =20 +struct counter_array { + enum counter_comp_type type; + const struct counter_available *avail; + union { + size_t length; + size_t idx; + }; +}; + +#define DEFINE_COUNTER_ARRAY_U64(_name, _length) \ + struct counter_array _name =3D { \ + .type =3D COUNTER_COMP_U64, \ + .length =3D (_length), \ + } + +#define DEFINE_COUNTER_ARRAY_CAPTURE(_name, _length) \ + DEFINE_COUNTER_ARRAY_U64(_name, _length) + +#define DEFINE_COUNTER_ARRAY_POLARITY(_name, _enums, _length) \ + DEFINE_COUNTER_AVAILABLE(_name##_available, _enums); \ + struct counter_array _name =3D { \ + .type =3D COUNTER_COMP_SIGNAL_POLARITY, \ + .avail =3D &(_name##_available), \ + .length =3D (_length), \ + } + +#define COUNTER_COMP_DEVICE_ARRAY_U64(_name, _read, _write, _array) \ +{ \ + .type =3D COUNTER_COMP_ARRAY, \ + .name =3D (_name), \ + .device_array_u64_read =3D (_read), \ + .device_array_u64_write =3D (_write), \ + .priv =3D &(_array), \ +} +#define COUNTER_COMP_COUNT_ARRAY_U64(_name, _read, _write, _array) \ +{ \ + .type =3D COUNTER_COMP_ARRAY, \ + .name =3D (_name), \ + .count_array_u64_read =3D (_read), \ + .count_array_u64_write =3D (_write), \ + .priv =3D &(_array), \ +} +#define COUNTER_COMP_SIGNAL_ARRAY_U64(_name, _read, _write, _array) \ +{ \ + .type =3D COUNTER_COMP_ARRAY, \ + .name =3D (_name), \ + .signal_array_u64_read =3D (_read), \ + .signal_array_u64_write =3D (_write), \ + .priv =3D &(_array), \ +} + #define COUNTER_COMP_CAPTURE(_read, _write) \ COUNTER_COMP_COUNT_U64("capture", _read, _write) =20 @@ -496,4 +618,16 @@ struct counter_available { #define COUNTER_COMP_PRESET_ENABLE(_read, _write) \ COUNTER_COMP_COUNT_BOOL("preset_enable", _read, _write) =20 +#define COUNTER_COMP_ARRAY_CAPTURE(_read, _write, _array) \ + COUNTER_COMP_COUNT_ARRAY_U64("capture", _read, _write, _array) + +#define COUNTER_COMP_ARRAY_POLARITY(_read, _write, _array) \ +{ \ + .type =3D COUNTER_COMP_ARRAY, \ + .name =3D "polarity", \ + .signal_array_u32_read =3D (_read), \ + .signal_array_u32_write =3D (_write), \ + .priv =3D &(_array), \ +} + #endif /* _COUNTER_H_ */ --=20 2.37.3