summaryrefslogtreecommitdiff
path: root/board
diff options
context:
space:
mode:
authorVic Yang <victoryang@google.com>2012-01-14 20:46:10 +0800
committerVic Yang <victoryang@google.com>2012-02-02 10:24:26 +0800
commit1e5233a66d80b34230b0a462bbf2983277e7c4cc (patch)
tree813fd8d0a9520d95d039f609b617d3ae2c988604 /board
parentdf1d8933223817b4b5afe33101e939ff243aa9f6 (diff)
downloadchrome-ec-1e5233a66d80b34230b0a462bbf2983277e7c4cc.tar.gz
Refactor ADC code and add Link charger current ADC support
Refactor ADC code and move board/chip-specific part to corresponding directories. Implement function and console command to read Link charger current. BUG=chrome-os-partner:7527 TEST=Read EC temperature and POT input on BDS. Change-Id: I7fafd310ea49d9b2781f10c3453f5488da29a08a
Diffstat (limited to 'board')
-rw-r--r--board/bds/board.c19
-rw-r--r--board/bds/board.h10
-rw-r--r--board/link/board.c18
-rw-r--r--board/link/board.h10
4 files changed, 57 insertions, 0 deletions
diff --git a/board/bds/board.c b/board/bds/board.c
index 71bc810444..631cf29079 100644
--- a/board/bds/board.c
+++ b/board/bds/board.c
@@ -9,6 +9,25 @@
#include "power_button.h"
#include "registers.h"
#include "util.h"
+#include "lm4_adc.h"
+#include "adc.h"
+
+/* ADC channels. Must be in the exactly same order as in enum adc_channel. */
+const struct adc_t adc_channels[ADC_CH_COUNT] =
+{
+ /* EC internal temperature is calculated by
+ * 273 + (295 - 450 * ADC_VALUE / ADC_READ_MAX) / 2
+ * = -225 * ADC_VALUE / ADC_READ_MAX + 420.5
+ */
+ {"ECTemp", LM4_ADC_SEQ0, -225, ADC_READ_MAX, 420,
+ LM4_NO_AIN, 0x0e /* TS0 | IE0 | END0 */},
+
+ /* Charger current is mapped from 0~4000mA to 0~1.6V.
+ * And ADC maps 0~3.3V to ADC_READ_MAX.
+ */
+ {"ChargerCurrent", LM4_ADC_SEQ1, 33 * 4000, ADC_READ_MAX * 16, 0,
+ LM4_AIN(ADC_IN0), 0x06 /* IE0 | END0 */},
+};
/* GPIO signal list. Must match order from enum gpio_signal. */
diff --git a/board/bds/board.h b/board/bds/board.h
index 9b28cd6e46..fbd4f153ca 100644
--- a/board/bds/board.h
+++ b/board/bds/board.h
@@ -46,6 +46,16 @@
/* TODO: really just need a lookup table for channels to inputs */
#define ADC_IN0 0 /* Turn POT on badger board */
+enum adc_channel
+{
+ /* EC internal die temperature in degrees K. */
+ ADC_CH_EC_TEMP = 0,
+ /* Treat BDS pot input as charger current. */
+ ADC_CH_CHARGER_CURRENT,
+
+ ADC_CH_COUNT
+};
+
/* I2C ports */
#define I2C_PORT_BATTERY 5 // port 0 / PB2:3 on Link, open on badger
#define I2C_PORT_CHARGER 5 // port 1 / PA6:7 on Link, user LED on badger
diff --git a/board/link/board.c b/board/link/board.c
index 20a2437b00..67d975686e 100644
--- a/board/link/board.c
+++ b/board/link/board.c
@@ -11,6 +11,8 @@
#include "registers.h"
#include "util.h"
#include "x86_power.h"
+#include "lm4_adc.h"
+#include "adc.h"
#ifndef CONFIG_TASK_X86POWER
#define x86_power_interrupt NULL
@@ -99,6 +101,22 @@ const struct gpio_info gpio_list[GPIO_COUNT] = {
{"USB2_ILIM_SEL", LM4_GPIO_E, (1<<0), GPIO_OUT_LOW, NULL},
};
+/* ADC channels. Must be in the exactly same order as in enum adc_channel. */
+const struct adc_t adc_channels[ADC_CH_COUNT] =
+{
+ /* EC internal temperature is calculated by
+ * 273 + (295 - 450 * ADC_VALUE / ADC_READ_MAX) / 2
+ * = -225 * ADC_VALUE / ADC_READ_MAX + 420.5
+ */
+ {"ECTemp", LM4_ADC_SEQ0, -225, ADC_READ_MAX, 420,
+ LM4_NO_AIN, 0x0e /* TS0 | IE0 | END0 */},
+
+ /* Charger current is mapped from 0~4000mA to 0~1.6V.
+ * And ADC maps 0~3.3V to ADC_READ_MAX.
+ */
+ {"ChargerCurrent", LM4_ADC_SEQ1, 33 * 4000, ADC_READ_MAX * 16, 0,
+ LM4_AIN(ADC_IN0), 0x06 /* IE0 | END0 */},
+};
void configure_board(void)
{
diff --git a/board/link/board.h b/board/link/board.h
index 923ae716ad..0387bc45fc 100644
--- a/board/link/board.h
+++ b/board/link/board.h
@@ -46,6 +46,16 @@
/* TODO: assign real ADC inputs */
#define ADC_IN0 11 /* Charger current */
+enum adc_channel
+{
+ /* EC internal die temperature in degrees K. */
+ ADC_CH_EC_TEMP = 0,
+ /* Charger current in mA. */
+ ADC_CH_CHARGER_CURRENT,
+
+ ADC_CH_COUNT
+};
+
/* I2C ports */
#define I2C_PORT_BATTERY 0
#define I2C_PORT_CHARGER 1