hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/hwmon/pmbus/adm1275.c
....@@ -37,9 +37,12 @@
3737
3838 #define ADM1272_IRANGE BIT(0)
3939
40
+#define ADM1278_TSFILT BIT(15)
4041 #define ADM1278_TEMP1_EN BIT(3)
4142 #define ADM1278_VIN_EN BIT(2)
4243 #define ADM1278_VOUT_EN BIT(1)
44
+
45
+#define ADM1278_PMON_DEFCONFIG (ADM1278_VOUT_EN | ADM1278_TEMP1_EN | ADM1278_TSFILT)
4346
4447 #define ADM1293_IRANGE_25 0
4548 #define ADM1293_IRANGE_50 BIT(6)
....@@ -462,6 +465,22 @@
462465 };
463466 MODULE_DEVICE_TABLE(i2c, adm1275_id);
464467
468
+/* Enable VOUT & TEMP1 if not enabled (disabled by default) */
469
+static int adm1275_enable_vout_temp(struct i2c_client *client, int config)
470
+{
471
+ int ret;
472
+
473
+ if ((config & ADM1278_PMON_DEFCONFIG) != ADM1278_PMON_DEFCONFIG) {
474
+ config |= ADM1278_PMON_DEFCONFIG;
475
+ ret = i2c_smbus_write_word_data(client, ADM1275_PMON_CONFIG, config);
476
+ if (ret < 0) {
477
+ dev_err(&client->dev, "Failed to enable VOUT/TEMP1 monitoring\n");
478
+ return ret;
479
+ }
480
+ }
481
+ return 0;
482
+}
483
+
465484 static int adm1275_probe(struct i2c_client *client)
466485 {
467486 s32 (*config_read_fn)(const struct i2c_client *client, u8 reg);
....@@ -475,6 +494,7 @@
475494 int vindex = -1, voindex = -1, cindex = -1, pindex = -1;
476495 int tindex = -1;
477496 u32 shunt;
497
+ u32 avg;
478498
479499 if (!i2c_check_functionality(client->adapter,
480500 I2C_FUNC_SMBUS_READ_BYTE_DATA
....@@ -611,24 +631,13 @@
611631 tindex = 8;
612632
613633 info->func[0] |= PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT |
614
- PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT;
634
+ PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
635
+ PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP;
615636
616
- /* Enable VOUT if not enabled (it is disabled by default) */
617
- if (!(config & ADM1278_VOUT_EN)) {
618
- config |= ADM1278_VOUT_EN;
619
- ret = i2c_smbus_write_byte_data(client,
620
- ADM1275_PMON_CONFIG,
621
- config);
622
- if (ret < 0) {
623
- dev_err(&client->dev,
624
- "Failed to enable VOUT monitoring\n");
625
- return -ENODEV;
626
- }
627
- }
637
+ ret = adm1275_enable_vout_temp(client, config);
638
+ if (ret)
639
+ return ret;
628640
629
- if (config & ADM1278_TEMP1_EN)
630
- info->func[0] |=
631
- PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP;
632641 if (config & ADM1278_VIN_EN)
633642 info->func[0] |= PMBUS_HAVE_VIN;
634643 break;
....@@ -685,19 +694,9 @@
685694 PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
686695 PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP;
687696
688
- /* Enable VOUT & TEMP1 if not enabled (disabled by default) */
689
- if ((config & (ADM1278_VOUT_EN | ADM1278_TEMP1_EN)) !=
690
- (ADM1278_VOUT_EN | ADM1278_TEMP1_EN)) {
691
- config |= ADM1278_VOUT_EN | ADM1278_TEMP1_EN;
692
- ret = i2c_smbus_write_byte_data(client,
693
- ADM1275_PMON_CONFIG,
694
- config);
695
- if (ret < 0) {
696
- dev_err(&client->dev,
697
- "Failed to enable VOUT monitoring\n");
698
- return -ENODEV;
699
- }
700
- }
697
+ ret = adm1275_enable_vout_temp(client, config);
698
+ if (ret)
699
+ return ret;
701700
702701 if (config & ADM1278_VIN_EN)
703702 info->func[0] |= PMBUS_HAVE_VIN;
....@@ -758,6 +757,43 @@
758757 return -ENODEV;
759758 }
760759
760
+ if (data->have_power_sampling &&
761
+ of_property_read_u32(client->dev.of_node,
762
+ "adi,power-sample-average", &avg) == 0) {
763
+ if (!avg || avg > ADM1275_SAMPLES_AVG_MAX ||
764
+ BIT(__fls(avg)) != avg) {
765
+ dev_err(&client->dev,
766
+ "Invalid number of power samples");
767
+ return -EINVAL;
768
+ }
769
+ ret = adm1275_write_pmon_config(data, client, true,
770
+ ilog2(avg));
771
+ if (ret < 0) {
772
+ dev_err(&client->dev,
773
+ "Setting power sample averaging failed with error %d",
774
+ ret);
775
+ return ret;
776
+ }
777
+ }
778
+
779
+ if (of_property_read_u32(client->dev.of_node,
780
+ "adi,volt-curr-sample-average", &avg) == 0) {
781
+ if (!avg || avg > ADM1275_SAMPLES_AVG_MAX ||
782
+ BIT(__fls(avg)) != avg) {
783
+ dev_err(&client->dev,
784
+ "Invalid number of voltage/current samples");
785
+ return -EINVAL;
786
+ }
787
+ ret = adm1275_write_pmon_config(data, client, false,
788
+ ilog2(avg));
789
+ if (ret < 0) {
790
+ dev_err(&client->dev,
791
+ "Setting voltage and current sample averaging failed with error %d",
792
+ ret);
793
+ return ret;
794
+ }
795
+ }
796
+
761797 if (voindex < 0)
762798 voindex = vindex;
763799 if (vindex >= 0) {