Rev 1625 | Rev 1633 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 982 | decky | 1 | /* |
| 2 | * Copyright (C) 2006 Martin Decky |
||
| 3 | * All rights reserved. |
||
| 4 | * |
||
| 5 | * Redistribution and use in source and binary forms, with or without |
||
| 6 | * modification, are permitted provided that the following conditions |
||
| 7 | * are met: |
||
| 8 | * |
||
| 9 | * - Redistributions of source code must retain the above copyright |
||
| 10 | * notice, this list of conditions and the following disclaimer. |
||
| 11 | * - Redistributions in binary form must reproduce the above copyright |
||
| 12 | * notice, this list of conditions and the following disclaimer in the |
||
| 13 | * documentation and/or other materials provided with the distribution. |
||
| 14 | * - The name of the author may not be used to endorse or promote products |
||
| 15 | * derived from this software without specific prior written permission. |
||
| 16 | * |
||
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
| 27 | */ |
||
| 28 | |||
| 29 | #include <arch/drivers/cuda.h> |
||
| 30 | #include <arch/asm.h> |
||
| 987 | decky | 31 | #include <console/console.h> |
| 1628 | decky | 32 | #include <console/chardev.h> |
| 1480 | palkovsky | 33 | #include <arch/drivers/pic.h> |
| 1625 | decky | 34 | #include <sysinfo/sysinfo.h> |
| 1480 | palkovsky | 35 | #include <interrupt.h> |
| 1619 | decky | 36 | #include <stdarg.h> |
| 982 | decky | 37 | |
| 1619 | decky | 38 | #define PACKET_ADB 0x00 |
| 39 | #define PACKET_CUDA 0x01 |
||
| 40 | |||
| 982 | decky | 41 | #define CUDA_POWERDOWN 0x0a |
| 42 | |||
| 43 | #define RS 0x200 |
||
| 44 | #define B (0 * RS) |
||
| 45 | #define A (1 * RS) |
||
| 46 | #define SR (10 * RS) |
||
| 47 | #define ACR (11 * RS) |
||
| 48 | |||
| 49 | #define SR_OUT 0x10 |
||
| 50 | #define TACK 0x10 |
||
| 51 | #define TIP 0x20 |
||
| 52 | |||
| 53 | |||
| 1619 | decky | 54 | static volatile __u8 *cuda = NULL; |
| 982 | decky | 55 | |
| 1606 | decky | 56 | |
| 1619 | decky | 57 | static char lchars[0x80] = { |
| 58 | 'a', 's', 'd', 'f', 'h', 'g', 'z', 'x', 'c', 'v', 0, 'b', 'q', 'w', 'e', 'r', |
||
| 59 | 'y', 't', '1', '2', '3', '4', '6', '5', '=', '9', '7', '-', '8', '0', ']', 'o', |
||
| 60 | 'u', '[', 'i', 'p', 13, 'l', 'j', '\'', 'k', ';', '\\', ',', '/', 'n', 'm', '.', |
||
| 61 | 9, 32, '`', 8, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||
| 62 | 0, '.', 0, '*', 0, '+', 0, 0, 0, 0, 0, '/', 13, 0, '-', 0, |
||
| 63 | 0, 0, '0', '1', '2', '3', '4', '5', '6', '7', 0, '8', '9', 0, 0, 0, |
||
| 64 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
||
| 65 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
||
| 66 | }; |
||
| 67 | |||
| 68 | |||
| 1628 | decky | 69 | void send_packet(const __u8 kind, index_t count, ...); |
| 1619 | decky | 70 | |
| 71 | |||
| 72 | static void receive_packet(__u8 *kind, index_t count, __u8 data[]) |
||
| 73 | { |
||
| 74 | cuda[B] = cuda[B] & ~TIP; |
||
| 75 | *kind = cuda[SR]; |
||
| 76 | |||
| 77 | index_t i; |
||
| 78 | for (i = 0; i < count; i++) |
||
| 79 | data[i] = cuda[SR]; |
||
| 80 | |||
| 81 | cuda[B] = cuda[B] | TIP; |
||
| 82 | } |
||
| 83 | |||
| 84 | |||
| 1606 | decky | 85 | /* Called from getc(). */ |
| 86 | static void cuda_resume(chardev_t *d) |
||
| 87 | { |
||
| 88 | } |
||
| 89 | |||
| 90 | |||
| 91 | /* Called from getc(). */ |
||
| 92 | static void cuda_suspend(chardev_t *d) |
||
| 93 | { |
||
| 94 | } |
||
| 95 | |||
| 96 | |||
| 97 | static char key_read(chardev_t *d) |
||
| 98 | { |
||
| 99 | char ch; |
||
| 100 | |||
| 101 | ch = 0; |
||
| 102 | return ch; |
||
| 103 | } |
||
| 104 | |||
| 105 | |||
| 1628 | decky | 106 | static chardev_t kbrd; |
| 1606 | decky | 107 | static chardev_operations_t ops = { |
| 108 | .suspend = cuda_suspend, |
||
| 109 | .resume = cuda_resume, |
||
| 110 | .read = key_read |
||
| 111 | }; |
||
| 112 | |||
| 1619 | decky | 113 | |
| 1628 | decky | 114 | __u8 cuda_get_scancode(void) |
| 1480 | palkovsky | 115 | { |
| 1619 | decky | 116 | __u8 kind; |
| 117 | __u8 data[4]; |
||
| 118 | |||
| 119 | receive_packet(&kind, 4, data); |
||
| 120 | |||
| 1628 | decky | 121 | if ((kind == PACKET_ADB) && (data[0] == 0x40) && (data[1] == 0x2c)) |
| 122 | return data[2]; |
||
| 123 | |||
| 124 | return 0; |
||
| 1480 | palkovsky | 125 | } |
| 982 | decky | 126 | |
| 1619 | decky | 127 | |
| 1628 | decky | 128 | static void cuda_irq(int n, istate_t *istate) |
| 129 | { |
||
| 130 | __u8 scancode = cuda_get_scancode(); |
||
| 131 | |||
| 132 | if ((scancode != 0) && ((scancode & 0x80) != 0x80)) |
||
| 133 | chardev_push_character(&kbrd, lchars[scancode & 0x7f]); |
||
| 134 | } |
||
| 135 | |||
| 136 | |||
| 1619 | decky | 137 | void cuda_init(__address base, size_t size) |
| 990 | decky | 138 | { |
| 1619 | decky | 139 | cuda = (__u8 *) hw_map(base, size); |
| 140 | |||
| 1480 | palkovsky | 141 | int_register(CUDA_IRQ, "cuda", cuda_irq); |
| 142 | pic_enable_interrupt(CUDA_IRQ); |
||
| 1606 | decky | 143 | |
| 144 | chardev_initialize("cuda_kbd", &kbrd, &ops); |
||
| 145 | stdin = &kbrd; |
||
| 1625 | decky | 146 | |
| 147 | sysinfo_set_item_val("cuda", NULL, true); |
||
| 148 | sysinfo_set_item_val("cuda.irq", NULL, CUDA_IRQ); |
||
| 990 | decky | 149 | } |
| 150 | |||
| 151 | |||
| 1628 | decky | 152 | void send_packet(const __u8 kind, index_t count, ...) |
| 153 | { |
||
| 154 | index_t i; |
||
| 155 | va_list va; |
||
| 156 | |||
| 157 | cuda[B] = cuda[B] | TIP; |
||
| 158 | cuda[ACR] = cuda[ACR] | SR_OUT; |
||
| 159 | cuda[SR] = kind; |
||
| 160 | cuda[B] = cuda[B] & ~TIP; |
||
| 161 | |||
| 162 | va_start(va, count); |
||
| 163 | |||
| 164 | for (i = 0; i < count; i++) { |
||
| 165 | cuda[ACR] = cuda[ACR] | SR_OUT; |
||
| 166 | cuda[SR] = va_arg(va, int); |
||
| 167 | cuda[B] = cuda[B] | TACK; |
||
| 168 | } |
||
| 169 | |||
| 170 | va_end(va); |
||
| 171 | |||
| 172 | cuda[B] = cuda[B] | TIP; |
||
| 173 | } |
||
| 174 | |||
| 175 | |||
| 982 | decky | 176 | void cpu_halt(void) { |
| 1004 | decky | 177 | #ifdef CONFIG_POWEROFF |
| 1619 | decky | 178 | send_packet(PACKET_CUDA, 1, CUDA_POWERDOWN); |
| 179 | #endif |
||
| 1269 | decky | 180 | asm volatile ( |
| 181 | "b 0\n" |
||
| 182 | ); |
||
| 982 | decky | 183 | } |