From patchwork Tue Feb 20 22:43:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13564675 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.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 65E0F55787; Tue, 20 Feb 2024 22:43:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708469041; cv=none; b=W91yo1oRonU14lkK4phmJWz96oKqO7Rl0630VtV0hl7vMozq+xqI2JAcmd8InvK8/qyYQihVor3y6+2BccPHP8M36nVYbwfP2w4dq3lRQfe7+7tvdpQH0c4KjYuI+saJqfjZX6fF/UehscsCxrcGYcMIoa3XdRw0qZDuBP4Z8xg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708469041; c=relaxed/simple; bh=7OBXl7slkbYXNkGIWbZGvBwkUN2P3K/p4aq4Pl//018=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=uLYzlmlZjl1FtLjKUUp9k47ZGKnZ/SvNRHrOdtjYjmpcMLAV0NWRxCu8LHj2QGYrYlX5hXY7pZ1dnNMUSlw0tZWw9dcGM8Lx24Jh7TTcpOWkkgeULB6Nzj9h670RbaQGZTkQTwmY+kC8tz3xqerLFlRR2z3vbBlkTVbpo6S0LEo= 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=ieqhiT33; arc=none smtp.client-ip=209.85.218.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="ieqhiT33" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a3e87b2de41so266895866b.2; Tue, 20 Feb 2024 14:43:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708469038; x=1709073838; 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=DHuB3jZibZ6qtCUb9uZTADnW27tWsLt6G/FLrbSZCEs=; b=ieqhiT33QBrWIosXfxuF6R2nzZv/hAVRDUns/c/dsfVfni0XzH20tT7EZU0KbIhXRp Tj1eznH/IceQX7ZRsF9Sc0f2qZKlbr/m2GpJw6o87oQeKtcN9MIYR47HnSGr8Wxd+tN1 p9onkqrANL4kanaFLljG91ooGEEOUxWFZx1gENvF66A3z60e+zr/tmLT+ecBpoJO2V5k a39AHFG1wPNL2E67rKKj0yoyjce7xuR+CBm42HtynLHFy2av9F/8a/0+ol5zZctnp9dz hTOo+KZwlR6eLtru6E6eG+zIXwNDJckGsBpSMpUCZCnpp2g7mbqE1Z+8ARVg5Q10/pjl 6eaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708469038; x=1709073838; 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=DHuB3jZibZ6qtCUb9uZTADnW27tWsLt6G/FLrbSZCEs=; b=nh9lYMliKO8CF7ft53X+3N3PB/j4eS2+Zavu5C3E9lO7V7fG04OKD0ihjtUEEjbM0S 76v/DezBl9J340TBVoSJYpHlKbqCIkb28WWI6J65nnyvRxaJ6K54dHiMN1Mz9qsk+UID d/r0Dgu0oOv5lTHaMMRlpkCHl/P+sLN+9ogdpHMCsWmMxwpDnIrX6vnZYmymBWtUi4HG u1qIxU3SnDTdTKBakzy5Duz62GItO8aVhJRLEBdxy9AA65ge8cBnTmNgcT9yASXCKiSW JyeRlhR8ofcMdHfPipV5/CWiKO6T07Dh1K/d2mGO7yQp6SPtLHZyXvYNsWQhz+teb2d7 mlpQ== X-Forwarded-Encrypted: i=1; AJvYcCU/ESNCPBNtYAZX5Hx8Ed7mrVzZySQUZcILUegzHwqYBW+z/bmS3Tvt32Qzz4fPvxQRbo34NG5/XIgYsZPv/kV59WBbb2yO35hZhhanWwwwHLW3MNAjZbgsaySJf7/unSs/rbKTgWb3 X-Gm-Message-State: AOJu0YxQQZHia4nexg0vpv8vDzADPyXtVqygZtHwUpsLkNzKNniNd8Nl KuIdZrobyqDopmlgNk6jwejH83l+JDGalaL/0j49/T1v19jfDuZF X-Google-Smtp-Source: AGHT+IGef7cRx9p63So5jxOp2xHPGDx88OvziqNvplGafUO49cZ0JlsFYG1MOnGYkhXrNduPY2WEog== X-Received: by 2002:a17:906:af09:b0:a3e:d515:cdf3 with SMTP id lx9-20020a170906af0900b00a3ed515cdf3mr3933296ejb.27.1708469037440; Tue, 20 Feb 2024 14:43:57 -0800 (PST) Received: from localhost.localdomain ([2a04:ee41:82:7577:4de1:dcc0:a48:7f]) by smtp.gmail.com with ESMTPSA id xg11-20020a170907320b00b00a3d83cff358sm4328489ejb.70.2024.02.20.14.43.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 14:43:57 -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: Sort headers of BMPxxx SPI driver Date: Tue, 20 Feb 2024 23:43:28 +0100 Message-Id: <20240220224329.53729-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 Alphabetical sorting and separation of headers for the BMPxxx SPI driver. Signed-off-by: Vasileios Amoiridis Reviewed-by: Andy Shevchenko Acked-by: Angel Iglesias --- drivers/iio/pressure/bmp280-spi.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/iio/pressure/bmp280-spi.c b/drivers/iio/pressure/bmp280-spi.c index e8a5fed07e88..fd7ec6a5bca3 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 "bmp280.h" static int bmp280_regmap_spi_write(void *context, const void *data, From patchwork Tue Feb 20 22:43:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13564676 Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E6FF9153BFF; Tue, 20 Feb 2024 22:44:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708469048; cv=none; b=kJEZZX+zK2nZ1ssmjDhE+qw7jqhKVIL5IfU6gt3Cj/Bf1bwq+1Sqb2OBfPLzDRTUAN+lkVmU6+K9yzLy1mRHQE5zONVtkKmXM7JKdhyTJJqvclQzPdlxLeX4+h7k60DQVaL3f64fum1wLa9IhJ5hf2r7rYohUT5QNxXw1u9Nr3I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708469048; c=relaxed/simple; bh=/pVkv4ahqKqlMfpVpKXwkQU6mvxYDlM+vpKV0K0Y2i8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QA3Zb5D9nCrTlRw99DctFRIkX6pmvvGS8be/rzUuyRVaZt0cM0lAgUrWGwKcknprbMD13d8FaXa6hdQnnrJzOK2obYmbhJJ4w7Hl6zsZlhwHzgJbSeAvlBenptXSUrDQxxcDqXJ6gT44ss1OKlDwgK/JpdVH99UbC6xFZBzEn5A= 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=WZLJuqEV; arc=none smtp.client-ip=209.85.218.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WZLJuqEV" Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a3f1bf03722so90779766b.1; Tue, 20 Feb 2024 14:44:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708469045; x=1709073845; 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=GDvZdKqqAEQWTERmxxTyBVJONY656Jlnfr4NEFK+UlQ=; b=WZLJuqEVgBHEeviE4+s4tyyIU7UecjHBVD2raLwpq4PsnVkXFRWxOan354vplnMnjr CgfyIBZTlFkiI2xSF/PT9SN1l/90uc6EJ/VmSScrlm752jlnV/io3Da42VPsFt6zLWqh dzoVYDasJQtMwe5LxID5hGm0ljeu9fQWsm/YQd6s9bpse5jRBh8xqJo4bDGw5B3UgT8O chUeCxjcjyoLubYHHhj0SePmG5D3lM9AeyVcUo1NqC6IsllchyT4dwuEC3QT2PHGapu2 O3nXQqSoxAZYFjjUHuh33N5cTR3a/LUOhULJaZOHj4JBX/Vi3PGzcRO3OyL/SFO8dluI 6OfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708469045; x=1709073845; 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=GDvZdKqqAEQWTERmxxTyBVJONY656Jlnfr4NEFK+UlQ=; b=C+U9L2K7piYBXmLj+j9IB8vUsFQnjzcQmGrh2TNU7/72/S38KnKer4WNipiLKXvuyo yiVgKXUzEmvNwHqk/nw9Su9++neNt57gh+z0InfQimgQsg43lyIK2DndgQqVVLDh08HY G5G787fNneXewqbWKvBFraYKeHf5AslD74fahhYjTi6azfC7+dRDY+2acDg9slq0oP00 s724khfDmLnTzQS5HNlltmqrqFYialD9n28zO0TyPRABhr7/JL3DLDZOeq+l/ODA1vsz lUS13Zoynuu0TsqHVx4DXM0bQ/GhfatP83Pj432bJ+IZX8Cgo1so0osfyNetEka2fQU7 3OgA== X-Forwarded-Encrypted: i=1; AJvYcCUcAQ5TZrqoooEeZ60cS4kiiVFSWjgqBwmb8+knEbtlF8a3LCBlofM0ue5fzlVdjFH7XDiuMeIrLvh3Bq3sBp//C/mUb/D/eo7SVmz+99x2YF7OCDjsTR34pX3yTF1QHMWj6qbj6ym1 X-Gm-Message-State: AOJu0YwypPATjaNeAtTlp++u5LqfgprRpRt34+2WHIUhcDOWWK2s7aDT 743Uc2xpmzlJDNPcVNcbus9X6CraaO7YUNxWNF60+CxPT4qbrsAs X-Google-Smtp-Source: AGHT+IGTA9rs4XK3xLUoJnEUnhuvWSDMuSCJP8DRqX0O1OxxoD6AwNDr9F6IrJiFCRqqiPUwi97j8A== X-Received: by 2002:a17:906:6408:b0:a3d:19e4:113f with SMTP id d8-20020a170906640800b00a3d19e4113fmr11608828ejm.76.1708469045105; Tue, 20 Feb 2024 14:44:05 -0800 (PST) Received: from localhost.localdomain ([2a04:ee41:82:7577:4de1:dcc0:a48:7f]) by smtp.gmail.com with ESMTPSA id xg11-20020a170907320b00b00a3d83cff358sm4328489ejb.70.2024.02.20.14.44.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 14:44:04 -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: Fixes BMP38x and BMP390 SPI support Date: Tue, 20 Feb 2024 23:43:29 +0100 Message-Id: <20240220224329.53729-2-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240220224329.53729-1-vassilisamir@gmail.com> References: <20240220224329.53729-1-vassilisamir@gmail.com> 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 Acked-by: Angel Iglesias --- drivers/iio/pressure/bmp280-spi.c | 50 ++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/drivers/iio/pressure/bmp280-spi.c b/drivers/iio/pressure/bmp280-spi.c index fd7ec6a5bca3..7ea79fe57cfd 100644 --- a/drivers/iio/pressure/bmp280-spi.c +++ b/drivers/iio/pressure/bmp280-spi.c @@ -4,6 +4,7 @@ * * Inspired by the older BMP085 driver drivers/misc/bmp085-spi.c */ +#include #include #include #include @@ -36,6 +37,34 @@ 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, @@ -43,10 +72,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; @@ -59,8 +97,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)) {