nand_micron.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. struct nand_onfi_vendor_micron {
  19. u8 two_plane_read;
  20. u8 read_cache;
  21. u8 read_unique_id;
  22. u8 dq_imped;
  23. u8 dq_imped_num_settings;
  24. u8 dq_imped_feat_addr;
  25. u8 rb_pulldown_strength;
  26. u8 rb_pulldown_strength_feat_addr;
  27. u8 rb_pulldown_strength_num_settings;
  28. u8 otp_mode;
  29. u8 otp_page_start;
  30. u8 otp_data_prot_addr;
  31. u8 otp_num_pages;
  32. u8 otp_feat_addr;
  33. u8 read_retry_options;
  34. u8 reserved[72];
  35. u8 param_revision;
  36. } __packed;
  37. static int micron_nand_setup_read_retry(struct mtd_info *mtd, int retry_mode)
  38. {
  39. struct nand_chip *chip = mtd_to_nand(mtd);
  40. u8 feature[ONFI_SUBFEATURE_PARAM_LEN] = {retry_mode};
  41. return chip->onfi_set_features(mtd, chip, ONFI_FEATURE_ADDR_READ_RETRY,
  42. feature);
  43. }
  44. /*
  45. * Configure chip properties from Micron vendor-specific ONFI table
  46. */
  47. static int micron_nand_onfi_init(struct nand_chip *chip)
  48. {
  49. struct nand_onfi_params *p = &chip->onfi_params;
  50. struct nand_onfi_vendor_micron *micron = (void *)p->vendor;
  51. if (!chip->onfi_version)
  52. return 0;
  53. if (le16_to_cpu(p->vendor_revision) < 1)
  54. return 0;
  55. chip->read_retries = micron->read_retry_options;
  56. chip->setup_read_retry = micron_nand_setup_read_retry;
  57. return 0;
  58. }
  59. static int micron_nand_init(struct nand_chip *chip)
  60. {
  61. struct mtd_info *mtd = nand_to_mtd(chip);
  62. int ret;
  63. ret = micron_nand_onfi_init(chip);
  64. if (ret)
  65. return ret;
  66. if (mtd->writesize == 2048)
  67. chip->bbt_options |= NAND_BBT_SCAN2NDPAGE;
  68. return 0;
  69. }
  70. const struct nand_manufacturer_ops micron_nand_manuf_ops = {
  71. .init = micron_nand_init,
  72. };