1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Honeywell ABP2 series pressure sensor driver 4 * 5 * Copyright (c) 2025 Petre Rodan <petre.rodan@subdimension.ro> 6 */ 7 8 #include <linux/device.h> 9 #include <linux/errno.h> 10 #include <linux/i2c.h> 11 #include <linux/mod_devicetable.h> 12 #include <linux/module.h> 13 #include <linux/types.h> 14 15 #include "abp2030pa.h" 16 17 static int abp2_i2c_read(struct abp2_data *data, u8 unused, u8 nbytes) 18 { 19 struct i2c_client *client = to_i2c_client(data->dev); 20 int ret; 21 22 if (nbytes > ABP2_MEASUREMENT_RD_SIZE) 23 return -EOVERFLOW; 24 25 ret = i2c_master_recv(client, data->rx_buf, nbytes); 26 if (ret < 0) 27 return ret; 28 if (ret != nbytes) 29 return -EIO; 30 31 return 0; 32 } 33 34 static int abp2_i2c_write(struct abp2_data *data, u8 cmd, u8 nbytes) 35 { 36 struct i2c_client *client = to_i2c_client(data->dev); 37 int ret; 38 39 if (nbytes > ABP2_MEASUREMENT_RD_SIZE) 40 return -EOVERFLOW; 41 42 data->tx_buf[0] = cmd; 43 ret = i2c_master_send(client, data->tx_buf, nbytes); 44 if (ret < 0) 45 return ret; 46 if (ret != nbytes) 47 return -EIO; 48 49 return 0; 50 } 51 52 static const struct abp2_ops abp2_i2c_ops = { 53 .read = abp2_i2c_read, 54 .write = abp2_i2c_write, 55 }; 56 57 static int abp2_i2c_probe(struct i2c_client *client) 58 { 59 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 60 return -EOPNOTSUPP; 61 62 return abp2_common_probe(&client->dev, &abp2_i2c_ops, client->irq); 63 } 64 65 static const struct of_device_id abp2_i2c_match[] = { 66 { .compatible = "honeywell,abp2030pa" }, 67 { } 68 }; 69 MODULE_DEVICE_TABLE(of, abp2_i2c_match); 70 71 static const struct i2c_device_id abp2_i2c_id[] = { 72 { "abp2030pa" }, 73 { } 74 }; 75 MODULE_DEVICE_TABLE(i2c, abp2_i2c_id); 76 77 static struct i2c_driver abp2_i2c_driver = { 78 .driver = { 79 .name = "abp2030pa", 80 .of_match_table = abp2_i2c_match, 81 }, 82 .probe = abp2_i2c_probe, 83 .id_table = abp2_i2c_id, 84 }; 85 module_i2c_driver(abp2_i2c_driver); 86 87 MODULE_AUTHOR("Petre Rodan <petre.rodan@subdimension.ro>"); 88 MODULE_DESCRIPTION("Honeywell ABP2 pressure sensor i2c driver"); 89 MODULE_LICENSE("GPL"); 90 MODULE_IMPORT_NS("IIO_HONEYWELL_ABP2030PA"); 91