1f824d2f151e9664e25ddabce563561376647ee6
2 * arch/ubicom32/kernel/devtree.c
3 * Ubicom32 architecture device tree implementation.
5 * (C) Copyright 2009, Ubicom, Inc.
7 * This file is part of the Ubicom32 Linux Kernel Port.
9 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
10 * it and/or modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation, either version 2 of the
12 * License, or (at your option) any later version.
14 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
15 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with the Ubicom32 Linux Kernel Port. If not,
21 * see <http://www.gnu.org/licenses/>.
23 * Ubicom32 implementation derived from (with many thanks):
29 #include <linux/module.h>
30 #include <linux/kernel.h>
31 #include <linux/string.h>
32 #include <linux/errno.h>
33 #include <asm/devtree.h>
38 struct devtree_node
*devtree
;
42 * Print the device tree.
44 void devtree_print(void)
46 struct devtree_node
*p
= devtree
;
47 printk(KERN_INFO
"Device Tree:\n");
49 if (p
->magic
!= DEVTREE_NODE_MAGIC
) {
51 "device tree has improper node: %p\n", p
);
54 printk(KERN_INFO
"\t%p: sendirq=%03d, recvirq=%03d, "
55 " name=%s\n", p
, p
->sendirq
, p
->recvirq
, p
->name
);
59 EXPORT_SYMBOL(devtree_print
);
63 * Return the IRQ(s) associated with devtree node.
65 int devtree_irq(struct devtree_node
*dn
,
66 unsigned char *sendirq
,
67 unsigned char *recvirq
)
69 if (dn
->magic
!= DEVTREE_NODE_MAGIC
) {
70 printk(KERN_EMERG
"improper node: %p\n", dn
);
72 *sendirq
= DEVTREE_IRQ_NONE
;
75 *recvirq
= DEVTREE_IRQ_NONE
;
81 * Copy the devtree irq(s) to the output parameters.
84 *sendirq
= dn
->sendirq
;
87 *recvirq
= dn
->recvirq
;
91 EXPORT_SYMBOL(devtree_irq
);
95 * Provide an iterator for walking the device tree.
97 struct devtree_node
*devtree_find_next(struct devtree_node
**cur
)
99 struct devtree_node
*p
= *cur
;
110 * devtree_find_by_irq()
111 * Return the node associated with a given irq.
113 struct devtree_node
*devtree_find_by_irq(uint8_t sendirq
, uint8_t recvirq
)
115 struct devtree_node
*p
= devtree
;
117 if (sendirq
== recvirq
) {
118 printk(KERN_EMERG
"identical request makes no sense sendirq = "
119 "%d, recvirq= %d\n", sendirq
, recvirq
);
124 if (p
->magic
!= DEVTREE_NODE_MAGIC
) {
126 "device tree has improper node: %p\n", p
);
131 * See if we can find a match on the IRQ(s) specified.
133 if ((sendirq
== p
->sendirq
) && (recvirq
== p
->recvirq
)) {
137 if ((sendirq
== DEVTREE_IRQ_DONTCARE
) &&
138 (p
->recvirq
== recvirq
)) {
142 if ((recvirq
== DEVTREE_IRQ_DONTCARE
) &&
143 (p
->sendirq
== sendirq
)) {
151 EXPORT_SYMBOL(devtree_find_by_irq
);
154 * devtree_find_node()
155 * Find a node in the device tree by name.
157 struct devtree_node
*devtree_find_node(const char *str
)
159 struct devtree_node
*p
= devtree
;
161 if (p
->magic
!= DEVTREE_NODE_MAGIC
) {
163 "device tree has improper node: %p\n", p
);
166 if (strcmp(p
->name
, str
) == 0) {
173 EXPORT_SYMBOL(devtree_find_node
);