From nobody Sun Oct 5 05:31:41 2025 Received: from mail-0201.mail-europe.com (mail-0201.mail-europe.com [51.77.79.158]) (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 66BE9285C8D for ; Fri, 8 Aug 2025 15:57:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=51.77.79.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754668681; cv=none; b=Ik81CzHQPJW8QRt2zCpwbZcSlB10d2y8DTQdP6UMgJ5XgBt2bTxTxVmafCeE5KuDkHqOy2KHY+dCgASUMf2qEARHZafyTW0wBW33nhA90GfuDrXq4rQ2rGITAi+P2s+Fp+3jYPMlZvFvO3z+4M39wDi7gQD3BuEHgtEfofkgStE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754668681; c=relaxed/simple; bh=rvt6rM4Vqo/82nMtBHiRIxI6C70kbBNbWpNvi6u01aY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UjHKC4ZKaOsvD9MX1LCnYgTRHOjA77p7zx0zotmitUFMknZdWgIw5ImEmDUbgtAQb8ELyfK95O1ev6gnNuQHBf7ha/aaLVW/siCzj4RLkO1Lnal9Uy/85SwIh3frEQR7CdTlu+H7Q1GpUTHA4LFfpF/1t7k8bzV/pbecpkiRAqo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=geanix.com; spf=pass smtp.mailfrom=geanix.com; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b=RKQPyx6f; arc=none smtp.client-ip=51.77.79.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=geanix.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=geanix.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b="RKQPyx6f" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=geanix.com; s=protonmail; t=1754668668; x=1754927868; bh=NsrBLr1O+psgUK8h5GJ977rYQy+ePA4Gy8v6K3B17og=; h=From:Date:Subject:Message-Id:References:In-Reply-To:To:Cc:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=RKQPyx6ffw3/KYUp2cAvczvyyjTrnjd8W/CmtxhrIg6H8sQp9waW7bfStLftEtOx2 z1IUgU5zwQl/GnlqmB5q2F7qcKpeQW+XYyQTWpqOUmOn2JhK7DyQornRaXhrLxf4Xe /z3RPhtCVrDWJ03DfPngPQD+sOuzKFlEBkX1haWR6uTZkvHd6TFntyZpanosuGeaTi ra6U+hv6z/hxbfeUXLYRaAS8jj1km5mhtjVtEBFvVYOsJpc6jmRQY7koFnlDZaBVmn XdeSPXM8c+ec4HqLeATPuByx7Pj0b6+66NoEI7JjoX74LCUFDppdfZX0FRbFoiqE48 Ewlm3ceFMfmcw== X-Pm-Submission-Id: 4bz7wB4jN3z1DDBp From: Sean Nyekjaer Date: Fri, 08 Aug 2025 17:57:41 +0200 Subject: [PATCH v2 1/5] iio: imu: inv_icm42600: Simplify pm_runtime setup 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: <20250808-icm42pmreg-v2-1-a480279e7721@geanix.com> References: <20250808-icm42pmreg-v2-0-a480279e7721@geanix.com> In-Reply-To: <20250808-icm42pmreg-v2-0-a480279e7721@geanix.com> To: Jean-Baptiste Maneyrol , Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Jean-Baptiste Maneyrol , Jonathan Cameron , Sean Nyekjaer X-Mailer: b4 0.14.2 Rework the power management in inv_icm42600_core_probe() to use devm_pm_runtime_set_active_enabled(), which simplifies the runtime PM setup by handling activation and enabling in one step. Remove the separate inv_icm42600_disable_pm callback, as it's no longer needed with the devm-managed approach. Using devm_pm_runtime_enable() also fixes the missing disable of autosuspend. Update inv_icm42600_disable_vddio_reg() to only disable the regulator if the device is not suspended i.e. powered-down, preventing unbalanced disables. Also remove redundant error msg on regulator_disable(), the regulator framework already emits an error message when regulator_disable() fails. This simplifies the PM setup and avoids manipulating the usage counter unnecessarily. Fixes: 31c24c1e93c3 ("iio: imu: inv_icm42600: add core of new inv_icm42600 = driver") Signed-off-by: Sean Nyekjaer --- drivers/iio/imu/inv_icm42600/inv_icm42600_core.c | 24 ++++++--------------= ---- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c b/drivers/iio= /imu/inv_icm42600/inv_icm42600_core.c index a4d42e7e21807f7954def431e9cf03dffaa5bd5e..c19615750c717101312f358a916= 0dd2c455cfb14 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c @@ -711,20 +711,10 @@ static void inv_icm42600_disable_vdd_reg(void *_data) static void inv_icm42600_disable_vddio_reg(void *_data) { struct inv_icm42600_state *st =3D _data; - const struct device *dev =3D regmap_get_device(st->map); - int ret; - - ret =3D regulator_disable(st->vddio_supply); - if (ret) - dev_err(dev, "failed to disable vddio error %d\n", ret); -} - -static void inv_icm42600_disable_pm(void *_data) -{ - struct device *dev =3D _data; + struct device *dev =3D regmap_get_device(st->map); =20 - pm_runtime_put_sync(dev); - pm_runtime_disable(dev); + if (!pm_runtime_status_suspended(dev)) + regulator_disable(st->vddio_supply); } =20 int inv_icm42600_core_probe(struct regmap *regmap, int chip, @@ -824,16 +814,14 @@ int inv_icm42600_core_probe(struct regmap *regmap, in= t chip, return ret; =20 /* setup runtime power management */ - ret =3D pm_runtime_set_active(dev); + ret =3D devm_pm_runtime_set_active_enabled(dev); if (ret) return ret; - pm_runtime_get_noresume(dev); - pm_runtime_enable(dev); + pm_runtime_set_autosuspend_delay(dev, INV_ICM42600_SUSPEND_DELAY_MS); pm_runtime_use_autosuspend(dev); - pm_runtime_put(dev); =20 - return devm_add_action_or_reset(dev, inv_icm42600_disable_pm, dev); + return ret; } EXPORT_SYMBOL_NS_GPL(inv_icm42600_core_probe, "IIO_ICM42600"); =20 --=20 2.50.1 From nobody Sun Oct 5 05:31:41 2025 Received: from mail-0301.mail-europe.com (mail-0301.mail-europe.com [188.165.51.139]) (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 BA8FD285CBA for ; Fri, 8 Aug 2025 15:58:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=188.165.51.139 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754668682; cv=none; b=en9zJMAG611N3gk/EDkKqCzrgZJ2Xl0m0a+UQ+xaVfhX+lQ5i7LgEEIvunLJcD1gISTsHhiwU/YEejEI56ky2HmZhTu2++v8pKnURO+63RP0buM0p4Jrfb8y8GD4Ibvner+nuQpt7pT92JdDiBVLgTFV567mtejbuQIXa32sdFo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754668682; c=relaxed/simple; bh=bg72bqTzyflyJZv1HaKyzubxfUtGoxOZtzk3iL5qQQw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=G9oSgBmW5eZ6O+dp2Iuww+Knr06jYVa7kPm4MN+cObPv3g6znflTOSnnVDJwz6Etzvb9C6N5U2bWdheOeQ3SgaJ76LNdcspQ19KVpgRT4CKmrYNWl5EiiTWGFn6CeWR4sv65FDSy6flsSAONzZpcIhD1nAymX+67sLzc/c7wTT0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=geanix.com; spf=pass smtp.mailfrom=geanix.com; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b=omSkU17J; arc=none smtp.client-ip=188.165.51.139 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=geanix.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=geanix.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b="omSkU17J" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=geanix.com; s=protonmail; t=1754668670; x=1754927870; bh=pLNiFemUUUSl6LvDv6/uCzyLnyhH5smRs/HatvPcFaU=; h=From:Date:Subject:Message-Id:References:In-Reply-To:To:Cc:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=omSkU17JlKI3KgwwDPzljiRVkU0J4vcBq4aFPAGP4kk18Q0YeNey0xRjUyzp78WJa aVUXk/u6P0NNYM5g5BXZ/F2HYrwrZ/XFb96OCB0vR79dLBO2qY2PC6ufWoks9+FpYw 0X40uSA64TSfYIzVC1pceL16dcM0DDtrZ5/9SrJlgYCfOLqLr2JJvSZCVonkxYJhyX 97n4NEgd/L+yZTkQ4oqzi3lYNVLEKxSm2ZucSIp0SbPMPFV5l6OgTshRh3cWXfx64X mGcav0TcNnWSX839e7HOxX7pvXgmPieqCI83DBMKmjnpIbrFh/JjdzIqI+5WiOMEiU 0Dk69srXig92g== X-Pm-Submission-Id: 4bz7wD1hWYz1DDBr From: Sean Nyekjaer Date: Fri, 08 Aug 2025 17:57:42 +0200 Subject: [PATCH v2 2/5] iio: imu: inv_icm42600: Drop redundant pm_runtime reinitialization in resume 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: <20250808-icm42pmreg-v2-2-a480279e7721@geanix.com> References: <20250808-icm42pmreg-v2-0-a480279e7721@geanix.com> In-Reply-To: <20250808-icm42pmreg-v2-0-a480279e7721@geanix.com> To: Jean-Baptiste Maneyrol , Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Jean-Baptiste Maneyrol , Jonathan Cameron , Sean Nyekjaer X-Mailer: b4 0.14.2 Remove unnecessary calls to pm_runtime_disable(), pm_runtime_set_active(), and pm_runtime_enable() from the resume path. These operations are not required here and can interfere with proper pm_runtime state handling, especially when resuming from a pm_runtime suspended state. Fixes: 31c24c1e93c3 ("iio: imu: inv_icm42600: add core of new inv_icm42600 = driver") Signed-off-by: Sean Nyekjaer --- drivers/iio/imu/inv_icm42600/inv_icm42600_core.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c b/drivers/iio= /imu/inv_icm42600/inv_icm42600_core.c index c19615750c717101312f358a9160dd2c455cfb14..bb0dbbb7ad03bb57ffd3180785a= 686f2cdb5c845 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c @@ -915,10 +915,6 @@ static int inv_icm42600_resume(struct device *dev) goto out_unlock; } =20 - pm_runtime_disable(dev); - pm_runtime_set_active(dev); - pm_runtime_enable(dev); - /* restore sensors state */ ret =3D inv_icm42600_set_pwr_mgmt0(st, st->suspended.gyro, st->suspended.accel, --=20 2.50.1 From nobody Sun Oct 5 05:31:41 2025 Received: from mail-0301.mail-europe.com (mail-0301.mail-europe.com [188.165.51.139]) (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 5F1522868B0 for ; Fri, 8 Aug 2025 15:58:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=188.165.51.139 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754668686; cv=none; b=b71behcFknspvu2buRTzuPGs7ZeahPqd1i+dpkPVave0NUFbenDG8WmMK7y2Ib3aSP59MLXXIowszwUWllib3Ff6ykejRy/bSjEqdd+SFZ++VFJUy6KoaACs/zrj9xQ9ajVkBao5T790bg6tNzfxd8kFBgQb4A26ACn0gjxiW/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754668686; c=relaxed/simple; bh=uYqP9SSVha25TgfnfTcKOUq9hhB9ISoe8o7K384Zaus=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dhj04R8TztozErC9Wcmy970zXfrdSNBzFmVf5C8kCTRia862BNGO3dQk549fP3I9pD8UL5r0LFHpk76teLab87JhzX5Dv63kMvmK7sJJ0nt6miWvCfkkq1sha/gCFExUq8c+R99r0pMhCOtZQvbpL0LPqcosMG3p4omzMP9A8zs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=geanix.com; spf=pass smtp.mailfrom=geanix.com; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b=QK/HRNHS; arc=none smtp.client-ip=188.165.51.139 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=geanix.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=geanix.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b="QK/HRNHS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=geanix.com; s=protonmail; t=1754668673; x=1754927873; bh=2dzssqd2MPlmKUNBjcZT8UxbSJiIXNPn042fkwsXbyw=; h=From:Date:Subject:Message-Id:References:In-Reply-To:To:Cc:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=QK/HRNHSrtJOCLaafumIF/fvpz6xpUkr1c0J5xArbykXjHdFMY5nvwJGZ9E32AeMV 4aT6P0ztgTl/aeno6fsWAOpmlCe4MrVZEqtygmd9Z5Pz48DpsvPM9xPizoEus3lUa3 +Mf/WeplA+UwlJJ2qfXyzFfq9Ys2SFAxPg1ceC0NpgWEMb4yVxfy7xjoeOZ/ECFb1X 3nuGK61Qtxyud85wlyy4sbkNNW7/J/bCQt0u2Su70Z4RmbHwCIAUbO0/BT9249abe7 Cb9Hnm7wm76+HZequk6K0gOeJnkpOm15NhO7pnMMZJp3W9voz/0hnE4hsHkUqlcNtM kqnWUD0p1crCw== X-Pm-Submission-Id: 4bz7wG4xX2z1DDBg From: Sean Nyekjaer Date: Fri, 08 Aug 2025 17:57:43 +0200 Subject: [PATCH v2 3/5] iio: imu: inv_icm42600: Avoid configuring if already pm_runtime suspended 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: <20250808-icm42pmreg-v2-3-a480279e7721@geanix.com> References: <20250808-icm42pmreg-v2-0-a480279e7721@geanix.com> In-Reply-To: <20250808-icm42pmreg-v2-0-a480279e7721@geanix.com> To: Jean-Baptiste Maneyrol , Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Jean-Baptiste Maneyrol , Jonathan Cameron , Sean Nyekjaer X-Mailer: b4 0.14.2 Do as in suspend, skip resume configuration steps if the device is already pm_runtime suspended. This avoids reconfiguring a device that is already in the correct low-power state and ensures that pm_runtime handles the power state transitions properly. Fixes: 31c24c1e93c3 ("iio: imu: inv_icm42600: add core of new inv_icm42600 = driver") Signed-off-by: Sean Nyekjaer --- drivers/iio/imu/inv_icm42600/inv_icm42600_core.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c b/drivers/iio= /imu/inv_icm42600/inv_icm42600_core.c index bb0dbbb7ad03bb57ffd3180785a686f2cdb5c845..39ba94e2e473abe7af64c655f03= 99bd756ddfe11 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c @@ -835,17 +835,15 @@ static int inv_icm42600_suspend(struct device *dev) struct device *accel_dev; bool wakeup; int accel_conf; - int ret; + int ret =3D 0; =20 mutex_lock(&st->lock); =20 st->suspended.gyro =3D st->conf.gyro.mode; st->suspended.accel =3D st->conf.accel.mode; st->suspended.temp =3D st->conf.temp_en; - if (pm_runtime_suspended(dev)) { - ret =3D 0; + if (pm_runtime_suspended(dev)) goto out_unlock; - } =20 /* disable FIFO data streaming */ if (st->fifo.on) { @@ -898,10 +896,13 @@ static int inv_icm42600_resume(struct device *dev) struct inv_icm42600_sensor_state *accel_st =3D iio_priv(st->indio_accel); struct device *accel_dev; bool wakeup; - int ret; + int ret =3D 0; =20 mutex_lock(&st->lock); =20 + if (pm_runtime_suspended(dev)) + goto out_unlock; + /* check wakeup capability */ accel_dev =3D &st->indio_accel->dev; wakeup =3D st->apex.on && device_may_wakeup(accel_dev); --=20 2.50.1 From nobody Sun Oct 5 05:31:41 2025 Received: from mail-0201.mail-europe.com (mail-0201.mail-europe.com [51.77.79.158]) (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 5BAE3286D5E; Fri, 8 Aug 2025 15:58:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=51.77.79.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754668685; cv=none; b=WSdyHhRjiCikXDvneY8m0MwTZNUUVIexKWBwP4uipScu3JcDkPHNuFr8whlrs5D+Fy2Zv5I139tHL9RhoI5Vaz9a8dzUSqj8jB95tNeENLIw7ZD4RJwO/n1DxNepEv62oVhSX5srgLnKAveWTiyZhTgPAZYAfhWdSzRcWmcCsps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754668685; c=relaxed/simple; bh=Nw1uGgXeW4j1JkUEG3B8v+vzkkHUpPSC9zUmgMbsLS4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Fp2R0NecOkFWKcz7JHPsUCXGF2jY1JQNbFKvW/4okTQItMHl34FDuIMYyHbnGjsNfhLKOiv+OShfuyFlHq99zPzcb1B35vKOGGINxlF48PGWSFmi4Ck8UcVBzcr0XwQ4N1f+YJsPcqvkOit2VgGPnlKSxozV3DEdTSY4UmS1bnk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=geanix.com; spf=pass smtp.mailfrom=geanix.com; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b=tD+Lnr9a; arc=none smtp.client-ip=51.77.79.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=geanix.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=geanix.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b="tD+Lnr9a" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=geanix.com; s=protonmail; t=1754668675; x=1754927875; bh=3gIzQL82i1incBkOlRsS99CnvUyVAey9nSxJMAxkUmE=; h=From:Date:Subject:Message-Id:References:In-Reply-To:To:Cc:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=tD+Lnr9a51YR32puwjvntLmyz5ZzWCL1oltCjtk3SoJlVrstpF3cRROT9rEyJVHxZ cDssiOdCNOblQsOXI00TcAyK/2E7DT5T9Re2MKJzZYM1CQ79+0KEdLSRtrMkJoGyNo qI8c+rNuBQZBAS84fH0mgc2prvkcId2A3jc2TQKawGluoWQaTtQvNvyAtOKYplaP6x jKPLVRiOqWiov4qedEeq/Fb45MbjrH9t++5CrA0o58CfQZ105t6VUpIiwbWztvSHgp aAWraELFdYPxXgVIt+8jSKbsGBtJ15oMNgdrIrDgMs9cVdHDS+EjKwybwsxQPWmiP4 5MQ+C/iBj6+dg== X-Pm-Submission-Id: 4bz7wK2lFQz1DDBv From: Sean Nyekjaer Date: Fri, 08 Aug 2025 17:57:44 +0200 Subject: [PATCH v2 4/5] iio: imu: inv_icm42600: Use devm_regulator_get_enable() for vdd regulator 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: <20250808-icm42pmreg-v2-4-a480279e7721@geanix.com> References: <20250808-icm42pmreg-v2-0-a480279e7721@geanix.com> In-Reply-To: <20250808-icm42pmreg-v2-0-a480279e7721@geanix.com> To: Jean-Baptiste Maneyrol , Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Jean-Baptiste Maneyrol , Jonathan Cameron , Sean Nyekjaer X-Mailer: b4 0.14.2 The vdd regulator is not used for runtime power management, so it does not need explicit enable/disable handling. Use devm_regulator_get_enable() to let the regulator be managed automatically by devm. This simplifies the code by removing the manual enable and cleanup logic. Signed-off-by: Sean Nyekjaer --- drivers/iio/imu/inv_icm42600/inv_icm42600.h | 1 - drivers/iio/imu/inv_icm42600/inv_icm42600_core.c | 29 +++++---------------= ---- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600.h b/drivers/iio/imu/= inv_icm42600/inv_icm42600.h index 1430ab4f1dea5d5ba6277d74275fc44a6cd30eb8..c8b48a5c5ed0677bb35201d3293= 4936faaf7a1a6 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600.h +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600.h @@ -167,7 +167,6 @@ struct inv_icm42600_state { enum inv_icm42600_chip chip; const char *name; struct regmap *map; - struct regulator *vdd_supply; struct regulator *vddio_supply; int irq; struct iio_mount_matrix orientation; diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c b/drivers/iio= /imu/inv_icm42600/inv_icm42600_core.c index 39ba94e2e473abe7af64c655f0399bd756ddfe11..52f61e90fec3e08effc1d398293= bece5413406d1 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c @@ -697,17 +697,6 @@ static int inv_icm42600_enable_regulator_vddio(struct = inv_icm42600_state *st) return 0; } =20 -static void inv_icm42600_disable_vdd_reg(void *_data) -{ - struct inv_icm42600_state *st =3D _data; - const struct device *dev =3D regmap_get_device(st->map); - int ret; - - ret =3D regulator_disable(st->vdd_supply); - if (ret) - dev_err(dev, "failed to disable vdd error %d\n", ret); -} - static void inv_icm42600_disable_vddio_reg(void *_data) { struct inv_icm42600_state *st =3D _data; @@ -763,23 +752,17 @@ int inv_icm42600_core_probe(struct regmap *regmap, in= t chip, return ret; } =20 - st->vdd_supply =3D devm_regulator_get(dev, "vdd"); - if (IS_ERR(st->vdd_supply)) - return PTR_ERR(st->vdd_supply); + ret =3D devm_regulator_get_enable(dev, "vdd"); + if (ret) + return dev_err_probe(dev, ret, + "Failed to get vdd regulator\n"); + + msleep(INV_ICM42600_POWER_UP_TIME_MS); =20 st->vddio_supply =3D devm_regulator_get(dev, "vddio"); if (IS_ERR(st->vddio_supply)) return PTR_ERR(st->vddio_supply); =20 - ret =3D regulator_enable(st->vdd_supply); - if (ret) - return ret; - msleep(INV_ICM42600_POWER_UP_TIME_MS); - - ret =3D devm_add_action_or_reset(dev, inv_icm42600_disable_vdd_reg, st); - if (ret) - return ret; - ret =3D inv_icm42600_enable_regulator_vddio(st); if (ret) return ret; --=20 2.50.1 From nobody Sun Oct 5 05:31:41 2025 Received: from mail-06.mail-europe.com (mail-06.mail-europe.com [85.9.210.45]) (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 428C1287247 for ; Fri, 8 Aug 2025 15:58:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=85.9.210.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754668689; cv=none; b=T5BDZwnebciwXGq/6iOR0QQR8H4wvgWXYOHUj8G/heU2RvI/Vk8Zyw4yj5VxMjNuTtOMUDwQ0hBE8wKGMSmM165uQbi7PbiR2NPNeFusWg1xAnma+eNZAwWNeK5bokRwlVHQboPM6cQ5ZUNE6+ILzlUopnOR86rlpAk7VWeB7oI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754668689; c=relaxed/simple; bh=VlR1RGNnD4IEMBjMzMVabP+MObfwMXuyj/dNymvqJls=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=isNntfjhyQMrS74rfPlHMzuI1G1rNwXciI5Fr2MITThp0SNMSGqkYCwHnFMgRAiyDgMzVy1d56nepSm1B0RqT7NC+e8HLIpC2PJ2yu9LME60Y8fFnf8SXG6gam2XHtysNPd9BmgsUuirxBvPTfGBDLsb06GvZEHeW3lGqX3VU5w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=geanix.com; spf=pass smtp.mailfrom=geanix.com; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b=tKt5Ef9I; arc=none smtp.client-ip=85.9.210.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=geanix.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=geanix.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b="tKt5Ef9I" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=geanix.com; s=protonmail; t=1754668677; x=1754927877; bh=JJ31uYs28q0YM2qlOujyLMfEI3sbvQ5uz3Sp7TuvQp0=; h=From:Date:Subject:Message-Id:References:In-Reply-To:To:Cc:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=tKt5Ef9IE5SmXUmimx73uK73RAyNNXcebVk6gYiqUj2VQ1wif4dj7UUAX9cbBymmJ ZNe5TJfNKkpwO+YVeyJSc/xbDJx4n1gzo5XPm6JFd4mjShNxMHKS+J1qTuGIpXviea Tz/v9uuwGz0srkVmYpcXR9xtuKRuon1/6Sc1Ec9DfyjrHPt1RjPbs3W4BZzCDV1GIR RaTV7U1XlVQMvcQnrickC6jWZD6X/0bqbqI5ybMOhs6I3IQ1UyXkN+6t8bxHWVRteI IBEhT71Lg7SYkt/5iAEkwp8VEROJEtMYcnMpacbhWyQuDsN1o+fbJhC0BAq7orXQQP Owwaf531JSmHg== X-Pm-Submission-Id: 4bz7wM16Zpz1DDBr From: Sean Nyekjaer Date: Fri, 08 Aug 2025 17:57:45 +0200 Subject: [PATCH v2 5/5] iio: imu: inv_icm42600: use guard() to release mutexes 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: <20250808-icm42pmreg-v2-5-a480279e7721@geanix.com> References: <20250808-icm42pmreg-v2-0-a480279e7721@geanix.com> In-Reply-To: <20250808-icm42pmreg-v2-0-a480279e7721@geanix.com> To: Jean-Baptiste Maneyrol , Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Jean-Baptiste Maneyrol , Jonathan Cameron , Sean Nyekjaer X-Mailer: b4 0.14.2 Replace explicit mutex_lock() and mutex_unlock() with the guard() macro for cleaner and safer mutex handling. Signed-off-by: Sean Nyekjaer --- drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c | 11 ++---- drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c | 27 ++++++-------- drivers/iio/imu/inv_icm42600/inv_icm42600_core.c | 43 +++++++++---------= ---- drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c | 11 ++---- 4 files changed, 36 insertions(+), 56 deletions(-) diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c b/drivers/ii= o/imu/inv_icm42600/inv_icm42600_accel.c index 7a28051330b79098bfa94b8c8c78c2bce20b7230..1e58253b3ddc0028d0899ec04ca= bbc65c6bf2b72 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c @@ -562,11 +562,10 @@ static int inv_icm42600_accel_write_scale(struct iio_= dev *indio_dev, conf.fs =3D idx / 2; =20 pm_runtime_get_sync(dev); - mutex_lock(&st->lock); + guard(mutex)(&st->lock); =20 ret =3D inv_icm42600_set_accel_conf(st, &conf, NULL); =20 - mutex_unlock(&st->lock); pm_runtime_mark_last_busy(dev); pm_runtime_put_autosuspend(dev); =20 @@ -993,13 +992,11 @@ static int inv_icm42600_accel_hwfifo_set_watermark(st= ruct iio_dev *indio_dev, struct inv_icm42600_state *st =3D iio_device_get_drvdata(indio_dev); int ret; =20 - mutex_lock(&st->lock); + guard(mutex)(&st->lock); =20 st->fifo.watermark.accel =3D val; ret =3D inv_icm42600_buffer_update_watermark(st); =20 - mutex_unlock(&st->lock); - return ret; } =20 @@ -1012,14 +1009,12 @@ static int inv_icm42600_accel_hwfifo_flush(struct i= io_dev *indio_dev, if (count =3D=3D 0) return 0; =20 - mutex_lock(&st->lock); + guard(mutex)(&st->lock); =20 ret =3D inv_icm42600_buffer_hwfifo_flush(st, count); if (!ret) ret =3D st->fifo.nb.accel; =20 - mutex_unlock(&st->lock); - return ret; } =20 diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c b/drivers/i= io/imu/inv_icm42600/inv_icm42600_buffer.c index 7c4ed981db043b4e8f3967b0802655d34f863954..d052b7069dc5c99dfea634415c1= 07e188994c995 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c @@ -292,9 +292,8 @@ static int inv_icm42600_buffer_preenable(struct iio_dev= *indio_dev) =20 pm_runtime_get_sync(dev); =20 - mutex_lock(&st->lock); + guard(mutex)(&st->lock); inv_sensors_timestamp_reset(ts); - mutex_unlock(&st->lock); =20 return 0; } @@ -308,7 +307,7 @@ static int inv_icm42600_buffer_postenable(struct iio_de= v *indio_dev) struct inv_icm42600_state *st =3D iio_device_get_drvdata(indio_dev); int ret; =20 - mutex_lock(&st->lock); + guard(mutex)(&st->lock); =20 /* exit if FIFO is already on */ if (st->fifo.on) { @@ -320,30 +319,29 @@ static int inv_icm42600_buffer_postenable(struct iio_= dev *indio_dev) ret =3D regmap_set_bits(st->map, INV_ICM42600_REG_INT_SOURCE0, INV_ICM42600_INT_SOURCE0_FIFO_THS_INT1_EN); if (ret) - goto out_unlock; + return ret; =20 /* flush FIFO data */ ret =3D regmap_write(st->map, INV_ICM42600_REG_SIGNAL_PATH_RESET, INV_ICM42600_SIGNAL_PATH_RESET_FIFO_FLUSH); if (ret) - goto out_unlock; + return ret; =20 /* set FIFO in streaming mode */ ret =3D regmap_write(st->map, INV_ICM42600_REG_FIFO_CONFIG, INV_ICM42600_FIFO_CONFIG_STREAM); if (ret) - goto out_unlock; + return ret; =20 /* workaround: first read of FIFO count after reset is always 0 */ ret =3D regmap_bulk_read(st->map, INV_ICM42600_REG_FIFO_COUNT, st->buffer= , 2); if (ret) - goto out_unlock; + return ret; =20 out_on: /* increase FIFO on counter */ st->fifo.on++; -out_unlock: - mutex_unlock(&st->lock); + return ret; } =20 @@ -352,7 +350,7 @@ static int inv_icm42600_buffer_predisable(struct iio_de= v *indio_dev) struct inv_icm42600_state *st =3D iio_device_get_drvdata(indio_dev); int ret; =20 - mutex_lock(&st->lock); + guard(mutex)(&st->lock); =20 /* exit if there are several sensors using the FIFO */ if (st->fifo.on > 1) { @@ -364,25 +362,24 @@ static int inv_icm42600_buffer_predisable(struct iio_= dev *indio_dev) ret =3D regmap_write(st->map, INV_ICM42600_REG_FIFO_CONFIG, INV_ICM42600_FIFO_CONFIG_BYPASS); if (ret) - goto out_unlock; + return ret; =20 /* flush FIFO data */ ret =3D regmap_write(st->map, INV_ICM42600_REG_SIGNAL_PATH_RESET, INV_ICM42600_SIGNAL_PATH_RESET_FIFO_FLUSH); if (ret) - goto out_unlock; + return ret; =20 /* disable FIFO threshold interrupt */ ret =3D regmap_clear_bits(st->map, INV_ICM42600_REG_INT_SOURCE0, INV_ICM42600_INT_SOURCE0_FIFO_THS_INT1_EN); if (ret) - goto out_unlock; + return ret; =20 out_off: /* decrease FIFO on counter */ st->fifo.on--; -out_unlock: - mutex_unlock(&st->lock); + return ret; } =20 diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c b/drivers/iio= /imu/inv_icm42600/inv_icm42600_core.c index 52f61e90fec3e08effc1d398293bece5413406d1..82e6c8b3fba5b63d4eebb0a68bd= 88b950dbe881d 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c @@ -441,15 +441,13 @@ int inv_icm42600_debugfs_reg(struct iio_dev *indio_de= v, unsigned int reg, struct inv_icm42600_state *st =3D iio_device_get_drvdata(indio_dev); int ret; =20 - mutex_lock(&st->lock); + guard(mutex)(&st->lock); =20 if (readval) ret =3D regmap_read(st->map, reg, readval); else ret =3D regmap_write(st->map, reg, writeval); =20 - mutex_unlock(&st->lock); - return ret; } =20 @@ -820,20 +818,21 @@ static int inv_icm42600_suspend(struct device *dev) int accel_conf; int ret =3D 0; =20 - mutex_lock(&st->lock); + guard(mutex)(&st->lock); =20 st->suspended.gyro =3D st->conf.gyro.mode; st->suspended.accel =3D st->conf.accel.mode; st->suspended.temp =3D st->conf.temp_en; - if (pm_runtime_suspended(dev)) - goto out_unlock; + ret =3D pm_runtime_suspended(dev); + if (ret) + return ret; =20 /* disable FIFO data streaming */ if (st->fifo.on) { ret =3D regmap_write(st->map, INV_ICM42600_REG_FIFO_CONFIG, INV_ICM42600_FIFO_CONFIG_BYPASS); if (ret) - goto out_unlock; + return ret; } =20 /* keep chip on and wake-up capable if APEX and wakeup on */ @@ -849,7 +848,7 @@ static int inv_icm42600_suspend(struct device *dev) if (st->apex.wom.enable) { ret =3D inv_icm42600_disable_wom(st); if (ret) - goto out_unlock; + return ret; } accel_conf =3D INV_ICM42600_SENSOR_MODE_OFF; } @@ -857,14 +856,12 @@ static int inv_icm42600_suspend(struct device *dev) ret =3D inv_icm42600_set_pwr_mgmt0(st, INV_ICM42600_SENSOR_MODE_OFF, accel_conf, false, NULL); if (ret) - goto out_unlock; + return ret; =20 /* disable vddio regulator if chip is sleeping */ if (!wakeup) regulator_disable(st->vddio_supply); =20 -out_unlock: - mutex_unlock(&st->lock); return ret; } =20 @@ -881,10 +878,11 @@ static int inv_icm42600_resume(struct device *dev) bool wakeup; int ret =3D 0; =20 - mutex_lock(&st->lock); + guard(mutex)(&st->lock); =20 - if (pm_runtime_suspended(dev)) - goto out_unlock; + ret =3D pm_runtime_suspended(dev); + if (ret) + return ret; =20 /* check wakeup capability */ accel_dev =3D &st->indio_accel->dev; @@ -896,7 +894,7 @@ static int inv_icm42600_resume(struct device *dev) } else { ret =3D inv_icm42600_enable_regulator_vddio(st); if (ret) - goto out_unlock; + return ret; } =20 /* restore sensors state */ @@ -904,13 +902,13 @@ static int inv_icm42600_resume(struct device *dev) st->suspended.accel, st->suspended.temp, NULL); if (ret) - goto out_unlock; + return ret; =20 /* restore APEX features if disabled */ if (!wakeup && st->apex.wom.enable) { ret =3D inv_icm42600_enable_wom(st); if (ret) - goto out_unlock; + return ret; } =20 /* restore FIFO data streaming */ @@ -921,8 +919,6 @@ static int inv_icm42600_resume(struct device *dev) INV_ICM42600_FIFO_CONFIG_STREAM); } =20 -out_unlock: - mutex_unlock(&st->lock); return ret; } =20 @@ -932,19 +928,17 @@ static int inv_icm42600_runtime_suspend(struct device= *dev) struct inv_icm42600_state *st =3D dev_get_drvdata(dev); int ret; =20 - mutex_lock(&st->lock); + guard(mutex)(&st->lock); =20 /* disable all sensors */ ret =3D inv_icm42600_set_pwr_mgmt0(st, INV_ICM42600_SENSOR_MODE_OFF, INV_ICM42600_SENSOR_MODE_OFF, false, NULL); if (ret) - goto error_unlock; + return ret; =20 regulator_disable(st->vddio_supply); =20 -error_unlock: - mutex_unlock(&st->lock); return ret; } =20 @@ -954,11 +948,10 @@ static int inv_icm42600_runtime_resume(struct device = *dev) struct inv_icm42600_state *st =3D dev_get_drvdata(dev); int ret; =20 - mutex_lock(&st->lock); + guard(mutex)(&st->lock); =20 ret =3D inv_icm42600_enable_regulator_vddio(st); =20 - mutex_unlock(&st->lock); return ret; } =20 diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c b/drivers/iio= /imu/inv_icm42600/inv_icm42600_gyro.c index 9ba6f13628e6af5e19d047476ae93754f07aa95f..875e48748d70678bcd3963187be= 6de8c5a2b2fcc 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c @@ -278,11 +278,10 @@ static int inv_icm42600_gyro_write_scale(struct iio_d= ev *indio_dev, conf.fs =3D idx / 2; =20 pm_runtime_get_sync(dev); - mutex_lock(&st->lock); + guard(mutex)(&st->lock); =20 ret =3D inv_icm42600_set_gyro_conf(st, &conf, NULL); =20 - mutex_unlock(&st->lock); pm_runtime_mark_last_busy(dev); pm_runtime_put_autosuspend(dev); =20 @@ -695,13 +694,11 @@ static int inv_icm42600_gyro_hwfifo_set_watermark(str= uct iio_dev *indio_dev, struct inv_icm42600_state *st =3D iio_device_get_drvdata(indio_dev); int ret; =20 - mutex_lock(&st->lock); + guard(mutex)(&st->lock); =20 st->fifo.watermark.gyro =3D val; ret =3D inv_icm42600_buffer_update_watermark(st); =20 - mutex_unlock(&st->lock); - return ret; } =20 @@ -714,14 +711,12 @@ static int inv_icm42600_gyro_hwfifo_flush(struct iio_= dev *indio_dev, if (count =3D=3D 0) return 0; =20 - mutex_lock(&st->lock); + guard(mutex)(&st->lock); =20 ret =3D inv_icm42600_buffer_hwfifo_flush(st, count); if (!ret) ret =3D st->fifo.nb.gyro; =20 - mutex_unlock(&st->lock); - return ret; } =20 --=20 2.50.1