X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=carlfw%2Fusb%2Fmain.c;h=dc48bf2115a4537fb3477ade2a33e4a124f5850b;hb=dc294e837216a4b10470b63203cc3b0070444b45;hp=57f75a44162f93635161182b7a8cc5013f3d1fdd;hpb=0eb34487ee8e70ecb8e4ee2ed5092b2788eb7f26;p=carl9170fw.git diff --git a/carlfw/usb/main.c b/carlfw/usb/main.c index 57f75a4..dc48bf2 100644 --- a/carlfw/usb/main.c +++ b/carlfw/usb/main.c @@ -224,6 +224,17 @@ static void turn_power_off(void) set(AR9170_MAC_REG_DMA_TRIGGER, 0); + andl(AR9170_USB_REG_DMA_CTL, ~(AR9170_USB_DMA_CTL_ENABLE_TO_DEVICE | + AR9170_USB_DMA_CTL_ENABLE_FROM_DEVICE | + AR9170_USB_DMA_CTL_UP_PACKET_MODE | + AR9170_USB_DMA_CTL_DOWN_STREAM)); + + /* Do a software reset to PTA component */ + orl(AR9170_PTA_REG_DMA_MODE_CTRL, AR9170_PTA_DMA_MODE_CTRL_RESET); + andl(AR9170_PTA_REG_DMA_MODE_CTRL, ~AR9170_PTA_DMA_MODE_CTRL_RESET); + + orl(AR9170_PTA_REG_DMA_MODE_CTRL, AR9170_PTA_DMA_MODE_CTRL_DISABLE_USB); + set(AR9170_MAC_REG_POWER_STATE_CTRL, AR9170_MAC_POWER_STATE_CTRL_RESET); @@ -270,18 +281,29 @@ static void turn_power_off(void) set(AR9170_PHY_REG_ADC_SERIAL_CTL, AR9170_PHY_ADC_SCTL_SEL_INTERNAL_ADDAC); } -void __noreturn reboot(void) +static void disable_watchdog(void) { + if (!fw.watchdog_enable) + return; + /* write watchdog magic pattern for suspend */ andl(AR9170_PWR_REG_WATCH_DOG_MAGIC, 0xffff); orl(AR9170_PWR_REG_WATCH_DOG_MAGIC, 0x98760000); /* Disable watchdog */ - orl(AR9170_TIMER_REG_WATCH_DOG, 0xffff); + set(AR9170_TIMER_REG_WATCH_DOG, 0xffff); +} + +void __noreturn reboot(void) +{ + disable_watchdog(); /* Turn off power */ turn_power_off(); + /* clean bootloader workspace */ + memset(&dma_mem, 0, sizeof(dma_mem)); + /* add by ygwei for work around USB PHY chirp sequence problem */ set(0x10f100, 0x12345678); @@ -356,20 +378,18 @@ static void usb_handler(uint8_t usb_interrupt_level1) } if (usb_interrupt_level2 & BIT(2)) { - /* ACK USB suspend interrupt */ usb_suspend_ack(); - /* Set GO_TO_SUSPEND bit to USB main control register */ - setb(AR9170_USB_REG_MAIN_CTRL, BIT(3)); - - /* add by ygwei for work around USB PHY chirp sequence problem */ - set(0x10f100, 0x12345678); + disable_watchdog(); - reboot(); + /* GO_TO_SUSPEND stops the CPU clock too. */ + orb(AR9170_USB_REG_MAIN_CTRL, AR9170_USB_MAIN_CTRL_GO_TO_SUSPEND); } - if (usb_interrupt_level2 & BIT(3)) + if (usb_interrupt_level2 & BIT(3)) { usb_resume_ack(); + reboot(); + } } }