From 9ace404b1098221021b01c2ba0eeea0c257fa4a5 Mon Sep 17 00:00:00 2001 From: Ben Skeggs Date: Thu, 20 Aug 2015 14:54:06 +1000 Subject: drm/nouveau/device: include core/device.h automatically for subdevs/engines Pretty much every subdev/engine is going to need access to nvkm_device shortly to touch registers and/or output messages. The odd placement of the includes is necessary to work around some inter-dependencies that currently exist. This will be fixed later. Signed-off-by: Ben Skeggs --- drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c') diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c index ec327cb64a0d..eb86c3ed5f56 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c @@ -23,8 +23,6 @@ */ #include "priv.h" -#include - static int nvkm_therm_update_trip(struct nvkm_therm *therm) { -- cgit v1.2.3 From da06b46b720687117178d3ee85a601762f1c36b5 Mon Sep 17 00:00:00 2001 From: Ben Skeggs Date: Thu, 20 Aug 2015 14:54:07 +1000 Subject: drm/nouveau/therm: cosmetic changes This is purely preparation for upcoming commits, there should be no code changes here. Signed-off-by: Ben Skeggs --- drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c | 232 +++++++++++------------ 1 file changed, 115 insertions(+), 117 deletions(-) (limited to 'drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c') diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c index eb86c3ed5f56..abb3fdc18910 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c @@ -24,18 +24,18 @@ #include "priv.h" static int -nvkm_therm_update_trip(struct nvkm_therm *therm) +nvkm_therm_update_trip(struct nvkm_therm *obj) { - struct nvkm_therm_priv *priv = (void *)therm; - struct nvbios_therm_trip_point *trip = priv->fan->bios.trip, + struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base); + struct nvbios_therm_trip_point *trip = therm->fan->bios.trip, *cur_trip = NULL, - *last_trip = priv->last_trip; - u8 temp = therm->temp_get(therm); + *last_trip = therm->last_trip; + u8 temp = therm->base.temp_get(&therm->base); u16 duty, i; /* look for the trip point corresponding to the current temperature */ cur_trip = NULL; - for (i = 0; i < priv->fan->bios.nr_fan_trip; i++) { + for (i = 0; i < therm->fan->bios.nr_fan_trip; i++) { if (temp >= trip[i].temp) cur_trip = &trip[i]; } @@ -47,72 +47,72 @@ nvkm_therm_update_trip(struct nvkm_therm *therm) if (cur_trip) { duty = cur_trip->fan_duty; - priv->last_trip = cur_trip; + therm->last_trip = cur_trip; } else { duty = 0; - priv->last_trip = NULL; + therm->last_trip = NULL; } return duty; } static int -nvkm_therm_update_linear(struct nvkm_therm *therm) +nvkm_therm_update_linear(struct nvkm_therm *obj) { - struct nvkm_therm_priv *priv = (void *)therm; - u8 linear_min_temp = priv->fan->bios.linear_min_temp; - u8 linear_max_temp = priv->fan->bios.linear_max_temp; - u8 temp = therm->temp_get(therm); + struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base); + u8 linear_min_temp = therm->fan->bios.linear_min_temp; + u8 linear_max_temp = therm->fan->bios.linear_max_temp; + u8 temp = therm->base.temp_get(&therm->base); u16 duty; /* handle the non-linear part first */ if (temp < linear_min_temp) - return priv->fan->bios.min_duty; + return therm->fan->bios.min_duty; else if (temp > linear_max_temp) - return priv->fan->bios.max_duty; + return therm->fan->bios.max_duty; /* we are in the linear zone */ duty = (temp - linear_min_temp); - duty *= (priv->fan->bios.max_duty - priv->fan->bios.min_duty); + duty *= (therm->fan->bios.max_duty - therm->fan->bios.min_duty); duty /= (linear_max_temp - linear_min_temp); - duty += priv->fan->bios.min_duty; + duty += therm->fan->bios.min_duty; return duty; } static void -nvkm_therm_update(struct nvkm_therm *therm, int mode) +nvkm_therm_update(struct nvkm_therm *obj, int mode) { + struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base); struct nvkm_timer *ptimer = nvkm_timer(therm); - struct nvkm_therm_priv *priv = (void *)therm; unsigned long flags; bool immd = true; bool poll = true; int duty = -1; - spin_lock_irqsave(&priv->lock, flags); + spin_lock_irqsave(&therm->lock, flags); if (mode < 0) - mode = priv->mode; - priv->mode = mode; + mode = therm->mode; + therm->mode = mode; switch (mode) { case NVKM_THERM_CTRL_MANUAL: - ptimer->alarm_cancel(ptimer, &priv->alarm); - duty = nvkm_therm_fan_get(therm); + ptimer->alarm_cancel(ptimer, &therm->alarm); + duty = nvkm_therm_fan_get(&therm->base); if (duty < 0) duty = 100; poll = false; break; case NVKM_THERM_CTRL_AUTO: - switch(priv->fan->bios.fan_mode) { + switch(therm->fan->bios.fan_mode) { case NVBIOS_THERM_FAN_TRIP: - duty = nvkm_therm_update_trip(therm); + duty = nvkm_therm_update_trip(&therm->base); break; case NVBIOS_THERM_FAN_LINEAR: - duty = nvkm_therm_update_linear(therm); + duty = nvkm_therm_update_linear(&therm->base); break; case NVBIOS_THERM_FAN_OTHER: - if (priv->cstate) - duty = priv->cstate; + if (therm->cstate) + duty = therm->cstate; poll = false; break; } @@ -120,29 +120,29 @@ nvkm_therm_update(struct nvkm_therm *therm, int mode) break; case NVKM_THERM_CTRL_NONE: default: - ptimer->alarm_cancel(ptimer, &priv->alarm); + ptimer->alarm_cancel(ptimer, &therm->alarm); poll = false; } - if (list_empty(&priv->alarm.head) && poll) - ptimer->alarm(ptimer, 1000000000ULL, &priv->alarm); - spin_unlock_irqrestore(&priv->lock, flags); + if (list_empty(&therm->alarm.head) && poll) + ptimer->alarm(ptimer, 1000000000ULL, &therm->alarm); + spin_unlock_irqrestore(&therm->lock, flags); if (duty >= 0) { nv_debug(therm, "FAN target request: %d%%\n", duty); - nvkm_therm_fan_set(therm, immd, duty); + nvkm_therm_fan_set(&therm->base, immd, duty); } } int -nvkm_therm_cstate(struct nvkm_therm *ptherm, int fan, int dir) +nvkm_therm_cstate(struct nvkm_therm *obj, int fan, int dir) { - struct nvkm_therm_priv *priv = (void *)ptherm; - if (!dir || (dir < 0 && fan < priv->cstate) || - (dir > 0 && fan > priv->cstate)) { - nv_debug(ptherm, "default fan speed -> %d%%\n", fan); - priv->cstate = fan; - nvkm_therm_update(ptherm, -1); + struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base); + if (!dir || (dir < 0 && fan < therm->cstate) || + (dir > 0 && fan > therm->cstate)) { + nv_debug(therm, "default fan speed -> %d%%\n", fan); + therm->cstate = fan; + nvkm_therm_update(&therm->base, -1); } return 0; } @@ -150,15 +150,15 @@ nvkm_therm_cstate(struct nvkm_therm *ptherm, int fan, int dir) static void nvkm_therm_alarm(struct nvkm_alarm *alarm) { - struct nvkm_therm_priv *priv = + struct nvkm_therm_priv *therm = container_of(alarm, struct nvkm_therm_priv, alarm); - nvkm_therm_update(&priv->base, -1); + nvkm_therm_update(&therm->base, -1); } int -nvkm_therm_fan_mode(struct nvkm_therm *therm, int mode) +nvkm_therm_fan_mode(struct nvkm_therm *obj, int mode) { - struct nvkm_therm_priv *priv = (void *)therm; + struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base); struct nvkm_device *device = nv_device(therm); static const char *name[] = { "disabled", @@ -174,105 +174,105 @@ nvkm_therm_fan_mode(struct nvkm_therm *therm, int mode) /* do not allow automatic fan management if the thermal sensor is * not available */ - if (mode == NVKM_THERM_CTRL_AUTO && therm->temp_get(therm) < 0) + if (mode == NVKM_THERM_CTRL_AUTO && + therm->base.temp_get(&therm->base) < 0) return -EINVAL; - if (priv->mode == mode) + if (therm->mode == mode) return 0; nv_info(therm, "fan management: %s\n", name[mode]); - nvkm_therm_update(therm, mode); + nvkm_therm_update(&therm->base, mode); return 0; } int -nvkm_therm_attr_get(struct nvkm_therm *therm, - enum nvkm_therm_attr_type type) +nvkm_therm_attr_get(struct nvkm_therm *obj, enum nvkm_therm_attr_type type) { - struct nvkm_therm_priv *priv = (void *)therm; + struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base); switch (type) { case NVKM_THERM_ATTR_FAN_MIN_DUTY: - return priv->fan->bios.min_duty; + return therm->fan->bios.min_duty; case NVKM_THERM_ATTR_FAN_MAX_DUTY: - return priv->fan->bios.max_duty; + return therm->fan->bios.max_duty; case NVKM_THERM_ATTR_FAN_MODE: - return priv->mode; + return therm->mode; case NVKM_THERM_ATTR_THRS_FAN_BOOST: - return priv->bios_sensor.thrs_fan_boost.temp; + return therm->bios_sensor.thrs_fan_boost.temp; case NVKM_THERM_ATTR_THRS_FAN_BOOST_HYST: - return priv->bios_sensor.thrs_fan_boost.hysteresis; + return therm->bios_sensor.thrs_fan_boost.hysteresis; case NVKM_THERM_ATTR_THRS_DOWN_CLK: - return priv->bios_sensor.thrs_down_clock.temp; + return therm->bios_sensor.thrs_down_clock.temp; case NVKM_THERM_ATTR_THRS_DOWN_CLK_HYST: - return priv->bios_sensor.thrs_down_clock.hysteresis; + return therm->bios_sensor.thrs_down_clock.hysteresis; case NVKM_THERM_ATTR_THRS_CRITICAL: - return priv->bios_sensor.thrs_critical.temp; + return therm->bios_sensor.thrs_critical.temp; case NVKM_THERM_ATTR_THRS_CRITICAL_HYST: - return priv->bios_sensor.thrs_critical.hysteresis; + return therm->bios_sensor.thrs_critical.hysteresis; case NVKM_THERM_ATTR_THRS_SHUTDOWN: - return priv->bios_sensor.thrs_shutdown.temp; + return therm->bios_sensor.thrs_shutdown.temp; case NVKM_THERM_ATTR_THRS_SHUTDOWN_HYST: - return priv->bios_sensor.thrs_shutdown.hysteresis; + return therm->bios_sensor.thrs_shutdown.hysteresis; } return -EINVAL; } int -nvkm_therm_attr_set(struct nvkm_therm *therm, +nvkm_therm_attr_set(struct nvkm_therm *obj, enum nvkm_therm_attr_type type, int value) { - struct nvkm_therm_priv *priv = (void *)therm; + struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base); switch (type) { case NVKM_THERM_ATTR_FAN_MIN_DUTY: if (value < 0) value = 0; - if (value > priv->fan->bios.max_duty) - value = priv->fan->bios.max_duty; - priv->fan->bios.min_duty = value; + if (value > therm->fan->bios.max_duty) + value = therm->fan->bios.max_duty; + therm->fan->bios.min_duty = value; return 0; case NVKM_THERM_ATTR_FAN_MAX_DUTY: if (value < 0) value = 0; - if (value < priv->fan->bios.min_duty) - value = priv->fan->bios.min_duty; - priv->fan->bios.max_duty = value; + if (value < therm->fan->bios.min_duty) + value = therm->fan->bios.min_duty; + therm->fan->bios.max_duty = value; return 0; case NVKM_THERM_ATTR_FAN_MODE: - return nvkm_therm_fan_mode(therm, value); + return nvkm_therm_fan_mode(&therm->base, value); case NVKM_THERM_ATTR_THRS_FAN_BOOST: - priv->bios_sensor.thrs_fan_boost.temp = value; - priv->sensor.program_alarms(therm); + therm->bios_sensor.thrs_fan_boost.temp = value; + therm->sensor.program_alarms(&therm->base); return 0; case NVKM_THERM_ATTR_THRS_FAN_BOOST_HYST: - priv->bios_sensor.thrs_fan_boost.hysteresis = value; - priv->sensor.program_alarms(therm); + therm->bios_sensor.thrs_fan_boost.hysteresis = value; + therm->sensor.program_alarms(&therm->base); return 0; case NVKM_THERM_ATTR_THRS_DOWN_CLK: - priv->bios_sensor.thrs_down_clock.temp = value; - priv->sensor.program_alarms(therm); + therm->bios_sensor.thrs_down_clock.temp = value; + therm->sensor.program_alarms(&therm->base); return 0; case NVKM_THERM_ATTR_THRS_DOWN_CLK_HYST: - priv->bios_sensor.thrs_down_clock.hysteresis = value; - priv->sensor.program_alarms(therm); + therm->bios_sensor.thrs_down_clock.hysteresis = value; + therm->sensor.program_alarms(&therm->base); return 0; case NVKM_THERM_ATTR_THRS_CRITICAL: - priv->bios_sensor.thrs_critical.temp = value; - priv->sensor.program_alarms(therm); + therm->bios_sensor.thrs_critical.temp = value; + therm->sensor.program_alarms(&therm->base); return 0; case NVKM_THERM_ATTR_THRS_CRITICAL_HYST: - priv->bios_sensor.thrs_critical.hysteresis = value; - priv->sensor.program_alarms(therm); + therm->bios_sensor.thrs_critical.hysteresis = value; + therm->sensor.program_alarms(&therm->base); return 0; case NVKM_THERM_ATTR_THRS_SHUTDOWN: - priv->bios_sensor.thrs_shutdown.temp = value; - priv->sensor.program_alarms(therm); + therm->bios_sensor.thrs_shutdown.temp = value; + therm->sensor.program_alarms(&therm->base); return 0; case NVKM_THERM_ATTR_THRS_SHUTDOWN_HYST: - priv->bios_sensor.thrs_shutdown.hysteresis = value; - priv->sensor.program_alarms(therm); + therm->bios_sensor.thrs_shutdown.hysteresis = value; + therm->sensor.program_alarms(&therm->base); return 0; } @@ -282,65 +282,63 @@ nvkm_therm_attr_set(struct nvkm_therm *therm, int _nvkm_therm_init(struct nvkm_object *object) { - struct nvkm_therm *therm = (void *)object; - struct nvkm_therm_priv *priv = (void *)therm; + struct nvkm_therm_priv *therm = (void *)object; int ret; - ret = nvkm_subdev_init(&therm->base); + ret = nvkm_subdev_init(&therm->base.subdev); if (ret) return ret; - if (priv->suspend >= 0) { + if (therm->suspend >= 0) { /* restore the pwm value only when on manual or auto mode */ - if (priv->suspend > 0) - nvkm_therm_fan_set(therm, true, priv->fan->percent); + if (therm->suspend > 0) + nvkm_therm_fan_set(&therm->base, true, therm->fan->percent); - nvkm_therm_fan_mode(therm, priv->suspend); + nvkm_therm_fan_mode(&therm->base, therm->suspend); } - nvkm_therm_sensor_init(therm); - nvkm_therm_fan_init(therm); + nvkm_therm_sensor_init(&therm->base); + nvkm_therm_fan_init(&therm->base); return 0; } int _nvkm_therm_fini(struct nvkm_object *object, bool suspend) { - struct nvkm_therm *therm = (void *)object; - struct nvkm_therm_priv *priv = (void *)therm; + struct nvkm_therm_priv *therm = (void *)object; - nvkm_therm_fan_fini(therm, suspend); - nvkm_therm_sensor_fini(therm, suspend); + nvkm_therm_fan_fini(&therm->base, suspend); + nvkm_therm_sensor_fini(&therm->base, suspend); if (suspend) { - priv->suspend = priv->mode; - priv->mode = NVKM_THERM_CTRL_NONE; + therm->suspend = therm->mode; + therm->mode = NVKM_THERM_CTRL_NONE; } - return nvkm_subdev_fini(&therm->base, suspend); + return nvkm_subdev_fini(&therm->base.subdev, suspend); } int nvkm_therm_create_(struct nvkm_object *parent, struct nvkm_object *engine, struct nvkm_oclass *oclass, int length, void **pobject) { - struct nvkm_therm_priv *priv; + struct nvkm_therm_priv *therm; int ret; ret = nvkm_subdev_create_(parent, engine, oclass, 0, "PTHERM", "therm", length, pobject); - priv = *pobject; + therm = *pobject; if (ret) return ret; - nvkm_alarm_init(&priv->alarm, nvkm_therm_alarm); - spin_lock_init(&priv->lock); - spin_lock_init(&priv->sensor.alarm_program_lock); + nvkm_alarm_init(&therm->alarm, nvkm_therm_alarm); + spin_lock_init(&therm->lock); + spin_lock_init(&therm->sensor.alarm_program_lock); - priv->base.fan_get = nvkm_therm_fan_user_get; - priv->base.fan_set = nvkm_therm_fan_user_set; - priv->base.fan_sense = nvkm_therm_fan_sense; - priv->base.attr_get = nvkm_therm_attr_get; - priv->base.attr_set = nvkm_therm_attr_set; - priv->mode = priv->suspend = -1; /* undefined */ + therm->base.fan_get = nvkm_therm_fan_user_get; + therm->base.fan_set = nvkm_therm_fan_user_set; + therm->base.fan_sense = nvkm_therm_fan_sense; + therm->base.attr_get = nvkm_therm_attr_get; + therm->base.attr_set = nvkm_therm_attr_set; + therm->mode = therm->suspend = -1; /* undefined */ return 0; } @@ -359,7 +357,7 @@ nvkm_therm_preinit(struct nvkm_therm *therm) void _nvkm_therm_dtor(struct nvkm_object *object) { - struct nvkm_therm_priv *priv = (void *)object; - kfree(priv->fan); - nvkm_subdev_destroy(&priv->base.base); + struct nvkm_therm_priv *therm = (void *)object; + kfree(therm->fan); + nvkm_subdev_destroy(&therm->base.subdev); } -- cgit v1.2.3 From cb8bb9cedb6015eafd56ef9e9c5b2c216e8e7960 Mon Sep 17 00:00:00 2001 From: Ben Skeggs Date: Thu, 20 Aug 2015 14:54:07 +1000 Subject: drm/nouveau/tmr: cosmetic changes This is purely preparation for upcoming commits, there should be no code changes here. Signed-off-by: Ben Skeggs --- drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c') diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c index abb3fdc18910..87c20d197102 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c @@ -83,7 +83,7 @@ static void nvkm_therm_update(struct nvkm_therm *obj, int mode) { struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base); - struct nvkm_timer *ptimer = nvkm_timer(therm); + struct nvkm_timer *tmr = nvkm_timer(therm); unsigned long flags; bool immd = true; bool poll = true; @@ -96,7 +96,7 @@ nvkm_therm_update(struct nvkm_therm *obj, int mode) switch (mode) { case NVKM_THERM_CTRL_MANUAL: - ptimer->alarm_cancel(ptimer, &therm->alarm); + tmr->alarm_cancel(tmr, &therm->alarm); duty = nvkm_therm_fan_get(&therm->base); if (duty < 0) duty = 100; @@ -120,12 +120,12 @@ nvkm_therm_update(struct nvkm_therm *obj, int mode) break; case NVKM_THERM_CTRL_NONE: default: - ptimer->alarm_cancel(ptimer, &therm->alarm); + tmr->alarm_cancel(tmr, &therm->alarm); poll = false; } if (list_empty(&therm->alarm.head) && poll) - ptimer->alarm(ptimer, 1000000000ULL, &therm->alarm); + tmr->alarm(tmr, 1000000000ULL, &therm->alarm); spin_unlock_irqrestore(&therm->lock, flags); if (duty >= 0) { -- cgit v1.2.3 From b3c418bb48228a206a8c421adaf269cdc83c3c52 Mon Sep 17 00:00:00 2001 From: Ben Skeggs Date: Thu, 20 Aug 2015 14:54:12 +1000 Subject: drm/nouveau/therm: switch to subdev printk macros Signed-off-by: Ben Skeggs --- drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c') diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c index 87c20d197102..18fa0443b6d3 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c @@ -83,7 +83,8 @@ static void nvkm_therm_update(struct nvkm_therm *obj, int mode) { struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base); - struct nvkm_timer *tmr = nvkm_timer(therm); + struct nvkm_subdev *subdev = &therm->base.subdev; + struct nvkm_timer *tmr = subdev->device->timer; unsigned long flags; bool immd = true; bool poll = true; @@ -129,7 +130,7 @@ nvkm_therm_update(struct nvkm_therm *obj, int mode) spin_unlock_irqrestore(&therm->lock, flags); if (duty >= 0) { - nv_debug(therm, "FAN target request: %d%%\n", duty); + nvkm_debug(subdev, "FAN target request: %d%%\n", duty); nvkm_therm_fan_set(&therm->base, immd, duty); } } @@ -138,9 +139,10 @@ int nvkm_therm_cstate(struct nvkm_therm *obj, int fan, int dir) { struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base); + struct nvkm_subdev *subdev = &therm->base.subdev; if (!dir || (dir < 0 && fan < therm->cstate) || (dir > 0 && fan > therm->cstate)) { - nv_debug(therm, "default fan speed -> %d%%\n", fan); + nvkm_debug(subdev, "default fan speed -> %d%%\n", fan); therm->cstate = fan; nvkm_therm_update(&therm->base, -1); } @@ -159,7 +161,8 @@ int nvkm_therm_fan_mode(struct nvkm_therm *obj, int mode) { struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base); - struct nvkm_device *device = nv_device(therm); + struct nvkm_subdev *subdev = &therm->base.subdev; + struct nvkm_device *device = subdev->device; static const char *name[] = { "disabled", "manual", @@ -181,7 +184,7 @@ nvkm_therm_fan_mode(struct nvkm_therm *obj, int mode) if (therm->mode == mode) return 0; - nv_info(therm, "fan management: %s\n", name[mode]); + nvkm_debug(subdev, "fan management: %s\n", name[mode]); nvkm_therm_update(&therm->base, mode); return 0; } -- cgit v1.2.3 From 3a8c3400f3e74638bedd0d2410416aa8b794c0fd Mon Sep 17 00:00:00 2001 From: Ben Skeggs Date: Thu, 20 Aug 2015 14:54:16 +1000 Subject: drm/nouveau/subdev: rename some functions to avoid upcoming conflicts Signed-off-by: Ben Skeggs --- drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c') diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c index 18fa0443b6d3..e757fd9b7a07 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c @@ -288,7 +288,7 @@ _nvkm_therm_init(struct nvkm_object *object) struct nvkm_therm_priv *therm = (void *)object; int ret; - ret = nvkm_subdev_init(&therm->base.subdev); + ret = nvkm_subdev_init_old(&therm->base.subdev); if (ret) return ret; @@ -316,7 +316,7 @@ _nvkm_therm_fini(struct nvkm_object *object, bool suspend) therm->mode = NVKM_THERM_CTRL_NONE; } - return nvkm_subdev_fini(&therm->base.subdev, suspend); + return nvkm_subdev_fini_old(&therm->base.subdev, suspend); } int -- cgit v1.2.3 From 57113c0170b9efeacb3e3e9d4c2178c30d9cd991 Mon Sep 17 00:00:00 2001 From: Ben Skeggs Date: Thu, 20 Aug 2015 14:54:21 +1000 Subject: drm/nouveau/therm: convert to new-style nvkm_subdev Signed-off-by: Ben Skeggs --- drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c | 212 ++++++++++++----------- 1 file changed, 114 insertions(+), 98 deletions(-) (limited to 'drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c') diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c index e757fd9b7a07..304bdfc54445 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c @@ -23,14 +23,21 @@ */ #include "priv.h" +int +nvkm_therm_temp_get(struct nvkm_therm *therm) +{ + if (therm->func->temp_get) + return therm->func->temp_get(therm); + return -ENODEV; +} + static int -nvkm_therm_update_trip(struct nvkm_therm *obj) +nvkm_therm_update_trip(struct nvkm_therm *therm) { - struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base); struct nvbios_therm_trip_point *trip = therm->fan->bios.trip, *cur_trip = NULL, *last_trip = therm->last_trip; - u8 temp = therm->base.temp_get(&therm->base); + u8 temp = therm->func->temp_get(therm); u16 duty, i; /* look for the trip point corresponding to the current temperature */ @@ -57,12 +64,11 @@ nvkm_therm_update_trip(struct nvkm_therm *obj) } static int -nvkm_therm_update_linear(struct nvkm_therm *obj) +nvkm_therm_update_linear(struct nvkm_therm *therm) { - struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base); u8 linear_min_temp = therm->fan->bios.linear_min_temp; u8 linear_max_temp = therm->fan->bios.linear_max_temp; - u8 temp = therm->base.temp_get(&therm->base); + u8 temp = therm->func->temp_get(therm); u16 duty; /* handle the non-linear part first */ @@ -80,10 +86,9 @@ nvkm_therm_update_linear(struct nvkm_therm *obj) } static void -nvkm_therm_update(struct nvkm_therm *obj, int mode) +nvkm_therm_update(struct nvkm_therm *therm, int mode) { - struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base); - struct nvkm_subdev *subdev = &therm->base.subdev; + struct nvkm_subdev *subdev = &therm->subdev; struct nvkm_timer *tmr = subdev->device->timer; unsigned long flags; bool immd = true; @@ -98,7 +103,7 @@ nvkm_therm_update(struct nvkm_therm *obj, int mode) switch (mode) { case NVKM_THERM_CTRL_MANUAL: tmr->alarm_cancel(tmr, &therm->alarm); - duty = nvkm_therm_fan_get(&therm->base); + duty = nvkm_therm_fan_get(therm); if (duty < 0) duty = 100; poll = false; @@ -106,10 +111,10 @@ nvkm_therm_update(struct nvkm_therm *obj, int mode) case NVKM_THERM_CTRL_AUTO: switch(therm->fan->bios.fan_mode) { case NVBIOS_THERM_FAN_TRIP: - duty = nvkm_therm_update_trip(&therm->base); + duty = nvkm_therm_update_trip(therm); break; case NVBIOS_THERM_FAN_LINEAR: - duty = nvkm_therm_update_linear(&therm->base); + duty = nvkm_therm_update_linear(therm); break; case NVBIOS_THERM_FAN_OTHER: if (therm->cstate) @@ -131,20 +136,19 @@ nvkm_therm_update(struct nvkm_therm *obj, int mode) if (duty >= 0) { nvkm_debug(subdev, "FAN target request: %d%%\n", duty); - nvkm_therm_fan_set(&therm->base, immd, duty); + nvkm_therm_fan_set(therm, immd, duty); } } int -nvkm_therm_cstate(struct nvkm_therm *obj, int fan, int dir) +nvkm_therm_cstate(struct nvkm_therm *therm, int fan, int dir) { - struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base); - struct nvkm_subdev *subdev = &therm->base.subdev; + struct nvkm_subdev *subdev = &therm->subdev; if (!dir || (dir < 0 && fan < therm->cstate) || (dir > 0 && fan > therm->cstate)) { nvkm_debug(subdev, "default fan speed -> %d%%\n", fan); therm->cstate = fan; - nvkm_therm_update(&therm->base, -1); + nvkm_therm_update(therm, -1); } return 0; } @@ -152,16 +156,15 @@ nvkm_therm_cstate(struct nvkm_therm *obj, int fan, int dir) static void nvkm_therm_alarm(struct nvkm_alarm *alarm) { - struct nvkm_therm_priv *therm = - container_of(alarm, struct nvkm_therm_priv, alarm); - nvkm_therm_update(&therm->base, -1); + struct nvkm_therm *therm = + container_of(alarm, struct nvkm_therm, alarm); + nvkm_therm_update(therm, -1); } int -nvkm_therm_fan_mode(struct nvkm_therm *obj, int mode) +nvkm_therm_fan_mode(struct nvkm_therm *therm, int mode) { - struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base); - struct nvkm_subdev *subdev = &therm->base.subdev; + struct nvkm_subdev *subdev = &therm->subdev; struct nvkm_device *device = subdev->device; static const char *name[] = { "disabled", @@ -172,28 +175,26 @@ nvkm_therm_fan_mode(struct nvkm_therm *obj, int mode) /* The default PPWR ucode on fermi interferes with fan management */ if ((mode >= ARRAY_SIZE(name)) || (mode != NVKM_THERM_CTRL_NONE && device->card_type >= NV_C0 && - !nvkm_subdev(device, NVDEV_SUBDEV_PMU))) + !device->pmu)) return -EINVAL; /* do not allow automatic fan management if the thermal sensor is * not available */ if (mode == NVKM_THERM_CTRL_AUTO && - therm->base.temp_get(&therm->base) < 0) + therm->func->temp_get(therm) < 0) return -EINVAL; if (therm->mode == mode) return 0; nvkm_debug(subdev, "fan management: %s\n", name[mode]); - nvkm_therm_update(&therm->base, mode); + nvkm_therm_update(therm, mode); return 0; } int -nvkm_therm_attr_get(struct nvkm_therm *obj, enum nvkm_therm_attr_type type) +nvkm_therm_attr_get(struct nvkm_therm *therm, enum nvkm_therm_attr_type type) { - struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base); - switch (type) { case NVKM_THERM_ATTR_FAN_MIN_DUTY: return therm->fan->bios.min_duty; @@ -223,11 +224,9 @@ nvkm_therm_attr_get(struct nvkm_therm *obj, enum nvkm_therm_attr_type type) } int -nvkm_therm_attr_set(struct nvkm_therm *obj, +nvkm_therm_attr_set(struct nvkm_therm *therm, enum nvkm_therm_attr_type type, int value) { - struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base); - switch (type) { case NVKM_THERM_ATTR_FAN_MIN_DUTY: if (value < 0) @@ -244,123 +243,140 @@ nvkm_therm_attr_set(struct nvkm_therm *obj, therm->fan->bios.max_duty = value; return 0; case NVKM_THERM_ATTR_FAN_MODE: - return nvkm_therm_fan_mode(&therm->base, value); + return nvkm_therm_fan_mode(therm, value); case NVKM_THERM_ATTR_THRS_FAN_BOOST: therm->bios_sensor.thrs_fan_boost.temp = value; - therm->sensor.program_alarms(&therm->base); + therm->func->program_alarms(therm); return 0; case NVKM_THERM_ATTR_THRS_FAN_BOOST_HYST: therm->bios_sensor.thrs_fan_boost.hysteresis = value; - therm->sensor.program_alarms(&therm->base); + therm->func->program_alarms(therm); return 0; case NVKM_THERM_ATTR_THRS_DOWN_CLK: therm->bios_sensor.thrs_down_clock.temp = value; - therm->sensor.program_alarms(&therm->base); + therm->func->program_alarms(therm); return 0; case NVKM_THERM_ATTR_THRS_DOWN_CLK_HYST: therm->bios_sensor.thrs_down_clock.hysteresis = value; - therm->sensor.program_alarms(&therm->base); + therm->func->program_alarms(therm); return 0; case NVKM_THERM_ATTR_THRS_CRITICAL: therm->bios_sensor.thrs_critical.temp = value; - therm->sensor.program_alarms(&therm->base); + therm->func->program_alarms(therm); return 0; case NVKM_THERM_ATTR_THRS_CRITICAL_HYST: therm->bios_sensor.thrs_critical.hysteresis = value; - therm->sensor.program_alarms(&therm->base); + therm->func->program_alarms(therm); return 0; case NVKM_THERM_ATTR_THRS_SHUTDOWN: therm->bios_sensor.thrs_shutdown.temp = value; - therm->sensor.program_alarms(&therm->base); + therm->func->program_alarms(therm); return 0; case NVKM_THERM_ATTR_THRS_SHUTDOWN_HYST: therm->bios_sensor.thrs_shutdown.hysteresis = value; - therm->sensor.program_alarms(&therm->base); + therm->func->program_alarms(therm); return 0; } return -EINVAL; } -int -_nvkm_therm_init(struct nvkm_object *object) +static void +nvkm_therm_intr(struct nvkm_subdev *subdev) { - struct nvkm_therm_priv *therm = (void *)object; - int ret; - - ret = nvkm_subdev_init_old(&therm->base.subdev); - if (ret) - return ret; - - if (therm->suspend >= 0) { - /* restore the pwm value only when on manual or auto mode */ - if (therm->suspend > 0) - nvkm_therm_fan_set(&therm->base, true, therm->fan->percent); - - nvkm_therm_fan_mode(&therm->base, therm->suspend); - } - nvkm_therm_sensor_init(&therm->base); - nvkm_therm_fan_init(&therm->base); - return 0; + struct nvkm_therm *therm = nvkm_therm(subdev); + if (therm->func->intr) + therm->func->intr(therm); } -int -_nvkm_therm_fini(struct nvkm_object *object, bool suspend) +static int +nvkm_therm_fini(struct nvkm_subdev *subdev, bool suspend) { - struct nvkm_therm_priv *therm = (void *)object; + struct nvkm_therm *therm = nvkm_therm(subdev); + + if (therm->func->fini) + therm->func->fini(therm); + + nvkm_therm_fan_fini(therm, suspend); + nvkm_therm_sensor_fini(therm, suspend); - nvkm_therm_fan_fini(&therm->base, suspend); - nvkm_therm_sensor_fini(&therm->base, suspend); if (suspend) { therm->suspend = therm->mode; therm->mode = NVKM_THERM_CTRL_NONE; } - return nvkm_subdev_fini_old(&therm->base.subdev, suspend); -} - -int -nvkm_therm_create_(struct nvkm_object *parent, struct nvkm_object *engine, - struct nvkm_oclass *oclass, int length, void **pobject) -{ - struct nvkm_therm_priv *therm; - int ret; - - ret = nvkm_subdev_create_(parent, engine, oclass, 0, "PTHERM", - "therm", length, pobject); - therm = *pobject; - if (ret) - return ret; - - nvkm_alarm_init(&therm->alarm, nvkm_therm_alarm); - spin_lock_init(&therm->lock); - spin_lock_init(&therm->sensor.alarm_program_lock); - - therm->base.fan_get = nvkm_therm_fan_user_get; - therm->base.fan_set = nvkm_therm_fan_user_set; - therm->base.fan_sense = nvkm_therm_fan_sense; - therm->base.attr_get = nvkm_therm_attr_get; - therm->base.attr_set = nvkm_therm_attr_set; - therm->mode = therm->suspend = -1; /* undefined */ return 0; } -int -nvkm_therm_preinit(struct nvkm_therm *therm) +static int +nvkm_therm_oneinit(struct nvkm_subdev *subdev) { + struct nvkm_therm *therm = nvkm_therm(subdev); nvkm_therm_sensor_ctor(therm); nvkm_therm_ic_ctor(therm); nvkm_therm_fan_ctor(therm); - nvkm_therm_fan_mode(therm, NVKM_THERM_CTRL_AUTO); nvkm_therm_sensor_preinit(therm); return 0; } -void -_nvkm_therm_dtor(struct nvkm_object *object) +static int +nvkm_therm_init(struct nvkm_subdev *subdev) +{ + struct nvkm_therm *therm = nvkm_therm(subdev); + + therm->func->init(therm); + + if (therm->suspend >= 0) { + /* restore the pwm value only when on manual or auto mode */ + if (therm->suspend > 0) + nvkm_therm_fan_set(therm, true, therm->fan->percent); + + nvkm_therm_fan_mode(therm, therm->suspend); + } + + nvkm_therm_sensor_init(therm); + nvkm_therm_fan_init(therm); + return 0; +} + +static void * +nvkm_therm_dtor(struct nvkm_subdev *subdev) { - struct nvkm_therm_priv *therm = (void *)object; + struct nvkm_therm *therm = nvkm_therm(subdev); kfree(therm->fan); - nvkm_subdev_destroy(&therm->base.subdev); + return therm; +} + +static const struct nvkm_subdev_func +nvkm_therm = { + .dtor = nvkm_therm_dtor, + .oneinit = nvkm_therm_oneinit, + .init = nvkm_therm_init, + .fini = nvkm_therm_fini, + .intr = nvkm_therm_intr, +}; + +int +nvkm_therm_new_(const struct nvkm_therm_func *func, struct nvkm_device *device, + int index, struct nvkm_therm **ptherm) +{ + struct nvkm_therm *therm; + + if (!(therm = *ptherm = kzalloc(sizeof(*therm), GFP_KERNEL))) + return -ENOMEM; + + nvkm_subdev_ctor(&nvkm_therm, device, index, 0, &therm->subdev); + therm->func = func; + + nvkm_alarm_init(&therm->alarm, nvkm_therm_alarm); + spin_lock_init(&therm->lock); + spin_lock_init(&therm->sensor.alarm_program_lock); + + therm->fan_get = nvkm_therm_fan_user_get; + therm->fan_set = nvkm_therm_fan_user_set; + therm->attr_get = nvkm_therm_attr_get; + therm->attr_set = nvkm_therm_attr_set; + therm->mode = therm->suspend = -1; /* undefined */ + return 0; } -- cgit v1.2.3 From 31649ecf47a44e02e73bffc5680c8f56d6cf587a Mon Sep 17 00:00:00 2001 From: Ben Skeggs Date: Thu, 20 Aug 2015 14:54:21 +1000 Subject: drm/nouveau/tmr: convert to new-style nvkm_subdev Signed-off-by: Ben Skeggs --- drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c') diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c index 304bdfc54445..949dc6101a58 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c @@ -102,7 +102,7 @@ nvkm_therm_update(struct nvkm_therm *therm, int mode) switch (mode) { case NVKM_THERM_CTRL_MANUAL: - tmr->alarm_cancel(tmr, &therm->alarm); + nvkm_timer_alarm_cancel(tmr, &therm->alarm); duty = nvkm_therm_fan_get(therm); if (duty < 0) duty = 100; @@ -126,12 +126,12 @@ nvkm_therm_update(struct nvkm_therm *therm, int mode) break; case NVKM_THERM_CTRL_NONE: default: - tmr->alarm_cancel(tmr, &therm->alarm); + nvkm_timer_alarm_cancel(tmr, &therm->alarm); poll = false; } if (list_empty(&therm->alarm.head) && poll) - tmr->alarm(tmr, 1000000000ULL, &therm->alarm); + nvkm_timer_alarm(tmr, 1000000000ULL, &therm->alarm); spin_unlock_irqrestore(&therm->lock, flags); if (duty >= 0) { -- cgit v1.2.3