Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+60 -50
+60 -50
drivers/input/keyboard/pxa27x_keypad.c
··· 12 12 * on some suggestions by Nicolas Pitre <nico@fluxnic.net>. 13 13 */ 14 14 15 - 15 + #include <linux/bits.h> 16 + #include <linux/bitfield.h> 16 17 #include <linux/kernel.h> 17 18 #include <linux/module.h> 18 19 #include <linux/interrupt.h> ··· 31 30 /* 32 31 * Keypad Controller registers 33 32 */ 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 */ 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 */ 39 38 40 39 /* Keypad Automatic Scan Multiple Key Presser register 0-3 */ 41 - #define KPASMKP0 0x0028 42 - #define KPASMKP1 0x0030 43 - #define KPASMKP2 0x0038 44 - #define KPASMKP3 0x0040 45 - #define KPKDI 0x0048 40 + #define KPASMKP0 0x0028 41 + #define KPASMKP1 0x0030 42 + #define KPASMKP2 0x0038 43 + #define KPASMKP3 0x0040 44 + #define KPKDI 0x0048 46 45 47 46 /* bit definitions */ 48 - #define KPC_MKRN(n) ((((n) - 1) & 0x7) << 26) /* matrix key row number */ 49 - #define KPC_MKCN(n) ((((n) - 1) & 0x7) << 23) /* matrix key column number */ 50 - #define KPC_DKN(n) ((((n) - 1) & 0x7) << 6) /* direct key number */ 47 + #define KPC_MKRN_MASK GENMASK(28, 26) 48 + #define KPC_MKCN_MASK GENMASK(25, 23) 49 + #define KPC_DKN_MASK GENMASK(8, 6) 50 + #define KPC_MKRN(n) FIELD_PREP(KPC_MKRN_MASK, (n) - 1) 51 + #define KPC_MKCN(n) FIELD_PREP(KPC_MKCN_MASK, (n) - 1) 52 + #define KPC_DKN(n) FIELD_PREP(KPC_DKN_MASK, (n) - 1) 51 53 52 - #define KPC_AS (0x1 << 30) /* Automatic Scan bit */ 53 - #define KPC_ASACT (0x1 << 29) /* Automatic Scan on Activity */ 54 - #define KPC_MI (0x1 << 22) /* Matrix interrupt bit */ 55 - #define KPC_IMKP (0x1 << 21) /* Ignore Multiple Key Press */ 54 + #define KPC_AS BIT(30) /* Automatic Scan bit */ 55 + #define KPC_ASACT BIT(29) /* Automatic Scan on Activity */ 56 + #define KPC_MI BIT(22) /* Matrix interrupt bit */ 57 + #define KPC_IMKP BIT(21) /* Ignore Multiple Key Press */ 56 58 57 - #define KPC_MS(n) (0x1 << (13 + (n))) /* Matrix scan line 'n' */ 58 - #define KPC_MS_ALL (0xff << 13) 59 + #define KPC_MS(n) BIT(13 + (n)) /* Matrix scan line 'n' */ 60 + #define KPC_MS_ALL GENMASK(20, 13) 59 61 60 - #define KPC_ME (0x1 << 12) /* Matrix Keypad Enable */ 61 - #define KPC_MIE (0x1 << 11) /* Matrix Interrupt Enable */ 62 - #define KPC_DK_DEB_SEL (0x1 << 9) /* Direct Keypad Debounce Select */ 63 - #define KPC_DI (0x1 << 5) /* Direct key interrupt bit */ 64 - #define KPC_RE_ZERO_DEB (0x1 << 4) /* Rotary Encoder Zero Debounce */ 65 - #define KPC_REE1 (0x1 << 3) /* Rotary Encoder1 Enable */ 66 - #define KPC_REE0 (0x1 << 2) /* Rotary Encoder0 Enable */ 67 - #define KPC_DE (0x1 << 1) /* Direct Keypad Enable */ 68 - #define KPC_DIE (0x1 << 0) /* Direct Keypad interrupt Enable */ 62 + #define KPC_ME BIT(12) /* Matrix Keypad Enable */ 63 + #define KPC_MIE BIT(11) /* Matrix Interrupt Enable */ 64 + #define KPC_DK_DEB_SEL BIT(9) /* Direct Keypad Debounce Select */ 65 + #define KPC_DI BIT(5) /* Direct key interrupt bit */ 66 + #define KPC_RE_ZERO_DEB BIT(4) /* Rotary Encoder Zero Debounce */ 67 + #define KPC_REE1 BIT(3) /* Rotary Encoder1 Enable */ 68 + #define KPC_REE0 BIT(2) /* Rotary Encoder0 Enable */ 69 + #define KPC_DE BIT(1) /* Direct Keypad Enable */ 70 + #define KPC_DIE BIT(0) /* Direct Keypad interrupt Enable */ 69 71 70 - #define KPDK_DKP (0x1 << 31) 71 - #define KPDK_DK(n) ((n) & 0xff) 72 + #define KPDK_DKP BIT(31) 73 + #define KPDK_DK_MASK GENMASK(7, 0) 74 + #define KPDK_DK(n) FIELD_GET(KPDK_DK_MASK, n) 72 75 73 - #define KPREC_OF1 (0x1 << 31) 74 - #define kPREC_UF1 (0x1 << 30) 75 - #define KPREC_OF0 (0x1 << 15) 76 - #define KPREC_UF0 (0x1 << 14) 76 + #define KPREC_OF1 BIT(31) 77 + #define KPREC_UF1 BIT(30) 78 + #define KPREC_OF0 BIT(15) 79 + #define KPREC_UF0 BIT(14) 77 80 78 - #define KPREC_RECOUNT0(n) ((n) & 0xff) 79 - #define KPREC_RECOUNT1(n) (((n) >> 16) & 0xff) 81 + #define KPREC_RECOUNT0_MASK GENMASK(7, 0) 82 + #define KPREC_RECOUNT1_MASK GENMASK(23, 16) 83 + #define KPREC_RECOUNT0(n) FIELD_GET(KPREC_RECOUNT0_MASK, n) 84 + #define KPREC_RECOUNT1(n) FIELD_GET(KPREC_RECOUNT1_MASK, n) 80 85 81 - #define KPMK_MKP (0x1 << 31) 82 - #define KPAS_SO (0x1 << 31) 83 - #define KPASMKPx_SO (0x1 << 31) 86 + #define KPMK_MKP BIT(31) 87 + #define KPAS_SO BIT(31) 88 + #define KPASMKPx_SO BIT(31) 84 89 85 - #define KPAS_MUKP(n) (((n) >> 26) & 0x1f) 86 - #define KPAS_RP(n) (((n) >> 4) & 0xf) 87 - #define KPAS_CP(n) ((n) & 0xf) 90 + #define KPAS_MUKP_MASK GENMASK(30, 26) 91 + #define KPAS_RP_MASK GENMASK(7, 4) 92 + #define KPAS_CP_MASK GENMASK(3, 0) 93 + #define KPAS_MUKP(n) FIELD_GET(KPAS_MUKP_MASK, n) 94 + #define KPAS_RP(n) FIELD_GET(KPAS_RP_MASK, n) 95 + #define KPAS_CP(n) FIELD_GET(KPAS_CP_MASK, n) 88 96 89 - #define KPASMKP_MKC_MASK (0xff) 97 + #define KPASMKP_MKC_MASK GENMASK(7, 0) 90 98 91 99 #define keypad_readl(off) __raw_readl(keypad->mmio_base + (off)) 92 100 #define keypad_writel(off, v) __raw_writel((v), keypad->mmio_base + (off)) ··· 439 429 row >= pdata->matrix_key_rows) 440 430 goto scan; 441 431 442 - new_state[col] = (1 << row); 432 + new_state[col] = BIT(row); 443 433 goto scan; 444 434 } 445 435 ··· 468 458 continue; 469 459 470 460 for (row = 0; row < pdata->matrix_key_rows; row++) { 471 - if ((bits_changed & (1 << row)) == 0) 461 + if ((bits_changed & BIT(row)) == 0) 472 462 continue; 473 463 474 464 code = MATRIX_SCAN_CODE(row, col, keypad->row_shift); 475 465 476 466 input_event(input_dev, EV_MSC, MSC_SCAN, code); 477 467 input_report_key(input_dev, keypad->keycodes[code], 478 - new_state[col] & (1 << row)); 468 + new_state[col] & BIT(row)); 479 469 } 480 470 } 481 471 input_sync(input_dev); ··· 562 552 return; 563 553 564 554 for (i = 0; i < pdata->direct_key_num; i++) { 565 - if (bits_changed & (1 << i)) { 555 + if (bits_changed & BIT(i)) { 566 556 int code = MAX_MATRIX_KEY_NUM + i; 567 557 568 558 input_event(input_dev, EV_MSC, MSC_SCAN, code); 569 559 input_report_key(input_dev, keypad->keycodes[code], 570 - new_state & (1 << i)); 560 + new_state & BIT(i)); 571 561 } 572 562 } 573 563 input_sync(input_dev); ··· 637 627 if (pdata->direct_key_mask) 638 628 keypad->direct_key_mask = pdata->direct_key_mask; 639 629 else 640 - keypad->direct_key_mask = ((1 << direct_key_num) - 1) & ~mask; 630 + keypad->direct_key_mask = GENMASK(direct_key_num - 1, 0) & ~mask; 641 631 642 632 /* enable direct key */ 643 633 if (direct_key_num)