+static bool ufs_temp_enabled(struct ufs_hba *hba, struct ufs_hwmon_data *data)
+{
+ u32 ee_mask;
+
+ if (ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR,
+ QUERY_ATTR_IDN_EE_CONTROL, 0, 0, &ee_mask))
+ return false;
+
+ return (data->mask & ee_mask & MASK_EE_TOO_HIGH_TEMP) ||
+ (data->mask & ee_mask & MASK_EE_TOO_LOW_TEMP);
+}
+static bool ufs_temp_valid(struct ufs_hba *hba, struct ufs_hwmon_data *data,
+ enum attr_idn idn, u32 value)
+{
+ return (idn == QUERY_ATTR_IDN_CASE_ROUGH_TEMP && value >= 1 &&
+ value <= 250 && ufs_temp_enabled(hba, data)) ||
+ (idn == QUERY_ATTR_IDN_HIGH_TEMP_BOUND && value >= 100 &&
+ value <= 250) ||
+ (idn == QUERY_ATTR_IDN_LOW_TEMP_BOUND && value >= 1 &&
+ value <= 80);
+}
+static int ufs_get_temp(struct ufs_hba *hba, struct ufs_hwmon_data *data,
+ enum attr_idn idn)
+{
+ u32 value;
+
+ if (ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR, idn, 0, 0,
+ &value))
+ return 0;
+
+ if (ufs_temp_valid(hba, data, idn, value))
+ return value - 80;
+
+ return 0;
+}
+void ufs_hwmon_remove(struct ufs_hba *hba)
+{
+ if (hba->hwmon_device) {
+ struct ufs_hwmon_data *data =
+ dev_get_drvdata(hba->hwmon_device);
+
+ hwmon_device_unregister(hba->hwmon_device);
+ hba->hwmon_device = NULL;
+ kfree(data);
+ }
+}