sm_common.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright © 2009 - Maxim Levitsky
  4. * Common routines & support for SmartMedia/xD format
  5. */
  6. #include <linux/bitops.h>
  7. #include <linux/mtd/mtd.h>
  8. /* Full oob structure as written on the flash */
  9. struct sm_oob {
  10. uint32_t reserved;
  11. uint8_t data_status;
  12. uint8_t block_status;
  13. uint8_t lba_copy1[2];
  14. uint8_t ecc2[3];
  15. uint8_t lba_copy2[2];
  16. uint8_t ecc1[3];
  17. } __packed;
  18. /* one sector is always 512 bytes, but it can consist of two nand pages */
  19. #define SM_SECTOR_SIZE 512
  20. /* oob area is also 16 bytes, but might be from two pages */
  21. #define SM_OOB_SIZE 16
  22. /* This is maximum zone size, and all devices that have more that one zone
  23. have this size */
  24. #define SM_MAX_ZONE_SIZE 1024
  25. /* support for small page nand */
  26. #define SM_SMALL_PAGE 256
  27. #define SM_SMALL_OOB_SIZE 8
  28. int sm_register_device(struct mtd_info *mtd, int smartmedia);
  29. static inline int sm_sector_valid(struct sm_oob *oob)
  30. {
  31. return hweight16(oob->data_status) >= 5;
  32. }
  33. static inline int sm_block_valid(struct sm_oob *oob)
  34. {
  35. return hweight16(oob->block_status) >= 7;
  36. }
  37. static inline int sm_block_erased(struct sm_oob *oob)
  38. {
  39. static const uint32_t erased_pattern[4] = {
  40. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
  41. /* First test for erased block */
  42. if (!memcmp(oob, erased_pattern, sizeof(*oob)))
  43. return 1;
  44. return 0;
  45. }