From patchwork Sun Dec 24 14:34:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petre Rodan X-Patchwork-Id: 183064 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp2161683dyi; Sun, 24 Dec 2023 06:38:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+x3NVj/PZOuXurL5TQAAFY91JOKdGEMh4aqoEFEDdWU/pDhLN1rPLBsUnKJ5a32MsdKZA X-Received: by 2002:a05:600c:524b:b0:40d:566f:cb41 with SMTP id fc11-20020a05600c524b00b0040d566fcb41mr17379wmb.93.1703428681509; Sun, 24 Dec 2023 06:38:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703428681; cv=none; d=google.com; s=arc-20160816; b=IH5n3vjqyOrE/8eTK7XqykF7SewYo7rUJXXUVdRKCiPGmwG3/KqUzW7D47i3hEtXLf zr3uHkayxnek3rWBTr1PtQz9Pa2EQicqht7T7ihZNmTUqV9dv8/69fWuP7LSXZNssqTG EoQHFuwVSzybWXfoNN22GmP1SeFNszqPzUXjqrbUH2C9sR6Cih+tenr3ZZsF+sa0Ajzx H+ARqqmQgwG4mEWP+9oGq6GY8YY8flu6uOV4MM5F4TZnleayfA+RLSEgXsjk8MVpiBxZ BkNZIyYWLgHhTZlNb+vIwq9RoIqf/tY11aEj+F5dr6JuIJvNBg9pEQqcnB/a0QgYQRwh x3Ug== ARC-Message-Signature: i=1; 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 :date:subject:cc:to:from:dkim-signature; bh=8w4/VJ/ygPCBAB67H54TxgV1QezOZ9xo+IEAmceO3Co=; fh=cuSrpdmFbNnIGKLvcD6905UtzyKVEbJe+tTFY3eiseU=; b=mSQJnPbXT0FLz/OHOqN4haOzQprO0Vfh8uONF9qt7FAIRQ+pXcCCL9/eV0obNZTVlM NvQCR00RawBC5FvDm6CSgZcnXBgKF9xwFqOOHNHUDqOyyCWGEpWvnsdB7jc1qfNm5/HQ l/N+TyFYRSKEZoqdFaEeWlbd0Iu9z+v3y6y+msszgBqJf1fmZSHBPCPcoJcEw0ap1e2o gWmFr4r95O8I5U2AdN97pbq/nO2GHJWqY5NCvnWRoNyLeV8fNGj3SMKMVO2+eHc5eMhT 5IZT362ZroSVYf6FXX4YIJJAY0ehJHVEHbF5jTKusx/6nVP/2FuOa5f4YA68v8KgSCrN zQDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@subdimension.ro header.s=skycaves header.b="MDn/w3Yu"; spf=pass (google.com: domain of linux-kernel+bounces-10729-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10729-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=subdimension.ro Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ca7-20020a170906a3c700b00a2695e0a390si3752622ejb.829.2023.12.24.06.38.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Dec 2023 06:38:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10729-ouuuleilei=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=@subdimension.ro header.s=skycaves header.b="MDn/w3Yu"; spf=pass (google.com: domain of linux-kernel+bounces-10729-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10729-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=subdimension.ro 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 253ED1F2177B for ; Sun, 24 Dec 2023 14:38:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C8CDF15E93; Sun, 24 Dec 2023 14:35:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=subdimension.ro header.i=@subdimension.ro header.b="MDn/w3Yu" X-Original-To: linux-kernel@vger.kernel.org Received: from mail.subdimension.ro (skycaves.subdimension.ro [172.104.132.142]) (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 AB8F0D2E5; Sun, 24 Dec 2023 14:35:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=subdimension.ro Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=subdimension.ro Received: from localhost.localdomain (unknown [188.24.94.216]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mail.subdimension.ro (Postfix) with ESMTPSA id 761CE28B597; Sun, 24 Dec 2023 14:35:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=subdimension.ro; s=skycaves; t=1703428513; bh=KDRAxKlPjg5H/Rw/NBwFCVs5lMGFbcXAUuvCmLYArFk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MDn/w3Yue04BzNM1VWayAQyGNCcFVz3ouPJXBLd77fiyiOtQ7Ykhy2+r2W56LmBz6 HJmD3+xx+WfxKOGJdbeOu7nN9Lgtm/C2+QXBcQrIy2QJ7WOlhuRBSy7QhhjELetkOk f5qT3YtSGkpO76jhmVbn6WQDhcxWBI/idtqDwHjQ= From: Petre Rodan To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Petre Rodan , Andreas Klinger , Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , Angel Iglesias , Matti Vaittinen Subject: [PATCH v2 10/10] iio: pressure: mprls0025pa.c add SPI driver Date: Sun, 24 Dec 2023 16:34:55 +0200 Message-ID: <20231224143500.10940-11-petre.rodan@subdimension.ro> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231224143500.10940-1-petre.rodan@subdimension.ro> References: <20231224143500.10940-1-petre.rodan@subdimension.ro> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786174433218074076 X-GMAIL-MSGID: 1786174433218074076 Add SPI component of the driver. Tested with mprls0015pa0000sa in spi mode on BeagleBone Black on slightly patched 6.7.0-rc6 mainline. Tested with mprls0025pa in i2c mode on BeagleBone Black with togreg branch on git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git (tag: iio-for-6.8a) Signed-off-by: Petre Rodan Tested-by: Andreas Klinger --- drivers/iio/pressure/Kconfig | 8 ++- drivers/iio/pressure/Makefile | 1 + drivers/iio/pressure/mprls0025pa_spi.c | 91 ++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 drivers/iio/pressure/mprls0025pa_spi.c -- 2.41.0 diff --git a/drivers/iio/pressure/Kconfig b/drivers/iio/pressure/Kconfig index f03007cfec85..5da7931dc537 100644 --- a/drivers/iio/pressure/Kconfig +++ b/drivers/iio/pressure/Kconfig @@ -181,8 +181,9 @@ config MPL3115 config MPRLS0025PA tristate "Honeywell MPRLS0025PA (MicroPressure sensors series)" - depends on I2C + depends on (I2C || SPI_MASTER) select MPRLS0025PA_I2C if I2C + select MPRLS0025PA_SPI if SPI_MASTER select IIO_BUFFER select IIO_TRIGGERED_BUFFER help @@ -198,6 +199,11 @@ config MPRLS0025PA_I2C depends on MPRLS0025PA depends on I2C +config MPRLS0025PA_SPI + tristate + depends on MPRLS0025PA + depends on SPI_MASTER + config MS5611 tristate "Measurement Specialties MS5611 pressure sensor driver" select IIO_BUFFER diff --git a/drivers/iio/pressure/Makefile b/drivers/iio/pressure/Makefile index 7754135e190c..a93709e35760 100644 --- a/drivers/iio/pressure/Makefile +++ b/drivers/iio/pressure/Makefile @@ -25,6 +25,7 @@ obj-$(CONFIG_MPL115_SPI) += mpl115_spi.o obj-$(CONFIG_MPL3115) += mpl3115.o obj-$(CONFIG_MPRLS0025PA) += mprls0025pa.o obj-$(CONFIG_MPRLS0025PA_I2C) += mprls0025pa_i2c.o +obj-$(CONFIG_MPRLS0025PA_SPI) += mprls0025pa_spi.o obj-$(CONFIG_MS5611) += ms5611_core.o obj-$(CONFIG_MS5611_I2C) += ms5611_i2c.o obj-$(CONFIG_MS5611_SPI) += ms5611_spi.o diff --git a/drivers/iio/pressure/mprls0025pa_spi.c b/drivers/iio/pressure/mprls0025pa_spi.c new file mode 100644 index 000000000000..7ef43a7abc83 --- /dev/null +++ b/drivers/iio/pressure/mprls0025pa_spi.c @@ -0,0 +1,91 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * MPRLS0025PA - Honeywell MicroPressure MPR series SPI sensor driver + * + * Copyright (c) 2024 Petre Rodan + * + * Data sheet: + * https://prod-edam.honeywell.com/content/dam/honeywell-edam/sps/siot/en-us/products/sensors/pressure-sensors/board-mount-pressure-sensors/micropressure-mpr-series/documents/sps-siot-mpr-series-datasheet-32332628-ciid-172626.pdf + */ + +#include +#include +#include +#include + +#include + +#include "mprls0025pa.h" + +struct mpr_spi_buf { + u8 tx[MPR_MEASUREMENT_RD_SIZE] __aligned(IIO_DMA_MINALIGN); +}; + +static int mpr_spi_init(struct device *dev) +{ + struct spi_device *spi = to_spi_device(dev); + struct mpr_spi_buf *buf; + + buf = devm_kzalloc(dev, sizeof(*buf), GFP_KERNEL); + if (!buf) + return -ENOMEM; + + spi_set_drvdata(spi, buf); + + return 0; +} + +static int mpr_spi_xfer(struct mpr_data *data, const u8 cmd, const u8 pkt_len) +{ + struct spi_device *spi = to_spi_device(data->dev); + struct mpr_spi_buf *buf = spi_get_drvdata(spi); + struct spi_transfer xfer; + + if (pkt_len > MPR_MEASUREMENT_RD_SIZE) + return -EOVERFLOW; + + buf->tx[0] = cmd; + xfer.tx_buf = buf->tx; + xfer.rx_buf = data->buffer; + xfer.len = pkt_len; + + return spi_sync_transfer(spi, &xfer, 1); +} + +static const struct mpr_ops mpr_spi_ops = { + .init = mpr_spi_init, + .read = mpr_spi_xfer, + .write = mpr_spi_xfer, +}; + +static int mpr_spi_probe(struct spi_device *spi) +{ + return mpr_common_probe(&spi->dev, &mpr_spi_ops, spi->irq); +} + +static const struct of_device_id mpr_spi_match[] = { + { .compatible = "honeywell,mprls0025pa" }, + {} +}; +MODULE_DEVICE_TABLE(of, mpr_spi_match); + +static const struct spi_device_id mpr_spi_id[] = { + { "mprls0025pa" }, + {} +}; +MODULE_DEVICE_TABLE(spi, mpr_spi_id); + +static struct spi_driver mpr_spi_driver = { + .driver = { + .name = "mprls0025pa", + .of_match_table = mpr_spi_match, + }, + .probe = mpr_spi_probe, + .id_table = mpr_spi_id, +}; +module_spi_driver(mpr_spi_driver); + +MODULE_AUTHOR("Petre Rodan "); +MODULE_DESCRIPTION("Honeywell MPR pressure sensor spi driver"); +MODULE_LICENSE("GPL"); +MODULE_IMPORT_NS(IIO_HONEYWELL_MPRLS0025PA);