Merge branch 'next' of ../next
[platform/kernel/u-boot.git] / board / esd / common / xilinx_jtag / ports.c
1 /*
2  * (C) Copyright 2003
3  * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23
24 /*******************************************************/
25 /* file: ports.c                                       */
26 /* abstract:  This file contains the routines to       */
27 /*            output values on the JTAG ports, to read */
28 /*            the TDO bit, and to read a byte of data  */
29 /*            from the prom                            */
30 /*                                                     */
31 /*******************************************************/
32
33 #include <common.h>
34 #include <asm/processor.h>
35 #include <asm/io.h>
36
37 #include "ports.h"
38
39 static unsigned long output = 0;
40 static int filepos = 0;
41 static int oldstate = 0;
42 static int newstate = 0;
43 static int readptr = 0;
44
45 extern long filesize;
46 extern const unsigned char fpgadata[];
47
48
49 /* if in debugging mode, then just set the variables */
50 void setPort(short p,short val)
51 {
52         if (p==TMS) {
53                 if (val) {
54                         output |= JTAG_TMS;
55                 } else {
56                         output &= ~JTAG_TMS;
57                 }
58         }
59         if (p==TDI) {
60                 if (val) {
61                         output |= JTAG_TDI;
62                 } else {
63                         output &= ~JTAG_TDI;
64                 }
65         }
66         if (p==TCK) {
67                 if (val) {
68                         output |= JTAG_TCK;
69                 } else {
70                         output &= ~JTAG_TCK;
71                 }
72                 out_be32((void *)GPIO0_OR, output);
73         }
74 }
75
76
77 /* toggle tck LH */
78 void pulseClock(void)
79 {
80         setPort(TCK,0);  /* set the TCK port to low  */
81         setPort(TCK,1);  /* set the TCK port to high */
82 }
83
84
85 /* read in a byte of data from the prom */
86 void readByte(unsigned char *data)
87 {
88         /* pretend reading using a file */
89         *data = fpgadata[readptr++];
90         newstate = (100 * filepos++) / filesize;
91         if (newstate != oldstate) {
92                 printf("%4d\r\r\r\r", newstate);
93                 oldstate = newstate;
94         }
95 }
96
97 /* read the TDO bit from port */
98 unsigned char readTDOBit(void)
99 {
100         unsigned long inputs;
101
102         inputs = in_be32((void *)GPIO0_IR);
103         if (inputs & JTAG_TDO)
104                 return 1;
105         else
106                 return 0;
107 }
108
109
110 /* Wait at least the specified number of microsec.                           */
111 /* Use a timer if possible; otherwise estimate the number of instructions    */
112 /* necessary to be run based on the microcontroller speed.  For this example */
113 /* we pulse the TCK port a number of times based on the processor speed.     */
114 void waitTime(long microsec)
115 {
116         udelay(microsec); /* esd */
117 }