gpmi-nand.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * Freescale GPMI NAND Flash Driver
  3. *
  4. * Copyright (C) 2010-2011 Freescale Semiconductor, Inc.
  5. * Copyright (C) 2008 Embedded Alley Solutions, Inc.
  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 as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #ifndef __DRIVERS_MTD_NAND_GPMI_NAND_H
  18. #define __DRIVERS_MTD_NAND_GPMI_NAND_H
  19. #include <linux/mtd/nand.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/dma-mapping.h>
  22. #include <linux/fsl/mxs-dma.h>
  23. #define GPMI_CLK_MAX 5 /* MX6Q needs five clocks */
  24. struct resources {
  25. void __iomem *gpmi_regs;
  26. void __iomem *bch_regs;
  27. unsigned int bch_low_interrupt;
  28. unsigned int bch_high_interrupt;
  29. unsigned int dma_low_channel;
  30. unsigned int dma_high_channel;
  31. struct clk *clock[GPMI_CLK_MAX];
  32. };
  33. /**
  34. * struct bch_geometry - BCH geometry description.
  35. * @gf_len: The length of Galois Field. (e.g., 13 or 14)
  36. * @ecc_strength: A number that describes the strength of the ECC
  37. * algorithm.
  38. * @page_size: The size, in bytes, of a physical page, including
  39. * both data and OOB.
  40. * @metadata_size: The size, in bytes, of the metadata.
  41. * @ecc_chunk_size: The size, in bytes, of a single ECC chunk. Note
  42. * the first chunk in the page includes both data and
  43. * metadata, so it's a bit larger than this value.
  44. * @ecc_chunk_count: The number of ECC chunks in the page,
  45. * @payload_size: The size, in bytes, of the payload buffer.
  46. * @auxiliary_size: The size, in bytes, of the auxiliary buffer.
  47. * @auxiliary_status_offset: The offset into the auxiliary buffer at which
  48. * the ECC status appears.
  49. * @block_mark_byte_offset: The byte offset in the ECC-based page view at
  50. * which the underlying physical block mark appears.
  51. * @block_mark_bit_offset: The bit offset into the ECC-based page view at
  52. * which the underlying physical block mark appears.
  53. */
  54. struct bch_geometry {
  55. unsigned int gf_len;
  56. unsigned int ecc_strength;
  57. unsigned int page_size;
  58. unsigned int metadata_size;
  59. unsigned int ecc_chunk_size;
  60. unsigned int ecc_chunk_count;
  61. unsigned int payload_size;
  62. unsigned int auxiliary_size;
  63. unsigned int auxiliary_status_offset;
  64. unsigned int block_mark_byte_offset;
  65. unsigned int block_mark_bit_offset;
  66. };
  67. /**
  68. * struct boot_rom_geometry - Boot ROM geometry description.
  69. * @stride_size_in_pages: The size of a boot block stride, in pages.
  70. * @search_area_stride_exponent: The logarithm to base 2 of the size of a
  71. * search area in boot block strides.
  72. */
  73. struct boot_rom_geometry {
  74. unsigned int stride_size_in_pages;
  75. unsigned int search_area_stride_exponent;
  76. };
  77. /* DMA operations types */
  78. enum dma_ops_type {
  79. DMA_FOR_COMMAND = 1,
  80. DMA_FOR_READ_DATA,
  81. DMA_FOR_WRITE_DATA,
  82. DMA_FOR_READ_ECC_PAGE,
  83. DMA_FOR_WRITE_ECC_PAGE
  84. };
  85. /**
  86. * struct nand_timing - Fundamental timing attributes for NAND.
  87. * @data_setup_in_ns: The data setup time, in nanoseconds. Usually the
  88. * maximum of tDS and tWP. A negative value
  89. * indicates this characteristic isn't known.
  90. * @data_hold_in_ns: The data hold time, in nanoseconds. Usually the
  91. * maximum of tDH, tWH and tREH. A negative value
  92. * indicates this characteristic isn't known.
  93. * @address_setup_in_ns: The address setup time, in nanoseconds. Usually
  94. * the maximum of tCLS, tCS and tALS. A negative
  95. * value indicates this characteristic isn't known.
  96. * @gpmi_sample_delay_in_ns: A GPMI-specific timing parameter. A negative value
  97. * indicates this characteristic isn't known.
  98. * @tREA_in_ns: tREA, in nanoseconds, from the data sheet. A
  99. * negative value indicates this characteristic isn't
  100. * known.
  101. * @tRLOH_in_ns: tRLOH, in nanoseconds, from the data sheet. A
  102. * negative value indicates this characteristic isn't
  103. * known.
  104. * @tRHOH_in_ns: tRHOH, in nanoseconds, from the data sheet. A
  105. * negative value indicates this characteristic isn't
  106. * known.
  107. */
  108. struct nand_timing {
  109. int8_t data_setup_in_ns;
  110. int8_t data_hold_in_ns;
  111. int8_t address_setup_in_ns;
  112. int8_t gpmi_sample_delay_in_ns;
  113. int8_t tREA_in_ns;
  114. int8_t tRLOH_in_ns;
  115. int8_t tRHOH_in_ns;
  116. };
  117. struct gpmi_nand_data {
  118. /* System Interface */
  119. struct device *dev;
  120. struct platform_device *pdev;
  121. struct gpmi_nand_platform_data *pdata;
  122. /* Resources */
  123. struct resources resources;
  124. /* Flash Hardware */
  125. struct nand_timing timing;
  126. /* BCH */
  127. struct bch_geometry bch_geometry;
  128. struct completion bch_done;
  129. /* NAND Boot issue */
  130. bool swap_block_mark;
  131. struct boot_rom_geometry rom_geometry;
  132. /* MTD / NAND */
  133. struct nand_chip nand;
  134. struct mtd_info mtd;
  135. /* General-use Variables */
  136. int current_chip;
  137. unsigned int command_length;
  138. /* passed from upper layer */
  139. uint8_t *upper_buf;
  140. int upper_len;
  141. /* for DMA operations */
  142. bool direct_dma_map_ok;
  143. struct scatterlist cmd_sgl;
  144. char *cmd_buffer;
  145. struct scatterlist data_sgl;
  146. char *data_buffer_dma;
  147. void *page_buffer_virt;
  148. dma_addr_t page_buffer_phys;
  149. unsigned int page_buffer_size;
  150. void *payload_virt;
  151. dma_addr_t payload_phys;
  152. void *auxiliary_virt;
  153. dma_addr_t auxiliary_phys;
  154. /* DMA channels */
  155. #define DMA_CHANS 8
  156. struct dma_chan *dma_chans[DMA_CHANS];
  157. struct mxs_dma_data dma_data;
  158. enum dma_ops_type last_dma_type;
  159. enum dma_ops_type dma_type;
  160. struct completion dma_done;
  161. /* private */
  162. void *private;
  163. };
  164. /**
  165. * struct gpmi_nfc_hardware_timing - GPMI hardware timing parameters.
  166. * @data_setup_in_cycles: The data setup time, in cycles.
  167. * @data_hold_in_cycles: The data hold time, in cycles.
  168. * @address_setup_in_cycles: The address setup time, in cycles.
  169. * @use_half_periods: Indicates the clock is running slowly, so the
  170. * NFC DLL should use half-periods.
  171. * @sample_delay_factor: The sample delay factor.
  172. */
  173. struct gpmi_nfc_hardware_timing {
  174. uint8_t data_setup_in_cycles;
  175. uint8_t data_hold_in_cycles;
  176. uint8_t address_setup_in_cycles;
  177. bool use_half_periods;
  178. uint8_t sample_delay_factor;
  179. };
  180. /**
  181. * struct timing_threshod - Timing threshold
  182. * @max_data_setup_cycles: The maximum number of data setup cycles that
  183. * can be expressed in the hardware.
  184. * @internal_data_setup_in_ns: The time, in ns, that the NFC hardware requires
  185. * for data read internal setup. In the Reference
  186. * Manual, see the chapter "High-Speed NAND
  187. * Timing" for more details.
  188. * @max_sample_delay_factor: The maximum sample delay factor that can be
  189. * expressed in the hardware.
  190. * @max_dll_clock_period_in_ns: The maximum period of the GPMI clock that the
  191. * sample delay DLL hardware can possibly work
  192. * with (the DLL is unusable with longer periods).
  193. * If the full-cycle period is greater than HALF
  194. * this value, the DLL must be configured to use
  195. * half-periods.
  196. * @max_dll_delay_in_ns: The maximum amount of delay, in ns, that the
  197. * DLL can implement.
  198. * @clock_frequency_in_hz: The clock frequency, in Hz, during the current
  199. * I/O transaction. If no I/O transaction is in
  200. * progress, this is the clock frequency during
  201. * the most recent I/O transaction.
  202. */
  203. struct timing_threshod {
  204. const unsigned int max_chip_count;
  205. const unsigned int max_data_setup_cycles;
  206. const unsigned int internal_data_setup_in_ns;
  207. const unsigned int max_sample_delay_factor;
  208. const unsigned int max_dll_clock_period_in_ns;
  209. const unsigned int max_dll_delay_in_ns;
  210. unsigned long clock_frequency_in_hz;
  211. };
  212. /* Common Services */
  213. extern int common_nfc_set_geometry(struct gpmi_nand_data *);
  214. extern struct dma_chan *get_dma_chan(struct gpmi_nand_data *);
  215. extern void prepare_data_dma(struct gpmi_nand_data *,
  216. enum dma_data_direction dr);
  217. extern int start_dma_without_bch_irq(struct gpmi_nand_data *,
  218. struct dma_async_tx_descriptor *);
  219. extern int start_dma_with_bch_irq(struct gpmi_nand_data *,
  220. struct dma_async_tx_descriptor *);
  221. /* GPMI-NAND helper function library */
  222. extern int gpmi_init(struct gpmi_nand_data *);
  223. extern void gpmi_clear_bch(struct gpmi_nand_data *);
  224. extern void gpmi_dump_info(struct gpmi_nand_data *);
  225. extern int bch_set_geometry(struct gpmi_nand_data *);
  226. extern int gpmi_is_ready(struct gpmi_nand_data *, unsigned chip);
  227. extern int gpmi_send_command(struct gpmi_nand_data *);
  228. extern void gpmi_begin(struct gpmi_nand_data *);
  229. extern void gpmi_end(struct gpmi_nand_data *);
  230. extern int gpmi_read_data(struct gpmi_nand_data *);
  231. extern int gpmi_send_data(struct gpmi_nand_data *);
  232. extern int gpmi_send_page(struct gpmi_nand_data *,
  233. dma_addr_t payload, dma_addr_t auxiliary);
  234. extern int gpmi_read_page(struct gpmi_nand_data *,
  235. dma_addr_t payload, dma_addr_t auxiliary);
  236. /* BCH : Status Block Completion Codes */
  237. #define STATUS_GOOD 0x00
  238. #define STATUS_ERASED 0xff
  239. #define STATUS_UNCORRECTABLE 0xfe
  240. /* Use the platform_id to distinguish different Archs. */
  241. #define IS_MX23 0x0
  242. #define IS_MX28 0x1
  243. #define IS_MX6Q 0x2
  244. #define GPMI_IS_MX23(x) ((x)->pdev->id_entry->driver_data == IS_MX23)
  245. #define GPMI_IS_MX28(x) ((x)->pdev->id_entry->driver_data == IS_MX28)
  246. #define GPMI_IS_MX6Q(x) ((x)->pdev->id_entry->driver_data == IS_MX6Q)
  247. #endif