003-mtd-spi-nor-from-3.19.patch 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. --- a/drivers/mtd/spi-nor/spi-nor.c
  2. +++ b/drivers/mtd/spi-nor/spi-nor.c
  3. @@ -26,7 +26,38 @@
  4. /* Define max times to check status register before we give up. */
  5. #define MAX_READY_WAIT_JIFFIES (40 * HZ) /* M25P16 specs 40s max chip erase */
  6. -#define JEDEC_MFR(_jedec_id) ((_jedec_id) >> 16)
  7. +#define SPI_NOR_MAX_ID_LEN 6
  8. +
  9. +struct flash_info {
  10. + /*
  11. + * This array stores the ID bytes.
  12. + * The first three bytes are the JEDIC ID.
  13. + * JEDEC ID zero means "no ID" (mostly older chips).
  14. + */
  15. + u8 id[SPI_NOR_MAX_ID_LEN];
  16. + u8 id_len;
  17. +
  18. + /* The size listed here is what works with SPINOR_OP_SE, which isn't
  19. + * necessarily called a "sector" by the vendor.
  20. + */
  21. + unsigned sector_size;
  22. + u16 n_sectors;
  23. +
  24. + u16 page_size;
  25. + u16 addr_width;
  26. +
  27. + u16 flags;
  28. +#define SECT_4K 0x01 /* SPINOR_OP_BE_4K works uniformly */
  29. +#define SPI_NOR_NO_ERASE 0x02 /* No erase command needed */
  30. +#define SST_WRITE 0x04 /* use SST byte programming */
  31. +#define SPI_NOR_NO_FR 0x08 /* Can't do fastread */
  32. +#define SECT_4K_PMC 0x10 /* SPINOR_OP_BE_4K_PMC works uniformly */
  33. +#define SPI_NOR_DUAL_READ 0x20 /* Flash supports Dual Read */
  34. +#define SPI_NOR_QUAD_READ 0x40 /* Flash supports Quad Read */
  35. +#define USE_FSR 0x80 /* use flag status register */
  36. +};
  37. +
  38. +#define JEDEC_MFR(info) ((info)->id[0])
  39. static const struct spi_device_id *spi_nor_match_id(const char *name);
  40. @@ -98,7 +129,7 @@ static inline int spi_nor_read_dummy_cyc
  41. case SPI_NOR_FAST:
  42. case SPI_NOR_DUAL:
  43. case SPI_NOR_QUAD:
  44. - return 1;
  45. + return 8;
  46. case SPI_NOR_NORMAL:
  47. return 0;
  48. }
  49. @@ -138,13 +169,14 @@ static inline struct spi_nor *mtd_to_spi
  50. }
  51. /* Enable/disable 4-byte addressing mode. */
  52. -static inline int set_4byte(struct spi_nor *nor, u32 jedec_id, int enable)
  53. +static inline int set_4byte(struct spi_nor *nor, struct flash_info *info,
  54. + int enable)
  55. {
  56. int status;
  57. bool need_wren = false;
  58. u8 cmd;
  59. - switch (JEDEC_MFR(jedec_id)) {
  60. + switch (JEDEC_MFR(info)) {
  61. case CFI_MFR_ST: /* Micron, actually */
  62. /* Some Micron need WREN command; all will accept it */
  63. need_wren = true;
  64. @@ -165,81 +197,74 @@ static inline int set_4byte(struct spi_n
  65. return nor->write_reg(nor, SPINOR_OP_BRWR, nor->cmd_buf, 1, 0);
  66. }
  67. }
  68. -
  69. -static int spi_nor_wait_till_ready(struct spi_nor *nor)
  70. +static inline int spi_nor_sr_ready(struct spi_nor *nor)
  71. {
  72. - unsigned long deadline;
  73. - int sr;
  74. -
  75. - deadline = jiffies + MAX_READY_WAIT_JIFFIES;
  76. -
  77. - do {
  78. - cond_resched();
  79. + int sr = read_sr(nor);
  80. + if (sr < 0)
  81. + return sr;
  82. + else
  83. + return !(sr & SR_WIP);
  84. +}
  85. - sr = read_sr(nor);
  86. - if (sr < 0)
  87. - break;
  88. - else if (!(sr & SR_WIP))
  89. - return 0;
  90. - } while (!time_after_eq(jiffies, deadline));
  91. +static inline int spi_nor_fsr_ready(struct spi_nor *nor)
  92. +{
  93. + int fsr = read_fsr(nor);
  94. + if (fsr < 0)
  95. + return fsr;
  96. + else
  97. + return fsr & FSR_READY;
  98. +}
  99. - return -ETIMEDOUT;
  100. +static int spi_nor_ready(struct spi_nor *nor)
  101. +{
  102. + int sr, fsr;
  103. + sr = spi_nor_sr_ready(nor);
  104. + if (sr < 0)
  105. + return sr;
  106. + fsr = nor->flags & SNOR_F_USE_FSR ? spi_nor_fsr_ready(nor) : 1;
  107. + if (fsr < 0)
  108. + return fsr;
  109. + return sr && fsr;
  110. }
  111. -static int spi_nor_wait_till_fsr_ready(struct spi_nor *nor)
  112. +/*
  113. + * Service routine to read status register until ready, or timeout occurs.
  114. + * Returns non-zero if error.
  115. + */
  116. +static int spi_nor_wait_till_ready(struct spi_nor *nor)
  117. {
  118. unsigned long deadline;
  119. - int sr;
  120. - int fsr;
  121. + int timeout = 0, ret;
  122. deadline = jiffies + MAX_READY_WAIT_JIFFIES;
  123. - do {
  124. + while (!timeout) {
  125. + if (time_after_eq(jiffies, deadline))
  126. + timeout = 1;
  127. +
  128. + ret = spi_nor_ready(nor);
  129. + if (ret < 0)
  130. + return ret;
  131. + if (ret)
  132. + return 0;
  133. +
  134. cond_resched();
  135. + }
  136. - sr = read_sr(nor);
  137. - if (sr < 0) {
  138. - break;
  139. - } else if (!(sr & SR_WIP)) {
  140. - fsr = read_fsr(nor);
  141. - if (fsr < 0)
  142. - break;
  143. - if (fsr & FSR_READY)
  144. - return 0;
  145. - }
  146. - } while (!time_after_eq(jiffies, deadline));
  147. + dev_err(nor->dev, "flash operation timed out\n");
  148. return -ETIMEDOUT;
  149. }
  150. /*
  151. - * Service routine to read status register until ready, or timeout occurs.
  152. - * Returns non-zero if error.
  153. - */
  154. -static int wait_till_ready(struct spi_nor *nor)
  155. -{
  156. - return nor->wait_till_ready(nor);
  157. -}
  158. -
  159. -/*
  160. * Erase the whole flash memory
  161. *
  162. * Returns 0 if successful, non-zero otherwise.
  163. */
  164. static int erase_chip(struct spi_nor *nor)
  165. {
  166. - int ret;
  167. -
  168. dev_dbg(nor->dev, " %lldKiB\n", (long long)(nor->mtd->size >> 10));
  169. - /* Wait until finished previous write command. */
  170. - ret = wait_till_ready(nor);
  171. - if (ret)
  172. - return ret;
  173. -
  174. - /* Send write enable, then erase commands. */
  175. - write_enable(nor);
  176. -
  177. return nor->write_reg(nor, SPINOR_OP_CHIP_ERASE, NULL, 0, 0);
  178. }
  179. @@ -294,11 +319,17 @@ static int spi_nor_erase(struct mtd_info
  180. /* whole-chip erase? */
  181. if (len == mtd->size) {
  182. + write_enable(nor);
  183. +
  184. if (erase_chip(nor)) {
  185. ret = -EIO;
  186. goto erase_err;
  187. }
  188. + ret = spi_nor_wait_till_ready(nor);
  189. + if (ret)
  190. + goto erase_err;
  191. +
  192. /* REVISIT in some cases we could speed up erasing large regions
  193. * by using SPINOR_OP_SE instead of SPINOR_OP_BE_4K. We may have set up
  194. * to use "small sector erase", but that's not always optimal.
  195. @@ -307,6 +338,8 @@ static int spi_nor_erase(struct mtd_info
  196. /* "sector"-at-a-time erase */
  197. } else {
  198. while (len) {
  199. + write_enable(nor);
  200. +
  201. if (nor->erase(nor, addr)) {
  202. ret = -EIO;
  203. goto erase_err;
  204. @@ -314,9 +347,15 @@ static int spi_nor_erase(struct mtd_info
  205. addr += mtd->erasesize;
  206. len -= mtd->erasesize;
  207. +
  208. + ret = spi_nor_wait_till_ready(nor);
  209. + if (ret)
  210. + goto erase_err;
  211. }
  212. }
  213. + write_disable(nor);
  214. +
  215. spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_ERASE);
  216. instr->state = MTD_ERASE_DONE;
  217. @@ -341,11 +380,6 @@ static int spi_nor_lock(struct mtd_info
  218. if (ret)
  219. return ret;
  220. - /* Wait until finished previous command */
  221. - ret = wait_till_ready(nor);
  222. - if (ret)
  223. - goto err;
  224. -
  225. status_old = read_sr(nor);
  226. if (offset < mtd->size - (mtd->size / 2))
  227. @@ -388,11 +422,6 @@ static int spi_nor_unlock(struct mtd_inf
  228. if (ret)
  229. return ret;
  230. - /* Wait until finished previous command */
  231. - ret = wait_till_ready(nor);
  232. - if (ret)
  233. - goto err;
  234. -
  235. status_old = read_sr(nor);
  236. if (offset+len > mtd->size - (mtd->size / 64))
  237. @@ -424,38 +453,34 @@ err:
  238. return ret;
  239. }
  240. -struct flash_info {
  241. - /* JEDEC id zero means "no ID" (most older chips); otherwise it has
  242. - * a high byte of zero plus three data bytes: the manufacturer id,
  243. - * then a two byte device id.
  244. - */
  245. - u32 jedec_id;
  246. - u16 ext_id;
  247. -
  248. - /* The size listed here is what works with SPINOR_OP_SE, which isn't
  249. - * necessarily called a "sector" by the vendor.
  250. - */
  251. - unsigned sector_size;
  252. - u16 n_sectors;
  253. -
  254. - u16 page_size;
  255. - u16 addr_width;
  256. -
  257. - u16 flags;
  258. -#define SECT_4K 0x01 /* SPINOR_OP_BE_4K works uniformly */
  259. -#define SPI_NOR_NO_ERASE 0x02 /* No erase command needed */
  260. -#define SST_WRITE 0x04 /* use SST byte programming */
  261. -#define SPI_NOR_NO_FR 0x08 /* Can't do fastread */
  262. -#define SECT_4K_PMC 0x10 /* SPINOR_OP_BE_4K_PMC works uniformly */
  263. -#define SPI_NOR_DUAL_READ 0x20 /* Flash supports Dual Read */
  264. -#define SPI_NOR_QUAD_READ 0x40 /* Flash supports Quad Read */
  265. -#define USE_FSR 0x80 /* use flag status register */
  266. -};
  267. -
  268. +/* Used when the "_ext_id" is two bytes at most */
  269. #define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors, _flags) \
  270. ((kernel_ulong_t)&(struct flash_info) { \
  271. - .jedec_id = (_jedec_id), \
  272. - .ext_id = (_ext_id), \
  273. + .id = { \
  274. + ((_jedec_id) >> 16) & 0xff, \
  275. + ((_jedec_id) >> 8) & 0xff, \
  276. + (_jedec_id) & 0xff, \
  277. + ((_ext_id) >> 8) & 0xff, \
  278. + (_ext_id) & 0xff, \
  279. + }, \
  280. + .id_len = (!(_jedec_id) ? 0 : (3 + ((_ext_id) ? 2 : 0))), \
  281. + .sector_size = (_sector_size), \
  282. + .n_sectors = (_n_sectors), \
  283. + .page_size = 256, \
  284. + .flags = (_flags), \
  285. + })
  286. +
  287. +#define INFO6(_jedec_id, _ext_id, _sector_size, _n_sectors, _flags) \
  288. + ((kernel_ulong_t)&(struct flash_info) { \
  289. + .id = { \
  290. + ((_jedec_id) >> 16) & 0xff, \
  291. + ((_jedec_id) >> 8) & 0xff, \
  292. + (_jedec_id) & 0xff, \
  293. + ((_ext_id) >> 16) & 0xff, \
  294. + ((_ext_id) >> 8) & 0xff, \
  295. + (_ext_id) & 0xff, \
  296. + }, \
  297. + .id_len = 6, \
  298. .sector_size = (_sector_size), \
  299. .n_sectors = (_n_sectors), \
  300. .page_size = 256, \
  301. @@ -507,6 +532,9 @@ static const struct spi_device_id spi_no
  302. { "mr25h256", CAT25_INFO( 32 * 1024, 1, 256, 2, SPI_NOR_NO_ERASE | SPI_NOR_NO_FR) },
  303. { "mr25h10", CAT25_INFO(128 * 1024, 1, 256, 3, SPI_NOR_NO_ERASE | SPI_NOR_NO_FR) },
  304. + /* Fujitsu */
  305. + { "mb85rs1mt", INFO(0x047f27, 0, 128 * 1024, 1, SPI_NOR_NO_ERASE) },
  306. +
  307. /* GigaDevice */
  308. { "gd25q32", INFO(0xc84016, 0, 64 * 1024, 64, SECT_4K) },
  309. { "gd25q64", INFO(0xc84017, 0, 64 * 1024, 128, SECT_4K) },
  310. @@ -537,6 +565,7 @@ static const struct spi_device_id spi_no
  311. { "mx66l1g55g", INFO(0xc2261b, 0, 64 * 1024, 2048, SPI_NOR_QUAD_READ) },
  312. /* Micron */
  313. + { "n25q032", INFO(0x20ba16, 0, 64 * 1024, 64, 0) },
  314. { "n25q064", INFO(0x20ba17, 0, 64 * 1024, 128, 0) },
  315. { "n25q128a11", INFO(0x20bb18, 0, 64 * 1024, 256, 0) },
  316. { "n25q128a13", INFO(0x20ba18, 0, 64 * 1024, 256, 0) },
  317. @@ -561,6 +590,7 @@ static const struct spi_device_id spi_no
  318. { "s70fl01gs", INFO(0x010221, 0x4d00, 256 * 1024, 256, 0) },
  319. { "s25sl12800", INFO(0x012018, 0x0300, 256 * 1024, 64, 0) },
  320. { "s25sl12801", INFO(0x012018, 0x0301, 64 * 1024, 256, 0) },
  321. + { "s25fl128s", INFO6(0x012018, 0x4d0180, 64 * 1024, 256, SPI_NOR_QUAD_READ) },
  322. { "s25fl129p0", INFO(0x012018, 0x4d00, 256 * 1024, 64, 0) },
  323. { "s25fl129p1", INFO(0x012018, 0x4d01, 64 * 1024, 256, 0) },
  324. { "s25sl004a", INFO(0x010212, 0, 64 * 1024, 8, 0) },
  325. @@ -582,6 +612,7 @@ static const struct spi_device_id spi_no
  326. { "sst25wf010", INFO(0xbf2502, 0, 64 * 1024, 2, SECT_4K | SST_WRITE) },
  327. { "sst25wf020", INFO(0xbf2503, 0, 64 * 1024, 4, SECT_4K | SST_WRITE) },
  328. { "sst25wf040", INFO(0xbf2504, 0, 64 * 1024, 8, SECT_4K | SST_WRITE) },
  329. + { "sst25wf080", INFO(0xbf2505, 0, 64 * 1024, 16, SECT_4K | SST_WRITE) },
  330. /* ST Microelectronics -- newer production may have feature updates */
  331. { "m25p05", INFO(0x202010, 0, 32 * 1024, 2, 0) },
  332. @@ -593,7 +624,6 @@ static const struct spi_device_id spi_no
  333. { "m25p32", INFO(0x202016, 0, 64 * 1024, 64, 0) },
  334. { "m25p64", INFO(0x202017, 0, 64 * 1024, 128, 0) },
  335. { "m25p128", INFO(0x202018, 0, 256 * 1024, 64, 0) },
  336. - { "n25q032", INFO(0x20ba16, 0, 64 * 1024, 64, 0) },
  337. { "m25p05-nonjedec", INFO(0, 0, 32 * 1024, 2, 0) },
  338. { "m25p10-nonjedec", INFO(0, 0, 32 * 1024, 4, 0) },
  339. @@ -649,32 +679,24 @@ static const struct spi_device_id spi_no
  340. static const struct spi_device_id *spi_nor_read_id(struct spi_nor *nor)
  341. {
  342. int tmp;
  343. - u8 id[5];
  344. - u32 jedec;
  345. - u16 ext_jedec;
  346. + u8 id[SPI_NOR_MAX_ID_LEN];
  347. struct flash_info *info;
  348. - tmp = nor->read_reg(nor, SPINOR_OP_RDID, id, 5);
  349. + tmp = nor->read_reg(nor, SPINOR_OP_RDID, id, SPI_NOR_MAX_ID_LEN);
  350. if (tmp < 0) {
  351. dev_dbg(nor->dev, " error %d reading JEDEC ID\n", tmp);
  352. return ERR_PTR(tmp);
  353. }
  354. - jedec = id[0];
  355. - jedec = jedec << 8;
  356. - jedec |= id[1];
  357. - jedec = jedec << 8;
  358. - jedec |= id[2];
  359. -
  360. - ext_jedec = id[3] << 8 | id[4];
  361. for (tmp = 0; tmp < ARRAY_SIZE(spi_nor_ids) - 1; tmp++) {
  362. info = (void *)spi_nor_ids[tmp].driver_data;
  363. - if (info->jedec_id == jedec) {
  364. - if (info->ext_id == 0 || info->ext_id == ext_jedec)
  365. + if (info->id_len) {
  366. + if (!memcmp(info->id, id, info->id_len))
  367. return &spi_nor_ids[tmp];
  368. }
  369. }
  370. - dev_err(nor->dev, "unrecognized JEDEC id %06x\n", jedec);
  371. + dev_err(nor->dev, "unrecognized JEDEC id bytes: %02x, %2x, %2x\n",
  372. + id[0], id[1], id[2]);
  373. return ERR_PTR(-ENODEV);
  374. }
  375. @@ -709,11 +731,6 @@ static int sst_write(struct mtd_info *mt
  376. if (ret)
  377. return ret;
  378. - /* Wait until finished previous write command. */
  379. - ret = wait_till_ready(nor);
  380. - if (ret)
  381. - goto time_out;
  382. -
  383. write_enable(nor);
  384. nor->sst_write_second = false;
  385. @@ -725,7 +742,7 @@ static int sst_write(struct mtd_info *mt
  386. /* write one byte. */
  387. nor->write(nor, to, 1, retlen, buf);
  388. - ret = wait_till_ready(nor);
  389. + ret = spi_nor_wait_till_ready(nor);
  390. if (ret)
  391. goto time_out;
  392. }
  393. @@ -737,7 +754,7 @@ static int sst_write(struct mtd_info *mt
  394. /* write two bytes. */
  395. nor->write(nor, to, 2, retlen, buf + actual);
  396. - ret = wait_till_ready(nor);
  397. + ret = spi_nor_wait_till_ready(nor);
  398. if (ret)
  399. goto time_out;
  400. to += 2;
  401. @@ -746,7 +763,7 @@ static int sst_write(struct mtd_info *mt
  402. nor->sst_write_second = false;
  403. write_disable(nor);
  404. - ret = wait_till_ready(nor);
  405. + ret = spi_nor_wait_till_ready(nor);
  406. if (ret)
  407. goto time_out;
  408. @@ -757,7 +774,7 @@ static int sst_write(struct mtd_info *mt
  409. nor->program_opcode = SPINOR_OP_BP;
  410. nor->write(nor, to, 1, retlen, buf + actual);
  411. - ret = wait_till_ready(nor);
  412. + ret = spi_nor_wait_till_ready(nor);
  413. if (ret)
  414. goto time_out;
  415. write_disable(nor);
  416. @@ -785,11 +802,6 @@ static int spi_nor_write(struct mtd_info
  417. if (ret)
  418. return ret;
  419. - /* Wait until finished previous write command. */
  420. - ret = wait_till_ready(nor);
  421. - if (ret)
  422. - goto write_err;
  423. -
  424. write_enable(nor);
  425. page_offset = to & (nor->page_size - 1);
  426. @@ -808,16 +820,20 @@ static int spi_nor_write(struct mtd_info
  427. if (page_size > nor->page_size)
  428. page_size = nor->page_size;
  429. - wait_till_ready(nor);
  430. + ret = spi_nor_wait_till_ready(nor);
  431. + if (ret)
  432. + goto write_err;
  433. +
  434. write_enable(nor);
  435. nor->write(nor, to + i, page_size, retlen, buf + i);
  436. }
  437. }
  438. + ret = spi_nor_wait_till_ready(nor);
  439. write_err:
  440. spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_WRITE);
  441. - return 0;
  442. + return ret;
  443. }
  444. static int macronix_quad_enable(struct spi_nor *nor)
  445. @@ -830,7 +846,7 @@ static int macronix_quad_enable(struct s
  446. nor->cmd_buf[0] = val | SR_QUAD_EN_MX;
  447. nor->write_reg(nor, SPINOR_OP_WRSR, nor->cmd_buf, 1, 0);
  448. - if (wait_till_ready(nor))
  449. + if (spi_nor_wait_till_ready(nor))
  450. return 1;
  451. ret = read_sr(nor);
  452. @@ -887,11 +903,11 @@ static int spansion_quad_enable(struct s
  453. return 0;
  454. }
  455. -static int set_quad_mode(struct spi_nor *nor, u32 jedec_id)
  456. +static int set_quad_mode(struct spi_nor *nor, struct flash_info *info)
  457. {
  458. int status;
  459. - switch (JEDEC_MFR(jedec_id)) {
  460. + switch (JEDEC_MFR(info)) {
  461. case CFI_MFR_MACRONIX:
  462. status = macronix_quad_enable(nor);
  463. if (status) {
  464. @@ -917,11 +933,6 @@ static int spi_nor_check(struct spi_nor
  465. return -EINVAL;
  466. }
  467. - if (!nor->read_id)
  468. - nor->read_id = spi_nor_read_id;
  469. - if (!nor->wait_till_ready)
  470. - nor->wait_till_ready = spi_nor_wait_till_ready;
  471. -
  472. return 0;
  473. }
  474. @@ -939,16 +950,24 @@ int spi_nor_scan(struct spi_nor *nor, co
  475. if (ret)
  476. return ret;
  477. - id = spi_nor_match_id(name);
  478. - if (!id)
  479. + /* Try to auto-detect if chip name wasn't specified */
  480. + if (!name)
  481. + id = spi_nor_read_id(nor);
  482. + else
  483. + id = spi_nor_match_id(name);
  484. + if (IS_ERR_OR_NULL(id))
  485. return -ENOENT;
  486. info = (void *)id->driver_data;
  487. - if (info->jedec_id) {
  488. + /*
  489. + * If caller has specified name of flash model that can normally be
  490. + * detected using JEDEC, let's verify it.
  491. + */
  492. + if (name && info->id_len) {
  493. const struct spi_device_id *jid;
  494. - jid = nor->read_id(nor);
  495. + jid = spi_nor_read_id(nor);
  496. if (IS_ERR(jid)) {
  497. return PTR_ERR(jid);
  498. } else if (jid != id) {
  499. @@ -973,10 +992,10 @@ int spi_nor_scan(struct spi_nor *nor, co
  500. * up with the software protection bits set
  501. */
  502. - if (JEDEC_MFR(info->jedec_id) == CFI_MFR_ATMEL ||
  503. - JEDEC_MFR(info->jedec_id) == CFI_MFR_INTEL ||
  504. - JEDEC_MFR(info->jedec_id) == CFI_MFR_MACRONIX ||
  505. - JEDEC_MFR(info->jedec_id) == CFI_MFR_SST) {
  506. + if (JEDEC_MFR(info) == CFI_MFR_ATMEL ||
  507. + JEDEC_MFR(info) == CFI_MFR_INTEL ||
  508. + JEDEC_MFR(info) == CFI_MFR_MACRONIX ||
  509. + JEDEC_MFR(info) == CFI_MFR_SST) {
  510. write_enable(nor);
  511. write_sr(nor, 0);
  512. }
  513. @@ -991,7 +1010,7 @@ int spi_nor_scan(struct spi_nor *nor, co
  514. mtd->_read = spi_nor_read;
  515. /* nor protection support for STmicro chips */
  516. - if (JEDEC_MFR(info->jedec_id) == CFI_MFR_ST) {
  517. + if (JEDEC_MFR(info) == CFI_MFR_ST) {
  518. mtd->_lock = spi_nor_lock;
  519. mtd->_unlock = spi_nor_unlock;
  520. }
  521. @@ -1002,9 +1021,8 @@ int spi_nor_scan(struct spi_nor *nor, co
  522. else
  523. mtd->_write = spi_nor_write;
  524. - if ((info->flags & USE_FSR) &&
  525. - nor->wait_till_ready == spi_nor_wait_till_ready)
  526. - nor->wait_till_ready = spi_nor_wait_till_fsr_ready;
  527. + if (info->flags & USE_FSR)
  528. + nor->flags |= SNOR_F_USE_FSR;
  529. #ifdef CONFIG_MTD_SPI_NOR_USE_4K_SECTORS
  530. /* prefer "small sector" erase if possible */
  531. @@ -1045,7 +1063,7 @@ int spi_nor_scan(struct spi_nor *nor, co
  532. /* Quad/Dual-read mode takes precedence over fast/normal */
  533. if (mode == SPI_NOR_QUAD && info->flags & SPI_NOR_QUAD_READ) {
  534. - ret = set_quad_mode(nor, info->jedec_id);
  535. + ret = set_quad_mode(nor, info);
  536. if (ret) {
  537. dev_err(dev, "quad mode not supported\n");
  538. return ret;
  539. @@ -1081,7 +1099,7 @@ int spi_nor_scan(struct spi_nor *nor, co
  540. else if (mtd->size > 0x1000000) {
  541. /* enable 4-byte addressing if the device exceeds 16MiB */
  542. nor->addr_width = 4;
  543. - if (JEDEC_MFR(info->jedec_id) == CFI_MFR_AMD) {
  544. + if (JEDEC_MFR(info) == CFI_MFR_AMD) {
  545. /* Dedicated 4-byte command set */
  546. switch (nor->flash_read) {
  547. case SPI_NOR_QUAD:
  548. @@ -1102,7 +1120,7 @@ int spi_nor_scan(struct spi_nor *nor, co
  549. nor->erase_opcode = SPINOR_OP_SE_4B;
  550. mtd->erasesize = info->sector_size;
  551. } else
  552. - set_4byte(nor, info->jedec_id, 1);
  553. + set_4byte(nor, info, 1);
  554. } else {
  555. nor->addr_width = 3;
  556. }
  557. --- a/include/linux/mtd/spi-nor.h
  558. +++ b/include/linux/mtd/spi-nor.h
  559. @@ -116,6 +116,10 @@ enum spi_nor_ops {
  560. SPI_NOR_OPS_UNLOCK,
  561. };
  562. +enum spi_nor_option_flags {
  563. + SNOR_F_USE_FSR = BIT(0),
  564. +};
  565. +
  566. /**
  567. * struct spi_nor - Structure for defining a the SPI NOR layer
  568. * @mtd: point to a mtd_info structure
  569. @@ -129,6 +133,7 @@ enum spi_nor_ops {
  570. * @program_opcode: the program opcode
  571. * @flash_read: the mode of the read
  572. * @sst_write_second: used by the SST write operation
  573. + * @flags: flag options for the current SPI-NOR (SNOR_F_*)
  574. * @cfg: used by the read_xfer/write_xfer
  575. * @cmd_buf: used by the write_reg
  576. * @prepare: [OPTIONAL] do some preparations for the
  577. @@ -139,9 +144,6 @@ enum spi_nor_ops {
  578. * @write_xfer: [OPTIONAL] the writefundamental primitive
  579. * @read_reg: [DRIVER-SPECIFIC] read out the register
  580. * @write_reg: [DRIVER-SPECIFIC] write data to the register
  581. - * @read_id: [REPLACEABLE] read out the ID data, and find
  582. - * the proper spi_device_id
  583. - * @wait_till_ready: [REPLACEABLE] wait till the NOR becomes ready
  584. * @read: [DRIVER-SPECIFIC] read data from the SPI NOR
  585. * @write: [DRIVER-SPECIFIC] write data to the SPI NOR
  586. * @erase: [DRIVER-SPECIFIC] erase a sector of the SPI NOR
  587. @@ -160,6 +162,7 @@ struct spi_nor {
  588. u8 program_opcode;
  589. enum read_mode flash_read;
  590. bool sst_write_second;
  591. + u32 flags;
  592. struct spi_nor_xfer_cfg cfg;
  593. u8 cmd_buf[SPI_NOR_MAX_CMD_SIZE];
  594. @@ -172,8 +175,6 @@ struct spi_nor {
  595. int (*read_reg)(struct spi_nor *nor, u8 opcode, u8 *buf, int len);
  596. int (*write_reg)(struct spi_nor *nor, u8 opcode, u8 *buf, int len,
  597. int write_enable);
  598. - const struct spi_device_id *(*read_id)(struct spi_nor *nor);
  599. - int (*wait_till_ready)(struct spi_nor *nor);
  600. int (*read)(struct spi_nor *nor, loff_t from,
  601. size_t len, size_t *retlen, u_char *read_buf);