From patchwork Fri Feb 12 13:50:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 61843 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp835072lbl; Fri, 12 Feb 2016 05:50:49 -0800 (PST) X-Received: by 10.66.222.129 with SMTP id qm1mr2296551pac.22.1455285046971; Fri, 12 Feb 2016 05:50:46 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 68si20186960pfj.77.2016.02.12.05.50.46; Fri, 12 Feb 2016 05:50:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752628AbcBLNuq (ORCPT + 4 others); Fri, 12 Feb 2016 08:50:46 -0500 Received: from mail-lb0-f171.google.com ([209.85.217.171]:36548 "EHLO mail-lb0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752598AbcBLNup (ORCPT ); Fri, 12 Feb 2016 08:50:45 -0500 Received: by mail-lb0-f171.google.com with SMTP id tk3so33192529lbb.3 for ; Fri, 12 Feb 2016 05:50:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=qsLursBT2fc9hPLwpeWD+NeWAuMcW8xQdGHqSgJOcMc=; b=fv2Eygum1kktrCrnmIrOcjYJclZvzoFDKNkyHOXSkstu0zVwWYawtZMXtxHnjJGtUk DIuuhyWD51VhsTmKdWR3L0i0lnu/54XSTbxxNXEA8JWE8wWHZT9Mh5+3JqbkE6F5XF98 Rc3n6qoPb0rXiOZ/GbhN8PiR11lqnHcKEhLFY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=qsLursBT2fc9hPLwpeWD+NeWAuMcW8xQdGHqSgJOcMc=; b=P++g2d+INTcBCsHih6rpwEXNfOVVxdkDTf8McJH9cOM2FrRK2x3/6iNM1pj5F0mS6H 60B09L4Ylljm9sVVb85O2J+TV7Tkw1RncQLNXxLjIgwbDoYOdbIi5cmTH3fXAp1D3Ue3 G7soIk1/RCx/SDA/xQgcRG+5GomW8sYNsOOADVymvFrEUySjo3F+iCf1etpPo55xjZoO D4yJAFPVl9b122LNvmMAc1xYJBbS1LmcA9uHA/pw7NvFspaWarFBRPr0F7XN3T3v6zLn isDg1fzy3m1H2ivxCnCYoXR/zB3qEGV0bbglCEEARxN63sIJo5CsbFqFPIhau6XLo29m lVdw== X-Gm-Message-State: AG10YORAxEMdSPd9qFiTyVgAtkqqIosqxFGfPZwxIkXtdEn69cKv5Z8XQ9vucjj7Fp8Gjryd X-Received: by 10.112.171.4 with SMTP id aq4mr691504lbc.85.1455285043884; Fri, 12 Feb 2016 05:50:43 -0800 (PST) Received: from localhost.localdomain ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id h72sm1930224lfe.33.2016.02.12.05.50.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Feb 2016 05:50:43 -0800 (PST) From: Linus Walleij To: linux-gpio@vger.kernel.org, Alexandre Courbot , Johan Hovold , Michael Welling , Markus Pargmann Cc: Bamvor Jian Zhang , Grant Likely , Linus Walleij Subject: [PATCH] gpio: store reflect the label to userspace Date: Fri, 12 Feb 2016 14:50:38 +0100 Message-Id: <1455285038-2071-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.4.3 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The gpio_chip label is useful for userspace to understand what kind of GPIO chip it is dealing with. Let's store a copy of this label in the gpio_device, add it to the struct passed to userspace for GPIO_GET_CHIPINFO_IOCTL and modify lsgpio to show it. Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 13 +++++++++++++ drivers/gpio/gpiolib.h | 3 +++ include/linux/gpio/driver.h | 3 ++- include/uapi/linux/gpio.h | 2 ++ tools/gpio/lsgpio.c | 4 ++-- 5 files changed, 22 insertions(+), 3 deletions(-) -- 2.4.3 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index aa4a60e19339..9fff3b0847bf 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -342,6 +342,9 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) strncpy(chipinfo.name, dev_name(&gdev->dev), sizeof(chipinfo.name)); chipinfo.name[sizeof(chipinfo.name)-1] = '\0'; + strncpy(chipinfo.label, gdev->label, + sizeof(chipinfo.label)); + chipinfo.label[sizeof(chipinfo.label)-1] = '\0'; chipinfo.lines = gdev->ngpio; if (copy_to_user(ip, &chipinfo, sizeof(chipinfo))) return -EFAULT; @@ -479,6 +482,16 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data) status = -EINVAL; goto err_free_gdev; } + + if (chip->label) + gdev->label = devm_kstrdup(&gdev->dev, chip->label, GFP_KERNEL); + else + gdev->label = devm_kstrdup(&gdev->dev, chip->label, "unknown"); + if (!gdev->label) { + status = -ENOMEM; + goto err_free_gdev; + } + gdev->ngpio = chip->ngpio; gdev->data = data; diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index ddbe409ad48f..e30e5fdb1214 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -37,6 +37,8 @@ struct acpi_device; * of the @descs array. * @base: GPIO base in the DEPRECATED global Linux GPIO numberspace, assigned * at device creation time. + * @label: a descriptive name for the GPIO device, such as the part number + * or name of the IP component in a System on Chip. * @data: per-instance data assigned by the driver * @list: links gpio_device:s together for traversal * @@ -55,6 +57,7 @@ struct gpio_device { struct gpio_desc *descs; int base; u16 ngpio; + char *label; void *data; struct list_head list; diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index b92ab9efdb69..341c3d6b2650 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -21,7 +21,8 @@ struct gpio_device; /** * struct gpio_chip - abstract a GPIO controller - * @label: for diagnostics + * @label: a functional name for the GPIO device, such as a part + * number or the name of the SoC IP-block implementing it. * @gpiodev: the internal state holder, opaque struct * @parent: optional parent device providing the GPIOs * @owner: helps prevent removal of modules exporting active GPIOs diff --git a/include/uapi/linux/gpio.h b/include/uapi/linux/gpio.h index 3188a87bdaa0..3f93e1bcd3dd 100644 --- a/include/uapi/linux/gpio.h +++ b/include/uapi/linux/gpio.h @@ -16,10 +16,12 @@ /** * struct gpiochip_info - Information about a certain GPIO chip * @name: the name of this GPIO chip + * @label: a functional name for this GPIO chip * @lines: number of GPIO lines on this chip */ struct gpiochip_info { char name[32]; + char label[32]; __u32 lines; }; diff --git a/tools/gpio/lsgpio.c b/tools/gpio/lsgpio.c index 4cfe29da279b..692233f561fb 100644 --- a/tools/gpio/lsgpio.c +++ b/tools/gpio/lsgpio.c @@ -54,8 +54,8 @@ int list_device(const char *device_name) goto free_chrdev_name; } - fprintf(stdout, "GPIO chip: %s, %u GPIO lines\n", - cinfo.name, cinfo.lines); + fprintf(stdout, "GPIO chip: %s, \"%s\", %u GPIO lines\n", + cinfo.name, cinfo.label, cinfo.lines); if (close(fd) == -1) { ret = -errno;