* Re: spi_mpc8xxx.c: chip select polarity problem
@ 2009-11-26 12:12 ` Anton Vorontsov
0 siblings, 0 replies; 32+ messages in thread
From: Anton Vorontsov @ 2009-11-26 12:12 UTC (permalink / raw)
To: Grant Likely; +Cc: Torsten Fleischer, spi-devel-general, linuxppc-dev
On Wed, Nov 25, 2009 at 03:11:57PM -0700, Grant Likely wrote:
> On Wed, Nov 25, 2009 at 1:41 PM, Torsten Fleischer
> <to-fleischer@t-online.de> wrote:
> > On Wen, Nov 25, 2009 at 01:33:57 Grant Likely wrote:
> >> Thanks. However, there needs to be a proper description of what this
> >> patch does to go in the commit header. Can you please write one?
> >>
> >> Thanks,
> >> g.
> >>
> > [...]
> >
> > The initialization of the chip selects is removed from the probe() function of
> > the spi_mpc8xxx driver, because the driver doesn't know the polarity of the
> > chip selects of the SPI devices at the time of its initialization.
> >
> > For this reason the initialization of the several chip selects is postponed
> > to the point of time when the very first SPI transfer to the associated device
> > occurs.
> >
> >
> > Signed-off-by: Torsten Fleischer <to-fleischer@t-online.de>
>
> Ah. I understand what you're doing now. Hmmm. This approach
> concerns me because it relies on firmware or platform code to get CS
> gpios set up properly before the driver is probed.
Yes, that was said at the very beginning of this thread.
> Firmware doesn't
> always get it right, and I prefer to avoid platform specific setups as
> much as possible. Why can't the CS polarity be encoded into the
> device tree so the driver *does* have the polarity data at probe time?
We have the spi-cs-high property, but it duplicates compatible
property. 'compatible' is enough to tell whether some device has
cs-high or cs-low (device's driver knows that already).
The problem is that SPI bus master doesn't know all the devices,
so it can't extract that information from the compatible string.
To workaround that we can use 'spi-cs-high', but that's ugly
workaround.
SPI modes (0,1,2,3) is another matter, some devices can work in
several modes, so 'spi-cpol' and 'spi-cpha' are actually useful.
--
Anton Vorontsov
email: cbouatmailru@gmail.com
irc://irc.freenode.net/bd2
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: spi_mpc8xxx.c: chip select polarity problem
2009-11-26 12:12 ` Anton Vorontsov
(?)
@ 2009-11-26 17:27 ` Torsten Fleischer
2009-11-26 18:18 ` Grant Likely
-1 siblings, 1 reply; 32+ messages in thread
From: Torsten Fleischer @ 2009-11-26 17:27 UTC (permalink / raw)
To: avorontsov; +Cc: spi-devel-general, linuxppc-dev
On Thu, Nov 26, 2009 at 13:12:04 Anton Vorontsov wrote:
[...]
> > Ah. I understand what you're doing now. Hmmm. This approach
> > concerns me because it relies on firmware or platform code to get CS
> > gpios set up properly before the driver is probed.
>
> Yes, that was said at the very beginning of this thread.
>
> > Firmware doesn't
> > always get it right, and I prefer to avoid platform specific setups as
> > much as possible. Why can't the CS polarity be encoded into the
> > device tree so the driver *does* have the polarity data at probe time?
>
> We have the spi-cs-high property, but it duplicates compatible
> property. 'compatible' is enough to tell whether some device has
> cs-high or cs-low (device's driver knows that already).
>
> The problem is that SPI bus master doesn't know all the devices,
> so it can't extract that information from the compatible string.
> To workaround that we can use 'spi-cs-high', but that's ugly
> workaround.
>
> SPI modes (0,1,2,3) is another matter, some devices can work in
> several modes, so 'spi-cpol' and 'spi-cpha' are actually useful.
>
To get a sane initial state the needed GPIOs can be set to be inputs during
the driver's initialization.
This requires pull-up/pull-down resistors connected to the chip select
lines. I think we can assume that they exist, because the GPIOs are all inputs
after the controller's hardware reset and the resistors are needed to have a
well-defined voltage level on the chip select lines. Normally the level is set
so that the devices are disabled.
Therefore, it doesn't matter if the firmware sets the GPIOs wrong.
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: spi_mpc8xxx.c: chip select polarity problem
2009-11-26 17:27 ` Torsten Fleischer
@ 2009-11-26 18:18 ` Grant Likely
0 siblings, 0 replies; 32+ messages in thread
From: Grant Likely @ 2009-11-26 18:18 UTC (permalink / raw)
To: Torsten Fleischer; +Cc: spi-devel-general, linuxppc-dev
On Thu, Nov 26, 2009 at 10:27 AM, Torsten Fleischer
<to-fleischer@t-online.de> wrote:
> On Thu, Nov 26, 2009 at 13:12:04 Anton Vorontsov wrote:
> [...]
>> > Ah. I understand what you're doing now. Hmmm. This approach
>> > concerns me because it relies on firmware or platform code to get CS
>> > gpios set up properly before the driver is probed.
>>
>> Yes, that was said at the very beginning of this thread.
>>
>> > Firmware doesn't
>> > always get it right, and I prefer to avoid platform specific setups as
>> > much as possible. Why can't the CS polarity be encoded into the
>> > device tree so the driver *does* have the polarity data at probe time?
>>
>> We have the spi-cs-high property, but it duplicates compatible
>> property. 'compatible' is enough to tell whether some device has
>> cs-high or cs-low (device's driver knows that already).
>>
>> The problem is that SPI bus master doesn't know all the devices,
>> so it can't extract that information from the compatible string.
>> To workaround that we can use 'spi-cs-high', but that's ugly
>> workaround.
>>
>> SPI modes (0,1,2,3) is another matter, some devices can work in
>> several modes, so 'spi-cpol' and 'spi-cpha' are actually useful.
>>
> To get a sane initial state the needed GPIOs can be set to be inputs during
> the driver's initialization.
> This requires pull-up/pull-down resistors connected to the chip select
> lines. I think we can assume that they exist, because the GPIOs are all inputs
> after the controller's hardware reset and the resistors are needed to have a
> well-defined voltage level on the chip select lines. Normally the level is set
> so that the devices are disabled.
>
> Therefore, it doesn't matter if the firmware sets the GPIOs wrong.
No, that's just shifting responsibility from firmware to hardware.
There is just as much broken hardware out there as broken firmware.
The assumption cannot be made that the initial state of the pin is the
inactive state of the CS line. Plus, some GPIO pins are output only
and the inital state cannot be read.
g.
--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: spi_mpc8xxx.c: chip select polarity problem
@ 2009-11-26 18:18 ` Grant Likely
0 siblings, 0 replies; 32+ messages in thread
From: Grant Likely @ 2009-11-26 18:18 UTC (permalink / raw)
To: Torsten Fleischer; +Cc: spi-devel-general, linuxppc-dev
On Thu, Nov 26, 2009 at 10:27 AM, Torsten Fleischer
<to-fleischer@t-online.de> wrote:
> On Thu, Nov 26, 2009 at 13:12:04 Anton Vorontsov wrote:
> [...]
>> > Ah. =A0I understand what you're doing now. =A0 Hmmm. =A0This approach
>> > concerns me because it relies on firmware or platform code to get CS
>> > gpios set up properly before the driver is probed.
>>
>> Yes, that was said at the very beginning of this thread.
>>
>> > =A0Firmware doesn't
>> > always get it right, and I prefer to avoid platform specific setups as
>> > much as possible. =A0Why can't the CS polarity be encoded into the
>> > device tree so the driver *does* have the polarity data at probe time?
>>
>> We have the spi-cs-high property, but it duplicates compatible
>> property. 'compatible' is enough to tell whether some device has
>> cs-high or cs-low (device's driver knows that already).
>>
>> The problem is that SPI bus master doesn't know all the devices,
>> so it can't extract that information from the compatible string.
>> To workaround that we can use 'spi-cs-high', but that's ugly
>> workaround.
>>
>> SPI modes (0,1,2,3) is another matter, some devices can work in
>> several modes, so 'spi-cpol' and 'spi-cpha' are actually useful.
>>
> To get a sane initial state the needed GPIOs can be set to be inputs duri=
ng
> the driver's initialization.
> This requires pull-up/pull-down resistors connected to the chip select
> lines. I think we can assume that they exist, because the GPIOs are all i=
nputs
> after the controller's hardware reset and the resistors are needed to hav=
e a
> well-defined voltage level on the chip select lines. Normally the level i=
s set
> so that the devices are disabled.
>
> Therefore, it doesn't matter if the firmware sets the GPIOs wrong.
No, that's just shifting responsibility from firmware to hardware.
There is just as much broken hardware out there as broken firmware.
The assumption cannot be made that the initial state of the pin is the
inactive state of the CS line. Plus, some GPIO pins are output only
and the inital state cannot be read.
g.
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: spi_mpc8xxx.c: chip select polarity problem
2009-11-26 12:12 ` Anton Vorontsov
@ 2009-11-26 18:16 ` Grant Likely
-1 siblings, 0 replies; 32+ messages in thread
From: Grant Likely @ 2009-11-26 18:16 UTC (permalink / raw)
To: avorontsov; +Cc: Torsten Fleischer, spi-devel-general, linuxppc-dev
On Thu, Nov 26, 2009 at 5:12 AM, Anton Vorontsov
<avorontsov@ru.mvista.com> wrote:
> On Wed, Nov 25, 2009 at 03:11:57PM -0700, Grant Likely wrote:
>> On Wed, Nov 25, 2009 at 1:41 PM, Torsten Fleischer
>> <to-fleischer@t-online.de> wrote:
>> > On Wen, Nov 25, 2009 at 01:33:57 Grant Likely wrote:
>> >> Thanks. However, there needs to be a proper description of what this
>> >> patch does to go in the commit header. Can you please write one?
>> >>
>> >> Thanks,
>> >> g.
>> >>
>> > [...]
>> >
>> > The initialization of the chip selects is removed from the probe() function of
>> > the spi_mpc8xxx driver, because the driver doesn't know the polarity of the
>> > chip selects of the SPI devices at the time of its initialization.
>> >
>> > For this reason the initialization of the several chip selects is postponed
>> > to the point of time when the very first SPI transfer to the associated device
>> > occurs.
>> >
>> >
>> > Signed-off-by: Torsten Fleischer <to-fleischer@t-online.de>
>>
>> Ah. I understand what you're doing now. Hmmm. This approach
>> concerns me because it relies on firmware or platform code to get CS
>> gpios set up properly before the driver is probed.
>
> Yes, that was said at the very beginning of this thread.
I also came in part way through as I wasn't an SPI maintainer when
this thread started. :-)
>> Firmware doesn't
>> always get it right, and I prefer to avoid platform specific setups as
>> much as possible. Why can't the CS polarity be encoded into the
>> device tree so the driver *does* have the polarity data at probe time?
>
> We have the spi-cs-high property, but it duplicates compatible
> property. 'compatible' is enough to tell whether some device has
> cs-high or cs-low (device's driver knows that already).
But the device's driver isn't controlling the CS line, the SPI bus
driver is. Besides, there is no guarantee that all drivers will
actualy be loaded before something starts using SPI. The bus driver
*must* know what the active state of each CS line is before activating
any devices.
The spi bus binding is deficient in this case. A property (can be
optional) need to be added to the spi bus node to explicitly state the
CS polarities. It's not entirely sane to look for a "spi-cs-high'
property in the spi device nodes because the SPI bus may not be fully
populated (ie. if a device happens to be sitting on the bus, but isn't
in the device tree yet). Before any SPI transactions go out, it is
the responsibility of the bus driver to ensure all CS lines are in the
correct state.
> The problem is that SPI bus master doesn't know all the devices,
> so it can't extract that information from the compatible string.
> To workaround that we can use 'spi-cs-high', but that's ugly
> workaround.
It doesn't need to know about the devices, but is must know how all of
its CS lines behave. So it isn't an really an ugly workaround, but I
do think the binding is insufficient for the SPI bus driver (see
below)
> SPI modes (0,1,2,3) is another matter, some devices can work in
> several modes, so 'spi-cpol' and 'spi-cpha' are actually useful.
yes. spi-cpol and spi-cpha are actually properties of the device, and
belong in the spi device node, not the spi bus node.
The spi-cs-high property is defined in
Documentation/powerpc/dts-bindings/spi-bus.txt, but it definitely was
a mistake for the reasons I described above. It does work in some
cases, but a property at the bus node would be better. The driver can
still fallback to looking for spi-cs-high properties in child nodes.
Currently the spi-cs-high property is parsed in the
of_register_spi_devices() function, but the CS polarity needs to be
known before registering devices. It needs to be factored out into
another utility function callable by spi bus drivers so that it can
get polarity data at probe time.
Cheers,
g.
--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: spi_mpc8xxx.c: chip select polarity problem
@ 2009-11-26 18:16 ` Grant Likely
0 siblings, 0 replies; 32+ messages in thread
From: Grant Likely @ 2009-11-26 18:16 UTC (permalink / raw)
To: avorontsov; +Cc: Torsten Fleischer, spi-devel-general, linuxppc-dev
On Thu, Nov 26, 2009 at 5:12 AM, Anton Vorontsov
<avorontsov@ru.mvista.com> wrote:
> On Wed, Nov 25, 2009 at 03:11:57PM -0700, Grant Likely wrote:
>> On Wed, Nov 25, 2009 at 1:41 PM, Torsten Fleischer
>> <to-fleischer@t-online.de> wrote:
>> > On Wen, Nov 25, 2009 at 01:33:57 Grant Likely wrote:
>> >> Thanks. =A0However, there needs to be a proper description of what th=
is
>> >> patch does to go in the commit header. =A0Can you please write one?
>> >>
>> >> Thanks,
>> >> g.
>> >>
>> > [...]
>> >
>> > The initialization of the chip selects is removed from the probe() fun=
ction of
>> > the spi_mpc8xxx driver, because the driver doesn't know the polarity o=
f the
>> > chip selects of the SPI devices at the time of its initialization.
>> >
>> > For this reason the initialization of the several chip selects is post=
poned
>> > to the point of time when the very first SPI transfer to the associate=
d device
>> > occurs.
>> >
>> >
>> > Signed-off-by: Torsten Fleischer <to-fleischer@t-online.de>
>>
>> Ah. =A0I understand what you're doing now. =A0 Hmmm. =A0This approach
>> concerns me because it relies on firmware or platform code to get CS
>> gpios set up properly before the driver is probed.
>
> Yes, that was said at the very beginning of this thread.
I also came in part way through as I wasn't an SPI maintainer when
this thread started. :-)
>> =A0Firmware doesn't
>> always get it right, and I prefer to avoid platform specific setups as
>> much as possible. =A0Why can't the CS polarity be encoded into the
>> device tree so the driver *does* have the polarity data at probe time?
>
> We have the spi-cs-high property, but it duplicates compatible
> property. 'compatible' is enough to tell whether some device has
> cs-high or cs-low (device's driver knows that already).
But the device's driver isn't controlling the CS line, the SPI bus
driver is. Besides, there is no guarantee that all drivers will
actualy be loaded before something starts using SPI. The bus driver
*must* know what the active state of each CS line is before activating
any devices.
The spi bus binding is deficient in this case. A property (can be
optional) need to be added to the spi bus node to explicitly state the
CS polarities. It's not entirely sane to look for a "spi-cs-high'
property in the spi device nodes because the SPI bus may not be fully
populated (ie. if a device happens to be sitting on the bus, but isn't
in the device tree yet). Before any SPI transactions go out, it is
the responsibility of the bus driver to ensure all CS lines are in the
correct state.
> The problem is that SPI bus master doesn't know all the devices,
> so it can't extract that information from the compatible string.
> To workaround that we can use 'spi-cs-high', but that's ugly
> workaround.
It doesn't need to know about the devices, but is must know how all of
its CS lines behave. So it isn't an really an ugly workaround, but I
do think the binding is insufficient for the SPI bus driver (see
below)
> SPI modes (0,1,2,3) is another matter, some devices can work in
> several modes, so 'spi-cpol' and 'spi-cpha' are actually useful.
yes. spi-cpol and spi-cpha are actually properties of the device, and
belong in the spi device node, not the spi bus node.
The spi-cs-high property is defined in
Documentation/powerpc/dts-bindings/spi-bus.txt, but it definitely was
a mistake for the reasons I described above. It does work in some
cases, but a property at the bus node would be better. The driver can
still fallback to looking for spi-cs-high properties in child nodes.
Currently the spi-cs-high property is parsed in the
of_register_spi_devices() function, but the CS polarity needs to be
known before registering devices. It needs to be factored out into
another utility function callable by spi bus drivers so that it can
get polarity data at probe time.
Cheers,
g.
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: spi_mpc8xxx.c: chip select polarity problem
2009-11-26 18:16 ` Grant Likely
(?)
@ 2009-11-26 18:41 ` Anton Vorontsov
2009-11-26 18:50 ` Grant Likely
-1 siblings, 1 reply; 32+ messages in thread
From: Anton Vorontsov @ 2009-11-26 18:41 UTC (permalink / raw)
To: Grant Likely; +Cc: Torsten Fleischer, spi-devel-general, linuxppc-dev
On Thu, Nov 26, 2009 at 11:16:34AM -0700, Grant Likely wrote:
[...]
> The spi-cs-high property is defined in
> Documentation/powerpc/dts-bindings/spi-bus.txt, but it definitely was
> a mistake
Yup.
> Currently the spi-cs-high property is parsed in the
> of_register_spi_devices() function, but the CS polarity needs to be
> known before registering devices. It needs to be factored out into
> another utility function callable by spi bus drivers so that it can
> get polarity data at probe time.
Untill we have this, Torsten's patch is a real improvement, and
works for non-broken hw/fw.
So I think it should be applied.
Thanks,
--
Anton Vorontsov
email: cbouatmailru@gmail.com
irc://irc.freenode.net/bd2
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: spi_mpc8xxx.c: chip select polarity problem
2009-11-26 18:41 ` Anton Vorontsov
@ 2009-11-26 18:50 ` Grant Likely
0 siblings, 0 replies; 32+ messages in thread
From: Grant Likely @ 2009-11-26 18:50 UTC (permalink / raw)
To: avorontsov; +Cc: Torsten Fleischer, spi-devel-general, linuxppc-dev
On Thu, Nov 26, 2009 at 11:41 AM, Anton Vorontsov
<avorontsov@ru.mvista.com> wrote:
> On Thu, Nov 26, 2009 at 11:16:34AM -0700, Grant Likely wrote:
> [...]
>> The spi-cs-high property is defined in
>> Documentation/powerpc/dts-bindings/spi-bus.txt, but it definitely was
>> a mistake
>
> Yup.
>
>> Currently the spi-cs-high property is parsed in the
>> of_register_spi_devices() function, but the CS polarity needs to be
>> known before registering devices. It needs to be factored out into
>> another utility function callable by spi bus drivers so that it can
>> get polarity data at probe time.
>
> Untill we have this, Torsten's patch is a real improvement, and
> works for non-broken hw/fw.
>
> So I think it should be applied.
I disagree since it only band-aids the problem and uglifies the driver
in the process. In the immediate term the driver needs to be changed
to read the spi-cs-high property out of the child nodes before
registering the devices. I'm not going to apply this patch.
g.
--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: spi_mpc8xxx.c: chip select polarity problem
@ 2009-11-26 18:50 ` Grant Likely
0 siblings, 0 replies; 32+ messages in thread
From: Grant Likely @ 2009-11-26 18:50 UTC (permalink / raw)
To: avorontsov; +Cc: Torsten Fleischer, spi-devel-general, linuxppc-dev
On Thu, Nov 26, 2009 at 11:41 AM, Anton Vorontsov
<avorontsov@ru.mvista.com> wrote:
> On Thu, Nov 26, 2009 at 11:16:34AM -0700, Grant Likely wrote:
> [...]
>> The spi-cs-high property is defined in
>> Documentation/powerpc/dts-bindings/spi-bus.txt, but it definitely was
>> a mistake
>
> Yup.
>
>> Currently the spi-cs-high property is parsed in the
>> of_register_spi_devices() function, but the CS polarity needs to be
>> known before registering devices. =A0It needs to be factored out into
>> another utility function callable by spi bus drivers so that it can
>> get polarity data at probe time.
>
> Untill we have this, Torsten's patch is a real improvement, and
> works for non-broken hw/fw.
>
> So I think it should be applied.
I disagree since it only band-aids the problem and uglifies the driver
in the process. In the immediate term the driver needs to be changed
to read the spi-cs-high property out of the child nodes before
registering the devices. I'm not going to apply this patch.
g.
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: spi_mpc8xxx.c: chip select polarity problem
2009-11-26 18:50 ` Grant Likely
@ 2009-11-26 19:01 ` Anton Vorontsov
-1 siblings, 0 replies; 32+ messages in thread
From: Anton Vorontsov @ 2009-11-26 19:01 UTC (permalink / raw)
To: Grant Likely; +Cc: Torsten Fleischer, spi-devel-general, linuxppc-dev
On Thu, Nov 26, 2009 at 11:50:05AM -0700, Grant Likely wrote:
> On Thu, Nov 26, 2009 at 11:41 AM, Anton Vorontsov
> <avorontsov@ru.mvista.com> wrote:
> > On Thu, Nov 26, 2009 at 11:16:34AM -0700, Grant Likely wrote:
> > [...]
> >> The spi-cs-high property is defined in
> >> Documentation/powerpc/dts-bindings/spi-bus.txt, but it definitely was
> >> a mistake
> >
> > Yup.
> >
> >> Currently the spi-cs-high property is parsed in the
> >> of_register_spi_devices() function, but the CS polarity needs to be
> >> known before registering devices. It needs to be factored out into
> >> another utility function callable by spi bus drivers so that it can
> >> get polarity data at probe time.
> >
> > Untill we have this, Torsten's patch is a real improvement, and
> > works for non-broken hw/fw.
> >
> > So I think it should be applied.
>
> I disagree since it only band-aids the problem and uglifies the driver
> in the process. In the immediate term the driver needs to be changed
> to read the spi-cs-high property out of the child nodes before
> registering the devices.
Hm. I thought we agreed that spi-cs-high is not good? Why do you
encourage using it then? We'll have to uglify the driver with
legacy device-tree handling code.
--
Anton Vorontsov
email: cbouatmailru@gmail.com
irc://irc.freenode.net/bd2
_______________________________________________
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: spi_mpc8xxx.c: chip select polarity problem
@ 2009-11-26 19:01 ` Anton Vorontsov
0 siblings, 0 replies; 32+ messages in thread
From: Anton Vorontsov @ 2009-11-26 19:01 UTC (permalink / raw)
To: Grant Likely; +Cc: Torsten Fleischer, spi-devel-general, linuxppc-dev
On Thu, Nov 26, 2009 at 11:50:05AM -0700, Grant Likely wrote:
> On Thu, Nov 26, 2009 at 11:41 AM, Anton Vorontsov
> <avorontsov@ru.mvista.com> wrote:
> > On Thu, Nov 26, 2009 at 11:16:34AM -0700, Grant Likely wrote:
> > [...]
> >> The spi-cs-high property is defined in
> >> Documentation/powerpc/dts-bindings/spi-bus.txt, but it definitely was
> >> a mistake
> >
> > Yup.
> >
> >> Currently the spi-cs-high property is parsed in the
> >> of_register_spi_devices() function, but the CS polarity needs to be
> >> known before registering devices. It needs to be factored out into
> >> another utility function callable by spi bus drivers so that it can
> >> get polarity data at probe time.
> >
> > Untill we have this, Torsten's patch is a real improvement, and
> > works for non-broken hw/fw.
> >
> > So I think it should be applied.
>
> I disagree since it only band-aids the problem and uglifies the driver
> in the process. In the immediate term the driver needs to be changed
> to read the spi-cs-high property out of the child nodes before
> registering the devices.
Hm. I thought we agreed that spi-cs-high is not good? Why do you
encourage using it then? We'll have to uglify the driver with
legacy device-tree handling code.
--
Anton Vorontsov
email: cbouatmailru@gmail.com
irc://irc.freenode.net/bd2
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: spi_mpc8xxx.c: chip select polarity problem
2009-11-26 19:01 ` Anton Vorontsov
@ 2009-11-26 19:17 ` Grant Likely
-1 siblings, 0 replies; 32+ messages in thread
From: Grant Likely @ 2009-11-26 19:17 UTC (permalink / raw)
To: avorontsov; +Cc: Torsten Fleischer, spi-devel-general, linuxppc-dev
On Thu, Nov 26, 2009 at 12:01 PM, Anton Vorontsov
<avorontsov@ru.mvista.com> wrote:
> On Thu, Nov 26, 2009 at 11:50:05AM -0700, Grant Likely wrote:
>> On Thu, Nov 26, 2009 at 11:41 AM, Anton Vorontsov
>> <avorontsov@ru.mvista.com> wrote:
>> > On Thu, Nov 26, 2009 at 11:16:34AM -0700, Grant Likely wrote:
>> > [...]
>> >> The spi-cs-high property is defined in
>> >> Documentation/powerpc/dts-bindings/spi-bus.txt, but it definitely was
>> >> a mistake
>> >
>> > Yup.
>> >
>> >> Currently the spi-cs-high property is parsed in the
>> >> of_register_spi_devices() function, but the CS polarity needs to be
>> >> known before registering devices. It needs to be factored out into
>> >> another utility function callable by spi bus drivers so that it can
>> >> get polarity data at probe time.
>> >
>> > Untill we have this, Torsten's patch is a real improvement, and
>> > works for non-broken hw/fw.
>> >
>> > So I think it should be applied.
>>
>> I disagree since it only band-aids the problem and uglifies the driver
>> in the process. In the immediate term the driver needs to be changed
>> to read the spi-cs-high property out of the child nodes before
>> registering the devices.
>
> Hm. I thought we agreed that spi-cs-high is not good? Why do you
> encourage using it then? We'll have to uglify the driver with
> legacy device-tree handling code.
spi-cs-high is definitely not a complete solution, but it isn't
actively evil either. Plus it is documented and (presumably) in
active use. so support for it should not be dropped.
Regardless, there needs to be a library function for parsing all the
SPI child nodes and returning the active state for each GPIO chip
select. All the code for parsing the old spi-cs-high properties can
be contained in the same place as a new yet-to-be-defined bus node cs
polarity property. The rework to the driver itself is not ugly.
g.
--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: spi_mpc8xxx.c: chip select polarity problem
@ 2009-11-26 19:17 ` Grant Likely
0 siblings, 0 replies; 32+ messages in thread
From: Grant Likely @ 2009-11-26 19:17 UTC (permalink / raw)
To: avorontsov; +Cc: Torsten Fleischer, spi-devel-general, linuxppc-dev
On Thu, Nov 26, 2009 at 12:01 PM, Anton Vorontsov
<avorontsov@ru.mvista.com> wrote:
> On Thu, Nov 26, 2009 at 11:50:05AM -0700, Grant Likely wrote:
>> On Thu, Nov 26, 2009 at 11:41 AM, Anton Vorontsov
>> <avorontsov@ru.mvista.com> wrote:
>> > On Thu, Nov 26, 2009 at 11:16:34AM -0700, Grant Likely wrote:
>> > [...]
>> >> The spi-cs-high property is defined in
>> >> Documentation/powerpc/dts-bindings/spi-bus.txt, but it definitely was
>> >> a mistake
>> >
>> > Yup.
>> >
>> >> Currently the spi-cs-high property is parsed in the
>> >> of_register_spi_devices() function, but the CS polarity needs to be
>> >> known before registering devices. =A0It needs to be factored out into
>> >> another utility function callable by spi bus drivers so that it can
>> >> get polarity data at probe time.
>> >
>> > Untill we have this, Torsten's patch is a real improvement, and
>> > works for non-broken hw/fw.
>> >
>> > So I think it should be applied.
>>
>> I disagree since it only band-aids the problem and uglifies the driver
>> in the process. =A0In the immediate term the driver needs to be changed
>> to read the spi-cs-high property out of the child nodes before
>> registering the devices.
>
> Hm. I thought we agreed that spi-cs-high is not good? Why do you
> encourage using it then? We'll have to uglify the driver with
> legacy device-tree handling code.
spi-cs-high is definitely not a complete solution, but it isn't
actively evil either. Plus it is documented and (presumably) in
active use. so support for it should not be dropped.
Regardless, there needs to be a library function for parsing all the
SPI child nodes and returning the active state for each GPIO chip
select. All the code for parsing the old spi-cs-high properties can
be contained in the same place as a new yet-to-be-defined bus node cs
polarity property. The rework to the driver itself is not ugly.
g.
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: spi_mpc8xxx.c: chip select polarity problem
2009-11-26 19:17 ` Grant Likely
(?)
@ 2009-12-09 15:49 ` Torsten Fleischer
2009-12-09 17:46 ` Grant Likely
-1 siblings, 1 reply; 32+ messages in thread
From: Torsten Fleischer @ 2009-12-09 15:49 UTC (permalink / raw)
To: Grant Likely; +Cc: avorontsov
On Thu, Nov 26, 2009 at 20:17:35, Grant Likely wrote:
[...]
> spi-cs-high is definitely not a complete solution, but it isn't
> actively evil either. Plus it is documented and (presumably) in
> active use. so support for it should not be dropped.
>
> Regardless, there needs to be a library function for parsing all the
> SPI child nodes and returning the active state for each GPIO chip
> select. All the code for parsing the old spi-cs-high properties can
> be contained in the same place as a new yet-to-be-defined bus node cs
> polarity property. The rework to the driver itself is not ugly.
>
The following patch adds a function to get the active state of the chip select
of a SPI device by looking for the 'spi-cs-high' property in the associated device
tree node.
This function is used by the spi_mpc8xxx driver to set a proper initial value
to the associated GPIOs.
Signed-off-by: Torsten Fleischer <to-fleischer@t-online.de>
---
diff -ruN linux-2.6.32_orig//drivers/of/of_spi.c linux-2.6.32/drivers/of/of_spi.c
--- linux-2.6.32_orig//drivers/of/of_spi.c 2009-12-03 04:51:21.000000000 +0100
+++ linux-2.6.32/drivers/of/of_spi.c 2009-12-09 12:37:01.000000000 +0100
@@ -10,6 +10,49 @@
#include <linux/device.h>
#include <linux/spi/spi.h>
#include <linux/of_spi.h>
+#include <linux/errno.h>
+
+/**
+ * of_get_spi_cs_active_state - Gets the chip select's active state of a SPI
+ * child devices.
+ * @np: parent node of the SPI device nodes
+ * @index: index/address of the SPI device (refers to the 'reg' property)
+ * @cs_active: pointer to return the chip select's active state
+ * (true = active high; false = active low)
+ *
+ * Returns 0 on success; negative errno on failure
+ */
+int of_get_spi_cs_active_state(struct device_node *np, int index, bool *cs_active)
+{
+ struct device_node *child;
+ const int *prop;
+ int len;
+ bool active = 0;
+
+ /* search for the matching SPI device */
+ for_each_child_of_node(np, child) {
+ prop = of_get_property(child, "reg", &len);
+ if (!prop || len < sizeof(*prop)) {
+ /* property 'reg' not available (not an error) */
+ continue;
+ }
+
+ if ( *prop == index ) {
+ /* matching device found */
+ if (of_find_property(child, "spi-cs-high", NULL))
+ active = 1;
+
+ if (cs_active)
+ *cs_active = active;
+
+ return 0;
+ }
+ }
+
+ return -ENODEV;
+}
+EXPORT_SYMBOL(of_get_spi_cs_active_state);
+
/**
* of_register_spi_devices - Register child devices onto the SPI bus
diff -ruN linux-2.6.32_orig//drivers/spi/spi_mpc8xxx.c linux-2.6.32/drivers/spi/spi_mpc8xxx.c
--- linux-2.6.32_orig//drivers/spi/spi_mpc8xxx.c 2009-12-03 04:51:21.000000000 +0100
+++ linux-2.6.32/drivers/spi/spi_mpc8xxx.c 2009-12-09 12:50:36.000000000 +0100
@@ -705,6 +705,7 @@
for (; i < ngpios; i++) {
int gpio;
enum of_gpio_flags flags;
+ bool astate;
gpio = of_get_gpio_flags(np, i, &flags);
if (!gpio_is_valid(gpio)) {
@@ -721,8 +722,15 @@
pinfo->gpios[i] = gpio;
pinfo->alow_flags[i] = flags & OF_GPIO_ACTIVE_LOW;
+ ret = of_get_spi_cs_active_state(np, i, &astate);
+ if (ret) {
+ dev_err(dev, "can't get cs active state of device "
+ "#%d: %d\n", i, ret);
+ goto err_loop;
+ }
+
ret = gpio_direction_output(pinfo->gpios[i],
- pinfo->alow_flags[i]);
+ pinfo->alow_flags[i] ^ !astate);
if (ret) {
dev_err(dev, "can't set output direction for gpio "
"#%d: %d\n", i, ret);
diff -ruN linux-2.6.32_orig//include/linux/of_spi.h linux-2.6.32/include/linux/of_spi.h
--- linux-2.6.32_orig//include/linux/of_spi.h 2009-12-03 04:51:21.000000000 +0100
+++ linux-2.6.32/include/linux/of_spi.h 2009-12-09 12:36:48.000000000 +0100
@@ -15,4 +15,7 @@
extern void of_register_spi_devices(struct spi_master *master,
struct device_node *np);
+extern int of_get_spi_cs_active_state(struct device_node *np,
+ int index, bool *cs_active);
+
#endif /* __LINUX_OF_SPI */
^ permalink raw reply [flat|nested] 32+ messages in thread* Re: spi_mpc8xxx.c: chip select polarity problem
2009-12-09 15:49 ` Torsten Fleischer
@ 2009-12-09 17:46 ` Grant Likely
2009-12-09 19:13 ` Torsten Fleischer
2009-12-14 16:54 ` Torsten Fleischer
0 siblings, 2 replies; 32+ messages in thread
From: Grant Likely @ 2009-12-09 17:46 UTC (permalink / raw)
To: Torsten Fleischer; +Cc: avorontsov
On Wed, Dec 9, 2009 at 8:49 AM, Torsten Fleischer
<to-fleischer@t-online.de> wrote:
> On Thu, Nov 26, 2009 at 20:17:35, =A0Grant Likely wrote:
> [...]
>> spi-cs-high is definitely not a complete solution, but it isn't
>> actively evil either. =A0Plus it is documented and (presumably) in
>> active use. so support for it should not be dropped.
>>
>> Regardless, there needs to be a library function for parsing all the
>> SPI child nodes and returning the active state for each GPIO chip
>> select. =A0All the code for parsing the old spi-cs-high properties can
>> be contained in the same place as a new yet-to-be-defined bus node cs
>> polarity property. =A0The rework to the driver itself is not ugly.
>>
>
> The following patch adds a function to get the active state of the chip s=
elect
> of a SPI device by looking for the 'spi-cs-high' property in the associat=
ed device
> tree node.
> This function is used by the spi_mpc8xxx driver to set a proper initial v=
alue
> to the associated GPIOs.
>
>
> Signed-off-by: Torsten Fleischer <to-fleischer@t-online.de>
I like this better. See comments below.
> ---
>
> diff -ruN linux-2.6.32_orig//drivers/of/of_spi.c linux-2.6.32/drivers/of/=
of_spi.c
> --- linux-2.6.32_orig//drivers/of/of_spi.c =A0 =A0 =A02009-12-03 04:51:21=
.000000000 +0100
> +++ linux-2.6.32/drivers/of/of_spi.c =A0 =A02009-12-09 12:37:01.000000000=
+0100
> @@ -10,6 +10,49 @@
> =A0#include <linux/device.h>
> =A0#include <linux/spi/spi.h>
> =A0#include <linux/of_spi.h>
> +#include <linux/errno.h>
> +
> +/**
> + * of_get_spi_cs_active_state - Gets the chip select's active state of a=
SPI
> + * child devices.
> + * @np: =A0 =A0 =A0 =A0parent node of the SPI device nodes
> + * @index: =A0 =A0 index/address of the SPI device (refers to the 'reg' =
property)
> + * @cs_active: pointer to return the chip select's active state
> + * =A0 =A0 =A0 =A0 =A0 =A0 (true =3D active high; false =3D active low)
> + *
> + * Returns 0 on success; negative errno on failure
> + */
> +int of_get_spi_cs_active_state(struct device_node *np, int index, bool *=
cs_active)
> +{
> + =A0 =A0 =A0 struct device_node *child;
> + =A0 =A0 =A0 const int *prop;
> + =A0 =A0 =A0 int len;
> + =A0 =A0 =A0 bool active =3D 0;
> +
> + =A0 =A0 =A0 /* search for the matching SPI device */
> + =A0 =A0 =A0 for_each_child_of_node(np, child) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 prop =3D of_get_property(child, "reg", &len=
);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!prop || len < sizeof(*prop)) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* property 'reg' not avail=
able (not an error) */
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 continue;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if ( *prop =3D=3D index ) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* matching device found */
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (of_find_property(child,=
"spi-cs-high", NULL))
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 active =3D =
1;
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (cs_active)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *cs_active =
=3D active;
A little odd. If cs_active is NULL, then this routine does nothing,
and the caller is entirely defective. Either test at the top of the
function or not at all. Then *cs_active can be assigned directly.
But even then, this function will probably need to be reworked (see
comments below).
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 return -ENODEV;
> +}
> +EXPORT_SYMBOL(of_get_spi_cs_active_state);
> +
>
> =A0/**
> =A0* of_register_spi_devices - Register child devices onto the SPI bus
> diff -ruN linux-2.6.32_orig//drivers/spi/spi_mpc8xxx.c linux-2.6.32/drive=
rs/spi/spi_mpc8xxx.c
> --- linux-2.6.32_orig//drivers/spi/spi_mpc8xxx.c =A0 =A0 =A0 =A02009-12-0=
3 04:51:21.000000000 +0100
> +++ linux-2.6.32/drivers/spi/spi_mpc8xxx.c =A0 =A0 =A02009-12-09 12:50:36=
.000000000 +0100
> @@ -705,6 +705,7 @@
> =A0 =A0 =A0 =A0for (; i < ngpios; i++) {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0int gpio;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0enum of_gpio_flags flags;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 bool astate;
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0gpio =3D of_get_gpio_flags(np, i, &flags);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (!gpio_is_valid(gpio)) {
> @@ -721,8 +722,15 @@
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pinfo->gpios[i] =3D gpio;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pinfo->alow_flags[i] =3D flags & OF_GPIO_A=
CTIVE_LOW;
>
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D of_get_spi_cs_active_state(np, i, &=
astate);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (ret) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(dev, "can't get cs =
active state of device "
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "#%d: %d\n"=
, i, ret);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto err_loop;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
This is a bit heavy handed in that it expects the device tree to be
fully populated with all SPI devices which isn't always a given. For
example a board that has some unpopulated SPI devices could have some
gaps in the GPIO CS layout. If a node can't be found, then just
ignore it silently and move on to the next. I'd do something like
this:
+ astate =3D of_get_spi_cs_active_state(np, i);
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret =3D gpio_direction_output(pinfo->gpios[i=
],
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 pinfo->alow_flags[i]);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 pinfo->alow_flags[i] ^ !astate);
BTW, why the xor? The usage is non-obvious enough that I'd like to
see a comment describing the use case.
g.
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
^ permalink raw reply [flat|nested] 32+ messages in thread* Re: spi_mpc8xxx.c: chip select polarity problem
2009-12-09 17:46 ` Grant Likely
@ 2009-12-09 19:13 ` Torsten Fleischer
2009-12-14 16:54 ` Torsten Fleischer
1 sibling, 0 replies; 32+ messages in thread
From: Torsten Fleischer @ 2009-12-09 19:13 UTC (permalink / raw)
To: Grant Likely; +Cc: avorontsov
On Wed, Dec 9, 2009 at 18:46:51 Grant Likely wrote:
[...]
> > + ret = of_get_spi_cs_active_state(np, i, &astate);
> > + if (ret) {
> > + dev_err(dev, "can't get cs active state of device
> > " + "#%d: %d\n", i, ret);
> > + goto err_loop;
> > + }
>
> This is a bit heavy handed in that it expects the device tree to be
> fully populated with all SPI devices which isn't always a given. For
> example a board that has some unpopulated SPI devices could have some
> gaps in the GPIO CS layout. If a node can't be found, then just
> ignore it silently and move on to the next. I'd do something like
> this:
>
> + astate = of_get_spi_cs_active_state(np, i);
What should be returned if the node can't be found, 'true' or 'false?
Maybe its better to do the following:
+ ret = of_get_spi_cs_active_state(np, i, &astate);
+ if (ret) {
+ /* Device node not found */
+ continue;
+ }
> ret = gpio_direction_output(pinfo->gpios[i],
> - pinfo->alow_flags[i]);
> + pinfo->alow_flags[i] ^ !astate);
>
> BTW, why the xor? The usage is non-obvious enough that I'd like to
> see a comment describing the use case.
If I understand it right, the alow_flags describe the wiring. If set to 0 the
wiring is non-inverted, if set to 1 its inverted respectively. To take this
into account the active state has to be xor'd with the appropriate alow_flag.
^ permalink raw reply [flat|nested] 32+ messages in thread* Re: spi_mpc8xxx.c: chip select polarity problem
2009-12-09 17:46 ` Grant Likely
2009-12-09 19:13 ` Torsten Fleischer
@ 2009-12-14 16:54 ` Torsten Fleischer
1 sibling, 0 replies; 32+ messages in thread
From: Torsten Fleischer @ 2009-12-14 16:54 UTC (permalink / raw)
To: Grant Likely; +Cc: avorontsov, linuxppc-dev
On Wed, Dec 9, 2009 at 18:46:51 Grant Likely wrote:
> <to-fleischer@t-online.de> wrote:
> [...]
> > The following patch adds a function to get the active state of the chip
> > select of a SPI device by looking for the 'spi-cs-high' property in the
> > associated device tree node.
> > This function is used by the spi_mpc8xxx driver to set a proper initial
> > value to the associated GPIOs.
> >
> >
> > Signed-off-by: Torsten Fleischer <to-fleischer@t-online.de>
>
> I like this better. See comments below.
>
[...]
Hey Grant,
below there is a new version of the patch containing the modifications
according to your comments.
Thanks for the hints,
Torsten
Signed-off-by: Torsten Fleischer <to-fleischer@t-online.de>
---
diff -ruN linux-2.6.32_orig//drivers/of/of_spi.c linux-2.6.32/drivers/of/of_spi.c
--- linux-2.6.32_orig//drivers/of/of_spi.c 2009-12-03 04:51:21.000000000 +0100
+++ linux-2.6.32/drivers/of/of_spi.c 2009-12-11 17:57:22.016787665 +0100
@@ -12,6 +12,43 @@
#include <linux/of_spi.h>
/**
+ * of_get_spi_cs_active_state - Gets the chip select's active state of a SPI
+ * child devices.
+ * @np: parent node of the SPI device nodes
+ * @index: index/address of the SPI device (refers to the 'reg' property)
+ *
+ * Returns 0 for 'active low' or if the child's node can't be found.
+ * Otherwise it returns 1 ('active high').
+ */
+bool of_get_spi_cs_active_state(struct device_node *np, int index)
+{
+ struct device_node *child;
+ const int *prop;
+ int len;
+ bool active = 0;
+
+ /* search for the matching SPI device */
+ for_each_child_of_node(np, child) {
+ prop = of_get_property(child, "reg", &len);
+ if (!prop || len < sizeof(*prop)) {
+ /* property 'reg' not available (not an error) */
+ continue;
+ }
+
+ if ( *prop == index ) {
+ /* matching device found */
+ if (of_find_property(child, "spi-cs-high", NULL))
+ active = 1;
+ break;
+ }
+ }
+
+ return active;
+}
+EXPORT_SYMBOL(of_get_spi_cs_active_state);
+
+
+/**
* of_register_spi_devices - Register child devices onto the SPI bus
* @master: Pointer to spi_master device
* @np: parent node of SPI device nodes
diff -ruN linux-2.6.32_orig//drivers/spi/spi_mpc8xxx.c linux-2.6.32/drivers/spi/spi_mpc8xxx.c
--- linux-2.6.32_orig//drivers/spi/spi_mpc8xxx.c 2009-12-03 04:51:21.000000000 +0100
+++ linux-2.6.32/drivers/spi/spi_mpc8xxx.c 2009-12-11 17:15:47.957379333 +0100
@@ -705,6 +705,7 @@
for (; i < ngpios; i++) {
int gpio;
enum of_gpio_flags flags;
+ bool astate;
gpio = of_get_gpio_flags(np, i, &flags);
if (!gpio_is_valid(gpio)) {
@@ -721,8 +722,18 @@
pinfo->gpios[i] = gpio;
pinfo->alow_flags[i] = flags & OF_GPIO_ACTIVE_LOW;
+ /* get the active state of the SPI device */
+ astate = of_get_spi_cs_active_state(np, i);
+
+ /*
+ * alow_flags describe the wiring of the chip select
+ * (0 = non-inverted, 1 = inverted); this must be taken into
+ * account when setting the GPIO's initial value
+ * (see also mpc8xxx_spi_cs_control()); note that astate will
+ * be 0 for active low and 1 for active high respectively
+ */
ret = gpio_direction_output(pinfo->gpios[i],
- pinfo->alow_flags[i]);
+ pinfo->alow_flags[i] ^ !astate);
if (ret) {
dev_err(dev, "can't set output direction for gpio "
"#%d: %d\n", i, ret);
diff -ruN linux-2.6.32_orig//include/linux/of_spi.h linux-2.6.32/include/linux/of_spi.h
--- linux-2.6.32_orig//include/linux/of_spi.h 2009-12-03 04:51:21.000000000 +0100
+++ linux-2.6.32/include/linux/of_spi.h 2009-12-11 17:10:21.681380685 +0100
@@ -15,4 +15,7 @@
extern void of_register_spi_devices(struct spi_master *master,
struct device_node *np);
+extern bool of_get_spi_cs_active_state(struct device_node *np,
+ int index);
+
#endif /* __LINUX_OF_SPI */
^ permalink raw reply [flat|nested] 32+ messages in thread