Merge tag 'clk-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux.git] / drivers / iio / pressure / mprls0025pa_i2c.c
blob48b23a4256ced00f02d41853e6c0eb976124be8c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * MPRLS0025PA - Honeywell MicroPressure pressure sensor series driver
5 * Copyright (c) Andreas Klinger <ak@it-klinger.de>
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 */
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>
18 #include "mprls0025pa.h"
20 static int mpr_i2c_init(struct device *unused)
22 return 0;
25 static int mpr_i2c_read(struct mpr_data *data, const u8 unused, const u8 cnt)
27 int ret;
28 struct i2c_client *client = to_i2c_client(data->dev);
30 if (cnt > MPR_MEASUREMENT_RD_SIZE)
31 return -EOVERFLOW;
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;
40 return 0;
43 static int mpr_i2c_write(struct mpr_data *data, const u8 cmd, const u8 unused)
45 int ret;
46 struct i2c_client *client = to_i2c_client(data->dev);
47 u8 wdata[MPR_PKT_SYNC_LEN];
49 memset(wdata, 0, sizeof(wdata));
50 wdata[0] = cmd;
52 ret = i2c_master_send(client, wdata, MPR_PKT_SYNC_LEN);
53 if (ret < 0)
54 return ret;
55 else if (ret != MPR_PKT_SYNC_LEN)
56 return -EIO;
58 return 0;
61 static const struct mpr_ops mpr_i2c_ops = {
62 .init = mpr_i2c_init,
63 .read = mpr_i2c_read,
64 .write = mpr_i2c_write,
67 static int mpr_i2c_probe(struct i2c_client *client)
69 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_BYTE))
70 return -EOPNOTSUPP;
72 return mpr_common_probe(&client->dev, &mpr_i2c_ops, client->irq);
75 static const struct of_device_id mpr_i2c_match[] = {
76 { .compatible = "honeywell,mprls0025pa" },
79 MODULE_DEVICE_TABLE(of, mpr_i2c_match);
81 static const struct i2c_device_id mpr_i2c_id[] = {
82 { "mprls0025pa" },
85 MODULE_DEVICE_TABLE(i2c, mpr_i2c_id);
87 static struct i2c_driver mpr_i2c_driver = {
88 .probe = mpr_i2c_probe,
89 .id_table = mpr_i2c_id,
90 .driver = {
91 .name = "mprls0025pa",
92 .of_match_table = mpr_i2c_match,
95 module_i2c_driver(mpr_i2c_driver);
97 MODULE_AUTHOR("Andreas Klinger <ak@it-klinger.de>");
98 MODULE_DESCRIPTION("Honeywell MPR pressure sensor i2c driver");
99 MODULE_LICENSE("GPL");
100 MODULE_IMPORT_NS("IIO_HONEYWELL_MPRLS0025PA");