github.com/f-secure-foundry/tamago@v0.0.0-20220307101044-d73fcdd7f11b/soc/imx6/wdog.go (about)

     1  // NXP i.MX6UL/i.MX6ULL/i.MX6Q support
     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 imx6
    11  
    12  import (
    13  	"github.com/f-secure-foundry/tamago/internal/reg"
    14  )
    15  
    16  // Watchdog control registers, 32-bit access should be avoided as all registers
    17  // are 16-bit.
    18  const (
    19  	WDOG1_WCR  = 0x020bc000
    20  	WDOG1_WMCR = 0x020bc008
    21  
    22  	WDOG2_WCR  = 0x020c0000
    23  	WDOG2_WMCR = 0x020c0008
    24  
    25  	WDOG3_WCR  = 0x021e4000
    26  	WDOG3_WMCR = 0x021e4008
    27  
    28  	WCR_SRE  = 6
    29  	WCR_WDA  = 5
    30  	WCR_SRS  = 4
    31  	WMCR_PDE = 0
    32  )
    33  
    34  // System Reset Controller registers
    35  const (
    36  	SRC_SCR               = 0x020d8000
    37  	SCR_WARM_RESET_ENABLE = 0
    38  )
    39  
    40  func init() {
    41  	// Clear the 16 seconds power-down counter event for all watchdogs
    42  	// (p4085, 59.5.3 Power-down counter event, IMX6ULLRM).
    43  	reg.Clear16(WDOG1_WMCR, WMCR_PDE)
    44  	reg.Clear16(WDOG2_WMCR, WMCR_PDE)
    45  	reg.Clear16(WDOG3_WMCR, WMCR_PDE)
    46  }
    47  
    48  // Reset asserts the global watchdog reset causing the SoC to restart (warm
    49  // reset).
    50  //
    51  // Note that only the SoC itself is guaranteed to restart as, depending on the
    52  // board hardware layout, the system might remain powered (which might not be
    53  // desirable). See respective board packages for cold reset options.
    54  func Reset() {
    55  	// enable warm reset
    56  	reg.Clear(SRC_SCR, SCR_WARM_RESET_ENABLE)
    57  
    58  	// enable software reset extension
    59  	reg.Set16(WDOG1_WCR, WCR_SRE)
    60  
    61  	// assert system reset signal
    62  	reg.Clear16(WDOG1_WCR, WCR_SRS)
    63  }