github.com/usbarmory/tamago@v0.0.0-20240508072735-8612bbe1e454/soc/nxp/imx6ul/reset.go (about)

     1  // NXP i.MX6UL system reset controller (SRC) support
     2  // https://github.com/usbarmory/tamago
     3  //
     4  // Copyright (c) WithSecure Corporation
     5  // https://foundry.withsecure.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 imx6ul
    11  
    12  import (
    13  	"github.com/usbarmory/tamago/internal/reg"
    14  )
    15  
    16  // System Reset Controller registers
    17  const (
    18  	SRC_SCR               = 0x020d8000
    19  	SCR_WARM_RESET_ENABLE = 0
    20  
    21  	SRC_GPR10                    = SRC_SCR + 0x44
    22  	GPR10_PERSIST_SECONDARY_BOOT = 30
    23  )
    24  
    25  // PersistSecondaryBoot controls whether the primary (false) or secondary boot
    26  // image (true) should be selected after a software reset.
    27  func PersistSecondaryBoot(enable bool) {
    28  	// tested to work correctly only with SetWarmReset(false)
    29  	reg.SetTo(SRC_GPR10, GPR10_PERSIST_SECONDARY_BOOT, enable)
    30  }
    31  
    32  // SetWarmReset controls whether warm reset sources are enabled (true) or if
    33  // they should generate a cold reset (false).
    34  func SetWarmReset(enable bool) {
    35  	reg.SetTo(SRC_SCR, SCR_WARM_RESET_ENABLE, enable)
    36  }
    37  
    38  // Reset asserts the global watchdog reset causing the SoC to restart with a
    39  // cold reset.
    40  //
    41  // Note that only the SoC itself is guaranteed to restart as, depending on the
    42  // board hardware layout, the system might remain powered (which might not be
    43  // desirable). See respective board packages for cold reset options.
    44  func Reset() {
    45  	SetWarmReset(false)
    46  
    47  	// assert software reset
    48  	WDOG1.SoftwareReset()
    49  }