From nobody Tue Dec 2 00:02:03 2025 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 AF8162D8363 for ; Tue, 25 Nov 2025 12:55:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764075347; cv=none; b=ahiCAjc+8LSn7Y00/0g994ztfDRBl1LFSTJwXk/JM/mN+HfsLPP4HQFBVjL4Fm4A69E4jXeEEt/YxfM12Qsyu8sq/wfIUbu422Xh9fQ7xHmn0xxhmzximbG2Oa+kzz5RA3zNWB/b7fhakbSzKWwJG+02TmV5L2TJEtYBvS4ds+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764075347; c=relaxed/simple; bh=bHglC6U1OozqxXTVhErD34h2QO4PSi/HpXrwWbmU4x8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=dbIEqzunXWObAdy+q1AhS5SGceLIqyD0s5lno9mFfh+jmzHyh2fre/KfAzFCS5d3lIue6rrv7krpARUMWMegMnUE1WRYZG/Z1hajJ3A6xMb6iP60xwtu4EDlDNK9eTnwNvZjGThau9g4bzAS5lNVrtaSkisZZw1C1aDII8JReyc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=Qh/3KRmd; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="Qh/3KRmd" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-477b198f4bcso36093775e9.3 for ; Tue, 25 Nov 2025 04:55:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1764075343; x=1764680143; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=VrQgVPpQ2lbVMny7bag/S2NlxymSgh2UoS920uymtPM=; b=Qh/3KRmdvVXSdWnHXoYJzzu9/UHMZTHZeWnPVx9AVpVrUAeXQoX6se7dKaJHH7UNvc e/kgr+UmkKTW+FKAG09WVfP89O8Dp5vkaNcF52JiNcScIwxMHO0JR6musRPs+hz1apeP C9qdwyl0AU72xlvmSGBNrbe71biYdJD/iDLOKswEVUYI1FVFp6SmbnjzzUbGtCFGHYgd H6dIOx07ZbC4UCwk2YPG6FIcqp20NvUurriE98RprrLVCzgUNYj2UC3qLmAoN1j60dOE IcGO3h4aVD/faVw0h2poUuuOKBJUBtgiI5+5MtB4zjnwgrd70/LqnyuHC5hVZc7STypF hbWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764075343; x=1764680143; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=VrQgVPpQ2lbVMny7bag/S2NlxymSgh2UoS920uymtPM=; b=kx/xZfvYLaZDTet8KD/xcWoE1tdEV8+QrQfgS+Trsy03IR1XHC6EXrfo7iJ7lMAR8y jFY5n3lCjy0C+D6XNZ0oXWPxkxwV4uEJFJa77HpMj3HUo7mceIO5UK3ho3g7Vt0ymqT4 s2eTSbPweX78JVEto+3Wnn55Mf7YBbiVeUIskmNvx5Cbo3LBuAvIytOUycy/YoGhOeHg WBNbN6z8aRAMPv1MeUSfaqHaeh/7WTUiFaPkNYIgVMwSiVQfatEOJW3oc6tEjjCjrBor ui/pymiTj4ACKAPF6wrrZ7qbR/XCZH9dU+8PWPfNUQuIRb62BmKewdecHhHf+rDw85Jh KKxA== X-Forwarded-Encrypted: i=1; AJvYcCX3df0qTp0AtCeOfrqizUWfEH2XZlSD2OltWozKmDTyhF3WLQxvrb53B6j0bQxE1m4RymEJh6znvxdC9MM=@vger.kernel.org X-Gm-Message-State: AOJu0YxCOXQ+jxWVtRRlg//o8KMOTt6GvjwwZiV7os2X0jrX2AqB+uIj Edbe707FALvWtA4DMqlM8HKue/2fMMUcWlvGL8wNldyGyD/zkh3HbLcsVp6lIr5UCFI= X-Gm-Gg: ASbGncs+6ec6vplnwUafmkxXo/6OWhII2t44nDtzVqhz+Sicbn+GGDoKG+eGEz/QMtS 1gKQsl8p26f/kV6NnfXwgzA5VruHG+GB2jX8bHDYXbyBpgUWFfuDQZwejD4oaEUijvnjpQVQA7j 72xpyzWJ3HLhsz49pLTdzDw2xmV2jK14lnwDQn0XD6XqSBNkOjInPyWyIcPpZPSGscvzECwaqZT coXyWxKSjRMb5rye1dZ0GGOkSRWa/ORbDPYu46CUjOh1XwAsRwkITpnSQ9Pk9ooRca5saWEDH0x gYT1XhMtNh6cNmVG7hcO4wP6uO63OvXNDXBJhFiSbINAHK5F0ye5uyEzp+IsZb+rJ+vJIbV5vwy gCb2NbOzC5/NndmSIsvMlm1yFB8UOaRgg2M1TpoGhLSilXLaqikkzH0Ko3nlY4x+6OF36BPlpog PnrNHbKg== X-Google-Smtp-Source: AGHT+IHJl/rt+yQiY4gVfjuBNuANNJaM+KMK8zu0UKJ6yg8A/y3fdJYtIycxtF69cDY/P960+lp6NA== X-Received: by 2002:a05:600c:450b:b0:477:b642:9dc9 with SMTP id 5b1f17b1804b1-477c01d736dmr138658875e9.28.1764075342833; Tue, 25 Nov 2025 04:55:42 -0800 (PST) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:df0c:79ae:5345:c3b0]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-479052d9445sm15075685e9.11.2025.11.25.04.55.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Nov 2025 04:55:42 -0800 (PST) From: Bartosz Golaszewski Date: Tue, 25 Nov 2025 13:55:35 +0100 Subject: [PATCH] reset: gpio: add a devlink between reset-gpio and its consumer Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251125-reset-gpio-add-devlink-v1-1-a1909fef227b@linaro.org> X-B4-Tracking: v=1; b=H4sIAEanJWkC/x3MQQqEMBAF0atIr20wgYiZq4gLtb/aOERJRATx7 gaXb1F1U0JUJPoVN0WcmnQLGaYsaFz6MINVsslW1hljHUckHDzvunEvwoLzr2HlZoIbvGuk9p5 yvEdMen3jtnueF8PtNmhoAAAA X-Change-ID: 20251125-reset-gpio-add-devlink-8fe5b958d699 To: Philipp Zabel , Krzysztof Kozlowski , Val Packett Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5894; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=/Cn5DzGw9tmuv7/Ad/S+TzmqH885u2CaCD6/Juv1SFs=; b=owEBbQKS/ZANAwAKAQWdLsv/NoTDAcsmYgBpJadKf6RqXl6qeQROjtis3NItU4IW8WxjtgcvO HGOPJQZBVmJAjMEAAEKAB0WIQSR5RMt5bVGHXuiZfwFnS7L/zaEwwUCaSWnSgAKCRAFnS7L/zaE w0CKEACNlTu7UbZOAwjahuRMO6wxaEmhpxBHIi8gLefC/h+nT1DDIdy2CnVHZdWF3eQ9/+r0YlQ Qh50Pi9jJt0p02d4mW3HM4bOgA8hNoDLSMjIokTfUTpBm+5f29PsFVct2FEFpnURWNd1UYe3jrE R5aeX/2AbE1mOVT2fsmcEYj8FwtvBzBEYFLXe5bz08iiCtz91S5PNP1lBrBDAP1NUQD0u6hREdv Ln0+m3h58PxL6CmX3wIZBEwY0DanEDbOEjDiDNHiEA/yxyxb9G0WGp223zZdjfWWril9NTeOqaI mRkjxLtgAS7jZaoj6GN2KU1gqcfk2tVKSfMwx+6EM/mKD2hZsJ0f1tX6xTL9gbRut3MA/mHinrC dcF1KQ2+FSBKhnVz+0XZqUk/XE/h2hYx4GQzUpdDLQcrgveQ/AovhgFpRHRszEo2eJQAolyt8EF PvFg7zsvorNdA3tz6jtFTbnpsaJi25g5vya+2lveZqscSMfvXppW2Fbd43Ffpj1acNveQK4THvj 8JF05V81jNBZFMyWDEOJqt9rN3nlQbcRhhmcTwhspc7+mHXf7+NaTaHMic0UsJh3xZghPJZkl5G 2zq0H65Y+lMeNSQ5U0Q2DEMV+vU/WKYzhhSvE3/ng3xzkEdsBz1xlrjRp5xr42PVJU7Cs5+Qgo3 yGNZdS0eJI9oimw== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski The device that requests the reset control managed by the reset-gpio device is effectively its consumer but the devlink is only established between it and the GPIO controller exposing the reset pin. Add a devlink between the consumer of the reset control and its supplier. This will allow us to simplify the GPIOLIB code managing shared GPIOs when handling the corner case of reset-gpio and gpiolib-shared interacting. Signed-off-by: Bartosz Golaszewski --- This change will allow us to simplify the code in gpiolib-shared.c in the next cycle, so it would be awesome if it could make v6.19. Val: I'm Cc'ing you as you're already playing with audio on hamoa. If v2 of the reset-gpios fix works for you, could you please also test this and make sure it doesn't break anything with soundwire? Thanks in advance, Bart --- drivers/reset/core.c | 73 +++++++++++++++++++++++++++++++++++++++++-------= ---- 1 file changed, 58 insertions(+), 15 deletions(-) diff --git a/drivers/reset/core.c b/drivers/reset/core.c index 0135dd0ae20498396fdb5a682f913b6048cb5750..15b8da9ebcf196f7d5ce7921e4f= 8aba0ea6b0de4 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -82,6 +83,7 @@ struct reset_gpio_lookup { struct of_phandle_args of_args; struct fwnode_handle *swnode; struct list_head list; + struct auxiliary_device *adev; }; =20 static const char *rcdev_name(struct reset_controller_dev *rcdev) @@ -829,16 +831,16 @@ static void reset_gpio_aux_device_release(struct devi= ce *dev) kfree(adev); } =20 -static int reset_add_gpio_aux_device(struct device *parent, - struct fwnode_handle *swnode, - int id, void *pdata) +static struct auxiliary_device * +reset_add_gpio_aux_device(struct device *parent, struct fwnode_handle *swn= ode, + int id, void *pdata) { struct auxiliary_device *adev; int ret; =20 adev =3D kzalloc(sizeof(*adev), GFP_KERNEL); if (!adev) - return -ENOMEM; + return ERR_PTR(-ENOMEM); =20 adev->id =3D id; adev->name =3D "gpio"; @@ -850,23 +852,55 @@ static int reset_add_gpio_aux_device(struct device *p= arent, ret =3D auxiliary_device_init(adev); if (ret) { kfree(adev); - return ret; + return ERR_PTR(ret); } =20 ret =3D __auxiliary_device_add(adev, "reset"); if (ret) { auxiliary_device_uninit(adev); kfree(adev); - return ret; + return ERR_PTR(ret); } =20 - return ret; + return adev; +} + +static void reset_gpio_add_devlink(struct device_node *np, + struct reset_gpio_lookup *rgpio_dev) +{ + struct device *consumer; + + /* + * We must use get_dev_from_fwnode() and not of_find_device_by_node() + * because the latter only considers the platform bus while we want to + * get consumers of any kind that can be associated with firmware + * nodes: auxiliary, soundwire, etc. + */ + consumer =3D get_dev_from_fwnode(of_fwnode_handle(np)); + if (consumer) { + if (!device_link_add(consumer, &rgpio_dev->adev->dev, DL_FLAG_STATELESS)) + pr_warn("Failed to create a device link between reset-gpio and its cons= umer"); + + put_device(consumer); + } + /* + * else { } + * + * TODO: If ever there's a case where we need to support shared + * reset-gpios retrieved from a device node for which there's no + * device present yet, this is where we'd set up a notifier waiting + * for the device to appear in the system. This would be a lot of code + * that would go unused for now so let's cross that bridge when and if + * we get there. + */ } =20 /* - * @args: phandle to the GPIO provider with all the args like GPIO number + * @np: OF-node associated with the consumer + * @args: phandle to the GPIO provider with all the args like GPIO number */ -static int __reset_add_reset_gpio_device(const struct of_phandle_args *arg= s) +static int __reset_add_reset_gpio_device(struct device_node *np, + const struct of_phandle_args *args) { struct property_entry properties[2] =3D { }; unsigned int offset, of_flags, lflags; @@ -916,8 +950,14 @@ static int __reset_add_reset_gpio_device(const struct = of_phandle_args *args) =20 list_for_each_entry(rgpio_dev, &reset_gpio_lookup_list, list) { if (args->np =3D=3D rgpio_dev->of_args.np) { - if (of_phandle_args_equal(args, &rgpio_dev->of_args)) - return 0; /* Already on the list, done */ + if (of_phandle_args_equal(args, &rgpio_dev->of_args)) { + /* + * Already on the list, create the device link + * and stop here. + */ + reset_gpio_add_devlink(np, rgpio_dev); + return 0; + } } } =20 @@ -950,11 +990,14 @@ static int __reset_add_reset_gpio_device(const struct= of_phandle_args *args) goto err_put_of_node; } =20 - ret =3D reset_add_gpio_aux_device(parent, rgpio_dev->swnode, id, - &rgpio_dev->of_args); - if (ret) + rgpio_dev->adev =3D reset_add_gpio_aux_device(parent, rgpio_dev->swnode, + id, &rgpio_dev->of_args); + if (IS_ERR(rgpio_dev->adev)) { + ret =3D PTR_ERR(rgpio_dev->adev); goto err_del_swnode; + } =20 + reset_gpio_add_devlink(np, rgpio_dev); list_add(&rgpio_dev->list, &reset_gpio_lookup_list); =20 return 0; @@ -1034,7 +1077,7 @@ __of_reset_control_get(struct device_node *node, cons= t char *id, int index, =20 gpio_fallback =3D true; =20 - ret =3D __reset_add_reset_gpio_device(&args); + ret =3D __reset_add_reset_gpio_device(node, &args); if (ret) { rstc =3D ERR_PTR(ret); goto out_put; --- base-commit: 0067c9346f8746a9d9ddc15ffc0ddf7545d318e6 change-id: 20251125-reset-gpio-add-devlink-8fe5b958d699 Best regards, --=20 Bartosz Golaszewski