140-mtd-brcmnand-set-initial-ECC-params-based-on-info-fr.patch 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. From eff78bc2c385f592294278582f38ad5fa4ed2b34 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
  3. Date: Wed, 27 Jan 2016 08:47:03 +0100
  4. Subject: [PATCH] mtd: brcmnand: set initial ECC params based on info from HW
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. So far we were depending on nand_dt_init getting ECC info from DT and
  9. setting it in ECC struct. It is possible to simply read this info from
  10. hardware registers which makes adding support for new hardware way
  11. easier (no more guessing & trying all combinations).
  12. Please note it still gives a precedence to DT which was overwrite
  13. whatever was initially set by the driver.
  14. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
  15. ---
  16. It took me hours to figure out how to setup NAND on my D-Link DIR-885L.
  17. This should be very helpful for ppl adding new devices support.
  18. ---
  19. drivers/mtd/nand/brcmnand/brcmnand.c | 14 ++++++++++++++
  20. 1 file changed, 14 insertions(+)
  21. --- a/drivers/mtd/nand/brcmnand/brcmnand.c
  22. +++ b/drivers/mtd/nand/brcmnand/brcmnand.c
  23. @@ -645,6 +645,17 @@ static inline u32 brcmnand_ecc_level_mas
  24. return mask << NAND_ACC_CONTROL_ECC_SHIFT;
  25. }
  26. +static int brcmnand_get_ecc_strength(struct brcmnand_host *host)
  27. +{
  28. + struct brcmnand_controller *ctrl = host->ctrl;
  29. + u32 mask = brcmnand_ecc_level_mask(ctrl);
  30. + u16 acc_control_offs = brcmnand_cs_offset(ctrl, host->cs,
  31. + BRCMNAND_CS_ACC_CONTROL);
  32. +
  33. + return (nand_readreg(ctrl, acc_control_offs) & mask) >>
  34. + NAND_ACC_CONTROL_ECC_SHIFT;
  35. +}
  36. +
  37. static void brcmnand_set_ecc_enabled(struct brcmnand_host *host, int en)
  38. {
  39. struct brcmnand_controller *ctrl = host->ctrl;
  40. @@ -1990,6 +2001,9 @@ static int brcmnand_init_cs(struct brcmn
  41. nand_writereg(ctrl, cfg_offs,
  42. nand_readreg(ctrl, cfg_offs) & ~CFG_BUS_WIDTH);
  43. + chip->ecc.strength = brcmnand_get_ecc_strength(host);
  44. + chip->ecc.size = brcmnand_get_sector_size_1k(host) ? 1024 : 512;
  45. +
  46. if (nand_scan_ident(mtd, 1, NULL))
  47. return -ENXIO;