summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorNick Vaccaro <nvaccaro@google.com>2019-05-07 12:48:56 -0700
committerchrome-bot <chrome-bot@chromium.org>2019-05-09 16:05:59 -0700
commit2d38e7cd712834d763ff59704cd04af2a95b8367 (patch)
tree25b44b030408b514217b9c91e08fd1fe9696ae88 /driver
parentd600316362ef86d893d0f65db73e962184d8c3ce (diff)
downloadchrome-ec-2d38e7cd712834d763ff59704cd04af2a95b8367.tar.gz
tcs3400: rename tcs3400_drv_data_t to als_drv_data_t
- rename tsc3400_drv_data_t to als_drv_data_t - change tcs3400 driver to use common als_drv_data_t - change flapjack config to use common als_drv_data_t - rename TSC3400_SCALE() macro to ALS_CHANNEL_SCALE() - create and use new I2C_PORT_ALS definition - fix a couple nits BUG=b:124512628 BRANCH=master TEST=build and flash to flapjack, verify ALS and RGB still work. Change-Id: I9a45d255ff77794ef34026406c9b702a04e09c11 Signed-off-by: Nick Vaccaro <nvaccaro@google.com> Reviewed-on: https://chromium-review.googlesource.com/1601052 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r--driver/als_tcs3400.c38
-rw-r--r--driver/als_tcs3400.h22
2 files changed, 30 insertions, 30 deletions
diff --git a/driver/als_tcs3400.c b/driver/als_tcs3400.c
index e821b6bb9c..213e5424fd 100644
--- a/driver/als_tcs3400.c
+++ b/driver/als_tcs3400.c
@@ -70,7 +70,7 @@ static int tcs3400_post_events(struct motion_sensor_t *s, uint32_t last_ts)
* routine will only get called from ALS sensor driver.
*/
struct motion_sensor_t *rgb_s = s + 1;
- struct tcs3400_drv_data_t *drv_data = TCS3400_DRV_DATA(s);
+ struct als_drv_data_t *drv_data = TCS3400_DRV_DATA(s);
struct tcs3400_rgb_drv_data_t *rgb_drv_data =
TCS3400_RGB_DRV_DATA(rgb_s);
struct ec_response_motion_sensor_data vector;
@@ -153,7 +153,7 @@ skip_clear_vector_load:
rgb_data[i] = ((light_data[index] << 8) | light_data[index-1]);
rgb_data[i] += rgb_drv_data->rgb_cal[i].offset;
- rgb_data[i] *= rgb_drv_data->rgb_cal[i].scale / BIT(15);
+ rgb_data[i] *= rgb_drv_data->rgb_cal[i].scale >> 15;
rgb_data[i] = rgb_data[i] * rgb_drv_data->device_scale +
rgb_data[i] * rgb_drv_data->device_uscale / 10000;
@@ -194,7 +194,6 @@ skip_vector_load:
vector.sensor_num = rgb_s - motion_sensors;
motion_sense_fifo_add_data(&vector, rgb_s, 3, last_ts);
}
-
return EC_SUCCESS;
}
@@ -235,7 +234,6 @@ static int tcs3400_irq_handler(struct motion_sensor_t *s, uint32_t *event)
if ((status & TCS_I2C_STATUS_RGBC_VALID) ||
((status & TCS_I2C_STATUS_ALS_IRQ) &&
(status & TCS_I2C_STATUS_ALS_VALID))) {
-
ret = tcs3400_post_events(s, last_interrupt_timestamp);
if (ret)
return ret;
@@ -401,26 +399,28 @@ static int tcs3400_init(const struct motion_sensor_t *s)
{
/*
* These are default power-on register values with two exceptions:
- * Set ATIME = 0x4 (700.88ms)
+ * Set ATIME = 0 (712 ms)
* Set AGAIN = 16 (0x10) (AGAIN is in CONTROL register)
*/
const struct reg_data {
uint8_t reg;
uint8_t data;
- } defaults[] = { { TCS_I2C_ENABLE, 0 },
- { TCS_I2C_ATIME, 0x4 },
- { TCS_I2C_WTIME, 0xFF },
- { TCS_I2C_AILTL, 0 },
- { TCS_I2C_AILTH, 0 },
- { TCS_I2C_AIHTL, 0 },
- { TCS_I2C_AIHTH, 0 },
- { TCS_I2C_PERS, 0 },
- { TCS_I2C_CONFIG, 0x40 },
- { TCS_I2C_CONTROL, 0x10 },
- { TCS_I2C_AUX, 0 },
- { TCS_I2C_IR, 0 },
- { TCS_I2C_CICLEAR, 0 },
- { TCS_I2C_AICLEAR, 0 } };
+ } defaults[] = {
+ { TCS_I2C_ENABLE, 0 },
+ { TCS_I2C_ATIME, TCS_DEFAULT_ATIME },
+ { TCS_I2C_WTIME, 0xFF },
+ { TCS_I2C_AILTL, 0 },
+ { TCS_I2C_AILTH, 0 },
+ { TCS_I2C_AIHTL, 0 },
+ { TCS_I2C_AIHTH, 0 },
+ { TCS_I2C_PERS, 0 },
+ { TCS_I2C_CONFIG, 0x40 },
+ { TCS_I2C_CONTROL, (TCS_DEFAULT_AGAIN & TCS_I2C_CONTROL_MASK)},
+ { TCS_I2C_AUX, 0 },
+ { TCS_I2C_IR, 0 },
+ { TCS_I2C_CICLEAR, 0 },
+ { TCS_I2C_AICLEAR, 0 }
+ };
int data = 0;
int ret;
diff --git a/driver/als_tcs3400.h b/driver/als_tcs3400.h
index f695fdb387..1e53b83954 100644
--- a/driver/als_tcs3400.h
+++ b/driver/als_tcs3400.h
@@ -63,6 +63,7 @@ enum tcs3400_mode {
TCS_I2C_ENABLE_INT_ENABLE),
};
+#define TCS_I2C_CONTROL_MASK 0x03
#define TCS_I2C_STATUS_RGBC_VALID BIT(0)
#define TCS_I2C_STATUS_ALS_IRQ BIT(4)
#define TCS_I2C_STATUS_ALS_VALID BIT(7)
@@ -81,21 +82,20 @@ enum tcs3400_mode {
#error "EC too slow for light sensor"
#endif
-/* Individual channel scale value between 0 and 2 to a 32-bit value */
-#define TCS3400_SCALE(x) (x << 15)
-
-#define TCS3400_DRV_DATA(_s) ((struct tcs3400_drv_data_t *)(_s)->drv_data)
+#define TCS3400_DRV_DATA(_s) ((struct als_drv_data_t *)(_s)->drv_data)
#define TCS3400_RGB_DRV_DATA(_s) \
((struct tcs3400_rgb_drv_data_t *)(_s)->drv_data)
-/* Private tcs3400 als driver data */
-struct tcs3400_drv_data_t {
- int rate; /* holds current sensor rate */
- int last_value; /* holds last als clear channel value */
- struct als_calibration_t als_cal; /* calibration data */
-};
+/* NOTE: The higher the ATIME value in reg, the shorter the accumulation time */
+#define TCS_MIN_ATIME 0x00 /* 712 ms */
+#define TCS_MAX_ATIME 0x70 /* 400 ms */
+#define TCS_DEFAULT_ATIME TCS_MIN_ATIME /* 712 ms */
+
+#define TCS_MIN_AGAIN 0x00 /* 1x gain */
+#define TCS_MAX_AGAIN 0x03 /* 64x gain */
+#define TCS_DEFAULT_AGAIN 0x02 /* 16x gain */
-/* Private tcs3400 rgb driver data */
+/* tcs3400 rgb als driver data */
struct tcs3400_rgb_drv_data_t {
/*
* device_scale and device_uscale are used to adjust raw rgb channel