forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/drivers/hwmon/pmbus/max34440.c
....@@ -1,22 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Hardware monitoring driver for Maxim MAX34440/MAX34441
34 *
45 * Copyright (c) 2011 Ericsson AB.
56 * Copyright (c) 2012 Guenter Roeck
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/bitops.h>
....@@ -44,6 +31,13 @@
4431 #define MAX34440_STATUS_OT_FAULT BIT(5)
4532 #define MAX34440_STATUS_OT_WARN BIT(6)
4633
34
+/*
35
+ * The whole max344* family have IOUT_OC_WARN_LIMIT and IOUT_OC_FAULT_LIMIT
36
+ * swapped from the standard pmbus spec addresses.
37
+ */
38
+#define MAX34440_IOUT_OC_WARN_LIMIT 0x46
39
+#define MAX34440_IOUT_OC_FAULT_LIMIT 0x4A
40
+
4741 #define MAX34451_MFR_CHANNEL_CONFIG 0xe4
4842 #define MAX34451_MFR_CHANNEL_CONFIG_SEL_MASK 0x3f
4943
....@@ -54,52 +48,63 @@
5448
5549 #define to_max34440_data(x) container_of(x, struct max34440_data, info)
5650
57
-static int max34440_read_word_data(struct i2c_client *client, int page, int reg)
51
+static const struct i2c_device_id max34440_id[];
52
+
53
+static int max34440_read_word_data(struct i2c_client *client, int page,
54
+ int phase, int reg)
5855 {
5956 int ret;
6057 const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
6158 const struct max34440_data *data = to_max34440_data(info);
6259
6360 switch (reg) {
61
+ case PMBUS_IOUT_OC_FAULT_LIMIT:
62
+ ret = pmbus_read_word_data(client, page, phase,
63
+ MAX34440_IOUT_OC_FAULT_LIMIT);
64
+ break;
65
+ case PMBUS_IOUT_OC_WARN_LIMIT:
66
+ ret = pmbus_read_word_data(client, page, phase,
67
+ MAX34440_IOUT_OC_WARN_LIMIT);
68
+ break;
6469 case PMBUS_VIRT_READ_VOUT_MIN:
65
- ret = pmbus_read_word_data(client, page,
70
+ ret = pmbus_read_word_data(client, page, phase,
6671 MAX34440_MFR_VOUT_MIN);
6772 break;
6873 case PMBUS_VIRT_READ_VOUT_MAX:
69
- ret = pmbus_read_word_data(client, page,
74
+ ret = pmbus_read_word_data(client, page, phase,
7075 MAX34440_MFR_VOUT_PEAK);
7176 break;
7277 case PMBUS_VIRT_READ_IOUT_AVG:
7378 if (data->id != max34446 && data->id != max34451)
7479 return -ENXIO;
75
- ret = pmbus_read_word_data(client, page,
80
+ ret = pmbus_read_word_data(client, page, phase,
7681 MAX34446_MFR_IOUT_AVG);
7782 break;
7883 case PMBUS_VIRT_READ_IOUT_MAX:
79
- ret = pmbus_read_word_data(client, page,
84
+ ret = pmbus_read_word_data(client, page, phase,
8085 MAX34440_MFR_IOUT_PEAK);
8186 break;
8287 case PMBUS_VIRT_READ_POUT_AVG:
8388 if (data->id != max34446)
8489 return -ENXIO;
85
- ret = pmbus_read_word_data(client, page,
90
+ ret = pmbus_read_word_data(client, page, phase,
8691 MAX34446_MFR_POUT_AVG);
8792 break;
8893 case PMBUS_VIRT_READ_POUT_MAX:
8994 if (data->id != max34446)
9095 return -ENXIO;
91
- ret = pmbus_read_word_data(client, page,
96
+ ret = pmbus_read_word_data(client, page, phase,
9297 MAX34446_MFR_POUT_PEAK);
9398 break;
9499 case PMBUS_VIRT_READ_TEMP_AVG:
95100 if (data->id != max34446 && data->id != max34460 &&
96101 data->id != max34461)
97102 return -ENXIO;
98
- ret = pmbus_read_word_data(client, page,
103
+ ret = pmbus_read_word_data(client, page, phase,
99104 MAX34446_MFR_TEMPERATURE_AVG);
100105 break;
101106 case PMBUS_VIRT_READ_TEMP_MAX:
102
- ret = pmbus_read_word_data(client, page,
107
+ ret = pmbus_read_word_data(client, page, phase,
103108 MAX34440_MFR_TEMPERATURE_PEAK);
104109 break;
105110 case PMBUS_VIRT_RESET_POUT_HISTORY:
....@@ -127,6 +132,14 @@
127132 int ret;
128133
129134 switch (reg) {
135
+ case PMBUS_IOUT_OC_FAULT_LIMIT:
136
+ ret = pmbus_write_word_data(client, page, MAX34440_IOUT_OC_FAULT_LIMIT,
137
+ word);
138
+ break;
139
+ case PMBUS_IOUT_OC_WARN_LIMIT:
140
+ ret = pmbus_write_word_data(client, page, MAX34440_IOUT_OC_WARN_LIMIT,
141
+ word);
142
+ break;
130143 case PMBUS_VIRT_RESET_POUT_HISTORY:
131144 ret = pmbus_write_word_data(client, page,
132145 MAX34446_MFR_POUT_PEAK, 0);
....@@ -172,14 +185,14 @@
172185 int mfg_status;
173186
174187 if (page >= 0) {
175
- ret = pmbus_set_page(client, page);
188
+ ret = pmbus_set_page(client, page, 0xff);
176189 if (ret < 0)
177190 return ret;
178191 }
179192
180193 switch (reg) {
181194 case PMBUS_STATUS_IOUT:
182
- mfg_status = pmbus_read_word_data(client, 0,
195
+ mfg_status = pmbus_read_word_data(client, 0, 0xff,
183196 PMBUS_STATUS_MFR_SPECIFIC);
184197 if (mfg_status < 0)
185198 return mfg_status;
....@@ -189,7 +202,7 @@
189202 ret |= PB_IOUT_OC_FAULT;
190203 break;
191204 case PMBUS_STATUS_TEMPERATURE:
192
- mfg_status = pmbus_read_word_data(client, 0,
205
+ mfg_status = pmbus_read_word_data(client, 0, 0xff,
193206 PMBUS_STATUS_MFR_SPECIFIC);
194207 if (mfg_status < 0)
195208 return mfg_status;
....@@ -470,8 +483,7 @@
470483 },
471484 };
472485
473
-static int max34440_probe(struct i2c_client *client,
474
- const struct i2c_device_id *id)
486
+static int max34440_probe(struct i2c_client *client)
475487 {
476488 struct max34440_data *data;
477489 int rv;
....@@ -480,8 +492,8 @@
480492 GFP_KERNEL);
481493 if (!data)
482494 return -ENOMEM;
483
- data->id = id->driver_data;
484
- data->info = max34440_info[id->driver_data];
495
+ data->id = i2c_match_id(max34440_id, client)->driver_data;
496
+ data->info = max34440_info[data->id];
485497
486498 if (data->id == max34451) {
487499 rv = max34451_set_supported_funcs(client, data);
....@@ -489,7 +501,7 @@
489501 return rv;
490502 }
491503
492
- return pmbus_do_probe(client, id, &data->info);
504
+ return pmbus_do_probe(client, &data->info);
493505 }
494506
495507 static const struct i2c_device_id max34440_id[] = {
....@@ -508,7 +520,7 @@
508520 .driver = {
509521 .name = "max34440",
510522 },
511
- .probe = max34440_probe,
523
+ .probe_new = max34440_probe,
512524 .remove = pmbus_do_remove,
513525 .id_table = max34440_id,
514526 };