2019-05-24 18:04:09 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2010-03-22 14:23:24 +08:00
|
|
|
/*
|
|
|
|
* AD714X CapTouch Programmable Controller driver (I2C bus)
|
|
|
|
*
|
2011-08-23 00:45:42 +08:00
|
|
|
* Copyright 2009-2011 Analog Devices Inc.
|
2010-03-22 14:23:24 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/input.h> /* BUS_I2C */
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/types.h>
|
2011-02-12 00:49:05 +08:00
|
|
|
#include <linux/pm.h>
|
2010-03-22 14:23:24 +08:00
|
|
|
#include "ad714x.h"
|
|
|
|
|
2014-11-02 15:02:46 +08:00
|
|
|
static int __maybe_unused ad714x_i2c_suspend(struct device *dev)
|
2010-03-22 14:23:24 +08:00
|
|
|
{
|
2011-02-12 00:49:05 +08:00
|
|
|
return ad714x_disable(i2c_get_clientdata(to_i2c_client(dev)));
|
2010-03-22 14:23:24 +08:00
|
|
|
}
|
|
|
|
|
2014-11-02 15:02:46 +08:00
|
|
|
static int __maybe_unused ad714x_i2c_resume(struct device *dev)
|
2010-03-22 14:23:24 +08:00
|
|
|
{
|
2011-02-12 00:49:05 +08:00
|
|
|
return ad714x_enable(i2c_get_clientdata(to_i2c_client(dev)));
|
2010-03-22 14:23:24 +08:00
|
|
|
}
|
|
|
|
|
2011-02-12 00:49:05 +08:00
|
|
|
static SIMPLE_DEV_PM_OPS(ad714x_i2c_pm, ad714x_i2c_suspend, ad714x_i2c_resume);
|
|
|
|
|
2011-08-23 00:45:39 +08:00
|
|
|
static int ad714x_i2c_write(struct ad714x_chip *chip,
|
|
|
|
unsigned short reg, unsigned short data)
|
2010-03-22 14:23:24 +08:00
|
|
|
{
|
2011-08-23 00:45:39 +08:00
|
|
|
struct i2c_client *client = to_i2c_client(chip->dev);
|
|
|
|
int error;
|
|
|
|
|
|
|
|
chip->xfer_buf[0] = cpu_to_be16(reg);
|
|
|
|
chip->xfer_buf[1] = cpu_to_be16(data);
|
|
|
|
|
|
|
|
error = i2c_master_send(client, (u8 *)chip->xfer_buf,
|
|
|
|
2 * sizeof(*chip->xfer_buf));
|
|
|
|
if (unlikely(error < 0)) {
|
|
|
|
dev_err(&client->dev, "I2C write error: %d\n", error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2010-03-22 14:23:24 +08:00
|
|
|
}
|
|
|
|
|
2011-08-23 00:45:39 +08:00
|
|
|
static int ad714x_i2c_read(struct ad714x_chip *chip,
|
2011-08-23 00:45:42 +08:00
|
|
|
unsigned short reg, unsigned short *data, size_t len)
|
2010-03-22 14:23:24 +08:00
|
|
|
{
|
2011-08-23 00:45:39 +08:00
|
|
|
struct i2c_client *client = to_i2c_client(chip->dev);
|
2011-08-23 00:45:42 +08:00
|
|
|
int i;
|
2011-08-23 00:45:39 +08:00
|
|
|
int error;
|
|
|
|
|
|
|
|
chip->xfer_buf[0] = cpu_to_be16(reg);
|
2010-03-22 14:23:24 +08:00
|
|
|
|
2011-08-23 00:45:39 +08:00
|
|
|
error = i2c_master_send(client, (u8 *)chip->xfer_buf,
|
|
|
|
sizeof(*chip->xfer_buf));
|
|
|
|
if (error >= 0)
|
|
|
|
error = i2c_master_recv(client, (u8 *)chip->xfer_buf,
|
2011-08-23 00:45:42 +08:00
|
|
|
len * sizeof(*chip->xfer_buf));
|
2010-03-22 14:23:24 +08:00
|
|
|
|
2011-08-23 00:45:39 +08:00
|
|
|
if (unlikely(error < 0)) {
|
|
|
|
dev_err(&client->dev, "I2C read error: %d\n", error);
|
|
|
|
return error;
|
2010-03-22 14:23:24 +08:00
|
|
|
}
|
|
|
|
|
2011-08-23 00:45:42 +08:00
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
data[i] = be16_to_cpu(chip->xfer_buf[i]);
|
|
|
|
|
2011-08-23 00:45:39 +08:00
|
|
|
return 0;
|
2010-03-22 14:23:24 +08:00
|
|
|
}
|
|
|
|
|
2022-11-19 06:39:00 +08:00
|
|
|
static int ad714x_i2c_probe(struct i2c_client *client)
|
2010-03-22 14:23:24 +08:00
|
|
|
{
|
|
|
|
struct ad714x_chip *chip;
|
|
|
|
|
|
|
|
chip = ad714x_probe(&client->dev, BUS_I2C, client->irq,
|
|
|
|
ad714x_i2c_read, ad714x_i2c_write);
|
|
|
|
if (IS_ERR(chip))
|
|
|
|
return PTR_ERR(chip);
|
|
|
|
|
|
|
|
i2c_set_clientdata(client, chip);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct i2c_device_id ad714x_id[] = {
|
|
|
|
{ "ad7142_captouch", 0 },
|
2010-03-22 14:23:29 +08:00
|
|
|
{ "ad7143_captouch", 0 },
|
2010-03-22 14:23:24 +08:00
|
|
|
{ "ad7147_captouch", 0 },
|
2010-03-22 14:23:29 +08:00
|
|
|
{ "ad7147a_captouch", 0 },
|
|
|
|
{ "ad7148_captouch", 0 },
|
2010-03-22 14:23:24 +08:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, ad714x_id);
|
|
|
|
|
|
|
|
static struct i2c_driver ad714x_i2c_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "ad714x_captouch",
|
2011-02-12 00:49:05 +08:00
|
|
|
.pm = &ad714x_i2c_pm,
|
2010-03-22 14:23:24 +08:00
|
|
|
},
|
2022-11-19 06:39:00 +08:00
|
|
|
.probe_new = ad714x_i2c_probe,
|
2010-03-22 14:23:24 +08:00
|
|
|
.id_table = ad714x_id,
|
|
|
|
};
|
|
|
|
|
2012-03-17 14:05:41 +08:00
|
|
|
module_i2c_driver(ad714x_i2c_driver);
|
2010-03-22 14:23:24 +08:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Analog Devices AD714X Capacitance Touch Sensor I2C Bus Driver");
|
|
|
|
MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
|
|
|
|
MODULE_LICENSE("GPL");
|