make some stupid assumptions about sd cards and reclock them before transitioning...
authorchristinaa <tinab@tuta.io>
Tue, 3 Jan 2017 08:46:30 +0000 (08:46 +0000)
committerchristinaa <tinab@tuta.io>
Tue, 3 Jan 2017 08:46:30 +0000 (08:46 +0000)
arm_chainloader/drivers/sdhost_impl.cc

index 4a0991a..c9b1421 100644 (file)
@@ -62,9 +62,34 @@ SDHOST driver. This used to be known as ALTMMC.
 #define SDHSTS_TRANSFER_ERROR_MASK      (SDHSTS_CRC7_ERROR|SDHSTS_CRC16_ERROR|SDHSTS_REW_TIME_OUT|SDHSTS_FIFO_ERROR)\r
 #define SDHSTS_ERROR_MASK               (SDHSTS_CMD_TIME_OUT|SDHSTS_TRANSFER_ERROR_MASK)\r
 \r
+#define logf(fmt, ...) printf("[GPIO:%s]: " fmt, __FUNCTION__, ##__VA_ARGS__);\r
+\r
+enum BCM2708PinmuxSetting {\r
+       kBCM2708PinmuxIn = 0,\r
+       kBCM2708PinmuxOut = 1,\r
+       kBCM2708Pinmux_ALT5 = 2,\r
+       kBCM2708Pinmux_ALT4 = 3,\r
+       kBCM2708Pinmux_ALT0 = 4,\r
+       kBCM2708Pinmux_ALT1 = 5,\r
+       kBCM2708Pinmux_ALT2 = 6,\r
+       kBCM2708Pinmux_ALT3 = 7\r
+};\r
+\r
+struct BCM2708GPIO {\r
+\r
+       static void set(uint32_t pin_num, BCM2708PinmuxSetting setting) {\r
+               uint32_t* fsel = reinterpret_cast<uint32_t*>(\r
+                       reinterpret_cast<uint32_t>(&GP_FSEL0) + (0x4 * (pin_num/10))\r
+               );\r
+               uint32_t pin_shift = (pin_num % 10) * 3;\r
+\r
+       }\r
+};\r
+\r
+#undef logf\r
 #define logf(fmt, ...) printf("[EMMC:%s]: " fmt, __FUNCTION__, ##__VA_ARGS__);\r
 \r
-struct SdhostImpl : BlockDevice {\r
+struct BCM2708SDHost : BlockDevice {\r
        bool is_sdhc;\r
        bool is_high_capacity;\r
        bool card_ready;\r
@@ -397,6 +422,7 @@ struct SdhostImpl : BlockDevice {
        bool init_card() {\r
                char pnm[8];\r
                uint32_t block_length;\r
+               uint32_t clock_div = 0;\r
 \r
                send_no_resp(MMC_GO_IDLE_STATE);\r
 \r
@@ -424,6 +450,8 @@ struct SdhostImpl : BlockDevice {
 \r
                        /* work out the capacity of the card in bytes */\r
                        capacity_bytes = (SD_CSD_V2_CAPACITY(csd) * block_length);\r
+\r
+                       clock_div = 5;\r
                }\r
                else if (SD_CSD_CSDVER(csd) == SD_CSD_CSDVER_1_0) {\r
                        printf("    CSD     : Ver 1.0\n");\r
@@ -433,7 +461,9 @@ struct SdhostImpl : BlockDevice {
                        block_length = 1 << SD_CSD_READ_BL_LEN(csd);\r
 \r
                        /* work out the capacity of the card in bytes */\r
-                       capacity_bytes = (SD_CSD_CAPACITY(csd) * block_length); \r
+                       capacity_bytes = (SD_CSD_CAPACITY(csd) * block_length);\r
+\r
+                       clock_div = 10;\r
                }\r
                else {\r
                        printf("ERROR: Unknown CSD version 0x%x!\n", SD_CSD_CSDVER(csd));\r
@@ -464,6 +494,15 @@ struct SdhostImpl : BlockDevice {
 \r
                logf("Card initialization complete: %s %dMB SD%s Card\n", &pnm, capacity_bytes >> 20, is_high_capacity ? "HC" : "");\r
 \r
+               /*\r
+                * this makes some dangerous assumptions that the all csd2 cards are sdio cards\r
+                * and all csd1 cards are sd cards and that mmc cards won't be used.\r
+                */\r
+               if (clock_div) {\r
+                       logf("Indentification complete, changing clock to %dMHz for data mode ...", 250 / clock_div);\r
+                       SH_CDIV = clock_div - 2;\r
+               }\r
+\r
                return true;\r
        }\r
 \r
@@ -531,13 +570,13 @@ struct SdhostImpl : BlockDevice {
                SH_ARG = 0;\r
        }\r
 \r
-       SdhostImpl() {\r
+       BCM2708SDHost() {\r
                restart_controller();\r
                logf("eMMC driver sucessfully started!\n");\r
        }\r
 };\r
 \r
-SdhostImpl STATIC_DRIVER g_SDHostDriver {};\r
+BCM2708SDHost STATIC_DRIVER g_SDHostDriver {};\r
 \r
 BlockDevice* get_sdhost_device() {\r
        return &g_SDHostDriver;\r
This page took 0.030908 seconds and 4 git commands to generate.