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 20 static int mpr_i2c_init(struct device *unused) 21 { 22 return 0; 23 } 24 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 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]; 48 49 memset(wdata, 0, sizeof(wdata)); 50 wdata[0] = cmd; 51 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; 57 58 return 0; 59 } 60 61 static const struct mpr_ops mpr_i2c_ops = { 62 .init = mpr_i2c_init, 63 .read = mpr_i2c_read, 64 .write = mpr_i2c_write, 65 }; 66 67 static int mpr_i2c_probe(struct i2c_client *client) 68 { 69 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_BYTE)) 70 return -EOPNOTSUPP; 71 72 return mpr_common_probe(&client->dev, &mpr_i2c_ops, client->irq); 73 } 74 75 static const struct of_device_id mpr_i2c_match[] = { 76 { .compatible = "honeywell,mprls0025pa" }, 77 {} 78 }; 79 MODULE_DEVICE_TABLE(of, mpr_i2c_match); 80 81 static const struct i2c_device_id mpr_i2c_id[] = { 82 { "mprls0025pa" }, 83 {} 84 }; 85 MODULE_DEVICE_TABLE(i2c, mpr_i2c_id); 86 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, 93 }, 94 }; 95 module_i2c_driver(mpr_i2c_driver); 96 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); 101