treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / input / misc / ad714x-i2c.c
blobefeef135007a07204d84747b2b638212e5629a82
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * AD714X CapTouch Programmable Controller driver (I2C bus)
5 * Copyright 2009-2011 Analog Devices Inc.
6 */
8 #include <linux/input.h> /* BUS_I2C */
9 #include <linux/i2c.h>
10 #include <linux/module.h>
11 #include <linux/types.h>
12 #include <linux/pm.h>
13 #include "ad714x.h"
15 static int __maybe_unused ad714x_i2c_suspend(struct device *dev)
17 return ad714x_disable(i2c_get_clientdata(to_i2c_client(dev)));
20 static int __maybe_unused ad714x_i2c_resume(struct device *dev)
22 return ad714x_enable(i2c_get_clientdata(to_i2c_client(dev)));
25 static SIMPLE_DEV_PM_OPS(ad714x_i2c_pm, ad714x_i2c_suspend, ad714x_i2c_resume);
27 static int ad714x_i2c_write(struct ad714x_chip *chip,
28 unsigned short reg, unsigned short data)
30 struct i2c_client *client = to_i2c_client(chip->dev);
31 int error;
33 chip->xfer_buf[0] = cpu_to_be16(reg);
34 chip->xfer_buf[1] = cpu_to_be16(data);
36 error = i2c_master_send(client, (u8 *)chip->xfer_buf,
37 2 * sizeof(*chip->xfer_buf));
38 if (unlikely(error < 0)) {
39 dev_err(&client->dev, "I2C write error: %d\n", error);
40 return error;
43 return 0;
46 static int ad714x_i2c_read(struct ad714x_chip *chip,
47 unsigned short reg, unsigned short *data, size_t len)
49 struct i2c_client *client = to_i2c_client(chip->dev);
50 int i;
51 int error;
53 chip->xfer_buf[0] = cpu_to_be16(reg);
55 error = i2c_master_send(client, (u8 *)chip->xfer_buf,
56 sizeof(*chip->xfer_buf));
57 if (error >= 0)
58 error = i2c_master_recv(client, (u8 *)chip->xfer_buf,
59 len * sizeof(*chip->xfer_buf));
61 if (unlikely(error < 0)) {
62 dev_err(&client->dev, "I2C read error: %d\n", error);
63 return error;
66 for (i = 0; i < len; i++)
67 data[i] = be16_to_cpu(chip->xfer_buf[i]);
69 return 0;
72 static int ad714x_i2c_probe(struct i2c_client *client,
73 const struct i2c_device_id *id)
75 struct ad714x_chip *chip;
77 chip = ad714x_probe(&client->dev, BUS_I2C, client->irq,
78 ad714x_i2c_read, ad714x_i2c_write);
79 if (IS_ERR(chip))
80 return PTR_ERR(chip);
82 i2c_set_clientdata(client, chip);
84 return 0;
87 static const struct i2c_device_id ad714x_id[] = {
88 { "ad7142_captouch", 0 },
89 { "ad7143_captouch", 0 },
90 { "ad7147_captouch", 0 },
91 { "ad7147a_captouch", 0 },
92 { "ad7148_captouch", 0 },
93 { }
95 MODULE_DEVICE_TABLE(i2c, ad714x_id);
97 static struct i2c_driver ad714x_i2c_driver = {
98 .driver = {
99 .name = "ad714x_captouch",
100 .pm = &ad714x_i2c_pm,
102 .probe = ad714x_i2c_probe,
103 .id_table = ad714x_id,
106 module_i2c_driver(ad714x_i2c_driver);
108 MODULE_DESCRIPTION("Analog Devices AD714X Capacitance Touch Sensor I2C Bus Driver");
109 MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
110 MODULE_LICENSE("GPL");