Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2544939pxb; Tue, 9 Mar 2021 05:25:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJyq9gYZsEBJD5RSDyek8WQ2Mym/7bQoahm0kA8REh2GyqdV3vxa+97TNthHKHchyLLH7P4V X-Received: by 2002:aa7:c456:: with SMTP id n22mr3976507edr.277.1615296302495; Tue, 09 Mar 2021 05:25:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615296302; cv=none; d=google.com; s=arc-20160816; b=cXYMTFZo8SfGTygxXkw3KQ5C6Z5ib91RHfLxDXZ/XtfuBnuxXTGzdqzoSqTZpHgWbb Vgl/T+iq7ZOGIPp1bmypFrUBAaJRiMY5cwkxjDLQPIiptZs1qEmt1N8ZgIc8OR1MD9LL njCD79vjMofhX2dsjAPNEh+neL6pNCetTKGZAOL91edYt7P3Qv1oaRosgxRlLWOqKP7L 1iq4aCxB+bnGYNggxgRJDqFjeQow8X6MhAVVKkGogumksUSMPAoraMBdcmmy9VzNGtZj 5vGCB7tg0zLeoYbkvnt0i51bKdpNfEYVDe4e96/ixDbqHzK3qdUj7Ye7/cLdkt1ArYOD uxGA== 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=Pil4P2EiLTeNqa4+JCYgDjTol3Ay4ymexuC8jw3Zjn0=; b=Nn3fLUanB0+7EqtaD2HPDxw5KAOSJwtmYX2ExdtGm2/HdH1wUjbgyXewzyBz3j0lse ooNR5n0zSpIJdwmWAG45mvN+PY/sJ/o6z7AxLd38piU1+DLnjZ70HCVbBBClQpy9c5WY 4ix/GFX1b0u1iYASocz5zBEBm7CRRy4C0yU5EcyP+hVvwOgMozvTqP7HPHE32fdC0KUO b/glDFJyjn89Nxa+I9prN9GfJC8XaaeLoRkvpCWdfQdQE4RQWcE2URuajxY+ks9sc/36 aN0SP+tZD+eiplB6ptWTiW8cQubsYvky1Aagbt5XWeq+uevEiWxPR2eZN35uMxq/jGoP SjSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vHWBQdDr; 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 c8si8608287edw.367.2021.03.09.05.24.39; Tue, 09 Mar 2021 05:25:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vHWBQdDr; 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 S231744AbhCINXN (ORCPT + 99 others); Tue, 9 Mar 2021 08:23:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231856AbhCINWo (ORCPT ); Tue, 9 Mar 2021 08:22:44 -0500 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F06FC06174A; Tue, 9 Mar 2021 05:22:44 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id cl21-20020a17090af695b02900c61ac0f0e9so886104pjb.1; Tue, 09 Mar 2021 05:22:44 -0800 (PST) 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=Pil4P2EiLTeNqa4+JCYgDjTol3Ay4ymexuC8jw3Zjn0=; b=vHWBQdDrLaykvvsgZrbdom6eyYce8unhe7aM985VIl5WEK8HbLU/P7l7zAp9gUfHla qm4eydAHJd2zCHWBhk7YlmHzbJMcMEA+rMSuNUuWhfbgHQxdO0l5YVwhPEm0q1Ks8Zdy wY0Wsf86dR+cd9rBADOg+/+4mxmMo1D6jg4NKIf9SZ+9l6uf4UtMRTZvepPVDUzSutKE FnqKsvZcCf41WMX9NXPp9ZSreVmS1WJPewO11tMj9R1qKp6HmEzMNP/1aDmcWr+wNDGA rSkPw5KDs1l4aGgb/yTNXDEPvFhG2F4Z4a5pL2WbxmBDQ6WcjfULPKl15Th+CClN87DG EM/A== 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=Pil4P2EiLTeNqa4+JCYgDjTol3Ay4ymexuC8jw3Zjn0=; b=Ehy8sAtHL6NAbVpTuLtiNGZo139d3EvKgwmb4G2fVikau/D8k+oVWuk4sZc3qfauUA GMrQOWjRkM2WU5MHkaHF12hzLaKZAe0MzT7TR0hN3u89tQa/RZtATskd8qBChrVrt8Tw ANfDVXs1PzUKghr1NZxN5I+Cth1JMNJ8j0tPplDSDw5/rX77fAW34PvOvWuFx3yTSiuu zB5aydvE+aSuuMVjmN+FkiQxqDRDYAgxAVT4S7BChLDblQA5i9FtJBNwVQSg/cgoG5g6 p3VtkMtdSvhrQ8yg0bJAtwSMwjJ1uP2EjQowrarcneFQNJCukBWHTPhfU0Z7i/JKlC7i AzRQ== X-Gm-Message-State: AOAM5338zqQYWpBhzb1oKb6/1ENoAIKqjT4nHG5km4MWmTVtqGSgzIHe 14pmjWif0T+eG0x1Zzv6wDo= X-Received: by 2002:a17:902:6bca:b029:e2:c5d6:973e with SMTP id m10-20020a1709026bcab02900e2c5d6973emr25715061plt.40.1615296163745; Tue, 09 Mar 2021 05:22:43 -0800 (PST) Received: from localhost.localdomain ([156.146.35.76]) by smtp.gmail.com with ESMTPSA id y9sm7647421pfl.201.2021.03.09.05.22.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 05:22:43 -0800 (PST) From: William Breathitt Gray To: jic23@kernel.org Cc: kernel@pengutronix.de, linux-stm32@st-md-mailman.stormreply.com, a.fatoum@pengutronix.de, kamel.bouhara@bootlin.com, gwendal@chromium.org, alexandre.belloni@bootlin.com, 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, William Breathitt Gray , Dan Carpenter Subject: [PATCH v9 29/33] counter: Implement signalZ_action_component_id sysfs attribute Date: Tue, 9 Mar 2021 22:19:42 +0900 Message-Id: X-Mailer: git-send-email 2.30.1 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: David Lechner Cc: Gwendal Grignou Cc: Dan Carpenter 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 6353f0a2f8f8..bee9289aecd1 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.13 +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/name KernelVersion: 5.2 Contact: linux-iio@vger.kernel.org diff --git a/drivers/counter/counter-sysfs.c b/drivers/counter/counter-sysfs.c index e65e6039a347..8f11499c8ec1 100644 --- a/drivers/counter/counter-sysfs.c +++ b/drivers/counter/counter-sysfs.c @@ -533,6 +533,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 sysfs_emit(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", @@ -627,6 +667,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.30.1