28 #include <linux/slab.h>
33 #define alt_jtag_io(a, b, c)\
34 astate->config->jtag_io(astate->config->dev, a, b, c);
36 #define alt_malloc(a) kzalloc(a, GFP_KERNEL);
74 static const u16 altera_jtag_path_map[16] = {
76 0x0001, 0xFFFD, 0xFE01, 0xFFE7, 0xFFEF, 0xFF0F, 0xFFBF, 0xFFFF,
78 0xFEFD, 0x0001, 0xF3FF, 0xF7FF, 0x87FF, 0xDFFF, 0xFFFF, 0x7FFD
149 for (i = 0; i <
count; ++
i) {
152 if (preamble_data ==
NULL)
155 if (preamble_data[j >> 3] & (1 << (j & 7)))
160 ~(
u32)(1 << (i & 7));
188 for (i = 0; i <
count; ++
i) {
190 if (preamble_data ==
NULL)
193 if (preamble_data[j >> 3] & (1 << (j & 7)))
198 ~(
u32)(1 << (i & 7));
227 for (i = 0; i <
count; ++
i) {
230 if (postamble_data ==
NULL)
233 if (postamble_data[j >> 3] & (1 << (j & 7)))
238 ~(
u32)(1 << (i & 7));
268 for (i = 0; i <
count; ++
i) {
271 if (postamble_data ==
NULL)
274 if (postamble_data[j >> 3] & (1 << (j & 7)))
278 ~(
u32)(1 << (i & 7));
286 static void altera_jreset_idle(
struct altera_state *astate)
291 for (i = 0; i < 5; ++
i)
309 altera_jreset_idle(astate);
321 }
else if (state ==
RESET)
325 while ((js->
jtag_state != state) && (count < 9)) {
370 for (count = 0
L; count < cycles; count++)
404 static void altera_concatenate_data(
u8 *
buffer,
419 for (i = 0L; i < preamble_count; ++
i) {
420 if (preamble_data[i >> 3L] & (1L << (i & 7L)))
421 buffer[i >> 3L] |= (1L << (i & 7L));
423 buffer[i >> 3L] &= ~(
u32)(1L << (i & 7L));
428 k = preamble_count + target_count;
429 for (; i <
k; ++
i, ++
j) {
430 if (target_data[j >> 3L] & (1L << (j & 7L)))
431 buffer[i >> 3L] |= (1L << (i & 7L));
433 buffer[i >> 3L] &= ~(
u32)(1L << (i & 7L));
438 k = preamble_count + target_count + postamble_count;
439 for (; i <
k; ++
i, ++
j) {
440 if (postamble_data[j >> 3L] & (1L << (j & 7L)))
441 buffer[i >> 3L] |= (1L << (i & 7L));
443 buffer[i >> 3L] &= ~(
u32)(1L << (i & 7L));
459 switch (start_state) {
488 for (i = 0; i <
count; i++) {
491 tdi[i >> 3] & (1 << (i & 7)),
496 tdo[i >> 3] |= (1 << (i & 7));
498 tdo[i >> 3] &= ~(
u32)(1 << (i & 7));
520 switch (start_state) {
552 for (i = 0; i <
count; i++) {
555 tdi[i >> 3] & (1 << (i & 7)),
559 tdo[i >> 3] |= (1 << (i & 7));
561 tdo[i >> 3] &= ~(
u32)(1 << (i & 7));
572 static void altera_extract_target_data(
u8 *buffer,
587 k = start_index + target_count;
588 for (i = start_index; i <
k; ++
i, ++
j) {
589 if (buffer[j >> 3] & (1 << (j & 7)))
590 target_data[i >> 3] |= (1 << (i & 7));
592 target_data[i >> 3] &= ~(
u32)(1 << (i & 7));
651 alloc_chars = (shift_count + 7) >> 3;
676 alt_jtag_irscan(astate,
750 alloc_chars = (shift_count + 7) >> 3;
776 alt_jtag_irscan(astate,
793 altera_extract_target_data(js->
ir_buffer,
854 alloc_chars = (shift_count + 7) >> 3;
879 alt_jtag_drscan(astate, start_code, shift_count,
893 u8 *in_data,
u32 in_index,
894 u8 *out_data,
u32 out_index)
945 alloc_chars = (shift_count + 7) >> 3;
972 alt_jtag_drscan(astate,
988 altera_extract_target_data(js->
dr_buffer,
1002 altera_jreset_idle(astate);