[82da5f5] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2006 Jakub Jermar
|
---|
[82da5f5] | 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 |
|
---|
[c5429fe] | 29 | /** @addtogroup kernel_sparc64
|
---|
[b45c443] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[287920f] | 35 | #include <arch/drivers/kbd.h>
|
---|
[28ecadb] | 36 | #include <genarch/ofw/ofw_tree.h>
|
---|
[e731b0d] | 37 | #include <genarch/ofw/ebus.h>
|
---|
| 38 | #include <console/console.h>
|
---|
| 39 | #include <ddi/irq.h>
|
---|
[387416b] | 40 | #include <mm/page.h>
|
---|
[e731b0d] | 41 | #include <arch/mm/page.h>
|
---|
[d4673296] | 42 | #include <mm/km.h>
|
---|
[d99c1d2] | 43 | #include <typedefs.h>
|
---|
[e731b0d] | 44 | #include <align.h>
|
---|
[19f857a] | 45 | #include <str.h>
|
---|
[b2fa1204] | 46 | #include <log.h>
|
---|
[e731b0d] | 47 | #include <sysinfo/sysinfo.h>
|
---|
[411b6a6] | 48 |
|
---|
| 49 | #ifdef CONFIG_SUN_KBD
|
---|
| 50 | #include <genarch/kbrd/kbrd.h>
|
---|
| 51 | #endif
|
---|
[e731b0d] | 52 |
|
---|
[8b4be29] | 53 | #ifdef CONFIG_NS16550
|
---|
[411b6a6] | 54 | #include <genarch/drivers/ns16550/ns16550.h>
|
---|
[da74747] | 55 | #endif
|
---|
[411b6a6] | 56 |
|
---|
[9693835] | 57 | #ifdef CONFIG_SUN_KBD
|
---|
[63b1537] | 58 |
|
---|
[c2417bc] | 59 | #ifdef CONFIG_NS16550
|
---|
| 60 |
|
---|
| 61 | static bool kbd_ns16550_init(ofw_tree_node_t *node)
|
---|
| 62 | {
|
---|
| 63 | const char *name = ofw_tree_node_name(node);
|
---|
[a35b458] | 64 |
|
---|
[c2417bc] | 65 | if (str_cmp(name, "su") != 0)
|
---|
| 66 | return false;
|
---|
[a35b458] | 67 |
|
---|
[0b414b5] | 68 | /*
|
---|
| 69 | * Read 'interrupts' property.
|
---|
| 70 | */
|
---|
[c2417bc] | 71 | ofw_tree_property_t *prop = ofw_tree_getprop(node, "interrupts");
|
---|
| 72 | if ((!prop) || (!prop->value)) {
|
---|
[b2fa1204] | 73 | log(LF_ARCH, LVL_ERROR,
|
---|
| 74 | "ns16550: Unable to find interrupts property");
|
---|
[c2417bc] | 75 | return false;
|
---|
| 76 | }
|
---|
[a35b458] | 77 |
|
---|
[c2417bc] | 78 | uint32_t interrupts = *((uint32_t *) prop->value);
|
---|
[a35b458] | 79 |
|
---|
[0b414b5] | 80 | /*
|
---|
| 81 | * Read 'reg' property.
|
---|
| 82 | */
|
---|
[28ecadb] | 83 | prop = ofw_tree_getprop(node, "reg");
|
---|
[c2417bc] | 84 | if ((!prop) || (!prop->value)) {
|
---|
[b2fa1204] | 85 | log(LF_ARCH, LVL_ERROR,
|
---|
| 86 | "ns16550: Unable to find reg property");
|
---|
[c2417bc] | 87 | return false;
|
---|
| 88 | }
|
---|
[a35b458] | 89 |
|
---|
[c2417bc] | 90 | size_t size = ((ofw_ebus_reg_t *) prop->value)->size;
|
---|
[a35b458] | 91 |
|
---|
[566da7f8] | 92 | uintptr_t pa = 0; // Prevent -Werror=maybe-uninitialized
|
---|
[c2417bc] | 93 | if (!ofw_ebus_apply_ranges(node->parent,
|
---|
| 94 | ((ofw_ebus_reg_t *) prop->value), &pa)) {
|
---|
[b2fa1204] | 95 | log(LF_ARCH, LVL_ERROR,
|
---|
| 96 | "ns16550: Failed to determine address");
|
---|
[c2417bc] | 97 | return false;
|
---|
| 98 | }
|
---|
[a35b458] | 99 |
|
---|
[c2417bc] | 100 | inr_t inr;
|
---|
| 101 | cir_t cir;
|
---|
| 102 | void *cir_arg;
|
---|
| 103 | if (!ofw_ebus_map_interrupt(node->parent,
|
---|
| 104 | ((ofw_ebus_reg_t *) prop->value), interrupts, &inr, &cir,
|
---|
| 105 | &cir_arg)) {
|
---|
[b2fa1204] | 106 | log(LF_ARCH, LVL_ERROR,
|
---|
| 107 | "ns16550: Failed to determine interrupt");
|
---|
[c2417bc] | 108 | return false;
|
---|
[28ecadb] | 109 | }
|
---|
[a35b458] | 110 |
|
---|
[7f7d642] | 111 | ioport8_t *ns16550 = (ioport8_t *) km_map(pa, size,
|
---|
| 112 | KM_NATURAL_ALIGNMENT, PAGE_WRITE | PAGE_NOT_CACHEABLE);
|
---|
[a35b458] | 113 |
|
---|
[38b0ae2] | 114 | ns16550_instance_t *ns16550_instance = ns16550_init(ns16550, 0, inr, cir,
|
---|
[21b6307] | 115 | cir_arg, NULL);
|
---|
[c2417bc] | 116 | if (ns16550_instance) {
|
---|
| 117 | kbrd_instance_t *kbrd_instance = kbrd_init();
|
---|
| 118 | if (kbrd_instance) {
|
---|
| 119 | indev_t *sink = stdin_wire();
|
---|
| 120 | indev_t *kbrd = kbrd_wire(kbrd_instance, sink);
|
---|
| 121 | ns16550_wire(ns16550_instance, kbrd);
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
[a35b458] | 124 |
|
---|
[c2417bc] | 125 | /*
|
---|
| 126 | * This is the necessary evil until the userspace drivers are
|
---|
| 127 | * entirely self-sufficient.
|
---|
| 128 | */
|
---|
| 129 | sysinfo_set_item_val("kbd", NULL, true);
|
---|
| 130 | sysinfo_set_item_val("kbd.inr", NULL, inr);
|
---|
| 131 | sysinfo_set_item_val("kbd.address.physical", NULL, pa);
|
---|
| 132 | sysinfo_set_item_val("kbd.type.ns16550", NULL, true);
|
---|
[a35b458] | 133 |
|
---|
[c2417bc] | 134 | return true;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | #endif /* CONFIG_NS16550 */
|
---|
| 138 |
|
---|
| 139 | /** Initialize keyboard.
|
---|
| 140 | *
|
---|
| 141 | * Traverse OpenFirmware device tree in order to find necessary
|
---|
| 142 | * info about the keyboard device.
|
---|
| 143 | *
|
---|
| 144 | * @param node Keyboard device node.
|
---|
| 145 | *
|
---|
| 146 | */
|
---|
| 147 | void kbd_init(ofw_tree_node_t *node)
|
---|
| 148 | {
|
---|
[8b4be29] | 149 | #ifdef CONFIG_NS16550
|
---|
[c2417bc] | 150 | kbd_ns16550_init(node);
|
---|
[da74747] | 151 | #endif
|
---|
[82da5f5] | 152 | }
|
---|
[b45c443] | 153 |
|
---|
[c2417bc] | 154 | #endif /* CONFIG_SUN_KBD */
|
---|
[9693835] | 155 |
|
---|
[0ffa3ef5] | 156 | /** @}
|
---|
[b45c443] | 157 | */
|
---|