diff options
author | Vishnudev Ramakrishnan <vramakri@sta.samsung.com> | 2011-07-01 16:02:38 -0700 |
---|---|---|
committer | Arve Hjønnevåg <arve@android.com> | 2011-11-17 17:54:41 -0800 |
commit | 7913941122fe09636297da3b656d4af4e46d952a (patch) | |
tree | 83245e243008b45967595c7abbc3e691b8bec5b6 | |
parent | b0e6fc0f12ce4c2fc27f4aa7c07c0bd4c31ab7e4 (diff) | |
download | kernel_samsung_aries-7913941122fe09636297da3b656d4af4e46d952a.zip kernel_samsung_aries-7913941122fe09636297da3b656d4af4e46d952a.tar.gz kernel_samsung_aries-7913941122fe09636297da3b656d4af4e46d952a.tar.bz2 |
tuna: sensors: light sensor bug fixes
Fixed the following bugs in light sensor driver:
1. Eliminated error values from being considered as valid light values
2. Fix an off-by-one error in the averaging buffer
Change-Id: I7ec86ab0d3e423a0e736406c4f786d2933cb7e8d
Signed-off-by: Vishnudev Ramakrishnan <vramakri@sta.samsung.com>
-rw-r--r-- | drivers/input/misc/gp2a.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/drivers/input/misc/gp2a.c b/drivers/input/misc/gp2a.c index 1cd501e..04db6ed 100644 --- a/drivers/input/misc/gp2a.c +++ b/drivers/input/misc/gp2a.c @@ -312,8 +312,12 @@ static int lightsensor_get_adcvalue(struct gp2a_data *gp2a) unsigned int adc_min = 0; int value = 0; - /* get ADC */ + /* get ADC value */ value = gp2a->pdata->light_adc_value(); + if (value < 0) { + pr_err("adc returned error %d\n", value); + return value; + } gp2a_dbgmsg("adc returned light value %d\n", value); adc_index = (gp2a->adc_index_count++) % ADC_BUFFER_NUM; @@ -340,7 +344,7 @@ static int lightsensor_get_adcvalue(struct gp2a_data *gp2a) } adc_avr_value = (adc_total-(adc_max+adc_min))/(ADC_BUFFER_NUM-2); - if (gp2a->adc_index_count == ADC_BUFFER_NUM-1) + if (gp2a->adc_index_count == ADC_BUFFER_NUM) gp2a->adc_index_count = 0; gp2a_dbgmsg("average adc light value %d\n", adc_avr_value); @@ -352,8 +356,10 @@ static void gp2a_work_func_light(struct work_struct *work) struct gp2a_data *gp2a = container_of(work, struct gp2a_data, work_light); int adc = lightsensor_get_adcvalue(gp2a); - input_report_abs(gp2a->light_input_dev, ABS_MISC, adc); - input_sync(gp2a->light_input_dev); + if (adc >= 0) { + input_report_abs(gp2a->light_input_dev, ABS_MISC, adc); + input_sync(gp2a->light_input_dev); + } } /* This function is for light sensor. It operates every a few seconds. |