- /* Program IO scan chain in 128-bit iteration */
- for (i = 0; i < io_scan_chain_len_in_bits / 128; i++) {
- /* Write TDI_TDO packet header for 128-bit IO scan chain */
- scan_mgr_jtag_io(JTAG_BP_INSN | JTAG_BP_2BYTE, 0x0,
- TDI_TDO_MAX_PAYLOAD);
-
- /* write 4 successive 32-bit IO scan chain data into WFIFO */
- scan_mgr_jtag_io(JTAG_BP_4BYTE, 0x0, iocsr_scan_chain[index++]);
- scan_mgr_jtag_io(JTAG_BP_4BYTE, 0x0, iocsr_scan_chain[index++]);
- scan_mgr_jtag_io(JTAG_BP_4BYTE, 0x0, iocsr_scan_chain[index++]);
- scan_mgr_jtag_io(JTAG_BP_4BYTE, 0x0, iocsr_scan_chain[index++]);
-
- /*
- * Check if the scan chain engine has completed the
- * IO scan chain data shifting
- */
- ret = scan_chain_engine_is_idle(SCANMGR_MAX_DELAY);
- if (ret)
- goto error;
- }
-
- residual = io_scan_chain_len_in_bits % 128;
-
- /* Final TDI_TDO packet (if chain length is not aligned to 128 bits) */
- if (residual) {
- /*
- * Program the last part of IO scan chain write TDI_TDO
- * packet header (2 bytes) to scan manager.
- */
- scan_mgr_jtag_io(JTAG_BP_INSN | JTAG_BP_2BYTE, 0x0,
- residual - 1);
-
- for (i = 0; i < residual / 32; i++) {
- /*
- * write remaining scan chain data into scan
- * manager WFIFO with 4 bytes write
- */
- scan_mgr_jtag_io(JTAG_BP_4BYTE, 0x0,
- iocsr_scan_chain[index++]);
- }
-
- residual = io_scan_chain_len_in_bits % 32;
- if (residual > 24) {
- /*
- * write the last 4B scan chain data
- * into scan manager WFIFO
- */
- scan_mgr_jtag_io(JTAG_BP_4BYTE, 0x0,
- iocsr_scan_chain[index]);
- } else {
- /*
- * write the remaining 1 - 3 bytes scan chain
- * data into scan manager WFIFO byte by byte
- * to prevent JTAG engine shifting unused data
- * from the FIFO and mistaken the data as a
- * valid command (even though unused bits are
- * set to 0, but just to prevent hardware
- * glitch)
- */
- for (i = 0; i < residual; i += 8) {
- scan_mgr_jtag_io(0, 0x0,
- iocsr_scan_chain[index] >> i);
- }
- }