From patchwork Sat Nov 2 13:13:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13860131 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (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 134E818B47B; Sat, 2 Nov 2024 13:13:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730553210; cv=none; b=C5Zy8FUrbSRDYsVsA31wDc0XdkWM0WakKsOtjYhVn/jkfCuUCAVkKVgxkKO/XZjhPSveZS/sWeajLaCz7lQp/47QEPB6TTWpwCi/HoFtMXvonoaP5qRASsw1/NYpa0KHxAvk3PcXHzJ1d0hRzRldkzxSeFC0Cl8yFynj4W/PMcA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730553210; c=relaxed/simple; bh=Ivj3K4QViitvAojGVDS5oG0DyH9SDexyGRYnaxNC38g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D9tVqg0XZGq9lGkSgqObGTsQzO9UXdpjlE0WTkpUN2vKfFe7TjWSFxP1lFltu4e84YUKkUMKjNYs1n8uuYqEkNAHIHun8QeVNG3RstFXX+Hu7SC3duWJs/MxnhngUWZ85xNPLtiw/EcN0oCCFRrqKNRsfMXtcfj627xmAUNfvmo= 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=FA0yDPcU; arc=none smtp.client-ip=209.85.128.51 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="FA0yDPcU" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-43152b79d25so24077575e9.1; Sat, 02 Nov 2024 06:13:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730553206; x=1731158006; 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=nQkyYg38PIPTosx7BKhjuXp+ykRKp2GeAROi5exy52I=; b=FA0yDPcUDy30MCBxAPCZq/VdDxtNpUHR0BZnaGZi9kf3+//pxezXPcJG8aw43zg4N6 8TCsVMlL/WwOlCFOfVxgCF+32Lnwv3lw04LOproRUfY7iwEnlM3RrsmfxMDgEWAQlIRM C3w0H14H03+AFB2xQ2zahyUQ1k1fKWG95HAtXCdIog8fDayPOKKvxSLrJycJNtHaCbWo rbab9hiIJUVtf+K2fyjrClJ69FnxwIjefsgdDYdAU6pl/aiZ52ECMLrMFgaj6FAu/Wka xF1aA46byb+Wl9LCrTch0Igqrd1SepnWIyhESoeAkZ0mZ8D4J8eXH5C/NYkOVEUqOVus TJnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730553206; x=1731158006; 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=nQkyYg38PIPTosx7BKhjuXp+ykRKp2GeAROi5exy52I=; b=nioKgtJ/kZxRp/HvJwuIomx3G4KpbbXrMwbCrGvJlhcvnCFNo7Yk9qu5ucbQ7BN/nC hk7Iz7jaG+HN5fyM08yVjWemU+roqR6VSTpdowUjJfwZoeoPy5IQ/zdGmw++FISRwxP5 OGMQlEuMfo+r4w5rOE++mpvkiIfGwEtWjJWVWlE3lfT92hBNl2QscrZAzx2hiYPMgTUF V3Jf+KhvwXFy37wQMW+yu0TusfRtEuxvgkIB2tNNSTvGtGY/BOhYDaZTlWjRnGnifQcE 2NXl1kDBY/zy5wEGyEhuYX0FeJBzRzA1OL9PXkafdHkIh3X4wLnH2+vTbgkT+Nz3JoJe stfw== X-Forwarded-Encrypted: i=1; AJvYcCUNCyx2G1S5uET0vq6wthLPHs4SBhjQj+CfawTHavXhkVd/lhpGl216pD0+8KjOD9N2qehhZmvwZEB6@vger.kernel.org, AJvYcCUuyq8xSdWuwQpQuXCuKkxdldTM7Q0GPhee6UGW6D8tQpXDShotONrXc7qPJd/6BLu1wVXXEqnnPCleVqib@vger.kernel.org, AJvYcCVyc1vy9hfbgBE3OjeX42ETwQ92lO+/HonsU55dvauRiTWPH2/hoG/Ls2OuAztYDQ3CSy3uMp0sUSbY@vger.kernel.org X-Gm-Message-State: AOJu0YyOOZbkDR4DbIxOADhLPvYG5BMqICmIssSSAzFk3erEQYjxU9do kMe5EjsqE+Pm6NIghyypbKeEcmGfDVtMWIK9Qzl86CrhXqeCcxNxgvWRsxCJ X-Google-Smtp-Source: AGHT+IE7gzmhQd2zPicrOhNTa10EM9/0J1ENm4Nw+5Oy2etWO+kC0CtFrU7HbWQ/nBqwV6KwQu4tIg== X-Received: by 2002:a05:600c:3b91:b0:431:57d2:d7b4 with SMTP id 5b1f17b1804b1-4327b7ea7c6mr96883325e9.26.1730553205713; Sat, 02 Nov 2024 06:13:25 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:b243:5cd3:bfdd:a16e]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-381c113e5cbsm8081570f8f.80.2024.11.02.06.13.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Nov 2024 06:13:25 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andriy.shevchenko@linux.intel.com Cc: vassilisamir@gmail.com, anshulusr@gmail.com, gustavograzs@gmail.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/7] iio: chemical: bme680: refactorize set_mode() mode Date: Sat, 2 Nov 2024 14:13:05 +0100 Message-ID: <20241102131311.36210-2-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241102131311.36210-1-vassilisamir@gmail.com> References: <20241102131311.36210-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Refactorize the set_mode() function to use an external enum that describes the possible modes of the BME680 device instead of using true/false variables for selecting SLEEPING/FORCED mode. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680.h | 2 -- drivers/iio/chemical/bme680_core.c | 31 ++++++++++++++---------------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/drivers/iio/chemical/bme680.h b/drivers/iio/chemical/bme680.h index f5be4516dde7..77136b55e7f6 100644 --- a/drivers/iio/chemical/bme680.h +++ b/drivers/iio/chemical/bme680.h @@ -27,8 +27,6 @@ #define BME680_OSRS_TEMP_MASK GENMASK(7, 5) #define BME680_OSRS_PRESS_MASK GENMASK(4, 2) #define BME680_MODE_MASK GENMASK(1, 0) -#define BME680_MODE_FORCED 1 -#define BME680_MODE_SLEEP 0 #define BME680_REG_CONFIG 0x75 #define BME680_FILTER_MASK GENMASK(4, 2) diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c index 6d11f9188367..5c2c327c4540 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -95,6 +95,12 @@ struct bme680_calib { s8 range_sw_err; }; +/* values of CTRL_MEAS register */ +enum bme680_op_mode { + BME680_MODE_SLEEP = 0, + BME680_MODE_FORCED = 1, +}; + struct bme680_data { struct regmap *regmap; struct bme680_calib bme680; @@ -502,23 +508,16 @@ static u8 bme680_calc_heater_dur(u16 dur) return durval; } -static int bme680_set_mode(struct bme680_data *data, bool mode) +static int bme680_set_mode(struct bme680_data *data, enum bme680_op_mode mode) { struct device *dev = regmap_get_device(data->regmap); int ret; - if (mode) { - ret = regmap_write_bits(data->regmap, BME680_REG_CTRL_MEAS, - BME680_MODE_MASK, BME680_MODE_FORCED); - if (ret < 0) - dev_err(dev, "failed to set forced mode\n"); - - } else { - ret = regmap_write_bits(data->regmap, BME680_REG_CTRL_MEAS, - BME680_MODE_MASK, BME680_MODE_SLEEP); - if (ret < 0) - dev_err(dev, "failed to set sleep mode\n"); - + ret = regmap_write_bits(data->regmap, BME680_REG_CTRL_MEAS, + BME680_MODE_MASK, mode); + if (ret < 0) { + dev_err(dev, "failed to set ctrl_meas register\n"); + return ret; } return ret; @@ -613,8 +612,7 @@ static int bme680_gas_config(struct bme680_data *data) int ret; u8 heatr_res, heatr_dur; - /* Go to sleep */ - ret = bme680_set_mode(data, false); + ret = bme680_set_mode(data, BME680_MODE_SLEEP); if (ret < 0) return ret; @@ -745,8 +743,7 @@ static int bme680_read_raw(struct iio_dev *indio_dev, guard(mutex)(&data->lock); - /* set forced mode to trigger measurement */ - ret = bme680_set_mode(data, true); + ret = bme680_set_mode(data, BME680_MODE_FORCED); if (ret < 0) return ret; From patchwork Sat Nov 2 13:13:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13860133 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.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 361E818BB8B; Sat, 2 Nov 2024 13:13:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730553212; cv=none; b=rde38avE3Q1tv6fLUiRCfkMqtZJVy70f30jAJNAewVtE1tNy6gV3uWTAcm2wOCYRnDGpO7sS8CWbO7aMSDzLj9ub53yqtuDRI1ZxEweqkPWhkaH5VF7OUFreqPK178WgIXcG0LWwV35RQhmc3c1sKiYwiN+DKJfAWp1LbBDKBC4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730553212; c=relaxed/simple; bh=hpZ7s1TKLNsx3yD0VK+9X+2FkS+kR2XEN8EtMR/yUUI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sUdtg3osBWEPp0/wFQZiaXHn8Y4zhAsxsZnfv70dXB7QkcUGj+rWvqyOZQRrWmHUln/dyn1IfOVz2Md7qs8vqUIZWCkoTJWgK3HHZxJGj0zzO99bYM6+gnrZeTIJGA1v+j4DB82wHm8wyvCa++briHmlt0tAtNmcXiHGA6NmQRA= 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=G3kx6gz0; arc=none smtp.client-ip=209.85.221.53 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="G3kx6gz0" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-37d49ffaba6so1878040f8f.0; Sat, 02 Nov 2024 06:13:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730553208; x=1731158008; 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=Bxa5B2WoofuznyY0TJXdMJAjcuehnDgQbKM8qtJik0Y=; b=G3kx6gz0+Zvkn5umPYnMvvkyUjFD4IOW5nNR2w/h15SpleDUkKvntwHzgshpl94pPz 0VIKodarQGWbXClTw/A27MNoD95QGEwma5FWGsDsUnSwqvK/RTsJrD5qy2G+D+ZPVsoQ axddoPNpjVW8qd4I5p8hIJZ3nNbo/xaiV7RIMOLv1FJxGMh0aTvJYq9Zup6dhsht+rSP v5os4XJmUBYJQS0SPMHAFds3WP3IKMVaz+Md6YPdvv6t5GIgA4P0FPqD5fTUPfS6DtCH Przv7TxVmjhMPxSTFH9KhTRtRvNN2W4V2YhqQJ1cdtbkXX3o2LL2P7NuNucuNgIiNMud YJjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730553208; x=1731158008; 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=Bxa5B2WoofuznyY0TJXdMJAjcuehnDgQbKM8qtJik0Y=; b=NWQ+6kBllCuVRvGwYT+QxE7GYKDAPK2j7Ai7bVhisqOu7Zf8TforMwSemjBanJIOTn L1rQMlyoW6VVXjBJgnF45vvhAOKF2EC/jEWjgIbQlYneCf9FO2vb6+1qMmQnZOx1NWil WHbSkA5FIb8dSDa4lhzUOOGW0lI/F+t6mxlXoSgWidciO2SAIE81mD5UEBCz0wcIzYzw wDmIfoQpO4kH9U0vIon0xTS9QNqGwPFj399N/7b54d4iVod71ctk8otDI6+V4FUedf2R me8fTBi87oEo0z9HfaZhxMdkmwku/S4oF3xJ3j3HKm1huP2TCQjgpQ+UQkbze1+Js0OS 6sPQ== X-Forwarded-Encrypted: i=1; AJvYcCU18rEioIKAvtI76nfyP++a+S6+OI7NrKSSd48BteZieKd7Smh67M7N4p71vVfif0USrbrQzhU4yga2pE2r@vger.kernel.org, AJvYcCUB4yyiSxdx9e4xcUDL/IOs3wtREi6pOVMyJM3NM2epSc8d5yXUH/CgV/KEJEvsrhuDRPQxaMZ8LNvr@vger.kernel.org, AJvYcCVf/nZlwc+hllJxvdD4MRpqhKt9Hzo6P1HXse6XnHXLLNYSy1k4oR3ZENnLzWZw0TchJJ/wO6IzvZyN@vger.kernel.org X-Gm-Message-State: AOJu0YwzmpoDiVW0PAH3dsU/ZjhH8LbQeH6uF01xxwn7+WmGkw1P9JN9 TnMI251VpY4sKMn60jWnfIWuqUBpXz16Y247gSDP6ESlb2fZcsPG X-Google-Smtp-Source: AGHT+IEcd2TQHJTCED8JlppR3V8PQ8ys3ru7tBZ+dl/gyO4ZLyyfQ46UadCseH1OZcn9wqZ4uSzTSA== X-Received: by 2002:a5d:4d82:0:b0:371:8319:4dcc with SMTP id ffacd0b85a97d-381b705764fmr10769065f8f.2.1730553206869; Sat, 02 Nov 2024 06:13:26 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:b243:5cd3:bfdd:a16e]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-381c113e5cbsm8081570f8f.80.2024.11.02.06.13.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Nov 2024 06:13:26 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andriy.shevchenko@linux.intel.com Cc: vassilisamir@gmail.com, anshulusr@gmail.com, gustavograzs@gmail.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/7] iio: chemical: bme680: Add SCALE and RAW channels Date: Sat, 2 Nov 2024 14:13:06 +0100 Message-ID: <20241102131311.36210-3-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241102131311.36210-1-vassilisamir@gmail.com> References: <20241102131311.36210-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add SCALE,RAW channels to the device. Even though PROCESSED should be kept for backwards compatibility add comment to avoid using it if the value is not actually reported in IIO values. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680_core.c | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c index 5c2c327c4540..ea1ee9964870 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -144,17 +144,26 @@ EXPORT_SYMBOL_NS(bme680_regmap_config, IIO_BME680); static const struct iio_chan_spec bme680_channels[] = { { .type = IIO_TEMP, + /* PROCESSED maintained for ABI backwards compatibility */ .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), }, { .type = IIO_PRESSURE, + /* PROCESSED maintained for ABI backwards compatibility */ .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), }, { .type = IIO_HUMIDITYRELATIVE, + /* PROCESSED maintained for ABI backwards compatibility */ .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), }, { @@ -787,6 +796,48 @@ static int bme680_read_raw(struct iio_dev *indio_dev, default: return -EINVAL; } + case IIO_CHAN_INFO_RAW: + switch (chan->type) { + case IIO_TEMP: + ret = bme680_read_temp(data, (s16 *)&chan_val); + if (ret) + return ret; + + *val = chan_val; + return IIO_VAL_INT; + case IIO_PRESSURE: + ret = bme680_read_press(data, &chan_val); + if (ret) + return ret; + + *val = chan_val; + return IIO_VAL_INT; + case IIO_HUMIDITYRELATIVE: + ret = bme680_read_humid(data, &chan_val); + if (ret) + return ret; + + *val = chan_val; + return IIO_VAL_INT; + default: + return -EINVAL; + } + case IIO_CHAN_INFO_SCALE: + switch (chan->type) { + case IIO_TEMP: + *val = 10; + return IIO_VAL_INT; + case IIO_PRESSURE: + *val = 1; + *val2 = 1000; + return IIO_VAL_FRACTIONAL; + case IIO_HUMIDITYRELATIVE: + *val = 1; + *val2 = 1000; + return IIO_VAL_FRACTIONAL; + default: + return -EINVAL; + } case IIO_CHAN_INFO_OVERSAMPLING_RATIO: switch (chan->type) { case IIO_TEMP: From patchwork Sat Nov 2 13:13:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13860132 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 CC4F418B497; Sat, 2 Nov 2024 13:13:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730553211; cv=none; b=uU/2GjCicgwJxtcosz80ZXlZ7g5oG+bere6l+27W/te2KbJVcxImswTETCmcZe92IZV52jIfZlgNVadGhR0FkCLZFpCj7gYLa4gSQwNCMDWRbK3XIycjPNITn7tI1X0hRyAWjxtw61N2S3mr7m/7qHoju+sDF2PIXs8HvzRwXz0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730553211; c=relaxed/simple; bh=ZBUPc0dVD2pf/HoEzgKaKn3lWwlNkgbcVveKDHLt+2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M79aivIjEQvMKYw7gkA67dIGRuf9tn9L5D7DaAl9hMKvVKVPSuI6ok/YL88ulq+nZ+uIdJkiErr4V0LKBUk5Ni0Zlm4nrCt9yOFmQTpYM9UAqmxCq3+bkc8CscNGln4zTtN9Kf2e0ktNOkejdsVatk9jsO6MQK0SHh/iTRgnXYc= 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=U3PCiq2X; arc=none smtp.client-ip=209.85.128.50 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="U3PCiq2X" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4315abed18aso22808535e9.2; Sat, 02 Nov 2024 06:13:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730553208; x=1731158008; 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=vttvluHX+R2cAF1FzL6jm9YL5IFUsw8MbaVeOkGyLNI=; b=U3PCiq2XKo+hoqcMhxNt5hHSB5RDEvEdNHZMKb1jfjLugeAxGayC9YaC2gKavMo2iS 25wXcDvWjCL3mMO1M5WIohZAmLmcIihKwL2inj5KmQsd2/b5WISMrt5+IG7szJiNREEj 2CDmqY8bd5Hh7gaxkzEBG4zY9OhJSnV6lNyobQZxcH2PGs+C+IMJgKgehsRcwLmHo9lj XbHv50qFyng8uEkxIuzABUiBF4zCCXkhVF2FtZ3UDSHD+GImdI2VX0Z8umc/l06wM/4V Kh0gUsFmsUqMoTmtED/1m3MlP118MZG9gFzXOW1vbPV3C2xSg8zWVzjZINUi4CNTo2IZ LIkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730553208; x=1731158008; 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=vttvluHX+R2cAF1FzL6jm9YL5IFUsw8MbaVeOkGyLNI=; b=Bkie/xtX8876I7RLdW3XJaZoaw+xBMKthb3RTinZenrfQ+plIG0+uqY6hVW4mJkHEe yu52hS1mpeyUuFD2qfPO8V7uv3TpFDOqJQ7xq3N/t0soS/Qpt0UefdoF8hTYPQUdPJHw +j3VLx56F2RGQTH8Q47tXAMpEs23/LkLcQFrmsg/K1iDjjfYZMMeBJIDUI7GYwr5Mngg 25gEMdq7PZ6/5JzojdYwxVF9QdZ+YdFaqC25vzLNkGAuVbaWSwK9WjZXUppGH/n20vAm qpyeRNRGrhH0cF/Q5n/qL2s8pv6/gvNHKFuiATuN+9bnswCcOkMg85EkYDUSEE5fywTF qSIQ== X-Forwarded-Encrypted: i=1; AJvYcCVoHAogpZJmaopUpXcs8JUVU0TlwZNPiRqnWCVbFqRxCyRJYm3e4hn0kKnLs1bfC2G9mmMUok5P2/8JeSlc@vger.kernel.org, AJvYcCVqOdtVI0NsD8YOVNjJ6qW8AVtXZiBnnKVHHbnvSUA8gjMR/unkPw4j7uMlVzN1b6RBRRDgUQj0LCKT@vger.kernel.org, AJvYcCXTlfVuwlVS6DJ+9/wlOZ22pyzNhQmCK09S6exYQm0hmYcvWXh+2ArJ4kVrR4mt9seSu4aWqsfiGSU/@vger.kernel.org X-Gm-Message-State: AOJu0YzkFgK7GzQ/+KtzeM+7ycfDYA2r+xSBUqDZuZYhJ4PShTqDM3J2 uRIq8FhnJom8FcF1u1lp0sXjftcqFLLHOHQfn+3X6Tq6G9IMZF2j X-Google-Smtp-Source: AGHT+IHAcgCetDeoMMlJSmmFSuFU9vPt/zepxaowJz5oLKkdH2KFiDoNP+eYtecSrEbS29NF8yJGkA== X-Received: by 2002:a05:6000:4185:b0:381:cde6:4ced with SMTP id ffacd0b85a97d-381cde64d44mr2493230f8f.45.1730553207758; Sat, 02 Nov 2024 06:13:27 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:b243:5cd3:bfdd:a16e]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-381c113e5cbsm8081570f8f.80.2024.11.02.06.13.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Nov 2024 06:13:27 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andriy.shevchenko@linux.intel.com Cc: vassilisamir@gmail.com, anshulusr@gmail.com, gustavograzs@gmail.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/7] iio: chemical: bme680: Add triggered buffer support Date: Sat, 2 Nov 2024 14:13:07 +0100 Message-ID: <20241102131311.36210-4-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241102131311.36210-1-vassilisamir@gmail.com> References: <20241102131311.36210-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add triggered buffer and soft timestamp support. The available scan mask enables all the channels of the sensor in order to follow the operation of the sensor. The sensor basically starts to capture from all channels as long as it enters into FORCED mode. The bulk read, reads a total of 15 registers from the sensor, 0x1D..0x2B. Even though some of those registers are not reported in the register map of the device, this is how the BME680 Sensor API [1] proposes to do it. This allows to have one bulk read instead of multiple ones. Link: https://github.com/boschsensortec/BME68x_SensorAPI/blob/v4.4.8/bme68x.c#L1200 Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/Kconfig | 2 + drivers/iio/chemical/bme680.h | 3 + drivers/iio/chemical/bme680_core.c | 137 ++++++++++++++++++++++++++++- 3 files changed, 141 insertions(+), 1 deletion(-) diff --git a/drivers/iio/chemical/Kconfig b/drivers/iio/chemical/Kconfig index 6c87223f58d9..330fe0af946f 100644 --- a/drivers/iio/chemical/Kconfig +++ b/drivers/iio/chemical/Kconfig @@ -50,6 +50,8 @@ config BME680 select REGMAP select BME680_I2C if I2C select BME680_SPI if SPI + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER help Say yes here to build support for Bosch Sensortec BME680 sensor with temperature, pressure, humidity and gas sensing capability. diff --git a/drivers/iio/chemical/bme680.h b/drivers/iio/chemical/bme680.h index 77136b55e7f6..a0a7794543c8 100644 --- a/drivers/iio/chemical/bme680.h +++ b/drivers/iio/chemical/bme680.h @@ -66,6 +66,9 @@ /* Datasheet Section 1.1, Table 1 */ #define BME680_STARTUP_TIME_US 2000 +#define BME680_NUM_CHANNELS 4 +#define BME680_NUM_BULK_READ_REGS 15 + /* Calibration Parameters */ #define BME680_T2_LSB_REG 0x8A #define BME680_H2_MSB_REG 0xE1 diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c index ea1ee9964870..6df87383c243 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -16,8 +16,11 @@ #include #include +#include #include #include +#include +#include #include @@ -101,6 +104,13 @@ enum bme680_op_mode { BME680_MODE_FORCED = 1, }; +enum bme680_scan { + BME680_TEMP, + BME680_PRESS, + BME680_HUMID, + BME680_GAS, +}; + struct bme680_data { struct regmap *regmap; struct bme680_calib bme680; @@ -111,8 +121,13 @@ struct bme680_data { u16 heater_dur; u16 heater_temp; + struct { + s32 chan[4]; + aligned_s64 ts; + } scan; + union { - u8 buf[3]; + u8 buf[BME680_NUM_BULK_READ_REGS]; unsigned int check; __be16 be16; u8 bme680_cal_buf_1[BME680_CALIB_RANGE_1_LEN]; @@ -149,6 +164,13 @@ static const struct iio_chan_spec bme680_channels[] = { BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .scan_index = 0, + .scan_type = { + .sign = 's', + .realbits = 16, + .storagebits = 16, + .endianness = IIO_CPU, + }, }, { .type = IIO_PRESSURE, @@ -157,6 +179,13 @@ static const struct iio_chan_spec bme680_channels[] = { BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .scan_index = 1, + .scan_type = { + .sign = 'u', + .realbits = 32, + .storagebits = 32, + .endianness = IIO_CPU, + }, }, { .type = IIO_HUMIDITYRELATIVE, @@ -165,11 +194,26 @@ static const struct iio_chan_spec bme680_channels[] = { BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .scan_index = 2, + .scan_type = { + .sign = 'u', + .realbits = 32, + .storagebits = 32, + .endianness = IIO_CPU, + }, }, { .type = IIO_RESISTANCE, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), + .scan_index = 3, + .scan_type = { + .sign = 'u', + .realbits = 32, + .storagebits = 32, + .endianness = IIO_CPU, + }, }, + IIO_CHAN_SOFT_TIMESTAMP(4), }; static int bme680_read_calib(struct bme680_data *data, @@ -920,6 +964,88 @@ static const struct iio_info bme680_info = { .attrs = &bme680_attribute_group, }; +static const unsigned long bme680_avail_scan_masks[] = { + BIT(BME680_GAS) | BIT(BME680_HUMID) | BIT(BME680_PRESS) | BIT(BME680_TEMP), + 0 +}; + +static irqreturn_t bme680_trigger_handler(int irq, void *p) +{ + struct iio_poll_func *pf = p; + struct iio_dev *indio_dev = pf->indio_dev; + struct bme680_data *data = iio_priv(indio_dev); + struct device *dev = regmap_get_device(data->regmap); + u32 adc_temp, adc_press, adc_humid; + u16 adc_gas_res, gas_regs_val; + u8 gas_range; + s32 t_fine; + int ret; + + guard(mutex)(&data->lock); + + ret = bme680_set_mode(data, BME680_MODE_FORCED); + if (ret < 0) + goto out; + + ret = bme680_wait_for_eoc(data); + if (ret) + goto out; + + /* Burst read data regs */ + ret = regmap_bulk_read(data->regmap, BME680_REG_MEAS_STAT_0, + data->buf, sizeof(data->buf)); + if (ret) { + dev_err(dev, "failed to burst read sensor data\n"); + goto out; + } + if (data->buf[0] & BME680_GAS_MEAS_BIT) { + dev_err(dev, "gas measurement incomplete\n"); + goto out; + } + + /* Temperature calculations */ + adc_temp = FIELD_GET(BME680_MEAS_TRIM_MASK, get_unaligned_be24(&data->buf[5])); + if (adc_temp == BME680_MEAS_SKIPPED) { + dev_err(dev, "reading temperature skipped\n"); + goto out; + } + data->scan.chan[0] = bme680_compensate_temp(data, adc_temp); + t_fine = bme680_calc_t_fine(data, adc_temp); + + /* Pressure calculations */ + adc_press = FIELD_GET(BME680_MEAS_TRIM_MASK, get_unaligned_be24(&data->buf[2])); + if (adc_press == BME680_MEAS_SKIPPED) { + dev_err(dev, "reading pressure skipped\n"); + goto out; + } + data->scan.chan[1] = bme680_compensate_press(data, adc_press, t_fine); + + /* Humidity calculations */ + adc_humid = get_unaligned_be16(&data->buf[8]); + if (adc_humid == BME680_MEAS_SKIPPED) { + dev_err(dev, "reading humidity skipped\n"); + goto out; + } + data->scan.chan[2] = bme680_compensate_humid(data, adc_humid, t_fine); + + /* Gas calculations */ + gas_regs_val = get_unaligned_be16(&data->buf[13]); + adc_gas_res = FIELD_GET(BME680_ADC_GAS_RES, gas_regs_val); + if ((gas_regs_val & BME680_GAS_STAB_BIT) == 0) { + dev_err(dev, "heater failed to reach the target temperature\n"); + goto out; + } + gas_range = FIELD_GET(BME680_GAS_RANGE_MASK, gas_regs_val); + data->scan.chan[3] = bme680_compensate_gas(data, adc_gas_res, gas_range); + + /* Push to buffer */ + iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, + iio_get_time_ns(indio_dev)); +out: + iio_trigger_notify_done(indio_dev->trig); + return IRQ_HANDLED; +} + int bme680_core_probe(struct device *dev, struct regmap *regmap, const char *name) { @@ -938,6 +1064,7 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap, indio_dev->name = name; indio_dev->channels = bme680_channels; indio_dev->num_channels = ARRAY_SIZE(bme680_channels); + indio_dev->available_scan_masks = bme680_avail_scan_masks; indio_dev->info = &bme680_info; indio_dev->modes = INDIO_DIRECT_MODE; @@ -980,6 +1107,14 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap, return dev_err_probe(dev, ret, "failed to set gas config data\n"); + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, + iio_pollfunc_store_time, + bme680_trigger_handler, + NULL); + if (ret) + return dev_err_probe(dev, ret, + "iio triggered buffer setup failed\n"); + return devm_iio_device_register(dev, indio_dev); } EXPORT_SYMBOL_NS_GPL(bme680_core_probe, IIO_BME680); From patchwork Sat Nov 2 13:13:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13860134 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 8E14118A925; Sat, 2 Nov 2024 13:13:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730553212; cv=none; b=MIPZ3bxchok5xh+4cHgtho6VK/oxRTor+ZvzxopP7bCPiBAvLwBaPcWujUtNqP3Nh4Pu11GkwenwxIaSH+KTv8V0YJpEq89AylwP6ZiqDsBHVtnKIsRCoKSmTE7lpn2tqBLegpIuKyhXMIiCMufuxNlwVTDkhiL4e4zt+ITt3cc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730553212; c=relaxed/simple; bh=7zHkW07VE4G+KlDd97FTSWyFbdEYftQNN9LdHd0WbHQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SDFzYNO/cHejFeHNVzlZJuf2/kXRNRWDSAwyd1iIk65cjda+nv4P0FMW/jCTUusyXwnAAYmU5fFLTElwqZDDKjFQvA0kMu1KMbOzJpDAlFRBX6SFsVpZ4sI0eBJZ9BwwMVTg4xhotXo5QDwCcISZZI6vNKtgGy1rTUohiOzvWuE= 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=NXvGOppR; arc=none smtp.client-ip=209.85.221.41 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="NXvGOppR" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-37d49a7207cso1798224f8f.0; Sat, 02 Nov 2024 06:13:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730553209; x=1731158009; 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=XC8udOzSRteZ7eNrWAXeLvof8SAQ9Jq2fsHq7ONSNCU=; b=NXvGOppRIbD02vfwv0pI48sguV+7VjQ147ceIKgMJLVlX4yMiVrmR8edncqDYNq/MO 5KvsH7221CchvE6H8UxzVBO5lQyEJ/ZCLDL4ZkzxQHMR7J6xrXvnQ++AwKhOq6Xx5BxW fIgbJZuMuTtf2prIGJtz21BF/i86ldOi4MrtFev7wHDRgeNL/rsjP5nQh6ivN3fu0XFe PCILKrEzh+mqfibHT7z3aJgLZWRJUALpMAbpYyUo1WJiLU5R9e0CNUWd9koihLp1O0s1 AT1EYYJDRL8vIiugrhmye2Y/lxQ5sV18zJ8N2XZuu1Um1KehS8LQwJqV0C9lqe/5hTg7 DVgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730553209; x=1731158009; 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=XC8udOzSRteZ7eNrWAXeLvof8SAQ9Jq2fsHq7ONSNCU=; b=eMUirNXp/tt8eyHcvLlRD0bCy1d6DB0EHfIfaqM7DDSSBvtAOK3ty0hdxToiKbZ3u/ +5lAqrvBjOAX7Z3M53mSFiDwSkFn4JqA7Y71XrLFgPsQ6q+R31e0VUl3zhWz+guDCmSV hpudy5o5cH0hAYirXk+1oNF9J6S8TuKZAe/YFC5IQfroyOsCzaKvK+6IVuECwMUMLzSK PMAmDtH6qo1ZOFBwc2E+5xmmt9kDNtRKJLvIkZcBbhXedXFdn7TTQiHG9Zwc1QbB5S6u f8on5EQSzqTOS46MJlmNBjaF03oZ3/FdOtMpmwNA7w//b6uYm7gvxHrJO055aFbDVJi6 /Yiw== X-Forwarded-Encrypted: i=1; AJvYcCUFYe29hARjH7oSsGPMaIDO/lqiGhwkHrwM3m6+QPaLxtWUt5fgI7VKKZ1DFfFaz4fq4RU6VCx+PATp@vger.kernel.org, AJvYcCUfjNX0oZsM34XPpuIQJzuZ2VpM0hqBt8U9V5HPHnZDdqO2/ayYVwYbn0RmkY1GG5gd35KAl8796Rr3x+BT@vger.kernel.org, AJvYcCX+7U46rclF0Fpv0hD6qbZO+iYM8ogkBPoM22E422bxZXw4zV7pklJmdojqTI/ymez/1PJ8ftELLTr5@vger.kernel.org X-Gm-Message-State: AOJu0Yx2eoA+9izWVi8rzlBcfkmv15p8OPfoi7gg6JZVkVz8DMdFSoal MGIrAZGFQfRP/SgwkxcXquICS2uH9BuZgiw4RXciqH2/0cdSrRkytlxjx1zN X-Google-Smtp-Source: AGHT+IGg5RzG/e2A7vGkkYRjDa3UjnErQAyZ/n8CjyCqGhzZGZxbV8U5XBIYqH3smkpvOoAr4aih4w== X-Received: by 2002:a5d:6d0e:0:b0:37c:cc60:2c63 with SMTP id ffacd0b85a97d-381c7a3a23dmr5866217f8f.5.1730553208690; Sat, 02 Nov 2024 06:13:28 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:b243:5cd3:bfdd:a16e]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-381c113e5cbsm8081570f8f.80.2024.11.02.06.13.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Nov 2024 06:13:28 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andriy.shevchenko@linux.intel.com Cc: vassilisamir@gmail.com, anshulusr@gmail.com, gustavograzs@gmail.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 4/7] iio: chemical: bme680: Add support for preheat current Date: Sat, 2 Nov 2024 14:13:08 +0100 Message-ID: <20241102131311.36210-5-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241102131311.36210-1-vassilisamir@gmail.com> References: <20241102131311.36210-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add functionality to inject a specified amount of current to the heating plate before the start of the gas measurement to allow the sensor to reach faster to the requested temperature. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680.h | 1 + drivers/iio/chemical/bme680_core.c | 41 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/drivers/iio/chemical/bme680.h b/drivers/iio/chemical/bme680.h index a0a7794543c8..00ab89b3138b 100644 --- a/drivers/iio/chemical/bme680.h +++ b/drivers/iio/chemical/bme680.h @@ -42,6 +42,7 @@ #define BME680_RHRANGE_MASK GENMASK(5, 4) #define BME680_REG_RES_HEAT_VAL 0x00 #define BME680_RSERROR_MASK GENMASK(7, 4) +#define BME680_REG_IDAC_HEAT_0 0x50 #define BME680_REG_RES_HEAT_0 0x5A #define BME680_REG_GAS_WAIT_0 0x64 #define BME680_ADC_GAS_RES GENMASK(15, 6) diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c index 6df87383c243..6cc1cb9e0477 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -118,6 +118,7 @@ struct bme680_data { u8 oversampling_temp; u8 oversampling_press; u8 oversampling_humid; + u8 preheat_curr_mA; u16 heater_dur; u16 heater_temp; @@ -214,6 +215,12 @@ static const struct iio_chan_spec bme680_channels[] = { }, }, IIO_CHAN_SOFT_TIMESTAMP(4), + { + .type = IIO_CURRENT, + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), + .output = 1, + .scan_index = -1, + }, }; static int bme680_read_calib(struct bme680_data *data, @@ -561,6 +568,12 @@ static u8 bme680_calc_heater_dur(u16 dur) return durval; } +/* Taken from datasheet, section 5.3.3 */ +static u8 bme680_calc_heater_preheat_current(u8 curr) +{ + return 8 * curr - 1; +} + static int bme680_set_mode(struct bme680_data *data, enum bme680_op_mode mode) { struct device *dev = regmap_get_device(data->regmap); @@ -659,6 +672,20 @@ static int bme680_chip_config(struct bme680_data *data) return 0; } +static int bme680_preheat_curr_config(struct bme680_data *data, u8 val) +{ + struct device *dev = regmap_get_device(data->regmap); + u8 heatr_curr; + int ret; + + heatr_curr = bme680_calc_heater_preheat_current(val); + ret = regmap_write(data->regmap, BME680_REG_IDAC_HEAT_0, heatr_curr); + if (ret < 0) + dev_err(dev, "failed to write idac_heat_0 register\n"); + + return ret; +} + static int bme680_gas_config(struct bme680_data *data) { struct device *dev = regmap_get_device(data->regmap); @@ -687,6 +714,10 @@ static int bme680_gas_config(struct bme680_data *data) return ret; } + ret = bme680_preheat_curr_config(data, data->preheat_curr_mA); + if (ret) + return ret; + /* Enable the gas sensor and select heater profile set-point 0 */ ret = regmap_update_bits(data->regmap, BME680_REG_CTRL_GAS_1, BME680_RUN_GAS_MASK | BME680_NB_CONV_MASK, @@ -939,6 +970,15 @@ static int bme680_write_raw(struct iio_dev *indio_dev, return bme680_chip_config(data); } + case IIO_CHAN_INFO_PROCESSED: + { + switch (chan->type) { + case IIO_CURRENT: + return bme680_preheat_curr_config(data, (u8)val); + default: + return -EINVAL; + } + } default: return -EINVAL; } @@ -1074,6 +1114,7 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap, data->oversampling_temp = 8; /* 8X oversampling rate */ data->heater_temp = 320; /* degree Celsius */ data->heater_dur = 150; /* milliseconds */ + data->preheat_curr_mA = 0; ret = regmap_write(regmap, BME680_REG_SOFT_RESET, BME680_CMD_SOFTRESET); if (ret < 0) From patchwork Sat Nov 2 13:13:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13860136 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.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 BBEB219DF4B; Sat, 2 Nov 2024 13:13:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730553215; cv=none; b=brx9whOhRPBPg4+rBcdauh9m+O5GcW2g6ZYXT7o/PAWRqZ46F5SXi3kX0DKHGm97HorrSik7brDNEBlFXTI4MB8YPtkDtvBJgUF90UKAknvoVdGqIZzkDCBs9MeE30awxU3MKYf2auveDyQhMEMpWmrk6bpa6hKXY3TVN88Hch8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730553215; c=relaxed/simple; bh=i0fX1+lyrC4NgLycap4qU/EdlBM9aorbPxUHYhSre4c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ul+FDau9EbNwHr9CHn/goRskRA39V482iYriAa2Ey0fcebs+NgFahilalFT4RxT6m/jrvTG0ntoJdx4+n+dlShIKoaOBp513EsFQCJI/bYDlTKbHy9PGmA32ruel7GggjAOkaEJ8LUgkLcYHh35lyErTtoiscHwgMCAk2QTZRTU= 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=SGn5+iFO; arc=none smtp.client-ip=209.85.221.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="SGn5+iFO" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-37d47b38336so2063004f8f.3; Sat, 02 Nov 2024 06:13:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730553210; x=1731158010; 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=g+XO8GAvfJ1/DzA87LDoicKydO/A50Yh5zO7qiytmXk=; b=SGn5+iFOCe/J/W62VnWbD7GiI6ttB+N+ETw8Xxt/xFszFviXOHlZ4L/KuQJlHBVj+R bAXRvCivzL7uMWS9S9J47SzqYAPra0O9NB+dQUCDECePwmbXAZywcAHclr+L98Z76HZj kqqWD0Bab4x4QUCKHZMBfbsR530lhDiTVx4R+y05KoGm8YZdi1XSchVX67ga/Kh33tSK r/B5uDxIq+QJGCMREKNcMoZsYJCAdN4CQoRzDhHUTapeYcJPdHNf9sNwjPIic2Xdy8Lq 0hhAkTNXtjsk4g7T3YDlQY+Ure5B+dcM5zMfpn2nn+jyyRAbvq3OFGK1ooW3o4TnlCGq lTiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730553210; x=1731158010; 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=g+XO8GAvfJ1/DzA87LDoicKydO/A50Yh5zO7qiytmXk=; b=nyEbrRhpTlhTqiwfOjTaa6MfNKNMK5GUJwdu+9iUnxFcV/c07QhxApnnUM2tEDTMBf 69JHtzA/eQ7EeqBQ7wDCcTiBLBR2/+GELd4tJxjytSQsQqgWQARYaPxt6ijTt0ZBv/43 FiPv/WvB+Hem9FYkS1nCLZaGqom1EU4yjtsRG0IJXVx5GsVIiACLDYoHCXFrpD5JBjTd BttLfd60MbBDFnw5EnsDyBpMwDHKTnIlJ58l/cB3eoyzW+20M1Ni9zmva3qZ6sBJ1dWj 950UcEccBoYk7O2OZ5oNe265MvfEv2/UQpEihxiVclovI4IHWdKb+Kts8cyT4B+Tat42 PwrA== X-Forwarded-Encrypted: i=1; AJvYcCUJ8ViIzEjPd2Mc9uzeITa9RGqk8dWSFsDevlwurVa+vuE6Y2zlR1WDhM+EZLSJpL7N9wYjqWpMG3QSsnEh@vger.kernel.org, AJvYcCVAMOAfy36s4vD+oVJU8SxXDjrvLe3Dnhv9ILPoZHrcVEioCsOZJSZ8TlKC7w6V38rZNbcukMeIQrDH@vger.kernel.org, AJvYcCXdsaqhG9UEjCGcbfUFzB7qC2pfjFJFP6cFgDcHfuyhWsheed2eIwgmJ4/OrzGFl/G+Fc6GaotqlO1Y@vger.kernel.org X-Gm-Message-State: AOJu0YzhtQSeH7EPc/Rh3a7/PHCoIsOAOCmweKpw7Qo7Jdg2yYSlx6BL HzQ5Ifq2ukeJJF6PxXsSyF7uzqur3YoxB8JVuCQBu5xTQgX6v42t X-Google-Smtp-Source: AGHT+IH7Setz+I8lq709NR0+6I/1dZ2krPxiMlgdBIN7IXE/uZkUbAuOFIFMgMlVhFxYgZvVj3eImw== X-Received: by 2002:a5d:4441:0:b0:374:c56e:1d44 with SMTP id ffacd0b85a97d-3806121fdf9mr17496945f8f.48.1730553209897; Sat, 02 Nov 2024 06:13:29 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:b243:5cd3:bfdd:a16e]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-381c113e5cbsm8081570f8f.80.2024.11.02.06.13.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Nov 2024 06:13:29 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andriy.shevchenko@linux.intel.com Cc: vassilisamir@gmail.com, anshulusr@gmail.com, gustavograzs@gmail.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 5/7] dt-bindings: iio: bosch,bme680: Add supply properties Date: Sat, 2 Nov 2024 14:13:09 +0100 Message-ID: <20241102131311.36210-6-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241102131311.36210-1-vassilisamir@gmail.com> References: <20241102131311.36210-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Extend dt-binding for BME680 gas sensor device. The device incorporates as well temperature, pressure and relative humidity sensors. Signed-off-by: Vasileios Amoiridis --- .../bindings/iio/chemical/bosch,bme680.yaml | 62 +++++++++++++++++++ .../devicetree/bindings/trivial-devices.yaml | 2 - 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/chemical/bosch,bme680.yaml diff --git a/Documentation/devicetree/bindings/iio/chemical/bosch,bme680.yaml b/Documentation/devicetree/bindings/iio/chemical/bosch,bme680.yaml new file mode 100644 index 000000000000..0eac22e465e7 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/chemical/bosch,bme680.yaml @@ -0,0 +1,62 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/chemical/bosch,bme680.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Bosch BME680 Gas sensor + +maintainers: + - Vasileios Amoiridis + +description: > + BME680 is a gas sensor which combines relative humidity, barometric pressure, + ambient temperature and gas (VOC - Volatile Organic Compounds) measurements. + + https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bme680-ds001.pdf + +properties: + compatible: + const: bosch,bme680 + + reg: + maxItems: 1 + + vdd-supply: true + vddio-supply: true + +required: + - compatible + - reg + +allOf: + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +unevaluatedProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + bme680@77 { + compatible = "bosch,bme680"; + reg = <0x77>; + vddio-supply = <&vddio>; + vdd-supply = <&vdd>; + }; + }; + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + + bme680@0 { + compatible = "bosch,bme680"; + reg = <0>; + spi-max-frequency = <500000>; + vddio-supply = <&vddio>; + vdd-supply = <&vdd>; + }; + }; diff --git a/Documentation/devicetree/bindings/trivial-devices.yaml b/Documentation/devicetree/bindings/trivial-devices.yaml index 9bf0fb17a05e..b651826e2d21 100644 --- a/Documentation/devicetree/bindings/trivial-devices.yaml +++ b/Documentation/devicetree/bindings/trivial-devices.yaml @@ -55,8 +55,6 @@ properties: - atmel,atsha204a # BPA-RS600: Power Supply - blutek,bpa-rs600 - # Bosch Sensortec pressure, temperature, humididty and VOC sensor - - bosch,bme680 # CM32181: Ambient Light Sensor - capella,cm32181 # CM3232: Ambient Light Sensor From patchwork Sat Nov 2 13:13:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13860135 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (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 A148319D065; Sat, 2 Nov 2024 13:13:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730553214; cv=none; b=UfX1OqDMWK6Mb8HB1kuwBY/1/gsyhqYXnM/7TT8jDmMH5JJaG7Klnw8gm29NxAQvO9ylMnwCSfNCIzqyHAtY8xymqUOcxiG99K4sfl1DaKsTMNiw1pE1aEcDtZOJmUJCZdqeptZaXAQxFTZ5pYpmAi8x88BgpPYXJp1zopSG2Ww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730553214; c=relaxed/simple; bh=KZ7yRqFrxO5vZ6XwJuTZtI8BBPu1nq9S72MpajT8Xds=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GIK14tnbu9yfT1vuDq7SC4AArtsFOhWfCLjPdTj3LjoQcztSP9Aw4MhNeecHxg5X9bHXvOXnfl/5+MS+XBLMp+a2Oe0ETRz/Ztduv555Ntu+nxwo7eBSKN1VUqXaWt9WiOIijKeK+Qhdq3O3KG8ontFPAcXqP1D7rjdHolmVMnY= 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=dCVw3U5o; arc=none smtp.client-ip=209.85.221.42 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="dCVw3U5o" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-37d41894a32so1492747f8f.1; Sat, 02 Nov 2024 06:13:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730553211; x=1731158011; 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=M2Y13fa6Xzzr6xJ4akxb48+KgpVI9Ht9FgRsxSII0Xw=; b=dCVw3U5oj4dZhlJtek+wFh0ACCL2nVP9lgDt9z6oqdjZOmT98C/cCY7eL+k0gipHOn khe0MkjfP6ZawbxLlcB9vMB7lhHDQ6mihe12A/x3luC4aXx9o4xQCtJkv6AkebpxPN+2 NwbK4wKSXXXoZ/ZTnalxkrhLuqSY2bDaf9X2ipc+Gf6P0ImPdT+17DvPvu2YPBO5qs8T D0MndinSrLLIZ+RQse7vguaRSPjvj0Mbt5AQFMwg7niGd6X5nNMusMaXJK+TkUfEsHrF wvkYTW18ReW+ubf/rEsafG/BkZjr4CDEQ/GKit8Wc/H1CCd9ARlRf70Ub+YfPqskAkHI fOjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730553211; x=1731158011; 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=M2Y13fa6Xzzr6xJ4akxb48+KgpVI9Ht9FgRsxSII0Xw=; b=Klh5DHEGviCtpZ8z1J/dZn5a0SuBlcXRt5GGAKbXm3h3Fyul7DPOZ3b8Iz0OmlPnYk LmlK7TiYSM/Tqb3oOhB+AdKJAR/RHitAWCSFbWAdM6hWQ3wKOrlecBt1ZKCWyJE08/ML /IIV5sgEnGcinqF+6UOQZtt6lYg2lMGgxmwS6HKUD3RDUqE4sIIAWva0zCf3JhO8lS7I T9ky7TSurcf4hAvCNtVerdBTTVQblboR+YFTCRDy9KRKhELf/kqVrY9RJLt0ci6XRBbS 8nu5pz9K6No7Lgj4Y1wnzrGpb6TYgLRCXzAZaZli09KV2xgWekF3wMVQFO9diO41dcmx 9FIQ== X-Forwarded-Encrypted: i=1; AJvYcCU9PbT3H52tGIqFI58b+to8oTf36CzRshsOUvsTIhVK7+Zi0riEuWstfaDP/pURBwsdN60Vqc88jlVM@vger.kernel.org, AJvYcCVoiHnf1a21+upryNshZ8nzaRUX4ppUqxe5GuQw+Zgob3BoTuVhotQSd5h96skfrkr8J0ditiUiD4/V@vger.kernel.org, AJvYcCXp+8oVvDNdKVGz7yjl4J+XIX+7+Tg9qrbAMCkjvU1+CP/1VUTWdkJimZyjVkon+s/1JHOCaHgu8AOpSI+C@vger.kernel.org X-Gm-Message-State: AOJu0YxXu6YKVWQqZB0JiazJh3eqpVPLCZ0gTPOj8ZAOd8Xr6fRVntm2 TihHxNGpejxS7lSwh0BrEH+ICdSysSKAY2pB2rq7k1weHeGkLCTR X-Google-Smtp-Source: AGHT+IEHiBbDJyKEk4ts/PQ+bwvyRZE6BE+wTe1MqXo1sV/zE+BTw5GfoCfTpnPkTBR5RMXmn/6OCQ== X-Received: by 2002:a5d:64ed:0:b0:374:c157:a84a with SMTP id ffacd0b85a97d-381c149f462mr7160631f8f.16.1730553211031; Sat, 02 Nov 2024 06:13:31 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:b243:5cd3:bfdd:a16e]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-381c113e5cbsm8081570f8f.80.2024.11.02.06.13.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Nov 2024 06:13:30 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andriy.shevchenko@linux.intel.com Cc: vassilisamir@gmail.com, anshulusr@gmail.com, gustavograzs@gmail.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 6/7] iio: chemical: bme680: add regulators Date: Sat, 2 Nov 2024 14:13:10 +0100 Message-ID: <20241102131311.36210-7-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241102131311.36210-1-vassilisamir@gmail.com> References: <20241102131311.36210-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add support for the regulators described in the dt-binding. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680_core.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c index 6cc1cb9e0477..31769e0df7c2 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -111,6 +112,10 @@ enum bme680_scan { BME680_GAS, }; +static const char *const bme680_supply_names[] = { "vdd", "vddio" }; + +#define BME680_NUM_SUPPLIES ARRAY_SIZE(bme680_supply_names) + struct bme680_data { struct regmap *regmap; struct bme680_calib bme680; @@ -1116,6 +1121,14 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap, data->heater_dur = 150; /* milliseconds */ data->preheat_curr_mA = 0; + ret = devm_regulator_bulk_get_enable(dev, BME680_NUM_SUPPLIES, + bme680_supply_names); + if (ret) + return dev_err_probe(dev, ret, + "failed to get and enable supplies.\n"); + + fsleep(BME680_STARTUP_TIME_US); + ret = regmap_write(regmap, BME680_REG_SOFT_RESET, BME680_CMD_SOFTRESET); if (ret < 0) return dev_err_probe(dev, ret, "Failed to reset chip\n"); From patchwork Sat Nov 2 13:13:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13860137 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (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 D7D281A76D2; Sat, 2 Nov 2024 13:13:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730553217; cv=none; b=T/u/cvG/Vo9rCSSqEqdK4b2fZ8mfBQ89SL2ExZa/4ttRM6XFnBTP3cpGTRhTk/Z6YwpCbRckg3QKcqsUc0WwAyJ82oUPRNAaEbf9csRYac5sfJtEf1Z6FTl7O4luhoOmxaSHEDs+Ydhwx7bpGq31KchT7kap6v82OC3EXhANqPU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730553217; c=relaxed/simple; bh=3uM+WTqtBsg0xw8sisrXt1kS0w4vpxas/UEHkXkdmv4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iH7zy8emM+q52oN4OUPU7whaAK25s/kLKX2wBIHVYa3Ypxsz0JnYwA3RR/HovCPj+iy27hq1VOtv2HmJ8nmOKUekfPFWvx/64G5Sp+7oY8RQNN+nbakOGQVRvaEu7KSXbxuOBl4z3uUUqudQbAW0WWXG+Gsth7j0xfg6bco9g28= 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=kSuEOdNw; arc=none smtp.client-ip=209.85.221.47 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="kSuEOdNw" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-37d5aedd177so1760429f8f.1; Sat, 02 Nov 2024 06:13:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730553212; x=1731158012; 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=SDHI8hy0XPenUBZmXhVO2K57CVRNbJxHW4WA2n3XfjI=; b=kSuEOdNwkg3xsw7RAIUfbe1SkyXgVL+8FF/MNDjdVNggAq+fHQ0CvhhG7fTDDC781V ft2zZmk3Qw7wH1/YMA9PiYNjJLA0XDddHWLxN5fMWD3H9zO8k3wIqYJy83PV5ZOBo3cF 2DSt6vlmJf0JUXhykNcNS0JHo0NPL9WydsDX//Mw4JmcxLvtCbwlOZH9kuZ0TB8QTqiH 7NYx8/PUBegrMZfg1dM3cDRyOH9sGhOdM1/3Io2Patq976jypgeCxB836HSnwxGtIkXw +Ox10RQyVXan6pFpFz1a1BZa6DCi+xqUeCNTfwZ3J2kOjZaeeoEIq9Cx+hBNveu24zi5 AE2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730553212; x=1731158012; 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=SDHI8hy0XPenUBZmXhVO2K57CVRNbJxHW4WA2n3XfjI=; b=I9QngpKUFGU8+9yuRJYeSoOFlbFLZWthIdJ/iWCnkds8bwLgsqTrFfT0OnwNec/A/B Z1UOow9Aan7aUDdZpUirAonLeqnI2n3d+2J9iGpKGAzJpzt03UuqwRpa2CpffxmI6jfp BOFaykWV7N3BrBrclabMj1ugoIYQZH7P5/goSGq9yb6/1vMrB1AcpvpFngEPmww1vjDx tgaiXqkQ+ThU0qUVr9AJa+BDvw6OtUUVvY9fxUZpSa6BWohmLdfe6w+AvfG4bwW3s5zW 7N18tB279PLVaSOoWTY9G/wVls75Y4J0Sr+vsVhRmY34VvNlVmE5M+SyamXtk6mSUJqA hKnA== X-Forwarded-Encrypted: i=1; AJvYcCVuMqboeWVr5NryMbgijgo8k6y87xzWiykh9n9rqaL1GGfcvKJYRSSl9ibt9lrVC3OGXg/KUitqL01tn7lP@vger.kernel.org, AJvYcCW1inn1igZ1hIJ7uLATSHRZd410UanqaUTEWdAypLylGkM6xS/DEclYz4Wn7tlXjq0Xir6nzIMialYY@vger.kernel.org, AJvYcCWw2JDThIaDmzlBjMdyisYCjH1jDR4Hqp0AMy+oqMevbLKDkt2y5NfgsvORS7wIWsq/Lz2YHQ9r/DaD@vger.kernel.org X-Gm-Message-State: AOJu0YzuoSKRSjN8+tCfuACtAr9W1h+lP7rlvcE6F6g0Tx0+PgFIfGMA cSwRRx+xpi6+Xc3ojrd0dMjAkl5wRIjImYBMV5nVm6VbTRKpA7Ry X-Google-Smtp-Source: AGHT+IHInBw6EOfyGKOt2Y7vXqIXSTg7zRjKrOAcNA2fScdV1r1eN3P0K2WiUFiXsmR3YlX53y4v4g== X-Received: by 2002:a05:6000:178a:b0:37c:c5c4:627 with SMTP id ffacd0b85a97d-381be765277mr8898023f8f.5.1730553212000; Sat, 02 Nov 2024 06:13:32 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:b243:5cd3:bfdd:a16e]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-381c113e5cbsm8081570f8f.80.2024.11.02.06.13.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Nov 2024 06:13:31 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andriy.shevchenko@linux.intel.com Cc: vassilisamir@gmail.com, anshulusr@gmail.com, gustavograzs@gmail.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 7/7] iio: chemical: bme680: add power management Date: Sat, 2 Nov 2024 14:13:11 +0100 Message-ID: <20241102131311.36210-8-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241102131311.36210-1-vassilisamir@gmail.com> References: <20241102131311.36210-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add runtime power management to the device. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680.h | 2 + drivers/iio/chemical/bme680_core.c | 104 +++++++++++++++++++++++++++-- drivers/iio/chemical/bme680_i2c.c | 1 + drivers/iio/chemical/bme680_spi.c | 1 + 4 files changed, 101 insertions(+), 7 deletions(-) diff --git a/drivers/iio/chemical/bme680.h b/drivers/iio/chemical/bme680.h index 00ab89b3138b..7d86ed8b02e6 100644 --- a/drivers/iio/chemical/bme680.h +++ b/drivers/iio/chemical/bme680.h @@ -2,6 +2,7 @@ #ifndef BME680_H_ #define BME680_H_ +#include #include #define BME680_REG_CHIP_ID 0xD0 @@ -80,6 +81,7 @@ #define BME680_CALIB_RANGE_3_LEN 5 extern const struct regmap_config bme680_regmap_config; +extern const struct dev_pm_ops bme680_dev_pm_ops; int bme680_core_probe(struct device *dev, struct regmap *regmap, const char *name); diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c index 31769e0df7c2..61d095f1d2f6 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include #include @@ -822,9 +824,9 @@ static int bme680_read_gas(struct bme680_data *data, int *comp_gas_res) return 0; } -static int bme680_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, int *val2, long mask) +static int __bme680_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) { struct bme680_data *data = iio_priv(indio_dev); int chan_val, ret; @@ -937,14 +939,30 @@ static int bme680_read_raw(struct iio_dev *indio_dev, } } +static int bme680_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct bme680_data *data = iio_priv(indio_dev); + struct device *dev = regmap_get_device(data->regmap); + int ret; + + pm_runtime_get_sync(dev); + ret = __bme680_read_raw(indio_dev, chan, val, val2, mask); + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); + + return ret; +} + static bool bme680_is_valid_oversampling(int rate) { return (rate > 0 && rate <= 16 && is_power_of_2(rate)); } -static int bme680_write_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int val, int val2, long mask) +static int __bme680_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) { struct bme680_data *data = iio_priv(indio_dev); @@ -989,6 +1007,22 @@ static int bme680_write_raw(struct iio_dev *indio_dev, } } +static int bme680_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct bme680_data *data = iio_priv(indio_dev); + struct device *dev = regmap_get_device(data->regmap); + int ret; + + pm_runtime_get_sync(dev); + ret = __bme680_write_raw(indio_dev, chan, val, val2, mask); + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); + + return ret; +} + static const char bme680_oversampling_ratio_show[] = "1 2 4 8 16"; static IIO_CONST_ATTR(oversampling_ratio_available, @@ -1091,6 +1125,30 @@ static irqreturn_t bme680_trigger_handler(int irq, void *p) return IRQ_HANDLED; } +static int bme680_buffer_preenable(struct iio_dev *indio_dev) +{ + struct bme680_data *data = iio_priv(indio_dev); + struct device *dev = regmap_get_device(data->regmap); + + pm_runtime_get_sync(dev); + return 0; +} + +static int bme680_buffer_postdisable(struct iio_dev *indio_dev) +{ + struct bme680_data *data = iio_priv(indio_dev); + struct device *dev = regmap_get_device(data->regmap); + + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); + return 0; +} + +static const struct iio_buffer_setup_ops bme680_buffer_setup_ops = { + .preenable = bme680_buffer_preenable, + .postdisable = bme680_buffer_postdisable, +}; + int bme680_core_probe(struct device *dev, struct regmap *regmap, const char *name) { @@ -1164,15 +1222,47 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap, ret = devm_iio_triggered_buffer_setup(dev, indio_dev, iio_pollfunc_store_time, bme680_trigger_handler, - NULL); + &bme680_buffer_setup_ops); if (ret) return dev_err_probe(dev, ret, "iio triggered buffer setup failed\n"); + /* Enable runtime PM */ + pm_runtime_set_autosuspend_delay(dev, BME680_STARTUP_TIME_US); + pm_runtime_use_autosuspend(dev); + pm_runtime_set_active(dev); + ret = devm_pm_runtime_enable(dev); + if (ret) + return ret; + return devm_iio_device_register(dev, indio_dev); } EXPORT_SYMBOL_NS_GPL(bme680_core_probe, IIO_BME680); +static int bme680_runtime_suspend(struct device *dev) +{ + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct bme680_data *data = iio_priv(indio_dev); + + return bme680_set_mode(data, BME680_MODE_SLEEP); +} + +static int bme680_runtime_resume(struct device *dev) +{ + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct bme680_data *data = iio_priv(indio_dev); + int ret; + + ret = bme680_chip_config(data); + if (ret) + return ret; + + return bme680_gas_config(data); +} + +EXPORT_RUNTIME_DEV_PM_OPS(bme680_dev_pm_ops, bme680_runtime_suspend, + bme680_runtime_resume, NULL); + MODULE_AUTHOR("Himanshu Jha "); MODULE_DESCRIPTION("Bosch BME680 Driver"); MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/chemical/bme680_i2c.c b/drivers/iio/chemical/bme680_i2c.c index 7c4224d75955..9998d7fa3e98 100644 --- a/drivers/iio/chemical/bme680_i2c.c +++ b/drivers/iio/chemical/bme680_i2c.c @@ -51,6 +51,7 @@ static struct i2c_driver bme680_i2c_driver = { .driver = { .name = "bme680_i2c", .of_match_table = bme680_of_i2c_match, + .pm = pm_ptr(&bme680_dev_pm_ops), }, .probe = bme680_i2c_probe, .id_table = bme680_i2c_id, diff --git a/drivers/iio/chemical/bme680_spi.c b/drivers/iio/chemical/bme680_spi.c index 7c54bd17d4b0..43d59544d903 100644 --- a/drivers/iio/chemical/bme680_spi.c +++ b/drivers/iio/chemical/bme680_spi.c @@ -154,6 +154,7 @@ static struct spi_driver bme680_spi_driver = { .driver = { .name = "bme680_spi", .of_match_table = bme680_of_spi_match, + .pm = pm_ptr(&bme680_dev_pm_ops), }, .probe = bme680_spi_probe, .id_table = bme680_spi_id,