paragon.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2019 Jeff Kletsky
  4. *
  5. * Author: Jeff Kletsky <[email protected]>
  6. */
  7. #include <linux/device.h>
  8. #include <linux/kernel.h>
  9. #include <linux/mtd/spinand.h>
  10. #define SPINAND_MFR_PARAGON 0xa1
  11. #define PN26G0XA_STATUS_ECC_BITMASK (3 << 4)
  12. #define PN26G0XA_STATUS_ECC_NONE_DETECTED (0 << 4)
  13. #define PN26G0XA_STATUS_ECC_1_7_CORRECTED (1 << 4)
  14. #define PN26G0XA_STATUS_ECC_ERRORED (2 << 4)
  15. #define PN26G0XA_STATUS_ECC_8_CORRECTED (3 << 4)
  16. static SPINAND_OP_VARIANTS(read_cache_variants,
  17. SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
  18. SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
  19. SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
  20. SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
  21. SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
  22. SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
  23. static SPINAND_OP_VARIANTS(write_cache_variants,
  24. SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
  25. SPINAND_PROG_LOAD(true, 0, NULL, 0));
  26. static SPINAND_OP_VARIANTS(update_cache_variants,
  27. SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
  28. SPINAND_PROG_LOAD(false, 0, NULL, 0));
  29. static int pn26g0xa_ooblayout_ecc(struct mtd_info *mtd, int section,
  30. struct mtd_oob_region *region)
  31. {
  32. if (section > 3)
  33. return -ERANGE;
  34. region->offset = 6 + (15 * section); /* 4 BBM + 2 user bytes */
  35. region->length = 13;
  36. return 0;
  37. }
  38. static int pn26g0xa_ooblayout_free(struct mtd_info *mtd, int section,
  39. struct mtd_oob_region *region)
  40. {
  41. if (section > 4)
  42. return -ERANGE;
  43. if (section == 4) {
  44. region->offset = 64;
  45. region->length = 64;
  46. } else {
  47. region->offset = 4 + (15 * section);
  48. region->length = 2;
  49. }
  50. return 0;
  51. }
  52. static int pn26g0xa_ecc_get_status(struct spinand_device *spinand,
  53. u8 status)
  54. {
  55. switch (status & PN26G0XA_STATUS_ECC_BITMASK) {
  56. case PN26G0XA_STATUS_ECC_NONE_DETECTED:
  57. return 0;
  58. case PN26G0XA_STATUS_ECC_1_7_CORRECTED:
  59. return 7; /* Return upper limit by convention */
  60. case PN26G0XA_STATUS_ECC_8_CORRECTED:
  61. return 8;
  62. case PN26G0XA_STATUS_ECC_ERRORED:
  63. return -EBADMSG;
  64. default:
  65. break;
  66. }
  67. return -EINVAL;
  68. }
  69. static const struct mtd_ooblayout_ops pn26g0xa_ooblayout = {
  70. .ecc = pn26g0xa_ooblayout_ecc,
  71. .free = pn26g0xa_ooblayout_free,
  72. };
  73. static const struct spinand_info paragon_spinand_table[] = {
  74. SPINAND_INFO("PN26G01A",
  75. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xe1),
  76. NAND_MEMORG(1, 2048, 128, 64, 1024, 21, 1, 1, 1),
  77. NAND_ECCREQ(8, 512),
  78. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  79. &write_cache_variants,
  80. &update_cache_variants),
  81. 0,
  82. SPINAND_ECCINFO(&pn26g0xa_ooblayout,
  83. pn26g0xa_ecc_get_status)),
  84. SPINAND_INFO("PN26G02A",
  85. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xe2),
  86. NAND_MEMORG(1, 2048, 128, 64, 2048, 41, 1, 1, 1),
  87. NAND_ECCREQ(8, 512),
  88. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  89. &write_cache_variants,
  90. &update_cache_variants),
  91. 0,
  92. SPINAND_ECCINFO(&pn26g0xa_ooblayout,
  93. pn26g0xa_ecc_get_status)),
  94. };
  95. static const struct spinand_manufacturer_ops paragon_spinand_manuf_ops = {
  96. };
  97. const struct spinand_manufacturer paragon_spinand_manufacturer = {
  98. .id = SPINAND_MFR_PARAGON,
  99. .name = "Paragon",
  100. .chips = paragon_spinand_table,
  101. .nchips = ARRAY_SIZE(paragon_spinand_table),
  102. .ops = &paragon_spinand_manuf_ops,
  103. };