summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/fruitpie/board.c101
-rw-r--r--board/fruitpie/board.h14
2 files changed, 115 insertions, 0 deletions
diff --git a/board/fruitpie/board.c b/board/fruitpie/board.c
index 17a01934a5..9353943edd 100644
--- a/board/fruitpie/board.c
+++ b/board/fruitpie/board.c
@@ -13,8 +13,12 @@
#include "i2c.h"
#include "registers.h"
#include "task.h"
+#include "timer.h"
+#include "usb_pd.h"
#include "util.h"
+#include "driver/tsu6721.h"
+
void rohm_event(enum gpio_signal signal)
{
ccprintf("ROHM!\n");
@@ -35,6 +39,11 @@ void tsu_event(enum gpio_signal signal)
/* Initialize board. */
static void board_init(void)
{
+ /* enable SYSCFG clock */
+ STM32_RCC_APB2ENR |= 1 << 0;
+
+ /* Remap SPI2 to DMA channels 6 and 7 */
+ STM32_SYSCFG_CFGR1 |= (1 << 24);
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
@@ -62,6 +71,98 @@ const struct i2c_port_t i2c_ports[] = {
};
const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
+int board_set_debug(int enable)
+{
+ timestamp_t timeout;
+ int rv = EC_SUCCESS;
+
+ if (enable) {
+ /* Disable the PD module */
+ gpio_config_module(MODULE_USB_PD, 0);
+
+ /* Suspend the USB PD task */
+ pd_set_suspend(1);
+
+ /* Decrease BCDv1.2 timer to 0.6s */
+ tsu6721_write(TSU6721_REG_TIMER, 0x05);
+
+ timeout.val = get_time().val + DEBUG_SWITCH_TIMEOUT_MSEC;
+ /* Wait for power to be detected to allow switching debug mux */
+ while (!(tsu6721_read(TSU6721_REG_DEV_TYPE3) & 0x74)) {
+ if (get_time().val > timeout.val)
+ return EC_ERROR_TIMEOUT;
+
+ /* Not already powered by cable, turn on regulator */
+ gpio_set_level(GPIO_USB_C_5V_EN, 1);
+
+ ccputs("Sleeping for 1s, waiting for TSU6721...\n");
+ usleep(1000*MSEC);
+ }
+
+ /* Enable manual switching */
+ rv = tsu6721_mux(TSU6721_MUX_USB);
+ if (rv)
+ return rv;
+
+ /* Switch debug mux */
+ tsu6721_set_pins(TSU6721_PIN_MANUAL2_BOOT);
+
+ /* Set pins PD_CLK_IN, PD_TX_DATA, and
+ * VCONN1_EN to alternate function. */
+ /* Set pin PD_TX_EN (NSS) to general purpose output mode. */
+ STM32_GPIO_MODER(GPIO_B) &= ~0xff000000;
+ STM32_GPIO_MODER(GPIO_B) |= 0xa9000000;
+
+ /* Set all four pins to alternate function 0 */
+ STM32_GPIO_AFRH(GPIO_B) &= ~(0xffff0000);
+
+ /* Set all four pins to output push-pull */
+ STM32_GPIO_OTYPER(GPIO_B) &= ~(0xf000);
+
+ /* Set pullup on PD_TX_EN */
+ STM32_GPIO_PUPDR(GPIO_B) |= 0x1000000;
+
+ /* Set all four pins to high speed */
+ STM32_GPIO_OSPEEDR(GPIO_B) |= 0xff000000;
+
+ /* Reset SPI2 */
+ STM32_RCC_APB1RSTR |= (1 << 14);
+ STM32_RCC_APB1RSTR &= ~(1 << 14);
+
+ /* Enable clocks to SPI2 module */
+ STM32_RCC_APB1ENR |= STM32_RCC_PB1_SPI2;
+ } else {
+ /* Reset SPI2 */
+ STM32_RCC_APB1RSTR |= (1 << 14);
+ STM32_RCC_APB1RSTR &= ~(1 << 14);
+
+ /* Set all but VCONN1_EN to input mode */
+ STM32_GPIO_MODER(GPIO_B) &= ~0x3f000000;
+
+ /* Unset pullup on PD_TX_EN/SPI_NSS */
+ gpio_set_flags(GPIO_PD_TX_EN, GPIO_OUTPUT | GPIO_PULL_UP);
+
+ /* Turn off debug mux */
+ tsu6721_set_pins(0);
+
+ /* Disable manual switching */
+ rv = tsu6721_mux(TSU6721_MUX_AUTO);
+ if (rv)
+ return rv;
+
+ /* Disable power on USB_C_5V_EN pin */
+ gpio_set_level(GPIO_USB_C_5V_EN, 0);
+
+ /* Restore BCDv1.2 timer to 1.6s */
+ tsu6721_write(TSU6721_REG_TIMER, 0x15);
+
+ /* Restore the USB PD task */
+ pd_set_suspend(0);
+ }
+
+ return rv;
+}
+
void board_set_usb_mux(enum typec_mux mux)
{
/* reset everything */
diff --git a/board/fruitpie/board.h b/board/fruitpie/board.h
index aec3faf648..9181e15dba 100644
--- a/board/fruitpie/board.h
+++ b/board/fruitpie/board.h
@@ -25,6 +25,9 @@
#define CONFIG_I2C
#define CONFIG_BATTERY_SMART
#define CONFIG_USB_SWITCH_TSU6721
+#define CONFIG_SPI_FLASH
+#define CONFIG_SPI_FLASH_SIZE 8388608
+#define CONFIG_SPI_FLASH_REGISTER STM32_SPI2_REGS
#undef CONFIG_WATCHDOG_HELP
#undef CONFIG_LID_SWITCH
#undef CONFIG_TASK_PROFILING
@@ -52,6 +55,17 @@
#ifndef __ASSEMBLER__
+/*
+ * Timeout to wait for TSU6721 to detect power. Set to double the BCD timer.
+ */
+#define DEBUG_SWITCH_TIMEOUT_MSEC (1200*MSEC)
+
+/*
+ * Used to set GPIO's and clock to SPI module used for debug
+ * @param enable Whether to enable or disable debug
+ */
+int board_set_debug(int enable);
+
/* Timer selection */
#define TIM_CLOCK32 2
#define TIM_ADC 3