From patchwork Wed Sep 4 02:09:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 1980414 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=m3y9NdIQ; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=mJhF2Qd3; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wz5Yq0zbwz1yXY for ; Wed, 4 Sep 2024 12:10:39 +1000 (AEST) 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:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=j1zcGK8nrCAMDxsoz4YgBScIe6oGeHXxC10Y1DBKNjI=; b=m3y9NdIQXiqu2g dvn/YAN6By93U5TyoLmy6h6nrdufonu/6V01kD3U+WonPlll7VuSskVZyUbXCwhAj+qxGTbCchOGl iXm6AALVvFxUnCDCy+pToSSPv3BApNC50siBtY8R/0/1VBd6iQS2Ubkopq5OS+PQlG6Mjwg8YdTnZ WY4Nux1vcm0zadle21U7jwIKP6P9N/4UVB12ulAH1BG2FpKr0ybq/SzQvaJeHT3k1k0ms1Uz87FfK X6UB+jMlr5x8UZd32QKa4+tKT7U+80b4BYSefUmWy5D/Uv99BcGxd8UK3EYvPBK87l4JDu5phqWHA t3byLbqGMUml7j9BBw3A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slfTd-00000002YRl-1s4O; Wed, 04 Sep 2024 02:10:33 +0000 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slfTa-00000002YQi-1Qmj for opensbi@lists.infradead.org; Wed, 04 Sep 2024 02:10:31 +0000 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-2d8a744aa9bso2319516a91.3 for ; Tue, 03 Sep 2024 19:10:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1725415829; x=1726020629; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=J1g1QyHOrUJ/SEdkJadutVCyLOjkxOk2wSNzeFNfSjI=; b=mJhF2Qd3msGgeWstRQID2r5UfT4sDnbEwOqh3Cm6be+ZNMRUVIKJ2BOTUED33N+5ZO oobNME3ITJ3rqB1vn1NFq721bqUJ+vH9YwJ84ZoeY8oCvj0FCCbQHiO546FE78I/dDRi VzhsNQIv82Pn+vHVIFy6j0RNujNIrw3ptBa/xA8hUyJl54sWauSOEZar+8MfwnzOvE9P DIjyVAhM3PiYsBavGUHwwy7SfgwhXsJd9WdyAmuI2UjuMmkZfGsvZZHX0x/DMG3S3YfA gneDButr1uNFD8joc7AacsIhlo1g2Bc0bk/XnPbGIu1OqeNXeAQhygT1GsB9yi0Zcju/ Lekw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725415829; x=1726020629; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=J1g1QyHOrUJ/SEdkJadutVCyLOjkxOk2wSNzeFNfSjI=; b=qiMxwNOVGPdcSyhDua8c9BHYT8vejatouWipRQxjc52lI9dmqHkSr4x4/zV0B0MFiT 7xcOOi7iX6TMXeL9KizrCBy5F2RIf6tg3acYt1w6zO7/ldKNge463ToDiFYF/dcJ9RuA +rZSI87ghnEQY19V9VYSCYhJ5yXTlcocRYi45Jvt8uE8cv2CbHSqrNj7HFiK9b3KyiaH BD8FnOtX5W+TZ+7jwQ0J66CSe7EQH0E1aDPsCfJeiInoArG6XITQpjQo4GMTITpLMhsh Ne16uucbvFWf5AQSAR1md5FgbSsNTGX15abB/nxD+74CE+JIdP8yVRA4FIM6nI2oH4r3 qIWQ== X-Gm-Message-State: AOJu0YxDsJ+7s6DxMoDlQasUGZu+9rsW3ol23AMlYVDj/7cUQxsEgLp8 rFQhY36u8fqxQzbE8heTgEeJ5Z0wzD8Nrf7bqupLaFAXr0NOWd4kagDQOY5UW01ug/cqYAV4Gaa JVCWE6AcNIYhaIgE9dwACQIno/GoLw1rmT2uuSB4qUr96Ovr/V9waG3U+YivUOa+3Ohf6IcrjSo GqkO3ISJ/K4olOhWmjETBUpooDl0Sx5IH863G8avbtOpSBRjxxyyA= X-Google-Smtp-Source: AGHT+IHVSaKq1qHEzqQbdlLJArCBG7/wjkyKw4cSee88u7wj3aCBEd+I589hm0UcEOIxiKIFB/tHGA== X-Received: by 2002:a17:90b:314b:b0:2c9:649c:5e08 with SMTP id 98e67ed59e1d1-2d89728e436mr11198670a91.15.1725415829058; Tue, 03 Sep 2024 19:10:29 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d8af988d0esm6738385a91.45.2024.09.03.19.10.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 19:10:26 -0700 (PDT) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH 2/3] lib: utils/gpio: Use FDT node offset as GPIO chip ID Date: Tue, 3 Sep 2024 19:09:38 -0700 Message-ID: <20240904021006.3653559-3-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240904021006.3653559-1-samuel.holland@sifive.com> References: <20240904021006.3653559-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240903_191030_409204_6DFCFE12 X-CRM114-Status: GOOD ( 17.70 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Since the FDT is not modified during driver initialization, node offsets are just as suitable as phandles for use as identifiers: they are stable and unique. With this change, it is no longer necessar [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:102a listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Since the FDT is not modified during driver initialization, node offsets are just as suitable as phandles for use as identifiers: they are stable and unique. With this change, it is no longer necessary to pass the phandle to the driver init functions, so these init functions now use the same prototype as other kinds of drivers. This matches what is already done for I2C adapters. Signed-off-by: Samuel Holland Reviewed-by: Anup Patel --- include/sbi_utils/gpio/fdt_gpio.h | 2 +- lib/utils/gpio/fdt_gpio.c | 23 ++++++++--------------- lib/utils/gpio/fdt_gpio_designware.c | 4 ++-- lib/utils/gpio/fdt_gpio_sifive.c | 4 ++-- lib/utils/gpio/fdt_gpio_starfive.c | 4 ++-- 5 files changed, 15 insertions(+), 22 deletions(-) diff --git a/include/sbi_utils/gpio/fdt_gpio.h b/include/sbi_utils/gpio/fdt_gpio.h index 303ef632..ab9304bf 100644 --- a/include/sbi_utils/gpio/fdt_gpio.h +++ b/include/sbi_utils/gpio/fdt_gpio.h @@ -20,7 +20,7 @@ struct fdt_gpio { int (*xlate)(struct gpio_chip *chip, const struct fdt_phandle_args *pargs, struct gpio_pin *out_pin); - int (*init)(const void *fdt, int nodeoff, u32 phandle, + int (*init)(const void *fdt, int nodeoff, const struct fdt_match *match); }; diff --git a/lib/utils/gpio/fdt_gpio.c b/lib/utils/gpio/fdt_gpio.c index 6422c45f..953fa13a 100644 --- a/lib/utils/gpio/fdt_gpio.c +++ b/lib/utils/gpio/fdt_gpio.c @@ -16,17 +16,12 @@ extern struct fdt_gpio *fdt_gpio_drivers[]; extern unsigned long fdt_gpio_drivers_size; -static int fdt_gpio_init(const void *fdt, u32 phandle) +static int fdt_gpio_init(const void *fdt, int nodeoff) { - int pos, nodeoff, rc; + int pos, rc; struct fdt_gpio *drv; const struct fdt_match *match; - /* Find node offset */ - nodeoff = fdt_node_offset_by_phandle(fdt, phandle); - if (nodeoff < 0) - return nodeoff; - /* Check "gpio-controller" property */ if (!fdt_getprop(fdt, nodeoff, "gpio-controller", &rc)) return SBI_EINVAL; @@ -37,7 +32,7 @@ static int fdt_gpio_init(const void *fdt, u32 phandle) match = fdt_match_node(fdt, nodeoff, drv->match_table); if (match && drv->init) { - rc = drv->init(fdt, nodeoff, phandle, match); + rc = drv->init(fdt, nodeoff, match); if (rc == SBI_ENODEV) continue; if (rc) @@ -49,20 +44,20 @@ static int fdt_gpio_init(const void *fdt, u32 phandle) return SBI_ENOSYS; } -static int fdt_gpio_chip_find(const void *fdt, u32 phandle, +static int fdt_gpio_chip_find(const void *fdt, int nodeoff, struct gpio_chip **out_chip) { int rc; - struct gpio_chip *chip = gpio_chip_find(phandle); + struct gpio_chip *chip = gpio_chip_find(nodeoff); if (!chip) { /* GPIO chip not found so initialize matching driver */ - rc = fdt_gpio_init(fdt, phandle); + rc = fdt_gpio_init(fdt, nodeoff); if (rc) return rc; /* Try to find GPIO chip again */ - chip = gpio_chip_find(phandle); + chip = gpio_chip_find(nodeoff); if (!chip) return SBI_ENOSYS; } @@ -77,7 +72,6 @@ int fdt_gpio_pin_get(const void *fdt, int nodeoff, int index, struct gpio_pin *out_pin) { int rc; - u32 phandle; struct fdt_gpio *drv; struct gpio_chip *chip = NULL; struct fdt_phandle_args pargs; @@ -92,8 +86,7 @@ int fdt_gpio_pin_get(const void *fdt, int nodeoff, int index, if (rc) return rc; - phandle = fdt_get_phandle(fdt, pargs.node_offset); - rc = fdt_gpio_chip_find(fdt, phandle, &chip); + rc = fdt_gpio_chip_find(fdt, pargs.node_offset, &chip); if (rc) return rc; diff --git a/lib/utils/gpio/fdt_gpio_designware.c b/lib/utils/gpio/fdt_gpio_designware.c index 20701a15..36733bb4 100644 --- a/lib/utils/gpio/fdt_gpio_designware.c +++ b/lib/utils/gpio/fdt_gpio_designware.c @@ -78,7 +78,7 @@ static void dw_gpio_set(struct gpio_pin *gp, int value) * bank A is the only one with irq support but we're not using it here */ -static int dw_gpio_init_bank(const void *fdt, int nodeoff, u32 phandle, +static int dw_gpio_init_bank(const void *fdt, int nodeoff, const struct fdt_match *match) { struct dw_gpio_chip *chip; @@ -115,7 +115,7 @@ static int dw_gpio_init_bank(const void *fdt, int nodeoff, u32 phandle, chip->dr = (void *)(uintptr_t)addr + (bank * 0xc); chip->ext = (void *)(uintptr_t)addr + (bank * 4) + 0x50; chip->chip.driver = &fdt_gpio_designware; - chip->chip.id = phandle; + chip->chip.id = nodeoff; chip->chip.ngpio = nr_pins; chip->chip.set = dw_gpio_set; chip->chip.direction_output = dw_gpio_direction_output; diff --git a/lib/utils/gpio/fdt_gpio_sifive.c b/lib/utils/gpio/fdt_gpio_sifive.c index e5dbe2be..d96bf775 100644 --- a/lib/utils/gpio/fdt_gpio_sifive.c +++ b/lib/utils/gpio/fdt_gpio_sifive.c @@ -62,7 +62,7 @@ static void sifive_gpio_set(struct gpio_pin *gp, int value) extern struct fdt_gpio fdt_gpio_sifive; -static int sifive_gpio_init(const void *fdt, int nodeoff, u32 phandle, +static int sifive_gpio_init(const void *fdt, int nodeoff, const struct fdt_match *match) { int rc; @@ -81,7 +81,7 @@ static int sifive_gpio_init(const void *fdt, int nodeoff, u32 phandle, chip->addr = addr; chip->chip.driver = &fdt_gpio_sifive; - chip->chip.id = phandle; + chip->chip.id = nodeoff; chip->chip.ngpio = SIFIVE_GPIO_PINS_DEF; chip->chip.direction_output = sifive_gpio_direction_output; chip->chip.set = sifive_gpio_set; diff --git a/lib/utils/gpio/fdt_gpio_starfive.c b/lib/utils/gpio/fdt_gpio_starfive.c index d84ff1fe..55752425 100644 --- a/lib/utils/gpio/fdt_gpio_starfive.c +++ b/lib/utils/gpio/fdt_gpio_starfive.c @@ -71,7 +71,7 @@ static void starfive_gpio_set(struct gpio_pin *gp, int value) extern struct fdt_gpio fdt_gpio_starfive; -static int starfive_gpio_init(const void *fdt, int nodeoff, u32 phandle, +static int starfive_gpio_init(const void *fdt, int nodeoff, const struct fdt_match *match) { int rc; @@ -90,7 +90,7 @@ static int starfive_gpio_init(const void *fdt, int nodeoff, u32 phandle, chip->addr = addr; chip->chip.driver = &fdt_gpio_starfive; - chip->chip.id = phandle; + chip->chip.id = nodeoff; chip->chip.ngpio = STARFIVE_GPIO_PINS_DEF; chip->chip.direction_output = starfive_gpio_direction_output; chip->chip.set = starfive_gpio_set;