diff options
Diffstat (limited to 'include/linux/mtd/nand.h')
-rw-r--r-- | include/linux/mtd/nand.h | 234 |
1 files changed, 165 insertions, 69 deletions
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h index 8dd6e01f45c0..c5d3d5024fc8 100644 --- a/include/linux/mtd/nand.h +++ b/include/linux/mtd/nand.h | |||
@@ -29,26 +29,26 @@ struct nand_flash_dev; | |||
29 | struct device_node; | 29 | struct device_node; |
30 | 30 | ||
31 | /* Scan and identify a NAND device */ | 31 | /* Scan and identify a NAND device */ |
32 | extern int nand_scan(struct mtd_info *mtd, int max_chips); | 32 | int nand_scan(struct mtd_info *mtd, int max_chips); |
33 | /* | 33 | /* |
34 | * Separate phases of nand_scan(), allowing board driver to intervene | 34 | * Separate phases of nand_scan(), allowing board driver to intervene |
35 | * and override command or ECC setup according to flash type. | 35 | * and override command or ECC setup according to flash type. |
36 | */ | 36 | */ |
37 | extern int nand_scan_ident(struct mtd_info *mtd, int max_chips, | 37 | int nand_scan_ident(struct mtd_info *mtd, int max_chips, |
38 | struct nand_flash_dev *table); | 38 | struct nand_flash_dev *table); |
39 | extern int nand_scan_tail(struct mtd_info *mtd); | 39 | int nand_scan_tail(struct mtd_info *mtd); |
40 | 40 | ||
41 | /* Free resources held by the NAND device */ | 41 | /* Unregister the MTD device and free resources held by the NAND device */ |
42 | extern void nand_release(struct mtd_info *mtd); | 42 | void nand_release(struct mtd_info *mtd); |
43 | 43 | ||
44 | /* Internal helper for board drivers which need to override command function */ | 44 | /* Internal helper for board drivers which need to override command function */ |
45 | extern void nand_wait_ready(struct mtd_info *mtd); | 45 | void nand_wait_ready(struct mtd_info *mtd); |
46 | 46 | ||
47 | /* locks all blocks present in the device */ | 47 | /* locks all blocks present in the device */ |
48 | extern int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len); | 48 | int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len); |
49 | 49 | ||
50 | /* unlocks specified locked blocks */ | 50 | /* unlocks specified locked blocks */ |
51 | extern int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len); | 51 | int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len); |
52 | 52 | ||
53 | /* The maximum number of NAND chips in an array */ | 53 | /* The maximum number of NAND chips in an array */ |
54 | #define NAND_MAX_CHIPS 8 | 54 | #define NAND_MAX_CHIPS 8 |
@@ -141,6 +141,7 @@ enum nand_ecc_algo { | |||
141 | * pages and you want to rely on the default implementation. | 141 | * pages and you want to rely on the default implementation. |
142 | */ | 142 | */ |
143 | #define NAND_ECC_GENERIC_ERASED_CHECK BIT(0) | 143 | #define NAND_ECC_GENERIC_ERASED_CHECK BIT(0) |
144 | #define NAND_ECC_MAXIMIZE BIT(1) | ||
144 | 145 | ||
145 | /* Bit mask for flags passed to do_nand_read_ecc */ | 146 | /* Bit mask for flags passed to do_nand_read_ecc */ |
146 | #define NAND_GET_DEVICE 0x80 | 147 | #define NAND_GET_DEVICE 0x80 |
@@ -460,6 +461,13 @@ struct nand_hw_control { | |||
460 | wait_queue_head_t wq; | 461 | wait_queue_head_t wq; |
461 | }; | 462 | }; |
462 | 463 | ||
464 | static inline void nand_hw_control_init(struct nand_hw_control *nfc) | ||
465 | { | ||
466 | nfc->active = NULL; | ||
467 | spin_lock_init(&nfc->lock); | ||
468 | init_waitqueue_head(&nfc->wq); | ||
469 | } | ||
470 | |||
463 | /** | 471 | /** |
464 | * struct nand_ecc_ctrl - Control structure for ECC | 472 | * struct nand_ecc_ctrl - Control structure for ECC |
465 | * @mode: ECC mode | 473 | * @mode: ECC mode |
@@ -566,6 +574,123 @@ struct nand_buffers { | |||
566 | }; | 574 | }; |
567 | 575 | ||
568 | /** | 576 | /** |
577 | * struct nand_sdr_timings - SDR NAND chip timings | ||
578 | * | ||
579 | * This struct defines the timing requirements of a SDR NAND chip. | ||
580 | * These information can be found in every NAND datasheets and the timings | ||
581 | * meaning are described in the ONFI specifications: | ||
582 | * www.onfi.org/~/media/ONFI/specs/onfi_3_1_spec.pdf (chapter 4.15 Timing | ||
583 | * Parameters) | ||
584 | * | ||
585 | * All these timings are expressed in picoseconds. | ||
586 | * | ||
587 | * @tALH_min: ALE hold time | ||
588 | * @tADL_min: ALE to data loading time | ||
589 | * @tALS_min: ALE setup time | ||
590 | * @tAR_min: ALE to RE# delay | ||
591 | * @tCEA_max: CE# access time | ||
592 | * @tCEH_min: | ||
593 | * @tCH_min: CE# hold time | ||
594 | * @tCHZ_max: CE# high to output hi-Z | ||
595 | * @tCLH_min: CLE hold time | ||
596 | * @tCLR_min: CLE to RE# delay | ||
597 | * @tCLS_min: CLE setup time | ||
598 | * @tCOH_min: CE# high to output hold | ||
599 | * @tCS_min: CE# setup time | ||
600 | * @tDH_min: Data hold time | ||
601 | * @tDS_min: Data setup time | ||
602 | * @tFEAT_max: Busy time for Set Features and Get Features | ||
603 | * @tIR_min: Output hi-Z to RE# low | ||
604 | * @tITC_max: Interface and Timing Mode Change time | ||
605 | * @tRC_min: RE# cycle time | ||
606 | * @tREA_max: RE# access time | ||
607 | * @tREH_min: RE# high hold time | ||
608 | * @tRHOH_min: RE# high to output hold | ||
609 | * @tRHW_min: RE# high to WE# low | ||
610 | * @tRHZ_max: RE# high to output hi-Z | ||
611 | * @tRLOH_min: RE# low to output hold | ||
612 | * @tRP_min: RE# pulse width | ||
613 | * @tRR_min: Ready to RE# low (data only) | ||
614 | * @tRST_max: Device reset time, measured from the falling edge of R/B# to the | ||
615 | * rising edge of R/B#. | ||
616 | * @tWB_max: WE# high to SR[6] low | ||
617 | * @tWC_min: WE# cycle time | ||
618 | * @tWH_min: WE# high hold time | ||
619 | * @tWHR_min: WE# high to RE# low | ||
620 | * @tWP_min: WE# pulse width | ||
621 | * @tWW_min: WP# transition to WE# low | ||
622 | */ | ||
623 | struct nand_sdr_timings { | ||
624 | u32 tALH_min; | ||
625 | u32 tADL_min; | ||
626 | u32 tALS_min; | ||
627 | u32 tAR_min; | ||
628 | u32 tCEA_max; | ||
629 | u32 tCEH_min; | ||
630 | u32 tCH_min; | ||
631 | u32 tCHZ_max; | ||
632 | u32 tCLH_min; | ||
633 | u32 tCLR_min; | ||
634 | u32 tCLS_min; | ||
635 | u32 tCOH_min; | ||
636 | u32 tCS_min; | ||
637 | u32 tDH_min; | ||
638 | u32 tDS_min; | ||
639 | u32 tFEAT_max; | ||
640 | u32 tIR_min; | ||
641 | u32 tITC_max; | ||
642 | u32 tRC_min; | ||
643 | u32 tREA_max; | ||
644 | u32 tREH_min; | ||
645 | u32 tRHOH_min; | ||
646 | u32 tRHW_min; | ||
647 | u32 tRHZ_max; | ||
648 | u32 tRLOH_min; | ||
649 | u32 tRP_min; | ||
650 | u32 tRR_min; | ||
651 | u64 tRST_max; | ||
652 | u32 tWB_max; | ||
653 | u32 tWC_min; | ||
654 | u32 tWH_min; | ||
655 | u32 tWHR_min; | ||
656 | u32 tWP_min; | ||
657 | u32 tWW_min; | ||
658 | }; | ||
659 | |||
660 | /** | ||
661 | * enum nand_data_interface_type - NAND interface timing type | ||
662 | * @NAND_SDR_IFACE: Single Data Rate interface | ||
663 | */ | ||
664 | enum nand_data_interface_type { | ||
665 | NAND_SDR_IFACE, | ||
666 | }; | ||
667 | |||
668 | /** | ||
669 | * struct nand_data_interface - NAND interface timing | ||
670 | * @type: type of the timing | ||
671 | * @timings: The timing, type according to @type | ||
672 | */ | ||
673 | struct nand_data_interface { | ||
674 | enum nand_data_interface_type type; | ||
675 | union { | ||
676 | struct nand_sdr_timings sdr; | ||
677 | } timings; | ||
678 | }; | ||
679 | |||
680 | /** | ||
681 | * nand_get_sdr_timings - get SDR timing from data interface | ||
682 | * @conf: The data interface | ||
683 | */ | ||
684 | static inline const struct nand_sdr_timings * | ||
685 | nand_get_sdr_timings(const struct nand_data_interface *conf) | ||
686 | { | ||
687 | if (conf->type != NAND_SDR_IFACE) | ||
688 | return ERR_PTR(-EINVAL); | ||
689 | |||
690 | return &conf->timings.sdr; | ||
691 | } | ||
692 | |||
693 | /** | ||
569 | * struct nand_chip - NAND Private Flash Chip Data | 694 | * struct nand_chip - NAND Private Flash Chip Data |
570 | * @mtd: MTD device registered to the MTD framework | 695 | * @mtd: MTD device registered to the MTD framework |
571 | * @IO_ADDR_R: [BOARDSPECIFIC] address to read the 8 I/O lines of the | 696 | * @IO_ADDR_R: [BOARDSPECIFIC] address to read the 8 I/O lines of the |
@@ -627,10 +752,9 @@ struct nand_buffers { | |||
627 | * also from the datasheet. It is the recommended ECC step | 752 | * also from the datasheet. It is the recommended ECC step |
628 | * size, if known; if unknown, set to zero. | 753 | * size, if known; if unknown, set to zero. |
629 | * @onfi_timing_mode_default: [INTERN] default ONFI timing mode. This field is | 754 | * @onfi_timing_mode_default: [INTERN] default ONFI timing mode. This field is |
630 | * either deduced from the datasheet if the NAND | 755 | * set to the actually used ONFI mode if the chip is |
631 | * chip is not ONFI compliant or set to 0 if it is | 756 | * ONFI compliant or deduced from the datasheet if |
632 | * (an ONFI chip is always configured in mode 0 | 757 | * the NAND chip is not ONFI compliant. |
633 | * after a NAND reset) | ||
634 | * @numchips: [INTERN] number of physical chips | 758 | * @numchips: [INTERN] number of physical chips |
635 | * @chipsize: [INTERN] the size of one chip for multichip arrays | 759 | * @chipsize: [INTERN] the size of one chip for multichip arrays |
636 | * @pagemask: [INTERN] page number mask = number of (pages / chip) - 1 | 760 | * @pagemask: [INTERN] page number mask = number of (pages / chip) - 1 |
@@ -650,6 +774,7 @@ struct nand_buffers { | |||
650 | * @read_retries: [INTERN] the number of read retry modes supported | 774 | * @read_retries: [INTERN] the number of read retry modes supported |
651 | * @onfi_set_features: [REPLACEABLE] set the features for ONFI nand | 775 | * @onfi_set_features: [REPLACEABLE] set the features for ONFI nand |
652 | * @onfi_get_features: [REPLACEABLE] get the features for ONFI nand | 776 | * @onfi_get_features: [REPLACEABLE] get the features for ONFI nand |
777 | * @setup_data_interface: [OPTIONAL] setup the data interface and timing | ||
653 | * @bbt: [INTERN] bad block table pointer | 778 | * @bbt: [INTERN] bad block table pointer |
654 | * @bbt_td: [REPLACEABLE] bad block table descriptor for flash | 779 | * @bbt_td: [REPLACEABLE] bad block table descriptor for flash |
655 | * lookup. | 780 | * lookup. |
@@ -696,6 +821,10 @@ struct nand_chip { | |||
696 | int (*onfi_get_features)(struct mtd_info *mtd, struct nand_chip *chip, | 821 | int (*onfi_get_features)(struct mtd_info *mtd, struct nand_chip *chip, |
697 | int feature_addr, uint8_t *subfeature_para); | 822 | int feature_addr, uint8_t *subfeature_para); |
698 | int (*setup_read_retry)(struct mtd_info *mtd, int retry_mode); | 823 | int (*setup_read_retry)(struct mtd_info *mtd, int retry_mode); |
824 | int (*setup_data_interface)(struct mtd_info *mtd, | ||
825 | const struct nand_data_interface *conf, | ||
826 | bool check_only); | ||
827 | |||
699 | 828 | ||
700 | int chip_delay; | 829 | int chip_delay; |
701 | unsigned int options; | 830 | unsigned int options; |
@@ -725,6 +854,8 @@ struct nand_chip { | |||
725 | struct nand_jedec_params jedec_params; | 854 | struct nand_jedec_params jedec_params; |
726 | }; | 855 | }; |
727 | 856 | ||
857 | struct nand_data_interface *data_interface; | ||
858 | |||
728 | int read_retries; | 859 | int read_retries; |
729 | 860 | ||
730 | flstate_t state; | 861 | flstate_t state; |
@@ -893,14 +1024,14 @@ struct nand_manufacturers { | |||
893 | extern struct nand_flash_dev nand_flash_ids[]; | 1024 | extern struct nand_flash_dev nand_flash_ids[]; |
894 | extern struct nand_manufacturers nand_manuf_ids[]; | 1025 | extern struct nand_manufacturers nand_manuf_ids[]; |
895 | 1026 | ||
896 | extern int nand_default_bbt(struct mtd_info *mtd); | 1027 | int nand_default_bbt(struct mtd_info *mtd); |
897 | extern int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs); | 1028 | int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs); |
898 | extern int nand_isreserved_bbt(struct mtd_info *mtd, loff_t offs); | 1029 | int nand_isreserved_bbt(struct mtd_info *mtd, loff_t offs); |
899 | extern int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt); | 1030 | int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt); |
900 | extern int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, | 1031 | int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, |
901 | int allowbbt); | 1032 | int allowbbt); |
902 | extern int nand_do_read(struct mtd_info *mtd, loff_t from, size_t len, | 1033 | int nand_do_read(struct mtd_info *mtd, loff_t from, size_t len, |
903 | size_t *retlen, uint8_t *buf); | 1034 | size_t *retlen, uint8_t *buf); |
904 | 1035 | ||
905 | /** | 1036 | /** |
906 | * struct platform_nand_chip - chip level device structure | 1037 | * struct platform_nand_chip - chip level device structure |
@@ -988,6 +1119,11 @@ static inline int onfi_get_sync_timing_mode(struct nand_chip *chip) | |||
988 | return le16_to_cpu(chip->onfi_params.src_sync_timing_mode); | 1119 | return le16_to_cpu(chip->onfi_params.src_sync_timing_mode); |
989 | } | 1120 | } |
990 | 1121 | ||
1122 | int onfi_init_data_interface(struct nand_chip *chip, | ||
1123 | struct nand_data_interface *iface, | ||
1124 | enum nand_data_interface_type type, | ||
1125 | int timing_mode); | ||
1126 | |||
991 | /* | 1127 | /* |
992 | * Check if it is a SLC nand. | 1128 | * Check if it is a SLC nand. |
993 | * The !nand_is_slc() can be used to check the MLC/TLC nand chips. | 1129 | * The !nand_is_slc() can be used to check the MLC/TLC nand chips. |
@@ -1023,57 +1159,10 @@ static inline int jedec_feature(struct nand_chip *chip) | |||
1023 | : 0; | 1159 | : 0; |
1024 | } | 1160 | } |
1025 | 1161 | ||
1026 | /* | ||
1027 | * struct nand_sdr_timings - SDR NAND chip timings | ||
1028 | * | ||
1029 | * This struct defines the timing requirements of a SDR NAND chip. | ||
1030 | * These informations can be found in every NAND datasheets and the timings | ||
1031 | * meaning are described in the ONFI specifications: | ||
1032 | * www.onfi.org/~/media/ONFI/specs/onfi_3_1_spec.pdf (chapter 4.15 Timing | ||
1033 | * Parameters) | ||
1034 | * | ||
1035 | * All these timings are expressed in picoseconds. | ||
1036 | */ | ||
1037 | |||
1038 | struct nand_sdr_timings { | ||
1039 | u32 tALH_min; | ||
1040 | u32 tADL_min; | ||
1041 | u32 tALS_min; | ||
1042 | u32 tAR_min; | ||
1043 | u32 tCEA_max; | ||
1044 | u32 tCEH_min; | ||
1045 | u32 tCH_min; | ||
1046 | u32 tCHZ_max; | ||
1047 | u32 tCLH_min; | ||
1048 | u32 tCLR_min; | ||
1049 | u32 tCLS_min; | ||
1050 | u32 tCOH_min; | ||
1051 | u32 tCS_min; | ||
1052 | u32 tDH_min; | ||
1053 | u32 tDS_min; | ||
1054 | u32 tFEAT_max; | ||
1055 | u32 tIR_min; | ||
1056 | u32 tITC_max; | ||
1057 | u32 tRC_min; | ||
1058 | u32 tREA_max; | ||
1059 | u32 tREH_min; | ||
1060 | u32 tRHOH_min; | ||
1061 | u32 tRHW_min; | ||
1062 | u32 tRHZ_max; | ||
1063 | u32 tRLOH_min; | ||
1064 | u32 tRP_min; | ||
1065 | u32 tRR_min; | ||
1066 | u64 tRST_max; | ||
1067 | u32 tWB_max; | ||
1068 | u32 tWC_min; | ||
1069 | u32 tWH_min; | ||
1070 | u32 tWHR_min; | ||
1071 | u32 tWP_min; | ||
1072 | u32 tWW_min; | ||
1073 | }; | ||
1074 | |||
1075 | /* get timing characteristics from ONFI timing mode. */ | 1162 | /* get timing characteristics from ONFI timing mode. */ |
1076 | const struct nand_sdr_timings *onfi_async_timing_mode_to_sdr_timings(int mode); | 1163 | const struct nand_sdr_timings *onfi_async_timing_mode_to_sdr_timings(int mode); |
1164 | /* get data interface from ONFI timing mode 0, used after reset. */ | ||
1165 | const struct nand_data_interface *nand_get_default_data_interface(void); | ||
1077 | 1166 | ||
1078 | int nand_check_erased_ecc_chunk(void *data, int datalen, | 1167 | int nand_check_erased_ecc_chunk(void *data, int datalen, |
1079 | void *ecc, int ecclen, | 1168 | void *ecc, int ecclen, |
@@ -1093,4 +1182,11 @@ int nand_read_oob_std(struct mtd_info *mtd, struct nand_chip *chip, int page); | |||
1093 | /* Default read_oob syndrome implementation */ | 1182 | /* Default read_oob syndrome implementation */ |
1094 | int nand_read_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip, | 1183 | int nand_read_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip, |
1095 | int page); | 1184 | int page); |
1185 | |||
1186 | /* Reset and initialize a NAND device */ | ||
1187 | int nand_reset(struct nand_chip *chip); | ||
1188 | |||
1189 | /* Free resources held by the NAND device */ | ||
1190 | void nand_cleanup(struct nand_chip *chip); | ||
1191 | |||
1096 | #endif /* __LINUX_MTD_NAND_H */ | 1192 | #endif /* __LINUX_MTD_NAND_H */ |