diff mbox series

[2/2] Input: pm8941-powerkey - fix debounce on gen2+ PMICs

Message ID 20230529-pm8941-pwrkey-debounce-v1-2-c043a6d5c814@linaro.org (mailing list archive)
State Not Applicable
Headers show
Series Fix pm8941-pwrkey debounce programming | expand

Commit Message

Caleb Connolly May 29, 2023, 7:55 p.m. UTC
Since PM8998/PM660, the power key debounce register was redefined to
support shorter debounce times. On PM8941 the shortest debounce time
(represented by register value 0) was 15625us, on PM8998 the shortest
debounce time is 62us, with the default being 2ms.

Adjust the bit shift to correctly program debounce on PM8998 and newer.

Fixes: 68c581d5e7d8 ("Input: add Qualcomm PM8941 power key driver")
Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
---
This patch shouldn't be backported earlier then 5.4, as that is the
first kernel with support for PM8998.
---
 drivers/input/misc/pm8941-pwrkey.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

Comments

Konrad Dybcio May 30, 2023, 9:36 a.m. UTC | #1
On 29.05.2023 21:55, Caleb Connolly wrote:
> Since PM8998/PM660, the power key debounce register was redefined to
> support shorter debounce times. On PM8941 the shortest debounce time
> (represented by register value 0) was 15625us, on PM8998 the shortest
> debounce time is 62us, with the default being 2ms.
> 
> Adjust the bit shift to correctly program debounce on PM8998 and newer.
> 
> Fixes: 68c581d5e7d8 ("Input: add Qualcomm PM8941 power key driver")
> Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
> ---
> This patch shouldn't be backported earlier then 5.4, as that is the
> first kernel with support for PM8998.
> ---
>  drivers/input/misc/pm8941-pwrkey.c | 19 +++++++++++++++----
>  1 file changed, 15 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/input/misc/pm8941-pwrkey.c b/drivers/input/misc/pm8941-pwrkey.c
> index b6a27ebae977..74d77d8aaeff 100644
> --- a/drivers/input/misc/pm8941-pwrkey.c
> +++ b/drivers/input/misc/pm8941-pwrkey.c
> @@ -50,7 +50,10 @@
>  #define  PON_RESIN_PULL_UP		BIT(0)
>  
>  #define PON_DBC_CTL			0x71
> -#define  PON_DBC_DELAY_MASK		0x7
> +#define  PON_DBC_DELAY_MASK_GEN1	0x7
> +#define  PON_DBC_DELAY_MASK_GEN2	0xf
> +#define  PON_DBC_SHIFT_GEN1		6
> +#define  PON_DBC_SHIFT_GEN2		14
mask+shift -> field_prep/get?

Nice find!

Konrad
>  
>  struct pm8941_data {
>  	unsigned int	pull_up_bit;
> @@ -247,7 +250,7 @@ static int pm8941_pwrkey_probe(struct platform_device *pdev)
>  	struct device *parent;
>  	struct device_node *regmap_node;
>  	const __be32 *addr;
> -	u32 req_delay;
> +	u32 req_delay, mask, delay_shift;
>  	int error;
>  
>  	if (of_property_read_u32(pdev->dev.of_node, "debounce", &req_delay))
> @@ -336,12 +339,20 @@ static int pm8941_pwrkey_probe(struct platform_device *pdev)
>  	pwrkey->input->phys = pwrkey->data->phys;
>  
>  	if (pwrkey->data->supports_debounce_config) {
> -		req_delay = (req_delay << 6) / USEC_PER_SEC;
> +		if (pwrkey->subtype >= PON_SUBTYPE_GEN2_PRIMARY) {
> +			mask = PON_DBC_DELAY_MASK_GEN2;
> +			delay_shift = PON_DBC_SHIFT_GEN2;
> +		} else {
> +			mask = PON_DBC_DELAY_MASK_GEN1;
> +			delay_shift = PON_DBC_SHIFT_GEN1;
> +		}
> +
> +		req_delay = (req_delay << delay_shift) / USEC_PER_SEC;
>  		req_delay = ilog2(req_delay);
>  
>  		error = regmap_update_bits(pwrkey->regmap,
>  					   pwrkey->baseaddr + PON_DBC_CTL,
> -					   PON_DBC_DELAY_MASK,
> +					   mask,
>  					   req_delay);
>  		if (error) {
>  			dev_err(&pdev->dev, "failed to set debounce: %d\n",
>
Caleb Connolly May 30, 2023, 1 p.m. UTC | #2
On 30/05/2023 10:36, Konrad Dybcio wrote:
> 
> 
> On 29.05.2023 21:55, Caleb Connolly wrote:
>> Since PM8998/PM660, the power key debounce register was redefined to
>> support shorter debounce times. On PM8941 the shortest debounce time
>> (represented by register value 0) was 15625us, on PM8998 the shortest
>> debounce time is 62us, with the default being 2ms.
>>
>> Adjust the bit shift to correctly program debounce on PM8998 and newer.
>>
>> Fixes: 68c581d5e7d8 ("Input: add Qualcomm PM8941 power key driver")
>> Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
>> ---
>> This patch shouldn't be backported earlier then 5.4, as that is the
>> first kernel with support for PM8998.
>> ---
>>  drivers/input/misc/pm8941-pwrkey.c | 19 +++++++++++++++----
>>  1 file changed, 15 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/input/misc/pm8941-pwrkey.c b/drivers/input/misc/pm8941-pwrkey.c
>> index b6a27ebae977..74d77d8aaeff 100644
>> --- a/drivers/input/misc/pm8941-pwrkey.c
>> +++ b/drivers/input/misc/pm8941-pwrkey.c
>> @@ -50,7 +50,10 @@
>>  #define  PON_RESIN_PULL_UP		BIT(0)
>>  
>>  #define PON_DBC_CTL			0x71
>> -#define  PON_DBC_DELAY_MASK		0x7
>> +#define  PON_DBC_DELAY_MASK_GEN1	0x7
>> +#define  PON_DBC_DELAY_MASK_GEN2	0xf
>> +#define  PON_DBC_SHIFT_GEN1		6
>> +#define  PON_DBC_SHIFT_GEN2		14
> mask+shift -> field_prep/get?

I figured it was better to keep it consistent and try to minimise the
diff so that backporting is easier.

Migrating over to bitfield helpers probably makes sense to do as a
separate change - maybe if a new platform comes along and requires even
more additional complexity?
> 
> Nice find!
> 
> Konrad
>>  
>>  struct pm8941_data {
>>  	unsigned int	pull_up_bit;
>> @@ -247,7 +250,7 @@ static int pm8941_pwrkey_probe(struct platform_device *pdev)
>>  	struct device *parent;
>>  	struct device_node *regmap_node;
>>  	const __be32 *addr;
>> -	u32 req_delay;
>> +	u32 req_delay, mask, delay_shift;
>>  	int error;
>>  
>>  	if (of_property_read_u32(pdev->dev.of_node, "debounce", &req_delay))
>> @@ -336,12 +339,20 @@ static int pm8941_pwrkey_probe(struct platform_device *pdev)
>>  	pwrkey->input->phys = pwrkey->data->phys;
>>  
>>  	if (pwrkey->data->supports_debounce_config) {
>> -		req_delay = (req_delay << 6) / USEC_PER_SEC;
>> +		if (pwrkey->subtype >= PON_SUBTYPE_GEN2_PRIMARY) {
>> +			mask = PON_DBC_DELAY_MASK_GEN2;
>> +			delay_shift = PON_DBC_SHIFT_GEN2;
>> +		} else {
>> +			mask = PON_DBC_DELAY_MASK_GEN1;
>> +			delay_shift = PON_DBC_SHIFT_GEN1;
>> +		}
>> +
>> +		req_delay = (req_delay << delay_shift) / USEC_PER_SEC;
>>  		req_delay = ilog2(req_delay);
>>  
>>  		error = regmap_update_bits(pwrkey->regmap,
>>  					   pwrkey->baseaddr + PON_DBC_CTL,
>> -					   PON_DBC_DELAY_MASK,
>> +					   mask,
>>  					   req_delay);
>>  		if (error) {
>>  			dev_err(&pdev->dev, "failed to set debounce: %d\n",
>>
Dmitry Torokhov June 6, 2023, 7:12 p.m. UTC | #3
On Mon, May 29, 2023 at 08:55:07PM +0100, Caleb Connolly wrote:
> Since PM8998/PM660, the power key debounce register was redefined to
> support shorter debounce times. On PM8941 the shortest debounce time
> (represented by register value 0) was 15625us, on PM8998 the shortest
> debounce time is 62us, with the default being 2ms.
> 
> Adjust the bit shift to correctly program debounce on PM8998 and newer.
> 
> Fixes: 68c581d5e7d8 ("Input: add Qualcomm PM8941 power key driver")
> Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>

Applied, thank you.
diff mbox series

Patch

diff --git a/drivers/input/misc/pm8941-pwrkey.c b/drivers/input/misc/pm8941-pwrkey.c
index b6a27ebae977..74d77d8aaeff 100644
--- a/drivers/input/misc/pm8941-pwrkey.c
+++ b/drivers/input/misc/pm8941-pwrkey.c
@@ -50,7 +50,10 @@ 
 #define  PON_RESIN_PULL_UP		BIT(0)
 
 #define PON_DBC_CTL			0x71
-#define  PON_DBC_DELAY_MASK		0x7
+#define  PON_DBC_DELAY_MASK_GEN1	0x7
+#define  PON_DBC_DELAY_MASK_GEN2	0xf
+#define  PON_DBC_SHIFT_GEN1		6
+#define  PON_DBC_SHIFT_GEN2		14
 
 struct pm8941_data {
 	unsigned int	pull_up_bit;
@@ -247,7 +250,7 @@  static int pm8941_pwrkey_probe(struct platform_device *pdev)
 	struct device *parent;
 	struct device_node *regmap_node;
 	const __be32 *addr;
-	u32 req_delay;
+	u32 req_delay, mask, delay_shift;
 	int error;
 
 	if (of_property_read_u32(pdev->dev.of_node, "debounce", &req_delay))
@@ -336,12 +339,20 @@  static int pm8941_pwrkey_probe(struct platform_device *pdev)
 	pwrkey->input->phys = pwrkey->data->phys;
 
 	if (pwrkey->data->supports_debounce_config) {
-		req_delay = (req_delay << 6) / USEC_PER_SEC;
+		if (pwrkey->subtype >= PON_SUBTYPE_GEN2_PRIMARY) {
+			mask = PON_DBC_DELAY_MASK_GEN2;
+			delay_shift = PON_DBC_SHIFT_GEN2;
+		} else {
+			mask = PON_DBC_DELAY_MASK_GEN1;
+			delay_shift = PON_DBC_SHIFT_GEN1;
+		}
+
+		req_delay = (req_delay << delay_shift) / USEC_PER_SEC;
 		req_delay = ilog2(req_delay);
 
 		error = regmap_update_bits(pwrkey->regmap,
 					   pwrkey->baseaddr + PON_DBC_CTL,
-					   PON_DBC_DELAY_MASK,
+					   mask,
 					   req_delay);
 		if (error) {
 			dev_err(&pdev->dev, "failed to set debounce: %d\n",