Maxim Levitsky | 9fc51a3 | 2010-02-22 20:39:39 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2009 - Maxim Levitsky |
| 3 | * Common routines & support for SmartMedia/xD format |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation. |
| 8 | */ |
| 9 | #include <linux/bitops.h> |
| 10 | #include <linux/mtd/mtd.h> |
| 11 | |
| 12 | /* Full oob structure as written on the flash */ |
| 13 | struct sm_oob { |
| 14 | uint32_t reserved; |
| 15 | uint8_t data_status; |
| 16 | uint8_t block_status; |
| 17 | uint8_t lba_copy1[2]; |
| 18 | uint8_t ecc2[3]; |
| 19 | uint8_t lba_copy2[2]; |
| 20 | uint8_t ecc1[3]; |
| 21 | } __attribute__((packed)); |
| 22 | |
| 23 | |
| 24 | /* one sector is always 512 bytes, but it can consist of two nand pages */ |
| 25 | #define SM_SECTOR_SIZE 512 |
| 26 | |
| 27 | /* oob area is also 16 bytes, but might be from two pages */ |
| 28 | #define SM_OOB_SIZE 16 |
| 29 | |
| 30 | /* This is maximum zone size, and all devices that have more that one zone |
| 31 | have this size */ |
| 32 | #define SM_MAX_ZONE_SIZE 1024 |
| 33 | |
| 34 | /* support for small page nand */ |
| 35 | #define SM_SMALL_PAGE 256 |
| 36 | #define SM_SMALL_OOB_SIZE 8 |
| 37 | |
| 38 | |
Maxim Levitsky | c361157 | 2010-04-19 18:20:41 +0300 | [diff] [blame] | 39 | extern int sm_register_device(struct mtd_info *mtd, int smartmedia); |
Maxim Levitsky | 9fc51a3 | 2010-02-22 20:39:39 +0200 | [diff] [blame] | 40 | |
| 41 | |
Stephen Rothwell | 1f6ca0d | 2010-03-01 20:44:57 +1100 | [diff] [blame] | 42 | static inline int sm_sector_valid(struct sm_oob *oob) |
Maxim Levitsky | 9fc51a3 | 2010-02-22 20:39:39 +0200 | [diff] [blame] | 43 | { |
| 44 | return hweight16(oob->data_status) >= 5; |
| 45 | } |
| 46 | |
Stephen Rothwell | 1f6ca0d | 2010-03-01 20:44:57 +1100 | [diff] [blame] | 47 | static inline int sm_block_valid(struct sm_oob *oob) |
Maxim Levitsky | 9fc51a3 | 2010-02-22 20:39:39 +0200 | [diff] [blame] | 48 | { |
| 49 | return hweight16(oob->block_status) >= 7; |
| 50 | } |
| 51 | |
Stephen Rothwell | 1f6ca0d | 2010-03-01 20:44:57 +1100 | [diff] [blame] | 52 | static inline int sm_block_erased(struct sm_oob *oob) |
Maxim Levitsky | 9fc51a3 | 2010-02-22 20:39:39 +0200 | [diff] [blame] | 53 | { |
| 54 | static const uint32_t erased_pattern[4] = { |
| 55 | 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF }; |
| 56 | |
| 57 | /* First test for erased block */ |
| 58 | if (!memcmp(oob, erased_pattern, sizeof(*oob))) |
| 59 | return 1; |
| 60 | return 0; |
| 61 | } |