onenand.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * linux/include/linux/mtd/onenand.h
  3. *
  4. * Copyright (C) 2005 Samsung Electronics
  5. * Kyungmin Park <kyungmin.park@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #ifndef __LINUX_MTD_ONENAND_H
  12. #define __LINUX_MTD_ONENAND_H
  13. #include <linux/spinlock.h>
  14. #include <linux/mtd/onenand_regs.h>
  15. #include <linux/mtd/bbm.h>
  16. #define MAX_BUFFERRAM 2
  17. /* Scan and identify a OneNAND device */
  18. extern int onenand_scan(struct mtd_info *mtd, int max_chips);
  19. /* Free resources held by the OneNAND device */
  20. extern void onenand_release(struct mtd_info *mtd);
  21. /**
  22. * onenand_state_t - chip states
  23. * Enumeration for OneNAND flash chip state
  24. */
  25. typedef enum {
  26. FL_READY,
  27. FL_READING,
  28. FL_WRITING,
  29. FL_ERASING,
  30. FL_SYNCING,
  31. FL_UNLOCKING,
  32. FL_LOCKING,
  33. FL_PM_SUSPENDED,
  34. } onenand_state_t;
  35. /**
  36. * struct onenand_bufferram - OneNAND BufferRAM Data
  37. * @param block block address in BufferRAM
  38. * @param page page address in BufferRAM
  39. * @param valid valid flag
  40. */
  41. struct onenand_bufferram {
  42. int block;
  43. int page;
  44. int valid;
  45. };
  46. /**
  47. * struct onenand_chip - OneNAND Private Flash Chip Data
  48. * @param base [BOARDSPECIFIC] address to access OneNAND
  49. * @param chipsize [INTERN] the size of one chip for multichip arrays
  50. * @param device_id [INTERN] device ID
  51. * @param verstion_id [INTERN] version ID
  52. * @param options [BOARDSPECIFIC] various chip options. They can partly be set to inform onenand_scan about
  53. * @param erase_shift [INTERN] number of address bits in a block
  54. * @param page_shift [INTERN] number of address bits in a page
  55. * @param ppb_shift [INTERN] number of address bits in a pages per block
  56. * @param page_mask [INTERN] a page per block mask
  57. * @param bufferam_index [INTERN] BufferRAM index
  58. * @param bufferam [INTERN] BufferRAM info
  59. * @param readw [REPLACEABLE] hardware specific function for read short
  60. * @param writew [REPLACEABLE] hardware specific function for write short
  61. * @param command [REPLACEABLE] hardware specific function for writing commands to the chip
  62. * @param wait [REPLACEABLE] hardware specific function for wait on ready
  63. * @param read_bufferram [REPLACEABLE] hardware specific function for BufferRAM Area
  64. * @param write_bufferram [REPLACEABLE] hardware specific function for BufferRAM Area
  65. * @param read_word [REPLACEABLE] hardware specific function for read register of OneNAND
  66. * @param write_word [REPLACEABLE] hardware specific function for write register of OneNAND
  67. * @param scan_bbt [REPLACEALBE] hardware specific function for scaning Bad block Table
  68. * @param chip_lock [INTERN] spinlock used to protect access to this structure and the chip
  69. * @param wq [INTERN] wait queue to sleep on if a OneNAND operation is in progress
  70. * @param state [INTERN] the current state of the OneNAND device
  71. * @param autooob [REPLACEABLE] the default (auto)placement scheme
  72. * @param bbm [REPLACEABLE] pointer to Bad Block Management
  73. * @param priv [OPTIONAL] pointer to private chip date
  74. */
  75. struct onenand_chip {
  76. void __iomem *base;
  77. unsigned int chipsize;
  78. unsigned int device_id;
  79. unsigned int density_mask;
  80. unsigned int options;
  81. unsigned int erase_shift;
  82. unsigned int page_shift;
  83. unsigned int ppb_shift; /* Pages per block shift */
  84. unsigned int page_mask;
  85. unsigned int bufferram_index;
  86. struct onenand_bufferram bufferram[MAX_BUFFERRAM];
  87. int (*command)(struct mtd_info *mtd, int cmd, loff_t address, size_t len);
  88. int (*wait)(struct mtd_info *mtd, int state);
  89. int (*read_bufferram)(struct mtd_info *mtd, int area,
  90. unsigned char *buffer, int offset, size_t count);
  91. int (*write_bufferram)(struct mtd_info *mtd, int area,
  92. const unsigned char *buffer, int offset, size_t count);
  93. unsigned short (*read_word)(void __iomem *addr);
  94. void (*write_word)(unsigned short value, void __iomem *addr);
  95. void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
  96. int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
  97. int (*scan_bbt)(struct mtd_info *mtd);
  98. spinlock_t chip_lock;
  99. wait_queue_head_t wq;
  100. onenand_state_t state;
  101. unsigned char *page_buf;
  102. struct nand_oobinfo *autooob;
  103. void *bbm;
  104. void *priv;
  105. };
  106. /*
  107. * Helper macros
  108. */
  109. #define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index)
  110. #define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1)
  111. #define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1)
  112. #define ONENAND_GET_SYS_CFG1(this) \
  113. (this->read_word(this->base + ONENAND_REG_SYS_CFG1))
  114. #define ONENAND_SET_SYS_CFG1(v, this) \
  115. (this->write_word(v, this->base + ONENAND_REG_SYS_CFG1))
  116. /*
  117. * Options bits
  118. */
  119. #define ONENAND_CONT_LOCK (0x0001)
  120. #define ONENAND_PAGEBUF_ALLOC (0x1000)
  121. /*
  122. * OneNAND Flash Manufacturer ID Codes
  123. */
  124. #define ONENAND_MFR_SAMSUNG 0xec
  125. /**
  126. * struct nand_manufacturers - NAND Flash Manufacturer ID Structure
  127. * @param name: Manufacturer name
  128. * @param id: manufacturer ID code of device.
  129. */
  130. struct onenand_manufacturers {
  131. int id;
  132. char *name;
  133. };
  134. #endif /* __LINUX_MTD_ONENAND_H */