summaryrefslogtreecommitdiff
path: root/arch/arm/mach-tegra/include/nvddk_sdio.h
blob: bcbeea3a361b01a434fd98c89e496c2f741ea407 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
/*
 * Copyright (c) 2008-2009 NVIDIA Corporation.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * Neither the name of the NVIDIA Corporation nor the names of its contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */


/**
 * @file
 * <b> NVIDIA Driver Development Kit: SDIO Interface</b>
 *
 * @b Description: SD memory (standard capacity as well
 * as high capacity), SDIO, MMC interface.
 */

/**
 * @defgroup nvddk_sdio SDIO Controller Interface
 * SD memory (standard capacity as well as high capacity), SDIO, MMC
 * interface for controlling and managing SD/SDIO/MMC cards present
 * in SD slots on handheld and embedded devices.

 * This interface provides methods to initialize the SD module, identify
 * the type of the card present in the slot, and read or write data to the
 * SD memory/SDIO card. NvDdkSdio also has power management capabilities
 *
 * @ingroup nvddk_modules
 *
 * @{
 */

#ifndef INCLUDED_NVDDKSDIO_H
#define INCLUDED_NVDDKSDIO_H

#include "nvos.h"
#include "nvrm_init.h"
#include "nvrm_gpio.h"
#include "nvrm_power.h"
#include "nvddk_blockdev.h"

#if defined(__cplusplus)
extern "C"
{
#endif  /* __cplusplus */

/**
 * Opaque handle for NvDdkSdio context.
 */
typedef struct NvDdkSdioInfoRec *NvDdkSdioDeviceHandle;

/**
 * Indicates the interface being used for the card,
 * i.e., number of data lines used for data transfer.
 */
typedef enum
{
    /** Only D0 is used for the data transferl */
    NvDdkSdioDataWidth_1Bit = 0,
    /** Data Lines D0-D3 used for data transfer. */
    NvDdkSdioDataWidth_4Bit,
    /** Data Lines D0-D7 used for data transfer. */
    NvDdkSdioDataWidth_8Bit,
    /** Ignore -- Forces compilers to make 32-bit enums. */
    NvDdkSdioDataWidth_Force32 = 0x7FFFFFFF
} NvDdkSdioDataWidth;

/**
 * Defines constants that indicate types of command
 * for SDMMC/MMC cards.
 */
typedef enum
{
    /** Normal. */
    NvDdkSdioCommandType_Normal = 0,
    /** Suspend. */
    NvDdkSdioCommandType_Suspend,
    /** Resume. */
    NvDdkSdioCommandType_Resume,
    /** Abort data operations. */
    NvDdkSdioCommandType_Abort,
    /** Ignore -- Forces compilers to make 32-bit enums. */
    NvDdkSdioCommandType_Force32 = 0x7FFFFFFF
} NvDdkSdioCommandType;

/**
 * Defines constants that indicate types of command
 * responses for SDMMC/MMC cards.
 */
typedef enum
{
    /// No response type.
    NvDdkSdioRespType_NoResp = 1,
    /// R1 response type.
    NvDdkSdioRespType_R1,
    /// R1b response type.
    NvDdkSdioRespType_R1b,
    /// R2 response type.
    NvDdkSdioRespType_R2,
    /// R3 response type.
    NvDdkSdioRespType_R3,
    /** Responses R4 and R5 are applicable only to SDIO devices. */
    NvDdkSdioRespType_R4,
    /** Responses R4 and R5 are applicable only to SDIO devices. */
    NvDdkSdioRespType_R5,
    /// R6 response type.
    NvDdkSdioRespType_R6,
    /// R7 response type.
    NvDdkSdioRespType_R7,
    /// Ignore -- Forces compilers to make 32-bit enums.
    NvDdkSdioRespType_Force32 = 0x7FFFFFFF
} NvDdkSdioRespType;

/**
 * Defines constants that indicate the bus voltage for
 * SDMMC card.
 */
typedef enum
{
    /** Invalid. */
    NvDdkSdioSDBusVoltage_invalid = 0,
     /** 1.8 V. */
    NvDdkSdioSDBusVoltage_1_8 = 5,
     /** 3.0 V. */
    NvDdkSdioSDBusVoltage_3_0 = 6,
    /** 3.3 V. */
    NvDdkSdioSDBusVoltage_3_3 = 7,
    /** Ignore -- Forces compilers to make 32-bit enums. */
    NvDdkSdioSDBusVoltage_Force32 = 0x7FFFFFFF
} NvDdkSdioSDBusVoltage;

/**
 * Defines constants that indicate status of the last sent
 * SD command/operation.
 */
typedef enum
{
    /** No error. */
    NvDdkSdioCommandStatus_None = 0,
    /** Error.  */
    NvDdkSdioCommandStatus_Error = 0x200,
    /** Card interrupt. */
    NvDdkSdioCommandStatus_Card = 0x100,
    /** Card removal. */
    NvDdkSdioCommandStatus_CardRemoval = 0x80,
    /** Card insertion. */
    NvDdkSdioCommandStatus_CardInsertion = 0x40,
    /** Buffer read ready. */
    NvDdkSdioCommandStatus_BufferReadReady = 0x20,
    /** Buffer write ready. */
    NvDdkSdioCommandStatus_BufferWriteReady = 0x10,
    /** DMA boundary detected.  */
    NvDdkSdioCommandStatus_DMA = 0x8,
    /** Block gap event. */
    NvDdkSdioCommandStatus_BlockGapEvent = 0x4,
    /** Transfer complete. */
    NvDdkSdioCommandStatus_TransferComplete = 0x2,
    /** Command complete. */
    NvDdkSdioCommandStatus_CommandComplete = 0x1,
    /** Ignore -- Forces compilers to make 32-bit enums. */
    NvDdkSdioCommandStatus_Force32 = 0x7FFFFFFF
} NvDdkSdioControllerStatus;

/**
 * Defines constants that indicate error status information as a result
 * of the last sent SD command/operation.
 */
 typedef enum
{
    /** No error. */
    NvDdkSdioError_None = 0,
    /** Error interrupt. */
    NvDdkSdioError_Err = 0x8000,
    /** Command timeout error. */
    NvDdkSdioError_CommandTimeout = 0x10000,
    /** Command CRC error. */
    NvDdkSdioError_CommandCRC = 0x20000,
    /** Command end bit error. */
    NvDdkSdioError_CommandEndBit = 0x40000,
    /** Command index error. */
    NvDdkSdioError_CommandIndex  = 0x80000,
    /** Data timeout error. */    
    NvDdkSdioError_DataTimeout = 0x100000,
    /** Data CRC error. */    
    NvDdkSdioError_DataCRC = 0x200000,
    /** Data endbit error. */
    NvDdkSdioError_DataEndBit = 0x400000,
    /** Current limit error. */
    NvDdkSdioError_CurrentLimit = 0x800000,
    /** Auto CMD12 error. */    
    NvDdkSdioError_AutoCMD12 = 0x1000000,
    /** ADMA error. */
    NvDdkSdioError_ADMA = 0x2000000,
    /** Target response error. */    
    NvDdkSdioError_TargetResponse = 0x10000000,
    /** Ceata error. */    
    NvDdkSdioError_Ceata = 0x20000000,
    /** Ignore -- Forces compilers to make 32-bit enums. */
    NvDdkSdioError_Force32 = 0x7FFFFFFF
} NvDdkSdioErrorStatus;

/**
 * SD memory command contains the command-related information.
 * Will be passed from the upper layers using NvDdkSdio.
 */
 typedef struct
 {
   /** Command code to be used for the current operation. */
    NvU32 CommandCode;
    /** Command type (normal/resume/abort/suspend, etc.)*/
   NvDdkSdioCommandType CommandType;
   /** Indicates whether this is a data/non-data command request. */
    NvBool IsDataCommand;
   /**
    * Command argument: In case of memory cards, argument will consist
    * the card address and in case of SDIO cards the argument will consist of
    * the argument value to be sent along with the commands CMD52/CMD53.
    */
    NvU32 CmdArgument;
    /**
     * Command response: type of response expected to this command R1/R2/R3, etc.
     * A response type also indicates the length of the reponse. For example,
     * R1 type of response is 48 bits long.
     */
    NvDdkSdioRespType ResponseType;
    /**
     * Block size in bytes.
     */
    NvU32  BlockSize;
 } NvDdkSdioCommand;

/**
 * SDIO status contains the read/write information.
 * Will be passed from the upper layers using NvDdkSdio while read/write.
 */
 typedef struct NvDdkSdioStatusRec
 {
   /** Error information for the current read/write operation. It can contain
   * multiple values.
   */
    volatile NvDdkSdioErrorStatus    SDErrorStatus;
   /** Status Information for the current read/write operation. It can contain
   * multiple values.
   */
    volatile NvDdkSdioControllerStatus  SDControllerStatus;
 } NvDdkSdioStatus;

/**
 * Indicates the data block size.
 */
typedef enum
{
    NvDdkSdioBlockSize_512Bytes = 0,
    NvDdkSdioBlockSize_1024Bytes,
    NvDdkSdioBlockSize_2048Bytes,
    /** Ignore -- Forces compilers to make 32-bit enums. */
    NvDdkSdioBlockSize_Force32 = 0x7FFFFFFF
} NvDdkSdioBlockSize;

/**
 * Indicates the timeout clock unit.
 */
typedef enum
{
    NvDdkSdioTimeoutClk_KHz= 0,
    NvDdkSdioTimeoutClk_MHz= 1,
    /** Ignore -- Forces compilers to make 32-bit enums. */
    NvDdkSdioTimeoutClkUnit_Force32 = 0x7FFFFFFF
} NvDdkSdioTimeoutClkUnit;


typedef enum
{
    NvDdkSdioClkDivider_DIV_BASE = 0x0,
    /// Base clock divided by 2.
    NvDdkSdioClkDivider_DIV_2 = 0x1,
    /// Base clock divided by 4.
    NvDdkSdioClkDivider_DIV_4 = 0x2,
    /// Base clock divided by 6.
    NvDdkSdioClkDivider_DIV_8 = 0x4,
    /// Base clock divided by 16.
    NvDdkSdioClkDivider_DIV_16 = 0x8,
    /// Base clock divided by 32.
    NvDdkSdioClkDivider_DIV_32 = 0x10,
    /// Base clock divided by 64.
    NvDdkSdioClkDivider_DIV_64 = 0x20,
    /// Base clock divided by 128.
    NvDdkSdioClkDivider_DIV_128 = 0x40,
    /// Base clock divided by 256.
    NvDdkSdioClkDivider_DIV_256 = 0x80
}NvDdkSdioClkDivider;

typedef enum
{
    NVDDK_SDIO_NORMAL_REQUEST = 0,
    NVDDK_SDIO_MEMORY_ABORT_REQUEST,
    NVDDK_SDIO_IO_ABORT_REQUEST,
    NVDDK_SDIO_SUSPEND_REQUEST,
    NVDDK_SDIO_RESUME_REQUEST
} SdioRequestType;

/**
 * SD host capabilities contains the information specific to the host controller 
 * implementation. The host controller may implement these values as fixed or
 * loaded from flash memory during power on initialization.
 */
 typedef struct NvDdkSdioHostCapabilitiesRec
 {
    /// Holds the max instances supported.
    NvU8 MaxInstances;   

    NvBool IsAutoCMD12Supported;
    /// Holds a flag indicating whether the instance is being powered from the AO domain.
    NvBool AlwaysON;    
    /// Holds a flag indicating whether the host controller is version 2.
    NvBool IsSdControllerVersion2;
    /// Holds teh bus voltage supported by the host controller.
    NvDdkSdioSDBusVoltage BusVoltage;
    /// Holds the maximum block size supported by the controller.
    NvU32 MaxBlockLength;
 }NvDdkSdioHostCapabilities;

 typedef struct NvDdkSdioInterfaceCapabilitiesRec
{
    ///  Maximum bus width supported by the physical interface.
    ///  Will be 2, 4, or 8 depending on the selected pin mux.
    NvU32 MmcInterfaceWidth;

    /// SDIO card HW settling time after reset, i.e. before reading the OCR.
    NvU32 SDIOCardSettlingDelayMSec;
} NvDdkSdioInterfaceCapabilities;

/// Function to get log2 of a power of 2.
/// When argument Val is not power of 2, log2 of the next 
/// smaller power of 2 is returned
NvU8 SdUtilGetLog2(NvU32 Val);

/**
 * Get the SD host controller and SD interface capabilities.
 *
 * This API fills the SDIO host controller capabilities and
 * SDIO interface capabilities.
 *
 * @param hDevice       the Rm device handle
 * @param pHostCap      A pointer to SDIO host controlelr capabilities struct.
 * @param pInterfaceCap    A pointer to SDIO interface capabilities struct.
 * @param instance        The particular SDIO instance.
 * @retval NvSuccess                 Success.
 */
NvError
NvDdkSdioGetCapabilities(
    NvRmDeviceHandle hDevice,
    NvDdkSdioHostCapabilities *pHostCap,
    NvDdkSdioInterfaceCapabilities *pInterfaceCap,
    NvU32 instance);

/**
 * Initializes the HW SD module.
 * Allocates the resources needed for the SD data transfer operations.
 * Allocates the device handle for subsequent use. This API can be called
 * multiple times, to open various instances of the SDIO controller. This API
 * associates an instance of the SDIO controller to an SDIO handle. After the
 * client acquires an SDIO handle, it can use it for all further operations.
 *
 * @see NvDdkSdioClose
 *
 * @pre This method must be called before any other NvDdkSdio APIs.
 *
 * @param  hDevice       The RM device handle.
 * @param hGpio          The GPIO device handle, used for card interrupts.
 * @param phSdio         A pointer to the device handle
 * @param pNotificationSema  A pointer to the sempahore that will be used by
 *                              SDIO module to signal notifications to the
 *                              client.
 * @param pCardEventsSema    A pointer to the semaphore that will be used by
 *                              the GPIO module to signal card events like
 *                              card insertion/removal.
 * @param Instance   The particular SDIO instance.
 * To the client, this covers command completion event, error event,
 * and card removal event notification to the client.
 *
 * @retval NvSuccess                          Open device successful.
 * @retval NvError_SdioInstanceTaken          The requested instance is
 *                                            already been taken.
 * @retval NvError_InsufficientMemory         Cannot allocate memory.
 */
NvError
NvDdkSdioOpen(
    NvRmDeviceHandle hDevice,
    NvRmGpioHandle hGpio,
    NvDdkSdioDeviceHandle *phSdio,
    NvOsSemaphoreHandle *pNotificationSema,
    NvOsSemaphoreHandle *pCardEventsSema,
    NvU8 Instance);

/**
 * Deinitializes the HW SD module.
 * Closes all the opened handles and release all the allocated resources for SD.
 * @see NvDdkSdioOpen
 * @param hSdio The SDIO device handle.
 */
void NvDdkSdioClose(NvDdkSdioDeviceHandle hSdio);

/**
 * Sends non-data commands to the card. If the command is an abort
 * command, DAT and CMD lines will be reset using software reset register.
 * This command returns after succesfully sending a command. This API
 * waits until command inhibit (DAT) and command inhibit (CMD) both become
 * 0 and then sends the current command.
 * @param hSdio             The device handle.
 * @param pCommand           A pointer to the ::NvDdkSdioCommand struct,
 *                             which contains information like command index,
 *                               response type, argument, etc.
 * @param SdioStatus         The SDIO status.
 * @retval NvSuccess                 Success.
 * @retval NvError_SdioDeviceNotMounted Module not mounted. Need to
 *                                  call NvDdkSdioOpen() first.
 * @retval NvError_SdioCardNotPresent   Card not present in slot.
 */
NvError
NvDdkSdioSendCommand(
        NvDdkSdioDeviceHandle hSdio,
        NvDdkSdioCommand *pCommand,
        NvU32* SdioStatus);

/**
 * Reads the response from SDMMC controller.
 *
 * @param hSdio             The device handle.
 * @param CommandNumber     Command number.
 * @param ResponseType      Type of response.
 * @param pResponse         A pointer to  the response buffer.
 *
 * @retval NvSuccess                 Success.
 * @retval NvError_SdioDeviceNotMounted   Module not mounted. Need to
 *                                  call NvDdkSdioOpen() first.
 * @retval NvError_SdioCardNotPresent     Card not present in slot.
 */
NvError
NvDdkSdioGetCommandResponse(
    NvDdkSdioDeviceHandle hSdio,
    NvU32 CommandNumber,
    NvDdkSdioRespType ResponseType,
    NvU32 *pResponse);

/**
 * Reads the data from SD/SDIO card into \a pReadBuffer.
 *
 * @pre The SD module must be mounted using NvDdkSdioOpen() before
 * using this method.
 *
 * @param hSdio                 The device handle.
 * @param NumOfBytesToRead      Number of bytes to read from the card.
 * @param pReadBuffer           A pointer to the application buffer in which data
 *                                 is read.
 * @param pRWRequest            A pointer to SD RW request struct.
 * @param HWAutoCMD12Enable     Flag to indicate if auto CMD12 is to be used.
 *                                 This flag can be ignored for SDIO cards.
 * @param SdioStatus         The SDIO status.
 * @retval NvSuccess                 Identification successful.
 * @retval NvError_SdioDeviceNotMounted   Module not mounted. Need to
 *                                  call NvDdkSdioOpen() first.
 * @retval NvError_SdioCardNotPresent     Card not present in slot.
 */
NvError
NvDdkSdioRead(
    NvDdkSdioDeviceHandle hSdio,
    NvU32 NumOfBytesToRead,
    void  *pReadBuffer,
    NvDdkSdioCommand *pRWRequest,
    NvBool HWAutoCMD12Enable,
    NvU32* SdioStatus);

/**
 * Used to write data from \a pWriteBuffer on SD/SDIO card.
 * 
 * @pre The SD module needs to be mounted using NvDdkSdioOpen() before
 * using this method.
 *
 * @param hSdio                 The device handle.
 * @param NumOfBytesToWrite     Number of bytes to write.
 * @param pWriteBuffer          A pointer to the application buffer from which
 *                                 data is taken and written on card.
 * @param pRWCommand            A pointer to SD read/write command.
 * @param HWAutoCMD12Enable     Flag to indicate if auto CMD12 is to be used.
 *                                 This flag can be ignored for SDIO cards.
 * @param SdioStatus         The SDIO status.
 * @retval NvSuccess                 Identification successful.
 * @retval NvError_SdioDeviceNotMounted   Module not mounted. Need to
 *                                  call NvDdkSdioOpen first().
 * @retval NvError_SdioCardNotPresent     Card not present in slot.
 * @retval NvError_SdioCardWriteProtected Card is write protected
 *                                  (for SD memory cards only).
 */
NvError
NvDdkSdioWrite(
    NvDdkSdioDeviceHandle hSdio,
    NvU32 NumOfBytesToWrite,
    void *pWriteBuffer,
    NvDdkSdioCommand *pRWCommand,
    NvBool HWAutoCMD12Enable,
    NvU32* SdioStatus);

/**
 * Gets write protect status (for memory/combo cards only).
 * There is a write protect switch present for SD memory cards
 * or mini/micro SD card adapters. These switches are used to restrict
 * writes to the memory card. The upper layers using NvDdkSdio have to
 * use this function to see whether the memory card is write-protected.
 * @param hSdio            The device handle.
 * @param hGpio              The GPIO device handle.
 * @param IsWriteprotected   A pointer to information whether the card is
 *                               write protected (NV_TRUE)
                                 or write enabled (NV_FALSE).
 * @retval NvSuccess                      Operation successful.
 * @retval NvError_SdioCardNotPresent     Card not present in slot.
 */
NvError
NvDdkSdioIsWriteProtected(
        NvDdkSdioDeviceHandle hSdio,
        NvRmGpioHandle hGpio,
        NvBool *IsWriteprotected);


/**
 * Set the voltage level for the card
 * operations.
 * @param hSdio            The device handle.
 * @param Voltage          Enum for voltage.
 * @retval NvSuccess                 Success.
 * @retval NvError_SdioDeviceNotMounted   Module not mounted. Need to
 *                                  call NvDdkSdioOpen() first.
 * @retval NvError_SdioCardNotPresent     Card not present in slot.
 */
NvError
NvDdkSdioSetSDBusVoltage(
    NvDdkSdioDeviceHandle hSdio,
    NvDdkSdioSDBusVoltage Voltage);

/**
 * Enables high speed mode for SD high speed card
 * operations. Before setting this bit, the host driver shall check the high
 * speed support in the capabilities register. if this bit is set to 0
 * (default), the host controller outputs CMD line and DAT lines at the falling
 * edge of the SD clock (up to 25 MHz). If this bit is set to 1, the host
 * controller outputs CMD line and DAT lines at the rising edge of the SD clock
 * (up to 50 MHz).
 * @param hSdio            The device handle.
 * @retval NvSuccess                 Success.
 * @retval NvError_SdioDeviceNotMounted   Module not mounted. Need to
 *                                  call NvDdkSdioOpen() first.
 * @retval NvError_SdioCardNotPresent     Card not present in slot.
 */
NvError NvDdkSdioHighSpeedEnable(NvDdkSdioDeviceHandle hSdio);

/**
 * Disables high speed mode for SD high speed cards.
 * The host controller outputs CMD line and DAT lines at the falling
 * edge of the SD Clock (up to 25 MHz).
 *
 * @param hSdio            The device handle.
 * @retval NvSuccess                 Success.
 * @retval NvError_SdioDeviceNotMounted   Module not mounted. Need to
 *                                  call NvDdkSdioOpen() first.
 * @retval NvError_SdioCardNotPresent     Card not present in slot.
 */
NvError NvDdkSdioHighSpeedDisable(NvDdkSdioDeviceHandle hSdio);

/**
 * Set clock rate for the card. Upper layers using
 * NvDdkSdio have to use this function to set the clock rate
 * to be used for subsequent data transfer
 * operations.
 * @param hSdio            The device handle.
 * @param FrequencyKHz   SD Clock Frequency to be configured.
 * @param pConfiguredFrequencyKHz This field is updated with the
 * actual frequency configured by the driver..
 * @retval NvSuccess                 Success
 * @retval NvError_SdioDeviceNotMounted   Module not mounted. Need to
 *                                  call NvDdkSdioOpen() first.
 * @retval NvError_SdioCardNotPresent     Card not present in slot.
 */
NvError
NvDdkSdioSetClockFrequency(
    NvDdkSdioDeviceHandle hSdio,
    NvRmFreqKHz FrequencyKHz,
    NvRmFreqKHz* pConfiguredFrequencyKHz);

/**
 * Sets host controller bus width for the subsequent data operations.
 * By default the bus width is set to 1-bit mode.
 * SD Memory card is set to 4-bit mode when the it has to go in the
 * data transfer mode for fast data transfer.
 * Low speed SDIO cards do not support high data rate operations
 * (4-bit data mode) and so card capability must
 * be checked to see if card is a low speed card before setting the bus
 * width for the card to 4 bits. If a card does not support 4-bit mode
 * and this API is used to set its bus width to 4 bit mode,
 * assert is encountered in debug mode.
 *
 *
 * @param hSdio              The device handle.
 * @param CardDataWidth      1 or 4 bit mode.
 * @retval NvSuccess                Success.
 * @retval NvError_SdioDeviceNotMounted   Module not mounted. Need to
 *                                  call NvDdkSdioOpen() first.
 * @retval NvError_SdioCardNotPresent     Card not present in slot.
 */
NvError
NvDdkSdioSetHostBusWidth(
    NvDdkSdioDeviceHandle hSdio,
    NvDdkSdioDataWidth CardDataWidth);

/**
 * Checks the present state register to see if the card has been
 * actually inserted. If NV_TRUE is returned, then it is safe to apply SD clock
 * to the card.
 * @param hSdio                 The device handle.
 * @param IsCardInserted    A pointer to information whether the card is
 *                                          inserted (NV_TRUE)
                                            or removed (NV_FALSE).
 * @retval NvSuccess        Card detect feature present.
 * @retval NvError_SdioCardAlwaysPresent   Card is soldered on the board.
 * @retval NvError_SdioAutoDetectCard Auto detect the card by sending the commands.
 */
NvError
NvDdkSdioIsCardInserted(
        NvDdkSdioDeviceHandle hSdio,
        NvBool *IsCardInserted);

/**
 * Resets the host controller by setting the software reset
 * for all bit in the software reset register.
 * @param hSdio            The device handle.
 */
void NvDdkSdioResetController(NvDdkSdioDeviceHandle hSdio);

/**
 * Sets the blocksize of the host controller.
 * This API should be called after the blocksize is set on the SD device
 * using CMD16.
 *
 * @param hSdio                  The device handle.
 * @param Blocksize              The blocksize to be set in bytes.
 *
 * @retval  NvSuccess Indicates the operation succeeded.
 * @retval  NvError_NotInitialized Indicates that the SDIO was not opened.
 * @retval  NvError_SdioControllerBusy Indicates the controller is busy carrying out
 *                               read/write operation.
 */
NvError NvDdkSdioSetBlocksize(NvDdkSdioDeviceHandle hSdio, NvU32 Blocksize);

/**
 * Enables the SDIO host controller to accept the events generated by the I/O card.
 *
 * @param hSdio                  The device handle.
 * @param IsAcceptCardEvents     Flag to know whether or not to accept the card
 *                                   events.
 */
void
    NvDdkSdioEnableIoMode(
        NvDdkSdioDeviceHandle hSdio,
        NvBool IsAcceptCardEvents);

/**
 * Part of static power management, call this API to put the SDIO controller
 * into suspend state. This API is a mechanism for the client to augment OS power
 * management policy.
 *
 * The H/W context of the SDIO controller is saved. Clock is disabled and power 
 * is also disabled to the controller.
 *
 *
 * @param hSdio             The SDIO device handle.
 * @param SwitchOffSDDevice      If NV_TRUE, switches off the voltage to the SD device.
 * (like sd card or wifi module). If NV_FALSE, does not switch off the voltage to the SD device.
 *
 */
void NvDdkSdioSuspend(NvDdkSdioDeviceHandle hSdio, NvBool SwitchOffSDDevice);


/**
 * Part of static power management, call this API to wake the SDIO controller
 * from suspend state. This API is a mechanism for the client to augment OS
 * power management policy.
 *
 * The H/W context of the SDIO controller is restored. Clock is enabled and power 
 * is also enabled to the controller.
 *
 *
 * @param hSdio             The SDIO device handle.
 * @param IsCardInserted      Flag to indicate whether the following is API is 
 * called during the card insertion or in normal operation.
 * @param SwitchOnSDDevice      If NV_TRUE, switches on the voltage to the SD device.
 * (like SD card or Wi-Fi module). If NV_FALSE, does not change the voltage to the SD device.
 *
 * @retval NvSuccess                 Success.
 */
NvError
NvDdkSdioResume(
    NvDdkSdioDeviceHandle hSdio,
    NvBool IsCardInserted,
    NvBool SwitchOnSDDevice);

/**
 * Aborts the SDIO memory or I/O operation.
 *
 * @param hSdio            The SDIO device handle.
 * @param RequestType      The type of abort request.
 * @param FunctionNumber   Function number of the SDIO module.
 */
 void
NvDdkSdioAbort(
    NvDdkSdioDeviceHandle hSdio,
    SdioRequestType RequestType,
    NvU32 FunctionNumber);

/**
 * Allocates the required resources, powers on the device, and
 * prepares the device for I/O operations.
 * Client gets a valid handle only if the device is found.
 * The same handle must be used for further operations.
 * The device can be opened by only one client at a time.
 *
 * @pre This method must be called once before using other 
 *           NvDdkBlockDev APIs.
 *
 * @param Instance Instance of specific device.
 * @param MinorInstance Minor instance of specific device.
 * @param phBlockDev Returns pointer to device handle.
 *
 * @retval NvSuccess Device is present and ready for I/O operations.
 * @retval NvError_BadParameter One or more of the arguments provided
 * are incorrect.
 * @retval NvError_SdioCardNotPresent SD card is not present or unsupported.
 * @retval NvError_NotSupported The requested instance is not supported.
 * @retval NvError_SdioCommandFailed SD card is not responding.
 * @retval NvError_SdioInstanceTaken The requested instance is unavailable
 * or already in use.
 * @retval NvError_InsufficientMemory Cannot allocate memory.
 */
NvError 
NvDdkSdBlockDevOpen(
    NvU32 Instance, 
    NvU32 MinorInstance,
    NvDdkBlockDevHandle *phBlockDev);

NvError
NvDdkSdBlockDevInit(NvRmDeviceHandle hDevice);

void
NvDdkSdBlockDevDeinit(void);

#if defined(__cplusplus)
}
#endif  /* __cplusplus */

/** @} */

#endif  /* INCLUDED_NVDDKSDIO_H */