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