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

     1  // NXP i.MX6UL configuration and 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 provides support to Go bare metal unikernels, written using
    11  // the TamaGo framework, on the NXP i.MX6UL family of System-on-Chip (SoC)
    12  // application processors.
    13  //
    14  // The package implements initialization and drivers for NXP
    15  // i.MX6UL/i.MX6ULL/i.MX6ULZ SoCs, adopting the following reference
    16  // specifications:
    17  //   - IMX6ULCEC  - i.MX6UL  Data Sheet                               - Rev 2.2 2015/05
    18  //   - IMX6ULLCEC - i.MX6ULL Data Sheet                               - Rev 1.2 2017/11
    19  //   - IMX6ULZCEC - i.MX6ULZ Data Sheet                               - Rev 0   2018/09
    20  //   - IMX6ULRM   - i.MX 6UL  Applications Processor Reference Manual - Rev 1   2016/04
    21  //   - IMX6ULLRM  - i.MX 6ULL Applications Processor Reference Manual - Rev 1   2017/11
    22  //   - IMX6ULZRM  - i.MX 6ULZ Applications Processor Reference Manual - Rev 0   2018/10
    23  //
    24  // This package is only meant to be used with `GOOS=tamago GOARCH=arm` as
    25  // supported by the TamaGo framework for bare metal Go on ARM SoCs, see
    26  // https://github.com/usbarmory/tamago.
    27  package imx6ul
    28  
    29  import (
    30  	"encoding/binary"
    31  
    32  	"github.com/usbarmory/tamago/internal/reg"
    33  
    34  	"github.com/usbarmory/tamago/arm"
    35  	"github.com/usbarmory/tamago/arm/gic"
    36  	"github.com/usbarmory/tamago/arm/tzc380"
    37  
    38  	"github.com/usbarmory/tamago/soc/nxp/bee"
    39  	"github.com/usbarmory/tamago/soc/nxp/caam"
    40  	"github.com/usbarmory/tamago/soc/nxp/csu"
    41  	"github.com/usbarmory/tamago/soc/nxp/dcp"
    42  	"github.com/usbarmory/tamago/soc/nxp/enet"
    43  	"github.com/usbarmory/tamago/soc/nxp/gpio"
    44  	"github.com/usbarmory/tamago/soc/nxp/i2c"
    45  	"github.com/usbarmory/tamago/soc/nxp/ocotp"
    46  	"github.com/usbarmory/tamago/soc/nxp/rngb"
    47  	"github.com/usbarmory/tamago/soc/nxp/snvs"
    48  	"github.com/usbarmory/tamago/soc/nxp/tempmon"
    49  	"github.com/usbarmory/tamago/soc/nxp/uart"
    50  	"github.com/usbarmory/tamago/soc/nxp/usb"
    51  	"github.com/usbarmory/tamago/soc/nxp/usdhc"
    52  	"github.com/usbarmory/tamago/soc/nxp/wdog"
    53  )
    54  
    55  // Peripheral registers
    56  const (
    57  	// Bus Encryption Engine (UL only)
    58  	BEE_BASE = 0x02044000
    59  
    60  	// Cryptographic Acceleration and Assurance Module (UL only)
    61  	CAAM_BASE = 0x02140000
    62  
    63  	// Central Security Unit
    64  	CSU_BASE = 0x021c0000
    65  
    66  	// Data Co-Processor (ULL/ULZ only)
    67  	DCP_BASE = 0x02280000
    68  
    69  	// General Interrupt Controller
    70  	GIC_BASE = 0x00a00000
    71  
    72  	// General Purpose I/O
    73  	GPIO1_BASE = 0x0209c000
    74  	GPIO2_BASE = 0x020a0000
    75  	GPIO3_BASE = 0x020a4000
    76  	GPIO4_BASE = 0x020a8000
    77  	GPIO5_BASE = 0x020ac000
    78  
    79  	// Ethernet MAC (UL/ULL only)
    80  	ENET1_BASE = 0x02188000
    81  	ENET2_BASE = 0x020b4000
    82  
    83  	// Ethernet MAC interrupts
    84  	ENET1_IRQ  = 32 + 118
    85  	ENET2_IRQ  = 32 + 120
    86  
    87  	// I2C
    88  	I2C1_BASE = 0x021a0000
    89  	I2C2_BASE = 0x021a4000
    90  
    91  	// Multi Mode DDR Controller
    92  	MMDC_BASE = 0x80000000
    93  
    94  	// On-Chip OTP Controller
    95  	OCOTP_BASE      = 0x021bc000
    96  	OCOTP_BANK_BASE = 0x021bc400
    97  
    98  	// On-Chip Random-Access Memory
    99  	OCRAM_START = 0x00900000
   100  	OCRAM_SIZE  = 0x20000
   101  
   102  	// True Random Number Generator (ULL/ULZ only)
   103  	RNGB_BASE = 0x02284000
   104  
   105  	// Secure Non-Volatile Storage
   106  	SNVS_HP_BASE = 0x020cc000
   107  	SNVS_LP_BASE = 0x020b0000
   108  
   109  	// Temperature Monitor
   110  	TEMPMON_BASE = 0x020c8180
   111  
   112  	// TrustZone Address Space Controller
   113  	TZASC_BASE            = 0x021d0000
   114  	TZASC_BYPASS          = 0x020e4024
   115  	GPR1_TZASC1_BOOT_LOCK = 23
   116  
   117  	// Serial ports
   118  	UART1_BASE = 0x02020000
   119  	UART2_BASE = 0x021e8000
   120  	UART3_BASE = 0x021ec000
   121  	UART4_BASE = 0x021f0000
   122  
   123  	// USB 2.0 controller
   124  	USB_ANALOG1_BASE   = 0x020c81a0
   125  	USB_ANALOG2_BASE   = 0x020c8200
   126  	USB_ANALOG_DIGPROG = 0x020c8260
   127  	USBPHY1_BASE       = 0x020c9000
   128  	USBPHY2_BASE       = 0x020ca000
   129  	USB1_BASE          = 0x02184000
   130  	USB2_BASE          = 0x02184200
   131  
   132  	// USB 2.0 controller interrupts
   133  	USB1_IRQ           = 32 + 43
   134  	USB2_IRQ           = 32 + 42
   135  
   136  	// SD/MMC
   137  	USDHC1_BASE = 0x02190000
   138  	USDHC2_BASE = 0x02194000
   139  
   140  	// Watchdog Timers
   141  	WDOG1_BASE = 0x020bc000
   142  	WDOG2_BASE = 0x020c0000
   143  	WDOG3_BASE = 0x021e4000
   144  
   145  	// Watchdog Timer interrupts
   146  	WDOG1_IRQ  = 32 + 80
   147  	WDOG2_IRQ  = 32 + 81
   148  	WDOG3_IRQ  = 32 + 11
   149  )
   150  
   151  // Peripheral instances
   152  var (
   153  	// ARM core
   154  	ARM = &arm.CPU{}
   155  
   156  	// Bus Encryption Engine (UL only)
   157  	BEE *bee.BEE
   158  
   159  	// Cryptographic Acceleration and Assurance Module (UL only)
   160  	CAAM *caam.CAAM
   161  
   162  	// Central Security Unit
   163  	CSU = &csu.CSU{
   164  		Base: CSU_BASE,
   165  		CCGR: CCM_CCGR1,
   166  		CG:   CCGRx_CG14,
   167  	}
   168  
   169  	// Data Co-Processor (ULL/ULZ only)
   170  	DCP *dcp.DCP
   171  
   172  	// Generic Interrupt Controller
   173  	GIC = &gic.GIC{
   174  		Base: GIC_BASE,
   175  	}
   176  
   177  	// GPIO controller 1
   178  	GPIO1 = &gpio.GPIO{
   179  		Index: 1,
   180  		Base:  GPIO1_BASE,
   181  		CCGR:  CCM_CCGR1,
   182  		CG:    CCGRx_CG13,
   183  	}
   184  
   185  	// GPIO controller 2
   186  	GPIO2 = &gpio.GPIO{
   187  		Index: 2,
   188  		Base:  GPIO2_BASE,
   189  		CCGR:  CCM_CCGR0,
   190  		CG:    CCGRx_CG15,
   191  	}
   192  
   193  	// GPIO controller 3
   194  	GPIO3 = &gpio.GPIO{
   195  		Index: 3,
   196  		Base:  GPIO3_BASE,
   197  		CCGR:  CCM_CCGR2,
   198  		CG:    CCGRx_CG13,
   199  	}
   200  
   201  	// GPIO controller 4
   202  	GPIO4 = &gpio.GPIO{
   203  		Index: 4,
   204  		Base:  GPIO4_BASE,
   205  		CCGR:  CCM_CCGR3,
   206  		CG:    CCGRx_CG6,
   207  	}
   208  
   209  	// GPIO controller 5
   210  	GPIO5 = &gpio.GPIO{
   211  		Index: 5,
   212  		Base:  GPIO5_BASE,
   213  		CCGR:  CCM_CCGR1,
   214  		CG:    CCGRx_CG15,
   215  	}
   216  
   217  	// Ethernet MAC 1 (UL/ULL only)
   218  	ENET1 *enet.ENET
   219  	ENET2 *enet.ENET
   220  
   221  	// I2C controller 1
   222  	I2C1 = &i2c.I2C{
   223  		Index: 1,
   224  		Base:  I2C1_BASE,
   225  		CCGR:  CCM_CCGR2,
   226  		CG:    CCGRx_CG3,
   227  	}
   228  
   229  	// I2C controller 2
   230  	I2C2 = &i2c.I2C{
   231  		Index: 2,
   232  		Base:  I2C2_BASE,
   233  		CCGR:  CCM_CCGR2,
   234  		CG:    CCGRx_CG5,
   235  	}
   236  
   237  	// On-Chip OTP Controller
   238  	OCOTP = &ocotp.OCOTP{
   239  		Base:     OCOTP_BASE,
   240  		BankBase: OCOTP_BANK_BASE,
   241  		CCGR:     CCM_CCGR2,
   242  		CG:       CCGRx_CG6,
   243  	}
   244  
   245  	// True Random Number Generator (ULL/ULZ only)
   246  	RNGB *rngb.RNGB
   247  
   248  	// Secure Non-Volatile Storage
   249  	SNVS = &snvs.SNVS{
   250  		Base: SNVS_HP_BASE,
   251  		CCGR: CCM_CCGR5,
   252  		CG:   CCGRx_CG9,
   253  	}
   254  
   255  	// Temperature Monitor
   256  	TEMPMON = &tempmon.TEMPMON{
   257  		Base: TEMPMON_BASE,
   258  	}
   259  
   260  	// TrustZone Address Space Controller
   261  	TZASC = &tzc380.TZASC{
   262  		Base:              TZASC_BASE,
   263  		Bypass:            TZASC_BYPASS,
   264  		SecureBootLockReg: IOMUXC_GPR_GPR1,
   265  		SecureBootLockPos: GPR1_TZASC1_BOOT_LOCK,
   266  	}
   267  
   268  	// Serial port 1
   269  	UART1 = &uart.UART{
   270  		Index: 1,
   271  		Base:  UART1_BASE,
   272  		CCGR:  CCM_CCGR5,
   273  		CG:    CCGRx_CG12,
   274  		Clock: GetUARTClock,
   275  	}
   276  
   277  	// Serial port 2
   278  	UART2 = &uart.UART{
   279  		Index: 2,
   280  		Base:  UART2_BASE,
   281  		CCGR:  CCM_CCGR0,
   282  		CG:    CCGRx_CG14,
   283  		Clock: GetUARTClock,
   284  	}
   285  
   286  	// USB controller 1
   287  	USB1 = &usb.USB{
   288  		Index:     1,
   289  		Base:      USB1_BASE,
   290  		CCGR:      CCM_CCGR6,
   291  		CG:        CCGRx_CG0,
   292  		Analog:    USB_ANALOG1_BASE,
   293  		PHY:       USBPHY1_BASE,
   294  		IRQ:       USB1_IRQ,
   295  		EnablePLL: EnableUSBPLL,
   296  	}
   297  
   298  	// USB controller 2
   299  	USB2 = &usb.USB{
   300  		Index:     2,
   301  		Base:      USB2_BASE,
   302  		CCGR:      CCM_CCGR6,
   303  		CG:        CCGRx_CG0,
   304  		Analog:    USB_ANALOG2_BASE,
   305  		PHY:       USBPHY2_BASE,
   306  		IRQ:       USB2_IRQ,
   307  		EnablePLL: EnableUSBPLL,
   308  	}
   309  
   310  	// SD/MMC controller 1
   311  	USDHC1 = &usdhc.USDHC{
   312  		Index:    1,
   313  		Base:     USDHC1_BASE,
   314  		CCGR:     CCM_CCGR6,
   315  		CG:       CCGRx_CG1,
   316  		SetClock: SetUSDHCClock,
   317  	}
   318  
   319  	// SD/MMC controller 2
   320  	USDHC2 = &usdhc.USDHC{
   321  		Index:    2,
   322  		Base:     USDHC2_BASE,
   323  		CCGR:     CCM_CCGR6,
   324  		CG:       CCGRx_CG2,
   325  		SetClock: SetUSDHCClock,
   326  	}
   327  
   328  	// Watchdog Timer 1
   329  	WDOG1 = &wdog.WDOG{
   330  		Index: 1,
   331  		Base:  WDOG1_BASE,
   332  		CCGR:  CCM_CCGR3,
   333  		CG:    CCGRx_CG8,
   334  		IRQ:   WDOG1_IRQ,
   335  	}
   336  
   337  	// Watchdog Timer 2
   338  	WDOG2 = &wdog.WDOG{
   339  		Index: 2,
   340  		Base:  WDOG2_BASE,
   341  		CCGR:  CCM_CCGR5,
   342  		CG:    CCGRx_CG5,
   343  		IRQ:   WDOG2_IRQ,
   344  	}
   345  
   346  	// TrustZone Watchdog
   347  	TZ_WDOG = WDOG2
   348  
   349  	// Watchdog Timer 3
   350  	WDOG3 = &wdog.WDOG{
   351  		Index: 3,
   352  		Base:  WDOG3_BASE,
   353  		CCGR:  CCM_CCGR6,
   354  		CG:    CCGRx_CG10,
   355  		IRQ:   WDOG3_IRQ,
   356  	}
   357  )
   358  
   359  // SiliconVersion returns the SoC silicon version information
   360  // (p3945, 57.4.11 Chip Silicon Version (USB_ANALOG_DIGPROG), IMX6ULLRM).
   361  func SiliconVersion() (sv, family, revMajor, revMinor uint32) {
   362  	sv = reg.Read(USB_ANALOG_DIGPROG)
   363  
   364  	family = (sv >> 16) & 0xff
   365  	revMajor = (sv >> 8) & 0xff
   366  	revMinor = sv & 0xff
   367  
   368  	return
   369  }
   370  
   371  // UniqueID returns the NXP SoC Device Unique 64-bit ID.
   372  func UniqueID() (uid [8]byte) {
   373  	cfg0, _ := OCOTP.Read(0, 1)
   374  	cfg1, _ := OCOTP.Read(0, 2)
   375  
   376  	binary.LittleEndian.PutUint32(uid[0:4], cfg0)
   377  	binary.LittleEndian.PutUint32(uid[4:8], cfg1)
   378  
   379  	return
   380  }
   381  
   382  // Model returns the SoC model name.
   383  func Model() (model string) {
   384  	switch Family {
   385  	case IMX6UL:
   386  		model = "i.MX6UL"
   387  	case IMX6ULL:
   388  		cfg5, _ := OCOTP.Read(0, 6)
   389  
   390  		if (cfg5>>6)&1 == 1 {
   391  			model = "i.MX6ULZ"
   392  		} else {
   393  			model = "i.MX6ULL"
   394  		}
   395  	default:
   396  		model = "unknown"
   397  	}
   398  
   399  	return
   400  }