sm_common.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. /* Full oob structure as written on the flash */
  12. struct sm_oob {
  13. uint32_t reserved;
  14. uint8_t data_status;
  15. uint8_t block_status;
  16. uint8_t lba_copy1[2];
  17. uint8_t ecc2[3];
  18. uint8_t lba_copy2[2];
  19. uint8_t ecc1[3];
  20. } __packed;
  21. /* one sector is always 512 bytes, but it can consist of two nand pages */
  22. #define SM_SECTOR_SIZE 512
  23. /* oob area is also 16 bytes, but might be from two pages */
  24. #define SM_OOB_SIZE 16
  25. /* This is maximum zone size, and all devices that have more that one zone
  26. have this size */
  27. #define SM_MAX_ZONE_SIZE 1024
  28. /* support for small page nand */
  29. #define SM_SMALL_PAGE 256
  30. #define SM_SMALL_OOB_SIZE 8
  31. extern int sm_register_device(struct mtd_info *mtd, int smartmedia);
  32. static inline int sm_sector_valid(struct sm_oob *oob)
  33. {
  34. return hweight16(oob->data_status) >= 5;
  35. }
  36. static inline int sm_block_valid(struct sm_oob *oob)
  37. {
  38. return hweight16(oob->block_status) >= 7;
  39. }
  40. static inline int sm_block_erased(struct sm_oob *oob)
  41. {
  42. static const uint32_t erased_pattern[4] = {
  43. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
  44. /* First test for erased block */
  45. if (!memcmp(oob, erased_pattern, sizeof(*oob)))
  46. return 1;
  47. return 0;
  48. }