]>
git.proxmox.com Git - mirror_edk2.git/blob - QuarkSocPkg/QuarkSouthCluster/Sdio/Dxe/SDMediaDeviceDxe/CEATA.c
0261295cbf7842a0c847d870470d3a77b30e3448
3 CEATA specific functions implementation
5 Copyright (c) 2013-2015 Intel Corporation.
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "SDMediaDevice.h"
20 Send RW_MULTIPLE_REGISTER command
22 @param CardData Pointer to CARD_DATA.
23 @param Address Register address.
24 @param ByteCount Buffer size.
25 @param Write TRUE means write, FALSE means read.
26 @param Buffer Buffer pointer.
28 @retval EFI_SUCCESS Success
29 @retval EFI_DEVICE_ERROR Hardware Error
30 @retval EFI_INVALID_PARAMETER Parameter is error
31 @retval EFI_NO_MEDIA No media
32 @retval EFI_MEDIA_CHANGED Media Change
33 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
37 ReadWriteMultipleRegister (
38 IN CARD_DATA
*CardData
,
50 if ((Address
% 4 != 0) || (ByteCount
% 4 != 0)) {
51 Status
= EFI_INVALID_PARAMETER
;
55 Argument
= (Address
<< 16) | ByteCount
;
62 CopyMem (CardData
->AlignedBuffer
, Buffer
, ByteCount
);
64 Status
= SendCommand (
69 CardData
->AlignedBuffer
,
73 (UINT32
*)&(CardData
->CardStatus
)
76 Status
= SendCommand (
81 CardData
->AlignedBuffer
,
85 (UINT32
*)&(CardData
->CardStatus
)
87 if (!EFI_ERROR (Status
)) {
88 CopyMem (Buffer
, CardData
->AlignedBuffer
, ByteCount
);
97 Send ReadWriteMultipleBlock command with RW_MULTIPLE_REGISTER command
99 @param CardData Pointer to CARD_DATA.
100 @param DataUnitCount Buffer size in 512 bytes unit.
101 @param Write TRUE means write, FALSE means read.
102 @param Buffer Buffer pointer.
104 @retval EFI_SUCCESS Success
105 @retval EFI_DEVICE_ERROR Hardware Error
106 @retval EFI_INVALID_PARAMETER Parameter is error
107 @retval EFI_NO_MEDIA No media
108 @retval EFI_MEDIA_CHANGED Media Change
109 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
113 ReadWriteMultipleBlock (
114 IN CARD_DATA
*CardData
,
115 IN UINT16 DataUnitCount
,
121 EFI_SD_HOST_IO_PROTOCOL
*SDHostIo
;
122 UINT32 TransferLength
;
124 Status
= EFI_SUCCESS
;
125 SDHostIo
= CardData
->SDHostIo
;
127 TransferLength
= DataUnitCount
* DATA_UNIT_SIZE
;
128 if (TransferLength
> SDHostIo
->HostCapability
.BoundarySize
) {
129 return EFI_INVALID_PARAMETER
;
133 CopyMem (CardData
->AlignedBuffer
, Buffer
, TransferLength
);
135 Status
= SendCommand (
138 (DataUnitCount
| BIT31
),
140 CardData
->AlignedBuffer
,
144 (UINT32
*)&(CardData
->CardStatus
)
147 Status
= SendCommand (
152 CardData
->AlignedBuffer
,
156 (UINT32
*)&(CardData
->CardStatus
)
158 if (!EFI_ERROR (Status
)) {
159 CopyMem (Buffer
, CardData
->AlignedBuffer
, TransferLength
);
169 @param CardData Pointer to CARD_DATA.
171 @retval EFI_SUCCESS Success
172 @retval EFI_DEVICE_ERROR Hardware Error
173 @retval EFI_INVALID_PARAMETER Parameter is error
174 @retval EFI_NO_MEDIA No media
175 @retval EFI_MEDIA_CHANGED Media Change
176 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
181 IN CARD_DATA
*CardData
190 Status
= FastIO (CardData
, Reg_Control
, &Data
, TRUE
);
191 if (EFI_ERROR (Status
)) {
198 gBS
->Stall (1 * 1000);
199 Status
= FastIO (CardData
, Reg_Control
, &Data
, FALSE
);
200 if (EFI_ERROR (Status
)) {
203 if ((Data
& BIT2
) == BIT2
) {
208 } while (TimeOut
> 0);
211 Status
= EFI_TIMEOUT
;
216 Status
= FastIO (CardData
, Reg_Control
, &Data
, TRUE
);
221 gBS
->Stall (1 * 1000);
222 Status
= FastIO (CardData
, Reg_Control
, &Data
, FALSE
);
223 if (EFI_ERROR (Status
)) {
226 if ((Data
& BIT2
) != BIT2
) {
231 } while (TimeOut
> 0);
235 Status
= EFI_TIMEOUT
;
246 SendATACommand specificed in Taskfile
248 @param CardData Pointer to CARD_DATA.
249 @param TaskFile Pointer to TASK_FILE.
250 @param Write TRUE means write, FALSE means read.
251 @param Buffer If NULL, means no data transfer, neither read nor write.
252 @param SectorCount Buffer size in 512 bytes unit.
254 @retval EFI_SUCCESS Success
255 @retval EFI_DEVICE_ERROR Hardware Error
256 @retval EFI_INVALID_PARAMETER Parameter is error
257 @retval EFI_NO_MEDIA No media
258 @retval EFI_MEDIA_CHANGED Media Change
259 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
264 IN CARD_DATA
*CardData
,
265 IN TASK_FILE
*TaskFile
,
268 IN UINT16 SectorCount
272 EFI_SD_HOST_IO_PROTOCOL
*SDHostIo
;
276 SDHostIo
= CardData
->SDHostIo
;
281 Status
= ReadWriteMultipleRegister (
288 if (EFI_ERROR (Status
)) {
289 DEBUG((EFI_D_ERROR
, "ReadWriteMultipleRegister 0x%x\n", Status
));
295 gBS
->Stall (1 * 1000);
303 if (EFI_ERROR (Status
)) {
307 if (((Data
& BIT7
) == 0) && ((Data
& BIT6
) == BIT6
)) {
312 } while (TimeOut
> 0);
315 DEBUG((EFI_D_ERROR
, "ReadWriteMultipleRegister FastIO EFI_TIMEOUT 0x%x\n", Data
));
316 Status
= EFI_TIMEOUT
;
321 if (Buffer
!= NULL
) {
322 Status
= ReadWriteMultipleBlock (
328 if (EFI_ERROR (Status
)) {
329 DEBUG((EFI_D_ERROR
, "ReadWriteMultipleBlock EFI_TIMEOUT 0x%x\n", Status
));
335 gBS
->Stall (1 * 1000);
344 if (EFI_ERROR (Status
)) {
348 if (((Data
& BIT7
) == 0) && ((Data
& BIT3
) == 0)) {
353 } while (TimeOut
> 0);
355 DEBUG((EFI_D_ERROR
, "ReadWriteMultipleBlock FastIO EFI_TIMEOUT 0x%x\n", Data
));
356 Status
= EFI_TIMEOUT
;
361 if (((Data
& BIT6
) == BIT6
) && (Data
& BIT0
) == 0) {
362 Status
= EFI_SUCCESS
;
364 Status
= EFI_DEVICE_ERROR
;
369 if (EFI_ERROR (Status
)) {
370 SoftwareReset (CardData
);
377 IDENTIFY_DEVICE command
379 @param CardData Pointer to CARD_DATA.
381 @retval EFI_SUCCESS Success
382 @retval EFI_DEVICE_ERROR Hardware Error
383 @retval EFI_INVALID_PARAMETER Parameter is error
384 @retval EFI_NO_MEDIA No media
385 @retval EFI_MEDIA_CHANGED Media Change
386 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
391 IN CARD_DATA
*CardData
396 ZeroMem (&CardData
->TaskFile
, sizeof (TASK_FILE
));
399 //The host only supports nIEN = 0
401 CardData
->TaskFile
.Command_Status
= IDENTIFY_DEVICE
;
404 Status
= SendATACommand (
408 (UINT8
*)&(CardData
->IndentifyDeviceData
),
417 FLUSH_CACHE_EXT command
419 @param CardData Pointer to CARD_DATA.
421 @retval EFI_SUCCESS Success
422 @retval EFI_DEVICE_ERROR Hardware Error
423 @retval EFI_INVALID_PARAMETER Parameter is error
424 @retval EFI_NO_MEDIA No media
425 @retval EFI_MEDIA_CHANGED Media Change
426 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
431 IN CARD_DATA
*CardData
436 //Hitachi CE-ATA will always make the busy high after
437 //receving this command
441 ZeroMem (&CardData->TaskFile, sizeof (TASK_FILE));
443 //The host only supports nIEN = 0
445 CardData->TaskFile.Command_Status = FLUSH_CACHE_EXT;
447 Status = SendATACommand (
459 STANDBY_IMMEDIATE command
461 @param CardData Pointer to CARD_DATA.
463 @retval EFI_SUCCESS Success
464 @retval EFI_DEVICE_ERROR Hardware Error
465 @retval EFI_INVALID_PARAMETER Parameter is error
466 @retval EFI_NO_MEDIA No media
467 @retval EFI_MEDIA_CHANGED Media Change
468 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
473 IN CARD_DATA
*CardData
478 ZeroMem (&CardData
->TaskFile
, sizeof (TASK_FILE
));
480 //The host only supports nIEN = 0
482 CardData
->TaskFile
.Command_Status
= STANDBY_IMMEDIATE
;
485 Status
= SendATACommand (
498 @param CardData Pointer to CARD_DATA.
499 @param LBA The starting logical block address to read from on the device.
500 @param Buffer A pointer to the destination buffer for the data. The caller
501 is responsible for either having implicit or explicit ownership
503 @param SectorCount Size in 512 bytes unit.
505 @retval EFI_SUCCESS Success
506 @retval EFI_DEVICE_ERROR Hardware Error
507 @retval EFI_INVALID_PARAMETER Parameter is error
508 @retval EFI_NO_MEDIA No media
509 @retval EFI_MEDIA_CHANGED Media Change
510 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
515 IN CARD_DATA
*CardData
,
518 IN UINT16 SectorCount
524 ZeroMem (&CardData
->TaskFile
, sizeof (TASK_FILE
));
526 //The host only supports nIEN = 0
528 CardData
->TaskFile
.Command_Status
= READ_DMA_EXT
;
530 CardData
->TaskFile
.SectorCount
= (UINT8
)SectorCount
;
531 CardData
->TaskFile
.SectorCount_Exp
= (UINT8
)(SectorCount
>> 8);
533 CardData
->TaskFile
.LBALow
= (UINT8
)LBA
;
534 CardData
->TaskFile
.LBAMid
= (UINT8
)RShiftU64(LBA
, 8);
535 CardData
->TaskFile
.LBAHigh
= (UINT8
)RShiftU64(LBA
, 16);
537 CardData
->TaskFile
.LBALow_Exp
= (UINT8
)RShiftU64(LBA
, 24);
538 CardData
->TaskFile
.LBAMid_Exp
= (UINT8
)RShiftU64(LBA
, 32);
539 CardData
->TaskFile
.LBAHigh_Exp
= (UINT8
)RShiftU64(LBA
, 40);
541 Status
= SendATACommand (
553 WRITE_DMA_EXT command
555 @param CardData Pointer to CARD_DATA.
556 @param LBA The starting logical block address to read from on the device.
557 @param Buffer A pointer to the destination buffer for the data. The caller
558 is responsible for either having implicit or explicit ownership
560 @param SectorCount Size in 512 bytes unit.
562 @retval EFI_SUCCESS Success
563 @retval EFI_DEVICE_ERROR Hardware Error
564 @retval EFI_INVALID_PARAMETER Parameter is error
565 @retval EFI_NO_MEDIA No media
566 @retval EFI_MEDIA_CHANGED Media Change
567 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
572 IN CARD_DATA
*CardData
,
575 IN UINT16 SectorCount
581 ZeroMem (&CardData
->TaskFile
, sizeof (TASK_FILE
));
583 //The host only supports nIEN = 0
585 CardData
->TaskFile
.Command_Status
= WRITE_DMA_EXT
;
587 CardData
->TaskFile
.SectorCount
= (UINT8
)SectorCount
;
588 CardData
->TaskFile
.SectorCount_Exp
= (UINT8
)(SectorCount
>> 8);
590 CardData
->TaskFile
.LBALow
= (UINT8
)LBA
;
591 CardData
->TaskFile
.LBAMid
= (UINT8
)RShiftU64(LBA
, 8);
592 CardData
->TaskFile
.LBAHigh
= (UINT8
)RShiftU64(LBA
, 16);
594 CardData
->TaskFile
.LBALow_Exp
= (UINT8
)RShiftU64(LBA
, 24);
595 CardData
->TaskFile
.LBAMid_Exp
= (UINT8
)RShiftU64(LBA
, 32);
596 CardData
->TaskFile
.LBAHigh_Exp
= (UINT8
)RShiftU64(LBA
, 40);
598 Status
= SendATACommand (
611 Judge whether it is CE-ATA device or not.
613 @param CardData Pointer to CARD_DATA.
621 IN CARD_DATA
*CardData
626 Status
= ReadWriteMultipleRegister (
631 (UINT8
*)&CardData
->TaskFile
633 if (EFI_ERROR (Status
)) {
635 //To bring back the normal MMC card to work
637 CardData
->SDHostIo
->ResetSDHost (CardData
->SDHostIo
, Reset_DAT_CMD
);
641 if (CardData
->TaskFile
.LBAMid
== CE_ATA_SIG_CE
&&
642 CardData
->TaskFile
.LBAHigh
== CE_ATA_SIG_AA
645 //Disable Auto CMD for CE-ATA
647 CardData
->SDHostIo
->EnableAutoStopCmd (CardData
->SDHostIo
, FALSE
);