From patchwork Tue Feb 20 18:41:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13564342 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (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 7BA1876C94; Tue, 20 Feb 2024 18:41:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708454493; cv=none; b=Bb2WkObviu0ub/f3PtNhpEejyagI81aFqTb50jwWDyV2P1Wshu+z9jFTHW3hogTVzz2KNTj2D0RYol3pJMPWSgzyH3UQGuvX0D5Y5x6CCMfyBvOeiaW+BWC39od2aI1x16/HjLwM2kVZ6AFjN1PWnUcpJZZi96nm7DK8Y5NmAeI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708454493; c=relaxed/simple; bh=DwSB6eIUrVV5+VdOy3mihW0HfnTmkbLesBD6cSOFYUw=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=cpApiiS21V6GLOlJcgd0IyThs+ekwcCULJpu9wb5E7Gvi8Bd9dq2f3cikyxgzOBOIQDpv7VDhKtQJIF8VtlbKWIQGnKkjeZDKXMIsAjK8rdB5OVo6l2hDZJpm7UOW7FzyJu/SYaWlObuxjytnpGJm5VuYLVmFMGBgz7irwF9LlQ= 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=Ye+2xP9N; arc=none smtp.client-ip=209.85.208.52 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="Ye+2xP9N" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-563ed3d221aso7107232a12.0; Tue, 20 Feb 2024 10:41:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708454489; x=1709059289; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=1owq7Fy9RtBGgkYmyx+BQD0R3AB0m5IEudYK4GtR2Mw=; b=Ye+2xP9NMgRCwa2r+PKU6SkLkJhsn/cn2wMazz5t2pieeggYGi86BTL6/Tectp8T9n OgMafTGLa8xC2yzDsJmXpOk4t7lWBYN40YJzK29fVRM2H0Wl/KgYtN9V7Fb/xMnZRRHR xdX/ffi3mVFPofkuLwsR+b+dOYCHDiEooS0TOHAgjp7V4Sxw339YqJShxUMmFqk2ANUx rv9F89GWNDO2YXOnVmsVXCOedhZFm8Q3znUDh6QxVqkMU3s0/muWNWBbrEpqz+bPbMtT mE3PVTC4ilR81giQrpbLU97sOn+ua+yWENBeK3nXTVfPhglx+3fKALD3JUCNz4smM/GU NYuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708454489; x=1709059289; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1owq7Fy9RtBGgkYmyx+BQD0R3AB0m5IEudYK4GtR2Mw=; b=tUP1mFWtv+fN8hKGthF7eLy+HgRtlunXL7bsMhGhmYtRcr3p99WFCbc3Ssezrx3rz3 W18V3r89uftPfeeuPpRt30YECXkH3EOiso1UoYUo4H+Jk+5+zszCymG13HYe0Mx6PFT3 Z0uSdpbyvz3USG2EE01XYPVOH3nwaa0uDDinGKjbTOxGh54uQ7BBbNrHDg2XzIVFow6y jt7C0HDH0ekssUyQowi6xe1slnl2gCEc3Q2xUYggLIpbyNSEe6WBKV/jlCF6DN3AVRZo H4/RdnnckKoNcw81zvir6c0yvhNukDwL4aw2UxJm32beFK3OKBtZ7b1MUDIw3kP9FaIc wVGw== X-Forwarded-Encrypted: i=1; AJvYcCWpI12rD28pN0tBWkLZkEHwWKqUneGWhpeG62raZz9rBsYvvNU+dPXHe1K9aMEZVAsOEyRS2EAKEA7qe7/jqFpnRJXXqukoyIvyIFKvshBMw8CLvh0QxcAmNEa8nxv7DfVxrm8j7UcR X-Gm-Message-State: AOJu0YzbRjb8aBNN+/WpTEY9QfS/MV9i90kRX9eL9sWD+nFHAW+KhxyA ujoE2L6qBcCtROQhrexjj8Do73g917FXaumm8+LlpOtectY1hday X-Google-Smtp-Source: AGHT+IFjHdwnwUxKeWXHSiGMm1iXa1mDeBERgCFjP3WMT9aHIgdToj2cGLMD5jeV30pW7fa9u9YM0Q== X-Received: by 2002:a17:906:fa87:b0:a3e:c6de:e5ae with SMTP id lt7-20020a170906fa8700b00a3ec6dee5aemr5152274ejb.0.1708454488971; Tue, 20 Feb 2024 10:41:28 -0800 (PST) Received: from localhost.localdomain ([2a04:ee41:82:7577:4de1:dcc0:a48:7f]) by smtp.gmail.com with ESMTPSA id bm8-20020a170906c04800b00a3d9e6e9983sm4269594ejb.174.2024.02.20.10.41.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 10:41:28 -0800 (PST) From: Vasileios Amoiridis To: jic23@kernel.org 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, Vasileios Amoiridis Subject: [PATCH 1/2] drivers: iio: pressure: Fixes BMP38x and BMP390 SPI support Date: Tue, 20 Feb 2024 19:41:24 +0100 Message-Id: <20240220184125.32602-1-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Andy Shevchenko --- 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)) { From patchwork Tue Feb 20 18:41: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: 13564343 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.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 8EA3612E1D8; Tue, 20 Feb 2024 18:41:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708454495; cv=none; b=nClh6xRoNpiZVxu1Y86T1QEoyIxezDY6K5TGEKdrn+H2yw0WiZakdL9SwDjLIb6D08MeSfRFmJ6VyQvLOaJpcwTeZh4eBnaJoPX7jxmVCaXQJuBQ11l/m0F7UEY2jrfB7Ws0Xv8t3kSgLAze8CWDv5cQcP2dH8FgBQVggsNvYQg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708454495; c=relaxed/simple; bh=BWfTajOPUTzLygxio5pKNoa4Z8AGiKngDpmKELsS4hc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LcrrZeR2x1v1qC4TZUJf3qKuknQZjXjYx5fE3PWSmwk/8OE9EAU8+sAaVxic5Tovci8zWLD0jNWtELbkBgwXPxRufuUR8Gp4fyb+0N42xsGEturzWby7N1jmm9Wyx1Tu9Eg4xmD98+4vb1/sq6XDmzN1tQLBTaEHNtDFv0SFaTs= 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=gdM6V29I; arc=none smtp.client-ip=209.85.167.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="gdM6V29I" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-512bde3d197so2316460e87.0; Tue, 20 Feb 2024 10:41:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708454491; x=1709059291; 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=sO+tJy+OcpVtqK+jntLOR303MXxAWwT3SO7chMYMGqE=; b=gdM6V29I2xHgOxOegYFv2PNYM7042yJdxvR7efLlZ5ZQPvjAvFZRca119wDEMXSrSy yD+hJzdn12jROCQwxHJubEt4m/TZIOgwGwrO/O6G3g3VR1FqHMclb5UA4/O3/wm0ArLu Lcvrx76pL41c6PP3LT2s14lWjJMwd5nHH4IaPge40Dfvw4yk+qv/EEKTvCOg4OySHjoY OxMYGgaoPmEXSG1EK8K/579lzEbbpMrMeXT0tNWD0GQao8OX7Dfqabf0XaOY4TGou1Vq ZGp4M6Jf3ktssPfHfcSFddF/7zG19RiZgDvyIteRt2a7NgTaHIgKdFXppFUmHsyDo3l9 JsNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708454491; x=1709059291; 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=sO+tJy+OcpVtqK+jntLOR303MXxAWwT3SO7chMYMGqE=; b=kMEUZq5c2/iPZDxzYGaf80+h6eMIaF51QMQAGjKGksmnGkrh8RVmn7fRVRlyX+0ZBW MaoCkpprWFaSIjWsa21KLJYDAzzHfq1fO+tnMdZEQzN8ZoAmZClhkwKSHQJONbEg2eh6 14QEQY2pgRi1+agV1O/vi7iq9C4ZeJlw406B5rMPV0kZZdgvPmMfVWeMVsBhgXSH8VLf e0iJ5YHr32fnzv81z544FHMUAyIKWAJ+E5TSOCPHZpm4myF+IhfJWB7ACNZwzftkUigI jEv7/Ef3Dp9Y5QzVVkAhK03P6x+bfzYuBN22wFVfMDZuYucDFFvwIJGbFRVr3x0ge7J6 pijg== X-Forwarded-Encrypted: i=1; AJvYcCX3qdgUuO7yLU0HEE+07kUr8f0wRLKULIuwuP/X6GU9yCpm9gDz54fd6tBsw48LpOrVivDwqB21V6lT8QLW9ppta4a3ycPCnELK92a7k2BRz2fFVcuvpR0Q3IVJuG5Ron2icPQD+7th X-Gm-Message-State: AOJu0YzpjRjxgh4z/mwxNIEPTB4Eig6WbPUehzCpVCpesOJ8yhq0+LSk 4TGTzugKPNCIZT+PcZqGUIVd8GC8nvdK3KnuRORtdgIEubGGuNbG X-Google-Smtp-Source: AGHT+IHtWYfkDBoLoAYirXD9KiiCz8Ftzjhn1hRyEgC5esQHBNHHN/zxhNoamgNoIf6uAxqJ8H1zNg== X-Received: by 2002:a05:6512:488a:b0:512:afcf:771 with SMTP id eq10-20020a056512488a00b00512afcf0771mr4718567lfb.42.1708454491250; Tue, 20 Feb 2024 10:41:31 -0800 (PST) Received: from localhost.localdomain ([2a04:ee41:82:7577:4de1:dcc0:a48:7f]) by smtp.gmail.com with ESMTPSA id bm8-20020a170906c04800b00a3d9e6e9983sm4269594ejb.174.2024.02.20.10.41.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 10:41:30 -0800 (PST) From: Vasileios Amoiridis To: jic23@kernel.org 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, Vasileios Amoiridis Subject: [PATCH 2/2] drivers: iio: pressure: Sort headers of BMPxxx SPI driver Date: Tue, 20 Feb 2024 19:41:25 +0100 Message-Id: <20240220184125.32602-2-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240220184125.32602-1-vassilisamir@gmail.com> References: <20240220184125.32602-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Alphabetical sorting and separation of headers for the BMPxxx SPI driver. Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-spi.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/iio/pressure/bmp280-spi.c b/drivers/iio/pressure/bmp280-spi.c index 1972014dca93..3458806f11fb 100644 --- a/drivers/iio/pressure/bmp280-spi.c +++ b/drivers/iio/pressure/bmp280-spi.c @@ -4,11 +4,12 @@ * * Inspired by the older BMP085 driver drivers/misc/bmp085-spi.c */ -#include -#include +#include #include +#include #include -#include + +#include #include "bmp280.h"