Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

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

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

parent e829d804
Loading
Loading
Loading
Loading
+3 −2
Original line number Original line Diff line number Diff line
@@ -411,6 +411,8 @@ struct nouveau_pm_engine {
	struct nouveau_pm_level boot;
	struct nouveau_pm_level boot;
	struct nouveau_pm_level *cur;
	struct nouveau_pm_level *cur;


	struct device *hwmon;

	int (*clock_get)(struct drm_device *, u32 id);
	int (*clock_get)(struct drm_device *, u32 id);
	void *(*clock_pre)(struct drm_device *, u32 id, int khz);
	void *(*clock_pre)(struct drm_device *, u32 id, int khz);
	void (*clock_set)(struct drm_device *, void *);
	void (*clock_set)(struct drm_device *, void *);
@@ -418,6 +420,7 @@ struct nouveau_pm_engine {
	int (*voltage_set)(struct drm_device *, int voltage);
	int (*voltage_set)(struct drm_device *, int voltage);
	int (*fanspeed_get)(struct drm_device *);
	int (*fanspeed_get)(struct drm_device *);
	int (*fanspeed_set)(struct drm_device *, int fanspeed);
	int (*fanspeed_set)(struct drm_device *, int fanspeed);
	int (*temp_get)(struct drm_device *);
};
};


struct nouveau_engine {
struct nouveau_engine {
@@ -679,8 +682,6 @@ struct drm_nouveau_private {


	struct nouveau_fbdev *nfbdev;
	struct nouveau_fbdev *nfbdev;
	struct apertures_struct *apertures;
	struct apertures_struct *apertures;

	struct device *int_hwmon_dev;
};
};


static inline struct drm_nouveau_private *
static inline struct drm_nouveau_private *
+11 −8
Original line number Original line Diff line number Diff line
@@ -289,8 +289,10 @@ static ssize_t
nouveau_hwmon_show_temp(struct device *d, struct device_attribute *a, char *buf)
nouveau_hwmon_show_temp(struct device *d, struct device_attribute *a, char *buf)
{
{
	struct drm_device *dev = dev_get_drvdata(d);
	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,
static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, nouveau_hwmon_show_temp,
						  NULL, 0);
						  NULL, 0);
@@ -399,10 +401,12 @@ static int
nouveau_hwmon_init(struct drm_device *dev)
nouveau_hwmon_init(struct drm_device *dev)
{
{
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
	struct device *hwmon_dev;
	struct device *hwmon_dev;
	int ret;
	int ret;


	dev_priv->int_hwmon_dev = NULL;
	if (!pm->temp_get)
		return -ENODEV;


	hwmon_dev = hwmon_device_register(&dev->pdev->dev);
	hwmon_dev = hwmon_device_register(&dev->pdev->dev);
	if (IS_ERR(hwmon_dev)) {
	if (IS_ERR(hwmon_dev)) {
@@ -421,7 +425,7 @@ nouveau_hwmon_init(struct drm_device *dev)
		return ret;
		return ret;
	}
	}


	dev_priv->int_hwmon_dev = hwmon_dev;
	pm->hwmon = hwmon_dev;


	return 0;
	return 0;
}
}
@@ -430,15 +434,14 @@ static void
nouveau_hwmon_fini(struct drm_device *dev)
nouveau_hwmon_fini(struct drm_device *dev)
{
{
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	struct nouveau_pm_engine *pm = &dev_priv->engine.pm;


	if (dev_priv->int_hwmon_dev) {
	if (pm->hwmon) {
		sysfs_remove_group(&dev_priv->int_hwmon_dev->kobj,
		sysfs_remove_group(&pm->hwmon->kobj, &hwmon_attrgroup);
						   &hwmon_attrgroup);
		hwmon_device_unregister(pm->hwmon);
		hwmon_device_unregister(dev_priv->int_hwmon_dev);
	}
	}
}
}



int
int
nouveau_pm_init(struct drm_device *dev)
nouveau_pm_init(struct drm_device *dev)
{
{
+2 −1
Original line number Original line Diff line number Diff line
@@ -56,6 +56,7 @@ void nv50_pm_clock_set(struct drm_device *, void *);
void nouveau_temp_init(struct drm_device *dev);
void nouveau_temp_init(struct drm_device *dev);
void nouveau_temp_fini(struct drm_device *dev);
void nouveau_temp_fini(struct drm_device *dev);
void nouveau_temp_safety_checks(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
#endif
+5 −0
Original line number Original line Diff line number Diff line
@@ -320,6 +320,7 @@ static int nouveau_init_engine_ptrs(struct drm_device *dev)
		engine->pm.clock_set		= nv04_pm_clock_set;
		engine->pm.clock_set		= nv04_pm_clock_set;
		engine->pm.voltage_get		= nouveau_voltage_gpio_get;
		engine->pm.voltage_get		= nouveau_voltage_gpio_get;
		engine->pm.voltage_set		= nouveau_voltage_gpio_set;
		engine->pm.voltage_set		= nouveau_voltage_gpio_set;
		engine->pm.temp_get		= nv40_temp_get;
		break;
		break;
	case 0x50:
	case 0x50:
	case 0x80: /* gotta love NVIDIA's consistency.. */
	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.clock_set		= nv50_pm_clock_set;
		engine->pm.voltage_get		= nouveau_voltage_gpio_get;
		engine->pm.voltage_get		= nouveau_voltage_gpio_get;
		engine->pm.voltage_set		= nouveau_voltage_gpio_set;
		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;
		break;
	case 0xC0:
	case 0xC0:
		engine->instmem.init		= nvc0_instmem_init;
		engine->instmem.init		= nvc0_instmem_init;
+22 −28
Original line number Original line Diff line number Diff line
@@ -154,8 +154,8 @@ nouveau_temp_vbios_parse(struct drm_device *dev, u8 *temp)
	nouveau_temp_safety_checks(dev);
	nouveau_temp_safety_checks(dev);
}
}


static s16
static int
nouveau_nv40_sensor_setup(struct drm_device *dev)
nv40_sensor_setup(struct drm_device *dev)
{
{
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
	struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
@@ -182,18 +182,14 @@ nouveau_nv40_sensor_setup(struct drm_device *dev)
	return nv_rd32(dev, 0x0015b4) & 0x1fff;
	return nv_rd32(dev, 0x0015b4) & 0x1fff;
}
}


s16
int
nouveau_temp_get(struct drm_device *dev)
nv40_temp_get(struct drm_device *dev)
{
{
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
	struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
	struct nouveau_pm_temp_sensor_constants *sensor = &pm->sensor_constants;
	struct nouveau_pm_temp_sensor_constants *sensor = &pm->sensor_constants;

	int offset = sensor->offset_mult / sensor->offset_div;
	if (dev_priv->chipset >= 0x84) {
	int core_temp;
		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) {
	if (dev_priv->chipset >= 0x50) {
		core_temp = nv_rd32(dev, 0x20008);
		core_temp = nv_rd32(dev, 0x20008);
@@ -201,21 +197,19 @@ nouveau_temp_get(struct drm_device *dev)
		core_temp = nv_rd32(dev, 0x0015b4) & 0x1fff;
		core_temp = nv_rd32(dev, 0x0015b4) & 0x1fff;
		/* Setup the sensor if the temperature is 0 */
		/* Setup the sensor if the temperature is 0 */
		if (core_temp == 0)
		if (core_temp == 0)
				core_temp = nouveau_nv40_sensor_setup(dev);
			core_temp = nv40_sensor_setup(dev);
	}
	}


	core_temp = core_temp * sensor->slope_mult / sensor->slope_div;
	core_temp = core_temp * sensor->slope_mult / sensor->slope_div;
	core_temp = core_temp + offset + sensor->offset_constant;
	core_temp = core_temp + offset + sensor->offset_constant;


	return core_temp;
	return core_temp;
	} else {
		NV_ERROR(dev,
				 "Temperature cannot be retrieved from an nv%x card\n",
				 dev_priv->chipset);
		return 0;
}
}


	return 0;
int
nv84_temp_get(struct drm_device *dev)
{
	return nv_rd32(dev, 0x20400);
}
}


void
void