static int soctherm_bind(struct thermal_zone_device *thz,
struct thermal_cooling_device *cdev)
{
- int i, index = ((int)thz->devdata) - TSENSE_SIZE;
+ int i;
+ struct soctherm_therm *therm = thz->devdata;
struct thermal_trip_info *trip_state;
u32 base_cp, base_ft;
s32 shft_cp, shft_ft;
- if (index < 0)
- return 0;
-
/* skip binding cooling devices on improperly fused soctherm */
if (tegra_fuse_calib_base_get_cp(&base_cp, &shft_cp) < 0 ||
tegra_fuse_calib_base_get_ft(&base_ft, &shft_ft) < 0)
return 0;
- for (i = 0; i < plat_data.therm[index].num_trips; i++) {
- trip_state = &plat_data.therm[index].trips[i];
+ for (i = 0; i < therm->num_trips; i++) {
+ trip_state = &therm->trips[i];
if (trip_state->cdev_type &&
!strncmp(trip_state->cdev_type, cdev->type,
THERMAL_NAME_LENGTH)) {
static int soctherm_unbind(struct thermal_zone_device *thz,
struct thermal_cooling_device *cdev)
{
- int i, index = ((int)thz->devdata) - TSENSE_SIZE;
+ int i;
+ struct soctherm_therm *therm = thz->devdata;
struct thermal_trip_info *trip_state;
- if (index < 0)
- return 0;
-
- for (i = 0; i < plat_data.therm[index].num_trips; i++) {
- trip_state = &plat_data.therm[index].trips[i];
+ for (i = 0; i < therm->num_trips; i++) {
+ trip_state = &therm->trips[i];
if (!trip_state->bound)
continue;
if (trip_state->cdev_type &&
static int soctherm_get_temp(struct thermal_zone_device *thz,
unsigned long *temp)
{
- int index = (int)thz->devdata;
+ struct soctherm_therm *therm = thz->devdata;
+ ptrdiff_t index = therm - plat_data.therm;
u32 r, regv, shft, mask;
enum soctherm_sense i, j;
int tt, ti;
- if (index < TSENSE_SIZE) { /* 'TSENSE_XXX' thermal zone */
- regv = TS_CPU0_STATUS1;
- shft = TS_CPU0_STATUS1_TEMP_SHIFT;
- mask = TS_CPU0_STATUS1_TEMP_MASK;
- i = index;
- j = index;
- } else {
- index -= TSENSE_SIZE; /* 'THERM_XXX' thermal zone */
-
- switch (index) {
- case THERM_CPU:
- regv = TS_TEMP1;
- shft = TS_TEMP1_CPU_TEMP_SHIFT;
- mask = TS_TEMP1_CPU_TEMP_MASK;
- i = TSENSE_CPU0;
- j = TSENSE_CPU3;
- break;
-
- case THERM_GPU:
- regv = TS_TEMP1;
- shft = TS_TEMP1_GPU_TEMP_SHIFT;
- mask = TS_TEMP1_GPU_TEMP_MASK;
- i = TSENSE_GPU;
- j = TSENSE_GPU;
- break;
-
- case THERM_PLL:
- regv = TS_TEMP2;
- shft = TS_TEMP2_PLLX_TEMP_SHIFT;
- mask = TS_TEMP2_PLLX_TEMP_MASK;
- i = TSENSE_PLLX;
- j = TSENSE_PLLX;
- break;
-
- case THERM_MEM:
- regv = TS_TEMP2;
- shft = TS_TEMP2_MEM_TEMP_SHIFT;
- mask = TS_TEMP2_MEM_TEMP_MASK;
- i = TSENSE_MEM0;
- j = TSENSE_MEM1;
- break;
-
- default:
- return 0; /* error really */
- }
+ switch (index) {
+ case THERM_CPU:
+ regv = TS_TEMP1;
+ shft = TS_TEMP1_CPU_TEMP_SHIFT;
+ mask = TS_TEMP1_CPU_TEMP_MASK;
+ i = TSENSE_CPU0;
+ j = TSENSE_CPU3;
+ break;
+
+ case THERM_GPU:
+ regv = TS_TEMP1;
+ shft = TS_TEMP1_GPU_TEMP_SHIFT;
+ mask = TS_TEMP1_GPU_TEMP_MASK;
+ i = TSENSE_GPU;
+ j = TSENSE_GPU;
+ break;
+
+ case THERM_MEM:
+ regv = TS_TEMP2;
+ shft = TS_TEMP2_MEM_TEMP_SHIFT;
+ mask = TS_TEMP2_MEM_TEMP_MASK;
+ i = TSENSE_MEM0;
+ j = TSENSE_MEM1;
+ break;
+
+ case THERM_PLL:
+ default: /* if devdata has error, return PLL temp to be safe */
+ regv = TS_TEMP2;
+ shft = TS_TEMP2_PLLX_TEMP_SHIFT;
+ mask = TS_TEMP2_PLLX_TEMP_MASK;
+ i = TSENSE_PLLX;
+ j = TSENSE_PLLX;
+ break;
}
if (read_hw_temp) {
static int soctherm_get_trip_type(struct thermal_zone_device *thz,
int trip, enum thermal_trip_type *type)
{
- int index = ((int)thz->devdata) - TSENSE_SIZE;
- struct thermal_trip_info *trip_state;
+ struct soctherm_therm *therm = thz->devdata;
- if (index < 0)
- return -EINVAL;
-
- trip_state = &plat_data.therm[index].trips[trip];
- *type = trip_state->trip_type;
+ *type = therm->trips[trip].trip_type;
return 0;
}
static int soctherm_get_trip_temp(struct thermal_zone_device *thz,
int trip, unsigned long *temp)
{
- int index = ((int)thz->devdata) - TSENSE_SIZE;
+ struct soctherm_therm *therm = thz->devdata;
struct thermal_trip_info *trip_state;
unsigned long trip_temp, zone_temp;
- if (index < 0)
- return -EINVAL;
-
- trip_state = &plat_data.therm[index].trips[trip];
+ trip_state = &therm->trips[trip];
trip_temp = trip_state->trip_temp;
zone_temp = thz->temperature;
}
*temp = trip_temp;
-
return 0;
}
static int soctherm_set_trip_temp(struct thermal_zone_device *thz,
int trip, unsigned long temp)
{
- int index = ((int)thz->devdata) - TSENSE_SIZE;
+ struct soctherm_therm *therm = thz->devdata;
struct thermal_trip_info *trip_state;
long rem;
- if (index < 0)
- return -EINVAL;
-
- trip_state = &plat_data.therm[index].trips[trip];
-
+ trip_state = &therm->trips[trip];
trip_state->trip_temp = enforce_temp_range(temp);
rem = trip_state->trip_temp % LOWER_PRECISION_FOR_CONV(1000);
if (rem) {
pr_warn("soctherm: zone%d/trip_point%d %ld mC rounded down\n",
- index, trip, trip_state->trip_temp);
+ thz->id, trip, trip_state->trip_temp);
trip_state->trip_temp -= rem;
}
if (trip_state->trip_type == THERMAL_TRIP_HOT) {
if (strnstr(trip_state->cdev_type,
"heavy", THERMAL_NAME_LENGTH))
- prog_hw_threshold(trip_state, index, THROTTLE_HEAVY);
+ prog_hw_threshold(trip_state, thz->id, THROTTLE_HEAVY);
else if (strnstr(trip_state->cdev_type,
"light", THERMAL_NAME_LENGTH))
- prog_hw_threshold(trip_state, index, THROTTLE_LIGHT);
+ prog_hw_threshold(trip_state, thz->id, THROTTLE_LIGHT);
}
/* Allow SW to shutdown at 'Critical temperature reached' */
- soctherm_update_zone(index);
+ thermal_notify_framework(&thz[thz->id], trip);
/* Reprogram HW thermtrip */
if (trip_state->trip_type == THERMAL_TRIP_CRITICAL)
- prog_hw_shutdown(trip_state, index);
+ prog_hw_shutdown(trip_state, thz->id);
return 0;
}
static int soctherm_get_crit_temp(struct thermal_zone_device *thz,
unsigned long *temp)
{
- int i, index = ((int)thz->devdata) - TSENSE_SIZE;
+ int i;
+ struct soctherm_therm *therm = thz->devdata;
struct thermal_trip_info *trip_state;
- if (index < 0)
- return -EINVAL;
-
- for (i = 0; i < plat_data.therm[index].num_trips; i++) {
- trip_state = &plat_data.therm[index].trips[i];
+ for (i = 0; i < therm->num_trips; i++) {
+ trip_state = &therm->trips[i];
if (trip_state->trip_type != THERMAL_TRIP_CRITICAL)
continue;
*temp = trip_state->trip_temp;
int trip,
enum thermal_trend *trend)
{
- int index = ((int)thz->devdata) - TSENSE_SIZE;
+ struct soctherm_therm *therm = thz->devdata;
struct thermal_trip_info *trip_state;
long trip_temp;
- if (index < 0)
- return -EINVAL;
-
- trip_state = &plat_data.therm[index].trips[trip];
+ trip_state = &therm->trips[trip];
thz->ops->get_trip_temp(thz, trip, &trip_temp);
switch (trip_state->trip_type) {
if (!soctherm_init_platform_done)
return 0;
- for (i = 0; i < TSENSE_SIZE; i++) {
- if (plat_data.sensor_data[i].zone_enable) {
- snprintf(name, THERMAL_NAME_LENGTH,
- "%s-tsensor", sensor_names[i]);
- /* Create a thermal zone device for each sensor */
- thermal_zone_device_register(
- name,
- 0,
- 0,
- (void *)i,
- &soctherm_ops,
- NULL,
- 0,
- 0);
- }
- }
-
for (i = 0; i < THERM_SIZE; i++) {
therm = &plat_data.therm[i];
if (!therm->zone_enable)
}
}
- snprintf(name, THERMAL_NAME_LENGTH,
- "%s-therm", therm_names[i]);
+ snprintf(name, THERMAL_NAME_LENGTH, "%s-therm", therm_names[i]);
thz[i] = thermal_zone_device_register(
name,
therm->num_trips,
(1ULL << therm->num_trips) - 1,
- (void *)TSENSE_SIZE + i,
+ therm,
&soctherm_ops,
therm->tzp,
therm->passive_delay,
for (i = 0; i < TSENSE_SIZE; i++) {
therm = &plat_data.therm[tsensor2therm_map[i]];
s = &plat_data.sensor_data[i];
- s->sensor_enable = s->zone_enable;
s->sensor_enable = s->sensor_enable ?: therm->zone_enable;
s->tall = s->tall ?: sensor_defaults.tall;
s->tiddq = s->tiddq ?: sensor_defaults.tiddq;