Skip to content

Instantly share code, notes, and snippets.

@invisiblek
Created July 13, 2016 21:10
Show Gist options
  • Save invisiblek/1f9bbbbd6155b6f8fb87efea65ee9773 to your computer and use it in GitHub Desktop.
Save invisiblek/1f9bbbbd6155b6f8fb87efea65ee9773 to your computer and use it in GitHub Desktop.
diff --git a/drivers/i2c/chips/CwMcuSensor.c b/drivers/i2c/chips/CwMcuSensor.c
index fac1dbb..c390305 100644
--- a/drivers/i2c/chips/CwMcuSensor.c
+++ b/drivers/i2c/chips/CwMcuSensor.c
@@ -69,7 +69,7 @@ static int UseWakeMcu = 0;
#define MAX_BACKUP_CALL_STACK_SIZE 64
#define MAX_CALL_STACK_SIZE 512
#define MAX_I2C_BUF_SIZE 32
-#define VIB_TIME 40
+#define VIB_TIME 20
static int cwmcu_opened;
static int cwmcu_wdg_reset = 0;
static int cwmcu_i2c_error = 0;
@@ -119,7 +119,6 @@ struct wake_lock ges_wake_lock;
struct wake_lock significant_wake_lock;
static int power_key_pressed = 0;
-static int tap2wake = 0;
struct CWMCU_data {
struct i2c_client *client;
atomic_t delay;
@@ -924,9 +923,15 @@ static int get_proximity(struct device *dev, struct device_attribute *attr, char
u8 data[3]={0};
uint16_t data2;
- CWMCU_i2c_read(mcu_data, CWSTM32_READ_Proximity, data, 3);
- data2 = (data[2] << 8) | data[1];
- return snprintf(buf, PAGE_SIZE, "%x %x \n",data[0],data2);
+ if(mcu_data->enabled_list & (1<<Proximity)){
+ CWMCU_i2c_read(mcu_data, CWSTM32_READ_Proximity, data, 3);
+ data2 = (data[2] << 8) | data[1];
+ return snprintf(buf, PAGE_SIZE, "%x %x \n",data[0],data2);
+ } else {
+
+ D("get_proximity when proximity is not enabled!!\n");
+ return snprintf(buf, PAGE_SIZE, "%x %x \n", 9, 0);
+ }
}
static int get_proximity_polling(struct device *dev, struct device_attribute *attr, char *buf){
@@ -1600,26 +1605,6 @@ static int boot_mode_show(struct device *dev, struct device_attribute *attr, cha
return snprintf(buf, PAGE_SIZE, "%d\n", -1);
}
-static int tap2wake_set(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t count)
-{
- int val;
- sscanf(buf, "%du", &val);
-
- if (val > 1 || val < 0) {
- pr_err("[CWMCU] %s: tap2wake value %d is invalid!\n", __func__, val);
- } else {
- tap2wake = val;
- }
-
- return count;
-}
-
-static int tap2wake_show(struct device *dev, struct device_attribute *attr, char *buf)
-{
- return sprintf(buf, "%d\n", tap2wake);
-}
-
#if 0
static DEVICE_ATTR(enable, 0666, active_show,
active_set);
@@ -1779,7 +1764,7 @@ static void CWMCU_read(struct CWMCU_data *sensor)
D("%s: Accelerometer(x, y, z) = (%d, %d, %d), Filtered\n",
__func__, data_buff[0], data_buff[1], data_buff[2]);
} else {
- input_report_abs(sensor->input, ABS_ACC_X, 1);
+ input_report_abs(sensor->input, ABS_ACC_X, 10000);
input_report_abs(sensor->input, ABS_ACC_X, data_buff[0]);
input_report_abs(sensor->input, ABS_ACC_Y, data_buff[1]);
input_report_abs(sensor->input, ABS_ACC_Z, data_buff[2]);
@@ -1855,7 +1840,7 @@ static void CWMCU_read(struct CWMCU_data *sensor)
D("%s: Gyro(x, y, z) = (%d, %d, %d), Filtered\n",
__func__, data_buff[0], data_buff[1], data_buff[2]);
} else {
- input_report_abs(sensor->input, ABS_GYRO_X, 1);
+ input_report_abs(sensor->input, ABS_GYRO_X, 10000);
input_report_abs(sensor->input, ABS_GYRO_X, data_buff[0]);
input_report_abs(sensor->input, ABS_GYRO_Y, data_buff[1]);
input_report_abs(sensor->input, ABS_GYRO_Z, data_buff[2]);
@@ -2074,7 +2059,7 @@ static void CWMCU_read(struct CWMCU_data *sensor)
D("%s: LinearAcceleration(0, 1, 2) = (%d, %d, %d), Filtered\n",
__func__, data_buff[0], data_buff[1], data_buff[2]);
} else {
- input_report_abs(sensor->input, ABS_LIN_X, 1);
+ input_report_abs(sensor->input, ABS_LIN_X, 10000);
input_report_abs(sensor->input, ABS_LIN_X, data_buff[0]);
input_report_abs(sensor->input, ABS_LIN_Y, data_buff[1]);
input_report_abs(sensor->input, ABS_LIN_Z, data_buff[2]);
@@ -2975,21 +2960,35 @@ static void cwmcu_irq_work_func(struct work_struct *work)
D("[CWMCU]CW_MCU_INT_BIT_HTC_GESTURE_MOTION_HIDI: i2c bus read %d bytes\n", ret);
data_event = (s32)((data[0] & 0x1F) | (((data[1] | (data[2] << 8)) & 0x3FF) << 5) | (data[3] << 15) | (data[4] << 23));
if (vib_trigger) {
- /* 15 is the tap to wake gesture */
- if (data[0] == 15) {
- if (tap2wake == 1) {
- D("[CWMCU] Tap to wake - waking device\n");
- vib_trigger_event(vib_trigger, VIB_TIME);
- sensor->sensors_time[Gesture_Motion_HIDI] = 0;
- input_report_rel(sensor->input, HTC_Gesture_Motion_HIDI, data_event);
- input_sync(sensor->input);
- power_key_pressed = 0;
- } else {
- D("[CWMCU] Tap to wake disabled, ignoring\n");
- }
+ if (data[0] == 14) {
+ vib_trigger_event(vib_trigger, VIB_TIME);
+ D("Gesture motion HIDI detected, vibrate for %d ms!\n", VIB_TIME);
+ } else if(data[0] == 6 || data[0] == 15 || data[0] == 18 || data[0] == 19 || data[0] == 24 || data[0] == 25 || data[0] == 26 || data[0] == 27) {
+ vib_trigger_event(vib_trigger, VIB_TIME);
+ sensor->sensors_time[Gesture_Motion_HIDI] = 0;
+ input_report_rel(sensor->input, HTC_Gesture_Motion_HIDI, data_event);
+ input_sync(sensor->input);
+ power_key_pressed = 0;
+ D("[CWMCU][vib_trigger] Gesture_Motion_HIDI: df0: %d, d0: %d, d1: %d\n", data_buff[0], data[0], data[1]);
+ D("[CWMCU][vib_trigger] Gesture_Motion_HIDI: data_buff: %d, data_event: %d\n", data_buff[1], data_event);
+ D("[CWMCU][vib_trigger] Gesture_Motion_HIDI input sync\n");
} else {
- D("[CWMCU] Discard gesture wake\n");
+ sensor->sensors_time[Gesture_Motion_HIDI] = 0;
+ input_report_rel(sensor->input, HTC_Gesture_Motion_HIDI, data_event);
+ input_sync(sensor->input);
+ power_key_pressed = 0;
+ D("[CWMCU][disable vib_trigger] Gesture_Motion_HIDI: df0: %d, d0: %d, d1: %d\n", data_buff[0], data[0], data[1]);
+ D("[CWMCU][disable vib_trigger] Gesture_Motion_HIDI: data_buff: %d, data_event: %d\n", data_buff[1], data_event);
+ D("[CWMCU][disable vib_trigger] Gesture_Motion_HIDI input sync\n");
}
+ } else {
+ sensor->sensors_time[Gesture_Motion_HIDI] = 0;
+ input_report_rel(sensor->input, HTC_Gesture_Motion_HIDI, data_event);
+ input_sync(sensor->input);
+ power_key_pressed = 0;
+ D("[CWMCU] Gesture_Motion_HIDI: df0: %d, d0: %d, d1: %d\n", data_buff[0], data[0], data[1]);
+ D("[CWMCU] Gesture_Motion_HIDI: data_buff: %d, data_event: %d\n", data_buff[1], data_event);
+ D("[CWMCU] Gesture_Motion_HIDI input sync\n");
}
clear_intr = CW_MCU_INT_BIT_HTC_GESTURE_MOTION_HIDI;
ret = CWMCU_i2c_write(sensor, CWSTM32_INT_ST4, &clear_intr, 1);
@@ -3407,7 +3406,6 @@ static struct device_attribute attributes[] = {
#ifdef HTC_ENABLE_SENSORHUB_UART_DEBUG
__ATTR(uart_debug, 0666, NULL, uart_debug_switch),
#endif
- __ATTR(tap2wake, 0666, tap2wake_show, tap2wake_set),
};
@@ -3492,7 +3490,10 @@ static int fb_notifier_callback(struct notifier_block *self,
struct fb_event *evdata = data;
int *blank;
+ return 0;
+
D("%s\n", __func__);
+
if (evdata && evdata->data && event == FB_EVENT_BLANK && mcu_data &&
mcu_data->client) {
blank = evdata->data;
@@ -3641,7 +3642,8 @@ static int __devinit CWMCU_i2c_probe(struct i2c_client *client,
sensor->mfg_mode = board_mfg_mode();
D("%s: Boot mode = %d\n", __func__, sensor->mfg_mode);
- D("castor: CWMCU_i2c_probe success!\n");
+ I("%s: Probe success. [Do not change polling rate when screen off]\n",
+ __func__);
#ifdef CONFIG_FB
sensor->mcu_poll_wq = create_singlethread_workqueue("mcu_poll_reuqest");
if (!sensor->mcu_poll_wq) {
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig
index 93bb505..9c7baa9 100644
--- a/drivers/i2c/chips/Kconfig
+++ b/drivers/i2c/chips/Kconfig
@@ -160,6 +160,12 @@ config INPUT_CAPELLA_CM36686
Say Y here to enable the CM36686 Short Distance Proximity
Sensor with Ambient Light Sensor.
+config INPUT_EMINENT_EPL88051KPW
+ tristate "EPL88051KPW proximity and light sensor"
+ help
+ Say Y here to enable the EPL88051KPW Short Distance Proximity
+ Sensor with Ambient Light Sensor.
+
config INPUT_CAPELLA_CM32181
tristate "CM32181 light sensor"
help
diff --git a/drivers/i2c/chips/Makefile b/drivers/i2c/chips/Makefile
index 4a63f05..98f702e 100644
--- a/drivers/i2c/chips/Makefile
+++ b/drivers/i2c/chips/Makefile
@@ -19,29 +19,31 @@ obj-$(CONFIG_AMP_RT5506) += rt5506.o
ifeq ($(CONFIG_INPUT_CAPELLA_CM3629),y)
proximity-objs := cm3629.o
-obj-$(CONFIG_INPUT_CAPELLA_CM3629) += proximity.o
+obj-$(CONFIG_INPUT_CAPELLA_CM3629) += proximity.o
endif
ifeq ($(CONFIG_INPUT_CAPELLA_CM36686),y)
proximity-objs := cm36686.o
-obj-$(CONFIG_INPUT_CAPELLA_CM36686) += proximity.o
+obj-$(CONFIG_INPUT_CAPELLA_CM36686) += proximity.o
endif
obj-$(CONFIG_INPUT_CAPELLA_CM32181) += cm32181.o
-obj-$(CONFIG_SENSORS_AKM8975) += akm8975.o
-obj-$(CONFIG_SENSORS_AKM8975_PANA_GYRO) += akm8975_pana_gyro.o
+obj-$(CONFIG_SENSORS_AKM8975) += akm8975.o
+obj-$(CONFIG_SENSORS_AKM8975_PANA_GYRO) += akm8975_pana_gyro.o
obj-$(CONFIG_SENSORS_PANASONIC_GYRO) += ewtzmu2.o
-obj-$(CONFIG_SENSORS_AK8963) += akm8963.o
-obj-$(CONFIG_SENSORS_AK8963_DOE_PLUS) += akm8963_doe_plus.o
-obj-$(CONFIG_SENSORS_R3GD20) += r3gd20.o
+obj-$(CONFIG_SENSORS_AK8963) += akm8963.o
+obj-$(CONFIG_SENSORS_AK8963_DOE_PLUS) += akm8963_doe_plus.o
+obj-$(CONFIG_SENSORS_R3GD20) += r3gd20.o
obj-$(CONFIG_SENSORS_LSM330_ACC) += lsm330_acc.o
obj-$(CONFIG_SENSORS_LSM330_GYRO) += lsm330_gyr.o
-obj-$(CONFIG_SENSORS_BMA250) += bma250.o
-obj-$(CONFIG_BOSCH_BMA250) += bma250_bosch.o
-obj-$(CONFIG_INPUT_YAS_MAGNETOMETER) += yas53x_kernel.o
-obj-$(CONFIG_VP_A1028) += a1028.o
-obj-$(CONFIG_INPUT_CWSTM32) += CwMcuSensor.o
-obj-$(CONFIG_LIGHTSENSOR_EPL88051) += epl88051.o
+obj-$(CONFIG_SENSORS_BMA250) += bma250.o
+obj-$(CONFIG_BOSCH_BMA250) += bma250_bosch.o
+obj-$(CONFIG_INPUT_YAS_MAGNETOMETER) += yas53x_kernel.o
+obj-$(CONFIG_VP_A1028) += a1028.o
+obj-$(CONFIG_INPUT_CWSTM32) += CwMcuSensor.o
+obj-$(CONFIG_LIGHTSENSOR_EPL88051) += epl88051.o
+obj-$(CONFIG_INPUT_EMINENT_EPL88051KPW) += epl88051_KPW.o
+
ifeq ($(CONFIG_I2C_DEBUG_CHIP),y)
EXTRA_CFLAGS += -DDEBUG
endif
diff --git a/drivers/i2c/chips/akm8963_doe_plus.c b/drivers/i2c/chips/akm8963_doe_plus.c
old mode 100644
new mode 100755
index 760e075..95f8403
--- a/drivers/i2c/chips/akm8963_doe_plus.c
+++ b/drivers/i2c/chips/akm8963_doe_plus.c
@@ -14,6 +14,8 @@
*
*/
+/*#define DEBUG*/
+/*#define VERBOSE_DEBUG*/
#include <linux/akm8963_doe_plus.h>
#include <linux/delay.h>
@@ -54,6 +56,8 @@ struct akm_compass_data {
wait_queue_head_t drdy_wq;
wait_queue_head_t open_wq;
+ /* These two buffers are initialized at start up.
+ After that, the value is not changed */
uint8_t sense_info[AKM_SENSOR_INFO_SIZE];
uint8_t sense_conf[AKM_SENSOR_CONF_SIZE];
@@ -62,6 +66,9 @@ struct akm_compass_data {
struct mutex accel_mutex;
int16_t accel_data[3];
+ /* Positive value means the device is working.
+ 0 or negative value means the device is not woking,
+ i.e. in power-down mode. */
int8_t is_busy;
struct mutex val_mutex;
@@ -85,6 +92,7 @@ static struct akm_compass_data *s_akm;
+/***** I2C I/O function ***********************************************/
static int akm_i2c_rxdata(
struct i2c_client *i2c,
uint8_t *rxData,
@@ -156,6 +164,7 @@ static int akm_i2c_txdata(
return 0;
}
+/***** akm miscdevice functions *************************************/
static int AKECS_Set_CNTL(
struct akm_compass_data *akm,
uint8_t mode)
@@ -163,15 +172,15 @@ static int AKECS_Set_CNTL(
uint8_t buffer[2];
int err;
-
+ /***** lock *****/
mutex_lock(&akm->sensor_mutex);
-
+ /* Busy check */
if (akm->is_busy > 0) {
dev_err(&akm->i2c->dev,
"%s: device is busy.", __func__);
err = -EBUSY;
} else {
-
+ /* Set measure mode */
buffer[0] = AKM_REG_MODE;
buffer[1] = mode;
err = akm_i2c_txdata(akm->i2c, buffer, 2);
@@ -181,16 +190,16 @@ static int AKECS_Set_CNTL(
} else {
dev_vdbg(&akm->i2c->dev,
"Mode is set to (%d).", mode);
-
+ /* Set flag */
akm->is_busy = 1;
atomic_set(&akm->drdy, 0);
-
+ /* wait at least 100us after changing mode */
udelay(100);
}
}
mutex_unlock(&akm->sensor_mutex);
-
+ /***** unlock *****/
return err;
}
@@ -201,10 +210,10 @@ static int AKECS_Set_PowerDown(
uint8_t buffer[2];
int err;
-
+ /***** lock *****/
mutex_lock(&akm->sensor_mutex);
-
+ /* Set powerdown mode */
buffer[0] = AKM_REG_MODE;
buffer[1] = AKM_MODE_POWERDOWN;
err = akm_i2c_txdata(akm->i2c, buffer, 2);
@@ -213,15 +222,15 @@ static int AKECS_Set_PowerDown(
"%s: Can not set to powerdown mode.", __func__);
} else {
dev_dbg(&akm->i2c->dev, "Powerdown mode is set.");
-
+ /* wait at least 100us after changing mode */
udelay(100);
}
-
+ /* Clear status */
akm->is_busy = 0;
atomic_set(&akm->drdy, 0);
mutex_unlock(&akm->sensor_mutex);
-
+ /***** unlock *****/
return err;
}
@@ -235,14 +244,14 @@ static int AKECS_Reset(
#if AKM_HAS_RESET
uint8_t buffer[2];
-
+ /***** lock *****/
mutex_lock(&akm->sensor_mutex);
if (hard != 0) {
gpio_set_value(akm->gpio_rstn, 0);
udelay(5);
gpio_set_value(akm->gpio_rstn, 1);
-
+ /* No error is returned */
err = 0;
} else {
buffer[0] = AKM_REG_RESET;
@@ -255,14 +264,14 @@ static int AKECS_Reset(
dev_dbg(&akm->i2c->dev, "Soft reset is done.");
}
}
-
+ /* Device will be accessible 100 us after */
udelay(100);
-
+ /* Clear status */
akm->is_busy = 0;
atomic_set(&akm->drdy, 0);
mutex_unlock(&akm->sensor_mutex);
-
+ /***** unlock *****/
#else
err = AKECS_Set_PowerDown(akm);
@@ -310,8 +319,17 @@ static void AKECS_SetYPR(
dev_vdbg(&akm->input->dev, " Rotation V : %6d,%6d,%6d,%6d",
rbuf[12], rbuf[13], rbuf[14], rbuf[15]);
+ /*D("%s: flag =0x%X", __func__, rbuf[0]);
+ D(" Acc [LSB] : %6d,%6d,%6d stat=%d",
+ rbuf[1], rbuf[2], rbuf[3], rbuf[4]);
+ D(" Geo [LSB] : %6d,%6d,%6d stat=%d",
+ rbuf[5], rbuf[6], rbuf[7], rbuf[8]);
+ D(" Orientation : %6d,%6d,%6d",
+ rbuf[9], rbuf[10], rbuf[11]);
+ D(" Rotation V : %6d,%6d,%6d,%6d",
+ rbuf[12], rbuf[13], rbuf[14], rbuf[15]);*/
-
+ /* No events are reported */
if (!rbuf[0]) {
dev_dbg(&akm->i2c->dev, "Don't waste a time.");
return;
@@ -321,34 +339,31 @@ static void AKECS_SetYPR(
ready = (akm->enable_flag & (uint32_t)rbuf[0]);
mutex_unlock(&akm->val_mutex);
-
+ /* Report acceleration sensor information */
if (ready & ACC_DATA_READY) {
-
- input_report_abs(akm->input, ABS_X, 10000);
+ /*D("%s: Report Acc\n", __func__);*/
input_report_abs(akm->input, ABS_X, rbuf[1]);
input_report_abs(akm->input, ABS_Y, rbuf[2]);
input_report_abs(akm->input, ABS_Z, rbuf[3]);
-
+ //input_report_abs(akm->input, ABS_THROTTLE, rbuf[4]);
}
-
+ /* Report magnetic vector information */
if (ready & MAG_DATA_READY) {
-
- input_report_abs(akm->input, ABS_RX, 10000);
+ /*D("%s: Report Magnetic Field\n", __func__);*/
input_report_abs(akm->input, ABS_RX, rbuf[5]);
input_report_abs(akm->input, ABS_RY, rbuf[6]);
input_report_abs(akm->input, ABS_RZ, rbuf[7]);
input_report_abs(akm->input, ABS_RUDDER, rbuf[8]);
}
-
+ /* Report fusion sensor information */
if (ready & FUSION_DATA_READY) {
-
-
- input_report_abs(akm->input, ABS_HAT0X, 10000);
+ /*D("%s: Report Fusion\n", __func__);*/
+ /* Orientation */
input_report_abs(akm->input, ABS_HAT0X, rbuf[9]);
input_report_abs(akm->input, ABS_HAT0Y, rbuf[10]);
input_report_abs(akm->input, ABS_HAT1X, rbuf[11]);
input_report_abs(akm->input, ABS_HAT1Y, rbuf[4]);
-
+ /* Rotation Vector */
input_report_abs(akm->input, ABS_TILT_X, rbuf[12]);
input_report_abs(akm->input, ABS_TILT_Y, rbuf[13]);
input_report_abs(akm->input, ABS_TOOL_WIDTH, rbuf[14]);
@@ -358,6 +373,9 @@ static void AKECS_SetYPR(
input_sync(akm->input);
}
+/* This function will block a process until the latest measurement
+ * data is available.
+ */
static int AKECS_GetData(
struct akm_compass_data *akm,
uint8_t *rbuf,
@@ -365,7 +383,7 @@ static int AKECS_GetData(
{
int err;
-
+ /* Block! */
err = wait_event_interruptible_timeout(
akm->drdy_wq,
atomic_read(&akm->drdy),
@@ -381,14 +399,16 @@ static int AKECS_GetData(
return -ENODATA;
}
-
+ /***** lock *****/
mutex_lock(&akm->sensor_mutex);
memcpy(rbuf, akm->sense_data, size);
atomic_set(&akm->drdy, 0);
mutex_unlock(&akm->sensor_mutex);
-
+ /***** unlock *****/
+ /*D("%s: rbuf(0, 1, 2, 3) = (0x%x, 0x%x, 0x%x, 0x%x)\n",
+ __func__, rbuf[0], rbuf[1], rbuf[2], rbuf[3]);*/
return 0;
}
@@ -400,7 +420,7 @@ static int AKECS_GetData_Poll(
uint8_t buffer[AKM_SENSOR_DATA_SIZE];
int err;
-
+ /* Read status */
buffer[0] = AKM_REG_STATUS;
err = akm_i2c_rxdata(akm->i2c, buffer, 1);
if (err < 0) {
@@ -408,26 +428,28 @@ static int AKECS_GetData_Poll(
return err;
}
-
+ /* Check ST bit */
if (!(AKM_DRDY_IS_HIGH(buffer[0])))
return -EAGAIN;
-
+ /* Read rest data */
buffer[1] = AKM_REG_STATUS + 1;
err = akm_i2c_rxdata(akm->i2c, &(buffer[1]), AKM_SENSOR_DATA_SIZE-1);
if (err < 0) {
dev_err(&akm->i2c->dev, "%s failed.", __func__);
return err;
}
+ /*D("%s: buffer(0, 1, 2, 3) = (0x%x, 0x%x, 0x%x, 0x%x)\n",
+ __func__, buffer[0], buffer[1], buffer[2], buffer[3]);*/
memcpy(rbuf, buffer, size);
atomic_set(&akm->drdy, 0);
-
+ /***** lock *****/
mutex_lock(&akm->sensor_mutex);
akm->is_busy = 0;
mutex_unlock(&akm->sensor_mutex);
-
+ /***** unlock *****/
return 0;
}
@@ -585,15 +607,15 @@ AKECS_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
void __user *argp = (void __user *)arg;
struct akm_compass_data *akm = file->private_data;
-
- uint8_t i2c_buf[AKM_RWBUF_SIZE] = {0};
- uint8_t dat_buf[AKM_SENSOR_DATA_SIZE] = {0};
- int32_t ypr_buf[AKM_YPR_DATA_SIZE] = {0};
- int64_t delay[AKM_NUM_SENSORS] = {0};
- int16_t acc_buf[3] = {0};
- uint8_t mode = 0;
- int status = 0;
- int ret = 0;
+ /* NOTE: In this function the size of "char" should be 1-byte. */
+ uint8_t i2c_buf[AKM_RWBUF_SIZE] = {0}; /* for READ/WRITE */
+ uint8_t dat_buf[AKM_SENSOR_DATA_SIZE] = {0}; /* for GET_DATA */
+ int32_t ypr_buf[AKM_YPR_DATA_SIZE] = {0}; /* for SET_YPR */
+ int64_t delay[AKM_NUM_SENSORS] = {0}; /* for GET_DELAY */
+ int16_t acc_buf[3] = {0}; /* for GET_ACCEL */
+ uint8_t mode = 0; /* for SET_MODE*/
+ int status = 0; /* for OPEN/CLOSE_STATUS */
+ int ret = 0; /* Return value. */
switch (cmd) {
case ECS_IOCTL_READ:
@@ -634,7 +656,7 @@ AKECS_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
case ECS_IOCTL_GET_DELAY:
case ECS_IOCTL_GET_LAYOUT:
case ECS_IOCTL_GET_ACCEL:
-
+ /* Check buffer pointer for writing a data later. */
if (argp == NULL) {
dev_err(&akm->i2c->dev, "invalid argument.");
return -EINVAL;
@@ -744,7 +766,7 @@ AKECS_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
switch (cmd) {
case ECS_IOCTL_READ:
-
+ /* +1 is for the first byte */
if (copy_to_user(argp, &i2c_buf, i2c_buf[0]+1)) {
dev_err(&akm->i2c->dev, "copy_to_user failed.");
return -EFAULT;
@@ -816,6 +838,7 @@ static struct miscdevice akm_compass_dev = {
.fops = &AKECS_fops,
};
+/***** akm sysfs functions ******************************************/
static int create_device_attributes(
struct device *dev,
struct device_attribute *attrs)
@@ -880,7 +903,30 @@ static void remove_device_binary_attributes(
sysfs_remove_bin_file(kobj, &attrs[i]);
}
+/*********************************************************************
+ *
+ * SysFS attribute functions
+ *
+ * directory : /sys/class/compass/akmXXXX/
+ * files :
+ * - enable_acc [rw] [t] : enable flag for accelerometer
+ * - enable_mag [rw] [t] : enable flag for magnetometer
+ * - enable_fusion [rw] [t] : enable flag for fusion sensor
+ * - delay_acc [rw] [t] : delay in nanosecond for accelerometer
+ * - delay_mag [rw] [t] : delay in nanosecond for magnetometer
+ * - delay_fusion [rw] [t] : delay in nanosecond for fusion sensor
+ *
+ * debug :
+ * - mode [w] [t] : E-Compass mode
+ * - bdata [r] [t] : buffered raw data
+ * - asa [r] [t] : FUSEROM data
+ * - regs [r] [t] : read all registers
+ *
+ * [b] = binary format
+ * [t] = text format
+ */
+/***** sysfs enable *************************************************/
static void akm_compass_sysfs_update_status(
struct akm_compass_data *akm)
{
@@ -943,6 +989,7 @@ static ssize_t akm_compass_sysfs_enable_store(
return count;
}
+/***** Acceleration ***/
static ssize_t akm_enable_acc_show(
struct device *dev, struct device_attribute *attr, char *buf)
{
@@ -957,6 +1004,7 @@ static ssize_t akm_enable_acc_store(
dev_get_drvdata(dev), buf, count, ACC_DATA_FLAG);
}
+/***** Magnetic field ***/
static ssize_t akm_enable_mag_show(
struct device *dev, struct device_attribute *attr, char *buf)
{
@@ -971,6 +1019,7 @@ static ssize_t akm_enable_mag_store(
dev_get_drvdata(dev), buf, count, MAG_DATA_FLAG);
}
+/***** Fusion ***/
static ssize_t akm_enable_fusion_show(
struct device *dev, struct device_attribute *attr, char *buf)
{
@@ -985,6 +1034,7 @@ static ssize_t akm_enable_fusion_store(
dev_get_drvdata(dev), buf, count, FUSION_DATA_FLAG);
}
+/***** sysfs delay **************************************************/
static ssize_t akm_compass_sysfs_delay_show(
struct akm_compass_data *akm, char *buf, int pos)
{
@@ -1018,6 +1068,7 @@ static ssize_t akm_compass_sysfs_delay_store(
return count;
}
+/***** Accelerometer ***/
static ssize_t akm_delay_acc_show(
struct device *dev, struct device_attribute *attr, char *buf)
{
@@ -1032,6 +1083,7 @@ static ssize_t akm_delay_acc_store(
dev_get_drvdata(dev), buf, count, ACC_DATA_FLAG);
}
+/***** Magnetic field ***/
static ssize_t akm_delay_mag_show(
struct device *dev, struct device_attribute *attr, char *buf)
{
@@ -1046,6 +1098,7 @@ static ssize_t akm_delay_mag_store(
dev_get_drvdata(dev), buf, count, MAG_DATA_FLAG);
}
+/***** Fusion ***/
static ssize_t akm_delay_fusion_show(
struct device *dev, struct device_attribute *attr, char *buf)
{
@@ -1060,6 +1113,7 @@ static ssize_t akm_delay_fusion_store(
dev_get_drvdata(dev), buf, count, FUSION_DATA_FLAG);
}
+/***** accel (binary) ***/
static ssize_t akm_bin_accel_write(
struct file *file,
struct kobject *kobj,
@@ -1182,12 +1236,12 @@ static ssize_t akm_sysfs_asa_show(
static ssize_t akm_sysfs_regs_show(
struct device *dev, struct device_attribute *attr, char *buf)
{
-
+ /* The total number of registers depends on the device. */
struct akm_compass_data *akm = dev_get_drvdata(dev);
int err;
uint8_t regs[AKM_REGS_SIZE];
-
+ /* This function does not lock mutex obj */
regs[0] = AKM_REGS_1ST_ADDR;
err = akm_i2c_rxdata(akm->i2c, regs, AKM_REGS_SIZE);
if (err < 0)
@@ -1326,19 +1380,20 @@ static void remove_sysfs_interfaces(struct akm_compass_data *akm)
}
+/***** akm input device functions ***********************************/
static int akm_compass_input_init(
struct input_dev **input)
{
int err = 0;
-
+ /* Declare input device */
*input = input_allocate_device();
if (!*input)
return -ENOMEM;
-
+ /* Setup input device */
set_bit(EV_ABS, (*input)->evbit);
-
+ /* Accelerometer (720 x 16G)*/
input_set_abs_params(*input, ABS_X,
-11520, 11520, 0, 0);
input_set_abs_params(*input, ABS_Y,
@@ -1347,7 +1402,7 @@ static int akm_compass_input_init(
-11520, 11520, 0, 0);
input_set_abs_params(*input, ABS_RX,
0, 3, 0, 0);
-
+ /* Magnetic field (limited to 16bit) */
input_set_abs_params(*input, ABS_RY,
-32768, 32767, 0, 0);
input_set_abs_params(*input, ABS_RZ,
@@ -1357,8 +1412,8 @@ static int akm_compass_input_init(
input_set_abs_params(*input, ABS_RUDDER,
0, 3, 0, 0);
-
-
+ /* Orientation (degree in Q6 format) */
+ /* yaw[0,360) pitch[-180,180) roll[-90,90) */
input_set_abs_params(*input, ABS_HAT0X,
0, 23040, 0, 0);
input_set_abs_params(*input, ABS_HAT0Y,
@@ -1368,7 +1423,7 @@ static int akm_compass_input_init(
input_set_abs_params(*input, ABS_HAT1Y,
0, 3, 0, 0);
-
+ /* Rotation Vector [-1,+1] in Q14 format */
input_set_abs_params(*input, ABS_TILT_X,
-16384, 16384, 0, 0);
input_set_abs_params(*input, ABS_TILT_Y,
@@ -1378,10 +1433,10 @@ static int akm_compass_input_init(
input_set_abs_params(*input, ABS_VOLUME,
-16384, 16384, 0, 0);
-
+ /* Set name */
(*input)->name = AKM_INPUT_DEVICE_NAME;
-
+ /* Register */
err = input_register_device(*input);
if (err) {
input_free_device(*input);
@@ -1391,6 +1446,7 @@ static int akm_compass_input_init(
return err;
}
+/***** akm functions ************************************************/
static irqreturn_t akm_compass_irq(int irq, void *handle)
{
struct akm_compass_data *akm = handle;
@@ -1399,21 +1455,21 @@ static irqreturn_t akm_compass_irq(int irq, void *handle)
memset(buffer, 0, sizeof(buffer));
-
+ /***** lock *****/
mutex_lock(&akm->sensor_mutex);
-
+ /* Read whole data */
buffer[0] = AKM_REG_STATUS;
err = akm_i2c_rxdata(akm->i2c, buffer, AKM_SENSOR_DATA_SIZE);
if (err < 0) {
dev_err(&akm->i2c->dev, "IRQ I2C error.");
akm->is_busy = 0;
mutex_unlock(&akm->sensor_mutex);
-
+ /***** unlock *****/
return IRQ_HANDLED;
}
-
+ /* Check ST bit */
if (!(AKM_DRDY_IS_HIGH(buffer[0])))
goto work_func_none;
@@ -1421,7 +1477,7 @@ static irqreturn_t akm_compass_irq(int irq, void *handle)
akm->is_busy = 0;
mutex_unlock(&akm->sensor_mutex);
-
+ /***** unlock *****/
atomic_set(&akm->drdy, 1);
wake_up(&akm->drdy_wq);
@@ -1431,7 +1487,7 @@ static irqreturn_t akm_compass_irq(int irq, void *handle)
work_func_none:
mutex_unlock(&akm->sensor_mutex);
-
+ /***** unlock *****/
dev_vdbg(&akm->i2c->dev, "IRQ not handled.");
return IRQ_NONE;
@@ -1453,7 +1509,7 @@ static int akm_compass_resume(struct device *dev)
static int akm8963_i2c_check_device(
struct i2c_client *client)
{
-
+ /* AK8963 specific function */
struct akm_compass_data *akm = i2c_get_clientdata(client);
int err;
@@ -1462,7 +1518,7 @@ static int akm8963_i2c_check_device(
if (err < 0)
return err;
-
+ /* Set FUSE access mode */
err = AKECS_SetMode(akm, AK8963_MODE_FUSE_ACCESS);
if (err < 0)
return err;
@@ -1476,7 +1532,7 @@ static int akm8963_i2c_check_device(
if (err < 0)
return err;
-
+ /* Check read data */
if (akm->sense_info[0] != AK8963_WIA_VALUE) {
dev_err(&client->dev,
"%s: The device is not AKM Compass.", __func__);
@@ -1506,13 +1562,13 @@ static int akm8963_parse_dt(struct device *dev, struct akm8963_platform_data *pd
} else
I("%s: compass_akm8963,layout not found", __func__);
-
-
-
-
-
-
-
+ //prop = of_find_property(dt, "compass_akm8963,outbit", NULL);
+ //if (prop) {
+ // of_property_read_u32(dt, "compass_akm8963,outbit", &buf);
+ // pdata->outbit = buf;
+ // I("%s: outbit = %d", __func__, pdata->outbit);
+ //} else
+ // I("%s: compass_akm8963,outbit not found", __func__);
pdata->gpio_DRDY = of_get_named_gpio_flags(dt,
"compass_akm8963,gpio_DRDY",
@@ -1555,7 +1611,7 @@ int __devinit akm_compass_probe(struct i2c_client *client, const struct i2c_devi
goto exit0;
}
-
+ /* Allocate memory for driver data */
s_akm = kzalloc(sizeof(struct akm_compass_data), GFP_KERNEL);
if (!s_akm) {
dev_err(&client->dev,
@@ -1564,7 +1620,7 @@ int __devinit akm_compass_probe(struct i2c_client *client, const struct i2c_devi
goto exit1;
}
-
+ /**** initialize variables in akm_compass_data *****/
init_waitqueue_head(&s_akm->drdy_wq);
init_waitqueue_head(&s_akm->open_wq);
@@ -1578,7 +1634,7 @@ int __devinit akm_compass_probe(struct i2c_client *client, const struct i2c_devi
s_akm->is_busy = 0;
s_akm->enable_flag = 0;
-
+ /* Set to 1G in Android coordination, AKSC format */
s_akm->accel_data[0] = 0;
s_akm->accel_data[1] = 0;
s_akm->accel_data[2] = 720;
@@ -1586,7 +1642,7 @@ int __devinit akm_compass_probe(struct i2c_client *client, const struct i2c_devi
for (i = 0; i < AKM_NUM_SENSORS; i++)
s_akm->delay[i] = -1;
-
+ /***** Set platform information *****/
if (client->dev.of_node) {
I("Device Tree parsing.");
pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
@@ -1614,27 +1670,29 @@ int __devinit akm_compass_probe(struct i2c_client *client, const struct i2c_devi
}
if (pdata) {
-
+ /* Platform data is available. copy its value to local. */
s_akm->layout = pdata->layout;
s_akm->gpio_rstn = pdata->gpio_RSTN;
s_akm->power_LPM = pdata->power_LPM;
} else {
+ /* Platform data is not available.
+ Layout and information should be set by each application. */
dev_dbg(&client->dev, "%s: No platform data.", __func__);
s_akm->layout = 0;
s_akm->gpio_rstn = 0;
s_akm->power_LPM = NULL;
}
-
+ /***** I2C initialization *****/
s_akm->i2c = client;
-
+ /* set client data */
i2c_set_clientdata(client, s_akm);
-
+ /* check connection */
err = akm8963_i2c_check_device(client);
if (err < 0)
goto exit3;
-
+ /***** input *****/
err = akm_compass_input_init(&s_akm->input);
if (err) {
dev_err(&client->dev,
@@ -1643,7 +1701,7 @@ int __devinit akm_compass_probe(struct i2c_client *client, const struct i2c_devi
}
input_set_drvdata(s_akm->input, s_akm);
-
+ /***** IRQ setup *****/
s_akm->irq = client->irq;
dev_dbg(&client->dev, "%s: IRQ is #%d.",
@@ -1664,7 +1722,7 @@ int __devinit akm_compass_probe(struct i2c_client *client, const struct i2c_devi
}
}
-
+ /***** misc *****/
err = misc_register(&akm_compass_dev);
if (err) {
dev_err(&client->dev,
@@ -1685,7 +1743,7 @@ int __devinit akm_compass_probe(struct i2c_client *client, const struct i2c_devi
if (err)
E("%s: akm8963_sr_lpm failed 222\n", __func__);
-
+ /***** sysfs *****/
err = create_sysfs_interfaces(s_akm);
if (0 > err) {
dev_err(&client->dev,
@@ -1771,9 +1829,9 @@ static struct i2c_driver akm_compass_driver = {
.of_match_table = akm8963_match_table,
#ifdef CONFIG_PM
.pm = &akm_compass_pm_ops,
-#endif
+#endif /* CONFIG_PM */
},
-#else
+#else /* CONFIG_OF */
.probe = akm_compass_probe,
.remove = akm_compass_remove,
.id_table = akm_compass_id,
@@ -1781,14 +1839,14 @@ static struct i2c_driver akm_compass_driver = {
.name = AKM_I2C_NAME,
.pm = &akm_compass_pm_ops,
},
-#endif
+#endif /* CONFIG_OF */
};
#ifdef CONFIG_OF
module_i2c_driver(akm_compass_driver);
-#else
+#else /* CONFIG_OF */
static int __init akm_compass_init(void)
{
@@ -1805,7 +1863,7 @@ static void __exit akm_compass_exit(void)
module_init(akm_compass_init);
module_exit(akm_compass_exit);
-#endif
+#endif /* Not defined CONFIG_OF */
MODULE_DESCRIPTION("AKM compass driver");
MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/chips/bma250_bosch.c b/drivers/i2c/chips/bma250_bosch.c
index beec73a..4d3c497 100644
--- a/drivers/i2c/chips/bma250_bosch.c
+++ b/drivers/i2c/chips/bma250_bosch.c
@@ -1,3 +1,6 @@
+/* Date: 2011/11/02 17:00:00
+ * Revision: 2.9
+ */
/*
* This software program is licensed subject to the GNU General Public License
@@ -8,6 +11,10 @@
*/
+/* file bma250_bosch.c
+ brief This file contains all function implementations for the BMA250 in linux
+
+ */
#undef CONFIG_HAS_EARLYSUSPEND
@@ -85,7 +92,7 @@ struct bma250_data {
#ifdef HTC_ATTR
struct class *g_sensor_class;
struct device *g_sensor_dev;
-#endif
+#endif /* HTC_ATTR */
struct bma250_platform_data *pdata;
short offset_buf[3];
@@ -264,7 +271,7 @@ static int bma250_set_int1_pad_sel(struct i2c_client *client, unsigned char
return comres;
}
-#endif
+#endif /* BMA250_ENABLE_INT1 */
#ifdef BMA250_ENABLE_INT2
static int bma250_set_int2_pad_sel(struct i2c_client *client, unsigned char
int2sel)
@@ -338,7 +345,7 @@ static int bma250_set_int2_pad_sel(struct i2c_client *client, unsigned char
return comres;
}
-#endif
+#endif /* BMA250_ENABLE_INT2 */
static int bma250_set_Int_Enable(struct i2c_client *client, unsigned char
InterruptType , unsigned char value)
@@ -353,70 +360,70 @@ static int bma250_set_Int_Enable(struct i2c_client *client, unsigned char
value = value & 1;
switch (InterruptType) {
case 0:
-
+ /* Low G Interrupt */
data2 = BMA250_SET_BITSLICE(data2, BMA250_EN_LOWG_INT, value);
break;
case 1:
-
+ /* High G X Interrupt */
data2 = BMA250_SET_BITSLICE(data2, BMA250_EN_HIGHG_X_INT,
value);
break;
case 2:
-
+ /* High G Y Interrupt */
data2 = BMA250_SET_BITSLICE(data2, BMA250_EN_HIGHG_Y_INT,
value);
break;
case 3:
-
+ /* High G Z Interrupt */
data2 = BMA250_SET_BITSLICE(data2, BMA250_EN_HIGHG_Z_INT,
value);
break;
case 4:
-
+ /* New Data Interrupt */
data2 = BMA250_SET_BITSLICE(data2, BMA250_EN_NEW_DATA_INT,
value);
break;
case 5:
-
+ /* Slope X Interrupt */
data1 = BMA250_SET_BITSLICE(data1, BMA250_EN_SLOPE_X_INT,
value);
break;
case 6:
-
+ /* Slope Y Interrupt */
data1 = BMA250_SET_BITSLICE(data1, BMA250_EN_SLOPE_Y_INT,
value);
break;
case 7:
-
+ /* Slope Z Interrupt */
data1 = BMA250_SET_BITSLICE(data1, BMA250_EN_SLOPE_Z_INT,
value);
break;
case 8:
-
+ /* Single Tap Interrupt */
data1 = BMA250_SET_BITSLICE(data1, BMA250_EN_SINGLE_TAP_INT,
value);
break;
case 9:
-
+ /* Double Tap Interrupt */
data1 = BMA250_SET_BITSLICE(data1, BMA250_EN_DOUBLE_TAP_INT,
value);
break;
case 10:
-
+ /* Orient Interrupt */
data1 = BMA250_SET_BITSLICE(data1, BMA250_EN_ORIENT_INT, value);
break;
case 11:
-
+ /* Flat Interrupt */
data1 = BMA250_SET_BITSLICE(data1, BMA250_EN_FLAT_INT, value);
break;
@@ -705,7 +712,7 @@ static int bma250_get_orient_flat_status(struct i2c_client *client, unsigned
return comres;
}
#endif
-#endif
+#endif /* defined(BMA250_ENABLE_INT1)||defined(BMA250_ENABLE_INT2) */
static int bma250_set_Int_Mode(struct i2c_client *client, unsigned char Mode)
{
int comres = 0;
@@ -1512,7 +1519,6 @@ static void bma250_work_func(struct work_struct *work)
data_z = ((bma250->pdata->negate_z) ? (-hw_d[bma250->pdata->axis_map_z])
: (hw_d[bma250->pdata->axis_map_z]));
- input_report_abs(bma250->input, ABS_X, 10000);
input_report_abs(bma250->input, ABS_X, data_x);
input_report_abs(bma250->input, ABS_Y, data_y);
input_report_abs(bma250->input, ABS_Z, data_z);
@@ -1630,7 +1636,7 @@ static void debug_do_work(struct work_struct *w)
}
-static ssize_t bma250_chip_layout_show(struct device *dev,
+static ssize_t bma250_chip_layout_show(struct device *dev, /* show chip layou attribute */
struct device_attribute *attr, char *buf)
{
if (gdata == NULL) {
@@ -1656,7 +1662,7 @@ static ssize_t bma250_chip_layout_store(struct device *dev,
unsigned long data = 0;
int error = 0;
-
+ /*D("%s++: debug: data = %lu\n", __func__, data);*/
error = strict_strtoul(buf, 10, &data);
if (error)
@@ -1670,13 +1676,13 @@ static ssize_t bma250_chip_layout_store(struct device *dev,
cancel_delayed_work(&debug_work);
}
-
+ /*D("%s: debug: data = %lu\n", __func__, data);*/
return count;
}
-static ssize_t bma250_get_raw_data_show(struct device *dev,
+static ssize_t bma250_get_raw_data_show(struct device *dev, /* show chip layou attribute */
struct device_attribute *attr, char *buf)
{
struct bma250_data *bma250 = gdata;
@@ -1748,30 +1754,6 @@ static ssize_t bma250_set_k_value_store(struct device *dev,
return count;
}
-static ssize_t flush_show(struct device *dev,
- struct device_attribute *attr, char *buf)
-{
- int ret;
-
- ret = sprintf(buf, "%d\n", 1);
-
- return ret;
-}
-
-static ssize_t flush_store(struct device *dev,
- struct device_attribute *attr,
- const char *buf, size_t count)
-{
- struct bma250_data *bma250 = gdata;
-
- I("%s++:\n", __func__);
-
- input_report_rel(bma250->input_cir, SLOP_INTERRUPT, 777);
- input_sync(bma250->input_cir);
-
- return count;
-}
-
static ssize_t bma250_mode_show(struct device *dev,
struct device_attribute *attr, char *buf)
@@ -1872,7 +1854,7 @@ static int bma250_sr_ldo_init(int init)
if (!init) {
regulator_set_voltage(bma250->sr_1v8, 0, 1800000);
-
+ //per HW request, correct sr_2v85 changes to 3v for A11
if(bma250->pdata->SR_3v_used)
regulator_set_voltage(bma250->sr_2v85, 0, 3000000);
else
@@ -1889,7 +1871,7 @@ static int bma250_sr_ldo_init(int init)
}
I("%s: bma250->sr_2v85 = 0x%p\n", __func__, bma250->sr_2v85);
-
+ //per HW request, correct sr_2v85 changes to 3v for A11
if(bma250->pdata->SR_3v_used)
rc = regulator_set_voltage(bma250->sr_2v85, 3000000, 3000000);
else
@@ -2702,7 +2684,7 @@ static ssize_t bma250_fast_calibration_x_store(struct device *dev,
mdelay(2);
bma250_get_cal_ready(bma250->bma250_client, &tmp);
-
+ /* I("wait 2ms cal ready flag is %d\n",tmp);*/
timeout++;
if (timeout == 50) {
I("get fast calibration ready error\n");
@@ -2757,7 +2739,7 @@ static ssize_t bma250_fast_calibration_y_store(struct device *dev,
mdelay(2);
bma250_get_cal_ready(bma250->bma250_client, &tmp);
-
+ /* I("wait 2ms cal ready flag is %d\n",tmp);*/
timeout++;
if (timeout == 50) {
I("get fast calibration ready error\n");
@@ -2812,7 +2794,7 @@ static ssize_t bma250_fast_calibration_z_store(struct device *dev,
mdelay(2);
bma250_get_cal_ready(bma250->bma250_client, &tmp);
-
+ /* I("wait 2ms cal ready flag is %d\n",tmp);*/
timeout++;
if (timeout == 50) {
I("get fast calibration ready error\n");
@@ -2859,17 +2841,19 @@ static ssize_t bma250_selftest_store(struct device *dev,
if (data != 1)
return -EINVAL;
-
+ /* set to 2 G range */
if (bma250_set_range(bma250->bma250_client, 0) < 0)
return -EINVAL;
bma250_write_reg(bma250->bma250_client, 0x32, &clear_value);
- bma250_set_selftest_st(bma250->bma250_client, 1);
- bma250_set_selftest_stn(bma250->bma250_client, 0);
+ bma250_set_selftest_st(bma250->bma250_client, 1); /* 1 for x-axis*/
+ bma250_set_selftest_stn(bma250->bma250_client, 0); /* positive
+ direction*/
mdelay(10);
bma250_read_accel_x(bma250->bma250_client, &value1);
- bma250_set_selftest_stn(bma250->bma250_client, 1);
+ bma250_set_selftest_stn(bma250->bma250_client, 1); /* negative
+ direction*/
mdelay(10);
bma250_read_accel_x(bma250->bma250_client, &value2);
diff = value1-value2;
@@ -2880,11 +2864,13 @@ static ssize_t bma250_selftest_store(struct device *dev,
if (abs(diff) < 204)
result |= 1;
- bma250_set_selftest_st(bma250->bma250_client, 2);
- bma250_set_selftest_stn(bma250->bma250_client, 0);
+ bma250_set_selftest_st(bma250->bma250_client, 2); /* 2 for y-axis*/
+ bma250_set_selftest_stn(bma250->bma250_client, 0); /* positive
+ direction*/
mdelay(10);
bma250_read_accel_y(bma250->bma250_client, &value1);
- bma250_set_selftest_stn(bma250->bma250_client, 1);
+ bma250_set_selftest_stn(bma250->bma250_client, 1); /* negative
+ direction*/
mdelay(10);
bma250_read_accel_y(bma250->bma250_client, &value2);
diff = value1-value2;
@@ -2894,11 +2880,13 @@ static ssize_t bma250_selftest_store(struct device *dev,
result |= 2;
- bma250_set_selftest_st(bma250->bma250_client, 3);
- bma250_set_selftest_stn(bma250->bma250_client, 0);
+ bma250_set_selftest_st(bma250->bma250_client, 3); /* 3 for z-axis*/
+ bma250_set_selftest_stn(bma250->bma250_client, 0); /* positive
+ direction*/
mdelay(10);
bma250_read_accel_z(bma250->bma250_client, &value1);
- bma250_set_selftest_stn(bma250->bma250_client, 1);
+ bma250_set_selftest_stn(bma250->bma250_client, 1); /* negative
+ direction*/
mdelay(10);
bma250_read_accel_z(bma250->bma250_client, &value2);
diff = value1-value2;
@@ -2937,7 +2925,7 @@ static ssize_t bma250_eeprom_writing_store(struct device *dev,
if (data != 1)
return -EINVAL;
-
+ /* unlock eeprom */
if (bma250_set_ee_w(bma250->bma250_client, 1) < 0)
return -EINVAL;
@@ -2962,7 +2950,7 @@ static ssize_t bma250_eeprom_writing_store(struct device *dev,
I("eeprom writing is finished\n");
-
+ /* unlock eeprom */
if (bma250_set_ee_w(bma250->bma250_client, 0) < 0)
return -EINVAL;
@@ -2984,23 +2972,23 @@ static ssize_t bma250_enable_interrupt(struct device *dev,
if (error)
return error;
I("bma250_enable_interrupt, power_key_pressed = %d\n", power_key_pressed);
- if(enable == 1 && !power_key_pressed){
+ if(enable == 1 && !power_key_pressed){ // Slope interrupt
cir_flag = 1;
-
+ //Don't change to low power mode due to enabling interrupt mode
if(bma250->pdata->power_LPM)
bma250->pdata->power_LPM(0);
-
- error = bma250_set_Int_Mode(bma250->bma250_client, 1);
+ /*Set the related parameters*/
+ error = bma250_set_Int_Mode(bma250->bma250_client, 1);/*latch interrupt 250ms*/
- error += bma250_set_slope_duration(bma250->bma250_client, 0x01);
- error += bma250_set_slope_threshold(bma250->bma250_client, 0x07);
+ error += bma250_set_slope_duration(bma250->bma250_client, 0x01);//dur+1
+ error += bma250_set_slope_threshold(bma250->bma250_client, 0x07);//0x07 * 3.91 =
-
- error += bma250_set_Int_Enable(bma250->bma250_client, 5, 1);
- error += bma250_set_Int_Enable(bma250->bma250_client, 6, 1);
- error += bma250_set_Int_Enable(bma250->bma250_client, 7, 0);
+ /*Enable the interrupts*/
+ error += bma250_set_Int_Enable(bma250->bma250_client, 5, 1);//Slope X
+ error += bma250_set_Int_Enable(bma250->bma250_client, 6, 1);//Slope Y
+ error += bma250_set_Int_Enable(bma250->bma250_client, 7, 0);//Slope Z
error += bma250_set_int1_pad_sel(bma250->bma250_client, PAD_SLOP);
error += bma250_set_mode(bma250->bma250_client, BMA250_MODE_NORMAL);
@@ -3011,9 +2999,9 @@ static ssize_t bma250_enable_interrupt(struct device *dev,
} else if(enable == 0){
- error += bma250_set_Int_Enable(bma250->bma250_client, 5, 0);
- error += bma250_set_Int_Enable(bma250->bma250_client, 6, 0);
- error += bma250_set_Int_Enable(bma250->bma250_client, 7, 0);
+ error += bma250_set_Int_Enable(bma250->bma250_client, 5, 0);//Slope X
+ error += bma250_set_Int_Enable(bma250->bma250_client, 6, 0);//Slope Y
+ error += bma250_set_Int_Enable(bma250->bma250_client, 7, 0);//Slope Z
power_key_pressed = 0;
cir_flag = 0;
@@ -3127,9 +3115,6 @@ static DEVICE_ATTR(get_raw_data, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP,
static DEVICE_ATTR(set_k_value, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP,
bma250_set_k_value_show, bma250_set_k_value_store);
-static DEVICE_ATTR(flush, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP,
- flush_show, flush_store);
-
static struct attribute *bma250_attributes[] = {
&dev_attr_range.attr,
&dev_attr_bandwidth.attr,
@@ -3165,7 +3150,6 @@ static struct attribute *bma250_attributes[] = {
&dev_attr_chip_layout.attr,
&dev_attr_get_raw_data.attr,
&dev_attr_set_k_value.attr,
- &dev_attr_flush.attr,
#ifdef CONFIG_CIR_ALWAYS_READY
&dev_attr_enable_cir_interrupt.attr,
#endif
@@ -3234,7 +3218,7 @@ static irqreturn_t bma250_irq_handler(int irq, void *handle)
}
#endif
-#endif
+#endif /* defined(BMA250_ENABLE_INT1)||defined(BMA250_ENABLE_INT2) */
static int bma250_parse_dt(struct device *dev, struct bma250_platform_data *pdata)
{
@@ -3359,6 +3343,10 @@ static int __devinit bma250_probe(struct i2c_client *client,
int res;
#endif
+/*
+ omap_mux_init_gpio(145, OMAP_PIN_INPUT);
+ omap_mux_init_gpio(146, OMAP_PIN_INPUT);
+*/
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
I("i2c_check_functionality error\n");
goto exit;
@@ -3368,7 +3356,7 @@ static int __devinit bma250_probe(struct i2c_client *client,
err = -ENOMEM;
goto exit;
}
-
+ /* read chip id */
tempvalue = i2c_smbus_read_byte_data(client, BMA250_CHIP_ID_REG);
if ((tempvalue == BMA250_CHIP_ID) || (tempvalue == BMA250E_CHIP_ID)) {
@@ -3417,6 +3405,7 @@ static int __devinit bma250_probe(struct i2c_client *client,
if (data->pdata) {
data->chip_layout = data->pdata->chip_layout;
if (!(client->dev.of_node)) {
+// data->pdata->gs_kvalue = gs_kvalue;
I("%s: Use ATAG Calibration data\n", __func__);
}
} else {
@@ -3430,14 +3419,30 @@ static int __devinit bma250_probe(struct i2c_client *client,
D("%s: layout = %d\n", __func__, gdata->chip_layout);
#if defined(BMA250_ENABLE_INT1) || defined(BMA250_ENABLE_INT2)
+// bma250_set_Int_Mode(client, 1);/*latch interrupt 250ms*/
#endif
+ /*8,single tap
+ 10,orient
+ 11,flat*/
+/* bma250_set_Int_Enable(client,8, 1);
+ bma250_set_Int_Enable(client,10, 1);
+ bma250_set_Int_Enable(client,11, 1);
+*/
#ifdef BMA250_ENABLE_INT1
-
+ /* maps interrupt to INT1 pin */
+ /*
+ bma250_set_int1_pad_sel(client, PAD_LOWG);
+ bma250_set_int1_pad_sel(client, PAD_HIGHG);
+ bma250_set_int1_pad_sel(client, PAD_SLOP);
+ bma250_set_int1_pad_sel(client, PAD_DOUBLE_TAP);
+ bma250_set_int1_pad_sel(client, PAD_SINGLE_TAP);
+ bma250_set_int1_pad_sel(client, PAD_ORIENT);
+ bma250_set_int1_pad_sel(client, PAD_FLAT);*/
#endif
#ifdef BMA250_ENABLE_INT2
-
+ /* maps interrupt to INT2 pin */
bma250_set_int2_pad_sel(client, PAD_LOWG);
bma250_set_int2_pad_sel(client, PAD_HIGHG);
bma250_set_int2_pad_sel(client, PAD_SLOP);
@@ -3471,7 +3476,7 @@ static int __devinit bma250_probe(struct i2c_client *client,
dev_cir = input_allocate_device();
if (!dev_cir) {
kfree(data);
- input_free_device(dev);
+ input_free_device(dev);//free the successful dev and return
return -ENOMEM;
}
#endif
@@ -3556,14 +3561,14 @@ static int __devinit bma250_probe(struct i2c_client *client,
if (err < 0)
goto error_sysfs;
-#else
+#else /* HTC_ATTR */
err = sysfs_create_group(&data->input->dev.kobj,
&bma250_attribute_group);
if (err < 0)
goto error_sysfs;
-#endif
+#endif /* HTC_ATTR */
err = bma250_sr_ldo_init(1);
if (err) {
@@ -3709,7 +3714,7 @@ static int bma250_suspend(struct device *dev)
mutex_unlock(&data->enable_mutex);
#ifdef CONFIG_CIR_ALWAYS_READY
-
+ //Add CIR Flag for always ready feature
if ((data->pdata->power_LPM) && !cir_flag){
#else
@@ -3745,7 +3750,7 @@ static int bma250_resume(struct device *dev)
#define bma250_suspend NULL
#define bma250_resume NULL
-#endif
+#endif /* CONFIG_PM */
static const struct dev_pm_ops bma250_pm_ops = {
#ifdef CONFIG_PM
diff --git a/drivers/i2c/chips/cm3629.c b/drivers/i2c/chips/cm3629.c
old mode 100644
new mode 100755
index 36089a9..da374ab
--- a/drivers/i2c/chips/cm3629.c
+++ b/drivers/i2c/chips/cm3629.c
@@ -140,8 +140,8 @@ struct cm3629_info {
uint16_t cali_table[10];
int irq;
int ls_calibrate;
- int (*power)(int, uint8_t);
- int (*lpm_power)(int on);
+ int (*power)(int, uint8_t); /* power to the chip */
+ int (*lpm_power)(int on); /* power to the chip */
uint32_t als_kadc;
uint32_t emmc_als_kadc;
uint32_t als_gadc;
@@ -160,7 +160,7 @@ struct cm3629_info {
uint8_t original_ps_thd_set;
int current_level;
uint16_t current_adc;
-
+ /* Command code 0x02, intelligent cancel level */
uint8_t inte_ps1_canc;
uint8_t inte_ps2_canc;
uint8_t ps_conf1_val;
@@ -168,7 +168,7 @@ struct cm3629_info {
uint8_t ps_conf1_val_from_board;
uint8_t ps_conf2_val_from_board;
uint8_t ps_conf3_val;
- uint8_t ps_calibration_rule;
+ uint8_t ps_calibration_rule; /* For Saga */
int ps_pocket_mode;
unsigned long j_start;
unsigned long j_end;
@@ -195,6 +195,7 @@ struct cm3629_info {
uint32_t ws_gadc;
uint16_t w_golden_adc;
uint32_t *correction_table;
+ int ps_stop_polling;
};
#if defined(CONFIG_FB)
@@ -320,9 +321,11 @@ static int _cm3629_I2C_Read2(uint16_t slaveAddr,
for (i = 0; i < length; i++) {
*(pdata+i) = buffer[i];
+ /*printk(KERN_INFO "[cm3629] %s: I2C_RxData[0x%x] = 0x%x\n",
+ __func__, slaveAddr, buffer[i]);*/
}
#if 0
-
+ /* Debug use */
printk(KERN_DEBUG "[cm3629] %s: I2C_RxData[0x%x] = 0x%x\n",
__func__, slaveAddr, buffer);
#endif
@@ -335,7 +338,7 @@ static int _cm3629_I2C_Write2(uint16_t SlaveAddress,
char buffer[3];
int ret = 0;
#if 0
-
+ /* Debug use */
printk(KERN_DEBUG
"[cm3629] %s: _cm3629_I2C_Write_Byte[0x%x, 0x%x, 0x%x]\n",
__func__, SlaveAddress, cmd, *data);
@@ -382,13 +385,13 @@ static int get_ls_adc_value(uint32_t *als_step, int resume)
if (resume == 1) {
if (sensor_chipId[0] != 0x29)
- ls_cmd = (CM3629_ALS_IT_80ms | CM3629_ALS_PERS_1);
+ ls_cmd = (CM3629_ALS_IT_80ms | CM3629_ALS_PERS_1);/* disable CM3629_ALS_INT_EN */
else
- ls_cmd = (CM3629_ALS_IT_50ms | CM3629_ALS_PERS_1);
+ ls_cmd = (CM3629_ALS_IT_50ms | CM3629_ALS_PERS_1);/* disable CM3629_ALS_INT_EN */
D("[LS][cm3629] %s:resume %d\n",
__func__, resume);
} else
- ls_cmd = (lpi->ls_cmd);
+ ls_cmd = (lpi->ls_cmd);/* disable CM3629_ALS_INT_EN */
cmd[0] = ls_cmd;
cmd[1] = 0;
@@ -402,7 +405,7 @@ static int get_ls_adc_value(uint32_t *als_step, int resume)
return -EIO;
}
-
+ /* Read ALS data */
ret = _cm3629_I2C_Read2(lpi->cm3629_slave_address, ALS_data, cmd, 2);
if (ret < 0) {
@@ -450,13 +453,13 @@ static int get_ws_adc_value(uint32_t *als_step, bool resume)
if (resume) {
if (sensor_chipId[0] != 0x29)
- ls_cmd = (CM3629_ALS_IT_80ms | CM3629_ALS_PERS_1);
+ ls_cmd = (CM3629_ALS_IT_80ms | CM3629_ALS_PERS_1);/* disable CM3629_ALS_INT_EN */
else
- ls_cmd = (CM3629_ALS_IT_50ms | CM3629_ALS_PERS_1);
+ ls_cmd = (CM3629_ALS_IT_50ms | CM3629_ALS_PERS_1);/* disable CM3629_ALS_INT_EN */
D("[LS][cm3629] %s:resume %d\n",
__func__, resume);
} else
- ls_cmd = (lpi->ls_cmd);
+ ls_cmd = (lpi->ls_cmd);/* disable CM3629_ALS_INT_EN */
cmd[0] = ls_cmd;
cmd[1] = 0;
@@ -470,7 +473,7 @@ static int get_ws_adc_value(uint32_t *als_step, bool resume)
return -EIO;
}
-
+ /* Read WS data */
ret = _cm3629_I2C_Read2(lpi->cm3629_slave_address, WS_data, cmd, 2);
if (ret < 0) {
pr_err(
@@ -488,7 +491,7 @@ static int get_ws_adc_value(uint32_t *als_step, bool resume)
D("[LS][cm3629] %s: w sensor raw adc = 0x%X, ws_calibrate = %d\n",
__func__, *als_step, lpi->ws_calibrate);
-
+ /* W sesnor Calibration*/
if (!lpi->ws_calibrate) {
*als_step = (*als_step) * lpi->ws_gadc / lpi->ws_kadc;
if (*als_step > 0xFFFF)
@@ -520,6 +523,10 @@ static int get_ps_adc_value(uint8_t *ps1_adc, uint8_t *ps2_adc)
*ps1_adc = cmd[0];
*ps2_adc = cmd[1];
+/*
+ pr_info("[PS][cm3629] %s: PS1_ADC = 0x%02X, PS2_ADC = 0x%02X\n",
+ __func__, *ps1_adc, *ps2_adc);
+*/
return ret;
}
@@ -582,12 +589,12 @@ static void report_psensor_input_event(struct cm3629_info *lpi, int interrupt_fl
cancel_delayed_work(&report_near_work);
lpi->j_end = jiffies;
-
+ /* D("%s: j_end = %lu", __func__, lpi->j_end); */
ret = get_ps_adc_value(&ps1_adc, &ps2_adc);
if (pocket_mode_flag == 1 || psensor_enable_by_touch == 1) {
D("[PS][cm3629] pocket_mode_flag: %d, psensor_enable_by_touch: %d, add delay = 7ms\n", pocket_mode_flag, psensor_enable_by_touch);
- mdelay(7);
+ mdelay(7); // 0.32ms * IT * ITB * 12 = 6.144
while (index <= 10 && ps1_adc == 0) {
D("[PS][cm3629]ps1_adc = 0 retry");
get_ps_adc_value(&ps1_adc, &ps2_adc);
@@ -609,23 +616,24 @@ static void report_psensor_input_event(struct cm3629_info *lpi, int interrupt_fl
ps_thd_set = lpi->ps1_thd_set + lpi->ps1_thh_diff;
ps_adc = ps1_adc;
}
- if (interrupt_flag == 0) {
+ if (interrupt_flag == 0) {/*interrupt_fla = 0 meam polling mode*/
if (ret == 0) {
val = (ps_adc >= ps_thd_set) ? 0 : 1;
- } else {
+ } else {/*i2c err, report far to workaround*/
val = 1;
ps_adc = 0;
D("[PS][cm3629] proximity i2c err, report %s, "
"ps_adc=%d, record_init_fail %d\n",
val ? "FAR" : "NEAR", ps_adc, record_init_fail);
}
- } else {
+ } else {/*interrupt_fla = 2 meam close isr, interrupt_fla = 1 mean far isr*/
val = (interrupt_flag == 2) ? 0 : 1;
}
ps_near = !val;
if (lpi->ps_debounce == 1 && lpi->mfg_mode != MFG_MODE) {
if (val == 0) {
+/*======== dynamic threshold adjustment ====*/
if (lpi->dynamical_threshold == 1 && val == 0
&& pocket_mode_flag != 1 && psensor_enable_by_touch != 1 &&
time_before(lpi->j_end, (lpi->j_start + NEAR_DELAY_TIME))) {
@@ -633,6 +641,7 @@ static void report_psensor_input_event(struct cm3629_info *lpi, int interrupt_fl
blocking_notifier_call_chain(&psensor_notifier_list, 2 + oncall, NULL);
D("[PS][cm3629] Ignore NEAR event\n");
return;
+/*======== dynamic threshold adjustment ====*/
}
D("[PS][cm3629] delay proximity %s, ps_adc=%d, High thd= %d, interrupt_flag %d\n",
val ? "FAR" : "NEAR", ps_adc, ps_thd_set, interrupt_flag);
@@ -640,28 +649,30 @@ static void report_psensor_input_event(struct cm3629_info *lpi, int interrupt_fl
msecs_to_jiffies(lpi->ps_delay_time));
return;
} else {
-
+ /* dummy report */
input_report_abs(lpi->ps_input_dev, ABS_DISTANCE, -1);
input_sync(lpi->ps_input_dev);
}
}
D("[PS][cm3629] proximity %s, ps_adc=%d, High thd= %d, interrupt_flag %d, calibration %d\n",
val ? "FAR" : "NEAR", ps_adc, ps_thd_set, interrupt_flag, psensor_cali);
+/*======== dynamic threshold adjustment ====*/
if (lpi->dynamical_threshold == 1 && val == 0 && lpi->mfg_mode != MFG_MODE &&
pocket_mode_flag != 1 && psensor_enable_by_touch != 1 &&
time_before(lpi->j_end, (lpi->j_start + NEAR_DELAY_TIME))) {
blocking_notifier_call_chain(&psensor_notifier_list, 2 + oncall, NULL);
lpi->ps_pocket_mode = 1;
D("[PS][cm3629] Ignore NEAR event\n");
+/*======== dynamic threshold adjustment ====*/
} else {
-
+ /* 0 is close, 1 is far */
input_report_abs(lpi->ps_input_dev, ABS_DISTANCE, val);
input_sync(lpi->ps_input_dev);
blocking_notifier_call_chain(&psensor_notifier_list, val + 2 + oncall, NULL);
}
}
-static void enable_als_interrupt(void)
+static void enable_als_interrupt(void)/*enable als interrupt*/
{
char cmd[3];
struct cm3629_info *lpi = lp_info;
@@ -679,7 +690,7 @@ static void enable_als_interrupt(void)
}
static void report_lsensor_input_event(struct cm3629_info *lpi, int resume)
-{
+{/*when resume need report a data, so the paramerter need to quick reponse*/
uint32_t adc_value = 0;
#ifdef CONFIG_WSENSOR_ENABLE
int gain = 0;
@@ -698,7 +709,7 @@ static void report_lsensor_input_event(struct cm3629_info *lpi, int resume)
ret = get_ws_adc_value(&w_adc_value, resume);
D("[LS][cm3629] %s: before w sensor tuned, ws_adc = 0x%X, ls_adc = 0x%X, ls_calibrate = %d, ws_calibrate = %d\n",
__func__, w_adc_value, adc_value, lpi->ls_calibrate, lpi->ws_calibrate);
-
+ /* Algorithm */
if( adc_value >= (w_adc_value*12/10) )
gain = 100;
else
@@ -710,9 +721,9 @@ static void report_lsensor_input_event(struct cm3629_info *lpi, int resume)
if (resume) {
if (sensor_chipId[0] != 0x29)
- adc_value = adc_value*4;
+ adc_value = adc_value*4;/*because the cm3629_ALS_IT for 320ms - >80ms*/
else
- adc_value = adc_value*8;
+ adc_value = adc_value*8;/*because the cm3629_ALS_IT for 400ms - >50ms*/
if (adc_value > 0xFFFF)
adc_value = 0xFFFF;
}
@@ -722,7 +733,7 @@ static void report_lsensor_input_event(struct cm3629_info *lpi, int resume)
if (*(lpi->adc_table + i))
break;
}
- if (i == 9) {
+ if (i == 9) {/*avoid i = 10, because 'cali_table' of size is 10 */
level = i;
break;
}
@@ -748,7 +759,7 @@ static void report_lsensor_input_event(struct cm3629_info *lpi, int resume)
-
+ /*D("[cm3629] %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 (f_cm3629_level >= 0) {
D("[LS][cm3629] L-sensor force level enable level=%d f_cm3629_level=%d\n", level, f_cm3629_level);
level = f_cm3629_level;
@@ -786,7 +797,7 @@ static void enable_ps_interrupt(char *ps_conf)
ret = _cm3629_I2C_Write2(lpi->cm3629_slave_address,
PS_config_ms, cmd, 3);
- cmd[0] = ps_conf[0];
+ cmd[0] = ps_conf[0];/*power on at last step*/
cmd[1] = ps_conf[1];
D("[PS][cm3629] %s, write cmd[0] = 0x%x, cmd[1] = 0x%x\n",
__func__, cmd[0], cmd[1]);
@@ -807,22 +818,24 @@ static void sensor_irq_do_work(struct work_struct *work)
struct cm3629_info *lpi = lp_info;
uint8_t cmd[3];
uint8_t add = 0;
-
+ /* Check ALS or PS */
_cm3629_I2C_Read2(lpi->cm3629_slave_address, INT_FLAG, cmd, 2);
add = cmd[1];
-
+ /*D("[cm3629] %s:, INTERRUPT = 0x%x \n", __func__, add); */
if ((add & CM3629_PS1_IF_AWAY) || (add & CM3629_PS1_IF_CLOSE) ||
(add & CM3629_PS2_IF_AWAY) || (add & CM3629_PS2_IF_CLOSE)) {
wake_lock_timeout(&(lpi->ps_wake_lock), 2*HZ);
inter_error = 0;
if ((add & CM3629_PS1_IF_AWAY) || (add & CM3629_PS2_IF_AWAY)) {
- report_psensor_input_event(lpi, 1);
+ report_psensor_input_event(lpi, 1);/*1 meam far*/
p_irq_status = 0;
+/*======== dynamic threshold adjustment ====*/
min_adc = 255;
lpi->ps_base_index = lpi->mapping_size - 1;
+/*======== dynamic threshold adjustment ====*/
} else {
- report_psensor_input_event(lpi, 2);
+ report_psensor_input_event(lpi, 2);/*2 meam close*/
p_irq_status = 1;
}
if (lpi->ps_pocket_mode | p_irq_status)
@@ -841,7 +854,7 @@ static void sensor_irq_do_work(struct work_struct *work)
}
}
- if (!(add & 0x3F)) {
+ if (!(add & 0x3F)) { //Not P-sensor or Light sensor trigger
if (inter_error < 30) {
D("[PS][cm3629 warning]%s unkown interrupt: 0x%x!\n",
__func__, add);
@@ -891,8 +904,16 @@ static int get_stable_ps_adc_value(uint8_t *ps_adc1, uint8_t *ps_adc2)
}
}
+/*
+ D(" Before sort: adc1[] = [%d, %d, %d], adc2[] = [%d, %d, %d]\n",
+ adc1[0], adc1[1], adc1[2], adc2[0], adc2[1], adc2[2]);
+*/
mid_adc1 = mid_value(adc1, 3);
mid_adc2 = mid_value(adc2, 3);
+/*
+ D("After sort: adc1[] = [%d, %d, %d], adc2[] = [%d, %d, %d]\n",
+ adc1[0], adc1[1], adc1[2], adc2[0], adc2[1], adc2[2]);
+*/
*ps_adc1 = mid_adc1;
*ps_adc2 = mid_adc2;
@@ -936,7 +957,7 @@ static void polling_do_work(struct work_struct *w)
char cmd[3];
uint32_t ls_adc = 0;
uint8_t light_sensor_correction = 0;
-
+ /*D("lpi->ps_enable = %d\n", lpi->ps_enable);*/
lpi->j_end = jiffies;
if (time_after(lpi->j_end, (lpi->j_start + 3* HZ))){
lpi->ps_pocket_mode = 0;
@@ -955,8 +976,15 @@ static void polling_do_work(struct work_struct *w)
compute_light_sensor_correction(ls_adc, &light_sensor_correction);
} else
light_sensor_correction = 0;
+/*
+ D("[cm3629] Polling: ps_adc1 = 0x%02X, ps_adc2 = 0x%02X, "
+ "ps_next_base_value = 0x%02X, ps1_thd_set = 0x%02X\n",
+ ps_adc1, ps_adc2, lpi->mapping_table[lpi->ps_base_index],
+ lpi->ps1_thd_set);
+*/
if ( min_adc > (ps_adc1 + light_sensor_correction) ) {
+// D("[PS][cm3629] min_adc = %d, ps_adc1 = %d, light_sensor_correction = %d", min_adc, ps_adc1, light_sensor_correction);
avg_min_adc = 0;
min_adc = ps_adc1 + light_sensor_correction;
if (call_count < 2) {
@@ -990,7 +1018,7 @@ static void polling_do_work(struct work_struct *w)
if (lpi->ps1_thd_set <= avg_min_adc)
lpi->ps1_thd_set = 0xFF;
-
+ /* settng command code(0x01) = 0x03*/
cmd[0] = lpi->ps1_thd_set;
if (lpi->ps1_thh_diff == 0)
cmd[1] = lpi->ps1_thd_set + 1;
@@ -1011,7 +1039,7 @@ static void polling_do_work(struct work_struct *w)
if (avg_min_adc == 0 && lpi->ps1_thd_set != (lpi->mapping_table[0] + lpi->ps_th_add)) {
lpi->ps1_thd_set = (lpi->mapping_table[0] + lpi->ps_th_add);
-
+ /* settng command code(0x01) = 0x03*/
cmd[0] = lpi->ps1_thd_set;
if (lpi->ps1_thh_diff == 0)
cmd[1] = lpi->ps1_thd_set + 1;
@@ -1026,9 +1054,10 @@ static void polling_do_work(struct work_struct *w)
" cmd[0] = 0x%x, cmd[1] = 0x%x, avg_min_adc = %d\n",
lpi->ps1_thd_set, cmd[0], cmd[1], avg_min_adc);
}
-
- queue_delayed_work(lpi->lp_wq, &polling_work,
- msecs_to_jiffies(POLLING_DELAY));
+ if (!lpi->ps_stop_polling) {
+ queue_delayed_work(lpi->lp_wq, &polling_work,
+ msecs_to_jiffies(POLLING_DELAY));
+ }
}
#endif
@@ -1132,23 +1161,25 @@ static int psensor_enable(struct cm3629_info *lpi)
sensor_lpm_power(0);
blocking_notifier_call_chain(&psensor_notifier_list, 1 + oncall, NULL);
lpi->j_start = jiffies;
-
+ /*D("%s: j_start = %lu", __func__, lpi->j_start);*/
-
+ /* dummy report */
input_report_abs(lpi->ps_input_dev, ABS_DISTANCE, -1);
input_sync(lpi->ps_input_dev);
psensor_initial_cmd(lpi);
+/*======== dynamic threshold adjustment ====*/
if (lpi->dynamical_threshold == 1 && lpi->mfg_mode != MFG_MODE &&
pocket_mode_flag != 1 && psensor_enable_by_touch != 1 ) {
-
+ // default report FAR
D("[PS][cm3629] default report FAR ");
input_report_abs(lpi->ps_input_dev, ABS_DISTANCE, 1);
input_sync(lpi->ps_input_dev);
blocking_notifier_call_chain(&psensor_notifier_list, 1 + 2 + oncall, NULL);
} else
report_psensor_input_event(lpi, 0);
+/*======== dynamic threshold adjustment ====*/
cmd[0] = lpi->ps_conf1_val | CM3629_PS1_SD | CM3629_PS2_SD;
cmd[1] = lpi->ps_conf2_val;
@@ -1176,6 +1207,7 @@ static int psensor_enable(struct cm3629_info *lpi)
mutex_unlock(&ps_enable_mutex);
return ret;
}
+/*======== dynamic threshold adjustment ====*/
if (lpi->dynamical_threshold == 1 && lpi->mfg_mode != MFG_MODE &&
pocket_mode_flag != 1 && psensor_enable_by_touch != 1 ) {
@@ -1200,6 +1232,7 @@ static int psensor_enable(struct cm3629_info *lpi)
msecs_to_jiffies(POLLING_DELAY));
}
}
+/*======== dynamic threshold adjustment ====*/
mutex_unlock(&ps_enable_mutex);
D("[PS][cm3629] %s -\n", __func__);
return ret;
@@ -1262,7 +1295,7 @@ static int psensor_disable(struct cm3629_info *lpi)
lpi->ps_base_index = (lpi->mapping_size - 1);
if (lpi->ps1_thd_set > Max_open_value) {
lpi->ps1_thd_set = lpi->original_ps_thd_set;
-
+ // settng command code(0x01) = 0x03
cmd[0] = lpi->ps1_thd_set;
if (lpi->ps1_thh_diff == 0)
cmd[1] = lpi->ps1_thd_set + 1;
@@ -1417,7 +1450,7 @@ static void psensor_set_kvalue(struct cm3629_info *lpi)
D("[PS][cm3629] %s: PS calibrated ps_kparam1 = 0x%04X, "
"ps_kparam2 = 0x%04X\n", __func__, lpi->ps_kparam1, lpi->ps_kparam2);
ps_conf1_val = lpi->ps_conf1_val;
-
+ /* Only use ps_kparam2 for CM36282/CM36292 */
if (lpi->ps_kparam1 >> 16 == PS_CALIBRATED) {
psensor_cali = 1;
@@ -1427,7 +1460,7 @@ static void psensor_set_kvalue(struct cm3629_info *lpi)
else
lpi->inte_ps2_canc = (uint8_t) ((lpi->ps_kparam2 >> 16) & 0xFF);
- if (lpi->ps_calibration_rule == 3) {
+ if (lpi->ps_calibration_rule == 3) {/*for vigor*/
if ((lpi->ps_conf1_val & CM3629_PS_IT_1_6T) == CM3629_PS_IT_1_6T) {
D("[PS][cm3629] %s: lpi->ps_conf1_val 0x%x, CM3629_PS_IT_1_6T\n",
@@ -1512,7 +1545,7 @@ static int lightsensor_enable(struct cm3629_info *lpi)
D("[LS][cm3629] %s\n", __func__);
if (sensor_chipId[0] != 0x29)
- cmd[0] = (CM3629_ALS_IT_80ms | CM3629_ALS_PERS_1);
+ cmd[0] = (CM3629_ALS_IT_80ms | CM3629_ALS_PERS_1);/* disable CM3629_ALS_INT_EN */
else
cmd[0] = (CM3629_ALS_IT_50ms | CM3629_ALS_PERS_1);
@@ -1589,7 +1622,7 @@ static long lightsensor_ioctl(struct file *file, unsigned int cmd,
int rc, val;
struct cm3629_info *lpi = lp_info;
-
+ /*D("[cm3629] %s cmd %d\n", __func__, _IOC_NR(cmd));*/
switch (cmd) {
case LIGHTSENSOR_IOCTL_ENABLE:
@@ -1676,7 +1709,7 @@ static ssize_t ps_enable_store(struct device *dev,
return -EINVAL;
if (lpi->ps_calibration_rule == 3 &&
- (ps_en == 10 || ps_en == 13 || ps_en == 16)) {
+ (ps_en == 10 || ps_en == 13 || ps_en == 16)) {/*for vigor*/
if ((lpi->ps_conf1_val & CM3629_PS_IT_1_6T) == CM3629_PS_IT_1_6T) {
D("[PS][cm3629] %s: lpi->ps_conf1_val 0x%x, CM3629_PS_IT_1_6T\n",
__func__, lpi->ps_conf1_val);
@@ -1758,7 +1791,7 @@ static ssize_t ps_kadc_store(struct device *dev,
sscanf(buf, "0x%x 0x%x", &param1, &param2);
D("[PS][cm3629]%s: store value = 0x%X, 0x%X\n", __func__, param1, param2);
ps_conf1_val = lpi->ps_conf1_val;
- if (lpi->ps_calibration_rule == 3) {
+ if (lpi->ps_calibration_rule == 3) {/*for vigor*/
if ((lpi->ps_conf1_val & CM3629_PS_IT_1_6T) == CM3629_PS_IT_1_6T) {
D("[PS][cm3629] %s: lpi->ps_conf1_val 0x%x, CM3629_PS_IT_1_6T\n",
@@ -2103,7 +2136,7 @@ static ssize_t ls_adc_show(struct device *dev,
int ret;
struct cm3629_info *lpi = lp_info;
-
+ /*because 3628 is interrupt mode*/
report_lsensor_input_event(lpi, 0);
D("[LS][cm3629] %s: ADC = 0x%04X, Level = %d \n",
@@ -2119,7 +2152,7 @@ static DEVICE_ATTR(ls_adc, 0664, ls_adc_show, NULL);
static ssize_t ls_enable_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
-
+ /*Todo: becase cm3629 registers can't be read, need to think ho w*/
int ret = 0;
struct cm3629_info *lpi = lp_info;
@@ -2381,6 +2414,7 @@ static ssize_t p_status_show(struct device *dev,
}
static DEVICE_ATTR(p_status, 0444, p_status_show, NULL);
+/*======== dynamic threshold adjustment ====*/
static ssize_t phone_status_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -2395,18 +2429,31 @@ static ssize_t phone_status_store(struct device *dev,
const char *buf, size_t count)
{
int phone_status1 = 0;
+/* int i;
+ char cmd[2];*/
struct cm3629_info *lpi = lp_info;
sscanf(buf, "%d" , &phone_status1);
phone_status = phone_status1;
+/*
+phone_status:
+call end = 0
+call out = 1
+call connect = 2
+call in = 3
+*/
D("[PS][cm3629] %s: phone_status = %d\n", __func__, phone_status);
+/* if (phone_status == 0)
+ oncall = 0;
+ else
+ oncall = 4;*/
if ((phone_status == 1 || phone_status == 3) && (call_count < 2))
call_count++;
- if (phone_status == 1 || phone_status == 2) {
+ if (phone_status == 1 || phone_status == 2) { // reset polling index
min_adc = 255;
lpi->ps_base_index = (lpi->mapping_size - 1);
}
@@ -2416,10 +2463,12 @@ static ssize_t phone_status_store(struct device *dev,
if (phone_status == 2 && ps_hal_enable == 1 && lpi->dynamical_threshold == 1
&&(lpi->mapping_table != NULL)) {
-
+ /* default report FAR */
input_report_abs(lpi->ps_input_dev, ABS_DISTANCE, 1);
input_sync(lpi->ps_input_dev);
+/* do not report to touch when phone connect*/
+// blocking_notifier_call_chain(&psensor_notifier_list, 1 + 2 + oncall, NULL);
queue_delayed_work(lpi->lp_wq, &polling_work,
msecs_to_jiffies(POLLING_DELAY));
@@ -2436,7 +2485,7 @@ static ssize_t phone_status_store(struct device *dev,
lpi->ps_base_index = (lpi->mapping_size - 1);
if (lpi->ps1_thd_set > Max_open_value) {
lpi->ps1_thd_set = lpi->original_ps_thd_set;
-
+ // settng command code(0x01) = 0x03
cmd[0] = lpi->ps1_thd_set;
if (lpi->ps1_thh_diff == 0)
cmd[1] = lpi->ps1_thd_set + 1;
@@ -2450,6 +2499,7 @@ static ssize_t phone_status_store(struct device *dev,
#endif
}
static DEVICE_ATTR(PhoneApp_status, 0666, phone_status_show, phone_status_store);
+/*======== dynamic threshold adjustment ====*/
static ssize_t ls_dark_level_show(struct device *dev,
struct device_attribute *attr, char *buf)
@@ -2571,12 +2621,12 @@ int power_key_check_in_pocket(void)
}
pocket_mode_flag = 1;
D("[cm3629] %s +++\n", __func__);
-
+ /* get p-sensor status */
psensor_enable(lpi);
D("[cm3629] %s ps_near %d\n", __func__, ps_near);
psensor_disable(lpi);
-
+ /* get light sensor status */
mutex_lock(&als_get_adc_mutex);
get_ls_adc_value(&ls_adc, 0);
enable_als_interrupt();
@@ -2587,7 +2637,7 @@ int power_key_check_in_pocket(void)
if (*(lpi->adc_table + i))
break;
}
- if (i == 9) {
+ if (i == 9) {/*avoid i = 10, because 'cali_table' of size is 10 */
ls_level = i;
break;
}
@@ -2669,7 +2719,7 @@ static int cm3629_setup(struct cm3629_info *lpi)
ls_initial_cmd(lpi);
psensor_initial_cmd(lpi);
-
+ /* Disable P-sensor by default */
cmd[0] = lpi->ps_conf1_val | CM3629_PS1_SD | CM3629_PS2_SD;
cmd[1] = lpi->ps_conf2_val;
_cm3629_I2C_Write2(lpi->cm3629_slave_address, PS_config, cmd, 3);
@@ -2678,6 +2728,7 @@ static int cm3629_setup(struct cm3629_info *lpi)
cmd[1] = CM3629_PS_255_STEPS;
_cm3629_I2C_Write2(lpi->cm3629_slave_address, PS_config_ms, cmd, 3);
+// ret = request_any_context_irq(lpi->irq,
ret = request_irq(lpi->irq,
cm3629_irq_handler,
IRQF_TRIGGER_LOW,
@@ -2749,6 +2800,13 @@ static void cm3629_late_resume(struct early_suspend *h)
}
#endif
+/*
+static void release_psensor_wakelock_handler(void)
+{
+ struct cm3629_info *lpi = lp_info;
+ wake_unlock(&lpi->ps_wake_lock);
+ D("[PS][cm3629] %s\n", __func__);
+}*/
static int cm3629_ldo_init(int init)
{
int rc = 0;
@@ -3047,8 +3105,8 @@ static int __devinit cm3629_probe(struct i2c_client *client,
lpi->ps_calibration_rule = pdata->ps_calibration_rule;
lpi->j_start = 0;
lpi->j_end = 0;
- lpi->mapping_table = cm3629_mapping_table;
- lpi->mapping_size = ARRAY_SIZE(cm3629_mapping_table);
+ lpi->mapping_table = cm3629_mapping_table;//pdata->mapping_table;
+ lpi->mapping_size = ARRAY_SIZE(cm3629_mapping_table);//pdata->mapping_size;
lpi->ps_base_index = (ARRAY_SIZE(cm3629_mapping_table) - 1);
lpi->dynamical_threshold = pdata->dynamical_threshold;
lpi->ps1_thd_no_cal = pdata->ps1_thd_no_cal;
@@ -3068,6 +3126,7 @@ static int __devinit cm3629_probe(struct i2c_client *client,
lpi->emmc_ps_kadc1 = pdata->emmc_ps_kadc1;
lpi->emmc_ps_kadc2 = pdata->emmc_ps_kadc2;
lpi->use__PS2v85 = pdata->use__PS2v85;
+ lpi->ps_stop_polling = 0;
lp_info = lpi;
ret = cm3629_read_chip_id(lpi);
@@ -3260,6 +3319,7 @@ static int __devinit cm3629_probe(struct i2c_client *client,
lpi->early_suspend.resume = cm3629_late_resume;
register_early_suspend(&lpi->early_suspend);
#endif
+// state_helper_register_notifier(&release_psensor_wakelock_handler, "psensor_release_wakelock_event");
ret = cm3629_ldo_init(1);
if (ret) {
pr_err(" [PS][cm3629] Sensor vreg configuration failed\n");
@@ -3308,6 +3368,33 @@ err_alloc_data_failed:
return ret;
}
+static int cm3629_suspend(struct device *dev)
+{
+ struct cm3629_info *lpi = lp_info;
+
+ D("[PS][cm3629] cm3629_suspend\n");
+ lpi->ps_stop_polling = 1;
+ cancel_delayed_work(&polling_work);
+ return 0;
+}
+static int cm3629_resume(struct device *dev)
+{
+ struct cm3629_info *lpi = lp_info;
+
+ D("[PS][cm3629] cm3629_resume\n");
+ lpi->ps_stop_polling = 0;
+ if (lpi->dynamical_threshold == 1 && lpi->mfg_mode != MFG_MODE
+ && lpi->ps_enable && pocket_mode_flag != 1 && psensor_enable_by_touch != 1) {
+ queue_delayed_work(lpi->lp_wq, &polling_work,
+ msecs_to_jiffies(POLLING_DELAY));
+ }
+ return 0;
+}
+
+static const struct dev_pm_ops cm3629_pm_ops = {
+ .suspend = cm3629_suspend,
+ .resume = cm3629_resume
+};
static struct i2c_device_id cm3629_i2c_id[] = {
{"CM3629", 0},
@@ -3324,6 +3411,7 @@ static struct i2c_driver cm3629_driver = {
.driver = {
.name = "CM3629",
.owner = THIS_MODULE,
+ .pm = &cm3629_pm_ops,
#ifdef CONFIG_OF
.of_match_table = cm3629_match_table,
#endif
diff --git a/drivers/i2c/chips/cm36686.c b/drivers/i2c/chips/cm36686.c
index cbb1b5e..afabe61 100644
--- a/drivers/i2c/chips/cm36686.c
+++ b/drivers/i2c/chips/cm36686.c
@@ -121,8 +121,8 @@ struct cm36686_info {
uint16_t cali_table[10];
int irq;
int ls_calibrate;
- int (*power)(int, uint8_t);
- int (*lpm_power)(int on);
+ int (*power)(int, uint8_t); /* power to the chip */
+ int (*lpm_power)(int on); /* power to the chip */
uint32_t als_kadc;
uint32_t emmc_als_kadc;
uint32_t als_gadc;
@@ -287,7 +287,7 @@ static int _cm36686_I2C_Read2(uint16_t slaveAddr,
*(pdata+i) = buffer[i];
}
#if 0
-
+ /* Debug use */
printk(KERN_DEBUG "[cm36686] %s: I2C_RxData[0x%x] = 0x%x\n",
__func__, slaveAddr, buffer);
#endif
@@ -300,7 +300,7 @@ static int _cm36686_I2C_Write2(uint16_t SlaveAddress,
char buffer[3];
int ret = 0;
#if 0
-
+ /* Debug use */
printk(KERN_DEBUG
"[cm36686] %s: _cm36686_I2C_Write_Byte[0x%x, 0x%x, 0x%x]\n",
__func__, SlaveAddress, cmd, *data);
@@ -344,10 +344,10 @@ static int get_ls_adc_value(uint32_t *als_step, int resume)
return -EFAULT;
if (resume == 1) {
- ls_cmd = (CM36686_ALS_IT_80ms | CM36686_ALS_PERS_1);
+ ls_cmd = (CM36686_ALS_IT_80ms | CM36686_ALS_PERS_1); /* disable CM36686_ALS_INT_EN */
D("[LS][cm36686] %s:resume %d\n", __func__, resume);
} else
- ls_cmd = (lpi->ls_cmd);
+ ls_cmd = (lpi->ls_cmd); /* disable CM36686_ALS_INT_EN */
cmd[0] = ls_cmd;
cmd[1] = 0;
@@ -358,7 +358,7 @@ static int get_ls_adc_value(uint32_t *als_step, int resume)
return -EIO;
}
-
+ /* Read ALS data */
ret = _cm36686_I2C_Read2(lpi->cm36686_slave_address, ALS_data, cmd, 2);
if (ret < 0) {
@@ -404,6 +404,10 @@ static int get_ps_adc_value(uint16_t *ps_adc)
return -EIO;
}
*ps_adc = (cmd[1] << 8) | cmd[0];
+ /*
+ pr_info("[PS][cm36686] %s: PS1_ADC = 0x%02X, PS2_ADC = 0x%02X\n",
+ __func__, *ps1_adc, *ps2_adc);
+ */
return ret;
}
@@ -462,13 +466,13 @@ static void report_psensor_input_event(struct cm36686_info *lpi, int interrupt_f
cancel_delayed_work(&report_near_work);
lpi->j_end = jiffies;
-
+ /* D("%s: j_end = %lu", __func__, lpi->j_end); */
ret = get_ps_adc_value(&ps1_adc);
if (pocket_mode_flag == 1 || psensor_enable_by_touch == 1) {
D("[PS][cm36686] pocket_mode_flag: %d, psensor_enable_by_touch: %d, add delay = 7ms\n", pocket_mode_flag, psensor_enable_by_touch);
- mdelay(7);
+ mdelay(7); /* 0.32ms * IT * ITB * 12 = 6.144*/
while (index <= 10 && ps1_adc == 0) {
D("[PS][cm36686]ps1_adc = 0 retry");
get_ps_adc_value(&ps1_adc);
@@ -488,23 +492,23 @@ static void report_psensor_input_event(struct cm36686_info *lpi, int interrupt_f
ps_adc = ps1_adc;
- if (interrupt_flag == 0) {
+ if (interrupt_flag == 0) { /*interrupt_fla = 0 meam polling mode*/
if (ret == 0) {
val = (ps_adc >= ps_thd_set) ? 0 : 1;
- } else {
+ } else { /*i2c err, report far to workaround*/
val = 1;
ps_adc = 0;
D("[PS][cm36686] proximity i2c err, report %s, ps_adc=%d, record_init_fail %d\n",
val ? "FAR" : "NEAR", ps_adc, record_init_fail);
}
- } else {
+ } else { /*interrupt_fla = 2 meam close isr, interrupt_fla = 1 mean far isr*/
val = (interrupt_flag == 2) ? 0 : 1;
}
ps_near = !val;
if (lpi->ps_debounce == 1 && lpi->mfg_mode != MFG_MODE) {
if (val == 0) {
-
+ /*======== dynamic threshold adjustment ====*/
if (lpi->dynamical_threshold == 1 && val == 0
&& pocket_mode_flag != 1 && psensor_enable_by_touch != 1 &&
time_before(lpi->j_end, (lpi->j_start + NEAR_DELAY_TIME))) {
@@ -512,7 +516,7 @@ static void report_psensor_input_event(struct cm36686_info *lpi, int interrupt_f
blocking_notifier_call_chain(&psensor_notifier_list, 2 + oncall, NULL);
D("[PS][cm36686] Ignore NEAR event\n");
return;
-
+ /*======== dynamic threshold adjustment ====*/
}
D("[PS][cm36686] delay proximity %s, ps_adc=%d, High thd= %d, interrupt_flag %d\n",
val ? "FAR" : "NEAR", ps_adc, ps_thd_set, interrupt_flag);
@@ -520,23 +524,23 @@ static void report_psensor_input_event(struct cm36686_info *lpi, int interrupt_f
msecs_to_jiffies(lpi->ps_delay_time));
return;
} else {
-
+ /* dummy report */
input_report_abs(lpi->ps_input_dev, ABS_DISTANCE, -1);
input_sync(lpi->ps_input_dev);
}
}
D("[PS][cm36686] proximity %s, ps_adc=%d, High thd= %d, interrupt_flag %d, calibration %d\n",
val ? "FAR" : "NEAR", ps_adc, ps_thd_set, interrupt_flag, psensor_cali);
-
+ /*======== dynamic threshold adjustment ====*/
if (lpi->dynamical_threshold == 1 && val == 0 && lpi->mfg_mode != MFG_MODE &&
pocket_mode_flag != 1 && psensor_enable_by_touch != 1 &&
time_before(lpi->j_end, (lpi->j_start + NEAR_DELAY_TIME))) {
blocking_notifier_call_chain(&psensor_notifier_list, 2 + oncall, NULL);
lpi->ps_pocket_mode = 1;
D("[PS][cm36686] Ignore NEAR event\n");
-
+ /*======== dynamic threshold adjustment ====*/
} else {
-
+ /* 0 is close, 1 is far */
input_report_abs(lpi->ps_input_dev, ABS_DISTANCE, val);
input_sync(lpi->ps_input_dev);
blocking_notifier_call_chain(&psensor_notifier_list, val + 2 + oncall, NULL);
@@ -562,7 +566,7 @@ static void enable_als_interrupt(void)
static void report_lsensor_input_event(struct cm36686_info *lpi, int resume)
{
-
+ /*when resume need report a data, so the paramerter need to quick reponse*/
uint32_t adc_value = 0;
int level = 0, i, ret = 0;
@@ -572,7 +576,7 @@ static void report_lsensor_input_event(struct cm36686_info *lpi, int resume)
ret = get_ls_adc_value(&adc_value, resume);
if (resume) {
- adc_value = adc_value * 4;
+ adc_value = adc_value * 4; /*because the cm36686_ALS_IT for 320ms - >80ms*/
if (adc_value > 0xFFFF)
adc_value = 0xFFFF;
}
@@ -582,7 +586,7 @@ static void report_lsensor_input_event(struct cm36686_info *lpi, int resume)
if (*(lpi->adc_table + i))
break;
}
- if (i == 9) {
+ if (i == 9) { /*avoid i = 10, because 'cali_table' of size is 10 */
level = i;
break;
}
@@ -604,7 +608,7 @@ static void report_lsensor_input_event(struct cm36686_info *lpi, int resume)
lpi->current_level = level;
lpi->current_adc = adc_value;
-
+ /*D("[cm36686] %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 (f_cm36686_level >= 0) {
D("[LS][cm36686] L-sensor force level enable level=%d f_cm36686_level=%d\n", level, f_cm36686_level);
level = f_cm36686_level;
@@ -640,7 +644,7 @@ static void enable_ps_interrupt(char *ps_conf)
ret = _cm36686_I2C_Write2(lpi->cm36686_slave_address,
PS_config_ms, cmd, 3);
- cmd[0] = ps_conf[0];
+ cmd[0] = ps_conf[0]; /*power on at last step*/
cmd[1] = ps_conf[1];
D("[PS][cm36686] %s, write cmd[0] = 0x%x, cmd[1] = 0x%x\n", __func__, cmd[0], cmd[1]);
ret = _cm36686_I2C_Write2(lpi->cm36686_slave_address, PS_config, cmd, 3);
@@ -660,23 +664,23 @@ static void sensor_irq_do_work(struct work_struct *work)
struct cm36686_info *lpi = lp_info;
uint8_t cmd[3];
uint8_t add = 0;
-
+ /* Check ALS or PS */
_cm36686_I2C_Read2(lpi->cm36686_slave_address, INT_FLAG, cmd, 2);
add = cmd[1];
-
+ /*D("[cm36686] %s:, INTERRUPT = 0x%x \n", __func__, add); */
if ((add & CM36686_PS_IF_AWAY) || (add & CM36686_PS_IF_CLOSE)) {
wake_lock_timeout(&(lpi->ps_wake_lock), 2*HZ);
inter_error = 0;
if (add & CM36686_PS_IF_AWAY) {
- report_psensor_input_event(lpi, 1);
+ report_psensor_input_event(lpi, 1); /*1 meam far*/
p_irq_status = 0;
-
+ /*======== dynamic threshold adjustment ====*/
min_adc = PS_max;
lpi->ps_base_index = lpi->mapping_size - 1;
-
+ /*======== dynamic threshold adjustment ====*/
} else {
- report_psensor_input_event(lpi, 2);
+ report_psensor_input_event(lpi, 2); /*2 meam close*/
p_irq_status = 1;
}
if (lpi->ps_pocket_mode | p_irq_status)
@@ -695,7 +699,7 @@ static void sensor_irq_do_work(struct work_struct *work)
}
}
- if (!(add & 0x3F)) {
+ if (!(add & 0x3F)) { /*Not P-sensor or Light sensor trigger*/
if (inter_error < 30) {
D("[PS][cm36686 warning]%s unkown interrupt: 0x%x!\n", __func__, add);
inter_error++ ;
@@ -781,7 +785,7 @@ static void polling_do_work(struct work_struct *w)
char cmd[3];
uint32_t ls_adc = 0;
uint8_t light_sensor_correction = 0;
-
+ /*D("lpi->ps_enable = %d\n", lpi->ps_enable);*/
lpi->j_end = jiffies;
if (time_after(lpi->j_end, (lpi->j_start + 3* HZ))){
lpi->ps_pocket_mode = 0;
@@ -800,9 +804,15 @@ static void polling_do_work(struct work_struct *w)
compute_light_sensor_correction(ls_adc, &light_sensor_correction);
} else
light_sensor_correction = 0;
+ /*
+ D("[cm36686] Polling: ps_adc = 0x%02X, ps_adc2 = 0x%02X, "
+ "ps_next_base_value = 0x%02X, ps1_thd_set = 0x%02X\n",
+ ps_adc, ps_adc2, lpi->mapping_table[lpi->ps_base_index],
+ lpi->ps1_thd_set);
+ */
if ( min_adc > (ps_adc + light_sensor_correction) ) {
-
+ // D("[PS][cm36686] min_adc = %d, ps_adc = %d, light_sensor_correction = %d", min_adc, ps_adc, light_sensor_correction);
avg_min_adc = 0;
min_adc = ps_adc + light_sensor_correction;
if (call_count < 2) {
@@ -975,25 +985,25 @@ static int psensor_enable(struct cm36686_info *lpi)
sensor_lpm_power(0);
blocking_notifier_call_chain(&psensor_notifier_list, 1 + oncall, NULL);
lpi->j_start = jiffies;
-
+ /*D("%s: j_start = %lu", __func__, lpi->j_start);*/
-
+ /* dummy report */
input_report_abs(lpi->ps_input_dev, ABS_DISTANCE, -1);
input_sync(lpi->ps_input_dev);
psensor_initial_cmd(lpi);
-
+ /*======== dynamic threshold adjustment ====*/
if (lpi->dynamical_threshold == 1 && lpi->mfg_mode != MFG_MODE &&
pocket_mode_flag != 1 && psensor_enable_by_touch != 1 ) {
-
+ // default report FAR
D("[PS][cm36686] default report FAR ");
input_report_abs(lpi->ps_input_dev, ABS_DISTANCE, 1);
input_sync(lpi->ps_input_dev);
blocking_notifier_call_chain(&psensor_notifier_list, 1 + 2 + oncall, NULL);
} else
report_psensor_input_event(lpi, 0);
-
+ /*======== dynamic threshold adjustment ====*/
cmd[0] = lpi->ps_conf1_val | CM36686_PS_SD;
cmd[1] = lpi->ps_conf2_val;
@@ -1015,7 +1025,7 @@ static int psensor_enable(struct cm36686_info *lpi)
mutex_unlock(&ps_enable_mutex);
return ret;
}
-
+ /*======== dynamic threshold adjustment ====*/
if (lpi->dynamical_threshold == 1 && lpi->mfg_mode != MFG_MODE &&
pocket_mode_flag != 1 && psensor_enable_by_touch != 1 ) {
@@ -1041,7 +1051,7 @@ static int psensor_enable(struct cm36686_info *lpi)
msecs_to_jiffies(POLLING_DELAY));
}
}
-
+ /*======== dynamic threshold adjustment ====*/
mutex_unlock(&ps_enable_mutex);
D("[PS][cm36686] %s -\n", __func__);
return ret;
@@ -1232,7 +1242,7 @@ static void psensor_set_kvalue(struct cm36686_info *lpi)
D("[PS][cm36686] %s: PS calibrated ps_kparam1 = 0x%04X, "
"ps_kparam2 = 0x%04X\n", __func__, lpi->ps_kparam1, lpi->ps_kparam2);
ps_conf1_val = lpi->ps_conf1_val;
-
+ /* Only use ps_kparam2 for CM36282/CM36686 */
if (lpi->ps_kparam1 >> 16 == PS_CALIBRATED) {
psensor_cali = 1;
lpi->inte_ps_canc = (uint16_t) (lpi->ps_kparam2 & 0xFFFF);
@@ -1279,7 +1289,7 @@ static int lightsensor_enable(struct cm36686_info *lpi)
sensor_lpm_power(0);
D("[LS][cm36686] %s\n", __func__);
- cmd[0] = (CM36686_ALS_IT_80ms | CM36686_ALS_PERS_1);
+ cmd[0] = (CM36686_ALS_IT_80ms | CM36686_ALS_PERS_1);/* disable CM36686_ALS_INT_EN */
cmd[1] = 0;
ret = _cm36686_I2C_Write2(lpi->cm36686_slave_address,
ALS_config_cmd, cmd, 3);
@@ -1350,7 +1360,7 @@ static long lightsensor_ioctl(struct file *file, unsigned int cmd,
int rc, val;
struct cm36686_info *lpi = lp_info;
-
+ /*D("[cm36686] %s cmd %d\n", __func__, _IOC_NR(cmd));*/
switch (cmd) {
case LIGHTSENSOR_IOCTL_ENABLE:
@@ -1986,6 +1996,7 @@ static ssize_t p_status_show(struct device *dev,
return sprintf(buf,"%d\n",p_status);
}
static DEVICE_ATTR(p_status, 0444, p_status_show, NULL);
+/*======== dynamic threshold adjustment ====*/
static ssize_t phone_status_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -2005,13 +2016,24 @@ static ssize_t phone_status_store(struct device *dev,
sscanf(buf, "%d" , &phone_status1);
phone_status = phone_status1;
+ /*
+phone_status:
+call end = 0
+call out = 1
+call connect = 2
+call in = 3
+ */
D("[PS][cm36686] %s: phone_status = %d\n", __func__, phone_status);
+ /* if (phone_status == 0)
+ oncall = 0;
+ else
+ oncall = 4;*/
if ((phone_status == 1 || phone_status == 3) && (call_count < 2))
call_count++;
- if (phone_status == 1 || phone_status == 2) {
+ if (phone_status == 1 || phone_status == 2) { // reset polling index
min_adc = PS_max;
lpi->ps_base_index = (lpi->mapping_size - 1);
}
@@ -2019,6 +2041,7 @@ static ssize_t phone_status_store(struct device *dev,
return count;
}
static DEVICE_ATTR(PhoneApp_status, 0666, phone_status_show, phone_status_store);
+/*======== dynamic threshold adjustment ====*/
static ssize_t ls_dark_level_show(struct device *dev,
struct device_attribute *attr, char *buf)
@@ -2128,12 +2151,12 @@ int power_key_check_in_pocket(void)
}
pocket_mode_flag = 1;
D("[cm36686] %s +++\n", __func__);
-
+ /* get p-sensor status */
psensor_enable(lpi);
D("[cm36686] %s ps_near %d\n", __func__, ps_near);
psensor_disable(lpi);
-
+ /* get light sensor status */
mutex_lock(&als_get_adc_mutex);
get_ls_adc_value(&ls_adc, 0);
enable_als_interrupt();
@@ -2144,7 +2167,7 @@ int power_key_check_in_pocket(void)
if (*(lpi->adc_table + i))
break;
}
- if (i == 9) {
+ if (i == 9) { /*avoid i = 10, because 'cali_table' of size is 10 */
ls_level = i;
break;
}
@@ -2225,7 +2248,7 @@ static int cm36686_setup(struct cm36686_info *lpi)
ls_initial_cmd(lpi);
psensor_initial_cmd(lpi);
-
+ /* Disable P-sensor by default */
cmd[0] = lpi->ps_conf1_val | CM36686_PS_SD;
cmd[1] = lpi->ps_conf2_val;
_cm36686_I2C_Write2(lpi->cm36686_slave_address, PS_config, cmd, 3);
@@ -2234,7 +2257,7 @@ static int cm36686_setup(struct cm36686_info *lpi)
cmd[1] = lpi->ps_ms_val;
_cm36686_I2C_Write2(lpi->cm36686_slave_address, PS_config_ms, cmd, 3);
-
+ // ret = request_any_context_irq(lpi->irq,
ret = request_irq(lpi->irq,
cm36686_irq_handler,
IRQF_TRIGGER_LOW,
@@ -2292,7 +2315,7 @@ static int cm36686_ldo_init(int init)
return -1;
}
if (!init) {
-
+ //per HW request, correct sr_2v85 changes to 3v for A11
if(lpi->SR_3v_used)
regulator_set_voltage(lpi->sr_2v85, 0, 3000000);
else
@@ -2316,7 +2339,7 @@ static int cm36686_ldo_init(int init)
}
D("[PS][cm36686] %s: lpi->sr_2v85 = 0x%p\n", __func__, lpi->sr_2v85);
-
+ //per HW request, correct sr_2v85 changes to 3v for A11
if(lpi->SR_3v_used)
rc = regulator_set_voltage(lpi->sr_2v85, 3000000, 3000000);
else
diff --git a/drivers/i2c/chips/epl88051.c b/drivers/i2c/chips/epl88051.c
index 4a81f0f..7e07560 100644
--- a/drivers/i2c/chips/epl88051.c
+++ b/drivers/i2c/chips/epl88051.c
@@ -12,6 +12,7 @@
*
*/
+/** VERSION: 1.02**/
#include <linux/lightsensor.h>
#include <linux/hrtimer.h>
#include <linux/timer.h>
@@ -47,15 +48,19 @@
#include <mach/board_htc.h>
#define PS_RAW_8BIT
-#define PS_POLLING_MODE 0
+//#define outputLUX
+/******************************************************************************
+ * configuration
+ *******************************************************************************/
+#define PS_POLLING_MODE 0 // 1 is polling mode, 0 is interrupt mode
-#ifdef PS_RAW_8BIT
+#ifdef PS_RAW_8BIT //ices add by 20131230 /*PS_RAW_8BIT*/
#define PS_LOW_THRESHOLD 7
#define PS_HIGH_THRESHOLD 13
#else
#define PS_LOW_THRESHOLD 2000
#define PS_HIGH_THRESHOLD 5000
-#endif
+#endif //ices add by 20131230 /*PS_RAW_8BIT*/
#define LUX_PER_COUNT 700
#define PS_DELAY 35
@@ -73,10 +78,10 @@ static int hs_count = 0;
static int start_idx = 0;
static struct mutex sensor_mutex;
static int HS_INTT = EPL_INTT_PS_250;
-static int PS_INTT = EPL_INTT_PS_150;
+static int PS_INTT = EPL_INTT_PS_150; //EPL_INTT_PS_70; //psensor integration time
int c_gain;
int dynamic_intt_idx;
-int dynamic_intt_init_idx = 1;
+int dynamic_intt_init_idx = 1; //Dynamic init idx
static int lightsensor_cali;
uint32_t dynamic_intt_min_unit = 1000;
uint8_t dynamic_intt_intt;
@@ -92,21 +97,22 @@ static int als_dynamic_intt_intt_num = sizeof(als_dynamic_intt_intt_value)/size
static uint32_t adctable[10] = {0};
static int p_status = 9;
static int psensor_enabled;
+/*******************************************************************************/
#define TXBYTES 2
#define RXBYTES 2
#define PACKAGE_SIZE 2
#define I2C_RETRY_COUNT 10
-#define MAX_PS_CH0 30000
+#define MAX_PS_CH0 30000 //ices add 20140814
typedef struct _epl_raw_data
{
u8 raw_bytes[PACKAGE_SIZE];
u16 ps_state;
- u8 con_sat;
+ u8 con_sat; //ices add by 20140812
u16 ps_raw;
- u16 ps_ch0_raw;
+ u16 ps_ch0_raw; //ices add by 20140814
u16 als_ch0_raw;
u16 als_ch1_raw;
u16 als_ch0_raw_now;
@@ -170,11 +176,11 @@ struct epl88051_priv
int read_flag;
int irq;
- int c_gain_h;
- int c_gain_l;
+ int c_gain_h; // fluorescent (C1)
+ int c_gain_l; // incandescent (C2)
int c_gain_saturated;
- uint32_t lsource_thd_high;
- uint32_t lsource_thd_low;
+ uint32_t lsource_thd_high; //different light source boundary (N) fluorescent (C1)
+ uint32_t lsource_thd_low; //different light source boundary (N) incandescent (C2)
int ps_delay;
uint32_t emmc_als_kadc;
@@ -309,17 +315,18 @@ static void epl88051_restart_work(void)
struct epl88051_priv *epld = epl88051_obj;
cancel_delayed_work(&polling_work);
queue_delayed_work(epld->epl_wq, &polling_work,msecs_to_jiffies(50));
-#if 1
+#if 1 //ices add by 20140812
if(epld->mfg_mode != MFG_MODE)
{
cancel_delayed_work(&dyna_thd_polling_work);
queue_delayed_work(epld->epl_wq, &dyna_thd_polling_work,msecs_to_jiffies(POLLING_DELAY));
}
-#endif
+#endif //ices end by 20140812
}
+/*-------healthy sensor Enable------------------------------------------------------*/
static void epl88051_hs_enable(struct epl88051_priv *epld, bool interrupt, bool full_enable)
{
int ret;
@@ -356,21 +363,78 @@ static int epl88051_psensor_enable(struct epl88051_priv *epld)
LOG_INFO("[PS] %s --- Proximity sensor Enable ---\n", __FUNCTION__);
+ /*
+ Interrupt Channel Selection(3-2): ch0(00), ch1(01), ch2(10), ch3(11)
+ Interrupt Mode Selection(1-0): binary(00), disable(10), active-low(11)
+ */
ret = epl88051_I2C_Write(client, REG_6, W_SINGLE_BYTE, 0x02, EPL_INT_DISABLE | EPL_INT_CH1);
+ /*
+ Operation Mode Selection(7-4):
+ 0001: PS mode (continuous sensing for PS)
+ 1001: PSS mode (single sensing for PS)
+ 0110: ALS mode (continuous sensing for ALS)
+ 1110: ALSS mode (single sensing for ALS)
+ ADC Resolution Setting(3-2):
+ 00: 6 bits ADC resolution setting
+ 01: 8 bits ADC resolution setting
+ 10: 10 bits ADC resolution setting
+ 11: 12 bits ADC resolution setting
+ Gain Setting(1-0):
+ 00:High gain
+ 01: Middle gain
+ 10: Not used
+ 11: Low gain
+ */
regdata = EPL_PS_MODE | EPL_10BIT_ADC | EPL_M_GAIN ;
regdata = regdata | (epld->polling_mode_ps == 0 ? EPL_C_SENSING_MODE : EPL_S_SENSING_MODE);
ret = epl88051_I2C_Write(client, REG_0, W_SINGLE_BYTE, 0X02, regdata);
+ /*
+ Average Cycle(7-5):
+ 000 : 1 time sensing average at each ALS/PS measurement
+ 001 : 2 times sensing average at each ALS /PS measurement
+ 010 : 4 times sensing average at each ALS /PS measurement
+ 011 : 8 times sensing average at each ALS /PS measurement
+ 100 : 16 times sensing average at each ALS /PS measurement
+ 101 : 32 times sensing average at each ALS /PS measurement
+ 110 : 64 times sensing average at each ALS /PS measurement
+ 111 : 128 times sensing average at each ALS /PS measurement
+ Integration Time(4-0):(us)
+ 00000: 4
+ 00001: 6
+ 00010: 8
+ 00011: 10
+ 00100: 15
+ 00101: 20
+ 00110: 25
+ 00111: 30
+ 01000: 40
+ 01001: 55
+ 01010: 70
+ 01011: 90
+ 01100: 110
+ 01101: 150
+ 01110: 200
+ 01111: 250
+ 10000: 350
+ 10001: 450
+ 10010: 550
+ */
regdata = PS_INTT | EPL_SENSING_8_TIME;
ret = epl88051_I2C_Write(client, REG_1, W_SINGLE_BYTE, 0X02, regdata);
-
+ /*IR LED voltage mode*/
ret = epl88051_I2C_Write(client, REG_9, W_SINGLE_BYTE, 0X02, EPL_IR_MODE_VOLTAGE);
-
+ /*Set P-sensor high/low threshold*/
epl88051_set_ps_threshold(epld->ps_threshold_low, epld->ps_threshold_high);
+ /*
+ Chip Reset Control(2)
+ 0 : the chip reset (exclusive of I2C registers)
+ 1 : the chip start to run
+ */
ret = epl88051_I2C_Write(client, REG_8, W_SINGLE_BYTE, 0X02, EPL_C_RESET);
ret = epl88051_I2C_Write(client, REG_8, W_SINGLE_BYTE, 0x02, EPL_C_START_RUN);
@@ -379,9 +443,9 @@ static int epl88051_psensor_enable(struct epl88051_priv *epld)
epl88051_I2C_Write(client, REG_13, R_SINGLE_BYTE, 0x01, 0);
epl88051_I2C_Read(client);
ps_state= !((gRawData.raw_bytes[0] & 0x04) >> 2);
- gRawData.con_sat = (gRawData.raw_bytes[0] >> 1) & 0x01;
-#if 1
-
+ gRawData.con_sat = (gRawData.raw_bytes[0] >> 1) & 0x01; //ices add by 20140812
+#if 1 //ices add by 20140814
+ /*read channel 0 raw data*/
epl88051_I2C_Write(client, REG_14, R_TWO_BYTE, 0x01, 0x00);
epl88051_I2C_Read(client);
gRawData.ps_ch0_raw = (gRawData.raw_bytes[1] << 8) | gRawData.raw_bytes[0];
@@ -389,20 +453,20 @@ static int epl88051_psensor_enable(struct epl88051_priv *epld)
epl88051_I2C_Write(client, REG_16, R_TWO_BYTE, 0x01, 0x00);
epl88051_I2C_Read(client);
-#ifdef PS_RAW_8BIT
+#ifdef PS_RAW_8BIT //ices add by 20131230 /*PS_RAW_8BIT*/
if (gRawData.raw_bytes[1] >= (uint8_t) (epld->emmc_ps_kadc2 & 0xFF))
- gRawData.ps_raw = gRawData.raw_bytes[1] - (uint8_t) (epld->emmc_ps_kadc2 & 0xFF);
+ gRawData.ps_raw = gRawData.raw_bytes[1] - (uint8_t) (epld->emmc_ps_kadc2 & 0xFF); //8bit
else
gRawData.ps_raw = 0;
#else
if (((gRawData.raw_bytes[1] << 8) | gRawData.raw_bytes[0]) >= (uint8_t) epld->emmc_ps_kadc2)
- gRawData.ps_raw = ((gRawData.raw_bytes[1] << 8) | gRawData.raw_bytes[0]) - (uint8_t) epld->emmc_ps_kadc2;
+ gRawData.ps_raw = ((gRawData.raw_bytes[1] << 8) | gRawData.raw_bytes[0]) - (uint8_t) epld->emmc_ps_kadc2; //16bit
else
gRawData.ps_raw = 0;
-#endif
+#endif //ices end by 20131230 /*PS_RAW_8BIT*/
LOG_INFO("[PS] %s gRawData.ps_raw=%d\n", __FUNCTION__, gRawData.ps_raw);
if (gRawData.ps_state != ps_state) {
- regdata = EPL_INT_CH1 | EPL_INT_FRAME_ENABLE;
+ regdata = EPL_INT_CH1 | EPL_INT_FRAME_ENABLE; ///??????
epl88051_I2C_Write(client, REG_6, W_SINGLE_BYTE, 0x02, regdata);
} else {
regdata = EPL_INT_CH1 | EPL_INT_ACTIVE_LOW;
@@ -428,18 +492,79 @@ static int epl88051_lsensor_enable(struct epl88051_priv *epld)
struct i2c_client *client = epld->client;
LOG_INFO("[LS] %s --- ALS sensor Enable --- \n", __FUNCTION__);
+ /*
+ Interrupt Channel Selection(3-2): ch0(00), ch1(01), ch2(10), ch3(11)
+ Interrupt Mode Selection(1-0): binary(00), disable(10), active-low(11)
+ */
regdata = EPL_INT_DISABLE;
ret = epl88051_I2C_Write(client, REG_6, W_SINGLE_BYTE, 0x02, regdata);
+ /*
+ Operation Mode Selection(7-4):
+ 0001: PS mode (continuous sensing for PS)
+ 1001: PSS mode (single sensing for PS)
+ 0110: ALS mode (continuous sensing for ALS)
+ 1110: ALSS mode (single sensing for ALS)
+ ADC Resolution Setting(3-2):
+ 00: 6 bits ADC resolution setting
+ 01: 8 bits ADC resolution setting
+ 10: 10 bits ADC resolution setting
+ 11: 12 bits ADC resolution setting
+ Gain Setting(1-0):
+ 00:High gain
+ 01: Middle gain
+ 10: Not used
+ 11: Low gain
+ */
regdata = EPL_S_SENSING_MODE | EPL_ALS_MODE | dynamic_intt_gain | EPL_8BIT_ADC;
ret = epl88051_I2C_Write(client, REG_0, W_SINGLE_BYTE, 0X02, regdata);
+ /*
+ Average Cycle(7-5):
+ 000 : 1 time sensing average at each ALS/PS measurement
+ 001 : 2 times sensing average at each ALS /PS measurement
+ 010 : 4 times sensing average at each ALS /PS measurement
+ 011 : 8 times sensing average at each ALS /PS measurement
+ 100 : 16 times sensing average at each ALS /PS measurement
+ 101 : 32 times sensing average at each ALS /PS measurement
+ 110 : 64 times sensing average at each ALS /PS measurement
+ 111 : 128 times sensing average at each ALS /PS measurement
+ Integration Time(4-0):
+ 00000: 4
+ 00001: 6
+ 00010: 8
+ 00011: 10
+ 00100: 15
+ 00101: 20
+ 00110: 25
+ 00111: 30
+ 01000: 40
+ 01001: 55
+ 01010: 70
+ 01011: 90
+ 01100: 110
+ 01101: 150
+ 01110: 200
+ 01111: 250
+ 10000: 350
+ 10001: 450
+ 10010: 550
+ */
regdata = dynamic_intt_intt | EPL_SENSING_16_TIME;
ret = epl88051_I2C_Write(client, REG_1, W_SINGLE_BYTE, 0X02, regdata);
+ /*
+ Go Low Gain Threshold in Auto-Gain Operation for ALS(7-4)
+ Go Mid Gain Threshold in Auto-Gain Operation for ALS(3-0)
+ */
ret = epl88051_I2C_Write(client, REG_10, W_SINGLE_BYTE, 0x02, (EPL_GO_LOW << 4) | EPL_GO_MID);
+ /*
+ Chip Reset Control(2)
+ 0 : the chip reset (exclusive of I2C registers)
+ 1 : the chip start to run
+ */
ret = epl88051_I2C_Write(client,REG_8, W_SINGLE_BYTE, 0X02, EPL_C_RESET);
ret = epl88051_I2C_Write(client,REG_8, W_SINGLE_BYTE, 0x02, EPL_C_START_RUN);
msleep(ALS_DELAY);
@@ -447,6 +572,12 @@ static int epl88051_lsensor_enable(struct epl88051_priv *epld)
return ret;
}
+//====================epl88051_read_ps===============//
+//polling method for proximity sensor detect. Report proximity sensor raw data.
+//Report "ABS_DISTANCE" event to HAL layer.
+//Variable "value" 0 and 1 to represent which distance from psensor to target(human's face..etc).
+//value: 0 represent near.
+//value: 1 represent far.
static void epl88051_read_ps(void)
{
struct epl88051_priv *epld = epl88051_obj;
@@ -454,7 +585,7 @@ static void epl88051_read_ps(void)
int is_ps_mode = 1;
uint8_t setting;
epld->j_end = jiffies;
-
+ /*read ps state*/
epl88051_I2C_Write(epld->client, REG_13, R_SINGLE_BYTE, 0x01, 0);
epl88051_I2C_Read(epld->client);
setting = gRawData.raw_bytes[0];
@@ -464,25 +595,25 @@ static void epl88051_read_ps(void)
}
if(is_ps_mode) {
gRawData.ps_state= !((gRawData.raw_bytes[0] & 0x04) >> 2);
-
-
+ //FAR: gRawData.ps_state=1
+ //NEAR: gRawData.ps_state=0
-
+ /*read channel 1 raw data*/
epl88051_I2C_Write(client, REG_16, R_TWO_BYTE, 0x01, 0x00);
epl88051_I2C_Read(client);
-#ifdef PS_RAW_8BIT
+#ifdef PS_RAW_8BIT //ices add by 20131230 /*PS_RAW_8BIT*/
if (gRawData.raw_bytes[1] >= (uint8_t) (epld->emmc_ps_kadc2 & 0xFF))
- gRawData.ps_raw = gRawData.raw_bytes[1] - (uint8_t) (epld->emmc_ps_kadc2 & 0xFF);
+ gRawData.ps_raw = gRawData.raw_bytes[1] - (uint8_t) (epld->emmc_ps_kadc2 & 0xFF); //8bit
else
gRawData.ps_raw = 0;
epl_ps_raw_data = gRawData.raw_bytes[1];
#else
if (((gRawData.raw_bytes[1] << 8) | gRawData.raw_bytes[0]) >= (uint8_t) epld->emmc_ps_kadc2)
- gRawData.ps_raw = ((gRawData.raw_bytes[1] << 8) | gRawData.raw_bytes[0]) - (uint8_t) epld->emmc_ps_kadc2;
+ gRawData.ps_raw = ((gRawData.raw_bytes[1] << 8) | gRawData.raw_bytes[0]) - (uint8_t) epld->emmc_ps_kadc2; //16bit
else
gRawData.ps_raw = 0;
epl_ps_raw_data = (gRawData.raw_bytes[1] << 8) | gRawData.raw_bytes[0];
-#endif
+#endif //ices end by 20131230 /*PS_RAW_8BIT*/
}
LOG_INFO("[PS] %s proximity %s ps_raw_data: %d\n", __FUNCTION__, gRawData.ps_state ? "FAR" : "NEAR", gRawData.ps_raw);
@@ -504,15 +635,15 @@ static void epl88051_dyna_thd_read_ps(void)
struct epl88051_priv *epld = epl88051_obj;
struct i2c_client *client = epld->client;
uint8_t setting;
-#if 1
+#if 1 //ices add by 20140812
bool enable_ps = epld->enable_pflag == 1 && epld->ps_suspend == 0;
bool enable_als = epld->enable_lflag == 1 && epld->als_suspend == 0;
LOG_INFO("[%s]: enable_ps=%d, enable_als=%d \r\n", __func__, enable_ps, enable_als);
-#endif
- if(enable_ps == 1 && enable_als == 0)
- {
-
+#endif //ices end by 20140812
+ if(enable_ps == 1 && enable_als == 0) //ices add by 20140812
+ { //ices add by 20140812
+ /*read ps state*/
epl88051_I2C_Write(epld->client, REG_13, R_SINGLE_BYTE, 0x01, 0);
epl88051_I2C_Read(epld->client);
setting = gRawData.raw_bytes[0];
@@ -520,42 +651,42 @@ static void epl88051_dyna_thd_read_ps(void)
LOG_ERR("read ps data in wrong mode\n");
}
gRawData.ps_state= !((gRawData.raw_bytes[0] & 0x04) >> 2);
-#if 1
+#if 1 //ices add by 20140812
gRawData.con_sat = (gRawData.raw_bytes[0] >> 1) & 0x01;
-#endif
+#endif //ices end by 20140812
- }
+ }//ices add by 20140812
-
-
- if(enable_ps == 1 && enable_als == 0)
- {
+ //FAR: gRawData.ps_state=1
+ //NEAR: gRawData.ps_state=0
+ if(enable_ps == 1 && enable_als == 0)//ices add by 20140812
+ { //ices add by 20140812
-#if 1
-
+#if 1 //ices add by 20140814
+ /*read channel 0 raw data*/
epl88051_I2C_Write(client, REG_14, R_TWO_BYTE, 0x01, 0x00);
epl88051_I2C_Read(client);
gRawData.ps_ch0_raw = (gRawData.raw_bytes[1] << 8) | gRawData.raw_bytes[0];
-#endif
+#endif //ices end by 20140814
-
+ /*read channel 1 raw data*/
epl88051_I2C_Write(client, REG_16, R_TWO_BYTE, 0x01, 0x00);
epl88051_I2C_Read(client);
-#ifdef PS_RAW_8BIT
+#ifdef PS_RAW_8BIT //ices add by 20131230 /*PS_RAW_8BIT*/
if (gRawData.raw_bytes[1] >= (uint8_t) (epld->emmc_ps_kadc2 & 0xFF))
- gRawData.ps_raw = gRawData.raw_bytes[1] - (uint8_t) (epld->emmc_ps_kadc2 & 0xFF);
+ gRawData.ps_raw = gRawData.raw_bytes[1] - (uint8_t) (epld->emmc_ps_kadc2 & 0xFF); //8bit
else
gRawData.ps_raw = 0;
epl_ps_raw_data = gRawData.raw_bytes[1];
#else
if (((gRawData.raw_bytes[1] << 8) | gRawData.raw_bytes[0]) >= (uint8_t) epld->emmc_ps_kadc2)
- gRawData.ps_raw = ((gRawData.raw_bytes[1] << 8) | gRawData.raw_bytes[0]) - (uint8_t) epld->emmc_ps_kadc2;
+ gRawData.ps_raw = ((gRawData.raw_bytes[1] << 8) | gRawData.raw_bytes[0]) - (uint8_t) epld->emmc_ps_kadc2; //16bit
else
gRawData.ps_raw = 0;
epl_ps_raw_data = (gRawData.raw_bytes[1] << 8) | gRawData.raw_bytes[0];
-#endif
- }
-#if 1
+#endif //ices end by 20131230 /*PS_RAW_8BIT*/
+ } //ices add by 20140812
+#if 1 //ices add by 20140812
else
{
#ifdef PS_RAW_8BIT
@@ -564,7 +695,7 @@ static void epl88051_dyna_thd_read_ps(void)
epl_ps_raw_data = gRawData.ps_raw + (uint8_t) epld->emmc_ps_kadc2;
#endif
}
-#endif
+#endif //ices end by 20140812
LOG_INFO("[PS] %s proximity %s ps_raw_data: %d\n", __FUNCTION__, gRawData.ps_state ? "FAR" : "NEAR", gRawData.ps_raw);
@@ -580,8 +711,8 @@ uint32_t raw_convert_to_lux(u16 raw_data)
{
uint32_t lux = 0;
-
-
+ // 42 = 15 * 2.8
+ // 2.8 is for leverage capella's adc range(a3)
if ((gRawData.als_ch1_raw * 42 / als_dynamic_intt_intt_value[dynamic_intt_idx]) > 65535)
gRawData.als_raw = 65535;
else
@@ -611,11 +742,11 @@ static void epl88051_read_als(void)
if (((now_gain >> 3) & 7) != 0x00) {
LOG_ERR("read als data in wrong mode %d\n", (now_gain >> 3) & 7);
}
-
+ /*ambient channel*/
epl88051_I2C_Write(client, REG_16, R_TWO_BYTE, 0x01, 0x00);
epl88051_I2C_Read(client);
ch1 = (gRawData.raw_bytes[1] << 8) | gRawData.raw_bytes[0];
-
+ /*ambient IR channel*/
epl88051_I2C_Write(client, REG_14, R_TWO_BYTE, 0x01, 0x00);
epl88051_I2C_Read(client);
ch0 = (gRawData.raw_bytes[1] << 8) | gRawData.raw_bytes[0];
@@ -624,7 +755,7 @@ static void epl88051_read_als(void)
LOG_ERR("read ch0 data is 0 \r\n");
}
- luxratio = (long)((ch1*dynamic_intt_min_unit) / (ch0));
+ luxratio = (long)((ch1*dynamic_intt_min_unit) / (ch0)); //lux ratio (A=CH1/CH0)
gRawData.ratio = luxratio;
@@ -634,7 +765,7 @@ static void epl88051_read_als(void)
} else if (gRawData.ratio < epld->lsource_thd_low || gRawData.ratio == epld->lsource_thd_low) {
c_gain = epld->c_gain_l;
ratio_flag = 1;
- } else {
+ } else { /*mix*/
int a = 0, b = 0;
a = (epld->c_gain_h - epld->c_gain_l) * dynamic_intt_min_unit / (epld->lsource_thd_high - epld->lsource_thd_low);
b = (epld->c_gain_h) - ((a * epld->lsource_thd_high) / dynamic_intt_min_unit );
@@ -667,28 +798,28 @@ static void epl88051_read_als(void)
lux_temp = raw_convert_to_lux(gRawData.als_ch0_raw);
}
-
+ //LOG_INFO("[LS] %s>>>>>>>>>>>>>>>>>>>>>>>> INTT_MAX_LUX\r\n", __FUNCTION__);
} else {
gRawData.als_ch1_raw = dynamic_intt_high_thr;
lux_temp = raw_convert_to_lux(gRawData.als_ch1_raw);
dynamic_intt_idx++;
-
+ //LOG_INFO("[LS] %s>>>>>>>>>>>>>>>>>>>>>>>> change INTT high: %d, raw: %d \r\n", __FUNCTION__, dynamic_intt_idx, gRawData.als_ch1_raw);
}
} else if (gRawData.als_ch1_raw < dynamic_intt_low_thr) {
if (dynamic_intt_idx == 0) {
lux_temp = raw_convert_to_lux(gRawData.als_ch1_raw);
-
+ //LOG_INFO("[LS] %s>>>>>>>>>>>>>>>>>>>>>>>> INTT_MIN_LUX\r\n", __FUNCTION__);
} else {
gRawData.als_ch1_raw = dynamic_intt_low_thr;
lux_temp = raw_convert_to_lux(gRawData.als_ch1_raw);
dynamic_intt_idx--;
-
+ //LOG_INFO("[LS] %s>>>>>>>>>>>>>>>>>>>>>>>> change INTT low: %d, raw: %d \r\n", __FUNCTION__, dynamic_intt_idx, gRawData.als_ch1_raw);
}
} else {
lux_temp = raw_convert_to_lux(gRawData.als_ch1_raw);
}
if (!epld->ls_calibrate) {
- als_step_temp = gRawData.als_raw;
+ als_step_temp = gRawData.als_raw;//ch1;
gRawData.als_raw = als_step_temp * epld->als_gadc / epld->als_kadc;
if((gRawData.als_raw * epld->als_kadc) < (als_step_temp * epld->als_gadc)) {
gRawData.als_raw++;
@@ -704,7 +835,7 @@ static void epl88051_read_als(void)
if (*(epld->adc_table + i))
break;
}
- if (i == 9) {
+ if (i == 9) {/*avoid i = 10, because 'cali_table' of size is 10 */
gRawData.als_level = i;
break;
}
@@ -722,7 +853,7 @@ static void epl88051_read_hs(void)
struct epl88051_priv *epld = epl88051_obj;
struct i2c_client *client = epld->client;
u16 data;
-
+ // int max_frame = HS_BUFFER_SIZE;
int idx = start_idx+hs_count;
mutex_lock(&sensor_mutex);
epl88051_I2C_Write(client, REG_16, R_EIGHT_BYTE, 0x01, 0x00);
@@ -749,6 +880,13 @@ static void epl88051_read_hs(void)
mutex_unlock(&sensor_mutex);
}
+/*
+//====================epl88051_set_ps_threshold===============//
+//low_thd: The value is psensor interrupt low threshold.
+//high_thd: The value is psensor interrupt hihg threshold.
+//When psensor rawdata > hihg_threshold, interrupt pin will be pulled low.
+//After interrupt occur, psensor rawdata < low_threshold, interrupt pin will be pulled high.
+ */
static int epl88051_set_ps_threshold(uint16_t low_thd, uint16_t high_thd)
{
@@ -763,7 +901,7 @@ static int epl88051_set_ps_threshold(uint16_t low_thd, uint16_t high_thd)
high_thd_l = high_thd & 0xFF;
low_thd_h = (low_thd >> 8) & 0xFF;
low_thd_l = low_thd & 0xFF;
-#ifdef PS_RAW_8BIT
+#ifdef PS_RAW_8BIT //ices add by 20131230 /*PS_RAW_8BIT*/
LOG_INFO("[PS] %s high_thd_l:%d, low_thd_l:%d\n", __FUNCTION__, high_thd_l, low_thd_l);
epl88051_I2C_Write(client,REG_2, W_SINGLE_BYTE, 0x02, 0);
epl88051_I2C_Write(client,REG_3, W_SINGLE_BYTE, 0x02, high_thd_l);
@@ -774,24 +912,24 @@ static int epl88051_set_ps_threshold(uint16_t low_thd, uint16_t high_thd)
epl88051_I2C_Write(client,REG_3, W_SINGLE_BYTE, 0x02, high_thd_h);
epl88051_I2C_Write(client,REG_4, W_SINGLE_BYTE, 0x02, low_thd_l);
epl88051_I2C_Write(client,REG_5, W_SINGLE_BYTE, 0x02, low_thd_h);
-#endif
+#endif //ices end by 20131230 /*PS_RAW_8BIT*/
return ret;
}
static void epl88051_dyna_thd_polling_work(struct work_struct *work)
{
struct epl88051_priv *epld = epl88051_obj;
-#if 1
+#if 1 //ices add by 20140812
bool enable_ps = epld->enable_pflag == 1 && epld->ps_suspend == 0;
bool enable_als = epld->enable_lflag == 1 && epld->als_suspend == 0;
LOG_INFO("[%s]: enable_ps=%d, enable_als=%d \r\n", __FUNCTION__, enable_ps, enable_als);
if (psensor_enabled == 1 && enable_ps == 1) {
#else
if (psensor_enabled == 1) {
-#endif
+#endif //ices end by 20140812
epl88051_dyna_thd_read_ps();
LOG_INFO("[PS] epl_ps_raw_data:%d, min_epl_ps_raw_data:%d\n", epl_ps_raw_data, min_epl_ps_raw_data);
if (epl_ps_raw_data != 0) {
- if ((min_epl_ps_raw_data > epl_ps_raw_data) && gRawData.con_sat == 0 && gRawData.ps_ch0_raw < epld->ps_max_ch0) {
+ if ((min_epl_ps_raw_data > epl_ps_raw_data) && gRawData.con_sat == 0 && gRawData.ps_ch0_raw < epld->ps_max_ch0) { //ices add by 20140812
min_epl_ps_raw_data = epl_ps_raw_data;
epld->ps_threshold_low = min_epl_ps_raw_data + TH_ADD;
epld->ps_threshold_high = epld->ps_threshold_low + epld->ps_threshold_diff;
@@ -801,10 +939,10 @@ static void epl88051_dyna_thd_polling_work(struct work_struct *work)
epld->ps_threshold_high = 255;
LOG_INFO("[PS] set low thd:%d .........................\n", epld->ps_threshold_low);
- if(enable_ps == 1 && enable_als == 0)
- {
+ if(enable_ps == 1 && enable_als == 0) //ices add by 20140812
+ { //ices add by 20140812
epl88051_set_ps_threshold(epld->ps_threshold_low, epld->ps_threshold_high);
- }
+ } //ices add by 20140812
}
}
queue_delayed_work(epld->epl_wq, &dyna_thd_polling_work,
@@ -820,7 +958,7 @@ static void epl88051_polling_work(struct work_struct *work)
bool enable_als = epld->enable_lflag == 1 && epld->als_suspend == 0;
bool enable_hs = epld->enable_hflag == 1 && epld->hs_suspend == 0;
-
+ //LOG_INFO("%s enable_pflag = %d, enable_lflag = %d \n", __FUNCTION__, enable_ps, enable_als);
cancel_delayed_work(&polling_work);
if (enable_als == true) {
@@ -837,11 +975,11 @@ static void epl88051_polling_work(struct work_struct *work)
}
} else {
if (enable_als) {
-
+ /*enable ALS*/
epl88051_lsensor_enable(epld);
-
+ /*read als*/
epl88051_read_als();
-
+ /*report als event*/
#ifdef outputLUX
input_report_abs(epld->als_input_dev, ABS_MISC, gRawData.als_lux);
#else
@@ -851,9 +989,9 @@ static void epl88051_polling_work(struct work_struct *work)
}
if (enable_ps) {
-
+ /*enable psensor*/
epl88051_psensor_enable(epld);
-
+ /*reading psensor if ps is polling mode*/
if (epld->polling_mode_ps == 1) {
epl88051_read_ps();
}
@@ -869,7 +1007,9 @@ static void epl88051_polling_work(struct work_struct *work)
}
}
+/*----------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------*/
static irqreturn_t epl88051_eint_func(int irqNo, void *handle)
{
struct epl88051_priv *epld = (struct epl88051_priv*) handle;
@@ -889,22 +1029,22 @@ static void epl88051_eint_work(struct work_struct *work)
epl88051_read_hs();
epl88051_hs_enable(epld, true, true);
} else if (epld->enable_pflag) {
-
+ /*check comparator*/
epl88051_I2C_Write(client, REG_13, R_SINGLE_BYTE, 0x01, 0);
epl88051_I2C_Read(client);
mode = (gRawData.raw_bytes[0] >> 3) & 7;
if (mode == 0x01 && epld->enable_pflag) {
-
+ /*read ps*/
epl88051_read_ps();
} else {
LOG_ERR("error: interrupt in ps\n");
}
-
+ /*enable interrupt mode, active-low*/
epl88051_I2C_Write(client, REG_6, W_SINGLE_BYTE, 0x02, EPL_INT_CH1 | EPL_INT_ACTIVE_LOW);
-
+ /*data unlock*/
epl88051_I2C_Write(client, REG_8, W_SINGLE_BYTE, 0x02, EPL_DATA_UNLOCK);
}
@@ -946,11 +1086,11 @@ static ssize_t ls_adc_show(struct device *dev,
{
int ret;
struct epl88051_priv *epld = epl88051_obj;
-
+ /*Todo: set levels */
if (epld->enable_lflag == 0 && epld->enable_pflag == 0) {
epl88051_lsensor_enable(epld);
-
+ /*read als*/
epl88051_read_als();
} else {
epld->enable_lflag = 1;
@@ -1006,6 +1146,7 @@ static ssize_t ls_enable_store(struct device *dev,
static DEVICE_ATTR(ls_auto, 0664, ls_enable_show, ls_enable_store);
+/*----------------------------------------------------------------------------*/
static ssize_t epl88051_show_reg(struct device *dev, struct device_attribute *attr, char *buf)
{
ssize_t len = 0;
@@ -1031,6 +1172,7 @@ static ssize_t epl88051_show_reg(struct device *dev, struct device_attribute *at
return len;
}
static DEVICE_ATTR(elan_reg, 0644, epl88051_show_reg, NULL);
+/*show sensor status ---------------------------------------------------------*/
static ssize_t epl88051_show_status(struct device *dev, struct device_attribute *attr, char *buf)
{
size_t len = 0;
@@ -1056,6 +1198,7 @@ static ssize_t epl88051_show_status(struct device *dev, struct device_attribute
}
static DEVICE_ATTR(elan_status, 0664, epl88051_show_status, NULL);
+/*Setting integration time for ALS mode---------------------------------------*/
static ssize_t epl88051_store_als_int_time(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
int input = 0;
@@ -1068,6 +1211,7 @@ static ssize_t epl88051_store_als_int_time(struct device *dev, struct device_att
}
static DEVICE_ATTR(als_int_time, 0664, NULL, epl88051_store_als_int_time);
+/*show ps calibration raw data------------------------------------------------*/
static ssize_t epl88051_show_ps_cal_raw(struct device *dev, struct device_attribute *attr, char *buf)
{
struct epl88051_priv *obj = epl88051_obj;
@@ -1088,7 +1232,7 @@ static ssize_t epl88051_show_ps_cal_raw(struct device *dev, struct device_attrib
epl88051_I2C_Write(obj->client, REG_8, W_SINGLE_BYTE, 0x02, EPL_DATA_LOCK);
epl88051_I2C_Write(obj->client, REG_16, R_TWO_BYTE, 0x01, 0x00);
epl88051_I2C_Read(obj->client);
-#ifdef PS_RAW_8BIT
+#ifdef PS_RAW_8BIT //ices add by 20131230 /*PS_RAW_8BIT*/
ch1_all = ch1_all + gRawData.raw_bytes[1];
#else
ch1_all = ch1_all + ((gRawData.raw_bytes[1] << 8) | gRawData.raw_bytes[0]);
@@ -1105,6 +1249,7 @@ static ssize_t epl88051_show_ps_cal_raw(struct device *dev, struct device_attrib
}
static DEVICE_ATTR(ps_cal_raw, 0664, epl88051_show_ps_cal_raw, NULL);
+/*Setting ps integration time ---------------------------------------------------------*/
static ssize_t epl88051_store_ps_int_time(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
LOG_FUN();
@@ -1115,6 +1260,7 @@ static ssize_t epl88051_store_ps_int_time(struct device *dev, struct device_attr
}
static DEVICE_ATTR(ps_int_time, 0664, NULL, epl88051_store_ps_int_time);
+/*Setting ps H/L threshold ------------------------------------------------------------*/
static ssize_t epl88051_store_ps_threshold(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct epl88051_priv *epld = epl88051_obj;
@@ -1126,6 +1272,7 @@ static ssize_t epl88051_store_ps_threshold(struct device *dev, struct device_att
}
static DEVICE_ATTR(ps_threshold, 0664, NULL, epl88051_store_ps_threshold);
+/*Setting ps polling mode(0: interrupt, 1: polling) ----------------------------------*/
static ssize_t epl88051_store_ps_polling_mode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct epl88051_priv *epld = epl88051_obj;
@@ -1140,7 +1287,7 @@ static ssize_t epl88051_store_ps_polling_mode(struct device *dev, struct device_
}
static DEVICE_ATTR(ps_polling_mode, 0664, NULL, epl88051_store_ps_polling_mode);
-#if 1
+#if 1 //ices add by 20140812
static ssize_t epl88051_store_ps_max_ch0(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct epl88051_priv *epld = epl88051_obj;
@@ -1153,7 +1300,7 @@ static ssize_t epl88051_store_ps_max_ch0(struct device *dev, struct device_attri
return count;
}
static DEVICE_ATTR(dyn_max_ps_ch0, 0664, NULL, epl88051_store_ps_max_ch0);
-#endif
+#endif //ices end by 20140812
static ssize_t epl88051_store_hs_enable(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
@@ -1184,7 +1331,7 @@ static ssize_t epl88051_show_hs_raws(struct device *dev, struct device_attribute
u16 *tmp = (u16*)buf;
u16 length = hs_count * 1;
int byte_count = 2 + length * 2;
- int i = 0;
+ int i = 0;//, idx=0;
int start = 0;
mutex_lock(&sensor_mutex);
tmp[0] = length;
@@ -1220,20 +1367,20 @@ static ssize_t ps_adc_show(struct device *dev,
epl88051_psensor_enable(epl88051);
epl88051_dyna_thd_read_ps();
} else if (epl88051->enable_pflag == 1 && epl88051->enable_lflag == 0){
-
+ /*read channel 1 raw data*/
epl88051_I2C_Write(epl88051->client, REG_16, R_TWO_BYTE, 0x01, 0x00);
epl88051_I2C_Read(epl88051->client);
-#ifdef PS_RAW_8BIT
+#ifdef PS_RAW_8BIT //ices add by 20131230 /*PS_RAW_8BIT*/
if (gRawData.raw_bytes[1] >= (uint8_t) (epl88051->emmc_ps_kadc2 & 0xFF))
- gRawData.ps_raw = gRawData.raw_bytes[1] - (uint8_t) (epl88051->emmc_ps_kadc2 & 0xFF);
+ gRawData.ps_raw = gRawData.raw_bytes[1] - (uint8_t) (epl88051->emmc_ps_kadc2 & 0xFF); //8bit
else
gRawData.ps_raw = 0;
#else
if (((gRawData.raw_bytes[1]<<8) | gRawData.raw_bytes[0]) >= (uint8_t) epl88051->emmc_ps_kadc2)
- gRawData.ps_raw = ((gRawData.raw_bytes[1]<<8) | gRawData.raw_bytes[0]) - (uint8_t) epl88051->emmc_ps_kadc2;
+ gRawData.ps_raw = ((gRawData.raw_bytes[1]<<8) | gRawData.raw_bytes[0]) - (uint8_t) epl88051->emmc_ps_kadc2; //16bit
else
gRawData.ps_raw = 0;
-#endif
+#endif //ices end by 20131230 /*PS_RAW_8BIT*/
} else {
epl88051->enable_pflag = 1;
@@ -1408,7 +1555,7 @@ static long epl88051_als_ioctl(struct file *file, unsigned int cmd, unsigned lon
LOG_INFO("[LS] %s als io ctrl cmd %d\n", __FUNCTION__, _IOC_NR(cmd));
switch(cmd) {
-
+ /*Get enable lightsensor flag*/
case ELAN_EPL6800_IOCTL_GET_LFLAG:
case LIGHTSENSOR_IOCTL_GET_ENABLED:
@@ -1419,7 +1566,7 @@ static long epl88051_als_ioctl(struct file *file, unsigned int cmd, unsigned lon
LOG_INFO("[LS] %s elan ambient-light Sensor get lflag %d\n", __FUNCTION__, flag);
break;
-
+ /*Setting lightsensor enable and restart*/
case ELAN_EPL6800_IOCTL_ENABLE_LFLAG:
case LIGHTSENSOR_IOCTL_ENABLE:
LOG_INFO("[LS] %s elan ambient-light IOCTL Sensor set lflag \n", __FUNCTION__);
@@ -1439,7 +1586,7 @@ static long epl88051_als_ioctl(struct file *file, unsigned int cmd, unsigned lon
LOG_INFO("[LS] %s elan ambient-light Sensor set lflag %d\n", __FUNCTION__, flag);
break;
-
+ /*Get lightsensor raw data*/
case ELAN_EPL6800_IOCTL_GETDATA:
buf[0] = (unsigned long)gRawData.als_ch1_raw;
if (copy_to_user(argp, &buf , sizeof(buf)))
@@ -1467,7 +1614,7 @@ static struct file_operations epl88051_als_fops =
static struct miscdevice epl88051_als_device =
{
.minor = MISC_DYNAMIC_MINOR,
- .name = "lightsensor",
+ .name = "lightsensor", //"elan_als",
.fops = &epl88051_als_fops
};
@@ -1503,10 +1650,10 @@ static long epl88051_ps_ioctl(struct file *file, unsigned int cmd, unsigned long
LOG_INFO("[PS] %s ps io ctrl cmd %d\n", __FUNCTION__, _IOC_NR(cmd));
-
+ //ioctl message handle must define by android sensor library (case by case)
switch(cmd) {
-
-
+ /*Get enable psensor flag*/
+ //case ELAN_EPL6800_IOCTL_GET_PFLAG:
case CAPELLA_CM3602_IOCTL_GET_ENABLED:
LOG_INFO("[PS] %s elan Proximity Sensor IOCTL get pflag \n", __FUNCTION__);
flag = epld->enable_pflag;
@@ -1515,8 +1662,8 @@ static long epl88051_ps_ioctl(struct file *file, unsigned int cmd, unsigned long
LOG_INFO("[PS] %s elan Proximity Sensor get pflag %d\n", __FUNCTION__, flag);
break;
-
-
+ /*Setting psensor enable and restart*/
+ //case ELAN_EPL6800_IOCTL_ENABLE_PFLAG:
case CAPELLA_CM3602_IOCTL_ENABLE:
LOG_INFO("[PS] %s elan Proximity IOCTL Sensor set pflag \n", __FUNCTION__);
if (copy_from_user(&flag, argp, sizeof(flag)))
@@ -1542,8 +1689,8 @@ static long epl88051_ps_ioctl(struct file *file, unsigned int cmd, unsigned long
LOG_INFO("[PS] default report FAR ");
input_report_abs(epld->ps_input_dev, ABS_DISTANCE, 1);
input_sync(epld->ps_input_dev);
-
-
+ //queue_delayed_work(epld->epl_wq, &dyna_thd_polling_work,
+ // msecs_to_jiffies(200)); //ices del by 20140812
}
if (!flag) {
@@ -1552,7 +1699,7 @@ static long epl88051_ps_ioctl(struct file *file, unsigned int cmd, unsigned long
}
LOG_INFO("[PS] %s elan Proximity Sensor set pflag %d\n", __FUNCTION__, flag);
break;
-
+ /*Get psensor raw data*/
case ELAN_EPL6800_IOCTL_GETDATA:
value = gRawData.ps_raw;
@@ -1581,7 +1728,7 @@ static struct file_operations epl88051_ps_fops =
static struct miscdevice epl88051_ps_device =
{
.minor = MISC_DYNAMIC_MINOR,
- .name = "cm3602",
+ .name = "cm3602", //"elan_ps",
.fops = &epl88051_ps_fops
};
@@ -1597,7 +1744,7 @@ static int epl88051_initial_sensor(struct epl88051_priv *epld)
if (ret < 0)
return -EINVAL;
-
+ /* Setting single mode and disable interrupt mode */
epl88051_I2C_Write(client, REG_0, W_SINGLE_BYTE, 0x02, EPL_S_SENSING_MODE);
epl88051_I2C_Write(client, REG_6, W_SINGLE_BYTE, 0x02, EPL_INT_DISABLE);
@@ -1894,6 +2041,7 @@ static int fb_notifier_callback(struct notifier_block *self,
blank = evdata->data;
switch (*blank) {
case FB_BLANK_UNBLANK:
+// sensor_lpm_power(0);
epld->als_suspend = 0;
epld->ps_suspend = 0;
epld->hs_suspend = 0;
@@ -1907,6 +2055,7 @@ static int fb_notifier_callback(struct notifier_block *self,
case FB_BLANK_VSYNC_SUSPEND:
case FB_BLANK_NORMAL:
if (epld->enable_pflag == 0) {
+// sensor_lpm_power(1);
epld->als_suspend = 1;
epld->hs_suspend = 1;
epld->ps_suspend = 1;
@@ -2061,7 +2210,7 @@ static int epl88051_parse_dt(struct device *dev, struct epl88051_priv *pdata)
pdata->intr_pin = of_get_named_gpio_flags(dt, "epl88051,irq-gpio",
0, &pdata->irq_gpio_flags);
-
+ //pdata->lpm_power = cm3629_sr_lpm;
return 0;
@@ -2129,7 +2278,7 @@ static int epl88051_probe(struct i2c_client *client,const struct i2c_device_id *
epld->ps_threshold_low = (uint8_t) ((epld->emmc_ps_kadc2 >> 16) & 0xFF) + (uint8_t) (epld->emmc_ps_kadc2 & 0xFF);
epld->ps_threshold_high = epld->ps_threshold_low + epld->ps_threshold_diff;
epld->polling_mode_ps = PS_POLLING_MODE;
- epld->ps_max_ch0 = MAX_PS_CH0;
+ epld->ps_max_ch0 = MAX_PS_CH0; //ices add by 20140814
epl88051_obj = epld;
@@ -2140,21 +2289,21 @@ static int epl88051_probe(struct i2c_client *client,const struct i2c_device_id *
goto err_create_singlethread_workqueue;
}
-
+ /*setup lightsensor*/
err = epl88051_setup_lsensor(epld);
if (err < 0) {
LOG_ERR("epl88051_setup_lsensor error!!\n");
goto err_lightsensor_setup;
}
-
+ /*setup psensor*/
err = epl88051_setup_psensor(epld);
if (err < 0) {
LOG_ERR("epl88051_setup_psensor error!!\n");
goto err_psensor_setup;
}
-
+ /*init sensor*/
err = epl88051_initial_sensor(epld);
if (err < 0) {
LOG_ERR("fail to initial sensor (%d)\n", err);
@@ -2162,7 +2311,7 @@ static int epl88051_probe(struct i2c_client *client,const struct i2c_device_id *
}
if (epld->polling_mode_ps == 0) {
-
+ /*setup interrupt*/
err = epl88051_setup_interrupt(epld);
if (err < 0) {
LOG_ERR("setup error!\n");
@@ -2251,7 +2400,7 @@ static int epl88051_probe(struct i2c_client *client,const struct i2c_device_id *
err = device_create_file(epld->ps_dev, &dev_attr_ps_polling_mode);
if (err)
goto err_create_ps_device;
-#if 1
+#if 1 //ices add by 20140812
err = device_create_file(epld->ps_dev, &dev_attr_dyn_max_ps_ch0);
if (err)
goto err_create_ps_device;
@@ -2303,7 +2452,7 @@ err_sensor_setup:
misc_deregister(&epl88051_als_device);
err_create_singlethread_workqueue:
i2c_fail:
-
+ //err_platform_data_null:
kfree(epld);
return err;
}
@@ -2314,7 +2463,7 @@ static int epl88051_remove(struct i2c_client *client)
dev_dbg(&client->dev, "%s: enter.\n", __func__);
-
+ //sysfs_remove_group(&sensor_dev->dev.kobj, &epl88051_attr_group);
platform_device_unregister(sensor_dev);
input_unregister_device(epld->als_input_dev);
input_unregister_device(epld->ps_input_dev);
diff --git a/drivers/i2c/chips/pn544.c b/drivers/i2c/chips/pn544.c
index 5866cb8..e4c77d6 100644
--- a/drivers/i2c/chips/pn544.c
+++ b/drivers/i2c/chips/pn544.c
@@ -17,7 +17,7 @@
#include <linux/spinlock.h>
#include <linux/wakelock.h>
#include <linux/of_gpio.h>
-#include <linux/nfc/pn544.h>
+#include <linux/pn544.h>
#include <mach/board_htc.h>
int is_debug = 0;
@@ -164,12 +164,11 @@ static irqreturn_t pn544_dev_irq_handler(int irq, void *dev_id)
struct pn544_dev *pn544_dev = dev_id;
static unsigned long orig_jiffies = 0;
-#ifdef CONFIG_SENSORS_NFC_IRQ_WORKAROUND
if (gpio_get_value(pn544_dev->irq_gpio) == 0) {
I("%s: irq_workaround\n", __func__);
return IRQ_HANDLED;
}
-#endif
+
pn544_disable_irq(pn544_dev);
@@ -209,6 +208,7 @@ static int pn544_isEn(void)
return pni->ven_value;
}
+
uint8_t read_buffer[MAX_BUFFER_SIZE];
static ssize_t pn544_dev_read(struct file *filp, char __user *buf,
@@ -223,7 +223,7 @@ static ssize_t pn544_dev_read(struct file *filp, char __user *buf,
D("%s: start count = %u\n", __func__, count);
if (count > MAX_BUFFER_SIZE) {
- E("%s : count =%d> MAX_BUFFER_SIZE\n", __func__, count);
+ E("%s : count =%zu> MAX_BUFFER_SIZE\n", __func__, count);
count = MAX_BUFFER_SIZE;
}
@@ -284,7 +284,7 @@ static ssize_t pn544_dev_read(struct file *filp, char __user *buf,
return -EFAULT;
}
- D("%s done count = %u\n", __func__, count);
+ D("%s done count = %zu\n", __func__, count);
return count;
fail:
@@ -301,11 +301,11 @@ static ssize_t pn544_dev_write(struct file *filp, const char __user *buf,
int i;
i = 0;
- D("%s: start count = %u\n", __func__, count);
+ D("%s: start count = %zu\n", __func__, count);
wake_lock_timeout(&pni ->io_wake_lock, IO_WAKE_LOCK_TIMEOUT);
if (count > MAX_BUFFER_SIZE) {
- E("%s : count =%d> MAX_BUFFER_SIZE\n", __func__, count);
+ E("%s : count =%zu> MAX_BUFFER_SIZE\n", __func__, count);
count = MAX_BUFFER_SIZE;
}
@@ -329,7 +329,7 @@ static ssize_t pn544_dev_write(struct file *filp, const char __user *buf,
E("%s : i2c_master_send returned %d\n", __func__, ret);
ret = -EIO;
} else {
- D("%s done count = %u\n", __func__, count);
+ D("%s done count = %zu\n", __func__, count);
return count;
}
@@ -450,7 +450,7 @@ static ssize_t pn_temp1_show(struct device *dev,
}
#endif
- ret = sprintf(buf, "GPIO INT = %d "
+ ret = snprintf(buf, MAX_BUFFER_SIZE*2 , "GPIO INT = %d "
"Rx:ret=%d [0x%x, 0x%x, 0x%x, 0x%x]\n", val, ret, buffer[0], buffer[1],
buffer[2], buffer[3]);
@@ -557,7 +557,7 @@ static ssize_t debug_enable_show(struct device *dev,
int ret = 0;
I("debug_enable_show\n");
- ret = sprintf(buf, "is_debug=%d\n", is_debug);
+ ret = snprintf(buf, MAX_BUFFER_SIZE *2 ,"is_debug=%d\n", is_debug);
return ret;
}
@@ -576,18 +576,18 @@ static ssize_t nxp_chip_alive_show(struct device *dev,
{
int ret = 0;
I("%s is %d\n", __func__, is_alive);
- ret = sprintf(buf, "%d\n", is_alive);
+ ret = snprintf(buf, MAX_BUFFER_SIZE*2 ,"%d\n", is_alive);
return ret;
}
-static DEVICE_ATTR(nxp_chip_alive, 0664, nxp_chip_alive_show, NULL);
+static DEVICE_ATTR(nxp_chip_alive, 0444, nxp_chip_alive_show, NULL);
static ssize_t nxp_uicc_swp_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
int ret = 0;
I("%s is %d\n", __func__, is_uicc_swp);
- ret = sprintf(buf, "%d\n", is_uicc_swp);
+ ret = snprintf(buf, MAX_BUFFER_SIZE*2 ,"%d\n", is_uicc_swp);
return ret;
}
@@ -605,8 +605,8 @@ static ssize_t mfg_nfc_ctrl_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
int ret = 0;
- I("%s mfc_nfc_cmd_result is %d\n", __func__, mfc_nfc_cmd_result);
- ret = sprintf(buf, "%d\n", mfc_nfc_cmd_result);
+ I("%s not implement yet!! mfc_nfc_cmd_result is %d\n", __func__, mfc_nfc_cmd_result);
+ ret = snprintf(buf, MAX_BUFFER_SIZE*2 ,"%d\n", mfc_nfc_cmd_result);
return ret;
}
@@ -617,30 +617,30 @@ static ssize_t mfg_nfc_ctrl_store(struct device *dev,
int code = -1;
sscanf(buf, "%d", &code);
- I("%s: store value = %d\n", __func__, code);
+ I("%s: not implement yet!! store value = %d\n", __func__, code);
switch (code) {
case 0:
- I("%s: get nfcversion :\n", __func__);
- mfc_nfc_cmd_result = 137;
+ I("%s: not implement yet!! get nfcversion :\n", __func__);
+ mfc_nfc_cmd_result = -100;
break;
case 1:
- I("%s: nfcreader test :\n", __func__);
- mfc_nfc_cmd_result = 1;
+ I("%s: not implement yet!! nfcreader test :\n", __func__);
+ mfc_nfc_cmd_result = -100;
break;
case 2:
- I("%s: nfccard test :\n", __func__);
- mfc_nfc_cmd_result = 1;
+ I("%s: not implement yet!! nfccard test :\n", __func__);
+ mfc_nfc_cmd_result = -100;
break;
default:
- E("%s: case default\n", __func__);
+ E("%s: not implement yet!! case default do nothing\n", __func__);
break;
}
I("%s: END\n", __func__);
return count;
}
-static DEVICE_ATTR(mfg_nfc_ctrl, 0664, mfg_nfc_ctrl_show, mfg_nfc_ctrl_store);
+static DEVICE_ATTR(mfg_nfc_ctrl, 0660, mfg_nfc_ctrl_show, mfg_nfc_ctrl_store);
static int pn544_parse_dt(struct device *dev, struct pn544_i2c_platform_data *pdata)
{
@@ -741,7 +741,7 @@ static int pn544_probe(struct i2c_client *client,
"pn544_probe : failed to allocate \
memory for module data\n");
ret = -ENOMEM;
- goto err_exit;
+ goto err_kzalloc;
}
pn_info = pni;
@@ -878,12 +878,14 @@ err_misc_register:
wake_lock_destroy(&pni->io_wake_lock);
kfree(pni);
pn_info = NULL;
+err_kzalloc:
gpio_free(platform_data->firm_gpio);
err_request_gpio_firm:
gpio_free(platform_data->ven_gpio);
err_request_gpio_ven:
gpio_free(platform_data->irq_gpio);
err_exit:
+ kfree(platform_data);
E("%s: prob fail\n", __func__);
return ret;
}
diff --git a/drivers/i2c/chips/rt5501.c b/drivers/i2c/chips/rt5501.c
index 0d2956d..76ac1a9 100644
--- a/drivers/i2c/chips/rt5501.c
+++ b/drivers/i2c/chips/rt5501.c
@@ -37,6 +37,13 @@
#include <mach/htc_acoustic_pmic.h>
#include <linux/jiffies.h>
+//htc audio ++
+#undef pr_info
+#undef pr_err
+#define pr_info(fmt, ...) pr_aud_info(fmt, ##__VA_ARGS__)
+#define pr_err(fmt, ...) pr_aud_err(fmt, ##__VA_ARGS__)
+//htc audio --
+
#ifdef CONFIG_AMP_RT5501_ON_GPIO
#define DEBUG (1)
#else
@@ -259,8 +266,8 @@ static int rt5501_i2c_write(struct rt5501_reg_data *txData, int length)
},
};
for (i = 0; i < length; i++) {
-
-
+ //if (i == 2) /* According to rt5501 Spec */
+ // mdelay(1);
buf[0] = txData[i].addr;
buf[1] = txData[i].val;
@@ -301,8 +308,8 @@ static int rt5501_i2c_write_for_read(char *txData, int length)
},
};
for (i = 0; i < length; i++) {
-
-
+ //if (i == 2) /* According to rt5501 Spec */
+ // mdelay(1);
buf[0] = i;
buf[1] = txData[i];
#if DEBUG
@@ -392,6 +399,12 @@ static int rt5501_i2c_read_addr(char *rxData, unsigned char addr)
return rc;
}
+ /*{
+ int i = 0;
+ for (i = 0; i < length; i++)
+ pr_info("i2c_read %s: rx[%d] = %2x\n", __func__, i, \
+ rxData[i]);
+ }*/
pr_info("%s:i2c_read addr 0x%x value = 0x%x\n", __func__, addr, *rxData);
return 0;
}
@@ -556,7 +569,7 @@ static void hs_imp_detec_func(struct work_struct *work)
om = (temp[0] & 0xe) >> 1;
if((temp[0] == 0xc0 || temp[0] == 0xc1) && (temp[1] == 0)) {
-
+ //mono headset
hsom = HEADSET_MONO;
} else {
@@ -669,7 +682,7 @@ static void volume_ramp_func(struct work_struct *work)
u8 val;
pr_info("%s: ramping-------------------------\n",__func__);
mdelay(1);
-
+ //start state machine and disable noise gate
if(high_imp)
rt5501_write_reg(0xb1,0x80);
@@ -933,7 +946,7 @@ err2:
update_amp_parameter(RT5501_MODE_OFF);
update_amp_parameter(RT5501_MUTE);
update_amp_parameter(RT5501_INIT);
-
+ //update_amp_parameter(RT5501_MODE_MFG);
mutex_unlock(&hp_amp_lock);
rc = 0;
break;
diff --git a/drivers/i2c/chips/rt5501_evm.c b/drivers/i2c/chips/rt5501_evm.c
index 1b83ae4..e584fae 100644
--- a/drivers/i2c/chips/rt5501_evm.c
+++ b/drivers/i2c/chips/rt5501_evm.c
@@ -36,6 +36,13 @@
#include <linux/of_gpio.h>
#include <mach/htc_acoustic_alsa.h>
+//htc audio ++
+#undef pr_info
+#undef pr_err
+#define pr_info(fmt, ...) pr_aud_info(fmt, ##__VA_ARGS__)
+#define pr_err(fmt, ...) pr_aud_err(fmt, ##__VA_ARGS__)
+//htc audio --
+
#ifdef CONFIG_AMP_RT5501_ON_GPIO
#define DEBUG (1)
#else
diff --git a/drivers/i2c/chips/rt5506.c b/drivers/i2c/chips/rt5506.c
index 05c72c0..6bfa75a 100644
--- a/drivers/i2c/chips/rt5506.c
+++ b/drivers/i2c/chips/rt5506.c
@@ -36,6 +36,12 @@
#include <linux/of_gpio.h>
#include <mach/htc_acoustic_alsa.h>
+#undef pr_info
+#undef pr_err
+#define pr_info(fmt, ...) pr_aud_info(fmt, ##__VA_ARGS__)
+#define pr_err(fmt, ...) pr_aud_err(fmt, ##__VA_ARGS__)
+
+
#define DEBUG (1)
#define AMP_ON_CMD_LEN 7
#define RETRY_CNT 5
@@ -75,6 +81,9 @@ struct headset_query {
struct delayed_work volume_ramp_work;
struct delayed_work gpio_off_work;
int hs_connec;
+#ifdef CONFIG_HTC_HEADSET_DET_DEBOUNCE
+ int hs_imp_over;
+#endif
unsigned long power_mask;
};
@@ -105,6 +114,17 @@ static struct workqueue_struct *ramp_wq;
static struct workqueue_struct *gpio_wq;
static int high_imp = 0;
+#ifdef CONFIG_HTC_HEADSET_DET_DEBOUNCE
+int query_imp_over_threshold(void)
+{
+ int ret = 0;
+ mutex_lock(&rt5506_query.mlock);
+ ret = rt5506_query.hs_imp_over;
+ mutex_unlock(&rt5506_query.mlock);
+ return ret;
+}
+#endif
+
static int set_rt5506_regulator(enum AMP_REG_MODE mode)
{
if(pdata->power_reg) {
@@ -187,6 +207,9 @@ static int rt5506_headset_detect(void *private_data, int on)
rt5506_query.hs_qstatus = QUERY_HEADSET;
rt5506_query.headsetom = HEADSET_OM_UNDER_DETECT;
+#ifdef CONFIG_HTC_HEADSET_DET_DEBOUNCE
+ rt5506_query.hs_imp_over = -EINVAL;
+#endif
if(rt5506_query.rt5506_status == STATUS_PLAYBACK) {
if(high_imp) {
@@ -590,6 +613,17 @@ static void hs_imp_detec_func(struct work_struct *work)
if(hs->rt5506_status == STATUS_PLAYBACK)
hs->rt5506_status = STATUS_SUSPEND;
+#ifdef CONFIG_HTC_HEADSET_DET_DEBOUNCE
+
+ if(hs->hs_qstatus == QUERY_FINISH) {
+
+ if(r_channel > 0x88)
+ hs->hs_imp_over = 1;
+ else
+ hs->hs_imp_over = 0;
+ }
+#endif
+
unvote_power(&rt5506_query.power_mask, POWER_IMPEDANCE);
mutex_unlock(&hs->mlock);
mutex_unlock(&hs->gpiolock);
diff --git a/drivers/i2c/chips/tfa9887.c b/drivers/i2c/chips/tfa9887.c
index 0fc8f41..d70a722 100644
--- a/drivers/i2c/chips/tfa9887.c
+++ b/drivers/i2c/chips/tfa9887.c
@@ -34,13 +34,19 @@
#include <linux/of_gpio.h>
#include <mach/htc_acoustic_alsa.h>
+#undef pr_info
+#undef pr_err
+#define pr_info(fmt, ...) pr_aud_info(fmt, ##__VA_ARGS__)
+#define pr_err(fmt, ...) pr_aud_err(fmt, ##__VA_ARGS__)
+
#define TPA9887_IOCTL_MAGIC 'a'
#define TPA9887_WRITE_CONFIG _IOW(TPA9887_IOCTL_MAGIC, 0x01, unsigned int)
#define TPA9887_READ_CONFIG _IOW(TPA9887_IOCTL_MAGIC, 0x02, unsigned int)
#define TPA9887_ENABLE_DSP _IOW(TPA9887_IOCTL_MAGIC, 0x03, unsigned int)
#define TPA9887_WRITE_L_CONFIG _IOW(TPA9887_IOCTL_MAGIC, 0x04, unsigned int)
#define TPA9887_READ_L_CONFIG _IOW(TPA9887_IOCTL_MAGIC, 0x05, unsigned int)
-#define TPA9887_KERNEL_LOCK _IOW(TPA9887_IOCTL_MAGIC, 0x06, unsigned int)
+#define TPA9887_KERNEL_LOCK _IOW(TPA9887_IOCTL_MAGIC, 0x06, unsigned int)
+#define TPA9887_KERNEL_INIT _IOW(TPA9887_IOCTL_MAGIC, 0x07, unsigned int)
#define DEBUG (0)
static struct i2c_client *this_client;
@@ -48,6 +54,7 @@ static struct tfa9887_platform_data *pdata;
struct mutex spk_amp_lock;
static int tfa9887_opened;
static int last_spkamp_state;
+static int lock_from_userspace;
static int dsp_enabled;
static int tfa9887_i2c_write(char *txData, int length);
static int tfa9887_i2c_read(char *rxData, int length);
@@ -116,7 +123,7 @@ static ssize_t codec_debug_write(struct file *filp,
lbuf[cnt] = '\0';
if (!strcmp(access_str, "poke")) {
- /* write */
+
rc = get_parameters(lbuf, param, 2);
if ((param[0] <= 0xFF) && (param[1] <= 0xFF) &&
(rc == 0)) {
@@ -126,7 +133,7 @@ static ssize_t codec_debug_write(struct file *filp,
} else
rc = -EINVAL;
} else if (!strcmp(access_str, "peek")) {
- /* read */
+
rc = get_parameters(lbuf, param, 1);
if ((param[0] <= 0xFF) && (rc == 0)) {
reg_idx[0] = param[0];
@@ -469,10 +476,34 @@ static long tfa9887_ioctl(struct file *file, unsigned int cmd,
len = reg_value[0];
pr_debug("TPA9887_KLOCK1 %d\n", reg_value[1]);
- if (reg_value[1])
- mutex_lock(&spk_amp_lock);
- else
- mutex_unlock(&spk_amp_lock);
+ if (reg_value[1]) {
+ mutex_lock(&spk_amp_lock);
+ lock_from_userspace++;
+ } else {
+ lock_from_userspace--;
+ if (lock_from_userspace >= 0) {
+ mutex_unlock(&spk_amp_lock);
+ } else {
+ pr_warn("%s: lock_from_userspace is not equal to zero, should not meet."
+ "don't unlock it again", __func__);
+ lock_from_userspace = 0;
+ }
+ }
+ break;
+
+ case TPA9887_KERNEL_INIT:
+ pr_info("%s: TPA9887_KERNEL_INIT ++ kernel count %d\n",
+ __func__, atomic_read(&(spk_amp_lock.count)));
+ while (lock_from_userspace > 0) {
+ pr_info("%s: TPA9887_KERNEL_INIT lock count from userspace %d != 0, unlock it\n",
+ __func__, lock_from_userspace);
+ lock_from_userspace--;
+ mutex_unlock(&spk_amp_lock);
+ }
+ lock_from_userspace = 0;
+ mutex_init(&spk_amp_lock);
+ pr_info("%s: TPA9887_KERNEL_INIT -- kernel count %d\n",
+ __func__, atomic_read(&(spk_amp_lock.count)));
break;
case ACOUSTIC_AMP_CTRL:
@@ -633,7 +664,9 @@ static int __init tfa9887_init(void)
{
pr_info("%s\n", __func__);
mutex_init(&spk_amp_lock);
- dsp_enabled = 0;
+ dsp_enabled = 0;
+ last_spkamp_state = 0;
+ lock_from_userspace = 0;
return i2c_add_driver(&tfa9887_driver);
}
diff --git a/drivers/i2c/chips/tfa9887l.c b/drivers/i2c/chips/tfa9887l.c
index 12ef241..ef71d33 100644
--- a/drivers/i2c/chips/tfa9887l.c
+++ b/drivers/i2c/chips/tfa9887l.c
@@ -33,11 +33,17 @@
#include <linux/of_gpio.h>
#include <mach/htc_acoustic_alsa.h>
+#undef pr_info
+#undef pr_err
+#define pr_info(fmt, ...) pr_aud_info(fmt, ##__VA_ARGS__)
+#define pr_err(fmt, ...) pr_aud_err(fmt, ##__VA_ARGS__)
+
#define TPA9887_IOCTL_MAGIC 'a'
#define TPA9887_WRITE_CONFIG _IOW(TPA9887_IOCTL_MAGIC, 0x01, unsigned int)
#define TPA9887_READ_CONFIG _IOW(TPA9887_IOCTL_MAGIC, 0x02, unsigned int)
#define TPA9887_ENABLE_DSP _IOW(TPA9887_IOCTL_MAGIC, 0x03, unsigned int)
-#define TPA9887_KERNEL_LOCK _IOW(TPA9887_IOCTL_MAGIC, 0x06, unsigned int)
+#define TPA9887_KERNEL_LOCK _IOW(TPA9887_IOCTL_MAGIC, 0x06, unsigned int)
+#define TPA9887_KERNEL_INIT _IOW(TPA9887_IOCTL_MAGIC, 0x07, unsigned int)
#define DEBUG (0)
static struct i2c_client *this_client;
@@ -45,6 +51,7 @@ static struct tfa9887_platform_data *pdata;
struct mutex spk_ampl_lock;
static int tfa9887l_opened;
static int last_spkampl_state;
+static int lock_from_userspace;
static int dspl_enabled;
static int tfa9887_i2c_write(char *txData, int length);
static int tfa9887_i2c_read(char *rxData, int length);
@@ -113,7 +120,7 @@ static ssize_t codec_debug_write(struct file *filp,
lbuf[cnt] = '\0';
if (!strcmp(access_str, "poke")) {
- /* write */
+
rc = get_parameters(lbuf, param, 2);
if ((param[0] <= 0xFF) && (param[1] <= 0xFF) &&
(rc == 0)) {
@@ -123,7 +130,7 @@ static ssize_t codec_debug_write(struct file *filp,
} else
rc = -EINVAL;
} else if (!strcmp(access_str, "peek")) {
- /* read */
+
rc = get_parameters(lbuf, param, 1);
if ((param[0] <= 0xFF) && (rc == 0)) {
reg_idx[0] = param[0];
@@ -405,10 +412,35 @@ static long tfa9887l_ioctl(struct file *file, unsigned int cmd,
len = reg_value[0];
pr_debug("TPA9887_KLOCK2 %d\n", reg_value[1]);
- if (reg_value[1])
- mutex_lock(&spk_ampl_lock);
- else
- mutex_unlock(&spk_ampl_lock);
+ if (reg_value[1]) {
+ mutex_lock(&spk_ampl_lock);
+ lock_from_userspace++;
+ }
+ else {
+ lock_from_userspace--;
+ if (lock_from_userspace >= 0) {
+ mutex_unlock(&spk_ampl_lock);
+ } else {
+ pr_warn("%s: lock_from_userspace is not equal to zero, should not meet."
+ "don't unlock it again", __func__);
+ lock_from_userspace = 0;
+ }
+ }
+ break;
+
+ case TPA9887_KERNEL_INIT:
+ pr_info("%s: TPA9887_KERNEL_INIT (L) ++ kernel count %d\n",
+ __func__, atomic_read(&(spk_ampl_lock.count)));
+ while (lock_from_userspace > 0) {
+ pr_info("%s: TPA9887_KERNEL_INIT (L) lock count from userspace %d != 0, unlock it\n",
+ __func__, lock_from_userspace);
+ lock_from_userspace--;
+ mutex_unlock(&spk_ampl_lock);
+ }
+ lock_from_userspace = 0;
+ mutex_init(&spk_ampl_lock);
+ pr_info("%s: TPA9887_KERNEL_INIT (L) -- kernel count %d\n",
+ __func__, atomic_read(&(spk_ampl_lock.count)));
break;
case ACOUSTIC_AMP_CTRL:
@@ -569,7 +601,9 @@ static int __init tfa9887l_init(void)
{
pr_info("%s\n", __func__);
mutex_init(&spk_ampl_lock);
- dspl_enabled = 0;
+ dspl_enabled = 0;
+ last_spkampl_state = 0;
+ lock_from_userspace = 0;
return i2c_add_driver(&tfa9887l_driver);
}
diff --git a/drivers/i2c/chips/tpa6185.c b/drivers/i2c/chips/tpa6185.c
index fb1fb4b..f9afd44 100644
--- a/drivers/i2c/chips/tpa6185.c
+++ b/drivers/i2c/chips/tpa6185.c
@@ -32,6 +32,13 @@
#include <linux/module.h>
#include <linux/mfd/pm8xxx/pm8921.h>
+//htc audio ++
+#undef pr_info
+#undef pr_err
+#define pr_info(fmt, ...) pr_aud_info(fmt, ##__VA_ARGS__)
+#define pr_err(fmt, ...) pr_aud_err(fmt, ##__VA_ARGS__)
+//htc audio --
+
#ifdef CONFIG_AMP_TPA6185_ON_GPIO
#define DEBUG (1)
#else
diff --git a/drivers/i2c/chips/yas53x_drv.c b/drivers/i2c/chips/yas53x_drv.c
old mode 100644
new mode 100755
index 5e28c3f..e96aeac
--- a/drivers/i2c/chips/yas53x_drv.c
+++ b/drivers/i2c/chips/yas53x_drv.c
@@ -32,18 +32,18 @@
#define YAS_REG_TEST2 (0x89)
#define YAS_REG_CAL (0x90)
#define YAS_REG_MEASURE_DATA (0xb0)
-#define YAS_YAS530_DEVICE_ID (0x01)
-#define YAS_YAS530_VERSION_A (0)
-#define YAS_YAS530_VERSION_B (1)
+#define YAS_YAS530_DEVICE_ID (0x01) /* YAS530 (MS-3E) */
+#define YAS_YAS530_VERSION_A (0) /* YAS530 (MS-3E Aver) */
+#define YAS_YAS530_VERSION_B (1) /* YAS530B (MS-3E Bver) */
#define YAS_YAS530_VERSION_A_COEF (380)
#define YAS_YAS530_VERSION_B_COEF (550)
#define YAS_YAS530_DATA_CENTER (2048)
#define YAS_YAS530_DATA_UNDERFLOW (0)
#define YAS_YAS530_DATA_OVERFLOW (4095)
-#define YAS_YAS532_DEVICE_ID (0x02)
-#define YAS_YAS532_VERSION_AB (0)
-#define YAS_YAS532_VERSION_AC (1)
+#define YAS_YAS532_DEVICE_ID (0x02) /* YAS532_533 (MS-3R/3F) */
+#define YAS_YAS532_VERSION_AB (0) /* YAS532_533AB (MS-3R/3F ABver) */
+#define YAS_YAS532_VERSION_AC (1) /* YAS532_533AC (MS-3R/3F ACver) */
#define YAS_YAS532_VERSION_AB_COEF (1800)
#define YAS_YAS532_VERSION_AC_COEF_X (850)
#define YAS_YAS532_VERSION_AC_COEF_Y1 (750)
@@ -56,7 +56,7 @@
#define YAS_MAG_STATE_INIT_COIL (1)
#define YAS_MAG_STATE_MEASURE_OFFSET (2)
#define YAS_MAG_NOTRANS_POSITION (3)
-#define YAS_MAG_INITCOIL_TIMEOUT (500)
+#define YAS_MAG_INITCOIL_TIMEOUT (500) /* msec */
#define YAS_MAG_TEMPERATURE_LOG (10)
#define set_vector(to, from) \
@@ -384,9 +384,9 @@ static int yas_cdrv_measure(int32_t *xyz, int16_t *xy1y2, int32_t *xy1y2_linear,
for (i = 0; i < 3; i++) {
xyz_tmp[i] -= xyz_tmp[i] % 10;
if (ouflow & (1<<(i*2)))
- xyz_tmp[i] += 1;
+ xyz_tmp[i] += 1; /* set overflow */
if (ouflow & (1<<(i*2+1)))
- xyz_tmp[i] += 2;
+ xyz_tmp[i] += 2; /* set underflow */
}
set_vector(xyz, xyz_tmp);
if (busy)
@@ -472,7 +472,7 @@ static int yas_measure(struct yas_mag_data *data, int temp_correction) {
driver.measure_state = YAS_MAG_STATE_NORMAL;
break;
}
-
+ /* FALLTHRU */
case YAS_MAG_STATE_MEASURE_OFFSET:
set_vector(hard_offset, driver.hard_offset);
rt = yas_cdrv_measure_and_set_offset();
diff --git a/drivers/i2c/chips/yas53x_kernel.c b/drivers/i2c/chips/yas53x_kernel.c
old mode 100644
new mode 100755
index a5c5ea0..61f0c50
--- a/drivers/i2c/chips/yas53x_kernel.c
+++ b/drivers/i2c/chips/yas53x_kernel.c
@@ -40,7 +40,7 @@
#include "yas53x_drv.c"
#define YAS53X_NAME "yas53x"
-#define YAS53X_MIN_DELAY (200)
+#define YAS53X_MIN_DELAY (200) /* msec */
#define D(x...) printk(KERN_DEBUG "[COMP][YAS53X] " x)
#define I(x...) printk(KERN_INFO "[COMP][YAS53X] " x)
@@ -135,6 +135,7 @@ static int yas53x_disable(struct yas53x_data *data) {
return 0;
}
+/* Sysfs interface */
static ssize_t yas53x_delay_show(struct device *dev, struct device_attribute *attr, char *buf) {
struct yas53x_data *data = i2c_get_clientdata(this_client);
int32_t delay;
@@ -303,7 +304,7 @@ static void yas53x_input_work_func(struct work_struct *work) {
yas53x_current_time(&time_after);
delay = data->delay - (time_after - time_before);
mutex_unlock(&data->mutex);
-
+ /* report magnetic data in [nT] */
input_report_abs(data->input_data, ABS_X, mag.xyz.v[0]);
input_report_abs(data->input_data, ABS_Y, mag.xyz.v[1]);
input_report_abs(data->input_data, ABS_Z, mag.xyz.v[2]);
@@ -539,9 +540,29 @@ static struct i2c_driver yas53x_i2c_driver = {
.remove = yas53x_remove,
.id_table = yas53x_id,
+/* .id_table = yas53x_id,
+ .probe = yas53x_probe,
+ .remove = yas53x_remove,
+ .suspend = yas53x_suspend,
+ .resume = yas53x_resume,*/
};
module_i2c_driver(yas53x_i2c_driver);
+/*static int __init
+yas53x_init(void)
+{
+ return i2c_add_driver(&yas53x_i2c_driver);
+}
+
+static void __exit
+yas53x_term(void)
+{
+ i2c_del_driver(&yas53x_i2c_driver);
+}
+
+module_init(yas53x_init);
+module_exit(yas53x_term);
+*/
MODULE_AUTHOR("Yamaha Corporation");
MODULE_DESCRIPTION("YAS53x Geomagnetic Sensor Driver");
MODULE_LICENSE("GPL");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment