From patchwork Fri Aug 23 18:17:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13775660 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.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 23A44191F64; Fri, 23 Aug 2024 18:17:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724437043; cv=none; b=fRqL0j8nnq26qdhloW1ZIxJmTDPp66KGMn99uXjqd2NKfpOqEBBEgA8WhF3ZKqAH18GEZa01b14Pvg3EqWnUuMN6pLzd6DsZJbEn6O8iQ0BF1wBaCj6CEg+QpuBvSDt9dfFgxupt8ZHIFlDxPNK1BbiWaN0F/Ce9AG+q/pZuXtI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724437043; c=relaxed/simple; bh=Dm3pIlii8u9e0jZ0Y6BnPz8p5SELz+k6jzyoRF0YADw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=R87w5Ks+jyHnXdw06i3mc/Y3RmO/9fpmUT+bZOkDWgWc68d0ff8E5I+pk8wi2QI5z8yVZ/Rebwgdz9o6wEdSZGk1CodNZNzBh+yv8PEj5o/hxrG1xRX80+H5Hi4pMehRZ0jJKnUzsSDU5siajeYLR10cKlDerOj2dhvZ/GaFvOA= 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=aCLurHyO; arc=none smtp.client-ip=209.85.128.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="aCLurHyO" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-428e1915e18so17268215e9.1; Fri, 23 Aug 2024 11:17:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724437040; x=1725041840; 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=VrwIpvLrRFP7oKPLvCMon+/Vo0FO1x4rOnetJCQOaDQ=; b=aCLurHyOP5xe0/zvjStPINBKd83xT3fqVDFH7VdXFqcBMYOplHHPHtY80ry8NgUzDw 6tEXp9eMq6MqbpZg/YNdyJHUoV2mkJSn2ND0lJ84VG8BNxXwmPAyocyjZ1teRYg2YKYB upVjJEAgPbI6wfqQoLk+jBKAs52/qEcr0LcYEu6vvuqitRb7187F3d0Kixa3RxHceUM5 cr2DWLDK7YP9XFg2yPUtMlY1PH2W3hzXGBdM5s9++gJ6ux3CvyFNiN97IxMCEI9v/gF7 QjzUbjNKrH0cZ5vrIVzgCQRENgEWbgE9PeJ6/Rf+oOTrMDgEQqLWRbZAeWCMHE99lErg NN7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724437040; x=1725041840; 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=VrwIpvLrRFP7oKPLvCMon+/Vo0FO1x4rOnetJCQOaDQ=; b=JUUBSHOEcaPNVaAlQIL1mH01czZLlfRqJg4nIUpU0tRaSRCGK6jLCkUi2bL2LaeStG uEZoyTF05SBopVkj/ueLtdpy5L5kG8mq2EHxmdH8LOe5xNg6QTEw0de03S2Iasy+qwvz nTCWrMNDCG3Ozy+y4N9GkcN/pgM+Rl8eNQdDAeeunGESQWuGXZoBwxznHh0lf9zpEqiS mhzmfEuAm/aQwkzy+e+T9XkokBK8bJ7yoJf+4bs0voS4DXFEFj7VLBYM2RlHcaPXTkgn Su9TtW3VFy59HW243NdqVpiytZUdWisGQPEPEWcTYuNFpMY6THnMQahBXiW3hBTKH88S 2eSw== X-Forwarded-Encrypted: i=1; AJvYcCUUzY1FlUOeeiulyShgo/bZd8saHNoBOV/5xAW2VxPZip9nQNTiP5O9P2CqbevJ4xIyHb/4AdrjwkJn@vger.kernel.org, AJvYcCVCMiuqzE6OOHgvNmojTFLzEuYNAm4rSEG+UBcmvp5bd3Iwi2+oaEEllQaZ0g3GIzaqlxNi0kzmCUJ1@vger.kernel.org, AJvYcCXh2tOasCQ5d1uc+tnXO57d04HUFvo7Uhb+pV5T6Ci+47Gy4o6kiiIJgTQicGUfooTB6gydhMzPt20cL/27@vger.kernel.org X-Gm-Message-State: AOJu0Ywoq+NXgLns4vTwtXUG/cm1tVJBHL4fusssAFynsc0LnN4qknOj y23wGG0WesVPZUujQDQBdzLmnuIPZxLVZw4VaBfUya9BIaLean1+ X-Google-Smtp-Source: AGHT+IGf9aiwjdXfuWRZQ4W3pm5m9vOVmjrMWCxz6sdZm3VeG34KgzLdAKIdrsetsaqAw1pq3sCpZw== X-Received: by 2002:a05:6000:8:b0:371:7d84:9bef with SMTP id ffacd0b85a97d-3731187d118mr2122192f8f.28.1724437039709; Fri, 23 Aug 2024 11:17:19 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:f90d:5a72:8d56:a041]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3730814602asm4677939f8f.44.2024.08.23.11.17.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 11:17: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 v3 1/7] iio: pressure: bmp280: Use bulk read for humidity calibration data Date: Fri, 23 Aug 2024 20:17:08 +0200 Message-Id: <20240823181714.64545-2-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240823181714.64545-1-vassilisamir@gmail.com> References: <20240823181714.64545-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 | 64 +++++++++++------------------- drivers/iio/pressure/bmp280.h | 6 +++ 2 files changed, 29 insertions(+), 41 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 8383d1a73cf9..c23515048081 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; 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,24 @@ 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]; + h4_upper = FIELD_GET(BME280_COMP_H4_GET_MASK_UP, + get_unaligned_be16(&data->bme280_humid_cal_buf[H4])); + h4_upper = FIELD_PREP(BME280_COMP_H4_PREP_MASK_UP, h4_upper); + h4_lower = FIELD_GET(BME280_COMP_H4_MASK_LOW, + get_unaligned_be16(&data->bme280_humid_cal_buf[H4])); + calib->H4 = sign_extend32(h4_upper | 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 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 Fri Aug 23 18:17:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13775661 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D3801922C0; Fri, 23 Aug 2024 18:17:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724437044; cv=none; b=PgbVG6Jp5qvvcb27g3BdPiMgDSdbg5jrXdCFtZu+NZ0iDyOg1YfpXNZBSH3IDuJ1FEL3mnBSTKZk6E2vqxxKOrtamt7CwaUrrAzYKX0hXh9Q00utS1mZWvHmhyHFPVvuLhwzqTApG+41+iXkRM/dlOkQ89vqVhjMZtXvthvhlnY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724437044; c=relaxed/simple; bh=dInEK1RyoEbx8ygTH0UIyODtMxSFAhWcTeVnffqBY8U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=krsPT2mxjsMSbb8/rH/99MhJaRlu6pERrXmTFUOeW9OYyFYQXCkYhuOtvtHhOK7IwgpzMsIQx+fcnGCCr+aH5DdAFlu85wHBwl1S4AB3y09fYv5npHX0458HzQ077oqTcGIW70vqusQrchUPD2Rgd2Rwx0UDc/i3eAAuHhhysY4= 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=eR/kcwLd; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eR/kcwLd" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-428119da952so18506945e9.0; Fri, 23 Aug 2024 11:17:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724437041; x=1725041841; 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=nol3XnobnccYGXWjsSL+QwZzmXq+Own29WJ/wbPBdgk=; b=eR/kcwLdIGZ5tENCkaNngPUTi6dB0y1CBJz+zkaqMnxnpTnELKgqHFOaCJq1lZ0oZ3 fKki/jSNQGb5mJAg/q65Ny4T4YfGetoG0qkoxmxEI7zlWDS0LtpFl999uiz3gchE+U74 +fZdzAMLEjBbgyn9pn02iVob5m/0libeOCfvtAcYHek2Ce0Z7aCn4DZnwJrX4c0FZm1i 2RyQfCXqMPheajMmENEIsTqr7mhhSlHzKfDxfkRco+7jyPdyHCJBETOosTvp/tY1m8XR G2TvVCcjRlItAYGQgKr+WQ6s0V+I4MUPVE0rHC2IyJ9SDsqr1TCFapNppeB0dy/GSeS8 +7AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724437041; x=1725041841; 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=nol3XnobnccYGXWjsSL+QwZzmXq+Own29WJ/wbPBdgk=; b=cKdpycxi1g+kkdKmX6tgWP+Vgb8xIeOslCmrxbLCcRA07Pnth1tKu7J/0d33JJ3jN5 PO02XjV5cHi3dioaNh6LTtidnpW00OAJ3sRpuEHRDcOq8OVJIN88waEPjhttDqe19toY fUtq5hby1vUUskP0eFbVODeJBYWFKfGtJKYhY6Oj+pZIlKMuhAp9OpJ4zPhwYsqpjlf0 CftwGzPepTwOzO/zyKtkRqWR1LYml5/BD+9C5soQp+KykQ3UmUIvvzPlew5K2Uzws+H2 m1bJe4YWTP/PO8jzqIcXWyvyYxyFuKYbuaqJ8wdvVbPQVVIsnYD9+wCcRmekMZHINW/f P3oA== X-Forwarded-Encrypted: i=1; AJvYcCVPHrmQx2FVJFJ8K7T2rr2Prgo+BWAkFDnFm51eTvNRdLYhBmouIUEQBDqv+vXZLgg8a8AMTG2USAT0XOw0@vger.kernel.org, AJvYcCVkIo5UBMC64Bd0VMO0l43SbpoD15yXGlI86eCTDR/f4T+35j8mZ1Ca36s1jl4JYwWs9K4bn4NjhWAa@vger.kernel.org, AJvYcCWKPIWtO3pNlfFuzhsSlwTqCyK/PdymqV6tP3ubOPhNY6wcLCJHPYN51HpigaxolXQG7jYvtuV9fXIX@vger.kernel.org X-Gm-Message-State: AOJu0YyyS6TDwGCP4gvnRjdx+JwiHMBaj7eiZ+c75dzmHQh0tT4etfSW GPpJm6Gy5dhDV9cvQK0yH1PGYKHQBpTvkkb+O3zcbKkAht/VnYAB X-Google-Smtp-Source: AGHT+IGy/pxOyZdjCPAqNV54p2ut2qDfwuz42B5CWo92jB82B1jfwDxcLoKPba9RAYjmBd/ejhBWwg== X-Received: by 2002:a05:6000:1f89:b0:367:9ce3:1667 with SMTP id ffacd0b85a97d-3731189afa4mr2351730f8f.15.1724437040947; Fri, 23 Aug 2024 11:17:20 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:f90d:5a72:8d56:a041]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3730814602asm4677939f8f.44.2024.08.23.11.17.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 11:17:20 -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 v3 2/7] iio: pressure: bmp280: Add support for bmp280 soft reset Date: Fri, 23 Aug 2024 20:17:09 +0200 Message-Id: <20240823181714.64545-3-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240823181714.64545-1-vassilisamir@gmail.com> References: <20240823181714.64545-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 | 26 ++++++++++++++++++++++++++ drivers/iio/pressure/bmp280.h | 3 +++ 2 files changed, 29 insertions(+) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index c23515048081..e01c9369bd67 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -965,6 +965,30 @@ 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) + return dev_err_probe(data->dev, ret, + "Failed to reset device.\n"); + + usleep_range(data->start_up_time, data->start_up_time + 500); + + ret = regmap_read(data->regmap, BMP280_REG_STATUS, ®); + if (ret) + return dev_err_probe(data->dev, ret, + "Failed to read status register.\n"); + + if (reg & BMP280_REG_STATUS_IM_UPDATE) + return dev_err_probe(data->dev, ret, + "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) | @@ -1082,6 +1106,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, }; @@ -1202,6 +1227,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 Fri Aug 23 18:17:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13775662 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C727192585; Fri, 23 Aug 2024 18:17:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724437045; cv=none; b=UHeHoGoq1kXesfVkEkZ6NO9H5wXwSjLP2zCnTWFVXlMFwbEJ4kvrikM9aF1aYcxpkByrhPOwOLlproz8e2XIcDx+cyqB92RjpM5fjlCUvbd6YBgbS+2GmrbvhxnzW9isMDid21B38h///mx1I7SjkBVilXIJn9Tx6kumZGsdyy8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724437045; c=relaxed/simple; bh=ELEh/8U/XhpTzYiXqpqPnwmy2HGOAVgO3wIGOIh2WAQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Oto6ayoXSiXy6zCHprYNxRgRn9Aobci0JXgnM/BdQi7FrCFB4hSMAZjRFY3ur93O2EHyCHrl1bILOOwHPVPTs7zSR3olfkzbg5T7pXLEtGDuUr1cw/MVes+xJuHLs+xXoq5eisqJoYmrvP9dG6gFMt4KNdtlkrbs9bp1bX7JNUg= 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=g3Dsk20a; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g3Dsk20a" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-371a92d8c90so1135176f8f.3; Fri, 23 Aug 2024 11:17:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724437042; x=1725041842; 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=KnyWsDgDdmHzGpI1ttRRBbvkkmI+2IPKzA7O8Bj7mPs=; b=g3Dsk20aYPlH0zYJiPBi7g9w4bYHY/9vHgpY//9/x/oumLXuFe2Ltie5evPoFGNbiU NwRWM4zaDVs7fkWZqqA45h8zX4eTXaIDQri0eIzlM0LtHGbM6wkCnB7BeCAGAaOTc2wT 3PU+BDwwdmetbfNYScQXK5AnjeHQKuxWXW6NdfBNVoe8M87/hFFQ+h3n6QfGnbsBrbxy YGqUxf8KWixjzWP7mZ7tl5blTwKVp89FkjDWTx8HmSwGBBgKBArfbccudtM5CgxlQPYh xXaufy+C2fHChE+TWbi4VSpJt1bRw31NyCPpSHKnql0QxEcDnPJmOeD+27tt5mkhXOK+ 513A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724437042; x=1725041842; 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=KnyWsDgDdmHzGpI1ttRRBbvkkmI+2IPKzA7O8Bj7mPs=; b=G47NJT7fejknaPLR/t4eexTaEkFRK0QA8a8glttxvczln0+GPr2coG08BIUWYTtBS7 VDklvs0UCoQqKsuGtG9ow7ijTXAta8DoX64PcA4Gv9fNJbiQqDvjNArAzn9S9UITxBG3 Z9MTAw1I4VckCphddwb+X5x8C8Ox0RkOFhp5Kpu7TG0Ba87M6FJHguXs+JX9yTMHrul/ wrqEq6YKQPhVd0/12MrjtTVvPFksf0et79lFFV1H3dteVKtmtTviQSkMKQoRow25sPRA SQmJBUjGwPQbacI0M/Sg3PPfGFkvQ4KsXJIfrcMsZwBulrVFNE1WrrVRZawMPNgT3Jd7 Hzxg== X-Forwarded-Encrypted: i=1; AJvYcCUPgJ3/P1AF5vffNXQtMIqCXpbHxsdu+xQGV1vsjbB6fHsUqbye2ztJdg1pp/+KTc1BOHedXoJIKj97@vger.kernel.org, AJvYcCXDAGD5Ur+ZbxG3BMtI/iUkdgJwasWnQtiyBeGX08AQAZUoQU1AtnSMcP/ziTeGUnJg1W3F2yraJGCy@vger.kernel.org, AJvYcCXdCFX+0UHPrPoVrItfgUtEr8omfvBz8p4oMthSPon9N8v12/0TXsImWiTHOqWUbyUA9UDoGC6vXA3F+aoy@vger.kernel.org X-Gm-Message-State: AOJu0YygF8+gsMKqngPPYCJ7EKRYkPPllJrtiUmXLn6orTJR801c3qih i+faZ1nyZFHWMTvqN4F5piLX4QjtxHVZiFiSJpMLkbAXnRNRO9/S X-Google-Smtp-Source: AGHT+IG5FQPD1Av1eiqKZfDgPpWmLf8u0kInlvmBUKc90S86F2JCHTQF1PNprUt47iz6s8Ebr14rJQ== X-Received: by 2002:a05:6000:2ad:b0:371:8484:57d7 with SMTP id ffacd0b85a97d-3731185e93amr2102022f8f.15.1724437042006; Fri, 23 Aug 2024 11:17:22 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:f90d:5a72:8d56:a041]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3730814602asm4677939f8f.44.2024.08.23.11.17.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 11:17: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 v3 3/7] iio: pressure: bmp280: Remove config error check for IIR filter updates Date: Fri, 23 Aug 2024 20:17:10 +0200 Message-Id: <20240823181714.64545-4-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240823181714.64545-1-vassilisamir@gmail.com> References: <20240823181714.64545-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 e01c9369bd67..736a1f4fd5dc 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -1557,14 +1557,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) { /* @@ -2154,15 +2152,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 Fri Aug 23 18:17:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13775663 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.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 318401925B3; Fri, 23 Aug 2024 18:17:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724437047; cv=none; b=LzT0G+PwRb1TSDWYuWoyZ5zQNnmsFgu6/JyP1vq2DogQ6XpVLFegjg3datkANAfvDNR5jJ0+aZk5mce8YavvZmV5wHyOpie61xtUoHaPy7MxaR+lJPF53+GszzaZBcTOBNzF9PD+Mip9+YAQreQFiKmTDkH7p5Rpbt+ZipfOVCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724437047; c=relaxed/simple; bh=ecuhficNmCfQpxSlfvPALIJiHH4vtImAG3pqSQ7YDhI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lGATJUOJ1bqcG7/vb/q/07uC6DQcd61ivl04qmuEsc78HPwzma5oIKh3SlZmimAa5aLu8eYorN2MlgL0907P5szi2Mcj4JId1mW2TPudPHwo1TbU0Y3CehpopiLYDyaps7VbLTePkUA9o82/1dZ3ls1EZGvJqbdVf5SfH0p6tw4= 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=j8iN5prM; arc=none smtp.client-ip=209.85.221.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="j8iN5prM" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-3719896b7c8so1112011f8f.3; Fri, 23 Aug 2024 11:17:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724437044; x=1725041844; 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=oCqLHDpZWjOO83Tbb1goX6058h8PiyPnjUYwXZy/ApQ=; b=j8iN5prM7sJ479uST8HtWApaciZOZCcZvXm2Z+/hokHRzutBSnCjbzdmjbvCDtsDh4 QKEwzpXpvHN/iLvUzEb3w+NF7U0nJPmPWf2fOoNLTuu9dg1WgM1L8gSMY0v4ZzYsXl9b 3hnqChyzZXXpnPSq/VKuI/8VmydcFw/cLEJa1UmcViSPE6pUTJHKkuEUxoipF6vsx9ne 9BoMbNsyiFApgTBoF2dv5cDwIuPds1Ei5lIRCX8LfCS/brbfIfVdZfvp+fb+wFVZQDGb aW43p/ot3hpZsBdyADr3h4CS1FCXRjN6clprHV3XBpCEFaw/vH/M3MqnGPwg4n9R75Wj qRmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724437044; x=1725041844; 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=oCqLHDpZWjOO83Tbb1goX6058h8PiyPnjUYwXZy/ApQ=; b=QH5nfOsCLrd5kTSVzfxOmvqywl0+a78+O+p1QM4DQlw1qa2JbnSTymrozsMnl0zArA T9ZsmsYe9T8PXF3Yb3hlibI9m+CeA/G4Xf5CpnY4sEnGZvzIsWEvQn2zyh4+44pQptFV 8FQI7uVdcHZDkD9/FikimmSvuSlzRLKrs16sDfLwP+VdFRPwfB3Y5lJtcrYlUEEd2lT4 ann2b/HGYym5z5Nz9spf4SM6wQ8g+StXTWl+uwN9VGRIQnFCj24k0/UHWvrE9ZvWGQ13 ZrrzDKGCC6sLanDQk1SonUKaVG8gqOJwHox3IUOJ0Dv7OPJdkLOd4mEdN8lb5VufO+a0 iqzQ== X-Forwarded-Encrypted: i=1; AJvYcCU0iM1xgWUYykZYcxV76/423tgswfjzJilMk1fXVgvQiPwBFBMpML7VWUEu6BM07XtMN27YO2cGkF5M@vger.kernel.org, AJvYcCWR7OUuTgAAAsGS0m2YJ03oyz8x44Ce0WLIurHu+yFHPU0RHSBhe0F64tOFha3wG7I4H5he1+4SDJsn@vger.kernel.org, AJvYcCXdWWUjE1rHXkKvIj8EInf8ccizIzrYuuDtET25AzC1iGErA9stwOXEhWRSqLGn+t+ILenofYgeqrGBKw2D@vger.kernel.org X-Gm-Message-State: AOJu0YybnwYK7kkOBXU4JYPAntWyBtRDkL+ttjMwtG0U8Mp2tbX3JCzK a2esbDjvEq7HbKp+Hj5EkU29DgZIzhRoYJ1jaEQ1m07F7RB62ZGg X-Google-Smtp-Source: AGHT+IFB8a0D684LPnadIEylwBRPe4KC/ikeT7obSo2BkTIM2325DYTarIv74BoCJS37586khJV2Bg== X-Received: by 2002:adf:ecd0:0:b0:371:9121:5642 with SMTP id ffacd0b85a97d-3731186390amr2042610f8f.30.1724437043114; Fri, 23 Aug 2024 11:17:23 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:f90d:5a72:8d56:a041]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3730814602asm4677939f8f.44.2024.08.23.11.17.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 11:17: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 v3 4/7] iio: pressure: bmp280: Use sleep and forced mode for oneshot captures Date: Fri, 23 Aug 2024 20:17:11 +0200 Message-Id: <20240823181714.64545-5-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240823181714.64545-1-vassilisamir@gmail.com> References: <20240823181714.64545-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 | 277 ++++++++++++++++++++++++++--- drivers/iio/pressure/bmp280.h | 21 +++ 2 files changed, 278 insertions(+), 20 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 736a1f4fd5dc..e1336aeceec0 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -617,6 +617,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); @@ -646,6 +654,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); @@ -989,6 +1005,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; + int ret, meas_time; + + meas_time = BMP280_MEAS_OFFSET; + + /* Check if we are using a BME280 device */ + 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) | @@ -999,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; @@ -1106,6 +1185,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, @@ -1227,6 +1308,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, @@ -1514,6 +1597,70 @@ 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; + + /* 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)) { + 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; @@ -1574,17 +1721,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; @@ -1610,6 +1755,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; } @@ -1703,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, @@ -2090,6 +2248,66 @@ 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) +{ + int ret; + + switch (mode) { + case BMP280_SLEEP: + break; + case BMP280_FORCED: + ret = regmap_set_bits(data->regmap, BMP580_REG_DSP_CONFIG, + BMP580_DSP_IIR_FORCED_FLUSH); + if (ret) { + dev_err(data->dev, + "Could not flush IIR filter constants.\n"); + return ret; + } + break; + case BMP280_NORMAL: + 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(data->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; + + 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; @@ -2160,17 +2378,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 @@ -2266,6 +2473,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, @@ -2513,6 +2722,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; @@ -2583,6 +2805,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, }; @@ -2635,6 +2859,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; } @@ -2805,6 +3030,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); @@ -2830,6 +3059,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); } @@ -2844,7 +3076,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 Fri Aug 23 18:17:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13775664 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FAAA192D8B; Fri, 23 Aug 2024 18:17:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724437048; cv=none; b=fGRbaXuKxb2tqzFcd95zTvetjyjRiuS+PLSAVFN0JC29MZTQgG4BNIzeHC3nl8Vx8jtOhlhoJzyWJf+zTskHf4K7fEeD6Q7fi5sahWHZC6Uin8lei6TTD1rCuug2ccavIgDsWuzI4dqKHrwjDSeJcDsvkf+Hqdw4NH0vY6xCTdY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724437048; c=relaxed/simple; bh=3wtsOGntTA2EIT7umcv//Zg6qc+Tm+J0IMAe4ZJ/BnY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sZbJU61w9nakFbvtr7VVNTcoBswnLgUR+ZkigurXm6Kf4TMRayoQC1V7iRZLi1PZf92Mrip8FY7GduMm5t6CIWfAsKeAppoke+WMelo9VZpQZ9XWOXtY3lH/i3ibP8qrJdsQYR9mQHBiK92ac9Mh/9CLgj9jv7/VZB9QCyQOqKo= 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=nO9ScDjK; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nO9ScDjK" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-3718acbc87fso1145500f8f.3; Fri, 23 Aug 2024 11:17:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724437044; x=1725041844; 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=MZT399FYQw+nUYF3pf7lvE7xdWfuUjkXJO7D1WP/rJA=; b=nO9ScDjK378DVpjgt5OJRowrmMhLf+Zqpx/dl6IJh7HF27VYLsoSYhq6I2RbD3PaG+ bHFtn6w2H5uwsay5954K+v7Q/C9PdcnWkk+h9eK2ggApLAoMNzR5e24X9XZYQ7e0p1aJ TV+ooQ6cgW/tj7g6nB/I1Q95TapfpFQnSy0FxioxPqpkiJKcDefDwdv7O/gM6nP8B4Sl 799CXYlN3gIK5le/5mOhizBBfvdQz2A6lMziUJhEB5ZynBuyZl6HAzC+zURD9EPgu/LZ c7G7/IF1tPUJG/k7DwTG40L0cEqwyS/6fT7orr7ZmBEtcaiZDzwkhgIO8czZ9HN/QGhU 0T8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724437044; x=1725041844; 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=MZT399FYQw+nUYF3pf7lvE7xdWfuUjkXJO7D1WP/rJA=; b=JYny8at14FDpyvEEj6/gUzD9+ZpyYNqWvcdqqw+aiuDvcO01U1cByQRP+PS1bT/Q7A RLDM/88EmyJ+D1zoqWNIropWmxMbBYyF46TEOdjBHLAhRQ2ZI1wn3gUpeCGRVJjT6v9L MkdAaNMNF08lMlnckZSd0/e35595KERLClijv1Qus51ppobbwX+nfMMsL/zlm7wOna8/ tJVgtDl4KDcLyXJUVSW7oAbxU/zedDfsxdTCBkMQPKSrATUW6BpfoZzz9jXPiOu5L2Th aPcnzeAEFjaWJjqr5BrN+qDaBWnKdy8sWnkSTZH36sEP8PGb1Ciu0nr5luKeNhmdfcc+ sSRg== X-Forwarded-Encrypted: i=1; AJvYcCUf1fK8b5EuU++pDXXPd/Rofz/mB6c2tkqN0h4YRTM8uh79nbCo8r/4WEn5PhITN4i7bZgO7gxvcGXe@vger.kernel.org, AJvYcCWTVe20tfmpq7z+h10a7+LIPOPrd9JyQymBAEB64AoS0leKxQaDABvbxZzlXxITsdj2LpiRQTuLJ0iw+SOF@vger.kernel.org, AJvYcCWYDCzy92BHY+lv5N2QmaW7F6bqIJGG4UINHghky+6F+KdMLvw/AjaECsNXDfr+S/eq2R8AFIPezsSH@vger.kernel.org X-Gm-Message-State: AOJu0Yzz2z5dCzKZwvtrwmPOqyESuvP+aGxyYsjPmk6eulxMqqSHBl5W w7lovTHo2HrDd1UPU8sCPDVnj+M3xg8BVFNZU7AtrXjsc9meGn8H X-Google-Smtp-Source: AGHT+IHKPYmZ4nWzYw9K36dKDTEu0K35LSFp3iEJbuELTA8swnxWqRay+4Z/gPDRDbBb3omyFFwEqw== X-Received: by 2002:adf:e0c6:0:b0:368:6f64:3072 with SMTP id ffacd0b85a97d-37311841974mr2027756f8f.7.1724437044128; Fri, 23 Aug 2024 11:17:24 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:f90d:5a72:8d56:a041]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3730814602asm4677939f8f.44.2024.08.23.11.17.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 11:17: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 v3 5/7] dt-bindings: iio: pressure: bmp085: Add interrupts for BMP3xx and BMP5xx devices Date: Fri, 23 Aug 2024 20:17:12 +0200 Message-Id: <20240823181714.64545-6-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240823181714.64545-1-vassilisamir@gmail.com> References: <20240823181714.64545-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 --- Documentation/devicetree/bindings/iio/pressure/bmp085.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/iio/pressure/bmp085.yaml b/Documentation/devicetree/bindings/iio/pressure/bmp085.yaml index 6fda887ee9d4..eb1e1ab3dd18 100644 --- a/Documentation/devicetree/bindings/iio/pressure/bmp085.yaml +++ b/Documentation/devicetree/bindings/iio/pressure/bmp085.yaml @@ -48,9 +48,14 @@ 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. + required: - compatible - vddd-supply From patchwork Fri Aug 23 18:17:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13775665 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.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 6EB80193064; Fri, 23 Aug 2024 18:17:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724437049; cv=none; b=OmKqxKLerCdX4PCeLOfT41TKnBjpvXLCuol1YhaOkcOlsYASGZ3Cp6zuCgUlcwEA7UdN5Iwhjfk8mwENIF22h+H6DkfXX44nIV8fR4t9bJ9JfQm7vx7cKzj18rDnj1k1+fx5M45AZVu2FWKdM2/tcBr+t6C7N8g/0jfL61BFTS0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724437049; c=relaxed/simple; bh=Y89p6DX8N6ueQTeusfzloJW6JIV2Rz2X9y/aLL7X28A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fmLQR1qgYf/hKgKzm6u51enocoS+XbKRyd4wW6wkvjfr3t7O8CeqkgnDRNxmyFfIIX/bd1xDohqlG9if8o2hNiilgzCrcpInwROFFCZWLO9cEbhjJuETfaTsForn4EGayZbTKjf1TZy/8lMmXCjVRLSWbX3JKB2EGSD/bUPcU08= 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=igZaUU7R; arc=none smtp.client-ip=209.85.128.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="igZaUU7R" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4280ca0791bso18503385e9.1; Fri, 23 Aug 2024 11:17:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724437046; x=1725041846; 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=jvt/FNpAYtEaAShVFEEPm8RnUqdU6ni6d6jREI6w6aA=; b=igZaUU7Rw/BZVQL2Zvg1HOyFf+p5WzarxOowST2N/dvUsngOwH0096lP5bgaw4GGAZ SzRlHdUxjsdnATmpXHrniDi4rBvn701lHxeGP4C6LhNl0sYpRLC9zM2K4+KL4Uf5jN6t WN4vNdtiy+4WxXMBHvrgIVdU7sf2/9O8YSxZFZg42ZOIMhNVvTljUokjL+vpIqFprFEb sjZ6jM1vnQnr4YkTkzZVrkTi06lrJxCmS9dT062Sv6q03vWnD9zA4hL8VHwnGWCwwUst /S93QlnDkEStYXEUmwBqNZHLFcE0UKcnbbSBcUJfxOZ9PkF0RP4u0jOzDtxpriAFfWuZ yTgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724437046; x=1725041846; 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=jvt/FNpAYtEaAShVFEEPm8RnUqdU6ni6d6jREI6w6aA=; b=PgYbZrkppah+9VYogq4zF+ba9788c+m0fPGI3bYIqEoUAo6nXYk1PwphqTavA4GIQZ aGO3U/HE6V4sCatECBgOWZkZy+0XJbtda4AHJKWtfPhcnJSDv5DwN2tEaWWwZcvyhHe5 FNhx7US63upPmsis595dWw9qN/BsysX88B/elEw6/+sZ1P038aL4sOUmGIMc1zutsWEo MwgkovGAksw+u7Pdip7wAIMaSbPcdtulwkNyA9jPic6HB6+J5DwPSAFWj7aKE2V2/brS TdbbcdHv9Hizv7bC5Jq84hL6+Qn9HN6xQyxylOASCGIEgPgfTgIQgeBNv43oYCTUExwx qicA== X-Forwarded-Encrypted: i=1; AJvYcCVpJpMr9kS0StrAow0hBTfQ8bBNm/tApK5d/s5HwLvTmU4WHB5hmB4rZpjJSCl0x1DSSNIUeQ8PsZ/r@vger.kernel.org, AJvYcCWU9nb3XkgTfpfolnQGx5sDdFKbGpakUXVYkOzzdMpe3GlIBh5GI65zTzOrsVGEdksjJKwq+d19y/Hpwm8D@vger.kernel.org, AJvYcCWlVcOvBC87DyMshqRZHeJAaegM0HG69fXdirQt3Oduy/LdOLId6g1+nnKlM4wNhU0ejJSt1sMIHRI5@vger.kernel.org X-Gm-Message-State: AOJu0YxL4kvtZdGkEv8pA5o9h98EQAiUCwyh8+Pf8+Py0sKSPOCRUUWX v9Xw8Ri3VBpI452h4oV+lC4a2/59Z6euGeBUiDzRVifXmWkPT3qM X-Google-Smtp-Source: AGHT+IFht4GCmA2FH2vNSh2pKJ6oWtzpmhrnSk1tpdhrVa4t6+hdDXBOiNPAJ6BjzxIEnLwq8Owqeg== X-Received: by 2002:a05:6000:e52:b0:367:9d05:cf2a with SMTP id ffacd0b85a97d-373118d2295mr2015799f8f.42.1724437045122; Fri, 23 Aug 2024 11:17:25 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:f90d:5a72:8d56:a041]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3730814602asm4677939f8f.44.2024.08.23.11.17.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 11:17:24 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andriy.shevchenko@linux.intel.com Cc: vassilisamir@gmail.com, 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 v3 6/7] iio: pressure: bmp280: Add data ready trigger support Date: Fri, 23 Aug 2024 20:17:13 +0200 Message-Id: <20240823181714.64545-7-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240823181714.64545-1-vassilisamir@gmail.com> References: <20240823181714.64545-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 | 252 ++++++++++++++++++++++++++++- drivers/iio/pressure/bmp280.h | 21 +++ 2 files changed, 269 insertions(+), 4 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index e1336aeceec0..f5268a13bfdb 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 @@ -1271,6 +1273,74 @@ 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), + irqreturn_t (*irq_thread_handler)(int irq, void *p)) +{ + 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(fwnode, 0); + if (!irq) + return dev_err_probe(data->dev, -ENODEV, + "No interrupt found.\n"); + + 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: + return dev_err_probe(data->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(data->dev, ret, "request irq failed.\n"); + + ret = devm_iio_trigger_register(data->dev, data->trig); + if (ret) + return dev_err_probe(data->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 }; @@ -1769,6 +1839,85 @@ 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 ? 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_CONTROL, + BMP380_INT_CTRL_SETTINGS_MASK, int_cfg); + if (ret) { + dev_err(data->dev, "Could not set interrupt settings\n"); + return ret; + } + + return 0; +} + +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; @@ -1863,6 +2012,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); @@ -2401,6 +2551,92 @@ 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 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; @@ -2477,6 +2713,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); @@ -3024,10 +3261,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.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 Fri Aug 23 18:17:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13775666 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.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 4A711191F64; Fri, 23 Aug 2024 18:17:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724437050; cv=none; b=iemphswloqPrflXxy2LBrOn4bX0SCchygrTZhX8E8EV8g0Zp55BV8/EWclBmbcrhmV9KtrIgIFOyjUCfpwmqOPN1PQTflO7b+jkz5aW7zUlLxaB45fDx4noA6TRFFp0DphiVrwfPWwpkXOfbeFyy05FS+pmheshTHHBGCm6dLvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724437050; c=relaxed/simple; bh=VqZ7aNHjQnz9CcP+r4qLOzHuM6HL3rFgPOdK5GOcS7U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=k+lWNL2QHHGO8p829KQfM3xMuNzmnx0FHUoVgUArf+yRH7BLN1k/cmIwpH73+TntUpBt7qkxfJOvqJ4noYEq/C4LVAhklPqxViyqc9vkQK5IOgP2J1db6ipXdY5WDnNY13RrFZjuCQw655A8rqqXBwktTnlsPaSiT9kWPkoutsE= 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=jII/dAvy; arc=none smtp.client-ip=209.85.221.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="jII/dAvy" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-371a92d8c90so1135213f8f.3; Fri, 23 Aug 2024 11:17:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724437047; x=1725041847; 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=A5/2QyWRZZHfgqy3T++OUbtEdcV7A9JzQS0OF1wredA=; b=jII/dAvyG+V2TwKMarHOeyEoRA1dU7BaUCmuxmRHV3VC9zYHSOHCGlPxTyKc4ji/3a ej5Oba5KJkWnbWXOlIRmK0sOWB1uuT3rugy2qS3zZMeTi0xnTr6HyzkuXEbaDg5NHRkx o7Znuwa9ZQrSroqmPMClcCob1wZYW3v4jH70+MEn8hx4aj4XzmqJFbV951dQ98lnxR2I nqfZybgbTYc4yWQ62JW/gt4oLdWo4ULpGCfIhB8CXYCcOyOxUErQs6L0lBXZ4uhk2E9f t41oSgmlDD3JT+ohid/NTWcx7QhKcqTI63olFU+iUtgPQwoJJgilMnQlPjLX6G0H0Tj+ ONkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724437047; x=1725041847; 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=A5/2QyWRZZHfgqy3T++OUbtEdcV7A9JzQS0OF1wredA=; b=msLpfmQ73I9cFPpZXA8p8aXMdWQZo+APUMRsr88cyXIyfRwmtl/wfXZSJCMWzTOxkl AXwMmTUOskiLoDOOw0rXxlths2HHlmf+3N8hsNZLJsgHFwxlI+OfKgzG1/3pXwZkAxVi BhyAKrRzELZ/fehgE/s1wF3emw6PYA7nOX9UpIN3e01oLru6B4M9+RU4nykPRCGTimuZ KSaDTYvXkE8Ds61qwJ6hbN2wHXH5GuBpzv0BvtZuitX7OI2jE1eVBzwXeWufZs1BesQ6 jWQsTPs6jcvtm8DbrjZZVqvI9YYyMGHlLzUctiOjUWZTVK+ZLY5DZ/Jow1tRENlV7fdt RyIw== X-Forwarded-Encrypted: i=1; AJvYcCUn5YPiB87fG+4uGYv9dI324WemOaXZ2jbcb5mYNHIt3LYqS2PjgM1T8VH3eSnY66ZR2SVKH4DNAdprnfJk@vger.kernel.org, AJvYcCVNAO4UL/Uu1hAlaIaT6Cxdi2SzEbKcpXEIS1ta3nk7+APcXd1eKOby/zSYPmSBPjvzV9fG/TWDJSTp@vger.kernel.org, AJvYcCWA/hWTI+mZdJs9/LxSNRV7wiQ6ctgDonpuURLPaKl34TMBuWymqSj14EoPbKrdX57XJO6KfhbbYL0l@vger.kernel.org X-Gm-Message-State: AOJu0Yz5sxG7cJZdnvZ2n52bLX3gWes7oJnkZg2hpaTColBz0tEEePU7 w+y7GK04yrhIScqJCOwBooy+GSSaggaQ4db/tUfmrPqmSkDOsjen X-Google-Smtp-Source: AGHT+IFPQKxcftU84dhm0fkb1SNgKD2EAJn7TvWPiUzYwBNh/RAU+o9AnxfXRexWrzsEQDadMchCaw== X-Received: by 2002:a05:6000:1810:b0:368:12ef:92d0 with SMTP id ffacd0b85a97d-373118fb7e7mr1771367f8f.51.1724437046167; Fri, 23 Aug 2024 11:17:26 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:f90d:5a72:8d56:a041]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3730814602asm4677939f8f.44.2024.08.23.11.17.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 11:17: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 v3 7/7] iio: pressure: bmp280: Move bmp085 interrupt to new configuration Date: Fri, 23 Aug 2024 20:17:14 +0200 Message-Id: <20240823181714.64545-8-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240823181714.64545-1-vassilisamir@gmail.com> References: <20240823181714.64545-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 | 68 ++++++++++++++++++++++-------- drivers/iio/pressure/bmp280-i2c.c | 4 +- drivers/iio/pressure/bmp280-spi.c | 4 +- drivers/iio/pressure/bmp280.h | 1 + 4 files changed, 56 insertions(+), 21 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index f5268a13bfdb..1d27777d8a2c 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -3058,13 +3058,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) { @@ -3074,13 +3080,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"); @@ -3091,6 +3092,44 @@ static int bmp085_fetch_eoc_irq(struct device *dev, 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); @@ -3262,11 +3301,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 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;