mxs_nand.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * NXP GPMI NAND flash driver
  4. *
  5. * Copyright (C) 2018 Toradex
  6. * Authors:
  7. * Stefan Agner <stefan.agner@toradex.com>
  8. */
  9. #include <linux/mtd/mtd.h>
  10. #include <linux/mtd/rawnand.h>
  11. #include <asm/cache.h>
  12. #include <nand.h>
  13. #include <asm/mach-imx/dma.h>
  14. /**
  15. * @gf_len: The length of Galois Field. (e.g., 13 or 14)
  16. * @ecc_strength: A number that describes the strength of the ECC
  17. * algorithm.
  18. * @ecc_chunk0_size: The size, in bytes, of a first ECC chunk.
  19. * @ecc_chunkn_size: The size, in bytes, of a single ECC chunk after
  20. * the first chunk in the page.
  21. * @ecc_chunk_count: The number of ECC chunks in the page,
  22. * @block_mark_byte_offset: The byte offset in the ECC-based page view at
  23. * which the underlying physical block mark appears.
  24. * @block_mark_bit_offset: The bit offset into the ECC-based page view at
  25. * which the underlying physical block mark appears.
  26. * @ecc_for_meta: The flag to indicate if there is a dedicate ecc
  27. * for meta.
  28. */
  29. struct bch_geometry {
  30. unsigned int gf_len;
  31. unsigned int ecc_strength;
  32. unsigned int ecc_chunk0_size;
  33. unsigned int ecc_chunkn_size;
  34. unsigned int ecc_chunk_count;
  35. unsigned int block_mark_byte_offset;
  36. unsigned int block_mark_bit_offset;
  37. unsigned int ecc_for_meta; /* ECC for meta data */
  38. };
  39. struct mxs_nand_info {
  40. struct nand_chip chip;
  41. struct udevice *dev;
  42. unsigned int max_ecc_strength_supported;
  43. bool use_minimum_ecc;
  44. /* legacy bch geometry flag */
  45. bool legacy_bch_geometry;
  46. int cur_chip;
  47. uint32_t cmd_queue_len;
  48. uint32_t data_buf_size;
  49. struct bch_geometry bch_geometry;
  50. uint8_t *cmd_buf;
  51. uint8_t *data_buf;
  52. uint8_t *oob_buf;
  53. uint8_t marking_block_bad;
  54. uint8_t raw_oob_mode;
  55. struct mxs_gpmi_regs *gpmi_regs;
  56. struct mxs_bch_regs *bch_regs;
  57. /* Functions with altered behaviour */
  58. int (*hooked_read_oob)(struct mtd_info *mtd,
  59. loff_t from, struct mtd_oob_ops *ops);
  60. int (*hooked_write_oob)(struct mtd_info *mtd,
  61. loff_t to, struct mtd_oob_ops *ops);
  62. int (*hooked_block_markbad)(struct mtd_info *mtd,
  63. loff_t ofs);
  64. /* DMA descriptors */
  65. struct mxs_dma_desc **desc;
  66. uint32_t desc_index;
  67. /* Hardware BCH interface and randomizer */
  68. u32 en_randomizer;
  69. u32 writesize;
  70. u32 oobsize;
  71. u32 bch_flash0layout0;
  72. u32 bch_flash0layout1;
  73. };
  74. struct mxs_nand_layout {
  75. u32 nblocks;
  76. u32 meta_size;
  77. u32 data0_size;
  78. u32 ecc0;
  79. u32 datan_size;
  80. u32 eccn;
  81. u32 gf_len;
  82. };
  83. int mxs_nand_init_ctrl(struct mxs_nand_info *nand_info);
  84. int mxs_nand_init_spl(struct nand_chip *nand);
  85. int mxs_nand_setup_ecc(struct mtd_info *mtd);
  86. void mxs_nand_mode_fcb_62bit(struct mtd_info *mtd);
  87. void mxs_nand_mode_fcb_40bit(struct mtd_info *mtd);
  88. void mxs_nand_mode_normal(struct mtd_info *mtd);
  89. u32 mxs_nand_mark_byte_offset(struct mtd_info *mtd);
  90. u32 mxs_nand_mark_bit_offset(struct mtd_info *mtd);
  91. void mxs_nand_get_layout(struct mtd_info *mtd, struct mxs_nand_layout *l);