nand_legacy.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2000 Steven J. Hill ([email protected])
  4. * 2002-2006 Thomas Gleixner ([email protected])
  5. *
  6. * Credits:
  7. * David Woodhouse for adding multichip support
  8. *
  9. * Aleph One Ltd. and Toby Churchill Ltd. for supporting the
  10. * rework for 2K page size chips
  11. *
  12. * This file contains all legacy helpers/code that should be removed
  13. * at some point.
  14. */
  15. #include <linux/delay.h>
  16. #include <linux/io.h>
  17. #include <linux/nmi.h>
  18. #include "internals.h"
  19. /**
  20. * nand_read_byte - [DEFAULT] read one byte from the chip
  21. * @chip: NAND chip object
  22. *
  23. * Default read function for 8bit buswidth
  24. */
  25. static uint8_t nand_read_byte(struct nand_chip *chip)
  26. {
  27. return readb(chip->legacy.IO_ADDR_R);
  28. }
  29. /**
  30. * nand_read_byte16 - [DEFAULT] read one byte endianness aware from the chip
  31. * @chip: NAND chip object
  32. *
  33. * Default read function for 16bit buswidth with endianness conversion.
  34. *
  35. */
  36. static uint8_t nand_read_byte16(struct nand_chip *chip)
  37. {
  38. return (uint8_t) cpu_to_le16(readw(chip->legacy.IO_ADDR_R));
  39. }
  40. /**
  41. * nand_select_chip - [DEFAULT] control CE line
  42. * @chip: NAND chip object
  43. * @chipnr: chipnumber to select, -1 for deselect
  44. *
  45. * Default select function for 1 chip devices.
  46. */
  47. static void nand_select_chip(struct nand_chip *chip, int chipnr)
  48. {
  49. switch (chipnr) {
  50. case -1:
  51. chip->legacy.cmd_ctrl(chip, NAND_CMD_NONE,
  52. 0 | NAND_CTRL_CHANGE);
  53. break;
  54. case 0:
  55. break;
  56. default:
  57. BUG();
  58. }
  59. }
  60. /**
  61. * nand_write_byte - [DEFAULT] write single byte to chip
  62. * @chip: NAND chip object
  63. * @byte: value to write
  64. *
  65. * Default function to write a byte to I/O[7:0]
  66. */
  67. static void nand_write_byte(struct nand_chip *chip, uint8_t byte)
  68. {
  69. chip->legacy.write_buf(chip, &byte, 1);
  70. }
  71. /**
  72. * nand_write_byte16 - [DEFAULT] write single byte to a chip with width 16
  73. * @chip: NAND chip object
  74. * @byte: value to write
  75. *
  76. * Default function to write a byte to I/O[7:0] on a 16-bit wide chip.
  77. */
  78. static void nand_write_byte16(struct nand_chip *chip, uint8_t byte)
  79. {
  80. uint16_t word = byte;
  81. /*
  82. * It's not entirely clear what should happen to I/O[15:8] when writing
  83. * a byte. The ONFi spec (Revision 3.1; 2012-09-19, Section 2.16) reads:
  84. *
  85. * When the host supports a 16-bit bus width, only data is
  86. * transferred at the 16-bit width. All address and command line
  87. * transfers shall use only the lower 8-bits of the data bus. During
  88. * command transfers, the host may place any value on the upper
  89. * 8-bits of the data bus. During address transfers, the host shall
  90. * set the upper 8-bits of the data bus to 00h.
  91. *
  92. * One user of the write_byte callback is nand_set_features. The
  93. * four parameters are specified to be written to I/O[7:0], but this is
  94. * neither an address nor a command transfer. Let's assume a 0 on the
  95. * upper I/O lines is OK.
  96. */
  97. chip->legacy.write_buf(chip, (uint8_t *)&word, 2);
  98. }
  99. /**
  100. * nand_write_buf - [DEFAULT] write buffer to chip
  101. * @chip: NAND chip object
  102. * @buf: data buffer
  103. * @len: number of bytes to write
  104. *
  105. * Default write function for 8bit buswidth.
  106. */
  107. static void nand_write_buf(struct nand_chip *chip, const uint8_t *buf, int len)
  108. {
  109. iowrite8_rep(chip->legacy.IO_ADDR_W, buf, len);
  110. }
  111. /**
  112. * nand_read_buf - [DEFAULT] read chip data into buffer
  113. * @chip: NAND chip object
  114. * @buf: buffer to store date
  115. * @len: number of bytes to read
  116. *
  117. * Default read function for 8bit buswidth.
  118. */
  119. static void nand_read_buf(struct nand_chip *chip, uint8_t *buf, int len)
  120. {
  121. ioread8_rep(chip->legacy.IO_ADDR_R, buf, len);
  122. }
  123. /**
  124. * nand_write_buf16 - [DEFAULT] write buffer to chip
  125. * @chip: NAND chip object
  126. * @buf: data buffer
  127. * @len: number of bytes to write
  128. *
  129. * Default write function for 16bit buswidth.
  130. */
  131. static void nand_write_buf16(struct nand_chip *chip, const uint8_t *buf,
  132. int len)
  133. {
  134. u16 *p = (u16 *) buf;
  135. iowrite16_rep(chip->legacy.IO_ADDR_W, p, len >> 1);
  136. }
  137. /**
  138. * nand_read_buf16 - [DEFAULT] read chip data into buffer
  139. * @chip: NAND chip object
  140. * @buf: buffer to store date
  141. * @len: number of bytes to read
  142. *
  143. * Default read function for 16bit buswidth.
  144. */
  145. static void nand_read_buf16(struct nand_chip *chip, uint8_t *buf, int len)
  146. {
  147. u16 *p = (u16 *) buf;
  148. ioread16_rep(chip->legacy.IO_ADDR_R, p, len >> 1);
  149. }
  150. /**
  151. * panic_nand_wait_ready - [GENERIC] Wait for the ready pin after commands.
  152. * @chip: NAND chip object
  153. * @timeo: Timeout
  154. *
  155. * Helper function for nand_wait_ready used when needing to wait in interrupt
  156. * context.
  157. */
  158. static void panic_nand_wait_ready(struct nand_chip *chip, unsigned long timeo)
  159. {
  160. int i;
  161. /* Wait for the device to get ready */
  162. for (i = 0; i < timeo; i++) {
  163. if (chip->legacy.dev_ready(chip))
  164. break;
  165. touch_softlockup_watchdog();
  166. mdelay(1);
  167. }
  168. }
  169. /**
  170. * nand_wait_ready - [GENERIC] Wait for the ready pin after commands.
  171. * @chip: NAND chip object
  172. *
  173. * Wait for the ready pin after a command, and warn if a timeout occurs.
  174. */
  175. void nand_wait_ready(struct nand_chip *chip)
  176. {
  177. struct mtd_info *mtd = nand_to_mtd(chip);
  178. unsigned long timeo = 400;
  179. if (mtd->oops_panic_write)
  180. return panic_nand_wait_ready(chip, timeo);
  181. /* Wait until command is processed or timeout occurs */
  182. timeo = jiffies + msecs_to_jiffies(timeo);
  183. do {
  184. if (chip->legacy.dev_ready(chip))
  185. return;
  186. cond_resched();
  187. } while (time_before(jiffies, timeo));
  188. if (!chip->legacy.dev_ready(chip))
  189. pr_warn_ratelimited("timeout while waiting for chip to become ready\n");
  190. }
  191. EXPORT_SYMBOL_GPL(nand_wait_ready);
  192. /**
  193. * nand_wait_status_ready - [GENERIC] Wait for the ready status after commands.
  194. * @chip: NAND chip object
  195. * @timeo: Timeout in ms
  196. *
  197. * Wait for status ready (i.e. command done) or timeout.
  198. */
  199. static void nand_wait_status_ready(struct nand_chip *chip, unsigned long timeo)
  200. {
  201. int ret;
  202. timeo = jiffies + msecs_to_jiffies(timeo);
  203. do {
  204. u8 status;
  205. ret = nand_read_data_op(chip, &status, sizeof(status), true,
  206. false);
  207. if (ret)
  208. return;
  209. if (status & NAND_STATUS_READY)
  210. break;
  211. touch_softlockup_watchdog();
  212. } while (time_before(jiffies, timeo));
  213. };
  214. /**
  215. * nand_command - [DEFAULT] Send command to NAND device
  216. * @chip: NAND chip object
  217. * @command: the command to be sent
  218. * @column: the column address for this command, -1 if none
  219. * @page_addr: the page address for this command, -1 if none
  220. *
  221. * Send command to NAND device. This function is used for small page devices
  222. * (512 Bytes per page).
  223. */
  224. static void nand_command(struct nand_chip *chip, unsigned int command,
  225. int column, int page_addr)
  226. {
  227. struct mtd_info *mtd = nand_to_mtd(chip);
  228. int ctrl = NAND_CTRL_CLE | NAND_CTRL_CHANGE;
  229. /* Write out the command to the device */
  230. if (command == NAND_CMD_SEQIN) {
  231. int readcmd;
  232. if (column >= mtd->writesize) {
  233. /* OOB area */
  234. column -= mtd->writesize;
  235. readcmd = NAND_CMD_READOOB;
  236. } else if (column < 256) {
  237. /* First 256 bytes --> READ0 */
  238. readcmd = NAND_CMD_READ0;
  239. } else {
  240. column -= 256;
  241. readcmd = NAND_CMD_READ1;
  242. }
  243. chip->legacy.cmd_ctrl(chip, readcmd, ctrl);
  244. ctrl &= ~NAND_CTRL_CHANGE;
  245. }
  246. if (command != NAND_CMD_NONE)
  247. chip->legacy.cmd_ctrl(chip, command, ctrl);
  248. /* Address cycle, when necessary */
  249. ctrl = NAND_CTRL_ALE | NAND_CTRL_CHANGE;
  250. /* Serially input address */
  251. if (column != -1) {
  252. /* Adjust columns for 16 bit buswidth */
  253. if (chip->options & NAND_BUSWIDTH_16 &&
  254. !nand_opcode_8bits(command))
  255. column >>= 1;
  256. chip->legacy.cmd_ctrl(chip, column, ctrl);
  257. ctrl &= ~NAND_CTRL_CHANGE;
  258. }
  259. if (page_addr != -1) {
  260. chip->legacy.cmd_ctrl(chip, page_addr, ctrl);
  261. ctrl &= ~NAND_CTRL_CHANGE;
  262. chip->legacy.cmd_ctrl(chip, page_addr >> 8, ctrl);
  263. if (chip->options & NAND_ROW_ADDR_3)
  264. chip->legacy.cmd_ctrl(chip, page_addr >> 16, ctrl);
  265. }
  266. chip->legacy.cmd_ctrl(chip, NAND_CMD_NONE,
  267. NAND_NCE | NAND_CTRL_CHANGE);
  268. /*
  269. * Program and erase have their own busy handlers status and sequential
  270. * in needs no delay
  271. */
  272. switch (command) {
  273. case NAND_CMD_NONE:
  274. case NAND_CMD_PAGEPROG:
  275. case NAND_CMD_ERASE1:
  276. case NAND_CMD_ERASE2:
  277. case NAND_CMD_SEQIN:
  278. case NAND_CMD_STATUS:
  279. case NAND_CMD_READID:
  280. case NAND_CMD_SET_FEATURES:
  281. return;
  282. case NAND_CMD_RESET:
  283. if (chip->legacy.dev_ready)
  284. break;
  285. udelay(chip->legacy.chip_delay);
  286. chip->legacy.cmd_ctrl(chip, NAND_CMD_STATUS,
  287. NAND_CTRL_CLE | NAND_CTRL_CHANGE);
  288. chip->legacy.cmd_ctrl(chip, NAND_CMD_NONE,
  289. NAND_NCE | NAND_CTRL_CHANGE);
  290. /* EZ-NAND can take upto 250ms as per ONFi v4.0 */
  291. nand_wait_status_ready(chip, 250);
  292. return;
  293. /* This applies to read commands */
  294. case NAND_CMD_READ0:
  295. /*
  296. * READ0 is sometimes used to exit GET STATUS mode. When this
  297. * is the case no address cycles are requested, and we can use
  298. * this information to detect that we should not wait for the
  299. * device to be ready.
  300. */
  301. if (column == -1 && page_addr == -1)
  302. return;
  303. fallthrough;
  304. default:
  305. /*
  306. * If we don't have access to the busy pin, we apply the given
  307. * command delay
  308. */
  309. if (!chip->legacy.dev_ready) {
  310. udelay(chip->legacy.chip_delay);
  311. return;
  312. }
  313. }
  314. /*
  315. * Apply this short delay always to ensure that we do wait tWB in
  316. * any case on any machine.
  317. */
  318. ndelay(100);
  319. nand_wait_ready(chip);
  320. }
  321. static void nand_ccs_delay(struct nand_chip *chip)
  322. {
  323. const struct nand_sdr_timings *sdr =
  324. nand_get_sdr_timings(nand_get_interface_config(chip));
  325. /*
  326. * The controller already takes care of waiting for tCCS when the RNDIN
  327. * or RNDOUT command is sent, return directly.
  328. */
  329. if (!(chip->options & NAND_WAIT_TCCS))
  330. return;
  331. /*
  332. * Wait tCCS_min if it is correctly defined, otherwise wait 500ns
  333. * (which should be safe for all NANDs).
  334. */
  335. if (!IS_ERR(sdr) && nand_controller_can_setup_interface(chip))
  336. ndelay(sdr->tCCS_min / 1000);
  337. else
  338. ndelay(500);
  339. }
  340. /**
  341. * nand_command_lp - [DEFAULT] Send command to NAND large page device
  342. * @chip: NAND chip object
  343. * @command: the command to be sent
  344. * @column: the column address for this command, -1 if none
  345. * @page_addr: the page address for this command, -1 if none
  346. *
  347. * Send command to NAND device. This is the version for the new large page
  348. * devices. We don't have the separate regions as we have in the small page
  349. * devices. We must emulate NAND_CMD_READOOB to keep the code compatible.
  350. */
  351. static void nand_command_lp(struct nand_chip *chip, unsigned int command,
  352. int column, int page_addr)
  353. {
  354. struct mtd_info *mtd = nand_to_mtd(chip);
  355. /* Emulate NAND_CMD_READOOB */
  356. if (command == NAND_CMD_READOOB) {
  357. column += mtd->writesize;
  358. command = NAND_CMD_READ0;
  359. }
  360. /* Command latch cycle */
  361. if (command != NAND_CMD_NONE)
  362. chip->legacy.cmd_ctrl(chip, command,
  363. NAND_NCE | NAND_CLE | NAND_CTRL_CHANGE);
  364. if (column != -1 || page_addr != -1) {
  365. int ctrl = NAND_CTRL_CHANGE | NAND_NCE | NAND_ALE;
  366. /* Serially input address */
  367. if (column != -1) {
  368. /* Adjust columns for 16 bit buswidth */
  369. if (chip->options & NAND_BUSWIDTH_16 &&
  370. !nand_opcode_8bits(command))
  371. column >>= 1;
  372. chip->legacy.cmd_ctrl(chip, column, ctrl);
  373. ctrl &= ~NAND_CTRL_CHANGE;
  374. /* Only output a single addr cycle for 8bits opcodes. */
  375. if (!nand_opcode_8bits(command))
  376. chip->legacy.cmd_ctrl(chip, column >> 8, ctrl);
  377. }
  378. if (page_addr != -1) {
  379. chip->legacy.cmd_ctrl(chip, page_addr, ctrl);
  380. chip->legacy.cmd_ctrl(chip, page_addr >> 8,
  381. NAND_NCE | NAND_ALE);
  382. if (chip->options & NAND_ROW_ADDR_3)
  383. chip->legacy.cmd_ctrl(chip, page_addr >> 16,
  384. NAND_NCE | NAND_ALE);
  385. }
  386. }
  387. chip->legacy.cmd_ctrl(chip, NAND_CMD_NONE,
  388. NAND_NCE | NAND_CTRL_CHANGE);
  389. /*
  390. * Program and erase have their own busy handlers status, sequential
  391. * in and status need no delay.
  392. */
  393. switch (command) {
  394. case NAND_CMD_NONE:
  395. case NAND_CMD_CACHEDPROG:
  396. case NAND_CMD_PAGEPROG:
  397. case NAND_CMD_ERASE1:
  398. case NAND_CMD_ERASE2:
  399. case NAND_CMD_SEQIN:
  400. case NAND_CMD_STATUS:
  401. case NAND_CMD_READID:
  402. case NAND_CMD_SET_FEATURES:
  403. return;
  404. case NAND_CMD_RNDIN:
  405. nand_ccs_delay(chip);
  406. return;
  407. case NAND_CMD_RESET:
  408. if (chip->legacy.dev_ready)
  409. break;
  410. udelay(chip->legacy.chip_delay);
  411. chip->legacy.cmd_ctrl(chip, NAND_CMD_STATUS,
  412. NAND_NCE | NAND_CLE | NAND_CTRL_CHANGE);
  413. chip->legacy.cmd_ctrl(chip, NAND_CMD_NONE,
  414. NAND_NCE | NAND_CTRL_CHANGE);
  415. /* EZ-NAND can take upto 250ms as per ONFi v4.0 */
  416. nand_wait_status_ready(chip, 250);
  417. return;
  418. case NAND_CMD_RNDOUT:
  419. /* No ready / busy check necessary */
  420. chip->legacy.cmd_ctrl(chip, NAND_CMD_RNDOUTSTART,
  421. NAND_NCE | NAND_CLE | NAND_CTRL_CHANGE);
  422. chip->legacy.cmd_ctrl(chip, NAND_CMD_NONE,
  423. NAND_NCE | NAND_CTRL_CHANGE);
  424. nand_ccs_delay(chip);
  425. return;
  426. case NAND_CMD_READ0:
  427. /*
  428. * READ0 is sometimes used to exit GET STATUS mode. When this
  429. * is the case no address cycles are requested, and we can use
  430. * this information to detect that READSTART should not be
  431. * issued.
  432. */
  433. if (column == -1 && page_addr == -1)
  434. return;
  435. chip->legacy.cmd_ctrl(chip, NAND_CMD_READSTART,
  436. NAND_NCE | NAND_CLE | NAND_CTRL_CHANGE);
  437. chip->legacy.cmd_ctrl(chip, NAND_CMD_NONE,
  438. NAND_NCE | NAND_CTRL_CHANGE);
  439. fallthrough; /* This applies to read commands */
  440. default:
  441. /*
  442. * If we don't have access to the busy pin, we apply the given
  443. * command delay.
  444. */
  445. if (!chip->legacy.dev_ready) {
  446. udelay(chip->legacy.chip_delay);
  447. return;
  448. }
  449. }
  450. /*
  451. * Apply this short delay always to ensure that we do wait tWB in
  452. * any case on any machine.
  453. */
  454. ndelay(100);
  455. nand_wait_ready(chip);
  456. }
  457. /**
  458. * nand_get_set_features_notsupp - set/get features stub returning -ENOTSUPP
  459. * @chip: nand chip info structure
  460. * @addr: feature address.
  461. * @subfeature_param: the subfeature parameters, a four bytes array.
  462. *
  463. * Should be used by NAND controller drivers that do not support the SET/GET
  464. * FEATURES operations.
  465. */
  466. int nand_get_set_features_notsupp(struct nand_chip *chip, int addr,
  467. u8 *subfeature_param)
  468. {
  469. return -ENOTSUPP;
  470. }
  471. EXPORT_SYMBOL(nand_get_set_features_notsupp);
  472. /**
  473. * nand_wait - [DEFAULT] wait until the command is done
  474. * @chip: NAND chip structure
  475. *
  476. * Wait for command done. This applies to erase and program only.
  477. */
  478. static int nand_wait(struct nand_chip *chip)
  479. {
  480. struct mtd_info *mtd = nand_to_mtd(chip);
  481. unsigned long timeo = 400;
  482. u8 status;
  483. int ret;
  484. /*
  485. * Apply this short delay always to ensure that we do wait tWB in any
  486. * case on any machine.
  487. */
  488. ndelay(100);
  489. ret = nand_status_op(chip, NULL);
  490. if (ret)
  491. return ret;
  492. if (mtd->oops_panic_write) {
  493. panic_nand_wait(chip, timeo);
  494. } else {
  495. timeo = jiffies + msecs_to_jiffies(timeo);
  496. do {
  497. if (chip->legacy.dev_ready) {
  498. if (chip->legacy.dev_ready(chip))
  499. break;
  500. } else {
  501. ret = nand_read_data_op(chip, &status,
  502. sizeof(status), true,
  503. false);
  504. if (ret)
  505. return ret;
  506. if (status & NAND_STATUS_READY)
  507. break;
  508. }
  509. cond_resched();
  510. } while (time_before(jiffies, timeo));
  511. }
  512. ret = nand_read_data_op(chip, &status, sizeof(status), true, false);
  513. if (ret)
  514. return ret;
  515. /* This can happen if in case of timeout or buggy dev_ready */
  516. WARN_ON(!(status & NAND_STATUS_READY));
  517. return status;
  518. }
  519. void nand_legacy_set_defaults(struct nand_chip *chip)
  520. {
  521. unsigned int busw = chip->options & NAND_BUSWIDTH_16;
  522. if (nand_has_exec_op(chip))
  523. return;
  524. /* check for proper chip_delay setup, set 20us if not */
  525. if (!chip->legacy.chip_delay)
  526. chip->legacy.chip_delay = 20;
  527. /* check, if a user supplied command function given */
  528. if (!chip->legacy.cmdfunc)
  529. chip->legacy.cmdfunc = nand_command;
  530. /* check, if a user supplied wait function given */
  531. if (chip->legacy.waitfunc == NULL)
  532. chip->legacy.waitfunc = nand_wait;
  533. if (!chip->legacy.select_chip)
  534. chip->legacy.select_chip = nand_select_chip;
  535. /* If called twice, pointers that depend on busw may need to be reset */
  536. if (!chip->legacy.read_byte || chip->legacy.read_byte == nand_read_byte)
  537. chip->legacy.read_byte = busw ? nand_read_byte16 : nand_read_byte;
  538. if (!chip->legacy.write_buf || chip->legacy.write_buf == nand_write_buf)
  539. chip->legacy.write_buf = busw ? nand_write_buf16 : nand_write_buf;
  540. if (!chip->legacy.write_byte || chip->legacy.write_byte == nand_write_byte)
  541. chip->legacy.write_byte = busw ? nand_write_byte16 : nand_write_byte;
  542. if (!chip->legacy.read_buf || chip->legacy.read_buf == nand_read_buf)
  543. chip->legacy.read_buf = busw ? nand_read_buf16 : nand_read_buf;
  544. }
  545. void nand_legacy_adjust_cmdfunc(struct nand_chip *chip)
  546. {
  547. struct mtd_info *mtd = nand_to_mtd(chip);
  548. /* Do not replace user supplied command function! */
  549. if (mtd->writesize > 512 && chip->legacy.cmdfunc == nand_command)
  550. chip->legacy.cmdfunc = nand_command_lp;
  551. }
  552. int nand_legacy_check_hooks(struct nand_chip *chip)
  553. {
  554. /*
  555. * ->legacy.cmdfunc() is legacy and will only be used if ->exec_op() is
  556. * not populated.
  557. */
  558. if (nand_has_exec_op(chip))
  559. return 0;
  560. /*
  561. * Default functions assigned for ->legacy.cmdfunc() and
  562. * ->legacy.select_chip() both expect ->legacy.cmd_ctrl() to be
  563. * populated.
  564. */
  565. if ((!chip->legacy.cmdfunc || !chip->legacy.select_chip) &&
  566. !chip->legacy.cmd_ctrl) {
  567. pr_err("->legacy.cmd_ctrl() should be provided\n");
  568. return -EINVAL;
  569. }
  570. return 0;
  571. }