1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * AD714X CapTouch Programmable Controller driver (I2C bus)
5 * Copyright 2009-2011 Analog Devices Inc.
8 #include <linux/input.h> /* BUS_I2C */
10 #include <linux/module.h>
11 #include <linux/types.h>
15 static int ad714x_i2c_write(struct ad714x_chip
*chip
,
16 unsigned short reg
, unsigned short data
)
18 struct i2c_client
*client
= to_i2c_client(chip
->dev
);
21 chip
->xfer_buf
[0] = cpu_to_be16(reg
);
22 chip
->xfer_buf
[1] = cpu_to_be16(data
);
24 error
= i2c_master_send(client
, (u8
*)chip
->xfer_buf
,
25 2 * sizeof(*chip
->xfer_buf
));
26 if (unlikely(error
< 0)) {
27 dev_err(&client
->dev
, "I2C write error: %d\n", error
);
34 static int ad714x_i2c_read(struct ad714x_chip
*chip
,
35 unsigned short reg
, unsigned short *data
, size_t len
)
37 struct i2c_client
*client
= to_i2c_client(chip
->dev
);
41 chip
->xfer_buf
[0] = cpu_to_be16(reg
);
43 error
= i2c_master_send(client
, (u8
*)chip
->xfer_buf
,
44 sizeof(*chip
->xfer_buf
));
46 error
= i2c_master_recv(client
, (u8
*)chip
->xfer_buf
,
47 len
* sizeof(*chip
->xfer_buf
));
49 if (unlikely(error
< 0)) {
50 dev_err(&client
->dev
, "I2C read error: %d\n", error
);
54 for (i
= 0; i
< len
; i
++)
55 data
[i
] = be16_to_cpu(chip
->xfer_buf
[i
]);
60 static int ad714x_i2c_probe(struct i2c_client
*client
)
62 struct ad714x_chip
*chip
;
64 chip
= ad714x_probe(&client
->dev
, BUS_I2C
, client
->irq
,
65 ad714x_i2c_read
, ad714x_i2c_write
);
69 i2c_set_clientdata(client
, chip
);
74 static const struct i2c_device_id ad714x_id
[] = {
75 { "ad7142_captouch" },
76 { "ad7143_captouch" },
77 { "ad7147_captouch" },
78 { "ad7147a_captouch" },
79 { "ad7148_captouch" },
82 MODULE_DEVICE_TABLE(i2c
, ad714x_id
);
84 static struct i2c_driver ad714x_i2c_driver
= {
86 .name
= "ad714x_captouch",
87 .pm
= pm_sleep_ptr(&ad714x_pm
),
89 .probe
= ad714x_i2c_probe
,
90 .id_table
= ad714x_id
,
93 module_i2c_driver(ad714x_i2c_driver
);
95 MODULE_DESCRIPTION("Analog Devices AD714X Capacitance Touch Sensor I2C Bus Driver");
96 MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
97 MODULE_LICENSE("GPL");