forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
kernel/drivers/hwmon/pmbus/ucd9000.c
....@@ -1,22 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Hardware monitoring driver for UCD90xxx Sequencer and System Health
34 * Controller series
45 *
56 * Copyright (C) 2011 Ericsson AB.
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 as published by
9
- * the Free Software Foundation; either version 2 of the License, or
10
- * (at your option) any later version.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU General Public License
18
- * along with this program; if not, write to the Free Software
19
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
207 */
218
229 #include <linux/debugfs.h>
....@@ -28,11 +15,11 @@
2815 #include <linux/slab.h>
2916 #include <linux/i2c.h>
3017 #include <linux/pmbus.h>
31
-#include <linux/gpio.h>
3218 #include <linux/gpio/driver.h>
3319 #include "pmbus.h"
3420
35
-enum chips { ucd9000, ucd90120, ucd90124, ucd90160, ucd9090, ucd90910 };
21
+enum chips { ucd9000, ucd90120, ucd90124, ucd90160, ucd90320, ucd9090,
22
+ ucd90910 };
3623
3724 #define UCD9000_MONITOR_CONFIG 0xd5
3825 #define UCD9000_NUM_PAGES 0xd6
....@@ -52,7 +39,7 @@
5239 #define UCD9000_GPIO_OUTPUT 1
5340
5441 #define UCD9000_MON_TYPE(x) (((x) >> 5) & 0x07)
55
-#define UCD9000_MON_PAGE(x) ((x) & 0x0f)
42
+#define UCD9000_MON_PAGE(x) ((x) & 0x1f)
5643
5744 #define UCD9000_MON_VOLTAGE 1
5845 #define UCD9000_MON_TEMPERATURE 2
....@@ -64,10 +51,12 @@
6451 #define UCD9000_GPIO_NAME_LEN 16
6552 #define UCD9090_NUM_GPIOS 23
6653 #define UCD901XX_NUM_GPIOS 26
54
+#define UCD90320_NUM_GPIOS 84
6755 #define UCD90910_NUM_GPIOS 26
6856
6957 #define UCD9000_DEBUGFS_NAME_LEN 24
7058 #define UCD9000_GPI_COUNT 8
59
+#define UCD90320_GPI_COUNT 32
7160
7261 struct ucd9000_data {
7362 u8 fan_data[UCD9000_NUM_FAN][I2C_SMBUS_BLOCK_MAX];
....@@ -145,13 +134,14 @@
145134 {"ucd90120", ucd90120},
146135 {"ucd90124", ucd90124},
147136 {"ucd90160", ucd90160},
137
+ {"ucd90320", ucd90320},
148138 {"ucd9090", ucd9090},
149139 {"ucd90910", ucd90910},
150140 {}
151141 };
152142 MODULE_DEVICE_TABLE(i2c, ucd9000_id);
153143
154
-static const struct of_device_id ucd9000_of_match[] = {
144
+static const struct of_device_id __maybe_unused ucd9000_of_match[] = {
155145 {
156146 .compatible = "ti,ucd9000",
157147 .data = (void *)ucd9000
....@@ -167,6 +157,10 @@
167157 {
168158 .compatible = "ti,ucd90160",
169159 .data = (void *)ucd90160
160
+ },
161
+ {
162
+ .compatible = "ti,ucd90320",
163
+ .data = (void *)ucd90320
170164 },
171165 {
172166 .compatible = "ti,ucd9090",
....@@ -336,6 +330,9 @@
336330 case ucd90160:
337331 data->gpio.ngpio = UCD901XX_NUM_GPIOS;
338332 break;
333
+ case ucd90320:
334
+ data->gpio.ngpio = UCD90320_NUM_GPIOS;
335
+ break;
339336 case ucd90910:
340337 data->gpio.ngpio = UCD90910_NUM_GPIOS;
341338 break;
....@@ -373,7 +370,7 @@
373370 #ifdef CONFIG_DEBUG_FS
374371 static int ucd9000_get_mfr_status(struct i2c_client *client, u8 *buffer)
375372 {
376
- int ret = pmbus_set_page(client, 0);
373
+ int ret = pmbus_set_page(client, 0, 0xff);
377374
378375 if (ret < 0)
379376 return ret;
....@@ -386,17 +383,18 @@
386383 struct ucd9000_debugfs_entry *entry = data;
387384 struct i2c_client *client = entry->client;
388385 u8 buffer[I2C_SMBUS_BLOCK_MAX];
389
- int ret;
386
+ int ret, i;
390387
391388 ret = ucd9000_get_mfr_status(client, buffer);
392389 if (ret < 0)
393390 return ret;
394391
395392 /*
396
- * Attribute only created for devices with gpi fault bits at bits
397
- * 16-23, which is the second byte of the response.
393
+ * GPI fault bits are in sets of 8, two bytes from end of response.
398394 */
399
- *val = !!(buffer[1] & BIT(entry->index));
395
+ i = ret - 3 - entry->index / 8;
396
+ if (i >= 0)
397
+ *val = !!(buffer[i] & BIT(entry->index % 8));
400398
401399 return 0;
402400 }
....@@ -436,7 +434,7 @@
436434 {
437435 struct dentry *debugfs;
438436 struct ucd9000_debugfs_entry *entries;
439
- int i;
437
+ int i, gpi_count;
440438 char name[UCD9000_DEBUGFS_NAME_LEN];
441439
442440 debugfs = pmbus_get_debugfs_dir(client);
....@@ -449,18 +447,21 @@
449447
450448 /*
451449 * Of the chips this driver supports, only the UCD9090, UCD90160,
452
- * and UCD90910 report GPI faults in their MFR_STATUS register, so only
453
- * create the GPI fault debugfs attributes for those chips.
450
+ * UCD90320, and UCD90910 report GPI faults in their MFR_STATUS
451
+ * register, so only create the GPI fault debugfs attributes for those
452
+ * chips.
454453 */
455454 if (mid->driver_data == ucd9090 || mid->driver_data == ucd90160 ||
456
- mid->driver_data == ucd90910) {
455
+ mid->driver_data == ucd90320 || mid->driver_data == ucd90910) {
456
+ gpi_count = mid->driver_data == ucd90320 ? UCD90320_GPI_COUNT
457
+ : UCD9000_GPI_COUNT;
457458 entries = devm_kcalloc(&client->dev,
458
- UCD9000_GPI_COUNT, sizeof(*entries),
459
+ gpi_count, sizeof(*entries),
459460 GFP_KERNEL);
460461 if (!entries)
461462 return -ENOMEM;
462463
463
- for (i = 0; i < UCD9000_GPI_COUNT; i++) {
464
+ for (i = 0; i < gpi_count; i++) {
464465 entries[i].client = client;
465466 entries[i].index = i;
466467 scnprintf(name, UCD9000_DEBUGFS_NAME_LEN,
....@@ -486,8 +487,7 @@
486487 }
487488 #endif /* CONFIG_DEBUG_FS */
488489
489
-static int ucd9000_probe(struct i2c_client *client,
490
- const struct i2c_device_id *id)
490
+static int ucd9000_probe(struct i2c_client *client)
491491 {
492492 u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1];
493493 struct ucd9000_data *data;
....@@ -522,12 +522,12 @@
522522 if (client->dev.of_node)
523523 chip = (enum chips)of_device_get_match_data(&client->dev);
524524 else
525
- chip = id->driver_data;
525
+ chip = mid->driver_data;
526526
527
- if (chip != ucd9000 && chip != mid->driver_data)
527
+ if (chip != ucd9000 && strcmp(client->name, mid->name) != 0)
528528 dev_notice(&client->dev,
529529 "Device mismatch: Configured %s, detected %s\n",
530
- id->name, mid->name);
530
+ client->name, mid->name);
531531
532532 data = devm_kzalloc(&client->dev, sizeof(struct ucd9000_data),
533533 GFP_KERNEL);
....@@ -602,7 +602,7 @@
602602
603603 ucd9000_probe_gpio(client, mid, data);
604604
605
- ret = pmbus_do_probe(client, mid, info);
605
+ ret = pmbus_do_probe(client, info);
606606 if (ret)
607607 return ret;
608608
....@@ -620,7 +620,7 @@
620620 .name = "ucd9000",
621621 .of_match_table = of_match_ptr(ucd9000_of_match),
622622 },
623
- .probe = ucd9000_probe,
623
+ .probe_new = ucd9000_probe,
624624 .remove = pmbus_do_remove,
625625 .id_table = ucd9000_id,
626626 };