Commit 8155cac4 authored by Francisco Jerez's avatar Francisco Jerez Committed by Ben Skeggs

drm/nouveau: Refactor nouveau_temp_get() into engine pointers.

Signed-off-by: default avatarFrancisco Jerez <currojerez@riseup.net>
Signed-off-by: default avatarBen Skeggs <bskeggs@redhat.com>
parent e829d804
......@@ -411,6 +411,8 @@ struct nouveau_pm_engine {
struct nouveau_pm_level boot;
struct nouveau_pm_level *cur;
struct device *hwmon;
int (*clock_get)(struct drm_device *, u32 id);
void *(*clock_pre)(struct drm_device *, u32 id, int khz);
void (*clock_set)(struct drm_device *, void *);
......@@ -418,6 +420,7 @@ struct nouveau_pm_engine {
int (*voltage_set)(struct drm_device *, int voltage);
int (*fanspeed_get)(struct drm_device *);
int (*fanspeed_set)(struct drm_device *, int fanspeed);
int (*temp_get)(struct drm_device *);
};
struct nouveau_engine {
......@@ -679,8 +682,6 @@ struct drm_nouveau_private {
struct nouveau_fbdev *nfbdev;
struct apertures_struct *apertures;
struct device *int_hwmon_dev;
};
static inline struct drm_nouveau_private *
......
......@@ -289,8 +289,10 @@ static ssize_t
nouveau_hwmon_show_temp(struct device *d, struct device_attribute *a, char *buf)
{
struct drm_device *dev = dev_get_drvdata(d);
struct drm_nouveau_private *dev_priv = dev->dev_private;
struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
return snprintf(buf, PAGE_SIZE, "%d\n", nouveau_temp_get(dev)*1000);
return snprintf(buf, PAGE_SIZE, "%d\n", pm->temp_get(dev)*1000);
}
static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, nouveau_hwmon_show_temp,
NULL, 0);
......@@ -399,10 +401,12 @@ static int
nouveau_hwmon_init(struct drm_device *dev)
{
struct drm_nouveau_private *dev_priv = dev->dev_private;
struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
struct device *hwmon_dev;
int ret;
dev_priv->int_hwmon_dev = NULL;
if (!pm->temp_get)
return -ENODEV;
hwmon_dev = hwmon_device_register(&dev->pdev->dev);
if (IS_ERR(hwmon_dev)) {
......@@ -421,7 +425,7 @@ nouveau_hwmon_init(struct drm_device *dev)
return ret;
}
dev_priv->int_hwmon_dev = hwmon_dev;
pm->hwmon = hwmon_dev;
return 0;
}
......@@ -430,15 +434,14 @@ static void
nouveau_hwmon_fini(struct drm_device *dev)
{
struct drm_nouveau_private *dev_priv = dev->dev_private;
struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
if (dev_priv->int_hwmon_dev) {
sysfs_remove_group(&dev_priv->int_hwmon_dev->kobj,
&hwmon_attrgroup);
hwmon_device_unregister(dev_priv->int_hwmon_dev);
if (pm->hwmon) {
sysfs_remove_group(&pm->hwmon->kobj, &hwmon_attrgroup);
hwmon_device_unregister(pm->hwmon);
}
}
int
nouveau_pm_init(struct drm_device *dev)
{
......
......@@ -56,6 +56,7 @@ void nv50_pm_clock_set(struct drm_device *, void *);
void nouveau_temp_init(struct drm_device *dev);
void nouveau_temp_fini(struct drm_device *dev);
void nouveau_temp_safety_checks(struct drm_device *dev);
int16_t nouveau_temp_get(struct drm_device *dev);
int nv40_temp_get(struct drm_device *dev);
int nv84_temp_get(struct drm_device *dev);
#endif
......@@ -320,6 +320,7 @@ static int nouveau_init_engine_ptrs(struct drm_device *dev)
engine->pm.clock_set = nv04_pm_clock_set;
engine->pm.voltage_get = nouveau_voltage_gpio_get;
engine->pm.voltage_set = nouveau_voltage_gpio_set;
engine->pm.temp_get = nv40_temp_get;
break;
case 0x50:
case 0x80: /* gotta love NVIDIA's consistency.. */
......@@ -379,6 +380,10 @@ static int nouveau_init_engine_ptrs(struct drm_device *dev)
engine->pm.clock_set = nv50_pm_clock_set;
engine->pm.voltage_get = nouveau_voltage_gpio_get;
engine->pm.voltage_set = nouveau_voltage_gpio_set;
if (dev_priv->chipset >= 0x84)
engine->pm.temp_get = nv84_temp_get;
else
engine->pm.temp_get = nv40_temp_get;
break;
case 0xC0:
engine->instmem.init = nvc0_instmem_init;
......
......@@ -154,8 +154,8 @@ nouveau_temp_vbios_parse(struct drm_device *dev, u8 *temp)
nouveau_temp_safety_checks(dev);
}
static s16
nouveau_nv40_sensor_setup(struct drm_device *dev)
static int
nv40_sensor_setup(struct drm_device *dev)
{
struct drm_nouveau_private *dev_priv = dev->dev_private;
struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
......@@ -182,40 +182,34 @@ nouveau_nv40_sensor_setup(struct drm_device *dev)
return nv_rd32(dev, 0x0015b4) & 0x1fff;
}
s16
nouveau_temp_get(struct drm_device *dev)
int
nv40_temp_get(struct drm_device *dev)
{
struct drm_nouveau_private *dev_priv = dev->dev_private;
struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
struct nouveau_pm_temp_sensor_constants *sensor = &pm->sensor_constants;
int offset = sensor->offset_mult / sensor->offset_div;
int core_temp;
if (dev_priv->chipset >= 0x84) {
return nv_rd32(dev, 0x20400);
} else if (dev_priv->chipset >= 0x40) {
u32 offset = sensor->offset_mult / sensor->offset_div;
u32 core_temp;
if (dev_priv->chipset >= 0x50) {
core_temp = nv_rd32(dev, 0x20008);
} else {
core_temp = nv_rd32(dev, 0x0015b4) & 0x1fff;
/* Setup the sensor if the temperature is 0 */
if (core_temp == 0)
core_temp = nouveau_nv40_sensor_setup(dev);
}
core_temp = core_temp * sensor->slope_mult / sensor->slope_div;
core_temp = core_temp + offset + sensor->offset_constant;
return core_temp;
if (dev_priv->chipset >= 0x50) {
core_temp = nv_rd32(dev, 0x20008);
} else {
NV_ERROR(dev,
"Temperature cannot be retrieved from an nv%x card\n",
dev_priv->chipset);
return 0;
core_temp = nv_rd32(dev, 0x0015b4) & 0x1fff;
/* Setup the sensor if the temperature is 0 */
if (core_temp == 0)
core_temp = nv40_sensor_setup(dev);
}
return 0;
core_temp = core_temp * sensor->slope_mult / sensor->slope_div;
core_temp = core_temp + offset + sensor->offset_constant;
return core_temp;
}
int
nv84_temp_get(struct drm_device *dev)
{
return nv_rd32(dev, 0x20400);
}
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