gpmi-nand.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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/dmaengine.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 dma_low_channel;
  28. unsigned int dma_high_channel;
  29. struct clk *clock[GPMI_CLK_MAX];
  30. };
  31. /**
  32. * struct bch_geometry - BCH geometry description.
  33. * @gf_len: The length of Galois Field. (e.g., 13 or 14)
  34. * @ecc_strength: A number that describes the strength of the ECC
  35. * algorithm.
  36. * @page_size: The size, in bytes, of a physical page, including
  37. * both data and OOB.
  38. * @metadata_size: The size, in bytes, of the metadata.
  39. * @ecc_chunk_size: The size, in bytes, of a single ECC chunk. Note
  40. * the first chunk in the page includes both data and
  41. * metadata, so it's a bit larger than this value.
  42. * @ecc_chunk_count: The number of ECC chunks in the page,
  43. * @payload_size: The size, in bytes, of the payload buffer.
  44. * @auxiliary_size: The size, in bytes, of the auxiliary buffer.
  45. * @auxiliary_status_offset: The offset into the auxiliary buffer at which
  46. * the ECC status appears.
  47. * @block_mark_byte_offset: The byte offset in the ECC-based page view at
  48. * which the underlying physical block mark appears.
  49. * @block_mark_bit_offset: The bit offset into the ECC-based page view at
  50. * which the underlying physical block mark appears.
  51. */
  52. struct bch_geometry {
  53. unsigned int gf_len;
  54. unsigned int ecc_strength;
  55. unsigned int page_size;
  56. unsigned int metadata_size;
  57. unsigned int ecc_chunk_size;
  58. unsigned int ecc_chunk_count;
  59. unsigned int payload_size;
  60. unsigned int auxiliary_size;
  61. unsigned int auxiliary_status_offset;
  62. unsigned int block_mark_byte_offset;
  63. unsigned int block_mark_bit_offset;
  64. };
  65. /**
  66. * struct boot_rom_geometry - Boot ROM geometry description.
  67. * @stride_size_in_pages: The size of a boot block stride, in pages.
  68. * @search_area_stride_exponent: The logarithm to base 2 of the size of a
  69. * search area in boot block strides.
  70. */
  71. struct boot_rom_geometry {
  72. unsigned int stride_size_in_pages;
  73. unsigned int search_area_stride_exponent;
  74. };
  75. /* DMA operations types */
  76. enum dma_ops_type {
  77. DMA_FOR_COMMAND = 1,
  78. DMA_FOR_READ_DATA,
  79. DMA_FOR_WRITE_DATA,
  80. DMA_FOR_READ_ECC_PAGE,
  81. DMA_FOR_WRITE_ECC_PAGE
  82. };
  83. /**
  84. * struct nand_timing - Fundamental timing attributes for NAND.
  85. * @data_setup_in_ns: The data setup time, in nanoseconds. Usually the
  86. * maximum of tDS and tWP. A negative value
  87. * indicates this characteristic isn't known.
  88. * @data_hold_in_ns: The data hold time, in nanoseconds. Usually the
  89. * maximum of tDH, tWH and tREH. A negative value
  90. * indicates this characteristic isn't known.
  91. * @address_setup_in_ns: The address setup time, in nanoseconds. Usually
  92. * the maximum of tCLS, tCS and tALS. A negative
  93. * value indicates this characteristic isn't known.
  94. * @gpmi_sample_delay_in_ns: A GPMI-specific timing parameter. A negative value
  95. * indicates this characteristic isn't known.
  96. * @tREA_in_ns: tREA, in nanoseconds, from the data sheet. A
  97. * negative value indicates this characteristic isn't
  98. * known.
  99. * @tRLOH_in_ns: tRLOH, in nanoseconds, from the data sheet. A
  100. * negative value indicates this characteristic isn't
  101. * known.
  102. * @tRHOH_in_ns: tRHOH, in nanoseconds, from the data sheet. A
  103. * negative value indicates this characteristic isn't
  104. * known.
  105. */
  106. struct nand_timing {
  107. int8_t data_setup_in_ns;
  108. int8_t data_hold_in_ns;
  109. int8_t address_setup_in_ns;
  110. int8_t gpmi_sample_delay_in_ns;
  111. int8_t tREA_in_ns;
  112. int8_t tRLOH_in_ns;
  113. int8_t tRHOH_in_ns;
  114. };
  115. enum gpmi_type {
  116. IS_MX23,
  117. IS_MX28,
  118. IS_MX6Q,
  119. IS_MX6SX
  120. };
  121. struct gpmi_devdata {
  122. enum gpmi_type type;
  123. int bch_max_ecc_strength;
  124. int max_chain_delay; /* See the async EDO mode */
  125. };
  126. struct gpmi_nand_data {
  127. /* flags */
  128. #define GPMI_ASYNC_EDO_ENABLED (1 << 0)
  129. #define GPMI_TIMING_INIT_OK (1 << 1)
  130. int flags;
  131. const struct gpmi_devdata *devdata;
  132. /* System Interface */
  133. struct device *dev;
  134. struct platform_device *pdev;
  135. /* Resources */
  136. struct resources resources;
  137. /* Flash Hardware */
  138. struct nand_timing timing;
  139. int timing_mode;
  140. /* BCH */
  141. struct bch_geometry bch_geometry;
  142. struct completion bch_done;
  143. /* NAND Boot issue */
  144. bool swap_block_mark;
  145. struct boot_rom_geometry rom_geometry;
  146. /* MTD / NAND */
  147. struct nand_chip nand;
  148. struct mtd_info mtd;
  149. /* General-use Variables */
  150. int current_chip;
  151. unsigned int command_length;
  152. /* passed from upper layer */
  153. uint8_t *upper_buf;
  154. int upper_len;
  155. /* for DMA operations */
  156. bool direct_dma_map_ok;
  157. struct scatterlist cmd_sgl;
  158. char *cmd_buffer;
  159. struct scatterlist data_sgl;
  160. char *data_buffer_dma;
  161. void *page_buffer_virt;
  162. dma_addr_t page_buffer_phys;
  163. unsigned int page_buffer_size;
  164. void *payload_virt;
  165. dma_addr_t payload_phys;
  166. void *auxiliary_virt;
  167. dma_addr_t auxiliary_phys;
  168. void *raw_buffer;
  169. /* DMA channels */
  170. #define DMA_CHANS 8
  171. struct dma_chan *dma_chans[DMA_CHANS];
  172. enum dma_ops_type last_dma_type;
  173. enum dma_ops_type dma_type;
  174. struct completion dma_done;
  175. /* private */
  176. void *private;
  177. };
  178. /**
  179. * struct gpmi_nfc_hardware_timing - GPMI hardware timing parameters.
  180. * @data_setup_in_cycles: The data setup time, in cycles.
  181. * @data_hold_in_cycles: The data hold time, in cycles.
  182. * @address_setup_in_cycles: The address setup time, in cycles.
  183. * @device_busy_timeout: The timeout waiting for NAND Ready/Busy,
  184. * this value is the number of cycles multiplied
  185. * by 4096.
  186. * @use_half_periods: Indicates the clock is running slowly, so the
  187. * NFC DLL should use half-periods.
  188. * @sample_delay_factor: The sample delay factor.
  189. * @wrn_dly_sel: The delay on the GPMI write strobe.
  190. */
  191. struct gpmi_nfc_hardware_timing {
  192. /* for HW_GPMI_TIMING0 */
  193. uint8_t data_setup_in_cycles;
  194. uint8_t data_hold_in_cycles;
  195. uint8_t address_setup_in_cycles;
  196. /* for HW_GPMI_TIMING1 */
  197. uint16_t device_busy_timeout;
  198. #define GPMI_DEFAULT_BUSY_TIMEOUT 0x500 /* default busy timeout value.*/
  199. /* for HW_GPMI_CTRL1 */
  200. bool use_half_periods;
  201. uint8_t sample_delay_factor;
  202. uint8_t wrn_dly_sel;
  203. };
  204. /**
  205. * struct timing_threshod - Timing threshold
  206. * @max_data_setup_cycles: The maximum number of data setup cycles that
  207. * can be expressed in the hardware.
  208. * @internal_data_setup_in_ns: The time, in ns, that the NFC hardware requires
  209. * for data read internal setup. In the Reference
  210. * Manual, see the chapter "High-Speed NAND
  211. * Timing" for more details.
  212. * @max_sample_delay_factor: The maximum sample delay factor that can be
  213. * expressed in the hardware.
  214. * @max_dll_clock_period_in_ns: The maximum period of the GPMI clock that the
  215. * sample delay DLL hardware can possibly work
  216. * with (the DLL is unusable with longer periods).
  217. * If the full-cycle period is greater than HALF
  218. * this value, the DLL must be configured to use
  219. * half-periods.
  220. * @max_dll_delay_in_ns: The maximum amount of delay, in ns, that the
  221. * DLL can implement.
  222. * @clock_frequency_in_hz: The clock frequency, in Hz, during the current
  223. * I/O transaction. If no I/O transaction is in
  224. * progress, this is the clock frequency during
  225. * the most recent I/O transaction.
  226. */
  227. struct timing_threshod {
  228. const unsigned int max_chip_count;
  229. const unsigned int max_data_setup_cycles;
  230. const unsigned int internal_data_setup_in_ns;
  231. const unsigned int max_sample_delay_factor;
  232. const unsigned int max_dll_clock_period_in_ns;
  233. const unsigned int max_dll_delay_in_ns;
  234. unsigned long clock_frequency_in_hz;
  235. };
  236. /* Common Services */
  237. extern int common_nfc_set_geometry(struct gpmi_nand_data *);
  238. extern struct dma_chan *get_dma_chan(struct gpmi_nand_data *);
  239. extern void prepare_data_dma(struct gpmi_nand_data *,
  240. enum dma_data_direction dr);
  241. extern int start_dma_without_bch_irq(struct gpmi_nand_data *,
  242. struct dma_async_tx_descriptor *);
  243. extern int start_dma_with_bch_irq(struct gpmi_nand_data *,
  244. struct dma_async_tx_descriptor *);
  245. /* GPMI-NAND helper function library */
  246. extern int gpmi_init(struct gpmi_nand_data *);
  247. extern int gpmi_extra_init(struct gpmi_nand_data *);
  248. extern void gpmi_clear_bch(struct gpmi_nand_data *);
  249. extern void gpmi_dump_info(struct gpmi_nand_data *);
  250. extern int bch_set_geometry(struct gpmi_nand_data *);
  251. extern int gpmi_is_ready(struct gpmi_nand_data *, unsigned chip);
  252. extern int gpmi_send_command(struct gpmi_nand_data *);
  253. extern void gpmi_begin(struct gpmi_nand_data *);
  254. extern void gpmi_end(struct gpmi_nand_data *);
  255. extern int gpmi_read_data(struct gpmi_nand_data *);
  256. extern int gpmi_send_data(struct gpmi_nand_data *);
  257. extern int gpmi_send_page(struct gpmi_nand_data *,
  258. dma_addr_t payload, dma_addr_t auxiliary);
  259. extern int gpmi_read_page(struct gpmi_nand_data *,
  260. dma_addr_t payload, dma_addr_t auxiliary);
  261. void gpmi_copy_bits(u8 *dst, size_t dst_bit_off,
  262. const u8 *src, size_t src_bit_off,
  263. size_t nbits);
  264. /* BCH : Status Block Completion Codes */
  265. #define STATUS_GOOD 0x00
  266. #define STATUS_ERASED 0xff
  267. #define STATUS_UNCORRECTABLE 0xfe
  268. /* Use the devdata to distinguish different Archs. */
  269. #define GPMI_IS_MX23(x) ((x)->devdata->type == IS_MX23)
  270. #define GPMI_IS_MX28(x) ((x)->devdata->type == IS_MX28)
  271. #define GPMI_IS_MX6Q(x) ((x)->devdata->type == IS_MX6Q)
  272. #define GPMI_IS_MX6SX(x) ((x)->devdata->type == IS_MX6SX)
  273. #define GPMI_IS_MX6(x) (GPMI_IS_MX6Q(x) || GPMI_IS_MX6SX(x))
  274. #endif