From patchwork Thu Jul 11 21:15:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13731069 Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (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 3F24C770E6; Thu, 11 Jul 2024 21:16:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720732582; cv=none; b=boilFn7r/ez0Btkmptud/IugiGcjIArIA3UHWywTK9/5/ccz1TbMZKuL2HLSVFykQHRPoGQ4R7PdjVFXIx0Bf1/TK7XQpl1QZg8ELJtQCKPg+xB+WxtvOMyxZ5c5Go6voRmyl/jzMBsbC8w/o4F2eWkJ6Mx0ve5inXw/2tA7yuw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720732582; c=relaxed/simple; bh=Rwdi6Q9D/I6KXmAJBUQzkxRoJWu0Llv7++pHrz2iMhg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pk0wZ/TEgkwhBwa9hNMHueNDb2i0jF47No0sCbrOqTNGf41brqbZ4UeMhdId32SmZnDX4zPDB/fgpQPgEnumgsQLLioalth4RTWV9w9rcACjzoEpSvfmqcY2Ql0SpmNSl4HYdLsVTP1fdHK/M/snYXHfK5DjPbEIann7ZhyEDp4= 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=de05rCpV; arc=none smtp.client-ip=209.85.208.181 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="de05rCpV" Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2ebed33cb65so18238711fa.2; Thu, 11 Jul 2024 14:16:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720732578; x=1721337378; 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=h9nzgbT0FGdXa+0/Jx/FoO1y5bmb3p3axOlg8rQy+GA=; b=de05rCpV9AGdmzUt/hrrVI9UTgcLOvUokLiS0L6M9WswtjZdCTgQAOWbHh7b+KDzja Ncx0Y+JyBQzsLVld9iFM/NzvnbzF7UY1JaqUVoJJgUloLLxLqELw/2IcRfppM0joxCaF PetrkVpZwVaPr5stX8GhSktGlazSMJ701jmSb95sQ/gw0TY3UeA58zHWdG1xj0C8oVy7 xior/sZMbAopyNUfKwyl0BMjWznAt/fS7XqOBae1iB8UKpuKDc8VdkyGnqr9aGma+Xz+ gxqXXg6QF9JwHLOXruPQJ0BBQf/fceZfMLiuKSnv1ONFUTUT9877wE8CftMRxix+70Fw 4aEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720732578; x=1721337378; 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=h9nzgbT0FGdXa+0/Jx/FoO1y5bmb3p3axOlg8rQy+GA=; b=eao3arxXlVEpWS8l4WKkPoDErI+93XZavdvMgMWKGOMfBvdnd1iD/Y75FhtS/EvKcR n6G5RAmHmoqjdVJc+szDaxuw7PZIB1LSRmLjXW9jEB4Zn/bqgai4FYFtL/ouoFTZfXEu vk0oofvPEDpFU41qvVajrdhHsrh33tCJNGZuEuHe1kbJ0gv/QNbUvJFmpCTBGrcZtSjg kBqgw7/Ufl2IQF7MVRmg4ObOqushZMVzoYIl81btLrPhc8EFEPTifhLb6pMhZPuYFcUx eoXWxO8JtxLdaYTZZRisgseQKlHkPF8ix0Ue0ezmTgcaiZjtX7h+bcYG6VhGmWMkvVZ7 nBjA== X-Forwarded-Encrypted: i=1; AJvYcCVZQLbXRMWTWnNPx7Rix+RiFFLl7paRWvz1gTltB6VoYiMhbttAvF/UuHNeGBVShFNBMH8oRldGByrEzIGoNjtZbLmbBXimUQvmxOG3Nu8IKcsVw0EkrYlT9drhilEXe5WkbK6CNWY8wTfw95M6irt2+I+ciJURDHeL+F3GhwHYs/b05A== X-Gm-Message-State: AOJu0YzZIfhr54R8e5Bt5wwrN6Kj4kcGpN1bJIrxYCFo2xk2AtWdrwpn MOQhZpkNzKs93rHjnGHRDpfewoZUzCsKnJQ11TQSyyIApsryYXF+ X-Google-Smtp-Source: AGHT+IEbD49X4NpzCy3qwikcrZ+FoIhWYVb1Yw6YPmcCJQ0KCme3Qfs7oMTtOuTsOYNIzKuTSgT8xA== X-Received: by 2002:a2e:b0d8:0:b0:2ec:53a9:2037 with SMTP id 38308e7fff4ca-2eeb31887d7mr62051581fa.37.1720732578082; Thu, 11 Jul 2024 14:16:18 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:3e02:47b2:c845:ae3a]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-594bd45a1b6sm3815737a12.60.2024.07.11.14.16.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 14:16:17 -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, ang.iglesiasg@gmail.com, linus.walleij@linaro.org, biju.das.jz@bp.renesas.com, javier.carrasco.cruz@gmail.com, semen.protsenko@linaro.org, 579lpy@gmail.com, ak@it-klinger.de, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 01/10] iio: pressure: bmp280: Fix regmap for BMP280 device Date: Thu, 11 Jul 2024 23:15:49 +0200 Message-Id: <20240711211558.106327-2-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240711211558.106327-1-vassilisamir@gmail.com> References: <20240711211558.106327-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Up to now, the BMP280 device is using the regmap of the BME280 which has registers that exist only in the BME280 device. Fixes: 14e8015f8569 ("iio: pressure: bmp280: split driver in logical parts") Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-core.c | 2 +- drivers/iio/pressure/bmp280-regmap.c | 45 ++++++++++++++++++++++++++-- drivers/iio/pressure/bmp280.h | 1 + 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 2fc5724196e3..cc8553177977 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -1186,7 +1186,7 @@ const struct bmp280_chip_info bme280_chip_info = { .id_reg = BMP280_REG_ID, .chip_id = bme280_chip_ids, .num_chip_id = ARRAY_SIZE(bme280_chip_ids), - .regmap_config = &bmp280_regmap_config, + .regmap_config = &bme280_regmap_config, .start_up_time = 2000, .channels = bme280_channels, .num_channels = ARRAY_SIZE(bme280_channels), diff --git a/drivers/iio/pressure/bmp280-regmap.c b/drivers/iio/pressure/bmp280-regmap.c index fa52839474b1..d27d68edd906 100644 --- a/drivers/iio/pressure/bmp280-regmap.c +++ b/drivers/iio/pressure/bmp280-regmap.c @@ -41,7 +41,7 @@ const struct regmap_config bmp180_regmap_config = { }; EXPORT_SYMBOL_NS(bmp180_regmap_config, IIO_BMP280); -static bool bmp280_is_writeable_reg(struct device *dev, unsigned int reg) +static bool bme280_is_writeable_reg(struct device *dev, unsigned int reg) { switch (reg) { case BMP280_REG_CONFIG: @@ -54,7 +54,35 @@ static bool bmp280_is_writeable_reg(struct device *dev, unsigned int reg) } } +static bool bmp280_is_writeable_reg(struct device *dev, unsigned int reg) +{ + switch (reg) { + case BMP280_REG_CONFIG: + case BMP280_REG_CTRL_MEAS: + case BMP280_REG_RESET: + return true; + default: + return false; + } +} + static bool bmp280_is_volatile_reg(struct device *dev, unsigned int reg) +{ + switch (reg) { + case BMP280_REG_TEMP_XLSB: + case BMP280_REG_TEMP_LSB: + case BMP280_REG_TEMP_MSB: + case BMP280_REG_PRESS_XLSB: + case BMP280_REG_PRESS_LSB: + case BMP280_REG_PRESS_MSB: + case BMP280_REG_STATUS: + return true; + default: + return false; + } +} + +static bool bme280_is_volatile_reg(struct device *dev, unsigned int reg) { switch (reg) { case BME280_REG_HUMIDITY_LSB: @@ -71,7 +99,6 @@ static bool bmp280_is_volatile_reg(struct device *dev, unsigned int reg) return false; } } - static bool bmp380_is_writeable_reg(struct device *dev, unsigned int reg) { switch (reg) { @@ -167,7 +194,7 @@ const struct regmap_config bmp280_regmap_config = { .reg_bits = 8, .val_bits = 8, - .max_register = BME280_REG_HUMIDITY_LSB, + .max_register = BMP280_REG_TEMP_XLSB, .cache_type = REGCACHE_RBTREE, .writeable_reg = bmp280_is_writeable_reg, @@ -175,6 +202,18 @@ const struct regmap_config bmp280_regmap_config = { }; EXPORT_SYMBOL_NS(bmp280_regmap_config, IIO_BMP280); +const struct regmap_config bme280_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + + .max_register = BME280_REG_HUMIDITY_LSB, + .cache_type = REGCACHE_RBTREE, + + .writeable_reg = bme280_is_writeable_reg, + .volatile_reg = bme280_is_volatile_reg, +}; +EXPORT_SYMBOL_NS(bme280_regmap_config, IIO_BMP280); + const struct regmap_config bmp380_regmap_config = { .reg_bits = 8, .val_bits = 8, diff --git a/drivers/iio/pressure/bmp280.h b/drivers/iio/pressure/bmp280.h index 0933e411ae2c..4b0ebce001df 100644 --- a/drivers/iio/pressure/bmp280.h +++ b/drivers/iio/pressure/bmp280.h @@ -490,6 +490,7 @@ extern const struct bmp280_chip_info bmp580_chip_info; /* Regmap configurations */ extern const struct regmap_config bmp180_regmap_config; extern const struct regmap_config bmp280_regmap_config; +extern const struct regmap_config bme280_regmap_config; extern const struct regmap_config bmp380_regmap_config; extern const struct regmap_config bmp580_regmap_config; From patchwork Thu Jul 11 21:15:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13731070 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 2AB2E19EED0; Thu, 11 Jul 2024 21:16:20 +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=1720732582; cv=none; b=ickqUGbHhO5tlgxcLlUvzxnqyCtJto+n7jlxfGQnhRp7W+6XG19tDezO7i1o4yerTed3N2bvWQPTUmCRQiCOndvAwJSLnxx/C8yYac32lMtOpy10qRS0usAookW+tvtR0UpU2gxUOETctBJuISyp1OL2/lZ08hMdqZOoCmJUPT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720732582; c=relaxed/simple; bh=MBeTOc9YtaSE78apP7OyABkoi+w1f3Nn1NzMgGfoI4U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PDl+A3ZT575PVnop+eHZ3KHWyBknCfVNyuSig0Y4pUsoluRfNG+Naieov/ADCdVrO0gA6fd7rlQRbTCW6e9qwpwld5c+8u3AD5CjtOI+vNjLYOALiuSzHrM4fLK19nQmpO5CbUE//5jFcJn1xlNHCvlSsC73WHj9ZmNIUO89Xyg= 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=NIGh13vn; 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="NIGh13vn" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-57cf8880f95so1669764a12.3; Thu, 11 Jul 2024 14:16:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720732579; x=1721337379; 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=AeeW8xyl27sE8Lugc1U1TAa9CA2UyB3BowAvCkxaT3Q=; b=NIGh13vnbJNh3MInUGILj3zQVtKqKw9cKRguco5E0UONyJVGPxZfIXTylfKIn2PKen 36qkAzsSAD8alqyJZEJgmikQvJGxV3nNExGuhjF782v9mZRDnIUIYIdX8Z/9jgl1bLVb u9xpkwfeH+ybTl8dYnmG8xmmIYu8qVCwO+p8/h2niRvvuPKlEoHrmH8SmX7w+uxPHBXP CbG8iZO9GtP1OSqhHigM9YMQ5IJfZCbRKm+o/4OaLxC+UXogSCTuQRKg8BuXmkQuqKwA TP3vB7l83Ls230knnHqRkV6LomRpYUwgXvT2rjLg3CXfHbQiFyK4GBCm8jUdBVsOXM/7 cj3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720732579; x=1721337379; 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=AeeW8xyl27sE8Lugc1U1TAa9CA2UyB3BowAvCkxaT3Q=; b=cSDJBHC6BzQ15V3sg5/a/Nr02+c6pfBxOrfpJRfpOYXwO9tCyPwPsiYtiVISZlSM8r ++sqspCjWvmIssG5ndeQ+nb22ukXhVRjzA4FXg+OsqEfFwJjsguFxYAIownY3iHVmW8E ggSfR+2MLWMlvS5ZDOeJsGW9LMebMTJUZXc03UasvmXRwZ2Bzi5yqRjyz/uPb+8sefmY Eo9jWXbo6csBa7D5p9vrJIS0x/oD3IW1jZM80PgrqisON5Bkg0mLYxPlPYdQx9+KjANP Ola+kCBdTAFfMJ4ZPY2qg2d/9Uaj0LLIuy/anGLGvCe4ltVaOS31mtYn/9lbDqH2gZ8m Kpgg== X-Forwarded-Encrypted: i=1; AJvYcCV9V3z7iV00jscxT9IKQj+GHuztVNtB2sk9zdj81s/FnBsOBZXAyn6FFyAzp9me7OYEvF0lOpEhZ82HWbNFvg7qsP+6VACZIUET4Cekj/WbfkB/rskXG+/Nd3T/kHHJQpipbAedm3fA++Nht/qAcLvkz2ADTODj8Ncs0B40eZBhUbJ7wA== X-Gm-Message-State: AOJu0YyW57MUwX8pUsyhJt+vVfEXvPnfxcwUuQGneG48Tq9xOA4YcdaD dYK+CJQZUuVCNgZgewwBY5YqsG1hYLPWSsFP4bS87BflMJzoHft8 X-Google-Smtp-Source: AGHT+IG4hpFl1A+ErxqxderxC0zFIovKeq1a1Zak+qKO4TxzK7+kM0NSROESPPLmZziZJ3u2LLlqJA== X-Received: by 2002:a05:6402:1286:b0:57d:4f47:d9ee with SMTP id 4fb4d7f45d1cf-594bc7c88e8mr6402364a12.31.1720732579243; Thu, 11 Jul 2024 14:16:19 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:3e02:47b2:c845:ae3a]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-594bd45a1b6sm3815737a12.60.2024.07.11.14.16.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 14:16:18 -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, ang.iglesiasg@gmail.com, linus.walleij@linaro.org, biju.das.jz@bp.renesas.com, javier.carrasco.cruz@gmail.com, semen.protsenko@linaro.org, 579lpy@gmail.com, ak@it-klinger.de, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 02/10] iio: pressure: bmp280: Fix waiting time for BMP3xx configuration Date: Thu, 11 Jul 2024 23:15:50 +0200 Message-Id: <20240711211558.106327-3-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240711211558.106327-1-vassilisamir@gmail.com> References: <20240711211558.106327-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 the datasheet, both pressure and temperature can go up to oversampling x32. With this option, the maximum measurement time is not 80ms (this is for press x32 and temp x2), but it is 130ms nominal (calculated from table 3.9.2) and since most of the maximum values are around +15%, it is configured to 150ms. Fixes: 8d329309184d ("iio: pressure: bmp280: Add support for BMP380 sensor family") Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index cc8553177977..3deaa57bb3f5 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -1581,10 +1581,11 @@ static int bmp380_chip_config(struct bmp280_data *data) } /* * Waits for measurement before checking configuration error - * flag. Selected longest measure time indicated in - * section 3.9.1 in the datasheet. + * flag. Selected longest measurement time, calculated from + * formula in datasheet section 3.9.2 with an offset of ~+15% + * as it seen as well in table 3.9.1. */ - msleep(80); + msleep(150); /* Check config error flag */ ret = regmap_read(data->regmap, BMP380_REG_ERROR, &tmp); From patchwork Thu Jul 11 21:15:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13731071 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (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 B9C5919F49E; Thu, 11 Jul 2024 21:16:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720732584; cv=none; b=i/QtOpoWBylMrQjAztAgePMaJWp91QisTvB/FxMGZ1jL4IL/QjMW7agOJ+KJd6tKpNgw8hx6fcoa2Xb4/Xl5u1qj/WguSuxqITLmyQ3t91J1PivrkuSH15yQufhverqxO7LJyHd2XZ9A5CSB/j2yhC0JnF4Hz0pp9aHQvyVLZms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720732584; c=relaxed/simple; bh=Ryx9odQE94LbQFlGjL9tBqUwo5hOa1lfTe7ez58Wmd4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fYR+HKw6k+Dy4qu4LFJzSzPz7Xk82o5fUVv5zsikP9LKAokoFtSW5gpOTY3/1wm3xilBRfpkDHmOzxHMgNYwUFdaKZjyZGnfF2pMv/Jo6Ua7Bk/O9KL8l/psDNyMBOUraGNr+MS9RjKSOschM3G7x29KJcIjY3bqib422LVbrGs= 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=NT6lmSZD; arc=none smtp.client-ip=209.85.208.169 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="NT6lmSZD" Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2eea8ea8c06so17733461fa.2; Thu, 11 Jul 2024 14:16:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720732581; x=1721337381; 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=+mhnPhXWMiIZAO7ocU9BDacUYcJJKaQsmKDtkiOOP4g=; b=NT6lmSZDCYWSPrKs+Z7qMSHOUxiosYq8XKqGQDygzifcGwrOfLE/GPoVL0dPlZsJtz UIvw4jNIBrnTLjLT+nEPaycJpEAM3E/RNA5u4xQ0cObW6B9MeNneDtEHA9Dcl9nYGiIN uob8uj/EENyJTyf5uEPhjs7MN6hdbf6gLVDnkWQbQujlGOFiD+mSl4Z+34hjc6AjK7eA Xf1ZjqZUGmVsYHbj72Y3XmvBudgizi6tMee6s02TnpSXTZuSYztNEKmrgLcdNf//cdGu xkDrY4bXnuk80NZHl0jC9L1VLWF3a6IyEzlvCThSPweE/OvvV9LqbxR1mppK+T7zuqXo c+lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720732581; x=1721337381; 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=+mhnPhXWMiIZAO7ocU9BDacUYcJJKaQsmKDtkiOOP4g=; b=Z+XIclVFStSLuRXwRWIkDaqvQ6tS1lOTonMk5e/zFSzNwhoDTzcQ/D6CbC/seBDsA5 ZeWw0yutljXRw7946UexVnGNAgmbv51oiZGld8DuZdTaHEeLOqOX+brIdthtK5eG0HTo PAYeBgTir0oTeobto3KdQ0GTO24MY1jNL+KyBUK2QVqrCKCRlB108gEidTzCZxTwTaEG zLqbyvK+OpFU900yGU7n+TPsUhz71km7QQGXBzSyU/EnQbBllOpa8KPhqKbLIvUM7d3+ PBVE5KyvB3CbhxXWA+t8ojDQcFX0lQM404aaOUyMLS7YiSRIxNmaj/AWiBBiQb7WTJch CrgA== X-Forwarded-Encrypted: i=1; AJvYcCVSG6KtaXYouStmxUFePBalBcXk6X/JeHV0aY5Er6QtFRYeJ2r/0CLheGDgUdjdNGwLRigaKbKKLMghkDqDZyXvQnQgKX3psWhOH9tU2n/oMEg0FFqZP7/OOETV7P9AbaBU8vZLf81pCP6M4RVnkDPYqPM9soF3W2BoTED/OauxlOIbEQ== X-Gm-Message-State: AOJu0YxNmzOHWnRE2Dr/UhNNsDhO5KWejAF9Xw5tsiKuFOdyHontJcBn YsymP69AXiEAI/Na/FzrDI+rmGJqs3ISWySoAQ5JLhxUeB8sB6eC X-Google-Smtp-Source: AGHT+IFzXoWK10tJ6U3HY93qesHOTUCHNRZAYl10K7Vyd2rqgae59p4P8wMEhhtTEb0wHTiFKN6O/Q== X-Received: by 2002:a2e:bc13:0:b0:2ec:440c:4e1c with SMTP id 38308e7fff4ca-2eeb30ba2bdmr71918451fa.11.1720732580492; Thu, 11 Jul 2024 14:16:20 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:3e02:47b2:c845:ae3a]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-594bd45a1b6sm3815737a12.60.2024.07.11.14.16.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 14:16:19 -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, ang.iglesiasg@gmail.com, linus.walleij@linaro.org, biju.das.jz@bp.renesas.com, javier.carrasco.cruz@gmail.com, semen.protsenko@linaro.org, 579lpy@gmail.com, ak@it-klinger.de, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 03/10] iio: pressure: bmp280: Sort headers alphabetically Date: Thu, 11 Jul 2024 23:15:51 +0200 Message-Id: <20240711211558.106327-4-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240711211558.106327-1-vassilisamir@gmail.com> References: <20240711211558.106327-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Sort headers in alphabetical order Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-i2c.c | 2 +- drivers/iio/pressure/bmp280-spi.c | 4 ++-- drivers/iio/pressure/bmp280.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/iio/pressure/bmp280-i2c.c b/drivers/iio/pressure/bmp280-i2c.c index 34e3bc758493..5c3a63b4327c 100644 --- a/drivers/iio/pressure/bmp280-i2c.c +++ b/drivers/iio/pressure/bmp280-i2c.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only -#include #include +#include #include #include "bmp280.h" diff --git a/drivers/iio/pressure/bmp280-spi.c b/drivers/iio/pressure/bmp280-spi.c index f855f56a1b06..d18549d9bb64 100644 --- a/drivers/iio/pressure/bmp280-spi.c +++ b/drivers/iio/pressure/bmp280-spi.c @@ -5,10 +5,10 @@ * Inspired by the older BMP085 driver drivers/misc/bmp085-spi.c */ #include -#include -#include #include +#include #include +#include #include "bmp280.h" diff --git a/drivers/iio/pressure/bmp280.h b/drivers/iio/pressure/bmp280.h index 4b0ebce001df..ccacc67c1473 100644 --- a/drivers/iio/pressure/bmp280.h +++ b/drivers/iio/pressure/bmp280.h @@ -1,10 +1,10 @@ /* SPDX-License-Identifier: GPL-2.0 */ #include #include -#include #include #include +#include /* BMP580 specific registers */ #define BMP580_REG_CMD 0x7E From patchwork Thu Jul 11 21:15:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13731072 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73F4E19FA8A; Thu, 11 Jul 2024 21:16:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720732585; cv=none; b=bTRAN0p7vL2eLRuDSTrBBn+882zJOEzKGaXm6VVDZzXQruJ92Vb7qoluD6ut+DNySg13E72Mp6MiZrj+LPCOGDsP4s0TT/vLH9IWhpk4qQWhVNEqRSFnWPCFr9+Tb7s1Eyqk6g/zw/eBOj255wVPNkDo5CtaqLFsveeNO5Rxu90= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720732585; c=relaxed/simple; bh=iswt38ZDh5L35RqJMLBJbpHgastqMexyjy5NdMfQDk0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lAKYFXZ8LLO6Zey0/hFG5UpD/cRT+GFJ+dhagb0wHc976xk9wey9mwY/S1kKL9HFiHzNy5f1GOPazfCNYkajFat2Pb8Y6NCCHLkYB/LL8fX4Vdb/mImpOnKoOBTyRBdorK8KR2TEV+f29V1r/Up+r8yfDJbmUx16xEuByy5K0xc= 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=IOkSWY/X; arc=none smtp.client-ip=209.85.208.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IOkSWY/X" Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-58e76294858so4386655a12.0; Thu, 11 Jul 2024 14:16:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720732582; x=1721337382; 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=ZJzviKKMGlR+YckvWALlWpdSojxVWWeJ6E/wr0TtI5g=; b=IOkSWY/X+0RCzjBcjZoD8vPiV35vDBGGlt1zSM+4+O+X1aIwzu8SmlHFYU8rsYG6Q+ Lt3w45FXAI3DKw95Cm+mRRZSUAdqoBKN0k6AyCOAgEsrCXYRoStjT1NTtdWr/PPRdndk jOWMT443AY8gPKIkS+bZGoHKl6TBakVmLICoaobnY46Mj3fWy4K0A02rm3i5rubnb7x8 cC/Et530mbcrsPKc41huJ7Qj8lRBV+ZUzbWQ5UES2JCcOvJAINsmUJlLdrSqnaAwFJx3 bYZFjBk6FI0SBFiy8w5tzM+fCpQC4Zug4ema5aBz/AtlrSnKym6v3BYd8dNX+0z82uHv mYBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720732582; x=1721337382; 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=ZJzviKKMGlR+YckvWALlWpdSojxVWWeJ6E/wr0TtI5g=; b=QqP9MHTfnyiOHxybr+WicNUSDClh6LlN1k/eAeOWuVVoU70B/qP5ELzOftL2BCVF7h 9Px5Aq22eBZKuXp5bPpD03Q6CWqANil4DkiGyPZdqiJlNCBsjfc5Oi7AYS4bbK8yMQBu DLht/C/Ho14P4FWVgR54N13VhWQUL4IrKRZTHLetp7CbuF3+FKVMsD8EkIU7WaxnkctS MGV+J11lw9rDPxtyBpBDGLVIVAeST4K2f/1CCam6vYV9Gudp12F8yvdAh5f7cfCEaZ2R d5iBYJ4h3Nbhuvaq7ecf1x1Lp3LtLhnCEryONA2QM5IE7rbPIqvZmR2EOsQD7EhV/u/Z 15Rw== X-Forwarded-Encrypted: i=1; AJvYcCWEDnRQUVcPMfM19Jg9etaFHjgDwfI6ej3AiZM9HfBURGu8Ye9AFSfSHJIAgKWXb5R689I36QdRUsROHKFhaUEGTYnN5t5uzdE3Lrw6lxqBLw2jNrIj8FND6cb9d2vd+AWSzDGzzi2P1LFNR7gV5tMUnCWGQQVwYWDr7bYBRCqewgCrbQ== X-Gm-Message-State: AOJu0YwQsmK+IObRsL/iAlMlhfJjgWD5dPmFcm2J9/8mA6eCwmqvqcPt b4cvczSMw526vX1YHy7SSxuk/Yo4Jo6e0PzcfPacwnl0wmlQmLFZ X-Google-Smtp-Source: AGHT+IGpWELhWi4gemSWFK9z79m77Dok2T6N/te+SGPKg7gKeTxVmsr5r/QurBA+2htn2bVGiZ8Uqg== X-Received: by 2002:a50:d744:0:b0:57c:a8e5:35f0 with SMTP id 4fb4d7f45d1cf-59963bf4683mr524904a12.2.1720732581863; Thu, 11 Jul 2024 14:16:21 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:3e02:47b2:c845:ae3a]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-594bd45a1b6sm3815737a12.60.2024.07.11.14.16.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 14:16:21 -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, ang.iglesiasg@gmail.com, linus.walleij@linaro.org, biju.das.jz@bp.renesas.com, javier.carrasco.cruz@gmail.com, semen.protsenko@linaro.org, 579lpy@gmail.com, ak@it-klinger.de, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 04/10] iio: pressure: bmp280: Use bulk read for humidity calibration data Date: Thu, 11 Jul 2024 23:15:52 +0200 Message-Id: <20240711211558.106327-5-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240711211558.106327-1-vassilisamir@gmail.com> References: <20240711211558.106327-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Convert individual reads to a bulk read for the humidity calibration data. Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-core.c | 57 +++++++++--------------------- drivers/iio/pressure/bmp280.h | 5 +++ 2 files changed, 21 insertions(+), 41 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 3deaa57bb3f5..9c32266403bd 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -118,6 +118,8 @@ enum bmp580_odr { */ enum { T1, T2, T3, P1, P2, P3, P4, P5, P6, P7, P8, P9 }; +enum { H2 = 0, H3 = 2, H4 = 3, H5 = 4, H6 = 6 }; + enum { /* Temperature calib indexes */ BMP380_T1 = 0, @@ -344,6 +346,7 @@ static int bme280_read_calib(struct bmp280_data *data) { struct bmp280_calib *calib = &data->calib.bmp280; struct device *dev = data->dev; + s16 h4_upper, h4_lower; unsigned int tmp; int ret; @@ -352,14 +355,6 @@ static int bme280_read_calib(struct bmp280_data *data) if (ret) return ret; - /* - * Read humidity calibration values. - * Due to some odd register addressing we cannot just - * do a big bulk read. Instead, we have to read each Hx - * value separately and sometimes do some bit shifting... - * Humidity data is only available on BME280. - */ - ret = regmap_read(data->regmap, BME280_REG_COMP_H1, &tmp); if (ret) { dev_err(dev, "failed to read H1 comp value\n"); @@ -368,43 +363,23 @@ static int bme280_read_calib(struct bmp280_data *data) calib->H1 = tmp; ret = regmap_bulk_read(data->regmap, BME280_REG_COMP_H2, - &data->le16, sizeof(data->le16)); - if (ret) { - dev_err(dev, "failed to read H2 comp value\n"); - return ret; - } - calib->H2 = sign_extend32(le16_to_cpu(data->le16), 15); - - ret = regmap_read(data->regmap, BME280_REG_COMP_H3, &tmp); - if (ret) { - dev_err(dev, "failed to read H3 comp value\n"); - return ret; - } - calib->H3 = tmp; - - ret = regmap_bulk_read(data->regmap, BME280_REG_COMP_H4, - &data->be16, sizeof(data->be16)); - if (ret) { - dev_err(dev, "failed to read H4 comp value\n"); - return ret; - } - calib->H4 = sign_extend32(((be16_to_cpu(data->be16) >> 4) & 0xff0) | - (be16_to_cpu(data->be16) & 0xf), 11); - - ret = regmap_bulk_read(data->regmap, BME280_REG_COMP_H5, - &data->le16, sizeof(data->le16)); + data->bme280_humid_cal_buf, + sizeof(data->bme280_humid_cal_buf)); if (ret) { - dev_err(dev, "failed to read H5 comp value\n"); + dev_err(dev, "failed to read humidity calibration values\n"); return ret; } - calib->H5 = sign_extend32(FIELD_GET(BME280_COMP_H5_MASK, le16_to_cpu(data->le16)), 11); - ret = regmap_read(data->regmap, BME280_REG_COMP_H6, &tmp); - if (ret) { - dev_err(dev, "failed to read H6 comp value\n"); - return ret; - } - calib->H6 = sign_extend32(tmp, 7); + calib->H2 = get_unaligned_le16(&data->bme280_humid_cal_buf[H2]); + calib->H3 = data->bme280_humid_cal_buf[H3]; + h4_upper = FIELD_GET(BME280_COMP_H4_MASK_UP, + get_unaligned_be16(&data->bme280_humid_cal_buf[H4])); + h4_lower = FIELD_GET(BME280_COMP_H4_MASK_LOW, + get_unaligned_be16(&data->bme280_humid_cal_buf[H4])); + calib->H4 = sign_extend32((h4_upper & ~BME280_COMP_H4_MASK_LOW) | h4_lower, 11); + calib->H5 = sign_extend32(FIELD_GET(BME280_COMP_H5_MASK, + get_unaligned_le16(&data->bme280_humid_cal_buf[H5])), 11); + calib->H6 = data->bme280_humid_cal_buf[H6]; return 0; } diff --git a/drivers/iio/pressure/bmp280.h b/drivers/iio/pressure/bmp280.h index ccacc67c1473..56c01f224728 100644 --- a/drivers/iio/pressure/bmp280.h +++ b/drivers/iio/pressure/bmp280.h @@ -257,8 +257,12 @@ #define BME280_REG_COMP_H5 0xE5 #define BME280_REG_COMP_H6 0xE7 +#define BME280_COMP_H4_MASK_UP GENMASK(15, 4) +#define BME280_COMP_H4_MASK_LOW GENMASK(3, 0) #define BME280_COMP_H5_MASK GENMASK(15, 4) +#define BME280_CONTIGUOUS_CALIB_REGS 7 + #define BME280_OSRS_HUMIDITY_MASK GENMASK(2, 0) #define BME280_OSRS_HUMIDITY_SKIP 0 #define BME280_OSRS_HUMIDITY_1X 1 @@ -423,6 +427,7 @@ struct bmp280_data { /* Calibration data buffers */ __le16 bmp280_cal_buf[BMP280_CONTIGUOUS_CALIB_REGS / 2]; __be16 bmp180_cal_buf[BMP180_REG_CALIB_COUNT / 2]; + u8 bme280_humid_cal_buf[BME280_CONTIGUOUS_CALIB_REGS]; u8 bmp380_cal_buf[BMP380_CALIB_REG_COUNT]; /* Miscellaneous, endianness-aware data buffers */ __le16 le16; From patchwork Thu Jul 11 21:15:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13731073 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 1F6B01A00EB; Thu, 11 Jul 2024 21:16:24 +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=1720732586; cv=none; b=qlabfqmhBdLgjsdiKer/FfS7cG9klabtB6UX4yPiFEca3xZZvLOHu6jOmZPhk1Qm/n/JPlyv/JsuSztacMUCD/W6tuqZzKNpOUz8Fiu0JZme2xTiSwlDCsGNPwF7WPIFwqMznLqZGZGGBp4svHb4Fqoi+Z8vH8I6nXUz0t0vGnA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720732586; c=relaxed/simple; bh=oNz9jbnau5US66OL2TkVYMflazhurOtygod0jl8rWz4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TjoB327NRCiUO8z6LkoB3hqbk1dOYsfVJGAuxl8Jl40NZALsdt5/37telECS8OnuMcQj5poOL0ht8nukpVFf69GP1X6az/dU4iZW6lxPMm6CrUfVIZKU/Wb/J7SWu450uGkbDoRemNTfKIgUKVPBbe8THfvmw7esyx4JzT3Gt4A= 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=GQ3erRy/; 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="GQ3erRy/" Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2eeb1ba0481so17161141fa.2; Thu, 11 Jul 2024 14:16:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720732583; x=1721337383; 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=eCp4C86w9awpHIw8DaJsMnbo3g5VipSX+X5uHPVqBok=; b=GQ3erRy/GF71EVkXkuVZalM3BvOR/JNzNJpyyjURiCIhFMcBlwf1yYtKxiM9KgPe4P FpI6cH6QJI0gTpUs7g+m+L7dOJjL+j/llT0mjFPb2Mv97FlkRIk/AH1OJXBrbaPd/9zU 9DGQnr/wkbYhIwiMTpixS50psNly+HmOnoR5P1ykhe3Vfj0DSWLJ4iCxGtMMLDYWOaS2 ylG+p7EgeMaOvGbbn1LzVwq6+tecnfjxxgmXk4f4+1HRmtivFuc9a0g3FHj0/TmJUj6S fcsZ92pYiYXqWrlbEqZhljv5LcPA9qEoHi57LnU9awz50m+RsgpljK6u18eeiv1yeb6d U7Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720732583; x=1721337383; 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=eCp4C86w9awpHIw8DaJsMnbo3g5VipSX+X5uHPVqBok=; b=Ve2tgJ2vW1Bsl9mwx8bBSFFiOGFIuUwfg8t/Qof+hrcROQMJPOWVgPzw8ss0fW5SK3 6Gvw4cLt4y9B+pEP5FRWy/bEYpqrAneX/GvJoELepk7eUr4tsGBqkLZD67gkEA85dAmo k6gMlYJ59ysjBolYjtx5tB9NFFYfsGuTseFZmfSt+9Wus0YjXhzf2n4cvUxn/lT57F8Y tf3LS98Mdt3nczpyx30xmVc/Ujz5f6s7hYJUeJsjx/uQsIOlglTHwCRknsoYNbbU1zMx jwu+1PQGqcr8Q49/d9ZqkmZJCUAGXnIW93Iy+nU4Ie6buDtVAfGZQMJ8gQxt0gRRZ8jK 7Q0g== X-Forwarded-Encrypted: i=1; AJvYcCVcw5kJv+1huXZhdqHc+91rF+SQbtg9YA4SKUWG9IyXSPfvrSbzYXLg8RAR93Pxd4QZIxb7orUZZYqVWhIbF/Bsw85QlGE9TtoPU0uZlkcb0tGKd3g5jGCzeLqc4i8C2OCS3/2GcVvsQE9OvPYWCk44WSNYZMz2uR0FmIHRTg6sTZMGZg== X-Gm-Message-State: AOJu0YzBlKQforv08KU74ZwHc+K+3q3HAGd5kw5oomhl+bipI3JxCMVB bT8FFlGVh0EREDR0YuMqfw0I89fEopyZ7t7BcNaLgeHwBN1GvtSk X-Google-Smtp-Source: AGHT+IEYZLAB94CBOmZJVnkxcftaT7/EGoAOq6CXg50riSEJYqiv8MglGKQVpKvOSm6lRLQ5iAFNLw== X-Received: by 2002:a05:651c:102f:b0:2ec:1a8b:c374 with SMTP id 38308e7fff4ca-2eeb3198692mr60717471fa.45.1720732582984; Thu, 11 Jul 2024 14:16:22 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:3e02:47b2:c845:ae3a]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-594bd45a1b6sm3815737a12.60.2024.07.11.14.16.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 14:16: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, ang.iglesiasg@gmail.com, linus.walleij@linaro.org, biju.das.jz@bp.renesas.com, javier.carrasco.cruz@gmail.com, semen.protsenko@linaro.org, 579lpy@gmail.com, ak@it-klinger.de, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 05/10] iio: pressure: bmp280: Add support for bmp280 soft reset Date: Thu, 11 Jul 2024 23:15:53 +0200 Message-Id: <20240711211558.106327-6-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240711211558.106327-1-vassilisamir@gmail.com> References: <20240711211558.106327-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The BM(P/E)28x devices have an option for soft reset which is also recommended by the Bosch Sensortech BME2 Sensor API to be used before the initial configuration of the device. Link: https://github.com/boschsensortec/BME280_SensorAPI/blob/bme280_v3.5.1/bme280.c#L429 Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-core.c | 28 ++++++++++++++++++++++++++++ drivers/iio/pressure/bmp280.h | 3 +++ 2 files changed, 31 insertions(+) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 9c32266403bd..caee586b2268 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -958,6 +958,32 @@ static const unsigned long bme280_avail_scan_masks[] = { 0 }; +static int bmp280_preinit(struct bmp280_data *data) +{ + unsigned int reg; + int ret; + + ret = regmap_write(data->regmap, BMP280_REG_RESET, BMP280_RST_SOFT_CMD); + if (ret) { + dev_err(data->dev, "Failed to reset device.\n"); + return ret; + } + + usleep_range(data->start_up_time, data->start_up_time + 500); + + ret = regmap_read(data->regmap, BMP280_REG_STATUS, ®); + if (ret) { + dev_err(data->dev, "Failed to read status register.\n"); + return ret; + } + if (reg & BMP280_REG_STATUS_IM_UPDATE) { + dev_err(data->dev, "Failed to copy NVM contents.\n"); + return ret; + } + + return 0; +} + static int bmp280_chip_config(struct bmp280_data *data) { u8 osrs = FIELD_PREP(BMP280_OSRS_TEMP_MASK, data->oversampling_temp + 1) | @@ -1074,6 +1100,7 @@ const struct bmp280_chip_info bmp280_chip_info = { .read_temp = bmp280_read_temp, .read_press = bmp280_read_press, .read_calib = bmp280_read_calib, + .preinit = bmp280_preinit, .trigger_handler = bmp280_trigger_handler, }; @@ -1191,6 +1218,7 @@ const struct bmp280_chip_info bme280_chip_info = { .read_press = bmp280_read_press, .read_humid = bme280_read_humid, .read_calib = bme280_read_calib, + .preinit = bmp280_preinit, .trigger_handler = bme280_trigger_handler, }; diff --git a/drivers/iio/pressure/bmp280.h b/drivers/iio/pressure/bmp280.h index 56c01f224728..02647454bd02 100644 --- a/drivers/iio/pressure/bmp280.h +++ b/drivers/iio/pressure/bmp280.h @@ -205,6 +205,9 @@ #define BMP280_REG_CONFIG 0xF5 #define BMP280_REG_CTRL_MEAS 0xF4 #define BMP280_REG_STATUS 0xF3 +#define BMP280_REG_STATUS_IM_UPDATE BIT(0) +#define BMP280_REG_RESET 0xE0 +#define BMP280_RST_SOFT_CMD 0xB6 #define BMP280_REG_COMP_TEMP_START 0x88 #define BMP280_COMP_TEMP_REG_COUNT 6 From patchwork Thu Jul 11 21:15:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13731074 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05F3A1A01D9; Thu, 11 Jul 2024 21:16:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720732587; cv=none; b=up8dZs5DL1knXlsm7HGb3mNsVph2OXBv9BLCIQE7lz+qYPEN9laO9AlaFGIJq5Est/zfsDjjJ3oMjAr0/KJQFlh5agcZGi1qTIO+O1TPXBIoBETAmAkbg8wRZXr5mkPxUgbescwJr6y4VGfHH733OnNWE2GrV1mMmWfmRWlXvyM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720732587; c=relaxed/simple; bh=dKyWi8LcT1C1CFo4MuCPSYE2WNQ7OFauCzJpwZMvqqY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KPNdJjzMuh/51hprqjOP3k5NsGjWlTZHTV3gJli3qUggrM/tyWQm3pyRXlUt/qimuMT3J0SlweoeNklxEAjr1cDQr43pfJpleKxcBupUPLxljpbiJth0VeVyCHFwXLwi51PZB/csV1ZjmY2v8pI5gwg/zwWf3XZWeV+TkbDC5IY= 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=b8OGIiJ5; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b8OGIiJ5" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-58ef19aa6b3so867709a12.1; Thu, 11 Jul 2024 14:16:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720732584; x=1721337384; 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=CYcXNPOh0TR9ECTWQep62KZXJN1EG0+nQZbBk6Melzg=; b=b8OGIiJ5cz2b8yXq/KE0HvLwJVAn5RTYAxF7/ZSyqci0T5Oy643EeEV//Z2ZqCSnIe klj1uQS+OlOJeysunwjYoUMLT/AjIxVs4mWXr08AChVfSl5jXxRnIKpnxhxgqWJEiihd b8zm3o8Yo0SDf+qoM6RP9zwNw763eGc9F3hgD3PBMgDAODX3QPu+A0aZXqf9uLUhxSC5 aKLPJkjOIYe9+A57T+ZJOhS7PGbTsanY5lwgZUYrFLE8GRuRiNLP+WhMBwJAhOFNPjp1 /lHeb6i5ylNicFqfVQJiU64+FZhwo5vmmJdft+lKvmOj020hhHxkY/xbkCpg+Vh4WoSN 6koQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720732584; x=1721337384; 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=CYcXNPOh0TR9ECTWQep62KZXJN1EG0+nQZbBk6Melzg=; b=KkNLBIlzCAfn8bE7Yq8chS3xoK5j68kG/6IM+JUW4VMDuzVqiIDCLINOCk8GRarK2i KfL71/DGzEtumvegCSNlFnJVEki5ScqW14gx8p24A62yvsk6jh3VOEFJE+B/DviZoL/n z6/7dDe5/HV37bxc2EbNmNlmKVOjYM8ZKGab/5UpHEIZ6GRyg6hdFioAy7sI98KOQ10g UPNujPOvfOhwEmKqgj20xbiLbux19snAyea6c76XZgsummxoADijgJAbVu2cFX0qV67u qltHAcSCXvtVd8RRePeX5qJ6ECZC4cKEjk7qMdsVsmrHS2TLpzeCH06Usool2k6cDE9z Z4LA== X-Forwarded-Encrypted: i=1; AJvYcCWLiDBoXUK35qba/EYzTEPCypj+vf17BeUlT6OREwWKw4DMTNTtOvsKY35DByzMtj9Rm9NXXSvpP2tUTLdayMSdYvzIM46ttn4ZekhiXmY6Nl+cip+xNWKQPlAb9qf2QKifBlNsYrjQtHpv2kjqET4O8e6XWWnOywfKCg7v/dfy9qcrkQ== X-Gm-Message-State: AOJu0YytbQPSuRcGJD9z7trmNflxjEYMmGKMWgoY+FwvztUpawEyjZdm XPnqFY6vDWOWsaUovE6rTAf06vqQZiBIMMHVtVo2poZQV3Brgsu6Uzyp8yNtwaA= X-Google-Smtp-Source: AGHT+IFWGpm4uzU78tmcS1v8Zu0tJZv9xaswEb3PNtUV/MczU98LOEwk36+ssRUHVZg3Oxm5a9/hxg== X-Received: by 2002:a05:6402:430b:b0:58c:3252:3ab8 with SMTP id 4fb4d7f45d1cf-594bcba83fcmr10193206a12.37.1720732584286; Thu, 11 Jul 2024 14:16:24 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:3e02:47b2:c845:ae3a]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-594bd45a1b6sm3815737a12.60.2024.07.11.14.16.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 14:16:23 -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, ang.iglesiasg@gmail.com, linus.walleij@linaro.org, biju.das.jz@bp.renesas.com, javier.carrasco.cruz@gmail.com, semen.protsenko@linaro.org, 579lpy@gmail.com, ak@it-klinger.de, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 06/10] iio: pressure: bmp280: Remove config error check for IIR filter updates Date: Thu, 11 Jul 2024 23:15:54 +0200 Message-Id: <20240711211558.106327-7-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240711211558.106327-1-vassilisamir@gmail.com> References: <20240711211558.106327-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When there is a change in the configuration of the BMP3xx device, several steps take place. These steps include: 1) Update the OSR settings and check if there was an update 2) Update the ODR settings and check if there was an update 3) Update the IIR settings and check if there was an update 4) Check if there was an update with the following procedure: a) Set sensor to SLEEP mode and after to NORMAL mode to trigger a new measurement. b) Wait the maximum amount possible depending on the OSR settings c) Check the configuration error register if there was an error during the configuration of the sensor. This check is necessary, because there could be a case where the OSR is too high for the requested ODR so either the ODR needs to be slower or the OSR needs to be less. This is something that is checked internally by the sensor when it runs in NORMAL mode. In the BMP58x devices the previous steps are done internally by the sensor. The IIR filter settings do not depend on the OSR or ODR settings, and there is no need to run a check in case they change. Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-core.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index caee586b2268..9c99373d66ec 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -1548,14 +1548,12 @@ static int bmp380_chip_config(struct bmp280_data *data) change = change || aux; /* Set filter data */ - ret = regmap_update_bits_check(data->regmap, BMP380_REG_CONFIG, BMP380_FILTER_MASK, - FIELD_PREP(BMP380_FILTER_MASK, data->iir_filter_coeff), - &aux); + ret = regmap_update_bits(data->regmap, BMP380_REG_CONFIG, BMP380_FILTER_MASK, + FIELD_PREP(BMP380_FILTER_MASK, data->iir_filter_coeff)); if (ret) { dev_err(data->dev, "failed to write config register\n"); return ret; } - change = change || aux; if (change) { /* @@ -2144,15 +2142,13 @@ static int bmp580_chip_config(struct bmp280_data *data) reg_val = FIELD_PREP(BMP580_DSP_IIR_PRESS_MASK, data->iir_filter_coeff) | FIELD_PREP(BMP580_DSP_IIR_TEMP_MASK, data->iir_filter_coeff); - ret = regmap_update_bits_check(data->regmap, BMP580_REG_DSP_IIR, - BMP580_DSP_IIR_PRESS_MASK | - BMP580_DSP_IIR_TEMP_MASK, - reg_val, &aux); + ret = regmap_update_bits(data->regmap, BMP580_REG_DSP_IIR, + BMP580_DSP_IIR_PRESS_MASK | + BMP580_DSP_IIR_TEMP_MASK, reg_val); if (ret) { dev_err(data->dev, "failed to write config register\n"); return ret; } - change = change || aux; /* Restore sensor to normal operation mode */ ret = regmap_write_bits(data->regmap, BMP580_REG_ODR_CONFIG, From patchwork Thu Jul 11 21:15:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13731075 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 315CD1A0725; Thu, 11 Jul 2024 21:16:26 +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=1720732589; cv=none; b=G4H7Eo7u5ymGXOGMHBNjOPKjTwRQN2ZneYLyaBbKqF7ozSSPTglz+Uq5PaqMxp45esTwppEtaoUOpG9ImBZU3OLkZk3sRLd+0H2B4CxcA6d7RjtVwlPFzX48gwu9pF4f43JZaXVS+W6qLFHXb3miUnE13wnKt9uAVZYplAtui84= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720732589; c=relaxed/simple; bh=wqVtrgUtnDmwTlfHIFjCyf9iIRUKIg98JHzUq5SJ+jQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ppYos22KgJkg6+hirC/SaTiD/YrM4SmJN8A5kjmU4MWOzi6gykJKxSZBQXlJ8CdGtvebDQXGZptYgRhVfa+pT/FAhKv0eCmMr7qkHBBtis9MBCRaiULvs54O3IGitn+jMNV7HhU7KWTlNGrOM7+l/JfafcEe35eE7lHPdWz3Yfw= 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=AD4G0gLD; 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="AD4G0gLD" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-58e76294858so4386733a12.0; Thu, 11 Jul 2024 14:16:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720732585; x=1721337385; 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=HxVh2Sfi+9HqjHvHaFZvSf8nxNpjwkTgMPpFouegvVQ=; b=AD4G0gLDIPDgtQ8zEfKqC9YFuUiCJU06IOJ6kriuofiHAI4zGKdBqXSxBEbM4I3JJV O/gezkgYEODMBLQS2OAJWq2iNIGnWGEcF4rwPta2LZB8lsr5p7nufIvAxAFnEybQcpbM tjjH2YrhdKJyMQayJpuqBOS+JGDqRkB+mo/o7oH7M1SeJzDz+Qc6+CblERs76X+b58Q7 iWvpIFz7MO8rg4mSLmC1TCmWhrs4qxCAUY0ZVeaHhCUHII9iB867G2y81kfE77e7pv8O dxfDHSlxZbaYAXEqk7rY9GFvFA14VP7WhCTl6+hDB9PzNmXDljHMHxEynsae8sJ7W/BK 2HMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720732585; x=1721337385; 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=HxVh2Sfi+9HqjHvHaFZvSf8nxNpjwkTgMPpFouegvVQ=; b=TLb7E9LbeCEm2S6LtlC6UXeAxDhG4md8x+rRPoCjFwHgAdNQFnCT45qt0cXDTYy7lz VjeByVOVpnV50cD/lnf/KnZFFAQBS2NwMPSV7m3bmQlTuj9YIIAn+4YOaQpwxjR4eApu FPi5jqy8M7YPhD8STWMpPKRxfI5oYw/Y0D07pTxxDoyqiia1eW3/9EDIDJ96/FDeYiak 6EGEGJg7CSMWNxYkGAT2X7tcEIC+ujl/PRf2jtxbDjGntaCbR6yQ3v2AmOxrlNYtzBtw hk4f8yaiUdNSQvbaZSFZ3yOX6wSpYRyCEH3+V6LAryR4qy2NL5JHtGF9TkzyUw43PQzO 28sQ== X-Forwarded-Encrypted: i=1; AJvYcCXa+ynsqq+LxqczkzqWX7xZto75Wbr7jjj8AzAIGdPZ6JnChl8VUmO6TvhDUb83aLyJIEFNjHNtPwnn7D8feqW/0tKQE+291DrV5UHR2KoUwqVdhmsv5s+UXxYhIjXV2cbVLGm56HspKrLDWQKsua3K5I+Dj4zTdVUrZZU/lAP7rX7tqg== X-Gm-Message-State: AOJu0Yweb2fCBY8xDEIlzgzfjqRzPCLxKpQRBMLcGOMNK+iyK96BC1c2 dOQB5jxabNXSoKB2luuaBfYuFeCNQVE1hPuPdy2HQ0V/PYZLvdf3 X-Google-Smtp-Source: AGHT+IEJZO1U64B255yG15iNqqSRVZ4pq+qt3TdtOudnJyzpR2/Ip7Qa+DJsbJUPOovpmXdtcnzUSA== X-Received: by 2002:a50:9e66:0:b0:585:2924:1569 with SMTP id 4fb4d7f45d1cf-599609a3be5mr493022a12.21.1720732585378; Thu, 11 Jul 2024 14:16:25 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:3e02:47b2:c845:ae3a]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-594bd45a1b6sm3815737a12.60.2024.07.11.14.16.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 14:16: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, ang.iglesiasg@gmail.com, linus.walleij@linaro.org, biju.das.jz@bp.renesas.com, javier.carrasco.cruz@gmail.com, semen.protsenko@linaro.org, 579lpy@gmail.com, ak@it-klinger.de, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 07/10] iio: pressure: bmp280: Use sleep and forced mode for oneshot captures Date: Thu, 11 Jul 2024 23:15:55 +0200 Message-Id: <20240711211558.106327-8-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240711211558.106327-1-vassilisamir@gmail.com> References: <20240711211558.106327-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This commit adds forced mode support in sensors BMP28x, BME28x, BMP3xx and BMP58x. Sensors BMP18x and BMP085 are old and do not support this feature so their operation is not affected at all. Essentially, up to now, the rest of the sensors were used in normal mode all the time. This means that they are continuously doing measurements even though these measurements are not used. Even though the sensor does provide PM support, to cover all the possible use cases, the sensor needs to go into sleep mode and wake up whenever necessary. This commit, adds sleep and forced mode support. Essentially, the sensor sleeps all the time except for when a measurement is requested. When there is a request for a measurement, the sensor is put into forced mode, starts the measurement and after it is done we read the output and we put it again in sleep mode. For really fast and more deterministic measurements, the triggered buffer interface can be used, since the sensor is still used in normal mode for that use case. This commit does not add though support for DEEP STANDBY, Low Power NORMAL and CONTINUOUS modes, supported only by the BMP58x version. Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-core.c | 276 +++++++++++++++++++++++++++-- drivers/iio/pressure/bmp280.h | 12 ++ 2 files changed, 269 insertions(+), 19 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 9c99373d66ec..fc8d42880eb8 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -145,6 +145,12 @@ enum bmp280_scan { BME280_HUMID, }; +enum bmp280_power_modes { + BMP280_SLEEP, + BMP280_NORMAL, + BMP280_FORCED, +}; + static const struct iio_chan_spec bmp280_channels[] = { { .type = IIO_PRESSURE, @@ -610,6 +616,14 @@ static int bmp280_read_raw_impl(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_PROCESSED: + ret = data->chip_info->set_mode(data, BMP280_FORCED); + if (ret) + return ret; + + ret = data->chip_info->wait_conv(data); + if (ret) + return ret; + switch (chan->type) { case IIO_HUMIDITYRELATIVE: ret = data->chip_info->read_humid(data, &chan_value); @@ -639,6 +653,14 @@ static int bmp280_read_raw_impl(struct iio_dev *indio_dev, return -EINVAL; } case IIO_CHAN_INFO_RAW: + ret = data->chip_info->set_mode(data, BMP280_FORCED); + if (ret) + return ret; + + ret = data->chip_info->wait_conv(data); + if (ret) + return ret; + switch (chan->type) { case IIO_HUMIDITYRELATIVE: ret = data->chip_info->read_humid(data, &chan_value); @@ -984,6 +1006,68 @@ static int bmp280_preinit(struct bmp280_data *data) return 0; } +static int bmp280_set_mode(struct bmp280_data *data, u8 mode) +{ + int ret; + + switch (mode) { + case BMP280_SLEEP: + ret = regmap_write_bits(data->regmap, BMP280_REG_CTRL_MEAS, + BMP280_MODE_MASK, BMP280_MODE_SLEEP); + break; + case BMP280_FORCED: + ret = regmap_write_bits(data->regmap, BMP280_REG_CTRL_MEAS, + BMP280_MODE_MASK, BMP280_MODE_FORCED); + break; + case BMP280_NORMAL: + ret = regmap_write_bits(data->regmap, BMP280_REG_CTRL_MEAS, + BMP280_MODE_MASK, BMP280_MODE_NORMAL); + break; + default: + return -EINVAL; + } + + if (ret) { + dev_err(data->dev, "failed to write ctrl_meas register\n"); + return ret; + } + + return 0; +} + +static int bmp280_wait_conv(struct bmp280_data *data) +{ + unsigned int reg; + int ret, meas_time; + + meas_time = BMP280_MEAS_OFFSET; + + if (data->oversampling_humid) + meas_time += (1 << data->oversampling_humid) * BMP280_MEAS_DUR + + BMP280_PRESS_HUMID_MEAS_OFFSET; + + /* Pressure measurement time */ + meas_time += (1 << data->oversampling_press) * BMP280_MEAS_DUR + + BMP280_PRESS_HUMID_MEAS_OFFSET; + + /* Temperature measurement time */ + meas_time += (1 << data->oversampling_temp) * BMP280_MEAS_DUR; + + usleep_range(meas_time, meas_time * 12 / 10); + + ret = regmap_read(data->regmap, BMP280_REG_STATUS, ®); + if (ret) { + dev_err(data->dev, "failed to read status register\n"); + return ret; + } + if (reg & BMP280_REG_STATUS_MEAS_BIT) { + dev_err(data->dev, "Measurement cycle didn't complete\n"); + return -EBUSY; + } + + return 0; +} + static int bmp280_chip_config(struct bmp280_data *data) { u8 osrs = FIELD_PREP(BMP280_OSRS_TEMP_MASK, data->oversampling_temp + 1) | @@ -994,7 +1078,7 @@ static int bmp280_chip_config(struct bmp280_data *data) BMP280_OSRS_TEMP_MASK | BMP280_OSRS_PRESS_MASK | BMP280_MODE_MASK, - osrs | BMP280_MODE_NORMAL); + osrs | BMP280_MODE_SLEEP); if (ret) { dev_err(data->dev, "failed to write ctrl_meas register\n"); return ret; @@ -1100,6 +1184,8 @@ const struct bmp280_chip_info bmp280_chip_info = { .read_temp = bmp280_read_temp, .read_press = bmp280_read_press, .read_calib = bmp280_read_calib, + .set_mode = bmp280_set_mode, + .wait_conv = bmp280_wait_conv, .preinit = bmp280_preinit, .trigger_handler = bmp280_trigger_handler, @@ -1218,6 +1304,8 @@ const struct bmp280_chip_info bme280_chip_info = { .read_press = bmp280_read_press, .read_humid = bme280_read_humid, .read_calib = bme280_read_calib, + .set_mode = bmp280_set_mode, + .wait_conv = bmp280_wait_conv, .preinit = bmp280_preinit, .trigger_handler = bme280_trigger_handler, @@ -1505,6 +1593,75 @@ static int bmp380_preinit(struct bmp280_data *data) return bmp380_cmd(data, BMP380_CMD_SOFT_RESET); } +static int bmp380_set_mode(struct bmp280_data *data, u8 mode) +{ + int ret; + + switch (mode) { + case BMP280_SLEEP: + ret = regmap_write_bits(data->regmap, BMP380_REG_POWER_CONTROL, + BMP380_MODE_MASK, + FIELD_PREP(BMP380_MODE_MASK, + BMP380_MODE_SLEEP)); + break; + case BMP280_FORCED: + ret = regmap_write_bits(data->regmap, BMP380_REG_POWER_CONTROL, + BMP380_MODE_MASK, + FIELD_PREP(BMP380_MODE_MASK, + BMP380_MODE_FORCED)); + break; + case BMP280_NORMAL: + ret = regmap_write_bits(data->regmap, BMP380_REG_POWER_CONTROL, + BMP380_MODE_MASK, + FIELD_PREP(BMP380_MODE_MASK, + BMP380_MODE_NORMAL)); + break; + default: + return -EINVAL; + } + + if (ret) { + dev_err(data->dev, "failed to write power control register\n"); + return ret; + } + + return 0; +} + +static int bmp380_wait_conv(struct bmp280_data *data) +{ + unsigned int reg; + int ret, meas_time; + + /* Offset measurement time */ + meas_time = BMP380_MEAS_OFFSET; + + /* Pressure measurement time */ + meas_time += (1 << data->oversampling_press) * BMP380_MEAS_DUR + + BMP380_PRESS_MEAS_OFFSET; + + /* Temperature measurement time */ + meas_time += (1 << data->oversampling_temp) * BMP380_MEAS_DUR + + BMP380_TEMP_MEAS_OFFSET; + + usleep_range(meas_time, meas_time * 12 / 10); + + ret = regmap_read(data->regmap, BMP380_REG_STATUS, ®); + if (ret) { + dev_err(data->dev, "failed to read status register\n"); + return ret; + } + + if (!(reg & BMP380_STATUS_DRDY_PRESS_MASK) || + !(reg & BMP380_STATUS_DRDY_TEMP_MASK)) { + pr_info("Meas_time: %d\n", meas_time); + dev_err(data->dev, "Measurement cycle didn't complete\n"); + return -EBUSY; + } + + return 0; +} + static int bmp380_chip_config(struct bmp280_data *data) { bool change = false, aux; @@ -1565,17 +1722,15 @@ static int bmp380_chip_config(struct bmp280_data *data) * Resets sensor measurement loop toggling between sleep and * normal operating modes. */ - ret = regmap_write_bits(data->regmap, BMP380_REG_POWER_CONTROL, - BMP380_MODE_MASK, - FIELD_PREP(BMP380_MODE_MASK, BMP380_MODE_SLEEP)); + ret = bmp380_set_mode(data, BMP280_SLEEP); if (ret) { dev_err(data->dev, "failed to set sleep mode\n"); return ret; } - usleep_range(2000, 2500); - ret = regmap_write_bits(data->regmap, BMP380_REG_POWER_CONTROL, - BMP380_MODE_MASK, - FIELD_PREP(BMP380_MODE_MASK, BMP380_MODE_NORMAL)); + + usleep_range(data->start_up_time, data->start_up_time + 500); + + ret = bmp380_set_mode(data, BMP280_NORMAL); if (ret) { dev_err(data->dev, "failed to set normal mode\n"); return ret; @@ -1601,6 +1756,17 @@ static int bmp380_chip_config(struct bmp280_data *data) } } + /* Dummy read to empty data registers. */ + ret = bmp380_read_press(data, &tmp); + if (ret) + return ret; + + ret = bmp380_set_mode(data, BMP280_SLEEP); + if (ret) { + dev_err(data->dev, "failed to set sleep mode\n"); + return ret; + } + return 0; } @@ -1693,6 +1859,8 @@ const struct bmp280_chip_info bmp380_chip_info = { .read_temp = bmp380_read_temp, .read_press = bmp380_read_press, .read_calib = bmp380_read_calib, + .set_mode = bmp380_set_mode, + .wait_conv = bmp380_wait_conv, .preinit = bmp380_preinit, .trigger_handler = bmp380_trigger_handler, @@ -2080,6 +2248,65 @@ static int bmp580_preinit(struct bmp280_data *data) return PTR_ERR_OR_ZERO(devm_nvmem_register(config.dev, &config)); } +static int bmp580_set_mode(struct bmp280_data *data, u8 mode) +{ + int ret; + + switch (mode) { + case BMP280_SLEEP: + ret = regmap_write_bits(data->regmap, BMP580_REG_ODR_CONFIG, + BMP580_MODE_MASK, + FIELD_PREP(BMP580_MODE_MASK, + BMP580_MODE_SLEEP)); + break; + case BMP280_FORCED: + ret = regmap_set_bits(data->regmap, BMP580_REG_DSP_CONFIG, + BMP580_DSP_IIR_FORCED_FLUSH); + + ret = regmap_write_bits(data->regmap, BMP580_REG_ODR_CONFIG, + BMP580_MODE_MASK, + FIELD_PREP(BMP580_MODE_MASK, + BMP580_MODE_FORCED)); + break; + case BMP280_NORMAL: + ret = regmap_write_bits(data->regmap, BMP580_REG_ODR_CONFIG, + BMP580_MODE_MASK, + FIELD_PREP(BMP580_MODE_MASK, + BMP580_MODE_NORMAL)); + break; + default: + return -EINVAL; + } + + if (ret) { + dev_err(data->dev, "failed to write power control register\n"); + return ret; + } + + return 0; +} + +static int bmp580_wait_conv(struct bmp280_data *data) +{ + /* + * Taken from datasheet, Section 2 "Specification, Table 3 "Electrical + * characteristics + */ + const int time_conv_press[] = { 0, 1050, 1785, 3045, 5670, 10920, 21420, + 42420, 84420}; + const int time_conv_temp[] = { 0, 1050, 1105, 1575, 2205, 3465, 6090, + 11340, 21840}; + int meas_time; + + meas_time = 4000 + time_conv_temp[data->oversampling_temp] + + time_conv_press[data->oversampling_press]; + + usleep_range(meas_time, meas_time * 12 / 10); + + return 0; +} + + static int bmp580_chip_config(struct bmp280_data *data) { bool change = false, aux; @@ -2150,17 +2377,6 @@ static int bmp580_chip_config(struct bmp280_data *data) return ret; } - /* Restore sensor to normal operation mode */ - ret = regmap_write_bits(data->regmap, BMP580_REG_ODR_CONFIG, - BMP580_MODE_MASK, - FIELD_PREP(BMP580_MODE_MASK, BMP580_MODE_NORMAL)); - if (ret) { - dev_err(data->dev, "failed to set normal mode\n"); - return ret; - } - /* From datasheet's table 4: electrical characteristics */ - usleep_range(3000, 3500); - if (change) { /* * Check if ODR and OSR settings are valid or we are @@ -2256,6 +2472,8 @@ const struct bmp280_chip_info bmp580_chip_info = { .chip_config = bmp580_chip_config, .read_temp = bmp580_read_temp, .read_press = bmp580_read_press, + .set_mode = bmp580_set_mode, + .wait_conv = bmp580_wait_conv, .preinit = bmp580_preinit, .trigger_handler = bmp580_trigger_handler, @@ -2503,6 +2721,16 @@ static int bmp180_read_press(struct bmp280_data *data, u32 *comp_press) return 0; } +static int bmp180_set_mode(struct bmp280_data *data, u8 mode) +{ + return 0; +} + +static int bmp180_wait_conv(struct bmp280_data *data) +{ + return 0; +} + static int bmp180_chip_config(struct bmp280_data *data) { return 0; @@ -2573,6 +2801,8 @@ const struct bmp280_chip_info bmp180_chip_info = { .read_temp = bmp180_read_temp, .read_press = bmp180_read_press, .read_calib = bmp180_read_calib, + .set_mode = bmp180_set_mode, + .wait_conv = bmp180_wait_conv, .trigger_handler = bmp180_trigger_handler, }; @@ -2625,6 +2855,7 @@ static int bmp280_buffer_preenable(struct iio_dev *indio_dev) struct bmp280_data *data = iio_priv(indio_dev); pm_runtime_get_sync(data->dev); + data->chip_info->set_mode(data, BMP280_NORMAL); return 0; } @@ -2795,6 +3026,10 @@ int bmp280_common_probe(struct device *dev, return ret; } + ret = data->chip_info->set_mode(data, BMP280_SLEEP); + if (ret) + return dev_err_probe(dev, ret, "Failed to set sleep mode\n"); + /* Enable runtime PM */ pm_runtime_get_noresume(dev); pm_runtime_set_active(dev); @@ -2820,6 +3055,9 @@ static int bmp280_runtime_suspend(struct device *dev) struct iio_dev *indio_dev = dev_get_drvdata(dev); struct bmp280_data *data = iio_priv(indio_dev); + data->chip_info->set_mode(data, BMP280_SLEEP); + + usleep_range(2500, 3000); return regulator_bulk_disable(BMP280_NUM_SUPPLIES, data->supplies); } diff --git a/drivers/iio/pressure/bmp280.h b/drivers/iio/pressure/bmp280.h index 02647454bd02..93c006c33552 100644 --- a/drivers/iio/pressure/bmp280.h +++ b/drivers/iio/pressure/bmp280.h @@ -170,6 +170,11 @@ #define BMP380_MODE_FORCED 1 #define BMP380_MODE_NORMAL 3 +#define BMP380_MEAS_OFFSET 234 +#define BMP380_MEAS_DUR 2020 +#define BMP380_TEMP_MEAS_OFFSET 163 +#define BMP380_PRESS_MEAS_OFFSET 392 + #define BMP380_MIN_TEMP -4000 #define BMP380_MAX_TEMP 8500 #define BMP380_MIN_PRES 3000000 @@ -206,6 +211,7 @@ #define BMP280_REG_CTRL_MEAS 0xF4 #define BMP280_REG_STATUS 0xF3 #define BMP280_REG_STATUS_IM_UPDATE BIT(0) +#define BMP280_REG_STATUS_MEAS_BIT BIT(3) #define BMP280_REG_RESET 0xE0 #define BMP280_RST_SOFT_CMD 0xB6 @@ -246,6 +252,10 @@ #define BMP280_MODE_FORCED 1 #define BMP280_MODE_NORMAL 3 +#define BMP280_MEAS_OFFSET 1250 +#define BMP280_MEAS_DUR 2300 +#define BMP280_PRESS_HUMID_MEAS_OFFSET 575 + /* BME280 specific registers */ #define BME280_REG_HUMIDITY_LSB 0xFE #define BME280_REG_HUMIDITY_MSB 0xFD @@ -484,6 +494,8 @@ struct bmp280_chip_info { int (*read_humid)(struct bmp280_data *data, u32 *adc_humidity); int (*read_calib)(struct bmp280_data *data); int (*preinit)(struct bmp280_data *data); + int (*set_mode)(struct bmp280_data *data, u8 mode); + int (*wait_conv)(struct bmp280_data *data); irqreturn_t (*trigger_handler)(int irq, void *p); }; From patchwork Thu Jul 11 21:15:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13731076 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 236AE1A08BA; Thu, 11 Jul 2024 21:16:28 +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=1720732589; cv=none; b=KX9Pl6Anv7BEtPnKpgsOBzyTzLd+ZD83tRPw3BYSsFe91WYaYaqEH9tmiOirShI46ffC2R3WOsKdbRaFmWHsmeZ7Urn6SdPsnwZ6CtH5Vpw7n9pKfgkwTBfACbD9nrzfhHAAcUgTSKiBVZBUbmqnIZBddVcUWTfs3mGj8kJgtZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720732589; c=relaxed/simple; bh=MIY4+L0NmEMynecVeO/0pkCJzUVTmZV2u8f7wglj/fg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rGRKUtxhiC5theHgHxnNqw5zEBSfoamO8bNxz+RyhNYs6+U30Qb3RbrCXMVEa3StrCCWiEhCrs/YNBi/nTkEODfbPo5Lo4wttbi8x/4p8GojVD3gp/lxoVN/rpHW/WcdC+4V6xOylU/nTbunZjO+CgKVhwDIL9BdjiwN9rGKmvs= 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=RYo0Fnjf; 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="RYo0Fnjf" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-58b0beaf703so1731598a12.2; Thu, 11 Jul 2024 14:16:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720732586; x=1721337386; 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=qyXjzhY9ezlQQbIjndFy7mwRcLTwO66fXSYZzAg/9+Y=; b=RYo0FnjfS9hmLPqzigoiBIqFINMhk/TDtoUN6pMarOd2f2wTiU9BofCpiFFKWrcCwP ADXgbldIGg/nnJJiMJVFKRCwNz8Wp3+urYJo2FIZbgL10otcEsMrCTa7wJsg3D3O5mdW RvM4hjmZWNhcK5JVEJuDbSaJ3YKBL2MihuNcRDYQsQTmRzxCoOqHC0zkjYXJT+quY7/e +pNwmyRlXSWsqfEdYjwP/uTi4r2s38CbtNaUJZGl/5CoJXX/v1ltlR9gu8YHoeGQubIF 2F1yDiPwQfVoYDwHf2N0Qqgsav/vFG0/qGPOYXBbgPQbWgu1fvGNq2fa+xdWuTV2WcIn RWDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720732586; x=1721337386; 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=qyXjzhY9ezlQQbIjndFy7mwRcLTwO66fXSYZzAg/9+Y=; b=CF6LpfpFuWzbimW2TQLL0RsVHrAYW3lXem+8fSZpLPbTZDWHhxUtNeMKhmkHX4vwPf qTtBt9jZTqtQEl+im+GVnAFs7b623YdNxWLFEFMabXWYIqGl2EqLTZN6/Hgp8PAGSxQB g2J+AMDn90eBAFGIUkqJJk8M1G7jkwBuqlmfUJTUXecbmd+JXKObaOYAS63P9cCZBCtm kt5zbzz1IRoKTOBKhPLiJ/N52NjbN5HbsMnk+ux1fj/3MKL3dS6OlTHx3CW8j7Xn7R2O gnv5QGPohBSJ29nQw1MTrZVReSbWntn1KVJEknDaB3xUWBM6PbrfWuBACjd/RUlLnVyJ QR+Q== X-Forwarded-Encrypted: i=1; AJvYcCWfrU0k1Jcc70dOPR5cfSMGQntdQsKULwRz/dSTlK3PDuHTV3nifLL2biJQkmx9TaXbqtQXPB7TxP2me9HkSeg2iMa/q8gS8d1P20P7dwzz0skF5xzwboE6XBhZlzfLYgBClgw7CGcqQVvGqagUvSa4PVbKSxIrlXcyCX77m+JI9nuVUg== X-Gm-Message-State: AOJu0YyLHYGa6uz+x/l1EY8x0r9xVmBhQ109yorO/JW9CO9l7XN9zxE5 GI1VFQ2rQTDlqYN0wVc3nVQgr9zZHXqT4NkTRRi5KcXdbv9e02Hy X-Google-Smtp-Source: AGHT+IGYbC04IPcy7glc5gF3FWSXRl/0yTHBnXil0eHjKGuw3seH1ySoSv0/yZwVDIaIgI84WVEhQw== X-Received: by 2002:a05:6402:350b:b0:58d:b529:7dc2 with SMTP id 4fb4d7f45d1cf-594b7d836d2mr7914147a12.0.1720732586511; Thu, 11 Jul 2024 14:16:26 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:3e02:47b2:c845:ae3a]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-594bd45a1b6sm3815737a12.60.2024.07.11.14.16.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 14:16:26 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andriy.shevchenko@linux.intel.com Cc: vassilisamir@gmail.com, ang.iglesiasg@gmail.com, linus.walleij@linaro.org, biju.das.jz@bp.renesas.com, javier.carrasco.cruz@gmail.com, semen.protsenko@linaro.org, 579lpy@gmail.com, ak@it-klinger.de, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 08/10] dt-bindings: iio: pressure: bmp085: Add interrupts for BMP3xx and BMP5xx devices Date: Thu, 11 Jul 2024 23:15:56 +0200 Message-Id: <20240711211558.106327-9-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240711211558.106327-1-vassilisamir@gmail.com> References: <20240711211558.106327-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 interrupt options for BMP3xx and BMP5xx devices as well. Signed-off-by: Vasileios Amoiridis --- .../devicetree/bindings/iio/pressure/bmp085.yaml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/iio/pressure/bmp085.yaml b/Documentation/devicetree/bindings/iio/pressure/bmp085.yaml index 6fda887ee9d4..f06f119963bc 100644 --- a/Documentation/devicetree/bindings/iio/pressure/bmp085.yaml +++ b/Documentation/devicetree/bindings/iio/pressure/bmp085.yaml @@ -48,9 +48,20 @@ properties: interrupts: description: - interrupt mapping for IRQ (BMP085 only) + interrupt mapping for IRQ. Supported in BMP085, BMP3xx, BMP5xx maxItems: 1 + interrupt-names: + maxItems: 1 + items: + enum: + - DRDY + + int-open-drain: + desription: + set if the interrupt pin should be configured as open drain. + If not set, defaults to push-pull configuration. + required: - compatible - vddd-supply From patchwork Thu Jul 11 21:15:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13731077 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (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 5D2931A0AF1; Thu, 11 Jul 2024 21:16:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720732591; cv=none; b=XcANpEA1yIbeBberW0tptrYVl5rXfqOpVIbqoaq2bVtBtan2nQ+sscjcXAtHF1oP7+u6fuysBkJ0pVMC/FX4MeQIfxOcZRV9jdhtw6gR3IA9ue1yezHtGtATVWDBecBjSVh6WH+nKSoP/13S2JbxBE61tCPLIz8mHeRCeutUVOY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720732591; c=relaxed/simple; bh=mXlp8AXeYs1aDEecQQhE5xrrli/ravongaTp4YEvJjM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZYbzggS0h7qmZxh54bdhO2Xl3AWOBdD4rx0QHpS8SN4kGK279Zq6615kvXOI4dJYtmOSiRvXw+6p1Pndoxq1N32Rhz/fl/u/IsolGH/clXbhy7RTdNq/U7cvffn+tjZbet0aNVvotMAneznngHb6plSh9v0YagTSsTj0Z36XvcQ= 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=GsgHAtYA; arc=none smtp.client-ip=209.85.208.44 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="GsgHAtYA" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-5854ac817afso1742481a12.2; Thu, 11 Jul 2024 14:16:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720732588; x=1721337388; 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=ERqlFA6Bq2+zv49jpttYmy1q1HQyui34ltOA6nDZRxM=; b=GsgHAtYAkGwRCEL2hwQ2ZHnY+1yRM6r/wa4cM6SetuRfx9gg/4wrCQIHS7eJqDEEVW 9hXfc2nMQl9l/eej4tpSuFIE5BU740/FtdPQok4pxufZJZDxs0FF4iNph24R4a+xZXJk vjYMtZdybujD7G/qDu4EMfYIDh74iJT+hCSR2x93p/7NPdddpHZUxn3V6l+Bq8al9gtE VFPJ/fz2yZAiPo+Z+ot98R+yBJZ8cge52amJ+cYVwiRvPgCVEEX8br/t+DZTfNnvR8aN NNEtMt6CHpo654Tc7JdpEKKOdGFqmN/qpuC1KAezFDgXUHWhzWhpi4yMDlhnPfcJBITX qmLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720732588; x=1721337388; 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=ERqlFA6Bq2+zv49jpttYmy1q1HQyui34ltOA6nDZRxM=; b=GJ64IubndiEBxBJiWt+mhkIa2DA5Azikxxd9KKBqEw/E91ZzC/UFTwQLhVKCaHLl1D a20aOT/JJWiFo9TrCJrKKl3qI7ycSD2d5Yxf4RInwDEmKqWqvFvT3dXCkf9z/3trSRcR j4jkFiPI1/No/rIVa2gM7J2Muw/aRWg/hBmfocXjVoTFh+CxPF343zLMjQAdlnAqBJ+X KVb/892TBWR5s59XxzRz0WZ4eM8xhOoe41YTAIdQP+Fm9qDUP6qGVaqcIwA9LzSYV4zk 88wOiXyQ1gFPuVcqJV3T45C3KmpYbXlw8Q5t6f8x6llmP0qsWIre4cPOH0wSXYwGTL5t fu4g== X-Forwarded-Encrypted: i=1; AJvYcCWcG2RYI1uPnbdPX8jNvq0fuzlnxlBMpPHho5AHskBcFYrXgZwkS/uIxdo4jqwg6J1R+rMVnYcH0sO5ddJ65G0rhC+bpPUjd6AGC1qd6l1NxHtOVorQJxgjUAbf4aIimfUJm9ixZQEQzQX/N5YvJIaAWZUViv10jN5QzwMWVI3IXH0UPQ== X-Gm-Message-State: AOJu0YzyaWKHUT5+tJ8R2laK+yqebSEm5uoDIk911FFbq8725YIQNBFB 9X8+mWaXkPEsJk7+DIu1RoXjbkVfGUMVCXzswX0YDx5JD0WKNQo1 X-Google-Smtp-Source: AGHT+IGm7EgVWvkJNX/R8I+9PeJdcZv20AS+90ljfrjvX7Rk42cZ++VCnMjDtswmCoZdhZb1/VaYDA== X-Received: by 2002:a50:ee93:0:b0:57c:fda3:b669 with SMTP id 4fb4d7f45d1cf-594bb180488mr5340564a12.17.1720732587637; Thu, 11 Jul 2024 14:16:27 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:3e02:47b2:c845:ae3a]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-594bd45a1b6sm3815737a12.60.2024.07.11.14.16.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 14:16: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, ang.iglesiasg@gmail.com, linus.walleij@linaro.org, biju.das.jz@bp.renesas.com, javier.carrasco.cruz@gmail.com, semen.protsenko@linaro.org, 579lpy@gmail.com, ak@it-klinger.de, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 09/10] iio: pressure: bmp280: Add data ready trigger support Date: Thu, 11 Jul 2024 23:15:57 +0200 Message-Id: <20240711211558.106327-10-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240711211558.106327-1-vassilisamir@gmail.com> References: <20240711211558.106327-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The BMP3xx and BMP5xx sensors have an interrupt pin which can be used as a trigger for when there are data ready in the sensor for pick up. This use case is used along with NORMAL_MODE in the sensor, which allows the sensor to do consecutive measurements depending on the ODR rate value. The trigger pin can be configured to be open-drain or push-pull and either rising or falling edge. No support is added yet for interrupts for FIFO, WATERMARK and out of range values. Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-core.c | 271 ++++++++++++++++++++++++++- drivers/iio/pressure/bmp280-regmap.c | 2 +- drivers/iio/pressure/bmp280.h | 23 ++- 3 files changed, 290 insertions(+), 6 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index fc8d42880eb8..ee9b9676ad10 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -37,12 +37,14 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include @@ -1770,6 +1772,129 @@ static int bmp380_chip_config(struct bmp280_data *data) return 0; } +static void bmp380_trigger_reenable(struct iio_trigger *trig) +{ + struct bmp280_data *data = iio_trigger_get_drvdata(trig); + unsigned int tmp; + int ret; + + ret = regmap_read(data->regmap, BMP380_REG_INT_STATUS, &tmp); + if (ret) + dev_err(data->dev, "Failed to reset interrupt\n"); +} + +static int bmp380_data_rdy_trigger_set_state(struct iio_trigger *trig, + bool state) +{ + struct bmp280_data *data = iio_trigger_get_drvdata(trig); + int ret; + + guard(mutex)(&data->lock); + + ret = regmap_update_bits(data->regmap, BMP380_REG_INT_CTRL, + BMP380_INT_CTRL_DRDY_EN, + FIELD_PREP(BMP380_INT_CTRL_DRDY_EN, + state ? 1 : 0)); + if (ret) { + dev_err(data->dev, "Could not enable/disable interrupt\n"); + return ret; + } + + return 0; +} + +static const struct iio_trigger_ops bmp380_trigger_ops = { + .set_trigger_state = &bmp380_data_rdy_trigger_set_state, + .reenable = &bmp380_trigger_reenable, +}; + +static int bmp380_int_config(struct bmp280_data *data) +{ + int ret, int_cfg = FIELD_PREP(BMP380_INT_CTRL_OPEN_DRAIN, + data->trig_open_drain) | + FIELD_PREP(BMP380_INT_CTRL_LEVEL, + data->trig_active_high); + + ret = regmap_update_bits(data->regmap, BMP380_REG_INT_CTRL, + BMP380_INT_CTRL_SETTINGS_MASK, int_cfg); + if (ret) { + dev_err(data->dev, "Could not set interrupt settings\n"); + return ret; + } + + return 0; +} + +static int bmp380_trigger_probe(struct iio_dev *indio_dev) +{ + struct bmp280_data *data = iio_priv(indio_dev); + struct fwnode_handle *fwnode; + int ret, irq, irq_type; + struct irq_data *desc; + + fwnode = dev_fwnode(data->dev); + if (!fwnode) + return -ENODEV; + + irq = fwnode_irq_get_byname(fwnode, "DRDY"); + if (!irq) { + dev_err(data->dev, "No DRDY interrupt found\n"); + return -ENODEV; + } + + desc = irq_get_irq_data(irq); + if (!desc) + return -EINVAL; + + irq_type = irqd_get_trigger_type(desc); + switch (irq_type) { + case IRQF_TRIGGER_RISING: + data->trig_active_high = true; + break; + case IRQF_TRIGGER_FALLING: + data->trig_active_high = false; + break; + default: + dev_err(data->dev, "Invalid interrupt type specified\n"); + return -EINVAL; + } + + data->trig_open_drain = fwnode_property_read_bool(fwnode, + "int-open-drain"); + + ret = bmp380_int_config(data); + if (ret) + return ret; + + data->trig = devm_iio_trigger_alloc(data->dev, "%s-dev%d", + indio_dev->name, + iio_device_id(indio_dev)); + if (!data->trig) + return -ENOMEM; + + data->trig->ops = &bmp380_trigger_ops; + iio_trigger_set_drvdata(data->trig, data); + + ret = devm_request_irq(data->dev, irq, + &iio_trigger_generic_data_rdy_poll, + IRQF_ONESHOT, indio_dev->name, data->trig); + if (ret) { + dev_err(data->dev, "request irq failed\n"); + return ret; + } + + ret = devm_iio_trigger_register(data->dev, data->trig); + if (ret) { + dev_err(data->dev, "iio trigger register failed\n"); + return ret; + } + + indio_dev->trig = iio_trigger_get(data->trig); + + return 0; +} + + static irqreturn_t bmp380_trigger_handler(int irq, void *p) { struct iio_poll_func *pf = p; @@ -1863,6 +1988,7 @@ const struct bmp280_chip_info bmp380_chip_info = { .wait_conv = bmp380_wait_conv, .preinit = bmp380_preinit, + .trigger_probe = bmp380_trigger_probe, .trigger_handler = bmp380_trigger_handler, }; EXPORT_SYMBOL_NS(bmp380_chip_info, IIO_BMP280); @@ -2400,6 +2526,135 @@ static int bmp580_chip_config(struct bmp280_data *data) return 0; } +static void bmp580_trigger_reenable(struct iio_trigger *trig) +{ + struct bmp280_data *data = iio_trigger_get_drvdata(trig); + unsigned int tmp; + int ret; + + ret = regmap_read(data->regmap, BMP580_REG_INT_STATUS, &tmp); + if (ret) + dev_err(data->dev, "Failed to reset interrupt\n"); +} + +static int bmp580_data_rdy_trigger_set_state(struct iio_trigger *trig, + bool state) +{ + struct bmp280_data *data = iio_trigger_get_drvdata(trig); + int ret; + + guard(mutex)(&data->lock); + + ret = regmap_update_bits(data->regmap, BMP580_REG_INT_CONFIG, + BMP580_INT_CONFIG_INT_EN, + FIELD_PREP(BMP580_INT_CONFIG_INT_EN, + state ? 1 : 0)); + if (ret) { + dev_err(data->dev, "Could not enable/disable interrupt\n"); + return ret; + } + + return 0; +} + +static const struct iio_trigger_ops bmp580_trigger_ops = { + .set_trigger_state = &bmp580_data_rdy_trigger_set_state, + .reenable = &bmp580_trigger_reenable, +}; + +static int bmp580_int_config(struct bmp280_data *data) +{ + int ret, int_cfg = FIELD_PREP(BMP580_INT_CONFIG_OPEN_DRAIN, + data->trig_open_drain) | + FIELD_PREP(BMP580_INT_CONFIG_LEVEL, + data->trig_active_high); + + ret = regmap_update_bits(data->regmap, BMP580_REG_INT_CONFIG, + BMP580_INT_CONFIG_MASK, int_cfg); + if (ret) { + dev_err(data->dev, "Could not set interrupt settings\n"); + return ret; + } + + ret = regmap_set_bits(data->regmap, BMP580_REG_INT_SOURCE, + BMP580_INT_SOURCE_DRDY); + if (ret) { + dev_err(data->dev, "Could not set interrupt source\n"); + return ret; + } + + return 0; +} + +static int bmp580_trigger_probe(struct iio_dev *indio_dev) +{ + struct bmp280_data *data = iio_priv(indio_dev); + struct fwnode_handle *fwnode; + int ret, irq, irq_type; + struct irq_data *desc; + + fwnode = dev_fwnode(data->dev); + if (!fwnode) + return -ENODEV; + + irq = fwnode_irq_get_byname(fwnode, "DRDY"); + if (!irq) { + dev_err(data->dev, "No DRDY interrupt found\n"); + return -ENODEV; + } + + desc = irq_get_irq_data(irq); + if (!desc) + return -EINVAL; + + irq_type = irqd_get_trigger_type(desc); + switch (irq_type) { + case IRQF_TRIGGER_RISING: + data->trig_active_high = true; + break; + case IRQF_TRIGGER_FALLING: + data->trig_active_high = false; + break; + default: + dev_err(data->dev, "Invalid interrupt type specified\n"); + return -EINVAL; + } + + data->trig_open_drain = fwnode_property_read_bool(fwnode, + "int-open-drain"); + + ret = bmp580_int_config(data); + if (ret) + return ret; + + data->trig = devm_iio_trigger_alloc(data->dev, "%s-dev%d", + indio_dev->name, + iio_device_id(indio_dev)); + if (!data->trig) + return -ENOMEM; + + data->trig->ops = &bmp580_trigger_ops; + iio_trigger_set_drvdata(data->trig, data); + + ret = devm_request_irq(data->dev, irq, + &iio_trigger_generic_data_rdy_poll, + IRQF_ONESHOT, indio_dev->name, data->trig); + if (ret) { + dev_err(data->dev, "request irq failed\n"); + return ret; + } + + ret = devm_iio_trigger_register(data->dev, data->trig); + if (ret) { + dev_err(data->dev, "iio trigger register failed\n"); + return ret; + } + + indio_dev->trig = iio_trigger_get(data->trig); + + return 0; +} + static irqreturn_t bmp580_trigger_handler(int irq, void *p) { struct iio_poll_func *pf = p; @@ -2476,6 +2731,7 @@ const struct bmp280_chip_info bmp580_chip_info = { .wait_conv = bmp580_wait_conv, .preinit = bmp580_preinit, + .trigger_probe = bmp580_trigger_probe, .trigger_handler = bmp580_trigger_handler, }; EXPORT_SYMBOL_NS(bmp580_chip_info, IIO_BMP280); @@ -3020,10 +3276,17 @@ int bmp280_common_probe(struct device *dev, * however as it happens, the BMP085 shares the chip ID of BMP180 * so we look for an IRQ if we have that. */ - if (irq > 0 && (chip_id == BMP180_CHIP_ID)) { - ret = bmp085_fetch_eoc_irq(dev, name, irq, data); - if (ret) - return ret; + if (irq > 0) { + if (chip_id == BMP180_CHIP_ID) { + ret = bmp085_fetch_eoc_irq(dev, name, irq, data); + if (ret) + return ret; + } + if (data->chip_info->trigger_probe) { + ret = data->chip_info->trigger_probe(indio_dev); + if (ret) + return ret; + } } ret = data->chip_info->set_mode(data, BMP280_SLEEP); diff --git a/drivers/iio/pressure/bmp280-regmap.c b/drivers/iio/pressure/bmp280-regmap.c index d27d68edd906..cccdf8fc6c09 100644 --- a/drivers/iio/pressure/bmp280-regmap.c +++ b/drivers/iio/pressure/bmp280-regmap.c @@ -109,7 +109,7 @@ static bool bmp380_is_writeable_reg(struct device *dev, unsigned int reg) case BMP380_REG_FIFO_WATERMARK_LSB: case BMP380_REG_FIFO_WATERMARK_MSB: case BMP380_REG_POWER_CONTROL: - case BMP380_REG_INT_CONTROL: + case BMP380_REG_INT_CTRL: case BMP380_REG_IF_CONFIG: case BMP380_REG_ODR: case BMP380_REG_OSR: diff --git a/drivers/iio/pressure/bmp280.h b/drivers/iio/pressure/bmp280.h index 93c006c33552..73d0d25ae0f4 100644 --- a/drivers/iio/pressure/bmp280.h +++ b/drivers/iio/pressure/bmp280.h @@ -55,8 +55,17 @@ #define BMP580_CMD_NVM_WRITE_SEQ_1 0xA0 #define BMP580_CMD_SOFT_RESET 0xB6 +#define BMP580_INT_STATUS_DRDY_MASK BIT(0) #define BMP580_INT_STATUS_POR_MASK BIT(4) +#define BMP580_INT_SOURCE_DRDY BIT(0) + +#define BMP580_INT_CONFIG_MASK GENMASK(3, 0) +#define BMP580_INT_CONFIG_LATCH BIT(0) +#define BMP580_INT_CONFIG_LEVEL BIT(1) +#define BMP580_INT_CONFIG_OPEN_DRAIN BIT(2) +#define BMP580_INT_CONFIG_INT_EN BIT(3) + #define BMP580_STATUS_CORE_RDY_MASK BIT(0) #define BMP580_STATUS_NVM_RDY_MASK BIT(1) #define BMP580_STATUS_NVM_ERR_MASK BIT(2) @@ -117,7 +126,7 @@ #define BMP380_REG_OSR 0x1C #define BMP380_REG_POWER_CONTROL 0x1B #define BMP380_REG_IF_CONFIG 0x1A -#define BMP380_REG_INT_CONTROL 0x19 +#define BMP380_REG_INT_CTRL 0x19 #define BMP380_REG_INT_STATUS 0x11 #define BMP380_REG_EVENT 0x10 #define BMP380_REG_STATUS 0x03 @@ -175,6 +184,14 @@ #define BMP380_TEMP_MEAS_OFFSET 163 #define BMP380_PRESS_MEAS_OFFSET 392 +#define BMP380_INT_STATUS_DRDY BIT(3) + +#define BMP380_INT_CTRL_SETTINGS_MASK GENMASK(2, 0) +#define BMP380_INT_CTRL_OPEN_DRAIN BIT(0) +#define BMP380_INT_CTRL_LEVEL BIT(1) +#define BMP380_INT_CTRL_LATCH BIT(2) +#define BMP380_INT_CTRL_DRDY_EN BIT(6) + #define BMP380_MIN_TEMP -4000 #define BMP380_MAX_TEMP 8500 #define BMP380_MIN_PRES 3000000 @@ -399,6 +416,9 @@ struct bmp280_data { struct regmap *regmap; struct completion done; bool use_eoc; + bool trig_open_drain; + bool trig_active_high; + struct iio_trigger *trig; const struct bmp280_chip_info *chip_info; union { struct bmp180_calib bmp180; @@ -497,6 +517,7 @@ struct bmp280_chip_info { int (*set_mode)(struct bmp280_data *data, u8 mode); int (*wait_conv)(struct bmp280_data *data); + int (*trigger_probe)(struct iio_dev *indio_dev); irqreturn_t (*trigger_handler)(int irq, void *p); }; From patchwork Thu Jul 11 21:15:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13731078 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52EE71A08C3; Thu, 11 Jul 2024 21:16:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720732592; cv=none; b=QmvEGAFU/cCzOmtlb7BB+1NzPlgZxoRvjegP57Lhoaclt07rPrPWEQ52n1iU/5THyqM9vqPacXjGRwXj8ktTC24RfIvEL9SUx+g/xp6KB/abBOFB8bhbAc5NU99xHfDaJfzfLrlT3Exn2/nkZY+yiSU69JroX8j6R87JTFv6G6Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720732592; c=relaxed/simple; bh=aSBhTkkoLHZFWl60nBtEjUz2JQQz1WXc3mxknELd6WE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PPKz2J1l06z0cJwpta8H2P5cENs/1KF2mrSEjPU++7fC3r2QpcHb+jh9TNZ4pqpUOnpegh/BvGuRYCLAgjQ7D9qtiKIFonAcPBdBUZ6W/GcBbZiktPsDecZSe/Tg6deyywBMfNsygL17/n1aos+W5jf0GOXAR8tCBlTWVOP5WXk= 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=L+vA9+1t; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="L+vA9+1t" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-595856e2336so2235134a12.1; Thu, 11 Jul 2024 14:16:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720732589; x=1721337389; 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=JCKKw6ZGeRpSiHrVmvFeUrR/FKl0FfFZJqKXYoh168A=; b=L+vA9+1tHVSIBKtvjlFReVowz8Lggid7v/Rf/i0yJRwIvOcSCZriI57TwrbAZiBsyP hPGESLuWuWduru0YnZxkhDdjoEIj3Sx/YvaYXWqFeeh45SQLDQFgvQXtdMPx1Wd2cFjL TLuyu5eIUaC65q8MLLvo3uJoGDzuEO9ZSWnXL/guSJ5Fso45cfv/ttOc5hGQqqeEV9mQ 73sMti52LUVPAGFHC5TLDBO8x/Q9+SjyvFf2YbsJmI8j6ab7ucLKc6QZ3TNI9k+77/yM SNKiJHtFVEC7Iglv2LKgikcj+9BjcU4KX7XJBXwclrH6FaGUhATIxSwIDI22wA3klNSW bz2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720732589; x=1721337389; 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=JCKKw6ZGeRpSiHrVmvFeUrR/FKl0FfFZJqKXYoh168A=; b=g6xPyEH+QvPsaflKLy+8m/ulsN1ZPBWGFhixKqwLIDU6hH0iS/Yjjjx5wK1t5rBVFU Me5SnWD21NbQCRZcAPLJyJ33RHVtLsuk2h9xY5tyWlRXjDOOjR+/viFN4auQ2LRjbNmi AcOIETsI03xiRvykKB/4oFdPB6bGQ0KrGCKjzSQ0nE+PloSXRHo+l+N9YqAx68YNPRyi QbEeGRJ+EGw8OJQOE/Cbjm+2RzgxrCRNHq4c5x6QIT3U/9cRBgNhtg/rJu+FVXD6HFsA wSXFNvc+uLG4qgH99rLZNPgxeS/UXyNVq4Nxq5dNEYWSmaaF6wwDZeBGvPRzfqPaeGQ+ awmA== X-Forwarded-Encrypted: i=1; AJvYcCUtIqwsuLO1rkoqXP2JfjfCF4myasHQEkEEdsK/edjK+hSaLi/X4qBy192PCs52F4b4daXoVKhdiWqIFVXAdR08Q8Trd5siKvefVlAD9JFt2XUKtugg+CtI427OwCMysOb8flM+HvPo5cn5YyO1u3F/ECv4DBIr8TFxAOZT6HrPbdHTog== X-Gm-Message-State: AOJu0YwDeARt3nFnRfjsHF9N1jwP2SpaDH3QXh/tCH3b5YNPM0Ihi6sN Y1GBbW6l1J8Cuerhcxy4rsmQdkU7IlVe380maHa0TEUAv8K2qk4h X-Google-Smtp-Source: AGHT+IGE4NWKCAqde8ANroEgTkk0EAevT8quSYx4DopJTl9SwToGdvgXUADw+1bALN6TzndvFNmHhA== X-Received: by 2002:a05:6402:2107:b0:58c:36e:51bf with SMTP id 4fb4d7f45d1cf-59963bf43a4mr693987a12.3.1720732588654; Thu, 11 Jul 2024 14:16:28 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:3e02:47b2:c845:ae3a]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-594bd45a1b6sm3815737a12.60.2024.07.11.14.16.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 14:16:28 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andriy.shevchenko@linux.intel.com Cc: vassilisamir@gmail.com, ang.iglesiasg@gmail.com, linus.walleij@linaro.org, biju.das.jz@bp.renesas.com, javier.carrasco.cruz@gmail.com, semen.protsenko@linaro.org, 579lpy@gmail.com, ak@it-klinger.de, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 10/10] iio: pressure bmp280: Move bmp085 interrupt to new configuration Date: Thu, 11 Jul 2024 23:15:58 +0200 Message-Id: <20240711211558.106327-11-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240711211558.106327-1-vassilisamir@gmail.com> References: <20240711211558.106327-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This commit intends to add the old BMP085 sensor to the new IRQ interface of the sensor consistence. No functional changes intended. The BMP085 sensor is equivalent with the BMP180 with the only difference of BMP085 having an extra interrupt pin to inform about an End of Conversion. Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-core.c | 72 +++++++++++++++++++++++------- drivers/iio/pressure/bmp280-i2c.c | 4 +- drivers/iio/pressure/bmp280-spi.c | 4 +- drivers/iio/pressure/bmp280.h | 1 + 4 files changed, 60 insertions(+), 21 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index ee9b9676ad10..f0443016a2f7 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -3073,13 +3073,19 @@ static irqreturn_t bmp085_eoc_irq(int irq, void *d) return IRQ_HANDLED; } -static int bmp085_fetch_eoc_irq(struct device *dev, - const char *name, - int irq, - struct bmp280_data *data) +static int bmp085_trigger_probe(struct iio_dev *indio_dev) { + struct bmp280_data *data = iio_priv(indio_dev); + struct device *dev = data->dev; + struct fwnode_handle *fwnode; unsigned long irq_trig; - int ret; + int ret, irq; + + fwnode = dev_fwnode(data->dev); + if (!fwnode) + return -ENODEV; + + irq = fwnode_irq_get(fwnode, 0); irq_trig = irqd_get_trigger_type(irq_get_irq_data(irq)); if (irq_trig != IRQF_TRIGGER_RISING) { @@ -3089,13 +3095,12 @@ static int bmp085_fetch_eoc_irq(struct device *dev, init_completion(&data->done); - ret = devm_request_threaded_irq(dev, - irq, - bmp085_eoc_irq, - NULL, - irq_trig, - name, - data); + ret = devm_request_irq(dev, + irq, + bmp085_eoc_irq, + irq_trig, + indio_dev->name, + data); if (ret) { /* Bail out without IRQ but keep the driver in place */ dev_err(dev, "unable to request DRDY IRQ\n"); @@ -3106,6 +3111,44 @@ static int bmp085_fetch_eoc_irq(struct device *dev, return 0; } +const struct bmp280_chip_info bmp085_chip_info = { + .id_reg = bmp180_chip_info.id_reg, + .chip_id = bmp180_chip_info.chip_id, + .num_chip_id = bmp180_chip_info.num_chip_id, + .regmap_config = bmp180_chip_info.regmap_config, + .start_up_time = bmp180_chip_info.start_up_time, + .channels = bmp180_chip_info.channels, + .num_channels = bmp180_chip_info.num_channels, + .avail_scan_masks = bmp180_chip_info.avail_scan_masks, + + .oversampling_temp_avail = bmp180_chip_info.oversampling_temp_avail, + .num_oversampling_temp_avail = + bmp180_chip_info.num_oversampling_temp_avail, + .oversampling_temp_default = bmp180_chip_info.oversampling_temp_default, + + .oversampling_press_avail = bmp180_chip_info.oversampling_press_avail, + .num_oversampling_press_avail = + bmp180_chip_info.num_oversampling_press_avail, + .oversampling_press_default = + bmp180_chip_info.oversampling_press_default, + + .temp_coeffs = bmp180_chip_info.temp_coeffs, + .temp_coeffs_type = bmp180_chip_info.temp_coeffs_type, + .press_coeffs = bmp180_chip_info.press_coeffs, + .press_coeffs_type = bmp180_chip_info.press_coeffs_type, + + .chip_config = bmp180_chip_info.chip_config, + .read_temp = bmp180_chip_info.read_temp, + .read_press = bmp180_chip_info.read_press, + .read_calib = bmp180_chip_info.read_calib, + .set_mode = bmp180_chip_info.set_mode, + .wait_conv = bmp180_chip_info.wait_conv, + + .trigger_probe = bmp085_trigger_probe, + .trigger_handler = bmp180_trigger_handler, +}; +EXPORT_SYMBOL_NS(bmp085_chip_info, IIO_BMP280); + static int bmp280_buffer_preenable(struct iio_dev *indio_dev) { struct bmp280_data *data = iio_priv(indio_dev); @@ -3277,11 +3320,6 @@ int bmp280_common_probe(struct device *dev, * so we look for an IRQ if we have that. */ if (irq > 0) { - if (chip_id == BMP180_CHIP_ID) { - ret = bmp085_fetch_eoc_irq(dev, name, irq, data); - if (ret) - return ret; - } if (data->chip_info->trigger_probe) { ret = data->chip_info->trigger_probe(indio_dev); if (ret) diff --git a/drivers/iio/pressure/bmp280-i2c.c b/drivers/iio/pressure/bmp280-i2c.c index 5c3a63b4327c..2f7b25984c7b 100644 --- a/drivers/iio/pressure/bmp280-i2c.c +++ b/drivers/iio/pressure/bmp280-i2c.c @@ -27,7 +27,7 @@ static int bmp280_i2c_probe(struct i2c_client *client) } static const struct of_device_id bmp280_of_i2c_match[] = { - { .compatible = "bosch,bmp085", .data = &bmp180_chip_info }, + { .compatible = "bosch,bmp085", .data = &bmp085_chip_info }, { .compatible = "bosch,bmp180", .data = &bmp180_chip_info }, { .compatible = "bosch,bmp280", .data = &bmp280_chip_info }, { .compatible = "bosch,bme280", .data = &bme280_chip_info }, @@ -38,7 +38,7 @@ static const struct of_device_id bmp280_of_i2c_match[] = { MODULE_DEVICE_TABLE(of, bmp280_of_i2c_match); static const struct i2c_device_id bmp280_i2c_id[] = { - {"bmp085", (kernel_ulong_t)&bmp180_chip_info }, + {"bmp085", (kernel_ulong_t)&bmp085_chip_info }, {"bmp180", (kernel_ulong_t)&bmp180_chip_info }, {"bmp280", (kernel_ulong_t)&bmp280_chip_info }, {"bme280", (kernel_ulong_t)&bme280_chip_info }, diff --git a/drivers/iio/pressure/bmp280-spi.c b/drivers/iio/pressure/bmp280-spi.c index d18549d9bb64..49aa8c2cd85b 100644 --- a/drivers/iio/pressure/bmp280-spi.c +++ b/drivers/iio/pressure/bmp280-spi.c @@ -114,7 +114,7 @@ static int bmp280_spi_probe(struct spi_device *spi) } static const struct of_device_id bmp280_of_spi_match[] = { - { .compatible = "bosch,bmp085", .data = &bmp180_chip_info }, + { .compatible = "bosch,bmp085", .data = &bmp085_chip_info }, { .compatible = "bosch,bmp180", .data = &bmp180_chip_info }, { .compatible = "bosch,bmp181", .data = &bmp180_chip_info }, { .compatible = "bosch,bmp280", .data = &bmp280_chip_info }, @@ -126,7 +126,7 @@ static const struct of_device_id bmp280_of_spi_match[] = { MODULE_DEVICE_TABLE(of, bmp280_of_spi_match); static const struct spi_device_id bmp280_spi_id[] = { - { "bmp085", (kernel_ulong_t)&bmp180_chip_info }, + { "bmp085", (kernel_ulong_t)&bmp085_chip_info }, { "bmp180", (kernel_ulong_t)&bmp180_chip_info }, { "bmp181", (kernel_ulong_t)&bmp180_chip_info }, { "bmp280", (kernel_ulong_t)&bmp280_chip_info }, diff --git a/drivers/iio/pressure/bmp280.h b/drivers/iio/pressure/bmp280.h index 73d0d25ae0f4..1c1e3001efc9 100644 --- a/drivers/iio/pressure/bmp280.h +++ b/drivers/iio/pressure/bmp280.h @@ -522,6 +522,7 @@ struct bmp280_chip_info { }; /* Chip infos for each variant */ +extern const struct bmp280_chip_info bmp085_chip_info; extern const struct bmp280_chip_info bmp180_chip_info; extern const struct bmp280_chip_info bmp280_chip_info; extern const struct bmp280_chip_info bme280_chip_info;