spi-nor.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2014 Freescale Semiconductor, Inc.
  4. */
  5. #ifndef __LINUX_MTD_SPI_NOR_H
  6. #define __LINUX_MTD_SPI_NOR_H
  7. #include <linux/bitops.h>
  8. #include <linux/mtd/mtd.h>
  9. #include <linux/spi/spi-mem.h>
  10. /*
  11. * Note on opcode nomenclature: some opcodes have a format like
  12. * SPINOR_OP_FUNCTION{4,}_x_y_z. The numbers x, y, and z stand for the number
  13. * of I/O lines used for the opcode, address, and data (respectively). The
  14. * FUNCTION has an optional suffix of '4', to represent an opcode which
  15. * requires a 4-byte (32-bit) address.
  16. */
  17. /* Flash opcodes. */
  18. #define SPINOR_OP_WRDI 0x04 /* Write disable */
  19. #define SPINOR_OP_WREN 0x06 /* Write enable */
  20. #define SPINOR_OP_RDSR 0x05 /* Read status register */
  21. #define SPINOR_OP_WRSR 0x01 /* Write status register 1 byte */
  22. #define SPINOR_OP_RDSR2 0x3f /* Read status register 2 */
  23. #define SPINOR_OP_WRSR2 0x3e /* Write status register 2 */
  24. #define SPINOR_OP_READ 0x03 /* Read data bytes (low frequency) */
  25. #define SPINOR_OP_READ_FAST 0x0b /* Read data bytes (high frequency) */
  26. #define SPINOR_OP_READ_1_1_2 0x3b /* Read data bytes (Dual Output SPI) */
  27. #define SPINOR_OP_READ_1_2_2 0xbb /* Read data bytes (Dual I/O SPI) */
  28. #define SPINOR_OP_READ_1_1_4 0x6b /* Read data bytes (Quad Output SPI) */
  29. #define SPINOR_OP_READ_1_4_4 0xeb /* Read data bytes (Quad I/O SPI) */
  30. #define SPINOR_OP_READ_1_1_8 0x8b /* Read data bytes (Octal Output SPI) */
  31. #define SPINOR_OP_READ_1_8_8 0xcb /* Read data bytes (Octal I/O SPI) */
  32. #define SPINOR_OP_PP 0x02 /* Page program (up to 256 bytes) */
  33. #define SPINOR_OP_PP_1_1_4 0x32 /* Quad page program */
  34. #define SPINOR_OP_PP_1_4_4 0x38 /* Quad page program */
  35. #define SPINOR_OP_PP_1_1_8 0x82 /* Octal page program */
  36. #define SPINOR_OP_PP_1_8_8 0xc2 /* Octal page program */
  37. #define SPINOR_OP_BE_4K 0x20 /* Erase 4KiB block */
  38. #define SPINOR_OP_BE_4K_PMC 0xd7 /* Erase 4KiB block on PMC chips */
  39. #define SPINOR_OP_BE_32K 0x52 /* Erase 32KiB block */
  40. #define SPINOR_OP_CHIP_ERASE 0xc7 /* Erase whole flash chip */
  41. #define SPINOR_OP_SE 0xd8 /* Sector erase (usually 64KiB) */
  42. #define SPINOR_OP_RDID 0x9f /* Read JEDEC ID */
  43. #define SPINOR_OP_RDSFDP 0x5a /* Read SFDP */
  44. #define SPINOR_OP_RDCR 0x35 /* Read configuration register */
  45. #define SPINOR_OP_SRSTEN 0x66 /* Software Reset Enable */
  46. #define SPINOR_OP_SRST 0x99 /* Software Reset */
  47. #define SPINOR_OP_GBULK 0x98 /* Global Block Unlock */
  48. /* 4-byte address opcodes - used on Spansion and some Macronix flashes. */
  49. #define SPINOR_OP_READ_4B 0x13 /* Read data bytes (low frequency) */
  50. #define SPINOR_OP_READ_FAST_4B 0x0c /* Read data bytes (high frequency) */
  51. #define SPINOR_OP_READ_1_1_2_4B 0x3c /* Read data bytes (Dual Output SPI) */
  52. #define SPINOR_OP_READ_1_2_2_4B 0xbc /* Read data bytes (Dual I/O SPI) */
  53. #define SPINOR_OP_READ_1_1_4_4B 0x6c /* Read data bytes (Quad Output SPI) */
  54. #define SPINOR_OP_READ_1_4_4_4B 0xec /* Read data bytes (Quad I/O SPI) */
  55. #define SPINOR_OP_READ_1_1_8_4B 0x7c /* Read data bytes (Octal Output SPI) */
  56. #define SPINOR_OP_READ_1_8_8_4B 0xcc /* Read data bytes (Octal I/O SPI) */
  57. #define SPINOR_OP_PP_4B 0x12 /* Page program (up to 256 bytes) */
  58. #define SPINOR_OP_PP_1_1_4_4B 0x34 /* Quad page program */
  59. #define SPINOR_OP_PP_1_4_4_4B 0x3e /* Quad page program */
  60. #define SPINOR_OP_PP_1_1_8_4B 0x84 /* Octal page program */
  61. #define SPINOR_OP_PP_1_8_8_4B 0x8e /* Octal page program */
  62. #define SPINOR_OP_BE_4K_4B 0x21 /* Erase 4KiB block */
  63. #define SPINOR_OP_BE_32K_4B 0x5c /* Erase 32KiB block */
  64. #define SPINOR_OP_SE_4B 0xdc /* Sector erase (usually 64KiB) */
  65. /* Double Transfer Rate opcodes - defined in JEDEC JESD216B. */
  66. #define SPINOR_OP_READ_1_1_1_DTR 0x0d
  67. #define SPINOR_OP_READ_1_2_2_DTR 0xbd
  68. #define SPINOR_OP_READ_1_4_4_DTR 0xed
  69. #define SPINOR_OP_READ_1_1_1_DTR_4B 0x0e
  70. #define SPINOR_OP_READ_1_2_2_DTR_4B 0xbe
  71. #define SPINOR_OP_READ_1_4_4_DTR_4B 0xee
  72. /* Used for SST flashes only. */
  73. #define SPINOR_OP_BP 0x02 /* Byte program */
  74. #define SPINOR_OP_AAI_WP 0xad /* Auto address increment word program */
  75. /* Used for Macronix and Winbond flashes. */
  76. #define SPINOR_OP_EN4B 0xb7 /* Enter 4-byte mode */
  77. #define SPINOR_OP_EX4B 0xe9 /* Exit 4-byte mode */
  78. /* Used for Spansion flashes only. */
  79. #define SPINOR_OP_BRWR 0x17 /* Bank register write */
  80. /* Used for Micron flashes only. */
  81. #define SPINOR_OP_RD_EVCR 0x65 /* Read EVCR register */
  82. #define SPINOR_OP_WD_EVCR 0x61 /* Write EVCR register */
  83. /* Used for GigaDevices and Winbond flashes. */
  84. #define SPINOR_OP_ESECR 0x44 /* Erase Security registers */
  85. #define SPINOR_OP_PSECR 0x42 /* Program Security registers */
  86. #define SPINOR_OP_RSECR 0x48 /* Read Security registers */
  87. /* Status Register bits. */
  88. #define SR_WIP BIT(0) /* Write in progress */
  89. #define SR_WEL BIT(1) /* Write enable latch */
  90. /* meaning of other SR_* bits may differ between vendors */
  91. #define SR_BP0 BIT(2) /* Block protect 0 */
  92. #define SR_BP1 BIT(3) /* Block protect 1 */
  93. #define SR_BP2 BIT(4) /* Block protect 2 */
  94. #define SR_BP3 BIT(5) /* Block protect 3 */
  95. #define SR_TB_BIT5 BIT(5) /* Top/Bottom protect */
  96. #define SR_BP3_BIT6 BIT(6) /* Block protect 3 */
  97. #define SR_TB_BIT6 BIT(6) /* Top/Bottom protect */
  98. #define SR_SRWD BIT(7) /* SR write protect */
  99. /* Spansion/Cypress specific status bits */
  100. #define SR_E_ERR BIT(5)
  101. #define SR_P_ERR BIT(6)
  102. #define SR1_QUAD_EN_BIT6 BIT(6)
  103. #define SR_BP_SHIFT 2
  104. /* Enhanced Volatile Configuration Register bits */
  105. #define EVCR_QUAD_EN_MICRON BIT(7) /* Micron Quad I/O */
  106. /* Status Register 2 bits. */
  107. #define SR2_QUAD_EN_BIT1 BIT(1)
  108. #define SR2_LB1 BIT(3) /* Security Register Lock Bit 1 */
  109. #define SR2_LB2 BIT(4) /* Security Register Lock Bit 2 */
  110. #define SR2_LB3 BIT(5) /* Security Register Lock Bit 3 */
  111. #define SR2_QUAD_EN_BIT7 BIT(7)
  112. /* Supported SPI protocols */
  113. #define SNOR_PROTO_INST_MASK GENMASK(23, 16)
  114. #define SNOR_PROTO_INST_SHIFT 16
  115. #define SNOR_PROTO_INST(_nbits) \
  116. ((((unsigned long)(_nbits)) << SNOR_PROTO_INST_SHIFT) & \
  117. SNOR_PROTO_INST_MASK)
  118. #define SNOR_PROTO_ADDR_MASK GENMASK(15, 8)
  119. #define SNOR_PROTO_ADDR_SHIFT 8
  120. #define SNOR_PROTO_ADDR(_nbits) \
  121. ((((unsigned long)(_nbits)) << SNOR_PROTO_ADDR_SHIFT) & \
  122. SNOR_PROTO_ADDR_MASK)
  123. #define SNOR_PROTO_DATA_MASK GENMASK(7, 0)
  124. #define SNOR_PROTO_DATA_SHIFT 0
  125. #define SNOR_PROTO_DATA(_nbits) \
  126. ((((unsigned long)(_nbits)) << SNOR_PROTO_DATA_SHIFT) & \
  127. SNOR_PROTO_DATA_MASK)
  128. #define SNOR_PROTO_IS_DTR BIT(24) /* Double Transfer Rate */
  129. #define SNOR_PROTO_STR(_inst_nbits, _addr_nbits, _data_nbits) \
  130. (SNOR_PROTO_INST(_inst_nbits) | \
  131. SNOR_PROTO_ADDR(_addr_nbits) | \
  132. SNOR_PROTO_DATA(_data_nbits))
  133. #define SNOR_PROTO_DTR(_inst_nbits, _addr_nbits, _data_nbits) \
  134. (SNOR_PROTO_IS_DTR | \
  135. SNOR_PROTO_STR(_inst_nbits, _addr_nbits, _data_nbits))
  136. enum spi_nor_protocol {
  137. SNOR_PROTO_1_1_1 = SNOR_PROTO_STR(1, 1, 1),
  138. SNOR_PROTO_1_1_2 = SNOR_PROTO_STR(1, 1, 2),
  139. SNOR_PROTO_1_1_4 = SNOR_PROTO_STR(1, 1, 4),
  140. SNOR_PROTO_1_1_8 = SNOR_PROTO_STR(1, 1, 8),
  141. SNOR_PROTO_1_2_2 = SNOR_PROTO_STR(1, 2, 2),
  142. SNOR_PROTO_1_4_4 = SNOR_PROTO_STR(1, 4, 4),
  143. SNOR_PROTO_1_8_8 = SNOR_PROTO_STR(1, 8, 8),
  144. SNOR_PROTO_2_2_2 = SNOR_PROTO_STR(2, 2, 2),
  145. SNOR_PROTO_4_4_4 = SNOR_PROTO_STR(4, 4, 4),
  146. SNOR_PROTO_8_8_8 = SNOR_PROTO_STR(8, 8, 8),
  147. SNOR_PROTO_1_1_1_DTR = SNOR_PROTO_DTR(1, 1, 1),
  148. SNOR_PROTO_1_2_2_DTR = SNOR_PROTO_DTR(1, 2, 2),
  149. SNOR_PROTO_1_4_4_DTR = SNOR_PROTO_DTR(1, 4, 4),
  150. SNOR_PROTO_1_8_8_DTR = SNOR_PROTO_DTR(1, 8, 8),
  151. SNOR_PROTO_8_8_8_DTR = SNOR_PROTO_DTR(8, 8, 8),
  152. };
  153. static inline bool spi_nor_protocol_is_dtr(enum spi_nor_protocol proto)
  154. {
  155. return !!(proto & SNOR_PROTO_IS_DTR);
  156. }
  157. static inline u8 spi_nor_get_protocol_inst_nbits(enum spi_nor_protocol proto)
  158. {
  159. return ((unsigned long)(proto & SNOR_PROTO_INST_MASK)) >>
  160. SNOR_PROTO_INST_SHIFT;
  161. }
  162. static inline u8 spi_nor_get_protocol_addr_nbits(enum spi_nor_protocol proto)
  163. {
  164. return ((unsigned long)(proto & SNOR_PROTO_ADDR_MASK)) >>
  165. SNOR_PROTO_ADDR_SHIFT;
  166. }
  167. static inline u8 spi_nor_get_protocol_data_nbits(enum spi_nor_protocol proto)
  168. {
  169. return ((unsigned long)(proto & SNOR_PROTO_DATA_MASK)) >>
  170. SNOR_PROTO_DATA_SHIFT;
  171. }
  172. static inline u8 spi_nor_get_protocol_width(enum spi_nor_protocol proto)
  173. {
  174. return spi_nor_get_protocol_data_nbits(proto);
  175. }
  176. /**
  177. * struct spi_nor_hwcaps - Structure for describing the hardware capabilies
  178. * supported by the SPI controller (bus master).
  179. * @mask: the bitmask listing all the supported hw capabilies
  180. */
  181. struct spi_nor_hwcaps {
  182. u32 mask;
  183. };
  184. /*
  185. *(Fast) Read capabilities.
  186. * MUST be ordered by priority: the higher bit position, the higher priority.
  187. * As a matter of performances, it is relevant to use Octal SPI protocols first,
  188. * then Quad SPI protocols before Dual SPI protocols, Fast Read and lastly
  189. * (Slow) Read.
  190. */
  191. #define SNOR_HWCAPS_READ_MASK GENMASK(15, 0)
  192. #define SNOR_HWCAPS_READ BIT(0)
  193. #define SNOR_HWCAPS_READ_FAST BIT(1)
  194. #define SNOR_HWCAPS_READ_1_1_1_DTR BIT(2)
  195. #define SNOR_HWCAPS_READ_DUAL GENMASK(6, 3)
  196. #define SNOR_HWCAPS_READ_1_1_2 BIT(3)
  197. #define SNOR_HWCAPS_READ_1_2_2 BIT(4)
  198. #define SNOR_HWCAPS_READ_2_2_2 BIT(5)
  199. #define SNOR_HWCAPS_READ_1_2_2_DTR BIT(6)
  200. #define SNOR_HWCAPS_READ_QUAD GENMASK(10, 7)
  201. #define SNOR_HWCAPS_READ_1_1_4 BIT(7)
  202. #define SNOR_HWCAPS_READ_1_4_4 BIT(8)
  203. #define SNOR_HWCAPS_READ_4_4_4 BIT(9)
  204. #define SNOR_HWCAPS_READ_1_4_4_DTR BIT(10)
  205. #define SNOR_HWCAPS_READ_OCTAL GENMASK(15, 11)
  206. #define SNOR_HWCAPS_READ_1_1_8 BIT(11)
  207. #define SNOR_HWCAPS_READ_1_8_8 BIT(12)
  208. #define SNOR_HWCAPS_READ_8_8_8 BIT(13)
  209. #define SNOR_HWCAPS_READ_1_8_8_DTR BIT(14)
  210. #define SNOR_HWCAPS_READ_8_8_8_DTR BIT(15)
  211. /*
  212. * Page Program capabilities.
  213. * MUST be ordered by priority: the higher bit position, the higher priority.
  214. * Like (Fast) Read capabilities, Octal/Quad SPI protocols are preferred to the
  215. * legacy SPI 1-1-1 protocol.
  216. * Note that Dual Page Programs are not supported because there is no existing
  217. * JEDEC/SFDP standard to define them. Also at this moment no SPI flash memory
  218. * implements such commands.
  219. */
  220. #define SNOR_HWCAPS_PP_MASK GENMASK(23, 16)
  221. #define SNOR_HWCAPS_PP BIT(16)
  222. #define SNOR_HWCAPS_PP_QUAD GENMASK(19, 17)
  223. #define SNOR_HWCAPS_PP_1_1_4 BIT(17)
  224. #define SNOR_HWCAPS_PP_1_4_4 BIT(18)
  225. #define SNOR_HWCAPS_PP_4_4_4 BIT(19)
  226. #define SNOR_HWCAPS_PP_OCTAL GENMASK(23, 20)
  227. #define SNOR_HWCAPS_PP_1_1_8 BIT(20)
  228. #define SNOR_HWCAPS_PP_1_8_8 BIT(21)
  229. #define SNOR_HWCAPS_PP_8_8_8 BIT(22)
  230. #define SNOR_HWCAPS_PP_8_8_8_DTR BIT(23)
  231. #define SNOR_HWCAPS_X_X_X (SNOR_HWCAPS_READ_2_2_2 | \
  232. SNOR_HWCAPS_READ_4_4_4 | \
  233. SNOR_HWCAPS_READ_8_8_8 | \
  234. SNOR_HWCAPS_PP_4_4_4 | \
  235. SNOR_HWCAPS_PP_8_8_8)
  236. #define SNOR_HWCAPS_X_X_X_DTR (SNOR_HWCAPS_READ_8_8_8_DTR | \
  237. SNOR_HWCAPS_PP_8_8_8_DTR)
  238. #define SNOR_HWCAPS_DTR (SNOR_HWCAPS_READ_1_1_1_DTR | \
  239. SNOR_HWCAPS_READ_1_2_2_DTR | \
  240. SNOR_HWCAPS_READ_1_4_4_DTR | \
  241. SNOR_HWCAPS_READ_1_8_8_DTR | \
  242. SNOR_HWCAPS_READ_8_8_8_DTR)
  243. #define SNOR_HWCAPS_ALL (SNOR_HWCAPS_READ_MASK | \
  244. SNOR_HWCAPS_PP_MASK)
  245. /* Forward declaration that is used in 'struct spi_nor_controller_ops' */
  246. struct spi_nor;
  247. /**
  248. * struct spi_nor_controller_ops - SPI NOR controller driver specific
  249. * operations.
  250. * @prepare: [OPTIONAL] do some preparations for the
  251. * read/write/erase/lock/unlock operations.
  252. * @unprepare: [OPTIONAL] do some post work after the
  253. * read/write/erase/lock/unlock operations.
  254. * @read_reg: read out the register.
  255. * @write_reg: write data to the register.
  256. * @read: read data from the SPI NOR.
  257. * @write: write data to the SPI NOR.
  258. * @erase: erase a sector of the SPI NOR at the offset @offs; if
  259. * not provided by the driver, SPI NOR will send the erase
  260. * opcode via write_reg().
  261. */
  262. struct spi_nor_controller_ops {
  263. int (*prepare)(struct spi_nor *nor);
  264. void (*unprepare)(struct spi_nor *nor);
  265. int (*read_reg)(struct spi_nor *nor, u8 opcode, u8 *buf, size_t len);
  266. int (*write_reg)(struct spi_nor *nor, u8 opcode, const u8 *buf,
  267. size_t len);
  268. ssize_t (*read)(struct spi_nor *nor, loff_t from, size_t len, u8 *buf);
  269. ssize_t (*write)(struct spi_nor *nor, loff_t to, size_t len,
  270. const u8 *buf);
  271. int (*erase)(struct spi_nor *nor, loff_t offs);
  272. };
  273. /**
  274. * enum spi_nor_cmd_ext - describes the command opcode extension in DTR mode
  275. * @SPI_NOR_EXT_NONE: no extension. This is the default, and is used in Legacy
  276. * SPI mode
  277. * @SPI_NOR_EXT_REPEAT: the extension is same as the opcode
  278. * @SPI_NOR_EXT_INVERT: the extension is the bitwise inverse of the opcode
  279. * @SPI_NOR_EXT_HEX: the extension is any hex value. The command and opcode
  280. * combine to form a 16-bit opcode.
  281. */
  282. enum spi_nor_cmd_ext {
  283. SPI_NOR_EXT_NONE = 0,
  284. SPI_NOR_EXT_REPEAT,
  285. SPI_NOR_EXT_INVERT,
  286. SPI_NOR_EXT_HEX,
  287. };
  288. /*
  289. * Forward declarations that are used internally by the core and manufacturer
  290. * drivers.
  291. */
  292. struct flash_info;
  293. struct spi_nor_manufacturer;
  294. struct spi_nor_flash_parameter;
  295. /**
  296. * struct spi_nor - Structure for defining the SPI NOR layer
  297. * @mtd: an mtd_info structure
  298. * @lock: the lock for the read/write/erase/lock/unlock operations
  299. * @dev: pointer to an SPI device or an SPI NOR controller device
  300. * @spimem: pointer to the SPI memory device
  301. * @bouncebuf: bounce buffer used when the buffer passed by the MTD
  302. * layer is not DMA-able
  303. * @bouncebuf_size: size of the bounce buffer
  304. * @info: SPI NOR part JEDEC MFR ID and other info
  305. * @manufacturer: SPI NOR manufacturer
  306. * @addr_nbytes: number of address bytes
  307. * @erase_opcode: the opcode for erasing a sector
  308. * @read_opcode: the read opcode
  309. * @read_dummy: the dummy needed by the read operation
  310. * @program_opcode: the program opcode
  311. * @sst_write_second: used by the SST write operation
  312. * @flags: flag options for the current SPI NOR (SNOR_F_*)
  313. * @cmd_ext_type: the command opcode extension type for DTR mode.
  314. * @read_proto: the SPI protocol for read operations
  315. * @write_proto: the SPI protocol for write operations
  316. * @reg_proto: the SPI protocol for read_reg/write_reg/erase operations
  317. * @sfdp: the SFDP data of the flash
  318. * @debugfs_root: pointer to the debugfs directory
  319. * @controller_ops: SPI NOR controller driver specific operations.
  320. * @params: [FLASH-SPECIFIC] SPI NOR flash parameters and settings.
  321. * The structure includes legacy flash parameters and
  322. * settings that can be overwritten by the spi_nor_fixups
  323. * hooks, or dynamically when parsing the SFDP tables.
  324. * @dirmap: pointers to struct spi_mem_dirmap_desc for reads/writes.
  325. * @priv: pointer to the private data
  326. */
  327. struct spi_nor {
  328. struct mtd_info mtd;
  329. struct mutex lock;
  330. struct device *dev;
  331. struct spi_mem *spimem;
  332. u8 *bouncebuf;
  333. size_t bouncebuf_size;
  334. const struct flash_info *info;
  335. const struct spi_nor_manufacturer *manufacturer;
  336. u8 addr_nbytes;
  337. u8 erase_opcode;
  338. u8 read_opcode;
  339. u8 read_dummy;
  340. u8 program_opcode;
  341. enum spi_nor_protocol read_proto;
  342. enum spi_nor_protocol write_proto;
  343. enum spi_nor_protocol reg_proto;
  344. bool sst_write_second;
  345. u32 flags;
  346. enum spi_nor_cmd_ext cmd_ext_type;
  347. struct sfdp *sfdp;
  348. struct dentry *debugfs_root;
  349. const struct spi_nor_controller_ops *controller_ops;
  350. struct spi_nor_flash_parameter *params;
  351. struct {
  352. struct spi_mem_dirmap_desc *rdesc;
  353. struct spi_mem_dirmap_desc *wdesc;
  354. } dirmap;
  355. void *priv;
  356. };
  357. static inline void spi_nor_set_flash_node(struct spi_nor *nor,
  358. struct device_node *np)
  359. {
  360. mtd_set_of_node(&nor->mtd, np);
  361. }
  362. static inline struct device_node *spi_nor_get_flash_node(struct spi_nor *nor)
  363. {
  364. return mtd_get_of_node(&nor->mtd);
  365. }
  366. /**
  367. * spi_nor_scan() - scan the SPI NOR
  368. * @nor: the spi_nor structure
  369. * @name: the chip type name
  370. * @hwcaps: the hardware capabilities supported by the controller driver
  371. *
  372. * The drivers can use this function to scan the SPI NOR.
  373. * In the scanning, it will try to get all the necessary information to
  374. * fill the mtd_info{} and the spi_nor{}.
  375. *
  376. * The chip type name can be provided through the @name parameter.
  377. *
  378. * Return: 0 for success, others for failure.
  379. */
  380. int spi_nor_scan(struct spi_nor *nor, const char *name,
  381. const struct spi_nor_hwcaps *hwcaps);
  382. /**
  383. * spi_nor_restore_addr_mode() - restore the status of SPI NOR
  384. * @nor: the spi_nor structure
  385. */
  386. void spi_nor_restore(struct spi_nor *nor);
  387. #endif