xref: /linux/drivers/iio/pressure/hsc030pa_spi.c (revision 1e525507)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Honeywell TruStability HSC Series pressure/temperature sensor
4  *
5  * Copyright (c) 2023 Petre Rodan <petre.rodan@subdimension.ro>
6  *
7  * Datasheet: https://prod-edam.honeywell.com/content/dam/honeywell-edam/sps/siot/en-us/products/sensors/pressure-sensors/common/documents/sps-siot-spi-comms-digital-ouptu-pressure-sensors-tn-008202-3-en-ciid-45843.pdf
8  * Datasheet: https://prod-edam.honeywell.com/content/dam/honeywell-edam/sps/siot/en-us/products/sensors/pressure-sensors/common/documents/sps-siot-sleep-mode-technical-note-008286-1-en-ciid-155793.pdf
9  */
10 
11 #include <linux/delay.h>
12 #include <linux/device.h>
13 #include <linux/mod_devicetable.h>
14 #include <linux/module.h>
15 #include <linux/spi/spi.h>
16 #include <linux/stddef.h>
17 #include <linux/types.h>
18 
19 #include <linux/iio/iio.h>
20 
21 #include "hsc030pa.h"
22 
23 static int hsc_spi_recv(struct hsc_data *data)
24 {
25 	struct spi_device *spi = to_spi_device(data->dev);
26 	struct spi_transfer xfer = {
27 		.tx_buf = NULL,
28 		.rx_buf = data->buffer,
29 		.len = HSC_REG_MEASUREMENT_RD_SIZE,
30 	};
31 
32 	msleep_interruptible(HSC_RESP_TIME_MS);
33 	return spi_sync_transfer(spi, &xfer, 1);
34 }
35 
36 static int hsc_spi_probe(struct spi_device *spi)
37 {
38 	return hsc_common_probe(&spi->dev, hsc_spi_recv);
39 }
40 
41 static const struct of_device_id hsc_spi_match[] = {
42 	{ .compatible = "honeywell,hsc030pa" },
43 	{}
44 };
45 MODULE_DEVICE_TABLE(of, hsc_spi_match);
46 
47 static const struct spi_device_id hsc_spi_id[] = {
48 	{ "hsc030pa" },
49 	{}
50 };
51 MODULE_DEVICE_TABLE(spi, hsc_spi_id);
52 
53 static struct spi_driver hsc_spi_driver = {
54 	.driver = {
55 		.name = "hsc030pa",
56 		.of_match_table = hsc_spi_match,
57 	},
58 	.probe = hsc_spi_probe,
59 	.id_table = hsc_spi_id,
60 };
61 module_spi_driver(hsc_spi_driver);
62 
63 MODULE_AUTHOR("Petre Rodan <petre.rodan@subdimension.ro>");
64 MODULE_DESCRIPTION("Honeywell HSC and SSC pressure sensor spi driver");
65 MODULE_LICENSE("GPL");
66 MODULE_IMPORT_NS(IIO_HONEYWELL_HSC030PA);
67