From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f170.google.com (mail-oi1-f170.google.com [209.85.167.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACAB130E0F4 for ; Sat, 14 Feb 2026 21:32:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771104768; cv=none; b=Di8qbSgFuuSctYckXC1aGPzoltlAlGKQlzlMeGhiZHyRRgFEFY1ESDjrY3N+nQlmXYKFOQMQxMJk0LKHejmx1Aj2LyzODH4SPZ6Jv1fOzGb/Na5Jo/F38JAsFiNbIvAFB5shJNoiSZWpAp6Lhe1PmeFtoF7oCGPbQ3ctgJQtLnI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771104768; c=relaxed/simple; bh=mHYCYIynKnTU9C6JHA+3biClChxi9HQvWugV7yDWqRg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=u3tj6ghDZdyNtdEgakaWTM6DalsA+pU6nyQQ/ed7CC4EGQ7XwVxaUXVpw3nte+TTrjUxRA05T98kERHghwrH5L+3K+tz/zGIarD4FQFnfBFbBdl0t88CWwn9gbnX1vCOQ9zraBXvKK0Pir8y/aJtSyoiDkEZC1L1UYYv3ANsQB8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Dt7Sqne3; arc=none smtp.client-ip=209.85.167.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Dt7Sqne3" Received: by mail-oi1-f170.google.com with SMTP id 5614622812f47-463960df4a8so1250097b6e.2 for ; Sat, 14 Feb 2026 13:32:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771104765; x=1771709565; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=L4c/Ah4XWvxrSV/SoFkvHi4YIXjIbfcCsisFz1apAmI=; b=Dt7Sqne3mt7LHEjiLpAizzud9qGkhu8FZRVJea5bQZE6KU65aDVOVu5pIy0T/MmelM cUDS35QVqsArihgdI+gxfpWrbyNBoifSVbOwXIBGN+25V/YYL2yxnL8Ys/Jqp6MmVxQw 0J3MaAgLBz3D75kNd3N74H6Lk3JlnJ593rTlzyVtpTezc4M9654BOi6H/NQyYc+W81cH MonKO3bPrrAox2WYx6nAswS4/Fh3Rm2OG3PjfKbMihRtGj+2cYeQDApfIIJtD0XiIpVd 8GKhJTEKUp2jN1rNA73zewdA/VxpthSPr/GsGauI4JdJAQd40i5/+msLhxwooSjxSz+n f4JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771104765; x=1771709565; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=L4c/Ah4XWvxrSV/SoFkvHi4YIXjIbfcCsisFz1apAmI=; b=RVvoTFf6hIG3mPiBOslDh2AjyAtCAAuMdxzao98KEZ9cFUYyo+10Qmycxoup430Ja2 3tVy4a+2l76Hik19DRAZREtXywNiqy05EwQ7RM8gtXv1P7jctN24rJNmv0iPs/z9aYE1 nmkM6wtkGG24B6//uREg8Cv1SnE1IJ66keYEmQ0rlpttWl6Pm/6S4uVXdnAKQAc7Y/zv 7sx4wiDvcUcuAXhBBl/d1N1y/zHkaQtYrKE2qxmDGAHjAoWyX9jE16gQJU7OkNmFFev5 y8zL/3Yzv6H/BsKEmNPLmSiqzJo2TfC6DBEQ8/jUkQRs2G+8R48EiPFrE4cz0XLMpmhb jePQ== X-Forwarded-Encrypted: i=1; AJvYcCU8eoKQenIU924P6XSAea0mfKUaIT/egUDdvL16YmIYArEuRldpgP+/LwqN3PRL+O2ZvzUYNc69z46w1tA=@vger.kernel.org X-Gm-Message-State: AOJu0YxIidiVeS/8NLt9OouQaYdpFThHlRLjd58Ir69sbJhlmXUAogKz bDD7Gb9pJUlcO/VJNBduNJ5kk3uZwj16J8dQvSIgAV4CUFt10Bh0JGB5gpXviw== X-Gm-Gg: AZuq6aKsVIodjpo+qOp1TvaPiiWMp/+f9+K221/WmfX+o76rzoq3g0z6wIPEyF4z4Ca PRPAnWCwN1Hi/7sQHh+Y+hthAT3Z4prUkDE6/ATKdDWoA/p9T4reZo43L6j6sQ6WMW1LOTQDOAS a8+gY3q8fiPcgIL2S60s2nDmJ7oMFPCepZhxzYt+f2R/1FRWDYocBxo6AuhiISComEeBNF22GTv UU4Eenv5gDcGX68z5EOa6I8d4B3FP9udQTuvk0O4g9P0VKrYK1DDhlMYte9kag34ZK6ksNIVhZj 5YyBC+bzP7f7AP2RgrSExsVHN9slr40x3+7CsEQ3E7V39aS2Vblaw66g2imFJh2uUj2czHTBlWG WZpXQy7a1eD3xJpfAO4QAtTjBGp3Oj8rjt0HAjil7Ma3mXDvUXogta1uGgjNz1zn6hef4vbl5Iy pCYgG3oiL4lfUqJveyL2DNxcm2MNFPLOiRBKBqs/ec6sbfrzMs+MSBVjHSsJw5zQiudfnLbKwrw geoK0LKxp6TeVxvgOirgXcXQqUAD5OtUUOMBFm4yUwGszjw3FEewfCKk9MlCxI= X-Received: by 2002:a05:6808:1208:b0:450:4628:e3ce with SMTP id 5614622812f47-4639ef1a5f3mr3413419b6e.15.1771104765501; Sat, 14 Feb 2026 13:32:45 -0800 (PST) Received: from james-x399.localdomain (71-218-105-26.hlrn.qwest.net. [71.218.105.26]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4636ae901d4sm7319937b6e.2.2026.02.14.13.32.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Feb 2026 13:32:44 -0800 (PST) From: James Hilliard To: linux-gpio@vger.kernel.org Cc: James Hilliard , Linus Walleij , Bartosz Golaszewski , Rob Herring , Saravana Kannan , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v2 1/1] gpiolib: of: add gpio-line node support Date: Sat, 14 Feb 2026 14:32:37 -0700 Message-ID: <20260214213239.2546012-1-james.hilliard1@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Allow GPIO controller child nodes marked with "gpio-line" to configure direction/flags at probe time without hogging the line. Teach OF gpiochip scanning and OF dynamic reconfiguration handlers to process gpio-line nodes in addition to gpio-hog nodes. Also parse "gpio-line-name" and apply it to desc->name. For gpio-hog nodes, keep "line-name" semantics as the hog consumer label. Signed-off-by: James Hilliard --- Depends on: - https://github.com/devicetree-org/dt-schema/pull/185 Changes v1 -> v2: - drop documentation changes - add depends on to changelog --- drivers/gpio/gpiolib-of.c | 89 ++++++++++++++++++++++++++++------- drivers/gpio/gpiolib-shared.c | 7 +-- drivers/of/property.c | 7 +-- scripts/dtc/checks.c | 4 +- 4 files changed, 82 insertions(+), 25 deletions(-) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index ef1ac68b94b7..b10a21a63d46 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -744,6 +744,7 @@ struct gpio_desc *of_find_gpio(struct device_node *np, const char *con_id, * @lflags: bitmask of gpio_lookup_flags GPIO_* values - returned from * of_find_gpio() or of_parse_own_gpio() * @dflags: gpiod_flags - optional GPIO initialization flags + * @hog: indicates if this is a gpio-hog node * * Returns: * GPIO descriptor to use with Linux GPIO API, or one of the errno @@ -753,11 +754,13 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np, struct gpio_chip *chip, unsigned int idx, const char **name, unsigned long *lflags, - enum gpiod_flags *dflags) + enum gpiod_flags *dflags, + bool hog) { struct device_node *chip_np; enum of_gpio_flags xlate_flags; struct of_phandle_args gpiospec; + const char *desc_name; struct gpio_desc *desc; unsigned int i; u32 tmp; @@ -797,15 +800,19 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np, *dflags |= GPIOD_OUT_LOW; else if (of_property_read_bool(np, "output-high")) *dflags |= GPIOD_OUT_HIGH; - else { + else if (hog) { pr_warn("GPIO line %d (%pOFn): no hogging state specified, bailing out\n", desc_to_gpio(desc), np); return ERR_PTR(-EINVAL); } - if (name && of_property_read_string(np, "line-name", name)) + if (hog && name && of_property_read_string(np, "line-name", name)) *name = np->name; + if (!of_property_read_string(np, "gpio-line-name", &desc_name) && + desc_name[0]) + desc->name = desc_name; + return desc; } @@ -827,7 +834,8 @@ static int of_gpiochip_add_hog(struct gpio_chip *chip, struct device_node *hog) int ret; for (i = 0;; i++) { - desc = of_parse_own_gpio(hog, chip, i, &name, &lflags, &dflags); + desc = of_parse_own_gpio(hog, chip, i, &name, &lflags, &dflags, + true); if (IS_ERR(desc)) break; @@ -843,6 +851,36 @@ static int of_gpiochip_add_hog(struct gpio_chip *chip, struct device_node *hog) return 0; } +/** + * of_gpiochip_add_line - Configure all lines in a gpio-line device node + * @chip: gpio chip to act on + * @line: device node describing GPIO lines to configure + * + * Returns: + * 0 on success, or negative errno on failure. + */ +static int of_gpiochip_add_line(struct gpio_chip *chip, struct device_node *line) +{ + enum gpiod_flags dflags; + struct gpio_desc *desc; + unsigned long lflags; + unsigned int i; + int ret; + + for (i = 0;; i++) { + desc = of_parse_own_gpio(line, chip, i, NULL, &lflags, &dflags, + false); + if (IS_ERR(desc)) + break; + + ret = gpiod_configure_flags(desc, NULL, lflags, dflags); + if (ret < 0) + return ret; + } + + return 0; +} + /** * of_gpiochip_scan_gpios - Scan gpio-controller for gpio definitions * @chip: gpio chip to act on @@ -858,14 +896,22 @@ static int of_gpiochip_scan_gpios(struct gpio_chip *chip) int ret; for_each_available_child_of_node_scoped(dev_of_node(&chip->gpiodev->dev), np) { - if (!of_property_read_bool(np, "gpio-hog")) + if (of_property_read_bool(np, "gpio-hog")) { + ret = of_gpiochip_add_hog(chip, np); + if (ret < 0) + return ret; + + of_node_set_flag(np, OF_POPULATED); continue; + } - ret = of_gpiochip_add_hog(chip, np); - if (ret < 0) - return ret; + if (of_property_read_bool(np, "gpio-line")) { + ret = of_gpiochip_add_line(chip, np); + if (ret < 0) + return ret; - of_node_set_flag(np, OF_POPULATED); + of_node_set_flag(np, OF_POPULATED); + } } return 0; @@ -905,14 +951,15 @@ static int of_gpio_notify(struct notifier_block *nb, unsigned long action, int ret; /* - * This only supports adding and removing complete gpio-hog nodes. - * Modifying an existing gpio-hog node is not supported (except for - * changing its "status" property, which is treated the same as - * addition/removal). + * This only supports adding and removing complete gpio-hog and + * gpio-line nodes. Modifying an existing node is not supported + * (except for changing its "status" property, which is treated + * the same as addition/removal). */ switch (of_reconfig_get_state_change(action, arg)) { case OF_RECONFIG_CHANGE_ADD: - if (!of_property_read_bool(rd->dn, "gpio-hog")) + if (!of_property_read_bool(rd->dn, "gpio-hog") && + !of_property_read_bool(rd->dn, "gpio-line")) return NOTIFY_DONE; /* not for us */ if (of_node_test_and_set_flag(rd->dn, OF_POPULATED)) @@ -922,9 +969,12 @@ static int of_gpio_notify(struct notifier_block *nb, unsigned long action, if (!gdev) return NOTIFY_DONE; /* not for us */ - ret = of_gpiochip_add_hog(gpio_device_get_chip(gdev), rd->dn); + if (of_property_read_bool(rd->dn, "gpio-hog")) + ret = of_gpiochip_add_hog(gpio_device_get_chip(gdev), rd->dn); + else + ret = of_gpiochip_add_line(gpio_device_get_chip(gdev), rd->dn); if (ret < 0) { - pr_err("%s: failed to add hogs for %pOF\n", __func__, + pr_err("%s: failed to configure lines for %pOF\n", __func__, rd->dn); of_node_clear_flag(rd->dn, OF_POPULATED); return notifier_from_errno(ret); @@ -932,6 +982,10 @@ static int of_gpio_notify(struct notifier_block *nb, unsigned long action, return NOTIFY_OK; case OF_RECONFIG_CHANGE_REMOVE: + if (!of_property_read_bool(rd->dn, "gpio-hog") && + !of_property_read_bool(rd->dn, "gpio-line")) + return NOTIFY_DONE; /* not for us */ + if (!of_node_check_flag(rd->dn, OF_POPULATED)) return NOTIFY_DONE; /* already depopulated */ @@ -939,7 +993,8 @@ static int of_gpio_notify(struct notifier_block *nb, unsigned long action, if (!gdev) return NOTIFY_DONE; /* not for us */ - of_gpiochip_remove_hog(gpio_device_get_chip(gdev), rd->dn); + if (of_property_read_bool(rd->dn, "gpio-hog")) + of_gpiochip_remove_hog(gpio_device_get_chip(gdev), rd->dn); of_node_clear_flag(rd->dn, OF_POPULATED); return NOTIFY_OK; } diff --git a/drivers/gpio/gpiolib-shared.c b/drivers/gpio/gpiolib-shared.c index b3525d1f06a4..b934e58a07f0 100644 --- a/drivers/gpio/gpiolib-shared.c +++ b/drivers/gpio/gpiolib-shared.c @@ -147,10 +147,11 @@ static bool gpio_shared_of_node_ignore(struct device_node *node) return true; /* - * GPIO hogs have a "gpios" property which is not a phandle and can't - * possibly refer to a shared GPIO. + * GPIO hog and gpio-line nodes have a "gpios" property which is not a + * phandle and can't possibly refer to a shared GPIO. */ - if (of_property_present(node, "gpio-hog")) + if (of_property_present(node, "gpio-hog") || + of_property_present(node, "gpio-line")) return true; return false; diff --git a/drivers/of/property.c b/drivers/of/property.c index 50d95d512bf5..7689c4315115 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -1435,10 +1435,11 @@ static struct device_node *parse_gpio_compat(struct device_node *np, return NULL; /* - * Ignore node with gpio-hog property since its gpios are all provided - * by its parent. + * Ignore nodes with gpio-hog and gpio-line properties since their gpios + * are all provided by their parent. */ - if (of_property_read_bool(np, "gpio-hog")) + if (of_property_read_bool(np, "gpio-hog") || + of_property_read_bool(np, "gpio-line")) return NULL; if (of_parse_phandle_with_args(np, prop_name, "#gpio-cells", index, diff --git a/scripts/dtc/checks.c b/scripts/dtc/checks.c index 45d0213f3bf3..ee64cb4ada4f 100644 --- a/scripts/dtc/checks.c +++ b/scripts/dtc/checks.c @@ -1533,8 +1533,8 @@ static void check_gpios_property(struct check *c, { struct property *prop; - /* Skip GPIO hog nodes which have 'gpios' property */ - if (get_property(node, "gpio-hog")) + /* Skip gpio-hog and gpio-line nodes which have 'gpios' property */ + if (get_property(node, "gpio-hog") || get_property(node, "gpio-line")) return; for_each_property(node, prop) { -- 2.43.0