From patchwork Thu Dec 17 16:48:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda Delgado X-Patchwork-Id: 558423 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 7F5C0140134 for ; Fri, 18 Dec 2015 03:48:34 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=IX51XyYw; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933374AbbLQQsT (ORCPT ); Thu, 17 Dec 2015 11:48:19 -0500 Received: from mail-lf0-f50.google.com ([209.85.215.50]:35556 "EHLO mail-lf0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932470AbbLQQsR (ORCPT ); Thu, 17 Dec 2015 11:48:17 -0500 Received: by mail-lf0-f50.google.com with SMTP id l133so55530753lfd.2; Thu, 17 Dec 2015 08:48:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=z2wsKNCZKxii21K47u/VY0Ucu35ohVdSm3fqELIzLww=; b=IX51XyYwvHVwAuDmbBMfynl6Ca41cJ4gQvcG1j3Uhckh6L7NEmFcxezfkJu9J3uy1j sJt3x3/t3rghFVe8tQEaF2ZJxURj9pCzGGrodAkVVHcub8/9Pym542if2VDBnmbPUWTt B5UpEbDDxpASMRJPIdf9xQyDpYeEH+kIHbaPB3C6oGp3G8HLhNfEKCeJ26PQYf8rqee/ tvnjFx1u+QU1q9Ry2AmwPgLHcDQx8nIFqARC9ARbfamT/Hy9RC7+VxXqp947MD8WoX9p QNTCe6PxRE4GRduNHAgfoIa45Kv5CPxoBVUCDfvWX+2LeFsWOnXUI241LQb0Dju4ksmg Ob0A== X-Received: by 10.25.18.89 with SMTP id h86mr10291123lfi.165.1450370895649; Thu, 17 Dec 2015 08:48:15 -0800 (PST) Received: from neopili.qtec.com (cpe.xe-3-0-1-778.vbrnqe10.dk.customer.tdc.net. [80.197.57.18]) by smtp.gmail.com with ESMTPSA id au8sm2018177lbc.31.2015.12.17.08.48.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 Dec 2015 08:48:14 -0800 (PST) From: Ricardo Ribalda Delgado To: Alexandre Courbot , linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org Cc: Ricardo Ribalda Delgado Subject: [PATCH] gpio/sysfs: Add ID parameter for GPIO lines Date: Thu, 17 Dec 2015 17:48:12 +0100 Message-Id: <1450370892-2517-1-git-send-email-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.6.4 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org On named GPIOs there is currently no find out their numerical id. Because of this, a GPIO pin named like: /sys/class/gpio/PROG_B cannot be unexported by an application different than the one that exported it. This patch adds a new parameter to the GPIO line called id, that shows the numerical id of a given GPIO. E.g.: $ cat /sys/class/gpio/PROG_B/id 496 $ echo 496 > unexport Signed-off-by: Ricardo Ribalda Delgado Acked-by: Alexandre Courbot --- Documentation/ABI/testing/sysfs-gpio | 1 + Documentation/gpio/sysfs.txt | 3 +++ drivers/gpio/gpiolib-sysfs.c | 10 ++++++++++ 3 files changed, 14 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-gpio b/Documentation/ABI/testing/sysfs-gpio index 55ffa2df1c10..53d78abef4f3 100644 --- a/Documentation/ABI/testing/sysfs-gpio +++ b/Documentation/ABI/testing/sysfs-gpio @@ -21,6 +21,7 @@ Description: /value ... always readable, writes fail for input GPIOs /direction ... r/w as: in, out (default low); write: high, low /edge ... r/w as: none, falling, rising, both + /id ... r only, GPIO number /gpiochipN ... for each gpiochip; #N is its first GPIO /base ... (r/o) same as N /label ... (r/o) descriptive, not necessarily unique diff --git a/Documentation/gpio/sysfs.txt b/Documentation/gpio/sysfs.txt index aeab01aa4d00..68e1b16e747b 100644 --- a/Documentation/gpio/sysfs.txt +++ b/Documentation/gpio/sysfs.txt @@ -96,6 +96,9 @@ and have the following read/write attributes: for "rising" and "falling" edges will follow this setting. + "id" ... ID used for export/unxexport the GPIO. This value may + be used by named GPIOs, to find out their numerical id. + GPIO controllers have paths like /sys/class/gpio/gpiochip42/ (for the controller implementing GPIOs starting at #42) and have the following read-only attributes: diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index b57ed8e55ab5..3fc5c7231aae 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -350,6 +350,15 @@ static ssize_t active_low_store(struct device *dev, } static DEVICE_ATTR_RW(active_low); +static ssize_t id_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct gpiod_data *data = dev_get_drvdata(dev); + + return sprintf(buf, "%d\n", desc_to_gpio(data->desc)); +} +static DEVICE_ATTR_RO(id); + static umode_t gpio_is_visible(struct kobject *kobj, struct attribute *attr, int n) { @@ -377,6 +386,7 @@ static struct attribute *gpio_attrs[] = { &dev_attr_edge.attr, &dev_attr_value.attr, &dev_attr_active_low.attr, + &dev_attr_id.attr, NULL, };