From patchwork Fri Sep 23 14:57:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 9348281 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3DBBB601C2 for ; Fri, 23 Sep 2016 14:57:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F3932A789 for ; Fri, 23 Sep 2016 14:57:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 23E0B2ABBC; Fri, 23 Sep 2016 14:57:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D82CB2A789 for ; Fri, 23 Sep 2016 14:57:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752797AbcIWO5P (ORCPT ); Fri, 23 Sep 2016 10:57:15 -0400 Received: from mga09.intel.com ([134.134.136.24]:39708 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752728AbcIWO5O (ORCPT ); Fri, 23 Sep 2016 10:57:14 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP; 23 Sep 2016 07:57:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.30,381,1470726000"; d="scan'208";a="172417785" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga004.fm.intel.com with ESMTP; 23 Sep 2016 07:57:11 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id DA77016D; Fri, 23 Sep 2016 17:57:10 +0300 (EEST) From: Mika Westerberg To: "Rafael J. Wysocki" , Linus Walleij Cc: Alexandre Courbot , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Mika Westerberg Subject: [PATCH 2/5] ACPI / gpio: Add support for naming GPIOs Date: Fri, 23 Sep 2016 17:57:07 +0300 Message-Id: <20160923145710.105489-3-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160923145710.105489-1-mika.westerberg@linux.intel.com> References: <20160923145710.105489-1-mika.westerberg@linux.intel.com> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP DT has property 'gpio-line-names' to name GPIO lines the controller has if present. Use this very same property in ACPI as well to provide nice names for the GPIOS. Signed-off-by: Mika Westerberg --- Documentation/acpi/gpio-properties.txt | 21 +++++++++++++++++ drivers/gpio/gpiolib-acpi.c | 43 ++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/Documentation/acpi/gpio-properties.txt b/Documentation/acpi/gpio-properties.txt index 5aafe0b351a1..7875974823ae 100644 --- a/Documentation/acpi/gpio-properties.txt +++ b/Documentation/acpi/gpio-properties.txt @@ -51,6 +51,27 @@ it to 1 marks the GPIO as active low. In our Bluetooth example the "reset-gpios" refers to the second GpioIo() resource, second pin in that resource with the GPIO number of 31. +Other supported properties +-------------------------- + +Following Device Tree compatible device properties are also supported by +_DSD device properties for GPIO controllers: + +- gpio-line-names + +Example: + + Package () { + "gpio-line-names", + Package () { + "SPI0_CS_N", "EXP2_INT", "MUX6_IO", "UART0_RXD", "MUX7_IO", + "LVL_C_A1", "MUX0_IO", "SPI1_MISO" + } + } + +See Documentation/devicetree/bindings/gpio/gpio.tx for more information +about these properties. + ACPI GPIO Mappings Provided by Drivers -------------------------------------- diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c index af514618d7fb..202cf1b842de 100644 --- a/drivers/gpio/gpiolib-acpi.c +++ b/drivers/gpio/gpiolib-acpi.c @@ -805,6 +805,46 @@ static void acpi_gpiochip_free_regions(struct acpi_gpio_chip *achip) } } +static void acpi_gpiochip_set_names(struct acpi_gpio_chip *achip) +{ + struct gpio_chip *chip = achip->chip; + struct gpio_device *gdev = chip->gpiodev; + const char **names; + int ret, i; + + ret = device_property_read_string_array(chip->parent, "gpio-line-names", + NULL, 0); + if (ret < 0) + return; + + if (ret != gdev->ngpio) { + dev_warn(chip->parent, + "names %d do not match number of GPIOs %d\n", ret, + gdev->ngpio); + return; + } + + names = kcalloc(gdev->ngpio, sizeof(*names), GFP_KERNEL); + if (!names) + return; + + ret = device_property_read_string_array(chip->parent, "gpio-line-names", + names, gdev->ngpio); + if (ret < 0) { + dev_warn(chip->parent, "Failed to read GPIO line names\n"); + return; + } + + /* + * It is fine to assign the name, it will be allocated as long as + * the ACPI device exists. + */ + for (i = 0; i < gdev->ngpio; i++) + gdev->descs[i].name = names[i]; + + kfree(names); +} + void acpi_gpiochip_add(struct gpio_chip *chip) { struct acpi_gpio_chip *acpi_gpio; @@ -835,6 +875,9 @@ void acpi_gpiochip_add(struct gpio_chip *chip) return; } + if (!chip->names) + acpi_gpiochip_set_names(acpi_gpio); + acpi_gpiochip_request_regions(acpi_gpio); acpi_walk_dep_device_list(handle); }