forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 748e4f3d702def1a4bff191e0cf93b6a05340f01
kernel/drivers/leds/leds-is31fl32xx.c
....@@ -1,12 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Driver for ISSI IS31FL32xx family of I2C LED controllers
34 *
45 * Copyright 2015 Allworx Corp.
5
- *
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License version 2 as
9
- * published by the Free Software Foundation.
106 *
117 * Datasheets:
128 * http://www.issi.com/US/product-analog-fxled-driver.shtml
....@@ -48,7 +44,7 @@
4844 const struct is31fl32xx_chipdef *cdef;
4945 struct i2c_client *client;
5046 unsigned int num_leds;
51
- struct is31fl32xx_led_data leds[0];
47
+ struct is31fl32xx_led_data leds[];
5248 };
5349
5450 /**
....@@ -328,12 +324,6 @@
328324 return 0;
329325 }
330326
331
-static inline size_t sizeof_is31fl32xx_priv(int num_leds)
332
-{
333
- return sizeof(struct is31fl32xx_priv) +
334
- (sizeof(struct is31fl32xx_led_data) * num_leds);
335
-}
336
-
337327 static int is31fl32xx_parse_child_dt(const struct device *dev,
338328 const struct device_node *child,
339329 struct is31fl32xx_led_data *led_data)
....@@ -341,9 +331,6 @@
341331 struct led_classdev *cdev = &led_data->cdev;
342332 int ret = 0;
343333 u32 reg;
344
-
345
- if (of_property_read_string(child, "label", &cdev->name))
346
- cdev->name = child->name;
347334
348335 ret = of_property_read_u32(child, "reg", &reg);
349336 if (ret || reg < 1 || reg > led_data->priv->cdef->channels) {
....@@ -353,9 +340,6 @@
353340 return -EINVAL;
354341 }
355342 led_data->channel = reg;
356
-
357
- of_property_read_string(child, "linux,default-trigger",
358
- &cdev->default_trigger);
359343
360344 cdev->brightness_set_blocking = is31fl32xx_brightness_set;
361345
....@@ -382,7 +366,8 @@
382366 struct device_node *child;
383367 int ret = 0;
384368
385
- for_each_child_of_node(dev->of_node, child) {
369
+ for_each_available_child_of_node(dev_of_node(dev), child) {
370
+ struct led_init_data init_data = {};
386371 struct is31fl32xx_led_data *led_data =
387372 &priv->leds[priv->num_leds];
388373 const struct is31fl32xx_led_data *other_led_data;
....@@ -398,17 +383,19 @@
398383 led_data->channel);
399384 if (other_led_data) {
400385 dev_err(dev,
401
- "%s and %s both attempting to use channel %d\n",
402
- led_data->cdev.name,
403
- other_led_data->cdev.name,
404
- led_data->channel);
386
+ "Node %pOF 'reg' conflicts with another LED\n",
387
+ child);
388
+ ret = -EINVAL;
405389 goto err;
406390 }
407391
408
- ret = devm_led_classdev_register(dev, &led_data->cdev);
392
+ init_data.fwnode = of_fwnode_handle(child);
393
+
394
+ ret = devm_led_classdev_register_ext(dev, &led_data->cdev,
395
+ &init_data);
409396 if (ret) {
410
- dev_err(dev, "failed to register PWM led for %s: %d\n",
411
- led_data->cdev.name, ret);
397
+ dev_err(dev, "Failed to register LED for %pOF: %d\n",
398
+ child, ret);
412399 goto err;
413400 }
414401
....@@ -438,23 +425,18 @@
438425 const struct i2c_device_id *id)
439426 {
440427 const struct is31fl32xx_chipdef *cdef;
441
- const struct of_device_id *of_dev_id;
442428 struct device *dev = &client->dev;
443429 struct is31fl32xx_priv *priv;
444430 int count;
445431 int ret = 0;
446432
447
- of_dev_id = of_match_device(of_is31fl32xx_match, dev);
448
- if (!of_dev_id)
449
- return -EINVAL;
433
+ cdef = device_get_match_data(dev);
450434
451
- cdef = of_dev_id->data;
452
-
453
- count = of_get_child_count(dev->of_node);
435
+ count = of_get_available_child_count(dev_of_node(dev));
454436 if (!count)
455437 return -EINVAL;
456438
457
- priv = devm_kzalloc(dev, sizeof_is31fl32xx_priv(count),
439
+ priv = devm_kzalloc(dev, struct_size(priv, leds, count),
458440 GFP_KERNEL);
459441 if (!priv)
460442 return -ENOMEM;