foresee.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // SPDX-License-Identifier: (GPL-2.0+ OR MIT)
  2. /*
  3. * Copyright (c) 2023, SberDevices. All Rights Reserved.
  4. *
  5. * Author: Martin Kurbanov <mmkurbanov@salutedevices.com>
  6. */
  7. #include <linux/device.h>
  8. #include <linux/kernel.h>
  9. #include <linux/mtd/spinand.h>
  10. #define SPINAND_MFR_FORESEE 0xCD
  11. #define F35SQB002G_STATUS_ECC_MASK (7 << 4)
  12. #define F35SQB002G_STATUS_ECC_NO_BITFLIPS (0 << 4)
  13. #define F35SQB002G_STATUS_ECC_1_3_BITFLIPS (1 << 4)
  14. #define F35SQB002G_STATUS_ECC_UNCOR_ERROR (7 << 4)
  15. static SPINAND_OP_VARIANTS(read_cache_variants,
  16. SPINAND_PAGE_READ_FROM_CACHE_1S_1S_4S_OP(0, 1, NULL, 0, 0),
  17. SPINAND_PAGE_READ_FROM_CACHE_1S_1S_2S_OP(0, 1, NULL, 0, 0),
  18. SPINAND_PAGE_READ_FROM_CACHE_FAST_1S_1S_1S_OP(0, 1, NULL, 0, 0),
  19. SPINAND_PAGE_READ_FROM_CACHE_1S_1S_1S_OP(0, 1, NULL, 0, 0));
  20. static SPINAND_OP_VARIANTS(write_cache_variants,
  21. SPINAND_PROG_LOAD_1S_1S_4S_OP(true, 0, NULL, 0),
  22. SPINAND_PROG_LOAD_1S_1S_1S_OP(true, 0, NULL, 0));
  23. static SPINAND_OP_VARIANTS(update_cache_variants,
  24. SPINAND_PROG_LOAD_1S_1S_4S_OP(false, 0, NULL, 0),
  25. SPINAND_PROG_LOAD_1S_1S_1S_OP(false, 0, NULL, 0));
  26. static int f35sqa002g_ooblayout_ecc(struct mtd_info *mtd, int section,
  27. struct mtd_oob_region *region)
  28. {
  29. return -ERANGE;
  30. }
  31. static int f35sqa002g_ooblayout_free(struct mtd_info *mtd, int section,
  32. struct mtd_oob_region *region)
  33. {
  34. if (section)
  35. return -ERANGE;
  36. /* Reserve 2 bytes for the BBM. */
  37. region->offset = 2;
  38. region->length = 62;
  39. return 0;
  40. }
  41. static const struct mtd_ooblayout_ops f35sqa002g_ooblayout = {
  42. .ecc = f35sqa002g_ooblayout_ecc,
  43. .free = f35sqa002g_ooblayout_free,
  44. };
  45. static int f35sqa002g_ecc_get_status(struct spinand_device *spinand, u8 status)
  46. {
  47. struct nand_device *nand = spinand_to_nand(spinand);
  48. switch (status & STATUS_ECC_MASK) {
  49. case STATUS_ECC_NO_BITFLIPS:
  50. return 0;
  51. case STATUS_ECC_HAS_BITFLIPS:
  52. return nanddev_get_ecc_conf(nand)->strength;
  53. default:
  54. break;
  55. }
  56. /* More than 1-bit error was detected in one or more sectors and
  57. * cannot be corrected.
  58. */
  59. return -EBADMSG;
  60. }
  61. static int f35sqb002g_ecc_get_status(struct spinand_device *spinand, u8 status)
  62. {
  63. switch (status & F35SQB002G_STATUS_ECC_MASK) {
  64. case F35SQB002G_STATUS_ECC_NO_BITFLIPS:
  65. return 0;
  66. case F35SQB002G_STATUS_ECC_1_3_BITFLIPS:
  67. return 3;
  68. case F35SQB002G_STATUS_ECC_UNCOR_ERROR:
  69. return -EBADMSG;
  70. default: /* (2 << 4) through (6 << 4) are 4-8 corrected errors */
  71. return ((status & F35SQB002G_STATUS_ECC_MASK) >> 4) + 2;
  72. }
  73. return -EINVAL;
  74. }
  75. static const struct spinand_info foresee_spinand_table[] = {
  76. SPINAND_INFO("F35SQA002G",
  77. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x72, 0x72),
  78. NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 1, 1, 1),
  79. NAND_ECCREQ(1, 512),
  80. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  81. &write_cache_variants,
  82. &update_cache_variants),
  83. SPINAND_HAS_QE_BIT,
  84. SPINAND_ECCINFO(&f35sqa002g_ooblayout,
  85. f35sqa002g_ecc_get_status)),
  86. SPINAND_INFO("F35SQA001G",
  87. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x71, 0x71),
  88. NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
  89. NAND_ECCREQ(1, 512),
  90. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  91. &write_cache_variants,
  92. &update_cache_variants),
  93. SPINAND_HAS_QE_BIT,
  94. SPINAND_ECCINFO(&f35sqa002g_ooblayout,
  95. f35sqa002g_ecc_get_status)),
  96. SPINAND_INFO("F35SQB002G",
  97. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x52, 0x52),
  98. NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
  99. NAND_ECCREQ(8, 512),
  100. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  101. &write_cache_variants,
  102. &update_cache_variants),
  103. SPINAND_HAS_QE_BIT,
  104. SPINAND_ECCINFO(&f35sqa002g_ooblayout,
  105. f35sqb002g_ecc_get_status)),
  106. };
  107. static const struct spinand_manufacturer_ops foresee_spinand_manuf_ops = {
  108. };
  109. const struct spinand_manufacturer foresee_spinand_manufacturer = {
  110. .id = SPINAND_MFR_FORESEE,
  111. .name = "FORESEE",
  112. .chips = foresee_spinand_table,
  113. .nchips = ARRAY_SIZE(foresee_spinand_table),
  114. .ops = &foresee_spinand_manuf_ops,
  115. };