Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright © 2009 - Maxim Levitsky
0004  * Common routines & support for SmartMedia/xD format
0005  */
0006 #include <linux/bitops.h>
0007 #include <linux/mtd/mtd.h>
0008 
0009 /* Full oob structure as written on the flash */
0010 struct sm_oob {
0011     uint32_t reserved;
0012     uint8_t data_status;
0013     uint8_t block_status;
0014     uint8_t lba_copy1[2];
0015     uint8_t ecc2[3];
0016     uint8_t lba_copy2[2];
0017     uint8_t ecc1[3];
0018 } __packed;
0019 
0020 
0021 /* one sector is always 512 bytes, but it can consist of two nand pages */
0022 #define SM_SECTOR_SIZE      512
0023 
0024 /* oob area is also 16 bytes, but might be from two pages */
0025 #define SM_OOB_SIZE     16
0026 
0027 /* This is maximum zone size, and all devices that have more that one zone
0028    have this size */
0029 #define SM_MAX_ZONE_SIZE    1024
0030 
0031 /* support for small page nand */
0032 #define SM_SMALL_PAGE       256
0033 #define SM_SMALL_OOB_SIZE   8
0034 
0035 
0036 int sm_register_device(struct mtd_info *mtd, int smartmedia);
0037 
0038 
0039 static inline int sm_sector_valid(struct sm_oob *oob)
0040 {
0041     return hweight16(oob->data_status) >= 5;
0042 }
0043 
0044 static inline int sm_block_valid(struct sm_oob *oob)
0045 {
0046     return hweight16(oob->block_status) >= 7;
0047 }
0048 
0049 static inline int sm_block_erased(struct sm_oob *oob)
0050 {
0051     static const uint32_t erased_pattern[4] = {
0052         0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
0053 
0054     /* First test for erased block */
0055     if (!memcmp(oob, erased_pattern, sizeof(*oob)))
0056         return 1;
0057     return 0;
0058 }