summaryrefslogtreecommitdiff
path: root/board/strago
diff options
context:
space:
mode:
authorKevin K Wong <kevin.k.wong@intel.com>2015-07-09 15:52:25 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-07-25 17:45:10 +0000
commit43671e0348b52f4dbe0963aec8831bc7e9cc6792 (patch)
tree97d89217a092595780636f8853f66d7a4cb9e107 /board/strago
parent1c7baaf71f842874e80d7260ac725c2296239271 (diff)
downloadchrome-ec-43671e0348b52f4dbe0963aec8831bc7e9cc6792.tar.gz
strago: add initial PD support
Ported the PD support from Kunimitsu. kunimitsu: add initial PD support Change-Id: I0cb1edcf1703f55882f81c65e6359a45be4c1629 Reviewed-on: https://chromium-review.googlesource.com/281833 BUG=none TEST=Verified the PD negotiation on BCRD2. Device boots after plugging in the USB charger. Battery is getting charged. BRANCH=none Change-Id: If4efb0463118414fb02ad8e53700eac578a4954a Signed-off-by: Kevin K Wong <kevin.k.wong@intel.com> Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/287124 Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'board/strago')
-rw-r--r--board/strago/board.c185
-rw-r--r--board/strago/board.h51
-rw-r--r--board/strago/build.mk3
-rw-r--r--board/strago/ec.tasklist5
-rw-r--r--board/strago/gpio.inc21
-rw-r--r--board/strago/usb_pd_policy.c338
6 files changed, 588 insertions, 15 deletions
diff --git a/board/strago/board.c b/board/strago/board.c
index 42ec939e28..89e447f91a 100644
--- a/board/strago/board.c
+++ b/board/strago/board.c
@@ -5,10 +5,13 @@
/* Strago board-specific configuration */
#include "adc.h"
+#include "adc_chip.h"
#include "als.h"
#include "button.h"
#include "charger.h"
+#include "charge_manager.h"
#include "charge_state.h"
+#include "console.h"
#include "driver/accel_kxcj9.h"
#include "driver/als_isl29035.h"
#include "driver/temp_sensor/tmp432.h"
@@ -21,6 +24,7 @@
#include "math_util.h"
#include "motion_lid.h"
#include "motion_sense.h"
+#include "pi3usb9281.h"
#include "power.h"
#include "power_button.h"
#include "pwm.h"
@@ -29,12 +33,58 @@
#include "temp_sensor.h"
#include "temp_sensor_chip.h"
#include "thermal.h"
+#include "usb_charge.h"
+#include "usb_pd.h"
+#include "usb_pd_tcpm.h"
#include "util.h"
+#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
+
#define GPIO_KB_INPUT (GPIO_INPUT | GPIO_PULL_UP)
#define GPIO_KB_OUTPUT (GPIO_ODR_HIGH)
#define GPIO_KB_OUTPUT_COL2 (GPIO_OUT_LOW)
+/* Exchange status with PD MCU. */
+static void pd_mcu_interrupt(enum gpio_signal signal)
+{
+#ifdef HAS_TASK_PDCMD
+ /* Exchange status with PD MCU to determine interrupt cause */
+ host_command_pd_send_status(0);
+#endif
+}
+
+static void update_vbus_supplier(int port, int vbus_level)
+{
+ struct charge_port_info charge;
+
+ /*
+ * If VBUS is low, or VBUS is high and we are not outputting VBUS
+ * ourselves, then update the VBUS supplier.
+ */
+ if (!vbus_level || !usb_charger_port_is_sourcing_vbus(port)) {
+ charge.voltage = USB_CHARGER_VOLTAGE_MV;
+ charge.current = vbus_level ? USB_CHARGER_MIN_CURR_MA : 0;
+ charge_manager_update_charge(CHARGE_SUPPLIER_VBUS,
+ port,
+ &charge);
+ }
+}
+
+void vbus0_evt(enum gpio_signal signal)
+{
+ /* VBUS present GPIO is inverted */
+ int vbus_level = !gpio_get_level(signal);
+
+ update_vbus_supplier(0, vbus_level);
+ task_wake(TASK_ID_PD);
+}
+
+void usb0_evt(enum gpio_signal signal)
+{
+ task_wake(TASK_ID_USB_CHG_P0);
+}
+
#include "gpio_list.h"
/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */
@@ -55,12 +105,19 @@ const struct power_signal_info power_signal_list[] = {
};
BUILD_ASSERT(ARRAY_SIZE(power_signal_list) == POWER_SIGNAL_COUNT);
+/* ADC channels */
+const struct adc_t adc_channels[] = {
+ /* Vbus sensing. Converted to mV, full ADC is equivalent to 33V. */
+ [ADC_VBUS] = {"VBUS", 33000, 1024, 0, 4},
+};
+BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
+
const struct i2c_port_t i2c_ports[] = {
{"batt_chg", MEC1322_I2C0_0, 100,
GPIO_I2C_PORT0_SCL, GPIO_I2C_PORT0_SDA},
{"sensors", MEC1322_I2C1, 100,
GPIO_I2C_PORT1_SCL, GPIO_I2C_PORT1_SDA},
- {"pd_mcu", MEC1322_I2C2, 100,
+ {"pd_mcu", MEC1322_I2C2, 1000,
GPIO_I2C_PORT2_SCL, GPIO_I2C_PORT2_SDA},
{"thermal", MEC1322_I2C3, 100,
GPIO_I2C_PORT3_SCL, GPIO_I2C_PORT3_SDA}
@@ -68,9 +125,21 @@ const struct i2c_port_t i2c_ports[] = {
const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
const enum gpio_signal hibernate_wake_pins[] = {
+ GPIO_AC_PRESENT,
+ GPIO_LID_OPEN,
+ GPIO_POWER_BUTTON_L,
};
-const int hibernate_wake_pins_used;
+const int hibernate_wake_pins_used = ARRAY_SIZE(hibernate_wake_pins);
+
+struct pi3usb9281_config pi3usb9281_chips[] = {
+ {
+ .i2c_port = I2C_PORT_USB_CHARGER_1,
+ .mux_lock = NULL,
+ },
+};
+BUILD_ASSERT(ARRAY_SIZE(pi3usb9281_chips) ==
+ CONFIG_USB_SWITCH_PI3USB9281_CHIP_COUNT);
/*
* Temperature sensors data; must be in same order as enum temp_sensor_id.
@@ -114,6 +183,21 @@ const struct button_config buttons[] = {
};
BUILD_ASSERT(ARRAY_SIZE(buttons) == CONFIG_BUTTON_COUNT);
+void board_set_usb_switches(int port, enum usb_switch setting)
+{
+ /* TODO: Set open / close USB switches based on param */
+}
+
+/**
+ * Reset PD MCU
+ */
+void board_reset_pd_mcu(void)
+{
+ gpio_set_level(GPIO_PD_RST_L, 0);
+ usleep(100);
+ gpio_set_level(GPIO_PD_RST_L, 1);
+}
+
/* Four Motion sensors */
/* kxcj9 mutex and local/private data*/
static struct mutex g_kxcj9_mutex[2];
@@ -213,3 +297,100 @@ static void adc_pre_init(void)
gpio_config_module(MODULE_ADC, 1);
}
DECLARE_HOOK(HOOK_INIT, adc_pre_init, HOOK_PRIO_INIT_ADC - 1);
+
+/* Initialize board. */
+static void board_init(void)
+{
+ struct charge_port_info charge_none;
+
+ /* Enable PD MCU interrupt */
+ gpio_enable_interrupt(GPIO_PD_MCU_INT);
+ /* Enable VBUS interrupt */
+ gpio_enable_interrupt(GPIO_USB_C0_VBUS_WAKE_L);
+
+ /* Initialize all pericom charge suppliers to 0 */
+ charge_none.voltage = USB_CHARGER_VOLTAGE_MV;
+ charge_none.current = 0;
+ charge_manager_update_charge(CHARGE_SUPPLIER_PROPRIETARY,
+ 0,
+ &charge_none);
+ charge_manager_update_charge(CHARGE_SUPPLIER_BC12_CDP,
+ 0,
+ &charge_none);
+ charge_manager_update_charge(CHARGE_SUPPLIER_BC12_DCP,
+ 0,
+ &charge_none);
+ charge_manager_update_charge(CHARGE_SUPPLIER_BC12_SDP,
+ 0,
+ &charge_none);
+ charge_manager_update_charge(CHARGE_SUPPLIER_OTHER,
+ 0,
+ &charge_none);
+
+ /* Initialize VBUS supplier based on whether or not VBUS is present */
+ update_vbus_supplier(0, !gpio_get_level(GPIO_USB_C0_VBUS_WAKE_L));
+
+ /* Enable pericom BC1.2 interrupts */
+ gpio_enable_interrupt(GPIO_USB_C0_BC12_INT_L);
+}
+DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
+
+/**
+ * Set active charge port -- Enable or Disable charging
+ *
+ * @param charge_port Charge port to enable.
+ *
+ * Returns EC_SUCCESS if charge port is accepted and made active,
+ * EC_ERROR_* otherwise.
+ */
+int board_set_active_charge_port(int charge_port)
+{
+ /* charge port is a realy physical port */
+ int is_real_port = (charge_port >= 0 &&
+ charge_port < CONFIG_USB_PD_PORT_COUNT);
+ /* check if we are source vbus on that port */
+ int source = gpio_get_level(GPIO_USB_C0_5V_EN);
+
+ if (is_real_port && source) {
+ CPRINTS("Skip enable p%d", charge_port);
+ return EC_ERROR_INVAL;
+ }
+
+ CPRINTS("New chg p%d", charge_port);
+
+ if (charge_port == CHARGE_PORT_NONE) {
+ /* Disable charging port */
+ gpio_set_level(GPIO_USB_C0_CHARGE_EN_L, 1);
+ gpio_set_level(GPIO_EC_ACDET_CTRL, 1);
+ } else {
+ /* Enable charging port */
+ gpio_set_level(GPIO_USB_C0_CHARGE_EN_L, 0);
+ gpio_set_level(GPIO_EC_ACDET_CTRL, 0);
+ }
+
+ return EC_SUCCESS;
+}
+
+/**
+ * Set the charge limit based upon desired maximum.
+ *
+ * @param charge_ma Desired charge limit (mA).
+ */
+void board_set_charge_limit(int charge_ma)
+{
+ charge_set_input_current_limit(MAX(charge_ma,
+ CONFIG_CHARGER_INPUT_CURRENT));
+}
+
+/**
+ * TODO: Remove this code after the BAT_PRESENT_L GPIO is implemented in
+ * the hardware.
+ *
+ * Get the battery present status.
+ *
+ * Return EC_ERROR_UNIMPLEMENTED.
+ */
+enum battery_present battery_is_present(void)
+{
+ return EC_ERROR_UNIMPLEMENTED;
+}
diff --git a/board/strago/board.h b/board/strago/board.h
index 1bebbe6b1b..864a32ad83 100644
--- a/board/strago/board.h
+++ b/board/strago/board.h
@@ -31,6 +31,16 @@
#define CONFIG_EXTPOWER_GPIO
#define CONFIG_PORT80_TASK_EN
+#define CONFIG_USB_CHARGER
+#define CONFIG_USB_POWER_DELIVERY
+#define CONFIG_USB_PD_ALT_MODE
+#define CONFIG_USB_PD_ALT_MODE_DFP
+#define CONFIG_USB_PD_CUSTOM_VDM
+#define CONFIG_USB_PD_DUAL_ROLE
+#define CONFIG_USB_PD_PORT_COUNT 1
+#define CONFIG_USB_PD_TCPM_TCPCI
+#define CONFIG_USB_SWITCH_PI3USB9281
+#define CONFIG_USB_SWITCH_PI3USB9281_CHIP_COUNT 1
#define CONFIG_SPI_PORT 1
#define CONFIG_SPI_CS_GPIO GPIO_PVT_CS0
@@ -58,6 +68,8 @@
#define CONFIG_CHARGER_SENSE_RESISTOR_AC 10
#define CONFIG_CHARGER_INPUT_CURRENT 2240
#define CONFIG_CHARGER_DISCHARGE_ON_AC
+#define CONFIG_CHARGE_MANAGER
+#define CONFIG_HOSTCMD_PD
#define CONFIG_PWM
#define CONFIG_LED_COMMON
@@ -66,8 +78,8 @@
/* Accelerometer */
#define CONFIG_ACCEL_KXCJ9
-#define CONFIG_CMD_ACCELS
-#define CONFIG_CMD_ACCEL_INFO
+#undef CONFIG_CMD_ACCELS
+#undef CONFIG_CMD_ACCEL_INFO
#define CONFIG_LID_ANGLE
#define CONFIG_LID_ANGLE_SENSOR_BASE 0
#define CONFIG_LID_ANGLE_SENSOR_LID 1
@@ -75,13 +87,21 @@
/* Number of buttons */
#define CONFIG_BUTTON_COUNT 2
+#undef DEFERRABLE_MAX_COUNT
+#define DEFERRABLE_MAX_COUNT 11
+
+#define CONFIG_ADC
+
/* Modules we want to exclude */
+#undef CONFIG_CMD_HASH
+#undef CONFIG_CMD_TIMERINFO
+#undef CONFIG_CONSOLE_CMDHELP
+#undef CONFIG_CONSOLE_HISTORY
#undef CONFIG_EEPROM
#undef CONFIG_EOPTION
+#undef CONFIG_FANS
#undef CONFIG_PSTORE
#undef CONFIG_PECI
-#undef CONFIG_FANS
-#undef CONFIG_ADC
#ifndef __ASSEMBLER__
#include "gpio_signal.h"
@@ -93,11 +113,14 @@
#define I2C_PORT_ACCEL MEC1322_I2C1
#define I2C_PORT_GYRO MEC1322_I2C1
#define I2C_PORT_ALS MEC1322_I2C1
+#define I2C_PORT_USB_CHARGER_1 MEC1322_I2C2
#define I2C_PORT_PD_MCU MEC1322_I2C2
+#define I2C_PORT_TCPC MEC1322_I2C2
#define I2C_PORT_THERMAL MEC1322_I2C3
/* ADC signal */
enum adc_channel {
+ ADC_VBUS,
/* Number of ADC channels */
ADC_CH_COUNT
};
@@ -140,6 +163,26 @@ enum als_id {
ALS_COUNT,
};
+/* start as a sink in case we have no other power supply/battery */
+#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
+
+/* TODO: determine the following board specific type-C power constants */
+/*
+ * delay to turn on the power supply max is ~16ms.
+ * delay to turn off the power supply max is about ~180ms.
+ */
+#define PD_POWER_SUPPLY_TURN_ON_DELAY 30000 /* us */
+#define PD_POWER_SUPPLY_TURN_OFF_DELAY 250000 /* us */
+
+/* Define typical operating power and max power */
+#define PD_OPERATING_POWER_MW 15000
+#define PD_MAX_POWER_MW 60000
+#define PD_MAX_CURRENT_MA 3000
+#define PD_MAX_VOLTAGE_MV 20000
+
+/* Reset PD MCU */
+void board_reset_pd_mcu(void);
+
#endif /* !__ASSEMBLER__ */
#endif /* __CROS_EC_BOARD_H */
diff --git a/board/strago/build.mk b/board/strago/build.mk
index 894de2b191..f978c868b4 100644
--- a/board/strago/build.mk
+++ b/board/strago/build.mk
@@ -6,9 +6,10 @@
# Board specific files build
#
-# the IC is SMSC MEC1322 / external SPI is 4MB / external clock is crystal
+# the IC is SMSC MEC1322 / external SPI is 512KB / external clock is crystal
CHIP:=mec1322
CHIP_SPI_SIZE_KB:=512
board-y=board.o led.o
board-$(CONFIG_BATTERY_SMART)+=battery.o
+board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o
diff --git a/board/strago/ec.tasklist b/board/strago/ec.tasklist
index 370444648e..3b1efb3150 100644
--- a/board/strago/ec.tasklist
+++ b/board/strago/ec.tasklist
@@ -18,12 +18,15 @@
*/
#define CONFIG_TASK_LIST \
TASK_ALWAYS(HOOKS, hook_task, NULL, TASK_STACK_SIZE) \
+ TASK_ALWAYS(USB_CHG_P0, usb_charger_task, NULL, TASK_STACK_SIZE) \
TASK_ALWAYS(CHARGER, charger_task, NULL, TASK_STACK_SIZE) \
TASK_NOTEST(MOTIONSENSE, motion_sense_task, NULL, LARGER_TASK_STACK_SIZE) \
TASK_NOTEST(CHIPSET, chipset_task, NULL, TASK_STACK_SIZE) \
TASK_NOTEST(KEYPROTO, keyboard_protocol_task, NULL, TASK_STACK_SIZE) \
+ TASK_NOTEST(PDCMD, pd_command_task, NULL, TASK_STACK_SIZE) \
TASK_ALWAYS(HOSTCMD, host_command_task, NULL, TASK_STACK_SIZE) \
TASK_ALWAYS(CONSOLE, console_task, NULL, TASK_STACK_SIZE) \
TASK_NOTEST(PORT80, port80_task, NULL, TASK_STACK_SIZE) \
TASK_ALWAYS(POWERBTN, power_button_task, NULL, TASK_STACK_SIZE) \
- TASK_NOTEST(KEYSCAN, keyboard_scan_task, NULL, TASK_STACK_SIZE)
+ TASK_NOTEST(KEYSCAN, keyboard_scan_task, NULL, TASK_STACK_SIZE) \
+ TASK_ALWAYS(PD, pd_task, NULL, LARGER_TASK_STACK_SIZE)
diff --git a/board/strago/gpio.inc b/board/strago/gpio.inc
index e08bb7477c..7a89ab7b07 100644
--- a/board/strago/gpio.inc
+++ b/board/strago/gpio.inc
@@ -5,6 +5,9 @@
* found in the LICENSE file.
*/
+GPIO_INT(PD_MCU_INT, PIN(47), GPIO_INT_FALLING | GPIO_INT_DSLEEP, pd_mcu_interrupt)
+GPIO_INT(USB_C0_VBUS_WAKE_L,PIN(12), GPIO_INT_BOTH, vbus0_evt)
+GPIO_INT(USB_C0_BC12_INT_L, PIN(155), GPIO_INT_FALLING, usb0_evt)
GPIO_INT(LID_OPEN, PIN(27), GPIO_INT_BOTH | GPIO_PULL_UP, lid_interrupt) /* Lid switch */
GPIO_INT(AC_PRESENT, PIN(30), GPIO_INT_BOTH | GPIO_PULL_UP | GPIO_PULL_DOWN, extpower_interrupt) /* BC_ACOK / EC_ACIN - to know if battery or AC connected */
#ifdef CONFIG_BUTTON_COUNT
@@ -22,10 +25,12 @@ GPIO_INT(UART0_RX, PIN(162), GPIO_INPUT | GPIO_PULL_UP, NULL)
GPIO_INT(PCH_SLP_S4_L, PIN(200), GPIO_INT_BOTH, power_signal_interrupt) /* SLP_S4# signal from PCH */
GPIO_INT(PCH_SLP_S3_L, PIN(206), GPIO_INT_BOTH, power_signal_interrupt) /* SLP_S3# signal from PCH */
+UNIMPLEMENTED(BAT_PRESENT_L)
+UNIMPLEMENTED(USB_PD_WAKE)
+
GPIO(NC_GPIO0, PIN(0), GPIO_INPUT | GPIO_PULL_UP) /* NC */
GPIO(KBD_KSO2, PIN(1), GPIO_KB_OUTPUT_COL2) /* Negative edge triggered irq. */
-GPIO(NC_USBPD_BOOT0, PIN(12), GPIO_INPUT | GPIO_PULL_DOWN) /* NC */
GPIO(USB_ILIM_SEL, PIN(13), GPIO_OUT_HIGH) /* USB current control */
GPIO(I2C_PORT0_SCL, PIN(15), GPIO_ODR_HIGH)
GPIO(I2C_PORT0_SDA, PIN(16), GPIO_ODR_HIGH)
@@ -53,9 +58,9 @@ GPIO(PCH_SMI_L, PIN(44), GPIO_ODR_HIGH) /* SMI output */
GPIO(USB_OC1_L, PIN(45), GPIO_INT_FALLING) /* DB2 BC1.2 over current signal to EC */
GPIO(DP_USB_C_HPD_Q, PIN(46), GPIO_OUT_HIGH) /* DP hot plug detect from EC to SOC */
-GPIO(OTG_SW_EN, PIN(50), GPIO_OUT_LOW) /* */
+GPIO(USB_C0_5V_EN, PIN(50), GPIO_OUT_LOW) /* USB C0 5V enable */
GPIO(PCH_SUS_STAT_L, PIN(51), GPIO_INT_FALLING) /* Signal to inform EC that SOC is entering low power state */
-GPIO(EC_ACDET_CTRL, PIN(52), GPIO_INPUT | GPIO_PULL_UP)
+GPIO(EC_ACDET_CTRL, PIN(52), GPIO_OUT_HIGH) /* EC AC Detect control */
GPIO(TRACKPAD_PWREN, PIN(53), GPIO_OUT_HIGH) /* Enable power for Track Pad */
GPIO(USB_OC0_L, PIN(55), GPIO_INT_FALLING) /* Over current signal of the BC1.2 charger to EC */
GPIO(EC_ADC1, PIN(57), GPIO_INPUT) /* EC_ADC1, TEMP_SENSOR_2 no_stuff */
@@ -84,7 +89,7 @@ GPIO(PD_RST_L, PIN(135), GPIO_ODR_HIGH) /* USB PD MCU r
GPIO(THERMAL_PROBE_EN_L,PIN(140), GPIO_OUT_HIGH)
GPIO(PCH_RSMRST_L, PIN(143), GPIO_OUT_LOW) /* RSMRST_N to PCH */
-GPIO(EC_KBD_ALERT, PIN(145), GPIO_OUT_LOW) /* EC_KBD_ALERT */
+GPIO(EC_KBD_ALERT, PIN(145), GPIO_OUT_LOW) /* EC_KBD_ALERT */
GPIO(PVT_CS0, PIN(146), GPIO_ODR_HIGH) /* SPI PVT Chip select */
GPIO(ALS_INT, PIN(147), GPIO_INPUT | GPIO_PULL_UP) /* ALS sensor interrupt to EC */
@@ -92,7 +97,6 @@ GPIO(WLAN_OFF_L, PIN(150), GPIO_ODR_HIGH) /* Wireless LAN
GPIO(CPU_PROCHOT, PIN(151), GPIO_OUT_LOW)
GPIO(KBD_IRQ_L, PIN(152), GPIO_ODR_HIGH) /* Negative edge triggered irq. */
GPIO(BOARD_VERSION1, PIN(154), GPIO_INPUT) /* BOARD_ID0 */
-GPIO(EC_PERICOM_INT, PIN(155), GPIO_INT_BOTH) /* Pericom USB device interrupt */
GPIO(PWR_BTN_SELECT, PIN(156), GPIO_ODR_HIGH) /* HIGH in clamshell mode and LOW in tablet mode */
GPIO(PCH_SUSPWRDNACK, PIN(157), GPIO_INT_FALLING) /* PMC SUSPWRDNACK signal from SOC to EC */
@@ -103,7 +107,7 @@ GPIO(VP9_CODEC_RESET_L, PIN(163), GPIO_OUT_LOW) /* VP9_CODEC_RE
GPIO(STARTUP_LATCH_SET, PIN(201), GPIO_OUT_HIGH) /* Output from EC to POL signal of USB Type C Mux */
GPIO(EC_BL_DISABLE_L, PIN(202), GPIO_OUT_HIGH) /* EDP backligh disable signal from EC */
GPIO(SMC_SHUTDOWN, PIN(203), GPIO_OUT_LOW) /* Shutdown signal from EC to power sequencing PLD */
-GPIO(USBPD_BST_OFF, PIN(204), GPIO_OUT_LOW)
+GPIO(USB_C0_CHARGE_EN_L,PIN(204), GPIO_OUT_LOW)
GPIO(SUSPWRDNACK_SOC_EC,PIN(210), GPIO_OUT_LOW) /* SUSPWRDNACK signal from MOIC device to EC */
GPIO(GPIO_3_EC, PIN(211), GPIO_OUT_LOW) /* Sleep SOIX signal from SOC to EC */
@@ -134,10 +138,13 @@ ALTERNATE(PIN_MASK(15, 0x08), 1, MODULE_SPI, 0)
ALTERNATE(PIN_MASK(13, 0x48), 1, MODULE_PWM_LED, GPIO_OUTPUT) /* 133: PWM0, 136: PWM1 */
ALTERNATE(PIN_MASK(14, 0x02), 1, MODULE_PWM_LED, GPIO_OUTPUT) /* 141: PWM3 */
ALTERNATE(PIN_MASK(5, 0x40), 1, MODULE_ADC, 0) /* 56: temperature sensor 1 */
-ALTERNATE(PIN_MASK(6, 0x05), 1, MODULE_ADC, 0) /* 60: PC_MON, 62: temperature sensor 3 */
+ALTERNATE(PIN_MASK(6, 0x01), 1, MODULE_ADC, 0) /* 60: PC_MON, 62: temperature sensor 3 */
/* Re-Config LPC Pins to GPIO Open Drain for SOC G3 (EC - POWER_G3) state */
ALTERNATE(PIN_MASK(1, 0x10), 0, MODULE_GPIO, GPIO_ODR_HIGH) /* 14: LPC CLKRUN */
ALTERNATE(PIN_MASK(11, 0x9e), 0, MODULE_GPIO, GPIO_ODR_HIGH) /* 111~114:LAD[0:3], 117:PCI_CLK */
ALTERNATE(PIN_MASK(11, 0x40), 0, MODULE_GPIO, GPIO_ODR_HIGH) /* 116: LRESET# */
ALTERNATE(PIN_MASK(12, 0x01), 0, MODULE_GPIO, GPIO_ODR_HIGH) /* 120: LFRAME# */
+
+/* FOR USBPD - GP62/ADC4 */
+ALTERNATE(PIN_MASK(6, 0x04), 1, MODULE_ADC, GPIO_ANALOG)
diff --git a/board/strago/usb_pd_policy.c b/board/strago/usb_pd_policy.c
new file mode 100644
index 0000000000..ba7a162fab
--- /dev/null
+++ b/board/strago/usb_pd_policy.c
@@ -0,0 +1,338 @@
+/* Copyright 2015 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.
+ */
+
+#include "atomic.h"
+#include "charge_manager.h"
+#include "common.h"
+#include "console.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "host_command.h"
+#include "registers.h"
+#include "system.h"
+#include "task.h"
+#include "timer.h"
+#include "util.h"
+#include "usb_pd.h"
+
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+
+#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP)
+
+/* TODO: fill in correct source and sink capabilities */
+const uint32_t pd_src_pdo[] = {
+ PDO_FIXED(5000, 1500, PDO_FIXED_FLAGS),
+};
+const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo);
+
+const uint32_t pd_snk_pdo[] = {
+ PDO_FIXED(5000, 500, PDO_FIXED_FLAGS),
+ PDO_BATT(5000, 20000, 15000),
+ PDO_VAR(5000, 20000, 3000),
+};
+const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo);
+
+int pd_is_valid_input_voltage(int mv)
+{
+ return 1;
+}
+
+int pd_check_requested_voltage(uint32_t rdo)
+{
+ int max_ma = rdo & 0x3FF;
+ int op_ma = (rdo >> 10) & 0x3FF;
+ int idx = rdo >> 28;
+ uint32_t pdo;
+ uint32_t pdo_ma;
+
+ if (!idx || idx > pd_src_pdo_cnt)
+ return EC_ERROR_INVAL; /* Invalid index */
+
+ /* check current ... */
+ pdo = pd_src_pdo[idx - 1];
+ pdo_ma = (pdo & 0x3ff);
+ if (op_ma > pdo_ma)
+ return EC_ERROR_INVAL; /* too much op current */
+ if (max_ma > pdo_ma)
+ return EC_ERROR_INVAL; /* too much max current */
+
+ CPRINTF("Requested %d V %d mA (for %d/%d mA)\n",
+ ((pdo >> 10) & 0x3ff) * 50, (pdo & 0x3ff) * 10,
+ ((rdo >> 10) & 0x3ff) * 10, (rdo & 0x3ff) * 10);
+
+ return EC_SUCCESS;
+}
+
+void pd_transition_voltage(int idx)
+{
+ /* No-operation: we are always 5V */
+}
+
+int pd_set_power_supply_ready(int port)
+{
+ /* Disable charging */
+ gpio_set_level(GPIO_USB_C0_CHARGE_EN_L, 1);
+
+ /* Provide VBUS */
+ gpio_set_level(GPIO_USB_C0_5V_EN, 1);
+
+ return EC_SUCCESS; /* we are ready */
+}
+
+void pd_power_supply_reset(int port)
+{
+ /* Disable VBUS */
+ gpio_set_level(GPIO_USB_C0_5V_EN, 0);
+}
+
+void pd_set_input_current_limit(int port, uint32_t max_ma,
+ uint32_t supply_voltage)
+{
+#ifdef CONFIG_CHARGE_MANAGER
+ struct charge_port_info charge;
+ charge.current = max_ma;
+ charge.voltage = supply_voltage;
+ charge_manager_update_charge(CHARGE_SUPPLIER_PD, port, &charge);
+#endif
+ /* notify host of power info change */
+}
+
+void typec_set_input_current_limit(int port, uint32_t max_ma,
+ uint32_t supply_voltage)
+{
+#ifdef CONFIG_CHARGE_MANAGER
+ struct charge_port_info charge;
+ charge.current = max_ma;
+ charge.voltage = supply_voltage;
+ charge_manager_update_charge(CHARGE_SUPPLIER_TYPEC, port, &charge);
+#endif
+
+ /* notify host of power info change */
+}
+
+int pd_snk_is_vbus_provided(int port)
+{
+ return !gpio_get_level(GPIO_USB_C0_VBUS_WAKE_L);
+}
+
+int pd_board_checks(void)
+{
+ return EC_SUCCESS;
+}
+
+int pd_check_power_swap(int port)
+{
+ /*
+ * Allow power swap as long as we are acting as a dual role device,
+ * otherwise assume our role is fixed (not in S0 or console command
+ * to fix our role).
+ */
+ return pd_get_dual_role() == PD_DRP_TOGGLE_ON ? 1 : 0;
+}
+
+int pd_check_data_swap(int port, int data_role)
+{
+ /* Allow data swap if we are a UFP, otherwise don't allow */
+ return (data_role == PD_ROLE_UFP) ? 1 : 0;
+}
+
+void pd_execute_data_swap(int port, int data_role)
+{
+ /* TODO: need to open/close D+/D- switch based on role */
+}
+
+void pd_check_pr_role(int port, int pr_role, int partner_pr_swap)
+{
+ /* If sink, and dual role toggling is on, then switch to source */
+ if (partner_pr_swap && pr_role == PD_ROLE_SINK &&
+ pd_get_dual_role() == PD_DRP_TOGGLE_ON)
+ pd_request_power_swap(port);
+}
+
+void pd_check_dr_role(int port, int dr_role, int partner_dr_swap)
+{
+ /* If UFP, try to switch to DFP */
+ if (partner_dr_swap && dr_role == PD_ROLE_UFP)
+ pd_request_data_swap(port);
+}
+
+/* ----------------- Vendor Defined Messages ------------------ */
+const struct svdm_response svdm_rsp = {
+ .identity = NULL,
+ .svids = NULL,
+ .modes = NULL,
+};
+
+int pd_custom_vdm(int port, int cnt, uint32_t *payload,
+ uint32_t **rpayload)
+{
+ int cmd = PD_VDO_CMD(payload[0]);
+ uint16_t dev_id = 0;
+ int is_rw;
+
+ /* make sure we have some payload */
+ if (cnt == 0)
+ return 0;
+
+ switch (cmd) {
+ case VDO_CMD_VERSION:
+ /* guarantee last byte of payload is null character */
+ *(payload + cnt - 1) = 0;
+ CPRINTF("version: %s\n", (char *)(payload+1));
+ break;
+ case VDO_CMD_READ_INFO:
+ case VDO_CMD_SEND_INFO:
+ /* copy hash */
+ if (cnt == 7) {
+ dev_id = VDO_INFO_HW_DEV_ID(payload[6]);
+ is_rw = VDO_INFO_IS_RW(payload[6]);
+
+ CPRINTF("DevId:%d.%d SW:%d RW:%d\n",
+ HW_DEV_ID_MAJ(dev_id),
+ HW_DEV_ID_MIN(dev_id),
+ VDO_INFO_SW_DBG_VER(payload[6]),
+ is_rw);
+ } else if (cnt == 6) {
+ /* really old devices don't have last byte */
+ pd_dev_store_rw_hash(port, dev_id, payload + 1,
+ SYSTEM_IMAGE_UNKNOWN);
+ }
+ break;
+ case VDO_CMD_CURRENT:
+ CPRINTF("Current: %dmA\n", payload[1]);
+ break;
+ case VDO_CMD_FLIP:
+ /* board_flip_usb_mux(port); */
+ break;
+#ifdef CONFIG_USB_PD_LOGGING
+ case VDO_CMD_GET_LOG:
+ pd_log_recv_vdm(port, cnt, payload);
+ break;
+#endif /* CONFIG_USB_PD_LOGGING */
+ }
+
+ return 0;
+}
+
+#ifdef CONFIG_USB_PD_ALT_MODE_DFP
+static int dp_flags;
+
+static void svdm_safe_dp_mode(int port)
+{
+ /* make DP interface safe until configure */
+ dp_flags = 0;
+ /* board_set_usb_mux(port, TYPEC_MUX_NONE, pd_get_polarity(port)); */
+}
+
+static int svdm_enter_dp_mode(int port, uint32_t mode_caps)
+{
+ /* Only enter mode if device is DFP_D capable */
+ if (mode_caps & MODE_DP_SNK) {
+ svdm_safe_dp_mode(port);
+ return 0;
+ }
+
+ return -1;
+}
+
+static int svdm_dp_status(int port, uint32_t *payload)
+{
+ int opos = pd_alt_mode(port, USB_SID_DISPLAYPORT);
+ payload[0] = VDO(USB_SID_DISPLAYPORT, 1,
+ CMD_DP_STATUS | VDO_OPOS(opos));
+ payload[1] = VDO_DP_STATUS(0, /* HPD IRQ ... not applicable */
+ 0, /* HPD level ... not applicable */
+ 0, /* exit DP? ... no */
+ 0, /* usb mode? ... no */
+ 0, /* multi-function ... no */
+ (!!(dp_flags & DP_FLAGS_DP_ON)),
+ 0, /* power low? ... no */
+ (!!(dp_flags & DP_FLAGS_DP_ON)));
+ return 2;
+};
+
+static int svdm_dp_config(int port, uint32_t *payload)
+{
+ int opos = pd_alt_mode(port, USB_SID_DISPLAYPORT);
+ /* board_set_usb_mux(port, TYPEC_MUX_DP, pd_get_polarity(port)); */
+ payload[0] = VDO(USB_SID_DISPLAYPORT, 1,
+ CMD_DP_CONFIG | VDO_OPOS(opos));
+ payload[1] = VDO_DP_CFG(MODE_DP_PIN_E, /* pin mode */
+ 1, /* DPv1.3 signaling */
+ 2); /* UFP connected */
+ return 2;
+};
+
+static void svdm_dp_post_config(int port)
+{
+ dp_flags |= DP_FLAGS_DP_ON;
+ if (!(dp_flags & DP_FLAGS_HPD_HI_PENDING))
+ return;
+}
+
+static int svdm_dp_attention(int port, uint32_t *payload)
+{
+ /* ack */
+ return 1;
+}
+
+static void svdm_exit_dp_mode(int port)
+{
+ svdm_safe_dp_mode(port);
+ /* gpio_set_level(PORT_TO_HPD(port), 0); */
+}
+
+static int svdm_enter_gfu_mode(int port, uint32_t mode_caps)
+{
+ /* Always enter GFU mode */
+ return 0;
+}
+
+static void svdm_exit_gfu_mode(int port)
+{
+}
+
+static int svdm_gfu_status(int port, uint32_t *payload)
+{
+ /*
+ * This is called after enter mode is successful, send unstructured
+ * VDM to read info.
+ */
+ pd_send_vdm(port, USB_VID_GOOGLE, VDO_CMD_READ_INFO, NULL, 0);
+ return 0;
+}
+
+static int svdm_gfu_config(int port, uint32_t *payload)
+{
+ return 0;
+}
+
+static int svdm_gfu_attention(int port, uint32_t *payload)
+{
+ return 0;
+}
+
+const struct svdm_amode_fx supported_modes[] = {
+ {
+ .svid = USB_SID_DISPLAYPORT,
+ .enter = &svdm_enter_dp_mode,
+ .status = &svdm_dp_status,
+ .config = &svdm_dp_config,
+ .post_config = &svdm_dp_post_config,
+ .attention = &svdm_dp_attention,
+ .exit = &svdm_exit_dp_mode,
+ },
+ {
+ .svid = USB_VID_GOOGLE,
+ .enter = &svdm_enter_gfu_mode,
+ .status = &svdm_gfu_status,
+ .config = &svdm_gfu_config,
+ .attention = &svdm_gfu_attention,
+ .exit = &svdm_exit_gfu_mode,
+ }
+};
+const int supported_modes_cnt = ARRAY_SIZE(supported_modes);
+#endif /* CONFIG_USB_PD_ALT_MODE_DFP */