* [RFC v2] OLPC: add missing elements to device tree
@ 2011-03-12 18:04 Daniel Drake
[not found] ` <20110312180448.572A49D401E-k/4jFdqg8LLlyo9zxV8I99HuzzzSOjJt@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Drake @ 2011-03-12 18:04 UTC (permalink / raw)
To: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ; +Cc: dilinger-pFFUokh25LWsTnJN9+BGXg
In response to new device tree code in the kernel, OLPC will start
using it for probing of certain devices. However, some firmware fixes
are needed to put the devicetree into a usable state.
Retain compatibility with old firmware by fixing up the device tree
at boot-time if it does not contain the new nodes/properties that
we need for probing.
Signed-off-by: Daniel Drake <dsd-2X9k7bc8m7Mdnm+yROfE0A@public.gmane.org>
---
arch/x86/platform/olpc/olpc_dt.c | 104 ++++++++++++++++++++++++++++++++++++++
1 files changed, 104 insertions(+), 0 deletions(-)
v2: ask OpenFirmware to adjust the tree instead of manipulating the tree
on the linux level.
diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
index 24f2598..d6ee929 100644
--- a/arch/x86/platform/olpc/olpc_dt.c
+++ b/arch/x86/platform/olpc/olpc_dt.c
@@ -21,6 +21,7 @@
#include <linux/of.h>
#include <linux/of_platform.h>
#include <linux/of_pdt.h>
+#include <asm/olpc.h>
#include <asm/olpc_ofw.h>
static phandle __init olpc_dt_getsibling(phandle node)
@@ -164,6 +165,107 @@ static struct of_pdt_ops prom_olpc_ops __initdata = {
.pkg2path = olpc_dt_pkg2path,
};
+static phandle __init olpc_dt_finddevice(const char *path)
+{
+ phandle node;
+ const void *args[] = { path };
+ void *res[] = { &node };
+
+ if (olpc_ofw("finddevice", args, res)) {
+ pr_err("olpc_dt: finddevice failed!\n");
+ return 0;
+ }
+
+ if ((s32) node == -1)
+ return 0;
+
+ return node;
+}
+
+static int __init olpc_dt_interpret(const char *words)
+{
+ int result;
+ const void *args[] = { words };
+ void *res[] = { &result };
+
+ if (olpc_ofw("interpret", args, res)) {
+ pr_err("olpc_dt: interpret failed!\n");
+ return -1;
+ }
+
+ return result;
+}
+
+/*
+ * Extract board revision directly from OFW device tree.
+ * We can't use olpc_platform_info because that hasn't been set up yet.
+ */
+static u32 __init olpc_dt_get_board_revision(void)
+{
+ phandle node;
+ __be32 rev;
+ int r;
+
+ node = olpc_dt_finddevice("/");
+ if (!node)
+ return 0;
+
+ r = olpc_dt_getproperty(node, "board-revision-int",
+ (char *) &rev, sizeof(rev));
+ if (r < 0)
+ return 0;
+
+ return be32_to_cpu(rev);
+}
+
+void __init olpc_dt_fixup(void)
+{
+ int r;
+ char buf[64];
+ phandle node;
+ u32 board_rev;
+
+ node = olpc_dt_finddevice("/battery@0");
+ if (!node)
+ return;
+
+ /*
+ * If the battery node has a compatible property, we are running a new
+ * enough firmware and don't have fixups to make.
+ */
+ r = olpc_dt_getproperty(node, "compatible", buf, sizeof(buf));
+ if (r > 0)
+ return;
+
+ pr_info("PROM DT: Old firmware detected, applying fixes\n");
+
+ /* Add olpc,xo1-battery compatible marker to battery node */
+ olpc_dt_interpret("\" /battery@0\" find-device"
+ " \" olpc,xo1-battery\" +compatible"
+ " device-end");
+
+ board_rev = olpc_dt_get_board_revision();
+ if (!board_rev)
+ return;
+
+ if (board_rev >= olpc_board_pre(0xd0)) {
+ /* XO-1.5: add dcon device */
+ olpc_dt_interpret("\" /pci/display@1\" find-device"
+ " new-device"
+ " \" dcon\" device-name \" olpc,xo1-dcon\" +compatible"
+ " finish-device device-end");
+ } else {
+ /* XO-1: add dcon device, mark RTC as olpc,xo1-rtc */
+ olpc_dt_interpret("\" /pci/display@1,1\" find-device"
+ " new-device"
+ " \" dcon\" device-name \" olpc,xo1-dcon\" +compatible"
+ " finish-device device-end"
+ " \" /rtc\" find-device"
+ " \" olpc,xo1-rtc\" +compatible"
+ " device-end");
+ }
+}
+
void __init olpc_dt_build_devicetree(void)
{
phandle root;
@@ -171,6 +273,8 @@ void __init olpc_dt_build_devicetree(void)
if (!olpc_ofw_is_installed())
return;
+ olpc_dt_fixup();
+
root = olpc_dt_getsibling(0);
if (!root) {
pr_err("PROM: unable to get root node from OFW!\n");
--
1.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [RFC v2] OLPC: add missing elements to device tree
[not found] ` <20110312180448.572A49D401E-k/4jFdqg8LLlyo9zxV8I99HuzzzSOjJt@public.gmane.org>
@ 2011-03-15 3:33 ` Grant Likely
[not found] ` <20110315033335.GC5600-MrY2KI0G/OVr83L8+7iqerDks+cytr/Z@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Grant Likely @ 2011-03-15 3:33 UTC (permalink / raw)
To: Daniel Drake
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
dilinger-pFFUokh25LWsTnJN9+BGXg
On Sat, Mar 12, 2011 at 06:04:48PM +0000, Daniel Drake wrote:
> In response to new device tree code in the kernel, OLPC will start
> using it for probing of certain devices. However, some firmware fixes
> are needed to put the devicetree into a usable state.
>
> Retain compatibility with old firmware by fixing up the device tree
> at boot-time if it does not contain the new nodes/properties that
> we need for probing.
>
> Signed-off-by: Daniel Drake <dsd-2X9k7bc8m7Mdnm+yROfE0A@public.gmane.org>
Looks okay to me.
Acked-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
g.
> ---
> arch/x86/platform/olpc/olpc_dt.c | 104 ++++++++++++++++++++++++++++++++++++++
> 1 files changed, 104 insertions(+), 0 deletions(-)
>
> v2: ask OpenFirmware to adjust the tree instead of manipulating the tree
> on the linux level.
>
> diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
> index 24f2598..d6ee929 100644
> --- a/arch/x86/platform/olpc/olpc_dt.c
> +++ b/arch/x86/platform/olpc/olpc_dt.c
> @@ -21,6 +21,7 @@
> #include <linux/of.h>
> #include <linux/of_platform.h>
> #include <linux/of_pdt.h>
> +#include <asm/olpc.h>
> #include <asm/olpc_ofw.h>
>
> static phandle __init olpc_dt_getsibling(phandle node)
> @@ -164,6 +165,107 @@ static struct of_pdt_ops prom_olpc_ops __initdata = {
> .pkg2path = olpc_dt_pkg2path,
> };
>
> +static phandle __init olpc_dt_finddevice(const char *path)
> +{
> + phandle node;
> + const void *args[] = { path };
> + void *res[] = { &node };
> +
> + if (olpc_ofw("finddevice", args, res)) {
> + pr_err("olpc_dt: finddevice failed!\n");
> + return 0;
> + }
> +
> + if ((s32) node == -1)
> + return 0;
> +
> + return node;
> +}
> +
> +static int __init olpc_dt_interpret(const char *words)
> +{
> + int result;
> + const void *args[] = { words };
> + void *res[] = { &result };
> +
> + if (olpc_ofw("interpret", args, res)) {
> + pr_err("olpc_dt: interpret failed!\n");
> + return -1;
> + }
> +
> + return result;
> +}
> +
> +/*
> + * Extract board revision directly from OFW device tree.
> + * We can't use olpc_platform_info because that hasn't been set up yet.
> + */
> +static u32 __init olpc_dt_get_board_revision(void)
> +{
> + phandle node;
> + __be32 rev;
> + int r;
> +
> + node = olpc_dt_finddevice("/");
> + if (!node)
> + return 0;
> +
> + r = olpc_dt_getproperty(node, "board-revision-int",
> + (char *) &rev, sizeof(rev));
> + if (r < 0)
> + return 0;
> +
> + return be32_to_cpu(rev);
> +}
> +
> +void __init olpc_dt_fixup(void)
> +{
> + int r;
> + char buf[64];
> + phandle node;
> + u32 board_rev;
> +
> + node = olpc_dt_finddevice("/battery@0");
> + if (!node)
> + return;
> +
> + /*
> + * If the battery node has a compatible property, we are running a new
> + * enough firmware and don't have fixups to make.
> + */
> + r = olpc_dt_getproperty(node, "compatible", buf, sizeof(buf));
> + if (r > 0)
> + return;
> +
> + pr_info("PROM DT: Old firmware detected, applying fixes\n");
> +
> + /* Add olpc,xo1-battery compatible marker to battery node */
> + olpc_dt_interpret("\" /battery@0\" find-device"
> + " \" olpc,xo1-battery\" +compatible"
> + " device-end");
> +
> + board_rev = olpc_dt_get_board_revision();
> + if (!board_rev)
> + return;
> +
> + if (board_rev >= olpc_board_pre(0xd0)) {
> + /* XO-1.5: add dcon device */
> + olpc_dt_interpret("\" /pci/display@1\" find-device"
> + " new-device"
> + " \" dcon\" device-name \" olpc,xo1-dcon\" +compatible"
> + " finish-device device-end");
> + } else {
> + /* XO-1: add dcon device, mark RTC as olpc,xo1-rtc */
> + olpc_dt_interpret("\" /pci/display@1,1\" find-device"
> + " new-device"
> + " \" dcon\" device-name \" olpc,xo1-dcon\" +compatible"
> + " finish-device device-end"
> + " \" /rtc\" find-device"
> + " \" olpc,xo1-rtc\" +compatible"
> + " device-end");
> + }
> +}
> +
> void __init olpc_dt_build_devicetree(void)
> {
> phandle root;
> @@ -171,6 +273,8 @@ void __init olpc_dt_build_devicetree(void)
> if (!olpc_ofw_is_installed())
> return;
>
> + olpc_dt_fixup();
> +
> root = olpc_dt_getsibling(0);
> if (!root) {
> pr_err("PROM: unable to get root node from OFW!\n");
> --
> 1.7.4
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFC v2] OLPC: add missing elements to device tree
[not found] ` <20110315033335.GC5600-MrY2KI0G/OVr83L8+7iqerDks+cytr/Z@public.gmane.org>
@ 2011-03-15 22:27 ` Andres Salomon
0 siblings, 0 replies; 3+ messages in thread
From: Andres Salomon @ 2011-03-15 22:27 UTC (permalink / raw)
To: Grant Likely, Daniel Drake; +Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ
Looks good to me as well.
Acked-by: Andres Salomon <dilinger-pFFUokh25LWsTnJN9+BGXg@public.gmane.org>
This should probably be forwarded to the x86 folks.
On Mon, 14 Mar 2011
21:33:35 -0600 Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org> wrote:
> On Sat, Mar 12, 2011 at 06:04:48PM +0000, Daniel Drake wrote:
> > In response to new device tree code in the kernel, OLPC will start
> > using it for probing of certain devices. However, some firmware
> > fixes are needed to put the devicetree into a usable state.
> >
> > Retain compatibility with old firmware by fixing up the device tree
> > at boot-time if it does not contain the new nodes/properties that
> > we need for probing.
> >
> > Signed-off-by: Daniel Drake <dsd-2X9k7bc8m7Mdnm+yROfE0A@public.gmane.org>
>
> Looks okay to me.
>
> Acked-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
>
> g.
>
> > ---
> > arch/x86/platform/olpc/olpc_dt.c | 104
> > ++++++++++++++++++++++++++++++++++++++ 1 files changed, 104
> > insertions(+), 0 deletions(-)
> >
> > v2: ask OpenFirmware to adjust the tree instead of manipulating the
> > tree on the linux level.
> >
> > diff --git a/arch/x86/platform/olpc/olpc_dt.c
> > b/arch/x86/platform/olpc/olpc_dt.c index 24f2598..d6ee929 100644
> > --- a/arch/x86/platform/olpc/olpc_dt.c
> > +++ b/arch/x86/platform/olpc/olpc_dt.c
> > @@ -21,6 +21,7 @@
> > #include <linux/of.h>
> > #include <linux/of_platform.h>
> > #include <linux/of_pdt.h>
> > +#include <asm/olpc.h>
> > #include <asm/olpc_ofw.h>
> >
> > static phandle __init olpc_dt_getsibling(phandle node)
> > @@ -164,6 +165,107 @@ static struct of_pdt_ops prom_olpc_ops
> > __initdata = { .pkg2path = olpc_dt_pkg2path,
> > };
> >
> > +static phandle __init olpc_dt_finddevice(const char *path)
> > +{
> > + phandle node;
> > + const void *args[] = { path };
> > + void *res[] = { &node };
> > +
> > + if (olpc_ofw("finddevice", args, res)) {
> > + pr_err("olpc_dt: finddevice failed!\n");
> > + return 0;
> > + }
> > +
> > + if ((s32) node == -1)
> > + return 0;
> > +
> > + return node;
> > +}
> > +
> > +static int __init olpc_dt_interpret(const char *words)
> > +{
> > + int result;
> > + const void *args[] = { words };
> > + void *res[] = { &result };
> > +
> > + if (olpc_ofw("interpret", args, res)) {
> > + pr_err("olpc_dt: interpret failed!\n");
> > + return -1;
> > + }
> > +
> > + return result;
> > +}
> > +
> > +/*
> > + * Extract board revision directly from OFW device tree.
> > + * We can't use olpc_platform_info because that hasn't been set up
> > yet.
> > + */
> > +static u32 __init olpc_dt_get_board_revision(void)
> > +{
> > + phandle node;
> > + __be32 rev;
> > + int r;
> > +
> > + node = olpc_dt_finddevice("/");
> > + if (!node)
> > + return 0;
> > +
> > + r = olpc_dt_getproperty(node, "board-revision-int",
> > + (char *) &rev, sizeof(rev));
> > + if (r < 0)
> > + return 0;
> > +
> > + return be32_to_cpu(rev);
> > +}
> > +
> > +void __init olpc_dt_fixup(void)
> > +{
> > + int r;
> > + char buf[64];
> > + phandle node;
> > + u32 board_rev;
> > +
> > + node = olpc_dt_finddevice("/battery@0");
> > + if (!node)
> > + return;
> > +
> > + /*
> > + * If the battery node has a compatible property, we are
> > running a new
> > + * enough firmware and don't have fixups to make.
> > + */
> > + r = olpc_dt_getproperty(node, "compatible", buf,
> > sizeof(buf));
> > + if (r > 0)
> > + return;
> > +
> > + pr_info("PROM DT: Old firmware detected, applying
> > fixes\n"); +
> > + /* Add olpc,xo1-battery compatible marker to battery node
> > */
> > + olpc_dt_interpret("\" /battery@0\" find-device"
> > + " \" olpc,xo1-battery\" +compatible"
> > + " device-end");
> > +
> > + board_rev = olpc_dt_get_board_revision();
> > + if (!board_rev)
> > + return;
> > +
> > + if (board_rev >= olpc_board_pre(0xd0)) {
> > + /* XO-1.5: add dcon device */
> > + olpc_dt_interpret("\" /pci/display@1\" find-device"
> > + " new-device"
> > + " \" dcon\" device-name \" olpc,xo1-dcon\"
> > +compatible"
> > + " finish-device device-end");
> > + } else {
> > + /* XO-1: add dcon device, mark RTC as olpc,xo1-rtc
> > */
> > + olpc_dt_interpret("\" /pci/display@1,1\"
> > find-device"
> > + " new-device"
> > + " \" dcon\" device-name \" olpc,xo1-dcon\"
> > +compatible"
> > + " finish-device device-end"
> > + " \" /rtc\" find-device"
> > + " \" olpc,xo1-rtc\" +compatible"
> > + " device-end");
> > + }
> > +}
> > +
> > void __init olpc_dt_build_devicetree(void)
> > {
> > phandle root;
> > @@ -171,6 +273,8 @@ void __init olpc_dt_build_devicetree(void)
> > if (!olpc_ofw_is_installed())
> > return;
> >
> > + olpc_dt_fixup();
> > +
> > root = olpc_dt_getsibling(0);
> > if (!root) {
> > pr_err("PROM: unable to get root node from
> > OFW!\n"); --
> > 1.7.4
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-03-15 22:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-12 18:04 [RFC v2] OLPC: add missing elements to device tree Daniel Drake
[not found] ` <20110312180448.572A49D401E-k/4jFdqg8LLlyo9zxV8I99HuzzzSOjJt@public.gmane.org>
2011-03-15 3:33 ` Grant Likely
[not found] ` <20110315033335.GC5600-MrY2KI0G/OVr83L8+7iqerDks+cytr/Z@public.gmane.org>
2011-03-15 22:27 ` Andres Salomon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).