1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright © 2009 - Maxim Levitsky
4 * Common routines & support for SmartMedia/xD format
6 #include <linux/bitops.h>
7 #include <linux/mtd/mtd.h>
9 /* Full oob structure as written on the flash */
21 /* one sector is always 512 bytes, but it can consist of two nand pages */
22 #define SM_SECTOR_SIZE 512
24 /* oob area is also 16 bytes, but might be from two pages */
25 #define SM_OOB_SIZE 16
27 /* This is maximum zone size, and all devices that have more that one zone
29 #define SM_MAX_ZONE_SIZE 1024
31 /* support for small page nand */
32 #define SM_SMALL_PAGE 256
33 #define SM_SMALL_OOB_SIZE 8
36 int sm_register_device(struct mtd_info *mtd, int smartmedia);
39 static inline int sm_sector_valid(struct sm_oob *oob)
41 return hweight16(oob->data_status) >= 5;
44 static inline int sm_block_valid(struct sm_oob *oob)
46 return hweight16(oob->block_status) >= 7;
49 static inline int sm_block_erased(struct sm_oob *oob)
51 static const uint32_t erased_pattern[4] = {
52 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
54 /* First test for erased block */
55 if (!memcmp(oob, erased_pattern, sizeof(*oob)))