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