fmsh.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2020-2021 Rockchip Electronics Co., Ltd.
  4. *
  5. * Author: Dingqiang Lin <jon.lin@rock-chips.com>
  6. */
  7. #include <linux/device.h>
  8. #include <linux/kernel.h>
  9. #include <linux/mtd/spinand.h>
  10. #define FM25S01BI3_STATUS_ECC_MASK (7 << 4)
  11. #define FM25S01BI3_STATUS_ECC_NO_BITFLIPS (0 << 4)
  12. #define FM25S01BI3_STATUS_ECC_1_3_BITFLIPS (1 << 4)
  13. #define FM25S01BI3_STATUS_ECC_UNCOR_ERROR (2 << 4)
  14. #define FM25S01BI3_STATUS_ECC_4_6_BITFLIPS (3 << 4)
  15. #define FM25S01BI3_STATUS_ECC_7_8_BITFLIPS (5 << 4)
  16. #define SPINAND_MFR_FMSH 0xA1
  17. static SPINAND_OP_VARIANTS(read_cache_variants,
  18. SPINAND_PAGE_READ_FROM_CACHE_1S_4S_4S_OP(0, 2, NULL, 0, 0),
  19. SPINAND_PAGE_READ_FROM_CACHE_1S_1S_4S_OP(0, 1, NULL, 0, 0),
  20. SPINAND_PAGE_READ_FROM_CACHE_1S_2S_2S_OP(0, 1, NULL, 0, 0),
  21. SPINAND_PAGE_READ_FROM_CACHE_1S_1S_2S_OP(0, 1, NULL, 0, 0),
  22. SPINAND_PAGE_READ_FROM_CACHE_FAST_1S_1S_1S_OP(0, 1, NULL, 0, 0),
  23. SPINAND_PAGE_READ_FROM_CACHE_1S_1S_1S_OP(0, 1, NULL, 0, 0));
  24. static SPINAND_OP_VARIANTS(write_cache_variants,
  25. SPINAND_PROG_LOAD_1S_1S_4S_OP(true, 0, NULL, 0),
  26. SPINAND_PROG_LOAD_1S_1S_1S_OP(true, 0, NULL, 0));
  27. static SPINAND_OP_VARIANTS(update_cache_variants,
  28. SPINAND_PROG_LOAD_1S_1S_4S_OP(false, 0, NULL, 0),
  29. SPINAND_PROG_LOAD_1S_1S_1S_OP(false, 0, NULL, 0));
  30. static int fm25s01a_ooblayout_ecc(struct mtd_info *mtd, int section,
  31. struct mtd_oob_region *region)
  32. {
  33. return -ERANGE;
  34. }
  35. static int fm25s01a_ooblayout_free(struct mtd_info *mtd, int section,
  36. struct mtd_oob_region *region)
  37. {
  38. if (section)
  39. return -ERANGE;
  40. region->offset = 2;
  41. region->length = 62;
  42. return 0;
  43. }
  44. static int fm25s01bi3_ecc_get_status(struct spinand_device *spinand,
  45. u8 status)
  46. {
  47. switch (status & FM25S01BI3_STATUS_ECC_MASK) {
  48. case FM25S01BI3_STATUS_ECC_NO_BITFLIPS:
  49. return 0;
  50. case FM25S01BI3_STATUS_ECC_UNCOR_ERROR:
  51. return -EBADMSG;
  52. case FM25S01BI3_STATUS_ECC_1_3_BITFLIPS:
  53. return 3;
  54. case FM25S01BI3_STATUS_ECC_4_6_BITFLIPS:
  55. return 6;
  56. case FM25S01BI3_STATUS_ECC_7_8_BITFLIPS:
  57. return 8;
  58. default:
  59. break;
  60. }
  61. return -EINVAL;
  62. }
  63. static int fm25s01bi3_ooblayout_ecc(struct mtd_info *mtd, int section,
  64. struct mtd_oob_region *region)
  65. {
  66. if (section)
  67. return -ERANGE;
  68. region->offset = 64;
  69. region->length = 64;
  70. return 0;
  71. }
  72. static int fm25s01bi3_ooblayout_free(struct mtd_info *mtd, int section,
  73. struct mtd_oob_region *region)
  74. {
  75. if (section > 3)
  76. return -ERANGE;
  77. region->offset = (16 * section) + 4;
  78. region->length = 12;
  79. return 0;
  80. }
  81. static const struct mtd_ooblayout_ops fm25s01a_ooblayout = {
  82. .ecc = fm25s01a_ooblayout_ecc,
  83. .free = fm25s01a_ooblayout_free,
  84. };
  85. static const struct mtd_ooblayout_ops fm25s01bi3_ooblayout = {
  86. .ecc = fm25s01bi3_ooblayout_ecc,
  87. .free = fm25s01bi3_ooblayout_free,
  88. };
  89. static const struct spinand_info fmsh_spinand_table[] = {
  90. SPINAND_INFO("FM25S01A",
  91. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xE4),
  92. NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
  93. NAND_ECCREQ(1, 512),
  94. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  95. &write_cache_variants,
  96. &update_cache_variants),
  97. 0,
  98. SPINAND_ECCINFO(&fm25s01a_ooblayout, NULL)),
  99. SPINAND_INFO("FM25S01BI3",
  100. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xd4),
  101. NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
  102. NAND_ECCREQ(8, 512),
  103. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  104. &write_cache_variants,
  105. &update_cache_variants),
  106. SPINAND_HAS_QE_BIT,
  107. SPINAND_ECCINFO(&fm25s01bi3_ooblayout,
  108. fm25s01bi3_ecc_get_status)),
  109. };
  110. static const struct spinand_manufacturer_ops fmsh_spinand_manuf_ops = {
  111. };
  112. const struct spinand_manufacturer fmsh_spinand_manufacturer = {
  113. .id = SPINAND_MFR_FMSH,
  114. .name = "Fudan Micro",
  115. .chips = fmsh_spinand_table,
  116. .nchips = ARRAY_SIZE(fmsh_spinand_table),
  117. .ops = &fmsh_spinand_manuf_ops,
  118. };