github.com/f-secure-foundry/tamago@v0.0.0-20220307101044-d73fcdd7f11b/board/f-secure/usbarmory/mark-two/usdhc.go (about) 1 // USB armory Mk II 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 usbarmory 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 // SD instance 18 var SD = usdhc.USDHC1 19 20 // MMC instance 21 var MMC = usdhc.USDHC2 22 23 // SD/MMC configuration constants. 24 // 25 // On the USB armory Mk II the following uSDHC interfaces are connected: 26 // * uSDHC1: external uSD slot (SD1) 27 // * uSDHC2: internal eMMC card (SD2/NAND) 28 // 29 // On the USB armory Mk II β revision the maximum achievable theoretical speed 30 // modes are: 31 // * uSD: High Speed (HS) 25MB/s, 50MHz, 3.3V, 4-bit data bus 32 // * eMMC: High Speed (HS) DDR 104MB/s, 52MHz, 3.3V, 8-bit data bus 33 // 34 // On the USB armory Mk II γ revision the maximum achievable theoretical speed 35 // modes are: 36 // * uSD: SDR104 75MB/s, 150MHz, 1.8V, 4-bit data bus 37 // * eMMC: HS200 150MB/s, 150MHz, 1.8V, 8-bit data bus 38 const ( 39 IOMUXC_SW_MUX_CTL_PAD_CSI_DATA04 = 0x020e01f4 40 IOMUXC_SW_PAD_CTL_PAD_CSI_DATA04 = 0x020e0480 41 IOMUXC_USDHC1_WP_SELECT_INPUT = 0x020e066c 42 43 USDHC1_WP_MODE = 8 44 DAISY_CSI_DATA04 = 0b10 45 46 IOMUXC_SW_MUX_CTL_PAD_CSI_PIXCLK = 0x020e01d8 47 IOMUXC_SW_PAD_CTL_PAD_CSI_PIXCLK = 0x020e0464 48 IOMUXC_USDHC2_WP_SELECT_INPUT = 0x020e069c 49 50 USDHC2_WP_MODE = 1 51 DAISY_CSI_PIXCLK = 0b10 52 53 SD_BUS_WIDTH = 4 54 MMC_BUS_WIDTH = 8 55 56 PF1510_LDO3_VOLT = 0x52 57 LDO3_VOLT_1V8 = 0x10 58 LDO3_VOLT_3V3 = 0x1f 59 ) 60 61 func init() { 62 // There are no write-protect lines on uSD or eMMC cards, therefore the 63 // respective SoC pads must be selected on pulled down unconnected pads 64 // to ensure the driver never sees write protection enabled. 65 ctl := uint32((1 << imx6.SW_PAD_CTL_PUE) | (1 << imx6.SW_PAD_CTL_PKE)) 66 67 // SD write protect (USDHC1_WP) 68 wpSD, err := imx6.NewPad(IOMUXC_SW_MUX_CTL_PAD_CSI_DATA04, 69 IOMUXC_SW_PAD_CTL_PAD_CSI_DATA04, 70 IOMUXC_USDHC1_WP_SELECT_INPUT) 71 72 if err != nil { 73 panic(err) 74 } 75 76 // MMC write protect (USDHC2_WP) 77 wpMMC, err := imx6.NewPad(IOMUXC_SW_MUX_CTL_PAD_CSI_PIXCLK, 78 IOMUXC_SW_PAD_CTL_PAD_CSI_PIXCLK, 79 IOMUXC_USDHC2_WP_SELECT_INPUT) 80 81 if err != nil { 82 panic(err) 83 } 84 85 if !imx6.Native { 86 return 87 } 88 89 wpSD.Mode(USDHC1_WP_MODE) 90 wpSD.Select(DAISY_CSI_DATA04) 91 wpSD.Ctl(ctl) 92 93 wpMMC.Mode(USDHC2_WP_MODE) 94 wpMMC.Select(DAISY_CSI_PIXCLK) 95 wpMMC.Ctl(ctl) 96 97 SD.Init(SD_BUS_WIDTH) 98 MMC.Init(MMC_BUS_WIDTH) 99 100 switch Model() { 101 case "UA-MKII-β": 102 // β revisions do not support SDR104 (SD) or HS200 (MMC) 103 return 104 case "UA-MKII-γ": 105 SD.LowVoltage = lowVoltageSD 106 MMC.LowVoltage = lowVoltageMMC 107 } 108 } 109 110 func lowVoltageSD(enable bool) bool { 111 a := make([]byte, 1) 112 113 if enable { 114 a[0] = LDO3_VOLT_1V8 115 } else { 116 a[0] = LDO3_VOLT_3V3 117 } 118 119 err := imx6.I2C1.Write(a, PF1510_ADDR, PF1510_LDO3_VOLT, 1) 120 121 return err == nil 122 } 123 124 func lowVoltageMMC(enable bool) bool { 125 return true 126 }