@@ -52,7 +52,7 @@ spisd_t sdcard;
5252struct block_device bd = {
5353 NULL , /* priv */
5454 "sdc" , /* name */
55- 0 , /* devNr */
55+ 1 , /* devNr, mx4sio is always in the second port */
5656 0 , /* parNr */
5757 0x00 , /* parId */
5858 SECTOR_SIZE , /* sectorSize */
@@ -64,7 +64,7 @@ struct block_device bd = {
6464 spisd_stop };
6565
6666/* NOTE: SIO2 does *NOT* allow for direct control of /CS line.
67- * It's controlled by the SIO2 hardware and automatically asserted at the start
67+ * It's controlled by the SIO2 hardware and automatically asserted at the start
6868 * of a transfer and deasserted at the end. This has lead to the need for some
6969 * conditions surrounding dummy writes to avoid timing disruption. */
7070static uint8_t spisd_send_cmd (uint8_t cmd , uint32_t arg )
@@ -123,12 +123,12 @@ static uint8_t spisd_send_cmd_recv_data(uint8_t cmd, uint32_t arg, uint8_t *data
123123static uint8_t spisd_read_register (uint8_t * buff , uint32_t len )
124124{
125125 uint8_t results = SPISD_RESULT_ERROR ;
126-
126+
127127 results = mx_sio2_wait_equal (0xFE , 2000 );
128128 if (results == SPISD_RESULT_OK ) {
129129 /* got read token, start SIO2 PIO RX transfer */
130130 mx_sio2_rx_pio (buff , len );
131- }
131+ }
132132
133133 return results ;
134134}
@@ -179,11 +179,11 @@ int spisd_init_card()
179179 /* send CMD8 with check pattern, store R3 response in buffer */
180180 response = spisd_send_cmd_recv_data (CMD8 , 0x1AA , buffer , sizeof (buffer ));
181181
182- /* if CMD8 response is idle, card is CSD v2 */
182+ /* if CMD8 response is idle, card is CSD v2 */
183183 if (response == SPISD_R1_IDLE_FLAG ) {
184-
184+
185185 /* valid check pattern */
186- if (buffer [2 ] == 0x01 && buffer [3 ] == 0xAA ) {
186+ if (buffer [2 ] == 0x01 && buffer [3 ] == 0xAA ) {
187187 /* CMD55 / ACMD41 pairs */
188188 for (int i = 0 ; i < 0xFFF ; i ++ ) {
189189 response = spisd_send_cmd (CMD55 , 0 );
@@ -262,7 +262,7 @@ int spisd_init_card()
262262 sdcard .card_type = CARD_TYPE_SDV1 ;
263263 M_DEBUG ("Card Type : CSD v1\r\n" );
264264 }
265-
265+
266266 /* set baud to 25MHz */
267267 mx_sio2_set_baud (SIO2_BAUD_DIV_FAST );
268268
@@ -280,7 +280,7 @@ int spisd_init_card()
280280 M_DEBUG ("ERROR: CMD16 returned 0x%x, exp 0x0\n" , response );
281281 return SPISD_RESULT_TIMEOUT ;
282282 }
283-
283+
284284 /* CMD8 response invalid */
285285 } else {
286286 M_DEBUG ("ERROR: CMD8 returned 0x%x, exp 0x1 or 0x4\n" , response );
@@ -295,15 +295,15 @@ int spisd_get_card_info()
295295{
296296 /* 16 bytes + 2 byte CRC16 */
297297 uint8_t reg_data [18 ];
298-
298+
299299 /* send CMD9, read CSD */
300300 uint8_t result = spisd_send_cmd (CMD9 , 0 );
301301 if (result != 0x0 ) {
302302 return result ;
303303 }
304304
305305 result = spisd_read_register (sdcard .csd , sizeof (reg_data ));
306-
306+
307307 /* dummy write between reg reads */
308308 mx_sio2_write_dummy ();
309309
@@ -319,7 +319,7 @@ int spisd_get_card_info()
319319 }
320320
321321 result = spisd_read_register (reg_data , sizeof (reg_data ));
322-
322+
323323 mx_sio2_write_dummy ();
324324
325325 if (result != 0x0 ) {
@@ -362,7 +362,7 @@ int spisd_get_card_info()
362362
363363 struct t_csdVer1 * csdv1 = (struct t_csdVer1 * )sdcard .csd ;
364364 struct t_csdVer2 * csdv2 = (struct t_csdVer2 * )sdcard .csd ;
365-
365+
366366 /* CSD v1 - SDSC */
367367 if (csdv1 -> csd_structure == 0 ) {
368368 unsigned int c_size_mult = (csdv1 -> c_size_multHi << 1 ) | csdv1 -> c_size_multLo ;
@@ -418,7 +418,7 @@ static int spisd_read_multi_begin(uint32_t sector)
418418 }
419419
420420 /* send CMD18 to being multi block read */
421- results = spisd_send_cmd (CMD18 , sector );
421+ results = spisd_send_cmd (CMD18 , sector );
422422 if (results == SPISD_RESULT_OK ) {
423423 /* wait for first read token (0xFE) */
424424 results = mx_sio2_wait_equal (0xFE , 100000 );
@@ -449,9 +449,9 @@ static int spisd_read_multi_do(void *buffer, uint16_t count)
449449
450450 if (resbits & EF_SIO2_INTR_REVERSE ) {
451451 ClearEventFlag (sio2_event_flag , ~EF_SIO2_INTR_REVERSE );
452-
452+
453453 while (cmd .sectors_reversed < cmd .sectors_transferred && cmd .abort == 0 ) {
454- void * buf = (uint32_t * )& cmd .buffer [cmd .sectors_reversed * SECTOR_SIZE ];
454+ void * buf = (uint32_t * )& cmd .buffer [cmd .sectors_reversed * SECTOR_SIZE ];
455455 reverse_buffer (buf , SECTOR_SIZE / 4 );
456456
457457#ifdef CONFIG_USE_CRC16
@@ -492,7 +492,7 @@ static void spisd_read_multi_end()
492492static int spisd_write_multi_begin (uint32_t sector , uint16_t count )
493493{
494494 uint8_t results = SPISD_RESULT_ERROR ;
495-
495+
496496 /* get idle */
497497 results = mx_sio2_wait_equal (0xFF , 4000 );
498498
@@ -517,7 +517,7 @@ static int spisd_write_multi_begin(uint32_t sector, uint16_t count)
517517 mx_sio2_write_dummy ();
518518
519519 return results ;
520- }
520+ }
521521
522522static int spisd_write_multi_do (void * buffer , uint16_t count )
523523{
@@ -533,7 +533,7 @@ static int spisd_write_multi_do(void* buffer, uint16_t count)
533533
534534 /* send initial write token */
535535 mx_sio2_write_byte (0xFC );
536-
536+
537537 /* start transfer */
538538 mx_sio2_start_tx_dma (buffer );
539539
@@ -603,10 +603,10 @@ int spisd_read(struct block_device *bd, uint64_t sector, void *buffer, uint16_t
603603 /* start reading blocks */
604604 results = spisd_read_multi_do (buffer , sectors_left );
605605 sectors_left = sectors_left - results ;
606-
606+
607607 /* fail condition */
608608 if (sectors_left > 0 ) {
609- buffer = (uint8_t * )buffer + (results * 512 );
609+ buffer = (uint8_t * )buffer + (results * 512 );
610610 M_DEBUG ("ERROR: failed to read all sectors, read:%i, abort:%i\n" , sectors_left , cmd .abort );
611611
612612 if (cmd .abort == CMD_ABORT_NO_READ_TOKEN ) {
@@ -633,7 +633,7 @@ int spisd_read(struct block_device *bd, uint64_t sector, void *buffer, uint16_t
633633int spisd_write (struct block_device * bd , uint64_t sector , const void * buffer , uint16_t count )
634634{
635635 (void )bd ;
636-
636+
637637 uint16_t sectors_left = count ;
638638 uint16_t results = 0 ;
639639 uint16_t retries = 0 ;
@@ -647,7 +647,7 @@ int spisd_write(struct block_device *bd, uint64_t sector, const void *buffer, ui
647647 void * write_buffer = (uint32_t * )buffer ;
648648
649649 /* pre-reverse the entire buffer */
650- reverse_buffer (write_buffer , ((count * SECTOR_SIZE ) / 4 ));
650+ reverse_buffer (write_buffer , ((count * SECTOR_SIZE ) / 4 ));
651651
652652 mx_sio2_lock (INTR_TX );
653653
@@ -681,7 +681,7 @@ int spisd_write(struct block_device *bd, uint64_t sector, const void *buffer, ui
681681 }
682682
683683 sdcard .used = 1 ;
684-
684+
685685 mx_sio2_unlock (INTR_TX );
686686
687687 return count - sectors_left ;
@@ -694,7 +694,7 @@ void spisd_flush(struct block_device *bd)
694694}
695695
696696int spisd_stop (struct block_device * bd )
697- {
697+ {
698698 (void )bd ;
699699 return 0 ;
700700}
0 commit comments