From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C93B35D604 for ; Mon, 23 Feb 2026 10:06:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771841203; cv=none; b=ZCdNYsYtpv9YXI+KqaT7Uccnvo5AY5DXzsxRgwvbCT+vz4kiplBmyvkRxeHmoSAG68N/7Sg25ARSEGxsC2KVMlV2LoZthA0wVwNYF3L4r2IKfAVA66xExGEMTknN1Zh3yDEF44VzXOjwmWB2Ve/7zjtOCSijmENNoy7XoZce/D4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771841203; c=relaxed/simple; bh=JZWuny8/TcvSZjzaVdqaESeV6oNV6YTL1+iT2y0pExo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eEU9UT2/1/aZnGsc2j7docHijlBqWoL1XiPApBkaW4iOsy5W9B6A0qRV240CDIn1GTw/5+pV88znMOwA5JP6jnqqD6lX/PsS6R6ZtLbdaY2tjKX8IabyCNvPTgzELLpIR/mGXjJDkotpCWMzRW4TakjLNQG3qaFm4PAUe1YhB8w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=nk46jamK; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=csluF7hU; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="nk46jamK"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="csluF7hU" Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 61N17nML2203676 for ; Mon, 23 Feb 2026 10:06:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= R3rlwUodHa1xBLQFp92Dedtm+Zhls9xlJ8VVyipx7aA=; b=nk46jamKMyJuWz3Y Hy5L1s3SDaDgWfyQ6ODqtJUgDRRPjxdS/Zr/td99NhNMe8SUlDEd+Z6zskiqpvOV gcadDLr3Q03XwfHNFwtr+yX+8MRVH5ikT7qURvue1oZupKHqvkfzWPOg3F7S4HZv 4F9zwT3Qx7VYvx3/dojQIwmQfshqkXs4sBtdCInbhDxPoZNb00BxQAbBYDv+a1uA DblgE0Na4EsKP77J1Dr7S3i75yFSPdu27iqsJ+HggZkfe5Wlz2Rp6e/QkZOY39EQ 1cSJll3P/8kJ2YaHy2OMsY4VSgkCV0VmvCjHUgYwWVpoPRfd54vlliTCAPDmw9zM 2CYbKA== Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4cf5wbca6e-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 23 Feb 2026 10:06:40 +0000 (GMT) Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-8cb706313beso580451385a.3 for ; Mon, 23 Feb 2026 02:06:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1771841200; x=1772446000; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=R3rlwUodHa1xBLQFp92Dedtm+Zhls9xlJ8VVyipx7aA=; b=csluF7hU/VIebD1HFzOZOphMmLgeqwW/4MHRhvYbqlf0HOwBdRBp0w5L9slcVtnQOc Q7FFOlv/8fzkZomYZRxVbqMTzY6mp3ojyr9wVARIs2z4welwLeUu65d/p/7koa50zUXf qjlBiBDati44Oyv/PCY74DyGGt9eBJVCxTIJs+dDh0OOr6rkTps30dbeBGowW+hUJIi/ RSwJgrDKi0M+S0ux4rcHL9dNWwlNAATAexe7VFPClQnE7x75ruKeXRlaWWbdMvL6IWP4 0Aaw3bPlfxlZx3hOj8Q2PlY/nJQxxSmlND1s2GObR0cApsQJTXJIj5PR5RbG8MzPD59L UI4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771841200; x=1772446000; h=cc:to:in-reply-to:references: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=R3rlwUodHa1xBLQFp92Dedtm+Zhls9xlJ8VVyipx7aA=; b=pKz6Umm0hQgud9cvuzOEyT2/fsm3Hi5orbSrzIykY3Cfx37Wdgs26bwiMQZ9E/cH4X me8DjSgB/hlXUHDpGhjG7D0CUit0nHn32tJKE4cypPhqv1edG8RA3DLAVykHoyEx8rnK yBxa7axjJBzQFZPFWK2LuUvHeN9O/KR050bSwdJVJDPjBVxXOsRNV9oRhLsSNhwbD8PR 5fagnlmJWRRKh3aa8ZVkUKkLaFupihZqxdpXybaGgMfPTOdTd0Q0MidcClVEtWcA+Vjp VgkBCzpvsxrnUPxgMu8GJ5R2bcnrlHjqDhAfElWnuP1lFRf0FYItDwk5IXsZdtBazHMB Xvgw== X-Gm-Message-State: AOJu0YyJNZi4kXjZX3xakexS1rN+a+I57QXXG47kncv71kesREGVMvL4 O9XLygEG4vaTiksIJuYiPslJwwIXl5iTK+3jZUbh7/hpbrVYUnNGHGCRy3JrlkR+nX5/jmmtCCr 1MbJSak6sw/s98deq1VAHUz7SjI88GjVifJ+XXqVSdEcagyS1uqJ54q1rLLSaY2ruIXrskdgk3R Y= X-Gm-Gg: AZuq6aJPf5f4ieOYzPR12L5BYo7KOkEpliP3ys73/geUinNlop25UhyqAp2GrowfQch OaNRl8t58O0jjt3U9F9jmoMSdu8Je+8x96gLcuF8/hsY326yrG07PMBOlSgKQxAbuKwSYP4t3Tj z5AkLkdKObIfJBqwHz7CihHw0H/8vYukey8OB7Fc/RWtlTDCN1rhrGyDy2XGp4ZX1ygzMUL/+Af 5172W3c+Q6EVj1rhg7LqX3/4jHuIJsk2iAL6bnSj2Y8fhCbKFMeAn90+cV4ttjgBlEZAeSTWe2y u33o9RCO/mh0TYye+KXU8vvdKXw7wsqSPOd2hiQEvqQS1gZqR1P0oSdsyErjczkPMxrj3K8Z24e /Wy9N7S5g/N56GGBhDtrq/U7ku/UG1B5aunqAmQ2CeUxbQT16LvWD X-Received: by 2002:a05:620a:3706:b0:8be:dd2c:a0fd with SMTP id af79cd13be357-8cb8ca66084mr958516885a.44.1771841199810; Mon, 23 Feb 2026 02:06:39 -0800 (PST) X-Received: by 2002:a05:620a:3706:b0:8be:dd2c:a0fd with SMTP id af79cd13be357-8cb8ca66084mr958513385a.44.1771841199236; Mon, 23 Feb 2026 02:06:39 -0800 (PST) Received: from brgl-qcom.local ([2a01:cb1d:dc:7e00:bd71:422c:5e83:8b37]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43970d54760sm18288885f8f.35.2026.02.23.02.06.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Feb 2026 02:06:38 -0800 (PST) From: Bartosz Golaszewski Date: Mon, 23 Feb 2026 11:06:15 +0100 Subject: [PATCH v2 02/14] 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: 7bit Message-Id: <20260223-reset-core-refactor-v2-2-5e5a7289190c@oss.qualcomm.com> References: <20260223-reset-core-refactor-v2-0-5e5a7289190c@oss.qualcomm.com> In-Reply-To: <20260223-reset-core-refactor-v2-0-5e5a7289190c@oss.qualcomm.com> To: Krzysztof Kozlowski , Philipp Zabel Cc: linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5824; i=bartosz.golaszewski@oss.qualcomm.com; h=from:subject:message-id; bh=JZWuny8/TcvSZjzaVdqaESeV6oNV6YTL1+iT2y0pExo=; b=owEBbQKS/ZANAwAKAQWdLsv/NoTDAcsmYgBpnCagCkVOuhGU6iU+OCIIx96hU0Nj4o0r+Pofp nJ5EUefInqJAjMEAAEKAB0WIQSR5RMt5bVGHXuiZfwFnS7L/zaEwwUCaZwmoAAKCRAFnS7L/zaE w3sFD/9on0QjCLLAndgkc0/WOLQTch+SEQp74Q/QrIZMiJVSIK35f3fLSlvFUsDU2TEFFw7k5nA CyFlC370exYea9CCKhCCu79PyNXfK44hdcswmFPnU4jsWNokiCrt9FysuhQWQ8IwSOkLnlf6Jv1 cvp+0jnFqUOyviwoKUKC0vjxjGUoi0BFp1GIaqpiKYxtgKKAe0QFTzl2WaZvvPtChtHvkAu/Xji B9+qprNy9fpy0liPC1v3h72t3W5uuQ4tkIHAXoaVFm4P/oDVBbmbtzxnOWGUH3oFVKVOqtf4RLo 6B4yRgou/MEzAyjwlF0UOstwDemAgoIZ9t9OqnoFiB8HankYM0pzZpM5Cg9GtJWmEaVZWmsuD7Y PzZHlOfz1EScFy5ONnlgV6FOCkIcZK1DSmeFpnUqoxvTtLhaD29iPjuvAba8ukzMxzZWR8ztEPL Dtw3Nn9QRnFDqRZ5zNgcVyyk+gbHg7NVcoos+1GueDT7zWxoDqqqBQkMUW8Ayq0K30xztBVU5qs /RZLsTcf6t7msvML/5xhJWUsEXYxoCVsRizde4xTGf/sHYpUrq3wMk+Sah5/5XrjI1t4CxVdcj6 GsRKm+UipoYw9I3Gk79O7ROaE4AU7LDLiLjK+Zt+wjg/6wSZ9Vu5vYVZdFLzIpYqCy2m21N7lTV 2g5jnehox3TX0OQ== X-Developer-Key: i=bartosz.golaszewski@oss.qualcomm.com; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 X-Proofpoint-ORIG-GUID: D3Uhtj5SO8anj1oC0RC0mEQ8VhKxEhfa X-Authority-Analysis: v=2.4 cv=UZlciaSN c=1 sm=1 tr=0 ts=699c26b0 cx=c_pps a=qKBjSQ1v91RyAK45QCPf5w==:117 a=xqWC_Br6kY4A:10 a=IkcTkHD0fZMA:10 a=HzLeVaNsDn8A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=eoimf2acIAo5FJnRuUoq:22 a=EUspDBNiAAAA:8 a=gl4R_IGdbvU1KyCt79YA:9 a=QEXdDO2ut3YA:10 a=NFOGd7dJGGMPyQGDc5-O:22 X-Proofpoint-GUID: D3Uhtj5SO8anj1oC0RC0mEQ8VhKxEhfa X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMjIzMDA4NiBTYWx0ZWRfXz23ZXFpZsLnL eQHJ96vtiVSDUyKoG15Xbi7Yod5wiHcveZFFCiTgi12Y1sNsYPhLqe8DMq/5QU6lpPS8nak7/6h N5Gfri3Th8uuipH2XoAAGlusB0NHSgUcHvoT0/tUUGC/LVRyqGPj49hpkBGmbWPzzWS+Ox7sNWp AgVxltSCxXJhOWLPulRPKuSfIkgZoTzoDyHdrzEgjIYF/kumEyMtDyQLbQyXD/LTWum1XHREThp oZHNal4UyUeWaPMnlNzsZAyNg0jaLMKSS7ZMrYwydAoiNIkF39musjlKwsnNtSYQrD/QT4BxQsi 9TfWJ24vDuCWMp+ix8o3yav57LuCLrZNLxUk7hcHJv4AGqyDOcsJIqvUxWsDM922CDLZFA8KIco E0Yni+S4UV6lHZ1TCbPiGiMSD1139Ns4QSUVuoP6vdMOGALGtRjvC1oc+48A+wd+RnfmyI52AHZ xNByfL3OWmJpsy3rsCA== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-02-23_02,2026-02-20_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 phishscore=0 spamscore=0 malwarescore=0 bulkscore=0 impostorscore=0 lowpriorityscore=0 clxscore=1015 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2602130000 definitions=main-2602230086 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. While at it and since we need to store the address of the auxiliary device: don't allocate memory for the device separately but fold it into struct reset_gpio_lookup instead. Reviewed-by: Philipp Zabel Signed-off-by: Bartosz Golaszewski --- drivers/reset/core.c | 79 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 24 deletions(-) diff --git a/drivers/reset/core.c b/drivers/reset/core.c index fceec45c8afc1e74fe46311bdc023ff257e8d770..3845e77a8d32bf615c9d430847b497af0ba374ad 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c @@ -77,11 +77,13 @@ struct reset_control_array { * @of_args: phandle to the reset controller with all the args like GPIO number * @swnode: Software node containing the reference to the GPIO provider * @list: list entry for the reset_gpio_lookup_list + * @adev: Auxiliary device representing the reset controller */ struct reset_gpio_lookup { struct of_phandle_args of_args; struct fwnode_handle *swnode; struct list_head list; + struct auxiliary_device adev; }; static const char *rcdev_name(struct reset_controller_dev *rcdev) @@ -824,49 +826,72 @@ static void __reset_control_put_internal(struct reset_control *rstc) static void reset_gpio_aux_device_release(struct device *dev) { - struct auxiliary_device *adev = to_auxiliary_dev(dev); - kfree(adev); } -static int reset_add_gpio_aux_device(struct device *parent, - struct fwnode_handle *swnode, - int id, void *pdata) +static int reset_create_gpio_aux_device(struct reset_gpio_lookup *rgpio_dev, + struct device *parent, int id) { - struct auxiliary_device *adev; + struct auxiliary_device *adev = &rgpio_dev->adev; int ret; - adev = kzalloc_obj(*adev); - if (!adev) - return -ENOMEM; - adev->id = id; adev->name = "gpio"; adev->dev.parent = parent; - adev->dev.platform_data = pdata; + adev->dev.platform_data = &rgpio_dev->of_args; adev->dev.release = reset_gpio_aux_device_release; - device_set_node(&adev->dev, swnode); + device_set_node(&adev->dev, rgpio_dev->swnode); ret = auxiliary_device_init(adev); - if (ret) { - kfree(adev); + if (ret) return ret; - } ret = __auxiliary_device_add(adev, "reset"); if (ret) { auxiliary_device_uninit(adev); - kfree(adev); return ret; } - return ret; + return 0; +} + +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 = get_dev_from_fwnode(of_fwnode_handle(np)); + if (consumer) { + if (!device_link_add(consumer, &rgpio_dev->adev.dev, + DL_FLAG_AUTOREMOVE_CONSUMER)) + pr_warn("Failed to create a device link between reset-gpio and its consumer"); + + 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. + */ } /* - * @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 *args) +static int __reset_add_reset_gpio_device(struct device_node *np, + const struct of_phandle_args *args) { struct property_entry properties[3] = { }; unsigned int offset, of_flags, lflags; @@ -916,8 +941,14 @@ static int __reset_add_reset_gpio_device(const struct of_phandle_args *args) list_for_each_entry(rgpio_dev, &reset_gpio_lookup_list, list) { if (args->np == 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; + } } } @@ -951,11 +982,11 @@ static int __reset_add_reset_gpio_device(const struct of_phandle_args *args) goto err_put_of_node; } - ret = reset_add_gpio_aux_device(parent, rgpio_dev->swnode, id, - &rgpio_dev->of_args); + ret = reset_create_gpio_aux_device(rgpio_dev, parent, id); if (ret) goto err_del_swnode; + reset_gpio_add_devlink(np, rgpio_dev); list_add(&rgpio_dev->list, &reset_gpio_lookup_list); return 0; @@ -1035,7 +1066,7 @@ __of_reset_control_get(struct device_node *node, const char *id, int index, gpio_fallback = true; - ret = __reset_add_reset_gpio_device(&args); + ret = __reset_add_reset_gpio_device(node, &args); if (ret) { rstc = ERR_PTR(ret); goto out_put; -- 2.47.3