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

leds: pca955x: Convert enum->pointer for data in the match tables

Convert enum->pointer for data in the match tables, so that
device_get_match_data() can do match against OF/ACPI/I2C tables, once i2c
bus type match support added to it.

Replace enum->struct *pca955x_chipdefs for data in the match table.
Simplify the probe() by replacing device_get_match_data() and ID lookup
for retrieving data by i2c_get_match_data().

While at it, add const definition to pca955x_chipdefs[].

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20230923171921.53503-2-biju.das.jz@bp.renesas.com
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

Biju Das and committed by
Lee Jones
3b581cb5 a337ee0d

+17 -30
+17 -30
drivers/leds/leds-pca955x.c
··· 76 76 int slv_addr_shift; /* Number of bits to ignore */ 77 77 }; 78 78 79 - static struct pca955x_chipdef pca955x_chipdefs[] = { 79 + static const struct pca955x_chipdef pca955x_chipdefs[] = { 80 80 [pca9550] = { 81 81 .bits = 2, 82 82 .slv_addr = /* 110000x */ 0x60, ··· 105 105 }; 106 106 107 107 static const struct i2c_device_id pca955x_id[] = { 108 - { "pca9550", pca9550 }, 109 - { "pca9551", pca9551 }, 110 - { "pca9552", pca9552 }, 111 - { "ibm-pca9552", ibm_pca9552 }, 112 - { "pca9553", pca9553 }, 108 + { "pca9550", (kernel_ulong_t)&pca955x_chipdefs[pca9550] }, 109 + { "pca9551", (kernel_ulong_t)&pca955x_chipdefs[pca9551] }, 110 + { "pca9552", (kernel_ulong_t)&pca955x_chipdefs[pca9552] }, 111 + { "ibm-pca9552", (kernel_ulong_t)&pca955x_chipdefs[ibm_pca9552] }, 112 + { "pca9553", (kernel_ulong_t)&pca955x_chipdefs[pca9553] }, 113 113 { } 114 114 }; 115 115 MODULE_DEVICE_TABLE(i2c, pca955x_id); ··· 117 117 struct pca955x { 118 118 struct mutex lock; 119 119 struct pca955x_led *leds; 120 - struct pca955x_chipdef *chipdef; 120 + const struct pca955x_chipdef *chipdef; 121 121 struct i2c_client *client; 122 122 unsigned long active_pins; 123 123 #ifdef CONFIG_LEDS_PCA955X_GPIO ··· 415 415 #endif /* CONFIG_LEDS_PCA955X_GPIO */ 416 416 417 417 static struct pca955x_platform_data * 418 - pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip) 418 + pca955x_get_pdata(struct i2c_client *client, const struct pca955x_chipdef *chip) 419 419 { 420 420 struct pca955x_platform_data *pdata; 421 421 struct pca955x_led *led; ··· 458 458 } 459 459 460 460 static const struct of_device_id of_pca955x_match[] = { 461 - { .compatible = "nxp,pca9550", .data = (void *)pca9550 }, 462 - { .compatible = "nxp,pca9551", .data = (void *)pca9551 }, 463 - { .compatible = "nxp,pca9552", .data = (void *)pca9552 }, 464 - { .compatible = "ibm,pca9552", .data = (void *)ibm_pca9552 }, 465 - { .compatible = "nxp,pca9553", .data = (void *)pca9553 }, 461 + { .compatible = "nxp,pca9550", .data = &pca955x_chipdefs[pca9550] }, 462 + { .compatible = "nxp,pca9551", .data = &pca955x_chipdefs[pca9551] }, 463 + { .compatible = "nxp,pca9552", .data = &pca955x_chipdefs[pca9552] }, 464 + { .compatible = "ibm,pca9552", .data = &pca955x_chipdefs[ibm_pca9552] }, 465 + { .compatible = "nxp,pca9553", .data = &pca955x_chipdefs[pca9553] }, 466 466 {}, 467 467 }; 468 468 MODULE_DEVICE_TABLE(of, of_pca955x_match); ··· 471 471 { 472 472 struct pca955x *pca955x; 473 473 struct pca955x_led *pca955x_led; 474 - struct pca955x_chipdef *chip; 474 + const struct pca955x_chipdef *chip; 475 475 struct led_classdev *led; 476 476 struct led_init_data init_data; 477 477 struct i2c_adapter *adapter; ··· 480 480 bool set_default_label = false; 481 481 bool keep_pwm = false; 482 482 char default_label[8]; 483 - enum pca955x_type chip_type; 484 - const void *md = device_get_match_data(&client->dev); 485 483 486 - if (md) { 487 - chip_type = (enum pca955x_type)(uintptr_t)md; 488 - } else { 489 - const struct i2c_device_id *id = i2c_match_id(pca955x_id, 490 - client); 484 + chip = i2c_get_match_data(client); 485 + if (!chip) 486 + return dev_err_probe(&client->dev, -ENODEV, "unknown chip\n"); 491 487 492 - if (id) { 493 - chip_type = (enum pca955x_type)id->driver_data; 494 - } else { 495 - dev_err(&client->dev, "unknown chip\n"); 496 - return -ENODEV; 497 - } 498 - } 499 - 500 - chip = &pca955x_chipdefs[chip_type]; 501 488 adapter = client->adapter; 502 489 pdata = dev_get_platdata(&client->dev); 503 490 if (!pdata) {