forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/drivers/hwmon/pmbus/lm25066.c
....@@ -1,22 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Hardware monitoring driver for LM25056 / LM25066 / LM5064 / LM5066
34 *
45 * Copyright (c) 2011 Ericsson AB.
56 * Copyright (c) 2013 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>
....@@ -26,6 +13,7 @@
2613 #include <linux/err.h>
2714 #include <linux/slab.h>
2815 #include <linux/i2c.h>
16
+#include <linux/log2.h>
2917 #include "pmbus.h"
3018
3119 enum chips { lm25056, lm25066, lm5064, lm5066, lm5066i };
....@@ -39,11 +27,14 @@
3927 #define LM25066_CLEAR_PIN_PEAK 0xd6
4028 #define LM25066_DEVICE_SETUP 0xd9
4129 #define LM25066_READ_AVG_VIN 0xdc
30
+#define LM25066_SAMPLES_FOR_AVG 0xdb
4231 #define LM25066_READ_AVG_VOUT 0xdd
4332 #define LM25066_READ_AVG_IIN 0xde
4433 #define LM25066_READ_AVG_PIN 0xdf
4534
4635 #define LM25066_DEV_SETUP_CL BIT(4) /* Current limit */
36
+
37
+#define LM25066_SAMPLES_FOR_AVG_MAX 4096
4738
4839 /* LM25056 only */
4940
....@@ -243,7 +234,10 @@
243234
244235 #define to_lm25066_data(x) container_of(x, struct lm25066_data, info)
245236
246
-static int lm25066_read_word_data(struct i2c_client *client, int page, int reg)
237
+static const struct i2c_device_id lm25066_id[];
238
+
239
+static int lm25066_read_word_data(struct i2c_client *client, int page,
240
+ int phase, int reg)
247241 {
248242 const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
249243 const struct lm25066_data *data = to_lm25066_data(info);
....@@ -251,7 +245,7 @@
251245
252246 switch (reg) {
253247 case PMBUS_VIRT_READ_VMON:
254
- ret = pmbus_read_word_data(client, 0, LM25066_READ_VAUX);
248
+ ret = pmbus_read_word_data(client, 0, 0xff, LM25066_READ_VAUX);
255249 if (ret < 0)
256250 break;
257251 /* Adjust returned value to match VIN coefficients */
....@@ -276,36 +270,49 @@
276270 }
277271 break;
278272 case PMBUS_READ_IIN:
279
- ret = pmbus_read_word_data(client, 0, LM25066_MFR_READ_IIN);
273
+ ret = pmbus_read_word_data(client, 0, 0xff,
274
+ LM25066_MFR_READ_IIN);
280275 break;
281276 case PMBUS_READ_PIN:
282
- ret = pmbus_read_word_data(client, 0, LM25066_MFR_READ_PIN);
277
+ ret = pmbus_read_word_data(client, 0, 0xff,
278
+ LM25066_MFR_READ_PIN);
283279 break;
284280 case PMBUS_IIN_OC_WARN_LIMIT:
285
- ret = pmbus_read_word_data(client, 0,
281
+ ret = pmbus_read_word_data(client, 0, 0xff,
286282 LM25066_MFR_IIN_OC_WARN_LIMIT);
287283 break;
288284 case PMBUS_PIN_OP_WARN_LIMIT:
289
- ret = pmbus_read_word_data(client, 0,
285
+ ret = pmbus_read_word_data(client, 0, 0xff,
290286 LM25066_MFR_PIN_OP_WARN_LIMIT);
291287 break;
292288 case PMBUS_VIRT_READ_VIN_AVG:
293
- ret = pmbus_read_word_data(client, 0, LM25066_READ_AVG_VIN);
289
+ ret = pmbus_read_word_data(client, 0, 0xff,
290
+ LM25066_READ_AVG_VIN);
294291 break;
295292 case PMBUS_VIRT_READ_VOUT_AVG:
296
- ret = pmbus_read_word_data(client, 0, LM25066_READ_AVG_VOUT);
293
+ ret = pmbus_read_word_data(client, 0, 0xff,
294
+ LM25066_READ_AVG_VOUT);
297295 break;
298296 case PMBUS_VIRT_READ_IIN_AVG:
299
- ret = pmbus_read_word_data(client, 0, LM25066_READ_AVG_IIN);
297
+ ret = pmbus_read_word_data(client, 0, 0xff,
298
+ LM25066_READ_AVG_IIN);
300299 break;
301300 case PMBUS_VIRT_READ_PIN_AVG:
302
- ret = pmbus_read_word_data(client, 0, LM25066_READ_AVG_PIN);
301
+ ret = pmbus_read_word_data(client, 0, 0xff,
302
+ LM25066_READ_AVG_PIN);
303303 break;
304304 case PMBUS_VIRT_READ_PIN_MAX:
305
- ret = pmbus_read_word_data(client, 0, LM25066_READ_PIN_PEAK);
305
+ ret = pmbus_read_word_data(client, 0, 0xff,
306
+ LM25066_READ_PIN_PEAK);
306307 break;
307308 case PMBUS_VIRT_RESET_PIN_HISTORY:
308309 ret = 0;
310
+ break;
311
+ case PMBUS_VIRT_SAMPLES:
312
+ ret = pmbus_read_byte_data(client, 0, LM25066_SAMPLES_FOR_AVG);
313
+ if (ret < 0)
314
+ break;
315
+ ret = 1 << ret;
309316 break;
310317 default:
311318 ret = -ENODATA;
....@@ -314,13 +321,14 @@
314321 return ret;
315322 }
316323
317
-static int lm25056_read_word_data(struct i2c_client *client, int page, int reg)
324
+static int lm25056_read_word_data(struct i2c_client *client, int page,
325
+ int phase, int reg)
318326 {
319327 int ret;
320328
321329 switch (reg) {
322330 case PMBUS_VIRT_VMON_UV_WARN_LIMIT:
323
- ret = pmbus_read_word_data(client, 0,
331
+ ret = pmbus_read_word_data(client, 0, 0xff,
324332 LM25056_VAUX_UV_WARN_LIMIT);
325333 if (ret < 0)
326334 break;
....@@ -328,7 +336,7 @@
328336 ret = DIV_ROUND_CLOSEST(ret * 293, 6140);
329337 break;
330338 case PMBUS_VIRT_VMON_OV_WARN_LIMIT:
331
- ret = pmbus_read_word_data(client, 0,
339
+ ret = pmbus_read_word_data(client, 0, 0xff,
332340 LM25056_VAUX_OV_WARN_LIMIT);
333341 if (ret < 0)
334342 break;
....@@ -336,7 +344,7 @@
336344 ret = DIV_ROUND_CLOSEST(ret * 293, 6140);
337345 break;
338346 default:
339
- ret = lm25066_read_word_data(client, page, reg);
347
+ ret = lm25066_read_word_data(client, page, phase, reg);
340348 break;
341349 }
342350 return ret;
....@@ -421,6 +429,11 @@
421429 case PMBUS_VIRT_RESET_PIN_HISTORY:
422430 ret = pmbus_write_byte(client, 0, LM25066_CLEAR_PIN_PEAK);
423431 break;
432
+ case PMBUS_VIRT_SAMPLES:
433
+ word = clamp_val(word, 1, LM25066_SAMPLES_FOR_AVG_MAX);
434
+ ret = pmbus_write_byte_data(client, 0, LM25066_SAMPLES_FOR_AVG,
435
+ ilog2(word));
436
+ break;
424437 default:
425438 ret = -ENODATA;
426439 break;
....@@ -428,8 +441,7 @@
428441 return ret;
429442 }
430443
431
-static int lm25066_probe(struct i2c_client *client,
432
- const struct i2c_device_id *id)
444
+static int lm25066_probe(struct i2c_client *client)
433445 {
434446 int config;
435447 struct lm25066_data *data;
....@@ -449,7 +461,7 @@
449461 if (config < 0)
450462 return config;
451463
452
- data->id = id->driver_data;
464
+ data->id = i2c_match_id(lm25066_id, client)->driver_data;
453465 info = &data->info;
454466
455467 info->pages = 1;
....@@ -461,7 +473,7 @@
461473
462474 info->func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VMON
463475 | PMBUS_HAVE_PIN | PMBUS_HAVE_IIN | PMBUS_HAVE_STATUS_INPUT
464
- | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP;
476
+ | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP | PMBUS_HAVE_SAMPLES;
465477
466478 if (data->id == lm25056) {
467479 info->func[0] |= PMBUS_HAVE_STATUS_VMON;
....@@ -499,7 +511,7 @@
499511 info->b[PSC_POWER] = coeff[PSC_POWER].b;
500512 }
501513
502
- return pmbus_do_probe(client, id, info);
514
+ return pmbus_do_probe(client, info);
503515 }
504516
505517 static const struct i2c_device_id lm25066_id[] = {
....@@ -518,7 +530,7 @@
518530 .driver = {
519531 .name = "lm25066",
520532 },
521
- .probe = lm25066_probe,
533
+ .probe_new = lm25066_probe,
522534 .remove = pmbus_do_remove,
523535 .id_table = lm25066_id,
524536 };