Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp2381187pxy; Tue, 3 Aug 2021 05:14:40 -0700 (PDT) X-Received: by 2002:aa7:c542:: with SMTP id s2mr25996718edr.41.1627992640972; Tue, 03 Aug 2021 05:10:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycDDAvw3eYP8Txt9gh/cJBRBJsrIloukk6C2zJNlcVzvFjNmVs9eZd7Jlo1PALR20pUTb+ X-Received: by 2002:aa7:c542:: with SMTP id s2mr25996585edr.41.1627992639716; Tue, 03 Aug 2021 05:10:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627992639; cv=none; d=google.com; s=arc-20160816; b=vTJ1jRTLD6nViZvWtOTdLo0EeE2dmbmqHbIUZptiBuUcCkBqfPeICrOTbIZ6kD83v0 P7ZSoC1gjvUwp4AhLSJls3r5w5Shxamii3xCWA37//nDF4unZtsfTwMQdf5fWE182oAf BhJ4Yrivv9BUcAjFZEnfe0N4qkElioQH4h8VKyHzg+4W5aOy+IHSH1hhwdKuh/jgdGl+ nppzByRegD2JiQ/k0F0YCIrob2eA5Kl7r3DsmvyL4pCzEpgz6L9ev5OFKDF8gkooVT0H xY2QPBEjEXNXRb66iITfJmCLXe0/HyCta7hlpRT69Ek/q5ZkZAS92x7qNrYKC0nYBAxF V4ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GKMCNriu6Oe0b4ijgDqgdhWJc4dVQTXn+gR1UFw9WGc=; b=M7L/1TzB4XAZ6JsABuBu3bwwr1bt/vw8OXIBOWA5OB7mxzFs4rVSsBu4er+RQD+yEn QMe/x0OiRy318ei6oYVcNwbR9qKASsrLxX7SkkXpD8Raz2pF/YshhB/AeeVGWb0PFFLv h7N/YtpYyIkEJgk3hxOU5RMtCw864F11ms3TP2pTQi2kqCfpg+vS88k3kmru+WqBwpMg Z6wK9QR890p1aDDp02fHZCtGugaQoahB2Eng3C1UKTvH8gyBaA543zVeu/d5kdUcrZl1 89ZQSZkslMwskJ0Ml/kVJtgHNhqeAQ/in3XEFYykZAmjXp6+2RT+OAXl9qn/aZVjXDXe hgtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=t16QRjZI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n6si13066095edv.308.2021.08.03.05.10.16; Tue, 03 Aug 2021 05:10:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=t16QRjZI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235982AbhHCMIJ (ORCPT + 99 others); Tue, 3 Aug 2021 08:08:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235773AbhHCMII (ORCPT ); Tue, 3 Aug 2021 08:08:08 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D60E0C061764; Tue, 3 Aug 2021 05:07:56 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id mt6so29408117pjb.1; Tue, 03 Aug 2021 05:07:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GKMCNriu6Oe0b4ijgDqgdhWJc4dVQTXn+gR1UFw9WGc=; b=t16QRjZIxcuYdstsPWLMVOH/nKmuF5tZxc61xEAvfR0GMoxYmpjaQeUAS8sUFqX9jl YAjhlkc964yIo8VUWzcnAI5hI0QNDqpJXnAFTtLaR81HI4UGEm7iODItlB9BKddN5M6t qU/eHbDqLg3xO2WqXTUoeMolqnhBPPtmfr1sWKwqMnNrAqw8BRXJFKNS/2/kmxOBrixu JotPQAyEfy38LcVluV5FmfUksZHpQ4mtN0JWc3XaO+ElD/KITPegAlAzbiQaVjvc9D+X NCrO20OOyxtjKvMEwmVt9uEr/joDaV40IgIEdh/jzM61V0B69ZasMH4yrmNLOCpe2XCi ltNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GKMCNriu6Oe0b4ijgDqgdhWJc4dVQTXn+gR1UFw9WGc=; b=o3dXxI+a2r/NZKS2Qy0XQKLlZuMvJnqrycI3x0WGArr/KsV6yv9xA2gjElVTGcM/5U RL3brh6nrMcb5XmNSyFvaz/SomlgZJf7pHQ2Ye6QB0L3XnRePfYZrStuk3pyD268aAyW V1tc1ohfClx3e5nV4d3sLQcD7Bvl6JHzyAjAKxda0yrtBDOu99Bs01rmyAsnIBlTbzAa ZoLypjW3IudoR4vC32dQ0XUmpivMUdMX6pYMOB3GCmjZIXAJiN5+TJoasHngt2w/4x10 ZJvHUrBhySXPii3LRmcepoHdLRnQGOoKeV1JlJXXvpKZaBlRSQWyL6LLFkgsCBQ1VPmt MBKQ== X-Gm-Message-State: AOAM533OkIcKQRM2H+8y/MjsWHvWPUzkZEubtOzalVm8q65LO+J2aZAH J7MYVdt+G0TcBy5biMI2k6s= X-Received: by 2002:a17:90a:fc6:: with SMTP id 64mr22516402pjz.1.1627992476483; Tue, 03 Aug 2021 05:07:56 -0700 (PDT) Received: from localhost.localdomain ([156.146.35.76]) by smtp.gmail.com with ESMTPSA id n35sm7197502pfv.152.2021.08.03.05.07.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 05:07:55 -0700 (PDT) From: William Breathitt Gray To: jic23@kernel.org Cc: linux-stm32@st-md-mailman.stormreply.com, kernel@pengutronix.de, a.fatoum@pengutronix.de, kamel.bouhara@bootlin.com, gwendal@chromium.org, alexandre.belloni@bootlin.com, david@lechnology.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, syednwaris@gmail.com, patrick.havelange@essensium.com, fabrice.gasnier@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, o.rempel@pengutronix.de, jarkko.nikula@linux.intel.com, William Breathitt Gray , Dan Carpenter Subject: [PATCH v14 13/17] counter: Implement signalZ_action_component_id sysfs attribute Date: Tue, 3 Aug 2021 21:06:23 +0900 Message-Id: <7a9fc7e7272650e0d43b23a6ba65bffe889f4c86.1627990337.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The Generic Counter chrdev interface expects users to supply component IDs in order to select Synapses for requests. In order for users to know what component ID belongs to which Synapse this information must be exposed. The signalZ_action_component_id attribute provides a way for users to discover what component ID belongs to the respective Synapse. Cc: Gwendal Grignou Cc: Dan Carpenter Reviewed-by: David Lechner Signed-off-by: William Breathitt Gray --- Documentation/ABI/testing/sysfs-bus-counter | 7 ++++ drivers/counter/counter-sysfs.c | 46 ++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-bus-counter b/Documentation/ABI/testing/sysfs-bus-counter index dee79b606847..9809d8a47431 100644 --- a/Documentation/ABI/testing/sysfs-bus-counter +++ b/Documentation/ABI/testing/sysfs-bus-counter @@ -203,6 +203,13 @@ Description: both edges: Any state transition. +What: /sys/bus/counter/devices/counterX/countY/signalZ_action_component_id +KernelVersion: 5.15 +Contact: linux-iio@vger.kernel.org +Description: + Read-only attribute that indicates the component ID of the + respective Synapse of Count Y for Signal Z. + What: /sys/bus/counter/devices/counterX/countY/spike_filter_ns KernelVersion: 5.14 Contact: linux-iio@vger.kernel.org diff --git a/drivers/counter/counter-sysfs.c b/drivers/counter/counter-sysfs.c index dbb507c9da11..11bef9f8190f 100644 --- a/drivers/counter/counter-sysfs.c +++ b/drivers/counter/counter-sysfs.c @@ -393,7 +393,6 @@ static int counter_avail_attr_create(struct device *const dev, struct counter_attribute *counter_attr; struct device_attribute *dev_attr; - /* Allocate Counter attribute */ counter_attr = devm_kzalloc(dev, sizeof(*counter_attr), GFP_KERNEL); if (!counter_attr) return -ENOMEM; @@ -535,6 +534,46 @@ static int counter_name_attr_create(struct device *const dev, return 0; } +static ssize_t counter_comp_id_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + const size_t id = (size_t)to_counter_attribute(attr)->comp.priv; + + return sprintf(buf, "%zu\n", id); +} + +static int counter_comp_id_attr_create(struct device *const dev, + struct counter_attribute_group *const group, + const char *name, const size_t id) +{ + struct counter_attribute *counter_attr; + + /* Allocate Counter attribute */ + counter_attr = devm_kzalloc(dev, sizeof(*counter_attr), GFP_KERNEL); + if (!counter_attr) + return -ENOMEM; + + /* Generate component ID name */ + name = devm_kasprintf(dev, GFP_KERNEL, "%s_component_id", name); + if (!name) + return -ENOMEM; + + /* Configure Counter attribute */ + counter_attr->comp.priv = (void *)id; + + /* Configure device attribute */ + sysfs_attr_init(&counter_attr->dev_attr.attr); + counter_attr->dev_attr.attr.name = name; + counter_attr->dev_attr.attr.mode = 0444; + counter_attr->dev_attr.show = counter_comp_id_show; + + /* Store list node */ + list_add(&counter_attr->l, &group->attr_list); + group->num_attr++; + + return 0; +} + static struct counter_comp counter_signal_comp = { .type = COUNTER_COMP_SIGNAL_LEVEL, .name = "signal", @@ -629,6 +668,11 @@ static int counter_sysfs_synapses_add(struct counter_device *const counter, COUNTER_SCOPE_COUNT, count); if (err < 0) return err; + + /* Create Synapse component ID attribute */ + err = counter_comp_id_attr_create(dev, group, comp.name, i); + if (err < 0) + return err; } return 0; -- 2.32.0