flashchip.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright © 2000 Red Hat UK Limited
  4. * Copyright © 2000-2010 David Woodhouse <dwmw2@infradead.org>
  5. *
  6. */
  7. #ifndef __MTD_FLASHCHIP_H__
  8. #define __MTD_FLASHCHIP_H__
  9. #ifndef __UBOOT__
  10. /* For spinlocks. sched.h includes spinlock.h from whichever directory it
  11. * happens to be in - so we don't have to care whether we're on 2.2, which
  12. * has asm/spinlock.h, or 2.4, which has linux/spinlock.h
  13. */
  14. #include <linux/sched.h>
  15. #include <linux/mutex.h>
  16. #endif
  17. typedef enum {
  18. FL_READY,
  19. FL_STATUS,
  20. FL_CFI_QUERY,
  21. FL_JEDEC_QUERY,
  22. FL_ERASING,
  23. FL_ERASE_SUSPENDING,
  24. FL_ERASE_SUSPENDED,
  25. FL_WRITING,
  26. FL_WRITING_TO_BUFFER,
  27. FL_OTP_WRITE,
  28. FL_WRITE_SUSPENDING,
  29. FL_WRITE_SUSPENDED,
  30. FL_PM_SUSPENDED,
  31. FL_SYNCING,
  32. FL_UNLOADING,
  33. FL_LOCKING,
  34. FL_UNLOCKING,
  35. FL_POINT,
  36. FL_XIP_WHILE_ERASING,
  37. FL_XIP_WHILE_WRITING,
  38. FL_SHUTDOWN,
  39. /* These 2 come from nand_state_t, which has been unified here */
  40. FL_READING,
  41. FL_CACHEDPRG,
  42. /* These 4 come from onenand_state_t, which has been unified here */
  43. FL_RESETING,
  44. FL_OTPING,
  45. FL_PREPARING_ERASE,
  46. FL_VERIFYING_ERASE,
  47. FL_UNKNOWN
  48. } flstate_t;
  49. /* NOTE: confusingly, this can be used to refer to more than one chip at a time,
  50. if they're interleaved. This can even refer to individual partitions on
  51. the same physical chip when present. */
  52. struct flchip {
  53. unsigned long start; /* Offset within the map */
  54. // unsigned long len;
  55. /* We omit len for now, because when we group them together
  56. we insist that they're all of the same size, and the chip size
  57. is held in the next level up. If we get more versatile later,
  58. it'll make it a damn sight harder to find which chip we want from
  59. a given offset, and we'll want to add the per-chip length field
  60. back in.
  61. */
  62. int ref_point_counter;
  63. flstate_t state;
  64. flstate_t oldstate;
  65. unsigned int write_suspended:1;
  66. unsigned int erase_suspended:1;
  67. unsigned long in_progress_block_addr;
  68. struct mutex mutex;
  69. #ifndef __UBOOT__
  70. wait_queue_head_t wq; /* Wait on here when we're waiting for the chip
  71. to be ready */
  72. #endif
  73. int word_write_time;
  74. int buffer_write_time;
  75. int erase_time;
  76. int word_write_time_max;
  77. int buffer_write_time_max;
  78. int erase_time_max;
  79. void *priv;
  80. };
  81. /* This is used to handle contention on write/erase operations
  82. between partitions of the same physical chip. */
  83. struct flchip_shared {
  84. struct mutex lock;
  85. struct flchip *writing;
  86. struct flchip *erasing;
  87. };
  88. #endif /* __MTD_FLASHCHIP_H__ */