github.com/usbarmory/tamago@v0.0.0-20240508072735-8612bbe1e454/board/nxp/mx6ullevk/usdhc.go (about)

     1  // MCIMX6ULL-EVK support for tamago/arm
     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 mx6ullevk
    11  
    12  import (
    13  	"github.com/usbarmory/tamago/soc/nxp/iomuxc"
    14  )
    15  
    16  // SD1 is the base board full size SD instance
    17  var SD1 = USDHC1
    18  
    19  // SD2 is the CPU board microSD instance
    20  var SD2 = USDHC2
    21  
    22  // SD1/SD2 configuration constants.
    23  //
    24  // On the MCIMX6ULL-EVK the following uSDHC interfaces are connected:
    25  //   - uSDHC1: base board full size SD slot (SD1)
    26  //   - uSDHC2: CPU board microSD slot (SD2)
    27  const (
    28  	IOMUXC_SW_MUX_CTL_PAD_CSI_DATA04 = 0x020e01f4
    29  	IOMUXC_SW_PAD_CTL_PAD_CSI_DATA04 = 0x020e0480
    30  	IOMUXC_USDHC1_WP_SELECT_INPUT    = 0x020e066c
    31  
    32  	USDHC1_WP_MODE   = 8
    33  	DAISY_CSI_DATA04 = 0b10
    34  
    35  	IOMUXC_SW_MUX_CTL_PAD_CSI_PIXCLK = 0x020e01d8
    36  	IOMUXC_SW_PAD_CTL_PAD_CSI_PIXCLK = 0x020e0464
    37  	IOMUXC_USDHC2_WP_SELECT_INPUT    = 0x020e069c
    38  
    39  	USDHC2_WP_MODE   = 1
    40  	DAISY_CSI_PIXCLK = 0b10
    41  
    42  	SD1_BUS_WIDTH = 4
    43  	SD2_BUS_WIDTH = 4
    44  )
    45  
    46  func init() {
    47  	// There are no write-protect lines on uSD cards. The write-protect
    48  	// line on the full size slot is not connected. Therefore the
    49  	// respective SoC pads must be selected on pulled down unconnected pads
    50  	// to ensure the driver never see write protection enabled.
    51  	ctl := uint32((1 << iomuxc.SW_PAD_CTL_PUE) | (1 << iomuxc.SW_PAD_CTL_PKE))
    52  
    53  	// SD write protect (USDHC1_WP)
    54  	wpSD1 := &iomuxc.Pad{
    55  		Mux:   IOMUXC_SW_MUX_CTL_PAD_CSI_DATA04,
    56  		Pad:   IOMUXC_SW_PAD_CTL_PAD_CSI_DATA04,
    57  		Daisy: IOMUXC_USDHC1_WP_SELECT_INPUT,
    58  	}
    59  
    60  	// SD2 write protect (USDHC2_WP)
    61  	wpSD2 := &iomuxc.Pad{
    62  		Mux:   IOMUXC_SW_MUX_CTL_PAD_CSI_PIXCLK,
    63  		Pad:   IOMUXC_SW_PAD_CTL_PAD_CSI_PIXCLK,
    64  		Daisy: IOMUXC_USDHC2_WP_SELECT_INPUT,
    65  	}
    66  
    67  	wpSD1.Mode(USDHC1_WP_MODE)
    68  	wpSD1.Select(DAISY_CSI_DATA04)
    69  	wpSD1.Ctl(ctl)
    70  
    71  	wpSD2.Mode(USDHC2_WP_MODE)
    72  	wpSD2.Select(DAISY_CSI_PIXCLK)
    73  	wpSD2.Ctl(ctl)
    74  
    75  	SD1.Init(SD1_BUS_WIDTH)
    76  	SD2.Init(SD2_BUS_WIDTH)
    77  
    78  	// Only SD1 supports 1.8V switching on this board.
    79  	SD1.LowVoltage = func(enable bool) bool {
    80  		// No actual function is required as VEND_SPEC_VSELECT, already
    81  		// set by the usdhc driver, is used on this board circuitry to
    82  		// switch to LV.
    83  		return true
    84  	}
    85  }