msm_qpic_nand.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. Introduction
  2. ============
  3. In MDM9x25, new NAND controller(NANDc) has been added and it has the
  4. following major changes as compared to its previous version -
  5. 1. It includes Secured BAM-Lite and the support for ADM(Application Data Mover)
  6. has been removed.
  7. 2. It includes 4 bit BCH ECC and the support for 4 bit Reed Solomon ECC has
  8. been removed.
  9. 3. The support for Dual NAND controllers has been removed and thus the
  10. software features like ping-pong mode and interleave mode are deprecated.
  11. 4. It includes support for dual buffers in case of read and one dedicated
  12. write buffer to each processor (Modem and Apps).
  13. This new NAND driver takes care of all the above new hardware changes. In
  14. addition to the above hardware changes, it also takes care of software device
  15. tree changes.
  16. Hardware description
  17. ====================
  18. The NANDc Core:
  19. ---------------
  20. Qualcomm Parallel Interface Controller (QPIC), formerly named EBI2, is a
  21. wrapper module which integrates a NAND controller core and a LCD controller
  22. core and multiplexes their access to shared parallel interfaces pins. Both
  23. controller cores are accessible to processors (Modem and Apps), and share
  24. master access to the Peripheral NoC (Network on Chip) via a BAM module.
  25. In MDM9x25, QPIC is located on the peripheral NoC, connected via a 32-bit AHB
  26. Master port and a 32-bit AHB Slave Port. The NANDc register interface goes
  27. through AHB Slave Port and data transfers using BAM goes through AHB Master
  28. Port. The NAND Controller (NANDc) is a hardware core which manages the access
  29. to an off-chip NAND device.
  30. BAM-Lite:
  31. ---------
  32. BAM(Bus Access Manager) can transfer data between a peripheral and memory,
  33. or between two peripherals in a BAM to BAM mode. Each BAM contains multiple
  34. DMA channels, called pipes. A pipe provides a unidirectional data transfer
  35. engine, capable of either receiving data in consumer mode, or transmitting
  36. data in producer mode. The consumer fetches the data from the source system
  37. memory, and the producer writes data to the destination system memory.
  38. BAM-Lite's interface is similar to the BAM interface with slight changes to
  39. the sideband interface. BAM-Lite is an area-optimized version of BAM. BAM-Lite
  40. supports new features such as Notify-When-Done(NWD), pipe lock/unlock and
  41. command descriptors.
  42. NANDc has a secured BAM-Lite which provides DMA support for the NANDc and
  43. command support for accessing the NANDc registers. It is called secured
  44. because it has an integrated APU (Address Protection Unit) that validates
  45. every access to BAM and its peripheral registers.
  46. The NANDc has in total 6 BAM pipes - 3 pipes are dedicated for each processor
  47. (Modem and Apps) at the hardware level.
  48. Software description
  49. ====================
  50. The NAND device is shared between two independent file systems, each running
  51. on a different processor - the application processor (Apps) and the Modem.
  52. The NAND driver uses BAM driver to transfer NAND operation requests and
  53. data to/from the NAND Controller (NANDc) core through the BAM pipes. Every
  54. NANDc register read/write access must go through BAM as it facilitates security
  55. mechanisms to enable simultaneous access to NAND device from both processors
  56. (Modem and Apps).
  57. The Apps NAND driver registers NANDc BAM peripheral with BAM driver, allocates
  58. endpoints and descriptor FIFO memory and registers for complete event
  59. notification for the following pipes:
  60. - system consumer pipe for data (pipe#0) : This BAM pipe will be used
  61. for transferring data from system memory to NANDc i.e., during write.
  62. - system producer pipe for data (pipe#1) : This BAM pipe will be used
  63. for transferring data from NANDc to system memory i.e., during read.
  64. - system consumer pipe for commands (pipe#2) : This BAM pipe will be
  65. used for both reading and writing to NANDc registers. It can be
  66. configured either as consumer pipe or producer pipe but as per HW
  67. team's recommendation it is configured as consumer pipe.
  68. Control path:
  69. -------------
  70. Each NAND operation can be described as a set of BAM command or/and data
  71. descriptors.
  72. A command descriptor(CD) points to the starting address of a command
  73. block. Each command block may contain a set of command elements where
  74. each command element is a single NANDc register read/write. The NAND
  75. driver submits all command descriptors to its system consumer pipe#2.
  76. Data path:
  77. ----------
  78. A Data Descriptor(DD) points to the start of a data block which is a sequential
  79. chunk of data.
  80. For page write operations, the NAND driver submits data descriptors to system
  81. consumer pipe#0 and as per the descriptors submitted, the BAM reads data from
  82. the data block into the NANDc buffer.
  83. For page read operations, the NAND driver submits data descriptors to system
  84. producer pipe#1 and as per the descriptors submitted, the BAM reads data from
  85. the NANDc buffer into the data block.
  86. The driver submits a CD/DD using BAM driver APIs sps_transfer_one()/
  87. sps_transfer(). To this API, flags is passed as one of the arguments and if
  88. SPS_IOVEC_FLAG_CMD is passed, then it is identified as a CD. Otherwise, it is
  89. identified as a DD. The other valid SPS flags for a CD/DD are -
  90. - SPS_IOVEC_FLAG_INT : This flag indicates BAM driver to raise BAM
  91. interrupt after the current descriptor with this flag has been
  92. processed by BAM HW. This flag is applicable for both CD and DD.
  93. - SPS_IOVEC_FLAG_NWD : This flag indicates BAM HW to not process
  94. next descriptors until it receives an acknowledgement by NANDc
  95. that the current descriptor with this flag is completely
  96. executed. This flag is applicable only for a CD.
  97. - SPS_IOVEC_FLAG_LOCK: This flag marks the beginning of a series of
  98. commands and it indicates that all the CDs submitted on this pipe
  99. must be executed atomically without any interruption by commands
  100. from other pipes. This is applicable only for a CD.
  101. - SPS_IOVEC_FLAG_UNLOCK: This flag marks the end of a series of
  102. commands and it indicates that the other pipe that was locked due to
  103. SPS_IOVEC_FLAG_LOCK flag can be unblocked after the current CD
  104. with this flag is executed. This is applicable only for a CD.
  105. - SPS_IOVEC_FLAG_EOT - This flag indicates to BAM driver that the
  106. current descriptor with this flag is the last descriptor submitted
  107. during write operation. This is applicable only for a DD.
  108. Error handling:
  109. ---------------
  110. After a page read/write complete notification from BAM, NAND driver validates
  111. the values read from NANDc registers to confirm the success/failure of page
  112. read/write operation. For example, after a page read/write is complete, the
  113. drivers reads the NANDc status registers to check for any operational errors,
  114. protection violation errors and device status errors, number of correctable/
  115. uncorrectable errors reported by the controller. Based on the error conditions
  116. that are met, the driver reports appropriate error codes to upper layers. The
  117. upper layers respond to these errors and take appropriate action.
  118. Design
  119. ======
  120. The existing NAND driver (ADM based) can not be reused due to many major HW
  121. changes (see Introduction section) in the new NANDc core. Some of the complex
  122. features (Dual NAND controllers support) too are deprecated in the new NANDc.
  123. Hence, a new NAND driver is written to take care of both SPS/BAM changes and
  124. other controller specific changes. The rest of the interaction with MTD and
  125. YAFFS2 remains same as its previous version of NAND driver msm_nand.c.
  126. Power Management
  127. ================
  128. Two clocks are supplied by the system's clock controller to NANDc - AHB clock
  129. and interface clock. The interface clock is the clock that drives some of the
  130. HW blocks within NANDc. As of now, both these clocks are always on. But NANDc
  131. provides clock gating if some of the QPIC clock control registers are
  132. configured. The clock gating is yet to be enabled by driver.
  133. SMP/Multi-Core
  134. ==============
  135. The locking mechanism for page read/write operations is taken care of by the
  136. higher layers such as MTD/YAFFS2 and only one single page operation can happen
  137. at any time on a given partition. For a single page operation, there is always
  138. only one context associated within the driver and thus no additional handling
  139. is required within the driver. But it is possible for file system to issue
  140. one request on partition and at the same time to issue another request on
  141. another partition as each partition corresponds to different MTD block device.
  142. This situation is handled within the driver by properly acquiring a mutex lock
  143. before submitting any command/data descriptors to any of the BAM pipes.
  144. Security
  145. ========
  146. The same NAND device is accessible from both processors (Modem and Apps) and
  147. thus to avoid any configuration overwrite issues during a page operation,
  148. driver on each processor (Modem and Apps) must explicitly use BAM pipe
  149. lock/unlock mechanism. This is taken care of by the NAND driver. The partition
  150. violation issues are prevented by an MPU (Memory Protection Unit) that is
  151. attached to NANDc.
  152. Performance
  153. ===========
  154. None.
  155. Interface
  156. =========
  157. The NAND driver registers each partition on NAND device as a MTD block device
  158. using mtd_device_register(). As part of this registration, the following ops
  159. (struct mtd_info *mtd) are registered with MTD layer for each partition:
  160. mtd->_block_isbad = msm_nand_block_isbad;
  161. mtd->_block_markbad = msm_nand_block_markbad;
  162. mtd->_read = msm_nand_read;
  163. mtd->_write = msm_nand_write;
  164. mtd->_read_oob = msm_nand_read_oob;
  165. mtd->_write_oob = msm_nand_write_oob;
  166. mtd->_erase = msm_nand_erase;
  167. msm_nand_block_isbad() - This checks if a block is bad or not by reading bad
  168. block byte in the first page of a block. A block is considered as bad if bad
  169. block byte location contains any value other than 0xFF.
  170. msm_nand_block_markbad() - This marks a block as bad by writing 0 to the
  171. entire first page of the block and thus writing 0 to bad block byte location.
  172. msm_nand_read/write() - This is used to read/write only main data from/to
  173. single/multiple pages within NAND device. The YAFFS2 file system can send
  174. read/write request for two types of data -
  175. - Main data : This is the actual data to be read/written from/to a
  176. page during a read/write operation on this device. The size of this
  177. data request is typically based on the page size of the device
  178. (2K/4K).
  179. - OOB(Out Of Band) data : This is the spare data that will be used by
  180. file system to keep track of its meta data/tags associated with the
  181. actual data. As of now, the file system needs only 16 bytes to
  182. accommodate this data. The NAND driver always writes this data
  183. towards the end of main data.
  184. It is up to the file system whether or not to send a read/write request for OOB
  185. data along with main data.
  186. msm_nand_read_oob()/write_oob() - This is used to read/write both main data
  187. and spare data from/to single/multiple pages within NAND device.
  188. msm_nand_erase() - This erases the complete block by sending erase command to
  189. the device.
  190. The YAFFS2 file system registers as the user of MTD device and uses the ops
  191. exposed by the NAND driver to perform read/write/erase operations on NAND
  192. device. As of now, the driver can work with only YAFFS2 file system. An
  193. attempt to use it with any other file system might demand additional changes
  194. in the driver.
  195. Driver parameters
  196. =================
  197. None.
  198. Config options
  199. ==============
  200. The config option MTD_MSM_QPIC_NAND enables this driver.
  201. Dependencies
  202. ============
  203. It depends on the following kernel components:
  204. - SPS/BAM driver
  205. - MTD core layer
  206. - To add necessary NANDc and BAM resources to .dts file
  207. It depends on the following non-kernel components:
  208. The partition information of the NAND device must be passed by Modem subsystem
  209. to Apps boot loader and Apps boot loader must update the .dts file
  210. with the partition information as per the defined MTD bindings.
  211. The detailed information on MTD bindings can be found at -
  212. Documentation/devicetree/bindings/mtd/msm_qpic_nand.txt
  213. User space utilities
  214. ====================
  215. None.
  216. Other
  217. =====
  218. No changes other than device tree changes are anticipated.
  219. Known issues
  220. ============
  221. None.
  222. To do
  223. =====
  224. The NANDc core supports clock gating and is not yet supported by the driver.