linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Input: adp5589-keys - use BIT()
@ 2020-11-19  7:24 Dmitry Torokhov
  2020-11-19  7:34 ` Joe Perches
  2020-11-19  8:28 ` Ardelean, Alexandru
  0 siblings, 2 replies; 4+ messages in thread
From: Dmitry Torokhov @ 2020-11-19  7:24 UTC (permalink / raw)
  To: linux-input; +Cc: Alexandru Ardelean, linux-kernel

Let's use BIT() macro instead of explicitly shifting '1'.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/input/keyboard/adp5589-keys.c | 69 ++++++++++++++-------------
 1 file changed, 35 insertions(+), 34 deletions(-)

diff --git a/drivers/input/keyboard/adp5589-keys.c b/drivers/input/keyboard/adp5589-keys.c
index a9b69a268c09..70c8d1c298ee 100644
--- a/drivers/input/keyboard/adp5589-keys.c
+++ b/drivers/input/keyboard/adp5589-keys.c
@@ -7,6 +7,7 @@
  * Copyright (C) 2010-2011 Analog Devices Inc.
  */
 
+#include <linux/bitops.h>
 #include <linux/module.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
@@ -153,48 +154,48 @@
 #define ADP5589_5_MAN_ID		0x02
 
 /* GENERAL_CFG Register */
-#define OSC_EN		(1 << 7)
+#define OSC_EN		BIT(7)
 #define CORE_CLK(x)	(((x) & 0x3) << 5)
-#define LCK_TRK_LOGIC	(1 << 4)	/* ADP5589 only */
-#define LCK_TRK_GPI	(1 << 3)	/* ADP5589 only */
-#define INT_CFG		(1 << 1)
-#define RST_CFG		(1 << 0)
+#define LCK_TRK_LOGIC	BIT(4)		/* ADP5589 only */
+#define LCK_TRK_GPI	BIT(3)		/* ADP5589 only */
+#define INT_CFG		BIT(1)
+#define RST_CFG		BIT(0)
 
 /* INT_EN Register */
-#define LOGIC2_IEN	(1 << 5)	/* ADP5589 only */
-#define LOGIC1_IEN	(1 << 4)
-#define LOCK_IEN	(1 << 3)	/* ADP5589 only */
-#define OVRFLOW_IEN	(1 << 2)
-#define GPI_IEN		(1 << 1)
-#define EVENT_IEN	(1 << 0)
+#define LOGIC2_IEN	BIT(5)		/* ADP5589 only */
+#define LOGIC1_IEN	BIT(4)
+#define LOCK_IEN	BIT(3)		/* ADP5589 only */
+#define OVRFLOW_IEN	BIT(2)
+#define GPI_IEN		BIT(1)
+#define EVENT_IEN	BIT(0)
 
 /* Interrupt Status Register */
-#define LOGIC2_INT	(1 << 5)	/* ADP5589 only */
-#define LOGIC1_INT	(1 << 4)
-#define LOCK_INT	(1 << 3)	/* ADP5589 only */
-#define OVRFLOW_INT	(1 << 2)
-#define GPI_INT		(1 << 1)
-#define EVENT_INT	(1 << 0)
+#define LOGIC2_INT	BIT(5)		/* ADP5589 only */
+#define LOGIC1_INT	BIT(4)
+#define LOCK_INT	BIT(3)		/* ADP5589 only */
+#define OVRFLOW_INT	BIT(2)
+#define GPI_INT		BIT(1)
+#define EVENT_INT	BIT(0)
 
 /* STATUS Register */
-#define LOGIC2_STAT	(1 << 7)	/* ADP5589 only */
-#define LOGIC1_STAT	(1 << 6)
-#define LOCK_STAT	(1 << 5)	/* ADP5589 only */
+#define LOGIC2_STAT	BIT(7)		/* ADP5589 only */
+#define LOGIC1_STAT	BIT(6)
+#define LOCK_STAT	BIT(5)		/* ADP5589 only */
 #define KEC		0x1F
 
 /* PIN_CONFIG_D Register */
-#define C4_EXTEND_CFG	(1 << 6)	/* RESET2 */
-#define R4_EXTEND_CFG	(1 << 5)	/* RESET1 */
+#define C4_EXTEND_CFG	BIT(6)		/* RESET2 */
+#define R4_EXTEND_CFG	BIT(5)		/* RESET1 */
 
 /* LOCK_CFG */
-#define LOCK_EN		(1 << 0)
+#define LOCK_EN		BIT(0)
 
 #define PTIME_MASK	0x3
 #define LTIME_MASK	0x3		/* ADP5589 only */
 
 /* Key Event Register xy */
-#define KEY_EV_PRESSED		(1 << 7)
-#define KEY_EV_MASK		(0x7F)
+#define KEY_EV_PRESSED	BIT(7)
+#define KEY_EV_MASK	0x7F
 
 #define KEYP_MAX_EVENT		16
 #define ADP5589_MAXGPIO		19
@@ -472,7 +473,7 @@ static int adp5589_build_gpiomap(struct adp5589_kpad *kpad,
 	memset(pin_used, false, sizeof(pin_used));
 
 	for (i = 0; i < kpad->var->maxgpio; i++)
-		if (pdata->keypad_en_mask & (1 << i))
+		if (pdata->keypad_en_mask & BIT(i))
 			pin_used[i] = true;
 
 	for (i = 0; i < kpad->gpimapsize; i++)
@@ -651,13 +652,13 @@ static int adp5589_setup(struct adp5589_kpad *kpad)
 		unsigned short pin = pdata->gpimap[i].pin;
 
 		if (pin <= kpad->var->gpi_pin_row_end) {
-			evt_mode1 |= (1 << (pin - kpad->var->gpi_pin_row_base));
+			evt_mode1 |= BIT(pin - kpad->var->gpi_pin_row_base);
 		} else {
 			evt_mode2 |=
-			    ((1 << (pin - kpad->var->gpi_pin_col_base)) & 0xFF);
+			    BIT(pin - kpad->var->gpi_pin_col_base) & 0xFF;
 			if (!kpad->is_adp5585)
-				evt_mode3 |= ((1 << (pin -
-					kpad->var->gpi_pin_col_base)) >> 8);
+				evt_mode3 |=
+				    BIT(pin - kpad->var->gpi_pin_col_base) >> 8;
 		}
 	}
 
@@ -677,7 +678,7 @@ static int adp5589_setup(struct adp5589_kpad *kpad)
 		dev_warn(&client->dev, "Conflicting pull resistor config\n");
 
 	for (i = 0; i <= kpad->var->max_row_num; i++) {
-		unsigned val = 0, bit = (1 << i);
+		unsigned val = 0, bit = BIT(i);
 		if (pdata->pullup_en_300k & bit)
 			val = 0;
 		else if (pdata->pulldown_en_300k & bit)
@@ -697,7 +698,7 @@ static int adp5589_setup(struct adp5589_kpad *kpad)
 	}
 
 	for (i = 0; i <= kpad->var->max_col_num; i++) {
-		unsigned val = 0, bit = 1 << (i + kpad->var->col_shift);
+		unsigned val = 0, bit = BIT(i + kpad->var->col_shift);
 		if (pdata->pullup_en_300k & bit)
 			val = 0;
 		else if (pdata->pulldown_en_300k & bit)
@@ -813,7 +814,7 @@ static void adp5589_report_switch_state(struct adp5589_kpad *kpad)
 
 		input_report_switch(kpad->input,
 				    kpad->gpimap[i].sw_evt,
-				    !(gpi_stat_tmp & (1 << pin_loc)));
+				    !(gpi_stat_tmp & BIT(pin_loc)));
 	}
 
 	input_sync(kpad->input);
@@ -859,7 +860,7 @@ static int adp5589_keypad_add(struct adp5589_kpad *kpad, unsigned int revid)
 			return -EINVAL;
 		}
 
-		if ((1 << (pin - kpad->var->gpi_pin_row_base)) &
+		if (BIT(pin - kpad->var->gpi_pin_row_base) &
 				pdata->keypad_en_mask) {
 			dev_err(&client->dev, "invalid gpi row/col data\n");
 			return -EINVAL;
-- 
2.29.2.299.gdc1121823c-goog


-- 
Dmitry

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Input: adp5589-keys - use BIT()
  2020-11-19  7:24 [PATCH] Input: adp5589-keys - use BIT() Dmitry Torokhov
@ 2020-11-19  7:34 ` Joe Perches
  2020-11-19  7:44   ` Dmitry Torokhov
  2020-11-19  8:28 ` Ardelean, Alexandru
  1 sibling, 1 reply; 4+ messages in thread
From: Joe Perches @ 2020-11-19  7:34 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input; +Cc: Alexandru Ardelean, linux-kernel

On Wed, 2020-11-18 at 23:24 -0800, Dmitry Torokhov wrote:
> Let's use BIT() macro instead of explicitly shifting '1'.
[]
> diff --git a/drivers/input/keyboard/adp5589-keys.c b/drivers/input/keyboard/adp5589-keys.c

> @@ -651,13 +652,13 @@ static int adp5589_setup(struct adp5589_kpad *kpad)
>  		unsigned short pin = pdata->gpimap[i].pin;
>  

trivia:

Perhaps nicer to create and use a temporary

	unsigned int bit = BIT(pin - kpad->var->gpi_pin_col_base);

so in these places below:

>  		if (pin <= kpad->var->gpi_pin_row_end) {
> -			evt_mode1 |= (1 << (pin - kpad->var->gpi_pin_row_base));
> +			evt_mode1 |= BIT(pin - kpad->var->gpi_pin_row_base);

			evt_mode1 |= bit;

>  		} else {
>  			evt_mode2 |=
> -			    ((1 << (pin - kpad->var->gpi_pin_col_base)) & 0xFF);
> +			    BIT(pin - kpad->var->gpi_pin_col_base) & 0xFF;

			evt_mode2 |= bit & 0xff;

>  			if (!kpad->is_adp5585)
> -				evt_mode3 |= ((1 << (pin -
> -					kpad->var->gpi_pin_col_base)) >> 8);
> +				evt_mode3 |=
> +				    BIT(pin - kpad->var->gpi_pin_col_base) >> 8;

				evt_mode3 |= bit >> 8;



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Input: adp5589-keys - use BIT()
  2020-11-19  7:34 ` Joe Perches
@ 2020-11-19  7:44   ` Dmitry Torokhov
  0 siblings, 0 replies; 4+ messages in thread
From: Dmitry Torokhov @ 2020-11-19  7:44 UTC (permalink / raw)
  To: Joe Perches; +Cc: linux-input, Alexandru Ardelean, linux-kernel

On Wed, Nov 18, 2020 at 11:34:28PM -0800, Joe Perches wrote:
> On Wed, 2020-11-18 at 23:24 -0800, Dmitry Torokhov wrote:
> > Let's use BIT() macro instead of explicitly shifting '1'.
> []
> > diff --git a/drivers/input/keyboard/adp5589-keys.c b/drivers/input/keyboard/adp5589-keys.c
> 
> > @@ -651,13 +652,13 @@ static int adp5589_setup(struct adp5589_kpad *kpad)
> >  		unsigned short pin = pdata->gpimap[i].pin;
> >  
> 
> trivia:
> 
> Perhaps nicer to create and use a temporary
> 
> 	unsigned int bit = BIT(pin - kpad->var->gpi_pin_col_base);
> 
> so in these places below:
> 
> >  		if (pin <= kpad->var->gpi_pin_row_end) {
> > -			evt_mode1 |= (1 << (pin - kpad->var->gpi_pin_row_base));
> > +			evt_mode1 |= BIT(pin - kpad->var->gpi_pin_row_base);
> 
> 			evt_mode1 |= bit;
> 
> >  		} else {
> >  			evt_mode2 |=
> > -			    ((1 << (pin - kpad->var->gpi_pin_col_base)) & 0xFF);
> > +			    BIT(pin - kpad->var->gpi_pin_col_base) & 0xFF;
> 
> 			evt_mode2 |= bit & 0xff;

Different "bit" tough - row vs column.

> 
> >  			if (!kpad->is_adp5585)
> > -				evt_mode3 |= ((1 << (pin -
> > -					kpad->var->gpi_pin_col_base)) >> 8);
> > +				evt_mode3 |=
> > +				    BIT(pin - kpad->var->gpi_pin_col_base) >> 8;
> 
> 				evt_mode3 |= bit >> 8;
> 
> 

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] Input: adp5589-keys - use BIT()
  2020-11-19  7:24 [PATCH] Input: adp5589-keys - use BIT() Dmitry Torokhov
  2020-11-19  7:34 ` Joe Perches
@ 2020-11-19  8:28 ` Ardelean, Alexandru
  1 sibling, 0 replies; 4+ messages in thread
From: Ardelean, Alexandru @ 2020-11-19  8:28 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input; +Cc: linux-kernel



> -----Original Message-----
> From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Sent: Thursday, November 19, 2020 9:25 AM
> To: linux-input@vger.kernel.org
> Cc: Ardelean, Alexandru <alexandru.Ardelean@analog.com>; linux-
> kernel@vger.kernel.org
> Subject: [PATCH] Input: adp5589-keys - use BIT()
> 
> [External]
> 
> Let's use BIT() macro instead of explicitly shifting '1'.

As a first iteration for cleaning up bitmask stuff, this looks good.
So:

Acked-by: Alexandru Ardelean <Alexandru.ardelean@analog.com>

As a continuation, in some places, some GENMASK() and FIELD_GET() macros would be an idea for some contiguous bits.
I can do that later.
For now, my todo-list doesn't include these conversions.

Thanks
Alex

> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>  drivers/input/keyboard/adp5589-keys.c | 69 ++++++++++++++-------------
>  1 file changed, 35 insertions(+), 34 deletions(-)
> 
> diff --git a/drivers/input/keyboard/adp5589-keys.c
> b/drivers/input/keyboard/adp5589-keys.c
> index a9b69a268c09..70c8d1c298ee 100644
> --- a/drivers/input/keyboard/adp5589-keys.c
> +++ b/drivers/input/keyboard/adp5589-keys.c
> @@ -7,6 +7,7 @@
>   * Copyright (C) 2010-2011 Analog Devices Inc.
>   */
> 
> +#include <linux/bitops.h>
>  #include <linux/module.h>
>  #include <linux/interrupt.h>
>  #include <linux/irq.h>
> @@ -153,48 +154,48 @@
>  #define ADP5589_5_MAN_ID		0x02
> 
>  /* GENERAL_CFG Register */
> -#define OSC_EN		(1 << 7)
> +#define OSC_EN		BIT(7)
>  #define CORE_CLK(x)	(((x) & 0x3) << 5)
> -#define LCK_TRK_LOGIC	(1 << 4)	/* ADP5589 only */
> -#define LCK_TRK_GPI	(1 << 3)	/* ADP5589 only */
> -#define INT_CFG		(1 << 1)
> -#define RST_CFG		(1 << 0)
> +#define LCK_TRK_LOGIC	BIT(4)		/* ADP5589 only */
> +#define LCK_TRK_GPI	BIT(3)		/* ADP5589 only */
> +#define INT_CFG		BIT(1)
> +#define RST_CFG		BIT(0)
> 
>  /* INT_EN Register */
> -#define LOGIC2_IEN	(1 << 5)	/* ADP5589 only */
> -#define LOGIC1_IEN	(1 << 4)
> -#define LOCK_IEN	(1 << 3)	/* ADP5589 only */
> -#define OVRFLOW_IEN	(1 << 2)
> -#define GPI_IEN		(1 << 1)
> -#define EVENT_IEN	(1 << 0)
> +#define LOGIC2_IEN	BIT(5)		/* ADP5589 only */
> +#define LOGIC1_IEN	BIT(4)
> +#define LOCK_IEN	BIT(3)		/* ADP5589 only */
> +#define OVRFLOW_IEN	BIT(2)
> +#define GPI_IEN		BIT(1)
> +#define EVENT_IEN	BIT(0)
> 
>  /* Interrupt Status Register */
> -#define LOGIC2_INT	(1 << 5)	/* ADP5589 only */
> -#define LOGIC1_INT	(1 << 4)
> -#define LOCK_INT	(1 << 3)	/* ADP5589 only */
> -#define OVRFLOW_INT	(1 << 2)
> -#define GPI_INT		(1 << 1)
> -#define EVENT_INT	(1 << 0)
> +#define LOGIC2_INT	BIT(5)		/* ADP5589 only */
> +#define LOGIC1_INT	BIT(4)
> +#define LOCK_INT	BIT(3)		/* ADP5589 only */
> +#define OVRFLOW_INT	BIT(2)
> +#define GPI_INT		BIT(1)
> +#define EVENT_INT	BIT(0)
> 
>  /* STATUS Register */
> -#define LOGIC2_STAT	(1 << 7)	/* ADP5589 only */
> -#define LOGIC1_STAT	(1 << 6)
> -#define LOCK_STAT	(1 << 5)	/* ADP5589 only */
> +#define LOGIC2_STAT	BIT(7)		/* ADP5589 only */
> +#define LOGIC1_STAT	BIT(6)
> +#define LOCK_STAT	BIT(5)		/* ADP5589 only */
>  #define KEC		0x1F
> 
>  /* PIN_CONFIG_D Register */
> -#define C4_EXTEND_CFG	(1 << 6)	/* RESET2 */
> -#define R4_EXTEND_CFG	(1 << 5)	/* RESET1 */
> +#define C4_EXTEND_CFG	BIT(6)		/* RESET2 */
> +#define R4_EXTEND_CFG	BIT(5)		/* RESET1 */
> 
>  /* LOCK_CFG */
> -#define LOCK_EN		(1 << 0)
> +#define LOCK_EN		BIT(0)
> 
>  #define PTIME_MASK	0x3
>  #define LTIME_MASK	0x3		/* ADP5589 only */
> 
>  /* Key Event Register xy */
> -#define KEY_EV_PRESSED		(1 << 7)
> -#define KEY_EV_MASK		(0x7F)
> +#define KEY_EV_PRESSED	BIT(7)
> +#define KEY_EV_MASK	0x7F
> 
>  #define KEYP_MAX_EVENT		16
>  #define ADP5589_MAXGPIO		19
> @@ -472,7 +473,7 @@ static int adp5589_build_gpiomap(struct adp5589_kpad
> *kpad,
>  	memset(pin_used, false, sizeof(pin_used));
> 
>  	for (i = 0; i < kpad->var->maxgpio; i++)
> -		if (pdata->keypad_en_mask & (1 << i))
> +		if (pdata->keypad_en_mask & BIT(i))
>  			pin_used[i] = true;
> 
>  	for (i = 0; i < kpad->gpimapsize; i++) @@ -651,13 +652,13 @@ static int
> adp5589_setup(struct adp5589_kpad *kpad)
>  		unsigned short pin = pdata->gpimap[i].pin;
> 
>  		if (pin <= kpad->var->gpi_pin_row_end) {
> -			evt_mode1 |= (1 << (pin - kpad->var-
> >gpi_pin_row_base));
> +			evt_mode1 |= BIT(pin - kpad->var->gpi_pin_row_base);
>  		} else {
>  			evt_mode2 |=
> -			    ((1 << (pin - kpad->var->gpi_pin_col_base)) & 0xFF);
> +			    BIT(pin - kpad->var->gpi_pin_col_base) & 0xFF;
>  			if (!kpad->is_adp5585)
> -				evt_mode3 |= ((1 << (pin -
> -					kpad->var->gpi_pin_col_base)) >> 8);
> +				evt_mode3 |=
> +				    BIT(pin - kpad->var->gpi_pin_col_base) >> 8;
>  		}
>  	}
> 
> @@ -677,7 +678,7 @@ static int adp5589_setup(struct adp5589_kpad *kpad)
>  		dev_warn(&client->dev, "Conflicting pull resistor config\n");
> 
>  	for (i = 0; i <= kpad->var->max_row_num; i++) {
> -		unsigned val = 0, bit = (1 << i);
> +		unsigned val = 0, bit = BIT(i);
>  		if (pdata->pullup_en_300k & bit)
>  			val = 0;
>  		else if (pdata->pulldown_en_300k & bit) @@ -697,7 +698,7 @@
> static int adp5589_setup(struct adp5589_kpad *kpad)
>  	}
> 
>  	for (i = 0; i <= kpad->var->max_col_num; i++) {
> -		unsigned val = 0, bit = 1 << (i + kpad->var->col_shift);
> +		unsigned val = 0, bit = BIT(i + kpad->var->col_shift);
>  		if (pdata->pullup_en_300k & bit)
>  			val = 0;
>  		else if (pdata->pulldown_en_300k & bit) @@ -813,7 +814,7 @@
> static void adp5589_report_switch_state(struct adp5589_kpad *kpad)
> 
>  		input_report_switch(kpad->input,
>  				    kpad->gpimap[i].sw_evt,
> -				    !(gpi_stat_tmp & (1 << pin_loc)));
> +				    !(gpi_stat_tmp & BIT(pin_loc)));
>  	}
> 
>  	input_sync(kpad->input);
> @@ -859,7 +860,7 @@ static int adp5589_keypad_add(struct adp5589_kpad
> *kpad, unsigned int revid)
>  			return -EINVAL;
>  		}
> 
> -		if ((1 << (pin - kpad->var->gpi_pin_row_base)) &
> +		if (BIT(pin - kpad->var->gpi_pin_row_base) &
>  				pdata->keypad_en_mask) {
>  			dev_err(&client->dev, "invalid gpi row/col data\n");
>  			return -EINVAL;
> --
> 2.29.2.299.gdc1121823c-goog
> 
> 
> --
> Dmitry

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-11-19  8:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-19  7:24 [PATCH] Input: adp5589-keys - use BIT() Dmitry Torokhov
2020-11-19  7:34 ` Joe Perches
2020-11-19  7:44   ` Dmitry Torokhov
2020-11-19  8:28 ` Ardelean, Alexandru

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).