487-mtd-spinand-Add-support-for-Etron-EM73D044VCx.patch 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. From f32085fc0b87049491b07e198d924d738a1a2834 Mon Sep 17 00:00:00 2001
  2. From: Daniel Danzberger <[email protected]>
  3. Date: Wed, 3 Aug 2022 17:31:03 +0200
  4. Subject: [PATCH] mtd: spinand: Add support for Etron EM73D044VCx
  5. Airoha is a new ARM platform based on Cortex-A53 which has recently been
  6. merged into linux-next.
  7. Due to BootROM limitations on this platform, the Cortex-A53 can't run in
  8. Aarch64 mode and code must be compiled for 32-Bit ARM.
  9. This support is based mostly on those linux-next commits backported
  10. for kernel 5.15.
  11. Patches:
  12. 1 - platform support = linux-next
  13. 2 - clock driver = linux-next
  14. 3 - gpio driver = linux-next
  15. 4 - linux,usable-memory-range dts support = linux-next
  16. 5 - mtd spinand driver
  17. 6 - spi driver
  18. 7 - pci driver (kconfig only, uses mediatek PCI) = linux-next
  19. Still missing:
  20. - Ethernet driver
  21. - Sysupgrade support
  22. A.t.m there exists one subtarget EN7523 with only one evaluation
  23. board.
  24. The initramfs can be run with the following commands from u-boot:
  25. -
  26. u-boot> setenv bootfile \
  27. openwrt-airoha-airoha_en7523-evb-initramfs-kernel.bin
  28. u-boot> tftpboot
  29. u-boot> bootm 0x81800000
  30. -
  31. Submitted-by: Daniel Danzberger <[email protected]>
  32. --- a/drivers/mtd/nand/spi/Makefile
  33. +++ b/drivers/mtd/nand/spi/Makefile
  34. @@ -1,4 +1,4 @@
  35. # SPDX-License-Identifier: GPL-2.0
  36. -spinand-objs := core.o alliancememory.o ato.o esmt.o gigadevice.o macronix.o
  37. -spinand-objs += micron.o paragon.o toshiba.o winbond.o xtx.o
  38. +spinand-objs := core.o alliancememory.o ato.o esmt.o etron.o gigadevice.o
  39. +spinand-objs += macronix.o micron.o paragon.o toshiba.o winbond.o xtx.o
  40. obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
  41. --- a/drivers/mtd/nand/spi/core.c
  42. +++ b/drivers/mtd/nand/spi/core.c
  43. @@ -940,6 +940,7 @@ static const struct spinand_manufacturer
  44. &alliancememory_spinand_manufacturer,
  45. &ato_spinand_manufacturer,
  46. &esmt_c8_spinand_manufacturer,
  47. + &etron_spinand_manufacturer,
  48. &gigadevice_spinand_manufacturer,
  49. &macronix_spinand_manufacturer,
  50. &micron_spinand_manufacturer,
  51. --- /dev/null
  52. +++ b/drivers/mtd/nand/spi/etron.c
  53. @@ -0,0 +1,98 @@
  54. +// SPDX-License-Identifier: GPL-2.0
  55. +
  56. +#include <linux/device.h>
  57. +#include <linux/kernel.h>
  58. +#include <linux/mtd/spinand.h>
  59. +
  60. +#define SPINAND_MFR_ETRON 0xd5
  61. +
  62. +
  63. +static SPINAND_OP_VARIANTS(read_cache_variants,
  64. + SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 1, NULL, 0),
  65. + SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
  66. + SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
  67. + SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
  68. + SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
  69. + SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
  70. +
  71. +static SPINAND_OP_VARIANTS(write_cache_variants,
  72. + SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
  73. + SPINAND_PROG_LOAD(true, 0, NULL, 0));
  74. +
  75. +static SPINAND_OP_VARIANTS(update_cache_variants,
  76. + SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
  77. + SPINAND_PROG_LOAD(false, 0, NULL, 0));
  78. +
  79. +static int etron_ooblayout_ecc(struct mtd_info *mtd, int section,
  80. + struct mtd_oob_region *oobregion)
  81. +{
  82. + if (section)
  83. + return -ERANGE;
  84. +
  85. + oobregion->offset = 72;
  86. + oobregion->length = 56;
  87. +
  88. + return 0;
  89. +}
  90. +
  91. +static int etron_ooblayout_free(struct mtd_info *mtd, int section,
  92. + struct mtd_oob_region *oobregion)
  93. +{
  94. + if (section)
  95. + return -ERANGE;
  96. +
  97. + oobregion->offset = 1;
  98. + oobregion->length = 71;
  99. +
  100. + return 0;
  101. +}
  102. +
  103. +static int etron_ecc_get_status(struct spinand_device *spinand, u8 status)
  104. +{
  105. + switch (status & STATUS_ECC_MASK) {
  106. + case STATUS_ECC_NO_BITFLIPS:
  107. + return 0;
  108. +
  109. + case STATUS_ECC_HAS_BITFLIPS:
  110. + /* Between 1-7 bitflips were corrected */
  111. + return 7;
  112. +
  113. + case STATUS_ECC_MASK:
  114. + /* Maximum bitflips were corrected */
  115. + return 8;
  116. +
  117. + case STATUS_ECC_UNCOR_ERROR:
  118. + return -EBADMSG;
  119. + }
  120. +
  121. + return -EINVAL;
  122. +}
  123. +
  124. +static const struct mtd_ooblayout_ops etron_ooblayout = {
  125. + .ecc = etron_ooblayout_ecc,
  126. + .free = etron_ooblayout_free,
  127. +};
  128. +
  129. +static const struct spinand_info etron_spinand_table[] = {
  130. + SPINAND_INFO("EM73D044VCx",
  131. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x1f),
  132. + // bpc, pagesize, oobsize, pagesperblock, bperlun, maxbadplun, ppl, lpt, #t
  133. + NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
  134. + NAND_ECCREQ(8, 512),
  135. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  136. + &write_cache_variants,
  137. + &update_cache_variants),
  138. + SPINAND_HAS_QE_BIT,
  139. + SPINAND_ECCINFO(&etron_ooblayout, etron_ecc_get_status)),
  140. +};
  141. +
  142. +static const struct spinand_manufacturer_ops etron_spinand_manuf_ops = {
  143. +};
  144. +
  145. +const struct spinand_manufacturer etron_spinand_manufacturer = {
  146. + .id = SPINAND_MFR_ETRON,
  147. + .name = "Etron",
  148. + .chips = etron_spinand_table,
  149. + .nchips = ARRAY_SIZE(etron_spinand_table),
  150. + .ops = &etron_spinand_manuf_ops,
  151. +};
  152. --- a/include/linux/mtd/spinand.h
  153. +++ b/include/linux/mtd/spinand.h
  154. @@ -263,6 +263,7 @@ struct spinand_manufacturer {
  155. extern const struct spinand_manufacturer alliancememory_spinand_manufacturer;
  156. extern const struct spinand_manufacturer ato_spinand_manufacturer;
  157. extern const struct spinand_manufacturer esmt_c8_spinand_manufacturer;
  158. +extern const struct spinand_manufacturer etron_spinand_manufacturer;
  159. extern const struct spinand_manufacturer gigadevice_spinand_manufacturer;
  160. extern const struct spinand_manufacturer macronix_spinand_manufacturer;
  161. extern const struct spinand_manufacturer micron_spinand_manufacturer;