Boris Brezillon | 348d56a | 2018-09-07 00:38:48 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * Copyright (c) 2018 - Bootlin |
| 4 | * |
| 5 | * Author: Boris Brezillon <boris.brezillon@bootlin.com> |
| 6 | * |
| 7 | * Header containing internal definitions to be used only by core files. |
| 8 | * NAND controller drivers should not include this file. |
| 9 | */ |
| 10 | |
| 11 | #ifndef __LINUX_RAWNAND_INTERNALS |
| 12 | #define __LINUX_RAWNAND_INTERNALS |
| 13 | |
| 14 | #include <linux/mtd/rawnand.h> |
| 15 | |
| 16 | /* |
| 17 | * NAND Flash Manufacturer ID Codes |
| 18 | */ |
Marcel Ziswiler | 727d378 | 2018-09-06 23:30:19 +0200 | [diff] [blame] | 19 | #define NAND_MFR_AMD 0x01 |
| 20 | #define NAND_MFR_ATO 0x9b |
| 21 | #define NAND_MFR_EON 0x92 |
Boris Brezillon | 348d56a | 2018-09-07 00:38:48 +0200 | [diff] [blame] | 22 | #define NAND_MFR_ESMT 0xc8 |
Boris Brezillon | 348d56a | 2018-09-07 00:38:48 +0200 | [diff] [blame] | 23 | #define NAND_MFR_FUJITSU 0x04 |
Marcel Ziswiler | 727d378 | 2018-09-06 23:30:19 +0200 | [diff] [blame] | 24 | #define NAND_MFR_HYNIX 0xad |
| 25 | #define NAND_MFR_INTEL 0x89 |
| 26 | #define NAND_MFR_MACRONIX 0xc2 |
| 27 | #define NAND_MFR_MICRON 0x2c |
Boris Brezillon | 348d56a | 2018-09-07 00:38:48 +0200 | [diff] [blame] | 28 | #define NAND_MFR_NATIONAL 0x8f |
| 29 | #define NAND_MFR_RENESAS 0x07 |
Marcel Ziswiler | 727d378 | 2018-09-06 23:30:19 +0200 | [diff] [blame] | 30 | #define NAND_MFR_SAMSUNG 0xec |
Boris Brezillon | 348d56a | 2018-09-07 00:38:48 +0200 | [diff] [blame] | 31 | #define NAND_MFR_SANDISK 0x45 |
Marcel Ziswiler | 727d378 | 2018-09-06 23:30:19 +0200 | [diff] [blame] | 32 | #define NAND_MFR_STMICRO 0x20 |
| 33 | #define NAND_MFR_TOSHIBA 0x98 |
Boris Brezillon | 348d56a | 2018-09-07 00:38:48 +0200 | [diff] [blame] | 34 | #define NAND_MFR_WINBOND 0xef |
| 35 | |
| 36 | /** |
| 37 | * struct nand_manufacturer_ops - NAND Manufacturer operations |
| 38 | * @detect: detect the NAND memory organization and capabilities |
| 39 | * @init: initialize all vendor specific fields (like the ->read_retry() |
| 40 | * implementation) if any. |
| 41 | * @cleanup: the ->init() function may have allocated resources, ->cleanup() |
| 42 | * is here to let vendor specific code release those resources. |
| 43 | * @fixup_onfi_param_page: apply vendor specific fixups to the ONFI parameter |
| 44 | * page. This is called after the checksum is verified. |
| 45 | */ |
| 46 | struct nand_manufacturer_ops { |
| 47 | void (*detect)(struct nand_chip *chip); |
| 48 | int (*init)(struct nand_chip *chip); |
| 49 | void (*cleanup)(struct nand_chip *chip); |
| 50 | void (*fixup_onfi_param_page)(struct nand_chip *chip, |
| 51 | struct nand_onfi_params *p); |
| 52 | }; |
| 53 | |
| 54 | /** |
| 55 | * struct nand_manufacturer - NAND Flash Manufacturer structure |
| 56 | * @name: Manufacturer name |
| 57 | * @id: manufacturer ID code of device. |
| 58 | * @ops: manufacturer operations |
| 59 | */ |
| 60 | struct nand_manufacturer { |
| 61 | int id; |
| 62 | char *name; |
| 63 | const struct nand_manufacturer_ops *ops; |
| 64 | }; |
| 65 | |
| 66 | |
| 67 | extern struct nand_flash_dev nand_flash_ids[]; |
| 68 | |
Boris Brezillon | 348d56a | 2018-09-07 00:38:48 +0200 | [diff] [blame] | 69 | extern const struct nand_manufacturer_ops amd_nand_manuf_ops; |
Marcel Ziswiler | a68642a | 2018-09-19 13:40:49 +0200 | [diff] [blame] | 70 | extern const struct nand_manufacturer_ops esmt_nand_manuf_ops; |
Marcel Ziswiler | 727d378 | 2018-09-06 23:30:19 +0200 | [diff] [blame] | 71 | extern const struct nand_manufacturer_ops hynix_nand_manuf_ops; |
Boris Brezillon | 348d56a | 2018-09-07 00:38:48 +0200 | [diff] [blame] | 72 | extern const struct nand_manufacturer_ops macronix_nand_manuf_ops; |
Marcel Ziswiler | 727d378 | 2018-09-06 23:30:19 +0200 | [diff] [blame] | 73 | extern const struct nand_manufacturer_ops micron_nand_manuf_ops; |
| 74 | extern const struct nand_manufacturer_ops samsung_nand_manuf_ops; |
| 75 | extern const struct nand_manufacturer_ops toshiba_nand_manuf_ops; |
Boris Brezillon | 348d56a | 2018-09-07 00:38:48 +0200 | [diff] [blame] | 76 | |
| 77 | /* Core functions */ |
| 78 | const struct nand_manufacturer *nand_get_manufacturer(u8 id); |
Frieder Schrempf | f90da78 | 2019-04-17 12:36:37 +0000 | [diff] [blame] | 79 | int nand_bbm_get_next_page(struct nand_chip *chip, int page); |
Boris Brezillon | 348d56a | 2018-09-07 00:38:48 +0200 | [diff] [blame] | 80 | int nand_markbad_bbm(struct nand_chip *chip, loff_t ofs); |
| 81 | int nand_erase_nand(struct nand_chip *chip, struct erase_info *instr, |
| 82 | int allowbbt); |
| 83 | int onfi_fill_data_interface(struct nand_chip *chip, |
| 84 | enum nand_data_interface_type type, |
| 85 | int timing_mode); |
| 86 | int nand_get_features(struct nand_chip *chip, int addr, u8 *subfeature_param); |
| 87 | int nand_set_features(struct nand_chip *chip, int addr, u8 *subfeature_param); |
| 88 | int nand_read_page_raw_notsupp(struct nand_chip *chip, u8 *buf, |
| 89 | int oob_required, int page); |
| 90 | int nand_write_page_raw_notsupp(struct nand_chip *chip, const u8 *buf, |
| 91 | int oob_required, int page); |
| 92 | int nand_exit_status_op(struct nand_chip *chip); |
Boris Brezillon | 1c325cc | 2018-09-07 00:38:50 +0200 | [diff] [blame] | 93 | int nand_read_param_page_op(struct nand_chip *chip, u8 page, void *buf, |
| 94 | unsigned int len); |
Boris Brezillon | 348d56a | 2018-09-07 00:38:48 +0200 | [diff] [blame] | 95 | void nand_decode_ext_id(struct nand_chip *chip); |
Boris Brezillon | 3d4af7c | 2018-09-07 00:38:49 +0200 | [diff] [blame] | 96 | void panic_nand_wait(struct nand_chip *chip, unsigned long timeo); |
Boris Brezillon | 1c325cc | 2018-09-07 00:38:50 +0200 | [diff] [blame] | 97 | void sanitize_string(uint8_t *s, size_t len); |
Boris Brezillon | 348d56a | 2018-09-07 00:38:48 +0200 | [diff] [blame] | 98 | |
Boris Brezillon | f2abfeb | 2018-11-11 08:55:23 +0100 | [diff] [blame] | 99 | static inline bool nand_has_exec_op(struct nand_chip *chip) |
| 100 | { |
| 101 | if (!chip->controller || !chip->controller->ops || |
| 102 | !chip->controller->ops->exec_op) |
| 103 | return false; |
| 104 | |
| 105 | return true; |
| 106 | } |
| 107 | |
Boris Brezillon | 1f2d29e | 2018-11-11 08:55:06 +0100 | [diff] [blame] | 108 | static inline int nand_exec_op(struct nand_chip *chip, |
| 109 | const struct nand_operation *op) |
| 110 | { |
Boris Brezillon | f2abfeb | 2018-11-11 08:55:23 +0100 | [diff] [blame] | 111 | if (!nand_has_exec_op(chip)) |
Boris Brezillon | 1f2d29e | 2018-11-11 08:55:06 +0100 | [diff] [blame] | 112 | return -ENOTSUPP; |
| 113 | |
Boris Brezillon | 32813e2 | 2018-10-29 11:58:29 +0100 | [diff] [blame] | 114 | if (WARN_ON(op->cs >= nanddev_ntargets(&chip->base))) |
Boris Brezillon | ae2294b | 2018-11-11 08:55:15 +0100 | [diff] [blame] | 115 | return -EINVAL; |
| 116 | |
Boris Brezillon | f2abfeb | 2018-11-11 08:55:23 +0100 | [diff] [blame] | 117 | return chip->controller->ops->exec_op(chip, op, false); |
Boris Brezillon | 1f2d29e | 2018-11-11 08:55:06 +0100 | [diff] [blame] | 118 | } |
| 119 | |
Boris Brezillon | 7a08dba | 2018-11-11 08:55:24 +0100 | [diff] [blame] | 120 | static inline bool nand_has_setup_data_iface(struct nand_chip *chip) |
| 121 | { |
| 122 | if (!chip->controller || !chip->controller->ops || |
| 123 | !chip->controller->ops->setup_data_interface) |
| 124 | return false; |
| 125 | |
| 126 | if (chip->options & NAND_KEEP_TIMINGS) |
| 127 | return false; |
| 128 | |
| 129 | return true; |
| 130 | } |
| 131 | |
Boris Brezillon | 348d56a | 2018-09-07 00:38:48 +0200 | [diff] [blame] | 132 | /* BBT functions */ |
| 133 | int nand_markbad_bbt(struct nand_chip *chip, loff_t offs); |
| 134 | int nand_isreserved_bbt(struct nand_chip *chip, loff_t offs); |
| 135 | int nand_isbad_bbt(struct nand_chip *chip, loff_t offs, int allowbbt); |
| 136 | |
Boris Brezillon | 3d4af7c | 2018-09-07 00:38:49 +0200 | [diff] [blame] | 137 | /* Legacy */ |
| 138 | void nand_legacy_set_defaults(struct nand_chip *chip); |
| 139 | void nand_legacy_adjust_cmdfunc(struct nand_chip *chip); |
| 140 | int nand_legacy_check_hooks(struct nand_chip *chip); |
| 141 | |
Boris Brezillon | 1c325cc | 2018-09-07 00:38:50 +0200 | [diff] [blame] | 142 | /* ONFI functions */ |
| 143 | u16 onfi_crc16(u16 crc, u8 const *p, size_t len); |
| 144 | int nand_onfi_detect(struct nand_chip *chip); |
| 145 | |
Boris Brezillon | 8ae3fbf | 2018-09-07 00:38:51 +0200 | [diff] [blame] | 146 | /* JEDEC functions */ |
| 147 | int nand_jedec_detect(struct nand_chip *chip); |
| 148 | |
Boris Brezillon | 348d56a | 2018-09-07 00:38:48 +0200 | [diff] [blame] | 149 | #endif /* __LINUX_RAWNAND_INTERNALS */ |