1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 Daniel Ankers
11 * Copyright © 2008-2009 Rafaël Carré
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
23 /* Driver for the ARM PL180 SD/MMC controller inside AS3525 SoC */
25 /* TODO: Find the real capacity of >2GB models (will be useful for USB) */
27 #include "config.h" /* for HAVE_MULTIDRIVE & AMS_OF_SIZE */
38 #include "pl180.h" /* SD controller */
39 #include "pl081.h" /* DMA controller */
40 #include "dma-target.h" /* DMA request lines */
41 #include "clock-target.h"
43 #ifdef HAVE_BUTTON_LIGHT
44 #include "backlight-target.h"
47 #include "ata_idle_notify.h"
56 #define MCI_NO_FLAGS (0<<0)
57 #define MCI_RESP (1<<0)
58 #define MCI_LONG_RESP (1<<1)
59 #define MCI_ARG (1<<2)
61 /* ARM PL180 registers */
62 #define MCI_POWER(i) (*(volatile unsigned char *) (pl180_base[i]+0x00))
63 #define MCI_CLOCK(i) (*(volatile unsigned long *) (pl180_base[i]+0x04))
64 #define MCI_ARGUMENT(i) (*(volatile unsigned long *) (pl180_base[i]+0x08))
65 #define MCI_COMMAND(i) (*(volatile unsigned long *) (pl180_base[i]+0x0C))
66 #define MCI_RESPCMD(i) (*(volatile unsigned long *) (pl180_base[i]+0x10))
67 #define MCI_RESP0(i) (*(volatile unsigned long *) (pl180_base[i]+0x14))
68 #define MCI_RESP1(i) (*(volatile unsigned long *) (pl180_base[i]+0x18))
69 #define MCI_RESP2(i) (*(volatile unsigned long *) (pl180_base[i]+0x1C))
70 #define MCI_RESP3(i) (*(volatile unsigned long *) (pl180_base[i]+0x20))
71 #define MCI_DATA_TIMER(i) (*(volatile unsigned long *) (pl180_base[i]+0x24))
72 #define MCI_DATA_LENGTH(i) (*(volatile unsigned short*) (pl180_base[i]+0x28))
73 #define MCI_DATA_CTRL(i) (*(volatile unsigned char *) (pl180_base[i]+0x2C))
74 #define MCI_DATA_CNT(i) (*(volatile unsigned short*) (pl180_base[i]+0x30))
75 #define MCI_STATUS(i) (*(volatile unsigned long *) (pl180_base[i]+0x34))
76 #define MCI_CLEAR(i) (*(volatile unsigned long *) (pl180_base[i]+0x38))
77 #define MCI_MASK0(i) (*(volatile unsigned long *) (pl180_base[i]+0x3C))
78 #define MCI_MASK1(i) (*(volatile unsigned long *) (pl180_base[i]+0x40))
79 #define MCI_SELECT(i) (*(volatile unsigned long *) (pl180_base[i]+0x44))
80 #define MCI_FIFO_CNT(i) (*(volatile unsigned long *) (pl180_base[i]+0x48))
83 (MCI_DATA_CRC_FAIL | MCI_DATA_TIMEOUT | MCI_RX_OVERRUN | MCI_TX_UNDERRUN)
85 #define MCI_FIFO(i) ((unsigned long *) (pl180_base[i]+0x80))
87 #define INTERNAL_AS3525 0 /* embedded SD card */
88 #define SD_SLOT_AS3525 1 /* SD slot if present */
90 static const int pl180_base
[NUM_DRIVES
] = {
92 #ifdef HAVE_MULTIDRIVE
97 static int sd_wait_for_state(const int drive
, unsigned int state
);
98 static int sd_select_bank(signed char bank
);
99 static int sd_init_card(const int drive
);
100 static void init_pl180_controller(const int drive
);
101 #define SECTOR_SIZE 512 /* XXX: different sector sizes ? */
102 #define BLOCKS_PER_BANK 0x7a7800
104 static tCardInfo card_info
[NUM_DRIVES
];
106 /* maximum timeouts recommanded in the SD Specification v2.00 */
107 #define SD_MAX_READ_TIMEOUT ((AS3525_PCLK_FREQ) / 1000 * 100) /* 100 ms */
108 #define SD_MAX_WRITE_TIMEOUT ((AS3525_PCLK_FREQ) / 1000 * 250) /* 250 ms */
110 /* for compatibility */
111 static long last_disk_activity
= -1;
113 #define MIN_YIELD_PERIOD 5 /* ticks */
114 static long next_yield
= 0;
116 static long sd_stack
[(DEFAULT_STACK_SIZE
*2 + 0x200)/sizeof(long)];
117 static const char sd_thread_name
[] = "ata/sd";
118 static struct mutex sd_mtx
;
119 static struct event_queue sd_queue
;
121 static bool sd_enabled
= false;
124 static struct wakeup transfer_completion_signal
;
125 static volatile unsigned int transfer_error
[NUM_VOLUMES
];
126 #define PL180_MAX_TRANSFER_ERRORS 10
128 #define UNALIGNED_NUM_SECTORS 10
129 static unsigned char aligned_buffer
[UNALIGNED_NUM_SECTORS
* SECTOR_SIZE
] __attribute__((aligned(32))); /* align on cache line size */
130 static unsigned char *uncached_buffer
= UNCACHED_ADDR(&aligned_buffer
[0]);
132 static inline void mci_delay(void) { int i
= 0xffff; while(i
--) ; }
135 static int sd1_oneshot_callback(struct timeout
*tmo
)
139 /* This is called only if the state was stable for 300ms - check state
140 * and post appropriate event. */
141 if (card_detect_target())
143 queue_broadcast(SYS_HOTSWAP_INSERTED
, 0);
146 queue_broadcast(SYS_HOTSWAP_EXTRACTED
, 0);
153 static struct timeout sd1_oneshot
;
154 /* acknowledge interrupt */
156 timeout_register(&sd1_oneshot
, sd1_oneshot_callback
, (3*HZ
/10), 0);
158 #endif /* HAVE_HOTSWAP */
162 const int status
= MCI_STATUS(INTERNAL_AS3525
);
164 transfer_error
[INTERNAL_AS3525
] = status
& MCI_ERROR
;
166 wakeup_signal(&transfer_completion_signal
);
167 MCI_CLEAR(INTERNAL_AS3525
) = status
;
170 #ifdef HAVE_MULTIDRIVE
173 const int status
= MCI_STATUS(SD_SLOT_AS3525
);
175 transfer_error
[SD_SLOT_AS3525
] = status
& MCI_ERROR
;
177 wakeup_signal(&transfer_completion_signal
);
178 MCI_CLEAR(SD_SLOT_AS3525
) = status
;
182 static bool send_cmd(const int drive
, const int cmd
, const int arg
,
183 const int flags
, long *response
)
187 while(MCI_STATUS(drive
) & MCI_CMD_ACTIVE
);
189 if(MCI_COMMAND(drive
) & MCI_COMMAND_ENABLE
) /* clears existing command */
191 MCI_COMMAND(drive
) = 0;
195 val
= cmd
| MCI_COMMAND_ENABLE
;
198 val
|= MCI_COMMAND_RESPONSE
;
199 if(flags
& MCI_LONG_RESP
)
200 val
|= MCI_COMMAND_LONG_RESPONSE
;
203 MCI_CLEAR(drive
) = 0x7ff;
205 MCI_ARGUMENT(drive
) = (flags
& MCI_ARG
) ? arg
: 0;
206 MCI_COMMAND(drive
) = val
;
208 while(MCI_STATUS(drive
) & MCI_CMD_ACTIVE
); /* wait for cmd completion */
210 MCI_COMMAND(drive
) = 0;
211 MCI_ARGUMENT(drive
) = ~0;
213 status
= MCI_STATUS(drive
);
214 MCI_CLEAR(drive
) = 0x7ff;
218 if(status
& MCI_CMD_TIMEOUT
)
220 else if(status
& (MCI_CMD_CRC_FAIL
/* FIXME? */ | MCI_CMD_RESP_END
))
221 { /* resp received */
222 if(flags
& MCI_LONG_RESP
)
224 /* store the response in reverse words order */
225 response
[0] = MCI_RESP3(drive
);
226 response
[1] = MCI_RESP2(drive
);
227 response
[2] = MCI_RESP1(drive
);
228 response
[3] = MCI_RESP0(drive
);
231 response
[0] = MCI_RESP0(drive
);
235 else if(status
& MCI_CMD_SENT
)
241 static int sd_init_card(const int drive
)
243 unsigned long response
;
246 unsigned long temp_reg
[4];
249 if(!send_cmd(drive
, SD_GO_IDLE_STATE
, 0, MCI_NO_FLAGS
, NULL
))
254 /* CMD8 Check for v2 sd card */
255 if(send_cmd(drive
, SD_SEND_IF_COND
, 0x1AA, MCI_RESP
|MCI_ARG
, &response
))
256 if((response
& 0xFFF) == 0x1AA)
259 /* timeout for initialization is 1sec, from SD Specification 2.00 */
260 init_timeout
= current_tick
+ HZ
;
264 if(TIME_AFTER(current_tick
, init_timeout
))
268 if( !send_cmd(drive
, SD_APP_CMD
, 0, MCI_RESP
|MCI_ARG
, &response
) )
273 /* acmd41 If we have a v2 sd card set HCS bit[30] with voltage range */
274 if(!send_cmd(drive
, SD_APP_OP_COND
, (0x00FF8000 | (sd_v2
? 1<<30 : 0)),
275 MCI_RESP
|MCI_ARG
, &card_info
[drive
].ocr
))
280 } while(!(card_info
[drive
].ocr
& (1<<31)));
282 MCI_CLOCK(drive
) |= MCI_CLOCK_BYPASS
; /* full speed for controller clock */
286 if(!send_cmd(drive
, SD_ALL_SEND_CID
, 0, MCI_RESP
|MCI_LONG_RESP
|MCI_ARG
,
291 card_info
[drive
].cid
[3-i
] = temp_reg
[i
];
294 if(!send_cmd(drive
, SD_SEND_RELATIVE_ADDR
, 0, MCI_RESP
|MCI_ARG
,
295 &card_info
[drive
].rca
))
298 /* Select card to put it in TRAN state */
299 if(!send_cmd(drive
, SD_SELECT_CARD
, card_info
[drive
].rca
, MCI_ARG
, NULL
))
302 /* Try to switch V2 cards to HS timings, non HS seem to ignore this */
305 if(sd_wait_for_state(drive
, SD_TRAN
))
307 if(!send_cmd(drive
, SD_SWITCH_FUNC
, 0x80fffff1, MCI_ARG
, NULL
))
312 /* go back to STBY state so we can read csd */
313 if(!send_cmd(drive
, SD_DESELECT_CARD
, 0, MCI_ARG
, NULL
))
317 if(!send_cmd(drive
, SD_SEND_CSD
, card_info
[drive
].rca
,
318 MCI_RESP
|MCI_LONG_RESP
|MCI_ARG
, temp_reg
))
322 card_info
[drive
].csd
[3-i
] = temp_reg
[i
];
324 sd_parse_csd(&card_info
[drive
]);
326 /* Select card to put back in TRAN state */
327 if(!send_cmd(drive
, SD_SELECT_CARD
, card_info
[drive
].rca
, MCI_ARG
, NULL
))
331 * enable bank switching
332 * without issuing this command, we only have access to 1/4 of the blocks
333 * of the first bank (0x1E9E00 blocks, which is the size reported in the
336 if(drive
== INTERNAL_AS3525
)
338 const int ret
= sd_select_bank(-1);
343 card_info
[drive
].initialized
= 1;
348 static void sd_thread(void) __attribute__((noreturn
));
349 static void sd_thread(void)
351 struct queue_event ev
;
352 bool idle_notified
= false;
356 queue_wait_w_tmo(&sd_queue
, &ev
, HZ
);
361 case SYS_HOTSWAP_INSERTED
:
362 case SYS_HOTSWAP_EXTRACTED
:
364 int microsd_init
= 1;
365 fat_lock(); /* lock-out FAT activity first -
366 prevent deadlocking via disk_mount that
367 would cause a reverse-order attempt with
369 mutex_lock(&sd_mtx
); /* lock-out card activity - direct calls
370 into driver that bypass the fat cache */
372 /* We now have exclusive control of fat cache and ata */
374 disk_unmount(SD_SLOT_AS3525
); /* release "by force", ensure file
375 descriptors aren't leaked and any busy
376 ones are invalid if mounting */
378 /* Force card init for new card, re-init for re-inserted one or
379 * clear if the last attempt to init failed with an error. */
380 card_info
[SD_SLOT_AS3525
].initialized
= 0;
382 if (ev
.id
== SYS_HOTSWAP_INSERTED
)
385 init_pl180_controller(SD_SLOT_AS3525
);
386 microsd_init
= sd_init_card(SD_SLOT_AS3525
);
387 if (microsd_init
< 0) /* initialisation failed */
388 panicf("microSD init failed : %d", microsd_init
);
390 microsd_init
= disk_mount(SD_SLOT_AS3525
); /* 0 if fail */
394 * Mount succeeded, or this was an EXTRACTED event,
395 * in both cases notify the system about the changed filesystems
398 queue_broadcast(SYS_FS_CHANGED
, 0);
400 /* Access is now safe */
401 mutex_unlock(&sd_mtx
);
408 if (TIME_BEFORE(current_tick
, last_disk_activity
+(3*HZ
)))
410 idle_notified
= false;
414 /* never let a timer wrap confuse us */
415 next_yield
= current_tick
;
419 call_storage_idle_notifys(false);
420 idle_notified
= true;
425 case SYS_USB_CONNECTED
:
426 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
427 /* Wait until the USB cable is extracted again */
428 usb_wait_for_disconnect(&sd_queue
);
431 case SYS_USB_DISCONNECTED
:
432 usb_acknowledge(SYS_USB_DISCONNECTED_ACK
);
438 static void init_pl180_controller(const int drive
)
440 MCI_COMMAND(drive
) = MCI_DATA_CTRL(drive
) = 0;
441 MCI_CLEAR(drive
) = 0x7ff;
443 MCI_MASK0(drive
) = MCI_MASK1(drive
) = MCI_ERROR
| MCI_DATA_END
;
445 #ifdef HAVE_MULTIDRIVE
447 (drive
== INTERNAL_AS3525
) ? INTERRUPT_NAND
: INTERRUPT_MCI0
;
449 /* setup isr for microsd monitoring */
450 VIC_INT_ENABLE
|= (INTERRUPT_GPIOA
);
451 /* clear previous irq */
453 /* enable edge detecting */
455 /* detect both raising and falling edges */
459 VIC_INT_ENABLE
|= INTERRUPT_NAND
;
462 MCI_POWER(drive
) = MCI_POWER_UP
|(10 /*voltage*/ << 2); /* use OF voltage */
465 MCI_POWER(drive
) |= MCI_POWER_ON
;
468 MCI_SELECT(drive
) = 0;
470 MCI_CLOCK(drive
) = MCI_CLOCK_ENABLE
| AS3525_SD_IDENT_DIV
;
477 CGU_IDE
= (1<<7) /* AHB interface enable */ |
478 (1<<6) /* interface enable */ |
479 (AS3525_IDE_DIV
<< 2) |
480 AS3525_CLK_PLLA
; /* clock source = PLLA */
483 CGU_PERI
|= CGU_NAF_CLOCK_ENABLE
;
484 #ifdef HAVE_MULTIDRIVE
485 CGU_PERI
|= CGU_MCI_CLOCK_ENABLE
;
486 CCU_IO
&= ~(1<<3); /* bits 3:2 = 01, xpd is SD interface */
490 wakeup_init(&transfer_completion_signal
);
492 init_pl180_controller(INTERNAL_AS3525
);
493 ret
= sd_init_card(INTERNAL_AS3525
);
496 #ifdef HAVE_MULTIDRIVE
497 init_pl180_controller(SD_SLOT_AS3525
);
503 queue_init(&sd_queue
, true);
504 create_thread(sd_thread
, sd_stack
, sizeof(sd_stack
), 0,
505 sd_thread_name
IF_PRIO(, PRIORITY_USER_INTERFACE
) IF_COP(, CPU
));
515 bool sd_removable(IF_MD_NONVOID(int drive
))
520 bool sd_present(IF_MD_NONVOID(int drive
))
522 return (drive
== 0) ? true : card_detect_target();
524 #endif /* HAVE_HOTSWAP */
526 static int sd_wait_for_state(const int drive
, unsigned int state
)
528 unsigned long response
= 0;
529 unsigned int timeout
= 100; /* ticks */
530 long t
= current_tick
;
536 if(!send_cmd(drive
, SD_SEND_STATUS
, card_info
[drive
].rca
,
537 MCI_RESP
|MCI_ARG
, &response
))
540 if (((response
>> 9) & 0xf) == state
)
543 if(TIME_AFTER(current_tick
, t
+ timeout
))
546 if (TIME_AFTER((tick
= current_tick
), next_yield
))
549 timeout
+= current_tick
- tick
;
550 next_yield
= tick
+ MIN_YIELD_PERIOD
;
555 static int sd_select_bank(signed char bank
)
561 if(loops
++ > PL180_MAX_TRANSFER_ERRORS
)
562 panicf("SD bank %d error : 0x%x", bank
,
563 transfer_error
[INTERNAL_AS3525
]);
565 ret
= sd_wait_for_state(INTERNAL_AS3525
, SD_TRAN
);
569 if(!send_cmd(INTERNAL_AS3525
, SD_SWITCH_FUNC
, 0x80ffffef, MCI_ARG
, NULL
))
574 if(!send_cmd(INTERNAL_AS3525
, 35, 0, MCI_NO_FLAGS
, NULL
))
579 memset(uncached_buffer
, 0, 512);
581 { /* enable bank switching */
582 uncached_buffer
[0] = 16;
583 uncached_buffer
[1] = 1;
584 uncached_buffer
[2] = 10;
587 uncached_buffer
[0] = bank
;
590 /* we don't use the uncached buffer here, because we need the
591 * physical memory address for DMA transfers */
592 dma_enable_channel(0, aligned_buffer
, MCI_FIFO(INTERNAL_AS3525
),
593 DMA_PERI_SD
, DMAC_FLOWCTRL_PERI_MEM_TO_PERI
, true, false, 0, DMA_S8
,
596 MCI_DATA_TIMER(INTERNAL_AS3525
) = SD_MAX_WRITE_TIMEOUT
;
597 MCI_DATA_LENGTH(INTERNAL_AS3525
) = 512;
598 MCI_DATA_CTRL(INTERNAL_AS3525
) = (1<<0) /* enable */ |
599 (0<<1) /* transfer direction */ |
601 (9<<4) /* 2^9 = 512 */ ;
603 wakeup_wait(&transfer_completion_signal
, TIMEOUT_BLOCK
);
605 /* Wait for FIFO to empty */
606 while(MCI_STATUS(INTERNAL_AS3525
) & (MCI_TX_ACTIVE
| MCI_RX_ACTIVE
));
610 ret
= sd_wait_for_state(INTERNAL_AS3525
, SD_TRAN
);
613 } while(transfer_error
[INTERNAL_AS3525
]);
615 card_info
[INTERNAL_AS3525
].current_bank
= (bank
== -1) ? 0 : bank
;
620 static int sd_transfer_sectors(IF_MD2(int drive
,) unsigned long start
,
621 int count
, void* buf
, const bool write
)
623 #ifndef HAVE_MULTIDRIVE
629 /* skip SanDisk OF */
630 if (drive
== INTERNAL_AS3525
)
631 start
+= AMS_OF_SIZE
;
639 if (card_info
[drive
].initialized
<= 0)
641 ret
= sd_init_card(drive
);
642 if (!(card_info
[drive
].initialized
))
643 goto sd_transfer_error
;
646 last_disk_activity
= current_tick
;
648 ret
= sd_wait_for_state(drive
, SD_TRAN
);
652 goto sd_transfer_error
;
659 /* 128 * 512 = 2^16, and doesn't fit in the 16 bits of DATA_LENGTH
660 * register, so we have to transfer maximum 127 sectors at a time. */
661 unsigned int transfer
= (count
>= 128) ? 127 : count
; /* sectors */
664 write
? SD_WRITE_MULTIPLE_BLOCK
: SD_READ_MULTIPLE_BLOCK
;
665 unsigned long bank_start
= start
;
667 /* Only switch banks for internal storage */
668 if(drive
== INTERNAL_AS3525
)
670 unsigned int bank
= start
/ BLOCKS_PER_BANK
; /* Current bank */
672 /* Switch bank if needed */
673 if(card_info
[INTERNAL_AS3525
].current_bank
!= bank
)
675 ret
= sd_select_bank(bank
);
679 goto sd_transfer_error
;
683 /* Adjust start block in current bank */
684 bank_start
-= bank
* BLOCKS_PER_BANK
;
686 /* Do not cross a bank boundary in a single transfer loop */
687 if((transfer
+ bank_start
) > BLOCKS_PER_BANK
)
688 transfer
= BLOCKS_PER_BANK
- bank_start
;
691 dma_buf
= aligned_buffer
;
692 if(transfer
> UNALIGNED_NUM_SECTORS
)
693 transfer
= UNALIGNED_NUM_SECTORS
;
695 memcpy(uncached_buffer
, buf
, transfer
* SECTOR_SIZE
);
697 /* Set bank_start to the correct unit (blocks or bytes) */
698 if(!(card_info
[drive
].ocr
& (1<<30))) /* not SDHC */
699 bank_start
*= SD_BLOCK_SIZE
;
701 if(!send_cmd(drive
, cmd
, bank_start
, MCI_ARG
, NULL
))
704 goto sd_transfer_error
;
708 dma_enable_channel(0, dma_buf
, MCI_FIFO(drive
),
709 (drive
== INTERNAL_AS3525
) ? DMA_PERI_SD
: DMA_PERI_SD_SLOT
,
710 DMAC_FLOWCTRL_PERI_MEM_TO_PERI
, true, false, 0, DMA_S8
, NULL
);
712 dma_enable_channel(0, MCI_FIFO(drive
), dma_buf
,
713 (drive
== INTERNAL_AS3525
) ? DMA_PERI_SD
: DMA_PERI_SD_SLOT
,
714 DMAC_FLOWCTRL_PERI_PERI_TO_MEM
, false, true, 0, DMA_S8
, NULL
);
716 /* FIXME : we should check if the timeouts calculated from the card's
717 * CSD are lower, and use them if it is the case
718 * Note : the OF doesn't seem to use them anyway */
719 MCI_DATA_TIMER(drive
) = write
?
720 SD_MAX_WRITE_TIMEOUT
: SD_MAX_READ_TIMEOUT
;
721 MCI_DATA_LENGTH(drive
) = transfer
* card_info
[drive
].blocksize
;
722 MCI_DATA_CTRL(drive
) = (1<<0) /* enable */ |
723 (!write
<<1) /* transfer direction */ |
725 (9<<4) /* 2^9 = 512 */ ;
728 wakeup_wait(&transfer_completion_signal
, TIMEOUT_BLOCK
);
730 /* Wait for FIFO to empty */
731 while(MCI_STATUS(drive
) & (MCI_TX_ACTIVE
| MCI_RX_ACTIVE
));
733 if(!transfer_error
[drive
])
736 memcpy(buf
, uncached_buffer
, transfer
* SECTOR_SIZE
);
737 buf
+= transfer
* SECTOR_SIZE
;
740 loops
= 0; /* reset errors counter */
742 else if(loops
++ > PL180_MAX_TRANSFER_ERRORS
)
743 panicf("SD transfer error : 0x%x", transfer_error
[drive
]);
745 last_disk_activity
= current_tick
;
747 if(!send_cmd(drive
, SD_STOP_TRANSMISSION
, 0, MCI_NO_FLAGS
, NULL
))
750 goto sd_transfer_error
;
753 ret
= sd_wait_for_state(drive
, SD_TRAN
);
757 goto sd_transfer_error
;
761 ret
= 0; /* success */
773 card_info
[drive
].initialized
= 0;
775 mutex_unlock(&sd_mtx
);
779 int sd_read_sectors(IF_MD2(int drive
,) unsigned long start
, int count
,
782 return sd_transfer_sectors(IF_MD2(drive
,) start
, count
, buf
, false);
785 int sd_write_sectors(IF_MD2(int drive
,) unsigned long start
, int count
,
789 #ifdef BOOTLOADER /* we don't need write support in bootloader */
790 #ifdef HAVE_MULTIDRIVE
798 return sd_transfer_sectors(IF_MD2(drive
,) start
, count
, (void*)buf
, true);
803 long sd_last_disk_activity(void)
805 return last_disk_activity
;
808 void sd_enable(bool on
)
810 /* buttonlight AMSes need a bit of special handling for the buttonlight here
811 * due to the dual mapping of GPIOD and XPD */
812 #if defined(HAVE_BUTTON_LIGHT) && defined(HAVE_MULTIDRIVE)
813 extern int buttonlight_is_on
;
817 static bool cpu_boosted
= false;
820 if (sd_enabled
== on
)
821 return; /* nothing to do */
824 CGU_PERI
|= CGU_NAF_CLOCK_ENABLE
;
825 #ifdef HAVE_MULTIDRIVE
826 CGU_PERI
|= CGU_MCI_CLOCK_ENABLE
;
827 #ifdef HAVE_BUTTON_LIGHT
829 if (buttonlight_is_on
)
830 GPIOD_DIR
&= ~(1<<7);
833 #endif /* HAVE_BUTTON_LIGHT */
834 #endif /* HAVE_MULTIDRIVE */
835 CGU_IDE
|= (1<<7) /* AHB interface enable */ |
836 (1<<6) /* interface enable */;
840 if(card_detect_target()) /* If SD card present Boost cpu for voltage */
849 CGU_PERI
&= ~CGU_NAF_CLOCK_ENABLE
;
850 #ifdef HAVE_MULTIDRIVE
851 #ifdef HAVE_BUTTON_LIGHT
853 if (buttonlight_is_on
)
855 #endif /* HAVE_BUTTON_LIGHT */
856 CGU_PERI
&= ~CGU_MCI_CLOCK_ENABLE
;
857 #endif /* HAVE_MULTIDRIVE */
858 CGU_IDE
&= ~((1<<7)|(1<<6));
871 tCardInfo
*card_get_info_target(int card_no
)
873 return &card_info
[card_no
];
876 bool card_detect_target(void)
878 #if defined(HAVE_MULTIDRIVE)
879 return !(GPIOA_PIN(2));
886 void card_enable_monitoring_target(bool on
)
888 if (on
) /* enable interrupt */
890 else /* disable interrupt */
893 #endif /* HAVE_HOTSWAP */
895 #endif /* !BOOTLOADER */
897 #ifdef CONFIG_STORAGE_MULTI
898 int sd_num_drives(int first_drive
)
900 /* We don't care which logical drive number(s) we have been assigned */
905 #endif /* CONFIG_STORAGE_MULTI */