0018-MTD-nand-lots-of-xrx200-fixes.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. From 997a8965db8417266bea3fbdcfa3e5655a1b52fa Mon Sep 17 00:00:00 2001
  2. From: John Crispin <blogic@openwrt.org>
  3. Date: Tue, 9 Sep 2014 23:12:15 +0200
  4. Subject: [PATCH 18/36] MTD: nand: lots of xrx200 fixes
  5. Signed-off-by: John Crispin <blogic@openwrt.org>
  6. ---
  7. drivers/mtd/nand/xway_nand.c | 63 ++++++++++++++++++++++++++++++++++++++++++
  8. 1 file changed, 63 insertions(+)
  9. --- a/drivers/mtd/nand/xway_nand.c
  10. +++ b/drivers/mtd/nand/xway_nand.c
  11. @@ -54,8 +54,27 @@
  12. #define NAND_CON_CSMUX (1 << 1)
  13. #define NAND_CON_NANDM 1
  14. +#define DANUBE_PCI_REG32( addr ) (*(volatile u32 *)(addr))
  15. +#define PCI_CR_PR_OFFSET (KSEG1+0x1E105400)
  16. +#define PCI_CR_PC_ARB (PCI_CR_PR_OFFSET + 0x0080)
  17. +
  18. static u32 xway_latchcmd;
  19. +/*
  20. + * req_mask provides a mechanism to prevent interference between
  21. + * nand and pci (probably only relevant for the BT Home Hub 2B).
  22. + * Setting it causes the corresponding pci req pins to be masked
  23. + * during nand access, and also moves ebu locking from the read/write
  24. + * functions to the chip select function to ensure that the whole
  25. + * operation runs with interrupts disabled.
  26. + * In addition it switches on some extra waiting in xway_cmd_ctrl().
  27. + * This seems to be necessary if the ebu_cs1 pin has open-drain disabled,
  28. + * which in turn seems to be necessary for the nor chip to be recognised
  29. + * reliably, on a board (Home Hub 2B again) which has both nor and nand.
  30. + */
  31. +
  32. +static __be32 req_mask = 0;
  33. +
  34. static void xway_reset_chip(struct nand_chip *chip)
  35. {
  36. unsigned long nandaddr = (unsigned long) chip->IO_ADDR_W;
  37. @@ -86,12 +105,24 @@ static void xway_select_chip(struct mtd_
  38. case -1:
  39. ltq_ebu_w32_mask(NAND_CON_CE, 0, EBU_NAND_CON);
  40. ltq_ebu_w32_mask(NAND_CON_NANDM, 0, EBU_NAND_CON);
  41. +
  42. + if (req_mask) {
  43. + /* Unmask all external PCI request */
  44. + DANUBE_PCI_REG32(PCI_CR_PC_ARB) &= ~(req_mask << 16);
  45. + }
  46. spin_unlock_irqrestore(&ebu_lock, csflags);
  47. +
  48. break;
  49. case 0:
  50. spin_lock_irqsave(&ebu_lock, csflags);
  51. + if (req_mask) {
  52. + /* Mask all external PCI request */
  53. + DANUBE_PCI_REG32(PCI_CR_PC_ARB) |= (req_mask << 16);
  54. + }
  55. +
  56. ltq_ebu_w32_mask(0, NAND_CON_NANDM, EBU_NAND_CON);
  57. ltq_ebu_w32_mask(0, NAND_CON_CE, EBU_NAND_CON);
  58. +
  59. break;
  60. default:
  61. BUG();
  62. @@ -103,6 +134,12 @@ static void xway_cmd_ctrl(struct mtd_inf
  63. struct nand_chip *this = mtd->priv;
  64. unsigned long nandaddr = (unsigned long) this->IO_ADDR_W;
  65. + if (req_mask) {
  66. + if (cmd != NAND_CMD_STATUS)
  67. + ltq_ebu_w32(EBU_NAND_WAIT, 0); /* Clear nand ready */
  68. + }
  69. +
  70. +
  71. if (ctrl & NAND_CTRL_CHANGE) {
  72. if (ctrl & NAND_CLE)
  73. xway_latchcmd = NAND_WRITE_CMD;
  74. @@ -115,6 +152,24 @@ static void xway_cmd_ctrl(struct mtd_inf
  75. while ((ltq_ebu_r32(EBU_NAND_WAIT) & NAND_WAIT_WR_C) == 0)
  76. ;
  77. }
  78. +
  79. + if (req_mask) {
  80. + /*
  81. + * program and erase have their own busy handlers
  82. + * status and sequential in needs no delay
  83. + */
  84. + switch (cmd) {
  85. + case NAND_CMD_ERASE1:
  86. + case NAND_CMD_SEQIN:
  87. + case NAND_CMD_STATUS:
  88. + case NAND_CMD_READID:
  89. + return;
  90. + }
  91. +
  92. + /* wait until command is processed */
  93. + while ((ltq_ebu_r32(EBU_NAND_WAIT) & NAND_WAIT_RD) == 0)
  94. + ;
  95. + }
  96. }
  97. static int xway_dev_ready(struct mtd_info *mtd)
  98. @@ -157,6 +212,8 @@ static int xway_nand_probe(struct platfo
  99. {
  100. struct nand_chip *this = platform_get_drvdata(pdev);
  101. unsigned long nandaddr = (unsigned long) this->IO_ADDR_W;
  102. + const __be32 *req_mask_ptr = of_get_property(pdev->dev.of_node,
  103. + "req-mask", NULL);
  104. const __be32 *cs = of_get_property(pdev->dev.of_node,
  105. "lantiq,cs", NULL);
  106. u32 cs_flag = 0;
  107. @@ -165,6 +222,12 @@ static int xway_nand_probe(struct platfo
  108. if (cs && (*cs == 1))
  109. cs_flag = NAND_CON_IN_CS1 | NAND_CON_OUT_CS1;
  110. + /*
  111. + * Load the PCI req lines to mask from the device tree. If the
  112. + * property is not present, setting req_mask to 0 disables masking.
  113. + */
  114. + req_mask = (req_mask_ptr ? *req_mask_ptr : 0);
  115. +
  116. /* setup the EBU to run in NAND mode on our base addr */
  117. ltq_ebu_w32(CPHYSADDR(nandaddr)
  118. | ADDSEL1_MASK(3) | ADDSEL1_REGEN, EBU_ADDSEL1);