Skip to content

Commit 770f82c

Browse files
committed
Input: pxa27x-keypad - use BIT, GENMASK, FIELD_GET, etc
Instead of using explicit binary values for masks and shifts to do bit operations use appropriate macros. Link: https://lore.kernel.org/r/20250817215316.1872689-2-dmitry.torokhov@gmail.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 53e49cb commit 770f82c

1 file changed

Lines changed: 69 additions & 59 deletions

File tree

drivers/input/keyboard/pxa27x_keypad.c

Lines changed: 69 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
* on some suggestions by Nicolas Pitre <nico@fluxnic.net>.
1313
*/
1414

15-
15+
#include <linux/bits.h>
16+
#include <linux/bitfield.h>
1617
#include <linux/kernel.h>
1718
#include <linux/module.h>
1819
#include <linux/interrupt.h>
@@ -30,62 +31,71 @@
3031
/*
3132
* Keypad Controller registers
3233
*/
33-
#define KPC 0x0000 /* Keypad Control register */
34-
#define KPDK 0x0008 /* Keypad Direct Key register */
35-
#define KPREC 0x0010 /* Keypad Rotary Encoder register */
36-
#define KPMK 0x0018 /* Keypad Matrix Key register */
37-
#define KPAS 0x0020 /* Keypad Automatic Scan register */
34+
#define KPC 0x0000 /* Keypad Control register */
35+
#define KPDK 0x0008 /* Keypad Direct Key register */
36+
#define KPREC 0x0010 /* Keypad Rotary Encoder register */
37+
#define KPMK 0x0018 /* Keypad Matrix Key register */
38+
#define KPAS 0x0020 /* Keypad Automatic Scan register */
3839

3940
/* Keypad Automatic Scan Multiple Key Presser register 0-3 */
40-
#define KPASMKP0 0x0028
41-
#define KPASMKP1 0x0030
42-
#define KPASMKP2 0x0038
43-
#define KPASMKP3 0x0040
44-
#define KPKDI 0x0048
41+
#define KPASMKP0 0x0028
42+
#define KPASMKP1 0x0030
43+
#define KPASMKP2 0x0038
44+
#define KPASMKP3 0x0040
45+
#define KPKDI 0x0048
4546

4647
/* bit definitions */
47-
#define KPC_MKRN(n) ((((n) - 1) & 0x7) << 26) /* matrix key row number */
48-
#define KPC_MKCN(n) ((((n) - 1) & 0x7) << 23) /* matrix key column number */
49-
#define KPC_DKN(n) ((((n) - 1) & 0x7) << 6) /* direct key number */
50-
51-
#define KPC_AS (0x1 << 30) /* Automatic Scan bit */
52-
#define KPC_ASACT (0x1 << 29) /* Automatic Scan on Activity */
53-
#define KPC_MI (0x1 << 22) /* Matrix interrupt bit */
54-
#define KPC_IMKP (0x1 << 21) /* Ignore Multiple Key Press */
55-
56-
#define KPC_MS(n) (0x1 << (13 + (n))) /* Matrix scan line 'n' */
57-
#define KPC_MS_ALL (0xff << 13)
58-
59-
#define KPC_ME (0x1 << 12) /* Matrix Keypad Enable */
60-
#define KPC_MIE (0x1 << 11) /* Matrix Interrupt Enable */
61-
#define KPC_DK_DEB_SEL (0x1 << 9) /* Direct Keypad Debounce Select */
62-
#define KPC_DI (0x1 << 5) /* Direct key interrupt bit */
63-
#define KPC_RE_ZERO_DEB (0x1 << 4) /* Rotary Encoder Zero Debounce */
64-
#define KPC_REE1 (0x1 << 3) /* Rotary Encoder1 Enable */
65-
#define KPC_REE0 (0x1 << 2) /* Rotary Encoder0 Enable */
66-
#define KPC_DE (0x1 << 1) /* Direct Keypad Enable */
67-
#define KPC_DIE (0x1 << 0) /* Direct Keypad interrupt Enable */
68-
69-
#define KPDK_DKP (0x1 << 31)
70-
#define KPDK_DK(n) ((n) & 0xff)
71-
72-
#define KPREC_OF1 (0x1 << 31)
73-
#define kPREC_UF1 (0x1 << 30)
74-
#define KPREC_OF0 (0x1 << 15)
75-
#define KPREC_UF0 (0x1 << 14)
76-
77-
#define KPREC_RECOUNT0(n) ((n) & 0xff)
78-
#define KPREC_RECOUNT1(n) (((n) >> 16) & 0xff)
79-
80-
#define KPMK_MKP (0x1 << 31)
81-
#define KPAS_SO (0x1 << 31)
82-
#define KPASMKPx_SO (0x1 << 31)
83-
84-
#define KPAS_MUKP(n) (((n) >> 26) & 0x1f)
85-
#define KPAS_RP(n) (((n) >> 4) & 0xf)
86-
#define KPAS_CP(n) ((n) & 0xf)
87-
88-
#define KPASMKP_MKC_MASK (0xff)
48+
#define KPC_MKRN_MASK GENMASK(28, 26)
49+
#define KPC_MKCN_MASK GENMASK(25, 23)
50+
#define KPC_DKN_MASK GENMASK(8, 6)
51+
#define KPC_MKRN(n) FIELD_PREP(KPC_MKRN_MASK, (n) - 1)
52+
#define KPC_MKCN(n) FIELD_PREP(KPC_MKCN_MASK, (n) - 1)
53+
#define KPC_DKN(n) FIELD_PREP(KPC_DKN_MASK, (n) - 1)
54+
55+
#define KPC_AS BIT(30) /* Automatic Scan bit */
56+
#define KPC_ASACT BIT(29) /* Automatic Scan on Activity */
57+
#define KPC_MI BIT(22) /* Matrix interrupt bit */
58+
#define KPC_IMKP BIT(21) /* Ignore Multiple Key Press */
59+
60+
#define KPC_MS(n) BIT(13 + (n)) /* Matrix scan line 'n' */
61+
#define KPC_MS_ALL GENMASK(20, 13)
62+
63+
#define KPC_ME BIT(12) /* Matrix Keypad Enable */
64+
#define KPC_MIE BIT(11) /* Matrix Interrupt Enable */
65+
#define KPC_DK_DEB_SEL BIT(9) /* Direct Keypad Debounce Select */
66+
#define KPC_DI BIT(5) /* Direct key interrupt bit */
67+
#define KPC_RE_ZERO_DEB BIT(4) /* Rotary Encoder Zero Debounce */
68+
#define KPC_REE1 BIT(3) /* Rotary Encoder1 Enable */
69+
#define KPC_REE0 BIT(2) /* Rotary Encoder0 Enable */
70+
#define KPC_DE BIT(1) /* Direct Keypad Enable */
71+
#define KPC_DIE BIT(0) /* Direct Keypad interrupt Enable */
72+
73+
#define KPDK_DKP BIT(31)
74+
#define KPDK_DK_MASK GENMASK(7, 0)
75+
#define KPDK_DK(n) FIELD_GET(KPDK_DK_MASK, n)
76+
77+
#define KPREC_OF1 BIT(31)
78+
#define KPREC_UF1 BIT(30)
79+
#define KPREC_OF0 BIT(15)
80+
#define KPREC_UF0 BIT(14)
81+
82+
#define KPREC_RECOUNT0_MASK GENMASK(7, 0)
83+
#define KPREC_RECOUNT1_MASK GENMASK(23, 16)
84+
#define KPREC_RECOUNT0(n) FIELD_GET(KPREC_RECOUNT0_MASK, n)
85+
#define KPREC_RECOUNT1(n) FIELD_GET(KPREC_RECOUNT1_MASK, n)
86+
87+
#define KPMK_MKP BIT(31)
88+
#define KPAS_SO BIT(31)
89+
#define KPASMKPx_SO BIT(31)
90+
91+
#define KPAS_MUKP_MASK GENMASK(30, 26)
92+
#define KPAS_RP_MASK GENMASK(7, 4)
93+
#define KPAS_CP_MASK GENMASK(3, 0)
94+
#define KPAS_MUKP(n) FIELD_GET(KPAS_MUKP_MASK, n)
95+
#define KPAS_RP(n) FIELD_GET(KPAS_RP_MASK, n)
96+
#define KPAS_CP(n) FIELD_GET(KPAS_CP_MASK, n)
97+
98+
#define KPASMKP_MKC_MASK GENMASK(7, 0)
8999

90100
#define keypad_readl(off) __raw_readl(keypad->mmio_base + (off))
91101
#define keypad_writel(off, v) __raw_writel((v), keypad->mmio_base + (off))
@@ -429,7 +439,7 @@ static void pxa27x_keypad_scan_matrix(struct pxa27x_keypad *keypad)
429439
row >= pdata->matrix_key_rows)
430440
goto scan;
431441

432-
new_state[col] = (1 << row);
442+
new_state[col] = BIT(row);
433443
goto scan;
434444
}
435445

@@ -458,14 +468,14 @@ static void pxa27x_keypad_scan_matrix(struct pxa27x_keypad *keypad)
458468
continue;
459469

460470
for (row = 0; row < pdata->matrix_key_rows; row++) {
461-
if ((bits_changed & (1 << row)) == 0)
471+
if ((bits_changed & BIT(row)) == 0)
462472
continue;
463473

464474
code = MATRIX_SCAN_CODE(row, col, keypad->row_shift);
465475

466476
input_event(input_dev, EV_MSC, MSC_SCAN, code);
467477
input_report_key(input_dev, keypad->keycodes[code],
468-
new_state[col] & (1 << row));
478+
new_state[col] & BIT(row));
469479
}
470480
}
471481
input_sync(input_dev);
@@ -552,12 +562,12 @@ static void pxa27x_keypad_scan_direct(struct pxa27x_keypad *keypad)
552562
return;
553563

554564
for (i = 0; i < pdata->direct_key_num; i++) {
555-
if (bits_changed & (1 << i)) {
565+
if (bits_changed & BIT(i)) {
556566
int code = MAX_MATRIX_KEY_NUM + i;
557567

558568
input_event(input_dev, EV_MSC, MSC_SCAN, code);
559569
input_report_key(input_dev, keypad->keycodes[code],
560-
new_state & (1 << i));
570+
new_state & BIT(i));
561571
}
562572
}
563573
input_sync(input_dev);
@@ -627,7 +637,7 @@ static void pxa27x_keypad_config(struct pxa27x_keypad *keypad)
627637
if (pdata->direct_key_mask)
628638
keypad->direct_key_mask = pdata->direct_key_mask;
629639
else
630-
keypad->direct_key_mask = ((1 << direct_key_num) - 1) & ~mask;
640+
keypad->direct_key_mask = GENMASK(direct_key_num - 1, 0) & ~mask;
631641

632642
/* enable direct key */
633643
if (direct_key_num)

0 commit comments

Comments
 (0)