]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
drm/nouveau: Refactor nouveau_temp_get() into engine pointers.
authorFrancisco Jerez <currojerez@riseup.net>
Thu, 23 Sep 2010 18:58:38 +0000 (20:58 +0200)
committerBen Skeggs <bskeggs@redhat.com>
Fri, 24 Sep 2010 06:29:29 +0000 (16:29 +1000)
Signed-off-by: Francisco Jerez <currojerez@riseup.net>
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
drivers/gpu/drm/nouveau/nouveau_drv.h
drivers/gpu/drm/nouveau/nouveau_pm.c
drivers/gpu/drm/nouveau/nouveau_pm.h
drivers/gpu/drm/nouveau/nouveau_state.c
drivers/gpu/drm/nouveau/nouveau_temp.c

index 3fc5596df3601131fb2820f20a49bd9e9b3a8d0c..799cd149745d000246dfe4a4bbc92c444cfde0f7 100644 (file)
@@ -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 *
index 09b638435f8fa077a0d7b3c36514153f1474f43d..85a56dea0ef76e5d5751444f8cd20432b75bba64 100644 (file)
@@ -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)
 {
index d048b7516b1c10ee4f9fe539b0e21ba87f5b7414..6ad0ca9db88f0d060e1af0395fd24a5f26702053 100644 (file)
@@ -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
index f9f77de6bbc0bb07043ddf20a6fb8453af428dcd..affcfc2fae192be7de2804daec21ab2ae0d1df4c 100644 (file)
@@ -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;
index 86b170a851be3d83b6592ec83ceafc7003d7c0db..2f7785ca4e482836b5e7c23fc36fde909029e803 100644 (file)
@@ -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