summaryrefslogtreecommitdiff
path: root/arch/arm/mach-tegra/include/nvddk_nand.h
blob: 84d963b02d40932618658481f1d4694d7b63d928 (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
/*
 * 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: NAND Flash Controller Interface</b>
 *
 * @b Description: This file declares the interface for the NAND module.
 */

#ifndef INCLUDED_NVDDK_NAND_H
#define INCLUDED_NVDDK_NAND_H

/**
 * @defgroup nvddk_nand NAND Flash Controller Interface
 *
 * This driver provides the interface to access external NAND flash devices
 * that are interfaced to the SOC.
 * It provides the APIs to access the NAND flash physically (in raw block number
 * and page numbers) and logically (in logical block number through 
 * block device interface).
 * It does not support any software ECC algorithms. It makes use of hardware ECC 
 * features supported by NAND Controller for validating the data.
 * It supports accessing NAND flash devices in interleave mode.
 *
 * @ingroup nvddk_modules
 * @{
 */

#include "nvcommon.h"
#include "nvos.h"
#include "nvrm_init.h"
#include "nvodm_query_nand.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
 * NvDdkNandHandle is an opaque context to the NvDdkNandRec interface.
 */
typedef struct NvDdkNandRec *NvDdkNandHandle;


enum{ MAX_NAND_SUPPORTED = 8};


/**
 * NAND flash device information.
 */
typedef struct
{
    /// Vendor ID.
    NvU8 VendorId;
    /// Device ID.
    NvU8 DeviceId;
    /**
     * Redundant area size per page to write any tag information. This will
     * be calculated as:
     * <pre>    TagSize = spareAreaSize - mainAreaEcc - SpareAreaEcc </pre>
     * Shim layer is always supposed to request in multiples
     * of this number when spare area operations are requested.
     */
    NvU8 TagSize;
    /// Bus width of the chip: can be 8- or 16-bit.
    NvU8 BusWidth;
    /// Page size in bytes, includes only data area, no redundant area.
    NvU32 PageSize;
    /// Number of Pages per block.
    NvU32 PagesPerBlock;
    /// Total number of blocks that are present in the NAND flash device.
    NvU32 NoOfBlocks;
    /**
     * Holds the zones per flash device--minimum value possible is 1.
     * Zone is a group of contiguous blocks among which internal copy back can 
     * be performed, if the chip supports copy-back operation.
     * Zone is also referred as plane or district by some flashes.
     */
    NvU32 ZonesPerDevice;
    /**
     * Total device capacity in kilobytes.
     * Includes only data area, no redundant area.
     */
    NvU32 DeviceCapacityInKBytes;
    /// Interleave capability of the flash.
    NvOdmNandInterleaveCapability InterleaveCapability;
    /// Device type: SLC or MLC.
    NvOdmNandFlashType NandType;
    /// Number of NAND flash devices present on the board.
    NvU8 NumberOfDevices;
    // Size of Spare area
    NvU32 NumSpareAreaBytes;
    // Offset of Tag data in the spare area.
    NvU32 TagOffset;
}NvDdkNandDeviceInfo;

/**
 * Information related to a physical block.
 */
typedef struct 
{
    /// Tag information of the block.
    NvU8* pTagBuffer;
    /// Number of bytes to copy in tag buffer.
    NvU32 TagBufferSize;
    /// Determines whether the block is factory good block or not. 
    /// - NV_TRUE if factory good block.
    /// - NV_FALSE if factory bad block.
    NvBool IsFactoryGoodBlock;
    /// Gives the lock status of the block.
    NvBool IsBlockLocked;
}NandBlockInfo;


/**
 * NAND DDK capabilities.
 */
typedef struct
{
    /**
     * Flag indicating whether or not ECC is supported by the driver.
     * NV_TRUE means it supports ECC, else not supported.
     */
    NvBool IsEccSupported;
    /**
     * Flag indicating whether or not interleaving operation is
     * supported by the driver.
     * NV_TRUE means it supports interleaving, else not supported.
     */
    NvBool IsInterleavingSupported;
    /// Whether the command queue mode is supported by the SOC.
    NvBool IsCommandQueueModeSupported;
    /// Whether EDO mode is suported by the SOC.
    NvBool IsEdoModeSupported;
    /// Number of ECC parity bytes per spare area.
    NvU8 TagEccParitySize;
    /// Total number of NAND devices supported by SOC.
    NvU32 NumberOfDevicesSupported;
    /// Maximum data size that DMA can transfer.
    NvU32 MaxDataTransferSize;
    /// NAND controller default timing register value.
    NvU32 ControllerDefaultTiming;
    NvBool IsBCHEccSupported;
}NvDdkNandDriverCapabilities;

/**
 * The structure for locking of required NAND flash pages.
 */
typedef struct
{
    /// Device number of the flash being protected by lock feature.
    NvU8 DeviceNumber;
    /// Starting page number, from where NAND lock feature should protect data.
    NvU32 StartPageNumber;
    /// Ending page number, up to where NAND lock feature should protect data.
    NvU32 EndPageNumber;
}LockParams;

/*
 * Macro to get expression for modulo value that is power of 2
 * Expression: DIVIDEND % (pow(2, Log2X))
 */
#define MACRO_MOD_LOG2NUM(DIVIDEND, Log2X) \
            ((DIVIDEND) & ((1 << (Log2X)) - 1))

/*
 * Macro to get expression for multiply by number which is power of 2
 * Expression: VAL * (1 << Log2Num)
 */
#define MACRO_POW2_LOG2NUM(Log2Num) \
            (1 << (Log2Num))

/*
 * Macro to get expression for multiply by number which is power of 2
 * Expression: VAL * (1 << Log2Num)
 */
#define MACRO_MULT_POW2_LOG2NUM(VAL, Log2Num) \
            ((VAL) << (Log2Num))

/*
 * Macro to get expression for div by number that is power of 2
 * Expression: VAL / (1 << Log2Num)
 */
#define MACRO_DIV_POW2_LOG2NUM(VAL, Log2Num) \
            ((VAL) >> (Log2Num))

/**
 * Initializes the NAND Controller and returns a created handle to the client.
 * Only one instance of the handle can be created.
 *
 * @pre NAND client must call this API first before calling any further NAND APIs.
 *
 * @param hRmDevice Handle to RM device.
 * @param phNand Returns the created handle.
 *
 * @retval NvSuccess Initialization is successful.
 * @retval NvError_AlreadyAllocated The NAND device is already in use.
 */
NvError NvDdkNandOpen(NvRmDeviceHandle hRmDevice, NvDdkNandHandle *phNand);

/**
 * Closes the NAND controller and frees the handle.
 *
 * @param hNand Handle to the NAND, which is returned by NvDdkNandOpen().
 *
 */
void NvDdkNandClose(NvDdkNandHandle hNand);

/**
 * Reads the data from the selected NAND device(s) synchronously.
 *
 * @param hNand Handle to the NAND, which is returned by NvDdkNandOpen().
 * @param StartDeviceNum The Device number, which read operation has to be 
 *      started from. It starts from value '0'.
 * @param pPageNumbers A pointer to an array containing page numbers for
 *      each NAND Device. If there are (n + 1) NAND Devices, then 
 *      array size should be (n + 1).
 *      - pPageNumbers[0] gives page number to access in NAND Device 0.
 *      - pPageNumbers[1] gives page number to access in NAND Device 1.
 *      - ....................................
 *      - pPageNumbers[n] gives page number to access in NAND Device n.
 *      
 *      If NAND Device 'n' should not be accessed, fill pPageNumbers[n] as 
 *      0xFFFFFFFF.
 *      If the read starts from NAND Device 'n', all the page numbers 
 *      in the array should correspond to the same row, even though we don't 
 *      access the same row pages for '0' to 'n-1' Devices.
 * @param pDataBuffer A pointer to read the page data into. The size of buffer 
 *      should be (*pNoOfPages * PageSize).
 * @param pTagBuffer Pointer to read the tag data into. The size of buffer 
 *      should be (*pNoOfPages * TagSize).
 * @param pNoOfPages The number of pages to read. This count should include 
 *      only valid page count. Consder that total NAND devices present is 4,
 *      Need to read 1 page from Device1 and 1 page from Device3. In this case,
 *      \a StartDeviceNum should be 1 and Number of pages should be 2. 
 *      \a pPageNumbers[0] and \a pPageNumbers[2] should have 0xFFFFFFFF.
 *      \a pPageNumbers[1] and \a pPageNumbers[3] should have valid page numbers.
 *      The same pointer returns the number of pages read successfully.
 * @param IgnoreEccError If set to NV_TRUE, it ignores the ECC error and 
 *      continues to read the subsequent pages with out aborting read operation.
 *      This is required during bad block replacements.
 *
 * @retval NvSuccess NAND read operation completed successfully.
 * @retval NvError_NandReadEccFailed Indicates NAND read encountered ECC 
 *      errors that cannot be corrected.
 * @retval NvError_NandErrorThresholdReached Indicates NAND read encountered 
 *      correctable ECC errors and they are equal to the threshold value set.
 * @retval NvError_NandOperationFailed NAND read operation failed.
 */
NvError
NvDdkNandRead(
    NvDdkNandHandle hNand,
    NvU8 StartDeviceNum,
    NvU32* pPageNumbers,
    NvU8* const pDataBuffer,
    NvU8* const pTagBuffer,
    NvU32 *pNoOfPages,
    NvBool IgnoreEccError);

/**
 * Writes the data to the selected NAND device(s) synchronously.
 *
 * @param hNand Handle to the NAND, which is returned by NvDdkNandOpen().
 * @param StartDeviceNum The device number, which write operation has to be 
 *      started from. It starts from value '0'.
 * @param pPageNumbers A pointer to an array containing page numbers for
 *      each NAND Device. If there are (n + 1) NAND Devices, then 
 *      array size should be (n + 1).
 *      - pPageNumbers[0] gives page number to access in NAND Device 0.
 *      - pPageNumbers[1] gives page number to access in NAND Device 1.
 *      - ....................................
 *      - pPageNumbers[n] gives page number to access in NAND Device n.
 *      
 *      If NAND Device 'n' should not be accessed, fill \a pPageNumbers[n] as 
 *      0xFFFFFFFF.
 *      If the read starts from NAND device 'n', all the page numbers 
 *      in the array should correspond to the same row, even though we don't 
 *      access the same row pages for '0' to 'n-1' Devices.
 * @param pDataBuffer A pointer to read the page data into. The size of buffer 
 *      should be (*pNoOfPages * PageSize).
 * @param pTagBuffer Pointer to read the tag data into. The size of buffer 
 *      should be (*pNoOfPages * TagSize).
 * @param pNoOfPages The number of pages to write. This count should include 
 *      only valid page count. Consder that total NAND devices present is 4,
 *      Need to write 1 page to Device1 and 1 page to Device3. In this case,
 *      \a StartDeviceNum should be 1 and Number of pages should be 2.
 *      \a pPageNumbers[0] and \a pPageNumbers[2] should have 0xFFFFFFFF.
 *      \a pPageNumbers[1] and \a pPageNumbers[3] should have valid page numbers.
 *      The same pointer returns the number of pages written successfully.
 * 
 * @retval NvSuccess Operation completed successfully.
 * @retval NvError_NandOperationFailed Operation failed.
 */
NvError
NvDdkNandWrite(
    NvDdkNandHandle hNand,
    NvU8 StartDeviceNum,
    NvU32* pPageNumbers,
    const NvU8* pDataBuffer,
    const NvU8* pTagBuffer,
    NvU32 *pNoOfPages);

/**
 * Erases the selected blocks from the NAND device(s) synchronously.
 *
 * @param hNand Handle to the NAND, which is returned by NvDdkNandOpen().
 * @param StartDeviceNum The Device number, which erase operation has to be 
 *      started from. It starts from value '0'.
 * @param pPageNumbers A pointer to an array containing page numbers for
 *      each NAND Device. If there are (n + 1) NAND Devices, then 
 *      array size should be (n + 1).
 *      - pPageNumbers[0] gives page number to access in NAND Device 0.
 *      - pPageNumbers[1] gives page number to access in NAND Device 1.
 *      - ....................................
 *      - pPageNumbers[n] gives page number to access in NAND Device n.
 *      
 *      If NAND Device 'n' should not be accessed, fill pPageNumbers[n] as 
 *      0xFFFFFFFF.
 *      If the read starts from NAND device 'n', all the page numbers 
 *      in the array should correspond to the same row, even though we don't 
 *      access the same row pages for '0' to 'n-1' Devices.
 * @param pNumberOfBlocks The number of blocks to erase. This count should include 
 *      only valid block count. Consder that total NAND devices present is 4,
 *      Need to erase 1 block from Device1 and 1 block from Device3. In this case,
 *      \a StartDeviceNum should be 1 and Number of blocks should be 2.
 *      \a pPageNumbers[0] and \a pPageNumbers[2] should have 0xFFFFFFFF.
 *      \a pPageNumbers[1] and \a pPageNumbers[3] should have valid page numbers
 *      corresponding to blocks.
 *      The same pointer returns the number of blocks erased successfully.
 *
 * @retval NvSuccess Operation completed successfully.
 * @retval NvError_NandOperationFailed Operation failed.
 */
NvError
NvDdkNandErase(
    NvDdkNandHandle hNand,
    NvU8 StartDeviceNum,
    NvU32* pPageNumbers,
    NvU32* pNumberOfBlocks);

/**
 * Copies the data in the source page(s) to the destination page(s) 
 *      synchronously.
 *
 * @param hNand Handle to the NAND, which is returned by NvDdkNandOpen().
 * @param SrcStartDeviceNum The device number, from which data has to be read 
 *      for the copy back operation. It starts from value '0'.
 * @param DstStartDeviceNum The device number, to which data has to be copied 
 *      for the copy back operation. It starts from value '0'.
 * @param pSrcPageNumbers A pointer to an array containing page numbers for
 *      each NAND Device. If there are (n + 1) NAND Devices, then 
 *      array size should be (n + 1).
 *      - pSrcPageNumbers[0] gives page number to access in NAND Device 0.
 *      - pSrcPageNumbers[1] gives page number to access in NAND Device 1.
 *      - ....................................
 *      - pSrcPageNumbers[n] gives page number to access in NAND Device n.
 *     
 *      If NAND Device 'n' should not be accessed, fill \a pSrcPageNumbers[n] as 
 *      0xFFFFFFFF.
 *      If the copy-back starts from NAND devices 'n', all the page numbers 
 *      in the array should correspond to the same row, even though we don't 
 *      access the same row pages for '0' to 'n-1' Devices.
 * @param pDestPageNumbers A pointer to an array containing page numbers for
 *      each NAND Device. If there are (n + 1) NAND Devices, then 
 *      array size should be (n + 1).
 *      - pDestPageNumbers[0] gives page number to access in NAND Device 0.
 *      - pDestPageNumbers[1] gives page number to access in NAND Device 1.
 *      - ....................................
 *      - pDestPageNumbers[n] gives page number to access in NAND Device n.
 *     
 *      If NAND Device 'n' should not be accessed, fill \a pDestPageNumbers[n] as 
 *      0xFFFFFFFF.
 *      If the Copy-back starts from Interleave column 'n', all the page numbers 
 *      in the array should correspond to the same row, even though we don't 
 *      access the same row pages for '0' to 'n-1' Devices.
 * @param pNoOfPages The number of pages to copy-back. This count should include 
 *      only valid page count. Consider that total NAND devices present is 4,
 *      Need to Copy-back 1 page from Device1 and 1 page from Device3. In this 
 *      case, \a StartDeviceNum should be 1 and Number of pages should be 2.
 *      \a pSrcPageNumbers[0], \a pSrcPageNumbers[2], \a pDestPageNumbers[0] and 
 *      \a pDestPageNumbers[2] should have 0xFFFFFFFF. \a pSrcPageNumbers[1], 
 *      \a pSrcPageNumbers[3], \a pDestPageNumbers[1] and \a pDestPageNumbers[3]
 *      should have valid page numbers.
 *      The same pointer returns the number of pages copied-back successfully.
 * @param IgnoreEccError NV_TRUE to ingnore ECC errors, NV_FALSE otherwise.
 * 
 * @retval NvSuccess Operation completed successfully
 * @retval NvError_NandOperationFailed Operation failed.
 */
NvError
NvDdkNandCopybackPages(
    NvDdkNandHandle hNand,
    NvU8 SrcStartDeviceNum,
    NvU8 DstStartDeviceNum,
    NvU32* pSrcPageNumbers,
    NvU32* pDestPageNumbers,
    NvU32 *pNoOfPages,
    NvBool IgnoreEccError);

/**
 * Gets the NAND flash device information.
 *
 * @param hNand Handle to the NAND, which is returned by NvDdkNandOpen().
 * @param DeviceNumber NAND flash device number.
 * @param pDeviceInfo Returns the device information.
 *
 * @retval NvSuccess Operation completed successfully.
 * @retval NvError_NandOperationFailed NAND copy back operation failed.
 */
 NvError
 NvDdkNandGetDeviceInfo(
    NvDdkNandHandle hNand,
    NvU8 DeviceNumber,
    NvDdkNandDeviceInfo* pDeviceInfo);

/**
 * Locks the specified NAND flash pages.
 *
 * @param hNand Handle to the NAND, which is returned by NvDdkNandOpen().
 * @param pFlashLockParams A pointer to the range of pages to be locked.
 */
void 
NvDdkNandSetFlashLock(
    NvDdkNandHandle hNand,
    LockParams* pFlashLockParams);

/**
 * Returns the details of the locked apertures, like device number, starting 
 * page number, ending page number of the region locked.
 *
 * @param hNand Handle to the NAND, which is returned by NvDdkNandOpen().
 * @param pFlashLockParams A pointer to first array element of \a LockParams type 
 * with eight elements in the array. 
 * Check if \a pFlashLockParams[i].DeviceNumber == 0xFF, then that aperture is 
 * free to use for locking.
 */
void 
NvDdkNandGetLockedRegions(
    NvDdkNandHandle hNand,
    LockParams* pFlashLockParams);
/**
 * Releases all regions that were locked using NvDdkNandSetFlashLock API.
 *
 * @param hNand Handle to the NAND, which is returned by NvDdkNandOpen().
 */
void NvDdkNandReleaseFlashLock(NvDdkNandHandle hNand);

/**
 * Gets the NAND driver capabilities.
 *
 * @param hNand Handle to the NAND, which is returned by NvDdkNandOpen().
 * @param pNandDriverCapabilities Returns the capabilities.
 *
 */
void
NvDdkNandGetCapabilities(
    NvDdkNandHandle hNand,
    NvDdkNandDriverCapabilities* pNandDriverCapabilities);

/**
 * Gives the block specific information such as tag information, lock status, block good/bad.
 * @param hNand Handle to the NAND, which is returned by NvDdkNandOpen().
 * @param DeviceNumber Device number in which the requested block exists.
 * @param BlockNumber Requested physical block number.
 * @param pBlockInfo Return the block information.
 * @param SkippedBytesReadEnable NV_TRUE enables reading skipped bytes.
 *
 * @retval NvSuccess Success
 */
NvError
NvDdkNandGetBlockInfo(
    NvDdkNandHandle hNand,
    NvU32 DeviceNumber,
    NvU32 BlockNumber,
    NandBlockInfo* pBlockInfo,
    NvBool SkippedBytesReadEnable);

/**
 * Part of static power management, call this API to put the NAND controller
 * into suspend state. This API is a mechanism for client to augment OS
 * power management policy.
 *
 * The h/w context of the NAND controller is saved. Clock is disabled and power
 * is also disabled to the controller.
 *
 * @param hNand Handle to the NAND, which is returned by NvDdkNandOpen().
 *
 * @retval NvSuccess Success
 * @retval NvError_BadParameter Invalid input parameter value
 */
NvError NvDdkNandSuspend(NvDdkNandHandle hNand);

/**
 * Part of static power management, call this API to wake the NAND controller
 * from suspend state. This API is a mechanism for client to augment OS power
 * management policy.
 *
 * The h/w context of the NAND controller is restored. Clock is enabled and power
 * is also enabled to the controller
 *
 * @param hNand Handle to the NAND, which is returned by NvDdkNandOpen().
 *
 * @retval NvSuccess Success
 * @retval NvError_BadParameter Invalid input parameter value
 */
NvError NvDdkNandResume(NvDdkNandHandle hNand);

/**
 * Part of local power management of the driver. Call this API to turn off the 
 * clocks required for NAND controller operation.
 *
 * @param hNand Handle to the NAND, which is returned by NvDdkNandOpen().
 *
 * @retval NvSuccess Success
 * @retval NvError_BadParameter Invalid input parameter value
 */
NvError NvDdkNandSuspendClocks(NvDdkNandHandle hNand);

/**
 * Part of local power management of the driver. Call this API to turn on the 
 * clocks required for NAND controller operation.
 *
 * @param hNand Handle to the NAND, which is returned by NvDdkNandOpen().
 *
 * @retval NvSuccess Success
 * @retval NvError_BadParameter Invalid input parameter value
 */
NvError NvDdkNandResumeClocks(NvDdkNandHandle hNand);

/**
 *  API to read to the spare area.
 */
NvError
NvDdkNandReadSpare(
    NvDdkNandHandle hNand,
    NvU8 StartDeviceNum,
    NvU32* pPageNumbers,
    NvU8* const pSpareBuffer,
    NvU8 OffsetInSpareAreaInBytes,
    NvU8 NumSpareAreaBytes);

/**
 *  API to write to the spare area. Use this API with caution, as there is a
 *  risk of overriding the factory bad block data.
 */
NvError
NvDdkNandWriteSpare(
    NvDdkNandHandle hNand,
    NvU8 StartDeviceNum,
    NvU32* pPageNumbers,
    NvU8* const pSpareBuffer,
    NvU8 OffsetInSpareAreaInBytes,
    NvU8 NumSpareAreaBytes);

/*
 * Functions shared between Ddk Nand, block driver and FTL code
 */
// Function to compare buffer contents
NvU32 NandUtilMemcmp(const void *pSrc, const void *pDst, NvU32 Size);

// Simple function to get log2, assumed value power of 2, else return 
// log2 for immediately smaller number
NvU8 NandUtilGetLog2(NvU32 Val);

#ifdef __cplusplus
}
#endif

/** @} */
#endif // INCLUDED_NVDDK_NAND_H