Path: blob/master/arch/powerpc/platforms/powermac/udbg_adb.c
10818 views
#include <linux/string.h>1#include <linux/kernel.h>2#include <linux/errno.h>3#include <linux/bitops.h>4#include <linux/ptrace.h>5#include <linux/adb.h>6#include <linux/pmu.h>7#include <linux/cuda.h>8#include <asm/machdep.h>9#include <asm/io.h>10#include <asm/page.h>11#include <asm/xmon.h>12#include <asm/prom.h>13#include <asm/bootx.h>14#include <asm/errno.h>15#include <asm/pmac_feature.h>16#include <asm/processor.h>17#include <asm/delay.h>18#include <asm/btext.h>19#include <asm/time.h>20#include <asm/udbg.h>2122/*23* This implementation is "special", it can "patch" the current24* udbg implementation and work on top of it. It must thus be25* initialized last26*/2728static void (*udbg_adb_old_putc)(char c);29static int (*udbg_adb_old_getc)(void);30static int (*udbg_adb_old_getc_poll)(void);3132static enum {33input_adb_none,34input_adb_pmu,35input_adb_cuda,36} input_type = input_adb_none;3738int xmon_wants_key, xmon_adb_keycode;3940static inline void udbg_adb_poll(void)41{42#ifdef CONFIG_ADB_PMU43if (input_type == input_adb_pmu)44pmu_poll_adb();45#endif /* CONFIG_ADB_PMU */46#ifdef CONFIG_ADB_CUDA47if (input_type == input_adb_cuda)48cuda_poll();49#endif /* CONFIG_ADB_CUDA */50}5152#ifdef CONFIG_BOOTX_TEXT5354static int udbg_adb_use_btext;55static int xmon_adb_shiftstate;5657static unsigned char xmon_keytab[128] =58"asdfhgzxcv\000bqwer" /* 0x00 - 0x0f */59"yt123465=97-80]o" /* 0x10 - 0x1f */60"u[ip\rlj'k;\\,/nm." /* 0x20 - 0x2f */61"\t `\177\0\033\0\0\0\0\0\0\0\0\0\0" /* 0x30 - 0x3f */62"\0.\0*\0+\0\0\0\0\0/\r\0-\0" /* 0x40 - 0x4f */63"\0\0000123456789\0\0\0"; /* 0x50 - 0x5f */6465static unsigned char xmon_shift_keytab[128] =66"ASDFHGZXCV\000BQWER" /* 0x00 - 0x0f */67"YT!@#$^%+(&_*)}O" /* 0x10 - 0x1f */68"U{IP\rLJ\"K:|<?NM>" /* 0x20 - 0x2f */69"\t ~\177\0\033\0\0\0\0\0\0\0\0\0\0" /* 0x30 - 0x3f */70"\0.\0*\0+\0\0\0\0\0/\r\0-\0" /* 0x40 - 0x4f */71"\0\0000123456789\0\0\0"; /* 0x50 - 0x5f */7273static int udbg_adb_local_getc(void)74{75int k, t, on;7677xmon_wants_key = 1;78for (;;) {79xmon_adb_keycode = -1;80t = 0;81on = 0;82k = -1;83do {84if (--t < 0) {85on = 1 - on;86btext_drawchar(on? 0xdb: 0x20);87btext_drawchar('\b');88t = 200000;89}90udbg_adb_poll();91if (udbg_adb_old_getc_poll)92k = udbg_adb_old_getc_poll();93} while (k == -1 && xmon_adb_keycode == -1);94if (on)95btext_drawstring(" \b");96if (k != -1)97return k;98k = xmon_adb_keycode;99100/* test for shift keys */101if ((k & 0x7f) == 0x38 || (k & 0x7f) == 0x7b) {102xmon_adb_shiftstate = (k & 0x80) == 0;103continue;104}105if (k >= 0x80)106continue; /* ignore up transitions */107k = (xmon_adb_shiftstate? xmon_shift_keytab: xmon_keytab)[k];108if (k != 0)109break;110}111xmon_wants_key = 0;112return k;113}114#endif /* CONFIG_BOOTX_TEXT */115116static int udbg_adb_getc(void)117{118#ifdef CONFIG_BOOTX_TEXT119if (udbg_adb_use_btext && input_type != input_adb_none)120return udbg_adb_local_getc();121#endif122if (udbg_adb_old_getc)123return udbg_adb_old_getc();124return -1;125}126127/* getc_poll() is not really used, unless you have the xmon-over modem128* hack that doesn't quite concern us here, thus we just poll the low level129* ADB driver to prevent it from timing out and call back the original poll130* routine.131*/132static int udbg_adb_getc_poll(void)133{134udbg_adb_poll();135136if (udbg_adb_old_getc_poll)137return udbg_adb_old_getc_poll();138return -1;139}140141static void udbg_adb_putc(char c)142{143#ifdef CONFIG_BOOTX_TEXT144if (udbg_adb_use_btext)145btext_drawchar(c);146#endif147if (udbg_adb_old_putc)148return udbg_adb_old_putc(c);149}150151void __init udbg_adb_init_early(void)152{153#ifdef CONFIG_BOOTX_TEXT154if (btext_find_display(1) == 0) {155udbg_adb_use_btext = 1;156udbg_putc = udbg_adb_putc;157}158#endif159}160161int __init udbg_adb_init(int force_btext)162{163struct device_node *np;164165/* Capture existing callbacks */166udbg_adb_old_putc = udbg_putc;167udbg_adb_old_getc = udbg_getc;168udbg_adb_old_getc_poll = udbg_getc_poll;169170/* Check if our early init was already called */171if (udbg_adb_old_putc == udbg_adb_putc)172udbg_adb_old_putc = NULL;173#ifdef CONFIG_BOOTX_TEXT174if (udbg_adb_old_putc == btext_drawchar)175udbg_adb_old_putc = NULL;176#endif177178/* Set ours as output */179udbg_putc = udbg_adb_putc;180udbg_getc = udbg_adb_getc;181udbg_getc_poll = udbg_adb_getc_poll;182183#ifdef CONFIG_BOOTX_TEXT184/* Check if we should use btext output */185if (btext_find_display(force_btext) == 0)186udbg_adb_use_btext = 1;187#endif188189/* See if there is a keyboard in the device tree with a parent190* of type "adb". If not, we return a failure, but we keep the191* bext output set for now192*/193for (np = NULL; (np = of_find_node_by_name(np, "keyboard")) != NULL;) {194struct device_node *parent = of_get_parent(np);195int found = (parent && strcmp(parent->type, "adb") == 0);196of_node_put(parent);197if (found)198break;199}200if (np == NULL)201return -ENODEV;202of_node_put(np);203204#ifdef CONFIG_ADB_PMU205if (find_via_pmu())206input_type = input_adb_pmu;207#endif208#ifdef CONFIG_ADB_CUDA209if (find_via_cuda())210input_type = input_adb_cuda;211#endif212213/* Same as above: nothing found, keep btext set for output */214if (input_type == input_adb_none)215return -ENODEV;216217return 0;218}219220221