| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
/* |
| 3 |
* Honeywell ABP2 series pressure sensor driver |
| 4 |
* |
| 5 |
* Copyright (c) 2025 Petre Rodan <[email protected]> |
| 6 |
*/ |
| 7 |
|
| 8 |
#include <linux/errno.h> |
| 9 |
#include <linux/mod_devicetable.h> |
| 10 |
#include <linux/module.h> |
| 11 |
#include <linux/spi/spi.h> |
| 12 |
#include <linux/types.h> |
| 13 |
|
| 14 |
#include "abp2030pa.h" |
| 15 |
|
| 16 |
static int abp2_spi_xfer(struct abp2_data *data, u8 cmd, u8 nbytes) |
| 17 |
{ |
| 18 |
struct spi_device *spi = to_spi_device(data->dev); |
| 19 |
struct spi_transfer xfer = { }; |
| 20 |
|
| 21 |
if (nbytes > ABP2_MEASUREMENT_RD_SIZE) |
| 22 |
return -EOVERFLOW; |
| 23 |
|
| 24 |
data->tx_buf[0] = cmd; |
| 25 |
xfer.tx_buf = data->tx_buf; |
| 26 |
xfer.rx_buf = data->rx_buf; |
| 27 |
xfer.len = nbytes; |
| 28 |
|
| 29 |
return spi_sync_transfer(spi, &xfer, 1); |
| 30 |
} |
| 31 |
|
| 32 |
static const struct abp2_ops abp2_spi_ops = { |
| 33 |
.read = abp2_spi_xfer, |
| 34 |
.write = abp2_spi_xfer, |
| 35 |
}; |
| 36 |
|
| 37 |
static int abp2_spi_probe(struct spi_device *spi) |
| 38 |
{ |
| 39 |
return abp2_common_probe(&spi->dev, &abp2_spi_ops, spi->irq); |
| 40 |
} |
| 41 |
|
| 42 |
static const struct of_device_id abp2_spi_match[] = { |
| 43 |
{ .compatible = "honeywell,abp2030pa" }, |
| 44 |
{ } |
| 45 |
}; |
| 46 |
MODULE_DEVICE_TABLE(of, abp2_spi_match); |
| 47 |
|
| 48 |
static const struct spi_device_id abp2_spi_id[] = { |
| 49 |
{ "abp2030pa" }, |
| 50 |
{ } |
| 51 |
}; |
| 52 |
MODULE_DEVICE_TABLE(spi, abp2_spi_id); |
| 53 |
|
| 54 |
static struct spi_driver abp2_spi_driver = { |
| 55 |
.driver = { |
| 56 |
.name = "abp2030pa", |
| 57 |
.of_match_table = abp2_spi_match, |
| 58 |
}, |
| 59 |
.probe = abp2_spi_probe, |
| 60 |
.id_table = abp2_spi_id, |
| 61 |
}; |
| 62 |
module_spi_driver(abp2_spi_driver); |
| 63 |
|
| 64 |
MODULE_AUTHOR("Petre Rodan <[email protected]>"); |
| 65 |
MODULE_DESCRIPTION("Honeywell ABP2 pressure sensor spi driver"); |
| 66 |
MODULE_LICENSE("GPL"); |
| 67 |
MODULE_IMPORT_NS("IIO_HONEYWELL_ABP2030PA"); |