summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2012-12-19 23:58:12 +0800
committerChromeBot <chrome-bot@google.com>2013-01-08 08:58:36 -0800
commit40c79398a63e8192246ff79900a3974041c9d48d (patch)
treebdd54584127c8134b3fdc2e9eec5820463a10eba
parent6eb8a6e9999618e6111db7549b46edddaa09313c (diff)
downloadchrome-ec-40c79398a63e8192246ff79900a3974041c9d48d.tar.gz
spring: Sense attached device type
This adds USB port control to charger task. For now, it only senses attached device type and log it to console. BUG=chrome-os-partner:14319 TEST=Attach/detach charger and see console output. BRANCH=none Change-Id: I1218d520c292d9d398c868122ae3876d3fc889bc Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/40078 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--board/spring/board.c4
-rw-r--r--board/spring/board.h3
-rw-r--r--board/spring/usb_charging.c57
-rw-r--r--common/pmu_tps65090_charger.c17
-rw-r--r--common/tsu6721.c5
-rw-r--r--include/tsu6721.h1
6 files changed, 86 insertions, 1 deletions
diff --git a/board/spring/board.c b/board/spring/board.c
index 49d591b87e..db39e26344 100644
--- a/board/spring/board.c
+++ b/board/spring/board.c
@@ -39,6 +39,7 @@ void gaia_lid_event(enum gpio_signal signal);
#ifndef CONFIG_TASK_KEYSCAN
#define matrix_interrupt NULL
#endif
+void usb_charge_interrupt(enum gpio_signal signal);
/* GPIO signal list. Must match order from enum gpio_signal. */
const struct gpio_info gpio_list[GPIO_COUNT] = {
@@ -58,7 +59,8 @@ const struct gpio_info gpio_list[GPIO_COUNT] = {
{"KB_IN05", GPIO_C, (1<<14), GPIO_KB_INPUT, matrix_interrupt},
{"KB_IN06", GPIO_C, (1<<15), GPIO_KB_INPUT, matrix_interrupt},
{"KB_IN07", GPIO_D, (1<<2), GPIO_KB_INPUT, matrix_interrupt},
- {"USB_CHG_INT", GPIO_A, (1<<6), GPIO_INT_FALLING, NULL},
+ {"USB_CHG_INT", GPIO_A, (1<<6), GPIO_INT_FALLING,
+ usb_charge_interrupt},
/* Other inputs */
{"BCHGR_VACG", GPIO_A, (1<<0), GPIO_INT_BOTH, NULL},
/*
diff --git a/board/spring/board.h b/board/spring/board.h
index 4e78134842..bd9db98f69 100644
--- a/board/spring/board.h
+++ b/board/spring/board.h
@@ -153,6 +153,9 @@ void board_ilim_config(enum ilim_config config);
/* Set PWM duty cycle */
void board_pwm_duty_cycle(int percent);
+/* Update USB port status */
+void board_usb_charge_update(void);
+
#endif /* !__ASSEMBLER__ */
#endif /* __BOARD_H */
diff --git a/board/spring/usb_charging.c b/board/spring/usb_charging.c
index d10f1cfa6e..e4d9a362fd 100644
--- a/board/spring/usb_charging.c
+++ b/board/spring/usb_charging.c
@@ -9,10 +9,17 @@
#include "console.h"
#include "gpio.h"
#include "registers.h"
+#include "task.h"
+#include "timer.h"
+#include "tsu6721.h"
#include "util.h"
#define PWM_FREQUENCY 100 /* Hz */
+/* Console output macros */
+#define CPUTS(outstr) cputs(CC_USBCHARGE, outstr)
+#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
+
static enum ilim_config current_ilim_config = ILIM_CONFIG_MANUAL_OFF;
static void board_ilim_use_gpio(void)
@@ -99,6 +106,56 @@ void board_pwm_duty_cycle(int percent)
STM32_TIM_CCR1(3) = (percent * STM32_TIM_ARR(3)) / 100;
}
+void usb_charge_interrupt(enum gpio_signal signal)
+{
+ task_wake(TASK_ID_PMU_TPS65090_CHARGER);
+}
+
+static void usb_device_change(int dev_type)
+{
+ static int last_dev_type;
+
+ if (last_dev_type == dev_type)
+ return;
+ last_dev_type = dev_type;
+
+ CPRINTF("[%T USB Attached: ");
+ if (dev_type == TSU6721_TYPE_NONE)
+ CPRINTF("Nothing]\n");
+ else if (dev_type & TSU6721_TYPE_OTG)
+ CPRINTF("OTG]\n");
+ else if (dev_type & TSU6721_TYPE_USB_HOST)
+ CPRINTF("USB Host]\n");
+ else if (dev_type & TSU6721_TYPE_CHG12)
+ CPRINTF("Type 1/2 Charger]\n");
+ else if (dev_type & TSU6721_TYPE_NON_STD_CHG)
+ CPRINTF("Non standard charger]\n");
+ else if (dev_type & TSU6721_TYPE_DCP)
+ CPRINTF("DCP]\n");
+ else if (dev_type & TSU6721_TYPE_CDP)
+ CPRINTF("CDP]\n");
+ else if (dev_type & TSU6721_TYPE_U200_CHG)
+ CPRINTF("U200]\n");
+ else if (dev_type & TSU6721_TYPE_APPLE_CHG)
+ CPRINTF("Apple charger]\n");
+ else if (dev_type & TSU6721_TYPE_JIG_UART_ON)
+ CPRINTF("JIG UART ON]\n");
+ else if (dev_type & TSU6721_TYPE_VBUS_DEBOUNCED)
+ CPRINTF("Unknown with power]\n");
+ else
+ CPRINTF("Unknown]\n");
+}
+
+void board_usb_charge_update(void)
+{
+ int int_val = tsu6721_get_interrupts();
+
+ if (int_val & TSU6721_INT_DETACH)
+ usb_device_change(TSU6721_TYPE_NONE);
+ else if (int_val)
+ usb_device_change(tsu6721_get_device_type());
+}
+
/*
* Console command for debugging.
* TODO(victoryang): Remove after charging control is done.
diff --git a/common/pmu_tps65090_charger.c b/common/pmu_tps65090_charger.c
index 4e474451fc..14475a1c71 100644
--- a/common/pmu_tps65090_charger.c
+++ b/common/pmu_tps65090_charger.c
@@ -16,6 +16,7 @@
#include "system.h"
#include "task.h"
#include "timer.h"
+#include "tsu6721.h"
#include "util.h"
#define CPUTS(outstr) cputs(CC_CHARGER, outstr)
@@ -388,10 +389,26 @@ void pmu_charger_task(void)
enable_charging(0);
disable_sleep(SLEEP_MASK_CHARGING);
+#ifdef CONFIG_TSU6721
+ /*
+ * Somehow TSU6721 comes up slowly. Let's wait for a moment before
+ * accessing it.
+ * TODO(victoryang): Investigate slow init issue.
+ */
+ msleep(500);
+
+ tsu6721_init(); /* Init here until we can do with HOOK_INIT */
+ gpio_enable_interrupt(GPIO_USB_CHG_INT);
+#endif
+
while (1) {
last_waken = get_time();
pmu_clear_irq();
+#ifdef CONFIG_TSU6721
+ board_usb_charge_update();
+#endif
+
/*
* When battery is extremely low, the internal voltage can not
* power on its gas guage IC. Charging loop will enable the
diff --git a/common/tsu6721.c b/common/tsu6721.c
index af562a579b..d6fc67ce23 100644
--- a/common/tsu6721.c
+++ b/common/tsu6721.c
@@ -110,6 +110,11 @@ void tsu6721_init(void)
settings = tsu6721_read(TSU6721_REG_TIMER);
settings = (settings & ~0x38);
tsu6721_write(TSU6721_REG_TIMER, settings);
+
+ tsu6721_enable_interrupts(TSU6721_INT_ATTACH |
+ TSU6721_INT_DETACH |
+ TSU6721_INT_ADC_CHANGE |
+ TSU6721_INT_VBUS);
}
/*
* TODO(vpalatin): using the I2C early in the HOOK_INIT
diff --git a/include/tsu6721.h b/include/tsu6721.h
index e6be4555e1..f1101acf06 100644
--- a/include/tsu6721.h
+++ b/include/tsu6721.h
@@ -65,6 +65,7 @@ enum tsu6721_mux {
#define TSU6721_TYPE_AUDIO2 0x000002
#define TSU6721_TYPE_AUDIO1 0x000001
#define TSU6721_TYPE_AUDIO3 0x008000
+#define TSU6721_TYPE_JIG_UART_ON 0x000400
#define TSU6721_TYPE_U200_CHG 0x400000
#define TSU6721_TYPE_APPLE_CHG 0x200000
#define TSU6721_TYPE_NON_STD_CHG 0x040000