Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp477989rbb; Sat, 24 Feb 2024 08:31:17 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVXVoEjPC4n2O0iXCH155YAw+7yaF9kY5fjoyO8rRBumfIxaDYcl2tk+YRI7fM/X4MmawXMlwcb9ze9BO+QyDuKVfLHqMtGUvj5dfO4nw== X-Google-Smtp-Source: AGHT+IEB7n20lq4NL8xTQbOqMRxdjARf/lAMH4dhN78dkA3OkvwRYe7pbg+63TkdkViymfsbUs9f X-Received: by 2002:aa7:c0d1:0:b0:565:a266:45df with SMTP id j17-20020aa7c0d1000000b00565a26645dfmr1130121edp.42.1708792277018; Sat, 24 Feb 2024 08:31:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708792277; cv=pass; d=google.com; s=arc-20160816; b=YoMBQ7LSthHZ4YZobnMN5q7hg2z1UgNz7B1oXkkG66YufGE163aNSEEc4OYpfbP8E9 KmNGkdYcuZyJlj1H9x8BxHtoZccGijoSwqK7VAgR2c8SP2B+wG94OK0sedNhibb74mea usgFKZJ1FpOKSly70ejFaAVCxZpKz8mzGtge+zAnl+gZ/P35GmIt5k8N5UN94rQ8NqLC z7DRe0PS5mW1NT3Wajo4TOoKp7tnCBR68aHGCRKyfZl7CFqelwb4YqMk/ZFaxaP/toUC RgTMIzJFBgZ4F01eileE9dpr0THX12MyM3SalDzIhd5X3gJKtbwtAxEBF9OP51+HdRLx Ggig== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=CAleUEHhv7naD4IUhULTdYUWjPazPSwqbWidJJ/zg7A=; fh=CkzsunZGGsdZIwrvxlKSBUjwip65+k8xzf2LSBoKZgo=; b=T7oeyoeUpKCRjq2nTQZTvZ1TPoUlmWM83Tc3keOT6QbC9swjn6ODLIgDj8DTeOT5XQ PkrOH7FK3dcKj81b9SgFcaxN+i+YZYz+zWAH+ae0A25zZnxIov0eqGf1tJ3rDvWGlp+3 1aurlmJNYPnxPiMtvSh7Ow6id0qjAx9k8ksl6i3rdnJEwVtIogCkqDDekgWrTXrzuMuV H8yemUYBU8tzFony9OWjQEqZ6v8m9KysgGXKTpQBXF/9XF1lFAlV4hKaN+kYnW9Gz5yo 3ajSm7CiBj8RUo3hFmzd90Yc88OD4vM7yU6XYgL9nIs2Ixk+G9ejXnYrPRF3L70NJ85o vt4A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VJq87c58; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-79739-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79739-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 18-20020a508e52000000b00565a27c5c63si625070edx.119.2024.02.24.08.31.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 08:31:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79739-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VJq87c58; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-79739-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79739-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C47D61F21D74 for ; Sat, 24 Feb 2024 16:31:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B73781EF1E; Sat, 24 Feb 2024 16:31:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VJq87c58" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E122CEC7; Sat, 24 Feb 2024 16:31:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708792264; cv=none; b=H6iWDbqoYW4x8xdWRtZzJBnF5Znl3/aGZ0Dbv3eMKx1+FJ96odyw9cXItR/kp3S9l6zj3NksriNL60F5I6RLDYBT04NElmFM3VmeCzd+KfeEkwLXAvWf48E73LK2dqKUUJPFdhcyw5KskxVv72atith9ZAf6R4OhmcAESzh/GI8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708792264; c=relaxed/simple; bh=8nObHrysG8EXeSQ7JcK3mcZ3ndfVs2t62O/vtkPkBSI=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eDw4oBIXBgklAZmEBXmR21z2ifuYL6OrspNtlIAzM3TY1e+USSh7uScvBWImqeB4ZLv0lONoDm5i7sE7VROV0e1ecV7MfVt7qJftlfAOvpOeKU5ZkgAXiFNEVCeaT4szUv+CLyWwJsXLkcgWENHwORV5xjmnsLSS91hb1QF2WW4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VJq87c58; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB705C433F1; Sat, 24 Feb 2024 16:31:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708792263; bh=8nObHrysG8EXeSQ7JcK3mcZ3ndfVs2t62O/vtkPkBSI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=VJq87c58xgQ/XrRNUqLPWtkBdCAm2Dqy+IbhDu6TdUtQ4ZIs7idX3goka6Lyo017v wpoEuxWAOsNZu1VDNzbFEKRNELIgpYT8j8WwgOoU+eHaWve93Umyo6oTjmJZPxe7Rq XyyAg1RuLEbil9exGoFBRWl6HNN7buhWKEWzanjoDSkJNh+fZ9aWdjcrQXJXIo7F9D /ckyb/iYOmGwf3t/qNa0j82O1PCtPV51lvsijjRODOEq8QpbVrTg8FKCFcOOBrn0FA 8FAkQ8ekqRvvRnnFX5XZskviGlLsz/T7MzTzZw6BS/glMRJzJppsBZ5zpqC0T3oyde w5rEUgEXA8UDA== Date: Sat, 24 Feb 2024 16:30:51 +0000 From: Jonathan Cameron To: Vasileios Amoiridis Cc: lars@metafoo.de, ang.iglesiasg@gmail.com, andriy.shevchenko@linux.intel.com, linus.walleij@linaro.org, semen.protsenko@linaro.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] drivers: iio: pressure: Fixes BMP38x and BMP390 SPI support Message-ID: <20240224163051.3edcf102@jic23-huawei> In-Reply-To: <20240219191359.18367-1-vassilisamir@gmail.com> References: <20240219191359.18367-1-vassilisamir@gmail.com> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 19 Feb 2024 20:13:59 +0100 Vasileios Amoiridis wrote: > According to the datasheet of BMP38x and BMP390 devices, for an SPI > read operation the first byte that is returned needs to be dropped, > and the rest of the bytes are the actual data returned from the > sensor. > > Fixes: 8d329309184d ("iio: pressure: bmp280: Add support for BMP380 sensor family") > > Signed-off-by: Vasileios Amoiridis Applied and marked for stable - with tweaks to header order and the space above as per discussion. > --- > drivers/iio/pressure/bmp280-spi.c | 49 ++++++++++++++++++++++++++++++- > 1 file changed, 48 insertions(+), 1 deletion(-) > > diff --git a/drivers/iio/pressure/bmp280-spi.c b/drivers/iio/pressure/bmp280-spi.c > index e8a5fed07e88..1972014dca93 100644 > --- a/drivers/iio/pressure/bmp280-spi.c > +++ b/drivers/iio/pressure/bmp280-spi.c > @@ -8,6 +8,7 @@ > #include > #include > #include > +#include > > #include "bmp280.h" > > @@ -35,6 +36,33 @@ static int bmp280_regmap_spi_read(void *context, const void *reg, > return spi_write_then_read(spi, reg, reg_size, val, val_size); > } > > +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]; > + ssize_t status; > + > + /* > + * Maximum number of consecutive bytes read for a temperature or > + * pressure measurement is 3. > + */ > + if (val_size > 3) > + return -EINVAL; > + /* > + * According to the BMP3xx datasheets, for a basic SPI read opertion, > + * the first byte needs to be dropped and the rest are the requested > + * data. > + */ > + status = spi_write_then_read(spi, reg, 1, rx_buf, val_size + 1); > + if (status) > + return status; > + > + memcpy(val, rx_buf + 1, val_size); > + > + return 0; > +} > + > static struct regmap_bus bmp280_regmap_bus = { > .write = bmp280_regmap_spi_write, > .read = bmp280_regmap_spi_read, > @@ -42,10 +70,19 @@ static struct regmap_bus bmp280_regmap_bus = { > .val_format_endian_default = REGMAP_ENDIAN_BIG, > }; > > +static struct regmap_bus bmp380_regmap_bus = { > + .write = bmp280_regmap_spi_write, > + .read = bmp380_regmap_spi_read, > + .read_flag_mask = BIT(7), > + .reg_format_endian_default = REGMAP_ENDIAN_BIG, > + .val_format_endian_default = REGMAP_ENDIAN_BIG, > +}; > + > static int bmp280_spi_probe(struct spi_device *spi) > { > const struct spi_device_id *id = spi_get_device_id(spi); > const struct bmp280_chip_info *chip_info; > + struct regmap_bus *bmp_regmap_bus; > struct regmap *regmap; > int ret; > > @@ -58,8 +95,18 @@ static int bmp280_spi_probe(struct spi_device *spi) > > chip_info = spi_get_device_match_data(spi); > > + switch (chip_info->chip_id[0]) { > + case BMP380_CHIP_ID: > + case BMP390_CHIP_ID: > + bmp_regmap_bus = &bmp380_regmap_bus; > + break; > + default: > + bmp_regmap_bus = &bmp280_regmap_bus; > + break; > + } > + > regmap = devm_regmap_init(&spi->dev, > - &bmp280_regmap_bus, > + bmp_regmap_bus, > &spi->dev, > chip_info->regmap_config); > if (IS_ERR(regmap)) {