From patchwork Fri Jun 28 17:17:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13716450 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.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 94B611CCCDF; Fri, 28 Jun 2024 17:17:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719595057; cv=none; b=gB24D0/mCZqTmBLcy6YLlGoN8h8bxjx2Huiuo7Yb8HMw1Ck9pdzBfNZ8myoU/P8OMB4ycoNaCgy+6wZV1O1v+YEK+Zgay6T/kDccHopNYcjGRGSvn2v97B7VfBKy2fRnsQ7owvXWvXJVyeF6fhRTVFrLyqzGAB+zXIsvQqFCkrw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719595057; c=relaxed/simple; bh=05qX4Wvjc0g7Um0b9nuNNVC11KnJMkaVbof5alU6WN0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=U95j3f7hc023SDfwYktQmQ6MyrJ0Co+oEp1hew9T8q5zrOcRTfvtU6PadNHjy2D5+aHuwViCbE0naBddukF56dEkVoQh/ARiGDCs+A+TiYfTwaOeZ4msyL50woVva7nN8byIqZq6TMBGKfwfN+3OnhuuJskUAFNOmmPEGq+BdR0= 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=UZD0HYIx; arc=none smtp.client-ip=209.85.208.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="UZD0HYIx" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-57d280e2d5dso1130293a12.1; Fri, 28 Jun 2024 10:17:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719595054; x=1720199854; 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=W+k2Itu1+1xeevVvn+fCmv36/tgLFg08aRj8+DwZgAw=; b=UZD0HYIxoDTShbcYr9KXx61W9F7lnK3w4nI+Dh4AKPptDFogivIeQtJrN+MOI4FG+e TshOI3AdZF2cYruAGrNaSMie9jGGrlQJxj6e4Itp4lGrBbwsICK+e2huSPcGajBMZAhB ZI3AqJ1HPi6rCJqYWtJddiw4WAUnT6brvmeGcZCJ2iX++tNm6E3W6DAlXwCJupzL5ggZ uSw3Oz/8gZ3rRSUy7kBZ00DPCMNE+2GDlXqtw7K1kodgG5GbIHEMHkYc/gDY3Ra76NrZ 6pbByqS+lGmApkIb7k8GgzVJcr0P258tqLPSxbej+HbfdMCceGi4RAqlZnHO7rxMbxZm gTzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719595054; x=1720199854; 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=W+k2Itu1+1xeevVvn+fCmv36/tgLFg08aRj8+DwZgAw=; b=vYaiiVXV4Xgk380m8RP5A+g3HgKF34MRKysnvmoWFIGWwauoFjd0PmSLNdJqKdPTiI JZ22dxJwq8jjsbD2E1Ceicnc69nufJPtz9fcVOOZppWPBQHlV5yHBAeNRAcLsTuEZX6/ 0uxie73vetHkUpZnnhY3hu5z8pk6+UiBuUNSFsA4v7sVdOQ/xRA55QtigQxX9vJzvR5S KoZ+mkjNuQD8OMtvEGOkjhZgkbFUAdZqZ/I3CI2dGF8Z2IvSY9BC+KRfuS+S/UNdity0 mPAW1oKjJUY7WPMKVaxl+aOxNWOqghvTzcay91TE3dHChc4LoAhApOKfm1+dZBJTosw9 2jNg== X-Forwarded-Encrypted: i=1; AJvYcCXQBxGo73QSMP1M2bqkZ/0INiD1/21BFGMqFK5U9CeYL44IyFktAw4m/fy9s283NXDDVoT87VQIcCD3Tnv7Hwbva/XouXLDtiQPUWITHn1vy/eUPMtWEqFYndQCsGvJHD9MQnTrQ5Rm X-Gm-Message-State: AOJu0YyIoGicnhI6HiKd/Uh3YsupF1cVSj5IGrxmjjoT2eRyNdQbVIyT 515cRtX5If+UoAdvPVs2oudSMdNshQgDd4ArXuO1hGbAd5R06D9S X-Google-Smtp-Source: AGHT+IEKmQL11Q538MAjC3r5Fn8nhjnOqGYGuDie3Qra0iYvRsF1H3SvmdquidfSHP/L90gtprgf2A== X-Received: by 2002:a05:6402:40cd:b0:582:ca34:31b1 with SMTP id 4fb4d7f45d1cf-582ca343627mr8564417a12.16.1719595053633; Fri, 28 Jun 2024 10:17:33 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:b996:e85b:4fbf:5c89]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-58612c838casm1271039a12.4.2024.06.28.10.17.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jun 2024 10:17:33 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org, lars@metafoo.de Cc: petre.rodan@subdimension.ro, mazziesaccount@gmail.com, ak@it-klinger.de, vassilisamir@gmail.com, ang.iglesiasg@gmail.com, linus.walleij@linaro.org, tgamblin@baylibre.com, ajarizzo@gmail.com, phil@raspberrypi.com, 579lpy@gmail.com, andriy.shevchenko@linux.intel.com, semen.protsenko@linaro.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v9 2/3] iio: pressure: bmp280: Add SCALE, RAW values in channels and refactorize them Date: Fri, 28 Jun 2024 19:17:25 +0200 Message-Id: <20240628171726.124852-3-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240628171726.124852-1-vassilisamir@gmail.com> References: <20240628171726.124852-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 Link: https://lore.kernel.org/r/20240512230524.53990-5-vassilisamir@gmail.com --- drivers/iio/pressure/bmp280-core.c | 96 ++++++++++++++++++++++++++---- 1 file changed, 83 insertions(+), 13 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 9ff26a8e85d3..f709ad8a54e1 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), @@ -537,6 +564,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) + return ret; + + *val = chan_value; + return IIO_VAL_INT; + case IIO_PRESSURE: + ret = data->chip_info->read_press(data, &chan_value); + if (ret) + return ret; + + *val = chan_value; + return IIO_VAL_INT; + case IIO_TEMP: + ret = data->chip_info->read_temp(data, &chan_value); + if (ret) + 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: @@ -843,7 +913,7 @@ 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 = ARRAY_SIZE(bmp280_channels), .oversampling_temp_avail = bmp280_oversampling_avail, .num_oversampling_temp_avail = ARRAY_SIZE(bmp280_oversampling_avail), @@ -903,8 +973,8 @@ const struct bmp280_chip_info bme280_chip_info = { .num_chip_id = ARRAY_SIZE(bme280_chip_ids), .regmap_config = &bmp280_regmap_config, .start_up_time = 2000, - .channels = bmp280_channels, - .num_channels = 3, + .channels = bme280_channels, + .num_channels = ARRAY_SIZE(bme280_channels), .oversampling_temp_avail = bmp280_oversampling_avail, .num_oversampling_temp_avail = ARRAY_SIZE(bmp280_oversampling_avail), @@ -1328,7 +1398,7 @@ 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 = ARRAY_SIZE(bmp380_channels), .oversampling_temp_avail = bmp380_oversampling_avail, .num_oversampling_temp_avail = ARRAY_SIZE(bmp380_oversampling_avail), @@ -1859,7 +1929,7 @@ 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 = ARRAY_SIZE(bmp380_channels), .oversampling_temp_avail = bmp580_oversampling_avail, .num_oversampling_temp_avail = ARRAY_SIZE(bmp580_oversampling_avail), @@ -2148,7 +2218,7 @@ 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 = ARRAY_SIZE(bmp280_channels), .oversampling_temp_avail = bmp180_oversampling_temp_avail, .num_oversampling_temp_avail =