summaryrefslogtreecommitdiff
path: root/drivers/leds
diff options
context:
space:
mode:
authorBiju Das <biju.das.jz@bp.renesas.com>2023-09-23 20:19:20 +0300
committerLee Jones <lee@kernel.org>2023-11-01 14:28:54 +0300
commit3b581cb58816d07b033c800d42a040d7ba566fb6 (patch)
tree5e56ef83dd1d215d3618d667e92b2ece3f2f366e /drivers/leds
parenta337ee0d25ba24212269c2442981dc4fb5232a8c (diff)
downloadlinux-3b581cb58816d07b033c800d42a040d7ba566fb6.tar.xz
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>
Diffstat (limited to 'drivers/leds')
-rw-r--r--drivers/leds/leds-pca955x.c49
1 files changed, 18 insertions, 31 deletions
diff --git a/drivers/leds/leds-pca955x.c b/drivers/leds/leds-pca955x.c
index 1d7fa0cd97bf..891cfc05301d 100644
--- a/drivers/leds/leds-pca955x.c
+++ b/drivers/leds/leds-pca955x.c
@@ -76,7 +76,7 @@ struct pca955x_chipdef {
int slv_addr_shift; /* Number of bits to ignore */
};
-static struct pca955x_chipdef pca955x_chipdefs[] = {
+static const struct pca955x_chipdef pca955x_chipdefs[] = {
[pca9550] = {
.bits = 2,
.slv_addr = /* 110000x */ 0x60,
@@ -105,11 +105,11 @@ static struct pca955x_chipdef pca955x_chipdefs[] = {
};
static const struct i2c_device_id pca955x_id[] = {
- { "pca9550", pca9550 },
- { "pca9551", pca9551 },
- { "pca9552", pca9552 },
- { "ibm-pca9552", ibm_pca9552 },
- { "pca9553", pca9553 },
+ { "pca9550", (kernel_ulong_t)&pca955x_chipdefs[pca9550] },
+ { "pca9551", (kernel_ulong_t)&pca955x_chipdefs[pca9551] },
+ { "pca9552", (kernel_ulong_t)&pca955x_chipdefs[pca9552] },
+ { "ibm-pca9552", (kernel_ulong_t)&pca955x_chipdefs[ibm_pca9552] },
+ { "pca9553", (kernel_ulong_t)&pca955x_chipdefs[pca9553] },
{ }
};
MODULE_DEVICE_TABLE(i2c, pca955x_id);
@@ -117,7 +117,7 @@ MODULE_DEVICE_TABLE(i2c, pca955x_id);
struct pca955x {
struct mutex lock;
struct pca955x_led *leds;
- struct pca955x_chipdef *chipdef;
+ const struct pca955x_chipdef *chipdef;
struct i2c_client *client;
unsigned long active_pins;
#ifdef CONFIG_LEDS_PCA955X_GPIO
@@ -415,7 +415,7 @@ static int pca955x_gpio_direction_output(struct gpio_chip *gc,
#endif /* CONFIG_LEDS_PCA955X_GPIO */
static struct pca955x_platform_data *
-pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
+pca955x_get_pdata(struct i2c_client *client, const struct pca955x_chipdef *chip)
{
struct pca955x_platform_data *pdata;
struct pca955x_led *led;
@@ -458,11 +458,11 @@ pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
}
static const struct of_device_id of_pca955x_match[] = {
- { .compatible = "nxp,pca9550", .data = (void *)pca9550 },
- { .compatible = "nxp,pca9551", .data = (void *)pca9551 },
- { .compatible = "nxp,pca9552", .data = (void *)pca9552 },
- { .compatible = "ibm,pca9552", .data = (void *)ibm_pca9552 },
- { .compatible = "nxp,pca9553", .data = (void *)pca9553 },
+ { .compatible = "nxp,pca9550", .data = &pca955x_chipdefs[pca9550] },
+ { .compatible = "nxp,pca9551", .data = &pca955x_chipdefs[pca9551] },
+ { .compatible = "nxp,pca9552", .data = &pca955x_chipdefs[pca9552] },
+ { .compatible = "ibm,pca9552", .data = &pca955x_chipdefs[ibm_pca9552] },
+ { .compatible = "nxp,pca9553", .data = &pca955x_chipdefs[pca9553] },
{},
};
MODULE_DEVICE_TABLE(of, of_pca955x_match);
@@ -471,7 +471,7 @@ static int pca955x_probe(struct i2c_client *client)
{
struct pca955x *pca955x;
struct pca955x_led *pca955x_led;
- struct pca955x_chipdef *chip;
+ const struct pca955x_chipdef *chip;
struct led_classdev *led;
struct led_init_data init_data;
struct i2c_adapter *adapter;
@@ -480,24 +480,11 @@ static int pca955x_probe(struct i2c_client *client)
bool set_default_label = false;
bool keep_pwm = false;
char default_label[8];
- enum pca955x_type chip_type;
- const void *md = device_get_match_data(&client->dev);
-
- if (md) {
- chip_type = (enum pca955x_type)(uintptr_t)md;
- } else {
- const struct i2c_device_id *id = i2c_match_id(pca955x_id,
- client);
-
- if (id) {
- chip_type = (enum pca955x_type)id->driver_data;
- } else {
- dev_err(&client->dev, "unknown chip\n");
- return -ENODEV;
- }
- }
- chip = &pca955x_chipdefs[chip_type];
+ chip = i2c_get_match_data(client);
+ if (!chip)
+ return dev_err_probe(&client->dev, -ENODEV, "unknown chip\n");
+
adapter = client->adapter;
pdata = dev_get_platdata(&client->dev);
if (!pdata) {