From patchwork Tue Jul 21 13:14:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1333031 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=Q/N64mbC; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B9zbj3DzXz9sR4 for ; Tue, 21 Jul 2020 23:15:11 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id ABC3C819F0; Tue, 21 Jul 2020 15:15:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.b="Q/N64mbC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BF43081BA2; Tue, 21 Jul 2020 15:15:02 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5079E81991 for ; Tue, 21 Jul 2020 15:14:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ed1-x542.google.com with SMTP id a1so15230065edt.10 for ; Tue, 21 Jul 2020 06:14:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Xr7TS13sjRoDbV07Gfe4gRqh5z8nWxawKXofcDrjpWE=; b=Q/N64mbCDy8aBQklymH+srPJJc9aQRDVmaHEpWbqVwKGP8VrcaBZkc+03JJODEMuHo TRTPzBSldmSZfw76E9WxGPKcnWFI19PgwJbusOT6HwcnkvaoeBI8ddTvpcWahi10mcxW iMg5bXO/NCNNcXGg00g67URX4gtU4ohkzSSxYFeoegLaEKpLqrhc9aSYqNKYZcfWLwnw i2ZUVYP+qTm7DvNL0CvtVego8+UKmsDluPpi+Qu/DSKnS4zL0yceHkDVNj111/iN+qCk pXBuYCU04yYlYKodRk7JZc+45XzRztddWRogH20z7Uj2Aya2z6OkkFWsUnNTtK2Iq58/ rT6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=Xr7TS13sjRoDbV07Gfe4gRqh5z8nWxawKXofcDrjpWE=; b=Vo561t1VK2JuHfIDuVhqeclSbzO7EAG4nMxoXYvEO3uQX33BnvFSJlaKhqXSAUKKlk hCmSN8VeMpoRndATXzMruqWCioYtAiACjaWm6WfDZKPJFq9qxtBd1wkX7o0iiqNev0HQ 7z48Y2VnaqXE0+I3mGhYtGiwA/UHH7SOes/LlsKFNIvBTQJXGh562uKCGtEObWu1hUox hQfOWUkBCKReXROX/3iZlpXrm82wZ1O8kozKvE7BPwnGB6fyo/HBpldk9Y4e/LY/NGUZ Ol/a6kMaKRZ9mBjiQHxIyz8ITXEULdBd0kdyMRQzXKSSvHSACC8BogN/eYyIF4NDH5Os D9Ng== X-Gm-Message-State: AOAM530dOGxWu3lRalRQy9LU2hzRtum1LXGHMv6i2VbfxOxlZBJhS+eG ywVVw9uoiQ2egw7H0k4WxluelxAsz9dSjA== X-Google-Smtp-Source: ABdhPJxfJgmRe6OgrOFQWrmqtYllTPqPOx2N0I3Cp/P2iwNrjCaDz1ZQcenQ3Xw8x1J6va2mebHmag== X-Received: by 2002:a05:6402:1757:: with SMTP id v23mr26584295edx.356.1595337298615; Tue, 21 Jul 2020 06:14:58 -0700 (PDT) Received: from localhost (nat-35.starnet.cz. [178.255.168.35]) by smtp.gmail.com with ESMTPSA id r19sm17163630edp.79.2020.07.21.06.14.57 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Jul 2020 06:14:57 -0700 (PDT) From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com, Heiko Schocher Cc: AKASHI Takahiro , Bin Meng , Chunfeng Yun , Neil Armstrong , Patrick Delaunay , Sean Anderson , Simon Glass , Wolfgang Wallner Subject: [PATCH] gpio: Add support for gpio-line-names reading Date: Tue, 21 Jul 2020 15:14:56 +0200 Message-Id: <2ea0889ef7947c7feda0c9327ceed087c0521fed.1595337294.git.michal.simek@xilinx.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean The commit 2bd261dd1712 ("gpio: search for gpio label if gpio is not found through bank name") introduced the option to search gpio via labels (gpio hog). This patch is just follow up on this and fills pin name based on gpio-line-names DT property. Signed-off-by: Michal Simek Reviewed-by: Heiko Schocher Reviewed-by: Simon Glass --- arch/sandbox/dts/test.dts | 2 ++ drivers/gpio/gpio-uclass.c | 31 +++++++++++++++++++++++++++++++ test/dm/gpio.c | 6 ++++++ 3 files changed, 39 insertions(+) diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 3744a4660300..1b33cd4c0878 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -388,6 +388,8 @@ #gpio-cells = <2>; gpio-bank-name = "c"; sandbox,gpio-count = <10>; + gpio-line-names = "ZERO", "ONE", "TWO", "THREE", "FOUR", + "FIVE", "SIX", "SEVEL", "EIGHT", ""; }; }; diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c index 9c53299b6a3b..430c6849f4cd 100644 --- a/drivers/gpio/gpio-uclass.c +++ b/drivers/gpio/gpio-uclass.c @@ -1177,6 +1177,37 @@ static int gpio_post_probe(struct udevice *dev) if (!uc_priv->name) return -ENOMEM; + if (IS_ENABLED(CONFIG_DM_GPIO_LOOKUP_LABEL) && + dev_read_string(dev, "gpio-line-names")) { + int i, ret, count; + const char *name; + char *str; + + count = dev_read_string_count(dev, "gpio-line-names"); + + if (count != uc_priv->gpio_count) { + printf("Incorrect gpio-line-names count %d/%d\n", + count, uc_priv->gpio_count); + return -EINVAL; + } + + for (i = 0; i < uc_priv->gpio_count; i++) { + ret = dev_read_string_index(dev, "gpio-line-names", i, + &name); + if (ret) + return ret; + + if (strlen(name)) { + str = strdup(name); + if (!str) + return -ENOMEM; + + /* All the time there is pointer to name in DT */ + uc_priv->name[i] = (char *)str; + } + } + } + return gpio_renumber(NULL); } diff --git a/test/dm/gpio.c b/test/dm/gpio.c index 29701389fcd5..623a157ff1db 100644 --- a/test/dm/gpio.c +++ b/test/dm/gpio.c @@ -142,6 +142,12 @@ static int dm_test_gpio(struct unit_test_state *uts) ut_assert(gpio_lookup_name("hog_not_exist", &dev, &offset, &gpio)); + /* Check if lookup for names filled via gpio-line-names work */ + ut_assertok(gpio_lookup_name("EIGHT", &dev, &offset, &gpio)); + ut_asserteq_str(dev->name, "pinmux-gpios"); + ut_asserteq(8, offset); + ut_asserteq(CONFIG_SANDBOX_GPIO_COUNT + 20 + 10 + 8, gpio); + return 0; } DM_TEST(dm_test_gpio, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);