2 * Console via Blackfin JTAG Communication
4 * Copyright 2008-2011 Analog Devices Inc.
6 * Enter bugs at http://blackfin.uclinux.org/
8 * Licensed under the GPL-2 or later.
11 #include <linux/console.h>
12 #include <linux/delay.h>
13 #include <linux/err.h>
14 #include <linux/init.h>
15 #include <linux/moduleparam.h>
16 #include <linux/types.h>
18 #include "hvc_console.h"
20 /* See the Debug/Emulation chapter in the HRM */
21 #define EMUDOF 0x00000001 /* EMUDAT_OUT full & valid */
22 #define EMUDIF 0x00000002 /* EMUDAT_IN full & valid */
23 #define EMUDOOVF 0x00000004 /* EMUDAT_OUT overflow */
24 #define EMUDIOVF 0x00000008 /* EMUDAT_IN overflow */
26 /* Helper functions to glue the register API to simple C operations */
27 static inline uint32_t bfin_write_emudat(uint32_t emudat)
29 __asm__ __volatile__("emudat = %0;" : : "d"(emudat));
33 static inline uint32_t bfin_read_emudat(void)
36 __asm__ __volatile__("%0 = emudat;" : "=d"(emudat));
40 /* Send data to the host */
41 static int hvc_bfin_put_chars(uint32_t vt, const char *buf, int count)
43 static uint32_t outbound_len;
47 if (bfin_read_DBGSTAT() & EMUDOF)
52 bfin_write_emudat(outbound_len);
56 ret = min(outbound_len, (uint32_t)4);
57 memcpy(&emudat, buf, ret);
58 bfin_write_emudat(emudat);
64 /* Receive data from the host */
65 static int hvc_bfin_get_chars(uint32_t vt, char *buf, int count)
67 static uint32_t inbound_len;
71 if (!(bfin_read_DBGSTAT() & EMUDIF))
73 emudat = bfin_read_emudat();
80 ret = min(inbound_len, (uint32_t)4);
81 memcpy(buf, &emudat, ret);
87 /* Glue the HVC layers to the Blackfin layers */
88 static const struct hv_ops hvc_bfin_get_put_ops = {
89 .get_chars = hvc_bfin_get_chars,
90 .put_chars = hvc_bfin_put_chars,
93 static int __init hvc_bfin_console_init(void)
95 hvc_instantiate(0, 0, &hvc_bfin_get_put_ops);
98 console_initcall(hvc_bfin_console_init);
100 static int __init hvc_bfin_init(void)
102 hvc_alloc(0, 0, &hvc_bfin_get_put_ops, 128);
105 device_initcall(hvc_bfin_init);