Commit 9f15b43f authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

Merge Intel DTS IOSF thermal driver changes for 6.6-rc1.

These fix a few issues in the Intel DTS IOSF thermal driver, clean up
code in it and make it use trip point tables for registering thermal
zones.

* thermal-intel:
  thermal: intel: intel_soc_dts_iosf: Use struct thermal_trip
  thermal: intel: intel_soc_dts_iosf: Rework critical trip setup
  thermal: intel: intel_soc_dts_iosf: Add helper for resetting trip points
  thermal: intel: intel_soc_dts_iosf: Change initialization ordering
  thermal: intel: intel_soc_dts_iosf: Pass sensors to update_trip_temp()
  thermal: intel: intel_soc_dts_iosf: Untangle update_trip_temp()
  thermal: intel: intel_soc_dts_iosf: Always assume notification support
  thermal: intel: intel_soc_dts_iosf: Drop redundant symbol definition
  thermal: intel: intel_soc_dts_iosf: Always use 2 trips
parents f6a756e8 4effd28e
...@@ -59,7 +59,7 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev, ...@@ -59,7 +59,7 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev,
* ACPI/MSR. So we don't want to fail for auxiliary DTSs. * ACPI/MSR. So we don't want to fail for auxiliary DTSs.
*/ */
proc_priv->soc_dts = intel_soc_dts_iosf_init( proc_priv->soc_dts = intel_soc_dts_iosf_init(
INTEL_SOC_DTS_INTERRUPT_MSI, 2, 0); INTEL_SOC_DTS_INTERRUPT_MSI, false, 0);
if (!IS_ERR(proc_priv->soc_dts) && pdev->irq) { if (!IS_ERR(proc_priv->soc_dts) && pdev->irq) {
ret = pci_enable_msi(pdev); ret = pci_enable_msi(pdev);
......
...@@ -37,44 +37,11 @@ ...@@ -37,44 +37,11 @@
/* DTS encoding for TJ MAX temperature */ /* DTS encoding for TJ MAX temperature */
#define SOC_DTS_TJMAX_ENCODING 0x7F #define SOC_DTS_TJMAX_ENCODING 0x7F
/* Only 2 out of 4 is allowed for OSPM */
#define SOC_MAX_DTS_TRIPS 2
/* Mask for two trips in status bits */ /* Mask for two trips in status bits */
#define SOC_DTS_TRIP_MASK 0x03 #define SOC_DTS_TRIP_MASK 0x03
/* DTS0 and DTS 1 */ static int update_trip_temp(struct intel_soc_dts_sensors *sensors,
#define SOC_MAX_DTS_SENSORS 2 int thres_index, int temp)
static int sys_get_trip_temp(struct thermal_zone_device *tzd, int trip,
int *temp)
{
int status;
u32 out;
struct intel_soc_dts_sensor_entry *dts;
struct intel_soc_dts_sensors *sensors;
dts = thermal_zone_device_priv(tzd);
sensors = dts->sensors;
mutex_lock(&sensors->dts_update_lock);
status = iosf_mbi_read(BT_MBI_UNIT_PMC, MBI_REG_READ,
SOC_DTS_OFFSET_PTPS, &out);
mutex_unlock(&sensors->dts_update_lock);
if (status)
return status;
out = (out >> (trip * 8)) & SOC_DTS_TJMAX_ENCODING;
if (!out)
*temp = 0;
else
*temp = sensors->tj_max - out * 1000;
return 0;
}
static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts,
int thres_index, int temp,
enum thermal_trip_type trip_type)
{ {
int status; int status;
u32 temp_out; u32 temp_out;
...@@ -85,7 +52,6 @@ static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts, ...@@ -85,7 +52,6 @@ static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts,
u32 store_te_out; u32 store_te_out;
u32 te_out; u32 te_out;
u32 int_enable_bit = SOC_DTS_TE_APICA_ENABLE; u32 int_enable_bit = SOC_DTS_TE_APICA_ENABLE;
struct intel_soc_dts_sensors *sensors = dts->sensors;
if (sensors->intr_type == INTEL_SOC_DTS_INTERRUPT_MSI) if (sensors->intr_type == INTEL_SOC_DTS_INTERRUPT_MSI)
int_enable_bit |= SOC_DTS_TE_MSI_ENABLE; int_enable_bit |= SOC_DTS_TE_MSI_ENABLE;
...@@ -148,8 +114,6 @@ static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts, ...@@ -148,8 +114,6 @@ static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts,
if (status) if (status)
goto err_restore_te_out; goto err_restore_te_out;
dts->trip_types[thres_index] = trip_type;
return 0; return 0;
err_restore_te_out: err_restore_te_out:
iosf_mbi_write(BT_MBI_UNIT_PMC, MBI_REG_WRITE, iosf_mbi_write(BT_MBI_UNIT_PMC, MBI_REG_WRITE,
...@@ -165,6 +129,22 @@ static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts, ...@@ -165,6 +129,22 @@ static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts,
return status; return status;
} }
static int configure_trip(struct intel_soc_dts_sensor_entry *dts,
int thres_index, enum thermal_trip_type trip_type,
int temp)
{
int ret;
ret = update_trip_temp(dts->sensors, thres_index, temp);
if (ret)
return ret;
dts->trips[thres_index].temperature = temp;
dts->trips[thres_index].type = trip_type;
return 0;
}
static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip,
int temp) int temp)
{ {
...@@ -176,23 +156,12 @@ static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, ...@@ -176,23 +156,12 @@ static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip,
return -EINVAL; return -EINVAL;
mutex_lock(&sensors->dts_update_lock); mutex_lock(&sensors->dts_update_lock);
status = update_trip_temp(dts, trip, temp, status = update_trip_temp(sensors, trip, temp);
dts->trip_types[trip]);
mutex_unlock(&sensors->dts_update_lock); mutex_unlock(&sensors->dts_update_lock);
return status; return status;
} }
static int sys_get_trip_type(struct thermal_zone_device *tzd,
int trip, enum thermal_trip_type *type)
{
struct intel_soc_dts_sensor_entry *dts = thermal_zone_device_priv(tzd);
*type = dts->trip_types[trip];
return 0;
}
static int sys_get_curr_temp(struct thermal_zone_device *tzd, static int sys_get_curr_temp(struct thermal_zone_device *tzd,
int *temp) int *temp)
{ {
...@@ -217,8 +186,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, ...@@ -217,8 +186,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd,
static struct thermal_zone_device_ops tzone_ops = { static struct thermal_zone_device_ops tzone_ops = {
.get_temp = sys_get_curr_temp, .get_temp = sys_get_curr_temp,
.get_trip_temp = sys_get_trip_temp,
.get_trip_type = sys_get_trip_type,
.set_trip_temp = sys_set_trip_temp, .set_trip_temp = sys_set_trip_temp,
}; };
...@@ -253,14 +220,12 @@ static void remove_dts_thermal_zone(struct intel_soc_dts_sensor_entry *dts) ...@@ -253,14 +220,12 @@ static void remove_dts_thermal_zone(struct intel_soc_dts_sensor_entry *dts)
} }
static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts,
bool notification_support, int trip_cnt, bool critical_trip)
int read_only_trip_cnt)
{ {
int writable_trip_cnt = SOC_MAX_DTS_TRIPS;
char name[10]; char name[10];
unsigned long trip; unsigned long trip;
int trip_count = 0; int trip_mask;
int trip_mask = 0;
int writable_trip_cnt = 0;
unsigned long ptps; unsigned long ptps;
u32 store_ptps; u32 store_ptps;
unsigned long i; unsigned long i;
...@@ -273,11 +238,11 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, ...@@ -273,11 +238,11 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts,
goto err_ret; goto err_ret;
dts->id = id; dts->id = id;
if (notification_support) {
trip_count = min(SOC_MAX_DTS_TRIPS, trip_cnt); if (critical_trip)
writable_trip_cnt = trip_count - read_only_trip_cnt; writable_trip_cnt--;
trip_mask = GENMASK(writable_trip_cnt - 1, 0);
} trip_mask = GENMASK(writable_trip_cnt - 1, 0);
/* Check if the writable trip we provide is not used by BIOS */ /* Check if the writable trip we provide is not used by BIOS */
ret = iosf_mbi_read(BT_MBI_UNIT_PMC, MBI_REG_READ, ret = iosf_mbi_read(BT_MBI_UNIT_PMC, MBI_REG_READ,
...@@ -290,13 +255,12 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, ...@@ -290,13 +255,12 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts,
trip_mask &= ~BIT(i / 8); trip_mask &= ~BIT(i / 8);
} }
dts->trip_mask = trip_mask; dts->trip_mask = trip_mask;
dts->trip_count = trip_count;
snprintf(name, sizeof(name), "soc_dts%d", id); snprintf(name, sizeof(name), "soc_dts%d", id);
dts->tzone = thermal_zone_device_register(name, dts->tzone = thermal_zone_device_register_with_trips(name, dts->trips,
trip_count, SOC_MAX_DTS_TRIPS,
trip_mask, trip_mask,
dts, &tzone_ops, dts, &tzone_ops,
NULL, 0, 0); NULL, 0, 0);
if (IS_ERR(dts->tzone)) { if (IS_ERR(dts->tzone)) {
ret = PTR_ERR(dts->tzone); ret = PTR_ERR(dts->tzone);
goto err_ret; goto err_ret;
...@@ -316,26 +280,6 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, ...@@ -316,26 +280,6 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts,
return ret; return ret;
} }
int intel_soc_dts_iosf_add_read_only_critical_trip(
struct intel_soc_dts_sensors *sensors, int critical_offset)
{
int i, j;
for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) {
struct intel_soc_dts_sensor_entry *entry = &sensors->soc_dts[i];
int temp = sensors->tj_max - critical_offset;
unsigned long count = entry->trip_count;
unsigned long mask = entry->trip_mask;
j = find_first_zero_bit(&mask, count);
if (j < count)
return update_trip_temp(entry, j, temp, THERMAL_TRIP_CRITICAL);
}
return -EINVAL;
}
EXPORT_SYMBOL_GPL(intel_soc_dts_iosf_add_read_only_critical_trip);
void intel_soc_dts_iosf_interrupt_handler(struct intel_soc_dts_sensors *sensors) void intel_soc_dts_iosf_interrupt_handler(struct intel_soc_dts_sensors *sensors)
{ {
u32 sticky_out; u32 sticky_out;
...@@ -371,12 +315,17 @@ void intel_soc_dts_iosf_interrupt_handler(struct intel_soc_dts_sensors *sensors) ...@@ -371,12 +315,17 @@ void intel_soc_dts_iosf_interrupt_handler(struct intel_soc_dts_sensors *sensors)
} }
EXPORT_SYMBOL_GPL(intel_soc_dts_iosf_interrupt_handler); EXPORT_SYMBOL_GPL(intel_soc_dts_iosf_interrupt_handler);
struct intel_soc_dts_sensors *intel_soc_dts_iosf_init( static void dts_trips_reset(struct intel_soc_dts_sensors *sensors, int dts_index)
enum intel_soc_dts_interrupt_type intr_type, int trip_count, {
int read_only_trip_count) configure_trip(&sensors->soc_dts[dts_index], 0, 0, 0);
configure_trip(&sensors->soc_dts[dts_index], 1, 0, 0);
}
struct intel_soc_dts_sensors *
intel_soc_dts_iosf_init(enum intel_soc_dts_interrupt_type intr_type,
bool critical_trip, int crit_offset)
{ {
struct intel_soc_dts_sensors *sensors; struct intel_soc_dts_sensors *sensors;
bool notification;
int tj_max; int tj_max;
int ret; int ret;
int i; int i;
...@@ -384,9 +333,6 @@ struct intel_soc_dts_sensors *intel_soc_dts_iosf_init( ...@@ -384,9 +333,6 @@ struct intel_soc_dts_sensors *intel_soc_dts_iosf_init(
if (!iosf_mbi_available()) if (!iosf_mbi_available())
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
if (!trip_count || read_only_trip_count > trip_count)
return ERR_PTR(-EINVAL);
tj_max = intel_tcc_get_tjmax(-1); tj_max = intel_tcc_get_tjmax(-1);
if (tj_max < 0) if (tj_max < 0)
return ERR_PTR(tj_max); return ERR_PTR(tj_max);
...@@ -399,37 +345,46 @@ struct intel_soc_dts_sensors *intel_soc_dts_iosf_init( ...@@ -399,37 +345,46 @@ struct intel_soc_dts_sensors *intel_soc_dts_iosf_init(
mutex_init(&sensors->dts_update_lock); mutex_init(&sensors->dts_update_lock);
sensors->intr_type = intr_type; sensors->intr_type = intr_type;
sensors->tj_max = tj_max * 1000; sensors->tj_max = tj_max * 1000;
if (intr_type == INTEL_SOC_DTS_INTERRUPT_NONE)
notification = false;
else
notification = true;
for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) { for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) {
enum thermal_trip_type trip_type;
int temp;
sensors->soc_dts[i].sensors = sensors; sensors->soc_dts[i].sensors = sensors;
ret = add_dts_thermal_zone(i, &sensors->soc_dts[i],
notification, trip_count, ret = configure_trip(&sensors->soc_dts[i], 0,
read_only_trip_count); THERMAL_TRIP_PASSIVE, 0);
if (ret) if (ret)
goto err_free; goto err_reset_trips;
if (critical_trip) {
trip_type = THERMAL_TRIP_CRITICAL;
temp = sensors->tj_max - crit_offset;
} else {
trip_type = THERMAL_TRIP_PASSIVE;
temp = 0;
}
ret = configure_trip(&sensors->soc_dts[i], 1, trip_type, temp);
if (ret)
goto err_reset_trips;
} }
for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) { for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) {
ret = update_trip_temp(&sensors->soc_dts[i], 0, 0, ret = add_dts_thermal_zone(i, &sensors->soc_dts[i], critical_trip);
THERMAL_TRIP_PASSIVE);
if (ret)
goto err_remove_zone;
ret = update_trip_temp(&sensors->soc_dts[i], 1, 0,
THERMAL_TRIP_PASSIVE);
if (ret) if (ret)
goto err_remove_zone; goto err_remove_zone;
} }
return sensors; return sensors;
err_remove_zone: err_remove_zone:
for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i)
remove_dts_thermal_zone(&sensors->soc_dts[i]); remove_dts_thermal_zone(&sensors->soc_dts[i]);
err_free: err_reset_trips:
for (i = 0; i < SOC_MAX_DTS_SENSORS; i++)
dts_trips_reset(sensors, i);
kfree(sensors); kfree(sensors);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
...@@ -440,9 +395,8 @@ void intel_soc_dts_iosf_exit(struct intel_soc_dts_sensors *sensors) ...@@ -440,9 +395,8 @@ void intel_soc_dts_iosf_exit(struct intel_soc_dts_sensors *sensors)
int i; int i;
for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) { for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) {
update_trip_temp(&sensors->soc_dts[i], 0, 0, 0);
update_trip_temp(&sensors->soc_dts[i], 1, 0, 0);
remove_dts_thermal_zone(&sensors->soc_dts[i]); remove_dts_thermal_zone(&sensors->soc_dts[i]);
dts_trips_reset(sensors, i);
} }
kfree(sensors); kfree(sensors);
} }
......
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
/* DTS0 and DTS 1 */ /* DTS0 and DTS 1 */
#define SOC_MAX_DTS_SENSORS 2 #define SOC_MAX_DTS_SENSORS 2
/* Only 2 out of 4 is allowed for OSPM */
#define SOC_MAX_DTS_TRIPS 2
enum intel_soc_dts_interrupt_type { enum intel_soc_dts_interrupt_type {
INTEL_SOC_DTS_INTERRUPT_NONE, INTEL_SOC_DTS_INTERRUPT_NONE,
INTEL_SOC_DTS_INTERRUPT_APIC, INTEL_SOC_DTS_INTERRUPT_APIC,
...@@ -26,8 +29,7 @@ struct intel_soc_dts_sensor_entry { ...@@ -26,8 +29,7 @@ struct intel_soc_dts_sensor_entry {
int id; int id;
u32 store_status; u32 store_status;
u32 trip_mask; u32 trip_mask;
u32 trip_count; struct thermal_trip trips[SOC_MAX_DTS_TRIPS];
enum thermal_trip_type trip_types[2];
struct thermal_zone_device *tzone; struct thermal_zone_device *tzone;
struct intel_soc_dts_sensors *sensors; struct intel_soc_dts_sensors *sensors;
}; };
...@@ -40,12 +42,11 @@ struct intel_soc_dts_sensors { ...@@ -40,12 +42,11 @@ struct intel_soc_dts_sensors {
struct intel_soc_dts_sensor_entry soc_dts[SOC_MAX_DTS_SENSORS]; struct intel_soc_dts_sensor_entry soc_dts[SOC_MAX_DTS_SENSORS];
}; };
struct intel_soc_dts_sensors *intel_soc_dts_iosf_init(
enum intel_soc_dts_interrupt_type intr_type, int trip_count, struct intel_soc_dts_sensors *
int read_only_trip_count); intel_soc_dts_iosf_init(enum intel_soc_dts_interrupt_type intr_type,
bool critical_trip, int crit_offset);
void intel_soc_dts_iosf_exit(struct intel_soc_dts_sensors *sensors); void intel_soc_dts_iosf_exit(struct intel_soc_dts_sensors *sensors);
void intel_soc_dts_iosf_interrupt_handler( void intel_soc_dts_iosf_interrupt_handler(
struct intel_soc_dts_sensors *sensors); struct intel_soc_dts_sensors *sensors);
int intel_soc_dts_iosf_add_read_only_critical_trip(
struct intel_soc_dts_sensors *sensors, int critical_offset);
#endif #endif
...@@ -51,7 +51,8 @@ static int __init intel_soc_thermal_init(void) ...@@ -51,7 +51,8 @@ static int __init intel_soc_thermal_init(void)
return -ENODEV; return -ENODEV;
/* Create a zone with 2 trips with marked as read only */ /* Create a zone with 2 trips with marked as read only */
soc_dts = intel_soc_dts_iosf_init(INTEL_SOC_DTS_INTERRUPT_APIC, 2, 1); soc_dts = intel_soc_dts_iosf_init(INTEL_SOC_DTS_INTERRUPT_APIC, true,
crit_offset);
if (IS_ERR(soc_dts)) { if (IS_ERR(soc_dts)) {
err = PTR_ERR(soc_dts); err = PTR_ERR(soc_dts);
return err; return err;
...@@ -88,21 +89,7 @@ static int __init intel_soc_thermal_init(void) ...@@ -88,21 +89,7 @@ static int __init intel_soc_thermal_init(void)
} }
} }
err = intel_soc_dts_iosf_add_read_only_critical_trip(soc_dts,
crit_offset);
if (err)
goto error_trips;
return 0; return 0;
error_trips:
if (soc_dts_thres_irq) {
free_irq(soc_dts_thres_irq, soc_dts);
acpi_unregister_gsi(soc_dts_thres_gsi);
}
intel_soc_dts_iosf_exit(soc_dts);
return err;
} }
static void __exit intel_soc_thermal_exit(void) static void __exit intel_soc_thermal_exit(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment