source: mainline/kernel/arch/sparc64/src/drivers/kbd.c@ 49160c4

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 49160c4 was 336d2f52, checked in by Jakub Jermar <jakub@…>, 14 years ago

Remove support for Sun hardware for which we have no test plan.

This includes the removal of the following functionality only available
via the Simics simulator, for which we have been unable to secure a
license:

  • FHC bus and interrupt controller
  • Zilog 8530 serial controller attached to Sun keyboard
  • Serengeti and SGCN support
  • Property mode set to 100644
File size: 4.4 KB
Line 
1/*
2 * Copyright (c) 2006 Jakub Jermar
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/** @addtogroup sparc64
30 * @{
31 */
32/** @file
33 */
34
35#include <arch/drivers/kbd.h>
36#include <genarch/ofw/ofw_tree.h>
37#include <genarch/ofw/ebus.h>
38#include <console/console.h>
39#include <ddi/irq.h>
40#include <mm/page.h>
41#include <arch/mm/page.h>
42#include <typedefs.h>
43#include <align.h>
44#include <str.h>
45#include <print.h>
46#include <sysinfo/sysinfo.h>
47
48#ifdef CONFIG_SUN_KBD
49#include <genarch/kbrd/kbrd.h>
50#endif
51
52#ifdef CONFIG_NS16550
53#include <genarch/drivers/ns16550/ns16550.h>
54#endif
55
56#ifdef CONFIG_SUN_KBD
57
58#ifdef CONFIG_NS16550
59
60static bool kbd_ns16550_init(ofw_tree_node_t *node)
61{
62 const char *name = ofw_tree_node_name(node);
63
64 if (str_cmp(name, "su") != 0)
65 return false;
66
67 /*
68 * Read 'interrupts' property.
69 */
70 ofw_tree_property_t *prop = ofw_tree_getprop(node, "interrupts");
71 if ((!prop) || (!prop->value)) {
72 printf("ns16550: Unable to find interrupts property\n");
73 return false;
74 }
75
76 uint32_t interrupts = *((uint32_t *) prop->value);
77
78 /*
79 * Read 'reg' property.
80 */
81 prop = ofw_tree_getprop(node, "reg");
82 if ((!prop) || (!prop->value)) {
83 printf("ns16550: Unable to find reg property\n");
84 return false;
85 }
86
87 size_t size = ((ofw_ebus_reg_t *) prop->value)->size;
88
89 uintptr_t pa;
90 if (!ofw_ebus_apply_ranges(node->parent,
91 ((ofw_ebus_reg_t *) prop->value), &pa)) {
92 printf("ns16550: Failed to determine address\n");
93 return false;
94 }
95
96 inr_t inr;
97 cir_t cir;
98 void *cir_arg;
99 if (!ofw_ebus_map_interrupt(node->parent,
100 ((ofw_ebus_reg_t *) prop->value), interrupts, &inr, &cir,
101 &cir_arg)) {
102 printf("ns16550: Failed to determine interrupt\n");
103 return false;
104 }
105
106 /*
107 * We need to pass aligned address to hw_map().
108 * However, the physical keyboard address can
109 * be pretty much unaligned, depending on the
110 * underlying controller.
111 */
112 uintptr_t aligned_addr = ALIGN_DOWN(pa, PAGE_SIZE);
113 size_t offset = pa - aligned_addr;
114
115 ns16550_t *ns16550 = (ns16550_t *)
116 (hw_map(aligned_addr, offset + size) + offset);
117
118 ns16550_instance_t *ns16550_instance = ns16550_init(ns16550, inr, cir, cir_arg);
119 if (ns16550_instance) {
120 kbrd_instance_t *kbrd_instance = kbrd_init();
121 if (kbrd_instance) {
122 indev_t *sink = stdin_wire();
123 indev_t *kbrd = kbrd_wire(kbrd_instance, sink);
124 ns16550_wire(ns16550_instance, kbrd);
125 }
126 }
127
128 /*
129 * This is the necessary evil until the userspace drivers are
130 * entirely self-sufficient.
131 */
132 sysinfo_set_item_val("kbd", NULL, true);
133 sysinfo_set_item_val("kbd.inr", NULL, inr);
134 sysinfo_set_item_val("kbd.address.kernel", NULL,
135 (uintptr_t) ns16550);
136 sysinfo_set_item_val("kbd.address.physical", NULL, pa);
137 sysinfo_set_item_val("kbd.type.ns16550", NULL, true);
138
139 return true;
140}
141
142#endif /* CONFIG_NS16550 */
143
144/** Initialize keyboard.
145 *
146 * Traverse OpenFirmware device tree in order to find necessary
147 * info about the keyboard device.
148 *
149 * @param node Keyboard device node.
150 *
151 */
152void kbd_init(ofw_tree_node_t *node)
153{
154#ifdef CONFIG_NS16550
155 kbd_ns16550_init(node);
156#endif
157}
158
159#endif /* CONFIG_SUN_KBD */
160
161/** @}
162 */
Note: See TracBrowser for help on using the repository browser.