@@ -70,23 +70,6 @@ struct ssi_sd_state {
7070#define TYPE_SSI_SD "ssi-sd"
7171OBJECT_DECLARE_SIMPLE_TYPE (ssi_sd_state , SSI_SD )
7272
73- /* State word bits. */
74- #define SSI_SDR_LOCKED 0x0001
75- #define SSI_SDR_WP_ERASE 0x0002
76- #define SSI_SDR_ERROR 0x0004
77- #define SSI_SDR_CC_ERROR 0x0008
78- #define SSI_SDR_ECC_FAILED 0x0010
79- #define SSI_SDR_WP_VIOLATION 0x0020
80- #define SSI_SDR_ERASE_PARAM 0x0040
81- #define SSI_SDR_OUT_OF_RANGE 0x0080
82- #define SSI_SDR_IDLE 0x0100
83- #define SSI_SDR_ERASE_RESET 0x0200
84- #define SSI_SDR_ILLEGAL_COMMAND 0x0400
85- #define SSI_SDR_COM_CRC_ERROR 0x0800
86- #define SSI_SDR_ERASE_SEQ_ERROR 0x1000
87- #define SSI_SDR_ADDRESS_ERROR 0x2000
88- #define SSI_SDR_PARAMETER_ERROR 0x4000
89-
9073/* multiple block write */
9174#define SSI_TOKEN_MULTI_WRITE 0xfc
9275/* terminate multiple block write */
@@ -104,7 +87,7 @@ static uint32_t ssi_sd_transfer(SSIPeripheral *dev, uint32_t val)
10487{
10588 ssi_sd_state * s = SSI_SD (dev );
10689 SDRequest request ;
107- uint8_t longresp [16 ];
90+ uint8_t longresp [5 ];
10891
10992 /*
11093 * Special case: allow CMD12 (STOP TRANSMISSION) while reading data.
@@ -171,74 +154,18 @@ static uint32_t ssi_sd_transfer(SSIPeripheral *dev, uint32_t val)
171154 /* FIXME: Check CRC. */
172155 request .cmd = s -> cmd ;
173156 request .arg = ldl_be_p (s -> cmdarg );
174- DPRINTF ("CMD%d arg 0x%08x\n" , s -> cmd , request .arg );
175157 s -> arglen = sdbus_do_command (& s -> sdbus , & request ,
176158 longresp , sizeof (longresp ));
177- if (s -> arglen == 0 ) {
178- s -> arglen = 1 ;
179- s -> response [0 ] = 4 ;
180- DPRINTF ("SD command failed\n" );
181- } else if (s -> cmd == 8 || s -> cmd == 58 ) {
182- /* CMD8/CMD58 returns R3/R7 response */
183- DPRINTF ("Returned R3/R7\n" );
184- s -> arglen = 5 ;
185- s -> response [0 ] = 1 ;
186- memcpy (& s -> response [1 ], longresp , 4 );
187- } else if (s -> arglen != 4 ) {
188- BADF ("Unexpected response to cmd %d\n" , s -> cmd );
189- /* Illegal command is about as near as we can get. */
190- s -> arglen = 1 ;
191- s -> response [0 ] = 4 ;
192- } else {
193- /* All other commands return status. */
194- uint32_t cardstatus ;
195- uint16_t status ;
159+ DPRINTF ("CMD%d arg 0x%08x = %d\n" , s -> cmd , request .arg , s -> arglen );
160+ assert (s -> arglen > 0 );
196161 /* CMD13 returns a 2-byte statuse work. Other commands
197162 only return the first byte. */
198163 s -> arglen = (s -> cmd == 13 ) ? 2 : 1 ;
164+ memcpy (s -> response , longresp , s -> arglen );
199165
200- /* handle R1b */
201- if (s -> cmd == 28 || s -> cmd == 29 || s -> cmd == 38 ) {
202- s -> stopping = 1 ;
203- }
204-
205- cardstatus = ldl_be_p (longresp );
206- status = 0 ;
207- if (((cardstatus >> 9 ) & 0xf ) < 4 )
208- status |= SSI_SDR_IDLE ;
209- if (cardstatus & ERASE_RESET )
210- status |= SSI_SDR_ERASE_RESET ;
211- if (cardstatus & ILLEGAL_COMMAND )
212- status |= SSI_SDR_ILLEGAL_COMMAND ;
213- if (cardstatus & COM_CRC_ERROR )
214- status |= SSI_SDR_COM_CRC_ERROR ;
215- if (cardstatus & ERASE_SEQ_ERROR )
216- status |= SSI_SDR_ERASE_SEQ_ERROR ;
217- if (cardstatus & ADDRESS_ERROR )
218- status |= SSI_SDR_ADDRESS_ERROR ;
219- if (cardstatus & CARD_IS_LOCKED )
220- status |= SSI_SDR_LOCKED ;
221- if (cardstatus & (LOCK_UNLOCK_FAILED | WP_ERASE_SKIP ))
222- status |= SSI_SDR_WP_ERASE ;
223- if (cardstatus & SD_ERROR )
224- status |= SSI_SDR_ERROR ;
225- if (cardstatus & CC_ERROR )
226- status |= SSI_SDR_CC_ERROR ;
227- if (cardstatus & CARD_ECC_FAILED )
228- status |= SSI_SDR_ECC_FAILED ;
229- if (cardstatus & WP_VIOLATION )
230- status |= SSI_SDR_WP_VIOLATION ;
231- if (cardstatus & ERASE_PARAM )
232- status |= SSI_SDR_ERASE_PARAM ;
233- if (cardstatus & (OUT_OF_RANGE | CID_CSD_OVERWRITE ))
234- status |= SSI_SDR_OUT_OF_RANGE ;
235- /* ??? Don't know what Parameter Error really means, so
236- assume it's set if the second byte is nonzero. */
237- if (status & 0xff )
238- status |= SSI_SDR_PARAMETER_ERROR ;
239- s -> response [0 ] = status >> 8 ;
240- s -> response [1 ] = status ;
241- DPRINTF ("Card status 0x%02x\n" , status );
166+ /* handle R1b (busy signal) */
167+ if (s -> cmd == 28 || s -> cmd == 29 || s -> cmd == 38 ) {
168+ s -> stopping = 1 ;
242169 }
243170 s -> mode = SSI_SD_PREP_RESP ;
244171 s -> response_pos = 0 ;
0 commit comments