forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/drivers/hwmon/pmbus/ltc2978.c
....@@ -1,19 +1,11 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Hardware monitoring driver for LTC2978 and compatible chips.
34 *
45 * Copyright (c) 2011 Ericsson AB.
56 * Copyright (c) 2013, 2014, 2015 Guenter Roeck
67 * Copyright (c) 2015 Linear Technology
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
8
+ * Copyright (c) 2018 Analog Devices Inc.
179 */
1810
1911 #include <linux/delay.h>
....@@ -27,8 +19,15 @@
2719 #include <linux/regulator/driver.h>
2820 #include "pmbus.h"
2921
30
-enum chips { ltc2974, ltc2975, ltc2977, ltc2978, ltc2980, ltc3880, ltc3882,
31
- ltc3883, ltc3886, ltc3887, ltm2987, ltm4675, ltm4676 };
22
+enum chips {
23
+ /* Managers */
24
+ ltc2972, ltc2974, ltc2975, ltc2977, ltc2978, ltc2979, ltc2980,
25
+ /* Controllers */
26
+ ltc3880, ltc3882, ltc3883, ltc3884, ltc3886, ltc3887, ltc3889, ltc7880,
27
+ /* Modules */
28
+ ltm2987, ltm4664, ltm4675, ltm4676, ltm4677, ltm4678, ltm4680, ltm4686,
29
+ ltm4700,
30
+};
3231
3332 /* Common for all chips */
3433 #define LTC2978_MFR_VOUT_PEAK 0xdd
....@@ -51,8 +50,9 @@
5150 #define LTC3880_MFR_CLEAR_PEAKS 0xe3
5251 #define LTC3880_MFR_TEMPERATURE2_PEAK 0xf4
5352
54
-/* LTC3883 and LTC3886 only */
53
+/* LTC3883, LTC3884, LTC3886, LTC3889 and LTC7880 only */
5554 #define LTC3883_MFR_IIN_PEAK 0xe1
55
+
5656
5757 /* LTC2975 only */
5858 #define LTC2975_MFR_IIN_PEAK 0xc4
....@@ -62,26 +62,41 @@
6262
6363 #define LTC2978_ID_MASK 0xfff0
6464
65
+#define LTC2972_ID 0x0310
6566 #define LTC2974_ID 0x0210
6667 #define LTC2975_ID 0x0220
6768 #define LTC2977_ID 0x0130
6869 #define LTC2978_ID_REV1 0x0110 /* Early revision */
6970 #define LTC2978_ID_REV2 0x0120
71
+#define LTC2979_ID_A 0x8060
72
+#define LTC2979_ID_B 0x8070
7073 #define LTC2980_ID_A 0x8030 /* A/B for two die IDs */
7174 #define LTC2980_ID_B 0x8040
7275 #define LTC3880_ID 0x4020
7376 #define LTC3882_ID 0x4200
7477 #define LTC3882_ID_D1 0x4240 /* Dash 1 */
7578 #define LTC3883_ID 0x4300
79
+#define LTC3884_ID 0x4C00
7680 #define LTC3886_ID 0x4600
7781 #define LTC3887_ID 0x4700
7882 #define LTM2987_ID_A 0x8010 /* A/B for two die IDs */
7983 #define LTM2987_ID_B 0x8020
84
+#define LTC3889_ID 0x4900
85
+#define LTC7880_ID 0x49E0
86
+#define LTM4664_ID 0x4120
8087 #define LTM4675_ID 0x47a0
8188 #define LTM4676_ID_REV1 0x4400
8289 #define LTM4676_ID_REV2 0x4480
8390 #define LTM4676A_ID 0x47e0
91
+#define LTM4677_ID_REV1 0x47B0
92
+#define LTM4677_ID_REV2 0x47D0
93
+#define LTM4678_ID_REV1 0x4100
94
+#define LTM4678_ID_REV2 0x4110
95
+#define LTM4680_ID 0x4140
96
+#define LTM4686_ID 0x4770
97
+#define LTM4700_ID 0x4130
8498
99
+#define LTC2972_NUM_PAGES 2
85100 #define LTC2974_NUM_PAGES 4
86101 #define LTC2978_NUM_PAGES 8
87102 #define LTC3880_NUM_PAGES 2
....@@ -158,7 +173,8 @@
158173 return -ETIMEDOUT;
159174 }
160175
161
-static int ltc_read_word_data(struct i2c_client *client, int page, int reg)
176
+static int ltc_read_word_data(struct i2c_client *client, int page, int phase,
177
+ int reg)
162178 {
163179 int ret;
164180
....@@ -166,7 +182,7 @@
166182 if (ret < 0)
167183 return ret;
168184
169
- return pmbus_read_word_data(client, page, reg);
185
+ return pmbus_read_word_data(client, page, 0xff, reg);
170186 }
171187
172188 static int ltc_read_byte_data(struct i2c_client *client, int page, int reg)
....@@ -209,7 +225,7 @@
209225 {
210226 int ret;
211227
212
- ret = ltc_read_word_data(client, page, reg);
228
+ ret = ltc_read_word_data(client, page, 0xff, reg);
213229 if (ret >= 0) {
214230 if (lin11_to_val(ret) > lin11_to_val(*pmax))
215231 *pmax = ret;
....@@ -223,7 +239,7 @@
223239 {
224240 int ret;
225241
226
- ret = ltc_read_word_data(client, page, reg);
242
+ ret = ltc_read_word_data(client, page, 0xff, reg);
227243 if (ret >= 0) {
228244 if (lin11_to_val(ret) < lin11_to_val(*pmin))
229245 *pmin = ret;
....@@ -245,7 +261,8 @@
245261 &data->vin_max);
246262 break;
247263 case PMBUS_VIRT_READ_VOUT_MAX:
248
- ret = ltc_read_word_data(client, page, LTC2978_MFR_VOUT_PEAK);
264
+ ret = ltc_read_word_data(client, page, 0xff,
265
+ LTC2978_MFR_VOUT_PEAK);
249266 if (ret >= 0) {
250267 /*
251268 * VOUT is 16 bit unsigned with fixed exponent,
....@@ -276,7 +293,8 @@
276293 return ret;
277294 }
278295
279
-static int ltc2978_read_word_data(struct i2c_client *client, int page, int reg)
296
+static int ltc2978_read_word_data(struct i2c_client *client, int page,
297
+ int phase, int reg)
280298 {
281299 const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
282300 struct ltc2978_data *data = to_ltc2978_data(info);
....@@ -288,7 +306,8 @@
288306 &data->vin_min);
289307 break;
290308 case PMBUS_VIRT_READ_VOUT_MIN:
291
- ret = ltc_read_word_data(client, page, LTC2978_MFR_VOUT_MIN);
309
+ ret = ltc_read_word_data(client, page, phase,
310
+ LTC2978_MFR_VOUT_MIN);
292311 if (ret >= 0) {
293312 /*
294313 * VOUT_MIN is known to not be supported on some lots
....@@ -321,7 +340,8 @@
321340 return ret;
322341 }
323342
324
-static int ltc2974_read_word_data(struct i2c_client *client, int page, int reg)
343
+static int ltc2974_read_word_data(struct i2c_client *client, int page,
344
+ int phase, int reg)
325345 {
326346 const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
327347 struct ltc2978_data *data = to_ltc2978_data(info);
....@@ -340,13 +360,14 @@
340360 ret = 0;
341361 break;
342362 default:
343
- ret = ltc2978_read_word_data(client, page, reg);
363
+ ret = ltc2978_read_word_data(client, page, phase, reg);
344364 break;
345365 }
346366 return ret;
347367 }
348368
349
-static int ltc2975_read_word_data(struct i2c_client *client, int page, int reg)
369
+static int ltc2975_read_word_data(struct i2c_client *client, int page,
370
+ int phase, int reg)
350371 {
351372 const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
352373 struct ltc2978_data *data = to_ltc2978_data(info);
....@@ -374,13 +395,14 @@
374395 ret = 0;
375396 break;
376397 default:
377
- ret = ltc2978_read_word_data(client, page, reg);
398
+ ret = ltc2978_read_word_data(client, page, phase, reg);
378399 break;
379400 }
380401 return ret;
381402 }
382403
383
-static int ltc3880_read_word_data(struct i2c_client *client, int page, int reg)
404
+static int ltc3880_read_word_data(struct i2c_client *client, int page,
405
+ int phase, int reg)
384406 {
385407 const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
386408 struct ltc2978_data *data = to_ltc2978_data(info);
....@@ -412,7 +434,8 @@
412434 return ret;
413435 }
414436
415
-static int ltc3883_read_word_data(struct i2c_client *client, int page, int reg)
437
+static int ltc3883_read_word_data(struct i2c_client *client, int page,
438
+ int phase, int reg)
416439 {
417440 const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
418441 struct ltc2978_data *data = to_ltc2978_data(info);
....@@ -427,7 +450,7 @@
427450 ret = 0;
428451 break;
429452 default:
430
- ret = ltc3880_read_word_data(client, page, reg);
453
+ ret = ltc3880_read_word_data(client, page, phase, reg);
431454 break;
432455 }
433456 return ret;
....@@ -499,19 +522,30 @@
499522 }
500523
501524 static const struct i2c_device_id ltc2978_id[] = {
525
+ {"ltc2972", ltc2972},
502526 {"ltc2974", ltc2974},
503527 {"ltc2975", ltc2975},
504528 {"ltc2977", ltc2977},
505529 {"ltc2978", ltc2978},
530
+ {"ltc2979", ltc2979},
506531 {"ltc2980", ltc2980},
507532 {"ltc3880", ltc3880},
508533 {"ltc3882", ltc3882},
509534 {"ltc3883", ltc3883},
535
+ {"ltc3884", ltc3884},
510536 {"ltc3886", ltc3886},
511537 {"ltc3887", ltc3887},
538
+ {"ltc3889", ltc3889},
539
+ {"ltc7880", ltc7880},
512540 {"ltm2987", ltm2987},
541
+ {"ltm4664", ltm4664},
513542 {"ltm4675", ltm4675},
514543 {"ltm4676", ltm4676},
544
+ {"ltm4677", ltm4677},
545
+ {"ltm4678", ltm4678},
546
+ {"ltm4680", ltm4680},
547
+ {"ltm4686", ltm4686},
548
+ {"ltm4700", ltm4700},
515549 {}
516550 };
517551 MODULE_DEVICE_TABLE(i2c, ltc2978_id);
....@@ -561,7 +595,9 @@
561595
562596 chip_id &= LTC2978_ID_MASK;
563597
564
- if (chip_id == LTC2974_ID)
598
+ if (chip_id == LTC2972_ID)
599
+ return ltc2972;
600
+ else if (chip_id == LTC2974_ID)
565601 return ltc2974;
566602 else if (chip_id == LTC2975_ID)
567603 return ltc2975;
....@@ -569,6 +605,8 @@
569605 return ltc2977;
570606 else if (chip_id == LTC2978_ID_REV1 || chip_id == LTC2978_ID_REV2)
571607 return ltc2978;
608
+ else if (chip_id == LTC2979_ID_A || chip_id == LTC2979_ID_B)
609
+ return ltc2979;
572610 else if (chip_id == LTC2980_ID_A || chip_id == LTC2980_ID_B)
573611 return ltc2980;
574612 else if (chip_id == LTC3880_ID)
....@@ -577,28 +615,46 @@
577615 return ltc3882;
578616 else if (chip_id == LTC3883_ID)
579617 return ltc3883;
618
+ else if (chip_id == LTC3884_ID)
619
+ return ltc3884;
580620 else if (chip_id == LTC3886_ID)
581621 return ltc3886;
582622 else if (chip_id == LTC3887_ID)
583623 return ltc3887;
624
+ else if (chip_id == LTC3889_ID)
625
+ return ltc3889;
626
+ else if (chip_id == LTC7880_ID)
627
+ return ltc7880;
584628 else if (chip_id == LTM2987_ID_A || chip_id == LTM2987_ID_B)
585629 return ltm2987;
630
+ else if (chip_id == LTM4664_ID)
631
+ return ltm4664;
586632 else if (chip_id == LTM4675_ID)
587633 return ltm4675;
588634 else if (chip_id == LTM4676_ID_REV1 || chip_id == LTM4676_ID_REV2 ||
589635 chip_id == LTM4676A_ID)
590636 return ltm4676;
637
+ else if (chip_id == LTM4677_ID_REV1 || chip_id == LTM4677_ID_REV2)
638
+ return ltm4677;
639
+ else if (chip_id == LTM4678_ID_REV1 || chip_id == LTM4678_ID_REV2)
640
+ return ltm4678;
641
+ else if (chip_id == LTM4680_ID)
642
+ return ltm4680;
643
+ else if (chip_id == LTM4686_ID)
644
+ return ltm4686;
645
+ else if (chip_id == LTM4700_ID)
646
+ return ltm4700;
591647
592648 dev_err(&client->dev, "Unsupported chip ID 0x%x\n", chip_id);
593649 return -ENODEV;
594650 }
595651
596
-static int ltc2978_probe(struct i2c_client *client,
597
- const struct i2c_device_id *id)
652
+static int ltc2978_probe(struct i2c_client *client)
598653 {
599654 int i, chip_id;
600655 struct ltc2978_data *data;
601656 struct pmbus_driver_info *info;
657
+ const struct i2c_device_id *id;
602658
603659 if (!i2c_check_functionality(client->adapter,
604660 I2C_FUNC_SMBUS_READ_WORD_DATA))
....@@ -614,11 +670,13 @@
614670 return chip_id;
615671
616672 data->id = chip_id;
673
+ id = i2c_match_id(ltc2978_id, client);
617674 if (data->id != id->driver_data)
618675 dev_warn(&client->dev,
619
- "Device mismatch: Configured %s, detected %s\n",
676
+ "Device mismatch: Configured %s (%d), detected %d\n",
620677 id->name,
621
- ltc2978_id[data->id].name);
678
+ (int) id->driver_data,
679
+ chip_id);
622680
623681 info = &data->info;
624682 info->write_word_data = ltc2978_write_word_data;
....@@ -641,6 +699,19 @@
641699 data->temp2_max = 0x7c00;
642700
643701 switch (data->id) {
702
+ case ltc2972:
703
+ info->read_word_data = ltc2975_read_word_data;
704
+ info->pages = LTC2972_NUM_PAGES;
705
+ info->func[0] = PMBUS_HAVE_IIN | PMBUS_HAVE_PIN
706
+ | PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT
707
+ | PMBUS_HAVE_TEMP2;
708
+ for (i = 0; i < info->pages; i++) {
709
+ info->func[i] |= PMBUS_HAVE_VOUT
710
+ | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_POUT
711
+ | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP
712
+ | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT;
713
+ }
714
+ break;
644715 case ltc2974:
645716 info->read_word_data = ltc2974_read_word_data;
646717 info->pages = LTC2974_NUM_PAGES;
....@@ -666,8 +737,10 @@
666737 | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT;
667738 }
668739 break;
740
+
669741 case ltc2977:
670742 case ltc2978:
743
+ case ltc2979:
671744 case ltc2980:
672745 case ltm2987:
673746 info->read_word_data = ltc2978_read_word_data;
....@@ -684,6 +757,8 @@
684757 case ltc3887:
685758 case ltm4675:
686759 case ltm4676:
760
+ case ltm4677:
761
+ case ltm4686:
687762 data->features |= FEAT_CLEAR_PEAKS | FEAT_NEEDS_POLLING;
688763 info->read_word_data = ltc3880_read_word_data;
689764 info->pages = LTC3880_NUM_PAGES;
....@@ -724,7 +799,14 @@
724799 | PMBUS_HAVE_PIN | PMBUS_HAVE_POUT | PMBUS_HAVE_TEMP
725800 | PMBUS_HAVE_TEMP2 | PMBUS_HAVE_STATUS_TEMP;
726801 break;
802
+ case ltc3884:
727803 case ltc3886:
804
+ case ltc3889:
805
+ case ltc7880:
806
+ case ltm4664:
807
+ case ltm4678:
808
+ case ltm4680:
809
+ case ltm4700:
728810 data->features |= FEAT_CLEAR_PEAKS | FEAT_NEEDS_POLLING;
729811 info->read_word_data = ltc3883_read_word_data;
730812 info->pages = LTC3880_NUM_PAGES;
....@@ -752,24 +834,36 @@
752834 }
753835 #endif
754836
755
- return pmbus_do_probe(client, id, info);
837
+ return pmbus_do_probe(client, info);
756838 }
839
+
757840
758841 #ifdef CONFIG_OF
759842 static const struct of_device_id ltc2978_of_match[] = {
843
+ { .compatible = "lltc,ltc2972" },
760844 { .compatible = "lltc,ltc2974" },
761845 { .compatible = "lltc,ltc2975" },
762846 { .compatible = "lltc,ltc2977" },
763847 { .compatible = "lltc,ltc2978" },
848
+ { .compatible = "lltc,ltc2979" },
764849 { .compatible = "lltc,ltc2980" },
765850 { .compatible = "lltc,ltc3880" },
766851 { .compatible = "lltc,ltc3882" },
767852 { .compatible = "lltc,ltc3883" },
853
+ { .compatible = "lltc,ltc3884" },
768854 { .compatible = "lltc,ltc3886" },
769855 { .compatible = "lltc,ltc3887" },
856
+ { .compatible = "lltc,ltc3889" },
857
+ { .compatible = "lltc,ltc7880" },
770858 { .compatible = "lltc,ltm2987" },
859
+ { .compatible = "lltc,ltm4664" },
771860 { .compatible = "lltc,ltm4675" },
772861 { .compatible = "lltc,ltm4676" },
862
+ { .compatible = "lltc,ltm4677" },
863
+ { .compatible = "lltc,ltm4678" },
864
+ { .compatible = "lltc,ltm4680" },
865
+ { .compatible = "lltc,ltm4686" },
866
+ { .compatible = "lltc,ltm4700" },
773867 { }
774868 };
775869 MODULE_DEVICE_TABLE(of, ltc2978_of_match);
....@@ -780,7 +874,7 @@
780874 .name = "ltc2978",
781875 .of_match_table = of_match_ptr(ltc2978_of_match),
782876 },
783
- .probe = ltc2978_probe,
877
+ .probe_new = ltc2978_probe,
784878 .remove = pmbus_do_remove,
785879 .id_table = ltc2978_id,
786880 };
....@@ -788,5 +882,5 @@
788882 module_i2c_driver(ltc2978_driver);
789883
790884 MODULE_AUTHOR("Guenter Roeck");
791
-MODULE_DESCRIPTION("PMBus driver for LTC2978 and comppatible chips");
885
+MODULE_DESCRIPTION("PMBus driver for LTC2978 and compatible chips");
792886 MODULE_LICENSE("GPL");