xref: /linux/drivers/iio/pressure/hsc030pa_i2c.c (revision 4b132aacb0768ac1e652cf517097ea6f237214b9)
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/board-mount-pressure-sensors/common/documents/sps-siot-i2c-comms-digital-output-pressure-sensors-tn-008201-3-en-ciid-45841.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/errno.h>
14 #include <linux/i2c.h>
15 #include <linux/mod_devicetable.h>
16 #include <linux/module.h>
17 #include <linux/types.h>
18 
19 #include <linux/iio/iio.h>
20 
21 #include "hsc030pa.h"
22 
23 static int hsc_i2c_recv(struct hsc_data *data)
24 {
25 	struct i2c_client *client = to_i2c_client(data->dev);
26 	struct i2c_msg msg;
27 	int ret;
28 
29 	msleep_interruptible(HSC_RESP_TIME_MS);
30 
31 	msg.addr = client->addr;
32 	msg.flags = client->flags | I2C_M_RD;
33 	msg.len = HSC_REG_MEASUREMENT_RD_SIZE;
34 	msg.buf = data->buffer;
35 
36 	ret = i2c_transfer(client->adapter, &msg, 1);
37 
38 	return (ret == 2) ? 0 : ret;
39 }
40 
41 static int hsc_i2c_probe(struct i2c_client *client)
42 {
43 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
44 		return -EOPNOTSUPP;
45 
46 	return hsc_common_probe(&client->dev, hsc_i2c_recv);
47 }
48 
49 static const struct of_device_id hsc_i2c_match[] = {
50 	{ .compatible = "honeywell,hsc030pa" },
51 	{}
52 };
53 MODULE_DEVICE_TABLE(of, hsc_i2c_match);
54 
55 static const struct i2c_device_id hsc_i2c_id[] = {
56 	{ "hsc030pa" },
57 	{}
58 };
59 MODULE_DEVICE_TABLE(i2c, hsc_i2c_id);
60 
61 static struct i2c_driver hsc_i2c_driver = {
62 	.driver = {
63 		.name = "hsc030pa",
64 		.of_match_table = hsc_i2c_match,
65 	},
66 	.probe = hsc_i2c_probe,
67 	.id_table = hsc_i2c_id,
68 };
69 module_i2c_driver(hsc_i2c_driver);
70 
71 MODULE_AUTHOR("Petre Rodan <petre.rodan@subdimension.ro>");
72 MODULE_DESCRIPTION("Honeywell HSC and SSC pressure sensor i2c driver");
73 MODULE_LICENSE("GPL");
74 MODULE_IMPORT_NS(IIO_HONEYWELL_HSC030PA);
75