gpmi-nand.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Freescale GPMI NAND Flash Driver
  4. *
  5. * Copyright (C) 2010-2011 Freescale Semiconductor, Inc.
  6. * Copyright (C) 2008 Embedded Alley Solutions, Inc.
  7. */
  8. #ifndef __DRIVERS_MTD_NAND_GPMI_NAND_H
  9. #define __DRIVERS_MTD_NAND_GPMI_NAND_H
  10. #include <linux/mtd/rawnand.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/dma-mapping.h>
  13. #include <linux/dmaengine.h>
  14. #define GPMI_CLK_MAX 5 /* MX6Q needs five clocks */
  15. struct resources {
  16. void __iomem *gpmi_regs;
  17. void __iomem *bch_regs;
  18. unsigned int dma_low_channel;
  19. unsigned int dma_high_channel;
  20. struct clk *clock[GPMI_CLK_MAX];
  21. };
  22. /**
  23. * struct bch_geometry - BCH geometry description.
  24. * @gf_len: The length of Galois Field. (e.g., 13 or 14)
  25. * @ecc_strength: A number that describes the strength of the ECC
  26. * algorithm.
  27. * @page_size: The size, in bytes, of a physical page, including
  28. * both data and OOB.
  29. * @metadata_size: The size, in bytes, of the metadata.
  30. * @ecc_chunk_size: The size, in bytes, of a single ECC chunk. Note
  31. * the first chunk in the page includes both data and
  32. * metadata, so it's a bit larger than this value.
  33. * @ecc_chunk_count: The number of ECC chunks in the page,
  34. * @payload_size: The size, in bytes, of the payload buffer.
  35. * @auxiliary_size: The size, in bytes, of the auxiliary buffer.
  36. * @auxiliary_status_offset: The offset into the auxiliary buffer at which
  37. * the ECC status appears.
  38. * @block_mark_byte_offset: The byte offset in the ECC-based page view at
  39. * which the underlying physical block mark appears.
  40. * @block_mark_bit_offset: The bit offset into the ECC-based page view at
  41. * which the underlying physical block mark appears.
  42. */
  43. struct bch_geometry {
  44. unsigned int gf_len;
  45. unsigned int ecc_strength;
  46. unsigned int page_size;
  47. unsigned int metadata_size;
  48. unsigned int ecc_chunk_size;
  49. unsigned int ecc_chunk_count;
  50. unsigned int payload_size;
  51. unsigned int auxiliary_size;
  52. unsigned int auxiliary_status_offset;
  53. unsigned int block_mark_byte_offset;
  54. unsigned int block_mark_bit_offset;
  55. };
  56. /**
  57. * struct boot_rom_geometry - Boot ROM geometry description.
  58. * @stride_size_in_pages: The size of a boot block stride, in pages.
  59. * @search_area_stride_exponent: The logarithm to base 2 of the size of a
  60. * search area in boot block strides.
  61. */
  62. struct boot_rom_geometry {
  63. unsigned int stride_size_in_pages;
  64. unsigned int search_area_stride_exponent;
  65. };
  66. enum gpmi_type {
  67. IS_MX23,
  68. IS_MX28,
  69. IS_MX6Q,
  70. IS_MX6SX,
  71. IS_MX7D,
  72. };
  73. struct gpmi_devdata {
  74. enum gpmi_type type;
  75. int bch_max_ecc_strength;
  76. int max_chain_delay; /* See the async EDO mode */
  77. const char * const *clks;
  78. const int clks_count;
  79. };
  80. /**
  81. * struct gpmi_nfc_hardware_timing - GPMI hardware timing parameters.
  82. * @must_apply_timings: Whether controller timings have already been
  83. * applied or not (useful only while there is
  84. * support for only one chip select)
  85. * @clk_rate: The clock rate that must be used to derive the
  86. * following parameters
  87. * @timing0: HW_GPMI_TIMING0 register
  88. * @timing1: HW_GPMI_TIMING1 register
  89. * @ctrl1n: HW_GPMI_CTRL1n register
  90. */
  91. struct gpmi_nfc_hardware_timing {
  92. bool must_apply_timings;
  93. unsigned long int clk_rate;
  94. u32 timing0;
  95. u32 timing1;
  96. u32 ctrl1n;
  97. };
  98. struct gpmi_nand_data {
  99. /* Devdata */
  100. const struct gpmi_devdata *devdata;
  101. /* System Interface */
  102. struct device *dev;
  103. struct platform_device *pdev;
  104. /* Resources */
  105. struct resources resources;
  106. /* Flash Hardware */
  107. struct gpmi_nfc_hardware_timing hw;
  108. /* BCH */
  109. struct bch_geometry bch_geometry;
  110. struct completion bch_done;
  111. /* NAND Boot issue */
  112. bool swap_block_mark;
  113. struct boot_rom_geometry rom_geometry;
  114. /* MTD / NAND */
  115. struct nand_chip nand;
  116. /* General-use Variables */
  117. int current_chip;
  118. unsigned int command_length;
  119. struct scatterlist cmd_sgl;
  120. char *cmd_buffer;
  121. struct scatterlist data_sgl;
  122. char *data_buffer_dma;
  123. void *page_buffer_virt;
  124. dma_addr_t page_buffer_phys;
  125. unsigned int page_buffer_size;
  126. void *payload_virt;
  127. dma_addr_t payload_phys;
  128. void *auxiliary_virt;
  129. dma_addr_t auxiliary_phys;
  130. void *raw_buffer;
  131. /* DMA channels */
  132. #define DMA_CHANS 8
  133. struct dma_chan *dma_chans[DMA_CHANS];
  134. struct completion dma_done;
  135. /* private */
  136. void *private;
  137. };
  138. /* Common Services */
  139. int common_nfc_set_geometry(struct gpmi_nand_data *);
  140. struct dma_chan *get_dma_chan(struct gpmi_nand_data *);
  141. bool prepare_data_dma(struct gpmi_nand_data *, const void *buf, int len,
  142. enum dma_data_direction dr);
  143. int start_dma_without_bch_irq(struct gpmi_nand_data *,
  144. struct dma_async_tx_descriptor *);
  145. int start_dma_with_bch_irq(struct gpmi_nand_data *,
  146. struct dma_async_tx_descriptor *);
  147. /* GPMI-NAND helper function library */
  148. int gpmi_init(struct gpmi_nand_data *);
  149. void gpmi_clear_bch(struct gpmi_nand_data *);
  150. void gpmi_dump_info(struct gpmi_nand_data *);
  151. int bch_set_geometry(struct gpmi_nand_data *);
  152. int gpmi_is_ready(struct gpmi_nand_data *, unsigned chip);
  153. int gpmi_send_command(struct gpmi_nand_data *);
  154. int gpmi_enable_clk(struct gpmi_nand_data *this);
  155. int gpmi_disable_clk(struct gpmi_nand_data *this);
  156. int gpmi_setup_data_interface(struct nand_chip *chip, int chipnr,
  157. const struct nand_data_interface *conf);
  158. void gpmi_nfc_apply_timings(struct gpmi_nand_data *this);
  159. int gpmi_read_data(struct gpmi_nand_data *, void *buf, int len);
  160. int gpmi_send_data(struct gpmi_nand_data *, const void *buf, int len);
  161. int gpmi_send_page(struct gpmi_nand_data *,
  162. dma_addr_t payload, dma_addr_t auxiliary);
  163. int gpmi_read_page(struct gpmi_nand_data *,
  164. dma_addr_t payload, dma_addr_t auxiliary);
  165. void gpmi_copy_bits(u8 *dst, size_t dst_bit_off,
  166. const u8 *src, size_t src_bit_off,
  167. size_t nbits);
  168. /* BCH : Status Block Completion Codes */
  169. #define STATUS_GOOD 0x00
  170. #define STATUS_ERASED 0xff
  171. #define STATUS_UNCORRECTABLE 0xfe
  172. /* Use the devdata to distinguish different Archs. */
  173. #define GPMI_IS_MX23(x) ((x)->devdata->type == IS_MX23)
  174. #define GPMI_IS_MX28(x) ((x)->devdata->type == IS_MX28)
  175. #define GPMI_IS_MX6Q(x) ((x)->devdata->type == IS_MX6Q)
  176. #define GPMI_IS_MX6SX(x) ((x)->devdata->type == IS_MX6SX)
  177. #define GPMI_IS_MX7D(x) ((x)->devdata->type == IS_MX7D)
  178. #define GPMI_IS_MX6(x) (GPMI_IS_MX6Q(x) || GPMI_IS_MX6SX(x) || \
  179. GPMI_IS_MX7D(x))
  180. #endif