From nobody Tue Apr 7 10:52:40 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 53AF5ECAAA1 for ; Sat, 17 Sep 2022 01:16:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229821AbiIQBQj (ORCPT ); Fri, 16 Sep 2022 21:16:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbiIQBQc (ORCPT ); Fri, 16 Sep 2022 21:16:32 -0400 Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF47822BF8 for ; Fri, 16 Sep 2022 18:16:31 -0700 (PDT) Received: by mail-qk1-x730.google.com with SMTP id y2so14521497qkl.11 for ; Fri, 16 Sep 2022 18:16:31 -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=ZWmtlqwjalwbyKw/Fcj9jEMqxbpTWmVENNin+d9iBuc=; b=EKVdNJWZOaVxvLS8EvGyyXR82e46oPh7T3DOiRxI/kalrPlPv3Ed1IPGdbEdhBath+ esjb7cKYxvG2GI9ICA1zupnSIc/bJIW8nMUDdtnliH+KprsWRGJPO+hjqsRX52i3ZyqL 9QAi/UuELRmOlx3Do691nXqwp8xZddehJRwBBsa32KvTs/Dl5j5Bst0/OjoksxfkI5/Y YDgVFfbrrNUTb4MSfOsOF9KtbjCmWx3h9rsuoQu0SJOZkTMBH5MxNTc4q4LYDQ9d1UXQ upJUqjG7kPVr1GTmYRdZvrFxTbB1tbRuOFRkZaQtZn5JQN59qwWZRoyTs4dkrHgx9Us5 rzEA== 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=ZWmtlqwjalwbyKw/Fcj9jEMqxbpTWmVENNin+d9iBuc=; b=722Lx6eHZdH4zbRpKxX1dK563efBk1Puie5vRvaxsa5E1TakJ61+oBw4kuc9/vGIPm jk5AvL0bGjSPdNEC0F4xE80qFdMU3R84m+YAUe1WT99Plmpf1S/0dv6Mnx+5BHhqbTRl OdQSRXRlMnC4poAJsp4ROUdpv0R8EmBHv1bY1gsqTSkVe7ik+sC+PNxu0188Fk1LJ7fA sGDcBVe4opoJ01DYT11prK6AvwhyRXatI8yDwR7HhuurVIXJ05Km1002M52CuLfR4Eui UwaSrIr3cfXcQB/Trnnsrmfm5ikWcqKKs3UctUFYFRREKy5T0ujXusoEk77MnIvjCGQI t7ww== X-Gm-Message-State: ACrzQf1654BNESpDTPbs5VX9wXvwdf6jusTrRm55+WG5jybeL4szafAj GU1FWJ6OjTUL4dX/TiTYA7thTw== X-Google-Smtp-Source: AMsMyM6bbDXxpSQ/PR+f+LUP/IpV/hQChv532e48wJf1oTx10TO//q3dz5joUxxjPbw52EKxi4jzWQ== X-Received: by 2002:ae9:e114:0:b0:6ce:33c9:5cc2 with SMTP id g20-20020ae9e114000000b006ce33c95cc2mr5986453qkm.388.1663377391104; Fri, 16 Sep 2022 18:16:31 -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 v6-20020a05620a440600b006bb87c4833asm8085434qkp.109.2022.09.16.18.16.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 18:16:30 -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 v2 1/4] counter: Introduce the Signal polarity component Date: Fri, 16 Sep 2022 20:39: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. Signed-off-by: William Breathitt Gray --- Documentation/ABI/testing/sysfs-bus-counter | 13 +++++++++++++ drivers/counter/counter-sysfs.c | 11 +++++++++++ include/linux/counter.h | 10 ++++++++++ include/uapi/linux/counter.h | 6 ++++++ 4 files changed, 40 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-sysfs.c b/drivers/counter/counter-sysf= s.c index 04eac41dad33..92d3d4f549cb 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; diff --git a/include/linux/counter.h b/include/linux/counter.h index 1fe17f5adb09..d508b260aaca 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 /** @@ -483,4 +484,13 @@ struct counter_available { #define COUNTER_COMP_PRESET_ENABLE(_read, _write) \ COUNTER_COMP_COUNT_BOOL("preset_enable", _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), \ +} + #endif /* _COUNTER_H_ */ 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 Tue Apr 7 10:52:40 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 DCDA4ECAAD8 for ; Sat, 17 Sep 2022 01:16:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229479AbiIQBQp (ORCPT ); Fri, 16 Sep 2022 21:16:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229745AbiIQBQe (ORCPT ); Fri, 16 Sep 2022 21:16:34 -0400 Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7945E22BF8 for ; Fri, 16 Sep 2022 18:16:33 -0700 (PDT) Received: by mail-qt1-x829.google.com with SMTP id s18so14234962qtx.6 for ; Fri, 16 Sep 2022 18:16:33 -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=zKW3vycHDAYSzOkMpIJKV1+gXuwPgKuVH+YJh8CZYUL/g3l17pCEnVKrJRfpjmSXGp tkPj9qEdpTSorQb+5GKBYbzxb46d1rSJU7mEvniRf2Y3SXtch97X+th7RYYhPCvLzd6Y Gp2MIfZi+Jt9clv7ObsJFD/NVfOgSaNBDnbs3wwCpqvYI654OIp0FWaeJaG5sSbp99Kt 6Xciao3SA/VFdgnoQASCdP/2AeCe9GgszAipMf/a24KPnc6WOwLTpEURlIEPJNO6F6SQ CmViffUeMDPEh5ABy0XFt+Ae237qKK713CbAVa/6B/q3HyVCyM2qJguA9XZgyIVHPnm9 +X9Q== 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=nKObxwU/otwTg1F1uvQcuGyEf+nS62g47oIp1eZj+xafIvlDVnhhypwryj+zb3KjZu rwURBPzDi9J1xcFUcTLvAU27vwsczyV3v9YtkcXvOC+stHI3GF9/2KFV7PjNHnQqNUQf KlNDmEAq7miNUicQtjsjl6V3HK/EmlfZ9WaKAqHKMzmXaKij/2Rqj1PhsHmL+SmlbEGF 6CH78UKI827Y4+DMCxI7EC0FNflxBIXutITPb7uILv5dNlT7bmw/+qXZ5a37MYYTSLVA zR2Z/f6LXhI3wIrFITCNe5ig9MuZaf0PliuWqCVpBnRAvCPUPO5M6O8uxm9h4vIx13c9 F2Hw== X-Gm-Message-State: ACrzQf0VPKdt41I+pss+ENcybbNvSywPp/Htz6LUp/cPJ3O57flVnOeQ FPkObG6Qh3sGo6R+MMeGZXbs4A== X-Google-Smtp-Source: AMsMyM6nIH8z4+OiRjabaE89EllLMSNNm9mCCWIcVTmLX4X2sleAmRHAvsKZ+nonIAjSY3x5Ufgd9g== X-Received: by 2002:ac8:7d0a:0:b0:35c:be89:fd65 with SMTP id g10-20020ac87d0a000000b0035cbe89fd65mr6901226qtb.99.1663377392645; Fri, 16 Sep 2022 18:16:32 -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 v6-20020a05620a440600b006bb87c4833asm8085434qkp.109.2022.09.16.18.16.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 18:16:32 -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 v2 2/4] counter: 104-quad-8: Add Signal polarity component Date: Fri, 16 Sep 2022 20:39:26 -0400 Message-Id: <3611fef702da4255dfd050520c4623134b26ca68.1663372750.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 --- 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 Tue Apr 7 10:52:40 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 7A70FECAAA1 for ; Sat, 17 Sep 2022 01:16:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229831AbiIQBQs (ORCPT ); Fri, 16 Sep 2022 21:16:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbiIQBQf (ORCPT ); Fri, 16 Sep 2022 21:16:35 -0400 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60BCBBB68B for ; Fri, 16 Sep 2022 18:16:34 -0700 (PDT) Received: by mail-qk1-x72e.google.com with SMTP id h28so17034919qka.0 for ; Fri, 16 Sep 2022 18:16:34 -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=u9zxwUyjTnHb6dXIFQytfA/XLHMka2VsioSd5KiJT2E=; b=T/Y8ua4PR5ZmLcpi7HRFvkzn7jZk7obT+HVwyyLypu3Z1ZIl0KNujdoZx+z4OmAzz6 TJQFWdYzFKGCwqKENxHWssZ1PnUs9QDoJ1iorroNn+UAhlCSo7axHpiOVleErxClxdkj zqHmSMxa56vFP9BUqzJUtoKsST46cprAjcKIHdnK5B6SotbRg4CKJ6t/0AZ4J7a5wxix /C5x7InFB3xbzkY6lhu6IYaExG1dN+d5rSNFufSKyUV1DCOflRlSDCrxLXl37pCDodrb PGrYxUXfuoRxQLBl4Zuesq1t4Cq7ZTwU5qTFqX5CLKfax7CUOSlf8DXau8+/ahZGruer Vl2g== 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=u9zxwUyjTnHb6dXIFQytfA/XLHMka2VsioSd5KiJT2E=; b=4b+8DoSh2yghLpGpiY/pq6cR/A3+FjkLBOTz9vgJ2Uqdo40o94ShO+Wcf2PLIply61 Ee3e9dCaQQUJztA22DeDat4eMZG+5xbrv9b95WCJ1ZJuaj1VY3yRUlnZkaUdxUgoMhAA xopBwrazIX6/fqoFHDhVTtEUWALMGzXLVKyUG3e6ob96BfQIfsdRV8ehEmzh5/apVq4i XYa6y6ZqBOEv/xXJw2bhsEFH7wFv6yMyUrr4iYt6xsmPkbXKifYkN3BTip/ZytTQ5jST jrBSNpJobkHSWVMZpOlqAidGZSwcSiCKx0CICfZSl88UlGm2VR/cF8DkxMwwsGxHQsBd OKLQ== X-Gm-Message-State: ACrzQf3N2pvdv20eWr2rq8xwsXOxTXQit7D0Hwh2KUdTqUGGXhbqO1W8 O39u6293d4Jk78ZLaNx6reQVTA== X-Google-Smtp-Source: AMsMyM4PhBnQfuUl3GK8Arbg7pQCPy4qG/RQWLpyzNL8rLOEreCkIHmk/WL5P3jjk9yQ2N+MyPcGgQ== X-Received: by 2002:a37:38d:0:b0:6cd:fd39:10e5 with SMTP id 135-20020a37038d000000b006cdfd3910e5mr5973510qkd.784.1663377393535; Fri, 16 Sep 2022 18:16:33 -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 v6-20020a05620a440600b006bb87c4833asm8085434qkp.109.2022.09.16.18.16.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 18:16:33 -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 v2 3/4] counter: Consolidate Counter extension sysfs attribute creation Date: Fri, 16 Sep 2022 20:39:27 -0400 Message-Id: <9fa4b496be11ea25aaef2c0515ec80a50827a498.1663372750.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 --- 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 92d3d4f549cb..7ce7c51395da 100644 --- a/drivers/counter/counter-sysfs.c +++ b/drivers/counter/counter-sysfs.c @@ -591,6 +591,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", @@ -604,8 +644,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; @@ -619,21 +657,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, @@ -718,8 +744,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; @@ -742,21 +766,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, @@ -849,8 +861,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); @@ -887,19 +897,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 Tue Apr 7 10:52:40 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 7A3E9ECAAD8 for ; Sat, 17 Sep 2022 01:16:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229869AbiIQBQz (ORCPT ); Fri, 16 Sep 2022 21:16:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229790AbiIQBQh (ORCPT ); Fri, 16 Sep 2022 21:16:37 -0400 Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D694EBBA7A for ; Fri, 16 Sep 2022 18:16:34 -0700 (PDT) Received: by mail-qt1-x829.google.com with SMTP id s18so14234988qtx.6 for ; Fri, 16 Sep 2022 18:16:34 -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=L4mHg8tr2Z6q5CevpFCH/2CHmo2l4J76jvGEI+vTweI=; b=yMVe0PTWztYIvx5p8MUTDDWCCx1KMEkZFnr3IrDL6TUHR1uMNxDGHICnMKpQBTag4D Bkw4iXm836hso+OJwOoY86hBgKFUpYbuyaGzxVAgGk2GA1ydX/LY+4eZRVK2P/VBh6Oe W+pCsmcYHfrblBqR5DZsCfDcpzV80LrKRjAvu06F/bnrQ0h5e+dI3ctlYvovziOzlGfw Kj7gKg580DFar3f+6zMa3eXi/+hVbgBqUVMgNCpl7WrmTOhhKUJCFrtdHcF9J7iVs+gF m49ZO7GjZAuug/egoVcCzqBwfPVP2yWTXpOFX9zZzrw7v9m6dRgXgFyhYn5bWQaHt+G9 PgYQ== 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=L4mHg8tr2Z6q5CevpFCH/2CHmo2l4J76jvGEI+vTweI=; b=e+HCtaTQgRecbmTz4PMw5ka9WoNGFz43vepOofgo43x+NGVnEMODJd03WXsV9bpKaT 9KORNiE2X+c0rtTU2xbEmvxeWHzlKgBHGWV8MEdSlQG+SvpdUtQPEyTyHU2WLm5nIokP u9Og7E4d9y9xbg5cXjDIfLBnc5Qmk6dc6RpOqkwhxEnpyZz1J+vtc7NeuBTvDH3ihCzS L0EqnhcsdzEY6o5hWsCPZWJkhGcUY7Kp6UoziPOD8oNtMOJfC8BtvdLDU/7x8p099HfL FnHS/Ij4NfTv5MShIhmfBkv57vgQBGPWGIi4oC+ccVQDEjSbVIuGdQf+bkqz2N64o7HH hJ0g== X-Gm-Message-State: ACrzQf37EcjZRYvODUwCCNnlsJrVA3wZeQrOWysHkLMrQPC8GK7R0AEo dcZGIxmB2NVBF57pclMWDRuiKg== X-Google-Smtp-Source: AMsMyM6aKMgStFDDLbzmAns6KpAhsjq03DMLxZ6sN7vtPws3hRt1FQtEy7ckUuOY7jPSdqrMQp8d4Q== X-Received: by 2002:ac8:5ac7:0:b0:35b:b658:4b6c with SMTP id d7-20020ac85ac7000000b0035bb6584b6cmr6686864qtd.207.1663377394452; Fri, 16 Sep 2022 18:16:34 -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 v6-20020a05620a440600b006bb87c4833asm8085434qkp.109.2022.09.16.18.16.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 18:16:34 -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 v2 4/4] counter: Introduce the COUNTER_COMP_ARRAY component type Date: Fri, 16 Sep 2022 20:39:28 -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 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. Five Counter array component macros are introduced:: DEFINE_COUNTER_ARRAY(_name, _type, _available, _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_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(foobar_capture_array, COUNTER_COMP_U64, NULL, 4) COUNTER_COMP_COUNT_ARRAY_U64("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. Cc: Julien Panis Signed-off-by: William Breathitt Gray --- drivers/counter/counter-sysfs.c | 193 +++++++++++++++++++++++++++++++- include/linux/counter.h | 121 ++++++++++++++++++++ 2 files changed, 312 insertions(+), 2 deletions(-) diff --git a/drivers/counter/counter-sysfs.c b/drivers/counter/counter-sysf= s.c index 7ce7c51395da..ea4401b4d578 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 @@ -499,6 +618,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; } @@ -608,6 +753,40 @@ 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++) { + /* Set index for array element extension */ + element =3D ext.priv; + element->idx =3D idx; + + /* Generate array element attribute name */ + ext.name =3D devm_kasprintf(dev, GFP_KERNEL, "%s%zu", comp->name, + idx); + if (!ext.name) + return -ENOMEM; + + /* 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, @@ -618,12 +797,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 d508b260aaca..61fe38e30626 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,47 @@ 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(_name, _type, _available, _length) \ + struct counter_array _name =3D { \ + .type =3D (_type), \ + .avail =3D &(_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_CEILING(_read, _write) \ COUNTER_COMP_COUNT_U64("ceiling", _read, _write) =20 @@ -493,4 +605,13 @@ struct counter_available { .priv =3D &(_available), \ } =20 +#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