gpio: pca953x: Add GPIO settle delay
PATCH 1/1 gpio: pca953x: Add GPIO settle delay
Some board designs have slow RC circuits on GPIO outputs controlled by PCA953X I2C expanders. On some board designs, pin voltage transitions can take significant time after I2C write command completes.
Add an optional "gpio-settle-delay-ms" device tree property for the pca953x driver to add a delay after I2C write if specified, allowing to compensate for slow RC circuits.
--- drivers/gpio/pca953x_gpio.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/gpio/pca953x_gpio.c +8 -0
@@ -28,6 +28,7 @@#include <dm/device_compat.h> #include <dt-bindings/gpio/gpio.h> #include <linux/bitops.h> +#include <linux/delay.h> #define PCA953X_INPUT 0#define PCA953X_OUTPUT 1
@@ -89,6 +90,7 @@ static const struct pca95xx_reg pca957x_regs = {* @reg_output: array to hold the value of output registers * @reg_direction: array to hold the value of direction registers * @regs: struct to hold the registers addresses +* @settle_delay_ms: GPIO pin settle delay in milliseconds */ struct pca953x_info {struct udevice *dev;
@@ -100,6 +102,7 @@ struct pca953x_info {u8 reg_output[MAX_BANK ];u8 reg_direction[MAX_BANK ];const struct pca95xx_reg *regs; +u32 settle_delay_ms; }; static int pca953x_write_single(struct udevice *dev, int reg, u8 val,
@@ -116,6 +119,9 @@ static int pca953x_write_single(struct udevice *dev, int reg, u8 val,return ret; } +if (info->settle_delay_ms) +mdelay (info->settle_delay_ms); +return 0 ; }
@@ -333,6 +339,8 @@ static int pca953x_probe(struct udevice *dev) info->bank_count =DIV_ROUND_UP (info->gpio_count,BANK_SZ ); + info->settle_delay_ms =dev_read_u32_default (dev,"gpio-settle-delay-ms" ,0 ); + ret =pca953x_read_regs (dev, info->regs->output, info->reg_output);if (ret) {dev_err (dev,"Error reading output register\n" );
Signature · 1 line
2.54.0
Hello Judith,
Quoted 18 lines · Judith Mendez
Some board designs have slow RC circuits on GPIO outputs controlled by PCA953X I2C expanders. On some board designs, pin voltage transitions can take significant time after I2C write command completes.
Add an optional "gpio-settle-delay-ms" device tree property for the pca953x driver to add a delay after I2C write if specified, allowing to compensate for slow RC circuits.
Signed-off-by Judith Mendez <[email protected]>--- drivers/gpio/pca953x_gpio.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/gpio/pca953x_gpio.c +0
-0
drivers/gpio/pca953x_gpio.c static int pca953x_probe(struct udevice *dev) · line 342
Quoted 4 lines
drivers/gpio/pca953x_gpio.c +1
-0@@ -333,6 +339,8 @@ static int pca953x_probe(struct udevice *dev) info->bank_count =DIV_ROUND_UP (info->gpio_count,BANK_SZ ); + info->settle_delay_ms =dev_read_u32_default (dev,"gpio-settle-delay-ms" ,0 );
Is this property supported also in Linux and defined in the Linux binding? I do not think we should have U-Boot specific DT properties.
Francesco
Hi Francesco,
Quoted 22 lines · Francesco Dolcini
Hello Judith,
Quoted 19 lines · Judith Mendez
Some board designs have slow RC circuits on GPIO outputs controlled by PCA953X I2C expanders. On some board designs, pin voltage transitions can take significant time after I2C write command completes.
Add an optional "gpio-settle-delay-ms" device tree property for the pca953x driver to add a delay after I2C write if specified, allowing to compensate for slow RC circuits.
Signed-off-by Judith Mendez <[email protected]>--- drivers/gpio/pca953x_gpio.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/gpio/pca953x_gpio.c +0
-0@@ -333,6 +339,8 @@ static int pca953x_probe(struct udevice *dev)
Quoted 6 lines
drivers/gpio/pca953x_gpio.c static int pca953x_probe(struct udevice *dev) · line 342
Quoted 3 lines
drivers/gpio/pca953x_gpio.c +1
-0info->bank_count =DIV_ROUND_UP (info->gpio_count,BANK_SZ ); + info->settle_delay_ms =dev_read_u32_default (dev,"gpio-settle-delay-ms" ,0 );Is this property supported also in Linux and defined in the Linux binding? I do not think we should have U-Boot specific DT properties.
yea you are right. I guess we can use gpio-delay instead.
~ Judith
Hi Judith,
Quoted 42 lines · Judith Mendez
Some board designs have slow RC circuits on GPIO outputs controlled by PCA953X I2C expanders. On some board designs, pin voltage transitions can take significant time after I2C write command completes.
Add an optional "gpio-settle-delay-ms" device tree property for the pca953x driver to add a delay after I2C write if specified, allowing to compensate for slow RC circuits.
Signed-off-by Judith Mendez <[email protected]>--- drivers/gpio/pca953x_gpio.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/gpio/pca953x_gpio.c +3
-0@@ -28,6 +28,7 @@#include <dm/device_compat.h> #include <dt-bindings/gpio/gpio.h> #include <linux/bitops.h> +#include <linux/delay.h> #define PCA953X_INPUT 0#define PCA953X_OUTPUT 1@@ -89,6 +90,7 @@ static const struct pca95xx_reg pca957x_regs = {* @reg_output: array to hold the value of output registers * @reg_direction: array to hold the value of direction registers * @regs: struct to hold the registers addresses +* @settle_delay_ms: GPIO pin settle delay in milliseconds */ struct pca953x_info {struct udevice *dev;@@ -100,6 +102,7 @@ struct pca953x_info {u8 reg_output[MAX_BANK ];u8 reg_direction[MAX_BANK ];const struct pca95xx_reg *regs; +u32 settle_delay_ms; }; static int pca953x_write_single(struct udevice *dev, int reg, u8 val,
drivers/gpio/pca953x_gpio.c static int pca953x_write_single(struct udevice *dev, int reg, u8 val, · line 126
Quoted 8 lines
drivers/gpio/pca953x_gpio.c +3
-0@@ -116,6 +119,9 @@ static int pca953x_write_single(struct udevice *dev, int reg, u8 val,return ret; } +if (info->settle_delay_ms) +mdelay (info->settle_delay_ms); +return 0 ; }
This delay is placed inside pca953x_write_single(), which is called by both pca953x_set_value() and pca953x_set_direction(). This results in a double delay for every direction_output call, which I think is unintended.
Additionally, a settle delay is only meaningful after changing an output level — it represents the time for the pin voltage to physically settle (e.g. through an RC circuit). Firing it on direction register writes does not make sense. The delay should be scoped only to pca953x_set_value().
drivers/gpio/pca953x_gpio.c static int pca953x_probe(struct udevice *dev) · line 343
Quoted 7 lines
drivers/gpio/pca953x_gpio.c +2
-0@@ -333,6 +339,8 @@ static int pca953x_probe(struct udevice *dev) info->bank_count =DIV_ROUND_UP (info->gpio_count,BANK_SZ ); + info->settle_delay_ms =dev_read_u32_default (dev,"gpio-settle-delay-ms" ,0 ); +
As Francesco mentioned, adding u-boot specifc properties causes the U-Boot DT to diverge from the Linux DT, which violates U-Boot's policy of maintaining DT compatibility with Linux.
drivers/gpio/pca953x_gpio.c static int pca953x_probe(struct udevice *dev) · line 346
Quoted 3 lines
drivers/gpio/pca953x_gpio.c +0
-0ret =pca953x_read_regs (dev, info->regs->output, info->reg_output);if (ret) {dev_err (dev,"Error reading output register\n" );
Given that the delay is due to a slow RC circuit on the output, I would suggest looking at the gpio-delay (gpio-delay.c, binding at gpio-delay.yaml). It is designed precisely for this scenario:
"This binding describes an electrical setup where setting a GPIO output is delayed by some external setup, e.g. RC circuit."
Regards,
Tanmay
Hi Tanmay,
Quoted 56 lines · Tanmay
Hi Judith,
Quoted 40 lines · Judith Mendez
Some board designs have slow RC circuits on GPIO outputs controlled by PCA953X I2C expanders. On some board designs, pin voltage transitions can take significant time after I2C write command completes.
Add an optional "gpio-settle-delay-ms" device tree property for the pca953x driver to add a delay after I2C write if specified, allowing to compensate for slow RC circuits.
Signed-off-by Judith Mendez <[email protected]>---
drivers/gpio/pca953x_gpio.c| 8 ++++++++1 file changed, 8 insertions(+)drivers/gpio/pca953x_gpio.c +3
-0@@ -28,6 +28,7 @@ #include <dm/device_compat.h> #include <dt-bindings/gpio/gpio.h> #include <linux/bitops.h> +#include <linux/delay.h> #define PCA953X_INPUT 0 #define PCA953X_OUTPUT 1@@ -89,6 +90,7 @@ static const struct pca95xx_reg pca957x_regs = {* @reg_output: array to hold the value of output registers * @reg_direction: array to hold the value of direction registers * @regs: struct to hold the registers addresses +* @settle_delay_ms: GPIO pin settle delay in milliseconds */ struct pca953x_info { struct udevice *dev;@@ -100,6 +102,7 @@ struct pca953x_info { u8 reg_output[MAX_BANK]; u8 reg_direction[MAX_BANK]; const struct pca95xx_reg *regs; + u32 settle_delay_ms; }; static int pca953x_write_single(struct udevice *dev, int reg, u8 val,drivers/gpio/pca953x_gpio.c static int pca953x_write_single(struct udevice · line 126
Quoted 8 lines
drivers/gpio/pca953x_gpio.c +3
-0@@ -116,6 +119,9 @@ static int pca953x_write_single(struct udevice *dev, int reg, u8 val, return ret; } + if (info->settle_delay_ms) + mdelay(info->settle_delay_ms); + return 0; }This delay is placed inside
pca953x_write_single(), which is called by bothpca953x_set_value()andpca953x_set_direction(). This results in a double delay for everydirection_outputcall, which I think is unintended.
Quoted 4 lines
Additionally, a settle delay is only meaningful after changing an output level — it represents the time for the pin voltage to physically settle (e.g. through an RC circuit). Firing it on direction register writes does not make sense. The delay should be scoped only to
pca953x_set_value().
Yea did not intended.
Quoted 15 lines
drivers/gpio/pca953x_gpio.c static int pca953x_probe(struct udevice *dev) · line 342
Quoted 6 lines
drivers/gpio/pca953x_gpio.c +2
-0@@ -333,6 +339,8 @@ static int pca953x_probe(struct udevice *dev) info->bank_count = DIV_ROUND_UP(info->gpio_count, BANK_SZ); + info->settle_delay_ms = dev_read_u32_default(dev, "gpio-settle- delay-ms", 0); +As Francesco mentioned, adding u-boot specifc properties causes the U- Boot DT to diverge from the Linux DT, which violates U-Boot's policy of maintaining DT compatibility with Linux.
drivers/gpio/pca953x_gpio.c static int pca953x_probe(struct udevice *dev) · line 346
Quoted 3 lines
drivers/gpio/pca953x_gpio.c +0
-0ret = pca953x_read_regs(dev, info->regs->output, info->reg_output); if (ret) { dev_err(dev, "Error reading output register\n");
Quoted 5 lines
Given that the delay is due to a slow RC circuit on the output, I would suggest looking at the gpio-delay (
gpio-delay.c, binding atgpio-delay.yaml). It is designed precisely for this scenario:
"This binding describes an electrical setup where setting a GPIO output is delayed by some external setup, e.g. RC circuit."
Thanks, Ill check that out.
~ Judith