onenand.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * linux/include/linux/mtd/onenand.h
  3. *
  4. * Copyright (C) 2005-2007 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/mtd/onenand_regs.h>
  14. /* Note: The header order is impoertant */
  15. #include <onenand_uboot.h>
  16. #include <linux/mtd/compat.h>
  17. #include <linux/mtd/bbm.h>
  18. #define MAX_BUFFERRAM 2
  19. #define MAX_ONENAND_PAGESIZE (2048 + 64)
  20. /* Scan and identify a OneNAND device */
  21. extern int onenand_scan (struct mtd_info *mtd, int max_chips);
  22. /* Free resources held by the OneNAND device */
  23. extern void onenand_release (struct mtd_info *mtd);
  24. /**
  25. * struct onenand_bufferram - OneNAND BufferRAM Data
  26. * @param blockpage block & page address in BufferRAM
  27. */
  28. struct onenand_bufferram {
  29. int blockpage;
  30. };
  31. /**
  32. * struct onenand_chip - OneNAND Private Flash Chip Data
  33. * @param base [BOARDSPECIFIC] address to access OneNAND
  34. * @param chipsize [INTERN] the size of one chip for multichip arrays
  35. * @param device_id [INTERN] device ID
  36. * @param verstion_id [INTERN] version ID
  37. * @param options [BOARDSPECIFIC] various chip options. They can partly be set to inform onenand_scan about
  38. * @param erase_shift [INTERN] number of address bits in a block
  39. * @param page_shift [INTERN] number of address bits in a page
  40. * @param ppb_shift [INTERN] number of address bits in a pages per block
  41. * @param page_mask [INTERN] a page per block mask
  42. * @param writesize [INTERN] a real page size
  43. * @param bufferam_index [INTERN] BufferRAM index
  44. * @param bufferam [INTERN] BufferRAM info
  45. * @param readw [REPLACEABLE] hardware specific function for read short
  46. * @param writew [REPLACEABLE] hardware specific function for write short
  47. * @param command [REPLACEABLE] hardware specific function for writing commands to the chip
  48. * @param wait [REPLACEABLE] hardware specific function for wait on ready
  49. * @param read_bufferram [REPLACEABLE] hardware specific function for BufferRAM Area
  50. * @param write_bufferram [REPLACEABLE] hardware specific function for BufferRAM Area
  51. * @param chip_lock [INTERN] spinlock used to protect access to this structure and the chip
  52. * @param wq [INTERN] wait queue to sleep on if a OneNAND operation is in progress
  53. * @param state [INTERN] the current state of the OneNAND device
  54. * @param autooob [REPLACEABLE] the default (auto)placement scheme
  55. * @param priv [OPTIONAL] pointer to private chip date
  56. */
  57. struct onenand_chip {
  58. void __iomem *base;
  59. unsigned int chipsize;
  60. unsigned int device_id;
  61. unsigned int version_id;
  62. unsigned int density_mask;
  63. unsigned int options;
  64. unsigned int erase_shift;
  65. unsigned int page_shift;
  66. unsigned int ppb_shift; /* Pages per block shift */
  67. unsigned int page_mask;
  68. unsigned int writesize;
  69. unsigned int bufferram_index;
  70. struct onenand_bufferram bufferram[MAX_BUFFERRAM];
  71. int (*command) (struct mtd_info *mtd, int cmd, loff_t address,
  72. size_t len);
  73. int (*wait) (struct mtd_info *mtd, int state);
  74. int (*bbt_wait) (struct mtd_info *mtd, int state);
  75. int (*read_bufferram) (struct mtd_info *mtd, loff_t addr, int area,
  76. unsigned char *buffer, int offset, size_t count);
  77. int (*read_spareram) (struct mtd_info *mtd, loff_t addr, int area,
  78. unsigned char *buffer, int offset, size_t count);
  79. int (*write_bufferram) (struct mtd_info *mtd, loff_t addr, int area,
  80. const unsigned char *buffer, int offset,
  81. size_t count);
  82. unsigned short (*read_word) (void __iomem *addr);
  83. void (*write_word) (unsigned short value, void __iomem *addr);
  84. void (*mmcontrol) (struct mtd_info *mtd, int sync_read);
  85. int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
  86. int (*scan_bbt)(struct mtd_info *mtd);
  87. unsigned char *main_buf;
  88. unsigned char *spare_buf;
  89. #ifdef DONT_USE_UBOOT
  90. spinlock_t chip_lock;
  91. wait_queue_head_t wq;
  92. #endif
  93. int state;
  94. unsigned char *page_buf;
  95. unsigned char *oob_buf;
  96. struct nand_oobinfo *autooob;
  97. int subpagesize;
  98. struct nand_ecclayout *ecclayout;
  99. void *bbm;
  100. void *priv;
  101. };
  102. /*
  103. * Helper macros
  104. */
  105. #define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index)
  106. #define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1)
  107. #define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1)
  108. #define ONENAND_SET_PREV_BUFFERRAM(this) (this->bufferram_index ^= 1)
  109. #define ONENAND_SET_BUFFERRAM0(this) (this->bufferram_index = 0)
  110. #define ONENAND_SET_BUFFERRAM1(this) (this->bufferram_index = 1)
  111. #define ONENAND_IS_DDP(this) \
  112. (this->device_id & ONENAND_DEVICE_IS_DDP)
  113. #define ONENAND_IS_2PLANE(this) (0)
  114. /*
  115. * Options bits
  116. */
  117. #define ONENAND_HAS_CONT_LOCK (0x0001)
  118. #define ONENAND_HAS_UNLOCK_ALL (0x0002)
  119. #define ONENAND_HAS_2PLANE (0x0004)
  120. #define ONENAND_PAGEBUF_ALLOC (0x1000)
  121. #define ONENAND_OOBBUF_ALLOC (0x2000)
  122. /*
  123. * OneNAND Flash Manufacturer ID Codes
  124. */
  125. #define ONENAND_MFR_SAMSUNG 0xec
  126. /**
  127. * struct nand_manufacturers - NAND Flash Manufacturer ID Structure
  128. * @param name: Manufacturer name
  129. * @param id: manufacturer ID code of device.
  130. */
  131. struct onenand_manufacturers {
  132. int id;
  133. char *name;
  134. };
  135. int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
  136. struct mtd_oob_ops *ops);
  137. #endif /* __LINUX_MTD_ONENAND_H */