hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/leds/leds-pca955x.c
....@@ -1,11 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright 2007-2008 Extreme Engineering Solutions, Inc.
34 *
45 * Author: Nate Case <ncase@xes-inc.com>
5
- *
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.
96 *
107 * LED driver for various PCA955x I2C LED drivers
118 *
....@@ -40,16 +37,15 @@
4037 * bits the chip supports.
4138 */
4239
43
-#include <linux/acpi.h>
4440 #include <linux/ctype.h>
4541 #include <linux/delay.h>
4642 #include <linux/err.h>
47
-#include <linux/gpio.h>
43
+#include <linux/gpio/driver.h>
4844 #include <linux/i2c.h>
4945 #include <linux/leds.h>
5046 #include <linux/module.h>
51
-#include <linux/of_device.h>
5247 #include <linux/of.h>
48
+#include <linux/property.h>
5349 #include <linux/slab.h>
5450 #include <linux/string.h>
5551
....@@ -69,6 +65,7 @@
6965 pca9550,
7066 pca9551,
7167 pca9552,
68
+ ibm_pca9552,
7269 pca9553,
7370 };
7471
....@@ -94,6 +91,11 @@
9491 .slv_addr = /* 1100xxx */ 0x60,
9592 .slv_addr_shift = 3,
9693 },
94
+ [ibm_pca9552] = {
95
+ .bits = 16,
96
+ .slv_addr = /* 0110xxx */ 0x30,
97
+ .slv_addr_shift = 3,
98
+ },
9799 [pca9553] = {
98100 .bits = 4,
99101 .slv_addr = /* 110001x */ 0x62,
....@@ -105,19 +107,11 @@
105107 { "pca9550", pca9550 },
106108 { "pca9551", pca9551 },
107109 { "pca9552", pca9552 },
110
+ { "ibm-pca9552", ibm_pca9552 },
108111 { "pca9553", pca9553 },
109112 { }
110113 };
111114 MODULE_DEVICE_TABLE(i2c, pca955x_id);
112
-
113
-static const struct acpi_device_id pca955x_acpi_ids[] = {
114
- { "PCA9550", pca9550 },
115
- { "PCA9551", pca9551 },
116
- { "PCA9552", pca9552 },
117
- { "PCA9553", pca9553 },
118
- { }
119
-};
120
-MODULE_DEVICE_TABLE(acpi, pca955x_acpi_ids);
121115
122116 struct pca955x {
123117 struct mutex lock;
....@@ -373,16 +367,14 @@
373367 }
374368 #endif /* CONFIG_LEDS_PCA955X_GPIO */
375369
376
-#if IS_ENABLED(CONFIG_OF)
377370 static struct pca955x_platform_data *
378
-pca955x_pdata_of_init(struct i2c_client *client, struct pca955x_chipdef *chip)
371
+pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
379372 {
380
- struct device_node *np = client->dev.of_node;
381
- struct device_node *child;
382373 struct pca955x_platform_data *pdata;
374
+ struct fwnode_handle *child;
383375 int count;
384376
385
- count = of_get_child_count(np);
377
+ count = device_get_child_node_count(&client->dev);
386378 if (!count || count > chip->bits)
387379 return ERR_PTR(-ENODEV);
388380
....@@ -396,24 +388,25 @@
396388 if (!pdata->leds)
397389 return ERR_PTR(-ENOMEM);
398390
399
- for_each_child_of_node(np, child) {
391
+ device_for_each_child_node(&client->dev, child) {
400392 const char *name;
401393 u32 reg;
402394 int res;
403395
404
- res = of_property_read_u32(child, "reg", &reg);
396
+ res = fwnode_property_read_u32(child, "reg", &reg);
405397 if ((res != 0) || (reg >= chip->bits))
406398 continue;
407399
408
- if (of_property_read_string(child, "label", &name))
409
- name = child->name;
400
+ res = fwnode_property_read_string(child, "label", &name);
401
+ if ((res != 0) && is_of_node(child))
402
+ name = to_of_node(child)->name;
410403
411404 snprintf(pdata->leds[reg].name, sizeof(pdata->leds[reg].name),
412405 "%s", name);
413406
414407 pdata->leds[reg].type = PCA955X_TYPE_LED;
415
- of_property_read_u32(child, "type", &pdata->leds[reg].type);
416
- of_property_read_string(child, "linux,default-trigger",
408
+ fwnode_property_read_u32(child, "type", &pdata->leds[reg].type);
409
+ fwnode_property_read_string(child, "linux,default-trigger",
417410 &pdata->leds[reg].default_trigger);
418411 }
419412
....@@ -426,18 +419,11 @@
426419 { .compatible = "nxp,pca9550", .data = (void *)pca9550 },
427420 { .compatible = "nxp,pca9551", .data = (void *)pca9551 },
428421 { .compatible = "nxp,pca9552", .data = (void *)pca9552 },
422
+ { .compatible = "ibm,pca9552", .data = (void *)ibm_pca9552 },
429423 { .compatible = "nxp,pca9553", .data = (void *)pca9553 },
430424 {},
431425 };
432
-
433426 MODULE_DEVICE_TABLE(of, of_pca955x_match);
434
-#else
435
-static struct pca955x_platform_data *
436
-pca955x_pdata_of_init(struct i2c_client *client, struct pca955x_chipdef *chip)
437
-{
438
- return ERR_PTR(-ENODEV);
439
-}
440
-#endif
441427
442428 static int pca955x_probe(struct i2c_client *client,
443429 const struct i2c_device_id *id)
....@@ -450,20 +436,11 @@
450436 struct pca955x_platform_data *pdata;
451437 int ngpios = 0;
452438
453
- if (id) {
454
- chip = &pca955x_chipdefs[id->driver_data];
455
- } else {
456
- const struct acpi_device_id *acpi_id;
457
-
458
- acpi_id = acpi_match_device(pca955x_acpi_ids, &client->dev);
459
- if (!acpi_id)
460
- return -ENODEV;
461
- chip = &pca955x_chipdefs[acpi_id->driver_data];
462
- }
463
- adapter = to_i2c_adapter(client->dev.parent);
439
+ chip = &pca955x_chipdefs[id->driver_data];
440
+ adapter = client->adapter;
464441 pdata = dev_get_platdata(&client->dev);
465442 if (!pdata) {
466
- pdata = pca955x_pdata_of_init(client, chip);
443
+ pdata = pca955x_get_pdata(client, chip);
467444 if (IS_ERR(pdata))
468445 return PTR_ERR(pdata);
469446 }
....@@ -602,8 +579,7 @@
602579 static struct i2c_driver pca955x_driver = {
603580 .driver = {
604581 .name = "leds-pca955x",
605
- .acpi_match_table = ACPI_PTR(pca955x_acpi_ids),
606
- .of_match_table = of_match_ptr(of_pca955x_match),
582
+ .of_match_table = of_pca955x_match,
607583 },
608584 .probe = pca955x_probe,
609585 .id_table = pca955x_id,