diff mbox series

[2/5] Input: mtk-pmic-keys - Use regmap_{set, clear}_bits where possible

Message ID 20220520125132.229191-3-angelogioacchino.delregno@collabora.com (mailing list archive)
State New
Headers show
Series MediaTek Helio X10 MT6795 - MT6331 PMIC Keys | expand

Commit Message

AngeloGioacchino Del Regno May 20, 2022, 12:51 p.m. UTC
Instead of always using regmap_update_bits(), let's go for the shorter
regmap_set_bits() and regmap_clear_bits() where possible.

No functional change.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
 drivers/input/keyboard/mtk-pmic-keys.c | 24 ++++++------------------
 1 file changed, 6 insertions(+), 18 deletions(-)

Comments

Mattijs Korpershoek May 20, 2022, 3:38 p.m. UTC | #1
On ven., mai 20, 2022 at 14:51, AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> wrote:

> Instead of always using regmap_update_bits(), let's go for the shorter
> regmap_set_bits() and regmap_clear_bits() where possible.
>
> No functional change.
>
> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>

Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
> ---
>  drivers/input/keyboard/mtk-pmic-keys.c | 24 ++++++------------------
>  1 file changed, 6 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c
> index 8e4fa7cd16e6..83d0b90cc8cb 100644
> --- a/drivers/input/keyboard/mtk-pmic-keys.c
> +++ b/drivers/input/keyboard/mtk-pmic-keys.c
> @@ -157,28 +157,16 @@ static void mtk_pmic_keys_lp_reset_setup(struct mtk_pmic_keys *keys,
>  
>  	switch (long_press_mode) {
>  	case LP_ONEKEY:
> -		regmap_update_bits(keys->regmap, pmic_rst_reg,
> -				   MTK_PMIC_PWRKEY_RST,
> -				   MTK_PMIC_PWRKEY_RST);
> -		regmap_update_bits(keys->regmap, pmic_rst_reg,
> -				   MTK_PMIC_HOMEKEY_RST,
> -				   0);
> +		regmap_set_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_PWRKEY_RST);
> +		regmap_clear_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_HOMEKEY_RST);
>  		break;
>  	case LP_TWOKEY:
> -		regmap_update_bits(keys->regmap, pmic_rst_reg,
> -				   MTK_PMIC_PWRKEY_RST,
> -				   MTK_PMIC_PWRKEY_RST);
> -		regmap_update_bits(keys->regmap, pmic_rst_reg,
> -				   MTK_PMIC_HOMEKEY_RST,
> -				   MTK_PMIC_HOMEKEY_RST);
> +		regmap_set_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_PWRKEY_RST);
> +		regmap_set_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_HOMEKEY_RST);
>  		break;
>  	case LP_DISABLE:
> -		regmap_update_bits(keys->regmap, pmic_rst_reg,
> -				   MTK_PMIC_PWRKEY_RST,
> -				   0);
> -		regmap_update_bits(keys->regmap, pmic_rst_reg,
> -				   MTK_PMIC_HOMEKEY_RST,
> -				   0);
> +		regmap_clear_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_PWRKEY_RST);
> +		regmap_clear_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_HOMEKEY_RST);
>  		break;
>  	default:
>  		break;
> -- 
> 2.35.1
Dmitry Torokhov May 23, 2022, 4:51 a.m. UTC | #2
On Fri, May 20, 2022 at 02:51:29PM +0200, AngeloGioacchino Del Regno wrote:
> Instead of always using regmap_update_bits(), let's go for the shorter
> regmap_set_bits() and regmap_clear_bits() where possible.
> 
> No functional change.
> 
> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> ---
>  drivers/input/keyboard/mtk-pmic-keys.c | 24 ++++++------------------
>  1 file changed, 6 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c
> index 8e4fa7cd16e6..83d0b90cc8cb 100644
> --- a/drivers/input/keyboard/mtk-pmic-keys.c
> +++ b/drivers/input/keyboard/mtk-pmic-keys.c
> @@ -157,28 +157,16 @@ static void mtk_pmic_keys_lp_reset_setup(struct mtk_pmic_keys *keys,
>  
>  	switch (long_press_mode) {
>  	case LP_ONEKEY:
> -		regmap_update_bits(keys->regmap, pmic_rst_reg,
> -				   MTK_PMIC_PWRKEY_RST,
> -				   MTK_PMIC_PWRKEY_RST);
> -		regmap_update_bits(keys->regmap, pmic_rst_reg,
> -				   MTK_PMIC_HOMEKEY_RST,
> -				   0);
> +		regmap_set_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_PWRKEY_RST);
> +		regmap_clear_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_HOMEKEY_RST);

Why not combine this into a single update instead? I.e. assuming

#define MTK_PMIC_KEY_RST_MASK GENMASK(6, 5)

		regmap_update_bits(keys->regmap, pmic_rst_reg,
				   MTK_PMIC_KEY_RST_MASK,
				   MTK_PMIC_PWRKEY_RST);

>  		break;
>  	case LP_TWOKEY:
> -		regmap_update_bits(keys->regmap, pmic_rst_reg,
> -				   MTK_PMIC_PWRKEY_RST,
> -				   MTK_PMIC_PWRKEY_RST);
> -		regmap_update_bits(keys->regmap, pmic_rst_reg,
> -				   MTK_PMIC_HOMEKEY_RST,
> -				   MTK_PMIC_HOMEKEY_RST);
> +		regmap_set_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_PWRKEY_RST);
> +		regmap_set_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_HOMEKEY_RST);

		regmap_update_bits(keys->regmap, pmic_rst_reg,
				   MTK_PMIC_KEY_RST_MASK,
				   MTK_PMIC_PWRKEY_RST | MTK_PMIC_HOMEKEY_RST);

>  		break;
>  	case LP_DISABLE:
> -		regmap_update_bits(keys->regmap, pmic_rst_reg,
> -				   MTK_PMIC_PWRKEY_RST,
> -				   0);
> -		regmap_update_bits(keys->regmap, pmic_rst_reg,
> -				   MTK_PMIC_HOMEKEY_RST,
> -				   0);
> +		regmap_clear_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_PWRKEY_RST);
> +		regmap_clear_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_HOMEKEY_RST);

		regmap_update_bits(keys->regmap, pmic_rst_reg,
				   MTK_PMIC_KEY_RST_MASKi, 0);

>  		break;
>  	default:
>  		break;
> -- 
> 2.35.1
> 

Thanks.
AngeloGioacchino Del Regno May 23, 2022, 8:58 a.m. UTC | #3
Il 23/05/22 06:51, Dmitry Torokhov ha scritto:
> On Fri, May 20, 2022 at 02:51:29PM +0200, AngeloGioacchino Del Regno wrote:
>> Instead of always using regmap_update_bits(), let's go for the shorter
>> regmap_set_bits() and regmap_clear_bits() where possible.
>>
>> No functional change.
>>
>> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
>> ---
>>   drivers/input/keyboard/mtk-pmic-keys.c | 24 ++++++------------------
>>   1 file changed, 6 insertions(+), 18 deletions(-)
>>
>> diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c
>> index 8e4fa7cd16e6..83d0b90cc8cb 100644
>> --- a/drivers/input/keyboard/mtk-pmic-keys.c
>> +++ b/drivers/input/keyboard/mtk-pmic-keys.c
>> @@ -157,28 +157,16 @@ static void mtk_pmic_keys_lp_reset_setup(struct mtk_pmic_keys *keys,
>>   
>>   	switch (long_press_mode) {
>>   	case LP_ONEKEY:
>> -		regmap_update_bits(keys->regmap, pmic_rst_reg,
>> -				   MTK_PMIC_PWRKEY_RST,
>> -				   MTK_PMIC_PWRKEY_RST);
>> -		regmap_update_bits(keys->regmap, pmic_rst_reg,
>> -				   MTK_PMIC_HOMEKEY_RST,
>> -				   0);
>> +		regmap_set_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_PWRKEY_RST);
>> +		regmap_clear_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_HOMEKEY_RST);
> 
> Why not combine this into a single update instead? I.e. assuming
> 

All downstream kernels (at least, I checked 4 different kernel versions for 4
different SoCs) are doing these updates one-at-a-time, never combining them.

Even though I agree with you about one single update being simply more logical,
I am afraid that (on some SoCs) the IP will not like that so - since I don't have
any *clear* documentation saying that this is possible, or that this is not, I
would leave it like that.


> #define MTK_PMIC_KEY_RST_MASK GENMASK(6, 5)
> 
> 		regmap_update_bits(keys->regmap, pmic_rst_reg,
> 				   MTK_PMIC_KEY_RST_MASK,
> 				   MTK_PMIC_PWRKEY_RST);
> 
>>   		break;
>>   	case LP_TWOKEY:
>> -		regmap_update_bits(keys->regmap, pmic_rst_reg,
>> -				   MTK_PMIC_PWRKEY_RST,
>> -				   MTK_PMIC_PWRKEY_RST);
>> -		regmap_update_bits(keys->regmap, pmic_rst_reg,
>> -				   MTK_PMIC_HOMEKEY_RST,
>> -				   MTK_PMIC_HOMEKEY_RST);
>> +		regmap_set_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_PWRKEY_RST);
>> +		regmap_set_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_HOMEKEY_RST);
> 
> 		regmap_update_bits(keys->regmap, pmic_rst_reg,
> 				   MTK_PMIC_KEY_RST_MASK,
> 				   MTK_PMIC_PWRKEY_RST | MTK_PMIC_HOMEKEY_RST);
> 
>>   		break;
>>   	case LP_DISABLE:
>> -		regmap_update_bits(keys->regmap, pmic_rst_reg,
>> -				   MTK_PMIC_PWRKEY_RST,
>> -				   0);
>> -		regmap_update_bits(keys->regmap, pmic_rst_reg,
>> -				   MTK_PMIC_HOMEKEY_RST,
>> -				   0);
>> +		regmap_clear_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_PWRKEY_RST);
>> +		regmap_clear_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_HOMEKEY_RST);
> 
> 		regmap_update_bits(keys->regmap, pmic_rst_reg,
> 				   MTK_PMIC_KEY_RST_MASKi, 0);
> 
>>   		break;
>>   	default:
>>   		break;
>> -- 
>> 2.35.1
>>
> 
> Thanks.
>
Dmitry Torokhov May 23, 2022, 4:58 p.m. UTC | #4
On Mon, May 23, 2022 at 10:58:47AM +0200, AngeloGioacchino Del Regno wrote:
> Il 23/05/22 06:51, Dmitry Torokhov ha scritto:
> > On Fri, May 20, 2022 at 02:51:29PM +0200, AngeloGioacchino Del Regno wrote:
> > > Instead of always using regmap_update_bits(), let's go for the shorter
> > > regmap_set_bits() and regmap_clear_bits() where possible.
> > > 
> > > No functional change.
> > > 
> > > Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> > > ---
> > >   drivers/input/keyboard/mtk-pmic-keys.c | 24 ++++++------------------
> > >   1 file changed, 6 insertions(+), 18 deletions(-)
> > > 
> > > diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c
> > > index 8e4fa7cd16e6..83d0b90cc8cb 100644
> > > --- a/drivers/input/keyboard/mtk-pmic-keys.c
> > > +++ b/drivers/input/keyboard/mtk-pmic-keys.c
> > > @@ -157,28 +157,16 @@ static void mtk_pmic_keys_lp_reset_setup(struct mtk_pmic_keys *keys,
> > >   	switch (long_press_mode) {
> > >   	case LP_ONEKEY:
> > > -		regmap_update_bits(keys->regmap, pmic_rst_reg,
> > > -				   MTK_PMIC_PWRKEY_RST,
> > > -				   MTK_PMIC_PWRKEY_RST);
> > > -		regmap_update_bits(keys->regmap, pmic_rst_reg,
> > > -				   MTK_PMIC_HOMEKEY_RST,
> > > -				   0);
> > > +		regmap_set_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_PWRKEY_RST);
> > > +		regmap_clear_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_HOMEKEY_RST);
> > 
> > Why not combine this into a single update instead? I.e. assuming
> > 
> 
> All downstream kernels (at least, I checked 4 different kernel versions for 4
> different SoCs) are doing these updates one-at-a-time, never combining them.

It is not like drivers in these downstream kernels were developed
separately and each of them discovered this as a requirement. It was
written once by someone and then either copied as is, or maybe
additional key handling was added later.

> 
> Even though I agree with you about one single update being simply more logical,
> I am afraid that (on some SoCs) the IP will not like that so - since I don't have
> any *clear* documentation saying that this is possible, or that this is not, I
> would leave it like that.

If we go with that we will never be able to touch any of the hardware
interfaces, as I do not recall when spec would explicitly document every
register and call out that individual bits can be changed together in
one write.

Thanks.
diff mbox series

Patch

diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c
index 8e4fa7cd16e6..83d0b90cc8cb 100644
--- a/drivers/input/keyboard/mtk-pmic-keys.c
+++ b/drivers/input/keyboard/mtk-pmic-keys.c
@@ -157,28 +157,16 @@  static void mtk_pmic_keys_lp_reset_setup(struct mtk_pmic_keys *keys,
 
 	switch (long_press_mode) {
 	case LP_ONEKEY:
-		regmap_update_bits(keys->regmap, pmic_rst_reg,
-				   MTK_PMIC_PWRKEY_RST,
-				   MTK_PMIC_PWRKEY_RST);
-		regmap_update_bits(keys->regmap, pmic_rst_reg,
-				   MTK_PMIC_HOMEKEY_RST,
-				   0);
+		regmap_set_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_PWRKEY_RST);
+		regmap_clear_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_HOMEKEY_RST);
 		break;
 	case LP_TWOKEY:
-		regmap_update_bits(keys->regmap, pmic_rst_reg,
-				   MTK_PMIC_PWRKEY_RST,
-				   MTK_PMIC_PWRKEY_RST);
-		regmap_update_bits(keys->regmap, pmic_rst_reg,
-				   MTK_PMIC_HOMEKEY_RST,
-				   MTK_PMIC_HOMEKEY_RST);
+		regmap_set_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_PWRKEY_RST);
+		regmap_set_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_HOMEKEY_RST);
 		break;
 	case LP_DISABLE:
-		regmap_update_bits(keys->regmap, pmic_rst_reg,
-				   MTK_PMIC_PWRKEY_RST,
-				   0);
-		regmap_update_bits(keys->regmap, pmic_rst_reg,
-				   MTK_PMIC_HOMEKEY_RST,
-				   0);
+		regmap_clear_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_PWRKEY_RST);
+		regmap_clear_bits(keys->regmap, pmic_rst_reg, MTK_PMIC_HOMEKEY_RST);
 		break;
 	default:
 		break;