summaryrefslogtreecommitdiffstats
path: root/drivers/leds/leds-lp5562.c
diff options
context:
space:
mode:
authorChristian Marangi <ansuelsmth@gmail.com>2024-06-26 18:00:09 +0200
committerLee Jones <lee@kernel.org>2024-06-26 18:08:30 +0200
commitdb30c2891bfc74acb8823edee5f39cbc36bd9a4d (patch)
treedc5c978901b4d70f55f2703ca574ba4ea159dc06 /drivers/leds/leds-lp5562.c
parentleds: leds-lp55xx: Generalize stop_all_engine OP (diff)
downloadlinux-db30c2891bfc74acb8823edee5f39cbc36bd9a4d.tar.xz
linux-db30c2891bfc74acb8823edee5f39cbc36bd9a4d.zip
leds: leds-lp55xx: Generalize probe/remove functions
Now that stop_all_engine is generalized, probe and remove function are the same across every lp55xx based LED driver and can be generalized. To permit to use a common probe, make use of the OF match_data and i2c driver_data value to store the device_config struct specific for the LED. Also drop the now unused exported symbol in lp55xx-common and make them static. Update any lp55xx based LED driver to use the new generic probe/remove. Suggested-by: Lee Jones <lee@kernel.org> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com> Link: https://lore.kernel.org/r/20240626160027.19703-5-ansuelsmth@gmail.com Signed-off-by: Lee Jones <lee@kernel.org>
Diffstat (limited to 'drivers/leds/leds-lp5562.c')
-rw-r--r--drivers/leds/leds-lp5562.c80
1 files changed, 4 insertions, 76 deletions
diff --git a/drivers/leds/leds-lp5562.c b/drivers/leds/leds-lp5562.c
index 123abfc7b6c4..65a6a05c3848 100644
--- a/drivers/leds/leds-lp5562.c
+++ b/drivers/leds/leds-lp5562.c
@@ -508,86 +508,14 @@ static struct lp55xx_device_config lp5562_cfg = {
.dev_attr_group = &lp5562_group,
};
-static int lp5562_probe(struct i2c_client *client)
-{
- int ret;
- struct lp55xx_chip *chip;
- struct lp55xx_led *led;
- struct lp55xx_platform_data *pdata = dev_get_platdata(&client->dev);
- struct device_node *np = dev_of_node(&client->dev);
-
- chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
- if (!chip)
- return -ENOMEM;
-
- chip->cfg = &lp5562_cfg;
-
- if (!pdata) {
- if (np) {
- pdata = lp55xx_of_populate_pdata(&client->dev, np,
- chip);
- if (IS_ERR(pdata))
- return PTR_ERR(pdata);
- } else {
- dev_err(&client->dev, "no platform data\n");
- return -EINVAL;
- }
- }
-
-
- led = devm_kcalloc(&client->dev,
- pdata->num_channels, sizeof(*led), GFP_KERNEL);
- if (!led)
- return -ENOMEM;
-
- chip->cl = client;
- chip->pdata = pdata;
-
- mutex_init(&chip->lock);
-
- i2c_set_clientdata(client, led);
-
- ret = lp55xx_init_device(chip);
- if (ret)
- goto err_init;
-
- ret = lp55xx_register_leds(led, chip);
- if (ret)
- goto err_out;
-
- ret = lp55xx_register_sysfs(chip);
- if (ret) {
- dev_err(&client->dev, "registering sysfs failed\n");
- goto err_out;
- }
-
- return 0;
-
-err_out:
- lp55xx_deinit_device(chip);
-err_init:
- return ret;
-}
-
-static void lp5562_remove(struct i2c_client *client)
-{
- struct lp55xx_led *led = i2c_get_clientdata(client);
- struct lp55xx_chip *chip = led->chip;
-
- lp55xx_stop_all_engine(chip);
-
- lp55xx_unregister_sysfs(chip);
- lp55xx_deinit_device(chip);
-}
-
static const struct i2c_device_id lp5562_id[] = {
- { "lp5562" },
+ { "lp5562", .driver_data = (kernel_ulong_t)&lp5562_cfg, },
{ }
};
MODULE_DEVICE_TABLE(i2c, lp5562_id);
static const struct of_device_id of_lp5562_leds_match[] = {
- { .compatible = "ti,lp5562", },
+ { .compatible = "ti,lp5562", .data = &lp5562_cfg, },
{},
};
@@ -598,8 +526,8 @@ static struct i2c_driver lp5562_driver = {
.name = "lp5562",
.of_match_table = of_lp5562_leds_match,
},
- .probe = lp5562_probe,
- .remove = lp5562_remove,
+ .probe = lp55xx_probe,
+ .remove = lp55xx_remove,
.id_table = lp5562_id,
};