From patchwork Wed Mar 13 17:40:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13591657 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.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 330C5524DD; Wed, 13 Mar 2024 17:40:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710351618; cv=none; b=QzsVggBQWgXLcTCWFq6n6hwOWi4MBXIq8y+te9qreasu1WSqk6WlQLDFuPIOMiTW6KXezOzvuYx/L2piiLh9lFfOLJaZbdRxXx97rKtFaDUhMtiD6TtZzc+7BbJ2ZXGT9w09zSKK/zGV5mklFji5qswD+rWhumQVUfrRVsRpe8M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710351618; c=relaxed/simple; bh=6Ouxyk1MFE8oPL5EtYMsLRqOrNWjyubaatGPHGKRHrs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=W0gJY/OpsOd/2fTM7Bf8Lsx+pAaBgY96KVFgc8BYpp+JZhrk8/N2Xy9vkcq/67H5P3j5Q9VCYzCiToyxFkUq3uWUTN8PfFnoI6w9dRotE4r1LkPZE9x8VNtu25bTE/xOVGkKo05CJDK7STib6Kmc/oKVZ/QCPfkt6h0nXbIyXi0= 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=IXEjV1Gx; arc=none smtp.client-ip=209.85.218.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="IXEjV1Gx" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a44665605f3so10646966b.2; Wed, 13 Mar 2024 10:40:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710351615; x=1710956415; 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=6laUTApqd01ANpCuz0jrMfAwGjaFU1xJS3mFm+uw6r0=; b=IXEjV1Gxdn/4ASL8GtLHdlwDb8we+OZodmg2hFo3Th2vG85ol1pEIgXxtZQ1kJ8/0D VJkmADTjQcoxibVEyWtWb1Jvht4bftg+WGTjOBIkDWLqtXmyOrg9Nr0pGaWMG1GDdwud N5NpqBAF3zu00pwRPDK2S9LyNijC6QIJBISZYrBalwCah+lXaeutd7iDmQzOJzKzq2Q5 8B3551Q+nOX4U0ksJHKwos8N7heIQ7jb9WS3GXt2PwFjR+s7CCH/AcO0VDTICsa4dnD3 f2Mx39UIguMwEBvPfMDo980+w4qf10h4DwvRcCeV7YadcokWvabw618zmRGAMpSA+3IB bLiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710351615; x=1710956415; 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=6laUTApqd01ANpCuz0jrMfAwGjaFU1xJS3mFm+uw6r0=; b=OBykvX2hxCdVNb66k933IaWxDctjcDzyILhhbBwFga07CtCu6DCnEzb6sfZss0DLkR BmXX/FxFrsNBULM0Bk07VxZavyYxmecwz0ZSUtK/Z/cm5kz6UuX3R5xNLLwSzQq597p+ aplN6L+5ihxeXqzpeB/I197OCQyC98BqT7P1iV5d8TyzaymAp0CdXyXL2VQ1cWose68T 8Z7xXB0yQFpBZ4eom6ynxxrwcSniphJr1QRP6s8z1SpEBL4Tg5t7aDckd8tkSBHm7n7u d9N6zuwENukKORBDu27lZGGx1qNJmNkueK9q20GLNwYNjGiRYZKQDfpMscC2kyWMM02e nDfQ== X-Forwarded-Encrypted: i=1; AJvYcCUivlDLmJn5UEZOefLmhyYqw81SPgVm1oVWUduZGNX3V7WxrnuNYoU3wsx+wfv2crv6ejAEB7obOhdl+WuzOGNvMDdOszvzB1C8AF0kibgt3oUYzASZbuIctdITerEVNnjjh72LaYlf X-Gm-Message-State: AOJu0Yxp3OfZ5KlNw6LrGdl0ikXdjswxuRoQVUF4EKO366Kdq4pf6iAS zua/gW/xMDplRut515nJthE1aTe9+msUT9Xkhl1fJGyz5pno4PrI X-Google-Smtp-Source: AGHT+IGHlFExJN1yZ70hUjVMTDdX6foAzMMX10X8m78kkMw1BMjLQrxPvlsaPFOBXAoHTe1iMbWN4A== X-Received: by 2002:a17:906:e292:b0:a46:651b:b62 with SMTP id gg18-20020a170906e29200b00a46651b0b62mr985545ejb.15.1710351615513; Wed, 13 Mar 2024 10:40:15 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:fa35:157e:1a40:3463]) by smtp.gmail.com with ESMTPSA id m17-20020a1709061ed100b00a449076d0dbsm5028215ejj.53.2024.03.13.10.40.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:40:15 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org Cc: lars@metafoo.de, andriy.shevchenko@linux.intel.com, ang.iglesiasg@gmail.com, mazziesaccount@gmail.com, ak@it-klinger.de, petre.rodan@subdimension.ro, linus.walleij@linaro.org, phil@raspberrypi.com, 579lpy@gmail.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Vasileios Amoiridis Subject: [PATCH v2 1/6] iio: pressure: BMP280 core driver headers sorting Date: Wed, 13 Mar 2024 18:40:02 +0100 Message-Id: <20240313174007.1934983-2-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240313174007.1934983-1-vassilisamir@gmail.com> References: <20240313174007.1934983-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Sort headers in alphabetical order. Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-core.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index fe8734468ed3..871b2214121b 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -27,20 +27,20 @@ #include #include -#include -#include -#include -#include +#include #include -#include -#include +#include #include -#include #include #include /* For irq_get_irq_data() */ -#include +#include +#include #include #include +#include +#include + +#include #include From patchwork Wed Mar 13 17:40:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13591658 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.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 D342453381; Wed, 13 Mar 2024 17:40:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710351621; cv=none; b=eysZ0QgRmSeAo8DHf4z2G4Fk6G/HMg8OugH3aRBvPwY7OO8pQZt7a7APhB3o3MidJIMby4rHmzhvIoL+rGFMeJKDgAqpBfYA2tUJAEVjWCikwmlSg23596LKvhyuFyN745Vqx750QNoZDDVUdcJkEeXxMS+nJiEY5zTvaIDz7Wg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710351621; c=relaxed/simple; bh=On9sVYDLvPUcsKk2DF0yvW4V+rsN3YG+MuHq8vOLHfg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fh+/sA9TbD5bRDs6RQvjSJ3NKpt4UdEQ2JRmcjdG3kkgQdc8uXNoeN5D9X/tHFRRwxH82SAQAc3qbr7wXCjELjI1OpCg8AAoMH3NEEtestMh3759lLyz9KBg/OiEVjxDkUV8GY/tIXvHDqBWDBIO4vELRmobC+sEnQh2h51hFyI= 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=WshdTlhi; arc=none smtp.client-ip=209.85.167.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="WshdTlhi" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-51320ca689aso150766e87.2; Wed, 13 Mar 2024 10:40:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710351618; x=1710956418; 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=hB48c/985v0iXsymw7ct5Hw7M/WwZxYtKNkSzqMQG38=; b=WshdTlhiuEdLHw/0cTJHWcvfJrKxNRh/krLWZKWZd0q6ivfABHRlbwTTL1E8wdaIHG b3DjCEDLF17pbFJ5QUiRJbP1OTzTCeWL6kaiXp98HGPlhHZ4wvCm34Vmo4RqFl4rnqVy hoCZ7IOJyfJe5qNzRsvhDfAmkJidfO9POflFyfXb8x/tHVvp+WmwQYOcNY9RN0uhIqQk 7Kmc5Ju82uHbqstTAd/Bdek9irSAi4pRVd91F8QOpTctc9Pazx4NjRCtBSa0W15nbc8R BYMxPsv7tA+ofTwpWtVK05il8q/VYFCiw2GoC0GJt8zayG5U7vAJte6rj1OSSRCdQWS2 /AHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710351618; x=1710956418; 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=hB48c/985v0iXsymw7ct5Hw7M/WwZxYtKNkSzqMQG38=; b=mUByMCKNObeRvePgtMOD3FOlLmVOxkZNCVnlJJzGtjxbE2kKWrt40tENpsP7LssxR+ bGex9apgyNcnTVeuyyfGMAmGa7EoT5djn3nDPmLtFD6mV8gnEtM5d5PdbvaFiYiI2uB6 vsoDW79km/Fzyr0FCwQj6r3mrQ31BOhiYBuMZ1GhE2RhoaZT47kQTKz2GU1fo5xVJvyo VpHc3/zhJWarr4NYaVVNXPl722nuqto92w08twn2PWEPmiq9WNmNObvwwshMNbI3uCLl VKvWwAqZ/Dj8DwXvroHO7bnc+JF5PhhzyM+BFNWGMjKjmUxe2W+sDRzhqVsooxVJlzR7 dewQ== X-Forwarded-Encrypted: i=1; AJvYcCVBtFQNFvX7ZhEe3lKwlQtorueE8bClNpXtD1ge5a9MxzA8cfhCZi8uchZNwJyVDmYPvIj32T71xGe6GpCr1kqYUZBqyt3pFwQuKMYreGzvyjcGP0vTfsi8HCDQiJzALjhGjs75MbqE X-Gm-Message-State: AOJu0YzHnKD7PYm1pHstKFl0K2aBIXDManJv24InlXTg+U7NXNWPJ8Px yx7NDmPj7MaPLxn+YHUmiy14RVrOt0EMj2OSQjDIiearoeh+yAZp2Xp8pJtu0M3Wf0Hp X-Google-Smtp-Source: AGHT+IFfBnoncQGUY2cQcKcc2zKkLrdLPxIKy/eJtxbuwTU3/HG88bh8J9UNaCNd/AulgCrVppEiBQ== X-Received: by 2002:a05:6512:522:b0:513:bc99:677 with SMTP id o2-20020a056512052200b00513bc990677mr3676970lfc.27.1710351617983; Wed, 13 Mar 2024 10:40:17 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:fa35:157e:1a40:3463]) by smtp.gmail.com with ESMTPSA id m17-20020a1709061ed100b00a449076d0dbsm5028215ejj.53.2024.03.13.10.40.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:40:17 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org Cc: lars@metafoo.de, andriy.shevchenko@linux.intel.com, ang.iglesiasg@gmail.com, mazziesaccount@gmail.com, ak@it-klinger.de, petre.rodan@subdimension.ro, linus.walleij@linaro.org, phil@raspberrypi.com, 579lpy@gmail.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Vasileios Amoiridis Subject: [PATCH v2 2/6] iio: pressure: Simplify read_* functions Date: Wed, 13 Mar 2024 18:40:03 +0100 Message-Id: <20240313174007.1934983-3-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240313174007.1934983-1-vassilisamir@gmail.com> References: <20240313174007.1934983-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add the coefficients for the IIO standard units inside the chip_info structure. Remove the calculations with the coefficients for the IIO compatibility from inside the read_(temp/press/humid) functions and move it to the read_raw function. Execute the calculations with the coefficients inside the read_raw oneshot capture functions. Also fix raw_* and comp_* values signs. Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-core.c | 150 +++++++++++++---------------- drivers/iio/pressure/bmp280.h | 10 +- 2 files changed, 74 insertions(+), 86 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 871b2214121b..dfd845acfa22 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -363,8 +363,7 @@ static u32 bmp280_compensate_press(struct bmp280_data *data, return (u32)p; } -static int bmp280_read_temp(struct bmp280_data *data, - int *val, int *val2) +static s32 bmp280_read_temp(struct bmp280_data *data) { s32 adc_temp, comp_temp; int ret; @@ -384,27 +383,17 @@ static int bmp280_read_temp(struct bmp280_data *data, } comp_temp = bmp280_compensate_temp(data, adc_temp); - /* - * val might be NULL if we're called by the read_press routine, - * who only cares about the carry over t_fine value. - */ - if (val) { - *val = comp_temp * 10; - return IIO_VAL_INT; - } - - return 0; + return comp_temp; } -static int bmp280_read_press(struct bmp280_data *data, - int *val, int *val2) +static u32 bmp280_read_press(struct bmp280_data *data) { u32 comp_press; s32 adc_press; int ret; /* Read and compensate temperature so we get a reading of t_fine. */ - ret = bmp280_read_temp(data, NULL, NULL); + ret = bmp280_read_temp(data); if (ret < 0) return ret; @@ -423,20 +412,17 @@ static int bmp280_read_press(struct bmp280_data *data, } comp_press = bmp280_compensate_press(data, adc_press); - *val = comp_press; - *val2 = 256000; - - return IIO_VAL_FRACTIONAL; + return comp_press; } -static int bmp280_read_humid(struct bmp280_data *data, int *val, int *val2) +static u32 bmp280_read_humid(struct bmp280_data *data) { u32 comp_humidity; s32 adc_humidity; int ret; /* Read and compensate temperature so we get a reading of t_fine. */ - ret = bmp280_read_temp(data, NULL, NULL); + ret = bmp280_read_temp(data); if (ret < 0) return ret; @@ -455,9 +441,7 @@ static int bmp280_read_humid(struct bmp280_data *data, int *val, int *val2) } comp_humidity = bmp280_compensate_humidity(data, adc_humidity); - *val = comp_humidity * 1000 / 1024; - - return IIO_VAL_INT; + return comp_humidity; } static int bmp280_read_raw(struct iio_dev *indio_dev, @@ -474,13 +458,27 @@ static int bmp280_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_PROCESSED: switch (chan->type) { case IIO_HUMIDITYRELATIVE: - ret = data->chip_info->read_humid(data, val, val2); + ret = data->chip_info->read_humid(data); + *val = data->chip_info->humid_coeffs[0] * ret; + *val2 = data->chip_info->humid_coeffs[1]; + ret = IIO_VAL_FRACTIONAL; break; case IIO_PRESSURE: - ret = data->chip_info->read_press(data, val, val2); + ret = data->chip_info->read_press(data); + *val = data->chip_info->press_coeffs[0] * ret; + *val2 = data->chip_info->press_coeffs[1]; + ret = IIO_VAL_FRACTIONAL; break; case IIO_TEMP: - ret = data->chip_info->read_temp(data, val, val2); + ret = data->chip_info->read_temp(data); + *val = data->chip_info->temp_coeffs[0] * ret; + *val2 = data->chip_info->temp_coeffs[1]; + + if (!strcmp(indio_dev->name, "bmp580")) + ret = IIO_VAL_FRACTIONAL_LOG2; + else + ret = IIO_VAL_FRACTIONAL; + break; default: ret = -EINVAL; @@ -796,6 +794,8 @@ static int bmp280_chip_config(struct bmp280_data *data) static const int bmp280_oversampling_avail[] = { 1, 2, 4, 8, 16 }; static const u8 bmp280_chip_ids[] = { BMP280_CHIP_ID }; +static const int bmp280_temp_coeffs[] = { 10, 1 }; +static const int bmp280_press_coeffs[] = { 1, 256000 }; const struct bmp280_chip_info bmp280_chip_info = { .id_reg = BMP280_REG_ID, @@ -824,6 +824,9 @@ const struct bmp280_chip_info bmp280_chip_info = { .num_oversampling_press_avail = ARRAY_SIZE(bmp280_oversampling_avail), .oversampling_press_default = BMP280_OSRS_PRESS_16X - 1, + .temp_coeffs = bmp280_temp_coeffs, + .press_coeffs = bmp280_press_coeffs, + .chip_config = bmp280_chip_config, .read_temp = bmp280_read_temp, .read_press = bmp280_read_press, @@ -850,6 +853,7 @@ static int bme280_chip_config(struct bmp280_data *data) } static const u8 bme280_chip_ids[] = { BME280_CHIP_ID }; +static const int bme280_humid_coeffs[] = { 1000, 1024 }; const struct bmp280_chip_info bme280_chip_info = { .id_reg = BMP280_REG_ID, @@ -872,6 +876,10 @@ const struct bmp280_chip_info bme280_chip_info = { .num_oversampling_humid_avail = ARRAY_SIZE(bmp280_oversampling_avail), .oversampling_humid_default = BMP280_OSRS_HUMIDITY_16X - 1, + .temp_coeffs = bmp280_temp_coeffs, + .press_coeffs = bmp280_press_coeffs, + .humid_coeffs = bme280_humid_coeffs, + .chip_config = bme280_chip_config, .read_temp = bmp280_read_temp, .read_press = bmp280_read_press, @@ -997,7 +1005,7 @@ static u32 bmp380_compensate_press(struct bmp280_data *data, u32 adc_press) return comp_press; } -static int bmp380_read_temp(struct bmp280_data *data, int *val, int *val2) +static s32 bmp380_read_temp(struct bmp280_data *data) { s32 comp_temp; u32 adc_temp; @@ -1017,27 +1025,17 @@ static int bmp380_read_temp(struct bmp280_data *data, int *val, int *val2) } comp_temp = bmp380_compensate_temp(data, adc_temp); - /* - * Val might be NULL if we're called by the read_press routine, - * who only cares about the carry over t_fine value. - */ - if (val) { - /* IIO reports temperatures in milli Celsius */ - *val = comp_temp * 10; - return IIO_VAL_INT; - } - - return 0; + return comp_temp; } -static int bmp380_read_press(struct bmp280_data *data, int *val, int *val2) +static u32 bmp380_read_press(struct bmp280_data *data) { - s32 comp_press; - u32 adc_press; + u32 comp_press; + s32 adc_press; int ret; /* Read and compensate for temperature so we get a reading of t_fine */ - ret = bmp380_read_temp(data, NULL, NULL); + ret = bmp380_read_temp(data); if (ret) return ret; @@ -1055,11 +1053,7 @@ static int bmp380_read_press(struct bmp280_data *data, int *val, int *val2) } comp_press = bmp380_compensate_press(data, adc_press); - *val = comp_press; - /* Compensated pressure is in cPa (centipascals) */ - *val2 = 100000; - - return IIO_VAL_FRACTIONAL; + return comp_press; } static int bmp380_read_calib(struct bmp280_data *data) @@ -1227,6 +1221,8 @@ static int bmp380_chip_config(struct bmp280_data *data) static const int bmp380_oversampling_avail[] = { 1, 2, 4, 8, 16, 32 }; static const int bmp380_iir_filter_coeffs_avail[] = { 1, 2, 4, 8, 16, 32, 64, 128}; static const u8 bmp380_chip_ids[] = { BMP380_CHIP_ID, BMP390_CHIP_ID }; +static const int bmp380_temp_coeffs[] = { 10, 1 }; +static const int bmp380_press_coeffs[] = { 1, 100000 }; const struct bmp280_chip_info bmp380_chip_info = { .id_reg = BMP380_REG_ID, @@ -1253,6 +1249,9 @@ const struct bmp280_chip_info bmp380_chip_info = { .num_iir_filter_coeffs_avail = ARRAY_SIZE(bmp380_iir_filter_coeffs_avail), .iir_filter_coeff_default = 2, + .temp_coeffs = bmp380_temp_coeffs, + .press_coeffs = bmp380_press_coeffs, + .chip_config = bmp380_chip_config, .read_temp = bmp380_read_temp, .read_press = bmp380_read_press, @@ -1373,7 +1372,7 @@ static int bmp580_nvm_operation(struct bmp280_data *data, bool is_write) * for what is expected on IIO ABI. */ -static int bmp580_read_temp(struct bmp280_data *data, int *val, int *val2) +static s32 bmp580_read_temp(struct bmp280_data *data) { s32 raw_temp; int ret; @@ -1391,17 +1390,10 @@ static int bmp580_read_temp(struct bmp280_data *data, int *val, int *val2) return -EIO; } - /* - * Temperature is returned in Celsius degrees in fractional - * form down 2^16. We rescale by x1000 to return milli Celsius - * to respect IIO ABI. - */ - *val = raw_temp * 1000; - *val2 = 16; - return IIO_VAL_FRACTIONAL_LOG2; + return raw_temp; } -static int bmp580_read_press(struct bmp280_data *data, int *val, int *val2) +static u32 bmp580_read_press(struct bmp280_data *data) { u32 raw_press; int ret; @@ -1418,13 +1410,8 @@ static int bmp580_read_press(struct bmp280_data *data, int *val, int *val2) dev_err(data->dev, "reading pressure skipped\n"); return -EIO; } - /* - * Pressure is returned in Pascals in fractional form down 2^16. - * We rescale /1000 to convert to kilopascal to respect IIO ABI. - */ - *val = raw_press; - *val2 = 64000; /* 2^6 * 1000 */ - return IIO_VAL_FRACTIONAL; + + return raw_press; } static const int bmp580_odr_table[][2] = { @@ -1729,6 +1716,8 @@ static int bmp580_chip_config(struct bmp280_data *data) static const int bmp580_oversampling_avail[] = { 1, 2, 4, 8, 16, 32, 64, 128 }; static const u8 bmp580_chip_ids[] = { BMP580_CHIP_ID, BMP580_CHIP_ID_ALT }; +static const int bmp580_temp_coeffs[] = { 1000, 16 }; +static const int bmp580_press_coeffs[] = { 1, 64000 }; const struct bmp280_chip_info bmp580_chip_info = { .id_reg = BMP580_REG_CHIP_ID, @@ -1755,6 +1744,9 @@ const struct bmp280_chip_info bmp580_chip_info = { .num_iir_filter_coeffs_avail = ARRAY_SIZE(bmp380_iir_filter_coeffs_avail), .iir_filter_coeff_default = 2, + .temp_coeffs = bmp580_temp_coeffs, + .press_coeffs = bmp580_press_coeffs, + .chip_config = bmp580_chip_config, .read_temp = bmp580_read_temp, .read_press = bmp580_read_press, @@ -1882,7 +1874,7 @@ static s32 bmp180_compensate_temp(struct bmp280_data *data, s32 adc_temp) return (data->t_fine + 8) >> 4; } -static int bmp180_read_temp(struct bmp280_data *data, int *val, int *val2) +static s32 bmp180_read_temp(struct bmp280_data *data) { s32 adc_temp, comp_temp; int ret; @@ -1893,16 +1885,7 @@ static int bmp180_read_temp(struct bmp280_data *data, int *val, int *val2) comp_temp = bmp180_compensate_temp(data, adc_temp); - /* - * val might be NULL if we're called by the read_press routine, - * who only cares about the carry over t_fine value. - */ - if (val) { - *val = comp_temp * 100; - return IIO_VAL_INT; - } - - return 0; + return comp_temp; } static int bmp180_read_adc_press(struct bmp280_data *data, int *val) @@ -1962,15 +1945,14 @@ static u32 bmp180_compensate_press(struct bmp280_data *data, s32 adc_press) return p + ((x1 + x2 + 3791) >> 4); } -static int bmp180_read_press(struct bmp280_data *data, - int *val, int *val2) +static u32 bmp180_read_press(struct bmp280_data *data) { u32 comp_press; s32 adc_press; int ret; /* Read and compensate temperature so we get a reading of t_fine. */ - ret = bmp180_read_temp(data, NULL, NULL); + ret = bmp180_read_temp(data); if (ret) return ret; @@ -1980,10 +1962,7 @@ static int bmp180_read_press(struct bmp280_data *data, comp_press = bmp180_compensate_press(data, adc_press); - *val = comp_press; - *val2 = 1000; - - return IIO_VAL_FRACTIONAL; + return comp_press; } static int bmp180_chip_config(struct bmp280_data *data) @@ -1994,6 +1973,8 @@ static int bmp180_chip_config(struct bmp280_data *data) static const int bmp180_oversampling_temp_avail[] = { 1 }; static const int bmp180_oversampling_press_avail[] = { 1, 2, 4, 8 }; static const u8 bmp180_chip_ids[] = { BMP180_CHIP_ID }; +static const int bmp180_temp_coeffs[] = { 100, 1 }; +static const int bmp180_press_coeffs[] = { 1, 1000 }; const struct bmp280_chip_info bmp180_chip_info = { .id_reg = BMP280_REG_ID, @@ -2014,6 +1995,9 @@ const struct bmp280_chip_info bmp180_chip_info = { ARRAY_SIZE(bmp180_oversampling_press_avail), .oversampling_press_default = BMP180_MEAS_PRESS_8X, + .temp_coeffs = bmp180_temp_coeffs, + .press_coeffs = bmp180_press_coeffs, + .chip_config = bmp180_chip_config, .read_temp = bmp180_read_temp, .read_press = bmp180_read_press, diff --git a/drivers/iio/pressure/bmp280.h b/drivers/iio/pressure/bmp280.h index 4012387d7956..dde55b556ea2 100644 --- a/drivers/iio/pressure/bmp280.h +++ b/drivers/iio/pressure/bmp280.h @@ -448,10 +448,14 @@ struct bmp280_chip_info { int num_sampling_freq_avail; int sampling_freq_default; + const int *temp_coeffs; + const int *press_coeffs; + const int *humid_coeffs; + int (*chip_config)(struct bmp280_data *); - int (*read_temp)(struct bmp280_data *, int *, int *); - int (*read_press)(struct bmp280_data *, int *, int *); - int (*read_humid)(struct bmp280_data *, int *, int *); + s32 (*read_temp)(struct bmp280_data *); + u32 (*read_press)(struct bmp280_data *); + u32 (*read_humid)(struct bmp280_data *); int (*read_calib)(struct bmp280_data *); int (*preinit)(struct bmp280_data *); }; From patchwork Wed Mar 13 17:40:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13591659 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1FF512FF69; Wed, 13 Mar 2024 17:40:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710351623; cv=none; b=iisuRhKoV7BZFHsFyKcBIfSjOekf681ILbqqr2rfDomBwhS8ObKODqvCM58K//fP0h33SZqF2ITOKBNPJR4JgNX4LOvW6Je4DTHoxsUjgbO31gGZbPiPIJI9vwFjS3gBVzQM0rs8rLoO96CrLxQL7qupw+VEfTlqHZl5GH4MO+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710351623; c=relaxed/simple; bh=zN8xCu1gH5zHdheG29PSsKuC/jtm9T0XpojF7b5SZ3g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GTgOrPqBo58vnj0noOGVukHgjwWwfocguyv2uxn0X9PilOjh8Z1MbwyY6XcvgtwKcz2678+B7fhC+X2B2bmERDQsx9QmzOVjV1VTdblYLYoA0S7nZJvvcFPCdEFJ6z31z46XGLlsdKb+YI3/aViHhbLM4CjUTnZrOkOKdHa4GPw= 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=XqtvRuDt; arc=none smtp.client-ip=209.85.208.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XqtvRuDt" Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-56838e00367so136774a12.0; Wed, 13 Mar 2024 10:40:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710351620; x=1710956420; 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=gdi90LxAyqPq+F4TfJtl0rFJuWs6klQUvdsruwMjWcE=; b=XqtvRuDtlrkjQcV6UBEjgtKYVQ5hwEePbNuzNRt6Za9GneqA+ZywPJCkfwPmnbH0Rn MDFL++6ruDdR0i8gc0iPfTAuP7Wivp+aQyjq7teBhptSvyr/dFWoRxWl1FetkswWpAB/ 978FlDoWoG/kWOpvABYSt822vnMW68uX0aM+tQRh1c/dZtxMrmiXDDzn2T5EPzKt7Zv0 Jot1VtcmZvlUi+XyYYSLZssEBphLqXFmM4z79hKZVXciN0zPhUPtamIv4h6mh6Uarn+W 6z5anA8EM78aJq/p4SL2hps3bBWxmahZZue08NRyazFw/1WO4N98cBKPxU1/Rc7/z3V/ zq2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710351620; x=1710956420; 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=gdi90LxAyqPq+F4TfJtl0rFJuWs6klQUvdsruwMjWcE=; b=YLLVwqnJW2Q0z9PZ+CP3sVtQwtOk/P9es79bfDgORW21xxzGh9mU9+q1uV9kBnv9ah FDNKCU+aFuYwxULOkVqe9AJ29EFJeSMsQsTVMJJfWkcPzf8LNIIHiJ8oPh94S9JtTLFO b+HgUetGFrwlo4ewdzN1OqfTPcFN8Vr/HToVqprx30BWkjtDUiuJstFOxbI6+2Ms3qdR r56ob33XceSsbRxDOUDFlTD0ytisLVyoskT4yIRLHkAo9yAvrlzMEtYvyspTRRnu+8gE rR6V4kUMKUudg/QkOeOoR+8ke10WBmlm5UFbab9auph8/WskC81g74HrZKR3wOGiqKUK RqHg== X-Forwarded-Encrypted: i=1; AJvYcCUtEPqOSMXZPGNJAtos7H+5vVNuzk9XjxUsfBnRkibM8HaoP/pw/oBzD3XC0O2r3FSHNw2d2ADxmhOzN1+mZUQPjiS9iCSADiKHQUWB8y8QG9fl1gI5FI1GEDWXzXw2DE6rHh2PqMKL X-Gm-Message-State: AOJu0YyamvN+3mRZzfTBX1KocfzLd2lzAcTUrSbQQchweoLqUwc3E71j /KwroxS1d+Ga4nxqHbXtrmBWksZ7b9wqb7FVaaIzOB/btPycOLqC X-Google-Smtp-Source: AGHT+IEX3CdOr5y/3yGr0P7V8smY4MN88DXQT+HrFDPy7YX/asuOzflumw2wS7VnWCyGByiL9F6aFw== X-Received: by 2002:a17:907:d50c:b0:a46:3ce4:5aef with SMTP id wb12-20020a170907d50c00b00a463ce45aefmr5219842ejc.57.1710351619935; Wed, 13 Mar 2024 10:40:19 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:fa35:157e:1a40:3463]) by smtp.gmail.com with ESMTPSA id m17-20020a1709061ed100b00a449076d0dbsm5028215ejj.53.2024.03.13.10.40.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:40:19 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org Cc: lars@metafoo.de, andriy.shevchenko@linux.intel.com, ang.iglesiasg@gmail.com, mazziesaccount@gmail.com, ak@it-klinger.de, petre.rodan@subdimension.ro, linus.walleij@linaro.org, phil@raspberrypi.com, 579lpy@gmail.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Vasileios Amoiridis Subject: [PATCH v3 3/6] iio: pressure: add SCALE and RAW values for channels Date: Wed, 13 Mar 2024 18:40:04 +0100 Message-Id: <20240313174007.1934983-4-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240313174007.1934983-1-vassilisamir@gmail.com> References: <20240313174007.1934983-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 extra IIO_CHAN_INFO_SCALE and IIO_CHAN_INFO_RAW in order to be able to calculate the processed value with standard userspace IIO tools. Can be used for triggered buffers as well. Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-core.c | 58 ++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index dfd845acfa22..6d7734f867bc 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -138,16 +138,22 @@ static const struct iio_chan_spec bmp280_channels[] = { { .type = IIO_PRESSURE, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), }, { .type = IIO_TEMP, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), }, { .type = IIO_HUMIDITYRELATIVE, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), }, }; @@ -156,6 +162,8 @@ static const struct iio_chan_spec bmp380_channels[] = { { .type = IIO_PRESSURE, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), @@ -163,6 +171,8 @@ static const struct iio_chan_spec bmp380_channels[] = { { .type = IIO_TEMP, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), @@ -170,6 +180,8 @@ static const struct iio_chan_spec bmp380_channels[] = { { .type = IIO_HUMIDITYRELATIVE, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), @@ -485,6 +497,52 @@ static int bmp280_read_raw(struct iio_dev *indio_dev, break; } break; + case IIO_CHAN_INFO_RAW: + switch (chan->type) { + case IIO_HUMIDITYRELATIVE: + *val = data->chip_info->read_humid(data); + ret = IIO_VAL_INT; + break; + case IIO_PRESSURE: + *val = data->chip_info->read_press(data); + ret = IIO_VAL_INT; + break; + case IIO_TEMP: + *val = data->chip_info->read_temp(data); + ret = IIO_VAL_INT; + break; + default: + ret = -EINVAL; + break; + } + break; + case IIO_CHAN_INFO_SCALE: + switch (chan->type) { + case IIO_HUMIDITYRELATIVE: + *val = data->chip_info->humid_coeffs[0]; + *val2 = data->chip_info->humid_coeffs[1]; + ret = IIO_VAL_FRACTIONAL; + break; + case IIO_PRESSURE: + *val = data->chip_info->press_coeffs[0]; + *val2 = data->chip_info->press_coeffs[1]; + ret = IIO_VAL_FRACTIONAL; + break; + case IIO_TEMP: + *val = data->chip_info->temp_coeffs[0]; + *val2 = data->chip_info->temp_coeffs[1]; + + if (!strcmp(indio_dev->name, "bmp580")) + ret = IIO_VAL_FRACTIONAL_LOG2; + else + ret = IIO_VAL_FRACTIONAL; + + break; + default: + ret = -EINVAL; + break; + } + break; case IIO_CHAN_INFO_OVERSAMPLING_RATIO: switch (chan->type) { case IIO_HUMIDITYRELATIVE: From patchwork Wed Mar 13 17:40:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13591660 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B06012FF9D; Wed, 13 Mar 2024 17:40:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710351625; cv=none; b=tXqSw+GaDGkopPE8auhdETyujp1VnpwzUMFJ4Zkg37rCDDaQDCZenpBU5glaGPSs6e5MbuFJ4ZkeFALy/4CwL1OGUng+hlh5vP7l+W+9zmrthtuyoMVVVzmGukCwNAKFAan6RRGudf43NYsuqish9DEOip5n3hTs8PlqbeZW25g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710351625; c=relaxed/simple; bh=S9zF1Lvby+c7nTni5s4hL/8l9Ch+C18fqZYolOwShGk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rTC6/ODZ5Ms3t2a5p9w/6EIf9JgszHDSDn40lkFl36d280I846kFy0mMc/Ga7G0tgWDtn9/huS3S30hHcdwcxuPpecD+dpIwanvwn3xNkAhNA03h67GiQn8sKaIQaTxb0Z9SLwMGV/TS2KqFlQIPSdZtNfk5hmOtJVOWVo9R7/s= 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=avYasxa4; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="avYasxa4" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a446b5a08f0so25025366b.1; Wed, 13 Mar 2024 10:40:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710351621; x=1710956421; 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=myKz1FVxkkY2My67LEfKvneqOReMkZwpEuPPL7ER9GA=; b=avYasxa4L4gFpsLxajxqWhM+GrtpoA72+qmArUpdjEHsbXifU3qvLlYo1TS0Gkg7Fz JuxWzwoFligD1aWt6bE6qo8fgQyLC9yUOdgO+7MoyQePvw8aQl7BJr1SHc5Z0jQ3Vo3a DT/oT8rkbcFcQIHzlkSqO+X54xTBVpRZEvFsZK1OTCE6UmNx3Ty6UDoCAlUJzeLcKgZf 15eI+e2+zt1nkifgAsw7txU7KpVyy0T8C3L49KfQIx1Nrx5n+yL6wpVkpWZuFL0BtsQY hbkm3HxVdGxtyHMQja2ojdD0d0NxzBLdxd/Ae+gYEbe/gUqjyuTeX8wkFMwJ9rs0h3df Pr/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710351621; x=1710956421; 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=myKz1FVxkkY2My67LEfKvneqOReMkZwpEuPPL7ER9GA=; b=wsZ7mX+Ll2jJQqKUy+ybiEnGl9FkfPng3tj/FugNPKsvTP6jyS2WEnb0TNdM7ZMTfw NfOpz0OR7YA+6Mp2INjgbewmALaA+OqjonVYVe5WnsT7rzRsnpQou/RLz4rHRjn4kLMV L0DDUS+gijLNSjS2cYisqBWIqZ5tklaw/bl8toStiLvdNBVjzAQp04hqW4w1jFqYN1qt ir5h0yLN/JMZQ02DLyLEvvmglZFMFcKgGAUCp1jEfmGbfD5K6qoBWrBVsjWCWv9pXcdZ x8XXprFR/V+7qOCdTKsRYgG9Lvt0LSKrOyNVs3Jlv1NitQCB0nX7+TaF65iknzmEKBN2 Y3FA== X-Forwarded-Encrypted: i=1; AJvYcCUy9UA33MRobzhP7x5jd1uP75B5AhM5PODvQy/aKeHNNI+buraY23Pa7gXJVsiuTTdtVKOw0WEU8aAPkzotx07phwhwq0C3Esf7MT+ou/gAre2pRjSBzYJTUpjc2098R85B/YvcTMS1 X-Gm-Message-State: AOJu0YzKbxlhov17ShyPdAmleTqocxrlwcYK/OZUhSN5aT5lPtizttnt YnOw3z+Vw1Qu60RQ7S0u2bLoMpMm8SCulp3iVpDG0Z3BrAlYwLGP X-Google-Smtp-Source: AGHT+IHR555BbTASeXdN+ypMqGbZN430GdtQ3U+LRAa2fZGP1GVOOw0Pyy/X6aHBgkwGoPkpt1m1vg== X-Received: by 2002:a17:906:4f01:b0:a46:605d:697c with SMTP id t1-20020a1709064f0100b00a46605d697cmr1546466eju.4.1710351621511; Wed, 13 Mar 2024 10:40:21 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:fa35:157e:1a40:3463]) by smtp.gmail.com with ESMTPSA id m17-20020a1709061ed100b00a449076d0dbsm5028215ejj.53.2024.03.13.10.40.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:40:21 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org Cc: lars@metafoo.de, andriy.shevchenko@linux.intel.com, ang.iglesiasg@gmail.com, mazziesaccount@gmail.com, ak@it-klinger.de, petre.rodan@subdimension.ro, linus.walleij@linaro.org, phil@raspberrypi.com, 579lpy@gmail.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Vasileios Amoiridis Subject: [PATCH v2 4/6] iio: pressure: Simplify and make more clear temperature readings Date: Wed, 13 Mar 2024 18:40:05 +0100 Message-Id: <20240313174007.1934983-5-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240313174007.1934983-1-vassilisamir@gmail.com> References: <20240313174007.1934983-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 read_press/read_humid functions need the updated t_fine value in order to calculate the current pressure/humidity. Temperature reads should be removed from the read_press/read_humid functions and should be placed in the oneshot captures before the pressure and humidity reads. This makes the code more intuitive. Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-core.c | 38 ++++++++++++++---------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 6d7734f867bc..377e90d9e5a2 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -404,11 +404,6 @@ static u32 bmp280_read_press(struct bmp280_data *data) s32 adc_press; int ret; - /* Read and compensate temperature so we get a reading of t_fine. */ - ret = bmp280_read_temp(data); - if (ret < 0) - return ret; - ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB, data->buf, sizeof(data->buf)); if (ret < 0) { @@ -433,11 +428,6 @@ static u32 bmp280_read_humid(struct bmp280_data *data) s32 adc_humidity; int ret; - /* Read and compensate temperature so we get a reading of t_fine. */ - ret = bmp280_read_temp(data); - if (ret < 0) - return ret; - ret = regmap_bulk_read(data->regmap, BMP280_REG_HUMIDITY_MSB, &data->be16, sizeof(data->be16)); if (ret < 0) { @@ -470,12 +460,21 @@ static int bmp280_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_PROCESSED: switch (chan->type) { case IIO_HUMIDITYRELATIVE: + /* Read temperature to update the t_fine value */ + data->chip_info->read_temp(data); ret = data->chip_info->read_humid(data); *val = data->chip_info->humid_coeffs[0] * ret; *val2 = data->chip_info->humid_coeffs[1]; ret = IIO_VAL_FRACTIONAL; break; case IIO_PRESSURE: + /* + * Read temperature to update the t_fine value. + * BMP5xx devices do this in hardware, so skip it. + */ + if (strcmp(indio_dev->name, "bmp580")) + data->chip_info->read_temp(data); + ret = data->chip_info->read_press(data); *val = data->chip_info->press_coeffs[0] * ret; *val2 = data->chip_info->press_coeffs[1]; @@ -500,10 +499,19 @@ static int bmp280_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_RAW: switch (chan->type) { case IIO_HUMIDITYRELATIVE: + /* Read temperature to update the t_fine value */ + data->chip_info->read_temp(data); *val = data->chip_info->read_humid(data); ret = IIO_VAL_INT; break; case IIO_PRESSURE: + /* + * Read temperature to update the t_fine value. + * BMP5xx devices do this in hardware, so skip it. + */ + if (strcmp(indio_dev->name, "bmp580")) + data->chip_info->read_temp(data); + *val = data->chip_info->read_press(data); ret = IIO_VAL_INT; break; @@ -1092,11 +1100,6 @@ static u32 bmp380_read_press(struct bmp280_data *data) s32 adc_press; int ret; - /* Read and compensate for temperature so we get a reading of t_fine */ - ret = bmp380_read_temp(data); - if (ret) - return ret; - ret = regmap_bulk_read(data->regmap, BMP380_REG_PRESS_XLSB, data->buf, sizeof(data->buf)); if (ret) { @@ -2009,11 +2012,6 @@ static u32 bmp180_read_press(struct bmp280_data *data) s32 adc_press; int ret; - /* Read and compensate temperature so we get a reading of t_fine. */ - ret = bmp180_read_temp(data); - if (ret) - return ret; - ret = bmp180_read_adc_press(data, &adc_press); if (ret) return ret; From patchwork Wed Mar 13 17:40:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13591661 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.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 C5600130AE5; Wed, 13 Mar 2024 17:40:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710351626; cv=none; b=nWT6k2koL2Ovx4e698Hd1AODYO6mX43wM3Tj3hIyoovnzrBDhNspbF2r0C3VIzG6pRVRcfNA09Hiq4TalUZS4W0IeOD6NEIEfrumMucIi73djS3CCTEYbRVK/3jsPBDxjg9puzfCsgn8Zss9a9mZmdijBJdLAfcUjFlz7JNzAH4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710351626; c=relaxed/simple; bh=TA1y5b636zP09b5cRSGNjocDkGQZA6dZ+p28CQdY4aY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=q+boZ5vn8VFg4uvSNkqqf6Mp83udc4R3GcAu9D6J6YYGChw15aHfuBh/18Ts0+E0KSBc3+KtBGWkil9wF4jKof0UEJ+/bQCkFdj/c2sNkHom1jtC4aLzaV3AnDFSnE4X7SqCpsn4xZl07bhpHFkETmZS72zNbkA6OEtsgFVExUo= 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=JMPaMNwf; arc=none smtp.client-ip=209.85.218.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="JMPaMNwf" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a466381b411so12879866b.2; Wed, 13 Mar 2024 10:40:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710351623; x=1710956423; 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=ORPW/2ZdzZ09PyYXpFYFfEaDEBdWrfCLAH5sJrFRgL4=; b=JMPaMNwfck/d9hN2QBDouv/ZS3FwzdONuL4CHEYnvlcr/plTCNrbk67a6xvblXsSN9 NGwpNPKiqcpUH7AKOJi9cXd+NCcBAcExlYchNItCMayz1WELGnnkaoSTvVwiZpH3z9yw 1GTKi67IgDjPHBua8j7YEgYlP9t5379Sr4XfbTCpap7ZQRTHQwhQAna1z1W0+qRzw3t2 T61BmHTdfMqW6UgkQt4kTAVkC7kCkHyJVGkk+uxKRqp2cKpjVwAWwbxGZpoCcfGsx89/ AWq6aZMkTA+liF/OqOf0UBHTL9PIL6ywFKXeRycejwA48FULHy2PbBkg0QXeWbH+enoC TUGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710351623; x=1710956423; 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=ORPW/2ZdzZ09PyYXpFYFfEaDEBdWrfCLAH5sJrFRgL4=; b=mC7561kfAmVsGTTcYD2HsRkOwo5HaJxG8cJhxK/jc6Tn1wo0+x4SH2TUIMkcxIUODW oHFG9cYAvpiAeaIp8ZUyUacMbD7Xle3lhgleg4MKkN5n0C2N0byPxSoTIpxEjKV1uT1d HCrUgkYrLpxzQtl6aZ2poEGGvvj/okPADPvjH2zzT/GJ4Vwiru5CDm8cVE0Sua3swV35 /YW6rHTmtOhHuWLVXTG4UUGB5gRXj96KaRKXhDi1lqNynvjFY88w4HfetMzPucXGgt5r qtWOFQrAJrgLpybV/2/KquN4MVZZuTOu0IMolvc5BMNdPWFIuOUB4vlYCvBvN/EnXXnJ 4zxA== X-Forwarded-Encrypted: i=1; AJvYcCWLLnHpE0jKlWOKC5MI5vyQp7nAa15sIPbA0/RrxYXAlN/sRkPbRpTVTcXBYFtrnp7TgYoZneluo9ntxeAogwUlTBKlWYV4XD2lxVZ4KJaoLkDj3JzFdWQBm1koBLb4ReYjhYN4ggkR X-Gm-Message-State: AOJu0Yx+6FfbGZsxXcNYHGVfnOv8eNMHWmxNPu94eKAxBwTlfD/uQWZ9 1K0QOEAs1aPsEoJXSiiN0ugItXZUOOdiSqa9DXD1tvK+zoZ02qzL X-Google-Smtp-Source: AGHT+IFWl2+PSZlnEjBjFEKLfk48VCPTdUb486waFs89vkIiUVnQrE3LLmxSKPzOz9DFeW2A1ENZ4w== X-Received: by 2002:a17:906:eece:b0:a45:511:1533 with SMTP id wu14-20020a170906eece00b00a4505111533mr10619941ejb.75.1710351623116; Wed, 13 Mar 2024 10:40:23 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:fa35:157e:1a40:3463]) by smtp.gmail.com with ESMTPSA id m17-20020a1709061ed100b00a449076d0dbsm5028215ejj.53.2024.03.13.10.40.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:40:22 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org Cc: lars@metafoo.de, andriy.shevchenko@linux.intel.com, ang.iglesiasg@gmail.com, mazziesaccount@gmail.com, ak@it-klinger.de, petre.rodan@subdimension.ro, linus.walleij@linaro.org, phil@raspberrypi.com, 579lpy@gmail.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Vasileios Amoiridis Subject: [PATCH v2 5/6] iio: pressure: Add timestamp and scan_masks for BMP280 driver Date: Wed, 13 Mar 2024 18:40:06 +0100 Message-Id: <20240313174007.1934983-6-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240313174007.1934983-1-vassilisamir@gmail.com> References: <20240313174007.1934983-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 scan mask for the BME280 supports humidity measurement needs to be distinguished from the rest in order for the timestamp to be able to work. Scan masks are added for different combinations of measurements. The temperature measurement is always needed for pressure and humidity measurements. Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-core.c | 116 +++++++++++++++++++++++++---- drivers/iio/pressure/bmp280.h | 1 + 2 files changed, 102 insertions(+), 15 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 377e90d9e5a2..f2cf9bef522c 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -134,40 +134,91 @@ enum { BMP380_P11 = 20, }; +enum bmp280_scan { + BMP280_TEMP, + BMP280_PRESS, + BME280_HUMID, +}; + static const struct iio_chan_spec bmp280_channels[] = { + { + .type = IIO_TEMP, + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .scan_index = 0, + .scan_type = { + .sign = 's', + .realbits = 32, + .storagebits = 32, + .endianness = IIO_CPU, + }, + }, { .type = IIO_PRESSURE, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .scan_index = 1, + .scan_type = { + .sign = 's', + .realbits = 32, + .storagebits = 32, + .endianness = IIO_CPU, + }, }, + IIO_CHAN_SOFT_TIMESTAMP(2), +}; + +static const struct iio_chan_spec bme280_channels[] = { { .type = IIO_TEMP, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .scan_index = 0, + .scan_type = { + .sign = 's', + .realbits = 32, + .storagebits = 32, + .endianness = IIO_CPU, + }, }, { - .type = IIO_HUMIDITYRELATIVE, + .type = IIO_PRESSURE, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .scan_index = 1, + .scan_type = { + .sign = 'u', + .realbits = 32, + .storagebits = 32, + .endianness = IIO_CPU, + }, }, -}; - -static const struct iio_chan_spec bmp380_channels[] = { { - .type = IIO_PRESSURE, + .type = IIO_HUMIDITYRELATIVE, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), - .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | - BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), + .scan_index = 2, + .scan_type = { + .sign = 'u', + .realbits = 32, + .storagebits = 32, + .endianness = IIO_CPU, + }, }, + IIO_CHAN_SOFT_TIMESTAMP(3), +}; + +static const struct iio_chan_spec bmp380_channels[] = { { .type = IIO_TEMP, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | @@ -176,16 +227,31 @@ static const struct iio_chan_spec bmp380_channels[] = { BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), + .scan_index = 0, + .scan_type = { + .sign = 's', + .realbits = 32, + .storagebits = 32, + .endianness = IIO_CPU, + }, }, { - .type = IIO_HUMIDITYRELATIVE, + .type = IIO_PRESSURE, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), - .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), + .scan_index = 1, + .scan_type = { + .sign = 'u', + .realbits = 32, + .storagebits = 32, + .endianness = IIO_CPU, + }, }, + IIO_CHAN_SOFT_TIMESTAMP(2), }; static int bmp280_read_calib(struct bmp280_data *data) @@ -829,6 +895,20 @@ static const struct iio_info bmp280_info = { .write_raw = &bmp280_write_raw, }; +static const unsigned long bmp280_avail_scan_masks[] = { + BIT(BMP280_TEMP), + BIT(BMP280_PRESS) | BIT(BMP280_TEMP), + 0 +}; + +static const unsigned long bme280_avail_scan_masks[] = { + BIT(BMP280_TEMP), + BIT(BMP280_PRESS) | BIT(BMP280_TEMP), + BIT(BME280_HUMID) | BIT(BMP280_TEMP), + BIT(BME280_HUMID) | BIT(BMP280_PRESS) | BIT(BMP280_TEMP), + 0 +}; + static int bmp280_chip_config(struct bmp280_data *data) { u8 osrs = FIELD_PREP(BMP280_OSRS_TEMP_MASK, data->oversampling_temp + 1) | @@ -870,7 +950,8 @@ const struct bmp280_chip_info bmp280_chip_info = { .regmap_config = &bmp280_regmap_config, .start_up_time = 2000, .channels = bmp280_channels, - .num_channels = 2, + .num_channels = 3, + .avail_scan_masks = bmp280_avail_scan_masks, .oversampling_temp_avail = bmp280_oversampling_avail, .num_oversampling_temp_avail = ARRAY_SIZE(bmp280_oversampling_avail), @@ -927,8 +1008,9 @@ const struct bmp280_chip_info bme280_chip_info = { .num_chip_id = ARRAY_SIZE(bme280_chip_ids), .regmap_config = &bmp280_regmap_config, .start_up_time = 2000, - .channels = bmp280_channels, - .num_channels = 3, + .channels = bme280_channels, + .num_channels = 4, + .avail_scan_masks = bme280_avail_scan_masks, .oversampling_temp_avail = bmp280_oversampling_avail, .num_oversampling_temp_avail = ARRAY_SIZE(bmp280_oversampling_avail), @@ -1292,7 +1374,8 @@ const struct bmp280_chip_info bmp380_chip_info = { .regmap_config = &bmp380_regmap_config, .start_up_time = 2000, .channels = bmp380_channels, - .num_channels = 2, + .num_channels = 3, + .avail_scan_masks = bmp280_avail_scan_masks, .oversampling_temp_avail = bmp380_oversampling_avail, .num_oversampling_temp_avail = ARRAY_SIZE(bmp380_oversampling_avail), @@ -1787,7 +1870,8 @@ const struct bmp280_chip_info bmp580_chip_info = { .regmap_config = &bmp580_regmap_config, .start_up_time = 2000, .channels = bmp380_channels, - .num_channels = 2, + .num_channels = 3, + .avail_scan_masks = bmp280_avail_scan_masks, .oversampling_temp_avail = bmp580_oversampling_avail, .num_oversampling_temp_avail = ARRAY_SIZE(bmp580_oversampling_avail), @@ -2039,7 +2123,8 @@ const struct bmp280_chip_info bmp180_chip_info = { .regmap_config = &bmp180_regmap_config, .start_up_time = 2000, .channels = bmp280_channels, - .num_channels = 2, + .num_channels = 3, + .avail_scan_masks = bmp280_avail_scan_masks, .oversampling_temp_avail = bmp180_oversampling_temp_avail, .num_oversampling_temp_avail = @@ -2149,6 +2234,7 @@ int bmp280_common_probe(struct device *dev, /* Apply initial values from chip info structure */ indio_dev->channels = chip_info->channels; indio_dev->num_channels = chip_info->num_channels; + indio_dev->available_scan_masks = chip_info->avail_scan_masks; data->oversampling_press = chip_info->oversampling_press_default; data->oversampling_humid = chip_info->oversampling_humid_default; data->oversampling_temp = chip_info->oversampling_temp_default; diff --git a/drivers/iio/pressure/bmp280.h b/drivers/iio/pressure/bmp280.h index dde55b556ea2..c8cb7c417dab 100644 --- a/drivers/iio/pressure/bmp280.h +++ b/drivers/iio/pressure/bmp280.h @@ -427,6 +427,7 @@ struct bmp280_chip_info { const struct iio_chan_spec *channels; int num_channels; unsigned int start_up_time; + const unsigned long *avail_scan_masks; const int *oversampling_temp_avail; int num_oversampling_temp_avail; From patchwork Wed Mar 13 17:40:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13591662 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B1A8132C15; Wed, 13 Mar 2024 17:40:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710351628; cv=none; b=FYFBBb0l2dVpF2RJO7sO3GVbXJ9bAEjrJAeY8NB2mYNJZTKBEsYEi91gyZmMk7NdY/m4Ozalbdyt3dWabiBZbBAStLhj2SR2UhLxXJFF1xLFRprd4bwV/EwnaGnkUV5+O9jleCKF8m72NU8m+9e9Hdqz4LuKrp9i/DOM7y5svGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710351628; c=relaxed/simple; bh=tc9DKMBR8KwBT2icGVg5+ZgjQyRhDAM94iKrIGcjx/s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rY7luiytaiM2xFjvdvJLr74dfQFeDhNNOkHVCkRydalDvQXQobyJQZ+9izS+NoqocxNjNT6zZK6D8DXNsiZr4rkyMXJjQAuSMdDI7zc0KTaHCuiuxAGOlvx3iuD5a9xSmnRUVtzkzmDoCLX70EB1ypP/yBJfHDHEwn7SQVHY52k= 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=d3fMC6X7; arc=none smtp.client-ip=209.85.208.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="d3fMC6X7" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-56845954fffso87620a12.3; Wed, 13 Mar 2024 10:40:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710351625; x=1710956425; 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=pDUkRWMU6Em/8H0zDUO+LaCCaghhRbcYZfIR5KeSXa8=; b=d3fMC6X7XPrf3kV+3bWnuVFzDz7bYwRKX25gSkUsTipzxzkogKEPRC+zyogmGq0VNb o51Q61PeNNG1a6z4CZKIQILH+9q9dSURjTqL8rlkwI5/A2gWD5cP5NTexznq0GPx5n31 CIRiRUBUsPPYJAP79gF8Qqw6oAGqZbLpff5zSU9c+/ffLB8K+eKZ7rCeqfBUx+AgfSGI 3rtw/jXRoxcQICv6UyGVxc4rai2tv5JVn33xiNtHUxhR+apmy8PS7UH+3cLTv4lEBxPe WkyYR7WWeqVyjE4fLmOS05IZo3EvoYNwyyz18raq+RAioBedn2CPenL7K92Re5fnjmI9 0qGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710351625; x=1710956425; 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=pDUkRWMU6Em/8H0zDUO+LaCCaghhRbcYZfIR5KeSXa8=; b=FZLQbUYiu9bs7lofLf79kgMf2qJPspmoF0hKH8dN4KgAkSlHprnkKRZTzyApNWq+Xs W2g0dRAxfOBfiTjS/515EUj/DAc0rn4XRfd5BHj3J9SDGSCNiDodxd28jIy4M/MkmUGB UJHLrHXuzSJaIdJ2glj6FTB1Sox//rxcP2YKQ8nURjd6sZ+ANaovK52PautIf+P0EWY3 wh82ecWHn9OdBA6A6U+G3nxEVMlvMjFvHhxacmkl7ysBoRQGR5SN5sKVhpSzZfqwJK5w yeL53KeIBbU3+gIRhjVKdYQUADJjNrv6g0cZVApyT9QK7YtxnCPyt5Rk2jq/u2q2HqeJ WxUA== X-Forwarded-Encrypted: i=1; AJvYcCW7J14xEeQXfucS6TSuUCDBhVBJ94wdciBbFHa0x86XZs6677KtP/DAW9a3CF7SVL+4bZLvkA4CQEDCUmT9O8Xf6yduaXnAzSvSz6mKErqbfKhK4BXWFgh3br3Z3d/EIIprc911sMjV X-Gm-Message-State: AOJu0Yw5PGyr99k8dgMSQV1NDUj7apJ4KHiHR+KJLwpwRX71WzoOEKGo dDqeUweUzxN5lRgm7cf75qpBcJm5q5FsJ9IFZAoaFj9OhYGygveDv27ubJQ44dmFLYKg X-Google-Smtp-Source: AGHT+IFnomHxxYnPOy5YMpL0B+A3GiwKNdZ/A9KAwzNIJEuZEqLNCTOE0dLpx9FOf/kA0WSh938wIQ== X-Received: by 2002:a17:907:d389:b0:a45:92c4:7892 with SMTP id vh9-20020a170907d38900b00a4592c47892mr10865628ejc.56.1710351624808; Wed, 13 Mar 2024 10:40:24 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:fa35:157e:1a40:3463]) by smtp.gmail.com with ESMTPSA id m17-20020a1709061ed100b00a449076d0dbsm5028215ejj.53.2024.03.13.10.40.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:40:24 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org Cc: lars@metafoo.de, andriy.shevchenko@linux.intel.com, ang.iglesiasg@gmail.com, mazziesaccount@gmail.com, ak@it-klinger.de, petre.rodan@subdimension.ro, linus.walleij@linaro.org, phil@raspberrypi.com, 579lpy@gmail.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Vasileios Amoiridis Subject: [PATCH v2 6/6] iio: pressure: Add triggered buffer support for BMP280 driver Date: Wed, 13 Mar 2024 18:40:07 +0100 Message-Id: <20240313174007.1934983-7-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240313174007.1934983-1-vassilisamir@gmail.com> References: <20240313174007.1934983-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 a buffer struct that will hold the values of the measurements and will be pushed to userspace and a buffer_handler function to read the data and push them. Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/Kconfig | 2 + drivers/iio/pressure/bmp280-core.c | 61 ++++++++++++++++++++++++++++++ drivers/iio/pressure/bmp280.h | 7 ++++ 3 files changed, 70 insertions(+) diff --git a/drivers/iio/pressure/Kconfig b/drivers/iio/pressure/Kconfig index 79adfd059c3a..5145b94b4679 100644 --- a/drivers/iio/pressure/Kconfig +++ b/drivers/iio/pressure/Kconfig @@ -31,6 +31,8 @@ config BMP280 select REGMAP select BMP280_I2C if (I2C) select BMP280_SPI if (SPI_MASTER) + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER help Say yes here to build support for Bosch Sensortec BMP180, BMP280, BMP380 and BMP580 pressure and temperature sensors. Also supports the BME280 with diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index f2cf9bef522c..7c889cda396a 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -40,7 +40,10 @@ #include #include +#include #include +#include +#include #include @@ -2188,6 +2191,57 @@ static int bmp085_fetch_eoc_irq(struct device *dev, return 0; } +static irqreturn_t bmp280_buffer_handler(int irq, void *p) +{ + struct iio_poll_func *pf = p; + struct iio_dev *indio_dev = pf->indio_dev; + struct bmp280_data *data = iio_priv(indio_dev); + int ret, temp; + + /* + * data->buf[3] is used to transfer data from the device. Whenever a + * pressure or a humidity reading takes place, the data written in the + * data->buf[3] overwrites the iio_buf.temperature value. Keep the + * temperature value and apply it after the readings. + */ + mutex_lock(&data->lock); + + if (test_bit(BMP280_TEMP, indio_dev->active_scan_mask)) { + ret = data->chip_info->read_temp(data); + if (ret < 0) + goto done; + + temp = ret; + } + + if (test_bit(BMP280_PRESS, indio_dev->active_scan_mask)) { + ret = data->chip_info->read_press(data); + if (ret < 0) + goto done; + + data->iio_buf.pressure = ret; + data->iio_buf.temperature = temp; + } + + if (test_bit(BME280_HUMID, indio_dev->active_scan_mask)) { + ret = data->chip_info->read_humid(data); + if (ret < 0) + goto done; + + data->iio_buf.humidity = ret; + data->iio_buf.temperature = temp; + } + + iio_push_to_buffers_with_timestamp(indio_dev, &data->iio_buf, + iio_get_time_ns(indio_dev)); + +done: + mutex_unlock(&data->lock); + iio_trigger_notify_done(indio_dev->trig); + + return IRQ_HANDLED; +} + static void bmp280_pm_disable(void *data) { struct device *dev = data; @@ -2329,6 +2383,13 @@ int bmp280_common_probe(struct device *dev, return ret; } + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, + iio_pollfunc_store_time, + &bmp280_buffer_handler, NULL); + if (ret) + return dev_err_probe(data->dev, ret, + "iio triggered buffer setup failed\n"); + /* Enable runtime PM */ pm_runtime_get_noresume(dev); pm_runtime_set_active(dev); diff --git a/drivers/iio/pressure/bmp280.h b/drivers/iio/pressure/bmp280.h index c8cb7c417dab..b5369dd496ba 100644 --- a/drivers/iio/pressure/bmp280.h +++ b/drivers/iio/pressure/bmp280.h @@ -407,6 +407,13 @@ struct bmp280_data { union { /* Sensor data buffer */ u8 buf[3]; + /* Data buffer to push to userspace */ + struct { + s32 temperature; + u32 pressure; + u32 humidity; + s64 timestamp __aligned(8); + } iio_buf; /* Calibration data buffers */ __le16 bmp280_cal_buf[BMP280_CONTIGUOUS_CALIB_REGS / 2]; __be16 bmp180_cal_buf[BMP180_REG_CALIB_COUNT / 2];