IEEE 1275 defined a standard "status" property to indicate the operational
status of a device. The property has four possible values: okay, disabled,
fail, fail-xxx. The absence of this property means the operational status
of the device is unknown or okay.
This adds a function called of_device_is_disabled that checks to see if a
node has the status property set to "disabled". This can be quite useful
for devices that may be present but disabled due to pin sharing, etc.
Signed-off-by: Josh Boyer <redacted>
---
drivers/of/base.c | 18 ++++++++++++++++++
include/linux/of.h | 1 +
2 files changed, 19 insertions(+)
Some SoC chips have multiple serial ports on board. The usability of these
ports can rely on various factors, ranging from pin sharing to unpopulated
connectors. This uses the new of_device_is_disabled function to check for
and ignore disabled UARTs.
Signed-off-by: Josh Boyer <redacted>
---
arch/powerpc/kernel/legacy_serial.c | 4 ++++
drivers/serial/of_serial.c | 5 +++++
2 files changed, 9 insertions(+)
@@ -72,6 +72,11 @@ static int __devinit of_platform_serial_intport_type;intret;+if(of_device_is_disabled(ofdev->node)){+dev_info(&ofdev->dev,"Disabled serial port. Ignored\n");+return-ENODEV;+}+if(of_find_property(ofdev->node,"used-by-rtas",NULL))return-EBUSY;---linux-2.6.orig/arch/powerpc/kernel/legacy_serial.c+++linux-2.6/arch/powerpc/kernel/legacy_serial.c
@@ -54,6 +54,10 @@ static int __init add_legacy_port(structu32clock=BASE_BAUD*16;intindex;+/* Check the status property if present. Ignore disabled devices */+if(of_device_is_disabled(np))+return-1;+/* get clock freq. if present */clk=of_get_property(np,"clock-frequency",NULL);if(clk&&*clk)
On Sat, 23 Feb 2008 15:58:23 -0600
Josh Boyer [off-list ref] wrote:
IEEE 1275 defined a standard "status" property to indicate the operational
status of a device. The property has four possible values: okay, disabled,
fail, fail-xxx. The absence of this property means the operational status
of the device is unknown or okay.
This adds a function called of_device_is_disabled that checks to see if a
node has the status property set to "disabled". This can be quite useful
for devices that may be present but disabled due to pin sharing, etc.
Signed-off-by: Josh Boyer <redacted>
Talking with Ben H a bit, he suggested to reverse this API. Basically,
create an of_device_is_available that returns 1 if the status property
is completely missing, or if it's set to "okay" or "ok". The latter is
to cope with some broken firmwares.
I can do either really. Eventually you could embed the is_available
check in the of_platform code so that devices don't even get presented
to drivers if they aren't available.
Dave, I'm not sure how applicable this all is to sparc. But for some
of the "newer" embedded ports that are coming into powerpc I can see it
being very useful.
Thoughts?
josh
On Sat, 23 Feb 2008 18:59:04 -0600
Josh Boyer [off-list ref] wrote:
On Sat, 23 Feb 2008 15:58:23 -0600
Josh Boyer [off-list ref] wrote:
quoted
IEEE 1275 defined a standard "status" property to indicate the operational
status of a device. The property has four possible values: okay, disabled,
fail, fail-xxx. The absence of this property means the operational status
of the device is unknown or okay.
This adds a function called of_device_is_disabled that checks to see if a
node has the status property set to "disabled". This can be quite useful
for devices that may be present but disabled due to pin sharing, etc.
Signed-off-by: Josh Boyer <redacted>
Talking with Ben H a bit, he suggested to reverse this API. Basically,
create an of_device_is_available that returns 1 if the status property
is completely missing, or if it's set to "okay" or "ok". The latter is
to cope with some broken firmwares.
And since I seem to be talking to myself and have nothing better to do
on a Saturday evening, here's the code.
josh
IEEE 1275 defined a standard "status" property to indicate the operational
status of a device. The property has four possible values: okay, disabled,
fail, fail-xxx. The absence of this property means the operational status
of the device is unknown or okay.
This adds a function called of_device_is_available that checks the state
of the status property of a device. If the property is absent or set to
either "okay" or "ok", it returns 1. Otherwise it returns 0.
Signed-off-by: Josh Boyer <redacted>
---
drivers/of/base.c | 23 +++++++++++++++++++++++
include/linux/of.h | 1 +
2 files changed, 24 insertions(+)
Dave, I'm not sure how applicable this all is to sparc. But for some
of the "newer" embedded ports that are coming into powerpc I can see it
being very useful.
I think I've seen this property on sparc boxes too, I'm fine
with whatever you guys come up with.
On Sat, 23 Feb 2008 15:58:23 -0600
Josh Boyer [off-list ref] wrote:
quoted
IEEE 1275 defined a standard "status" property to indicate the operational
status of a device. The property has four possible values: okay, disabled,
fail, fail-xxx. The absence of this property means the operational status
of the device is unknown or okay.
This adds a function called of_device_is_disabled that checks to see if a
node has the status property set to "disabled". This can be quite useful
for devices that may be present but disabled due to pin sharing, etc.
Talking with Ben H a bit, he suggested to reverse this API. Basically,
create an of_device_is_available that returns 1 if the status property
is completely missing, or if it's set to "okay" or "ok". The latter is
to cope with some broken firmwares.
I agree with Ben's suggestion. The rtas_pci and eeh code could be
converted to use this, which gives a net savings of a few bytes with
ppc64_defconfig:
From: David Miller <davem@davemloft.net> Date: 2008-02-26 21:33:49
From: Paul Mackerras <redacted>
Date: Tue, 26 Feb 2008 20:04:12 +1100
It would probably be good to defend against the possibility that the
property isn't null-terminated (for example if its length is zero).
FWIW, when I pull in the device tree on sparc I eliminate any need for
those kinds of checks by putting a '\0' at the end of every property
blob.
I copied a lot of this code from you guys, so it wouldn't surprise
me if ppc does this too. :-)
From: Benjamin Herrenschmidt <benh@kernel.crashing.org> Date: 2008-02-26 21:46:13
On Tue, 2008-02-26 at 13:34 -0800, David Miller wrote:
From: Paul Mackerras <redacted>
Date: Tue, 26 Feb 2008 20:04:12 +1100
quoted
It would probably be good to defend against the possibility that the
property isn't null-terminated (for example if its length is zero).
FWIW, when I pull in the device tree on sparc I eliminate any need for
those kinds of checks by putting a '\0' at the end of every property
blob.
I copied a lot of this code from you guys, so it wouldn't surprise
me if ppc does this too. :-)
I doubt we do that. Properties that contain things like ranges, or "reg"
properties are expected to be of a size that is a multiple of
#size-cells/#address-cells and I'm not sure that won't break things here
or there if they suddenly get one more byte..
Or do you mean you/we are appending that-without- changing the length
field ?
Ben.
From: David Miller <davem@davemloft.net> Date: 2008-02-26 22:43:39
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Date: Wed, 27 Feb 2008 08:45:37 +1100
I doubt we do that. Properties that contain things like ranges, or "reg"
properties are expected to be of a size that is a multiple of
#size-cells/#address-cells and I'm not sure that won't break things here
or there if they suddenly get one more byte..
Or do you mean you/we are appending that-without- changing the length
field ?
Right, simply don't change the length field. Put the zero byte
at offset "length + 1"
It's stupid to validate NULL termination everywhere when we
can make it an invariant in one spot.
From: Benjamin Herrenschmidt <benh@kernel.crashing.org> Date: 2008-02-26 22:59:23
On Tue, 2008-02-26 at 14:44 -0800, David Miller wrote:
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Date: Wed, 27 Feb 2008 08:45:37 +1100
quoted
I doubt we do that. Properties that contain things like ranges, or "reg"
properties are expected to be of a size that is a multiple of
#size-cells/#address-cells and I'm not sure that won't break things here
or there if they suddenly get one more byte..
Or do you mean you/we are appending that-without- changing the length
field ?
Right, simply don't change the length field. Put the zero byte
at offset "length + 1"
It's stupid to validate NULL termination everywhere when we
can make it an invariant in one spot.
On Tue, 26 Feb 2008 14:44:23 -0800 (PST)
David Miller [off-list ref] wrote:
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Date: Wed, 27 Feb 2008 08:45:37 +1100
quoted
I doubt we do that. Properties that contain things like ranges, or "reg"
properties are expected to be of a size that is a multiple of
#size-cells/#address-cells and I'm not sure that won't break things here
or there if they suddenly get one more byte..
Or do you mean you/we are appending that-without- changing the length
field ?
Right, simply don't change the length field. Put the zero byte
at offset "length + 1"
It's stupid to validate NULL termination everywhere when we
can make it an invariant in one spot.
I don't mind fixing up the function to use strncmp and checking for a 0
length from of_get_property. However, I'm almost certain that other
places in the code have the same issue so what you're saying here seems
to make sense.
josh