| 1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 |
/* |
| 3 |
* MPRLS0025PA - Honeywell MicroPressure pressure sensor series driver |
| 4 |
* |
| 5 |
* Copyright (c) Andreas Klinger <[email protected]> |
| 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 |
|
| 20 |
static int mpr_i2c_read(struct mpr_data *data, const u8 unused, const u8 cnt) |
| 21 |
{ |
| 22 |
int ret; |
| 23 |
struct i2c_client *client = to_i2c_client(data->dev); |
| 24 |
|
| 25 |
if (cnt > MPR_MEASUREMENT_RD_SIZE) |
| 26 |
return -EOVERFLOW; |
| 27 |
|
| 28 |
ret = i2c_master_recv(client, data->rx_buf, cnt); |
| 29 |
if (ret < 0) |
| 30 |
return ret; |
| 31 |
else if (ret != cnt) |
| 32 |
return -EIO; |
| 33 |
|
| 34 |
return 0; |
| 35 |
} |
| 36 |
|
| 37 |
static int mpr_i2c_write(struct mpr_data *data, const u8 cmd, const u8 unused) |
| 38 |
{ |
| 39 |
int ret; |
| 40 |
struct i2c_client *client = to_i2c_client(data->dev); |
| 41 |
|
| 42 |
data->tx_buf[0] = cmd; |
| 43 |
ret = i2c_master_send(client, data->tx_buf, MPR_PKT_SYNC_LEN); |
| 44 |
if (ret < 0) |
| 45 |
return ret; |
| 46 |
else if (ret != MPR_PKT_SYNC_LEN) |
| 47 |
return -EIO; |
| 48 |
|
| 49 |
return 0; |
| 50 |
} |
| 51 |
|
| 52 |
static const struct mpr_ops mpr_i2c_ops = { |
| 53 |
.read = mpr_i2c_read, |
| 54 |
.write = mpr_i2c_write, |
| 55 |
}; |
| 56 |
|
| 57 |
static int mpr_i2c_probe(struct i2c_client *client) |
| 58 |
{ |
| 59 |
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_BYTE)) |
| 60 |
return -EOPNOTSUPP; |
| 61 |
|
| 62 |
return mpr_common_probe(&client->dev, &mpr_i2c_ops, client->irq); |
| 63 |
} |
| 64 |
|
| 65 |
static const struct of_device_id mpr_i2c_match[] = { |
| 66 |
{ .compatible = "honeywell,mprls0025pa" }, |
| 67 |
{ } |
| 68 |
}; |
| 69 |
MODULE_DEVICE_TABLE(of, mpr_i2c_match); |
| 70 |
|
| 71 |
static const struct i2c_device_id mpr_i2c_id[] = { |
| 72 |
{ "mprls0025pa" }, |
| 73 |
{ } |
| 74 |
}; |
| 75 |
MODULE_DEVICE_TABLE(i2c, mpr_i2c_id); |
| 76 |
|
| 77 |
static struct i2c_driver mpr_i2c_driver = { |
| 78 |
.probe = mpr_i2c_probe, |
| 79 |
.id_table = mpr_i2c_id, |
| 80 |
.driver = { |
| 81 |
.name = "mprls0025pa", |
| 82 |
.of_match_table = mpr_i2c_match, |
| 83 |
}, |
| 84 |
}; |
| 85 |
module_i2c_driver(mpr_i2c_driver); |
| 86 |
|
| 87 |
MODULE_AUTHOR("Andreas Klinger <[email protected]>"); |
| 88 |
MODULE_DESCRIPTION("Honeywell MPR pressure sensor i2c driver"); |
| 89 |
MODULE_LICENSE("GPL"); |
| 90 |
MODULE_IMPORT_NS("IIO_HONEYWELL_MPRLS0025PA"); |