misc: max9635: add lens coefficient
authormakarand.karvekar <makarand.karvekar@motorola.com>
Wed, 6 Oct 2010 21:00:16 +0000 (16:00 -0500)
committerRebecca Schultz Zavin <rebecca@android.com>
Thu, 7 Oct 2010 20:38:19 +0000 (13:38 -0700)
lens coefficient compensates for the lost light
filtered by glass lens covering als.
light thresholds maintained high for continuous reporting.
switch to EV_MSC event for 0 lux reporting.

Change-Id: Ia891e678c0d2d622d40cc4b9748ccae165ba2656
Signed-off-by: makarand.karvekar <makarand.karvekar@motorola.com>
drivers/misc/max9635.c
include/linux/max9635.h

index 5acdc1ab4e9506dcbb01d4323aecda32e823db19..505457edfccd7c62c0f410e4908c4cea7fe20ddd 100644 (file)
@@ -214,7 +214,6 @@ static int max9635_read_adj_als(struct max9635_data *als_data)
 {
        int ret;
        int lux = 0;
-       u8 buf[2] = { MAX9635_ALS_DATA_H, 0 };
        u8 low_buf = MAX9635_ALS_DATA_L;
        u8 high_buf = MAX9635_ALS_DATA_H;
        u8 exponent;
@@ -241,40 +240,18 @@ static int max9635_read_adj_als(struct max9635_data *als_data)
                pr_info("exp = 0x%X, mant = 0x%X, lux = %d\n",
                        exponent, mantissa, lux);
 
-       /* lux can be in the range of 0 to 208896, per maxim */
-       if (lux == 0)
-               lux += 1;
-       if (lux == 208896)
-               lux -= 1;
-
-       buf[0] = (AUTO_INCREMENT | MAX9635_ALS_THRESH_L);
-       buf[1] = lux - 1;
-       ret = max9635_write_reg(als_data, buf, 1);
-       if (ret != 0) {
-               pr_err("%s:Unable to write reg: %d\n", __func__, buf[0]);
-               return -1;
-       }
-       if (max9635_debug & 1)
-               pr_err("lower threshold = %d\n", buf[1]);
-
-       buf[0] = (AUTO_INCREMENT | MAX9635_ALS_THRESH_H);
-       buf[1] = lux + 1;
-       ret = max9635_write_reg(als_data, buf, 1);
-       if (ret != 0) {
-               pr_err("%s:Unable to write reg: %d\n", __func__, buf[0]);
-               return -1;
-       }
-       if (max9635_debug & 1)
-               pr_err("upper threshold = %d\n", buf[1]);
+       /* TODO: temporary lens coefficient adjustment, final
+                calculation pending on shipping lens profile. */
+       if (lux < 200)
+               lux = lux * als_data->als_pdata->lens_coeff_l;
+       else
+               lux = lux * als_data->als_pdata->lens_coeff_h;
 
        if (max9635_debug & 1)
                pr_info("%s:Reporting LUX %d\n", __func__, lux);
        return lux;
 }
 
-/* TO DO: Do we need to read the interrupt to clear the bit?
-Spec indicates that a read needs to be done to confirm it was this
-IC but does not indicate whether it is mandatory */
 static int max9635_report_input(struct max9635_data *als_data)
 {
        int ret = 0;
@@ -283,7 +260,7 @@ static int max9635_report_input(struct max9635_data *als_data)
 
        lux_val = max9635_read_adj_als(als_data);
        if (lux_val >= 0) {
-               input_event(als_data->idev, EV_LED, LED_MISC, lux_val);
+               input_event(als_data->idev, EV_MSC, MSC_RAW, lux_val);
                input_sync(als_data->idev);
        }
 
@@ -513,7 +490,6 @@ static int max9635_probe(struct i2c_client *client,
 
        als_data->idev->name = "max9635_als";
        input_set_capability(als_data->idev, EV_MSC, MSC_RAW);
-       input_set_capability(als_data->idev, EV_LED, LED_MISC);
 
        error = misc_register(&max9635_misc_device);
        if (error < 0) {
index 4968a6835e675361204fc1044e8b2045c307ff3f..aef416691dbe6ef7d9cad7fc91f194bcfa9ebfa1 100644 (file)
@@ -28,8 +28,8 @@ struct max9635_platform_data {
        u8 threshold_timer;
        u8 def_low_threshold;
        u8 def_high_threshold;
-       int (*power_on)(void);
-       int (*power_off)(void);
+       u8 lens_coeff_l;
+       u8 lens_coeff_h;
 };
 
 #endif /* __KERNEL__ */