hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/leds/leds-is31fl319x.c
....@@ -1,15 +1,11 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright 2015-16 Golden Delicious Computers
34 *
45 * Author: Nikolaus Schaller <hns@goldelico.com>
56 *
6
- * This file is subject to the terms and conditions of version 2 of
7
- * the GNU General Public License. See the file COPYING in the main
8
- * directory of this archive for more details.
9
- *
107 * LED driver for the IS31FL319{0,1,3,6,9} to drive 1, 3, 6 or 9 light
118 * effect LEDs.
12
- *
139 */
1410
1511 #include <linux/err.h>
....@@ -20,6 +16,8 @@
2016 #include <linux/of_device.h>
2117 #include <linux/regmap.h>
2218 #include <linux/slab.h>
19
+#include <linux/delay.h>
20
+#include <linux/gpio/consumer.h>
2321
2422 /* register numbers */
2523 #define IS31FL319X_SHUTDOWN 0x00
....@@ -65,6 +63,7 @@
6563 struct is31fl319x_chip {
6664 const struct is31fl319x_chipdef *cdef;
6765 struct i2c_client *client;
66
+ struct gpio_desc *shutdown_gpio;
6867 struct regmap *regmap;
6968 struct mutex lock;
7069 u32 audio_gain_db;
....@@ -203,26 +202,27 @@
203202 static int is31fl319x_parse_dt(struct device *dev,
204203 struct is31fl319x_chip *is31)
205204 {
206
- struct device_node *np = dev->of_node, *child;
207
- const struct of_device_id *of_dev_id;
205
+ struct device_node *np = dev_of_node(dev), *child;
208206 int count;
209207 int ret;
210208
211209 if (!np)
212210 return -ENODEV;
213211
214
- of_dev_id = of_match_device(of_is31fl319x_match, dev);
215
- if (!of_dev_id) {
216
- dev_err(dev, "Failed to match device with supported chips\n");
217
- return -EINVAL;
212
+ is31->shutdown_gpio = devm_gpiod_get_optional(dev,
213
+ "shutdown",
214
+ GPIOD_OUT_HIGH);
215
+ if (IS_ERR(is31->shutdown_gpio)) {
216
+ ret = PTR_ERR(is31->shutdown_gpio);
217
+ dev_err(dev, "Failed to get shutdown gpio: %d\n", ret);
218
+ return ret;
218219 }
219220
220
- is31->cdef = of_dev_id->data;
221
+ is31->cdef = device_get_match_data(dev);
221222
222
- count = of_get_child_count(np);
223
+ count = of_get_available_child_count(np);
223224
224
- dev_dbg(dev, "probe %s with %d leds defined in DT\n",
225
- of_dev_id->compatible, count);
225
+ dev_dbg(dev, "probing with %d leds defined in DT\n", count);
226226
227227 if (!count || count > is31->cdef->num_leds) {
228228 dev_err(dev, "Number of leds defined must be between 1 and %u\n",
....@@ -230,7 +230,7 @@
230230 return -ENODEV;
231231 }
232232
233
- for_each_child_of_node(np, child) {
233
+ for_each_available_child_of_node(np, child) {
234234 struct is31fl319x_led *led;
235235 u32 reg;
236236
....@@ -337,12 +337,11 @@
337337 {
338338 struct is31fl319x_chip *is31;
339339 struct device *dev = &client->dev;
340
- struct i2c_adapter *adapter = to_i2c_adapter(dev->parent);
341340 int err;
342341 int i = 0;
343342 u32 aggregated_led_microamp = IS31FL319X_CURRENT_MAX;
344343
345
- if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
344
+ if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
346345 return -EIO;
347346
348347 is31 = devm_kzalloc(&client->dev, sizeof(*is31), GFP_KERNEL);
....@@ -355,6 +354,12 @@
355354 if (err)
356355 goto free_mutex;
357356
357
+ if (is31->shutdown_gpio) {
358
+ gpiod_direction_output(is31->shutdown_gpio, 0);
359
+ mdelay(5);
360
+ gpiod_direction_output(is31->shutdown_gpio, 1);
361
+ }
362
+
358363 is31->client = client;
359364 is31->regmap = devm_regmap_init_i2c(client, &regmap_config);
360365 if (IS_ERR(is31->regmap)) {