From patchwork Mon Sep 2 18:42:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13787627 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (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 0314719CC11; Mon, 2 Sep 2024 18:42:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725302550; cv=none; b=mqR6tugpN1M+iOGpQOULzfoLq2M2/QotXXBLB8Yu2x4OQg0mG/X5cJxGogOLZA8G8P6GSwSPLJsCTpUCcTBh77uUEIlt/cHgCANDaxFju/ZqVFDgOqRma6KVD7RYgJSOO/xQYoLVEJ8QAc4ZdkfSHo6e5j+Z5YIBxNSaz0cxKw4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725302550; c=relaxed/simple; bh=HOK0g8c+oxKQNNbxQsPOZaeb4IYAdSGXTp+hdXNkatc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lu8A8scmxjdTwFHkzRh8nbi5rriakI0qCqFtq/+pWyO4xyeftHcT2sGYXJqoM4lPVURI0tMYup4T+HeAPBxPhAuuQCZUSuTsTrFTZeuuUAIQ+5Ur7cXSr4WVN1pC9n6LuTJyGEN9ikHoep+zcOJHvjsQBxDMCGlXhdJRw//RGaY= 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=lDR6r2S5; arc=none smtp.client-ip=209.85.208.46 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="lDR6r2S5" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-5c241feb80dso4462145a12.0; Mon, 02 Sep 2024 11:42:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725302547; x=1725907347; 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=7qOPxrqYeKueDE+9V5z0BX1gKk66+Q3HbGFskdXy1+o=; b=lDR6r2S5nacACxtmE+4bOjqOqI33lTwOIlcy7z5ZvlULVwUrhv4gy8cz31zVFAwt4A Ralg7S/P95bJv15D0SNXumqVp9rIO196jdLtCByk80SdH+317t7SvppD1RW8RaZVRy6I 9bevWEou9cD8rxni8d/r+IP52kBrgEh7xvYdZpSFWq37vrMI+49OCQzIzJYRIwuFyNUJ oLUb0/Ao6bLf/ntKXoi7L3IJcNRFCbYIO33YYYgQsACO4YP6zh1kOkv946P2c3q21zmZ FbHpmerPjeQ6n3iwaPgLUmFSC0jj1bfotTTz8Z2RTLiO5fDTiu3QzYmC7khGjmQqCWYx doiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725302547; x=1725907347; 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=7qOPxrqYeKueDE+9V5z0BX1gKk66+Q3HbGFskdXy1+o=; b=ar8yoDFO7RXfR6KNi7IqBVYstjr6+jb++1zM/yGSqgaeuSljx0cANFAF3RzsJ/gLs/ 8oEriquA+E05THMQQVfQwdD2wMhqJyZuCIwfH/5hJ3cfHGSQhNL8T6rZsE7KnTqo634h s5QOFA/9AMCNfxLFdRIsKL8tLhW9dNRBJj+5wYwO7MYvCpRcCZA9J1RSeyGLAKgEWDEP u1xr/9+qhB5fQjytKQFaXaxWWI2sh1bdz+Y8RA3QmBkn2+5lwonjjEv4BCmZZORKQhtC ktqxV1SjIWjLh0Q6O27HHo6FERmAYuNUvkwg3bPNxQ7XUR/K7Fh2opypP2QWE9yR1wvF Y9VQ== X-Forwarded-Encrypted: i=1; AJvYcCU0cCkuVeZJCworGeqSdODJ1ponT5qWHvpRSzBe7U4q61DOHQaDqV0XUnNQP+ITrP2XmooVIMlYXXoCnb33@vger.kernel.org, AJvYcCUPzrfzr4tJdwhbUhhjmN6QCG7kVB2JkGB89wcRe5B7l2l4jvNNybIHBP10AV+gPYZR1koPQlNv8fKG@vger.kernel.org, AJvYcCXXhMwW+2Kph2DnpeqwgMbHzATJNtOs9XG4xMfvr1QA20tH9NtwRyrkZl0UCr25UcXbqBz+2cg66s0r@vger.kernel.org X-Gm-Message-State: AOJu0YyNr/l7KhFsgIZ1w8KB3ceBVrpOmN9r0Zt+qOF9FeDhYhZQjQdY JZafxuCYTJOlUSxpU8gjRgMkczAfZYiqRsbVbgcglz6QuhCxT5IY X-Google-Smtp-Source: AGHT+IE95YWHgElKEcuGFQyi9I2WZjUWGW4BqeJGxmsJ4wWGcUjXyJVAuQnYgNGlh7KFmTqhOPamJQ== X-Received: by 2002:a17:907:3e84:b0:a86:b448:cbe with SMTP id a640c23a62f3a-a89823c984amr1421166566b.10.1725302546680; Mon, 02 Sep 2024 11:42:26 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:bc14:b544:1196:d1a]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a898900ec0asm590537966b.53.2024.09.02.11.42.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 11:42: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, christophe.jaillet@wanadoo.fr Subject: [PATCH v5 1/7] iio: pressure: bmp280: Use bulk read for humidity calibration data Date: Mon, 2 Sep 2024 20:42:16 +0200 Message-Id: <20240902184222.24874-2-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240902184222.24874-1-vassilisamir@gmail.com> References: <20240902184222.24874-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 | 63 +++++++++++------------------- drivers/iio/pressure/bmp280.h | 6 +++ 2 files changed, 28 insertions(+), 41 deletions(-) base-commit: 0f718e10da81446df0909c9939dff2b77e3b4e95 prerequisite-patch-id: e4f81f31f4fbb2aa872c0c74ed4511893eee0c9a diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 8383d1a73cf9..3b221e16aa42 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -340,10 +340,19 @@ static int bmp280_read_calib(struct bmp280_data *data) return 0; } +/* + * These enums are used for indexing into the array of humidity parameters + * for BME280. Due to some weird indexing, unaligned BE/LE accesses co-exist in + * order to prepare the FIELD_{GET/PREP}() fields. Table 16 in Section 4.2.2 of + * the datasheet. + */ +enum { H2 = 0, H3 = 2, H4 = 3, H5 = 4, H6 = 6 }; + 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, tmp_1, tmp_2, tmp_3; unsigned int tmp; int ret; @@ -352,14 +361,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 +369,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)); + data->bme280_humid_cal_buf, + sizeof(data->bme280_humid_cal_buf)); if (ret) { - dev_err(dev, "failed to read H4 comp value\n"); + dev_err(dev, "failed to read humidity calibration values\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)); - if (ret) { - dev_err(dev, "failed to read H5 comp value\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]; + tmp_1 = get_unaligned_be16(&data->bme280_humid_cal_buf[H4]); + tmp_2 = FIELD_GET(BME280_COMP_H4_GET_MASK_UP, tmp_1); + h4_upper = FIELD_PREP(BME280_COMP_H4_PREP_MASK_UP, tmp_2); + h4_lower = FIELD_GET(BME280_COMP_H4_MASK_LOW, tmp_1); + calib->H4 = sign_extend32(h4_upper | h4_lower, 11); + tmp_3 = get_unaligned_le16(&data->bme280_humid_cal_buf[H5]); + calib->H5 = sign_extend32(FIELD_GET(BME280_COMP_H5_MASK, tmp_3), 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 a853b6d5bdfa..4e675401d61b 100644 --- a/drivers/iio/pressure/bmp280.h +++ b/drivers/iio/pressure/bmp280.h @@ -257,8 +257,13 @@ #define BME280_REG_COMP_H5 0xE5 #define BME280_REG_COMP_H6 0xE7 +#define BME280_COMP_H4_GET_MASK_UP GENMASK(15, 8) +#define BME280_COMP_H4_PREP_MASK_UP GENMASK(11, 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 @@ -426,6 +431,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 Mon Sep 2 18:42:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13787628 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1EDED1C62AB; Mon, 2 Sep 2024 18:42:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725302551; cv=none; b=jAfQJMoIMdCCm1QJgSQNRm8xdMZgoOxV86ISdXE11+aiD8zJVI9oyvKopPiZD6kUKfPYszqS91M2B7YZW4b+D6wFFF7Lck/CDzFwM5w1cXWLqpxz+9nTN7WQ1kTbnH/a78GMbV08nMaKcIE2iqZKVy1xXFTCK1uFO+BirPU/zP0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725302551; c=relaxed/simple; bh=QyAVJGMiAY2LFK4Kijid6vcfHvf1Mrht5kDDvvp6A04=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IEn7Nju6iLl43mVSUEeafB+oRyr70PxmhgrbRV+pGaJkZN1fqG+DUdBt9Jc7NF99Hxiun9bFN5OuLE2h6fJhYyL1muqIRO+2Qb1eSoaYrN3Orhz2ppNAPZobf6RAzVrkZpyAuaY5do7u5uwOyJw8Tpni9SV/MBC9TDKNpZ9WtmI= 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=IjQPp7g+; arc=none smtp.client-ip=209.85.208.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IjQPp7g+" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-5c241feb80dso4462172a12.0; Mon, 02 Sep 2024 11:42:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725302548; x=1725907348; 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=NxkS+G4/mG3C/JwlvfIOcjaZNNcAt8BK5nQ0rGeJ7ik=; b=IjQPp7g+2/8EkBFxAqoqoI8ath1Azr/wl/+PwJcVcomZkzS1FDSfumTmgaLVNbjaBP BuE07NcmlZXbyJDId3DcaEQVlnnU2RQRuW9sHm3XypWj5PZ7lzPhK4wcUKwSVc6hsDe7 oMZ1u3jfwqebeVD0WWyRjsuVkCplWf8ya9WVJocDTd/XXVAXMj6HD6Yp3tdb5OF7od2T 4+csSAk4+DCVujklwhntA2rOiEjNCsFvM9Yos2PbiSbtwzVAj66IyPAgRy2yT0gdbIrt Dp94Wh/IeEk3FOFfzeZxDfmAyttkYWgiwh/HJRojtB6EBC/rTfvMtUw5Ox8xf7Qke1fJ GXNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725302548; x=1725907348; 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=NxkS+G4/mG3C/JwlvfIOcjaZNNcAt8BK5nQ0rGeJ7ik=; b=aZ9/NGRXcO2B4v5MLhZiaFh30u3mrfdLHWMaLUT7BMfc9f5J5eTTcDaDF18hAMqqJm L/UGISPNz0MUKXdPZSbfoKj4P6LqYdAj/V3ImFieNHRY3nBWHvgvRG12R7g7FumTYDI6 W0Vdrzyun0WbfMmNjW5aoHN6T09J9rWHAO23RyawvZAzH5nuV2XFx5sjZ4Wbu4wfD6Tm 9DyaHq+LNU+mWLvefckr7/RA8k/k6myuGP1uSEz3uSBPZkHKvMzc7prlCfk8XZEobawB 8hK5nh4DSCwJIx9dQpLmayXs63W2wreg8SvAh8FJN2OhlQ4eDxZP5Hq3OR2lHFCLSDmZ Y7zA== X-Forwarded-Encrypted: i=1; AJvYcCVK2JipU1xXTmnZrvB+K/vbeuMqaOM2NDMhaFbXcoGyvDXhGjh0lq0YEL5bbRyF3EjZ/fnD6oNqk444@vger.kernel.org, AJvYcCVsxUUfvPu8Kb5BJi2Tm365v6xlOF1EoJAQ07FQnKP/9CMUIaNRfCshT6PLwTzMRqLBkxrXqE3m4Uxu+1+c@vger.kernel.org, AJvYcCXD9jBuhKIpC1NP5Iz1cO+Le4FMs+h0rWqMb8f/zKy7Mk2yc0s189MANOJnN647UCmffrnHHSLqt/uw@vger.kernel.org X-Gm-Message-State: AOJu0Yy3z4J0Ur7fU2/771Ko9WkOSFbHLPd6LgTnu+B7GVpqM2rYp9OW 3UCz5/vpSYeriFOgb4q8r9WoxfXYBLo31YEzH9iZwFc6ymo1HzWmyuy8Zci6Sew= X-Google-Smtp-Source: AGHT+IEnVfm9q127Nc664sYpi9I18/xqg8GawB8oiKwgk/iVnqmY/YwBTFR3zcPraNY513eUjfC5NA== X-Received: by 2002:a17:907:7f27:b0:a86:e168:609f with SMTP id a640c23a62f3a-a89a1fdd5f7mr1187633066b.0.1725302547804; Mon, 02 Sep 2024 11:42:27 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:bc14:b544:1196:d1a]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a898900ec0asm590537966b.53.2024.09.02.11.42.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 11:42: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, christophe.jaillet@wanadoo.fr Subject: [PATCH v5 2/7] iio: pressure: bmp280: Add support for bmp280 soft reset Date: Mon, 2 Sep 2024 20:42:17 +0200 Message-Id: <20240902184222.24874-3-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240902184222.24874-1-vassilisamir@gmail.com> References: <20240902184222.24874-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 | 29 +++++++++++++++++++++++++++++ drivers/iio/pressure/bmp280.h | 3 +++ 2 files changed, 32 insertions(+) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 3b221e16aa42..cd975fad2753 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -964,6 +964,33 @@ static const unsigned long bme280_avail_scan_masks[] = { 0 }; +static int bmp280_preinit(struct bmp280_data *data) +{ + struct device *dev = data->dev; + unsigned int reg; + int ret; + + ret = regmap_write(data->regmap, BMP280_REG_RESET, BMP280_RST_SOFT_CMD); + if (ret) + return dev_err_probe(dev, ret, "Failed to reset device.\n"); + + /* + * According to the datasheet in Chapter 1: Specification, Table 2, + * after resetting, the device uses the complete power-on sequence so + * it needs to wait for the defined start-up time. + */ + fsleep(data->start_up_time); + + ret = regmap_read(data->regmap, BMP280_REG_STATUS, ®); + if (ret) + return dev_err_probe(dev, ret, "Failed to read status register.\n"); + + if (reg & BMP280_REG_STATUS_IM_UPDATE) + return dev_err_probe(dev, -EIO, "Failed to copy NVM contents.\n"); + + return 0; +} + static int bmp280_chip_config(struct bmp280_data *data) { u8 osrs = FIELD_PREP(BMP280_OSRS_TEMP_MASK, data->oversampling_temp + 1) | @@ -1081,6 +1108,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, }; @@ -1201,6 +1229,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 4e675401d61b..73516878d020 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 Mon Sep 2 18:42:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13787629 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.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 6BF021D54FA; Mon, 2 Sep 2024 18:42:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725302554; cv=none; b=LdE/MMDilRWML3lbLeLRthpjoGutsweeRNdBt2pHBLBAD6SEFs9hEVHJiCsjdkbTWpkk9irPRNJJC0Q5IaSeHEuB9P9mRz0GZ+5xNg9iruZxQW4YeDK4swGnfDkxl3gPGiNP47go25aShUTgS09jcLtIPryNsT0Fc1V73W2BEmY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725302554; c=relaxed/simple; bh=lVC7WlN7YckA2mM8wFj8qrXa0WB/KGPHOOm8UvTq8Ek=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=egXz0tsVqlhBDts3VG71oD3h1Oml9+uuswCIxnsCuPEX0T0JTrFUNfLR90ZMH9EQ+v5KcisSOP2mJChFCCIaeuORME8QSe10nJQq4Yrn5zoDsydVs0KZJ2J+zs0zh4cl0MFuGAEgZp034NxeYx27CU4611UHcfR+KhTwVJFhP9s= 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=LFVOdIit; arc=none smtp.client-ip=209.85.218.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="LFVOdIit" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a8692bbec79so510275266b.3; Mon, 02 Sep 2024 11:42:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725302550; x=1725907350; 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=Yvk2TMmuGsaW1+rcNYCCXTK4HcycwNpIaYWePsGt+E0=; b=LFVOdIitJGsOltl4bNEgmBs9B4UO+inzpmG+wXy6eX448TifZPfAxsvMCB9AgHQ5ym ZHiJ4CSM2A7UH4c9hH3fp+lA20INwekgwS2xZVWWHvQ0PfGZRvcnX+7nMOecEyjO9OW3 6lCL7Wm0M2AKfB8bfVHxwDkBh3f3YjwB7lJ9lr5MnKbnxAQxjEPXBKWASnPL422lBzAs WVer30wrgbOahCtPBp3iFWNqbnH/tE9uvesO/KAN/RzU9unhvZugHjyWjmiRz0z5FsTG LeQDwWNlfCNTc88ApHrRexbso8WeK/0E1o/ajn1Qi0FGRRY1q9r2J5DrmBo7B+i4C2M1 vlxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725302550; x=1725907350; 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=Yvk2TMmuGsaW1+rcNYCCXTK4HcycwNpIaYWePsGt+E0=; b=LaHdc+u42ftCuP1HpfE79bsmiFWWNDzS2IBImtXVwyIgqq6PdLuwInAwKbw8XjTxnf lPclivwesmCQUVp6RCX6fa+d2uykeZxkCCM+Tj//4AOwanvnapoYgWRE3RMJ+pgVH3C1 +artl9XPDiC6E55dJmylmflwN3xYUTD/iDmHwUbcLAMeEim+z7/XcPEVQGmkd8Gj7X8U y3m2gJ90IbiaNmuQqtFTeStCzhOhPqei5ucZOenn8u4om2Iwx63JimO6iBvjW3DHBE6D skLcblHoP9oRgzyNgY2g6t4MqNqAGYhQqakmnbI7xUFivx9Z3h3sEC2suVrtCrxVZIU/ DGYA== X-Forwarded-Encrypted: i=1; AJvYcCVOqsnrytTOUuPQrdBls8Dumg3+ZlXsSfjcCFof+S+q3nuIt8nAUAzdWuP61NuOWrXs99ZgZKaL9ZPFHvJA@vger.kernel.org, AJvYcCVSIqwAcl6nreNqeVH42NHxSr3hzjjCzrrdjKzbPUfOsernbE9Ake+AAutnk3BFjkqxS4sxd9hwU6ii@vger.kernel.org, AJvYcCXat73kMC2I3Ua3CO8qFZoY6otfNmQjoVfXLlCqK8k6m8mDsNtwz9BJ/O5wyN5PKHbpIOF7/J7db3z2@vger.kernel.org X-Gm-Message-State: AOJu0Yz6IepKMrO0CJHJbRcI50BHbbC81n8OtCvwjQi4sTyOuM8SSKKe J5tOL+EQBkYq5XNJyxspDrFlYAz35mEB9ZqZFzGeihc6qPRXC9B5 X-Google-Smtp-Source: AGHT+IHe8YUfrEPyU3d6xE8V5nUPszHrEqi/Q4L2hZGuDGXWs005Bh05PMD4GrgbjGCFrx2PtA+WYg== X-Received: by 2002:a17:907:1b97:b0:a89:b820:335 with SMTP id a640c23a62f3a-a89b820043cmr477451066b.65.1725302548831; Mon, 02 Sep 2024 11:42:28 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:bc14:b544:1196:d1a]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a898900ec0asm590537966b.53.2024.09.02.11.42.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 11:42: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, christophe.jaillet@wanadoo.fr Subject: [PATCH v5 3/7] iio: pressure: bmp280: Remove config error check for IIR filter updates Date: Mon, 2 Sep 2024 20:42:18 +0200 Message-Id: <20240902184222.24874-4-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240902184222.24874-1-vassilisamir@gmail.com> References: <20240902184222.24874-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 cd975fad2753..ba77c428042d 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -1559,14 +1559,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) { /* @@ -2156,15 +2154,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 Mon Sep 2 18:42:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13787630 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.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 C166B205E16; Mon, 2 Sep 2024 18:42:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725302555; cv=none; b=hJ1A25fe5T/+2e7wREpKq0tsaEp9hR12wEPBMLSWBs7FlpoTRSD7gZyFXLO6FIBwY25pYyrhriCW85Lev1AUcwaUU6WLIsUqFxUpXVSdAAoy+eDL3LrlIcQgTSt/r76bVJXH2c+UhWn/SPR6aIoj2VKfD001pcS+qrsChto1Wpk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725302555; c=relaxed/simple; bh=sI6iMkj20cGbAs8qslhqSpRCc1EK8UHgB/LCX+GhGI8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Hb1hk6sUBJK8F4QD3hJ78xGfgfoOCWayCBOGh1wU9wwEo8osseD7e8i5eh28rYPy6wN2YwDV8cJ6pMzRaQ2dMpZYa1jhThWavw7DakNN1OdDZS01SS2MfA0rsB2w2UlDhkn5mFanpblG91/FRdmw/EpQ3xRH2O12v6RfyuLhJYw= 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=Wu0UtBXS; arc=none smtp.client-ip=209.85.167.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="Wu0UtBXS" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-534366c194fso4114739e87.0; Mon, 02 Sep 2024 11:42:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725302551; x=1725907351; 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=A2TyNBQeitR3XYQX6NhBJE8FJuK2K2Pq4PAQRZivBC8=; b=Wu0UtBXS7ZE0l8IHLThSFHEoCZRU2+NwVUa+MWa49+lwY/Fc4Jz1/VuCROtE16lEoi J2aXpUYNLAo43a0s6APjlT5HM14Vdvh7hnH3PKWhnQ3AI0xsd/RHjwTENBiWj4bArngf wmxOxD7qdGbScJnziRv34CgZbrtQMoeAF/YWlVWDz6eJhmFC9cs1JaNq+4kg0cTW6Frs F9+v3ehQfw9aKkkYeUL4JxHyJP/FUPC9/heWggJPBMfoZZbKR8o5PMlB5Ri1ZWybsyfP 8c4Q2wUiPbDpeayDwvBYXi6AqCcVCC5WoT90xTYKtPhjoRy26+MOcJJjs1H1sdN1s6/L lUiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725302551; x=1725907351; 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=A2TyNBQeitR3XYQX6NhBJE8FJuK2K2Pq4PAQRZivBC8=; b=MSBItsO8fLalIUoXGkUDM7UfNYRGrSI2Y5DDWk0xm4Q3OvFZHGVojpQpWeqOuSMmuN E4Nop59zbdHEpLhmdAAyt/OW63aMgav+IeX5afMzu+qchMnuwVxI7Z21Y4RWLqQ6QbpP xadgZ2yGs2A7z+YsRDsg2GHqCJR3FK4+6fDwIXRKhRQFNGMkMl61TuLIyWjbpLak4aD1 kXwhl4jdfmp1b0ezroPBVYJ46Y6c9Iu1m6FnMxDfUWFJTg7jPE030oyr04bnS9v7IQez yh+NLXmdUcZ0Xf5+QmZYyjb8jx4tf75TFHycd4w+36v2XC0Icp+ZNfsbc4Rrs6r77Utq OWLg== X-Forwarded-Encrypted: i=1; AJvYcCVKGqB+xdzAzAD2Ax0YqU7bdKZxD0Avu/jthNfGUfYXxe7+T2V0wDKcm/SW297fwHDABc+Hypu9EW+F@vger.kernel.org, AJvYcCW2n+Lk+kByeiDTDqMi3lez4WrVy9RpAw8oYfDGbfhMirTIO5uFo/HZxpFH4kMYqiZ1W0oSGK4NvCLkMNC1@vger.kernel.org, AJvYcCXjySGqahV0nchK8laf1iU7IuoDQNWo08z2IrrYQO85rse3ppwalNRdbtjfaAdUMRz8wWkQkTgzeeb5@vger.kernel.org X-Gm-Message-State: AOJu0Yz+fJRtfiBtdWC3zaMnf3dYWR3UwlPwAoTmGw9xZGANsDWy7o89 6B1ecVl4c+T/EhIRZGlYzTCc+SipNOK7R+oIpAo2/CGPjbC+cpEl X-Google-Smtp-Source: AGHT+IFd45jwcTjneTVYvr2DbIkbE+GOyxpG/xYKfnGIBhcM3z2w08F2r/G2oqQ8Jr+bPH5eSD32hQ== X-Received: by 2002:a05:6512:3a8a:b0:530:c1fb:5192 with SMTP id 2adb3069b0e04-53546b335b3mr8002292e87.16.1725302550025; Mon, 02 Sep 2024 11:42:30 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:bc14:b544:1196:d1a]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a898900ec0asm590537966b.53.2024.09.02.11.42.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 11:42:29 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andriy.shevchenko@linux.intel.com Cc: vassilisamir@gmail.com, 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, christophe.jaillet@wanadoo.fr Subject: [PATCH v5 4/7] iio: pressure: bmp280: Use sleep and forced mode for oneshot captures Date: Mon, 2 Sep 2024 20:42:19 +0200 Message-Id: <20240902184222.24874-5-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240902184222.24874-1-vassilisamir@gmail.com> References: <20240902184222.24874-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 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. The idea is that the sensor is by default in sleep mode, wakes up in forced mode when a oneshot capture is requested, or in normal mode when the buffer is enabled. The difference lays in the fact that in forced mode, the sensor does only one conversion and goes back to sleep while in normal mode, the sensor does continuous measurements with the frequency that was set in the ODR registers. The bmpX_chip_config() functions which are responsible for applying the requested configuration to the sensor, are modified accordingly in order to set the sensor by default in sleep mode. DEEP STANDBY, Low Power NORMAL and CONTINUOUS modes, supported only by the BMP58x version, are not added. Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-core.c | 291 +++++++++++++++++++++++++++-- drivers/iio/pressure/bmp280.h | 21 +++ 2 files changed, 292 insertions(+), 20 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index ba77c428042d..b8a55de78616 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -16,6 +16,11 @@ * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp390-ds002.pdf * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp581-ds004.pdf * + * Sensor API: + * https://github.com/boschsensortec/BME280_SensorAPI + * https://github.com/boschsensortec/BMP3_SensorAPI + * https://github.com/boschsensortec/BMP5_SensorAPI + * * Notice: * The link to the bmp180 datasheet points to an outdated version missing these changes: * - Changed document referral from ANP015 to BST-MPS-AN004-00 on page 26 @@ -616,6 +621,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); @@ -645,6 +658,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); @@ -991,6 +1012,69 @@ static int bmp280_preinit(struct bmp280_data *data) return 0; } +static const u8 bmp280_operation_mode[] = { + BMP280_MODE_SLEEP, BMP280_MODE_FORCED, BMP280_MODE_NORMAL, +}; + +static int bmp280_set_mode(struct bmp280_data *data, enum bmp280_op_mode mode) +{ + int ret; + + switch (mode) { + case BMP280_SLEEP: + case BMP280_FORCED: + case BMP280_NORMAL: + break; + default: + return -EINVAL; + } + + ret = regmap_write_bits(data->regmap, BMP280_REG_CTRL_MEAS, + BMP280_MODE_MASK, bmp280_operation_mode[mode]); + if (ret) { + dev_err(data->dev, "failed to write ctrl_meas register.\n"); + return ret; + } + + data->op_mode = mode; + + return 0; +} + +static int bmp280_wait_conv(struct bmp280_data *data) +{ + unsigned int reg, meas_time_us; + int ret; + + /* Check if we are using a BME280 device */ + if (data->oversampling_humid) + meas_time_us += BMP280_PRESS_HUMID_MEAS_OFFSET + + (BIT(data->oversampling_humid) * BMP280_MEAS_DUR); + + /* Pressure measurement time */ + meas_time_us += BMP280_PRESS_HUMID_MEAS_OFFSET + + (BIT(data->oversampling_press) * BMP280_MEAS_DUR); + + /* Temperature measurement time */ + meas_time_us += BIT(data->oversampling_temp) * BMP280_MEAS_DUR; + + /* Waiting time according to the BM(P/E)2 Sensor API */ + fsleep(meas_time_us); + + 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) | @@ -1001,7 +1085,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; @@ -1108,6 +1192,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, @@ -1229,6 +1315,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, @@ -1516,6 +1604,71 @@ static int bmp380_preinit(struct bmp280_data *data) return bmp380_cmd(data, BMP380_CMD_SOFT_RESET); } +static const u8 bmp380_operation_mode[] = { + BMP380_MODE_SLEEP, BMP380_MODE_FORCED, BMP380_MODE_NORMAL, +}; + +static int bmp380_set_mode(struct bmp280_data *data, enum bmp280_op_mode mode) +{ + int ret; + + switch (mode) { + case BMP280_SLEEP: + case BMP280_FORCED: + case BMP280_NORMAL: + break; + default: + return -EINVAL; + } + + ret = regmap_write_bits(data->regmap, BMP380_REG_POWER_CONTROL, + BMP380_MODE_MASK, + FIELD_PREP(BMP380_MODE_MASK, + bmp380_operation_mode[mode])); + if (ret) { + dev_err(data->dev, "failed to write power control register.\n"); + return ret; + } + + data->op_mode = mode; + + return 0; +} + +static int bmp380_wait_conv(struct bmp280_data *data) +{ + unsigned int reg; + int ret, meas_time_us; + + /* Offset measurement time */ + meas_time_us = BMP380_MEAS_OFFSET; + + /* Pressure measurement time */ + meas_time_us += BMP380_PRESS_MEAS_OFFSET + + (BIT(data->oversampling_press) * BMP380_MEAS_DUR); + + /* Temperature measurement time */ + meas_time_us += BMP380_TEMP_MEAS_OFFSET + + (BIT(data->oversampling_temp) * BMP380_MEAS_DUR); + + /* Measurement time defined in Datasheet Section 3.9.2 */ + fsleep(meas_time_us); + + 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)) { + 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; @@ -1576,17 +1729,19 @@ 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)); + + /* + * According to the BMP3 Sensor API, the sensor needs 5000us + * in order to go to the sleep mode. + */ + fsleep(5000); + + ret = bmp380_set_mode(data, BMP280_NORMAL); if (ret) { dev_err(data->dev, "failed to set normal mode\n"); return ret; @@ -1612,6 +1767,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; } @@ -1705,6 +1871,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, @@ -2092,6 +2260,70 @@ static int bmp580_preinit(struct bmp280_data *data) return PTR_ERR_OR_ZERO(devm_nvmem_register(config.dev, &config)); } +static const u8 bmp580_operation_mode[] = { + BMP580_MODE_SLEEP, BMP580_MODE_FORCED, BMP580_MODE_NORMAL, +}; + +static int bmp580_set_mode(struct bmp280_data *data, enum bmp280_op_mode mode) +{ + struct device *dev = data->dev; + int ret; + + switch (mode) { + case BMP280_SLEEP: + case BMP280_NORMAL: + break; + case BMP280_FORCED: + ret = regmap_set_bits(data->regmap, BMP580_REG_DSP_CONFIG, + BMP580_DSP_IIR_FORCED_FLUSH); + if (ret) { + dev_err(dev, "Could not flush IIR filter constants.\n"); + return ret; + } + break; + default: + return -EINVAL; + } + + ret = regmap_write_bits(data->regmap, BMP580_REG_ODR_CONFIG, + BMP580_MODE_MASK, + FIELD_PREP(BMP580_MODE_MASK, + bmp580_operation_mode[mode])); + if (ret) { + dev_err(dev, "failed to write power control register.\n"); + return ret; + } + + data->op_mode = mode; + + return 0; +} + +static int bmp580_wait_conv(struct bmp280_data *data) +{ + /* + * Taken from datasheet, Section 2 "Specification, Table 3 "Electrical + * characteristics. + */ + static const int time_conv_press[] = { + 0, 1050, 1785, 3045, 5670, 10920, 21420, 42420, + 84420, + }; + static const int time_conv_temp[] = { + 0, 1050, 1105, 1575, 2205, 3465, 6090, 11340, + 21840, + }; + int meas_time_us; + + meas_time_us = 4 * USEC_PER_MSEC + time_conv_temp[data->oversampling_temp] + + time_conv_press[data->oversampling_press]; + + /* Measurement time mentioned in Chapter 2, Table 4 of the datasheet. */ + fsleep(meas_time_us); + + return 0; +} + static int bmp580_chip_config(struct bmp280_data *data) { bool change = false, aux; @@ -2162,17 +2394,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 @@ -2268,6 +2489,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, @@ -2515,6 +2738,19 @@ static int bmp180_read_press(struct bmp280_data *data, u32 *comp_press) return 0; } +/* Keep compatibility with newer generations of the sensor */ +static int bmp180_set_mode(struct bmp280_data *data, enum bmp280_op_mode mode) +{ + return 0; +} + +/* Keep compatibility with newer generations of the sensor */ +static int bmp180_wait_conv(struct bmp280_data *data) +{ + return 0; +} + +/* Keep compatibility with newer generations of the sensor */ static int bmp180_chip_config(struct bmp280_data *data) { return 0; @@ -2585,6 +2821,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, }; @@ -2637,6 +2875,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; } @@ -2807,6 +3046,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); @@ -2832,6 +3075,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); + + fsleep(data->start_up_time + 500); return regulator_bulk_disable(BMP280_NUM_SUPPLIES, data->supplies); } @@ -2846,7 +3092,12 @@ static int bmp280_runtime_resume(struct device *dev) return ret; usleep_range(data->start_up_time, data->start_up_time + 100); - return data->chip_info->chip_config(data); + + ret = data->chip_info->chip_config(data); + if (ret) + return ret; + + return data->chip_info->set_mode(data, data->op_mode); } EXPORT_RUNTIME_DEV_PM_OPS(bmp280_dev_pm_ops, bmp280_runtime_suspend, diff --git a/drivers/iio/pressure/bmp280.h b/drivers/iio/pressure/bmp280.h index 73516878d020..c9840b8d58b0 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 @@ -384,6 +394,12 @@ struct bmp380_calib { s8 P11; }; +enum bmp280_op_mode { + BMP280_SLEEP, + BMP280_FORCED, + BMP280_NORMAL, +}; + struct bmp280_data { struct device *dev; struct mutex lock; @@ -424,6 +440,9 @@ struct bmp280_data { s64 ts __aligned(8); } buffer; + /* Value to hold the current operation mode of the device */ + enum bmp280_op_mode op_mode; + /* * DMA (thus cache coherency maintenance) may require the * transfer buffers to live in their own cache lines. @@ -488,6 +507,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, enum bmp280_op_mode mode); + int (*wait_conv)(struct bmp280_data *data); irqreturn_t (*trigger_handler)(int irq, void *p); }; From patchwork Mon Sep 2 18:42:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13787631 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D714E3B1AC; Mon, 2 Sep 2024 18:42:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725302555; cv=none; b=sOzWWySyUsgrNPWEJi4IzS370i0Zsl9gQsEhPyuuBcUdu+QIDR7+qq9V1LLrgblXn6L/K1cwBEscbRrNThkejRcmwfHaa5MplAI2RRh3y1sv7NHqaHn7yFdxXtWcHY97rTHgd0w7gQvoGLnwmMhWy5Qq8UV0vPu3Zys5oR23f7s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725302555; c=relaxed/simple; bh=GkiarHMmH9pJs7XDXCDb+vBjRm3RV657WRgvnnni5MA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ckWayYsXhZy512JgkTLK9SWbExinW95N+r80Am/xxlopsKEInnrtlXgk6I27HfL7IUXRS+yXXGyPGkwe/P34tEaqeIb4zXL/s+eis7teoY52ipob+opah8jF6okLyHy6zxORv3rIfQ6WnAuDhiyK/tiBcKx4El1laY02FCLchRI= 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=apuVUKnQ; arc=none smtp.client-ip=209.85.167.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="apuVUKnQ" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-534366c1aa2so4662839e87.1; Mon, 02 Sep 2024 11:42:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725302552; x=1725907352; 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=+G8g0J/q8QWuHVcxWZKshG+cNgLOqquv02fgoHW0NJ8=; b=apuVUKnQmTDrcchMyRQGdHlRFpA+MTwJ5qYHF6hbHNswscatGjk80dx6PB+LYQ3B3A XI9bCRVXxwuC797a3pRMv/SJCY8vV8vLa8ZB9d5+u156x2I0/hCIxAOj+36S05GJ+yAA 2g+Osfd7rrKIceMBTfTKDRVLgWo0g+VGU5kATmchlBWqeMju2ldfNeYECyqelnw1EA8l hD+Eg14a7aLrS+z8sYxzJOMgZarzzfiRhXE3MBq44JWmO0iPEl3f/3WNgieywbltqJSW dx+VBQADf6a30fTyyQysgXCmll7O3/TNYcq5TwC3LwxKlXQdRLEBSb4b2eLA69hYkMNx +7BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725302552; x=1725907352; 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=+G8g0J/q8QWuHVcxWZKshG+cNgLOqquv02fgoHW0NJ8=; b=P86353If1TG0mYp1dDKBvpYw7Bt+ov/zn9bNakSv5dxOR3Dncv48smKJLQtB3A6T3u iRY3uu2pitNVQOdARioJbKRD9E6kcKbAymg4kZC/i7m7fwzuyRtQuZV7iPFHAweHe8tP 7gPB8oN1XTPuVA8+2lvn0qgUlRuBw3cr4fPEPMthzG40I1sBTInHE6xuLyoLI/VSPNtL v1Z2lqplzANA+UYvJ+1Vl07eq6R3A6QmlQe1uChKAi76rnSORbB8Q5kyJ1nWbYbhtbxI XQR+zwlhwp7RScyWSkDJH0BxWm9cwBe2GhjD9wrQOSgN9D/FuRZIMafRh6deZeIEtRhb JvRA== X-Forwarded-Encrypted: i=1; AJvYcCUFSilZW/plnRqxXjStpcU3dMA3gwkOBzxR8MEDHuWnQp+o/UGR7yHzy+CdwG5mozYGytdigF7nVBqlCLv7@vger.kernel.org, AJvYcCVH94Z8fyR5iM8lhxFIkh/l84RKjS5miJJ8AglYQGc1us1sKCcOQwe1+fSBdZ72Ta70EpE37kzngzRe@vger.kernel.org, AJvYcCVySR6N7KpO2xLCe4GQWXLMCCtIq4RLDN1Z4MQHpDagumU+bMAchStmPJ9FJ4IclPtaSnIAUA7j6doU@vger.kernel.org X-Gm-Message-State: AOJu0YxrzRTu9MOjVc/o5DgmRb9nAnsTGbc7aH+26gkCjiO1ZuWGhUvw stH/hDYdHQ3P8EPYq+ojY7mi81Be4iCag1wFOjEc35aMBEv1qcD+vC/pEn/PuMk= X-Google-Smtp-Source: AGHT+IGKd75Yg3LvTV2Nt6i0JlpMKC9tZKvwNxsQyYGudmeUw2Qosgc5/N1tCSSunmUmVQ+iaY4ZJw== X-Received: by 2002:a05:6512:3187:b0:52e:be50:9c66 with SMTP id 2adb3069b0e04-53546b9b710mr5663789e87.53.1725302551122; Mon, 02 Sep 2024 11:42:31 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:bc14:b544:1196:d1a]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a898900ec0asm590537966b.53.2024.09.02.11.42.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 11:42:30 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andriy.shevchenko@linux.intel.com Cc: vassilisamir@gmail.com, 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, christophe.jaillet@wanadoo.fr Subject: [PATCH v5 5/7] dt-bindings: iio: pressure: bmp085: Add interrupts for BMP3xx and BMP5xx devices Date: Mon, 2 Sep 2024 20:42:20 +0200 Message-Id: <20240902184222.24874-6-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240902184222.24874-1-vassilisamir@gmail.com> References: <20240902184222.24874-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 --- .../bindings/iio/pressure/bmp085.yaml | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/iio/pressure/bmp085.yaml b/Documentation/devicetree/bindings/iio/pressure/bmp085.yaml index 6fda887ee9d4..20b75865e02f 100644 --- a/Documentation/devicetree/bindings/iio/pressure/bmp085.yaml +++ b/Documentation/devicetree/bindings/iio/pressure/bmp085.yaml @@ -48,14 +48,34 @@ properties: interrupts: description: - interrupt mapping for IRQ (BMP085 only) + interrupt mapping for IRQ. Supported in BMP085, BMP3xx, BMP5xx maxItems: 1 + drive-open-drain: + description: + set if the interrupt pin should be configured as open drain. + If not set, defaults to push-pull configuration. + type: boolean + + required: - compatible - vddd-supply - vdda-supply +allOf: + - if: + properties: + compatible: + not: + enum: + - bosch,bmp085 + - bosch,bmp380 + - bosch,bmp580 + then: + properties: + interrupts: false + additionalProperties: false examples: From patchwork Mon Sep 2 18:42:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13787632 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.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 D36FA21C17D; Mon, 2 Sep 2024 18:42:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725302558; cv=none; b=cyFIVT8ogMWfUKN+s294ibnkeg6ekLiCDuQj/IA4yo6Y/GAgSiNpRbNrYU1BVUGdBfo7OQMx+bnaBO/RtFE3MoGxZYIrAL5lfSBDsJwNLT4GB2DjQ/uWwZby2n1ieEZuLrmxOVyugcV9nq+thDTdqBduW+ayXvMRdzev25XnrOk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725302558; c=relaxed/simple; bh=JLGdr8dn/4cNOUgp1SlM//NNrNxkIn4AfxGXTNvhkXI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=i3qGakyuhenFg4sip3m2kUekRBfRqG5tE9Xj3D4Ba0BErMtu9vpJ9HNYlnFkkIY7+86vieHJjNONnT+iEMCxzyinJqWagWkC72qlx+2kZaXJ2j9z5sqNgQ3EAap483B0t1H5CRcOlbiFKMS89TB1/9b8DyQQtdJpK0EaJqrcWTA= 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=fzf8+/tU; arc=none smtp.client-ip=209.85.218.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="fzf8+/tU" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a86984e035aso551004366b.2; Mon, 02 Sep 2024 11:42:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725302553; x=1725907353; 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=CtUyd1x07/AOHbjnYKnt62eAHZJsJYoZUWuDynWvrW8=; b=fzf8+/tUxEbP2NoyYGQ5Rgz8KsjVFjLpdhzFZ1cFa7/iJS3wwOyvJI/99aJlHWgXIk gBqXWDNPHNMlHULgbq5r6LDFeTYiBryzFBXN9hFQvK5OnEzml3W/FazqoKIOBmxbdW/n HmaNHIh7Z3sPJoVi0vmTkL/I6p/XZXSPCdIBOkFdSwFYXt7+pZAqmN4OdMO0oT3Ioh5n H8iNXF7iO/aqegCbtA+c50dnk5LCS96FBAa4NZQlgXvcDP1aHj12/Armtl7a71eEvn5S gXiEMh5VcEUN4c0ihqMYXvwMUu0kRns6kTU/gGboG2dIpdNu8lfcks6ZO5WJHpkO0Lp+ UFcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725302553; x=1725907353; 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=CtUyd1x07/AOHbjnYKnt62eAHZJsJYoZUWuDynWvrW8=; b=JGs11UWQ2slovrrSdCrpXaLrnnFb3yOqKJKaq++sEz8+KBw9MOVFJt0eO4Umj+ycFs VBL4BSxwbS1kBqjH6TS4ZrtQSmxygvWCLUFAXRgOzUw9EmLOp4PYfEkSZS4wINGG+Rfp M7XZdN//AIQ+Kbp/95/sj1FcYZ6Lp/NuXwb15fBX7rf+KYtXAE+Y6xiqJdBNMZIfm4XL wL5FodUMM2C7vSvs2URKggJPaC7UBjWo4deZGX1+2h/kvdGZ1uLiYv9SKNvXKirh6mZ0 5lRukfSo+JKlMDUg4I7JLiIOAk0j/BHUW3gpK1Xel3YdRWnhPI5QKEdNiNtH88B2IcgX 01aA== X-Forwarded-Encrypted: i=1; AJvYcCUoCkbT/MsBY/C4E5p8fE6bNiJHcDPLg5/5TLM032G4Rnt9GdEVHGQRup2x63+xEcmLDpMa9tob0dwU@vger.kernel.org, AJvYcCVu4R0ow5+UcCZ5fo2CHli48bH9Xpyih7QscyPVXvzXDsEhaSiUiGvN8ynTOaKQfeTpxxH83CtY2as8Spg4@vger.kernel.org, AJvYcCW2kf+cUn6+IpWuN/mo29FZKxHr4Dz6OOQDVg6Fwm/dJXI5NipEgM56B7r0yy+tLvyGJ2SoMJpbAR6M@vger.kernel.org X-Gm-Message-State: AOJu0YyPsWkIjOPYh2xAak6PCEJz9CGL9DYSJpqG58yLuPN99Xdo91uj O4Owb3xuZQitrlYL+OamljeLEetBgXe8CBv1DeTVqDM1BU7WuMBd X-Google-Smtp-Source: AGHT+IEdgu3OGxy6vYTS1GEQpHhoym+apinNg4KLbciHtCNE3E/yZsIOthFLniGC5Wzb35JcsX3Cmw== X-Received: by 2002:a17:907:1c9f:b0:a8a:18f9:269f with SMTP id a640c23a62f3a-a8a18f92a81mr97891266b.60.1725302552231; Mon, 02 Sep 2024 11:42:32 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:bc14:b544:1196:d1a]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a898900ec0asm590537966b.53.2024.09.02.11.42.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 11:42:31 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andriy.shevchenko@linux.intel.com Cc: vassilisamir@gmail.com, 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, christophe.jaillet@wanadoo.fr Subject: [PATCH v5 6/7] iio: pressure: bmp280: Add data ready trigger support Date: Mon, 2 Sep 2024 20:42:21 +0200 Message-Id: <20240902184222.24874-7-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240902184222.24874-1-vassilisamir@gmail.com> References: <20240902184222.24874-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 | 226 ++++++++++++++++++++++++++++- drivers/iio/pressure/bmp280.h | 21 +++ 2 files changed, 245 insertions(+), 2 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index b8a55de78616..74233778df35 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -42,12 +42,14 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include @@ -1278,6 +1280,64 @@ static irqreturn_t bme280_trigger_handler(int irq, void *p) return IRQ_HANDLED; } +static int __bmp280_trigger_probe(struct iio_dev *indio_dev, + const struct iio_trigger_ops *trigger_ops, + int (*int_config)(struct bmp280_data *data), + irq_handler_t irq_thread_handler) +{ + struct bmp280_data *data = iio_priv(indio_dev); + struct device *dev = data->dev; + struct fwnode_handle *fwnode; + u32 irq_type; + int ret, irq; + + irq = fwnode_irq_get(dev_fwnode(dev), 0); + if (irq < 0) + return dev_err_probe(dev, irq, "No interrupt found.\n"); + + irq_type = irq_get_trigger_type(irq); + switch (irq_type) { + case IRQF_TRIGGER_RISING: + data->trig_active_high = true; + break; + case IRQF_TRIGGER_FALLING: + data->trig_active_high = false; + break; + default: + return dev_err_probe(dev, -EINVAL, "Invalid interrupt type specified.\n"); + } + + data->trig_open_drain = + fwnode_property_read_bool(fwnode, "int-open-drain"); + + ret = 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 = trigger_ops; + iio_trigger_set_drvdata(data->trig, data); + + ret = devm_request_threaded_irq(data->dev, irq, NULL, + irq_thread_handler, IRQF_ONESHOT, + indio_dev->name, indio_dev); + if (ret) + return dev_err_probe(dev, ret, "request irq failed.\n"); + + ret = devm_iio_trigger_register(data->dev, data->trig); + if (ret) + return dev_err_probe(dev, ret, "iio trigger register failed.\n"); + + indio_dev->trig = iio_trigger_get(data->trig); + + return 0; +} + static const u8 bme280_chip_ids[] = { BME280_CHIP_ID }; static const int bme280_humid_coeffs[] = { 1000, 1024 }; @@ -1781,6 +1841,81 @@ 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_CONTROL, + BMP380_INT_CTRL_DRDY_EN, + FIELD_PREP(BMP380_INT_CTRL_DRDY_EN, !!state)); + if (ret) + dev_err(data->dev, + "Could not %s interrupt.\n", str_enable_disable(state)); + return ret; +} + +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 pin_drive_cfg = FIELD_PREP(BMP380_INT_CTRL_OPEN_DRAIN, + data->trig_open_drain); + int pin_level_cfg = FIELD_PREP(BMP380_INT_CTRL_LEVEL, + data->trig_active_high); + int ret, int_cfg = pin_drive_cfg | pin_level_cfg; + + ret = regmap_update_bits(data->regmap, BMP380_REG_INT_CONTROL, + BMP380_INT_CTRL_SETTINGS_MASK, int_cfg); + if (ret) + dev_err(data->dev, "Could not set interrupt settings.\n"); + + return ret; +} + +static irqreturn_t bmp380_irq_thread_handler(int irq, void *p) +{ + struct iio_dev *indio_dev = p; + struct bmp280_data *data = iio_priv(indio_dev); + unsigned int int_ctrl; + int ret; + + scoped_guard(mutex, &data->lock) { + ret = regmap_read(data->regmap, BMP380_REG_INT_STATUS, &int_ctrl); + if (ret) + return IRQ_NONE; + } + + if (FIELD_GET(BMP380_INT_STATUS_DRDY, int_ctrl)) + iio_trigger_poll_nested(data->trig); + + return IRQ_HANDLED; +} + +static int bmp380_trigger_probe(struct iio_dev *indio_dev) +{ + return __bmp280_trigger_probe(indio_dev, &bmp380_trigger_ops, + bmp380_int_config, + bmp380_irq_thread_handler); +} + static irqreturn_t bmp380_trigger_handler(int irq, void *p) { struct iio_poll_func *pf = p; @@ -1875,6 +2010,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); @@ -2417,6 +2553,88 @@ 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)); + if (ret) + dev_err(data->dev, + "Could not %s interrupt.\n", str_enable_disable(state)); + return ret; +} + +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 pin_drive_cfg = FIELD_PREP(BMP580_INT_CONFIG_OPEN_DRAIN, + data->trig_open_drain); + int pin_level_cfg = FIELD_PREP(BMP580_INT_CONFIG_LEVEL, + data->trig_active_high); + int ret, int_cfg = pin_drive_cfg | pin_level_cfg; + + 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; +} + +static irqreturn_t bmp580_irq_thread_handler(int irq, void *p) +{ + struct iio_dev *indio_dev = p; + struct bmp280_data *data = iio_priv(indio_dev); + unsigned int int_ctrl; + int ret; + + scoped_guard(mutex, &data->lock) { + ret = regmap_read(data->regmap, BMP580_REG_INT_STATUS, &int_ctrl); + if (ret) + return IRQ_NONE; + } + + if (FIELD_GET(BMP580_INT_STATUS_DRDY_MASK, int_ctrl)) + iio_trigger_poll_nested(data->trig); + + return IRQ_HANDLED; +} + +static int bmp580_trigger_probe(struct iio_dev *indio_dev) +{ + return __bmp280_trigger_probe(indio_dev, &bmp580_trigger_ops, + bmp580_int_config, + bmp580_irq_thread_handler); +} + static irqreturn_t bmp580_trigger_handler(int irq, void *p) { struct iio_poll_func *pf = p; @@ -2493,6 +2711,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); @@ -3040,8 +3259,11 @@ 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 (irq > 0) { + if (chip_id == BMP180_CHIP_ID) + ret = bmp085_fetch_eoc_irq(dev, name, irq, data); + if (data->chip_info->trigger_probe) + ret = data->chip_info->trigger_probe(indio_dev); if (ret) return ret; } diff --git a/drivers/iio/pressure/bmp280.h b/drivers/iio/pressure/bmp280.h index c9840b8d58b0..0c32b6430677 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) @@ -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 @@ -406,6 +423,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; @@ -510,6 +530,7 @@ struct bmp280_chip_info { int (*set_mode)(struct bmp280_data *data, enum bmp280_op_mode 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 Mon Sep 2 18:42:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13787633 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.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 3C6BF21C187; Mon, 2 Sep 2024 18:42:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725302559; cv=none; b=kNERde9h0BltJxhsTPjo1RnILOZBbu6rDSEyxV4BdhWJuUuDrjdrbNmSXyszK3Z7n4U6AnVx8XNQoeJuRddi0L8KioOR6Syb2kEOVkP4RDunt2KQWdJv3ClvKdFXA43UGFQIkKRAYo8D4qrp9vEx3N9CMCtJKvvuNZJjQaXQW2g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725302559; c=relaxed/simple; bh=WWAmhNjah9crhyBMvMVbn/J1Sxemr78dk9V2kbGeanU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=q6boGKWJgKnEskJjWbwH2j1ymVFpbOJUuWltiE649pm7KkxZdg9/9243GBCdpzMxB9jggRENn/qO+BNG3qTLpULKCIEtu8Sx8ljY0SFUYQ2ZaqorXgHCwi6SItPwdL4WsbjQ/oFjTPlL2X+v3gY8BQ3nOqRQenLsoEGnR20iDLU= 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=GQgYtZvw; arc=none smtp.client-ip=209.85.167.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="GQgYtZvw" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-533488ffaf7so6130818e87.0; Mon, 02 Sep 2024 11:42:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725302554; x=1725907354; 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=i9ss9HdLsigH+9uZPMqVFlBWKlXTSDUOX9N8A2zmG7U=; b=GQgYtZvwgYu8/gkzv2ccmMDjbumu9FU3AADCirGmI4KIv25g2dhn3wgF3fTWtqA7H/ kbFJDuzhiIJIBrOm2ZjwIh3hZxl5QXBT7uW8nlZcAmx9YGM645QJg4VO9wGHXebxLTQb N6s0OLXp5yNhQ5hXFRgl5jgPcMpC528nSngnatr6xUxKjx7j48G2beWGOdtg3lFNItkS ewWhKxPdu+JDBfF0c2VNkHB9CbdapR1MMroQhdP0qc2uNdLSq6P7X+jhtFJtknF/8+Os 04BL/YZh5Yx2oUfvT0CkCMn1t7befFhRyEoGPnEwjrfnBRkDafUgc5ZErNZKBzbQkFxr Ia+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725302554; x=1725907354; 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=i9ss9HdLsigH+9uZPMqVFlBWKlXTSDUOX9N8A2zmG7U=; b=Ob2rjHbmDeidHBOuWOOsPb1ezgmrl0Y4aTGOkYL+hsv/Mj1rPGgRRhzE16garE5Ry1 vXIiL97K15IE2fkSl5m2R9s+7mo/bybnmhwoILW1ejE28A0CiN5/RnGb5x3hEakJk0bU FwytorP7nJvhucv2SZc/zibGHx56/ZJrSFt8jvlGdDmhtcOUpcNNY1uRR3dmFwwBTzTu H7EB3HyvbygDy9OSDBHJ4mIcyw0SkwPheqy0wOp88+nOS5Zl1Qr/cA7rYa6Kdufu3gZb Fa8uIfSY0kj4658P0+wfQTEwiAPeQJp7fkdYGN+TRdSCsVxLEawgsjHAGDcvQWTh80G7 VfYw== X-Forwarded-Encrypted: i=1; AJvYcCUHYNzHPcP+xL7NXlSKDwPYAoBu4AyZWj5KZqcK7ewDOZaMIqDn31QZNyk7eha9h1TVV4tPAa167kUo@vger.kernel.org, AJvYcCUwmjxgVnvKg3LvFizoiOa3im/TQncIR/mgsWD6Fl4iLQNjtvJenUoyC0GatGiRVEK3/3ELXIiXWmBO@vger.kernel.org, AJvYcCVdUwGXU5P2nXkDq0Xq6GbjTLkpVyqwk22FmzrSi/V26KfI9M8b8o9+jswjOt0fd8U6ceaSjIkG8Dk8nO+T@vger.kernel.org X-Gm-Message-State: AOJu0Yz238Yv0dyBvn+cvbde5U1G4MOeYQva/TQJq+sAzBn80T7muQA0 Gampjc/cnHux/Iv1112sHwblA361jKvRir3/m0cS6n2yoQjd/EWd X-Google-Smtp-Source: AGHT+IEvG6aAsQWI5Tw/ZncjxuPde+5tWIhRizQHOA6cZB2zK1HUQX7NkowjXvIHEe7E69vcO8dbzg== X-Received: by 2002:a05:6512:2309:b0:52e:9b9e:a6cb with SMTP id 2adb3069b0e04-53546b24bfbmr8207456e87.15.1725302553513; Mon, 02 Sep 2024 11:42:33 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:bc14:b544:1196:d1a]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a898900ec0asm590537966b.53.2024.09.02.11.42.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 11:42:33 -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, christophe.jaillet@wanadoo.fr Subject: [PATCH v5 7/7] iio: pressure: bmp280: Move bmp085 interrupt to new configuration Date: Mon, 2 Sep 2024 20:42:22 +0200 Message-Id: <20240902184222.24874-8-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240902184222.24874-1-vassilisamir@gmail.com> References: <20240902184222.24874-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 driver for 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 Reviewed-by: Andy Shevchenko --- drivers/iio/pressure/bmp280-core.c | 63 +++++++++++++++++++++++------- drivers/iio/pressure/bmp280-i2c.c | 4 +- drivers/iio/pressure/bmp280-spi.c | 4 +- drivers/iio/pressure/bmp280.h | 1 + 4 files changed, 54 insertions(+), 18 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 74233778df35..2cfe29f7681b 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -3056,13 +3056,16 @@ 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; unsigned long irq_trig; - int ret; + int ret, irq; + + irq = fwnode_irq_get(dev_fwnode(dev), 0); + if (irq < 0) + return dev_err_probe(dev, irq, "No interrupt found.\n"); irq_trig = irqd_get_trigger_type(irq_get_irq_data(irq)); if (irq_trig != IRQF_TRIGGER_RISING) { @@ -3072,13 +3075,8 @@ 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"); @@ -3086,9 +3084,48 @@ static int bmp085_fetch_eoc_irq(struct device *dev, } data->use_eoc = true; + return 0; } +/* Identical to bmp180_chip_info + bmp085_trigger_probe */ +const struct bmp280_chip_info bmp085_chip_info = { + .id_reg = BMP280_REG_ID, + .chip_id = bmp180_chip_ids, + .num_chip_id = ARRAY_SIZE(bmp180_chip_ids), + .regmap_config = &bmp180_regmap_config, + .start_up_time = 2000, + .channels = bmp280_channels, + .num_channels = ARRAY_SIZE(bmp280_channels), + .avail_scan_masks = bmp280_avail_scan_masks, + + .oversampling_temp_avail = bmp180_oversampling_temp_avail, + .num_oversampling_temp_avail = + ARRAY_SIZE(bmp180_oversampling_temp_avail), + .oversampling_temp_default = 0, + + .oversampling_press_avail = bmp180_oversampling_press_avail, + .num_oversampling_press_avail = + ARRAY_SIZE(bmp180_oversampling_press_avail), + .oversampling_press_default = BMP180_MEAS_PRESS_8X, + + .temp_coeffs = bmp180_temp_coeffs, + .temp_coeffs_type = IIO_VAL_FRACTIONAL, + .press_coeffs = bmp180_press_coeffs, + .press_coeffs_type = IIO_VAL_FRACTIONAL, + + .chip_config = bmp180_chip_config, + .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_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); @@ -3260,8 +3297,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 (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 0c32b6430677..e0e47bf22472 100644 --- a/drivers/iio/pressure/bmp280.h +++ b/drivers/iio/pressure/bmp280.h @@ -535,6 +535,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;