summaryrefslogtreecommitdiff
path: root/drivers/input
diff options
context:
space:
mode:
authorJohnny Qiu <joqiu@nvidia.com>2012-02-13 15:33:11 +0800
committerRohan Somvanshi <rsomvanshi@nvidia.com>2012-02-17 06:43:39 -0800
commit03835470a673447cd3dafd2df9d7081e378b1aac (patch)
treeac7875dfa8f1beefcdbfce17869138e1153b4680 /drivers/input
parent46aa6c47a60afebb79b21e4f909bb892148a41ef (diff)
input: misc: Fix code style issues for CM3217
Bug 937953 Change-Id: I5466fedf6fdcd1f577753736e9eb9b2dbf5b52c0 Signed-off-by: Johnny Qiu <joqiu@nvidia.com> Reviewed-on: http://git-master/r/83386 Reviewed-by: Bharat Nihalani <bnihalani@nvidia.com>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/misc/cm3217.c553
1 files changed, 303 insertions, 250 deletions
diff --git a/drivers/input/misc/cm3217.c b/drivers/input/misc/cm3217.c
index eed3a6dd331e..f6dc7e58eb17 100644
--- a/drivers/input/misc/cm3217.c
+++ b/drivers/input/misc/cm3217.c
@@ -1,7 +1,7 @@
/* drivers/input/misc/cm3217.c - cm3217 optical sensors driver
*
* Copyright (C) 2011 Capella Microsystems Inc.
- * Author: Frank Hsieh <pengyueh@gmail.com>
+ * Author: Frank Hsieh <pengyueh@gmail.com>
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
@@ -29,18 +29,18 @@
#include <linux/miscdevice.h>
#include <linux/lightsensor.h>
#include <linux/slab.h>
-#include <asm/uaccess.h>
-#include <asm/mach-types.h>
+#include <linux/uaccess.h>
#include <linux/cm3217.h>
-#include <asm/setup.h>
#include <linux/wakelock.h>
#include <linux/jiffies.h>
+#include <asm/mach-types.h>
+#include <asm/setup.h>
-#define D(x...) pr_info(x)
+#define D(x...) pr_info(x)
-#define I2C_RETRY_COUNT 10
+#define I2C_RETRY_COUNT 10
-#define LS_POLLING_DELAY 500
+#define LS_POLLING_DELAY 500
static void report_do_work(struct work_struct *w);
static DECLARE_DELAYED_WORK(report_work, report_do_work);
@@ -59,7 +59,7 @@ struct cm3217_info {
uint16_t cali_table[10];
int irq;
int ls_calibrate;
- int (*power)(int, uint8_t); /* power to the chip */
+ int (*power) (int, uint8_t); /* power to the chip */
uint32_t als_kadc;
uint32_t als_gadc;
@@ -68,12 +68,16 @@ struct cm3217_info {
int lightsensor_opened;
int current_level;
uint16_t current_adc;
- int polling_delay;
+ int polling_delay;
};
+
struct cm3217_info *lp_info;
-int enable_log = 0;
-int fLevel=-1;
+
+int enable_log;
+int fLevel = -1;
+
static struct mutex als_enable_mutex, als_disable_mutex, als_get_adc_mutex;
+
static int lightsensor_enable(struct cm3217_info *lpi);
static int lightsensor_disable(struct cm3217_info *lpi);
@@ -85,27 +89,26 @@ static int I2C_RxData(uint16_t slaveAddr, uint8_t *rxData, int length)
struct i2c_msg msgs[] = {
{
- .addr = slaveAddr,
- .flags = I2C_M_RD,
- .len = length,
- .buf = rxData,
- },
+ .addr = slaveAddr,
+ .flags = I2C_M_RD,
+ .len = length,
+ .buf = rxData,
+ },
};
for (loop_i = 0; loop_i < I2C_RETRY_COUNT; loop_i++) {
-
if (i2c_transfer(lp_info->i2c_client->adapter, msgs, 1) > 0)
break;
-
msleep(10);
}
+
if (loop_i >= I2C_RETRY_COUNT) {
printk(KERN_ERR "[ERR][CM3217 error] %s retry over %d\n",
- __func__, I2C_RETRY_COUNT);
+ __func__, I2C_RETRY_COUNT);
return -EIO;
}
- return 0;
+ return 0;
}
static int I2C_TxData(uint16_t slaveAddr, uint8_t *txData, int length)
@@ -114,23 +117,22 @@ static int I2C_TxData(uint16_t slaveAddr, uint8_t *txData, int length)
struct i2c_msg msg[] = {
{
- .addr = slaveAddr,
- .flags = 0,
- .len = length,
- .buf = txData,
- },
+ .addr = slaveAddr,
+ .flags = 0,
+ .len = length,
+ .buf = txData,
+ },
};
for (loop_i = 0; loop_i < I2C_RETRY_COUNT; loop_i++) {
if (i2c_transfer(lp_info->i2c_client->adapter, msg, 1) > 0)
break;
-
msleep(10);
}
if (loop_i >= I2C_RETRY_COUNT) {
printk(KERN_ERR "[ERR][CM3217 error] %s retry over %d\n",
- __func__, I2C_RETRY_COUNT);
+ __func__, I2C_RETRY_COUNT);
return -EIO;
}
@@ -147,32 +149,34 @@ static int _cm3217_I2C_Read_Byte(uint16_t slaveAddr, uint8_t *pdata)
ret = I2C_RxData(slaveAddr, &buffer, 1);
if (ret < 0) {
- pr_err(
- "[ERR][CM3217 error]%s: I2C_RxData fail, slave addr: 0x%x\n",
- __func__, slaveAddr);
+ pr_err("[ERR][CM3217 error]%s: I2C_RxData fail, slave addr: 0x%x\n",
+ __func__, slaveAddr);
return ret;
}
*pdata = buffer;
+
#if 0
/* Debug use */
printk(KERN_DEBUG "[CM3217] %s: I2C_RxData[0x%x] = 0x%x\n",
- __func__, slaveAddr, buffer);
+ __func__, slaveAddr, buffer);
#endif
+
return ret;
}
-static int _cm3217_I2C_Write_Byte(uint16_t SlaveAddress,
- uint8_t data)
+static int _cm3217_I2C_Write_Byte(uint16_t SlaveAddress, uint8_t data)
{
char buffer[2];
int ret = 0;
+
#if 0
/* Debug use */
printk(KERN_DEBUG
- "[CM3217] %s: _cm3217_I2C_Write_Byte[0x%x, 0x%x, 0x%x]\n",
- __func__, SlaveAddress, cmd, data);
+ "[CM3217] %s: _cm3217_I2C_Write_Byte[0x%x, 0x%x, 0x%x]\n",
+ __func__, SlaveAddress, cmd, data);
#endif
+
buffer[0] = data;
ret = I2C_TxData(SlaveAddress, buffer, 1);
@@ -186,9 +190,9 @@ static int _cm3217_I2C_Write_Byte(uint16_t SlaveAddress,
static int get_ls_adc_value(uint16_t *als_step, bool resume)
{
- uint8_t lsb, msb;
+ uint8_t lsb, msb;
int ret = 0;
- struct cm3217_info *lpi = lp_info;
+ struct cm3217_info *lpi = lp_info;
if (als_step == NULL)
return -EFAULT;
@@ -196,29 +200,26 @@ static int get_ls_adc_value(uint16_t *als_step, bool resume)
/* Read ALS data: LSB */
ret = _cm3217_I2C_Read_Byte(ALS_R_LSB_addr, &lsb);
if (ret < 0) {
- pr_err(
- "[LS][CM3217 error]%s: _cm3217_I2C_Read_Byte LSB fail\n",
- __func__);
+ pr_err("[LS][CM3217 error]%s: _cm3217_I2C_Read_Byte LSB fail\n",
+ __func__);
return -EIO;
}
/* Read ALS data: MSB */
ret = _cm3217_I2C_Read_Byte(ALS_R_MSB_addr, &msb);
if (ret < 0) {
- pr_err(
- "[LS][CM3217 error]%s: _cm3217_I2C_Read_Byte MSB fail\n",
- __func__);
+ pr_err("[LS][CM3217 error]%s: _cm3217_I2C_Read_Byte MSB fail\n",
+ __func__);
return -EIO;
}
- *als_step = (uint16_t)msb;
+ *als_step = (uint16_t) msb;
*als_step <<= 8;
- *als_step |= (uint16_t)lsb;
+ *als_step |= (uint16_t) lsb;
- D("[LS][CM3217] %s: raw adc = 0x%X\n",
- __func__, *als_step);
+ D("[LS][CM3217] %s: raw adc = 0x%X\n", __func__, *als_step);
- if (!lpi->ls_calibrate) {
+ if (!lpi->ls_calibrate) {
*als_step = (*als_step) * lpi->als_gadc / lpi->als_kadc;
if (*als_step > 0xFFFF)
*als_step = 0xFFFF;
@@ -228,7 +229,7 @@ static int get_ls_adc_value(uint16_t *als_step, bool resume)
}
static void report_lsensor_input_event(struct cm3217_info *lpi, bool resume)
-{/*when resume need report a data, so the paramerter need to quick reponse*/
+{
uint16_t adc_value = 0;
int level = 0, i, ret = 0;
@@ -236,46 +237,58 @@ static void report_lsensor_input_event(struct cm3217_info *lpi, bool resume)
ret = get_ls_adc_value(&adc_value, resume);
- if( lpi->ls_calibrate ) {
- for (i = 0; i < 10; i++) {
- if (adc_value <= (*(lpi->cali_table + i))) {
- level = i;
- if (*(lpi->cali_table + i))
- break;
- }
- if ( i == 9) {/*avoid i = 10, because 'cali_table' of size is 10 */
- level = i;
- break;
- }
- }
- } else {
- for (i = 0; i < 10; i++) {
- if (adc_value <= (*(lpi->adc_table + i))) {
- level = i;
- if (*(lpi->adc_table + i))
- break;
- }
- if ( i == 9) {/*avoid i = 10, because 'cali_table' of size is 10 */
- level = i;
- break;
- }
- }
+ if (lpi->ls_calibrate) {
+ for (i = 0; i < 10; i++) {
+ if (adc_value <= (*(lpi->cali_table + i))) {
+ level = i;
+ if (*(lpi->cali_table + i))
+ break;
+ }
+ /* avoid i = 10, because 'cali_table' of size is 10 */
+ if (i == 9) {
+ level = i;
+ break;
+ }
+ }
+ } else {
+ for (i = 0; i < 10; i++) {
+ if (adc_value <= (*(lpi->adc_table + i))) {
+ level = i;
+ if (*(lpi->adc_table + i))
+ break;
+ }
+ /* avoid i = 10, because 'cali_table' of size is 10 */
+ if (i == 9) {
+ level = i;
+ break;
+ }
+ }
}
if ((i == 0) || (adc_value == 0))
- D("[LS][CM3217] %s: ADC=0x%03X, Level=%d, l_thd equal 0, h_thd = 0x%x \n",
- __func__, adc_value, level, *(lpi->cali_table + i));
+ D("[LS][CM3217] %s: ADC=0x%03X, Level=%d, l_thd equal 0, "
+ "h_thd = 0x%x\n", __func__, adc_value, level,
+ *(lpi->cali_table + i));
else
- D("[LS][CM3217] %s: ADC=0x%03X, Level=%d, l_thd = 0x%x, h_thd = 0x%x \n",
- __func__, adc_value, level, *(lpi->cali_table + (i - 1)) + 1, *(lpi->cali_table + i));
+ D("[LS][CM3217] %s: ADC=0x%03X, Level=%d, l_thd = 0x%x, "
+ "h_thd = 0x%x\n", __func__, adc_value, level,
+ *(lpi->cali_table + (i - 1)) + 1, *(lpi->cali_table + i));
lpi->current_level = level;
lpi->current_adc = adc_value;
- /*D("[CM3217] %s: *(lpi->cali_table + (i - 1)) + 1 = 0x%X, *(lpi->cali_table + i) = 0x%x \n", __func__, *(lpi->cali_table + (i - 1)) + 1, *(lpi->cali_table + i));*/
- if(fLevel>=0){
- D("[LS][CM3217] L-sensor force level enable level=%d fLevel=%d\n",level,fLevel);
- level=fLevel;
+
+ /*
+ D("[CM3217] %s: *(lpi->cali_table + (i - 1)) + 1 = 0x%X, "
+ "*(lpi->cali_table + i) = 0x%x\n", __func__,
+ *(lpi->cali_table + (i - 1)) + 1, *(lpi->cali_table + i));
+ */
+
+ if (fLevel >= 0) {
+ D("[LS][CM3217] L-sensor force level enable level=%d "
+ "fLevel=%d\n", level, fLevel);
+ level = fLevel;
}
+
input_report_abs(lpi->ls_input_dev, ABS_MISC, level);
input_sync(lpi->ls_input_dev);
@@ -285,13 +298,13 @@ static void report_lsensor_input_event(struct cm3217_info *lpi, bool resume)
static void report_do_work(struct work_struct *work)
{
struct cm3217_info *lpi = lp_info;
-
- if (enable_log)
+
+ if (enable_log)
D("[CM3217] %s\n", __func__);
report_lsensor_input_event(lpi, 0);
- queue_delayed_work(lpi->lp_wq, &report_work, lpi->polling_delay);
+ queue_delayed_work(lpi->lp_wq, &report_work, lpi->polling_delay);
}
static int als_power(int enable)
@@ -312,7 +325,7 @@ void lightsensor_set_kvalue(struct cm3217_info *lpi)
}
D("[LS][CM3217] %s: ALS calibrated als_kadc=0x%x\n",
- __func__, als_kadc);
+ __func__, als_kadc);
if (als_kadc >> 16 == ALS_CALIBRATED)
lpi->als_kadc = als_kadc & 0xFFFF;
@@ -329,24 +342,25 @@ void lightsensor_set_kvalue(struct cm3217_info *lpi)
lpi->als_kadc = 1;
lpi->als_gadc = 1;
}
+
D("[LS][CM3217] %s: als_kadc=0x%x, als_gadc=0x%x\n",
- __func__, lpi->als_kadc, lpi->als_gadc);
+ __func__, lpi->als_kadc, lpi->als_gadc);
}
static int lightsensor_update_table(struct cm3217_info *lpi)
{
uint32_t tmpData[10];
int i;
+
for (i = 0; i < 10; i++) {
- tmpData[i] = (uint32_t)(*(lpi->adc_table + i))
- * lpi->als_kadc / lpi->als_gadc ;
- if( tmpData[i] <= 0xFFFF ){
- lpi->cali_table[i] = (uint16_t) tmpData[i];
- } else {
- lpi->cali_table[i] = 0xFFFF;
- }
+ tmpData[i] = (uint32_t) (*(lpi->adc_table + i))
+ * lpi->als_kadc / lpi->als_gadc;
+ if (tmpData[i] <= 0xFFFF)
+ lpi->cali_table[i] = (uint16_t) tmpData[i];
+ else
+ lpi->cali_table[i] = 0xFFFF;
D("[LS][CM3217] %s: Calibrated adc_table: data[%d], %x\n",
- __func__, i, lpi->cali_table[i]);
+ __func__, i, lpi->cali_table[i]);
}
return 0;
@@ -358,30 +372,33 @@ static int lightsensor_enable(struct cm3217_info *lpi)
uint8_t cmd = 0;
mutex_lock(&als_enable_mutex);
+
D("[LS][CM3217] %s\n", __func__);
-
- cmd = ( CM3217_ALS_IT_2_T | CM3217_ALS_BIT5_Default_1 |
- CM3217_ALS_WDM_DEFAULT_1);
+
+ cmd = (CM3217_ALS_IT_2_T | CM3217_ALS_BIT5_Default_1 |
+ CM3217_ALS_WDM_DEFAULT_1);
ret = _cm3217_I2C_Write_Byte(ALS_W_CMD1_addr, cmd);
if (ret < 0)
- pr_err(
- "[LS][CM3217 error]%s: set auto light sensor fail\n",
- __func__);
+ pr_err("[LS][CM3217 error]%s: set auto light sensor fail\n",
+ __func__);
else {
- msleep(50);/*wait for 50 ms for the first report adc*/
- /* report an invalid value first to ensure we
- * trigger an event when adc_level is zero.
- */
+ msleep(50); /* wait for 50 ms for the first report adc */
+ /* report an invalid value first to ensure we
+ * trigger an event when adc_level is zero.
+ */
input_report_abs(lpi->ls_input_dev, ABS_MISC, -1);
input_sync(lpi->ls_input_dev);
- report_lsensor_input_event(lpi, 1);/*resume, IOCTL and DEVICE_ATTR*/
- lpi->als_enable = 1;
+ /* resume, IOCTL and DEVICE_ATTR */
+ report_lsensor_input_event(lpi, 1);
+ lpi->als_enable = 1;
}
- queue_delayed_work(lpi->lp_wq, &report_work, lpi->polling_delay);
- lpi->als_enable=1;
+
+ queue_delayed_work(lpi->lp_wq, &report_work, lpi->polling_delay);
+ lpi->als_enable = 1;
+
mutex_unlock(&als_enable_mutex);
-
+
return ret;
}
@@ -395,18 +412,20 @@ static int lightsensor_disable(struct cm3217_info *lpi)
D("[LS][CM3217] %s\n", __func__);
cmd = (CM3217_ALS_IT_2_T | CM3217_ALS_BIT5_Default_1 |
- CM3217_ALS_WDM_DEFAULT_1 | CM3217_ALS_SD);
+ CM3217_ALS_WDM_DEFAULT_1 | CM3217_ALS_SD);
ret = _cm3217_I2C_Write_Byte(ALS_W_CMD1_addr, cmd);
if (ret < 0)
pr_err("[LS][CM3217 error]%s: disable auto light sensor fail\n",
- __func__);
+ __func__);
else {
lpi->als_enable = 0;
}
- cancel_delayed_work(&report_work);
- lpi->als_enable=0;
+
+ cancel_delayed_work(&report_work);
+ lpi->als_enable = 0;
+
mutex_unlock(&als_disable_mutex);
-
+
return ret;
}
@@ -421,6 +440,7 @@ static int lightsensor_open(struct inode *inode, struct file *file)
rc = -EBUSY;
}
lpi->lightsensor_opened = 1;
+
return rc;
}
@@ -430,16 +450,17 @@ static int lightsensor_release(struct inode *inode, struct file *file)
D("[LS][CM3217] %s\n", __func__);
lpi->lightsensor_opened = 0;
+
return 0;
}
static long lightsensor_ioctl(struct file *file, unsigned int cmd,
- unsigned long arg)
+ unsigned long arg)
{
int rc, val;
struct cm3217_info *lpi = lp_info;
- /*D("[CM3217] %s cmd %d\n", __func__, _IOC_NR(cmd));*/
+ /* D("[CM3217] %s cmd %d\n", __func__, _IOC_NR(cmd)); */
switch (cmd) {
case LIGHTSENSOR_IOCTL_ENABLE:
@@ -448,18 +469,20 @@ static long lightsensor_ioctl(struct file *file, unsigned int cmd,
break;
}
D("[LS][CM3217] %s LIGHTSENSOR_IOCTL_ENABLE, value = %d\n",
- __func__, val);
+ __func__, val);
rc = val ? lightsensor_enable(lpi) : lightsensor_disable(lpi);
break;
+
case LIGHTSENSOR_IOCTL_GET_ENABLED:
val = lpi->als_enable;
D("[LS][CM3217] %s LIGHTSENSOR_IOCTL_GET_ENABLED, enabled %d\n",
- __func__, val);
+ __func__, val);
rc = put_user(val, (unsigned long __user *)arg);
break;
+
default:
pr_err("[LS][CM3217 error]%s: invalid cmd %d\n",
- __func__, _IOC_NR(cmd));
+ __func__, _IOC_NR(cmd));
rc = -EINVAL;
}
@@ -480,15 +503,16 @@ static struct miscdevice lightsensor_misc = {
};
static ssize_t ls_adc_show(struct device *dev,
- struct device_attribute *attr, char *buf)
+ struct device_attribute *attr, char *buf)
{
int ret;
struct cm3217_info *lpi = lp_info;
- D("[LS][CM3217] %s: ADC = 0x%04X, Level = %d \n",
- __func__, lpi->current_adc, lpi->current_level);
+ D("[LS][CM3217] %s: ADC = 0x%04X, Level = %d\n",
+ __func__, lpi->current_adc, lpi->current_level);
+
ret = sprintf(buf, "ADC[0x%04X] => level %d\n",
- lpi->current_adc, lpi->current_level);
+ lpi->current_adc, lpi->current_level);
return ret;
}
@@ -496,20 +520,19 @@ static ssize_t ls_adc_show(struct device *dev,
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)
+ struct device_attribute *attr, char *buf)
{
int ret = 0;
struct cm3217_info *lpi = lp_info;
- ret = sprintf(buf, "Light sensor Auto Enable = %d\n",
- lpi->als_enable);
+ ret = sprintf(buf, "Light sensor Auto Enable = %d\n", lpi->als_enable);
return ret;
}
static ssize_t ls_enable_store(struct device *dev,
- struct device_attribute *attr,
- const char *buf, size_t count)
+ struct device_attribute *attr,
+ const char *buf, size_t count)
{
int ret = 0;
int ls_auto;
@@ -518,78 +541,82 @@ static ssize_t ls_enable_store(struct device *dev,
ls_auto = -1;
sscanf(buf, "%d", &ls_auto);
- if (ls_auto != 0 && ls_auto != 1 )
+ if (ls_auto != 0 && ls_auto != 1)
return -EINVAL;
- if (ls_auto) {
+ if (ls_auto)
ret = lightsensor_enable(lpi);
- } else {
+ else
ret = lightsensor_disable(lpi);
- }
- D("[LS][CM3217] %s: lpi->als_enable = %d, lpi->ls_calibrate = %d, ls_auto=%d\n",
- __func__, lpi->als_enable, lpi->ls_calibrate, ls_auto);
+ D("[LS][CM3217] %s: lpi->als_enable = %d, lpi->ls_calibrate = %d, "
+ "ls_auto=%d\n", __func__, lpi->als_enable, lpi->ls_calibrate,
+ ls_auto);
if (ret < 0)
- pr_err(
- "[LS][CM3217 error]%s: set auto light sensor fail\n",
- __func__);
+ pr_err("[LS][CM3217 error]%s: set auto light sensor fail\n",
+ __func__);
return count;
}
-static DEVICE_ATTR(ls_auto, 0664,
- ls_enable_show, ls_enable_store);
+static DEVICE_ATTR(ls_auto, 0664, ls_enable_show, ls_enable_store);
static ssize_t ls_kadc_show(struct device *dev,
- struct device_attribute *attr, char *buf)
+ struct device_attribute *attr, char *buf)
{
struct cm3217_info *lpi = lp_info;
int ret;
- ret = sprintf(buf, "kadc = 0x%x",
- lpi->als_kadc);
+ ret = sprintf(buf, "kadc = 0x%x", lpi->als_kadc);
return ret;
}
static ssize_t ls_kadc_store(struct device *dev,
- struct device_attribute *attr,
- const char *buf, size_t count)
+ struct device_attribute *attr,
+ const char *buf, size_t count)
{
struct cm3217_info *lpi = lp_info;
int kadc_temp = 0;
sscanf(buf, "%d", &kadc_temp);
- /*
- if (kadc_temp <= 0 || lpi->golden_adc <= 0) {
- printk(KERN_ERR "[LS][CM3217 error] %s: kadc_temp=0x%x, als_gadc=0x%x\n",
- __func__, kadc_temp, lpi->golden_adc);
+
+ /* if (kadc_temp <= 0 || lpi->golden_adc <= 0) {
+ printk(KERN_ERR "[LS][CM3217 error] %s: kadc_temp=0x%x, "
+ "als_gadc=0x%x\n", __func__, kadc_temp,
+ lpi->golden_adc);
return -EINVAL;
- }*/
+ } */
+
mutex_lock(&als_get_adc_mutex);
- if(kadc_temp != 0) {
+
+ if (kadc_temp != 0) {
lpi->als_kadc = kadc_temp;
- if( lpi->als_gadc != 0){
- if (lightsensor_update_table(lpi) < 0)
- printk(KERN_ERR "[LS][CM3217 error] %s: update ls table fail\n", __func__);
- } else {
- printk(KERN_INFO "[LS]%s: als_gadc =0x%x wait to be set\n",
- __func__, lpi->als_gadc);
- }
+ if (lpi->als_gadc != 0) {
+ if (lightsensor_update_table(lpi) < 0)
+ printk(KERN_ERR
+ "[LS][CM3217 error] %s: "
+ "update ls table fail\n", __func__);
+ } else {
+ printk(KERN_INFO
+ "[LS]%s: als_gadc =0x%x wait to be set\n",
+ __func__, lpi->als_gadc);
+ }
} else {
printk(KERN_INFO "[LS]%s: als_kadc can't be set to zero\n",
- __func__);
+ __func__);
}
-
+
mutex_unlock(&als_get_adc_mutex);
+
return count;
}
static DEVICE_ATTR(ls_kadc, 0664, ls_kadc_show, ls_kadc_store);
static ssize_t ls_gadc_show(struct device *dev,
- struct device_attribute *attr, char *buf)
+ struct device_attribute *attr, char *buf)
{
struct cm3217_info *lpi = lp_info;
int ret;
@@ -600,158 +627,185 @@ static ssize_t ls_gadc_show(struct device *dev,
}
static ssize_t ls_gadc_store(struct device *dev,
- struct device_attribute *attr,
- const char *buf, size_t count)
+ struct device_attribute *attr,
+ const char *buf, size_t count)
{
struct cm3217_info *lpi = lp_info;
int gadc_temp = 0;
sscanf(buf, "%d", &gadc_temp);
- /*if (gadc_temp <= 0 || lpi->golden_adc <= 0) {
- printk(KERN_ERR "[LS][CM3217 error] %s: kadc_temp=0x%x, als_gadc=0x%x\n",
- __func__, kadc_temp, lpi->golden_adc);
+
+ /* if (gadc_temp <= 0 || lpi->golden_adc <= 0) {
+ printk(KERN_ERR "[LS][CM3217 error] %s: kadc_temp=0x%x, "
+ "als_gadc=0x%x\n", __func__, kadc_temp,
+ lpi->golden_adc);
return -EINVAL;
- }*/
-
+ } */
+
mutex_lock(&als_get_adc_mutex);
- if(gadc_temp != 0) {
+
+ if (gadc_temp != 0) {
lpi->als_gadc = gadc_temp;
- if( lpi->als_kadc != 0){
- if (lightsensor_update_table(lpi) < 0)
- printk(KERN_ERR "[LS][CM3217 error] %s: update ls table fail\n", __func__);
- } else {
- printk(KERN_INFO "[LS]%s: als_kadc =0x%x wait to be set\n",
- __func__, lpi->als_kadc);
- }
+ if (lpi->als_kadc != 0) {
+ if (lightsensor_update_table(lpi) < 0)
+ printk(KERN_ERR
+ "[LS][CM3217 error] %s: "
+ "update ls table fail\n", __func__);
+ } else {
+ printk(KERN_INFO
+ "[LS]%s: als_kadc =0x%x wait to be set\n",
+ __func__, lpi->als_kadc);
+ }
} else {
printk(KERN_INFO "[LS]%s: als_gadc can't be set to zero\n",
- __func__);
+ __func__);
}
+
mutex_unlock(&als_get_adc_mutex);
+
return count;
}
static DEVICE_ATTR(ls_gadc, 0664, ls_gadc_show, ls_gadc_store);
static ssize_t ls_adc_table_show(struct device *dev,
- struct device_attribute *attr, char *buf)
+ struct device_attribute *attr, char *buf)
{
unsigned length = 0;
int i;
for (i = 0; i < 10; i++) {
length += sprintf(buf + length,
- "[CM3217]Get adc_table[%d] = 0x%x ; %d, Get cali_table[%d] = 0x%x ; %d, \n",
- i, *(lp_info->adc_table + i),
- *(lp_info->adc_table + i),
- i, *(lp_info->cali_table + i),
- *(lp_info->cali_table + i));
+ "[CM3217]Get adc_table[%d] = 0x%x ; %d, "
+ "Get cali_table[%d] = 0x%x ; %d,\n",
+ i, *(lp_info->adc_table + i),
+ *(lp_info->adc_table + i),
+ i, *(lp_info->cali_table + i),
+ *(lp_info->cali_table + i));
}
+
return length;
}
static ssize_t ls_adc_table_store(struct device *dev,
- struct device_attribute *attr,
- const char *buf, size_t count)
+ struct device_attribute *attr,
+ const char *buf, size_t count)
{
-
struct cm3217_info *lpi = lp_info;
char *token[10];
- uint16_t tempdata[10];
- int i;
+ unsigned long tempdata[10];
+ int i, r;
printk(KERN_INFO "[LS][CM3217]%s\n", buf);
for (i = 0; i < 10; i++) {
token[i] = strsep((char **)&buf, " ");
- tempdata[i] = simple_strtoul(token[i], NULL, 16);
- if (tempdata[i] < 1 || tempdata[i] > 0xffff) {
+ r = kstrtoul(token[i], 16, &tempdata[i]);
+ if (tempdata[i] < 1 || tempdata[i] > 0xffff || r) {
printk(KERN_ERR
- "[LS][CM3217 error] adc_table[%d] = 0x%x Err\n",
- i, tempdata[i]);
+ "[LS][CM3217 error] adc_table[%d] = "
+ "0x%lx Err\n", i, tempdata[i]);
return count;
}
}
+
mutex_lock(&als_get_adc_mutex);
+
for (i = 0; i < 10; i++) {
lpi->adc_table[i] = tempdata[i];
printk(KERN_INFO
- "[LS][CM3217]Set lpi->adc_table[%d] = 0x%x\n",
- i, *(lp_info->adc_table + i));
+ "[LS][CM3217]Set lpi->adc_table[%d] = 0x%x\n",
+ i, *(lp_info->adc_table + i));
}
if (lightsensor_update_table(lpi) < 0)
printk(KERN_ERR "[LS][CM3217 error] %s: update ls table fail\n",
- __func__);
+ __func__);
+
mutex_unlock(&als_get_adc_mutex);
+
D("[LS][CM3217] %s\n", __func__);
return count;
}
-static DEVICE_ATTR(ls_adc_table, 0664,
- ls_adc_table_show, ls_adc_table_store);
+static DEVICE_ATTR(ls_adc_table, 0664, ls_adc_table_show, ls_adc_table_store);
+
+static uint8_t ALS_CONF1;
-static uint8_t ALS_CONF1 = 0;
static ssize_t ls_conf1_show(struct device *dev,
- struct device_attribute *attr, char *buf)
+ struct device_attribute *attr, char *buf)
{
return sprintf(buf, "ALS_CONF1 = %x\n", ALS_CONF1);
}
+
static ssize_t ls_conf1_store(struct device *dev,
- struct device_attribute *attr,
- const char *buf, size_t count)
+ struct device_attribute *attr,
+ const char *buf, size_t count)
{
int value = 0;
+
sscanf(buf, "0x%x", &value);
ALS_CONF1 = value;
printk(KERN_INFO "[LS]set ALS_CONF1 = %x\n", ALS_CONF1);
_cm3217_I2C_Write_Byte(ALS_W_CMD1_addr, ALS_CONF1);
+
return count;
}
+
static DEVICE_ATTR(ls_conf1, 0664, ls_conf1_show, ls_conf1_store);
-static uint8_t ALS_CONF2 = 0;
+static uint8_t ALS_CONF2;
static ssize_t ls_conf2_show(struct device *dev,
- struct device_attribute *attr, char *buf)
+ struct device_attribute *attr, char *buf)
{
return sprintf(buf, "ALS_CONF2 = %x\n", ALS_CONF2);
}
+
static ssize_t ls_conf2_store(struct device *dev,
- struct device_attribute *attr,
- const char *buf, size_t count)
+ struct device_attribute *attr,
+ const char *buf, size_t count)
{
int value = 0;
+
sscanf(buf, "0x%x", &value);
ALS_CONF2 = value;
printk(KERN_INFO "[LS]set ALS_CONF2 = %x\n", ALS_CONF2);
_cm3217_I2C_Write_Byte(ALS_W_CMD2_addr, ALS_CONF2);
+
return count;
}
+
static DEVICE_ATTR(ls_conf2, 0664, ls_conf2_show, ls_conf2_store);
static ssize_t ls_fLevel_show(struct device *dev,
- struct device_attribute *attr, char *buf)
+ struct device_attribute *attr, char *buf)
{
return sprintf(buf, "fLevel = %d\n", fLevel);
}
+
static ssize_t ls_fLevel_store(struct device *dev,
- struct device_attribute *attr,
- const char *buf, size_t count)
+ struct device_attribute *attr,
+ const char *buf, size_t count)
{
struct cm3217_info *lpi = lp_info;
- int value=0;
+ int value = 0;
+
sscanf(buf, "%d", &value);
- (value>=0)?(value=min(value,10)):(value=max(value,-1));
- fLevel=value;
+ (value >= 0) ? (value = min(value, 10)) : (value = max(value, -1));
+ fLevel = value;
+
input_report_abs(lpi->ls_input_dev, ABS_MISC, fLevel);
input_sync(lpi->ls_input_dev);
+
printk(KERN_INFO "[LS]set fLevel = %d\n", fLevel);
msleep(1000);
- fLevel=-1;
+ fLevel = -1;
+
return count;
}
+
static DEVICE_ATTR(ls_flevel, 0664, ls_fLevel_show, ls_fLevel_store);
static int lightsensor_setup(struct cm3217_info *lpi)
@@ -760,9 +814,8 @@ static int lightsensor_setup(struct cm3217_info *lpi)
lpi->ls_input_dev = input_allocate_device();
if (!lpi->ls_input_dev) {
- pr_err(
- "[LS][CM3217 error]%s: could not allocate ls input device\n",
- __func__);
+ pr_err("[LS][CM3217 error]%s: "
+ "could not allocate ls input device\n", __func__);
return -ENOMEM;
}
lpi->ls_input_dev->name = "cm3217-ls";
@@ -771,15 +824,15 @@ static int lightsensor_setup(struct cm3217_info *lpi)
ret = input_register_device(lpi->ls_input_dev);
if (ret < 0) {
- pr_err("[LS][CM3217 error]%s: can not register ls input device\n",
- __func__);
+ pr_err("[LS][CM3217 error]%s: "
+ "can not register ls input device\n", __func__);
goto err_free_ls_input_device;
}
ret = misc_register(&lightsensor_misc);
if (ret < 0) {
- pr_err("[LS][CM3217 error]%s: can not register ls misc device\n",
- __func__);
+ pr_err("[LS][CM3217 error]%s: "
+ "can not register ls misc device\n", __func__);
goto err_unregister_ls_input_device;
}
@@ -799,11 +852,14 @@ static int cm3217_setup(struct cm3217_info *lpi)
als_power(1);
msleep(5);
- ret = _cm3217_I2C_Write_Byte(ALS_W_CMD2_addr, CM3217_ALS_WDM_DEFAULT_1 |CM3217_ALS_IT_2_T|CM3217_ALS_BIT5_Default_1);
- if(ret<0)
- return ret;
-
- ret = _cm3217_I2C_Write_Byte(ALS_W_CMD2_addr, CM3217_ALS_IT_100ms);
+ ret = _cm3217_I2C_Write_Byte(ALS_W_CMD2_addr,
+ CM3217_ALS_WDM_DEFAULT_1
+ | CM3217_ALS_IT_2_T
+ | CM3217_ALS_BIT5_Default_1);
+ if (ret < 0)
+ return ret;
+
+ ret = _cm3217_I2C_Write_Byte(ALS_W_CMD2_addr, CM3217_ALS_IT_100ms);
msleep(10);
return ret;
@@ -830,7 +886,7 @@ static void cm3217_late_resume(struct early_suspend *h)
}
static int cm3217_probe(struct i2c_client *client,
- const struct i2c_device_id *id)
+ const struct i2c_device_id *id)
{
int ret = 0;
struct cm3217_info *lpi;
@@ -838,18 +894,17 @@ static int cm3217_probe(struct i2c_client *client,
D("[CM3217] %s\n", __func__);
-
lpi = kzalloc(sizeof(struct cm3217_info), GFP_KERNEL);
if (!lpi)
return -ENOMEM;
- /*D("[CM3217] %s: client->irq = %d\n", __func__, client->irq);*/
+ /* D("[CM3217] %s: client->irq = %d\n", __func__, client->irq); */
lpi->i2c_client = client;
pdata = client->dev.platform_data;
if (!pdata) {
pr_err("[CM3217 error]%s: Assign platform_data error!!\n",
- __func__);
+ __func__);
ret = -EBUSY;
goto err_platform_data_null;
}
@@ -872,27 +927,27 @@ static int cm3217_probe(struct i2c_client *client,
ret = lightsensor_setup(lpi);
if (ret < 0) {
pr_err("[LS][CM3217 error]%s: lightsensor_setup error!!\n",
- __func__);
+ __func__);
goto err_lightsensor_setup;
}
-
- //SET LUX STEP FACTOR HERE
- // if adc raw value one step = 0.3 lux
- // the following will set the factor 0.3 = 3/10
- // and lpi->golden_adc = 3;
- // set als_kadc = (ALS_CALIBRATED <<16) | 10;
-
- als_kadc = (ALS_CALIBRATED <<16) | 10;
- lpi->golden_adc = 3;
-
- //ls calibrate always set to 1
- lpi->ls_calibrate = 1;
-
+
+ /* SET LUX STEP FACTOR HERE
+ * if adc raw value one step = 0.3 lux
+ * the following will set the factor 0.3 = 3/10
+ * and lpi->golden_adc = 3;
+ * set als_kadc = (ALS_CALIBRATED <<16) | 10; */
+
+ als_kadc = (ALS_CALIBRATED << 16) | 10;
+ lpi->golden_adc = 3;
+
+ /* ls calibrate always set to 1 */
+ lpi->ls_calibrate = 1;
+
lightsensor_set_kvalue(lpi);
ret = lightsensor_update_table(lpi);
if (ret < 0) {
pr_err("[LS][CM3217 error]%s: update ls table fail\n",
- __func__);
+ __func__);
goto err_lightsensor_update_table;
}
@@ -905,7 +960,8 @@ static int cm3217_probe(struct i2c_client *client,
ret = cm3217_setup(lpi);
if (ret < 0) {
- pr_err("[ERR][CM3217 error]%s: cm3217_setup error!\n", __func__);
+ pr_err("[ERR][CM3217 error]%s: cm3217_setup error!\n",
+ __func__);
goto err_cm3217_setup;
}
@@ -917,7 +973,7 @@ static int cm3217_probe(struct i2c_client *client,
}
lpi->ls_dev = device_create(lpi->cm3217_class,
- NULL, 0, "%s", "lightsensor");
+ NULL, 0, "%s", "lightsensor");
if (unlikely(IS_ERR(lpi->ls_dev))) {
ret = PTR_ERR(lpi->ls_dev);
lpi->ls_dev = NULL;
@@ -959,13 +1015,12 @@ static int cm3217_probe(struct i2c_client *client,
if (ret)
goto err_create_ls_device_file;
- lpi->early_suspend.level =
- EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
+ lpi->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
lpi->early_suspend.suspend = cm3217_early_suspend;
lpi->early_suspend.resume = cm3217_late_resume;
register_early_suspend(&lpi->early_suspend);
- lpi->als_enable=0;
+ lpi->als_enable = 0;
D("[CM3217] %s: Probe success!\n", __func__);
return ret;
@@ -984,7 +1039,7 @@ err_cm3217_setup:
input_free_device(lpi->ls_input_dev);
err_create_singlethread_workqueue:
err_lightsensor_update_table:
- misc_deregister(&lightsensor_misc);
+ misc_deregister(&lightsensor_misc);
err_lightsensor_setup:
err_platform_data_null:
kfree(lpi);
@@ -1021,5 +1076,3 @@ module_exit(cm3217_exit);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("CM3217 Driver");
MODULE_AUTHOR("Frank Hsieh <pengyueh@gmail.com>");
-
-