drain FIFO before SDHOST reset
authorchristinaa <tinab@tuta.io>
Tue, 3 Jan 2017 02:39:34 +0000 (02:39 +0000)
committerchristinaa <tinab@tuta.io>
Tue, 3 Jan 2017 02:39:34 +0000 (02:39 +0000)
arm_chainloader/drivers/sdhost_impl.cc

index 3f974b2..19ff449 100644 (file)
@@ -305,6 +305,16 @@ struct SdhostImpl : BlockDevice {
                }\r
        }\r
 \r
+       void drain_fifo_nowait() {\r
+               while (true) {\r
+                       SH_DATA;\r
+\r
+                       uint32_t hsts = SH_HSTS;\r
+                       if (hsts != SH_HSTS_DATA_FLAG_SET)\r
+                               break;\r
+               }\r
+       }\r
+\r
        virtual bool read_block(uint32_t sector, uint32_t* buf) override {\r
                if (!card_ready)\r
                        panic("card not ready");\r
@@ -496,6 +506,11 @@ struct SdhostImpl : BlockDevice {
        }\r
 \r
        virtual void stop() override {\r
+               if (card_ready) {\r
+                       logf("flushing fifo ...\n");\r
+                       drain_fifo_nowait();\r
+               }\r
+\r
                logf("stopping sdhost controller driver ...\n");\r
 \r
                SH_CMD = 0;\r
@@ -510,8 +525,11 @@ struct SdhostImpl : BlockDevice {
                SH_HBLC = 0;\r
                SH_HSTS = 0x7F8;\r
 \r
-               logf("controller down!\n");\r
-       }\r
+               logf("resetting state machine ...\n");\r
+\r
+               SH_CMD = 0;\r
+               SH_ARG = 0;\r
+       }\r
 \r
        SdhostImpl() {\r
                restart_controller();\r
This page took 0.032857 seconds and 4 git commands to generate.