Suspicious debounce handling code in pintctrl-baytrail
Hi Cristina,
In this commit:
commit 658b476c742fe379e7020309fd590a27b457a4c1
Date: Fri Apr 1 14:00:07 2016 +0300
pinctrl: baytrail: Add debounce configuration
you added support for getting and setting debounce configuration for the Baytrail pins. Now gcc complains about the following:
CC [M] drivers/pinctrl/intel/pinctrl-baytrail.odrivers/pinctrl/intel/pinctrl-baytrail.c: In function ‘byt_pin_config_set’:drivers/pinctrl/intel/pinctrl-baytrail.c:1181:17: warning: variable ‘debounce’ set but not used [-Wunused-but-set-variable]
u32 conf, val, debounce;
^I looked at the code, and it indeed looks wrong. You are reading the BYT_DEBOUNCE_REG register, clearing the debounce time bits from it, and then writing the debounce time bits to the *BYT_CONF0_REG* register. This is certainly corrupting the chip configuration, as the configuration register bits 2-0 have a completely different meaning (mux configuration.)
Did you ever test that code?
Additionally, I suspect that in the "get" path, the following is wrong:
case PIN_CONFIG_INPUT_DEBOUNCE: if (!(conf & BYT_DEBOUNCE_EN)) return -EINVAL;
I'm not familiar with the pinctrl interface but my understanding of the PIN_CONFIG_INPUT_DEBOUNCE documentation is that the driver must return 0 if debouncing is disabled. The "set" path would also need to handle this case properly (setting BYT_DEBOUNCE_EN if debounce timing is non-zero, clearing it if value is zero.)
Signature · 2 lines
Jean Delvare SUSE L3 Support
Quoted 18 lines · Jean Delvare
Hi Cristina,
In this commit:
commit
658b476c742fe379e7020309fd590a27b457a4c1
Date: Fri Apr 1 14:00:07 2016 +0300pinctrl: baytrail: Add debounce configuration
you added support for getting and setting debounce configuration for the Baytrail pins. Now gcc complains about the following:
CC [M]
drivers/pinctrl/intel/pinctrl-baytrail.odrivers/pinctrl/intel/pinctrl-baytrail.c: In function ‘byt_pin_config_set’:drivers/pinctrl/intel/pinctrl-baytrail.c:1181:17: warning: variable ‘debounce’ set but not used [-Wunused-but-set-variable]u32 conf, val, debounce; ^
Quoted 6 lines
I looked at the code, and it indeed looks wrong. You are reading the
BYT_DEBOUNCE_REGregister, clearing the debounce time bits from it, and then writing the debounce time bits to the *BYT_CONF0_REG* register. This is certainly corrupting the chip configuration, as the configuration register bits 2-0 have a completely different meaning (mux configuration.)
Yes, you are right.
This is fixed by following commit from Andy:
Hi Mika, hello Andy,
Quoted 26 lines · Mika Westerberg
Quoted 18 lines · Jean Delvare
Hi Cristina,
In this commit:
commit
658b476c742fe379e7020309fd590a27b457a4c1
Date: Fri Apr 1 14:00:07 2016 +0300pinctrl: baytrail: Add debounce configuration
you added support for getting and setting debounce configuration for the Baytrail pins. Now gcc complains about the following:
CC [M]
drivers/pinctrl/intel/pinctrl-baytrail.odrivers/pinctrl/intel/pinctrl-baytrail.c: In function ‘byt_pin_config_set’:drivers/pinctrl/intel/pinctrl-baytrail.c:1181:17: warning: variable ‘debounce’ set but not used [-Wunused-but-set-variable]u32 conf, val, debounce; ^Quoted 6 lines
I looked at the code, and it indeed looks wrong. You are reading the
BYT_DEBOUNCE_REGregister, clearing the debounce time bits from it, and then writing the debounce time bits to the *BYT_CONF0_REG* register. This is certainly corrupting the chip configuration, as the configuration register bits 2-0 have a completely different meaning (mux configuration.)
Quoted 5 lines
Yes, you are right.
This is fixed by following commit from Andy:
Thanks for the pointer, I wasn't aware of that patch. Looks overall good, but:
+ case 0:
+ conf &= BYT_DEBOUNCE_EN;
+ break;
looks suspicious to me. I think ~BYT_DEBOUNCE_EN was intended? Furthermore I would expect conf |= BYT_DEBOUNCE_EN in the other cases, otherwise disabling debounce once will prevent you from enabling it forever.
Also Andy's patch doesn't seem to address my second point:
Quoted 9 lines
Additionally, I suspect that in the "get" path, the following is wrong:
case PIN_CONFIG_INPUT_DEBOUNCE: if (!(conf & BYT_DEBOUNCE_EN)) return -EINVAL;I'm not familiar with the pinctrl interface but my understanding of the
PIN_CONFIG_INPUT_DEBOUNCEdocumentation is that the driver must return 0 if debouncing is disabled.
?
Thanks,
Signature · 2 lines
Jean Delvare SUSE L3 Support
Quoted 42 lines · Jean Delvare
Hi Mika, hello Andy,
Quoted 26 lines · Mika Westerberg
Quoted 18 lines · Jean Delvare
Hi Cristina,
In this commit:
commit
658b476c742fe379e7020309fd590a27b457a4c1
Date: Fri Apr 1 14:00:07 2016 +0300pinctrl: baytrail: Add debounce configuration
you added support for getting and setting debounce configuration for the Baytrail pins. Now gcc complains about the following:
CC [M]
drivers/pinctrl/intel/pinctrl-baytrail.odrivers/pinctrl/intel/pinctrl-baytrail.c: In function ‘byt_pin_config_set’:drivers/pinctrl/intel/pinctrl-baytrail.c:1181:17: warning: variable ‘debounce’ set but not used [-Wunused-but-set-variable]u32 conf, val, debounce; ^Quoted 6 lines
I looked at the code, and it indeed looks wrong. You are reading the
BYT_DEBOUNCE_REGregister, clearing the debounce time bits from it, and then writing the debounce time bits to the *BYT_CONF0_REG* register. This is certainly corrupting the chip configuration, as the configuration register bits 2-0 have a completely different meaning (mux configuration.)Quoted 5 lines
Yes, you are right.
This is fixed by following commit from Andy:
Thanks for the pointer, I wasn't aware of that patch. Looks overall good, but:
(quoted diff) +3
-0+ case 0: + conf &= BYT_DEBOUNCE_EN; + break;
Quoted 1 line
looks suspicious to me. I think ~BYT_DEBOUNCE_EN was intended?
Good catch! Yes, definitely it should be ~BYT_DEBOUNCE_EN.
Quoted 4 lines
Furthermore I would expect conf |=
BYT_DEBOUNCE_ENin the other cases, otherwise disabling debounce once will prevent you from enabling it forever.
Quoted 11 lines
Also Andy's patch doesn't seem to address my second point:
Quoted 9 lines
Additionally, I suspect that in the "get" path, the following is wrong:
case PIN_CONFIG_INPUT_DEBOUNCE: if (!(conf & BYT_DEBOUNCE_EN)) return -EINVAL;I'm not familiar with the pinctrl interface but my understanding of the
PIN_CONFIG_INPUT_DEBOUNCEdocumentation is that the driver must return 0 if debouncing is disabled.
Indeed, I also agree it should return 0 here.
We will fix this, thanks!
Quoted 12 lines · Jean Delvare
Hi Mika, hello Andy,
Quoted 1 line · Mika Westerberg
On Thu, Jan 26, 2017 at 02:20:20PM +0100, Jean Delvare wrote:
Thanks for the pointer, I wasn't aware of that patch. Looks overall good, but:
(quoted diff) +3
-0+ case 0: + conf &= BYT_DEBOUNCE_EN; + break;
Quoted 1 line
looks suspicious to me. I think ~BYT_DEBOUNCE_EN was intended?
Yes!
Quoted 3 lines
Furthermore I would expect conf |=
BYT_DEBOUNCE_ENin the other cases, otherwise disabling debounce once will prevent you from enabling it forever.
Yes.
Quoted 9 lines
Also Andy's patch doesn't seem to address my second point:
Quoted 7 lines
Additionally, I suspect that in the "get" path, the following is wrong:
case PIN_CONFIG_INPUT_DEBOUNCE: if (!(conf & BYT_DEBOUNCE_EN)) return -EINVAL;
Quoted 5 lines
Quoted 3 lines
I'm not familiar with the pinctrl interface but my understanding of the
PIN_CONFIG_INPUT_DEBOUNCEdocumentation is that the driver must return 0 if debouncing is disabled.?
I need to check this.
I will address your comments. Thanks for report!
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo
Quoted 11 lines · Andy Shevchenko
Quoted 10 lines · Jean Delvare
Hi Mika, hello Andy,
Additionally, I suspect that in the "get" path, the following is
Quoted 6 lines
wrong:
case PIN_CONFIG_INPUT_DEBOUNCE: if (!(conf & BYT_DEBOUNCE_EN)) return -EINVAL;
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
I'm not familiar with the pinctrl interface but my understanding of
thePIN_CONFIG_INPUT_DEBOUNCEdocumentation is that the driver must
return 0 if debouncing is disabled.?
No, this is correct.
"...if it is available but disabled it should return -EINVAL"
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo
Quoted 1 line · Mika Westerberg
We will fix this, thanks!
Great, thanks.
BTW I think that Andy's patch which fixes a bug that "even might break something physically" would deserve to be Cc'd to stable@ (once the fix itself is fixed, that is.)
Signature · 2 lines
Jean Delvare SUSE L3 Support
Quoted 18 lines · Andriy
Quoted 17 lines · Andy Shevchenko
Quoted 16 lines · Jean Delvare
Hi Mika, hello Andy,
Additionally, I suspect that in the "get" path, the following is
Quoted 11 lines
wrong:
case PIN_CONFIG_INPUT_DEBOUNCE: if (!(conf & BYT_DEBOUNCE_EN)) return -EINVAL;I'm not familiar with the pinctrl interface but my understanding of
thePIN_CONFIG_INPUT_DEBOUNCEdocumentation is that the driver must
return 0 if debouncing is disabled.
Quoted 4 lines
Quoted 1 line
Quoted 1 line
?
No, this is correct.
"...if it is available but disabled it should return-EINVAL"
OK, thanks Andy for checking it up.