Commit da06b46b authored by Ben Skeggs's avatar Ben Skeggs

drm/nouveau/therm: cosmetic changes

This is purely preparation for upcoming commits, there should be no
code changes here.
Signed-off-by: default avatarBen Skeggs <bskeggs@redhat.com>
parent 5a7d1e22
......@@ -24,7 +24,7 @@ enum nvkm_therm_attr_type {
};
struct nvkm_therm {
struct nvkm_subdev base;
struct nvkm_subdev subdev;
int (*pwm_ctrl)(struct nvkm_therm *, int line, bool);
int (*pwm_get)(struct nvkm_therm *, int line, u32 *, u32 *);
......@@ -50,16 +50,16 @@ nvkm_therm(void *obj)
#define nvkm_therm_create(p,e,o,d) \
nvkm_therm_create_((p), (e), (o), sizeof(**d), (void **)d)
#define nvkm_therm_destroy(p) ({ \
struct nvkm_therm *therm = (p); \
_nvkm_therm_dtor(nv_object(therm)); \
struct nvkm_therm *_therm = (p); \
_nvkm_therm_dtor(nv_object(_therm)); \
})
#define nvkm_therm_init(p) ({ \
struct nvkm_therm *therm = (p); \
_nvkm_therm_init(nv_object(therm)); \
struct nvkm_therm *_therm = (p); \
_nvkm_therm_init(nv_object(_therm)); \
})
#define nvkm_therm_fini(p,s) ({ \
struct nvkm_therm *therm = (p); \
_nvkm_therm_init(nv_object(therm), (s)); \
struct nvkm_therm *_therm = (p); \
_nvkm_therm_init(nv_object(_therm), (s)); \
})
int nvkm_therm_create_(struct nvkm_object *, struct nvkm_object *,
......
......@@ -76,7 +76,7 @@ nvkm_clk_adjust(struct nvkm_clk *clk, bool adjust,
static int
nvkm_cstate_prog(struct nvkm_clk *clk, struct nvkm_pstate *pstate, int cstatei)
{
struct nvkm_therm *ptherm = nvkm_therm(clk);
struct nvkm_therm *therm = nvkm_therm(clk);
struct nvkm_volt *volt = nvkm_volt(clk);
struct nvkm_cstate *cstate;
int ret;
......@@ -87,8 +87,8 @@ nvkm_cstate_prog(struct nvkm_clk *clk, struct nvkm_pstate *pstate, int cstatei)
cstate = &pstate->base;
}
if (ptherm) {
ret = nvkm_therm_cstate(ptherm, pstate->fanspeed, +1);
if (therm) {
ret = nvkm_therm_cstate(therm, pstate->fanspeed, +1);
if (ret && ret != -ENODEV) {
nv_error(clk, "failed to raise fan speed: %d\n", ret);
return ret;
......@@ -115,8 +115,8 @@ nvkm_cstate_prog(struct nvkm_clk *clk, struct nvkm_pstate *pstate, int cstatei)
nv_error(clk, "failed to lower voltage: %d\n", ret);
}
if (ptherm) {
ret = nvkm_therm_cstate(ptherm, pstate->fanspeed, -1);
if (therm) {
ret = nvkm_therm_cstate(therm, pstate->fanspeed, -1);
if (ret && ret != -ENODEV)
nv_error(clk, "failed to lower fan speed: %d\n", ret);
}
......
......@@ -31,9 +31,8 @@
static int
nvkm_fan_update(struct nvkm_fan *fan, bool immediate, int target)
{
struct nvkm_therm *therm = fan->parent;
struct nvkm_therm_priv *priv = (void *)therm;
struct nvkm_timer *ptimer = nvkm_timer(priv);
struct nvkm_therm_priv *therm = (void *)fan->parent;
struct nvkm_timer *ptimer = nvkm_timer(therm);
unsigned long flags;
int ret = 0;
int duty;
......@@ -50,7 +49,7 @@ nvkm_fan_update(struct nvkm_fan *fan, bool immediate, int target)
}
/* check that we're not already at the target duty cycle */
duty = fan->get(therm);
duty = fan->get(&therm->base);
if (duty == target) {
spin_unlock_irqrestore(&fan->lock, flags);
return 0;
......@@ -71,7 +70,7 @@ nvkm_fan_update(struct nvkm_fan *fan, bool immediate, int target)
}
nv_debug(therm, "FAN update: %d\n", duty);
ret = fan->set(therm, duty);
ret = fan->set(&therm->base, duty);
if (ret) {
spin_unlock_irqrestore(&fan->lock, flags);
return ret;
......@@ -109,29 +108,29 @@ nvkm_fan_alarm(struct nvkm_alarm *alarm)
}
int
nvkm_therm_fan_get(struct nvkm_therm *therm)
nvkm_therm_fan_get(struct nvkm_therm *obj)
{
struct nvkm_therm_priv *priv = (void *)therm;
return priv->fan->get(therm);
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
return therm->fan->get(&therm->base);
}
int
nvkm_therm_fan_set(struct nvkm_therm *therm, bool immediate, int percent)
nvkm_therm_fan_set(struct nvkm_therm *obj, bool immediate, int percent)
{
struct nvkm_therm_priv *priv = (void *)therm;
return nvkm_fan_update(priv->fan, immediate, percent);
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
return nvkm_fan_update(therm->fan, immediate, percent);
}
int
nvkm_therm_fan_sense(struct nvkm_therm *therm)
nvkm_therm_fan_sense(struct nvkm_therm *obj)
{
struct nvkm_therm_priv *priv = (void *)therm;
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
struct nvkm_timer *ptimer = nvkm_timer(therm);
struct nvkm_gpio *gpio = nvkm_gpio(therm);
u32 cycles, cur, prev;
u64 start, end, tach;
if (priv->fan->tach.func == DCB_GPIO_UNUSED)
if (therm->fan->tach.func == DCB_GPIO_UNUSED)
return -ENODEV;
/* Time a complete rotation and extrapolate to RPM:
......@@ -139,12 +138,12 @@ nvkm_therm_fan_sense(struct nvkm_therm *therm)
* We get 4 changes (0 -> 1 -> 0 -> 1) per complete rotation.
*/
start = ptimer->read(ptimer);
prev = gpio->get(gpio, 0, priv->fan->tach.func, priv->fan->tach.line);
prev = gpio->get(gpio, 0, therm->fan->tach.func, therm->fan->tach.line);
cycles = 0;
do {
usleep_range(500, 1000); /* supports 0 < rpm < 7500 */
cur = gpio->get(gpio, 0, priv->fan->tach.func, priv->fan->tach.line);
cur = gpio->get(gpio, 0, therm->fan->tach.func, therm->fan->tach.line);
if (prev != cur) {
if (!start)
start = ptimer->read(ptimer);
......@@ -163,71 +162,72 @@ nvkm_therm_fan_sense(struct nvkm_therm *therm)
}
int
nvkm_therm_fan_user_get(struct nvkm_therm *therm)
nvkm_therm_fan_user_get(struct nvkm_therm *obj)
{
return nvkm_therm_fan_get(therm);
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
return nvkm_therm_fan_get(&therm->base);
}
int
nvkm_therm_fan_user_set(struct nvkm_therm *therm, int percent)
nvkm_therm_fan_user_set(struct nvkm_therm *obj, int percent)
{
struct nvkm_therm_priv *priv = (void *)therm;
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
if (priv->mode != NVKM_THERM_CTRL_MANUAL)
if (therm->mode != NVKM_THERM_CTRL_MANUAL)
return -EINVAL;
return nvkm_therm_fan_set(therm, true, percent);
return nvkm_therm_fan_set(&therm->base, true, percent);
}
static void
nvkm_therm_fan_set_defaults(struct nvkm_therm *therm)
nvkm_therm_fan_set_defaults(struct nvkm_therm *obj)
{
struct nvkm_therm_priv *priv = (void *)therm;
priv->fan->bios.pwm_freq = 0;
priv->fan->bios.min_duty = 0;
priv->fan->bios.max_duty = 100;
priv->fan->bios.bump_period = 500;
priv->fan->bios.slow_down_period = 2000;
priv->fan->bios.linear_min_temp = 40;
priv->fan->bios.linear_max_temp = 85;
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
therm->fan->bios.pwm_freq = 0;
therm->fan->bios.min_duty = 0;
therm->fan->bios.max_duty = 100;
therm->fan->bios.bump_period = 500;
therm->fan->bios.slow_down_period = 2000;
therm->fan->bios.linear_min_temp = 40;
therm->fan->bios.linear_max_temp = 85;
}
static void
nvkm_therm_fan_safety_checks(struct nvkm_therm *therm)
nvkm_therm_fan_safety_checks(struct nvkm_therm *obj)
{
struct nvkm_therm_priv *priv = (void *)therm;
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
if (priv->fan->bios.min_duty > 100)
priv->fan->bios.min_duty = 100;
if (priv->fan->bios.max_duty > 100)
priv->fan->bios.max_duty = 100;
if (therm->fan->bios.min_duty > 100)
therm->fan->bios.min_duty = 100;
if (therm->fan->bios.max_duty > 100)
therm->fan->bios.max_duty = 100;
if (priv->fan->bios.min_duty > priv->fan->bios.max_duty)
priv->fan->bios.min_duty = priv->fan->bios.max_duty;
if (therm->fan->bios.min_duty > therm->fan->bios.max_duty)
therm->fan->bios.min_duty = therm->fan->bios.max_duty;
}
int
nvkm_therm_fan_init(struct nvkm_therm *therm)
nvkm_therm_fan_init(struct nvkm_therm *obj)
{
return 0;
}
int
nvkm_therm_fan_fini(struct nvkm_therm *therm, bool suspend)
nvkm_therm_fan_fini(struct nvkm_therm *obj, bool suspend)
{
struct nvkm_therm_priv *priv = (void *)therm;
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
struct nvkm_timer *ptimer = nvkm_timer(therm);
if (suspend)
ptimer->alarm_cancel(ptimer, &priv->fan->alarm);
ptimer->alarm_cancel(ptimer, &therm->fan->alarm);
return 0;
}
int
nvkm_therm_fan_ctor(struct nvkm_therm *therm)
nvkm_therm_fan_ctor(struct nvkm_therm *obj)
{
struct nvkm_therm_priv *priv = (void *)therm;
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
struct nvkm_gpio *gpio = nvkm_gpio(therm);
struct nvkm_bios *bios = nvkm_bios(therm);
struct dcb_gpio_func func;
......@@ -241,42 +241,42 @@ nvkm_therm_fan_ctor(struct nvkm_therm *therm)
nv_debug(therm, "GPIO_FAN is in input mode\n");
ret = -EINVAL;
} else {
ret = nvkm_fanpwm_create(therm, &func);
ret = nvkm_fanpwm_create(&therm->base, &func);
if (ret != 0)
ret = nvkm_fantog_create(therm, &func);
ret = nvkm_fantog_create(&therm->base, &func);
}
}
/* no controllable fan found, create a dummy fan module */
if (ret != 0) {
ret = nvkm_fannil_create(therm);
ret = nvkm_fannil_create(&therm->base);
if (ret)
return ret;
}
nv_info(therm, "FAN control: %s\n", priv->fan->type);
nv_info(therm, "FAN control: %s\n", therm->fan->type);
/* read the current speed, it is useful when resuming */
priv->fan->percent = nvkm_therm_fan_get(therm);
therm->fan->percent = nvkm_therm_fan_get(&therm->base);
/* attempt to detect a tachometer connection */
ret = gpio->find(gpio, 0, DCB_GPIO_FAN_SENSE, 0xff, &priv->fan->tach);
ret = gpio->find(gpio, 0, DCB_GPIO_FAN_SENSE, 0xff, &therm->fan->tach);
if (ret)
priv->fan->tach.func = DCB_GPIO_UNUSED;
therm->fan->tach.func = DCB_GPIO_UNUSED;
/* initialise fan bump/slow update handling */
priv->fan->parent = therm;
nvkm_alarm_init(&priv->fan->alarm, nvkm_fan_alarm);
spin_lock_init(&priv->fan->lock);
therm->fan->parent = &therm->base;
nvkm_alarm_init(&therm->fan->alarm, nvkm_fan_alarm);
spin_lock_init(&therm->fan->lock);
/* other random init... */
nvkm_therm_fan_set_defaults(therm);
nvbios_perf_fan_parse(bios, &priv->fan->perf);
if (!nvbios_fan_parse(bios, &priv->fan->bios)) {
nvkm_therm_fan_set_defaults(&therm->base);
nvbios_perf_fan_parse(bios, &therm->fan->perf);
if (!nvbios_fan_parse(bios, &therm->fan->bios)) {
nv_debug(therm, "parsing the fan table failed\n");
if (nvbios_therm_fan_parse(bios, &priv->fan->bios))
if (nvbios_therm_fan_parse(bios, &therm->fan->bios))
nv_error(therm, "parsing both fan tables failed\n");
}
nvkm_therm_fan_safety_checks(therm);
nvkm_therm_fan_safety_checks(&therm->base);
return 0;
}
......@@ -36,13 +36,13 @@ nvkm_fannil_set(struct nvkm_therm *therm, int percent)
}
int
nvkm_fannil_create(struct nvkm_therm *therm)
nvkm_fannil_create(struct nvkm_therm *obj)
{
struct nvkm_therm_priv *tpriv = (void *)therm;
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
struct nvkm_fan *priv;
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
tpriv->fan = priv;
therm->fan = priv;
if (!priv)
return -ENOMEM;
......
......@@ -29,84 +29,85 @@
#include <subdev/bios/fan.h>
#include <subdev/gpio.h>
struct nvkm_fanpwm_priv {
struct nvkm_fanpwm {
struct nvkm_fan base;
struct dcb_gpio_func func;
};
static int
nvkm_fanpwm_get(struct nvkm_therm *therm)
nvkm_fanpwm_get(struct nvkm_therm *obj)
{
struct nvkm_therm_priv *tpriv = (void *)therm;
struct nvkm_fanpwm_priv *priv = (void *)tpriv->fan;
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
struct nvkm_fanpwm *fan = (void *)therm->fan;
struct nvkm_gpio *gpio = nvkm_gpio(therm);
int card_type = nv_device(therm)->card_type;
u32 divs, duty;
int ret;
ret = therm->pwm_get(therm, priv->func.line, &divs, &duty);
ret = therm->base.pwm_get(&therm->base, fan->func.line, &divs, &duty);
if (ret == 0 && divs) {
divs = max(divs, duty);
if (card_type <= NV_40 || (priv->func.log[0] & 1))
if (card_type <= NV_40 || (fan->func.log[0] & 1))
duty = divs - duty;
return (duty * 100) / divs;
}
return gpio->get(gpio, 0, priv->func.func, priv->func.line) * 100;
return gpio->get(gpio, 0, fan->func.func, fan->func.line) * 100;
}
static int
nvkm_fanpwm_set(struct nvkm_therm *therm, int percent)
nvkm_fanpwm_set(struct nvkm_therm *obj, int percent)
{
struct nvkm_therm_priv *tpriv = (void *)therm;
struct nvkm_fanpwm_priv *priv = (void *)tpriv->fan;
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
struct nvkm_fanpwm *fan = (void *)therm->fan;
int card_type = nv_device(therm)->card_type;
u32 divs, duty;
int ret;
divs = priv->base.perf.pwm_divisor;
if (priv->base.bios.pwm_freq) {
divs = fan->base.perf.pwm_divisor;
if (fan->base.bios.pwm_freq) {
divs = 1;
if (therm->pwm_clock)
divs = therm->pwm_clock(therm, priv->func.line);
divs /= priv->base.bios.pwm_freq;
if (therm->base.pwm_clock)
divs = therm->base.pwm_clock(&therm->base,
fan->func.line);
divs /= fan->base.bios.pwm_freq;
}
duty = ((divs * percent) + 99) / 100;
if (card_type <= NV_40 || (priv->func.log[0] & 1))
if (card_type <= NV_40 || (fan->func.log[0] & 1))
duty = divs - duty;
ret = therm->pwm_set(therm, priv->func.line, divs, duty);
ret = therm->base.pwm_set(&therm->base, fan->func.line, divs, duty);
if (ret == 0)
ret = therm->pwm_ctrl(therm, priv->func.line, true);
ret = therm->base.pwm_ctrl(&therm->base, fan->func.line, true);
return ret;
}
int
nvkm_fanpwm_create(struct nvkm_therm *therm, struct dcb_gpio_func *func)
nvkm_fanpwm_create(struct nvkm_therm *obj, struct dcb_gpio_func *func)
{
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
struct nvkm_device *device = nv_device(therm);
struct nvkm_therm_priv *tpriv = (void *)therm;
struct nvkm_bios *bios = nvkm_bios(therm);
struct nvkm_fanpwm_priv *priv;
struct nvbios_therm_fan fan;
struct nvkm_fanpwm *fan;
struct nvbios_therm_fan info;
u32 divs, duty;
nvbios_fan_parse(bios, &fan);
nvbios_fan_parse(bios, &info);
if (!nvkm_boolopt(device->cfgopt, "NvFanPWM", func->param) ||
!therm->pwm_ctrl || fan.type == NVBIOS_THERM_FAN_TOGGLE ||
therm->pwm_get(therm, func->line, &divs, &duty) == -ENODEV)
!therm->base.pwm_ctrl || info.type == NVBIOS_THERM_FAN_TOGGLE ||
therm->base.pwm_get(&therm->base, func->line, &divs, &duty) == -ENODEV)
return -ENODEV;
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
tpriv->fan = &priv->base;
if (!priv)
fan = kzalloc(sizeof(*fan), GFP_KERNEL);
therm->fan = &fan->base;
if (!fan)
return -ENOMEM;
priv->base.type = "PWM";
priv->base.get = nvkm_fanpwm_get;
priv->base.set = nvkm_fanpwm_set;
priv->func = *func;
fan->base.type = "PWM";
fan->base.get = nvkm_fanpwm_get;
fan->base.set = nvkm_fanpwm_set;
fan->func = *func;
return 0;
}
......@@ -26,7 +26,7 @@
#include <subdev/gpio.h>
#include <subdev/timer.h>
struct nvkm_fantog_priv {
struct nvkm_fantog {
struct nvkm_fan base;
struct nvkm_alarm alarm;
spinlock_t lock;
......@@ -36,83 +36,83 @@ struct nvkm_fantog_priv {
};
static void
nvkm_fantog_update(struct nvkm_fantog_priv *priv, int percent)
nvkm_fantog_update(struct nvkm_fantog *fan, int percent)
{
struct nvkm_therm_priv *tpriv = (void *)priv->base.parent;
struct nvkm_timer *ptimer = nvkm_timer(tpriv);
struct nvkm_gpio *gpio = nvkm_gpio(tpriv);
struct nvkm_therm_priv *therm = (void *)fan->base.parent;
struct nvkm_timer *ptimer = nvkm_timer(therm);
struct nvkm_gpio *gpio = nvkm_gpio(therm);
unsigned long flags;
int duty;
spin_lock_irqsave(&priv->lock, flags);
spin_lock_irqsave(&fan->lock, flags);
if (percent < 0)
percent = priv->percent;
priv->percent = percent;
percent = fan->percent;
fan->percent = percent;
duty = !gpio->get(gpio, 0, DCB_GPIO_FAN, 0xff);
gpio->set(gpio, 0, DCB_GPIO_FAN, 0xff, duty);
if (list_empty(&priv->alarm.head) && percent != (duty * 100)) {
u64 next_change = (percent * priv->period_us) / 100;
if (list_empty(&fan->alarm.head) && percent != (duty * 100)) {
u64 next_change = (percent * fan->period_us) / 100;
if (!duty)
next_change = priv->period_us - next_change;
ptimer->alarm(ptimer, next_change * 1000, &priv->alarm);
next_change = fan->period_us - next_change;
ptimer->alarm(ptimer, next_change * 1000, &fan->alarm);
}
spin_unlock_irqrestore(&priv->lock, flags);
spin_unlock_irqrestore(&fan->lock, flags);
}
static void
nvkm_fantog_alarm(struct nvkm_alarm *alarm)
{
struct nvkm_fantog_priv *priv =
container_of(alarm, struct nvkm_fantog_priv, alarm);
nvkm_fantog_update(priv, -1);
struct nvkm_fantog *fan =
container_of(alarm, struct nvkm_fantog, alarm);
nvkm_fantog_update(fan, -1);
}
static int
nvkm_fantog_get(struct nvkm_therm *therm)
nvkm_fantog_get(struct nvkm_therm *obj)
{
struct nvkm_therm_priv *tpriv = (void *)therm;
struct nvkm_fantog_priv *priv = (void *)tpriv->fan;
return priv->percent;
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
struct nvkm_fantog *fan = (void *)therm->fan;
return fan->percent;
}
static int
nvkm_fantog_set(struct nvkm_therm *therm, int percent)
nvkm_fantog_set(struct nvkm_therm *obj, int percent)
{
struct nvkm_therm_priv *tpriv = (void *)therm;
struct nvkm_fantog_priv *priv = (void *)tpriv->fan;
if (therm->pwm_ctrl)
therm->pwm_ctrl(therm, priv->func.line, false);
nvkm_fantog_update(priv, percent);
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
struct nvkm_fantog *fan = (void *)therm->fan;
if (therm->base.pwm_ctrl)
therm->base.pwm_ctrl(&therm->base, fan->func.line, false);
nvkm_fantog_update(fan, percent);
return 0;
}
int
nvkm_fantog_create(struct nvkm_therm *therm, struct dcb_gpio_func *func)
nvkm_fantog_create(struct nvkm_therm *obj, struct dcb_gpio_func *func)
{
struct nvkm_therm_priv *tpriv = (void *)therm;
struct nvkm_fantog_priv *priv;
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
struct nvkm_fantog *fan;
int ret;
if (therm->pwm_ctrl) {
ret = therm->pwm_ctrl(therm, func->line, false);
if (therm->base.pwm_ctrl) {
ret = therm->base.pwm_ctrl(&therm->base, func->line, false);
if (ret)
return ret;
}
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
tpriv->fan = &priv->base;
if (!priv)
fan = kzalloc(sizeof(*fan), GFP_KERNEL);
therm->fan = &fan->base;
if (!fan)
return -ENOMEM;
priv->base.type = "toggle";
priv->base.get = nvkm_fantog_get;
priv->base.set = nvkm_fantog_set;
nvkm_alarm_init(&priv->alarm, nvkm_fantog_alarm);
priv->period_us = 100000; /* 10Hz */
priv->percent = 100;
priv->func = *func;
spin_lock_init(&priv->lock);
fan->base.type = "toggle";
fan->base.get = nvkm_fantog_get;
fan->base.set = nvkm_fantog_set;
nvkm_alarm_init(&fan->alarm, nvkm_fantog_alarm);
fan->period_us = 100000; /* 10Hz */
fan->percent = 100;
fan->func = *func;
spin_lock_init(&fan->lock);
return 0;
}
......@@ -26,10 +26,6 @@
#include <subdev/fuse.h>
struct g84_therm_priv {
struct nvkm_therm_priv base;
};
int
g84_temp_get(struct nvkm_therm *therm)
{
......@@ -55,13 +51,13 @@ g84_sensor_setup(struct nvkm_therm *therm)
}
static void
g84_therm_program_alarms(struct nvkm_therm *therm)
g84_therm_program_alarms(struct nvkm_therm *obj)
{
struct nvkm_therm_priv *priv = (void *)therm;
struct nvbios_therm_sensor *sensor = &priv->bios_sensor;
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
struct nvbios_therm_sensor *sensor = &therm->bios_sensor;
unsigned long flags;
spin_lock_irqsave(&priv->sensor.alarm_program_lock, flags);
spin_lock_irqsave(&therm->sensor.alarm_program_lock, flags);
/* enable RISING and FALLING IRQs for shutdown, THRS 0, 1, 2 and 4 */
nv_wr32(therm, 0x20000, 0x000003ff);
......@@ -78,7 +74,7 @@ g84_therm_program_alarms(struct nvkm_therm *therm)
/* THRS_4 : down clock */
nv_wr32(therm, 0x20414, sensor->thrs_down_clock.temp);
spin_unlock_irqrestore(&priv->sensor.alarm_program_lock, flags);
spin_unlock_irqrestore(&therm->sensor.alarm_program_lock, flags);
nv_debug(therm,
"Programmed thresholds [ %d(%d), %d(%d), %d(%d), %d(%d) ]\n",
......@@ -137,19 +133,18 @@ g84_therm_threshold_hyst_emulation(struct nvkm_therm *therm,
static void
g84_therm_intr(struct nvkm_subdev *subdev)
{
struct nvkm_therm *therm = nvkm_therm(subdev);
struct nvkm_therm_priv *priv = (void *)therm;
struct nvbios_therm_sensor *sensor = &priv->bios_sensor;
struct nvkm_therm_priv *therm = (void *)subdev;
struct nvbios_therm_sensor *sensor = &therm->bios_sensor;
unsigned long flags;
uint32_t intr;
spin_lock_irqsave(&priv->sensor.alarm_program_lock, flags);
spin_lock_irqsave(&therm->sensor.alarm_program_lock, flags);
intr = nv_rd32(therm, 0x20100) & 0x3ff;
/* THRS_4: downclock */
if (intr & 0x002) {
g84_therm_threshold_hyst_emulation(therm, 0x20414, 24,
g84_therm_threshold_hyst_emulation(&therm->base, 0x20414, 24,
&sensor->thrs_down_clock,
NVKM_THERM_THRS_DOWNCLOCK);
intr &= ~0x002;
......@@ -157,7 +152,7 @@ g84_therm_intr(struct nvkm_subdev *subdev)
/* shutdown */
if (intr & 0x004) {
g84_therm_threshold_hyst_emulation(therm, 0x20480, 20,
g84_therm_threshold_hyst_emulation(&therm->base, 0x20480, 20,
&sensor->thrs_shutdown,
NVKM_THERM_THRS_SHUTDOWN);
intr &= ~0x004;
......@@ -165,7 +160,7 @@ g84_therm_intr(struct nvkm_subdev *subdev)
/* THRS_1 : fan boost */
if (intr & 0x008) {
g84_therm_threshold_hyst_emulation(therm, 0x204c4, 21,
g84_therm_threshold_hyst_emulation(&therm->base, 0x204c4, 21,
&sensor->thrs_fan_boost,
NVKM_THERM_THRS_FANBOOST);
intr &= ~0x008;
......@@ -173,7 +168,7 @@ g84_therm_intr(struct nvkm_subdev *subdev)
/* THRS_2 : critical */
if (intr & 0x010) {
g84_therm_threshold_hyst_emulation(therm, 0x204c0, 22,
g84_therm_threshold_hyst_emulation(&therm->base, 0x204c0, 22,
&sensor->thrs_critical,
NVKM_THERM_THRS_CRITICAL);
intr &= ~0x010;
......@@ -186,20 +181,20 @@ g84_therm_intr(struct nvkm_subdev *subdev)
nv_wr32(therm, 0x20100, 0xffffffff);
nv_wr32(therm, 0x1100, 0x10000); /* PBUS */
spin_unlock_irqrestore(&priv->sensor.alarm_program_lock, flags);
spin_unlock_irqrestore(&therm->sensor.alarm_program_lock, flags);
}
static int
g84_therm_init(struct nvkm_object *object)
{
struct g84_therm_priv *priv = (void *)object;
struct nvkm_therm_priv *therm = (void *)object;
int ret;
ret = nvkm_therm_init(&priv->base.base);
ret = nvkm_therm_init(&therm->base);
if (ret)
return ret;
g84_sensor_setup(&priv->base.base);
g84_sensor_setup(&therm->base);
return 0;
}
......@@ -208,37 +203,37 @@ g84_therm_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
struct nvkm_oclass *oclass, void *data, u32 size,
struct nvkm_object **pobject)
{
struct g84_therm_priv *priv;
struct nvkm_therm_priv *therm;
int ret;
ret = nvkm_therm_create(parent, engine, oclass, &priv);
*pobject = nv_object(priv);
ret = nvkm_therm_create(parent, engine, oclass, &therm);
*pobject = nv_object(therm);
if (ret)
return ret;
priv->base.base.pwm_ctrl = nv50_fan_pwm_ctrl;
priv->base.base.pwm_get = nv50_fan_pwm_get;
priv->base.base.pwm_set = nv50_fan_pwm_set;
priv->base.base.pwm_clock = nv50_fan_pwm_clock;
priv->base.base.temp_get = g84_temp_get;
priv->base.sensor.program_alarms = g84_therm_program_alarms;
nv_subdev(priv)->intr = g84_therm_intr;
therm->base.pwm_ctrl = nv50_fan_pwm_ctrl;
therm->base.pwm_get = nv50_fan_pwm_get;
therm->base.pwm_set = nv50_fan_pwm_set;
therm->base.pwm_clock = nv50_fan_pwm_clock;
therm->base.temp_get = g84_temp_get;
therm->sensor.program_alarms = g84_therm_program_alarms;
nv_subdev(therm)->intr = g84_therm_intr;
/* init the thresholds */
nvkm_therm_sensor_set_threshold_state(&priv->base.base,
nvkm_therm_sensor_set_threshold_state(&therm->base,
NVKM_THERM_THRS_SHUTDOWN,
NVKM_THERM_THRS_LOWER);
nvkm_therm_sensor_set_threshold_state(&priv->base.base,
nvkm_therm_sensor_set_threshold_state(&therm->base,
NVKM_THERM_THRS_FANBOOST,
NVKM_THERM_THRS_LOWER);
nvkm_therm_sensor_set_threshold_state(&priv->base.base,
nvkm_therm_sensor_set_threshold_state(&therm->base,
NVKM_THERM_THRS_CRITICAL,
NVKM_THERM_THRS_LOWER);
nvkm_therm_sensor_set_threshold_state(&priv->base.base,
nvkm_therm_sensor_set_threshold_state(&therm->base,
NVKM_THERM_THRS_DOWNCLOCK,
NVKM_THERM_THRS_LOWER);
return nvkm_therm_preinit(&priv->base.base);
return nvkm_therm_preinit(&therm->base);
}
int
......
......@@ -23,10 +23,6 @@
*/
#include "priv.h"
struct gf110_therm_priv {
struct nvkm_therm_priv base;
};
static int
pwm_info(struct nvkm_therm *therm, int line)
{
......@@ -116,21 +112,21 @@ gf110_fan_pwm_clock(struct nvkm_therm *therm, int line)
int
gf110_therm_init(struct nvkm_object *object)
{
struct gf110_therm_priv *priv = (void *)object;
struct nvkm_therm_priv *therm = (void *)object;
int ret;
ret = nvkm_therm_init(&priv->base.base);
ret = nvkm_therm_init(&therm->base);
if (ret)
return ret;
/* enable fan tach, count revolutions per-second */
nv_mask(priv, 0x00e720, 0x00000003, 0x00000002);
if (priv->base.fan->tach.func != DCB_GPIO_UNUSED) {
nv_mask(priv, 0x00d79c, 0x000000ff, priv->base.fan->tach.line);
nv_wr32(priv, 0x00e724, nv_device(priv)->crystal * 1000);
nv_mask(priv, 0x00e720, 0x00000001, 0x00000001);
nv_mask(therm, 0x00e720, 0x00000003, 0x00000002);
if (therm->fan->tach.func != DCB_GPIO_UNUSED) {
nv_mask(therm, 0x00d79c, 0x000000ff, therm->fan->tach.line);
nv_wr32(therm, 0x00e724, nv_device(therm)->crystal * 1000);
nv_mask(therm, 0x00e720, 0x00000001, 0x00000001);
}
nv_mask(priv, 0x00e720, 0x00000002, 0x00000000);
nv_mask(therm, 0x00e720, 0x00000002, 0x00000000);
return 0;
}
......@@ -140,24 +136,24 @@ gf110_therm_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
struct nvkm_oclass *oclass, void *data, u32 size,
struct nvkm_object **pobject)
{
struct gf110_therm_priv *priv;
struct nvkm_therm_priv *therm;
int ret;
ret = nvkm_therm_create(parent, engine, oclass, &priv);
*pobject = nv_object(priv);
ret = nvkm_therm_create(parent, engine, oclass, &therm);
*pobject = nv_object(therm);
if (ret)
return ret;
g84_sensor_setup(&priv->base.base);
g84_sensor_setup(&therm->base);
priv->base.base.pwm_ctrl = gf110_fan_pwm_ctrl;
priv->base.base.pwm_get = gf110_fan_pwm_get;
priv->base.base.pwm_set = gf110_fan_pwm_set;
priv->base.base.pwm_clock = gf110_fan_pwm_clock;
priv->base.base.temp_get = g84_temp_get;
priv->base.base.fan_sense = gt215_therm_fan_sense;
priv->base.sensor.program_alarms = nvkm_therm_program_alarms_polling;
return nvkm_therm_preinit(&priv->base.base);
therm->base.pwm_ctrl = gf110_fan_pwm_ctrl;
therm->base.pwm_get = gf110_fan_pwm_get;
therm->base.pwm_set = gf110_fan_pwm_set;
therm->base.pwm_clock = gf110_fan_pwm_clock;
therm->base.temp_get = g84_temp_get;
therm->base.fan_sense = gt215_therm_fan_sense;
therm->sensor.program_alarms = nvkm_therm_program_alarms_polling;
return nvkm_therm_preinit(&therm->base);
}
struct nvkm_oclass
......
......@@ -23,10 +23,6 @@
*/
#include "priv.h"
struct gm107_therm_priv {
struct nvkm_therm_priv base;
};
static int
gm107_fan_pwm_ctrl(struct nvkm_therm *therm, int line, bool enable)
{
......@@ -61,22 +57,22 @@ gm107_therm_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
struct nvkm_oclass *oclass, void *data, u32 size,
struct nvkm_object **pobject)
{
struct gm107_therm_priv *priv;
struct nvkm_therm_priv *therm;
int ret;
ret = nvkm_therm_create(parent, engine, oclass, &priv);
*pobject = nv_object(priv);
ret = nvkm_therm_create(parent, engine, oclass, &therm);
*pobject = nv_object(therm);
if (ret)
return ret;
priv->base.base.pwm_ctrl = gm107_fan_pwm_ctrl;
priv->base.base.pwm_get = gm107_fan_pwm_get;
priv->base.base.pwm_set = gm107_fan_pwm_set;
priv->base.base.pwm_clock = gm107_fan_pwm_clock;
priv->base.base.temp_get = g84_temp_get;
priv->base.base.fan_sense = gt215_therm_fan_sense;
priv->base.sensor.program_alarms = nvkm_therm_program_alarms_polling;
return nvkm_therm_preinit(&priv->base.base);
therm->base.pwm_ctrl = gm107_fan_pwm_ctrl;
therm->base.pwm_get = gm107_fan_pwm_get;
therm->base.pwm_set = gm107_fan_pwm_set;
therm->base.pwm_clock = gm107_fan_pwm_clock;
therm->base.temp_get = g84_temp_get;
therm->base.fan_sense = gt215_therm_fan_sense;
therm->sensor.program_alarms = nvkm_therm_program_alarms_polling;
return nvkm_therm_preinit(&therm->base);
}
struct nvkm_oclass
......
......@@ -25,10 +25,6 @@
#include <subdev/gpio.h>
struct gt215_therm_priv {
struct nvkm_therm_priv base;
};
int
gt215_therm_fan_sense(struct nvkm_therm *therm)
{
......@@ -42,24 +38,24 @@ gt215_therm_fan_sense(struct nvkm_therm *therm)
static int
gt215_therm_init(struct nvkm_object *object)
{
struct gt215_therm_priv *priv = (void *)object;
struct dcb_gpio_func *tach = &priv->base.fan->tach;
struct nvkm_therm_priv *therm = (void *)object;
struct dcb_gpio_func *tach = &therm->fan->tach;
int ret;
ret = nvkm_therm_init(&priv->base.base);
ret = nvkm_therm_init(&therm->base);
if (ret)
return ret;
g84_sensor_setup(&priv->base.base);
g84_sensor_setup(&therm->base);
/* enable fan tach, count revolutions per-second */
nv_mask(priv, 0x00e720, 0x00000003, 0x00000002);
nv_mask(therm, 0x00e720, 0x00000003, 0x00000002);
if (tach->func != DCB_GPIO_UNUSED) {
nv_wr32(priv, 0x00e724, nv_device(priv)->crystal * 1000);
nv_mask(priv, 0x00e720, 0x001f0000, tach->line << 16);
nv_mask(priv, 0x00e720, 0x00000001, 0x00000001);
nv_wr32(therm, 0x00e724, nv_device(therm)->crystal * 1000);
nv_mask(therm, 0x00e720, 0x001f0000, tach->line << 16);
nv_mask(therm, 0x00e720, 0x00000001, 0x00000001);
}
nv_mask(priv, 0x00e720, 0x00000002, 0x00000000);
nv_mask(therm, 0x00e720, 0x00000002, 0x00000000);
return 0;
}
......@@ -69,22 +65,22 @@ gt215_therm_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
struct nvkm_oclass *oclass, void *data, u32 size,
struct nvkm_object **pobject)
{
struct gt215_therm_priv *priv;
struct nvkm_therm_priv *therm;
int ret;
ret = nvkm_therm_create(parent, engine, oclass, &priv);
*pobject = nv_object(priv);
ret = nvkm_therm_create(parent, engine, oclass, &therm);
*pobject = nv_object(therm);
if (ret)
return ret;
priv->base.base.pwm_ctrl = nv50_fan_pwm_ctrl;
priv->base.base.pwm_get = nv50_fan_pwm_get;
priv->base.base.pwm_set = nv50_fan_pwm_set;
priv->base.base.pwm_clock = nv50_fan_pwm_clock;
priv->base.base.temp_get = g84_temp_get;
priv->base.base.fan_sense = gt215_therm_fan_sense;
priv->base.sensor.program_alarms = nvkm_therm_program_alarms_polling;
return nvkm_therm_preinit(&priv->base.base);
therm->base.pwm_ctrl = nv50_fan_pwm_ctrl;
therm->base.pwm_get = nv50_fan_pwm_get;
therm->base.pwm_set = nv50_fan_pwm_set;
therm->base.pwm_clock = nv50_fan_pwm_clock;
therm->base.temp_get = g84_temp_get;
therm->base.fan_sense = gt215_therm_fan_sense;
therm->sensor.program_alarms = nvkm_therm_program_alarms_polling;
return nvkm_therm_preinit(&therm->base);
}
struct nvkm_oclass
......
......@@ -30,8 +30,8 @@ static bool
probe_monitoring_device(struct nvkm_i2c_port *i2c,
struct i2c_board_info *info, void *data)
{
struct nvkm_therm_priv *priv = data;
struct nvbios_therm_sensor *sensor = &priv->bios_sensor;
struct nvkm_therm_priv *therm = data;
struct nvbios_therm_sensor *sensor = &therm->bios_sensor;
struct i2c_client *client;
request_module("%s%s", I2C_MODULE_PREFIX, info->type);
......@@ -46,11 +46,11 @@ probe_monitoring_device(struct nvkm_i2c_port *i2c,
return false;
}
nv_info(priv,
nv_info(therm,
"Found an %s at address 0x%x (controlled by lm_sensors, "
"temp offset %+i C)\n",
info->type, info->addr, sensor->offset_constant);
priv->ic = client;
therm->ic = client;
return true;
}
......@@ -80,9 +80,9 @@ nv_board_infos[] = {
};
void
nvkm_therm_ic_ctor(struct nvkm_therm *therm)
nvkm_therm_ic_ctor(struct nvkm_therm *obj)
{
struct nvkm_therm_priv *priv = (void *)therm;
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
struct nvkm_bios *bios = nvkm_bios(therm);
struct nvkm_i2c *i2c = nvkm_i2c(therm);
struct nvbios_extdev_func extdev_entry;
......@@ -95,7 +95,7 @@ nvkm_therm_ic_ctor(struct nvkm_therm *therm)
i2c->identify(i2c, NV_I2C_DEFAULT(0), "monitoring device",
board, probe_monitoring_device, therm);
if (priv->ic)
if (therm->ic)
return;
}
......@@ -107,7 +107,7 @@ nvkm_therm_ic_ctor(struct nvkm_therm *therm)
i2c->identify(i2c, NV_I2C_DEFAULT(0), "monitoring device",
board, probe_monitoring_device, therm);
if (priv->ic)
if (therm->ic)
return;
}
......
......@@ -24,10 +24,6 @@
*/
#include "priv.h"
struct nv40_therm_priv {
struct nvkm_therm_priv base;
};
enum nv40_sensor_style { INVALID_STYLE = -1, OLD_STYLE = 0, NEW_STYLE = 1 };
static enum nv40_sensor_style
......@@ -76,11 +72,11 @@ nv40_sensor_setup(struct nvkm_therm *therm)
}
static int
nv40_temp_get(struct nvkm_therm *therm)
nv40_temp_get(struct nvkm_therm *obj)
{
struct nvkm_therm_priv *priv = (void *)therm;
struct nvbios_therm_sensor *sensor = &priv->bios_sensor;
enum nv40_sensor_style style = nv40_sensor_style(therm);
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
struct nvbios_therm_sensor *sensor = &therm->bios_sensor;
enum nv40_sensor_style style = nv40_sensor_style(&therm->base);
int core_temp;
if (style == NEW_STYLE) {
......@@ -184,21 +180,21 @@ nv40_therm_ctor(struct nvkm_object *parent,
struct nvkm_oclass *oclass, void *data, u32 size,
struct nvkm_object **pobject)
{
struct nv40_therm_priv *priv;
struct nvkm_therm_priv *therm;
int ret;
ret = nvkm_therm_create(parent, engine, oclass, &priv);
*pobject = nv_object(priv);
ret = nvkm_therm_create(parent, engine, oclass, &therm);
*pobject = nv_object(therm);
if (ret)
return ret;
priv->base.base.pwm_ctrl = nv40_fan_pwm_ctrl;
priv->base.base.pwm_get = nv40_fan_pwm_get;
priv->base.base.pwm_set = nv40_fan_pwm_set;
priv->base.base.temp_get = nv40_temp_get;
priv->base.sensor.program_alarms = nvkm_therm_program_alarms_polling;
nv_subdev(priv)->intr = nv40_therm_intr;
return nvkm_therm_preinit(&priv->base.base);
therm->base.pwm_ctrl = nv40_fan_pwm_ctrl;
therm->base.pwm_get = nv40_fan_pwm_get;
therm->base.pwm_set = nv40_fan_pwm_set;
therm->base.temp_get = nv40_temp_get;
therm->sensor.program_alarms = nvkm_therm_program_alarms_polling;
nv_subdev(therm)->intr = nv40_therm_intr;
return nvkm_therm_preinit(&therm->base);
}
static int
......
......@@ -24,10 +24,6 @@
*/
#include "priv.h"
struct nv50_therm_priv {
struct nvkm_therm_priv base;
};
static int
pwm_info(struct nvkm_therm *therm, int *line, int *ctrl, int *indx)
{
......@@ -125,10 +121,10 @@ nv50_sensor_setup(struct nvkm_therm *therm)
}
static int
nv50_temp_get(struct nvkm_therm *therm)
nv50_temp_get(struct nvkm_therm *obj)
{
struct nvkm_therm_priv *priv = (void *)therm;
struct nvbios_therm_sensor *sensor = &priv->bios_sensor;
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
struct nvbios_therm_sensor *sensor = &therm->bios_sensor;
int core_temp;
core_temp = nv_rd32(therm, 0x20014) & 0x3fff;
......@@ -155,23 +151,23 @@ nv50_therm_ctor(struct nvkm_object *parent,
struct nvkm_oclass *oclass, void *data, u32 size,
struct nvkm_object **pobject)
{
struct nv50_therm_priv *priv;
struct nvkm_therm_priv *therm;
int ret;
ret = nvkm_therm_create(parent, engine, oclass, &priv);
*pobject = nv_object(priv);
ret = nvkm_therm_create(parent, engine, oclass, &therm);
*pobject = nv_object(therm);
if (ret)
return ret;
priv->base.base.pwm_ctrl = nv50_fan_pwm_ctrl;
priv->base.base.pwm_get = nv50_fan_pwm_get;
priv->base.base.pwm_set = nv50_fan_pwm_set;
priv->base.base.pwm_clock = nv50_fan_pwm_clock;
priv->base.base.temp_get = nv50_temp_get;
priv->base.sensor.program_alarms = nvkm_therm_program_alarms_polling;
nv_subdev(priv)->intr = nv40_therm_intr;
therm->base.pwm_ctrl = nv50_fan_pwm_ctrl;
therm->base.pwm_get = nv50_fan_pwm_get;
therm->base.pwm_set = nv50_fan_pwm_set;
therm->base.pwm_clock = nv50_fan_pwm_clock;
therm->base.temp_get = nv50_temp_get;
therm->sensor.program_alarms = nvkm_therm_program_alarms_polling;
nv_subdev(therm)->intr = nv40_therm_intr;
return nvkm_therm_preinit(&priv->base.base);
return nvkm_therm_preinit(&therm->base);
}
static int
......
......@@ -24,31 +24,31 @@
#include "priv.h"
static void
nvkm_therm_temp_set_defaults(struct nvkm_therm *therm)
nvkm_therm_temp_set_defaults(struct nvkm_therm *obj)
{
struct nvkm_therm_priv *priv = (void *)therm;
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
priv->bios_sensor.offset_constant = 0;
therm->bios_sensor.offset_constant = 0;
priv->bios_sensor.thrs_fan_boost.temp = 90;
priv->bios_sensor.thrs_fan_boost.hysteresis = 3;
therm->bios_sensor.thrs_fan_boost.temp = 90;
therm->bios_sensor.thrs_fan_boost.hysteresis = 3;
priv->bios_sensor.thrs_down_clock.temp = 95;
priv->bios_sensor.thrs_down_clock.hysteresis = 3;
therm->bios_sensor.thrs_down_clock.temp = 95;
therm->bios_sensor.thrs_down_clock.hysteresis = 3;
priv->bios_sensor.thrs_critical.temp = 105;
priv->bios_sensor.thrs_critical.hysteresis = 5;
therm->bios_sensor.thrs_critical.temp = 105;
therm->bios_sensor.thrs_critical.hysteresis = 5;
priv->bios_sensor.thrs_shutdown.temp = 135;
priv->bios_sensor.thrs_shutdown.hysteresis = 5; /*not that it matters */
therm->bios_sensor.thrs_shutdown.temp = 135;
therm->bios_sensor.thrs_shutdown.hysteresis = 5; /*not that it matters */
}
static void
nvkm_therm_temp_safety_checks(struct nvkm_therm *therm)
nvkm_therm_temp_safety_checks(struct nvkm_therm *obj)
{
struct nvkm_therm_priv *priv = (void *)therm;
struct nvbios_therm_sensor *s = &priv->bios_sensor;
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
struct nvbios_therm_sensor *s = &therm->bios_sensor;
/* enforce a minimum hysteresis on thresholds */
s->thrs_fan_boost.hysteresis = max_t(u8, s->thrs_fan_boost.hysteresis, 2);
......@@ -59,21 +59,21 @@ nvkm_therm_temp_safety_checks(struct nvkm_therm *therm)
/* must be called with alarm_program_lock taken ! */
void
nvkm_therm_sensor_set_threshold_state(struct nvkm_therm *therm,
nvkm_therm_sensor_set_threshold_state(struct nvkm_therm *obj,
enum nvkm_therm_thrs thrs,
enum nvkm_therm_thrs_state st)
{
struct nvkm_therm_priv *priv = (void *)therm;
priv->sensor.alarm_state[thrs] = st;
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
therm->sensor.alarm_state[thrs] = st;
}
/* must be called with alarm_program_lock taken ! */
enum nvkm_therm_thrs_state
nvkm_therm_sensor_get_threshold_state(struct nvkm_therm *therm,
nvkm_therm_sensor_get_threshold_state(struct nvkm_therm *obj,
enum nvkm_therm_thrs thrs)
{
struct nvkm_therm_priv *priv = (void *)therm;
return priv->sensor.alarm_state[thrs];
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
return therm->sensor.alarm_state[thrs];
}
static void
......@@ -84,15 +84,15 @@ nv_poweroff_work(struct work_struct *work)
}
void
nvkm_therm_sensor_event(struct nvkm_therm *therm, enum nvkm_therm_thrs thrs,
nvkm_therm_sensor_event(struct nvkm_therm *obj, enum nvkm_therm_thrs thrs,
enum nvkm_therm_thrs_direction dir)
{
struct nvkm_therm_priv *priv = (void *)therm;
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
bool active;
const char *thresolds[] = {
"fanboost", "downclock", "critical", "shutdown"
};
int temperature = therm->temp_get(therm);
int temperature = therm->base.temp_get(&therm->base);
if (thrs < 0 || thrs > 3)
return;
......@@ -108,17 +108,17 @@ nvkm_therm_sensor_event(struct nvkm_therm *therm, enum nvkm_therm_thrs thrs,
switch (thrs) {
case NVKM_THERM_THRS_FANBOOST:
if (active) {
nvkm_therm_fan_set(therm, true, 100);
nvkm_therm_fan_mode(therm, NVKM_THERM_CTRL_AUTO);
nvkm_therm_fan_set(&therm->base, true, 100);
nvkm_therm_fan_mode(&therm->base, NVKM_THERM_CTRL_AUTO);
}
break;
case NVKM_THERM_THRS_DOWNCLOCK:
if (priv->emergency.downclock)
priv->emergency.downclock(therm, active);
if (therm->emergency.downclock)
therm->emergency.downclock(&therm->base, active);
break;
case NVKM_THERM_THRS_CRITICAL:
if (priv->emergency.pause)
priv->emergency.pause(therm, active);
if (therm->emergency.pause)
therm->emergency.pause(&therm->base, active);
break;
case NVKM_THERM_THRS_SHUTDOWN:
if (active) {
......@@ -166,39 +166,39 @@ nvkm_therm_threshold_hyst_polling(struct nvkm_therm *therm,
static void
alarm_timer_callback(struct nvkm_alarm *alarm)
{
struct nvkm_therm_priv *priv =
struct nvkm_therm_priv *therm =
container_of(alarm, struct nvkm_therm_priv, sensor.therm_poll_alarm);
struct nvbios_therm_sensor *sensor = &priv->bios_sensor;
struct nvkm_timer *ptimer = nvkm_timer(priv);
struct nvkm_therm *therm = &priv->base;
struct nvbios_therm_sensor *sensor = &therm->bios_sensor;
struct nvkm_timer *ptimer = nvkm_timer(therm);
unsigned long flags;
spin_lock_irqsave(&priv->sensor.alarm_program_lock, flags);
spin_lock_irqsave(&therm->sensor.alarm_program_lock, flags);
nvkm_therm_threshold_hyst_polling(therm, &sensor->thrs_fan_boost,
nvkm_therm_threshold_hyst_polling(&therm->base, &sensor->thrs_fan_boost,
NVKM_THERM_THRS_FANBOOST);
nvkm_therm_threshold_hyst_polling(therm, &sensor->thrs_down_clock,
nvkm_therm_threshold_hyst_polling(&therm->base,
&sensor->thrs_down_clock,
NVKM_THERM_THRS_DOWNCLOCK);
nvkm_therm_threshold_hyst_polling(therm, &sensor->thrs_critical,
nvkm_therm_threshold_hyst_polling(&therm->base, &sensor->thrs_critical,
NVKM_THERM_THRS_CRITICAL);
nvkm_therm_threshold_hyst_polling(therm, &sensor->thrs_shutdown,
nvkm_therm_threshold_hyst_polling(&therm->base, &sensor->thrs_shutdown,
NVKM_THERM_THRS_SHUTDOWN);
spin_unlock_irqrestore(&priv->sensor.alarm_program_lock, flags);
spin_unlock_irqrestore(&therm->sensor.alarm_program_lock, flags);
/* schedule the next poll in one second */
if (therm->temp_get(therm) >= 0 && list_empty(&alarm->head))
if (therm->base.temp_get(&therm->base) >= 0 && list_empty(&alarm->head))
ptimer->alarm(ptimer, 1000000000ULL, alarm);
}
void
nvkm_therm_program_alarms_polling(struct nvkm_therm *therm)
nvkm_therm_program_alarms_polling(struct nvkm_therm *obj)
{
struct nvkm_therm_priv *priv = (void *)therm;
struct nvbios_therm_sensor *sensor = &priv->bios_sensor;
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
struct nvbios_therm_sensor *sensor = &therm->bios_sensor;
nv_debug(therm,
"programmed thresholds [ %d(%d), %d(%d), %d(%d), %d(%d) ]\n",
......@@ -208,25 +208,25 @@ nvkm_therm_program_alarms_polling(struct nvkm_therm *therm)
sensor->thrs_critical.temp, sensor->thrs_critical.hysteresis,
sensor->thrs_shutdown.temp, sensor->thrs_shutdown.hysteresis);
alarm_timer_callback(&priv->sensor.therm_poll_alarm);
alarm_timer_callback(&therm->sensor.therm_poll_alarm);
}
int
nvkm_therm_sensor_init(struct nvkm_therm *therm)
nvkm_therm_sensor_init(struct nvkm_therm *obj)
{
struct nvkm_therm_priv *priv = (void *)therm;
priv->sensor.program_alarms(therm);
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
therm->sensor.program_alarms(&therm->base);
return 0;
}
int
nvkm_therm_sensor_fini(struct nvkm_therm *therm, bool suspend)
nvkm_therm_sensor_fini(struct nvkm_therm *obj, bool suspend)
{
struct nvkm_therm_priv *priv = (void *)therm;
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
struct nvkm_timer *ptimer = nvkm_timer(therm);
if (suspend)
ptimer->alarm_cancel(ptimer, &priv->sensor.therm_poll_alarm);
ptimer->alarm_cancel(ptimer, &therm->sensor.therm_poll_alarm);
return 0;
}
......@@ -242,18 +242,18 @@ nvkm_therm_sensor_preinit(struct nvkm_therm *therm)
}
int
nvkm_therm_sensor_ctor(struct nvkm_therm *therm)
nvkm_therm_sensor_ctor(struct nvkm_therm *obj)
{
struct nvkm_therm_priv *priv = (void *)therm;
struct nvkm_therm_priv *therm = container_of(obj, typeof(*therm), base);
struct nvkm_bios *bios = nvkm_bios(therm);
nvkm_alarm_init(&priv->sensor.therm_poll_alarm, alarm_timer_callback);
nvkm_alarm_init(&therm->sensor.therm_poll_alarm, alarm_timer_callback);
nvkm_therm_temp_set_defaults(therm);
nvkm_therm_temp_set_defaults(&therm->base);
if (nvbios_therm_sensor_parse(bios, NVBIOS_THERM_DOMAIN_CORE,
&priv->bios_sensor))
&therm->bios_sensor))
nv_error(therm, "nvbios_therm_sensor_parse failed\n");
nvkm_therm_temp_safety_checks(therm);
nvkm_therm_temp_safety_checks(&therm->base);
return 0;
}
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