hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/leds/leds-lm3601x.c
....@@ -1,7 +1,7 @@
11 // SPDX-License-Identifier: GPL-2.0
22 // Flash and torch driver for Texas Instruments LM3601X LED
33 // Flash driver chip family
4
-// Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
4
+// Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com/
55
66 #include <linux/delay.h>
77 #include <linux/i2c.h>
....@@ -10,7 +10,6 @@
1010 #include <linux/module.h>
1111 #include <linux/regmap.h>
1212 #include <linux/slab.h>
13
-#include <uapi/linux/uleds.h>
1413
1514 #define LM3601X_LED_IR 0x0
1615 #define LM3601X_LED_TORCH 0x1
....@@ -89,8 +88,6 @@
8988 struct i2c_client *client;
9089 struct regmap *regmap;
9190 struct mutex lock;
92
-
93
- char led_name[LED_MAX_NAME_SIZE];
9491
9592 unsigned int flash_timeout;
9693 unsigned int last_flag;
....@@ -322,10 +319,12 @@
322319 .fault_get = lm3601x_flash_fault_get,
323320 };
324321
325
-static int lm3601x_register_leds(struct lm3601x_led *led)
322
+static int lm3601x_register_leds(struct lm3601x_led *led,
323
+ struct fwnode_handle *fwnode)
326324 {
327325 struct led_classdev *led_cdev;
328326 struct led_flash_setting *setting;
327
+ struct led_init_data init_data = {};
329328
330329 led->fled_cdev.ops = &flash_ops;
331330
....@@ -342,20 +341,24 @@
342341 setting->val = led->flash_current_max;
343342
344343 led_cdev = &led->fled_cdev.led_cdev;
345
- led_cdev->name = led->led_name;
346344 led_cdev->brightness_set_blocking = lm3601x_brightness_set;
347345 led_cdev->max_brightness = DIV_ROUND_UP(led->torch_current_max,
348346 LM3601X_TORCH_REG_DIV);
349347 led_cdev->flags |= LED_DEV_CAP_FLASH;
350348
351
- return led_classdev_flash_register(&led->client->dev, &led->fled_cdev);
349
+ init_data.fwnode = fwnode;
350
+ init_data.devicename = led->client->name;
351
+ init_data.default_label = (led->led_mode == LM3601X_LED_TORCH) ?
352
+ "torch" : "infrared";
353
+ return devm_led_classdev_flash_register_ext(&led->client->dev,
354
+ &led->fled_cdev, &init_data);
352355 }
353356
354
-static int lm3601x_parse_node(struct lm3601x_led *led)
357
+static int lm3601x_parse_node(struct lm3601x_led *led,
358
+ struct fwnode_handle **fwnode)
355359 {
356360 struct fwnode_handle *child = NULL;
357361 int ret = -ENODEV;
358
- const char *name;
359362
360363 child = device_get_next_child_node(&led->client->dev, child);
361364 if (!child) {
....@@ -375,17 +378,6 @@
375378 ret = -EINVAL;
376379 goto out_err;
377380 }
378
-
379
- ret = fwnode_property_read_string(child, "label", &name);
380
- if (ret) {
381
- if (led->led_mode == LM3601X_LED_TORCH)
382
- name = "torch";
383
- else
384
- name = "infrared";
385
- }
386
-
387
- snprintf(led->led_name, sizeof(led->led_name),
388
- "%s:%s", led->client->name, name);
389381
390382 ret = fwnode_property_read_u32(child, "led-max-microamp",
391383 &led->torch_current_max);
....@@ -411,6 +403,8 @@
411403 goto out_err;
412404 }
413405
406
+ *fwnode = child;
407
+
414408 out_err:
415409 fwnode_handle_put(child);
416410 return ret;
....@@ -419,6 +413,7 @@
419413 static int lm3601x_probe(struct i2c_client *client)
420414 {
421415 struct lm3601x_led *led;
416
+ struct fwnode_handle *fwnode;
422417 int ret;
423418
424419 led = devm_kzalloc(&client->dev, sizeof(*led), GFP_KERNEL);
....@@ -428,7 +423,7 @@
428423 led->client = client;
429424 i2c_set_clientdata(client, led);
430425
431
- ret = lm3601x_parse_node(led);
426
+ ret = lm3601x_parse_node(led, &fwnode);
432427 if (ret)
433428 return -ENODEV;
434429
....@@ -442,15 +437,12 @@
442437
443438 mutex_init(&led->lock);
444439
445
- return lm3601x_register_leds(led);
440
+ return lm3601x_register_leds(led, fwnode);
446441 }
447442
448443 static int lm3601x_remove(struct i2c_client *client)
449444 {
450445 struct lm3601x_led *led = i2c_get_clientdata(client);
451
-
452
- led_classdev_flash_unregister(&led->fled_cdev);
453
- mutex_destroy(&led->lock);
454446
455447 return regmap_update_bits(led->regmap, LM3601X_ENABLE_REG,
456448 LM3601X_ENABLE_MASK,