122-mtd-nand-sunxi-add-partition-support.patch 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. From 5cb31780791d0f6b68e3712f1b35f1a28c47add0 Mon Sep 17 00:00:00 2001
  2. From: Boris Brezillon <boris.brezillon@free-electrons.com>
  3. Date: Tue, 21 Oct 2014 14:37:15 +0200
  4. Subject: [PATCH] mtd: nand: sunxi: Add NAND partition support
  5. Add NAND partition support to the sunxi_nand driver.
  6. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
  7. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  8. ---
  9. drivers/mtd/nand/Kconfig | 1 +
  10. drivers/mtd/nand/sunxi_nand.c | 73 +++++++++++++++++++++++++++++++++++++------
  11. 2 files changed, 65 insertions(+), 9 deletions(-)
  12. --- a/drivers/mtd/nand/Kconfig
  13. +++ b/drivers/mtd/nand/Kconfig
  14. @@ -525,6 +525,7 @@ config MTD_NAND_XWAY
  15. config MTD_NAND_SUNXI
  16. tristate "Support for NAND on Allwinner SoCs"
  17. depends on ARCH_SUNXI
  18. + select MTD_OF_NAND_PARTS
  19. help
  20. Enables support for NAND Flash chips on Allwinner SoCs.
  21. --- a/drivers/mtd/nand/sunxi_nand.c
  22. +++ b/drivers/mtd/nand/sunxi_nand.c
  23. @@ -206,6 +206,23 @@ struct sunxi_nand_hw_ecc {
  24. };
  25. /*
  26. + * sunxi NAND partition structure: stores NAND partitions information
  27. + *
  28. + * @part: base paritition structure
  29. + * @ecc: per-partition ECC info
  30. + */
  31. +struct sunxi_nand_part {
  32. + struct nand_part part;
  33. + struct nand_ecc_ctrl ecc;
  34. +};
  35. +
  36. +static inline struct sunxi_nand_part *
  37. +to_sunxi_nand_part(struct nand_part *part)
  38. +{
  39. + return container_of(part, struct sunxi_nand_part, part);
  40. +}
  41. +
  42. +/*
  43. * NAND chip structure: stores NAND chip device related information
  44. *
  45. * @node: used to store NAND chips into a list
  46. @@ -525,7 +542,7 @@ static int sunxi_nfc_hw_ecc_read_page(st
  47. int oob_required, int page)
  48. {
  49. struct sunxi_nfc *nfc = to_sunxi_nfc(chip->controller);
  50. - struct nand_ecc_ctrl *ecc = &chip->ecc;
  51. + struct nand_ecc_ctrl *ecc = chip->cur_ecc;
  52. struct nand_ecclayout *layout = ecc->layout;
  53. struct sunxi_nand_hw_ecc *data = ecc->priv;
  54. unsigned int max_bitflips = 0;
  55. @@ -611,7 +628,7 @@ static int sunxi_nfc_hw_ecc_write_page(s
  56. const uint8_t *buf, int oob_required)
  57. {
  58. struct sunxi_nfc *nfc = to_sunxi_nfc(chip->controller);
  59. - struct nand_ecc_ctrl *ecc = &chip->ecc;
  60. + struct nand_ecc_ctrl *ecc = chip->cur_ecc;
  61. struct nand_ecclayout *layout = ecc->layout;
  62. struct sunxi_nand_hw_ecc *data = ecc->priv;
  63. int offset;
  64. @@ -679,7 +696,7 @@ static int sunxi_nfc_hw_syndrome_ecc_rea
  65. int page)
  66. {
  67. struct sunxi_nfc *nfc = to_sunxi_nfc(chip->controller);
  68. - struct nand_ecc_ctrl *ecc = &chip->ecc;
  69. + struct nand_ecc_ctrl *ecc = chip->cur_ecc;
  70. struct sunxi_nand_hw_ecc *data = ecc->priv;
  71. unsigned int max_bitflips = 0;
  72. uint8_t *oob = chip->oob_poi;
  73. @@ -747,7 +764,7 @@ static int sunxi_nfc_hw_syndrome_ecc_wri
  74. int oob_required)
  75. {
  76. struct sunxi_nfc *nfc = to_sunxi_nfc(chip->controller);
  77. - struct nand_ecc_ctrl *ecc = &chip->ecc;
  78. + struct nand_ecc_ctrl *ecc = chip->cur_ecc;
  79. struct sunxi_nand_hw_ecc *data = ecc->priv;
  80. uint8_t *oob = chip->oob_poi;
  81. int offset = 0;
  82. @@ -1091,8 +1108,13 @@ static int sunxi_nand_ecc_init(struct mt
  83. ecc->strength = nand->ecc_strength_ds;
  84. }
  85. - if (!ecc->size || !ecc->strength)
  86. - return -EINVAL;
  87. + if (!ecc->size || !ecc->strength) {
  88. + if (ecc == &nand->ecc)
  89. + return -EINVAL;
  90. +
  91. + ecc->size = nand->ecc.size;
  92. + ecc->strength = nand->ecc.strength;
  93. + }
  94. ecc->mode = NAND_ECC_HW;
  95. @@ -1127,12 +1149,39 @@ static int sunxi_nand_ecc_init(struct mt
  96. return 0;
  97. }
  98. +static void sunxi_nand_part_release(struct nand_part *part)
  99. +{
  100. + kfree(to_sunxi_nand_part(part));
  101. +}
  102. +
  103. +struct nand_part *sunxi_ofnandpart_parse(void *priv, struct mtd_info *master,
  104. + struct device_node *pp)
  105. +{
  106. + struct sunxi_nand_part *part;
  107. + int ret;
  108. +
  109. + part = kzalloc(sizeof(*part), GFP_KERNEL);
  110. + part->part.release = sunxi_nand_part_release;
  111. +
  112. + ret = sunxi_nand_ecc_init(master, &part->ecc, pp);
  113. + if (ret)
  114. + goto err;
  115. +
  116. + part->part.ecc = &part->ecc;
  117. +
  118. + return &part->part;
  119. +
  120. +err:
  121. + kfree(part);
  122. + return ERR_PTR(ret);
  123. +}
  124. +
  125. static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc,
  126. struct device_node *np)
  127. {
  128. const struct nand_sdr_timings *timings;
  129. struct sunxi_nand_chip *chip;
  130. - struct mtd_part_parser_data ppdata;
  131. + struct ofnandpart_data ppdata;
  132. struct mtd_info *mtd;
  133. struct nand_chip *nand;
  134. int nsels;
  135. @@ -1261,8 +1310,14 @@ static int sunxi_nand_chip_init(struct d
  136. return ret;
  137. }
  138. - ppdata.of_node = np;
  139. - ret = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
  140. + ppdata.node = np;
  141. + ppdata.parse = sunxi_ofnandpart_parse;
  142. + ret = ofnandpart_parse(mtd, &ppdata);
  143. + if (!ret)
  144. + ret = mtd_device_register(mtd, NULL, 0);
  145. + else if (ret > 0)
  146. + ret = 0;
  147. +
  148. if (ret) {
  149. dev_err(dev, "failed to register mtd device: %d\n", ret);
  150. nand_release(mtd);