/*
* AD714X CapTouch Programmable Controller driver supporting AD7142/3/7/8/7A
*
* Copyright 2009-2011 Analog Devices Inc.
*
* Licensed under the GPL-2 or later.
*/
#include <linux/device.h>
#include <linux/init.h>
#include <linux/input.h>
#include <linux/interrupt.h>
#include <linux/slab.h>
#include <linux/input/ad714x.h>
#include <linux/module.h>
#include "ad714x.h"
#define AD714X_PWR_CTRL 0x0
#define AD714X_STG_CAL_EN_REG 0x1
#define AD714X_AMB_COMP_CTRL0_REG 0x2
#define AD714X_PARTID_REG 0x17
#define AD7142_PARTID 0xE620
#define AD7143_PARTID 0xE630
#define AD7147_PARTID 0x1470
#define AD7148_PARTID 0x1480
#define AD714X_STAGECFG_REG 0x80
#define AD714X_SYSCFG_REG 0x0
#define STG_LOW_INT_EN_REG 0x5
#define STG_HIGH_INT_EN_REG 0x6
#define STG_COM_INT_EN_REG 0x7
#define STG_LOW_INT_STA_REG 0x8
#define STG_HIGH_INT_STA_REG 0x9
#define STG_COM_INT_STA_REG 0xA
#define CDC_RESULT_S0 0xB
#define CDC_RESULT_S1 0xC
#define CDC_RESULT_S2 0xD
#define CDC_RESULT_S3 0xE
#define CDC_RESULT_S4 0xF
#define CDC_RESULT_S5 0x10
#define CDC_RESULT_S6 0x11
#define CDC_RESULT_S7 0x12
#define CDC_RESULT_S8 0x13
#define CDC_RESULT_S9 0x14
#define CDC_RESULT_S10 0x15
#define CDC_RESULT_S11 0x16
#define STAGE0_AMBIENT 0xF1
#define STAGE1_AMBIENT 0x115
#define STAGE2_AMBIENT 0x139
#define STAGE3_AMBIENT 0x15D
#define STAGE4_AMBIENT 0x181
#define STAGE5_AMBIENT 0x1A5
#define STAGE6_AMBIENT 0x1C9
#define STAGE7_AMBIENT 0x1ED
#define STAGE8_AMBIENT 0x211
#define STAGE9_AMBIENT 0x234
#define STAGE10_AMBIENT 0x259
#define STAGE11_AMBIENT 0x27D
#define PER_STAGE_REG_NUM 36
#define STAGE_CFGREG_NUM 8
#define SYS_CFGREG_NUM 8
/*
* driver information which will be used to maintain the software flow
*/
enum ad714x_device_state { IDLE, JITTER, ACTIVE, SPACE };
struct ad714x_slider_drv {
int highest_stage;
int abs_pos;
int flt_pos;
enum ad714x_device_state state;
struct input_dev *input;
};
struct ad714x_wheel_drv {
int abs_pos;
int flt_pos;
int pre_highest_stage;
int highest_stage;
enum ad714x_device_state state;
struct input_dev *input;
};
struct ad714x_touchpad_drv {
int x_highest_stage;
int x_flt_pos;
int x_abs_pos;
int y_highest_stage;
int y_flt_pos;
int y_abs_pos;
int left_ep;
int left_ep_val;
int right_ep;
int right_ep_val;
int top_ep;
int top_ep_val;
int bottom_ep;
int bottom_ep_val;
enum ad714x_device_state state;
struct input_dev *input;
};
struct ad714x_button_drv {
enum ad714x_device_state state;
/*
* Unlike slider/wheel/touchpad, all buttons point to
* same input_dev instance
*/
struct input_dev *input;
};
struct ad714x_driver_data {
struct ad714x_slider_drv *slider;
struct ad714x_wheel_drv *wheel;
struct ad714x_touchpad_drv *touchpad;
struct ad714x_button_drv *button;
};
/*
* information to integrate all things which will be private data
* of spi/i2c device
*/
static void ad714x_use_com_int(struct ad714x_chip *ad714x,
int start_stage, int end_stage)
{
unsigned short data;
unsigned short mask;
mask = ((1 << (end_stage + 1)) - 1) - ((1 << start_stage) - 1);
ad714x->read(ad714x, STG_COM_INT_EN_REG, &data, 1);
data |= 1 <<