github.com/f-secure-foundry/tamago@v0.0.0-20220307101044-d73fcdd7f11b/board/f-secure/usbarmory/mark-two/pmic.go (about)

     1  // USB armory Mk II support for tamago/arm
     2  // https://github.com/f-secure-foundry/tamago
     3  //
     4  // Copyright (c) F-Secure Corporation
     5  // https://foundry.f-secure.com
     6  //
     7  // Use of this source code is governed by the license
     8  // that can be found in the LICENSE file.
     9  
    10  package usbarmory
    11  
    12  import (
    13  	"github.com/f-secure-foundry/tamago/bits"
    14  	"github.com/f-secure-foundry/tamago/internal/reg"
    15  	"github.com/f-secure-foundry/tamago/soc/imx6"
    16  )
    17  
    18  // On the USB armory Mk II the PMIC watchdog input (WDI) is connected to the
    19  // SoC external reset source (WDOG2_WDOG_RST_B_DEB) through
    20  // ENET1_TX_EN/KPP_COL2 (p4081, Table 59-1. WDOG External Signals, IMX6ULLRM).
    21  const (
    22  	IOMUXC_SW_MUX_CTL_PAD_ENET1_TX_EN = 0x020e00d8
    23  	IOMUXC_SW_PAD_CTL_PAD_ENET1_TX_EN = 0x020e0364
    24  
    25  	WDOG2_WDOG_RST_B_DEB_MODE = 8
    26  )
    27  
    28  func init() {
    29  	var ctl uint32
    30  
    31  	bits.Set(&ctl, imx6.SW_PAD_CTL_HYS)
    32  	bits.Set(&ctl, imx6.SW_PAD_CTL_PUE)
    33  	bits.Set(&ctl, imx6.SW_PAD_CTL_PKE)
    34  
    35  	bits.SetN(&ctl, imx6.SW_PAD_CTL_PUS, 0b11, imx6.SW_PAD_CTL_PUS_PULL_UP_22K)
    36  	bits.SetN(&ctl, imx6.SW_PAD_CTL_SPEED, 0b11, imx6.SW_PAD_CTL_SPEED_50MHZ)
    37  	bits.SetN(&ctl, imx6.SW_PAD_CTL_DSE, 0b111, imx6.SW_PAD_CTL_DSE_2_R0_6)
    38  
    39  	p, err := imx6.NewPad(IOMUXC_SW_MUX_CTL_PAD_ENET1_TX_EN,
    40  		IOMUXC_SW_PAD_CTL_PAD_ENET1_TX_EN,
    41  		0)
    42  
    43  	if err != nil {
    44  		panic(err)
    45  	}
    46  
    47  	p.Mode(WDOG2_WDOG_RST_B_DEB_MODE)
    48  	p.Ctl(ctl)
    49  }
    50  
    51  // Reset deasserts the PMIC watchdog signal (through the SoC external reset
    52  // source) causing the USB armory Mk II board to power cycle (cold reset).
    53  func Reset() {
    54  	for {
    55  		// enable software reset extension
    56  		reg.Set16(imx6.WDOG2_WCR, imx6.WCR_SRE)
    57  
    58  		// assert system reset signal
    59  		reg.Clear16(imx6.WDOG2_WCR, imx6.WCR_SRS)
    60  	}
    61  }