Add thermal sensor configuration code for Amber-Lite NICs.
Due to differences in hardware design, Amber-Lite NICs require
different configuration from Sapphire NICs to initialize and
retrieve thermal sensor data.

Signed-off-by: Zaiyu Wang <[email protected]>
---
 drivers/net/txgbe/base/txgbe_hw.c   | 81 ++++++++++++++++++++++-------
 drivers/net/txgbe/base/txgbe_type.h | 27 ++++++++++
 2 files changed, 90 insertions(+), 18 deletions(-)

diff --git a/drivers/net/txgbe/base/txgbe_hw.c 
b/drivers/net/txgbe/base/txgbe_hw.c
index 3cbb21a686..5017886896 100644
--- a/drivers/net/txgbe/base/txgbe_hw.c
+++ b/drivers/net/txgbe/base/txgbe_hw.c
@@ -2220,27 +2220,56 @@ void txgbe_clear_tx_pending(struct txgbe_hw *hw)
  *
  *  Returns the thermal sensor data structure
  **/
+#define PHYINIT_TIMEOUT 1000
 s32 txgbe_get_thermal_sensor_data(struct txgbe_hw *hw)
 {
        struct txgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
        s64 tsv;
        u32 ts_stat;
+       u32 data_code;
+       int temp_data, temp_fraction;
+       int i = 0;
 
        /* Only support thermal sensors attached to physical port 0 */
        if (hw->bus.lan_id != 0)
                return TXGBE_NOT_IMPLEMENTED;
 
-       ts_stat = rd32(hw, TXGBE_TSSTAT);
-       tsv = (s64)TXGBE_TSSTAT_DATA(ts_stat);
-       tsv = tsv > 1200 ? tsv : 1200;
-       tsv = -(48380 << 8) / 1000
-               + tsv * (31020 << 8) / 100000
-               - tsv * tsv * (18201 << 8) / 100000000
-               + tsv * tsv * tsv * (81542 << 8) / 1000000000000
-               - tsv * tsv * tsv * tsv * (16743 << 8) / 1000000000000000;
-       tsv >>= 8;
+       if (hw->mac.type == txgbe_mac_aml || hw->mac.type == txgbe_mac_aml40) {
+               wr32(hw, TXGBE_AML_TS_ENA, 0x0001);
+
+               while (1) {
+                       data_code = rd32(hw, TXGBE_AML_TS_STS);
+                       if ((data_code & TXGBE_AML_TS_STS_VLD) != 0)
+                               break;
+                       msleep(1);
+                       if (i++ > PHYINIT_TIMEOUT) {
+                               PMD_DRV_LOG(ERR, "ERROR: Wait 0x1033c 
Timeout!!!");
+                               return -1;
+                       }
+               }
+
+               data_code = data_code & 0xFFF;
+               temp_data = 419400 + 2205 * (data_code * 1000 / 4094 - 500);
 
-       data->sensor[0].temp = (s16)tsv;
+               /* Change double Temperature to int */
+               tsv = temp_data / 10000;
+               temp_fraction = temp_data - (tsv * 10000);
+               if (temp_fraction >= 5000)
+                       tsv += 1;
+               data->sensor[0].temp = (s16)tsv;
+       } else {
+               ts_stat = rd32(hw, TXGBE_TSSTAT);
+               tsv = (s64)TXGBE_TSSTAT_DATA(ts_stat);
+               tsv = tsv > 1200 ? tsv : 1200;
+               tsv = -(48380 << 8) / 1000
+                       + tsv * (31020 << 8) / 100000
+                       - tsv * tsv * (18201 << 8) / 100000000
+                       + tsv * tsv * tsv * (81542 << 8) / 1000000000000
+                       - tsv * tsv * tsv * tsv * (16743 << 8) / 
1000000000000000;
+               tsv >>= 8;
+
+               data->sensor[0].temp = (s16)tsv;
+       }
 
        return 0;
 }
@@ -2261,16 +2290,32 @@ s32 txgbe_init_thermal_sensor_thresh(struct txgbe_hw 
*hw)
        if (hw->bus.lan_id != 0)
                return TXGBE_NOT_IMPLEMENTED;
 
-       wr32(hw, TXGBE_TSCTRL, TXGBE_TSCTRL_EVALMD);
-       wr32(hw, TXGBE_TSINTR,
-               TXGBE_TSINTR_AEN | TXGBE_TSINTR_DEN);
-       wr32(hw, TXGBE_TSEN, TXGBE_TSEN_ENA);
-
-
        data->sensor[0].alarm_thresh = 100;
-       wr32(hw, TXGBE_TSATHRE, 677);
        data->sensor[0].dalarm_thresh = 90;
-       wr32(hw, TXGBE_TSDTHRE, 614);
+
+       if (hw->mac.type == txgbe_mac_aml || hw->mac.type == txgbe_mac_aml40) {
+               wr32(hw, TXGBE_AML_TS_ENA, 0x0);
+               wr32(hw, TXGBE_AML_INTR_RAW_LO, TXGBE_AML_INTR_CL_LO);
+               wr32(hw, TXGBE_AML_INTR_RAW_HI, TXGBE_AML_INTR_CL_HI);
+
+               wr32(hw, TXGBE_AML_INTR_HIGH_EN, TXGBE_AML_INTR_EN_HI);
+               wr32(hw, TXGBE_AML_INTR_LOW_EN, TXGBE_AML_INTR_EN_LO);
+
+               wr32m(hw, TXGBE_AML_TS_CTL1, TXGBE_AML_EVAL_MODE_MASK, 0x10);
+               wr32m(hw, TXGBE_AML_TS_CTL1, TXGBE_AML_ALARM_THRE_MASK, 
0x186a0000);
+               wr32m(hw, TXGBE_AML_TS_CTL1, TXGBE_AML_DALARM_THRE_MASK, 
0x16f60);
+               wr32(hw, TXGBE_AML_TS_ENA, 0x1);
+       } else {
+               wr32(hw, TXGBE_TSCTRL, TXGBE_TSCTRL_EVALMD);
+               wr32(hw, TXGBE_TSINTR,
+                        TXGBE_TSINTR_AEN | TXGBE_TSINTR_DEN);
+               wr32(hw, TXGBE_TSEN, TXGBE_TSEN_ENA);
+
+               data->sensor[0].alarm_thresh = 100;
+               wr32(hw, TXGBE_TSATHRE, 677);
+               data->sensor[0].dalarm_thresh = 90;
+               wr32(hw, TXGBE_TSDTHRE, 614);
+       }
 
        return 0;
 }
diff --git a/drivers/net/txgbe/base/txgbe_type.h 
b/drivers/net/txgbe/base/txgbe_type.h
index c5f51b3ade..07b443c2e0 100644
--- a/drivers/net/txgbe/base/txgbe_type.h
+++ b/drivers/net/txgbe/base/txgbe_type.h
@@ -37,6 +37,33 @@
 #include "txgbe_osdep.h"
 #include "txgbe_devids.h"
 
+/* Sensors for AMLITE PVT(Process Voltage Temperature) */
+#define TXGBE_AML_INTR_RAW_HI           0x10300
+#define TXGBE_AML_INTR_RAW_ME           0x10304
+#define TXGBE_AML_INTR_RAW_LO           0x10308
+#define TXGBE_AML_TS_CTL1               0x10330
+#define TXGBE_AML_TS_CTL2               0x10334
+#define TXGBE_AML_TS_ENA                0x10338
+#define TXGBE_AML_TS_STS                0x1033C
+#define TXGBE_AML_INTR_HIGH_EN          0x10318
+#define TXGBE_AML_INTR_MED_EN           0x1031C
+#define TXGBE_AML_INTR_LOW_EN           0x10320
+#define TXGBE_AML_INTR_HIGH_STS         0x1030C
+#define TXGBE_AML_INTR_MED_STS          0x10310
+#define TXGBE_AML_INTR_LOW_STS          0x10314
+
+#define TXGBE_AML_TS_STS_VLD            0x00001000U
+#define TXGBE_AML_INTR_EN_HI            0x00000002U
+#define TXGBE_AML_INTR_EN_ME            0x00000001U
+#define TXGBE_AML_INTR_EN_LO            0x00000001U
+#define TXGBE_AML_INTR_CL_HI            0x00000002U
+#define TXGBE_AML_INTR_CL_ME            0x00000001U
+#define TXGBE_AML_INTR_CL_LO            0x00000001U
+#define TXGBE_AML_EVAL_MODE_MASK        0x00000010U
+#define TXGBE_AML_CAL_MODE_MASK         0x00000008U
+#define TXGBE_AML_ALARM_THRE_MASK       0x1FFE0000U
+#define TXGBE_AML_DALARM_THRE_MASK      0x0001FFE0U
+
 struct txgbe_thermal_diode_data {
        s16 temp;
        s16 alarm_thresh;
-- 
2.21.0.windows.1

Reply via email to