1 #include <linux/config.h>
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/machdep.h>
17 #include <asm/errno.h>
18 #include <asm/pmac_feature.h>
19 #include <asm/processor.h>
20 #include <asm/delay.h>
21 #include <asm/btext.h>
26 * This implementation is "special", it can "patch" the current
27 * udbg implementation and work on top of it. It must thus be
31 static void (*udbg_adb_old_putc
)(char c
);
32 static int (*udbg_adb_old_getc
)(void);
33 static int (*udbg_adb_old_getc_poll
)(void);
39 } input_type
= input_adb_none
;
41 int xmon_wants_key
, xmon_adb_keycode
;
43 static inline void udbg_adb_poll(void)
46 if (input_type
== input_adb_pmu
)
48 #endif /* CONFIG_ADB_PMU */
49 #ifdef CONFIG_ADB_CUDA
50 if (input_type
== input_adb_cuda
)
52 #endif /* CONFIG_ADB_CUDA */
55 #ifdef CONFIG_BOOTX_TEXT
57 static int udbg_adb_use_btext
;
58 static int xmon_adb_shiftstate
;
60 static unsigned char xmon_keytab
[128] =
61 "asdfhgzxcv\000bqwer" /* 0x00 - 0x0f */
62 "yt123465=97-80]o" /* 0x10 - 0x1f */
63 "u[ip\rlj'k;\\,/nm." /* 0x20 - 0x2f */
64 "\t `\177\0\033\0\0\0\0\0\0\0\0\0\0" /* 0x30 - 0x3f */
65 "\0.\0*\0+\0\0\0\0\0/\r\0-\0" /* 0x40 - 0x4f */
66 "\0\0000123456789\0\0\0"; /* 0x50 - 0x5f */
68 static unsigned char xmon_shift_keytab
[128] =
69 "ASDFHGZXCV\000BQWER" /* 0x00 - 0x0f */
70 "YT!@#$^%+(&_*)}O" /* 0x10 - 0x1f */
71 "U{IP\rLJ\"K:|<?NM>" /* 0x20 - 0x2f */
72 "\t ~\177\0\033\0\0\0\0\0\0\0\0\0\0" /* 0x30 - 0x3f */
73 "\0.\0*\0+\0\0\0\0\0/\r\0-\0" /* 0x40 - 0x4f */
74 "\0\0000123456789\0\0\0"; /* 0x50 - 0x5f */
76 static int udbg_adb_local_getc(void)
82 xmon_adb_keycode
= -1;
89 btext_drawchar(on
? 0xdb: 0x20);
94 if (udbg_adb_old_getc_poll
)
95 k
= udbg_adb_old_getc_poll();
96 } while (k
== -1 && xmon_adb_keycode
== -1);
98 btext_drawstring(" \b");
101 k
= xmon_adb_keycode
;
103 /* test for shift keys */
104 if ((k
& 0x7f) == 0x38 || (k
& 0x7f) == 0x7b) {
105 xmon_adb_shiftstate
= (k
& 0x80) == 0;
109 continue; /* ignore up transitions */
110 k
= (xmon_adb_shiftstate
? xmon_shift_keytab
: xmon_keytab
)[k
];
117 #endif /* CONFIG_BOOTX_TEXT */
119 static int udbg_adb_getc(void)
121 #ifdef CONFIG_BOOTX_TEXT
122 if (udbg_adb_use_btext
&& input_type
!= input_adb_none
)
123 return udbg_adb_local_getc();
125 if (udbg_adb_old_getc
)
126 return udbg_adb_old_getc();
130 /* getc_poll() is not really used, unless you have the xmon-over modem
131 * hack that doesn't quite concern us here, thus we just poll the low level
132 * ADB driver to prevent it from timing out and call back the original poll
135 static int udbg_adb_getc_poll(void)
139 if (udbg_adb_old_getc_poll
)
140 return udbg_adb_old_getc_poll();
144 static void udbg_adb_putc(char c
)
146 #ifdef CONFIG_BOOTX_TEXT
147 if (udbg_adb_use_btext
)
150 if (udbg_adb_old_putc
)
151 return udbg_adb_old_putc(c
);
154 void udbg_adb_init_early(void)
156 #ifdef CONFIG_BOOTX_TEXT
157 if (btext_find_display(1) == 0) {
158 udbg_adb_use_btext
= 1;
159 udbg_putc
= udbg_adb_putc
;
164 int udbg_adb_init(int force_btext
)
166 struct device_node
*np
;
168 /* Capture existing callbacks */
169 udbg_adb_old_putc
= udbg_putc
;
170 udbg_adb_old_getc
= udbg_getc
;
171 udbg_adb_old_getc_poll
= udbg_getc_poll
;
173 /* Check if our early init was already called */
174 if (udbg_adb_old_putc
== udbg_adb_putc
)
175 udbg_adb_old_putc
= NULL
;
176 #ifdef CONFIG_BOOTX_TEXT
177 if (udbg_adb_old_putc
== btext_drawchar
)
178 udbg_adb_old_putc
= NULL
;
181 /* Set ours as output */
182 udbg_putc
= udbg_adb_putc
;
183 udbg_getc
= udbg_adb_getc
;
184 udbg_getc_poll
= udbg_adb_getc_poll
;
186 #ifdef CONFIG_BOOTX_TEXT
187 /* Check if we should use btext output */
188 if (btext_find_display(force_btext
) == 0)
189 udbg_adb_use_btext
= 1;
192 /* See if there is a keyboard in the device tree with a parent
193 * of type "adb". If not, we return a failure, but we keep the
194 * bext output set for now
196 for (np
= NULL
; (np
= of_find_node_by_name(np
, "keyboard")) != NULL
;) {
197 struct device_node
*parent
= of_get_parent(np
);
198 int found
= (parent
&& strcmp(parent
->type
, "adb") == 0);
207 #ifdef CONFIG_ADB_PMU
209 input_type
= input_adb_pmu
;
211 #ifdef CONFIG_ADB_CUDA
213 input_type
= input_adb_cuda
;
216 /* Same as above: nothing found, keep btext set for output */
217 if (input_type
== input_adb_none
)