]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/esd/common/xilinx_jtag/ports.c
imported Ka-Ro specific additions to U-Boot 2009.08 for TX28
[karo-tx-uboot.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 const unsigned char *xsvfdata;
46
47 /* if in debugging mode, then just set the variables */
48 void setPort(short p,short val)
49 {
50         if (p==TMS) {
51                 if (val) {
52                         output |= JTAG_TMS;
53                 } else {
54                         output &= ~JTAG_TMS;
55                 }
56         }
57         if (p==TDI) {
58                 if (val) {
59                         output |= JTAG_TDI;
60                 } else {
61                         output &= ~JTAG_TDI;
62                 }
63         }
64         if (p==TCK) {
65                 if (val) {
66                         output |= JTAG_TCK;
67                 } else {
68                         output &= ~JTAG_TCK;
69                 }
70                 out_be32((void *)GPIO0_OR, output);
71         }
72 }
73
74
75 /* toggle tck LH */
76 void pulseClock(void)
77 {
78         setPort(TCK,0);  /* set the TCK port to low  */
79         setPort(TCK,1);  /* set the TCK port to high */
80 }
81
82
83 /* read in a byte of data from the prom */
84 void readByte(unsigned char *data)
85 {
86         /* pretend reading using a file */
87         *data = xsvfdata[readptr++];
88         newstate = filepos++ >> 10;
89         if (newstate != oldstate) {
90                 printf("%4d kB\r\r\r\r", newstate);
91                 oldstate = newstate;
92         }
93 }
94
95 /* read the TDO bit from port */
96 unsigned char readTDOBit(void)
97 {
98         unsigned long inputs;
99
100         inputs = in_be32((void *)GPIO0_IR);
101         if (inputs & JTAG_TDO)
102                 return 1;
103         else
104                 return 0;
105 }
106
107
108 /* Wait at least the specified number of microsec.                           */
109 /* Use a timer if possible; otherwise estimate the number of instructions    */
110 /* necessary to be run based on the microcontroller speed.  For this example */
111 /* we pulse the TCK port a number of times based on the processor speed.     */
112 void waitTime(long microsec)
113 {
114         udelay(microsec); /* esd */
115 }