From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f49.google.com (mail-ot1-f49.google.com [209.85.210.49]) (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 AE15B37F001 for ; Mon, 13 Jul 2026 22:01:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783980077; cv=none; b=EyQtpqUeUmD0mdJloh2KERGZUoPnMzLV3axLEGqb8sXf7iS8+2qadVEMH9RROrur1rzyEiZTImFXTSeHPJu/9nq+c4GMmqamaR5SKNPtwcSmBDs/iNP8e1RHST/OJhAgST/2imWO0IMVT6T5gDCJd3Q6F08f5znDJ4927d6ECM4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783980077; c=relaxed/simple; bh=IFjEF5GVRpVgIrAjjlzZ92594mVurMfg8hIoETAVS6U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=f/i58XYB8WfGoDfe6nYjaegFy5fcANT9kC7kMmtdiJY1S9w1r5hV7oSTpFmVigH12lhaV7TCecQWGn13+rgc5KyFPG2I/qshj/+sZhAKmhwMq/ncfkaPFpwVsIq8vUNMY0zDJc6mNq7dlzgui/iuT65oGSX6XQZqpQVSuEtr1z4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=m9WFozbK; arc=none smtp.client-ip=209.85.210.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m9WFozbK" Received: by mail-ot1-f49.google.com with SMTP id 46e09a7af769-7eb5a9f02e8so1856177a34.0 for ; Mon, 13 Jul 2026 15:01:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783980075; x=1784584875; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=LV9Nx9OHn8LspN9c94eHX0WIuVIbVeXxm+nhxzOUshI=; b=m9WFozbKOqAqQydSes65Ki3SQyfFqjURcuhjfAzvA9OiIsM6ml7bRfWA1++3KhksRU njT70vmXAMCfgETeenbvFKfe7OQrawkD7LVqC+BzxnOvg7M9Ob4IKiU3znjscX+YN5KZ IrQ9drBgdhryQDy9gzbkLVPueElPZuYDJsADV1mET1Z2QSHNu7YavtEEI2r93Z3LbTGC O4UDPw2xuRP5VVTRW811+hTXSrtVb7NyqxgttsXlIco8hWve4jlPny/JVMRUAVu4Lsu4 VqR9XK5H8DYYt4b+niBumgyaW5inxetUBx7sUlbc3EKvVQNmCEhUI2BR+eu0m5y35+Qz PXDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783980075; x=1784584875; h=content-transfer-encoding:content-type: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 :content-type; bh=LV9Nx9OHn8LspN9c94eHX0WIuVIbVeXxm+nhxzOUshI=; b=i7y2RtCSyF+gd1OWQggUNjGq9qOQ1R148r5LZdz1EdjPCPZruv0GFdDh7hexj9s1hl /ESIuImSNJKR/Ds6lKag80sA5vtbs5yDBcK1mkeon0owf2Dx1r3sRLcFdBgEn65eVC6s EZwxIAHjkIS+Kd2nfx3ZMZSHeU1THQZp+I9G6hgOlXLccxX4uN7yNx/tGQHb5vAUF9ni gHJPb93XoTBnQ0p6fPw9Ow/YhI4Il9OD0XwjLzFp/JM5XAb+YoxdpCSwwCtsKSIOlmIn 0r6OkqrFgqRrYvQStrvvociQmKHML3aq+En0cKOFY4PEv3J9mAVTSmIk87FCUNoTbcTX nLRQ== X-Gm-Message-State: AOJu0YzkluE5Cya8CQteuKvpdjyRDRrPDYF4LTu0e6ANC2o1zP5SOt2t MpyG737oD9OGDhEgLchFhVztyl23+b2etv6ik5DzDOexAiMfSY1L5RxhSN4djQ== X-Gm-Gg: AfdE7cntIo9GclXyHYN9D1UuYd82fTmY18M5XIHKUQSK72j+znSNb2cU1e357jHhh4f MXRMYy9Y4vKToSxQ0Qo+VdaKWE+7LbJq2a/5Jp516ttsrf37D2+L+pkF62gg0o24TR3VTOA9ru9 cy/UONljfjj+1Cenea6vvkNbDVhIreLtvJ9vAD3oyuOMgWQn1Fg28c+NmpmiLqMl5mdR47Vzqex jA9gEL5PH6o1RMV5pnPv1mNSrPlTQicLKX+54eR8zLzwXux2mN7TeyqoXRU4fOLC3sLBReIkpS7 CTFQNr5jBfCzs6xmWN9/9+JAxzMIdyMYrl62KrBf2UDlQTwOeoGHj07DLdAmBzPFPw1tNjsYzhz ou/U5kaeG9bOIiySEV4C9zsNR8LVvIhTwdPpKcpkwE7i7vJdhiBqCSBcv+wzTNwTVrDwQGYtRS0 77ImEe1RtQps0= X-Received: by 2002:a05:6808:13c8:b0:497:daad:d03 with SMTP id 5614622812f47-4a42af80172mr8446464b6e.36.1783980074491; Mon, 13 Jul 2026 15:01:14 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bc0::54]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4a1acc82f3csm12939785b6e.3.2026.07.13.15.01.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2026 15:01:13 -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 v16 09/10] iio: imu: inv_icm42607: Add Temp Support in icm42607 Date: Mon, 13 Jul 2026 16:58:39 -0500 Message-ID: <20260713215842.69097-10-macroalpha82@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260713215842.69097-1-macroalpha82@gmail.com> References: <20260713215842.69097-1-macroalpha82@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Chris Morgan Add functions for reading temperature sensor data. Signed-off-by: Chris Morgan --- drivers/iio/imu/inv_icm42607/Makefile | 1 + .../iio/imu/inv_icm42607/inv_icm42607_accel.c | 6 ++ .../iio/imu/inv_icm42607/inv_icm42607_gyro.c | 6 ++ .../iio/imu/inv_icm42607/inv_icm42607_temp.c | 98 +++++++++++++++++++ .../iio/imu/inv_icm42607/inv_icm42607_temp.h | 38 +++++++ 5 files changed, 149 insertions(+) create mode 100644 drivers/iio/imu/inv_icm42607/inv_icm42607_temp.c create mode 100644 drivers/iio/imu/inv_icm42607/inv_icm42607_temp.h diff --git a/drivers/iio/imu/inv_icm42607/Makefile b/drivers/iio/imu/inv_icm42607/Makefile index 8e73385c8f4b..7b907e019601 100644 --- a/drivers/iio/imu/inv_icm42607/Makefile +++ b/drivers/iio/imu/inv_icm42607/Makefile @@ -4,6 +4,7 @@ obj-$(CONFIG_INV_ICM42607) += inv-icm42607.o inv-icm42607-y += inv_icm42607_core.o inv-icm42607-y += inv_icm42607_gyro.o inv-icm42607-y += inv_icm42607_accel.o +inv-icm42607-y += inv_icm42607_temp.o obj-$(CONFIG_INV_ICM42607_I2C) += inv-icm42607-i2c.o inv-icm42607-i2c-y += inv_icm42607_i2c.o diff --git a/drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c b/drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c index 7a0c419c0f06..a6cd3aebadaa 100644 --- a/drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c +++ b/drivers/iio/imu/inv_icm42607/inv_icm42607_accel.c @@ -15,6 +15,7 @@ #include #include "inv_icm42607.h" +#include "inv_icm42607_temp.h" #define INV_ICM42607_ACCEL_CHAN(_modifier, _index, _ext_info) \ { \ @@ -40,6 +41,7 @@ enum inv_icm42607_accel_scan { INV_ICM42607_ACCEL_SCAN_X, INV_ICM42607_ACCEL_SCAN_Y, INV_ICM42607_ACCEL_SCAN_Z, + INV_ICM42607_ACCEL_SCAN_TEMP, }; static const struct iio_chan_spec_ext_info inv_icm42607_accel_ext_infos[] = { @@ -54,6 +56,7 @@ static const struct iio_chan_spec inv_icm42607_accel_channels[] = { inv_icm42607_accel_ext_infos), INV_ICM42607_ACCEL_CHAN(IIO_MOD_Z, INV_ICM42607_ACCEL_SCAN_Z, inv_icm42607_accel_ext_infos), + INV_ICM42607_TEMP_CHAN(INV_ICM42607_ACCEL_SCAN_TEMP), }; static const int inv_icm42607_accel_scale_nano[][2] = { @@ -186,6 +189,9 @@ static int inv_icm42607_accel_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: + if (chan->type == IIO_TEMP) + return inv_icm42607_temp_read_raw(indio_dev, chan, + val, val2, mask); ret = inv_icm42607_read_sensor(indio_dev, chan, &data); if (ret) return ret; diff --git a/drivers/iio/imu/inv_icm42607/inv_icm42607_gyro.c b/drivers/iio/imu/inv_icm42607/inv_icm42607_gyro.c index e4b674070ed9..897cdbf987bf 100644 --- a/drivers/iio/imu/inv_icm42607/inv_icm42607_gyro.c +++ b/drivers/iio/imu/inv_icm42607/inv_icm42607_gyro.c @@ -15,6 +15,7 @@ #include #include "inv_icm42607.h" +#include "inv_icm42607_temp.h" #define INV_ICM42607_GYRO_CHAN(_modifier, _index, _ext_info) \ { \ @@ -40,6 +41,7 @@ enum inv_icm42607_gyro_scan { INV_ICM42607_GYRO_SCAN_X, INV_ICM42607_GYRO_SCAN_Y, INV_ICM42607_GYRO_SCAN_Z, + INV_ICM42607_GYRO_SCAN_TEMP, }; static const struct iio_chan_spec_ext_info inv_icm42607_gyro_ext_infos[] = { @@ -54,6 +56,7 @@ static const struct iio_chan_spec inv_icm42607_gyro_channels[] = { inv_icm42607_gyro_ext_infos), INV_ICM42607_GYRO_CHAN(IIO_MOD_Z, INV_ICM42607_GYRO_SCAN_Z, inv_icm42607_gyro_ext_infos), + INV_ICM42607_TEMP_CHAN(INV_ICM42607_GYRO_SCAN_TEMP), }; static const int inv_icm42607_gyro_scale_nano[][2] = { @@ -183,6 +186,9 @@ static int inv_icm42607_gyro_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: + if (chan->type == IIO_TEMP) + return inv_icm42607_temp_read_raw(indio_dev, chan, + val, val2, mask); ret = inv_icm42607_read_sensor(indio_dev, chan, &data); if (ret) return ret; diff --git a/drivers/iio/imu/inv_icm42607/inv_icm42607_temp.c b/drivers/iio/imu/inv_icm42607/inv_icm42607_temp.c new file mode 100644 index 000000000000..8681ef2b49e2 --- /dev/null +++ b/drivers/iio/imu/inv_icm42607/inv_icm42607_temp.c @@ -0,0 +1,98 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2026 InvenSense, Inc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "inv_icm42607.h" +#include "inv_icm42607_temp.h" + +static int inv_icm42607_temp_read(struct inv_icm42607_state *st, s16 *temp) +{ + struct inv_icm42607_sensor_conf conf = INV_ICM42607_SENSOR_CONF_INIT; + struct device *dev = regmap_get_device(st->map); + int ret, gyro_mode, accel_mode; + unsigned int val; + u8 raw[2]; + + PM_RUNTIME_ACQUIRE_AUTOSUSPEND(dev, pm); + ret = PM_RUNTIME_ACQUIRE_ERR(&pm); + if (ret) + return ret; + + guard(mutex)(&st->lock); + + /* + * Check if both the gyro and accel are off and if so, enable one + * of them. The temp sensor cannot be read if both the gyro and + * accel sensor are off. Prefer to enable the accel over the gyro + * as the datasheet says the gyro uses 5x more power and it has + * a minimum run time of 45ms. + */ + ret = regmap_read(st->map, INV_ICM42607_REG_PWR_MGMT0, &val); + if (ret) + return ret; + + accel_mode = FIELD_GET(INV_ICM42607_PWR_MGMT0_ACCEL_MODE_MASK, val); + gyro_mode = FIELD_GET(INV_ICM42607_PWR_MGMT0_GYRO_MODE_MASK, val); + if (!gyro_mode && !accel_mode) { + /* enable accel sensor */ + conf.mode = INV_ICM42607_SENSOR_MODE_LOW_NOISE; + ret = inv_icm42607_set_sensor_conf(st, &conf, IIO_ACCEL); + if (ret) + return ret; + } + + ret = regmap_bulk_read(st->map, INV_ICM42607_REG_TEMP_DATA1, + raw, sizeof(raw)); + if (ret) + return ret; + + *temp = get_unaligned_be16(raw); + if (*temp == INV_ICM42607_DATA_INVALID) + return -EINVAL; + + return 0; +} + +int inv_icm42607_temp_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct inv_icm42607_state *st = iio_device_get_drvdata(indio_dev); + s16 temp; + int ret; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + ret = inv_icm42607_temp_read(st, &temp); + if (ret) + return ret; + *val = temp; + return IIO_VAL_INT; + /* + * T°C = (temp / 128) + 25 + * Tm°C = 1000 * ((temp * 100 / 12800) + 25) + * scale: 100000 / 12800 ~= 7.8125 + * offset: 3200 + */ + case IIO_CHAN_INFO_SCALE: + *val = 7; + *val2 = 812500000; + return IIO_VAL_INT_PLUS_NANO; + case IIO_CHAN_INFO_OFFSET: + *val = 3200; + return IIO_VAL_INT; + default: + return -EINVAL; + } +} diff --git a/drivers/iio/imu/inv_icm42607/inv_icm42607_temp.h b/drivers/iio/imu/inv_icm42607/inv_icm42607_temp.h new file mode 100644 index 000000000000..18499b4d0b94 --- /dev/null +++ b/drivers/iio/imu/inv_icm42607/inv_icm42607_temp.h @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2026 InvenSense, Inc. + */ + +#ifndef INV_ICM42607_TEMP_H_ +#define INV_ICM42607_TEMP_H_ + +#include + +struct iio_dev; +struct iio_chan_spec; + +#define INV_ICM42607_TEMP_CHAN(_index) \ +{ \ + .type = IIO_TEMP, \ + .info_mask_separate = \ + BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_OFFSET) | \ + BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_all = \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .info_mask_shared_by_all_available = \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .scan_index = _index, \ + .scan_type = { \ + .sign = 's', \ + .realbits = 16, \ + .storagebits = 16, \ + .endianness = IIO_BE, \ + }, \ +} + +int inv_icm42607_temp_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask); + +#endif -- 2.43.0