Skip to content

Commit 3b581cb

Browse files
bijudaslag-linaro
authored andcommitted
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 <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent a337ee0 commit 3b581cb

File tree

1 file changed

+18
-31
lines changed

1 file changed

+18
-31
lines changed

drivers/leds/leds-pca955x.c

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct pca955x_chipdef {
7676
int slv_addr_shift; /* Number of bits to ignore */
7777
};
7878

79-
static struct pca955x_chipdef pca955x_chipdefs[] = {
79+
static const struct pca955x_chipdef pca955x_chipdefs[] = {
8080
[pca9550] = {
8181
.bits = 2,
8282
.slv_addr = /* 110000x */ 0x60,
@@ -105,19 +105,19 @@ static struct pca955x_chipdef pca955x_chipdefs[] = {
105105
};
106106

107107
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] },
113113
{ }
114114
};
115115
MODULE_DEVICE_TABLE(i2c, pca955x_id);
116116

117117
struct pca955x {
118118
struct mutex lock;
119119
struct pca955x_led *leds;
120-
struct pca955x_chipdef *chipdef;
120+
const struct pca955x_chipdef *chipdef;
121121
struct i2c_client *client;
122122
unsigned long active_pins;
123123
#ifdef CONFIG_LEDS_PCA955X_GPIO
@@ -415,7 +415,7 @@ static int pca955x_gpio_direction_output(struct gpio_chip *gc,
415415
#endif /* CONFIG_LEDS_PCA955X_GPIO */
416416

417417
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)
419419
{
420420
struct pca955x_platform_data *pdata;
421421
struct pca955x_led *led;
@@ -458,11 +458,11 @@ pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
458458
}
459459

460460
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] },
466466
{},
467467
};
468468
MODULE_DEVICE_TABLE(of, of_pca955x_match);
@@ -471,7 +471,7 @@ static int pca955x_probe(struct i2c_client *client)
471471
{
472472
struct pca955x *pca955x;
473473
struct pca955x_led *pca955x_led;
474-
struct pca955x_chipdef *chip;
474+
const struct pca955x_chipdef *chip;
475475
struct led_classdev *led;
476476
struct led_init_data init_data;
477477
struct i2c_adapter *adapter;
@@ -480,24 +480,11 @@ static int pca955x_probe(struct i2c_client *client)
480480
bool set_default_label = false;
481481
bool keep_pwm = false;
482482
char default_label[8];
483-
enum pca955x_type chip_type;
484-
const void *md = device_get_match_data(&client->dev);
485-
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);
491-
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-
}
499483

500-
chip = &pca955x_chipdefs[chip_type];
484+
chip = i2c_get_match_data(client);
485+
if (!chip)
486+
return dev_err_probe(&client->dev, -ENODEV, "unknown chip\n");
487+
501488
adapter = client->adapter;
502489
pdata = dev_get_platdata(&client->dev);
503490
if (!pdata) {

0 commit comments

Comments
 (0)