Lines Matching +full:chip +full:- +full:to +full:- +full:chip

1 // SPDX-License-Identifier: GPL-2.0
4 * 2002-2006 Thomas Gleixner (tglx@linutronix.de)
23 * nand_read_byte - [DEFAULT] read one byte from the chip
24 * @chip: NAND chip object
28 static uint8_t nand_read_byte(struct nand_chip *chip) in nand_read_byte() argument
30 return readb(chip->legacy.IO_ADDR_R); in nand_read_byte()
34 * nand_read_byte16 - [DEFAULT] read one byte endianness aware from the chip
35 * @chip: NAND chip object
40 static uint8_t nand_read_byte16(struct nand_chip *chip) in nand_read_byte16() argument
42 return (uint8_t) cpu_to_le16(readw(chip->legacy.IO_ADDR_R)); in nand_read_byte16()
46 * nand_select_chip - [DEFAULT] control CE line
47 * @chip: NAND chip object
48 * @chipnr: chipnumber to select, -1 for deselect
50 * Default select function for 1 chip devices.
52 static void nand_select_chip(struct nand_chip *chip, int chipnr) in nand_select_chip() argument
55 case -1: in nand_select_chip()
56 chip->legacy.cmd_ctrl(chip, NAND_CMD_NONE, in nand_select_chip()
68 * nand_write_byte - [DEFAULT] write single byte to chip
69 * @chip: NAND chip object
70 * @byte: value to write
72 * Default function to write a byte to I/O[7:0]
74 static void nand_write_byte(struct nand_chip *chip, uint8_t byte) in nand_write_byte() argument
76 chip->legacy.write_buf(chip, &byte, 1); in nand_write_byte()
80 * nand_write_byte16 - [DEFAULT] write single byte to a chip with width 16
81 * @chip: NAND chip object
82 * @byte: value to write
84 * Default function to write a byte to I/O[7:0] on a 16-bit wide chip.
86 static void nand_write_byte16(struct nand_chip *chip, uint8_t byte) in nand_write_byte16() argument
91 * It's not entirely clear what should happen to I/O[15:8] when writing in nand_write_byte16()
92 * a byte. The ONFi spec (Revision 3.1; 2012-09-19, Section 2.16) reads: in nand_write_byte16()
94 * When the host supports a 16-bit bus width, only data is in nand_write_byte16()
95 * transferred at the 16-bit width. All address and command line in nand_write_byte16()
96 * transfers shall use only the lower 8-bits of the data bus. During in nand_write_byte16()
98 * 8-bits of the data bus. During address transfers, the host shall in nand_write_byte16()
99 * set the upper 8-bits of the data bus to 00h. in nand_write_byte16()
102 * four parameters are specified to be written to I/O[7:0], but this is in nand_write_byte16()
106 chip->legacy.write_buf(chip, (uint8_t *)&word, 2); in nand_write_byte16()
110 * nand_write_buf - [DEFAULT] write buffer to chip
111 * @chip: NAND chip object
113 * @len: number of bytes to write
117 static void nand_write_buf(struct nand_chip *chip, const uint8_t *buf, int len) in nand_write_buf() argument
119 iowrite8_rep(chip->legacy.IO_ADDR_W, buf, len); in nand_write_buf()
123 * nand_read_buf - [DEFAULT] read chip data into buffer
124 * @chip: NAND chip object
125 * @buf: buffer to store date
126 * @len: number of bytes to read
130 static void nand_read_buf(struct nand_chip *chip, uint8_t *buf, int len) in nand_read_buf() argument
132 ioread8_rep(chip->legacy.IO_ADDR_R, buf, len); in nand_read_buf()
136 * nand_write_buf16 - [DEFAULT] write buffer to chip
137 * @chip: NAND chip object
139 * @len: number of bytes to write
143 static void nand_write_buf16(struct nand_chip *chip, const uint8_t *buf, in nand_write_buf16() argument
148 iowrite16_rep(chip->legacy.IO_ADDR_W, p, len >> 1); in nand_write_buf16()
152 * nand_read_buf16 - [DEFAULT] read chip data into buffer
153 * @chip: NAND chip object
154 * @buf: buffer to store date
155 * @len: number of bytes to read
159 static void nand_read_buf16(struct nand_chip *chip, uint8_t *buf, int len) in nand_read_buf16() argument
163 ioread16_rep(chip->legacy.IO_ADDR_R, p, len >> 1); in nand_read_buf16()
167 * panic_nand_wait_ready - [GENERIC] Wait for the ready pin after commands.
168 * @chip: NAND chip object
171 * Helper function for nand_wait_ready used when needing to wait in interrupt
174 static void panic_nand_wait_ready(struct nand_chip *chip, unsigned long timeo) in panic_nand_wait_ready() argument
178 /* Wait for the device to get ready */ in panic_nand_wait_ready()
180 if (chip->legacy.dev_ready(chip)) in panic_nand_wait_ready()
188 * nand_wait_ready - [GENERIC] Wait for the ready pin after commands.
189 * @chip: NAND chip object
193 void nand_wait_ready(struct nand_chip *chip) in nand_wait_ready() argument
195 struct mtd_info *mtd = nand_to_mtd(chip); in nand_wait_ready()
198 if (mtd->oops_panic_write) in nand_wait_ready()
199 return panic_nand_wait_ready(chip, timeo); in nand_wait_ready()
204 if (chip->legacy.dev_ready(chip)) in nand_wait_ready()
209 if (!chip->legacy.dev_ready(chip)) in nand_wait_ready()
210 pr_warn_ratelimited("timeout while waiting for chip to become ready\n"); in nand_wait_ready()
215 * nand_wait_status_ready - [GENERIC] Wait for the ready status after commands.
216 * @chip: NAND chip object
221 static void nand_wait_status_ready(struct nand_chip *chip, unsigned long timeo) in nand_wait_status_ready() argument
229 ret = nand_read_data_op(chip, &status, sizeof(status), true, in nand_wait_status_ready()
241 * nand_command - [DEFAULT] Send command to NAND device
242 * @chip: NAND chip object
243 * @command: the command to be sent
244 * @column: the column address for this command, -1 if none
245 * @page_addr: the page address for this command, -1 if none
247 * Send command to NAND device. This function is used for small page devices
250 static void nand_command(struct nand_chip *chip, unsigned int command, in nand_command() argument
253 struct mtd_info *mtd = nand_to_mtd(chip); in nand_command()
256 /* Write out the command to the device */ in nand_command()
260 if (column >= mtd->writesize) { in nand_command()
262 column -= mtd->writesize; in nand_command()
265 /* First 256 bytes --> READ0 */ in nand_command()
268 column -= 256; in nand_command()
271 chip->legacy.cmd_ctrl(chip, readcmd, ctrl); in nand_command()
275 chip->legacy.cmd_ctrl(chip, command, ctrl); in nand_command()
280 if (column != -1) { in nand_command()
282 if (chip->options & NAND_BUSWIDTH_16 && in nand_command()
285 chip->legacy.cmd_ctrl(chip, column, ctrl); in nand_command()
288 if (page_addr != -1) { in nand_command()
289 chip->legacy.cmd_ctrl(chip, page_addr, ctrl); in nand_command()
291 chip->legacy.cmd_ctrl(chip, page_addr >> 8, ctrl); in nand_command()
292 if (chip->options & NAND_ROW_ADDR_3) in nand_command()
293 chip->legacy.cmd_ctrl(chip, page_addr >> 16, ctrl); in nand_command()
295 chip->legacy.cmd_ctrl(chip, NAND_CMD_NONE, in nand_command()
315 if (chip->legacy.dev_ready) in nand_command()
317 udelay(chip->legacy.chip_delay); in nand_command()
318 chip->legacy.cmd_ctrl(chip, NAND_CMD_STATUS, in nand_command()
320 chip->legacy.cmd_ctrl(chip, NAND_CMD_NONE, in nand_command()
322 /* EZ-NAND can take upto 250ms as per ONFi v4.0 */ in nand_command()
323 nand_wait_status_ready(chip, 250); in nand_command()
326 /* This applies to read commands */ in nand_command()
329 * READ0 is sometimes used to exit GET STATUS mode. When this in nand_command()
331 * this information to detect that we should not wait for the in nand_command()
332 * device to be ready. in nand_command()
334 if (column == -1 && page_addr == -1) in nand_command()
339 * If we don't have access to the busy pin, we apply the given in nand_command()
342 if (!chip->legacy.dev_ready) { in nand_command()
343 udelay(chip->legacy.chip_delay); in nand_command()
348 * Apply this short delay always to ensure that we do wait tWB in in nand_command()
353 nand_wait_ready(chip); in nand_command()
356 static void nand_ccs_delay(struct nand_chip *chip) in nand_ccs_delay() argument
359 nand_get_sdr_timings(nand_get_interface_config(chip)); in nand_ccs_delay()
365 if (!(chip->options & NAND_WAIT_TCCS)) in nand_ccs_delay()
372 if (!IS_ERR(sdr) && nand_controller_can_setup_interface(chip)) in nand_ccs_delay()
373 ndelay(sdr->tCCS_min / 1000); in nand_ccs_delay()
379 * nand_command_lp - [DEFAULT] Send command to NAND large page device
380 * @chip: NAND chip object
381 * @command: the command to be sent
382 * @column: the column address for this command, -1 if none
383 * @page_addr: the page address for this command, -1 if none
385 * Send command to NAND device. This is the version for the new large page
387 * devices. We must emulate NAND_CMD_READOOB to keep the code compatible.
389 static void nand_command_lp(struct nand_chip *chip, unsigned int command, in nand_command_lp() argument
392 struct mtd_info *mtd = nand_to_mtd(chip); in nand_command_lp()
396 column += mtd->writesize; in nand_command_lp()
402 chip->legacy.cmd_ctrl(chip, command, in nand_command_lp()
405 if (column != -1 || page_addr != -1) { in nand_command_lp()
409 if (column != -1) { in nand_command_lp()
411 if (chip->options & NAND_BUSWIDTH_16 && in nand_command_lp()
414 chip->legacy.cmd_ctrl(chip, column, ctrl); in nand_command_lp()
419 chip->legacy.cmd_ctrl(chip, column >> 8, ctrl); in nand_command_lp()
421 if (page_addr != -1) { in nand_command_lp()
422 chip->legacy.cmd_ctrl(chip, page_addr, ctrl); in nand_command_lp()
423 chip->legacy.cmd_ctrl(chip, page_addr >> 8, in nand_command_lp()
425 if (chip->options & NAND_ROW_ADDR_3) in nand_command_lp()
426 chip->legacy.cmd_ctrl(chip, page_addr >> 16, in nand_command_lp()
430 chip->legacy.cmd_ctrl(chip, NAND_CMD_NONE, in nand_command_lp()
451 nand_ccs_delay(chip); in nand_command_lp()
455 if (chip->legacy.dev_ready) in nand_command_lp()
457 udelay(chip->legacy.chip_delay); in nand_command_lp()
458 chip->legacy.cmd_ctrl(chip, NAND_CMD_STATUS, in nand_command_lp()
460 chip->legacy.cmd_ctrl(chip, NAND_CMD_NONE, in nand_command_lp()
462 /* EZ-NAND can take upto 250ms as per ONFi v4.0 */ in nand_command_lp()
463 nand_wait_status_ready(chip, 250); in nand_command_lp()
468 chip->legacy.cmd_ctrl(chip, NAND_CMD_RNDOUTSTART, in nand_command_lp()
470 chip->legacy.cmd_ctrl(chip, NAND_CMD_NONE, in nand_command_lp()
473 nand_ccs_delay(chip); in nand_command_lp()
478 * READ0 is sometimes used to exit GET STATUS mode. When this in nand_command_lp()
480 * this information to detect that READSTART should not be in nand_command_lp()
483 if (column == -1 && page_addr == -1) in nand_command_lp()
486 chip->legacy.cmd_ctrl(chip, NAND_CMD_READSTART, in nand_command_lp()
488 chip->legacy.cmd_ctrl(chip, NAND_CMD_NONE, in nand_command_lp()
490 fallthrough; /* This applies to read commands */ in nand_command_lp()
493 * If we don't have access to the busy pin, we apply the given in nand_command_lp()
496 if (!chip->legacy.dev_ready) { in nand_command_lp()
497 udelay(chip->legacy.chip_delay); in nand_command_lp()
503 * Apply this short delay always to ensure that we do wait tWB in in nand_command_lp()
508 nand_wait_ready(chip); in nand_command_lp()
512 * nand_get_set_features_notsupp - set/get features stub returning -ENOTSUPP
513 * @chip: nand chip info structure
520 int nand_get_set_features_notsupp(struct nand_chip *chip, int addr, in nand_get_set_features_notsupp() argument
523 return -ENOTSUPP; in nand_get_set_features_notsupp()
528 * nand_wait - [DEFAULT] wait until the command is done
529 * @chip: NAND chip structure
531 * Wait for command done. This applies to erase and program only.
533 static int nand_wait(struct nand_chip *chip) in nand_wait() argument
535 struct mtd_info *mtd = nand_to_mtd(chip); in nand_wait()
541 * Apply this short delay always to ensure that we do wait tWB in any in nand_wait()
546 ret = nand_status_op(chip, NULL); in nand_wait()
550 if (mtd->oops_panic_write) { in nand_wait()
551 panic_nand_wait(chip, timeo); in nand_wait()
555 if (chip->legacy.dev_ready) { in nand_wait()
556 if (chip->legacy.dev_ready(chip)) in nand_wait()
559 ret = nand_read_data_op(chip, &status, in nand_wait()
572 ret = nand_read_data_op(chip, &status, sizeof(status), true, false); in nand_wait()
581 void nand_legacy_set_defaults(struct nand_chip *chip) in nand_legacy_set_defaults() argument
583 unsigned int busw = chip->options & NAND_BUSWIDTH_16; in nand_legacy_set_defaults()
585 if (nand_has_exec_op(chip)) in nand_legacy_set_defaults()
589 if (!chip->legacy.chip_delay) in nand_legacy_set_defaults()
590 chip->legacy.chip_delay = 20; in nand_legacy_set_defaults()
593 if (!chip->legacy.cmdfunc) in nand_legacy_set_defaults()
594 chip->legacy.cmdfunc = nand_command; in nand_legacy_set_defaults()
597 if (chip->legacy.waitfunc == NULL) in nand_legacy_set_defaults()
598 chip->legacy.waitfunc = nand_wait; in nand_legacy_set_defaults()
600 if (!chip->legacy.select_chip) in nand_legacy_set_defaults()
601 chip->legacy.select_chip = nand_select_chip; in nand_legacy_set_defaults()
603 /* If called twice, pointers that depend on busw may need to be reset */ in nand_legacy_set_defaults()
604 if (!chip->legacy.read_byte || chip->legacy.read_byte == nand_read_byte) in nand_legacy_set_defaults()
605 chip->legacy.read_byte = busw ? nand_read_byte16 : nand_read_byte; in nand_legacy_set_defaults()
606 if (!chip->legacy.write_buf || chip->legacy.write_buf == nand_write_buf) in nand_legacy_set_defaults()
607 chip->legacy.write_buf = busw ? nand_write_buf16 : nand_write_buf; in nand_legacy_set_defaults()
608 if (!chip->legacy.write_byte || chip->legacy.write_byte == nand_write_byte) in nand_legacy_set_defaults()
609 chip->legacy.write_byte = busw ? nand_write_byte16 : nand_write_byte; in nand_legacy_set_defaults()
610 if (!chip->legacy.read_buf || chip->legacy.read_buf == nand_read_buf) in nand_legacy_set_defaults()
611 chip->legacy.read_buf = busw ? nand_read_buf16 : nand_read_buf; in nand_legacy_set_defaults()
614 void nand_legacy_adjust_cmdfunc(struct nand_chip *chip) in nand_legacy_adjust_cmdfunc() argument
616 struct mtd_info *mtd = nand_to_mtd(chip); in nand_legacy_adjust_cmdfunc()
619 if (mtd->writesize > 512 && chip->legacy.cmdfunc == nand_command) in nand_legacy_adjust_cmdfunc()
620 chip->legacy.cmdfunc = nand_command_lp; in nand_legacy_adjust_cmdfunc()
623 int nand_legacy_check_hooks(struct nand_chip *chip) in nand_legacy_check_hooks() argument
626 * ->legacy.cmdfunc() is legacy and will only be used if ->exec_op() is in nand_legacy_check_hooks()
629 if (nand_has_exec_op(chip)) in nand_legacy_check_hooks()
633 * Default functions assigned for ->legacy.cmdfunc() and in nand_legacy_check_hooks()
634 * ->legacy.select_chip() both expect ->legacy.cmd_ctrl() to be in nand_legacy_check_hooks()
637 if ((!chip->legacy.cmdfunc || !chip->legacy.select_chip) && in nand_legacy_check_hooks()
638 !chip->legacy.cmd_ctrl) { in nand_legacy_check_hooks()
639 pr_err("->legacy.cmd_ctrl() should be provided\n"); in nand_legacy_check_hooks()
640 return -EINVAL; in nand_legacy_check_hooks()