i2c: chips: update cm3628 from vivo source.
Cherry-picked from: Evan McClain <aeroevan@gmail.com>
Change-Id: Icd30002667e3718bc8743e9951886e9a1042b7be
diff --git a/drivers/i2c/chips/cm3628.c b/drivers/i2c/chips/cm3628.c
index f2cea4c..fa4a4f1 100644
--- a/drivers/i2c/chips/cm3628.c
+++ b/drivers/i2c/chips/cm3628.c
@@ -28,7 +28,7 @@
#include <linux/miscdevice.h>
#include <linux/lightsensor.h>
#include <linux/slab.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
#include <asm/mach-types.h>
#include <linux/cm3628.h>
#include <linux/pl_sensor.h>
@@ -41,7 +41,7 @@
#define D(x...) pr_info(x)
-#define I2C_RETRY_COUNT 10
+#define I2C_RETRY_COUNT 3
#define POLLING_PROXIMITY 1
#define NO_IGNORE_BOOT_MODE 1
@@ -52,7 +52,7 @@
#define POLLING_DELAY 200
#define TH_ADD 3
#endif
-static int record_init_fail = 0;
+static int record_init_fail;
static void sensor_irq_do_work(struct work_struct *work);
static DECLARE_WORK(sensor_irq_work, sensor_irq_do_work);
@@ -71,8 +71,9 @@
struct input_dev *ls_input_dev;
struct input_dev *ps_input_dev;
-
+#ifdef CONFIG_HAS_EARLYSUSPEND
struct early_suspend early_suspend;
+#endif
struct i2c_client *i2c_client;
struct workqueue_struct *lp_wq;
@@ -134,8 +135,8 @@
static uint8_t ps_offset_adc;
static uint8_t ps_offset_adc2;
struct cm3628_info *lp_info;
-int enable_log = 0;
-int fLevel=-1;
+int enable_log;
+int fLevel = -1;
static struct mutex als_enable_mutex, als_disable_mutex, als_get_adc_mutex;
static int lightsensor_enable(struct cm3628_info *lpi);
static int lightsensor_disable(struct cm3628_info *lpi);
@@ -145,7 +146,6 @@
static int I2C_RxData(uint16_t slaveAddr, uint8_t *rxData, int length)
{
uint8_t loop_i;
- int val;
struct cm3628_info *lpi = lp_info;
struct i2c_msg msgs[] = {
@@ -168,13 +168,13 @@
if (i2c_transfer(lp_info->i2c_client->adapter, msgs, 1) > 0)
break;
- val = gpio_get_value(lpi->intr_pin);
+ /*val = gpio_get_value(lpi->intr_pin);*/
/*check intr GPIO when i2c error*/
- if (loop_i == 0 || loop_i == I2C_RETRY_COUNT -1)
- D("[PS][CM3628 error] %s, i2c err, slaveAddr 0x%x ISR gpio %d = %d, record_init_fail %d \n",
- __func__, slaveAddr, lpi->intr_pin, val, record_init_fail);
+ if (loop_i == 0 || loop_i == I2C_RETRY_COUNT - 1)
+ D("[PS][CM3628 error] %s, i2c err, slaveAddr 0x%x ISR gpio %d, record_init_fail %d \n",
+ __func__, slaveAddr, lpi->intr_pin, record_init_fail);
- msleep(10);
+ /*mdelay(1);*/
}
if (loop_i >= I2C_RETRY_COUNT) {
printk(KERN_ERR "[PS_ERR][CM3628 error] %s retry over %d\n",
@@ -188,7 +188,6 @@
static int I2C_TxData(uint16_t slaveAddr, uint8_t *txData, int length)
{
uint8_t loop_i;
- int val;
struct cm3628_info *lpi = lp_info;
struct i2c_msg msg[] = {
{
@@ -203,13 +202,12 @@
if (i2c_transfer(lp_info->i2c_client->adapter, msg, 1) > 0)
break;
- val = gpio_get_value(lpi->intr_pin);
/*check intr GPIO when i2c error*/
- if (loop_i == 0 || loop_i == I2C_RETRY_COUNT -1)
- D("[PS][CM3628 error] %s, i2c err, slaveAddr 0x%x, register 0x%x, value 0x%x, ISR gpio%d = %d, record_init_fail %d\n",
- __func__, slaveAddr, txData[0], txData[1], lpi->intr_pin, val, record_init_fail);
+ if (loop_i == 0 || loop_i == I2C_RETRY_COUNT - 1)
+ D("[PS][CM3628 error] %s, i2c err, slaveAddr 0x%x, register 0x%x, value 0x%x, ISR gpio%d, record_init_fail %d\n",
+ __func__, slaveAddr, txData[0], txData[1], lpi->intr_pin, record_init_fail);
- msleep(10);
+ /*mdelay(1);*/
}
if (loop_i >= I2C_RETRY_COUNT) {
@@ -388,7 +386,6 @@
input_report_abs(lpi->ps_input_dev, ABS_DISTANCE, 0);
input_sync(lpi->ps_input_dev);
blocking_notifier_call_chain(&psensor_notifier_list, 2, NULL);
- wake_lock_timeout(&(lpi->ps_wake_lock), 2*HZ);
}
static void report_psensor_input_event(struct cm3628_info *lpi, int interrupt_flag)
{
@@ -449,7 +446,6 @@
blocking_notifier_call_chain(&psensor_notifier_list, val+2, NULL);
}
- wake_lock_timeout(&(lpi->ps_wake_lock), 2*HZ);
}
static void enable_als_int(void)/*enable als interrupt*/
@@ -486,7 +482,7 @@
if (*(lpi->adc_table + i))
break;
}
- if ( i == 9) {/*avoid i = 10, because 'cali_table' of size is 10 */
+ if (i == 9) {/*avoid i = 10, because 'cali_table' of size is 10 */
level = i;
break;
}
@@ -508,9 +504,10 @@
lpi->current_level = level;
lpi->current_adc = adc_value;
/*D("[CM3628] %s: *(lpi->cali_table + (i - 1)) + 1 = 0x%X, *(lpi->cali_table + i) = 0x%x \n", __func__, *(lpi->cali_table + (i - 1)) + 1, *(lpi->cali_table + i));*/
- if(fLevel>=0){
- D("[LS][CM3628] L-sensor force level enable level=%d fLevel=%d\n",level,fLevel);
- level=fLevel;
+ if (fLevel >= 0) {
+ D("[LS][CM3628] L-sensor force level enable level=%d fLevel=%d\n",
+ level, fLevel);
+ level = fLevel;
}
input_report_abs(lpi->ls_input_dev, ABS_MISC, level);
input_sync(lpi->ls_input_dev);
@@ -552,12 +549,13 @@
uint8_t add = 0;
+ wake_lock_timeout(&(lpi->ps_wake_lock), 3*HZ);
/*check ALS or PS*/
_cm3628_I2C_Read_Byte(lpi->check_interrupt_add, &add);
/*D("[PS][CM3628] %s: check_interrupt_add = 0x%03X, add = 0x%x , add>>1 = 0x%x\n",
__func__, lpi->check_interrupt_add, add, add>>1);*/
add = add>>1;
- if (add == lpi->ALS_slave_address ) {
+ if (add == lpi->ALS_slave_address) {
report_lsensor_input_event(lpi, 0);
} else if (add == lpi->PS_slave_address) {
report_psensor_input_event(lpi, 1);
@@ -771,7 +769,7 @@
} else
report_psensor_input_event(lpi, 0);
- cmd = ( lpi->ps_conf1_val | CM3628_PS_INT_EN);
+ cmd = (lpi->ps_conf1_val | CM3628_PS_INT_EN);
enable_ps_int(cmd);
ret = set_irq_wake(lpi->irq, 1);
@@ -832,11 +830,10 @@
return ret;
}
while (1) {
- ret = psensor_set_disable (lpi);
+ ret = psensor_set_disable(lpi);
retry_count++;
- if (ret >= 0 || retry_count == 3) {
+ if (ret >= 0 || retry_count == 3)
break;
- }
}
if (ret < 0) {
pr_err("[PS][CM3628 error]%s: retry disable psensor fail\n", __func__);
@@ -1128,16 +1125,16 @@
if (lpi->ps_calibration_rule == 1) {
D("[PS][CM3628] %s: ps ADC value=0x%x, adc offset 0x%x\n",
__func__, value, lpi->ps_adc_offset);
- if (value >= lpi->ps_adc_offset )
- value = value -lpi->ps_adc_offset;
+ if (value >= lpi->ps_adc_offset)
+ value = value - lpi->ps_adc_offset;
else
value = 0;
} else if (lpi->ps_calibration_rule == 2 && lpi->ps_adc_offset > 0) {/*for saga*/
D("[PS][CM3628] %s: ps ADC value=0x%x, adc offset 0x%x, adc offset2 0x%x,\n",
__func__, value, lpi->ps_adc_offset, lpi->ps_adc_offset2);
- if (value < 20 ) {
- if (value >= lpi->ps_adc_offset )
- value = value -lpi->ps_adc_offset;
+ if (value < 20) {
+ if (value >= lpi->ps_adc_offset)
+ value = value - lpi->ps_adc_offset;
else
value = 0;
} else
@@ -1178,7 +1175,7 @@
}
static DEVICE_ATTR(ps_adc, 0664, ps_adc_show, ps_enable_store);
-
+/*
unsigned PS_cmd_test_value;
static ssize_t ps_parameters_show(struct device *dev,
struct device_attribute *attr, char *buf)
@@ -1207,8 +1204,8 @@
for (i = 0; i < 2; i++)
token[i] = strsep((char **)&buf, " ");
- lpi->ps_thd_set = simple_strtoul(token[0], NULL, 16);
- PS_cmd_test_value = simple_strtoul(token[1], NULL, 16);
+ lpi->ps_thd_set = strict_strtoul(token[0], 16);
+ PS_cmd_test_value = strict_strtoul(token[1], 16);
printk(KERN_INFO
"[PS][CM3628]Set lpi->ps_thd_set = 0x%x, PS_cmd_cmd:value = 0x%x\n",
lp_info->ps_thd_set, PS_cmd_test_value);
@@ -1221,7 +1218,7 @@
static DEVICE_ATTR(ps_parameters, 0664,
ps_parameters_show, ps_parameters_store);
-
+*/
static ssize_t ps_kadc_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -1261,7 +1258,7 @@
__func__, lpi->ps_thd_set);
}
if (lpi->ps_enable)
- enable_ps_int(lpi->ps_conf1_val |CM3628_PS_INT_EN);
+ enable_ps_int(lpi->ps_conf1_val | CM3628_PS_INT_EN);
lpi->inte_cancel_set = (param2 & 0xFF);
ps_cancel_set = lpi->inte_cancel_set;
@@ -1308,7 +1305,7 @@
static DEVICE_ATTR(ps_conf2, 0664, ps_conf2_show, ps_conf2_store);
-static uint8_t PS_CONF1 = 0;
+static uint8_t PS_CONF1;
static ssize_t ps_conf1_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -1335,7 +1332,7 @@
}
static DEVICE_ATTR(ps_conf1, 0664, ps_conf1_show, ps_conf1_store);
-static uint8_t PS_THD = 0;
+static uint8_t PS_THD;
static ssize_t ps_thd_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -1557,7 +1554,7 @@
}
static DEVICE_ATTR(ls_kadc, 0664, ls_kadc_show, ls_kadc_store);
-
+/*
static ssize_t ls_adc_table_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -1588,7 +1585,7 @@
printk(KERN_INFO "[LS][CM3628]%s\n", buf);
for (i = 0; i < 10; i++) {
token[i] = strsep((char **)&buf, " ");
- tempdata[i] = simple_strtoul(token[i], NULL, 16);
+ tempdata[i] = strict_strtoul(token[i], 16);
if (tempdata[i] < 1 || tempdata[i] > 0xffff) {
printk(KERN_ERR
"[LS][CM3628 error] adc_table[%d] = 0x%x Err\n",
@@ -1614,8 +1611,8 @@
static DEVICE_ATTR(ls_adc_table, 0664,
ls_adc_table_show, ls_adc_table_store);
-
-static uint8_t ALS_CONF1 = 0;
+*/
+static uint8_t ALS_CONF1;
static ssize_t ls_conf1_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -1636,7 +1633,7 @@
}
static DEVICE_ATTR(ls_conf1, 0664, ls_conf1_show, ls_conf1_store);
-static uint8_t ALS_CONF2 = 0;
+static uint8_t ALS_CONF2;
static ssize_t ls_conf2_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -1667,16 +1664,16 @@
const char *buf, size_t count)
{
struct cm3628_info *lpi = lp_info;
- int value=0;
+ int value = 0;
sscanf(buf, "%d", &value);
- (value>=0)?(value=min(value,10)):(value=max(value,-1));
- fLevel=value;
+ (value >= 0)?(value = min(value, 10)):(value = max(value, -1));
+ fLevel = value;
input_report_abs(lpi->ls_input_dev, ABS_MISC, fLevel);
input_sync(lpi->ls_input_dev);
printk(KERN_INFO "[LS]set fLevel = %d\n", fLevel);
msleep(1000);
- fLevel=-1;
+ fLevel = -1;
return count;
}
static DEVICE_ATTR(ls_flevel, 0664, ls_fLevel_show, ls_fLevel_store);
@@ -1771,29 +1768,29 @@
check_interrupt_gpio:
if (fail_counter > 0) {
- ret =_cm3628_I2C_Read_Byte(lpi->check_interrupt_add, &add);
+ ret = _cm3628_I2C_Read_Byte(lpi->check_interrupt_add, &add);
D("[PS][CM3628] %s, check_interrupt_add value = 0x%x, ret %d\n",
__func__, add, ret);
}
ret = _cm3628_I2C_Write_Byte(lpi->ALS_slave_address,
ALS_cmd_cmd, CM3628_ALS_BIT2_Default_1);/*0x04 bit[3:2] */
- if ((ret < 0) && (fail_counter < 10)) {
+ if ((ret < 0) && (fail_counter < 4)) {
fail_counter++;
- val = gpio_get_value(lpi->intr_pin);
+ /*val = gpio_get_value_cansleep(lpi->intr_pin);
D("[LS][CM3628] %s, interrupt GPIO val = %d, , inital fail_counter %d\n",
- __func__, val, fail_counter);
+ __func__, val, fail_counter);*/
goto check_interrupt_gpio;
}
ret = _cm3628_I2C_Write_Byte(lpi->PS_slave_address,
PS_cmd_cmd, 0x00);/*first init need 0x0*/
- if ((ret < 0) && (fail_counter < 10)) {
+ if ((ret < 0) && (fail_counter < 4)) {
fail_counter++;
- val = gpio_get_value(lpi->intr_pin);
+ /*val = gpio_get_value_cansleep(lpi->intr_pin);
D("[PS][CM3628] %s, interrupt GPIO val = %d, , inital fail_counter %d\n",
- __func__, val, fail_counter);
+ __func__, val, fail_counter);*/
goto check_interrupt_gpio;
}
- if (fail_counter >= 10) {
+ if (fail_counter >= 4) {
D("[PS][CM3628] %s, initial fail_counter = %d\n", __func__, fail_counter);
if (record_init_fail == 0)
record_init_fail = 1;
@@ -1850,7 +1847,7 @@
psensor_initial_cmd(lpi);
_cm3628_I2C_Write_Byte(lpi->PS_slave_address,
PS_cmd_cmd,
- lpi->ps_conf1_val |CM3628_PS_SD);
+ lpi->ps_conf1_val | CM3628_PS_SD);
/*Default disable P sensor*/
lpi->led = 0;
@@ -1874,7 +1871,7 @@
gpio_free(lpi->intr_pin);
return ret;
}
-
+#ifdef CONFIG_HAS_EARLYSUSPEND
static void cm3628_early_suspend(struct early_suspend *h)
{
struct cm3628_info *lpi = lp_info;
@@ -1895,13 +1892,14 @@
if (!lpi->als_enable)
lightsensor_enable(lpi);
}
-
+#endif
static int cm3628_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
int ret = 0;
struct cm3628_info *lpi;
struct cm3628_platform_data *pdata;
+ int irq = 0;
D("[PS][CM3628] %s\n", __func__);
@@ -1920,9 +1918,11 @@
ret = -EBUSY;
goto err_platform_data_null;
}
+ irq = gpio_to_irq(pdata->intr);/*for kernel 3.0*/
- lpi->irq = client->irq;
-
+ lpi->irq = irq;
+ pr_info("[PS][CM3628]%s: client->irq %d, irq %d!!\n",
+ __func__, client->irq, irq);
lpi->mfg_mode = board_mfg_mode();
i2c_set_clientdata(client, lpi);
@@ -1953,9 +1953,8 @@
lpi->ps_reset_thd = pdata->ps_reset_thd;
D("[PS][CM3628] %s: is_cmd 0x%x, ps_adc_offset=0x%x, ps_debounce=0x%x\n",
__func__, lpi->is_cmd, lpi->ps_adc_offset, lpi->ps_debounce);
- if (pdata->is_cmd == 0) {
+ if (pdata->is_cmd == 0)
lpi->is_cmd = CM3628_ALS_IT_400ms | CM3628_ALS_PERS_4;
- }
lp_info = lpi;
@@ -2038,9 +2037,9 @@
if (ret)
goto err_create_ls_device_file;
- ret = device_create_file(lpi->ls_dev, &dev_attr_ls_adc_table);
+ /*ret = device_create_file(lpi->ls_dev, &dev_attr_ls_adc_table);
if (ret)
- goto err_create_ls_device_file;
+ goto err_create_ls_device_file;*/
ret = device_create_file(lpi->ls_dev, &dev_attr_ls_conf1);
if (ret)
@@ -2067,11 +2066,11 @@
if (ret)
goto err_create_ps_device;
- ret = device_create_file(lpi->ps_dev,
+ /*ret = device_create_file(lpi->ps_dev,
&dev_attr_ps_parameters);
if (ret)
goto err_create_ps_device;
-
+*/
/* register the attributes */
ret = device_create_file(lpi->ps_dev, &dev_attr_ps_kadc);
if (ret)
@@ -2100,13 +2099,13 @@
ret = device_create_file(lpi->ps_dev, &dev_attr_ps_hw);
if (ret)
goto err_create_ps_device;
-
+#ifdef CONFIG_HAS_EARLYSUSPEND
lpi->early_suspend.level =
EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
lpi->early_suspend.suspend = cm3628_early_suspend;
lpi->early_suspend.resume = cm3628_late_resume;
register_early_suspend(&lpi->early_suspend);
-
+#endif
D("[PS][CM3628] %s: Probe success!\n", __func__);
return ret;
diff --git a/include/linux/cm3628.h b/include/linux/cm3628.h
index 0b9ecee..81ae81e 100644
--- a/include/linux/cm3628.h
+++ b/include/linux/cm3628.h
@@ -91,12 +91,13 @@
extern unsigned int ps_kparam1;
extern unsigned int ps_kparam2;
-
+extern unsigned int als_kadc;
struct cm3628_platform_data {
int intr;
uint16_t levels[10];
uint16_t golden_adc;
int (*power)(int, uint8_t); /* power to the chip */
+ int (*re_power)(uint8_t); /* power to the chip */
uint8_t ALS_IT;
uint8_t ALS_PERS;
uint8_t ALS_AV;