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

Input: samsung-keypad - use per-chip parameters

Instead of doing conditional logic based on the chip type, define
per-chip parameter structure, and reference it in the match data
(either of_device_id or platform_device_id).

Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20240819045813.2154642-8-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+37 -24
+37 -24
drivers/input/keyboard/samsung-keypad.c
··· 44 44 #define S5PV210_KEYIFSTSCLR_R_INT_OFFSET 16 45 45 46 46 /* SAMSUNG_KEYIFCOL */ 47 - #define SAMSUNG_KEYIFCOL_MASK (0xff << 0) 48 - #define S5PV210_KEYIFCOLEN_MASK (0xff << 8) 47 + #define SAMSUNG_KEYIFCOL_MASK 0xff 49 48 50 49 /* SAMSUNG_KEYIFROW */ 51 50 #define SAMSUNG_KEYIFROW_MASK (0xff << 0) ··· 53 54 /* SAMSUNG_KEYIFFC */ 54 55 #define SAMSUNG_KEYIFFC_MASK (0x3ff << 0) 55 56 56 - enum samsung_keypad_type { 57 - KEYPAD_TYPE_SAMSUNG, 58 - KEYPAD_TYPE_S5PV210, 57 + struct samsung_chip_info { 58 + unsigned int column_shift; 59 59 }; 60 60 61 61 struct samsung_keypad { 62 + const struct samsung_chip_info *chip; 62 63 struct input_dev *input_dev; 63 64 struct platform_device *pdev; 64 65 struct clk *clk; ··· 67 68 bool stopped; 68 69 bool wake_enabled; 69 70 int irq; 70 - enum samsung_keypad_type type; 71 71 unsigned int row_shift; 72 72 unsigned int rows; 73 73 unsigned int cols; ··· 81 83 unsigned int val; 82 84 83 85 for (col = 0; col < keypad->cols; col++) { 84 - if (keypad->type == KEYPAD_TYPE_S5PV210) { 85 - val = S5PV210_KEYIFCOLEN_MASK; 86 - val &= ~(1 << col) << 8; 87 - } else { 88 - val = SAMSUNG_KEYIFCOL_MASK; 89 - val &= ~(1 << col); 90 - } 86 + val = SAMSUNG_KEYIFCOL_MASK & ~(1 << col); 87 + val <<= keypad->chip->column_shift; 91 88 92 89 writel(val, keypad->base + SAMSUNG_KEYIFCOL); 93 90 mdelay(1); ··· 307 314 { 308 315 const struct samsung_keypad_platdata *pdata; 309 316 const struct matrix_keymap_data *keymap_data; 317 + const struct platform_device_id *id; 310 318 struct samsung_keypad *keypad; 311 319 struct resource *res; 312 320 struct input_dev *input_dev; ··· 372 378 keypad->stopped = true; 373 379 init_waitqueue_head(&keypad->wait); 374 380 375 - if (pdev->dev.of_node) 376 - keypad->type = of_device_is_compatible(pdev->dev.of_node, 377 - "samsung,s5pv210-keypad"); 378 - else 379 - keypad->type = platform_get_device_id(pdev)->driver_data; 381 + keypad->chip = device_get_match_data(&pdev->dev); 382 + if (!keypad->chip) { 383 + id = platform_get_device_id(pdev); 384 + if (id) 385 + keypad->chip = (const void *)id->driver_data; 386 + } 387 + 388 + if (!keypad->chip) { 389 + dev_err(&pdev->dev, "Unable to determine chip type"); 390 + return -EINVAL; 391 + } 380 392 381 393 input_dev->name = pdev->name; 382 394 input_dev->id.bustype = BUS_HOST; ··· 542 542 samsung_keypad_runtime_resume, NULL) 543 543 }; 544 544 545 + static const struct samsung_chip_info samsung_s3c6410_chip_info = { 546 + .column_shift = 0, 547 + }; 548 + 549 + static const struct samsung_chip_info samsung_s5pv210_chip_info = { 550 + .column_shift = 8, 551 + }; 552 + 545 553 #ifdef CONFIG_OF 546 554 static const struct of_device_id samsung_keypad_dt_match[] = { 547 - { .compatible = "samsung,s3c6410-keypad" }, 548 - { .compatible = "samsung,s5pv210-keypad" }, 549 - {}, 555 + { 556 + .compatible = "samsung,s3c6410-keypad", 557 + .data = &samsung_s3c6410_chip_info, 558 + }, { 559 + .compatible = "samsung,s5pv210-keypad", 560 + .data = &samsung_s5pv210_chip_info, 561 + }, 562 + { } 550 563 }; 551 564 MODULE_DEVICE_TABLE(of, samsung_keypad_dt_match); 552 565 #endif ··· 567 554 static const struct platform_device_id samsung_keypad_driver_ids[] = { 568 555 { 569 556 .name = "samsung-keypad", 570 - .driver_data = KEYPAD_TYPE_SAMSUNG, 557 + .driver_data = (kernel_ulong_t)&samsung_s3c6410_chip_info, 571 558 }, { 572 559 .name = "s5pv210-keypad", 573 - .driver_data = KEYPAD_TYPE_S5PV210, 560 + .driver_data = (kernel_ulong_t)&samsung_s5pv210_chip_info, 574 561 }, 575 - { }, 562 + { } 576 563 }; 577 564 MODULE_DEVICE_TABLE(platform, samsung_keypad_driver_ids); 578 565