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