nand_hynix.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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/nand.h>
  18. static void hynix_nand_decode_id(struct nand_chip *chip)
  19. {
  20. struct mtd_info *mtd = nand_to_mtd(chip);
  21. /* Hynix MLC (6 byte ID): Hynix H27UBG8T2B (p.22) */
  22. if (chip->id.len == 6 && !nand_is_slc(chip)) {
  23. u8 tmp, extid = chip->id.data[3];
  24. /* Extract pagesize */
  25. mtd->writesize = 2048 << (extid & 0x03);
  26. extid >>= 2;
  27. /* Extract oobsize */
  28. switch (((extid >> 2) & 0x4) | (extid & 0x3)) {
  29. case 0:
  30. mtd->oobsize = 128;
  31. break;
  32. case 1:
  33. mtd->oobsize = 224;
  34. break;
  35. case 2:
  36. mtd->oobsize = 448;
  37. break;
  38. case 3:
  39. mtd->oobsize = 64;
  40. break;
  41. case 4:
  42. mtd->oobsize = 32;
  43. break;
  44. case 5:
  45. mtd->oobsize = 16;
  46. break;
  47. default:
  48. mtd->oobsize = 640;
  49. break;
  50. }
  51. /* Extract blocksize */
  52. extid >>= 2;
  53. tmp = ((extid >> 1) & 0x04) | (extid & 0x03);
  54. if (tmp < 0x03)
  55. mtd->erasesize = (128 * 1024) << tmp;
  56. else if (tmp == 0x03)
  57. mtd->erasesize = 768 * 1024;
  58. else
  59. mtd->erasesize = (64 * 1024) << tmp;
  60. } else {
  61. nand_decode_ext_id(chip);
  62. }
  63. }
  64. static int hynix_nand_init(struct nand_chip *chip)
  65. {
  66. if (!nand_is_slc(chip))
  67. chip->bbt_options |= NAND_BBT_SCANLASTPAGE;
  68. else
  69. chip->bbt_options |= NAND_BBT_SCAN2NDPAGE;
  70. return 0;
  71. }
  72. const struct nand_manufacturer_ops hynix_nand_manuf_ops = {
  73. .detect = hynix_nand_decode_id,
  74. .init = hynix_nand_init,
  75. };