2019-05-24 03:04:09 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2010-03-21 23:23:24 -07:00
|
|
|
/*
|
|
|
|
* AD714X CapTouch Programmable Controller driver (I2C bus)
|
|
|
|
*
|
2011-08-22 09:45:42 -07:00
|
|
|
* Copyright 2009-2011 Analog Devices Inc.
|
2010-03-21 23:23:24 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/input.h> /* BUS_I2C */
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/types.h>
|
2011-02-11 09:49:05 -07:00
|
|
|
#include <linux/pm.h>
|
2010-03-21 23:23:24 -07:00
|
|
|
#include "ad714x.h"
|
|
|
|
|
2011-08-22 09:45:39 -07:00
|
|
|
static int ad714x_i2c_write(struct ad714x_chip *chip,
|
|
|
|
unsigned short reg, unsigned short data)
|
2010-03-21 23:23:24 -07:00
|
|
|
{
|
2011-08-22 09:45:39 -07: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-21 23:23:24 -07:00
|
|
|
}
|
|
|
|
|
2011-08-22 09:45:39 -07:00
|
|
|
static int ad714x_i2c_read(struct ad714x_chip *chip,
|
2011-08-22 09:45:42 -07:00
|
|
|
unsigned short reg, unsigned short *data, size_t len)
|
2010-03-21 23:23:24 -07:00
|
|
|
{
|
2011-08-22 09:45:39 -07:00
|
|
|
struct i2c_client *client = to_i2c_client(chip->dev);
|
2011-08-22 09:45:42 -07:00
|
|
|
int i;
|
2011-08-22 09:45:39 -07:00
|
|
|
int error;
|
|
|
|
|
|
|
|
chip->xfer_buf[0] = cpu_to_be16(reg);
|
2010-03-21 23:23:24 -07:00
|
|
|
|
2011-08-22 09:45:39 -07: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-22 09:45:42 -07:00
|
|
|
len * sizeof(*chip->xfer_buf));
|
2010-03-21 23:23:24 -07:00
|
|
|
|
2011-08-22 09:45:39 -07:00
|
|
|
if (unlikely(error < 0)) {
|
|
|
|
dev_err(&client->dev, "I2C read error: %d\n", error);
|
|
|
|
return error;
|
2010-03-21 23:23:24 -07:00
|
|
|
}
|
|
|
|
|
2011-08-22 09:45:42 -07:00
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
data[i] = be16_to_cpu(chip->xfer_buf[i]);
|
|
|
|
|
2011-08-22 09:45:39 -07:00
|
|
|
return 0;
|
2010-03-21 23:23:24 -07:00
|
|
|
}
|
|
|
|
|
2022-11-18 15:39:00 -07:00
|
|
|
static int ad714x_i2c_probe(struct i2c_client *client)
|
2010-03-21 23:23:24 -07: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[] = {
|
2024-05-09 10:41:59 -07:00
|
|
|
{ "ad7142_captouch" },
|
|
|
|
{ "ad7143_captouch" },
|
|
|
|
{ "ad7147_captouch" },
|
|
|
|
{ "ad7147a_captouch" },
|
|
|
|
{ "ad7148_captouch" },
|
2010-03-21 23:23:24 -07:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, ad714x_id);
|
|
|
|
|
|
|
|
static struct i2c_driver ad714x_i2c_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "ad714x_captouch",
|
2023-01-14 10:16:11 -07:00
|
|
|
.pm = pm_sleep_ptr(&ad714x_pm),
|
2010-03-21 23:23:24 -07:00
|
|
|
},
|
2023-05-17 09:55:42 -07:00
|
|
|
.probe = ad714x_i2c_probe,
|
2010-03-21 23:23:24 -07:00
|
|
|
.id_table = ad714x_id,
|
|
|
|
};
|
|
|
|
|
2012-03-16 23:05:41 -07:00
|
|
|
module_i2c_driver(ad714x_i2c_driver);
|
2010-03-21 23:23:24 -07:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Analog Devices AD714X Capacitance Touch Sensor I2C Bus Driver");
|
|
|
|
MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
|
|
|
|
MODULE_LICENSE("GPL");
|