hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/leds/leds-pca9532.c
....@@ -1,15 +1,11 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * pca9532.c - 16-bit Led dimmer
34 *
45 * Copyright (C) 2011 Jan Weitzel
56 * Copyright (C) 2008 Riku Voipio
67 *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation; version 2 of the License.
10
- *
118 * Datasheet: http://www.nxp.com/documents/data_sheet/PCA9532.pdf
12
- *
139 */
1410
1511 #include <linux/module.h>
....@@ -20,7 +16,7 @@
2016 #include <linux/mutex.h>
2117 #include <linux/workqueue.h>
2218 #include <linux/leds-pca9532.h>
23
-#include <linux/gpio.h>
19
+#include <linux/gpio/driver.h>
2420 #include <linux/of.h>
2521 #include <linux/of_device.h>
2622
....@@ -31,6 +27,8 @@
3127 #define PCA9532_REG_PWM(m, i) (PCA9532_REG_OFFSET(m) + 0x2 + (i) * 2)
3228 #define LED_REG(m, led) (PCA9532_REG_OFFSET(m) + 0x5 + (led >> 2))
3329 #define LED_NUM(led) (led & 0x3)
30
+#define LED_SHIFT(led) (LED_NUM(led) * 2)
31
+#define LED_MASK(led) (0x3 << LED_SHIFT(led))
3432
3533 #define ldev_to_led(c) container_of(c, struct pca9532_led, ldev)
3634
....@@ -166,9 +164,9 @@
166164 mutex_lock(&data->update_lock);
167165 reg = i2c_smbus_read_byte_data(client, LED_REG(maxleds, led->id));
168166 /* zero led bits */
169
- reg = reg & ~(0x3<<LED_NUM(led->id)*2);
167
+ reg = reg & ~LED_MASK(led->id);
170168 /* set the new value */
171
- reg = reg | (led->state << LED_NUM(led->id)*2);
169
+ reg = reg | (led->state << LED_SHIFT(led->id));
172170 i2c_smbus_write_byte_data(client, LED_REG(maxleds, led->id), reg);
173171 mutex_unlock(&data->update_lock);
174172 }
....@@ -264,7 +262,7 @@
264262
265263 mutex_lock(&data->update_lock);
266264 reg = i2c_smbus_read_byte_data(client, LED_REG(maxleds, led->id));
267
- ret = reg >> LED_NUM(led->id)/2;
265
+ ret = (reg & LED_MASK(led->id)) >> LED_SHIFT(led->id);
268266 mutex_unlock(&data->update_lock);
269267 return ret;
270268 }
....@@ -471,23 +469,23 @@
471469 {
472470 struct pca9532_platform_data *pdata;
473471 struct device_node *child;
474
- const struct of_device_id *match;
475472 int devid, maxleds;
476473 int i = 0;
477474 const char *state;
478475
479
- match = of_match_device(of_pca9532_leds_match, dev);
480
- if (!match)
481
- return ERR_PTR(-ENODEV);
482
-
483
- devid = (int)(uintptr_t)match->data;
476
+ devid = (int)(uintptr_t)of_device_get_match_data(dev);
484477 maxleds = pca9532_chip_info_tbl[devid].num_leds;
485478
486479 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
487480 if (!pdata)
488481 return ERR_PTR(-ENOMEM);
489482
490
- for_each_child_of_node(np, child) {
483
+ of_property_read_u8_array(np, "nxp,pwm", &pdata->pwm[0],
484
+ ARRAY_SIZE(pdata->pwm));
485
+ of_property_read_u8_array(np, "nxp,psc", &pdata->psc[0],
486
+ ARRAY_SIZE(pdata->psc));
487
+
488
+ for_each_available_child_of_node(np, child) {
491489 if (of_property_read_string(child, "label",
492490 &pdata->leds[i].name))
493491 pdata->leds[i].name = child->name;
....@@ -513,11 +511,10 @@
513511 const struct i2c_device_id *id)
514512 {
515513 int devid;
516
- const struct of_device_id *of_id;
517514 struct pca9532_data *data = i2c_get_clientdata(client);
518515 struct pca9532_platform_data *pca9532_pdata =
519516 dev_get_platdata(&client->dev);
520
- struct device_node *np = client->dev.of_node;
517
+ struct device_node *np = dev_of_node(&client->dev);
521518
522519 if (!pca9532_pdata) {
523520 if (np) {
....@@ -529,11 +526,7 @@
529526 dev_err(&client->dev, "no platform data\n");
530527 return -EINVAL;
531528 }
532
- of_id = of_match_device(of_pca9532_leds_match,
533
- &client->dev);
534
- if (unlikely(!of_id))
535
- return -EINVAL;
536
- devid = (int)(uintptr_t) of_id->data;
529
+ devid = (int)(uintptr_t)of_device_get_match_data(&client->dev);
537530 } else {
538531 devid = id->driver_data;
539532 }
....@@ -559,13 +552,8 @@
559552 static int pca9532_remove(struct i2c_client *client)
560553 {
561554 struct pca9532_data *data = i2c_get_clientdata(client);
562
- int err;
563555
564
- err = pca9532_destroy_devices(data, data->chip_info->num_leds);
565
- if (err)
566
- return err;
567
-
568
- return 0;
556
+ return pca9532_destroy_devices(data, data->chip_info->num_leds);
569557 }
570558
571559 module_i2c_driver(pca9532_driver);