From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A3BEDCD98CE for ; Wed, 10 Jun 2026 17:57:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=94KgLBlW6IxrmzwrLS1HlXukMNhg9SFn3+wYvh/Cdbo=; b=33hdbMWjWd9jgd Tx/CzS3QVt9Fzu06iaqEyBNGm6zeDX1asIlPY9RluVTJuXdNhXRQBCnbVTfvHRhmstNYXkVOx5HpP upcxsIthJENxwZlV6a0uKih9QHHcVm05qn28UAJ95O0tzXMQufJFnAN70sNzyYEbHEaxz7aJ34MUc WIddMJekzkzU/UIy4Y8oVlI/9tsQcywMt2MpeUO5I8n2dTkyjbGIJrTTw+4zFsXjY0tTG1rBJPc7A mjpdXPVcZuvl/7FzMzTaq0ZEXmG7zwJakByQfK8l/qDnCJy7XWCEvgYmLdsL1rhAPANBHRN7LpKFM LJsVEL3i6tGnApcY9NoQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wXNBF-00000008DMf-1e80; Wed, 10 Jun 2026 17:57:33 +0000 Received: from mail-oa1-x31.google.com ([2001:4860:4864:20::31]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wXNBC-00000008DIq-1XeR for linux-rockchip@lists.infradead.org; Wed, 10 Jun 2026 17:57:31 +0000 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-43cce8288c7so3730205fac.3 for ; Wed, 10 Jun 2026 10:57:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781114249; x=1781719049; darn=lists.infradead.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=CW8Syt234OPRTlLmgS/3iLS5D5+Ulgv06ZIc/zfEuUM=; b=WGqCQSMkQUIY+yCCy03VYSYqdz8/geiFg6MqagOtQL7pieK1oJcqYJdBJTC04/ihcz jv6VN1nrN0lBkcqnq1D205uAPIQqixqN9VEdp6HnNP41lrajRgIxdUa31RnyCRsaM5lt MvzhtfdS/fyFOzuM5H6Mm3BiDGRqGkJ2pkcYA1SzR2qe3CAiR341kCy2Bwayeq+iRxfI KX9EDdqHo4V0vV4/r2hthtzqsu4pUE4wJqN1F0tPCjBCc+ZhbS/liwzyrUWIlOxJwusV KFUfMH8ikyiUMLo5+0rK+ZFFvc9IEJNURxWf3u2S5whH22HY7HpjnruYjTDLbeGIvegz 4Nzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781114249; x=1781719049; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=CW8Syt234OPRTlLmgS/3iLS5D5+Ulgv06ZIc/zfEuUM=; b=jPUPbKlL1HTMp27zfanaga7IMpXz5mY2w22VUtuLnLMgSIfWjFjvrpIzDYVfb56CpB pv3746Nspf7LuoxgcHrZJOSWRrHZ/3934qmYcGP6IAuO+RJ9TFB/M7K1/9F95Re9swJH nswqyvfugm0oM3TNX8q27u0BfCuRirgjr3AQqyA1byBuVhGxbFUAPhEldEOAj+2YDyG9 MfoS0CB0BmSGuImUHn0SGfv5x5ZaECJ3E3V+ccVw9bQm6bYIpe421WUfHh3whmgGvXkF FvGLS+zHhfQoPqtUXSMcbdLEnIuH4giJxEUnSYvkRi5N8xhoipxL5acHKxEtqmqfM5jA 55Cw== X-Forwarded-Encrypted: i=1; AFNElJ8n+ieTWyqEIAOIBdsDwSaVuGnt+4A0mCgohbax0opb2dxQdVoK9AYgxPOyOyVI10UFK3Ath+moolduETzV2A==@lists.infradead.org X-Gm-Message-State: AOJu0Yx+NWHEW4N7F/NBJdxbS6GWz2XPwy5kfD3/kWXQqtSiHShqTab5 Wjjq24ZF1pTwtPGH06YYuClL7/M3IENU9Pjr3SGgDavLNtZ/O0uC4jcLJ3YWuw== X-Gm-Gg: Acq92OFYAfOnJCFAwPkMlfBm6kC1KVCUHy8iM5JBgJ+hz/luXN0znqfdmOkh66RC8A6 i+Me5AZq4A30S77TccjgRjh8pzcogHIYCzQ21Md6YlIsSLgfvySfG6I0a9Ds5CeSI6gixy35Q8i BWxTK1BPXgzl+yKVgrCEqD4b+w01vOTHo7EgY4HPG1U23pW0hMtHzO+MFhSYFZA2roitN51zw3f 06RaOxo7hqaMc/EEodz/UNefeaXrgasAbI0ra0NypSeQdwc+2aDm2h9PvYf447tgY2ed6L2+gzB Np0eushCSBBtvAJ2UBUfdOmB80IjWHT4vLNfZc2rtO1j0jgYeB6esm+bWObSDM51dT4v3AkWvcY m5b5xR/FLC43C08RFS8BIflN2rzRb2ZaN8GHYbTXUqCgpKca4pae/TmrTyHJry5GdR4DQ44LSTC ksSot3jmMORydmnfRA30Edg96zY2fa8txa2DCxKcHaoZ1VEwmWKgAKCAYlSDCHk+vQ X-Received: by 2002:a05:6870:b61f:b0:43d:1d30:7ea6 with SMTP id 586e51a60fabf-4413d32eb67mr15919489fac.2.1781114249085; Wed, 10 Jun 2026 10:57:29 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bc0:b86b:51ed:28ca:695f]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-440d7d4f449sm21180794fac.8.2026.06.10.10.57.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2026 10:57:28 -0700 (PDT) From: Chris Morgan To: linux-iio@vger.kernel.org Cc: andy@kernel.org, nuno.sa@analog.com, dlechner@baylibre.com, jic23@kernel.org, jean-baptiste.maneyrol@tdk.com, linux-rockchip@lists.infradead.org, devicetree@vger.kernel.org, heiko@sntech.de, conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org, andriy.shevchenko@intel.com, Chris Morgan Subject: [PATCH V11 5/9] iio: imu: inv_icm42607: Add PM support for icm42607 Date: Wed, 10 Jun 2026 12:54:49 -0500 Message-ID: <20260610175455.19006-6-macroalpha82@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260610175455.19006-1-macroalpha82@gmail.com> References: <20260610175455.19006-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260610_105730_443020_2A982C93 X-CRM114-Status: GOOD ( 21.32 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org From: Chris Morgan Add power management support for the ICM42607 device driver. Signed-off-by: Chris Morgan --- drivers/iio/imu/inv_icm42607/inv_icm42607.h | 18 +++ .../iio/imu/inv_icm42607/inv_icm42607_core.c | 125 ++++++++++++++++++ .../iio/imu/inv_icm42607/inv_icm42607_i2c.c | 1 + .../iio/imu/inv_icm42607/inv_icm42607_spi.c | 1 + 4 files changed, 145 insertions(+) diff --git a/drivers/iio/imu/inv_icm42607/inv_icm42607.h b/drivers/iio/imu/inv_icm42607/inv_icm42607.h index 743a15fb1b89..1f1397eaa00e 100644 --- a/drivers/iio/imu/inv_icm42607/inv_icm42607.h +++ b/drivers/iio/imu/inv_icm42607/inv_icm42607.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -103,22 +104,32 @@ struct inv_icm42607_hw { const struct inv_icm42607_conf *conf; }; +struct inv_icm42607_suspended { + enum inv_icm42607_sensor_mode gyro; + enum inv_icm42607_sensor_mode accel; + bool temp; +}; + /** * struct inv_icm42607_state - driver state variables * @lock: lock for serializing multiple registers access. * @hw: Hardware specific data. * @map: regmap pointer. * @vddio_supply: I/O voltage regulator for the chip. + * @vddio_en: I/O voltage status for runtime PM. * @orientation: sensor chip orientation relative to main hardware. * @conf: chip sensors configurations. + * @suspended: suspended sensors configuration. */ struct inv_icm42607_state { struct mutex lock; const struct inv_icm42607_hw *hw; struct regmap *map; struct regulator *vddio_supply; + bool vddio_en; struct iio_mount_matrix orientation; struct inv_icm42607_conf conf; + struct inv_icm42607_suspended suspended; }; /* Virtual register addresses: @bank on MSB (4 upper bits), @address on LSB */ @@ -337,11 +348,18 @@ struct inv_icm42607_state { #define INV_ICM42607_GYRO_STARTUP_TIME_MS 30 #define INV_ICM42607_TEMP_STARTUP_TIME_MS 77 +/* + * Suspend delay assumed from other icm42600 series device, not + * documented in datasheet. + */ +#define INV_ICM42607_SUSPEND_DELAY_MS 2000 + typedef int (*inv_icm42607_bus_setup)(struct inv_icm42607_state *); extern const struct regmap_config inv_icm42607_regmap_config; extern const struct inv_icm42607_hw inv_icm42607_hw_data; extern const struct inv_icm42607_hw inv_icm42607p_hw_data; +extern const struct dev_pm_ops inv_icm42607_pm_ops; int inv_icm42607_core_probe(struct regmap *regmap, const struct inv_icm42607_hw *hw, diff --git a/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c b/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c index 26dc09bbeaed..5e1f924a3e34 100644 --- a/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c +++ b/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -71,6 +72,51 @@ const struct inv_icm42607_hw inv_icm42607p_hw_data = { }; EXPORT_SYMBOL_NS_GPL(inv_icm42607p_hw_data, "IIO_ICM42607"); +static int inv_icm42607_set_pwr_mgmt0(struct inv_icm42607_state *st, + enum inv_icm42607_sensor_mode gyro, + enum inv_icm42607_sensor_mode accel, + bool temp, unsigned int *sleep_ms) +{ + enum inv_icm42607_sensor_mode oldgyro = st->conf.gyro.mode; + enum inv_icm42607_sensor_mode oldaccel = st->conf.accel.mode; + bool oldtemp = st->conf.temp_en; + unsigned int sleepval; + unsigned int val; + int ret; + + if (gyro == oldgyro && accel == oldaccel && temp == oldtemp) + return 0; + + val = FIELD_PREP(INV_ICM42607_PWR_MGMT0_GYRO_MODE_MASK, gyro); + val |= FIELD_PREP(INV_ICM42607_PWR_MGMT0_ACCEL_MODE_MASK, accel); + if (!temp) + val |= INV_ICM42607_PWR_MGMT0_ACCEL_LP_CLK_SEL; + ret = regmap_write(st->map, INV_ICM42607_REG_PWR_MGMT0, val); + if (ret) + return ret; + + st->conf.gyro.mode = gyro; + st->conf.accel.mode = accel; + st->conf.temp_en = temp; + + sleepval = 0; + if (temp && !oldtemp) + sleepval = max(sleepval, INV_ICM42607_TEMP_STARTUP_TIME_MS); + + if (accel != oldaccel) + sleepval = max(sleepval, INV_ICM42607_ACCEL_STARTUP_TIME_MS); + + if (gyro != oldgyro) + sleepval = max(sleepval, INV_ICM42607_GYRO_STARTUP_TIME_MS); + + if (sleep_ms) + *sleep_ms = sleepval; + else if (sleepval) + fsleep(sleepval * USEC_PER_MSEC); + + return 0; +} + static int inv_icm42607_set_conf(struct inv_icm42607_state *st, const struct inv_icm42607_conf *conf) { @@ -181,12 +227,17 @@ static int inv_icm42607_enable_vddio_reg(struct inv_icm42607_state *st) { int ret; + if (st->vddio_en) + return 0; + ret = regulator_enable(st->vddio_supply); if (ret) return ret; fsleep(INV_ICM42607_POWER_UP_TIME_US); + st->vddio_en = true; + return 0; } @@ -194,7 +245,12 @@ static void inv_icm42607_disable_vddio_reg(void *_data) { struct inv_icm42607_state *st = _data; + if (!st->vddio_en) + return; + regulator_disable(st->vddio_supply); + + st->vddio_en = false; } int inv_icm42607_core_probe(struct regmap *regmap, @@ -209,6 +265,8 @@ int inv_icm42607_core_probe(struct regmap *regmap, if (!st) return -ENOMEM; + dev_set_drvdata(dev, st); + ret = devm_mutex_init(dev, &st->lock); if (ret) return ret; @@ -244,10 +302,77 @@ int inv_icm42607_core_probe(struct regmap *regmap, if (ret) return ret; + ret = devm_pm_runtime_set_active_enabled(dev); + if (ret) + return ret; + + pm_runtime_set_autosuspend_delay(dev, INV_ICM42607_SUSPEND_DELAY_MS); + pm_runtime_use_autosuspend(dev); + return 0; } EXPORT_SYMBOL_NS_GPL(inv_icm42607_core_probe, "IIO_ICM42607"); +static int inv_icm42607_suspend(struct device *dev) +{ + struct inv_icm42607_state *st = dev_get_drvdata(dev); + int ret; + + ret = pm_runtime_force_suspend(dev); + if (ret) + return ret; + + inv_icm42607_disable_vddio_reg(st); + + return 0; +} + +static int inv_icm42607_resume(struct device *dev) +{ + struct inv_icm42607_state *st = dev_get_drvdata(dev); + int ret; + + ret = inv_icm42607_enable_vddio_reg(st); + if (ret) + return ret; + + return pm_runtime_force_resume(dev); +} + +static int inv_icm42607_runtime_suspend(struct device *dev) +{ + struct inv_icm42607_state *st = dev_get_drvdata(dev); + + guard(mutex)(&st->lock); + + /* save sensors state */ + st->suspended.gyro = st->conf.gyro.mode; + st->suspended.accel = st->conf.accel.mode; + st->suspended.temp = st->conf.temp_en; + + return inv_icm42607_set_pwr_mgmt0(st, INV_ICM42607_SENSOR_MODE_OFF, + INV_ICM42607_SENSOR_MODE_OFF, false, + NULL); +} + +static int inv_icm42607_runtime_resume(struct device *dev) +{ + struct inv_icm42607_state *st = dev_get_drvdata(dev); + + guard(mutex)(&st->lock); + + /* restore sensors state */ + return inv_icm42607_set_pwr_mgmt0(st, st->suspended.gyro, + st->suspended.accel, + st->suspended.temp, NULL); +} + +EXPORT_NS_GPL_DEV_PM_OPS(inv_icm42607_pm_ops, IIO_ICM42607) = { + SYSTEM_SLEEP_PM_OPS(inv_icm42607_suspend, inv_icm42607_resume) + RUNTIME_PM_OPS(inv_icm42607_runtime_suspend, + inv_icm42607_runtime_resume, NULL) +}; + MODULE_AUTHOR("InvenSense, Inc."); MODULE_DESCRIPTION("InvenSense ICM-42607x device driver"); MODULE_LICENSE("GPL"); diff --git a/drivers/iio/imu/inv_icm42607/inv_icm42607_i2c.c b/drivers/iio/imu/inv_icm42607/inv_icm42607_i2c.c index 2946d5465853..0c2ff8e12643 100644 --- a/drivers/iio/imu/inv_icm42607/inv_icm42607_i2c.c +++ b/drivers/iio/imu/inv_icm42607/inv_icm42607_i2c.c @@ -80,6 +80,7 @@ static struct i2c_driver inv_icm42607_driver = { .driver = { .name = "inv-icm42607-i2c", .of_match_table = inv_icm42607_of_matches, + .pm = pm_ptr(&inv_icm42607_pm_ops), }, .id_table = inv_icm42607_id, .probe = inv_icm42607_probe, diff --git a/drivers/iio/imu/inv_icm42607/inv_icm42607_spi.c b/drivers/iio/imu/inv_icm42607/inv_icm42607_spi.c index 3485777ac5b6..1a7f6b0fa86b 100644 --- a/drivers/iio/imu/inv_icm42607/inv_icm42607_spi.c +++ b/drivers/iio/imu/inv_icm42607/inv_icm42607_spi.c @@ -92,6 +92,7 @@ static struct spi_driver inv_icm42607_driver = { .driver = { .name = "inv-icm42607-spi", .of_match_table = inv_icm42607_of_matches, + .pm = pm_ptr(&inv_icm42607_pm_ops), }, .id_table = inv_icm42607_spi_id_table, .probe = inv_icm42607_probe, -- 2.43.0 _______________________________________________ Linux-rockchip mailing list Linux-rockchip@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-rockchip