gpio: pcf857x: restore the initial line state of all pcf lines
Subsystems (2)
PATCH 1/1 gpio: pcf857x: restore the initial line state of all pcf lines
The reset values for all the PCF lines are high and hence on shutdown we should drive all the lines high in order to bring it to the reset state.
This is actually required since pcf doesn't have a reset line and even after warm reset (by invoking "reboot" in prompt) the pcf lines maintains it's previous programmed state. This becomes a problem if the boards are designed to work with the default initial state.
DRA7XX_evm uses PCF8575 and one of the PCF output lines feeds to MMC/SD and this line should be driven high in order for the MMC/SD to be detected. This line is modelled as regulator and the hsmmc driver takes care of enabling and disabling it. In the case of 'reboot', during shutdown path as part of it's cleanup process the hsmmc driver disables this regulator. This makes MMC boot not functional.
Fixed it by driving high all the pcf lines.
--- drivers/gpio/gpio-pcf857x.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/gpio/gpio-pcf857x.c +9 -0
@@ -448,6 +448,14 @@ static int pcf857x_remove(struct i2c_client *client)return status; } +static void pcf857x_shutdown (struct i2c_client *client) +{ +struct pcf857x *gpio =i2c_get_clientdata (client); + +/* Drive all the I/O lines high */ + gpio->write (gpio->client,BIT (gpio->chip.ngpio) -1 ); +} +static struct i2c_driver pcf857x_driver = { .driver = { .name ="pcf857x" ,
@@ -456,6 +464,7 @@ static struct i2c_driver pcf857x_driver = { }, .probe = pcf857x_probe, .remove = pcf857x_remove, + .shutdown = pcf857x_shutdown, .id_table = pcf857x_id, };
Signature · 1 line
1.7.9.5
Quoted 27 lines · Kishon Vijay Abraham I
The reset values for all the PCF lines are high and hence on shutdown we should drive all the lines high in order to bring it to the reset state.
This is actually required since pcf doesn't have a reset line and even after warm reset (by invoking "reboot" in prompt) the pcf lines maintains it's previous programmed state. This becomes a problem if the boards are designed to work with the default initial state.
DRA7XX_evmuses PCF8575 and one of the PCF output lines feeds to MMC/SD and this line should be driven high in order for the MMC/SD to be detected. This line is modelled as regulator and the hsmmc driver takes care of enabling and disabling it. In the case of 'reboot', during shutdown path as part of it's cleanup process the hsmmc driver disables this regulator. This makes MMC boot not functional.Fixed it by driving high all the pcf lines.
Signed-off-by Kishon Vijay Abraham I <[email protected]>--- drivers/gpio/gpio-pcf857x.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/gpio/gpio-pcf857x.c +0
-0
drivers/gpio/gpio-pcf857x.c static int pcf857x_remove(struct i2c_client *client) · line 456
Quoted 9 lines
drivers/gpio/gpio-pcf857x.c +6
-0@@ -448,6 +448,14 @@ static int pcf857x_remove(struct i2c_client *client)return status; } +static void pcf857x_shutdown (struct i2c_client *client) +{ +struct pcf857x *gpio =i2c_get_clientdata (client); + +/* Drive all the I/O lines high */ + gpio->write (gpio->client,BIT (gpio->chip.ngpio) -1 );
you might force a contention here - depending on System configuration. example:
+-------+
| |
| U1 | +------+ +-----------+
| +---------> | | |
+-------+ | | | |
| Switch<-----+ SoC |
+-------+ | | | |
| | | | | |
| U2 <---------+--^---+ +-----------+
| | |
| | |
+-------+ |
+--+--+
| |
| PCF |
| |
+-----+At low, SoC pin is connected to U2 as drive. when reset to high, you now have U1 driving to the same pin that SoC has, potentially resulting in contention.
Unfortunately, at this level, you do not know what the state of the system is, blindly forcing a pin level will potentially cause contention risk depending on pin configuration.
Quoted 14 lines
drivers/gpio/gpio-pcf857x.c +3
-0+} +static struct i2c_driver pcf857x_driver = { .driver = { .name ="pcf857x" ,@@ -456,6 +464,7 @@ static struct i2c_driver pcf857x_driver = { }, .probe = pcf857x_probe, .remove = pcf857x_remove, + .shutdown = pcf857x_shutdown, .id_table = pcf857x_id, };
Signature · 2 lines
Regards, Nishanth Menon
Quoted 58 lines · Nishanth Menon
Quoted 27 lines · Kishon Vijay Abraham I
The reset values for all the PCF lines are high and hence on shutdown we should drive all the lines high in order to bring it to the reset state.
This is actually required since pcf doesn't have a reset line and even after warm reset (by invoking "reboot" in prompt) the pcf lines maintains it's previous programmed state. This becomes a problem if the boards are designed to work with the default initial state.
DRA7XX_evmuses PCF8575 and one of the PCF output lines feeds to MMC/SD and this line should be driven high in order for the MMC/SD to be detected. This line is modelled as regulator and the hsmmc driver takes care of enabling and disabling it. In the case of 'reboot', during shutdown path as part of it's cleanup process the hsmmc driver disables this regulator. This makes MMC boot not functional.Fixed it by driving high all the pcf lines.
Signed-off-by Kishon Vijay Abraham I <[email protected]>--- drivers/gpio/gpio-pcf857x.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/gpio/gpio-pcf857x.c +0
-0drivers/gpio/gpio-pcf857x.c static int pcf857x_remove(struct i2c_client *client) · line 456
Quoted 9 lines
drivers/gpio/gpio-pcf857x.c +6
-0@@ -448,6 +448,14 @@ static int pcf857x_remove(struct i2c_client *client)return status; } +static void pcf857x_shutdown (struct i2c_client *client) +{ +struct pcf857x *gpio =i2c_get_clientdata (client); + +/* Drive all the I/O lines high */ + gpio->write (gpio->client,BIT (gpio->chip.ngpio) -1 );you might force a contention here - depending on System configuration. example:
+-------+ | | | U1 | +------+ +-----------+ | +---------> | | | +-------+ | | | | | Switch<-----+ SoC | +-------+ | | | | | | | | | | | U2 <---------+--^---+ +-----------+ | | | | | | +-------+ | +--+--+ | | | PCF | | | +-----+
Quoted 8 lines
At low, SoC pin is connected to U2 as drive. when reset to high, you now have U1 driving to the same pin that SoC has, potentially resulting in contention.
Unfortunately, at this level, you do not know what the state of the system is, blindly forcing a pin level will potentially cause contention risk depending on pin configuration.
Assume we are doing a reset when the system is powered on, irrespective of the state of the system, we'll be forcing the pin level to the default state.
The same thing happens here so I don't think this would be a problem.
Thanks
Kishon
Quoted 66 lines · Kishon Vijay Abraham I
Quoted 63 lines · Nishanth Menon
Quoted 27 lines · Kishon Vijay Abraham I
The reset values for all the PCF lines are high and hence on shutdown we should drive all the lines high in order to bring it to the reset state.
This is actually required since pcf doesn't have a reset line and even after warm reset (by invoking "reboot" in prompt) the pcf lines maintains it's previous programmed state. This becomes a problem if the boards are designed to work with the default initial state.
DRA7XX_evmuses PCF8575 and one of the PCF output lines feeds to MMC/SD and this line should be driven high in order for the MMC/SD to be detected. This line is modelled as regulator and the hsmmc driver takes care of enabling and disabling it. In the case of 'reboot', during shutdown path as part of it's cleanup process the hsmmc driver disables this regulator. This makes MMC boot not functional.Fixed it by driving high all the pcf lines.
Signed-off-by Kishon Vijay Abraham I <[email protected]>--- drivers/gpio/gpio-pcf857x.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/gpio/gpio-pcf857x.c +0
-0drivers/gpio/gpio-pcf857x.c static int pcf857x_remove(struct i2c_client *client) · line 456
Quoted 9 lines
drivers/gpio/gpio-pcf857x.c +6
-0@@ -448,6 +448,14 @@ static int pcf857x_remove(struct i2c_client *client)return status; } +static void pcf857x_shutdown (struct i2c_client *client) +{ +struct pcf857x *gpio =i2c_get_clientdata (client); + +/* Drive all the I/O lines high */ + gpio->write (gpio->client,BIT (gpio->chip.ngpio) -1 );you might force a contention here - depending on System configuration. example:
+-------+ | | | U1 | +------+ +-----------+ | +---------> | | | +-------+ | | | | | Switch<-----+ SoC | +-------+ | | | | | | | | | | | U2 <---------+--^---+ +-----------+ | | | | | | +-------+ | +--+--+ | | | PCF | | | +-----+At low, SoC pin is connected to U2 as drive. when reset to high, you now have U1 driving to the same pin that SoC has, potentially resulting in contention.
Quoted 6 lines
Quoted 3 lines
Unfortunately, at this level, you do not know what the state of the system is, blindly forcing a pin level will potentially cause contention risk depending on pin configuration.
Assume we are doing a reset when the system is powered on, irrespective of the state of the system, we'll be forcing the pin level to the default state.
Yes, I dont deny that system will be fine *after* reset sequence is started or completed. However there is a duration between the pcf shutdown handler is called and the final reset handler is invoked - that is the duration when the contention might cause device behavior. Essentially ignoring the state various drivers have asked PCF to setup the pins and doing a hands down configuration may have side effects we cant properly expect.
Quoted 6 lines
The same thing happens here so I don't think this would be a problem.
Thanks
Kishon
Signature · 2 lines
Regards, Nishanth Menon
Hi,
Quoted 74 lines · Nishanth Menon
Quoted 66 lines · Kishon Vijay Abraham I
Quoted 63 lines · Nishanth Menon
Quoted 27 lines · Kishon Vijay Abraham I
The reset values for all the PCF lines are high and hence on shutdown we should drive all the lines high in order to bring it to the reset state.
This is actually required since pcf doesn't have a reset line and even after warm reset (by invoking "reboot" in prompt) the pcf lines maintains it's previous programmed state. This becomes a problem if the boards are designed to work with the default initial state.
DRA7XX_evmuses PCF8575 and one of the PCF output lines feeds to MMC/SD and this line should be driven high in order for the MMC/SD to be detected. This line is modelled as regulator and the hsmmc driver takes care of enabling and disabling it. In the case of 'reboot', during shutdown path as part of it's cleanup process the hsmmc driver disables this regulator. This makes MMC boot not functional.Fixed it by driving high all the pcf lines.
Signed-off-by Kishon Vijay Abraham I <[email protected]>--- drivers/gpio/gpio-pcf857x.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/gpio/gpio-pcf857x.c +0
-0drivers/gpio/gpio-pcf857x.c static int pcf857x_remove(struct i2c_client *client) · line 456
Quoted 9 lines
drivers/gpio/gpio-pcf857x.c +6
-0@@ -448,6 +448,14 @@ static int pcf857x_remove(struct i2c_client *client)return status; } +static void pcf857x_shutdown (struct i2c_client *client) +{ +struct pcf857x *gpio =i2c_get_clientdata (client); + +/* Drive all the I/O lines high */ + gpio->write (gpio->client,BIT (gpio->chip.ngpio) -1 );you might force a contention here - depending on System configuration. example:
+-------+ | | | U1 | +------+ +-----------+ | +---------> | | | +-------+ | | | | | Switch<-----+ SoC | +-------+ | | | | | | | | | | | U2 <---------+--^---+ +-----------+ | | | | | | +-------+ | +--+--+ | | | PCF | | | +-----+At low, SoC pin is connected to U2 as drive. when reset to high, you now have U1 driving to the same pin that SoC has, potentially resulting in contention.
Quoted 6 lines
Quoted 3 lines
Unfortunately, at this level, you do not know what the state of the system is, blindly forcing a pin level will potentially cause contention risk depending on pin configuration.
Assume we are doing a reset when the system is powered on, irrespective of the state of the system, we'll be forcing the pin level to the default state.
Quoted 7 lines
Yes, I dont deny that system will be fine *after* reset sequence is started or completed. However there is a duration between the pcf shutdown handler is called and the final reset handler is invoked - that is the duration when the contention might cause device behavior. Essentially ignoring the state various drivers have asked PCF to setup the pins and doing a hands down configuration may have side effects we cant properly expect.
The solution might be to invoke the shutdown handler of the various drivers using the PCF before the shutdown handler of the PCF driver itself gets invoked? But I'm not sure how can that be achieved in linux kernel :-(
Thanks
Kishon
Quoted 83 lines · Kishon Vijay Abraham I
Quoted 74 lines · Nishanth Menon
Quoted 66 lines · Kishon Vijay Abraham I
Quoted 63 lines · Nishanth Menon
Quoted 27 lines · Kishon Vijay Abraham I
The reset values for all the PCF lines are high and hence on shutdown we should drive all the lines high in order to bring it to the reset state.
This is actually required since pcf doesn't have a reset line and even after warm reset (by invoking "reboot" in prompt) the pcf lines maintains it's previous programmed state. This becomes a problem if the boards are designed to work with the default initial state.
DRA7XX_evmuses PCF8575 and one of the PCF output lines feeds to MMC/SD and this line should be driven high in order for the MMC/SD to be detected. This line is modelled as regulator and the hsmmc driver takes care of enabling and disabling it. In the case of 'reboot', during shutdown path as part of it's cleanup process the hsmmc driver disables this regulator. This makes MMC boot not functional.Fixed it by driving high all the pcf lines.
Signed-off-by Kishon Vijay Abraham I <[email protected]>--- drivers/gpio/gpio-pcf857x.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/gpio/gpio-pcf857x.c +0
-0drivers/gpio/gpio-pcf857x.c static int pcf857x_remove(struct i2c_client *client) · line 456
Quoted 9 lines
drivers/gpio/gpio-pcf857x.c +6
-0@@ -448,6 +448,14 @@ static int pcf857x_remove(struct i2c_client *client)return status; } +static void pcf857x_shutdown (struct i2c_client *client) +{ +struct pcf857x *gpio =i2c_get_clientdata (client); + +/* Drive all the I/O lines high */ + gpio->write (gpio->client,BIT (gpio->chip.ngpio) -1 );you might force a contention here - depending on System configuration. example:
+-------+ | | | U1 | +------+ +-----------+ | +---------> | | | +-------+ | | | | | Switch<-----+ SoC | +-------+ | | | | | | | | | | | U2 <---------+--^---+ +-----------+ | | | | | | +-------+ | +--+--+ | | | PCF | | | +-----+At low, SoC pin is connected to U2 as drive. when reset to high, you now have U1 driving to the same pin that SoC has, potentially resulting in contention.
Quoted 6 lines
Quoted 3 lines
Unfortunately, at this level, you do not know what the state of the system is, blindly forcing a pin level will potentially cause contention risk depending on pin configuration.
Assume we are doing a reset when the system is powered on, irrespective of the state of the system, we'll be forcing the pin level to the default state.
Quoted 7 lines
Yes, I dont deny that system will be fine *after* reset sequence is started or completed. However there is a duration between the pcf shutdown handler is called and the final reset handler is invoked - that is the duration when the contention might cause device behavior. Essentially ignoring the state various drivers have asked PCF to setup the pins and doing a hands down configuration may have side effects we cant properly expect.
Quoted 3 lines
The solution might be to invoke the shutdown handler of the various drivers using the PCF before the shutdown handler of the PCF driver itself gets invoked? But I'm not sure how can that be achieved in linux kernel :-(
#include <linux/reboot.h>
static int foo_reboot_handler(struct notifier_block *this,
unsigned long code, void *unused)
{
pr_crit("do some last minute stuff\n");
return NOTIFY_OK;
}static struct notifier_block foo_reboot_notifier = {
.notifier_call = foo_reboot_handler,
};
register_reboot_notifier(&foo_reboot_notifier);
Yours,
Linus Walleij
Hi,
Quoted 98 lines · Linus Walleij
Quoted 83 lines · Kishon Vijay Abraham I
Quoted 74 lines · Nishanth Menon
Quoted 66 lines · Kishon Vijay Abraham I
Quoted 63 lines · Nishanth Menon
Quoted 27 lines · Kishon Vijay Abraham I
The reset values for all the PCF lines are high and hence on shutdown we should drive all the lines high in order to bring it to the reset state.
This is actually required since pcf doesn't have a reset line and even after warm reset (by invoking "reboot" in prompt) the pcf lines maintains it's previous programmed state. This becomes a problem if the boards are designed to work with the default initial state.
DRA7XX_evmuses PCF8575 and one of the PCF output lines feeds to MMC/SD and this line should be driven high in order for the MMC/SD to be detected. This line is modelled as regulator and the hsmmc driver takes care of enabling and disabling it. In the case of 'reboot', during shutdown path as part of it's cleanup process the hsmmc driver disables this regulator. This makes MMC boot not functional.Fixed it by driving high all the pcf lines.
Signed-off-by Kishon Vijay Abraham I <[email protected]>--- drivers/gpio/gpio-pcf857x.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/gpio/gpio-pcf857x.c +0
-0drivers/gpio/gpio-pcf857x.c static int pcf857x_remove(struct i2c_client *client) · line 456
Quoted 9 lines
drivers/gpio/gpio-pcf857x.c +6
-0@@ -448,6 +448,14 @@ static int pcf857x_remove(struct i2c_client *client)return status; } +static void pcf857x_shutdown (struct i2c_client *client) +{ +struct pcf857x *gpio =i2c_get_clientdata (client); + +/* Drive all the I/O lines high */ + gpio->write (gpio->client,BIT (gpio->chip.ngpio) -1 );you might force a contention here - depending on System configuration. example:
+-------+ | | | U1 | +------+ +-----------+ | +---------> | | | +-------+ | | | | | Switch<-----+ SoC | +-------+ | | | | | | | | | | | U2 <---------+--^---+ +-----------+ | | | | | | +-------+ | +--+--+ | | | PCF | | | +-----+At low, SoC pin is connected to U2 as drive. when reset to high, you now have U1 driving to the same pin that SoC has, potentially resulting in contention.
Quoted 6 lines
Quoted 3 lines
Unfortunately, at this level, you do not know what the state of the system is, blindly forcing a pin level will potentially cause contention risk depending on pin configuration.
Assume we are doing a reset when the system is powered on, irrespective of the state of the system, we'll be forcing the pin level to the default state.
Quoted 7 lines
Yes, I dont deny that system will be fine *after* reset sequence is started or completed. However there is a duration between the pcf shutdown handler is called and the final reset handler is invoked - that is the duration when the contention might cause device behavior. Essentially ignoring the state various drivers have asked PCF to setup the pins and doing a hands down configuration may have side effects we cant properly expect.
Quoted 3 lines
The solution might be to invoke the shutdown handler of the various drivers using the PCF before the shutdown handler of the PCF driver itself gets invoked? But I'm not sure how can that be achieved in linux kernel :-(
#include <
linux/reboot.h>static int foo_reboot_handler(struct
notifier_block*this,
unsigned long code, void *unused){ pr_crit("do some last minute stuff\n"); return NOTIFY_OK; }
Quoted 5 lines
static struct
notifier_blockfoo_reboot_notifier= {
.notifier_call =foo_reboot_handler,
};
register_reboot_notifier(&foo_reboot_notifier);
Added debug prints and found the reboot notifier gets invoked before the shutdown handler which means some stuff can be done after this reboot notifier:-(
Thanks
Kishon
Quoted 16 lines · Kishon Vijay Abraham I
Quoted 14 lines · Linus Walleij
#include <
linux/reboot.h>static int foo_reboot_handler(struct
notifier_block*this,
unsigned long code, void *unused){ pr_crit("do some last minute stuff\n"); return NOTIFY_OK; }static struct
notifier_blockfoo_reboot_notifier= {
.notifier_call =foo_reboot_handler,
};
Quoted 6 lines
Quoted 1 line
register_reboot_notifier(&foo_reboot_notifier);Added debug prints and found the reboot notifier gets invoked before the shutdown handler which means some stuff can be done after this reboot notifier:-(
Specify exactly what stuff may happen after the reboot notifier.
Of course stuff happens both before and after the reboot notifier, the question is exactly what, that may conflict with this.
Yours,
Linus Walleij
Hi,
Quoted 17 lines · Linus Walleij
Quoted 16 lines · Kishon Vijay Abraham I
Quoted 14 lines · Linus Walleij
#include <
linux/reboot.h>static int foo_reboot_handler(struct
notifier_block*this,
unsigned long code, void *unused){ pr_crit("do some last minute stuff\n"); return NOTIFY_OK; }static struct
notifier_blockfoo_reboot_notifier= {
.notifier_call =foo_reboot_handler,
};
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
register_reboot_notifier(&foo_reboot_notifier);Added debug prints and found the reboot notifier gets invoked before the shutdown handler which means some stuff can be done after this reboot notifier:-(
Specify exactly what stuff may happen after the reboot notifier.
okay, it's assumed the device may be used (active) till the shutdown handler of that particular device is called.
In this particular case we are restoring the initial line state of all pcf lines even though we don't know if the devices connected to it are still being active, which might cause a contention as explained by NM [1]
If the reboot notifier gets invoked after the shutdown handler then we could be sure that restoring the initial line state of the pcf lines wouldn't affect the devices connected to it.
Thanks
Kishon
[1] -> http://www.spinics.net/lists/linux-mmc/msg29855.html
Quoted 7 lines
Of course stuff happens both before and after the reboot notifier, the question is exactly what, that may conflict with this.
Yours,
Linus Walleij
Quoted 9 lines · Kishon Vijay Abraham I
[Me]
Quoted 1 line
Specify exactly what stuff may happen after the reboot notifier.
okay, it's assumed the device may be used (active) till the shutdown handler of that particular device is called.
In this particular case we are restoring the initial line state of all pcf lines even though we don't know if the devices connected to it are still being active, which might cause a contention as explained by NM [1]
OK I understand this, just that I want to know if it is a practical problem, i.e. do you run into it? Does the system lock up?
Quoted 3 lines
If the reboot notifier gets invoked after the shutdown handler then we could be sure that restoring the initial line state of the pcf lines wouldn't affect the devices connected to it.
OK so does it?
ftrace is your friend.
Yours,
Linus Walleij