From patchwork Mon Oct 21 19:53:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13844585 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.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 9822D1C9B82; Mon, 21 Oct 2024 19:53:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540406; cv=none; b=InHHbZnAlFdHjFQFqZ0U1lq5ep5rLJpqe45ItwVBpPn/mA+aE6motaaD4fzmP6o83BSEWXLtNsqldpERET6jHy8Kw4JWQmE8L4gDtc2jo0NyAESsDO/n9HCqbVgGSafAGVinX8R/x5bmEFKrfKDFDCLDkS0gjQbOLSE8hBWYi4U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540406; c=relaxed/simple; bh=OMe0uxbezRu1rkrj9/nozDm5exgPB0MM40eLMyJkIvU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cDrWpIR2p7aUPbQVZh7DTF6uac3+raCIFNHyL81+m9TRcHP3CnKPYUY2EhqijI5ZmbCLqqwyxkLdVryqv0nxcqEMjzuZdY3xCX9i+zS0dpuHKM1RyHwHSeSLRxCYHHgdfK71htPVNwHbjCWeLwz+Uio7YASHzCf20nwedqi+Sc4= 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=A761phUr; arc=none smtp.client-ip=209.85.208.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="A761phUr" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5cb6b2b7127so790268a12.1; Mon, 21 Oct 2024 12:53:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729540403; x=1730145203; 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=pqSw0K+aoijDk0c0l1QoWEgxZcS7eEIIOUUlgHO3FXY=; b=A761phUrXHe4ng4P2OB5et6VKFYr/QZqzXQ4Y59foEUR1jxhqZ7zyHKGuxq2u4O52W I4LcyANNjDyiVXaSIh2BLXKUtJppYHup5ucb5XTCr8pM9VEgiTbm/Wf6q2hh1M3aAJ3D KoaEkLPOpuAiw1xEFf3GZVTgFjr/mqFJy7CrcbIbxeTbW2ABZtF0kyUPq6BDxN39dLXP ++10bH6eNgyH+n16g6ElPGwkWOEbzlfS+P142q/Dye0lS/T/qL5CgmyWWisBIZ0aL7Xp EJ3TH4W/Qr+ujQvw1Zqxbz3W8bTG2l1/MuCPtlyVQUGLOyeC+YK4dXi6H9kVCwQxTKqI LOBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729540403; x=1730145203; 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=pqSw0K+aoijDk0c0l1QoWEgxZcS7eEIIOUUlgHO3FXY=; b=mWiwgCfepSvrYz46R/CvOz9Kn2qSbKjmO1dFd6j/CohVMXkW42dn8UBEAOHn7C0OCF IKnjSIYgI3gjzmLZ2a9e+8LF6T4pSgvtby7UV0GyeVMg98b1a758EDYVPng7hgx9RpuV 24ZiXcgEavkYZsGNiOgpHdVQuytXmnFZAkntVYpUhTtFNgBIRtsSdNxMVkz6iuYzAsEQ u+/rKkzrvItB6/RjM+E1RFGSI/k72HlBFKomA3qvXpscRRwmiCJB8U6Kwla3xpxJXZxa XqjajHJyWQ8SOLGO70G5ZieT8XioAJvSqnC3DQKNPloLRe4K4E38E28I5ywZESDUNl1a WiYw== X-Forwarded-Encrypted: i=1; AJvYcCUIH5aIR32VaTJQ+zbOQ9RqhZkQPWdKo5lt0LRxBszVxkhpFBl5WZ03FS9T4JtRve0wU8e0HV3PpLVXKrWI@vger.kernel.org, AJvYcCWNYQ8kdMyTPOj1ejyBqqlrszPJFJPxtzAEGg2edro+mvUoZbJqf5hg4oVYEWJrV9ZQDn/6w3i0D0f1Nw==@vger.kernel.org, AJvYcCWkitsREpd8t/gIqkY1iD/opKa618+1YvPN/WMfft/w4fenG+kds+yKrUmq3jw/1rs7/2y480c=@vger.kernel.org, AJvYcCX2WKApUt54jpzzNm9Wtog2R9a8nxcL+EIKehjSd/vv4C7a2onV+qIdtxwl0qtyKHvSq4GM7o1QWRfl@vger.kernel.org X-Gm-Message-State: AOJu0YzCj9pCJhjMXDZszP1fz7uWiKz0VKxsYZlaGZwU0XnigteJG0lw 9GFKJFvwMo9f1a5FtaC/D9viG1BHrOsPFuPs+E81Kzk7yeo6CMgX X-Google-Smtp-Source: AGHT+IFgcWx94Xo+Q3Rp5+o5bL9QLtp2dZ5d6eSDxJplcImLeKFl5UwlGtvs/Alg+94qBduQW3SUVQ== X-Received: by 2002:a05:6402:2551:b0:5c9:5a96:2869 with SMTP id 4fb4d7f45d1cf-5cb7fcdbfaamr91063a12.10.1729540402876; Mon, 21 Oct 2024 12:53:22 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:9cf6:f1e5:ce2b:ea6b]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-5cb66c6b12dsm2338702a12.77.2024.10.21.12.53.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 12:53:22 -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, Stable@vger.kernel.org Subject: [PATCH v2 01/13] iio: chemical: bme680: Fix missing header Date: Mon, 21 Oct 2024 21:53:04 +0200 Message-ID: <20241021195316.58911-2-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241021195316.58911-1-vassilisamir@gmail.com> References: <20241021195316.58911-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 the linux/regmap.h header since the struct regmap_config is used in this file. Cc: Fixes: 1b3bd8592780 ("iio: chemical: Add support for Bosch BME680 sensor") Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/iio/chemical/bme680.h b/drivers/iio/chemical/bme680.h index b2c547ac8d34..dc9ff477da34 100644 --- a/drivers/iio/chemical/bme680.h +++ b/drivers/iio/chemical/bme680.h @@ -2,6 +2,8 @@ #ifndef BME680_H_ #define BME680_H_ +#include + #define BME680_REG_CHIP_ID 0xD0 #define BME680_CHIP_ID_VAL 0x61 #define BME680_REG_SOFT_RESET 0xE0 From patchwork Mon Oct 21 19:53: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: 13844586 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (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 153A91E0DF9; Mon, 21 Oct 2024 19:53:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540409; cv=none; b=dcJewuUuss92t93mR4cMkr+53gvkj/o5A05pc8s0UTCytnnu5HwFO3nNZgWi3UwwcH7pf5zM/2Jnxp1+YKyWi8mblo2PL7x0eaxGep/9TF6ADekwmnZz4TQMNtpHF0lYTavel9z7ImdoRqMMRUpMpWBsIlUZ3QyhZdCU6aoGP/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540409; c=relaxed/simple; bh=ZxpP7aJwaJLHATVot1wu9EBhCXPJL7g2dbLyHzIBc7k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NGbCGeISe82MoWg3AxAa7jQuLo3hzZ2/hQ1k4kmnfJ0kVgaGuhhQ7uY2PZiiciI0tprJExqZ7otyOUA7g77wwoTx64PI65hQqPUAqsq+Z6naTOH/OEz+JdJp6iGaTOkBmbOSBL0rs3roLcd/o8bfdi9/bbjgyLQxwmIEvxkG+gU= 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=MUIyDxVC; arc=none smtp.client-ip=209.85.208.48 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="MUIyDxVC" Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-5c937b5169cso263368a12.1; Mon, 21 Oct 2024 12:53:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729540405; x=1730145205; 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=4gGP7bFWIQ4JodD++nMtz1bBbN0FE4q51Iek/goH/Gw=; b=MUIyDxVCh9LvlD4BTbstvUn8TIPPOtVFpLI0/bPBFpacqODi6Z3uoPU09F1NUKi+2q GlFPHx0KvINPi/rhGHBcCG1fitALNExiqfLlQrowx4IPBG5eCDXewzBXQKyD4XufNUH8 yRIODARzVEIMdj9x85M4Rbm8Hnfq7Vqs9FWpHtAcC+engcJ3x7YH2fjl+JxzMMkgR1rk WVNuaurx59JRvwzBDlzJ3p27ipRP4nEl16sssxhyHW0f1TlkUwkYejUjOctRmWPeeqN6 lr6pUWcJlNPkRaYwArpDLQ8MASk8eZ/5AjZvIyg1R0cJfUjFnSU1+WZxGFlnZvpyogkh 72iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729540405; x=1730145205; 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=4gGP7bFWIQ4JodD++nMtz1bBbN0FE4q51Iek/goH/Gw=; b=s6g7KpIgLWWyiFrXOi5iGXu2IavDmST0EUl0LHWiIsTHhIZBrSr8sZDssfe9UOWwaL vZEn+CqYQpmpLNYLn0VKGdU0M+QGkYkrnGFALTrT4FJDT2236Gu62qxSsNioXiJtE5AE mPJc0TcoZl729f8UH/IvdrW63K/U19kpCrOVhdIin2M2zetI90aL5rLkFelDNJuMes2H LNwjh9h5CIzwI9fLwzxNPOFtlDx0QhgV/RgoBK6mqx+YPWluOHXTxJoP8D8wYdQigwAd Plyl1w6u3PHlELKQiEi3TKeVNjwB4oFnaBuC9B/vxeHPoy+ARpyTtBy6QlF58wZnHVmI giSw== X-Forwarded-Encrypted: i=1; AJvYcCUNJExXtrur7Q1bT7WaG6ZCAW04rolY4QtGVxvPFB+WvuRvTYTi6PzORe8j2RDMdG8FRegWhbx+oW9V@vger.kernel.org, AJvYcCVE4WIu3PlqAZ1MR3KNpSFCuW2FcUEady6xhlvuQyZxpUsFT0ir2566b2EfTc1A+nmXg+zofpciIJgm@vger.kernel.org, AJvYcCWZmO0Q/TU7O1HjqMKe9H0nPCxXWuAn/3HTfzWTim6WN9Z5Hzfg+sEqRTjE8hzj0uqrNn3AgsYhKTKWf6CD@vger.kernel.org X-Gm-Message-State: AOJu0YxHzEF2erjnCy7jmpkZ8yN2xR9AB9BD6a7n7863zFNbjfm5DLRP wv3h5Ixu49OxhiMsNmbDMri/CPfRtUslO2hwQ8UTtA73xA8jlCzr X-Google-Smtp-Source: AGHT+IEOLHrwWtlApmwLQ+Se615asrYaJdL1yL//ZCA6cK6yt8cbuWqIVJw4MyA3nNKVYTXVq+MeRg== X-Received: by 2002:a05:6402:2808:b0:5c9:1cdf:bbae with SMTP id 4fb4d7f45d1cf-5cb79479ee0mr790864a12.11.1729540405150; Mon, 21 Oct 2024 12:53:25 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:9cf6:f1e5:ce2b:ea6b]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-5cb66c6b12dsm2338702a12.77.2024.10.21.12.53.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 12:53:24 -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 v2 02/13] iio: chemical: bme680: optimize startup time Date: Mon, 21 Oct 2024 21:53:05 +0200 Message-ID: <20241021195316.58911-3-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241021195316.58911-1-vassilisamir@gmail.com> References: <20241021195316.58911-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 According to datasheet's Section 1.1, Table 1, the startup time for the device is 2ms and not 5ms. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iio/chemical/bme680.h b/drivers/iio/chemical/bme680.h index dc9ff477da34..f5be4516dde7 100644 --- a/drivers/iio/chemical/bme680.h +++ b/drivers/iio/chemical/bme680.h @@ -65,7 +65,8 @@ #define BME680_MEAS_TRIM_MASK GENMASK(24, 4) -#define BME680_STARTUP_TIME_US 5000 +/* Datasheet Section 1.1, Table 1 */ +#define BME680_STARTUP_TIME_US 2000 /* Calibration Parameters */ #define BME680_T2_LSB_REG 0x8A From patchwork Mon Oct 21 19:53: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: 13844587 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (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 223E01EB9E3; Mon, 21 Oct 2024 19:53:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540410; cv=none; b=mZRLiy5iXkZsl0WTqCdk+gXRWU10MCwiesBh45Jys3uwry5JHi2WM7V32t3yCCVm1lsU0jhgsTiKIxuWvjzfv96F1wKA5RZybI/TJi9gUrGSpq1Ut5YSg6Nb4+YgoTGHRvPcPg4j+Q/9U3pnOFGuEYsqXblgXe5BjEXlggZy8MQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540410; c=relaxed/simple; bh=pacgdWs+yQkE73J1SRknkc07WNnGfj7yD2J0MaFNg08=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WiiB0DzKmXATkjyent5wpeuLVpkqN/L8dArp4fORIc4NucW4dHfTHGcctLELV7hDF0N9LKAGGKYzBr5JyTSe/hIgjKG/lExqqKPN+e4ziijy1CNopAdHtSmBruGV3g626h6NkbDinzs2LKe9qk3opYE8xaf7in8wYQUtAfWIWsM= 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=BGOeF8yy; arc=none smtp.client-ip=209.85.208.43 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="BGOeF8yy" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-5cb615671acso1368923a12.1; Mon, 21 Oct 2024 12:53:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729540406; x=1730145206; 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=0QJFX4ZiUvU/gkiEPA3cTN5cC96Exsyal6fVxhijVGg=; b=BGOeF8yy8aRlubFFCR+f7ollVhufN5s3sRTu4WmZLdCNA+OOkxAPRWJ2XdiaiiCg5n ypL5onfWnpQnRcdD8w0nwiL+BoRYn+flIAsyvk5j7wEZZmntRhi5Wtjohsuian+jcsri 8oP8AZArBIEZhSRcfW//gs8HHQz5+6/oqg/hLdjI3idLFdJgidefRNeoU5hImLcIjH7k m5OOCv6T7jvNX6oXmX9LxaiTbmXfi+EoHZ4os7rlEsi2w8TUHx1iikuRoD+E5o6cGPvm wTPEgaxqekRpM1z7qlpkSoWspDUVtJghT8ryviSrl+XrOEzJK0Rud68Z3rDzIK4EkCW4 wh1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729540406; x=1730145206; 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=0QJFX4ZiUvU/gkiEPA3cTN5cC96Exsyal6fVxhijVGg=; b=bzi6PcRXTbEkrc0wnXLhzuMmkwZe3ln5+iKQlag0XNn0YsuEry9rst92+A663baPRf soda9C8oRqPe0dguFoBLd3RT3DAY9SYDQsQSFNkzrtn9yRmFvhCcSqttn/FP3bd2gi8I X4D5efGIEljt/cjaBw0zdxU/+goM3TG0hgfmYqKHacJHyVRZZp3AYqlRfeztd9hKWHSC C4he7VhbvD7zqtHDznAa0AnY55bXJ1zvPbWNEGA0EWQfh6opmZf2HMin05nxHUOaxuKp T9kABoGY0m1hsZsRktC3/V/vNjn2RpNsTOKbn++r1+77mCRniVX4anWgI6b6I5QsrIJo m6Tg== X-Forwarded-Encrypted: i=1; AJvYcCVOoqMyI1lcaPUqKR4mDQEM3Fq/cpwvxWOYG0UW4GaHfzFW1CPB4ApLTusn1ag3NycQK5iKJdO86GSpK3dS@vger.kernel.org, AJvYcCVUlNNCgWJoIO/cvgBrMRqCrFA2PfKaD0nQMvRPNx/AZAHX73ips9FSsTgdM+xpuT3Rz65V5Cbca23q@vger.kernel.org, AJvYcCXrawjmF+LqCTWgpqVBfJhXBZDZZmG7ndLmXvO8MkKfs6A9+L6NmIiO+O4TVXjqFATEc1KxguBAR8hd@vger.kernel.org X-Gm-Message-State: AOJu0YyDbWvy4LtMnc4T3e3WG63mFBfXFzTOdcLaeuM2i+omySlsO991 A2pdZ+nR9aGvArtw64qrGQd+p2a4xRZUxeoWSECA7uVWDlfMgFrE X-Google-Smtp-Source: AGHT+IFwyqbRuZ9aFFw17AD30AfocCUP7M2gHGfhoZMs/40pJWnaeeIEOI7KURZ7lhwkqAT4SVm19A== X-Received: by 2002:a05:6402:350d:b0:5c9:48df:713c with SMTP id 4fb4d7f45d1cf-5ca0ac439c4mr14103571a12.2.1729540406326; Mon, 21 Oct 2024 12:53:26 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:9cf6:f1e5:ce2b:ea6b]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-5cb66c6b12dsm2338702a12.77.2024.10.21.12.53.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 12:53: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 v2 03/13] iio: chemical: bme680: avoid using camel case Date: Mon, 21 Oct 2024 21:53:06 +0200 Message-ID: <20241021195316.58911-4-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241021195316.58911-1-vassilisamir@gmail.com> References: <20241021195316.58911-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Rename camel case variable, as checkpatch.pl complains. While at it, fix also the indentation of the array for readability. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680_core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c index 0b96534c6867..d228f90b4dc6 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -438,15 +438,15 @@ static u32 bme680_compensate_gas(struct bme680_data *data, u16 gas_res_adc, u32 calc_gas_res; /* Look up table for the possible gas range values */ - static const u32 lookupTable[16] = {2147483647u, 2147483647u, - 2147483647u, 2147483647u, 2147483647u, - 2126008810u, 2147483647u, 2130303777u, - 2147483647u, 2147483647u, 2143188679u, - 2136746228u, 2147483647u, 2126008810u, - 2147483647u, 2147483647u}; + static const u32 lookup_table[16] = { + 2147483647u, 2147483647u, 2147483647u, 2147483647u, + 2147483647u, 2126008810u, 2147483647u, 2130303777u, + 2147483647u, 2147483647u, 2143188679u, 2136746228u, + 2147483647u, 2126008810u, 2147483647u, 2147483647u + }; var1 = ((1340 + (5 * (s64) calib->range_sw_err)) * - ((s64) lookupTable[gas_range])) >> 16; + ((s64)lookup_table[gas_range])) >> 16; var2 = ((gas_res_adc << 15) - 16777216) + var1; var3 = ((125000 << (15 - gas_range)) * var1) >> 9; var3 += (var2 >> 1); From patchwork Mon Oct 21 19:53: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: 13844588 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 7DCFF1C9B82; Mon, 21 Oct 2024 19:53:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540411; cv=none; b=TfTIx7A6wnG0xiTuCKmW48mJX/OJND1ipoBzdK0qRSXN2vmGfNXoexqXBtuWsstjyBufr3vKDhl2+fJfJVu0lwPBJoj9ilU9ehvybs7FbGJsTMA3oAbKrENOz0Vlf5XbhU+3PT9Lr0ZNmLAQIw8V2mEMyo4EM/ak47NiNOZKLwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540411; c=relaxed/simple; bh=ezXl4v8W4J6XN8omxgx9NgXx60OPexUxZJG+saDHlTs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sN7NMe0JUuHPM1ELwt7uQ9x/sw/03M7B0kz1qIKRneT7iqhAJQq7Dlma1/HHSxmdXBlZ5LZ+Lm6ELn90rf8sfLz/T3+WtZEVDcWxwi9QPCdBV0xY8uKHNOLQDJn8RudZ7j24EnBubt7RKDIwadSTdsnwbkbca2i5oWi40S2e5z8= 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=DuDC/YZd; arc=none smtp.client-ip=209.85.128.48 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="DuDC/YZd" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-431695fa98bso23944075e9.3; Mon, 21 Oct 2024 12:53:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729540408; x=1730145208; 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=DAEuSCx9ubPqQdyLtNi7rXlFj0w0O+VCxcD2ZmvWOgw=; b=DuDC/YZdrbDI5m+bDrHJWbphCPtYHhBqdI30Il+4E1Ws4+Om5mSyAzRxQXy0gdm41S RURfPrWK1cdWMO5sNGYPFR1Ub/htNu1LlsveuyrbRIEGjguWdLbEyYViFO5usFVkjdZz eSJ7KFqb4q6ecf6NXvSJm+3Uqsp08RYTEsT3D12mm7KaTwxwgCi3ODszqBa66mfahC6E Kr0mm91lXstac4eM5oBme+rvh8rvBW0aCDQYmTPfocC5SvAhhxNvyjLBlDD7Ub/4Gvuk 5U21rbkdvmRnZHtQGRnyWo5FrbZHu34Kb6hP2XnZE5UIPe4/Wi1nxNhEb/xGYEyXN1Ct 05DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729540408; x=1730145208; 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=DAEuSCx9ubPqQdyLtNi7rXlFj0w0O+VCxcD2ZmvWOgw=; b=uDijx6p42lVC74E9aU5x8DPcsspMtfLK0JsJO6XmNDACw0bqDtW1EGzfWZSvkn1yne JAtzIbXVqUCsYtz15Tw/sMSmtJ3DtaLS0Q2M8go5VkiY9K1L0I8IOUUiunPTLiry9NyP fLT7Her6v5B0w+WbOK1b7J3VF0XsEipRjtz5pvfYkpIb2NnVvP4VXHHxW759ISBP7hYm xVd1gUH86ioRw4nAjgQcSgkg9dNl5KZKO/P6YjF3Co4SwhSd6qx5t5+fno+Z7Fc8B4js BYP0UoO9GkPJJ5A0eQoGUXvHzISLuSIG9fkDd9JEVBEV+GEeCNigB6QXn9hWvbEKUMSI Vm8w== X-Forwarded-Encrypted: i=1; AJvYcCWaXC5xL6vVyeIIimwUbQphpdl8tJanImNeskg0weKaXu53bh+GCbsOnp9TU26GD3D6jeLCYZzd7uovpORv@vger.kernel.org, AJvYcCWj044Sl2w6w6SKDWJ0rv012UlYJnlCuHZF2VIwSr+XCaJmHrPPfN2o0qFsltf8YkIIE/0KfB5vLhfo@vger.kernel.org, AJvYcCXS017IIbnkjLMBd1HTQYBC/obee64d3bCtgqXesXk2naK2BrDvJb4Hp5Jp54/KB7PigvSNjRss0aHp@vger.kernel.org X-Gm-Message-State: AOJu0YxrotR42TZJWgL3VpriuuOATe1/RGg5IBXEG1Evgaa06SQgPdKI Sd127ftMd+xxqPYrLzMYZsCsEyk+L1pztf7DYt10pKv/FqVBduQF X-Google-Smtp-Source: AGHT+IHXBDjbuKYFxxBE3m07eIDPFlVH8nP6fc0n2zHCbM5higff1cgAAA+po3MrrJzUzIJ6raaoFA== X-Received: by 2002:a5d:54c3:0:b0:37d:3f42:9b59 with SMTP id ffacd0b85a97d-37eab4d13c2mr8153964f8f.11.1729540407758; Mon, 21 Oct 2024 12:53:27 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:9cf6:f1e5:ce2b:ea6b]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-5cb66c6b12dsm2338702a12.77.2024.10.21.12.53.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 12:53: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 v2 04/13] iio: chemical: bme680: refactorize set_mode() mode Date: Mon, 21 Oct 2024 21:53:07 +0200 Message-ID: <20241021195316.58911-5-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241021195316.58911-1-vassilisamir@gmail.com> References: <20241021195316.58911-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_core.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c index d228f90b4dc6..9002519d2c33 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -95,6 +95,11 @@ struct bme680_calib { s8 range_sw_err; }; +enum bme680_op_mode { + BME680_SLEEP, + BME680_FORCED, +}; + struct bme680_data { struct regmap *regmap; struct bme680_calib bme680; @@ -502,23 +507,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; @@ -615,8 +613,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_SLEEP); if (ret < 0) return ret; @@ -756,8 +753,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_FORCED); if (ret < 0) return ret; From patchwork Mon Oct 21 19:53: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: 13844589 Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (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 92F121FBCBA; Mon, 21 Oct 2024 19:53:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540413; cv=none; b=AVcFPtx4BNuDvyoze94ILkR7n3v/U6kf+delNAjb5i2y2bMG3dPLGrRtRqnS9+vkO5THq0zyDC/saW6fFa0oYBfKwxJtHmzs4KRGV6DAPGfLsI2e5ojDYAfm55Ew6g3N1LHmQsv+KsOzRAY9Sh5Ulzo0G7mua5KB2Woa3Ju47Ps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540413; c=relaxed/simple; bh=exX1qSG4caqUNRqf+dLnNnBec8h90+RnI+CYsIY98zE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Kwe7A+tbtZHKGx/UqDnx3uswzdLA8r4gU7dRgxsqtrz5MD8FSwvk9J0GSpxExqifb5/d3kvI60rjBHENpDAE++Ds7Ulzpjy0c1ezovh8iePQpF1R4aZr3XZ5kjLehrIhXC9t1HPwve4JjuDY5uJaXOtk2ODfOYyX2KLnEtdh5g0= 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=MfK1gCxm; arc=none smtp.client-ip=209.85.208.179 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="MfK1gCxm" Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-2fb49510250so46133981fa.0; Mon, 21 Oct 2024 12:53:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729540410; x=1730145210; 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=yaHW0AqwioA5ZdhItuYlJBN63Z60C9XMxnFZsCxv860=; b=MfK1gCxmlDmXJCTi1mlziViLeZrT0e40K2s+mhCkDpwF67/a07zkfPs/4l+wsOc5A0 F6oCQm7k9kQhYC9gldPWNMJyhgAewBLG1PBgWDZkYswWTnS4PHJ6yihFx2UhzzHrJRxn jmvLL3CPTMhyVtOOXfwYyZJ+7FdfGNdyYV9laHIwWBwqKCG15MBU10QkpZ/Q3d30VC2B yFnq0gGcJDhcZAxDAoqvEVGMqbBEjcP28bbRspD10312AENdT+9mVH3oRavjPsWQiXJr eXnzrQYkgG9frBeicm5QeUmlA7UL5LwOlu1TKbRSdqusyz7YPC4rBTGCoJVai9UlEmLR hAiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729540410; x=1730145210; 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=yaHW0AqwioA5ZdhItuYlJBN63Z60C9XMxnFZsCxv860=; b=upldQVQ7UDtHQXOd76eJPuaNoNP3/lWbRzSDVEluC3vVUuDJHIwUVyspRHaEFvZ4bE sXy+wuwlUwIzZK5lKlpd01oaiIclaPxrFJlXF00uMiOFjwi4h2p5KoA1pqhlMYr5RFsp YU59+w0KUWSE4Vw97sR6dA3FRsZW/g4/Hx80977wLU9yKM0wFGETNhGUWAuhpAme6cSS t3mxxJxfm+b//majebTmhIpR/xBPaIX4y1CSSK5q87QhwHPYMX6BMefq88VsgmrVqGfv NEZ4btCL2nfAdvHgF9BaWnBpXjxIdOHczoK5+AG6UEUbXp8UbPpzdUbLH833n48c7XIu QBlQ== X-Forwarded-Encrypted: i=1; AJvYcCWWXMzvmeTvkqjiIS1w6hbMDGckpV5qOC2Zo+FTDWwulDZynzindj1WgLaSMdIkSs0xNP1bhUuPTwtb@vger.kernel.org, AJvYcCXdfSRlGKNvPsu6oXExaioBHn5bANrSz9rs7eaJLpC0/ILsOPD1skVRZ7dj5MOOUDXKywk4Q8VUzsir@vger.kernel.org, AJvYcCXrSS7dO1PnWQuTSo0WQz7LP2bfzMmdyk++BUDVQYn9NQVXWrjWpRhwV+4lf+CNQ0h2+jyxmMfoq1KlKIk1@vger.kernel.org X-Gm-Message-State: AOJu0YxDck+Oxh5o5jtvdy80avx0AOteO6T9CBxQzAHZDxXM/lwgbLvy qcR6PNNMXSumup2O2oGXMfdr6mCqBA6jW6uLArJCmqFSFsA7vAY/ X-Google-Smtp-Source: AGHT+IGFT6DDNdiZIELy/v2zHKXoBMFfgTn6HTeYIG+9H0aoQf7VvuAEKUmuL3GgwYvVJ5JpP+K8UQ== X-Received: by 2002:a05:651c:1505:b0:2fb:6027:7c0a with SMTP id 38308e7fff4ca-2fc932e36aemr714101fa.8.1729540409447; Mon, 21 Oct 2024 12:53:29 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:9cf6:f1e5:ce2b:ea6b]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-5cb66c6b12dsm2338702a12.77.2024.10.21.12.53.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 12:53: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 v2 05/13] iio: chemical: bme680: move to fsleep() Date: Mon, 21 Oct 2024 21:53:08 +0200 Message-ID: <20241021195316.58911-6-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241021195316.58911-1-vassilisamir@gmail.com> References: <20241021195316.58911-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use the new fsleep() function in the remaining driver instances. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c index 9002519d2c33..2ff85e29bfc1 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -544,7 +544,7 @@ static int bme680_wait_for_eoc(struct bme680_data *data) data->oversampling_humid) * 1936) + (477 * 4) + (477 * 5) + 1000 + (data->heater_dur * 1000); - usleep_range(wait_eoc_us, wait_eoc_us + 100); + fsleep(wait_eoc_us); ret = regmap_read(data->regmap, BME680_REG_MEAS_STAT_0, &data->check); if (ret) { @@ -890,7 +890,7 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap, if (ret < 0) return dev_err_probe(dev, ret, "Failed to reset chip\n"); - usleep_range(BME680_STARTUP_TIME_US, BME680_STARTUP_TIME_US + 1000); + fsleep(BME680_STARTUP_TIME_US); ret = regmap_read(regmap, BME680_REG_CHIP_ID, &data->check); if (ret < 0) From patchwork Mon Oct 21 19:53: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: 13844590 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 A1CFC1FDF9E; Mon, 21 Oct 2024 19:53:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540416; cv=none; b=k+1xo1LSyqgU93xLTidHC51OBhH8s60YJ1RXWGIpk4Osm+qz9T8voV95bJDz/neggvmYsm2n4GNjjzx0Jm2jzQhWwnNQJ7Xcl053uCy7h9OrytBqJMuPKbQS8OsD9kJo4KLGW8HsGhSWYL7HZemZFB5kfZCvwsEOlBW5NQVcysE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540416; c=relaxed/simple; bh=vyQi9ZTVnpbOKfBHPIcB5RMs9bY6xG8O3WtbCaEM738=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hUAYXdxuGdxYR4Rt3EaIDB6yVM6//H1SFRM7K+sWsrfY9KUNOT7/YChJODZV4P9nwyflOHppQ9cBFQjS5ig+YcgGYUoxsgU4Ewu0TCB0r81yY5ySIObLPSt21s2CQbpxNa5NRIhzQSl0TLpSyvg6dJTxFc06DUSigSrpiboqzww= 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=BEMCesX0; arc=none smtp.client-ip=209.85.128.45 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="BEMCesX0" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-43168d9c6c9so27937785e9.3; Mon, 21 Oct 2024 12:53:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729540413; x=1730145213; 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=40gsg2Bc+Fe/tDyauIqUSjZTx45Ksw8BC4m72iFnA2c=; b=BEMCesX0k2Gn5LaEO6b4nbO/eK//D9g/T/HWbvqHJeTGcx0QrpZqwBU7zy40GwbJ57 upMJUu1ZhwpzJwXJFFFNAeZ7ps5ukBui28WTVtHdyJiZdVbsmEZqN6/TswMDUOUtxG/q o9z1axftrzsvWjh8n5ZgYiR4F0tskSU79KXiISPOrNK1HgXAu7PrbaAIW9U4PdViHqfy 2kFwkMPPAX3K+hRde+zG1iN93dbKEXfs2YWTQKXuIjApYKy143yQ4V6mHZiLKKfcTd+d oDtA0TcBMP3lUwLcAKTWQ5eGtZlzhbaW3mLvCZnvL1pRlJiBzz169vm0irscBRPt/MIn nP8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729540413; x=1730145213; 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=40gsg2Bc+Fe/tDyauIqUSjZTx45Ksw8BC4m72iFnA2c=; b=ChUTOPiCkHkBKvppsIrPz+OOxoBAcCuh4m5bzyBipwMWv7GIRhtD36/KaA+AouwkE3 WGnDJdtjS+zKJzApdeF3pGJ5ukjxzjPtDXkW7Kcjhz9D/t1YMKkF3l3mpmuN5N0Nl3/m Zh5o7ABJ7TuewpLZlqk1r3oNXUns0TPNzSlUuCBb34AynwHUsSMIN5R9KUjBMVmtF6an 9Y9FcMA22o7EWXMmavnuh+9Z2Ai4QejR2VCqR4Vrbaktl95m8xjtwNXHjmsdmDc+21B7 ueDuBim0QfBPaEloHYgZF8NEjs1qeYvcjls6JKzYeCKPv+xh1v4zKdUKtB5a+VRMJuIL w16A== X-Forwarded-Encrypted: i=1; AJvYcCU89eSX2k9DGmSTf7OT5t1Hd9woFeb8CVkQhhCxb0r4KRT1FQYjnhxa4PThQU3im5L/fSWso8e3Axp02w48@vger.kernel.org, AJvYcCVzCTxZCS8cHW/dJJaCTWL+P675IJ3rIzphF1+DWIH0S8dyLqmkrB1XmJrqLWmtUvXkrjCRj8hKveM5@vger.kernel.org, AJvYcCXdlJDOXAbPO6nfh4ZSYfx2vXeD66Fk33hchK9P7z0VXEBPS6YfGkNvq6cK93jQM6R6oRLTnIsAYEWC@vger.kernel.org X-Gm-Message-State: AOJu0Ywr0OIDInQaijHYYKkj1Kfm7CEUzwXqCYyaeAdUwQ4yFNJauNf8 jht/3elL2tTdQnOB6OtFEOASqoS9ltqHIeFW2UMbX5PzcBbwC8s+ybwMRA== X-Google-Smtp-Source: AGHT+IHwj9o1i1V0HMBSOt42E/or9FfHo0hiuTGCPj37k6RUpifDaLmfQVgHNwaRTJjOgzVQXzmY3Q== X-Received: by 2002:a5d:67cd:0:b0:37d:4318:d8e1 with SMTP id ffacd0b85a97d-37eab6e3db3mr7563883f8f.23.1729540412883; Mon, 21 Oct 2024 12:53:32 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:9cf6:f1e5:ce2b:ea6b]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-5cb66c6b12dsm2338702a12.77.2024.10.21.12.53.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 12:53: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 v2 06/13] iio: chemical: bme680: Fix indentation and unnecessary spaces Date: Mon, 21 Oct 2024 21:53:09 +0200 Message-ID: <20241021195316.58911-7-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241021195316.58911-1-vassilisamir@gmail.com> References: <20241021195316.58911-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Fix indentation issues, line breaking and unnecessary spaces reported by checkpatch.pl. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680_core.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c index 2ff85e29bfc1..2ad427f5deb4 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -229,7 +229,7 @@ static int bme680_read_calib(struct bme680_data *data, calib->res_heat_val = data->bme680_cal_buf_3[RES_HEAT_VAL]; calib->res_heat_range = FIELD_GET(BME680_RHRANGE_MASK, - data->bme680_cal_buf_3[RES_HEAT_RANGE]); + data->bme680_cal_buf_3[RES_HEAT_RANGE]); calib->range_sw_err = FIELD_GET(BME680_RSERROR_MASK, data->bme680_cal_buf_3[RANGE_SW_ERR]); @@ -450,12 +450,12 @@ static u32 bme680_compensate_gas(struct bme680_data *data, u16 gas_res_adc, 2147483647u, 2126008810u, 2147483647u, 2147483647u }; - var1 = ((1340 + (5 * (s64) calib->range_sw_err)) * - ((s64)lookup_table[gas_range])) >> 16; + var1 = ((1340LL + (5 * calib->range_sw_err)) * + (lookup_table[gas_range])) >> 16; var2 = ((gas_res_adc << 15) - 16777216) + var1; var3 = ((125000 << (15 - gas_range)) * var1) >> 9; var3 += (var2 >> 1); - calc_gas_res = div64_s64(var3, (s64) var2); + calc_gas_res = div64_s64(var3, (s64)var2); return calc_gas_res; } @@ -473,7 +473,7 @@ static u8 bme680_calc_heater_res(struct bme680_data *data, u16 temp) if (temp > 400) /* Cap temperature */ temp = 400; - var1 = (((s32) BME680_AMB_TEMP * calib->par_gh3) / 1000) * 256; + var1 = (((s32)BME680_AMB_TEMP * calib->par_gh3) / 1000) * 256; var2 = (calib->par_gh1 + 784) * (((((calib->par_gh2 + 154009) * temp * 5) / 100) + 3276800) / 10); @@ -569,9 +569,8 @@ static int bme680_chip_config(struct bme680_data *data) int ret; u8 osrs; - osrs = FIELD_PREP( - BME680_OSRS_HUMIDITY_MASK, - bme680_oversampling_to_reg(data->oversampling_humid)); + osrs = FIELD_PREP(BME680_OSRS_HUMIDITY_MASK, + bme680_oversampling_to_reg(data->oversampling_humid)); /* * Highly recommended to set oversampling of humidity before * temperature/pressure oversampling. @@ -585,8 +584,7 @@ static int bme680_chip_config(struct bme680_data *data) /* IIR filter settings */ ret = regmap_update_bits(data->regmap, BME680_REG_CONFIG, - BME680_FILTER_MASK, - BME680_FILTER_COEFF_VAL); + BME680_FILTER_MASK, BME680_FILTER_COEFF_VAL); if (ret < 0) { dev_err(dev, "failed to write config register\n"); return ret; @@ -885,8 +883,7 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap, data->heater_temp = 320; /* degree Celsius */ data->heater_dur = 150; /* milliseconds */ - ret = regmap_write(regmap, BME680_REG_SOFT_RESET, - BME680_CMD_SOFTRESET); + 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 Mon Oct 21 19:53: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: 13844591 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (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 AEBEB1FE0E0; Mon, 21 Oct 2024 19:53:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540419; cv=none; b=HBxQygh3QDB4X8xHT4AyCUQIz27Tw8ulK7O7sVlS6h3dJKoKRyUIJUKS6WlRlC5fv6Q2jMqm6dPOSH4epdIvY2iPhWQM53Jq2QeihQ2RvdP9I53Lt6oUEOVpvu0hS4zevbvxCtYn369QRrCb3CrMev2cN+7i2moGkyijNkCW4/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540419; c=relaxed/simple; bh=UVWXbwUbrUBs268eCFhh54s78PsYWHgLof76EVxrEjw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qF7wtcO0NDimgkhk7BzLn4Bzs7ChD/A/4cJxj43VapS2ZS/5daJKRYTUX1lntRYbJT4vs6YsVUWNf8JlWQMB0h3H9tMJYpNY0urSHgQ8JZG/DC+YMmVe4Rv7wvcEo9TWp7HI2TQ4GNhO+EBDXqHuqR5AiAxb2aWJLdv2S/nWYXw= 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=Yn9P1/ot; arc=none smtp.client-ip=209.85.167.52 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="Yn9P1/ot" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-539f72c8fc1so5550188e87.1; Mon, 21 Oct 2024 12:53:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729540416; x=1730145216; 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=zHOvuHmA4/toKmPxxQ13YCc+GHjBN2Z5SMzcuSpTD1Q=; b=Yn9P1/otLVgjn+UvZuiH4/9Uunp1aITj176czyiHYUtHNPuLj0eWITu+molWjY+qEK xEtJPQePsIbAZSzQ4XbEEfIwp9/e6AJEZPr5ELTrbsC6wqQ83Imi0wrvZdMv/BIuJD/M 9BmUcGCMgSy3Ne6G967uYFdW5hK7oRqKQ3zwWqmjXioDCqkqVxSCzbCqiGAkjhibmila CDphOpyM/y4l50Fb9s05fhQ8khsLpAWCDyQ8jBcgf3grl344qaTLu2dAT003RYgcQ5OE O89ztwgO+52sIFLJEpQQJAXx/AQRCHU9D+j7N+Bh5jMTekzTkKtE04Yw4gptab5xcRtL Z35Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729540416; x=1730145216; 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=zHOvuHmA4/toKmPxxQ13YCc+GHjBN2Z5SMzcuSpTD1Q=; b=drLiE3TKj6hj99OF0rClx7MSaNY5bbkcRhTAPKIJePmtshzaqzYepWjcbjdrONekEN SQj39IhHEOf6mizdS0ESMP2onYpRTlZJZM3cudCXH6Ge9lLJc/bnWDXnGe7lwt7tFxPN M4oUtRJcbXMB7xbTx1QA4aKm93pWQ7wW0jiw5Dy3xrrtwv458CtCoHn2VMMpOSka6mBz 75jJQ51++AE4/vIcyAIX/xbe4j57D5e0LNqLw7Z66JBxP5KqoRwimMLlkhfnPBdUdKvL 7Kh/yoNMBhfIfV0hNhMOp4YokSWvRhii3UMnO2YOftzsXduHfb5kojIVb9JcV4TBa7BN T39g== X-Forwarded-Encrypted: i=1; AJvYcCUsFA878NMvpE04a7ja/kX6IkeH9JKRsLr7VibKZXdvJhjbyy1Jgf2V6g2q4Fm/DlxLysfGY0BhrDO37cUu@vger.kernel.org, AJvYcCWohtXayk+nGBhK0STy7Mo+qk5PcHQJ+MVCwA+Ms6wb24SnYFQIpI3k47c6EQ9uaQChSqDJuX3IqCIo@vger.kernel.org, AJvYcCX65sqZGtbRRxWBsNo6lMA7dZQVFVcMh47d1ow/TEAbOmKqEYxIyUvNzPgV40Rs/vWtCLw3kp39FtKK@vger.kernel.org X-Gm-Message-State: AOJu0Yy3QolcC+s7ueMVw90yLHa6LfQgcZzlNboMd9nxMbTDAtkNuTDe HOjsMVwguKd21TfnOPC8fE5FYszWSQeNRXD4P3bEpMdFSi36LtBb X-Google-Smtp-Source: AGHT+IG6UDRo/01CqwTIuHIsaFtYn6v3bwZTt0oBDcQ3RkjuZr4vvUBDCFEVGOAFXpxxgjtlHcDFKw== X-Received: by 2002:a05:6512:158d:b0:537:a745:3e with SMTP id 2adb3069b0e04-53b12c36af5mr753067e87.45.1729540415578; Mon, 21 Oct 2024 12:53:35 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:9cf6:f1e5:ce2b:ea6b]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-5cb66c6b12dsm2338702a12.77.2024.10.21.12.53.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 12:53:34 -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 v2 07/13] iio: chemical: bme680: generalize read_*() functions Date: Mon, 21 Oct 2024 21:53:10 +0200 Message-ID: <20241021195316.58911-8-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241021195316.58911-1-vassilisamir@gmail.com> References: <20241021195316.58911-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove the IIO specific scaling measurement units from the read functions and add them inside the ->read_raw() function to keep the read_*() generic. This way they can be used in other parts of the driver. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680_core.c | 68 ++++++++++++++++++------------ 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c index 2ad427f5deb4..c79ba6d1ece8 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -644,23 +644,20 @@ static int bme680_gas_config(struct bme680_data *data) return ret; } -static int bme680_read_temp(struct bme680_data *data, int *val) +static int bme680_read_temp(struct bme680_data *data, s16 *comp_temp) { int ret; u32 adc_temp; - s16 comp_temp; ret = bme680_read_temp_adc(data, &adc_temp); if (ret) return ret; - comp_temp = bme680_compensate_temp(data, adc_temp); - *val = comp_temp * 10; /* Centidegrees to millidegrees */ - return IIO_VAL_INT; + *comp_temp = bme680_compensate_temp(data, adc_temp); + return 0; } -static int bme680_read_press(struct bme680_data *data, - int *val, int *val2) +static int bme680_read_press(struct bme680_data *data, u32 *comp_press) { int ret; u32 adc_press; @@ -674,16 +671,14 @@ static int bme680_read_press(struct bme680_data *data, if (ret) return ret; - *val = bme680_compensate_press(data, adc_press, t_fine); - *val2 = 1000; - return IIO_VAL_FRACTIONAL; + *comp_press = bme680_compensate_press(data, adc_press, t_fine); + return 0; } -static int bme680_read_humid(struct bme680_data *data, - int *val, int *val2) +static int bme680_read_humid(struct bme680_data *data, u32 *comp_humidity) { int ret; - u32 adc_humidity, comp_humidity; + u32 adc_humidity; s32 t_fine; ret = bme680_get_t_fine(data, &t_fine); @@ -694,15 +689,11 @@ static int bme680_read_humid(struct bme680_data *data, if (ret) return ret; - comp_humidity = bme680_compensate_humid(data, adc_humidity, t_fine); - - *val = comp_humidity; - *val2 = 1000; - return IIO_VAL_FRACTIONAL; + *comp_humidity = bme680_compensate_humid(data, adc_humidity, t_fine); + return 0; } -static int bme680_read_gas(struct bme680_data *data, - int *val) +static int bme680_read_gas(struct bme680_data *data, int *comp_gas_res) { struct device *dev = regmap_get_device(data->regmap); int ret; @@ -737,9 +728,8 @@ static int bme680_read_gas(struct bme680_data *data, } gas_range = FIELD_GET(BME680_GAS_RANGE_MASK, gas_regs_val); - - *val = bme680_compensate_gas(data, adc_gas_res, gas_range); - return IIO_VAL_INT; + *comp_gas_res = bme680_compensate_gas(data, adc_gas_res, gas_range); + return 0; } static int bme680_read_raw(struct iio_dev *indio_dev, @@ -747,7 +737,7 @@ static int bme680_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { struct bme680_data *data = iio_priv(indio_dev); - int ret; + int chan_val, ret; guard(mutex)(&data->lock); @@ -763,13 +753,35 @@ static int bme680_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_PROCESSED: switch (chan->type) { case IIO_TEMP: - return bme680_read_temp(data, val); + ret = bme680_read_temp(data, (s16 *)&chan_val); + if (ret) + return ret; + + *val = chan_val * 10; + return IIO_VAL_INT; case IIO_PRESSURE: - return bme680_read_press(data, val, val2); + ret = bme680_read_press(data, &chan_val); + if (ret) + return ret; + + *val = chan_val; + *val2 = 1000; + return IIO_VAL_FRACTIONAL; case IIO_HUMIDITYRELATIVE: - return bme680_read_humid(data, val, val2); + ret = bme680_read_humid(data, &chan_val); + if (ret) + return ret; + + *val = chan_val; + *val2 = 1000; + return IIO_VAL_FRACTIONAL; case IIO_RESISTANCE: - return bme680_read_gas(data, val); + ret = bme680_read_gas(data, &chan_val); + if (ret) + return ret; + + *val = chan_val; + return IIO_VAL_INT; default: return -EINVAL; } From patchwork Mon Oct 21 19:53: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: 13844592 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.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 6B8C01FE0F8; Mon, 21 Oct 2024 19:53:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540421; cv=none; b=iXPsSa/qv715tD9NeCcL+tizCPU7U/wTV8bEZUKcumgxEFsbOcot1XtJ1Uv7ZgBgtj1ukkLZ0MdwVpKztzkPrbvmoJeSyhXYo9Vp/16L3S4BoPN5U2bvid42S+53y5Gmtmx3cz3fiTApO/ZU3U6kOHnd1i4dQcepeORW+frQNRs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540421; c=relaxed/simple; bh=0gNsWS5mdan6YA0Yx4uRI+D/q95UpinMQTo4fP7TfpY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EQBB5DUEHyD+UUZ3d6cc8i3hY1c0waY/odkw17VG1ycpaSyVs9tFofhKSvNhEC3GrEDaOnF/ISlAn3JCp7n9jH/RLa/yus+55vCFGNaTiDiCxNGHZRo0MZ2CWFIvYucjjFfWYMOzwoRtP/U+5IjNyiB/KIuSG336gpI1JmhoyWk= 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=HOuriq22; arc=none smtp.client-ip=209.85.208.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="HOuriq22" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-5c94c4ad9d8so6309985a12.2; Mon, 21 Oct 2024 12:53:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729540418; x=1730145218; 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=N2kngOOnzpWjdddsQOkA3a+2iH1yfArg1N3g/ZRWe80=; b=HOuriq22xXmJqRNEw72iISlpfNgbBCtGNbuVOHvLunUvrsmWHq9aeyjepYBbN40e6X yULYTtF8hPM0OKS11o1QmQ3+eIE1Yh/dBIiTXOfbBdpYjraAeyDUafmE6kpEE1adb29M vdnQCX10T49X/fagrVlZQKY/D4F/6JfW7TWLM4/zpcB+OFO+Mi5xsUS82pgFUGCKKYFO Ng6J9SpT/cxciWWOEObTOCLXnj0vlqBQ49XMTAF90HYXZQ7U0StrXZuDLhLKZcDzP4i8 XHr2OHZb5bWjgAX+yaDZfgU8R9iMZOOuIzdOA+VE5kOBMtA94tRP/fDJf+XJQCNdg6LT pk2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729540418; x=1730145218; 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=N2kngOOnzpWjdddsQOkA3a+2iH1yfArg1N3g/ZRWe80=; b=i5D5fQ6Gq+yIbkzbcjLqqL90agwU5Xi47Cm/n372ew5+GfaJdABElYbgBfuLdgUVmA 1pgnK9s9xQS7FXIekIMAXFfItt2NvzFyjSMZGlGP9BUagFOqXHOQE92qBwBCQ1z2OB7E 1irC+DpgN9Dsa/CYeszSXzk9WuMxDdpmoahfOtpJ/NJRMAEvonMhzyiJprEDQdcQYcRB 3oC7Jf2wzAOnuCfmeCaGuVvQjLEOmi9bs+SwCymgccoscFLMEHnyecnnpdqks4w8RYxX Ux68LDjxd5WtZLdQofppdH06hzsOT4ysHYh1NQWFQM3WCC3P/tgerHoqS95hhTMtX5w3 bQeQ== X-Forwarded-Encrypted: i=1; AJvYcCUXEej9/T5aAerzgWlLuYA0+ryjtmo42OkpyZ2BcQ4/3K09ieI2aIg9rmj5EyWnhV5BCj4urNNH1fvhAcbq@vger.kernel.org, AJvYcCWIHxJM+OPPydv5/SQNnlMgKpv0MVLQfYyQFXBSBIfShoVhUmN/pmyx7Pyf8aFhv9lo63Pajwzo2tUI@vger.kernel.org, AJvYcCWxsjENCVKUxLXu2swxdXYTGJEz0UrmLzvPMMka/UsRZaZl5ZWcPtGyIKPWMxwHPsjpKbRcJMGcXx1G@vger.kernel.org X-Gm-Message-State: AOJu0YyYv8fKNjgeff/ceg55VJtXvNS1zsUAQWhgUQaV3oG02ajdpkxM AWdI2cNFzfM75fVxgjsMcONTmDAR2ICgECipcqptpF1a/lagbIGVMjq0RA== X-Google-Smtp-Source: AGHT+IGUMoXDwNLIySvBaN/OKHO2CpdxKys3ZpuZfub/Gl3Ae4H0AHskSzUo5jURp2ZKTvcRohGGsw== X-Received: by 2002:a05:6402:4403:b0:5c9:7dd9:3eda with SMTP id 4fb4d7f45d1cf-5cb7fcd8c18mr82328a12.5.1729540417501; Mon, 21 Oct 2024 12:53:37 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:9cf6:f1e5:ce2b:ea6b]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-5cb66c6b12dsm2338702a12.77.2024.10.21.12.53.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 12:53:37 -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 v2 08/13] iio: chemical: bme680: Add SCALE and RAW channels Date: Mon, 21 Oct 2024 21:53:11 +0200 Message-ID: <20241021195316.58911-9-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241021195316.58911-1-vassilisamir@gmail.com> References: <20241021195316.58911-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 c79ba6d1ece8..e8098754a85f 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -143,17 +143,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), }, { @@ -785,6 +794,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 Mon Oct 21 19:53:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13844593 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 7B30A1FEFA5; Mon, 21 Oct 2024 19:53:41 +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=1729540423; cv=none; b=MwSDLy/Ru1pq21Tqj6Ndmqp4tFEN13hODgX+dzEd1KzeMcNVT8rdQ2iitWR+18Bi3JGOV5JO2pUtOAT0N7p2EMyGja5DqP8JpqpieFN6kkU2xFp0w60zalgEVjumSzZOMmDjwTaV1lEitEzE8TRxlO8jHZGS3NfAuS9JYAN68ok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540423; c=relaxed/simple; bh=oqS/CWlkq1CAqDRmK9a4lGF4lA0kvg0ZX9DDaiRvWPg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VyQ+IUQi5SOdYpRYT9JSiJxdKR/9F8/7tguo9oeg0ob0iHhTSPV+35sVSYHbiT/FNTTsXCDiza34iWQJYe5VXn1XN7f0HNZXYdeWYQohh3XKMMh/ip6t8TlPNfwMIisTiXMHEn7YFyGdXmimYRq6g6WNjYNlgPyi/kTZ+MD6XfI= 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=KY4tN9Sl; 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="KY4tN9Sl" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-37d6ff1cbe1so3773109f8f.3; Mon, 21 Oct 2024 12:53:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729540420; x=1730145220; 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=2AgVYWAOh4OZE6jDzhMNTVLWtFaiOvfGB5liHZ7UsGg=; b=KY4tN9SlfKkds2vrgSm61eE+2WUQqqTlMtX1vC125D5HoCEhUjso/EE2l/iPKp6QyU wBy0ax11a65a8FornLwj7lg7AJRkZDlzMk8Z0siEuFa3cBL9UrxUeTMwX6FjhohjuSjS /CesBrV0oj9FCefXxHtrqSDgKCSouQ0B/x+jLJnU7ftpTW+GYXA/6XcCTZnSrCYsshsg CKjq97234b/NNcfgwt8Jejn/ZKI3j/5rBX5roND+iep99Qoj9qMG5segykrr7bYHSW0J 647SfDk0Ex0lc5YbwAbEPmEJ4H7Ck2V76QtINfsfYcRrBvcqbok9fu/3Wze//vvUumCD hNQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729540420; x=1730145220; 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=2AgVYWAOh4OZE6jDzhMNTVLWtFaiOvfGB5liHZ7UsGg=; b=tt3fNoGE2J9ul1OtcgDT2eu65v/7jp1vEpOSYkQoA0ShbuePQ3Sh+hmQpiec3DN3K/ xbFQU1tVOs4aYMuRbSfNokbWtp++X1WXt+R9uJENlSLB5gB0GbAfMtkRdaCygWlRGcWr 6g03v6Z6R/O0YlxDATVrwPdGYCRj7x8EAU57j3w7YvTX9k5Z1Q3LVS6wTPqN7P5lkFQw Xx9jU7suPrV9siFKgMQ05BnWRzWnUWJCfc/fpCHkV+iKEFWQ2Gl1+wKoOWpI0m5Ga5Po 7En8O9PZSucS64B6F+CIuoLtgecxbSwPVXI3K6P6PxSEZJ6zK4MJePyfZRLrfUtzKHWp DiUw== X-Forwarded-Encrypted: i=1; AJvYcCWNoe0gpVNXIPuX/6pzXv1+/+dW8ynjGFblOR5zNoWfpXkBoz+XQ7tfUYR8V437fppPXFR7yo92I3iV@vger.kernel.org, AJvYcCWdfViRatt6GnXUH5st6aGQc3TdtBcOiW0XExOpdQ92KdM80A3tGDr+z1M4+4XQGY0/QF2FgXjUCElLZuX8@vger.kernel.org, AJvYcCXKkiyQZ/VYJpU+Mq9M8quEiiDbmZOvv7W0Tvnis4mT7ZCOckh/MGQY5c00VkYRfY5M3qrNNiLOWiT5@vger.kernel.org X-Gm-Message-State: AOJu0YxbNuoHUQcpfzjQ3hNbta00zPQu7+Gd6OiyvbvMCvPAdq+1u9Kk lVS9NYzXmEnUnFNaUmfehREf2j//e3FKGz9HxsfzQelLwap6K4hf X-Google-Smtp-Source: AGHT+IEk3AOkFtkTJM3iIZPPQ5GO2ijKd1TbSZS8qM6BzW+q4A6HmEM7X075sRP6IG1pdCR3dR0yGg== X-Received: by 2002:a5d:504c:0:b0:37d:4e5:bac7 with SMTP id ffacd0b85a97d-37ef2133c1bmr169506f8f.11.1729540419679; Mon, 21 Oct 2024 12:53:39 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:9cf6:f1e5:ce2b:ea6b]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-5cb66c6b12dsm2338702a12.77.2024.10.21.12.53.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 12:53:38 -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 v2 09/13] iio: chemical: bme680: Add triggered buffer support Date: Mon, 21 Oct 2024 21:53:12 +0200 Message-ID: <20241021195316.58911-10-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241021195316.58911-1-vassilisamir@gmail.com> References: <20241021195316.58911-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 678a6adb9a75..447b205f57bd 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 f5be4516dde7..574877bc51c5 100644 --- a/drivers/iio/chemical/bme680.h +++ b/drivers/iio/chemical/bme680.h @@ -68,6 +68,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 e8098754a85f..7bf4daa35ba5 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 @@ -100,6 +103,13 @@ enum bme680_op_mode { BME680_FORCED, }; +enum bme680_scan { + BME680_TEMP, + BME680_PRESS, + BME680_HUMID, + BME680_GAS, +}; + struct bme680_data { struct regmap *regmap; struct bme680_calib bme680; @@ -110,8 +120,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]; @@ -148,6 +163,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, @@ -156,6 +178,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, @@ -164,11 +193,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, @@ -918,6 +962,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_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) { @@ -936,6 +1062,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; @@ -978,6 +1105,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 Mon Oct 21 19:53:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13844594 Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) (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 270771FEFBB; Mon, 21 Oct 2024 19:53:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540425; cv=none; b=S6UmMbNRHw0Q44AMMHE1u5EbP7oFk9dk1qVqnnfygn2bJPHDCG/Tm0m4Za2khxAGO7RFtZEEj6UdWRuTltOFqn0MBCmda9EMzDTr7SApV/Nk5L0s1//Yk3RUzAQv99MBcCrjDmhXvIaC5OlsouwNHv1ANg4jbHpaRg0tTAmUrUc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540425; c=relaxed/simple; bh=WMn2eYkD1TDSeknpCBtf1al8/6YBl+fbIaLWQn8dlHM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dIhhzt/qG+PTnfJw6zjK18ekUAYpPq1TLXfSjnMVKz7JXmIlgSGZbuJbr1kUFbgQ9gaOw1gO908EeoqT/UOru7o7BYAVEVCMYRv6dyxOgNN6MXTExKxr2HaPT8z+1UPm7EeT3QlxQR7LCWsx2Evs3bNsJZ/AFkAGH/x/EmmewPY= 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=Dm875eeF; arc=none smtp.client-ip=209.85.208.176 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="Dm875eeF" Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2fb51f39394so51032381fa.2; Mon, 21 Oct 2024 12:53:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729540421; x=1730145221; 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=0YnjJ8/zhtnYop/8ZDBf7vSXapFQNrBGViVFS5PeYFY=; b=Dm875eeFNA0Gi3Kq6iYiH5oT8chBnU+wWX2tAgi3UCxfunXL+ZTc/Mu2LI5NSMpCvC abR6ktkELeOsA02O7KEwuIdb0qMO1sIJyqXyo2ze6CipZfGtJ4Mw/aMYTmmDQvsYqVeD VBCiSA7K5WER0XcfNuUN8VYTEMWgEUykg25J0+AIZ/sz4gat3YKuqML+uyocIHgMGl2q 0du22kkFjnFNKkqDodeRod+0WRSBlLO/pSY90c+6YY7pS6Dk7UoJ21niStzMMzJpzVhE nUkyxr8lNHK7o/PtUoGOIC85aFOVMHzEqUaNGmWqwrOxDgagj1fMkoF0VA7ONzm8zuqo cxNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729540421; x=1730145221; 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=0YnjJ8/zhtnYop/8ZDBf7vSXapFQNrBGViVFS5PeYFY=; b=VhVL24r6m8f9CmKHbq74+9JzEWSvCEyUuLv3VVt0SkkAL9Ck7s64oBkwhxvho1p/RO Cdiu5UQRtywpeYPEzpuI/14YCPfu6dBeK9iIxHE9xnAUFMp9LAGKf8q32x/n6NsA9CWn gqRu0PXB/kCNh4Oxn0CCXvXzT3hDwoRAUyGSkn8Zon230I+kxjM+LCnIaL/EU7xG9Z6Q ORF4lTDRXdHuHvBxxz5VBEdxlliygzn+kYdX4zHyA20/9eaKvJPeIkw9Hb7tvxVQ5pVp dt5Q7RJjPUkNsA4C5YBie5yKQadrqwrwGe50kwyCys/4BC7KTVbm/2EYPfSpSZxzKI15 fNXA== X-Forwarded-Encrypted: i=1; AJvYcCVK4FLE5mmOfHb1jemcq8M3uLO9ultWVv6zCvwvsDKpOmeGqPaT7y7mFTLk9HWN8Rp3vHZyrxTanIJM@vger.kernel.org, AJvYcCW56jHBColic6P/jhOxlsT2o1fbgYEl35VGnyqWQHkrO+phgTM8QGcAd7Hh2jNlViFDuxPb8NnVPgaSpEaZ@vger.kernel.org, AJvYcCXyMpdb0DEHz44PC3wpp0u5Zo0XdyE6W2A9e0SENGnOfZrA2aTHcITMIIuTWdTU3h3+meU+zTZB516P@vger.kernel.org X-Gm-Message-State: AOJu0YyuA3fDj6UJ8q2pA4A8BujKt99uMmx57gCHGjlh+JWGyCx5wP6Q wGFmeOkMJElt+F75WvWFYsvGyOTUMp2i++8hfeO8nQcMPm0UXwm1 X-Google-Smtp-Source: AGHT+IHYinGx1REj6CM7N5rlymBC2ErBoX16/znp7FVMGsk6Z19Jx4XLJfXy4qBZJmrdOKK7OGaA+g== X-Received: by 2002:a2e:be22:0:b0:2fb:5014:c963 with SMTP id 38308e7fff4ca-2fb82eb03damr60889371fa.20.1729540420954; Mon, 21 Oct 2024 12:53:40 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:9cf6:f1e5:ce2b:ea6b]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-5cb66c6b12dsm2338702a12.77.2024.10.21.12.53.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 12:53:40 -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 v2 10/13] iio: chemical: bme680: Add support for preheat current Date: Mon, 21 Oct 2024 21:53:13 +0200 Message-ID: <20241021195316.58911-11-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241021195316.58911-1-vassilisamir@gmail.com> References: <20241021195316.58911-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 574877bc51c5..e5d82a6d5b59 100644 --- a/drivers/iio/chemical/bme680.h +++ b/drivers/iio/chemical/bme680.h @@ -44,6 +44,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 7bf4daa35ba5..8c80a5f1ef9e 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -117,6 +117,7 @@ struct bme680_data { u8 oversampling_temp; u8 oversampling_press; u8 oversampling_humid; + u8 preheat_curr_mA; u16 heater_dur; u16 heater_temp; @@ -213,6 +214,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, @@ -560,6 +567,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); @@ -658,6 +671,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); @@ -686,6 +713,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, @@ -937,6 +968,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; } @@ -1072,6 +1112,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 Mon Oct 21 19:53:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13844595 Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (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 D88B51DE8A8; Mon, 21 Oct 2024 19:53:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540425; cv=none; b=ica+tsKLX/veeVE6u6JHo4x3tp+Ij2RmJ02MNULh5pAsowI5moQlBJO9azZgRghcaOWB5c65AJGPXz/aM40UD3U6gNGSCwk2+O0jx4CSgJIQXBf4j6zF7XCIlGleEpPNgvWRqXrRC2FDQ+sQoXq6x0sM9evhTFwlIt8mLnsw6Ck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540425; c=relaxed/simple; bh=HuRrGvLfUNfkAK5g4HYaKiG55r68O+ccWYCmax6cs7A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k4+wtlDZ7b+vixaofyYauvLYXBa3VQUenhy9uCxjiA6I61d4Qk8DxgD45neZqqAEFc8gIJMm20ZPzDSChmE6PooBdb2j86DXkFkwzTWp3BGTyBuUOHWuYPNIbT7T0hBHpn1gggejF40ckM5nsCgrSILag/GOAFSo5+jyhGsMbio= 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=DYOq1kEQ; arc=none smtp.client-ip=209.85.208.45 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="DYOq1kEQ" Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-5c9552d02e6so6172073a12.2; Mon, 21 Oct 2024 12:53:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729540422; x=1730145222; 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=yiDiHoQKEX2h2gMZ6AYiTcdgVDx/hK9ufvUgR+J5zhg=; b=DYOq1kEQJJ4WVKxPx0e5MqdH42Y/bhszQTmQPIz5l6E+wQL477g9x+AXY0I0DYRwUG Cd5qxOUzN81P6AVtQ8Q2O1XP3g6+q/QlIO01HdJZ3iswXsIkloMBeEAn3j38NxadFM+f NqPspXBzSQ3M3HZzC+wbFlSCxcy9xDj4EJZNT723XSGWHR2VtNNJCOGPEiymCxwyXzsv ehYs+rgt1rEkfxSrqWfzVVxs4Fc8DhKEeaW97OI8U+bPi7lz/94V47b1QaRidJ/LXkVZ XYa7qfrE/fJWI0Znp+vEKfBzvo2t+Q+r77DgRqzrW//7cgJLwIexaq1CIK6XIa2Xcx2t sfFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729540422; x=1730145222; 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=yiDiHoQKEX2h2gMZ6AYiTcdgVDx/hK9ufvUgR+J5zhg=; b=KEuTWVX+pDREi2lzw0xP/Ud1cG1cAQStfNaDYznUii5wY1f8BkNt1Ui0wy0H7haeGr YS2PGrKi/OeA15FEmbpLCDR0w9kgi80wDb6XojuT9b4tf5B57nHEX6x+QwnQpMxBJpxI ANuyFjAx32Z435d0LamMmklK8qmcvyYlazaZ7BvbDjgryXQmlRxIthMT43PdIRow2zb1 5pdgt6nqF5ePhPNA/anew3zcAQKEo59O8/1BtG90JG/Hoe+gTlcvd39ZI2SX63olzVbT QTmQSPSXd+hoQwwa1XHfGbr6hmY/YadAGHZQ6Atp6om/vjOoWkzoy/wqcICRYtPICOkT X9qw== X-Forwarded-Encrypted: i=1; AJvYcCUe41BQHw4Lb6WBC9ZGerNuQHeidCQAHItThzdv9xNNj8t7ywUFyG1Z64RyQSkoqgmRwRLMTXQ78WfXuVIO@vger.kernel.org, AJvYcCW5rflwdaqiyQKjrnaKV1SyIGRQQ/ilKqPvfj6/tncQwtBmwFyfSS7geWVsJKdhiEb+wSMHTonYYR16@vger.kernel.org, AJvYcCXYmvIk86oTAYJL4ySDL6ZORLjsiW0GTGsfTc/o3Yw8nwtuh6Jwwu2NcN8W8zkLkUZVhGT5aA89Rk+k@vger.kernel.org X-Gm-Message-State: AOJu0Yx6nvrzbiynIRLKQ+j0YnNU75M+FqcUPb71RJSgegyjs4MmIkOt kjtHUtLOD2WGaAtjzQwrsqvb4v61orth8sAiuwO1zVl7e6njp4YdFMoxzg== X-Google-Smtp-Source: AGHT+IGZ3G6tkdAZXdOQVSnMdBgIlCvNW0HxUJpss8n0EtF7X5UP6Futk+URaFkK8drWShm5ByfY6Q== X-Received: by 2002:a05:6402:2313:b0:5c9:6eea:8e06 with SMTP id 4fb4d7f45d1cf-5ca0ae87e13mr9153927a12.24.1729540422010; Mon, 21 Oct 2024 12:53:42 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:9cf6:f1e5:ce2b:ea6b]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-5cb66c6b12dsm2338702a12.77.2024.10.21.12.53.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 12:53:41 -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 v2 11/13] dt-bindings: iio: add binding for BME680 driver Date: Mon, 21 Oct 2024 21:53:14 +0200 Message-ID: <20241021195316.58911-12-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241021195316.58911-1-vassilisamir@gmail.com> References: <20241021195316.58911-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 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 | 64 +++++++++++++++++++ .../devicetree/bindings/trivial-devices.yaml | 2 - 2 files changed, 64 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..e54df3afa7b2 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/chemical/bosch,bme680.yaml @@ -0,0 +1,64 @@ +# 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 + - vdd-supply + - vddio-supply + +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 0108d7507215..3d9c08ed7bce 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 Mon Oct 21 19:53:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13844596 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.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 769BE1FF03F; Mon, 21 Oct 2024 19:53:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540428; cv=none; b=relvCewhdgLOgzYWbWI8C5/OZv9VAZIEW9/ZV3WhSgOPs3Bx0u7wiQifOWWzkBazWXmgbmfFzdoAenX7fBuT9oQ1x6zAvsvcHgq1SzxwmGaaIbz0YChEx4/mOW09OrMKZOVX+hwb1uSNJbaf0vaNmPatnyKiWZNro37HJRZPjbs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540428; c=relaxed/simple; bh=Iv1qVeHWsnGwCkKp4JfXyhKcEjlk1L71tw7kBPDfmW8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EMKF6WGbknTcgfir60Dwdf8U21Lk1dgbI5NUekHFa7u16e5Zu34Wt8NQFlaFZjz3wG6UfkXnmEVhCwYYrMbV9D2WlgoR4pkAREiaBIrLuSCyFlpHpDSrwPKA0BJM8nYy+WSFMDZHCHVlL6ePoHMhmvO2KyvH60sKcNZxWjxRGQ0= 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=ZgSLa9UP; arc=none smtp.client-ip=209.85.167.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="ZgSLa9UP" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-539f84907caso5516286e87.3; Mon, 21 Oct 2024 12:53:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729540424; x=1730145224; 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=N7S9rQla1y9kYh7NcqnpT6la+7XaYudbdijz15z2RK4=; b=ZgSLa9UPNEW7QvY3GE8dqxaz9qILZCv5Y6pXGszUphTyDAneXamETHZQib9LFRnjiG 6R8l6N7vhI1/O2TgCy5V4Nvz5T9tvVgsjCjKfXbHdXDXOjxnJRiiBWJQqyfCUjE+ra7O NIoaYFHfLB1icR3UzkGKeqISt57M7fJHdvlgWnfoqsGnD5C+6I20duTZlw+aLOZ5kJCf jLv/IZ6jHL38nFcrKmUK1f1vc4i8bcZxk89H8JR6VfPSIxWXQQ+HuxOszxQJ6PWknu97 qupOTa2dlVG38BoiRHXaVqphYkDWpWWNAXpsYdz0cjvk8xh7KrCIFiwxeuamxAWmacZD BGlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729540425; x=1730145225; 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=N7S9rQla1y9kYh7NcqnpT6la+7XaYudbdijz15z2RK4=; b=dbvErmFyH8j4lN13hDSRGMF0G8YP0r1c3wws7QsBXIwM9HxcN4E3bUwtPYkIhlcpMS u/F7YXVo4+IAHzXsHD8Pr4uA/XF9oLa4xBrspMd1+Fmxv4Lk3ei0sKyVa3aur/f/IpQj 9k4ZmpJUxnULFeZNtit/vQitkOQoHF25LLQRSYa+FP4mUITQZON/BXItYUY8+l1RBs/z t8g8o4nrvskCroltulIvD2D30H93T+m3dL7wH3N0WEkvtbCHswLfoj2YUQVWE6Ur6uTY ZQdRlFainu/p8e4gOZKQDr/D08aZBaw74vD7slkXP+AqtiD4SS0gmhKepEx32W7rNZTA UuRw== X-Forwarded-Encrypted: i=1; AJvYcCU+hdMeRBNGYps8vc5A/oNy5epEpJi2VZCbQR1zM7OCypkta72OeNHTuX6r2fnVfb+S4Bp0A7OyY/UC@vger.kernel.org, AJvYcCWJ+E58xRug0PwLsVN2+st7xsn+TlTvaD5iqKz3d4dwx4H+DtRKnSUpeoVnFt0deT1T5fbK5sj6LYTf@vger.kernel.org, AJvYcCWeKf1BzfLHGFj/tXF44SFCzu3ggPkuaC8cJZ0RV9emwKX4IEbosaSPRxdws14OqcFxvjLFXQXGu3w7HN96@vger.kernel.org X-Gm-Message-State: AOJu0Yzd17nnOPHpmLR5DGkCp8QCxp7FAR7je/8bj+HNvPjKX243d2YS LAQaqzV0i5my7CqNjOmGhmGHEjzYgw7GfTw9rmyk1QuRXwflr4L6 X-Google-Smtp-Source: AGHT+IEIPVVkuMV4TTd4zpUQBME0OL0V+C1tdauapDgdNByMAL8QgfDQfJGVgGhMQ0zoVTL4Qqmp8w== X-Received: by 2002:a05:6512:3d05:b0:53a:16b:f14f with SMTP id 2adb3069b0e04-53a152193abmr6281588e87.19.1729540424350; Mon, 21 Oct 2024 12:53:44 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:9cf6:f1e5:ce2b:ea6b]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-5cb66c6b12dsm2338702a12.77.2024.10.21.12.53.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 12:53:43 -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 v2 12/13] iio: chemical: bme680: add regulators Date: Mon, 21 Oct 2024 21:53:15 +0200 Message-ID: <20241021195316.58911-13-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241021195316.58911-1-vassilisamir@gmail.com> References: <20241021195316.58911-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 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c index 8c80a5f1ef9e..2d9d20f203aa 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 @@ -110,6 +111,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; @@ -121,6 +126,8 @@ struct bme680_data { u16 heater_dur; u16 heater_temp; + struct regulator_bulk_data supplies[BME680_NUM_SUPPLIES]; + struct { s32 chan[4]; aligned_s64 ts; @@ -1114,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 Mon Oct 21 19:53:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13844597 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E1CB1FF60F; Mon, 21 Oct 2024 19:53:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540430; cv=none; b=CY75RzZWvoZgffRgoeF1EU2LX73BRRHZDiQYrzMQ9QlN4Lyj+/NOf3RjO4KvYdTG59zCSbxDP1id0UnNBnriklaZWrYm/Z2qoDzSl5zQ8wK9Jm+6xuHdAfhLCrWe8Q8vEMh73r3lKUD5dG3ttrURjqNMQ9SFzxD3Zydec1xUp0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729540430; c=relaxed/simple; bh=ir/Bq8Lb5t5AQjSoKh6DEHHLB/egS69QJTdjSonWAMI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i1WWLaHob4eiQGdBWCUwpgsMLxjqJd5SN9kH67p+QEPNlG58+PTw6SCZPdp90MFn8BvO0e8dsEtFlVqLkKH8Yx3ig+F36+Z8EJq9BjVRNmORnxcmTGWBDK8Yyf+PT64N1G6wKzL8sfQgtuolZM3TetCsHDine+5SirwDjqUMb5Q= 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=YtNGBkUk; arc=none smtp.client-ip=209.85.208.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="YtNGBkUk" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-5c9404c0d50so4962945a12.3; Mon, 21 Oct 2024 12:53:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729540427; x=1730145227; 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=7uZsh6bS907gxcHV3Ix/1vvyLEzvTd1yKdYjYRuiPt4=; b=YtNGBkUkVodjjEYtcQf50Vz7k907dTVMYStC/dqDR2vxXLcJDKJkzDehDFlSaOtIpW jNAcnVr4ymp0YKzEUGUGXgcFTY6R2v5ZEWNNdGK9GNnR2NWMvaTe9pc8DYXQFwAJ36yJ p/XUhT7h2gEp8ZTxKjSJU0eW8lBZoQukeTY3QxLt2uxrHlj1rayDtSc3eypAOjASpBcD oQAQSF8emXCLLWf9m68xeaNGYwnzMXih20wII4oYJOh0RcX9Bh1yuao5GYTDUqdWPKiT OjQfZcPFBh9WLRcx3bBKTomJZ/0RUV1/fK0e4nQBuixkmmg2lmoOtCcPnOSeI6IToc8r lrIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729540427; x=1730145227; 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=7uZsh6bS907gxcHV3Ix/1vvyLEzvTd1yKdYjYRuiPt4=; b=eY+1Y2NAfWCsVCejLBz9QgmWBYcnsh/KkkZ+BPxy4zy+yU0A2OyONky5hsPMM9T1nW fQiC0yNTKYh4C9OawqffMTfg3pe4R5jkxQK4Z91aOGq4qHsSQuFdZnbY+9OwXD7WmHQO TlmbYqO5+pts0YsV9fmP8EqPmE5T7mWQFGoSJAXxAscFnYw1IL8pQ4TLbWFxnaURSSDs 68c+dMA6sHRgUGWp+Cbn+mNXrf7gR1DQj+bI5gEwXn72kVNsww29qwR2GCOPjsXHp1/L qW9GihtCdz3nlYvhZpzyyRAinJqTk+OytulxBlhoX4M0qE5ZydB1+MlmzMzrmwnlYAy2 vVJQ== X-Forwarded-Encrypted: i=1; AJvYcCUgO6KJPOz00d/VQ2m9f9+fSciV2oKWcsYIvCVzy3iCpsz6atxnojx5LqriactQO4Xm38PR01svVynCmwcs@vger.kernel.org, AJvYcCVym8RLd+Sy9GZEU30L8ntRir42d6H1MCBtoArGiG/XG68crJ3C1q/32DTTQaGIza4e1fksBw9sVsSE@vger.kernel.org, AJvYcCX5Lq+W/niPkoarEjUsQEPMfbfz6WBRpAnjZ77fkj4cuhF3eKs5/xjj1isIuO2v7NHFiswVPlkBUXQS@vger.kernel.org X-Gm-Message-State: AOJu0YzyJUevhFoIH40X9ZxbexlavhtJ2qX08gM9WE0EDukt1au2FsG7 QhuDqLJv2XGhlwAKwUhwheDBou4Pr0BczpLsGFaKWDMJUZ1wZ0H3 X-Google-Smtp-Source: AGHT+IH7Y1XsktRICQK0ugPMuzy6DYxdiopCFaD26zm8aWrwnm4IuC31cQcFO0QYcwOk2i0AOCpD/A== X-Received: by 2002:a05:6402:440c:b0:5ca:db8:8cd with SMTP id 4fb4d7f45d1cf-5ca0db80a5fmr10977051a12.20.1729540427076; Mon, 21 Oct 2024 12:53:47 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:9cf6:f1e5:ce2b:ea6b]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-5cb66c6b12dsm2338702a12.77.2024.10.21.12.53.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 12:53:45 -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 v2 13/13] iio: chemical: bme680: add power management Date: Mon, 21 Oct 2024 21:53:16 +0200 Message-ID: <20241021195316.58911-14-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241021195316.58911-1-vassilisamir@gmail.com> References: <20241021195316.58911-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. To facilitate this, add also a struct dev* inside the bme680_data structure to have the device accesible from the data structure. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680.h | 2 + drivers/iio/chemical/bme680_core.c | 126 +++++++++++++++++++++++++++-- 2 files changed, 121 insertions(+), 7 deletions(-) diff --git a/drivers/iio/chemical/bme680.h b/drivers/iio/chemical/bme680.h index e5d82a6d5b59..74e97e35e35a 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 @@ -82,6 +83,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 2d9d20f203aa..803aa4f14b37 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 @@ -823,9 +825,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,39 @@ 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, +}; + +static void bme680_pm_disable(void *data) +{ + struct device *dev = data; + + pm_runtime_get_sync(dev); + pm_runtime_put_noidle(dev); + pm_runtime_disable(dev); +} + int bme680_core_probe(struct device *dev, struct regmap *regmap, const char *name) { @@ -1164,15 +1231,60 @@ 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_get_noresume(dev); + pm_runtime_set_autosuspend_delay(dev, BME680_STARTUP_TIME_US * 100); + pm_runtime_use_autosuspend(dev); + pm_runtime_set_active(dev); + ret = devm_pm_runtime_enable(dev); + if (ret) + return ret; + + pm_runtime_put(dev); + + ret = devm_add_action_or_reset(dev, bme680_pm_disable, 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 regulator_bulk_disable(BME680_NUM_SUPPLIES, data->supplies); +} + +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 = regulator_bulk_enable(BME680_NUM_SUPPLIES, data->supplies); + if (ret) + return ret; + + fsleep(BME680_STARTUP_TIME_US); + + 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");