Message ID | 20231229092445.30180-11-petre.rodan@subdimension.ro (mailing list archive) |
---|---|
State | Accepted |
Headers | show |
Series | changes to mprls0025pa | expand |
On Fri, Dec 29, 2023 at 11:24:38AM +0200, Petre Rodan wrote: > 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) I believe these paragraphs can be moved to the patch submission comments from the commit message... > Tested-by: Andreas Klinger <ak@it-klinger.de> > Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro> > --- > v2 -> v3 removed iio.h include line ...somewhere here. ... > +#include <linux/mod_devicetable.h> > +#include <linux/module.h> > +#include <linux/spi/spi.h> > +#include <linux/stddef.h> Basically here we need additionally these ones: device.h errno.h types.h (I haven't checked i2c counterpart for the similarities).
hello Andy, On Sat, Jan 06, 2024 at 05:30:21PM +0200, Andy Shevchenko wrote: > On Fri, Dec 29, 2023 at 11:24:38AM +0200, Petre Rodan wrote: > > 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) > > I believe these paragraphs can be moved to the patch submission comments from > the commit message... > > > Tested-by: Andreas Klinger <ak@it-klinger.de> > > Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro> > > --- > > v2 -> v3 removed iio.h include line > > ...somewhere here. > > ... > > > +#include <linux/mod_devicetable.h> > > +#include <linux/module.h> > > +#include <linux/spi/spi.h> > > +#include <linux/stddef.h> > > Basically here we need additionally these ones: > > device.h > errno.h > types.h ok, I'll add errno.h. the other two are in the shared .h file. cheers, peter > (I haven't checked i2c counterpart for the similarities). > > -- > With Best Regards, > Andy Shevchenko > >
On Sat, Jan 06, 2024 at 06:02:52PM +0200, Petre Rodan wrote: > On Sat, Jan 06, 2024 at 05:30:21PM +0200, Andy Shevchenko wrote: > > On Fri, Dec 29, 2023 at 11:24:38AM +0200, Petre Rodan wrote: > > > Add SPI component of the driver. > > > +#include <linux/mod_devicetable.h> > > > +#include <linux/module.h> > > > +#include <linux/spi/spi.h> > > > +#include <linux/stddef.h> > > > > Basically here we need additionally these ones: > > > > device.h > > errno.h > > types.h > > ok, I'll add errno.h. the other two are in the shared .h file. Yes, but it's better to follow IWYI principle. Generally speaking there is no guarantee that above will be _always_ the case. Anyway, I leave this to Jonathan.
On Sat, 6 Jan 2024 18:07:55 +0200 Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > On Sat, Jan 06, 2024 at 06:02:52PM +0200, Petre Rodan wrote: > > On Sat, Jan 06, 2024 at 05:30:21PM +0200, Andy Shevchenko wrote: > > > On Fri, Dec 29, 2023 at 11:24:38AM +0200, Petre Rodan wrote: > > > > Add SPI component of the driver. > > > > > +#include <linux/mod_devicetable.h> > > > > +#include <linux/module.h> > > > > +#include <linux/spi/spi.h> > > > > +#include <linux/stddef.h> > > > > > > Basically here we need additionally these ones: > > > > > > device.h > > > errno.h > > > types.h > > > > ok, I'll add errno.h. the other two are in the shared .h file. > > Yes, but it's better to follow IWYI principle. Generally speaking > there is no guarantee that above will be _always_ the case. > > Anyway, I leave this to Jonathan. > When it's a local include to the driver like this I don't mind as much if the includes aren't there in the c file, but do generally 'slightly prefer' them to be so. As such I've added them here and in the i2c file (I also renamed that patch as 'refactor' isn't exactly descriptive in the patch title!) I suspect none of us feel that strongly about this so rather than slowing things down I took a fairly random decision that let me apply the series today. Anyhow, along with dropping the text on what this was tested on in the final patch - series applied to the togreg branch of iio.git. However, I'll be rebasing that tree on rc1 once available hence for now this will only be pushed out as testing for 0-day to get a head start on poking it. Thanks, Jonathan
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..32f6c2e60380 --- /dev/null +++ b/drivers/iio/pressure/mprls0025pa_spi.c @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * MPRLS0025PA - Honeywell MicroPressure MPR series SPI sensor driver + * + * Copyright (c) 2024 Petre Rodan <petre.rodan@subdimension.ro> + * + * 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 <linux/mod_devicetable.h> +#include <linux/module.h> +#include <linux/spi/spi.h> +#include <linux/stddef.h> + +#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 <petre.rodan@subdimension.ro>"); +MODULE_DESCRIPTION("Honeywell MPR pressure sensor spi driver"); +MODULE_LICENSE("GPL"); +MODULE_IMPORT_NS(IIO_HONEYWELL_MPRLS0025PA);