From patchwork Mon Apr 29 19:00:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13647520 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4356313AA35; Mon, 29 Apr 2024 19:00:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714417261; cv=none; b=B/FMREYJdwFTRG0EnJVFaP2WPxK/YPp8vhhP4IlZr5CS7lQADtU/FF35sOYbZVoztqjVhMP94+L9X6LfHOPoBB4b45vr217Zl+1bSz7BcMRRHaHjkrRnNG27jl1qUDy51aeFZGLh44RgqFD8ZZdQjKdn26PpMm0dcqeiSZKO9KY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714417261; c=relaxed/simple; bh=ZRc3CH7rOFH16V1i5NHEc8iWUm6PlLJs3iCipBdb+sI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=GNN58IRAH8KdBiCIPu6kHw0neikFz/XqcsEfuUusQmWb84KCw5Aa1q/VGYSgZcLUcbeFb70p0pNGiT+6OpteG7G5k/EqGT8sPCwfbw7Qc28E1aQmFWm/4B40JoJqj+vQ8xdRvXPzHJI7fLyxqfXceg+hUp3bUjyXTzaV1xZAZvU= 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=DqVQbliC; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DqVQbliC" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-34ce52fb920so1520737f8f.3; Mon, 29 Apr 2024 12:00:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714417257; x=1715022057; 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=ysmCyCaN1vxE0Pt4X0+VDhhAy5VjpXDYfLOFJxIiE2c=; b=DqVQbliCK0Tue36+JoNNn+2V4ZLu4ZC+l7oAUrHkioKWzeZ/iCMoWd3MJKux2jDTDA Xst9Okypfhk1CMV5MFTnODnX+n4pPvZ2UbKctb0/z7rD7X3lHdbUkwVN42ZJasjJWq0W sBD1y1VZSllJkgICYEUvNfourfwS2G6RWhWsk7NF0gv4GTjLa5HgLBCuc5in41+aJm36 rmdsdXbH8Vg7f98k/d2Ybe6E0f3uOkOia84XmC/1byBPKgMqgPTLs75sm73mJwogDPcA mQWXZlc1pJrCF2jAezeCzNr2LFyhxf00Wwsdh2e4hti+CkxTQBBkfL4cJSf9DHs6FAw3 fDaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714417257; x=1715022057; 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=ysmCyCaN1vxE0Pt4X0+VDhhAy5VjpXDYfLOFJxIiE2c=; b=RDCCZJbihU+Fp5ESXLnrE9rO7t7DR+PRoRvYl24//sO+OekfcrSJfLBf2c8T2H/pd7 vjnv7CdOs+RgxLoxEstTVmW+30N/BOEp1YIEkFqFC2tCJg5RgLCY0NEmq3G8TXYtHSqC jqHcH6DyvHhq5kP0Fwe5WRt11TBudw+0KN1j79C+vMffUatROlItMDudrAx2FRBndnBL rntnLiWokIalKIJthl8l2lg9EfNc2EVL8zzI9lhqyljF1jH4KNnFb8uWbBQ6oTWAGR5M NNpU66Z1tSjIDII9znDT6zeXDbx3jf/LFbvLJWt9i5F1xkU+MZZ3ppPCTBYYE2PtpxcC bE3g== X-Forwarded-Encrypted: i=1; AJvYcCW/kVByNS05Gj80LekWRmHNZ1VqPuN+G/ceZNfMb+UFlOEEN1NbMjg4kBsnczSGUKWyVbVG0kv/AZAGdlQ42xommPPvv/NieoZL3FLwXoRh94veXQpTyREDIREDsXYOgxNwijQD7jKh X-Gm-Message-State: AOJu0YwJ9dMBDk8IqJg1SJaz/idb/KuslS+Nzv9rlw99MvWDT/7z2SB9 tP7EZsewxBj3EuWqHvwD7Ptj15EznDUdwKrdkkd9slkzE6XiJR11 X-Google-Smtp-Source: AGHT+IFcf70esZWyvyIEfH+OapZR/bC6zJ0avX0OzAEL4lFiKiWRu6XXm4OcDJgOVFTxK9cqn5/IVg== X-Received: by 2002:a5d:5707:0:b0:34c:d318:44f with SMTP id a7-20020a5d5707000000b0034cd318044fmr354139wrv.66.1714417257374; Mon, 29 Apr 2024 12:00:57 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:abbf:c98a:cf84:d14c]) by smtp.gmail.com with ESMTPSA id x2-20020adfdd82000000b0034c78bba70bsm8469456wrl.72.2024.04.29.12.00.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 12:00:56 -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, phil@raspberrypi.com, 579lpy@gmail.com, linus.walleij@linaro.org, semen.protsenko@linaro.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Vasileios Amoiridis Subject: [PATCH v5 01/10] iio: pressure: bmp280: Improve indentation and line wrapping Date: Mon, 29 Apr 2024 21:00:37 +0200 Message-Id: <20240429190046.24252-2-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240429190046.24252-1-vassilisamir@gmail.com> References: <20240429190046.24252-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Fix indentations that are not following the standards, remove extra white lines and add missing white lines. Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-core.c | 108 ++++++++++++++++------------- drivers/iio/pressure/bmp280-spi.c | 4 +- 2 files changed, 61 insertions(+), 51 deletions(-) base-commit: b0a2c79c6f3590b74742cbbc76687014d47972d8 diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 09f53d987c7d..1a3241a41768 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -52,7 +52,6 @@ */ enum { AC1, AC2, AC3, AC4, AC5, AC6, B1, B2, MB, MC, MD }; - enum bmp380_odr { BMP380_ODR_200HZ, BMP380_ODR_100HZ, @@ -181,18 +180,19 @@ static int bmp280_read_calib(struct bmp280_data *data) struct bmp280_calib *calib = &data->calib.bmp280; int ret; - /* Read temperature and pressure calibration values. */ ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_TEMP_START, - data->bmp280_cal_buf, sizeof(data->bmp280_cal_buf)); + data->bmp280_cal_buf, + sizeof(data->bmp280_cal_buf)); if (ret < 0) { dev_err(data->dev, - "failed to read temperature and pressure calibration parameters\n"); + "failed to read calibration parameters\n"); return ret; } - /* Toss the temperature and pressure calibration data into the entropy pool */ - add_device_randomness(data->bmp280_cal_buf, sizeof(data->bmp280_cal_buf)); + /* Toss calibration data into the entropy pool */ + add_device_randomness(data->bmp280_cal_buf, + sizeof(data->bmp280_cal_buf)); /* Parse temperature calibration values. */ calib->T1 = le16_to_cpu(data->bmp280_cal_buf[T1]); @@ -223,7 +223,7 @@ static int bme280_read_calib(struct bmp280_data *data) /* Load shared calibration params with bmp280 first */ ret = bmp280_read_calib(data); if (ret < 0) { - dev_err(dev, "failed to read common bmp280 calibration parameters\n"); + dev_err(dev, "failed to read calibration parameters\n"); return ret; } @@ -283,6 +283,7 @@ static int bme280_read_calib(struct bmp280_data *data) return 0; } + /* * Returns humidity in percent, resolution is 0.01 percent. Output value of * "47445" represents 47445/1024 = 46.333 %RH. @@ -305,7 +306,7 @@ static u32 bmp280_compensate_humidity(struct bmp280_data *data, var = clamp_val(var, 0, 419430400); return var >> 12; -}; +} /* * Returns temperature in DegC, resolution is 0.01 DegC. Output value of @@ -538,7 +539,7 @@ static int bmp280_read_raw(struct iio_dev *indio_dev, } static int bmp280_write_oversampling_ratio_humid(struct bmp280_data *data, - int val) + int val) { const int *avail = data->chip_info->oversampling_humid_avail; const int n = data->chip_info->num_oversampling_humid_avail; @@ -563,7 +564,7 @@ static int bmp280_write_oversampling_ratio_humid(struct bmp280_data *data, } static int bmp280_write_oversampling_ratio_temp(struct bmp280_data *data, - int val) + int val) { const int *avail = data->chip_info->oversampling_temp_avail; const int n = data->chip_info->num_oversampling_temp_avail; @@ -588,7 +589,7 @@ static int bmp280_write_oversampling_ratio_temp(struct bmp280_data *data, } static int bmp280_write_oversampling_ratio_press(struct bmp280_data *data, - int val) + int val) { const int *avail = data->chip_info->oversampling_press_avail; const int n = data->chip_info->num_oversampling_press_avail; @@ -772,13 +773,12 @@ static int bmp280_chip_config(struct bmp280_data *data) int ret; ret = regmap_write_bits(data->regmap, BMP280_REG_CTRL_MEAS, - BMP280_OSRS_TEMP_MASK | - BMP280_OSRS_PRESS_MASK | - BMP280_MODE_MASK, - osrs | BMP280_MODE_NORMAL); + BMP280_OSRS_TEMP_MASK | + BMP280_OSRS_PRESS_MASK | + BMP280_MODE_MASK, + osrs | BMP280_MODE_NORMAL); if (ret < 0) { - dev_err(data->dev, - "failed to write ctrl_meas register\n"); + dev_err(data->dev, "failed to write ctrl_meas register\n"); return ret; } @@ -786,8 +786,7 @@ static int bmp280_chip_config(struct bmp280_data *data) BMP280_FILTER_MASK, BMP280_FILTER_4X); if (ret < 0) { - dev_err(data->dev, - "failed to write config register\n"); + dev_err(data->dev, "failed to write config register\n"); return ret; } @@ -926,8 +925,8 @@ static int bmp380_cmd(struct bmp280_data *data, u8 cmd) } /* - * Returns temperature in Celsius degrees, resolution is 0.01º C. Output value of - * "5123" equals 51.2º C. t_fine carries fine temperature as global value. + * Returns temperature in Celsius degrees, resolution is 0.01º C. Output value + * of "5123" equals 51.2º C. t_fine carries fine temperature as global value. * * Taken from datasheet, Section Appendix 9, "Compensation formula" and repo * https://github.com/BoschSensortec/BMP3-Sensor-API. @@ -1069,7 +1068,8 @@ static int bmp380_read_calib(struct bmp280_data *data) /* Read temperature and pressure calibration data */ ret = regmap_bulk_read(data->regmap, BMP380_REG_CALIB_TEMP_START, - data->bmp380_cal_buf, sizeof(data->bmp380_cal_buf)); + data->bmp380_cal_buf, + sizeof(data->bmp380_cal_buf)); if (ret) { dev_err(data->dev, "failed to read temperature calibration parameters\n"); @@ -1077,7 +1077,8 @@ static int bmp380_read_calib(struct bmp280_data *data) } /* Toss the temperature calibration data into the entropy pool */ - add_device_randomness(data->bmp380_cal_buf, sizeof(data->bmp380_cal_buf)); + add_device_randomness(data->bmp380_cal_buf, + sizeof(data->bmp380_cal_buf)); /* Parse calibration values */ calib->T1 = get_unaligned_le16(&data->bmp380_cal_buf[BMP380_T1]); @@ -1159,7 +1160,8 @@ static int bmp380_chip_config(struct bmp280_data *data) /* Configure output data rate */ ret = regmap_update_bits_check(data->regmap, BMP380_REG_ODR, - BMP380_ODRS_MASK, data->sampling_freq, &aux); + BMP380_ODRS_MASK, data->sampling_freq, + &aux); if (ret) { dev_err(data->dev, "failed to write ODR selection register\n"); return ret; @@ -1178,12 +1180,13 @@ static int bmp380_chip_config(struct bmp280_data *data) if (change) { /* - * The configurations errors are detected on the fly during a measurement - * cycle. If the sampling frequency is too low, it's faster to reset - * the measurement loop than wait until the next measurement is due. + * The configurations errors are detected on the fly during a + * measurement cycle. If the sampling frequency is too low, it's + * faster to reset the measurement loop than wait until the next + * measurement is due. * - * Resets sensor measurement loop toggling between sleep and normal - * operating modes. + * Resets sensor measurement loop toggling between sleep and + * normal operating modes. */ ret = regmap_write_bits(data->regmap, BMP380_REG_POWER_CONTROL, BMP380_MODE_MASK, @@ -1201,22 +1204,21 @@ static int bmp380_chip_config(struct bmp280_data *data) return ret; } /* - * Waits for measurement before checking configuration error flag. - * Selected longest measure time indicated in section 3.9.1 - * in the datasheet. + * Waits for measurement before checking configuration error + * flag. Selected longest measure time indicated in + * section 3.9.1 in the datasheet. */ msleep(80); /* Check config error flag */ ret = regmap_read(data->regmap, BMP380_REG_ERROR, &tmp); if (ret) { - dev_err(data->dev, - "failed to read error register\n"); + dev_err(data->dev, "failed to read error register\n"); return ret; } if (tmp & BMP380_ERR_CONF_MASK) { dev_warn(data->dev, - "sensor flagged configuration as incompatible\n"); + "sensor flagged configuration as incompatible\n"); return -EINVAL; } } @@ -1317,9 +1319,11 @@ static int bmp580_nvm_operation(struct bmp280_data *data, bool is_write) } /* Start NVM operation sequence */ - ret = regmap_write(data->regmap, BMP580_REG_CMD, BMP580_CMD_NVM_OP_SEQ_0); + ret = regmap_write(data->regmap, BMP580_REG_CMD, + BMP580_CMD_NVM_OP_SEQ_0); if (ret) { - dev_err(data->dev, "failed to send nvm operation's first sequence\n"); + dev_err(data->dev, + "failed to send nvm operation's first sequence\n"); return ret; } if (is_write) { @@ -1327,7 +1331,8 @@ static int bmp580_nvm_operation(struct bmp280_data *data, bool is_write) ret = regmap_write(data->regmap, BMP580_REG_CMD, BMP580_CMD_NVM_WRITE_SEQ_1); if (ret) { - dev_err(data->dev, "failed to send nvm write sequence\n"); + dev_err(data->dev, + "failed to send nvm write sequence\n"); return ret; } /* Datasheet says on 4.8.1.2 it takes approximately 10ms */ @@ -1338,7 +1343,8 @@ static int bmp580_nvm_operation(struct bmp280_data *data, bool is_write) ret = regmap_write(data->regmap, BMP580_REG_CMD, BMP580_CMD_NVM_READ_SEQ_1); if (ret) { - dev_err(data->dev, "failed to send nvm read sequence\n"); + dev_err(data->dev, + "failed to send nvm read sequence\n"); return ret; } /* Datasheet says on 4.8.1.1 it takes approximately 200us */ @@ -1501,8 +1507,8 @@ static int bmp580_nvmem_read(void *priv, unsigned int offset, void *val, if (ret) goto exit; - ret = regmap_bulk_read(data->regmap, BMP580_REG_NVM_DATA_LSB, &data->le16, - sizeof(data->le16)); + ret = regmap_bulk_read(data->regmap, BMP580_REG_NVM_DATA_LSB, + &data->le16, sizeof(data->le16)); if (ret) { dev_err(data->dev, "error reading nvm data regs\n"); goto exit; @@ -1546,7 +1552,8 @@ static int bmp580_nvmem_write(void *priv, unsigned int offset, void *val, while (bytes >= sizeof(*buf)) { addr = bmp580_nvmem_addrs[offset / sizeof(*buf)]; - ret = regmap_write(data->regmap, BMP580_REG_NVM_ADDR, BMP580_NVM_PROG_EN | + ret = regmap_write(data->regmap, BMP580_REG_NVM_ADDR, + BMP580_NVM_PROG_EN | FIELD_PREP(BMP580_NVM_ROW_ADDR_MASK, addr)); if (ret) { dev_err(data->dev, "error writing nvm address\n"); @@ -1554,8 +1561,8 @@ static int bmp580_nvmem_write(void *priv, unsigned int offset, void *val, } data->le16 = cpu_to_le16(*buf++); - ret = regmap_bulk_write(data->regmap, BMP580_REG_NVM_DATA_LSB, &data->le16, - sizeof(data->le16)); + ret = regmap_bulk_write(data->regmap, BMP580_REG_NVM_DATA_LSB, + &data->le16, sizeof(data->le16)); if (ret) { dev_err(data->dev, "error writing LSB NVM data regs\n"); goto exit; @@ -1662,7 +1669,8 @@ static int bmp580_chip_config(struct bmp280_data *data) BMP580_OSR_PRESS_EN; ret = regmap_update_bits_check(data->regmap, BMP580_REG_OSR_CONFIG, - BMP580_OSR_TEMP_MASK | BMP580_OSR_PRESS_MASK | + BMP580_OSR_TEMP_MASK | + BMP580_OSR_PRESS_MASK | BMP580_OSR_PRESS_EN, reg_val, &aux); if (ret) { @@ -1713,7 +1721,8 @@ static int bmp580_chip_config(struct bmp280_data *data) */ ret = regmap_read(data->regmap, BMP580_REG_EFF_OSR, &tmp); if (ret) { - dev_err(data->dev, "error reading effective OSR register\n"); + dev_err(data->dev, + "error reading effective OSR register\n"); return ret; } if (!(tmp & BMP580_EFF_OSR_VALID_ODR)) { @@ -1848,7 +1857,8 @@ static int bmp180_read_calib(struct bmp280_data *data) } /* Toss the calibration data into the entropy pool */ - add_device_randomness(data->bmp180_cal_buf, sizeof(data->bmp180_cal_buf)); + add_device_randomness(data->bmp180_cal_buf, + sizeof(data->bmp180_cal_buf)); calib->AC1 = be16_to_cpu(data->bmp180_cal_buf[AC1]); calib->AC2 = be16_to_cpu(data->bmp180_cal_buf[AC2]); @@ -1963,8 +1973,7 @@ 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 int bmp180_read_press(struct bmp280_data *data, int *val, int *val2) { u32 comp_press; s32 adc_press; @@ -2241,6 +2250,7 @@ static int bmp280_runtime_resume(struct device *dev) ret = regulator_bulk_enable(BMP280_NUM_SUPPLIES, data->supplies); if (ret) return ret; + usleep_range(data->start_up_time, data->start_up_time + 100); return data->chip_info->chip_config(data); } diff --git a/drivers/iio/pressure/bmp280-spi.c b/drivers/iio/pressure/bmp280-spi.c index 4e19ea0b4d39..62b4e58104cf 100644 --- a/drivers/iio/pressure/bmp280-spi.c +++ b/drivers/iio/pressure/bmp280-spi.c @@ -13,7 +13,7 @@ #include "bmp280.h" static int bmp280_regmap_spi_write(void *context, const void *data, - size_t count) + size_t count) { struct spi_device *spi = to_spi_device(context); u8 buf[2]; @@ -29,7 +29,7 @@ static int bmp280_regmap_spi_write(void *context, const void *data, } static int bmp280_regmap_spi_read(void *context, const void *reg, - size_t reg_size, void *val, size_t val_size) + size_t reg_size, void *val, size_t val_size) { struct spi_device *spi = to_spi_device(context); From patchwork Mon Apr 29 19:00:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13647521 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37CE513AA53; Mon, 29 Apr 2024 19:01:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714417262; cv=none; b=mGI9AP49BHdB1wVrnpvLJ9n1f7Nsdkt9IUgDI8RIVk6s58zMMk9vDliHn8G6w6ZREe/C9PSEW2zghZ3tRfnwTtvI0hFHg1B3pBJN9XDhWTdeuM0k2VhcTCOKwx+wB+4Uahu8WaIpQrsZQjhu9SzFxfLUWuf6pVumt2mdfbrgaEM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714417262; c=relaxed/simple; bh=pyKoEaZamqmkgEdCEotX1uvTz2PnX/XidujYA1x1BcA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BHIv64gFjod36ixW4FVV/hlUuOlZ6+ptL0u2Ms0vQ85PA+jofMi/NNspJAc5nHKXzQY64kVpw1rAFtkbz+59CKiMhndLlBpo5+hfE9nZmew7e3zughI/x4YIhuDUKzzvbdvhHE90isjUqkwma+RW0OaU3igMGc4wkM+RxB7muqA= 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=BIwcWfMs; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BIwcWfMs" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-34c1fff534fso3556324f8f.1; Mon, 29 Apr 2024 12:00:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714417258; x=1715022058; 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=4ABoaoYIXELoew2vdUdRbCooyvR0CbBpVkqKlUmodqI=; b=BIwcWfMs2ZlzXpw7qtZGRig6+jSUVhu2izDU6LXESvjkcwSZHwq8a1sEMxFJ9OOGgk AnB9yz7rezv5goylPZdYG5AtNUryxTytO7libQx58VkTlCu/KvYTvER7p8Kdwz/CCEGw Bd5mLBkkr97zHYQUvUjTFj08XkV5IrFupGFaR0ruRVJmZ/1cHGTn9XL2PJXiv+J1Mojn X4atFtxrogR44WMx0GqZ25ayAVr/xVjAP1anW5ASzRr4+A5GWmIAdsFTw2VI7oH6Q67y xx6RkA4yaghMW4Dptei9fg4DfAx/Q+N9VsZuseUQ7KhWB2NJUrn5C7KBLCZsciHSfF+C HZlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714417258; x=1715022058; 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=4ABoaoYIXELoew2vdUdRbCooyvR0CbBpVkqKlUmodqI=; b=oWYRnwrpm8L1oGCYdTPfW5dfMF7rfuTO2zz/WjGRhmJ/1AcPwphTEjuS5sNbrw4+ZJ vWoK5ZBQ3xfOmHz/WFKP1aE7MMnSr6E+QXahCJA3oNCavB5+cI/2KIhmB7L/fSf6CIvh e8I3rwkTS1MKkdLJKOf5bVTSboPxnd6vyOdW3L50azxHzP111BV4H3sgQ4Dp8t9zMFTP Mx9pgSDO0rNzrZz/jAg4h0FpQg9DFvWdzbBC5FEw81hae12JpwausbIXCYh4XsyNdR4L Rw/SrxlhTCREAtoeslW0WGVQZFVhf5fr8WTHzz5xUnIKLf629um6qxxgH/sh5jC7HCKt n40g== X-Forwarded-Encrypted: i=1; AJvYcCUSBYXSX6FxNchczTN6W9SZq3QbJBNAg3XpRbnfnf2hqU8eotxaTC4aAogyP5NxAJX9eUX0slsQq2rq25WhUMjiCRuOnbGrtZODSXNTq+2me0PqQLyPPEdYg1DyScRWQlhX7skDB9SF X-Gm-Message-State: AOJu0YwLePj5GT7N/EvONaw379zZjFXG4jq4mn/rAmp7Kz24vA/drTmz QqBkGNK+4DK84422HgzNXgR0/+3Vawo2nTB5AMRncMZCrXOpvFJH X-Google-Smtp-Source: AGHT+IGLEfDCV+e7r+nDAh6M0jbAdlcqvCpiOYUCgBWQxUEmkW7tvwDhUrkoPqqdzk/j4VxXa2Y8Tw== X-Received: by 2002:adf:f6cc:0:b0:34a:d5e:afd2 with SMTP id y12-20020adff6cc000000b0034a0d5eafd2mr7998940wrp.4.1714417258581; Mon, 29 Apr 2024 12:00:58 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:abbf:c98a:cf84:d14c]) by smtp.gmail.com with ESMTPSA id x2-20020adfdd82000000b0034c78bba70bsm8469456wrl.72.2024.04.29.12.00.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 12:00:57 -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, phil@raspberrypi.com, 579lpy@gmail.com, linus.walleij@linaro.org, semen.protsenko@linaro.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Vasileios Amoiridis Subject: [PATCH v5 02/10] iio: pressure: bmp280: Use BME prefix for BME280 specifics Date: Mon, 29 Apr 2024 21:00:38 +0200 Message-Id: <20240429190046.24252-3-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240429190046.24252-1-vassilisamir@gmail.com> References: <20240429190046.24252-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Change the rest of the defines and function names that are used specifically by the BME280 humidity sensor to BME280 as it is done for the rest of the BMP{0,1,3,5}80 sensors. Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-core.c | 37 +++++++++++------------ drivers/iio/pressure/bmp280-regmap.c | 8 ++--- drivers/iio/pressure/bmp280.h | 45 +++++++++++++++------------- 3 files changed, 46 insertions(+), 44 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 1a3241a41768..edfa66953f87 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -235,14 +235,14 @@ static int bme280_read_calib(struct bmp280_data *data) * Humidity data is only available on BME280. */ - ret = regmap_read(data->regmap, BMP280_REG_COMP_H1, &tmp); + ret = regmap_read(data->regmap, BME280_REG_COMP_H1, &tmp); if (ret < 0) { dev_err(dev, "failed to read H1 comp value\n"); return ret; } calib->H1 = tmp; - ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H2, + ret = regmap_bulk_read(data->regmap, BME280_REG_COMP_H2, &data->le16, sizeof(data->le16)); if (ret < 0) { dev_err(dev, "failed to read H2 comp value\n"); @@ -250,14 +250,14 @@ static int bme280_read_calib(struct bmp280_data *data) } calib->H2 = sign_extend32(le16_to_cpu(data->le16), 15); - ret = regmap_read(data->regmap, BMP280_REG_COMP_H3, &tmp); + ret = regmap_read(data->regmap, BME280_REG_COMP_H3, &tmp); if (ret < 0) { dev_err(dev, "failed to read H3 comp value\n"); return ret; } calib->H3 = tmp; - ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H4, + ret = regmap_bulk_read(data->regmap, BME280_REG_COMP_H4, &data->be16, sizeof(data->be16)); if (ret < 0) { dev_err(dev, "failed to read H4 comp value\n"); @@ -266,15 +266,15 @@ static int bme280_read_calib(struct bmp280_data *data) calib->H4 = sign_extend32(((be16_to_cpu(data->be16) >> 4) & 0xff0) | (be16_to_cpu(data->be16) & 0xf), 11); - ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H5, + ret = regmap_bulk_read(data->regmap, BME280_REG_COMP_H5, &data->le16, sizeof(data->le16)); if (ret < 0) { dev_err(dev, "failed to read H5 comp value\n"); return ret; } - calib->H5 = sign_extend32(FIELD_GET(BMP280_COMP_H5_MASK, le16_to_cpu(data->le16)), 11); + calib->H5 = sign_extend32(FIELD_GET(BME280_COMP_H5_MASK, le16_to_cpu(data->le16)), 11); - ret = regmap_read(data->regmap, BMP280_REG_COMP_H6, &tmp); + ret = regmap_read(data->regmap, BME280_REG_COMP_H6, &tmp); if (ret < 0) { dev_err(dev, "failed to read H6 comp value\n"); return ret; @@ -290,7 +290,7 @@ static int bme280_read_calib(struct bmp280_data *data) * * Taken from BME280 datasheet, Section 4.2.3, "Compensation formula". */ -static u32 bmp280_compensate_humidity(struct bmp280_data *data, +static u32 bme280_compensate_humidity(struct bmp280_data *data, s32 adc_humidity) { struct bmp280_calib *calib = &data->calib.bmp280; @@ -430,7 +430,7 @@ static int bmp280_read_press(struct bmp280_data *data, return IIO_VAL_FRACTIONAL; } -static int bmp280_read_humid(struct bmp280_data *data, int *val, int *val2) +static int bme280_read_humid(struct bmp280_data *data, int *val, int *val2) { u32 comp_humidity; s32 adc_humidity; @@ -441,7 +441,7 @@ static int bmp280_read_humid(struct bmp280_data *data, int *val, int *val2) if (ret < 0) return ret; - ret = regmap_bulk_read(data->regmap, BMP280_REG_HUMIDITY_MSB, + ret = regmap_bulk_read(data->regmap, BME280_REG_HUMIDITY_MSB, &data->be16, sizeof(data->be16)); if (ret < 0) { dev_err(data->dev, "failed to read humidity\n"); @@ -454,7 +454,7 @@ static int bmp280_read_humid(struct bmp280_data *data, int *val, int *val2) dev_err(data->dev, "reading humidity skipped\n"); return -EIO; } - comp_humidity = bmp280_compensate_humidity(data, adc_humidity); + comp_humidity = bme280_compensate_humidity(data, adc_humidity); *val = comp_humidity * 1000 / 1024; @@ -538,7 +538,7 @@ static int bmp280_read_raw(struct iio_dev *indio_dev, return ret; } -static int bmp280_write_oversampling_ratio_humid(struct bmp280_data *data, +static int bme280_write_oversampling_ratio_humid(struct bmp280_data *data, int val) { const int *avail = data->chip_info->oversampling_humid_avail; @@ -682,7 +682,7 @@ static int bmp280_write_raw(struct iio_dev *indio_dev, mutex_lock(&data->lock); switch (chan->type) { case IIO_HUMIDITYRELATIVE: - ret = bmp280_write_oversampling_ratio_humid(data, val); + ret = bme280_write_oversampling_ratio_humid(data, val); break; case IIO_PRESSURE: ret = bmp280_write_oversampling_ratio_press(data, val); @@ -832,16 +832,15 @@ EXPORT_SYMBOL_NS(bmp280_chip_info, IIO_BMP280); static int bme280_chip_config(struct bmp280_data *data) { - u8 osrs = FIELD_PREP(BMP280_OSRS_HUMIDITY_MASK, data->oversampling_humid + 1); + u8 osrs = FIELD_PREP(BME280_OSRS_HUMIDITY_MASK, data->oversampling_humid + 1); int ret; /* * Oversampling of humidity must be set before oversampling of * temperature/pressure is set to become effective. */ - ret = regmap_update_bits(data->regmap, BMP280_REG_CTRL_HUMIDITY, - BMP280_OSRS_HUMIDITY_MASK, osrs); - + ret = regmap_update_bits(data->regmap, BME280_REG_CTRL_HUMIDITY, + BME280_OSRS_HUMIDITY_MASK, osrs); if (ret < 0) return ret; @@ -869,12 +868,12 @@ const struct bmp280_chip_info bme280_chip_info = { .oversampling_humid_avail = bmp280_oversampling_avail, .num_oversampling_humid_avail = ARRAY_SIZE(bmp280_oversampling_avail), - .oversampling_humid_default = BMP280_OSRS_HUMIDITY_16X - 1, + .oversampling_humid_default = BME280_OSRS_HUMIDITY_16X - 1, .chip_config = bme280_chip_config, .read_temp = bmp280_read_temp, .read_press = bmp280_read_press, - .read_humid = bmp280_read_humid, + .read_humid = bme280_read_humid, .read_calib = bme280_read_calib, }; EXPORT_SYMBOL_NS(bme280_chip_info, IIO_BMP280); diff --git a/drivers/iio/pressure/bmp280-regmap.c b/drivers/iio/pressure/bmp280-regmap.c index 3ee56720428c..fa52839474b1 100644 --- a/drivers/iio/pressure/bmp280-regmap.c +++ b/drivers/iio/pressure/bmp280-regmap.c @@ -45,7 +45,7 @@ static bool bmp280_is_writeable_reg(struct device *dev, unsigned int reg) { switch (reg) { case BMP280_REG_CONFIG: - case BMP280_REG_CTRL_HUMIDITY: + case BME280_REG_CTRL_HUMIDITY: case BMP280_REG_CTRL_MEAS: case BMP280_REG_RESET: return true; @@ -57,8 +57,8 @@ static bool bmp280_is_writeable_reg(struct device *dev, unsigned int reg) static bool bmp280_is_volatile_reg(struct device *dev, unsigned int reg) { switch (reg) { - case BMP280_REG_HUMIDITY_LSB: - case BMP280_REG_HUMIDITY_MSB: + case BME280_REG_HUMIDITY_LSB: + case BME280_REG_HUMIDITY_MSB: case BMP280_REG_TEMP_XLSB: case BMP280_REG_TEMP_LSB: case BMP280_REG_TEMP_MSB: @@ -167,7 +167,7 @@ const struct regmap_config bmp280_regmap_config = { .reg_bits = 8, .val_bits = 8, - .max_register = BMP280_REG_HUMIDITY_LSB, + .max_register = BME280_REG_HUMIDITY_LSB, .cache_type = REGCACHE_RBTREE, .writeable_reg = bmp280_is_writeable_reg, diff --git a/drivers/iio/pressure/bmp280.h b/drivers/iio/pressure/bmp280.h index 5812a344ed8e..91d4457a9230 100644 --- a/drivers/iio/pressure/bmp280.h +++ b/drivers/iio/pressure/bmp280.h @@ -192,8 +192,6 @@ #define BMP380_PRESS_SKIPPED 0x800000 /* BMP280 specific registers */ -#define BMP280_REG_HUMIDITY_LSB 0xFE -#define BMP280_REG_HUMIDITY_MSB 0xFD #define BMP280_REG_TEMP_XLSB 0xFC #define BMP280_REG_TEMP_LSB 0xFB #define BMP280_REG_TEMP_MSB 0xFA @@ -207,15 +205,6 @@ #define BMP280_REG_CONFIG 0xF5 #define BMP280_REG_CTRL_MEAS 0xF4 #define BMP280_REG_STATUS 0xF3 -#define BMP280_REG_CTRL_HUMIDITY 0xF2 - -/* Due to non linear mapping, and data sizes we can't do a bulk read */ -#define BMP280_REG_COMP_H1 0xA1 -#define BMP280_REG_COMP_H2 0xE1 -#define BMP280_REG_COMP_H3 0xE3 -#define BMP280_REG_COMP_H4 0xE4 -#define BMP280_REG_COMP_H5 0xE5 -#define BMP280_REG_COMP_H6 0xE7 #define BMP280_REG_COMP_TEMP_START 0x88 #define BMP280_COMP_TEMP_REG_COUNT 6 @@ -223,8 +212,6 @@ #define BMP280_REG_COMP_PRESS_START 0x8E #define BMP280_COMP_PRESS_REG_COUNT 18 -#define BMP280_COMP_H5_MASK GENMASK(15, 4) - #define BMP280_CONTIGUOUS_CALIB_REGS (BMP280_COMP_TEMP_REG_COUNT + \ BMP280_COMP_PRESS_REG_COUNT) @@ -235,14 +222,6 @@ #define BMP280_FILTER_8X 3 #define BMP280_FILTER_16X 4 -#define BMP280_OSRS_HUMIDITY_MASK GENMASK(2, 0) -#define BMP280_OSRS_HUMIDITY_SKIP 0 -#define BMP280_OSRS_HUMIDITY_1X 1 -#define BMP280_OSRS_HUMIDITY_2X 2 -#define BMP280_OSRS_HUMIDITY_4X 3 -#define BMP280_OSRS_HUMIDITY_8X 4 -#define BMP280_OSRS_HUMIDITY_16X 5 - #define BMP280_OSRS_TEMP_MASK GENMASK(7, 5) #define BMP280_OSRS_TEMP_SKIP 0 #define BMP280_OSRS_TEMP_1X 1 @@ -264,6 +243,30 @@ #define BMP280_MODE_FORCED 1 #define BMP280_MODE_NORMAL 3 +/* BME280 specific registers */ +#define BME280_REG_HUMIDITY_LSB 0xFE +#define BME280_REG_HUMIDITY_MSB 0xFD + +#define BME280_REG_CTRL_HUMIDITY 0xF2 + +/* Due to non linear mapping, and data sizes we can't do a bulk read */ +#define BME280_REG_COMP_H1 0xA1 +#define BME280_REG_COMP_H2 0xE1 +#define BME280_REG_COMP_H3 0xE3 +#define BME280_REG_COMP_H4 0xE4 +#define BME280_REG_COMP_H5 0xE5 +#define BME280_REG_COMP_H6 0xE7 + +#define BME280_COMP_H5_MASK GENMASK(15, 4) + +#define BME280_OSRS_HUMIDITY_MASK GENMASK(2, 0) +#define BME280_OSRS_HUMIDITY_SKIP 0 +#define BME280_OSRS_HUMIDITY_1X 1 +#define BME280_OSRS_HUMIDITY_2X 2 +#define BME280_OSRS_HUMIDITY_4X 3 +#define BME280_OSRS_HUMIDITY_8X 4 +#define BME280_OSRS_HUMIDITY_16X 5 + /* BMP180 specific registers */ #define BMP180_REG_OUT_XLSB 0xF8 #define BMP180_REG_OUT_LSB 0xF7 From patchwork Mon Apr 29 19:00:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13647522 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.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 36A8113AD1D; Mon, 29 Apr 2024 19:01:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714417262; cv=none; b=KzSlsXcKZqojbCOnTG8G4l2KLxk8a7eYDiAFGhdhA239JNPoKwATOrld7dnyGOLoYOBTfPj2BJZn2OZUucrD9jZjVNyUJ4fJW6AYjoyOyeWVX0to+w4dQLrgJSfbJDMEKF7VoOzQpB22ZNeeaFyYKXqRY8/vWive6y2LjMdBmH8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714417262; c=relaxed/simple; bh=e/EKtuPTPn4NChpsM6c21+3QDbDI1wDTorh6nJv74wU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YO0Cs+bAOSu2NR7wl6Sw4zWJjOzULePa37+zeVtz1ISeX1+fAibKKyta+b6Xb5G/UsryUheU897QOwtl+rf64dDDKSCOEZNhwLEP8InBbBKE2GQtO3WvnSJTztJSEhpufJRxJxjRYkDozwICiapUJc70XBVCFNOkfT+6NuozQwU= 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=ZaB4rAeB; arc=none smtp.client-ip=209.85.221.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="ZaB4rAeB" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-34d16d204f4so931078f8f.0; Mon, 29 Apr 2024 12:01:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714417260; x=1715022060; 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=F+OOjPjRo623dIYYIWsxFcTXv4CTjfVgOyFCPn/JKfg=; b=ZaB4rAeBt4uxkCrlhymjQUsuktW4AX2DlB3z5hFEhvEvOPlexLoFkl8rsnzEfPLOuD YoOpyMTwOUjk6XQLkBlG4nJzmjLWhY7rrrvsYjxETzrqMAbgfYKj3tAxCJxBLrA+FEms RljJN+O0+tIajAUf3YxPi4MNBpGAtfeGvG6GrohTnCSPXaJ7I8Iqyzfo8Yh4GUzNuTjJ 6aXJ6o5+WQ+TLy9bKoGPDN6BF8Rs3uBM5gC/MfXozdMVVN6P7ZvOKlFiW00VxG62hRPd OFdt3aq8u1x0HAIzCwcaqWmC2vfRZ5QwbhQ7yLcM155Kk7P6qGFe1TDX05KCQbVMAPHW acaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714417260; x=1715022060; 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=F+OOjPjRo623dIYYIWsxFcTXv4CTjfVgOyFCPn/JKfg=; b=eXnyPZcYhZYeCg2zaWDR97R1YHlvESgm+2mto9lL1KiOXDFPYDQ4CIExUVk5SBNh+D Jjyj2Pe3aT5dVIpoxIVmaARMA6nqGjMyjHEGszTUQbqB615ENvLOi2EpZPf4N2j4wuGb 008oqZPlDtF2IHMqQI1ls119jyD7VI0WaoM7JwQw8ykVA5I93KBUFd0oS20nQFSbVpoD fEEXYYYN81h2Y/O9nhlZ7gQZQYribucIU3EQlefV1+ThMrSQbkm4jdSnLLwXX77lWZO7 AqIHCsCklWDWZZGXATg3PavA9OQTNmAAl+TJYnQWqfLmWY0hal6fVzeNQ90bAWcKfc7N JpkA== X-Forwarded-Encrypted: i=1; AJvYcCUISumM7UQW10HA1Oask5T2tqmf+UPfDjBp3nUrGm37qsydhXBybAjgpTSaTx3DUmcwNjFSIlnLf3YxSAuAcgSyYW026jDa/p4eQWumMLMqyZ0hJJIPAQ9PN5mF8ggXKhedOF6sP5ll X-Gm-Message-State: AOJu0YyKH+msl1U/4gm/M4EZju1b7xmV6HLX8vlGv71ZAjOXNqbNvE7v NvzpVVMVR6nHgzpVzH+MCrMpk9zWXw8onKZxLGmsrkjiGbUdwSFl X-Google-Smtp-Source: AGHT+IFCG/f4fvOPYpgCtVIwD807apMXXXPXdiKyjA3/oZdLYym934G2JY3apElTiAsLB0wnEczZ0Q== X-Received: by 2002:a05:6000:8b:b0:34c:8673:21f5 with SMTP id m11-20020a056000008b00b0034c867321f5mr5295641wrx.38.1714417259599; Mon, 29 Apr 2024 12:00:59 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:abbf:c98a:cf84:d14c]) by smtp.gmail.com with ESMTPSA id x2-20020adfdd82000000b0034c78bba70bsm8469456wrl.72.2024.04.29.12.00.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 12:00:59 -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, phil@raspberrypi.com, 579lpy@gmail.com, linus.walleij@linaro.org, semen.protsenko@linaro.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Vasileios Amoiridis Subject: [PATCH v5 03/10] iio: pressure: bmp280: Add identifier names in function definitions Date: Mon, 29 Apr 2024 21:00:39 +0200 Message-Id: <20240429190046.24252-4-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240429190046.24252-1-vassilisamir@gmail.com> References: <20240429190046.24252-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 checkpatch.pl complained about missing identifier names in the input variables for some function definitions. Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/iio/pressure/bmp280.h b/drivers/iio/pressure/bmp280.h index 91d4457a9230..fe4d3f127954 100644 --- a/drivers/iio/pressure/bmp280.h +++ b/drivers/iio/pressure/bmp280.h @@ -452,12 +452,12 @@ struct bmp280_chip_info { int num_sampling_freq_avail; int sampling_freq_default; - 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 *); - int (*read_calib)(struct bmp280_data *); - int (*preinit)(struct bmp280_data *); + int (*chip_config)(struct bmp280_data *data); + int (*read_temp)(struct bmp280_data *data, int *val, int *val2); + int (*read_press)(struct bmp280_data *data, int *val, int *val2); + int (*read_humid)(struct bmp280_data *data, int *val, int *val2); + int (*read_calib)(struct bmp280_data *data); + int (*preinit)(struct bmp280_data *data); }; /* Chip infos for each variant */ @@ -476,7 +476,7 @@ extern const struct regmap_config bmp580_regmap_config; /* Probe called from different transports */ int bmp280_common_probe(struct device *dev, struct regmap *regmap, - const struct bmp280_chip_info *, + const struct bmp280_chip_info *chip_info, const char *name, int irq); From patchwork Mon Apr 29 19:00:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13647523 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDEB113B5BB; Mon, 29 Apr 2024 19:01:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714417264; cv=none; b=Jlh5c8DZcjiRz1ql7v/ibQKx+Avyzi5hDIeJfx40dtsbF3ZTLI21NaCzqreKJisyVStJJ3S1J0AkyDN/HDLes6Q7Mi8XwpuqY9RsI5zZRxyE3K9uhrFSD8bMM7ixqqf4VHKyqiqLI6+uxjkWAcN30CmI2QWkDW2yHNQ8DcI+5v8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714417264; c=relaxed/simple; bh=n7ZnkHS6L2EjKJdsc7qHUDXg5Zssd+Z6n1RohBzL08Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Y8LYtyqs0O71dO855EB3FGk62XEFPcEsgxFnTcHQIhBeT95gd2NE//PNHSlh2mmQ9fwyNpNhxaSeWJxJxmBRTFNnR7WyinrUHHBKHds8ka1pPUc/uYUnTHJoMWB1C3zcrlOOyQNx4xdsu7sh6bqgzHoeU41DD4HQmGNXeuHMqj0= 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=ZuSF7+R5; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZuSF7+R5" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-5194cebd6caso5515285e87.0; Mon, 29 Apr 2024 12:01:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714417261; x=1715022061; 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=d03SxwYQEgO9ihhxcMsHW4m7sHTd0aWe30L6xyAn2MA=; b=ZuSF7+R5Hc+0sCmIOaWVQZ6Z9d9H8zdo0Uv9anwSHINWAibAujQ7QGOcuzOzqJLvci KrGdzVRE6/k5QFl+o8DE0zfxqYhf7V0isFRfC22Cw1a5tNNKa7ca5AymawEMZJpCzERj 1Rc7A7/OodxfiqImeCiz9+uz51BqCItIbY3S3N4l8JfDgwvUh7Ol3V38VfcsMOEKl0+Q cp/Aw8CbiI2D53Ei+9qsNNsOx4237vyiJYsHLEFHIv8V9IKCwur+aaIQ8k38B2OWSQYa IRHfHvfmCucwaxVoC9hP2SdgTK8R9KRKw81zipf6FYW1ZV2led646N/0NXjRGPCWkisC e6LQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714417261; x=1715022061; 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=d03SxwYQEgO9ihhxcMsHW4m7sHTd0aWe30L6xyAn2MA=; b=VN7Sd2c9Qfh9UCKnFtAkYtXtL0H6GJbutuKIY46jSysmf0UvNIiSJIJpqZ+lvdgg0f uN1SsouTRf5JDFvozbZVxMZSKtXrWcdgMWc5R+ySu751Y/owX1Ylc+EmPS0+IziCuYcW Crdi+d6GYLAi6AVVQ12hlAACMZLGFpXc6nlGnnt1r+JEqQZOOGQGuN80QOoTpR6cpIav 6RMIi3mh3D120HHKy6mWuZ/M+qeU16ZewIOVBfXZUXsP6KO/CyAQY4nvAic62Ep5EcHC izNpQgUBQO+hczd48fKrUCwnFRxVjs+rkiY/wuu/ao5G/FVHbnlBRbrmjOSO6CddeyST najQ== X-Forwarded-Encrypted: i=1; AJvYcCXPlP5Wu2EfsVsiWckEu/QVE7rmDeeSdv/m0uE6bubbaZQJMwAdXk0+aLklojHYb2d091Nf9+zoPqWP85rtdtfkLtUWZix6vANvTnFN0rp0uRAwM++A1xIMSrAxt1eLlz0BcxdIbX5M X-Gm-Message-State: AOJu0YxkmFGXctxRjZmJOVqUYVQbBcVnNtAwIHhZIjtK8KPjCjVZqqfJ crL6rNmz+EVoy0VzGmxFdsyVH2PbWvipMQDjb7cBGv1k6e3O5g49 X-Google-Smtp-Source: AGHT+IHcEWUGYUu+eGd8rvmoytYJkD9N9qMYjCvgbDtw8yPFkdfJGBJp8RjNto3w/S9EmSXgROm/vw== X-Received: by 2002:ac2:59c1:0:b0:51a:f2fb:b13c with SMTP id x1-20020ac259c1000000b0051af2fbb13cmr6071080lfn.11.1714417260730; Mon, 29 Apr 2024 12:01:00 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:abbf:c98a:cf84:d14c]) by smtp.gmail.com with ESMTPSA id x2-20020adfdd82000000b0034c78bba70bsm8469456wrl.72.2024.04.29.12.00.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 12:01:00 -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, phil@raspberrypi.com, 579lpy@gmail.com, linus.walleij@linaro.org, semen.protsenko@linaro.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Vasileios Amoiridis Subject: [PATCH v5 04/10] iio: pressure: bmp280: Add more intuitive name for bmp180_measure() Date: Mon, 29 Apr 2024 21:00:40 +0200 Message-Id: <20240429190046.24252-5-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240429190046.24252-1-vassilisamir@gmail.com> References: <20240429190046.24252-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 bmp180_measure() function essentially waits for the end of the current conversion in order to read the values from the sensors. The name bmp180_measure() could be misinterpreted because it could be translated as "measure sensor values" even though it was probably trying to say "measure time for eoc". Give a more intuitive name to this function to be less confusing. 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 edfa66953f87..ed49e0779d41 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -1771,7 +1771,7 @@ const struct bmp280_chip_info bmp580_chip_info = { }; EXPORT_SYMBOL_NS(bmp580_chip_info, IIO_BMP280); -static int bmp180_measure(struct bmp280_data *data, u8 ctrl_meas) +static int bmp180_wait_for_eoc(struct bmp280_data *data, u8 ctrl_meas) { const int conversion_time_max[] = { 4500, 7500, 13500, 25500 }; unsigned int delay_us; @@ -1820,9 +1820,9 @@ static int bmp180_read_adc_temp(struct bmp280_data *data, int *val) { int ret; - ret = bmp180_measure(data, - FIELD_PREP(BMP180_MEAS_CTRL_MASK, BMP180_MEAS_TEMP) | - BMP180_MEAS_SCO); + ret = bmp180_wait_for_eoc(data, + FIELD_PREP(BMP180_MEAS_CTRL_MASK, BMP180_MEAS_TEMP) | + BMP180_MEAS_SCO); if (ret) return ret; @@ -1920,10 +1920,10 @@ static int bmp180_read_adc_press(struct bmp280_data *data, int *val) u8 oss = data->oversampling_press; int ret; - ret = bmp180_measure(data, - FIELD_PREP(BMP180_MEAS_CTRL_MASK, BMP180_MEAS_PRESS) | - FIELD_PREP(BMP180_OSRS_PRESS_MASK, oss) | - BMP180_MEAS_SCO); + ret = bmp180_wait_for_eoc(data, + FIELD_PREP(BMP180_MEAS_CTRL_MASK, BMP180_MEAS_PRESS) | + FIELD_PREP(BMP180_OSRS_PRESS_MASK, oss) | + BMP180_MEAS_SCO); if (ret) return ret; From patchwork Mon Apr 29 19:00:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13647524 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC80C13BC07; Mon, 29 Apr 2024 19:01:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714417266; cv=none; b=Q7qM/w/zD7km042k1ITe4KQnQoao89KQLqG8AcxtgERURSvLjT0nVQdMJesqISWd67ZX9nfJkdXv+Jn7PbzVsn7Mx6Z3bb01Eih8EJjkhjwk4XtvawfmgpHcXHofHn06vxWLGSa3152sQTuSpbflw0BMLZhLp6StqsA40dnxOZA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714417266; c=relaxed/simple; bh=vvmZIswHnUku9oseN2P7rPEbCOHxM5/CeF3KATn7JoM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Fi8UDbKKerNUPXG2E8OHjwFE8D2bJLQEuBnOeKTzJ3NNEsahQAGMe/MlXKz4/6izIeIRGevTBBhm/U3Nmq//6R31Q4MCVbPV0z5lsCHRcUt0p++Govv2nNc4UFqMl504erFuU9sW8UeRdo7sNaJz+elRDyvV2ap2NqYABtfHQdU= 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=GB6xdQav; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GB6xdQav" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-41ba1ba55e8so24805675e9.1; Mon, 29 Apr 2024 12:01:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714417262; x=1715022062; 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=Red/pDio/w2Qf/LzYh3/cV5la/dSjroNao1MDcKrofI=; b=GB6xdQav2A5KKGlVxDbSOUzU9cX94dUR4NXGYc69D1z3NTByFZ1Um9YhQDternMcvN PqHRHRSPZvM59SanRkIaYtlXPjVDOY31ZAaqNO5I40xY5JQnKr2BLSxhkd9EjrNAEybh FduCsK+QQVXrHXwLQqMuAiyj8/XLGba2r/XAyAr+4s47ykj8cjTOzVMA+52cb2R072SW C2rjw0GNNyK71Xem0419xulJSXLfZ7KFlXAkVmBiDvN+u4vcpjpIALYGXKPhQSvTudEL wVR86M5maUFTvXMlMwBbgEUF2/rR7JblZWHLya6LcblSAknTyHSkF4UrZFrUKa5k10ME 7A4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714417262; x=1715022062; 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=Red/pDio/w2Qf/LzYh3/cV5la/dSjroNao1MDcKrofI=; b=bk5TEYr5h5p9W+eKn0d/2WcUG7xzxraRhnLZ9WJpek9Xl7cH77ifG8mtV/I9DsMhJe wtqt8XFNShhgo3L6IKhojsrLb/z5uXLhKdTJ16vgJV4rLpTaijgxigozyw+l1/fRytTX q8sq8NvTgz8DXnr1XrJaT1WnP4YlrC1XELD54B16Jr2saXDYONf8ZA2pHdTxuFA8s9tY MQdZngWmIG63rtNljdZhrymP4VObxeNbEue+hghnrESMxT4r2uxRPGHXJbYu81WfXyBW quFJ6pqOzKJkK2oW0J8zlfT+VjPMcMObbJjb+X5vHh/OUporM2Fy2o87RxkEdCsi6DLO zCBQ== X-Forwarded-Encrypted: i=1; AJvYcCVVRA0uVocnRuTaM1YgTizMm6llJG23ZQqOw9eMCCvcocRUqUKTG3WZlTvrvkGjStvc45yrmRLoGKOMMnGhwkDZpvMD4T2SOGvkCxn987L5N6U7FaNw05Cds54Gh2C49r/7Hu6qT8sd X-Gm-Message-State: AOJu0Yz/AcLT1yFfdMymz09IkriIV+c3kEB6wmkwSOBqpoxBgThktDkY w1Nhqfn7zpUiGoUfQL2k0RwkqV5uaoPJ933KFBwUaLhMCwgcZ41W X-Google-Smtp-Source: AGHT+IFTaKaPF8v7IF8APw16pwoa+pMny0mbHJOCE6KMF4+X92iL8bQGrpYGrWpXEYGmKytihixt1g== X-Received: by 2002:adf:e487:0:b0:34c:d63a:aa20 with SMTP id i7-20020adfe487000000b0034cd63aaa20mr465102wrm.19.1714417262069; Mon, 29 Apr 2024 12:01:02 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:abbf:c98a:cf84:d14c]) by smtp.gmail.com with ESMTPSA id x2-20020adfdd82000000b0034c78bba70bsm8469456wrl.72.2024.04.29.12.01.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 12:01:01 -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, phil@raspberrypi.com, 579lpy@gmail.com, linus.walleij@linaro.org, semen.protsenko@linaro.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Vasileios Amoiridis Subject: [PATCH v5 05/10] iio: pressure: bmp280: Make return values consistent Date: Mon, 29 Apr 2024 21:00:41 +0200 Message-Id: <20240429190046.24252-6-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240429190046.24252-1-vassilisamir@gmail.com> References: <20240429190046.24252-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Throughout the driver there are quite a few places were return values are treated as errors if they are negative or not-zero. This commit tries to make the return values of those functions consistent and treat them as errors in case there is a negative value since the vast majority of the functions are returning erorrs coming from regmap_*() functions. While at it, add error messages that were not implemented before. Finally, remove any extra error checks that are dead code. Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-core.c | 175 ++++++++++++++++------------- 1 file changed, 96 insertions(+), 79 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index ed49e0779d41..8290028824e9 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -222,10 +222,8 @@ static int bme280_read_calib(struct bmp280_data *data) /* Load shared calibration params with bmp280 first */ ret = bmp280_read_calib(data); - if (ret < 0) { - dev_err(dev, "failed to read calibration parameters\n"); + if (ret < 0) return ret; - } /* * Read humidity calibration values. @@ -552,7 +550,7 @@ static int bme280_write_oversampling_ratio_humid(struct bmp280_data *data, data->oversampling_humid = ilog2(val); ret = data->chip_info->chip_config(data); - if (ret) { + if (ret < 0) { data->oversampling_humid = prev; data->chip_info->chip_config(data); return ret; @@ -577,7 +575,7 @@ static int bmp280_write_oversampling_ratio_temp(struct bmp280_data *data, data->oversampling_temp = ilog2(val); ret = data->chip_info->chip_config(data); - if (ret) { + if (ret < 0) { data->oversampling_temp = prev; data->chip_info->chip_config(data); return ret; @@ -602,7 +600,7 @@ static int bmp280_write_oversampling_ratio_press(struct bmp280_data *data, data->oversampling_press = ilog2(val); ret = data->chip_info->chip_config(data); - if (ret) { + if (ret < 0) { data->oversampling_press = prev; data->chip_info->chip_config(data); return ret; @@ -627,7 +625,7 @@ static int bmp280_write_sampling_frequency(struct bmp280_data *data, data->sampling_freq = i; ret = data->chip_info->chip_config(data); - if (ret) { + if (ret < 0) { data->sampling_freq = prev; data->chip_info->chip_config(data); return ret; @@ -651,7 +649,7 @@ static int bmp280_write_iir_filter_coeffs(struct bmp280_data *data, int val) data->iir_filter_coeff = i; ret = data->chip_info->chip_config(data); - if (ret) { + if (ret < 0) { data->iir_filter_coeff = prev; data->chip_info->chip_config(data); return ret; @@ -841,8 +839,10 @@ static int bme280_chip_config(struct bmp280_data *data) */ ret = regmap_update_bits(data->regmap, BME280_REG_CTRL_HUMIDITY, BME280_OSRS_HUMIDITY_MASK, osrs); - if (ret < 0) + if (ret < 0) { + dev_err(data->dev, "failed to set humidity oversampling"); return ret; + } return bmp280_chip_config(data); } @@ -892,7 +892,7 @@ static int bmp380_cmd(struct bmp280_data *data, u8 cmd) /* Check if device is ready to process a command */ ret = regmap_read(data->regmap, BMP380_REG_STATUS, ®); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to read error register\n"); return ret; } @@ -903,7 +903,7 @@ static int bmp380_cmd(struct bmp280_data *data, u8 cmd) /* Send command to process */ ret = regmap_write(data->regmap, BMP380_REG_CMD, cmd); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to send command to device\n"); return ret; } @@ -911,7 +911,7 @@ static int bmp380_cmd(struct bmp280_data *data, u8 cmd) usleep_range(data->start_up_time, data->start_up_time + 100); /* Check for command processing error */ ret = regmap_read(data->regmap, BMP380_REG_ERROR, ®); - if (ret) { + if (ret < 0) { dev_err(data->dev, "error reading ERROR reg\n"); return ret; } @@ -1003,7 +1003,7 @@ static int bmp380_read_temp(struct bmp280_data *data, int *val, int *val2) ret = regmap_bulk_read(data->regmap, BMP380_REG_TEMP_XLSB, data->buf, sizeof(data->buf)); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to read temperature\n"); return ret; } @@ -1036,12 +1036,12 @@ static int bmp380_read_press(struct bmp280_data *data, int *val, int *val2) /* Read and compensate for temperature so we get a reading of t_fine */ ret = bmp380_read_temp(data, NULL, NULL); - if (ret) + if (ret < 0) return ret; ret = regmap_bulk_read(data->regmap, BMP380_REG_PRESS_XLSB, data->buf, sizeof(data->buf)); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to read pressure\n"); return ret; } @@ -1069,9 +1069,9 @@ static int bmp380_read_calib(struct bmp280_data *data) ret = regmap_bulk_read(data->regmap, BMP380_REG_CALIB_TEMP_START, data->bmp380_cal_buf, sizeof(data->bmp380_cal_buf)); - if (ret) { + if (ret < 0) { dev_err(data->dev, - "failed to read temperature calibration parameters\n"); + "failed to read calibration parameters\n"); return ret; } @@ -1137,7 +1137,7 @@ static int bmp380_chip_config(struct bmp280_data *data) BMP380_CTRL_SENSORS_MASK, BMP380_CTRL_SENSORS_PRESS_EN | BMP380_CTRL_SENSORS_TEMP_EN); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to write operation control register\n"); return ret; @@ -1151,7 +1151,7 @@ static int bmp380_chip_config(struct bmp280_data *data) BMP380_OSRS_TEMP_MASK | BMP380_OSRS_PRESS_MASK, osrs, &aux); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to write oversampling register\n"); return ret; } @@ -1161,7 +1161,7 @@ static int bmp380_chip_config(struct bmp280_data *data) ret = regmap_update_bits_check(data->regmap, BMP380_REG_ODR, BMP380_ODRS_MASK, data->sampling_freq, &aux); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to write ODR selection register\n"); return ret; } @@ -1171,7 +1171,7 @@ static int bmp380_chip_config(struct bmp280_data *data) ret = regmap_update_bits_check(data->regmap, BMP380_REG_CONFIG, BMP380_FILTER_MASK, FIELD_PREP(BMP380_FILTER_MASK, data->iir_filter_coeff), &aux); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to write config register\n"); return ret; } @@ -1190,7 +1190,7 @@ static int bmp380_chip_config(struct bmp280_data *data) ret = regmap_write_bits(data->regmap, BMP380_REG_POWER_CONTROL, BMP380_MODE_MASK, FIELD_PREP(BMP380_MODE_MASK, BMP380_MODE_SLEEP)); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to set sleep mode\n"); return ret; } @@ -1198,7 +1198,7 @@ static int bmp380_chip_config(struct bmp280_data *data) ret = regmap_write_bits(data->regmap, BMP380_REG_POWER_CONTROL, BMP380_MODE_MASK, FIELD_PREP(BMP380_MODE_MASK, BMP380_MODE_NORMAL)); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to set normal mode\n"); return ret; } @@ -1211,7 +1211,7 @@ static int bmp380_chip_config(struct bmp280_data *data) /* Check config error flag */ ret = regmap_read(data->regmap, BMP380_REG_ERROR, &tmp); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to read error register\n"); return ret; } @@ -1269,7 +1269,7 @@ static int bmp580_soft_reset(struct bmp280_data *data) int ret; ret = regmap_write(data->regmap, BMP580_REG_CMD, BMP580_CMD_SOFT_RESET); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to send reset command to device\n"); return ret; } @@ -1277,13 +1277,13 @@ static int bmp580_soft_reset(struct bmp280_data *data) /* Dummy read of chip_id */ ret = regmap_read(data->regmap, BMP580_REG_CHIP_ID, ®); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to reestablish comms after reset\n"); return ret; } ret = regmap_read(data->regmap, BMP580_REG_INT_STATUS, ®); - if (ret) { + if (ret < 0) { dev_err(data->dev, "error reading interrupt status register\n"); return ret; } @@ -1308,7 +1308,7 @@ static int bmp580_nvm_operation(struct bmp280_data *data, bool is_write) /* Check NVM ready flag */ ret = regmap_read(data->regmap, BMP580_REG_STATUS, ®); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to check nvm status\n"); return ret; } @@ -1320,7 +1320,7 @@ static int bmp580_nvm_operation(struct bmp280_data *data, bool is_write) /* Start NVM operation sequence */ ret = regmap_write(data->regmap, BMP580_REG_CMD, BMP580_CMD_NVM_OP_SEQ_0); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to send nvm operation's first sequence\n"); return ret; @@ -1329,7 +1329,7 @@ static int bmp580_nvm_operation(struct bmp280_data *data, bool is_write) /* Send NVM write sequence */ ret = regmap_write(data->regmap, BMP580_REG_CMD, BMP580_CMD_NVM_WRITE_SEQ_1); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to send nvm write sequence\n"); return ret; @@ -1341,7 +1341,7 @@ static int bmp580_nvm_operation(struct bmp280_data *data, bool is_write) /* Send NVM read sequence */ ret = regmap_write(data->regmap, BMP580_REG_CMD, BMP580_CMD_NVM_READ_SEQ_1); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to send nvm read sequence\n"); return ret; @@ -1350,16 +1350,12 @@ static int bmp580_nvm_operation(struct bmp280_data *data, bool is_write) poll = 50; timeout = 400; } - if (ret) { - dev_err(data->dev, "failed to write command sequence\n"); - return -EIO; - } /* Wait until NVM is ready again */ ret = regmap_read_poll_timeout(data->regmap, BMP580_REG_STATUS, reg, (reg & BMP580_STATUS_NVM_RDY_MASK), poll, timeout); - if (ret) { + if (ret < 0) { dev_err(data->dev, "error checking nvm operation status\n"); return ret; } @@ -1386,7 +1382,7 @@ static int bmp580_read_temp(struct bmp280_data *data, int *val, int *val2) ret = regmap_bulk_read(data->regmap, BMP580_REG_TEMP_XLSB, data->buf, sizeof(data->buf)); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to read temperature\n"); return ret; } @@ -1414,7 +1410,7 @@ static int bmp580_read_press(struct bmp280_data *data, int *val, int *val2) ret = regmap_bulk_read(data->regmap, BMP580_REG_PRESS_XLSB, data->buf, sizeof(data->buf)); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to read pressure\n"); return ret; } @@ -1485,7 +1481,7 @@ static int bmp580_nvmem_read(void *priv, unsigned int offset, void *val, BMP580_MODE_MASK | BMP580_ODR_DEEPSLEEP_DIS, BMP580_ODR_DEEPSLEEP_DIS | FIELD_PREP(BMP580_MODE_MASK, BMP580_MODE_SLEEP)); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to change sensor to standby mode\n"); goto exit; } @@ -1497,18 +1493,18 @@ static int bmp580_nvmem_read(void *priv, unsigned int offset, void *val, ret = regmap_write(data->regmap, BMP580_REG_NVM_ADDR, FIELD_PREP(BMP580_NVM_ROW_ADDR_MASK, addr)); - if (ret) { + if (ret < 0) { dev_err(data->dev, "error writing nvm address\n"); goto exit; } ret = bmp580_nvm_operation(data, false); - if (ret) + if (ret < 0) goto exit; ret = regmap_bulk_read(data->regmap, BMP580_REG_NVM_DATA_LSB, &data->le16, sizeof(data->le16)); - if (ret) { + if (ret < 0) { dev_err(data->dev, "error reading nvm data regs\n"); goto exit; } @@ -1541,7 +1537,7 @@ static int bmp580_nvmem_write(void *priv, unsigned int offset, void *val, BMP580_MODE_MASK | BMP580_ODR_DEEPSLEEP_DIS, BMP580_ODR_DEEPSLEEP_DIS | FIELD_PREP(BMP580_MODE_MASK, BMP580_MODE_SLEEP)); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to change sensor to standby mode\n"); goto exit; } @@ -1554,7 +1550,7 @@ static int bmp580_nvmem_write(void *priv, unsigned int offset, void *val, ret = regmap_write(data->regmap, BMP580_REG_NVM_ADDR, BMP580_NVM_PROG_EN | FIELD_PREP(BMP580_NVM_ROW_ADDR_MASK, addr)); - if (ret) { + if (ret < 0) { dev_err(data->dev, "error writing nvm address\n"); goto exit; } @@ -1562,19 +1558,19 @@ static int bmp580_nvmem_write(void *priv, unsigned int offset, void *val, ret = regmap_bulk_write(data->regmap, BMP580_REG_NVM_DATA_LSB, &data->le16, sizeof(data->le16)); - if (ret) { + if (ret < 0) { dev_err(data->dev, "error writing LSB NVM data regs\n"); goto exit; } ret = bmp580_nvm_operation(data, true); - if (ret) + if (ret < 0) goto exit; /* Disable programming mode bit */ ret = regmap_update_bits(data->regmap, BMP580_REG_NVM_ADDR, BMP580_NVM_PROG_EN, 0); - if (ret) { + if (ret < 0) { dev_err(data->dev, "error resetting nvm write\n"); goto exit; } @@ -1608,25 +1604,29 @@ static int bmp580_preinit(struct bmp280_data *data) /* Issue soft-reset command */ ret = bmp580_soft_reset(data); - if (ret) + if (ret < 0) return ret; /* Post powerup sequence */ ret = regmap_read(data->regmap, BMP580_REG_CHIP_ID, ®); - if (ret) + if (ret < 0) { + dev_err(data->dev, "failed to establish comms with the chip\n"); return ret; + } /* Print warn message if we don't know the chip id */ if (reg != BMP580_CHIP_ID && reg != BMP580_CHIP_ID_ALT) - dev_warn(data->dev, "preinit: unexpected chip_id\n"); + dev_warn(data->dev, "unexpected chip_id\n"); ret = regmap_read(data->regmap, BMP580_REG_STATUS, ®); - if (ret) + if (ret < 0) { + dev_err(data->dev, "failed to read nvm status\n"); return ret; + } /* Check nvm status */ if (!(reg & BMP580_STATUS_NVM_RDY_MASK) || (reg & BMP580_STATUS_NVM_ERR_MASK)) { - dev_err(data->dev, "preinit: nvm error on powerup sequence\n"); + dev_err(data->dev, "nvm error on powerup sequence\n"); return -EIO; } @@ -1646,7 +1646,7 @@ static int bmp580_chip_config(struct bmp280_data *data) BMP580_MODE_MASK | BMP580_ODR_DEEPSLEEP_DIS, BMP580_ODR_DEEPSLEEP_DIS | FIELD_PREP(BMP580_MODE_MASK, BMP580_MODE_SLEEP)); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to change sensor to standby mode\n"); return ret; } @@ -1661,6 +1661,10 @@ static int bmp580_chip_config(struct bmp280_data *data) BMP580_DSP_COMP_MASK | BMP580_DSP_SHDW_IIR_TEMP_EN | BMP580_DSP_SHDW_IIR_PRESS_EN, reg_val); + if (ret < 0) { + dev_err(data->dev, "failed to change DSP mode settings\n"); + return ret; + } /* Configure oversampling */ reg_val = FIELD_PREP(BMP580_OSR_TEMP_MASK, data->oversampling_temp) | @@ -1672,7 +1676,7 @@ static int bmp580_chip_config(struct bmp280_data *data) BMP580_OSR_PRESS_MASK | BMP580_OSR_PRESS_EN, reg_val, &aux); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to write oversampling register\n"); return ret; } @@ -1682,7 +1686,7 @@ static int bmp580_chip_config(struct bmp280_data *data) ret = regmap_update_bits_check(data->regmap, BMP580_REG_ODR_CONFIG, BMP580_ODR_MASK, FIELD_PREP(BMP580_ODR_MASK, data->sampling_freq), &aux); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to write ODR configuration register\n"); return ret; } @@ -1696,7 +1700,7 @@ static int bmp580_chip_config(struct bmp280_data *data) BMP580_DSP_IIR_PRESS_MASK | BMP580_DSP_IIR_TEMP_MASK, reg_val, &aux); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to write config register\n"); return ret; } @@ -1706,7 +1710,7 @@ static int bmp580_chip_config(struct bmp280_data *data) ret = regmap_write_bits(data->regmap, BMP580_REG_ODR_CONFIG, BMP580_MODE_MASK, FIELD_PREP(BMP580_MODE_MASK, BMP580_MODE_NORMAL)); - if (ret) { + if (ret < 0) { dev_err(data->dev, "failed to set normal mode\n"); return ret; } @@ -1719,7 +1723,7 @@ static int bmp580_chip_config(struct bmp280_data *data) * operating in a degraded mode. */ ret = regmap_read(data->regmap, BMP580_REG_EFF_OSR, &tmp); - if (ret) { + if (ret < 0) { dev_err(data->dev, "error reading effective OSR register\n"); return ret; @@ -1782,8 +1786,10 @@ static int bmp180_wait_for_eoc(struct bmp280_data *data, u8 ctrl_meas) reinit_completion(&data->done); ret = regmap_write(data->regmap, BMP280_REG_CTRL_MEAS, ctrl_meas); - if (ret) + if (ret < 0) { + dev_err(data->dev, "failed to write crtl_meas register\n"); return ret; + } if (data->use_eoc) { /* @@ -1806,12 +1812,16 @@ static int bmp180_wait_for_eoc(struct bmp280_data *data, u8 ctrl_meas) } ret = regmap_read(data->regmap, BMP280_REG_CTRL_MEAS, &ctrl); - if (ret) + if (ret < 0) { + dev_err(data->dev, "failed to read ctrl_meas register\n"); return ret; + } /* The value of this bit reset to "0" after conversion is complete */ - if (ctrl & BMP180_MEAS_SCO) + if (ctrl & BMP180_MEAS_SCO) { + dev_err(data->dev, "conversion didn't complete\n"); return -EIO; + } return 0; } @@ -1823,13 +1833,15 @@ static int bmp180_read_adc_temp(struct bmp280_data *data, int *val) ret = bmp180_wait_for_eoc(data, FIELD_PREP(BMP180_MEAS_CTRL_MASK, BMP180_MEAS_TEMP) | BMP180_MEAS_SCO); - if (ret) + if (ret < 0) return ret; ret = regmap_bulk_read(data->regmap, BMP180_REG_OUT_MSB, &data->be16, sizeof(data->be16)); - if (ret) + if (ret < 0) { + dev_err(data->dev, "failed to read temperature\n"); return ret; + } *val = be16_to_cpu(data->be16); @@ -1844,9 +1856,10 @@ static int bmp180_read_calib(struct bmp280_data *data) ret = regmap_bulk_read(data->regmap, BMP180_REG_CALIB_START, data->bmp180_cal_buf, sizeof(data->bmp180_cal_buf)); - - if (ret < 0) + if (ret < 0) { + dev_err(data->dev, "failed to read calibration parameters\n"); return ret; + } /* None of the words has the value 0 or 0xFFFF */ for (i = 0; i < ARRAY_SIZE(data->bmp180_cal_buf); i++) { @@ -1898,7 +1911,7 @@ static int bmp180_read_temp(struct bmp280_data *data, int *val, int *val2) int ret; ret = bmp180_read_adc_temp(data, &adc_temp); - if (ret) + if (ret < 0) return ret; comp_temp = bmp180_compensate_temp(data, adc_temp); @@ -1924,13 +1937,15 @@ static int bmp180_read_adc_press(struct bmp280_data *data, int *val) FIELD_PREP(BMP180_MEAS_CTRL_MASK, BMP180_MEAS_PRESS) | FIELD_PREP(BMP180_OSRS_PRESS_MASK, oss) | BMP180_MEAS_SCO); - if (ret) + if (ret < 0) return ret; ret = regmap_bulk_read(data->regmap, BMP180_REG_OUT_MSB, data->buf, sizeof(data->buf)); - if (ret) + if (ret < 0) { + dev_err(data->dev, "failed to read pressure\n"); return ret; + } *val = get_unaligned_be24(data->buf) >> (8 - oss); @@ -1980,11 +1995,11 @@ static int bmp180_read_press(struct bmp280_data *data, int *val, int *val2) /* Read and compensate temperature so we get a reading of t_fine. */ ret = bmp180_read_temp(data, NULL, NULL); - if (ret) + if (ret < 0) return ret; ret = bmp180_read_adc_press(data, &adc_press); - if (ret) + if (ret < 0) return ret; comp_press = bmp180_compensate_press(data, adc_press); @@ -2062,7 +2077,7 @@ static int bmp085_fetch_eoc_irq(struct device *dev, irq_trig, name, data); - if (ret) { + if (ret < 0) { /* Bail out without IRQ but keep the driver in place */ dev_err(dev, "unable to request DRDY IRQ\n"); return 0; @@ -2132,20 +2147,20 @@ int bmp280_common_probe(struct device *dev, ret = devm_regulator_bulk_get(dev, BMP280_NUM_SUPPLIES, data->supplies); - if (ret) { + if (ret < 0) { dev_err(dev, "failed to get regulators\n"); return ret; } ret = regulator_bulk_enable(BMP280_NUM_SUPPLIES, data->supplies); - if (ret) { + if (ret < 0) { dev_err(dev, "failed to enable regulators\n"); return ret; } ret = devm_add_action_or_reset(dev, bmp280_regulators_disable, data->supplies); - if (ret) + if (ret < 0) return ret; /* Wait to make sure we started up properly */ @@ -2162,8 +2177,10 @@ int bmp280_common_probe(struct device *dev, data->regmap = regmap; ret = regmap_read(regmap, data->chip_info->id_reg, &chip_id); - if (ret < 0) + if (ret < 0) { + dev_err(data->dev, "failed to read chip id\n"); return ret; + } for (i = 0; i < data->chip_info->num_chip_id; i++) { if (chip_id == data->chip_info->chip_id[i]) { @@ -2177,7 +2194,7 @@ int bmp280_common_probe(struct device *dev, if (data->chip_info->preinit) { ret = data->chip_info->preinit(data); - if (ret) + if (ret < 0) return dev_err_probe(data->dev, ret, "error running preinit tasks\n"); } @@ -2208,7 +2225,7 @@ int bmp280_common_probe(struct device *dev, */ if (irq > 0 && (chip_id == BMP180_CHIP_ID)) { ret = bmp085_fetch_eoc_irq(dev, name, irq, data); - if (ret) + if (ret < 0) return ret; } @@ -2225,7 +2242,7 @@ int bmp280_common_probe(struct device *dev, pm_runtime_put(dev); ret = devm_add_action_or_reset(dev, bmp280_pm_disable, dev); - if (ret) + if (ret < 0) return ret; return devm_iio_device_register(dev, indio_dev); @@ -2247,7 +2264,7 @@ static int bmp280_runtime_resume(struct device *dev) int ret; ret = regulator_bulk_enable(BMP280_NUM_SUPPLIES, data->supplies); - if (ret) + if (ret < 0) return ret; usleep_range(data->start_up_time, data->start_up_time + 100); From patchwork Mon Apr 29 19:00:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13647526 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 600AF13C3EA; Mon, 29 Apr 2024 19:01:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714417269; cv=none; b=KTHab9DMORvWYhuetcV2heZGpyre46C/VxypJ6oCa1HWCW6jFAYOz8dBQn77TM1WUTKAJpgIqVwr64AtnDeWeM5nKs/RrraWwmACnQX3vyldjgKTA+8JG5s8Q640kOdixLH2FG3R2gtjX/tyhYnfdjEvlbHGq0eHTPkK1MRiU9k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714417269; c=relaxed/simple; bh=FQ834MkUHmcBNDaCmnN/SB+UjZtSdHWN30xnAKSQS7E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qKkwJ0WqrfN+aJXQ8jX9wBmAOxqSoLQHQdyloWVz3hEsb/N4htdO3tSpQ/ibaA7oiJZ11Mi5jQOoB8NTQWTF/MzXkRk1tOsak95HnNLIRFD4dj67b/swwO5+nXzTSfg6k8nX7hD50SunUU40aesxBJ6hCOmpofsGuvPOu1iSbo0= 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=aauxvmO6; arc=none smtp.client-ip=209.85.221.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aauxvmO6" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-343e46ec237so4085015f8f.2; Mon, 29 Apr 2024 12:01:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714417264; x=1715022064; 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=t3/iBXzdIz072pW4p/5iTz4vzAGpD6zPyh8wNEc+ajY=; b=aauxvmO6HlmUBuhfTGgRpuoainpYuArWf3LJvklOzai2mDST7epV0ml+MU8a3kwG4A GuXc5BLMUqcNSCTb+k/H0DIzHQ4kEQWyO8TmhZlPNpb8EOXUw2+RoDoueZ/zTgSw2sgG 7DVcSSD/cJPaoBsEK7go6aeRHHdgCId6gJ5g9fmuU2lytM9fsh5PhCPM/TWNPU4AHB3e YOhhWtxbliJZ1cSQlqc/SzuCsg4Q52PIeWUSJZV38RhAZRpllHCxCK8vqeHebPd4yLMD KG7rscRDsX971nhaHmmJ2MQHzmy36gbmCWe919DnkxEE9cH+JlVtm/eeEx/FUl7zLl/p OXgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714417264; x=1715022064; 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=t3/iBXzdIz072pW4p/5iTz4vzAGpD6zPyh8wNEc+ajY=; b=ZSkb2jiBdtoZtMfmqpzXa5h0WsVjJPPpWgqFSw4Pr4PM/BIjPyldqxMSXSgzKLQxmK uAXT3NMZOZGWhZXO+tqcsNIcSq0/MkPp6Js0/Isb5LzwQVM9WeDHVo5ezRXIDlAtM7NV ds2aj7W9JndyBdvY0tPmdGmkrnaH2ryKyYo8jfhqhsPWE/qq/McHRgjAL0Og8x/aDS9H P1FAl2qIwgKXaRU1/WPatfS0LEsN7js6wRrsTsi2i1e5RNfqOZx8AnSoVO/rjn9hejOK b/E6Vs37Eqf0GZUlZZJ2g8y1jVxml/MVpxroLly4ILEH7xaX34PKpr3Gwbe8UEZQCPHZ rPLw== X-Forwarded-Encrypted: i=1; AJvYcCUMKj8yLUNGr74/grQH0PkTXJUyrqP9eol+21mDUnZVkcy8T9udYEvkACpLy9xKy8NeBOJjp2Rm29/pvdxJKmJlpkQLwjTGIJpqbUwjXuotWbZyHu+NRvgEfH0jk9MPEsAHDfKy8TRP X-Gm-Message-State: AOJu0Yzi+lCds8DtW5cYJGwPsB5siL43IJuIrZ/dPfalhtvpIQS6tCXU Xh0MoQLETCHw2NTof0W+CMoCKkJYpnRi9GREQ06V4CY+eYVht0lj X-Google-Smtp-Source: AGHT+IEu3a96lk1ZlSvcb1+ofUEoW3P6yFb7F4kj2qTiAvyWUf5z6NluW2j9KsepTuI2xuvmkxMeaQ== X-Received: by 2002:a05:6000:506:b0:34a:3f3d:bb14 with SMTP id a6-20020a056000050600b0034a3f3dbb14mr5993297wrf.27.1714417263259; Mon, 29 Apr 2024 12:01:03 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:abbf:c98a:cf84:d14c]) by smtp.gmail.com with ESMTPSA id x2-20020adfdd82000000b0034c78bba70bsm8469456wrl.72.2024.04.29.12.01.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 12:01:02 -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, phil@raspberrypi.com, 579lpy@gmail.com, linus.walleij@linaro.org, semen.protsenko@linaro.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Vasileios Amoiridis , Jonathan Cameron Subject: [PATCH v5 06/10] iio: pressure: bmp280: Refactorize reading functions Date: Mon, 29 Apr 2024 21:00:42 +0200 Message-Id: <20240429190046.24252-7-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240429190046.24252-1-vassilisamir@gmail.com> References: <20240429190046.24252-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For BMP18x, BMP28x, BME280, BMP38x the reading of the pressure value requires an update of the t_fine variable which happens through reading the temperature value. So all the bmpxxx_read_press() functions of the above sensors are internally calling the equivalent bmpxxx_read_temp() function in order to update the t_fine value. By just looking at the code this functionality is a bit hidden and is not easy to understand why those channels are not independent. This commit tries to clear these things a bit by splitting the bmpxxx_{read/compensate}_{temp/press/humid}() to the following: i. bmpxxx_read_{temp/press/humid}_adc(): read the raw value from the sensor. ii. bmpxx_calc_t_fine(): calculate the t_fine variable. iii. bmpxxx_get_t_fine(): get the t_fine variable. iv. bmpxxx_compensate_{temp/press/humid}(): compensate the adc values and return the calculated value. v. bmpxxx_read_{temp/press/humid}(): combine calls of the aforementioned functions to return the requested value. Suggested-by: Jonathan Cameron Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-core.c | 351 ++++++++++++++++++----------- drivers/iio/pressure/bmp280.h | 6 - 2 files changed, 221 insertions(+), 136 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 8290028824e9..5ebce38e99f6 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -288,13 +288,33 @@ static int bme280_read_calib(struct bmp280_data *data) * * Taken from BME280 datasheet, Section 4.2.3, "Compensation formula". */ +static int bme280_read_humid_adc(struct bmp280_data *data, s32 *adc_humidity) +{ + int ret; + + ret = regmap_bulk_read(data->regmap, BME280_REG_HUMIDITY_MSB, + &data->be16, sizeof(data->be16)); + if (ret < 0) { + dev_err(data->dev, "failed to read humidity\n"); + return ret; + } + + *adc_humidity = be16_to_cpu(data->be16); + if (*adc_humidity == BMP280_HUMIDITY_SKIPPED) { + dev_err(data->dev, "reading humidity skipped\n"); + return -EIO; + } + + return 0; +} + static u32 bme280_compensate_humidity(struct bmp280_data *data, - s32 adc_humidity) + s32 adc_humidity, s32 t_fine) { struct bmp280_calib *calib = &data->calib.bmp280; s32 var; - var = ((s32)data->t_fine) - (s32)76800; + var = ((s32)t_fine) - (s32)76800; var = ((((adc_humidity << 14) - (calib->H4 << 20) - (calib->H5 * var)) + (s32)16384) >> 15) * (((((((var * calib->H6) >> 10) * (((var * (s32)calib->H3) >> 11) + (s32)32768)) >> 10) @@ -313,8 +333,27 @@ static u32 bme280_compensate_humidity(struct bmp280_data *data, * * Taken from datasheet, Section 3.11.3, "Compensation formula". */ -static s32 bmp280_compensate_temp(struct bmp280_data *data, - s32 adc_temp) +static int bmp280_read_temp_adc(struct bmp280_data *data, s32 *adc_temp) +{ + int ret; + + ret = regmap_bulk_read(data->regmap, BMP280_REG_TEMP_MSB, + data->buf, sizeof(data->buf)); + if (ret < 0) { + dev_err(data->dev, "failed to read temperature\n"); + return ret; + } + + *adc_temp = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(data->buf)); + if (*adc_temp == BMP280_TEMP_SKIPPED) { + dev_err(data->dev, "reading temperature skipped\n"); + return -EIO; + } + + return 0; +} + +static s32 bmp280_calc_t_fine(struct bmp280_data *data, s32 adc_temp) { struct bmp280_calib *calib = &data->calib.bmp280; s32 var1, var2; @@ -324,9 +363,26 @@ static s32 bmp280_compensate_temp(struct bmp280_data *data, var2 = (((((adc_temp >> 4) - ((s32)calib->T1)) * ((adc_temp >> 4) - ((s32)calib->T1))) >> 12) * ((s32)calib->T3)) >> 14; - data->t_fine = var1 + var2; + return var1 + var2; /* t_fine = var1 + var2 */ +} + +static int bmp280_get_t_fine(struct bmp280_data *data, s32 *t_fine) +{ + s32 adc_temp; + int ret; + + ret = bmp280_read_temp_adc(data, &adc_temp); + if (ret < 0) + return ret; + + *t_fine = bmp280_calc_t_fine(data, adc_temp); - return (data->t_fine * 5 + 128) >> 8; + return 0; +} + +static s32 bmp280_compensate_temp(struct bmp280_data *data, s32 adc_temp) +{ + return (bmp280_calc_t_fine(data, adc_temp) * 5 + 128) / 256; } /* @@ -336,13 +392,33 @@ static s32 bmp280_compensate_temp(struct bmp280_data *data, * * Taken from datasheet, Section 3.11.3, "Compensation formula". */ +static int bmp280_read_press_adc(struct bmp280_data *data, s32 *adc_press) +{ + int ret; + + ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB, + data->buf, sizeof(data->buf)); + if (ret < 0) { + dev_err(data->dev, "failed to read pressure\n"); + return ret; + } + + *adc_press = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(data->buf)); + if (*adc_press == BMP280_PRESS_SKIPPED) { + dev_err(data->dev, "reading pressure skipped\n"); + return -EIO; + } + + return 0; +} + static u32 bmp280_compensate_press(struct bmp280_data *data, - s32 adc_press) + s32 adc_press, s32 t_fine) { struct bmp280_calib *calib = &data->calib.bmp280; s64 var1, var2, p; - var1 = ((s64)data->t_fine) - 128000; + var1 = ((s64)t_fine) - 128000; var2 = var1 * var1 * (s64)calib->P6; var2 += (var1 * (s64)calib->P5) << 17; var2 += ((s64)calib->P4) << 35; @@ -368,60 +444,35 @@ static int bmp280_read_temp(struct bmp280_data *data, s32 adc_temp, comp_temp; int ret; - ret = regmap_bulk_read(data->regmap, BMP280_REG_TEMP_MSB, - data->buf, sizeof(data->buf)); - if (ret < 0) { - dev_err(data->dev, "failed to read temperature\n"); + ret = bmp280_read_temp_adc(data, &adc_temp); + if (ret < 0) return ret; - } - adc_temp = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(data->buf)); - if (adc_temp == BMP280_TEMP_SKIPPED) { - /* reading was skipped */ - dev_err(data->dev, "reading temperature skipped\n"); - return -EIO; - } 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; + /* IIO units are in milli Celsius */ + *val = comp_temp * 10; + return IIO_VAL_INT; } static int bmp280_read_press(struct bmp280_data *data, int *val, int *val2) { + s32 adc_press, t_fine; 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_get_t_fine(data, &t_fine); if (ret < 0) return ret; - ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB, - data->buf, sizeof(data->buf)); - if (ret < 0) { - dev_err(data->dev, "failed to read pressure\n"); + ret = bmp280_read_press_adc(data, &adc_press); + if (ret < 0) return ret; - } - adc_press = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(data->buf)); - if (adc_press == BMP280_PRESS_SKIPPED) { - /* reading was skipped */ - dev_err(data->dev, "reading pressure skipped\n"); - return -EIO; - } - comp_press = bmp280_compensate_press(data, adc_press); + comp_press = bmp280_compensate_press(data, adc_press, t_fine); + /* IIO units are in kPa */ *val = comp_press; *val2 = 256000; @@ -430,30 +481,21 @@ static int bmp280_read_press(struct bmp280_data *data, static int bme280_read_humid(struct bmp280_data *data, int *val, int *val2) { + s32 adc_humidity, t_fine; 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_get_t_fine(data, &t_fine); if (ret < 0) return ret; - ret = regmap_bulk_read(data->regmap, BME280_REG_HUMIDITY_MSB, - &data->be16, sizeof(data->be16)); - if (ret < 0) { - dev_err(data->dev, "failed to read humidity\n"); + ret = bme280_read_humid_adc(data, &adc_humidity); + if (ret < 0) return ret; - } - adc_humidity = be16_to_cpu(data->be16); - if (adc_humidity == BMP280_HUMIDITY_SKIPPED) { - /* reading was skipped */ - dev_err(data->dev, "reading humidity skipped\n"); - return -EIO; - } - comp_humidity = bme280_compensate_humidity(data, adc_humidity); + comp_humidity = bme280_compensate_humidity(data, adc_humidity, t_fine); + /* IIO units are in 1000 * % */ *val = comp_humidity * 1000 / 1024; return IIO_VAL_INT; @@ -930,9 +972,29 @@ static int bmp380_cmd(struct bmp280_data *data, u8 cmd) * Taken from datasheet, Section Appendix 9, "Compensation formula" and repo * https://github.com/BoschSensortec/BMP3-Sensor-API. */ -static s32 bmp380_compensate_temp(struct bmp280_data *data, u32 adc_temp) +static int bmp380_read_temp_adc(struct bmp280_data *data, u32 *adc_temp) +{ + int ret; + + ret = regmap_bulk_read(data->regmap, BMP380_REG_TEMP_XLSB, + data->buf, sizeof(data->buf)); + if (ret < 0) { + dev_err(data->dev, "failed to read temperature\n"); + return ret; + } + + *adc_temp = get_unaligned_le24(data->buf); + if (*adc_temp == BMP380_TEMP_SKIPPED) { + dev_err(data->dev, "reading temperature skipped\n"); + return -EIO; + } + + return 0; +} + +static s32 bmp380_calc_t_fine(struct bmp280_data *data, u32 adc_temp) { - s64 var1, var2, var3, var4, var5, var6, comp_temp; + s64 var1, var2, var3, var4, var5, var6; struct bmp380_calib *calib = &data->calib.bmp380; var1 = ((s64) adc_temp) - (((s64) calib->T1) << 8); @@ -941,7 +1003,29 @@ static s32 bmp380_compensate_temp(struct bmp280_data *data, u32 adc_temp) var4 = var3 * ((s64) calib->T3); var5 = (var2 << 18) + var4; var6 = var5 >> 32; - data->t_fine = (s32) var6; + return (s32) var6; /* t_fine = var6 */ +} + +static int bmp380_get_t_fine(struct bmp280_data *data, s32 *t_fine) +{ + s32 adc_temp; + int ret; + + ret = bmp380_read_temp_adc(data, &adc_temp); + if (ret < 0) + return ret; + + *t_fine = bmp380_calc_t_fine(data, adc_temp); + + return 0; +} + +static int bmp380_compensate_temp(struct bmp280_data *data, u32 adc_temp) +{ + s64 comp_temp; + s32 var6; + + var6 = bmp380_calc_t_fine(data, adc_temp); comp_temp = (var6 * 25) >> 14; comp_temp = clamp_val(comp_temp, BMP380_MIN_TEMP, BMP380_MAX_TEMP); @@ -955,27 +1039,48 @@ static s32 bmp380_compensate_temp(struct bmp280_data *data, u32 adc_temp) * Taken from datasheet, Section 9.3. "Pressure compensation" and repository * https://github.com/BoschSensortec/BMP3-Sensor-API. */ -static u32 bmp380_compensate_press(struct bmp280_data *data, u32 adc_press) +static int bmp380_read_press_adc(struct bmp280_data *data, u32 *adc_press) +{ + int ret; + + ret = regmap_bulk_read(data->regmap, BMP380_REG_PRESS_XLSB, + data->buf, sizeof(data->buf)); + if (ret < 0) { + dev_err(data->dev, "failed to read pressure\n"); + return ret; + } + + *adc_press = get_unaligned_le24(data->buf); + if (*adc_press == BMP380_PRESS_SKIPPED) { + dev_err(data->dev, "reading pressure skipped\n"); + return -EIO; + } + + return 0; +} + +static u32 bmp380_compensate_press(struct bmp280_data *data, + u32 adc_press, s32 t_fine) { s64 var1, var2, var3, var4, var5, var6, offset, sensitivity; struct bmp380_calib *calib = &data->calib.bmp380; u32 comp_press; - var1 = (s64)data->t_fine * (s64)data->t_fine; + var1 = (s64)t_fine * (s64)t_fine; var2 = var1 >> 6; - var3 = (var2 * ((s64) data->t_fine)) >> 8; + var3 = (var2 * ((s64) t_fine)) >> 8; var4 = ((s64)calib->P8 * var3) >> 5; var5 = ((s64)calib->P7 * var1) << 4; - var6 = ((s64)calib->P6 * (s64)data->t_fine) << 22; + var6 = ((s64)calib->P6 * (s64)t_fine) << 22; offset = ((s64)calib->P5 << 47) + var4 + var5 + var6; var2 = ((s64)calib->P4 * var3) >> 5; var4 = ((s64)calib->P3 * var1) << 2; var5 = ((s64)calib->P2 - ((s64)1 << 14)) * - ((s64)data->t_fine << 21); + ((s64)t_fine << 21); sensitivity = (((s64) calib->P1 - ((s64) 1 << 14)) << 46) + var2 + var4 + var5; var1 = (sensitivity >> 24) * (s64)adc_press; - var2 = (s64)calib->P10 * (s64)data->t_fine; + var2 = (s64)calib->P10 * (s64)t_fine; var3 = var2 + ((s64)calib->P9 << 16); var4 = (var3 * (s64)adc_press) >> 13; @@ -1001,60 +1106,34 @@ static int bmp380_read_temp(struct bmp280_data *data, int *val, int *val2) u32 adc_temp; int ret; - ret = regmap_bulk_read(data->regmap, BMP380_REG_TEMP_XLSB, - data->buf, sizeof(data->buf)); - if (ret < 0) { - dev_err(data->dev, "failed to read temperature\n"); + ret = bmp380_read_temp_adc(data, &adc_temp); + if (ret < 0) return ret; - } - adc_temp = get_unaligned_le24(data->buf); - if (adc_temp == BMP380_TEMP_SKIPPED) { - dev_err(data->dev, "reading temperature skipped\n"); - return -EIO; - } 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; + /* IIO units are in milli Celsius */ + *val = comp_temp * 10; + return IIO_VAL_INT; } static int bmp380_read_press(struct bmp280_data *data, int *val, int *val2) { - s32 comp_press; - u32 adc_press; + u32 adc_press, comp_press, t_fine; int ret; - /* Read and compensate for temperature so we get a reading of t_fine */ - ret = bmp380_read_temp(data, NULL, NULL); + ret = bmp380_get_t_fine(data, &t_fine); if (ret < 0) return ret; - ret = regmap_bulk_read(data->regmap, BMP380_REG_PRESS_XLSB, - data->buf, sizeof(data->buf)); - if (ret < 0) { - dev_err(data->dev, "failed to read pressure\n"); + ret = bmp380_read_press_adc(data, &adc_press); + if (ret < 0) return ret; - } - adc_press = get_unaligned_le24(data->buf); - if (adc_press == BMP380_PRESS_SKIPPED) { - dev_err(data->dev, "reading pressure skipped\n"); - return -EIO; - } - comp_press = bmp380_compensate_press(data, adc_press); + comp_press = bmp380_compensate_press(data, adc_press, t_fine); + /* IIO units are in kPa */ *val = comp_press; - /* Compensated pressure is in cPa (centipascals) */ *val2 = 100000; return IIO_VAL_FRACTIONAL; @@ -1826,7 +1905,7 @@ static int bmp180_wait_for_eoc(struct bmp280_data *data, u8 ctrl_meas) return 0; } -static int bmp180_read_adc_temp(struct bmp280_data *data, int *val) +static int bmp180_read_temp_adc(struct bmp280_data *data, s32 *adc_temp) { int ret; @@ -1843,7 +1922,7 @@ static int bmp180_read_adc_temp(struct bmp280_data *data, int *val) return ret; } - *val = be16_to_cpu(data->be16); + *adc_temp = be16_to_cpu(data->be16); return 0; } @@ -1893,16 +1972,34 @@ static int bmp180_read_calib(struct bmp280_data *data) * * Taken from datasheet, Section 3.5, "Calculating pressure and temperature". */ -static s32 bmp180_compensate_temp(struct bmp280_data *data, s32 adc_temp) + +static s32 bmp180_calc_t_fine(struct bmp280_data *data, s32 adc_temp) { struct bmp180_calib *calib = &data->calib.bmp180; s32 x1, x2; x1 = ((adc_temp - calib->AC6) * calib->AC5) >> 15; x2 = (calib->MC << 11) / (x1 + calib->MD); - data->t_fine = x1 + x2; + return x1 + x2; /* t_fine = x1 + x2; */ +} + +static int bmp180_get_t_fine(struct bmp280_data *data, s32 *t_fine) +{ + s32 adc_temp; + int ret; + + ret = bmp180_read_temp_adc(data, &adc_temp); + if (ret < 0) + return ret; + + *t_fine = bmp180_calc_t_fine(data, adc_temp); - return (data->t_fine + 8) >> 4; + return 0; +} + +static s32 bmp180_compensate_temp(struct bmp280_data *data, s32 adc_temp) +{ + return (bmp180_calc_t_fine(data, adc_temp) + 8) / 16; } static int bmp180_read_temp(struct bmp280_data *data, int *val, int *val2) @@ -1910,25 +2007,18 @@ static int bmp180_read_temp(struct bmp280_data *data, int *val, int *val2) s32 adc_temp, comp_temp; int ret; - ret = bmp180_read_adc_temp(data, &adc_temp); + ret = bmp180_read_temp_adc(data, &adc_temp); if (ret < 0) return ret; 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; + /* IIO units are in milli Celsius */ + *val = comp_temp * 100; + return IIO_VAL_INT; } -static int bmp180_read_adc_press(struct bmp280_data *data, int *val) +static int bmp180_read_press_adc(struct bmp280_data *data, s32 *adc_press) { u8 oss = data->oversampling_press; int ret; @@ -1947,7 +2037,7 @@ static int bmp180_read_adc_press(struct bmp280_data *data, int *val) return ret; } - *val = get_unaligned_be24(data->buf) >> (8 - oss); + *adc_press = get_unaligned_be24(data->buf) >> (8 - oss); return 0; } @@ -1957,7 +2047,8 @@ static int bmp180_read_adc_press(struct bmp280_data *data, int *val) * * Taken from datasheet, Section 3.5, "Calculating pressure and temperature". */ -static u32 bmp180_compensate_press(struct bmp280_data *data, s32 adc_press) +static u32 bmp180_compensate_press(struct bmp280_data *data, s32 adc_press, + s32 t_fine) { struct bmp180_calib *calib = &data->calib.bmp180; s32 oss = data->oversampling_press; @@ -1965,7 +2056,7 @@ static u32 bmp180_compensate_press(struct bmp280_data *data, s32 adc_press) s32 b3, b6; u32 b4, b7; - b6 = data->t_fine - 4000; + b6 = t_fine - 4000; x1 = (calib->B2 * (b6 * b6 >> 12)) >> 11; x2 = calib->AC2 * b6 >> 11; x3 = x1 + x2; @@ -1989,21 +2080,21 @@ static u32 bmp180_compensate_press(struct bmp280_data *data, s32 adc_press) static int bmp180_read_press(struct bmp280_data *data, int *val, int *val2) { + s32 adc_press, t_fine; 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_get_t_fine(data, &t_fine); if (ret < 0) return ret; - ret = bmp180_read_adc_press(data, &adc_press); + ret = bmp180_read_press_adc(data, &adc_press); if (ret < 0) return ret; - comp_press = bmp180_compensate_press(data, adc_press); + comp_press = bmp180_compensate_press(data, adc_press, t_fine); + /* IIO units are in kPa */ *val = comp_press; *val2 = 1000; diff --git a/drivers/iio/pressure/bmp280.h b/drivers/iio/pressure/bmp280.h index fe4d3f127954..7c30e4d523be 100644 --- a/drivers/iio/pressure/bmp280.h +++ b/drivers/iio/pressure/bmp280.h @@ -397,12 +397,6 @@ struct bmp280_data { */ int sampling_freq; - /* - * Carryover value from temperature conversion, used in pressure - * calculation. - */ - s32 t_fine; - /* * DMA (thus cache coherency maintenance) may require the * transfer buffers to live in their own cache lines. From patchwork Mon Apr 29 19:00:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13647525 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E40C213C671; Mon, 29 Apr 2024 19:01:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714417267; cv=none; b=CtDoXRWBb+nNZJUGom0zDZ3HLbVOO9EA7hTT/7fOn5NJ5IjuqRIdAU4fcQSgBtxsfykn9g49dkObaz/S6kssM/ri/dmz02LLDcqkRrQwnoovE6zIy+R73fYxHKYCC996U7FIJPNoM45LpdEIp7v0+LuSxdMf+Zj4XPsQXFl9oMo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714417267; c=relaxed/simple; bh=NOrJb6p7v7/w/7jahStUJxBEPe+89T748ZsfhUu2POc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sRc+vRc33nwCpn+/6sR4KePQkjepiNv7SeXYdd46djvTK8Ju9lVam0VKzukeI57RK7e80gYVlkBudAW5mR9MyF5FuAOdS6s8VTK/sqMnS0TanGpMHvPLRFwDwjZSbyOiP8xYTlUimmNay32K58CAA+MSW0JJtbGaAK8bLHuSSw0= 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=UIFVNKCT; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UIFVNKCT" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-34d13789e2fso994980f8f.3; Mon, 29 Apr 2024 12:01:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714417264; x=1715022064; 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=9G5hRyuWFdVeJfPqoqlg4bo6BPBFgmGTi1O6KMvVv+Q=; b=UIFVNKCT50aJ2SqRfD3Wy+yIxFG8L6JqFlK31L9TsvYz1g4ZYcaXCIsHskgNGi/hQp Y9ZUXdpDycqZS6xfwJHbXM1ePI4RLqr+CatDtox+lp9kn6jFaHKCwXoO13JNkExbVD2n 3gYqQyHiMT5n2hxJ2GAYUmOExXBOxA3kUyLZ7t8Qc5HcNpqs6NCbiW+pJHng0A3FKTtQ D5U7xSBlqDvE9U73WmlcWEjpW91PWeW7bxjFkIWLhDYe+Xq5uWqF60ehDP6bk97qimZk ubgmEQpQMHROa6FYjMlNj/ywaaroQDFaZwmF1FS8W+AmpEUmwKqAG9gA2H3g3/RAAHYw ygSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714417264; x=1715022064; 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=9G5hRyuWFdVeJfPqoqlg4bo6BPBFgmGTi1O6KMvVv+Q=; b=Zr9QHP53fBjL0s219dBY27/H+rsXNlzFBVK/HkRA9EQ11Jg+IHO5bjI4XeKdhWkGCy OrRulLTMfSuJLhOdjsKiXNNVhd0tgS5rCVKH35Xfs5Q9coMmalUFWJ6WW25FubPSA8Su D2ZVQhq5PK+EMXpqfezFkQAdMMjHB6yUcDNMHLhUk+9jVeBhg850dry/QOJA/S9F43XX 1bW6YcNybIYGg7/AiTnAi0ynUeeZSm42c7lYbqwZlTv6d6MmYIj8cWrxZ6/msHejSIXJ JqvuZ4E7jU1yluIGuMIA5wi9VzezxiWE8SkbKffPduJ/YxuLc/4gPDKjD0UG8MLzKn4R c83w== X-Forwarded-Encrypted: i=1; AJvYcCWwpGcweoBUhkz71pV0ddpGHcXapj58BlAv2aMZk+kjIA72FOR2jBxaQ4oInV7bRiw6CdwI0CYeFCxpDgXU310+OVMeZvImxg9mocuGd0ALyloD0Ud0wO28Yckih3Va9tNmjqf5yIu6 X-Gm-Message-State: AOJu0YxaTl43igqzUdHMjlMl5G6YkxnmDimrDMtQcJzozZuk8kX+BcWN yWPfiMG+visfrWpztFwqbCl3BemY6Fsvhu+miYFg7LNr+8glkttG X-Google-Smtp-Source: AGHT+IETR4IWEKTl5LAaTBFHjCqIkPl5Pe31CYpkAyFrfX65RMvDe5sLd2th/Nur0SOUdhv9ZUOC4A== X-Received: by 2002:a5d:444d:0:b0:34c:c66c:5624 with SMTP id x13-20020a5d444d000000b0034cc66c5624mr338749wrr.35.1714417264233; Mon, 29 Apr 2024 12:01:04 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:abbf:c98a:cf84:d14c]) by smtp.gmail.com with ESMTPSA id x2-20020adfdd82000000b0034c78bba70bsm8469456wrl.72.2024.04.29.12.01.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 12:01:03 -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, phil@raspberrypi.com, 579lpy@gmail.com, linus.walleij@linaro.org, semen.protsenko@linaro.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Vasileios Amoiridis , Jonathan Cameron Subject: [PATCH v5 07/10] iio: pressure: bmp280: Introduce new cleanup routines Date: Mon, 29 Apr 2024 21:00:43 +0200 Message-Id: <20240429190046.24252-8-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240429190046.24252-1-vassilisamir@gmail.com> References: <20240429190046.24252-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Introduce new linux/cleanup.h with the guard(mutex) functionality in the {read,write}_raw() functions. Suggested-by: Andy Shevchenko Suggested-by: Jonathan Cameron Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-core.c | 125 +++++++++++++---------------- 1 file changed, 54 insertions(+), 71 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 5ebce38e99f6..f14277bb882d 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -501,77 +502,67 @@ static int bme280_read_humid(struct bmp280_data *data, int *val, int *val2) return IIO_VAL_INT; } -static int bmp280_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, int *val2, long mask) +static int bmp280_read_raw_impl(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) { struct bmp280_data *data = iio_priv(indio_dev); - int ret; - pm_runtime_get_sync(data->dev); - mutex_lock(&data->lock); + guard(mutex)(&data->lock); switch (mask) { case IIO_CHAN_INFO_PROCESSED: switch (chan->type) { case IIO_HUMIDITYRELATIVE: - ret = data->chip_info->read_humid(data, val, val2); - break; + return data->chip_info->read_humid(data, val, val2); case IIO_PRESSURE: - ret = data->chip_info->read_press(data, val, val2); - break; + return data->chip_info->read_press(data, val, val2); case IIO_TEMP: - ret = data->chip_info->read_temp(data, val, val2); - break; + return data->chip_info->read_temp(data, val, val2); default: - ret = -EINVAL; - break; + return -EINVAL; } - break; case IIO_CHAN_INFO_OVERSAMPLING_RATIO: switch (chan->type) { case IIO_HUMIDITYRELATIVE: *val = 1 << data->oversampling_humid; - ret = IIO_VAL_INT; - break; + return IIO_VAL_INT; case IIO_PRESSURE: *val = 1 << data->oversampling_press; - ret = IIO_VAL_INT; - break; + return IIO_VAL_INT; case IIO_TEMP: *val = 1 << data->oversampling_temp; - ret = IIO_VAL_INT; - break; + return IIO_VAL_INT; default: - ret = -EINVAL; - break; + return -EINVAL; } - break; case IIO_CHAN_INFO_SAMP_FREQ: - if (!data->chip_info->sampling_freq_avail) { - ret = -EINVAL; - break; - } + if (!data->chip_info->sampling_freq_avail) + return -EINVAL; *val = data->chip_info->sampling_freq_avail[data->sampling_freq][0]; *val2 = data->chip_info->sampling_freq_avail[data->sampling_freq][1]; - ret = IIO_VAL_INT_PLUS_MICRO; - break; + return IIO_VAL_INT_PLUS_MICRO; case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: - if (!data->chip_info->iir_filter_coeffs_avail) { - ret = -EINVAL; - break; - } + if (!data->chip_info->iir_filter_coeffs_avail) + return -EINVAL; *val = (1 << data->iir_filter_coeff) - 1; - ret = IIO_VAL_INT; - break; + return IIO_VAL_INT; default: - ret = -EINVAL; - break; + return -EINVAL; } +} - mutex_unlock(&data->lock); +static int bmp280_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct bmp280_data *data = iio_priv(indio_dev); + int ret; + + pm_runtime_get_sync(data->dev); + ret = bmp280_read_raw_impl(indio_dev, chan, val, val2, mask); pm_runtime_mark_last_busy(data->dev); pm_runtime_put_autosuspend(data->dev); @@ -703,12 +694,13 @@ static int bmp280_write_iir_filter_coeffs(struct bmp280_data *data, int val) return -EINVAL; } -static int bmp280_write_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int val, int val2, long mask) +static int bmp280_write_raw_impl(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) { struct bmp280_data *data = iio_priv(indio_dev); - int ret = 0; + + guard(mutex)(&data->lock); /* * Helper functions to update sensor running configuration. @@ -718,45 +710,36 @@ static int bmp280_write_raw(struct iio_dev *indio_dev, */ switch (mask) { case IIO_CHAN_INFO_OVERSAMPLING_RATIO: - pm_runtime_get_sync(data->dev); - mutex_lock(&data->lock); switch (chan->type) { case IIO_HUMIDITYRELATIVE: - ret = bme280_write_oversampling_ratio_humid(data, val); - break; + return bme280_write_oversampling_ratio_humid(data, val); case IIO_PRESSURE: - ret = bmp280_write_oversampling_ratio_press(data, val); - break; + return bmp280_write_oversampling_ratio_press(data, val); case IIO_TEMP: - ret = bmp280_write_oversampling_ratio_temp(data, val); - break; + return bmp280_write_oversampling_ratio_temp(data, val); default: - ret = -EINVAL; - break; + return -EINVAL; } - mutex_unlock(&data->lock); - pm_runtime_mark_last_busy(data->dev); - pm_runtime_put_autosuspend(data->dev); - break; case IIO_CHAN_INFO_SAMP_FREQ: - pm_runtime_get_sync(data->dev); - mutex_lock(&data->lock); - ret = bmp280_write_sampling_frequency(data, val, val2); - mutex_unlock(&data->lock); - pm_runtime_mark_last_busy(data->dev); - pm_runtime_put_autosuspend(data->dev); - break; + return bmp280_write_sampling_frequency(data, val, val2); case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: - pm_runtime_get_sync(data->dev); - mutex_lock(&data->lock); - ret = bmp280_write_iir_filter_coeffs(data, val); - mutex_unlock(&data->lock); - pm_runtime_mark_last_busy(data->dev); - pm_runtime_put_autosuspend(data->dev); - break; + return bmp280_write_iir_filter_coeffs(data, val); default: return -EINVAL; } +} + +static int bmp280_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct bmp280_data *data = iio_priv(indio_dev); + int ret; + + pm_runtime_get_sync(data->dev); + ret = bmp280_write_raw_impl(indio_dev, chan, val, val2, mask); + pm_runtime_mark_last_busy(data->dev); + pm_runtime_put_autosuspend(data->dev); return ret; } From patchwork Mon Apr 29 19:00:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13647528 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.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 1CC2213C697; Mon, 29 Apr 2024 19:01:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714417270; cv=none; b=dUpuhwX756YwJpj0D+BO4XnkgNa2Dg90Wt2CKrlevVdB5SyliUSGa6czVA667/ftZY1WLmEFZmcnF9wIkslNkLpc+OXSNwLvM97kgIWxbE9GajylYpRwSXvC+cVKu6OqH6IRxef4vbDR0/oYCXMjSXzRFFEtEvI0LOkVu+HozEI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714417270; c=relaxed/simple; bh=jUnIFwmN479zaELfVxMHwdlJyanVM5evpT4EUceIxnw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RgEuHbnvA+XgmLe4yANgs967ANGb9MsX8klEYyJVRU+huWhz2MkDYF+c+8IcwlMb92kkd80mrkgn/Kp0akwX1kHGpiQaRB6OzK0JbX7Vzps5XtF+QmfK9MLulVaKfqt0ZpTXdeilgUYT9+TVYaUgKqUTNRqvccBrohRvcDOB3d0= 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=nqHASwMG; arc=none smtp.client-ip=209.85.128.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="nqHASwMG" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-41bca450fa3so19136925e9.2; Mon, 29 Apr 2024 12:01:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714417265; x=1715022065; 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=bFJJTF6UwFjuI8s1cb6ftzX78U2lf2vbFXrsFgT6sXQ=; b=nqHASwMGZnOCzmYPLrGijztAPI0Mt0MQUxdZ66k8hJSq9AUhYBqxt1eo4UBx1HZk3h QKdybxWsWylSl/5guuzth6V+yYst1e1M0PtX9hLK1+XeipetVeS10MR4Sk0X1bjjTuxs QphjF6uXczJ6jRrp7XyYYdI9LCkNPi79tuhXQbSrlhhmkJ6rby+2FV1TydKnJ1J9uqNg xnx5JkRImj8MN3GgxTuDFnPmNGp03OM0JnTGvdzBYUbk/XIC2s4ZKhZfTzuMgGOZEf58 CoPxB48OjFQOpkhwn5C3iaZsd73+A7zdz2rdUL6C4uibTC9Pp9m35BtZ6eLs09uE+r0q ghrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714417265; x=1715022065; 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=bFJJTF6UwFjuI8s1cb6ftzX78U2lf2vbFXrsFgT6sXQ=; b=uRXn4FuM/z9nhESQn8Y/vBQQ+vYPXPqqr4d/3DXpu6tZIurmUoAPgIMJWG0yy7+z0o 4i0TrGaj4DjgNccVm9eT0tRzXTYE+/TXkRTr36kPBbm7eX4IQlyyOAtFf+V8Hit8Ilh5 UcdWsNt7YGcvWTq9ghctZDaTO/pMLhnAX9zotbUAevQtSXItgFRnIARI/iho0B0otRec KtmqDQ2eyNl/h2aPdgFAGYdtXGwqnuwEC5Ix+tQiBhNGOXWHXZI0ZWPRvf4oizYjB5pR GAdf0KNw7R4dahZfBFWRGRDqHdNxwyfK7qnNkazhVYfA439PJGF0usImmv6z//CvkcIa EiWQ== X-Forwarded-Encrypted: i=1; AJvYcCVPZ5SqF95SHZFi1UyhlxbX8g35w96CUgOtp79SjjFsP8cDgBZQEWy/Tya4WCakUREFUYQ2bHbzdl6lRsa8JGQ2LDrAG1jlrNf8GUtLeAOGJjmDfPXoqLBdoZbHUwXEgf7W3zGmBcUJ X-Gm-Message-State: AOJu0Yx33RxrAKZg0tE/hXsGa8/KP2huIE8L2mEBzja0AKp2N2W594pc 5nFh7PjyBcgo19uDxP7GOjGnNxHbl43uCeyUnDKQp5+BtQ2zO/uD X-Google-Smtp-Source: AGHT+IER2nDA4wwne/lMiKEjxwd/2pJxjjgNia8wfNhq5uOK+Lre+WcI7Q0LuuF2u1ALiLOt6r1UFw== X-Received: by 2002:a5d:4387:0:b0:34c:a488:e6d0 with SMTP id i7-20020a5d4387000000b0034ca488e6d0mr437289wrq.36.1714417265254; Mon, 29 Apr 2024 12:01:05 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:abbf:c98a:cf84:d14c]) by smtp.gmail.com with ESMTPSA id x2-20020adfdd82000000b0034c78bba70bsm8469456wrl.72.2024.04.29.12.01.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 12:01:04 -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, phil@raspberrypi.com, 579lpy@gmail.com, linus.walleij@linaro.org, semen.protsenko@linaro.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Vasileios Amoiridis Subject: [PATCH v5 08/10] iio: pressure: bmp280: Generalize read_{temp,press,humid}() functions Date: Mon, 29 Apr 2024 21:00:44 +0200 Message-Id: <20240429190046.24252-9-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240429190046.24252-1-vassilisamir@gmail.com> References: <20240429190046.24252-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 and the IIO value inside the chip_info structure. Move the calculations for the IIO unit compatibility from inside the read_{temp,press,humid}() functions and move them to the general read_raw() function. In this way, all the data for the calculation of the value are located in the chip_info structure of the respective sensor. Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-core.c | 169 ++++++++++++++++------------- drivers/iio/pressure/bmp280.h | 13 ++- 2 files changed, 102 insertions(+), 80 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index f14277bb882d..668c4e8a2ebf 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -439,28 +439,23 @@ 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 int bmp280_read_temp(struct bmp280_data *data, s32 *comp_temp) { - s32 adc_temp, comp_temp; + s32 adc_temp; int ret; ret = bmp280_read_temp_adc(data, &adc_temp); if (ret < 0) return ret; - comp_temp = bmp280_compensate_temp(data, adc_temp); + *comp_temp = bmp280_compensate_temp(data, adc_temp); - /* IIO units are in milli Celsius */ - *val = comp_temp * 10; - return IIO_VAL_INT; + return 0; } -static int bmp280_read_press(struct bmp280_data *data, - int *val, int *val2) +static int bmp280_read_press(struct bmp280_data *data, u32 *comp_press) { s32 adc_press, t_fine; - u32 comp_press; int ret; ret = bmp280_get_t_fine(data, &t_fine); @@ -471,19 +466,14 @@ static int bmp280_read_press(struct bmp280_data *data, if (ret < 0) return ret; - comp_press = bmp280_compensate_press(data, adc_press, t_fine); + *comp_press = bmp280_compensate_press(data, adc_press, t_fine); - /* IIO units are in kPa */ - *val = comp_press; - *val2 = 256000; - - return IIO_VAL_FRACTIONAL; + return 0; } -static int bme280_read_humid(struct bmp280_data *data, int *val, int *val2) +static int bme280_read_humid(struct bmp280_data *data, u32 *comp_humidity) { s32 adc_humidity, t_fine; - u32 comp_humidity; int ret; ret = bmp280_get_t_fine(data, &t_fine); @@ -494,12 +484,9 @@ static int bme280_read_humid(struct bmp280_data *data, int *val, int *val2) if (ret < 0) return ret; - comp_humidity = bme280_compensate_humidity(data, adc_humidity, t_fine); + *comp_humidity = bme280_compensate_humidity(data, adc_humidity, t_fine); - /* IIO units are in 1000 * % */ - *val = comp_humidity * 1000 / 1024; - - return IIO_VAL_INT; + return 0; } static int bmp280_read_raw_impl(struct iio_dev *indio_dev, @@ -507,6 +494,8 @@ static int bmp280_read_raw_impl(struct iio_dev *indio_dev, int *val, int *val2, long mask) { struct bmp280_data *data = iio_priv(indio_dev); + int chan_value; + int ret; guard(mutex)(&data->lock); @@ -514,11 +503,29 @@ static int bmp280_read_raw_impl(struct iio_dev *indio_dev, case IIO_CHAN_INFO_PROCESSED: switch (chan->type) { case IIO_HUMIDITYRELATIVE: - return data->chip_info->read_humid(data, val, val2); + ret = data->chip_info->read_humid(data, &chan_value); + if (ret < 0) + return ret; + + *val = data->chip_info->humid_coeffs[0] * chan_value; + *val2 = data->chip_info->humid_coeffs[1]; + return data->chip_info->humid_coeffs_type; case IIO_PRESSURE: - return data->chip_info->read_press(data, val, val2); + ret = data->chip_info->read_press(data, &chan_value); + if (ret < 0) + return ret; + + *val = data->chip_info->press_coeffs[0] * chan_value; + *val2 = data->chip_info->press_coeffs[1]; + return data->chip_info->press_coeffs_type; case IIO_TEMP: - return data->chip_info->read_temp(data, val, val2); + ret = data->chip_info->read_temp(data, &chan_value); + if (ret < 0) + return ret; + + *val = data->chip_info->temp_coeffs[0] * chan_value; + *val2 = data->chip_info->temp_coeffs[1]; + return data->chip_info->temp_coeffs_type; default: return -EINVAL; } @@ -818,6 +825,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, @@ -846,6 +855,11 @@ 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, + .temp_coeffs_type = IIO_VAL_FRACTIONAL, + .press_coeffs = bmp280_press_coeffs, + .press_coeffs_type = IIO_VAL_FRACTIONAL, + .chip_config = bmp280_chip_config, .read_temp = bmp280_read_temp, .read_press = bmp280_read_press, @@ -873,6 +887,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, @@ -895,6 +910,13 @@ const struct bmp280_chip_info bme280_chip_info = { .num_oversampling_humid_avail = ARRAY_SIZE(bmp280_oversampling_avail), .oversampling_humid_default = BME280_OSRS_HUMIDITY_16X - 1, + .temp_coeffs = bmp280_temp_coeffs, + .temp_coeffs_type = IIO_VAL_FRACTIONAL, + .press_coeffs = bmp280_press_coeffs, + .press_coeffs_type = IIO_VAL_FRACTIONAL, + .humid_coeffs = bme280_humid_coeffs, + .humid_coeffs_type = IIO_VAL_FRACTIONAL, + .chip_config = bme280_chip_config, .read_temp = bmp280_read_temp, .read_press = bmp280_read_press, @@ -1083,9 +1105,8 @@ static u32 bmp380_compensate_press(struct bmp280_data *data, return comp_press; } -static int bmp380_read_temp(struct bmp280_data *data, int *val, int *val2) +static int bmp380_read_temp(struct bmp280_data *data, s32 *comp_temp) { - s32 comp_temp; u32 adc_temp; int ret; @@ -1093,16 +1114,14 @@ static int bmp380_read_temp(struct bmp280_data *data, int *val, int *val2) if (ret < 0) return ret; - comp_temp = bmp380_compensate_temp(data, adc_temp); + *comp_temp = bmp380_compensate_temp(data, adc_temp); - /* IIO units are in milli Celsius */ - *val = comp_temp * 10; - return IIO_VAL_INT; + return 0; } -static int bmp380_read_press(struct bmp280_data *data, int *val, int *val2) +static int bmp380_read_press(struct bmp280_data *data, u32 *comp_press) { - u32 adc_press, comp_press, t_fine; + u32 adc_press, t_fine; int ret; ret = bmp380_get_t_fine(data, &t_fine); @@ -1113,13 +1132,9 @@ static int bmp380_read_press(struct bmp280_data *data, int *val, int *val2) if (ret < 0) return ret; - comp_press = bmp380_compensate_press(data, adc_press, t_fine); + *comp_press = bmp380_compensate_press(data, adc_press, t_fine); - /* IIO units are in kPa */ - *val = comp_press; - *val2 = 100000; - - return IIO_VAL_FRACTIONAL; + return 0; } static int bmp380_read_calib(struct bmp280_data *data) @@ -1290,6 +1305,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, @@ -1317,6 +1334,11 @@ 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, + .temp_coeffs_type = IIO_VAL_FRACTIONAL, + .press_coeffs = bmp380_press_coeffs, + .press_coeffs_type = IIO_VAL_FRACTIONAL, + .chip_config = bmp380_chip_config, .read_temp = bmp380_read_temp, .read_press = bmp380_read_press, @@ -1437,9 +1459,8 @@ 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 int bmp580_read_temp(struct bmp280_data *data, s32 *raw_temp) { - s32 raw_temp; int ret; ret = regmap_bulk_read(data->regmap, BMP580_REG_TEMP_XLSB, data->buf, @@ -1449,25 +1470,17 @@ static int bmp580_read_temp(struct bmp280_data *data, int *val, int *val2) return ret; } - raw_temp = get_unaligned_le24(data->buf); - if (raw_temp == BMP580_TEMP_SKIPPED) { + *raw_temp = get_unaligned_le24(data->buf); + if (*raw_temp == BMP580_TEMP_SKIPPED) { dev_err(data->dev, "reading temperature skipped\n"); 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 0; } -static int bmp580_read_press(struct bmp280_data *data, int *val, int *val2) +static int bmp580_read_press(struct bmp280_data *data, u32 *raw_press) { - u32 raw_press; int ret; ret = regmap_bulk_read(data->regmap, BMP580_REG_PRESS_XLSB, data->buf, @@ -1477,18 +1490,13 @@ static int bmp580_read_press(struct bmp280_data *data, int *val, int *val2) return ret; } - raw_press = get_unaligned_le24(data->buf); - if (raw_press == BMP580_PRESS_SKIPPED) { + *raw_press = get_unaligned_le24(data->buf); + if (*raw_press == BMP580_PRESS_SKIPPED) { 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 0; } static const int bmp580_odr_table[][2] = { @@ -1804,6 +1812,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, @@ -1830,6 +1840,11 @@ 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, + .temp_coeffs_type = IIO_VAL_FRACTIONAL_LOG2, + .press_coeffs = bmp580_press_coeffs, + .press_coeffs_type = IIO_VAL_FRACTIONAL, + .chip_config = bmp580_chip_config, .read_temp = bmp580_read_temp, .read_press = bmp580_read_press, @@ -1985,20 +2000,18 @@ static s32 bmp180_compensate_temp(struct bmp280_data *data, s32 adc_temp) return (bmp180_calc_t_fine(data, adc_temp) + 8) / 16; } -static int bmp180_read_temp(struct bmp280_data *data, int *val, int *val2) +static int bmp180_read_temp(struct bmp280_data *data, s32 *comp_temp) { - s32 adc_temp, comp_temp; + s32 adc_temp; int ret; ret = bmp180_read_temp_adc(data, &adc_temp); if (ret < 0) return ret; - comp_temp = bmp180_compensate_temp(data, adc_temp); + *comp_temp = bmp180_compensate_temp(data, adc_temp); - /* IIO units are in milli Celsius */ - *val = comp_temp * 100; - return IIO_VAL_INT; + return 0; } static int bmp180_read_press_adc(struct bmp280_data *data, s32 *adc_press) @@ -2061,10 +2074,9 @@ 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 int bmp180_read_press(struct bmp280_data *data, u32 *comp_press) { s32 adc_press, t_fine; - u32 comp_press; int ret; ret = bmp180_get_t_fine(data, &t_fine); @@ -2075,13 +2087,9 @@ static int bmp180_read_press(struct bmp280_data *data, int *val, int *val2) if (ret < 0) return ret; - comp_press = bmp180_compensate_press(data, adc_press, t_fine); - - /* IIO units are in kPa */ - *val = comp_press; - *val2 = 1000; + *comp_press = bmp180_compensate_press(data, adc_press, t_fine); - return IIO_VAL_FRACTIONAL; + return 0; } static int bmp180_chip_config(struct bmp280_data *data) @@ -2092,6 +2100,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, @@ -2112,6 +2122,11 @@ 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, + .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, diff --git a/drivers/iio/pressure/bmp280.h b/drivers/iio/pressure/bmp280.h index 7c30e4d523be..a3d2cd722760 100644 --- a/drivers/iio/pressure/bmp280.h +++ b/drivers/iio/pressure/bmp280.h @@ -446,10 +446,17 @@ struct bmp280_chip_info { int num_sampling_freq_avail; int sampling_freq_default; + const int *temp_coeffs; + const int temp_coeffs_type; + const int *press_coeffs; + const int press_coeffs_type; + const int *humid_coeffs; + const int humid_coeffs_type; + int (*chip_config)(struct bmp280_data *data); - int (*read_temp)(struct bmp280_data *data, int *val, int *val2); - int (*read_press)(struct bmp280_data *data, int *val, int *val2); - int (*read_humid)(struct bmp280_data *data, int *val, int *val2); + int (*read_temp)(struct bmp280_data *data, s32 *adc_temp); + int (*read_press)(struct bmp280_data *data, u32 *adc_press); + int (*read_humid)(struct bmp280_data *data, u32 *adc_humidity); int (*read_calib)(struct bmp280_data *data); int (*preinit)(struct bmp280_data *data); }; From patchwork Mon Apr 29 19:00:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13647527 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.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 3B9F213C81A; Mon, 29 Apr 2024 19:01:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714417269; cv=none; b=AL9OL+pU05ncvf2zCWuyFHpaVkF49ZJHBE3IpnVJyvIG1DUXldV6rNes5AkGVmAA26sAzkf/vbKnFv9Ozo/5b2BRNe5SIgZhSOC5hwSAYwDCSEr2GalikMaFyUl3q8k3EtC4RitZQ5Yq64WaBw4uQSZ1Cj1HGEJ3HI/0aeHeQug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714417269; c=relaxed/simple; bh=7zD37O0cMqXfyAeXmkYzCAM0i0bqFUH6QgRBHqF6ofo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DaB2H3WPR/AB0SgdWBs0LOxmMGR4hbNCL2PWVExnxX/4ovNQKCe4ztW+V3lc2ckXOxFaib47TfDlS21/Dxsqt7tvaUi9NbF2RlVNJbWe/0nUSvQgW3zwDMu2YjDpg+Asqlm8yNlsdb+JmJa/BNvbMHFsSnRyeu5BlcqZ+5Ts9r4= 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=iSguUk/V; arc=none smtp.client-ip=209.85.167.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="iSguUk/V" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-51bafbe7509so6818655e87.1; Mon, 29 Apr 2024 12:01:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714417266; x=1715022066; 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=Mwn2MMGvK9G2qY6gm++WhwbYwYr8tU2LoZssFpAE/v0=; b=iSguUk/V67KHG18VNe9dNBMikuC8WtWcZxAqXR3QNuruD0YIx5h9B+ybZyHe4YhEE7 i4w5bg2Qzp0gfY1ZliCm8u3pePRmbYf2woyJXujLHApSTSrRroopBuwOTTLv44buJWHH 8C2bUV0pU+c+uMiiCuC82dYom9xGDYwNVadOSPFFrwHlY6/siUoxThYeczFn9SMiU0xV fsceINeeFeC62DZNxFUfHm7VxsRiYHxx91JPtH9skgTtOYk2v2gVmq73LBQWkIHI+XOC /jCT+tk4l2gF039hAMwNSns11Ufw3NIWB0G8VEZl0dkJI/3T/s5pzXJfsoFtom455CGX RY+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714417266; x=1715022066; 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=Mwn2MMGvK9G2qY6gm++WhwbYwYr8tU2LoZssFpAE/v0=; b=W8REo9dwRwTIadXdVi8sh0Ax224za4vGZUg0XyvChYWOhdZMc0+ZZ26XCq8HxTT8bd NAoMgplIWChIw/edm6lKoB8VXN9Oq+bNEYSIxFxQr59Qq7+YqAkCMvXl1GnYqajG/G/C NWFTzuOSCx06QXVdrjM47VilxSLvDbtcWBjRmwiUBpAO4MH5ci8G8gEL+88c3smVSdRJ 17d0QV/gcH9IvU7YqZwTnkNX+jqa4/uDyto0j4crcDg5UfkKnMIE+bN/xRSUxVg65Tea R/YspN9uneJSswxoeWn26P4XTCPeN/9VMwnYVcYn4CppAr8qUK3bOKsE1MdiedJ1QfDm C9HA== X-Forwarded-Encrypted: i=1; AJvYcCXhYTNht/wPczsQwigHOQ0SWgs5Pj/LNsoZsYomMJq1cmU9N2oNyWkRk+BN1W/pZuF3aTr+KB0MkKsmzFKeI4rVxmvuzVcZmrGFCJADoT4rY3sFvBAerXxPd3AEawH5xFskKWIn61Tj X-Gm-Message-State: AOJu0Yz8xv+qPnZ5KvRWB8r+waafuD1mR/q2O6KPGDEiKPrmK7VAPVlV IpJzBImSs4+wO4lF4M8L9AyLxxZGz9oCpdn7kZvmfBwOxKBNFgwd X-Google-Smtp-Source: AGHT+IH9nzto04uH8933cCAEYLrUBd1ZEEDmgvM68qUx5wNp/TVq3+OMpWrPvi7mr6g+QkZfz1rUZA== X-Received: by 2002:a05:6512:23a7:b0:51d:a1ab:98bc with SMTP id c39-20020a05651223a700b0051da1ab98bcmr4138196lfv.2.1714417266439; Mon, 29 Apr 2024 12:01:06 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:abbf:c98a:cf84:d14c]) by smtp.gmail.com with ESMTPSA id x2-20020adfdd82000000b0034c78bba70bsm8469456wrl.72.2024.04.29.12.01.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 12:01:06 -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, phil@raspberrypi.com, 579lpy@gmail.com, linus.walleij@linaro.org, semen.protsenko@linaro.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Vasileios Amoiridis Subject: [PATCH v5 09/10] iio: pressure: bmp280: Add SCALE, RAW values in channels and refactorize them Date: Mon, 29 Apr 2024 21:00:45 +0200 Message-Id: <20240429190046.24252-10-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240429190046.24252-1-vassilisamir@gmail.com> References: <20240429190046.24252-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 channels in order to be able to calculate the processed value with standard userspace IIO tools. Can be used for triggered buffers as well. Even though it is not a good design choice to have SCALE, RAW and PROCESSED together, the PROCESSED channel is kept for ABI compatibility. While at it, separate BMPxxx and BMExxx device channels since BME supports also humidity measurements. Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-core.c | 86 +++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 8 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 668c4e8a2ebf..e349ed87aad6 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -137,17 +137,45 @@ enum { static const struct iio_chan_spec bmp280_channels[] = { { .type = IIO_PRESSURE, + /* PROCESSED maintained for ABI backwards compatibility */ .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, + /* PROCESSED maintained for ABI backwards compatibility */ .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + }, +}; + +static const struct iio_chan_spec bme280_channels[] = { + { + .type = IIO_PRESSURE, + /* PROCESSED maintained for ABI backwards compatibility */ + .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, + /* PROCESSED maintained for ABI backwards compatibility */ + .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, + /* PROCESSED maintained for ABI backwards compatibility */ .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), }, }; @@ -155,21 +183,20 @@ static const struct iio_chan_spec bmp280_channels[] = { static const struct iio_chan_spec bmp380_channels[] = { { .type = IIO_PRESSURE, + /* PROCESSED maintained for ABI backwards compatibility */ .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), }, { .type = IIO_TEMP, + /* PROCESSED maintained for ABI backwards compatibility */ .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | - 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), - }, - { - .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), @@ -529,6 +556,49 @@ static int bmp280_read_raw_impl(struct iio_dev *indio_dev, default: return -EINVAL; } + case IIO_CHAN_INFO_RAW: + switch (chan->type) { + case IIO_HUMIDITYRELATIVE: + ret = data->chip_info->read_humid(data, &chan_value); + if (ret < 0) + return ret; + + *val = chan_value; + return IIO_VAL_INT; + case IIO_PRESSURE: + ret = data->chip_info->read_press(data, &chan_value); + if (ret < 0) + return ret; + + *val = chan_value; + return IIO_VAL_INT; + case IIO_TEMP: + ret = data->chip_info->read_temp(data, &chan_value); + if (ret < 0) + return ret; + + *val = chan_value; + return IIO_VAL_INT; + default: + return -EINVAL; + } + 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]; + return data->chip_info->humid_coeffs_type; + case IIO_PRESSURE: + *val = data->chip_info->press_coeffs[0]; + *val2 = data->chip_info->press_coeffs[1]; + return data->chip_info->press_coeffs_type; + case IIO_TEMP: + *val = data->chip_info->temp_coeffs[0]; + *val2 = data->chip_info->temp_coeffs[1]; + return data->chip_info->temp_coeffs_type; + default: + return -EINVAL; + } case IIO_CHAN_INFO_OVERSAMPLING_RATIO: switch (chan->type) { case IIO_HUMIDITYRELATIVE: @@ -895,7 +965,7 @@ 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, + .channels = bme280_channels, .num_channels = 3, .oversampling_temp_avail = bmp280_oversampling_avail, From patchwork Mon Apr 29 19:00:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13647529 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 480EC13C833; Mon, 29 Apr 2024 19:01:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714417271; cv=none; b=TDf4KoDDT7QmXcnIFx6CEQtQaN8tXdnsl8kG6EcG5eYsZloL3Ccfn6nDbMUbYo8Tfb2wzaCdrZPceQn4t0rTTVmNLgo1daBJ0ZqzOM2pd3y0RKjkvuJW1sRFHtuPYKDYWPSX71eXyBG8GI6+m8y4pNM+r4B/adm6RZapzTxuv4Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714417271; c=relaxed/simple; bh=TKYMqK9CIxoLp5MPf/GOZrITdU4lMP1kkQXhX4f7MM0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MRXoWlW3n+dBf9DdwqrheScnHH57BwLyPKmG7aL1PtPrq2vyUeGbKcBwRnQS8PKT4JfrRMZOYbdQtS7s4ZHgNwsWaz0vk49CsIBEYdwhjUAZvgVI+A+VeRx0ZkeshJgmj2G1HzvVBLyAAjQWOxpnhzFWu+vAPKdrkN8G227G9Ao= 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=WdP5FMid; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WdP5FMid" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-34cfd924eaeso1109049f8f.1; Mon, 29 Apr 2024 12:01:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714417267; x=1715022067; 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=GDAF+U19/5da4w0JG2HDaDZsWg8W9lSdmZuRHrNtLhk=; b=WdP5FMidpmEnap0Ym/D69m2mNWbKaKh/wj/f9uKN/Y1X/vpZl28ami+ZwUQBrkmEJ7 cUkg+eEi45+GKx1VI1sZ6AL/nXH9Vg8gq3FloG0/n7mk5/V6N3Z77sicRXzoTthhRjiV QKSpN3uic+UP8VjguVw69pHv3h54Wqyr8CMU/5b7XqkuX5IwMcARAiOJKs1YXAuq7Ba3 tjLLRsVkDWCF8NPTHe38qZT24Wn1XnM6IlD6A0ArrGP+FBJNkIOkqlC3R1KHwPnZmVlk vi4YkCl94JZohjC0nDis3obg9IKyiW/CNljKRLpr4VdER6QS0ZQHpenbvo56vmy0jgyS iJyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714417267; x=1715022067; 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=GDAF+U19/5da4w0JG2HDaDZsWg8W9lSdmZuRHrNtLhk=; b=YBxGd042njm0bTHv0l/Lbe6t99lV+IBfDpeYJlBTfg6ofRTa60GfyMnXmJjZuK1FF4 lnuFqpfJoZJG/1iEmUlsDWCPuQFk9rY4zH4eun7CwfZ8tk7485SyBpZtRnu/JzrRWukT zzcnzRKfyBm3uaVmLtSZc9da/6jA5ntWcxWQ8+Ca2c+/1ssTuE1gCY3qiHzwNyXj5ksW TFuE8eDU8YyNktgdO57Fg/Mn3gn7kwdzzyxk+XGlbHSQQOORr0Byof9mGB+/EXbNwZZ3 6cfJ7ZyKg+Za4b5DRNmRB51/FUSPKILbYwVdC8UoEez1F4I8YZ3bSA97u/FWXfDp7gAW cp9Q== X-Forwarded-Encrypted: i=1; AJvYcCXeTqkir5uukH+9AkvCoE/timmPVm6by/oCx9CmUqZ4yGONVdUDeXvotz6ivzzxYE0/Di0XqEHH9UuTAzK3lROFp4jE/4hLouB1uOHH0fpFs6b8XN4RGlJ+Xt7i/2kR4qcgibfO7ZNZ X-Gm-Message-State: AOJu0YzQHELQOooezhCarmpaAu6ni9CVlx0wEB5DyAvZ+OZLGyjXpvyD bSDo2ByoZ9KKp03K4R1wa/63rvLM+MfZIv/UwZmU0cN2PNvO1Vz3 X-Google-Smtp-Source: AGHT+IFOeOC8QLYCiZbaVho0p/Q7GgWAqrIBQzHM+Oosrs88s5nyv0iTBB6eFmE2/8BdPMdAKRJALQ== X-Received: by 2002:a05:6000:1cd:b0:34c:7ed4:7679 with SMTP id t13-20020a05600001cd00b0034c7ed47679mr5682658wrx.36.1714417267390; Mon, 29 Apr 2024 12:01:07 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:abbf:c98a:cf84:d14c]) by smtp.gmail.com with ESMTPSA id x2-20020adfdd82000000b0034c78bba70bsm8469456wrl.72.2024.04.29.12.01.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 12:01:07 -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, phil@raspberrypi.com, 579lpy@gmail.com, linus.walleij@linaro.org, semen.protsenko@linaro.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Vasileios Amoiridis Subject: [PATCH v5 10/10] iio: pressure: bmp280: Add triggered buffer support Date: Mon, 29 Apr 2024 21:00:46 +0200 Message-Id: <20240429190046.24252-11-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240429190046.24252-1-vassilisamir@gmail.com> References: <20240429190046.24252-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 BMP2xx, BME280, BMP3xx, and BMP5xx use continuous buffers for their temperature, pressure and humidity readings. This facilitates the use of burst/bulk reads in order to acquire data faster. The approach is different from the one used in oneshot captures. BMP085 & BMP1xx devices use a completely different measurement process that is well defined and is used in their buffer_handler(). Suggested-by: Angel Iglesias Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/Kconfig | 2 + drivers/iio/pressure/bmp280-core.c | 335 +++++++++++++++++++++++++++-- drivers/iio/pressure/bmp280-spi.c | 8 +- drivers/iio/pressure/bmp280.h | 21 +- 4 files changed, 344 insertions(+), 22 deletions(-) diff --git a/drivers/iio/pressure/Kconfig b/drivers/iio/pressure/Kconfig index 3ad38506028e..0b5406a3f85d 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 e349ed87aad6..2feadb56835f 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -41,7 +41,10 @@ #include #include +#include #include +#include +#include #include @@ -134,6 +137,12 @@ enum { BMP380_P11 = 20, }; +enum bmp280_scan { + BMP280_PRESS, + BMP280_TEMP, + BME280_HUMID, +}; + static const struct iio_chan_spec bmp280_channels[] = { { .type = IIO_PRESSURE, @@ -142,6 +151,13 @@ static const struct iio_chan_spec bmp280_channels[] = { BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .scan_index = 0, + .scan_type = { + .sign = 'u', + .realbits = 32, + .storagebits = 32, + .endianness = IIO_CPU, + }, }, { .type = IIO_TEMP, @@ -150,7 +166,15 @@ static const struct iio_chan_spec bmp280_channels[] = { 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[] = { @@ -161,6 +185,13 @@ static const struct iio_chan_spec bme280_channels[] = { BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .scan_index = 0, + .scan_type = { + .sign = 'u', + .realbits = 32, + .storagebits = 32, + .endianness = IIO_CPU, + }, }, { .type = IIO_TEMP, @@ -169,6 +200,13 @@ static const struct iio_chan_spec bme280_channels[] = { 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, + }, }, { .type = IIO_HUMIDITYRELATIVE, @@ -177,7 +215,15 @@ static const struct iio_chan_spec bme280_channels[] = { BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .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[] = { @@ -190,6 +236,13 @@ 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 = 'u', + .realbits = 32, + .storagebits = 32, + .endianness = IIO_CPU, + }, }, { .type = IIO_TEMP, @@ -200,7 +253,15 @@ 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 = 1, + .scan_type = { + .sign = 's', + .realbits = 32, + .storagebits = 32, + .endianness = IIO_CPU, + }, }, + IIO_CHAN_SOFT_TIMESTAMP(2), }; static int bmp280_read_calib(struct bmp280_data *data) @@ -321,7 +382,7 @@ static int bme280_read_humid_adc(struct bmp280_data *data, s32 *adc_humidity) int ret; ret = regmap_bulk_read(data->regmap, BME280_REG_HUMIDITY_MSB, - &data->be16, sizeof(data->be16)); + &data->be16, BME280_NUM_HUMIDITY_BYTES); if (ret < 0) { dev_err(data->dev, "failed to read humidity\n"); return ret; @@ -366,7 +427,7 @@ static int bmp280_read_temp_adc(struct bmp280_data *data, s32 *adc_temp) int ret; ret = regmap_bulk_read(data->regmap, BMP280_REG_TEMP_MSB, - data->buf, sizeof(data->buf)); + data->buf, BMP280_NUM_TEMP_BYTES); if (ret < 0) { dev_err(data->dev, "failed to read temperature\n"); return ret; @@ -425,7 +486,7 @@ static int bmp280_read_press_adc(struct bmp280_data *data, s32 *adc_press) int ret; ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB, - data->buf, sizeof(data->buf)); + data->buf, BMP280_NUM_PRESS_BYTES); if (ret < 0) { dev_err(data->dev, "failed to read pressure\n"); return ret; @@ -866,6 +927,16 @@ 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), + 0 +}; + +static const unsigned long bme280_avail_scan_masks[] = { + BIT(BME280_HUMID) | BIT(BMP280_TEMP) | BIT(BMP280_PRESS), + 0 +}; + static int bmp280_chip_config(struct bmp280_data *data) { u8 osrs = FIELD_PREP(BMP280_OSRS_TEMP_MASK, data->oversampling_temp + 1) | @@ -893,6 +964,73 @@ static int bmp280_chip_config(struct bmp280_data *data) return ret; } +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); + s32 adc_temp, adc_press, adc_humidity, t_fine; + u8 sizeof_burst_read; + int ret; + + guard(mutex)(&data->lock); + + /* + * If humidity channel is enabled it means that we are called for the + * BME280 humidity sensor. + */ + if (test_bit(BME280_HUMID, indio_dev->active_scan_mask)) + sizeof_burst_read = BME280_BURST_READ_BYTES; + else + sizeof_burst_read = BMP280_BURST_READ_BYTES; + + /* Burst read data registers */ + ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB, + data->buf, sizeof_burst_read); + if (ret < 0) { + dev_err(data->dev, "failed to burst read sensor data\n"); + return IRQ_HANDLED; + } + + /* Temperature calculations */ + adc_temp = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(&data->buf[3])); + if (adc_temp == BMP280_TEMP_SKIPPED) { + dev_err(data->dev, "reading temperature skipped\n"); + return IRQ_HANDLED; + } + + data->sensor_data[1] = bmp280_compensate_temp(data, adc_temp); + + /* Pressure calculations */ + adc_press = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(&data->buf[0])); + if (adc_press == BMP280_PRESS_SKIPPED) { + dev_err(data->dev, "reading pressure skipped\n"); + return IRQ_HANDLED; + } + + t_fine = bmp280_calc_t_fine(data, adc_temp); + + data->sensor_data[0] = bmp280_compensate_press(data, adc_press, t_fine); + + /* Humidity calculations */ + if (test_bit(BME280_HUMID, indio_dev->active_scan_mask)) { + adc_humidity = get_unaligned_be16(&data->buf[6]); + + if (adc_humidity == BMP280_HUMIDITY_SKIPPED) { + dev_err(data->dev, "reading humidity skipped\n"); + return IRQ_HANDLED; + } + data->sensor_data[2] = bme280_compensate_humidity(data, adc_humidity, t_fine); + } + + iio_push_to_buffers_with_timestamp(indio_dev, &data->sensor_data, + iio_get_time_ns(indio_dev)); + + iio_trigger_notify_done(indio_dev->trig); + + return IRQ_HANDLED; +} + 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 }; @@ -905,7 +1043,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), @@ -934,6 +1073,8 @@ const struct bmp280_chip_info bmp280_chip_info = { .read_temp = bmp280_read_temp, .read_press = bmp280_read_press, .read_calib = bmp280_read_calib, + + .buffer_handler = bmp280_buffer_handler, }; EXPORT_SYMBOL_NS(bmp280_chip_info, IIO_BMP280); @@ -966,7 +1107,8 @@ const struct bmp280_chip_info bme280_chip_info = { .regmap_config = &bmp280_regmap_config, .start_up_time = 2000, .channels = bme280_channels, - .num_channels = 3, + .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), @@ -992,6 +1134,8 @@ const struct bmp280_chip_info bme280_chip_info = { .read_press = bmp280_read_press, .read_humid = bme280_read_humid, .read_calib = bme280_read_calib, + + .buffer_handler = bmp280_buffer_handler, }; EXPORT_SYMBOL_NS(bme280_chip_info, IIO_BMP280); @@ -1052,7 +1196,7 @@ static int bmp380_read_temp_adc(struct bmp280_data *data, u32 *adc_temp) int ret; ret = regmap_bulk_read(data->regmap, BMP380_REG_TEMP_XLSB, - data->buf, sizeof(data->buf)); + data->buf, BMP280_NUM_TEMP_BYTES); if (ret < 0) { dev_err(data->dev, "failed to read temperature\n"); return ret; @@ -1119,7 +1263,7 @@ static int bmp380_read_press_adc(struct bmp280_data *data, u32 *adc_press) int ret; ret = regmap_bulk_read(data->regmap, BMP380_REG_PRESS_XLSB, - data->buf, sizeof(data->buf)); + data->buf, BMP280_NUM_PRESS_BYTES); if (ret < 0) { dev_err(data->dev, "failed to read pressure\n"); return ret; @@ -1372,6 +1516,52 @@ static int bmp380_chip_config(struct bmp280_data *data) return 0; } +static irqreturn_t bmp380_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); + s32 adc_temp, adc_press, t_fine; + int ret; + + guard(mutex)(&data->lock); + + /* Burst read data registers */ + ret = regmap_bulk_read(data->regmap, BMP380_REG_PRESS_XLSB, + data->buf, BMP280_BURST_READ_BYTES); + if (ret < 0) { + dev_err(data->dev, "failed to burst read sensor data\n"); + return IRQ_HANDLED; + } + + /* Temperature calculations */ + adc_temp = get_unaligned_le24(&data->buf[3]); + if (adc_temp == BMP380_TEMP_SKIPPED) { + dev_err(data->dev, "reading temperature skipped\n"); + return IRQ_HANDLED; + } + + data->sensor_data[1] = bmp380_compensate_temp(data, adc_temp); + + /* Pressure calculations */ + adc_press = get_unaligned_le24(&data->buf[0]); + if (adc_press == BMP380_PRESS_SKIPPED) { + dev_err(data->dev, "reading pressure skipped\n"); + return IRQ_HANDLED; + } + + t_fine = bmp380_calc_t_fine(data, adc_temp); + + data->sensor_data[0] = bmp380_compensate_press(data, adc_press, t_fine); + + iio_push_to_buffers_with_timestamp(indio_dev, &data->sensor_data, + iio_get_time_ns(indio_dev)); + + iio_trigger_notify_done(indio_dev->trig); + + return IRQ_HANDLED; +} + 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 }; @@ -1386,7 +1576,8 @@ const struct bmp280_chip_info bmp380_chip_info = { .spi_read_extra_byte = true, .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), @@ -1414,6 +1605,8 @@ const struct bmp280_chip_info bmp380_chip_info = { .read_press = bmp380_read_press, .read_calib = bmp380_read_calib, .preinit = bmp380_preinit, + + .buffer_handler = bmp380_buffer_handler, }; EXPORT_SYMBOL_NS(bmp380_chip_info, IIO_BMP280); @@ -1533,8 +1726,8 @@ static int bmp580_read_temp(struct bmp280_data *data, s32 *raw_temp) { int ret; - ret = regmap_bulk_read(data->regmap, BMP580_REG_TEMP_XLSB, data->buf, - sizeof(data->buf)); + ret = regmap_bulk_read(data->regmap, BMP580_REG_TEMP_XLSB, + data->buf, BMP280_NUM_TEMP_BYTES); if (ret < 0) { dev_err(data->dev, "failed to read temperature\n"); return ret; @@ -1553,8 +1746,8 @@ static int bmp580_read_press(struct bmp280_data *data, u32 *raw_press) { int ret; - ret = regmap_bulk_read(data->regmap, BMP580_REG_PRESS_XLSB, data->buf, - sizeof(data->buf)); + ret = regmap_bulk_read(data->regmap, BMP580_REG_PRESS_XLSB, + data->buf, BMP280_NUM_PRESS_BYTES); if (ret < 0) { dev_err(data->dev, "failed to read pressure\n"); return ret; @@ -1880,6 +2073,50 @@ static int bmp580_chip_config(struct bmp280_data *data) return 0; } +static irqreturn_t bmp580_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); + s32 adc_temp, adc_press; + int ret; + + guard(mutex)(&data->lock); + + /* Burst read data registers */ + ret = regmap_bulk_read(data->regmap, BMP580_REG_TEMP_XLSB, + data->buf, BMP280_BURST_READ_BYTES); + if (ret < 0) { + dev_err(data->dev, "failed to burst read sensor data\n"); + return IRQ_HANDLED; + } + + /* Temperature calculations */ + adc_temp = get_unaligned_le24(&data->buf[0]); + if (adc_temp == BMP580_TEMP_SKIPPED) { + dev_err(data->dev, "reading temperature skipped\n"); + return IRQ_HANDLED; + } + + data->sensor_data[1] = adc_temp; + + /* Pressure calculations */ + adc_press = get_unaligned_le24(&data->buf[3]); + if (adc_press == BMP380_PRESS_SKIPPED) { + dev_err(data->dev, "reading pressure skipped\n"); + return IRQ_HANDLED; + } + + data->sensor_data[0] = adc_press; + + iio_push_to_buffers_with_timestamp(indio_dev, &data->sensor_data, + iio_get_time_ns(indio_dev)); + + iio_trigger_notify_done(indio_dev->trig); + + return IRQ_HANDLED; +} + 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 }; @@ -1892,7 +2129,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), @@ -1919,6 +2157,8 @@ const struct bmp280_chip_info bmp580_chip_info = { .read_temp = bmp580_read_temp, .read_press = bmp580_read_press, .preinit = bmp580_preinit, + + .buffer_handler = bmp580_buffer_handler, }; EXPORT_SYMBOL_NS(bmp580_chip_info, IIO_BMP280); @@ -2097,7 +2337,7 @@ static int bmp180_read_press_adc(struct bmp280_data *data, s32 *adc_press) return ret; ret = regmap_bulk_read(data->regmap, BMP180_REG_OUT_MSB, - data->buf, sizeof(data->buf)); + data->buf, BMP280_NUM_PRESS_BYTES); if (ret < 0) { dev_err(data->dev, "failed to read pressure\n"); return ret; @@ -2167,6 +2407,35 @@ static int bmp180_chip_config(struct bmp280_data *data) return 0; } +static irqreturn_t bmp180_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, chan_value; + + guard(mutex)(&data->lock); + + ret = bmp180_read_temp(data, &chan_value); + if (ret < 0) + return IRQ_HANDLED; + + data->sensor_data[1] = chan_value; + + ret = bmp180_read_press(data, &chan_value); + if (ret < 0) + return IRQ_HANDLED; + + data->sensor_data[0] = chan_value; + + iio_push_to_buffers_with_timestamp(indio_dev, &data->sensor_data, + iio_get_time_ns(indio_dev)); + + iio_trigger_notify_done(indio_dev->trig); + + return IRQ_HANDLED; +} + 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 }; @@ -2180,7 +2449,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 = @@ -2201,6 +2471,8 @@ const struct bmp280_chip_info bmp180_chip_info = { .read_temp = bmp180_read_temp, .read_press = bmp180_read_press, .read_calib = bmp180_read_calib, + + .buffer_handler = bmp180_buffer_handler, }; EXPORT_SYMBOL_NS(bmp180_chip_info, IIO_BMP280); @@ -2246,6 +2518,30 @@ static int bmp085_fetch_eoc_irq(struct device *dev, return 0; } +static int bmp_buffer_preenable(struct iio_dev *indio_dev) +{ + struct bmp280_data *data = iio_priv(indio_dev); + + pm_runtime_get_sync(data->dev); + + return 0; +} + +static int bmp_buffer_postdisable(struct iio_dev *indio_dev) +{ + struct bmp280_data *data = iio_priv(indio_dev); + + pm_runtime_mark_last_busy(data->dev); + pm_runtime_put_autosuspend(data->dev); + + return 0; +} + +const struct iio_buffer_setup_ops bmp_buffer_setup_ops = { + .preenable = bmp_buffer_preenable, + .postdisable = bmp_buffer_postdisable, +}; + static void bmp280_pm_disable(void *data) { struct device *dev = data; @@ -2292,6 +2588,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; @@ -2377,6 +2674,14 @@ int bmp280_common_probe(struct device *dev, "failed to read calibration coefficients\n"); } + ret = devm_iio_triggered_buffer_setup(data->dev, indio_dev, + iio_pollfunc_store_time, + data->chip_info->buffer_handler, + NULL); + if (ret < 0) + return dev_err_probe(data->dev, ret, + "iio triggered buffer setup failed\n"); + /* * Attempt to grab an optional EOC IRQ - only the BMP085 has this * however as it happens, the BMP085 shares the chip ID of BMP180 diff --git a/drivers/iio/pressure/bmp280-spi.c b/drivers/iio/pressure/bmp280-spi.c index 62b4e58104cf..dd1127d493d3 100644 --- a/drivers/iio/pressure/bmp280-spi.c +++ b/drivers/iio/pressure/bmp280-spi.c @@ -40,14 +40,10 @@ static int bmp380_regmap_spi_read(void *context, const void *reg, size_t reg_size, void *val, size_t val_size) { struct spi_device *spi = to_spi_device(context); - u8 rx_buf[4]; + u8 rx_buf[BME280_BURST_READ_BYTES + 1]; ssize_t status; - /* - * Maximum number of consecutive bytes read for a temperature or - * pressure measurement is 3. - */ - if (val_size > 3) + if (val_size > BMP280_BURST_READ_BYTES) return -EINVAL; /* diff --git a/drivers/iio/pressure/bmp280.h b/drivers/iio/pressure/bmp280.h index a3d2cd722760..756c644354c2 100644 --- a/drivers/iio/pressure/bmp280.h +++ b/drivers/iio/pressure/bmp280.h @@ -304,6 +304,16 @@ #define BMP280_PRESS_SKIPPED 0x80000 #define BMP280_HUMIDITY_SKIPPED 0x8000 +/* Number of bytes for each value */ +#define BMP280_NUM_PRESS_BYTES 3 +#define BMP280_NUM_TEMP_BYTES 3 +#define BME280_NUM_HUMIDITY_BYTES 2 +#define BMP280_BURST_READ_BYTES (BMP280_NUM_PRESS_BYTES + \ + BMP280_NUM_TEMP_BYTES) +#define BME280_BURST_READ_BYTES (BMP280_NUM_PRESS_BYTES + \ + BMP280_NUM_TEMP_BYTES + \ + BME280_NUM_HUMIDITY_BYTES) + /* Core exported structs */ static const char *const bmp280_supply_names[] = { @@ -397,13 +407,19 @@ struct bmp280_data { */ int sampling_freq; + /* + * Data to push to userspace triggered buffer. Up to 3 channels and + * s64 timestamp, aligned. + */ + s32 sensor_data[6] __aligned(8); + /* * DMA (thus cache coherency maintenance) may require the * transfer buffers to live in their own cache lines. */ union { /* Sensor data buffer */ - u8 buf[3]; + u8 buf[BME280_BURST_READ_BYTES]; /* Calibration data buffers */ __le16 bmp280_cal_buf[BMP280_CONTIGUOUS_CALIB_REGS / 2]; __be16 bmp180_cal_buf[BMP180_REG_CALIB_COUNT / 2]; @@ -425,6 +441,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; @@ -459,6 +476,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); + + irqreturn_t (*buffer_handler)(int irq, void *p); }; /* Chip infos for each variant */