github.com/f-secure-foundry/tamago@v0.0.0-20220307101044-d73fcdd7f11b/board/nxp/mx6ullevk/usdhc.go (about)

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