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

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