1 // SPDX-License-Identifier: GPL-2.0+
3 * Console via Blackfin JTAG Communication
5 * Copyright 2008-2011 Analog Devices Inc.
7 * Enter bugs at http://blackfin.uclinux.org/
10 #include <linux/console.h>
11 #include <linux/delay.h>
12 #include <linux/err.h>
13 #include <linux/init.h>
14 #include <linux/moduleparam.h>
15 #include <linux/types.h>
17 #include "hvc_console.h"
19 /* See the Debug/Emulation chapter in the HRM */
20 #define EMUDOF 0x00000001 /* EMUDAT_OUT full & valid */
21 #define EMUDIF 0x00000002 /* EMUDAT_IN full & valid */
22 #define EMUDOOVF 0x00000004 /* EMUDAT_OUT overflow */
23 #define EMUDIOVF 0x00000008 /* EMUDAT_IN overflow */
25 /* Helper functions to glue the register API to simple C operations */
26 static inline uint32_t bfin_write_emudat(uint32_t emudat)
28 __asm__ __volatile__("emudat = %0;" : : "d"(emudat));
32 static inline uint32_t bfin_read_emudat(void)
35 __asm__ __volatile__("%0 = emudat;" : "=d"(emudat));
39 /* Send data to the host */
40 static int hvc_bfin_put_chars(uint32_t vt, const char *buf, int count)
42 static uint32_t outbound_len;
46 if (bfin_read_DBGSTAT() & EMUDOF)
51 bfin_write_emudat(outbound_len);
55 ret = min(outbound_len, (uint32_t)4);
56 memcpy(&emudat, buf, ret);
57 bfin_write_emudat(emudat);
63 /* Receive data from the host */
64 static int hvc_bfin_get_chars(uint32_t vt, char *buf, int count)
66 static uint32_t inbound_len;
70 if (!(bfin_read_DBGSTAT() & EMUDIF))
72 emudat = bfin_read_emudat();
79 ret = min(inbound_len, (uint32_t)4);
80 memcpy(buf, &emudat, ret);
86 /* Glue the HVC layers to the Blackfin layers */
87 static const struct hv_ops hvc_bfin_get_put_ops = {
88 .get_chars = hvc_bfin_get_chars,
89 .put_chars = hvc_bfin_put_chars,
92 static int __init hvc_bfin_console_init(void)
94 hvc_instantiate(0, 0, &hvc_bfin_get_put_ops);
97 console_initcall(hvc_bfin_console_init);
99 static int __init hvc_bfin_init(void)
101 hvc_alloc(0, 0, &hvc_bfin_get_put_ops, 128);
104 device_initcall(hvc_bfin_init);