1 #include <linux/string.h>
2 #include <linux/kernel.h>
3 #include <linux/errno.h>
4 #include <linux/bitops.h>
5 #include <linux/ptrace.h>
8 #include <linux/cuda.h>
9 #include <asm/machdep.h>
14 #include <asm/bootx.h>
15 #include <asm/errno.h>
16 #include <asm/pmac_feature.h>
17 #include <asm/processor.h>
18 #include <asm/delay.h>
19 #include <asm/btext.h>
24 * This implementation is "special", it can "patch" the current
25 * udbg implementation and work on top of it. It must thus be
29 static void (*udbg_adb_old_putc
)(char c
);
30 static int (*udbg_adb_old_getc
)(void);
31 static int (*udbg_adb_old_getc_poll
)(void);
37 } input_type
= input_adb_none
;
39 int xmon_wants_key
, xmon_adb_keycode
;
41 static inline void udbg_adb_poll(void)
44 if (input_type
== input_adb_pmu
)
46 #endif /* CONFIG_ADB_PMU */
47 #ifdef CONFIG_ADB_CUDA
48 if (input_type
== input_adb_cuda
)
50 #endif /* CONFIG_ADB_CUDA */
53 #ifdef CONFIG_BOOTX_TEXT
55 static int udbg_adb_use_btext
;
56 static int xmon_adb_shiftstate
;
58 static unsigned char xmon_keytab
[128] =
59 "asdfhgzxcv\000bqwer" /* 0x00 - 0x0f */
60 "yt123465=97-80]o" /* 0x10 - 0x1f */
61 "u[ip\rlj'k;\\,/nm." /* 0x20 - 0x2f */
62 "\t `\177\0\033\0\0\0\0\0\0\0\0\0\0" /* 0x30 - 0x3f */
63 "\0.\0*\0+\0\0\0\0\0/\r\0-\0" /* 0x40 - 0x4f */
64 "\0\0000123456789\0\0\0"; /* 0x50 - 0x5f */
66 static unsigned char xmon_shift_keytab
[128] =
67 "ASDFHGZXCV\000BQWER" /* 0x00 - 0x0f */
68 "YT!@#$^%+(&_*)}O" /* 0x10 - 0x1f */
69 "U{IP\rLJ\"K:|<?NM>" /* 0x20 - 0x2f */
70 "\t ~\177\0\033\0\0\0\0\0\0\0\0\0\0" /* 0x30 - 0x3f */
71 "\0.\0*\0+\0\0\0\0\0/\r\0-\0" /* 0x40 - 0x4f */
72 "\0\0000123456789\0\0\0"; /* 0x50 - 0x5f */
74 static int udbg_adb_local_getc(void)
80 xmon_adb_keycode
= -1;
87 btext_drawchar(on
? 0xdb: 0x20);
92 if (udbg_adb_old_getc_poll
)
93 k
= udbg_adb_old_getc_poll();
94 } while (k
== -1 && xmon_adb_keycode
== -1);
96 btext_drawstring(" \b");
101 /* test for shift keys */
102 if ((k
& 0x7f) == 0x38 || (k
& 0x7f) == 0x7b) {
103 xmon_adb_shiftstate
= (k
& 0x80) == 0;
107 continue; /* ignore up transitions */
108 k
= (xmon_adb_shiftstate
? xmon_shift_keytab
: xmon_keytab
)[k
];
115 #endif /* CONFIG_BOOTX_TEXT */
117 static int udbg_adb_getc(void)
119 #ifdef CONFIG_BOOTX_TEXT
120 if (udbg_adb_use_btext
&& input_type
!= input_adb_none
)
121 return udbg_adb_local_getc();
123 if (udbg_adb_old_getc
)
124 return udbg_adb_old_getc();
128 /* getc_poll() is not really used, unless you have the xmon-over modem
129 * hack that doesn't quite concern us here, thus we just poll the low level
130 * ADB driver to prevent it from timing out and call back the original poll
133 static int udbg_adb_getc_poll(void)
137 if (udbg_adb_old_getc_poll
)
138 return udbg_adb_old_getc_poll();
142 static void udbg_adb_putc(char c
)
144 #ifdef CONFIG_BOOTX_TEXT
145 if (udbg_adb_use_btext
)
148 if (udbg_adb_old_putc
)
149 return udbg_adb_old_putc(c
);
152 void __init
udbg_adb_init_early(void)
154 #ifdef CONFIG_BOOTX_TEXT
155 if (btext_find_display(1) == 0) {
156 udbg_adb_use_btext
= 1;
157 udbg_putc
= udbg_adb_putc
;
162 int __init
udbg_adb_init(int force_btext
)
164 struct device_node
*np
;
166 /* Capture existing callbacks */
167 udbg_adb_old_putc
= udbg_putc
;
168 udbg_adb_old_getc
= udbg_getc
;
169 udbg_adb_old_getc_poll
= udbg_getc_poll
;
171 /* Check if our early init was already called */
172 if (udbg_adb_old_putc
== udbg_adb_putc
)
173 udbg_adb_old_putc
= NULL
;
174 #ifdef CONFIG_BOOTX_TEXT
175 if (udbg_adb_old_putc
== btext_drawchar
)
176 udbg_adb_old_putc
= NULL
;
179 /* Set ours as output */
180 udbg_putc
= udbg_adb_putc
;
181 udbg_getc
= udbg_adb_getc
;
182 udbg_getc_poll
= udbg_adb_getc_poll
;
184 #ifdef CONFIG_BOOTX_TEXT
185 /* Check if we should use btext output */
186 if (btext_find_display(force_btext
) == 0)
187 udbg_adb_use_btext
= 1;
190 /* See if there is a keyboard in the device tree with a parent
191 * of type "adb". If not, we return a failure, but we keep the
192 * bext output set for now
194 for (np
= NULL
; (np
= of_find_node_by_name(np
, "keyboard")) != NULL
;) {
195 struct device_node
*parent
= of_get_parent(np
);
196 int found
= (parent
&& strcmp(parent
->type
, "adb") == 0);
205 #ifdef CONFIG_ADB_PMU
207 input_type
= input_adb_pmu
;
209 #ifdef CONFIG_ADB_CUDA
211 input_type
= input_adb_cuda
;
214 /* Same as above: nothing found, keep btext set for output */
215 if (input_type
== input_adb_none
)