]>
git.proxmox.com Git - mirror_edk2.git/blob - QuarkSocPkg/QuarkSouthCluster/Sdio/Dxe/SDMediaDeviceDxe/CEATA.c
3 CEATA specific functions implementation
5 Copyright (c) 2013-2015 Intel Corporation.
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include "SDMediaDevice.h"
14 Send RW_MULTIPLE_REGISTER command
16 @param CardData Pointer to CARD_DATA.
17 @param Address Register address.
18 @param ByteCount Buffer size.
19 @param Write TRUE means write, FALSE means read.
20 @param Buffer Buffer pointer.
22 @retval EFI_SUCCESS Success
23 @retval EFI_DEVICE_ERROR Hardware Error
24 @retval EFI_INVALID_PARAMETER Parameter is error
25 @retval EFI_NO_MEDIA No media
26 @retval EFI_MEDIA_CHANGED Media Change
27 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
31 ReadWriteMultipleRegister (
32 IN CARD_DATA
*CardData
,
44 if ((Address
% 4 != 0) || (ByteCount
% 4 != 0)) {
45 Status
= EFI_INVALID_PARAMETER
;
49 Argument
= (Address
<< 16) | ByteCount
;
56 CopyMem (CardData
->AlignedBuffer
, Buffer
, ByteCount
);
58 Status
= SendCommand (
63 CardData
->AlignedBuffer
,
67 (UINT32
*)&(CardData
->CardStatus
)
70 Status
= SendCommand (
75 CardData
->AlignedBuffer
,
79 (UINT32
*)&(CardData
->CardStatus
)
81 if (!EFI_ERROR (Status
)) {
82 CopyMem (Buffer
, CardData
->AlignedBuffer
, ByteCount
);
91 Send ReadWriteMultipleBlock command with RW_MULTIPLE_REGISTER command
93 @param CardData Pointer to CARD_DATA.
94 @param DataUnitCount Buffer size in 512 bytes unit.
95 @param Write TRUE means write, FALSE means read.
96 @param Buffer Buffer pointer.
98 @retval EFI_SUCCESS Success
99 @retval EFI_DEVICE_ERROR Hardware Error
100 @retval EFI_INVALID_PARAMETER Parameter is error
101 @retval EFI_NO_MEDIA No media
102 @retval EFI_MEDIA_CHANGED Media Change
103 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
107 ReadWriteMultipleBlock (
108 IN CARD_DATA
*CardData
,
109 IN UINT16 DataUnitCount
,
115 EFI_SD_HOST_IO_PROTOCOL
*SDHostIo
;
116 UINT32 TransferLength
;
118 Status
= EFI_SUCCESS
;
119 SDHostIo
= CardData
->SDHostIo
;
121 TransferLength
= DataUnitCount
* DATA_UNIT_SIZE
;
122 if (TransferLength
> SDHostIo
->HostCapability
.BoundarySize
) {
123 return EFI_INVALID_PARAMETER
;
127 CopyMem (CardData
->AlignedBuffer
, Buffer
, TransferLength
);
129 Status
= SendCommand (
132 (DataUnitCount
| BIT31
),
134 CardData
->AlignedBuffer
,
138 (UINT32
*)&(CardData
->CardStatus
)
141 Status
= SendCommand (
146 CardData
->AlignedBuffer
,
150 (UINT32
*)&(CardData
->CardStatus
)
152 if (!EFI_ERROR (Status
)) {
153 CopyMem (Buffer
, CardData
->AlignedBuffer
, TransferLength
);
163 @param CardData Pointer to CARD_DATA.
165 @retval EFI_SUCCESS Success
166 @retval EFI_DEVICE_ERROR Hardware Error
167 @retval EFI_INVALID_PARAMETER Parameter is error
168 @retval EFI_NO_MEDIA No media
169 @retval EFI_MEDIA_CHANGED Media Change
170 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
175 IN CARD_DATA
*CardData
184 Status
= FastIO (CardData
, Reg_Control
, &Data
, TRUE
);
185 if (EFI_ERROR (Status
)) {
192 gBS
->Stall (1 * 1000);
193 Status
= FastIO (CardData
, Reg_Control
, &Data
, FALSE
);
194 if (EFI_ERROR (Status
)) {
197 if ((Data
& BIT2
) == BIT2
) {
202 } while (TimeOut
> 0);
205 Status
= EFI_TIMEOUT
;
210 Status
= FastIO (CardData
, Reg_Control
, &Data
, TRUE
);
215 gBS
->Stall (1 * 1000);
216 Status
= FastIO (CardData
, Reg_Control
, &Data
, FALSE
);
217 if (EFI_ERROR (Status
)) {
220 if ((Data
& BIT2
) != BIT2
) {
225 } while (TimeOut
> 0);
229 Status
= EFI_TIMEOUT
;
240 SendATACommand specificed in Taskfile
242 @param CardData Pointer to CARD_DATA.
243 @param TaskFile Pointer to TASK_FILE.
244 @param Write TRUE means write, FALSE means read.
245 @param Buffer If NULL, means no data transfer, neither read nor write.
246 @param SectorCount Buffer size in 512 bytes unit.
248 @retval EFI_SUCCESS Success
249 @retval EFI_DEVICE_ERROR Hardware Error
250 @retval EFI_INVALID_PARAMETER Parameter is error
251 @retval EFI_NO_MEDIA No media
252 @retval EFI_MEDIA_CHANGED Media Change
253 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
258 IN CARD_DATA
*CardData
,
259 IN TASK_FILE
*TaskFile
,
262 IN UINT16 SectorCount
272 Status
= ReadWriteMultipleRegister (
279 if (EFI_ERROR (Status
)) {
280 DEBUG((EFI_D_ERROR
, "ReadWriteMultipleRegister 0x%x\n", Status
));
286 gBS
->Stall (1 * 1000);
294 if (EFI_ERROR (Status
)) {
298 if (((Data
& BIT7
) == 0) && ((Data
& BIT6
) == BIT6
)) {
303 } while (TimeOut
> 0);
306 DEBUG((EFI_D_ERROR
, "ReadWriteMultipleRegister FastIO EFI_TIMEOUT 0x%x\n", Data
));
307 Status
= EFI_TIMEOUT
;
312 if (Buffer
!= NULL
) {
313 Status
= ReadWriteMultipleBlock (
319 if (EFI_ERROR (Status
)) {
320 DEBUG((EFI_D_ERROR
, "ReadWriteMultipleBlock EFI_TIMEOUT 0x%x\n", Status
));
326 gBS
->Stall (1 * 1000);
335 if (EFI_ERROR (Status
)) {
339 if (((Data
& BIT7
) == 0) && ((Data
& BIT3
) == 0)) {
344 } while (TimeOut
> 0);
346 DEBUG((EFI_D_ERROR
, "ReadWriteMultipleBlock FastIO EFI_TIMEOUT 0x%x\n", Data
));
347 Status
= EFI_TIMEOUT
;
352 if (((Data
& BIT6
) == BIT6
) && (Data
& BIT0
) == 0) {
353 Status
= EFI_SUCCESS
;
355 Status
= EFI_DEVICE_ERROR
;
360 if (EFI_ERROR (Status
)) {
361 SoftwareReset (CardData
);
368 IDENTIFY_DEVICE command
370 @param CardData Pointer to CARD_DATA.
372 @retval EFI_SUCCESS Success
373 @retval EFI_DEVICE_ERROR Hardware Error
374 @retval EFI_INVALID_PARAMETER Parameter is error
375 @retval EFI_NO_MEDIA No media
376 @retval EFI_MEDIA_CHANGED Media Change
377 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
382 IN CARD_DATA
*CardData
387 ZeroMem (&CardData
->TaskFile
, sizeof (TASK_FILE
));
390 //The host only supports nIEN = 0
392 CardData
->TaskFile
.Command_Status
= IDENTIFY_DEVICE
;
395 Status
= SendATACommand (
399 (UINT8
*)&(CardData
->IndentifyDeviceData
),
408 FLUSH_CACHE_EXT command
410 @param CardData Pointer to CARD_DATA.
412 @retval EFI_SUCCESS Success
413 @retval EFI_DEVICE_ERROR Hardware Error
414 @retval EFI_INVALID_PARAMETER Parameter is error
415 @retval EFI_NO_MEDIA No media
416 @retval EFI_MEDIA_CHANGED Media Change
417 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
422 IN CARD_DATA
*CardData
427 //Hitachi CE-ATA will always make the busy high after
428 //receving this command
432 ZeroMem (&CardData->TaskFile, sizeof (TASK_FILE));
434 //The host only supports nIEN = 0
436 CardData->TaskFile.Command_Status = FLUSH_CACHE_EXT;
438 Status = SendATACommand (
450 STANDBY_IMMEDIATE command
452 @param CardData Pointer to CARD_DATA.
454 @retval EFI_SUCCESS Success
455 @retval EFI_DEVICE_ERROR Hardware Error
456 @retval EFI_INVALID_PARAMETER Parameter is error
457 @retval EFI_NO_MEDIA No media
458 @retval EFI_MEDIA_CHANGED Media Change
459 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
464 IN CARD_DATA
*CardData
469 ZeroMem (&CardData
->TaskFile
, sizeof (TASK_FILE
));
471 //The host only supports nIEN = 0
473 CardData
->TaskFile
.Command_Status
= STANDBY_IMMEDIATE
;
476 Status
= SendATACommand (
489 @param CardData Pointer to CARD_DATA.
490 @param LBA The starting logical block address to read from on the device.
491 @param Buffer A pointer to the destination buffer for the data. The caller
492 is responsible for either having implicit or explicit ownership
494 @param SectorCount Size in 512 bytes unit.
496 @retval EFI_SUCCESS Success
497 @retval EFI_DEVICE_ERROR Hardware Error
498 @retval EFI_INVALID_PARAMETER Parameter is error
499 @retval EFI_NO_MEDIA No media
500 @retval EFI_MEDIA_CHANGED Media Change
501 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
506 IN CARD_DATA
*CardData
,
509 IN UINT16 SectorCount
515 ZeroMem (&CardData
->TaskFile
, sizeof (TASK_FILE
));
517 //The host only supports nIEN = 0
519 CardData
->TaskFile
.Command_Status
= READ_DMA_EXT
;
521 CardData
->TaskFile
.SectorCount
= (UINT8
)SectorCount
;
522 CardData
->TaskFile
.SectorCount_Exp
= (UINT8
)(SectorCount
>> 8);
524 CardData
->TaskFile
.LBALow
= (UINT8
)LBA
;
525 CardData
->TaskFile
.LBAMid
= (UINT8
)RShiftU64(LBA
, 8);
526 CardData
->TaskFile
.LBAHigh
= (UINT8
)RShiftU64(LBA
, 16);
528 CardData
->TaskFile
.LBALow_Exp
= (UINT8
)RShiftU64(LBA
, 24);
529 CardData
->TaskFile
.LBAMid_Exp
= (UINT8
)RShiftU64(LBA
, 32);
530 CardData
->TaskFile
.LBAHigh_Exp
= (UINT8
)RShiftU64(LBA
, 40);
532 Status
= SendATACommand (
544 WRITE_DMA_EXT command
546 @param CardData Pointer to CARD_DATA.
547 @param LBA The starting logical block address to read from on the device.
548 @param Buffer A pointer to the destination buffer for the data. The caller
549 is responsible for either having implicit or explicit ownership
551 @param SectorCount Size in 512 bytes unit.
553 @retval EFI_SUCCESS Success
554 @retval EFI_DEVICE_ERROR Hardware Error
555 @retval EFI_INVALID_PARAMETER Parameter is error
556 @retval EFI_NO_MEDIA No media
557 @retval EFI_MEDIA_CHANGED Media Change
558 @retval EFI_BAD_BUFFER_SIZE Buffer size is bad
563 IN CARD_DATA
*CardData
,
566 IN UINT16 SectorCount
572 ZeroMem (&CardData
->TaskFile
, sizeof (TASK_FILE
));
574 //The host only supports nIEN = 0
576 CardData
->TaskFile
.Command_Status
= WRITE_DMA_EXT
;
578 CardData
->TaskFile
.SectorCount
= (UINT8
)SectorCount
;
579 CardData
->TaskFile
.SectorCount_Exp
= (UINT8
)(SectorCount
>> 8);
581 CardData
->TaskFile
.LBALow
= (UINT8
)LBA
;
582 CardData
->TaskFile
.LBAMid
= (UINT8
)RShiftU64(LBA
, 8);
583 CardData
->TaskFile
.LBAHigh
= (UINT8
)RShiftU64(LBA
, 16);
585 CardData
->TaskFile
.LBALow_Exp
= (UINT8
)RShiftU64(LBA
, 24);
586 CardData
->TaskFile
.LBAMid_Exp
= (UINT8
)RShiftU64(LBA
, 32);
587 CardData
->TaskFile
.LBAHigh_Exp
= (UINT8
)RShiftU64(LBA
, 40);
589 Status
= SendATACommand (
602 Judge whether it is CE-ATA device or not.
604 @param CardData Pointer to CARD_DATA.
612 IN CARD_DATA
*CardData
617 Status
= ReadWriteMultipleRegister (
622 (UINT8
*)&CardData
->TaskFile
624 if (EFI_ERROR (Status
)) {
626 //To bring back the normal MMC card to work
628 CardData
->SDHostIo
->ResetSDHost (CardData
->SDHostIo
, Reset_DAT_CMD
);
632 if (CardData
->TaskFile
.LBAMid
== CE_ATA_SIG_CE
&&
633 CardData
->TaskFile
.LBAHigh
== CE_ATA_SIG_AA
636 //Disable Auto CMD for CE-ATA
638 CardData
->SDHostIo
->EnableAutoStopCmd (CardData
->SDHostIo
, FALSE
);