winbond.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2017 exceet electronics GmbH
  4. *
  5. * Authors:
  6. * Frieder Schrempf <[email protected]>
  7. * Boris Brezillon <[email protected]>
  8. */
  9. #include <linux/device.h>
  10. #include <linux/kernel.h>
  11. #include <linux/mtd/spinand.h>
  12. #define SPINAND_MFR_WINBOND 0xEF
  13. #define WINBOND_CFG_BUF_READ BIT(3)
  14. static SPINAND_OP_VARIANTS(read_cache_variants,
  15. SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
  16. SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
  17. SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
  18. SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
  19. SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
  20. SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
  21. static SPINAND_OP_VARIANTS(write_cache_variants,
  22. SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
  23. SPINAND_PROG_LOAD(true, 0, NULL, 0));
  24. static SPINAND_OP_VARIANTS(update_cache_variants,
  25. SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
  26. SPINAND_PROG_LOAD(false, 0, NULL, 0));
  27. static int w25m02gv_ooblayout_ecc(struct mtd_info *mtd, int section,
  28. struct mtd_oob_region *region)
  29. {
  30. if (section > 3)
  31. return -ERANGE;
  32. region->offset = (16 * section) + 8;
  33. region->length = 8;
  34. return 0;
  35. }
  36. static int w25m02gv_ooblayout_free(struct mtd_info *mtd, int section,
  37. struct mtd_oob_region *region)
  38. {
  39. if (section > 3)
  40. return -ERANGE;
  41. region->offset = (16 * section) + 2;
  42. region->length = 6;
  43. return 0;
  44. }
  45. static const struct mtd_ooblayout_ops w25m02gv_ooblayout = {
  46. .ecc = w25m02gv_ooblayout_ecc,
  47. .free = w25m02gv_ooblayout_free,
  48. };
  49. static int w25m02gv_select_target(struct spinand_device *spinand,
  50. unsigned int target)
  51. {
  52. struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(0xc2, 1),
  53. SPI_MEM_OP_NO_ADDR,
  54. SPI_MEM_OP_NO_DUMMY,
  55. SPI_MEM_OP_DATA_OUT(1,
  56. spinand->scratchbuf,
  57. 1));
  58. *spinand->scratchbuf = target;
  59. return spi_mem_exec_op(spinand->spimem, &op);
  60. }
  61. static const struct spinand_info winbond_spinand_table[] = {
  62. SPINAND_INFO("W25M02GV",
  63. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xab),
  64. NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 2),
  65. NAND_ECCREQ(1, 512),
  66. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  67. &write_cache_variants,
  68. &update_cache_variants),
  69. 0,
  70. SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL),
  71. SPINAND_SELECT_TARGET(w25m02gv_select_target)),
  72. SPINAND_INFO("W25N01GV",
  73. SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa),
  74. NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
  75. NAND_ECCREQ(1, 512),
  76. SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
  77. &write_cache_variants,
  78. &update_cache_variants),
  79. 0,
  80. SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL)),
  81. };
  82. static int winbond_spinand_init(struct spinand_device *spinand)
  83. {
  84. struct nand_device *nand = spinand_to_nand(spinand);
  85. unsigned int i;
  86. /*
  87. * Make sure all dies are in buffer read mode and not continuous read
  88. * mode.
  89. */
  90. for (i = 0; i < nand->memorg.ntargets; i++) {
  91. spinand_select_target(spinand, i);
  92. spinand_upd_cfg(spinand, WINBOND_CFG_BUF_READ,
  93. WINBOND_CFG_BUF_READ);
  94. }
  95. return 0;
  96. }
  97. static const struct spinand_manufacturer_ops winbond_spinand_manuf_ops = {
  98. .init = winbond_spinand_init,
  99. };
  100. const struct spinand_manufacturer winbond_spinand_manufacturer = {
  101. .id = SPINAND_MFR_WINBOND,
  102. .name = "Winbond",
  103. .chips = winbond_spinand_table,
  104. .nchips = ARRAY_SIZE(winbond_spinand_table),
  105. .ops = &winbond_spinand_manuf_ops,
  106. };