From patchwork Tue Jan 11 20:14:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12710602 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EC20BC433EF for ; Tue, 11 Jan 2022 20:17:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7RWHdJCdrfG3wxM6Q85hxL0nIVUdo6aoI0EOrZlbdwg=; b=idhWZqQY1ms8jX zzB1LaPZ0IU4X2U9DCVY1sQH0N0PppKJzzAK6ZD9fu77MOZ7DC0/tEy0rq/2Xik8Nh4z2hfLEz+Up J8TQ4IOgL2OO6JL85ysPUYvQkPdE48IeUWPYTlyMCaBTvCg7uLuIjAYdDD3Iq01lHOIVnMDw86uTs UqxWJKnpus+Cptb4fX4kEa4wGxQf5SLjq6HRzRz8jxbqF92eSYcDaTpa/yi8hFk3qrI3zBIJBdqRQ 47GFT4NTYJli9kp6dHhNIau7cqBbOkjrruPMVarX+qeaj2czEzRXwQmSlJsEetQImx/TeJG5YKXTL eBcmjSpWC5q/GsU4TWng==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n7NZ0-00HWCR-80; Tue, 11 Jan 2022 20:16:14 +0000 Received: from smtp-relay-internal-0.canonical.com ([185.125.188.122]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n7NYD-00HVrG-P7 for linux-arm-kernel@lists.infradead.org; Tue, 11 Jan 2022 20:15:29 +0000 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id B6B9940A89 for ; Tue, 11 Jan 2022 20:15:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1641932119; bh=yNEEeI5zCJmr7xVf7gFV3sEIRbcvfS4VZZqxLHMMY6k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lORKy3il1SM/9rEJVRgtKJMjStE+g3TgKp0eqezJmAotNVmWnlsLjLTlcfp0V5R1e QWCkyZrOA+dAgtWAcCKUdF65uEWjn6Xg6ZmSbe9OBg0QryDaPQkGPwzRX75HRPHPMP tgdnR7EP3THFu3fJaohmNF/ccUHw9rC7Geh2d8FJ4Eryn7kxMCHJF5btB0+8qmKldv G9EzQ08UmD3f9FqsxTJ9VfGcxz8x79hKRrjAwIp4cYXcoM6iDVyrUISrItEAdCv57X jss2tR0R22mVE4KbJ1PQDYgwQU6UswrrUyCiPC4JIl1YzQoybZkzdF/7YJNmao44wh QNlc5zGLBrPag== Received: by mail-ed1-f70.google.com with SMTP id p8-20020aa7d308000000b003fe9b0c4760so159813edq.17 for ; Tue, 11 Jan 2022 12:15:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yNEEeI5zCJmr7xVf7gFV3sEIRbcvfS4VZZqxLHMMY6k=; b=Y7oclHYW02pu3bvCamdUpICtzL2HYrMAcaF7FAekUstpkZ9dj72hgWC0xLR7ZQcv2t GFZ47XPJh6BVhPxGLd2UGNLOH9u3K+6Kln+ieglYbTFsyKOR+gWQhZAnNkgj/0cZZy5N O0oRdfRgLS+YjR4YV2gmsKqerCTLKqhZbLawFde7nQa7pXnTqAf54AbrXfr0PqktQnpa Qzr0etmFVOMZlg5oT40RwVzyAUU4NXVU5SOURHeGrYj6DdIrGiSYgN+K3o/XKiwCB9ut oXItyn8cvgyyrQaei9bzn8n3jfG6Wx3YbpIcirJAB3HGQ52du91OlmDFAUxJymKnydXT vthg== X-Gm-Message-State: AOAM532bfFsVN9jHpX4xl00G/NTeFstQ5ZnNZsBcetZl3L4TVj6cPq4C ZAGNYUg4Me7LTMmM1hgFgVQBOANoajQSVdwc3xqEW9KgOfWzbOMyOpBkLIExxud0ISNfxfHKBDP hhggUa++Uxr+5wwxdHEIkbc1Grrx6sGQduknC7HiUzenDCOAcVbwh X-Received: by 2002:aa7:da50:: with SMTP id w16mr5952137eds.41.1641932118826; Tue, 11 Jan 2022 12:15:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJzKzK3Ptpd9d437ZzvCcxxfRuUl4Nu7v0FlOhHb5BgeOdhnGvZZDtlcZwgwq6CWiep3IXnraA== X-Received: by 2002:aa7:da50:: with SMTP id w16mr5952118eds.41.1641932118626; Tue, 11 Jan 2022 12:15:18 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-168-84.adslplus.ch. [188.155.168.84]) by smtp.gmail.com with ESMTPSA id f23sm3852212ejj.128.2022.01.11.12.15.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 12:15:18 -0800 (PST) From: Krzysztof Kozlowski To: Tomasz Figa , Krzysztof Kozlowski , Sylwester Nawrocki , Linus Walleij , Rob Herring , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Marek Szyprowski , Sam Protsenko , Chanho Park , Alim Akhtar Subject: [PATCH v2 02/28] pinctrl: samsung: accept GPIO bank nodes with a suffix Date: Tue, 11 Jan 2022 21:14:00 +0100 Message-Id: <20220111201426.326777-3-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220111201426.326777-1-krzysztof.kozlowski@canonical.com> References: <20220111201426.326777-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220111_121526_012124_6F4A40C2 X-CRM114-Status: GOOD ( 21.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Existing dt-bindings expected that each GPIO/pin bank within pin controller has its own node with name matching the bank (e.g. gpa0, gpx2) and "gpio-controller" property. The node name is then used for matching between driver data and DTS. Newly introduced dtschema expects to have nodes ending with "-gpio-bank" suffix, so rewrite bank-devicetree matching to look for old and new style of naming. Signed-off-by: Krzysztof Kozlowski Reviewed-by: Sam Protsenko --- drivers/pinctrl/samsung/pinctrl-samsung.c | 57 ++++++++++++++++++----- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c index b19ebc43d886..b3a5bc473841 100644 --- a/drivers/pinctrl/samsung/pinctrl-samsung.c +++ b/drivers/pinctrl/samsung/pinctrl-samsung.c @@ -1012,13 +1012,56 @@ static void samsung_banks_of_node_put(struct samsung_pinctrl_drv_data *d) of_node_put(bank->of_node); } +/* + * Iterate over all driver pin banks to find one matching the name of node, + * skipping optional "-gpio" node suffix. When found, assign node to the bank. + */ +static void samsung_banks_of_node_get(struct device *dev, + struct samsung_pinctrl_drv_data *d, + struct device_node *node) +{ + const char *suffix = "-gpio-bank"; + struct samsung_pin_bank *bank; + struct device_node *child; + /* Pin bank names are up to 4 characters */ + char node_name[20]; + unsigned int i; + size_t len; + + bank = d->pin_banks; + for (i = 0; i < d->nr_banks; ++i, ++bank) { + strscpy(node_name, bank->name, sizeof(node_name)); + len = strlcat(node_name, suffix, sizeof(node_name)); + if (len >= sizeof(node_name)) { + dev_err(dev, "Too long pin bank name '%s', ignoring\n", + bank->name); + continue; + } + + for_each_child_of_node(node, child) { + if (!of_find_property(child, "gpio-controller", NULL)) + continue; + if (of_node_name_eq(child, node_name)) + break; + else if (of_node_name_eq(child, bank->name)) + break; + } + + if (child) + bank->of_node = child; + else + dev_warn(dev, "Missing node for bank %s - invalid DTB\n", + bank->name); + /* child reference dropped in samsung_drop_banks_of_node() */ + } +} + /* retrieve the soc specific data */ static const struct samsung_pin_ctrl * samsung_pinctrl_get_soc_data(struct samsung_pinctrl_drv_data *d, struct platform_device *pdev) { struct device_node *node = pdev->dev.of_node; - struct device_node *np; const struct samsung_pin_bank_data *bdata; const struct samsung_pin_ctrl *ctrl; struct samsung_pin_bank *bank; @@ -1082,17 +1125,7 @@ samsung_pinctrl_get_soc_data(struct samsung_pinctrl_drv_data *d, */ d->virt_base = virt_base[0]; - for_each_child_of_node(node, np) { - if (!of_find_property(np, "gpio-controller", NULL)) - continue; - bank = d->pin_banks; - for (i = 0; i < d->nr_banks; ++i, ++bank) { - if (of_node_name_eq(np, bank->name)) { - bank->of_node = np; - break; - } - } - } + samsung_banks_of_node_get(&pdev->dev, d, node); d->pin_base = pin_base; pin_base += d->nr_pins;