340-mtd-spinand-Add-support-for-the-Fidelix-FM35X1GA.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. From 5f49a5c9b16330e0df8f639310e4715dcad71947 Mon Sep 17 00:00:00 2001
  2. From: Davide Fioravanti <[email protected]>
  3. Date: Fri, 8 Jan 2021 15:35:24 +0100
  4. Subject: [PATCH] mtd: spinand: Add support for the Fidelix FM35X1GA
  5. Datasheet: http://www.hobos.com.cn/upload/datasheet/DS35X1GAXXX_100_rev00.pdf
  6. Signed-off-by: Davide Fioravanti <[email protected]>
  7. ---
  8. drivers/mtd/nand/spi/Makefile | 2 +-
  9. drivers/mtd/nand/spi/core.c | 1 +
  10. drivers/mtd/nand/spi/fidelix.c | 76 ++++++++++++++++++++++++++++++++++
  11. include/linux/mtd/spinand.h | 1 +
  12. 4 files changed, 79 insertions(+), 1 deletion(-)
  13. create mode 100644 drivers/mtd/nand/spi/fidelix.c
  14. --- a/drivers/mtd/nand/spi/Makefile
  15. +++ b/drivers/mtd/nand/spi/Makefile
  16. @@ -1,4 +1,4 @@
  17. # SPDX-License-Identifier: GPL-2.0
  18. -spinand-objs := core.o alliancememory.o ato.o esmt.o etron.o gigadevice.o
  19. +spinand-objs := core.o alliancememory.o ato.o esmt.o etron.o fidelix.o gigadevice.o
  20. spinand-objs += macronix.o micron.o paragon.o toshiba.o winbond.o xtx.o
  21. obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
  22. --- a/drivers/mtd/nand/spi/core.c
  23. +++ b/drivers/mtd/nand/spi/core.c
  24. @@ -941,6 +941,7 @@ static const struct spinand_manufacturer
  25. &alliancememory_spinand_manufacturer,
  26. &ato_spinand_manufacturer,
  27. &esmt_c8_spinand_manufacturer,
  28. + &fidelix_spinand_manufacturer,
  29. &etron_spinand_manufacturer,
  30. &gigadevice_spinand_manufacturer,
  31. &macronix_spinand_manufacturer,
  32. --- /dev/null
  33. +++ b/drivers/mtd/nand/spi/fidelix.c
  34. @@ -0,0 +1,76 @@
  35. +// SPDX-License-Identifier: GPL-2.0
  36. +/*
  37. + * Copyright (c) 2020 Davide Fioravanti <[email protected]>
  38. + */
  39. +
  40. +#include <linux/device.h>
  41. +#include <linux/kernel.h>
  42. +#include <linux/mtd/spinand.h>
  43. +
  44. +#define SPINAND_MFR_FIDELIX 0xE5
  45. +#define FIDELIX_ECCSR_MASK 0x0F
  46. +
  47. +static SPINAND_OP_VARIANTS(read_cache_variants,
  48. + SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
  49. + SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
  50. + SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
  51. +
  52. +static SPINAND_OP_VARIANTS(write_cache_variants,
  53. + SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
  54. + SPINAND_PROG_LOAD(true, 0, NULL, 0));
  55. +
  56. +static SPINAND_OP_VARIANTS(update_cache_variants,
  57. + SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
  58. + SPINAND_PROG_LOAD(false, 0, NULL, 0));
  59. +
  60. +static int fm35x1ga_ooblayout_ecc(struct mtd_info *mtd, int section,
  61. + struct mtd_oob_region *region)
  62. +{
  63. + if (section > 3)
  64. + return -ERANGE;
  65. +
  66. + region->offset = (16 * section) + 8;
  67. + region->length = 8;
  68. +
  69. + return 0;
  70. +}
  71. +
  72. +static int fm35x1ga_ooblayout_free(struct mtd_info *mtd, int section,
  73. + struct mtd_oob_region *region)
  74. +{
  75. + if (section > 3)
  76. + return -ERANGE;
  77. +
  78. + region->offset = (16 * section) + 2;
  79. + region->length = 6;
  80. +
  81. + return 0;
  82. +}
  83. +
  84. +static const struct mtd_ooblayout_ops fm35x1ga_ooblayout = {
  85. + .ecc = fm35x1ga_ooblayout_ecc,
  86. + .free = fm35x1ga_ooblayout_free,
  87. +};
  88. +
  89. +static const struct spinand_info fidelix_spinand_table[] = {
  90. + SPINAND_INFO("FM35X1GA",
  91. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x71),
  92. + NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
  93. + NAND_ECCREQ(4, 512),
  94. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  95. + &write_cache_variants,
  96. + &update_cache_variants),
  97. + SPINAND_HAS_QE_BIT,
  98. + SPINAND_ECCINFO(&fm35x1ga_ooblayout, NULL)),
  99. +};
  100. +
  101. +static const struct spinand_manufacturer_ops fidelix_spinand_manuf_ops = {
  102. +};
  103. +
  104. +const struct spinand_manufacturer fidelix_spinand_manufacturer = {
  105. + .id = SPINAND_MFR_FIDELIX,
  106. + .name = "Fidelix",
  107. + .chips = fidelix_spinand_table,
  108. + .nchips = ARRAY_SIZE(fidelix_spinand_table),
  109. + .ops = &fidelix_spinand_manuf_ops,
  110. +};
  111. --- a/include/linux/mtd/spinand.h
  112. +++ b/include/linux/mtd/spinand.h
  113. @@ -264,6 +264,7 @@ extern const struct spinand_manufacturer
  114. extern const struct spinand_manufacturer ato_spinand_manufacturer;
  115. extern const struct spinand_manufacturer esmt_c8_spinand_manufacturer;
  116. extern const struct spinand_manufacturer etron_spinand_manufacturer;
  117. +extern const struct spinand_manufacturer fidelix_spinand_manufacturer;
  118. extern const struct spinand_manufacturer gigadevice_spinand_manufacturer;
  119. extern const struct spinand_manufacturer macronix_spinand_manufacturer;
  120. extern const struct spinand_manufacturer micron_spinand_manufacturer;