1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/string.h>
3 #include <linux/kernel.h>
4 #include <linux/errno.h>
5 #include <linux/bitops.h>
6 #include <linux/ptrace.h>
9 #include <linux/cuda.h>
10 #include <asm/machdep.h>
15 #include <asm/bootx.h>
16 #include <asm/errno.h>
17 #include <asm/pmac_feature.h>
18 #include <asm/processor.h>
19 #include <asm/delay.h>
20 #include <asm/btext.h>
25 * This implementation is "special", it can "patch" the current
26 * udbg implementation and work on top of it. It must thus be
30 static void (*udbg_adb_old_putc
)(char c
);
31 static int (*udbg_adb_old_getc
)(void);
32 static int (*udbg_adb_old_getc_poll
)(void);
38 } input_type
= input_adb_none
;
40 int xmon_wants_key
, xmon_adb_keycode
;
42 static inline void udbg_adb_poll(void)
45 if (input_type
== input_adb_pmu
)
47 #endif /* CONFIG_ADB_PMU */
48 #ifdef CONFIG_ADB_CUDA
49 if (input_type
== input_adb_cuda
)
51 #endif /* CONFIG_ADB_CUDA */
54 #ifdef CONFIG_BOOTX_TEXT
56 static int udbg_adb_use_btext
;
57 static int xmon_adb_shiftstate
;
59 static unsigned char xmon_keytab
[128] =
60 "asdfhgzxcv\000bqwer" /* 0x00 - 0x0f */
61 "yt123465=97-80]o" /* 0x10 - 0x1f */
62 "u[ip\rlj'k;\\,/nm." /* 0x20 - 0x2f */
63 "\t `\177\0\033\0\0\0\0\0\0\0\0\0\0" /* 0x30 - 0x3f */
64 "\0.\0*\0+\0\0\0\0\0/\r\0-\0" /* 0x40 - 0x4f */
65 "\0\0000123456789\0\0\0"; /* 0x50 - 0x5f */
67 static unsigned char xmon_shift_keytab
[128] =
68 "ASDFHGZXCV\000BQWER" /* 0x00 - 0x0f */
69 "YT!@#$^%+(&_*)}O" /* 0x10 - 0x1f */
70 "U{IP\rLJ\"K:|<?NM>" /* 0x20 - 0x2f */
71 "\t ~\177\0\033\0\0\0\0\0\0\0\0\0\0" /* 0x30 - 0x3f */
72 "\0.\0*\0+\0\0\0\0\0/\r\0-\0" /* 0x40 - 0x4f */
73 "\0\0000123456789\0\0\0"; /* 0x50 - 0x5f */
75 static int udbg_adb_local_getc(void)
81 xmon_adb_keycode
= -1;
88 btext_drawchar(on
? 0xdb: 0x20);
93 if (udbg_adb_old_getc_poll
)
94 k
= udbg_adb_old_getc_poll();
95 } while (k
== -1 && xmon_adb_keycode
== -1);
97 btext_drawstring(" \b");
100 k
= xmon_adb_keycode
;
102 /* test for shift keys */
103 if ((k
& 0x7f) == 0x38 || (k
& 0x7f) == 0x7b) {
104 xmon_adb_shiftstate
= (k
& 0x80) == 0;
108 continue; /* ignore up transitions */
109 k
= (xmon_adb_shiftstate
? xmon_shift_keytab
: xmon_keytab
)[k
];
116 #endif /* CONFIG_BOOTX_TEXT */
118 static int udbg_adb_getc(void)
120 #ifdef CONFIG_BOOTX_TEXT
121 if (udbg_adb_use_btext
&& input_type
!= input_adb_none
)
122 return udbg_adb_local_getc();
124 if (udbg_adb_old_getc
)
125 return udbg_adb_old_getc();
129 /* getc_poll() is not really used, unless you have the xmon-over modem
130 * hack that doesn't quite concern us here, thus we just poll the low level
131 * ADB driver to prevent it from timing out and call back the original poll
134 static int udbg_adb_getc_poll(void)
138 if (udbg_adb_old_getc_poll
)
139 return udbg_adb_old_getc_poll();
143 static void udbg_adb_putc(char c
)
145 #ifdef CONFIG_BOOTX_TEXT
146 if (udbg_adb_use_btext
)
149 if (udbg_adb_old_putc
)
150 return udbg_adb_old_putc(c
);
153 void __init
udbg_adb_init_early(void)
155 #ifdef CONFIG_BOOTX_TEXT
156 if (btext_find_display(1) == 0) {
157 udbg_adb_use_btext
= 1;
158 udbg_putc
= udbg_adb_putc
;
163 int __init
udbg_adb_init(int force_btext
)
165 struct device_node
*np
;
167 /* Capture existing callbacks */
168 udbg_adb_old_putc
= udbg_putc
;
169 udbg_adb_old_getc
= udbg_getc
;
170 udbg_adb_old_getc_poll
= udbg_getc_poll
;
172 /* Check if our early init was already called */
173 if (udbg_adb_old_putc
== udbg_adb_putc
)
174 udbg_adb_old_putc
= NULL
;
175 #ifdef CONFIG_BOOTX_TEXT
176 if (udbg_adb_old_putc
== btext_drawchar
)
177 udbg_adb_old_putc
= NULL
;
180 /* Set ours as output */
181 udbg_putc
= udbg_adb_putc
;
182 udbg_getc
= udbg_adb_getc
;
183 udbg_getc_poll
= udbg_adb_getc_poll
;
185 #ifdef CONFIG_BOOTX_TEXT
186 /* Check if we should use btext output */
187 if (btext_find_display(force_btext
) == 0)
188 udbg_adb_use_btext
= 1;
191 /* See if there is a keyboard in the device tree with a parent
192 * of type "adb". If not, we return a failure, but we keep the
193 * bext output set for now
195 for_each_node_by_name(np
, "keyboard") {
196 struct device_node
*parent
= of_get_parent(np
);
197 int found
= (parent
&& strcmp(parent
->type
, "adb") == 0);
206 #ifdef CONFIG_ADB_PMU
208 input_type
= input_adb_pmu
;
210 #ifdef CONFIG_ADB_CUDA
212 input_type
= input_adb_cuda
;
215 /* Same as above: nothing found, keep btext set for output */
216 if (input_type
== input_adb_none
)