nand_toshiba.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (C) 2017 Free Electrons
  3. * Copyright (C) 2017 NextThing Co
  4. *
  5. * Author: Boris Brezillon <boris.brezillon@free-electrons.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/mtd/rawnand.h>
  18. static void toshiba_nand_decode_id(struct nand_chip *chip)
  19. {
  20. struct mtd_info *mtd = nand_to_mtd(chip);
  21. nand_decode_ext_id(chip);
  22. /*
  23. * Toshiba 24nm raw SLC (i.e., not BENAND) have 32B OOB per
  24. * 512B page. For Toshiba SLC, we decode the 5th/6th byte as
  25. * follows:
  26. * - ID byte 6, bits[2:0]: 100b -> 43nm, 101b -> 32nm,
  27. * 110b -> 24nm
  28. * - ID byte 5, bit[7]: 1 -> BENAND, 0 -> raw SLC
  29. */
  30. if (chip->id.len >= 6 && nand_is_slc(chip) &&
  31. (chip->id.data[5] & 0x7) == 0x6 /* 24nm */ &&
  32. !(chip->id.data[4] & 0x80) /* !BENAND */)
  33. mtd->oobsize = 32 * mtd->writesize >> 9;
  34. /*
  35. * Extract ECC requirements from 6th id byte.
  36. * For Toshiba SLC, ecc requrements are as follows:
  37. * - 43nm: 1 bit ECC for each 512Byte is required.
  38. * - 32nm: 4 bit ECC for each 512Byte is required.
  39. * - 24nm: 8 bit ECC for each 512Byte is required.
  40. */
  41. if (chip->id.len >= 6 && nand_is_slc(chip)) {
  42. chip->ecc_step_ds = 512;
  43. switch (chip->id.data[5] & 0x7) {
  44. case 0x4:
  45. chip->ecc_strength_ds = 1;
  46. break;
  47. case 0x5:
  48. chip->ecc_strength_ds = 4;
  49. break;
  50. case 0x6:
  51. chip->ecc_strength_ds = 8;
  52. break;
  53. default:
  54. WARN(1, "Could not get ECC info");
  55. chip->ecc_step_ds = 0;
  56. break;
  57. }
  58. }
  59. }
  60. static int toshiba_nand_init(struct nand_chip *chip)
  61. {
  62. if (nand_is_slc(chip))
  63. chip->bbt_options |= NAND_BBT_SCAN2NDPAGE;
  64. return 0;
  65. }
  66. const struct nand_manufacturer_ops toshiba_nand_manuf_ops = {
  67. .detect = toshiba_nand_decode_id,
  68. .init = toshiba_nand_init,
  69. };