hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/leds/leds-lp5521.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * LP5521 LED chip driver.
34 *
....@@ -6,20 +7,6 @@
67 *
78 * Contact: Samu Onkalo <samu.p.onkalo@nokia.com>
89 * Milo(Woogyom) Kim <milo.kim@ti.com>
9
- *
10
- * This program is free software; you can redistribute it and/or
11
- * modify it under the terms of the GNU General Public License
12
- * version 2 as published by the Free Software Foundation.
13
- *
14
- * This program is distributed in the hope that it will be useful, but
15
- * WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
- * General Public License for more details.
18
- *
19
- * You should have received a copy of the GNU General Public License
20
- * along with this program; if not, write to the Free Software
21
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22
- * 02110-1301 USA
2310 */
2411
2512 #include <linux/delay.h>
....@@ -362,6 +349,25 @@
362349 return 0;
363350 }
364351
352
+static int lp5521_multicolor_brightness(struct lp55xx_led *led)
353
+{
354
+ struct lp55xx_chip *chip = led->chip;
355
+ int ret;
356
+ int i;
357
+
358
+ mutex_lock(&chip->lock);
359
+ for (i = 0; i < led->mc_cdev.num_colors; i++) {
360
+ ret = lp55xx_write(chip,
361
+ LP5521_REG_LED_PWM_BASE +
362
+ led->mc_cdev.subled_info[i].channel,
363
+ led->mc_cdev.subled_info[i].brightness);
364
+ if (ret)
365
+ break;
366
+ }
367
+ mutex_unlock(&chip->lock);
368
+ return ret;
369
+}
370
+
365371 static int lp5521_led_brightness(struct lp55xx_led *led)
366372 {
367373 struct lp55xx_chip *chip = led->chip;
....@@ -503,6 +509,7 @@
503509 .max_channel = LP5521_MAX_LEDS,
504510 .post_init_device = lp5521_post_init_device,
505511 .brightness_fn = lp5521_led_brightness,
512
+ .multicolor_brightness_fn = lp5521_multicolor_brightness,
506513 .set_led_current = lp5521_set_led_current,
507514 .firmware_cb = lp5521_firmware_loaded,
508515 .run_engine = lp5521_run_engine,
....@@ -516,11 +523,18 @@
516523 struct lp55xx_chip *chip;
517524 struct lp55xx_led *led;
518525 struct lp55xx_platform_data *pdata = dev_get_platdata(&client->dev);
519
- struct device_node *np = client->dev.of_node;
526
+ struct device_node *np = dev_of_node(&client->dev);
527
+
528
+ chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
529
+ if (!chip)
530
+ return -ENOMEM;
531
+
532
+ chip->cfg = &lp5521_cfg;
520533
521534 if (!pdata) {
522535 if (np) {
523
- pdata = lp55xx_of_populate_pdata(&client->dev, np);
536
+ pdata = lp55xx_of_populate_pdata(&client->dev, np,
537
+ chip);
524538 if (IS_ERR(pdata))
525539 return PTR_ERR(pdata);
526540 } else {
....@@ -529,10 +543,6 @@
529543 }
530544 }
531545
532
- chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
533
- if (!chip)
534
- return -ENOMEM;
535
-
536546 led = devm_kcalloc(&client->dev,
537547 pdata->num_channels, sizeof(*led), GFP_KERNEL);
538548 if (!led)
....@@ -540,7 +550,6 @@
540550
541551 chip->cl = client;
542552 chip->pdata = pdata;
543
- chip->cfg = &lp5521_cfg;
544553
545554 mutex_init(&chip->lock);
546555
....@@ -554,19 +563,17 @@
554563
555564 ret = lp55xx_register_leds(led, chip);
556565 if (ret)
557
- goto err_register_leds;
566
+ goto err_out;
558567
559568 ret = lp55xx_register_sysfs(chip);
560569 if (ret) {
561570 dev_err(&client->dev, "registering sysfs failed\n");
562
- goto err_register_sysfs;
571
+ goto err_out;
563572 }
564573
565574 return 0;
566575
567
-err_register_sysfs:
568
- lp55xx_unregister_leds(led, chip);
569
-err_register_leds:
576
+err_out:
570577 lp55xx_deinit_device(chip);
571578 err_init:
572579 return ret;
....@@ -579,7 +586,6 @@
579586
580587 lp5521_stop_all_engines(chip);
581588 lp55xx_unregister_sysfs(chip);
582
- lp55xx_unregister_leds(led, chip);
583589 lp55xx_deinit_device(chip);
584590
585591 return 0;