From 5da6583e8e71292881bd13f7fd3174fdcc056191 Mon Sep 17 00:00:00 2001 From: Leo Yan Date: Thu, 26 Apr 2012 08:54:36 +0800 Subject: [PATCH] misc/apds990x: Reduce the IR factor when CH1/CH0 ratio is abnormal BZ: 31055 31056 The lux equation in the apds990x datasheet assume the light source is far from the sensor and CH1/CH0 ratio is always below than 0.3. If the ratio is out of range, it means an abnormal incandescent light source is very close to the sensor. In this case, the lux equation doesn't work and we need to reduce the IR factor to get the correct lux value. Change-Id: I59b967bf775fbb3a46591728952688811c6347eb Signed-off-by: Leo Yan Reviewed-on: http://android.intel.com:8080/46184 Reviewed-by: Chen, Jie D Reviewed-by: Wang, Zhifeng Reviewed-by: Du, Alek Reviewed-by: Tang, HaifengX Tested-by: Wang, Zhifeng Reviewed-by: buildbot Tested-by: buildbot --- drivers/misc/apds990x.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/misc/apds990x.c b/drivers/misc/apds990x.c index 2b23cef..f9c83f7 100644 --- a/drivers/misc/apds990x.c +++ b/drivers/misc/apds990x.c @@ -3,9 +3,11 @@ * Chip is combined proximity and ambient light sensor. * * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). - * * Contact: Samu Onkalo * + * Copyright (C) 2012 Intel Corporation + * Contact: Leo Yan + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. @@ -115,6 +117,8 @@ #define APDS_PDIODE_IR 0x2 #define APDS990X_LUX_OUTPUT_SCALE 10 +#define APDS990X_CH1_CH0_ABN_RATIO 1229 +#define APDS990X_CH1_CH0_MAX_RATIO 2253 #define APDS_POWER_DOWN (0) #define APDS_POWER_ON (1) @@ -462,6 +466,28 @@ static int apds990x_get_lux(struct apds990x_chip *chip, int clear, int ir) { int iac, iac1, iac2; /* IR adjusted counts */ u32 lpc; /* Lux per count */ + int ratio, irfactor; + + if (clear == 0) + return 0; + /* If CH1/CH0 > 0.3 that means an abnormal incandescent light source + * is detected and is very close to the sensor, we need to reduce the + * IR factor to get the correct lux value + * Formulas: + * ratio = CH1/CH0 + * IR Factor = 1 - (6/11 * ratio) when 0.3 < ratio < 0.55 + * IR Factor = 0 when ratio >= 0.55 + */ + ratio = (ir * APDS_PARAM_SCALE) / clear; + if (ratio > APDS990X_CH1_CH0_ABN_RATIO) { + if (ratio >= APDS990X_CH1_CH0_MAX_RATIO) + irfactor = 0; + else + irfactor = APDS_PARAM_SCALE - 6 * ratio / 11; + + ir = ir * irfactor / APDS_PARAM_SCALE; + chip->lux_ir = ir; + } /* Formulas: * iac1 = CF1 * CLEAR_CH - IRF1 * IR_CH -- 2.7.4