1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * MPRLS0025PA - Honeywell MicroPressure pressure sensor series driver
4 *
5 * Copyright (c) Andreas Klinger <ak@it-klinger.de>
6 *
7 * Data sheet:
8 * 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
9 */
10
11 #include <linux/device.h>
12 #include <linux/errno.h>
13 #include <linux/i2c.h>
14 #include <linux/mod_devicetable.h>
15 #include <linux/module.h>
16 #include <linux/types.h>
17
18 #include "mprls0025pa.h"
19
mpr_i2c_init(struct device * unused)20 static int mpr_i2c_init(struct device *unused)
21 {
22 return 0;
23 }
24
mpr_i2c_read(struct mpr_data * data,const u8 unused,const u8 cnt)25 static int mpr_i2c_read(struct mpr_data *data, const u8 unused, const u8 cnt)
26 {
27 int ret;
28 struct i2c_client *client = to_i2c_client(data->dev);
29
30 if (cnt > MPR_MEASUREMENT_RD_SIZE)
31 return -EOVERFLOW;
32
33 memset(data->buffer, 0, MPR_MEASUREMENT_RD_SIZE);
34 ret = i2c_master_recv(client, data->buffer, cnt);
35 if (ret < 0)
36 return ret;
37 else if (ret != cnt)
38 return -EIO;
39
40 return 0;
41 }
42
mpr_i2c_write(struct mpr_data * data,const u8 cmd,const u8 unused)43 static int mpr_i2c_write(struct mpr_data *data, const u8 cmd, const u8 unused)
44 {
45 int ret;
46 struct i2c_client *client = to_i2c_client(data->dev);
47 u8 wdata[MPR_PKT_SYNC_LEN] = { cmd };
48
49 ret = i2c_master_send(client, wdata, MPR_PKT_SYNC_LEN);
50 if (ret < 0)
51 return ret;
52 else if (ret != MPR_PKT_SYNC_LEN)
53 return -EIO;
54
55 return 0;
56 }
57
58 static const struct mpr_ops mpr_i2c_ops = {
59 .init = mpr_i2c_init,
60 .read = mpr_i2c_read,
61 .write = mpr_i2c_write,
62 };
63
mpr_i2c_probe(struct i2c_client * client)64 static int mpr_i2c_probe(struct i2c_client *client)
65 {
66 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_BYTE))
67 return -EOPNOTSUPP;
68
69 return mpr_common_probe(&client->dev, &mpr_i2c_ops, client->irq);
70 }
71
72 static const struct of_device_id mpr_i2c_match[] = {
73 { .compatible = "honeywell,mprls0025pa" },
74 { }
75 };
76 MODULE_DEVICE_TABLE(of, mpr_i2c_match);
77
78 static const struct i2c_device_id mpr_i2c_id[] = {
79 { "mprls0025pa" },
80 { }
81 };
82 MODULE_DEVICE_TABLE(i2c, mpr_i2c_id);
83
84 static struct i2c_driver mpr_i2c_driver = {
85 .probe = mpr_i2c_probe,
86 .id_table = mpr_i2c_id,
87 .driver = {
88 .name = "mprls0025pa",
89 .of_match_table = mpr_i2c_match,
90 },
91 };
92 module_i2c_driver(mpr_i2c_driver);
93
94 MODULE_AUTHOR("Andreas Klinger <ak@it-klinger.de>");
95 MODULE_DESCRIPTION("Honeywell MPR pressure sensor i2c driver");
96 MODULE_LICENSE("GPL");
97 MODULE_IMPORT_NS("IIO_HONEYWELL_MPRLS0025PA");
98