File Index
Files and directories
Sign in
FILE

mprls0025pa_spi.c

File preview with syntax highlighting.

linux-6.19.14/drivers/iio/pressure/mprls0025pa_spi.c C
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * MPRLS0025PA - Honeywell MicroPressure MPR series SPI sensor driver
  4 *
  5 * Copyright (c) 2024 Petre Rodan <petre.rodan@subdimension.ro>
  6 *
  7 * Data sheet:
  8 *  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
  9 */
 10
 11#include <linux/array_size.h>
 12#include <linux/device.h>
 13#include <linux/errno.h>
 14#include <linux/mod_devicetable.h>
 15#include <linux/module.h>
 16#include <linux/spi/spi.h>
 17#include <linux/stddef.h>
 18#include <linux/types.h>
 19
 20#include "mprls0025pa.h"
 21
 22struct mpr_spi_buf {
 23	u8 tx[MPR_MEASUREMENT_RD_SIZE] __aligned(IIO_DMA_MINALIGN);
 24};
 25
 26static int mpr_spi_init(struct device *dev)
 27{
 28	struct spi_device *spi = to_spi_device(dev);
 29	struct mpr_spi_buf *buf;
 30
 31	buf = devm_kzalloc(dev, sizeof(*buf), GFP_KERNEL);
 32	if (!buf)
 33		return -ENOMEM;
 34
 35	spi_set_drvdata(spi, buf);
 36
 37	return 0;
 38}
 39
 40static int mpr_spi_xfer(struct mpr_data *data, const u8 cmd, const u8 pkt_len)
 41{
 42	struct spi_device *spi = to_spi_device(data->dev);
 43	struct mpr_spi_buf *buf = spi_get_drvdata(spi);
 44	struct spi_transfer xfers[2] = { };
 45
 46	if (pkt_len > MPR_MEASUREMENT_RD_SIZE)
 47		return -EOVERFLOW;
 48
 49	buf->tx[0] = cmd;
 50
 51	/*
 52	 * Dummy transfer with no data, just cause a 2.5us+ delay between the CS assert
 53	 * and the first clock edge as per the datasheet tHDSS timing requirement.
 54	 */
 55	xfers[0].delay.value = 2500;
 56	xfers[0].delay.unit = SPI_DELAY_UNIT_NSECS;
 57
 58	xfers[1].tx_buf = buf->tx;
 59	xfers[1].rx_buf = data->buffer;
 60	xfers[1].len = pkt_len;
 61
 62	return spi_sync_transfer(spi, xfers, ARRAY_SIZE(xfers));
 63}
 64
 65static const struct mpr_ops mpr_spi_ops = {
 66	.init = mpr_spi_init,
 67	.read = mpr_spi_xfer,
 68	.write = mpr_spi_xfer,
 69};
 70
 71static int mpr_spi_probe(struct spi_device *spi)
 72{
 73	return mpr_common_probe(&spi->dev, &mpr_spi_ops, spi->irq);
 74}
 75
 76static const struct of_device_id mpr_spi_match[] = {
 77	{ .compatible = "honeywell,mprls0025pa" },
 78	{ }
 79};
 80MODULE_DEVICE_TABLE(of, mpr_spi_match);
 81
 82static const struct spi_device_id mpr_spi_id[] = {
 83	{ "mprls0025pa" },
 84	{ }
 85};
 86MODULE_DEVICE_TABLE(spi, mpr_spi_id);
 87
 88static struct spi_driver mpr_spi_driver = {
 89	.driver = {
 90		.name = "mprls0025pa",
 91		.of_match_table = mpr_spi_match,
 92	},
 93	.probe = mpr_spi_probe,
 94	.id_table = mpr_spi_id,
 95};
 96module_spi_driver(mpr_spi_driver);
 97
 98MODULE_AUTHOR("Petre Rodan <petre.rodan@subdimension.ro>");
 99MODULE_DESCRIPTION("Honeywell MPR pressure sensor spi driver");
100MODULE_LICENSE("GPL");
101MODULE_IMPORT_NS("IIO_HONEYWELL_MPRLS0025PA");
~/ Read-only file preview.