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

Configure Feed

Select the types of activity you want to include in your feed.

Input: cap11xx - stop using chip ID when configuring it

struct cap11xx_hw_model is supposed to describe the chip capabilities,
however later code changes introduced checks against chip ID.

Introduce new capabilities in cap11xx_hw_model and use them when applying
chip configuration, and remove the enum for chip ID. While at it, rename
no_gain to has_gain to match the rest of the new capabilities.

Reviewed-by: Jiri Valek - 2N <jiriv@axis.com>
Link: https://lore.kernel.org/r/ZXlCRsnOu_L8xeTC@google.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+70 -55
+70 -55
drivers/input/keyboard/cap11xx.c
··· 86 86 struct device *dev; 87 87 struct input_dev *idev; 88 88 const struct cap11xx_hw_model *model; 89 - u8 id; 90 89 91 90 struct cap11xx_led *leds; 92 91 int num_leds; ··· 103 104 u8 product_id; 104 105 unsigned int num_channels; 105 106 unsigned int num_leds; 106 - bool no_gain; 107 - }; 108 - 109 - enum { 110 - CAP1106, 111 - CAP1126, 112 - CAP1188, 113 - CAP1203, 114 - CAP1206, 115 - CAP1293, 116 - CAP1298 117 - }; 118 - 119 - static const struct cap11xx_hw_model cap11xx_devices[] = { 120 - [CAP1106] = { .product_id = 0x55, .num_channels = 6, .num_leds = 0, .no_gain = false }, 121 - [CAP1126] = { .product_id = 0x53, .num_channels = 6, .num_leds = 2, .no_gain = false }, 122 - [CAP1188] = { .product_id = 0x50, .num_channels = 8, .num_leds = 8, .no_gain = false }, 123 - [CAP1203] = { .product_id = 0x6d, .num_channels = 3, .num_leds = 0, .no_gain = true }, 124 - [CAP1206] = { .product_id = 0x67, .num_channels = 6, .num_leds = 0, .no_gain = true }, 125 - [CAP1293] = { .product_id = 0x6f, .num_channels = 3, .num_leds = 0, .no_gain = false }, 126 - [CAP1298] = { .product_id = 0x71, .num_channels = 8, .num_leds = 0, .no_gain = false }, 107 + bool has_gain; 108 + bool has_irq_config; 109 + bool has_sensitivity_control; 110 + bool has_signal_guard; 127 111 }; 128 112 129 113 static const struct reg_default cap11xx_reg_defaults[] = { ··· 206 224 } 207 225 208 226 if (!of_property_read_u32(node, "microchip,sensor-gain", &u32_val)) { 209 - if (priv->model->no_gain) { 227 + if (!priv->model->has_gain) { 210 228 dev_warn(dev, 211 229 "This model doesn't support 'sensor-gain'\n"); 212 230 } else if (is_power_of_2(u32_val) && u32_val <= 8) { ··· 225 243 } 226 244 227 245 if (of_property_read_bool(node, "microchip,irq-active-high")) { 228 - if (priv->id == CAP1106 || 229 - priv->id == CAP1126 || 230 - priv->id == CAP1188) { 246 + if (priv->model->has_irq_config) { 231 247 error = regmap_update_bits(priv->regmap, 232 248 CAP11XX_REG_CONFIG2, 233 249 CAP11XX_REG_CONFIG2_ALT_POL, ··· 276 296 if (!of_property_read_u32_array(node, "microchip,calib-sensitivity", 277 297 priv->calib_sensitivities, 278 298 priv->model->num_channels)) { 279 - if (priv->id == CAP1293 || priv->id == CAP1298) { 299 + if (priv->model->has_sensitivity_control) { 280 300 for (i = 0; i < priv->model->num_channels; i++) { 281 301 if (!is_power_of_2(priv->calib_sensitivities[i]) || 282 302 priv->calib_sensitivities[i] > 4) { ··· 291 311 if (error) 292 312 return error; 293 313 294 - if (priv->id == CAP1298) { 314 + if (priv->model->num_channels > 4) { 295 315 error = cap11xx_write_calib_sens_config_2(priv); 296 316 if (error) 297 317 return error; ··· 313 333 } 314 334 315 335 if (priv->signal_guard_inputs_mask) { 316 - if (priv->id == CAP1293 || priv->id == CAP1298) { 336 + if (priv->model->has_signal_guard) { 317 337 error = regmap_write(priv->regmap, 318 338 CAP11XX_REG_SIGNAL_GUARD_ENABLE, 319 339 priv->signal_guard_inputs_mask); ··· 488 508 489 509 static int cap11xx_i2c_probe(struct i2c_client *i2c_client) 490 510 { 491 - const struct i2c_device_id *id = i2c_client_get_device_id(i2c_client); 511 + const struct i2c_device_id *id; 512 + const struct cap11xx_hw_model *cap; 492 513 struct device *dev = &i2c_client->dev; 493 514 struct cap11xx_priv *priv; 494 - const struct cap11xx_hw_model *cap; 495 515 int i, error; 496 516 unsigned int val, rev; 497 517 498 - if (id->driver_data >= ARRAY_SIZE(cap11xx_devices)) { 499 - dev_err(dev, "Invalid device ID %lu\n", id->driver_data); 500 - return -EINVAL; 501 - } 502 - 503 - cap = &cap11xx_devices[id->driver_data]; 504 - if (!cap || !cap->num_channels) { 518 + id = i2c_client_get_device_id(i2c_client); 519 + cap = i2c_get_match_data(i2c_client); 520 + if (!id || !cap || !cap->num_channels) { 505 521 dev_err(dev, "Invalid device configuration\n"); 506 522 return -EINVAL; 507 523 } ··· 542 566 id->name, rev); 543 567 544 568 priv->model = cap; 545 - priv->id = id->driver_data; 546 569 547 570 dev_info(dev, "CAP11XX device detected, model %s, revision 0x%02x\n", 548 571 id->name, rev); ··· 602 627 return 0; 603 628 } 604 629 630 + static const struct cap11xx_hw_model cap1106_model = { 631 + .product_id = 0x55, .num_channels = 6, .num_leds = 0, 632 + .has_gain = true, 633 + .has_irq_config = true, 634 + }; 635 + 636 + static const struct cap11xx_hw_model cap1126_model = { 637 + .product_id = 0x53, .num_channels = 6, .num_leds = 2, 638 + .has_gain = true, 639 + .has_irq_config = true, 640 + }; 641 + 642 + static const struct cap11xx_hw_model cap1188_model = { 643 + .product_id = 0x50, .num_channels = 8, .num_leds = 8, 644 + .has_gain = true, 645 + .has_irq_config = true, 646 + }; 647 + 648 + static const struct cap11xx_hw_model cap1203_model = { 649 + .product_id = 0x6d, .num_channels = 3, .num_leds = 0, 650 + }; 651 + 652 + static const struct cap11xx_hw_model cap1206_model = { 653 + .product_id = 0x67, .num_channels = 6, .num_leds = 0, 654 + }; 655 + 656 + static const struct cap11xx_hw_model cap1293_model = { 657 + .product_id = 0x6f, .num_channels = 3, .num_leds = 0, 658 + .has_gain = true, 659 + .has_sensitivity_control = true, 660 + .has_signal_guard = true, 661 + }; 662 + 663 + static const struct cap11xx_hw_model cap1298_model = { 664 + .product_id = 0x71, .num_channels = 8, .num_leds = 0, 665 + .has_gain = true, 666 + .has_sensitivity_control = true, 667 + .has_signal_guard = true, 668 + }; 669 + 605 670 static const struct of_device_id cap11xx_dt_ids[] = { 606 - { .compatible = "microchip,cap1106", }, 607 - { .compatible = "microchip,cap1126", }, 608 - { .compatible = "microchip,cap1188", }, 609 - { .compatible = "microchip,cap1203", }, 610 - { .compatible = "microchip,cap1206", }, 611 - { .compatible = "microchip,cap1293", }, 612 - { .compatible = "microchip,cap1298", }, 613 - {} 671 + { .compatible = "microchip,cap1106", .data = &cap1106_model }, 672 + { .compatible = "microchip,cap1126", .data = &cap1126_model }, 673 + { .compatible = "microchip,cap1188", .data = &cap1188_model }, 674 + { .compatible = "microchip,cap1203", .data = &cap1203_model }, 675 + { .compatible = "microchip,cap1206", .data = &cap1206_model }, 676 + { .compatible = "microchip,cap1293", .data = &cap1293_model }, 677 + { .compatible = "microchip,cap1298", .data = &cap1298_model }, 678 + { } 614 679 }; 615 680 MODULE_DEVICE_TABLE(of, cap11xx_dt_ids); 616 681 617 682 static const struct i2c_device_id cap11xx_i2c_ids[] = { 618 - { "cap1106", CAP1106 }, 619 - { "cap1126", CAP1126 }, 620 - { "cap1188", CAP1188 }, 621 - { "cap1203", CAP1203 }, 622 - { "cap1206", CAP1206 }, 623 - { "cap1293", CAP1293 }, 624 - { "cap1298", CAP1298 }, 625 - {} 683 + { "cap1106", (kernel_ulong_t)&cap1106_model }, 684 + { "cap1126", (kernel_ulong_t)&cap1126_model }, 685 + { "cap1188", (kernel_ulong_t)&cap1188_model }, 686 + { "cap1203", (kernel_ulong_t)&cap1203_model }, 687 + { "cap1206", (kernel_ulong_t)&cap1206_model }, 688 + { "cap1293", (kernel_ulong_t)&cap1293_model }, 689 + { "cap1298", (kernel_ulong_t)&cap1298_model }, 690 + { } 626 691 }; 627 692 MODULE_DEVICE_TABLE(i2c, cap11xx_i2c_ids); 628 693