022-mtd-pxa3xx_nand-Fix-initial-controller-configuration.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. From: =?UTF-8?q?Ezequiel=20Garc=C3=ADa?= <ezequiel@vanguardiasur.com.ar>
  2. Date: Wed, 4 Nov 2015 13:13:42 -0300
  3. Subject: [PATCH] mtd: pxa3xx_nand: Fix initial controller configuration
  4. The Data Flash Control Register (NDCR) contains two types
  5. of parameters: those that are needed for device identification,
  6. and those that can only be set after device identification.
  7. Therefore, the driver can't set them all at once and instead
  8. needs to configure the first group before nand_scan_ident()
  9. and the second group later.
  10. Let's split pxa3xx_nand_config in two halves, and set the
  11. parameters that depend on the device geometry once this is known.
  12. Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
  13. Signed-off-by: Brian Norris <computersforpeace@gmail.com>
  14. ---
  15. --- a/drivers/mtd/nand/pxa3xx_nand.c
  16. +++ b/drivers/mtd/nand/pxa3xx_nand.c
  17. @@ -1420,34 +1420,43 @@ static int pxa3xx_nand_waitfunc(struct m
  18. return NAND_STATUS_READY;
  19. }
  20. -static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info)
  21. +static int pxa3xx_nand_config_ident(struct pxa3xx_nand_info *info)
  22. {
  23. struct platform_device *pdev = info->pdev;
  24. struct pxa3xx_nand_platform_data *pdata = dev_get_platdata(&pdev->dev);
  25. - struct pxa3xx_nand_host *host = info->host[info->cs];
  26. - struct mtd_info *mtd = host->mtd;
  27. - struct nand_chip *chip = mtd->priv;
  28. - /* configure default flash values */
  29. + /* Configure default flash values */
  30. + info->chunk_size = PAGE_CHUNK_SIZE;
  31. info->reg_ndcr = 0x0; /* enable all interrupts */
  32. info->reg_ndcr |= (pdata->enable_arbiter) ? NDCR_ND_ARB_EN : 0;
  33. info->reg_ndcr |= NDCR_RD_ID_CNT(READ_ID_BYTES);
  34. - info->reg_ndcr |= NDCR_SPARE_EN; /* enable spare by default */
  35. + info->reg_ndcr |= NDCR_SPARE_EN;
  36. +
  37. + return 0;
  38. +}
  39. +
  40. +static void pxa3xx_nand_config_tail(struct pxa3xx_nand_info *info)
  41. +{
  42. + struct pxa3xx_nand_host *host = info->host[info->cs];
  43. + struct mtd_info *mtd = host->mtd;
  44. + struct nand_chip *chip = mtd->priv;
  45. +
  46. info->reg_ndcr |= (host->col_addr_cycles == 2) ? NDCR_RA_START : 0;
  47. info->reg_ndcr |= (chip->page_shift == 6) ? NDCR_PG_PER_BLK : 0;
  48. info->reg_ndcr |= (mtd->writesize == 2048) ? NDCR_PAGE_SZ : 0;
  49. -
  50. - return 0;
  51. }
  52. static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info)
  53. {
  54. + struct platform_device *pdev = info->pdev;
  55. + struct pxa3xx_nand_platform_data *pdata = dev_get_platdata(&pdev->dev);
  56. uint32_t ndcr = nand_readl(info, NDCR);
  57. /* Set an initial chunk size */
  58. info->chunk_size = ndcr & NDCR_PAGE_SZ ? 2048 : 512;
  59. info->reg_ndcr = ndcr &
  60. ~(NDCR_INT_MASK | NDCR_ND_ARB_EN | NFCV1_NDCR_ARB_CNTL);
  61. + info->reg_ndcr |= (pdata->enable_arbiter) ? NDCR_ND_ARB_EN : 0;
  62. info->ndtr0cs0 = nand_readl(info, NDTR0CS0);
  63. info->ndtr1cs0 = nand_readl(info, NDTR1CS0);
  64. return 0;
  65. @@ -1636,10 +1645,7 @@ static int pxa3xx_nand_scan(struct mtd_i
  66. if (pdata->keep_config && !pxa3xx_nand_detect_config(info))
  67. goto KEEP_CONFIG;
  68. - /* Set a default chunk size */
  69. - info->chunk_size = PAGE_CHUNK_SIZE;
  70. -
  71. - ret = pxa3xx_nand_config_flash(info);
  72. + ret = pxa3xx_nand_config_ident(info);
  73. if (ret)
  74. return ret;
  75. @@ -1652,7 +1658,6 @@ static int pxa3xx_nand_scan(struct mtd_i
  76. }
  77. KEEP_CONFIG:
  78. - info->reg_ndcr |= (pdata->enable_arbiter) ? NDCR_ND_ARB_EN : 0;
  79. if (info->reg_ndcr & NDCR_DWIDTH_M)
  80. chip->options |= NAND_BUSWIDTH_16;
  81. @@ -1737,6 +1742,10 @@ KEEP_CONFIG:
  82. host->row_addr_cycles = 3;
  83. else
  84. host->row_addr_cycles = 2;
  85. +
  86. + if (!pdata->keep_config)
  87. + pxa3xx_nand_config_tail(info);
  88. +
  89. return nand_scan_tail(mtd);
  90. }