summaryrefslogtreecommitdiff
path: root/chip
diff options
context:
space:
mode:
authorVic Yang <victoryang@google.com>2012-01-12 17:02:10 +0800
committerVic Yang <victoryang@google.com>2012-02-04 14:37:04 +0800
commit000a6d57423e96ffaa2061bd764b8141ea46bb8e (patch)
tree528dd0d5f798101470a1d45f9480bc7b2ecebcb0 /chip
parent249467b9f291e2b10a7aafdbb584c68c8b0a4e88 (diff)
downloadchrome-ec-000a6d57423e96ffaa2061bd764b8141ea46bb8e.tar.gz
Refactor temperature sensor code and add support of Link I2C temp sensor.
Refactor board/chip-specific code into corresponding directories. Add support of the four I2C temp sensor in Link. Use table lookup to handle different types of temperature sensors. BUG=chrome-os-partner:7527 TEST=Correctly read EC internal temperature on bds. Compile for link succeeded. Change-Id: I694cfa54e1545798d877fafdf18c5585ab5f03e2
Diffstat (limited to 'chip')
-rw-r--r--chip/lm4/build.mk3
-rw-r--r--chip/lm4/charger.c96
-rw-r--r--chip/lm4/chip_temp_sensor.c24
-rw-r--r--chip/lm4/config.h1
4 files changed, 123 insertions, 1 deletions
diff --git a/chip/lm4/build.mk b/chip/lm4/build.mk
index cfd78e9866..7a2053b2f9 100644
--- a/chip/lm4/build.mk
+++ b/chip/lm4/build.mk
@@ -14,5 +14,6 @@ chip-y+=watchdog.o eeprom.o hwtimer.o
chip-$(CONFIG_FLASH)+=flash.o
chip-$(CONFIG_LPC)+=lpc.o
chip-$(CONFIG_PWM)+=pwm.o
-chip-$(CONFIG_TEMP_SENSOR)+=temp_sensor.o
+chip-$(CONFIG_TEMP_SENSOR)+=chip_temp_sensor.o
chip-$(CONFIG_TASK_KEYSCAN)+=keyboard_scan.o
+chip-$(CONFIG_CHARGER)+=charger.o
diff --git a/chip/lm4/charger.c b/chip/lm4/charger.c
new file mode 100644
index 0000000000..e603e63453
--- /dev/null
+++ b/chip/lm4/charger.c
@@ -0,0 +1,96 @@
+/* Copyright (c) 2012 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.
+ */
+
+/* Charger/battery debug command module for Chrome EC */
+
+/* TODO: remove this or merge into charger/battery modules
+ * once charger and battery modules are ready.
+ */
+
+#include "charger.h"
+#include "board.h"
+#include "i2c.h"
+#include "console.h"
+#include "uart.h"
+#include "util.h"
+
+/* Address of battery charger */
+#define CHARGER_ADDR 0x12
+
+/* Address of battery */
+#define BATTERY_ADDR 0x16
+
+/*****************************************************************************/
+/* Console commands */
+
+static int command_charger(int argc, char **argv)
+{
+ int rv;
+ int d;
+
+ uart_puts("Reading battery charger...\n");
+
+ rv = i2c_read16(I2C_PORT_CHARGER, CHARGER_ADDR, 0xfe, &d);
+ if (rv)
+ return rv;
+ uart_printf(" Manufacturer ID: 0x%04x\n", d);
+
+ rv = i2c_read16(I2C_PORT_CHARGER, CHARGER_ADDR, 0xff, &d);
+ uart_printf(" Device ID: 0x%04x\n", d);
+
+ rv = i2c_read16(I2C_PORT_CHARGER, CHARGER_ADDR, 0x12, &d);
+ uart_printf(" Option: 0x%04x\n", d);
+
+ rv = i2c_read16(I2C_PORT_CHARGER, CHARGER_ADDR, 0x14, &d);
+ uart_printf(" Charge current: 0x%04x\n", d);
+
+ rv = i2c_read16(I2C_PORT_CHARGER, CHARGER_ADDR, 0x15, &d);
+ uart_printf(" Charge voltage: 0x%04x\n", d);
+
+ rv = i2c_read16(I2C_PORT_CHARGER, CHARGER_ADDR, 0x3f, &d);
+ uart_printf(" Input current: 0x%04x\n", d);
+
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(charger, command_charger);
+
+static int command_battery(int argc, char **argv)
+{
+ int rv;
+ int d;
+
+ uart_puts("Reading battery...\n");
+
+ rv = i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, 0x08, &d);
+ if (rv)
+ return rv;
+ uart_printf(" Temperature: 0x%04x = %d C\n",
+ d, (d-2731)/10);
+
+ rv = i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, 0x09, &d);
+ uart_printf(" Voltage: 0x%04x = %d mV\n", d, d);
+
+ rv = i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, 0x0f, &d);
+ uart_printf(" Remaining capacity: 0x%04x = %d mAh\n", d, d);
+ rv = i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, 0x10, &d);
+ uart_printf(" Full charge capacity: 0x%04x = %d mAh\n", d, d);
+
+ rv = i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, 0x14, &d);
+ uart_printf(" Desired charge current: 0x%04x = %d mA\n", d, d);
+ rv = i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, 0x15, &d);
+ uart_printf(" Desired charge voltage: 0x%04x = %d mV\n", d, d);
+
+
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(battery, command_battery);
+
+/*****************************************************************************/
+/* Initialization */
+
+int charger_init(void)
+{
+ return EC_SUCCESS;
+}
diff --git a/chip/lm4/chip_temp_sensor.c b/chip/lm4/chip_temp_sensor.c
new file mode 100644
index 0000000000..d810216851
--- /dev/null
+++ b/chip/lm4/chip_temp_sensor.c
@@ -0,0 +1,24 @@
+/* Copyright (c) 2011 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.
+ */
+
+/* Temperature sensor module for Chrome EC */
+
+#include "adc.h"
+#include "board.h"
+#include "temp_sensor.h"
+
+int chip_temp_sensor_read(const struct temp_sensor_t* sensor)
+{
+ /* LM4 only has internal temperature sensor */
+ if (sensor->id != TEMP_SENSOR_EC_INTERNAL)
+ return EC_ERROR_INVAL;
+
+ return adc_read_channel(ADC_CH_EC_TEMP);
+}
+
+int chip_temp_sensor_init(void)
+{
+ return EC_SUCCESS;
+}
diff --git a/chip/lm4/config.h b/chip/lm4/config.h
index d1c892bd68..f2224f8226 100644
--- a/chip/lm4/config.h
+++ b/chip/lm4/config.h
@@ -36,6 +36,7 @@
#define CONFIG_LPC
#define CONFIG_PWM
#define CONFIG_TEMP_SENSOR
+#define CONFIG_CHARGER
/* Compile for running from RAM instead of flash */
/* #define COMPILE_FOR_RAM */