119-mtd-nand-ecc-for-samsung.patch 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. From 3fecbdac2fe503fb6896ec08dd2474958d198d62 Mon Sep 17 00:00:00 2001
  2. From: Hans de Goede <hdegoede@redhat.com>
  3. Date: Sun, 24 May 2015 12:01:16 +0200
  4. Subject: [PATCH] mtd: nand: nand_decode_ext_id(): Fill in ecc strength and
  5. size for Samsung
  6. On some nand controllers with hw-ecc the controller code wants to know the
  7. ecc strength and size and having these as 0, 0 is not accepted.
  8. Specifying these in devicetree is possible but undesirable as the nand
  9. may be different in different production runs of the same board, so it
  10. is better to get this info from the nand id where possible.
  11. This commit adds code to read the ecc strength and size from the nand for
  12. Samsung extended-id nands. This code is based on the info for the 5th
  13. id byte in the datasheets for the following Samsung nands: K9GAG08U0E,
  14. K9GAG08U0F, K9GAG08X0D, K9GBG08U0A, K9GBG08U0B. These all use these bits
  15. in the exact same way.
  16. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  17. ---
  18. drivers/mtd/nand/nand_base.c | 35 +++++++++++++++++++++++++++++++++++
  19. 1 file changed, 35 insertions(+)
  20. --- a/drivers/mtd/nand/nand_base.c
  21. +++ b/drivers/mtd/nand/nand_base.c
  22. @@ -4063,6 +4063,41 @@ static void nand_decode_ext_id(struct mt
  23. mtd->erasesize = (128 * 1024) <<
  24. (((extid >> 1) & 0x04) | (extid & 0x03));
  25. *busw = 0;
  26. + /* Calc ecc strength and size from 5th id byte*/
  27. + switch ((id_data[4] >> 4) & 0x07) {
  28. + case 0:
  29. + chip->ecc_strength_ds = 1;
  30. + chip->ecc_step_ds = 512;
  31. + break;
  32. + case 1:
  33. + chip->ecc_strength_ds = 2;
  34. + chip->ecc_step_ds = 512;
  35. + break;
  36. + case 2:
  37. + chip->ecc_strength_ds = 4;
  38. + chip->ecc_step_ds = 512;
  39. + break;
  40. + case 3:
  41. + chip->ecc_strength_ds = 8;
  42. + chip->ecc_step_ds = 512;
  43. + break;
  44. + case 4:
  45. + chip->ecc_strength_ds = 16;
  46. + chip->ecc_step_ds = 512;
  47. + break;
  48. + case 5:
  49. + chip->ecc_strength_ds = 24;
  50. + chip->ecc_step_ds = 1024;
  51. + break;
  52. + case 6:
  53. + chip->ecc_strength_ds = 40;
  54. + chip->ecc_step_ds = 1024;
  55. + break;
  56. + case 7:
  57. + chip->ecc_strength_ds = 60;
  58. + chip->ecc_step_ds = 1024;
  59. + break;
  60. + }
  61. } else if (id_len == 6 && id_data[0] == NAND_MFR_HYNIX &&
  62. !nand_is_slc(chip)) {
  63. unsigned int tmp;