19 #include <linux/kernel.h>
29 const void *
args[] = { (
void *)node };
30 void *
res[] = { &node };
35 if (olpc_ofw(
"peer", args, res) || (
s32)node == -1)
43 const void *args[] = { (
void *)node };
44 void *res[] = { &node };
49 if (olpc_ofw(
"child", args, res) || (
s32)node == -1) {
50 pr_err(
"PROM: %s: fetching child failed!\n", __func__);
57 static int __init olpc_dt_getproplen(
phandle node,
const char *prop)
59 const void *args[] = { (
void *)node, prop };
61 void *res[] = { &len };
66 if (olpc_ofw(
"getproplen", args, res)) {
67 pr_err(
"PROM: %s: getproplen failed!\n", __func__);
74 static int __init olpc_dt_getproperty(
phandle node,
const char *prop,
79 plen = olpc_dt_getproplen(node, prop);
80 if (plen > bufsize || plen < 1) {
83 const void *args[] = { (
void *)node, prop, buf, (
void *)plen };
84 void *res[] = { &plen };
86 if (olpc_ofw(
"getprop", args, res)) {
87 pr_err(
"PROM: %s: getprop failed!\n", __func__);
97 const void *args[] = { (
void *)node, prev, buf };
99 void *res[] = { &success };
106 if (olpc_ofw(
"nextprop", args, res) || success != 1)
113 const int buflen,
int *len)
115 const void *args[] = { (
void *)node, buf, (
void *)buflen };
116 void *res[] = { len };
121 if (olpc_ofw(
"package-to-path", args, res) || *len < 1)
132 static size_t free_mem;
135 if (free_mem < size) {
147 memset(res, 0, chunk_size);
148 free_mem = chunk_size;
159 static struct of_pdt_ops prom_olpc_ops __initdata = {
161 .getproplen = olpc_dt_getproplen,
162 .getproperty = olpc_dt_getproperty,
163 .getchild = olpc_dt_getchild,
164 .getsibling = olpc_dt_getsibling,
165 .pkg2path = olpc_dt_pkg2path,
171 const void *args[] = { path };
172 void *res[] = { &node };
174 if (olpc_ofw(
"finddevice", args, res)) {
175 pr_err(
"olpc_dt: finddevice failed!\n");
179 if ((
s32) node == -1)
185 static int __init olpc_dt_interpret(
const char *words)
188 const void *args[] = { words };
189 void *res[] = { &result };
191 if (olpc_ofw(
"interpret", args, res)) {
192 pr_err(
"olpc_dt: interpret failed!\n");
203 static u32 __init olpc_dt_get_board_revision(
void)
209 node = olpc_dt_finddevice(
"/");
213 r = olpc_dt_getproperty(node,
"board-revision-int",
214 (
char *) &rev,
sizeof(rev));
228 node = olpc_dt_finddevice(
"/battery@0");
236 r = olpc_dt_getproperty(node,
"compatible", buf,
sizeof(buf));
240 pr_info(
"PROM DT: Old firmware detected, applying fixes\n");
243 olpc_dt_interpret(
"\" /battery@0\" find-device"
244 " \" olpc,xo1-battery\" +compatible"
247 board_rev = olpc_dt_get_board_revision();
251 if (board_rev >= olpc_board_pre(0xd0)) {
253 olpc_dt_interpret(
"\" /pci/display@1\" find-device"
255 " \" dcon\" device-name \" olpc,xo1-dcon\" +compatible"
256 " finish-device device-end");
259 olpc_dt_interpret(
"\" /pci/display@1,1\" find-device"
261 " \" dcon\" device-name \" olpc,xo1-dcon\" +compatible"
262 " finish-device device-end"
263 " \" /rtc\" find-device"
264 " \" olpc,xo1-rtc\" +compatible"
278 root = olpc_dt_getsibling(0);
280 pr_err(
"PROM: unable to get root node from OFW!\n");
285 pr_info(
"PROM DT: Built device tree with %u bytes of memory.\n",
291 { .compatible =
"olpc,xo1-battery" },
292 { .compatible =
"olpc,xo1-dcon" },
293 { .compatible =
"olpc,xo1-rtc" },
297 static int __init olpc_create_platform_devices(
void)
299 if (machine_is_olpc())
300 return of_platform_bus_probe(
NULL, of_ids,
NULL);