From nobody Wed Feb 11 03:02:41 2026 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (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 C5F101FA859 for ; Fri, 3 Jan 2025 14:00:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735912864; cv=none; b=WOlz/ZtXfyH+oPeKHZmrylIZNe2M4pj3YK71DHzH8i7yL9Ykr7RRGyKmo/vBvRSpGNO+9e2h/wZqM0/pJ9r5rV8NOs4u1OEMYs0bxP83nWoEJRgbT4tB2I0Z3ieeO2RHYGNqCNPmm+tdCnb9KvodG0enf5ntsZWvIQUG0Mkm87w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735912864; c=relaxed/simple; bh=EuNVdSlSZudyJoOAdfDuJcdMXRlPdSBuq49eBU9+fpc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Iw56xZewVpj071l20MIEx3/JpfVs3gr7b1kKl/i63M3taoWtrKCqBs8TlCo5vUTgjmIijffcuOQALx3JKiV3+ZzvwOVYiyhjg8FzE/2RbBdKPXtyHvfzCH5ax/roadKZjI8K2aQu7OWMeDNNRGXq+TUuSMWFji7/yASnONtj5zY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=T/bZ5UT7; arc=none smtp.client-ip=209.85.208.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="T/bZ5UT7" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-5d3d143376dso17880455a12.3 for ; Fri, 03 Jan 2025 06:00:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1735912857; x=1736517657; darn=vger.kernel.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=ZyoJR7eM+UULUVfgeh2RQ3JsSmCjTnPlEP7eCTmVZEM=; b=T/bZ5UT73CoqhM5XtnHfBCJOiLWuWT0OfsmasT+MBHyRKh6X62SEjlKJPUt/H5o7cf 5FnhkUNZdiYhObMiH5CjDWazzu1Ywhhw6URKiUWJ/BmGOmKiJXc+qEsWBVUtapza+fne SZL/UHtQt5z9RWHj2RCltLmxMibB041T2ILjvF3HKg4r7+XXa9ps9ojocjPB6GEhI7oe EPVu1YYJLcgQoMOzKNRsSglUba7S0FgzcHeZ+SiChyJ2I21CTYjihUlVfQzn+d6/CLJ/ VXKfRWYkS+9Upsu/rlxL1BjMkp/eaxLIuRfqeGiJ7yaeBWFSblsRcLwuZSOxnKJ8nioH 6EWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735912857; x=1736517657; 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=ZyoJR7eM+UULUVfgeh2RQ3JsSmCjTnPlEP7eCTmVZEM=; b=rjPGkhbGF2er2s9uXf3SRVraI1AuCmPcskSJfRMXaPzMLRrPBuPtdaYzdWLCOqWW3d +jy5lHiOJNe95UFsIXEZ4/yla4IvShlKYjxPjVCFt+ep9dKLIL5ziLRlfyOlRlPmJSLu 4hpx7P+7rBG1Exn82FSY/kad9ExBAbyG1frEfCeWZ0WlVfl+WMyovevbErrfr88Uy05v rUlxbJrraorvTJNriwzBF6biJTxaFQ9HbykGKsHfQq5E9lXqYb6dt8TIyHEsssLpIhR8 JBpCygI8yoSwlZS48txeoAa5QZMRdV2g+Nrc9zZwJNyd64RJzF7fhNTX1nrwI9l9kYeV AlwQ== X-Forwarded-Encrypted: i=1; AJvYcCVFM1NEyekN8tUm3sMjjiDynJjmd76oSO2yEvH70MMNjynxogTDwAMdjLycjcuDV6dZL0bpIBUI2KSHQb0=@vger.kernel.org X-Gm-Message-State: AOJu0YwoLv710Jh8k9VAIxx/1dS62DCq1gxUjeVSSWLukn7f8AS5tw01 l9Z53SZUuIBnmU8zehF188sfF7QSahS36frg8yAPdm2Epk/bD85UF8dTRj804Gk= X-Gm-Gg: ASbGnctvB2YPQjRCgGD+t4CjHjYsL367lvArVJYbVn7uEI58geFhb1esM/hbFYUnJYw jsril9ndgVTd+evp5yTokLuxM3rMLOcC29907yCX+imxBRfdpMvU1KPFpabwJgeQIhDWTzZ2S8k sYcYrorRYCbCfPOmJp1c/+2RC6tPyWycYP67okPbxYAeJwD1AgZ/FuQ/90/SvhRbmD05wKIqXP8 KWKK2OduVqt3ien+RHy78G86nxkcVL+eBj2It2Ne4COkzX5LaV8W2fNAqlj6CYGdUVMmcB6/BoC +ZU0zXnTdkk= X-Google-Smtp-Source: AGHT+IH73GcCsE/lQyg6qOmyCUftPapB8Jd9zfJekawKG6luwVZg0kmD20Vj1IYY2YIztuCKga/dhg== X-Received: by 2002:a05:6402:13cf:b0:5d3:fc60:a504 with SMTP id 4fb4d7f45d1cf-5d81ddb0d51mr39508173a12.20.1735912856437; Fri, 03 Jan 2025 06:00:56 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.102]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d80679f0e4sm19502384a12.42.2025.01.03.06.00.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jan 2025 06:00:55 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: prabhakar.mahadev-lad.rj@bp.renesas.com, jic23@kernel.org, lars@metafoo.de, ulf.hansson@linaro.org Cc: linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, claudiu.beznea@tuxon.dev, Claudiu Beznea Subject: [PATCH 1/2] iio: adc: rzg2l_adc: Drop devm_pm_runtime_enable() Date: Fri, 3 Jan 2025 16:00:41 +0200 Message-ID: <20250103140042.1619703-2-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250103140042.1619703-1-claudiu.beznea.uj@bp.renesas.com> References: <20250103140042.1619703-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea On all systems where the rzg2l_adc driver is used, the ADC clocks are part of a PM domain. The code that implements the PM domains support is in drivers/clk/renesas/rzg2l-cpg.c, the functions of interest for this commit being rzg2l_cpg_attach_dev() and rzg2l_cpg_deattach_dev(). The PM domains support is registered with GENPD_FLAG_PM_CLK which, according to the documentation, instructs genpd to use the PM clk framework while powering on/off attached devices. During probe, the ADC device is attached to the PM domain controlling the ADC clocks. Similarly, during removal, the ADC device is detached from the PM domain. The detachment call stack is as follows: device_driver_detach() -> device_release_driver_internal() -> __device_release_driver() -> device_remove() -> platform_remove() -> dev_pm_domain_detach() During driver unbind, after the ADC device is detached from its PM domain, the device_unbind_cleanup() function is called, which subsequently invokes devres_release_all(). This function handles devres resource cleanup. If runtime PM is enabled via devm_pm_runtime_enable(), the cleanup process triggers the action or reset function for disabling runtime PM. This function is pm_runtime_disable_action(), which leads to the following call stack of interest when called: pm_runtime_disable_action() -> pm_runtime_dont_use_autosuspend() -> __pm_runtime_use_autosuspend() -> update_autosuspend() -> rpm_idle() The rpm_idle() function attempts to runtime resume the ADC device. However, at the point it is called, the ADC device is no longer part of the PM domain (which manages the ADC clocks). Since the rzg2l_adc runtime PM APIs directly modifies hardware registers, the rzg2l_adc_pm_runtime_resume() function is invoked without the ADC clocks being enabled. This is because the PM domain no longer resumes along with the ADC device. As a result, this leads to system aborts. Drop the devres API for runtime PM enable. Fixes: 89ee8174e8c8 ("iio: adc: rzg2l_adc: Simplify the runtime PM code") Signed-off-by: Claudiu Beznea Reviewed-by: Ulf Hansson --- drivers/iio/adc/rzg2l_adc.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/drivers/iio/adc/rzg2l_adc.c b/drivers/iio/adc/rzg2l_adc.c index 883c167c0670..f12f3daf08cc 100644 --- a/drivers/iio/adc/rzg2l_adc.c +++ b/drivers/iio/adc/rzg2l_adc.c @@ -464,25 +464,26 @@ static int rzg2l_adc_probe(struct platform_device *pd= ev) =20 pm_runtime_set_autosuspend_delay(dev, 300); pm_runtime_use_autosuspend(dev); - ret =3D devm_pm_runtime_enable(dev); - if (ret) - return ret; + pm_runtime_enable(dev); =20 platform_set_drvdata(pdev, indio_dev); =20 ret =3D rzg2l_adc_hw_init(dev, adc); - if (ret) - return dev_err_probe(&pdev->dev, ret, - "failed to initialize ADC HW\n"); + if (ret) { + dev_err_probe(&pdev->dev, ret, "failed to initialize ADC HW\n"); + goto rpm_disable; + } =20 irq =3D platform_get_irq(pdev, 0); - if (irq < 0) - return irq; + if (irq < 0) { + ret =3D irq; + goto rpm_disable; + } =20 ret =3D devm_request_irq(dev, irq, rzg2l_adc_isr, 0, dev_name(dev), adc); if (ret < 0) - return ret; + goto rpm_disable; =20 init_completion(&adc->completion); =20 @@ -493,6 +494,19 @@ static int rzg2l_adc_probe(struct platform_device *pde= v) indio_dev->num_channels =3D adc->data->num_channels; =20 return devm_iio_device_register(dev, indio_dev); + +rpm_disable: + pm_runtime_disable(dev); + pm_runtime_dont_use_autosuspend(dev); + return ret; +} + +static void rzg2l_adc_remove(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + + pm_runtime_disable(dev); + pm_runtime_dont_use_autosuspend(dev); } =20 static const struct rzg2l_adc_hw_params rzg2l_hw_params =3D { @@ -614,6 +628,7 @@ static const struct dev_pm_ops rzg2l_adc_pm_ops =3D { =20 static struct platform_driver rzg2l_adc_driver =3D { .probe =3D rzg2l_adc_probe, + .remove =3D rzg2l_adc_remove, .driver =3D { .name =3D DRIVER_NAME, .of_match_table =3D rzg2l_adc_match, --=20 2.43.0 From nobody Wed Feb 11 03:02:41 2026 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.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 A15331FAC4D for ; Fri, 3 Jan 2025 14:01:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735912867; cv=none; b=qhM1OSzUylV72rCAnFE1ziRInic2dwYw/zycmX+kv69bOEXWHlKWgJhj5JJkp32nZk/FSjeo9Ytz4ReA+00MhAVuQ98tZTDha0YcU3yV2nZhOaK/GgscZkF6R+lt8CgZ9dbezNe/9cvt7EDxVnGoJkXHSmfzU0XGst2nFHdBxH8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735912867; c=relaxed/simple; bh=Fmy27Bnmn3Uj8FkD7cvCCt580n5f2IKg/FvXHV0a6+E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mmy6XYxfF0IQjdYj/bpHCrLTC4CzdDa0QQdw+R2V2G5sOisFOQpPOFjNAyuQv1YF3vEZJufBOTde8XGUTOq3CbY64ZOODCunNBlq6phXBha1D2Z5Zn3HerrzKuiYqy9le9xSvrP1buUKRkxiNNnO+m6YRxgY7QcyJmtU1UlFl+o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=I+pq1zuu; arc=none smtp.client-ip=209.85.208.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="I+pq1zuu" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-5d41848901bso23602225a12.0 for ; Fri, 03 Jan 2025 06:01:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1735912859; x=1736517659; darn=vger.kernel.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=5qluG0ViCE8ATiodOgOOl8Lv8eXopMgs1l45mWqKjsY=; b=I+pq1zuuau9nyQ6nQUz8NVH2lctcF/cobeGYcUVXMH5KZ2LPxvOj5WsZLbuX6dTkfr ErKG3RQ8whc/OuOusIJrRX3f6IzlBAo6zXAfGQK07foxC1G4VzeGunXjDEFNH1WtMAyu 3LuhoEaOWbbkOLJVxHj27UBtFAqj7z0RsuH11S2UNqWiivYXkqUYdqrUFoBTQUKarSVR BB9pppsbgj8FGYQhpkjSSOtZyMRWwhxHA2bgVdv5IPCDFUqckN6jsNvvmU7PB8883krO fODycMsFCBwwzbyE4KmC9jk8cQaiJKWb4LhrMKzrF8OcipEULCjXF0JEsE0j3Uap88ee XQgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735912859; x=1736517659; 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=5qluG0ViCE8ATiodOgOOl8Lv8eXopMgs1l45mWqKjsY=; b=HDnArvIxgUkkIPgnKN6p7UYg1RwDupdGQekHg2YFreggwDrWGa/f74eOpFeosihWFy fRsFB5IFEnLcDHB00Ziye2q1ocDWFMKJEuy9sg4xBNWRtH/8Ej9VH7H12JUsjSVLJtkr KqZPBxq9XKE8taOaek2L9oHC5U/xKF/3UNyn0iWFoikx4AbEIgPu1FqHuxXbCvHfeksc bpIC7tkwgZjuSlaMmiGH0CbQaXRiS9TAQ+xcu83Sfb40y32HQNofo4ALDxF+mA2Q8moE h1tTP+uVmW6LMdP5fsehutYfJ1uv/x9LXNrOP0ZRH8sfHEF8y8vqbR5hO3lvwoJdFWl3 KTUQ== X-Forwarded-Encrypted: i=1; AJvYcCUYNpPnZFky1YkGOzZz/ZUadwu3oRcLRsjpJPzYmtKLzM/wHqeYPeAOEcb32EQY25UxP1GORYYXwtNvR/I=@vger.kernel.org X-Gm-Message-State: AOJu0YzTIv8oo4JOs61YQF5sOT40vob1aIKqaJUgFTzqwxEtFCe8KPZy B0SU0w9+fQfUrG0bDiQD3ya4uM/OLNXyALa3ZZ1IbDs7hWW8itV2SocdnkqbdIc= X-Gm-Gg: ASbGncsdIkZ8dyWQqZTjTnM9wsSAJp+QzN1e72O5m2m6BmEQ47wyO/PHQIFYTV3/NDu UQ6nUv8Q8VKfqMbrbSPr/ok6RSgCN39oSbFhFVOYLr9X7xZUJLUadnX767Qn5zQj6gRGsUeKPiK QG1u2zCcw5+LHCCW55Vi8p1BTd/vtXCSmHLFfW1ks0aCLINJPy7byk2dZnCGpBwy7cpC9+XIgLs d2CtVdUrKI842vy0BnG6W1IlZidHO0ROAnTJUe/tzHtXFu6SFYvnzbVVyOyrPuU/LyOn5fagY3S JY6pmBzaKaw= X-Google-Smtp-Source: AGHT+IG1Xlx6lYKDq/Jh3aaztieX8SW5bSS3JbGGOUo0jKzSzCn1vGsHxn6qMMerERmHlKGSZGu+PA== X-Received: by 2002:a05:6402:2346:b0:5d8:17da:dcf0 with SMTP id 4fb4d7f45d1cf-5d81e523027mr36220171a12.4.1735912859111; Fri, 03 Jan 2025 06:00:59 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.102]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d80679f0e4sm19502384a12.42.2025.01.03.06.00.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jan 2025 06:00:57 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: prabhakar.mahadev-lad.rj@bp.renesas.com, jic23@kernel.org, lars@metafoo.de, ulf.hansson@linaro.org Cc: linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, claudiu.beznea@tuxon.dev, Claudiu Beznea Subject: [PATCH 2/2] iio: adc: rzg2l: Cleanup suspend/resume path Date: Fri, 3 Jan 2025 16:00:42 +0200 Message-ID: <20250103140042.1619703-3-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250103140042.1619703-1-claudiu.beznea.uj@bp.renesas.com> References: <20250103140042.1619703-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea There is no need to manually track the runtime PM status in the driver. The pm_runtime_force_suspend() and pm_runtime_force_resume() functions already call pm_runtime_status_suspended() to check the runtime PM state. Additionally, avoid calling pm_runtime_put_autosuspend() during the suspend/resume path, as this would decrease the usage counter of a potential user that had the ADC open before the suspend/resume cycle. Fixes: cb164d7c1526 ("iio: adc: rzg2l_adc: Add suspend/resume support") Signed-off-by: Claudiu Beznea --- drivers/iio/adc/rzg2l_adc.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/drivers/iio/adc/rzg2l_adc.c b/drivers/iio/adc/rzg2l_adc.c index f12f3daf08cc..8289b872b165 100644 --- a/drivers/iio/adc/rzg2l_adc.c +++ b/drivers/iio/adc/rzg2l_adc.c @@ -88,7 +88,6 @@ struct rzg2l_adc { struct completion completion; struct mutex lock; u16 last_val[RZG2L_ADC_MAX_CHANNELS]; - bool was_rpm_active; }; =20 /** @@ -563,14 +562,9 @@ static int rzg2l_adc_suspend(struct device *dev) }; int ret; =20 - if (pm_runtime_suspended(dev)) { - adc->was_rpm_active =3D false; - } else { - ret =3D pm_runtime_force_suspend(dev); - if (ret) - return ret; - adc->was_rpm_active =3D true; - } + ret =3D pm_runtime_force_suspend(dev); + if (ret) + return ret; =20 ret =3D reset_control_bulk_assert(ARRAY_SIZE(resets), resets); if (ret) @@ -579,9 +573,7 @@ static int rzg2l_adc_suspend(struct device *dev) return 0; =20 rpm_restore: - if (adc->was_rpm_active) - pm_runtime_force_resume(dev); - + pm_runtime_force_resume(dev); return ret; } =20 @@ -599,11 +591,9 @@ static int rzg2l_adc_resume(struct device *dev) if (ret) return ret; =20 - if (adc->was_rpm_active) { - ret =3D pm_runtime_force_resume(dev); - if (ret) - goto resets_restore; - } + ret =3D pm_runtime_force_resume(dev); + if (ret) + goto resets_restore; =20 ret =3D rzg2l_adc_hw_init(dev, adc); if (ret) @@ -612,10 +602,7 @@ static int rzg2l_adc_resume(struct device *dev) return 0; =20 rpm_restore: - if (adc->was_rpm_active) { - pm_runtime_mark_last_busy(dev); - pm_runtime_put_autosuspend(dev); - } + pm_runtime_force_suspend(dev); resets_restore: reset_control_bulk_assert(ARRAY_SIZE(resets), resets); return ret; --=20 2.43.0