summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2013-11-07 08:03:46 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2013-11-07 23:42:56 +0000
commitf23e68d721eb282619f1dd7b5b3ac4392234e6d4 (patch)
tree0aab4bd5d2134572087477d92aa52c24ca58c220
parentbb9b335e31cda78f4a0e7c3e546ffcc1499c989b (diff)
downloadchrome-ec-f23e68d721eb282619f1dd7b5b3ac4392234e6d4.tar.gz
Add ALS driver for light sensors connected to EC
This adds the driver and a console command to read an Intersil ISL29305 light sensor connected to the EC. BUG=chrome-os-partner:23380 BRANCH=samus TEST=manual Run the "als" command from the EC console, while pointing the sensor in various directions. It should give higher numbers when facing a light source. If you get "Error 1", it means the ALS isn't powered. Change-Id: I855ed64dab7fc60e29126ab3e97669be24dc6a64 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/176056
-rw-r--r--board/samus/board.c9
-rw-r--r--board/samus/board.h9
-rw-r--r--common/als.c45
-rw-r--r--common/build.mk1
-rw-r--r--driver/als_isl29035.c65
-rw-r--r--driver/als_isl29035.h13
-rw-r--r--driver/build.mk3
-rw-r--r--include/als.h32
-rw-r--r--include/config.h7
9 files changed, 184 insertions, 0 deletions
diff --git a/board/samus/board.c b/board/samus/board.c
index db8639acb9..d7f5b58e5f 100644
--- a/board/samus/board.c
+++ b/board/samus/board.c
@@ -4,12 +4,14 @@
*/
/* EC for Samus board configuration */
+#include "als.h"
#include "adc.h"
#include "adc_chip.h"
#include "backlight.h"
#include "chipset_x86_common.h"
#include "common.h"
#include "driver/temp_sensor/tmp006.h"
+#include "driver/als_isl29035.h"
#include "extpower.h"
#include "fan.h"
#include "gpio.h"
@@ -267,6 +269,13 @@ const struct temp_sensor_t temp_sensors[] = {
};
BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
+/* ALS instances. Must be in same order as enum als_id. */
+struct als_t als[] = {
+ {"ISL", isl29035_read_lux},
+};
+BUILD_ASSERT(ARRAY_SIZE(als) == ALS_COUNT);
+
+
/* Thermal limits for each temp sensor. All temps are in degrees K. Must be in
* same order as enum temp_sensor_id. To always ignore any temp, use 0.
*/
diff --git a/board/samus/board.h b/board/samus/board.h
index e32ee8beb3..8e124b066e 100644
--- a/board/samus/board.h
+++ b/board/samus/board.h
@@ -15,6 +15,8 @@
#undef HEY_USE_BUILTIN_CLKRUN
/* Optional features */
+#define CONFIG_ALS
+#define CONFIG_ALS_ISL29035
#define CONFIG_BOARD_VERSION
#define CONFIG_CHIPSET_X86
#define CONFIG_CHIPSET_CAN_THROTTLE
@@ -215,6 +217,13 @@ enum temp_sensor_id {
/* The number of TMP006 sensor chips on the board. */
#define TMP006_COUNT 6
+/* Light sensors attached to the EC. */
+enum als_id {
+ ALS_ISL29035 = 0,
+
+ ALS_COUNT,
+};
+
/* Known board versions for system_get_board_version(). */
enum board_version {
BOARD_VERSION_PROTO1 = 0,
diff --git a/common/als.c b/common/als.c
new file mode 100644
index 0000000000..bb2854132f
--- /dev/null
+++ b/common/als.c
@@ -0,0 +1,45 @@
+/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* This provides the interface for any Ambient Light Sensors that are connected
+ * to the EC instead of the AP.
+ */
+
+#include "als.h"
+#include "common.h"
+#include "console.h"
+#include "host_command.h"
+#include "util.h"
+
+int als_read(enum als_id id, int *lux)
+{
+ return als[id].read(lux);
+}
+
+/*****************************************************************************/
+/* Console commands */
+
+static int command_als(int argc, char **argv)
+{
+ int i, rv, val;
+
+ for (i = 0; i < ALS_COUNT; i++) {
+ ccprintf("%s: ", als[i].name);
+ rv = als_read(i, &val);
+ switch (rv) {
+ case EC_SUCCESS:
+ ccprintf("%d lux\n", val);
+ break;
+ default:
+ ccprintf("Error %d\n", rv);
+ }
+ }
+
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(als, command_als,
+ NULL,
+ "Print ALS values",
+ NULL);
diff --git a/common/build.mk b/common/build.mk
index 132fd62783..8cf26fab6e 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -10,6 +10,7 @@ common-y=main.o util.o console_output.o uart_buffering.o
common-y+=memory_commands.o shared_mem.o system.o hooks.o
common-y+=gpio.o version.o printf.o queue.o
+common-$(CONFIG_ALS)+=als.o
common-$(CONFIG_BACKLIGHT_LID)+=backlight_lid.o
# TODO(crosbug.com/p/23821): Why do these include battery_common but
# the other batteries don't? Perhaps should use CONFIG_CMD_BATTERY
diff --git a/driver/als_isl29035.c b/driver/als_isl29035.c
new file mode 100644
index 0000000000..13e5d77c14
--- /dev/null
+++ b/driver/als_isl29035.c
@@ -0,0 +1,65 @@
+/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Intersil ILS29035 light sensor driver
+ */
+
+#include "driver/als_isl29035.h"
+#include "common.h"
+#include "i2c.h"
+#include "timer.h"
+
+/* I2C interface */
+#define ILS29035_I2C_ADDR 0x88
+#define ILS29035_REG_COMMAND_I 0
+#define ILS29035_REG_COMMAND_II 1
+#define ILS29035_REG_DATA_LSB 2
+#define ILS29035_REG_DATA_MSB 3
+#define ILS29035_REG_INT_LT_LSB 4
+#define ILS29035_REG_INT_LT_MSB 5
+#define ILS29035_REG_INT_HT_LSB 6
+#define ILS29035_REG_INT_HT_MSB 7
+#define ILS29035_REG_ID 15
+
+int isl29035_read_lux(int *lux)
+{
+ int rv, lsb, msb, data;
+
+ /* Tell it to read once */
+ rv = i2c_write8(I2C_PORT_ALS, ILS29035_I2C_ADDR,
+ ILS29035_REG_COMMAND_I, 0x20);
+ if (rv)
+ return rv;
+
+ /* The highest precision (default) should take ~90ms */
+ usleep(100 * MSEC);
+
+ /* NOTE: It is necessary to read the LSB first, then the MSB. If you do
+ * it in the opposite order, the results are not correct. This is
+ * apparently an undocumented "feature".
+ */
+
+ /* Read lsb */
+ rv = i2c_read8(I2C_PORT_ALS, ILS29035_I2C_ADDR,
+ ILS29035_REG_DATA_LSB, &lsb);
+ if (rv)
+ return rv;
+
+ /* Read msb */
+ rv = i2c_read8(I2C_PORT_ALS, ILS29035_I2C_ADDR,
+ ILS29035_REG_DATA_MSB, &msb);
+ if (rv)
+ return rv;
+
+ data = (msb << 8) | lsb;
+
+ /*
+ * The default power-on values will give 16 bits of precision:
+ * 0x0000-0xffff indicates 0-1000 lux. If you change the defaults,
+ * you'll need to change the scale factor accordingly.
+ */
+ *lux = data * 1000 / 0xffff;
+
+ return EC_SUCCESS;
+}
diff --git a/driver/als_isl29035.h b/driver/als_isl29035.h
new file mode 100644
index 0000000000..8d3a4ac0f5
--- /dev/null
+++ b/driver/als_isl29035.h
@@ -0,0 +1,13 @@
+/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Intersil ILS29035 light sensor driver
+ */
+
+#ifndef __CROS_EC_ALS_ILS29035_H
+#define __CROS_EC_ALS_ILS29035_H
+
+int isl29035_read_lux(int *lux);
+
+#endif /* __CROS_EC_ALS_ILS29035_H */
diff --git a/driver/build.mk b/driver/build.mk
index 013cfb4159..59e27f1efa 100644
--- a/driver/build.mk
+++ b/driver/build.mk
@@ -6,6 +6,9 @@
# Drivers for off-chip devices
#
+# ALS drivers
+driver-$(CONFIG_ALS_ISL29035)+=als_isl29035.o
+
# Batteries
driver-$(CONFIG_BATTERY_BQ20Z453)+=battery/bq20z453.o
driver-$(CONFIG_BATTERY_BQ27541)+=battery/bq27541.o
diff --git a/include/als.h b/include/als.h
new file mode 100644
index 0000000000..e229a3791f
--- /dev/null
+++ b/include/als.h
@@ -0,0 +1,32 @@
+/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef __CROS_EC_ALS_H
+#define __CROS_EC_ALS_H
+
+#include "common.h"
+
+/* Defined in board.h */
+enum als_id;
+
+/* Initialized in board.c */
+struct als_t {
+ const char const *name;
+ int (*read)(int *lux);
+};
+
+extern struct als_t als[];
+
+/**
+ * Read an ALS
+ *
+ * @param id Which one?
+ * @param lux Put value here
+ *
+ * @return EC_SUCCESS, or non-zero if error.
+ */
+int als_read(enum als_id id, int *lux);
+
+#endif /* __CROS_EC_ALS_H */
diff --git a/include/config.h b/include/config.h
index c6e151158e..002d509def 100644
--- a/include/config.h
+++ b/include/config.h
@@ -46,6 +46,13 @@
#undef CONFIG_ADC_CLOCK
/*
+ * Some ALS modules may be connected to the EC. We need the command, and
+ * specific drivers for each module.
+ */
+#undef CONFIG_ALS
+#undef CONFIG_ALS_ISL29035
+
+/*
* Support controlling the display backlight based on the state of the lid
* switch. The EC will disable the backlight when the lid is closed.
*/