2 * jtag-console.c - console driver over Blackfin JTAG
4 * Copyright (c) 2008 Analog Devices Inc.
6 * Licensed under the GPL-2 or later.
11 #include <asm/blackfin.h>
13 #ifndef CONFIG_JTAG_CONSOLE_TIMEOUT
14 # define CONFIG_JTAG_CONSOLE_TIMEOUT 100
17 /* The Blackfin tends to be much much faster than the JTAG hardware. */
18 static void jtag_write_emudat(uint32_t emudat)
20 static bool overflowed = false;
21 ulong timeout = get_timer(0) + CONFIG_JTAG_CONSOLE_TIMEOUT;
22 while (bfin_read_DBGSTAT() & 0x1) {
25 if (timeout < get_timer(0))
29 __asm__ __volatile__("emudat = %0;" : : "d"(emudat));
31 /* Transmit a buffer. The format is:
32 * [32bit length][actual data]
34 static void jtag_send(const char *c, uint32_t len)
41 /* First send the length */
42 jtag_write_emudat(len);
44 /* Then send the data */
45 for (i = 0; i < len; i += 4)
46 jtag_write_emudat((c[i] << 0) | (c[i+1] << 8) | (c[i+2] << 16) | (c[i+3] << 24));
48 static void jtag_putc(const char c)
52 static void jtag_puts(const char *s)
54 jtag_send(s, strlen(s));
57 static int jtag_tstc(void)
59 return (bfin_read_DBGSTAT() & 0x2);
62 /* Receive a buffer. The format is:
63 * [32bit length][actual data]
65 static size_t inbound_len;
66 static int leftovers_len;
67 static uint32_t leftovers;
68 static int jtag_getc(void)
73 /* see if any data is left over */
76 ret = leftovers & 0xff;
81 /* wait for new data ! */
84 __asm__("%0 = emudat;" : "=d"(emudat));
86 if (inbound_len == 0) {
91 leftovers_len = min(4, inbound_len);
92 inbound_len -= leftovers_len;
99 int drv_jtag_console_init(void)
104 memset(&dev, 0x00, sizeof(dev));
105 strcpy(dev.name, "jtag");
106 dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
107 dev.putc = jtag_putc;
108 dev.puts = jtag_puts;
109 dev.tstc = jtag_tstc;
110 dev.getc = jtag_getc;
112 ret = device_register(&dev);
113 return (ret == 0 ? 1 : ret);
116 #ifdef CONFIG_UART_CONSOLE_IS_JTAG
117 /* Since the JTAG is always available (at power on), allow it to fake a UART */
118 void serial_set_baud(uint32_t baud) {}
119 void serial_setbrg(void) {}
120 int serial_init(void) { return 0; }
121 void serial_putc(const char c) __attribute__((alias("jtag_putc")));
122 void serial_puts(const char *s) __attribute__((alias("jtag_puts")));
123 int serial_tstc(void) __attribute__((alias("jtag_tstc")));
124 int serial_getc(void) __attribute__((alias("jtag_getc")));