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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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,3 +1,3 @@
  35. # SPDX-License-Identifier: GPL-2.0
  36. -spinand-objs := core.o ato.o esmt.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o xtx.o
  37. +spinand-objs := core.o ato.o esmt.o etron.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o xtx.o
  38. obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
  39. --- a/drivers/mtd/nand/spi/core.c
  40. +++ b/drivers/mtd/nand/spi/core.c
  41. @@ -939,6 +939,7 @@ static const struct nand_ops spinand_ops
  42. static const struct spinand_manufacturer *spinand_manufacturers[] = {
  43. &ato_spinand_manufacturer,
  44. &esmt_c8_spinand_manufacturer,
  45. + &etron_spinand_manufacturer,
  46. &gigadevice_spinand_manufacturer,
  47. &macronix_spinand_manufacturer,
  48. &micron_spinand_manufacturer,
  49. --- /dev/null
  50. +++ b/drivers/mtd/nand/spi/etron.c
  51. @@ -0,0 +1,98 @@
  52. +// SPDX-License-Identifier: GPL-2.0
  53. +
  54. +#include <linux/device.h>
  55. +#include <linux/kernel.h>
  56. +#include <linux/mtd/spinand.h>
  57. +
  58. +#define SPINAND_MFR_ETRON 0xd5
  59. +
  60. +
  61. +static SPINAND_OP_VARIANTS(read_cache_variants,
  62. + SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 1, NULL, 0),
  63. + SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
  64. + SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
  65. + SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
  66. + SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
  67. + SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
  68. +
  69. +static SPINAND_OP_VARIANTS(write_cache_variants,
  70. + SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
  71. + SPINAND_PROG_LOAD(true, 0, NULL, 0));
  72. +
  73. +static SPINAND_OP_VARIANTS(update_cache_variants,
  74. + SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
  75. + SPINAND_PROG_LOAD(false, 0, NULL, 0));
  76. +
  77. +static int etron_ooblayout_ecc(struct mtd_info *mtd, int section,
  78. + struct mtd_oob_region *oobregion)
  79. +{
  80. + if (section)
  81. + return -ERANGE;
  82. +
  83. + oobregion->offset = 72;
  84. + oobregion->length = 56;
  85. +
  86. + return 0;
  87. +}
  88. +
  89. +static int etron_ooblayout_free(struct mtd_info *mtd, int section,
  90. + struct mtd_oob_region *oobregion)
  91. +{
  92. + if (section)
  93. + return -ERANGE;
  94. +
  95. + oobregion->offset = 1;
  96. + oobregion->length = 71;
  97. +
  98. + return 0;
  99. +}
  100. +
  101. +static int etron_ecc_get_status(struct spinand_device *spinand, u8 status)
  102. +{
  103. + switch (status & STATUS_ECC_MASK) {
  104. + case STATUS_ECC_NO_BITFLIPS:
  105. + return 0;
  106. +
  107. + case STATUS_ECC_HAS_BITFLIPS:
  108. + /* Between 1-7 bitflips were corrected */
  109. + return 7;
  110. +
  111. + case STATUS_ECC_MASK:
  112. + /* Maximum bitflips were corrected */
  113. + return 8;
  114. +
  115. + case STATUS_ECC_UNCOR_ERROR:
  116. + return -EBADMSG;
  117. + }
  118. +
  119. + return -EINVAL;
  120. +}
  121. +
  122. +static const struct mtd_ooblayout_ops etron_ooblayout = {
  123. + .ecc = etron_ooblayout_ecc,
  124. + .free = etron_ooblayout_free,
  125. +};
  126. +
  127. +static const struct spinand_info etron_spinand_table[] = {
  128. + SPINAND_INFO("EM73D044VCx",
  129. + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x1f),
  130. + // bpc, pagesize, oobsize, pagesperblock, bperlun, maxbadplun, ppl, lpt, #t
  131. + NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
  132. + NAND_ECCREQ(8, 512),
  133. + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  134. + &write_cache_variants,
  135. + &update_cache_variants),
  136. + SPINAND_HAS_QE_BIT,
  137. + SPINAND_ECCINFO(&etron_ooblayout, etron_ecc_get_status)),
  138. +};
  139. +
  140. +static const struct spinand_manufacturer_ops etron_spinand_manuf_ops = {
  141. +};
  142. +
  143. +const struct spinand_manufacturer etron_spinand_manufacturer = {
  144. + .id = SPINAND_MFR_ETRON,
  145. + .name = "Etron",
  146. + .chips = etron_spinand_table,
  147. + .nchips = ARRAY_SIZE(etron_spinand_table),
  148. + .ops = &etron_spinand_manuf_ops,
  149. +};
  150. --- a/include/linux/mtd/spinand.h
  151. +++ b/include/linux/mtd/spinand.h
  152. @@ -262,6 +262,7 @@ struct spinand_manufacturer {
  153. /* SPI NAND manufacturers */
  154. extern const struct spinand_manufacturer ato_spinand_manufacturer;
  155. extern const struct spinand_manufacturer esmt_c8_spinand_manufacturer;
  156. +extern const struct spinand_manufacturer etron_spinand_manufacturer;
  157. extern const struct spinand_manufacturer gigadevice_spinand_manufacturer;
  158. extern const struct spinand_manufacturer macronix_spinand_manufacturer;
  159. extern const struct spinand_manufacturer micron_spinand_manufacturer;