From patchwork Wed Aug 28 20:51: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: 13781924 Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69C9B1AC420; Wed, 28 Aug 2024 20:51:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724878300; cv=none; b=c9sznk9oWHBznqFAwUWydZcOp3lKhfRNJJKOdD9NnMC91OLIrk+nIw6OQPpIQlCcNIay7BGGhGOsHFifTmd8DLtRWl57o/6OWZIfV3J97SE+TY7FB1NxxXshVUu5eECQ5ABXSR8jfYJ8hHCeOq2ONFqe/bs1z7wNeJsM1SnBQmE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724878300; c=relaxed/simple; bh=cdY/TENqpqXqAOnyRhO2/xpzQRllFMlVUbT6+Wo1keM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bLX865FTv+yaIuvxBGqKqFLMuhOMXBNGgPon4aDSu4jcJ4CplbrMZF7NXInp+m9KP2181VtmmglxWibXr2aAGe+dxx/8Okdu4GnSPvGgC5lXdWVB+0QF7hHKRGkJ3VUZhJJzlFyVh9nfCm1RFHXgjYjfEGlIEdEY2OwkB2J9gUo= 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=GWy5tlc+; arc=none smtp.client-ip=209.85.208.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GWy5tlc+" Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-5bf006f37daso1918539a12.1; Wed, 28 Aug 2024 13:51:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724878297; x=1725483097; 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=XhxstM4mID0lLB91lA10snaXJWiXlyBjKw1XE58PBaI=; b=GWy5tlc+rkbf3L87wDW+FuoWUXeqpG7ATeSgPwIetwTuu3SjAWrVQaM5Re6l2vZzte iwGaoGmuD1Yvo53/qfWJVLGlJ8ApLGCIVdHjimRyVGvUkxdOugwA5co72bEYCtAMQU4Z k1+AxZnAXbgX4223ZdnbsBLf8UnWGBdqe3osFcRBUmMW527bUcUXGJxrrX5jrFNtfo/A nMMOFBga8S/qyPfizFnNsqEukKVpLJ5WFW3CsJM2BD0DfGFly1DZhsN8oo+PSst69cdQ uQyj1BtDmVYTuKUqe0WB6NUn+UpyFXBY5u91QQ3FXz/ogH7l0yRlgsBCk1Rl1MelxBrF 3nHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724878297; x=1725483097; 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=XhxstM4mID0lLB91lA10snaXJWiXlyBjKw1XE58PBaI=; b=Gm3yerQIynr1S5dVmQV1qDAgXILHyFmh4mRtjMYfxpFhbFDqPPCbwbkFPRsbvAVnNv 6ESXdLviWxV194YtpA/9APBnlTYqa9V4U0ybBppDHL/rHE74tuzEJZlV8fmab/pIbVJ/ WF3GE19RiE7D+b+32eR2Zj9Jj+cf9Fc/AAnhsjhj0qZ+tvA1xVdL/aveHYRdCVWYf8Rv RJH3RuO/u8MAH1crKR6F6eOJH9SZthYGeGFQWjLdl0LluYKSir7GPRLd0qe0gOECISPD vYuTvGy2Lb6jOCKT9fuCpZB2+a3jkBW5c5NKAZwYW3eSs8kjTpnEwPjKY0CeI6vfogvq 8TRA== X-Forwarded-Encrypted: i=1; AJvYcCU61pkFIAh1Qm8TrMaIa/ZcGZ+6PkkKDLryPO7GgZXy/Dd9x8VGPA818C9XZnhHQu8alNSvNQ44F11c@vger.kernel.org, AJvYcCUrN2QHyPbEapKGKZH/ZRg50Uk/277htLPoG9h5Bf0ZcN3Ch2ws2tm/iGdTIB39mvP0WZ3C6d5zV1+6@vger.kernel.org, AJvYcCWESRvYGAewlTVN6/jGPgwYSMlEFw1JAuRr+/u/4Z3sVAgcz/G2Xw4mO18zs/wZ/YaSyclOz83QXatzmlQI@vger.kernel.org X-Gm-Message-State: AOJu0Yzm9mJmYWkaBr3KjRPCTScVDofUY4BjQoSjwcNtnG2qDqQTpYD4 H5YSxwtcd/Ys99goUEzj+sDgLbDHJRETMuktZeFkNTPie2ZyPDyC X-Google-Smtp-Source: AGHT+IEj+40dFJIDo1+J116D5d3sOqiA9FK7FU4HJWxta4M0H2u6XIh6WLb5TbdqMvxHQuPQxDZPEA== X-Received: by 2002:a05:6402:1ec7:b0:5bf:256a:a19e with SMTP id 4fb4d7f45d1cf-5c2200ddc2amr443158a12.4.1724878296021; Wed, 28 Aug 2024 13:51:36 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:4c6b:aa66:d4d1:a1d2]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c0bb1c2f53sm2646566a12.19.2024.08.28.13.51.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 13:51:35 -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 v4 1/7] iio: pressure: bmp280: Use bulk read for humidity calibration data Date: Wed, 28 Aug 2024 22:51:21 +0200 Message-Id: <20240828205128.92145-2-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240828205128.92145-1-vassilisamir@gmail.com> References: <20240828205128.92145-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..9c705f2c4a7b 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; 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]; + 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, + 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 Wed Aug 28 20:51: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: 13781925 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A48811AD3E3; Wed, 28 Aug 2024 20:51:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724878301; cv=none; b=HYLaLoP5xx28Gfh4r24GsTbhJ43LQI8wbBxQO8xIDig7fyR8f9mN1Y/NmTCLxR4rhXsgh0ulCu+sz0/HrHmKAIBgHE+CXz0AHz3MsYlaKcko0+tIpJHTEBboEv7mRcz1TIDKo6HZJEnRlVwmeyiI1sIZ73x58YOzENIi6amKS4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724878301; c=relaxed/simple; bh=vls9EuVu0bQaZPZBOJSZopuadCL4aBlQi8cbRT/QtzU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pXseWP1ZOGdCKbIxVCm5BBTTILrAIkQZfCvsKreuNeb8xI0XPZZWeRDIbWQo9zYkd0n8NWqNxPv6QS/yJap+LM8ks7GRM5Hx9qy58DzUz5535ZVwm8dbDUXSnYsARcd/4zGo550rKCfC0yfzX5JsOeRHhTC4kdtIS1yat2kz1IU= 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=DepO+fp9; arc=none smtp.client-ip=209.85.208.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DepO+fp9" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-5bec87ececeso7937495a12.0; Wed, 28 Aug 2024 13:51:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724878298; x=1725483098; 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=QmUinFSzzE3WO95ZRcc7laRZdgnoTLEoTy9z6rGQ07o=; b=DepO+fp9bPshuPIxI7XjNrGMFXDEN4K6WW+n5fTzqOEnnuKzHD+MdQgEP4q1ATMI7x 9VsnJrc9xGIFBBJXI7Ar6FbdTMAOp+0b9lNKrZpbvXRKqTkZdf8o8jbcgxrjBVJTEMAm DjfPg9DrFHrWaEq45cK48Dm5Lb9BXFc1yVT2K8qP8hMwk5yKk/FrPlHBB628v0/YgD2N jFQrwmHxytYTHAkDkK0pihwlRqKFIvlwEwSr55AaSNqHkQfFAkpf9vc/v/RJriJcSxjI x5xBkChOG+PWJCw8/TAUQ8RITtqZEghdWz7jUjvU4cjqLI2AHPn3Jm+Kgmpr7QTce+WR FzAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724878298; x=1725483098; 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=QmUinFSzzE3WO95ZRcc7laRZdgnoTLEoTy9z6rGQ07o=; b=k8sfEEK50DjdqOWZ1AVW+Nz5GEU9KCLgp+cfGeMkZmsnhrNJAo+7oDsEXH4nIbI5v/ 4WD6HmfvVm3kTddYubbm4PXPxb4JLEuUV5vI932D/dJ6T/NIMhrQxt/WT7znD1y7jOaJ aUpn2DiblLxS+od0PTL0+mCQbYnnhA//TTUR3+MVwtsoDrR5rqOFjASzPUziA8tknFCw nX9gTcuwW0b1hJ65/AsgZIkrEjJVsv++1lMD3m2ta5ue78bwueXlXQKjbqpg80LJya2i SB+lCQ6UtzlLnpIop6XiVOvr0E2UcRhCn4siqvy1mItY+ZxTbiwXyS6UuVqyUVfnDa4/ pDVQ== X-Forwarded-Encrypted: i=1; AJvYcCVPtIKIgc86h1nLAW3EfzVKXT28i8LxWYocGyGt2Hf2LQRftlJxu0IpUykmmpQvyS0Hl35Z0ZBSXPgWx75X@vger.kernel.org, AJvYcCVXa1tWquzALIvn1HM0lxNuYVIe7ZmH5Bg9qCAj8xF7Pdk8QO9uVLvyuP4kJ6mpee4AF9/38+qLyX7t@vger.kernel.org, AJvYcCVxgpG3mjtVky3BVYtTnqbOu4DdQjWtc9daQ3NKI9ge9aTUernVeWCRcEXh0iWbb+7X0pbPKTBWK6M9@vger.kernel.org X-Gm-Message-State: AOJu0YyoLZT/JKy8RuD561YN1gNgBDjK2gcho1ORg6PKLrN7lVX0i+Qt uxxUFNGkowcRWoPIbd71PO5Plm7sNNjkP4ePLkGiWXBN8iG3M/+X X-Google-Smtp-Source: AGHT+IHFWw+TAr+FZNVGYM5sflWZXs/B2vQHD5ngf0A+Y7U0Ougy1cgRZf55M+qLmiDqDlCci4FpHg== X-Received: by 2002:a05:6402:1ed1:b0:5ba:8ad7:4859 with SMTP id 4fb4d7f45d1cf-5c21ed3e1damr619677a12.14.1724878297280; Wed, 28 Aug 2024 13:51:37 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:4c6b:aa66:d4d1:a1d2]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c0bb1c2f53sm2646566a12.19.2024.08.28.13.51.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 13:51:36 -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 v4 2/7] iio: pressure: bmp280: Add support for bmp280 soft reset Date: Wed, 28 Aug 2024 22:51:22 +0200 Message-Id: <20240828205128.92145-3-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240828205128.92145-1-vassilisamir@gmail.com> References: <20240828205128.92145-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 | 31 ++++++++++++++++++++++++++++++ drivers/iio/pressure/bmp280.h | 3 +++ 2 files changed, 34 insertions(+) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 9c705f2c4a7b..193a8fcbb5d8 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -965,6 +965,35 @@ 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"); + + /* + * 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(data->dev, ret, + "Failed to read status register.\n"); + + if (reg & BMP280_REG_STATUS_IM_UPDATE) + return dev_err_probe(data->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) | @@ -1082,6 +1111,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 +1232,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 Wed Aug 28 20:51:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13781926 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A82FB1AD9EC; Wed, 28 Aug 2024 20:51:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724878302; cv=none; b=EuNLvSXjop4JXHjFkqxROQt26HRr5jORyLxuIAXEkT6jk5Tfioah1L5W3DSYvsVbX0tkKn17JqH10g45jAQlY+VzVClFUsm9nOT95gmAZuS87zCGSBx8tYXbfBQrVdZ4dOptqsPYyUsVnuAHiQ+rX/LdzzvxNlFWee2MZmaOy2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724878302; c=relaxed/simple; bh=0iet7D0rlK7q1YjM9WSEX/rBTI0SAhaaIvLj+kxB2Jg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BU78fCHD2Dye6WYea9WjMDZF3SZLbz8ZlrjxcDDYHngQGb2FkX+Cq1wfWHPc6PTj5r9DuFR2ou1q8m3piyRP3g3eGI/89hDLsAP1NXFU0DYzmIgGwQRxnciydCuCoNlp/dR9LEZtptP2XrcWi3FDSpFrFzRCITkD6a2ZYe6ssvg= 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=R13QM8Ey; arc=none smtp.client-ip=209.85.208.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="R13QM8Ey" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-5bed72ff443so8360001a12.1; Wed, 28 Aug 2024 13:51:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724878299; x=1725483099; 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=YhIMLJlEIHmwmWp2tRa34XckrWlMANUJGP6JuPKZqLc=; b=R13QM8Ey3HPLG+o2nTEG0vEHsFekmLt7MkBGPDZUlhWcLtcq+yFbxYRnL2KlPHnQKy DZgH+W8GfrwFVwBQNkJlkoRHXvKUkuNNlmeLbqCw2kOj2EY4STZDRO6SqP6o3oA2sESa Y89YR0wYacfRI/x7wjKHkkFPRa5GFrtu7kYwem03zOVA5yz+1rc7gg4csfVnb1K7FXqF eUnpOr6MuQtmLWhSruD9lzf1NSv0shiRpbSrE65CVvuPDDZ8bNcNVvLPtmyJrF6ILAt8 u/nmkhCVNn4eybphgVhjo8KYwB90XadY0VGSg/q/a7iOLKACazsLg82CipoYUxGh7Bso a0wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724878299; x=1725483099; 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=YhIMLJlEIHmwmWp2tRa34XckrWlMANUJGP6JuPKZqLc=; b=s4zURjwuLiqmTyU0wcs22jvpq4hpyhXc8lHDWJz00M+rGz3lJcZl2mvrA91MDn71uE 88EBedZG6HwPd1JwCrb8+PIqPayYrSFVqFWQw7d9OHBmwc/CTqJoYm7Fy3c1xd4tHZ6X BX092hUyVx/EeMDlFwwPE4hZAXTbvqdWsLA/bPdDD70S0CDlOtLFVkYt/vRNnouWVvCb VS+t5lfcyXVZPzMVxmwbvwKy0cvAzjf1gQnVlRwH0wKCqC2TAnCOynNSFu2UYsk3qAaO sy+N+38zCwe8NUB1hPmGEIF4eaVVsjlu4NNJSwe5YyKJEp5YMk/VFsvuhIjwb95Ai2iT rD2w== X-Forwarded-Encrypted: i=1; AJvYcCU7DVlVugGc46IilZ/5Xqn0YcqmppQAUvd4fPlxLXmNbkcIlpKC9IUs8mBTVBrtsYBLlXQQujhW+uV+3j1I@vger.kernel.org, AJvYcCWdxDMGKMnf3abrHxHn1fBSxReAfXapwpbJP0ykgW7/knLuGuRy7W8Njlspoy37ZZp3Do8jlKhvQbWg@vger.kernel.org, AJvYcCXttqTeNmaTvtrCkZ4e9iMzBPJZDu/5yhEkSxYSDf/7tYM70JTwfp9Akd2FpJNNZXZRtmahrBZ9G65d@vger.kernel.org X-Gm-Message-State: AOJu0YyR2GHhwBlPLQxsLV5zi0hCnagfW8bGWKJ6xXuec6Gzd6V8ixfk fl40JUCGxZUlSNcwxYt/BUuyY+9PpfrGcTRVCbvEMpol76KyJ/qn X-Google-Smtp-Source: AGHT+IFLyEkG91DwnEIVHhppVs5RZ9UJUlnFzgtkC9ODeVltQEq5VEf9924E2lA+nbkXJmpVH9u1yg== X-Received: by 2002:a05:6402:2714:b0:5bf:c8:774 with SMTP id 4fb4d7f45d1cf-5c21ed4085bmr573646a12.15.1724878298515; Wed, 28 Aug 2024 13:51:38 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:4c6b:aa66:d4d1:a1d2]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c0bb1c2f53sm2646566a12.19.2024.08.28.13.51.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 13:51:38 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andriy.shevchenko@linux.intel.com Cc: vassilisamir@gmail.com, 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 v4 3/7] iio: pressure: bmp280: Remove config error check for IIR filter updates Date: Wed, 28 Aug 2024 22:51:23 +0200 Message-Id: <20240828205128.92145-4-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240828205128.92145-1-vassilisamir@gmail.com> References: <20240828205128.92145-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 193a8fcbb5d8..2ca907771d42 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -1562,14 +1562,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) { /* @@ -2159,15 +2157,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 Wed Aug 28 20:51:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13781927 Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (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 C32231AE032; Wed, 28 Aug 2024 20:51:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724878304; cv=none; b=P09dQqsCVLuA98Ry0l0uUiO5M3Crn6OkDx54VQE/npAFC/AY59mXlHSSdvcK1apGC3K1Nh1p8mw7ilWGezenvdF35qIRm09xk8myfy0pV/5Dpgs63nGNWw21Arl5/jyJjNpfze16mPBBEmuPscSY8PYxg4tbTf3QYTFn2x3VQ1g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724878304; c=relaxed/simple; bh=NuXoFwvSc7sE4whJmVtv/72jwN/VcygIviN91Xc6XsQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cffUbaPftSO9frQbuxpx88QY8QpY4VPPru4pXJhp6j2AfHUe3sQelHl1Gj7LS2YL6wamPhKE0dHx5UpJ50uIG/5DvGJpsdSzNw99OD4Rt2NhGWWfa8WdMO/fz3uIRbxlUZ36tSYqg+pVDba84u9pxEWc/R0Nh7P7Dli9A1OnG2I= 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=HWaBL9f/; arc=none smtp.client-ip=209.85.208.54 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="HWaBL9f/" Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-5bec87ececeso7937540a12.0; Wed, 28 Aug 2024 13:51:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724878300; x=1725483100; 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=wYhFTLY6b7f+AMAz39N+orsF7lbeZTKDiBczyC6En4Y=; b=HWaBL9f/6beTVz5aAVByL5NZn4MxHWDyz+uqY2pCWSmbKH/g5+4hngfnfwlSxD9lvY vjWgpX1nTXDc+PCZUvX4rQYOzpEcp9r/4hJqdQxQHQg+D2SDniFob0UjluqHhy1JEo0a F4nJy5C+9s6m6yTq+EL443pGhgAw551zN6mTpMFN7+mnDXGSpOksxZGWpLZJ5H1x8cnj Mq7RnNj8fJjsdZoNBY51cVfGne5cAYkRM03tiq+y4MM8M94Z6NXBY7b6gCfnDF+3J+5u Pyb9yoehCRY3XnC4CZSM4FyzLYb50WOQLDlpY8Hppe0LPFQ6DtWdeFFdE+xjAKCt4X40 k6xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724878300; x=1725483100; 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=wYhFTLY6b7f+AMAz39N+orsF7lbeZTKDiBczyC6En4Y=; b=XveIDuUpQPObztqZPe1UzCO9dg721FFfIOzE/yJ/hjnBXq3fJPtBbQ1hP38IrWUsEe 0b++fMxjqdHmGXqgNbr6O9MNbhZfN1ObjznXIc2WlyWXGmn7aCNZe64AD/01Ol5QNIsf J5FPDNfM+mnMJElOGKnFft81tjXY6Nef/iUo3MlFvocrxgFmKGwmtM09e6UL+/bfPFmt +OBUxFXuEmnBoiXBR/FF/0TnwKdBG1KVBTBzRoNuJk1cEnSGd18tLN0+UmFp6JtEKodO Gww4yYu10AnNNiGukUt7vk114UaDO2QcsP/STo0Al9jP8hn62HNOSNSIIH2dsWFCP80s 7Z3w== X-Forwarded-Encrypted: i=1; AJvYcCVK65uEa5Qj6K3ylqZKpfz2UegeHzTSlSXMLkkObHmCODzQe326ZWgyqhXNqpCm5qBU/84MoMBCVedxERMx@vger.kernel.org, AJvYcCVXsFhPJdekhTQaxpySp1gUg92990N5R3xNgT9AeJxIMVT9cAoLAt0vSZUQ4YXn9uR6C8okVrdBzpy3@vger.kernel.org, AJvYcCWpY5HoTJ1MP27avTFrXzJfUvNJ36q5Ax3kdsbUqiErjroCNRBMYpN4r5RzNUIIIRSkNh7L23S1dhl4@vger.kernel.org X-Gm-Message-State: AOJu0YzVV1pt5lOY8FDd+Q+A5qbAXLiXtuNriB41rfWSvF1gCL/c+7i9 dc7xV6wnRD90C/Wg3b1wy6XqTIXG4wfZQpo4rTkSXd4ETaoiB13V X-Google-Smtp-Source: AGHT+IHj8Zlz/50MX/gPQYnqyr7TSqnZE+01Wu7GkCSlraWov9R1l2BBQ1iw7jJY9Jmor8PGzCDbZA== X-Received: by 2002:a05:6402:430f:b0:5c0:ad36:b38f with SMTP id 4fb4d7f45d1cf-5c21ed4e422mr501829a12.18.1724878299481; Wed, 28 Aug 2024 13:51:39 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:4c6b:aa66:d4d1:a1d2]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c0bb1c2f53sm2646566a12.19.2024.08.28.13.51.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 13:51:39 -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 v4 4/7] iio: pressure: bmp280: Use sleep and forced mode for oneshot captures Date: Wed, 28 Aug 2024 22:51:24 +0200 Message-Id: <20240828205128.92145-5-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240828205128.92145-1-vassilisamir@gmail.com> References: <20240828205128.92145-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 | 294 ++++++++++++++++++++++++++--- drivers/iio/pressure/bmp280.h | 21 +++ 2 files changed, 294 insertions(+), 21 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 2ca907771d42..e716bcb1dc96 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 @@ -617,6 +622,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 +659,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); @@ -994,6 +1015,70 @@ 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; + + + /* Check if we are using a BME280 device */ + if (data->oversampling_humid) + meas_time += BIT(data->oversampling_humid) * BMP280_MEAS_DUR + + BMP280_PRESS_HUMID_MEAS_OFFSET; + + /* Pressure measurement time */ + meas_time += BIT(data->oversampling_press) * BMP280_MEAS_DUR + + BMP280_PRESS_HUMID_MEAS_OFFSET; + + /* Temperature measurement time */ + meas_time += BIT(data->oversampling_temp) * BMP280_MEAS_DUR; + + /* Waiting time according to the BM(P/E)2 Sensor API */ + fsleep(meas_time); + + 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) | @@ -1004,7 +1089,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; @@ -1111,6 +1196,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, @@ -1232,6 +1319,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, @@ -1519,6 +1608,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; + + /* Offset measurement time */ + meas_time = BMP380_MEAS_OFFSET; + + /* Pressure measurement time */ + meas_time += BIT(data->oversampling_press) * BMP380_MEAS_DUR + + BMP380_PRESS_MEAS_OFFSET; + + /* Temperature measurement time */ + meas_time += BIT(data->oversampling_temp) * BMP380_MEAS_DUR + + BMP380_TEMP_MEAS_OFFSET; + + /* Measurement time defined in Datasheet Section 3.9.2 */ + fsleep(meas_time); + + 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; @@ -1579,17 +1733,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 5000ms + * 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; @@ -1615,6 +1771,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; } @@ -1708,6 +1875,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, @@ -2095,6 +2264,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) +{ + 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(data->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(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 = 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); + + return 0; +} + static int bmp580_chip_config(struct bmp280_data *data) { bool change = false, aux; @@ -2112,7 +2345,7 @@ static int bmp580_chip_config(struct bmp280_data *data) return ret; } /* From datasheet's table 4: electrical characteristics */ - usleep_range(2500, 3000); + fsleep(data->start_up_time + 500); /* Set default DSP mode settings */ reg_val = FIELD_PREP(BMP580_DSP_COMP_MASK, BMP580_DSP_PRESS_TEMP_COMP_EN) | @@ -2165,17 +2398,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 @@ -2271,6 +2493,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, @@ -2518,6 +2742,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; @@ -2588,6 +2825,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, }; @@ -2640,6 +2879,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; } @@ -2810,6 +3050,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); @@ -2835,6 +3079,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); } @@ -2849,7 +3096,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 Wed Aug 28 20:51:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13781928 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4D661AE04C; Wed, 28 Aug 2024 20:51:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724878304; cv=none; b=aB8DwMZKmMTjgctzK+GAxZye2Rdc8WjSdkfAiIRPatyayPuImgHJUJYxZ5lDv3btEEeCr96axWUROEabR61An0jFN1RF1QqbcZ6NNMNzu3PU7F9RGswvkuXeH4e51XoFyWjEpGLOlHpnIBKCReUaf4/3JOQ/klIootfaP9nEam0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724878304; c=relaxed/simple; bh=nR1UARKtJbgTLNjrbNerSzHx4yuTclXSA8lj7rB331s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ANL2YNUr3/TjRwLk3qm6VO1a17urpNfiDWn+YPtPEfbvoPyUZvVUjYcgpSt0zLvcFC06xZiTfieRsqJTSQeb2Sct5Hv/wwJFdgnvOlp02DLiuk7/YQBiEmpJEmf/0mKT5NJ5xMAMLu2PYdSjuiwDAgPfk3v8+D2db0yTImNW51M= 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=JLzLpgWF; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JLzLpgWF" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5bef295a2b4so1955583a12.0; Wed, 28 Aug 2024 13:51:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724878301; x=1725483101; 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=x8nxfW+rDWF5El11bTwqMOFX+cAJkoVWHy2J6xFbSEM=; b=JLzLpgWF845FaaNSErrHNkSU10wOmUf/u+gSXxCd/uq1VIp7oe54QieM6XQ5ePFygI 4bwJwUCQlX1d+tYR+IbvlyD4lqqh0BQSQVZbv9ag/PJl4qkiy/gIjq6NiNwBE6n9Hi2d Ifh/FuZ3dk2XlkATeGvUv38iy1eD8VDRnmq/zij7U380Hll06F19UgJZPSU1ENQ5qCW0 K3ksIWcroXCdKClJVi0HxiTZzvMmdk4RyuEhiMtY1iorsB1GaPTSfu/5UgqhmZBTZNef vLp0eecmppfR1BYFUeQ2YlN2cGUAs4n0eMREb1y7DldptSjjO74AcoLa6wfsRHf8c2Pg 7QDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724878301; x=1725483101; 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=x8nxfW+rDWF5El11bTwqMOFX+cAJkoVWHy2J6xFbSEM=; b=C/+kbtxEh/T27yDm8QKhBo91oXLuLtPsc7kwwUADu43p/TTDzy8JiVQpSOFlm8Pt/b PHkAI+p2IP/lqE9/Erwl6GByJaETiQFODHB/kRZ//IXJaYGt/VnOzmXNUiudXvqztxLs mThZqOdbH3YpWwybi1sEKUHEyVgO8xGlawpNidqOJNjOM8UUhfaoY8WJrKPLJckaZCOE utuCSgp9HFTbhMwsE3TBhLO1bT97Dfs7wz1EDab46SNXr2YyHohd2AoCk0kh/03wRx8I VpCePu/f76TLw5mRNJg7s5BRCUQMS5ityjDUA7cEw0zxKAltm6bX+5Lwrb1ujkgphK0U BjAw== X-Forwarded-Encrypted: i=1; AJvYcCUGY+FvnM14wG/JTbFRYa6N6FtVTqFfwIiAF2/EZxgvGmyE5tyk2T1zaBA2ZUjKm761cm9rLgL6mZtf@vger.kernel.org, AJvYcCX9EHCUupQH3rpQtilpq08do8CTUaNgMxUihhFbMfX57kqW77JmPcvuj31uquZHcPpqc/V4eJCx5+wK@vger.kernel.org, AJvYcCXRdX8NZn7ioOe23RERiBFMDVt1qduRWqPM4kC4CCDKlpj/czjKNwekserNKCDgod6nYLIHp1wGfiD5pz62@vger.kernel.org X-Gm-Message-State: AOJu0Yxezqeo6NPXTVMwrkymyotQizsFq2a0p28774ZOGMzoqjEcjKon 8KTq+CYefHf5RMiM2teblhkwUboBPVuPWu49UsF4r7K1zv3/EAKq X-Google-Smtp-Source: AGHT+IHfQqlMMMF6MVOKFWCqgXlr/u9wp4s+BpMMSzK55QWj2QozDxuq8o3d2RqZ9SkkIM2k8Fuz0g== X-Received: by 2002:a05:6402:50cc:b0:5c0:8ffd:6fd0 with SMTP id 4fb4d7f45d1cf-5c2201ad226mr389717a12.13.1724878300625; Wed, 28 Aug 2024 13:51:40 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:4c6b:aa66:d4d1:a1d2]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c0bb1c2f53sm2646566a12.19.2024.08.28.13.51.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 13:51:40 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andriy.shevchenko@linux.intel.com Cc: vassilisamir@gmail.com, 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 v4 5/7] dt-bindings: iio: pressure: bmp085: Add interrupts for BMP3xx and BMP5xx devices Date: Wed, 28 Aug 2024 22:51:25 +0200 Message-Id: <20240828205128.92145-6-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240828205128.92145-1-vassilisamir@gmail.com> References: <20240828205128.92145-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..edf5901c6c87 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. + required: - compatible - vddd-supply - vdda-supply +allOf: + - if: + properties: + compatible: + enum: + - bosch,bmp085 + - bosch,bmp380 + - bosch,bmp580 + then: + properties: + interrupts: true + else: + properties: + interrupts: false + additionalProperties: false examples: From patchwork Wed Aug 28 20:51:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13781929 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.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 5FCCD1AE85D; Wed, 28 Aug 2024 20:51:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724878306; cv=none; b=ha2ccJr3+F7ZrbnAg0mEOfhCB57pSCtAAognzDyjuxXwKfOEiLXvuo/nQa1Rm59zSQpO7nuNaH57ORT2kALYVO4PH++xsYrwakASQHB507JweWh4mvFoG5vwhJLGRivJ5SwK8Mm+ZQs2CFfq/oiTxYIljYjxtMt82cqV7FV5+Ys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724878306; c=relaxed/simple; bh=irbEEXLq3KeiYRXNIZnVt42/z9sHufSatG+DsR4OwsQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Rt1/e9r7ZxMRit+CIlEBub2dEe5G45tXGMVkXI3Q/8PxnxqDkCn2gD5qNenLsH8bLPwNt/+Ik8TjLHkUZeP/vd3jwSuThC4eRDj62aenm8xzALXDsX78o1f9P4fBIRU2EbqMYKJ0eq/0+JfW0e9mjV0caiVNmotdJms8N2w6vko= 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=N2it9TPr; arc=none smtp.client-ip=209.85.221.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="N2it9TPr" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-371afae614aso3795442f8f.0; Wed, 28 Aug 2024 13:51:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724878303; x=1725483103; 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=GPQMiMSnj5TVKRtNl5cJ/OcLpnpbWvPugl5U5PPuG44=; b=N2it9TPr4tZw8NkbqcrB31Y6Vi+Hq3QYaBRwLKNTQbzvJGVpJ3adBxq1yNgtKoVlea nxaDjz6VL0UZQtyBIU3mMfO8rjGxDnblDP8/WbVXkmlQK7wSM67GSL6YsGXkKJJ7gDAn Hh9wYDWm3iEz82XTbOgNSkcl+JN/MODPiWKEPQKP5qsivEpgavGbzw1HRSfz3ufr9riP IkCwXbEWo6683NxRbq7YuuImGyftNPLZf6zZu+yw41U6JYhZ270XjFFf10YIkAr0c1tP 9eKMs1j6CpJ8XF4hdbFI4PT/d2EX3Ye5xQoUMm7fNgEzA7hRw/jHg302Dvgnqi6k5SL7 TMKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724878303; x=1725483103; 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=GPQMiMSnj5TVKRtNl5cJ/OcLpnpbWvPugl5U5PPuG44=; b=kKsau3qS01ft+EgEaEd7Q6lBSpU8b5WXXwWjD/tL7bKHS6qPb85l8j13G76+1XFaV8 4PYJTvfuB9WjUI1PjXRBSWkoVpUmTnm/CxNsH1PIzjkCAaZe5WB19mYjflgUfzntPj/H u506w1NP45o9MbFdzcYwSUfRUZVpONkklqk6OV9kNXKrLPTLOhR4/HfQAMXoScIlFFmw jiE47v7Ri2c7VqDpnroE0fD1X/tXXalBdHcA/WXySPoQG3BY1RzZ7nB1zsZaPKLFacos wyhHGzG6pOYFXpVk7pJyCvdD4+77cm/x0udC0xXf8uaepAxt/UQhGI/0smIsvY2nn6dj v3BA== X-Forwarded-Encrypted: i=1; AJvYcCV7w3Y0rYvgIp6yHCroFTaMBwHZrUhWN09YLfWlwYMOcNULD5GODhZTuUvFpBhxVAVzbw4/3AK8QWTK@vger.kernel.org, AJvYcCVGDEY5Bs+JaIp/JBkVPNpm9rwLLYnAZdkkEWu5qRmVMrX0sERDYH/+p7bunmZqjwfd7shpNLH/TnrqCDuR@vger.kernel.org, AJvYcCVZA78IZLa61n7JrUECyjXT0pSnFqhutgoIGI95XVRBtpI+o2MmS628XS6fVFljbtpB2OcqIZmeTssB@vger.kernel.org X-Gm-Message-State: AOJu0Yx6iOsJoofgM/t4RQa7KoWd1WzV1tUg3QBtb4EXGWGjc/fOUWv5 r/WlYvPnmAjF7IFDCP7byiGc8LuAW1dIq3r4s0PzT6qMl79zuD3C X-Google-Smtp-Source: AGHT+IFTzxz9UqkPDmf37QrOgbo5+Di4bwMKgfIna/vJsLqwu082e6HexxXlMOVrCaVEv82MhaPIvg== X-Received: by 2002:adf:f410:0:b0:368:4d33:9aac with SMTP id ffacd0b85a97d-3749b54ecd6mr379254f8f.31.1724878302040; Wed, 28 Aug 2024 13:51:42 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:4c6b:aa66:d4d1:a1d2]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c0bb1c2f53sm2646566a12.19.2024.08.28.13.51.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 13:51:41 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andriy.shevchenko@linux.intel.com Cc: vassilisamir@gmail.com, 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 v4 6/7] iio: pressure: bmp280: Add data ready trigger support Date: Wed, 28 Aug 2024 22:51:26 +0200 Message-Id: <20240828205128.92145-7-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240828205128.92145-1-vassilisamir@gmail.com> References: <20240828205128.92145-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 | 231 ++++++++++++++++++++++++++++- drivers/iio/pressure/bmp280.h | 21 +++ 2 files changed, 250 insertions(+), 2 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index e716bcb1dc96..c37c56446183 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 @@ -1282,6 +1284,66 @@ 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 fwnode_handle *fwnode; + int ret, irq, irq_type; + struct irq_data *desc; + + irq = fwnode_irq_get(dev_fwnode(data->dev), 0); + if (irq < 0) + return dev_err_probe(data->dev, irq, "No interrupt found.\n"); + + desc = irq_get_irq_data(irq); + 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 }; @@ -1785,6 +1847,83 @@ 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; + } + + 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; @@ -1879,6 +2018,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); @@ -2421,6 +2561,89 @@ 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 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; @@ -2497,6 +2720,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); @@ -3044,8 +3268,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 Wed Aug 28 20:51:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13781930 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FEAB1AED27; Wed, 28 Aug 2024 20:51:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724878307; cv=none; b=P+hiPkPhTMQ+3j9JwdavMbpsG6Hi900JVIJzk0YSsh9kDeYpN41DXasgg02O93N5/5NIcY0Jfy94k4249gpb/PRLgdk7DVe+n8YvwFYk67N1fJMHjWC9xoeNK7K1veTmR27YSqubgoS5P8PEM7JZVPmm61rKb7rzF6e2na2khCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724878307; c=relaxed/simple; bh=VreTkHUpnWR7lb3dgZZXyDCzLJCJBO5+ymQLc/S2b7g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=R1PHXfFUYVezy0Qmnqgi1rxNULQIuJGmQ/d1BoG9NjOGmF+J/8giCPAw4f55KQyCBplEubLeXISOtR6h7Q5z7udPsVNK2AMFWD4t1UroamdAzuJGDhkfjlbr/MSzZ7RVCj2D2gpjcmngk8etdWvVYSn2QR5XvsU43e2JbsgJhXk= 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=W+LiPNf+; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W+LiPNf+" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5bef295a2b4so1955631a12.0; Wed, 28 Aug 2024 13:51:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724878304; x=1725483104; 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=qSJgUF7j/CDv51LHyvaqoomolwU97+ab+ITbPInKXdU=; b=W+LiPNf+Nm9u+oUEPMZ0aJDSh9cOxrVxYEn4WvArsWBH1L3OpoXhaLZdLaDIdhH+H0 I0Oc3i6MlH8pLoTmqEDQ71dyfxHtZXsrT+LH+00NAWOeXjAfFUyL8cmYiw0FILSBVuUj weErDRVKsRosDUJA4+0oi2PBQpLsAVrgYrkP5m501ZrFSyDEUJAe5GagZ++QQxwJlUCS 9XaHzBePftH9olkBIzBIP1rp+1yH/lVNQrKqsglcnt62+WVmLUB+VcE1eXSKhvTW9Sjz dFv6vWP/D8fFYDwniudupfpHNP4gAkXiQv9jh50uDJdm7b3F575tWANFVJ4OmG8UHtbo jRog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724878304; x=1725483104; 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=qSJgUF7j/CDv51LHyvaqoomolwU97+ab+ITbPInKXdU=; b=Os5ukGv7ZoOqA+ZsMc8+R0KhmWU8V9Ko205hZ4sSZaQhhZ+IYVCIX4Ozn2H3fuCMaR e7NAbl008jA9XgV3fKZP9n7TTasNcqlUtX8GHC8tN4tlsiO/DtPTfInMK7ivRog5mkZS Sxs/Of2mrBYC5ahUPrvJotZAEvfidGq3C0mFlhJdcGRVpReHFx9gvvbbaU+BTBPIE5l1 JK6iMBrrzSfagEpwka7m0kdoyjTMWAr6s5y7Bdd9WSk7LXV/mQV0n5wT+hydSQgkggzj dLA+b+FIGBtHJErDR+R3u9fbnVFsTEFBnTTWzOJIg+lnPjkU2+ke4csxx8/d6eTcPcdF sHhg== X-Forwarded-Encrypted: i=1; AJvYcCUHgojU+SpfvO/xWkE8Pa32yZ95PEv6WA8lzElwipIGwH9iHE8tvcMJG5n7Oowgu9vuOiNbyZLfSy6i@vger.kernel.org, AJvYcCUj+/kFALZAH2aT/4yITn3/eb9Zu9OVtBm1xpBCgjc94OJ6xTWoLT+AKzCBuD4znYIK+qEiMTLN2ZWJ@vger.kernel.org, AJvYcCWamLGxvHmzDxofq5k+/ECpxGUkUa7335WPM8fbHgHhzfOKSLCHHUn/G0hXAoCedvsaW0a6p0icopemx56D@vger.kernel.org X-Gm-Message-State: AOJu0YyIwURcAGz++whmsqhMboOKcR0JVROvsEIdE5CfPRLCq0b4J0jY U0GEOOGWJKn3jWXBNFWcrSyaJFQgcOztxnLZOjZz2xtJPUtYT4Yd X-Google-Smtp-Source: AGHT+IF7zUV8JYYcmFlef3xIaxgXgO6mzL3vCdS2v5HnNCXh+nN+nGhJg3NRsYnMOK/7ocUTO3PmOA== X-Received: by 2002:a05:6402:26c2:b0:5be:c2c8:8631 with SMTP id 4fb4d7f45d1cf-5c220126f2amr423487a12.8.1724878303595; Wed, 28 Aug 2024 13:51:43 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:4c6b:aa66:d4d1:a1d2]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c0bb1c2f53sm2646566a12.19.2024.08.28.13.51.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 13:51:43 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andriy.shevchenko@linux.intel.com Cc: vassilisamir@gmail.com, 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 v4 7/7] iio: pressure: bmp280: Move bmp085 interrupt to new configuration Date: Wed, 28 Aug 2024 22:51:27 +0200 Message-Id: <20240828205128.92145-8-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240828205128.92145-1-vassilisamir@gmail.com> References: <20240828205128.92145-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 --- drivers/iio/pressure/bmp280-core.c | 62 +++++++++++++++++++++++------- drivers/iio/pressure/bmp280-i2c.c | 4 +- drivers/iio/pressure/bmp280-spi.c | 4 +- drivers/iio/pressure/bmp280.h | 1 + 4 files changed, 53 insertions(+), 18 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index c37c56446183..948d11c6912f 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -3065,13 +3065,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(data->dev), 0); + if (irq < 0) + return dev_err_probe(data->dev, irq, "No interrupt found.\n"); irq_trig = irqd_get_trigger_type(irq_get_irq_data(irq)); if (irq_trig != IRQF_TRIGGER_RISING) { @@ -3081,13 +3084,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"); @@ -3098,6 +3096,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); @@ -3269,8 +3305,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;