From patchwork Fri Aug 27 03:47:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 12461213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1E55C432BE for ; Fri, 27 Aug 2021 03:55:18 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5FF3C60EE7 for ; Fri, 27 Aug 2021 03:55:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5FF3C60EE7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Qz8b+agD2L0ZPEdVcg7nTkao9wBnS7yOM3rbK1hzbjk=; b=lCFF1mRUmNKdgb /L0hW14cII0U6Hg/8ETRvjB7KsMZXhCbCBRSiey1ejM61lDJv12vPLOU3Jmd4RVM2kd7LCKTADGlm Bptnoza9buouUrm151oQ2cAk8CfN+QpOQ9qmFWxQ2Vl9KD7skU+m73eV9qmovaJQ985KBzf6hvVmL kUqjcEDEmTuexkSjKzNIkX0sM/PbEPCU/k4Dkr2EhsrDRA3lkyi8f0hJW51bmqW4g+B1CKb4SiBtx SZYwbQJlHu04Maoh/idGbDEA0KOvoFw7pFW5pjMcgI0+AH2F2IjIiH4gUbZ4Gn87NwQ4L+uIZ2W3s DiooseZgetGiVDu0SpLQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mJSus-00BTYA-P5; Fri, 27 Aug 2021 03:52:33 +0000 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mJSrb-00BS1l-He for linux-arm-kernel@lists.infradead.org; Fri, 27 Aug 2021 03:49:11 +0000 Received: by mail-pf1-x435.google.com with SMTP id r13so4156121pff.7 for ; Thu, 26 Aug 2021 20:49:07 -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=X2K+kS5TRvGGkXAwbGDp8tnI9+r3LlY6NFNe0uu/BE4=; b=k1WbMu8ca8Ct40n9Q0xZcjLb3Q4cHi9KvSJSWG2YCEFvUhdjko2wVk6ZwcMGKpdji7 dFiETS3KdIiymhyFe2ipAfp7abuUvmRdlfnLg7t+I7TKg6eSGgBaAbKgivUReOvYT8pk EgV+iJYf3+f26QLfkxIF+ua6I0NBXrLubi0cajWXvPD/vQRiEXRoK9c8mMuO/EBoaNo9 A4Qb1owPvMwn3bBPgauzPH3MYsZsR462sBPGT/1Pyp+U3XPhW9rPrbn5BY/Tt+vIXNOX 4M049c5ZjRleUsBSb33pdVC9oQw9eyOiYVdKKNYw4KHpRfC9/4GQnLmFVyuyqoftMiy/ PVOg== 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=X2K+kS5TRvGGkXAwbGDp8tnI9+r3LlY6NFNe0uu/BE4=; b=S3NKrp+Egax891Kapq1SR8CHHJF8PG/XtK9hfCjqZxGaBBQtv4+j2zPr+4o1LXRNCP NiY+gpV34RYdpMAhJw/OoKKXHwqezoPvfBSvjVuuVLdubdpGXnw4znPuxYu8qxXZk1Ld 8Qd1xzBXaUM4mTnIrdFm0QFWTJWFP/vGk2EUWxwA4rTxoS3uOW2CyihFQrmTgSN1Qjn4 PIStvpGoujC38374UCsuNCLPl9a/eRmLaV255O3qkVJ4i5t1R9X1IraT6wsQQPyVUTef vl5uzQeOTTNUF7DHAB38cdt8v9KabYr4BXZkQF6n5oHJ/EJDs4XRANpk+k78c4blsHYm TUkA== X-Gm-Message-State: AOAM531dg7Z7rZtmY5kFS4jwE+m0iZbgOvCZ3cOXidBm3Lk18+CzZLnE WtC4WXBf0kQoPhdF52gWYnU= X-Google-Smtp-Source: ABdhPJwX1U5ELlZ+GkFtm8/nGPz8fVhImmJ/9iReiB1g6lN8ocy4/mI0Kx5nceb3/fjL3f2Vz8u2WQ== X-Received: by 2002:a65:51c7:: with SMTP id i7mr6107703pgq.300.1630036146775; Thu, 26 Aug 2021 20:49:06 -0700 (PDT) Received: from localhost.localdomain ([156.146.35.76]) by smtp.gmail.com with ESMTPSA id o6sm4364693pjk.4.2021.08.26.20.49.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Aug 2021 20:49:06 -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 v16 10/14] counter: Implement signalZ_action_component_id sysfs attribute Date: Fri, 27 Aug 2021 12:47:54 +0900 Message-Id: X-Mailer: git-send-email 2.33.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210826_204907_652595_25991AB9 X-CRM114-Status: GOOD ( 14.03 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 | 45 +++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-counter b/Documentation/ABI/testing/sysfs-bus-counter index dee79b606847..aa2cd3c10d74 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.16 +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 108cbd838eb9..ee7ff1cde454 100644 --- a/drivers/counter/counter-sysfs.c +++ b/drivers/counter/counter-sysfs.c @@ -532,6 +532,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", @@ -626,6 +666,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;