.. | .. |
---|
37 | 37 | |
---|
38 | 38 | #define ADM1272_IRANGE BIT(0) |
---|
39 | 39 | |
---|
| 40 | +#define ADM1278_TSFILT BIT(15) |
---|
40 | 41 | #define ADM1278_TEMP1_EN BIT(3) |
---|
41 | 42 | #define ADM1278_VIN_EN BIT(2) |
---|
42 | 43 | #define ADM1278_VOUT_EN BIT(1) |
---|
| 44 | + |
---|
| 45 | +#define ADM1278_PMON_DEFCONFIG (ADM1278_VOUT_EN | ADM1278_TEMP1_EN | ADM1278_TSFILT) |
---|
43 | 46 | |
---|
44 | 47 | #define ADM1293_IRANGE_25 0 |
---|
45 | 48 | #define ADM1293_IRANGE_50 BIT(6) |
---|
.. | .. |
---|
462 | 465 | }; |
---|
463 | 466 | MODULE_DEVICE_TABLE(i2c, adm1275_id); |
---|
464 | 467 | |
---|
| 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 | + |
---|
465 | 484 | static int adm1275_probe(struct i2c_client *client) |
---|
466 | 485 | { |
---|
467 | 486 | s32 (*config_read_fn)(const struct i2c_client *client, u8 reg); |
---|
.. | .. |
---|
475 | 494 | int vindex = -1, voindex = -1, cindex = -1, pindex = -1; |
---|
476 | 495 | int tindex = -1; |
---|
477 | 496 | u32 shunt; |
---|
| 497 | + u32 avg; |
---|
478 | 498 | |
---|
479 | 499 | if (!i2c_check_functionality(client->adapter, |
---|
480 | 500 | I2C_FUNC_SMBUS_READ_BYTE_DATA |
---|
.. | .. |
---|
611 | 631 | tindex = 8; |
---|
612 | 632 | |
---|
613 | 633 | 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; |
---|
615 | 636 | |
---|
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; |
---|
628 | 640 | |
---|
629 | | - if (config & ADM1278_TEMP1_EN) |
---|
630 | | - info->func[0] |= |
---|
631 | | - PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP; |
---|
632 | 641 | if (config & ADM1278_VIN_EN) |
---|
633 | 642 | info->func[0] |= PMBUS_HAVE_VIN; |
---|
634 | 643 | break; |
---|
.. | .. |
---|
685 | 694 | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | |
---|
686 | 695 | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP; |
---|
687 | 696 | |
---|
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; |
---|
701 | 700 | |
---|
702 | 701 | if (config & ADM1278_VIN_EN) |
---|
703 | 702 | info->func[0] |= PMBUS_HAVE_VIN; |
---|
.. | .. |
---|
758 | 757 | return -ENODEV; |
---|
759 | 758 | } |
---|
760 | 759 | |
---|
| 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 | + |
---|
761 | 797 | if (voindex < 0) |
---|
762 | 798 | voindex = vindex; |
---|
763 | 799 | if (vindex >= 0) { |
---|