onenand.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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/bbm.h>
  17. #define MAX_BUFFERRAM 2
  18. #define MAX_ONENAND_PAGESIZE (2048 + 64)
  19. /* Scan and identify a OneNAND device */
  20. extern int onenand_scan (struct mtd_info *mtd, int max_chips);
  21. /* Free resources held by the OneNAND device */
  22. extern void onenand_release (struct mtd_info *mtd);
  23. /**
  24. * onenand_state_t - chip states
  25. * Enumeration for OneNAND flash chip state
  26. */
  27. typedef enum {
  28. FL_READY,
  29. FL_READING,
  30. FL_WRITING,
  31. FL_ERASING,
  32. FL_SYNCING,
  33. FL_UNLOCKING,
  34. FL_LOCKING,
  35. } onenand_state_t;
  36. /**
  37. * struct onenand_bufferram - OneNAND BufferRAM Data
  38. * @param block block address in BufferRAM
  39. * @param page page address in BufferRAM
  40. * @param valid valid flag
  41. */
  42. struct onenand_bufferram {
  43. int block;
  44. int page;
  45. int valid;
  46. };
  47. /**
  48. * struct onenand_chip - OneNAND Private Flash Chip Data
  49. * @param base [BOARDSPECIFIC] address to access OneNAND
  50. * @param chipsize [INTERN] the size of one chip for multichip arrays
  51. * @param device_id [INTERN] device ID
  52. * @param verstion_id [INTERN] version ID
  53. * @param options [BOARDSPECIFIC] various chip options. They can partly be set to inform onenand_scan about
  54. * @param erase_shift [INTERN] number of address bits in a block
  55. * @param page_shift [INTERN] number of address bits in a page
  56. * @param ppb_shift [INTERN] number of address bits in a pages per block
  57. * @param page_mask [INTERN] a page per block mask
  58. * @param bufferam_index [INTERN] BufferRAM index
  59. * @param bufferam [INTERN] BufferRAM info
  60. * @param readw [REPLACEABLE] hardware specific function for read short
  61. * @param writew [REPLACEABLE] hardware specific function for write short
  62. * @param command [REPLACEABLE] hardware specific function for writing commands to the chip
  63. * @param wait [REPLACEABLE] hardware specific function for wait on ready
  64. * @param read_bufferram [REPLACEABLE] hardware specific function for BufferRAM Area
  65. * @param write_bufferram [REPLACEABLE] hardware specific function for BufferRAM Area
  66. * @param chip_lock [INTERN] spinlock used to protect access to this structure and the chip
  67. * @param wq [INTERN] wait queue to sleep on if a OneNAND operation is in progress
  68. * @param state [INTERN] the current state of the OneNAND device
  69. * @param autooob [REPLACEABLE] the default (auto)placement scheme
  70. * @param priv [OPTIONAL] pointer to private chip date
  71. */
  72. struct onenand_chip {
  73. void __iomem *base;
  74. unsigned int chipsize;
  75. unsigned int device_id;
  76. unsigned int options;
  77. unsigned int erase_shift;
  78. unsigned int page_shift;
  79. unsigned int ppb_shift; /* Pages per block shift */
  80. unsigned int page_mask;
  81. unsigned int bufferram_index;
  82. struct onenand_bufferram bufferram[MAX_BUFFERRAM];
  83. int (*command) (struct mtd_info * mtd, int cmd, loff_t address,
  84. size_t len);
  85. int (*wait) (struct mtd_info * mtd, int state);
  86. int (*read_bufferram) (struct mtd_info * mtd, int area,
  87. unsigned char *buffer, int offset, size_t count);
  88. int (*write_bufferram) (struct mtd_info * mtd, int area,
  89. const unsigned char *buffer, int offset,
  90. size_t count);
  91. unsigned short (*read_word) (void __iomem * addr);
  92. void (*write_word) (unsigned short value, void __iomem * addr);
  93. void (*mmcontrol) (struct mtd_info * mtd, int sync_read);
  94. spinlock_t chip_lock;
  95. wait_queue_head_t wq;
  96. onenand_state_t state;
  97. struct nand_oobinfo *autooob;
  98. void *bbm;
  99. void *priv;
  100. };
  101. #define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index)
  102. #define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1)
  103. #define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1)
  104. /*
  105. * Options bits
  106. */
  107. #define ONENAND_CONT_LOCK (0x0001)
  108. /*
  109. * OneNAND Flash Manufacturer ID Codes
  110. */
  111. #define ONENAND_MFR_SAMSUNG 0xec
  112. #define ONENAND_MFR_UNKNOWN 0x00
  113. /**
  114. * struct nand_manufacturers - NAND Flash Manufacturer ID Structure
  115. * @param name: Manufacturer name
  116. * @param id: manufacturer ID code of device.
  117. */
  118. struct onenand_manufacturers {
  119. int id;
  120. char *name;
  121. };
  122. #endif /* __LINUX_MTD_ONENAND_H */